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,194 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { r as PermDockRevokedError } from "./errors-Iy71s7Oj.js";
3
+ //#region src/server/connection.ts
4
+ /** `setTimeout` stores delays in a signed 32-bit integer. */
5
+ const MAX_DELAY = 2147483647;
6
+ const REVOKED = Object.freeze({
7
+ outcome: "denied",
8
+ denials: Object.freeze([Object.freeze({
9
+ role: null,
10
+ reason: "no-grant",
11
+ detail: "connection-revoked"
12
+ })]),
13
+ alternatives: Object.freeze([])
14
+ });
15
+ function principalId(permdock) {
16
+ return permdock.subject.principal?.id;
17
+ }
18
+ function nextMembershipExpiry(permdock, now) {
19
+ let next;
20
+ for (const membership of permdock.memberships()) {
21
+ const at = membership.expiresAt;
22
+ if (at !== void 0 && at > now && (next === void 0 || at < next)) next = at;
23
+ }
24
+ return next;
25
+ }
26
+ async function loadData(data) {
27
+ if (data === void 0) return {
28
+ ok: true,
29
+ value: void 0
30
+ };
31
+ if (typeof data !== "function") return {
32
+ ok: true,
33
+ value: data
34
+ };
35
+ const loaded = await data();
36
+ return loaded === null || loaded === void 0 ? {
37
+ ok: false,
38
+ value: void 0
39
+ } : {
40
+ ok: true,
41
+ value: loaded
42
+ };
43
+ }
44
+ function matches(event, permdock, tenant) {
45
+ if (event.principal !== principalId(permdock)) return false;
46
+ const session = permdock.subject.session;
47
+ if (event.session !== void 0 && session !== void 0 && event.session !== session) return false;
48
+ return !(event.kind === "changed" && event.tenant !== void 0 && tenant !== void 0 && event.tenant !== tenant);
49
+ }
50
+ /** Opens a long-lived connection. Never throws; a failure aborts. */
51
+ async function openConnection(input) {
52
+ const controller = new AbortController();
53
+ const timers = /* @__PURE__ */ new Set();
54
+ const decideOptions = compact({
55
+ source: "adapter",
56
+ adapter: input.adapter
57
+ });
58
+ let unsubscribe;
59
+ let closed = false;
60
+ let current;
61
+ let chain = Promise.resolve();
62
+ const clear = () => {
63
+ for (const timer of timers) clearTimeout(timer);
64
+ timers.clear();
65
+ unsubscribe?.();
66
+ unsubscribe = void 0;
67
+ };
68
+ const abort = (code, decision) => {
69
+ if (controller.signal.aborted) return;
70
+ clear();
71
+ controller.abort(new PermDockRevokedError(compact({
72
+ code,
73
+ permission: input.options.permission?.key,
74
+ decision
75
+ })));
76
+ };
77
+ const after = (ms, run) => {
78
+ const timer = setTimeout(() => {
79
+ timers.delete(timer);
80
+ run();
81
+ }, Math.max(0, Math.min(ms, MAX_DELAY)));
82
+ timers.add(timer);
83
+ };
84
+ /** `true` when `permdock` still holds the opening permission. */
85
+ const admits = async (permdock) => {
86
+ const { permission } = input.options;
87
+ if (permission === void 0) return true;
88
+ const loaded = await loadData(input.options.data);
89
+ if (!loaded.ok) {
90
+ abort("denied");
91
+ return false;
92
+ }
93
+ const decision = permdock.decide(permission, loaded.value, decideOptions);
94
+ if (decision.outcome !== "granted") {
95
+ abort("denied", decision);
96
+ return false;
97
+ }
98
+ return true;
99
+ };
100
+ let schedule;
101
+ const revalidate = () => {
102
+ chain = chain.then(async () => {
103
+ if (controller.signal.aborted || closed) return;
104
+ let next;
105
+ try {
106
+ next = await input.rebuild();
107
+ } catch {
108
+ abort("subject-changed");
109
+ return;
110
+ }
111
+ const id = principalId(next);
112
+ if (id === void 0 || current === void 0 || id !== principalId(current)) {
113
+ abort("subject-changed");
114
+ return;
115
+ }
116
+ if (!await admits(next)) return;
117
+ current = next;
118
+ for (const timer of timers) clearTimeout(timer);
119
+ timers.clear();
120
+ schedule?.(next);
121
+ }).catch(() => {
122
+ abort("subject-changed");
123
+ });
124
+ };
125
+ schedule = (permdock) => {
126
+ const now = Date.now() / 1e3;
127
+ const expiresAt = permdock.subject.expiresAt;
128
+ if (expiresAt !== void 0) {
129
+ if (expiresAt <= now) {
130
+ abort("expired");
131
+ return;
132
+ }
133
+ const wait = (expiresAt - now) * 1e3;
134
+ after(wait, () => {
135
+ if (wait > MAX_DELAY) {
136
+ schedule?.(current ?? permdock);
137
+ return;
138
+ }
139
+ abort("expired");
140
+ });
141
+ }
142
+ const membership = nextMembershipExpiry(permdock, now);
143
+ if (membership !== void 0) after((membership - now) * 1e3, revalidate);
144
+ const every = input.options.revalidate;
145
+ if (every !== void 0 && Number.isFinite(every) && every > 0) after(every, revalidate);
146
+ };
147
+ try {
148
+ current = await input.open();
149
+ } catch {
150
+ abort("denied");
151
+ }
152
+ if (current !== void 0 && !controller.signal.aborted && await admits(current)) {
153
+ schedule(current);
154
+ if (input.feed !== void 0 && !controller.signal.aborted) try {
155
+ unsubscribe = input.feed.subscribe((event) => {
156
+ if (current === void 0 || !matches(event, current, input.tenant)) return;
157
+ if (event.kind === "session-revoked") abort("session-revoked");
158
+ else revalidate();
159
+ });
160
+ } catch {
161
+ abort("expired");
162
+ }
163
+ }
164
+ const live = () => controller.signal.aborted || closed ? void 0 : current;
165
+ return Object.freeze({
166
+ get permdock() {
167
+ if (current === void 0) throw new PermDockRevokedError({ code: "denied" });
168
+ return current;
169
+ },
170
+ signal: controller.signal,
171
+ check(permission, data, checkOptions) {
172
+ const permdock = live();
173
+ if (permdock === void 0) return REVOKED;
174
+ return permdock.decide(permission, data, checkOptions?.trusted === true ? {
175
+ ...decideOptions,
176
+ trusted: true
177
+ } : {
178
+ ...decideOptions,
179
+ trusted: false,
180
+ boundary: "manual"
181
+ });
182
+ },
183
+ filter(permission, items) {
184
+ const permdock = live();
185
+ return permdock === void 0 ? [] : permdock.filter(permission, items, decideOptions);
186
+ },
187
+ close() {
188
+ closed = true;
189
+ clear();
190
+ }
191
+ });
192
+ }
193
+ //#endregion
194
+ export { openConnection };
@@ -0,0 +1,73 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { t as emptySnapshot } from "./from-snapshot-BMGnhmgv.js";
3
+ import { t as createClientStore } from "./store-C6hFW6ta.js";
4
+ import { t as isPromiseLike } from "./source-DoBBYJi2.js";
5
+ import { getContext, onDestroy, setContext } from "svelte";
6
+ import { toStore } from "svelte/store";
7
+ //#region src/svelte/context.ts
8
+ const permDockKey = Symbol("permdock");
9
+ function isReadable(value) {
10
+ return typeof value === "object" && value !== null && "subscribe" in value && typeof value.subscribe === "function";
11
+ }
12
+ function reactiveSource(source) {
13
+ if (typeof source === "function") return toStore(source);
14
+ return isReadable(source) ? source : void 0;
15
+ }
16
+ /**
17
+ * Builds the store; the returned `stop` ends the subscription to a reactive
18
+ * snapshot source.
19
+ */
20
+ function connectSvelteStore(options) {
21
+ const source = options.snapshot;
22
+ const promised = isPromiseLike(source);
23
+ const reactive = promised ? void 0 : reactiveSource(source);
24
+ let initial = emptySnapshot();
25
+ if (reactive !== void 0) reactive.subscribe((value) => {
26
+ initial = value;
27
+ })();
28
+ else if (!promised) initial = source;
29
+ const store = createClientStore(compact({
30
+ snapshot: initial,
31
+ endpoint: options.endpoint,
32
+ approvals: options.approvals,
33
+ tenant: options.tenant,
34
+ fetch: options.fetch,
35
+ headers: options.headers,
36
+ maxAge: options.maxAge,
37
+ verifier: options.verifier
38
+ }));
39
+ if (promised) {
40
+ store.follow(source);
41
+ return {
42
+ store,
43
+ stop: () => void 0
44
+ };
45
+ }
46
+ if (reactive === void 0) return {
47
+ store,
48
+ stop: () => void 0
49
+ };
50
+ let current = initial;
51
+ return {
52
+ store,
53
+ stop: reactive.subscribe((value) => {
54
+ if (value !== current) {
55
+ current = value;
56
+ store.replace(value);
57
+ }
58
+ })
59
+ };
60
+ }
61
+ function providePermDock(options) {
62
+ const { store, stop } = connectSvelteStore(options);
63
+ onDestroy(stop);
64
+ setContext(permDockKey, store);
65
+ return store;
66
+ }
67
+ function getStore() {
68
+ const store = getContext(permDockKey);
69
+ if (store === void 0) throw new Error("PermDock: stores require setPermDock.");
70
+ return store;
71
+ }
72
+ //#endregion
73
+ export { providePermDock as n, getStore as t };
@@ -0,0 +1,6 @@
1
+ import { createContext } from "react";
2
+ //#region src/react/context.ts
3
+ const PermDockStoreContext = createContext(null);
4
+ const PermDockSnapshotPromiseContext = createContext(null);
5
+ //#endregion
6
+ export { PermDockStoreContext as n, PermDockSnapshotPromiseContext as t };
@@ -0,0 +1,40 @@
1
+ import { C as Policy, E as PolicyVocabulary, Zt as PermDock, mr as Principal } from "../policy-CInmNGkM.js";
2
+ import { d as Permission } from "../permissions-B4apnahQ.js";
3
+ import { o as ProblemDetails, r as PermDockDeniedError } from "../errors-DbZ1YOnb.js";
4
+ //#region src/convex/types.d.ts
5
+ type ConvexCtxLike = {
6
+ readonly auth?: {
7
+ readonly getUserIdentity?: () => Promise<unknown>;
8
+ };
9
+ readonly db?: unknown;
10
+ };
11
+ type ConvexPermDockCtx<TCtx, V extends PolicyVocabulary = PolicyVocabulary> = TCtx & {
12
+ readonly permdock: PermDock<V>;
13
+ };
14
+ type ConvexSubject<TCtx, TUser = unknown> = (ctx: TCtx) => TUser | Promise<TUser>;
15
+ type ConvexQueryBuilder = (definition: {
16
+ readonly args: Record<string, never>;
17
+ readonly handler: (ctx: ConvexCtxLike, args: Record<string, never>) => unknown;
18
+ }) => unknown;
19
+ type ConvexPermDockOptions<TCtx, TUser = unknown> = {
20
+ readonly subject: ConvexSubject<TCtx, TUser>;
21
+ readonly query?: ConvexQueryBuilder;
22
+ };
23
+ type ConvexHandler<TCtx, TArgs, TResult, V extends PolicyVocabulary = PolicyVocabulary> = (ctx: ConvexPermDockCtx<TCtx, V>, args: TArgs) => TResult | Promise<TResult>;
24
+ type ConvexErrorData = ProblemDetails;
25
+ type ConvexPermDock<TCtx, V extends PolicyVocabulary = PolicyVocabulary> = {
26
+ readonly withPermDock: <TArgs, TResult>(handler: ConvexHandler<TCtx, TArgs, TResult, V>) => (ctx: TCtx, args: TArgs) => Promise<TResult>;
27
+ readonly snapshotQuery: (options?: {
28
+ readonly include?: readonly Permission[];
29
+ }) => unknown;
30
+ };
31
+ //#endregion
32
+ //#region src/convex/create.d.ts
33
+ export declare class ConvexError extends Error {
34
+ override readonly name = "ConvexError";
35
+ readonly data: ReturnType<PermDockDeniedError["toProblemDetails"]>;
36
+ constructor(data: ReturnType<PermDockDeniedError["toProblemDetails"]>);
37
+ }
38
+ export declare function createPermDock<TCtx, TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: ConvexPermDockOptions<TCtx, TUser>): ConvexPermDock<TCtx, V>;
39
+ //#endregion
40
+ export type { ConvexCtxLike, ConvexErrorData, ConvexHandler, ConvexPermDock, ConvexPermDockCtx, ConvexPermDockOptions, ConvexQueryBuilder, ConvexSubject };
@@ -0,0 +1,55 @@
1
+ import { t as compact } from "../compact-y6vfu2_f.js";
2
+ import { n as PermDockDeniedError, t as PermDockApprovalRequiredError } from "../errors-Iy71s7Oj.js";
3
+ import { t as createPermDock$1 } from "../permdock-yoZ7EjxX.js";
4
+ //#region src/convex/create.ts
5
+ var ConvexError = class extends Error {
6
+ name = "ConvexError";
7
+ data;
8
+ constructor(data) {
9
+ super(data.detail);
10
+ this.data = data;
11
+ }
12
+ };
13
+ function toConvexError(error) {
14
+ if (error instanceof PermDockDeniedError || error instanceof PermDockApprovalRequiredError) return new ConvexError(error.toProblemDetails());
15
+ return error;
16
+ }
17
+ function createPermDock(policy, options) {
18
+ const withPermDock = (handler) => {
19
+ return async (ctx, args) => {
20
+ let user = null;
21
+ try {
22
+ user = await options.subject(ctx);
23
+ } catch {
24
+ user = null;
25
+ }
26
+ const permdock = await createPermDock$1(policy, user);
27
+ const next = {
28
+ ...ctx,
29
+ permdock
30
+ };
31
+ try {
32
+ return await handler(next, args);
33
+ } catch (error) {
34
+ throw toConvexError(error);
35
+ }
36
+ };
37
+ };
38
+ const snapshotQuery = (snapshotOptions) => {
39
+ const handler = withPermDock((ctx, args) => {
40
+ return Promise.resolve(ctx.permdock.snapshot(compact({ include: snapshotOptions?.include })));
41
+ });
42
+ const definition = {
43
+ args: {},
44
+ handler: (ctx, args) => handler(ctx, args)
45
+ };
46
+ if (options.query !== void 0) return options.query(definition);
47
+ return definition;
48
+ };
49
+ return {
50
+ withPermDock,
51
+ snapshotQuery
52
+ };
53
+ }
54
+ //#endregion
55
+ export { ConvexError, createPermDock };
@@ -0,0 +1,162 @@
1
+ import { $ as DecisionSink, C as Policy, E as PolicyVocabulary, Mn as Decision, Zt as PermDock, at as LimitStore, ct as MembershipSource, fr as JsonWebKeyLike, ft as RelationSource, hr as Subject, ir as Actor, mr as Principal, pt as RoleSource, sn as PolicySource, tt as EntitlementSource, xt as SnapshotSource } from "./policy-CInmNGkM.js";
2
+ import { d as Permission } from "./permissions-B4apnahQ.js";
3
+ import { f as ApprovalStore } from "./types-B8w5PFtS.js";
4
+ import { t as ApprovalHint } from "./errors-DbZ1YOnb.js";
5
+ import { n as RevocationFeed } from "./revocations-Cy06JNx2.js";
6
+ import { r as PdpFactory } from "./types-BvBk1wgn.js";
7
+ //#region src/server/connection.d.ts
8
+ type ConnectionData<T> = T | (() => T | null | undefined | Promise<T | null | undefined>);
9
+ type ConnectionOptions<T = unknown> = {
10
+ /** The permission the stream or socket is opened for; re-checked after every revalidation. */
11
+ readonly permission?: Permission;
12
+ /** The row for `permission`, or a loader re-run on every revalidation. */
13
+ readonly data?: ConnectionData<T>;
14
+ /** Milliseconds between periodic revalidations; off by default. */
15
+ readonly revalidate?: number;
16
+ };
17
+ type Connection = {
18
+ /** The current instance; replaced, never mutated, after a revalidation. */
19
+ readonly permdock: PermDock;
20
+ /** Aborts with a `PermDockRevokedError` when the connection must end. */
21
+ readonly signal: AbortSignal;
22
+ /**
23
+ * Per-message decision. Data is validated against the resource schema
24
+ * first unless `{ trusted: true }` marks it as a row the server loaded.
25
+ */
26
+ readonly check: (permission: Permission, data?: unknown, options?: {
27
+ readonly trusted?: boolean;
28
+ }) => Decision;
29
+ readonly filter: <T>(permission: Permission<string, T, "instance">, items: readonly T[]) => T[];
30
+ /** Stops timers and the feed subscription. Call it when the transport closes. */
31
+ readonly close: () => void;
32
+ };
33
+ //#endregion
34
+ //#region src/server/web-bot-auth.d.ts
35
+ type WebBotAuthJwk = JsonWebKeyLike & {
36
+ readonly kid?: string;
37
+ readonly crv?: string;
38
+ };
39
+ type WebBotAuthKeyLookup = (input: {
40
+ readonly request: Request;
41
+ readonly keyid: string;
42
+ readonly agent: string | undefined;
43
+ }) => WebBotAuthJwk | undefined | Promise<WebBotAuthJwk | undefined>;
44
+ type WebBotAuthKeys = {
45
+ readonly lookup: WebBotAuthKeyLookup;
46
+ };
47
+ type WebBotAuthOptions = {
48
+ readonly verify?: boolean;
49
+ readonly keys: WebBotAuthKeys | WebBotAuthKeyLookup;
50
+ readonly required?: boolean;
51
+ readonly maxAge?: number;
52
+ /** Unix seconds; defaults to the system clock. */
53
+ readonly now?: () => number;
54
+ };
55
+ /**
56
+ * An adapter's `webBotAuth` option: `(request) => verifyWebBotAuth(request, options)`,
57
+ * so an app without it does not bundle RFC 9421 verification.
58
+ */
59
+ type WebBotAuthVerifier = (request: Request) => Promise<Actor | undefined>;
60
+ type DiscoverViaSignatureAgentOptions = {
61
+ readonly allow: readonly string[];
62
+ readonly fetch?: typeof fetch;
63
+ };
64
+ declare class InvalidSignatureError extends Error {
65
+ override readonly name: "InvalidSignatureError";
66
+ readonly response: Response;
67
+ constructor(response: Response);
68
+ }
69
+ declare function invalidSignatureResponse(error: unknown): Response | undefined;
70
+ declare function invalidSignatureProblem(detail: string): Response;
71
+ declare function discoverViaSignatureAgent(options: DiscoverViaSignatureAgentOptions): WebBotAuthKeys;
72
+ declare function verifyWebBotAuth(request: Request, options: WebBotAuthOptions | undefined): Promise<Actor | undefined>;
73
+ //#endregion
74
+ //#region src/server/evaluations.d.ts
75
+ declare function createEvaluationsHandler(options: {
76
+ readonly policy: Policy;
77
+ readonly resolve?: (request: Request) => Promise<PermDock>;
78
+ readonly getPermDock?: (query?: {
79
+ readonly tenant?: string;
80
+ }) => Promise<PermDock>;
81
+ readonly store?: ApprovalStore;
82
+ readonly adapter?: string;
83
+ /** The most evaluations one POST may carry; a larger batch is a 413 before any instance is resolved. */
84
+ readonly maxEvaluations?: number;
85
+ }): {
86
+ readonly POST: (request: Request) => Promise<Response>;
87
+ readonly GET: (request: Request) => Promise<Response>;
88
+ };
89
+ //#endregion
90
+ //#region src/server/create.d.ts
91
+ type ServerPermDockOptions<TUser = unknown> = {
92
+ /** The user, or a full `Subject` (core then skips `policy.subject`); `null` is anonymous. */
93
+ readonly subject: (request: Request) => TUser | Subject | null | Promise<TUser | Subject | null>;
94
+ readonly actor?: (request: Request) => unknown;
95
+ /** `(request) => verifyWebBotAuth(request, options)`; a verified bot becomes the actor. */
96
+ readonly webBotAuth?: WebBotAuthVerifier;
97
+ readonly tenant?: string | ((request: Request) => string | undefined | Promise<string | undefined>);
98
+ readonly memberships?: MembershipSource | readonly MembershipSource[];
99
+ /** The object graph for relation grants that walk a parent chain; without it they deny. */
100
+ readonly relations?: RelationSource;
101
+ readonly entitlements?: EntitlementSource;
102
+ readonly customRoles?: RoleSource;
103
+ /** Hosted grants, read once per instance; see `PolicySource`. */
104
+ readonly policies?: PolicySource;
105
+ readonly store?: ApprovalStore;
106
+ readonly sink?: DecisionSink;
107
+ readonly limits?: LimitStore;
108
+ /** Ends or revalidates open connections; never a decision input. */
109
+ readonly revocations?: RevocationFeed;
110
+ /**
111
+ * `createPermDock` from `permdock/pdp`: `protect` then decides delegated
112
+ * permissions through the remote PDP. The instance handlers receive stays
113
+ * synchronous and keeps denying delegated permissions (`pdp-unavailable`).
114
+ */
115
+ readonly pdp?: PdpFactory;
116
+ /** Accepted for adapter parity; HTTP adapters do not read it. */
117
+ readonly snapshots?: SnapshotSource;
118
+ /** Added as `approval` to every `approval-required` problem. */
119
+ readonly approval?: ApprovalHint;
120
+ };
121
+ type Guard<T = unknown, V extends PolicyVocabulary = PolicyVocabulary> = {
122
+ readonly ok: true;
123
+ readonly permdock: PermDock<V>;
124
+ readonly decision: Extract<Decision, {
125
+ readonly outcome: "granted";
126
+ }>;
127
+ readonly data: T;
128
+ } | {
129
+ readonly ok: false;
130
+ readonly response: Response;
131
+ };
132
+ type OpenApiHooks = {
133
+ readonly security: (permission: Permission) => {
134
+ readonly security: readonly Record<string, readonly string[]>[];
135
+ readonly "x-permdock-permissions": readonly string[];
136
+ };
137
+ readonly securitySchemes: () => Readonly<Record<string, unknown>>;
138
+ };
139
+ type ProtectOptions = {
140
+ /**
141
+ * `true` when `loadData` returns a row the server loaded itself, to skip
142
+ * schema validation. Anything else is validated against the resource
143
+ * schema before the check.
144
+ */
145
+ readonly trusted?: boolean;
146
+ };
147
+ type TenantOption<TContext> = string | ((context: TContext) => string | undefined | Promise<string | undefined>);
148
+ type ServerPermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
149
+ readonly permdock: (request: Request) => Promise<PermDock<V>>;
150
+ readonly protect: <T = unknown>(permission: Permission, loadData?: (request: Request) => T | null | undefined | Promise<T | null | undefined>, protectOptions?: ProtectOptions) => (request: Request) => Promise<Guard<T, V>>;
151
+ /** A long-lived connection for a stream or socket opened by `request`. */
152
+ readonly connection: <T = unknown>(request: Request, options?: ConnectionOptions<T>) => Promise<Connection>;
153
+ readonly problem: (decision: Decision, init?: {
154
+ readonly permission?: Permission;
155
+ readonly instance?: string;
156
+ }) => Response;
157
+ readonly openapi: OpenApiHooks;
158
+ readonly permdockHandler: () => ReturnType<typeof createEvaluationsHandler>;
159
+ };
160
+ declare function createPermDock<TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: ServerPermDockOptions<TUser>): ServerPermDock<V>;
161
+ //#endregion
162
+ export { ConnectionOptions as S, invalidSignatureProblem as _, ServerPermDockOptions as a, Connection as b, createEvaluationsHandler as c, WebBotAuthJwk as d, WebBotAuthKeyLookup as f, discoverViaSignatureAgent as g, WebBotAuthVerifier as h, ServerPermDock as i, DiscoverViaSignatureAgentOptions as l, WebBotAuthOptions as m, OpenApiHooks as n, TenantOption as o, WebBotAuthKeys as p, ProtectOptions as r, createPermDock as s, Guard as t, InvalidSignatureError as u, invalidSignatureResponse as v, ConnectionData as x, verifyWebBotAuth as y };