@voyant-travel/hono 0.118.2 → 0.118.4
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.
|
@@ -10,9 +10,10 @@ import type { EventBus, OutboxEventStore } from "@voyant-travel/core";
|
|
|
10
10
|
* With a `store` (transactional outbox), emits are also DURABLE: the
|
|
11
11
|
* envelope is persisted before any handler runs, and failed deliveries
|
|
12
12
|
* are retried by the drain. If the durable capture itself fails (DB
|
|
13
|
-
* unreachable), the emit falls back to direct (non-durable) delivery
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
13
|
+
* unreachable), the emit falls back to direct (non-durable) delivery.
|
|
14
|
+
* Once capture has succeeded, the wrapper must not redeliver directly:
|
|
15
|
+
* the stored row owns completion/retry, and direct fallback would make
|
|
16
|
+
* subscriber side effects ambiguous.
|
|
16
17
|
*
|
|
17
18
|
* Buses that predate the {@link EmitOptions} parameter simply ignore it
|
|
18
19
|
* and keep awaiting all handlers — a safe degradation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-event-bus.d.ts","sourceRoot":"","sources":["../../src/lib/request-event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,QAAQ,EAAiB,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEjG
|
|
1
|
+
{"version":3,"file":"request-event-bus.d.ts","sourceRoot":"","sources":["../../src/lib/request-event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,QAAQ,EAAiB,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEjG;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,EAC3D,KAAK,CAAC,EAAE,gBAAgB,GACvB,QAAQ,CAiDV"}
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
* With a `store` (transactional outbox), emits are also DURABLE: the
|
|
10
10
|
* envelope is persisted before any handler runs, and failed deliveries
|
|
11
11
|
* are retried by the drain. If the durable capture itself fails (DB
|
|
12
|
-
* unreachable), the emit falls back to direct (non-durable) delivery
|
|
13
|
-
*
|
|
14
|
-
* the
|
|
12
|
+
* unreachable), the emit falls back to direct (non-durable) delivery.
|
|
13
|
+
* Once capture has succeeded, the wrapper must not redeliver directly:
|
|
14
|
+
* the stored row owns completion/retry, and direct fallback would make
|
|
15
|
+
* subscriber side effects ambiguous.
|
|
15
16
|
*
|
|
16
17
|
* Buses that predate the {@link EmitOptions} parameter simply ignore it
|
|
17
18
|
* and keep awaiting all handlers — a safe degradation.
|
|
@@ -26,12 +27,28 @@ export function requestScopedEventBus(bus, schedule, store) {
|
|
|
26
27
|
if (!store) {
|
|
27
28
|
return bus.emit(event, data, metadata, { ...base, ...options });
|
|
28
29
|
}
|
|
30
|
+
let captureFailed = false;
|
|
31
|
+
const guardedStore = {
|
|
32
|
+
async insert(envelope) {
|
|
33
|
+
try {
|
|
34
|
+
return await store.insert(envelope);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
captureFailed = true;
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
complete: (id) => store.complete(id),
|
|
42
|
+
fail: (id, error) => store.fail(id, error),
|
|
43
|
+
};
|
|
29
44
|
try {
|
|
30
|
-
return await bus.emit(event, data, metadata, { ...base, store, ...options });
|
|
45
|
+
return await bus.emit(event, data, metadata, { ...base, store: guardedStore, ...options });
|
|
31
46
|
}
|
|
32
47
|
catch (err) {
|
|
33
|
-
|
|
34
|
-
|
|
48
|
+
if (!captureFailed) {
|
|
49
|
+
console.error(`[events] durable delivery failed for "${event}" after outbox capture:`, err);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
35
52
|
console.error(`[events] outbox capture failed for "${event}" — falling back to direct delivery:`, err);
|
|
36
53
|
return bus.emit(event, data, metadata, { ...base, ...options });
|
|
37
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-actor.d.ts","sourceRoot":"","sources":["../../src/middleware/require-actor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAG7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"require-actor.d.ts","sourceRoot":"","sources":["../../src/middleware/require-actor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAG7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA8DlE;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,SAAS,SAAS,cAAc,GAAG,cAAc,EAC5E,GAAG,OAAO,EAAE,KAAK,EAAE,GAClB,iBAAiB,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,eAAe,CAAA;CAC3B,CAAC,CAAA;AACF,wBAAgB,YAAY,CAAC,SAAS,SAAS,cAAc,GAAG,cAAc,EAC5E,OAAO,EAAE,mBAAmB,EAC5B,GAAG,OAAO,EAAE,KAAK,EAAE,GAClB,iBAAiB,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,eAAe,CAAA;CAC3B,CAAC,CAAA"}
|
|
@@ -10,7 +10,7 @@ function apiKeyResourceFromPath(pathname) {
|
|
|
10
10
|
}
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function baseApiKeyPermissionActionsForMethod(method) {
|
|
14
14
|
switch (method.toUpperCase()) {
|
|
15
15
|
case "GET":
|
|
16
16
|
case "HEAD":
|
|
@@ -26,6 +26,27 @@ function apiKeyPermissionActionsForMethod(method) {
|
|
|
26
26
|
return [];
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Search endpoints accept complex request bodies, so they're exposed as `POST`
|
|
31
|
+
* even though they're read-family operations. Without this, `POST
|
|
32
|
+
* /v1/<surface>/catalog/search` would only accept `write`/`trigger`/`relay`,
|
|
33
|
+
* and a `catalog:search`/`catalog:read`-scoped token would be rejected
|
|
34
|
+
* (voyant#2649). Matching a `search` / `*-search` path segment (e.g.
|
|
35
|
+
* `/catalog/search`, `/catalog/package-search`) keeps every other POST route
|
|
36
|
+
* (product writes, bookings, pricing, …) gated on its normal write actions.
|
|
37
|
+
*/
|
|
38
|
+
function isSearchPath(pathname) {
|
|
39
|
+
// A segment that is `search` or ends in `-search` (e.g. `package-search`),
|
|
40
|
+
// bounded so `/searchable` or `/researcher` don't count.
|
|
41
|
+
return /(?:\/|-)search(?:\/|$)/.test(pathname);
|
|
42
|
+
}
|
|
43
|
+
function apiKeyPermissionActionsForMethod(method, pathname) {
|
|
44
|
+
const actions = baseApiKeyPermissionActionsForMethod(method);
|
|
45
|
+
if (isSearchPath(pathname)) {
|
|
46
|
+
return Array.from(new Set([...actions, "search", "read"]));
|
|
47
|
+
}
|
|
48
|
+
return actions;
|
|
49
|
+
}
|
|
29
50
|
function hasAnyApiKeyPermission(scopes, resource, actions) {
|
|
30
51
|
if (!scopes || scopes.length === 0)
|
|
31
52
|
return false;
|
|
@@ -69,7 +90,7 @@ export function requireActor(...args) {
|
|
|
69
90
|
// is a reserved namespace (no module is named `_meta`).
|
|
70
91
|
if (resource === "_meta")
|
|
71
92
|
return next();
|
|
72
|
-
const actions = apiKeyPermissionActionsForMethod(c.req.method);
|
|
93
|
+
const actions = apiKeyPermissionActionsForMethod(c.req.method, pathname);
|
|
73
94
|
if (resource && hasAnyApiKeyPermission(c.get("scopes"), resource, actions)) {
|
|
74
95
|
return next();
|
|
75
96
|
}
|
|
@@ -99,7 +120,7 @@ export function requireActor(...args) {
|
|
|
99
120
|
});
|
|
100
121
|
const resource = apiKeyResourceFromPath(pathname);
|
|
101
122
|
if (resource && resource !== "_meta") {
|
|
102
|
-
const actions = apiKeyPermissionActionsForMethod(c.req.method);
|
|
123
|
+
const actions = apiKeyPermissionActionsForMethod(c.req.method, pathname);
|
|
103
124
|
if (!hasAnyApiKeyPermission(scopes, resource, actions)) {
|
|
104
125
|
return c.json({ error: "Forbidden: missing required permission" }, 403);
|
|
105
126
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyant-travel/hono",
|
|
3
|
-
"version": "0.118.
|
|
3
|
+
"version": "0.118.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
"drizzle-orm": "^0.45.2",
|
|
136
136
|
"hono": "^4.12.25",
|
|
137
137
|
"zod": "^4.4.3",
|
|
138
|
-
"@voyant-travel/core": "^0.111.
|
|
138
|
+
"@voyant-travel/core": "^0.111.1",
|
|
139
139
|
"@voyant-travel/db": "^0.109.4",
|
|
140
140
|
"@voyant-travel/storage": "^0.106.0",
|
|
141
141
|
"@voyant-travel/types": "^0.106.1",
|