@voltro/protocol 0.84.0 → 0.86.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +1215 -0
  2. package/README.md +14 -0
  3. package/THIRD-PARTY-NOTICES.md +5 -89
  4. package/dist/apikey.d.ts +32 -34
  5. package/dist/approval.js +64 -0
  6. package/dist/approvalDescriptors.js +26 -0
  7. package/dist/auth.js +369 -0
  8. package/dist/boundedRing.js +27 -0
  9. package/dist/businessRule.js +11 -0
  10. package/dist/connection.js +73 -0
  11. package/dist/devActivity.js +4 -0
  12. package/dist/errorValue.js +21 -0
  13. package/dist/event.js +104 -0
  14. package/dist/idempotency.js +66 -0
  15. package/dist/identity.js +5 -9
  16. package/dist/index.d.ts +1494 -1366
  17. package/dist/index.js +42 -1411
  18. package/dist/inspect.d.ts +88 -88
  19. package/dist/inspect.js +14 -190
  20. package/dist/inspectBackfill.js +52 -0
  21. package/dist/inspectCommandRejection.js +21 -0
  22. package/dist/inspectProjection.js +133 -0
  23. package/dist/inspectStorageProjection.js +86 -0
  24. package/dist/inspectValueIdentity.js +4 -0
  25. package/dist/inspectWorkflowExecution.js +34 -0
  26. package/dist/inspectWorkflowQueuedStart.js +31 -0
  27. package/dist/jsonSchema.js +54 -0
  28. package/dist/jwt.d.ts +32 -34
  29. package/dist/outbox.js +10 -0
  30. package/dist/pairing.js +75 -0
  31. package/dist/plugin.js +61 -0
  32. package/dist/pluginNaming.js +32 -0
  33. package/dist/procedure.js +262 -0
  34. package/dist/publicApi.js +344 -0
  35. package/dist/reactivityChannel.js +34 -0
  36. package/dist/rest.d.ts +105 -57
  37. package/dist/rest.js +259 -437
  38. package/dist/restFormat.js +163 -0
  39. package/dist/rowEquality.js +31 -0
  40. package/dist/rowPatch.js +182 -0
  41. package/dist/schemaShape.js +67 -0
  42. package/dist/scopes.js +240 -0
  43. package/dist/serverErrorBus.js +15 -0
  44. package/dist/serviceCall.js +14 -0
  45. package/dist/session.d.ts +90 -96
  46. package/dist/session.js +13 -15
  47. package/dist/{sessionHeader-DriTZhmv.js → sessionHeader.js} +1 -1
  48. package/dist/storageAccess.js +14 -0
  49. package/dist/storeErrors.js +66 -0
  50. package/dist/storeScreenshots.js +90 -0
  51. package/dist/strictInput.js +27 -0
  52. package/dist/subscriptionEvent.js +37 -0
  53. package/dist/tenantSelection.js +40 -0
  54. package/dist/time.js +7 -0
  55. package/dist/undo.js +38 -0
  56. package/dist/validation.js +39 -0
  57. package/dist/webSocketGateway.js +10 -0
  58. package/dist/workflow.js +297 -0
  59. package/dist/workflowAccess.js +61 -0
  60. package/dist/workflowRestart.js +45 -0
  61. package/dist/workflowRetry.js +44 -0
  62. package/dist/workflowStartOutcome.js +30 -0
  63. package/package.json +4 -8
  64. package/dist/restFormat-EZ8k9ZcQ.js +0 -304
  65. package/dist/scopes-Di756ENh.js +0 -518
package/dist/rest.js CHANGED
@@ -1,341 +1,111 @@
1
- import { H as e, V as t } from "./scopes-Di756ENh.js";
2
- import { E as n, O as r, T as i, a, c as o, d as s, f as c, i as l, k as u, l as d, n as f, o as p, r as m, s as h, t as g, u as _, v, w as y, y as b } from "./restFormat-EZ8k9ZcQ.js";
3
- import { Effect as x, ParseResult as S, Schema as C } from "effect";
4
- import * as w from "effect/SchemaAST";
5
- //#region src/publicApi.ts
6
- var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("", t, n).method : void 0) ?? (e === "query" ? "GET" : "POST"), E = (e, t, n) => A(t.path ?? (t.resource !== void 0 && n !== void 0 ? k(e, t, n).path : `/${t.version ?? "v1"}/${e.replace(/\./g, "/")}`)), D = (e) => {
7
- let t = e.split("/").pop() ?? e;
8
- return t.endsWith("ies") ? `${t.slice(0, -3)}y` : t.endsWith("ses") || t.endsWith("xes") ? t.slice(0, -2) : t.endsWith("s") ? t.slice(0, -1) : t;
9
- }, O = (e, t) => {
10
- let n = t != null && (typeof t == "object" || typeof t == "function") && "ast" in t ? B(t) : void 0;
11
- if (n === void 0) return;
12
- let r = `${D(e)}Id`;
13
- return n.has(r) ? r : n.has("id") ? "id" : void 0;
14
- }, k = (e, t, n) => {
15
- let r = (t.resource ?? "").replace(/^\/+|\/+$/g, ""), i = `/${t.version ?? "v1"}/${r}`, a = O(r, n.input), o = a === void 0 ? i : `${i}/:${a}`, s = e.split(".").pop() ?? e, c = n.target?.op;
16
- return n.kind === "query" || n.kind === "stream" ? {
17
- method: "GET",
18
- path: o
19
- } : n.kind === "mutation" && c === "insert" ? {
20
- method: "POST",
21
- path: i
22
- } : n.kind === "mutation" && c === "update" ? {
23
- method: a === void 0 ? "POST" : "PATCH",
24
- path: o
25
- } : n.kind === "mutation" && c === "delete" ? {
26
- method: a === void 0 ? "POST" : "DELETE",
27
- path: o
28
- } : {
29
- method: "POST",
30
- path: `${o}/${s}`
31
- };
32
- }, A = (e) => e.replace(/\{([A-Za-z0-9_]+)\}/g, ":$1"), j = (e) => [...e.matchAll(/:([A-Za-z0-9_]+)/g)].map((e) => e[1]), M = (e) => {
33
- if (w.isUnion(e)) {
34
- let t = e.types.filter((e) => !w.isUndefinedKeyword(e));
35
- if (t.length === 1) return t[0];
36
- if (t.length !== e.types.length) return w.Union.make(t);
37
- }
38
- return e;
39
- }, N = /^-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i, P = (e, t) => {
40
- let n = M(t);
41
- if (w.isRefinement(n) || w.isTransformation(n)) return P(e, n.from);
42
- if (w.isUnion(n)) {
43
- for (let t of n.types) {
44
- let n = P(e, t);
45
- if (n !== e) return n;
46
- }
47
- return e;
48
- }
49
- if (w.isTupleType(n)) {
50
- let t = Array.isArray(e) ? e : e === void 0 ? void 0 : [e];
51
- if (t === void 0) return e;
52
- let r = n.rest[0]?.type ?? n.elements[0]?.type;
53
- return r === void 0 ? t : t.map((e) => P(e, r));
54
- }
55
- if (typeof e != "string") return e;
56
- if (w.isNumberKeyword(n)) return N.test(e.trim()) ? Number(e) : e;
57
- if (w.isBooleanKeyword(n)) return e === "true" || e !== "false" && e;
58
- if (w.isLiteral(n)) {
59
- let t = n.literal;
60
- return typeof t == "number" && N.test(e.trim()) && Number(e) === t || typeof t == "boolean" && String(t) === e ? t : e;
61
- }
62
- return e;
63
- }, F = (e, t) => {
64
- if (typeof e != "object" || !e || Array.isArray(e)) return e;
65
- let n = M(w.encodedAST(t.ast));
66
- if (!w.isTypeLiteral(n)) return e;
67
- let r = { ...e };
68
- for (let e of n.propertySignatures) {
69
- let t = String(e.name);
70
- t in r && (r[t] = P(r[t], e.type));
71
- }
72
- return r;
73
- }, I = (e) => {
74
- let t = /* @__PURE__ */ new Set();
75
- if (e === void 0) return t;
76
- let n = (e) => {
77
- if (w.isUnion(e)) {
78
- for (let t of e.types) n(t);
79
- return;
80
- }
81
- if (w.isTransformation(e)) {
82
- n(e.from), n(e.to);
83
- return;
84
- }
85
- if (w.isRefinement(e)) {
86
- n(e.from);
87
- return;
88
- }
89
- if (w.isTypeLiteral(e)) {
90
- let n = e.propertySignatures.find((e) => e.name === "_tag");
91
- n !== void 0 && w.isLiteral(n.type) && typeof n.type.literal == "string" && t.add(n.type.literal);
92
- }
93
- };
94
- return n(e.ast), t;
95
- }, L = (e, t, n) => {
96
- if (n !== void 0) try {
97
- let r = C.encodeUnknownSync(n)(e);
98
- if (typeof r == "object" && r) return {
99
- error: t,
100
- ...r
101
- };
102
- } catch {}
103
- let r = { error: t };
104
- for (let [t, n] of Object.entries(e)) t !== "stack" && t !== "_tag" && (r[t] = n);
105
- return r;
106
- }, R = (e, t, n, r = []) => {
107
- if (typeof e != "object" || !e) return e;
108
- let i = e._tag;
109
- if (typeof i != "string" || i === "ScopeError" || i === "NoSuchResource") return e;
110
- if (I(t.error).has(i)) return new Y(n.errorStatus?.[i] ?? 422, L(e, i, t.error));
111
- let a = r.find((e) => I(e.schema).has(i));
112
- if (a === void 0) return e;
113
- let o = n.errorStatus?.[i] ?? a.rest?.status ?? 422, s = a.rest?.headers?.(e);
114
- return new Y(o, L(e, i, a.schema), s);
115
- }, ee = (e, t, n, r, i, a) => {
116
- let o = R(e, t, n, r);
117
- if (!(o instanceof Y) || i.errors === "tagged" && i.encodeError === void 0) return o;
118
- let { error: s, _tag: c, ...u } = o.body, d = typeof u.message == "string" ? u.message : typeof u.reason == "string" ? u.reason : "", f = l(i, {
119
- status: o.status,
120
- tag: s,
121
- message: d,
122
- fields: u
123
- }, {
124
- ...a,
125
- status: o.status
126
- });
127
- return new Y(o.status, f.body, {
128
- ...o.headers ?? {},
129
- ...f.headers ?? {}
130
- }, f.contentType);
131
- }, z = (e, t) => {
132
- if (e === void 0) return;
133
- let n = w.isUnion(e.ast) ? e.ast.types : [e.ast];
134
- for (let e of n) {
135
- let n = C.make(e);
136
- if (I(n).has(t)) return n;
137
- }
138
- }, te = (e) => e.split(".").map((e, t) => t === 0 ? e : e.charAt(0).toUpperCase() + e.slice(1)).join("").replace(/[^A-Za-z0-9_]/g, "_"), B = (e) => {
139
- let t = M(w.encodedAST(e.ast));
140
- return w.isTypeLiteral(t) && t.indexSignatures.length === 0 ? new Set(t.propertySignatures.map((e) => String(e.name))) : void 0;
141
- }, ne = (e, t) => e === t || JSON.stringify(e) === JSON.stringify(t), re = (e, t) => {
142
- let n = M(w.encodedAST(t.ast)), r = {}, i = w.isTypeLiteral(n) ? new Map(n.propertySignatures.map((e) => [String(e.name), e.type])) : /* @__PURE__ */ new Map();
143
- for (let [t, n] of Object.entries(e)) {
144
- let e = i.get(t);
145
- r[t] = e === void 0 ? n : P(n, e);
146
- }
147
- return r;
148
- }, V = (e, t) => {
149
- if (e !== void 0) {
150
- try {
151
- return C.encodeUnknownSync(t)(e);
152
- } catch {}
153
- try {
154
- return C.decodeUnknownSync(t)(e), e;
155
- } catch {}
156
- return e;
157
- }
158
- }, H = (e, t, n) => ({
159
- ...e.request === void 0 ? {} : { request: V(e.request, t) },
160
- ...e.response === void 0 ? {} : { response: V(e.response, n) }
161
- }), ie = () => (e) => {
162
- if (e.subject.type !== "anonymous") return;
163
- let t = e.subject.credentialRejected;
164
- return t === void 0 ? void 0 : {
165
- status: 401,
166
- message: t
167
- };
168
- }, U = (e, t, n, r = {}) => {
169
- let i = e.publicApi;
170
- if (i === void 0) throw Error(`publicApiRoute: descriptor '${e.name}' has no publicApi annotation`);
171
- let o = d(r.profile, i.format), c = r.pluginErrors ?? [], l = {
172
- kind: e.kind,
173
- input: e.input,
174
- target: e.target
175
- }, u = T(e.kind, i, l), f = (e) => o.naming === "snake_case" ? s(e) : e, p = E(e.name, i, l), m = p.replace(/:([A-Za-z0-9_]+)/g, (e, t) => `:${f(t)}`), h = j(m), g = _(e.input, o), v = B(g);
176
- if (v !== void 0) {
177
- for (let t of h) if (!v.has(t)) throw Error(`publicApi: descriptor '${e.name}' — path '${p}' binds ':${t}', and the input declares no field of that name` + (v.size > 0 ? ` (fields: ${[...v].join(", ")})` : " (the input declares no fields)"));
178
- }
179
- let y = _(e.output, o), b = C.Struct({ value: g }), w = u !== "GET" && (v === void 0 || [...v].some((e) => !h.includes(e))), D = {
180
- query: C.Unknown,
181
- params: C.Unknown,
182
- form: C.Boolean
183
- }, O = w ? C.Struct({
184
- ...D,
185
- body: C.Unknown
186
- }) : C.Struct(D), k = C.transformOrFail(O, b, {
187
- strict: !1,
188
- decode: (e, t, n) => {
189
- let r = "body" in e ? e.body : void 0, i = u === "GET" ? F(e.query, g) : e.form ? F(r ?? {}, g) : r ?? {}, a = typeof e.params == "object" && e.params !== null ? re(e.params, g) : {};
190
- if (typeof i != "object" || !i || Array.isArray(i)) return S.succeed({ value: i });
191
- let o = i, s = Object.keys(a).filter((e) => e in o && !ne(o[e], a[e]));
192
- if (s.length > 0) {
193
- let t = u === "GET" ? "query string" : "body";
194
- return S.fail(new S.Type(n, e, `${s.map((e) => `'${e}'`).join(", ")} ${s.length === 1 ? "is" : "are"} bound by the path and sent with another value in the ${t}`));
195
- }
196
- return S.succeed({ value: {
197
- ...o,
198
- ...a
199
- } });
200
- },
201
- encode: (e) => S.succeed(e)
202
- }), A = [
203
- ie(),
204
- ...e.openAccess === void 0 ? [K()] : [],
205
- ...(i.scopes ?? []).map((e) => q(e))
206
- ], M = (() => {
207
- let t = e.source;
208
- return typeof t == "string" ? t : Array.isArray(t) ? t[0] : void 0;
209
- })(), N = (t, n = 200) => ({
210
- tag: e.name,
211
- method: t.method,
212
- path: t.path,
213
- query: t.query,
214
- source: M,
215
- status: n
216
- }), P = i.stream === "sse" && e.kind === "query" && n !== void 0, L = C.encodeUnknown(y), R = P ? (e, t) => ue((r) => n(e.value, t, (e) => {
217
- r(de(String(e._tag ?? "message"), e));
218
- })) : async (n, r) => {
219
- let s;
220
- try {
221
- s = await t(n.value, r);
222
- } catch (t) {
223
- throw ee(t, e, i, c, o, N(r));
224
- }
225
- let l = await x.runPromise(L(s)), u = a(o, l, N(r));
226
- return J(u.body, {
227
- ...u.headers === void 0 ? {} : { headers: u.headers },
228
- ...u.contentType === void 0 ? {} : { contentType: u.contentType }
229
- });
230
- }, V = e.error, U = [...I(V)], W = [];
231
- for (let e of U) {
232
- let t = z(V, e);
233
- t !== void 0 && W.push({
234
- status: i.errorStatus?.[e] ?? 422,
235
- tag: e,
236
- schema: t
237
- });
238
- }
239
- for (let e of c) for (let t of I(e.schema)) {
240
- if (U.includes(t)) continue;
241
- let n = i.errorStatus?.[t] ?? e.rest?.status;
242
- if (n === void 0) continue;
243
- let r = z(e.schema, t) ?? e.schema;
244
- W.push({
245
- status: n,
246
- tag: t,
247
- schema: r
248
- });
249
- }
250
- let G = i.security === !1 ? "none" : i.security ?? (e.openAccess === void 0 ? "required" : "optional"), ae = {
251
- tag: e.name,
252
- kind: e.kind,
253
- version: i.version ?? "v1",
254
- security: G,
255
- idempotent: i.idempotent === !0,
256
- input: g,
257
- pathParams: h,
258
- output: y,
259
- source: M,
260
- errorResponses: W,
261
- format: o
262
- };
263
- return le({
264
- method: u,
265
- path: m,
266
- input: k,
267
- output: C.Unknown,
268
- handler: R,
269
- ...P ? { streaming: !0 } : {},
270
- guards: A,
271
- operationId: i.operationId ?? te(e.name),
272
- tags: i.tags ?? [e.name.split(".")[0] ?? e.name],
273
- projection: ae,
274
- ...o.etag && u === "GET" && !P ? { etag: !0 } : {},
275
- ...i.cache !== void 0 && u === "GET" && !P ? { cache: i.cache } : {},
276
- ...i.example === void 0 ? {} : { example: H(i.example, g, y) },
277
- ...i.summary === void 0 ? {} : { summary: i.summary },
278
- ...i.description === void 0 ? {} : { description: i.description },
279
- ...i.deprecated === void 0 ? {} : { deprecated: i.deprecated },
280
- ...i.sunset === void 0 ? {} : { sunset: i.sunset }
281
- });
282
- }, W = (e, t = {}) => e.filter((e) => e.descriptor.publicApi !== void 0).map((e) => U(e.descriptor, e.invoke, e.subscribe, t)).sort((e, t) => e.path.localeCompare(t.path)), G = (e) => b(e.filter((e) => e.projection !== void 0).map((e) => {
283
- let t = e.projection, n = {
284
- tag: t.tag,
285
- method: e.method,
286
- path: e.path,
287
- pathParams: t.pathParams,
288
- version: t.version,
289
- security: t.security,
290
- errors: [...t.errorResponses].map((e) => `${e.status}:${e.tag}`).sort()
291
- };
292
- return `${JSON.stringify(n)} ${v(t.input.ast)} ${v(t.output.ast)}`;
293
- }).sort().join("\n")), K = () => (e) => {
1
+ import { Unauthenticated as e, anonymousSubject as t } from "./auth.js";
2
+ import "./scopes.js";
3
+ import { beginIdempotent as n, failIdempotent as r, finishIdempotent as i, holdIdempotentClaim as a, idempotencyScope as o } from "./idempotency.js";
4
+ import { publishServerError as s } from "./serverErrorBus.js";
5
+ import { JSONAPI_MEDIA_TYPE as c, PROBLEM_JSON as l, REST_PROFILE_NAMES as u, encodeRestError as d, encodeRestSuccess as f, nextLink as p, problemDetails as m, problemTypeOf as h, resolveRestFormat as g, restViewSchema as _, toSnakeCase as v } from "./restFormat.js";
6
+ import { coerceQueryObject as y, coerceQueryValue as b, collectPublicApiRoutes as x, declaredErrorTags as S, derivePublicMethod as C, derivePublicPath as w, deriveResource as T, errorMemberSchema as E, normalizePathParams as D, operationIdOf as O, pathParamNames as k, projectedFailure as ee, publicApiRoute as te, publicSurfaceDigest as ne, resourceIdField as re, wireExample as ie } from "./publicApi.js";
7
+ import { Effect as A, Schema as j } from "effect";
8
+ import * as M from "effect/SchemaAST";
9
+ //#region src/rest.ts
10
+ var ae = () => (e) => {
294
11
  if (e.subject.type === "anonymous") return {
295
12
  status: 401,
296
13
  message: e.subject.credentialRejected ?? "Authentication required"
297
14
  };
298
- }, q = (e) => (t) => {
15
+ }, oe = (e) => (t) => {
299
16
  let n = t.subject.scopes;
300
17
  if (!(n && (n.includes(e) || n.includes("admin:full")))) return {
301
18
  status: 403,
302
19
  message: `Missing required scope: ${e}`
303
20
  };
304
- }, ae = (e) => (t) => {
21
+ }, N = (e) => {
22
+ for (let t of [
23
+ "includes",
24
+ "some",
25
+ Symbol.iterator
26
+ ]) {
27
+ let n = Object.getOwnPropertyDescriptor(e, t);
28
+ if (n !== void 0 && !("value" in n)) return !1;
29
+ }
30
+ if (Object.getPrototypeOf(e) !== Array.prototype || e.includes !== Array.prototype.includes || e.some !== Array.prototype.some || e[Symbol.iterator] !== Array.prototype[Symbol.iterator]) return !1;
31
+ for (let t = 0; t < e.length; t++) {
32
+ let n = Object.getOwnPropertyDescriptor(e, t);
33
+ if (n === void 0 || !("value" in n) || typeof n.value != "string") return !1;
34
+ }
35
+ return !0;
36
+ }, se = (e) => (t) => {
305
37
  let n = t.subject.scopes;
306
- if (!(n && (n.includes("admin:full") || e.some((e) => n.includes(e))))) return {
38
+ if (n) {
39
+ if (n.includes("admin:full")) return;
40
+ let t = n.length >= 32 && e.length >= 256 && N(n) && N(e) ? new Set(n) : void 0;
41
+ if (e.some((e) => t === void 0 ? n.includes(e) : t.has(e))) return;
42
+ }
43
+ return {
307
44
  status: 403,
308
45
  message: `Missing required scope: one of ${e.join(", ")}`
309
46
  };
310
- }, oe = (e, t, n, r) => {
47
+ }, P = (e, t) => {
48
+ if (e === void 0) return {};
49
+ let n = { vary: "Origin" };
50
+ return t !== void 0 && (e.origins.includes(t) || e.origins.includes("*")) && (n["access-control-allow-origin"] = e.origins.includes("*") ? "*" : t, n["access-control-expose-headers"] = (e.exposeHeaders ?? [
51
+ "retry-after",
52
+ "ratelimit-limit",
53
+ "ratelimit-remaining",
54
+ "ratelimit-reset"
55
+ ]).join(", ")), n;
56
+ }, F = (e, t, n) => {
57
+ let r = P(e, n.origin), i = e.methods ?? (t === "GET" ? ["GET", "HEAD"] : [t]), a = e.headers ?? ["authorization", "content-type"], o = (n["access-control-request-headers"] ?? "").split(",").map((e) => e.trim().toLowerCase()).filter(Boolean), s = r["access-control-allow-origin"] !== void 0 && i.some((e) => e === n["access-control-request-method"]) && o.every((e) => a.some((t) => t.toLowerCase() === e));
58
+ return {
59
+ status: s ? 204 : 403,
60
+ headers: {
61
+ ...r,
62
+ vary: "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
63
+ ...s ? {
64
+ "access-control-allow-methods": i.join(", "),
65
+ "access-control-allow-headers": a.join(", "),
66
+ ...e.maxAge === void 0 ? {} : { "access-control-max-age": String(e.maxAge) }
67
+ } : {}
68
+ }
69
+ };
70
+ }, I = (e, t) => e.method === "GET" && e.cache !== void 0 && t.status !== 200 && t.status !== 304 ? {
71
+ ...t,
72
+ headers: {
73
+ ...t.headers,
74
+ "Cache-Control": "private, no-store"
75
+ }
76
+ } : t, ce = (e, t, n, r, i) => {
311
77
  if (e === void 0) return {};
312
- let i = { Vary: "Authorization, Cookie" };
313
- if (t.headers.authorization !== void 0 || t.headers.cookie !== void 0) return {
78
+ let a = { Vary: e.audience === void 0 ? "Authorization, Cookie" : "Authorization" };
79
+ if (t.headers.authorization !== void 0 || e.audience === void 0 && t.headers.cookie !== void 0) return {
314
80
  "Cache-Control": "private, no-cache",
315
- ...i
81
+ ...a
316
82
  };
317
- let a = Math.max(0, Math.floor(e.maxAge)), o = [
83
+ if (e.audience !== void 0 && e.audience(n, r, i) === "private") return {
84
+ "Cache-Control": "private, no-store",
85
+ ...a
86
+ };
87
+ let o = Math.max(0, Math.floor(e.maxAge)), s = [
318
88
  "public",
319
- `max-age=${a}`,
320
- `s-maxage=${a}`
89
+ `max-age=${o}`,
90
+ `s-maxage=${o}`
321
91
  ];
322
- e.staleWhileRevalidate !== void 0 && o.push(`stale-while-revalidate=${Math.max(0, Math.floor(e.staleWhileRevalidate))}`);
323
- let s = [...new Set((e.tags?.(n, r) ?? []).filter((e) => e !== "" && !/[\s,]/.test(e)))];
92
+ e.staleWhileRevalidate !== void 0 && s.push(`stale-while-revalidate=${Math.max(0, Math.floor(e.staleWhileRevalidate))}`);
93
+ let c = [...new Set((e.tags?.(n, r) ?? []).filter((e) => e !== "" && !/[\s,]/.test(e)))];
324
94
  return {
325
- "Cache-Control": o.join(", "),
326
- ...i,
327
- ...s.length > 0 ? {
328
- "Cache-Tag": s.join(","),
329
- "Surrogate-Key": s.join(" ")
95
+ "Cache-Control": s.join(", "),
96
+ ...a,
97
+ ...c.length > 0 ? {
98
+ "Cache-Tag": c.join(","),
99
+ "Surrogate-Key": c.join(" ")
330
100
  } : {}
331
101
  };
332
- }, J = (e, t = {}) => ({
102
+ }, L = (e, t = {}) => ({
333
103
  __voltroRestResponse: !0,
334
104
  status: t.status ?? 200,
335
105
  body: e,
336
106
  ...t.headers === void 0 ? {} : { headers: t.headers },
337
107
  ...t.contentType === void 0 ? {} : { contentType: t.contentType }
338
- }), se = (e) => typeof e == "object" && !!e && e.__voltroRestResponse === !0, Y = class extends Error {
108
+ }), R = (e) => typeof e == "object" && !!e && e.__voltroRestResponse === !0, z = class extends Error {
339
109
  status;
340
110
  body;
341
111
  headers;
@@ -343,7 +113,7 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
343
113
  constructor(e, t, n, r) {
344
114
  super(`REST ${e}`), this.name = "RestRouteError", this.status = e, this.body = t, this.headers = n, this.contentType = r;
345
115
  }
346
- }, ce = (e, t, n) => new Y(e, t, n), le = (e) => {
116
+ }, B = (e, t, n) => new z(e, t, n), V = (e) => {
347
117
  if (e.version === void 0) return e;
348
118
  if (!/^v\d+$/.test(e.version)) throw Error(`defineRestRoute(${e.method} ${e.path}): version "${e.version}" must be 'v' followed by digits — 'v1', 'v2', …`);
349
119
  if ((/* @__PURE__ */ RegExp("^/v\\d+(/|$)")).test(e.path)) throw Error(`defineRestRoute(${e.method} ${e.path}): the path already starts with a version segment AND declares version: '${e.version}'. Pick one spelling — either bake the version into the path, or declare version: and keep the path bare ('/customers'). Both would mount '/${e.version}${e.path}', which is never what the author meant.`);
@@ -351,13 +121,13 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
351
121
  ...e,
352
122
  path: `/${e.version}${e.path}`
353
123
  };
354
- }, ue = (e, t = {}) => ({
124
+ }, H = (e, t = {}) => ({
355
125
  __voltroRestStream: !0,
356
126
  stream: {
357
127
  subscribe: e,
358
128
  ...t.keepAliveMs === void 0 ? {} : { keepAliveMs: t.keepAliveMs }
359
129
  }
360
- }), de = (e, t) => `event: ${e}\n${(typeof t == "string" ? t : JSON.stringify(t)).split("\n").map((e) => `data: ${e}`).join("\n")}\n\n`, fe = (e) => typeof e == "object" && !!e && e.__voltroRestStream === !0, pe = (e, t = {}) => ({
130
+ }), U = (e, t) => `event: ${e}\n${(typeof t == "string" ? t : JSON.stringify(t)).split("\n").map((e) => `data: ${e}`).join("\n")}\n\n`, W = (e) => typeof e == "object" && !!e && e.__voltroRestStream === !0, le = (e, t = {}) => ({
361
131
  __voltroRestBytes: !0,
362
132
  byteStream: {
363
133
  stream: e,
@@ -367,17 +137,18 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
367
137
  ...t.contentType === void 0 ? {} : { contentType: t.contentType },
368
138
  ...t.status === void 0 ? {} : { status: t.status },
369
139
  ...t.headers === void 0 ? {} : { headers: t.headers }
370
- }), X = (e) => typeof e == "object" && !!e && e.__voltroRestBytes === !0, me = async (e) => {
371
- let t = await globalThis.crypto.subtle.digest("SHA-1", new TextEncoder().encode(e));
372
- return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
373
- }, Z = (e, t, n, r = "application/json; charset=utf-8") => ({
140
+ }), G = (e) => typeof e == "object" && !!e && e.__voltroRestBytes === !0, ue = async (e) => {
141
+ let t = await globalThis.crypto.subtle.digest("SHA-1", new TextEncoder().encode(e)), n = "";
142
+ for (let e of new Uint8Array(t)) n += e.toString(16).padStart(2, "0");
143
+ return n;
144
+ }, K = (e, t, n, r = "application/json; charset=utf-8") => ({
374
145
  status: e,
375
146
  contentType: r,
376
147
  body: JSON.stringify(t),
377
148
  ...n ? { headers: n } : {}
378
- }), Q = (e, t, n, r, i, a, o) => {
149
+ }), q = (e, t, n, r, i, a, o) => {
379
150
  let s = e.projection;
380
- if (s === void 0) return Z(n, {
151
+ if (s === void 0) return K(n, {
381
152
  error: i,
382
153
  ...a
383
154
  }, o);
@@ -388,17 +159,17 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
388
159
  query: t.query,
389
160
  source: s.source,
390
161
  status: n
391
- }, u = l(s.format, {
162
+ }, l = d(s.format, {
392
163
  status: n,
393
164
  tag: r,
394
165
  message: i,
395
166
  fields: a
396
167
  }, c);
397
- return Z(n, u.body, {
168
+ return K(n, l.body, {
398
169
  ...o,
399
- ...u.headers ?? {}
400
- }, u.contentType);
401
- }, he = (e) => (e.headers["content-type"] ?? "application/json").split(";")[0].trim().toLowerCase(), ge = (e, t) => {
170
+ ...l.headers ?? {}
171
+ }, l.contentType);
172
+ }, J = (e) => (e.headers["content-type"] ?? "application/json").split(";")[0].trim().toLowerCase(), Y = (e, t) => {
402
173
  if (e.length === 0) return;
403
174
  let n = t === "application/x-www-form-urlencoded";
404
175
  if (!n && t !== "application/json" && !/^application\/[^/;\s]+\+json$/.test(t)) return;
@@ -406,22 +177,22 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
406
177
  if (r.trim() !== "") {
407
178
  if (n) {
408
179
  let e = (e) => decodeURIComponent(e.replace(/\+/g, " "));
409
- return ve(r.split("&").filter(Boolean).map((t) => {
180
+ return X((r.match(/[^&]+/g) ?? []).map((t) => {
410
181
  let n = t.indexOf("=");
411
182
  return n < 0 ? [e(t), ""] : [e(t.slice(0, n)), e(t.slice(n + 1))];
412
183
  }));
413
184
  }
414
185
  return JSON.parse(r);
415
186
  }
416
- }, _e = (e) => ve(new URLSearchParams(e)), ve = (e) => {
187
+ }, de = (e) => X(new URLSearchParams(e)), X = (e) => {
417
188
  let t = /* @__PURE__ */ new Map();
418
189
  for (let [n, r] of e) {
419
190
  let e = t.get(n);
420
191
  e === void 0 ? t.set(n, r) : Array.isArray(e) ? e.push(r) : t.set(n, [e, r]);
421
192
  }
422
193
  return Object.fromEntries(t);
423
- }, ye = (e, t) => {
424
- let n = e.split("/").filter((e) => e.length > 0), r = t.split("/").filter((e) => e.length > 0), i = {};
194
+ }, Z = (e, t) => {
195
+ let n = e.match(/[^/]+/g) ?? [], r = t.match(/[^/]+/g) ?? [], i = {};
425
196
  for (let e = 0; e < n.length; e++) {
426
197
  let t = n[e];
427
198
  if (t !== void 0 && t.startsWith(":")) {
@@ -434,7 +205,7 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
434
205
  }
435
206
  }
436
207
  return i;
437
- }, be = (e, t) => {
208
+ }, fe = (e, t) => {
438
209
  let n = e.path.split("/"), r = n[n.length - 1] === "*", i = r ? n.slice(0, -1) : n, a = t.split("/");
439
210
  if (a.length < i.length) return !1;
440
211
  for (let e = 0; e < i.length; e++) {
@@ -444,191 +215,242 @@ var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("",
444
215
  } else if (t !== n) return !1;
445
216
  }
446
217
  return a.length === i.length ? !0 : e.match === "exact" && !r ? !1 : a.slice(i.length).some((e) => e.length > 0);
447
- }, xe = (e, t, n) => ({
448
- query: _e(e.query),
218
+ }, pe = (e, t, n) => ({
219
+ query: de(e.query),
449
220
  params: t,
450
- body: n ? ge(e.rawBody, he(e)) : void 0,
451
- form: he(e) === "application/x-www-form-urlencoded"
452
- }), $ = /* @__PURE__ */ new Set([
221
+ body: n ? Y(e.rawBody, J(e)) : void 0,
222
+ form: J(e) === "application/x-www-form-urlencoded"
223
+ }), Q = /* @__PURE__ */ new Set([
453
224
  "POST",
454
225
  "PUT",
455
226
  "PATCH",
456
227
  "DELETE"
457
- ]), Se = (e, n, r, i, a) => {
458
- if (e instanceof Y) return Z(e.status, e.body, {
228
+ ]), $ = (t, n, r, i, a) => {
229
+ if (t instanceof z) return K(t.status, t.body, {
459
230
  ...i,
460
- ...e.headers
461
- }, e.contentType);
462
- if (typeof e == "object" && e) {
463
- let o = e;
464
- if (typeof o.status == "number") return Q(r, a, o.status, typeof o._tag == "string" ? o._tag : "Error", typeof o.message == "string" ? o.message : "Error", {}, { ...i });
465
- if (o._tag === "Unauthenticated" || e instanceof t) return Q(r, a, 401, "Unauthorized", typeof o.reason == "string" ? o.reason : "Authentication required", {}, { ...i });
231
+ ...t.headers
232
+ }, t.contentType);
233
+ if (typeof t == "object" && t) {
234
+ let o = t;
235
+ if (typeof o.status == "number") return q(r, a, o.status, typeof o._tag == "string" ? o._tag : "Error", typeof o.message == "string" ? o.message : "Error", {}, { ...i });
236
+ if (o._tag === "Unauthenticated" || t instanceof e) return q(r, a, 401, "Unauthorized", typeof o.reason == "string" ? o.reason : "Authentication required", {}, { ...i });
466
237
  if (o._tag === "ScopeError") {
467
238
  let e = n.type === "anonymous" ? 401 : 403;
468
- return Q(r, a, e, e === 401 ? "Unauthorized" : "Forbidden", typeof o.message == "string" ? o.message : "Forbidden", {}, { ...i });
239
+ return q(r, a, e, e === 401 ? "Unauthorized" : "Forbidden", typeof o.message == "string" ? o.message : "Forbidden", {}, { ...i });
469
240
  }
470
241
  if (o._tag === "NoSuchResource") {
471
- let t = e;
472
- return Q(r, a, 404, "NoSuchResource", typeof o.message == "string" ? o.message : "Not Found", {
473
- resourceType: typeof t.resourceType == "string" ? t.resourceType : null,
474
- resourceId: typeof t.resourceId == "string" ? t.resourceId : null
242
+ let e = t;
243
+ return q(r, a, 404, "NoSuchResource", typeof o.message == "string" ? o.message : "Not Found", {
244
+ resourceType: typeof e.resourceType == "string" ? e.resourceType : null,
245
+ resourceId: typeof e.resourceId == "string" ? e.resourceId : null
475
246
  }, { ...i });
476
247
  }
477
248
  }
478
- return c({
479
- error: e,
249
+ return s({
250
+ error: t,
480
251
  source: "rest",
481
252
  name: `${r.method} ${r.path}`,
482
253
  fields: { status: 500 }
483
254
  }), {
484
- ...Q(r, a, 500, "InternalServerError", "Internal Server Error", {}, { ...i }),
485
- cause: e
255
+ ...q(r, a, 500, "InternalServerError", "Internal Server Error", {}, { ...i }),
256
+ cause: t
486
257
  };
487
- }, Ce = (a, o, s) => {
488
- let c = a.input ? C.decodeUnknown(a.input) : void 0, l = C.encode(a.output), d = a.input === void 0 ? void 0 : w.encodedAST(a.input.ast), f = d !== void 0 && (!w.isTypeLiteral(d) || d.indexSignatures.length > 0 || d.propertySignatures.some((e) => e.name === "body")), p = {};
489
- a.projection !== void 0 && (p["x-voltro-rest-profile"] = a.projection.format.name);
490
- let m = (e) => e.replace(/\/$/, "").split("/").length, h = m(a.path);
491
- return a.deprecated !== void 0 && (p.Deprecation = "true"), a.sunset !== void 0 && (p.Sunset = a.sunset), {
492
- method: a.method,
258
+ }, me = (s, c, l) => {
259
+ let u = s.input ? j.decodeUnknownEffect(s.input) : void 0, d = j.encodeEffect(s.output), f = s.input === void 0 ? void 0 : M.toEncoded(s.input.ast), p = f !== void 0 && (!M.isObjects(f) || f.indexSignatures.length > 0 || f.propertySignatures.some((e) => e.name === "body")), m = {};
260
+ s.projection !== void 0 && (m["x-voltro-rest-profile"] = s.projection.format.name);
261
+ let h = (e) => e.replace(/\/$/, "").split("/").length, g = h(s.path);
262
+ s.deprecated !== void 0 && (m.Deprecation = "true"), s.sunset !== void 0 && (m.Sunset = s.sunset);
263
+ let _ = {
264
+ method: s.method,
493
265
  answersOtherMethods: !0,
494
- path: a.path,
495
- match: a.path.endsWith("/*") ? "prefix" : "exact",
496
- ...a.maxBodyBytes === void 0 ? {} : { maxBodyBytes: a.maxBodyBytes },
497
- handle: async (d) => {
498
- if (!a.path.endsWith("/*") && m(d.path) !== h) return Q(a, d, 404, "NotFound", "Not Found", {}, { ...p });
499
- let g = d.method.toUpperCase();
500
- if (!(g === a.method || g === "HEAD" && a.method === "GET")) return Q(a, d, 405, "MethodNotAllowed", "Method Not Allowed", { allow: s }, {
501
- ...p,
502
- Allow: s
266
+ path: s.path,
267
+ match: s.path.endsWith("/*") ? "prefix" : "exact",
268
+ ...s.maxBodyBytes === void 0 ? {} : { maxBodyBytes: s.maxBodyBytes },
269
+ ...s.cors === void 0 ? {} : { cors: s.cors },
270
+ ...s.credentials === void 0 ? {} : { credentials: s.credentials },
271
+ handle: async (f) => {
272
+ if (!s.path.endsWith("/*") && h(f.path) !== g) return q(s, f, 404, "NotFound", "Not Found", {}, { ...m });
273
+ let _ = f.method.toUpperCase();
274
+ if (!(_ === s.method || _ === "HEAD" && s.method === "GET")) return q(s, f, 405, "MethodNotAllowed", "Method Not Allowed", { allow: l }, {
275
+ ...m,
276
+ Allow: l
503
277
  });
504
- if (a.sunset !== void 0) {
505
- let e = Date.parse(a.sunset);
506
- if (!Number.isNaN(e) && Date.now() >= e) return Q(a, d, 410, "Gone", "Gone", {
507
- ...a.version === void 0 ? {} : { version: a.version },
508
- ...a.deprecated === void 0 ? {} : { replacement: a.deprecated }
509
- }, { ...p });
278
+ if (s.sunset !== void 0) {
279
+ let e = Date.parse(s.sunset);
280
+ if (!Number.isNaN(e) && Date.now() >= e) return q(s, f, 410, "Gone", "Gone", {
281
+ ...s.version === void 0 ? {} : { version: s.version },
282
+ ...s.deprecated === void 0 ? {} : { replacement: s.deprecated }
283
+ }, { ...m });
510
284
  }
511
- let _;
512
- if (c) {
285
+ let v;
286
+ if (u) {
513
287
  let e;
514
288
  try {
515
- e = xe(d, ye(a.path, d.path), f);
289
+ e = pe(f, Z(s.path, f.path), p);
516
290
  } catch {
517
- return Q(a, d, 400, "InvalidRequest", "Malformed request body", {}, { ...p });
291
+ return q(s, f, 400, "InvalidRequest", "Malformed request body", {}, { ...m });
518
292
  }
519
- let t = await x.runPromise(c(e).pipe(x.map((e) => ({
293
+ let t = await A.runPromise(u(e).pipe(A.map((e) => ({
520
294
  ok: !0,
521
295
  value: e
522
- })), x.catchAll((e) => x.succeed({
296
+ })), A.catch((e) => A.succeed({
523
297
  ok: !1,
524
298
  cause: e
525
299
  }))));
526
- if (!t.ok) return Q(a, d, 400, "InvalidRequest", "Invalid request", { detail: String(t.cause) }, { ...p });
527
- _ = t.value;
300
+ if (!t.ok) return q(s, f, 400, "InvalidRequest", "Invalid request", { detail: String(t.cause) }, { ...m });
301
+ v = t.value;
528
302
  }
529
- let v;
303
+ let y;
530
304
  try {
531
- v = o.resolveSubject ? await o.resolveSubject(d.headers) : e(d.headers["x-tenant"] ?? null);
532
- } catch (e) {
533
- if (e instanceof t || typeof e == "object" && e && e._tag === "Unauthenticated") {
534
- let t = e.reason;
535
- return Q(a, d, 401, "Unauthorized", t ?? "Authentication required", {}, { ...p });
305
+ y = c.resolveSubject ? await c.resolveSubject(f.headers) : t(f.headers["x-tenant"] ?? null);
306
+ } catch (t) {
307
+ if (t instanceof e || typeof t == "object" && t && t._tag === "Unauthenticated") {
308
+ let e = t.reason;
309
+ return q(s, f, 401, "Unauthorized", e ?? "Authentication required", {}, { ...m });
536
310
  }
537
- throw e;
311
+ throw t;
538
312
  }
313
+ if (s.credentials === "bearer" && y.type === "anonymous") return q(s, f, 401, "Unauthorized", y.credentialRejected ?? "Authentication required", {}, { ...m });
539
314
  let b;
540
315
  try {
541
- b = o.buildContext ? await o.buildContext(v, d.headers) : void 0;
316
+ b = c.buildContext ? await c.buildContext(y, f.headers) : void 0;
542
317
  } catch (e) {
543
- return Se(e, v, a, p, d);
318
+ return I(s, $(e, y, s, m, f));
544
319
  }
545
- let S = typeof b == "object" && b && "store" in b ? b.store : o.store, C = {
546
- subject: v,
547
- headers: d.headers,
548
- store: S,
549
- method: g,
550
- path: d.path,
551
- query: d.query,
552
- rawBody: d.rawBody,
320
+ let x = typeof b == "object" && b && "store" in b ? b.store : c.store, S = {
321
+ subject: y,
322
+ headers: f.headers,
323
+ store: x,
324
+ method: _,
325
+ path: f.path,
326
+ query: f.query,
327
+ rawBody: f.rawBody,
553
328
  ...b === void 0 ? {} : { app: b },
554
- ...d.remoteAddr === void 0 ? {} : { remoteAddr: d.remoteAddr }
329
+ ...f.remoteAddr === void 0 ? {} : { remoteAddr: f.remoteAddr }
555
330
  };
556
- if (a.guards) for (let e of a.guards) {
557
- let t = await e(C);
558
- if (t) return Q(a, d, t.status, t.status === 401 ? "Unauthorized" : t.status === 403 ? "Forbidden" : "GuardRejected", t.message, {}, { ...p });
331
+ try {
332
+ if (s.guards) for (let e of s.guards) {
333
+ let t = await e(S);
334
+ if (t) return q(s, f, t.status, t.status === 401 ? "Unauthorized" : t.status === 403 ? "Forbidden" : "GuardRejected", t.message, {}, { ...m });
335
+ }
336
+ if (s.rateLimit !== void 0 && c.rateLimit !== void 0) {
337
+ let e = await A.runPromise(c.rateLimit(s.rateLimit, S, s).pipe(A.as({ allowed: !0 }), A.catch((e) => A.succeed({
338
+ allowed: !1,
339
+ error: e
340
+ }))));
341
+ if (!e.allowed) return $(e.error, y, s, m, f);
342
+ }
343
+ } catch (e) {
344
+ return $(e, y, s, m, f);
559
345
  }
560
- let w = o.idempotency, T = w && $.has(a.method) ? d.headers[w.header.toLowerCase()] : void 0, E = w && T ? u(v.tenantId, a.method, a.path) : "", D;
561
- if (w && T) {
562
- let e = await y(w.store, E, T, w.ttlMs, Date.now());
563
- if (e.kind === "replay") return Z(e.response.status, e.response.body, {
564
- ...p,
346
+ let C = c.idempotency, w = C && Q.has(s.method) ? f.headers[C.header.toLowerCase()] : void 0, T = C && w ? o(y.tenantId, s.method, s.path) : "", E;
347
+ if (C && w) {
348
+ let e = await n(C.store, T, w, C.ttlMs, Date.now());
349
+ if (e.kind === "replay") return K(e.response.status, e.response.body, {
350
+ ...m,
565
351
  "Idempotency-Replayed": "true"
566
352
  });
567
- if (e.kind === "conflict") return Q(a, d, 409, "Conflict", "A request with this Idempotency-Key is already being processed", {}, { ...p });
568
- D = r(w.store, E, T);
353
+ if (e.kind === "conflict") return q(s, f, 409, "Conflict", "A request with this Idempotency-Key is already being processed", {}, { ...m });
354
+ E = a(C.store, T, w);
569
355
  }
570
356
  try {
571
- let e = await a.handler(_, C);
572
- if (fe(e) || X(e)) return w && T && await i(w.store, E, T), X(e) ? {
357
+ let e = await s.handler(v, S);
358
+ if (W(e) || G(e)) return C && w && await r(C.store, T, w), G(e) ? {
573
359
  status: e.status ?? 200,
574
360
  headers: {
575
- ...p,
361
+ ...m,
576
362
  ...e.headers
577
363
  },
578
364
  byteStream: e.byteStream,
579
365
  ...e.contentType === void 0 ? {} : { contentType: e.contentType }
580
366
  } : {
581
367
  status: 200,
582
- headers: p,
368
+ headers: m,
583
369
  stream: e.stream
584
370
  };
585
- let t = se(e) ? e : J(e), r = await x.runPromise(l(t.body)), o = a.method === "GET" && t.status === 200 ? oe(a.cache, d, r, _) : {}, s = {
586
- ...p,
371
+ let t = R(e) ? e : L(e), n = await A.runPromise(d(t.body)), a = s.method === "GET" && t.status === 200 ? ce(s.cache, f, n, v, y) : {}, o = {
372
+ ...m,
587
373
  ...t.headers,
588
- ...o
374
+ ...a
589
375
  };
590
- if (w && T && await n(w.store, E, T, {
376
+ if (C && w && await i(C.store, T, w, {
591
377
  status: t.status,
592
- body: r
593
- }, Date.now()), a.etag === !0 && a.method === "GET") {
594
- let e = `W/"${await me(JSON.stringify(r))}"`, n = d.headers["if-none-match"];
595
- return n !== void 0 && n.split(",").some((t) => t.trim() === e) ? {
378
+ body: n
379
+ }, Date.now()), s.etag === !0 && s.method === "GET") {
380
+ let e = `W/"${await ue(JSON.stringify(n))}"`, r = f.headers["if-none-match"];
381
+ return r !== void 0 && r.split(",").some((t) => t.trim() === e) ? {
596
382
  status: 304,
597
383
  headers: {
598
- ...p,
599
- ...o,
384
+ ...m,
385
+ ...a,
600
386
  ETag: e
601
387
  }
602
- } : Z(t.status, r, {
603
- ...s,
388
+ } : I(s, K(t.status, n, {
389
+ ...o,
604
390
  ETag: e
605
- }, t.contentType);
391
+ }, t.contentType));
606
392
  }
607
- return t.status === 204 || t.status === 304 ? {
393
+ return t.status === 204 || t.status === 304 ? I(s, {
608
394
  status: t.status,
609
- headers: s
610
- } : Z(t.status, r, s, t.contentType);
395
+ headers: o
396
+ }) : I(s, K(t.status, n, o, t.contentType));
611
397
  } catch (e) {
612
- return w && T && await i(w.store, E, T), Se(e, v, a, p, d);
398
+ return C && w && await r(C.store, T, w), I(s, $(e, y, s, m, f));
613
399
  } finally {
614
- D?.();
400
+ E?.();
615
401
  }
616
402
  }
617
403
  };
618
- }, we = (e, t = {}) => {
404
+ return {
405
+ ..._,
406
+ handle: async (e) => {
407
+ let n = P(s.cors, e.headers.origin), r;
408
+ if (s.cors !== void 0 && e.method === "OPTIONS" && e.headers["access-control-request-method"] !== void 0 && e.headers["access-control-request-method"] === s.method) return F(s.cors, s.method, e.headers);
409
+ let i = e;
410
+ if (s.credentials === "bearer" && (e.method === s.method || e.method === "HEAD" && s.method === "GET")) {
411
+ let t = Object.fromEntries(Object.entries(e.headers).filter(([e]) => e.toLowerCase() !== "cookie"));
412
+ if (i = {
413
+ ...e,
414
+ headers: t
415
+ }, !/^Bearer\s+\S+$/i.test(t.authorization ?? "")) return q(s, i, 401, "Unauthorized", "Bearer authentication required", {}, n);
416
+ }
417
+ try {
418
+ r = await _.handle(i);
419
+ } catch (e) {
420
+ r = $(e, t(null), s, m, i);
421
+ }
422
+ let a = {
423
+ ...r.headers,
424
+ ...n
425
+ }, o = Object.entries(r.headers ?? {}).find(([e]) => e.toLowerCase() === "vary")?.[1];
426
+ if (o !== void 0 && s.cors !== void 0) {
427
+ for (let e of Object.keys(a)) e.toLowerCase() === "vary" && delete a[e];
428
+ a.vary = [...new Set(`${Array.isArray(o) ? o.join(", ") : o}, Origin`.split(",").map((e) => e.trim()))].join(", ");
429
+ }
430
+ return I(s, {
431
+ ...r,
432
+ headers: a
433
+ });
434
+ }
435
+ };
436
+ }, he = (e, t = {}) => {
437
+ for (let n of e) {
438
+ if (n.rateLimit !== void 0 && t.rateLimit === void 0) throw Error(`REST route ${n.method} ${n.path} declares rateLimit but no rate-limit plugin is mounted`);
439
+ if (n.rateLimit !== void 0 && (!Number.isInteger(n.rateLimit.limit) || n.rateLimit.limit <= 0)) throw Error(`REST route ${n.method} ${n.path} rateLimit.limit must be a positive integer`);
440
+ }
619
441
  if (t.idempotency !== void 0) {
620
- for (let t of e) if (t.streaming === !0 && $.has(t.method)) throw Error(`REST route ${t.method} ${t.path} declares \`streaming: true\` on a method the idempotency binding claims (${[...$].join("/")}). A stream cannot complete an idempotency claim — there is no replayable body to cache — so a retried request would 409 until the claim's TTL. Either serve the stream on GET, or scope the idempotency binding away from this app's streaming routes.`);
442
+ for (let t of e) if (t.streaming === !0 && Q.has(t.method)) throw Error(`REST route ${t.method} ${t.path} declares \`streaming: true\` on a method the idempotency binding claims (${[...Q].join("/")}). A stream cannot complete an idempotency claim — there is no replayable body to cache — so a retried request would 409 until the claim's TTL. Either serve the stream on GET, or scope the idempotency binding away from this app's streaming routes.`);
621
443
  }
622
444
  let n = (e) => e.split("/").map((e) => e.startsWith(":") ? ":" : e).join("/"), r = /* @__PURE__ */ new Map();
623
445
  for (let t of e) {
624
446
  let e = r.get(n(t.path)) ?? [];
625
447
  e.includes(t.method) || e.push(t.method), r.set(n(t.path), e);
626
448
  }
627
- return e.map((e) => Ce(e, t, r.get(n(e.path)).join(", ")));
628
- }, Te = async (e, t) => {
449
+ return e.map((e) => me(e, t, r.get(n(e.path)).join(", ")));
450
+ }, ge = async (e, t) => {
629
451
  let n = await e[0].handle(t);
630
452
  for (let r = 1; r < e.length && n.status === 405; r++) n = await e[r].handle(t);
631
453
  return n;
632
454
  };
633
455
  //#endregion
634
- export { g as JSONAPI_MEDIA_TYPE, f as PROBLEM_JSON, m as REST_PROFILE_NAMES, Y as RestRouteError, pe as bytes, F as coerceQueryObject, P as coerceQueryValue, W as collectPublicApiRoutes, I as declaredErrorTags, le as defineRestRoute, T as derivePublicMethod, E as derivePublicPath, k as deriveResource, Te as dispatchSharedPath, l as encodeRestError, a as encodeRestSuccess, z as errorMemberSchema, X as isRestByteResponse, se as isRestResponse, fe as isRestStreamResponse, ye as matchPathParams, p as nextLink, A as normalizePathParams, te as operationIdOf, j as pathParamNames, h as problemDetails, o as problemTypeOf, R as projectedFailure, U as publicApiRoute, G as publicSurfaceDigest, ae as requireAnyScope, K as requireAuthenticated, q as requireScope, d as resolveRestFormat, O as resourceIdField, J as response, ce as restError, we as restRoutesToHttpRoutes, _ as restViewSchema, be as routeAcceptsPath, ue as sse, de as sseFrame, s as toSnakeCase, H as wireExample };
456
+ export { c as JSONAPI_MEDIA_TYPE, l as PROBLEM_JSON, u as REST_PROFILE_NAMES, z as RestRouteError, le as bytes, y as coerceQueryObject, b as coerceQueryValue, x as collectPublicApiRoutes, S as declaredErrorTags, V as defineRestRoute, C as derivePublicMethod, w as derivePublicPath, T as deriveResource, ge as dispatchSharedPath, d as encodeRestError, f as encodeRestSuccess, E as errorMemberSchema, G as isRestByteResponse, R as isRestResponse, W as isRestStreamResponse, Z as matchPathParams, p as nextLink, D as normalizePathParams, O as operationIdOf, k as pathParamNames, m as problemDetails, h as problemTypeOf, ee as projectedFailure, te as publicApiRoute, ne as publicSurfaceDigest, se as requireAnyScope, ae as requireAuthenticated, oe as requireScope, g as resolveRestFormat, re as resourceIdField, L as response, P as restCorsHeaders, F as restCorsPreflight, B as restError, he as restRoutesToHttpRoutes, _ as restViewSchema, fe as routeAcceptsPath, H as sse, U as sseFrame, v as toSnakeCase, ie as wireExample };