@timothyw/pat-common 1.0.101 → 1.0.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/enums/module-type.d.ts +1 -0
  2. package/dist/enums/module-type.js +1 -0
  3. package/dist/types/api/account/update-user-types.d.ts +3 -3
  4. package/dist/types/api/auth/create-account-types.d.ts +2 -1
  5. package/dist/types/api/habits/create-habit-types.d.ts +2 -2
  6. package/dist/types/api/habits/update-habit-types.d.ts +2 -2
  7. package/dist/types/api/index.d.ts +1 -0
  8. package/dist/types/api/index.js +1 -0
  9. package/dist/types/api/notifications/create-notification-template-types.d.ts +93 -0
  10. package/dist/types/api/notifications/create-notification-template-types.js +31 -0
  11. package/dist/types/api/notifications/delete-notification-template-types.d.ts +14 -0
  12. package/dist/types/api/notifications/delete-notification-template-types.js +11 -0
  13. package/dist/types/api/notifications/get-notification-instances-types.d.ts +45 -0
  14. package/dist/types/api/notifications/get-notification-instances-types.js +19 -0
  15. package/dist/types/api/notifications/get-notification-templates-types.d.ts +23 -0
  16. package/dist/types/api/notifications/get-notification-templates-types.js +12 -0
  17. package/dist/types/api/notifications/index.d.ts +7 -0
  18. package/dist/types/api/notifications/index.js +23 -0
  19. package/dist/types/api/notifications/preview-notification-template-types.d.ts +58 -0
  20. package/dist/types/api/notifications/preview-notification-template-types.js +23 -0
  21. package/dist/types/api/notifications/sync-notification-template-types.d.ts +29 -0
  22. package/dist/types/api/notifications/sync-notification-template-types.js +14 -0
  23. package/dist/types/api/notifications/update-notification-template-types.d.ts +84 -0
  24. package/dist/types/api/notifications/update-notification-template-types.js +28 -0
  25. package/dist/types/api/people/create-person-note-types.d.ts +2 -2
  26. package/dist/types/id-types.d.ts +8 -0
  27. package/dist/types/id-types.js +3 -1
  28. package/dist/types/models/index.d.ts +3 -0
  29. package/dist/types/models/index.js +3 -0
  30. package/dist/types/models/notifiable.d.ts +42 -0
  31. package/dist/types/models/notifiable.js +2 -0
  32. package/dist/types/models/notification-instance-data.d.ts +128 -0
  33. package/dist/types/models/notification-instance-data.js +34 -0
  34. package/dist/types/models/notification-template-data.d.ts +224 -0
  35. package/dist/types/models/notification-template-data.js +52 -0
  36. package/dist/types/models/user-data.d.ts +2 -2
  37. package/dist/utils/serializing-utils.d.ts +5 -1
  38. package/dist/utils/serializing-utils.js +12 -0
  39. package/package.json +1 -1
  40. package/src/enums/module-type.ts +1 -0
  41. package/src/types/api/auth/create-account-types.ts +2 -1
  42. package/src/types/api/index.ts +1 -0
  43. package/src/types/api/notifications/create-notification-template-types.ts +39 -0
  44. package/src/types/api/notifications/delete-notification-template-types.ts +14 -0
  45. package/src/types/api/notifications/get-notification-instances-types.ts +29 -0
  46. package/src/types/api/notifications/get-notification-templates-types.ts +21 -0
  47. package/src/types/api/notifications/index.ts +7 -0
  48. package/src/types/api/notifications/preview-notification-template-types.ts +26 -0
  49. package/src/types/api/notifications/sync-notification-template-types.ts +23 -0
  50. package/src/types/api/notifications/update-notification-template-types.ts +36 -0
  51. package/src/types/id-types.ts +7 -1
  52. package/src/types/models/index.ts +3 -0
  53. package/src/types/models/notifiable.ts +52 -0
  54. package/src/types/models/notification-instance-data.ts +40 -0
  55. package/src/types/models/notification-template-data.ts +67 -0
  56. package/src/utils/serializing-utils.ts +18 -0
@@ -5,13 +5,13 @@ export declare const createPersonNoteRequestSchema: z.ZodObject<{
5
5
  personId: z.ZodEffects<z.ZodString, import("../../id-types").PersonId, string>;
6
6
  content: z.ZodString;
7
7
  }, "strip", z.ZodTypeAny, {
8
+ content: string;
8
9
  personId: string & {
9
10
  readonly __brand: "PersonId";
10
11
  };
11
- content: string;
12
12
  }, {
13
- personId: string;
14
13
  content: string;
14
+ personId: string;
15
15
  }>;
16
16
  export type CreatePersonNoteRequest = z.infer<typeof createPersonNoteRequestSchema>;
17
17
  export interface CreatePersonNoteResponse {
@@ -39,3 +39,11 @@ export declare const habitEntryIdSchema: z.ZodEffects<z.ZodString, TaskListId, s
39
39
  export type HabitEntryId = string & {
40
40
  readonly __brand: "HabitEntryId";
41
41
  };
42
+ export declare const notificationTemplateIdSchema: z.ZodEffects<z.ZodString, NotificationTemplateId, string>;
43
+ export type NotificationTemplateId = string & {
44
+ readonly __brand: "NotificationTemplateId";
45
+ };
46
+ export declare const notificationInstanceIdSchema: z.ZodEffects<z.ZodString, NotificationInstanceId, string>;
47
+ export type NotificationInstanceId = string & {
48
+ readonly __brand: "NotificationInstanceId";
49
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.habitEntryIdSchema = exports.habitIdSchema = exports.taskIdSchema = exports.taskListIdSchema = exports.thoughtIdSchema = exports.personNoteIdSchema = exports.personIdSchema = exports.itemIdSchema = exports.authIdSchema = exports.userIdSchema = void 0;
3
+ exports.notificationInstanceIdSchema = exports.notificationTemplateIdSchema = exports.habitEntryIdSchema = exports.habitIdSchema = exports.taskIdSchema = exports.taskListIdSchema = exports.thoughtIdSchema = exports.personNoteIdSchema = exports.personIdSchema = exports.itemIdSchema = exports.authIdSchema = exports.userIdSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.userIdSchema = zod_1.z.string().transform((val) => val);
6
6
  exports.authIdSchema = zod_1.z.string().transform((val) => val);
@@ -12,3 +12,5 @@ exports.taskListIdSchema = zod_1.z.string().transform((val) => val);
12
12
  exports.taskIdSchema = zod_1.z.string().transform((val) => val);
13
13
  exports.habitIdSchema = zod_1.z.string().transform((val) => val);
14
14
  exports.habitEntryIdSchema = zod_1.z.string().transform((val) => val);
15
+ exports.notificationTemplateIdSchema = zod_1.z.string().transform((val) => val);
16
+ exports.notificationInstanceIdSchema = zod_1.z.string().transform((val) => val);
@@ -1,6 +1,9 @@
1
1
  export * from './auth-data';
2
2
  export * from './habit-data';
3
3
  export * from './item-data';
4
+ export * from './notification-template-data';
5
+ export * from './notification-instance-data';
6
+ export * from './notifiable';
4
7
  export * from './person-data';
5
8
  export * from './program-config';
6
9
  export * from './task-data';
@@ -17,6 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./auth-data"), exports);
18
18
  __exportStar(require("./habit-data"), exports);
19
19
  __exportStar(require("./item-data"), exports);
20
+ __exportStar(require("./notification-template-data"), exports);
21
+ __exportStar(require("./notification-instance-data"), exports);
22
+ __exportStar(require("./notifiable"), exports);
20
23
  __exportStar(require("./person-data"), exports);
21
24
  __exportStar(require("./program-config"), exports);
22
25
  __exportStar(require("./task-data"), exports);
@@ -0,0 +1,42 @@
1
+ import { NotificationTemplateData, NotificationEntityType } from "./notification-template-data";
2
+ export interface NotificationContext<T = any> {
3
+ entityId: string;
4
+ entityType: NotificationEntityType;
5
+ entityData: T;
6
+ userId: string;
7
+ variables: Record<string, any>;
8
+ }
9
+ export interface INotifiable<T = any> {
10
+ /**
11
+ * Get the ID of this notifiable entity
12
+ */
13
+ getId(): string;
14
+ /**
15
+ * Get the entity type for notification purposes
16
+ */
17
+ getNotificationEntityType(): NotificationEntityType;
18
+ /**
19
+ * Get context data for notification template variables
20
+ */
21
+ getNotificationContext(): NotificationContext<T>;
22
+ /**
23
+ * Get inherited notification templates from parent entities
24
+ */
25
+ getInheritedNotificationTemplates(): Promise<NotificationTemplateData[]>;
26
+ /**
27
+ * Get custom notification templates specific to this entity
28
+ */
29
+ getCustomNotificationTemplates(): Promise<NotificationTemplateData[]>;
30
+ /**
31
+ * Get all effective notification templates (inherited + custom)
32
+ */
33
+ getAllNotificationTemplates(): Promise<NotificationTemplateData[]>;
34
+ /**
35
+ * Register notification triggers when entity is created/updated
36
+ */
37
+ registerNotificationTriggers(): Promise<void>;
38
+ /**
39
+ * Remove notification triggers when entity is deleted
40
+ */
41
+ removeNotificationTriggers(): Promise<void>;
42
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,128 @@
1
+ import { z } from "zod";
2
+ import { NotificationInstanceId, NotificationTemplateId, UserId } from "../id-types";
3
+ export declare const notificationStatusSchema: z.ZodEnum<["scheduled", "sent", "failed", "cancelled"]>;
4
+ export type NotificationStatus = z.infer<typeof notificationStatusSchema>;
5
+ export declare const notificationInstanceDataSchema: z.ZodObject<{
6
+ _id: z.ZodEffects<z.ZodString, NotificationInstanceId, string>;
7
+ templateId: z.ZodEffects<z.ZodString, NotificationTemplateId, string>;
8
+ userId: z.ZodEffects<z.ZodString, UserId, string>;
9
+ entityId: z.ZodString;
10
+ scheduledFor: z.ZodDate;
11
+ status: z.ZodEnum<["scheduled", "sent", "failed", "cancelled"]>;
12
+ sentAt: z.ZodOptional<z.ZodDate>;
13
+ content: z.ZodObject<{
14
+ title: z.ZodString;
15
+ body: z.ZodString;
16
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ title: string;
19
+ body: string;
20
+ data?: Record<string, any> | undefined;
21
+ }, {
22
+ title: string;
23
+ body: string;
24
+ data?: Record<string, any> | undefined;
25
+ }>;
26
+ redisId: z.ZodString;
27
+ error: z.ZodOptional<z.ZodString>;
28
+ createdAt: z.ZodDate;
29
+ updatedAt: z.ZodDate;
30
+ }, "strip", z.ZodTypeAny, {
31
+ _id: string & {
32
+ readonly __brand: "NotificationInstanceId";
33
+ };
34
+ createdAt: Date;
35
+ updatedAt: Date;
36
+ userId: string & {
37
+ readonly __brand: "UserId";
38
+ };
39
+ status: "scheduled" | "sent" | "failed" | "cancelled";
40
+ entityId: string;
41
+ content: {
42
+ title: string;
43
+ body: string;
44
+ data?: Record<string, any> | undefined;
45
+ };
46
+ templateId: string & {
47
+ readonly __brand: "NotificationTemplateId";
48
+ };
49
+ scheduledFor: Date;
50
+ redisId: string;
51
+ sentAt?: Date | undefined;
52
+ error?: string | undefined;
53
+ }, {
54
+ _id: string;
55
+ createdAt: Date;
56
+ updatedAt: Date;
57
+ userId: string;
58
+ status: "scheduled" | "sent" | "failed" | "cancelled";
59
+ entityId: string;
60
+ content: {
61
+ title: string;
62
+ body: string;
63
+ data?: Record<string, any> | undefined;
64
+ };
65
+ templateId: string;
66
+ scheduledFor: Date;
67
+ redisId: string;
68
+ sentAt?: Date | undefined;
69
+ error?: string | undefined;
70
+ }>;
71
+ export type NotificationInstanceData = z.infer<typeof notificationInstanceDataSchema>;
72
+ export declare const createNotificationInstanceSchema: z.ZodObject<Omit<{
73
+ _id: z.ZodEffects<z.ZodString, NotificationInstanceId, string>;
74
+ templateId: z.ZodEffects<z.ZodString, NotificationTemplateId, string>;
75
+ userId: z.ZodEffects<z.ZodString, UserId, string>;
76
+ entityId: z.ZodString;
77
+ scheduledFor: z.ZodDate;
78
+ status: z.ZodEnum<["scheduled", "sent", "failed", "cancelled"]>;
79
+ sentAt: z.ZodOptional<z.ZodDate>;
80
+ content: z.ZodObject<{
81
+ title: z.ZodString;
82
+ body: z.ZodString;
83
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ title: string;
86
+ body: string;
87
+ data?: Record<string, any> | undefined;
88
+ }, {
89
+ title: string;
90
+ body: string;
91
+ data?: Record<string, any> | undefined;
92
+ }>;
93
+ redisId: z.ZodString;
94
+ error: z.ZodOptional<z.ZodString>;
95
+ createdAt: z.ZodDate;
96
+ updatedAt: z.ZodDate;
97
+ }, "_id" | "createdAt" | "updatedAt" | "status" | "sentAt" | "error"> & {
98
+ status: z.ZodDefault<z.ZodEnum<["scheduled", "sent", "failed", "cancelled"]>>;
99
+ }, "strip", z.ZodTypeAny, {
100
+ userId: string & {
101
+ readonly __brand: "UserId";
102
+ };
103
+ status: "scheduled" | "sent" | "failed" | "cancelled";
104
+ entityId: string;
105
+ content: {
106
+ title: string;
107
+ body: string;
108
+ data?: Record<string, any> | undefined;
109
+ };
110
+ templateId: string & {
111
+ readonly __brand: "NotificationTemplateId";
112
+ };
113
+ scheduledFor: Date;
114
+ redisId: string;
115
+ }, {
116
+ userId: string;
117
+ entityId: string;
118
+ content: {
119
+ title: string;
120
+ body: string;
121
+ data?: Record<string, any> | undefined;
122
+ };
123
+ templateId: string;
124
+ scheduledFor: Date;
125
+ redisId: string;
126
+ status?: "scheduled" | "sent" | "failed" | "cancelled" | undefined;
127
+ }>;
128
+ export type CreateNotificationInstanceData = z.infer<typeof createNotificationInstanceSchema>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNotificationInstanceSchema = exports.notificationInstanceDataSchema = exports.notificationStatusSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.notificationStatusSchema = zod_1.z.enum(['scheduled', 'sent', 'failed', 'cancelled']);
6
+ exports.notificationInstanceDataSchema = zod_1.z.object({
7
+ _id: zod_1.z.string().transform((val) => val),
8
+ templateId: zod_1.z.string().transform((val) => val),
9
+ userId: zod_1.z.string().transform((val) => val),
10
+ entityId: zod_1.z.string(), // ID of the specific entity this notification is for
11
+ scheduledFor: zod_1.z.date(),
12
+ status: exports.notificationStatusSchema,
13
+ sentAt: zod_1.z.date().optional(),
14
+ content: zod_1.z.object({
15
+ title: zod_1.z.string(),
16
+ body: zod_1.z.string(),
17
+ data: zod_1.z.record(zod_1.z.any()).optional() // additional data for the notification
18
+ }),
19
+ redisId: zod_1.z.string(), // link to Redis scheduled notification for coordination
20
+ error: zod_1.z.string().optional(), // error message if status is 'failed'
21
+ createdAt: zod_1.z.date(),
22
+ updatedAt: zod_1.z.date()
23
+ });
24
+ // Helper type for creating new instances (without _id, dates, status)
25
+ exports.createNotificationInstanceSchema = exports.notificationInstanceDataSchema.omit({
26
+ _id: true,
27
+ status: true,
28
+ sentAt: true,
29
+ error: true,
30
+ createdAt: true,
31
+ updatedAt: true
32
+ }).extend({
33
+ status: exports.notificationStatusSchema.default('scheduled')
34
+ });
@@ -0,0 +1,224 @@
1
+ import { z } from "zod";
2
+ import { NotificationTemplateId, UserId } from "../id-types";
3
+ export declare const notificationEntityTypeSchema: z.ZodEnum<["agenda", "tasks", "habits", "inbox", "agenda_item", "task_list", "task", "habit", "agenda_defaults", "tasks_defaults", "habits_defaults"]>;
4
+ export type NotificationEntityType = z.infer<typeof notificationEntityTypeSchema>;
5
+ export declare const notificationTriggerTypeSchema: z.ZodEnum<["time_based", "event_based", "recurring"]>;
6
+ export type NotificationTriggerType = z.infer<typeof notificationTriggerTypeSchema>;
7
+ export declare const notificationTriggerSchema: z.ZodObject<{
8
+ type: z.ZodEnum<["time_based", "event_based", "recurring"]>;
9
+ conditions: z.ZodRecord<z.ZodString, z.ZodAny>;
10
+ timing: z.ZodRecord<z.ZodString, z.ZodAny>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ type: "time_based" | "event_based" | "recurring";
13
+ conditions: Record<string, any>;
14
+ timing: Record<string, any>;
15
+ }, {
16
+ type: "time_based" | "event_based" | "recurring";
17
+ conditions: Record<string, any>;
18
+ timing: Record<string, any>;
19
+ }>;
20
+ export type NotificationTrigger = z.infer<typeof notificationTriggerSchema>;
21
+ export declare const notificationContentSchema: z.ZodObject<{
22
+ title: z.ZodString;
23
+ body: z.ZodString;
24
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ title: string;
27
+ body: string;
28
+ variables?: Record<string, string> | undefined;
29
+ }, {
30
+ title: string;
31
+ body: string;
32
+ variables?: Record<string, string> | undefined;
33
+ }>;
34
+ export type NotificationContent = z.infer<typeof notificationContentSchema>;
35
+ export declare const notificationTemplateDataSchema: z.ZodObject<{
36
+ _id: z.ZodEffects<z.ZodString, NotificationTemplateId, string>;
37
+ userId: z.ZodEffects<z.ZodString, UserId, string>;
38
+ entityType: z.ZodEnum<["agenda", "tasks", "habits", "inbox", "agenda_item", "task_list", "task", "habit", "agenda_defaults", "tasks_defaults", "habits_defaults"]>;
39
+ entityId: z.ZodOptional<z.ZodString>;
40
+ name: z.ZodString;
41
+ description: z.ZodOptional<z.ZodString>;
42
+ trigger: z.ZodObject<{
43
+ type: z.ZodEnum<["time_based", "event_based", "recurring"]>;
44
+ conditions: z.ZodRecord<z.ZodString, z.ZodAny>;
45
+ timing: z.ZodRecord<z.ZodString, z.ZodAny>;
46
+ }, "strip", z.ZodTypeAny, {
47
+ type: "time_based" | "event_based" | "recurring";
48
+ conditions: Record<string, any>;
49
+ timing: Record<string, any>;
50
+ }, {
51
+ type: "time_based" | "event_based" | "recurring";
52
+ conditions: Record<string, any>;
53
+ timing: Record<string, any>;
54
+ }>;
55
+ content: z.ZodObject<{
56
+ title: z.ZodString;
57
+ body: z.ZodString;
58
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
59
+ }, "strip", z.ZodTypeAny, {
60
+ title: string;
61
+ body: string;
62
+ variables?: Record<string, string> | undefined;
63
+ }, {
64
+ title: string;
65
+ body: string;
66
+ variables?: Record<string, string> | undefined;
67
+ }>;
68
+ active: z.ZodDefault<z.ZodBoolean>;
69
+ inheritedFrom: z.ZodOptional<z.ZodEffects<z.ZodString, NotificationTemplateId, string>>;
70
+ customized: z.ZodDefault<z.ZodBoolean>;
71
+ createdAt: z.ZodDate;
72
+ updatedAt: z.ZodDate;
73
+ }, "strip", z.ZodTypeAny, {
74
+ _id: string & {
75
+ readonly __brand: "NotificationTemplateId";
76
+ };
77
+ createdAt: Date;
78
+ updatedAt: Date;
79
+ userId: string & {
80
+ readonly __brand: "UserId";
81
+ };
82
+ entityType: "agenda" | "inbox" | "tasks" | "habits" | "agenda_item" | "task_list" | "task" | "habit" | "agenda_defaults" | "tasks_defaults" | "habits_defaults";
83
+ name: string;
84
+ trigger: {
85
+ type: "time_based" | "event_based" | "recurring";
86
+ conditions: Record<string, any>;
87
+ timing: Record<string, any>;
88
+ };
89
+ content: {
90
+ title: string;
91
+ body: string;
92
+ variables?: Record<string, string> | undefined;
93
+ };
94
+ active: boolean;
95
+ customized: boolean;
96
+ entityId?: string | undefined;
97
+ description?: string | undefined;
98
+ inheritedFrom?: NotificationTemplateId | undefined;
99
+ }, {
100
+ _id: string;
101
+ createdAt: Date;
102
+ updatedAt: Date;
103
+ userId: string;
104
+ entityType: "agenda" | "inbox" | "tasks" | "habits" | "agenda_item" | "task_list" | "task" | "habit" | "agenda_defaults" | "tasks_defaults" | "habits_defaults";
105
+ name: string;
106
+ trigger: {
107
+ type: "time_based" | "event_based" | "recurring";
108
+ conditions: Record<string, any>;
109
+ timing: Record<string, any>;
110
+ };
111
+ content: {
112
+ title: string;
113
+ body: string;
114
+ variables?: Record<string, string> | undefined;
115
+ };
116
+ entityId?: string | undefined;
117
+ description?: string | undefined;
118
+ active?: boolean | undefined;
119
+ inheritedFrom?: string | undefined;
120
+ customized?: boolean | undefined;
121
+ }>;
122
+ export type NotificationTemplateData = z.infer<typeof notificationTemplateDataSchema>;
123
+ export declare const createNotificationTemplateSchema: z.ZodObject<Omit<{
124
+ _id: z.ZodEffects<z.ZodString, NotificationTemplateId, string>;
125
+ userId: z.ZodEffects<z.ZodString, UserId, string>;
126
+ entityType: z.ZodEnum<["agenda", "tasks", "habits", "inbox", "agenda_item", "task_list", "task", "habit", "agenda_defaults", "tasks_defaults", "habits_defaults"]>;
127
+ entityId: z.ZodOptional<z.ZodString>;
128
+ name: z.ZodString;
129
+ description: z.ZodOptional<z.ZodString>;
130
+ trigger: z.ZodObject<{
131
+ type: z.ZodEnum<["time_based", "event_based", "recurring"]>;
132
+ conditions: z.ZodRecord<z.ZodString, z.ZodAny>;
133
+ timing: z.ZodRecord<z.ZodString, z.ZodAny>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ type: "time_based" | "event_based" | "recurring";
136
+ conditions: Record<string, any>;
137
+ timing: Record<string, any>;
138
+ }, {
139
+ type: "time_based" | "event_based" | "recurring";
140
+ conditions: Record<string, any>;
141
+ timing: Record<string, any>;
142
+ }>;
143
+ content: z.ZodObject<{
144
+ title: z.ZodString;
145
+ body: z.ZodString;
146
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
147
+ }, "strip", z.ZodTypeAny, {
148
+ title: string;
149
+ body: string;
150
+ variables?: Record<string, string> | undefined;
151
+ }, {
152
+ title: string;
153
+ body: string;
154
+ variables?: Record<string, string> | undefined;
155
+ }>;
156
+ active: z.ZodDefault<z.ZodBoolean>;
157
+ inheritedFrom: z.ZodOptional<z.ZodEffects<z.ZodString, NotificationTemplateId, string>>;
158
+ customized: z.ZodDefault<z.ZodBoolean>;
159
+ createdAt: z.ZodDate;
160
+ updatedAt: z.ZodDate;
161
+ }, "_id" | "createdAt" | "updatedAt">, "strip", z.ZodTypeAny, {
162
+ userId: string & {
163
+ readonly __brand: "UserId";
164
+ };
165
+ entityType: "agenda" | "inbox" | "tasks" | "habits" | "agenda_item" | "task_list" | "task" | "habit" | "agenda_defaults" | "tasks_defaults" | "habits_defaults";
166
+ name: string;
167
+ trigger: {
168
+ type: "time_based" | "event_based" | "recurring";
169
+ conditions: Record<string, any>;
170
+ timing: Record<string, any>;
171
+ };
172
+ content: {
173
+ title: string;
174
+ body: string;
175
+ variables?: Record<string, string> | undefined;
176
+ };
177
+ active: boolean;
178
+ customized: boolean;
179
+ entityId?: string | undefined;
180
+ description?: string | undefined;
181
+ inheritedFrom?: NotificationTemplateId | undefined;
182
+ }, {
183
+ userId: string;
184
+ entityType: "agenda" | "inbox" | "tasks" | "habits" | "agenda_item" | "task_list" | "task" | "habit" | "agenda_defaults" | "tasks_defaults" | "habits_defaults";
185
+ name: string;
186
+ trigger: {
187
+ type: "time_based" | "event_based" | "recurring";
188
+ conditions: Record<string, any>;
189
+ timing: Record<string, any>;
190
+ };
191
+ content: {
192
+ title: string;
193
+ body: string;
194
+ variables?: Record<string, string> | undefined;
195
+ };
196
+ entityId?: string | undefined;
197
+ description?: string | undefined;
198
+ active?: boolean | undefined;
199
+ inheritedFrom?: string | undefined;
200
+ customized?: boolean | undefined;
201
+ }>;
202
+ export type CreateNotificationTemplateData = z.infer<typeof createNotificationTemplateSchema>;
203
+ export declare const entitySyncStateSchema: z.ZodObject<{
204
+ userId: z.ZodEffects<z.ZodString, UserId, string>;
205
+ entityType: z.ZodEnum<["agenda", "tasks", "habits", "inbox", "agenda_item", "task_list", "task", "habit", "agenda_defaults", "tasks_defaults", "habits_defaults"]>;
206
+ entityId: z.ZodString;
207
+ synced: z.ZodDefault<z.ZodBoolean>;
208
+ updatedAt: z.ZodDate;
209
+ }, "strip", z.ZodTypeAny, {
210
+ updatedAt: Date;
211
+ userId: string & {
212
+ readonly __brand: "UserId";
213
+ };
214
+ entityType: "agenda" | "inbox" | "tasks" | "habits" | "agenda_item" | "task_list" | "task" | "habit" | "agenda_defaults" | "tasks_defaults" | "habits_defaults";
215
+ entityId: string;
216
+ synced: boolean;
217
+ }, {
218
+ updatedAt: Date;
219
+ userId: string;
220
+ entityType: "agenda" | "inbox" | "tasks" | "habits" | "agenda_item" | "task_list" | "task" | "habit" | "agenda_defaults" | "tasks_defaults" | "habits_defaults";
221
+ entityId: string;
222
+ synced?: boolean | undefined;
223
+ }>;
224
+ export type EntitySyncState = z.infer<typeof entitySyncStateSchema>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.entitySyncStateSchema = exports.createNotificationTemplateSchema = exports.notificationTemplateDataSchema = exports.notificationContentSchema = exports.notificationTriggerSchema = exports.notificationTriggerTypeSchema = exports.notificationEntityTypeSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.notificationEntityTypeSchema = zod_1.z.enum([
6
+ // Individual entity types (notifications FOR the entity itself)
7
+ 'agenda', 'tasks', 'habits', 'inbox',
8
+ 'agenda_item', 'task_list', 'task', 'habit',
9
+ // Parent template types (default templates for children)
10
+ 'agenda_defaults', 'tasks_defaults', 'habits_defaults'
11
+ ]);
12
+ exports.notificationTriggerTypeSchema = zod_1.z.enum(['time_based', 'event_based', 'recurring']);
13
+ exports.notificationTriggerSchema = zod_1.z.object({
14
+ type: exports.notificationTriggerTypeSchema,
15
+ conditions: zod_1.z.record(zod_1.z.any()), // flexible conditions object
16
+ timing: zod_1.z.record(zod_1.z.any()) // timing configuration like "5 minutes before due"
17
+ });
18
+ exports.notificationContentSchema = zod_1.z.object({
19
+ title: zod_1.z.string(),
20
+ body: zod_1.z.string(),
21
+ // Support for template variables like {{entity.name}}
22
+ variables: zod_1.z.record(zod_1.z.string()).optional()
23
+ });
24
+ exports.notificationTemplateDataSchema = zod_1.z.object({
25
+ _id: zod_1.z.string().transform((val) => val),
26
+ userId: zod_1.z.string().transform((val) => val),
27
+ entityType: exports.notificationEntityTypeSchema,
28
+ entityId: zod_1.z.string().optional(), // null/undefined for panel-level templates
29
+ name: zod_1.z.string(),
30
+ description: zod_1.z.string().optional(),
31
+ trigger: exports.notificationTriggerSchema,
32
+ content: exports.notificationContentSchema,
33
+ active: zod_1.z.boolean().default(true),
34
+ inheritedFrom: zod_1.z.string().transform((val) => val).optional(),
35
+ customized: zod_1.z.boolean().default(false), // true if user modified inherited template
36
+ createdAt: zod_1.z.date(),
37
+ updatedAt: zod_1.z.date()
38
+ });
39
+ // Helper type for creating new templates (without _id, dates)
40
+ exports.createNotificationTemplateSchema = exports.notificationTemplateDataSchema.omit({
41
+ _id: true,
42
+ createdAt: true,
43
+ updatedAt: true
44
+ });
45
+ // Entity sync state for inheritance
46
+ exports.entitySyncStateSchema = zod_1.z.object({
47
+ userId: zod_1.z.string().transform((val) => val),
48
+ entityType: exports.notificationEntityTypeSchema,
49
+ entityId: zod_1.z.string(),
50
+ synced: zod_1.z.boolean().default(true), // true = inheriting from parent, false = has custom templates
51
+ updatedAt: zod_1.z.date()
52
+ });
@@ -95,13 +95,13 @@ export declare const userDataSchema: z.ZodObject<{
95
95
  };
96
96
  createdAt: Date;
97
97
  updatedAt: Date;
98
+ name: string;
98
99
  sandbox: {
99
100
  devices: {
100
101
  pushToken: string;
101
102
  }[];
102
103
  discordId?: string | undefined;
103
104
  };
104
- name: string;
105
105
  timezone: string;
106
106
  config: {
107
107
  agenda: {
@@ -120,13 +120,13 @@ export declare const userDataSchema: z.ZodObject<{
120
120
  _id: string;
121
121
  createdAt: Date;
122
122
  updatedAt: Date;
123
+ name: string;
123
124
  sandbox: {
124
125
  devices: {
125
126
  pushToken: string;
126
127
  }[];
127
128
  discordId?: string | undefined;
128
129
  };
129
- name: string;
130
130
  timezone: string;
131
131
  config: {
132
132
  agenda: {
@@ -1,4 +1,4 @@
1
- import { Habit, HabitData, HabitEntry, HabitEntryData, ItemData, Person, PersonData, PersonNoteData, TaskData, TaskListData, ThoughtData, UserData } from "../types";
1
+ import { Habit, HabitData, HabitEntry, HabitEntryData, ItemData, Person, PersonData, PersonNoteData, NotificationTemplateData, NotificationInstanceData, TaskData, TaskListData, ThoughtData, UserData } from "../types";
2
2
  export type Serialized<T> = T extends Date ? string : T extends Date | undefined ? string | undefined : T extends Date | null ? string | null : T extends (infer U)[] ? Serialized<U>[] : T extends object ? {
3
3
  [K in keyof T]: Serialized<T[K]>;
4
4
  } : T;
@@ -29,4 +29,8 @@ export declare class Serializer {
29
29
  static deserializeThoughtData(data: Serialized<ThoughtData>): ThoughtData;
30
30
  static serializeUserData(data: UserData): Serialized<UserData>;
31
31
  static deserializeUserData(data: Serialized<UserData>): UserData;
32
+ static serializeNotificationTemplateData(data: NotificationTemplateData): Serialized<NotificationTemplateData>;
33
+ static deserializeNotificationTemplateData(data: Serialized<NotificationTemplateData>): NotificationTemplateData;
34
+ static serializeNotificationInstanceData(data: NotificationInstanceData): Serialized<NotificationInstanceData>;
35
+ static deserializeNotificationInstanceData(data: Serialized<NotificationInstanceData>): NotificationInstanceData;
32
36
  }
@@ -80,6 +80,18 @@ class Serializer {
80
80
  static deserializeUserData(data) {
81
81
  return this.deserialize(data);
82
82
  }
83
+ static serializeNotificationTemplateData(data) {
84
+ return this.serialize(data);
85
+ }
86
+ static deserializeNotificationTemplateData(data) {
87
+ return this.deserialize(data);
88
+ }
89
+ static serializeNotificationInstanceData(data) {
90
+ return this.serialize(data);
91
+ }
92
+ static deserializeNotificationInstanceData(data) {
93
+ return this.deserialize(data);
94
+ }
83
95
  }
84
96
  exports.Serializer = Serializer;
85
97
  function serializeRecursive(obj) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@timothyw/pat-common",
3
3
  "description": "",
4
4
  "author": "Timothy Washburn",
5
- "version": "1.0.101",
5
+ "version": "1.0.103",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
@@ -5,5 +5,6 @@ export enum ModuleType {
5
5
  HABITS = 'habits',
6
6
  PEOPLE = 'people',
7
7
  SETTINGS = 'settings',
8
+ NOTIFICATIONS = 'notifications',
8
9
  DEV = 'dev'
9
10
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { UserId } from "../../id-types";
2
3
 
3
4
  export const createAccountRequestSchema = z.object({
4
5
  name: z.string().trim().min(1),
@@ -10,7 +11,7 @@ export const createAccountRequestSchema = z.object({
10
11
  export type CreateAccountRequest = z.infer<typeof createAccountRequestSchema>;
11
12
 
12
13
  export interface CreateAccountResponse {
13
- id: string;
14
+ id: UserId;
14
15
  name: string;
15
16
  email: string;
16
17
  }
@@ -3,6 +3,7 @@ export * from './auth'
3
3
  export * from './habits'
4
4
  export * from './items'
5
5
  export * from './misc'
6
+ export * from './notifications'
6
7
  export * from './people'
7
8
  export * from './tasks'
8
9
  export * from './thoughts'