@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for, the acceptance of support, warranty, indemnity, or
168
+ other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 PixelMakers Studio SRL
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # @voyant-travel/notifications
2
+
3
+ Notifications module for Voyant. It includes:
4
+
5
+ - provider abstraction via `NotificationProvider`
6
+ - first-party providers for local development and Voyant Cloud (email + SMS)
7
+ - database-backed notification templates
8
+ - database-backed delivery logs
9
+ - notification reminder rules and reminder runs
10
+ - finance-aware send flows for invoices and payment sessions
11
+ - booking document bundle/list + send flows for contract and invoice/proforma
12
+ artifacts
13
+ - routes for template management, delivery listing, reminder management, and sending
14
+
15
+ CRM communication history should remain a business-facing log. This module owns transport templates, delivery attempts, provider message ids, and reminder-oriented operational sends.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pnpm add @voyant-travel/notifications
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```typescript
26
+ import { getVoyantCloudClient } from "@voyant-travel/voyant-cloud"
27
+ import { createNotificationService } from "@voyant-travel/notifications"
28
+ import { createLocalProvider } from "@voyant-travel/notifications/providers/local"
29
+ import { createVoyantCloudEmailProvider } from "@voyant-travel/notifications/providers/voyant-cloud-email"
30
+ import { createVoyantCloudSmsProvider } from "@voyant-travel/notifications/providers/voyant-cloud-sms"
31
+
32
+ const cloud = getVoyantCloudClient(env)
33
+ const notifications = createNotificationService([
34
+ createLocalProvider({ channels: ["email"] }),
35
+ createVoyantCloudEmailProvider({ client: cloud, from: "noreply@example.com" }),
36
+ createVoyantCloudSmsProvider({ client: cloud }),
37
+ ])
38
+
39
+ await notifications.send({
40
+ to: "user@example.com",
41
+ channel: "email",
42
+ template: "welcome",
43
+ subject: "Hello",
44
+ html: "<p>Welcome</p>",
45
+ })
46
+ ```
47
+
48
+ Later providers override earlier ones on channel conflict; `sendWith(name, payload)` dispatches by provider name.
49
+
50
+ The bring-your-own path is first-class: any project can implement
51
+ `NotificationProvider` against another transport (raw Resend, Twilio, SES, …)
52
+ and register it in place of the cloud adapters.
53
+
54
+ For the Hono module:
55
+
56
+ ```ts
57
+ import { getVoyantCloudClient } from "@voyant-travel/voyant-cloud"
58
+ import {
59
+ createNotificationsHonoModule,
60
+ createVoyantCloudEmailProvider,
61
+ createVoyantCloudSmsProvider,
62
+ } from "@voyant-travel/notifications"
63
+
64
+ const notificationsModule = createNotificationsHonoModule({
65
+ resolveProviders: (env) => {
66
+ const cloud = getVoyantCloudClient(env as Record<string, unknown>)
67
+ return [
68
+ createVoyantCloudEmailProvider({ client: cloud, from: "noreply@example.com" }),
69
+ createVoyantCloudSmsProvider({ client: cloud }),
70
+ ]
71
+ },
72
+ })
73
+ ```
74
+
75
+ For scheduled reminder sweeps:
76
+
77
+ ```ts
78
+ import { sendDueNotificationReminders } from "@voyant-travel/notifications/tasks"
79
+
80
+ await sendDueNotificationReminders(db, process.env, {
81
+ now: "2026-04-08T09:00:00.000Z",
82
+ })
83
+ ```
84
+
85
+ Reminder rules can currently target:
86
+
87
+ - `booking_payment_schedule`
88
+ - `invoice`
89
+
90
+ Stage cadence and `maxSendsInStage` are evaluated against reminder run attempts.
91
+ A queued, sent, skipped, or failed run consumes the stage slot; failed runs are
92
+ terminal until an operator or explicit recovery flow requeues them.
93
+
94
+ For finance-aware collection sends, the routes also support:
95
+
96
+ - `POST /payment-sessions/:id/send`
97
+ - `POST /invoices/:id/send`
98
+ - `GET /bookings/:id/document-bundle`
99
+ - `POST /bookings/:id/send-documents`
100
+
101
+ Those routes resolve recipients from the payment session, invoice, and linked booking travelers, then render the selected notification template with finance context such as payment links, invoice balances, and booking references.
102
+
103
+ Booking document sends bundle the latest customer-facing contract attachment and
104
+ ready invoice/proforma rendition for a booking. By default they use the stored
105
+ artifact URL when one is durable and publicly readable. Private document flows
106
+ should override that behavior with `documentAttachmentResolver` or
107
+ `resolveDocumentAttachmentResolver` when mounting `createNotificationsRoutes()`
108
+ or `createNotificationsHonoModule()`, so attachment URLs are resolved at send
109
+ time from the current storage/runtime context.
110
+
111
+ ## Booking Document Bundle Lifecycle
112
+
113
+ `createNotificationsHonoModule()` can subscribe to booking confirmation and
114
+ fully-paid lifecycle signals through `documentBundleLifecycle`. The hook
115
+ resolves the booking, primary customer/recipient, travelers, booking items, and
116
+ existing legal/finance document bundle before invoking the configured policy.
117
+
118
+ ```ts
119
+ const notificationsModule = createNotificationsHonoModule({
120
+ resolveDb: (bindings) => getDbFromEnv(bindings),
121
+ resolveProviders,
122
+ documentBundleLifecycle: {
123
+ enabled: true,
124
+ confirmation: {
125
+ notification: { templateSlug: "booking-confirmation" },
126
+ },
127
+ fullyPaid: {
128
+ documentTypes: ["contract", "invoice"],
129
+ notification: { templateSlug: "booking-paid-in-full" },
130
+ },
131
+ ensureLegalDocuments: async (context) => {
132
+ await generateContractForBooking(context.booking.id)
133
+ },
134
+ ensureFinanceDocuments: async (context, request) => {
135
+ await generateInvoiceDocuments(context.booking.id, request.documentTypes)
136
+ },
137
+ notificationPolicy: async (context, result) => ({
138
+ templateSlug:
139
+ context.trigger === "booking.fully-paid"
140
+ ? "booking-paid-in-full"
141
+ : "booking-confirmation",
142
+ documentTypes: result.documents.map((document) => document.documentType),
143
+ }),
144
+ },
145
+ })
146
+ ```
147
+
148
+ The default policy is idempotent by document type: confirmation asks for
149
+ `contract` + `proforma`, and fully-paid asks for `contract` + `invoice`. If a
150
+ contract was already generated at confirmation, the fully-paid hook records it
151
+ as existing and only calls the configured finance generator for the missing
152
+ invoice. Generator exceptions are returned as failed lifecycle results and the
153
+ module subscriber logs booking id plus status only; it does not log document
154
+ contents, attachment bodies, or customer data.
155
+
156
+ Host apps can replace the entire policy with `policy`, or keep the default
157
+ composition and override only `notificationPolicy`. Product brochures remain an
158
+ extension point via `resolveBrochureDocuments`, so apps that install
159
+ `@voyant-travel/inventory` can add current brochure artifacts without making
160
+ notifications depend on products at runtime.
161
+
162
+ ## Exports
163
+
164
+ | Entry | Description |
165
+ | --- | --- |
166
+ | `.` | Barrel re-exports |
167
+ | `./schema` | Drizzle tables and module definitions |
168
+ | `./types` | `NotificationProvider`, payload types |
169
+ | `./validation` | Zod schemas for templates, deliveries, reminders, send input |
170
+ | `./routes` | Hono route factory |
171
+ | `./service` | Dispatcher + database-backed notifications service |
172
+ | `./tasks` | Reminder sweep task helpers |
173
+ | `./providers/local` | Console sink for dev |
174
+ | `./providers/voyant-cloud-email` | Voyant Cloud email provider |
175
+ | `./providers/voyant-cloud-sms` | Voyant Cloud SMS provider |
176
+
177
+ ## License
178
+
179
+ Apache-2.0
@@ -0,0 +1,61 @@
1
+ import type { AnyDrizzleDb } from "@voyant-travel/db";
2
+ import type { HonoModule } from "@voyant-travel/hono/module";
3
+ import { type NotificationsRoutesOptions } from "./routes.js";
4
+ import { type BookingDocumentBundleLifecycleOptions } from "./service-booking-document-lifecycle.js";
5
+ export { notificationLiquidEngine, renderLiquidTemplate, } from "./liquid.js";
6
+ export type { LocalProviderOptions } from "./providers/local.js";
7
+ export { createLocalProvider } from "./providers/local.js";
8
+ export type { VoyantCloudEmailProviderOptions, VoyantCloudEmailRendered, } from "./providers/voyant-cloud-email.js";
9
+ export { createVoyantCloudEmailProvider } from "./providers/voyant-cloud-email.js";
10
+ export type { VoyantCloudSmsProviderOptions, VoyantCloudSmsRendered, } from "./providers/voyant-cloud-sms.js";
11
+ export { createVoyantCloudSmsProvider } from "./providers/voyant-cloud-sms.js";
12
+ export type { NotificationsRouteRuntime, NotificationsRoutesOptions } from "./routes.js";
13
+ export { buildNotificationsRouteRuntime, createNotificationsRoutes, NOTIFICATIONS_ROUTE_RUNTIME_CONTAINER_KEY, } from "./routes.js";
14
+ export type { NewNotificationDelivery, NewNotificationReminderRule, NewNotificationReminderRun, NewNotificationTemplate, NotificationDelivery, NotificationReminderRule, NotificationReminderRun, NotificationsHonoModule, NotificationTemplate, } from "./schema.js";
15
+ export { notificationChannelEnum, notificationDeliveries, notificationDeliveryStatusEnum, notificationReminderRules, notificationReminderRunStatusEnum, notificationReminderRuns, notificationReminderStatusEnum, notificationReminderTargetTypeEnum, notificationsModule, notificationTargetTypeEnum, notificationTemplateStatusEnum, notificationTemplates, } from "./schema.js";
16
+ export type { NotificationService } from "./service.js";
17
+ export { createDefaultBookingDocumentAttachment, createNotificationService, NotificationError, notificationsService, previewNotificationTemplate, renderNotificationTemplate, } from "./service.js";
18
+ export type { BookingDocumentBundleLifecycleContext, BookingDocumentBundleLifecycleDocumentType, BookingDocumentBundleLifecycleEnsureDocuments, BookingDocumentBundleLifecycleEvent, BookingDocumentBundleLifecycleOptions, BookingDocumentBundleLifecyclePolicy, BookingDocumentBundleLifecyclePolicyResult, BookingDocumentBundleLifecycleResolveBrochures, BookingDocumentBundleLifecycleResult, BookingDocumentBundleLifecycleStageOptions, BookingDocumentBundleLifecycleStep, BookingDocumentBundleLifecycleTrigger, BookingDocumentBundleNotificationPolicy, BookingFullyPaidEvent, } from "./service-booking-document-lifecycle.js";
19
+ export { BOOKING_FULLY_PAID_EVENT, bookingDocumentBundleLifecycleService, createDefaultBookingDocumentBundlePolicy, resolveBookingDocumentBundleLifecycleContext, } from "./service-booking-document-lifecycle.js";
20
+ export type { BookingDocumentAttachmentResolver, BookingDocumentsSentEvent, SendBookingDocumentsRuntimeOptions, } from "./service-booking-documents.js";
21
+ export { bookingDocumentNotificationsService } from "./service-booking-documents.js";
22
+ export { bookingIsPaidInFullForNotification, dispatchReminderEventRules, } from "./service-reminders.js";
23
+ export type { NotificationTaskEnv, NotificationTaskRuntime, NotificationTaskRuntimeOptions, ReminderDeliveryJob, } from "./task-runtime.js";
24
+ export { buildNotificationTaskRuntime } from "./task-runtime.js";
25
+ export { deliverQueuedNotificationReminder, sendDueNotificationReminders } from "./tasks/index.js";
26
+ export type { NotificationLiquidSnippet, NotificationTemplateVariableCategory, NotificationTemplateVariableDefinition, NotificationTemplateVariableType, } from "./template-authoring.js";
27
+ export { notificationLiquidSnippets, notificationTemplateVariableCatalog, } from "./template-authoring.js";
28
+ export type { NotificationAttachment, NotificationChannel, NotificationPayload, NotificationProvider, NotificationResult, } from "./types.js";
29
+ export { bookingDocumentBundleItemSchema, bookingDocumentBundleSchema, insertNotificationReminderRuleSchema, insertNotificationReminderRuleStageSchema, insertNotificationReminderStageChannelSchema, insertNotificationTemplateSchema, notificationAttachmentSchema, notificationChannelSchema, notificationDeliveryListQuerySchema, notificationDeliveryStatusSchema, notificationDocumentSourceSchema, notificationDocumentTypeSchema, notificationReminderRuleListQuerySchema, notificationReminderRunDeliverySummarySchema, notificationReminderRunLinksSchema, notificationReminderRunListQuerySchema, notificationReminderRunListResponseSchema, notificationReminderRunRecordSchema, notificationReminderRunRuleSummarySchema, notificationReminderRunStatusSchema, notificationReminderStageAnchorSchema, notificationReminderStageCadenceIntervalSchema, notificationReminderStageCadenceKindSchema, notificationReminderStatusSchema, notificationReminderTargetTypeSchema, notificationStageRecipientKindSchema, notificationTargetTypeSchema, notificationTemplateListQuerySchema, notificationTemplateStatusSchema, previewNotificationTemplateResultSchema, previewNotificationTemplateSchema, previewRemindersQuerySchema, reorderReminderRuleStagesSchema, runDueRemindersSchema, sendBookingDocumentsNotificationResultSchema, sendBookingDocumentsNotificationSchema, sendInvoiceNotificationSchema, sendNotificationSchema, sendPaymentSessionNotificationSchema, updateNotificationReminderRuleSchema, updateNotificationReminderRuleStageSchema, updateNotificationReminderStageChannelSchema, updateNotificationSettingsSchema, updateNotificationTemplateSchema, } from "./validation.js";
30
+ /**
31
+ * Auto-dispatch policy for the `booking.confirmed` subscriber. Set `enabled:
32
+ * false` (or leave the option off entirely) to opt out.
33
+ */
34
+ export interface NotificationsAutoConfirmAndDispatchOptions {
35
+ enabled?: boolean;
36
+ /** Notification template slug used when the handler fires. */
37
+ templateSlug?: string;
38
+ /** Optional allowlist of document types to attach; defaults to all. */
39
+ documentTypes?: Array<"contract" | "invoice" | "proforma">;
40
+ }
41
+ export interface CreateNotificationsHonoModuleOptions extends NotificationsRoutesOptions {
42
+ /**
43
+ * Resolves a database from runtime bindings. Required for
44
+ * `autoConfirmAndDispatch` — the `booking.confirmed` subscriber fires
45
+ * outside a request scope and needs its own db handle. Returns
46
+ * `AnyDrizzleDb` (the union of `PostgresJsDatabase | NeonHttpDatabase`)
47
+ * so consumers don't have to cast through `unknown` when wiring a
48
+ * Hyperdrive/Neon client.
49
+ */
50
+ resolveDb?: (bindings: Record<string, unknown>) => AnyDrizzleDb;
51
+ autoConfirmAndDispatch?: NotificationsAutoConfirmAndDispatchOptions;
52
+ /**
53
+ * First-class booking lifecycle hook for composing customer document
54
+ * bundles after confirmation and fully-paid transitions. Host apps can
55
+ * plug legal/finance/brochure generators and override notification policy
56
+ * without replacing the upstream event wiring.
57
+ */
58
+ documentBundleLifecycle?: BookingDocumentBundleLifecycleOptions;
59
+ }
60
+ export declare function createNotificationsHonoModule(options?: CreateNotificationsHonoModuleOptions): HonoModule;
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
package/dist/index.js ADDED
@@ -0,0 +1,196 @@
1
+ import { buildNotificationsRouteRuntime, createNotificationsRoutes, NOTIFICATIONS_ROUTE_RUNTIME_CONTAINER_KEY, } from "./routes.js";
2
+ import { notificationsModule } from "./schema.js";
3
+ import { createNotificationService } from "./service.js";
4
+ import { BOOKING_FULLY_PAID_EVENT, bookingDocumentBundleLifecycleService, } from "./service-booking-document-lifecycle.js";
5
+ import { bookingDocumentNotificationsService } from "./service-booking-documents.js";
6
+ import { bookingIsPaidInFullForNotification, dispatchReminderEventRules, } from "./service-reminders.js";
7
+ export { notificationLiquidEngine, renderLiquidTemplate, } from "./liquid.js";
8
+ export { createLocalProvider } from "./providers/local.js";
9
+ export { createVoyantCloudEmailProvider } from "./providers/voyant-cloud-email.js";
10
+ export { createVoyantCloudSmsProvider } from "./providers/voyant-cloud-sms.js";
11
+ export { buildNotificationsRouteRuntime, createNotificationsRoutes, NOTIFICATIONS_ROUTE_RUNTIME_CONTAINER_KEY, } from "./routes.js";
12
+ export { notificationChannelEnum, notificationDeliveries, notificationDeliveryStatusEnum, notificationReminderRules, notificationReminderRunStatusEnum, notificationReminderRuns, notificationReminderStatusEnum, notificationReminderTargetTypeEnum, notificationsModule, notificationTargetTypeEnum, notificationTemplateStatusEnum, notificationTemplates, } from "./schema.js";
13
+ export { createDefaultBookingDocumentAttachment, createNotificationService, NotificationError, notificationsService, previewNotificationTemplate, renderNotificationTemplate, } from "./service.js";
14
+ export { BOOKING_FULLY_PAID_EVENT, bookingDocumentBundleLifecycleService, createDefaultBookingDocumentBundlePolicy, resolveBookingDocumentBundleLifecycleContext, } from "./service-booking-document-lifecycle.js";
15
+ export { bookingDocumentNotificationsService } from "./service-booking-documents.js";
16
+ export { bookingIsPaidInFullForNotification, dispatchReminderEventRules, } from "./service-reminders.js";
17
+ export { buildNotificationTaskRuntime } from "./task-runtime.js";
18
+ export { deliverQueuedNotificationReminder, sendDueNotificationReminders } from "./tasks/index.js";
19
+ export { notificationLiquidSnippets, notificationTemplateVariableCatalog, } from "./template-authoring.js";
20
+ export { bookingDocumentBundleItemSchema, bookingDocumentBundleSchema, insertNotificationReminderRuleSchema, insertNotificationReminderRuleStageSchema, insertNotificationReminderStageChannelSchema, insertNotificationTemplateSchema, notificationAttachmentSchema, notificationChannelSchema, notificationDeliveryListQuerySchema, notificationDeliveryStatusSchema, notificationDocumentSourceSchema, notificationDocumentTypeSchema, notificationReminderRuleListQuerySchema, notificationReminderRunDeliverySummarySchema, notificationReminderRunLinksSchema, notificationReminderRunListQuerySchema, notificationReminderRunListResponseSchema, notificationReminderRunRecordSchema, notificationReminderRunRuleSummarySchema, notificationReminderRunStatusSchema, notificationReminderStageAnchorSchema, notificationReminderStageCadenceIntervalSchema, notificationReminderStageCadenceKindSchema, notificationReminderStatusSchema, notificationReminderTargetTypeSchema, notificationStageRecipientKindSchema, notificationTargetTypeSchema, notificationTemplateListQuerySchema, notificationTemplateStatusSchema, previewNotificationTemplateResultSchema, previewNotificationTemplateSchema, previewRemindersQuerySchema, reorderReminderRuleStagesSchema, runDueRemindersSchema, sendBookingDocumentsNotificationResultSchema, sendBookingDocumentsNotificationSchema, sendInvoiceNotificationSchema, sendNotificationSchema, sendPaymentSessionNotificationSchema, updateNotificationReminderRuleSchema, updateNotificationReminderRuleStageSchema, updateNotificationReminderStageChannelSchema, updateNotificationSettingsSchema, updateNotificationTemplateSchema, } from "./validation.js";
21
+ function logDocumentBundleLifecycleFailure(input, message) {
22
+ console.error(`[notifications] document-bundle lifecycle failed for ${input.trigger} booking ${input.event.bookingId}: ${message}`);
23
+ }
24
+ export function createNotificationsHonoModule(options) {
25
+ const routes = createNotificationsRoutes(options);
26
+ const module = {
27
+ ...notificationsModule,
28
+ bootstrap: ({ bindings, container, eventBus }) => {
29
+ container.register(NOTIFICATIONS_ROUTE_RUNTIME_CONTAINER_KEY, buildNotificationsRouteRuntime(bindings, options));
30
+ // Auto-dispatch wiring — opt-in. When enabled, every `booking.confirmed`
31
+ // event triggers a `confirmAndDispatchBooking` call so the operator
32
+ // doesn't have to click a second button. The handler runs in the same
33
+ // process as the emitter (the in-process event bus) but outside the
34
+ // request scope, so we resolve our own db handle from bindings.
35
+ if (options?.autoConfirmAndDispatch?.enabled && options.resolveDb) {
36
+ const resolveDb = options.resolveDb;
37
+ const autoOptions = options.autoConfirmAndDispatch;
38
+ const runtime = buildNotificationsRouteRuntime(bindings, options);
39
+ const dispatcher = createNotificationService(runtime.providers);
40
+ eventBus.subscribe("booking.confirmed", async (event) => {
41
+ // Honor caller opt-out — the operator may want to confirm
42
+ // a booking without firing the customer-facing email/doc
43
+ // bundle (e.g. data correction, manual hand-off).
44
+ if (event.data.suppressNotifications === true)
45
+ return;
46
+ try {
47
+ // The resolver may return either drizzle flavor; the queries
48
+ // bookingDocumentNotificationsService runs are compatible with
49
+ // both at runtime, so we narrow at this internal boundary.
50
+ const db = resolveDb(bindings);
51
+ await bookingDocumentNotificationsService.confirmAndDispatchBooking(db, dispatcher, event.data.bookingId, {
52
+ templateSlug: autoOptions.templateSlug ?? null,
53
+ documentTypes: autoOptions.documentTypes ?? null,
54
+ }, {
55
+ attachmentResolver: runtime.documentAttachmentResolver,
56
+ eventBus,
57
+ });
58
+ }
59
+ catch (error) {
60
+ // Per the EventBus contract, handler failures are logged, not
61
+ // rethrown. We surface the context so ops can diagnose without
62
+ // digging through stack traces.
63
+ const message = error instanceof Error ? error.message : String(error);
64
+ console.error(`[notifications] auto-dispatch failed for booking ${event.data.bookingId}: ${message}`);
65
+ }
66
+ });
67
+ }
68
+ if (options?.documentBundleLifecycle?.enabled && options.resolveDb) {
69
+ const resolveDb = options.resolveDb;
70
+ const lifecycleOptions = options.documentBundleLifecycle;
71
+ const runtime = buildNotificationsRouteRuntime(bindings, options);
72
+ const dispatcher = createNotificationService(runtime.providers);
73
+ const runLifecycle = async (input) => {
74
+ try {
75
+ const db = resolveDb(bindings);
76
+ const result = await bookingDocumentBundleLifecycleService.run(db, dispatcher, input, lifecycleOptions, { attachmentResolver: runtime.documentAttachmentResolver, eventBus });
77
+ if (result.status === "failed") {
78
+ logDocumentBundleLifecycleFailure(input, result.error);
79
+ }
80
+ }
81
+ catch (error) {
82
+ const message = error instanceof Error ? error.message : String(error);
83
+ logDocumentBundleLifecycleFailure(input, message);
84
+ }
85
+ };
86
+ eventBus.subscribe("booking.confirmed", async (event) => {
87
+ await runLifecycle({ trigger: "booking.confirmed", event: event.data });
88
+ });
89
+ eventBus.subscribe(BOOKING_FULLY_PAID_EVENT, async (event) => {
90
+ await runLifecycle({ trigger: BOOKING_FULLY_PAID_EVENT, event: event.data });
91
+ });
92
+ eventBus.subscribe("payment.completed", async (event) => {
93
+ if (!event.data.bookingId) {
94
+ return;
95
+ }
96
+ try {
97
+ const db = resolveDb(bindings);
98
+ const isPaidInFull = await bookingIsPaidInFullForNotification(db, event.data.bookingId);
99
+ if (!isPaidInFull) {
100
+ return;
101
+ }
102
+ await eventBus.emit(BOOKING_FULLY_PAID_EVENT, {
103
+ bookingId: event.data.bookingId,
104
+ paymentSessionId: event.data.paymentSessionId,
105
+ invoiceId: event.data.invoiceId ?? null,
106
+ amountCents: event.data.amountCents,
107
+ currency: event.data.currency,
108
+ provider: event.data.provider,
109
+ }, { category: "domain", source: "subscriber" });
110
+ }
111
+ catch (error) {
112
+ const message = error instanceof Error ? error.message : String(error);
113
+ console.error(`[notifications] booking.fully-paid dispatch failed for booking ${event.data.bookingId}: ${message}`);
114
+ }
115
+ });
116
+ }
117
+ if (options?.resolveDb) {
118
+ const resolveDb = options.resolveDb;
119
+ const runtime = buildNotificationsRouteRuntime(bindings, options);
120
+ const dispatcher = createNotificationService(runtime.providers);
121
+ eventBus.subscribe("booking.confirmed", async (event) => {
122
+ try {
123
+ const db = resolveDb(bindings);
124
+ await dispatchReminderEventRules(db, dispatcher, {
125
+ targetType: "booking_confirmed",
126
+ bookingId: event.data.bookingId,
127
+ eventData: event.data,
128
+ }, { documentAttachmentResolver: runtime.documentAttachmentResolver });
129
+ }
130
+ catch (error) {
131
+ const message = error instanceof Error ? error.message : String(error);
132
+ console.error(`[notifications] booking_confirmed reminder rules failed for booking ${event.data.bookingId}: ${message}`);
133
+ }
134
+ });
135
+ eventBus.subscribe("payment.completed", async (event) => {
136
+ if (!event.data.bookingId) {
137
+ return;
138
+ }
139
+ try {
140
+ const db = resolveDb(bindings);
141
+ const isPaidInFull = await bookingIsPaidInFullForNotification(db, event.data.bookingId);
142
+ if (!isPaidInFull) {
143
+ return;
144
+ }
145
+ await dispatchReminderEventRules(db, dispatcher, {
146
+ targetType: "payment_complete",
147
+ bookingId: event.data.bookingId,
148
+ paymentSessionId: event.data.paymentSessionId,
149
+ eventData: event.data,
150
+ }, { documentAttachmentResolver: runtime.documentAttachmentResolver });
151
+ }
152
+ catch (error) {
153
+ const message = error instanceof Error ? error.message : String(error);
154
+ console.error(`[notifications] payment_complete reminder rules failed for booking ${event.data.bookingId}: ${message}`);
155
+ }
156
+ });
157
+ eventBus.subscribe("booking.cancelled", async (event) => {
158
+ if (event.data.previousStatus !== "on_hold") {
159
+ return;
160
+ }
161
+ try {
162
+ const db = resolveDb(bindings);
163
+ await dispatchReminderEventRules(db, dispatcher, {
164
+ targetType: "booking_cancelled_non_payment",
165
+ bookingId: event.data.bookingId,
166
+ eventData: event.data,
167
+ }, { documentAttachmentResolver: runtime.documentAttachmentResolver });
168
+ }
169
+ catch (error) {
170
+ const message = error instanceof Error ? error.message : String(error);
171
+ console.error(`[notifications] booking_cancelled_non_payment reminder rules failed for booking ${event.data.bookingId}: ${message}`);
172
+ }
173
+ });
174
+ eventBus.subscribe("booking.expired", async (event) => {
175
+ try {
176
+ const db = resolveDb(bindings);
177
+ await dispatchReminderEventRules(db, dispatcher, {
178
+ targetType: "booking_cancelled_non_payment",
179
+ bookingId: event.data.bookingId,
180
+ eventData: event.data,
181
+ }, { documentAttachmentResolver: runtime.documentAttachmentResolver });
182
+ }
183
+ catch (error) {
184
+ const message = error instanceof Error ? error.message : String(error);
185
+ console.error(`[notifications] booking_cancelled_non_payment reminder rules failed for expired booking ${event.data.bookingId}: ${message}`);
186
+ }
187
+ });
188
+ }
189
+ },
190
+ };
191
+ return {
192
+ module,
193
+ adminRoutes: routes,
194
+ routes,
195
+ };
196
+ }