Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
"import": "./dist/schemas/index.js",
"types": "./dist/schemas/index.d.ts"
},
"./templates": {
"import": "./dist/templates/index.js",
"types": "./dist/templates/index.d.ts"
},
"./i18n": {
"import": "./dist/i18n/index.js",
"types": "./dist/i18n/index.d.ts"
Expand Down
14 changes: 0 additions & 14 deletions src/schemas/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from 'zod';
import { countryCodeSchema } from './i18n';

const unsafeUuidSchema = z.string().uuid();
export const userIdSchema = unsafeUuidSchema.brand('UserId').or(unsafeUuidSchema.brand('Uuid'));
Expand All @@ -9,16 +8,3 @@ export const emailSchema = z.string().email().brand('Email');
export const idpIdSchema = z.string().brand('IdpId');
export const dateTimeSchema = z.string().datetime().brand('DateTime');
export const timeZoneSchema = z.string().brand('TimeZone');

export const phoneSchema = z.object({
type: z.literal('phone'),
countryCode: countryCodeSchema,
phoneNumber: z.string().brand('PhoneNumber')
});

export const rcsSenderSchema = z.object({
type: z.literal('rcs'),
identifier: z.string().brand('RCSSenderId')
});

export const senderSchema = z.discriminatedUnion('type', [rcsSenderSchema, phoneSchema]);
16 changes: 16 additions & 0 deletions src/schemas/contact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from 'zod';
import { countryCodeSchema } from './i18n';

export const phoneSchema = z.object({
type: z.literal('phone'),
countryCode: countryCodeSchema,
phoneNumber: z.string().brand('PhoneNumber')
});

export const rcsSenderSchema = z.object({
type: z.literal('rcs'),
identifier: z.string().brand('RCSSenderId')
});

export const senderSchema = z.discriminatedUnion('type', [rcsSenderSchema, phoneSchema]);
export const receiverSchema = z.discriminatedUnion('type', [phoneSchema]);
2 changes: 1 addition & 1 deletion src/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './calendar';
export * from './common';
export * from './contact';
export * from './i18n';
export * from './reminder';
21 changes: 7 additions & 14 deletions src/schemas/reminder.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { templateSelectionSchema } from '@templates';
import { z } from 'zod';
import { calendarSchema } from './calendar';
import { senderSchema } from './common';
import { dateTimeSchema, timeZoneSchema } from './common';
import { receiverSchema } from './contact';

export const templateSchema = z.string().max(160).brand('InterpolatedTemplate');

export const reminderConfigSchema = z.object({
calendars: z.array(calendarSchema.extend({ template: templateSelectionSchema })).min(1),
business: z.object({
name: z.string().min(1).brand('BusinessName'),
address: z.string().min(1).brand('BusinessAddress'),
senderContact: senderSchema
export const demoReminderPayloadSchema = z.object({
receiverContact: receiverSchema,
startTime: z.object({
dateTime: dateTimeSchema,
timeZone: timeZoneSchema
})
});

// This should really be defined in @types but this is an exception to resolve a circular dependency between @schemas, @templates and @types
export type ReminderConfig = z.infer<typeof reminderConfigSchema>;
1 change: 0 additions & 1 deletion src/templates/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/templates/reminders/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/types/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export type * from './authentication';
export type * from './calendar';
export type * from './responses';
export type * from './user';
File renamed without changes.
7 changes: 7 additions & 0 deletions src/types/contact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { phoneSchema, rcsSenderSchema } from '@schemas';
import type { z } from 'zod';

export type PhoneContact = z.infer<typeof phoneSchema>;
export type RCSSenderContact = z.infer<typeof rcsSenderSchema>;
export type SenderContact = PhoneContact | RCSSenderContact;
export type ReceiverContact = PhoneContact;
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type * from './api/index';
export type * from './calendar';
export type * from './common';
export type * from './contact';
export type * from './i18n';
export * from './reminder';
export type * from './template';
export type * from './user';
19 changes: 18 additions & 1 deletion src/templates/reminders/sms-rcs.ts → src/types/reminder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { BusinessAddress, BusinessName, Template, TemplateId, TemplateMap } from '@types';
import { calendarSchema } from '@schemas/calendar';
import { senderSchema } from '@schemas/contact';
import type { demoReminderPayloadSchema } from '@schemas/reminder';
import type { DateTime } from 'luxon';
import { z } from 'zod';
import type { BusinessAddress, BusinessName, TemplateId } from './common';
import type { Template, TemplateMap } from './template';

// Spanish
const formalEs01: Template = {
Expand Down Expand Up @@ -84,3 +88,16 @@ const templateList = Object.values(templateMap).map((t) =>
);

export const templateSelectionSchema = z.union([templateList[0]!, templateList[1]!, ...templateList.slice(2)]);

export const templateSchema = z.string().max(160).brand('InterpolatedTemplate');

export const reminderConfigSchema = z.object({
calendars: z.array(calendarSchema.extend({ template: templateSelectionSchema })).min(1),
business: z.object({
name: z.string().min(1).brand('BusinessName'),
address: z.string().min(1).brand('BusinessAddress'),
senderContact: senderSchema
})
});

export type DemoReminderPayload = z.infer<typeof demoReminderPayloadSchema>;
8 changes: 7 additions & 1 deletion src/types/api/user.ts → src/types/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Email, IdpId, UnixTimestamp, UserId } from '../common';
import type { z } from 'zod';
import type { Email, IdpId, UnixTimestamp, UserId } from './common';
import type { reminderConfigSchema } from './reminder';

// When time comes, append IdpName with | 'idpName2'
export type IdpName = 'google.com';
Expand All @@ -15,8 +17,12 @@ export interface Identity<IdpName> extends BaseIdentity {

export type UserStatus = 'banned' | 'onboarding' | 'live';

// This should really be defined in @schemas but this is an exception to resolve a circular dependency between @schemas, @templates and @types
export type ReminderConfig = z.infer<typeof reminderConfigSchema>;

export interface User<TIdpName extends IdpName> extends Identity<TIdpName> {
lastSignInAt: UnixTimestamp;
signedUpAt: UnixTimestamp;
userStatus: UserStatus;
config?: ReminderConfig;
}