better-supabase 0.3.0 → 0.5.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 (211) hide show
  1. package/README.md +9 -6
  2. package/bin/better-supabase.js +4 -0
  3. package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
  4. package/dist/channel-FQW-CnGR.d.ts +70 -0
  5. package/dist/claims-BAf6c7is.js +48 -0
  6. package/dist/cli/_format-Cax5EsM9.js +101 -0
  7. package/dist/cli/bin.d.ts +1 -0
  8. package/dist/cli/bin.js +48 -0
  9. package/dist/cli/codemod-DqV7612m.js +388 -0
  10. package/dist/cli/command-CK14fP91.js +502 -0
  11. package/dist/cli/compare-BmIWVEui.js +9 -0
  12. package/dist/cli/config-CPVpXP5I.js +1965 -0
  13. package/dist/cli/config-dtoekM0v.js +2 -0
  14. package/dist/cli/db-DOBPt660.js +52 -0
  15. package/dist/cli/diff-SjkO5rNr.js +752 -0
  16. package/dist/cli/dist-DBPdlPYK.js +1112 -0
  17. package/dist/cli/dist-DreZ24Sz.js +129 -0
  18. package/dist/cli/dist-xn4wlboc.js +732 -0
  19. package/dist/cli/doctor-L7Z8mYTx.js +2863 -0
  20. package/dist/cli/env-DmKv_G4A.js +108 -0
  21. package/dist/cli/env-jIFUADLY.js +511 -0
  22. package/dist/cli/errors-4v4DTtda.js +56 -0
  23. package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
  24. package/dist/cli/gen-BJc9vdyu.js +2 -0
  25. package/dist/cli/gen-C2osRcr5.js +2204 -0
  26. package/dist/cli/index.d.ts +493 -0
  27. package/dist/cli/index.js +184 -0
  28. package/dist/cli/init-Saf5-R9T.js +550 -0
  29. package/dist/cli/introspect--H7oGmcd.js +81 -0
  30. package/dist/cli/io-k41_z-jT.js +24 -0
  31. package/dist/cli/json5-ChRycquj.js +787 -0
  32. package/dist/cli/jsonc-BUniUpOk.js +2 -0
  33. package/dist/cli/jsonc-D5Fu67jw.js +45 -0
  34. package/dist/cli/keys-ByKHnvP9.js +83 -0
  35. package/dist/cli/ohash-D7bG_EOb.js +277 -0
  36. package/dist/cli/openapi-Cp5Fyta-.js +66 -0
  37. package/dist/cli/project-B_GeXyHh.js +70 -0
  38. package/dist/cli/prompts-BNcNfAve.js +1142 -0
  39. package/dist/cli/prompts-BTYQGunc.js +2 -0
  40. package/dist/cli/read-sets-BfMQcKy8.js +289 -0
  41. package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
  42. package/dist/cli/run-BKR2W_79.js +351 -0
  43. package/dist/cli/seed-CUlqWh-8.js +98 -0
  44. package/dist/cli/skills-LJJIhLFR.js +137 -0
  45. package/dist/cli/sql-DzPbfngx.js +348 -0
  46. package/dist/cli/style-C0NFdJRL.js +29 -0
  47. package/dist/cli/toml-DB-MNnFs.js +424 -0
  48. package/dist/cli/version-BDJuO0UR.js +4 -0
  49. package/dist/cli/yaml-CYCbJ6et.js +2252 -0
  50. package/dist/client/index.d.ts +2 -2
  51. package/dist/client/index.js +15 -22
  52. package/dist/clone-BfgmLU90.js +21 -0
  53. package/dist/{compiler-2zqGzxVZ.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  54. package/dist/config/index.d.ts +4 -4
  55. package/dist/config/index.js +5 -5
  56. package/dist/{config-DOsGYSiT.js → config-DreERlKo.js} +1 -1
  57. package/dist/{config-C1CYcm6o.d.ts → config-T_ejwyd3.d.ts} +176 -11
  58. package/dist/{define-DUbydmJa.d.ts → define-Bp_BZa5h.d.ts} +37 -29
  59. package/dist/{define-DF341GDj.js → define-cNKzqwL_.js} +356 -89
  60. package/dist/edge/index.d.ts +20 -13
  61. package/dist/edge/index.js +55 -26
  62. package/dist/{entitlements-DvJXoI02.d.ts → entitlements-DUxU4oHe.d.ts} +2 -2
  63. package/dist/env/index.d.ts +2 -2
  64. package/dist/env/index.js +34 -1
  65. package/dist/{errors-Bl3rkOzo.js → errors-DtwXa6b8.js} +2 -1
  66. package/dist/events/index.d.ts +3 -2
  67. package/dist/events/index.js +69 -16
  68. package/dist/events-aIO7vsIk.d.ts +230 -0
  69. package/dist/executor-BunPOO-k.d.ts +402 -0
  70. package/dist/{executor-B26lgbHD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  71. package/dist/{executor-C57jx2pn.js → executor-XycESQPH.js} +3 -3
  72. package/dist/hono/index.d.ts +27 -23
  73. package/dist/hono/index.js +46 -11
  74. package/dist/impersonation-VfaGc4Q_.js +41 -0
  75. package/dist/{index-BNsABq7P.d.ts → index-BGdgBPdf.d.ts} +66 -25
  76. package/dist/{index-qriRM9cZ.d.ts → index-C7f8cOBM.d.ts} +4 -4
  77. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  78. package/dist/{index-GV77NpRP.d.ts → index-DOESKG27.d.ts} +34 -9
  79. package/dist/{index-CriFFJ_p.d.ts → index-DgILJRXj.d.ts} +43 -17
  80. package/dist/{index-UJ-LUxtI.d.ts → index-DmXSxbLi.d.ts} +14 -14
  81. package/dist/{index-Cf-D2jk1.d.ts → index-Dxn2a5cw.d.ts} +2 -2
  82. package/dist/{index-CTTMS6_1.d.ts → index-SaTsEfGP.d.ts} +86 -9
  83. package/dist/{index-CADlNHK-.d.ts → index-fag8VJZ2.d.ts} +5 -6
  84. package/dist/index.d.ts +34 -17
  85. package/dist/index.js +15 -14
  86. package/dist/jobs/index.d.ts +147 -95
  87. package/dist/jobs/index.js +773 -250
  88. package/dist/{json-schema--aOXAGfU.js → json-schema-m1fiwKgN.js} +23 -2
  89. package/dist/kit-events-CTFDfSwb.js +60 -0
  90. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  91. package/dist/kit-transport-DJlHQUBU.js +55 -0
  92. package/dist/{config-Be4GwsqI.js → kits-CGLLrNPd.js} +38 -10
  93. package/dist/list/index.d.ts +1 -1
  94. package/dist/list/index.js +3 -3
  95. package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
  96. package/dist/{live-QE3UPbGm.d.ts → live-D9W2M5aO.d.ts} +16 -15
  97. package/dist/lookup-BaP5bI27.js +18 -0
  98. package/dist/mcp/index.d.ts +39 -22
  99. package/dist/mcp/index.js +39 -25
  100. package/dist/{mfa-x3V3vGh-.d.ts → mfa-CusDgPaD.d.ts} +5 -1
  101. package/dist/next/image/index.js +6 -3
  102. package/dist/next/index.d.ts +60 -36
  103. package/dist/next/index.js +167 -50
  104. package/dist/notifications/index.d.ts +162 -0
  105. package/dist/notifications/index.js +264 -0
  106. package/dist/openapi/index.d.ts +1 -1
  107. package/dist/openapi/index.js +6 -6
  108. package/dist/orgs/index.d.ts +132 -0
  109. package/dist/orgs/index.js +245 -0
  110. package/dist/orpc/index.d.ts +37 -20
  111. package/dist/orpc/index.js +24 -11
  112. package/dist/otel/index.d.ts +24 -5
  113. package/dist/otel/index.js +124 -64
  114. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  115. package/dist/permdock-sql-DgOfeixi.js +51 -0
  116. package/dist/plugin-DwARMuQp.js +59 -0
  117. package/dist/{plugin-DVRB8qNE.d.ts → plugin-o144f322.d.ts} +17 -5
  118. package/dist/plugins/actor/index.d.ts +5 -2
  119. package/dist/plugins/actor/index.js +22 -8
  120. package/dist/plugins/rules/index.d.ts +2 -2
  121. package/dist/plugins/rules/index.js +52 -17
  122. package/dist/plugins/soft-delete/index.d.ts +3 -3
  123. package/dist/plugins/soft-delete/index.js +14 -5
  124. package/dist/plugins/tenant/index.d.ts +3 -3
  125. package/dist/plugins/tenant/index.js +45 -21
  126. package/dist/plugins/timestamps/index.d.ts +1 -1
  127. package/dist/plugins/timestamps/index.js +4 -3
  128. package/dist/plugins/validation/index.d.ts +2 -2
  129. package/dist/plugins/validation/index.js +26 -6
  130. package/dist/{pool-B9qsLyFR.d.ts → pool-C9voM4Kw.d.ts} +24 -6
  131. package/dist/postgres/index.d.ts +5 -5
  132. package/dist/postgres/index.js +20 -10
  133. package/dist/{postgrest-DmBlevh-.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  134. package/dist/{problem-CGt1ADix.js → problem-BW1KhzSG.js} +2 -1
  135. package/dist/{problem-Z2RTQjZD.d.ts → problem-Blxe8S31.d.ts} +1 -1
  136. package/dist/query/index.d.ts +2 -2
  137. package/dist/query/index.js +3 -3
  138. package/dist/{query-BdKLTPlj.js → query-CCbo44lG.js} +18 -18
  139. package/dist/queue-BYUCjr59.d.ts +252 -0
  140. package/dist/react/index.d.ts +8 -7
  141. package/dist/react/index.js +4 -3
  142. package/dist/react/server.d.ts +16 -5
  143. package/dist/react/server.js +12 -4
  144. package/dist/react/session.d.ts +10 -4
  145. package/dist/react/session.js +11 -3
  146. package/dist/{react-DNBYNazu.js → react-C_s7kiNz.js} +138 -46
  147. package/dist/{read-set-D0qBcboM.js → read-set-DQFt1N_Y.js} +71 -15
  148. package/dist/realtime/index.d.ts +3 -3
  149. package/dist/realtime/index.js +14 -12
  150. package/dist/{index-kpgopLNv.d.ts → refresh-BTrQ_ZTp.d.ts} +6 -3
  151. package/dist/{resolve-BRciX2jK.d.ts → resolve-C15TJq77.d.ts} +22 -11
  152. package/dist/{resource-D30rp0GN.js → resource-CRxxwkQq.js} +24 -9
  153. package/dist/{resource-CwVgiI5q.d.ts → resource-D8iqWMr-.d.ts} +6 -6
  154. package/dist/respond-D2OQl62-.d.ts +371 -0
  155. package/dist/{result-DWXatkd6.js → result-BKiliPY7.js} +2 -2
  156. package/dist/server/index.d.ts +17 -15
  157. package/dist/server/index.js +16 -22
  158. package/dist/server-Csx2sRjg.js +655 -0
  159. package/dist/{shared-_6-uPL7E.js → shared-D1dRUrAg.js} +19 -4
  160. package/dist/signers-Cc6r98SW.d.ts +162 -0
  161. package/dist/{simplify-LakqK1vH.js → simplify-_0oUKqCd.js} +27 -95
  162. package/dist/sql/index.d.ts +247 -10
  163. package/dist/sql/index.js +8591 -780
  164. package/dist/{sql-BIgk12ew.js → sql-Coh6n4cC.js} +11 -3
  165. package/dist/ssr/index.d.ts +4 -4
  166. package/dist/ssr/index.js +1 -2
  167. package/dist/{standard-FUi3Z3-7.js → standard-D7r6dMUu.js} +6 -3
  168. package/dist/{standard-eudBiRk1.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  169. package/dist/{stats-D78UQ8Yu.js → stats-Bqob3WqT.js} +34 -9
  170. package/dist/storage/index.d.ts +4 -4
  171. package/dist/storage/index.js +174 -27
  172. package/dist/support-DT-OhSxD.d.ts +88 -0
  173. package/dist/support-Dk6vdmEw.js +291 -0
  174. package/dist/support-view-Da5peKFg.d.ts +17 -0
  175. package/dist/support-view-g4YLBeqX.js +18 -0
  176. package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
  177. package/dist/{permdock-sql-Bta_G0v-.js → template-TxrGI5jR.js} +2 -31
  178. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  179. package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CAt4Dc9Z.js} +2 -2
  180. package/dist/testing/index.d.ts +113 -24
  181. package/dist/testing/index.js +375 -47
  182. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  183. package/dist/user-change-CHFEUro1.js +49 -0
  184. package/dist/{webhooks-CAIFQSTM.js → verify-Ce49ETPz.js} +38 -19
  185. package/dist/{version-BfpG2gks.js → version-DM_Roffb.js} +1 -1
  186. package/dist/{view-3Po_PVlr.d.ts → view-BEf0diC5.d.ts} +10 -5
  187. package/dist/{mfa-BxoR1RkN.js → view-Bq64ki8-.js} +210 -64
  188. package/dist/webhooks/index.d.ts +136 -5
  189. package/dist/webhooks/index.js +588 -2
  190. package/dist/wire-D2dT86vi.js +35 -0
  191. package/package.json +50 -10
  192. package/schemas/config-v1.json +131 -1
  193. package/schemas/doctor-report-v1.json +10 -0
  194. package/skills/better-supabase/SKILL.md +60 -10
  195. package/skills/better-supabase/references/plugins.md +13 -14
  196. package/skills/better-supabase/references/troubleshooting.md +25 -4
  197. package/skills/better-supabase-api/SKILL.md +74 -19
  198. package/skills/better-supabase-api/references/adapters.md +48 -27
  199. package/skills/better-supabase-auth/SKILL.md +149 -0
  200. package/skills/better-supabase-auth/references/permdock.md +100 -0
  201. package/skills/better-supabase-testing/SKILL.md +58 -4
  202. package/dist/claims-CoTobNC-.js +0 -25
  203. package/dist/events-Do8jXh4D.d.ts +0 -84
  204. package/dist/executor-DynmIWhq.d.ts +0 -195
  205. package/dist/invalidate-DbxuL2jL.js +0 -18
  206. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  207. package/dist/plugin-BqR6wKMB.js +0 -23
  208. package/dist/respond-C44EZAJo.js +0 -399
  209. package/dist/respond-DAkPIdTH.d.ts +0 -175
  210. package/dist/result-c2OYgCV2.d.ts +0 -203
  211. package/dist/view-wZ-9qIUz.js +0 -45
@@ -1,7 +1,7 @@
1
- import { n as dbError } from "./errors-Bl3rkOzo.js";
2
- import { i as ok, n as err } from "./result-DWXatkd6.js";
3
- import { t as validate } from "./standard-FUi3Z3-7.js";
4
- import { i as respond } from "./respond-C44EZAJo.js";
1
+ import { n as dbError } from "./errors-DtwXa6b8.js";
2
+ import { i as ok, n as err } from "./result-BKiliPY7.js";
3
+ import { t as validate } from "./standard-D7r6dMUu.js";
4
+ import { p as respond } from "./server-Csx2sRjg.js";
5
5
  //#region src/server/resource.ts
6
6
  const INTEGER = /* @__PURE__ */ new Set([
7
7
  "int2",
@@ -9,7 +9,7 @@ const INTEGER = /* @__PURE__ */ new Set([
9
9
  "int8"
10
10
  ]);
11
11
  function keyValue(table, raw) {
12
- const invalid = err(dbError("invalid_request", `${JSON.stringify(raw)} is not a valid ${table.key} key`));
12
+ const invalid = err(dbError("invalid_input", `${JSON.stringify(raw)} is not a valid ${table.key} key`));
13
13
  const column = table.columns[table.primaryKey[0]];
14
14
  if (column && INTEGER.has(column.type)) {
15
15
  const value = typeof raw === "string" ? Number(raw) : raw;
@@ -17,12 +17,26 @@ function keyValue(table, raw) {
17
17
  }
18
18
  return typeof raw === "string" && raw !== "" ? ok(raw) : invalid;
19
19
  }
20
+ /**
21
+ * A cross-site browser request that needed no CORS preflight: a form post
22
+ * riding on the session cookie. Bearer requests and JSON bodies (which need a
23
+ * preflight) pass, as do requests without an `Origin` (not a browser).
24
+ */
25
+ function crossSiteSimpleRequest(request) {
26
+ if (request.method === "GET" || request.method === "HEAD") return false;
27
+ if (request.headers.has("authorization")) return false;
28
+ const origin = request.headers.get("origin");
29
+ if (!origin || origin === new URL(request.url).origin) return false;
30
+ if (request.headers.get("sec-fetch-site") === "same-origin") return false;
31
+ const type = request.headers.get("content-type") ?? "";
32
+ return !/^application\/(?:[\w.+-]+\+)?json\b/iu.test(type);
33
+ }
20
34
  async function readBody(request) {
21
35
  try {
22
36
  const body = await request.json();
23
37
  if (typeof body === "object" && body !== null && !Array.isArray(body)) return ok(body);
24
38
  } catch {}
25
- return err(dbError("invalid_request", "The request body must be a JSON object"));
39
+ return err(dbError("invalid_input", "The request body must be a JSON object"));
26
40
  }
27
41
  function pageArgs(query, max, pagination) {
28
42
  const raw = (name) => {
@@ -66,7 +80,7 @@ function pageArgs(query, max, pagination) {
66
80
  });
67
81
  }
68
82
  function asObject(value) {
69
- return typeof value === "object" && value !== null && !Array.isArray(value) ? ok(value) : err(dbError("invalid_request", "Expected an object of column values"));
83
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? ok(value) : err(dbError("invalid_input", "Expected an object of column values"));
70
84
  }
71
85
  async function settled(value) {
72
86
  return await value;
@@ -82,8 +96,8 @@ function notAllowed(allowed) {
82
96
  * `createOpenApi`: `GET/POST /<table>` and `GET/PATCH/DELETE /<table>/{id}`.
83
97
  * Shared by the HTTP adapters and the MCP table tools.
84
98
  */
85
- function defineResource(sb, table, options = {}) {
86
- const meta = sb.meta.tables[table];
99
+ function defineResource(betterSupabase, table, options = {}) {
100
+ const meta = betterSupabase.meta.tables[table];
87
101
  if (!meta) throw new TypeError(`Unknown table "${table}"`);
88
102
  if (options.list && options.list.table !== table) throw new TypeError(`The list query is for "${options.list.table}", not "${table}"`);
89
103
  const operations = options.operations ?? (meta.kind === "view" ? ["list", "get"] : [
@@ -155,6 +169,7 @@ function defineResource(sb, table, options = {}) {
155
169
  ...has("delete") ? ["DELETE"] : []
156
170
  ];
157
171
  const route = async (request, db, id) => {
172
+ if (crossSiteSimpleRequest(request)) return err(dbError("forbidden", "Cross-site requests need Content-Type: application/json or a bearer token", { code: "CROSS_SITE_REQUEST" }));
158
173
  if (id === void 0) {
159
174
  if (request.method === "GET" && has("list")) return execute(db, "list", { query: new URL(request.url).searchParams });
160
175
  if (request.method === "POST" && has("create")) {
@@ -1,8 +1,8 @@
1
- import { N as TableKey, P as TableMeta, R as Update, g as Insert, n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
2
- import { b as ValidationIssue, o as Result } from "./result-c2OYgCV2.js";
3
- import { t as BetterSupabase, xt as SelectArg } from "./define-DUbydmJa.js";
4
- import { r as RespondOptions } from "./respond-DAkPIdTH.js";
5
- import { i as ResourceOperation } from "./index-qriRM9cZ.js";
1
+ import { F as TableMeta, P as TableKey, _ as Insert, n as AnyFunctions, r as AnyModels, z as Update } from "./types-Dnf_wRDz.js";
2
+ import { u as Result, w as ValidationIssue } from "./executor-BunPOO-k.js";
3
+ import { t as BetterSupabase, xt as SelectArg } from "./define-Bp_BZa5h.js";
4
+ import { i as RespondOptions } from "./respond-D2OQl62-.js";
5
+ import { i as ResourceOperation } from "./index-C7f8cOBM.js";
6
6
  import { StandardSchemaV1 } from "@standard-schema/spec";
7
7
  //#region src/server/resource.d.ts
8
8
  /** What a resource needs from `defineListQuery`. */
@@ -69,6 +69,6 @@ interface ResourceHandler {
69
69
  * `createOpenApi`: `GET/POST /<table>` and `GET/PATCH/DELETE /<table>/{id}`.
70
70
  * Shared by the HTTP adapters and the MCP table tools.
71
71
  */
72
- declare function defineResource<M extends AnyModels, D, F extends AnyFunctions, E, T extends TableKey<M>>(sb: BetterSupabase<M, D, F, E>, table: T, options?: ResourceRouteOptions<M, T>): ResourceHandler;
72
+ declare function defineResource<M extends AnyModels, D, F extends AnyFunctions, E, T extends TableKey<M>>(betterSupabase: BetterSupabase<M, D, F, E>, table: T, options?: ResourceRouteOptions<M, T>): ResourceHandler;
73
73
  //#endregion
74
74
  export { ResourceRouteOptions as a, ResourcePagination as i, ResourceInput as n, defineResource as o, ResourceList as r, ResourceHandler as t };
@@ -0,0 +1,371 @@
1
+ import { n as AnyFunctions, r as AnyModels } from "./types-Dnf_wRDz.js";
2
+ import { _ as DbError, a as AsyncResult } from "./executor-BunPOO-k.js";
3
+ import { a as EventHub } from "./events-aIO7vsIk.js";
4
+ import { I as StatsRecorder, P as DbStats, t as BetterSupabase, y as Db } from "./define-Bp_BZa5h.js";
5
+ import { g as RequestContext } from "./plugin-o144f322.js";
6
+ import { t as BetterSupabaseEnv } from "./index-CLg87OBW.js";
7
+ import { s as SqlClaims, t as BetterPostgres } from "./pool-C9voM4Kw.js";
8
+ import { a as ResolveAuthOptions, r as AuthState, t as AuthResolution } from "./resolve-C15TJq77.js";
9
+ import { a as SupportSession, i as SupportListFilter, o as SupportSessionStore } from "./support-DT-OhSxD.js";
10
+ import { o as ImpersonationOptions, t as Aal } from "./mfa-CusDgPaD.js";
11
+ import { c as Bucket } from "./index-SaTsEfGP.js";
12
+ import { SupabaseClient } from "@supabase/supabase-js";
13
+ import { StandardSchemaV1 } from "@standard-schema/spec";
14
+ //#region src/auth/support-cookie.d.ts
15
+ /** The cookie that carries the support session id. */
16
+ declare const SUPPORT_COOKIE = "bs-support";
17
+ interface SupportCookieOptions {
18
+ /** Defaults to `bs-support`. */
19
+ readonly name?: string;
20
+ /** Defaults to `/`. */
21
+ readonly path?: string;
22
+ /** Defaults to true; set false for plain-HTTP local development. */
23
+ readonly secure?: boolean;
24
+ }
25
+ /** `Set-Cookie` for a session: HttpOnly, SameSite=Lax, gone when the session expires. */
26
+ declare function supportCookie(session: Pick<SupportSession, "id" | "expiresAt">, options?: SupportCookieOptions, now?: number): string;
27
+ /** `Set-Cookie` that removes the support cookie. */
28
+ declare function clearSupportCookie(options?: SupportCookieOptions): string;
29
+ /** The support session id in a `Cookie` header, or `undefined`. */
30
+ declare function supportCookieValue(cookieHeader: string | null, name?: string): string | undefined;
31
+ //#endregion
32
+ //#region src/server/support.d.ts
33
+ type UserAuth = Extract<AuthState, {
34
+ kind: "user";
35
+ }>;
36
+ interface SupportPolicy {
37
+ /** Seconds a session lasts. Defaults to 1800 (30 minutes). */
38
+ readonly ttl?: number;
39
+ /** The longest `ttl` a start may ask for. Defaults to 14400 (4 hours). */
40
+ readonly maxTtl?: number;
41
+ /** Defaults to true. */
42
+ readonly requireReason?: boolean;
43
+ /**
44
+ * `always` (the default): every session is read-only. `default`: read-only
45
+ * unless the start passes `readOnly: false`.
46
+ */
47
+ readonly readOnly?: "always" | "default";
48
+ }
49
+ interface SupportAuthorizeInput {
50
+ readonly admin: UserAuth;
51
+ readonly targetUserId: string;
52
+ readonly reason: string;
53
+ readonly readOnly: boolean;
54
+ readonly tenant?: string;
55
+ readonly metadata: Readonly<Record<string, unknown>>;
56
+ }
57
+ interface SupportOptions {
58
+ readonly store: SupportSessionStore;
59
+ /**
60
+ * Whether `admin` may view the app as the target. A throw or rejection
61
+ * counts as a deny. Defaults to allowing, so the store decides: the SQL
62
+ * store checks `is_platform(kits.support-sessions.permissions.start)`.
63
+ */
64
+ readonly authorize?: (input: SupportAuthorizeInput) => boolean | Promise<boolean>;
65
+ /**
66
+ * The claims the target gets. Defaults to `store.claims` (the SQL store
67
+ * runs your custom access token hook), then `{ role: 'authenticated' }`.
68
+ */
69
+ readonly claims?: (targetUserId: string) => Readonly<Record<string, unknown>> | Promise<Readonly<Record<string, unknown>>>;
70
+ readonly policy?: SupportPolicy;
71
+ readonly cookie?: SupportCookieOptions;
72
+ }
73
+ interface SupportStartRequest {
74
+ readonly targetUserId: string;
75
+ readonly reason?: string;
76
+ /** Seconds; defaults to `policy.ttl`. */
77
+ readonly ttl?: number;
78
+ /** Honoured only with `policy.readOnly: 'default'`. */
79
+ readonly readOnly?: boolean;
80
+ readonly tenant?: string;
81
+ readonly metadata?: Readonly<Record<string, unknown>>;
82
+ }
83
+ /** A running support session, as the request that carries its cookie sees it. */
84
+ interface ActiveSupport {
85
+ readonly session: SupportSession;
86
+ /** The admin behind the session, from their own verified token. */
87
+ readonly admin: {
88
+ readonly id: string;
89
+ readonly email?: string;
90
+ };
91
+ /** The target's claims plus `act`, which repositories run with. */
92
+ readonly claims: Readonly<Record<string, unknown>>;
93
+ }
94
+ /** `bs.support`: start, stop and inspect support sessions. */
95
+ interface SupportApi {
96
+ /**
97
+ * Starts a session for a signed-in admin and returns it with the
98
+ * `Set-Cookie` value that switches the admin's next requests to the target.
99
+ */
100
+ start(admin: AuthState, request: SupportStartRequest): AsyncResult<{
101
+ readonly session: SupportSession;
102
+ readonly cookie: string;
103
+ }>;
104
+ /** Ends the admin's own session and returns the `Set-Cookie` that clears the cookie. */
105
+ stop(admin: AuthState, sessionId: string): AsyncResult<{
106
+ readonly ended: boolean;
107
+ readonly cookie: string;
108
+ }>;
109
+ /**
110
+ * Ends a session as `caller`: the SQL store allows the session's admin and
111
+ * staff with the revoke permission.
112
+ */
113
+ revoke(caller: AuthState, sessionId: string): AsyncResult<boolean>;
114
+ /** The running session the request's cookie names for `auth`, if any. */
115
+ current(request: Request, auth: AuthState): Promise<ActiveSupport | undefined>;
116
+ /** The sessions `caller` may view (the SQL store checks the view permission). */
117
+ list(caller: AuthState, filter?: SupportListFilter): AsyncResult<readonly SupportSession[]>;
118
+ /** The support session id in a request's cookie. */
119
+ sessionIdOf(request: Request): string | undefined;
120
+ /** `Set-Cookie` that clears the support cookie. */
121
+ clearCookie(): string;
122
+ }
123
+ /** `ServerOptions.support`, from `supportSessions(options)`. */
124
+ interface SupportSessions {
125
+ readonly options: SupportOptions;
126
+ /** Builds `bs.support`; `createServer` calls it once. */
127
+ readonly create: (events: EventHub, claimsSchema: StandardSchemaV1 | undefined) => SupportApi;
128
+ }
129
+ /**
130
+ * Support sessions for `createServer(betterSupabase, { support })`. Apps that
131
+ * never import it don't bundle the support code.
132
+ */
133
+ declare function supportSessions(options: SupportOptions): SupportSessions;
134
+ //#endregion
135
+ //#region src/server/delete-account.d.ts
136
+ interface DeleteAccountOptions {
137
+ /**
138
+ * Buckets to clear first. Objects whose `owner` placeholder (`{userId}`,
139
+ * or `owner.param` for `owner` buckets) is the user are removed; buckets
140
+ * without one are skipped.
141
+ */
142
+ readonly buckets?: readonly Bucket<string>[];
143
+ /**
144
+ * App keys of tables whose rows the database deletes or updates with the
145
+ * user (`on delete cascade` or `set null` to `auth.users`). They get a
146
+ * table-wide `mutation` notice, so caches drop their reads.
147
+ */
148
+ readonly cascades?: readonly string[];
149
+ readonly context?: RequestContext;
150
+ readonly signal?: AbortSignal;
151
+ }
152
+ interface DeleteAccountResult {
153
+ readonly userId: string;
154
+ /** Removed objects per bucket id. */
155
+ readonly removed: Readonly<Record<string, number>>;
156
+ }
157
+ //#endregion
158
+ //#region src/server/replicas.d.ts
159
+ /** Cookie holding the epoch ms until which reads stay on the primary. */
160
+ declare const PRIMARY_COOKIE = "bs-primary-until";
161
+ /** Where a request context sends its reads. */
162
+ interface ReplicaState {
163
+ /** Reads go to the primary: this context wrote, or a recent request did. */
164
+ readonly pinned: boolean;
165
+ /** This context wrote through its repositories (or called `pin()`). */
166
+ readonly wrote: boolean;
167
+ /** Sends later reads to the primary, e.g. after a write through `$client` or `ctx.sql`. */
168
+ pin(): void;
169
+ }
170
+ //#endregion
171
+ //#region src/server/server.d.ts
172
+ interface ServerOptions {
173
+ /** Defaults to `loadEnv()`. */
174
+ readonly env?: BetterSupabaseEnv;
175
+ /** Enables `ctx.sql` and `actingAs()`. */
176
+ readonly postgres?: BetterPostgres;
177
+ readonly auth?: Omit<ResolveAuthOptions, "env">;
178
+ /**
179
+ * Fetch the JWKS when the server is created, so the first request verifies
180
+ * its token without waiting for it. Applies when neither `auth.jwks` nor
181
+ * `env.jwks` (`SUPABASE_JWKS`) holds the keys inline. Defaults to true, except under `NODE_ENV=test`.
182
+ */
183
+ readonly prefetchJwks?: boolean;
184
+ /**
185
+ * Extra headers on the caller's PostgREST requests, readable in Postgres as
186
+ * `current_setting('request.headers')` (channel, request id, client IP for audit).
187
+ */
188
+ readonly headers?: (request: Request) => Readonly<Record<string, string>>;
189
+ /**
190
+ * PostgREST URL for the caller's reads: a read replica or the `<ref>-all`
191
+ * load balancer. Defaults to `SUPABASE_READ_URL`; `false` reads from the
192
+ * primary.
193
+ */
194
+ readonly readUrl?: string | false;
195
+ /**
196
+ * `fetch` for the PostgREST and supabase-js clients, e.g. `tracedFetch()`
197
+ * from `better-supabase/otel`. Auth refreshes use `auth.fetch`.
198
+ */
199
+ readonly fetch?: typeof globalThis.fetch;
200
+ readonly replicas?: {
201
+ /** How long the next requests read from the primary after a write. Defaults to 5 s. */
202
+ readonly pinMs?: number;
203
+ };
204
+ /**
205
+ * The active tenant of a request when it doesn't come from a claim, e.g.
206
+ * from a URL slug (`kits.access.activeTenant: 'resolver'`). It becomes
207
+ * `context.tenant` for the `tenant()` plugin, the `better_supabase.tenant`
208
+ * setting over Postgres and the `x-bs-tenant` header over PostgREST, which
209
+ * `current_tenant_id()` reads only while the caller is a member. Async
210
+ * resolvers need `context(request)`; `contextFromResolution` takes
211
+ * `options.tenant` instead.
212
+ */
213
+ readonly tenant?: (request: Request, auth: AuthState) => string | undefined | PromiseLike<string | undefined>;
214
+ /**
215
+ * Support sessions ("view as user") from `supportSessions(options)`: a platform admin's requests that carry
216
+ * the support cookie run as the target user, read-only by default. Needs
217
+ * `postgres`, since the target's queries run over direct Postgres.
218
+ */
219
+ readonly support?: SupportSessions;
220
+ }
221
+ /** The header `current_tenant_id()` reads over the Data API. */
222
+ declare const TENANT_HEADER = "x-bs-tenant";
223
+ interface ServerContext<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
224
+ readonly auth: AuthState<C, P>;
225
+ readonly resolution: AuthResolution<C, P>;
226
+ /**
227
+ * supabase-js client scoped to the caller (RLS applies). Throws in a
228
+ * support session: Realtime, Storage and Auth would act as the admin.
229
+ */
230
+ readonly supabase: SupabaseClient;
231
+ /** Repositories over PostgREST as the caller. */
232
+ readonly db: Db<M, F, E, SupabaseClient>;
233
+ /** Repositories over direct Postgres as the caller, when `postgres` is configured. */
234
+ readonly sql: Db<M, F, E, undefined> | undefined;
235
+ /** Calls, waves, tables and time for `db` and `sql` together. */
236
+ stats(): DbStats;
237
+ /** Where `db` reads go, when a read URL is configured. */
238
+ readonly replica: ReplicaState | undefined;
239
+ /**
240
+ * `response` with this request's cookies: refreshed session cookies
241
+ * (`resolution.apply`) and, after a write, `bs-primary-until`.
242
+ */
243
+ apply(response: Response): Response;
244
+ /**
245
+ * Set while an admin views the app as another user: `auth`, `db` and
246
+ * `sql` are the target's, and `resolution` stays the admin's.
247
+ */
248
+ readonly support?: ActiveSupport;
249
+ }
250
+ interface ContextOptions {
251
+ readonly refresh?: boolean;
252
+ /** Read the session cookie. Defaults to true; `false` resolves bearer tokens only. */
253
+ readonly cookies?: boolean;
254
+ /** Epoch ms until which `db` reads from the primary (the `bs-primary-until` cookie). */
255
+ readonly pinnedUntil?: number;
256
+ /** Also records this context's calls into a request-wide recorder. */
257
+ readonly stats?: StatsRecorder;
258
+ /** The active tenant, instead of `ServerOptions.tenant`. */
259
+ readonly tenant?: string;
260
+ /**
261
+ * The request's support session, from `support.current()`. `context()`
262
+ * looks it up itself; `contextFromResolution` only uses this.
263
+ */
264
+ readonly support?: ActiveSupport;
265
+ }
266
+ interface BetterServer<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
267
+ readonly env: BetterSupabaseEnv;
268
+ resolve(request: Request, options?: {
269
+ readonly refresh?: boolean;
270
+ readonly cookies?: boolean;
271
+ }): Promise<AuthResolution<C, P>>;
272
+ /**
273
+ * Resolves auth and binds repositories to the caller. Refreshes an expired
274
+ * cookie session only with `refresh: true`; send `ctx.apply(response)`.
275
+ */
276
+ context(request: Request, options?: ContextOptions): Promise<ServerContext<M, F, E, C, P>>;
277
+ /**
278
+ * The context for a resolution from `resolve(request)`, so one resolution
279
+ * can back several contexts without verifying the token again.
280
+ */
281
+ contextFromResolution(resolution: AuthResolution<C, P>, request: Request, options?: Omit<ContextOptions, "refresh">): ServerContext<M, F, E, C, P>;
282
+ /** The context for an auth state resolved elsewhere (the proxy, a queue message). */
283
+ contextFor(auth: AuthState<C, P>, options?: ContextOptions): ServerContext<M, F, E, C, P>;
284
+ /** A stateless supabase-js client for an auth state, optionally with extra request headers. */
285
+ supabaseFor(auth: AuthState, headers?: Readonly<Record<string, string>>): SupabaseClient;
286
+ /** Repositories for an auth state (e.g. one resolved by the proxy). */
287
+ dbFor(auth: AuthState, context?: RequestContext): Db<M, F, E, SupabaseClient>;
288
+ /** Service-role repositories. Bypasses RLS; the actor is `service`. */
289
+ admin(context?: RequestContext): Db<M, F, E, SupabaseClient>;
290
+ /**
291
+ * Deletes a user: their objects in `buckets`, then the Auth user, then a
292
+ * `mutation` notice for `auth.users`. Needs the secret key. Access tokens
293
+ * already issued stay valid until they expire.
294
+ */
295
+ deleteAccount(userId: string, options?: DeleteAccountOptions): AsyncResult<DeleteAccountResult>;
296
+ /**
297
+ * Repositories running as a user, with RLS, over direct Postgres. With
298
+ * `impersonation`, the claims carry `act: { sub: actor, reason }`, which
299
+ * the `audit` and `actor` SQL kit modules record.
300
+ */
301
+ actingAs(userId: string, claims?: Omit<SqlClaims, "sub" | "act">, impersonation?: ImpersonationOptions): Db<M, F, E, undefined>;
302
+ /** Support sessions; every method fails without `ServerOptions.support`. */
303
+ readonly support: SupportApi;
304
+ }
305
+ /**
306
+ * Server-side entry point for APIs, jobs, MCP servers and framework
307
+ * adapters. Holds the secrets; `betterSupabase` stays isomorphic.
308
+ */
309
+ declare function createServer<M extends AnyModels, D, F extends AnyFunctions, E, C = unknown, P = unknown>(betterSupabase: BetterSupabase<M, D, F, E, C, P>, options?: ServerOptions): BetterServer<M, F, E, C, P>;
310
+ //#endregion
311
+ //#region src/server/respond.d.ts
312
+ type AuthKind = AuthState["kind"];
313
+ /** An auth kind a guard lets through; `anonymous` admits `signInAnonymously()` users. */
314
+ type AllowedCaller = Exclude<AuthKind, "invalid"> | "anonymous";
315
+ interface GuardOptions {
316
+ /**
317
+ * Callers allowed through. Defaults to `['user']`, which refuses anonymous
318
+ * users (`is_anonymous`); add `'anonymous'` (or `'anon'`) to admit them.
319
+ */
320
+ readonly allow?: readonly AllowedCaller[];
321
+ /**
322
+ * Assurance level user sessions need. `aal2` answers 403 with
323
+ * `required: 'aal2'` until the user verifies a second factor.
324
+ */
325
+ readonly aal?: Aal;
326
+ /**
327
+ * OAuth scopes a delegated token (an OAuth client or an `act` chain) needs.
328
+ * A missing one answers 403 with `error="insufficient_scope"`. The user's
329
+ * own session is not limited by scopes.
330
+ */
331
+ readonly scopes?: readonly string[];
332
+ }
333
+ /** Guard options for middleware and fetch handlers that resolve the caller themselves. */
334
+ interface MiddlewareOptions extends GuardOptions {
335
+ /**
336
+ * Refresh an expired cookie session and send the new cookies. Only for
337
+ * routes browsers call with cookies; bearer tokens never refresh.
338
+ */
339
+ readonly refresh?: boolean;
340
+ }
341
+ /** `undefined` when `auth` may pass; otherwise the 401/403 error to send. */
342
+ declare function guard(auth: AuthState, allow?: GuardOptions["allow"], aal?: Aal, scopes?: readonly string[]): DbError | undefined;
343
+ declare function isResult(value: unknown): value is {
344
+ ok: boolean;
345
+ data: unknown;
346
+ error: unknown;
347
+ };
348
+ type Settled = {
349
+ readonly ok: true;
350
+ readonly data: unknown;
351
+ } | {
352
+ readonly ok: false;
353
+ readonly error: DbError;
354
+ };
355
+ /**
356
+ * Settles a handler's return value: `Result`s and `AsyncResult`s unwrap,
357
+ * thrown `DbException`s (or errors whose `cause` is a `DbError`) become
358
+ * errors, anything else is data. Other thrown
359
+ * errors propagate.
360
+ */
361
+ declare function settle(run: () => unknown): Promise<Settled>;
362
+ interface RespondOptions {
363
+ readonly instance?: string;
364
+ readonly expose?: boolean;
365
+ /** Status for data responses. Defaults to 200 (204 without data). */
366
+ readonly status?: number;
367
+ }
368
+ /** A handler's value as a response: `Response` as is, data as JSON, errors as Problem Details. */
369
+ declare function respond(run: () => unknown, options?: RespondOptions): Promise<Response>;
370
+ //#endregion
371
+ export { clearSupportCookie as A, SupportOptions as C, supportSessions as D, SupportStartRequest as E, supportCookieValue as M, SUPPORT_COOKIE as O, SupportAuthorizeInput as S, SupportSessions as T, ReplicaState as _, Settled as a, ActiveSupport as b, respond as c, ContextOptions as d, ServerContext as f, PRIMARY_COOKIE as g, createServer as h, RespondOptions as i, supportCookie as j, SupportCookieOptions as k, settle as l, TENANT_HEADER as m, GuardOptions as n, guard as o, ServerOptions as p, MiddlewareOptions as r, isResult as s, AuthKind as t, BetterServer as u, DeleteAccountOptions as v, SupportPolicy as w, SupportApi as x, DeleteAccountResult as y };
@@ -1,4 +1,4 @@
1
- import { n as dbError, r as dbErrorOf, t as DbException } from "./errors-Bl3rkOzo.js";
1
+ import { n as dbError, r as dbErrorOf, t as DbException } from "./errors-DtwXa6b8.js";
2
2
  //#region src/core/result.ts
3
3
  const throwMappers = /* @__PURE__ */ new WeakMap();
4
4
  function inherit(from, next) {
@@ -49,7 +49,7 @@ var AsyncResult = class AsyncResult {
49
49
  /**
50
50
  * Resolves with the data, or rejects with a `DbException`. Pass `factory`
51
51
  * to throw your own error instead, e.g. an HTTP error for your framework;
52
- * without it, the mapper from `sb.mapError()` applies when one is set.
52
+ * without it, the mapper from `betterSupabase.mapError()` applies when one is set.
53
53
  */
54
54
  async orThrow(factory) {
55
55
  const result = await this.#promise;
@@ -1,14 +1,16 @@
1
- import { n as AnyModels, t as AnyFunctions } from "../types-DONv9SHN.js";
2
- import { p as DbError } from "../result-c2OYgCV2.js";
3
- import { t as BetterSupabase, y as Db } from "../define-DUbydmJa.js";
4
- import { h as RequestContext } from "../plugin-DVRB8qNE.js";
5
- import { a as checkAal, c as impersonatorOf, i as amrOf, n as AmrEntry, o as ImpersonationOptions, r as aalOf, s as Impersonator, t as Aal } from "../mfa-x3V3vGh-.js";
6
- import { _ as readSession, a as ResolveAuthOptions, b as writeSession, c as clientIp, d as CookieOptions, f as CookieRecord, i as InvalidReason, l as resolveAuth, m as StoredSession, n as AuthResolver, o as ResolvedState, p as CookieWrite, r as AuthState, s as authContext, t as AuthResolution, u as AUTH_CACHE_HEADERS, y as sessionCookieName } from "../resolve-BRciX2jK.js";
7
- import { _ as DeleteAccountResult, a as guard, c as settle, d as ServerContext, f as ServerOptions, g as DeleteAccountOptions, h as ReplicaState, i as Settled, l as BetterServer, m as PRIMARY_COOKIE, n as GuardOptions, o as isResult, p as createServer, r as RespondOptions, s as respond, t as AuthKind, u as ContextOptions } from "../respond-DAkPIdTH.js";
8
- import { a as ResourceRouteOptions, i as ResourcePagination, n as ResourceInput, o as defineResource, r as ResourceList, t as ResourceHandler } from "../resource-CwVgiI5q.js";
9
- import { a as ProblemResponseOptions, c as problemResponse, i as ProblemOptions, l as toProblem, n as PROBLEM_TYPE_BASE, o as fromProblem, r as ProblemDetails, s as isProblem, t as PROBLEM_CONTENT_TYPE } from "../problem-Z2RTQjZD.js";
10
- import { a as SessionDelegation, i as SessionActor, n as toSession, r as ActClaim, t as AuthSession } from "../view-3Po_PVlr.js";
11
- import { n as RefreshOutcome, r as refreshSession } from "../index-kpgopLNv.js";
1
+ import { n as AnyFunctions, r as AnyModels } from "../types-Dnf_wRDz.js";
2
+ import { _ as DbError } from "../executor-BunPOO-k.js";
3
+ import { t as BetterSupabase, y as Db } from "../define-Bp_BZa5h.js";
4
+ import { g as RequestContext } from "../plugin-o144f322.js";
5
+ import { _ as readSession, a as ResolveAuthOptions, b as writeSession, c as clientIp, d as CookieOptions, f as CookieRecord, i as InvalidReason, l as resolveAuth, m as StoredSession, n as AuthResolver, o as ResolvedState, p as CookieWrite, r as AuthState, s as authContext, t as AuthResolution, u as AUTH_CACHE_HEADERS, y as sessionCookieName } from "../resolve-C15TJq77.js";
6
+ import { a as SupportSession, c as sqlSupportStore, i as SupportListFilter, l as supportClaims, n as SupportCallerClaims, o as SupportSessionStore, r as SupportEndedBy, s as SupportStartInput, t as SqlSupportStoreOptions } from "../support-DT-OhSxD.js";
7
+ import { A as clearSupportCookie, C as SupportOptions, D as supportSessions, E as SupportStartRequest, M as supportCookieValue, O as SUPPORT_COOKIE, S as SupportAuthorizeInput, T as SupportSessions, _ as ReplicaState, a as Settled, b as ActiveSupport, c as respond, d as ContextOptions, f as ServerContext, g as PRIMARY_COOKIE, h as createServer, i as RespondOptions, j as supportCookie, k as SupportCookieOptions, l as settle, m as TENANT_HEADER, n as GuardOptions, o as guard, p as ServerOptions, r as MiddlewareOptions, s as isResult, t as AuthKind, u as BetterServer, v as DeleteAccountOptions, w as SupportPolicy, x as SupportApi, y as DeleteAccountResult } from "../respond-D2OQl62-.js";
8
+ import { a as checkAal, c as impersonatorOf, i as amrOf, n as AmrEntry, o as ImpersonationOptions, r as aalOf, s as Impersonator, t as Aal } from "../mfa-CusDgPaD.js";
9
+ import { a as ResourceRouteOptions, i as ResourcePagination, n as ResourceInput, o as defineResource, r as ResourceList, t as ResourceHandler } from "../resource-D8iqWMr-.js";
10
+ import { a as ProblemResponseOptions, c as problemResponse, i as ProblemOptions, l as toProblem, n as PROBLEM_TYPE_BASE, o as fromProblem, r as ProblemDetails, s as isProblem, t as PROBLEM_CONTENT_TYPE } from "../problem-Blxe8S31.js";
11
+ import { a as SessionDelegation, i as SessionActor, n as toSession, r as ActClaim, t as AuthSession } from "../view-BEf0diC5.js";
12
+ import { n as supportOf, t as SupportView } from "../support-view-Da5peKFg.js";
13
+ import { n as RefreshOutcome, r as refreshSession } from "../refresh-BTrQ_ZTp.js";
12
14
  import { SupabaseClient } from "@supabase/supabase-js";
13
15
  import { Middleware } from "@supabase/middleware";
14
16
  import { AuthMode, JWTClaims, UserClaims } from "@supabase/server";
@@ -27,17 +29,17 @@ export declare function contextFromSupabase(ctx: SupabaseAuthContext): RequestCo
27
29
  * `ctx.supabase` (the caller-scoped client from `withSupabase`).
28
30
  *
29
31
  * ```ts
30
- * pipeline([withSupabase({ auth: 'user' }), withBetterSupabase(sb)()], (req, ctx) => ...)
32
+ * pipeline([withSupabase({ auth: 'user' }), withBetterSupabase(betterSupabase)()], (req, ctx) => ...)
31
33
  * ```
32
34
  */
33
- export declare function withBetterSupabase<M extends AnyModels, D, F extends AnyFunctions, E>(sb: BetterSupabase<M, D, F, E>): Middleware<"db", void, SupabaseAuthContext & {
35
+ export declare function withBetterSupabase<M extends AnyModels, D, F extends AnyFunctions, E>(betterSupabase: BetterSupabase<M, D, F, E>): Middleware<"db", void, SupabaseAuthContext & {
34
36
  readonly supabase: SupabaseClient;
35
37
  }, Db<M, F, E, SupabaseClient>>;
36
38
  /**
37
39
  * Entry contributing `ctx.sql`: repositories over `ctx.postgres` from
38
40
  * `withPostgresClient`, which runs each query as the caller with RLS.
39
41
  */
40
- export declare function withBetterPostgres<M extends AnyModels, D, F extends AnyFunctions, E>(sb: BetterSupabase<M, D, F, E>): Middleware<"sql", void, SupabaseAuthContext & {
42
+ export declare function withBetterPostgres<M extends AnyModels, D, F extends AnyFunctions, E>(betterSupabase: BetterSupabase<M, D, F, E>): Middleware<"sql", void, SupabaseAuthContext & {
41
43
  readonly postgres: PostgresApi;
42
44
  }, Db<M, F, E, undefined>>;
43
45
  //#endregion
@@ -64,4 +66,4 @@ export declare function checkSession(sql: SessionLookup, auth: {
64
66
  readonly kind: string;
65
67
  }): Promise<DbError | undefined>;
66
68
  //#endregion
67
- export { AUTH_CACHE_HEADERS, type Aal, type ActClaim, type AmrEntry, type AuthKind, type AuthResolution, type AuthResolver, type AuthSession, type AuthState, type BetterServer, type ContextOptions, type CookieOptions, type CookieRecord, type CookieWrite, type DeleteAccountOptions, type DeleteAccountResult, type GuardOptions, type ImpersonationOptions, type Impersonator, type InvalidReason, PRIMARY_COOKIE, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, type ProblemDetails, type ProblemOptions, type ProblemResponseOptions, type RefreshOutcome, type ReplicaState, type ResolveAuthOptions, type ResolvedState, type ResourceHandler, type ResourceInput, type ResourceList, type ResourcePagination, type ResourceRouteOptions, type RespondOptions, type ServerContext, type ServerOptions, type SessionActor, type SessionDelegation, type SessionLookup, type Settled, type StoredSession, type SupabaseAuthContext, aalOf, amrOf, authContext, checkAal, clientIp, createServer, defineResource, fromProblem, guard, impersonatorOf, isProblem, isResult, problemResponse, readSession, refreshSession, resolveAuth, respond, sessionCookieName, settle, toProblem, toSession, writeSession };
69
+ export { AUTH_CACHE_HEADERS, type Aal, type ActClaim, type ActiveSupport, type AmrEntry, type AuthKind, type AuthResolution, type AuthResolver, type AuthSession, type AuthState, type BetterServer, type ContextOptions, type CookieOptions, type CookieRecord, type CookieWrite, type DeleteAccountOptions, type DeleteAccountResult, type GuardOptions, type ImpersonationOptions, type Impersonator, type InvalidReason, type MiddlewareOptions, PRIMARY_COOKIE, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, type ProblemDetails, type ProblemOptions, type ProblemResponseOptions, type RefreshOutcome, type ReplicaState, type ResolveAuthOptions, type ResolvedState, type ResourceHandler, type ResourceInput, type ResourceList, type ResourcePagination, type ResourceRouteOptions, type RespondOptions, SUPPORT_COOKIE, type ServerContext, type ServerOptions, type SessionActor, type SessionDelegation, type SessionLookup, type Settled, type SqlSupportStoreOptions, type StoredSession, type SupabaseAuthContext, type SupportApi, type SupportAuthorizeInput, type SupportCallerClaims, type SupportCookieOptions, type SupportEndedBy, type SupportListFilter, type SupportOptions, type SupportPolicy, type SupportSession, type SupportSessionStore, type SupportSessions, type SupportStartInput, type SupportStartRequest, type SupportView, TENANT_HEADER, aalOf, amrOf, authContext, checkAal, clearSupportCookie, clientIp, createServer, defineResource, fromProblem, guard, impersonatorOf, isProblem, isResult, problemResponse, readSession, refreshSession, resolveAuth, respond, sessionCookieName, settle, sqlSupportStore, supportClaims, supportCookie, supportCookieValue, supportOf, supportSessions, toProblem, toSession, writeSession };
@@ -1,10 +1,12 @@
1
- import { n as dbError } from "../errors-Bl3rkOzo.js";
2
- import { a as problemResponse, i as isProblem, n as PROBLEM_TYPE_BASE, o as toProblem, r as fromProblem, t as PROBLEM_CONTENT_TYPE } from "../problem-CGt1ADix.js";
3
- import { a as settle, i as respond, n as guard, o as createServer, r as isResult, u as PRIMARY_COOKIE } from "../respond-C44EZAJo.js";
4
- import { a as clientIp, f as sessionCookieName, i as authContext, m as refreshSession, n as amrOf, o as resolveAuth, p as writeSession, r as checkAal, s as AUTH_CACHE_HEADERS, t as aalOf, u as readSession, v as impersonatorOf } from "../mfa-BxoR1RkN.js";
5
- import { n as postgresExecutor } from "../executor-C57jx2pn.js";
6
- import { t as toSession } from "../view-wZ-9qIUz.js";
7
- import { t as defineResource } from "../resource-D30rp0GN.js";
1
+ import { n as dbError } from "../errors-DtwXa6b8.js";
2
+ import { a as problemResponse, i as isProblem, n as PROBLEM_TYPE_BASE, o as toProblem, r as fromProblem, t as PROBLEM_CONTENT_TYPE } from "../problem-BW1KhzSG.js";
3
+ import { n as impersonatorOf, r as userContext } from "../impersonation-VfaGc4Q_.js";
4
+ import { t as supportOf } from "../support-view-g4YLBeqX.js";
5
+ import { c as supportCookie, d as guard, f as isResult, l as supportCookieValue, m as settle, n as createServer, o as SUPPORT_COOKIE, p as respond, s as clearSupportCookie, t as TENANT_HEADER, v as PRIMARY_COOKIE } from "../server-Csx2sRjg.js";
6
+ import { _ as writeSession, a as checkAal, d as AUTH_CACHE_HEADERS, g as sessionCookieName, i as amrOf, m as readSession, n as toSession, o as authContext, r as aalOf, s as clientIp, u as resolveAuth, v as refreshSession } from "../view-Bq64ki8-.js";
7
+ import { n as sqlSupportStore, r as supportClaims, t as supportSessions } from "../support-Dk6vdmEw.js";
8
+ import { n as postgresExecutor } from "../executor-XycESQPH.js";
9
+ import { t as defineResource } from "../resource-CRxxwkQq.js";
8
10
  import { defineMiddleware } from "@supabase/middleware";
9
11
  //#region src/server/middleware.ts
10
12
  /** Repository context from a `@supabase/server` context. */
@@ -12,15 +14,7 @@ function contextFromSupabase(ctx) {
12
14
  switch (ctx.authMode) {
13
15
  case "user":
14
16
  if (!ctx.userClaims) break;
15
- return {
16
- actor: {
17
- id: ctx.userClaims.id,
18
- kind: "user",
19
- ...ctx.userClaims.role === void 0 ? {} : { role: ctx.userClaims.role },
20
- ...ctx.userClaims.email === void 0 ? {} : { email: ctx.userClaims.email }
21
- },
22
- claims: ctx.jwtClaims ?? {}
23
- };
17
+ return userContext(ctx.userClaims, ctx.jwtClaims ?? {});
24
18
  case "secret": return {
25
19
  actor: {
26
20
  id: "service",
@@ -50,23 +44,23 @@ function contextFromSupabase(ctx) {
50
44
  * `ctx.supabase` (the caller-scoped client from `withSupabase`).
51
45
  *
52
46
  * ```ts
53
- * pipeline([withSupabase({ auth: 'user' }), withBetterSupabase(sb)()], (req, ctx) => ...)
47
+ * pipeline([withSupabase({ auth: 'user' }), withBetterSupabase(betterSupabase)()], (req, ctx) => ...)
54
48
  * ```
55
49
  */
56
- function withBetterSupabase(sb) {
50
+ function withBetterSupabase(betterSupabase) {
57
51
  return defineMiddleware({
58
52
  key: "db",
59
- run: (_config) => (_req, ctx) => Promise.resolve({ db: sb.connect(ctx.supabase, contextFromSupabase(ctx)) })
53
+ run: (_config) => (_req, ctx) => Promise.resolve({ db: betterSupabase.connect(ctx.supabase, contextFromSupabase(ctx)) })
60
54
  });
61
55
  }
62
56
  /**
63
57
  * Entry contributing `ctx.sql`: repositories over `ctx.postgres` from
64
58
  * `withPostgresClient`, which runs each query as the caller with RLS.
65
59
  */
66
- function withBetterPostgres(sb) {
60
+ function withBetterPostgres(betterSupabase) {
67
61
  return defineMiddleware({
68
62
  key: "sql",
69
- run: (_config) => (_req, ctx) => Promise.resolve({ sql: sb.connect(postgresExecutor(ctx.postgres), contextFromSupabase(ctx)) })
63
+ run: (_config) => (_req, ctx) => Promise.resolve({ sql: betterSupabase.connect(postgresExecutor(ctx.postgres), contextFromSupabase(ctx)) })
70
64
  });
71
65
  }
72
66
  //#endregion
@@ -94,4 +88,4 @@ async function checkSession(sql, auth) {
94
88
  return row?.active === true ? void 0 : revoked;
95
89
  }
96
90
  //#endregion
97
- export { AUTH_CACHE_HEADERS, PRIMARY_COOKIE, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, aalOf, amrOf, authContext, checkAal, checkSession, clientIp, contextFromSupabase, createServer, defineResource, fromProblem, guard, impersonatorOf, isProblem, isResult, problemResponse, readSession, refreshSession, resolveAuth, respond, sessionCookieName, settle, toProblem, toSession, withBetterPostgres, withBetterSupabase, writeSession };
91
+ export { AUTH_CACHE_HEADERS, PRIMARY_COOKIE, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, SUPPORT_COOKIE, TENANT_HEADER, aalOf, amrOf, authContext, checkAal, checkSession, clearSupportCookie, clientIp, contextFromSupabase, createServer, defineResource, fromProblem, guard, impersonatorOf, isProblem, isResult, problemResponse, readSession, refreshSession, resolveAuth, respond, sessionCookieName, settle, sqlSupportStore, supportClaims, supportCookie, supportCookieValue, supportOf, supportSessions, toProblem, toSession, withBetterPostgres, withBetterSupabase, writeSession };