@voyant-travel/notifications 0.111.7

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 (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +179 -0
  3. package/dist/index.d.ts +61 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +196 -0
  6. package/dist/liquid.d.ts +5 -0
  7. package/dist/liquid.d.ts.map +1 -0
  8. package/dist/liquid.js +156 -0
  9. package/dist/providers/local.d.ts +22 -0
  10. package/dist/providers/local.d.ts.map +1 -0
  11. package/dist/providers/local.js +23 -0
  12. package/dist/providers/voyant-cloud-email.d.ts +27 -0
  13. package/dist/providers/voyant-cloud-email.d.ts.map +1 -0
  14. package/dist/providers/voyant-cloud-email.js +73 -0
  15. package/dist/providers/voyant-cloud-sms.d.ts +26 -0
  16. package/dist/providers/voyant-cloud-sms.d.ts.map +1 -0
  17. package/dist/providers/voyant-cloud-sms.js +24 -0
  18. package/dist/routes.d.ts +1546 -0
  19. package/dist/routes.d.ts.map +1 -0
  20. package/dist/routes.js +337 -0
  21. package/dist/schema.d.ts +2119 -0
  22. package/dist/schema.d.ts.map +1 -0
  23. package/dist/schema.js +356 -0
  24. package/dist/service-booking-document-lifecycle.d.ts +99 -0
  25. package/dist/service-booking-document-lifecycle.d.ts.map +1 -0
  26. package/dist/service-booking-document-lifecycle.js +259 -0
  27. package/dist/service-booking-documents.d.ts +256 -0
  28. package/dist/service-booking-documents.d.ts.map +1 -0
  29. package/dist/service-booking-documents.js +323 -0
  30. package/dist/service-deliveries.d.ts +183 -0
  31. package/dist/service-deliveries.d.ts.map +1 -0
  32. package/dist/service-deliveries.js +413 -0
  33. package/dist/service-delivery-metadata.d.ts +42 -0
  34. package/dist/service-delivery-metadata.d.ts.map +1 -0
  35. package/dist/service-delivery-metadata.js +114 -0
  36. package/dist/service-reminder-authoring.d.ts +33 -0
  37. package/dist/service-reminder-authoring.d.ts.map +1 -0
  38. package/dist/service-reminder-authoring.js +247 -0
  39. package/dist/service-reminder-booking-context.d.ts +94 -0
  40. package/dist/service-reminder-booking-context.d.ts.map +1 -0
  41. package/dist/service-reminder-booking-context.js +164 -0
  42. package/dist/service-reminder-events.d.ts +33 -0
  43. package/dist/service-reminder-events.d.ts.map +1 -0
  44. package/dist/service-reminder-events.js +178 -0
  45. package/dist/service-reminder-run-state.d.ts +114 -0
  46. package/dist/service-reminder-run-state.d.ts.map +1 -0
  47. package/dist/service-reminder-run-state.js +100 -0
  48. package/dist/service-reminder-stage-runs.d.ts +6 -0
  49. package/dist/service-reminder-stage-runs.d.ts.map +1 -0
  50. package/dist/service-reminder-stage-runs.js +310 -0
  51. package/dist/service-reminders.d.ts +30 -0
  52. package/dist/service-reminders.d.ts.map +1 -0
  53. package/dist/service-reminders.js +189 -0
  54. package/dist/service-sequence-targets.d.ts +50 -0
  55. package/dist/service-sequence-targets.d.ts.map +1 -0
  56. package/dist/service-sequence-targets.js +136 -0
  57. package/dist/service-sequence.d.ts +68 -0
  58. package/dist/service-sequence.d.ts.map +1 -0
  59. package/dist/service-sequence.js +316 -0
  60. package/dist/service-shared.d.ts +107 -0
  61. package/dist/service-shared.d.ts.map +1 -0
  62. package/dist/service-shared.js +159 -0
  63. package/dist/service-stages.d.ts +23 -0
  64. package/dist/service-stages.d.ts.map +1 -0
  65. package/dist/service-stages.js +203 -0
  66. package/dist/service-template-data.d.ts +19 -0
  67. package/dist/service-template-data.d.ts.map +1 -0
  68. package/dist/service-template-data.js +278 -0
  69. package/dist/service-templates.d.ts +260 -0
  70. package/dist/service-templates.d.ts.map +1 -0
  71. package/dist/service-templates.js +293 -0
  72. package/dist/service.d.ts +273 -0
  73. package/dist/service.d.ts.map +1 -0
  74. package/dist/service.js +51 -0
  75. package/dist/task-runtime.d.ts +19 -0
  76. package/dist/task-runtime.d.ts.map +1 -0
  77. package/dist/task-runtime.js +11 -0
  78. package/dist/tasks/deliver-reminder.d.ts +9 -0
  79. package/dist/tasks/deliver-reminder.d.ts.map +1 -0
  80. package/dist/tasks/deliver-reminder.js +12 -0
  81. package/dist/tasks/index.d.ts +3 -0
  82. package/dist/tasks/index.d.ts.map +1 -0
  83. package/dist/tasks/index.js +2 -0
  84. package/dist/tasks/send-due-reminders.d.ts +7 -0
  85. package/dist/tasks/send-due-reminders.d.ts.map +1 -0
  86. package/dist/tasks/send-due-reminders.js +31 -0
  87. package/dist/template-authoring.d.ts +23 -0
  88. package/dist/template-authoring.d.ts.map +1 -0
  89. package/dist/template-authoring.js +386 -0
  90. package/dist/types.d.ts +82 -0
  91. package/dist/types.d.ts.map +1 -0
  92. package/dist/types.js +1 -0
  93. package/dist/validation.d.ts +1093 -0
  94. package/dist/validation.d.ts.map +1 -0
  95. package/dist/validation.js +451 -0
  96. package/package.json +102 -0
@@ -0,0 +1,293 @@
1
+ import { and, desc, eq, ilike, or, sql } from "drizzle-orm";
2
+ import { notificationDeliveries, notificationReminderRules, notificationReminderRuns, notificationTemplates, } from "./schema.js";
3
+ import { buildWhereClause, paginate } from "./service-shared.js";
4
+ function normalizeDateTime(value) {
5
+ if (!value)
6
+ return null;
7
+ return value instanceof Date ? value.toISOString() : value;
8
+ }
9
+ function normalizeReminderRun(row) {
10
+ return {
11
+ id: row.id,
12
+ reminderRuleId: row.reminderRuleId,
13
+ targetType: row.targetType,
14
+ targetId: row.targetId,
15
+ dedupeKey: row.dedupeKey,
16
+ status: row.status,
17
+ recipient: row.recipient ?? null,
18
+ scheduledFor: normalizeDateTime(row.scheduledFor),
19
+ processedAt: normalizeDateTime(row.processedAt),
20
+ errorMessage: row.errorMessage ?? null,
21
+ metadata: row.metadata ?? null,
22
+ createdAt: normalizeDateTime(row.createdAt),
23
+ updatedAt: normalizeDateTime(row.updatedAt),
24
+ links: {
25
+ bookingId: row.bookingId ?? null,
26
+ bookingPaymentScheduleId: row.targetType === "booking_payment_schedule" ? row.targetId : null,
27
+ invoiceId: row.targetType === "invoice" ? row.targetId : null,
28
+ paymentSessionId: row.paymentSessionId ?? null,
29
+ personId: row.personId ?? null,
30
+ organizationId: row.organizationId ?? null,
31
+ notificationDeliveryId: row.notificationDeliveryId ?? null,
32
+ },
33
+ reminderRule: {
34
+ id: row.reminderRuleId,
35
+ slug: row.ruleSlug,
36
+ name: row.ruleName,
37
+ status: row.ruleStatus,
38
+ targetType: row.ruleTargetType,
39
+ channel: row.ruleChannel,
40
+ provider: row.ruleProvider ?? null,
41
+ templateId: row.ruleTemplateId ?? null,
42
+ templateSlug: row.ruleTemplateSlug ?? null,
43
+ },
44
+ delivery: row.deliveryId &&
45
+ row.deliveryStatus &&
46
+ row.deliveryChannel &&
47
+ row.deliveryProvider &&
48
+ row.toAddress
49
+ ? {
50
+ id: row.deliveryId,
51
+ status: row.deliveryStatus,
52
+ channel: row.deliveryChannel,
53
+ provider: row.deliveryProvider,
54
+ toAddress: row.toAddress,
55
+ subject: row.deliverySubject ?? null,
56
+ sentAt: normalizeDateTime(row.sentAt),
57
+ failedAt: normalizeDateTime(row.failedAt),
58
+ errorMessage: row.deliveryErrorMessage ?? null,
59
+ }
60
+ : null,
61
+ };
62
+ }
63
+ export async function listTemplates(db, query) {
64
+ const conditions = [];
65
+ if (query.channel)
66
+ conditions.push(eq(notificationTemplates.channel, query.channel));
67
+ if (query.provider)
68
+ conditions.push(eq(notificationTemplates.provider, query.provider));
69
+ if (query.status)
70
+ conditions.push(eq(notificationTemplates.status, query.status));
71
+ if (query.search) {
72
+ const term = `%${query.search}%`;
73
+ conditions.push(or(ilike(notificationTemplates.slug, term), ilike(notificationTemplates.name, term)));
74
+ }
75
+ const where = buildWhereClause(conditions);
76
+ return paginate(db
77
+ .select()
78
+ .from(notificationTemplates)
79
+ .where(where)
80
+ .limit(query.limit)
81
+ .offset(query.offset)
82
+ .orderBy(desc(notificationTemplates.updatedAt)), db.select({ total: sql `count(*)::int` }).from(notificationTemplates).where(where), query.limit, query.offset);
83
+ }
84
+ export async function getTemplateById(db, id) {
85
+ const [row] = await db
86
+ .select()
87
+ .from(notificationTemplates)
88
+ .where(eq(notificationTemplates.id, id))
89
+ .limit(1);
90
+ return row ?? null;
91
+ }
92
+ export async function getTemplateBySlug(db, slug) {
93
+ const [row] = await db
94
+ .select()
95
+ .from(notificationTemplates)
96
+ .where(eq(notificationTemplates.slug, slug))
97
+ .limit(1);
98
+ return row ?? null;
99
+ }
100
+ export async function createTemplate(db, data) {
101
+ const [row] = await db.insert(notificationTemplates).values(data).returning();
102
+ return row ?? null;
103
+ }
104
+ export async function updateTemplate(db, id, data) {
105
+ const [row] = await db
106
+ .update(notificationTemplates)
107
+ .set({ ...data, updatedAt: new Date() })
108
+ .where(eq(notificationTemplates.id, id))
109
+ .returning();
110
+ return row ?? null;
111
+ }
112
+ export async function deleteTemplate(db, id) {
113
+ const rows = await db
114
+ .delete(notificationTemplates)
115
+ .where(eq(notificationTemplates.id, id))
116
+ .returning({ id: notificationTemplates.id });
117
+ return rows.length > 0;
118
+ }
119
+ export async function listReminderRules(db, query) {
120
+ const conditions = [];
121
+ if (query.status)
122
+ conditions.push(eq(notificationReminderRules.status, query.status));
123
+ if (query.targetType)
124
+ conditions.push(eq(notificationReminderRules.targetType, query.targetType));
125
+ if (query.channel)
126
+ conditions.push(eq(notificationReminderRules.channel, query.channel));
127
+ if (query.search) {
128
+ const term = `%${query.search}%`;
129
+ conditions.push(or(ilike(notificationReminderRules.slug, term), ilike(notificationReminderRules.name, term)));
130
+ }
131
+ const where = buildWhereClause(conditions);
132
+ return paginate(db
133
+ .select()
134
+ .from(notificationReminderRules)
135
+ .where(where)
136
+ .limit(query.limit)
137
+ .offset(query.offset)
138
+ .orderBy(desc(notificationReminderRules.updatedAt)), db.select({ total: sql `count(*)::int` }).from(notificationReminderRules).where(where), query.limit, query.offset);
139
+ }
140
+ export async function getReminderRuleById(db, id) {
141
+ const [row] = await db
142
+ .select()
143
+ .from(notificationReminderRules)
144
+ .where(eq(notificationReminderRules.id, id))
145
+ .limit(1);
146
+ return row ?? null;
147
+ }
148
+ export async function createReminderRule(db, data) {
149
+ const [row] = await db.insert(notificationReminderRules).values(data).returning();
150
+ return row ?? null;
151
+ }
152
+ export async function updateReminderRule(db, id, data) {
153
+ const [row] = await db
154
+ .update(notificationReminderRules)
155
+ .set({ ...data, updatedAt: new Date() })
156
+ .where(eq(notificationReminderRules.id, id))
157
+ .returning();
158
+ return row ?? null;
159
+ }
160
+ export async function deleteReminderRule(db, id) {
161
+ const rows = await db
162
+ .delete(notificationReminderRules)
163
+ .where(eq(notificationReminderRules.id, id))
164
+ .returning({ id: notificationReminderRules.id });
165
+ return rows.length > 0;
166
+ }
167
+ export async function listReminderRuns(db, query) {
168
+ const conditions = [];
169
+ if (query.reminderRuleId) {
170
+ conditions.push(eq(notificationReminderRuns.reminderRuleId, query.reminderRuleId));
171
+ }
172
+ if (query.targetType)
173
+ conditions.push(eq(notificationReminderRuns.targetType, query.targetType));
174
+ if (query.targetId)
175
+ conditions.push(eq(notificationReminderRuns.targetId, query.targetId));
176
+ if (query.scheduleId) {
177
+ conditions.push(and(eq(notificationReminderRuns.targetType, "booking_payment_schedule"), eq(notificationReminderRuns.targetId, query.scheduleId)));
178
+ }
179
+ if (query.invoiceId) {
180
+ conditions.push(and(eq(notificationReminderRuns.targetType, "invoice"), eq(notificationReminderRuns.targetId, query.invoiceId)));
181
+ }
182
+ if (query.bookingId)
183
+ conditions.push(eq(notificationReminderRuns.bookingId, query.bookingId));
184
+ if (query.paymentSessionId) {
185
+ conditions.push(eq(notificationReminderRuns.paymentSessionId, query.paymentSessionId));
186
+ }
187
+ if (query.notificationDeliveryId) {
188
+ conditions.push(eq(notificationReminderRuns.notificationDeliveryId, query.notificationDeliveryId));
189
+ }
190
+ if (query.personId)
191
+ conditions.push(eq(notificationReminderRuns.personId, query.personId));
192
+ if (query.organizationId) {
193
+ conditions.push(eq(notificationReminderRuns.organizationId, query.organizationId));
194
+ }
195
+ if (query.recipient) {
196
+ conditions.push(eq(notificationReminderRuns.recipient, query.recipient));
197
+ }
198
+ if (query.status)
199
+ conditions.push(eq(notificationReminderRuns.status, query.status));
200
+ const where = buildWhereClause(conditions);
201
+ return paginate(db
202
+ .select({
203
+ id: notificationReminderRuns.id,
204
+ reminderRuleId: notificationReminderRuns.reminderRuleId,
205
+ targetType: notificationReminderRuns.targetType,
206
+ targetId: notificationReminderRuns.targetId,
207
+ dedupeKey: notificationReminderRuns.dedupeKey,
208
+ bookingId: notificationReminderRuns.bookingId,
209
+ personId: notificationReminderRuns.personId,
210
+ organizationId: notificationReminderRuns.organizationId,
211
+ paymentSessionId: notificationReminderRuns.paymentSessionId,
212
+ notificationDeliveryId: notificationReminderRuns.notificationDeliveryId,
213
+ status: notificationReminderRuns.status,
214
+ recipient: notificationReminderRuns.recipient,
215
+ scheduledFor: notificationReminderRuns.scheduledFor,
216
+ processedAt: notificationReminderRuns.processedAt,
217
+ errorMessage: notificationReminderRuns.errorMessage,
218
+ metadata: notificationReminderRuns.metadata,
219
+ createdAt: notificationReminderRuns.createdAt,
220
+ updatedAt: notificationReminderRuns.updatedAt,
221
+ ruleSlug: notificationReminderRules.slug,
222
+ ruleName: notificationReminderRules.name,
223
+ ruleStatus: notificationReminderRules.status,
224
+ ruleTargetType: notificationReminderRules.targetType,
225
+ ruleChannel: notificationReminderRules.channel,
226
+ ruleProvider: notificationReminderRules.provider,
227
+ ruleTemplateId: notificationReminderRules.templateId,
228
+ ruleTemplateSlug: notificationReminderRules.templateSlug,
229
+ deliveryId: notificationDeliveries.id,
230
+ deliveryStatus: notificationDeliveries.status,
231
+ deliveryChannel: notificationDeliveries.channel,
232
+ deliveryProvider: notificationDeliveries.provider,
233
+ toAddress: notificationDeliveries.toAddress,
234
+ deliverySubject: notificationDeliveries.subject,
235
+ sentAt: notificationDeliveries.sentAt,
236
+ failedAt: notificationDeliveries.failedAt,
237
+ deliveryErrorMessage: notificationDeliveries.errorMessage,
238
+ })
239
+ .from(notificationReminderRuns)
240
+ .innerJoin(notificationReminderRules, eq(notificationReminderRules.id, notificationReminderRuns.reminderRuleId))
241
+ .leftJoin(notificationDeliveries, eq(notificationDeliveries.id, notificationReminderRuns.notificationDeliveryId))
242
+ .where(where)
243
+ .limit(query.limit)
244
+ .offset(query.offset)
245
+ .orderBy(desc(notificationReminderRuns.createdAt))
246
+ .then((rows) => rows.map(normalizeReminderRun)), db.select({ total: sql `count(*)::int` }).from(notificationReminderRuns).where(where), query.limit, query.offset);
247
+ }
248
+ export async function getReminderRunById(db, id) {
249
+ const [row] = await db
250
+ .select({
251
+ id: notificationReminderRuns.id,
252
+ reminderRuleId: notificationReminderRuns.reminderRuleId,
253
+ targetType: notificationReminderRuns.targetType,
254
+ targetId: notificationReminderRuns.targetId,
255
+ dedupeKey: notificationReminderRuns.dedupeKey,
256
+ bookingId: notificationReminderRuns.bookingId,
257
+ personId: notificationReminderRuns.personId,
258
+ organizationId: notificationReminderRuns.organizationId,
259
+ paymentSessionId: notificationReminderRuns.paymentSessionId,
260
+ notificationDeliveryId: notificationReminderRuns.notificationDeliveryId,
261
+ status: notificationReminderRuns.status,
262
+ recipient: notificationReminderRuns.recipient,
263
+ scheduledFor: notificationReminderRuns.scheduledFor,
264
+ processedAt: notificationReminderRuns.processedAt,
265
+ errorMessage: notificationReminderRuns.errorMessage,
266
+ metadata: notificationReminderRuns.metadata,
267
+ createdAt: notificationReminderRuns.createdAt,
268
+ updatedAt: notificationReminderRuns.updatedAt,
269
+ ruleSlug: notificationReminderRules.slug,
270
+ ruleName: notificationReminderRules.name,
271
+ ruleStatus: notificationReminderRules.status,
272
+ ruleTargetType: notificationReminderRules.targetType,
273
+ ruleChannel: notificationReminderRules.channel,
274
+ ruleProvider: notificationReminderRules.provider,
275
+ ruleTemplateId: notificationReminderRules.templateId,
276
+ ruleTemplateSlug: notificationReminderRules.templateSlug,
277
+ deliveryId: notificationDeliveries.id,
278
+ deliveryStatus: notificationDeliveries.status,
279
+ deliveryChannel: notificationDeliveries.channel,
280
+ deliveryProvider: notificationDeliveries.provider,
281
+ toAddress: notificationDeliveries.toAddress,
282
+ deliverySubject: notificationDeliveries.subject,
283
+ sentAt: notificationDeliveries.sentAt,
284
+ failedAt: notificationDeliveries.failedAt,
285
+ deliveryErrorMessage: notificationDeliveries.errorMessage,
286
+ })
287
+ .from(notificationReminderRuns)
288
+ .innerJoin(notificationReminderRules, eq(notificationReminderRules.id, notificationReminderRuns.reminderRuleId))
289
+ .leftJoin(notificationDeliveries, eq(notificationDeliveries.id, notificationReminderRuns.notificationDeliveryId))
290
+ .where(eq(notificationReminderRuns.id, id))
291
+ .limit(1);
292
+ return row ? normalizeReminderRun(row) : null;
293
+ }
@@ -0,0 +1,273 @@
1
+ export { createDefaultBookingDocumentAttachment } from "./service-booking-documents.js";
2
+ export type { NotificationService } from "./service-shared.js";
3
+ export { createNotificationService, NotificationError, previewNotificationTemplate, renderNotificationTemplate, summarizeNotificationAttachments, } from "./service-shared.js";
4
+ import { createDefaultBookingDocumentAttachment } from "./service-booking-documents.js";
5
+ import { getDeliveryById, listDeliveries, resendDelivery, sendInvoiceNotification, sendNotification, sendPaymentSessionNotification } from "./service-deliveries.js";
6
+ import { composeNotificationReminderRule } from "./service-reminder-authoring.js";
7
+ import { runDueReminders } from "./service-reminders.js";
8
+ import { previewReminders } from "./service-sequence.js";
9
+ import { previewNotificationTemplate } from "./service-shared.js";
10
+ import { createReminderRuleStage, createStageChannel, deleteReminderRuleStage, deleteStageChannel, getNotificationSettingsRecord, getReminderRuleStageById, listReminderRuleStages, listStageChannels, reorderReminderRuleStages, updateReminderRuleStage, updateStageChannel, upsertNotificationSettings } from "./service-stages.js";
11
+ import { createReminderRule, createTemplate, deleteReminderRule, deleteTemplate, getReminderRuleById, getReminderRunById, getTemplateById, getTemplateBySlug, listReminderRules, listReminderRuns, listTemplates, updateReminderRule, updateTemplate } from "./service-templates.js";
12
+ export declare const notificationsService: {
13
+ listTemplates: typeof listTemplates;
14
+ getTemplateById: typeof getTemplateById;
15
+ getTemplateBySlug: typeof getTemplateBySlug;
16
+ createTemplate: typeof createTemplate;
17
+ updateTemplate: typeof updateTemplate;
18
+ deleteTemplate: typeof deleteTemplate;
19
+ previewNotificationTemplate: typeof previewNotificationTemplate;
20
+ listDeliveries: typeof listDeliveries;
21
+ getDeliveryById: typeof getDeliveryById;
22
+ resendDelivery: typeof resendDelivery;
23
+ sendNotification: typeof sendNotification;
24
+ listReminderRules: typeof listReminderRules;
25
+ getReminderRuleById: typeof getReminderRuleById;
26
+ getReminderRunById: typeof getReminderRunById;
27
+ createReminderRule: typeof createReminderRule;
28
+ composeNotificationReminderRule: typeof composeNotificationReminderRule;
29
+ updateReminderRule: typeof updateReminderRule;
30
+ deleteReminderRule: typeof deleteReminderRule;
31
+ listReminderRuns: typeof listReminderRuns;
32
+ runDueReminders: typeof runDueReminders;
33
+ previewReminders: typeof previewReminders;
34
+ listReminderRuleStages: typeof listReminderRuleStages;
35
+ getReminderRuleStageById: typeof getReminderRuleStageById;
36
+ createReminderRuleStage: typeof createReminderRuleStage;
37
+ updateReminderRuleStage: typeof updateReminderRuleStage;
38
+ deleteReminderRuleStage: typeof deleteReminderRuleStage;
39
+ reorderReminderRuleStages: typeof reorderReminderRuleStages;
40
+ listStageChannels: typeof listStageChannels;
41
+ createStageChannel: typeof createStageChannel;
42
+ updateStageChannel: typeof updateStageChannel;
43
+ deleteStageChannel: typeof deleteStageChannel;
44
+ getNotificationSettings: typeof getNotificationSettingsRecord;
45
+ upsertNotificationSettings: typeof upsertNotificationSettings;
46
+ sendPaymentSessionNotification: typeof sendPaymentSessionNotification;
47
+ sendInvoiceNotification: typeof sendInvoiceNotification;
48
+ listBookingDocumentBundle: (db: import("drizzle-orm/postgres-js").PostgresJsDatabase, bookingId: string) => Promise<{
49
+ bookingId: string;
50
+ documents: {
51
+ key: string;
52
+ source: "products" | "legal" | "finance";
53
+ documentType: "contract" | "invoice" | "proforma" | "brochure";
54
+ bookingId: string;
55
+ name: string;
56
+ createdAt: string;
57
+ contractId?: string | null | undefined;
58
+ invoiceId?: string | null | undefined;
59
+ attachmentId?: string | null | undefined;
60
+ renditionId?: string | null | undefined;
61
+ contractStatus?: string | null | undefined;
62
+ invoiceStatus?: string | null | undefined;
63
+ format?: string | null | undefined;
64
+ mimeType?: string | null | undefined;
65
+ storageKey?: string | null | undefined;
66
+ downloadUrl?: string | null | undefined;
67
+ language?: string | null | undefined;
68
+ metadata?: Record<string, unknown> | null | undefined;
69
+ }[];
70
+ } | null>;
71
+ sendBookingDocumentsNotification: (db: import("drizzle-orm/postgres-js").PostgresJsDatabase, dispatcher: import("./service-shared.js").NotificationService, bookingId: string, input: import("./service-shared.js").SendBookingDocumentsNotificationInput, runtime?: import("./service-booking-documents.js").SendBookingDocumentsRuntimeOptions) => Promise<{
72
+ status: "not_found";
73
+ bookingId?: undefined;
74
+ recipient?: undefined;
75
+ documents?: undefined;
76
+ delivery?: undefined;
77
+ } | {
78
+ status: "no_documents";
79
+ bookingId?: undefined;
80
+ recipient?: undefined;
81
+ documents?: undefined;
82
+ delivery?: undefined;
83
+ } | {
84
+ status: "no_recipient";
85
+ bookingId?: undefined;
86
+ recipient?: undefined;
87
+ documents?: undefined;
88
+ delivery?: undefined;
89
+ } | {
90
+ status: "no_attachments";
91
+ bookingId?: undefined;
92
+ recipient?: undefined;
93
+ documents?: undefined;
94
+ delivery?: undefined;
95
+ } | {
96
+ status: "send_failed";
97
+ bookingId?: undefined;
98
+ recipient?: undefined;
99
+ documents?: undefined;
100
+ delivery?: undefined;
101
+ } | {
102
+ status: "sent";
103
+ bookingId: string;
104
+ recipient: string;
105
+ documents: {
106
+ key: string;
107
+ source: "products" | "legal" | "finance";
108
+ documentType: "contract" | "invoice" | "proforma" | "brochure";
109
+ bookingId: string;
110
+ name: string;
111
+ createdAt: string;
112
+ contractId?: string | null | undefined;
113
+ invoiceId?: string | null | undefined;
114
+ attachmentId?: string | null | undefined;
115
+ renditionId?: string | null | undefined;
116
+ contractStatus?: string | null | undefined;
117
+ invoiceStatus?: string | null | undefined;
118
+ format?: string | null | undefined;
119
+ mimeType?: string | null | undefined;
120
+ storageKey?: string | null | undefined;
121
+ downloadUrl?: string | null | undefined;
122
+ language?: string | null | undefined;
123
+ metadata?: Record<string, unknown> | null | undefined;
124
+ }[];
125
+ delivery: {
126
+ id: string;
127
+ templateId: string | null;
128
+ templateSlug: string | null;
129
+ targetType: "invoice" | "booking" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization" | "other";
130
+ targetId: string | null;
131
+ personId: string | null;
132
+ organizationId: string | null;
133
+ bookingId: string | null;
134
+ invoiceId: string | null;
135
+ paymentSessionId: string | null;
136
+ channel: "email" | "sms";
137
+ provider: string;
138
+ providerMessageId: string | null;
139
+ status: "pending" | "sent" | "failed" | "cancelled";
140
+ toAddress: string;
141
+ fromAddress: string | null;
142
+ subject: string | null;
143
+ htmlBody: string | null;
144
+ textBody: string | null;
145
+ payloadData: Record<string, unknown> | null;
146
+ metadata: Record<string, unknown> | null;
147
+ errorMessage: string | null;
148
+ scheduledFor: Date | null;
149
+ sentAt: Date | null;
150
+ failedAt: Date | null;
151
+ createdAt: Date;
152
+ updatedAt: Date;
153
+ };
154
+ }>;
155
+ confirmAndDispatchBooking: (db: import("drizzle-orm/postgres-js").PostgresJsDatabase, dispatcher: import("./service-shared.js").NotificationService, bookingId: string, input: {
156
+ sendNotification?: boolean;
157
+ } & import("./service-shared.js").SendBookingDocumentsNotificationInput, runtime?: import("./service-booking-documents.js").SendBookingDocumentsRuntimeOptions) => Promise<{
158
+ status: "not_found";
159
+ bookingId?: undefined;
160
+ documents?: undefined;
161
+ skipReason?: undefined;
162
+ recipient?: undefined;
163
+ delivery?: undefined;
164
+ } | {
165
+ status: "preview";
166
+ bookingId: string;
167
+ documents: {
168
+ key: string;
169
+ source: "products" | "legal" | "finance";
170
+ documentType: "contract" | "invoice" | "proforma" | "brochure";
171
+ bookingId: string;
172
+ name: string;
173
+ createdAt: string;
174
+ contractId?: string | null | undefined;
175
+ invoiceId?: string | null | undefined;
176
+ attachmentId?: string | null | undefined;
177
+ renditionId?: string | null | undefined;
178
+ contractStatus?: string | null | undefined;
179
+ invoiceStatus?: string | null | undefined;
180
+ format?: string | null | undefined;
181
+ mimeType?: string | null | undefined;
182
+ storageKey?: string | null | undefined;
183
+ downloadUrl?: string | null | undefined;
184
+ language?: string | null | undefined;
185
+ metadata?: Record<string, unknown> | null | undefined;
186
+ }[];
187
+ skipReason?: undefined;
188
+ recipient?: undefined;
189
+ delivery?: undefined;
190
+ } | {
191
+ status: "skipped";
192
+ bookingId: string;
193
+ documents: {
194
+ key: string;
195
+ source: "products" | "legal" | "finance";
196
+ documentType: "contract" | "invoice" | "proforma" | "brochure";
197
+ bookingId: string;
198
+ name: string;
199
+ createdAt: string;
200
+ contractId?: string | null | undefined;
201
+ invoiceId?: string | null | undefined;
202
+ attachmentId?: string | null | undefined;
203
+ renditionId?: string | null | undefined;
204
+ contractStatus?: string | null | undefined;
205
+ invoiceStatus?: string | null | undefined;
206
+ format?: string | null | undefined;
207
+ mimeType?: string | null | undefined;
208
+ storageKey?: string | null | undefined;
209
+ downloadUrl?: string | null | undefined;
210
+ language?: string | null | undefined;
211
+ metadata?: Record<string, unknown> | null | undefined;
212
+ }[];
213
+ skipReason: "no_documents" | "no_recipient" | "no_attachments" | "send_failed";
214
+ recipient?: undefined;
215
+ delivery?: undefined;
216
+ } | {
217
+ status: "dispatched";
218
+ bookingId: string;
219
+ documents: {
220
+ key: string;
221
+ source: "products" | "legal" | "finance";
222
+ documentType: "contract" | "invoice" | "proforma" | "brochure";
223
+ bookingId: string;
224
+ name: string;
225
+ createdAt: string;
226
+ contractId?: string | null | undefined;
227
+ invoiceId?: string | null | undefined;
228
+ attachmentId?: string | null | undefined;
229
+ renditionId?: string | null | undefined;
230
+ contractStatus?: string | null | undefined;
231
+ invoiceStatus?: string | null | undefined;
232
+ format?: string | null | undefined;
233
+ mimeType?: string | null | undefined;
234
+ storageKey?: string | null | undefined;
235
+ downloadUrl?: string | null | undefined;
236
+ language?: string | null | undefined;
237
+ metadata?: Record<string, unknown> | null | undefined;
238
+ }[];
239
+ recipient: string;
240
+ delivery: {
241
+ id: string;
242
+ templateId: string | null;
243
+ templateSlug: string | null;
244
+ targetType: "invoice" | "booking" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization" | "other";
245
+ targetId: string | null;
246
+ personId: string | null;
247
+ organizationId: string | null;
248
+ bookingId: string | null;
249
+ invoiceId: string | null;
250
+ paymentSessionId: string | null;
251
+ channel: "email" | "sms";
252
+ provider: string;
253
+ providerMessageId: string | null;
254
+ status: "pending" | "sent" | "failed" | "cancelled";
255
+ toAddress: string;
256
+ fromAddress: string | null;
257
+ subject: string | null;
258
+ htmlBody: string | null;
259
+ textBody: string | null;
260
+ payloadData: Record<string, unknown> | null;
261
+ metadata: Record<string, unknown> | null;
262
+ errorMessage: string | null;
263
+ scheduledFor: Date | null;
264
+ sentAt: Date | null;
265
+ failedAt: Date | null;
266
+ createdAt: Date;
267
+ updatedAt: Date;
268
+ };
269
+ skipReason?: undefined;
270
+ }>;
271
+ createDefaultBookingDocumentAttachment: typeof createDefaultBookingDocumentAttachment;
272
+ };
273
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAAE,MAAM,gCAAgC,CAAA;AACvF,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,2BAA2B,EAC3B,0BAA0B,EAC1B,gCAAgC,GACjC,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAEL,sCAAsC,EACvC,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,gBAAgB,EAChB,8BAA8B,EAC/B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAA;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,6BAA6B,EAC7B,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACf,MAAM,wBAAwB,CAAA;AAE/B,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0CkpT,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADnrT,CAAA"}
@@ -0,0 +1,51 @@
1
+ export { createDefaultBookingDocumentAttachment } from "./service-booking-documents.js";
2
+ export { createNotificationService, NotificationError, previewNotificationTemplate, renderNotificationTemplate, summarizeNotificationAttachments, } from "./service-shared.js";
3
+ import { bookingDocumentNotificationsService, createDefaultBookingDocumentAttachment, } from "./service-booking-documents.js";
4
+ import { getDeliveryById, listDeliveries, resendDelivery, sendInvoiceNotification, sendNotification, sendPaymentSessionNotification, } from "./service-deliveries.js";
5
+ import { composeNotificationReminderRule } from "./service-reminder-authoring.js";
6
+ import { runDueReminders } from "./service-reminders.js";
7
+ import { previewReminders } from "./service-sequence.js";
8
+ import { previewNotificationTemplate } from "./service-shared.js";
9
+ import { createReminderRuleStage, createStageChannel, deleteReminderRuleStage, deleteStageChannel, getNotificationSettingsRecord, getReminderRuleStageById, listReminderRuleStages, listStageChannels, reorderReminderRuleStages, updateReminderRuleStage, updateStageChannel, upsertNotificationSettings, } from "./service-stages.js";
10
+ import { createReminderRule, createTemplate, deleteReminderRule, deleteTemplate, getReminderRuleById, getReminderRunById, getTemplateById, getTemplateBySlug, listReminderRules, listReminderRuns, listTemplates, updateReminderRule, updateTemplate, } from "./service-templates.js";
11
+ export const notificationsService = {
12
+ listTemplates,
13
+ getTemplateById,
14
+ getTemplateBySlug,
15
+ createTemplate,
16
+ updateTemplate,
17
+ deleteTemplate,
18
+ previewNotificationTemplate,
19
+ listDeliveries,
20
+ getDeliveryById,
21
+ resendDelivery,
22
+ sendNotification,
23
+ listReminderRules,
24
+ getReminderRuleById,
25
+ getReminderRunById,
26
+ createReminderRule,
27
+ composeNotificationReminderRule,
28
+ updateReminderRule,
29
+ deleteReminderRule,
30
+ listReminderRuns,
31
+ runDueReminders,
32
+ previewReminders,
33
+ listReminderRuleStages,
34
+ getReminderRuleStageById,
35
+ createReminderRuleStage,
36
+ updateReminderRuleStage,
37
+ deleteReminderRuleStage,
38
+ reorderReminderRuleStages,
39
+ listStageChannels,
40
+ createStageChannel,
41
+ updateStageChannel,
42
+ deleteStageChannel,
43
+ getNotificationSettings: getNotificationSettingsRecord,
44
+ upsertNotificationSettings,
45
+ sendPaymentSessionNotification,
46
+ sendInvoiceNotification,
47
+ listBookingDocumentBundle: bookingDocumentNotificationsService.listBookingDocumentBundle,
48
+ sendBookingDocumentsNotification: bookingDocumentNotificationsService.sendBookingDocumentsNotification,
49
+ confirmAndDispatchBooking: bookingDocumentNotificationsService.confirmAndDispatchBooking,
50
+ createDefaultBookingDocumentAttachment,
51
+ };
@@ -0,0 +1,19 @@
1
+ import type { ExecutionLockManager } from "@voyant-travel/core";
2
+ import type { NotificationProvider } from "./types.js";
3
+ export type NotificationTaskEnv = Record<string, unknown>;
4
+ export type ReminderDeliveryJob = {
5
+ reminderRunId: string;
6
+ };
7
+ export type NotificationTaskRuntime = {
8
+ providers: ReadonlyArray<NotificationProvider>;
9
+ reminderSweepLockManager?: ExecutionLockManager;
10
+ enqueueReminderDelivery?: (job: ReminderDeliveryJob) => Promise<void>;
11
+ };
12
+ export type NotificationTaskRuntimeOptions = {
13
+ providers?: ReadonlyArray<NotificationProvider>;
14
+ reminderSweepLockManager?: ExecutionLockManager;
15
+ enqueueReminderDelivery?: (job: ReminderDeliveryJob) => Promise<void>;
16
+ resolveProviders?: (env: NotificationTaskEnv) => ReadonlyArray<NotificationProvider>;
17
+ };
18
+ export declare function buildNotificationTaskRuntime(env: NotificationTaskEnv, options?: NotificationTaskRuntimeOptions): NotificationTaskRuntime;
19
+ //# sourceMappingURL=task-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-runtime.d.ts","sourceRoot":"","sources":["../src/task-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzD,MAAM,MAAM,mBAAmB,GAAG;IAChC,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAA;IAC9C,wBAAwB,CAAC,EAAE,oBAAoB,CAAA;IAC/C,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACtE,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,CAAC,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAA;IAC/C,wBAAwB,CAAC,EAAE,oBAAoB,CAAA;IAC/C,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACrE,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,aAAa,CAAC,oBAAoB,CAAC,CAAA;CACrF,CAAA;AAED,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,mBAAmB,EACxB,OAAO,GAAE,8BAAmC,GAC3C,uBAAuB,CAazB"}
@@ -0,0 +1,11 @@
1
+ export function buildNotificationTaskRuntime(env, options = {}) {
2
+ const providers = options.resolveProviders?.(env) ?? options.providers;
3
+ if (!providers) {
4
+ throw new Error("buildNotificationTaskRuntime requires `providers` or `resolveProviders` — there are no default providers.");
5
+ }
6
+ return {
7
+ providers,
8
+ reminderSweepLockManager: options.reminderSweepLockManager,
9
+ enqueueReminderDelivery: options.enqueueReminderDelivery,
10
+ };
11
+ }
@@ -0,0 +1,9 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import { type NotificationTaskEnv, type NotificationTaskRuntimeOptions } from "../task-runtime.js";
3
+ export declare function deliverQueuedNotificationReminder(db: PostgresJsDatabase, env: NotificationTaskEnv, input: {
4
+ reminderRunId: string;
5
+ }, options?: NotificationTaskRuntimeOptions): Promise<{
6
+ reminderRunId: string;
7
+ status: "sent" | "failed" | "queued" | "processing" | "skipped" | null;
8
+ }>;
9
+ //# sourceMappingURL=deliver-reminder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deliver-reminder.d.ts","sourceRoot":"","sources":["../../src/tasks/deliver-reminder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAIjE,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACpC,MAAM,oBAAoB,CAAA;AAE3B,wBAAsB,iCAAiC,CACrD,EAAE,EAAE,kBAAkB,EACtB,GAAG,EAAE,mBAAmB,EACxB,KAAK,EAAE;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,EAChC,OAAO,GAAE,8BAAmC;;;GAU7C"}