better-supabase 0.5.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 (62) hide show
  1. package/README.md +133 -16
  2. package/dist/actor-DaJjqD5R.d.ts +43 -0
  3. package/dist/cli/bin.js +1 -1
  4. package/dist/cli/{doctor-L7Z8mYTx.js → doctor-C_A-KEAz.js} +6 -4
  5. package/dist/cli/gen-CIdSQZad.js +2 -0
  6. package/dist/cli/{gen-C2osRcr5.js → gen-CjElD1Vw.js} +72 -35
  7. package/dist/cli/index.d.ts +1 -1
  8. package/dist/cli/index.js +3 -3
  9. package/dist/cli/{init-Saf5-R9T.js → init-DMa6M7hV.js} +1 -1
  10. package/dist/cli/{introspect--H7oGmcd.js → introspect-BKlaIu_M.js} +1 -1
  11. package/dist/cli/{read-sets-BfMQcKy8.js → read-sets-VQcPgxU9.js} +173 -26
  12. package/dist/cli/{run-BKR2W_79.js → run-Bo_NLT5n.js} +7 -7
  13. package/dist/cli/{sql-DzPbfngx.js → sql-CVx-1O8G.js} +30 -5
  14. package/dist/cli/{version-BDJuO0UR.js → version-BCtlgDQx.js} +1 -1
  15. package/dist/client/index.js +1 -1
  16. package/dist/config/index.d.ts +2 -2
  17. package/dist/{config-T_ejwyd3.d.ts → config-Bv7gvfzC.d.ts} +10 -1
  18. package/dist/edge/index.d.ts +2 -2
  19. package/dist/edge/index.js +2 -2
  20. package/dist/{entitlements-DUxU4oHe.d.ts → entitlements-BiJZ4t49.d.ts} +1 -1
  21. package/dist/hono/index.d.ts +3 -3
  22. package/dist/hono/index.js +2 -2
  23. package/dist/impersonation-BgSHAYLf.js +133 -0
  24. package/dist/{resolve-C15TJq77.d.ts → impersonation-BmePsuxz.d.ts} +25 -1
  25. package/dist/{index-Dxn2a5cw.d.ts → index-CWMDdEr4.d.ts} +1 -1
  26. package/dist/{index-BGdgBPdf.d.ts → index-Dp2VDwog.d.ts} +1 -1
  27. package/dist/mcp/index.d.ts +2 -2
  28. package/dist/mcp/index.js +2 -2
  29. package/dist/{mfa-CusDgPaD.d.ts → mfa-Cu96oJdw.d.ts} +1 -19
  30. package/dist/next/index.d.ts +6 -6
  31. package/dist/next/index.js +3 -3
  32. package/dist/orpc/index.d.ts +2 -2
  33. package/dist/orpc/index.js +1 -1
  34. package/dist/otel/index.js +5 -5
  35. package/dist/react/index.d.ts +5 -5
  36. package/dist/react/server.d.ts +5 -5
  37. package/dist/react/session.d.ts +2 -2
  38. package/dist/{refresh-BTrQ_ZTp.d.ts → refresh-CFPX0Qft.d.ts} +1 -1
  39. package/dist/{resource-D8iqWMr-.d.ts → resource-DNRFP7KR.d.ts} +1 -1
  40. package/dist/{resource-CRxxwkQq.js → resource-mqfJW4YF.js} +1 -1
  41. package/dist/{respond-D2OQl62-.d.ts → respond-BR1fJWOB.d.ts} +12 -6
  42. package/dist/server/index.d.ts +9 -8
  43. package/dist/server/index.js +5 -5
  44. package/dist/{server-Csx2sRjg.js → server-B1mZ7CgQ.js} +11 -6
  45. package/dist/sql/index.d.ts +38 -3
  46. package/dist/sql/index.js +237 -118
  47. package/dist/ssr/index.d.ts +4 -4
  48. package/dist/ssr/index.js +1 -1
  49. package/dist/{support-DT-OhSxD.d.ts → support-CEPwlw2G.d.ts} +2 -1
  50. package/dist/{support-view-Da5peKFg.d.ts → support-view-B8SlToQX.d.ts} +1 -1
  51. package/dist/{support-Dk6vdmEw.js → support-wHnK6zp-.js} +4 -2
  52. package/dist/testing/index.d.ts +36 -4
  53. package/dist/testing/index.js +141 -1
  54. package/dist/{version-DM_Roffb.js → version-DOYTYwHP.js} +1 -1
  55. package/dist/{view-Bq64ki8-.js → view-Bn6HNKUe.js} +7 -65
  56. package/dist/{view-BEf0diC5.d.ts → view-CbgObAeb.d.ts} +17 -31
  57. package/package.json +13 -13
  58. package/schemas/doctor-report-v1.json +1 -0
  59. package/skills/better-supabase-auth/SKILL.md +15 -7
  60. package/skills/better-supabase-auth/references/permdock.md +22 -0
  61. package/dist/cli/gen-BJc9vdyu.js +0 -2
  62. package/dist/impersonation-VfaGc4Q_.js +0 -41
@@ -1,5 +1,5 @@
1
1
  import { c as ClaimsMeta, j as SchemaMeta } from "./types-Dnf_wRDz.js";
2
- import { d as Generator } from "./config-T_ejwyd3.js";
2
+ import { d as Generator } from "./config-Bv7gvfzC.js";
3
3
  //#region src/core/claims.d.ts
4
4
  declare const DEFAULT_CLAIMS: ClaimsMeta;
5
5
  /** Where the active tenant is read from: the top-level claim, then `app_metadata`. */
@@ -2,7 +2,7 @@ import { _ as DbError } from "./executor-BunPOO-k.js";
2
2
  import { Z as QuerySpec } from "./define-Bp_BZa5h.js";
3
3
  import { i as ClientAuth, t as AuthSnapshot } from "./index-DmXSxbLi.js";
4
4
  import { n as TemplateValues } from "./template-mbvlysOo.js";
5
- import { t as AuthSession } from "./view-BEf0diC5.js";
5
+ import { t as AuthSession } from "./view-CbgObAeb.js";
6
6
  import { a as LiveSource, g as Topic, h as SubscriptionStatus, p as SubscribeOptions, r as LiveCountSeed, u as EventSchemas, v as TopicHandlers, y as TopicMessage } from "./live-D9W2M5aO.js";
7
7
  import { SupabaseClient } from "@supabase/supabase-js";
8
8
  import { ReactNode } from "react";
@@ -1,8 +1,8 @@
1
1
  import { P as TableKey, n as AnyFunctions, r as AnyModels } from "../types-Dnf_wRDz.js";
2
2
  import { t as BetterSupabase } from "../define-Bp_BZa5h.js";
3
- import { f as ServerContext, n as GuardOptions, p as ServerOptions, u as BetterServer } from "../respond-D2OQl62-.js";
3
+ import { f as ServerContext, n as GuardOptions, p as ServerOptions, u as BetterServer } from "../respond-BR1fJWOB.js";
4
4
  import { i as ResourceOperation } from "../index-C7f8cOBM.js";
5
- import { a as ResourceRouteOptions } from "../resource-D8iqWMr-.js";
5
+ import { a as ResourceRouteOptions } from "../resource-DNRFP7KR.js";
6
6
  import { StandardSchemaV1 } from "@standard-schema/spec";
7
7
  //#region src/mcp/mcp.d.ts
8
8
  export declare const MCP_PROTOCOL_VERSION: string;
package/dist/mcp/index.js CHANGED
@@ -4,8 +4,8 @@ import { t as validate } from "../standard-D7r6dMUu.js";
4
4
  import { a as problemResponse, o as toProblem } from "../problem-BW1KhzSG.js";
5
5
  import { t as SPEC_PINS } from "../spec-pins-C3oc-Tdp.js";
6
6
  import { t as buildJsonSchema } from "../json-schema-m1fiwKgN.js";
7
- import { a as withExtra, d as guard, g as jsonResponse, h as jsonReplacer, m as settle, n as createServer, r as extendServer, u as defaultExpose } from "../server-Csx2sRjg.js";
8
- import { t as defineResource } from "../resource-CRxxwkQq.js";
7
+ import { a as withExtra, d as guard, g as jsonResponse, h as jsonReplacer, m as settle, n as createServer, r as extendServer, u as defaultExpose } from "../server-B1mZ7CgQ.js";
8
+ import { t as defineResource } from "../resource-mqfJW4YF.js";
9
9
  import { fromSupabaseUrl, unauthorizedResponse } from "@supabase/server/oauth-protected-resource";
10
10
  //#region src/mcp/mcp.ts
11
11
  const MCP_PROTOCOL_VERSION = SPEC_PINS.mcp;
@@ -1,22 +1,4 @@
1
1
  import { _ as DbError } from "./executor-BunPOO-k.js";
2
- //#region src/auth/impersonation.d.ts
3
- /** The admin acting as the user, from the RFC 8693 `act` claim. */
4
- interface Impersonator {
5
- readonly id: string;
6
- readonly reason?: string;
7
- /** The support session, when the admin started one (`act.session_id`). */
8
- readonly sessionId?: string;
9
- /** Whether the support session blocks writes (`act.read_only`). */
10
- readonly readOnly?: boolean;
11
- }
12
- /** `actingAs(userId, claims, { actor, reason })`: who acts, and why (recorded by the audit module). */
13
- interface ImpersonationOptions {
14
- readonly actor: string;
15
- readonly reason: string;
16
- }
17
- /** The impersonator in `claims.act`, or `undefined` for a normal session. */
18
- declare function impersonatorOf(claims: Readonly<Record<string, unknown>>): Impersonator | undefined;
19
- //#endregion
20
2
  //#region src/auth/mfa.d.ts
21
3
  /** Authenticator assurance level: `aal2` once a second factor is verified in this session. */
22
4
  type Aal = "aal1" | "aal2";
@@ -45,4 +27,4 @@ declare function checkAal(auth: {
45
27
  readonly kind: string;
46
28
  }, required: Aal): DbError | undefined;
47
29
  //#endregion
48
- export { checkAal as a, impersonatorOf as c, amrOf as i, AmrEntry as n, ImpersonationOptions as o, aalOf as r, Impersonator as s, Aal as t };
30
+ export { checkAal as a, amrOf as i, AmrEntry as n, aalOf as r, Aal as t };
@@ -1,13 +1,13 @@
1
1
  import { n as AnyFunctions, r as AnyModels } from "../types-Dnf_wRDz.js";
2
2
  import { _ as DbError } from "../executor-BunPOO-k.js";
3
3
  import { B as ReadSet, P as DbStats, Z as QuerySpec, l as CacheAdapter, t as BetterSupabase } from "../define-Bp_BZa5h.js";
4
- import { r as AuthState } from "../resolve-C15TJq77.js";
5
- import { C as SupportOptions, D as supportSessions, E as SupportStartRequest, T as SupportSessions, b as ActiveSupport, d as ContextOptions, f as ServerContext, n as GuardOptions, p as ServerOptions, t as AuthKind, u as BetterServer, w as SupportPolicy } from "../respond-D2OQl62-.js";
6
- import { n as AmrEntry, s as Impersonator, t as Aal } from "../mfa-CusDgPaD.js";
7
- import { n as toSession, t as AuthSession } from "../view-BEf0diC5.js";
4
+ import { n as Impersonator, o as AuthState } from "../impersonation-BmePsuxz.js";
5
+ import { C as SupportOptions, D as supportSessions, E as SupportStartRequest, T as SupportSessions, b as ActiveSupport, d as ContextOptions, f as ServerContext, n as GuardOptions, p as ServerOptions, t as AuthKind, u as BetterServer, w as SupportPolicy } from "../respond-BR1fJWOB.js";
6
+ import { n as AmrEntry, t as Aal } from "../mfa-Cu96oJdw.js";
7
+ import { n as toSession, t as AuthSession } from "../view-CbgObAeb.js";
8
8
  import { r as LiveCountSeed, t as CountRunner } from "../live-D9W2M5aO.js";
9
- import { n as supportOf, t as SupportView } from "../support-view-Da5peKFg.js";
10
- import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-DUxU4oHe.js";
9
+ import { n as supportOf, t as SupportView } from "../support-view-B8SlToQX.js";
10
+ import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-BiJZ4t49.js";
11
11
  import { NextRequest } from "next/server.js";
12
12
  import { StandardSchemaV1 } from "@standard-schema/spec";
13
13
  //#region src/next/collector.d.ts
@@ -6,9 +6,9 @@ import { a as problemResponse } from "../problem-BW1KhzSG.js";
6
6
  import { t as isList } from "../guards-BnzDvFrz.js";
7
7
  import { t as supportOf } from "../support-view-g4YLBeqX.js";
8
8
  import { t as hasEntitlement } from "../entitlements-CTEBm7IB.js";
9
- import { a as withExtra, b as withPrimaryPin, d as guard, m as settle, n as createServer, p as respond, r as extendServer, u as defaultExpose, v as PRIMARY_COOKIE, y as primaryCookieOptions } from "../server-Csx2sRjg.js";
10
- import { a as checkAal, n as toSession } from "../view-Bq64ki8-.js";
11
- import { t as supportSessions } from "../support-Dk6vdmEw.js";
9
+ import { a as withExtra, b as withPrimaryPin, d as guard, m as settle, n as createServer, p as respond, r as extendServer, u as defaultExpose, v as PRIMARY_COOKIE, y as primaryCookieOptions } from "../server-B1mZ7CgQ.js";
10
+ import { a as checkAal, n as toSession } from "../view-Bn6HNKUe.js";
11
+ import { t as supportSessions } from "../support-wHnK6zp-.js";
12
12
  import { cache } from "react";
13
13
  import { cacheLife, cacheTag, revalidateTag, updateTag } from "next/cache.js";
14
14
  import { cookies, headers } from "next/headers.js";
@@ -1,8 +1,8 @@
1
1
  import { n as AnyFunctions, r as AnyModels } from "../types-Dnf_wRDz.js";
2
2
  import { _ as DbError, u as Result } from "../executor-BunPOO-k.js";
3
3
  import { t as BetterSupabase } from "../define-Bp_BZa5h.js";
4
- import { r as AuthState } from "../resolve-C15TJq77.js";
5
- import { f as ServerContext, n as GuardOptions, p as ServerOptions, r as MiddlewareOptions, u as BetterServer } from "../respond-D2OQl62-.js";
4
+ import { o as AuthState } from "../impersonation-BmePsuxz.js";
5
+ import { f as ServerContext, n as GuardOptions, p as ServerOptions, r as MiddlewareOptions, u as BetterServer } from "../respond-BR1fJWOB.js";
6
6
  import { r as ProblemDetails } from "../problem-Blxe8S31.js";
7
7
  import { DecoratedMiddleware, ORPCError } from "@orpc/server";
8
8
  //#region src/orpc/index.d.ts
@@ -1,6 +1,6 @@
1
1
  import { r as dbErrorOf } from "../errors-DtwXa6b8.js";
2
2
  import { o as toProblem } from "../problem-BW1KhzSG.js";
3
- import { d as guard, m as settle, n as createServer, r as extendServer, u as defaultExpose } from "../server-Csx2sRjg.js";
3
+ import { d as guard, m as settle, n as createServer, r as extendServer, u as defaultExpose } from "../server-B1mZ7CgQ.js";
4
4
  import { COMMON_ERROR_STATUS_MAP, ORPCError, os } from "@orpc/server";
5
5
  //#region src/orpc/index.ts
6
6
  const CODES = /* @__PURE__ */ new Map(Object.entries(COMMON_ERROR_STATUS_MAP).map(([code, status]) => [status, code]));
@@ -1,7 +1,7 @@
1
1
  import { r as definePlugin } from "../plugin-DwARMuQp.js";
2
2
  import { t as SPEC_PINS } from "../spec-pins-C3oc-Tdp.js";
3
3
  import { r as kitEventAttributes } from "../kit-events-CTFDfSwb.js";
4
- import "../version-DM_Roffb.js";
4
+ import "../version-DOYTYwHP.js";
5
5
  import { SpanKind, SpanStatusCode, context, metrics, propagation, trace } from "@opentelemetry/api";
6
6
  //#region src/otel/index.ts
7
7
  const INSTRUMENTATION_NAME = "better-supabase";
@@ -40,9 +40,9 @@ function systemOf(executor) {
40
40
  * ```
41
41
  */
42
42
  function otel(options = {}) {
43
- const tracer = options.tracer ?? trace.getTracer("better-supabase", "0.5.0");
43
+ const tracer = options.tracer ?? trace.getTracer("better-supabase", "0.5.1");
44
44
  let histogram;
45
- if (options.metrics !== false) histogram = (options.meter ?? metrics.getMeter("better-supabase", "0.5.0")).createHistogram("db.client.operation.duration", {
45
+ if (options.metrics !== false) histogram = (options.meter ?? metrics.getMeter("better-supabase", "0.5.1")).createHistogram("db.client.operation.duration", {
46
46
  unit: "s",
47
47
  description: "Duration of database client operations.",
48
48
  advice: { explicitBucketBoundaries: [
@@ -151,7 +151,7 @@ function otel(options = {}) {
151
151
  * Returns a function that stops listening.
152
152
  */
153
153
  function traceAuth(betterSupabase, options = {}) {
154
- const tracer = options.tracer ?? trace.getTracer("better-supabase", "0.5.0");
154
+ const tracer = options.tracer ?? trace.getTracer("better-supabase", "0.5.1");
155
155
  const offAuth = betterSupabase.events.on("auth", (event) => {
156
156
  const span = tracer.startSpan("auth.resolve", {
157
157
  kind: SpanKind.INTERNAL,
@@ -189,7 +189,7 @@ function traceAuth(betterSupabase, options = {}) {
189
189
  * set an error status. Returns a function that stops listening.
190
190
  */
191
191
  function traceKitEvents(betterSupabase, options = {}) {
192
- const tracer = options.tracer ?? trace.getTracer("better-supabase", "0.5.0");
192
+ const tracer = options.tracer ?? trace.getTracer("better-supabase", "0.5.1");
193
193
  return betterSupabase.events.on("kit", (event) => {
194
194
  const attributes = {
195
195
  ...options.attributes,
@@ -1,8 +1,8 @@
1
- import { s as Impersonator } from "../mfa-CusDgPaD.js";
2
- import { t as AuthSession } from "../view-BEf0diC5.js";
1
+ import { n as Impersonator } from "../impersonation-BmePsuxz.js";
2
+ import { t as AuthSession } from "../view-CbgObAeb.js";
3
3
  import { r as LiveCountSeed } from "../live-D9W2M5aO.js";
4
- import { n as supportOf, t as SupportView } from "../support-view-Da5peKFg.js";
5
- import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-DUxU4oHe.js";
6
- import { _ as useBroadcast, a as BetterHooks, b as useSupabase, c as BroadcastOptions, d as LiveCount, f as LiveCountHookOptions, g as useAuth, h as createHooks, i as useNotifications, l as ClaimsOf, m as ProfileOf, n as NotificationsState, o as BetterSupabaseProvider, p as LiveQueryHookOptions, r as UseNotificationsOptions, s as BetterSupabaseProviderProps, t as NotificationSource, u as ClientLike, v as useLiveCount, y as useLiveQuery } from "../index-BGdgBPdf.js";
4
+ import { n as supportOf, t as SupportView } from "../support-view-B8SlToQX.js";
5
+ import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-BiJZ4t49.js";
6
+ import { _ as useBroadcast, a as BetterHooks, b as useSupabase, c as BroadcastOptions, d as LiveCount, f as LiveCountHookOptions, g as useAuth, h as createHooks, i as useNotifications, l as ClaimsOf, m as ProfileOf, n as NotificationsState, o as BetterSupabaseProvider, p as LiveQueryHookOptions, r as UseNotificationsOptions, s as BetterSupabaseProviderProps, t as NotificationSource, u as ClientLike, v as useLiveCount, y as useLiveQuery } from "../index-Dp2VDwog.js";
7
7
  import { SessionProvider, SessionProviderProps, useSession, useSupportSession } from "./session.js";
8
8
  export { type AuthSession, type BetterHooks, BetterSupabaseProvider, type BetterSupabaseProviderProps, type BroadcastOptions, type ClaimsOf, type ClientLike, type EntitlementKey, type Impersonator, type LiveCount, type LiveCountHookOptions, type LiveCountSeed, type LiveQueryHookOptions, type MembershipClaim, type NotificationSource, type NotificationsState, type ProfileOf, SessionProvider, type SessionProviderProps, type SupportView, type UseNotificationsOptions, createHooks, hasEntitlement, supportOf, useAuth, useBroadcast, useLiveCount, useLiveQuery, useNotifications, useSession, useSupabase, useSupportSession };
@@ -1,10 +1,10 @@
1
1
  import { Z as QuerySpec } from "../define-Bp_BZa5h.js";
2
- import { s as Impersonator } from "../mfa-CusDgPaD.js";
3
- import { t as AuthSession } from "../view-BEf0diC5.js";
2
+ import { n as Impersonator } from "../impersonation-BmePsuxz.js";
3
+ import { t as AuthSession } from "../view-CbgObAeb.js";
4
4
  import { r as LiveCountSeed } from "../live-D9W2M5aO.js";
5
- import { n as supportOf, t as SupportView } from "../support-view-Da5peKFg.js";
6
- import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-DUxU4oHe.js";
7
- import { _ as useBroadcast, a as BetterHooks, b as useSupabase, c as BroadcastOptions, d as LiveCount, f as LiveCountHookOptions, g as useAuth, l as ClaimsOf, m as ProfileOf, n as NotificationsState, o as BetterSupabaseProvider, p as LiveQueryHookOptions, r as UseNotificationsOptions, s as BetterSupabaseProviderProps, t as NotificationSource, u as ClientLike, y as useLiveQuery } from "../index-BGdgBPdf.js";
5
+ import { n as supportOf, t as SupportView } from "../support-view-B8SlToQX.js";
6
+ import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-BiJZ4t49.js";
7
+ import { _ as useBroadcast, a as BetterHooks, b as useSupabase, c as BroadcastOptions, d as LiveCount, f as LiveCountHookOptions, g as useAuth, l as ClaimsOf, m as ProfileOf, n as NotificationsState, o as BetterSupabaseProvider, p as LiveQueryHookOptions, r as UseNotificationsOptions, s as BetterSupabaseProviderProps, t as NotificationSource, u as ClientLike, y as useLiveQuery } from "../index-Dp2VDwog.js";
8
8
  import { SessionProvider, SessionProviderProps } from "./session.js";
9
9
  //#region src/react/server.d.ts
10
10
  /** The `react-server` build of `useSession`: await `bs.session()` instead. */
@@ -1,5 +1,5 @@
1
- import { t as AuthSession } from "../view-BEf0diC5.js";
2
- import { t as SupportView } from "../support-view-Da5peKFg.js";
1
+ import { t as AuthSession } from "../view-CbgObAeb.js";
2
+ import { t as SupportView } from "../support-view-B8SlToQX.js";
3
3
  import { ReactNode } from "react";
4
4
  //#region src/react/session.d.ts
5
5
  export interface SessionProviderProps {
@@ -1,4 +1,4 @@
1
- import { m as StoredSession } from "./resolve-C15TJq77.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,7 +1,7 @@
1
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
2
  import { u as Result, w as ValidationIssue } from "./executor-BunPOO-k.js";
3
3
  import { t as BetterSupabase, xt as SelectArg } from "./define-Bp_BZa5h.js";
4
- import { i as RespondOptions } from "./respond-D2OQl62-.js";
4
+ import { i as RespondOptions } from "./respond-BR1fJWOB.js";
5
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
@@ -1,7 +1,7 @@
1
1
  import { n as dbError } from "./errors-DtwXa6b8.js";
2
2
  import { i as ok, n as err } from "./result-BKiliPY7.js";
3
3
  import { t as validate } from "./standard-D7r6dMUu.js";
4
- import { p as respond } from "./server-Csx2sRjg.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",
@@ -5,10 +5,10 @@ import { I as StatsRecorder, P as DbStats, t as BetterSupabase, y as Db } from "
5
5
  import { g as RequestContext } from "./plugin-o144f322.js";
6
6
  import { t as BetterSupabaseEnv } from "./index-CLg87OBW.js";
7
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";
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";
11
10
  import { c as Bucket } from "./index-SaTsEfGP.js";
11
+ import { t as Aal } from "./mfa-Cu96oJdw.js";
12
12
  import { SupabaseClient } from "@supabase/supabase-js";
13
13
  import { StandardSchemaV1 } from "@standard-schema/spec";
14
14
  //#region src/auth/support-cookie.d.ts
@@ -295,7 +295,7 @@ interface BetterServer<M extends AnyModels, F extends AnyFunctions, E, C = unkno
295
295
  deleteAccount(userId: string, options?: DeleteAccountOptions): AsyncResult<DeleteAccountResult>;
296
296
  /**
297
297
  * Repositories running as a user, with RLS, over direct Postgres. With
298
- * `impersonation`, the claims carry `act: { sub: actor, reason }`, which
298
+ * `impersonation`, the claims carry `act: { kind: "impersonation", sub, reason }`, which
299
299
  * the `audit` and `actor` SQL kit modules record.
300
300
  */
301
301
  actingAs(userId: string, claims?: Omit<SqlClaims, "sub" | "act">, impersonation?: ImpersonationOptions): Db<M, F, E, undefined>;
@@ -310,12 +310,18 @@ declare function createServer<M extends AnyModels, D, F extends AnyFunctions, E,
310
310
  //#endregion
311
311
  //#region src/server/respond.d.ts
312
312
  type AuthKind = AuthState["kind"];
313
- /** An auth kind a guard lets through; `anonymous` admits `signInAnonymously()` users. */
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
+ */
314
318
  type AllowedCaller = Exclude<AuthKind, "invalid"> | "anonymous";
315
319
  interface GuardOptions {
316
320
  /**
317
321
  * Callers allowed through. Defaults to `['user']`, which refuses anonymous
318
- * users (`is_anonymous`); add `'anonymous'` (or `'anon'`) to admit them.
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.
319
325
  */
320
326
  readonly allow?: readonly AllowedCaller[];
321
327
  /**
@@ -2,15 +2,16 @@ import { n as AnyFunctions, r as AnyModels } from "../types-Dnf_wRDz.js";
2
2
  import { _ as DbError } from "../executor-BunPOO-k.js";
3
3
  import { t as BetterSupabase, y as Db } from "../define-Bp_BZa5h.js";
4
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";
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
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";
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";
14
15
  import { SupabaseClient } from "@supabase/supabase-js";
15
16
  import { Middleware } from "@supabase/middleware";
16
17
  import { AuthMode, JWTClaims, UserClaims } from "@supabase/server";
@@ -1,12 +1,12 @@
1
1
  import { n as dbError } from "../errors-DtwXa6b8.js";
2
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";
3
+ import { n as impersonatorOf, r as userContext } from "../impersonation-BgSHAYLf.js";
4
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";
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
8
  import { n as postgresExecutor } from "../executor-XycESQPH.js";
9
- import { t as defineResource } from "../resource-CRxxwkQq.js";
9
+ import { t as defineResource } from "../resource-mqfJW4YF.js";
10
10
  import { defineMiddleware } from "@supabase/middleware";
11
11
  //#region src/server/middleware.ts
12
12
  /** Repository context from a `@supabase/server` context. */
@@ -2,9 +2,9 @@ import { n as dbError, o as isDbError, r as dbErrorOf } from "./errors-DtwXa6b8.
2
2
  import { i as ok, n as err, o as toDbError, t as AsyncResult } from "./result-BKiliPY7.js";
3
3
  import { a as postgrestExecutor, n as StatsRecorder } from "./stats-Bqob3WqT.js";
4
4
  import { a as problemResponse } from "./problem-BW1KhzSG.js";
5
- import { r as userContext, t as actClaim } from "./impersonation-VfaGc4Q_.js";
5
+ import { a as delegationOf, i as actorOf, r as userContext, t as actClaim } from "./impersonation-BgSHAYLf.js";
6
6
  import { loadEnv } from "./env/index.js";
7
- import { a as checkAal, b as delegationOf, c as prefetchJwks, l as rememberVerified, o as authContext, t as isAnonymousUser, u as resolveAuth, y as actorOf } from "./view-Bq64ki8-.js";
7
+ import { a as checkAal, c as prefetchJwks, l as rememberVerified, o as authContext, t as isAnonymousUser, u as resolveAuth } from "./view-Bn6HNKUe.js";
8
8
  import { parseCookieHeader, serializeCookieHeader } from "@supabase/ssr";
9
9
  import { createClient } from "@supabase/supabase-js";
10
10
  import { PostgrestClient } from "@supabase/postgrest-js";
@@ -178,27 +178,32 @@ function jsonResponse(data, init = {}) {
178
178
  }
179
179
  //#endregion
180
180
  //#region src/server/respond.ts
181
- /** The scopes a delegated user token lacks; empty for the user's own session. */
181
+ /**
182
+ * The scopes a delegated user token lacks. Empty for the user's own session,
183
+ * which a support or impersonated session counts as: only an `oauth-client`
184
+ * actor is limited to what the user delegated.
185
+ */
182
186
  function missingScopes(auth, required) {
183
187
  if (required.length === 0) return [];
184
188
  const outcome = actorOf(auth.claims);
185
- if (!outcome.ok || !outcome.actor) return [];
189
+ if (!outcome.ok || outcome.actor?.kind !== "oauth-client") return [];
186
190
  const granted = new Set(delegationOf(auth.claims)?.scopes);
187
191
  return required.filter((scope) => !granted.has(scope));
188
192
  }
189
193
  /** `undefined` when `auth` may pass; otherwise the 401/403 error to send. */
190
194
  function guard(auth, allow = ["user"], aal = "aal1", scopes = []) {
191
195
  if (auth.kind === "invalid") return auth.error;
192
- if (allow.includes(auth.kind)) {
196
+ const anonymous = auth.kind === "user" && isAnonymousUser(auth.claims);
197
+ if (anonymous ? allow.includes("anonymous") : allow.includes(auth.kind)) {
193
198
  const denied = checkAal(auth, aal);
194
199
  if (denied || auth.kind !== "user") return denied;
195
- if (isAnonymousUser(auth.claims) && !allow.includes("anonymous") && !allow.includes("anon")) return dbError("forbidden", "Sign up to continue", { code: "ANONYMOUS_USER" });
196
200
  const missing = missingScopes(auth, scopes);
197
201
  return missing.length > 0 ? dbError("forbidden", `The token lacks the scope ${missing.join(" ")}`, {
198
202
  code: "INSUFFICIENT_SCOPE",
199
203
  scopes
200
204
  }) : void 0;
201
205
  }
206
+ if (anonymous) return dbError("forbidden", "Sign up to continue", { code: "ANONYMOUS_USER" });
202
207
  return auth.kind === "anon" ? dbError("unauthorized", "Sign in to continue", { code: "MISSING_CREDENTIALS" }) : dbError("forbidden", `A ${auth.kind} caller is not allowed here`);
203
208
  }
204
209
  function isResult(value) {
@@ -1,6 +1,6 @@
1
1
  import { c as ClaimsMeta } from "../types-Dnf_wRDz.js";
2
2
  import { B as ReadSet } from "../define-Bp_BZa5h.js";
3
- import { b as ResolvedConfig, ct as KitsConfig, lt as ResolvedKitModule, ot as KitMode } from "../config-T_ejwyd3.js";
3
+ import { b as ResolvedConfig, ct as KitsConfig, lt as ResolvedKitModule, ot as KitMode } from "../config-Bv7gvfzC.js";
4
4
  import { a as permdockKeys, i as permdockKeyStatus, n as PermdockCatalog, r as PermdockKeyStatus, t as PERMDOCK_SCHEMA } from "../permdock-sql-C2Inc6Xc.js";
5
5
  //#region src/sql/context.d.ts
6
6
  /** The scope id types kit modules render. */
@@ -232,6 +232,8 @@ interface KitLayout {
232
232
  readonly claims?: ClaimsMeta;
233
233
  /** PermDock's helpers and membership sources, from its manifest: `entitlements` reads them instead of `tenant`. */
234
234
  readonly permdock?: KitPermdock;
235
+ /** PermDock's permission helpers for the `access` module's `permdock` model, from its manifest. */
236
+ readonly accessPermdock?: KitAccessPermdock;
235
237
  /** `config.kits`: modes, names and permission keys per module. */
236
238
  readonly kits?: KitsConfig;
237
239
  }
@@ -257,6 +259,15 @@ interface KitPermdock {
257
259
  readonly idType: KitIdType;
258
260
  readonly memberships: readonly KitMembershipSource[];
259
261
  }
262
+ /** Where the `permdock` access model finds `permitted_<scope>_ids` and `permdock_has`. */
263
+ interface KitAccessPermdock {
264
+ /** PermDock's `rls.schema`. */
265
+ readonly schema: string;
266
+ /** The PermDock scope tenants are: the manifest's root scope unless set. */
267
+ readonly scope: string;
268
+ /** The scope's id type, from the manifest's `rls.scopes[].type`. */
269
+ readonly idType: KitIdType;
270
+ }
260
271
  /** An embedding column `db.$search` can query. */
261
272
  interface VectorSearchTable {
262
273
  /** `table` or `schema.table`. */
@@ -296,6 +307,30 @@ export declare function kitFileVersion(contents: string): {
296
307
  } | undefined;
297
308
  /** A module's SQL for `layout`, without header; `undefined` in custom mode. */
298
309
  export declare function moduleBody(name: string, layout?: KitLayout): string | undefined;
310
+ /**
311
+ * The schema or test file `renderKit` writes for each of `names` and the
312
+ * modules they pull in, without rendering: modules in custom mode have none.
313
+ */
314
+ export declare function kitFilePaths(names: readonly string[], layout?: KitLayout): ReadonlyMap<string, string>;
315
+ /** A permission key a kit module checks, from `kitPermissionKeys`. */
316
+ interface KitPermissionKey {
317
+ readonly module: string;
318
+ /** The action in `kits.<module>.permissions` that overrides the key. */
319
+ readonly action: string;
320
+ readonly key: string;
321
+ /**
322
+ * `tenant` for keys checked in a tenant (`member_can`, `can`,
323
+ * `tenant_ids_with`), `platform` for `is_platform` and `platform_can`.
324
+ */
325
+ readonly scope: "tenant" | "platform";
326
+ }
327
+ /**
328
+ * Every permission key the modules `names` install (with what they pull
329
+ * in) check, after `kits.<module>.permissions` overrides. Modules in custom
330
+ * mode are skipped, and so is `invitations.invitePlatform` without platform
331
+ * roles. PermDock's doctor runs the same catalog check from its side.
332
+ */
333
+ export declare function kitPermissionKeys(kits: KitsConfig, names: readonly string[]): KitPermissionKey[];
299
334
  /**
300
335
  * The files `sql add` writes for these modules. Modules in `custom` mode
301
336
  * write nothing: the app implements their contract. A schema module's rows,
@@ -340,7 +375,7 @@ export declare function customContracts(names: readonly string[], layout?: KitLa
340
375
  //#endregion
341
376
  //#region src/sql/layout.d.ts
342
377
  /** Where and how `sql add` writes kit files for this config. */
343
- export declare function kitLayout(config: ResolvedConfig, testsDir?: string, readSets?: KitLayout["readSets"], permdock?: KitPermdock): KitLayout;
378
+ export declare function kitLayout(config: ResolvedConfig, testsDir?: string, readSets?: KitLayout["readSets"], permdock?: KitPermdock, accessPermdock?: KitAccessPermdock): KitLayout;
344
379
  //#endregion
345
380
  //#region src/sql/migration-options.d.ts
346
381
  /** A migration-only option a config sets. */
@@ -373,4 +408,4 @@ export declare function compileReadSet(set: ReadSet): Promise<CompiledReadSet>;
373
408
  /** Compiles every set, sorted by name. Throws on a duplicate name. */
374
409
  export declare function compileReadSets(sets: readonly ReadSet[]): Promise<CompiledReadSet[]>;
375
410
  //#endregion
376
- export { type CompiledReadSet, type InstalledKitModule, type KitContext, type KitContractFunction, type KitDeprecation, type KitFile, type KitIdType, type KitLayout, type KitNames, type KitPermdock, type KitTableSpec, type KitUpgrade, type KitUpgradePlan, type MigrationOptionUse, PERMDOCK_SCHEMA, type PermdockCatalog, type PermdockKeyStatus, type SqlModule, permdockKeyStatus, permdockKeys };
411
+ export { type CompiledReadSet, type InstalledKitModule, type KitAccessPermdock, type KitContext, type KitContractFunction, type KitDeprecation, type KitFile, type KitIdType, type KitLayout, type KitNames, type KitPermdock, type KitPermissionKey, type KitTableSpec, type KitUpgrade, type KitUpgradePlan, type MigrationOptionUse, PERMDOCK_SCHEMA, type PermdockCatalog, type PermdockKeyStatus, type SqlModule, permdockKeyStatus, permdockKeys };