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,1959 @@
1
+ import { _ as ResourceNode, d as Permission, f as PermissionKind, p as PermissionTree } from "./permissions-B4apnahQ.js";
2
+ import { a as RoleTree, i as RoleMeta, n as PlanTree, r as Role, t as Plan } from "./vocabulary-Dk0fs-Jk.js";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+ //#region src/conditions/ast.d.ts
5
+ type ConditionRef = {
6
+ readonly ref: string;
7
+ };
8
+ type ConditionDate = {
9
+ readonly date: string;
10
+ };
11
+ type ConditionValue = string | number | boolean | null | readonly ConditionValue[] | ConditionRef | ConditionDate;
12
+ type ComparisonOp = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains";
13
+ type ComparisonCondition = {
14
+ readonly op: ComparisonOp;
15
+ readonly field: string;
16
+ readonly value: ConditionValue;
17
+ };
18
+ type InCondition = {
19
+ readonly op: "in" | "notIn";
20
+ readonly field: string;
21
+ readonly value: readonly ConditionValue[] | ConditionRef;
22
+ };
23
+ type IsNullCondition = {
24
+ readonly op: "isNull";
25
+ readonly field: string;
26
+ readonly value: boolean;
27
+ };
28
+ type AndCondition = {
29
+ readonly op: "and";
30
+ readonly conditions: readonly Condition[];
31
+ };
32
+ type OrCondition = {
33
+ readonly op: "or";
34
+ readonly conditions: readonly Condition[];
35
+ };
36
+ type NotCondition = {
37
+ readonly op: "not";
38
+ readonly condition: Condition;
39
+ };
40
+ type MemberOfCondition = {
41
+ readonly op: "memberOf";
42
+ /** A declared scope name (or the `tenant` / `team` alias), or `'resource'`. */
43
+ readonly scope: string;
44
+ readonly field: string;
45
+ readonly roles: readonly string[];
46
+ readonly resource?: string;
47
+ readonly parents?: readonly MemberOfParent[];
48
+ };
49
+ /**
50
+ * A row field holding an ancestor's id. The keyed form matches only a
51
+ * membership on that resource; a bare field name matches a membership on any
52
+ * resource whose id equals the field.
53
+ */
54
+ type MemberOfParent = string | {
55
+ readonly field: string;
56
+ readonly resource: string;
57
+ };
58
+ /**
59
+ * The subject holds `relation` on the `resource` instance whose id the row's
60
+ * `field` holds, or on one of its ancestors within `depth` parent hops.
61
+ * Evaluated through a `RelationSource` in process, the closure table in RLS,
62
+ * and, given relation mappings, a subquery in the `toWhere` compilers.
63
+ */
64
+ type RelatedCondition = {
65
+ readonly op: "related";
66
+ readonly resource: string;
67
+ readonly relation: string;
68
+ /** The row's own id field, or (with `parent` or `hops`) the field holding the next instance's id. */
69
+ readonly field: string;
70
+ /** Parent hops walked above the first `resource` instance; `0` reads only that instance. */
71
+ readonly depth: number;
72
+ /** The row is a child of `resource`, reached through `field`. */
73
+ readonly parent?: true;
74
+ /**
75
+ * To-one links from the row to `resource`: `field` points at the first
76
+ * hop's resource, each later hop follows `link` on the resource before it,
77
+ * and the last hop's resource is `resource`.
78
+ */
79
+ readonly hops?: readonly RelatedHop[];
80
+ /**
81
+ * The `resource` instances the subject holds a resource role on; replaces
82
+ * the `relation` lookup (`relation` is then empty).
83
+ */
84
+ readonly ids?: readonly string[];
85
+ /**
86
+ * The row's boolean column that keeps ancestor grants out: with `parent` or
87
+ * `hops`, a restricted row matches nothing; without, the walk stops at the row.
88
+ */
89
+ readonly restricted?: string;
90
+ };
91
+ type RelatedHop = {
92
+ readonly link: string;
93
+ readonly resource: string;
94
+ };
95
+ type OpaqueCondition = {
96
+ readonly op: "opaque";
97
+ readonly sql: string;
98
+ readonly fingerprint: string;
99
+ };
100
+ type SqlFunctionField = {
101
+ readonly field: string;
102
+ };
103
+ type SqlFunctionArg = ConditionValue | SqlFunctionField;
104
+ type SqlFunctionCondition = {
105
+ readonly op: "sqlFunction";
106
+ readonly name: string;
107
+ readonly args: readonly SqlFunctionArg[];
108
+ readonly twin: Condition;
109
+ };
110
+ type Condition = ComparisonCondition | InCondition | IsNullCondition | AndCondition | OrCondition | NotCondition | MemberOfCondition | RelatedCondition | OpaqueCondition | SqlFunctionCondition;
111
+ declare function isConditionRef(value: unknown): value is ConditionRef;
112
+ declare function isConditionDate(value: unknown): value is ConditionDate;
113
+ declare function isCondition(value: unknown): value is Condition;
114
+ declare function isSqlFunctionField(value: unknown): value is SqlFunctionField;
115
+ declare function hasConditionOp(condition: Condition | undefined, op: Condition["op"]): boolean;
116
+ //#endregion
117
+ //#region src/core/subject.d.ts
118
+ type JsonWebKeyLike = {
119
+ readonly kty?: string;
120
+ readonly [key: string]: unknown;
121
+ };
122
+ type Binding = {
123
+ readonly jkt?: string;
124
+ readonly "x5t#S256"?: string;
125
+ readonly jwk?: JsonWebKeyLike;
126
+ readonly kid?: string;
127
+ };
128
+ /**
129
+ * One OpenID Connect for Identity Assurance `verified_claims` entry, kept as
130
+ * the issuer sent it: opaque, frozen evidence for conditions and audit.
131
+ */
132
+ type VerifiedClaims = {
133
+ readonly verification: Readonly<Record<string, unknown>> & {
134
+ readonly trust_framework: string;
135
+ };
136
+ readonly claims: Readonly<Record<string, unknown>>;
137
+ };
138
+ type Assurance = {
139
+ readonly acr?: string;
140
+ readonly amr?: readonly string[];
141
+ readonly authTime?: number;
142
+ readonly verified?: readonly VerifiedClaims[];
143
+ };
144
+ /**
145
+ * Roles held in one scope instance (`scope` + `id`, with the id of every
146
+ * ancestor scope in `within`) or on one resource (`on`). Evaluation only sees
147
+ * the canonical form; `tenant` / `team` are accepted as input for the first
148
+ * and second declared scope and normalised away.
149
+ */
150
+ type Membership = {
151
+ readonly scope?: string;
152
+ readonly id?: string;
153
+ readonly within?: Readonly<Record<string, string>>;
154
+ readonly on?: {
155
+ readonly resource: string;
156
+ readonly id: string;
157
+ };
158
+ readonly roles: readonly string[];
159
+ /** Roles the holder may activate here but does not hold; `permdock.activate` writes an elevated membership. */
160
+ readonly eligible?: readonly string[];
161
+ readonly via?: string;
162
+ readonly expiresAt?: number;
163
+ /** The principal id that wrote this membership: who elevated, consented to or granted the access. */
164
+ readonly grantedBy?: string;
165
+ /** Free text recording why the membership was written: the activation or consent justification. */
166
+ readonly reason?: string;
167
+ /** A subgroup the holder belongs to inside the instance (`vendor-support`); a `fromJunction` group column fills it. */
168
+ readonly member?: {
169
+ readonly group: string;
170
+ };
171
+ /** `idp`: the identity provider (SCIM) owns this membership; the application must not edit it. */
172
+ readonly managedBy?: "idp";
173
+ /** Seats this membership holds (`dev-mode`, `editor`); `plan()` grantees match them inside the active tenant. */
174
+ readonly entitlements?: readonly string[];
175
+ /** Input only: an instance of the first scope. */
176
+ readonly tenant?: string;
177
+ /** Input only: an instance of the second scope, inside `tenant`. */
178
+ readonly team?: string;
179
+ };
180
+ /**
181
+ * One permission a custom role adds or removes. It names a declared
182
+ * permission key and carries no condition, approval or limit of its own.
183
+ */
184
+ type CustomRoleGrant = {
185
+ readonly permission: string;
186
+ readonly effect?: "allow" | "deny";
187
+ };
188
+ type CustomRoleBody = {
189
+ readonly name: string;
190
+ readonly includes?: readonly string[];
191
+ readonly grants?: readonly CustomRoleGrant[];
192
+ readonly meta?: Readonly<Record<string, unknown>>;
193
+ };
194
+ /** A role a tenant defines, held on memberships inside that tenant. */
195
+ type TenantCustomRole = CustomRoleBody & {
196
+ /** The instance of the first scope that owns the role. */
197
+ readonly tenant: string;
198
+ /** The scope the role is held at; defaults to the first scope. Its ceiling is that scope's assignable roles. */
199
+ readonly scope?: string;
200
+ /** Pins the role to one instance of `scope`. */
201
+ readonly id?: string;
202
+ /** Input only: `scope` = the second scope, `id` = this team. */
203
+ readonly team?: string;
204
+ };
205
+ /**
206
+ * A role the platform defines, held through `principal.roles` like a declared
207
+ * global role. Its ceiling is the allows of the declared global roles marked
208
+ * `assignable`.
209
+ */
210
+ type GlobalCustomRole = CustomRoleBody & {
211
+ readonly scope: "global";
212
+ readonly tenant?: undefined;
213
+ readonly id?: undefined;
214
+ readonly team?: undefined;
215
+ };
216
+ type CustomRole = TenantCustomRole | GlobalCustomRole;
217
+ type Principal = {
218
+ readonly id: string;
219
+ readonly issuer?: string;
220
+ readonly kind?: "user" | "service" | "workload" | "link";
221
+ readonly roles?: readonly string[];
222
+ readonly plans?: readonly string[];
223
+ readonly memberships?: readonly Membership[];
224
+ /** The token dropped memberships to stay under its size budget; a `claimsFirst` source reads the rest. */
225
+ readonly membershipsTruncated?: boolean;
226
+ /** The authorization version the token was minted at (`authz_ver`). */
227
+ readonly authzVersion?: number;
228
+ readonly tenant?: string;
229
+ readonly assurance?: Assurance;
230
+ readonly binding?: Binding;
231
+ readonly [key: string]: unknown;
232
+ };
233
+ type Actor = {
234
+ readonly id: string;
235
+ readonly kind: string;
236
+ readonly binding?: Binding;
237
+ /** `true` narrows every policy delegation to this actor to its read-only permissions (`readOnlyHint`). */
238
+ readonly readOnly?: boolean;
239
+ readonly [key: string]: unknown;
240
+ };
241
+ type AuthorizationDetail = {
242
+ readonly type: string;
243
+ readonly actions?: readonly string[];
244
+ readonly [key: string]: unknown;
245
+ };
246
+ type GnapAccess = string | Readonly<Record<string, unknown>>;
247
+ type Delegation = {
248
+ readonly scopes?: readonly string[];
249
+ readonly authorizationDetails?: readonly AuthorizationDetail[];
250
+ readonly access?: readonly GnapAccess[];
251
+ readonly chain?: unknown;
252
+ };
253
+ type Subject<TPrincipal extends Principal = Principal> = {
254
+ readonly principal: TPrincipal | null;
255
+ readonly actor?: Actor;
256
+ readonly delegation?: Delegation;
257
+ readonly context: Readonly<Record<string, unknown>>;
258
+ readonly session?: string;
259
+ readonly expiresAt?: number;
260
+ /** The token's memberships are behind the source's authorization version: `fresh` permissions deny. */
261
+ readonly stale?: true;
262
+ };
263
+ //#endregion
264
+ //#region src/core/scopes.d.ts
265
+ /** One entry of `definePolicy({ scopes })`: the row field holding the scope id, and its parent scope. */
266
+ type ScopeDeclaration = {
267
+ readonly key: string;
268
+ readonly within?: string;
269
+ };
270
+ type PolicyScopesInput = Readonly<Record<string, ScopeDeclaration>>;
271
+ /**
272
+ * A declared scope, in declaration order. `key` is absent only on the
273
+ * implicit `tenant` / `team` pair of a policy that declares no scopes.
274
+ */
275
+ type Scope = {
276
+ readonly name: string;
277
+ readonly key?: string;
278
+ readonly within?: string;
279
+ };
280
+ /** The names `role(..., { on })`, `memberOf` and memberships may use: declared names plus the aliases. */
281
+ type ScopeNames<S> = [S] extends [PolicyScopesInput] ? string extends keyof S ? string : (keyof S & string) | "tenant" | "team" : string;
282
+ //#endregion
283
+ //#region src/core/grantee.d.ts
284
+ type RoleGrantee = {
285
+ readonly kind: "role";
286
+ readonly role: string;
287
+ /** `'global'`, a scope name, or one resource. */
288
+ readonly scope: string | {
289
+ readonly resource: string;
290
+ };
291
+ };
292
+ type AnyoneGrantee = {
293
+ readonly kind: "anyone";
294
+ };
295
+ type AuthenticatedGrantee = {
296
+ readonly kind: "authenticated";
297
+ };
298
+ type RelationGrantee = {
299
+ readonly kind: "relation";
300
+ readonly resource: string;
301
+ readonly relation: string;
302
+ /**
303
+ * `'parent'`: follow the row's `parent` chain upward to `resource`, then its
304
+ * own parents. A list of link names: follow those to-one links from the row
305
+ * to `resource`, then walk its parents only when `depth` is set.
306
+ */
307
+ readonly through?: "parent" | readonly string[];
308
+ /** Parent hops walked above the first `resource` instance; absent means `DEFAULT_RELATION_DEPTH` for `'parent'` and `0` for links. */
309
+ readonly depth?: number;
310
+ };
311
+ type PlanGrantee = {
312
+ readonly kind: "plan";
313
+ readonly plan: string;
314
+ };
315
+ type ActorGrantee = {
316
+ readonly kind: "actor";
317
+ readonly actor: string;
318
+ };
319
+ type AssuranceGrantee = {
320
+ readonly kind: "assurance";
321
+ readonly acr?: readonly string[];
322
+ readonly amr?: readonly string[];
323
+ readonly maxAge?: number;
324
+ };
325
+ type Grantee = RoleGrantee | AnyoneGrantee | AuthenticatedGrantee | RelationGrantee | PlanGrantee | ActorGrantee | AssuranceGrantee;
326
+ type GranteeInput = Grantee | Role | Plan | string | readonly GranteeInput[];
327
+ declare function anyone(): AnyoneGrantee;
328
+ declare function authenticated(): AuthenticatedGrantee;
329
+ declare function relation(resource: Permission | PermissionTree, name: string, options?: {
330
+ readonly through?: "parent" | readonly string[];
331
+ readonly depth?: number;
332
+ }): RelationGrantee;
333
+ declare function plan(name: Plan | string): PlanGrantee;
334
+ declare function actor(kind: string): ActorGrantee;
335
+ declare function assurance(options: {
336
+ readonly acr?: string | readonly string[];
337
+ readonly amr?: string | readonly string[];
338
+ readonly maxAge?: number;
339
+ }): AssuranceGrantee;
340
+ //#endregion
341
+ //#region src/core/decision.d.ts
342
+ type DenialReason = "no-grant" | "condition" | "deny" | "inactive-grant" | "closure-error" | "opaque-condition" | "server-only" | "anonymous" | "not-delegated" | "no-delegation" | "insufficient-user-authentication" | "not-entitled" | "purpose" | "reason-required" | "actor-required" | "limit" | "limit-unavailable" | "relation-depth" | "relation-unavailable" | "validation" | "tenant-mismatch" | "no-membership" | "scope" | "expired-membership" | "stale-credentials" | "unknown-role" | "last-holder" | "max-holders" | "transfer-only" | "not-assignable-by" | "self-demotion" | "externally-managed" | "not-allowed-for-membership" | "conflicting-role" | "approval" | "stale-approval" | "pdp-denied" | "pdp-unavailable" | "pdp-invalid-response" | "undocumented" | "unsupported" | "exceeds-creator" | "credential-policy";
343
+ type Denial = {
344
+ readonly role: string | null;
345
+ readonly reason: DenialReason;
346
+ readonly detail?: unknown;
347
+ readonly to?: Grantee | readonly Grantee[];
348
+ };
349
+ type MatchedGrant = {
350
+ readonly role: string | null;
351
+ readonly permission: string;
352
+ /** The grant's declared `name`, when it has one. */
353
+ readonly name?: string;
354
+ readonly to?: Grantee | readonly Grantee[];
355
+ readonly where?: Grant["where"];
356
+ readonly check?: Grant["check"];
357
+ readonly approval?: "human" | ApprovalRequirement;
358
+ readonly provider?: string;
359
+ /** The hosted policy document fingerprint and grant id, when a hosted grant matched. */
360
+ readonly hosted?: HostedGrantRef;
361
+ /** A break-glass grant overrode a matching deny. */
362
+ readonly breakGlass?: true;
363
+ };
364
+ /**
365
+ * Something the caller owes alongside a granted action. `over-limit`: a soft
366
+ * `limit` was past its count; `near-limit`: usage reached `alertAt`.
367
+ * `notify` / `review`: a break-glass grant's declared follow-ups.
368
+ * `justify`: the break-glass reason, carried so audit records why.
369
+ */
370
+ type Obligation = {
371
+ readonly kind: "over-limit" | "near-limit" | "notify" | "review";
372
+ } | {
373
+ readonly kind: "justify";
374
+ readonly reason: string;
375
+ };
376
+ /** What is left of the `limit` that applied; `resetsAt` is Unix seconds. */
377
+ type Quota = {
378
+ readonly remaining: number;
379
+ readonly resetsAt: number;
380
+ };
381
+ /**
382
+ * The `detail` of a `limit` denial: the grant's `count`, its window in
383
+ * seconds and when the window resets (Unix seconds).
384
+ */
385
+ type LimitDetail = {
386
+ readonly count: number;
387
+ readonly window: number;
388
+ readonly resetsAt: number;
389
+ };
390
+ /**
391
+ * Why a candidate grant for the permission was passed over before its
392
+ * condition ran: `via-only` (the subject holds no membership of its kind),
393
+ * `purpose` (no asserted purpose it lists), `field` (its `fields` do not
394
+ * cover the requested field), `grantee` (its `to` did not match and added no
395
+ * denial), `role` (a role it names is not held), `validity` (a deny outside
396
+ * its `validFrom` / `validUntil`; an inactive allow adds an `inactive-grant`
397
+ * denial instead), `break-glass-inactive` (a break-glass grant with no
398
+ * asserted purpose).
399
+ */
400
+ type TraceSkipReason = "via-only" | "purpose" | "field" | "grantee" | "role" | "validity" | "break-glass-inactive";
401
+ type TraceSkip = {
402
+ readonly role: string | null;
403
+ readonly permission: string;
404
+ readonly effect: "allow" | "deny";
405
+ readonly why: TraceSkipReason;
406
+ };
407
+ /**
408
+ * What `explain` saw: how many candidate grants it examined before the
409
+ * outcome, which allows matched (including the ones a deny overrode), which
410
+ * denies matched, and which grants it passed over. `denies[0]` is the deny
411
+ * that produced a `deny` outcome, or the deny a break-glass grant lifted.
412
+ * Pure local computation; never on a decision event.
413
+ */
414
+ type Trace = {
415
+ readonly evaluated: number;
416
+ readonly allows: readonly MatchedGrant[];
417
+ readonly denies: readonly MatchedGrant[];
418
+ readonly skipped: readonly TraceSkip[];
419
+ };
420
+ type GrantedDecision = {
421
+ readonly outcome: "granted";
422
+ readonly subject: Subject;
423
+ readonly matched: MatchedGrant;
424
+ readonly token: string;
425
+ readonly obligations?: readonly Obligation[];
426
+ readonly quota?: Quota;
427
+ /**
428
+ * The membership `permdock.activate` produced for the app to write: an
429
+ * elevated, time-bound, attributed row. Set only by `activate`; a plain
430
+ * `decide` never writes memberships.
431
+ */
432
+ readonly elevation?: Membership;
433
+ /** Present only with `explain: true`. */
434
+ readonly trace?: Trace;
435
+ };
436
+ type DeniedDecision = {
437
+ readonly outcome: "denied";
438
+ readonly denials: readonly Denial[];
439
+ readonly alternatives: readonly Permission[];
440
+ /** Present only with `explain: true`. */
441
+ readonly trace?: Trace;
442
+ };
443
+ type ApprovalRequiredDecision = {
444
+ readonly outcome: "approval-required";
445
+ readonly grant: MatchedGrant;
446
+ readonly reason: "human";
447
+ readonly token: string;
448
+ /** Present only with `explain: true`. */
449
+ readonly trace?: Trace;
450
+ };
451
+ /** A decision from `explain`: the same union, with the trace always present. */
452
+ type ExplainedDecision = Decision & {
453
+ readonly trace: Trace;
454
+ };
455
+ type Decision = GrantedDecision | DeniedDecision | ApprovalRequiredDecision;
456
+ //#endregion
457
+ //#region src/core/approval-policies.d.ts
458
+ /**
459
+ * One approval requirement kept as data, for a tenant or the whole platform.
460
+ * It adds to what the code requires and never removes a requirement.
461
+ */
462
+ type ApprovalPolicy = {
463
+ /** The permission key; a former key from `renamed` resolves. */
464
+ readonly permission: string;
465
+ /** Absent: every tenant. */
466
+ readonly tenant?: string;
467
+ /** Actor kinds it applies to (`['agent']`); absent: every call. A call without an actor never matches a list. */
468
+ readonly actors?: readonly string[];
469
+ /** A portable condition over the row. */
470
+ readonly where?: Condition;
471
+ /** A portable condition over the call's input (the proposed row). */
472
+ readonly check?: Condition;
473
+ /** The same shape as `allow(..., { approval })`, without `escalation`. */
474
+ readonly approval: ApprovalOption;
475
+ };
476
+ /**
477
+ * Data-driven approval requirements, a subject input like `RoleSource`:
478
+ * read once per instance for the subject's tenants (entries without a
479
+ * tenant always apply). A throw, a rejected promise or an invalid entry
480
+ * denies every call an allow would otherwise permit.
481
+ */
482
+ type ApprovalPolicySource = {
483
+ approvalPoliciesFor(query: {
484
+ readonly tenants: readonly string[];
485
+ }): readonly ApprovalPolicy[] | Promise<readonly ApprovalPolicy[]>;
486
+ };
487
+ declare function memoryApprovalPolicies(policies: readonly ApprovalPolicy[]): ApprovalPolicySource;
488
+ //#endregion
489
+ //#region src/core/arazzo.d.ts
490
+ type ArazzoSimulateInput = {
491
+ readonly arazzo: unknown;
492
+ readonly openapi: unknown;
493
+ readonly workflowId?: string;
494
+ readonly permissions?: PermissionTree;
495
+ readonly inputs?: Readonly<Record<string, unknown>>;
496
+ };
497
+ type ArazzoStepResult = {
498
+ readonly stepId: string;
499
+ /** The nested workflow that owns the step, when it is not the plan's workflow. */
500
+ readonly workflowId?: string;
501
+ readonly operationId?: string;
502
+ readonly permissions: readonly Permission[];
503
+ readonly decision: Decision;
504
+ readonly provisional?: true;
505
+ };
506
+ type ArazzoPlan = {
507
+ readonly workflowId: string;
508
+ readonly outcome: Decision["outcome"];
509
+ readonly steps: readonly ArazzoStepResult[];
510
+ };
511
+ type ArazzoFinding = {
512
+ readonly stepId: string;
513
+ readonly workflowId: string;
514
+ readonly reason: "undocumented" | "unsupported" | "validation" | "unknown-key";
515
+ readonly detail: string;
516
+ };
517
+ declare function arazzoFindings(input: ArazzoSimulateInput, tree: PermissionTree | undefined): readonly ArazzoFinding[];
518
+ declare function simulateArazzo(input: ArazzoSimulateInput, tree: PermissionTree | undefined, decide: (permission: Permission, data: unknown) => Decision): ArazzoPlan;
519
+ //#endregion
520
+ //#region src/core/elevated.d.ts
521
+ /**
522
+ * The only deny override: a break-glass grant overrides deny grants whose
523
+ * `name` it lists, and nothing else. It is an allow that stays non-portable
524
+ * (RLS never compiles it) and grants only once its `requires` are met.
525
+ */
526
+ declare function breakGlass<T>(permission: Permission<string, T> | readonly Permission<string, T>[], options?: BreakGlassOptions): Omit<Grant, "role" | "scope"> | Omit<Grant, "role" | "scope">[];
527
+ /**
528
+ * Support access with tenant consent: a role a vendor holds only through a
529
+ * consented, time-bound `via: 'support'` membership. `actorRequired` denies
530
+ * every decision under it without an `act`; `forbid` compiles to deny grants
531
+ * scoped to `via: 'support'`.
532
+ */
533
+ declare function supportAccess<const S extends string>(options: SupportAccessOptions<S> & {
534
+ readonly on: S;
535
+ }): RoleBinding<S>;
536
+ /** Support access held in the `tenant` scope. */
537
+ declare function supportAccess(options: SupportAccessOptions<never>): RoleBinding<"tenant">;
538
+ type ActivateInput = {
539
+ readonly role: string | Role;
540
+ /** The scope the activation applies in (a declared name or the `tenant` / `team` alias). */
541
+ readonly scope: string;
542
+ readonly id: string;
543
+ /** Ancestor scope ids, keyed by scope name, for a nested-scope activation. */
544
+ readonly within?: Readonly<Record<string, string>>;
545
+ /** How long the elevation lasts; capped at the role's `maxDuration`. */
546
+ readonly duration?: string;
547
+ readonly reason?: string;
548
+ };
549
+ //#endregion
550
+ //#region src/core/ownership.d.ts
551
+ /** Who a role change is about: their principal id and their membership in the scope instance. */
552
+ type RoleChangeTarget = {
553
+ readonly id: string;
554
+ /** The kind of the target's membership in the instance (`staff`, `contact`, ...). */
555
+ readonly via?: string;
556
+ /** The roles the target holds in the instance now. */
557
+ readonly roles?: readonly string[];
558
+ /** `idp` when the identity provider owns the target's membership: the application cannot change it. */
559
+ readonly managedBy?: "idp";
560
+ };
561
+ type RoleChange = {
562
+ readonly kind: "assign" | "revoke" | "transfer";
563
+ readonly role: string | Role;
564
+ /** The scope the role is held at (a declared name or alias). */
565
+ readonly scope: string;
566
+ /** The scope instance. */
567
+ readonly id: string;
568
+ /** Ids of the instance's ancestor scopes; a holder there may assign here. */
569
+ readonly within?: Readonly<Record<string, string>>;
570
+ readonly target: RoleChangeTarget;
571
+ /**
572
+ * How many principals hold `role` in the instance now, from the
573
+ * application's store. Without it a role with `min`, `max` or
574
+ * `transferOnly` is denied.
575
+ */
576
+ readonly holders?: number;
577
+ };
578
+ /**
579
+ * `granted` names the role that authorised the change (`null` when a
580
+ * `meta.manageRoles` holder or the declared-role ceiling did); `denied` lists
581
+ * every rule the change breaks.
582
+ */
583
+ type RoleChangeDecision = {
584
+ readonly outcome: "granted";
585
+ readonly change: RoleChange;
586
+ readonly role: string | null;
587
+ } | {
588
+ readonly outcome: "denied";
589
+ readonly change: RoleChange;
590
+ readonly denials: readonly Denial[];
591
+ };
592
+ type RoleChangeOptions = {
593
+ /**
594
+ * `true` when the application loaded `change.within` from its own store
595
+ * (the instance's stored parent), not from the request. Without it, a
596
+ * nested instance's tenant comes only from a live membership the actor
597
+ * holds on that instance or under it.
598
+ */
599
+ readonly trusted?: boolean;
600
+ };
601
+ //#endregion
602
+ //#region src/core/validation.d.ts
603
+ type Boundary = "http-body" | "mcp-args" | "tool-args" | "decision-endpoint" | "manual";
604
+ //#endregion
605
+ //#region src/core/who-can.d.ts
606
+ /** One way a principal holds a permission on an object. */
607
+ type HoldingVia = {
608
+ readonly kind: "role";
609
+ readonly role: string;
610
+ readonly membership: Membership;
611
+ } | {
612
+ readonly kind: "relation";
613
+ readonly resource: string;
614
+ readonly relation: string;
615
+ /** The instance the relation is held on: the object or one of its ancestors. */
616
+ readonly id: string;
617
+ } | {
618
+ readonly kind: "share";
619
+ readonly resource: string;
620
+ readonly relation: string;
621
+ readonly id: string;
622
+ readonly expiresAt?: number;
623
+ /** The group the share names, when the principal holds it as one of its members. */
624
+ readonly group?: RelationGroup;
625
+ };
626
+ type Holder = {
627
+ readonly principal: {
628
+ readonly id: string;
629
+ };
630
+ readonly via: readonly HoldingVia[];
631
+ };
632
+ /**
633
+ * Who holds a permission on one object, for share dialogs and access
634
+ * reviews. It lists and never grants. `complete: false` means some grantee
635
+ * could not be enumerated (a global role, a plan, a source without `list`,
636
+ * an unavailable relation): holders may be missing, so check with `decide`.
637
+ */
638
+ type WhoCan = {
639
+ readonly permission: string;
640
+ readonly holders: readonly Holder[];
641
+ readonly complete: boolean;
642
+ };
643
+ //#endregion
644
+ //#region src/core/hosted.d.ts
645
+ /** One grant authored in PermDock Cloud; its grantee is a declared role, plan or relation. */
646
+ type HostedGrant = {
647
+ readonly id: string;
648
+ readonly permission: string;
649
+ readonly effect?: "allow" | "deny";
650
+ readonly to: Grantee | readonly Grantee[];
651
+ readonly where?: Condition;
652
+ readonly check?: Condition;
653
+ readonly approval?: "human" | ApprovalRequirement;
654
+ readonly fields?: readonly string[];
655
+ };
656
+ /** PolicyDocument v1: the payload of a `permdock-policy+jwt` under the `policy` claim. */
657
+ type PolicyDocument = {
658
+ readonly v: 1;
659
+ readonly id: string;
660
+ readonly fingerprint: string;
661
+ /** The catalog fingerprint the document was authored against. */
662
+ readonly catalog: string;
663
+ readonly issuedAt: number;
664
+ readonly grants: readonly HostedGrant[];
665
+ };
666
+ /**
667
+ * The channel for hosted grants. `createPermDock` reads `current()` once;
668
+ * the application calls `refresh()` on its own schedule, never a check.
669
+ */
670
+ type PolicySource = {
671
+ current(): PolicyDocument | null;
672
+ refresh(): Promise<void>;
673
+ };
674
+ type HostedGrantDropReason = "not-hostable" | "unknown-permission" | "unknown-grantee" | "non-portable" | "weaker-approval" | "invalid";
675
+ /** Reported through `on('error')` when a hosted grant is not merged; never thrown. */
676
+ type HostedGrantDropped = {
677
+ readonly kind: "hosted-grant-dropped";
678
+ readonly document: string;
679
+ readonly grant: string;
680
+ readonly reason: HostedGrantDropReason;
681
+ };
682
+ declare function memoryPolicySource(document?: PolicyDocument | null): PolicySource;
683
+ /** Validates the document envelope; per-grant checks happen at merge time. */
684
+ declare function parsePolicyDocument(json: unknown): PolicyDocument;
685
+ /** True for the portable subset only: no `opaque`, no `sqlFunction`, no unknown op. */
686
+ declare function isPortableCondition(value: unknown): value is Condition;
687
+ /**
688
+ * The code policy plus the hosted grants that pass every rule. Hosted
689
+ * allows OR with code allows and any deny still wins, so a hosted grant can
690
+ * never override a code deny; one that fails a rule is dropped, not thrown.
691
+ */
692
+ declare function mergeHostedGrants(policy: Policy, document: PolicyDocument | null): {
693
+ readonly policy: Policy;
694
+ readonly dropped: readonly HostedGrantDropped[];
695
+ };
696
+ //#endregion
697
+ //#region src/core/permdock.d.ts
698
+ type DecideOptions = {
699
+ /** `true` skips schema validation for a row the server loaded itself. Otherwise `data` is validated against the resource schema first (`validate: 'boundary'`), and a failure denies with reason `validation`. */
700
+ readonly trusted?: boolean;
701
+ /** Where untrusted data came from, reported on validation errors. Defaults to `'manual'`. */
702
+ readonly boundary?: Boundary;
703
+ /** Decision clock in Unix seconds, for expiries and limits. Defaults to the current time. */
704
+ readonly now?: number;
705
+ /** The call that produced the decision, reported on the decision event. Defaults to `'decide'`. */
706
+ readonly source?: DecisionEvent["source"];
707
+ /** The adapter that made the call, reported on the decision event. */
708
+ readonly adapter?: string;
709
+ /** Per-call unauthorized handler for `assert`; runs before instance and policy handlers. */
710
+ readonly onDenied?: (decision: Decision) => never | void;
711
+ /** The field being read or written; only grants whose `fields` cover it match. */
712
+ readonly field?: string;
713
+ /** `true` attaches a `trace` to the decision: the grants evaluated, matched and skipped. Off by default and free when off. */
714
+ readonly explain?: boolean;
715
+ };
716
+ type SimulateOptions = {
717
+ /** Decision clock in Unix seconds for the whole batch: grant validity, membership expiry and limits are read as of this instant. Defaults to the current time. */
718
+ readonly now?: number;
719
+ };
720
+ type RowPair<T> = {
721
+ readonly current: T;
722
+ readonly next: T;
723
+ };
724
+ type WhereResult = {
725
+ readonly condition: Condition | {
726
+ readonly op: "or";
727
+ readonly conditions: readonly [];
728
+ };
729
+ readonly partial: boolean;
730
+ /**
731
+ * The subject `where()` was built for. `toWhere` reads its memberships for
732
+ * `memberOf` when no `subject` option is passed. Not enumerable, so it never
733
+ * serialises with the result.
734
+ */
735
+ readonly subject?: Subject;
736
+ /** The policy's scopes, for `memberOf`; not enumerable either. */
737
+ readonly scopes?: readonly Scope[];
738
+ /** The policy's resource graph, for `related`; not enumerable either. */
739
+ readonly resources?: ReadonlyMap<string, ResourceNode>;
740
+ };
741
+ type PermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
742
+ readonly can: {
743
+ (permission: Permission<string, unknown, "instance">, data: unknown, options?: DecideOptions): boolean;
744
+ (permission: Permission<string, unknown, "collection">, data?: unknown, options?: DecideOptions): boolean;
745
+ };
746
+ readonly decide: {
747
+ (permission: Permission<string, unknown, "instance">, data: unknown, options?: DecideOptions): Decision;
748
+ (permission: Permission<string, unknown, "collection">, data?: unknown, options?: DecideOptions): Decision;
749
+ };
750
+ readonly assert: {
751
+ (permission: Permission<string, unknown, "instance">, data: unknown, options?: DecideOptions): Extract<Decision, {
752
+ readonly outcome: "granted";
753
+ }>;
754
+ (permission: Permission<string, unknown, "collection">, data?: unknown, options?: DecideOptions): Extract<Decision, {
755
+ readonly outcome: "granted";
756
+ }>;
757
+ };
758
+ /**
759
+ * `decide` with `explain: true`: the same decision, with a `trace` that
760
+ * names the grants evaluated, the allows and denies that matched (so a
761
+ * `denied` says which deny won) and the grants passed over. Local
762
+ * computation only; the trace never reaches a `DecisionSink`.
763
+ */
764
+ readonly explain: {
765
+ (permission: Permission<string, unknown, "instance">, data: unknown, options?: Omit<DecideOptions, "explain">): ExplainedDecision;
766
+ (permission: Permission<string, unknown, "collection">, data?: unknown, options?: Omit<DecideOptions, "explain">): ExplainedDecision;
767
+ };
768
+ readonly filter: <T>(permission: Permission<string, T, "instance">, rows: readonly T[], options?: DecideOptions) => T[];
769
+ readonly pick: <T>(permission: Permission<string, T, "instance">, row: T, options?: DecideOptions) => Partial<T>;
770
+ readonly where: (permission: Permission) => WhereResult;
771
+ readonly actions: (resource: Permission | {
772
+ readonly [key: string]: unknown;
773
+ }, data: unknown, options?: DecideOptions) => Permission[];
774
+ readonly simulate: {
775
+ (checks: readonly (readonly [Permission, unknown?])[], options?: SimulateOptions): Decision[];
776
+ (preview: {
777
+ readonly roles?: readonly (string | Role)[];
778
+ readonly memberships?: readonly Membership[];
779
+ readonly tenant?: string;
780
+ }): PermDock<V>;
781
+ (plan: ArazzoSimulateInput): ArazzoPlan;
782
+ };
783
+ readonly snapshot: (options?: {
784
+ readonly include?: readonly (Permission | {
785
+ readonly [key: string]: unknown;
786
+ })[];
787
+ readonly tenants?: "all";
788
+ readonly signer?: TokenSigner;
789
+ readonly audience?: string | readonly string[];
790
+ }) => Snapshot | Promise<string>;
791
+ readonly on: (event: "decision" | "denied" | "approval" | "auth" | "error", handler: (payload: unknown) => void) => () => void;
792
+ readonly tenant: (id: string) => PermDock<V>;
793
+ readonly team: (id: string) => PermDock<V>;
794
+ readonly memberships: () => readonly Membership[];
795
+ readonly tenants: () => readonly string[];
796
+ /**
797
+ * Roles held in a tenant (the active one by default), or only on the
798
+ * memberships of one `scope` (and instance `id`). Ordered by rank: a role
799
+ * comes before the roles its `assigns` lists.
800
+ */
801
+ readonly heldRoles: (options?: {
802
+ readonly tenant?: string;
803
+ readonly scope?: string;
804
+ readonly id?: string;
805
+ }) => readonly Role[];
806
+ /** The distinct `meta.audience` values of the roles held in the active tenant, in rank order. */
807
+ readonly audiences: () => readonly string[];
808
+ readonly assignableRoles: (options?: {
809
+ readonly tenant?: string;
810
+ }) => readonly Role[];
811
+ /**
812
+ * The custom-role ceiling the subject may hand out: in a tenant (empty
813
+ * without one), or with `scope: 'global'` for platform custom roles, the
814
+ * allows of assignable global roles the subject holds. A snapshot answers
815
+ * only the tenant form.
816
+ */
817
+ readonly assignablePermissions: (options?: {
818
+ readonly tenant?: string;
819
+ readonly scope?: "global";
820
+ }) => readonly Permission[];
821
+ /**
822
+ * Whether the subject may assign, revoke or transfer a role in one scope
823
+ * instance: `assigns`, the ceiling, `for`, `exclusiveWith`, `min`, `max`
824
+ * and `transferOnly`. It never writes; the application does, and generated
825
+ * RLS triggers re-check the holder counts at commit. A nested instance's
826
+ * tenant comes from a live membership the subject holds on it, or from
827
+ * `change.within` only with `{ trusted: true }`; otherwise `no-membership`.
828
+ */
829
+ readonly decideRoleChange: (change: RoleChange, options?: RoleChangeOptions) => RoleChangeDecision;
830
+ /**
831
+ * Loads the relation facts `permission` needs for `rows` into this
832
+ * instance's cache, so `can`, `decide` and `filter` answer synchronously
833
+ * over an async `RelationSource`. It never grants; a failed load leaves
834
+ * the checks denied with `relation-unavailable`.
835
+ */
836
+ readonly loadRelations: (permission: Permission, rows: readonly unknown[]) => Promise<void>;
837
+ /**
838
+ * Who holds `permission` on `resource` and how (role, relation or share),
839
+ * from `MembershipSource.list` and `RelationSource.related`. It lists and
840
+ * never grants; `complete: false` means some holders could not be listed.
841
+ */
842
+ readonly whoCan: (permission: Permission<string, unknown, "instance">, resource: unknown) => Promise<WhoCan>;
843
+ /**
844
+ * Requests a just-in-time activation of an eligible role. It never writes:
845
+ * a granted decision carries the elevated membership under `elevation` for
846
+ * the app to write, and `approval-required` comes back first when the
847
+ * role's `activation` sets `approval`.
848
+ */
849
+ readonly activate: (input: ActivateInput) => Decision;
850
+ readonly roles: V["roles"] extends RoleTree ? V["roles"] : RoleTree;
851
+ readonly plans: V["plans"] extends PlanTree ? V["plans"] : PlanTree;
852
+ readonly permissions: V["permissions"] extends Policy["permissions"] ? V["permissions"] : Policy["permissions"];
853
+ readonly subject: Subject;
854
+ };
855
+ type PermDockOptions = {
856
+ readonly tenant?: string;
857
+ /** One source, or several composed with `composeMemberships`. */
858
+ readonly memberships?: MembershipSource | readonly MembershipSource[];
859
+ readonly customRoles?: RoleSource;
860
+ /** Plans and seats from billing, merged into `principal.plans` for the active tenant. */
861
+ readonly entitlements?: EntitlementSource;
862
+ readonly actor?: Actor;
863
+ readonly delegation?: Delegation;
864
+ readonly sink?: DecisionSink;
865
+ readonly limits?: LimitStore;
866
+ readonly session?: string;
867
+ readonly expiresAt?: number;
868
+ /** Hosted grants; `current()` is read once, when the instance is created. */
869
+ readonly policies?: PolicySource;
870
+ /** The object graph for `through` and edge-table relations; without it they deny with `relation-unavailable`. */
871
+ readonly relations?: RelationSource;
872
+ /** Approval requirements kept as data; they add to the code's and never remove one. A throw denies. */
873
+ readonly approvalPolicies?: ApprovalPolicySource;
874
+ };
875
+ declare function createPermDock<TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, user: TUser | Subject | null, options?: PermDockOptions): PermDock<V> | Promise<PermDock<V>>;
876
+ //#endregion
877
+ //#region src/core/credential.d.ts
878
+ type CredentialKind = "user" | "service";
879
+ /** One permission (a key) a credential may use: on every instance, or only on `ids`. */
880
+ type CredentialPermission = {
881
+ readonly permission: string;
882
+ readonly ids?: readonly string[];
883
+ };
884
+ /**
885
+ * Credential v1: what a verified API key stands for, never the secret. A
886
+ * `user` credential acts as its owner (`principal`) narrowed to
887
+ * `permissions`; a `service` credential is its own `service` principal
888
+ * holding `roles` in `tenant`, narrowed the same way.
889
+ */
890
+ type Credential = {
891
+ readonly v: 1;
892
+ readonly id: string;
893
+ readonly kind: CredentialKind;
894
+ /** The owner of a `user` credential, or the id of the service principal. */
895
+ readonly principal: string;
896
+ /** Service only: the instance of the first scope its roles are held in. */
897
+ readonly tenant?: string;
898
+ /** Service only: the roles it holds in `tenant`. */
899
+ readonly roles?: readonly string[];
900
+ readonly permissions: readonly CredentialPermission[];
901
+ readonly createdBy: string;
902
+ /** Seconds since the epoch. */
903
+ readonly createdAt: number;
904
+ /** Seconds since the epoch; absent only where a credential policy allows it. */
905
+ readonly expiresAt?: number;
906
+ readonly name?: string;
907
+ };
908
+ type CredentialPrincipal = Principal & {
909
+ readonly credential: Credential;
910
+ };
911
+ /**
912
+ * What one scope instance allows for API keys created in it. Every rule only
913
+ * tightens; several policies must all hold.
914
+ */
915
+ type CredentialPolicy = {
916
+ /** Longest a key may live, in seconds from `createdAt`. */
917
+ readonly maxTtl?: number;
918
+ /** Kinds that may be created. */
919
+ readonly kinds?: readonly CredentialKind[];
920
+ /** Creating a key is `approval-required`. */
921
+ readonly approval?: boolean;
922
+ /** A key may omit `expiresAt`; without it every key must expire. */
923
+ readonly allowNoExpiry?: boolean;
924
+ };
925
+ type CredentialPolicyViolation = "kind" | "no-expiry" | "ttl";
926
+ type CredentialPermissionInput = Permission | {
927
+ readonly permission: Permission;
928
+ readonly ids: readonly string[];
929
+ };
930
+ type CredentialRequestBase = {
931
+ readonly id: string;
932
+ readonly permissions: readonly CredentialPermissionInput[];
933
+ readonly expiresAt?: number;
934
+ readonly name?: string;
935
+ };
936
+ type CredentialRequest = (CredentialRequestBase & {
937
+ readonly kind: "user";
938
+ }) | (CredentialRequestBase & {
939
+ readonly kind: "service";
940
+ /** The service principal's id; defaults to the credential id. */
941
+ readonly principal?: string;
942
+ readonly tenant: string;
943
+ readonly roles: readonly string[];
944
+ });
945
+ type CredentialDecision = {
946
+ readonly outcome: "granted";
947
+ readonly credential: Credential;
948
+ } | {
949
+ readonly outcome: "approval-required";
950
+ readonly credential: Credential;
951
+ /** Bound to the credential's content and its creator; pass it as `approved` to resume. */
952
+ readonly token: string;
953
+ } | {
954
+ readonly outcome: "denied";
955
+ readonly denials: readonly Denial[];
956
+ };
957
+ type DecideCredentialOptions = {
958
+ /** Where the tenant's `credentials` policy comes from. Without it, only the no-expiry rule applies. */
959
+ readonly settings?: SettingsSource;
960
+ /** The `token` of an approval the application consumed for this request. */
961
+ readonly approved?: string;
962
+ /** Seconds since the epoch. */
963
+ readonly now?: number;
964
+ };
965
+ /**
966
+ * The first rule of `policy` the credential breaks, or `undefined`. A key
967
+ * without `expiresAt` passes only when some policy sets `allowNoExpiry` and
968
+ * none sets `maxTtl`; an empty list therefore refuses it.
969
+ */
970
+ declare function credentialPolicyViolation(credential: Credential, policy: CredentialPolicy | readonly CredentialPolicy[]): CredentialPolicyViolation | undefined;
971
+ /**
972
+ * Validates an untrusted credential record and returns a frozen copy with
973
+ * only the v1 fields, or `undefined`. Unknown fields are dropped; a wrong
974
+ * type in a known field, a service credential without `tenant` and `roles`,
975
+ * or a user credential with either, rejects the whole record.
976
+ */
977
+ declare function parseCredential(input: unknown): Credential | undefined;
978
+ /**
979
+ * The delegation a credential narrows its principal to: OAuth scopes for
980
+ * permissions on every instance, one RFC 9396 entry per id otherwise. A key
981
+ * the definitions no longer declare is dropped, so a credential whose every
982
+ * key is gone delegates nothing and every check is denied.
983
+ */
984
+ declare function credentialDelegation(credential: Credential, permissions: PermissionTree): Delegation;
985
+ /**
986
+ * The subject a verified credential acts as. A `user` credential is its
987
+ * owner, passed live as `owner` (roles and memberships as of this request),
988
+ * with the credential's delegation: every check is the owner's rights
989
+ * intersected with the key's. A `service` credential is a `service`
990
+ * principal whose only membership is `roles` in `tenant`. An owner whose id
991
+ * is not the credential's `principal`, or who is not a user, is anonymous.
992
+ */
993
+ declare function credentialSubject(credential: Credential, options: {
994
+ readonly permissions: PermissionTree;
995
+ readonly owner?: Principal;
996
+ }): Subject<CredentialPrincipal> | Subject;
997
+ /**
998
+ * Decides whether the subject of `permdock` may create the credential in
999
+ * `request`. The creator must be a signed-in user or service that is not
1000
+ * itself a link or a credential; a delegated creator hands out only what its
1001
+ * delegation covers. A service key's tenant must be one the creator is a
1002
+ * member of, its roles among the creator's `assignableRoles` there and its
1003
+ * permissions within `assignablePermissions` there (`exceeds-creator`). The
1004
+ * `credentials` policy of the key's tenant (a service key's own, a user
1005
+ * key's the creator's active tenant) then applies (`credential-policy`; a
1006
+ * settings source that throws denies with `rule: 'unavailable'`), and
1007
+ * `approval` makes the result `approval-required` until `approved` carries
1008
+ * its token. PermDock never stores the credential; the application does,
1009
+ * after a `granted` result.
1010
+ */
1011
+ declare function decideCredential(permdock: PermDock, request: CredentialRequest, options?: DecideCredentialOptions): Promise<CredentialDecision>;
1012
+ //#endregion
1013
+ //#region src/core/wire-denial.d.ts
1014
+ /**
1015
+ * A denial as it leaves the process: in a decision event, a Problem Details
1016
+ * body, an MCP or WebMCP refusal and the decision endpoint. `detail` is a
1017
+ * JSON value (a string, or `LimitDetail` on `limit`); what a closure threw
1018
+ * and a validation error stay in process.
1019
+ */
1020
+ type WireDenial = {
1021
+ readonly role: string | null;
1022
+ readonly reason: DenialReason;
1023
+ readonly to?: Grantee | readonly Grantee[];
1024
+ readonly detail?: unknown;
1025
+ };
1026
+ /** A `Decision` whose denials are `WireDenial`s, as the decision endpoint sends it. */
1027
+ type WireDecision = GrantedDecision | ApprovalRequiredDecision | (Omit<DeniedDecision, "denials"> & {
1028
+ readonly denials: readonly WireDenial[];
1029
+ });
1030
+ //#endregion
1031
+ //#region src/core/interfaces.d.ts
1032
+ type DecisionProvider = {
1033
+ readonly name: string;
1034
+ handles(permission: Permission): boolean;
1035
+ decide(request: {
1036
+ readonly permission: Permission;
1037
+ readonly data?: unknown;
1038
+ readonly subject: Subject;
1039
+ readonly local: Decision;
1040
+ }): Promise<Decision>;
1041
+ /**
1042
+ * Ids of the resources of `permission.resource` the subject may act on.
1043
+ * `null` means the provider could not answer and every row is denied;
1044
+ * `undefined` means it cannot list, and each row is decided on its own.
1045
+ */
1046
+ permitted?(request: {
1047
+ readonly permission: Permission;
1048
+ readonly subject: Subject;
1049
+ }): Promise<readonly string[] | null | undefined>;
1050
+ };
1051
+ type RoleSource = {
1052
+ rolesFor(tenant: string): CustomRole[] | Promise<CustomRole[]>;
1053
+ assignable?(tenant: string): string[] | Promise<string[]>;
1054
+ /** Platform custom roles (`scope: 'global'`), read once per signed-in subject. A role here with a tenant is ignored. */
1055
+ globalRoles?(): CustomRole[] | Promise<CustomRole[]>;
1056
+ };
1057
+ /** One member of a scope instance, as `MembershipSource.list` returns it. */
1058
+ type MemberEntry = {
1059
+ readonly principal: {
1060
+ readonly id: string;
1061
+ };
1062
+ readonly membership: Membership;
1063
+ };
1064
+ type MembershipSource = {
1065
+ membershipsFor(principal: {
1066
+ readonly id: string;
1067
+ readonly kind?: string;
1068
+ }, options: {
1069
+ readonly tenant?: string;
1070
+ }): Membership[] | Promise<Membership[]>;
1071
+ /** Every membership held in one scope instance, for member lists and access reviews. */
1072
+ list?(query: {
1073
+ readonly scope: string;
1074
+ readonly id: string;
1075
+ }): MemberEntry[] | Promise<MemberEntry[]>;
1076
+ /**
1077
+ * The principal's current authorization version, bumped on every membership
1078
+ * change. A token whose `authzVersion` is behind it is stale for the
1079
+ * policy's `fresh` permissions.
1080
+ */
1081
+ version?(principal: {
1082
+ readonly id: string;
1083
+ }): number | undefined | Promise<number | undefined>;
1084
+ /**
1085
+ * Keep the memberships the verified token carries and read this source only
1086
+ * when the token says they were truncated (`claimsFirst`).
1087
+ */
1088
+ readonly claimsFirst?: boolean;
1089
+ };
1090
+ /** An object's parent chain, as `RelationSource.ancestors` returns it. */
1091
+ type RelationChain = {
1092
+ /** Whether the object itself is restricted: nothing above it reaches it. */
1093
+ readonly restricted?: boolean;
1094
+ /** Ancestors nearest first, at most `depth`; a restricted one ends the walk after itself. */
1095
+ readonly ancestors: readonly {
1096
+ readonly id: string;
1097
+ readonly restricted?: boolean;
1098
+ }[];
1099
+ /** The chain goes on above the last entry. */
1100
+ readonly truncated?: boolean;
1101
+ };
1102
+ type HolderPeriod = {
1103
+ /** Seconds since the epoch; before it the relation does not hold yet. */
1104
+ readonly startsAt?: number;
1105
+ /** Seconds since the epoch; from it on the relation no longer holds. */
1106
+ readonly expiresAt?: number;
1107
+ };
1108
+ /** A group holding a relation on an object: whoever holds `relation` on the group's instance holds it too. */
1109
+ type RelationGroup = {
1110
+ readonly resource: string;
1111
+ readonly id: string;
1112
+ readonly relation: string;
1113
+ };
1114
+ /**
1115
+ * One holder of a relation on an object, as `RelationSource.related` returns
1116
+ * it: a principal, or a group (an edge row whose `groups` column names one).
1117
+ */
1118
+ type RelationHolder = HolderPeriod & ({
1119
+ readonly principal: {
1120
+ readonly id: string;
1121
+ };
1122
+ } | {
1123
+ readonly group: RelationGroup;
1124
+ });
1125
+ /**
1126
+ * The object graph: parent chains, links and who holds a relation on an
1127
+ * object. A source answers facts and never decides; a thrown or rejected
1128
+ * call, or a Promise the instance has not loaded, denies with
1129
+ * `relation-unavailable`.
1130
+ */
1131
+ type RelationSource = {
1132
+ /**
1133
+ * With `through: 'parent'`, the parent chain; with a link name, the one
1134
+ * instance that link points to (`depth` is then 1).
1135
+ */
1136
+ ancestors(query: {
1137
+ readonly resource: string;
1138
+ readonly id: string;
1139
+ readonly through: string;
1140
+ readonly depth: number;
1141
+ }): RelationChain | Promise<RelationChain>;
1142
+ related(query: {
1143
+ readonly resource: string;
1144
+ readonly id: string;
1145
+ readonly relation: string;
1146
+ }): RelationHolder[] | Promise<RelationHolder[]>;
1147
+ };
1148
+ /** Plan and seat names a principal holds in a tenant, from billing (Stripe Entitlements, a table). */
1149
+ type EntitlementSource = {
1150
+ entitlementsFor(principal: {
1151
+ readonly id: string;
1152
+ }, options: {
1153
+ readonly tenant?: string;
1154
+ }): string[] | Promise<string[]>;
1155
+ };
1156
+ declare function memoryEntitlementSource(entries: Readonly<Record<string, readonly string[]>>): EntitlementSource;
1157
+ type JwtClaims = {
1158
+ readonly iss?: string;
1159
+ readonly sub?: string;
1160
+ readonly aud?: string | readonly string[];
1161
+ readonly exp?: number;
1162
+ readonly nbf?: number;
1163
+ readonly iat?: number;
1164
+ readonly [key: string]: unknown;
1165
+ };
1166
+ type TokenFailureCause = "invalid-signature" | "expired" | "not-yet-valid" | "wrong-audience" | "wrong-issuer" | "wrong-token-type" | "alg-not-allowed" | "alg-none" | "unknown-kid" | "malformed" | "encrypted-token" | "dpop-proof-invalid" | "mtls-binding-mismatch" | "sender-constraint-required" | "token-in-query" | "invalid-claims" | "invalid-chain" | "jwks-unavailable" | "discovery-unavailable" | "discovery-mismatch";
1167
+ type VerifiedToken<TClaims extends JwtClaims = JwtClaims> = {
1168
+ readonly ok: true;
1169
+ readonly claims: TClaims;
1170
+ readonly header: {
1171
+ readonly alg: string;
1172
+ readonly kid?: string;
1173
+ readonly typ?: string;
1174
+ };
1175
+ };
1176
+ type VerificationFailure = {
1177
+ readonly ok: false;
1178
+ readonly reason: "invalid-token";
1179
+ readonly cause: TokenFailureCause;
1180
+ };
1181
+ type TokenVerifier<TClaims extends JwtClaims = JwtClaims> = {
1182
+ verify(token: string, expectations: {
1183
+ readonly typ?: string | readonly string[];
1184
+ readonly audience?: string | readonly string[];
1185
+ readonly issuer?: string;
1186
+ readonly clockTolerance?: number;
1187
+ }): Promise<VerifiedToken<TClaims> | VerificationFailure>;
1188
+ };
1189
+ type TokenSigner = {
1190
+ sign(payload: Readonly<Record<string, unknown>>, options: {
1191
+ readonly typ: "permdock-snapshot+jwt" | "permdock-approval+jwt" | "permdock-decisions+jwt" | "permdock-policy+jwt" | "permdock-capability+jwt";
1192
+ readonly audience?: string | readonly string[];
1193
+ readonly expiresAt?: number;
1194
+ }): Promise<string>;
1195
+ readonly kid?: string;
1196
+ jwks?(): Promise<{
1197
+ readonly keys: readonly JsonWebKeyLike[];
1198
+ }>;
1199
+ };
1200
+ type SubjectResolver<TInput, TPrincipal extends Principal = Principal> = (input: TInput, options?: {
1201
+ readonly tenant?: string;
1202
+ }) => Subject<TPrincipal> | Promise<Subject<TPrincipal>>;
1203
+ type Snapshot = {
1204
+ readonly v: 1;
1205
+ readonly issuedAt: number;
1206
+ readonly subject: {
1207
+ readonly principal: {
1208
+ readonly id: string;
1209
+ readonly roles: readonly string[];
1210
+ readonly plans?: readonly string[];
1211
+ readonly tenant?: string;
1212
+ readonly memberships?: readonly Membership[];
1213
+ } | null;
1214
+ readonly delegation?: Subject["delegation"];
1215
+ readonly context: Readonly<Record<string, unknown>>;
1216
+ };
1217
+ /** Roles held in the active tenant, in rank order. */
1218
+ readonly roles: readonly string[];
1219
+ /** The distinct `meta.audience` values of `roles`, in rank order; absent when none has one. */
1220
+ readonly audiences?: readonly string[];
1221
+ readonly grants: readonly SnapshotGrant[];
1222
+ readonly tenants: readonly string[];
1223
+ readonly include?: readonly string[];
1224
+ readonly simulated?: true;
1225
+ readonly expiresAt?: number;
1226
+ readonly vocabulary?: {
1227
+ readonly roles?: Readonly<Record<string, Role>>;
1228
+ readonly plans?: Readonly<Record<string, Plan>>;
1229
+ };
1230
+ /** The policy's scopes in order, so a client checks the row against each membership's instance. */
1231
+ readonly scopes?: readonly SnapshotScope[];
1232
+ /** One entry per tenant in `tenants`: what the subject may hand out there. Absent without tenants. */
1233
+ readonly assignable?: readonly SnapshotAssignable[];
1234
+ /**
1235
+ * Allow grants of held roles that only a plan the subject lacks keeps
1236
+ * from applying; they grant nothing and name the plan a denial asks for.
1237
+ */
1238
+ readonly notEntitled?: readonly SnapshotNotEntitled[];
1239
+ /**
1240
+ * The permission keys the policy's delegations let the actor use for the
1241
+ * principal, sorted; present only when one applies. Outside it a check is
1242
+ * `not-delegated`; inside it a token delegation, when there is one, must
1243
+ * still cover.
1244
+ */
1245
+ readonly delegated?: readonly string[];
1246
+ };
1247
+ /** A grant the subject would hold on another plan: its permission, role and `to`. */
1248
+ type SnapshotNotEntitled = {
1249
+ readonly permission: string;
1250
+ readonly role: string | null;
1251
+ readonly to: Grantee | readonly Grantee[];
1252
+ };
1253
+ /** One declared scope as a snapshot carries it. */
1254
+ type SnapshotScope = {
1255
+ readonly name: string;
1256
+ readonly key: string;
1257
+ readonly within?: string;
1258
+ /** Resources whose rows this scope's key partitions, from their `memberOf` relations. */
1259
+ readonly resources?: readonly string[];
1260
+ };
1261
+ /** The declared roles and the custom-role ceiling the subject may assign in one tenant. */
1262
+ type SnapshotAssignable = {
1263
+ readonly tenant: string;
1264
+ readonly roles: readonly string[];
1265
+ readonly permissions: readonly Permission[];
1266
+ };
1267
+ type SnapshotGrant = {
1268
+ readonly permission: string;
1269
+ readonly effect: "allow" | "deny";
1270
+ readonly role: string | null;
1271
+ readonly to: Grantee | readonly Grantee[];
1272
+ readonly where?: Condition;
1273
+ readonly check?: Condition;
1274
+ readonly approval?: "human" | ApprovalRequirement;
1275
+ /** A scope name or one resource; absent for a global grant. */
1276
+ readonly scope?: string | {
1277
+ readonly resource: string;
1278
+ };
1279
+ readonly membership?: Membership;
1280
+ readonly portable?: false;
1281
+ readonly fields?: readonly string[];
1282
+ /** When the grant applies (Unix seconds, `from` inclusive, `until` exclusive); absent means always. */
1283
+ readonly validity?: GrantValidity;
1284
+ };
1285
+ type SnapshotSource = {
1286
+ get(): Promise<Snapshot | string> | Snapshot | string;
1287
+ subscribe?(listener: () => void): () => void;
1288
+ };
1289
+ type WhereCompiler<TTarget, TOptions = unknown> = (condition: Condition, target: TTarget, options?: TOptions) => unknown;
1290
+ type LimitConsumeInput = {
1291
+ readonly key: string;
1292
+ readonly subjectId: string;
1293
+ readonly count: number;
1294
+ readonly per: string;
1295
+ readonly now?: number;
1296
+ /** The active tenant; a quota counts per subject and tenant. */
1297
+ readonly tenant?: string;
1298
+ };
1299
+ type LimitRemaining = {
1300
+ readonly remaining: number;
1301
+ };
1302
+ type LimitStore = {
1303
+ consume(input: LimitConsumeInput): Promise<LimitRemaining> | LimitRemaining;
1304
+ remaining(input: LimitConsumeInput): LimitRemaining | undefined;
1305
+ };
1306
+ type DecisionSink = {
1307
+ write(events: readonly SinkEvent[]): Promise<void> | void;
1308
+ flush?(): Promise<void>;
1309
+ };
1310
+ type DirectoryEvent = {
1311
+ readonly type: "directory";
1312
+ readonly at: string;
1313
+ readonly source: "scim";
1314
+ readonly operation: "create" | "replace" | "patch" | "delete";
1315
+ readonly tenant: string;
1316
+ readonly resource: {
1317
+ readonly type: "User" | "Group";
1318
+ readonly id: string;
1319
+ };
1320
+ readonly credential: {
1321
+ readonly kind: "token";
1322
+ } | {
1323
+ readonly kind: "jwt";
1324
+ readonly iss?: string;
1325
+ };
1326
+ readonly active?: boolean;
1327
+ };
1328
+ type MembershipEvent = {
1329
+ readonly type: "membership";
1330
+ readonly at: string;
1331
+ readonly source: string;
1332
+ readonly operation: "added" | "removed" | "changed";
1333
+ readonly principal: {
1334
+ readonly id: string;
1335
+ };
1336
+ /** A declared scope name, or the `tenant` / `team` alias; absent for a global role change. */
1337
+ readonly scope?: string;
1338
+ /** The scope instance; present exactly when `scope` is. */
1339
+ readonly id?: string;
1340
+ /** The id of every ancestor scope, keyed by scope name. */
1341
+ readonly within?: Readonly<Record<string, string>>;
1342
+ readonly via?: string;
1343
+ /** When the membership lapses, in seconds since the epoch. */
1344
+ readonly expiresAt?: number;
1345
+ readonly roles: {
1346
+ readonly added: readonly string[];
1347
+ readonly removed: readonly string[];
1348
+ };
1349
+ readonly by?: {
1350
+ readonly id: string;
1351
+ readonly kind: string;
1352
+ };
1353
+ };
1354
+ /**
1355
+ * An API key's lifecycle: `created`, `rotated` and `revoked` from the
1356
+ * application or a credential store, `used` from `subjectFromApiKey`. A
1357
+ * `used` event carries `sample`, the fraction of uses reported.
1358
+ */
1359
+ type CredentialEvent = {
1360
+ readonly type: "credential";
1361
+ readonly at: string;
1362
+ readonly source: string;
1363
+ readonly operation: "created" | "used" | "rotated" | "revoked";
1364
+ readonly credential: {
1365
+ readonly id: string;
1366
+ readonly kind: CredentialKind;
1367
+ };
1368
+ readonly principal: {
1369
+ readonly id: string;
1370
+ };
1371
+ readonly tenant?: string;
1372
+ readonly expiresAt?: number;
1373
+ readonly by?: {
1374
+ readonly id: string;
1375
+ readonly kind: string;
1376
+ };
1377
+ readonly sample?: number;
1378
+ };
1379
+ type SinkEvent = DecisionEvent | DirectoryEvent | MembershipEvent | CredentialEvent | AccessEvent;
1380
+ /**
1381
+ * A support-access session lifecycle event: a tenant consented to vendor
1382
+ * support (`started`), the session lapsed (`ended`), or the tenant pulled
1383
+ * consent early (`revoked`). It never decides; it records what happened for
1384
+ * audit and revocation.
1385
+ */
1386
+ type AccessEvent = {
1387
+ readonly type: "access";
1388
+ readonly at: string;
1389
+ readonly source: string;
1390
+ readonly operation: "started" | "ended" | "revoked";
1391
+ readonly tenant: string;
1392
+ readonly principal: {
1393
+ readonly id: string;
1394
+ };
1395
+ /** The membership kind the session runs under (`support`). */
1396
+ readonly via: string;
1397
+ readonly roles: readonly string[];
1398
+ readonly member?: {
1399
+ readonly group: string;
1400
+ };
1401
+ readonly expiresAt?: number;
1402
+ /** The tenant principal that consented. */
1403
+ readonly grantedBy?: string;
1404
+ readonly reason?: string;
1405
+ readonly actor?: {
1406
+ readonly id: string;
1407
+ readonly kind: string;
1408
+ };
1409
+ };
1410
+ /**
1411
+ * Looks up the credential an API key stands for. `null` for a key that is
1412
+ * malformed, unknown, revoked or whose secret does not match; never throws
1413
+ * for bad input. Verification is the application's (or `apiKeyVerifier`'s),
1414
+ * never core's.
1415
+ */
1416
+ type CredentialVerifier = {
1417
+ verify(secret: string): Credential | null | Promise<Credential | null>;
1418
+ /**
1419
+ * Records a successful use at `at` (Unix seconds), for a `lastUsedAt`
1420
+ * column. Called after a key resolved and not awaited; a throw or a
1421
+ * rejection is ignored, so it never changes the subject.
1422
+ */
1423
+ touch?(id: string, at: number): void | Promise<void>;
1424
+ };
1425
+ type DecisionEvent = {
1426
+ readonly type: "decision";
1427
+ readonly at: string;
1428
+ readonly outcome: "granted" | "denied" | "approval-required";
1429
+ readonly permission: string;
1430
+ readonly scope: string;
1431
+ readonly resource: {
1432
+ readonly type: string;
1433
+ readonly id?: string;
1434
+ };
1435
+ readonly subject: {
1436
+ readonly principal: {
1437
+ readonly id: string;
1438
+ readonly roles: readonly string[];
1439
+ readonly tenant?: string;
1440
+ } | null;
1441
+ readonly actor?: {
1442
+ readonly id: string;
1443
+ readonly kind: string;
1444
+ };
1445
+ readonly delegation?: {
1446
+ readonly scopes?: readonly string[];
1447
+ readonly authorizationDetails?: readonly unknown[];
1448
+ };
1449
+ /** The API key the subject came from. */
1450
+ readonly credential?: {
1451
+ readonly id: string;
1452
+ readonly kind: CredentialKind;
1453
+ };
1454
+ };
1455
+ readonly tenant?: string;
1456
+ readonly membership?: Membership;
1457
+ readonly via?: string | null;
1458
+ readonly matched?: {
1459
+ readonly role: string | null;
1460
+ readonly permission: string;
1461
+ readonly to?: Grantee | readonly Grantee[];
1462
+ readonly hosted?: HostedGrantRef;
1463
+ readonly breakGlass?: true;
1464
+ };
1465
+ /** Purposes of use the caller asserted (`context.purpose`); present when any was. */
1466
+ readonly purpose?: readonly string[];
1467
+ /** The justification the caller supplied (`context.reason`); present when set. */
1468
+ readonly reason?: string;
1469
+ readonly denials?: readonly WireDenial[];
1470
+ readonly alternatives?: readonly string[];
1471
+ readonly token?: string;
1472
+ readonly trusted: boolean;
1473
+ readonly source: "can" | "decide" | "assert" | "filter" | "endpoint" | "adapter" | "approval" | "simulate" | "explain";
1474
+ readonly adapter?: string;
1475
+ readonly phase?: "requested" | "resolved";
1476
+ readonly counts?: {
1477
+ readonly granted: number;
1478
+ readonly denied: number;
1479
+ readonly approvalRequired: number;
1480
+ };
1481
+ };
1482
+ type AuthEvent = {
1483
+ readonly reason: "invalid-token" | "schema" | "unknown-role" | "groups-overflow" | "source-threw";
1484
+ readonly cause?: string;
1485
+ readonly source: string;
1486
+ readonly kid?: string;
1487
+ readonly alg?: string;
1488
+ readonly typ?: string;
1489
+ readonly issuer?: string;
1490
+ readonly requestId?: string;
1491
+ };
1492
+ /** What one tenant configures for itself. Every field only tightens. */
1493
+ type TenantSettings = {
1494
+ /** Rules for API keys created in, or used against, this tenant. */
1495
+ readonly credentials?: CredentialPolicy;
1496
+ };
1497
+ /**
1498
+ * Per-tenant settings, a subject input like `RoleSource`: they tighten what
1499
+ * a key may be and never grant. A throw denies.
1500
+ */
1501
+ type SettingsSource = {
1502
+ settingsFor(tenant: string): TenantSettings | undefined | Promise<TenantSettings | undefined>;
1503
+ };
1504
+ declare function memorySettings(settings: Readonly<Record<string, TenantSettings>>): SettingsSource;
1505
+ declare function memoryRoleSource(customRoles: readonly CustomRole[]): RoleSource;
1506
+ //#endregion
1507
+ //#region src/conditions/normalize.d.ts
1508
+ type FieldOperator = {
1509
+ readonly eq?: unknown;
1510
+ readonly ne?: unknown;
1511
+ readonly gt?: unknown;
1512
+ readonly gte?: unknown;
1513
+ readonly lt?: unknown;
1514
+ readonly lte?: unknown;
1515
+ readonly contains?: unknown;
1516
+ readonly in?: unknown;
1517
+ readonly notIn?: unknown;
1518
+ readonly isNull?: boolean;
1519
+ };
1520
+ type WhereShorthand<T = Record<string, unknown>> = {
1521
+ readonly and?: readonly WhereShorthand<T>[];
1522
+ readonly or?: readonly WhereShorthand<T>[];
1523
+ readonly not?: WhereShorthand<T>;
1524
+ } & { readonly [K in keyof T]?: T[K] | FieldOperator | {
1525
+ readonly ref: string;
1526
+ }; };
1527
+ //#endregion
1528
+ //#region src/core/approvers.d.ts
1529
+ /** One named approver, by principal id. */
1530
+ type UserApprover = {
1531
+ readonly kind: "user";
1532
+ readonly id: string;
1533
+ };
1534
+ /**
1535
+ * Who may approve: a subject-only grantee, a `relation()` the approver holds
1536
+ * on the requested row (checked when the verdict is given), or `user(id)`.
1537
+ * A list matches an approver who satisfies every item.
1538
+ */
1539
+ type Approver = Grantee | UserApprover;
1540
+ type ApproverInput = GranteeInput | UserApprover | readonly ApproverInput[];
1541
+ /** A named approver for `approval.by`, matched on the approver's principal id. */
1542
+ declare function user(id: string): UserApprover;
1543
+ //#endregion
1544
+ //#region src/core/policy.d.ts
1545
+ type ClosureContext = {
1546
+ readonly subject: {
1547
+ readonly principal: Principal | null;
1548
+ readonly actor?: unknown;
1549
+ readonly delegation?: unknown;
1550
+ readonly context: Readonly<Record<string, unknown>>;
1551
+ };
1552
+ readonly actor?: unknown;
1553
+ readonly delegation?: unknown;
1554
+ readonly context: Readonly<Record<string, unknown>>;
1555
+ };
1556
+ type ClosureGrantFn<T = unknown> = (data: T, ctx: ClosureContext) => boolean;
1557
+ /** Who else may approve once a request has waited `after`. */
1558
+ type ApprovalEscalation = {
1559
+ /** A duration (`'4h'`) from the request's creation. */
1560
+ readonly after: string;
1561
+ readonly to: Approver | readonly Approver[];
1562
+ };
1563
+ /** One group of approvers; `quorum` distinct approvers of `by` complete it. */
1564
+ type ApprovalStage = {
1565
+ readonly by: Approver | readonly Approver[];
1566
+ /** Absent means 1. */
1567
+ readonly quorum?: number;
1568
+ };
1569
+ /**
1570
+ * `'any'`: `quorum` approvers from `by`. `'all'`: every stage completes, in
1571
+ * any order. `'sequential'`: stages complete in order; an approver signs
1572
+ * only the first incomplete stage. An approver signs once per request.
1573
+ */
1574
+ type ApprovalMode = "any" | "all" | "sequential";
1575
+ type ApprovalRequirement = {
1576
+ /** Set when `mode` is `'any'` (the default); absent under `stages`. */
1577
+ readonly by?: Approver | readonly Approver[];
1578
+ /** Absent means `'any'`. */
1579
+ readonly mode?: ApprovalMode;
1580
+ /** Set when `mode` is `'all'` or `'sequential'`. */
1581
+ readonly stages?: readonly ApprovalStage[];
1582
+ /** `false` lets the request's principal approve it; absent means `true`. */
1583
+ readonly distinct?: boolean;
1584
+ /** `'resource-change'` binds the approval to the row's `version` field. */
1585
+ readonly staleOn?: "resource-change";
1586
+ /** Distinct approvers a request needs before it is approved under `by`; absent means 1. */
1587
+ readonly quorum?: number;
1588
+ /** How long a request stays open (`'30m'`); the store's default when absent, and never longer than it. */
1589
+ readonly ttl?: string;
1590
+ readonly escalation?: ApprovalEscalation;
1591
+ };
1592
+ type ApprovalOption = "human" | {
1593
+ readonly by?: ApproverInput;
1594
+ /** `'all'` or `'sequential'` with `stages`; absent means `'any'` with `by`. */
1595
+ readonly mode?: ApprovalMode;
1596
+ readonly stages?: readonly {
1597
+ readonly by: ApproverInput;
1598
+ readonly quorum?: number;
1599
+ }[];
1600
+ /** `false` lets the request's principal approve it; absent means `true`. */
1601
+ readonly distinct?: boolean;
1602
+ /**
1603
+ * `'resource-change'`: the approval covers the row as it was when it was
1604
+ * requested. The resource must declare `version`; once that field
1605
+ * changes, resuming denies with `stale-approval`.
1606
+ */
1607
+ readonly staleOn?: "resource-change";
1608
+ /** Distinct approvers needed (an integer of at least 1); the same approver counts once. Absent means 1. */
1609
+ readonly quorum?: number;
1610
+ /** How long the request stays open (`'30m'`, `'2d'`); caps the approval store's default. */
1611
+ readonly ttl?: string;
1612
+ /** After `after` (`'4h'`), `to` may approve as well as `by`, at any open stage; same kinds as `by`. */
1613
+ readonly escalation?: {
1614
+ readonly after: string;
1615
+ readonly to: ApproverInput;
1616
+ };
1617
+ };
1618
+ /**
1619
+ * A quota on a grant. `hard` (the default) denies past `count`; `soft` grants
1620
+ * with an `over-limit` obligation. `alertAt` (a fraction of `count`, above 0
1621
+ * and at most 1) adds a `near-limit` obligation once usage reaches it.
1622
+ */
1623
+ type GrantLimit = {
1624
+ readonly count: number;
1625
+ readonly per: string;
1626
+ readonly mode?: "hard" | "soft";
1627
+ readonly alertAt?: number;
1628
+ };
1629
+ /** How fresh the subject's authentication must be for an elevated grant. */
1630
+ type AssuranceRequirement = {
1631
+ /** Seconds since the subject last authenticated (`assurance.authTime`). */
1632
+ readonly maxAge?: number;
1633
+ /** Authentication context class references, any of which satisfies it. */
1634
+ readonly acr?: readonly string[];
1635
+ /** Authentication methods, all of which must be present. */
1636
+ readonly amr?: readonly string[];
1637
+ };
1638
+ /**
1639
+ * Time-boxed role activation. A role with `activation` is never held
1640
+ * directly: a membership lists it under `eligible`, and `permdock.activate`
1641
+ * mints the elevated membership to write.
1642
+ */
1643
+ type ActivationOption = {
1644
+ /** The longest an activation may last, as a duration (`'4h'`, `'30m'`). */
1645
+ readonly maxDuration?: string;
1646
+ /** `'required'` denies an activation without a reason. */
1647
+ readonly justification?: "required" | "optional";
1648
+ /** When set, `activate` returns `approval-required` before the membership can be written. */
1649
+ readonly approval?: ApprovalOption;
1650
+ /** How fresh the activator's authentication must be. */
1651
+ readonly assurance?: AssuranceRequirement;
1652
+ };
1653
+ type ActivationSpec = {
1654
+ readonly maxDuration?: string;
1655
+ readonly justification: "required" | "optional";
1656
+ readonly approval?: "human" | ApprovalRequirement;
1657
+ readonly assurance?: AssuranceRequirement;
1658
+ };
1659
+ /** What a break-glass grant demands before it overrides a deny. */
1660
+ type BreakGlassRequirements = {
1661
+ /** Purposes of use (`context.purpose`), any of which engages break-glass. */
1662
+ readonly purpose?: readonly string[];
1663
+ /** `true` denies unless the caller supplies `context.reason`. */
1664
+ readonly reason?: boolean;
1665
+ readonly assurance?: AssuranceRequirement;
1666
+ };
1667
+ type BreakGlassOptions = {
1668
+ /** Names of the deny grants this override lifts; every other deny still wins. */
1669
+ readonly overrides?: readonly string[];
1670
+ readonly requires?: BreakGlassRequirements;
1671
+ /** The longest a break-glass session may last, as a duration. */
1672
+ readonly maxDuration?: string;
1673
+ /** Follow-ups the grant owes: each becomes an obligation on the decision. */
1674
+ readonly obligations?: readonly ("notify" | "review")[];
1675
+ };
1676
+ /** The normalized break-glass spec carried on a grant. */
1677
+ type BreakGlassSpec = {
1678
+ readonly overrides: readonly string[];
1679
+ readonly purpose?: readonly string[];
1680
+ readonly reason: boolean;
1681
+ readonly assurance?: AssuranceRequirement;
1682
+ readonly maxDuration?: string;
1683
+ readonly obligations: readonly ("notify" | "review")[];
1684
+ };
1685
+ /** How a tenant consents to support access, and for how long. */
1686
+ type SupportConsent = {
1687
+ readonly by: GranteeInput;
1688
+ /** The durations a tenant owner may pick, as duration strings. */
1689
+ readonly durations: readonly string[];
1690
+ };
1691
+ type SupportAccessOptions<S extends string = string> = {
1692
+ /** The role a consented support membership holds. */
1693
+ readonly role: string;
1694
+ /** The scope the support membership sits in; defaults to `tenant`. */
1695
+ readonly on?: S;
1696
+ /** Every decision under the support membership denies with `actor-required` without an `act`. */
1697
+ readonly actorRequired?: boolean;
1698
+ readonly consent: SupportConsent;
1699
+ /** Permissions a support session never reaches, compiled to deny grants scoped to `via: 'support'`. */
1700
+ readonly forbid?: readonly (Permission | PermissionTree)[];
1701
+ /** The subgroup a consented membership records under `member.group`. */
1702
+ readonly group?: string;
1703
+ };
1704
+ type SupportSpec = {
1705
+ readonly role: string;
1706
+ readonly actorRequired: boolean;
1707
+ readonly consent: {
1708
+ readonly by: Grantee | readonly Grantee[];
1709
+ readonly durations: readonly string[];
1710
+ };
1711
+ readonly group: string;
1712
+ };
1713
+ type GrantOptions<T = Record<string, unknown>> = {
1714
+ readonly to?: GranteeInput;
1715
+ readonly where?: WhereShorthand<T> | Condition;
1716
+ readonly check?: WhereShorthand<T> | Condition;
1717
+ readonly approval?: ApprovalOption;
1718
+ readonly limit?: GrantLimit;
1719
+ readonly reason?: string;
1720
+ readonly fields?: readonly (keyof T & string)[];
1721
+ /** A name a `breakGlass` override may lift; only meaningful on a deny. */
1722
+ readonly name?: string;
1723
+ /** Purposes of use (`context.purpose`) that make the grant apply; non-portable. */
1724
+ readonly purpose?: readonly string[];
1725
+ /** The grant applies from this instant on (RFC 3339 string or Unix seconds); before it an allow denies with `inactive-grant` and a deny does not apply. */
1726
+ readonly validFrom?: string | number;
1727
+ /** The grant stops applying at this instant (exclusive; RFC 3339 string or Unix seconds). */
1728
+ readonly validUntil?: string | number;
1729
+ };
1730
+ /**
1731
+ * When a grant applies, in Unix seconds. `from` is inclusive, `until`
1732
+ * exclusive; either may be absent. Portable: `where()` drops an inactive
1733
+ * grant at the decision clock and generated RLS compares against `now()`.
1734
+ */
1735
+ type GrantValidity = {
1736
+ readonly from?: number;
1737
+ readonly until?: number;
1738
+ };
1739
+ /** The actor a policy delegation is for: an actor kind, narrowed to one id when `id` is set. */
1740
+ type DelegationTarget = {
1741
+ readonly kind: string;
1742
+ readonly id?: string;
1743
+ };
1744
+ /**
1745
+ * A normalised policy delegation: holders of `from` let actors matching `to`
1746
+ * use `permissions` (keys) on their behalf while `validity` holds, without a
1747
+ * token saying so. Attenuation only: the principal's grants still decide.
1748
+ */
1749
+ type PolicyDelegation = {
1750
+ readonly from: Grantee | readonly Grantee[];
1751
+ readonly to: DelegationTarget;
1752
+ readonly permissions: readonly string[];
1753
+ /** The keys of `permissions` whose `readOnlyHint` is true: all a `readOnly` actor may use. */
1754
+ readonly readOnly: readonly string[];
1755
+ readonly validity?: GrantValidity;
1756
+ };
1757
+ type DelegationInput = {
1758
+ /** Who hands over: the same subject-only selectors as `approval.by` (a role, `authenticated()`, a plan, `assurance()`); not `relation()`. */
1759
+ readonly from: GranteeInput;
1760
+ /** Which actor may act: `actor('eve')`, an actor kind, or `{ kind, id }` for one agent. */
1761
+ readonly to: ActorGrantee | string | DelegationTarget;
1762
+ /** The leaves or subtrees the actor may use; a deny grant still applies. */
1763
+ readonly permissions: readonly (Permission | PermissionTree)[];
1764
+ readonly validFrom?: string | number;
1765
+ readonly validUntil?: string | number;
1766
+ };
1767
+ /** A declared scope name (or the `tenant` / `team` alias), or the resource a role is held on. */
1768
+ type RoleScope<S extends string = string> = S | Permission | PermissionTree | readonly (Permission | PermissionTree)[];
1769
+ type RoleOptions<S extends string = string> = {
1770
+ readonly on?: RoleScope<S>;
1771
+ readonly assignable?: boolean;
1772
+ /** Roles nobody may hold together with this one in the same scope instance. */
1773
+ readonly exclusiveWith?: readonly string[];
1774
+ /** Fewest holders a scope instance keeps (checked at commit); default 0. Needs a named-scope `on`. */
1775
+ readonly min?: number;
1776
+ /** Most holders a scope instance may have. Needs a named-scope `on`. */
1777
+ readonly max?: number;
1778
+ /** The holder count of a scope instance never changes: the role only moves by transfer. */
1779
+ readonly transferOnly?: boolean;
1780
+ /**
1781
+ * Roles a holder may assign and revoke. Once any role declares `assigns`,
1782
+ * a role nobody lists is assigned only by `meta.manageRoles` holders.
1783
+ */
1784
+ readonly assigns?: readonly string[];
1785
+ /** Membership kinds (`via`) that may hold the role; others hold it for nothing. */
1786
+ readonly for?: readonly string[];
1787
+ readonly meta?: RoleMeta;
1788
+ /** Time-boxed activation: the role becomes eligible-only and `activate` mints its membership. */
1789
+ readonly activation?: ActivationOption;
1790
+ /** Reserved for restricted credentials; setting it throws until it ships. */
1791
+ readonly restricted?: never;
1792
+ };
1793
+ /** Where a grant applies: `'global'`, a declared scope name, or one resource. */
1794
+ type GrantScope = string | {
1795
+ readonly resource: string;
1796
+ };
1797
+ type Grant = {
1798
+ readonly permission: Permission;
1799
+ readonly effect: "allow" | "deny";
1800
+ readonly to: Grantee | readonly Grantee[];
1801
+ readonly role: string | null;
1802
+ readonly where?: Condition;
1803
+ readonly check?: Condition;
1804
+ readonly approval?: "human" | ApprovalRequirement;
1805
+ readonly portable: boolean;
1806
+ /** Set when `portable` is false only because the grant reads the relation graph. */
1807
+ readonly graph?: true;
1808
+ readonly closure?: ClosureGrantFn;
1809
+ readonly limit?: GrantLimit;
1810
+ readonly fields?: readonly string[];
1811
+ readonly scope: GrantScope;
1812
+ /** A name a `breakGlass` override may lift; only meaningful on a deny. */
1813
+ readonly name?: string;
1814
+ /** Purposes of use that make the grant apply (`context.purpose`); non-portable. */
1815
+ readonly purpose?: readonly string[];
1816
+ /** Set on a break-glass allow: it overrides named denies and carries obligations. */
1817
+ readonly breakGlass?: BreakGlassSpec;
1818
+ /** The membership kind (`via`) this grant applies under; others never match it. */
1819
+ readonly viaOnly?: string;
1820
+ /** Set only on a grant merged from a hosted policy document. */
1821
+ readonly hosted?: HostedGrantRef;
1822
+ /** When the grant applies; absent means always. */
1823
+ readonly validity?: GrantValidity;
1824
+ };
1825
+ /** Which hosted policy document and grant a merged grant came from. */
1826
+ type HostedGrantRef = {
1827
+ readonly document: string;
1828
+ readonly grant: string;
1829
+ };
1830
+ type RoleBinding<S extends string = string> = {
1831
+ readonly name: string;
1832
+ readonly grants: readonly Grant[];
1833
+ readonly on?: RoleScope<S>;
1834
+ readonly assignable: boolean;
1835
+ readonly exclusiveWith?: readonly string[];
1836
+ readonly min?: number;
1837
+ readonly max?: number;
1838
+ readonly transferOnly?: boolean;
1839
+ readonly assigns?: readonly string[];
1840
+ readonly for?: readonly string[];
1841
+ readonly meta?: RoleMeta;
1842
+ /** Time-boxed activation: the role is eligible-only, and `activate` mints its membership. */
1843
+ readonly activation?: ActivationSpec;
1844
+ /** Support access: consent and `actorRequired` for a vendor-support membership. */
1845
+ readonly support?: SupportSpec;
1846
+ };
1847
+ type ValidateMode = "boundary" | "always" | "never";
1848
+ /** The declared scopes, in declaration order; empty when the policy declares none. */
1849
+ type PolicyScopes = readonly Scope[];
1850
+ type PolicyVocabulary = {
1851
+ readonly permissions: PermissionTree;
1852
+ readonly roles?: RoleTree;
1853
+ readonly plans?: PlanTree;
1854
+ };
1855
+ type VocabularyFromInput<Input> = Input extends PolicyVocabulary ? Input : {
1856
+ readonly permissions: Input & PermissionTree;
1857
+ readonly roles?: RoleTree;
1858
+ readonly plans?: PlanTree;
1859
+ };
1860
+ type Policy<TUser = unknown, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary> = {
1861
+ readonly permissions: V["permissions"];
1862
+ readonly roles: readonly RoleBinding[];
1863
+ readonly rolesByName: ReadonlyMap<string, RoleBinding>;
1864
+ readonly grants: readonly Grant[];
1865
+ readonly vocabulary: V;
1866
+ readonly scopes: PolicyScopes;
1867
+ principal(user: TUser): TPrincipal | null;
1868
+ subject(user: TUser): TPrincipal | null;
1869
+ context?(user: TUser): Readonly<Record<string, unknown>> | Promise<Readonly<Record<string, unknown>>>;
1870
+ readonly validate: ValidateMode;
1871
+ readonly onDenied?: (decision: unknown) => never | void;
1872
+ readonly fingerprint: string;
1873
+ readonly resources: ReadonlyMap<string, ResourceNode>;
1874
+ readonly providers?: readonly DecisionProvider[];
1875
+ /** Permission keys a hosted policy document may grant or deny; empty by default. */
1876
+ readonly hostable: readonly string[];
1877
+ /** Permission keys that deny with `stale-credentials` when the subject's token is behind the source. */
1878
+ readonly fresh?: readonly string[];
1879
+ /** Policy delegations in declaration order; absent or empty when the policy declares none. */
1880
+ readonly delegations?: readonly PolicyDelegation[];
1881
+ readonly index: PolicyIndex;
1882
+ };
1883
+ /** Lookups built once per policy, so a decision does not rescan every role and grant. */
1884
+ type PolicyIndex = {
1885
+ readonly declaredRoles: ReadonlySet<string>;
1886
+ readonly supports: readonly SupportSpec[];
1887
+ /** The grants `grantList` returns, by permission key, in the same order. */
1888
+ readonly grantsByKey: ReadonlyMap<string, readonly Grant[]>;
1889
+ };
1890
+ declare function normalizeApproval(approval: ApprovalOption | undefined, permission?: string): Grant["approval"];
1891
+ type GrantCondition<T, K extends PermissionKind> = K extends "collection" ? Omit<GrantOptions<T>, "where" | "fields"> | ClosureGrantFn<T> : GrantOptions<T> | ClosureGrantFn<T>;
1892
+ declare function allow<T, K extends PermissionKind = PermissionKind>(permission: Permission<string, T, K> | readonly Permission<string, T, K>[], condition?: GrantCondition<T, K>): Omit<Grant, "role" | "scope"> | Omit<Grant, "role" | "scope">[];
1893
+ declare function deny<T, K extends PermissionKind = PermissionKind>(permission: Permission<string, T, K> | readonly Permission<string, T, K>[], condition?: GrantCondition<T, K>): Omit<Grant, "role" | "scope"> | Omit<Grant, "role" | "scope">[];
1894
+ type RoleGrants = readonly (Omit<Grant, "role" | "scope"> | readonly Omit<Grant, "role" | "scope">[])[];
1895
+ /** A role held at a named scope: `on` is checked against `definePolicy({ scopes })`. */
1896
+ declare function role<const S extends string>(name: string | Role, grants: RoleGrants, options: RoleOptions<S> & {
1897
+ readonly on: S;
1898
+ }): RoleBinding<S>;
1899
+ /** A global role, or one held on a resource. */
1900
+ declare function role(name: string | Role, grants: RoleGrants, options?: RoleOptions<never>): RoleBinding<never>;
1901
+ /** Options built at runtime: the scope name is only checked by `definePolicy`. */
1902
+ declare function role(name: string | Role, grants: RoleGrants, options?: RoleOptions): RoleBinding;
1903
+ declare function normalizeAssurance(input: AssuranceRequirement | undefined): AssuranceRequirement | undefined;
1904
+ type DefinePolicyOptions<TUser, TPrincipal extends Principal, S extends PolicyScopesInput = PolicyScopesInput> = {
1905
+ readonly roles?: readonly RoleBinding<ScopeNames<S>>[];
1906
+ readonly grants?: readonly (Omit<Grant, "role" | "scope"> | readonly Omit<Grant, "role" | "scope">[] | Grant)[];
1907
+ /**
1908
+ * Named scopes in order, each with the row field holding its id and an
1909
+ * optional parent (`within`, an earlier scope). `tenant` and `team` alias
1910
+ * the first and second scope.
1911
+ */
1912
+ readonly scopes?: S;
1913
+ readonly principal?: (user: TUser) => TPrincipal | null;
1914
+ readonly subject?: (user: TUser) => TPrincipal | null;
1915
+ readonly context?: (user: TUser) => Readonly<Record<string, unknown>> | Promise<Readonly<Record<string, unknown>>>;
1916
+ readonly validate?: ValidateMode;
1917
+ readonly onDenied?: (decision: unknown) => never | void;
1918
+ readonly providers?: readonly DecisionProvider[];
1919
+ /**
1920
+ * Leaves or subtrees a hosted policy document (`PolicySource`) may touch.
1921
+ * The default is none, so a policy without it ignores every hosted grant.
1922
+ */
1923
+ readonly hostable?: readonly (Permission | PermissionTree)[];
1924
+ /**
1925
+ * Sensitive permissions that need an up-to-date token: when the subject's
1926
+ * memberships come from a token behind the `MembershipSource` version, they
1927
+ * deny with `stale-credentials`.
1928
+ */
1929
+ readonly fresh?: readonly (Permission | PermissionTree)[];
1930
+ /**
1931
+ * Standing delegations: holders of `from` let actors matching `to` use
1932
+ * `permissions` for them without a token saying so. A token delegation on
1933
+ * the call still applies as well; both must cover.
1934
+ */
1935
+ readonly delegations?: readonly DelegationInput[];
1936
+ };
1937
+ declare function definePolicy<TUser, TPrincipal extends Principal, const Input extends PermissionTree | PolicyVocabulary, const S extends PolicyScopesInput = PolicyScopesInput>(permissions: Input, options: DefinePolicyOptions<TUser, TPrincipal, S>): Policy<TUser, TPrincipal, VocabularyFromInput<Input>>;
1938
+ type MembershipFixture = {
1939
+ readonly principal?: string;
1940
+ readonly tenant?: string;
1941
+ readonly roles: readonly string[];
1942
+ };
1943
+ type SeparationConflict = {
1944
+ readonly principal: string;
1945
+ readonly tenant?: string;
1946
+ readonly roles: readonly [string, string];
1947
+ };
1948
+ declare function separationConflicts(policy: Policy, memberships: readonly MembershipFixture[]): readonly SeparationConflict[];
1949
+ type PrincipalOf<P> = P extends Policy<unknown, infer TPrincipal> ? TPrincipal : Principal;
1950
+ type SubjectOf<P> = {
1951
+ readonly principal: PrincipalOf<P> | null;
1952
+ readonly actor?: Actor;
1953
+ readonly delegation?: Delegation;
1954
+ readonly context: Readonly<Record<string, unknown>>;
1955
+ readonly session?: string;
1956
+ readonly expiresAt?: number;
1957
+ };
1958
+ //#endregion
1959
+ export { DecisionSink as $, relation as $n, RowPair as $t, RoleScope as A, memoryApprovalPolicies as An, isConditionRef as Ar, memoryEntitlementSource as At, normalizeAssurance as B, Obligation as Bn, CredentialPolicy as Bt, Policy as C, ArazzoPlan as Cn, RelatedCondition as Cr, TenantSettings as Ct, PrincipalOf as D, simulateArazzo as Dn, hasConditionOp as Dr, VerificationFailure as Dt, PolicyVocabulary as E, arazzoFindings as En, SqlFunctionCondition as Er, TokenVerifier as Et, ValidateMode as F, DeniedDecision as Fn, Credential as Ft, UserApprover as G, Grantee as Gn, credentialDelegation as Gt, separationConflicts as H, Trace as Hn, CredentialPrincipal as Ht, allow as I, ExplainedDecision as In, CredentialDecision as It, AuthEvent as J, actor as Jn, decideCredential as Jt, user as K, GranteeInput as Kn, credentialPolicyViolation as Kt, definePolicy as L, GrantedDecision as Ln, CredentialKind as Lt, SubjectOf as M, Decision as Mn, memorySettings as Mt, SupportAccessOptions as N, Denial as Nn, WireDecision as Nt, RoleBinding as O, ApprovalPolicy as On, isCondition as Or, VerifiedToken as Ot, SupportConsent as P, DenialReason as Pn, WireDenial as Pt, DecisionProvider as Q, plan as Qn, PermDockOptions as Qt, deny as R, LimitDetail as Rn, CredentialPermission as Rt, MembershipFixture as S, ArazzoFinding as Sn, OpaqueCondition as Sr, SubjectResolver as St, PolicyScopes as T, ArazzoStepResult as Tn, SqlFunctionArg as Tr, TokenSigner as Tt, Approver as U, TraceSkip as Un, CredentialRequest as Ut, role as V, Quota as Vn, CredentialPolicyViolation as Vt, ApproverInput as W, TraceSkipReason as Wn, DecideCredentialOptions as Wt, CredentialVerifier as X, assurance as Xn, DecideOptions as Xt, CredentialEvent as Y, anyone as Yn, parseCredential as Yt, DecisionEvent as Z, authenticated as Zn, PermDock as Zt, GrantLimit as _, RoleChangeOptions as _n, Condition as _r, SnapshotAssignable as _t, ApprovalRequirement as a, HostedGrantDropped as an, Assurance as ar, LimitStore as at, GrantValidity as b, breakGlass as bn, MemberOfCondition as br, SnapshotScope as bt, BreakGlassOptions as c, isPortableCondition as cn, CustomRole as cr, MembershipSource as ct, ClosureContext as d, parsePolicyDocument as dn, GnapAccess as dr, RelationHolder as dt, SimulateOptions as en, PolicyScopesInput as er, DirectoryEvent as et, ClosureGrantFn as f, Holder as fn, JsonWebKeyLike as fr, RelationSource as ft, GrantCondition as g, RoleChangeDecision as gn, VerifiedClaims as gr, Snapshot as gt, Grant as h, RoleChange as hn, Subject as hr, SinkEvent as ht, ApprovalOption as i, HostedGrantDropReason as in, Actor as ir, LimitRemaining as it, SeparationConflict as j, ApprovalRequiredDecision as jn, isSqlFunctionField as jr, memoryRoleSource as jt, RoleOptions as k, ApprovalPolicySource as kn, isConditionDate as kr, WhereCompiler as kt, BreakGlassRequirements as l, memoryPolicySource as ln, CustomRoleGrant as lr, RelationChain as lt, DelegationTarget as m, WhoCan as mn, Principal as mr, SettingsSource as mt, ApprovalEscalation as n, createPermDock as nn, ScopeDeclaration as nr, JwtClaims as nt, ApprovalStage as o, PolicyDocument as on, AuthorizationDetail as or, MemberEntry as ot, DelegationInput as p, HoldingVia as pn, Membership as pr, RoleSource as pt, AccessEvent as q, RelationGrantee as qn, credentialSubject as qt, ApprovalMode as r, HostedGrant as rn, ScopeNames as rr, LimitConsumeInput as rt, AssuranceRequirement as s, PolicySource as sn, Binding as sr, MembershipEvent as st, ActivationOption as t, WhereResult as tn, Scope as tr, EntitlementSource as tt, BreakGlassSpec as u, mergeHostedGrants as un, Delegation as ur, RelationGroup as ut, GrantOptions as v, RoleChangeTarget as vn, ConditionRef as vr, SnapshotGrant as vt, PolicyDelegation as w, ArazzoSimulateInput as wn, RelatedHop as wr, TokenFailureCause as wt, HostedGrantRef as x, supportAccess as xn, MemberOfParent as xr, SnapshotSource as xt, GrantScope as y, ActivateInput as yn, ConditionValue as yr, SnapshotNotEntitled as yt, normalizeApproval as z, MatchedGrant as zn, CredentialPermissionInput as zt };