@voyant-travel/core 0.109.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.
- package/LICENSE +201 -0
- package/README.md +48 -0
- package/dist/config.d.ts +204 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +251 -0
- package/dist/config.js.map +1 -0
- package/dist/container.d.ts +20 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +21 -0
- package/dist/container.js.map +1 -0
- package/dist/env.d.ts +29 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +2 -0
- package/dist/env.js.map +1 -0
- package/dist/events.d.ts +177 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +169 -0
- package/dist/events.js.map +1 -0
- package/dist/hooks.d.ts +19 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +33 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/links.d.ts +201 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +159 -0
- package/dist/links.js.map +1 -0
- package/dist/locking.d.ts +12 -0
- package/dist/locking.d.ts.map +1 -0
- package/dist/locking.js +21 -0
- package/dist/locking.js.map +1 -0
- package/dist/module.d.ts +147 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/orchestration.d.ts +30 -0
- package/dist/orchestration.d.ts.map +1 -0
- package/dist/orchestration.js +2 -0
- package/dist/orchestration.js.map +1 -0
- package/dist/plugin.d.ts +118 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +65 -0
- package/dist/plugin.js.map +1 -0
- package/dist/query.d.ts +111 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +126 -0
- package/dist/query.js.map +1 -0
- package/dist/registry.d.ts +17 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +31 -0
- package/dist/registry.js.map +1 -0
- package/dist/workflows.d.ts +140 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +142 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +103 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voyant configuration manifest.
|
|
3
|
+
*
|
|
4
|
+
* `voyant.config.ts` is a **manifest**, not a runtime config — it exists to
|
|
5
|
+
* power tooling (CLI generators, registry resolution, `voyant db:sync-links`,
|
|
6
|
+
* deployment scripts). Runtime composition of modules, plugins, and
|
|
7
|
+
* middleware still happens in code via `createApp({ modules, plugins, ... })`.
|
|
8
|
+
*
|
|
9
|
+
* Shape mirrors Medusa's `defineConfig` so users familiar with that
|
|
10
|
+
* ecosystem can transfer their mental model directly.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Identity helper that returns the config as-is.
|
|
14
|
+
*
|
|
15
|
+
* Exists purely so authors can write `defineVoyantConfig({ ... })` and get
|
|
16
|
+
* type inference + IDE help without casting. Does not perform runtime
|
|
17
|
+
* validation — malformed manifests will surface at CLI/tooling consumption
|
|
18
|
+
* time via {@link validateVoyantConfig}.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // starters/operator/voyant.config.ts
|
|
23
|
+
* import { defineVoyantConfig } from "@voyant-travel/core/config"
|
|
24
|
+
*
|
|
25
|
+
* export default defineVoyantConfig({
|
|
26
|
+
* modules: ["crm", "bookings", "products", "finance", "suppliers"],
|
|
27
|
+
* plugins: ["payload-cms", "bokun"],
|
|
28
|
+
* deployment: "cloudflare-worker",
|
|
29
|
+
* admin: { enabled: true, path: "/app" },
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function defineVoyantConfig(config) {
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Lightweight structural validation for a {@link VoyantConfig} manifest.
|
|
38
|
+
*
|
|
39
|
+
* Checks only shape/identity: field types, non-empty identifiers, no
|
|
40
|
+
* duplicate module/plugin names. It does **not** resolve package names or
|
|
41
|
+
* check that referenced modules exist on disk — that is CLI/tooling
|
|
42
|
+
* territory.
|
|
43
|
+
*
|
|
44
|
+
* Returns a result object rather than throwing so callers can choose how
|
|
45
|
+
* to surface issues (pretty printing, aggregating, etc.).
|
|
46
|
+
*/
|
|
47
|
+
export function validateVoyantConfig(config) {
|
|
48
|
+
const issues = [];
|
|
49
|
+
if (config === null || typeof config !== "object") {
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
issues: [{ path: "", message: "Config must be an object." }],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const cfg = config;
|
|
56
|
+
if (cfg.modules !== undefined) {
|
|
57
|
+
if (!Array.isArray(cfg.modules)) {
|
|
58
|
+
issues.push({ path: "modules", message: "Expected an array." });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
cfg.modules.forEach((entry, index) => {
|
|
63
|
+
const name = extractEntryName(entry);
|
|
64
|
+
if (!name) {
|
|
65
|
+
issues.push({
|
|
66
|
+
path: `modules[${index}]`,
|
|
67
|
+
message: "Module entry must be a non-empty string or an object with a `resolve` string.",
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (seen.has(name)) {
|
|
72
|
+
issues.push({
|
|
73
|
+
path: `modules[${index}]`,
|
|
74
|
+
message: `Duplicate module "${name}".`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
seen.add(name);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (cfg.plugins !== undefined) {
|
|
82
|
+
if (!Array.isArray(cfg.plugins)) {
|
|
83
|
+
issues.push({ path: "plugins", message: "Expected an array." });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
cfg.plugins.forEach((entry, index) => {
|
|
88
|
+
const name = extractEntryName(entry);
|
|
89
|
+
if (!name) {
|
|
90
|
+
issues.push({
|
|
91
|
+
path: `plugins[${index}]`,
|
|
92
|
+
message: "Plugin entry must be a non-empty string or an object with a `resolve` string.",
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (seen.has(name)) {
|
|
97
|
+
issues.push({
|
|
98
|
+
path: `plugins[${index}]`,
|
|
99
|
+
message: `Duplicate plugin "${name}".`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
seen.add(name);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (cfg.extensions !== undefined) {
|
|
107
|
+
if (!Array.isArray(cfg.extensions)) {
|
|
108
|
+
issues.push({ path: "extensions", message: "Expected an array." });
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const seen = new Set();
|
|
112
|
+
cfg.extensions.forEach((entry, index) => {
|
|
113
|
+
const name = extractEntryName(entry);
|
|
114
|
+
if (!name) {
|
|
115
|
+
issues.push({
|
|
116
|
+
path: `extensions[${index}]`,
|
|
117
|
+
message: "Extension entry must be a non-empty string or an object with a `resolve` string.",
|
|
118
|
+
});
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (seen.has(name)) {
|
|
122
|
+
issues.push({ path: `extensions[${index}]`, message: `Duplicate extension "${name}".` });
|
|
123
|
+
}
|
|
124
|
+
seen.add(name);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (cfg.additionalSchemas !== undefined) {
|
|
129
|
+
if (!Array.isArray(cfg.additionalSchemas)) {
|
|
130
|
+
issues.push({ path: "additionalSchemas", message: "Expected an array." });
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const seen = new Set();
|
|
134
|
+
cfg.additionalSchemas.forEach((entry, index) => {
|
|
135
|
+
const name = extractEntryName(entry);
|
|
136
|
+
if (!name) {
|
|
137
|
+
issues.push({
|
|
138
|
+
path: `additionalSchemas[${index}]`,
|
|
139
|
+
message: "additionalSchemas entry must be a non-empty string or an object with a `resolve` string.",
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (seen.has(name)) {
|
|
144
|
+
issues.push({
|
|
145
|
+
path: `additionalSchemas[${index}]`,
|
|
146
|
+
message: `Duplicate additionalSchemas entry "${name}".`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
seen.add(name);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (cfg.schemas !== undefined) {
|
|
154
|
+
if (!Array.isArray(cfg.schemas)) {
|
|
155
|
+
issues.push({ path: "schemas", message: "Expected an array of file-path strings." });
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
cfg.schemas.forEach((entry, index) => {
|
|
159
|
+
if (typeof entry !== "string" || entry.trim().length === 0) {
|
|
160
|
+
issues.push({
|
|
161
|
+
path: `schemas[${index}]`,
|
|
162
|
+
message: "schemas entry must be a non-empty file-path string.",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (cfg.admin !== undefined) {
|
|
169
|
+
if (cfg.admin === null || typeof cfg.admin !== "object" || Array.isArray(cfg.admin)) {
|
|
170
|
+
issues.push({ path: "admin", message: "Expected an object." });
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const admin = cfg.admin;
|
|
174
|
+
if (admin.enabled !== undefined && typeof admin.enabled !== "boolean") {
|
|
175
|
+
issues.push({ path: "admin.enabled", message: "Expected a boolean." });
|
|
176
|
+
}
|
|
177
|
+
if (admin.path !== undefined && typeof admin.path !== "string") {
|
|
178
|
+
issues.push({ path: "admin.path", message: "Expected a string." });
|
|
179
|
+
}
|
|
180
|
+
if (admin.backendUrl !== undefined && typeof admin.backendUrl !== "string") {
|
|
181
|
+
issues.push({ path: "admin.backendUrl", message: "Expected a string." });
|
|
182
|
+
}
|
|
183
|
+
if (admin.routes !== undefined) {
|
|
184
|
+
if (admin.routes === null ||
|
|
185
|
+
typeof admin.routes !== "object" ||
|
|
186
|
+
Array.isArray(admin.routes)) {
|
|
187
|
+
issues.push({ path: "admin.routes", message: "Expected an object." });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const routes = admin.routes;
|
|
191
|
+
for (const field of [
|
|
192
|
+
"dir",
|
|
193
|
+
"apiUrlModule",
|
|
194
|
+
"apiUrlExport",
|
|
195
|
+
"fetcherModule",
|
|
196
|
+
"fetcherExport",
|
|
197
|
+
]) {
|
|
198
|
+
if (routes[field] !== undefined && typeof routes[field] !== "string") {
|
|
199
|
+
issues.push({ path: `admin.routes.${field}`, message: "Expected a string." });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (cfg.featureFlags !== undefined) {
|
|
207
|
+
if (cfg.featureFlags === null ||
|
|
208
|
+
typeof cfg.featureFlags !== "object" ||
|
|
209
|
+
Array.isArray(cfg.featureFlags)) {
|
|
210
|
+
issues.push({ path: "featureFlags", message: "Expected an object of booleans." });
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
for (const [key, value] of Object.entries(cfg.featureFlags)) {
|
|
214
|
+
if (typeof value !== "boolean") {
|
|
215
|
+
issues.push({
|
|
216
|
+
path: `featureFlags.${key}`,
|
|
217
|
+
message: "Expected a boolean.",
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (cfg.deployment !== undefined && typeof cfg.deployment !== "string") {
|
|
224
|
+
issues.push({ path: "deployment", message: "Expected a string." });
|
|
225
|
+
}
|
|
226
|
+
return { ok: issues.length === 0, issues };
|
|
227
|
+
}
|
|
228
|
+
function extractEntryName(entry) {
|
|
229
|
+
if (typeof entry === "string") {
|
|
230
|
+
return entry.trim().length > 0 ? entry : null;
|
|
231
|
+
}
|
|
232
|
+
if (entry !== null && typeof entry === "object" && "resolve" in entry) {
|
|
233
|
+
const resolve = entry.resolve;
|
|
234
|
+
if (typeof resolve === "string" && resolve.trim().length > 0) {
|
|
235
|
+
return resolve;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Normalize a {@link ModuleEntry} or {@link PluginEntry} into the canonical
|
|
242
|
+
* `{ resolve, options }` object shape. Accepts string shorthand and inline
|
|
243
|
+
* descriptors alike.
|
|
244
|
+
*/
|
|
245
|
+
export function resolveEntry(entry) {
|
|
246
|
+
if (typeof entry === "string") {
|
|
247
|
+
return { resolve: entry, options: {} };
|
|
248
|
+
}
|
|
249
|
+
return { resolve: entry.resolve, options: entry.options ?? {} };
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgJH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAyB,MAAS;IAClE,OAAO,MAAM,CAAA;AACf,CAAC;AAsBD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAClD,MAAM,MAAM,GAA4B,EAAE,CAAA;IAE1C,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC;SAC7D,CAAA;IACH,CAAC;IAED,MAAM,GAAG,GAAG,MAAiC,CAAA;IAE7C,IAAI,GAAG,CA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,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7D,OAAO,OAAO,CAAA;QAChB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAQ;IAER,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IACxC,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE,EAAE,CAAA;AACjE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lightweight shared app/runtime container for explicit service resolution.
|
|
3
|
+
*
|
|
4
|
+
* Routes, workflows, subscribers, and bootstraps use this container to resolve
|
|
5
|
+
* app-owned runtime services. It is intentionally minimal (Map-based) — for
|
|
6
|
+
* richer DI (scoping, factory lifetimes) a template can wrap or replace it.
|
|
7
|
+
*/
|
|
8
|
+
export interface ModuleContainer {
|
|
9
|
+
/** Register a service by name. Overwrites any existing registration. */
|
|
10
|
+
register(name: string, service: unknown): void;
|
|
11
|
+
/** Resolve a service by name. Throws if not registered. */
|
|
12
|
+
resolve<T>(name: string): T;
|
|
13
|
+
/** Check if a service is registered. */
|
|
14
|
+
has(name: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a new module container backed by an in-memory Map.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createContainer(): ModuleContainer;
|
|
20
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IAE9C,2DAA2D;IAC3D,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAA;IAE3B,wCAAwC;IACxC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CAC3B;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAiBjD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a new module container backed by an in-memory Map.
|
|
3
|
+
*/
|
|
4
|
+
export function createContainer() {
|
|
5
|
+
const services = new Map();
|
|
6
|
+
return {
|
|
7
|
+
register(name, service) {
|
|
8
|
+
services.set(name, service);
|
|
9
|
+
},
|
|
10
|
+
resolve(name) {
|
|
11
|
+
if (!services.has(name)) {
|
|
12
|
+
throw new Error(`Service "${name}" is not registered in the container`);
|
|
13
|
+
}
|
|
14
|
+
return services.get(name);
|
|
15
|
+
},
|
|
16
|
+
has(name) {
|
|
17
|
+
return services.has(name);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAA;IAE3C,OAAO;QACL,QAAQ,CAAC,IAAI,EAAE,OAAO;YACpB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC7B,CAAC;QACD,OAAO,CAAI,IAAY;YACrB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,sCAAsC,CAAC,CAAA;YACzE,CAAC;YACD,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAM,CAAA;QAChC,CAAC;QACD,GAAG,CAAC,IAAI;YACN,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type VoyantCallerType = "session" | "api_key" | "internal";
|
|
2
|
+
/**
|
|
3
|
+
* Who the request represents. Routes under `/v1/admin/*` expect `"staff"`;
|
|
4
|
+
* `/v1/public/*` expects customer/partner/supplier actors.
|
|
5
|
+
*
|
|
6
|
+
* When unset, middleware treats the request as `"staff"` to preserve
|
|
7
|
+
* backwards compatibility with internal-only deployments.
|
|
8
|
+
*/
|
|
9
|
+
export type Actor = "staff" | "customer" | "partner" | "supplier";
|
|
10
|
+
export interface VoyantAuthContext {
|
|
11
|
+
userId?: string;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
organizationId?: string | null;
|
|
14
|
+
callerType?: VoyantCallerType;
|
|
15
|
+
actor?: Actor;
|
|
16
|
+
scopes?: string[] | null;
|
|
17
|
+
isInternalRequest?: boolean;
|
|
18
|
+
apiTokenId?: string;
|
|
19
|
+
apiKeyId?: string;
|
|
20
|
+
email?: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface VoyantPermission {
|
|
23
|
+
resource: string;
|
|
24
|
+
action: string;
|
|
25
|
+
}
|
|
26
|
+
export type VoyantVariables = VoyantAuthContext & {
|
|
27
|
+
db: unknown;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAA;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAA;AAEjE,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IAChD,EAAE,EAAE,OAAO,CAAA;CACZ,CAAA"}
|
package/dist/env.js
ADDED
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":""}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level classification for public event consumers.
|
|
3
|
+
*
|
|
4
|
+
* - `domain` events represent business milestones that other modules or
|
|
5
|
+
* external integrations may reasonably care about.
|
|
6
|
+
* - `internal` events are service/process signals that remain useful for
|
|
7
|
+
* subscribers, diagnostics, and automation, but are not part of the core
|
|
8
|
+
* business language.
|
|
9
|
+
*/
|
|
10
|
+
export type EventCategory = "domain" | "internal";
|
|
11
|
+
/**
|
|
12
|
+
* Where an event was emitted from. This helps consumers understand whether
|
|
13
|
+
* an event originated from a workflow boundary, a lower-level service, or a
|
|
14
|
+
* transport/runtime edge.
|
|
15
|
+
*/
|
|
16
|
+
export type EventSource = "workflow" | "service" | "route" | "subscriber" | "system";
|
|
17
|
+
/**
|
|
18
|
+
* Optional metadata attached to an emitted event.
|
|
19
|
+
*
|
|
20
|
+
* Templates and adapters may extend this with runtime-specific fields such as
|
|
21
|
+
* correlation identifiers or delivery handles.
|
|
22
|
+
*/
|
|
23
|
+
export interface EventMetadata {
|
|
24
|
+
category?: EventCategory;
|
|
25
|
+
source?: EventSource;
|
|
26
|
+
correlationId?: string;
|
|
27
|
+
causationId?: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Standard event envelope delivered to subscribers.
|
|
32
|
+
*/
|
|
33
|
+
export interface EventEnvelope<TData = unknown, TMetadata extends EventMetadata | undefined = EventMetadata | undefined> {
|
|
34
|
+
/** Event name, following the `<resource>.<pastTenseAction>` convention. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Business payload emitted by the caller. */
|
|
37
|
+
data: TData;
|
|
38
|
+
/** Optional metadata for source/taxonomy/tracing. */
|
|
39
|
+
metadata?: TMetadata;
|
|
40
|
+
/** ISO timestamp indicating when the event was emitted. */
|
|
41
|
+
emittedAt: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Event handler callback invoked when a subscribed event is emitted.
|
|
45
|
+
*/
|
|
46
|
+
export type EventHandler<TData = unknown, TMetadata extends EventMetadata | undefined = EventMetadata | undefined> = (event: EventEnvelope<TData, TMetadata>) => Promise<void> | void;
|
|
47
|
+
/**
|
|
48
|
+
* Subscription handle returned from {@link EventBus.subscribe}.
|
|
49
|
+
*
|
|
50
|
+
* Call `unsubscribe()` to remove the handler.
|
|
51
|
+
*/
|
|
52
|
+
export interface Subscription {
|
|
53
|
+
unsubscribe(): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Abstract event bus interface. Implementations live in templates or plugins.
|
|
57
|
+
*
|
|
58
|
+
* Adapter examples:
|
|
59
|
+
* - In-process (default, ships with core)
|
|
60
|
+
* - Cloudflare Queues — edge-native
|
|
61
|
+
* - Postgres-backed durable queue — for refund-saga-grade durability
|
|
62
|
+
*
|
|
63
|
+
* Event naming convention: `<resource>.<pastTenseAction>` in dot-case.
|
|
64
|
+
* Examples: `booking.created`, `quote.accepted`, `payment.received`.
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Per-subscription options.
|
|
68
|
+
*/
|
|
69
|
+
export interface SubscribeOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Inline handlers complete before `emit()` resolves even when the
|
|
72
|
+
* emitter supplies a deferral scheduler (see {@link EmitOptions}).
|
|
73
|
+
* Use for the rare subscriber whose side effects must be visible to
|
|
74
|
+
* the code that follows the emit (e.g. read-after-write within the
|
|
75
|
+
* same request). Default `false` — handlers are deferrable.
|
|
76
|
+
*/
|
|
77
|
+
inline?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Per-emit options. Call sites normally omit this; runtime adapters
|
|
81
|
+
* (e.g. `@voyant-travel/hono`'s request-scoped bus) supply `schedule` so
|
|
82
|
+
* deferrable handlers run after the HTTP response instead of blocking
|
|
83
|
+
* it.
|
|
84
|
+
*/
|
|
85
|
+
export interface EmitOptions {
|
|
86
|
+
/**
|
|
87
|
+
* Receives a single promise covering all deferrable (non-`inline`)
|
|
88
|
+
* handlers for this emit. When provided, `emit()` resolves after the
|
|
89
|
+
* `inline` handlers only; the scheduler owns keeping the runtime
|
|
90
|
+
* alive for the rest (Workers: `executionCtx.waitUntil`). When
|
|
91
|
+
* omitted, all handlers complete before `emit()` resolves.
|
|
92
|
+
*/
|
|
93
|
+
schedule?: (pending: Promise<unknown>) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Transactional-outbox store for this emit. When present, the
|
|
96
|
+
* envelope is persisted BEFORE any handler runs; after all handlers
|
|
97
|
+
* settle the row is completed (every handler succeeded) or failed
|
|
98
|
+
* (at least one error/timeout — the store schedules the retry).
|
|
99
|
+
* A `null` return from `insert` means the event was already captured
|
|
100
|
+
* (duplicate `metadata.eventId`) and delivery is skipped entirely.
|
|
101
|
+
*/
|
|
102
|
+
store?: OutboxEventStore;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Minimal persistence contract the event bus needs for durable emits.
|
|
106
|
+
* `@voyant-travel/db/outbox` provides the Postgres implementation; the bus
|
|
107
|
+
* itself stays storage-agnostic.
|
|
108
|
+
*/
|
|
109
|
+
export interface OutboxEventStore {
|
|
110
|
+
/**
|
|
111
|
+
* Persist the envelope before delivery. Returns the stored record id,
|
|
112
|
+
* or `null` when an event with the same `metadata.eventId` already
|
|
113
|
+
* exists (the original capture owns delivery).
|
|
114
|
+
*/
|
|
115
|
+
insert(envelope: EventEnvelope): Promise<{
|
|
116
|
+
id: string;
|
|
117
|
+
} | null>;
|
|
118
|
+
/** Every handler succeeded — mark delivered. */
|
|
119
|
+
complete(id: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* At least one handler failed or timed out. The store owns retry
|
|
122
|
+
* scheduling (backoff) and dead-lettering.
|
|
123
|
+
*/
|
|
124
|
+
fail(id: string, error: string): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
/** Outcome of delivering one envelope to all its subscribers. */
|
|
127
|
+
export interface DeliveryResult {
|
|
128
|
+
/** Handlers invoked. */
|
|
129
|
+
attempted: number;
|
|
130
|
+
/** Handlers that threw or timed out. */
|
|
131
|
+
failed: number;
|
|
132
|
+
errors: string[];
|
|
133
|
+
}
|
|
134
|
+
/** Stable, unique event id for envelope metadata / outbox dedup. */
|
|
135
|
+
export declare function generateEventId(): string;
|
|
136
|
+
export interface EventBusOptions {
|
|
137
|
+
/**
|
|
138
|
+
* Per-handler timeout in milliseconds. A handler that exceeds it is
|
|
139
|
+
* logged and no longer awaited — it is NOT cancelled (JS can't), so
|
|
140
|
+
* it may still finish in the background. Defaults to 15s, which
|
|
141
|
+
* bounds how long one slow third-party subscriber (CMS sync,
|
|
142
|
+
* e-invoicing API) can hold an emit. Set `false` to disable.
|
|
143
|
+
*/
|
|
144
|
+
handlerTimeoutMs?: number | false;
|
|
145
|
+
}
|
|
146
|
+
export interface EventBus {
|
|
147
|
+
/** Emit an event. Fire-and-forget; subscribers cannot affect the emitter. */
|
|
148
|
+
emit<TData, TMetadata extends EventMetadata | undefined = EventMetadata | undefined>(event: string, data: TData, metadata?: TMetadata, options?: EmitOptions): Promise<void>;
|
|
149
|
+
/** Subscribe to an event by name. Returns an unsubscribe handle. */
|
|
150
|
+
subscribe<TData, TMetadata extends EventMetadata | undefined = EventMetadata | undefined>(event: string, handler: EventHandler<TData, TMetadata>, options?: SubscribeOptions): Subscription;
|
|
151
|
+
/**
|
|
152
|
+
* Deliver an existing envelope to ALL its subscribers (inline and
|
|
153
|
+
* deferrable alike), reporting per-handler failures instead of only
|
|
154
|
+
* logging them. Used by outbox drains for redelivery — it does NOT
|
|
155
|
+
* persist anything. Optional so third-party bus implementations
|
|
156
|
+
* remain assignable; drains fall back to `emit` (fire-and-forget,
|
|
157
|
+
* counted as success) when absent.
|
|
158
|
+
*/
|
|
159
|
+
deliver?(envelope: EventEnvelope): Promise<DeliveryResult>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create an in-process event bus.
|
|
163
|
+
*
|
|
164
|
+
* Handlers run **in parallel** — they are independent observers by
|
|
165
|
+
* contract, so one slow subscriber doesn't serialize behind another.
|
|
166
|
+
* Errors thrown by a handler are caught and logged and never affect the
|
|
167
|
+
* emitter or sibling handlers ("subscribers are fire-and-forget").
|
|
168
|
+
* Each handler is bounded by {@link EventBusOptions.handlerTimeoutMs}.
|
|
169
|
+
*
|
|
170
|
+
* When the emitter passes {@link EmitOptions.schedule}, handlers not
|
|
171
|
+
* marked `inline` are handed to the scheduler as one promise and
|
|
172
|
+
* `emit()` resolves without waiting for them — this is how the HTTP
|
|
173
|
+
* runtime moves subscriber work (third-party syncs, notifications)
|
|
174
|
+
* after the response.
|
|
175
|
+
*/
|
|
176
|
+
export declare function createEventBus(options?: EventBusOptions): EventBus;
|
|
177
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAA;AAEjD;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,CAAA;AAEpF;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAC5B,KAAK,GAAG,OAAO,EACf,SAAS,SAAS,aAAa,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS;IAEvE,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAA;IACZ,8CAA8C;IAC9C,IAAI,EAAE,KAAK,CAAA;IACX,qDAAqD;IACrD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CACtB,KAAK,GAAG,OAAO,EACf,SAAS,SAAS,aAAa,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,IACrE,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAEpE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,IAAI,IAAI,CAAA;CACpB;AAED;;;;;;;;;;GA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