@voltro/protocol 0.84.0 → 0.86.0

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