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,280 @@
|
|
|
1
|
+
import { t as compact } from "../compact-y6vfu2_f.js";
|
|
2
|
+
import { n as freezeDeep } from "../freeze-y1_jQL4v.js";
|
|
3
|
+
import { t as ignoreRejection } from "../thenable-okc2xDsj.js";
|
|
4
|
+
import { t as anonymousSubject } from "../subject-C6dLxqHU.js";
|
|
5
|
+
//#region src/clerk/subject.ts
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function asRoles(value) {
|
|
10
|
+
if (typeof value === "string") return value === "" ? [] : [value];
|
|
11
|
+
if (!Array.isArray(value)) return [];
|
|
12
|
+
return value.filter((item) => typeof item === "string");
|
|
13
|
+
}
|
|
14
|
+
function readPath(record, path) {
|
|
15
|
+
let current = record;
|
|
16
|
+
for (const part of path.split(".")) {
|
|
17
|
+
if (!isRecord(current) || !Object.hasOwn(current, part)) return;
|
|
18
|
+
current = current[part];
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
function validateClaims(extra, schema) {
|
|
23
|
+
const result = schema["~standard"].validate(extra);
|
|
24
|
+
if (result instanceof Promise) {
|
|
25
|
+
ignoreRejection(result);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if ("issues" in result && result.issues !== void 0) return;
|
|
29
|
+
const value = result.value;
|
|
30
|
+
return isRecord(value) ? value : void 0;
|
|
31
|
+
}
|
|
32
|
+
const REGISTERED_CLAIMS = /* @__PURE__ */ new Set([
|
|
33
|
+
"iss",
|
|
34
|
+
"sub",
|
|
35
|
+
"aud",
|
|
36
|
+
"exp",
|
|
37
|
+
"nbf",
|
|
38
|
+
"iat",
|
|
39
|
+
"jti",
|
|
40
|
+
"sid",
|
|
41
|
+
"org_id",
|
|
42
|
+
"org_role",
|
|
43
|
+
"org_permissions",
|
|
44
|
+
"org_slug",
|
|
45
|
+
"pla",
|
|
46
|
+
"fea",
|
|
47
|
+
"o",
|
|
48
|
+
"v"
|
|
49
|
+
]);
|
|
50
|
+
function extraClaims(claims) {
|
|
51
|
+
const extra = {};
|
|
52
|
+
for (const [key, value] of Object.entries(claims)) {
|
|
53
|
+
if (REGISTERED_CLAIMS.has(key) || key === "unsafeMetadata") continue;
|
|
54
|
+
extra[key] = value;
|
|
55
|
+
}
|
|
56
|
+
return extra;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Plan slugs from `pla`, split by owner: `o:` plans belong to the session's
|
|
60
|
+
* organization, everything else (`u:` and unprefixed) to the user.
|
|
61
|
+
*/
|
|
62
|
+
function planSlugs(pla) {
|
|
63
|
+
const org = [];
|
|
64
|
+
const user = [];
|
|
65
|
+
if (typeof pla !== "string" || pla === "") return {
|
|
66
|
+
org,
|
|
67
|
+
user
|
|
68
|
+
};
|
|
69
|
+
for (const raw of pla.split(",")) {
|
|
70
|
+
const token = raw.trim();
|
|
71
|
+
if (token === "") continue;
|
|
72
|
+
const prefixed = /^([ou]):(.+)$/u.exec(token);
|
|
73
|
+
const slug = prefixed?.[2] ?? token;
|
|
74
|
+
if (slug !== "") (prefixed?.[1] === "o" ? org : user).push(slug);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
org,
|
|
78
|
+
user
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function featureRoles(fea, map) {
|
|
82
|
+
if (map === void 0 || typeof fea !== "string" || fea === "") return {
|
|
83
|
+
org: [],
|
|
84
|
+
user: [],
|
|
85
|
+
sources: {}
|
|
86
|
+
};
|
|
87
|
+
const org = [];
|
|
88
|
+
const user = [];
|
|
89
|
+
const sources = {};
|
|
90
|
+
for (const raw of fea.split(",")) {
|
|
91
|
+
const token = raw.trim();
|
|
92
|
+
if (token === "") continue;
|
|
93
|
+
const prefixed = /^([ou]):(.+)$/u.exec(token);
|
|
94
|
+
const slug = prefixed?.[2] ?? token;
|
|
95
|
+
const source = prefixed?.[1] === "o" || prefixed?.[1] === "u" ? prefixed[1] : void 0;
|
|
96
|
+
const role = map[slug];
|
|
97
|
+
if (role === void 0) continue;
|
|
98
|
+
(source === "o" ? org : user).push(role);
|
|
99
|
+
if (source !== void 0) sources[role] = source;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
org,
|
|
103
|
+
user,
|
|
104
|
+
sources
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function globalRolesFrom(claims, option) {
|
|
108
|
+
if (option === void 0) return [];
|
|
109
|
+
if (typeof option === "function") try {
|
|
110
|
+
return asRoles(option(claims));
|
|
111
|
+
} catch {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
return asRoles(readPath(claims, option));
|
|
115
|
+
}
|
|
116
|
+
function splitList(value) {
|
|
117
|
+
return typeof value === "string" ? value.split(",").map((item) => item.trim()).filter((item) => item !== "") : [];
|
|
118
|
+
}
|
|
119
|
+
function orgFeatures(fea) {
|
|
120
|
+
return splitList(fea).map((token) => /^o:(.+)$/u.exec(token)?.[1]).filter((feature) => feature !== void 0);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Session token v2 carries the organization as `o: { id, rol, per, fpm }`:
|
|
124
|
+
* `fpm` holds one bitmask per `o:` feature in `fea`, bit `i` selecting
|
|
125
|
+
* `per[i]`, so a permission key is `org:<feature>:<per[i]>`.
|
|
126
|
+
*/
|
|
127
|
+
function orgClaimsV2(claims) {
|
|
128
|
+
const org = claims["o"];
|
|
129
|
+
if (!isRecord(org) || typeof org["id"] !== "string" || org["id"] === "") return;
|
|
130
|
+
const role = typeof org["rol"] === "string" && org["rol"] !== "" ? org["rol"].startsWith("org:") ? org["rol"] : `org:${org["rol"]}` : void 0;
|
|
131
|
+
const actions = splitList(org["per"]);
|
|
132
|
+
const features = orgFeatures(claims["fea"]);
|
|
133
|
+
const masks = splitList(org["fpm"]).map(Number);
|
|
134
|
+
const orgPermissions = [];
|
|
135
|
+
for (const [index, feature] of features.entries()) {
|
|
136
|
+
const mask = masks[index];
|
|
137
|
+
if (mask === void 0 || !Number.isSafeInteger(mask) || mask < 0) continue;
|
|
138
|
+
for (const [bit, action] of actions.entries()) if (bit < 31 && (mask & 1 << bit) !== 0) orgPermissions.push(`org:${feature}:${action}`);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
tenant: org["id"],
|
|
142
|
+
orgRole: role,
|
|
143
|
+
orgPermissions
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function orgClaimsV1(claims) {
|
|
147
|
+
return {
|
|
148
|
+
tenant: typeof claims["org_id"] === "string" ? claims["org_id"] : void 0,
|
|
149
|
+
orgRole: typeof claims["org_role"] === "string" ? claims["org_role"] : void 0,
|
|
150
|
+
orgPermissions: asRoles(claims["org_permissions"])
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function orgClaims(claims) {
|
|
154
|
+
return orgClaimsV2(claims) ?? orgClaimsV1(claims);
|
|
155
|
+
}
|
|
156
|
+
function isAuthObject(value) {
|
|
157
|
+
if (!isRecord(value)) return false;
|
|
158
|
+
return typeof value["has"] === "function" || isRecord(value["sessionClaims"]);
|
|
159
|
+
}
|
|
160
|
+
function isVerifiedPayload(value) {
|
|
161
|
+
if (!isRecord(value)) return false;
|
|
162
|
+
if (typeof value["sub"] !== "string" || value["sub"] === "") return false;
|
|
163
|
+
return typeof value["sid"] === "string" || typeof value["azp"] === "string" || typeof value["org_id"] === "string" || orgClaimsV2(value) !== void 0;
|
|
164
|
+
}
|
|
165
|
+
function fromAuthObject(auth) {
|
|
166
|
+
const claims = isRecord(auth.sessionClaims) ? { ...auth.sessionClaims } : {};
|
|
167
|
+
const fromClaims = orgClaims(claims);
|
|
168
|
+
return {
|
|
169
|
+
id: typeof auth.userId === "string" ? auth.userId : typeof claims["sub"] === "string" ? claims["sub"] : void 0,
|
|
170
|
+
tenant: typeof auth.orgId === "string" ? auth.orgId : fromClaims.tenant,
|
|
171
|
+
orgRole: typeof auth.orgRole === "string" ? auth.orgRole : fromClaims.orgRole,
|
|
172
|
+
orgPermissions: auth.orgPermissions !== void 0 && auth.orgPermissions !== null ? asRoles(auth.orgPermissions) : fromClaims.orgPermissions,
|
|
173
|
+
claims,
|
|
174
|
+
session: typeof auth.sessionId === "string" ? auth.sessionId : typeof claims["sid"] === "string" ? claims["sid"] : void 0
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function fromPayload(claims) {
|
|
178
|
+
return {
|
|
179
|
+
id: typeof claims["sub"] === "string" ? claims["sub"] : void 0,
|
|
180
|
+
...orgClaims(claims),
|
|
181
|
+
claims,
|
|
182
|
+
session: typeof claims["sid"] === "string" ? claims["sid"] : void 0
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const MEMBERSHIP_PAGE = 100;
|
|
186
|
+
const MEMBERSHIP_PAGES = 50;
|
|
187
|
+
function membershipRow(item, userId) {
|
|
188
|
+
if (!isRecord(item)) return;
|
|
189
|
+
const owner = isRecord(item["publicUserData"]) ? item["publicUserData"]["userId"] : void 0;
|
|
190
|
+
if (typeof owner === "string" && owner !== userId) return;
|
|
191
|
+
const organization = isRecord(item["organization"]) ? item["organization"] : void 0;
|
|
192
|
+
const tenant = typeof item["organizationId"] === "string" ? item["organizationId"] : typeof organization?.["id"] === "string" ? organization["id"] : void 0;
|
|
193
|
+
const roles = asRoles(item["role"]);
|
|
194
|
+
if (tenant === void 0 || roles.length === 0) return;
|
|
195
|
+
return compact({
|
|
196
|
+
tenant,
|
|
197
|
+
roles
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
async function extraMemberships(backend, userId) {
|
|
201
|
+
const list = backend?.users?.getOrganizationMembershipList;
|
|
202
|
+
if (list === void 0) return [];
|
|
203
|
+
try {
|
|
204
|
+
const out = [];
|
|
205
|
+
for (let page = 0; page < MEMBERSHIP_PAGES; page += 1) {
|
|
206
|
+
const offset = page * MEMBERSHIP_PAGE;
|
|
207
|
+
const raw = await list({
|
|
208
|
+
userId,
|
|
209
|
+
limit: MEMBERSHIP_PAGE,
|
|
210
|
+
offset
|
|
211
|
+
});
|
|
212
|
+
const rows = Array.isArray(raw) ? raw : isRecord(raw) && Array.isArray(raw.data) ? raw.data : [];
|
|
213
|
+
for (const item of rows) {
|
|
214
|
+
const row = membershipRow(item, userId);
|
|
215
|
+
if (row !== void 0) out.push(row);
|
|
216
|
+
}
|
|
217
|
+
const total = isRecord(raw) && typeof raw.totalCount === "number" ? raw.totalCount : void 0;
|
|
218
|
+
if (rows.length < MEMBERSHIP_PAGE || total !== void 0 && offset + rows.length >= total) break;
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
} catch {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function subjectFromClerk(authObject, options = {}) {
|
|
226
|
+
try {
|
|
227
|
+
const trustedObject = isAuthObject(authObject);
|
|
228
|
+
const trustedPayload = isVerifiedPayload(authObject);
|
|
229
|
+
if (!trustedObject && !trustedPayload) return anonymousSubject();
|
|
230
|
+
const mapped = trustedObject ? fromAuthObject(authObject) : fromPayload(authObject);
|
|
231
|
+
if (mapped.id === void 0 || mapped.id === "") return anonymousSubject();
|
|
232
|
+
const declared = options.declared;
|
|
233
|
+
const orgRole = mapped.orgRole !== void 0 && (declared === void 0 || declared.includes(mapped.orgRole)) ? mapped.orgRole : void 0;
|
|
234
|
+
const permissionRoles = Object.keys(options.permissions ?? {}).filter((key) => mapped.orgPermissions.includes(key));
|
|
235
|
+
const features = featureRoles(mapped.claims["fea"], options.features);
|
|
236
|
+
const plans = planSlugs(mapped.claims["pla"]);
|
|
237
|
+
const membershipRoles = [
|
|
238
|
+
...orgRole === void 0 ? [] : [orgRole],
|
|
239
|
+
...permissionRoles,
|
|
240
|
+
...features.org
|
|
241
|
+
];
|
|
242
|
+
const sessionMembership = mapped.tenant !== void 0 && (membershipRoles.length > 0 || plans.org.length > 0) ? [compact({
|
|
243
|
+
tenant: mapped.tenant,
|
|
244
|
+
roles: membershipRoles,
|
|
245
|
+
entitlements: plans.org.length === 0 ? void 0 : plans.org
|
|
246
|
+
})] : [];
|
|
247
|
+
const loaded = options.memberships === "all" ? await extraMemberships(options.backend, mapped.id) : [];
|
|
248
|
+
const seen = new Set(sessionMembership.map((item) => item.tenant));
|
|
249
|
+
const memberships = [...sessionMembership, ...loaded.filter((item) => {
|
|
250
|
+
if (seen.has(item.tenant)) return false;
|
|
251
|
+
seen.add(item.tenant);
|
|
252
|
+
return true;
|
|
253
|
+
})];
|
|
254
|
+
let claims = extraClaims(mapped.claims);
|
|
255
|
+
if (options.schema !== void 0) claims = validateClaims(claims, options.schema) ?? {};
|
|
256
|
+
const global = [...globalRolesFrom(mapped.claims, options.globalRoles), ...features.user];
|
|
257
|
+
const exp = mapped.claims["exp"];
|
|
258
|
+
const principal = compact({
|
|
259
|
+
id: mapped.id,
|
|
260
|
+
kind: "user",
|
|
261
|
+
tenant: mapped.tenant,
|
|
262
|
+
roles: global,
|
|
263
|
+
plans: plans.user.length === 0 ? void 0 : plans.user,
|
|
264
|
+
memberships,
|
|
265
|
+
clerkPermissions: mapped.orgPermissions,
|
|
266
|
+
claims: Object.keys(claims).length === 0 ? void 0 : claims,
|
|
267
|
+
featureSources: Object.keys(features.sources).length === 0 ? void 0 : features.sources
|
|
268
|
+
});
|
|
269
|
+
return freezeDeep(compact({
|
|
270
|
+
principal,
|
|
271
|
+
context: {},
|
|
272
|
+
session: mapped.session,
|
|
273
|
+
expiresAt: typeof exp === "number" ? exp : void 0
|
|
274
|
+
}));
|
|
275
|
+
} catch {
|
|
276
|
+
return anonymousSubject();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
export { subjectFromClerk };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as run } from "../run-CJ6UvS3a.js";
|
|
3
|
+
import { n as streamHasColors } from "../style-CTm1AXDT.js";
|
|
4
|
+
//#region src/cli/bin.ts
|
|
5
|
+
const result = await run(process.argv.slice(2), {
|
|
6
|
+
cwd: process.cwd(),
|
|
7
|
+
io: {
|
|
8
|
+
env: process.env,
|
|
9
|
+
stdout: (text) => {
|
|
10
|
+
process.stdout.write(text.endsWith("\n") ? text : `${text}\n`);
|
|
11
|
+
},
|
|
12
|
+
stderr: (text) => {
|
|
13
|
+
process.stderr.write(text.endsWith("\n") ? text : `${text}\n`);
|
|
14
|
+
},
|
|
15
|
+
color: streamHasColors(process.stdout),
|
|
16
|
+
interactive: process.stdin.isTTY === true && process.stdout.isTTY === true && process.env["CI"] === void 0
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
process.exitCode ??= result.code;
|
|
20
|
+
//#endregion
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { a as CatalogDocument, c as CatalogResource, d as CatalogSupportAccess, f as CatalogUsage, l as CatalogRole, n as CatalogApproval, r as CatalogBreakGlass, s as CatalogPermission, t as CatalogActivation, u as CatalogScope } from "../types-BBK-exvJ.js";
|
|
2
|
+
import { c as RlsDialect, d as RlsMemberships, f as RlsSuspension, i as PermDockConfig, l as RlsFunctionMapping, m as RunResult, n as CliIo, o as RlsActiveRow, p as RlsTarget, r as CollectConfig, s as RlsConfig, t as CatalogConfig, u as RlsMembershipTable } from "../types-D6Z6-rKJ.js";
|
|
3
|
+
//#region src/cli/catalog-path.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The absolute path `permdock collect` writes the catalog to: `collect.out`,
|
|
6
|
+
* then `catalog.out`, then `permissions.catalog.json`, resolved against `cwd`.
|
|
7
|
+
* `out` overrides the config, as `collect --out` does.
|
|
8
|
+
*/
|
|
9
|
+
export declare function catalogPath(config: PermDockConfig, cwd: string, out?: string): string;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/cli/config.d.ts
|
|
12
|
+
export declare function defineConfig<T extends PermDockConfig>(config: T): T;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/cli/markers.d.ts
|
|
15
|
+
/** The first line of a hook migration `permdock supabase hook generate` wrote. */
|
|
16
|
+
type SupabaseHookMarker = {
|
|
17
|
+
/** The marker's major: `1` for `-- permdock:hook v1`. */
|
|
18
|
+
readonly version: number;
|
|
19
|
+
readonly schema?: string;
|
|
20
|
+
readonly tenantClaim?: string;
|
|
21
|
+
readonly budget?: number;
|
|
22
|
+
readonly claims: readonly string[];
|
|
23
|
+
};
|
|
24
|
+
/** The first line of a `--grants-out` migration. */
|
|
25
|
+
type SupabaseGrantsMarker = {
|
|
26
|
+
readonly version: number;
|
|
27
|
+
readonly schema?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Reads the `-- permdock:hook v<N>` line that starts a generated hook
|
|
31
|
+
* migration. Undefined when the first line is not a hook marker.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseHookMarker(sql: string): SupabaseHookMarker | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Reads the `-- permdock:grants v<N>` line that starts a `--grants-out`
|
|
36
|
+
* migration. Undefined when the first line is not a grants marker.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseGrantsMarker(sql: string): SupabaseGrantsMarker | undefined;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/cli/run.d.ts
|
|
41
|
+
export declare function run(argv: readonly string[], options?: {
|
|
42
|
+
readonly cwd?: string;
|
|
43
|
+
readonly io?: CliIo;
|
|
44
|
+
}): Promise<RunResult>;
|
|
45
|
+
//#endregion
|
|
46
|
+
export type { CatalogActivation, CatalogApproval, CatalogBreakGlass, CatalogConfig, CatalogDocument, CatalogPermission, CatalogResource, CatalogRole, CatalogScope, CatalogSupportAccess, CatalogUsage, CollectConfig, PermDockConfig, RlsActiveRow, RlsConfig, RlsDialect, RlsFunctionMapping, RlsMembershipTable, RlsMemberships, RlsSuspension, RlsTarget, RunResult, SupabaseGrantsMarker, SupabaseHookMarker };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { t as catalogPath } from "../catalog-path-CnI0XTFK.js";
|
|
2
|
+
import { t as defineConfig } from "../config-BPYmjTOp.js";
|
|
3
|
+
import { o as parseGrantsMarker, s as parseHookMarker } from "../markers-B0hYLvMD.js";
|
|
4
|
+
import { t as run } from "../run-CJ6UvS3a.js";
|
|
5
|
+
export { catalogPath, defineConfig, parseGrantsMarker, parseHookMarker, run };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { $ as DecisionSink, Et as TokenVerifier, Y as CredentialEvent, Z as DecisionEvent, et as DirectoryEvent, q as AccessEvent, sn as PolicySource, st as MembershipEvent, wt as TokenFailureCause, xt as SnapshotSource } from "../policy-CInmNGkM.js";
|
|
2
|
+
import { f as ApprovalStore } from "../types-B8w5PFtS.js";
|
|
3
|
+
import { n as CatalogEventData, o as CloudEventType } from "../sink-Cfr9-7YC.js";
|
|
4
|
+
import { a as JsonWebKeySet } from "../types-bva3i4Gf.js";
|
|
5
|
+
import { a as ReplayStore } from "../types-i4BAOvdb.js";
|
|
6
|
+
//#region src/cloud/types.d.ts
|
|
7
|
+
type CloudEndpointOptions = {
|
|
8
|
+
readonly url?: string;
|
|
9
|
+
readonly environment?: string;
|
|
10
|
+
};
|
|
11
|
+
type CloudEndpoints = {
|
|
12
|
+
/** The environment URL, `<url>/v1/environments/<env>`: `iss` and `aud` of the policy document. */
|
|
13
|
+
readonly issuer: string;
|
|
14
|
+
/** The environment's JWK Set URL, for `joseTokenVerifier({ jwks })`. */
|
|
15
|
+
readonly jwks: string;
|
|
16
|
+
};
|
|
17
|
+
type CloudOptions = CloudEndpointOptions & {
|
|
18
|
+
readonly key?: string;
|
|
19
|
+
readonly fetch?: typeof fetch;
|
|
20
|
+
readonly flushAt?: number;
|
|
21
|
+
/** Most events the sink holds while the Cloud is unreachable (default 10 000); the oldest are dropped first. */
|
|
22
|
+
readonly capacity?: number;
|
|
23
|
+
readonly waitUntil?: (task: Promise<void>) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Verifies the environment's signed policy document, typically
|
|
26
|
+
* `joseTokenVerifier({ jwks: cloudEndpoints().jwks })`. Without one,
|
|
27
|
+
* `policies.current()` stays `null`: an unverifiable document is never applied.
|
|
28
|
+
*/
|
|
29
|
+
readonly verifier?: TokenVerifier;
|
|
30
|
+
};
|
|
31
|
+
type CloudClient = CloudEndpoints & {
|
|
32
|
+
readonly approvals: ApprovalStore;
|
|
33
|
+
readonly sink: DecisionSink;
|
|
34
|
+
readonly snapshots: SnapshotSource;
|
|
35
|
+
readonly policies: PolicySource;
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/cloud/create.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* The environment URL and JWK Set URL `cloud()` uses, resolved with the same
|
|
41
|
+
* fallbacks (`PERMDOCK_CLOUD_URL`; `PERMDOCK_CLOUD_ENV`, `VERCEL_ENV`, `production`).
|
|
42
|
+
*/
|
|
43
|
+
export declare function cloudEndpoints(options?: CloudEndpointOptions): CloudEndpoints;
|
|
44
|
+
export declare function cloud(options?: CloudOptions): CloudClient;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/cloud/webhook.d.ts
|
|
47
|
+
type Envelope<TType extends CloudEventType, TData> = {
|
|
48
|
+
readonly specversion: "1.0";
|
|
49
|
+
readonly type: TType;
|
|
50
|
+
readonly source: string;
|
|
51
|
+
readonly subject?: string;
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly time: string;
|
|
54
|
+
readonly datacontenttype: "application/json";
|
|
55
|
+
readonly data: TData;
|
|
56
|
+
};
|
|
57
|
+
/** A CloudEvent PermDock Cloud delivers, discriminated by `type`. */
|
|
58
|
+
type PermDockCloudEvent = Envelope<"dev.permdock.decision", DecisionEvent> | Envelope<"dev.permdock.approval", DecisionEvent> | Envelope<"dev.permdock.directory", DirectoryEvent> | Envelope<"dev.permdock.membership", MembershipEvent> | Envelope<"dev.permdock.credential", CredentialEvent> | Envelope<"dev.permdock.catalog", CatalogEventData> | Envelope<"dev.permdock.access.started", AccessEvent> | Envelope<"dev.permdock.access.ended", AccessEvent> | Envelope<"dev.permdock.access.revoked", AccessEvent>;
|
|
59
|
+
type VerifyWebhookOptions = {
|
|
60
|
+
/** Your receiver's URL; the batch `aud` must name it. */
|
|
61
|
+
readonly audience: string | readonly string[];
|
|
62
|
+
/** A verifier over the Cloud JWKS; built from `jwks` when absent. */
|
|
63
|
+
readonly verifier?: TokenVerifier;
|
|
64
|
+
/** `cloud().jwks`, a JWKS URL, or an inline key set. */
|
|
65
|
+
readonly jwks?: string | URL | JsonWebKeySet;
|
|
66
|
+
/** Drops a batch whose `jti` was already delivered. */
|
|
67
|
+
readonly replay?: ReplayStore;
|
|
68
|
+
};
|
|
69
|
+
type WebhookFailureReason = "unsigned" | "invalid-token" | "invalid-events" | "replayed";
|
|
70
|
+
type VerifiedWebhook = {
|
|
71
|
+
readonly ok: true;
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly events: readonly PermDockCloudEvent[];
|
|
74
|
+
} | {
|
|
75
|
+
readonly ok: false;
|
|
76
|
+
readonly reason: WebhookFailureReason;
|
|
77
|
+
readonly cause?: TokenFailureCause;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Validates one CloudEvent against the closed type list and its data shape;
|
|
81
|
+
* returns `null` for anything else, never throws.
|
|
82
|
+
*/
|
|
83
|
+
export declare function parseCloudEvent(value: unknown): PermDockCloudEvent | null;
|
|
84
|
+
/**
|
|
85
|
+
* Verifies a PermDock Cloud webhook delivery: a compact JWS with
|
|
86
|
+
* `typ: permdock-decisions+jwt` whose `events` claim holds CloudEvents.
|
|
87
|
+
* There is no unsigned mode, and it never throws.
|
|
88
|
+
*/
|
|
89
|
+
export declare function verifyWebhook(request: Request, options: VerifyWebhookOptions): Promise<VerifiedWebhook>;
|
|
90
|
+
//#endregion
|
|
91
|
+
export type { CloudClient, CloudEndpointOptions, CloudEndpoints, CloudOptions, PermDockCloudEvent, VerifiedWebhook, VerifyWebhookOptions, WebhookFailureReason };
|