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,552 @@
|
|
|
1
|
+
import { t as compact } from "./compact-y6vfu2_f.js";
|
|
2
|
+
import { n as freezeDeep } from "./freeze-y1_jQL4v.js";
|
|
3
|
+
import { g as listPermissions } from "./permissions-DC7GROPA.js";
|
|
4
|
+
import { a as resolveScope, f as tenantOf, i as normalizeMemberships, t as activeFor, u as scopeList } from "./scopes-cKVp_WTw.js";
|
|
5
|
+
import { T as synthesiseRole, b as findRole, l as matchGrantee, w as listRoles } from "./grantee-Bv04_Vzf.js";
|
|
6
|
+
import { a as approvalMessage, n as PermDockDeniedError, o as deniedMessage, t as PermDockApprovalRequiredError } from "./errors-Iy71s7Oj.js";
|
|
7
|
+
import { a as whereFromGrants, f as resourceIdOf, g as evaluateCondition, h as simulateArazzo, m as isArazzoSimulateInput, o as decisionToken, s as payloadDigest, u as coveredByDelegation } from "./snapshot-DE8dE_hz.js";
|
|
8
|
+
import { d as rowInScope, i as isMembershipExpired, m as pickVisible, p as grantCoversField, r as inTeam, s as nowSeconds, t as isActive, u as resolveActiveTenant } from "./validity-D0uRmJKJ.js";
|
|
9
|
+
import { t as requiresApproval } from "./approval-required-TzNB9oQA.js";
|
|
10
|
+
//#region src/core/snapshot-evaluate.ts
|
|
11
|
+
function isRowPair(value) {
|
|
12
|
+
return value !== null && typeof value === "object" && "current" in value && "next" in value;
|
|
13
|
+
}
|
|
14
|
+
function coveredByInclude(snapshot, permission) {
|
|
15
|
+
const include = snapshot.include;
|
|
16
|
+
if (include === void 0 || include.length === 0) return true;
|
|
17
|
+
return include.some((prefix) => permission.key === prefix || permission.key.startsWith(`${prefix}.`) || permission.resource === prefix);
|
|
18
|
+
}
|
|
19
|
+
function rowId(data) {
|
|
20
|
+
if (data === null || typeof data !== "object") return "*";
|
|
21
|
+
const id = data["id"];
|
|
22
|
+
return typeof id === "string" || typeof id === "number" ? String(id) : "*";
|
|
23
|
+
}
|
|
24
|
+
function scopeOk(snapshot, grant, permission, subject, data, team, now) {
|
|
25
|
+
const scope = grant.scope;
|
|
26
|
+
if (scope === void 0) return { ok: true };
|
|
27
|
+
const principal = subject.principal;
|
|
28
|
+
const membership = grant.membership;
|
|
29
|
+
if (principal === null || membership === void 0) return {
|
|
30
|
+
ok: false,
|
|
31
|
+
reason: "no-membership"
|
|
32
|
+
};
|
|
33
|
+
if (isMembershipExpired(membership, now)) return {
|
|
34
|
+
ok: false,
|
|
35
|
+
reason: "expired-membership"
|
|
36
|
+
};
|
|
37
|
+
if (typeof scope === "string") {
|
|
38
|
+
const scopes = scopeList(snapshot.scopes);
|
|
39
|
+
if (membership.scope !== scope || !scopes.some((entry) => entry.name === scope)) return {
|
|
40
|
+
ok: false,
|
|
41
|
+
reason: "scope"
|
|
42
|
+
};
|
|
43
|
+
if (!activeFor(membership, scopes, principal.tenant)) return {
|
|
44
|
+
ok: false,
|
|
45
|
+
reason: principal.tenant === void 0 ? "no-membership" : "tenant-mismatch"
|
|
46
|
+
};
|
|
47
|
+
if (!inTeam(membership, scopes, team)) return {
|
|
48
|
+
ok: false,
|
|
49
|
+
reason: "scope"
|
|
50
|
+
};
|
|
51
|
+
if (permission.kind !== "instance" && (data === null || typeof data !== "object")) return { ok: true };
|
|
52
|
+
const partitioned = (name) => snapshot.scopes?.find((entry) => entry.name === name)?.resources?.includes(permission.resource) === true;
|
|
53
|
+
return rowInScope(membership, scopes, data !== null && typeof data === "object" ? data : {}, partitioned);
|
|
54
|
+
}
|
|
55
|
+
const on = membership.on;
|
|
56
|
+
if (on === void 0 || on.resource !== scope.resource || on.resource !== permission.resource) return {
|
|
57
|
+
ok: false,
|
|
58
|
+
reason: "scope"
|
|
59
|
+
};
|
|
60
|
+
if (on.id !== rowId(data)) return {
|
|
61
|
+
ok: false,
|
|
62
|
+
reason: "scope"
|
|
63
|
+
};
|
|
64
|
+
return { ok: true };
|
|
65
|
+
}
|
|
66
|
+
function conditionOk(grant, permission, current, next, subject, now, scopes) {
|
|
67
|
+
let opaqueReached = false;
|
|
68
|
+
const onOpaque = () => {
|
|
69
|
+
opaqueReached = true;
|
|
70
|
+
};
|
|
71
|
+
if (grant.portable === false) return {
|
|
72
|
+
matched: false,
|
|
73
|
+
reason: "opaque-condition"
|
|
74
|
+
};
|
|
75
|
+
if (grant.where !== void 0) {
|
|
76
|
+
if (permission.kind === "collection" || current === void 0) return {
|
|
77
|
+
matched: false,
|
|
78
|
+
reason: "condition"
|
|
79
|
+
};
|
|
80
|
+
if (grant.where.op === "opaque" || grant.check?.op === "opaque") return {
|
|
81
|
+
matched: false,
|
|
82
|
+
reason: "opaque-condition"
|
|
83
|
+
};
|
|
84
|
+
const matched = evaluateCondition(grant.where, current, subject, now, scopes, void 0, onOpaque);
|
|
85
|
+
if (opaqueReached) return {
|
|
86
|
+
matched: false,
|
|
87
|
+
reason: "opaque-condition"
|
|
88
|
+
};
|
|
89
|
+
if (!matched) return {
|
|
90
|
+
matched: false,
|
|
91
|
+
reason: "condition"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const check = grant.check;
|
|
95
|
+
if (check !== void 0) {
|
|
96
|
+
if (check.op === "opaque") return {
|
|
97
|
+
matched: false,
|
|
98
|
+
reason: "opaque-condition"
|
|
99
|
+
};
|
|
100
|
+
if (next === void 0) return {
|
|
101
|
+
matched: false,
|
|
102
|
+
reason: "condition"
|
|
103
|
+
};
|
|
104
|
+
const matched = evaluateCondition(check, next, subject, now, scopes, void 0, onOpaque);
|
|
105
|
+
if (opaqueReached) return {
|
|
106
|
+
matched: false,
|
|
107
|
+
reason: "opaque-condition"
|
|
108
|
+
};
|
|
109
|
+
if (!matched) return {
|
|
110
|
+
matched: false,
|
|
111
|
+
reason: "condition"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return { matched: true };
|
|
115
|
+
}
|
|
116
|
+
function matchedOf(grant) {
|
|
117
|
+
return compact({
|
|
118
|
+
role: grant.role,
|
|
119
|
+
permission: grant.permission,
|
|
120
|
+
to: grant.to,
|
|
121
|
+
where: grant.where,
|
|
122
|
+
check: grant.check,
|
|
123
|
+
approval: grant.approval
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function evaluateSnapshot(snapshot, subject, permission, data, team, options) {
|
|
127
|
+
const now = options.now ?? nowSeconds();
|
|
128
|
+
const tracer = options.explain === true ? {
|
|
129
|
+
evaluated: 0,
|
|
130
|
+
allows: [],
|
|
131
|
+
denies: [],
|
|
132
|
+
skipped: []
|
|
133
|
+
} : void 0;
|
|
134
|
+
const done = (decision) => freezeDeep(tracer === void 0 ? decision : {
|
|
135
|
+
...decision,
|
|
136
|
+
trace: {
|
|
137
|
+
evaluated: tracer.evaluated,
|
|
138
|
+
allows: tracer.allows,
|
|
139
|
+
denies: tracer.denies,
|
|
140
|
+
skipped: tracer.skipped
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const skip = (grant, why) => {
|
|
144
|
+
tracer?.skipped.push({
|
|
145
|
+
role: grant.role,
|
|
146
|
+
permission: grant.permission,
|
|
147
|
+
effect: grant.effect,
|
|
148
|
+
why
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
if (!coveredByInclude(snapshot, permission)) return done({
|
|
152
|
+
outcome: "denied",
|
|
153
|
+
denials: [{
|
|
154
|
+
role: null,
|
|
155
|
+
reason: "opaque-condition"
|
|
156
|
+
}],
|
|
157
|
+
alternatives: []
|
|
158
|
+
});
|
|
159
|
+
let current = data;
|
|
160
|
+
let next = data;
|
|
161
|
+
if (permission.kind === "instance" && isRowPair(data)) {
|
|
162
|
+
current = data.current;
|
|
163
|
+
next = data.next;
|
|
164
|
+
}
|
|
165
|
+
if (permission.kind === "collection") {
|
|
166
|
+
current = void 0;
|
|
167
|
+
next = data;
|
|
168
|
+
}
|
|
169
|
+
const denials = [];
|
|
170
|
+
const allows = [];
|
|
171
|
+
for (const grant of snapshot.grants) {
|
|
172
|
+
if (grant.permission !== permission.key) continue;
|
|
173
|
+
if (tracer !== void 0) tracer.evaluated += 1;
|
|
174
|
+
const match = matchGrantee(grant.to, subject, now, void 0, void 0, void 0, grant.effect === "deny");
|
|
175
|
+
if (!match.matched) {
|
|
176
|
+
denials.push(compact({
|
|
177
|
+
role: grant.role,
|
|
178
|
+
reason: match.reason ?? "no-grant",
|
|
179
|
+
to: grant.to
|
|
180
|
+
}));
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
let scoped = scopeOk(snapshot, grant, permission, subject, permission.kind === "instance" ? current : next, team, now);
|
|
184
|
+
if (scoped.ok && permission.kind === "instance" && next !== current) scoped = scopeOk(snapshot, grant, permission, subject, next, team, now);
|
|
185
|
+
if (!scoped.ok) {
|
|
186
|
+
denials.push(compact({
|
|
187
|
+
role: grant.role,
|
|
188
|
+
reason: scoped.reason,
|
|
189
|
+
to: grant.to
|
|
190
|
+
}));
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (!isActive(grant.validity, now)) {
|
|
194
|
+
if (grant.effect === "allow") denials.push({
|
|
195
|
+
role: grant.role,
|
|
196
|
+
reason: "inactive-grant",
|
|
197
|
+
detail: grant.validity
|
|
198
|
+
});
|
|
199
|
+
else skip(grant, "validity");
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (grant.effect === "deny" && grant.portable === false) {
|
|
203
|
+
if (!grantCoversField(grant.fields, options.field, grant.effect)) {
|
|
204
|
+
skip(grant, "field");
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
tracer?.denies.push(matchedOf(grant));
|
|
208
|
+
return done({
|
|
209
|
+
outcome: "denied",
|
|
210
|
+
denials: [{
|
|
211
|
+
role: grant.role,
|
|
212
|
+
reason: "opaque-condition"
|
|
213
|
+
}],
|
|
214
|
+
alternatives: []
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
const condition = conditionOk(grant, permission, current, next, subject, now, scopeList(snapshot.scopes));
|
|
218
|
+
if (!condition.matched && grant.effect === "deny" && condition.reason === "opaque-condition" && grantCoversField(grant.fields, options.field, grant.effect)) {
|
|
219
|
+
tracer?.denies.push(matchedOf(grant));
|
|
220
|
+
return done({
|
|
221
|
+
outcome: "denied",
|
|
222
|
+
denials: [{
|
|
223
|
+
role: grant.role,
|
|
224
|
+
reason: "opaque-condition"
|
|
225
|
+
}],
|
|
226
|
+
alternatives: []
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (!condition.matched) {
|
|
230
|
+
denials.push({
|
|
231
|
+
role: grant.role,
|
|
232
|
+
reason: condition.reason ?? "condition"
|
|
233
|
+
});
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (!grantCoversField(grant.fields, options.field, grant.effect)) {
|
|
237
|
+
skip(grant, "field");
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (grant.effect === "deny") {
|
|
241
|
+
tracer?.denies.push(matchedOf(grant));
|
|
242
|
+
return done({
|
|
243
|
+
outcome: "denied",
|
|
244
|
+
denials: [{
|
|
245
|
+
role: grant.role,
|
|
246
|
+
reason: "deny"
|
|
247
|
+
}],
|
|
248
|
+
alternatives: []
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
tracer?.allows.push(matchedOf(grant));
|
|
252
|
+
allows.push(grant);
|
|
253
|
+
}
|
|
254
|
+
const [matched] = allows;
|
|
255
|
+
if (matched === void 0) {
|
|
256
|
+
for (const entry of snapshot.notEntitled ?? []) if (entry.permission === permission.key) denials.push({
|
|
257
|
+
role: entry.role,
|
|
258
|
+
reason: "not-entitled",
|
|
259
|
+
to: entry.to
|
|
260
|
+
});
|
|
261
|
+
return done({
|
|
262
|
+
outcome: "denied",
|
|
263
|
+
denials: denials.length > 0 ? denials : [{
|
|
264
|
+
role: null,
|
|
265
|
+
reason: subject.principal === null ? "anonymous" : "no-grant"
|
|
266
|
+
}],
|
|
267
|
+
alternatives: []
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (snapshot.delegated !== void 0 && !snapshot.delegated.includes(permission.key)) return done({
|
|
271
|
+
outcome: "denied",
|
|
272
|
+
denials: [{
|
|
273
|
+
role: null,
|
|
274
|
+
reason: "not-delegated"
|
|
275
|
+
}],
|
|
276
|
+
alternatives: []
|
|
277
|
+
});
|
|
278
|
+
const miss = coveredByDelegation(permission, subject.delegation, resourceIdOf(current), subject.actor !== void 0 && snapshot.delegated === void 0);
|
|
279
|
+
if (miss !== void 0) return done({
|
|
280
|
+
outcome: "denied",
|
|
281
|
+
denials: [{
|
|
282
|
+
role: null,
|
|
283
|
+
reason: miss
|
|
284
|
+
}],
|
|
285
|
+
alternatives: []
|
|
286
|
+
});
|
|
287
|
+
const resourceId = permission.kind === "collection" ? "*" : rowId(current);
|
|
288
|
+
const token = decisionToken({
|
|
289
|
+
key: permission.key,
|
|
290
|
+
resourceId,
|
|
291
|
+
principal: subject.principal,
|
|
292
|
+
actor: subject.actor,
|
|
293
|
+
fingerprint: `snapshot:${String(snapshot.issuedAt)}`,
|
|
294
|
+
payload: resourceId === "*" && (next ?? current) !== void 0 ? payloadDigest(next ?? current) : void 0
|
|
295
|
+
});
|
|
296
|
+
const grant = matchedOf(matched);
|
|
297
|
+
if (requiresApproval(matched.approval)) return done({
|
|
298
|
+
outcome: "approval-required",
|
|
299
|
+
grant,
|
|
300
|
+
reason: "human",
|
|
301
|
+
token
|
|
302
|
+
});
|
|
303
|
+
return done({
|
|
304
|
+
outcome: "granted",
|
|
305
|
+
subject,
|
|
306
|
+
matched: grant,
|
|
307
|
+
token
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function whereFromSnapshot(snapshot, subject, permission, team) {
|
|
311
|
+
return whereFromGrants(snapshot.grants.filter((grant) => grant.permission === permission.key), {
|
|
312
|
+
resource: permission.resource,
|
|
313
|
+
scopes: scopeList(snapshot.scopes),
|
|
314
|
+
partitioned: (name) => snapshot.scopes?.find((entry) => entry.name === name)?.resources?.includes(permission.resource) === true,
|
|
315
|
+
tenant: subject.principal?.tenant,
|
|
316
|
+
team,
|
|
317
|
+
now: nowSeconds(),
|
|
318
|
+
subject
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/core/snapshot-subject.ts
|
|
323
|
+
function subjectFromSnapshot(snapshot, tenant) {
|
|
324
|
+
const principal = snapshot.subject.principal;
|
|
325
|
+
const nextTenant = principal === null ? void 0 : tenant === void 0 ? principal.tenant : resolveActiveTenant(compact({
|
|
326
|
+
...principal,
|
|
327
|
+
memberships: principal.memberships ?? []
|
|
328
|
+
}), tenant, scopeList(snapshot.scopes));
|
|
329
|
+
return freezeDeep(compact({
|
|
330
|
+
principal: principal === null ? null : compact({
|
|
331
|
+
...principal,
|
|
332
|
+
tenant: nextTenant
|
|
333
|
+
}),
|
|
334
|
+
delegation: snapshot.subject.delegation,
|
|
335
|
+
context: snapshot.subject.context,
|
|
336
|
+
expiresAt: snapshot.expiresAt
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Role names held in `tenant`, or only on memberships of one `scope` (and
|
|
341
|
+
* instance `id`), ordered like `rank` (the snapshot's ranked `roles`).
|
|
342
|
+
*/
|
|
343
|
+
function heldRoleNames(subject, tenant, scopes, only, now) {
|
|
344
|
+
const scope = only?.scope === void 0 ? void 0 : resolveScope(scopes, only.scope);
|
|
345
|
+
if (only?.scope !== void 0 && scope === void 0) return [];
|
|
346
|
+
const names = new Set(scope === void 0 ? subject.principal?.roles ?? [] : []);
|
|
347
|
+
for (const membership of subject.principal?.memberships ?? []) {
|
|
348
|
+
if (isMembershipExpired(membership, now)) continue;
|
|
349
|
+
if (!(scope === void 0 ? tenantOf(membership, scopes) === tenant : membership.scope === scope && (only?.id === void 0 || membership.id === only.id))) continue;
|
|
350
|
+
for (const role of membership.roles) names.add(role);
|
|
351
|
+
}
|
|
352
|
+
const rank = only?.rank ?? [];
|
|
353
|
+
const position = (name) => {
|
|
354
|
+
const index = rank.indexOf(name);
|
|
355
|
+
return index === -1 ? rank.length : index;
|
|
356
|
+
};
|
|
357
|
+
return [...names].toSorted((a, b) => position(a) - position(b));
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/core/from-snapshot.ts
|
|
361
|
+
function resourceRef(permission, data) {
|
|
362
|
+
const id = permission.kind === "collection" ? void 0 : rowId(data);
|
|
363
|
+
return id === void 0 || id === "*" ? { type: permission.resource } : {
|
|
364
|
+
type: permission.resource,
|
|
365
|
+
id
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function assignableEntry(snapshot, tenant) {
|
|
369
|
+
if (tenant === void 0) return;
|
|
370
|
+
return snapshot.assignable?.find((entry) => entry.tenant === tenant);
|
|
371
|
+
}
|
|
372
|
+
function fromSnapshot(snapshot, options = {}) {
|
|
373
|
+
const subject = subjectFromSnapshot(snapshot, options.tenant);
|
|
374
|
+
const team = options.team;
|
|
375
|
+
const run = (permission, data, decideOptions = {}) => evaluateSnapshot(snapshot, subject, permission, data, team, decideOptions);
|
|
376
|
+
const decide = ((permission, data, decideOptions = {}) => run(permission, data, decideOptions));
|
|
377
|
+
const can = ((permission, data, decideOptions) => run(permission, data, decideOptions).outcome === "granted");
|
|
378
|
+
const assert = ((permission, data, decideOptions) => {
|
|
379
|
+
const decision = run(permission, data, decideOptions);
|
|
380
|
+
if (decision.outcome === "granted") return decision;
|
|
381
|
+
if (decision.outcome === "approval-required") throw new PermDockApprovalRequiredError({
|
|
382
|
+
decision,
|
|
383
|
+
permission: permission.key,
|
|
384
|
+
scope: permission.scope,
|
|
385
|
+
resource: resourceRef(permission, data),
|
|
386
|
+
message: approvalMessage(permission.key, decision.reason, decision.token)
|
|
387
|
+
});
|
|
388
|
+
throw new PermDockDeniedError({
|
|
389
|
+
decision,
|
|
390
|
+
permission: permission.key,
|
|
391
|
+
scope: permission.scope,
|
|
392
|
+
resource: resourceRef(permission, data),
|
|
393
|
+
subject,
|
|
394
|
+
message: deniedMessage(permission.key, subject.principal?.id, decision.denials, [])
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
const explain = ((permission, data, decideOptions) => run(permission, data, {
|
|
398
|
+
...decideOptions,
|
|
399
|
+
source: decideOptions?.source ?? "explain",
|
|
400
|
+
explain: true
|
|
401
|
+
}));
|
|
402
|
+
const instance = {
|
|
403
|
+
can,
|
|
404
|
+
decide,
|
|
405
|
+
assert,
|
|
406
|
+
explain,
|
|
407
|
+
permissions: {},
|
|
408
|
+
roles: snapshot.vocabulary?.roles ?? {},
|
|
409
|
+
plans: snapshot.vocabulary?.plans ?? {},
|
|
410
|
+
filter(permission, rows, decideOptions) {
|
|
411
|
+
return rows.filter((row) => can(permission, row, decideOptions) === true);
|
|
412
|
+
},
|
|
413
|
+
pick(permission, row, decideOptions) {
|
|
414
|
+
if (row === null || typeof row !== "object") return {};
|
|
415
|
+
if (can(permission, row, decideOptions) !== true) return {};
|
|
416
|
+
return pickVisible(row, (field) => {
|
|
417
|
+
const next = compact({
|
|
418
|
+
...decideOptions,
|
|
419
|
+
field
|
|
420
|
+
});
|
|
421
|
+
return can(permission, row, next) === true;
|
|
422
|
+
});
|
|
423
|
+
},
|
|
424
|
+
where(permission) {
|
|
425
|
+
return whereFromSnapshot(snapshot, subject, permission, team);
|
|
426
|
+
},
|
|
427
|
+
actions(resource, data, decideOptions) {
|
|
428
|
+
return listPermissions(resource).filter((item) => run(item, data, decideOptions).outcome === "granted");
|
|
429
|
+
},
|
|
430
|
+
simulate: ((input, simulateOptions) => {
|
|
431
|
+
if (Array.isArray(input)) return input.map(([permission, data]) => run(permission, data, compact({ now: simulateOptions?.now })));
|
|
432
|
+
if (isArazzoSimulateInput(input)) return simulateArazzo(input, input.permissions, (permission, data) => run(permission, data));
|
|
433
|
+
const preview = input;
|
|
434
|
+
const previewRoles = preview.roles?.map((item) => typeof item === "string" ? item : item.key);
|
|
435
|
+
return fromSnapshot(freezeDeep({
|
|
436
|
+
...snapshot,
|
|
437
|
+
simulated: true,
|
|
438
|
+
subject: {
|
|
439
|
+
...snapshot.subject,
|
|
440
|
+
principal: snapshot.subject.principal === null ? null : compact({
|
|
441
|
+
...snapshot.subject.principal,
|
|
442
|
+
roles: previewRoles ?? snapshot.subject.principal.roles,
|
|
443
|
+
memberships: preview.memberships === void 0 ? snapshot.subject.principal.memberships : normalizeMemberships(preview.memberships, scopeList(snapshot.scopes)),
|
|
444
|
+
tenant: preview.tenant ?? snapshot.subject.principal.tenant
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
}), options);
|
|
448
|
+
}),
|
|
449
|
+
snapshot() {
|
|
450
|
+
return snapshot;
|
|
451
|
+
},
|
|
452
|
+
on() {
|
|
453
|
+
return () => void 0;
|
|
454
|
+
},
|
|
455
|
+
tenant(id) {
|
|
456
|
+
return fromSnapshot(snapshot, compact({
|
|
457
|
+
tenant: id,
|
|
458
|
+
team
|
|
459
|
+
}));
|
|
460
|
+
},
|
|
461
|
+
team(id) {
|
|
462
|
+
return fromSnapshot(snapshot, compact({
|
|
463
|
+
tenant: options.tenant,
|
|
464
|
+
team: id
|
|
465
|
+
}));
|
|
466
|
+
},
|
|
467
|
+
memberships() {
|
|
468
|
+
return subject.principal?.memberships ?? [];
|
|
469
|
+
},
|
|
470
|
+
tenants() {
|
|
471
|
+
return snapshot.tenants;
|
|
472
|
+
},
|
|
473
|
+
heldRoles(query) {
|
|
474
|
+
const names = heldRoleNames(subject, query?.tenant ?? subject.principal?.tenant, scopeList(snapshot.scopes), compact({
|
|
475
|
+
scope: query?.scope,
|
|
476
|
+
id: query?.id,
|
|
477
|
+
rank: snapshot.roles
|
|
478
|
+
}));
|
|
479
|
+
const tree = snapshot.vocabulary?.roles;
|
|
480
|
+
return names.map((name) => findRole(tree, name) ?? synthesiseRole(name));
|
|
481
|
+
},
|
|
482
|
+
audiences() {
|
|
483
|
+
const tenant = subject.principal?.tenant;
|
|
484
|
+
if (tenant === snapshot.subject.principal?.tenant) return snapshot.audiences ?? [];
|
|
485
|
+
const tree = snapshot.vocabulary?.roles;
|
|
486
|
+
const out = [];
|
|
487
|
+
for (const name of heldRoleNames(subject, tenant, scopeList(snapshot.scopes), { rank: snapshot.roles })) {
|
|
488
|
+
const audience = findRole(tree, name)?.meta.audience;
|
|
489
|
+
if (typeof audience === "string" && !out.includes(audience)) out.push(audience);
|
|
490
|
+
}
|
|
491
|
+
return out;
|
|
492
|
+
},
|
|
493
|
+
loadRelations() {
|
|
494
|
+
return Promise.resolve();
|
|
495
|
+
},
|
|
496
|
+
whoCan(permission) {
|
|
497
|
+
return Promise.resolve(freezeDeep({
|
|
498
|
+
permission: permission.key,
|
|
499
|
+
holders: [],
|
|
500
|
+
complete: false
|
|
501
|
+
}));
|
|
502
|
+
},
|
|
503
|
+
decideRoleChange(change) {
|
|
504
|
+
return freezeDeep({
|
|
505
|
+
outcome: "denied",
|
|
506
|
+
change,
|
|
507
|
+
denials: [{
|
|
508
|
+
role: null,
|
|
509
|
+
reason: "unsupported"
|
|
510
|
+
}]
|
|
511
|
+
});
|
|
512
|
+
},
|
|
513
|
+
activate() {
|
|
514
|
+
return freezeDeep({
|
|
515
|
+
outcome: "denied",
|
|
516
|
+
denials: [{
|
|
517
|
+
role: null,
|
|
518
|
+
reason: "unsupported"
|
|
519
|
+
}],
|
|
520
|
+
alternatives: []
|
|
521
|
+
});
|
|
522
|
+
},
|
|
523
|
+
assignableRoles(query) {
|
|
524
|
+
const tenant = query?.tenant ?? subject.principal?.tenant;
|
|
525
|
+
const tree = snapshot.vocabulary?.roles;
|
|
526
|
+
if (snapshot.assignable !== void 0) return (assignableEntry(snapshot, tenant)?.roles ?? []).map((name) => findRole(tree, name) ?? synthesiseRole(name, { assignable: true }));
|
|
527
|
+
const names = new Set(heldRoleNames(subject, tenant, scopeList(snapshot.scopes)));
|
|
528
|
+
return listRoles(tree).filter((leaf) => leaf.assignable && names.has(leaf.key));
|
|
529
|
+
},
|
|
530
|
+
assignablePermissions(query) {
|
|
531
|
+
if (query?.scope === "global") return [];
|
|
532
|
+
return assignableEntry(snapshot, query?.tenant ?? subject.principal?.tenant)?.permissions ?? [];
|
|
533
|
+
},
|
|
534
|
+
subject
|
|
535
|
+
};
|
|
536
|
+
return Object.freeze(instance);
|
|
537
|
+
}
|
|
538
|
+
function emptySnapshot() {
|
|
539
|
+
return freezeDeep({
|
|
540
|
+
v: 1,
|
|
541
|
+
issuedAt: 0,
|
|
542
|
+
subject: {
|
|
543
|
+
principal: null,
|
|
544
|
+
context: {}
|
|
545
|
+
},
|
|
546
|
+
roles: [],
|
|
547
|
+
grants: [],
|
|
548
|
+
tenants: []
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
export { fromSnapshot as n, emptySnapshot as t };
|