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,80 @@
1
+ import { $ as DecisionSink, C as Policy, Zt as PermDock, at as LimitStore, ct as MembershipSource, ft as RelationSource, 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 { n as RevocationFeed } from "../revocations-Cy06JNx2.js";
5
+ import { o as OtelWrap } from "../types-B9dmiiab.js";
6
+ import { r as PdpFactory } from "../types-BvBk1wgn.js";
7
+ import { S as ConnectionOptions, b as Connection, g as discoverViaSignatureAgent, h as WebBotAuthVerifier, n as OpenApiHooks, o as TenantOption, r as ProtectOptions, u as InvalidSignatureError, y as verifyWebBotAuth } from "../create-BKF3dgFk.js";
8
+ import { i as sendResponse, t as NodeRequest } from "../http-DPuDaChb.js";
9
+ import { CanActivate, ExceptionFilter, ExecutionContext, Type } from "@nestjs/common";
10
+ //#region src/nest/http.d.ts
11
+ /**
12
+ * `@nestjs/platform-express` hands the guard an `IncomingMessage`;
13
+ * `@nestjs/platform-fastify` hands it a `FastifyRequest` whose stream is `raw`.
14
+ */
15
+ export declare function toRequest(req: NodeRequest): Request;
16
+ //#endregion
17
+ //#region src/nest/create.d.ts
18
+ type NestRequest = NodeRequest & {
19
+ readonly params?: Readonly<Record<string, string>>;
20
+ permdock?: PermDock;
21
+ permdockData?: unknown;
22
+ };
23
+ type NestPermDockOptions<TUser = unknown> = {
24
+ readonly subject: (req: NestRequest) => TUser | Promise<TUser>;
25
+ readonly tenant?: TenantOption<NestRequest>;
26
+ readonly memberships?: MembershipSource | readonly MembershipSource[];
27
+ /** The object graph for relation grants that walk a parent chain; without it they deny. */
28
+ readonly relations?: RelationSource;
29
+ readonly entitlements?: EntitlementSource;
30
+ readonly customRoles?: RoleSource;
31
+ /** Hosted grants, read once per instance; see `PolicySource`. */
32
+ readonly policies?: PolicySource;
33
+ readonly store?: ApprovalStore;
34
+ readonly sink?: DecisionSink;
35
+ readonly limits?: LimitStore;
36
+ /** `createPermDock` from `permdock/pdp`; `protect` then decides delegated permissions remotely. */
37
+ readonly pdp?: PdpFactory;
38
+ /** Accepted for adapter parity; not read by this adapter. */
39
+ readonly snapshots?: SnapshotSource;
40
+ /** `(permdock) => withOtel(permdock, options)` from `permdock/otel`. */
41
+ readonly otel?: OtelWrap;
42
+ /** `(request) => verifyWebBotAuth(request, options)`; a verified bot becomes the actor. */
43
+ readonly webBotAuth?: WebBotAuthVerifier;
44
+ /**
45
+ * Maps a `ws`, `rpc` or `graphql` context to the request its subject comes
46
+ * from. Without it, a protected handler outside HTTP is denied.
47
+ */
48
+ readonly request?: (context: ExecutionContext) => NestRequest | undefined;
49
+ /** Ends or revalidates open gateway connections. */
50
+ readonly revocations?: RevocationFeed;
51
+ };
52
+ /** A gateway client: Socket.IO (`emit`, `disconnect`) or `ws` (`close`). */
53
+ type NestSocket = {
54
+ emit?(event: string, payload: unknown): unknown;
55
+ disconnect?(close?: boolean): unknown;
56
+ close?(code?: number, reason?: string): unknown;
57
+ };
58
+ type NestProtect = (permission: Permission, loadData?: (req: NestRequest) => unknown, protectOptions?: ProtectOptions) => ClassDecorator & MethodDecorator;
59
+ type NestHandlerOptions = {
60
+ /** Controller path; may hold route params such as `:org`. Default `api/permdock`. */
61
+ readonly path?: string;
62
+ };
63
+ type NestPermDock = {
64
+ readonly PermDockModule: Type<unknown>;
65
+ readonly PermDockGuard: Type<CanActivate>;
66
+ readonly Protect: NestProtect;
67
+ readonly InjectPermDock: () => ParameterDecorator;
68
+ readonly PermDockExceptionFilter: Type<ExceptionFilter>;
69
+ readonly permdockHandler: (options?: NestHandlerOptions) => Type<unknown>;
70
+ /**
71
+ * Opens the connection for a gateway client in `handleConnection`, from the
72
+ * handshake request. `Protect` rules on that client's messages then decide
73
+ * against the connection's current instance.
74
+ */
75
+ readonly connection: (client: NestSocket, req: NestRequest, connectionOptions?: ConnectionOptions) => Promise<Connection>;
76
+ readonly openapi: OpenApiHooks;
77
+ };
78
+ export declare function createPermDock<TUser, TPrincipal extends Principal = Principal>(policy: Policy<TUser, TPrincipal>, options: NestPermDockOptions<TUser>): NestPermDock;
79
+ //#endregion
80
+ export { InvalidSignatureError, type NestHandlerOptions, type NestPermDock, type NestPermDockOptions, type NestProtect, type NestRequest, type NestSocket, discoverViaSignatureAgent, sendResponse, verifyWebBotAuth };
@@ -0,0 +1,270 @@
1
+ import { t as compact } from "../compact-y6vfu2_f.js";
2
+ import { i as PermDockValidationError, n as PermDockDeniedError, t as PermDockApprovalRequiredError } from "../errors-Iy71s7Oj.js";
3
+ import { i as discoverViaSignatureAgent, r as InvalidSignatureError, s as verifyWebBotAuth } from "../evaluations-DsAU9ppl.js";
4
+ import { r as tenantScope, t as createKernel } from "../create-CSkhDU9T.js";
5
+ import { t as problemFromError } from "../map-error-RJ3ZsUyA.js";
6
+ import { i as onRevoked, t as POLICY_VIOLATION } from "../stream-Q_xlB6Ko.js";
7
+ import { i as toRequest$1, n as isServerResponse, r as sendResponse } from "../http-GgVApX1k.js";
8
+ import { Catch, Controller, Get, Inject, Injectable, Module, Post, Req, Res, createParamDecorator } from "@nestjs/common";
9
+ import { APP_FILTER, Reflector } from "@nestjs/core";
10
+ //#region src/nest/http.ts
11
+ function isReadable(value) {
12
+ return typeof value === "object" && value !== null && typeof value.read === "function";
13
+ }
14
+ function isFastifyReply(value) {
15
+ if (typeof value !== "object" || value === null) return false;
16
+ const reply = value;
17
+ return typeof reply["code"] === "function" && typeof reply["header"] === "function" && typeof reply["send"] === "function";
18
+ }
19
+ /**
20
+ * `@nestjs/platform-express` hands the guard an `IncomingMessage`;
21
+ * `@nestjs/platform-fastify` hands it a `FastifyRequest` whose stream is `raw`.
22
+ */
23
+ function toRequest(req) {
24
+ if (isReadable(req)) return toRequest$1(req);
25
+ const raw = req.raw;
26
+ return toRequest$1(req, isReadable(raw) ? raw : null);
27
+ }
28
+ async function sendNestResponse(res, response) {
29
+ if (isServerResponse(res)) {
30
+ await sendResponse(res, response);
31
+ return;
32
+ }
33
+ if (isFastifyReply(res)) {
34
+ res.code(response.status);
35
+ for (const [key, value] of response.headers.entries()) res.header(key, value);
36
+ await res.send(await response.text());
37
+ return;
38
+ }
39
+ throw new TypeError("permdock/nest supports @nestjs/platform-express and @nestjs/platform-fastify responses");
40
+ }
41
+ //#endregion
42
+ //#region src/nest/create.ts
43
+ const PROTECT_KEY = "permdock:protect";
44
+ var PermDockHttpError = class extends Error {
45
+ name = "PermDockHttpError";
46
+ response;
47
+ constructor(response) {
48
+ super("permdock denied");
49
+ this.response = response;
50
+ }
51
+ };
52
+ function reflectMeta() {
53
+ const ref = Reflect;
54
+ if (typeof ref.getMetadata !== "function" || typeof ref.defineMetadata !== "function") throw new TypeError("reflect-metadata is required for permdock/nest");
55
+ return ref;
56
+ }
57
+ function applyMethod(cls, key, decorator) {
58
+ const descriptor = Object.getOwnPropertyDescriptor(cls.prototype, key);
59
+ if (descriptor === void 0) throw new TypeError(`missing ${key} handler`);
60
+ decorator(cls.prototype, key, descriptor);
61
+ }
62
+ function applyParameter(cls, key, index, decorator) {
63
+ decorator(cls.prototype, key, index);
64
+ }
65
+ function hasEmit(value) {
66
+ return typeof value === "object" && value !== null && typeof value.emit === "function";
67
+ }
68
+ function rulesOf(target) {
69
+ const found = reflectMeta().getMetadata(PROTECT_KEY, target);
70
+ if (!Array.isArray(found)) return [];
71
+ return found;
72
+ }
73
+ const Protect = (permission, loadData, protectOptions) => {
74
+ const rule = compact({
75
+ permission,
76
+ loadData,
77
+ options: protectOptions
78
+ });
79
+ return ((target, _propertyKey, descriptor) => {
80
+ const store = descriptor === void 0 ? target : descriptor.value;
81
+ if (typeof store !== "function" && (typeof store !== "object" || store === null)) throw new TypeError("Protect requires a class or method");
82
+ const existing = rulesOf(store);
83
+ reflectMeta().defineMetadata(PROTECT_KEY, [...existing, rule], store);
84
+ });
85
+ };
86
+ function createPermDock(policy, options) {
87
+ const contexts = /* @__PURE__ */ new WeakMap();
88
+ const bound = /* @__PURE__ */ new WeakMap();
89
+ const kernel = createKernel(policy, compact({
90
+ subject: (request) => {
91
+ const req = contexts.get(request);
92
+ return req === void 0 ? null : options.subject(req);
93
+ },
94
+ memberships: options.memberships,
95
+ relations: options.relations,
96
+ entitlements: options.entitlements,
97
+ customRoles: options.customRoles,
98
+ policies: options.policies,
99
+ store: options.store,
100
+ sink: options.sink,
101
+ limits: options.limits,
102
+ pdp: options.pdp,
103
+ webBotAuth: options.webBotAuth,
104
+ revocations: options.revocations,
105
+ adapter: "nest",
106
+ wrap: options.otel
107
+ }));
108
+ const scopeOf = (req) => tenantScope(options.tenant, req);
109
+ const applyProtect = async (remaining, req, request, scope) => {
110
+ const [rule, ...rest] = remaining;
111
+ if (rule === void 0) return;
112
+ const loader = rule.loadData;
113
+ const guard = await kernel.protect(rule.permission, loader === void 0 ? void 0 : () => loader(req), rule.options)(request, scope);
114
+ if (!guard.ok) throw new PermDockHttpError(guard.response);
115
+ req.permdock = guard.permdock;
116
+ req.permdockData = guard.data;
117
+ await applyProtect(rest, req, request, scope);
118
+ };
119
+ const bind = (req) => {
120
+ const hit = bound.get(req);
121
+ if (hit !== void 0) return hit;
122
+ const request = toRequest(req);
123
+ bound.set(req, request);
124
+ contexts.set(request, req);
125
+ return request;
126
+ };
127
+ const sockets = /* @__PURE__ */ new WeakMap();
128
+ const connection = (client, req, connectionOptions) => {
129
+ const hit = sockets.get(client);
130
+ if (hit !== void 0) return hit;
131
+ const opened = (async () => {
132
+ const conn = await kernel.connection(bind(req), connectionOptions, await scopeOf(req));
133
+ onRevoked(conn, (problem) => {
134
+ client.emit?.("permdock:error", problem);
135
+ if (typeof client.disconnect === "function") client.disconnect(true);
136
+ else client.close?.(POLICY_VIOLATION, problem.type);
137
+ });
138
+ return conn;
139
+ })();
140
+ sockets.set(client, opened);
141
+ return opened;
142
+ };
143
+ /** Decides each rule for a gateway message against the client's connection. */
144
+ const checkMessage = async (rules, conn, req) => {
145
+ for (const rule of rules) {
146
+ const loader = rule.loadData;
147
+ let data;
148
+ if (loader !== void 0) {
149
+ data = req === void 0 ? void 0 : await loader(req);
150
+ if (data === null || data === void 0) throw new PermDockHttpError(new Response(null, { status: 404 }));
151
+ }
152
+ const decision = conn.check(rule.permission, data, rule.options?.trusted === true ? { trusted: true } : void 0);
153
+ if (decision.outcome !== "granted") throw new PermDockHttpError(kernel.problem(decision, { permission: rule.permission }));
154
+ }
155
+ };
156
+ class PermDockGuard {
157
+ reflector;
158
+ constructor(reflector) {
159
+ this.reflector = reflector;
160
+ }
161
+ async canActivate(context) {
162
+ const rules = this.rulesFor(context);
163
+ if (context.getType() === "ws" && rules.length > 0) {
164
+ const opened = sockets.get(context.switchToWs().getClient());
165
+ if (opened !== void 0) {
166
+ await checkMessage(rules, await opened, options.request?.(context));
167
+ return true;
168
+ }
169
+ }
170
+ const req = context.getType() === "http" ? context.switchToHttp().getRequest() : rules.length === 0 ? void 0 : options.request?.(context);
171
+ if (req === void 0) return rules.length === 0;
172
+ const request = bind(req);
173
+ const scope = await scopeOf(req);
174
+ req.permdock = await kernel.permdock(request, scope);
175
+ await applyProtect(rules, req, request, scope);
176
+ return true;
177
+ }
178
+ rulesFor(context) {
179
+ const fromClass = this.reflector.get(PROTECT_KEY, context.getClass());
180
+ const fromHandler = this.reflector.get(PROTECT_KEY, context.getHandler());
181
+ return [...Array.isArray(fromClass) ? fromClass : rulesOf(context.getClass()), ...Array.isArray(fromHandler) ? fromHandler : rulesOf(context.getHandler())];
182
+ }
183
+ }
184
+ Inject(Reflector)(PermDockGuard, void 0, 0);
185
+ Injectable()(PermDockGuard);
186
+ class PermDockExceptionFilter {
187
+ send = sendNestResponse;
188
+ async catch(exception, host) {
189
+ const problem = exception instanceof PermDockHttpError ? exception.response : problemFromError(exception);
190
+ if (problem === void 0) throw new TypeError("unhandled permdock exception");
191
+ if (host.getType() === "http") {
192
+ await this.send(host.switchToHttp().getResponse(), problem);
193
+ return;
194
+ }
195
+ const client = host.getType() === "ws" ? host.switchToWs().getClient() : null;
196
+ if (!hasEmit(client)) throw exception;
197
+ const body = await problem.json();
198
+ client.emit("exception", {
199
+ status: "error",
200
+ message: typeof body.title === "string" ? body.title : "Forbidden",
201
+ problem: body
202
+ });
203
+ }
204
+ }
205
+ Catch(PermDockHttpError, InvalidSignatureError, PermDockDeniedError, PermDockApprovalRequiredError, PermDockValidationError)(PermDockExceptionFilter);
206
+ Injectable()(PermDockExceptionFilter);
207
+ class PermDockRoot {
208
+ static adapter = "nest";
209
+ }
210
+ Module({
211
+ providers: [
212
+ {
213
+ provide: PermDockGuard,
214
+ useFactory: (reflector) => new PermDockGuard(reflector),
215
+ inject: [Reflector]
216
+ },
217
+ {
218
+ provide: PermDockExceptionFilter,
219
+ useFactory: () => new PermDockExceptionFilter()
220
+ },
221
+ {
222
+ provide: APP_FILTER,
223
+ useExisting: PermDockExceptionFilter
224
+ }
225
+ ],
226
+ exports: [PermDockGuard, PermDockExceptionFilter]
227
+ })(PermDockRoot);
228
+ const injectPermDock = createParamDecorator((_data, ctx) => {
229
+ if (ctx.getType() !== "http") return;
230
+ return ctx.switchToHttp().getRequest().permdock;
231
+ });
232
+ const InjectPermDock = () => injectPermDock();
233
+ const permdockHandler = (handlerOptions = {}) => {
234
+ const { POST, GET } = kernel.permdockHandler((request) => {
235
+ const req = contexts.get(request);
236
+ return req === void 0 ? { tenant: void 0 } : scopeOf(req);
237
+ });
238
+ class EvaluationsController {
239
+ send = sendNestResponse;
240
+ async post(req, res) {
241
+ const request = toRequest(req);
242
+ contexts.set(request, req);
243
+ await this.send(res, await POST(request));
244
+ }
245
+ async get(req, res) {
246
+ await this.send(res, await GET(bind(req)));
247
+ }
248
+ }
249
+ Controller(handlerOptions.path ?? "api/permdock")(EvaluationsController);
250
+ applyMethod(EvaluationsController, "post", Post());
251
+ applyMethod(EvaluationsController, "get", Get());
252
+ applyParameter(EvaluationsController, "post", 0, Req());
253
+ applyParameter(EvaluationsController, "post", 1, Res({ passthrough: false }));
254
+ applyParameter(EvaluationsController, "get", 0, Req());
255
+ applyParameter(EvaluationsController, "get", 1, Res({ passthrough: false }));
256
+ return EvaluationsController;
257
+ };
258
+ return {
259
+ PermDockModule: PermDockRoot,
260
+ PermDockGuard,
261
+ Protect,
262
+ InjectPermDock,
263
+ PermDockExceptionFilter,
264
+ permdockHandler,
265
+ connection,
266
+ openapi: kernel.openapi
267
+ };
268
+ }
269
+ //#endregion
270
+ export { InvalidSignatureError, createPermDock, discoverViaSignatureAgent, sendResponse, toRequest, verifyWebBotAuth };
@@ -0,0 +1,24 @@
1
+ import { t as PermDockDigest } from "../digest-B3kc_PgQ.js";
2
+ import { ComponentType, ReactNode } from "react";
3
+ //#region src/next/client.d.ts
4
+ export type PermissionBoundaryState = PermDockDigest & {
5
+ /** Re-fetches and re-renders the boundary's children, e.g. after an approval or a role change. */
6
+ readonly retry: () => void;
7
+ };
8
+ export type PermissionBoundaryProps = {
9
+ /** Rendered in place of the children when one throws `PermDockDeniedError`. */
10
+ readonly denied?: ReactNode;
11
+ /** Rendered when a child throws `PermDockApprovalRequiredError`; defaults to `denied`. */
12
+ readonly approval?: ReactNode;
13
+ };
14
+ /**
15
+ * A component-level boundary for PermDock errors thrown below it, in a Server
16
+ * Component or a Client Component. Other errors, `forbidden()`, `notFound()`
17
+ * and `redirect()` pass through.
18
+ */
19
+ export declare const PermissionBoundary: ComponentType<PermissionBoundaryProps & {
20
+ readonly children?: ReactNode;
21
+ }>;
22
+ /** Inside a `PermissionBoundary` fallback: what was refused, and `retry()`. */
23
+ export declare function usePermissionBoundary(): PermissionBoundaryState | null;
24
+ //#endregion
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import { r as parsePermDockDigest } from "../digest-BI-6aa6d.js";
3
+ import { createContext, useContext } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { catchError } from "next/error";
6
+ //#region src/next/client.tsx
7
+ const BoundaryContext = createContext(null);
8
+ function PermissionFallback(props, info) {
9
+ const parsed = parsePermDockDigest(info.error.digest);
10
+ if (parsed === null) throw info.error;
11
+ const node = parsed.outcome === "approval-required" ? props.approval ?? props.denied : props.denied;
12
+ return /* @__PURE__ */ jsx(BoundaryContext.Provider, {
13
+ value: {
14
+ ...parsed,
15
+ retry: info.retry
16
+ },
17
+ children: node ?? null
18
+ });
19
+ }
20
+ /**
21
+ * A component-level boundary for PermDock errors thrown below it, in a Server
22
+ * Component or a Client Component. Other errors, `forbidden()`, `notFound()`
23
+ * and `redirect()` pass through.
24
+ */
25
+ const PermissionBoundary = catchError(PermissionFallback);
26
+ /** Inside a `PermissionBoundary` fallback: what was refused, and `retry()`. */
27
+ function usePermissionBoundary() {
28
+ return useContext(BoundaryContext);
29
+ }
30
+ //#endregion
31
+ export { PermissionBoundary, usePermissionBoundary };
@@ -0,0 +1,110 @@
1
+ import { $ as DecisionSink, C as Policy, E as PolicyVocabulary, Mn as Decision, Zt as PermDock, at as LimitStore, ct as MembershipSource, ft as RelationSource, 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 { o as OtelWrap } from "../types-B9dmiiab.js";
5
+ import { ReactElement, ReactNode } from "react";
6
+ //#region src/next/cache-life.d.ts
7
+ type CacheLifeForOptions = {
8
+ /** Lower bound in seconds. Next.js includes a private entry in per-link prefetches from 30. */
9
+ readonly min?: number;
10
+ /** Upper bound in seconds. Next.js keeps a per-session App Shell entry from 300. */
11
+ readonly max?: number;
12
+ /** Seconds since the epoch; defaults to the snapshot's `issuedAt`, then the clock. */
13
+ readonly now?: number;
14
+ };
15
+ /**
16
+ * `{ stale }` for `cacheLife()` inside an app-owned `'use cache: private'` function: `max` when the
17
+ * value never expires, otherwise the seconds left, clamped to `[min, max]`. A value with less than
18
+ * `min` seconds left gets its real remainder, so Next.js leaves it out of prefetches instead of
19
+ * serving it past `expiresAt`.
20
+ */
21
+ export declare function cacheLifeFor(value: {
22
+ readonly expiresAt?: number | null;
23
+ readonly issuedAt?: number;
24
+ } | null, options?: CacheLifeForOptions): {
25
+ readonly stale: number;
26
+ };
27
+ //#endregion
28
+ //#region src/next/types.d.ts
29
+ type NextSubjectInput = unknown;
30
+ type NextPermDockOptions<TUser = NextSubjectInput> = {
31
+ readonly subject: () => TUser | Promise<TUser>;
32
+ readonly tenant?: string | (() => string | undefined | Promise<string | undefined>);
33
+ readonly onDenied?: (decision: Decision) => never | void;
34
+ readonly memberships?: MembershipSource | readonly MembershipSource[];
35
+ /** The object graph for relation grants that walk a parent chain; without it they deny. */
36
+ readonly relations?: RelationSource;
37
+ readonly entitlements?: EntitlementSource;
38
+ readonly customRoles?: RoleSource;
39
+ /** Hosted grants, read once per instance; see `PolicySource`. */
40
+ readonly policies?: PolicySource;
41
+ readonly store?: ApprovalStore;
42
+ readonly sink?: DecisionSink;
43
+ readonly limits?: LimitStore;
44
+ readonly snapshots?: SnapshotSource;
45
+ /** `(permdock) => withOtel(permdock, options)` from `permdock/otel`. */
46
+ readonly otel?: OtelWrap;
47
+ /**
48
+ * Where `PermDockProvider` sends checks the snapshot cannot answer; default `/api/permdock`.
49
+ * `false` is snapshot-only: no `permdockHandler` route, and those checks are denied with
50
+ * reason `server-only`.
51
+ */
52
+ readonly endpoint?: string | false;
53
+ };
54
+ type GetPermDockQuery = {
55
+ readonly tenant?: string;
56
+ };
57
+ type RequireAccessInput = {
58
+ readonly permission: Permission;
59
+ /** The row for an instance permission; omit it for a collection permission. */
60
+ readonly data?: unknown;
61
+ /** The active tenant, as for `getPermDock({ tenant })`; defaults to the factory's `tenant`. */
62
+ readonly tenant?: string;
63
+ };
64
+ type ServerPermissionState = {
65
+ readonly allowed: boolean;
66
+ readonly status: "ready";
67
+ readonly decision: Decision;
68
+ };
69
+ type ServerPermDockProviderProps = {
70
+ readonly children: ReactNode;
71
+ readonly tenant?: string;
72
+ readonly include?: readonly (Permission | {
73
+ readonly [key: string]: unknown;
74
+ })[];
75
+ readonly tenants?: "all";
76
+ /** Overrides the factory's `endpoint`; `false` is snapshot-only. */
77
+ readonly endpoint?: string | false;
78
+ };
79
+ type PermDockHandler = {
80
+ readonly POST: (request: Request) => Promise<Response>;
81
+ readonly GET: (request: Request) => Promise<Response>;
82
+ };
83
+ type NextPermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
84
+ readonly getPermDock: (query?: GetPermDockQuery) => Promise<PermDock<V>>;
85
+ readonly getPermission: (permission: Permission, data?: unknown) => Promise<ServerPermissionState>;
86
+ /**
87
+ * Resolves to the granted `Decision`. A denial calls `unauthorized()` for an
88
+ * anonymous subject and `forbidden()` otherwise (`experimental.authInterrupts`);
89
+ * approval-required and boundary validation throw as from `assert`.
90
+ */
91
+ readonly requireAccess: (input: RequireAccessInput) => Promise<Extract<Decision, {
92
+ readonly outcome: "granted";
93
+ }>>;
94
+ /** Never awaits: passes an unawaited snapshot to the client provider, whose hooks suspend. */
95
+ readonly PermDockProvider: (props: ServerPermDockProviderProps) => ReactElement;
96
+ readonly permdockHandler: () => PermDockHandler;
97
+ };
98
+ //#endregion
99
+ //#region src/next/create.d.ts
100
+ export declare function createPermDock<TUser = NextSubjectInput, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: NextPermDockOptions<TUser>): NextPermDock<V>;
101
+ //#endregion
102
+ //#region src/next/snapshot-tag.d.ts
103
+ /**
104
+ * The `cacheTag` for one subject's cached snapshots: `permdock:<sub>`, or `permdock:anon`
105
+ * without a subject. Tag the private cache with it and pass it to `updateTag` or
106
+ * `revalidateTag` on every write that changes the subject's snapshot.
107
+ */
108
+ export declare function snapshotTag(sub?: string | null): string;
109
+ //#endregion
110
+ export type { CacheLifeForOptions, GetPermDockQuery, NextPermDock, NextPermDockOptions, PermDockHandler, RequireAccessInput, ServerPermDockProviderProps, ServerPermissionState };