@voyant-travel/hono 0.109.1

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 (105) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +58 -0
  3. package/dist/app-workflows.d.ts +31 -0
  4. package/dist/app-workflows.d.ts.map +1 -0
  5. package/dist/app-workflows.js +110 -0
  6. package/dist/app.d.ts +45 -0
  7. package/dist/app.d.ts.map +1 -0
  8. package/dist/app.js +403 -0
  9. package/dist/auth/crypto.d.ts +16 -0
  10. package/dist/auth/crypto.d.ts.map +1 -0
  11. package/dist/auth/crypto.js +66 -0
  12. package/dist/auth/index.d.ts +5 -0
  13. package/dist/auth/index.d.ts.map +1 -0
  14. package/dist/auth/index.js +3 -0
  15. package/dist/auth/require-user.d.ts +3 -0
  16. package/dist/auth/require-user.d.ts.map +1 -0
  17. package/dist/auth/require-user.js +8 -0
  18. package/dist/auth/session-jwt.d.ts +7 -0
  19. package/dist/auth/session-jwt.d.ts.map +1 -0
  20. package/dist/auth/session-jwt.js +23 -0
  21. package/dist/composition.d.ts +67 -0
  22. package/dist/composition.d.ts.map +1 -0
  23. package/dist/composition.js +46 -0
  24. package/dist/document-download.d.ts +30 -0
  25. package/dist/document-download.d.ts.map +1 -0
  26. package/dist/document-download.js +102 -0
  27. package/dist/index.d.ts +17 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +9 -0
  30. package/dist/lib/db-selector.d.ts +24 -0
  31. package/dist/lib/db-selector.d.ts.map +1 -0
  32. package/dist/lib/db-selector.js +28 -0
  33. package/dist/lib/execution-ctx.d.ts +16 -0
  34. package/dist/lib/execution-ctx.d.ts.map +1 -0
  35. package/dist/lib/execution-ctx.js +16 -0
  36. package/dist/lib/public-paths.d.ts +19 -0
  37. package/dist/lib/public-paths.d.ts.map +1 -0
  38. package/dist/lib/public-paths.js +27 -0
  39. package/dist/lib/request-event-bus.d.ts +21 -0
  40. package/dist/lib/request-event-bus.d.ts.map +1 -0
  41. package/dist/lib/request-event-bus.js +43 -0
  42. package/dist/middleware/auth.d.ts +10 -0
  43. package/dist/middleware/auth.d.ts.map +1 -0
  44. package/dist/middleware/auth.js +280 -0
  45. package/dist/middleware/body-size.d.ts +7 -0
  46. package/dist/middleware/body-size.d.ts.map +1 -0
  47. package/dist/middleware/body-size.js +20 -0
  48. package/dist/middleware/cors.d.ts +6 -0
  49. package/dist/middleware/cors.d.ts.map +1 -0
  50. package/dist/middleware/cors.js +94 -0
  51. package/dist/middleware/db.d.ts +43 -0
  52. package/dist/middleware/db.d.ts.map +1 -0
  53. package/dist/middleware/db.js +78 -0
  54. package/dist/middleware/error-boundary.d.ts +5 -0
  55. package/dist/middleware/error-boundary.d.ts.map +1 -0
  56. package/dist/middleware/error-boundary.js +76 -0
  57. package/dist/middleware/idempotency-key.d.ts +97 -0
  58. package/dist/middleware/idempotency-key.d.ts.map +1 -0
  59. package/dist/middleware/idempotency-key.js +235 -0
  60. package/dist/middleware/index.d.ts +14 -0
  61. package/dist/middleware/index.d.ts.map +1 -0
  62. package/dist/middleware/index.js +13 -0
  63. package/dist/middleware/logger.d.ts +5 -0
  64. package/dist/middleware/logger.d.ts.map +1 -0
  65. package/dist/middleware/logger.js +27 -0
  66. package/dist/middleware/metrics.d.ts +55 -0
  67. package/dist/middleware/metrics.d.ts.map +1 -0
  68. package/dist/middleware/metrics.js +94 -0
  69. package/dist/middleware/public-cache.d.ts +44 -0
  70. package/dist/middleware/public-cache.d.ts.map +1 -0
  71. package/dist/middleware/public-cache.js +205 -0
  72. package/dist/middleware/rate-limit.d.ts +214 -0
  73. package/dist/middleware/rate-limit.d.ts.map +1 -0
  74. package/dist/middleware/rate-limit.js +240 -0
  75. package/dist/middleware/request-db.d.ts +42 -0
  76. package/dist/middleware/request-db.d.ts.map +1 -0
  77. package/dist/middleware/request-db.js +62 -0
  78. package/dist/middleware/require-actor.d.ts +28 -0
  79. package/dist/middleware/require-actor.d.ts.map +1 -0
  80. package/dist/middleware/require-actor.js +89 -0
  81. package/dist/middleware/require-permission.d.ts +9 -0
  82. package/dist/middleware/require-permission.d.ts.map +1 -0
  83. package/dist/middleware/require-permission.js +62 -0
  84. package/dist/middleware/security-headers.d.ts +10 -0
  85. package/dist/middleware/security-headers.d.ts.map +1 -0
  86. package/dist/middleware/security-headers.js +19 -0
  87. package/dist/module.d.ts +41 -0
  88. package/dist/module.d.ts.map +1 -0
  89. package/dist/module.js +1 -0
  90. package/dist/plugin.d.ts +66 -0
  91. package/dist/plugin.d.ts.map +1 -0
  92. package/dist/plugin.js +37 -0
  93. package/dist/public-capability.d.ts +46 -0
  94. package/dist/public-capability.d.ts.map +1 -0
  95. package/dist/public-capability.js +140 -0
  96. package/dist/public-document-delivery.d.ts +111 -0
  97. package/dist/public-document-delivery.d.ts.map +1 -0
  98. package/dist/public-document-delivery.js +234 -0
  99. package/dist/types.d.ts +318 -0
  100. package/dist/types.d.ts.map +1 -0
  101. package/dist/types.js +29 -0
  102. package/dist/validation.d.ts +36 -0
  103. package/dist/validation.d.ts.map +1 -0
  104. package/dist/validation.js +106 -0
  105. package/package.json +156 -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,58 @@
1
+ # @voyant-travel/hono
2
+
3
+ Hono transport adapter for Voyant. Provides `createApp()`, middleware, auth
4
+ helpers, and plugin expansion for mounting Voyant modules behind a Hono app.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pnpm add @voyant-travel/hono hono
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```typescript
15
+ import { createApp } from "@voyant-travel/hono"
16
+
17
+ const app = createApp({
18
+ db: (env) => getDb(env),
19
+ auth: { handler, resolve },
20
+ modules: [crmModule, productsModule, bookingsModule],
21
+ extensions: [smartbillFinanceExtension],
22
+ plugins: [
23
+ payloadCmsPlugin({
24
+ /* optional distribution bundle */
25
+ }),
26
+ ],
27
+ })
28
+ ```
29
+
30
+ Use `modules`, `extensions`, and provider-backed route helpers as the default
31
+ composition surface. Use `plugins` when you want to register a reusable
32
+ distribution bundle that packages those pieces together.
33
+
34
+ The middleware chain is: container → requestId → logger → errorBoundary → CORS → health → auth handler → requireAuth → db → actor guards → module routes.
35
+
36
+ ## Exports
37
+
38
+ | Entry | Description |
39
+ | --- | --- |
40
+ | `.` | Barrel re-exports |
41
+ | `./app` | `createApp` factory |
42
+ | `./module` | `HonoModule`, `HonoExtension` contracts |
43
+ | `./plugin` | `HonoPlugin`, `defineHonoPlugin`, `expandHonoPlugins` |
44
+ | `./middleware` | All middleware re-exports |
45
+ | `./middleware/auth` | `requireAuth` session/API-key/JWT auth |
46
+ | `./middleware/cors` | CORS configuration |
47
+ | `./middleware/error-boundary` | Error handling + JSON error envelope |
48
+ | `./middleware/db` | Attach db client to `c.var.db` |
49
+ | `./middleware/rate-limit` | KV-backed rate limiter |
50
+ | `./middleware/require-actor` | Enforce `staff`/`customer`/`partner`/`supplier` actor |
51
+ | `./middleware/require-permission` | Permission-based guards |
52
+ | `./middleware/logger` | Request logger |
53
+ | `./auth/session-jwt` | `verifySession` shared-secret bearer/session-claims verification |
54
+ | `./auth/crypto` | `sha256Base64Url`, cookie helpers |
55
+
56
+ ## License
57
+
58
+ Apache-2.0
@@ -0,0 +1,31 @@
1
+ import type { EventEnvelope, EventFilterDescriptor, Module, ModuleContainer, WorkflowDescriptor } from "@voyant-travel/core";
2
+ import type { WorkflowDriver } from "@voyant-travel/workflows/driver";
3
+ import type { VoyantAppConfig } from "./types.js";
4
+ export interface WireWorkflowRuntimeArgs {
5
+ modules: ReadonlyArray<Module>;
6
+ collectedWorkflows: ReadonlyArray<WorkflowDescriptor>;
7
+ collectedFilters: ReadonlyArray<EventFilterDescriptor>;
8
+ driver: WorkflowDriver;
9
+ environment: "production" | "preview" | "development";
10
+ projectId: string;
11
+ eventBus: {
12
+ subscribe(event: string, handler: (e: EventEnvelope) => Promise<void> | void): unknown;
13
+ };
14
+ }
15
+ /**
16
+ * Build the manifest, register it with the driver, and install a single
17
+ * EventBus subscriber per unique eventType seen across the manifest's filters.
18
+ */
19
+ export declare function wireWorkflowRuntime(args: WireWorkflowRuntimeArgs): Promise<void>;
20
+ /**
21
+ * Adapt the framework's `ModuleContainer` to a read-only `ServiceResolver`.
22
+ */
23
+ export declare function containerToServiceResolver(container: ModuleContainer): {
24
+ resolve<T>(name: string): T;
25
+ has(name: string): boolean;
26
+ };
27
+ /**
28
+ * Adapt the framework's optional `LoggerProvider` to the workflow driver logger.
29
+ */
30
+ export declare function makeFrameworkLogger(loggerProvider: VoyantAppConfig["logger"] | undefined): (level: "debug" | "info" | "warn" | "error", msg: string, data?: object) => void;
31
+ //# sourceMappingURL=app-workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-workflows.d.ts","sourceRoot":"","sources":["../src/app-workflows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,MAAM,EACN,eAAe,EACf,kBAAkB,EACnB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAOrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AASjD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC9B,kBAAkB,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAA;IACrD,gBAAgB,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAA;IACtD,MAAM,EAAE,cAAc,CAAA;IACtB,WAAW,EAAE,YAAY,GAAG,SAAS,GAAG,aAAa,CAAA;IACrD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE;QACR,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAA;KACvF,CAAA;CACF;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoDtF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,eAAe,GAAG;IACtE,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAA;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CAC3B,CASA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,SAAS,GACpD,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAclF"}
@@ -0,0 +1,110 @@
1
+ import { buildManifest, } from "@voyant-travel/workflows/events";
2
+ function toManifestWorkflowDescriptor(wf) {
3
+ const candidate = wf;
4
+ return candidate.config ? { id: wf.id, config: candidate.config } : { id: wf.id };
5
+ }
6
+ /**
7
+ * Build the manifest, register it with the driver, and install a single
8
+ * EventBus subscriber per unique eventType seen across the manifest's filters.
9
+ */
10
+ export async function wireWorkflowRuntime(args) {
11
+ // The descriptors collected from modules + plugins use core's structural
12
+ // types (`{ id, eventType }` only - see `EventFilterDescriptor` in core);
13
+ // the manifest builder needs the runtime shape with `.manifest` populated.
14
+ // Validate before casting so a contract-violating plugin fails loudly here
15
+ // instead of crashing on `entry.manifest.id` deep inside the sort.
16
+ const filterEntries = [];
17
+ for (const entry of args.collectedFilters) {
18
+ const candidate = entry;
19
+ if (!candidate.manifest || typeof candidate.manifest.id !== "string") {
20
+ throw new Error(`[voyant] event filter "${entry.id}" (event "${entry.eventType}") is missing the runtime ` +
21
+ `\`manifest\` field. Filters must be produced via \`trigger.on(eventName, { ... })\` from ` +
22
+ `@voyant-travel/workflows - the public EventFilterDescriptor is the structural minimum, but ` +
23
+ `createApp() needs the manifest payload to register with the driver.`);
24
+ }
25
+ filterEntries.push(candidate);
26
+ }
27
+ const manifest = await buildManifest({
28
+ projectId: args.projectId,
29
+ environment: args.environment,
30
+ workflows: args.collectedWorkflows.map(toManifestWorkflowDescriptor),
31
+ eventFilters: filterEntries,
32
+ });
33
+ await args.driver.registerManifest({
34
+ environment: args.environment,
35
+ manifest,
36
+ });
37
+ // Install one EventBus subscriber per unique eventType. Each subscriber
38
+ // forwards the envelope through `driver.ingestEvent(...)`, which routes
39
+ // through the same predicate/mapper machinery the HTTP ingest path uses.
40
+ const eventTypes = new Set(filterEntries.map((f) => f.eventType));
41
+ for (const eventType of eventTypes) {
42
+ args.eventBus.subscribe(eventType, async (envelope) => {
43
+ const stamped = ensureMetadataEventId(envelope);
44
+ try {
45
+ await args.driver.ingestEvent({
46
+ environment: args.environment,
47
+ envelope: stamped,
48
+ });
49
+ }
50
+ catch (err) {
51
+ // Subscribers are observers per the EventBus contract - a misbehaving
52
+ // driver / network glitch must not break the emitter.
53
+ const message = err instanceof Error ? err.message : String(err);
54
+ console.error(`[voyant] workflow forwarder for "${eventType}" failed: ${message}`);
55
+ }
56
+ });
57
+ }
58
+ }
59
+ /**
60
+ * Adapt the framework's `ModuleContainer` to a read-only `ServiceResolver`.
61
+ */
62
+ export function containerToServiceResolver(container) {
63
+ return {
64
+ resolve(name) {
65
+ return container.resolve(name);
66
+ },
67
+ has(name) {
68
+ return container.has(name);
69
+ },
70
+ };
71
+ }
72
+ /**
73
+ * Adapt the framework's optional `LoggerProvider` to the workflow driver logger.
74
+ */
75
+ export function makeFrameworkLogger(loggerProvider) {
76
+ void loggerProvider;
77
+ return (level, msg, data) => {
78
+ const fn = level === "error"
79
+ ? console.error
80
+ : level === "warn"
81
+ ? console.warn
82
+ : level === "debug"
83
+ ? console.debug
84
+ : console.log;
85
+ if (data !== undefined)
86
+ fn(`[voyant] ${msg}`, data);
87
+ else
88
+ fn(`[voyant] ${msg}`);
89
+ };
90
+ }
91
+ function ensureMetadataEventId(envelope) {
92
+ const metadata = envelope.metadata;
93
+ if (metadata !== undefined &&
94
+ metadata !== null &&
95
+ typeof metadata === "object" &&
96
+ typeof metadata.eventId === "string" &&
97
+ (metadata.eventId.length ?? 0) > 0) {
98
+ return envelope;
99
+ }
100
+ const eventId = `evt_${Date.now().toString(36)}_${Math.floor(Math.random() * 1_000_000)
101
+ .toString(36)
102
+ .padStart(4, "0")}`;
103
+ return {
104
+ ...envelope,
105
+ metadata: {
106
+ ...(metadata ?? {}),
107
+ eventId,
108
+ },
109
+ };
110
+ }
package/dist/app.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { Hono } from "hono";
2
+ import type { VoyantAppConfig, VoyantBindings, VoyantVariables } from "./types.js";
3
+ /**
4
+ * App handle returned alongside the Hono instance. Carries `ready()` for
5
+ * headless / sibling-process deployments that need to fire the lazy
6
+ * bootstrap before the first HTTP request — workflow runtimes (Mode 2's
7
+ * sibling-process pattern, tests) call this so the time wheel and
8
+ * manifest registration kick off without traffic.
9
+ *
10
+ * Returned via the augmented Hono instance: `app.ready` is attached
11
+ * directly so the existing call sites (which destructure / pass `app`
12
+ * around) keep working without a wrapper.
13
+ */
14
+ export interface VoyantAppExtensions<TBindings = unknown> {
15
+ /**
16
+ * Resolves once the lazy bootstrap completes. Idempotent — multiple
17
+ * calls share the same promise. Use from tests + Mode 2 sibling
18
+ * processes where no request will arrive to trigger boot. See
19
+ * architecture doc §18 + §18.1.
20
+ *
21
+ * Accepts the runtime bindings that the bootstrap should run with. For
22
+ * binding-dependent configs (e.g. Mode 1 / Cloudflare, where the driver
23
+ * factory reads DO + KV bindings off `env`) callers MUST pass the real
24
+ * bindings; otherwise the memoized bootstrap promise locks in a driver
25
+ * built from `{}` and every later request reuses that broken instance.
26
+ * Mode 2 / InMemory drivers ignore bindings, so the no-arg form is safe
27
+ * there (defaults to `{}` for back-compat with tests).
28
+ */
29
+ ready(bindings?: TBindings): Promise<void>;
30
+ /**
31
+ * The app's event bus (with every module/plugin subscriber attached).
32
+ * Exposed for non-request contexts that must deliver events through
33
+ * the same subscriber set — the outbox drain in a scheduled handler
34
+ * being the canonical consumer:
35
+ *
36
+ * await app.ready(env)
37
+ * await withDbFromEnv(env, (db) => drainOutbox(db, app.eventBus))
38
+ */
39
+ eventBus: import("@voyant-travel/core").EventBus;
40
+ }
41
+ export declare function createApp<TBindings extends VoyantBindings>(config: VoyantAppConfig<TBindings>): Hono<{
42
+ Bindings: TBindings;
43
+ Variables: VoyantVariables;
44
+ }> & VoyantAppExtensions<TBindings>;
45
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AA4B3B,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAY,eAAe,EAAE,MAAM,YAAY,CAAA;AA2C5F;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB,CAAC,SAAS,GAAG,OAAO;IACtD;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1C;;;;;;;;OAQG;IACH,QAAQ,EAAE,OAAO,qBAAqB,EAAE,QAAQ,CAAA;CACjD;AAED,wBAAgB,SAAS,CAAC,SAAS,SAAS,cAAc,EACxD,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,GACjC,IAAI,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,CAAC,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAia5F"}