@supabase/server 0.1.1-rc.25 → 0.1.1-rc.27

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.
package/README.md CHANGED
@@ -189,7 +189,7 @@ Extracts credentials from a Request and validates against the allow config.
189
189
  ```ts
190
190
  const { data: auth, error } = await verifyAuth(req, { allow: 'user' })
191
191
  if (error) {
192
- return Response.json({ error: error.message }, { status: error.status })
192
+ return Response.json({ message: error.message }, { status: error.status })
193
193
  }
194
194
  ```
195
195
 
@@ -246,7 +246,10 @@ export default {
246
246
  if (url.pathname === '/todos') {
247
247
  const { data: auth, error } = await verifyAuth(req, { allow: 'user' })
248
248
  if (error)
249
- return Response.json({ error: error.message }, { status: error.status })
249
+ return Response.json(
250
+ { message: error.message },
251
+ { status: error.status },
252
+ )
250
253
 
251
254
  const supabase = createContextClient(auth.token)
252
255
  const { data } = await supabase.from('todos').select()
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_create_supabase_context = require('../../create-supabase-context-DcVorGKG.cjs');
2
+ const require_create_supabase_context = require('../../create-supabase-context-BO7DGfth.cjs');
3
3
  let hono_http_exception = require("hono/http-exception");
4
4
  let hono_factory = require("hono/factory");
5
5
 
@@ -1,4 +1,4 @@
1
- import { t as createSupabaseContext } from "../../create-supabase-context-CmWaH3s6.mjs";
1
+ import { t as createSupabaseContext } from "../../create-supabase-context--JXiHT_N.mjs";
2
2
  import { HTTPException } from "hono/http-exception";
3
3
  import { createMiddleware } from "hono/factory";
4
4
 
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_verify_auth = require('../verify-auth-DvRVnjdq.cjs');
2
+ const require_verify_auth = require('../verify-auth-BjIehuNM.cjs');
3
3
 
4
4
  exports.createAdminClient = require_verify_auth.createAdminClient;
5
5
  exports.createContextClient = require_verify_auth.createContextClient;
@@ -1,3 +1,195 @@
1
- import "../types-CnKoFCMX.cjs";
2
- import { a as extractCredentials, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, t as createAdminClient } from "../create-admin-client-Cp7FxI6O.cjs";
1
+ import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "../types-CnKoFCMX.cjs";
2
+ import { i as EnvError, t as AuthError } from "../errors-O2ugIMec.cjs";
3
+ import { SupabaseClient } from "@supabase/supabase-js";
4
+
5
+ //#region src/core/resolve-env.d.ts
6
+ /**
7
+ * Resolves Supabase environment configuration from runtime environment variables.
8
+ *
9
+ * Reads `SUPABASE_URL`, keys (`SUPABASE_PUBLISHABLE_KEYS` / `SUPABASE_SECRET_KEYS`),
10
+ * and `SUPABASE_JWKS`. Works across Deno, Node.js, and Bun. For Cloudflare Workers,
11
+ * use `overrides` or enable node-compat.
12
+ *
13
+ * @param overrides - Partial values that take precedence over env vars.
14
+ * @returns `{ data: SupabaseEnv, error: null }` on success, `{ data: null, error: EnvError }` on failure.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const { data: env, error } = resolveEnv()
19
+ * if (error) throw error
20
+ *
21
+ * // Override for tests
22
+ * const { data: env } = resolveEnv({ url: 'http://localhost:54321' })
23
+ * ```
24
+ */
25
+ declare function resolveEnv(overrides?: Partial<SupabaseEnv>): {
26
+ data: SupabaseEnv;
27
+ error: null;
28
+ } | {
29
+ data: null;
30
+ error: EnvError;
31
+ };
32
+ //#endregion
33
+ //#region src/core/extract-credentials.d.ts
34
+ /**
35
+ * Extracts authentication credentials from an incoming HTTP request.
36
+ *
37
+ * Reads two headers:
38
+ * - `Authorization: Bearer <token>` → extracted as `token`
39
+ * - `apikey: <key>` → extracted as `apikey`
40
+ *
41
+ * This is a pure extraction step — no validation or verification is performed.
42
+ * Pass the result to {@link verifyCredentials} to validate against allowed auth modes.
43
+ *
44
+ * @param request - The incoming HTTP request.
45
+ * @returns The extracted {@link Credentials}. Fields are `null` when the corresponding header is absent.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { extractCredentials } from '@supabase/server/core'
50
+ *
51
+ * const creds = extractCredentials(request)
52
+ * console.log(creds.token) // "eyJhbGci..." or null
53
+ * console.log(creds.apikey) // "sb-abc123-publishable-..." or null
54
+ * ```
55
+ */
56
+ declare function extractCredentials(request: Request): Credentials;
57
+ //#endregion
58
+ //#region src/core/verify-credentials.d.ts
59
+ /**
60
+ * Options for {@link verifyCredentials}.
61
+ */
62
+ interface VerifyCredentialsOptions {
63
+ /**
64
+ * Auth mode(s) to try. Modes are attempted in order — the first match wins.
65
+ *
66
+ * @see {@link AllowWithKey} for the full syntax including named keys.
67
+ */
68
+ allow: AllowWithKey | AllowWithKey[];
69
+ /** Optional environment overrides (passed through to {@link resolveEnv}). */
70
+ env?: Partial<SupabaseEnv>;
71
+ }
72
+ /**
73
+ * Verifies pre-extracted credentials against one or more allowed auth modes.
74
+ *
75
+ * Tries each mode in order — first match wins. Use {@link verifyAuth} to extract
76
+ * and verify in a single call.
77
+ *
78
+ * @param credentials - The credentials to verify (from {@link extractCredentials}).
79
+ * @param options - Allowed auth modes and optional env overrides.
80
+ * @returns `{ data: AuthResult, error: null }` on success, `{ data: null, error: AuthError }` on failure.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const credentials = extractCredentials(request)
85
+ * const { data: auth, error } = await verifyCredentials(credentials, {
86
+ * allow: ['user', 'public'],
87
+ * })
88
+ * if (error) {
89
+ * return Response.json({ message: error.message }, { status: error.status })
90
+ * }
91
+ * ```
92
+ */
93
+ declare function verifyCredentials(credentials: Credentials, options: VerifyCredentialsOptions): Promise<{
94
+ data: AuthResult;
95
+ error: null;
96
+ } | {
97
+ data: null;
98
+ error: AuthError;
99
+ }>;
100
+ //#endregion
101
+ //#region src/core/verify-auth.d.ts
102
+ /**
103
+ * Options for {@link verifyAuth}.
104
+ */
105
+ interface VerifyAuthOptions {
106
+ /**
107
+ * Auth mode(s) to try. Modes are attempted in order — the first match wins.
108
+ *
109
+ * @see {@link AllowWithKey} for the full syntax including named keys.
110
+ */
111
+ allow: AllowWithKey | AllowWithKey[];
112
+ /** Optional environment overrides (passed through to {@link resolveEnv}). */
113
+ env?: Partial<SupabaseEnv>;
114
+ }
115
+ /**
116
+ * Extracts credentials from a request and verifies them in a single step.
117
+ *
118
+ * This is a convenience function that combines {@link extractCredentials} and
119
+ * {@link verifyCredentials}. Use it when you want the full auth flow without
120
+ * needing to inspect the raw credentials.
121
+ *
122
+ * @param request - The incoming HTTP request.
123
+ * @param options - Auth modes to accept and optional environment overrides.
124
+ *
125
+ * @returns A result tuple: `{ data, error }`.
126
+ * - On success: `{ data: AuthResult, error: null }`
127
+ * - On failure: `{ data: null, error: AuthError }`
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { verifyAuth } from '@supabase/server/core'
132
+ *
133
+ * const { data: auth, error } = await verifyAuth(request, {
134
+ * allow: 'user',
135
+ * })
136
+ *
137
+ * if (error) {
138
+ * return Response.json({ message: error.message }, { status: error.status })
139
+ * }
140
+ *
141
+ * console.log(auth.userClaims!.id) // "d0f1a2b3-..."
142
+ * ```
143
+ */
144
+ declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promise<{
145
+ data: AuthResult;
146
+ error: null;
147
+ } | {
148
+ data: null;
149
+ error: AuthError;
150
+ }>;
151
+ //#endregion
152
+ //#region src/core/create-context-client.d.ts
153
+ /**
154
+ * Creates a Supabase client scoped to the caller's context.
155
+ *
156
+ * Configured with a publishable key and (optionally) the caller's JWT,
157
+ * so Row-Level Security policies apply. Session persistence is disabled
158
+ * (stateless, one client per request).
159
+ *
160
+ * @param token - The caller's JWT, or `null` for anonymous access.
161
+ * @param env - Optional environment overrides (passed through to {@link resolveEnv}).
162
+ * @param keyName - Name of the publishable key to use. Falls back to `"default"`, then first available.
163
+ * @returns A configured {@link SupabaseClient} with RLS enforced.
164
+ * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const { data: auth } = await verifyAuth(request, { allow: 'user' })
169
+ * const supabase = createContextClient(auth.token)
170
+ * const { data } = await supabase.rpc('get_my_items')
171
+ * ```
172
+ */
173
+ declare function createContextClient<Database = unknown>(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
174
+ //#endregion
175
+ //#region src/core/create-admin-client.d.ts
176
+ /**
177
+ * Creates an admin Supabase client that bypasses Row-Level Security.
178
+ *
179
+ * Uses a secret key for authentication, giving full access to all data.
180
+ * Session persistence is disabled (stateless, one client per request).
181
+ *
182
+ * @param env - Optional environment overrides (passed through to {@link resolveEnv}).
183
+ * @param keyName - Name of the secret key to use. Falls back to `"default"`, then first available.
184
+ * @returns A configured {@link SupabaseClient} with admin (service-role) privileges.
185
+ * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const supabaseAdmin = createAdminClient()
190
+ * const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
191
+ * ```
192
+ */
193
+ declare function createAdminClient<Database = unknown>(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
194
+ //#endregion
3
195
  export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
@@ -1,3 +1,195 @@
1
- import "../types-ClmJ8pi8.mjs";
2
- import { a as extractCredentials, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, t as createAdminClient } from "../create-admin-client-ZTnl1zMe.mjs";
1
+ import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "../types-ClmJ8pi8.mjs";
2
+ import { i as EnvError, t as AuthError } from "../errors-CAH-RRA3.mjs";
3
+ import { SupabaseClient } from "@supabase/supabase-js";
4
+
5
+ //#region src/core/resolve-env.d.ts
6
+ /**
7
+ * Resolves Supabase environment configuration from runtime environment variables.
8
+ *
9
+ * Reads `SUPABASE_URL`, keys (`SUPABASE_PUBLISHABLE_KEYS` / `SUPABASE_SECRET_KEYS`),
10
+ * and `SUPABASE_JWKS`. Works across Deno, Node.js, and Bun. For Cloudflare Workers,
11
+ * use `overrides` or enable node-compat.
12
+ *
13
+ * @param overrides - Partial values that take precedence over env vars.
14
+ * @returns `{ data: SupabaseEnv, error: null }` on success, `{ data: null, error: EnvError }` on failure.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const { data: env, error } = resolveEnv()
19
+ * if (error) throw error
20
+ *
21
+ * // Override for tests
22
+ * const { data: env } = resolveEnv({ url: 'http://localhost:54321' })
23
+ * ```
24
+ */
25
+ declare function resolveEnv(overrides?: Partial<SupabaseEnv>): {
26
+ data: SupabaseEnv;
27
+ error: null;
28
+ } | {
29
+ data: null;
30
+ error: EnvError;
31
+ };
32
+ //#endregion
33
+ //#region src/core/extract-credentials.d.ts
34
+ /**
35
+ * Extracts authentication credentials from an incoming HTTP request.
36
+ *
37
+ * Reads two headers:
38
+ * - `Authorization: Bearer <token>` → extracted as `token`
39
+ * - `apikey: <key>` → extracted as `apikey`
40
+ *
41
+ * This is a pure extraction step — no validation or verification is performed.
42
+ * Pass the result to {@link verifyCredentials} to validate against allowed auth modes.
43
+ *
44
+ * @param request - The incoming HTTP request.
45
+ * @returns The extracted {@link Credentials}. Fields are `null` when the corresponding header is absent.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { extractCredentials } from '@supabase/server/core'
50
+ *
51
+ * const creds = extractCredentials(request)
52
+ * console.log(creds.token) // "eyJhbGci..." or null
53
+ * console.log(creds.apikey) // "sb-abc123-publishable-..." or null
54
+ * ```
55
+ */
56
+ declare function extractCredentials(request: Request): Credentials;
57
+ //#endregion
58
+ //#region src/core/verify-credentials.d.ts
59
+ /**
60
+ * Options for {@link verifyCredentials}.
61
+ */
62
+ interface VerifyCredentialsOptions {
63
+ /**
64
+ * Auth mode(s) to try. Modes are attempted in order — the first match wins.
65
+ *
66
+ * @see {@link AllowWithKey} for the full syntax including named keys.
67
+ */
68
+ allow: AllowWithKey | AllowWithKey[];
69
+ /** Optional environment overrides (passed through to {@link resolveEnv}). */
70
+ env?: Partial<SupabaseEnv>;
71
+ }
72
+ /**
73
+ * Verifies pre-extracted credentials against one or more allowed auth modes.
74
+ *
75
+ * Tries each mode in order — first match wins. Use {@link verifyAuth} to extract
76
+ * and verify in a single call.
77
+ *
78
+ * @param credentials - The credentials to verify (from {@link extractCredentials}).
79
+ * @param options - Allowed auth modes and optional env overrides.
80
+ * @returns `{ data: AuthResult, error: null }` on success, `{ data: null, error: AuthError }` on failure.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const credentials = extractCredentials(request)
85
+ * const { data: auth, error } = await verifyCredentials(credentials, {
86
+ * allow: ['user', 'public'],
87
+ * })
88
+ * if (error) {
89
+ * return Response.json({ message: error.message }, { status: error.status })
90
+ * }
91
+ * ```
92
+ */
93
+ declare function verifyCredentials(credentials: Credentials, options: VerifyCredentialsOptions): Promise<{
94
+ data: AuthResult;
95
+ error: null;
96
+ } | {
97
+ data: null;
98
+ error: AuthError;
99
+ }>;
100
+ //#endregion
101
+ //#region src/core/verify-auth.d.ts
102
+ /**
103
+ * Options for {@link verifyAuth}.
104
+ */
105
+ interface VerifyAuthOptions {
106
+ /**
107
+ * Auth mode(s) to try. Modes are attempted in order — the first match wins.
108
+ *
109
+ * @see {@link AllowWithKey} for the full syntax including named keys.
110
+ */
111
+ allow: AllowWithKey | AllowWithKey[];
112
+ /** Optional environment overrides (passed through to {@link resolveEnv}). */
113
+ env?: Partial<SupabaseEnv>;
114
+ }
115
+ /**
116
+ * Extracts credentials from a request and verifies them in a single step.
117
+ *
118
+ * This is a convenience function that combines {@link extractCredentials} and
119
+ * {@link verifyCredentials}. Use it when you want the full auth flow without
120
+ * needing to inspect the raw credentials.
121
+ *
122
+ * @param request - The incoming HTTP request.
123
+ * @param options - Auth modes to accept and optional environment overrides.
124
+ *
125
+ * @returns A result tuple: `{ data, error }`.
126
+ * - On success: `{ data: AuthResult, error: null }`
127
+ * - On failure: `{ data: null, error: AuthError }`
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { verifyAuth } from '@supabase/server/core'
132
+ *
133
+ * const { data: auth, error } = await verifyAuth(request, {
134
+ * allow: 'user',
135
+ * })
136
+ *
137
+ * if (error) {
138
+ * return Response.json({ message: error.message }, { status: error.status })
139
+ * }
140
+ *
141
+ * console.log(auth.userClaims!.id) // "d0f1a2b3-..."
142
+ * ```
143
+ */
144
+ declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promise<{
145
+ data: AuthResult;
146
+ error: null;
147
+ } | {
148
+ data: null;
149
+ error: AuthError;
150
+ }>;
151
+ //#endregion
152
+ //#region src/core/create-context-client.d.ts
153
+ /**
154
+ * Creates a Supabase client scoped to the caller's context.
155
+ *
156
+ * Configured with a publishable key and (optionally) the caller's JWT,
157
+ * so Row-Level Security policies apply. Session persistence is disabled
158
+ * (stateless, one client per request).
159
+ *
160
+ * @param token - The caller's JWT, or `null` for anonymous access.
161
+ * @param env - Optional environment overrides (passed through to {@link resolveEnv}).
162
+ * @param keyName - Name of the publishable key to use. Falls back to `"default"`, then first available.
163
+ * @returns A configured {@link SupabaseClient} with RLS enforced.
164
+ * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const { data: auth } = await verifyAuth(request, { allow: 'user' })
169
+ * const supabase = createContextClient(auth.token)
170
+ * const { data } = await supabase.rpc('get_my_items')
171
+ * ```
172
+ */
173
+ declare function createContextClient<Database = unknown>(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
174
+ //#endregion
175
+ //#region src/core/create-admin-client.d.ts
176
+ /**
177
+ * Creates an admin Supabase client that bypasses Row-Level Security.
178
+ *
179
+ * Uses a secret key for authentication, giving full access to all data.
180
+ * Session persistence is disabled (stateless, one client per request).
181
+ *
182
+ * @param env - Optional environment overrides (passed through to {@link resolveEnv}).
183
+ * @param keyName - Name of the secret key to use. Falls back to `"default"`, then first available.
184
+ * @returns A configured {@link SupabaseClient} with admin (service-role) privileges.
185
+ * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const supabaseAdmin = createAdminClient()
190
+ * const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
191
+ * ```
192
+ */
193
+ declare function createAdminClient<Database = unknown>(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
194
+ //#endregion
3
195
  export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
@@ -1,3 +1,3 @@
1
- import { a as createAdminClient, i as createContextClient, n as verifyCredentials, o as resolveEnv, r as extractCredentials, t as verifyAuth } from "../verify-auth-2S7zFfR-.mjs";
1
+ import { a as createAdminClient, i as createContextClient, n as verifyCredentials, o as resolveEnv, r as extractCredentials, t as verifyAuth } from "../verify-auth-mePXRNu9.mjs";
2
2
 
3
3
  export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
@@ -1,4 +1,4 @@
1
- import { a as createAdminClient, c as EnvError, i as createContextClient, s as AuthError, t as verifyAuth } from "./verify-auth-2S7zFfR-.mjs";
1
+ import { a as createAdminClient, f as Errors, i as createContextClient, l as CreateSupabaseClientError, s as AuthError, t as verifyAuth, u as EnvError } from "./verify-auth-mePXRNu9.mjs";
2
2
 
3
3
  //#region src/create-supabase-context.ts
4
4
  /**
@@ -16,7 +16,7 @@ import { a as createAdminClient, c as EnvError, i as createContextClient, s as A
16
16
  * ```ts
17
17
  * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
18
18
  * if (error) {
19
- * return Response.json({ error: error.message }, { status: error.status })
19
+ * return Response.json({ message: error.message }, { status: error.status })
20
20
  * }
21
21
  * const { data } = await ctx.supabase.rpc('get_my_items')
22
22
  * ```
@@ -46,7 +46,7 @@ async function createSupabaseContext(request, options) {
46
46
  } catch (e) {
47
47
  return {
48
48
  data: null,
49
- error: e instanceof EnvError ? new AuthError(e.message, e.code, 500) : new AuthError("Failed to create Supabase client", "CLIENT_ERROR", 500)
49
+ error: e instanceof EnvError ? new AuthError(e.message, e.code, 500) : Errors[CreateSupabaseClientError]()
50
50
  };
51
51
  }
52
52
  }
@@ -1,4 +1,4 @@
1
- const require_verify_auth = require('./verify-auth-DvRVnjdq.cjs');
1
+ const require_verify_auth = require('./verify-auth-BjIehuNM.cjs');
2
2
 
3
3
  //#region src/create-supabase-context.ts
4
4
  /**
@@ -16,7 +16,7 @@ const require_verify_auth = require('./verify-auth-DvRVnjdq.cjs');
16
16
  * ```ts
17
17
  * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
18
18
  * if (error) {
19
- * return Response.json({ error: error.message }, { status: error.status })
19
+ * return Response.json({ message: error.message }, { status: error.status })
20
20
  * }
21
21
  * const { data } = await ctx.supabase.rpc('get_my_items')
22
22
  * ```
@@ -46,7 +46,7 @@ async function createSupabaseContext(request, options) {
46
46
  } catch (e) {
47
47
  return {
48
48
  data: null,
49
- error: e instanceof require_verify_auth.EnvError ? new require_verify_auth.AuthError(e.message, e.code, 500) : new require_verify_auth.AuthError("Failed to create Supabase client", "CLIENT_ERROR", 500)
49
+ error: e instanceof require_verify_auth.EnvError ? new require_verify_auth.AuthError(e.message, e.code, 500) : require_verify_auth.Errors[require_verify_auth.CreateSupabaseClientError]()
50
50
  };
51
51
  }
52
52
  }
@@ -0,0 +1,109 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Thrown when a required environment variable is missing or malformed.
4
+ *
5
+ * Always has `status: 500` — environment errors are server-side configuration issues.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { EnvError } from '@supabase/server'
10
+ *
11
+ * try {
12
+ * const client = createAdminClient()
13
+ * } catch (e) {
14
+ * if (e instanceof EnvError) {
15
+ * console.error(`Config issue [${e.code}]: ${e.message}`)
16
+ * // → "Config issue [MISSING_SUPABASE_URL]: SUPABASE_URL is required but not set"
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ declare class EnvError extends Error {
22
+ /** Always `500` — environment errors are server-side issues. */
23
+ readonly status = 500;
24
+ /**
25
+ * Machine-readable error code.
26
+ *
27
+ * @see {@link EnvGenericError}, {@link MissingSupabaseURLError},
28
+ * {@link MissingPublishableKeyError}, {@link MissingDefaultPublishableKeyError},
29
+ * {@link MissingSecretKeyError}, {@link MissingDefaultSecretKeyError}
30
+ */
31
+ readonly code: string;
32
+ constructor(message: string, code?: string);
33
+ }
34
+ /** Generic environment error code. */
35
+ declare const EnvGenericError = "ENV_ERROR";
36
+ /** `SUPABASE_URL` is not set. */
37
+ declare const MissingSupabaseURLError = "MISSING_SUPABASE_URL";
38
+ /** Named publishable key not found in `SUPABASE_PUBLISHABLE_KEYS`. */
39
+ declare const MissingPublishableKeyError = "MISSING_PUBLISHABLE_KEY";
40
+ /** No default publishable key found. */
41
+ declare const MissingDefaultPublishableKeyError = "MISSING_DEFAULT_PUBLISHABLE_KEY";
42
+ /** Named secret key not found in `SUPABASE_SECRET_KEYS`. */
43
+ declare const MissingSecretKeyError = "MISSING_SECRET_KEY";
44
+ /** No default secret key found. */
45
+ declare const MissingDefaultSecretKeyError = "MISSING_DEFAULT_SECRET_KEY";
46
+ /**
47
+ * Thrown when authentication or authorization fails.
48
+ *
49
+ * Carries an HTTP `status` code suitable for returning directly in a response
50
+ * (typically `401` for invalid credentials, `500` for server-side auth failures).
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { AuthError, createSupabaseContext } from '@supabase/server'
55
+ *
56
+ * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
57
+ * if (error) {
58
+ * // error is an AuthError
59
+ * return Response.json(
60
+ * { message: error.message, code: error.code },
61
+ * { status: error.status },
62
+ * )
63
+ * }
64
+ * ```
65
+ */
66
+ declare class AuthError extends Error {
67
+ /**
68
+ * HTTP status code.
69
+ *
70
+ * - `401` — Invalid or missing credentials
71
+ * - `500` — Server-side auth failure (e.g., missing JWKS, env misconfiguration)
72
+ */
73
+ readonly status: number;
74
+ /**
75
+ * Machine-readable error code.
76
+ *
77
+ * @see {@link AuthGenericError}, {@link InvalidCredentialsError},
78
+ * {@link CreateSupabaseClientError}
79
+ */
80
+ readonly code: string;
81
+ constructor(message: string, code?: string, status?: number);
82
+ }
83
+ /** Generic authentication error code. */
84
+ declare const AuthGenericError = "AUTH_ERROR";
85
+ /** No credential matched any allowed auth mode. */
86
+ declare const InvalidCredentialsError = "INVALID_CREDENTIALS";
87
+ /** Failed to create a Supabase client after auth succeeded. */
88
+ declare const CreateSupabaseClientError = "CREATE_SUPABASE_CLIENT_ERROR";
89
+ /**
90
+ * Factory map for all error types. Keyed by error code constant, each entry
91
+ * returns a pre-configured {@link EnvError} or {@link AuthError}.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * throw Errors[MissingSupabaseURLError]()
96
+ * throw Errors[MissingPublishableKeyError]('mobile')
97
+ * ```
98
+ */
99
+ declare const Errors: {
100
+ INVALID_CREDENTIALS: () => AuthError;
101
+ CREATE_SUPABASE_CLIENT_ERROR: () => AuthError;
102
+ MISSING_SUPABASE_URL: () => EnvError;
103
+ MISSING_SECRET_KEY: (name: string) => EnvError;
104
+ MISSING_DEFAULT_SECRET_KEY: () => EnvError;
105
+ MISSING_PUBLISHABLE_KEY: (name: string) => EnvError;
106
+ MISSING_DEFAULT_PUBLISHABLE_KEY: () => EnvError;
107
+ };
108
+ //#endregion
109
+ export { EnvGenericError as a, MissingDefaultPublishableKeyError as c, MissingSecretKeyError as d, MissingSupabaseURLError as f, EnvError as i, MissingDefaultSecretKeyError as l, AuthGenericError as n, Errors as o, CreateSupabaseClientError as r, InvalidCredentialsError as s, AuthError as t, MissingPublishableKeyError as u };