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,194 +0,0 @@
1
- import { n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
2
- import { p as DbError, t as AsyncResult } from "./result-CqEsbgYs.js";
3
- import { I as StatsRecorder, P as DbStats, t as BetterSupabase, y as Db } from "./define-CRS2MRV3.js";
4
- import { h as RequestContext } from "./plugin-bNhvJwRh.js";
5
- import { t as BetterSupabaseEnv } from "./index-Dy6kuF0P.js";
6
- import { o as SqlClaims, t as BetterPostgres } from "./pool-DFwEQwmN.js";
7
- import { o as ImpersonationOptions, t as Aal } from "./mfa-C7MNQ1Ob.js";
8
- import { a as ResolveAuthOptions, r as AuthState, t as AuthResolution } from "./resolve-BAqQcwMW.js";
9
- import { n as Bucket } from "./index-528Ugmyp.js";
10
- import { SupabaseClient } from "@supabase/supabase-js";
11
- //#region src/server/delete-account.d.ts
12
- interface DeleteAccountOptions {
13
- /**
14
- * Buckets to clear first. Objects whose `owner` placeholder (`{userId}`,
15
- * or `owner.param` for `owner` buckets) is the user are removed; buckets
16
- * without one are skipped.
17
- */
18
- readonly buckets?: readonly Bucket<string>[];
19
- /**
20
- * App keys of tables whose rows the database deletes or updates with the
21
- * user (`on delete cascade` or `set null` to `auth.users`). They get a
22
- * table-wide `mutation` notice, so caches drop their reads.
23
- */
24
- readonly cascades?: readonly string[];
25
- readonly context?: RequestContext;
26
- readonly signal?: AbortSignal;
27
- }
28
- interface DeleteAccountResult {
29
- readonly userId: string;
30
- /** Removed objects per bucket id. */
31
- readonly removed: Readonly<Record<string, number>>;
32
- }
33
- //#endregion
34
- //#region src/server/replicas.d.ts
35
- /** Cookie holding the epoch ms until which reads stay on the primary. */
36
- declare const PRIMARY_COOKIE = "bs-primary-until";
37
- /** Where a request context sends its reads. */
38
- interface ReplicaState {
39
- /** Reads go to the primary: this context wrote, or a recent request did. */
40
- readonly pinned: boolean;
41
- /** This context wrote through its repositories (or called `pin()`). */
42
- readonly wrote: boolean;
43
- /** Sends later reads to the primary, e.g. after a write through `$client` or `ctx.sql`. */
44
- pin(): void;
45
- }
46
- //#endregion
47
- //#region src/server/server.d.ts
48
- interface ServerOptions {
49
- /** Defaults to `loadEnv()`. */
50
- readonly env?: BetterSupabaseEnv;
51
- /** Enables `ctx.sql` and `actingAs()`. */
52
- readonly postgres?: BetterPostgres;
53
- readonly auth?: Omit<ResolveAuthOptions, "env">;
54
- /**
55
- * Fetch the JWKS when the server is created, so the first request verifies
56
- * its token without waiting for it. Applies when `env.jwksUrl` is set and
57
- * `auth.jwks` is not. Defaults to true, except under `NODE_ENV=test`.
58
- */
59
- readonly prefetchJwks?: boolean;
60
- /**
61
- * Extra headers on the caller's PostgREST requests, readable in Postgres as
62
- * `current_setting('request.headers')` (channel, request id, client IP for audit).
63
- */
64
- readonly headers?: (request: Request) => Readonly<Record<string, string>>;
65
- /**
66
- * PostgREST URL for the caller's reads: a read replica or the `<ref>-all`
67
- * load balancer. Defaults to `SUPABASE_READ_URL`; `false` reads from the
68
- * primary.
69
- */
70
- readonly readUrl?: string | false;
71
- readonly replicas?: {
72
- /** How long the next requests read from the primary after a write. Defaults to 5 s. */
73
- readonly pinMs?: number;
74
- };
75
- }
76
- interface ServerContext<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
77
- readonly auth: AuthState<C, P>;
78
- readonly resolution: AuthResolution<C, P>;
79
- /** supabase-js client scoped to the caller (RLS applies). */
80
- readonly supabase: SupabaseClient;
81
- /** Repositories over PostgREST as the caller. */
82
- readonly db: Db<M, F, E, SupabaseClient>;
83
- /** Repositories over direct Postgres as the caller, when `postgres` is configured. */
84
- readonly sql: Db<M, F, E, undefined> | undefined;
85
- /** Calls, waves, tables and time for `db` and `sql` together. */
86
- stats(): DbStats;
87
- /** Where `db` reads go, when a read URL is configured. */
88
- readonly replica: ReplicaState | undefined;
89
- }
90
- interface ContextOptions {
91
- readonly refresh?: boolean;
92
- /** Epoch ms until which `db` reads from the primary (the `bs-primary-until` cookie). */
93
- readonly pinnedUntil?: number;
94
- /** Also records this context's calls into a request-wide recorder. */
95
- readonly stats?: StatsRecorder;
96
- }
97
- interface BetterServer<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
98
- readonly env: BetterSupabaseEnv;
99
- resolve(request: Request, options?: {
100
- readonly refresh?: boolean;
101
- }): Promise<AuthResolution<C, P>>;
102
- /**
103
- * Resolves auth and binds repositories to the caller. Refreshes an expired
104
- * cookie session only with `refresh: true`; send `ctx.resolution.apply(response)`.
105
- */
106
- context(request: Request, options?: ContextOptions): Promise<ServerContext<M, F, E, C, P>>;
107
- /**
108
- * The context for a resolution from `resolve(request)`, so one resolution
109
- * can back several contexts without verifying the token again.
110
- */
111
- contextFromResolution(resolution: AuthResolution<C, P>, request: Request, options?: Omit<ContextOptions, "refresh">): ServerContext<M, F, E, C, P>;
112
- /** The context for an auth state resolved elsewhere (the proxy, a queue message). */
113
- contextFor(auth: AuthState<C, P>, options?: ContextOptions): ServerContext<M, F, E, C, P>;
114
- /** A stateless supabase-js client for an auth state, optionally with extra request headers. */
115
- supabaseFor(auth: AuthState, headers?: Readonly<Record<string, string>>): SupabaseClient;
116
- /** Repositories for an auth state (e.g. one resolved by the proxy). */
117
- dbFor(auth: AuthState, context?: RequestContext): Db<M, F, E, SupabaseClient>;
118
- /** Service-role repositories. Bypasses RLS; the actor is `service`. */
119
- admin(context?: RequestContext): Db<M, F, E, SupabaseClient>;
120
- /**
121
- * Deletes a user: their objects in `buckets`, then the Auth user, then a
122
- * `mutation` notice for `auth.users`. Needs the secret key. Access tokens
123
- * already issued stay valid until they expire.
124
- */
125
- deleteAccount(userId: string, options?: DeleteAccountOptions): AsyncResult<DeleteAccountResult>;
126
- /**
127
- * Repositories running as a user, with RLS, over direct Postgres. With
128
- * `impersonation`, the claims carry `act: { sub: actor, reason }`, which
129
- * the `audit` and `actor` SQL kit modules record.
130
- */
131
- actingAs(userId: string, claims?: Omit<SqlClaims, "sub" | "act">, impersonation?: ImpersonationOptions): Db<M, F, E, undefined>;
132
- }
133
- /**
134
- * Server-side entry point for APIs, jobs, MCP servers and framework
135
- * adapters. Holds the secrets; `betterSupabase` stays isomorphic.
136
- */
137
- 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>;
138
- //#endregion
139
- //#region src/server/respond.d.ts
140
- type AuthKind = AuthState["kind"];
141
- interface GuardOptions {
142
- /** Auth kinds allowed through. Defaults to `['user']`. */
143
- readonly allow?: readonly Exclude<AuthKind, "invalid">[];
144
- /**
145
- * Assurance level user sessions need. `aal2` answers 403 with
146
- * `required: 'aal2'` until the user verifies a second factor.
147
- */
148
- readonly aal?: Aal;
149
- /**
150
- * OAuth scopes a delegated token (an OAuth client or an `act` chain) needs.
151
- * A missing one answers 403 with `error="insufficient_scope"`. The user's
152
- * own session is not limited by scopes.
153
- */
154
- readonly scopes?: readonly string[];
155
- }
156
- /** Guard options for middleware and fetch handlers that resolve the caller themselves. */
157
- interface MiddlewareOptions extends GuardOptions {
158
- /**
159
- * Refresh an expired cookie session and send the new cookies. Only for
160
- * routes browsers call with cookies; bearer tokens never refresh.
161
- */
162
- readonly refresh?: boolean;
163
- }
164
- /** `undefined` when `auth` may pass; otherwise the 401/403 error to send. */
165
- declare function guard(auth: AuthState, allow?: GuardOptions["allow"], aal?: Aal, scopes?: readonly string[]): DbError | undefined;
166
- declare function isResult(value: unknown): value is {
167
- ok: boolean;
168
- data: unknown;
169
- error: unknown;
170
- };
171
- type Settled = {
172
- readonly ok: true;
173
- readonly data: unknown;
174
- } | {
175
- readonly ok: false;
176
- readonly error: DbError;
177
- };
178
- /**
179
- * Settles a handler's return value: `Result`s and `AsyncResult`s unwrap,
180
- * thrown `DbException`s (or errors whose `cause` is a `DbError`) become
181
- * errors, anything else is data. Other thrown
182
- * errors propagate.
183
- */
184
- declare function settle(run: () => unknown): Promise<Settled>;
185
- interface RespondOptions {
186
- readonly instance?: string;
187
- readonly expose?: boolean;
188
- /** Status for data responses. Defaults to 200 (204 without data). */
189
- readonly status?: number;
190
- }
191
- /** A handler's value as a response: `Response` as is, data as JSON, errors as Problem Details. */
192
- declare function respond(run: () => unknown, options?: RespondOptions): Promise<Response>;
193
- //#endregion
194
- export { DeleteAccountOptions as _, Settled as a, respond as c, ContextOptions as d, ServerContext as f, ReplicaState as g, PRIMARY_COOKIE as h, RespondOptions as i, settle as l, createServer as m, GuardOptions as n, guard as o, ServerOptions as p, MiddlewareOptions as r, isResult as s, AuthKind as t, BetterServer as u, DeleteAccountResult as v };
@@ -1,45 +0,0 @@
1
- import { _ as delegationOf, g as actorOf, n as amrOf, t as aalOf, y as impersonatorOf } from "./mfa-byfjruR9.js";
2
- //#region src/auth/view.ts
3
- /** Drops the token from an `AuthState`, leaving only serializable fields. */
4
- function toSession(auth) {
5
- switch (auth.kind) {
6
- case "user": {
7
- const impersonator = impersonatorOf(auth.claims);
8
- const outcome = actorOf(auth.claims);
9
- const actor = outcome.ok ? outcome.actor : void 0;
10
- const scopes = actor ? delegationOf(auth.claims)?.scopes : void 0;
11
- const delegation = actor && (scopes || actor.chain) ? {
12
- scopes: scopes ?? [],
13
- ...actor.chain ? { chain: actor.chain } : {}
14
- } : void 0;
15
- return {
16
- kind: "user",
17
- user: auth.user,
18
- claims: auth.claims,
19
- expiresAt: auth.expiresAt,
20
- ...auth.profile === void 0 ? {} : { profile: auth.profile },
21
- aal: aalOf(auth.claims),
22
- amr: amrOf(auth.claims),
23
- ...impersonator ? { impersonator } : {},
24
- ...actor ? { actor } : {},
25
- ...delegation ? { delegation } : {}
26
- };
27
- }
28
- case "service": return {
29
- kind: "service",
30
- keyName: auth.keyName
31
- };
32
- case "anon": return {
33
- kind: "anon",
34
- reason: auth.reason
35
- };
36
- case "invalid": return {
37
- kind: "invalid",
38
- reason: auth.reason,
39
- error: auth.error
40
- };
41
- default: return auth;
42
- }
43
- }
44
- //#endregion
45
- export { toSession as t };