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.
Files changed (290) hide show
  1. package/README.md +268 -1
  2. package/dist/a2a/index.d.ts +178 -0
  3. package/dist/a2a/index.js +271 -0
  4. package/dist/ai-sdk/index.d.ts +74 -0
  5. package/dist/ai-sdk/index.js +137 -0
  6. package/dist/approval-required-TzNB9oQA.js +6 -0
  7. package/dist/approvals/index.d.ts +3 -0
  8. package/dist/approvals/index.js +4 -0
  9. package/dist/approvals-DaxY-Bdg.js +218 -0
  10. package/dist/approvers-aH0PJkmf.js +20 -0
  11. package/dist/arazzo-CTeVuXr5.js +70 -0
  12. package/dist/arazzo-aoTkqYsJ.js +54 -0
  13. package/dist/authzen/index.d.ts +48 -0
  14. package/dist/authzen/index.js +336 -0
  15. package/dist/better-auth/index.d.ts +92 -0
  16. package/dist/better-auth/index.js +324 -0
  17. package/dist/budget-JqcRqyhK.d.ts +11 -0
  18. package/dist/budget-NbEtbJC_.js +11 -0
  19. package/dist/capability-B68OFnZx.js +171 -0
  20. package/dist/capability-BDG_nkxt.d.ts +99 -0
  21. package/dist/catalog/index.d.ts +12 -0
  22. package/dist/catalog/index.js +2 -0
  23. package/dist/catalog-B0E6bggc.js +48 -0
  24. package/dist/catalog-H-vFGwWK.js +55 -0
  25. package/dist/catalog-doc-BSo_Q_-6.js +298 -0
  26. package/dist/catalog-idsHc0vo.js +2 -0
  27. package/dist/catalog-path-CnI0XTFK.js +12 -0
  28. package/dist/claude-agent/index.d.ts +81 -0
  29. package/dist/claude-agent/index.js +83 -0
  30. package/dist/clerk/index.d.ts +56 -0
  31. package/dist/clerk/index.js +280 -0
  32. package/dist/cli/bin.d.ts +1 -0
  33. package/dist/cli/bin.js +20 -0
  34. package/dist/cli/index.d.ts +46 -0
  35. package/dist/cli/index.js +5 -0
  36. package/dist/cloud/index.d.ts +91 -0
  37. package/dist/cloud/index.js +390 -0
  38. package/dist/cloud-BNQTrmrr.js +50 -0
  39. package/dist/cloud-Cuxr6Czw.js +117 -0
  40. package/dist/collect-B7_TIfmg.js +49 -0
  41. package/dist/collect-O-tOtbnk.js +350 -0
  42. package/dist/collect-fRPAQIWb.js +2 -0
  43. package/dist/commands-BMh_Etm2.js +93 -0
  44. package/dist/compact-y6vfu2_f.js +19 -0
  45. package/dist/compare-pfyVnBjE.js +12 -0
  46. package/dist/compile-CQbvyIBr.d.ts +30 -0
  47. package/dist/compile-D22iwvuV.js +558 -0
  48. package/dist/config-BPYmjTOp.js +26 -0
  49. package/dist/connection-JvqwHODC.js +194 -0
  50. package/dist/context-CKEAabd7.js +73 -0
  51. package/dist/context-gtAwAILx.js +6 -0
  52. package/dist/convex/index.d.ts +40 -0
  53. package/dist/convex/index.js +55 -0
  54. package/dist/create-BKF3dgFk.d.ts +162 -0
  55. package/dist/create-CSkhDU9T.js +222 -0
  56. package/dist/credential-B_rkUNlY.js +326 -0
  57. package/dist/credentials-BgRX3WEg.js +268 -0
  58. package/dist/describe-Bt1YD5uS.js +99 -0
  59. package/dist/describe-DernyItf.d.ts +37 -0
  60. package/dist/diff-BUzf5Poi.js +48 -0
  61. package/dist/diff-x5Il8LVa.js +418 -0
  62. package/dist/digest-B3kc_PgQ.d.ts +19 -0
  63. package/dist/digest-BI-6aa6d.js +27 -0
  64. package/dist/doctor-BGle8Gqi.js +1314 -0
  65. package/dist/doctor-Bqo6FwUa.js +53 -0
  66. package/dist/drizzle/index.d.ts +72 -0
  67. package/dist/drizzle/index.js +160 -0
  68. package/dist/duration-xK2jGFVc.js +25 -0
  69. package/dist/elysia/index.d.ts +71 -0
  70. package/dist/elysia/index.js +103 -0
  71. package/dist/errors-DSMnAVNa.js +43 -0
  72. package/dist/errors-DbZ1YOnb.d.ts +138 -0
  73. package/dist/errors-Iy71s7Oj.js +177 -0
  74. package/dist/errors-m3u9TmDu.js +27 -0
  75. package/dist/evaluations-DsAU9ppl.js +479 -0
  76. package/dist/eve/index.d.ts +95 -0
  77. package/dist/eve/index.js +181 -0
  78. package/dist/express/index.d.ts +46 -0
  79. package/dist/express/index.js +108 -0
  80. package/dist/fastify/index.d.ts +56 -0
  81. package/dist/fastify/index.js +141 -0
  82. package/dist/files-B_wAGYmt.js +121 -0
  83. package/dist/fixtures-Cvaw0gDG.js +64 -0
  84. package/dist/freeze-y1_jQL4v.js +31 -0
  85. package/dist/from-snapshot-BMGnhmgv.js +552 -0
  86. package/dist/generate-CH7ThJ14.js +173 -0
  87. package/dist/grantee-Bv04_Vzf.js +521 -0
  88. package/dist/headers-B5RRv3Xm.js +6 -0
  89. package/dist/headers-C8SHQccD.d.ts +6 -0
  90. package/dist/helpers-DnSOrhB9.js +682 -0
  91. package/dist/hono/index.d.ts +70 -0
  92. package/dist/hono/index.js +131 -0
  93. package/dist/hosted-BwKQ1BTA.js +265 -0
  94. package/dist/http-DPuDaChb.d.ts +13 -0
  95. package/dist/http-GgVApX1k.js +111 -0
  96. package/dist/index-CltcQ4Bf.d.ts +138 -0
  97. package/dist/index-LF_hS-yn.d.ts +177 -0
  98. package/dist/index-fG6NSXlc.d.ts +9 -0
  99. package/dist/index-xIxJLwOQ.d.ts +415 -0
  100. package/dist/index.d.ts +11 -0
  101. package/dist/index.js +21 -0
  102. package/dist/jwt/index.d.ts +87 -0
  103. package/dist/jwt/index.js +571 -0
  104. package/dist/kernel-YOGCWNLf.js +211 -0
  105. package/dist/kysely/index.d.ts +77 -0
  106. package/dist/kysely/index.js +129 -0
  107. package/dist/load-BZ24CpZP.js +69 -0
  108. package/dist/load-QOOm1z70.js +2 -0
  109. package/dist/load-jose-BL6LH4bL.js +11 -0
  110. package/dist/lru-8q4WZjBV.js +28 -0
  111. package/dist/manifest-DDQbC6K0.d.ts +118 -0
  112. package/dist/map-DowSO96j.js +158 -0
  113. package/dist/map-claims-B_6I1Rn-.js +360 -0
  114. package/dist/map-error-RJ3ZsUyA.js +16 -0
  115. package/dist/markers-B0hYLvMD.js +60 -0
  116. package/dist/may-use-CnFEjVEp.js +37 -0
  117. package/dist/mcp/index.d.ts +127 -0
  118. package/dist/mcp/index.js +563 -0
  119. package/dist/nest/index.d.ts +80 -0
  120. package/dist/nest/index.js +270 -0
  121. package/dist/next/client.d.ts +24 -0
  122. package/dist/next/client.js +31 -0
  123. package/dist/next/index.d.ts +110 -0
  124. package/dist/next/index.js +195 -0
  125. package/dist/next/plugin.d.ts +14 -0
  126. package/dist/next/plugin.js +2 -0
  127. package/dist/node/index.d.ts +43 -0
  128. package/dist/node/index.js +66 -0
  129. package/dist/openai/index.d.ts +71 -0
  130. package/dist/openai/index.js +105 -0
  131. package/dist/openapi/index.d.ts +93 -0
  132. package/dist/openapi/index.js +3 -0
  133. package/dist/openapi-CwePaF7C.js +164 -0
  134. package/dist/openapi-DWD0Uc_4.js +250 -0
  135. package/dist/openapi-DcqM8nU7.js +306 -0
  136. package/dist/openapi-import-BWRUNNeW.js +5959 -0
  137. package/dist/openapi-schema-D8j_T9tO.js +6902 -0
  138. package/dist/orpc/index.d.ts +64 -0
  139. package/dist/orpc/index.js +188 -0
  140. package/dist/otel/index.d.ts +13 -0
  141. package/dist/otel/index.js +202 -0
  142. package/dist/package-root-zGkxO3oN.js +30 -0
  143. package/dist/parse-DPfIvFMU.js +135 -0
  144. package/dist/pdp/index.d.ts +22 -0
  145. package/dist/pdp/index.js +795 -0
  146. package/dist/peer-BOr_kJE1.js +31 -0
  147. package/dist/permdock-yoZ7EjxX.js +2956 -0
  148. package/dist/permissions-B4apnahQ.d.ts +185 -0
  149. package/dist/permissions-B8vCg_bI.d.ts +52 -0
  150. package/dist/permissions-CofRqesP.js +142 -0
  151. package/dist/permissions-DC7GROPA.js +600 -0
  152. package/dist/pg-4GJWDUxG.js +953 -0
  153. package/dist/pins-CqE1jZuF.js +12 -0
  154. package/dist/plugin-4gr7IxFJ.js +65 -0
  155. package/dist/policy-ANp36PnI.js +971 -0
  156. package/dist/policy-CInmNGkM.d.ts +1959 -0
  157. package/dist/policy-Cq2fB8Q5.d.ts +20 -0
  158. package/dist/prisma/index.d.ts +135 -0
  159. package/dist/prisma/index.js +430 -0
  160. package/dist/problem-Cgp9-KZA.js +226 -0
  161. package/dist/prompt-CXYhLfsS.js +32 -0
  162. package/dist/protected-B4K3BKoX.js +138 -0
  163. package/dist/protected-BuPAycJT.d.ts +26 -0
  164. package/dist/protected-wY7nXhY9.d.ts +23 -0
  165. package/dist/provider-_wx46HpB.js +48 -0
  166. package/dist/provider-wTAUda2v.d.ts +6 -0
  167. package/dist/react/index.d.ts +6 -0
  168. package/dist/react/index.js +6 -0
  169. package/dist/react/provider-client.d.ts +2 -0
  170. package/dist/react/provider-client.js +3 -0
  171. package/dist/react-native/index.d.ts +42 -0
  172. package/dist/react-native/index.js +174 -0
  173. package/dist/refs-ChLSxbST.js +90 -0
  174. package/dist/relations-r4soIFZB.js +426 -0
  175. package/dist/revocations-Cy06JNx2.d.ts +21 -0
  176. package/dist/rls-BOFU3chG.js +233 -0
  177. package/dist/rls-CJVja9Ww.js +2119 -0
  178. package/dist/rls-graph-DxQ39PJj.js +371 -0
  179. package/dist/rls-helpers-BxRuif0l.js +1346 -0
  180. package/dist/rls-import-CXV6LBlS.js +942 -0
  181. package/dist/rls-migrate-DrFPbf8p.js +366 -0
  182. package/dist/row-check-BajTgQZ-.d.ts +43 -0
  183. package/dist/run-CJ6UvS3a.js +155 -0
  184. package/dist/runtime-DP9ttFh1.js +27 -0
  185. package/dist/saas-BRrZzJkM.js +1193 -0
  186. package/dist/schema-P8yoma__.js +296 -0
  187. package/dist/scim/index.d.ts +2 -0
  188. package/dist/scim/index.js +2 -0
  189. package/dist/scim-9NFa0XVZ.js +1445 -0
  190. package/dist/scopes-cKVp_WTw.js +212 -0
  191. package/dist/server/index.d.ts +123 -0
  192. package/dist/server/index.js +8 -0
  193. package/dist/sha256-BO0swRXL.js +150 -0
  194. package/dist/sink-Bd9PSyfq.js +141 -0
  195. package/dist/sink-Cfr9-7YC.d.ts +104 -0
  196. package/dist/skills-C_lpV4Jx.js +50 -0
  197. package/dist/skills-Dx3QLnMY.js +110 -0
  198. package/dist/snapshot-DE8dE_hz.js +1051 -0
  199. package/dist/solid/index.d.ts +63 -0
  200. package/dist/solid/index.js +197 -0
  201. package/dist/source-DoBBYJi2.js +6 -0
  202. package/dist/sources-DOpW5Ila.d.ts +347 -0
  203. package/dist/sources-DVHM3Mwq.js +284 -0
  204. package/dist/sql-Bll1d7y0.js +22 -0
  205. package/dist/src-CTNT-PBW.js +430 -0
  206. package/dist/ssf/index.d.ts +3 -0
  207. package/dist/ssf/index.js +622 -0
  208. package/dist/store-Bq90395i.d.ts +27 -0
  209. package/dist/store-C6hFW6ta.js +508 -0
  210. package/dist/stores-CkG2HrSg.js +140 -0
  211. package/dist/stores-CvOnu_2T.d.ts +41 -0
  212. package/dist/stream-BhMfZOwr.d.ts +12 -0
  213. package/dist/stream-Q_xlB6Ko.js +52 -0
  214. package/dist/style-CTm1AXDT.js +22 -0
  215. package/dist/subject-C6dLxqHU.js +24 -0
  216. package/dist/subject-settings-xt7V845g.js +82 -0
  217. package/dist/supabase/index.d.ts +67 -0
  218. package/dist/supabase/index.js +4 -0
  219. package/dist/supabase/middleware.d.ts +77 -0
  220. package/dist/supabase/middleware.js +68 -0
  221. package/dist/supabase-D8UlBA7Z.js +83 -0
  222. package/dist/supabase-DTxGtYdi.js +796 -0
  223. package/dist/supabase-hook-DW-xP4hU.js +2 -0
  224. package/dist/supabase-hook-D_OqGb_V.js +1528 -0
  225. package/dist/svelte/Protected.svelte +34 -0
  226. package/dist/svelte/index.d.ts +10 -0
  227. package/dist/svelte/index.js +53 -0
  228. package/dist/svelte/runtime.d.ts +6 -0
  229. package/dist/svelte/runtime.js +3 -0
  230. package/dist/svelte/source.d.ts +10 -0
  231. package/dist/svelte/source.js +8 -0
  232. package/dist/terminal/index.d.ts +171 -0
  233. package/dist/terminal/index.js +821 -0
  234. package/dist/testing/index.d.ts +656 -0
  235. package/dist/testing/index.js +3208 -0
  236. package/dist/testing/saas/index.d.ts +194 -0
  237. package/dist/testing/saas/index.js +3 -0
  238. package/dist/testing/saas/permissions.d.ts +2 -0
  239. package/dist/testing/saas/permissions.js +2 -0
  240. package/dist/text-diff-BdkkYSbi.js +15 -0
  241. package/dist/thenable-okc2xDsj.js +10 -0
  242. package/dist/timeout-D51niuQP.js +8 -0
  243. package/dist/trpc/index.d.ts +80 -0
  244. package/dist/trpc/index.js +205 -0
  245. package/dist/types-B8w5PFtS.d.ts +141 -0
  246. package/dist/types-B9dmiiab.d.ts +66 -0
  247. package/dist/types-BBK-exvJ.d.ts +177 -0
  248. package/dist/types-BvBk1wgn.d.ts +118 -0
  249. package/dist/types-CxquUByI.d.ts +9 -0
  250. package/dist/types-D6Z6-rKJ.d.ts +312 -0
  251. package/dist/types-DbWdEfcm.d.ts +87 -0
  252. package/dist/types-bva3i4Gf.d.ts +98 -0
  253. package/dist/types-i4BAOvdb.d.ts +97 -0
  254. package/dist/unplugin/index.d.ts +7 -0
  255. package/dist/unplugin/index.js +30 -0
  256. package/dist/usage-1ozMubLY.js +42 -0
  257. package/dist/usage-CUnK6Ou9.js +530 -0
  258. package/dist/usage-PyEor6GA.js +2 -0
  259. package/dist/validity-D0uRmJKJ.js +224 -0
  260. package/dist/verifier-B90agnhl.js +461 -0
  261. package/dist/version-CnSh33Fj.js +16 -0
  262. package/dist/vocabulary-Dk0fs-Jk.d.ts +56 -0
  263. package/dist/vue/index.d.ts +57 -0
  264. package/dist/vue/index.js +203 -0
  265. package/dist/webmcp/index.d.ts +75 -0
  266. package/dist/webmcp/index.js +313 -0
  267. package/package.json +423 -4
  268. package/rulesets/permdock.yaml +29 -0
  269. package/schemas/catalog-v1.json +507 -0
  270. package/schemas/openapi/oas-3.1.json +1298 -0
  271. package/schemas/openapi/oas-3.2.json +1516 -0
  272. package/schemas/openapi/overlay-1.1.json +79 -0
  273. package/schemas/supabase-claims-v1.json +139 -0
  274. package/schemas/supabase-manifest-v1.json +217 -0
  275. package/skills/permdock/SKILL.md +66 -0
  276. package/skills/permdock-agents/SKILL.md +77 -0
  277. package/skills/permdock-agents/references/runtimes.md +211 -0
  278. package/skills/permdock-approvals/SKILL.md +80 -0
  279. package/skills/permdock-approvals/references/stores-and-resume.md +83 -0
  280. package/skills/permdock-audit/SKILL.md +67 -0
  281. package/skills/permdock-credentials/SKILL.md +55 -0
  282. package/skills/permdock-credentials/references/tokens-keys-links.md +127 -0
  283. package/skills/permdock-data/SKILL.md +57 -0
  284. package/skills/permdock-data/references/queries-and-rls.md +54 -0
  285. package/skills/permdock-data/references/relationships.md +65 -0
  286. package/skills/permdock-tenancy/SKILL.md +77 -0
  287. package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +83 -0
  288. package/skills/permdock-wire/SKILL.md +116 -0
  289. package/skills/permdock-wire/references/adapters.md +480 -0
  290. package/skills/permdock-wire/references/policy-options.md +43 -0
@@ -0,0 +1,158 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { g as listPermissions, i as findPermission } from "./permissions-DC7GROPA.js";
3
+ //#region src/authzen/map.ts
4
+ const UNKNOWN = {
5
+ outcome: "denied",
6
+ denials: [{
7
+ role: null,
8
+ reason: "no-grant",
9
+ detail: "unknown-permission"
10
+ }],
11
+ alternatives: []
12
+ };
13
+ const UNAVAILABLE = {
14
+ outcome: "denied",
15
+ denials: [{
16
+ role: null,
17
+ reason: "no-grant",
18
+ detail: "resource-unavailable"
19
+ }],
20
+ alternatives: []
21
+ };
22
+ function isRecord(value) {
23
+ return value !== null && typeof value === "object" && !Array.isArray(value);
24
+ }
25
+ function actionNameOf(item) {
26
+ if (typeof item.action?.name === "string") return item.action.name;
27
+ if (!isRecord(item.action?.properties)) return;
28
+ const scope = item.action.properties["scope"];
29
+ return typeof scope === "string" ? scope : void 0;
30
+ }
31
+ function permissionOf(tree, item) {
32
+ const actionName = actionNameOf(item);
33
+ if (actionName === void 0) return;
34
+ const byKey = findPermission(tree, actionName);
35
+ if (byKey !== void 0) return byKey;
36
+ const resource = typeof item.resource?.type === "string" ? item.resource.type : void 0;
37
+ if (resource === void 0) return;
38
+ const dotted = findPermission(tree, `${resource}.${actionName}`);
39
+ if (dotted !== void 0) return dotted;
40
+ return listPermissions(tree).find((leaf) => leaf.resource === resource && leaf.action === actionName);
41
+ }
42
+ function resourceData(item) {
43
+ const properties = item.resource?.properties;
44
+ if (properties !== null && typeof properties === "object") return properties;
45
+ const id = item.resource?.id;
46
+ if (typeof id === "string" || typeof id === "number") return { id: String(id) };
47
+ }
48
+ function resourceIdOf(item) {
49
+ const id = item.resource?.id;
50
+ if (typeof id === "string" || typeof id === "number") return String(id);
51
+ }
52
+ function userFromEntity(entity) {
53
+ if (entity === void 0) return null;
54
+ const result = {};
55
+ if (typeof entity.id === "string" || typeof entity.id === "number") result["id"] = String(entity.id);
56
+ if (isRecord(entity.properties)) for (const [key, value] of Object.entries(entity.properties)) {
57
+ if (key === "actor" || key === "delegation") continue;
58
+ result[key] = value;
59
+ }
60
+ return Object.keys(result).length === 0 ? null : result;
61
+ }
62
+ function actorOf(item) {
63
+ const context = isRecord(item.context) ? item.context : {};
64
+ const fromSubject = isRecord(item.subject?.properties) ? item.subject.properties["actor"] : void 0;
65
+ const raw = context["actor"] ?? fromSubject;
66
+ if (!isRecord(raw) || typeof raw["id"] !== "string") return;
67
+ const kind = typeof raw["kind"] === "string" ? raw["kind"] : "oauth-client";
68
+ return {
69
+ id: raw["id"],
70
+ kind
71
+ };
72
+ }
73
+ function delegationOf(item) {
74
+ const context = isRecord(item.context) ? item.context : {};
75
+ const fromSubject = isRecord(item.subject?.properties) ? item.subject.properties["delegation"] : void 0;
76
+ const raw = context["delegation"] ?? fromSubject;
77
+ if (!isRecord(raw)) return;
78
+ const scopes = raw["scopes"];
79
+ const authorizationDetails = raw["authorizationDetails"];
80
+ return compact({
81
+ scopes: Array.isArray(scopes) ? scopes.filter((scope) => typeof scope === "string") : void 0,
82
+ authorizationDetails: Array.isArray(authorizationDetails) ? authorizationDetails : void 0
83
+ });
84
+ }
85
+ function tenantOf(item) {
86
+ if (!isRecord(item.context) || typeof item.context["tenant"] !== "string") return;
87
+ return item.context["tenant"];
88
+ }
89
+ function permdockContext(decision) {
90
+ switch (decision.outcome) {
91
+ case "granted": return { outcome: "granted" };
92
+ case "denied": {
93
+ const unknown = decision.denials.some((denial) => denial.detail === "unknown-permission");
94
+ return compact({
95
+ outcome: "denied",
96
+ denials: decision.denials.map((denial) => ({
97
+ role: denial.role,
98
+ reason: denial.reason
99
+ })),
100
+ reason: unknown ? "unknown-permission" : void 0
101
+ });
102
+ }
103
+ case "approval-required": return {
104
+ outcome: "approval-required",
105
+ token: decision.token
106
+ };
107
+ default: return decision;
108
+ }
109
+ }
110
+ function evaluationContext(decision) {
111
+ return { permdock: permdockContext(decision) };
112
+ }
113
+ function evaluationRow(decision) {
114
+ return {
115
+ decision: decision.outcome === "granted",
116
+ context: evaluationContext(decision)
117
+ };
118
+ }
119
+ function pathnameOf(request) {
120
+ return new URL(request.url).pathname;
121
+ }
122
+ function endsWithPath(pathname, suffix) {
123
+ return pathname === suffix || pathname.endsWith(suffix);
124
+ }
125
+ function mergeItem(shared, item) {
126
+ if (!isRecord(item)) return shared;
127
+ return compact({
128
+ subject: isRecord(item["subject"]) ? item["subject"] : shared.subject,
129
+ action: isRecord(item["action"]) ? item["action"] : shared.action,
130
+ resource: isRecord(item["resource"]) ? item["resource"] : shared.resource,
131
+ context: item["context"] ?? shared.context
132
+ });
133
+ }
134
+ function pageOf(body) {
135
+ const page = isRecord(body["page"]) ? body["page"] : {};
136
+ const raw = typeof page["token"] === "string" ? page["token"] : typeof page["next_token"] === "string" ? page["next_token"] : "0";
137
+ const parsed = Math.trunc(Number(raw));
138
+ const sizeRaw = page["limit"] ?? page["size"];
139
+ const size = typeof sizeRaw === "number" && sizeRaw > 0 ? Math.min(sizeRaw, 200) : 50;
140
+ return {
141
+ offset: Number.isFinite(parsed) && parsed > 0 ? parsed : 0,
142
+ size
143
+ };
144
+ }
145
+ function paged(items, offset, size) {
146
+ const slice = items.slice(offset, offset + size);
147
+ const next = offset + slice.length;
148
+ return {
149
+ results: slice,
150
+ page: {
151
+ next_token: next < items.length ? String(next) : "",
152
+ count: slice.length,
153
+ total: items.length
154
+ }
155
+ };
156
+ }
157
+ //#endregion
158
+ export { endsWithPath as a, mergeItem as c, pathnameOf as d, permissionOf as f, userFromEntity as g, tenantOf as h, delegationOf as i, pageOf as l, resourceIdOf as m, UNKNOWN as n, evaluationRow as o, resourceData as p, actorOf as r, isRecord as s, UNAVAILABLE as t, paged as u };
@@ -0,0 +1,360 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { n as freezeDeep } from "./freeze-y1_jQL4v.js";
3
+ import { S as isForbiddenKey, T as readPath } from "./permissions-DC7GROPA.js";
4
+ import { t as ignoreRejection } from "./thenable-okc2xDsj.js";
5
+ import { t as anonymousSubject } from "./subject-C6dLxqHU.js";
6
+ //#region src/jwt/map-claims.ts
7
+ /** OpenID Connect Core section 5.1: profile data the provider owns. */
8
+ const PROFILE_CLAIMS = [
9
+ "name",
10
+ "given_name",
11
+ "family_name",
12
+ "middle_name",
13
+ "nickname",
14
+ "preferred_username",
15
+ "profile",
16
+ "picture",
17
+ "website",
18
+ "email",
19
+ "email_verified",
20
+ "gender",
21
+ "birthdate",
22
+ "zoneinfo",
23
+ "locale",
24
+ "phone_number",
25
+ "phone_number_verified",
26
+ "address",
27
+ "updated_at"
28
+ ];
29
+ const DEFAULT_CLAIMS = {
30
+ id: "sub",
31
+ roles: "roles",
32
+ groups: "groups",
33
+ entitlements: "entitlements",
34
+ session: "sid"
35
+ };
36
+ function asStringArray(value) {
37
+ if (typeof value === "string") return value.length === 0 ? [] : value.split(/[,\s]+/u).filter(Boolean);
38
+ if (!Array.isArray(value)) return [];
39
+ const out = [];
40
+ for (const item of value) {
41
+ if (typeof item === "string") {
42
+ out.push(item);
43
+ continue;
44
+ }
45
+ if (item !== null && typeof item === "object" && "value" in item && typeof item.value === "string") out.push(item.value);
46
+ }
47
+ return out;
48
+ }
49
+ function kindOf(claims, paths) {
50
+ const kind = paths?.kind;
51
+ if (kind === "workload" || kind === "user" || kind === "service") return kind;
52
+ if (kind !== void 0) {
53
+ const value = readPath(claims, kind);
54
+ if (value === "workload" || value === "user" || value === "service") return value;
55
+ }
56
+ }
57
+ function assuranceOf(claims, paths) {
58
+ const configured = paths?.assurance;
59
+ const acrPath = typeof configured === "string" ? configured : configured?.acr ?? "acr";
60
+ const amrPath = typeof configured === "string" ? "amr" : configured?.amr ?? "amr";
61
+ const authTimePath = typeof configured === "string" ? "auth_time" : configured?.authTime ?? "auth_time";
62
+ const verifiedPath = typeof configured === "string" ? "verified_claims" : configured?.verified ?? "verified_claims";
63
+ const acr = readPath(claims, acrPath);
64
+ const amr = readPath(claims, amrPath);
65
+ const authTime = readPath(claims, authTimePath);
66
+ const assurance = compact({
67
+ acr: typeof acr === "string" ? acr : void 0,
68
+ amr: Array.isArray(amr) ? amr.filter((item) => typeof item === "string") : void 0,
69
+ authTime: typeof authTime === "number" ? authTime : void 0,
70
+ verified: verifiedClaimsOf(readPath(claims, verifiedPath))
71
+ });
72
+ return Object.keys(assurance).length === 0 ? void 0 : assurance;
73
+ }
74
+ function isPlainRecord(value) {
75
+ return value !== null && typeof value === "object" && !Array.isArray(value);
76
+ }
77
+ function hasForbiddenKey(value, depth = 0) {
78
+ if (depth > 16) return true;
79
+ if (Array.isArray(value)) return value.some((item) => hasForbiddenKey(item, depth + 1));
80
+ if (!isPlainRecord(value)) return false;
81
+ return Object.keys(value).some((key) => isForbiddenKey(key) || hasForbiddenKey(value[key], depth + 1));
82
+ }
83
+ /**
84
+ * `verified_claims` is one object or an array (OIDC4IDA section 5); an entry
85
+ * without `verification.trust_framework` and a `claims` object is dropped.
86
+ */
87
+ function verifiedClaimsOf(value) {
88
+ const verified = (Array.isArray(value) ? value : [value]).filter((entry) => isPlainRecord(entry) && isPlainRecord(entry["verification"]) && typeof entry["verification"]["trust_framework"] === "string" && isPlainRecord(entry["claims"]) && !hasForbiddenKey(entry));
89
+ return verified.length === 0 ? void 0 : freezeDeep(verified.map((entry) => ({
90
+ verification: entry.verification,
91
+ claims: entry.claims
92
+ })));
93
+ }
94
+ function bindingOf(claims) {
95
+ const cnf = claims["cnf"];
96
+ if (cnf === null || typeof cnf !== "object" || Array.isArray(cnf)) return;
97
+ const record = cnf;
98
+ const binding = compact({
99
+ jkt: typeof record["jkt"] === "string" ? record["jkt"] : void 0,
100
+ "x5t#S256": typeof record["x5t#S256"] === "string" ? record["x5t#S256"] : void 0,
101
+ jwk: record["jwk"] !== null && typeof record["jwk"] === "object" ? record["jwk"] : void 0,
102
+ kid: typeof record["kid"] === "string" ? record["kid"] : void 0
103
+ });
104
+ return Object.keys(binding).length === 0 ? void 0 : binding;
105
+ }
106
+ /** Group roles hold in the active tenant; the group itself is only the `via`. */
107
+ function membershipsFromGroups(groups, groupRoles, tenant) {
108
+ if (tenant === void 0) return [];
109
+ return groups.map((group) => compact({
110
+ tenant,
111
+ roles: groupRoles?.[group] ?? [],
112
+ via: `group:${group}`
113
+ }));
114
+ }
115
+ function stringRecord(value) {
116
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return;
117
+ const out = {};
118
+ for (const [key, item] of Object.entries(value)) if (typeof item === "string") out[key] = item;
119
+ return out;
120
+ }
121
+ function claimExtras(record) {
122
+ return compact({
123
+ via: typeof record["via"] === "string" ? record["via"] : void 0,
124
+ expiresAt: typeof record["expiresAt"] === "number" ? record["expiresAt"] : void 0
125
+ });
126
+ }
127
+ function membershipsFromClaim(value) {
128
+ if (Array.isArray(value)) return value.flatMap((item) => membershipsFromClaim(item));
129
+ if (value === null || typeof value !== "object") return [];
130
+ const record = value;
131
+ if (typeof record["scope"] === "string" && typeof record["id"] === "string") return [compact({
132
+ scope: record["scope"],
133
+ id: record["id"],
134
+ within: stringRecord(record["within"]),
135
+ roles: asStringArray(record["roles"]),
136
+ ...claimExtras(record)
137
+ })];
138
+ if (typeof record["tenant"] === "string" || typeof record["org_id"] === "string") return [compact({
139
+ tenant: typeof record["tenant"] === "string" ? record["tenant"] : String(record["org_id"]),
140
+ roles: asStringArray(record["roles"]),
141
+ team: typeof record["team"] === "string" ? record["team"] : void 0,
142
+ ...claimExtras(record)
143
+ })];
144
+ const out = [];
145
+ const byOrganisation = /* @__PURE__ */ new Map();
146
+ for (const [tenant, entry] of Object.entries(record)) {
147
+ if (Array.isArray(entry)) {
148
+ out.push(compact({
149
+ tenant,
150
+ roles: asStringArray(entry)
151
+ }));
152
+ continue;
153
+ }
154
+ if (entry !== null && typeof entry === "object") {
155
+ const nested = entry;
156
+ if (isRoleToOrganisations(nested)) {
157
+ for (const organisation of Object.keys(nested)) {
158
+ const roles = byOrganisation.get(organisation) ?? [];
159
+ roles.push(tenant);
160
+ byOrganisation.set(organisation, roles);
161
+ }
162
+ continue;
163
+ }
164
+ out.push(compact({
165
+ tenant,
166
+ roles: asStringArray(nested["roles"] ?? nested)
167
+ }));
168
+ }
169
+ }
170
+ for (const [tenant, roles] of byOrganisation) out.push({
171
+ tenant,
172
+ roles
173
+ });
174
+ return out;
175
+ }
176
+ /** Zitadel's `role -> { orgId: orgDomain }` form: string values and no `roles` key. */
177
+ function isRoleToOrganisations(value) {
178
+ const entries = Object.entries(value);
179
+ return entries.length > 0 && !("roles" in value) && entries.every(([key, item]) => typeof item === "string" && !isForbiddenKey(key));
180
+ }
181
+ function isActObject(value) {
182
+ return value !== null && typeof value === "object" && !Array.isArray(value);
183
+ }
184
+ function actorFromAct(claims, options) {
185
+ const configured = options.actor;
186
+ if (typeof configured === "function") {
187
+ const actor = configured(claims);
188
+ return actor === void 0 ? { status: "absent" } : {
189
+ status: "ok",
190
+ actor,
191
+ chain: claims["act"]
192
+ };
193
+ }
194
+ if (!Object.hasOwn(claims, "act") || claims["act"] === void 0) return { status: "absent" };
195
+ const act = claims["act"];
196
+ if (!isActObject(act)) return { status: "invalid" };
197
+ let current = act;
198
+ while (current !== void 0) {
199
+ if (!isActObject(current) || typeof current.sub !== "string" || current.sub.length === 0) return { status: "invalid" };
200
+ current = Object.hasOwn(current, "act") ? current.act : void 0;
201
+ }
202
+ if (typeof act.sub !== "string") return { status: "invalid" };
203
+ return {
204
+ status: "ok",
205
+ actor: compact({
206
+ id: act.sub,
207
+ kind: configured?.kind ?? "oauth-client"
208
+ }),
209
+ chain: act
210
+ };
211
+ }
212
+ function delegationOf(claims, options, chain) {
213
+ const paths = options.delegation;
214
+ const scopes = asStringArray(readPath(claims, paths?.scopes ?? "scope"));
215
+ const details = readPath(claims, paths?.authorizationDetails ?? "authorization_details");
216
+ const access = readPath(claims, paths?.access ?? "access");
217
+ const authorizationDetails = Array.isArray(details) ? details : void 0;
218
+ const accessList = Array.isArray(access) ? access : void 0;
219
+ const delegation = compact({
220
+ scopes: scopes.length > 0 ? scopes : void 0,
221
+ authorizationDetails,
222
+ access: accessList,
223
+ chain
224
+ });
225
+ return Object.keys(delegation).length === 0 ? void 0 : delegation;
226
+ }
227
+ function customClaims(claims, reserved) {
228
+ const out = {};
229
+ for (const [key, value] of Object.entries(claims)) {
230
+ if (reserved.includes(key)) continue;
231
+ out[key] = value;
232
+ }
233
+ return out;
234
+ }
235
+ function validateCustomClaims(claims, schema) {
236
+ const result = schema["~standard"].validate(claims);
237
+ if (result instanceof Promise) {
238
+ ignoreRejection(result);
239
+ return { ok: false };
240
+ }
241
+ if ("issues" in result && result.issues !== void 0) return { ok: false };
242
+ return {
243
+ ok: true,
244
+ value: result.value
245
+ };
246
+ }
247
+ function mapClaimsToSubject(claims, options) {
248
+ const paths = options.claims;
249
+ const idPath = paths?.id ?? DEFAULT_CLAIMS.id;
250
+ const id = readPath(claims, idPath);
251
+ if (typeof id !== "string" || id.length === 0) return {
252
+ subject: anonymousSubject(),
253
+ invalidClaims: false,
254
+ invalidChain: false
255
+ };
256
+ const tenantPath = paths?.tenant;
257
+ const tenant = tenantPath === void 0 ? void 0 : readPath(claims, tenantPath);
258
+ const activeTenant = typeof tenant === "string" ? tenant : void 0;
259
+ const roles = asStringArray(readPath(claims, paths?.roles ?? DEFAULT_CLAIMS.roles));
260
+ const plans = asStringArray(readPath(claims, paths?.plans ?? paths?.entitlements ?? DEFAULT_CLAIMS.entitlements));
261
+ const groups = asStringArray(readPath(claims, paths?.groups ?? DEFAULT_CLAIMS.groups));
262
+ const memberships = [...membershipsFromClaim(paths?.memberships === void 0 ? void 0 : readPath(claims, paths.memberships)), ...membershipsFromGroups(groups, options.groupRoles, activeTenant)];
263
+ let extra = customClaims(claims, [
264
+ "iss",
265
+ "sub",
266
+ "aud",
267
+ "exp",
268
+ "nbf",
269
+ "iat",
270
+ "jti",
271
+ "client_id",
272
+ "scope",
273
+ "cnf",
274
+ "act",
275
+ "sid",
276
+ "acr",
277
+ "amr",
278
+ "auth_time",
279
+ "roles",
280
+ "groups",
281
+ "entitlements",
282
+ "authorization_details",
283
+ "access",
284
+ "nonce",
285
+ "azp",
286
+ ...PROFILE_CLAIMS
287
+ ]);
288
+ let invalidClaims = false;
289
+ if (options.schema !== void 0) {
290
+ const validated = validateCustomClaims(extra, options.schema);
291
+ if (validated.ok) extra = validated.value;
292
+ else {
293
+ extra = {};
294
+ invalidClaims = true;
295
+ }
296
+ }
297
+ const binding = bindingOf(claims);
298
+ const act = actorFromAct(claims, options);
299
+ if (act.status === "invalid") return {
300
+ subject: anonymousSubject(),
301
+ invalidClaims: false,
302
+ invalidChain: true
303
+ };
304
+ const principal = freezeDeep(compact({
305
+ id,
306
+ issuer: typeof claims.iss === "string" ? claims.iss : void 0,
307
+ kind: kindOf(claims, paths),
308
+ roles: roles.length > 0 ? roles : void 0,
309
+ plans: plans.length > 0 ? plans : void 0,
310
+ memberships: memberships.length > 0 ? memberships : void 0,
311
+ tenant: activeTenant,
312
+ assurance: assuranceOf(claims, paths),
313
+ binding: act.status === "absent" ? binding : void 0,
314
+ claims: Object.keys(extra).length === 0 ? void 0 : extra
315
+ }));
316
+ const actor = act.status === "absent" ? void 0 : freezeDeep(compact({
317
+ ...act.actor,
318
+ binding
319
+ }));
320
+ const sessionPath = paths?.session ?? DEFAULT_CLAIMS.session;
321
+ const sessionValue = readPath(claims, sessionPath);
322
+ const sessionExpiry = claims["session_expiry"];
323
+ const exp = typeof claims.exp === "number" ? claims.exp : void 0;
324
+ const expiresAt = typeof sessionExpiry === "number" && exp !== void 0 ? Math.min(exp, sessionExpiry) : exp;
325
+ return {
326
+ subject: freezeDeep(compact({
327
+ principal,
328
+ actor,
329
+ delegation: options.accept === "id-token" ? void 0 : delegationOf(claims, options, act.status === "ok" ? act.chain : void 0),
330
+ context: {},
331
+ session: typeof sessionValue === "string" ? sessionValue : void 0,
332
+ expiresAt
333
+ })),
334
+ invalidClaims,
335
+ invalidChain: false
336
+ };
337
+ }
338
+ function acceptMismatch(claims, headerTyp, options, audience) {
339
+ const accept = options.accept ?? "access-token";
340
+ const typ = headerTyp?.toLowerCase();
341
+ if (accept === "id-token") {
342
+ if (typ !== void 0 && typ !== "jwt" && typ !== "application/jwt") return true;
343
+ if (typeof claims.iat !== "number") return true;
344
+ const aud = claims.aud;
345
+ const audiences = Array.isArray(aud) ? aud : aud === void 0 ? [] : [aud];
346
+ const clients = audience === void 0 ? [] : typeof audience === "string" ? [audience] : audience;
347
+ const azp = claims["azp"];
348
+ if (azp === void 0) return audiences.length > 1;
349
+ return typeof azp !== "string" || !clients.includes(azp);
350
+ }
351
+ if (options.profile === "fapi2" && typ !== "at+jwt") return true;
352
+ if (typeof claims["nonce"] === "string") return true;
353
+ if (audience !== void 0 && typeof claims.aud === "string") {
354
+ const expected = typeof audience === "string" ? audience : audience[0];
355
+ if (claims.aud !== expected && typ !== "at+jwt") return true;
356
+ }
357
+ return false;
358
+ }
359
+ //#endregion
360
+ export { mapClaimsToSubject as n, validateCustomClaims as r, acceptMismatch as t };
@@ -0,0 +1,16 @@
1
+ import { i as PermDockValidationError, n as PermDockDeniedError, r as PermDockRevokedError, t as PermDockApprovalRequiredError } from "./errors-Iy71s7Oj.js";
2
+ import { o as problemResponse } from "./problem-Cgp9-KZA.js";
3
+ import { r as InvalidSignatureError } from "./evaluations-DsAU9ppl.js";
4
+ //#region src/server/map-error.ts
5
+ /**
6
+ * Turns a thrown PermDock error into its Problem Details response. Returns
7
+ * `undefined` for anything else so the framework's own error path takes over.
8
+ */
9
+ function problemFromError(error) {
10
+ if (error instanceof InvalidSignatureError) return error.response;
11
+ if (error instanceof PermDockDeniedError || error instanceof PermDockApprovalRequiredError) return problemResponse(error.toProblemDetails(), void 0, error.decision);
12
+ if (error instanceof PermDockRevokedError) return problemResponse(error.toProblemDetails(), void 0, error.decision);
13
+ if (error instanceof PermDockValidationError) return problemResponse(error.toProblemDetails());
14
+ }
15
+ //#endregion
16
+ export { problemFromError as t };
@@ -0,0 +1,60 @@
1
+ //#region src/cli/markers.ts
2
+ const HOOK_MARKER = "-- permdock:hook v1";
3
+ /** The first line of a `--grants-out` file. */
4
+ const GRANTS_MARKER = "-- permdock:grants v1";
5
+ /** The first line of the `seeds` part: the `role_permissions` rows, a versioned migration. */
6
+ const SEEDS_MARKER = "-- permdock:seeds v1";
7
+ /** The first line of the `indexes` part: the indexes the policies and helpers read through. */
8
+ const INDEXES_MARKER = "-- permdock:indexes v1";
9
+ const HOOK_LINE = /^-- permdock:hook v(?<version>[1-9]\d*)(?: (?<rest>.*))?$/u;
10
+ const GRANTS_LINE = /^-- permdock:grants v(?<version>[1-9]\d*)(?: (?<rest>.*))?$/u;
11
+ function firstLine(sql) {
12
+ return (sql.split("\n", 1)[0] ?? "").replace(/\r$/u, "");
13
+ }
14
+ /** The `key=value` pairs after the marker, in a prototype-less object. */
15
+ function pairs(rest) {
16
+ const fields = Object.create(null);
17
+ for (const pair of (rest ?? "").split(" ")) {
18
+ const eq = pair.indexOf("=");
19
+ if (eq > 0) fields[pair.slice(0, eq)] = pair.slice(eq + 1);
20
+ }
21
+ return fields;
22
+ }
23
+ /** The fields of a hook marker line, or undefined when `sql` does not start with one. */
24
+ function hookMarkerFields(sql) {
25
+ const line = firstLine(sql);
26
+ return line.startsWith(`-- permdock:hook v1 `) ? pairs(line.slice(20)) : void 0;
27
+ }
28
+ /**
29
+ * Reads the `-- permdock:hook v<N>` line that starts a generated hook
30
+ * migration. Undefined when the first line is not a hook marker.
31
+ */
32
+ function parseHookMarker(sql) {
33
+ const match = HOOK_LINE.exec(firstLine(sql));
34
+ if (match?.groups === void 0) return;
35
+ const fields = pairs(match.groups["rest"]);
36
+ const budget = Number(fields["budget"]);
37
+ const claims = fields["claims"];
38
+ return Object.freeze({
39
+ version: Number(match.groups["version"]),
40
+ ...fields["schema"] === void 0 ? {} : { schema: fields["schema"] },
41
+ ...fields["tenant"] === void 0 ? {} : { tenantClaim: fields["tenant"] },
42
+ ...Number.isSafeInteger(budget) && budget > 0 ? { budget } : {},
43
+ claims: Object.freeze(claims === void 0 || claims === "" ? [] : claims.split(",").filter((name) => name !== ""))
44
+ });
45
+ }
46
+ /**
47
+ * Reads the `-- permdock:grants v<N>` line that starts a `--grants-out`
48
+ * migration. Undefined when the first line is not a grants marker.
49
+ */
50
+ function parseGrantsMarker(sql) {
51
+ const match = GRANTS_LINE.exec(firstLine(sql));
52
+ if (match?.groups === void 0) return;
53
+ const fields = pairs(match.groups["rest"]);
54
+ return Object.freeze({
55
+ version: Number(match.groups["version"]),
56
+ ...fields["schema"] === void 0 ? {} : { schema: fields["schema"] }
57
+ });
58
+ }
59
+ //#endregion
60
+ export { hookMarkerFields as a, SEEDS_MARKER as i, HOOK_MARKER as n, parseGrantsMarker as o, INDEXES_MARKER as r, parseHookMarker as s, GRANTS_MARKER as t };
@@ -0,0 +1,37 @@
1
+ import { f as tenantOf, u as scopeList } from "./scopes-cKVp_WTw.js";
2
+ import { u as coveredByDelegation } from "./snapshot-DE8dE_hz.js";
3
+ //#region src/core/may-use.ts
4
+ function delegationMayCover(permission, delegation, hasActor) {
5
+ return [void 0, ...[...delegation?.access ?? [], ...delegation?.authorizationDetails ?? []].flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry["identifier"] === "string" ? [entry["identifier"]] : [])].some((id) => coveredByDelegation(permission, delegation, id, hasActor) === void 0);
6
+ }
7
+ function blocksEveryRow(grant) {
8
+ return grant.effect === "deny" && grant.where === void 0 && grant.check === void 0 && grant.portable !== false && grant.fields === void 0 && (grant.scope === void 0 || grant.scope === "tenant");
9
+ }
10
+ /**
11
+ * Whether `permission` could be granted to this instance's subject for some
12
+ * row: the grants its snapshot carries for the active tenant, minus an
13
+ * unconditional deny, within its delegation. A listing hint for tools and
14
+ * skills, never a decision; the call itself is decided in full.
15
+ */
16
+ function mayUse(permdock, permission) {
17
+ try {
18
+ const snapshot = permdock.snapshot();
19
+ if (!("grants" in snapshot)) return false;
20
+ const ceiling = snapshot.delegated;
21
+ if (ceiling !== void 0 && !ceiling.includes(permission.key)) return false;
22
+ if (!delegationMayCover(permission, permdock.subject.delegation, permdock.subject.actor !== void 0 && ceiling === void 0)) return false;
23
+ const tenant = permdock.subject.principal?.tenant;
24
+ const scopes = scopeList(snapshot.scopes);
25
+ const grants = snapshot.grants.filter((grant) => {
26
+ if (grant.permission !== permission.key) return false;
27
+ const owner = grant.membership === void 0 ? void 0 : tenantOf(grant.membership, scopes);
28
+ return owner === void 0 || owner === tenant;
29
+ });
30
+ if (grants.some(blocksEveryRow)) return false;
31
+ return grants.some((grant) => grant.effect === "allow");
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+ //#endregion
37
+ export { mayUse as t };