better-supabase 0.4.0 → 0.5.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 (180) hide show
  1. package/README.md +135 -16
  2. package/dist/actor-DaJjqD5R.d.ts +43 -0
  3. package/dist/channel-FQW-CnGR.d.ts +70 -0
  4. package/dist/cli/bin.js +1 -1
  5. package/dist/cli/codemod-DqV7612m.js +388 -0
  6. package/dist/cli/{config-D9R0o1LH.js → config-CPVpXP5I.js} +78 -8
  7. package/dist/cli/{config-SSKSTUl2.js → config-dtoekM0v.js} +1 -1
  8. package/dist/cli/{read-sets-CMa29t9a.js → diff-SjkO5rNr.js} +1 -220
  9. package/dist/cli/{dist-CFgGknmZ.js → dist-DBPdlPYK.js} +4 -4
  10. package/dist/cli/{dist-B1MvLv-M.js → dist-DreZ24Sz.js} +1 -1
  11. package/dist/cli/{dist-Du7VnEUG.js → dist-xn4wlboc.js} +112 -1
  12. package/dist/cli/{doctor-BOym3mbL.js → doctor-C_A-KEAz.js} +533 -50
  13. package/dist/cli/{env-BZ0uy8XK.js → env-DmKv_G4A.js} +1 -1
  14. package/dist/cli/gen-CIdSQZad.js +2 -0
  15. package/dist/cli/{gen-Ccn_p90L.js → gen-CjElD1Vw.js} +321 -88
  16. package/dist/cli/index.d.ts +1 -1
  17. package/dist/cli/index.js +4 -4
  18. package/dist/cli/{init-ClnxRYBF.js → init-DMa6M7hV.js} +2 -2
  19. package/dist/cli/{introspect-DxqfkVIv.js → introspect-BKlaIu_M.js} +2 -2
  20. package/dist/cli/{openapi-8WHjxiTJ.js → openapi-Cp5Fyta-.js} +1 -1
  21. package/dist/cli/read-sets-VQcPgxU9.js +436 -0
  22. package/dist/cli/{run-CP20LKk_.js → run-Bo_NLT5n.js} +16 -12
  23. package/dist/cli/{seed-5J6eu_Xg.js → seed-CUlqWh-8.js} +1 -1
  24. package/dist/cli/sql-CVx-1O8G.js +373 -0
  25. package/dist/cli/{version-5mW_8sY1.js → version-BCtlgDQx.js} +1 -1
  26. package/dist/client/index.d.ts +1 -1
  27. package/dist/client/index.js +3 -10
  28. package/dist/clone-BfgmLU90.js +21 -0
  29. package/dist/{compiler-DB3aSFOA.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  30. package/dist/config/index.d.ts +4 -4
  31. package/dist/config/index.js +4 -4
  32. package/dist/{config-C1CYcm6o.d.ts → config-Bv7gvfzC.d.ts} +185 -11
  33. package/dist/{config-CbvFmGD8.js → config-DreERlKo.js} +1 -1
  34. package/dist/{define-CRS2MRV3.d.ts → define-Bp_BZa5h.d.ts} +11 -7
  35. package/dist/{define-Bh0AqTik.js → define-cNKzqwL_.js} +202 -16
  36. package/dist/edge/index.d.ts +16 -5
  37. package/dist/edge/index.js +10 -7
  38. package/dist/{entitlements-Dm-FHpNH.d.ts → entitlements-BiJZ4t49.d.ts} +1 -1
  39. package/dist/env/index.d.ts +2 -2
  40. package/dist/env/index.js +34 -1
  41. package/dist/{errors-L0xK41y_.js → errors-DtwXa6b8.js} +1 -0
  42. package/dist/events/index.d.ts +3 -2
  43. package/dist/events/index.js +65 -12
  44. package/dist/events-aIO7vsIk.d.ts +230 -0
  45. package/dist/{result-CqEsbgYs.d.ts → executor-BunPOO-k.d.ts} +200 -1
  46. package/dist/{executor-CZ7ImRiD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  47. package/dist/{executor-CVt6dD0B.js → executor-XycESQPH.js} +3 -3
  48. package/dist/hono/index.d.ts +17 -6
  49. package/dist/hono/index.js +40 -5
  50. package/dist/impersonation-BgSHAYLf.js +133 -0
  51. package/dist/{resolve-BAqQcwMW.d.ts → impersonation-BmePsuxz.d.ts} +36 -6
  52. package/dist/{index-BhHEC04r.d.ts → index-C7f8cOBM.d.ts} +2 -2
  53. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  54. package/dist/{index-Cf-D2jk1.d.ts → index-CWMDdEr4.d.ts} +2 -2
  55. package/dist/{index-D5IfUIDh.d.ts → index-DOESKG27.d.ts} +33 -8
  56. package/dist/{index-DFmOpBGC.d.ts → index-DgILJRXj.d.ts} +35 -9
  57. package/dist/{index-RlLXd8dL.d.ts → index-DmXSxbLi.d.ts} +4 -4
  58. package/dist/{index-BBdvo-5d.d.ts → index-Dp2VDwog.d.ts} +49 -6
  59. package/dist/{index-528Ugmyp.d.ts → index-SaTsEfGP.d.ts} +76 -8
  60. package/dist/{index-BAy4tsAP.d.ts → index-fag8VJZ2.d.ts} +3 -4
  61. package/dist/index.d.ts +30 -13
  62. package/dist/index.js +10 -9
  63. package/dist/jobs/index.d.ts +147 -101
  64. package/dist/jobs/index.js +744 -237
  65. package/dist/{json-schema-DP6V7cbr.js → json-schema-m1fiwKgN.js} +22 -1
  66. package/dist/kit-events-CTFDfSwb.js +60 -0
  67. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  68. package/dist/kit-transport-DJlHQUBU.js +55 -0
  69. package/dist/{config-BpxDfnbg.js → kits-CGLLrNPd.js} +37 -9
  70. package/dist/list/index.d.ts +1 -1
  71. package/dist/{live-BHakSWWo.d.ts → live-D9W2M5aO.d.ts} +6 -5
  72. package/dist/mcp/index.d.ts +25 -8
  73. package/dist/mcp/index.js +23 -14
  74. package/dist/{mfa-C7MNQ1Ob.d.ts → mfa-Cu96oJdw.d.ts} +2 -16
  75. package/dist/next/index.d.ts +31 -10
  76. package/dist/next/index.js +136 -27
  77. package/dist/notifications/index.d.ts +162 -0
  78. package/dist/notifications/index.js +264 -0
  79. package/dist/openapi/index.d.ts +1 -1
  80. package/dist/openapi/index.js +2 -2
  81. package/dist/orgs/index.d.ts +132 -0
  82. package/dist/orgs/index.js +245 -0
  83. package/dist/orpc/index.d.ts +28 -8
  84. package/dist/orpc/index.js +16 -3
  85. package/dist/otel/index.d.ts +21 -2
  86. package/dist/otel/index.js +50 -9
  87. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  88. package/dist/permdock-sql-DgOfeixi.js +51 -0
  89. package/dist/plugin-DwARMuQp.js +59 -0
  90. package/dist/{plugin-bNhvJwRh.d.ts → plugin-o144f322.d.ts} +17 -5
  91. package/dist/plugins/actor/index.d.ts +5 -2
  92. package/dist/plugins/actor/index.js +22 -8
  93. package/dist/plugins/rules/index.d.ts +2 -2
  94. package/dist/plugins/rules/index.js +15 -10
  95. package/dist/plugins/soft-delete/index.d.ts +3 -3
  96. package/dist/plugins/soft-delete/index.js +14 -5
  97. package/dist/plugins/tenant/index.d.ts +2 -2
  98. package/dist/plugins/tenant/index.js +38 -20
  99. package/dist/plugins/timestamps/index.d.ts +1 -1
  100. package/dist/plugins/timestamps/index.js +4 -3
  101. package/dist/plugins/validation/index.d.ts +2 -2
  102. package/dist/plugins/validation/index.js +26 -6
  103. package/dist/{pool-DFwEQwmN.d.ts → pool-C9voM4Kw.d.ts} +17 -6
  104. package/dist/postgres/index.d.ts +5 -5
  105. package/dist/postgres/index.js +20 -11
  106. package/dist/{postgrest-Bc-0Xw62.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  107. package/dist/{problem-BihjPR0t.js → problem-BW1KhzSG.js} +2 -1
  108. package/dist/{problem-U8UEKccv.d.ts → problem-Blxe8S31.d.ts} +1 -1
  109. package/dist/query/index.d.ts +2 -2
  110. package/dist/query/index.js +3 -3
  111. package/dist/{query-BMMSWbI7.js → query-CCbo44lG.js} +2 -2
  112. package/dist/queue-BYUCjr59.d.ts +252 -0
  113. package/dist/react/index.d.ts +8 -7
  114. package/dist/react/index.js +4 -3
  115. package/dist/react/server.d.ts +14 -3
  116. package/dist/react/server.js +10 -2
  117. package/dist/react/session.d.ts +7 -1
  118. package/dist/react/session.js +9 -1
  119. package/dist/{react-CQHMaESR.js → react-C_s7kiNz.js} +103 -11
  120. package/dist/{read-set-FWK8qQ58.js → read-set-DQFt1N_Y.js} +22 -1
  121. package/dist/realtime/index.d.ts +3 -3
  122. package/dist/realtime/index.js +5 -4
  123. package/dist/{refresh-BwYkyNOQ.d.ts → refresh-CFPX0Qft.d.ts} +1 -1
  124. package/dist/{resource-BJcaIfxi.d.ts → resource-DNRFP7KR.d.ts} +5 -5
  125. package/dist/{resource-My_y-Syh.js → resource-mqfJW4YF.js} +22 -7
  126. package/dist/respond-BR1fJWOB.d.ts +377 -0
  127. package/dist/{result-Bj6yt33D.js → result-BKiliPY7.js} +1 -1
  128. package/dist/server/index.d.ts +15 -12
  129. package/dist/server/index.js +11 -17
  130. package/dist/{server-BA75B0mT.js → server-B1mZ7CgQ.js} +259 -37
  131. package/dist/{shared-DnoCdMDr.js → shared-D1dRUrAg.js} +16 -2
  132. package/dist/signers-Cc6r98SW.d.ts +162 -0
  133. package/dist/{simplify-Cqvfr9dj.js → simplify-_0oUKqCd.js} +4 -115
  134. package/dist/sql/index.d.ts +283 -11
  135. package/dist/sql/index.js +8705 -775
  136. package/dist/{sql-B34HU2DI.js → sql-Coh6n4cC.js} +9 -2
  137. package/dist/ssr/index.d.ts +4 -4
  138. package/dist/ssr/index.js +1 -2
  139. package/dist/{standard-BRyBGTtp.js → standard-D7r6dMUu.js} +6 -3
  140. package/dist/{standard-BsaCYQJc.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  141. package/dist/{stats-C_YxA2r1.js → stats-Bqob3WqT.js} +4 -4
  142. package/dist/storage/index.d.ts +4 -4
  143. package/dist/storage/index.js +155 -26
  144. package/dist/support-CEPwlw2G.d.ts +89 -0
  145. package/dist/support-view-B8SlToQX.d.ts +17 -0
  146. package/dist/support-view-g4YLBeqX.js +18 -0
  147. package/dist/support-wHnK6zp-.js +293 -0
  148. package/dist/{permdock-sql-C4KFzLc9.js → template-TxrGI5jR.js} +2 -31
  149. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  150. package/dist/{temporal-required-CBNHT6ni.js → temporal-required-CAt4Dc9Z.js} +2 -2
  151. package/dist/testing/index.d.ts +132 -10
  152. package/dist/testing/index.js +476 -8
  153. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  154. package/dist/user-change-CHFEUro1.js +49 -0
  155. package/dist/{webhooks-Bh_Jf_-l.js → verify-Ce49ETPz.js} +5 -5
  156. package/dist/{version-Bmf7_FzM.js → version-DOYTYwHP.js} +1 -1
  157. package/dist/{mfa-byfjruR9.js → view-Bn6HNKUe.js} +97 -98
  158. package/dist/{view-B64o81wp.d.ts → view-CbgObAeb.d.ts} +22 -31
  159. package/dist/webhooks/index.d.ts +135 -4
  160. package/dist/webhooks/index.js +588 -2
  161. package/dist/wire-D2dT86vi.js +35 -0
  162. package/package.json +27 -19
  163. package/schemas/config-v1.json +131 -1
  164. package/schemas/doctor-report-v1.json +11 -0
  165. package/skills/better-supabase/SKILL.md +9 -6
  166. package/skills/better-supabase/references/plugins.md +6 -3
  167. package/skills/better-supabase/references/troubleshooting.md +1 -0
  168. package/skills/better-supabase-api/SKILL.md +9 -2
  169. package/skills/better-supabase-api/references/adapters.md +11 -8
  170. package/skills/better-supabase-auth/SKILL.md +18 -7
  171. package/skills/better-supabase-auth/references/permdock.md +78 -11
  172. package/dist/cli/gen-D5cLCULx.js +0 -2
  173. package/dist/cli/sql-D4VbqmXi.js +0 -199
  174. package/dist/events-B21UOhvP.d.ts +0 -84
  175. package/dist/executor-B5IoUxLE.d.ts +0 -195
  176. package/dist/invalidate-CgxmRamI.js +0 -24
  177. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  178. package/dist/plugin-BqR6wKMB.js +0 -23
  179. package/dist/respond-DgIbdrt8.d.ts +0 -194
  180. package/dist/view-BrJI2LKp.js +0 -45
@@ -1,4 +1,4 @@
1
- import { r as builderFor, u as tableMeta } from "./simplify-Cqvfr9dj.js";
1
+ import { r as builderFor, s as tableMeta } from "./simplify-_0oUKqCd.js";
2
2
  import { n as touchedTables } from "./tables-Cb-3_VWc.js";
3
3
  //#region src/core/spec.ts
4
4
  const READ_METHODS = [
@@ -159,6 +159,7 @@ function defineReadSet(betterSupabase, name, options, build) {
159
159
  const entries = Object.entries(specs);
160
160
  if (entries.length === 0 || entries.length > MAX_ENTRIES) throw new TypeError(`better-supabase: read set "${name}" needs between 1 and ${MAX_ENTRIES} reads`);
161
161
  for (const [key, spec] of entries) if (!isQuerySpec(spec)) throw new TypeError(`better-supabase: read set "${name}" entry "${key}" is not a spec from betterSupabase.spec`);
162
+ warnUnscopedReads(betterSupabase, name, specs);
162
163
  return {
163
164
  kind: "read-set",
164
165
  name,
@@ -169,6 +170,26 @@ function defineReadSet(betterSupabase, name, options, build) {
169
170
  definition: betterSupabase
170
171
  };
171
172
  }
173
+ /**
174
+ * The generated function runs the reads as compiled at `gen` time, without
175
+ * the runtime's `transformQuery` plugins, so tenant and soft-delete filters
176
+ * that only those plugins add never reach it.
177
+ */
178
+ function warnUnscopedReads(betterSupabase, name, specs) {
179
+ const scoping = betterSupabase.plugins.filter((plugin) => plugin.transformQuery !== void 0 && plugin.name !== "rules").map((plugin) => plugin.name);
180
+ if (scoping.length === 0) return;
181
+ const { meta } = betterSupabase;
182
+ const tables = [...new Set(Object.values(specs).flatMap((spec) => specTables(meta, spec)))].filter((key) => {
183
+ const flags = meta.tables[key]?.flags;
184
+ return flags?.tenant !== void 0 || flags?.softDelete !== void 0;
185
+ });
186
+ if (tables.length === 0) return;
187
+ betterSupabase.events.logger.warn(`read set "${name}" reads ${tables.join(", ")}, which ${scoping.join(", ")} scope at runtime; its generated function only sees those filters when the specs spell them out (or RLS enforces them)`, {
188
+ readSet: name,
189
+ tables,
190
+ plugins: scoping
191
+ });
192
+ }
172
193
  function isReadSet(value) {
173
194
  return typeof value === "object" && value !== null && value.kind === "read-set" && typeof value.name === "string";
174
195
  }
@@ -1,5 +1,5 @@
1
- import { x as PermdockTopicPolicy } from "../types-DONv9SHN.js";
2
- import { t as PermdockCatalog } from "../permdock-sql-DImJULY-.js";
1
+ import { S as PermdockTopicPolicy } from "../types-Dnf_wRDz.js";
2
+ import { n as PermdockCatalog } from "../permdock-sql-C2Inc6Xc.js";
3
3
  import { n as TemplateValues, t as TemplateParams } from "../template-mbvlysOo.js";
4
- import { C as defineTopic, S as TriggerOptions, _ as TopicEvent, a as LiveSource, b as TopicOptions, c as liveQuery, d as RealtimeClient, f as RowChange, g as Topic, h as SubscriptionStatus, i as LiveQueryOptions, l as liveTopic, m as Subscription, n as LiveCountOptions, o as LiveSubscription, p as SubscribeOptions, r as LiveCountSeed, s as liveCount, t as CountRunner, u as EventSchemas, v as TopicHandlers, w as rowChange, x as TopicPayload, y as TopicMessage } from "../live-BHakSWWo.js";
4
+ import { C as defineTopic, S as TriggerOptions, _ as TopicEvent, a as LiveSource, b as TopicOptions, c as liveQuery, d as RealtimeClient, f as RowChange, g as Topic, h as SubscriptionStatus, i as LiveQueryOptions, l as liveTopic, m as Subscription, n as LiveCountOptions, o as LiveSubscription, p as SubscribeOptions, r as LiveCountSeed, s as liveCount, t as CountRunner, u as EventSchemas, v as TopicHandlers, w as rowChange, x as TopicPayload, y as TopicMessage } from "../live-D9W2M5aO.js";
5
5
  export { type CountRunner, type EventSchemas, type LiveCountOptions, type LiveCountSeed, type LiveQueryOptions, type LiveSource, type LiveSubscription, type PermdockCatalog, type PermdockTopicPolicy, type RealtimeClient, type RowChange, type SubscribeOptions, type Subscription, type SubscriptionStatus, type TemplateParams, type TemplateValues, type Topic, type TopicEvent, type TopicHandlers, type TopicMessage, type TopicOptions, type TopicPayload, type TriggerOptions, defineTopic, liveCount, liveQuery, liveTopic, rowChange };
@@ -1,9 +1,10 @@
1
- import { n as dbError } from "../errors-L0xK41y_.js";
2
- import { i as ok, n as err, t as AsyncResult } from "../result-Bj6yt33D.js";
1
+ import { n as dbError } from "../errors-DtwXa6b8.js";
2
+ import { i as ok, n as err, t as AsyncResult } from "../result-BKiliPY7.js";
3
3
  import { i as tenantClaimPaths } from "../claims-BAf6c7is.js";
4
4
  import { n as liveQuery, r as liveTopic, t as liveCount } from "../live-CdJBOc4f.js";
5
- import { s as toApp } from "../shared-DnoCdMDr.js";
6
- import { a as sqlIdent, i as slug, o as sqlString, r as parseTemplate, t as permdockCheck } from "../permdock-sql-C4KFzLc9.js";
5
+ import { i as sqlString, n as slug, r as sqlIdent, t as parseTemplate } from "../template-TxrGI5jR.js";
6
+ import { c as toApp } from "../shared-D1dRUrAg.js";
7
+ import { n as permdockCheck } from "../permdock-sql-DgOfeixi.js";
7
8
  import { REALTIME_SUBSCRIBE_STATES } from "@supabase/supabase-js";
8
9
  //#region src/realtime/topic.ts
9
10
  const VALUE = /^[\w.@+=-]+$/;
@@ -1,4 +1,4 @@
1
- import { m as StoredSession } from "./resolve-BAqQcwMW.js";
1
+ import { _ as StoredSession } from "./impersonation-BmePsuxz.js";
2
2
  //#region src/auth/refresh.d.ts
3
3
  interface RefreshOptions {
4
4
  readonly url: string;
@@ -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-CqEsbgYs.js";
3
- import { t as BetterSupabase, xt as SelectArg } from "./define-CRS2MRV3.js";
4
- import { i as RespondOptions } from "./respond-DgIbdrt8.js";
5
- import { i as ResourceOperation } from "./index-BhHEC04r.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-BR1fJWOB.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`. */
@@ -1,7 +1,7 @@
1
- import { n as dbError } from "./errors-L0xK41y_.js";
2
- import { i as ok, n as err } from "./result-Bj6yt33D.js";
3
- import { t as validate } from "./standard-BRyBGTtp.js";
4
- import { s as respond } from "./server-BA75B0mT.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-B1mZ7CgQ.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;
@@ -155,6 +169,7 @@ function defineResource(betterSupabase, 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")) {
@@ -0,0 +1,377 @@
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 { c as ResolveAuthOptions, i as AuthResolution, o as AuthState, t as ImpersonationOptions } from "./impersonation-BmePsuxz.js";
9
+ import { a as SupportSession, i as SupportListFilter, o as SupportSessionStore } from "./support-CEPwlw2G.js";
10
+ import { c as Bucket } from "./index-SaTsEfGP.js";
11
+ import { t as Aal } from "./mfa-Cu96oJdw.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: { kind: "impersonation", sub, 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
+ /**
314
+ * An auth kind a guard lets through. `anonymous` admits users signed in with
315
+ * `signInAnonymously()` (`is_anonymous`); `anon` admits callers without a
316
+ * session only.
317
+ */
318
+ type AllowedCaller = Exclude<AuthKind, "invalid"> | "anonymous";
319
+ interface GuardOptions {
320
+ /**
321
+ * Callers allowed through. Defaults to `['user']`, which refuses anonymous
322
+ * sign-ins. Only `'anonymous'` admits them: `['anonymous']` alone admits
323
+ * anonymous sign-ins and refuses other users, and `'anon'` (no session)
324
+ * never admits them.
325
+ */
326
+ readonly allow?: readonly AllowedCaller[];
327
+ /**
328
+ * Assurance level user sessions need. `aal2` answers 403 with
329
+ * `required: 'aal2'` until the user verifies a second factor.
330
+ */
331
+ readonly aal?: Aal;
332
+ /**
333
+ * OAuth scopes a delegated token (an OAuth client or an `act` chain) needs.
334
+ * A missing one answers 403 with `error="insufficient_scope"`. The user's
335
+ * own session is not limited by scopes.
336
+ */
337
+ readonly scopes?: readonly string[];
338
+ }
339
+ /** Guard options for middleware and fetch handlers that resolve the caller themselves. */
340
+ interface MiddlewareOptions extends GuardOptions {
341
+ /**
342
+ * Refresh an expired cookie session and send the new cookies. Only for
343
+ * routes browsers call with cookies; bearer tokens never refresh.
344
+ */
345
+ readonly refresh?: boolean;
346
+ }
347
+ /** `undefined` when `auth` may pass; otherwise the 401/403 error to send. */
348
+ declare function guard(auth: AuthState, allow?: GuardOptions["allow"], aal?: Aal, scopes?: readonly string[]): DbError | undefined;
349
+ declare function isResult(value: unknown): value is {
350
+ ok: boolean;
351
+ data: unknown;
352
+ error: unknown;
353
+ };
354
+ type Settled = {
355
+ readonly ok: true;
356
+ readonly data: unknown;
357
+ } | {
358
+ readonly ok: false;
359
+ readonly error: DbError;
360
+ };
361
+ /**
362
+ * Settles a handler's return value: `Result`s and `AsyncResult`s unwrap,
363
+ * thrown `DbException`s (or errors whose `cause` is a `DbError`) become
364
+ * errors, anything else is data. Other thrown
365
+ * errors propagate.
366
+ */
367
+ declare function settle(run: () => unknown): Promise<Settled>;
368
+ interface RespondOptions {
369
+ readonly instance?: string;
370
+ readonly expose?: boolean;
371
+ /** Status for data responses. Defaults to 200 (204 without data). */
372
+ readonly status?: number;
373
+ }
374
+ /** A handler's value as a response: `Response` as is, data as JSON, errors as Problem Details. */
375
+ declare function respond(run: () => unknown, options?: RespondOptions): Promise<Response>;
376
+ //#endregion
377
+ 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-L0xK41y_.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) {
@@ -1,14 +1,17 @@
1
- import { n as AnyModels, t as AnyFunctions } from "../types-DONv9SHN.js";
2
- import { p as DbError } from "../result-CqEsbgYs.js";
3
- import { t as BetterSupabase, y as Db } from "../define-CRS2MRV3.js";
4
- import { h as RequestContext } from "../plugin-bNhvJwRh.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-C7MNQ1Ob.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-BAqQcwMW.js";
7
- import { _ as DeleteAccountOptions, a as Settled, c as respond, d as ContextOptions, f as ServerContext, g as ReplicaState, h as PRIMARY_COOKIE, i as RespondOptions, l as settle, m as createServer, n as GuardOptions, o as guard, p as ServerOptions, r as MiddlewareOptions, s as isResult, t as AuthKind, u as BetterServer, v as DeleteAccountResult } from "../respond-DgIbdrt8.js";
8
- import { a as ResourceRouteOptions, i as ResourcePagination, n as ResourceInput, o as defineResource, r as ResourceList, t as ResourceHandler } from "../resource-BJcaIfxi.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-U8UEKccv.js";
10
- import { a as SessionDelegation, i as SessionActor, n as toSession, r as ActClaim, t as AuthSession } from "../view-B64o81wp.js";
11
- import { n as RefreshOutcome, r as refreshSession } from "../refresh-BwYkyNOQ.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 { C as writeSession, S as sessionCookieName, _ as StoredSession, a as AuthResolver, b as readSession, c as ResolveAuthOptions, d as clientIp, f as resolveAuth, g as CookieWrite, h as CookieRecord, i as AuthResolution, l as ResolvedState, m as CookieOptions, n as Impersonator, o as AuthState, p as AUTH_CACHE_HEADERS, r as impersonatorOf, s as InvalidReason, t as ImpersonationOptions, u as authContext } from "../impersonation-BmePsuxz.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-CEPwlw2G.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-BR1fJWOB.js";
8
+ import { a as checkAal, i as amrOf, n as AmrEntry, r as aalOf, t as Aal } from "../mfa-Cu96oJdw.js";
9
+ import { a as ResourceRouteOptions, i as ResourcePagination, n as ResourceInput, o as defineResource, r as ResourceList, t as ResourceHandler } from "../resource-DNRFP7KR.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 { n as SessionActor, r as SessionDelegation, t as ActClaim } from "../actor-DaJjqD5R.js";
12
+ import { n as toSession, t as AuthSession } from "../view-CbgObAeb.js";
13
+ import { n as supportOf, t as SupportView } from "../support-view-B8SlToQX.js";
14
+ import { n as RefreshOutcome, r as refreshSession } from "../refresh-CFPX0Qft.js";
12
15
  import { SupabaseClient } from "@supabase/supabase-js";
13
16
  import { Middleware } from "@supabase/middleware";
14
17
  import { AuthMode, JWTClaims, UserClaims } from "@supabase/server";
@@ -64,4 +67,4 @@ export declare function checkSession(sql: SessionLookup, auth: {
64
67
  readonly kind: string;
65
68
  }): Promise<DbError | undefined>;
66
69
  //#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, 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, 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 };
70
+ 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-L0xK41y_.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-BihjPR0t.js";
3
- import { a as guard, c as settle, o as isResult, s as respond, t as createServer, u as PRIMARY_COOKIE } from "../server-BA75B0mT.js";
4
- import { a as clientIp, c as AUTH_CACHE_HEADERS, d as readSession, h as refreshSession, i as authContext, m as writeSession, n as amrOf, p as sessionCookieName, r as checkAal, s as resolveAuth, t as aalOf, y as impersonatorOf } from "../mfa-byfjruR9.js";
5
- import { n as postgresExecutor } from "../executor-CVt6dD0B.js";
6
- import { t as toSession } from "../view-BrJI2LKp.js";
7
- import { t as defineResource } from "../resource-My_y-Syh.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-BgSHAYLf.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-B1mZ7CgQ.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-Bn6HNKUe.js";
7
+ import { n as sqlSupportStore, r as supportClaims, t as supportSessions } from "../support-wHnK6zp-.js";
8
+ import { n as postgresExecutor } from "../executor-XycESQPH.js";
9
+ import { t as defineResource } from "../resource-mqfJW4YF.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",
@@ -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 };