From 74b14b525290fb8d7f4ebd82a767d9d2764534e3 Mon Sep 17 00:00:00 2001 From: Sergio Martin Sanchez Date: Thu, 17 Apr 2025 15:31:06 +0200 Subject: [PATCH 1/3] feat!: add config to user model. That introduced a circular dependency that had to be fixed. Added models for phone contact --- package.json | 6 +----- src/schemas/common.ts | 14 -------------- src/schemas/contact.ts | 15 +++++++++++++++ src/schemas/index.ts | 3 ++- src/schemas/reminder.ts | 18 ------------------ src/templates/index.ts | 1 - src/templates/reminders/index.ts | 1 - src/types/api/index.ts | 2 -- src/types/{api => }/calendar.ts | 0 src/types/contact.ts | 7 +++++++ src/types/index.ts | 5 +++++ .../reminders/sms-rcs.ts => types/reminder.ts} | 16 +++++++++++++++- src/types/{api => }/user.ts | 8 +++++++- 13 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 src/schemas/contact.ts delete mode 100644 src/schemas/reminder.ts delete mode 100644 src/templates/index.ts delete mode 100644 src/templates/reminders/index.ts rename src/types/{api => }/calendar.ts (100%) create mode 100644 src/types/contact.ts rename src/{templates/reminders/sms-rcs.ts => types/reminder.ts} (85%) rename src/types/{api => }/user.ts (54%) diff --git a/package.json b/package.json index 06c11f8..fae5ea8 100644 --- a/package.json +++ b/package.json @@ -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" @@ -66,4 +62,4 @@ "typescript": "^5.7.3", "zod": "3.24.2" } -} +} \ No newline at end of file diff --git a/src/schemas/common.ts b/src/schemas/common.ts index 8daa9b6..ee49acf 100644 --- a/src/schemas/common.ts +++ b/src/schemas/common.ts @@ -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')); @@ -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]); diff --git a/src/schemas/contact.ts b/src/schemas/contact.ts new file mode 100644 index 0000000..d2a2b95 --- /dev/null +++ b/src/schemas/contact.ts @@ -0,0 +1,15 @@ +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]); diff --git a/src/schemas/index.ts b/src/schemas/index.ts index 356a90b..2ea081d 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -1,4 +1,5 @@ export * from './calendar'; export * from './common'; +export * from './contact'; export * from './i18n'; -export * from './reminder'; + diff --git a/src/schemas/reminder.ts b/src/schemas/reminder.ts deleted file mode 100644 index 5a6238a..0000000 --- a/src/schemas/reminder.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { templateSelectionSchema } from '@templates'; -import { z } from 'zod'; -import { calendarSchema } from './calendar'; -import { senderSchema } from './common'; - -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 - }) -}); - -// 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; diff --git a/src/templates/index.ts b/src/templates/index.ts deleted file mode 100644 index 6f9be97..0000000 --- a/src/templates/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './reminders/index'; diff --git a/src/templates/reminders/index.ts b/src/templates/reminders/index.ts deleted file mode 100644 index 58fa6da..0000000 --- a/src/templates/reminders/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './sms-rcs'; diff --git a/src/types/api/index.ts b/src/types/api/index.ts index 3a4b83d..19f8b45 100644 --- a/src/types/api/index.ts +++ b/src/types/api/index.ts @@ -1,4 +1,2 @@ export type * from './authentication'; -export type * from './calendar'; export type * from './responses'; -export type * from './user'; diff --git a/src/types/api/calendar.ts b/src/types/calendar.ts similarity index 100% rename from src/types/api/calendar.ts rename to src/types/calendar.ts diff --git a/src/types/contact.ts b/src/types/contact.ts new file mode 100644 index 0000000..9c7d876 --- /dev/null +++ b/src/types/contact.ts @@ -0,0 +1,7 @@ +import type { phoneSchema, rcsSenderSchema } from '@schemas'; +import type { z } from 'zod'; + +export type PhoneContact = z.infer; +export type RCSSenderContact = z.infer; +export type SenderContact = PhoneContact | RCSSenderContact; +export type ReceiverContact = PhoneContact; diff --git a/src/types/index.ts b/src/types/index.ts index 0a57574..9df3236 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,9 @@ 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'; + diff --git a/src/templates/reminders/sms-rcs.ts b/src/types/reminder.ts similarity index 85% rename from src/templates/reminders/sms-rcs.ts rename to src/types/reminder.ts index 2fc6fa9..d2ec40a 100644 --- a/src/templates/reminders/sms-rcs.ts +++ b/src/types/reminder.ts @@ -1,6 +1,9 @@ -import type { BusinessAddress, BusinessName, Template, TemplateId, TemplateMap } from '@types'; +import { calendarSchema } from '@schemas/calendar'; +import { senderSchema } from '@schemas/contact'; 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 = { @@ -84,3 +87,14 @@ 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 + }) +}); diff --git a/src/types/api/user.ts b/src/types/user.ts similarity index 54% rename from src/types/api/user.ts rename to src/types/user.ts index 1c434e3..cb3696a 100644 --- a/src/types/api/user.ts +++ b/src/types/user.ts @@ -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'; @@ -15,8 +17,12 @@ export interface Identity 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; + export interface User extends Identity { lastSignInAt: UnixTimestamp; signedUpAt: UnixTimestamp; userStatus: UserStatus; + config?: ReminderConfig; } From 0f8019a7a6f2a43afd8f9ada289b70d6a9fc6060 Mon Sep 17 00:00:00 2001 From: Sergio Martin Sanchez Date: Fri, 18 Apr 2025 00:22:49 +0200 Subject: [PATCH 2/3] more stuff --- src/schemas/contact.ts | 1 + src/schemas/reminder.ts | 11 +++++++++++ src/types/reminder.ts | 3 +++ 3 files changed, 15 insertions(+) create mode 100644 src/schemas/reminder.ts diff --git a/src/schemas/contact.ts b/src/schemas/contact.ts index d2a2b95..8d8c2e9 100644 --- a/src/schemas/contact.ts +++ b/src/schemas/contact.ts @@ -13,3 +13,4 @@ export const rcsSenderSchema = z.object({ }); export const senderSchema = z.discriminatedUnion('type', [rcsSenderSchema, phoneSchema]); +export const receiverSchema = z.discriminatedUnion('type', [phoneSchema]); diff --git a/src/schemas/reminder.ts b/src/schemas/reminder.ts new file mode 100644 index 0000000..3213810 --- /dev/null +++ b/src/schemas/reminder.ts @@ -0,0 +1,11 @@ +import { z } from 'zod'; +import { dateTimeSchema, timeZoneSchema } from './common'; +import { receiverSchema } from './contact'; + +export const demoReminderPayloadSchema = z.object({ + receiverContact: receiverSchema, + startTime: z.object({ + dateTime: dateTimeSchema, + timeZone: timeZoneSchema + }) +}); diff --git a/src/types/reminder.ts b/src/types/reminder.ts index d2ec40a..d529576 100644 --- a/src/types/reminder.ts +++ b/src/types/reminder.ts @@ -1,5 +1,6 @@ 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'; @@ -98,3 +99,5 @@ export const reminderConfigSchema = z.object({ senderContact: senderSchema }) }); + +export type DemoReminderPayload = z.infer; \ No newline at end of file From 279642161b50c97952968abc70b3b747cf7c2b2f Mon Sep 17 00:00:00 2001 From: Sergio Martin Sanchez Date: Fri, 18 Apr 2025 00:23:21 +0200 Subject: [PATCH 3/3] prettier --- package.json | 2 +- src/schemas/index.ts | 1 - src/types/index.ts | 1 - src/types/reminder.ts | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fae5ea8..8371b2d 100644 --- a/package.json +++ b/package.json @@ -62,4 +62,4 @@ "typescript": "^5.7.3", "zod": "3.24.2" } -} \ No newline at end of file +} diff --git a/src/schemas/index.ts b/src/schemas/index.ts index 2ea081d..026238d 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -2,4 +2,3 @@ export * from './calendar'; export * from './common'; export * from './contact'; export * from './i18n'; - diff --git a/src/types/index.ts b/src/types/index.ts index 9df3236..56d853d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,4 +6,3 @@ export type * from './i18n'; export * from './reminder'; export type * from './template'; export type * from './user'; - diff --git a/src/types/reminder.ts b/src/types/reminder.ts index d529576..9fb7fef 100644 --- a/src/types/reminder.ts +++ b/src/types/reminder.ts @@ -100,4 +100,4 @@ export const reminderConfigSchema = z.object({ }) }); -export type DemoReminderPayload = z.infer; \ No newline at end of file +export type DemoReminderPayload = z.infer;