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,306 @@
|
|
|
1
|
+
import { t as compact } from "./compact-y6vfu2_f.js";
|
|
2
|
+
import { f as isPermission, g as listPermissions } from "./permissions-DC7GROPA.js";
|
|
3
|
+
import { n as sha256 } from "./sha256-BO0swRXL.js";
|
|
4
|
+
import { t as requiresApproval } from "./approval-required-TzNB9oQA.js";
|
|
5
|
+
import { i as PROFILE_PARAMETERS, n as GNAP_RESERVED, r as PROFILE_NAMES, t as DRAFT_PINS } from "./pins-CqE1jZuF.js";
|
|
6
|
+
//#region src/openapi/emit.ts
|
|
7
|
+
function assertScheme(options) {
|
|
8
|
+
if (options.scheme.type === "gnap") throw new TypeError(GNAP_RESERVED);
|
|
9
|
+
}
|
|
10
|
+
function asList(permission) {
|
|
11
|
+
return isPermission(permission) ? [permission] : permission;
|
|
12
|
+
}
|
|
13
|
+
function grantsOf(policy, permissions) {
|
|
14
|
+
const keys = new Set(permissions.map((leaf) => leaf.key));
|
|
15
|
+
return policy.grants.filter((grant) => keys.has(grant.permission.key));
|
|
16
|
+
}
|
|
17
|
+
function grantsAnyone(grant) {
|
|
18
|
+
return (Array.isArray(grant.to) ? grant.to : [grant.to]).some((grantee) => grantee.kind === "anyone");
|
|
19
|
+
}
|
|
20
|
+
/** Every subject is granted it: an unconditional allow to `anyone()` and no deny. */
|
|
21
|
+
function isPublic(policy, permission) {
|
|
22
|
+
const grants = grantsOf(policy, [permission]);
|
|
23
|
+
return grants.every((grant) => grant.effect === "allow") && grants.some((grant) => grantsAnyone(grant) && grant.where === void 0 && grant.check === void 0 && grant.approval === void 0 && grant.closure === void 0 && grant.limit === void 0 && grant.purpose === void 0 && grant.viaOnly === void 0);
|
|
24
|
+
}
|
|
25
|
+
function mergeRecord(base, extra) {
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const [key, value] of Object.entries(base)) result[key] = value;
|
|
28
|
+
for (const [key, value] of Object.entries(extra)) result[key] = value;
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function scopesOf(policy) {
|
|
32
|
+
const scopes = {};
|
|
33
|
+
for (const leaf of listPermissions(policy.permissions)) scopes[leaf.scope] = leaf.meta.description ?? leaf.meta.title ?? leaf.key;
|
|
34
|
+
return scopes;
|
|
35
|
+
}
|
|
36
|
+
function flowWithScopes(flow, scopes) {
|
|
37
|
+
return mergeRecord(flow ?? {}, { scopes });
|
|
38
|
+
}
|
|
39
|
+
function securitySchemesOf(policy, options) {
|
|
40
|
+
assertScheme(options);
|
|
41
|
+
const target = options.target ?? "3.2";
|
|
42
|
+
const scopes = scopesOf(policy);
|
|
43
|
+
const name = options.scheme.name;
|
|
44
|
+
if (options.scheme.ref !== void 0 && target !== "3.1") return { [name]: { $ref: options.scheme.ref } };
|
|
45
|
+
const flowsIn = options.scheme.flows ?? { authorizationCode: {} };
|
|
46
|
+
const flows = {};
|
|
47
|
+
if (flowsIn.authorizationCode !== void 0) flows["authorizationCode"] = flowWithScopes(flowsIn.authorizationCode, scopes);
|
|
48
|
+
if (flowsIn.clientCredentials !== void 0) flows["clientCredentials"] = flowWithScopes(flowsIn.clientCredentials, scopes);
|
|
49
|
+
if (flowsIn.deviceAuthorization !== void 0) {
|
|
50
|
+
if (target === "3.1") {
|
|
51
|
+
const { deviceAuthorizationUrl, ...rest } = flowsIn.deviceAuthorization;
|
|
52
|
+
flows["x-oai-deviceAuthorization"] = flowWithScopes(compact({
|
|
53
|
+
...rest,
|
|
54
|
+
"x-oai-deviceAuthorizationUrl": deviceAuthorizationUrl
|
|
55
|
+
}), scopes);
|
|
56
|
+
} else flows["deviceAuthorization"] = flowWithScopes(flowsIn.deviceAuthorization, scopes);
|
|
57
|
+
}
|
|
58
|
+
const scheme = compact({
|
|
59
|
+
type: options.scheme.type,
|
|
60
|
+
flows: options.scheme.type === "oauth2" ? flows : void 0,
|
|
61
|
+
openIdConnectUrl: options.scheme.type === "openIdConnect" ? options.scheme.openIdConnectUrl : void 0,
|
|
62
|
+
oauth2MetadataUrl: target === "3.2" || target === "3.3" ? options.scheme.oauth2MetadataUrl : void 0,
|
|
63
|
+
"x-permdock-oauth2MetadataUrl": target === "3.1" ? options.scheme.oauth2MetadataUrl : void 0,
|
|
64
|
+
deprecated: target !== "3.1" && options.scheme.deprecated === true ? true : void 0,
|
|
65
|
+
"x-oai-deprecated": target === "3.1" && options.scheme.deprecated === true ? true : void 0,
|
|
66
|
+
"x-permdock-securityProfile": options.securityProfile
|
|
67
|
+
});
|
|
68
|
+
const schemes = { [name]: scheme };
|
|
69
|
+
if (target === "3.3" && options.securityProfile !== void 0) {
|
|
70
|
+
const profileName = options.profileScheme ?? "permdockFapi2";
|
|
71
|
+
schemes[profileName] = compact({
|
|
72
|
+
type: "profile",
|
|
73
|
+
profileMetadata: compact({
|
|
74
|
+
name: PROFILE_NAMES[options.securityProfile],
|
|
75
|
+
supportedParametersSchema: PROFILE_PARAMETERS[options.securityProfile],
|
|
76
|
+
servers: options.scheme.oauth2MetadataUrl === void 0 ? void 0 : [{
|
|
77
|
+
name: "default",
|
|
78
|
+
url: options.scheme.oauth2MetadataUrl
|
|
79
|
+
}]
|
|
80
|
+
}),
|
|
81
|
+
"x-permdock-securityProfile": options.securityProfile
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return schemes;
|
|
85
|
+
}
|
|
86
|
+
function securityOf(policy, options, permissions, anyOf) {
|
|
87
|
+
assertScheme(options);
|
|
88
|
+
const name = options.scheme.name;
|
|
89
|
+
if (anyOf === true ? permissions.some((leaf) => isPublic(policy, leaf)) : permissions.length > 0 && permissions.every((leaf) => isPublic(policy, leaf))) return [];
|
|
90
|
+
if (anyOf === true) return permissions.map((leaf) => ({ [name]: [leaf.scope] }));
|
|
91
|
+
return [{ [name]: permissions.map((leaf) => leaf.scope) }];
|
|
92
|
+
}
|
|
93
|
+
function describeOf(policy, options, permissions, anyOf) {
|
|
94
|
+
const conditions = {};
|
|
95
|
+
const approvals = {};
|
|
96
|
+
for (const leaf of permissions) {
|
|
97
|
+
const grants = grantsOf(policy, [leaf]).filter((grant) => grant.effect === "allow");
|
|
98
|
+
const wheres = grants.filter((grant) => grant.portable).map((grant) => grant.where).filter((where) => where !== void 0);
|
|
99
|
+
const [only] = wheres;
|
|
100
|
+
if (only !== void 0) conditions[leaf.key] = wheres.length === 1 ? only : {
|
|
101
|
+
op: "or",
|
|
102
|
+
conditions: wheres
|
|
103
|
+
};
|
|
104
|
+
if (grants.some((grant) => requiresApproval(grant.approval))) approvals[leaf.key] = { reason: "human" };
|
|
105
|
+
}
|
|
106
|
+
const approval = Object.keys(approvals).length > 0;
|
|
107
|
+
return compact({
|
|
108
|
+
security: securityOf(policy, options, permissions, anyOf),
|
|
109
|
+
"x-permdock-permissions": permissions.map((leaf) => leaf.key),
|
|
110
|
+
"x-permdock-conditions": Object.keys(conditions).length > 0 ? conditions : void 0,
|
|
111
|
+
"x-permdock-approval": approval ? approvals : void 0,
|
|
112
|
+
"x-permdock-securityProfile": options.securityProfile,
|
|
113
|
+
"x-badges": options.docsHints?.badges === true && approval ? [{ name: "Approval required" }] : void 0
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function catalogOf(options, extraDrafts) {
|
|
117
|
+
const target = options.target ?? "3.2";
|
|
118
|
+
const drafts = {};
|
|
119
|
+
if (target === "3.3") {
|
|
120
|
+
drafts["oas"] = DRAFT_PINS.oas;
|
|
121
|
+
drafts["securityProfiles"] = DRAFT_PINS.securityProfiles;
|
|
122
|
+
}
|
|
123
|
+
if (extraDrafts !== void 0) for (const [key, value] of Object.entries(extraDrafts)) drafts[key] = value;
|
|
124
|
+
return compact({
|
|
125
|
+
v: 1,
|
|
126
|
+
generator: "permdock/openapi",
|
|
127
|
+
drafts: Object.keys(drafts).length > 0 ? drafts : void 0
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const GRANT_TYPES = {
|
|
131
|
+
authorizationCode: "authorization_code",
|
|
132
|
+
clientCredentials: "client_credentials",
|
|
133
|
+
deviceAuthorization: "urn:ietf:params:oauth:grant-type:device_code"
|
|
134
|
+
};
|
|
135
|
+
const FLOWS = [
|
|
136
|
+
"authorizationCode",
|
|
137
|
+
"clientCredentials",
|
|
138
|
+
"deviceAuthorization"
|
|
139
|
+
];
|
|
140
|
+
/** The client authentication methods FAPI 2.0 section 5.3.2.1 allows: sender-constrained, no shared secret. */
|
|
141
|
+
const FAPI2_AUTH_METHODS = ["private_key_jwt", "tls_client_auth"];
|
|
142
|
+
function pascal(value) {
|
|
143
|
+
return value.split(/[^A-Za-z0-9]+/u).filter((part) => part.length > 0).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* One Security Profile Requirement per distinct scope set: `scopeSets` from
|
|
147
|
+
* the operations, else one per permission.
|
|
148
|
+
*/
|
|
149
|
+
function securityProfileRequirementsOf(policy, options, scopeSets) {
|
|
150
|
+
if ((options.target ?? "3.2") !== "3.3" || options.securityProfile === void 0) return;
|
|
151
|
+
const profileName = options.profileScheme ?? "permdockFapi2";
|
|
152
|
+
const flows = options.scheme.flows ?? { authorizationCode: {} };
|
|
153
|
+
const grantTypes = FLOWS.filter((flow) => flows[flow] !== void 0).map((flow) => GRANT_TYPES[flow]);
|
|
154
|
+
const sets = scopeSets ?? listPermissions(policy.permissions).map((leaf) => [leaf.scope]);
|
|
155
|
+
const requirements = {};
|
|
156
|
+
for (const set of sets) {
|
|
157
|
+
const scopes = [...new Set(set)].toSorted();
|
|
158
|
+
if (scopes.length === 0) continue;
|
|
159
|
+
requirements[`${profileName}${pascal(scopes.join(" "))}`] = {
|
|
160
|
+
securityScheme: { $ref: `#/components/securitySchemes/${profileName}` },
|
|
161
|
+
token_endpoint_auth_methods: [...FAPI2_AUTH_METHODS],
|
|
162
|
+
grant_types: grantTypes,
|
|
163
|
+
scopes
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return requirements;
|
|
167
|
+
}
|
|
168
|
+
function openapiVersion(target) {
|
|
169
|
+
switch (target) {
|
|
170
|
+
case "3.1": return "3.1.0";
|
|
171
|
+
case "3.2": return "3.2.0";
|
|
172
|
+
case "3.3": return "3.3.0";
|
|
173
|
+
default: return target;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/openapi/overlay.ts
|
|
178
|
+
function pointerEscape(value) {
|
|
179
|
+
return value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
180
|
+
}
|
|
181
|
+
function actionKey(keys) {
|
|
182
|
+
return keys.toSorted().join(",");
|
|
183
|
+
}
|
|
184
|
+
/** An RFC 9535 single-quoted string literal. */
|
|
185
|
+
function jsonPathString(value) {
|
|
186
|
+
return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
187
|
+
}
|
|
188
|
+
function operationTarget(operationId) {
|
|
189
|
+
return `$.paths.*[?@.operationId == ${jsonPathString(operationId)}]`;
|
|
190
|
+
}
|
|
191
|
+
function hex(bytes) {
|
|
192
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
193
|
+
}
|
|
194
|
+
/** `sha256:` over the sorted permission keys and scopes, so the same catalog gives the same Overlay. */
|
|
195
|
+
function fingerprint(policy) {
|
|
196
|
+
const lines = listPermissions(policy.permissions).map((leaf) => `${leaf.key} ${leaf.scope}`).toSorted();
|
|
197
|
+
return `sha256:${hex(sha256(lines.join("\n")))}`;
|
|
198
|
+
}
|
|
199
|
+
function overlayOf(policy, options, overlayOptions = {}) {
|
|
200
|
+
const version = overlayOptions.version ?? "1.1";
|
|
201
|
+
const operations = (overlayOptions.operations ?? listPermissions(policy.permissions).map((leaf) => ({
|
|
202
|
+
operationId: leaf.key,
|
|
203
|
+
permissions: [leaf]
|
|
204
|
+
}))).toSorted((a, b) => a.operationId < b.operationId ? -1 : a.operationId > b.operationId ? 1 : 0);
|
|
205
|
+
const schemes = securitySchemesOf(policy, options);
|
|
206
|
+
const requirements = securityProfileRequirementsOf(policy, options, overlayOptions.operations?.map((operation) => operation.permissions.map((leaf) => leaf.scope)));
|
|
207
|
+
const catalogPin = fingerprint(policy);
|
|
208
|
+
const drafts = version === "1.2" ? { overlay: DRAFT_PINS.overlay } : void 0;
|
|
209
|
+
const info = {
|
|
210
|
+
title: "PermDock authorization metadata",
|
|
211
|
+
version: catalogPin
|
|
212
|
+
};
|
|
213
|
+
const head = [{
|
|
214
|
+
target: "$.components.securitySchemes",
|
|
215
|
+
description: "PermDock security schemes",
|
|
216
|
+
update: schemes
|
|
217
|
+
}];
|
|
218
|
+
if (requirements !== void 0) head.push({
|
|
219
|
+
target: "$.components.securityProfileRequirements",
|
|
220
|
+
description: "PermDock security profile requirements",
|
|
221
|
+
update: requirements
|
|
222
|
+
});
|
|
223
|
+
const catalogAction = {
|
|
224
|
+
target: "$",
|
|
225
|
+
description: "PermDock catalog pin",
|
|
226
|
+
update: { "x-permdock-catalog": catalogOf(options, drafts) }
|
|
227
|
+
};
|
|
228
|
+
const bodies = operations.map((operation) => {
|
|
229
|
+
const keys = operation.permissions.map((leaf) => leaf.key);
|
|
230
|
+
return {
|
|
231
|
+
operationId: operation.operationId,
|
|
232
|
+
key: actionKey(keys),
|
|
233
|
+
target: operationTarget(operation.operationId),
|
|
234
|
+
fields: describeOf(policy, options, operation.permissions)
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
if (version === "1.1") return compact({
|
|
238
|
+
overlay: "1.1.0",
|
|
239
|
+
info,
|
|
240
|
+
extends: overlayOptions.extends,
|
|
241
|
+
actions: [
|
|
242
|
+
...head,
|
|
243
|
+
...bodies.map((body) => ({
|
|
244
|
+
target: body.target,
|
|
245
|
+
description: body.key,
|
|
246
|
+
update: body.fields
|
|
247
|
+
})),
|
|
248
|
+
catalogAction
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
const reusable = {};
|
|
252
|
+
for (const body of bodies.toSorted((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0)) reusable[body.key] ??= {
|
|
253
|
+
description: body.key,
|
|
254
|
+
fields: { update: body.fields }
|
|
255
|
+
};
|
|
256
|
+
return compact({
|
|
257
|
+
overlay: "1.2.0",
|
|
258
|
+
info,
|
|
259
|
+
extends: overlayOptions.extends,
|
|
260
|
+
components: { actions: reusable },
|
|
261
|
+
actions: [
|
|
262
|
+
...head,
|
|
263
|
+
...bodies.map((body) => ({
|
|
264
|
+
$ref: `#/components/actions/${pointerEscape(body.key)}`,
|
|
265
|
+
target: body.target,
|
|
266
|
+
description: body.operationId
|
|
267
|
+
})),
|
|
268
|
+
catalogAction
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/openapi/create.ts
|
|
274
|
+
function extendOperation(operation, extra) {
|
|
275
|
+
const result = {};
|
|
276
|
+
for (const [key, value] of Object.entries(operation)) result[key] = value;
|
|
277
|
+
for (const [key, value] of Object.entries(extra)) result[key] = value;
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
const createPermDock = (policy, options) => {
|
|
281
|
+
return {
|
|
282
|
+
securitySchemes() {
|
|
283
|
+
return securitySchemesOf(policy, options);
|
|
284
|
+
},
|
|
285
|
+
security(permission, extra) {
|
|
286
|
+
return securityOf(policy, options, asList(permission), extra?.anyOf);
|
|
287
|
+
},
|
|
288
|
+
describe(permission, extra) {
|
|
289
|
+
return describeOf(policy, options, asList(permission), extra?.anyOf);
|
|
290
|
+
},
|
|
291
|
+
spec(permission) {
|
|
292
|
+
return (operation) => extendOperation(operation, describeOf(policy, options, asList(permission)));
|
|
293
|
+
},
|
|
294
|
+
overlay(overlayOptions) {
|
|
295
|
+
return overlayOf(policy, options, overlayOptions ?? {});
|
|
296
|
+
},
|
|
297
|
+
securityProfileRequirements(scopeSets) {
|
|
298
|
+
return securityProfileRequirementsOf(policy, options, scopeSets);
|
|
299
|
+
},
|
|
300
|
+
catalog() {
|
|
301
|
+
return catalogOf(options);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
export { securitySchemesOf as i, catalogOf as n, openapiVersion as r, createPermDock as t };
|