@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.
- package/CHANGELOG.md +1215 -0
- package/README.md +14 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/apikey.d.ts +32 -34
- package/dist/approval.js +64 -0
- package/dist/approvalDescriptors.js +26 -0
- package/dist/auth.js +369 -0
- package/dist/boundedRing.js +27 -0
- package/dist/businessRule.js +11 -0
- package/dist/connection.js +73 -0
- package/dist/devActivity.js +4 -0
- package/dist/errorValue.js +21 -0
- package/dist/event.js +104 -0
- package/dist/idempotency.js +66 -0
- package/dist/identity.js +5 -9
- package/dist/index.d.ts +1494 -1366
- package/dist/index.js +42 -1411
- package/dist/inspect.d.ts +88 -88
- package/dist/inspect.js +14 -190
- package/dist/inspectBackfill.js +52 -0
- package/dist/inspectCommandRejection.js +21 -0
- package/dist/inspectProjection.js +133 -0
- package/dist/inspectStorageProjection.js +86 -0
- package/dist/inspectValueIdentity.js +4 -0
- package/dist/inspectWorkflowExecution.js +34 -0
- package/dist/inspectWorkflowQueuedStart.js +31 -0
- package/dist/jsonSchema.js +54 -0
- package/dist/jwt.d.ts +32 -34
- package/dist/outbox.js +10 -0
- package/dist/pairing.js +75 -0
- package/dist/plugin.js +61 -0
- package/dist/pluginNaming.js +32 -0
- package/dist/procedure.js +262 -0
- package/dist/publicApi.js +344 -0
- package/dist/reactivityChannel.js +34 -0
- package/dist/rest.d.ts +105 -57
- package/dist/rest.js +259 -437
- package/dist/restFormat.js +163 -0
- package/dist/rowEquality.js +31 -0
- package/dist/rowPatch.js +182 -0
- package/dist/schemaShape.js +67 -0
- package/dist/scopes.js +240 -0
- package/dist/serverErrorBus.js +15 -0
- package/dist/serviceCall.js +14 -0
- package/dist/session.d.ts +90 -96
- package/dist/session.js +13 -15
- package/dist/{sessionHeader-DriTZhmv.js → sessionHeader.js} +1 -1
- package/dist/storageAccess.js +14 -0
- package/dist/storeErrors.js +66 -0
- package/dist/storeScreenshots.js +90 -0
- package/dist/strictInput.js +27 -0
- package/dist/subscriptionEvent.js +37 -0
- package/dist/tenantSelection.js +40 -0
- package/dist/time.js +7 -0
- package/dist/undo.js +38 -0
- package/dist/validation.js +39 -0
- package/dist/webSocketGateway.js +10 -0
- package/dist/workflow.js +297 -0
- package/dist/workflowAccess.js +61 -0
- package/dist/workflowRestart.js +45 -0
- package/dist/workflowRetry.js +44 -0
- package/dist/workflowStartOutcome.js +30 -0
- package/package.json +4 -8
- package/dist/restFormat-EZ8k9ZcQ.js +0 -304
- package/dist/scopes-Di756ENh.js +0 -518
package/dist/rest.js
CHANGED
|
@@ -1,341 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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 (
|
|
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
|
-
},
|
|
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
|
|
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
|
-
...
|
|
81
|
+
...a
|
|
316
82
|
};
|
|
317
|
-
|
|
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=${
|
|
320
|
-
`s-maxage=${
|
|
89
|
+
`max-age=${o}`,
|
|
90
|
+
`s-maxage=${o}`
|
|
321
91
|
];
|
|
322
|
-
e.staleWhileRevalidate !== void 0 &&
|
|
323
|
-
let
|
|
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":
|
|
326
|
-
...
|
|
327
|
-
...
|
|
328
|
-
"Cache-Tag":
|
|
329
|
-
"Surrogate-Key":
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
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
|
-
}),
|
|
371
|
-
let t = await globalThis.crypto.subtle.digest("SHA-1", new TextEncoder().encode(e));
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
}),
|
|
149
|
+
}), q = (e, t, n, r, i, a, o) => {
|
|
379
150
|
let s = e.projection;
|
|
380
|
-
if (s === void 0) return
|
|
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
|
-
},
|
|
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
|
|
168
|
+
return K(n, l.body, {
|
|
398
169
|
...o,
|
|
399
|
-
...
|
|
400
|
-
},
|
|
401
|
-
},
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
424
|
-
let n = e.
|
|
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
|
-
},
|
|
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
|
-
},
|
|
448
|
-
query:
|
|
218
|
+
}, pe = (e, t, n) => ({
|
|
219
|
+
query: de(e.query),
|
|
449
220
|
params: t,
|
|
450
|
-
body: n ?
|
|
451
|
-
form:
|
|
452
|
-
}),
|
|
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
|
-
]),
|
|
458
|
-
if (
|
|
228
|
+
]), $ = (t, n, r, i, a) => {
|
|
229
|
+
if (t instanceof z) return K(t.status, t.body, {
|
|
459
230
|
...i,
|
|
460
|
-
...
|
|
461
|
-
},
|
|
462
|
-
if (typeof
|
|
463
|
-
let o =
|
|
464
|
-
if (typeof o.status == "number") return
|
|
465
|
-
if (o._tag === "Unauthenticated" ||
|
|
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
|
|
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
|
|
472
|
-
return
|
|
473
|
-
resourceType: typeof
|
|
474
|
-
resourceId: typeof
|
|
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
|
|
479
|
-
error:
|
|
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
|
-
...
|
|
485
|
-
cause:
|
|
255
|
+
...q(r, a, 500, "InternalServerError", "Internal Server Error", {}, { ...i }),
|
|
256
|
+
cause: t
|
|
486
257
|
};
|
|
487
|
-
},
|
|
488
|
-
let
|
|
489
|
-
|
|
490
|
-
let
|
|
491
|
-
|
|
492
|
-
|
|
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:
|
|
495
|
-
match:
|
|
496
|
-
...
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (!(
|
|
501
|
-
|
|
502
|
-
|
|
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 (
|
|
505
|
-
let e = Date.parse(
|
|
506
|
-
if (!Number.isNaN(e) && Date.now() >= e) return
|
|
507
|
-
...
|
|
508
|
-
...
|
|
509
|
-
}, { ...
|
|
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 (
|
|
285
|
+
let v;
|
|
286
|
+
if (u) {
|
|
513
287
|
let e;
|
|
514
288
|
try {
|
|
515
|
-
e =
|
|
289
|
+
e = pe(f, Z(s.path, f.path), p);
|
|
516
290
|
} catch {
|
|
517
|
-
return
|
|
291
|
+
return q(s, f, 400, "InvalidRequest", "Malformed request body", {}, { ...m });
|
|
518
292
|
}
|
|
519
|
-
let t = await
|
|
293
|
+
let t = await A.runPromise(u(e).pipe(A.map((e) => ({
|
|
520
294
|
ok: !0,
|
|
521
295
|
value: e
|
|
522
|
-
})),
|
|
296
|
+
})), A.catch((e) => A.succeed({
|
|
523
297
|
ok: !1,
|
|
524
298
|
cause: e
|
|
525
299
|
}))));
|
|
526
|
-
if (!t.ok) return
|
|
527
|
-
|
|
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
|
|
303
|
+
let y;
|
|
530
304
|
try {
|
|
531
|
-
|
|
532
|
-
} catch (
|
|
533
|
-
if (
|
|
534
|
-
let
|
|
535
|
-
return
|
|
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
|
|
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 =
|
|
316
|
+
b = c.buildContext ? await c.buildContext(y, f.headers) : void 0;
|
|
542
317
|
} catch (e) {
|
|
543
|
-
return
|
|
318
|
+
return I(s, $(e, y, s, m, f));
|
|
544
319
|
}
|
|
545
|
-
let
|
|
546
|
-
subject:
|
|
547
|
-
headers:
|
|
548
|
-
store:
|
|
549
|
-
method:
|
|
550
|
-
path:
|
|
551
|
-
query:
|
|
552
|
-
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
|
-
...
|
|
329
|
+
...f.remoteAddr === void 0 ? {} : { remoteAddr: f.remoteAddr }
|
|
555
330
|
};
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
|
561
|
-
if (
|
|
562
|
-
let e = await
|
|
563
|
-
if (e.kind === "replay") return
|
|
564
|
-
...
|
|
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
|
|
568
|
-
|
|
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
|
|
572
|
-
if (
|
|
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
|
-
...
|
|
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:
|
|
368
|
+
headers: m,
|
|
583
369
|
stream: e.stream
|
|
584
370
|
};
|
|
585
|
-
let t =
|
|
586
|
-
...
|
|
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
|
-
...
|
|
374
|
+
...a
|
|
589
375
|
};
|
|
590
|
-
if (
|
|
376
|
+
if (C && w && await i(C.store, T, w, {
|
|
591
377
|
status: t.status,
|
|
592
|
-
body:
|
|
593
|
-
}, Date.now()),
|
|
594
|
-
let e = `W/"${await
|
|
595
|
-
return
|
|
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
|
-
...
|
|
599
|
-
...
|
|
384
|
+
...m,
|
|
385
|
+
...a,
|
|
600
386
|
ETag: e
|
|
601
387
|
}
|
|
602
|
-
} :
|
|
603
|
-
...
|
|
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:
|
|
610
|
-
} :
|
|
395
|
+
headers: o
|
|
396
|
+
}) : I(s, K(t.status, n, o, t.contentType));
|
|
611
397
|
} catch (e) {
|
|
612
|
-
return
|
|
398
|
+
return C && w && await r(C.store, T, w), I(s, $(e, y, s, m, f));
|
|
613
399
|
} finally {
|
|
614
|
-
|
|
400
|
+
E?.();
|
|
615
401
|
}
|
|
616
402
|
}
|
|
617
403
|
};
|
|
618
|
-
|
|
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 &&
|
|
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) =>
|
|
628
|
-
},
|
|
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 {
|
|
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 };
|