permdock 0.0.0 → 0.1.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/README.md +268 -1
- package/dist/a2a/index.d.ts +178 -0
- package/dist/a2a/index.js +271 -0
- package/dist/ai-sdk/index.d.ts +74 -0
- package/dist/ai-sdk/index.js +137 -0
- package/dist/approval-required-TzNB9oQA.js +6 -0
- package/dist/approvals/index.d.ts +3 -0
- package/dist/approvals/index.js +4 -0
- package/dist/approvals-DaxY-Bdg.js +218 -0
- package/dist/approvers-aH0PJkmf.js +20 -0
- package/dist/arazzo-CTeVuXr5.js +70 -0
- package/dist/arazzo-aoTkqYsJ.js +54 -0
- package/dist/authzen/index.d.ts +48 -0
- package/dist/authzen/index.js +336 -0
- package/dist/better-auth/index.d.ts +92 -0
- package/dist/better-auth/index.js +324 -0
- package/dist/budget-JqcRqyhK.d.ts +11 -0
- package/dist/budget-NbEtbJC_.js +11 -0
- package/dist/capability-B68OFnZx.js +171 -0
- package/dist/capability-BDG_nkxt.d.ts +99 -0
- package/dist/catalog/index.d.ts +12 -0
- package/dist/catalog/index.js +2 -0
- package/dist/catalog-B0E6bggc.js +48 -0
- package/dist/catalog-H-vFGwWK.js +55 -0
- package/dist/catalog-doc-BSo_Q_-6.js +298 -0
- package/dist/catalog-idsHc0vo.js +2 -0
- package/dist/catalog-path-CnI0XTFK.js +12 -0
- package/dist/claude-agent/index.d.ts +81 -0
- package/dist/claude-agent/index.js +83 -0
- package/dist/clerk/index.d.ts +56 -0
- package/dist/clerk/index.js +280 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +20 -0
- package/dist/cli/index.d.ts +46 -0
- package/dist/cli/index.js +5 -0
- package/dist/cloud/index.d.ts +91 -0
- package/dist/cloud/index.js +390 -0
- package/dist/cloud-BNQTrmrr.js +50 -0
- package/dist/cloud-Cuxr6Czw.js +117 -0
- package/dist/collect-B7_TIfmg.js +49 -0
- package/dist/collect-O-tOtbnk.js +350 -0
- package/dist/collect-fRPAQIWb.js +2 -0
- package/dist/commands-BMh_Etm2.js +93 -0
- package/dist/compact-y6vfu2_f.js +19 -0
- package/dist/compare-pfyVnBjE.js +12 -0
- package/dist/compile-CQbvyIBr.d.ts +30 -0
- package/dist/compile-D22iwvuV.js +558 -0
- package/dist/config-BPYmjTOp.js +26 -0
- package/dist/connection-JvqwHODC.js +194 -0
- package/dist/context-CKEAabd7.js +73 -0
- package/dist/context-gtAwAILx.js +6 -0
- package/dist/convex/index.d.ts +40 -0
- package/dist/convex/index.js +55 -0
- package/dist/create-BKF3dgFk.d.ts +162 -0
- package/dist/create-CSkhDU9T.js +222 -0
- package/dist/credential-B_rkUNlY.js +326 -0
- package/dist/credentials-BgRX3WEg.js +268 -0
- package/dist/describe-Bt1YD5uS.js +99 -0
- package/dist/describe-DernyItf.d.ts +37 -0
- package/dist/diff-BUzf5Poi.js +48 -0
- package/dist/diff-x5Il8LVa.js +418 -0
- package/dist/digest-B3kc_PgQ.d.ts +19 -0
- package/dist/digest-BI-6aa6d.js +27 -0
- package/dist/doctor-BGle8Gqi.js +1314 -0
- package/dist/doctor-Bqo6FwUa.js +53 -0
- package/dist/drizzle/index.d.ts +72 -0
- package/dist/drizzle/index.js +160 -0
- package/dist/duration-xK2jGFVc.js +25 -0
- package/dist/elysia/index.d.ts +71 -0
- package/dist/elysia/index.js +103 -0
- package/dist/errors-DSMnAVNa.js +43 -0
- package/dist/errors-DbZ1YOnb.d.ts +138 -0
- package/dist/errors-Iy71s7Oj.js +177 -0
- package/dist/errors-m3u9TmDu.js +27 -0
- package/dist/evaluations-DsAU9ppl.js +479 -0
- package/dist/eve/index.d.ts +95 -0
- package/dist/eve/index.js +181 -0
- package/dist/express/index.d.ts +46 -0
- package/dist/express/index.js +108 -0
- package/dist/fastify/index.d.ts +56 -0
- package/dist/fastify/index.js +141 -0
- package/dist/files-B_wAGYmt.js +121 -0
- package/dist/fixtures-Cvaw0gDG.js +64 -0
- package/dist/freeze-y1_jQL4v.js +31 -0
- package/dist/from-snapshot-BMGnhmgv.js +552 -0
- package/dist/generate-CH7ThJ14.js +173 -0
- package/dist/grantee-Bv04_Vzf.js +521 -0
- package/dist/headers-B5RRv3Xm.js +6 -0
- package/dist/headers-C8SHQccD.d.ts +6 -0
- package/dist/helpers-DnSOrhB9.js +682 -0
- package/dist/hono/index.d.ts +70 -0
- package/dist/hono/index.js +131 -0
- package/dist/hosted-BwKQ1BTA.js +265 -0
- package/dist/http-DPuDaChb.d.ts +13 -0
- package/dist/http-GgVApX1k.js +111 -0
- package/dist/index-CltcQ4Bf.d.ts +138 -0
- package/dist/index-LF_hS-yn.d.ts +177 -0
- package/dist/index-fG6NSXlc.d.ts +9 -0
- package/dist/index-xIxJLwOQ.d.ts +415 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +21 -0
- package/dist/jwt/index.d.ts +87 -0
- package/dist/jwt/index.js +571 -0
- package/dist/kernel-YOGCWNLf.js +211 -0
- package/dist/kysely/index.d.ts +77 -0
- package/dist/kysely/index.js +129 -0
- package/dist/load-BZ24CpZP.js +69 -0
- package/dist/load-QOOm1z70.js +2 -0
- package/dist/load-jose-BL6LH4bL.js +11 -0
- package/dist/lru-8q4WZjBV.js +28 -0
- package/dist/manifest-DDQbC6K0.d.ts +118 -0
- package/dist/map-DowSO96j.js +158 -0
- package/dist/map-claims-B_6I1Rn-.js +360 -0
- package/dist/map-error-RJ3ZsUyA.js +16 -0
- package/dist/markers-B0hYLvMD.js +60 -0
- package/dist/may-use-CnFEjVEp.js +37 -0
- package/dist/mcp/index.d.ts +127 -0
- package/dist/mcp/index.js +563 -0
- package/dist/nest/index.d.ts +80 -0
- package/dist/nest/index.js +270 -0
- package/dist/next/client.d.ts +24 -0
- package/dist/next/client.js +31 -0
- package/dist/next/index.d.ts +110 -0
- package/dist/next/index.js +195 -0
- package/dist/next/plugin.d.ts +14 -0
- package/dist/next/plugin.js +2 -0
- package/dist/node/index.d.ts +43 -0
- package/dist/node/index.js +66 -0
- package/dist/openai/index.d.ts +71 -0
- package/dist/openai/index.js +105 -0
- package/dist/openapi/index.d.ts +93 -0
- package/dist/openapi/index.js +3 -0
- package/dist/openapi-CwePaF7C.js +164 -0
- package/dist/openapi-DWD0Uc_4.js +250 -0
- package/dist/openapi-DcqM8nU7.js +306 -0
- package/dist/openapi-import-BWRUNNeW.js +5959 -0
- package/dist/openapi-schema-D8j_T9tO.js +6902 -0
- package/dist/orpc/index.d.ts +64 -0
- package/dist/orpc/index.js +188 -0
- package/dist/otel/index.d.ts +13 -0
- package/dist/otel/index.js +202 -0
- package/dist/package-root-zGkxO3oN.js +30 -0
- package/dist/parse-DPfIvFMU.js +135 -0
- package/dist/pdp/index.d.ts +22 -0
- package/dist/pdp/index.js +795 -0
- package/dist/peer-BOr_kJE1.js +31 -0
- package/dist/permdock-yoZ7EjxX.js +2956 -0
- package/dist/permissions-B4apnahQ.d.ts +185 -0
- package/dist/permissions-B8vCg_bI.d.ts +52 -0
- package/dist/permissions-CofRqesP.js +142 -0
- package/dist/permissions-DC7GROPA.js +600 -0
- package/dist/pg-4GJWDUxG.js +953 -0
- package/dist/pins-CqE1jZuF.js +12 -0
- package/dist/plugin-4gr7IxFJ.js +65 -0
- package/dist/policy-ANp36PnI.js +971 -0
- package/dist/policy-CInmNGkM.d.ts +1959 -0
- package/dist/policy-Cq2fB8Q5.d.ts +20 -0
- package/dist/prisma/index.d.ts +135 -0
- package/dist/prisma/index.js +430 -0
- package/dist/problem-Cgp9-KZA.js +226 -0
- package/dist/prompt-CXYhLfsS.js +32 -0
- package/dist/protected-B4K3BKoX.js +138 -0
- package/dist/protected-BuPAycJT.d.ts +26 -0
- package/dist/protected-wY7nXhY9.d.ts +23 -0
- package/dist/provider-_wx46HpB.js +48 -0
- package/dist/provider-wTAUda2v.d.ts +6 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +6 -0
- package/dist/react/provider-client.d.ts +2 -0
- package/dist/react/provider-client.js +3 -0
- package/dist/react-native/index.d.ts +42 -0
- package/dist/react-native/index.js +174 -0
- package/dist/refs-ChLSxbST.js +90 -0
- package/dist/relations-r4soIFZB.js +426 -0
- package/dist/revocations-Cy06JNx2.d.ts +21 -0
- package/dist/rls-BOFU3chG.js +233 -0
- package/dist/rls-CJVja9Ww.js +2119 -0
- package/dist/rls-graph-DxQ39PJj.js +371 -0
- package/dist/rls-helpers-BxRuif0l.js +1346 -0
- package/dist/rls-import-CXV6LBlS.js +942 -0
- package/dist/rls-migrate-DrFPbf8p.js +366 -0
- package/dist/row-check-BajTgQZ-.d.ts +43 -0
- package/dist/run-CJ6UvS3a.js +155 -0
- package/dist/runtime-DP9ttFh1.js +27 -0
- package/dist/saas-BRrZzJkM.js +1193 -0
- package/dist/schema-P8yoma__.js +296 -0
- package/dist/scim/index.d.ts +2 -0
- package/dist/scim/index.js +2 -0
- package/dist/scim-9NFa0XVZ.js +1445 -0
- package/dist/scopes-cKVp_WTw.js +212 -0
- package/dist/server/index.d.ts +123 -0
- package/dist/server/index.js +8 -0
- package/dist/sha256-BO0swRXL.js +150 -0
- package/dist/sink-Bd9PSyfq.js +141 -0
- package/dist/sink-Cfr9-7YC.d.ts +104 -0
- package/dist/skills-C_lpV4Jx.js +50 -0
- package/dist/skills-Dx3QLnMY.js +110 -0
- package/dist/snapshot-DE8dE_hz.js +1051 -0
- package/dist/solid/index.d.ts +63 -0
- package/dist/solid/index.js +197 -0
- package/dist/source-DoBBYJi2.js +6 -0
- package/dist/sources-DOpW5Ila.d.ts +347 -0
- package/dist/sources-DVHM3Mwq.js +284 -0
- package/dist/sql-Bll1d7y0.js +22 -0
- package/dist/src-CTNT-PBW.js +430 -0
- package/dist/ssf/index.d.ts +3 -0
- package/dist/ssf/index.js +622 -0
- package/dist/store-Bq90395i.d.ts +27 -0
- package/dist/store-C6hFW6ta.js +508 -0
- package/dist/stores-CkG2HrSg.js +140 -0
- package/dist/stores-CvOnu_2T.d.ts +41 -0
- package/dist/stream-BhMfZOwr.d.ts +12 -0
- package/dist/stream-Q_xlB6Ko.js +52 -0
- package/dist/style-CTm1AXDT.js +22 -0
- package/dist/subject-C6dLxqHU.js +24 -0
- package/dist/subject-settings-xt7V845g.js +82 -0
- package/dist/supabase/index.d.ts +67 -0
- package/dist/supabase/index.js +4 -0
- package/dist/supabase/middleware.d.ts +77 -0
- package/dist/supabase/middleware.js +68 -0
- package/dist/supabase-D8UlBA7Z.js +83 -0
- package/dist/supabase-DTxGtYdi.js +796 -0
- package/dist/supabase-hook-DW-xP4hU.js +2 -0
- package/dist/supabase-hook-D_OqGb_V.js +1528 -0
- package/dist/svelte/Protected.svelte +34 -0
- package/dist/svelte/index.d.ts +10 -0
- package/dist/svelte/index.js +53 -0
- package/dist/svelte/runtime.d.ts +6 -0
- package/dist/svelte/runtime.js +3 -0
- package/dist/svelte/source.d.ts +10 -0
- package/dist/svelte/source.js +8 -0
- package/dist/terminal/index.d.ts +171 -0
- package/dist/terminal/index.js +821 -0
- package/dist/testing/index.d.ts +656 -0
- package/dist/testing/index.js +3208 -0
- package/dist/testing/saas/index.d.ts +194 -0
- package/dist/testing/saas/index.js +3 -0
- package/dist/testing/saas/permissions.d.ts +2 -0
- package/dist/testing/saas/permissions.js +2 -0
- package/dist/text-diff-BdkkYSbi.js +15 -0
- package/dist/thenable-okc2xDsj.js +10 -0
- package/dist/timeout-D51niuQP.js +8 -0
- package/dist/trpc/index.d.ts +80 -0
- package/dist/trpc/index.js +205 -0
- package/dist/types-B8w5PFtS.d.ts +141 -0
- package/dist/types-B9dmiiab.d.ts +66 -0
- package/dist/types-BBK-exvJ.d.ts +177 -0
- package/dist/types-BvBk1wgn.d.ts +118 -0
- package/dist/types-CxquUByI.d.ts +9 -0
- package/dist/types-D6Z6-rKJ.d.ts +312 -0
- package/dist/types-DbWdEfcm.d.ts +87 -0
- package/dist/types-bva3i4Gf.d.ts +98 -0
- package/dist/types-i4BAOvdb.d.ts +97 -0
- package/dist/unplugin/index.d.ts +7 -0
- package/dist/unplugin/index.js +30 -0
- package/dist/usage-1ozMubLY.js +42 -0
- package/dist/usage-CUnK6Ou9.js +530 -0
- package/dist/usage-PyEor6GA.js +2 -0
- package/dist/validity-D0uRmJKJ.js +224 -0
- package/dist/verifier-B90agnhl.js +461 -0
- package/dist/version-CnSh33Fj.js +16 -0
- package/dist/vocabulary-Dk0fs-Jk.d.ts +56 -0
- package/dist/vue/index.d.ts +57 -0
- package/dist/vue/index.js +203 -0
- package/dist/webmcp/index.d.ts +75 -0
- package/dist/webmcp/index.js +313 -0
- package/package.json +423 -4
- package/rulesets/permdock.yaml +29 -0
- package/schemas/catalog-v1.json +507 -0
- package/schemas/openapi/oas-3.1.json +1298 -0
- package/schemas/openapi/oas-3.2.json +1516 -0
- package/schemas/openapi/overlay-1.1.json +79 -0
- package/schemas/supabase-claims-v1.json +139 -0
- package/schemas/supabase-manifest-v1.json +217 -0
- package/skills/permdock/SKILL.md +66 -0
- package/skills/permdock-agents/SKILL.md +77 -0
- package/skills/permdock-agents/references/runtimes.md +211 -0
- package/skills/permdock-approvals/SKILL.md +80 -0
- package/skills/permdock-approvals/references/stores-and-resume.md +83 -0
- package/skills/permdock-audit/SKILL.md +67 -0
- package/skills/permdock-credentials/SKILL.md +55 -0
- package/skills/permdock-credentials/references/tokens-keys-links.md +127 -0
- package/skills/permdock-data/SKILL.md +57 -0
- package/skills/permdock-data/references/queries-and-rls.md +54 -0
- package/skills/permdock-data/references/relationships.md +65 -0
- package/skills/permdock-tenancy/SKILL.md +77 -0
- package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +83 -0
- package/skills/permdock-wire/SKILL.md +116 -0
- package/skills/permdock-wire/references/adapters.md +480 -0
- package/skills/permdock-wire/references/policy-options.md +43 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { t as byCodePoint } from "./compare-pfyVnBjE.js";
|
|
2
|
+
//#region src/cli/generate.ts
|
|
3
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
4
|
+
const MAX_DEPTH = 6;
|
|
5
|
+
function isSchemaKind(value) {
|
|
6
|
+
return value === "zod" || value === "valibot" || value === "arktype";
|
|
7
|
+
}
|
|
8
|
+
function schemaImport(kind) {
|
|
9
|
+
switch (kind) {
|
|
10
|
+
case "zod": return "import { z } from 'zod'";
|
|
11
|
+
case "valibot": return "import * as v from 'valibot'";
|
|
12
|
+
case "arktype": return "import { type } from 'arktype'";
|
|
13
|
+
default: return kind;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function emptySchema(kind) {
|
|
17
|
+
return schemaExpression(kind, { type: "object" });
|
|
18
|
+
}
|
|
19
|
+
function propertyKey(name) {
|
|
20
|
+
return IDENTIFIER.test(name) ? name : JSON.stringify(name);
|
|
21
|
+
}
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function literalEnum(schema) {
|
|
26
|
+
const values = schema["enum"];
|
|
27
|
+
if (!Array.isArray(values) || values.length === 0 || !values.every((value) => typeof value === "string")) return;
|
|
28
|
+
return values;
|
|
29
|
+
}
|
|
30
|
+
function schemaType(schema) {
|
|
31
|
+
const type = schema["type"];
|
|
32
|
+
if (typeof type === "string") return type;
|
|
33
|
+
if (Array.isArray(type)) {
|
|
34
|
+
const named = type.filter((item) => item !== "null");
|
|
35
|
+
return named.length === 1 && typeof named[0] === "string" ? named[0] : void 0;
|
|
36
|
+
}
|
|
37
|
+
return isRecord(schema["properties"]) ? "object" : void 0;
|
|
38
|
+
}
|
|
39
|
+
function zodOf(schema, resolve, depth) {
|
|
40
|
+
const node = resolve(schema);
|
|
41
|
+
const values = literalEnum(node);
|
|
42
|
+
if (values !== void 0) return `z.enum(${JSON.stringify(values)})`;
|
|
43
|
+
const type = depth > MAX_DEPTH ? void 0 : schemaType(node);
|
|
44
|
+
if (type === void 0) return "z.unknown()";
|
|
45
|
+
switch (type) {
|
|
46
|
+
case "string": return "z.string()";
|
|
47
|
+
case "number": return "z.number()";
|
|
48
|
+
case "integer": return "z.number().int()";
|
|
49
|
+
case "boolean": return "z.boolean()";
|
|
50
|
+
case "array": return `z.array(${isRecord(node["items"]) ? zodOf(node["items"], resolve, depth + 1) : "z.unknown()"})`;
|
|
51
|
+
case "object": {
|
|
52
|
+
const required = new Set(Array.isArray(node["required"]) ? node["required"] : []);
|
|
53
|
+
const properties = isRecord(node["properties"]) ? node["properties"] : {};
|
|
54
|
+
const fields = Object.entries(properties).filter((entry) => isRecord(entry[1])).map(([name, child]) => {
|
|
55
|
+
const expression = zodOf(child, resolve, depth + 1);
|
|
56
|
+
return `${propertyKey(name)}: ${required.has(name) ? expression : `${expression}.optional()`}`;
|
|
57
|
+
});
|
|
58
|
+
return `z.object({${fields.length === 0 ? "" : ` ${fields.join(", ")} `}})`;
|
|
59
|
+
}
|
|
60
|
+
default: return "z.unknown()";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function valibotOf(schema, resolve, depth) {
|
|
64
|
+
const node = resolve(schema);
|
|
65
|
+
const values = literalEnum(node);
|
|
66
|
+
if (values !== void 0) return `v.picklist(${JSON.stringify(values)})`;
|
|
67
|
+
const type = depth > MAX_DEPTH ? void 0 : schemaType(node);
|
|
68
|
+
if (type === void 0) return "v.unknown()";
|
|
69
|
+
switch (type) {
|
|
70
|
+
case "string": return "v.string()";
|
|
71
|
+
case "number": return "v.number()";
|
|
72
|
+
case "integer": return "v.pipe(v.number(), v.integer())";
|
|
73
|
+
case "boolean": return "v.boolean()";
|
|
74
|
+
case "array": return `v.array(${isRecord(node["items"]) ? valibotOf(node["items"], resolve, depth + 1) : "v.unknown()"})`;
|
|
75
|
+
case "object": {
|
|
76
|
+
const required = new Set(Array.isArray(node["required"]) ? node["required"] : []);
|
|
77
|
+
const properties = isRecord(node["properties"]) ? node["properties"] : {};
|
|
78
|
+
const fields = Object.entries(properties).filter((entry) => isRecord(entry[1])).map(([name, child]) => {
|
|
79
|
+
const expression = valibotOf(child, resolve, depth + 1);
|
|
80
|
+
return `${propertyKey(name)}: ${required.has(name) ? expression : `v.optional(${expression})`}`;
|
|
81
|
+
});
|
|
82
|
+
return `v.object({${fields.length === 0 ? "" : ` ${fields.join(", ")} `}})`;
|
|
83
|
+
}
|
|
84
|
+
default: return "v.unknown()";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** An arktype definition: a string keyword or an object literal. */
|
|
88
|
+
function arktypeOf(schema, resolve, depth) {
|
|
89
|
+
const node = resolve(schema);
|
|
90
|
+
const values = literalEnum(node);
|
|
91
|
+
if (values !== void 0) return JSON.stringify(values.map((value) => `'${value.replaceAll("'", "\\'")}'`).join(" | "));
|
|
92
|
+
const type = depth > MAX_DEPTH ? void 0 : schemaType(node);
|
|
93
|
+
if (type === void 0) return "'unknown'";
|
|
94
|
+
switch (type) {
|
|
95
|
+
case "string": return "'string'";
|
|
96
|
+
case "number": return "'number'";
|
|
97
|
+
case "integer": return "'number.integer'";
|
|
98
|
+
case "boolean": return "'boolean'";
|
|
99
|
+
case "array": {
|
|
100
|
+
if (!isRecord(node["items"])) return "'unknown[]'";
|
|
101
|
+
const item = arktypeOf(node["items"], resolve, depth + 1);
|
|
102
|
+
return item.startsWith("'") && !item.includes("|") ? `'${item.slice(1, -1)}[]'` : `[${item}, '[]']`;
|
|
103
|
+
}
|
|
104
|
+
case "object": {
|
|
105
|
+
const required = new Set(Array.isArray(node["required"]) ? node["required"] : []);
|
|
106
|
+
const properties = isRecord(node["properties"]) ? node["properties"] : {};
|
|
107
|
+
const fields = Object.entries(properties).filter((entry) => isRecord(entry[1])).map(([name, child]) => `${JSON.stringify(required.has(name) ? name : `${name}?`)}: ${arktypeOf(child, resolve, depth + 1)}`);
|
|
108
|
+
return `{${fields.length === 0 ? "" : ` ${fields.join(", ")} `}}`;
|
|
109
|
+
}
|
|
110
|
+
default: return "'unknown'";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A validator expression for a JSON Schema object. Only the portable core
|
|
115
|
+
* (primitives, enums of strings, arrays, objects with `required`) is
|
|
116
|
+
* translated; anything else becomes the validator's `unknown`.
|
|
117
|
+
*/
|
|
118
|
+
function schemaExpression(kind, schema, resolve = (node) => node) {
|
|
119
|
+
switch (kind) {
|
|
120
|
+
case "zod": return zodOf(schema, resolve, 0);
|
|
121
|
+
case "valibot": return valibotOf(schema, resolve, 0);
|
|
122
|
+
case "arktype": return `type(${arktypeOf(schema, resolve, 0)})`;
|
|
123
|
+
default: return kind;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function renderList(value, indent) {
|
|
127
|
+
if (Array.isArray(value)) return JSON.stringify(value);
|
|
128
|
+
return JSON.stringify(value, null, 2).replaceAll("\n", `\n${indent}`);
|
|
129
|
+
}
|
|
130
|
+
function renderResource(resource, indent) {
|
|
131
|
+
const inner = `${indent} `;
|
|
132
|
+
const options = [
|
|
133
|
+
`${inner}id: '${(resource.id ?? "id").replaceAll("\\", "\\\\").replaceAll("'", "\\'")}',`,
|
|
134
|
+
`${inner}actions: ${renderList(resource.actions, inner)},`,
|
|
135
|
+
`${inner}collection: ${renderList(resource.collection, inner)},`
|
|
136
|
+
].join("\n");
|
|
137
|
+
return `${resource.schema === void 0 ? "resource({" : `resource(${resource.schema}, {`}\n${options}\n${indent}})`;
|
|
138
|
+
}
|
|
139
|
+
function insert(trie, resource) {
|
|
140
|
+
let node = trie;
|
|
141
|
+
for (const [index, segment] of resource.path.entries()) {
|
|
142
|
+
if (index === resource.path.length - 1) {
|
|
143
|
+
node.set(segment, resource);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const next = node.get(segment);
|
|
147
|
+
if (next instanceof Map) node = next;
|
|
148
|
+
else {
|
|
149
|
+
const created = /* @__PURE__ */ new Map();
|
|
150
|
+
node.set(segment, created);
|
|
151
|
+
node = created;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function renderTrie(trie, indent) {
|
|
156
|
+
return [...trie.entries()].toSorted(([a], [b]) => byCodePoint(a, b)).map(([segment, value]) => value instanceof Map ? `${indent}${propertyKey(segment)}: {\n${renderTrie(value, `${indent} `)}\n${indent}},` : `${indent}${propertyKey(segment)}: ${renderResource(value, indent)},`).join("\n");
|
|
157
|
+
}
|
|
158
|
+
/** A deterministic `definePermissions()` module with a `// @generated` header. */
|
|
159
|
+
function emitPermissionsModule(input) {
|
|
160
|
+
const trie = /* @__PURE__ */ new Map();
|
|
161
|
+
for (const resource of input.resources) insert(trie, resource);
|
|
162
|
+
const imports = ["import { definePermissions, resource } from 'permdock'", ...input.schema === void 0 ? [] : [schemaImport(input.schema)]];
|
|
163
|
+
const extras = Object.entries(input.exports ?? {}).map(([name, value]) => `export const ${name} = ${JSON.stringify(value, null, 2)} as const\n\n`);
|
|
164
|
+
return `// @generated by permdock ${input.generator}
|
|
165
|
+
${imports.join("\n")}
|
|
166
|
+
|
|
167
|
+
${extras.join("")}export const permissions = definePermissions({
|
|
168
|
+
${renderTrie(trie, " ")}
|
|
169
|
+
})
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { schemaExpression as i, emptySchema as n, isSchemaKind as r, emitPermissionsModule as t };
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { r as sole, t as compact } from "./compact-y6vfu2_f.js";
|
|
2
|
+
import { n as freezeDeep } from "./freeze-y1_jQL4v.js";
|
|
3
|
+
import { S as isForbiddenKey, d as isFieldRelation, g as listPermissions, h as isSelfParented, l as isComputedRelation, p as isPrincipalRelation, r as expandRelation, u as isEdgeRelation, w as ownKeys, x as assertSafeKey } from "./permissions-DC7GROPA.js";
|
|
4
|
+
import { a as resolveScope, s as rootScope, t as activeFor, u as scopeList } from "./scopes-cKVp_WTw.js";
|
|
5
|
+
//#region src/core/vocabulary.ts
|
|
6
|
+
const ROLE_KIND = "role";
|
|
7
|
+
const PLAN_KIND = "plan";
|
|
8
|
+
function makeRole(key, init) {
|
|
9
|
+
assertSafeKey(key, "role");
|
|
10
|
+
const on = init.on;
|
|
11
|
+
const leaf = {
|
|
12
|
+
key,
|
|
13
|
+
assignable: init.assignable ?? on !== void 0,
|
|
14
|
+
meta: freezeDeep({ ...init.meta })
|
|
15
|
+
};
|
|
16
|
+
if (on !== void 0) Object.assign(leaf, { on });
|
|
17
|
+
Object.defineProperty(leaf, "kind", {
|
|
18
|
+
value: ROLE_KIND,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
writable: false,
|
|
21
|
+
configurable: false
|
|
22
|
+
});
|
|
23
|
+
return Object.freeze(leaf);
|
|
24
|
+
}
|
|
25
|
+
function makePlan(key, init) {
|
|
26
|
+
assertSafeKey(key, "plan");
|
|
27
|
+
const leaf = {
|
|
28
|
+
key,
|
|
29
|
+
meta: freezeDeep({ ...init.meta })
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(leaf, "kind", {
|
|
32
|
+
value: PLAN_KIND,
|
|
33
|
+
enumerable: false,
|
|
34
|
+
writable: false,
|
|
35
|
+
configurable: false
|
|
36
|
+
});
|
|
37
|
+
return Object.freeze(leaf);
|
|
38
|
+
}
|
|
39
|
+
function isRole(value) {
|
|
40
|
+
return value !== null && typeof value === "object" && "key" in value && typeof value.key === "string" && value.kind === "role";
|
|
41
|
+
}
|
|
42
|
+
function isPlan(value) {
|
|
43
|
+
return value !== null && typeof value === "object" && "key" in value && typeof value.key === "string" && value.kind === "plan";
|
|
44
|
+
}
|
|
45
|
+
function defineRoles(input) {
|
|
46
|
+
const tree = {};
|
|
47
|
+
for (const key of Object.keys(input)) {
|
|
48
|
+
if (isForbiddenKey(key)) throw new Error(`PermDock: forbidden role key '${key}'`);
|
|
49
|
+
tree[key] = makeRole(key, input[key] ?? {});
|
|
50
|
+
}
|
|
51
|
+
return freezeDeep(tree);
|
|
52
|
+
}
|
|
53
|
+
function definePlans(input) {
|
|
54
|
+
const tree = {};
|
|
55
|
+
for (const key of Object.keys(input)) {
|
|
56
|
+
if (isForbiddenKey(key)) throw new Error(`PermDock: forbidden plan key '${key}'`);
|
|
57
|
+
tree[key] = makePlan(key, input[key] ?? {});
|
|
58
|
+
}
|
|
59
|
+
return freezeDeep(tree);
|
|
60
|
+
}
|
|
61
|
+
function listRoles(tree) {
|
|
62
|
+
if (tree === void 0) return [];
|
|
63
|
+
return ownKeys(tree).flatMap((key) => {
|
|
64
|
+
const leaf = tree[key];
|
|
65
|
+
return leaf === void 0 ? [] : [leaf];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function listPlans(tree) {
|
|
69
|
+
if (tree === void 0) return [];
|
|
70
|
+
return ownKeys(tree).flatMap((key) => {
|
|
71
|
+
const leaf = tree[key];
|
|
72
|
+
return leaf === void 0 ? [] : [leaf];
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function findRole(tree, key) {
|
|
76
|
+
if (tree === void 0 || isForbiddenKey(key)) return;
|
|
77
|
+
return tree[key];
|
|
78
|
+
}
|
|
79
|
+
function synthesiseRole(key, options) {
|
|
80
|
+
const on = options?.on;
|
|
81
|
+
const assignable = options?.assignable ?? false;
|
|
82
|
+
const meta = options?.meta;
|
|
83
|
+
if (on === void 0) return makeRole(key, meta === void 0 ? { assignable } : {
|
|
84
|
+
assignable,
|
|
85
|
+
meta
|
|
86
|
+
});
|
|
87
|
+
return makeRole(key, meta === void 0 ? {
|
|
88
|
+
on,
|
|
89
|
+
assignable
|
|
90
|
+
} : {
|
|
91
|
+
on,
|
|
92
|
+
assignable,
|
|
93
|
+
meta
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/core/grantee.ts
|
|
98
|
+
const DEFAULT_RELATION_DEPTH = 16;
|
|
99
|
+
function isGrantee(value) {
|
|
100
|
+
return value !== null && typeof value === "object" && "kind" in value && typeof value.kind === "string";
|
|
101
|
+
}
|
|
102
|
+
function anyone() {
|
|
103
|
+
return freezeDeep({ kind: "anyone" });
|
|
104
|
+
}
|
|
105
|
+
function authenticated() {
|
|
106
|
+
return freezeDeep({ kind: "authenticated" });
|
|
107
|
+
}
|
|
108
|
+
function relation(resource, name, options) {
|
|
109
|
+
const resourceName = listPermissions(resource)[0]?.resource;
|
|
110
|
+
if (resourceName === void 0) throw new Error("PermDock: relation() requires a resource tree");
|
|
111
|
+
const through = options?.through;
|
|
112
|
+
if (Array.isArray(through)) {
|
|
113
|
+
if (through.length === 0) throw new Error("PermDock: relation() through needs at least one link");
|
|
114
|
+
for (const link of through) if (typeof link !== "string" || link === "" || link === "parent") throw new Error("PermDock: relation() through lists link names; walk parents with through: 'parent' or depth");
|
|
115
|
+
} else if (through !== void 0 && through !== "parent") throw new Error(`PermDock: relation() through must be 'parent' or a list of link names (got '${String(through)}')`);
|
|
116
|
+
const depth = options?.depth;
|
|
117
|
+
if (depth !== void 0) {
|
|
118
|
+
if (through === void 0) throw new Error("PermDock: relation() depth needs through: 'parent' or a link list");
|
|
119
|
+
const hops = Array.isArray(through) ? through.length : 0;
|
|
120
|
+
if (!Number.isInteger(depth) || depth < 0 || depth + hops > 32) throw new Error(`PermDock: relation() depth must be an integer from 0 to 32, counting each link`);
|
|
121
|
+
}
|
|
122
|
+
return freezeDeep(compact({
|
|
123
|
+
kind: "relation",
|
|
124
|
+
resource: resourceName,
|
|
125
|
+
relation: name,
|
|
126
|
+
through: through === void 0 || through === "parent" ? through : [...through],
|
|
127
|
+
depth
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
function plan(name) {
|
|
131
|
+
return freezeDeep({
|
|
132
|
+
kind: "plan",
|
|
133
|
+
plan: typeof name === "string" ? name : name.key
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function actor(kind) {
|
|
137
|
+
return freezeDeep({
|
|
138
|
+
kind: "actor",
|
|
139
|
+
actor: kind
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function assurance(options) {
|
|
143
|
+
const acr = options.acr === void 0 ? void 0 : typeof options.acr === "string" ? [options.acr] : options.acr;
|
|
144
|
+
const amr = options.amr === void 0 ? void 0 : typeof options.amr === "string" ? [options.amr] : options.amr;
|
|
145
|
+
return freezeDeep(compact({
|
|
146
|
+
kind: "assurance",
|
|
147
|
+
acr,
|
|
148
|
+
amr,
|
|
149
|
+
maxAge: options.maxAge
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
function resolveRoleScope(on) {
|
|
153
|
+
return typeof on === "string" ? on : "global";
|
|
154
|
+
}
|
|
155
|
+
function asGrantee(input) {
|
|
156
|
+
if (Array.isArray(input)) {
|
|
157
|
+
const items = [];
|
|
158
|
+
for (const item of input) items.push(...flattenGrantee(asGrantee(item)));
|
|
159
|
+
return items;
|
|
160
|
+
}
|
|
161
|
+
if (typeof input === "string") return freezeDeep({
|
|
162
|
+
kind: "role",
|
|
163
|
+
role: input,
|
|
164
|
+
scope: "global"
|
|
165
|
+
});
|
|
166
|
+
if (isRole(input)) return freezeDeep({
|
|
167
|
+
kind: "role",
|
|
168
|
+
role: input.key,
|
|
169
|
+
scope: resolveRoleScope(input.on)
|
|
170
|
+
});
|
|
171
|
+
if (isPlan(input)) return freezeDeep({
|
|
172
|
+
kind: "plan",
|
|
173
|
+
plan: input.key
|
|
174
|
+
});
|
|
175
|
+
if (isGrantee(input)) return input;
|
|
176
|
+
throw new Error("PermDock: invalid grantee");
|
|
177
|
+
}
|
|
178
|
+
function flattenGrantee(input) {
|
|
179
|
+
if (input === void 0) return [];
|
|
180
|
+
if (Array.isArray(input)) return input;
|
|
181
|
+
return [input];
|
|
182
|
+
}
|
|
183
|
+
function roleNameOf(to) {
|
|
184
|
+
for (const item of flattenGrantee(to)) if (item.kind === "role") return item.role;
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
function roleScopeOf(to, fallback = "global") {
|
|
188
|
+
for (const item of flattenGrantee(to)) if (item.kind === "role") return item.scope;
|
|
189
|
+
return fallback;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Where a graph relation starts on the row: its own id when the relation is
|
|
193
|
+
* on the row's resource, the parent field when it is on the parent resource.
|
|
194
|
+
* `undefined` when `through` cannot reach the relation's resource.
|
|
195
|
+
*/
|
|
196
|
+
function relationStart(grantee, resource, target) {
|
|
197
|
+
if (resource === void 0 || target === void 0 || Array.isArray(grantee.through)) return;
|
|
198
|
+
const walks = grantee.through === "parent" && isSelfParented(target);
|
|
199
|
+
const requested = grantee.depth ?? DEFAULT_RELATION_DEPTH;
|
|
200
|
+
const depth = walks ? Number.isInteger(requested) ? Math.min(Math.max(requested, 0), 32) : 0 : 0;
|
|
201
|
+
if (target.name === resource.name) return {
|
|
202
|
+
field: resource.id,
|
|
203
|
+
parent: false,
|
|
204
|
+
depth
|
|
205
|
+
};
|
|
206
|
+
if (grantee.through === "parent" && resource.parent?.resource === target.name) return {
|
|
207
|
+
field: resource.parent.field,
|
|
208
|
+
parent: true,
|
|
209
|
+
depth
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A resource role held on self-parented `membershipResource` instances
|
|
214
|
+
* (`ids`) reaches rows below them: the row itself when it is of that
|
|
215
|
+
* resource, its parent field when its parent is, walked up to the default
|
|
216
|
+
* depth. `undefined` when the row is not on such a chain.
|
|
217
|
+
*/
|
|
218
|
+
function resourceRoleCondition(resource, membershipResource, ids, resources) {
|
|
219
|
+
if (resource === void 0 || !isSelfParented(resources.get(membershipResource))) return;
|
|
220
|
+
const start = resource.name === membershipResource ? {
|
|
221
|
+
field: resource.id,
|
|
222
|
+
parent: false
|
|
223
|
+
} : resource.parent?.resource === membershipResource ? {
|
|
224
|
+
field: resource.parent.field,
|
|
225
|
+
parent: true
|
|
226
|
+
} : void 0;
|
|
227
|
+
if (start === void 0) return;
|
|
228
|
+
return compact({
|
|
229
|
+
op: "related",
|
|
230
|
+
resource: membershipResource,
|
|
231
|
+
relation: "",
|
|
232
|
+
ids: [...new Set(ids)].toSorted(),
|
|
233
|
+
field: start.field,
|
|
234
|
+
depth: DEFAULT_RELATION_DEPTH,
|
|
235
|
+
parent: start.parent ? true : void 0,
|
|
236
|
+
restricted: resource.restricted
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The link path from the row to the grantee's resource: the row field of
|
|
241
|
+
* the first link and each hop. `undefined` when a link is not declared or
|
|
242
|
+
* the path ends on another resource.
|
|
243
|
+
*/
|
|
244
|
+
function relationHops(grantee, resource, resources) {
|
|
245
|
+
const through = grantee.through;
|
|
246
|
+
if (!Array.isArray(through) || resource === void 0) return;
|
|
247
|
+
const hops = [];
|
|
248
|
+
let current = resource;
|
|
249
|
+
let field;
|
|
250
|
+
for (const link of through) {
|
|
251
|
+
const spec = current !== void 0 && Object.hasOwn(current.links, link) ? current.links[link] : void 0;
|
|
252
|
+
if (spec === void 0) return;
|
|
253
|
+
field ??= spec.field;
|
|
254
|
+
hops.push({
|
|
255
|
+
link,
|
|
256
|
+
resource: spec.resource
|
|
257
|
+
});
|
|
258
|
+
current = resources?.get(spec.resource);
|
|
259
|
+
}
|
|
260
|
+
if (field === void 0 || current === void 0 || current.name !== grantee.resource) return;
|
|
261
|
+
const depth = grantee.depth ?? 0;
|
|
262
|
+
if (depth > 0 && !isSelfParented(current)) return;
|
|
263
|
+
return {
|
|
264
|
+
field,
|
|
265
|
+
hops,
|
|
266
|
+
depth
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Whether the grantee needs the relation graph: a `through` walk, an edge
|
|
271
|
+
* table, or an `includes` that reaches one.
|
|
272
|
+
*/
|
|
273
|
+
function isGraphRelation(grantee, resources) {
|
|
274
|
+
if (grantee.through !== void 0) return true;
|
|
275
|
+
const node = resources?.get(grantee.resource);
|
|
276
|
+
return expandRelation(node, grantee.relation).some((name) => isEdgeRelation(node?.relations[name]));
|
|
277
|
+
}
|
|
278
|
+
function periodConditions(spec, now) {
|
|
279
|
+
const out = [];
|
|
280
|
+
const startsAt = spec.period?.startsAt;
|
|
281
|
+
if (startsAt !== void 0) out.push({
|
|
282
|
+
op: "or",
|
|
283
|
+
conditions: [{
|
|
284
|
+
op: "isNull",
|
|
285
|
+
field: startsAt,
|
|
286
|
+
value: true
|
|
287
|
+
}, {
|
|
288
|
+
op: "lte",
|
|
289
|
+
field: startsAt,
|
|
290
|
+
value: now
|
|
291
|
+
}]
|
|
292
|
+
});
|
|
293
|
+
const expiresAt = spec.period?.expiresAt;
|
|
294
|
+
if (expiresAt !== void 0) out.push({
|
|
295
|
+
op: "or",
|
|
296
|
+
conditions: [{
|
|
297
|
+
op: "isNull",
|
|
298
|
+
field: expiresAt,
|
|
299
|
+
value: true
|
|
300
|
+
}, {
|
|
301
|
+
op: "gt",
|
|
302
|
+
field: expiresAt,
|
|
303
|
+
value: now
|
|
304
|
+
}]
|
|
305
|
+
});
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
function relationCondition(grantee, resource, scopes = scopeList(void 0), options = {}) {
|
|
309
|
+
const target = grantee.resource === resource?.name ? resource : options.resources?.get(grantee.resource);
|
|
310
|
+
if (isGraphRelation(grantee, options.resources ?? targetMap(target))) {
|
|
311
|
+
const spec = target?.relations[grantee.relation];
|
|
312
|
+
if (spec === void 0 || isFieldRelation(spec) && spec.memberOf !== void 0) return;
|
|
313
|
+
if (Array.isArray(grantee.through)) {
|
|
314
|
+
const path = relationHops(grantee, resource, options.resources);
|
|
315
|
+
if (path === void 0 || target === void 0) return;
|
|
316
|
+
return compact({
|
|
317
|
+
op: "related",
|
|
318
|
+
resource: target.name,
|
|
319
|
+
relation: grantee.relation,
|
|
320
|
+
field: path.field,
|
|
321
|
+
depth: path.depth,
|
|
322
|
+
hops: path.hops,
|
|
323
|
+
restricted: resource?.restricted
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
const start = relationStart(grantee, resource, target);
|
|
327
|
+
if (start === void 0 || target === void 0) return;
|
|
328
|
+
return compact({
|
|
329
|
+
op: "related",
|
|
330
|
+
resource: target.name,
|
|
331
|
+
relation: grantee.relation,
|
|
332
|
+
field: start.field,
|
|
333
|
+
depth: start.depth,
|
|
334
|
+
parent: start.parent ? true : void 0,
|
|
335
|
+
restricted: start.parent || start.depth > 0 ? resource?.restricted : void 0
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const spec = resource?.relations?.[grantee.relation];
|
|
339
|
+
if (spec === void 0 || isEdgeRelation(spec)) return;
|
|
340
|
+
if (spec.includes !== void 0 && options.includes !== false) {
|
|
341
|
+
const parts = expandRelation(resource, grantee.relation).flatMap((name) => {
|
|
342
|
+
const part = relationCondition({
|
|
343
|
+
...grantee,
|
|
344
|
+
relation: name
|
|
345
|
+
}, resource, scopes, {
|
|
346
|
+
...options,
|
|
347
|
+
includes: false
|
|
348
|
+
});
|
|
349
|
+
return part === void 0 ? [] : [part];
|
|
350
|
+
});
|
|
351
|
+
return sole(parts) ?? {
|
|
352
|
+
op: "or",
|
|
353
|
+
conditions: parts
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
if (isComputedRelation(spec)) return;
|
|
357
|
+
if (isPrincipalRelation(spec)) {
|
|
358
|
+
const owner = {
|
|
359
|
+
op: "eq",
|
|
360
|
+
field: spec.principal,
|
|
361
|
+
value: { ref: "principal.id" }
|
|
362
|
+
};
|
|
363
|
+
const period = periodConditions(spec, options.now ?? { date: (/* @__PURE__ */ new Date()).toISOString() });
|
|
364
|
+
return period.length === 0 ? owner : {
|
|
365
|
+
op: "and",
|
|
366
|
+
conditions: [owner, ...period]
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (spec.memberOf !== void 0) {
|
|
370
|
+
const scope = resolveScope(scopes, spec.memberOf);
|
|
371
|
+
if (scope === void 0) return {
|
|
372
|
+
op: "or",
|
|
373
|
+
conditions: []
|
|
374
|
+
};
|
|
375
|
+
if (scope === rootScope(scopes)) return {
|
|
376
|
+
op: "eq",
|
|
377
|
+
field: spec.field,
|
|
378
|
+
value: { ref: "principal.tenant" }
|
|
379
|
+
};
|
|
380
|
+
return {
|
|
381
|
+
op: "memberOf",
|
|
382
|
+
scope,
|
|
383
|
+
field: spec.field,
|
|
384
|
+
roles: []
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
op: "eq",
|
|
389
|
+
field: spec.field,
|
|
390
|
+
value: { ref: "principal.id" }
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function targetMap(target) {
|
|
394
|
+
return target === void 0 ? void 0 : /* @__PURE__ */ new Map([[target.name, target]]);
|
|
395
|
+
}
|
|
396
|
+
function combineWhere(left, right) {
|
|
397
|
+
if (left === void 0) return right;
|
|
398
|
+
if (right === void 0) return left;
|
|
399
|
+
return {
|
|
400
|
+
op: "and",
|
|
401
|
+
conditions: [left, right]
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/** Seats (`Membership.entitlements`) held through memberships that apply under the active tenant. */
|
|
405
|
+
function seatsInTenant(subject, scopes) {
|
|
406
|
+
const principal = subject.principal;
|
|
407
|
+
if (principal === null) return [];
|
|
408
|
+
const list = scopeList(scopes);
|
|
409
|
+
return (principal.memberships ?? []).flatMap((membership) => membership.entitlements !== void 0 && activeFor(membership, list, principal.tenant) ? membership.entitlements : []);
|
|
410
|
+
}
|
|
411
|
+
function matchOne(grantee, subject, now, resource, scopes, resources) {
|
|
412
|
+
switch (grantee.kind) {
|
|
413
|
+
case "anyone": return { matched: true };
|
|
414
|
+
case "authenticated": return subject.principal === null ? {
|
|
415
|
+
matched: false,
|
|
416
|
+
reason: "anonymous"
|
|
417
|
+
} : { matched: true };
|
|
418
|
+
case "plan":
|
|
419
|
+
if (subject.principal === null) return {
|
|
420
|
+
matched: false,
|
|
421
|
+
reason: "anonymous"
|
|
422
|
+
};
|
|
423
|
+
return (subject.principal.plans ?? []).includes(grantee.plan) || seatsInTenant(subject, scopes).includes(grantee.plan) ? { matched: true } : {
|
|
424
|
+
matched: false,
|
|
425
|
+
reason: "not-entitled"
|
|
426
|
+
};
|
|
427
|
+
case "actor":
|
|
428
|
+
if (subject.actor === void 0) return {
|
|
429
|
+
matched: false,
|
|
430
|
+
reason: "no-grant"
|
|
431
|
+
};
|
|
432
|
+
return subject.actor.kind === grantee.actor ? { matched: true } : {
|
|
433
|
+
matched: false,
|
|
434
|
+
reason: "no-grant"
|
|
435
|
+
};
|
|
436
|
+
case "assurance": {
|
|
437
|
+
if (subject.principal === null) return {
|
|
438
|
+
matched: false,
|
|
439
|
+
reason: "anonymous"
|
|
440
|
+
};
|
|
441
|
+
const principalAssurance = subject.principal.assurance;
|
|
442
|
+
if (grantee.acr !== void 0 && grantee.acr.length > 0) {
|
|
443
|
+
const acr = principalAssurance?.acr;
|
|
444
|
+
if (acr === void 0 || !grantee.acr.includes(acr)) return {
|
|
445
|
+
matched: false,
|
|
446
|
+
reason: "insufficient-user-authentication"
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
if (grantee.amr !== void 0 && grantee.amr.length > 0) {
|
|
450
|
+
const amr = principalAssurance?.amr ?? [];
|
|
451
|
+
if (!grantee.amr.every((method) => amr.includes(method))) return {
|
|
452
|
+
matched: false,
|
|
453
|
+
reason: "insufficient-user-authentication"
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (grantee.maxAge !== void 0) {
|
|
457
|
+
const authTime = principalAssurance?.authTime;
|
|
458
|
+
if (authTime === void 0 || now - authTime > grantee.maxAge) return {
|
|
459
|
+
matched: false,
|
|
460
|
+
reason: "insufficient-user-authentication"
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
return { matched: true };
|
|
464
|
+
}
|
|
465
|
+
case "relation": {
|
|
466
|
+
if (subject.principal === null) return {
|
|
467
|
+
matched: false,
|
|
468
|
+
reason: "anonymous"
|
|
469
|
+
};
|
|
470
|
+
const where = relationCondition(grantee, resource, scopes, {
|
|
471
|
+
resources,
|
|
472
|
+
now: { date: (/* @__PURE__ */ new Date(now * 1e3)).toISOString() }
|
|
473
|
+
});
|
|
474
|
+
if (where === void 0 && resource !== void 0) return {
|
|
475
|
+
matched: false,
|
|
476
|
+
reason: "condition"
|
|
477
|
+
};
|
|
478
|
+
return compact({
|
|
479
|
+
matched: true,
|
|
480
|
+
where
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
case "role":
|
|
484
|
+
if (subject.principal === null) return {
|
|
485
|
+
matched: false,
|
|
486
|
+
reason: "anonymous"
|
|
487
|
+
};
|
|
488
|
+
return { matched: true };
|
|
489
|
+
default: return unknownGrantee(grantee);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
/** A kind this build does not know, from a forged snapshot or a newer document, never matches. */
|
|
493
|
+
function unknownGrantee(_grantee) {
|
|
494
|
+
return {
|
|
495
|
+
matched: false,
|
|
496
|
+
reason: "no-grant",
|
|
497
|
+
unknown: true
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function matchGrantee(to, subject, now, resource, scopes, resources, unknownMatches = false) {
|
|
501
|
+
const items = flattenGrantee(to);
|
|
502
|
+
if (items.length === 0) return {
|
|
503
|
+
matched: false,
|
|
504
|
+
reason: "no-grant"
|
|
505
|
+
};
|
|
506
|
+
let where;
|
|
507
|
+
for (const item of items) {
|
|
508
|
+
const result = matchOne(item, subject, now, resource, scopes, resources);
|
|
509
|
+
if (!result.matched) {
|
|
510
|
+
if (unknownMatches && result.unknown === true) continue;
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
where = combineWhere(where, result.where);
|
|
514
|
+
}
|
|
515
|
+
return compact({
|
|
516
|
+
matched: true,
|
|
517
|
+
where
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
//#endregion
|
|
521
|
+
export { listPlans as C, isRole as S, synthesiseRole as T, roleScopeOf as _, authenticated as a, findRole as b, isGraphRelation as c, relation as d, relationCondition as f, roleNameOf as g, resourceRoleCondition as h, assurance as i, matchGrantee as l, relationStart as m, anyone as n, combineWhere as o, relationHops as p, asGrantee as r, flattenGrantee as s, actor as t, plan as u, definePlans as v, listRoles as w, isPlan as x, defineRoles as y };
|