@voyantjs/notifications 0.1.0

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 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAcvD,eAAO,MAAM,uBAAuB,wDAAmD,CAAA;AAEvF,eAAO,MAAM,8BAA8B,uEAIzC,CAAA;AAEF,eAAO,MAAM,8BAA8B,kFAKzC,CAAA;AAEF,eAAO,MAAM,0BAA0B,qKASrC,CAAA;AAEF,eAAO,MAAM,8BAA8B,uEAIzC,CAAA;AAEF,eAAO,MAAM,kCAAkC,oEAE7C,CAAA;AAEF,eAAO,MAAM,iCAAiC,mFAK5C,CAAA;AAEF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBjC,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,OAAO,qBAAqB,CAAC,YAAY,CAAA;AAC5E,MAAM,MAAM,uBAAuB,GAAG,OAAO,qBAAqB,CAAC,YAAY,CAAA;AAE/E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCpC,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,OAAO,wBAAwB,CAAC,YAAY,CAAA;AAClF,MAAM,MAAM,0BAA0B,GAAG,OAAO,wBAAwB,CAAC,YAAY,CAAA;AAErF,eAAO,MAAM,8BAA8B;;;EAGxC,CAAA;AAEH,eAAO,MAAM,+BAA+B;;EAKzC,CAAA;AAEH,eAAO,MAAM,kCAAkC;;;EAS9C,CAAA;AAED,eAAO,MAAM,iCAAiC;;;EAS3C,CAAA;AAEH,eAAO,MAAM,4BAA4B,EAAE,kBAK1C,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,kBAK1C,CAAA;AAED,eAAO,MAAM,gCAAgC,EAAE,kBAK9C,CAAA;AAED,eAAO,MAAM,+BAA+B,EAAE,kBAK7C,CAAA;AAED,eAAO,MAAM,qBAAqB;;;;;CAKjC,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,MAGjC,CAAA;AAGD,MAAM,MAAM,uBAAuB,GAAG,UAAU,CAAA"}
package/dist/schema.js ADDED
@@ -0,0 +1,215 @@
1
+ import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
2
+ import { relations } from "drizzle-orm";
3
+ import { boolean, integer, index, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
4
+ export const notificationChannelEnum = pgEnum("notification_channel", ["email", "sms"]);
5
+ export const notificationTemplateStatusEnum = pgEnum("notification_template_status", [
6
+ "draft",
7
+ "active",
8
+ "archived",
9
+ ]);
10
+ export const notificationDeliveryStatusEnum = pgEnum("notification_delivery_status", [
11
+ "pending",
12
+ "sent",
13
+ "failed",
14
+ "cancelled",
15
+ ]);
16
+ export const notificationTargetTypeEnum = pgEnum("notification_target_type", [
17
+ "booking",
18
+ "booking_payment_schedule",
19
+ "booking_guarantee",
20
+ "invoice",
21
+ "payment_session",
22
+ "person",
23
+ "organization",
24
+ "other",
25
+ ]);
26
+ export const notificationReminderStatusEnum = pgEnum("notification_reminder_status", [
27
+ "draft",
28
+ "active",
29
+ "archived",
30
+ ]);
31
+ export const notificationReminderTargetTypeEnum = pgEnum("notification_reminder_target_type", [
32
+ "booking_payment_schedule",
33
+ ]);
34
+ export const notificationReminderRunStatusEnum = pgEnum("notification_reminder_run_status", [
35
+ "processing",
36
+ "sent",
37
+ "skipped",
38
+ "failed",
39
+ ]);
40
+ export const notificationTemplates = pgTable("notification_templates", {
41
+ id: typeId("notification_templates"),
42
+ slug: text("slug").notNull().unique(),
43
+ name: text("name").notNull(),
44
+ channel: notificationChannelEnum("channel").notNull(),
45
+ provider: text("provider"),
46
+ status: notificationTemplateStatusEnum("status").notNull().default("draft"),
47
+ subjectTemplate: text("subject_template"),
48
+ htmlTemplate: text("html_template"),
49
+ textTemplate: text("text_template"),
50
+ fromAddress: text("from_address"),
51
+ isSystem: boolean("is_system").notNull().default(false),
52
+ metadata: jsonb("metadata").$type(),
53
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
54
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
55
+ }, (table) => [
56
+ index("idx_notification_templates_channel").on(table.channel),
57
+ index("idx_notification_templates_provider").on(table.provider),
58
+ index("idx_notification_templates_status").on(table.status),
59
+ uniqueIndex("uidx_notification_templates_slug").on(table.slug),
60
+ ]);
61
+ export const notificationDeliveries = pgTable("notification_deliveries", {
62
+ id: typeId("notification_deliveries"),
63
+ templateId: typeIdRef("template_id").references(() => notificationTemplates.id, {
64
+ onDelete: "set null",
65
+ }),
66
+ templateSlug: text("template_slug"),
67
+ targetType: notificationTargetTypeEnum("target_type").notNull().default("other"),
68
+ targetId: text("target_id"),
69
+ personId: text("person_id"),
70
+ organizationId: text("organization_id"),
71
+ bookingId: text("booking_id"),
72
+ invoiceId: text("invoice_id"),
73
+ paymentSessionId: text("payment_session_id"),
74
+ channel: notificationChannelEnum("channel").notNull(),
75
+ provider: text("provider").notNull(),
76
+ providerMessageId: text("provider_message_id"),
77
+ status: notificationDeliveryStatusEnum("status").notNull().default("pending"),
78
+ toAddress: text("to_address").notNull(),
79
+ fromAddress: text("from_address"),
80
+ subject: text("subject"),
81
+ htmlBody: text("html_body"),
82
+ textBody: text("text_body"),
83
+ payloadData: jsonb("payload_data").$type(),
84
+ metadata: jsonb("metadata").$type(),
85
+ errorMessage: text("error_message"),
86
+ scheduledFor: timestamp("scheduled_for", { withTimezone: true }),
87
+ sentAt: timestamp("sent_at", { withTimezone: true }),
88
+ failedAt: timestamp("failed_at", { withTimezone: true }),
89
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
90
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
91
+ }, (table) => [
92
+ index("idx_notification_deliveries_template").on(table.templateId),
93
+ index("idx_notification_deliveries_target").on(table.targetType, table.targetId),
94
+ index("idx_notification_deliveries_person").on(table.personId),
95
+ index("idx_notification_deliveries_org").on(table.organizationId),
96
+ index("idx_notification_deliveries_booking").on(table.bookingId),
97
+ index("idx_notification_deliveries_invoice").on(table.invoiceId),
98
+ index("idx_notification_deliveries_payment_session").on(table.paymentSessionId),
99
+ index("idx_notification_deliveries_channel").on(table.channel),
100
+ index("idx_notification_deliveries_provider").on(table.provider),
101
+ index("idx_notification_deliveries_status").on(table.status),
102
+ index("idx_notification_deliveries_scheduled_for").on(table.scheduledFor),
103
+ ]);
104
+ export const notificationReminderRules = pgTable("notification_reminder_rules", {
105
+ id: typeId("notification_reminder_rules"),
106
+ slug: text("slug").notNull().unique(),
107
+ name: text("name").notNull(),
108
+ status: notificationReminderStatusEnum("status").notNull().default("draft"),
109
+ targetType: notificationReminderTargetTypeEnum("target_type").notNull(),
110
+ channel: notificationChannelEnum("channel").notNull(),
111
+ provider: text("provider"),
112
+ templateId: typeIdRef("template_id").references(() => notificationTemplates.id, {
113
+ onDelete: "set null",
114
+ }),
115
+ templateSlug: text("template_slug"),
116
+ relativeDaysFromDueDate: integer("relative_days_from_due_date").notNull().default(0),
117
+ isSystem: boolean("is_system").notNull().default(false),
118
+ metadata: jsonb("metadata").$type(),
119
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
120
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
121
+ }, (table) => [
122
+ index("idx_notification_reminder_rules_status").on(table.status),
123
+ index("idx_notification_reminder_rules_target").on(table.targetType),
124
+ index("idx_notification_reminder_rules_channel").on(table.channel),
125
+ uniqueIndex("uidx_notification_reminder_rules_slug").on(table.slug),
126
+ ]);
127
+ export const notificationReminderRuns = pgTable("notification_reminder_runs", {
128
+ id: typeId("notification_reminder_runs"),
129
+ reminderRuleId: typeIdRef("reminder_rule_id")
130
+ .notNull()
131
+ .references(() => notificationReminderRules.id, { onDelete: "cascade" }),
132
+ targetType: notificationReminderTargetTypeEnum("target_type").notNull(),
133
+ targetId: text("target_id").notNull(),
134
+ dedupeKey: text("dedupe_key").notNull().unique(),
135
+ bookingId: text("booking_id"),
136
+ personId: text("person_id"),
137
+ organizationId: text("organization_id"),
138
+ paymentSessionId: text("payment_session_id"),
139
+ notificationDeliveryId: typeIdRef("notification_delivery_id").references(() => notificationDeliveries.id, { onDelete: "set null" }),
140
+ status: notificationReminderRunStatusEnum("status").notNull(),
141
+ recipient: text("recipient"),
142
+ scheduledFor: timestamp("scheduled_for", { withTimezone: true }).notNull(),
143
+ processedAt: timestamp("processed_at", { withTimezone: true }).notNull().defaultNow(),
144
+ errorMessage: text("error_message"),
145
+ metadata: jsonb("metadata").$type(),
146
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
147
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
148
+ }, (table) => [
149
+ index("idx_notification_reminder_runs_rule").on(table.reminderRuleId),
150
+ index("idx_notification_reminder_runs_target").on(table.targetType, table.targetId),
151
+ index("idx_notification_reminder_runs_booking").on(table.bookingId),
152
+ index("idx_notification_reminder_runs_status").on(table.status),
153
+ uniqueIndex("uidx_notification_reminder_runs_dedupe").on(table.dedupeKey),
154
+ ]);
155
+ export const notificationTemplatesRelations = relations(notificationTemplates, ({ many }) => ({
156
+ deliveries: many(notificationDeliveries),
157
+ reminderRules: many(notificationReminderRules),
158
+ }));
159
+ export const notificationDeliveriesRelations = relations(notificationDeliveries, ({ one }) => ({
160
+ template: one(notificationTemplates, {
161
+ fields: [notificationDeliveries.templateId],
162
+ references: [notificationTemplates.id],
163
+ }),
164
+ }));
165
+ export const notificationReminderRulesRelations = relations(notificationReminderRules, ({ many, one }) => ({
166
+ template: one(notificationTemplates, {
167
+ fields: [notificationReminderRules.templateId],
168
+ references: [notificationTemplates.id],
169
+ }),
170
+ runs: many(notificationReminderRuns),
171
+ }));
172
+ export const notificationReminderRunsRelations = relations(notificationReminderRuns, ({ one }) => ({
173
+ reminderRule: one(notificationReminderRules, {
174
+ fields: [notificationReminderRuns.reminderRuleId],
175
+ references: [notificationReminderRules.id],
176
+ }),
177
+ notificationDelivery: one(notificationDeliveries, {
178
+ fields: [notificationReminderRuns.notificationDeliveryId],
179
+ references: [notificationDeliveries.id],
180
+ }),
181
+ }));
182
+ export const notificationTemplateLinkable = {
183
+ module: "notifications",
184
+ entity: "notificationTemplate",
185
+ table: "notification_templates",
186
+ idPrefix: "ntpl",
187
+ };
188
+ export const notificationDeliveryLinkable = {
189
+ module: "notifications",
190
+ entity: "notificationDelivery",
191
+ table: "notification_deliveries",
192
+ idPrefix: "ntdl",
193
+ };
194
+ export const notificationReminderRuleLinkable = {
195
+ module: "notifications",
196
+ entity: "notificationReminderRule",
197
+ table: "notification_reminder_rules",
198
+ idPrefix: "ntrl",
199
+ };
200
+ export const notificationReminderRunLinkable = {
201
+ module: "notifications",
202
+ entity: "notificationReminderRun",
203
+ table: "notification_reminder_runs",
204
+ idPrefix: "ntrn",
205
+ };
206
+ export const notificationsLinkable = {
207
+ notificationTemplate: notificationTemplateLinkable,
208
+ notificationDelivery: notificationDeliveryLinkable,
209
+ notificationReminderRule: notificationReminderRuleLinkable,
210
+ notificationReminderRun: notificationReminderRunLinkable,
211
+ };
212
+ export const notificationsModule = {
213
+ name: "notifications",
214
+ linkable: notificationsLinkable,
215
+ };
@@ -0,0 +1,370 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import type { z } from "zod";
3
+ import type { NotificationChannel, NotificationPayload, NotificationProvider, NotificationResult } from "./types.js";
4
+ import type { insertNotificationReminderRuleSchema, insertNotificationTemplateSchema, notificationDeliveryListQuerySchema, notificationReminderRuleListQuerySchema, notificationReminderRunListQuerySchema, notificationTemplateListQuerySchema, runDueRemindersSchema, sendInvoiceNotificationSchema, sendPaymentSessionNotificationSchema, sendNotificationSchema, updateNotificationReminderRuleSchema, updateNotificationTemplateSchema } from "./validation.js";
5
+ type NotificationTemplateListQuery = z.infer<typeof notificationTemplateListQuerySchema>;
6
+ type NotificationDeliveryListQuery = z.infer<typeof notificationDeliveryListQuerySchema>;
7
+ type CreateNotificationTemplateInput = z.infer<typeof insertNotificationTemplateSchema>;
8
+ type UpdateNotificationTemplateInput = z.infer<typeof updateNotificationTemplateSchema>;
9
+ type SendNotificationInput = z.infer<typeof sendNotificationSchema>;
10
+ type NotificationReminderRuleListQuery = z.infer<typeof notificationReminderRuleListQuerySchema>;
11
+ type NotificationReminderRunListQuery = z.infer<typeof notificationReminderRunListQuerySchema>;
12
+ type CreateNotificationReminderRuleInput = z.infer<typeof insertNotificationReminderRuleSchema>;
13
+ type UpdateNotificationReminderRuleInput = z.infer<typeof updateNotificationReminderRuleSchema>;
14
+ type RunDueRemindersInput = z.infer<typeof runDueRemindersSchema>;
15
+ type SendPaymentSessionNotificationInput = z.infer<typeof sendPaymentSessionNotificationSchema>;
16
+ type SendInvoiceNotificationInput = z.infer<typeof sendInvoiceNotificationSchema>;
17
+ type ReminderSweepResult = {
18
+ processed: number;
19
+ sent: number;
20
+ skipped: number;
21
+ failed: number;
22
+ };
23
+ /**
24
+ * Thrown when `send()` is called with a channel that has no registered
25
+ * provider, or with a provider name that does not exist.
26
+ */
27
+ export declare class NotificationError extends Error {
28
+ constructor(message: string);
29
+ }
30
+ export interface NotificationService {
31
+ send(payload: NotificationPayload): Promise<NotificationResult>;
32
+ sendWith(providerName: string, payload: NotificationPayload): Promise<NotificationResult>;
33
+ getProvider(channel: NotificationChannel): NotificationProvider | undefined;
34
+ }
35
+ export declare function createNotificationService(providers: ReadonlyArray<NotificationProvider>): NotificationService;
36
+ export declare function renderNotificationTemplate(template: string | null | undefined, data: Record<string, unknown>): string | null;
37
+ export declare const notificationsService: {
38
+ listTemplates(db: PostgresJsDatabase, query: NotificationTemplateListQuery): Promise<{
39
+ data: {
40
+ id: string;
41
+ slug: string;
42
+ name: string;
43
+ channel: "email" | "sms";
44
+ provider: string | null;
45
+ status: "draft" | "active" | "archived";
46
+ subjectTemplate: string | null;
47
+ htmlTemplate: string | null;
48
+ textTemplate: string | null;
49
+ fromAddress: string | null;
50
+ isSystem: boolean;
51
+ metadata: Record<string, unknown> | null;
52
+ createdAt: Date;
53
+ updatedAt: Date;
54
+ }[];
55
+ total: number;
56
+ limit: number;
57
+ offset: number;
58
+ }>;
59
+ getTemplateById(db: PostgresJsDatabase, id: string): Promise<{
60
+ id: string;
61
+ slug: string;
62
+ name: string;
63
+ channel: "email" | "sms";
64
+ provider: string | null;
65
+ status: "draft" | "active" | "archived";
66
+ subjectTemplate: string | null;
67
+ htmlTemplate: string | null;
68
+ textTemplate: string | null;
69
+ fromAddress: string | null;
70
+ isSystem: boolean;
71
+ metadata: Record<string, unknown> | null;
72
+ createdAt: Date;
73
+ updatedAt: Date;
74
+ } | null>;
75
+ getTemplateBySlug(db: PostgresJsDatabase, slug: string): Promise<{
76
+ id: string;
77
+ slug: string;
78
+ name: string;
79
+ channel: "email" | "sms";
80
+ provider: string | null;
81
+ status: "draft" | "active" | "archived";
82
+ subjectTemplate: string | null;
83
+ htmlTemplate: string | null;
84
+ textTemplate: string | null;
85
+ fromAddress: string | null;
86
+ isSystem: boolean;
87
+ metadata: Record<string, unknown> | null;
88
+ createdAt: Date;
89
+ updatedAt: Date;
90
+ } | null>;
91
+ createTemplate(db: PostgresJsDatabase, data: CreateNotificationTemplateInput): Promise<{
92
+ id: string;
93
+ name: string;
94
+ status: "draft" | "active" | "archived";
95
+ createdAt: Date;
96
+ updatedAt: Date;
97
+ metadata: Record<string, unknown> | null;
98
+ channel: "email" | "sms";
99
+ provider: string | null;
100
+ slug: string;
101
+ subjectTemplate: string | null;
102
+ htmlTemplate: string | null;
103
+ textTemplate: string | null;
104
+ fromAddress: string | null;
105
+ isSystem: boolean;
106
+ } | null>;
107
+ updateTemplate(db: PostgresJsDatabase, id: string, data: UpdateNotificationTemplateInput): Promise<{
108
+ id: string;
109
+ slug: string;
110
+ name: string;
111
+ channel: "email" | "sms";
112
+ provider: string | null;
113
+ status: "draft" | "active" | "archived";
114
+ subjectTemplate: string | null;
115
+ htmlTemplate: string | null;
116
+ textTemplate: string | null;
117
+ fromAddress: string | null;
118
+ isSystem: boolean;
119
+ metadata: Record<string, unknown> | null;
120
+ createdAt: Date;
121
+ updatedAt: Date;
122
+ } | null>;
123
+ listDeliveries(db: PostgresJsDatabase, query: NotificationDeliveryListQuery): Promise<{
124
+ data: {
125
+ id: string;
126
+ templateId: string | null;
127
+ templateSlug: string | null;
128
+ targetType: "other" | "booking" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization";
129
+ targetId: string | null;
130
+ personId: string | null;
131
+ organizationId: string | null;
132
+ bookingId: string | null;
133
+ invoiceId: string | null;
134
+ paymentSessionId: string | null;
135
+ channel: "email" | "sms";
136
+ provider: string;
137
+ providerMessageId: string | null;
138
+ status: "cancelled" | "pending" | "failed" | "sent";
139
+ toAddress: string;
140
+ fromAddress: string | null;
141
+ subject: string | null;
142
+ htmlBody: string | null;
143
+ textBody: string | null;
144
+ payloadData: Record<string, unknown> | null;
145
+ metadata: Record<string, unknown> | null;
146
+ errorMessage: string | null;
147
+ scheduledFor: Date | null;
148
+ sentAt: Date | null;
149
+ failedAt: Date | null;
150
+ createdAt: Date;
151
+ updatedAt: Date;
152
+ }[];
153
+ total: number;
154
+ limit: number;
155
+ offset: number;
156
+ }>;
157
+ getDeliveryById(db: PostgresJsDatabase, id: string): Promise<{
158
+ id: string;
159
+ templateId: string | null;
160
+ templateSlug: string | null;
161
+ targetType: "other" | "booking" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization";
162
+ targetId: string | null;
163
+ personId: string | null;
164
+ organizationId: string | null;
165
+ bookingId: string | null;
166
+ invoiceId: string | null;
167
+ paymentSessionId: string | null;
168
+ channel: "email" | "sms";
169
+ provider: string;
170
+ providerMessageId: string | null;
171
+ status: "cancelled" | "pending" | "failed" | "sent";
172
+ toAddress: string;
173
+ fromAddress: string | null;
174
+ subject: string | null;
175
+ htmlBody: string | null;
176
+ textBody: string | null;
177
+ payloadData: Record<string, unknown> | null;
178
+ metadata: Record<string, unknown> | null;
179
+ errorMessage: string | null;
180
+ scheduledFor: Date | null;
181
+ sentAt: Date | null;
182
+ failedAt: Date | null;
183
+ createdAt: Date;
184
+ updatedAt: Date;
185
+ } | null>;
186
+ sendNotification(db: PostgresJsDatabase, dispatcher: NotificationService, input: SendNotificationInput): Promise<{
187
+ id: string;
188
+ templateId: string | null;
189
+ templateSlug: string | null;
190
+ targetType: "other" | "booking" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization";
191
+ targetId: string | null;
192
+ personId: string | null;
193
+ organizationId: string | null;
194
+ bookingId: string | null;
195
+ invoiceId: string | null;
196
+ paymentSessionId: string | null;
197
+ channel: "email" | "sms";
198
+ provider: string;
199
+ providerMessageId: string | null;
200
+ status: "cancelled" | "pending" | "failed" | "sent";
201
+ toAddress: string;
202
+ fromAddress: string | null;
203
+ subject: string | null;
204
+ htmlBody: string | null;
205
+ textBody: string | null;
206
+ payloadData: Record<string, unknown> | null;
207
+ metadata: Record<string, unknown> | null;
208
+ errorMessage: string | null;
209
+ scheduledFor: Date | null;
210
+ sentAt: Date | null;
211
+ failedAt: Date | null;
212
+ createdAt: Date;
213
+ updatedAt: Date;
214
+ } | null>;
215
+ listReminderRules(db: PostgresJsDatabase, query: NotificationReminderRuleListQuery): Promise<{
216
+ data: {
217
+ id: string;
218
+ slug: string;
219
+ name: string;
220
+ status: "draft" | "active" | "archived";
221
+ targetType: "booking_payment_schedule";
222
+ channel: "email" | "sms";
223
+ provider: string | null;
224
+ templateId: string | null;
225
+ templateSlug: string | null;
226
+ relativeDaysFromDueDate: number;
227
+ isSystem: boolean;
228
+ metadata: Record<string, unknown> | null;
229
+ createdAt: Date;
230
+ updatedAt: Date;
231
+ }[];
232
+ total: number;
233
+ limit: number;
234
+ offset: number;
235
+ }>;
236
+ getReminderRuleById(db: PostgresJsDatabase, id: string): Promise<{
237
+ id: string;
238
+ slug: string;
239
+ name: string;
240
+ status: "draft" | "active" | "archived";
241
+ targetType: "booking_payment_schedule";
242
+ channel: "email" | "sms";
243
+ provider: string | null;
244
+ templateId: string | null;
245
+ templateSlug: string | null;
246
+ relativeDaysFromDueDate: number;
247
+ isSystem: boolean;
248
+ metadata: Record<string, unknown> | null;
249
+ createdAt: Date;
250
+ updatedAt: Date;
251
+ } | null>;
252
+ createReminderRule(db: PostgresJsDatabase, data: CreateNotificationReminderRuleInput): Promise<{
253
+ id: string;
254
+ name: string;
255
+ status: "draft" | "active" | "archived";
256
+ createdAt: Date;
257
+ updatedAt: Date;
258
+ metadata: Record<string, unknown> | null;
259
+ channel: "email" | "sms";
260
+ provider: string | null;
261
+ targetType: "booking_payment_schedule";
262
+ templateId: string | null;
263
+ slug: string;
264
+ isSystem: boolean;
265
+ templateSlug: string | null;
266
+ relativeDaysFromDueDate: number;
267
+ } | null>;
268
+ updateReminderRule(db: PostgresJsDatabase, id: string, data: UpdateNotificationReminderRuleInput): Promise<{
269
+ id: string;
270
+ slug: string;
271
+ name: string;
272
+ status: "draft" | "active" | "archived";
273
+ targetType: "booking_payment_schedule";
274
+ channel: "email" | "sms";
275
+ provider: string | null;
276
+ templateId: string | null;
277
+ templateSlug: string | null;
278
+ relativeDaysFromDueDate: number;
279
+ isSystem: boolean;
280
+ metadata: Record<string, unknown> | null;
281
+ createdAt: Date;
282
+ updatedAt: Date;
283
+ } | null>;
284
+ listReminderRuns(db: PostgresJsDatabase, query: NotificationReminderRunListQuery): Promise<{
285
+ data: {
286
+ id: string;
287
+ reminderRuleId: string;
288
+ targetType: "booking_payment_schedule";
289
+ targetId: string;
290
+ dedupeKey: string;
291
+ bookingId: string | null;
292
+ personId: string | null;
293
+ organizationId: string | null;
294
+ paymentSessionId: string | null;
295
+ notificationDeliveryId: string | null;
296
+ status: "failed" | "sent" | "processing" | "skipped";
297
+ recipient: string | null;
298
+ scheduledFor: Date;
299
+ processedAt: Date;
300
+ errorMessage: string | null;
301
+ metadata: Record<string, unknown> | null;
302
+ createdAt: Date;
303
+ updatedAt: Date;
304
+ }[];
305
+ total: number;
306
+ limit: number;
307
+ offset: number;
308
+ }>;
309
+ runDueReminders(db: PostgresJsDatabase, dispatcher: NotificationService, input?: RunDueRemindersInput): Promise<ReminderSweepResult>;
310
+ sendPaymentSessionNotification(db: PostgresJsDatabase, dispatcher: NotificationService, sessionId: string, input: SendPaymentSessionNotificationInput): Promise<{
311
+ id: string;
312
+ templateId: string | null;
313
+ templateSlug: string | null;
314
+ targetType: "other" | "booking" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization";
315
+ targetId: string | null;
316
+ personId: string | null;
317
+ organizationId: string | null;
318
+ bookingId: string | null;
319
+ invoiceId: string | null;
320
+ paymentSessionId: string | null;
321
+ channel: "email" | "sms";
322
+ provider: string;
323
+ providerMessageId: string | null;
324
+ status: "cancelled" | "pending" | "failed" | "sent";
325
+ toAddress: string;
326
+ fromAddress: string | null;
327
+ subject: string | null;
328
+ htmlBody: string | null;
329
+ textBody: string | null;
330
+ payloadData: Record<string, unknown> | null;
331
+ metadata: Record<string, unknown> | null;
332
+ errorMessage: string | null;
333
+ scheduledFor: Date | null;
334
+ sentAt: Date | null;
335
+ failedAt: Date | null;
336
+ createdAt: Date;
337
+ updatedAt: Date;
338
+ } | null>;
339
+ sendInvoiceNotification(db: PostgresJsDatabase, dispatcher: NotificationService, invoiceId: string, input: SendInvoiceNotificationInput): Promise<{
340
+ id: string;
341
+ templateId: string | null;
342
+ templateSlug: string | null;
343
+ targetType: "other" | "booking" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "payment_session" | "person" | "organization";
344
+ targetId: string | null;
345
+ personId: string | null;
346
+ organizationId: string | null;
347
+ bookingId: string | null;
348
+ invoiceId: string | null;
349
+ paymentSessionId: string | null;
350
+ channel: "email" | "sms";
351
+ provider: string;
352
+ providerMessageId: string | null;
353
+ status: "cancelled" | "pending" | "failed" | "sent";
354
+ toAddress: string;
355
+ fromAddress: string | null;
356
+ subject: string | null;
357
+ htmlBody: string | null;
358
+ textBody: string | null;
359
+ payloadData: Record<string, unknown> | null;
360
+ metadata: Record<string, unknown> | null;
361
+ errorMessage: string | null;
362
+ scheduledFor: Date | null;
363
+ sentAt: Date | null;
364
+ failedAt: Date | null;
365
+ createdAt: Date;
366
+ updatedAt: Date;
367
+ } | null>;
368
+ };
369
+ export {};
370
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAQ5B,OAAO,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