@supabase/server 0.1.1-rc.26 → 0.1.1-rc.28

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-DDIAxA8h.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 { l as WithSupabaseConfig, o as SupabaseContext } from "../../types-CnKoFCMX.cjs";
1
+ import { f as WithSupabaseConfig, l as SupabaseContext } from "../../types-X7xYi2LN.cjs";
2
2
  import * as hono_types0 from "hono/types";
3
3
 
4
4
  //#region src/adapters/hono/middleware.d.ts
@@ -1,4 +1,4 @@
1
- import { l as WithSupabaseConfig, o as SupabaseContext } from "../../types-ClmJ8pi8.mjs";
1
+ import { f as WithSupabaseConfig, l as SupabaseContext } from "../../types-BmWSIuH7.mjs";
2
2
  import * as hono_types0 from "hono/types";
3
3
 
4
4
  //#region src/adapters/hono/middleware.d.ts
@@ -1,4 +1,4 @@
1
- import { t as createSupabaseContext } from "../../create-supabase-context-CmWaH3s6.mjs";
1
+ import { t as createSupabaseContext } from "../../create-supabase-context-Bmwyha9p.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-DrgvEuKo.cjs');
3
3
 
4
4
  exports.createAdminClient = require_verify_auth.createAdminClient;
5
5
  exports.createContextClient = require_verify_auth.createContextClient;
@@ -1,5 +1,5 @@
1
- import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "../types-CnKoFCMX.cjs";
2
- import { n as EnvError, t as AuthError } from "../errors-BmSsOAvx.cjs";
1
+ import { a as CreateAdminClientOptions, i as ClientAuth, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, u as SupabaseEnv } from "../types-X7xYi2LN.cjs";
2
+ import { i as EnvError, t as AuthError } from "../errors-O2ugIMec.cjs";
3
3
  import { SupabaseClient } from "@supabase/supabase-js";
4
4
 
5
5
  //#region src/core/resolve-env.d.ts
@@ -86,7 +86,7 @@ interface VerifyCredentialsOptions {
86
86
  * allow: ['user', 'public'],
87
87
  * })
88
88
  * if (error) {
89
- * return Response.json({ error: error.message }, { status: error.status })
89
+ * return Response.json({ message: error.message }, { status: error.status })
90
90
  * }
91
91
  * ```
92
92
  */
@@ -135,7 +135,7 @@ interface VerifyAuthOptions {
135
135
  * })
136
136
  *
137
137
  * if (error) {
138
- * return Response.json({ error: error.message }, { status: error.status })
138
+ * return Response.json({ message: error.message }, { status: error.status })
139
139
  * }
140
140
  *
141
141
  * console.log(auth.userClaims!.id) // "d0f1a2b3-..."
@@ -154,34 +154,28 @@ declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promi
154
154
  * Creates a Supabase client scoped to the caller's context.
155
155
  *
156
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).
157
+ * so Row-Level Security policies apply. Stateless one client per request.
159
158
  *
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
159
  * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
165
160
  *
166
161
  * @example
167
162
  * ```ts
168
163
  * const { data: auth } = await verifyAuth(request, { allow: 'user' })
169
- * const supabase = createContextClient(auth.token)
164
+ * const supabase = createContextClient({
165
+ * auth: { token: auth.token, keyName: auth.keyName },
166
+ * })
170
167
  * const { data } = await supabase.rpc('get_my_items')
171
168
  * ```
172
169
  */
173
- declare function createContextClient<Database = unknown>(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
170
+ declare function createContextClient<Database = unknown>(options?: CreateContextClientOptions): SupabaseClient<Database>;
174
171
  //#endregion
175
172
  //#region src/core/create-admin-client.d.ts
176
173
  /**
177
174
  * Creates an admin Supabase client that bypasses Row-Level Security.
178
175
  *
179
176
  * Uses a secret key for authentication, giving full access to all data.
180
- * Session persistence is disabled (stateless, one client per request).
177
+ * Stateless one client per request.
181
178
  *
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
179
  * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
186
180
  *
187
181
  * @example
@@ -190,6 +184,6 @@ declare function createContextClient<Database = unknown>(token?: string | null,
190
184
  * const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
191
185
  * ```
192
186
  */
193
- declare function createAdminClient<Database = unknown>(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
187
+ declare function createAdminClient<Database = unknown>(options?: CreateAdminClientOptions): SupabaseClient<Database>;
194
188
  //#endregion
195
- export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
189
+ export { type ClientAuth, type CreateAdminClientOptions, type CreateContextClientOptions, createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
@@ -1,5 +1,5 @@
1
- import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "../types-ClmJ8pi8.mjs";
2
- import { n as EnvError, t as AuthError } from "../errors-5ivL23qo.mjs";
1
+ import { a as CreateAdminClientOptions, i as ClientAuth, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, u as SupabaseEnv } from "../types-BmWSIuH7.mjs";
2
+ import { i as EnvError, t as AuthError } from "../errors-CAH-RRA3.mjs";
3
3
  import { SupabaseClient } from "@supabase/supabase-js";
4
4
 
5
5
  //#region src/core/resolve-env.d.ts
@@ -86,7 +86,7 @@ interface VerifyCredentialsOptions {
86
86
  * allow: ['user', 'public'],
87
87
  * })
88
88
  * if (error) {
89
- * return Response.json({ error: error.message }, { status: error.status })
89
+ * return Response.json({ message: error.message }, { status: error.status })
90
90
  * }
91
91
  * ```
92
92
  */
@@ -135,7 +135,7 @@ interface VerifyAuthOptions {
135
135
  * })
136
136
  *
137
137
  * if (error) {
138
- * return Response.json({ error: error.message }, { status: error.status })
138
+ * return Response.json({ message: error.message }, { status: error.status })
139
139
  * }
140
140
  *
141
141
  * console.log(auth.userClaims!.id) // "d0f1a2b3-..."
@@ -154,34 +154,28 @@ declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promi
154
154
  * Creates a Supabase client scoped to the caller's context.
155
155
  *
156
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).
157
+ * so Row-Level Security policies apply. Stateless one client per request.
159
158
  *
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
159
  * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
165
160
  *
166
161
  * @example
167
162
  * ```ts
168
163
  * const { data: auth } = await verifyAuth(request, { allow: 'user' })
169
- * const supabase = createContextClient(auth.token)
164
+ * const supabase = createContextClient({
165
+ * auth: { token: auth.token, keyName: auth.keyName },
166
+ * })
170
167
  * const { data } = await supabase.rpc('get_my_items')
171
168
  * ```
172
169
  */
173
- declare function createContextClient<Database = unknown>(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
170
+ declare function createContextClient<Database = unknown>(options?: CreateContextClientOptions): SupabaseClient<Database>;
174
171
  //#endregion
175
172
  //#region src/core/create-admin-client.d.ts
176
173
  /**
177
174
  * Creates an admin Supabase client that bypasses Row-Level Security.
178
175
  *
179
176
  * Uses a secret key for authentication, giving full access to all data.
180
- * Session persistence is disabled (stateless, one client per request).
177
+ * Stateless one client per request.
181
178
  *
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
179
  * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
186
180
  *
187
181
  * @example
@@ -190,6 +184,6 @@ declare function createContextClient<Database = unknown>(token?: string | null,
190
184
  * const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
191
185
  * ```
192
186
  */
193
- declare function createAdminClient<Database = unknown>(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient<Database>;
187
+ declare function createAdminClient<Database = unknown>(options?: CreateAdminClientOptions): SupabaseClient<Database>;
194
188
  //#endregion
195
- export { createAdminClient, createContextClient, extractCredentials, resolveEnv, verifyAuth, verifyCredentials };
189
+ export { type ClientAuth, type CreateAdminClientOptions, type CreateContextClientOptions, 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-Bt2uGltH.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-Bt2uGltH.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
  * ```
@@ -31,12 +31,23 @@ async function createSupabaseContext(request, options) {
31
31
  error
32
32
  };
33
33
  try {
34
- const supabase = createContextClient(auth.token, options?.env, auth.keyName);
35
- const adminKeyName = auth.authType === "secret" ? auth.keyName : void 0;
34
+ const config = {
35
+ env: options?.env,
36
+ supabaseOptions: options?.supabaseOptions
37
+ };
36
38
  return {
37
39
  data: {
38
- supabase,
39
- supabaseAdmin: createAdminClient(options?.env, adminKeyName),
40
+ supabase: createContextClient({
41
+ auth: {
42
+ token: auth.token,
43
+ keyName: auth.keyName
44
+ },
45
+ ...config
46
+ }),
47
+ supabaseAdmin: createAdminClient({
48
+ auth: { keyName: auth.authType === "secret" ? auth.keyName : void 0 },
49
+ ...config
50
+ }),
40
51
  userClaims: auth.userClaims,
41
52
  claims: auth.claims,
42
53
  authType: auth.authType
@@ -46,7 +57,7 @@ async function createSupabaseContext(request, options) {
46
57
  } catch (e) {
47
58
  return {
48
59
  data: null,
49
- error: e instanceof EnvError ? new AuthError(e.message, e.code, 500) : new AuthError("Failed to create Supabase client", "CLIENT_ERROR", 500)
60
+ error: e instanceof EnvError ? new AuthError(e.message, e.code, 500) : Errors[CreateSupabaseClientError]()
50
61
  };
51
62
  }
52
63
  }
@@ -1,4 +1,4 @@
1
- const require_verify_auth = require('./verify-auth-DvRVnjdq.cjs');
1
+ const require_verify_auth = require('./verify-auth-DrgvEuKo.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
  * ```
@@ -31,12 +31,23 @@ async function createSupabaseContext(request, options) {
31
31
  error
32
32
  };
33
33
  try {
34
- const supabase = require_verify_auth.createContextClient(auth.token, options?.env, auth.keyName);
35
- const adminKeyName = auth.authType === "secret" ? auth.keyName : void 0;
34
+ const config = {
35
+ env: options?.env,
36
+ supabaseOptions: options?.supabaseOptions
37
+ };
36
38
  return {
37
39
  data: {
38
- supabase,
39
- supabaseAdmin: require_verify_auth.createAdminClient(options?.env, adminKeyName),
40
+ supabase: require_verify_auth.createContextClient({
41
+ auth: {
42
+ token: auth.token,
43
+ keyName: auth.keyName
44
+ },
45
+ ...config
46
+ }),
47
+ supabaseAdmin: require_verify_auth.createAdminClient({
48
+ auth: { keyName: auth.authType === "secret" ? auth.keyName : void 0 },
49
+ ...config
50
+ }),
40
51
  userClaims: auth.userClaims,
41
52
  claims: auth.claims,
42
53
  authType: auth.authType
@@ -46,7 +57,7 @@ async function createSupabaseContext(request, options) {
46
57
  } catch (e) {
47
58
  return {
48
59
  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)
60
+ 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
61
  };
51
62
  }
52
63
  }
@@ -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 };
@@ -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 };
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_verify_auth = require('./verify-auth-DvRVnjdq.cjs');
3
- const require_create_supabase_context = require('./create-supabase-context-DcVorGKG.cjs');
2
+ const require_verify_auth = require('./verify-auth-DrgvEuKo.cjs');
3
+ const require_create_supabase_context = require('./create-supabase-context-DDIAxA8h.cjs');
4
4
  let _supabase_supabase_js_cors = require("@supabase/supabase-js/cors");
5
5
 
6
6
  //#region src/cors.ts
@@ -70,7 +70,7 @@ function withSupabase(config, handler) {
70
70
  });
71
71
  const { data: ctx, error } = await require_create_supabase_context.createSupabaseContext(req, config);
72
72
  if (error) return Response.json({
73
- error: error.message,
73
+ message: error.message,
74
74
  code: error.code
75
75
  }, {
76
76
  status: error.status,
@@ -84,6 +84,16 @@ function withSupabase(config, handler) {
84
84
 
85
85
  //#endregion
86
86
  exports.AuthError = require_verify_auth.AuthError;
87
+ exports.AuthGenericError = require_verify_auth.AuthGenericError;
88
+ exports.CreateSupabaseClientError = require_verify_auth.CreateSupabaseClientError;
87
89
  exports.EnvError = require_verify_auth.EnvError;
90
+ exports.EnvGenericError = require_verify_auth.EnvGenericError;
91
+ exports.Errors = require_verify_auth.Errors;
92
+ exports.InvalidCredentialsError = require_verify_auth.InvalidCredentialsError;
93
+ exports.MissingDefaultPublishableKeyError = require_verify_auth.MissingDefaultPublishableKeyError;
94
+ exports.MissingDefaultSecretKeyError = require_verify_auth.MissingDefaultSecretKeyError;
95
+ exports.MissingPublishableKeyError = require_verify_auth.MissingPublishableKeyError;
96
+ exports.MissingSecretKeyError = require_verify_auth.MissingSecretKeyError;
97
+ exports.MissingSupabaseURLError = require_verify_auth.MissingSupabaseURLError;
88
98
  exports.createSupabaseContext = require_create_supabase_context.createSupabaseContext;
89
99
  exports.withSupabase = withSupabase;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as JWTClaims, c as UserClaims, i as Credentials, l as WithSupabaseConfig, n as AllowWithKey, o as SupabaseContext, r as AuthResult, s as SupabaseEnv, t as Allow } from "./types-CnKoFCMX.cjs";
2
- import { n as EnvError, t as AuthError } from "./errors-BmSsOAvx.cjs";
1
+ import { a as CreateAdminClientOptions, c as JWTClaims, d as UserClaims, f as WithSupabaseConfig, i as ClientAuth, l as SupabaseContext, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, t as Allow, u as SupabaseEnv } from "./types-X7xYi2LN.cjs";
2
+ import { a as EnvGenericError, c as MissingDefaultPublishableKeyError, d as MissingSecretKeyError, f as MissingSupabaseURLError, i as EnvError, l as MissingDefaultSecretKeyError, n as AuthGenericError, o as Errors, r as CreateSupabaseClientError, s as InvalidCredentialsError, t as AuthError, u as MissingPublishableKeyError } from "./errors-O2ugIMec.cjs";
3
3
 
4
4
  //#region src/with-supabase.d.ts
5
5
  /**
@@ -43,7 +43,7 @@ declare function withSupabase<Database = unknown>(config: WithSupabaseConfig, ha
43
43
  * ```ts
44
44
  * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
45
45
  * if (error) {
46
- * return Response.json({ error: error.message }, { status: error.status })
46
+ * return Response.json({ message: error.message }, { status: error.status })
47
47
  * }
48
48
  * const { data } = await ctx.supabase.rpc('get_my_items')
49
49
  * ```
@@ -56,4 +56,4 @@ declare function createSupabaseContext<Database = unknown>(request: Request, opt
56
56
  error: AuthError;
57
57
  }>;
58
58
  //#endregion
59
- export { type Allow, type AllowWithKey, AuthError, type AuthResult, type Credentials, EnvError, type JWTClaims, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createSupabaseContext, withSupabase };
59
+ export { type Allow, type AllowWithKey, AuthError, AuthGenericError, type AuthResult, type ClientAuth, type CreateAdminClientOptions, type CreateContextClientOptions, CreateSupabaseClientError, type Credentials, EnvError, EnvGenericError, Errors, InvalidCredentialsError, type JWTClaims, MissingDefaultPublishableKeyError, MissingDefaultSecretKeyError, MissingPublishableKeyError, MissingSecretKeyError, MissingSupabaseURLError, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createSupabaseContext, withSupabase };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as JWTClaims, c as UserClaims, i as Credentials, l as WithSupabaseConfig, n as AllowWithKey, o as SupabaseContext, r as AuthResult, s as SupabaseEnv, t as Allow } from "./types-ClmJ8pi8.mjs";
2
- import { n as EnvError, t as AuthError } from "./errors-5ivL23qo.mjs";
1
+ import { a as CreateAdminClientOptions, c as JWTClaims, d as UserClaims, f as WithSupabaseConfig, i as ClientAuth, l as SupabaseContext, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, t as Allow, u as SupabaseEnv } from "./types-BmWSIuH7.mjs";
2
+ import { a as EnvGenericError, c as MissingDefaultPublishableKeyError, d as MissingSecretKeyError, f as MissingSupabaseURLError, i as EnvError, l as MissingDefaultSecretKeyError, n as AuthGenericError, o as Errors, r as CreateSupabaseClientError, s as InvalidCredentialsError, t as AuthError, u as MissingPublishableKeyError } from "./errors-CAH-RRA3.mjs";
3
3
 
4
4
  //#region src/with-supabase.d.ts
5
5
  /**
@@ -43,7 +43,7 @@ declare function withSupabase<Database = unknown>(config: WithSupabaseConfig, ha
43
43
  * ```ts
44
44
  * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
45
45
  * if (error) {
46
- * return Response.json({ error: error.message }, { status: error.status })
46
+ * return Response.json({ message: error.message }, { status: error.status })
47
47
  * }
48
48
  * const { data } = await ctx.supabase.rpc('get_my_items')
49
49
  * ```
@@ -56,4 +56,4 @@ declare function createSupabaseContext<Database = unknown>(request: Request, opt
56
56
  error: AuthError;
57
57
  }>;
58
58
  //#endregion
59
- export { type Allow, type AllowWithKey, AuthError, type AuthResult, type Credentials, EnvError, type JWTClaims, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createSupabaseContext, withSupabase };
59
+ export { type Allow, type AllowWithKey, AuthError, AuthGenericError, type AuthResult, type ClientAuth, type CreateAdminClientOptions, type CreateContextClientOptions, CreateSupabaseClientError, type Credentials, EnvError, EnvGenericError, Errors, InvalidCredentialsError, type JWTClaims, MissingDefaultPublishableKeyError, MissingDefaultSecretKeyError, MissingPublishableKeyError, MissingSecretKeyError, MissingSupabaseURLError, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createSupabaseContext, withSupabase };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as EnvError, s as AuthError } from "./verify-auth-2S7zFfR-.mjs";
2
- import { t as createSupabaseContext } from "./create-supabase-context-CmWaH3s6.mjs";
1
+ import { _ as MissingSecretKeyError, c as AuthGenericError, d as EnvGenericError, f as Errors, g as MissingPublishableKeyError, h as MissingDefaultSecretKeyError, l as CreateSupabaseClientError, m as MissingDefaultPublishableKeyError, p as InvalidCredentialsError, s as AuthError, u as EnvError, v as MissingSupabaseURLError } from "./verify-auth-Bt2uGltH.mjs";
2
+ import { t as createSupabaseContext } from "./create-supabase-context-Bmwyha9p.mjs";
3
3
  import { corsHeaders } from "@supabase/supabase-js/cors";
4
4
 
5
5
  //#region src/cors.ts
@@ -69,7 +69,7 @@ function withSupabase(config, handler) {
69
69
  });
70
70
  const { data: ctx, error } = await createSupabaseContext(req, config);
71
71
  if (error) return Response.json({
72
- error: error.message,
72
+ message: error.message,
73
73
  code: error.code
74
74
  }, {
75
75
  status: error.status,
@@ -82,4 +82,4 @@ function withSupabase(config, handler) {
82
82
  }
83
83
 
84
84
  //#endregion
85
- export { AuthError, EnvError, createSupabaseContext, withSupabase };
85
+ export { AuthError, AuthGenericError, CreateSupabaseClientError, EnvError, EnvGenericError, Errors, InvalidCredentialsError, MissingDefaultPublishableKeyError, MissingDefaultSecretKeyError, MissingPublishableKeyError, MissingSecretKeyError, MissingSupabaseURLError, createSupabaseContext, withSupabase };