better-supabase 0.4.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 (179) hide show
  1. package/README.md +2 -0
  2. package/dist/channel-FQW-CnGR.d.ts +70 -0
  3. package/dist/cli/bin.js +1 -1
  4. package/dist/cli/codemod-DqV7612m.js +388 -0
  5. package/dist/cli/{config-D9R0o1LH.js → config-CPVpXP5I.js} +78 -8
  6. package/dist/cli/{config-SSKSTUl2.js → config-dtoekM0v.js} +1 -1
  7. package/dist/cli/{read-sets-CMa29t9a.js → diff-SjkO5rNr.js} +1 -220
  8. package/dist/cli/{dist-CFgGknmZ.js → dist-DBPdlPYK.js} +4 -4
  9. package/dist/cli/{dist-B1MvLv-M.js → dist-DreZ24Sz.js} +1 -1
  10. package/dist/cli/{dist-Du7VnEUG.js → dist-xn4wlboc.js} +112 -1
  11. package/dist/cli/{doctor-BOym3mbL.js → doctor-L7Z8mYTx.js} +531 -50
  12. package/dist/cli/{env-BZ0uy8XK.js → env-DmKv_G4A.js} +1 -1
  13. package/dist/cli/gen-BJc9vdyu.js +2 -0
  14. package/dist/cli/{gen-Ccn_p90L.js → gen-C2osRcr5.js} +283 -87
  15. package/dist/cli/index.d.ts +1 -1
  16. package/dist/cli/index.js +4 -4
  17. package/dist/cli/{init-ClnxRYBF.js → init-Saf5-R9T.js} +2 -2
  18. package/dist/cli/{introspect-DxqfkVIv.js → introspect--H7oGmcd.js} +2 -2
  19. package/dist/cli/{openapi-8WHjxiTJ.js → openapi-Cp5Fyta-.js} +1 -1
  20. package/dist/cli/read-sets-BfMQcKy8.js +289 -0
  21. package/dist/cli/{run-CP20LKk_.js → run-BKR2W_79.js} +16 -12
  22. package/dist/cli/{seed-5J6eu_Xg.js → seed-CUlqWh-8.js} +1 -1
  23. package/dist/cli/sql-DzPbfngx.js +348 -0
  24. package/dist/cli/{version-5mW_8sY1.js → version-BDJuO0UR.js} +1 -1
  25. package/dist/client/index.d.ts +1 -1
  26. package/dist/client/index.js +3 -10
  27. package/dist/clone-BfgmLU90.js +21 -0
  28. package/dist/{compiler-DB3aSFOA.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  29. package/dist/config/index.d.ts +4 -4
  30. package/dist/config/index.js +4 -4
  31. package/dist/{config-CbvFmGD8.js → config-DreERlKo.js} +1 -1
  32. package/dist/{config-C1CYcm6o.d.ts → config-T_ejwyd3.d.ts} +176 -11
  33. package/dist/{define-CRS2MRV3.d.ts → define-Bp_BZa5h.d.ts} +11 -7
  34. package/dist/{define-Bh0AqTik.js → define-cNKzqwL_.js} +202 -16
  35. package/dist/edge/index.d.ts +16 -5
  36. package/dist/edge/index.js +10 -7
  37. package/dist/{entitlements-Dm-FHpNH.d.ts → entitlements-DUxU4oHe.d.ts} +1 -1
  38. package/dist/env/index.d.ts +2 -2
  39. package/dist/env/index.js +34 -1
  40. package/dist/{errors-L0xK41y_.js → errors-DtwXa6b8.js} +1 -0
  41. package/dist/events/index.d.ts +3 -2
  42. package/dist/events/index.js +65 -12
  43. package/dist/events-aIO7vsIk.d.ts +230 -0
  44. package/dist/{result-CqEsbgYs.d.ts → executor-BunPOO-k.d.ts} +200 -1
  45. package/dist/{executor-CZ7ImRiD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  46. package/dist/{executor-CVt6dD0B.js → executor-XycESQPH.js} +3 -3
  47. package/dist/hono/index.d.ts +17 -6
  48. package/dist/hono/index.js +40 -5
  49. package/dist/impersonation-VfaGc4Q_.js +41 -0
  50. package/dist/{index-BBdvo-5d.d.ts → index-BGdgBPdf.d.ts} +49 -6
  51. package/dist/{index-BhHEC04r.d.ts → index-C7f8cOBM.d.ts} +2 -2
  52. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  53. package/dist/{index-D5IfUIDh.d.ts → index-DOESKG27.d.ts} +33 -8
  54. package/dist/{index-DFmOpBGC.d.ts → index-DgILJRXj.d.ts} +35 -9
  55. package/dist/{index-RlLXd8dL.d.ts → index-DmXSxbLi.d.ts} +4 -4
  56. package/dist/{index-Cf-D2jk1.d.ts → index-Dxn2a5cw.d.ts} +2 -2
  57. package/dist/{index-528Ugmyp.d.ts → index-SaTsEfGP.d.ts} +76 -8
  58. package/dist/{index-BAy4tsAP.d.ts → index-fag8VJZ2.d.ts} +3 -4
  59. package/dist/index.d.ts +30 -13
  60. package/dist/index.js +10 -9
  61. package/dist/jobs/index.d.ts +147 -101
  62. package/dist/jobs/index.js +744 -237
  63. package/dist/{json-schema-DP6V7cbr.js → json-schema-m1fiwKgN.js} +22 -1
  64. package/dist/kit-events-CTFDfSwb.js +60 -0
  65. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  66. package/dist/kit-transport-DJlHQUBU.js +55 -0
  67. package/dist/{config-BpxDfnbg.js → kits-CGLLrNPd.js} +37 -9
  68. package/dist/list/index.d.ts +1 -1
  69. package/dist/{live-BHakSWWo.d.ts → live-D9W2M5aO.d.ts} +6 -5
  70. package/dist/mcp/index.d.ts +25 -8
  71. package/dist/mcp/index.js +23 -14
  72. package/dist/{mfa-C7MNQ1Ob.d.ts → mfa-CusDgPaD.d.ts} +5 -1
  73. package/dist/next/index.d.ts +31 -10
  74. package/dist/next/index.js +136 -27
  75. package/dist/notifications/index.d.ts +162 -0
  76. package/dist/notifications/index.js +264 -0
  77. package/dist/openapi/index.d.ts +1 -1
  78. package/dist/openapi/index.js +2 -2
  79. package/dist/orgs/index.d.ts +132 -0
  80. package/dist/orgs/index.js +245 -0
  81. package/dist/orpc/index.d.ts +28 -8
  82. package/dist/orpc/index.js +16 -3
  83. package/dist/otel/index.d.ts +21 -2
  84. package/dist/otel/index.js +50 -9
  85. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  86. package/dist/permdock-sql-DgOfeixi.js +51 -0
  87. package/dist/plugin-DwARMuQp.js +59 -0
  88. package/dist/{plugin-bNhvJwRh.d.ts → plugin-o144f322.d.ts} +17 -5
  89. package/dist/plugins/actor/index.d.ts +5 -2
  90. package/dist/plugins/actor/index.js +22 -8
  91. package/dist/plugins/rules/index.d.ts +2 -2
  92. package/dist/plugins/rules/index.js +15 -10
  93. package/dist/plugins/soft-delete/index.d.ts +3 -3
  94. package/dist/plugins/soft-delete/index.js +14 -5
  95. package/dist/plugins/tenant/index.d.ts +2 -2
  96. package/dist/plugins/tenant/index.js +38 -20
  97. package/dist/plugins/timestamps/index.d.ts +1 -1
  98. package/dist/plugins/timestamps/index.js +4 -3
  99. package/dist/plugins/validation/index.d.ts +2 -2
  100. package/dist/plugins/validation/index.js +26 -6
  101. package/dist/{pool-DFwEQwmN.d.ts → pool-C9voM4Kw.d.ts} +17 -6
  102. package/dist/postgres/index.d.ts +5 -5
  103. package/dist/postgres/index.js +20 -11
  104. package/dist/{postgrest-Bc-0Xw62.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  105. package/dist/{problem-BihjPR0t.js → problem-BW1KhzSG.js} +2 -1
  106. package/dist/{problem-U8UEKccv.d.ts → problem-Blxe8S31.d.ts} +1 -1
  107. package/dist/query/index.d.ts +2 -2
  108. package/dist/query/index.js +3 -3
  109. package/dist/{query-BMMSWbI7.js → query-CCbo44lG.js} +2 -2
  110. package/dist/queue-BYUCjr59.d.ts +252 -0
  111. package/dist/react/index.d.ts +8 -7
  112. package/dist/react/index.js +4 -3
  113. package/dist/react/server.d.ts +14 -3
  114. package/dist/react/server.js +10 -2
  115. package/dist/react/session.d.ts +7 -1
  116. package/dist/react/session.js +9 -1
  117. package/dist/{react-CQHMaESR.js → react-C_s7kiNz.js} +103 -11
  118. package/dist/{read-set-FWK8qQ58.js → read-set-DQFt1N_Y.js} +22 -1
  119. package/dist/realtime/index.d.ts +3 -3
  120. package/dist/realtime/index.js +5 -4
  121. package/dist/{refresh-BwYkyNOQ.d.ts → refresh-BTrQ_ZTp.d.ts} +1 -1
  122. package/dist/{resolve-BAqQcwMW.d.ts → resolve-C15TJq77.d.ts} +11 -5
  123. package/dist/{resource-My_y-Syh.js → resource-CRxxwkQq.js} +22 -7
  124. package/dist/{resource-BJcaIfxi.d.ts → resource-D8iqWMr-.d.ts} +5 -5
  125. package/dist/respond-D2OQl62-.d.ts +371 -0
  126. package/dist/{result-Bj6yt33D.js → result-BKiliPY7.js} +1 -1
  127. package/dist/server/index.d.ts +14 -12
  128. package/dist/server/index.js +11 -17
  129. package/dist/{server-BA75B0mT.js → server-Csx2sRjg.js} +251 -34
  130. package/dist/{shared-DnoCdMDr.js → shared-D1dRUrAg.js} +16 -2
  131. package/dist/signers-Cc6r98SW.d.ts +162 -0
  132. package/dist/{simplify-Cqvfr9dj.js → simplify-_0oUKqCd.js} +4 -115
  133. package/dist/sql/index.d.ts +247 -10
  134. package/dist/sql/index.js +8590 -779
  135. package/dist/{sql-B34HU2DI.js → sql-Coh6n4cC.js} +9 -2
  136. package/dist/ssr/index.d.ts +4 -4
  137. package/dist/ssr/index.js +1 -2
  138. package/dist/{standard-BRyBGTtp.js → standard-D7r6dMUu.js} +6 -3
  139. package/dist/{standard-BsaCYQJc.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  140. package/dist/{stats-C_YxA2r1.js → stats-Bqob3WqT.js} +4 -4
  141. package/dist/storage/index.d.ts +4 -4
  142. package/dist/storage/index.js +155 -26
  143. package/dist/support-DT-OhSxD.d.ts +88 -0
  144. package/dist/support-Dk6vdmEw.js +291 -0
  145. package/dist/support-view-Da5peKFg.d.ts +17 -0
  146. package/dist/support-view-g4YLBeqX.js +18 -0
  147. package/dist/{permdock-sql-C4KFzLc9.js → template-TxrGI5jR.js} +2 -31
  148. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  149. package/dist/{temporal-required-CBNHT6ni.js → temporal-required-CAt4Dc9Z.js} +2 -2
  150. package/dist/testing/index.d.ts +100 -10
  151. package/dist/testing/index.js +336 -8
  152. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  153. package/dist/user-change-CHFEUro1.js +49 -0
  154. package/dist/{webhooks-Bh_Jf_-l.js → verify-Ce49ETPz.js} +5 -5
  155. package/dist/{version-Bmf7_FzM.js → version-DM_Roffb.js} +1 -1
  156. package/dist/{view-B64o81wp.d.ts → view-BEf0diC5.d.ts} +8 -3
  157. package/dist/{mfa-byfjruR9.js → view-Bq64ki8-.js} +95 -38
  158. package/dist/webhooks/index.d.ts +135 -4
  159. package/dist/webhooks/index.js +588 -2
  160. package/dist/wire-D2dT86vi.js +35 -0
  161. package/package.json +16 -8
  162. package/schemas/config-v1.json +131 -1
  163. package/schemas/doctor-report-v1.json +10 -0
  164. package/skills/better-supabase/SKILL.md +9 -6
  165. package/skills/better-supabase/references/plugins.md +6 -3
  166. package/skills/better-supabase/references/troubleshooting.md +1 -0
  167. package/skills/better-supabase-api/SKILL.md +9 -2
  168. package/skills/better-supabase-api/references/adapters.md +11 -8
  169. package/skills/better-supabase-auth/SKILL.md +3 -0
  170. package/skills/better-supabase-auth/references/permdock.md +56 -11
  171. package/dist/cli/gen-D5cLCULx.js +0 -2
  172. package/dist/cli/sql-D4VbqmXi.js +0 -199
  173. package/dist/events-B21UOhvP.d.ts +0 -84
  174. package/dist/executor-B5IoUxLE.d.ts +0 -195
  175. package/dist/invalidate-CgxmRamI.js +0 -24
  176. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  177. package/dist/plugin-BqR6wKMB.js +0 -23
  178. package/dist/respond-DgIbdrt8.d.ts +0 -194
  179. package/dist/view-BrJI2LKp.js +0 -45
@@ -1,28 +1,9 @@
1
- import { n as dbError } from "./errors-L0xK41y_.js";
1
+ import { n as dbError } from "./errors-DtwXa6b8.js";
2
2
  import { t as consoleLogger } from "./logger-glM28NVN.js";
3
3
  import { n as decodeJwtPayload } from "./base64-D2gsioCY.js";
4
+ import { n as impersonatorOf, r as userContext } from "./impersonation-VfaGc4Q_.js";
4
5
  import { DEFAULT_COOKIE_OPTIONS, createChunks, isChunkLike, parseCookieHeader, serializeCookieHeader, stringFromBase64URL, stringToBase64URL } from "@supabase/ssr";
5
6
  import { extractCredentials, verifyCredentials } from "@supabase/server/core";
6
- //#region src/auth/impersonation.ts
7
- /** The `act` claim for an impersonated session. */
8
- function actClaim(options) {
9
- return {
10
- sub: options.actor,
11
- reason: options.reason
12
- };
13
- }
14
- /** The impersonator in `claims.act`, or `undefined` for a normal session. */
15
- function impersonatorOf(claims) {
16
- const act = claims["act"];
17
- if (typeof act !== "object" || act === null) return void 0;
18
- const { sub, reason } = act;
19
- if (typeof sub !== "string" || sub === "") return void 0;
20
- return typeof reason === "string" ? {
21
- id: sub,
22
- reason
23
- } : { id: sub };
24
- }
25
- //#endregion
26
7
  //#region src/auth/actor.ts
27
8
  function isRecord(value) {
28
9
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -284,7 +265,7 @@ function serverEnv(options) {
284
265
  url: env.url,
285
266
  publishableKeys: { default: env.publishableKey },
286
267
  secretKeys: env.secretKeys ?? (env.secretKey ? { default: env.secretKey } : {}),
287
- jwks: options.jwks ?? env.jwksUrl
268
+ jwks: options.jwks ?? env.jwks ?? env.jwksUrl
288
269
  };
289
270
  }
290
271
  const MEMO_SIZE = 256;
@@ -295,7 +276,7 @@ let memoByJwks = /* @__PURE__ */ new WeakMap();
295
276
  * and island resolves the same token again; this skips the signature check.
296
277
  */
297
278
  function memoFor(options) {
298
- const jwks = options.jwks;
279
+ const jwks = options.jwks ?? options.env.jwks;
299
280
  if (jwks && typeof jwks === "object" && !(jwks instanceof URL)) {
300
281
  let memo = memoByJwks.get(jwks);
301
282
  if (!memo) memoByJwks.set(jwks, memo = /* @__PURE__ */ new Map());
@@ -311,6 +292,42 @@ function memoFor(options) {
311
292
  if (!memo) memoByUrl.set(key, memo = /* @__PURE__ */ new Map());
312
293
  return memo;
313
294
  }
295
+ function sameJson(a, b) {
296
+ if (a === b) return true;
297
+ if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
298
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
299
+ const left = Object.entries(a);
300
+ const right = new Map(Object.entries(b));
301
+ return left.length === right.size && left.every(([key, value]) => right.has(key) && sameJson(value, right.get(key)));
302
+ }
303
+ /**
304
+ * Records a token that `@supabase/server` verified for this request, so the
305
+ * next `resolveAuth` with these options doesn't verify it again. Only when
306
+ * `claims` is the token's own payload, it hasn't expired, and its `iss` and
307
+ * `aud` pass the checks these options would apply; otherwise returns false
308
+ * and the token is verified as usual.
309
+ */
310
+ function rememberVerified(options, verified) {
311
+ const { token, claims, user } = verified;
312
+ const now = Math.floor((options.now ?? Date.now)() / 1e3);
313
+ const expiresAt = typeof claims.exp === "number" ? claims.exp : null;
314
+ if (expiresAt === null || expiresAt <= now) return false;
315
+ if (!sameJson(decodeJwtPayload(token), claims)) return false;
316
+ const issuers = [options.issuer ?? `${options.env.url}/auth/v1`].flat();
317
+ if (typeof claims.iss !== "string" || !issuers.includes(claims.iss)) return false;
318
+ const audiences = [options.audience ?? "authenticated"].flat();
319
+ const aud = claims.aud;
320
+ const given = Array.isArray(aud) ? aud : [aud];
321
+ if (!audiences.some((audience) => given.includes(audience))) return false;
322
+ remember(memoFor(options), token, {
323
+ kind: "user",
324
+ token,
325
+ claims,
326
+ user,
327
+ expiresAt
328
+ }, expiresAt);
329
+ return true;
330
+ }
314
331
  function remembered(memo, token, now) {
315
332
  const hit = memo.get(token);
316
333
  if (!hit) return void 0;
@@ -444,7 +461,7 @@ function base64url(text) {
444
461
  * fetch it as before.
445
462
  */
446
463
  function prefetchJwks(options) {
447
- if (options.jwks !== void 0) return Promise.resolve();
464
+ if (options.jwks !== void 0 || options.env.jwks !== void 0) return Promise.resolve();
448
465
  return verifyCredentials({
449
466
  token: PREFETCH_TOKEN,
450
467
  apikey: null
@@ -546,6 +563,10 @@ async function resolveAuth(request, options) {
546
563
  token: null,
547
564
  apikey: credentials.apikey
548
565
  }, options.secret === true ? ["secret"] : options.secret.map((name) => `secret:${name}`), options, "bearer"), cookies);
566
+ if (options.cookies === false) return resolution({
567
+ kind: "anon",
568
+ reason: "none"
569
+ }, cookies);
549
570
  const name = options.cookie?.name ?? sessionCookieName(options.env.url);
550
571
  const session = readSession(cookies(), name);
551
572
  if (!session) {
@@ -611,19 +632,7 @@ async function resolveAuth(request, options) {
611
632
  /** The repository context (`actor`, `claims`) for an auth state. */
612
633
  function authContext(auth) {
613
634
  switch (auth.kind) {
614
- case "user": {
615
- const impersonator = impersonatorOf(auth.claims);
616
- return {
617
- actor: {
618
- id: auth.user.id,
619
- kind: "user",
620
- ...auth.user.role === void 0 ? {} : { role: auth.user.role },
621
- ...auth.user.email === void 0 ? {} : { email: auth.user.email },
622
- ...impersonator ? { impersonator: impersonator.id } : {}
623
- },
624
- claims: auth.claims
625
- };
626
- }
635
+ case "user": return userContext(auth.user, auth.claims);
627
636
  case "service": return {
628
637
  actor: {
629
638
  id: `service:${auth.keyName}`,
@@ -682,4 +691,52 @@ function checkAal(auth, required) {
682
691
  });
683
692
  }
684
693
  //#endregion
685
- export { delegationOf as _, clientIp as a, AUTH_CACHE_HEADERS as c, readSession as d, serializeCookie as f, actorOf as g, refreshSession as h, authContext as i, applyCookieWrites as l, writeSession as m, amrOf as n, prefetchJwks as o, sessionCookieName as p, checkAal as r, resolveAuth as s, aalOf as t, parseCookies as u, actClaim as v, impersonatorOf as y };
694
+ //#region src/auth/view.ts
695
+ /** Whether the token belongs to an anonymous user (`signInAnonymously()`). */
696
+ function isAnonymousUser(claims) {
697
+ return "is_anonymous" in claims && claims.is_anonymous === true;
698
+ }
699
+ /** Drops the token from an `AuthState`, leaving only serializable fields. */
700
+ function toSession(auth) {
701
+ switch (auth.kind) {
702
+ case "user": {
703
+ const impersonator = impersonatorOf(auth.claims);
704
+ const outcome = actorOf(auth.claims);
705
+ const actor = outcome.ok ? outcome.actor : void 0;
706
+ const scopes = actor ? delegationOf(auth.claims)?.scopes : void 0;
707
+ const delegation = actor && (scopes || actor.chain) ? {
708
+ scopes: scopes ?? [],
709
+ ...actor.chain ? { chain: actor.chain } : {}
710
+ } : void 0;
711
+ return {
712
+ kind: "user",
713
+ user: auth.user,
714
+ claims: auth.claims,
715
+ expiresAt: auth.expiresAt,
716
+ ...auth.profile === void 0 ? {} : { profile: auth.profile },
717
+ aal: aalOf(auth.claims),
718
+ anonymous: isAnonymousUser(auth.claims),
719
+ amr: amrOf(auth.claims),
720
+ ...impersonator ? { impersonator } : {},
721
+ ...actor ? { actor } : {},
722
+ ...delegation ? { delegation } : {}
723
+ };
724
+ }
725
+ case "service": return {
726
+ kind: "service",
727
+ keyName: auth.keyName
728
+ };
729
+ case "anon": return {
730
+ kind: "anon",
731
+ reason: auth.reason
732
+ };
733
+ case "invalid": return {
734
+ kind: "invalid",
735
+ reason: auth.reason,
736
+ error: auth.error
737
+ };
738
+ default: return auth;
739
+ }
740
+ }
741
+ //#endregion
742
+ export { writeSession as _, checkAal as a, delegationOf as b, prefetchJwks as c, AUTH_CACHE_HEADERS as d, applyCookieWrites as f, sessionCookieName as g, serializeCookie as h, amrOf as i, rememberVerified as l, readSession as m, toSession as n, authContext as o, parseCookies as p, aalOf as r, clientIp as s, isAnonymousUser as t, resolveAuth as u, refreshSession as v, actorOf as y };
@@ -1,7 +1,12 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { N as TableKey, O as Row, n as AnyModels, t as AnyFunctions } from "../types-DONv9SHN.js";
3
- import { o as Result } from "../result-CqEsbgYs.js";
4
- import { t as BetterSupabase } from "../define-CRS2MRV3.js";
2
+ import { P as TableKey, k as Row, n as AnyFunctions, r as AnyModels } from "../types-Dnf_wRDz.js";
3
+ import { S as ErrorMapper, a as AsyncResult, u as Result } from "../executor-BunPOO-k.js";
4
+ import { a as EventHub } from "../events-aIO7vsIk.js";
5
+ import { t as BetterSupabase } from "../define-Bp_BZa5h.js";
6
+ import { g as RequestContext } from "../plugin-o144f322.js";
7
+ import { r as EventSink } from "../index-DOESKG27.js";
8
+ import { i as sqlTransport, n as RpcClient, r as rpcTransport, t as KitTransport } from "../kit-transport-B82k1djG.js";
9
+ import { _ as PublicUrlOptions, a as hmacSigner, b as publicUrl, c as WebhookSecretStore, d as WebhookPolicyError, f as WebhookRequest, g as AllowUrl, h as fetchTransport, i as WebhookSigner, l as sqlSecretStore, m as WebhookTransport, n as StandardWebhooksOptions, o as standardWebhooks, p as WebhookResponse, r as WebhookSignInput, s as RotateSecretOptions, t as HmacSignerOptions, u as FetchTransportOptions, v as ResolveHost, y as isPublicAddress } from "../signers-Cc6r98SW.js";
5
10
  //#region src/webhooks/verify.d.ts
6
11
  interface VerifiedWebhook<T = unknown> {
7
12
  readonly id: string;
@@ -73,6 +78,8 @@ interface AuthHooks {
73
78
  readonly site_url: string;
74
79
  readonly token_new: string;
75
80
  readonly token_hash_new: string;
81
+ /** Auth adds fields over time (`old_email`, `factor_type`, ...). */
82
+ readonly [key: string]: unknown;
76
83
  };
77
84
  };
78
85
  output: Record<never, never>;
@@ -151,4 +158,128 @@ export declare function isDatabaseWebhook(value: unknown): value is DatabaseWebh
151
158
  */
152
159
  export declare function databaseChange<M extends AnyModels, D, F extends AnyFunctions, E, T extends TableKey<M>>(betterSupabase: BetterSupabase<M, D, F, E>, table: T, payload: unknown): DatabaseChange<Row<M, T>> | null;
153
160
  //#endregion
154
- export type { AuthHookError, AuthHookKind, AuthHooks, DatabaseChange, DatabaseWebhookPayload, VerifiedWebhook, VerifyOptions, WebhookInput };
161
+ //#region src/webhooks/outgoing.d.ts
162
+ /** One claimed delivery, as `shouldDeliver`, `transform` and `headers` see it. */
163
+ interface WebhookDelivery {
164
+ readonly id: string;
165
+ readonly endpointId: string;
166
+ readonly url: string;
167
+ readonly type: string;
168
+ readonly payload: unknown;
169
+ /** 1 on the first try. Counted when the delivery is claimed. */
170
+ readonly attempt: number;
171
+ readonly tenant: string | null;
172
+ readonly eventId: string | null;
173
+ readonly runId: string | null;
174
+ readonly createdAt: Temporal.Instant;
175
+ }
176
+ interface RetryPolicy {
177
+ /** Attempts before a delivery is dead-lettered. Defaults to 8. */
178
+ readonly maxAttempts?: number;
179
+ /**
180
+ * Seconds before the next attempt. Defaults to 5 seconds, 5 minutes, 30
181
+ * minutes, 2 hours, 5 hours, then 10 hours, each with full jitter. A
182
+ * receiver's `Retry-After` wins when it asks for longer, up to a day.
183
+ */
184
+ readonly backoff?: (attempt: number) => number;
185
+ /** Statuses worth retrying. Defaults to 408, 429 and 5xx; network errors always retry. */
186
+ readonly retryable?: (status: number) => boolean;
187
+ }
188
+ interface WebhooksOptions {
189
+ /** `sqlTransport(postgres.admin)` for the worker, or the user's connection to manage. */
190
+ readonly transport: KitTransport;
191
+ /** `kits.webhooks-out.schema`. Defaults to `better_supabase`. */
192
+ readonly schema?: string;
193
+ /** Defaults to `fetchTransport({ allowUrl })`. */
194
+ readonly http?: WebhookTransport;
195
+ /** Used by the default `http`. Defaults to `publicUrl()`. */
196
+ readonly allowUrl?: AllowUrl;
197
+ /** Defaults to `standardWebhooks()`. */
198
+ readonly signer?: WebhookSigner;
199
+ /** Defaults to `sqlSecretStore(transport)`. */
200
+ readonly secrets?: WebhookSecretStore;
201
+ readonly retry?: RetryPolicy;
202
+ /** Return `false` (or throw) to cancel a delivery instead of sending it. */
203
+ readonly shouldDeliver?: (delivery: WebhookDelivery) => boolean | Promise<boolean>;
204
+ /**
205
+ * The JSON body. Defaults to the Standard Webhooks envelope,
206
+ * `{ type, timestamp, data }`.
207
+ */
208
+ readonly transform?: (delivery: WebhookDelivery) => unknown;
209
+ /** Extra headers, e.g. an `idempotency-key`. */
210
+ readonly headers?: (delivery: WebhookDelivery) => Readonly<Record<string, string>>;
211
+ /** Characters of the response body kept in the log. Defaults to 2000. */
212
+ readonly responseBodyLimit?: number;
213
+ /** `betterSupabase.events`, for `webhook.*` kit events. */
214
+ readonly events?: EventHub;
215
+ readonly context?: RequestContext;
216
+ readonly errorMappers?: readonly ErrorMapper[];
217
+ }
218
+ interface PublishInput {
219
+ readonly type: string;
220
+ readonly data: unknown;
221
+ readonly tenant?: string;
222
+ /** With an id, publishing it again never queues a second delivery. */
223
+ readonly id?: string;
224
+ }
225
+ interface DispatchInput {
226
+ readonly endpointId: string;
227
+ readonly type: string;
228
+ readonly data: unknown;
229
+ /** An external run id stored with the delivery, e.g. a workflow run. */
230
+ readonly runId?: string;
231
+ readonly eventId?: string;
232
+ }
233
+ interface DeliverWebhooksOptions {
234
+ /** Deliveries per claim. Defaults to 25. */
235
+ readonly batch?: number;
236
+ /**
237
+ * Requests in flight at once. Defaults to 10, so a batch of 25 at the
238
+ * 10-second timeout finishes well inside the lease.
239
+ */
240
+ readonly concurrency?: number;
241
+ /** How long a claim holds a delivery. Defaults to `'2 minutes'`. */
242
+ readonly lease?: string;
243
+ readonly budgetMs?: number;
244
+ }
245
+ interface DeliverWebhooksResult {
246
+ readonly succeeded: number;
247
+ /** Failed attempts that will retry. */
248
+ readonly retrying: number;
249
+ /** Deliveries that ran out of attempts or can't succeed. */
250
+ readonly dead: number;
251
+ readonly canceled: number;
252
+ /** Endpoints disabled after failing for `disableAfter`. */
253
+ readonly disabled: number;
254
+ }
255
+ interface WebhooksRouteOptions extends DeliverWebhooksOptions {
256
+ readonly secret: string | undefined;
257
+ readonly onError?: (error: unknown) => void;
258
+ }
259
+ interface Webhooks {
260
+ /** Queues the event for each subscribed endpoint; returns how many. */
261
+ publish(event: PublishInput): AsyncResult<number>;
262
+ /** Sends to one endpoint outside its subscriptions; returns the delivery id. */
263
+ dispatch(input: DispatchInput): AsyncResult<string>;
264
+ /** Queues a finished delivery again. */
265
+ redeliver(deliveryId: string): AsyncResult<string>;
266
+ /** A new signing secret, returned once. */
267
+ rotateSecret(endpointId: string, options?: RotateSecretOptions): AsyncResult<string>;
268
+ /** Sends due deliveries. Run it from a cron route or a job. */
269
+ deliver(options?: DeliverWebhooksOptions): Promise<DeliverWebhooksResult>;
270
+ /** A `GET`/`POST` handler for Vercel Cron that runs `deliver` behind a bearer secret. */
271
+ deliverRoute(options: WebhooksRouteOptions): (request: Request) => Promise<Response>;
272
+ /**
273
+ * An `EventSink` that publishes CloudEvents, e.g. from the outbox relay.
274
+ * Endpoints subscribe to unprefixed types, so it removes `typePrefix`
275
+ * (`dev.better-supabase` by default, the relay's default) and the dot.
276
+ */
277
+ sink(options?: WebhookSinkOptions): EventSink;
278
+ }
279
+ interface WebhookSinkOptions {
280
+ /** The relay's `typePrefix`. */
281
+ readonly typePrefix?: string;
282
+ }
283
+ export declare function createWebhooks(options: WebhooksOptions): Webhooks;
284
+ //#endregion
285
+ export { type AllowUrl, type AuthHookError, type AuthHookKind, type AuthHooks, type DatabaseChange, type DatabaseWebhookPayload, type DeliverWebhooksOptions, type DeliverWebhooksResult, type DispatchInput, type FetchTransportOptions, type HmacSignerOptions, type KitTransport, type PublicUrlOptions, type PublishInput, type ResolveHost, type RetryPolicy, type RotateSecretOptions, type RpcClient, type StandardWebhooksOptions, type VerifiedWebhook, type VerifyOptions, type WebhookDelivery, type WebhookInput, WebhookPolicyError, type WebhookRequest, type WebhookResponse, type WebhookSecretStore, type WebhookSignInput, type WebhookSigner, type WebhookSinkOptions, type WebhookTransport, type Webhooks, type WebhooksOptions, type WebhooksRouteOptions, fetchTransport, hmacSigner, isPublicAddress, publicUrl, rpcTransport, sqlSecretStore, sqlTransport, standardWebhooks };