@voltro/protocol 0.85.0 → 0.87.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 (80) hide show
  1. package/CHANGELOG.md +5987 -0
  2. package/README.md +14 -0
  3. package/THIRD-PARTY-NOTICES.md +1122 -31
  4. package/dist/apiRoleEndpoints.js +108 -0
  5. package/dist/apiRoleObservation.js +68 -0
  6. package/dist/apikey.d.ts +10 -0
  7. package/dist/approval.js +64 -0
  8. package/dist/approvalDescriptors.js +26 -0
  9. package/dist/auth.js +389 -0
  10. package/dist/boundedRing.js +27 -0
  11. package/dist/businessRule.js +11 -0
  12. package/dist/canonicalJson.js +14 -0
  13. package/dist/connection.js +73 -0
  14. package/dist/devActivity.js +4 -0
  15. package/dist/errorSchema.js +24 -0
  16. package/dist/errorValue.js +21 -0
  17. package/dist/event.js +110 -0
  18. package/dist/formCapture.js +12 -0
  19. package/dist/httpStreamMaxDuration.js +9 -0
  20. package/dist/idempotency.js +121 -0
  21. package/dist/idempotencyInput.js +123 -0
  22. package/dist/identity.js +5 -9
  23. package/dist/index.d.ts +1095 -139
  24. package/dist/index.js +54 -1700
  25. package/dist/inspect.d.ts +1 -1
  26. package/dist/inspect.js +14 -240
  27. package/dist/inspectBackfill.js +52 -0
  28. package/dist/inspectCommandRejection.js +21 -0
  29. package/dist/inspectProjection.js +133 -0
  30. package/dist/inspectStorageProjection.js +86 -0
  31. package/dist/inspectValueIdentity.js +4 -0
  32. package/dist/inspectWorkflowExecution.js +34 -0
  33. package/dist/inspectWorkflowQueuedStart.js +31 -0
  34. package/dist/jsonSchema.js +54 -0
  35. package/dist/jwt.d.ts +10 -0
  36. package/dist/jwt.js +1 -1
  37. package/dist/outbox.js +10 -0
  38. package/dist/pairing.js +75 -0
  39. package/dist/plugin.js +87 -0
  40. package/dist/pluginAccountMerge.js +88 -0
  41. package/dist/pluginNaming.js +32 -0
  42. package/dist/pluginPrivacy.js +166 -0
  43. package/dist/procedure.js +280 -0
  44. package/dist/publicApi.js +325 -0
  45. package/dist/queryOptionalSources.js +14 -0
  46. package/dist/reactivityChannel.js +34 -0
  47. package/dist/rest.d.ts +260 -64
  48. package/dist/rest.js +345 -499
  49. package/dist/restFormat.js +163 -0
  50. package/dist/restReceipt.js +43 -0
  51. package/dist/revalidate.js +13 -0
  52. package/dist/rowEquality.js +31 -0
  53. package/dist/rowPatch.js +182 -0
  54. package/dist/schemaShape.js +67 -0
  55. package/dist/scopes.js +273 -0
  56. package/dist/secretWindows.js +71 -0
  57. package/dist/serverErrorBus.js +15 -0
  58. package/dist/serviceCall.js +14 -0
  59. package/dist/session.d.ts +89 -6
  60. package/dist/session.js +62 -63
  61. package/dist/{sessionHeader-DriTZhmv.js → sessionHeader.js} +1 -1
  62. package/dist/ssrfPolicy.js +30 -0
  63. package/dist/storageAccess.js +14 -0
  64. package/dist/storeErrors.js +66 -0
  65. package/dist/storeScreenshots.js +90 -0
  66. package/dist/strictInput.js +27 -0
  67. package/dist/subscriptionEvent.js +37 -0
  68. package/dist/tenantSelection.js +40 -0
  69. package/dist/time.js +7 -0
  70. package/dist/undo.js +38 -0
  71. package/dist/validation.js +39 -0
  72. package/dist/webSocketGateway.js +16 -0
  73. package/dist/workflow.js +297 -0
  74. package/dist/workflowAccess.js +61 -0
  75. package/dist/workflowRestart.js +45 -0
  76. package/dist/workflowRetry.js +44 -0
  77. package/dist/workflowStartOutcome.js +30 -0
  78. package/package.json +5 -3
  79. package/dist/restFormat-BlgTLxm1.js +0 -298
  80. package/dist/scopes-ClywBij8.js +0 -548
@@ -1,548 +0,0 @@
1
- import { Context as e, Effect as t, Schema as n, Struct as r } from "effect";
2
- import { RpcMiddleware as i } from "effect/rpc";
3
- //#region src/tenantSelection.ts
4
- var a = (e) => e.type === "user" || e.type === "apiKey" || e.type === "serviceAccount", o = class extends n.TaggedError()("TenantSelectionRefused", {
5
- subjectType: n.String,
6
- subjectId: n.NullOr(n.String),
7
- tenantId: n.String,
8
- reason: n.Literals(["not-a-member", "subject-has-no-tenant"])
9
- }) {}, s = (e, t, n) => {
10
- if (!a(e)) throw new o({
11
- subjectType: e.type,
12
- subjectId: e.id,
13
- tenantId: t,
14
- reason: "subject-has-no-tenant"
15
- });
16
- if (!n.some((e) => e.tenantId === t)) throw new o({
17
- subjectType: e.type,
18
- subjectId: e.id,
19
- tenantId: t,
20
- reason: "not-a-member"
21
- });
22
- return {
23
- ...e,
24
- tenantId: t,
25
- metadata: {
26
- ...e.metadata,
27
- memberships: n.map((e) => e.role === void 0 ? { tenantId: e.tenantId } : {
28
- tenantId: e.tenantId,
29
- role: e.role
30
- })
31
- }
32
- };
33
- }, c = n.Record(n.String, n.Unknown), l = n.optional(n.Array(n.String)), u = n.Struct({
34
- type: n.Literal("user"),
35
- id: n.String,
36
- tenantId: n.String,
37
- scopes: l,
38
- metadata: n.optional(c)
39
- }), d = n.Struct({
40
- type: n.Literal("apiKey"),
41
- id: n.String,
42
- tenantId: n.String,
43
- scopes: l,
44
- metadata: n.optional(c)
45
- }), f = n.Struct({
46
- type: n.Literal("serviceAccount"),
47
- id: n.String,
48
- tenantId: n.String,
49
- auditActorId: n.optionalKey(n.NullOr(n.String)),
50
- scopes: l,
51
- metadata: n.optional(c)
52
- }), p = n.Struct({
53
- type: n.Literal("anonymous"),
54
- id: n.Null,
55
- tenantId: n.NullOr(n.String),
56
- credentialRejected: n.optional(n.String)
57
- }), m = n.Struct({
58
- type: n.Literal("system"),
59
- id: n.String,
60
- tenantId: n.Null,
61
- scopes: l,
62
- metadata: n.optional(c)
63
- }), h = n.Struct({
64
- type: n.Literal("service"),
65
- id: n.String,
66
- service: n.String,
67
- tenantId: n.Null,
68
- scopes: l,
69
- metadata: n.optional(c)
70
- }), ee = n.Union([
71
- u,
72
- d,
73
- f,
74
- p,
75
- m,
76
- h
77
- ]), te = n.Union([
78
- u.mapFields(r.omit(["scopes"])),
79
- d.mapFields(r.omit(["scopes"])),
80
- f.mapFields(r.omit(["scopes"])),
81
- p,
82
- m.mapFields(r.omit(["scopes"])),
83
- h.mapFields(r.omit(["scopes"]))
84
- ]), ne = (e) => {
85
- if (e.type === "anonymous") return e;
86
- let { scopes: t, ...n } = e;
87
- return n;
88
- }, g = (e) => e.scopes ?? [], _ = (e, t) => ({
89
- type: "anonymous",
90
- id: null,
91
- tenantId: e,
92
- ...t === void 0 ? {} : { credentialRejected: t }
93
- }), re = (e, t = ["admin:full"]) => ({
94
- type: "system",
95
- id: e,
96
- tenantId: null,
97
- scopes: t
98
- }), ie = (e) => ({
99
- type: "service",
100
- id: `service:${e}`,
101
- service: e,
102
- tenantId: null,
103
- scopes: []
104
- }), ae = (e) => e.type === "service", oe = (e) => e.type === "system" || e.type === "service", v = (e) => {
105
- if (e.type === "system") return null;
106
- if (e.type === "serviceAccount" && e.auditActorId !== void 0) return e.auditActorId;
107
- if (e.type !== "apiKey") return e.id;
108
- let t = e.metadata?.userId;
109
- return typeof t == "string" && t !== "" ? t : e.id;
110
- }, se = (e, t) => {
111
- let n = e;
112
- return {
113
- type: "serviceAccount",
114
- id: e.id ?? "system",
115
- tenantId: t,
116
- auditActorId: v(e),
117
- scopes: g(e),
118
- ...n.metadata === void 0 ? {} : { metadata: n.metadata }
119
- };
120
- }, ce = (e) => e.type === "system", le = "impersonation", ue = (e) => e.metadata?.impersonation ?? null, de = class extends e.Service()("@voltro/Subject") {}, fe = class extends e.Service()("@voltro/ConnectionInfo") {}, y = class extends n.TaggedError()("Unauthenticated", { reason: n.optional(n.String) }) {
121
- get message() {
122
- return this.reason ?? "Unauthenticated";
123
- }
124
- }, pe = class extends i.Service()("@voltro/AuthMiddleware", { error: y }) {}, me = class extends i.Service()("@voltro/ConnectionInfoMiddleware") {}, he = (e) => typeof e.mountRoutes == "function", ge = (e) => Array.isArray(e) ? {
125
- kind: "grant",
126
- scopes: e
127
- } : e, b = (e, t) => {
128
- if (t.kind === "vetoed") throw new y({ reason: `${t.code}: ${t.message}` });
129
- if (e.type === "anonymous") return {
130
- subject: e,
131
- removed: []
132
- };
133
- let n = g(e);
134
- if (t.kind === "grant") {
135
- if (t.scopes.length === 0) return {
136
- subject: e,
137
- removed: []
138
- };
139
- let r = [.../* @__PURE__ */ new Set([...n, ...t.scopes])];
140
- return {
141
- subject: {
142
- ...e,
143
- scopes: r
144
- },
145
- removed: []
146
- };
147
- }
148
- let r = new Set(t.scopes), i = n.filter((e) => !r.has(e));
149
- return {
150
- subject: {
151
- ...e,
152
- scopes: [...r]
153
- },
154
- removed: i
155
- };
156
- }, _e = 3e4, ve = 1e4, x = (e) => `${e.type}\u0000${e.tenantId ?? ""}\u0000${e.id ?? ""}`, ye = () => {
157
- if (typeof process > "u") return;
158
- let e = process.env.VOLTRO_AUTH_SCOPE_CACHE_TTL_MS;
159
- if (e === void 0 || e === "") return;
160
- let t = Number(e);
161
- return Number.isFinite(t) && t >= 0 ? t : void 0;
162
- }, S = (e = {}) => {
163
- let t = e.ttlMs ?? ye() ?? 3e4, n = e.maxEntries ?? 1e4, r = e.now ?? Date.now, i = /* @__PURE__ */ new Map(), a = () => {
164
- if (i.size <= n) return;
165
- let e = r();
166
- for (let [t, n] of i) n.freshUntil <= e && i.delete(t);
167
- for (let e of i.keys()) {
168
- if (i.size <= n) break;
169
- i.delete(e);
170
- }
171
- };
172
- return {
173
- ttlMs: t,
174
- invalidate: (e) => {
175
- i.delete(e);
176
- },
177
- invalidateAll: () => {
178
- i.clear();
179
- },
180
- resolve: async (e, n) => {
181
- let o = r();
182
- if (t > 0) {
183
- let t = i.get(e);
184
- if (t && t.freshUntil > o) return {
185
- decision: t.decision,
186
- fresh: !1
187
- };
188
- }
189
- let s = await n();
190
- return t > 0 && s.kind !== "unavailable" && (i.set(e, {
191
- decision: s,
192
- freshUntil: o + t
193
- }), a()), {
194
- decision: s,
195
- fresh: !0
196
- };
197
- }
198
- };
199
- }, be = (e) => typeof e.resolve == "function", xe = (e) => {
200
- let t = e.authorization ?? e.Authorization;
201
- if (t !== void 0) return /^Bearer\s+(.+)$/i.exec(t.trim())?.[1]?.trim();
202
- }, Se = async (e, t, n, r) => {
203
- if (!a(e)) return e;
204
- let i = {
205
- type: e.type,
206
- id: e.id
207
- }, c;
208
- try {
209
- c = await n.store.read(i);
210
- } catch (e) {
211
- throw r(`tenant selection unavailable: ${e instanceof Error ? e.message : String(e)}`);
212
- }
213
- if (c === null || c === e.tenantId) return e;
214
- let l;
215
- try {
216
- l = await n.memberships(e, t);
217
- } catch (e) {
218
- throw r(`memberships unavailable: ${e instanceof Error ? e.message : String(e)}`);
219
- }
220
- try {
221
- return s(e, c, l);
222
- } catch (t) {
223
- if (!(t instanceof o)) throw t;
224
- try {
225
- await n.store.clear(i);
226
- } catch (e) {
227
- throw r(`tenant selection unavailable: ${e instanceof Error ? e.message : String(e)}`);
228
- }
229
- return e;
230
- }
231
- }, C = (e, t) => {
232
- let n = xe(t);
233
- if (n === void 0) return e;
234
- let r = e.filter((e) => e.claimsBearerPrefix !== void 0 && e.claimsBearerPrefix !== "" && n.startsWith(e.claimsBearerPrefix));
235
- if (r.length === 0) return e;
236
- let i = new Set(r);
237
- return [...r, ...e.filter((e) => !i.has(e))];
238
- }, Ce = (e, t) => {
239
- if (e === "refuse") throw new y({ reason: "anonymous callers are refused" });
240
- if (e === "no-tenant") return "";
241
- if (e === "header") {
242
- if (t === void 0 || t === "") throw new y({ reason: "tenant required (x-tenant header missing)" });
243
- return t;
244
- }
245
- return "tenantId" in e ? e.tenantId : t !== void 0 && t !== "" ? t : e.headerOrTenant;
246
- }, w = (e, t) => {
247
- let n = t?.resolveScopes, r = t?.subjectGuards ?? [];
248
- if (t?.memberships === void 0 != (t?.tenantSelection === void 0)) throw Error("composeAuthStrategies: `memberships` and `tenantSelection` come together — a tenant selection is verified against the memberships and read from the store; configure both or neither.");
249
- let i = t?.memberships !== void 0 && t.tenantSelection !== void 0 ? {
250
- memberships: t.memberships,
251
- store: t.tenantSelection
252
- } : void 0, a = n !== void 0 || r.length > 0, o = !a || t?.scopeCache === !1 ? null : t?.scopeCache !== void 0 && be(t.scopeCache) ? t.scopeCache : S(t?.scopeCache ?? {});
253
- return async (s) => {
254
- let c = t?.getStore?.(), l = c === void 0 ? s : {
255
- ...s,
256
- store: c
257
- }, u;
258
- for (let s of C(e, l.headers)) {
259
- let e = await s.resolve(l);
260
- if (e.kind === "matched") {
261
- if (e.subject.type === "service") return { subject: {
262
- ...e.subject,
263
- scopes: []
264
- } };
265
- let c = i === void 0 ? e.subject : await Se(e.subject, l, i, (e) => (t?.onStrategyFailed?.({
266
- strategyId: s.id,
267
- reason: e
268
- }), new y({ reason: e }))), u = c;
269
- if (a) {
270
- let e = async () => {
271
- let e = n === void 0 ? {
272
- kind: "grant",
273
- scopes: []
274
- } : ge(await n(c, l));
275
- if (e.kind === "unavailable" || r.length === 0) return e;
276
- let t = b(c, e).subject, i = {
277
- origin: "request",
278
- headers: l.headers,
279
- clientId: l.clientId,
280
- store: l.store
281
- };
282
- for (let e of r) {
283
- let n = await e(t, i);
284
- if (!n.ok) return {
285
- kind: "vetoed",
286
- code: n.code,
287
- message: n.message
288
- };
289
- }
290
- return e;
291
- }, { decision: i, fresh: a } = o === null ? {
292
- decision: await e(),
293
- fresh: !0
294
- } : await o.resolve(x(c), e);
295
- if (i.kind === "vetoed") {
296
- let e = `${i.code}: ${i.message}`;
297
- throw t?.onStrategyFailed?.({
298
- strategyId: s.id,
299
- reason: e
300
- }), new y({ reason: e });
301
- }
302
- if (i.kind === "unavailable") {
303
- let e = `scope resolution unavailable: ${i.reason}`;
304
- throw t?.onStrategyFailed?.({
305
- strategyId: s.id,
306
- reason: e
307
- }), new y({ reason: e });
308
- }
309
- let d = b(c, i);
310
- a && d.removed.length > 0 && t?.onScopesNarrowed?.({
311
- strategyId: s.id,
312
- subjectType: c.type,
313
- subjectId: c.id,
314
- removed: d.removed,
315
- granted: i.scopes
316
- }), u = d.subject;
317
- }
318
- return e.credentialExpiresAt === void 0 ? { subject: u } : {
319
- subject: u,
320
- credentialExpiresAt: e.credentialExpiresAt
321
- };
322
- }
323
- if (e.kind === "failed") {
324
- t?.onStrategyFailed?.({
325
- strategyId: s.id,
326
- reason: e.reason
327
- }), u = e.reason;
328
- break;
329
- }
330
- }
331
- if (t?.fallback) {
332
- let e = await t.fallback(l);
333
- return { subject: u !== void 0 && e.type === "anonymous" ? {
334
- ...e,
335
- credentialRejected: u
336
- } : e };
337
- }
338
- if (u !== void 0) throw new y({ reason: `credential rejected: ${u}` });
339
- return { subject: _(Ce(t?.anonymous ?? "no-tenant", l.headers["x-tenant"])) };
340
- };
341
- }, T = (e, t) => {
342
- if (e.type === "anonymous") throw new y(t === void 0 ? {} : { reason: t });
343
- }, E = "admin:full", D = "apikeys:issue:self", O = "apikeys:issue:org", k = "apikeys:issue:other", A = "devices:manage", j = class extends n.TaggedError()("ScopeError", {
344
- required: n.String,
345
- message: n.String
346
- }) {}, M = class extends n.TaggedError()("NoSuchResource", {
347
- resourceType: n.NullOr(n.String),
348
- resourceId: n.String,
349
- message: n.String
350
- }) {}, N = (e) => "scopes" in e && e.scopes ? e.scopes : [], P = /* @__PURE__ */ new WeakMap(), we = (e, t) => {
351
- typeof e == "object" && e && P.set(e, t);
352
- }, F = (e) => {
353
- if (typeof e == "object" && e) {
354
- let t = P.get(e);
355
- if (t) return t;
356
- }
357
- return N(e);
358
- }, I = (e, t) => {
359
- let n = F(e);
360
- return n.includes("admin:full") || n.includes(t);
361
- }, Te = (e, t) => {
362
- let n = N(e);
363
- return n.includes("admin:full") || n.includes(t);
364
- }, Ee = (e, n) => I(e, n) ? t.void : t.fail(new j({
365
- required: n,
366
- message: `missing required scope '${n}'`
367
- })), L = (e, t) => {
368
- let n;
369
- try {
370
- n = typeof e.action == "function" ? e.action(t) : e.action;
371
- } catch {
372
- throw new j({
373
- required: e.resourceType,
374
- message: "policy action selector failed"
375
- });
376
- }
377
- if (typeof n != "string" || n.trim() === "") throw new j({
378
- required: e.resourceType,
379
- message: "policy action selector returned no action"
380
- });
381
- return n;
382
- }, R = (e) => (typeof e.action == "string" || typeof e.action == "function") && typeof e.resourceType == "string", De = (e) => e !== void 0 && e.some((e) => R(e) || typeof e.resource == "function"), z = (e) => typeof e.open == "string", B = (e) => Array.isArray(e.service), Oe = (e) => ({ service: [...e] }), V = (e) => e?.find(B)?.service, H = (e, t) => {
383
- let n = V(t);
384
- if (e.type === "service") return n !== void 0 && n.includes(e.service) ? null : new j({
385
- required: "service-procedure",
386
- message: n === void 0 ? `service '${e.service}' may only call procedures that declare it in \`service: { callers }\`` : `service '${e.service}' is not among this procedure's callers [${n.join(", ")}]`
387
- });
388
- if (n !== void 0) return Y(e, new j({
389
- required: `service:${n.join("|")}`,
390
- message: `this procedure is callable only by the service${n.length === 1 ? "" : "s"} [${n.join(", ")}]`
391
- }));
392
- }, U = (e) => e.authenticated === !0, ke = (e) => ({ open: e }), W = (e) => typeof e == "string" ? [e] : e, G, Ae = (e) => {
393
- G = e;
394
- }, je = (e) => G === void 0 ? e.filter((e) => (e.guards ?? []).some((e) => !R(e) && e.resource !== void 0)).map((e) => e.tag) : [], Me = (e) => [
395
- `${e.length} procedure${e.length === 1 ? "" : "s"} declare a per-resource guard that nothing enforces:`,
396
- ...e.slice(0, 10).map((e) => ` ${e}`),
397
- ...e.length > 10 ? [` … and ${e.length - 10} more`] : [],
398
- "",
399
- " `guards: [{ scope, resource }]` reads as \"may you do this to THIS resource\",",
400
- " but with no resource-scope resolver registered the extractor is advisory and",
401
- " the check runs against the caller's GLOBAL scopes. For an app whose",
402
- " authorization is per-resource, that guard passes callers it should refuse.",
403
- "",
404
- " Fix it one of two ways:",
405
- " • setResourceScopeResolver((req) => Effect<boolean>) — answers \"does this",
406
- " subject hold `req.scope` on `req.resource`\" from your own tables.",
407
- " • Drop the `resource` extractor if a global scope check is what you meant."
408
- ].join("\n"), Ne = () => G, K, q = (e) => {
409
- K = e;
410
- }, Pe = () => K, J = (e) => new j({
411
- required: "access-decision",
412
- message: `${e ?? "this procedure"} declares no access decision: it has neither \`guards:\` nor \`openAccess:\`, and the app runs with \`security.defaultDeny\`. Add the scope(s) a caller must hold (\`guards: [{ scope: '…' }]\`), or declare it open on purpose with \`openAccess: '<why anyone may call this>'\`.`
413
- }), Y = (e, t) => {
414
- let n = e.credentialRejected;
415
- return n === void 0 ? t : new y({ reason: `${n} — the request carried a credential and it was REJECTED, so this caller resolved to anonymous. The guard then refused (${t.message}); the scope is not the problem. Re-authenticate and retry.` });
416
- }, X = (e) => {
417
- let t = Array.isArray(e), n = Object.getPrototypeOf(e);
418
- if (t ? n !== Array.prototype : n !== Object.prototype && n !== null) return !1;
419
- for (let n of Reflect.ownKeys(e)) if (t && (typeof n != "string" || n !== "length" && !/^(0|[1-9][0-9]*)$/.test(n)) || !("value" in Object.getOwnPropertyDescriptor(e, n))) return !1;
420
- return !0;
421
- }, Z = (e, t) => {
422
- let n, r = 0, i, a = 0, o;
423
- return (s) => {
424
- let c = F(e);
425
- return (c !== n || c.length !== r) && (n = c, r = c.length, i = void 0, a = 0, o = void 0), i === void 0 && c.length >= 32 && ++a > 1 && (o ??= X(c) && X(e) && X(t) && t.every((e) => X(e) && (!("scope" in e) || typeof e.scope == "string" || X(e.scope))), o && (i = new Set(c))), i === void 0 ? c.includes("admin:full") || c.includes(s) : i.has("admin:full") || i.has(s);
426
- };
427
- }, Q = (e, t, n) => {
428
- let r = H(e, t);
429
- if (r !== void 0) return r;
430
- if (!t || t.length === 0) return n?.defaultDeny === !0 ? J(n.procedure) : null;
431
- let i = 0, a;
432
- for (let n of t) {
433
- if (z(n) || B(n)) continue;
434
- if (U(n)) {
435
- if (e.id !== null && e.id !== void 0) continue;
436
- return Y(e, new j({
437
- required: "authenticated",
438
- message: "this procedure requires an authenticated caller"
439
- }));
440
- }
441
- if (R(n)) {
442
- if (i++, a === void 0 && (t.length >= 512 || i >= 512) && (a = Z(e, t)), a === void 0 ? I(e, "admin:full") : a("admin:full")) continue;
443
- return Y(e, new j({
444
- required: `${n.resourceType}:${n.action}`,
445
- message: `relationship guard '${n.action}' on '${n.resourceType}' cannot be checked synchronously`
446
- }));
447
- }
448
- let r = W(n.scope);
449
- if (r.length === 0) continue;
450
- i += r.length, a === void 0 && (t.length >= 512 || i >= 512) && (a = Z(e, t));
451
- let o = n.mode ?? "all", s;
452
- if (o === "any") {
453
- if (a === void 0 ? r.some((t) => I(e, t)) : r.some(a)) continue;
454
- s = r[0];
455
- } else {
456
- let t = a === void 0 ? r.find((t) => !I(e, t)) : r.find((e) => !a(e));
457
- if (t === void 0) continue;
458
- s = t;
459
- }
460
- return Y(e, new j({
461
- required: s,
462
- message: o === "any" ? `missing all of required scopes [${r.join(", ")}]` : `missing required scope '${s}'`
463
- }));
464
- }
465
- return null;
466
- }, Fe = (e, n, r) => {
467
- let i;
468
- try {
469
- i = L(n, r);
470
- } catch (e) {
471
- return t.succeed(e);
472
- }
473
- let a = (e) => new j({
474
- required: `${n.resourceType}:${i}`,
475
- message: e
476
- });
477
- if (I(e, "admin:full")) return t.succeed(null);
478
- let o = K;
479
- if (o === void 0) return t.succeed(a(`no policy resolver registered — cannot authorize '${i}' on '${n.resourceType}'`));
480
- let s = n.resource(r);
481
- return s === void 0 || s === "" ? t.succeed(a(`input does not identify a '${n.resourceType}' to authorize`)) : t.suspend(() => o({
482
- subject: e,
483
- action: i,
484
- resourceType: n.resourceType,
485
- resourceId: s
486
- })).pipe(t.catchCause(() => t.succeed(!1)), t.map((t) => $(e, t, n.resourceType, s, () => a(`no '${i}' relation on ${n.resourceType}:${s}`))));
487
- }, $ = (e, t, n, r, i) => t === !0 ? null : t === "missing" && e.id !== null && e.id !== void 0 ? new M({
488
- resourceType: n,
489
- resourceId: r,
490
- message: n === null ? `no such resource '${r}'` : `no such ${n} '${r}'`
491
- }) : i(), Ie = (e, n, r, i) => {
492
- let a = H(e, n);
493
- if (a !== void 0) return t.succeed(a);
494
- if (!n || n.length === 0) return t.succeed(Q(e, n, i));
495
- let o = G;
496
- return !n.some(R) && (!o || !n.some((e) => e.resource !== void 0)) ? t.succeed(Q(e, n, i)) : t.gen(function* () {
497
- for (let i of n) {
498
- if (z(i) || B(i)) continue;
499
- if (U(i)) {
500
- if (e.id !== null && e.id !== void 0) continue;
501
- return Y(e, new j({
502
- required: "authenticated",
503
- message: "this procedure requires an authenticated caller"
504
- }));
505
- }
506
- if (R(i)) {
507
- let t = yield* Fe(e, i, r);
508
- if (t) return t;
509
- continue;
510
- }
511
- let n = W(i.scope);
512
- if (n.length === 0) continue;
513
- let a = i.resource ? i.resource(r) : void 0, s = [], c = !1;
514
- for (let r of n) {
515
- if (I(e, r)) {
516
- s.push(!0);
517
- continue;
518
- }
519
- if (a !== void 0 && o !== void 0) {
520
- let n = yield* t.suspend(() => o({
521
- subject: e,
522
- scope: r,
523
- resource: a
524
- })).pipe(t.catchCause(() => t.succeed(!1)));
525
- n === "missing" && (c = !0), s.push(n === !0);
526
- } else s.push(!1);
527
- }
528
- let l = i.mode ?? "all";
529
- if (!(l === "any" ? s.some(Boolean) : s.every(Boolean))) {
530
- let t = l === "any" ? n[0] : n[n.findIndex((e, t) => !s[t])];
531
- if (c && a !== void 0) {
532
- let n = $(e, "missing", null, a, () => new j({
533
- required: t,
534
- message: `missing required scope '${t}' on resource '${a}'`
535
- }));
536
- if (n !== null) return n;
537
- }
538
- return new j({
539
- required: t,
540
- message: l === "any" ? `missing all of required scopes [${n.join(", ")}]` : `missing required scope '${t}'` + (a === void 0 ? "" : ` on resource '${a}'`)
541
- });
542
- }
543
- }
544
- return null;
545
- });
546
- };
547
- //#endregion
548
- export { x as $, Ae as A, de as B, ke as C, V as D, Oe as E, ve as F, w as G, _ as H, _e as I, ae as J, he as K, le as L, pe as M, fe as N, we as O, me as P, ue as Q, ee as R, J as S, L as T, b as U, y as V, T as W, S as X, ce as Y, C as Z, Te as _, A as a, o as at, R as b, Me as c, De as d, ie as et, F as f, I as g, Ne as h, D as i, se as it, N as j, q as k, Q as l, Pe as m, O as n, ne as nt, M as o, a as ot, je as p, oe as q, k as r, re as rt, j as s, s as st, E as t, v as tt, Ie as u, U as v, Ee as w, B as x, z as y, te as z };