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,508 @@
1
+ import { t as compact } from "./compact-y6vfu2_f.js";
2
+ import { n as parseSnapshot } from "./snapshot-DE8dE_hz.js";
3
+ import { s as nowSeconds } from "./validity-D0uRmJKJ.js";
4
+ import { n as fromSnapshot, t as emptySnapshot } from "./from-snapshot-BMGnhmgv.js";
5
+ import { t as timeoutSignal } from "./timeout-D51niuQP.js";
6
+ //#region src/react/store.ts
7
+ /** Milliseconds a decision, refresh or approval request may take; a slower one is an error like a failed request. */
8
+ const STORE_TIMEOUT_MS = 1e4;
9
+ function cacheKey(permission, data) {
10
+ if (data === null || typeof data !== "object") return `${permission.key}:*`;
11
+ const id = data["id"];
12
+ return `${permission.key}:${typeof id === "string" || typeof id === "number" ? String(id) : "*"}`;
13
+ }
14
+ function withTenant(source, tenant) {
15
+ if (tenant === void 0) return source;
16
+ const hashAt = source.indexOf("#");
17
+ const hash = hashAt === -1 ? "" : source.slice(hashAt);
18
+ const rest = hashAt === -1 ? source : source.slice(0, hashAt);
19
+ const queryAt = rest.indexOf("?");
20
+ const path = queryAt === -1 ? rest : rest.slice(0, queryAt);
21
+ const params = new URLSearchParams(queryAt === -1 ? "" : rest.slice(queryAt + 1));
22
+ params.set("tenant", tenant);
23
+ return `${path}?${params.toString()}${hash}`;
24
+ }
25
+ function refKey(ref) {
26
+ if ("key" in ref && typeof ref.key === "string") return ref.key;
27
+ return "";
28
+ }
29
+ function isJws(value) {
30
+ const parts = value.split(".");
31
+ return parts.length === 3 && parts.every((part) => part.length > 0);
32
+ }
33
+ const CURRENT = Symbol.for("permdock.current");
34
+ const SERVER_ONLY = {
35
+ outcome: "denied",
36
+ denials: [{
37
+ role: null,
38
+ reason: "opaque-condition"
39
+ }],
40
+ alternatives: []
41
+ };
42
+ /** The client has no endpoint to ask (`endpoint: false`, or none given). */
43
+ const NO_ENDPOINT = {
44
+ outcome: "denied",
45
+ denials: [{
46
+ role: null,
47
+ reason: "server-only"
48
+ }],
49
+ alternatives: []
50
+ };
51
+ function needsEndpoint(decision) {
52
+ return decision.outcome === "denied" && decision.denials.some((denial) => denial.reason === "opaque-condition");
53
+ }
54
+ function createClientStore(options) {
55
+ const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
56
+ const server = options.server ?? globalThis.window === void 0;
57
+ const listeners = /* @__PURE__ */ new Set();
58
+ const answers = /* @__PURE__ */ new Map();
59
+ let queued = [];
60
+ let flushScheduled = false;
61
+ let emitScheduled = false;
62
+ let snapshot = emptySnapshot();
63
+ let tenant = options.tenant;
64
+ let base = "server-only";
65
+ let instance = fromSnapshot(snapshot, compact({ tenant }));
66
+ let cached;
67
+ let verifying = false;
68
+ let refreshing = 0;
69
+ let following = 0;
70
+ let refreshSeq = 0;
71
+ let silent = false;
72
+ let adopted;
73
+ let generation = 0;
74
+ const emit = () => {
75
+ cached = wrap(instance);
76
+ if (silent) return;
77
+ for (const listener of listeners) listener();
78
+ };
79
+ const emitSoon = () => {
80
+ if (emitScheduled) return;
81
+ emitScheduled = true;
82
+ queueMicrotask(() => {
83
+ emitScheduled = false;
84
+ emit();
85
+ });
86
+ };
87
+ const reset = () => {
88
+ generation += 1;
89
+ answers.clear();
90
+ queued = [];
91
+ };
92
+ const hydrate = (next) => {
93
+ reset();
94
+ snapshot = next;
95
+ instance = fromSnapshot(snapshot, compact({ tenant }));
96
+ base = "ready";
97
+ options.onSnapshot?.(next, tenant);
98
+ emit();
99
+ };
100
+ const storeStatus = () => {
101
+ if (verifying || refreshing > 0 || following > 0) return "pending";
102
+ if (base === "server-only") return "server-only";
103
+ if (base === "stale" || isStale()) return "stale";
104
+ for (const entry of answers.values()) if (entry.status === "pending") return "pending";
105
+ return "ready";
106
+ };
107
+ const isStale = () => {
108
+ const maxAge = snapshot.issuedAt > 0 ? options.maxAge : void 0;
109
+ if (snapshot.expiresAt === void 0 && maxAge === void 0) return false;
110
+ const now = nowSeconds();
111
+ if (snapshot.expiresAt !== void 0 && snapshot.expiresAt <= now) return true;
112
+ return maxAge !== void 0 && now - snapshot.issuedAt > maxAge;
113
+ };
114
+ const serverOnly = () => {
115
+ hydrate(emptySnapshot());
116
+ base = "server-only";
117
+ emit();
118
+ };
119
+ const applyParsed = (value) => {
120
+ try {
121
+ hydrate(parseSnapshot(value));
122
+ } catch {
123
+ serverOnly();
124
+ }
125
+ };
126
+ const verifyJws = async (raw) => {
127
+ if (options.verifier === void 0) return;
128
+ try {
129
+ const verified = await options.verifier.verify(raw, { typ: "permdock-snapshot+jwt" });
130
+ return verified.ok ? verified.claims["snapshot"] : void 0;
131
+ } catch {
132
+ return;
133
+ }
134
+ };
135
+ const bootJws = async (raw) => {
136
+ if (options.verifier === void 0) {
137
+ serverOnly();
138
+ return;
139
+ }
140
+ const started = generation;
141
+ verifying = true;
142
+ emit();
143
+ const claim = await verifyJws(raw);
144
+ verifying = false;
145
+ if (started !== generation) {
146
+ emit();
147
+ return;
148
+ }
149
+ if (claim === void 0) {
150
+ serverOnly();
151
+ return;
152
+ }
153
+ applyParsed(claim);
154
+ };
155
+ const scheduleFlush = () => {
156
+ if (flushScheduled || options.endpoint === void 0) return;
157
+ flushScheduled = true;
158
+ queueMicrotask(() => {
159
+ flushScheduled = false;
160
+ flush();
161
+ });
162
+ };
163
+ const flush = async () => {
164
+ const batch = queued;
165
+ queued = [];
166
+ if (batch.length === 0 || options.endpoint === void 0) return;
167
+ const started = generation;
168
+ if (snapshot.simulated === true) {
169
+ for (const item of batch) answers.set(item.key, {
170
+ decision: SERVER_ONLY,
171
+ status: "server-only"
172
+ });
173
+ emit();
174
+ return;
175
+ }
176
+ try {
177
+ const response = await fetchImpl(options.endpoint, {
178
+ method: "POST",
179
+ credentials: "include",
180
+ signal: timeoutSignal(STORE_TIMEOUT_MS),
181
+ headers: {
182
+ accept: "application/json",
183
+ "content-type": "application/json",
184
+ ...options.headers
185
+ },
186
+ body: JSON.stringify({ evaluations: batch.map((item) => ({
187
+ subject: {
188
+ type: instance.subject.principal?.kind ?? "user",
189
+ id: instance.subject.principal?.id ?? ""
190
+ },
191
+ action: { name: item.permission.action },
192
+ resource: {
193
+ type: item.permission.resource,
194
+ id: item.data !== null && typeof item.data === "object" && "id" in item.data ? String(item.data.id ?? "") : void 0,
195
+ properties: item.data
196
+ }
197
+ })) })
198
+ });
199
+ if (!response.ok) throw new Error("evaluations failed");
200
+ const body = await response.json();
201
+ if (started !== generation) return;
202
+ for (const [index, item] of batch.entries()) {
203
+ const decision = (body.evaluations?.[index])?.context?.permdock ?? SERVER_ONLY;
204
+ answers.set(item.key, {
205
+ decision,
206
+ status: "ready"
207
+ });
208
+ }
209
+ } catch {
210
+ if (started !== generation) return;
211
+ for (const item of batch) answers.set(item.key, {
212
+ decision: SERVER_ONLY,
213
+ status: "server-only"
214
+ });
215
+ }
216
+ emit();
217
+ };
218
+ const enqueue = (key, permission, data) => {
219
+ if (answers.has(key)) return;
220
+ if (options.endpoint === void 0) {
221
+ answers.set(key, {
222
+ decision: NO_ENDPOINT,
223
+ status: "server-only"
224
+ });
225
+ options.onServerOnly?.(permission);
226
+ emitSoon();
227
+ return;
228
+ }
229
+ answers.set(key, {
230
+ decision: SERVER_ONLY,
231
+ status: "pending"
232
+ });
233
+ queued.push({
234
+ permission,
235
+ data,
236
+ key
237
+ });
238
+ emitSoon();
239
+ scheduleFlush();
240
+ };
241
+ const permissionState = (permission, data) => {
242
+ const key = `${tenant ?? ""}|${cacheKey(permission, data)}`;
243
+ const hit = answers.get(key);
244
+ if (hit !== void 0) return {
245
+ allowed: hit.decision.outcome === "granted",
246
+ status: hit.status,
247
+ decision: hit.decision
248
+ };
249
+ const decision = instance.decide(permission, data);
250
+ if (needsEndpoint(decision)) {
251
+ if (server && options.endpoint !== void 0) return {
252
+ allowed: false,
253
+ status: "pending",
254
+ decision: SERVER_ONLY
255
+ };
256
+ enqueue(key, permission, data);
257
+ const next = answers.get(key);
258
+ if (next !== void 0) return {
259
+ allowed: false,
260
+ status: next.status,
261
+ decision: next.decision
262
+ };
263
+ return {
264
+ allowed: false,
265
+ status: "server-only",
266
+ decision: NO_ENDPOINT
267
+ };
268
+ }
269
+ return {
270
+ allowed: decision.outcome === "granted",
271
+ status: verifying || following > 0 ? "pending" : isStale() ? "stale" : "ready",
272
+ decision
273
+ };
274
+ };
275
+ const approvalInterval = options.approvalInterval ?? 2e3;
276
+ const approvals = /* @__PURE__ */ new Map();
277
+ const polls = /* @__PURE__ */ new Map();
278
+ let approvalEpoch = 0;
279
+ const TERMINAL = /* @__PURE__ */ new Set([
280
+ "approved",
281
+ "rejected",
282
+ "expired"
283
+ ]);
284
+ const stopPolls = () => {
285
+ for (const timer of polls.values()) clearTimeout(timer);
286
+ polls.clear();
287
+ };
288
+ const schedulePoll = (token) => {
289
+ if (server || options.approvals === void 0 || polls.has(token) || listeners.size === 0) return;
290
+ const epoch = approvalEpoch;
291
+ const href = `${options.approvals.replace(/\/+$/u, "")}/${encodeURIComponent(token)}`;
292
+ polls.set(token, setTimeout(() => {
293
+ (async () => {
294
+ let next;
295
+ try {
296
+ const response = await fetchImpl(href, {
297
+ method: "GET",
298
+ credentials: "include",
299
+ signal: timeoutSignal(STORE_TIMEOUT_MS),
300
+ headers: {
301
+ accept: "application/json",
302
+ ...options.headers
303
+ }
304
+ });
305
+ if (response.status === 404) next = "expired";
306
+ else if (response.ok) {
307
+ const body = await response.json();
308
+ next = body.status === "pending" || body.status === "approved" || body.status === "rejected" || body.status === "expired" ? body.status : void 0;
309
+ }
310
+ } catch {
311
+ next = void 0;
312
+ }
313
+ if (epoch !== approvalEpoch) return;
314
+ polls.delete(token);
315
+ if (next !== void 0 && approvals.get(token) !== next) {
316
+ approvals.set(token, next);
317
+ emit();
318
+ }
319
+ if (!TERMINAL.has(approvals.get(token) ?? "required")) schedulePoll(token);
320
+ })();
321
+ }, approvalInterval));
322
+ };
323
+ const approvalState = (decision) => {
324
+ if (decision.outcome !== "approval-required") return "not-needed";
325
+ const current = approvals.get(decision.token) ?? "required";
326
+ if (!TERMINAL.has(current)) schedulePoll(decision.token);
327
+ return current;
328
+ };
329
+ const subscribe = (listener) => {
330
+ listeners.add(listener);
331
+ return () => {
332
+ listeners.delete(listener);
333
+ if (listeners.size === 0) stopPolls();
334
+ };
335
+ };
336
+ const wrap = (permdock) => {
337
+ const client = {
338
+ ...permdock,
339
+ status(permission, data) {
340
+ if (permission === void 0) return storeStatus();
341
+ return permissionState(permission, data).status;
342
+ },
343
+ invalidate(ref) {
344
+ const prefix = refKey(ref);
345
+ for (const key of answers.keys()) {
346
+ const unscoped = key.slice(key.indexOf("|") + 1);
347
+ if (prefix === "" || unscoped === prefix || unscoped.startsWith(`${prefix}:`) || unscoped.startsWith(`${prefix}.`)) answers.delete(key);
348
+ }
349
+ base = "stale";
350
+ emit();
351
+ },
352
+ async refresh(query) {
353
+ const requested = query?.tenant;
354
+ const source = options.snapshotUrl ?? options.endpoint;
355
+ if (requested !== void 0 && (snapshot.tenants.includes(requested) || source === void 0)) {
356
+ tenant = requested;
357
+ hydrate(snapshot);
358
+ return;
359
+ }
360
+ if (source === void 0) return;
361
+ const started = generation;
362
+ refreshSeq += 1;
363
+ const seq = refreshSeq;
364
+ refreshing += 1;
365
+ emit();
366
+ let body;
367
+ let ok = false;
368
+ try {
369
+ const response = await fetchImpl(withTenant(source, requested), {
370
+ method: "GET",
371
+ credentials: "include",
372
+ signal: timeoutSignal(STORE_TIMEOUT_MS),
373
+ headers: {
374
+ accept: "application/json",
375
+ ...options.headers
376
+ }
377
+ });
378
+ if (response.ok) {
379
+ body = await response.json();
380
+ ok = true;
381
+ }
382
+ } catch {
383
+ ok = false;
384
+ }
385
+ if (ok && typeof body === "string" && isJws(body)) {
386
+ body = await verifyJws(body);
387
+ ok = body !== void 0;
388
+ }
389
+ refreshing -= 1;
390
+ if (started !== generation || seq !== refreshSeq) {
391
+ emit();
392
+ return;
393
+ }
394
+ let next;
395
+ try {
396
+ next = ok ? parseSnapshot(body) : void 0;
397
+ } catch {
398
+ next = void 0;
399
+ }
400
+ if (next === void 0) {
401
+ base = "stale";
402
+ emit();
403
+ return;
404
+ }
405
+ if (requested !== void 0) tenant = requested;
406
+ hydrate(next);
407
+ },
408
+ clear() {
409
+ reset();
410
+ tenant = options.tenant;
411
+ snapshot = emptySnapshot();
412
+ instance = fromSnapshot(snapshot, compact({ tenant }));
413
+ base = "server-only";
414
+ approvalEpoch += 1;
415
+ stopPolls();
416
+ approvals.clear();
417
+ options.onClear?.();
418
+ emit();
419
+ },
420
+ subscribe
421
+ };
422
+ Object.defineProperty(client, CURRENT, { value: () => cached });
423
+ return client;
424
+ };
425
+ const boot = (value) => {
426
+ if (typeof value === "string" && isJws(value)) {
427
+ cached = wrap(instance);
428
+ bootJws(value);
429
+ } else {
430
+ applyParsed(value);
431
+ cached = wrap(instance);
432
+ }
433
+ };
434
+ boot(options.snapshot);
435
+ return {
436
+ get() {
437
+ return cached;
438
+ },
439
+ subscribe,
440
+ permissionState,
441
+ approvalState,
442
+ replace(value) {
443
+ if (typeof value === "string" && isJws(value)) {
444
+ bootJws(value);
445
+ return;
446
+ }
447
+ applyParsed(value);
448
+ },
449
+ follow(value) {
450
+ const started = generation;
451
+ following += 1;
452
+ emit();
453
+ const settle = (next) => {
454
+ following -= 1;
455
+ if (started !== generation) {
456
+ emit();
457
+ return;
458
+ }
459
+ if (next === void 0) serverOnly();
460
+ else if (typeof next === "string" && isJws(next)) bootJws(next);
461
+ else applyParsed(next);
462
+ };
463
+ Promise.resolve(value).then(settle, () => {
464
+ settle(void 0);
465
+ });
466
+ },
467
+ adopt(value, source) {
468
+ if (adopted === source) return;
469
+ adopted = source;
470
+ reset();
471
+ silent = true;
472
+ try {
473
+ boot(value);
474
+ } finally {
475
+ silent = false;
476
+ }
477
+ queueMicrotask(emit);
478
+ },
479
+ snapshot() {
480
+ return snapshot;
481
+ },
482
+ async requestApproval(decision, note) {
483
+ if (decision.outcome !== "approval-required" || snapshot.simulated === true) return;
484
+ const href = options.approvals ?? options.endpoint;
485
+ if (href === void 0) return;
486
+ if ((await fetchImpl(href, {
487
+ method: "POST",
488
+ credentials: "include",
489
+ signal: timeoutSignal(STORE_TIMEOUT_MS),
490
+ headers: {
491
+ accept: "application/json",
492
+ "content-type": "application/json",
493
+ ...options.headers
494
+ },
495
+ body: JSON.stringify({
496
+ permission: decision.grant.permission,
497
+ token: decision.token,
498
+ note
499
+ })
500
+ })).ok && !TERMINAL.has(approvals.get(decision.token) ?? "required")) {
501
+ approvals.set(decision.token, "pending");
502
+ emit();
503
+ }
504
+ }
505
+ };
506
+ }
507
+ //#endregion
508
+ export { createClientStore as t };
@@ -0,0 +1,140 @@
1
+ import { n as providePermDock, t as getStore } from "./context-CKEAabd7.js";
2
+ import { readable, toStore } from "svelte/store";
3
+ //#region src/svelte/stores.ts
4
+ function fromStore(store, compute) {
5
+ return readable(compute(), (set) => {
6
+ const offStore = store.subscribe(() => {
7
+ set(compute());
8
+ });
9
+ const offRunes = toStore(compute).subscribe(set);
10
+ return () => {
11
+ offStore();
12
+ offRunes();
13
+ };
14
+ });
15
+ }
16
+ function sveltePermDock(store) {
17
+ return new Proxy({}, { get(_target, prop, _receiver) {
18
+ return Reflect.get(store.get(), prop);
19
+ } });
20
+ }
21
+ function setPermDock(options) {
22
+ return sveltePermDock(providePermDock(options));
23
+ }
24
+ function getPermDock() {
25
+ return sveltePermDock(getStore());
26
+ }
27
+ function permission(reference, data) {
28
+ return permissionFor(getStore(), reference, data);
29
+ }
30
+ function permissionFor(store, reference, data) {
31
+ return fromStore(store, () => store.permissionState(reference, data?.()));
32
+ }
33
+ function permissions(references, data) {
34
+ return permissionsFor(getStore(), references, data);
35
+ }
36
+ function permissionsFor(store, references, data) {
37
+ return fromStore(store, () => {
38
+ const granted = [];
39
+ const byKey = {};
40
+ for (const reference of references()) {
41
+ const next = store.permissionState(reference, data?.());
42
+ byKey[reference.key] = next;
43
+ if (next.allowed) granted.push(reference);
44
+ }
45
+ return new Proxy({
46
+ granted,
47
+ get(reference) {
48
+ return byKey[reference.key];
49
+ }
50
+ }, { get(target, prop, receiver) {
51
+ if (typeof prop === "string" && Object.hasOwn(byKey, prop)) return byKey[prop];
52
+ return Reflect.get(target, prop, receiver);
53
+ } });
54
+ });
55
+ }
56
+ function filtered(reference, rows) {
57
+ return filteredFor(getStore(), reference, rows);
58
+ }
59
+ function filteredFor(store, reference, rows) {
60
+ return fromStore(store, () => {
61
+ const permdock = store.get();
62
+ const next = permdock.filter(reference, rows());
63
+ next.partial = permdock.where(reference).partial;
64
+ return next;
65
+ });
66
+ }
67
+ function tenant() {
68
+ return tenantFor(getStore());
69
+ }
70
+ function tenantFor(store) {
71
+ return fromStore(store, () => {
72
+ const permdock = store.get();
73
+ return {
74
+ tenant: permdock.subject.principal?.tenant ?? null,
75
+ tenants: permdock.tenants(),
76
+ switchTo: (id) => permdock.refresh({ tenant: id }),
77
+ status: permdock.status()
78
+ };
79
+ });
80
+ }
81
+ function memberships() {
82
+ return membershipsFor(getStore());
83
+ }
84
+ function membershipsFor(store) {
85
+ return fromStore(store, () => store.get().memberships());
86
+ }
87
+ function roles(options = () => ({})) {
88
+ return rolesFor(getStore(), options);
89
+ }
90
+ function rolesFor(store, options = () => ({})) {
91
+ return fromStore(store, () => {
92
+ const next = options();
93
+ const permdock = store.get();
94
+ return { roles: (next.team === void 0 ? permdock : permdock.team(next.team)).heldRoles(next.tenant === void 0 ? void 0 : { tenant: next.tenant }) };
95
+ });
96
+ }
97
+ function assignable() {
98
+ return assignableFor(getStore());
99
+ }
100
+ function assignableFor(store) {
101
+ return fromStore(store, () => store.get().assignableRoles());
102
+ }
103
+ function assignablePermissions(options = {}) {
104
+ return assignablePermissionsFor(getStore(), options);
105
+ }
106
+ function assignablePermissionsFor(store, options = {}) {
107
+ return fromStore(store, () => store.get().assignablePermissions(options));
108
+ }
109
+ function subject() {
110
+ return subjectFor(getStore());
111
+ }
112
+ function subjectFor(store) {
113
+ return fromStore(store, () => {
114
+ const permdock = store.get();
115
+ const snapshot = permdock.snapshot();
116
+ const simulated = typeof snapshot === "object" && snapshot !== null && "simulated" in snapshot && snapshot.simulated === true;
117
+ return {
118
+ principal: permdock.subject.principal,
119
+ actor: permdock.subject.actor,
120
+ delegation: permdock.subject.delegation,
121
+ expiresAt: permdock.subject.expiresAt,
122
+ simulated
123
+ };
124
+ });
125
+ }
126
+ function approval(decision) {
127
+ return approvalFor(getStore(), decision);
128
+ }
129
+ function approvalFor(store, decision) {
130
+ return fromStore(store, () => {
131
+ const next = decision();
132
+ return {
133
+ state: store.approvalState(next),
134
+ token: next.outcome === "approval-required" ? next.token : void 0,
135
+ request: (note) => store.requestApproval(next, note)
136
+ };
137
+ });
138
+ }
139
+ //#endregion
140
+ export { getPermDock as a, permissions as c, subject as d, tenant as f, filtered as i, roles as l, assignable as n, memberships as o, assignablePermissions as r, permission as s, approval as t, setPermDock as u };
@@ -0,0 +1,41 @@
1
+ import { Et as TokenVerifier, Mn as Decision, gt as Snapshot, 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, r as ClientPermDock, s as PermissionSet, t as ApprovalHandle, u as SubjectView } from "./types-DbWdEfcm.js";
5
+ import { Readable } from "svelte/store";
6
+ //#region src/svelte/types.d.ts
7
+ type PermDockSvelteOptions = {
8
+ /**
9
+ * A getter (`() => data.snapshot`) or a readable store re-hydrates the
10
+ * store when it changes; a promise keeps the store `pending` until it
11
+ * settles (render the same promise with `{#await}`).
12
+ */
13
+ readonly snapshot: Snapshot | string | (() => Snapshot | string) | Readable<Snapshot | string> | PromiseLike<Snapshot | string>;
14
+ readonly endpoint?: string;
15
+ readonly approvals?: string;
16
+ readonly tenant?: string;
17
+ readonly fetch?: typeof fetch;
18
+ readonly headers?: Readonly<Record<string, string>>;
19
+ readonly maxAge?: number;
20
+ readonly verifier?: TokenVerifier;
21
+ };
22
+ //#endregion
23
+ //#region src/svelte/stores.d.ts
24
+ declare function setPermDock(options: PermDockSvelteOptions): ClientPermDock;
25
+ declare function getPermDock(): ClientPermDock;
26
+ declare function permission(reference: Permission, data?: () => unknown): Readable<PermissionState>;
27
+ declare function permissions(references: () => readonly Permission[], data?: () => unknown): Readable<PermissionSet>;
28
+ declare function filtered<T>(reference: Permission<string, T, "instance">, rows: () => readonly T[]): Readable<FilterResult<T>>;
29
+ declare function tenant(): Readable<TenantView>;
30
+ declare function memberships(): Readable<readonly Membership[]>;
31
+ declare function roles(options?: () => UseRolesOptions): Readable<{
32
+ readonly roles: readonly Role[];
33
+ }>;
34
+ declare function assignable(): Readable<readonly Role[]>;
35
+ declare function assignablePermissions(options?: {
36
+ readonly tenant?: string;
37
+ }): Readable<readonly Permission[]>;
38
+ declare function subject(): Readable<SubjectView>;
39
+ declare function approval(decision: () => Decision): Readable<ApprovalHandle>;
40
+ //#endregion
41
+ export { getPermDock as a, permissions as c, subject as d, tenant as f, filtered as i, roles as l, assignable as n, memberships as o, PermDockSvelteOptions as p, assignablePermissions as r, permission as s, approval as t, setPermDock as u };
@@ -0,0 +1,12 @@
1
+ import { d as Permission } from "./permissions-B4apnahQ.js";
2
+ import { r as ProtectOptions } from "./create-BKF3dgFk.js";
3
+ //#region src/server/stream.d.ts
4
+ type StreamProtectOptions = ProtectOptions & {
5
+ /**
6
+ * For a procedure that returns an async iterable: each outbound item is
7
+ * checked against this permission and dropped when the subscriber cannot read it.
8
+ */
9
+ readonly items?: Permission<string, unknown, "instance">;
10
+ };
11
+ //#endregion
12
+ export { StreamProtectOptions as t };