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,430 @@
|
|
|
1
|
+
import { t as compact } from "./compact-y6vfu2_f.js";
|
|
2
|
+
import { n as freezeDeep } from "./freeze-y1_jQL4v.js";
|
|
3
|
+
import { _ as assertSqlFunctionArg, g as assertPortableTwin, h as normalizeWhere, s as grantList, v as assertSqlFunctionName } from "./policy-ANp36PnI.js";
|
|
4
|
+
import { f as tenantOf, u as scopeList } from "./scopes-cKVp_WTw.js";
|
|
5
|
+
import { C as listPlans, s as flattenGrantee } from "./grantee-Bv04_Vzf.js";
|
|
6
|
+
import { l as canonicalJson } from "./snapshot-DE8dE_hz.js";
|
|
7
|
+
import { f as tenantsOf } from "./validity-D0uRmJKJ.js";
|
|
8
|
+
import { n as sha256, t as bytesToBase64Url } from "./sha256-BO0swRXL.js";
|
|
9
|
+
import { n as isThenable } from "./thenable-okc2xDsj.js";
|
|
10
|
+
import { i as snapshotOf, n as resolveSubject, o as declaredRoleNames, r as collectSnapshotGrants } from "./permdock-yoZ7EjxX.js";
|
|
11
|
+
//#region src/conditions/sql-function.ts
|
|
12
|
+
function sqlFunction(name, options) {
|
|
13
|
+
assertSqlFunctionName(name);
|
|
14
|
+
const args = options.args ?? [];
|
|
15
|
+
for (const arg of args) assertSqlFunctionArg(arg);
|
|
16
|
+
const twin = normalizeWhere(options.twin);
|
|
17
|
+
assertPortableTwin(twin);
|
|
18
|
+
return freezeDeep({
|
|
19
|
+
op: "sqlFunction",
|
|
20
|
+
name,
|
|
21
|
+
args,
|
|
22
|
+
twin
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/interfaces.ts
|
|
27
|
+
function memoryEntitlementSource(entries) {
|
|
28
|
+
return { entitlementsFor(_principal, options) {
|
|
29
|
+
return options.tenant === void 0 ? [] : [...entries[options.tenant] ?? []];
|
|
30
|
+
} };
|
|
31
|
+
}
|
|
32
|
+
function memorySettings(settings) {
|
|
33
|
+
const byTenant = new Map(Object.entries(settings));
|
|
34
|
+
return Object.freeze({ settingsFor(tenant) {
|
|
35
|
+
return byTenant.get(tenant);
|
|
36
|
+
} });
|
|
37
|
+
}
|
|
38
|
+
function memoryRoleSource(customRoles) {
|
|
39
|
+
const byTenant = /* @__PURE__ */ new Map();
|
|
40
|
+
const global = [];
|
|
41
|
+
for (const role of customRoles) {
|
|
42
|
+
if (role.tenant === void 0) {
|
|
43
|
+
global.push(role);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const list = byTenant.get(role.tenant) ?? [];
|
|
47
|
+
list.push(role);
|
|
48
|
+
byTenant.set(role.tenant, list);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
rolesFor(tenant) {
|
|
52
|
+
return byTenant.get(tenant) ?? [];
|
|
53
|
+
},
|
|
54
|
+
globalRoles() {
|
|
55
|
+
return global;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/core/stripe-entitlements.ts
|
|
61
|
+
const PAGE = 100;
|
|
62
|
+
const MAX_PAGES = 10;
|
|
63
|
+
/**
|
|
64
|
+
* Plan names from Stripe Entitlements: the `lookup_key` of every active
|
|
65
|
+
* entitlement of the tenant's Stripe customer. `customer` maps the active
|
|
66
|
+
* tenant to its customer id; no tenant or no customer means no entitlements.
|
|
67
|
+
* Pass it as `entitlements`, and grant with `plan('<lookup_key>')`.
|
|
68
|
+
*/
|
|
69
|
+
function fromStripeEntitlements(options) {
|
|
70
|
+
return { async entitlementsFor(principal, query) {
|
|
71
|
+
if (query.tenant === void 0) return [];
|
|
72
|
+
const customer = await options.customer(query.tenant, principal);
|
|
73
|
+
if (customer === void 0 || customer === "") return [];
|
|
74
|
+
const keys = /* @__PURE__ */ new Set();
|
|
75
|
+
let after;
|
|
76
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
77
|
+
const result = await options.stripe.entitlements.activeEntitlements.list(after === void 0 ? {
|
|
78
|
+
customer,
|
|
79
|
+
limit: PAGE
|
|
80
|
+
} : {
|
|
81
|
+
customer,
|
|
82
|
+
limit: PAGE,
|
|
83
|
+
starting_after: after
|
|
84
|
+
});
|
|
85
|
+
for (const item of result.data) if (typeof item.lookup_key === "string" && item.lookup_key !== "") keys.add(item.lookup_key);
|
|
86
|
+
const last = result.data.at(-1);
|
|
87
|
+
if (!result.has_more || last === void 0) break;
|
|
88
|
+
after = last.id;
|
|
89
|
+
}
|
|
90
|
+
return [...keys].toSorted();
|
|
91
|
+
} };
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/core/may-access.ts
|
|
95
|
+
function policyPlans(policy) {
|
|
96
|
+
const names = new Set(listPlans(policy.vocabulary?.plans).map((p) => p.key));
|
|
97
|
+
for (const grant of grantList(policy)) for (const item of flattenGrantee(grant.to)) if (item.kind === "plan") names.add(item.plan);
|
|
98
|
+
return [...names];
|
|
99
|
+
}
|
|
100
|
+
function heldRoleNames(principal) {
|
|
101
|
+
return [...principal.roles ?? [], ...(principal.memberships ?? []).flatMap((item) => item.roles)];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* An optimistic routing hint for a proxy or middleware, never a decision.
|
|
105
|
+
* `false` only when the subject's declared roles provably lack `permission`;
|
|
106
|
+
* `true` whenever custom roles, plans, memberships the claims do not carry or
|
|
107
|
+
* row conditions could still grant it. Synchronous, no network, never throws.
|
|
108
|
+
* Pages, Server Actions and RLS remain the enforcement points.
|
|
109
|
+
*/
|
|
110
|
+
function mayAccess(policy, user, permission, options = {}) {
|
|
111
|
+
try {
|
|
112
|
+
const resolved = resolveSubject(policy, user, compact({ tenant: options.tenant }), []);
|
|
113
|
+
if (isThenable(resolved)) return true;
|
|
114
|
+
const principal = resolved.principal;
|
|
115
|
+
const relevant = policy.index.grantsByKey.get(permission.key) ?? [];
|
|
116
|
+
if (principal !== null) {
|
|
117
|
+
const declared = declaredRoleNames(policy);
|
|
118
|
+
if (heldRoleNames(principal).some((name) => !declared.has(name))) return true;
|
|
119
|
+
if ((principal.memberships ?? []).length === 0 && relevant.some((grant) => grant.scope !== "global")) return true;
|
|
120
|
+
}
|
|
121
|
+
const tenant = options.tenant;
|
|
122
|
+
const subject = principal === null ? resolved : {
|
|
123
|
+
...resolved,
|
|
124
|
+
principal: {
|
|
125
|
+
...principal,
|
|
126
|
+
plans: policyPlans(policy),
|
|
127
|
+
memberships: (principal.memberships ?? []).filter((item) => {
|
|
128
|
+
const owner = tenantOf(item, scopeList(policy.scopes));
|
|
129
|
+
return tenant === void 0 || owner === void 0 || owner === tenant;
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const matched = collectSnapshotGrants(policy, subject, []).filter((item) => item.grant.permission.key === permission.key);
|
|
134
|
+
if (matched.some((item) => item.grant.effect === "deny" && item.grant.where === void 0 && item.grant.check === void 0 && item.grant.portable)) return false;
|
|
135
|
+
return matched.some((item) => item.grant.effect === "allow");
|
|
136
|
+
} catch {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/core/snapshot-for.ts
|
|
142
|
+
function withPlans(subject, plans) {
|
|
143
|
+
if (plans === void 0 || subject.principal === null) return subject;
|
|
144
|
+
return freezeDeep(compact({
|
|
145
|
+
...subject,
|
|
146
|
+
principal: compact({
|
|
147
|
+
...subject.principal,
|
|
148
|
+
plans: [...plans]
|
|
149
|
+
})
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Builds the serializable access snapshot for a subject without a request,
|
|
154
|
+
* a network call or a cache directive: call it inside the app's own
|
|
155
|
+
* `'use cache: private'` function. Synchronous; the policy's `subject` and
|
|
156
|
+
* `context` mappers must be synchronous too.
|
|
157
|
+
*/
|
|
158
|
+
function snapshotFor(policy, user, options = {}) {
|
|
159
|
+
const auth = [];
|
|
160
|
+
const memberships = options.memberships;
|
|
161
|
+
const resolved = resolveSubject(policy, user, compact({
|
|
162
|
+
tenant: options.tenant,
|
|
163
|
+
memberships: memberships === void 0 ? void 0 : { membershipsFor: () => [...memberships] }
|
|
164
|
+
}), auth);
|
|
165
|
+
if (isThenable(resolved)) throw new TypeError("PermDock: snapshotFor() needs synchronous subject and context mappers. Resolve async data first and pass it as a Subject, or use createPermDock(...).snapshot().");
|
|
166
|
+
const subject = withPlans(resolved, options.plans);
|
|
167
|
+
const tenants = new Set(tenantsOf(subject.principal, scopeList(policy.scopes)));
|
|
168
|
+
const customRoles = (options.customRoles ?? []).filter((item) => item.scope === "global" || item.tenant !== void 0 && tenants.has(item.tenant));
|
|
169
|
+
const names = options.assignable;
|
|
170
|
+
const assignable = names === void 0 ? void 0 : new Map([...tenants].map((tenant) => [tenant, Object.hasOwn(names, tenant) ? names[tenant] ?? [] : []]));
|
|
171
|
+
return snapshotOf(policy, subject, compact({
|
|
172
|
+
customRoles,
|
|
173
|
+
assignable,
|
|
174
|
+
include: options.include,
|
|
175
|
+
tenants: options.tenants,
|
|
176
|
+
now: options.now
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/core/presets.ts
|
|
181
|
+
const CRUD_ACTIONS = {
|
|
182
|
+
read: { readOnly: true },
|
|
183
|
+
update: {},
|
|
184
|
+
delete: { destructive: true }
|
|
185
|
+
};
|
|
186
|
+
const CRUD_COLLECTION = {
|
|
187
|
+
create: {},
|
|
188
|
+
list: { readOnly: true }
|
|
189
|
+
};
|
|
190
|
+
const READABLE_ACTIONS = { read: { readOnly: true } };
|
|
191
|
+
const READABLE_COLLECTION = { list: { readOnly: true } };
|
|
192
|
+
const WRITABLE_ACTIONS = {
|
|
193
|
+
read: { readOnly: true },
|
|
194
|
+
update: {}
|
|
195
|
+
};
|
|
196
|
+
const WRITABLE_COLLECTION = {};
|
|
197
|
+
function isNameList(list) {
|
|
198
|
+
return Array.isArray(list);
|
|
199
|
+
}
|
|
200
|
+
function toRecord(list) {
|
|
201
|
+
if (list === void 0) return {};
|
|
202
|
+
if (isNameList(list)) {
|
|
203
|
+
const out = {};
|
|
204
|
+
for (const name of list) out[name] = {};
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
return { ...list };
|
|
208
|
+
}
|
|
209
|
+
function mergeMeta(base, extra) {
|
|
210
|
+
return compact({
|
|
211
|
+
title: extra.title ?? base.title,
|
|
212
|
+
description: extra.description ?? base.description,
|
|
213
|
+
tags: extra.tags ?? base.tags,
|
|
214
|
+
readOnly: extra.readOnly ?? base.readOnly,
|
|
215
|
+
destructive: extra.destructive ?? base.destructive,
|
|
216
|
+
idempotent: extra.idempotent ?? base.idempotent
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function mergeActionLists(base, extra) {
|
|
220
|
+
const extraRecord = toRecord(extra);
|
|
221
|
+
const out = {};
|
|
222
|
+
for (const [name, baseMeta] of Object.entries(base)) {
|
|
223
|
+
const extraMeta = extraRecord[name];
|
|
224
|
+
out[name] = extraMeta === void 0 ? baseMeta : mergeMeta(baseMeta, extraMeta);
|
|
225
|
+
}
|
|
226
|
+
for (const [name, extraMeta] of Object.entries(extraRecord)) {
|
|
227
|
+
if (Object.hasOwn(out, name)) continue;
|
|
228
|
+
out[name] = extraMeta;
|
|
229
|
+
}
|
|
230
|
+
return freezeDeep(out);
|
|
231
|
+
}
|
|
232
|
+
function finishPreset(baseActions, baseCollection, options) {
|
|
233
|
+
const actions = mergeActionLists(baseActions, options?.actions);
|
|
234
|
+
const collection = mergeActionLists(baseCollection, options?.collection);
|
|
235
|
+
return compact({
|
|
236
|
+
id: options?.id,
|
|
237
|
+
parent: options?.parent,
|
|
238
|
+
relations: options?.relations,
|
|
239
|
+
restricted: options?.restricted,
|
|
240
|
+
disclosure: options?.disclosure,
|
|
241
|
+
actions,
|
|
242
|
+
collection: Object.keys(collection).length === 0 ? void 0 : collection
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function crud(options) {
|
|
246
|
+
return finishPreset(CRUD_ACTIONS, CRUD_COLLECTION, options);
|
|
247
|
+
}
|
|
248
|
+
function readable(options) {
|
|
249
|
+
return finishPreset(READABLE_ACTIONS, READABLE_COLLECTION, options);
|
|
250
|
+
}
|
|
251
|
+
function writable(options) {
|
|
252
|
+
return finishPreset(WRITABLE_ACTIONS, WRITABLE_COLLECTION, options);
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/core/ocsf.ts
|
|
256
|
+
/** The OCSF schema version `toOcsf` emits. */
|
|
257
|
+
const OCSF_VERSION = "1.3.0";
|
|
258
|
+
function status(outcome) {
|
|
259
|
+
switch (outcome) {
|
|
260
|
+
case "granted": return {
|
|
261
|
+
status_id: 1,
|
|
262
|
+
status: "Success"
|
|
263
|
+
};
|
|
264
|
+
case "denied": return {
|
|
265
|
+
status_id: 2,
|
|
266
|
+
status: "Failure"
|
|
267
|
+
};
|
|
268
|
+
case "approval-required": return {
|
|
269
|
+
status_id: 99,
|
|
270
|
+
status: "Other"
|
|
271
|
+
};
|
|
272
|
+
default: return unknownStatus(outcome);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/** An outcome this build does not know, from a newer producer, is reported as OCSF Unknown. */
|
|
276
|
+
function unknownStatus(_outcome) {
|
|
277
|
+
return {
|
|
278
|
+
status_id: 0,
|
|
279
|
+
status: "Unknown"
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/** Projects a decision or approval event onto OCSF Authorize Session; the event itself is unchanged. */
|
|
283
|
+
function toOcsf(event) {
|
|
284
|
+
const principal = event.subject.principal;
|
|
285
|
+
const actor = event.subject.actor;
|
|
286
|
+
const breakGlass = event.matched?.breakGlass === true;
|
|
287
|
+
const detail = event.outcome === "approval-required" ? "approval-required" : event.denials?.map((denial) => denial.reason).join(",");
|
|
288
|
+
const time = Date.parse(event.at);
|
|
289
|
+
return compact({
|
|
290
|
+
class_uid: 3003,
|
|
291
|
+
category_uid: 3,
|
|
292
|
+
activity_id: 1,
|
|
293
|
+
type_uid: 300301,
|
|
294
|
+
severity_id: breakGlass ? 4 : 1,
|
|
295
|
+
time: Number.isNaN(time) ? 0 : time,
|
|
296
|
+
...status(event.outcome),
|
|
297
|
+
status_detail: detail === "" ? void 0 : detail,
|
|
298
|
+
message: `${event.permission} ${event.outcome}`,
|
|
299
|
+
privileges: [event.permission],
|
|
300
|
+
user: principal === null ? { name: "anonymous" } : { uid: principal.id },
|
|
301
|
+
actor: actor === void 0 ? void 0 : compact({
|
|
302
|
+
user: principal === null ? void 0 : { uid: principal.id },
|
|
303
|
+
app_name: actor.id
|
|
304
|
+
}),
|
|
305
|
+
metadata: compact({
|
|
306
|
+
version: OCSF_VERSION,
|
|
307
|
+
product: compact({
|
|
308
|
+
name: "PermDock",
|
|
309
|
+
vendor_name: "PermDock",
|
|
310
|
+
feature: event.adapter === void 0 ? void 0 : { name: event.adapter }
|
|
311
|
+
}),
|
|
312
|
+
tenant_uid: event.tenant,
|
|
313
|
+
correlation_uid: event.token
|
|
314
|
+
}),
|
|
315
|
+
unmapped: compact({
|
|
316
|
+
outcome: event.outcome,
|
|
317
|
+
scope: event.scope,
|
|
318
|
+
resource: event.resource,
|
|
319
|
+
source: event.source,
|
|
320
|
+
phase: event.phase,
|
|
321
|
+
role: event.matched?.role,
|
|
322
|
+
via: event.via,
|
|
323
|
+
breakGlass: breakGlass ? true : void 0,
|
|
324
|
+
purpose: event.purpose,
|
|
325
|
+
reason: event.reason
|
|
326
|
+
})
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function accessToOcsf(event) {
|
|
330
|
+
const time = Date.parse(event.at);
|
|
331
|
+
const enable = event.operation === "started";
|
|
332
|
+
return compact({
|
|
333
|
+
class_uid: 3001,
|
|
334
|
+
category_uid: 3,
|
|
335
|
+
activity_id: enable ? 2 : 5,
|
|
336
|
+
type_uid: enable ? 300102 : 300105,
|
|
337
|
+
severity_id: 4,
|
|
338
|
+
time: Number.isNaN(time) ? 0 : time,
|
|
339
|
+
message: `support access ${event.operation}`,
|
|
340
|
+
user: { uid: event.principal.id },
|
|
341
|
+
actor: event.actor === void 0 ? void 0 : { user: { uid: event.actor.id } },
|
|
342
|
+
metadata: {
|
|
343
|
+
version: OCSF_VERSION,
|
|
344
|
+
product: {
|
|
345
|
+
name: "PermDock",
|
|
346
|
+
vendor_name: "PermDock"
|
|
347
|
+
},
|
|
348
|
+
tenant_uid: event.tenant
|
|
349
|
+
},
|
|
350
|
+
unmapped: compact({
|
|
351
|
+
operation: event.operation,
|
|
352
|
+
via: event.via,
|
|
353
|
+
roles: event.roles,
|
|
354
|
+
member: event.member,
|
|
355
|
+
grantedBy: event.grantedBy,
|
|
356
|
+
reason: event.reason
|
|
357
|
+
})
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/core/csv.ts
|
|
362
|
+
/** The CSV export columns, in order; the header row of every CSV file. */
|
|
363
|
+
const CSV_COLUMNS = Object.freeze([
|
|
364
|
+
"time",
|
|
365
|
+
"principal",
|
|
366
|
+
"actor",
|
|
367
|
+
"tenant",
|
|
368
|
+
"permission",
|
|
369
|
+
"outcome",
|
|
370
|
+
"matched.role",
|
|
371
|
+
"via",
|
|
372
|
+
"denials.reason",
|
|
373
|
+
"token"
|
|
374
|
+
]);
|
|
375
|
+
function field(value) {
|
|
376
|
+
const text = value ?? "";
|
|
377
|
+
return /[",\r\n]/u.test(text) ? `"${text.replaceAll("\"", "\"\"")}"` : text;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* One RFC 4180 row for a decision or approval event, without a line
|
|
381
|
+
* terminator; join rows with CRLF under a `CSV_COLUMNS` header.
|
|
382
|
+
*/
|
|
383
|
+
function toCsvRow(event) {
|
|
384
|
+
return [
|
|
385
|
+
event.at,
|
|
386
|
+
event.subject.principal?.id,
|
|
387
|
+
event.subject.actor?.id,
|
|
388
|
+
event.tenant,
|
|
389
|
+
event.permission,
|
|
390
|
+
event.outcome,
|
|
391
|
+
event.matched?.role,
|
|
392
|
+
event.via,
|
|
393
|
+
event.denials?.map((denial) => denial.reason).join(";"),
|
|
394
|
+
event.token
|
|
395
|
+
].map(field).join(",");
|
|
396
|
+
}
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/core/catalog-fingerprint.ts
|
|
399
|
+
const OMITTED_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
400
|
+
"generatedAt",
|
|
401
|
+
"generator",
|
|
402
|
+
"fingerprint"
|
|
403
|
+
]);
|
|
404
|
+
function isRecord(value) {
|
|
405
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
406
|
+
}
|
|
407
|
+
function fingerprintInput(catalog) {
|
|
408
|
+
const out = {};
|
|
409
|
+
for (const [key, value] of Object.entries(catalog)) {
|
|
410
|
+
if (OMITTED_TOP_LEVEL.has(key)) continue;
|
|
411
|
+
out[key] = key === "permissions" && Array.isArray(value) ? value.map((permission) => {
|
|
412
|
+
if (!isRecord(permission)) return permission;
|
|
413
|
+
const { usages: _usages, ...rest } = permission;
|
|
414
|
+
return rest;
|
|
415
|
+
}) : value;
|
|
416
|
+
}
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* The catalog v1 fingerprint: base64url SHA-256 of canonical JSON (keys
|
|
421
|
+
* sorted, no whitespace) without `generatedAt`, `generator`, `fingerprint`
|
|
422
|
+
* and every `permissions[].usages`, so neither the CLI version, the clock nor
|
|
423
|
+
* call sites change it.
|
|
424
|
+
*/
|
|
425
|
+
function catalogFingerprint(catalog) {
|
|
426
|
+
if (!isRecord(catalog)) throw new TypeError("PermDock: a catalog must be an object");
|
|
427
|
+
return bytesToBase64Url(sha256(canonicalJson(fingerprintInput(catalog))));
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
export { accessToOcsf as a, readable as c, mayAccess as d, fromStripeEntitlements as f, sqlFunction as g, memorySettings as h, OCSF_VERSION as i, writable as l, memoryRoleSource as m, CSV_COLUMNS as n, toOcsf as o, memoryEntitlementSource as p, toCsvRow as r, crud as s, catalogFingerprint as t, snapshotFor as u };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as ReplayStore, c as SsfEventHandler, d as SsfOnEvent, f as SsfPermDock, g as SsfSubjectMapper, h as SsfSubject, i as PollResult, l as SsfEventInput, m as SsfReceiver, n as PollHandle, o as SetSubject, p as SsfPermDockOptions, r as PollOptions, s as SsfAuditEvent, t as CaepEventName, u as SsfEventListener } from "../types-i4BAOvdb.js";
|
|
2
|
+
import { n as createPermDock, t as memoryReplayStore } from "../index-fG6NSXlc.js";
|
|
3
|
+
export { type CaepEventName, type PollHandle, type PollOptions, type PollResult, type ReplayStore, type SetSubject, type SsfAuditEvent, type SsfEventHandler, type SsfEventInput, type SsfEventListener, type SsfOnEvent, type SsfPermDock, type SsfPermDockOptions, type SsfReceiver, type SsfSubject, type SsfSubjectMapper, createPermDock, memoryReplayStore };
|