@timothyw/pat-common 1.0.121 → 1.0.123

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.
@@ -0,0 +1,78 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Static parent resolver - entity always inherits from the same parent type
5
+ */
6
+ export interface StaticParentResolver {
7
+ type: 'static';
8
+ parentType: string;
9
+ }
10
+
11
+ /**
12
+ * Dynamic parent resolver - parent determined by entity properties
13
+ */
14
+ export interface DynamicParentResolver {
15
+ type: 'dynamic';
16
+ parentProperty: string; // Property name on entity (e.g., 'category')
17
+ parentTypePrefix: string; // Prefix for parent type (e.g., 'agenda_category_')
18
+ fallbackParent: string; // Default parent if property is missing/empty
19
+ }
20
+
21
+ export type ParentResolver = StaticParentResolver | DynamicParentResolver;
22
+
23
+ /**
24
+ * Configuration for a notification entity type
25
+ */
26
+ export interface NotificationEntityConfig {
27
+ entityType: string;
28
+ parentResolver: ParentResolver;
29
+ displayName: string;
30
+ icon?: string;
31
+ description?: string;
32
+ }
33
+
34
+ /**
35
+ * Result of parent resolution for a specific entity instance
36
+ */
37
+ export interface ParentResolutionResult {
38
+ parentType: string;
39
+ isDynamic: boolean;
40
+ resolvedProperty?: string;
41
+ usedFallback?: boolean;
42
+ }
43
+
44
+ /**
45
+ * Zod schemas for validation
46
+ */
47
+ export const staticParentResolverSchema = z.object({
48
+ type: z.literal('static'),
49
+ parentType: z.string()
50
+ });
51
+
52
+ export const dynamicParentResolverSchema = z.object({
53
+ type: z.literal('dynamic'),
54
+ parentProperty: z.string(),
55
+ parentTypePrefix: z.string(),
56
+ fallbackParent: z.string()
57
+ });
58
+
59
+ export const parentResolverSchema = z.union([
60
+ staticParentResolverSchema,
61
+ dynamicParentResolverSchema
62
+ ]);
63
+
64
+ export const notificationEntityConfigSchema = z.object({
65
+ entityType: z.string(),
66
+ parentResolver: parentResolverSchema,
67
+ displayName: z.string(),
68
+ icon: z.string().optional(),
69
+ description: z.string().optional()
70
+ });
71
+
72
+ /**
73
+ * Type exports
74
+ */
75
+ export type StaticParentResolverData = z.infer<typeof staticParentResolverSchema>;
76
+ export type DynamicParentResolverData = z.infer<typeof dynamicParentResolverSchema>;
77
+ export type ParentResolverData = z.infer<typeof parentResolverSchema>;
78
+ export type NotificationEntityConfigData = z.infer<typeof notificationEntityConfigSchema>;
@@ -4,23 +4,32 @@ import { Serialized } from '../utils';
4
4
 
5
5
  export interface NotificationContext<T = any> {
6
6
  entityId: string;
7
- entityType: NotificationEntityType;
7
+ entityType: string;
8
8
  entityData: T;
9
9
  userId: string;
10
10
  variables: Record<string, any>;
11
11
  }
12
12
 
13
+ /**
14
+ * @deprecated Use string types with NotificationEntityRegistry instead
15
+ * These enums are kept for backward compatibility during migration
16
+ */
13
17
  export enum NotificationParentType {
14
18
  AGENDA_PANEL = 'agenda_panel',
15
19
  }
16
20
 
21
+ /**
22
+ * @deprecated Use string types with NotificationEntityRegistry instead
23
+ * These enums are kept for backward compatibility during migration
24
+ */
17
25
  export enum NotificationEntityType {
18
26
  INBOX_PANEL = 'inbox_panel',
19
- AGENDA_PANEL = 'agenda_item',
27
+ AGENDA_PANEL = 'agenda_panel',
20
28
  AGENDA_ITEM = 'agenda_item',
21
29
  }
22
30
 
23
- export const notificationEntityTypeSchema = z.nativeEnum(NotificationEntityType);
31
+ // Updated to use string instead of enum
32
+ export const notificationEntityTypeSchema = z.string();
24
33
 
25
34
  export enum NotificationStatus {
26
35
  SCHEDULED = 'scheduled',
@@ -46,8 +55,7 @@ export const notificationTriggerSchema = z.object({
46
55
 
47
56
  export const notificationContentSchema = z.object({
48
57
  title: z.string(),
49
- body: z.string(),
50
- variables: z.record(z.string()).optional()
58
+ body: z.string()
51
59
  });
52
60
 
53
61
  export const notificationTemplateSchema = z.object({
@@ -60,8 +68,6 @@ export const notificationTemplateSchema = z.object({
60
68
  trigger: notificationTriggerSchema,
61
69
  content: notificationContentSchema,
62
70
  active: z.boolean(),
63
- inheritedFrom: notificationTemplateIdSchema.optional(),
64
- customized: z.boolean(),
65
71
  createdAt: z.date(),
66
72
  updatedAt: z.date()
67
73
  });
@@ -111,12 +117,9 @@ export const createNotificationTemplateRequestSchema = z.object({
111
117
  }),
112
118
  content: z.object({
113
119
  title: z.string().min(1).max(200),
114
- body: z.string().min(1).max(1000),
115
- variables: z.record(z.string()).optional()
120
+ body: z.string().min(1).max(1000)
116
121
  }),
117
- active: z.boolean().default(true),
118
- inheritedFrom: z.string().optional(),
119
- customized: z.boolean().default(false)
122
+ active: z.boolean().default(true)
120
123
  });
121
124
 
122
125
  export const updateNotificationTemplateRequestSchema = z.object({
@@ -129,11 +132,9 @@ export const updateNotificationTemplateRequestSchema = z.object({
129
132
  }).optional(),
130
133
  content: z.object({
131
134
  title: z.string(),
132
- body: z.string(),
133
- variables: z.record(z.string()).optional()
135
+ body: z.string()
134
136
  }).optional(),
135
- active: z.boolean().optional(),
136
- customized: z.boolean().optional()
137
+ active: z.boolean().optional()
137
138
  });
138
139
 
139
140
  export const syncNotificationTemplateRequestSchema = z.object({
@@ -144,8 +145,7 @@ export const previewNotificationTemplateRequestSchema = z.object({
144
145
  templateTitle: z.string(),
145
146
  templateBody: z.string(),
146
147
  entityType: z.string(),
147
- entityId: z.string(),
148
- variables: z.record(z.any()).optional()
148
+ entityId: z.string()
149
149
  });
150
150
 
151
151
  export const getNotificationInstancesRequestSchema = z.object({
@@ -208,9 +208,7 @@ export interface PreviewNotificationTemplateResponse {
208
208
  preview: {
209
209
  title: string;
210
210
  body: string;
211
- variables: Record<string, any>;
212
211
  };
213
- missingVariables: string[];
214
212
  }
215
213
 
216
214
  export interface GetNotificationInstancesResponse {