@voltro/protocol 0.85.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 +666 -0
- package/README.md +14 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- 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 +225 -21
- package/dist/index.js +42 -1700
- package/dist/inspect.js +14 -240
- 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/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 +33 -0
- package/dist/rest.js +213 -470
- 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.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 +3 -3
- package/dist/restFormat-BlgTLxm1.js +0 -298
- package/dist/scopes-ClywBij8.js +0 -548
package/dist/rest.js
CHANGED
|
@@ -1,355 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (n === void 0) return;
|
|
12
|
-
let r = `${O(e)}Id`;
|
|
13
|
-
return n.has(r) ? r : n.has("id") ? "id" : void 0;
|
|
14
|
-
}, A = (e, t, n) => {
|
|
15
|
-
let r = (t.resource ?? "").replace(/^\/+|\/+$/g, ""), i = `/${t.version ?? "v1"}/${r}`, a = k(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
|
-
}, j = (e) => e.replace(/\{([A-Za-z0-9_]+)\}/g, ":$1"), M = (e) => [...e.matchAll(/:([A-Za-z0-9_]+)/g)].map((e) => e[1]), N = (e) => {
|
|
33
|
-
if (T.isUnion(e)) {
|
|
34
|
-
let t = e.types.filter((e) => !T.isUndefined(e));
|
|
35
|
-
if (t.length === 1) return t[0];
|
|
36
|
-
if (t.length !== e.types.length) return new T.Union(t);
|
|
37
|
-
}
|
|
38
|
-
return e;
|
|
39
|
-
}, P = /^-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i, F = (e, t) => {
|
|
40
|
-
let n = N(t);
|
|
41
|
-
if (n.encoding !== void 0) return F(e, T.toEncoded(n));
|
|
42
|
-
if (T.isUnion(n)) {
|
|
43
|
-
for (let t of n.types) {
|
|
44
|
-
let n = F(e, t);
|
|
45
|
-
if (n !== e) return n;
|
|
46
|
-
}
|
|
47
|
-
return e;
|
|
48
|
-
}
|
|
49
|
-
if (T.isArrays(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] ?? n.elements[0];
|
|
53
|
-
return r === void 0 ? t : t.map((e) => F(e, r));
|
|
54
|
-
}
|
|
55
|
-
if (typeof e != "string") return e;
|
|
56
|
-
if (T.isNumber(n)) return P.test(e.trim()) ? Number(e) : e;
|
|
57
|
-
if (T.isBoolean(n)) return e === "true" || e !== "false" && e;
|
|
58
|
-
if (T.isLiteral(n)) {
|
|
59
|
-
let t = n.literal;
|
|
60
|
-
return typeof t == "number" && P.test(e.trim()) && Number(e) === t || typeof t == "boolean" && String(t) === e ? t : e;
|
|
61
|
-
}
|
|
62
|
-
return e;
|
|
63
|
-
}, I = (e, t) => {
|
|
64
|
-
if (typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
65
|
-
let n = N(T.toEncoded(t.ast));
|
|
66
|
-
if (!T.isObjects(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] = F(r[t], e.type));
|
|
71
|
-
}
|
|
72
|
-
return r;
|
|
73
|
-
}, ee = (e) => {
|
|
74
|
-
let t = N(T.toEncoded(e.ast));
|
|
75
|
-
if (!T.isObjects(t)) return (e) => e;
|
|
76
|
-
let n = t.propertySignatures, r = /* @__PURE__ */ new Map(), i = n.length >= 32 && n.every((e, t) => typeof e.name != "string" || e.name in Object.prototype || r.has(e.name) ? !1 : (r.set(e.name, {
|
|
77
|
-
type: e.type,
|
|
78
|
-
order: t
|
|
79
|
-
}), !0));
|
|
80
|
-
return (e) => {
|
|
81
|
-
if (typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
82
|
-
let t = { ...e }, a = i ? Object.keys(t) : void 0;
|
|
83
|
-
if (a !== void 0 && a.length * 4 < n.length) {
|
|
84
|
-
let e = [];
|
|
85
|
-
for (let t of a) {
|
|
86
|
-
let n = r.get(t);
|
|
87
|
-
n !== void 0 && e.push({
|
|
88
|
-
key: t,
|
|
89
|
-
...n
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
e.sort((e, t) => e.order - t.order);
|
|
93
|
-
for (let { key: n, type: r } of e) t[n] = F(t[n], r);
|
|
94
|
-
} else for (let e of n) {
|
|
95
|
-
let n = String(e.name);
|
|
96
|
-
n in t && (t[n] = F(t[n], e.type));
|
|
97
|
-
}
|
|
98
|
-
return t;
|
|
99
|
-
};
|
|
100
|
-
}, L = (e) => {
|
|
101
|
-
let t = /* @__PURE__ */ new Set();
|
|
102
|
-
if (e === void 0) return t;
|
|
103
|
-
let n = (e) => {
|
|
104
|
-
if (T.isUnion(e)) {
|
|
105
|
-
for (let t of e.types) n(t);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (e.encoding !== void 0 && n(T.toEncoded(e)), T.isObjects(e)) {
|
|
109
|
-
let n = e.propertySignatures.find((e) => e.name === "_tag");
|
|
110
|
-
n !== void 0 && T.isLiteral(n.type) && typeof n.type.literal == "string" && t.add(n.type.literal);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
return n(e.ast), t;
|
|
114
|
-
}, R = (e, t, n) => {
|
|
115
|
-
if (n !== void 0) try {
|
|
116
|
-
let r = S.encodeUnknownSync(n)(e);
|
|
117
|
-
if (typeof r == "object" && r) return {
|
|
118
|
-
error: t,
|
|
119
|
-
...r
|
|
120
|
-
};
|
|
121
|
-
} catch {}
|
|
122
|
-
let r = { error: t };
|
|
123
|
-
for (let [t, n] of Object.entries(e)) t !== "stack" && t !== "_tag" && (r[t] = n);
|
|
124
|
-
return r;
|
|
125
|
-
}, z = (e, t, n, r = []) => B(e, t, n, r, L), B = (e, t, n, r, i) => {
|
|
126
|
-
if (typeof e != "object" || !e) return e;
|
|
127
|
-
let a = e._tag;
|
|
128
|
-
if (typeof a != "string" || a === "ScopeError" || a === "NoSuchResource") return e;
|
|
129
|
-
if (i(t.error).has(a)) return new Y(n.errorStatus?.[a] ?? 422, R(e, a, t.error));
|
|
130
|
-
let o = r.find((e) => i(e.schema).has(a));
|
|
131
|
-
if (o === void 0) return e;
|
|
132
|
-
let s = n.errorStatus?.[a] ?? o.rest?.status ?? 422, c = o.rest?.headers?.(e);
|
|
133
|
-
return new Y(s, R(e, a, o.schema), c);
|
|
134
|
-
}, te = (e, t, n, r, i, a, o) => {
|
|
135
|
-
let s = B(e, t, n, r, o);
|
|
136
|
-
if (!(s instanceof Y) || i.errors === "tagged" && i.encodeError === void 0) return s;
|
|
137
|
-
let { error: c, _tag: u, ...d } = s.body, f = typeof d.message == "string" ? d.message : typeof d.reason == "string" ? d.reason : "", p = l(i, {
|
|
138
|
-
status: s.status,
|
|
139
|
-
tag: c,
|
|
140
|
-
message: f,
|
|
141
|
-
fields: d
|
|
142
|
-
}, {
|
|
143
|
-
...a,
|
|
144
|
-
status: s.status
|
|
145
|
-
});
|
|
146
|
-
return new Y(s.status, p.body, {
|
|
147
|
-
...s.headers ?? {},
|
|
148
|
-
...p.headers ?? {}
|
|
149
|
-
}, p.contentType);
|
|
150
|
-
}, V = (e, t) => {
|
|
151
|
-
if (e === void 0) return;
|
|
152
|
-
let n = T.isUnion(e.ast) ? e.ast.types : [e.ast];
|
|
153
|
-
for (let e of n) {
|
|
154
|
-
let n = S.make(e);
|
|
155
|
-
if (L(n).has(t)) return n;
|
|
156
|
-
}
|
|
157
|
-
}, ne = (e) => e.split(".").map((e, t) => t === 0 ? e : e.charAt(0).toUpperCase() + e.slice(1)).join("").replace(/[^A-Za-z0-9_]/g, "_"), re = (e) => {
|
|
158
|
-
let t = N(T.toEncoded(e.ast));
|
|
159
|
-
return T.isObjects(t) && t.indexSignatures.length === 0 ? new Set(t.propertySignatures.map((e) => String(e.name))) : void 0;
|
|
160
|
-
}, ie = (e, t) => e === t || JSON.stringify(e) === JSON.stringify(t), ae = (e) => {
|
|
161
|
-
let t = N(T.toEncoded(e.ast)), n = T.isObjects(t) ? new Map(t.propertySignatures.map((e) => [String(e.name), e.type])) : /* @__PURE__ */ new Map();
|
|
162
|
-
return (e) => {
|
|
163
|
-
let t = {};
|
|
164
|
-
for (let [r, i] of Object.entries(e)) {
|
|
165
|
-
let e = n.get(r);
|
|
166
|
-
t[r] = e === void 0 ? i : F(i, e);
|
|
167
|
-
}
|
|
168
|
-
return t;
|
|
169
|
-
};
|
|
170
|
-
}, H = (e, t) => {
|
|
171
|
-
if (e !== void 0) {
|
|
172
|
-
try {
|
|
173
|
-
return S.encodeUnknownSync(t)(e);
|
|
174
|
-
} catch {}
|
|
175
|
-
try {
|
|
176
|
-
return S.decodeUnknownSync(t)(e), e;
|
|
177
|
-
} catch {}
|
|
178
|
-
return e;
|
|
179
|
-
}
|
|
180
|
-
}, oe = (e, t, n) => ({
|
|
181
|
-
...e.request === void 0 ? {} : { request: H(e.request, t) },
|
|
182
|
-
...e.response === void 0 ? {} : { response: H(e.response, n) }
|
|
183
|
-
}), se = () => (e) => {
|
|
184
|
-
if (e.subject.type !== "anonymous") return;
|
|
185
|
-
let t = e.subject.credentialRejected;
|
|
186
|
-
return t === void 0 ? void 0 : {
|
|
187
|
-
status: 401,
|
|
188
|
-
message: t
|
|
189
|
-
};
|
|
190
|
-
}, U = (e, t, n, r = {}) => {
|
|
191
|
-
let i = e.publicApi;
|
|
192
|
-
if (i === void 0) throw Error(`publicApiRoute: descriptor '${e.name}' has no publicApi annotation`);
|
|
193
|
-
let o = d(r.profile, i.format), c = r.pluginErrors ?? [], l = /* @__PURE__ */ new WeakMap(), u = (e) => {
|
|
194
|
-
if (e === void 0) return /* @__PURE__ */ new Set();
|
|
195
|
-
let t = l.get(e.ast);
|
|
196
|
-
if (t !== void 0) return t;
|
|
197
|
-
let n = L(e);
|
|
198
|
-
return l.set(e.ast, n), n;
|
|
199
|
-
}, f = /* @__PURE__ */ new WeakMap(), p = (e, t) => {
|
|
200
|
-
if (e === void 0) return;
|
|
201
|
-
let n = f.get(e.ast);
|
|
202
|
-
if (n === void 0) {
|
|
203
|
-
let t = /* @__PURE__ */ new Map();
|
|
204
|
-
for (let n of T.isUnion(e.ast) ? e.ast.types : [e.ast]) {
|
|
205
|
-
let e = S.make(n);
|
|
206
|
-
for (let n of u(e)) t.has(n) || t.set(n, e);
|
|
207
|
-
}
|
|
208
|
-
n = t, f.set(e.ast, n);
|
|
209
|
-
}
|
|
210
|
-
return n.get(t);
|
|
211
|
-
}, m = {
|
|
212
|
-
kind: e.kind,
|
|
213
|
-
input: e.input,
|
|
214
|
-
target: e.target
|
|
215
|
-
}, h = E(e.kind, i, m), g = (e) => o.naming === "snake_case" ? s(e) : e, v = D(e.name, i, m), y = v.replace(/:([A-Za-z0-9_]+)/g, (e, t) => `:${g(t)}`), b = M(y), O = _(e.input, o), k = ee(O), A = ae(O), j = re(O);
|
|
216
|
-
if (j !== void 0) {
|
|
217
|
-
for (let t of b) if (!j.has(t)) throw Error(`publicApi: descriptor '${e.name}' — path '${v}' binds ':${t}', and the input declares no field of that name` + (j.size > 0 ? ` (fields: ${[...j].join(", ")})` : " (the input declares no fields)"));
|
|
218
|
-
}
|
|
219
|
-
let N = _(e.output, o), P = S.Struct({ value: O }), F = h !== "GET" && j === void 0;
|
|
220
|
-
if (h !== "GET" && j !== void 0) {
|
|
221
|
-
let e = b.length >= 32 ? new Set(b) : void 0;
|
|
222
|
-
for (let t of j) if (!(e?.has(t) ?? b.includes(t))) {
|
|
223
|
-
F = !0;
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
let I = {
|
|
228
|
-
query: S.Unknown,
|
|
229
|
-
params: S.Unknown,
|
|
230
|
-
form: S.Boolean
|
|
231
|
-
}, R = (F ? S.Struct({
|
|
232
|
-
...I,
|
|
233
|
-
body: S.Unknown
|
|
234
|
-
}) : S.Struct(I)).pipe(S.decodeTo(P, {
|
|
235
|
-
decode: C.transformEffect((e) => {
|
|
236
|
-
let t = "body" in e ? e.body : void 0, n = h === "GET" ? k(e.query) : e.form ? k(t ?? {}) : t ?? {}, r = typeof e.params == "object" && e.params !== null ? A(e.params) : {};
|
|
237
|
-
if (typeof n != "object" || !n || Array.isArray(n)) return x.succeed({ value: n });
|
|
238
|
-
let i = n, a = Object.keys(r), o = 0;
|
|
239
|
-
for (let e of a) e in i && !ie(i[e], r[e]) && (a[o++] = e);
|
|
240
|
-
if (a.length = o, a.length > 0) {
|
|
241
|
-
let t = h === "GET" ? "query string" : "body";
|
|
242
|
-
return x.fail(new w.InvalidValue({ message: `${a.map((e) => `'${e}'`).join(", ")} ${a.length === 1 ? "is" : "are"} bound by the path and sent with another value in the ${t}` }, e));
|
|
243
|
-
}
|
|
244
|
-
return x.succeed({ value: {
|
|
245
|
-
...i,
|
|
246
|
-
...r
|
|
247
|
-
} });
|
|
248
|
-
}),
|
|
249
|
-
encode: C.transform((e) => e)
|
|
250
|
-
})), z = [
|
|
251
|
-
se(),
|
|
252
|
-
...e.openAccess === void 0 ? [le()] : [],
|
|
253
|
-
...(i.scopes ?? []).map((e) => ue(e))
|
|
254
|
-
], B = (() => {
|
|
255
|
-
let t = e.source;
|
|
256
|
-
return typeof t == "string" ? t : Array.isArray(t) ? t[0] : void 0;
|
|
257
|
-
})(), V = (t, n = 200) => ({
|
|
258
|
-
tag: e.name,
|
|
259
|
-
method: t.method,
|
|
260
|
-
path: t.path,
|
|
261
|
-
query: t.query,
|
|
262
|
-
source: B,
|
|
263
|
-
status: n
|
|
264
|
-
}), H = i.stream === "sse" && e.kind === "query" && n !== void 0, U = S.encodeUnknownEffect(N), ce = H ? (e, t) => he((r) => n(e.value, t, (e) => {
|
|
265
|
-
r(ge(String(e._tag ?? "message"), e));
|
|
266
|
-
})) : async (n, r) => {
|
|
267
|
-
let s;
|
|
268
|
-
try {
|
|
269
|
-
s = await t(n.value, r);
|
|
270
|
-
} catch (t) {
|
|
271
|
-
throw te(t, e, i, c, o, V(r), u);
|
|
272
|
-
}
|
|
273
|
-
let l = await x.runPromise(U(s)), d = a(o, l, V(r));
|
|
274
|
-
return q(d.body, {
|
|
275
|
-
...d.headers === void 0 ? {} : { headers: d.headers },
|
|
276
|
-
...d.contentType === void 0 ? {} : { contentType: d.contentType }
|
|
277
|
-
});
|
|
278
|
-
}, W = e.error, G = u(W), de = [...G], K = [];
|
|
279
|
-
for (let e of de) {
|
|
280
|
-
let t = p(W, e);
|
|
281
|
-
t !== void 0 && K.push({
|
|
282
|
-
status: i.errorStatus?.[e] ?? 422,
|
|
283
|
-
tag: e,
|
|
284
|
-
schema: t
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
for (let e of c) for (let t of u(e.schema)) {
|
|
288
|
-
if (G.has(t)) continue;
|
|
289
|
-
let n = i.errorStatus?.[t] ?? e.rest?.status;
|
|
290
|
-
if (n === void 0) continue;
|
|
291
|
-
let r = p(e.schema, t) ?? e.schema;
|
|
292
|
-
K.push({
|
|
293
|
-
status: n,
|
|
294
|
-
tag: t,
|
|
295
|
-
schema: r
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
let fe = i.security === !1 ? "none" : i.security ?? (e.openAccess === void 0 ? "required" : "optional"), J = {
|
|
299
|
-
tag: e.name,
|
|
300
|
-
kind: e.kind,
|
|
301
|
-
version: i.version ?? "v1",
|
|
302
|
-
security: fe,
|
|
303
|
-
idempotent: i.idempotent === !0,
|
|
304
|
-
input: O,
|
|
305
|
-
pathParams: b,
|
|
306
|
-
output: N,
|
|
307
|
-
source: B,
|
|
308
|
-
errorResponses: K,
|
|
309
|
-
format: o
|
|
310
|
-
};
|
|
311
|
-
return me({
|
|
312
|
-
method: h,
|
|
313
|
-
path: y,
|
|
314
|
-
input: R,
|
|
315
|
-
output: S.Unknown,
|
|
316
|
-
handler: ce,
|
|
317
|
-
...H ? { streaming: !0 } : {},
|
|
318
|
-
guards: z,
|
|
319
|
-
operationId: i.operationId ?? ne(e.name),
|
|
320
|
-
tags: i.tags ?? [e.name.split(".")[0] ?? e.name],
|
|
321
|
-
projection: J,
|
|
322
|
-
...o.etag && h === "GET" && !H ? { etag: !0 } : {},
|
|
323
|
-
...i.cache !== void 0 && h === "GET" && !H ? { cache: i.cache } : {},
|
|
324
|
-
...i.example === void 0 ? {} : { example: oe(i.example, O, N) },
|
|
325
|
-
...i.summary === void 0 ? {} : { summary: i.summary },
|
|
326
|
-
...i.description === void 0 ? {} : { description: i.description },
|
|
327
|
-
...i.deprecated === void 0 ? {} : { deprecated: i.deprecated },
|
|
328
|
-
...i.sunset === void 0 ? {} : { sunset: i.sunset }
|
|
329
|
-
});
|
|
330
|
-
}, ce = (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)), W = (e) => b(e.filter((e) => e.projection !== void 0).map((e) => {
|
|
331
|
-
let t = e.projection, n = {
|
|
332
|
-
tag: t.tag,
|
|
333
|
-
method: e.method,
|
|
334
|
-
path: e.path,
|
|
335
|
-
pathParams: t.pathParams,
|
|
336
|
-
version: t.version,
|
|
337
|
-
security: t.security,
|
|
338
|
-
errors: [...t.errorResponses].map((e) => `${e.status}:${e.tag}`).sort()
|
|
339
|
-
};
|
|
340
|
-
return `${JSON.stringify(n)} ${v(t.input.ast)} ${v(t.output.ast)}`;
|
|
341
|
-
}).sort().join("\n")), le = () => (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) => {
|
|
342
11
|
if (e.subject.type === "anonymous") return {
|
|
343
12
|
status: 401,
|
|
344
13
|
message: e.subject.credentialRejected ?? "Authentication required"
|
|
345
14
|
};
|
|
346
|
-
},
|
|
15
|
+
}, oe = (e) => (t) => {
|
|
347
16
|
let n = t.subject.scopes;
|
|
348
17
|
if (!(n && (n.includes(e) || n.includes("admin:full")))) return {
|
|
349
18
|
status: 403,
|
|
350
19
|
message: `Missing required scope: ${e}`
|
|
351
20
|
};
|
|
352
|
-
},
|
|
21
|
+
}, N = (e) => {
|
|
353
22
|
for (let t of [
|
|
354
23
|
"includes",
|
|
355
24
|
"some",
|
|
@@ -364,24 +33,47 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
364
33
|
if (n === void 0 || !("value" in n) || typeof n.value != "string") return !1;
|
|
365
34
|
}
|
|
366
35
|
return !0;
|
|
367
|
-
},
|
|
36
|
+
}, se = (e) => (t) => {
|
|
368
37
|
let n = t.subject.scopes;
|
|
369
38
|
if (n) {
|
|
370
39
|
if (n.includes("admin:full")) return;
|
|
371
|
-
let t = n.length >= 32 && e.length >= 256 &&
|
|
40
|
+
let t = n.length >= 32 && e.length >= 256 && N(n) && N(e) ? new Set(n) : void 0;
|
|
372
41
|
if (e.some((e) => t === void 0 ? n.includes(e) : t.has(e))) return;
|
|
373
42
|
}
|
|
374
43
|
return {
|
|
375
44
|
status: 403,
|
|
376
45
|
message: `Missing required scope: one of ${e.join(", ")}`
|
|
377
46
|
};
|
|
378
|
-
},
|
|
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 ? {
|
|
379
71
|
...t,
|
|
380
72
|
headers: {
|
|
381
73
|
...t.headers,
|
|
382
74
|
"Cache-Control": "private, no-store"
|
|
383
75
|
}
|
|
384
|
-
} : t,
|
|
76
|
+
} : t, ce = (e, t, n, r, i) => {
|
|
385
77
|
if (e === void 0) return {};
|
|
386
78
|
let a = { Vary: e.audience === void 0 ? "Authorization, Cookie" : "Authorization" };
|
|
387
79
|
if (t.headers.authorization !== void 0 || e.audience === void 0 && t.headers.cookie !== void 0) return {
|
|
@@ -407,13 +99,13 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
407
99
|
"Surrogate-Key": c.join(" ")
|
|
408
100
|
} : {}
|
|
409
101
|
};
|
|
410
|
-
},
|
|
102
|
+
}, L = (e, t = {}) => ({
|
|
411
103
|
__voltroRestResponse: !0,
|
|
412
104
|
status: t.status ?? 200,
|
|
413
105
|
body: e,
|
|
414
106
|
...t.headers === void 0 ? {} : { headers: t.headers },
|
|
415
107
|
...t.contentType === void 0 ? {} : { contentType: t.contentType }
|
|
416
|
-
}),
|
|
108
|
+
}), R = (e) => typeof e == "object" && !!e && e.__voltroRestResponse === !0, z = class extends Error {
|
|
417
109
|
status;
|
|
418
110
|
body;
|
|
419
111
|
headers;
|
|
@@ -421,7 +113,7 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
421
113
|
constructor(e, t, n, r) {
|
|
422
114
|
super(`REST ${e}`), this.name = "RestRouteError", this.status = e, this.body = t, this.headers = n, this.contentType = r;
|
|
423
115
|
}
|
|
424
|
-
},
|
|
116
|
+
}, B = (e, t, n) => new z(e, t, n), V = (e) => {
|
|
425
117
|
if (e.version === void 0) return e;
|
|
426
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', …`);
|
|
427
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.`);
|
|
@@ -429,13 +121,13 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
429
121
|
...e,
|
|
430
122
|
path: `/${e.version}${e.path}`
|
|
431
123
|
};
|
|
432
|
-
},
|
|
124
|
+
}, H = (e, t = {}) => ({
|
|
433
125
|
__voltroRestStream: !0,
|
|
434
126
|
stream: {
|
|
435
127
|
subscribe: e,
|
|
436
128
|
...t.keepAliveMs === void 0 ? {} : { keepAliveMs: t.keepAliveMs }
|
|
437
129
|
}
|
|
438
|
-
}),
|
|
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 = {}) => ({
|
|
439
131
|
__voltroRestBytes: !0,
|
|
440
132
|
byteStream: {
|
|
441
133
|
stream: e,
|
|
@@ -445,18 +137,18 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
445
137
|
...t.contentType === void 0 ? {} : { contentType: t.contentType },
|
|
446
138
|
...t.status === void 0 ? {} : { status: t.status },
|
|
447
139
|
...t.headers === void 0 ? {} : { headers: t.headers }
|
|
448
|
-
}),
|
|
140
|
+
}), G = (e) => typeof e == "object" && !!e && e.__voltroRestBytes === !0, ue = async (e) => {
|
|
449
141
|
let t = await globalThis.crypto.subtle.digest("SHA-1", new TextEncoder().encode(e)), n = "";
|
|
450
142
|
for (let e of new Uint8Array(t)) n += e.toString(16).padStart(2, "0");
|
|
451
143
|
return n;
|
|
452
|
-
},
|
|
144
|
+
}, K = (e, t, n, r = "application/json; charset=utf-8") => ({
|
|
453
145
|
status: e,
|
|
454
146
|
contentType: r,
|
|
455
147
|
body: JSON.stringify(t),
|
|
456
148
|
...n ? { headers: n } : {}
|
|
457
|
-
}),
|
|
149
|
+
}), q = (e, t, n, r, i, a, o) => {
|
|
458
150
|
let s = e.projection;
|
|
459
|
-
if (s === void 0) return
|
|
151
|
+
if (s === void 0) return K(n, {
|
|
460
152
|
error: i,
|
|
461
153
|
...a
|
|
462
154
|
}, o);
|
|
@@ -467,17 +159,17 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
467
159
|
query: t.query,
|
|
468
160
|
source: s.source,
|
|
469
161
|
status: n
|
|
470
|
-
},
|
|
162
|
+
}, l = d(s.format, {
|
|
471
163
|
status: n,
|
|
472
164
|
tag: r,
|
|
473
165
|
message: i,
|
|
474
166
|
fields: a
|
|
475
167
|
}, c);
|
|
476
|
-
return
|
|
168
|
+
return K(n, l.body, {
|
|
477
169
|
...o,
|
|
478
|
-
...
|
|
479
|
-
},
|
|
480
|
-
},
|
|
170
|
+
...l.headers ?? {}
|
|
171
|
+
}, l.contentType);
|
|
172
|
+
}, J = (e) => (e.headers["content-type"] ?? "application/json").split(";")[0].trim().toLowerCase(), Y = (e, t) => {
|
|
481
173
|
if (e.length === 0) return;
|
|
482
174
|
let n = t === "application/x-www-form-urlencoded";
|
|
483
175
|
if (!n && t !== "application/json" && !/^application\/[^/;\s]+\+json$/.test(t)) return;
|
|
@@ -485,21 +177,21 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
485
177
|
if (r.trim() !== "") {
|
|
486
178
|
if (n) {
|
|
487
179
|
let e = (e) => decodeURIComponent(e.replace(/\+/g, " "));
|
|
488
|
-
return
|
|
180
|
+
return X((r.match(/[^&]+/g) ?? []).map((t) => {
|
|
489
181
|
let n = t.indexOf("=");
|
|
490
182
|
return n < 0 ? [e(t), ""] : [e(t.slice(0, n)), e(t.slice(n + 1))];
|
|
491
183
|
}));
|
|
492
184
|
}
|
|
493
185
|
return JSON.parse(r);
|
|
494
186
|
}
|
|
495
|
-
},
|
|
187
|
+
}, de = (e) => X(new URLSearchParams(e)), X = (e) => {
|
|
496
188
|
let t = /* @__PURE__ */ new Map();
|
|
497
189
|
for (let [n, r] of e) {
|
|
498
190
|
let e = t.get(n);
|
|
499
191
|
e === void 0 ? t.set(n, r) : Array.isArray(e) ? e.push(r) : t.set(n, [e, r]);
|
|
500
192
|
}
|
|
501
193
|
return Object.fromEntries(t);
|
|
502
|
-
},
|
|
194
|
+
}, Z = (e, t) => {
|
|
503
195
|
let n = e.match(/[^/]+/g) ?? [], r = t.match(/[^/]+/g) ?? [], i = {};
|
|
504
196
|
for (let e = 0; e < n.length; e++) {
|
|
505
197
|
let t = n[e];
|
|
@@ -513,7 +205,7 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
513
205
|
}
|
|
514
206
|
}
|
|
515
207
|
return i;
|
|
516
|
-
},
|
|
208
|
+
}, fe = (e, t) => {
|
|
517
209
|
let n = e.path.split("/"), r = n[n.length - 1] === "*", i = r ? n.slice(0, -1) : n, a = t.split("/");
|
|
518
210
|
if (a.length < i.length) return !1;
|
|
519
211
|
for (let e = 0; e < i.length; e++) {
|
|
@@ -523,191 +215,242 @@ var E = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? A("",
|
|
|
523
215
|
} else if (t !== n) return !1;
|
|
524
216
|
}
|
|
525
217
|
return a.length === i.length ? !0 : e.match === "exact" && !r ? !1 : a.slice(i.length).some((e) => e.length > 0);
|
|
526
|
-
},
|
|
527
|
-
query:
|
|
218
|
+
}, pe = (e, t, n) => ({
|
|
219
|
+
query: de(e.query),
|
|
528
220
|
params: t,
|
|
529
|
-
body: n ?
|
|
530
|
-
form:
|
|
531
|
-
}),
|
|
221
|
+
body: n ? Y(e.rawBody, J(e)) : void 0,
|
|
222
|
+
form: J(e) === "application/x-www-form-urlencoded"
|
|
223
|
+
}), Q = /* @__PURE__ */ new Set([
|
|
532
224
|
"POST",
|
|
533
225
|
"PUT",
|
|
534
226
|
"PATCH",
|
|
535
227
|
"DELETE"
|
|
536
|
-
]),
|
|
537
|
-
if (
|
|
228
|
+
]), $ = (t, n, r, i, a) => {
|
|
229
|
+
if (t instanceof z) return K(t.status, t.body, {
|
|
538
230
|
...i,
|
|
539
|
-
...
|
|
540
|
-
},
|
|
541
|
-
if (typeof
|
|
542
|
-
let o =
|
|
543
|
-
if (typeof o.status == "number") return
|
|
544
|
-
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 });
|
|
545
237
|
if (o._tag === "ScopeError") {
|
|
546
238
|
let e = n.type === "anonymous" ? 401 : 403;
|
|
547
|
-
return
|
|
239
|
+
return q(r, a, e, e === 401 ? "Unauthorized" : "Forbidden", typeof o.message == "string" ? o.message : "Forbidden", {}, { ...i });
|
|
548
240
|
}
|
|
549
241
|
if (o._tag === "NoSuchResource") {
|
|
550
|
-
let
|
|
551
|
-
return
|
|
552
|
-
resourceType: typeof
|
|
553
|
-
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
|
|
554
246
|
}, { ...i });
|
|
555
247
|
}
|
|
556
248
|
}
|
|
557
|
-
return
|
|
558
|
-
error:
|
|
249
|
+
return s({
|
|
250
|
+
error: t,
|
|
559
251
|
source: "rest",
|
|
560
252
|
name: `${r.method} ${r.path}`,
|
|
561
253
|
fields: { status: 500 }
|
|
562
254
|
}), {
|
|
563
|
-
...
|
|
564
|
-
cause:
|
|
255
|
+
...q(r, a, 500, "InternalServerError", "Internal Server Error", {}, { ...i }),
|
|
256
|
+
cause: t
|
|
565
257
|
};
|
|
566
|
-
},
|
|
567
|
-
let
|
|
568
|
-
|
|
569
|
-
let
|
|
570
|
-
|
|
571
|
-
|
|
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,
|
|
572
265
|
answersOtherMethods: !0,
|
|
573
|
-
path:
|
|
574
|
-
match:
|
|
575
|
-
...
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (!(
|
|
580
|
-
|
|
581
|
-
|
|
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
|
|
582
277
|
});
|
|
583
|
-
if (
|
|
584
|
-
let e = Date.parse(
|
|
585
|
-
if (!Number.isNaN(e) && Date.now() >= e) return
|
|
586
|
-
...
|
|
587
|
-
...
|
|
588
|
-
}, { ...
|
|
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 });
|
|
589
284
|
}
|
|
590
|
-
let
|
|
591
|
-
if (
|
|
285
|
+
let v;
|
|
286
|
+
if (u) {
|
|
592
287
|
let e;
|
|
593
288
|
try {
|
|
594
|
-
e =
|
|
289
|
+
e = pe(f, Z(s.path, f.path), p);
|
|
595
290
|
} catch {
|
|
596
|
-
return
|
|
291
|
+
return q(s, f, 400, "InvalidRequest", "Malformed request body", {}, { ...m });
|
|
597
292
|
}
|
|
598
|
-
let t = await
|
|
293
|
+
let t = await A.runPromise(u(e).pipe(A.map((e) => ({
|
|
599
294
|
ok: !0,
|
|
600
295
|
value: e
|
|
601
|
-
})),
|
|
296
|
+
})), A.catch((e) => A.succeed({
|
|
602
297
|
ok: !1,
|
|
603
298
|
cause: e
|
|
604
299
|
}))));
|
|
605
|
-
if (!t.ok) return
|
|
606
|
-
|
|
300
|
+
if (!t.ok) return q(s, f, 400, "InvalidRequest", "Invalid request", { detail: String(t.cause) }, { ...m });
|
|
301
|
+
v = t.value;
|
|
607
302
|
}
|
|
608
|
-
let
|
|
303
|
+
let y;
|
|
609
304
|
try {
|
|
610
|
-
|
|
611
|
-
} catch (
|
|
612
|
-
if (
|
|
613
|
-
let
|
|
614
|
-
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 });
|
|
615
310
|
}
|
|
616
|
-
throw
|
|
311
|
+
throw t;
|
|
617
312
|
}
|
|
313
|
+
if (s.credentials === "bearer" && y.type === "anonymous") return q(s, f, 401, "Unauthorized", y.credentialRejected ?? "Authentication required", {}, { ...m });
|
|
618
314
|
let b;
|
|
619
315
|
try {
|
|
620
|
-
b =
|
|
316
|
+
b = c.buildContext ? await c.buildContext(y, f.headers) : void 0;
|
|
621
317
|
} catch (e) {
|
|
622
|
-
return
|
|
318
|
+
return I(s, $(e, y, s, m, f));
|
|
623
319
|
}
|
|
624
|
-
let
|
|
625
|
-
subject:
|
|
626
|
-
headers:
|
|
627
|
-
store:
|
|
628
|
-
method:
|
|
629
|
-
path:
|
|
630
|
-
query:
|
|
631
|
-
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,
|
|
632
328
|
...b === void 0 ? {} : { app: b },
|
|
633
|
-
...
|
|
329
|
+
...f.remoteAddr === void 0 ? {} : { remoteAddr: f.remoteAddr }
|
|
634
330
|
};
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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);
|
|
638
345
|
}
|
|
639
|
-
let
|
|
640
|
-
if (
|
|
641
|
-
let e = await
|
|
642
|
-
if (e.kind === "replay") return
|
|
643
|
-
...
|
|
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,
|
|
644
351
|
"Idempotency-Replayed": "true"
|
|
645
352
|
});
|
|
646
|
-
if (e.kind === "conflict") return
|
|
647
|
-
|
|
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);
|
|
648
355
|
}
|
|
649
356
|
try {
|
|
650
|
-
let e = await
|
|
651
|
-
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) ? {
|
|
652
359
|
status: e.status ?? 200,
|
|
653
360
|
headers: {
|
|
654
|
-
...
|
|
361
|
+
...m,
|
|
655
362
|
...e.headers
|
|
656
363
|
},
|
|
657
364
|
byteStream: e.byteStream,
|
|
658
365
|
...e.contentType === void 0 ? {} : { contentType: e.contentType }
|
|
659
366
|
} : {
|
|
660
367
|
status: 200,
|
|
661
|
-
headers:
|
|
368
|
+
headers: m,
|
|
662
369
|
stream: e.stream
|
|
663
370
|
};
|
|
664
|
-
let t =
|
|
665
|
-
...
|
|
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,
|
|
666
373
|
...t.headers,
|
|
667
|
-
...
|
|
374
|
+
...a
|
|
668
375
|
};
|
|
669
|
-
if (
|
|
376
|
+
if (C && w && await i(C.store, T, w, {
|
|
670
377
|
status: t.status,
|
|
671
|
-
body:
|
|
672
|
-
}, Date.now()),
|
|
673
|
-
let e = `W/"${await
|
|
674
|
-
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) ? {
|
|
675
382
|
status: 304,
|
|
676
383
|
headers: {
|
|
677
|
-
...
|
|
678
|
-
...
|
|
384
|
+
...m,
|
|
385
|
+
...a,
|
|
679
386
|
ETag: e
|
|
680
387
|
}
|
|
681
|
-
} :
|
|
682
|
-
...
|
|
388
|
+
} : I(s, K(t.status, n, {
|
|
389
|
+
...o,
|
|
683
390
|
ETag: e
|
|
684
391
|
}, t.contentType));
|
|
685
392
|
}
|
|
686
|
-
return t.status === 204 || t.status === 304 ?
|
|
393
|
+
return t.status === 204 || t.status === 304 ? I(s, {
|
|
687
394
|
status: t.status,
|
|
688
|
-
headers:
|
|
689
|
-
}) :
|
|
395
|
+
headers: o
|
|
396
|
+
}) : I(s, K(t.status, n, o, t.contentType));
|
|
690
397
|
} catch (e) {
|
|
691
|
-
return
|
|
398
|
+
return C && w && await r(C.store, T, w), I(s, $(e, y, s, m, f));
|
|
692
399
|
} finally {
|
|
693
|
-
|
|
400
|
+
E?.();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
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);
|
|
694
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
|
+
});
|
|
695
434
|
}
|
|
696
435
|
};
|
|
697
|
-
},
|
|
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
|
+
}
|
|
698
441
|
if (t.idempotency !== void 0) {
|
|
699
|
-
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.`);
|
|
700
443
|
}
|
|
701
444
|
let n = (e) => e.split("/").map((e) => e.startsWith(":") ? ":" : e).join("/"), r = /* @__PURE__ */ new Map();
|
|
702
445
|
for (let t of e) {
|
|
703
446
|
let e = r.get(n(t.path)) ?? [];
|
|
704
447
|
e.includes(t.method) || e.push(t.method), r.set(n(t.path), e);
|
|
705
448
|
}
|
|
706
|
-
return e.map((e) =>
|
|
707
|
-
},
|
|
449
|
+
return e.map((e) => me(e, t, r.get(n(e.path)).join(", ")));
|
|
450
|
+
}, ge = async (e, t) => {
|
|
708
451
|
let n = await e[0].handle(t);
|
|
709
452
|
for (let r = 1; r < e.length && n.status === 405; r++) n = await e[r].handle(t);
|
|
710
453
|
return n;
|
|
711
454
|
};
|
|
712
455
|
//#endregion
|
|
713
|
-
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 };
|