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,226 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { n as requiredPlans } from "./describe-Bt1YD5uS.js";
3
+ import { a as approvalMessage, i as PermDockValidationError, n as PermDockDeniedError, o as deniedMessage, t as PermDockApprovalRequiredError } from "./errors-Iy71s7Oj.js";
4
+ //#region src/server/problem.ts
5
+ const PROBLEM_BASE = "https://permdock.dev/problems";
6
+ function quoted(value) {
7
+ return `"${value.replaceAll(/["\\]/gu, "")}"`;
8
+ }
9
+ const UTF8 = /* @__PURE__ */ new TextEncoder();
10
+ /**
11
+ * An RFC 9651 sf-string: `"` and `\` escaped, and anything outside printable
12
+ * ASCII percent-encoded, which the grammar does not allow.
13
+ */
14
+ function sfString(value) {
15
+ return `"${value.replaceAll(/[\\"]/gu, (char) => `\\${char}`).replaceAll(/[^\u0020-\u007E]/gu, (char) => Array.from(UTF8.encode(char), (byte) => `%${byte.toString(16).toUpperCase().padStart(2, "0")}`).join(""))}"`;
16
+ }
17
+ /** An RFC 6750 `WWW-Authenticate: Bearer` value. */
18
+ function bearerChallenge(challenge) {
19
+ const parts = [`error=${quoted(challenge.error)}`];
20
+ if (challenge.description !== void 0) parts.push(`error_description=${quoted(challenge.description)}`);
21
+ if (challenge.scopes !== void 0 && challenge.scopes.length > 0) parts.push(`scope=${quoted([...new Set(challenge.scopes)].join(" "))}`);
22
+ if (challenge.acrValues !== void 0 && challenge.acrValues.length > 0) parts.push(`acr_values=${quoted(challenge.acrValues.join(" "))}`);
23
+ if (challenge.maxAge !== void 0) parts.push(`max_age=${quoted(String(challenge.maxAge))}`);
24
+ if (challenge.resourceMetadata !== void 0) parts.push(`resource_metadata=${quoted(challenge.resourceMetadata)}`);
25
+ return `Bearer ${parts.join(", ")}`;
26
+ }
27
+ /** The RFC 9728 well-known metadata URL for a resource identifier. */
28
+ function protectedResourceMetadataUrl(resource) {
29
+ const path = resource.pathname === "/" ? "" : resource.pathname;
30
+ return `${resource.origin}/.well-known/oauth-protected-resource${path}`;
31
+ }
32
+ /** The `acr` values and the tightest `maxAge` the failing assurance grants ask for. */
33
+ function stepUpOf(decision) {
34
+ if (decision.outcome !== "denied") return {};
35
+ const acr = /* @__PURE__ */ new Set();
36
+ let maxAge;
37
+ for (const denial of decision.denials) {
38
+ if (denial.reason !== "insufficient-user-authentication") continue;
39
+ const grantees = denial.to === void 0 ? [] : Array.isArray(denial.to) ? denial.to : [denial.to];
40
+ for (const grantee of grantees) {
41
+ if (grantee.kind !== "assurance") continue;
42
+ for (const value of grantee.acr ?? []) acr.add(value);
43
+ if (grantee.maxAge !== void 0) maxAge = maxAge === void 0 ? grantee.maxAge : Math.min(maxAge, grantee.maxAge);
44
+ }
45
+ }
46
+ return compact({
47
+ acrValues: acr.size === 0 ? void 0 : [...acr],
48
+ maxAge
49
+ });
50
+ }
51
+ /** The `error_description` of every `invalid_token` challenge (RFC 6750 section 3.1). */
52
+ const INVALID_TOKEN = "The access token is invalid";
53
+ function wwwAuthenticate(decision, permission, credentials = true) {
54
+ if (decision.outcome !== "denied") return;
55
+ const reasons = new Set(decision.denials.map((denial) => denial.reason));
56
+ if (reasons.has("insufficient-user-authentication")) return bearerChallenge({
57
+ error: "insufficient_user_authentication",
58
+ ...stepUpOf(decision)
59
+ });
60
+ if (reasons.has("anonymous")) return credentials ? bearerChallenge({
61
+ error: "invalid_token",
62
+ description: INVALID_TOKEN
63
+ }) : "Bearer";
64
+ if (reasons.has("not-delegated") || reasons.has("no-delegation")) return bearerChallenge(compact({
65
+ error: "insufficient_scope",
66
+ scopes: permission === void 0 ? void 0 : [permission.scope]
67
+ }));
68
+ }
69
+ function problemResponse(details, permission, decision, extra, credentials) {
70
+ const headers = new Headers({
71
+ ...extra,
72
+ "content-type": "application/problem+json"
73
+ });
74
+ if (decision !== void 0) {
75
+ const challenge = wwwAuthenticate(decision, permission, credentials);
76
+ if (challenge !== void 0) headers.set("WWW-Authenticate", challenge);
77
+ }
78
+ return new Response(JSON.stringify(details), {
79
+ status: details.status,
80
+ headers
81
+ });
82
+ }
83
+ /** RFC 9457 413 for a batch over `max` evaluations. */
84
+ function batchTooLarge(max) {
85
+ return problemResponse({
86
+ type: `${PROBLEM_BASE}/payload-too-large`,
87
+ title: "Payload too large",
88
+ status: 413,
89
+ detail: `evaluations batch exceeds ${String(max)}`
90
+ });
91
+ }
92
+ function validationProblem(detail) {
93
+ return problemResponse(compact({
94
+ type: `${PROBLEM_BASE}/validation`,
95
+ title: "Invalid request",
96
+ status: 400,
97
+ detail
98
+ }));
99
+ }
100
+ function resourceRef(permission, data) {
101
+ const id = data !== null && typeof data === "object" && "id" in data ? data.id : void 0;
102
+ return compact({
103
+ type: permission.resource,
104
+ id: typeof id === "string" || typeof id === "number" ? String(id) : void 0
105
+ });
106
+ }
107
+ function isLimitDetail(value) {
108
+ if (value === null || typeof value !== "object") return false;
109
+ const { count, window, resetsAt } = value;
110
+ return Number.isFinite(count) && Number.isFinite(window) && Number.isFinite(resetsAt);
111
+ }
112
+ /**
113
+ * `Retry-After` plus the `RateLimit` / `RateLimit-Policy` fields of
114
+ * draft-ietf-httpapi-ratelimit-headers-11, one policy per exhausted grant.
115
+ */
116
+ function rateLimitHeaders(decision, now = Date.now() / 1e3) {
117
+ if (decision.outcome !== "denied") return {};
118
+ const policies = /* @__PURE__ */ new Map();
119
+ for (const denial of decision.denials) {
120
+ if (denial.reason !== "limit" || !isLimitDetail(denial.detail)) continue;
121
+ const name = denial.role ?? "default";
122
+ if (!policies.has(name)) policies.set(name, denial.detail);
123
+ }
124
+ if (policies.size === 0) return {};
125
+ const entries = [...policies].map(([name, detail]) => ({
126
+ name: sfString(name),
127
+ detail,
128
+ wait: Math.max(1, Math.ceil(detail.resetsAt - now))
129
+ }));
130
+ return {
131
+ "Retry-After": String(Math.min(...entries.map((entry) => entry.wait))),
132
+ RateLimit: entries.map((entry) => `${entry.name};r=0;t=${entry.wait}`).join(", "),
133
+ "RateLimit-Policy": entries.map((entry) => `${entry.name};q=${entry.detail.count};w=${entry.detail.window}`).join(", ")
134
+ };
135
+ }
136
+ /** Reasons that only arise once a matching grant was found, so they reveal nothing hidden. */
137
+ const HOLDS_GRANT = /* @__PURE__ */ new Set([
138
+ "insufficient-user-authentication",
139
+ "limit",
140
+ "limit-unavailable"
141
+ ]);
142
+ function problemFromDecision(decision, permission, subject, options = {}) {
143
+ const base = PROBLEM_BASE;
144
+ if (decision.outcome === "granted") return new Response(null, { status: 204 });
145
+ if (decision.outcome === "approval-required") {
146
+ const details = new PermDockApprovalRequiredError({
147
+ decision,
148
+ permission: permission.key,
149
+ scope: permission.scope,
150
+ resource: resourceRef(permission, void 0),
151
+ message: approvalMessage(permission.key, decision.reason, decision.token)
152
+ }).toProblemDetails(compact({ instance: options.instance }));
153
+ const approval = options.approval === void 0 || options.approval.at === void 0 && options.approval.hint === void 0 ? void 0 : compact({
154
+ at: options.approval.at,
155
+ hint: options.approval.hint
156
+ });
157
+ return problemResponse(compact({
158
+ ...details,
159
+ type: `${base}/approval-required`,
160
+ approval
161
+ }), permission, decision);
162
+ }
163
+ const reasons = new Set(decision.denials.map((denial) => denial.reason));
164
+ if (options.disclosure === "hide" && ![...reasons].every((reason) => HOLDS_GRANT.has(reason))) return notFoundProblem(options.instance);
165
+ if (decision.denials.some((denial) => denial.detail instanceof PermDockValidationError)) {
166
+ const validation = decision.denials[0]?.detail;
167
+ if (validation instanceof PermDockValidationError) return problemResponse(validation.toProblemDetails(), permission, decision);
168
+ }
169
+ const details = new PermDockDeniedError({
170
+ decision,
171
+ permission: permission.key,
172
+ scope: permission.scope,
173
+ resource: resourceRef(permission, void 0),
174
+ subject,
175
+ message: deniedMessage(permission.key, subject.principal?.id, decision.denials, decision.alternatives.map((leaf) => leaf.key))
176
+ }).toProblemDetails(compact({ instance: options.instance }));
177
+ if (reasons.has("anonymous")) return problemResponse(compact({
178
+ type: `${base}/unauthenticated`,
179
+ title: "Authentication required",
180
+ status: 401,
181
+ detail: "Authenticate and repeat the request",
182
+ instance: options.instance,
183
+ permission: permission.key
184
+ }), permission, decision, void 0, options.credentials);
185
+ if (reasons.has("insufficient-user-authentication")) return problemResponse(compact({
186
+ ...details,
187
+ status: 401,
188
+ type: `${base}/step-up-required`,
189
+ ...stepUpOf(decision)
190
+ }), permission, decision);
191
+ const plans = requiredPlans(decision);
192
+ if (plans.length > 0) return problemResponse({
193
+ ...details,
194
+ type: `${base}/not-entitled`,
195
+ title: "Plan upgrade required",
196
+ plans
197
+ }, permission, decision);
198
+ if (reasons.size > 0 && [...reasons].every((reason) => reason === "limit")) return problemResponse({
199
+ ...details,
200
+ status: 429,
201
+ type: `${base}/rate-limited`,
202
+ title: "Rate limit exceeded"
203
+ }, permission, decision, rateLimitHeaders(decision));
204
+ if (reasons.has("limit-unavailable") && [...reasons].every((reason) => reason === "limit" || reason === "limit-unavailable")) return problemResponse({
205
+ ...details,
206
+ status: 503,
207
+ type: `${base}/limit-unavailable`,
208
+ title: "Rate limit unavailable"
209
+ }, permission, decision);
210
+ return problemResponse({
211
+ ...details,
212
+ type: `${base}/denied`
213
+ }, permission, decision);
214
+ }
215
+ /** The `404` a missing row and a hidden one share, so the two read the same. */
216
+ function notFoundProblem(instance) {
217
+ return problemResponse(compact({
218
+ type: `${PROBLEM_BASE}/not-found`,
219
+ title: "Not found",
220
+ status: 404,
221
+ detail: "No such resource",
222
+ instance
223
+ }));
224
+ }
225
+ //#endregion
226
+ export { problemFromDecision as a, stepUpOf as c, notFoundProblem as i, validationProblem as l, batchTooLarge as n, problemResponse as o, bearerChallenge as r, protectedResourceMetadataUrl as s, PROBLEM_BASE as t, wwwAuthenticate as u };
@@ -0,0 +1,32 @@
1
+ import { cancel, confirm, isCancel, multiselect } from "@clack/prompts";
2
+ //#region src/cli/commands/prompt.ts
3
+ /** What a command reports when the person at the terminal cancels a prompt. */
4
+ const CANCELLED = {
5
+ code: 2,
6
+ output: "Cancelled."
7
+ };
8
+ /** A yes or no question; `undefined` when cancelled. */
9
+ async function ask(message) {
10
+ const answer = await confirm({ message });
11
+ if (isCancel(answer)) {
12
+ cancel();
13
+ return;
14
+ }
15
+ return answer;
16
+ }
17
+ /** Pick one or more of `options`, `initial` preselected; `undefined` when cancelled. */
18
+ async function pick(message, options, initial) {
19
+ const answer = await multiselect({
20
+ message,
21
+ options: options.map((option) => ({ ...option })),
22
+ initialValues: [...initial],
23
+ required: true
24
+ });
25
+ if (isCancel(answer)) {
26
+ cancel();
27
+ return;
28
+ }
29
+ return answer;
30
+ }
31
+ //#endregion
32
+ export { ask as n, pick as r, CANCELLED as t };
@@ -0,0 +1,138 @@
1
+ import { n as PermDockStoreContext, t as PermDockSnapshotPromiseContext } from "./context-gtAwAILx.js";
2
+ import { Suspense, use, useMemo, useSyncExternalStore } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/react/hooks.ts
5
+ function useStore() {
6
+ const store = use(PermDockStoreContext);
7
+ if (store === null) throw new Error("PermDock: hooks require <PermDockProvider>.");
8
+ const pending = use(PermDockSnapshotPromiseContext);
9
+ if (pending !== null) store.adopt(use(pending), pending);
10
+ return store;
11
+ }
12
+ function usePermDock() {
13
+ const store = useStore();
14
+ return useSyncExternalStore((listener) => store.subscribe(listener), () => store.get(), () => store.get());
15
+ }
16
+ function usePermission(permission, data) {
17
+ const store = useStore();
18
+ const permdock = useSyncExternalStore((listener) => store.subscribe(listener), () => store.get(), () => store.get());
19
+ return useMemo(() => store.permissionState(permission, data), [
20
+ store,
21
+ permdock,
22
+ permission,
23
+ data
24
+ ]);
25
+ }
26
+ function usePermissions(permissions, data) {
27
+ const store = useStore();
28
+ const permdock = useSyncExternalStore((listener) => store.subscribe(listener), () => store.get(), () => store.get());
29
+ return useMemo(() => {
30
+ const granted = [];
31
+ const byKey = {};
32
+ for (const permission of permissions) {
33
+ const state = store.permissionState(permission, data);
34
+ byKey[permission.key] = state;
35
+ if (state.allowed) granted.push(permission);
36
+ }
37
+ return new Proxy({
38
+ granted,
39
+ get(permission) {
40
+ return byKey[permission.key];
41
+ }
42
+ }, { get(target, prop, receiver) {
43
+ if (typeof prop === "string" && Object.hasOwn(byKey, prop)) return byKey[prop];
44
+ return Reflect.get(target, prop, receiver);
45
+ } });
46
+ }, [
47
+ store,
48
+ permdock,
49
+ permissions,
50
+ data
51
+ ]);
52
+ }
53
+ function useFilter(permission, rows) {
54
+ const permdock = usePermDock();
55
+ return useMemo(() => {
56
+ const result = [...permdock.filter(permission, rows)];
57
+ result.partial = permdock.where(permission).partial;
58
+ return result;
59
+ }, [
60
+ permdock,
61
+ permission,
62
+ rows
63
+ ]);
64
+ }
65
+ function useTenant() {
66
+ const permdock = usePermDock();
67
+ return {
68
+ tenant: permdock.subject.principal?.tenant ?? null,
69
+ tenants: permdock.tenants(),
70
+ switchTo: (id) => permdock.refresh({ tenant: id }),
71
+ status: permdock.status()
72
+ };
73
+ }
74
+ function useMemberships() {
75
+ return usePermDock().memberships();
76
+ }
77
+ function useRoles(options = {}) {
78
+ const permdock = usePermDock();
79
+ return { roles: (options.team === void 0 ? permdock : permdock.team(options.team)).heldRoles(options.tenant === void 0 ? void 0 : { tenant: options.tenant }) };
80
+ }
81
+ function useAssignableRoles() {
82
+ return usePermDock().assignableRoles();
83
+ }
84
+ function useAssignablePermissions(options = {}) {
85
+ return usePermDock().assignablePermissions(options);
86
+ }
87
+ function useSubject() {
88
+ const permdock = usePermDock();
89
+ const snapshot = permdock.snapshot();
90
+ const simulated = typeof snapshot === "object" && snapshot !== null && "simulated" in snapshot && snapshot.simulated === true;
91
+ return {
92
+ principal: permdock.subject.principal,
93
+ actor: permdock.subject.actor,
94
+ delegation: permdock.subject.delegation,
95
+ expiresAt: permdock.subject.expiresAt,
96
+ simulated
97
+ };
98
+ }
99
+ function useApproval(decision) {
100
+ const store = useStore();
101
+ useSyncExternalStore((listener) => store.subscribe(listener), () => store.get(), () => store.get());
102
+ return {
103
+ state: store.approvalState(decision),
104
+ token: decision.outcome === "approval-required" ? decision.token : void 0,
105
+ request: (note) => store.requestApproval(decision, note)
106
+ };
107
+ }
108
+ //#endregion
109
+ //#region src/react/protected.tsx
110
+ function Protected(props) {
111
+ if (props.pending === void 0) return /* @__PURE__ */ jsx(Guard, { ...props });
112
+ return /* @__PURE__ */ jsx(Suspense, {
113
+ fallback: props.pending,
114
+ children: /* @__PURE__ */ jsx(Guard, { ...props })
115
+ });
116
+ }
117
+ function Guard(props) {
118
+ const root = usePermDock();
119
+ const local = usePermission(props.permission, props.data);
120
+ const run = (permdock) => {
121
+ const decision = permdock.decide(props.permission, props.data);
122
+ return {
123
+ allowed: decision.outcome === "granted",
124
+ status: "ready",
125
+ decision
126
+ };
127
+ };
128
+ const { allowed, status, decision } = props.tenant === void 0 ? local : run(root.tenant(props.tenant));
129
+ if (status === "pending") return props.pending ?? null;
130
+ if (!allowed || decision.outcome !== "granted") {
131
+ if (typeof props.fallback === "function") return props.fallback(decision);
132
+ return props.fallback ?? null;
133
+ }
134
+ if (typeof props.children === "function") return props.children(decision);
135
+ return props.children;
136
+ }
137
+ //#endregion
138
+ export { useFilter as a, usePermission as c, useSubject as d, useTenant as f, useAssignableRoles as i, usePermissions as l, useApproval as n, useMemberships as o, useAssignablePermissions as r, usePermDock as s, Protected as t, useRoles as u };
@@ -0,0 +1,26 @@
1
+ import { E as PolicyVocabulary, Mn as Decision, pr as Membership } from "./policy-CInmNGkM.js";
2
+ import { d as Permission } from "./permissions-B4apnahQ.js";
3
+ import { r as Role } from "./vocabulary-Dk0fs-Jk.js";
4
+ import { a as FilterResult, c as PermissionState, d as TenantView, f as UseRolesOptions, l as ProtectedProps, r as ClientPermDock, s as PermissionSet, t as ApprovalHandle, u as SubjectView } from "./types-DbWdEfcm.js";
5
+ import { ReactNode } from "react";
6
+ //#region src/react/hooks.d.ts
7
+ declare function usePermDock<V extends PolicyVocabulary = PolicyVocabulary>(): ClientPermDock<V>;
8
+ declare function usePermission(permission: Permission, data?: unknown): PermissionState;
9
+ declare function usePermissions(permissions: readonly Permission[], data?: unknown): PermissionSet;
10
+ declare function useFilter<T>(permission: Permission<string, T, "instance">, rows: readonly T[]): FilterResult<T>;
11
+ declare function useTenant(): TenantView;
12
+ declare function useMemberships(): readonly Membership[];
13
+ declare function useRoles(options?: UseRolesOptions): {
14
+ readonly roles: readonly Role[];
15
+ };
16
+ declare function useAssignableRoles(): readonly Role[];
17
+ declare function useAssignablePermissions(options?: {
18
+ readonly tenant?: string;
19
+ }): readonly Permission[];
20
+ declare function useSubject(): SubjectView;
21
+ declare function useApproval(decision: Decision): ApprovalHandle;
22
+ //#endregion
23
+ //#region src/react/protected.d.ts
24
+ declare function Protected(props: ProtectedProps): ReactNode;
25
+ //#endregion
26
+ export { useFilter as a, usePermission as c, useSubject as d, useTenant as f, useAssignableRoles as i, usePermissions as l, useApproval as n, useMemberships as o, useAssignablePermissions as r, usePermDock as s, Protected as t, useRoles as u };
@@ -0,0 +1,23 @@
1
+ import { Mn as Decision } from "./policy-CInmNGkM.js";
2
+ import { d as Permission } from "./permissions-B4apnahQ.js";
3
+ import { i as ClientStatus } from "./types-DbWdEfcm.js";
4
+ import { t as ClientStore } from "./store-Bq90395i.js";
5
+ import { Snippet } from "svelte";
6
+ //#region src/svelte/protected.d.ts
7
+ type ProtectedProps = {
8
+ readonly permission: Permission;
9
+ readonly data?: unknown;
10
+ readonly tenant?: string;
11
+ readonly children?: Snippet<[Decision]>;
12
+ readonly pending?: Snippet;
13
+ readonly fallback?: Snippet<[Decision]>;
14
+ };
15
+ type ProtectedView = {
16
+ readonly allowed: boolean;
17
+ readonly status: ClientStatus;
18
+ readonly decision: Decision;
19
+ readonly slot: "pending" | "fallback" | "default";
20
+ };
21
+ declare function protectedView(store: ClientStore, reference: Permission, data?: unknown, tenant?: string, _generation?: number): ProtectedView;
22
+ //#endregion
23
+ export { protectedView as n, ProtectedProps as t };
@@ -0,0 +1,48 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { t as emptySnapshot } from "./from-snapshot-BMGnhmgv.js";
3
+ import { n as PermDockStoreContext, t as PermDockSnapshotPromiseContext } from "./context-gtAwAILx.js";
4
+ import { t as createClientStore } from "./store-C6hFW6ta.js";
5
+ import { useMemo } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ //#region src/react/provider.tsx
8
+ /** One hint per provider: the first check `endpoint: false` turns into a `server-only` denial. */
9
+ function hintOnce() {
10
+ let shown = false;
11
+ return (permission) => {
12
+ if (shown) return;
13
+ shown = true;
14
+ console.info(`PermDock: ${permission.key} needs the server (a closure, graph relation or period grant) and endpoint is false, so it is denied with reason server-only; check it with getPermission instead`);
15
+ };
16
+ }
17
+ function PermDockProvider(props) {
18
+ const promise = props.snapshotPromise ?? null;
19
+ const store = useMemo(() => createClientStore(compact({
20
+ snapshot: props.snapshot ?? emptySnapshot(),
21
+ endpoint: props.endpoint === false ? void 0 : props.endpoint,
22
+ onServerOnly: props.endpoint === false ? hintOnce() : void 0,
23
+ approvals: props.approvals,
24
+ tenant: props.tenant,
25
+ fetch: props.fetch,
26
+ headers: props.headers,
27
+ maxAge: props.maxAge,
28
+ verifier: props.verifier
29
+ })), [
30
+ props.snapshot,
31
+ props.endpoint,
32
+ props.approvals,
33
+ props.tenant,
34
+ props.fetch,
35
+ props.headers,
36
+ props.maxAge,
37
+ props.verifier
38
+ ]);
39
+ return /* @__PURE__ */ jsx(PermDockStoreContext, {
40
+ value: store,
41
+ children: /* @__PURE__ */ jsx(PermDockSnapshotPromiseContext, {
42
+ value: promise,
43
+ children: props.children
44
+ })
45
+ });
46
+ }
47
+ //#endregion
48
+ export { PermDockProvider as t };
@@ -0,0 +1,6 @@
1
+ import { o as PermDockProviderProps } from "./types-DbWdEfcm.js";
2
+ import { ReactElement } from "react";
3
+ //#region src/react/provider.d.ts
4
+ declare function PermDockProvider(props: PermDockProviderProps): ReactElement;
5
+ //#endregion
6
+ export { PermDockProvider as t };
@@ -0,0 +1,6 @@
1
+ import { a as requiredPlans, i as describe } from "../describe-DernyItf.js";
2
+ import { t as approvalHeaders } from "../headers-C8SHQccD.js";
3
+ import { a as FilterResult, c as PermissionState, d as TenantView, i as ClientStatus, l as ProtectedProps, n as ApprovalState, o as PermDockProviderProps, r as ClientPermDock, s as PermissionSet, t as ApprovalHandle, u as SubjectView } from "../types-DbWdEfcm.js";
4
+ import { a as useFilter, c as usePermission, d as useSubject, f as useTenant, i as useAssignableRoles, l as usePermissions, n as useApproval, o as useMemberships, r as useAssignablePermissions, s as usePermDock, t as Protected, u as useRoles } from "../protected-BuPAycJT.js";
5
+ import { t as PermDockProvider } from "../provider-wTAUda2v.js";
6
+ export { type ApprovalHandle, type ApprovalState, type ClientPermDock, type ClientStatus, type FilterResult, PermDockProvider, type PermDockProviderProps, type PermissionSet, type PermissionState, Protected, type ProtectedProps, type SubjectView, type TenantView, approvalHeaders, describe, requiredPlans, useApproval, useAssignablePermissions, useAssignableRoles, useFilter, useMemberships, usePermDock, usePermission, usePermissions, useRoles, useSubject, useTenant };
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ import { n as requiredPlans, t as describe } from "../describe-Bt1YD5uS.js";
3
+ import { t as approvalHeaders } from "../headers-B5RRv3Xm.js";
4
+ import { a as useFilter, c as usePermission, d as useSubject, f as useTenant, i as useAssignableRoles, l as usePermissions, n as useApproval, o as useMemberships, r as useAssignablePermissions, s as usePermDock, t as Protected, u as useRoles } from "../protected-B4K3BKoX.js";
5
+ import { t as PermDockProvider } from "../provider-_wx46HpB.js";
6
+ export { PermDockProvider, Protected, approvalHeaders, describe, requiredPlans, useApproval, useAssignablePermissions, useAssignableRoles, useFilter, useMemberships, usePermDock, usePermission, usePermissions, useRoles, useSubject, useTenant };
@@ -0,0 +1,2 @@
1
+ import { t as PermDockProvider } from "../provider-wTAUda2v.js";
2
+ export { PermDockProvider };
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ import { t as PermDockProvider } from "../provider-_wx46HpB.js";
3
+ export { PermDockProvider };
@@ -0,0 +1,42 @@
1
+ import { Et as TokenVerifier, gt as Snapshot } from "../policy-CInmNGkM.js";
2
+ import { a as requiredPlans, i as describe } from "../describe-DernyItf.js";
3
+ import { t as approvalHeaders } from "../headers-C8SHQccD.js";
4
+ import { a as FilterResult, c as PermissionState, d as TenantView, i as ClientStatus, l as ProtectedProps, n as ApprovalState, r as ClientPermDock, s as PermissionSet, t as ApprovalHandle, u as SubjectView } from "../types-DbWdEfcm.js";
5
+ import { a as useFilter, c as usePermission, d as useSubject, f as useTenant, i as useAssignableRoles, l as usePermissions, n as useApproval, o as useMemberships, r as useAssignablePermissions, s as usePermDock, t as Protected, u as useRoles } from "../protected-BuPAycJT.js";
6
+ import { t as ClientStore } from "../store-Bq90395i.js";
7
+ import { ReactElement, ReactNode } from "react";
8
+ //#region src/react-native/types.d.ts
9
+ type PermDockStorage = {
10
+ getItem(key: string): string | null | Promise<string | null>;
11
+ setItem(key: string, value: string): void | Promise<void>;
12
+ removeItem(key: string): void | Promise<void>;
13
+ };
14
+ type NativeRevalidate = "launch" | "focus" | number;
15
+ type NativePermDockProviderProps = {
16
+ readonly storage: PermDockStorage;
17
+ readonly snapshot?: Snapshot | string;
18
+ readonly snapshotUrl?: string;
19
+ readonly endpoint?: string;
20
+ readonly approvals?: string;
21
+ readonly tenant?: string;
22
+ readonly subjectId?: string;
23
+ readonly revalidate?: NativeRevalidate;
24
+ readonly subscribeForeground?: (listener: () => void) => () => void;
25
+ readonly fetch?: typeof fetch;
26
+ readonly headers?: Readonly<Record<string, string>>;
27
+ readonly maxAge?: number;
28
+ readonly verifier?: TokenVerifier;
29
+ readonly children: ReactNode;
30
+ };
31
+ //#endregion
32
+ //#region src/react-native/provider.d.ts
33
+ export declare function PermDockProvider(props: NativePermDockProviderProps): ReactElement;
34
+ //#endregion
35
+ //#region src/react-native/storage.d.ts
36
+ export declare function memoryStorage(initial?: Readonly<Record<string, string>>): PermDockStorage;
37
+ //#endregion
38
+ //#region src/react-native/store.d.ts
39
+ type NativeStoreOptions = Omit<NativePermDockProviderProps, "children">;
40
+ export declare function createNativeStore(options: NativeStoreOptions): ClientStore;
41
+ //#endregion
42
+ export { type ApprovalHandle, type ApprovalState, type ClientPermDock, type ClientStatus, type FilterResult, type NativePermDockProviderProps, type NativeRevalidate, type PermDockStorage, type PermissionSet, type PermissionState, Protected, type ProtectedProps, type SubjectView, type TenantView, approvalHeaders, describe, requiredPlans, useApproval, useAssignablePermissions, useAssignableRoles, useFilter, useMemberships, usePermDock, usePermission, usePermissions, useRoles, useSubject, useTenant };