permdock 0.2.0 → 0.3.1

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 (192) hide show
  1. package/dist/a2a/index.d.ts +4 -4
  2. package/dist/a2a/index.js +2 -2
  3. package/dist/ai-sdk/index.d.ts +3 -3
  4. package/dist/ai-sdk/index.js +1 -1
  5. package/dist/approvals/index.d.ts +2 -2
  6. package/dist/{arazzo-cmvX2jDe.js → arazzo-C9chp3ST.js} +1 -1
  7. package/dist/authzen/index.d.ts +3 -3
  8. package/dist/authzen/index.js +1 -1
  9. package/dist/better-auth/index.d.ts +1 -1
  10. package/dist/better-supabase/index.d.ts +27 -10
  11. package/dist/better-supabase/index.js +44 -16
  12. package/dist/{bind-CVy3Espv.d.ts → bind-C_ob3LKa.d.ts} +5 -5
  13. package/dist/{bind-VnYn2HKq.js → bind-CuzGytRf.js} +1 -1
  14. package/dist/{capability-Dq43tT1u.d.ts → capability-2kYTMWDv.d.ts} +1 -1
  15. package/dist/catalog-CRW5Mx_B.js +2 -0
  16. package/dist/{catalog-h2tlKFkq.js → catalog-CYj-mX2O.js} +2 -2
  17. package/dist/{catalog-z8q6bi_r.js → catalog-DWF5cYqB.js} +2 -2
  18. package/dist/{catalog-doc-Dsc9y7sd.js → catalog-doc-DdGm82XT.js} +3 -26
  19. package/dist/claude-agent/index.d.ts +3 -3
  20. package/dist/claude-agent/index.js +1 -1
  21. package/dist/clerk/index.d.ts +2 -2
  22. package/dist/cli/bin.js +1 -1
  23. package/dist/cli/index.d.ts +1 -1
  24. package/dist/cli/index.js +1 -1
  25. package/dist/cloud/index.d.ts +4 -4
  26. package/dist/{cloud-BGhHS-lY.js → cloud-CfwZ39Rl.js} +2 -2
  27. package/dist/{cloud-Bo3e9Ak3.js → cloud-DWLXO2af.js} +3 -3
  28. package/dist/{collect-DLlujdHC.js → collect-CHB22Sx4.js} +3 -3
  29. package/dist/{collect-DDDv_ESs.js → collect-DSTE3ml9.js} +1 -1
  30. package/dist/collect-DSWOk19R.js +2 -0
  31. package/dist/{commands-DWOrSQic.js → commands-BeaGNj_o.js} +13 -13
  32. package/dist/compile/index.d.ts +1 -1
  33. package/dist/{compile-CNnl6uIt.d.ts → compile-BkRyBDBw.d.ts} +1 -1
  34. package/dist/{config-Bn00Z3ks.js → config-ir40y8m0.js} +2 -2
  35. package/dist/{config-report-Dw_JcUqT.js → config-report-CdCgbRnV.js} +4 -4
  36. package/dist/{context-Ttp0ekMT.js → context-Bcy85rGi.js} +2 -2
  37. package/dist/convex/index.d.ts +3 -3
  38. package/dist/convex/index.js +1 -1
  39. package/dist/{create-BWyx3jua.d.ts → create-B1d519XK.d.ts} +5 -5
  40. package/dist/{create-CPhDL6qx.js → create-CMwIl-w2.js} +1 -1
  41. package/dist/{describe-PdoqESvg.d.ts → describe-DMYiCjJV.d.ts} +1 -1
  42. package/dist/{diff-B8Tunc3o.js → diff-2VaeChzX.js} +3 -3
  43. package/dist/{diff-CzqLxZ77.js → diff-C9RDjjhs.js} +2 -2
  44. package/dist/{doctor-rOr-4ZfS.js → doctor-Djh6JDEk.js} +2 -2
  45. package/dist/{doctor-WpvG6p4k.js → doctor-DvH0IQff.js} +10 -10
  46. package/dist/{doctor-collect-ByfYlNv1.js → doctor-collect-CjdO0wQX.js} +10 -9
  47. package/dist/drizzle/index.d.ts +2 -2
  48. package/dist/elysia/index.d.ts +3 -3
  49. package/dist/elysia/index.js +1 -1
  50. package/dist/{errors-DAqevpNk.d.ts → errors-DPdqI50v.d.ts} +2 -2
  51. package/dist/eve/index.d.ts +3 -3
  52. package/dist/eve/index.js +1 -1
  53. package/dist/express/index.d.ts +3 -3
  54. package/dist/express/index.js +1 -1
  55. package/dist/fastify/index.d.ts +3 -3
  56. package/dist/fastify/index.js +1 -1
  57. package/dist/{from-snapshot-C3sHpZNS.js → from-snapshot-CTLijvdm.js} +1 -0
  58. package/dist/hono/index.d.ts +3 -3
  59. package/dist/hono/index.js +1 -1
  60. package/dist/{index-CtE07CBF.d.ts → index-0nNqHspG.d.ts} +2 -2
  61. package/dist/{index-D3vbkoSI.d.ts → index-BNc7Wer_.d.ts} +1 -1
  62. package/dist/{index-D6_cSa1z.d.ts → index-C7Tw7MaW.d.ts} +2 -2
  63. package/dist/{index-A0YNL8jZ.d.ts → index-C8z4RjQV.d.ts} +1 -1
  64. package/dist/index.d.ts +10 -10
  65. package/dist/index.js +3 -3
  66. package/dist/{instance-options-BK_rNOSC.d.ts → instance-options-jARdwfPN.d.ts} +1 -1
  67. package/dist/jwt/index.d.ts +4 -4
  68. package/dist/{kernel-GSQnMz3O.js → kernel-_RRHmnMY.js} +1 -1
  69. package/dist/kysely/index.d.ts +2 -2
  70. package/dist/mcp/index.d.ts +6 -6
  71. package/dist/mcp/index.js +2 -2
  72. package/dist/nest/index.d.ts +3 -3
  73. package/dist/nest/index.js +1 -1
  74. package/dist/next/index.d.ts +5 -5
  75. package/dist/next/index.js +1 -1
  76. package/dist/next/plugin.d.ts +1 -1
  77. package/dist/next/plugin.js +1 -1
  78. package/dist/node/index.d.ts +3 -3
  79. package/dist/node/index.js +1 -1
  80. package/dist/openai/index.d.ts +3 -3
  81. package/dist/openai/index.js +1 -1
  82. package/dist/openapi/index.d.ts +2 -2
  83. package/dist/{openapi-Bbg4wGVL.js → openapi-CQTsgKoB.js} +1 -1
  84. package/dist/orpc/index.d.ts +4 -4
  85. package/dist/orpc/index.js +2 -2
  86. package/dist/otel/index.d.ts +2 -2
  87. package/dist/{parse-local-manifest-BkGQNzAh.d.ts → parse-local-manifest-JLnaBH0S.d.ts} +1 -1
  88. package/dist/pdp/index.d.ts +2 -2
  89. package/dist/pdp/index.js +1 -1
  90. package/dist/{permdock-CzqXjCpU.js → permdock-CbgvLnuo.js} +35 -27
  91. package/dist/{permissions-CpZrivYv.js → permissions-RJrovw98.js} +1 -1
  92. package/dist/{policy-D8UFyERw.d.ts → policy-D2W7uv19.d.ts} +1 -1
  93. package/dist/{policy-CFZAr_Al.d.ts → policy-IB6yxpC3.d.ts} +21 -5
  94. package/dist/powersync-CrBX8hY6.js +2 -0
  95. package/dist/{powersync-yW1UUFzp.js → powersync-DE19b9dT.js} +2 -2
  96. package/dist/{powersync-C7kLglqX.js → powersync-Dv1_aWF7.js} +7 -7
  97. package/dist/prisma/index.d.ts +1 -1
  98. package/dist/{problem-details-CkL50EEf.d.ts → problem-details-DX075l9V.d.ts} +1 -1
  99. package/dist/{protected-CNsMzrVd.d.ts → protected-BdnIEFkY.d.ts} +3 -3
  100. package/dist/{protected-Cs6kTaHo.js → protected-utU-SLuy.js} +1 -1
  101. package/dist/{protected-bZs6rbT1.d.ts → protected-xAr24FEC.d.ts} +3 -3
  102. package/dist/{provider-DLzpb2Xz.js → provider-CSQd7m92.js} +2 -2
  103. package/dist/{provider-Cjr62YMV.d.ts → provider-DZY281jO.d.ts} +1 -1
  104. package/dist/{provider-store-DNyC1y48.js → provider-store-Cfbvo4DE.js} +2 -2
  105. package/dist/react/index.d.ts +6 -6
  106. package/dist/react/index.js +2 -2
  107. package/dist/react/provider-client.d.ts +1 -1
  108. package/dist/react/provider-client.js +1 -1
  109. package/dist/react-native/index.d.ts +8 -8
  110. package/dist/react-native/index.js +3 -3
  111. package/dist/{replay-sqBGMnNs.d.ts → replay-CYyiLiwO.d.ts} +1 -1
  112. package/dist/{rls-BMNydpHk.js → rls-DiinlRML.js} +12 -12
  113. package/dist/{rls-CEvs64Kj.js → rls-P-BeBx0n.js} +2 -2
  114. package/dist/{rls-fields-BMasREhR.js → rls-fields-CZOMlwHl.js} +96 -8
  115. package/dist/{rls-graph-pc9fuXYm.js → rls-graph-CHwx0V8q.js} +2 -2
  116. package/dist/{rls-import-D8F7j35Q.js → rls-import-4lLW_pbb.js} +2 -2
  117. package/dist/{rls-migrate-7wikfrVI.js → rls-migrate-CN4TlJTO.js} +2 -2
  118. package/dist/{rls-ownership-B5Lkq62W.js → rls-ownership-DcYlZ09B.js} +3 -3
  119. package/dist/{rls-shared-aOQ4hGTO.js → rls-shared-Cewd_-zI.js} +4 -2
  120. package/dist/{rls-verify-D8B7dOTh.js → rls-verify-CMv9H3wV.js} +8 -7
  121. package/dist/row-conditions-h2HythXQ.js +27 -0
  122. package/dist/{rpc-DOK54_CS.js → rpc-DL9Sqvb1.js} +1 -1
  123. package/dist/{run-YXCJDNYk.js → run-BWc9qqvE.js} +1 -1
  124. package/dist/{saas-Bj_FFkjN.js → saas-DhpJjnBA.js} +2 -2
  125. package/dist/scim/index.d.ts +1 -1
  126. package/dist/server/index.d.ts +6 -6
  127. package/dist/server/index.js +1 -1
  128. package/dist/{sink-Gs6TTVa-.d.ts → sink-B1fZzIMf.d.ts} +1 -1
  129. package/dist/{skills-JaymNCdK.js → skills-C5CbhhpG.js} +1 -1
  130. package/dist/{snapshot-cache-DwQH8ufx.d.ts → snapshot-cache-B-LxUahj.d.ts} +1 -1
  131. package/dist/solid/index.d.ts +4 -4
  132. package/dist/solid/index.js +2 -2
  133. package/dist/{sources-B0UvrJ21.js → sources-4p0-4xQm.js} +12 -1
  134. package/dist/{sources-BcJgw0lt.d.ts → sources-BdOYLw9j.d.ts} +2 -2
  135. package/dist/{src-CSbUiozF.js → src-BDwEZWrZ.js} +1 -1
  136. package/dist/ssf/index.d.ts +3 -3
  137. package/dist/{store-D_pjn91-.d.ts → store-jOBYpiXC.d.ts} +2 -2
  138. package/dist/{store-options-yO0V6gRn.js → store-options-ByhZq1jV.js} +1 -1
  139. package/dist/{stores-4_sqiOA1.js → stores-BT2pSCub.js} +1 -1
  140. package/dist/{stores-DVR5NHLE.d.ts → stores-C0IMQrGI.d.ts} +2 -2
  141. package/dist/{stream-DlvG2hs-.d.ts → stream-D1RXubw2.d.ts} +1 -1
  142. package/dist/supabase/index.d.ts +15 -4
  143. package/dist/supabase/index.js +2 -2
  144. package/dist/supabase/middleware.d.ts +4 -4
  145. package/dist/supabase/middleware.js +2 -2
  146. package/dist/{supabase-DTBaC20O.js → supabase-C0qESOa-.js} +7 -5
  147. package/dist/{supabase-config-Bs44dare.js → supabase-config-Bj3iDH2I.js} +1 -1
  148. package/dist/supabase-hook-gd3s8bxB.js +2 -0
  149. package/dist/{supabase-hook-BuxLQLpU.js → supabase-hook-ntETYCQu.js} +56 -10
  150. package/dist/{supabase-CwafwxxF.js → supabase-s4o9s1O1.js} +2 -2
  151. package/dist/{supautils-DYZnzRWV.js → supautils-u8jXTGrt.js} +1 -1
  152. package/dist/svelte/index.d.ts +5 -5
  153. package/dist/svelte/index.js +2 -2
  154. package/dist/svelte/runtime.d.ts +2 -2
  155. package/dist/svelte/runtime.js +1 -1
  156. package/dist/svelte/source.d.ts +5 -5
  157. package/dist/svelte/source.js +1 -1
  158. package/dist/terminal/index.d.ts +4 -4
  159. package/dist/terminal/index.js +1 -1
  160. package/dist/testing/index.d.ts +5 -5
  161. package/dist/testing/index.js +5 -5
  162. package/dist/testing/saas/index.d.ts +2 -2
  163. package/dist/testing/saas/index.js +2 -2
  164. package/dist/testing/saas/permissions.js +1 -1
  165. package/dist/trpc/index.d.ts +4 -4
  166. package/dist/trpc/index.js +2 -2
  167. package/dist/{types-C3s9xVJG.d.ts → types-BnIEz1sU.d.ts} +1 -1
  168. package/dist/{types-yF5LmQVD.d.ts → types-C97IskBw.d.ts} +1 -1
  169. package/dist/{types-kxznc7cn.d.ts → types-CKNSyIf_.d.ts} +1 -1
  170. package/dist/{types-9AWO9EGt.d.ts → types-Cq_H8N_X.d.ts} +2 -2
  171. package/dist/{types-BPxgszlT.d.ts → types-DbjRN55U.d.ts} +15 -2
  172. package/dist/{types-BVyImy5I.d.ts → types-DxiCGmmd.d.ts} +1 -1
  173. package/dist/{types-vNSDF7Dq.d.ts → types-QCuYJh4q.d.ts} +1 -1
  174. package/dist/{types-vKyAMtcX.d.ts → types-aqOHTHcp.d.ts} +1 -1
  175. package/dist/unplugin/index.d.ts +1 -1
  176. package/dist/unplugin/index.js +1 -1
  177. package/dist/{usage-D07N9QJ3.js → usage-B0YuTQRO.js} +2 -2
  178. package/dist/usage-DorAJiU_.js +2 -0
  179. package/dist/{usage-DG1oeCca.js → usage-ItS7nLcl.js} +2 -2
  180. package/dist/{validation-error-CtF23SrC.d.ts → validation-error-Ba264OaJ.d.ts} +1 -1
  181. package/dist/vue/index.d.ts +4 -4
  182. package/dist/vue/index.js +2 -2
  183. package/dist/watch-BwxLTYMZ.js +2 -0
  184. package/dist/{watch-UihESpsJ.js → watch-DVBJ9cBq.js} +1 -1
  185. package/dist/webmcp/index.d.ts +1 -1
  186. package/package.json +3 -3
  187. package/dist/catalog-BjZSovXQ.js +0 -2
  188. package/dist/collect-rG2IQ3t0.js +0 -2
  189. package/dist/powersync-A8x_Yyvh.js +0 -2
  190. package/dist/supabase-hook-D5qVd_D8.js +0 -2
  191. package/dist/usage-D82l1CwK.js +0 -2
  192. package/dist/watch-Etoa_Mvr.js +0 -2
@@ -1,4 +1,4 @@
1
- import { i as globalArgs, s as stringArg, t as COMMAND_DESCRIPTIONS } from "./commands-DWOrSQic.js";
1
+ import { i as globalArgs, s as stringArg, t as COMMAND_DESCRIPTIONS } from "./commands-BeaGNj_o.js";
2
2
  import { defineCommand } from "citty";
3
3
  //#region src/cli/commands/rls.ts
4
4
  function rls(ctx) {
@@ -189,7 +189,7 @@ function rls(ctx) {
189
189
  }
190
190
  },
191
191
  async run({ args: parsed }) {
192
- const result = await (await import("./rls-BMNydpHk.js")).runRls({
192
+ const result = await (await import("./rls-DiinlRML.js")).runRls({
193
193
  cwd: ctx.cwd,
194
194
  config: ctx.config,
195
195
  rest: parsed._,
@@ -7,15 +7,15 @@ import { E as listRoles, l as inheritCondition, m as relationCondition } from ".
7
7
  import { t as canonicalJson } from "./canonical-json-DemiK4Vp.js";
8
8
  import { d as partitionsOf, h as scopeField } from "./validity-uOp8UpYn.js";
9
9
  import { t as requiresApproval } from "./approval-required-TzNB9oQA.js";
10
- import { _ as leveled, p as andWhere } from "./permdock-CzqXjCpU.js";
10
+ import { _ as leveled, p as andWhere } from "./permdock-CbgvLnuo.js";
11
11
  import { i as requiresStandIn } from "./delegation-D8pUEuce.js";
12
12
  import { t as CliError } from "./errors-CWfoNg9N.js";
13
- import { o as jsonSchemaOf } from "./catalog-doc-Dsc9y7sd.js";
13
+ import { o as jsonSchemaOf } from "./catalog-doc-DdGm82XT.js";
14
14
  import { i as scopeMembershipTable, o as relatedSql, r as scopeColumn } from "./compile-Ba4blROR.js";
15
15
  import { t as SQL_IDENT } from "./sql-xdg5f4Fi.js";
16
- import { c as roleManifest, s as roleColumn } from "./sources-B0UvrJ21.js";
16
+ import { l as roleColumn, u as roleManifest } from "./sources-4p0-4xQm.js";
17
17
  import { n as requirePeer } from "./peer-BOr_kJE1.js";
18
- import { $ as sqlType, A as keyTenantSql, C as graphHelper, D as inheritedRowsHelper, E as hasMemberFor, F as memberForSources, G as quoteLiteral, H as permittedIdsHelper, J as roleKindSql, K as quoteTable, L as memberIdsHelper, M as linkHelper, N as liveSessionSql, O as isRecord, P as memberForHelper, R as memberRoleOf, S as grantPermissionSql, T as graphSqlText, U as qualifiedTable, V as permittedForHelper, W as quoteIdent, X as scopeTable, Y as scopeSources, Z as scopeTypeOf, _ as arrayColumnsOf, a as qualified$1, at as userIdHelperSql, b as disabledKeep, c as textArray, et as subjectClaimJsonSql, g as activeUserSql, i as helperSchema, it as tenantTypeOf, j as kindFilterSql, k as keptRowSql, l as CLAIM, m as activeMembershipSql, n as HELPERS, nt as subjectIdSql, o as rootName, p as activeInstancesSql, q as restrictedHelper, r as allowEntry, rt as tenantClaimSql, s as signedIn, t as CUSTOM_ROLES, tt as subjectClaimSql, u as CLOSURE, x as globalKindFilterSql, y as columnTypesOf, z as memberVia } from "./rls-shared-aOQ4hGTO.js";
18
+ import { A as keptRowSql, B as memberVia, C as grantPermissionSql, D as hasMemberFor, E as graphSqlText, F as memberForHelper, G as quoteIdent, H as permittedForHelper, I as memberForSources, J as restrictedHelper, K as quoteLiteral, M as kindFilterSql, N as linkHelper, O as inheritedRowsHelper, P as liveSessionSql, Q as scopeTypeOf, R as memberIdsHelper, S as globalKindFilterSql, U as permittedIdsHelper, W as qualifiedTable, X as scopeSources, Y as roleKindSql, Z as scopeTable, _ as activeUserSql, a as helperSchema, at as tenantTypeOf, b as columnTypesOf, c as signedIn, d as CLOSURE, et as sqlType, h as activeMembershipSql, i as allowEntry, it as tenantClaimSql, j as keyTenantSql, k as isRecord, l as textArray, m as activeInstancesSql, n as GLOBAL_ROLES, nt as subjectClaimSql, o as qualified$1, ot as userIdHelperSql, q as quoteTable, r as HELPERS, rt as subjectIdSql, s as rootName, t as CUSTOM_ROLES, tt as subjectClaimJsonSql, u as CLAIM, v as arrayColumnsOf, w as graphHelper, x as disabledKeep, z as memberRoleOf } from "./rls-shared-Cewd_-zI.js";
19
19
  import { createHash } from "node:crypto";
20
20
  //#region src/cli/rls-api-keys.ts
21
21
  const API_KEY_ALLOWS = "permdock_api_key_allows";
@@ -610,8 +610,12 @@ function roleNames(policy) {
610
610
  function qualify(name, schema) {
611
611
  return name.includes(".") ? name : `${schema}.${name}`;
612
612
  }
613
+ function throughTenant(through, roles) {
614
+ if (through === void 0 || roles?.tenant === void 0) return;
615
+ return qualify(roles.table, "public") === through.table ? roles.tenant : void 0;
616
+ }
613
617
  /** Resolves `source` against `schema`, aliasing the table `alias` and the roles table `<alias>k`. */
614
- function globalRoleSource(source, schema, alias) {
618
+ function globalRoleSource(source, schema, alias, roles) {
615
619
  const table = qualify(source.table, schema);
616
620
  const user = source.user ?? "user_id";
617
621
  const role = roleColumn(source.role ?? "role", table, alias, {
@@ -619,14 +623,17 @@ function globalRoleSource(source, schema, alias) {
619
623
  prefix: "PermDock CLI",
620
624
  indent: " "
621
625
  });
626
+ const tenant = role.lateral ? void 0 : throughTenant(role.through, roles);
627
+ const global = tenant === void 0 ? "" : ` and ${alias}k.${quoteIdent(tenant)} is null`;
622
628
  return {
623
629
  table,
624
630
  user,
625
- from: `${quoteTable(table)} ${alias}${role.join}`,
631
+ from: `${quoteTable(table)} ${alias}${role.join}${global}`,
626
632
  userSql: `${alias}.${quoteIdent(user)}`,
627
633
  roleSql: role.sql,
628
634
  role: roleManifest(role),
629
- ...role.through === void 0 ? {} : { through: role.through }
635
+ ...role.through === void 0 ? {} : { through: role.through },
636
+ ...tenant === void 0 ? {} : { tenant }
630
637
  };
631
638
  }
632
639
  //#endregion
@@ -1472,6 +1479,85 @@ create trigger "permdock_custom_role_cascade"
1472
1479
  `;
1473
1480
  }
1474
1481
  //#endregion
1482
+ //#region src/cli/rls-global-roles.ts
1483
+ function qualifiedName(name) {
1484
+ return name.includes(".") ? name : `public.${name}`;
1485
+ }
1486
+ /**
1487
+ * `permdock_replace_global_roles(p_user, p_roles)`: sets the global roles of
1488
+ * one user in `rls.roles` in one statement pair. It runs as the invoker, so
1489
+ * the table's policies and the `rls.assignments` trigger judge every row it
1490
+ * deletes or inserts.
1491
+ */
1492
+ function globalRolesSql(ctx) {
1493
+ if (ctx.roles === void 0) return "";
1494
+ const source = globalRoleSource(ctx.roles, "public", "t", ctx.customRoles?.table);
1495
+ const table = quoteTable(qualifiedName(ctx.roles.table));
1496
+ const user = quoteIdent(source.user);
1497
+ const fn = qualified$1(ctx, GLOBAL_ROLES.replace);
1498
+ const type = ctx.dialect === "supabase" ? "uuid" : "text";
1499
+ const wanted = `select distinct r from unnest(coalesce(p_roles, '{}'::text[])) r where r is not null`;
1500
+ const through = source.through;
1501
+ let body;
1502
+ if (through === void 0) {
1503
+ const role = typeof ctx.roles.role === "string" ? ctx.roles.role : "role";
1504
+ const column = quoteIdent(role);
1505
+ body = ` delete from ${table} t
1506
+ where t.${user} = p_user
1507
+ and t.${column}::text <> all(coalesce(p_roles, '{}'::text[]));
1508
+ insert into ${table} (${user}, ${column})
1509
+ select p_user, w.r
1510
+ from (${wanted}) w(r)
1511
+ where not exists (
1512
+ select 1 from ${table} t where t.${user} = p_user and t.${column}::text = w.r
1513
+ );`;
1514
+ } else {
1515
+ const keys = quoteTable(through.table);
1516
+ const id = quoteIdent(through.id);
1517
+ const key = quoteIdent(through.key);
1518
+ const ref = quoteIdent(through.ref);
1519
+ const global = source.tenant === void 0 ? "" : ` and k.${quoteIdent(source.tenant)} is null`;
1520
+ body = ` select string_agg(w.r, ', ' order by w.r) into v_unknown
1521
+ from (${wanted}) w(r)
1522
+ where not exists (select 1 from ${keys} k where k.${key}::text = w.r${global});
1523
+ if v_unknown is not null then
1524
+ raise exception using
1525
+ errcode = '22023',
1526
+ message = 'permdock: ' || v_unknown || ' is not a role',
1527
+ hint = 'unknown-role';
1528
+ end if;
1529
+ delete from ${table} t
1530
+ where t.${user} = p_user
1531
+ and not exists (
1532
+ select 1 from ${keys} k
1533
+ where k.${id} = t.${ref}
1534
+ and k.${key}::text = any(coalesce(p_roles, '{}'::text[]))${global}
1535
+ );
1536
+ insert into ${table} (${user}, ${ref})
1537
+ select p_user, k.${id}
1538
+ from ${keys} k
1539
+ where k.${key}::text in (${wanted})${global}
1540
+ and not exists (
1541
+ select 1 from ${table} t where t.${user} = p_user and t.${ref} = k.${id}
1542
+ );`;
1543
+ }
1544
+ const declare = through === void 0 ? "" : "declare\n v_unknown text;\n";
1545
+ const args = `${type}, text[]`;
1546
+ return `-- set the global roles of a user: delete the others and insert the missing ones, as the caller, so the table's policies and the assignment trigger still apply
1547
+ create or replace function ${fn}(p_user ${type}, p_roles text[])
1548
+ returns void
1549
+ language plpgsql
1550
+ volatile
1551
+ set search_path = ''
1552
+ as $$
1553
+ ${declare}begin
1554
+ ${body}
1555
+ end;
1556
+ $$;
1557
+ revoke execute on function ${fn}(${args}) from public, anon;
1558
+ grant execute on function ${fn}(${args}) to authenticated;`;
1559
+ }
1560
+ //#endregion
1475
1561
  //#region src/cli/rls-helpers.ts
1476
1562
  /** The helper `--capabilities` adds: ids of one resource a link capability claim reaches. Part of the SQL contract. */
1477
1563
  const CAPABILITIES = { ids: "permdock_capability_ids" };
@@ -1616,7 +1702,7 @@ function globalRoleRows(ctx) {
1616
1702
  from: `${qualified$1(ctx, "user_roles")} ur`,
1617
1703
  userSql: "ur.user_id",
1618
1704
  roleSql: "ur.role::text"
1619
- } : globalRoleSource(ctx.roles, "public", "ur");
1705
+ } : globalRoleSource(ctx.roles, "public", "ur", ctx.customRoles?.table);
1620
1706
  }
1621
1707
  function customKeysJoin(ctx, scope, allows, denies, includes) {
1622
1708
  return ` cross join lateral ${qualified$1(ctx, CUSTOM_ROLES.keys)}(
@@ -2183,6 +2269,8 @@ revoke all on table ${ur} from anon, authenticated, public;`);
2183
2269
  const cascade = customRoleCascadeSql(ctx);
2184
2270
  if (cascade !== "") chunks.push(cascade);
2185
2271
  }
2272
+ const globalRoles = globalRolesSql(ctx);
2273
+ if (globalRoles !== "") chunks.push(globalRoles);
2186
2274
  const readers = roleReadersSql(ctx, options.permissions, options.trustedReaders);
2187
2275
  if (readers !== "") chunks.push(readers);
2188
2276
  return `${chunks.join("\n\n")}\n`;
@@ -2,8 +2,8 @@ import { S as restrictedFor, d as isEdgeRelation, f as isFieldRelation, g as isS
2
2
  import { d as scopeList } from "./scopes-CVdPrWN-.js";
3
3
  import { l as inheritCondition, m as relationCondition, s as flattenGrantee } from "./grantee-Cv5Sogfv.js";
4
4
  import { c as relationArmSql, u as restrictedRowsSql } from "./compile-Ba4blROR.js";
5
- import "./sources-B0UvrJ21.js";
6
- import { C as graphHelper, G as quoteLiteral, K as quoteTable, M as linkHelper, T as graphSqlText, U as qualifiedTable, W as quoteIdent, g as activeUserSql, n as HELPERS, q as restrictedHelper, u as CLOSURE, w as graphSqlName } from "./rls-shared-aOQ4hGTO.js";
5
+ import "./sources-4p0-4xQm.js";
6
+ import { E as graphSqlText, G as quoteIdent, J as restrictedHelper, K as quoteLiteral, N as linkHelper, T as graphSqlName, W as qualifiedTable, _ as activeUserSql, d as CLOSURE, q as quoteTable, r as HELPERS, w as graphHelper } from "./rls-shared-Cewd_-zI.js";
7
7
  //#region src/cli/helper-calls.ts
8
8
  /**
9
9
  * Tables whose policies other packages write by calling the SQL helpers
@@ -1,7 +1,7 @@
1
1
  import { o as usageResult } from "./errors-CWfoNg9N.js";
2
2
  import { i as quoteSqlLiteral, n as escapeSqlIdent } from "./sql-xdg5f4Fi.js";
3
- import { B as parseMembershipsFlag, n as HELPERS } from "./rls-shared-aOQ4hGTO.js";
4
- import { t as FIELD_VIEWS, w as connectPg } from "./rls-fields-BMasREhR.js";
3
+ import { V as parseMembershipsFlag, r as HELPERS } from "./rls-shared-Cewd_-zI.js";
4
+ import { t as FIELD_VIEWS, w as connectPg } from "./rls-fields-CZOMlwHl.js";
5
5
  import { n as emptySchema, r as isSchemaKind, t as emitPermissionsModule } from "./generate-CH7ThJ14.js";
6
6
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
7
7
  import { dirname, resolve } from "node:path";
@@ -1,8 +1,8 @@
1
1
  import { i as describeError } from "./errors-CWfoNg9N.js";
2
2
  import { a as sqlFiles } from "./files-DWUN9PzI.js";
3
3
  import { i as quoteSqlLiteral, n as escapeSqlIdent } from "./sql-xdg5f4Fi.js";
4
- import "./sources-B0UvrJ21.js";
5
- import { n as HELPERS } from "./rls-shared-aOQ4hGTO.js";
4
+ import "./sources-4p0-4xQm.js";
5
+ import { r as HELPERS } from "./rls-shared-Cewd_-zI.js";
6
6
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
7
7
  import { relative, resolve } from "node:path";
8
8
  import { parse } from "pgsql-parser";
@@ -1,8 +1,8 @@
1
1
  import { l as scopeChain, o as resolveScope } from "./scopes-CVdPrWN-.js";
2
2
  import { S as findRole } from "./grantee-Cv5Sogfv.js";
3
- import { s as roleColumn } from "./sources-B0UvrJ21.js";
4
- import { F as memberForSources, G as quoteLiteral, I as memberForTable, J as roleKindSql, K as quoteTable, R as memberRoleOf, U as qualifiedTable, W as quoteIdent, X as scopeTable, Y as scopeSources, a as qualified, it as tenantTypeOf, j as kindFilterSql, nt as subjectIdSql, s as signedIn, t as CUSTOM_ROLES, x as globalKindFilterSql, z as memberVia } from "./rls-shared-aOQ4hGTO.js";
5
- import { D as claimKeptLines, I as sourceFilters, L as sourcesKeep, M as membershipRows, N as membershipTable, O as disabledColumn, P as roleRows, R as hasCustomRoleChecksFor, j as memberColumn, k as globalRoleRows } from "./rls-fields-BMasREhR.js";
3
+ import { l as roleColumn } from "./sources-4p0-4xQm.js";
4
+ import { B as memberVia, G as quoteIdent, I as memberForSources, K as quoteLiteral, L as memberForTable, M as kindFilterSql, S as globalKindFilterSql, W as qualifiedTable, X as scopeSources, Y as roleKindSql, Z as scopeTable, at as tenantTypeOf, c as signedIn, o as qualified, q as quoteTable, rt as subjectIdSql, t as CUSTOM_ROLES, z as memberRoleOf } from "./rls-shared-Cewd_-zI.js";
5
+ import { D as claimKeptLines, I as sourceFilters, L as sourcesKeep, M as membershipRows, N as membershipTable, O as disabledColumn, P as roleRows, R as hasCustomRoleChecksFor, j as memberColumn, k as globalRoleRows } from "./rls-fields-CZOMlwHl.js";
6
6
  //#region src/cli/rls-ownership.ts
7
7
  /** Objects the ownership rules add next to the helpers. Names are part of the SQL contract. */
8
8
  const OWNERSHIP = {
@@ -3,7 +3,7 @@ import { c as rootScope, l as scopeChain, o as resolveScope } from "./scopes-CVd
3
3
  import { t as byCodePoint } from "./compare-pfyVnBjE.js";
4
4
  import { i as scopeMembershipTable, r as scopeColumn } from "./compile-Ba4blROR.js";
5
5
  import { a as quoteSqlTable, i as quoteSqlLiteral, r as quoteSqlIdent, t as SQL_IDENT } from "./sql-xdg5f4Fi.js";
6
- import { l as keptKeys, s as roleColumn } from "./sources-B0UvrJ21.js";
6
+ import { d as keptKeys, l as roleColumn } from "./sources-4p0-4xQm.js";
7
7
  //#region src/cli/rls-sql.ts
8
8
  const CLI = "PermDock CLI";
9
9
  const CLAIM = SQL_IDENT;
@@ -469,6 +469,8 @@ const CUSTOM_ROLES = {
469
469
  trustedRemove: "permdock_trusted_delete_custom_role_grants",
470
470
  cascade: "permdock_cascade_custom_role"
471
471
  };
472
+ /** The function `rls.roles` adds. The name is part of the SQL contract. */
473
+ const GLOBAL_ROLES = { replace: "permdock_replace_global_roles" };
472
474
  function helperSchema(ctx) {
473
475
  return ctx.schema ?? "permdock";
474
476
  }
@@ -490,4 +492,4 @@ function textArray(values) {
490
492
  return values.length === 0 ? `'{}'::text[]` : `array[${values.map(quoteLiteral).join(", ")}]::text[]`;
491
493
  }
492
494
  //#endregion
493
- export { sqlType as $, keyTenantSql as A, parseMembershipsFlag as B, graphHelper as C, inheritedRowsHelper as D, hasMemberFor as E, memberForSources as F, quoteLiteral as G, permittedIdsHelper as H, memberForTable as I, roleKindSql as J, quoteTable as K, memberIdsHelper as L, linkHelper as M, liveSessionSql as N, isRecord as O, memberForHelper as P, sessionLiveHelperSql as Q, memberRoleOf as R, grantPermissionSql as S, graphSqlText as T, qualifiedTable as U, permittedForHelper as V, quoteIdent as W, scopeTable as X, scopeSources as Y, scopeTypeOf as Z, arrayColumnsOf as _, qualified as a, userIdHelperSql as at, disabledKeep as b, textArray as c, SESSION_LIVE_HELPER as d, subjectClaimJsonSql as et, USER_ID_HELPER as f, activeUserSql as g, activeRowSql as h, helperSchema as i, tenantTypeOf as it, kindFilterSql as j, keptRowSql as k, CLAIM as l, activeMembershipSql as m, HELPERS as n, subjectIdSql as nt, rootName as o, activeInstancesSql as p, restrictedHelper as q, allowEntry as r, tenantClaimSql as rt, signedIn as s, CUSTOM_ROLES as t, subjectClaimSql as tt, CLOSURE as u, checkSuspension as v, graphSqlName as w, globalKindFilterSql as x, columnTypesOf as y, memberVia as z };
495
+ export { sessionLiveHelperSql as $, keptRowSql as A, memberVia as B, grantPermissionSql as C, hasMemberFor as D, graphSqlText as E, memberForHelper as F, quoteIdent as G, permittedForHelper as H, memberForSources as I, restrictedHelper as J, quoteLiteral as K, memberForTable as L, kindFilterSql as M, linkHelper as N, inheritedRowsHelper as O, liveSessionSql as P, scopeTypeOf as Q, memberIdsHelper as R, globalKindFilterSql as S, graphSqlName as T, permittedIdsHelper as U, parseMembershipsFlag as V, qualifiedTable as W, scopeSources as X, roleKindSql as Y, scopeTable as Z, activeUserSql as _, helperSchema as a, tenantTypeOf as at, columnTypesOf as b, signedIn as c, CLOSURE as d, sqlType as et, SESSION_LIVE_HELPER as f, activeRowSql as g, activeMembershipSql as h, allowEntry as i, tenantClaimSql as it, keyTenantSql as j, isRecord as k, textArray as l, activeInstancesSql as m, GLOBAL_ROLES as n, subjectClaimSql as nt, qualified as o, userIdHelperSql as ot, USER_ID_HELPER as p, quoteTable as q, HELPERS as r, subjectIdSql as rt, rootName as s, CUSTOM_ROLES as t, subjectClaimJsonSql as tt, CLAIM as u, arrayColumnsOf as v, graphHelper as w, disabledKeep as x, checkSuspension as y, memberRoleOf as z };
@@ -1,17 +1,18 @@
1
1
  import { _ as listPermissions, d as isEdgeRelation, f as isFieldRelation, i as findPermission, m as isPrincipalRelation } from "./permissions-DVoF6dMt.js";
2
2
  import { a as hasConditionOp } from "./refs-KYb4ntaz.js";
3
- import { _ as memoryRoleSource } from "./src-CSbUiozF.js";
3
+ import { _ as memoryRoleSource } from "./src-BDwEZWrZ.js";
4
4
  import { d as scopeList } from "./scopes-CVdPrWN-.js";
5
- import { g as customRoleScope, t as createPermDock, v as membershipsClaim } from "./permdock-CzqXjCpU.js";
5
+ import { g as customRoleScope, t as createPermDock, v as membershipsClaim } from "./permdock-CbgvLnuo.js";
6
6
  import { t as memoryRelations } from "./relations-cjOL01hZ.js";
7
7
  import { i as describeError, o as usageResult } from "./errors-CWfoNg9N.js";
8
- import { o as jsonSchemaOf, s as policyRowConditionKeys } from "./catalog-doc-Dsc9y7sd.js";
8
+ import { t as policyRowConditionKeys } from "./row-conditions-h2HythXQ.js";
9
+ import { o as jsonSchemaOf } from "./catalog-doc-DdGm82XT.js";
9
10
  import { a as loadModule, n as asPolicy, o as pickNamed } from "./load-DhWEB9P1.js";
10
11
  import "./budget-NbEtbJC_.js";
11
- import "./sources-B0UvrJ21.js";
12
- import { G as quoteLiteral, K as quoteTable, W as quoteIdent, y as columnTypesOf } from "./rls-shared-aOQ4hGTO.js";
13
- import { p as commandFor, s as viewName, t as FIELD_VIEWS, w as connectPg } from "./rls-fields-BMasREhR.js";
14
- import { a as HELPER_TABLE_POLICIES_SQL, d as rowConditionMessage, n as graphPlan, u as helperTablePoliciesFromRows } from "./rls-graph-pc9fuXYm.js";
12
+ import "./sources-4p0-4xQm.js";
13
+ import { G as quoteIdent, K as quoteLiteral, b as columnTypesOf, q as quoteTable } from "./rls-shared-Cewd_-zI.js";
14
+ import { p as commandFor, s as viewName, t as FIELD_VIEWS, w as connectPg } from "./rls-fields-CZOMlwHl.js";
15
+ import { a as HELPER_TABLE_POLICIES_SQL, d as rowConditionMessage, n as graphPlan, u as helperTablePoliciesFromRows } from "./rls-graph-CHwx0V8q.js";
15
16
  import { n as fixtureSubject, r as loadFixtures, t as fixtureRow } from "./fixtures-ht28Cplr.js";
16
17
  import { resolve } from "node:path";
17
18
  import { randomUUID } from "node:crypto";
@@ -0,0 +1,27 @@
1
+ //#region src/core/row-conditions.ts
2
+ const ROW_GRANTEES = /* @__PURE__ */ new Set([
3
+ "relation",
4
+ "plan",
5
+ "actor",
6
+ "assurance",
7
+ "inherit"
8
+ ]);
9
+ /**
10
+ * Whether a grant depends on more than the role and the scope: a row or body
11
+ * condition, a closure, a field list, a purpose, a break-glass override, a
12
+ * validity window, a `requires`, or a relation, plan, actor or assurance grantee. The SQL helpers
13
+ * (`permdock_has`, `permitted_<scope>_ids`) check only role and scope, so a
14
+ * policy that calls them for such a permission would widen access.
15
+ */
16
+ function grantHasRowConditions(grant) {
17
+ const grantees = Array.isArray(grant.to) ? grant.to : [grant.to];
18
+ return grant.where !== void 0 || grant.check !== void 0 || grant.closure !== void 0 || !grant.portable || grant.fields !== void 0 || grant.purpose !== void 0 || grant.breakGlass !== void 0 || grant.validity !== void 0 || grant.requires !== void 0 || grantees.some((grantee) => ROW_GRANTEES.has(grantee.kind));
19
+ }
20
+ /** Per permission key, whether any code grant for it has row conditions. */
21
+ function policyRowConditionKeys(policy) {
22
+ const keys = /* @__PURE__ */ new Set();
23
+ for (const grant of [...policy.grants, ...policy.roles.flatMap((binding) => binding.grants)]) if (grant.hosted === void 0 && grantHasRowConditions(grant)) keys.add(grant.permission.key);
24
+ return keys;
25
+ }
26
+ //#endregion
27
+ export { policyRowConditionKeys as t };
@@ -1,7 +1,7 @@
1
1
  import { t as compact } from "./compact-y6vfu2_f.js";
2
2
  import { o as requestFromContext } from "./http-SO7qGttf.js";
3
3
  import { n as tenantScope } from "./adapter-context-mlWsVGGg.js";
4
- import { t as adapterKernel } from "./bind-VnYn2HKq.js";
4
+ import { t as adapterKernel } from "./bind-CuzGytRf.js";
5
5
  import { n as guardIterable } from "./stream-DDpvynSB.js";
6
6
  //#region src/server/rpc.ts
7
7
  /** The tRPC and oRPC error code for a Problem Details status. */
@@ -1,7 +1,7 @@
1
1
  import { a as exitCodeOf, i as describeError, n as cliErrorKind, r as cliProblem } from "./errors-CWfoNg9N.js";
2
2
  import { o as cliVersion } from "./version-BvacVTZR.js";
3
3
  import { a as resolveCwd, i as readConfig } from "./config-BJiM-xAm.js";
4
- import { i as globalArgs, n as commands, o as resolveArgs, r as isCommand, s as stringArg, t as COMMAND_DESCRIPTIONS } from "./commands-DWOrSQic.js";
4
+ import { i as globalArgs, n as commands, o as resolveArgs, r as isCommand, s as stringArg, t as COMMAND_DESCRIPTIONS } from "./commands-BeaGNj_o.js";
5
5
  import { stripVTControlCharacters } from "node:util";
6
6
  import { defineCommand, parseArgs, renderUsage, runCommand } from "citty";
7
7
  //#region src/cli/run.ts
@@ -1,10 +1,10 @@
1
1
  import { r as principal } from "./refs-KYb4ntaz.js";
2
2
  import { _ as memoryLimitStore, a as definePolicy, m as role, o as deny, t as allow } from "./policy-xyWg7QdR.js";
3
- import { _ as memoryRoleSource } from "./src-CSbUiozF.js";
3
+ import { _ as memoryRoleSource } from "./src-BDwEZWrZ.js";
4
4
  import { n as anyone, p as relation } from "./grantee-Cv5Sogfv.js";
5
5
  import { t as memoryRelations } from "./relations-cjOL01hZ.js";
6
6
  import { i as quoteSqlLiteral } from "./sql-xdg5f4Fi.js";
7
- import { a as saasPlans, i as saasPermissions, o as saasRoles } from "./permissions-CpZrivYv.js";
7
+ import { a as saasPlans, i as saasPermissions, o as saasRoles } from "./permissions-RJrovw98.js";
8
8
  //#region src/testing/saas/policy.ts
9
9
  function isSubject(user) {
10
10
  return user !== null && "context" in user && "principal" in user;
@@ -1,2 +1,2 @@
1
- import { A as ScimPageResult, C as LIST_SCHEMA, D as ScimFilter, E as SCIM_CONTENT_TYPE, M as ScimTokenOptions, N as USER_SCHEMA, O as ScimHandlerOptions, S as GROUP_SCHEMA, T as ROLES_EXTENSION, _ as DirectoryNotFoundError, a as scimHandler, b as DirectoryUser, c as parseScimFilter, d as serviceProviderConfig, f as authenticateScim, g as DirectoryMembershipSourceOptions, h as DirectoryGroup, i as tenantFromPath, j as ScimPatchOp, k as ScimPage, l as resourceTypes, m as DirectoryChange, n as directoryMembershipSource, o as filterSupported, p as sha256Hex, r as normalizePatchOps, s as matchFilter, t as memoryDirectoryStore, u as schemas, v as DirectoryStore, w as PATCH_SCHEMA, x as ERROR_SCHEMA, y as DirectoryUniquenessError } from "../index-A0YNL8jZ.js";
1
+ import { A as ScimPageResult, C as LIST_SCHEMA, D as ScimFilter, E as SCIM_CONTENT_TYPE, M as ScimTokenOptions, N as USER_SCHEMA, O as ScimHandlerOptions, S as GROUP_SCHEMA, T as ROLES_EXTENSION, _ as DirectoryNotFoundError, a as scimHandler, b as DirectoryUser, c as parseScimFilter, d as serviceProviderConfig, f as authenticateScim, g as DirectoryMembershipSourceOptions, h as DirectoryGroup, i as tenantFromPath, j as ScimPatchOp, k as ScimPage, l as resourceTypes, m as DirectoryChange, n as directoryMembershipSource, o as filterSupported, p as sha256Hex, r as normalizePatchOps, s as matchFilter, t as memoryDirectoryStore, u as schemas, v as DirectoryStore, w as PATCH_SCHEMA, x as ERROR_SCHEMA, y as DirectoryUniquenessError } from "../index-C8z4RjQV.js";
2
2
  export { type DirectoryChange, type DirectoryGroup, type DirectoryMembershipSourceOptions, DirectoryNotFoundError, type DirectoryStore, DirectoryUniquenessError, type DirectoryUser, ERROR_SCHEMA, GROUP_SCHEMA, LIST_SCHEMA, PATCH_SCHEMA, ROLES_EXTENSION, SCIM_CONTENT_TYPE, type ScimFilter, type ScimHandlerOptions, type ScimPage, type ScimPageResult, type ScimPatchOp, type ScimTokenOptions, USER_SCHEMA, authenticateScim, directoryMembershipSource, filterSupported, matchFilter, memoryDirectoryStore, normalizePatchOps, parseScimFilter, resourceTypes, schemas, scimHandler, serviceProviderConfig, sha256Hex, tenantFromPath };
@@ -1,11 +1,11 @@
1
- import { $t as CredentialPrincipal, Ct as SettingsSource, Kt as Credential, Nr as Principal, Pr as Subject, Yn as Decision, at as DecisionSink, et as AuthEvent, jt as SubjectResolver, nt as CredentialVerifier } from "../policy-CFZAr_Al.js";
1
+ import { $t as CredentialPrincipal, Ct as SettingsSource, Kt as Credential, Nr as Principal, Pr as Subject, Yn as Decision, at as DecisionSink, et as AuthEvent, jt as SubjectResolver, nt as CredentialVerifier } from "../policy-IB6yxpC3.js";
2
2
  import { f as Permission, m as PermissionTree } from "../permissions-DttnqqxC.js";
3
- import { n as PermDockValidationError, t as PROBLEM_BASE } from "../validation-error-CtF23SrC.js";
4
- import { t as Disclosure } from "../problem-details-CkL50EEf.js";
5
- import { a as ProblemDetails, i as PermDockRevokedError, n as PermDockApprovalRequiredError, r as PermDockDeniedError, t as ApprovalHint } from "../errors-DAqevpNk.js";
3
+ import { n as PermDockValidationError, t as PROBLEM_BASE } from "../validation-error-Ba264OaJ.js";
4
+ import { t as Disclosure } from "../problem-details-DX075l9V.js";
5
+ import { a as ProblemDetails, i as PermDockRevokedError, n as PermDockApprovalRequiredError, r as PermDockDeniedError, t as ApprovalHint } from "../errors-DPdqI50v.js";
6
6
  import { i as memoryRevocationFeed, n as RevocationFeed, t as RevocationEvent } from "../revocations-Cy06JNx2.js";
7
- import { A as ConnectionOptions, C as invalidSignatureResponse, D as tenantScope, E as TenantScope, O as Connection, S as invalidSignatureProblem, T as TenantOption, _ as WebBotAuthKeyLookup, a as ScopeGuard, b as WebBotAuthVerifier, c as ServerPermDock, d as createPermDock, f as createServerKernel, g as WebBotAuthJwk, h as InvalidSignatureError, i as ProtectOptions, k as ConnectionData, l as ServerPermDockOptions, m as DiscoverViaSignatureAgentOptions, n as OpenApiHooks, o as ServerKernel, p as createEvaluationsHandler, r as OperationScopes, s as ServerKernelOptions, t as Guard, u as SnapshotQuery, v as WebBotAuthKeys, w as verifyWebBotAuth, x as discoverViaSignatureAgent, y as WebBotAuthOptions } from "../create-BWyx3jua.js";
8
- import { a as snapshotHeaders, i as cacheLifeFor, n as SnapshotHeaders, o as snapshotTag, r as SnapshotHeadersOptions, t as CacheLifeForOptions } from "../snapshot-cache-DwQH8ufx.js";
7
+ import { A as ConnectionOptions, C as invalidSignatureResponse, D as tenantScope, E as TenantScope, O as Connection, S as invalidSignatureProblem, T as TenantOption, _ as WebBotAuthKeyLookup, a as ScopeGuard, b as WebBotAuthVerifier, c as ServerPermDock, d as createPermDock, f as createServerKernel, g as WebBotAuthJwk, h as InvalidSignatureError, i as ProtectOptions, k as ConnectionData, l as ServerPermDockOptions, m as DiscoverViaSignatureAgentOptions, n as OpenApiHooks, o as ServerKernel, p as createEvaluationsHandler, r as OperationScopes, s as ServerKernelOptions, t as Guard, u as SnapshotQuery, v as WebBotAuthKeys, w as verifyWebBotAuth, x as discoverViaSignatureAgent, y as WebBotAuthOptions } from "../create-B1d519XK.js";
8
+ import { a as snapshotHeaders, i as cacheLifeFor, n as SnapshotHeaders, o as snapshotTag, r as SnapshotHeadersOptions, t as CacheLifeForOptions } from "../snapshot-cache-B-LxUahj.js";
9
9
  //#region src/server/credentials.d.ts
10
10
  /** `on('auth')` causes for an API key that resolves to the anonymous subject. */
11
11
  type ApiKeyFailureCause = "malformed" | "unknown-credential" | "invalid-claims" | "expired" | "credential-policy" | "credential-revoked" | "owner-unavailable";
@@ -5,7 +5,7 @@ import { d as wwwAuthenticate, o as problemFromDecision, s as problemResponse, u
5
5
  import { n as snapshotHeaders, r as snapshotTag, t as cacheLifeFor } from "../snapshot-cache-D6jLelln.js";
6
6
  import { a as invalidSignatureProblem, i as discoverViaSignatureAgent, n as createEvaluationsHandler, o as invalidSignatureResponse, r as InvalidSignatureError, s as verifyWebBotAuth } from "../evaluations-tz6D9A2G.js";
7
7
  import { n as tenantScope } from "../adapter-context-mlWsVGGg.js";
8
- import { n as createServerKernel, t as createPermDock } from "../create-CPhDL6qx.js";
8
+ import { n as createServerKernel, t as createPermDock } from "../create-CMwIl-w2.js";
9
9
  import { a as parseApiKey, i as memoryCredentials, n as generateApiKey, o as subjectFromApiKey, r as hashApiKey, t as apiKeyVerifier } from "../server-DlZ28Oz5.js";
10
10
  import { t as problemFromError } from "../map-error-pgUWNNtG.js";
11
11
  export { InvalidSignatureError, PROBLEM_BASE, PermDockApprovalRequiredError, PermDockDeniedError, PermDockRevokedError, PermDockValidationError, apiKeyVerifier, cacheLifeFor, createEvaluationsHandler, createPermDock, createServerKernel, discoverViaSignatureAgent, generateApiKey, hashApiKey, invalidSignatureProblem, invalidSignatureResponse, memoryCredentials, memoryRevocationFeed, parseApiKey, problemFromDecision, problemFromError, problemResponse, snapshotHeaders, snapshotTag, subjectFromApiKey, tenantScope, validationProblem, verifyWebBotAuth, wwwAuthenticate };
@@ -1,4 +1,4 @@
1
- import { $ as AccessEvent, Kt as Credential, Pt as TokenSigner, at as DecisionSink, ht as MembershipEvent, tt as CredentialEvent, wt as SinkEvent } from "./policy-CFZAr_Al.js";
1
+ import { $ as AccessEvent, Kt as Credential, Pt as TokenSigner, at as DecisionSink, ht as MembershipEvent, tt as CredentialEvent, wt as SinkEvent } from "./policy-IB6yxpC3.js";
2
2
  //#region src/core/sink.d.ts
3
3
  /** The closed list of CloudEvents `type` values PermDock emits. */
4
4
  declare const CLOUD_EVENT_TYPES: {
@@ -1,4 +1,4 @@
1
- import { a as listArg, i as globalArgs, t as COMMAND_DESCRIPTIONS } from "./commands-DWOrSQic.js";
1
+ import { a as listArg, i as globalArgs, t as COMMAND_DESCRIPTIONS } from "./commands-BeaGNj_o.js";
2
2
  import { r as pick, t as CANCELLED } from "./prompt-CXYhLfsS.js";
3
3
  import { n as detectedAgents, r as runSkills, t as SKILL_AGENTS } from "./skills-Biq5uup3.js";
4
4
  import { defineCommand } from "citty";
@@ -1,4 +1,4 @@
1
- import { Tt as Snapshot } from "./policy-CFZAr_Al.js";
1
+ import { Tt as Snapshot } from "./policy-IB6yxpC3.js";
2
2
  //#region src/core/snapshot-cache.d.ts
3
3
  type CacheLifeForOptions = {
4
4
  /** Lower bound in seconds. Next.js includes a private entry in per-link prefetches from 30. */
@@ -1,11 +1,11 @@
1
- import { Ft as TokenVerifier, Mr as Membership, Tt as Snapshot, Yn as Decision } from "../policy-CFZAr_Al.js";
1
+ import { Ft as TokenVerifier, Mr as Membership, Tt as Snapshot, Yn as Decision } from "../policy-IB6yxpC3.js";
2
2
  import { f as Permission } from "../permissions-DttnqqxC.js";
3
3
  import { r as Role } from "../vocabulary-DA8a8zif.js";
4
- import { n as requiredPlans } from "../problem-details-CkL50EEf.js";
5
- import { i as describe } from "../describe-PdoqESvg.js";
4
+ import { n as requiredPlans } from "../problem-details-DX075l9V.js";
5
+ import { i as describe } from "../describe-DMYiCjJV.js";
6
6
  import { t as PermissionBoundaryState } from "../boundary-BmHxVH1J.js";
7
7
  import { t as approvalHeaders } from "../headers-Cf-zWvsO.js";
8
- import { a as FilterResult, c as SubjectView, i as ClientStatus, l as TenantView, n as ApprovalState, o as PermissionSet, r as ClientPermDock, s as PermissionState, t as ApprovalHandle, u as UseRolesOptions } from "../types-kxznc7cn.js";
8
+ import { a as FilterResult, c as SubjectView, i as ClientStatus, l as TenantView, n as ApprovalState, o as PermissionSet, r as ClientPermDock, s as PermissionState, t as ApprovalHandle, u as UseRolesOptions } from "../types-CKNSyIf_.js";
9
9
  import { Accessor, Accessor as Accessor$1, JSX } from "solid-js";
10
10
  //#region src/solid/types.d.ts
11
11
  /** Structural `JSX.Element`: text, a DOM node or a list of children. */
@@ -2,10 +2,10 @@ import { t as compact } from "../compact-y6vfu2_f.js";
2
2
  import { r as requiredPlans } from "../problem-details-_AMOYz-w.js";
3
3
  import { t as describe } from "../describe-B_gVZEVi.js";
4
4
  import { t as approvalHeaders } from "../headers-BZSDieNT.js";
5
- import { i as isPromiseLike } from "../store-options-yO0V6gRn.js";
5
+ import { i as isPromiseLike } from "../store-options-ByhZq1jV.js";
6
6
  import { a as protectedView, c as subjectView, i as permissionSet, l as tenantView, n as filterResult, o as rolesView, r as livePermDock, s as scopedTenant, t as approvalHandle } from "../views-Soe7bGSC.js";
7
7
  import { n as boundaryFallback, t as boundaryDigest } from "../boundary-BM8a_P6E.js";
8
- import { n as switchTenant, t as providerStore } from "../provider-store-DNyC1y48.js";
8
+ import { n as switchTenant, t as providerStore } from "../provider-store-Cfbvo4DE.js";
9
9
  import { ErrorBoundary, createComponent, createComputed, createContext, createMemo, createSignal, getOwner, on, onCleanup, useContext } from "solid-js";
10
10
  //#region src/solid/context.ts
11
11
  const PermDockContext = createContext(void 0);
@@ -518,6 +518,17 @@ const AUTHZ_VERSION_TABLE = "permdock_authz_version";
518
518
  * API's exposed schemas, so the `security definer` functions are not RPCs.
519
519
  */
520
520
  const PERMDOCK_SCHEMA = "permdock";
521
+ /** Where `supabase.hook.api` puts the PostgREST wrappers, and the prefix of their names. */
522
+ const HOOK_API_SCHEMA = "public";
523
+ const HOOK_API_PREFIX = "permdock_";
524
+ /** The wrapper function names of `supabase.hook.api` for `prefix`. */
525
+ function hookApiNames(prefix = HOOK_API_PREFIX) {
526
+ return {
527
+ subjectFor: `${prefix}subject_for`,
528
+ membersOf: `${prefix}members_of`,
529
+ authzVersionFor: `${prefix}authz_version_for`
530
+ };
531
+ }
521
532
  /**
522
533
  * Reads the authorization version `permdock supabase hook generate` keeps in
523
534
  * `<schema>.permdock_authz_version`: pass it to `claimsFirst(sources, { version })`.
@@ -531,4 +542,4 @@ function authzVersion(options) {
531
542
  };
532
543
  }
533
544
  //#endregion
534
- export { fromSupabasePostgres as a, roleManifest as c, fromJunction as i, keptKeys as l, PERMDOCK_SCHEMA as n, fromTable as o, authzVersion as r, roleColumn as s, AUTHZ_VERSION_TABLE as t };
545
+ export { fromJunction as a, hookApiNames as c, keptKeys as d, authzVersion as i, roleColumn as l, HOOK_API_SCHEMA as n, fromSupabasePostgres as o, PERMDOCK_SCHEMA as r, fromTable as s, AUTHZ_VERSION_TABLE as t, roleManifest as u };
@@ -1,5 +1,5 @@
1
- import { gt as MembershipSource } from "./policy-CFZAr_Al.js";
2
- import { n as RoleThrough, y as SupabaseSuspension } from "./types-yF5LmQVD.js";
1
+ import { gt as MembershipSource } from "./policy-IB6yxpC3.js";
2
+ import { n as RoleThrough, y as SupabaseSuspension } from "./types-C97IskBw.js";
3
3
  import { o as SupabaseManifestMembership } from "./manifest-uDS9y5de.js";
4
4
  //#region src/supabase/roles.d.ts
5
5
  /** A roles table a role column references, by `schema.table`. */
@@ -9,7 +9,7 @@ import { t as canonicalJson } from "./canonical-json-DemiK4Vp.js";
9
9
  import { n as sha256, t as bytesToBase64Url } from "./sha256-BO0swRXL.js";
10
10
  import { g as tenantsOf } from "./validity-uOp8UpYn.js";
11
11
  import { n as isThenable } from "./thenable-okc2xDsj.js";
12
- import { a as collectSnapshotGrants, c as rankRoles, l as usesAssigns, m as ceilingGrants, n as resolveSubject, o as snapshotOf, s as snapshotScopes, u as declaredRoleNames$1, y as resolveCustomRole } from "./permdock-CzqXjCpU.js";
12
+ import { a as collectSnapshotGrants, c as rankRoles, l as usesAssigns, m as ceilingGrants, n as resolveSubject, o as snapshotOf, s as snapshotScopes, u as declaredRoleNames$1, y as resolveCustomRole } from "./permdock-CbgvLnuo.js";
13
13
  import { n as LOCAL_CUSTOM_ROLE } from "./parse-local-manifest-BrMozJCo.js";
14
14
  //#region src/conditions/sql-function.ts
15
15
  function sqlFunction(name, options) {
@@ -1,4 +1,4 @@
1
- import { C as SsfPermDock, D as SsfSubjectMapper, E as SsfSubject, S as SsfOnEvent, T as SsfReceiver, _ as SetSubject, b as SsfEventInput, f as CaepEventName, g as ReplayStore, h as PollResult, m as PollOptions, p as PollHandle, v as SsfAuditEvent, w as SsfPermDockOptions, x as SsfEventListener, y as SsfEventHandler } from "../types-9AWO9EGt.js";
2
- import { t as memoryReplayStore } from "../replay-sqBGMnNs.js";
3
- import { t as createPermDock } from "../index-CtE07CBF.js";
1
+ import { C as SsfPermDock, D as SsfSubjectMapper, E as SsfSubject, S as SsfOnEvent, T as SsfReceiver, _ as SetSubject, b as SsfEventInput, f as CaepEventName, g as ReplayStore, h as PollResult, m as PollOptions, p as PollHandle, v as SsfAuditEvent, w as SsfPermDockOptions, x as SsfEventListener, y as SsfEventHandler } from "../types-Cq_H8N_X.js";
2
+ import { t as memoryReplayStore } from "../replay-CYyiLiwO.js";
3
+ import { t as createPermDock } from "../index-0nNqHspG.js";
4
4
  export { type CaepEventName, type PollHandle, type PollOptions, type PollResult, type ReplayStore, type SetSubject, type SsfAuditEvent, type SsfEventHandler, type SsfEventInput, type SsfEventListener, type SsfOnEvent, type SsfPermDock, type SsfPermDockOptions, type SsfReceiver, type SsfSubject, type SsfSubjectMapper, createPermDock, memoryReplayStore };
@@ -1,6 +1,6 @@
1
- import { Tt as Snapshot, Yn as Decision } from "./policy-CFZAr_Al.js";
1
+ import { Tt as Snapshot, Yn as Decision } from "./policy-IB6yxpC3.js";
2
2
  import { f as Permission } from "./permissions-DttnqqxC.js";
3
- import { n as ApprovalState, r as ClientPermDock, s as PermissionState } from "./types-kxznc7cn.js";
3
+ import { n as ApprovalState, r as ClientPermDock, s as PermissionState } from "./types-CKNSyIf_.js";
4
4
  //#region src/client/store.d.ts
5
5
  type ClientStore = {
6
6
  get(): ClientPermDock;
@@ -2,7 +2,7 @@ import { t as compact } from "./compact-y6vfu2_f.js";
2
2
  import { c as rowIdOf, n as parseSnapshot } from "./snapshot-Enxd0n-s.js";
3
3
  import { u as nowSeconds } from "./validity-uOp8UpYn.js";
4
4
  import { n as payloadDigest } from "./token-CIWxJOCh.js";
5
- import { n as fromSnapshot, t as emptySnapshot } from "./from-snapshot-C3sHpZNS.js";
5
+ import { n as fromSnapshot, t as emptySnapshot } from "./from-snapshot-CTLijvdm.js";
6
6
  import { t as timeoutSignal } from "./timeout-D51niuQP.js";
7
7
  //#region src/client/approvals.ts
8
8
  /** Ceiling for the approval poll backoff after a failed status request. */
@@ -1,5 +1,5 @@
1
1
  import { c as subjectView, i as permissionSet, l as tenantView, n as filterResult, o as rolesView, r as livePermDock, t as approvalHandle } from "./views-Soe7bGSC.js";
2
- import { n as providePermDock, t as getStore } from "./context-Ttp0ekMT.js";
2
+ import { n as providePermDock, t as getStore } from "./context-Bcy85rGi.js";
3
3
  import { readable, toStore } from "svelte/store";
4
4
  //#region src/svelte/stores.ts
5
5
  function fromStore(store, compute) {
@@ -1,7 +1,7 @@
1
- import { Ft as TokenVerifier, Mr as Membership, Tt as Snapshot, Yn as Decision } from "./policy-CFZAr_Al.js";
1
+ import { Ft as TokenVerifier, Mr as Membership, Tt as Snapshot, Yn as Decision } from "./policy-IB6yxpC3.js";
2
2
  import { f as Permission } from "./permissions-DttnqqxC.js";
3
3
  import { r as Role } from "./vocabulary-DA8a8zif.js";
4
- import { a as FilterResult, c as SubjectView, l as TenantView, o as PermissionSet, r as ClientPermDock, s as PermissionState, t as ApprovalHandle, u as UseRolesOptions } from "./types-kxznc7cn.js";
4
+ import { a as FilterResult, c as SubjectView, l as TenantView, o as PermissionSet, r as ClientPermDock, s as PermissionState, t as ApprovalHandle, u as UseRolesOptions } from "./types-CKNSyIf_.js";
5
5
  import { Readable } from "svelte/store";
6
6
  //#region src/svelte/types.d.ts
7
7
  type PermDockSvelteOptions = {
@@ -1,5 +1,5 @@
1
1
  import { f as Permission } from "./permissions-DttnqqxC.js";
2
- import { i as ProtectOptions } from "./create-BWyx3jua.js";
2
+ import { i as ProtectOptions } from "./create-B1d519XK.js";
3
3
  //#region src/server/stream.d.ts
4
4
  type StreamProtectOptions = ProtectOptions & {
5
5
  /**
@@ -1,8 +1,8 @@
1
- import { C as Policy, Dr as CustomRole, Mr as Membership, Pr as Subject, gt as MembershipSource, mt as MemberEntry, xt as RoleSource } from "../policy-CFZAr_Al.js";
2
- import { c as ApprovalRequest, f as ApprovalStore } from "../types-vKyAMtcX.js";
3
- import { C as SupabaseClaimsSchema, E as supabaseClaims, S as SupabaseClaimsOptions, T as SupabasePermDockClaims, _ as SupabaseSuspendedMembership, a as SupabaseActorResult, b as SupabaseActClaim, c as SupabaseMembershipTable, d as SupabaseRealtime, f as SupabaseRlsConfig, g as SupabaseSubjectOptions, h as SupabaseStorage, i as SupabaseActor, l as SupabasePermissionRef, m as SupabaseSessionLike, n as RoleThrough, o as SupabaseDelegation, p as SupabaseRlsOptions, r as SupabaseActiveRow, s as SupabaseInclude, t as AuthorizeSqlOptions, u as SupabasePrincipal, v as SupabaseSuspendedScope, w as SupabaseMembershipClaim, x as SupabaseClaims, y as SupabaseSuspension } from "../types-yF5LmQVD.js";
1
+ import { C as Policy, Dr as CustomRole, Mr as Membership, Pr as Subject, gt as MembershipSource, mt as MemberEntry, xt as RoleSource } from "../policy-IB6yxpC3.js";
2
+ import { c as ApprovalRequest, f as ApprovalStore } from "../types-aqOHTHcp.js";
3
+ import { C as SupabaseClaimsSchema, E as supabaseClaims, S as SupabaseClaimsOptions, T as SupabasePermDockClaims, _ as SupabaseSuspendedMembership, a as SupabaseActorResult, b as SupabaseActClaim, c as SupabaseMembershipTable, d as SupabaseRealtime, f as SupabaseRlsConfig, g as SupabaseSubjectOptions, h as SupabaseStorage, i as SupabaseActor, l as SupabasePermissionRef, m as SupabaseSessionLike, n as RoleThrough, o as SupabaseDelegation, p as SupabaseRlsOptions, r as SupabaseActiveRow, s as SupabaseInclude, t as AuthorizeSqlOptions, u as SupabasePrincipal, v as SupabaseSuspendedScope, w as SupabaseMembershipClaim, x as SupabaseClaims, y as SupabaseSuspension } from "../types-C97IskBw.js";
4
4
  import { a as SupabaseManifestHelper, c as SupabaseManifestRls, d as SupabaseManifestValue, f as parseSupabaseManifest, i as SupabaseManifestColumn, l as SupabaseManifestRole, n as SupabaseHookManifest, o as SupabaseManifestMembership, r as SupabaseManifestActiveRow, s as SupabaseManifestRequires, t as SupabaseHookClaim, u as SupabaseManifestThrough } from "../manifest-uDS9y5de.js";
5
- import { a as MembershipTableOptions, c as SupabasePostgres, d as fromSupabasePostgres, f as fromTable, i as MembershipSql, l as authzVersion, n as MembershipHolders, o as SqlMembershipSource, r as MembershipJunctionOptions, s as SqlQuery, t as AUTHZ_VERSION_TABLE, u as fromJunction } from "../sources-BcJgw0lt.js";
5
+ import { a as MembershipTableOptions, c as SupabasePostgres, d as fromSupabasePostgres, f as fromTable, i as MembershipSql, l as authzVersion, n as MembershipHolders, o as SqlMembershipSource, r as MembershipJunctionOptions, s as SqlQuery, t as AUTHZ_VERSION_TABLE, u as fromJunction } from "../sources-BdOYLw9j.js";
6
6
  import { n as supabaseTenantClaim, t as supabaseMembershipsBudget } from "../budget-JqcRqyhK.js";
7
7
  //#region src/supabase/capability.d.ts
8
8
  type ExchangeCapabilityOptions = {
@@ -54,6 +54,17 @@ type SupabaseRpcCaller = {
54
54
  };
55
55
  };
56
56
  type PostgrestSourcesOptions = {
57
+ /**
58
+ * The `supabase.hook.api` setting the hook file was generated with: the
59
+ * wrappers live in `schema` (default `public`) as `<prefix>subject_for`,
60
+ * `<prefix>members_of` and `<prefix>authz_version_for` (default prefix
61
+ * `permdock_`). It sets the defaults of `schema`, `fn`, `membersFn` and
62
+ * `versionFn`, which still override it.
63
+ */
64
+ readonly api?: {
65
+ readonly schema?: string;
66
+ readonly prefix?: string;
67
+ };
57
68
  /** Schema of the functions. Default `permdock`, where the hook generates `subject_for` and `members_of`. */
58
69
  readonly schema?: string;
59
70
  /** Function name, for a wrapper in an exposed schema. Default `subject_for`. */
@@ -1,5 +1,5 @@
1
- import { a as readSubjectRecord, i as postgrestSources, n as supabaseRls, o as supabaseClaims, r as supabaseApprovalStore, s as exchangeCapability, t as authorizeSql } from "../supabase-DTBaC20O.js";
1
+ import { a as readSubjectRecord, i as postgrestSources, n as supabaseRls, o as supabaseClaims, r as supabaseApprovalStore, s as exchangeCapability, t as authorizeSql } from "../supabase-C0qESOa-.js";
2
2
  import { n as supabaseTenantClaim, t as supabaseMembershipsBudget } from "../budget-NbEtbJC_.js";
3
- import { a as fromSupabasePostgres, i as fromJunction, o as fromTable, r as authzVersion, t as AUTHZ_VERSION_TABLE } from "../sources-B0UvrJ21.js";
3
+ import { a as fromJunction, i as authzVersion, o as fromSupabasePostgres, s as fromTable, t as AUTHZ_VERSION_TABLE } from "../sources-4p0-4xQm.js";
4
4
  import { a as subjectFromSupabase, n as actorOf, o as subjectFromSupabaseSession, r as delegationOf, t as parseSupabaseManifest } from "../manifest-iaoBXHKc.js";
5
5
  export { AUTHZ_VERSION_TABLE, actorOf, authorizeSql, authzVersion, delegationOf, exchangeCapability, fromJunction, fromSupabasePostgres, fromTable, parseSupabaseManifest, postgrestSources, readSubjectRecord, subjectFromSupabase, subjectFromSupabaseSession, supabaseApprovalStore, supabaseClaims, supabaseMembershipsBudget, supabaseRls, supabaseTenantClaim };