evo360-types 1.3.143 → 1.3.144

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,144 @@
1
+ import type { FirestoreDocumentReference, IFireDoc } from "../shared";
2
+ export declare const EvoNotificationsCollections: {
3
+ readonly Messages: "messages";
4
+ readonly Attempts: "attempts";
5
+ readonly Logs: "logs";
6
+ };
7
+ export type EvoNotificationsCollectionName = (typeof EvoNotificationsCollections)[keyof typeof EvoNotificationsCollections];
8
+ export declare const NotificationTaskKindEnum: {
9
+ readonly Send: "notification.send";
10
+ };
11
+ export type NotificationTaskKind = (typeof NotificationTaskKindEnum)[keyof typeof NotificationTaskKindEnum];
12
+ export declare const NotificationsTopics: {
13
+ readonly ExecuteRequests: "notifications.execute_requests";
14
+ readonly ExecutionReports: "notifications.execution_reports";
15
+ readonly ProviderWebhooks: "notifications.provider_webhooks";
16
+ };
17
+ export type NotificationsTopic = (typeof NotificationsTopics)[keyof typeof NotificationsTopics];
18
+ export declare const NotificationChannelTypeEnum: {
19
+ readonly WhatsApp: "whatsapp";
20
+ readonly Email: "email";
21
+ readonly SMS: "sms";
22
+ readonly Push: "push";
23
+ };
24
+ export type NotificationChannelType = (typeof NotificationChannelTypeEnum)[keyof typeof NotificationChannelTypeEnum];
25
+ export declare const NotificationMessageStatusEnum: {
26
+ readonly Queued: "queued";
27
+ readonly Processing: "processing";
28
+ readonly Sent: "sent";
29
+ readonly Delivered: "delivered";
30
+ readonly Failed: "failed";
31
+ readonly Cancelled: "cancelled";
32
+ readonly Suppressed: "suppressed";
33
+ };
34
+ export type NotificationMessageStatus = (typeof NotificationMessageStatusEnum)[keyof typeof NotificationMessageStatusEnum];
35
+ export declare const NotificationAttemptStatusEnum: {
36
+ readonly Success: "success";
37
+ readonly Retry: "retry";
38
+ readonly Error: "error";
39
+ };
40
+ export type NotificationAttemptStatus = (typeof NotificationAttemptStatusEnum)[keyof typeof NotificationAttemptStatusEnum];
41
+ export declare const NotificationRecipientKindEnum: {
42
+ readonly Patient: "patient";
43
+ readonly Professional: "professional";
44
+ readonly Preconfigured: "preconfigured";
45
+ readonly Raw: "raw";
46
+ };
47
+ export type NotificationRecipientKind = (typeof NotificationRecipientKindEnum)[keyof typeof NotificationRecipientKindEnum];
48
+ export interface INotificationRecipient {
49
+ kind: NotificationRecipientKind;
50
+ id?: string;
51
+ ref?: FirestoreDocumentReference;
52
+ address?: string;
53
+ display_name?: string;
54
+ [key: string]: unknown;
55
+ }
56
+ export interface INotificationChannelRef {
57
+ type: NotificationChannelType;
58
+ channel_id: string;
59
+ sender_id?: string;
60
+ [key: string]: unknown;
61
+ }
62
+ export interface INotificationTemplateRef {
63
+ template_id: string;
64
+ locale?: string;
65
+ version?: number | string;
66
+ [key: string]: unknown;
67
+ }
68
+ export interface INotificationProviderMeta {
69
+ name?: string;
70
+ message_id?: string;
71
+ status?: string;
72
+ raw?: Record<string, unknown>;
73
+ [key: string]: unknown;
74
+ }
75
+ export interface INotificationError {
76
+ message: string;
77
+ code?: string | number;
78
+ details?: Record<string, unknown>;
79
+ [key: string]: unknown;
80
+ }
81
+ export interface INotificationSendPayload {
82
+ kind: "notification.send";
83
+ classification?: string;
84
+ importance?: number;
85
+ recipient: INotificationRecipient;
86
+ channel: INotificationChannelRef;
87
+ template?: INotificationTemplateRef;
88
+ variables?: Record<string, unknown>;
89
+ routine?: {
90
+ id: string;
91
+ version?: number | string;
92
+ [key: string]: unknown;
93
+ };
94
+ idempotency_key?: string;
95
+ dedup_key?: string;
96
+ dedup_group_key?: string;
97
+ [key: string]: unknown;
98
+ }
99
+ export interface INotificationMessage extends IFireDoc {
100
+ tenant: string;
101
+ task_id?: string;
102
+ routine_id?: string;
103
+ routine_version?: number | string;
104
+ classification?: string;
105
+ importance?: number;
106
+ channel: INotificationChannelRef;
107
+ template?: INotificationTemplateRef;
108
+ recipient: INotificationRecipient;
109
+ variables?: Record<string, unknown>;
110
+ status: NotificationMessageStatus;
111
+ queued_at: Date;
112
+ processing_started_at?: Date;
113
+ sent_at?: Date;
114
+ delivered_at?: Date;
115
+ completed_at?: Date;
116
+ provider?: INotificationProviderMeta;
117
+ error?: INotificationError;
118
+ dedup_key?: string;
119
+ dedup_group_key?: string;
120
+ date_bucket?: string;
121
+ [key: string]: unknown;
122
+ }
123
+ export interface INotificationAttempt extends IFireDoc {
124
+ message_id: string;
125
+ task_id?: string;
126
+ attempt: number;
127
+ status: NotificationAttemptStatus;
128
+ requested_at: Date;
129
+ started_at?: Date;
130
+ finished_at?: Date;
131
+ provider?: INotificationProviderMeta;
132
+ error?: INotificationError;
133
+ request_summary?: Record<string, unknown>;
134
+ response_summary?: Record<string, unknown>;
135
+ [key: string]: unknown;
136
+ }
137
+ export interface INotificationLog extends IFireDoc {
138
+ message_id: string;
139
+ level: "debug" | "info" | "warn" | "error";
140
+ message: string;
141
+ data?: Record<string, unknown>;
142
+ at: Date;
143
+ [key: string]: unknown;
144
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotificationRecipientKindEnum = exports.NotificationAttemptStatusEnum = exports.NotificationMessageStatusEnum = exports.NotificationChannelTypeEnum = exports.NotificationsTopics = exports.NotificationTaskKindEnum = exports.EvoNotificationsCollections = void 0;
4
+ // ======================================================
5
+ // evo-notifications
6
+ //
7
+ // Responsibilities (types only):
8
+ // - Define the notification execution payload schema (used by Task Runner)
9
+ // - Define persistence models for notification messages and attempts
10
+ // - Keep channel/provider details generic and extensible
11
+ //
12
+ // Firestore (per tenant):
13
+ // - Root app path: /tenants/{tenant}/apps/evo-notifications
14
+ // - Messages: /tenants/{tenant}/apps/evo-notifications/messages/{messageId}
15
+ // - Attempts: /tenants/{tenant}/apps/evo-notifications/messages/{messageId}/attempts/{attemptId}
16
+ // - Logs: /tenants/{tenant}/apps/evo-notifications/messages/{messageId}/logs/{logId}
17
+ // ======================================================
18
+ // ----- Firestore collections
19
+ exports.EvoNotificationsCollections = {
20
+ Messages: "messages",
21
+ Attempts: "attempts",
22
+ Logs: "logs",
23
+ };
24
+ // ----- Task Runner integration
25
+ exports.NotificationTaskKindEnum = {
26
+ Send: "notification.send",
27
+ };
28
+ // Logical Pub/Sub topic names (optional, but useful as shared constants)
29
+ exports.NotificationsTopics = {
30
+ ExecuteRequests: "notifications.execute_requests",
31
+ ExecutionReports: "notifications.execution_reports",
32
+ ProviderWebhooks: "notifications.provider_webhooks",
33
+ };
34
+ // ----- Channel types
35
+ exports.NotificationChannelTypeEnum = {
36
+ WhatsApp: "whatsapp",
37
+ Email: "email",
38
+ SMS: "sms",
39
+ Push: "push",
40
+ };
41
+ // ----- High-level message status (channel-agnostic)
42
+ exports.NotificationMessageStatusEnum = {
43
+ Queued: "queued", // created and waiting execution
44
+ Processing: "processing", // being handled by notifications service
45
+ Sent: "sent", // accepted by provider
46
+ Delivered: "delivered", // delivery confirmed (when supported)
47
+ Failed: "failed", // permanent failure
48
+ Cancelled: "cancelled",
49
+ Suppressed: "suppressed", // dedup/skip decision
50
+ };
51
+ // ----- Attempt status
52
+ exports.NotificationAttemptStatusEnum = {
53
+ Success: "success",
54
+ Retry: "retry",
55
+ Error: "error",
56
+ };
57
+ // ----- Recipient
58
+ exports.NotificationRecipientKindEnum = {
59
+ Patient: "patient",
60
+ Professional: "professional",
61
+ Preconfigured: "preconfigured",
62
+ Raw: "raw",
63
+ };
@@ -0,0 +1,261 @@
1
+ import type { FirestoreDocumentReference, IFireDoc } from "../shared";
2
+
3
+ // ======================================================
4
+ // evo-notifications
5
+ //
6
+ // Responsibilities (types only):
7
+ // - Define the notification execution payload schema (used by Task Runner)
8
+ // - Define persistence models for notification messages and attempts
9
+ // - Keep channel/provider details generic and extensible
10
+ //
11
+ // Firestore (per tenant):
12
+ // - Root app path: /tenants/{tenant}/apps/evo-notifications
13
+ // - Messages: /tenants/{tenant}/apps/evo-notifications/messages/{messageId}
14
+ // - Attempts: /tenants/{tenant}/apps/evo-notifications/messages/{messageId}/attempts/{attemptId}
15
+ // - Logs: /tenants/{tenant}/apps/evo-notifications/messages/{messageId}/logs/{logId}
16
+ // ======================================================
17
+
18
+ // ----- Firestore collections
19
+ export const EvoNotificationsCollections = {
20
+ Messages: "messages",
21
+ Attempts: "attempts",
22
+ Logs: "logs",
23
+ } as const;
24
+
25
+ export type EvoNotificationsCollectionName =
26
+ (typeof EvoNotificationsCollections)[keyof typeof EvoNotificationsCollections];
27
+
28
+ // ----- Task Runner integration
29
+ export const NotificationTaskKindEnum = {
30
+ Send: "notification.send",
31
+ } as const;
32
+
33
+ export type NotificationTaskKind =
34
+ (typeof NotificationTaskKindEnum)[keyof typeof NotificationTaskKindEnum];
35
+
36
+ // Logical Pub/Sub topic names (optional, but useful as shared constants)
37
+ export const NotificationsTopics = {
38
+ ExecuteRequests: "notifications.execute_requests",
39
+ ExecutionReports: "notifications.execution_reports",
40
+ ProviderWebhooks: "notifications.provider_webhooks",
41
+ } as const;
42
+
43
+ export type NotificationsTopic =
44
+ (typeof NotificationsTopics)[keyof typeof NotificationsTopics];
45
+
46
+ // ----- Channel types
47
+ export const NotificationChannelTypeEnum = {
48
+ WhatsApp: "whatsapp",
49
+ Email: "email",
50
+ SMS: "sms",
51
+ Push: "push",
52
+ } as const;
53
+
54
+ export type NotificationChannelType =
55
+ (typeof NotificationChannelTypeEnum)[keyof typeof NotificationChannelTypeEnum];
56
+
57
+ // ----- High-level message status (channel-agnostic)
58
+ export const NotificationMessageStatusEnum = {
59
+ Queued: "queued", // created and waiting execution
60
+ Processing: "processing", // being handled by notifications service
61
+ Sent: "sent", // accepted by provider
62
+ Delivered: "delivered", // delivery confirmed (when supported)
63
+ Failed: "failed", // permanent failure
64
+ Cancelled: "cancelled",
65
+ Suppressed: "suppressed", // dedup/skip decision
66
+ } as const;
67
+
68
+ export type NotificationMessageStatus =
69
+ (typeof NotificationMessageStatusEnum)[keyof typeof NotificationMessageStatusEnum];
70
+
71
+ // ----- Attempt status
72
+ export const NotificationAttemptStatusEnum = {
73
+ Success: "success",
74
+ Retry: "retry",
75
+ Error: "error",
76
+ } as const;
77
+
78
+ export type NotificationAttemptStatus =
79
+ (typeof NotificationAttemptStatusEnum)[keyof typeof NotificationAttemptStatusEnum];
80
+
81
+ // ----- Recipient
82
+ export const NotificationRecipientKindEnum = {
83
+ Patient: "patient",
84
+ Professional: "professional",
85
+ Preconfigured: "preconfigured",
86
+ Raw: "raw",
87
+ } as const;
88
+
89
+ export type NotificationRecipientKind =
90
+ (typeof NotificationRecipientKindEnum)[keyof typeof NotificationRecipientKindEnum];
91
+
92
+ export interface INotificationRecipient {
93
+ kind: NotificationRecipientKind;
94
+
95
+ // Internal references (optional)
96
+ id?: string; // patientId/professionalId/etc.
97
+ ref?: FirestoreDocumentReference;
98
+
99
+ // Destination address (required for kind=raw, may also be filled for others)
100
+ // - whatsapp/sms: E.164 phone
101
+ // - email: email address
102
+ // - push: device token or topic
103
+ address?: string;
104
+
105
+ // Display helpers
106
+ display_name?: string;
107
+
108
+ [key: string]: unknown;
109
+ }
110
+
111
+ // ----- Channel reference (points to CHAT module configuration)
112
+ export interface INotificationChannelRef {
113
+ type: NotificationChannelType;
114
+ channel_id: string; // reference to channel config in CHAT module
115
+ sender_id?: string; // optional (e.g., whatsapp business number, email sender id)
116
+ [key: string]: unknown;
117
+ }
118
+
119
+ // ----- Template reference
120
+ export interface INotificationTemplateRef {
121
+ template_id: string; // HSM template id, email template id, push template id...
122
+ locale?: string;
123
+ version?: number | string;
124
+ [key: string]: unknown;
125
+ }
126
+
127
+ // ----- Provider metadata (generic)
128
+ export interface INotificationProviderMeta {
129
+ name?: string; // e.g., meta, twilio, sendgrid, firebase
130
+ message_id?: string; // provider-specific id
131
+ status?: string; // provider status string
132
+ raw?: Record<string, unknown>; // sanitized provider response
133
+ [key: string]: unknown;
134
+ }
135
+
136
+ // ----- Error model
137
+ export interface INotificationError {
138
+ message: string;
139
+ code?: string | number;
140
+ details?: Record<string, unknown>;
141
+ [key: string]: unknown;
142
+ }
143
+
144
+ // ======================================================
145
+ // Payload schema for Task Runner (task.auto.kind = "notification.send")
146
+ // ======================================================
147
+
148
+ export interface INotificationSendPayload {
149
+ kind: "notification.send";
150
+
151
+ // Classification/category is useful for UI filters and dedup grouping
152
+ classification?: string; // e.g. REMINDER, CSAT, BILLING, SYSTEM
153
+ importance?: number; // 0-100 tie-breaker
154
+
155
+ // Destination + channel
156
+ recipient: INotificationRecipient;
157
+ channel: INotificationChannelRef;
158
+
159
+ // Template and variables
160
+ template?: INotificationTemplateRef;
161
+ variables?: Record<string, unknown>; // resolved upstream (Automation Hub / Task Runner)
162
+
163
+ // Optional business context
164
+ routine?: {
165
+ id: string;
166
+ version?: number | string;
167
+ [key: string]: unknown;
168
+ };
169
+
170
+ // Idempotency for provider send (for the same attempt)
171
+ idempotency_key?: string;
172
+
173
+ // Optional dedup keys (mirrors Task dedup; helpful when writing message docs)
174
+ dedup_key?: string;
175
+ dedup_group_key?: string;
176
+
177
+ [key: string]: unknown;
178
+ }
179
+
180
+ // ======================================================
181
+ // Persistence models
182
+ // ======================================================
183
+
184
+ // A persisted notification message represents the execution of a task in this module.
185
+ // It should be easily listable/filterable in the UI.
186
+ export interface INotificationMessage extends IFireDoc {
187
+ tenant: string;
188
+
189
+ // Link back to the originating task
190
+ task_id?: string;
191
+
192
+ // Optional routine context
193
+ routine_id?: string;
194
+ routine_version?: number | string;
195
+
196
+ // Classification and importance for filtering
197
+ classification?: string;
198
+ importance?: number;
199
+
200
+ // Channel/template snapshot
201
+ channel: INotificationChannelRef;
202
+ template?: INotificationTemplateRef;
203
+
204
+ // Recipient snapshot
205
+ recipient: INotificationRecipient;
206
+
207
+ // Variables snapshot (avoid storing sensitive info when possible)
208
+ variables?: Record<string, unknown>;
209
+
210
+ // Status tracking
211
+ status: NotificationMessageStatus;
212
+ queued_at: Date;
213
+ processing_started_at?: Date;
214
+ sent_at?: Date;
215
+ delivered_at?: Date;
216
+ completed_at?: Date;
217
+
218
+ // Final outcome
219
+ provider?: INotificationProviderMeta;
220
+ error?: INotificationError;
221
+
222
+ // Dedup helpers
223
+ dedup_key?: string;
224
+ dedup_group_key?: string;
225
+
226
+ // Indexing helpers (optional)
227
+ date_bucket?: string; // e.g., YYYY-MM-DD (tenant timezone)
228
+
229
+ [key: string]: unknown;
230
+ }
231
+
232
+ // Each send attempt is stored in a sub-collection to keep the message list lightweight.
233
+ export interface INotificationAttempt extends IFireDoc {
234
+ message_id: string;
235
+ task_id?: string;
236
+
237
+ attempt: number; // 0-based
238
+ status: NotificationAttemptStatus;
239
+
240
+ requested_at: Date;
241
+ started_at?: Date;
242
+ finished_at?: Date;
243
+
244
+ provider?: INotificationProviderMeta;
245
+ error?: INotificationError;
246
+
247
+ // Sanitized request/response summaries (never store secrets)
248
+ request_summary?: Record<string, unknown>;
249
+ response_summary?: Record<string, unknown>;
250
+
251
+ [key: string]: unknown;
252
+ }
253
+
254
+ export interface INotificationLog extends IFireDoc {
255
+ message_id: string;
256
+ level: "debug" | "info" | "warn" | "error";
257
+ message: string;
258
+ data?: Record<string, unknown>;
259
+ at: Date;
260
+ [key: string]: unknown;
261
+ }