@supabase/server 0.1.1-rc.26 → 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,5 +1,5 @@
1
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";
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-..."
@@ -1,5 +1,5 @@
1
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";
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-..."
@@ -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 };
@@ -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-BjIehuNM.cjs');
3
+ const require_create_supabase_context = require('./create-supabase-context-BO7DGfth.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
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";
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, 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
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";
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, 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-mePXRNu9.mjs";
2
+ import { t as createSupabaseContext } from "./create-supabase-context--JXiHT_N.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 };
@@ -5,8 +5,7 @@ let jose = require("jose");
5
5
  /**
6
6
  * Thrown when a required environment variable is missing or malformed.
7
7
  *
8
- * Has a fixed `status` of `500` since environment errors are server-side
9
- * configuration issues, not client errors.
8
+ * Always has `status: 500` environment errors are server-side configuration issues.
10
9
  *
11
10
  * @example
12
11
  * ```ts
@@ -23,13 +22,32 @@ let jose = require("jose");
23
22
  * ```
24
23
  */
25
24
  var EnvError = class extends Error {
26
- constructor(message, code = "ENV_ERROR") {
25
+ constructor(message, code = EnvGenericError) {
27
26
  super(message);
28
27
  this.status = 500;
29
28
  this.name = "EnvError";
30
29
  this.code = code;
31
30
  }
32
31
  };
32
+ /** Generic environment error code. */
33
+ const EnvGenericError = "ENV_ERROR";
34
+ /** `SUPABASE_URL` is not set. */
35
+ const MissingSupabaseURLError = "MISSING_SUPABASE_URL";
36
+ /** Named publishable key not found in `SUPABASE_PUBLISHABLE_KEYS`. */
37
+ const MissingPublishableKeyError = "MISSING_PUBLISHABLE_KEY";
38
+ /** No default publishable key found. */
39
+ const MissingDefaultPublishableKeyError = "MISSING_DEFAULT_PUBLISHABLE_KEY";
40
+ /** Named secret key not found in `SUPABASE_SECRET_KEYS`. */
41
+ const MissingSecretKeyError = "MISSING_SECRET_KEY";
42
+ /** No default secret key found. */
43
+ const MissingDefaultSecretKeyError = "MISSING_DEFAULT_SECRET_KEY";
44
+ const EnvErrorMap = {
45
+ [MissingSupabaseURLError]: () => new EnvError("SUPABASE_URL is required but not set", MissingSupabaseURLError),
46
+ [MissingSecretKeyError]: (name) => new EnvError(`No "${name}" secret key found. Include a "${name}" entry in SUPABASE_SECRET_KEYS.`, MissingSecretKeyError),
47
+ [MissingDefaultSecretKeyError]: () => new EnvError("No default secret key found. Set SUPABASE_SECRET_KEY or include a \"default\" entry in SUPABASE_SECRET_KEYS.", MissingDefaultSecretKeyError),
48
+ [MissingPublishableKeyError]: (name) => new EnvError(`No "${name}" publishable key found. Include a "${name}" entry in SUPABASE_PUBLISHABLE_KEYS.`, MissingPublishableKeyError),
49
+ [MissingDefaultPublishableKeyError]: () => new EnvError("No default publishable key found. Set SUPABASE_PUBLISHABLE_KEY or include a \"default\" entry in SUPABASE_PUBLISHABLE_KEYS.", MissingDefaultPublishableKeyError)
50
+ };
33
51
  /**
34
52
  * Thrown when authentication or authorization fails.
35
53
  *
@@ -44,20 +62,44 @@ var EnvError = class extends Error {
44
62
  * if (error) {
45
63
  * // error is an AuthError
46
64
  * return Response.json(
47
- * { error: error.message, code: error.code },
65
+ * { message: error.message, code: error.code },
48
66
  * { status: error.status },
49
67
  * )
50
68
  * }
51
69
  * ```
52
70
  */
53
71
  var AuthError = class extends Error {
54
- constructor(message, code = "AUTH_ERROR", status = 401) {
72
+ constructor(message, code = AuthGenericError, status = 401) {
55
73
  super(message);
56
74
  this.name = "AuthError";
57
75
  this.code = code;
58
76
  this.status = status;
59
77
  }
60
78
  };
79
+ /** Generic authentication error code. */
80
+ const AuthGenericError = "AUTH_ERROR";
81
+ /** No credential matched any allowed auth mode. */
82
+ const InvalidCredentialsError = "INVALID_CREDENTIALS";
83
+ /** Failed to create a Supabase client after auth succeeded. */
84
+ const CreateSupabaseClientError = "CREATE_SUPABASE_CLIENT_ERROR";
85
+ const AuthErrorMap = {
86
+ [InvalidCredentialsError]: () => new AuthError("Invalid credentials", InvalidCredentialsError, 401),
87
+ [CreateSupabaseClientError]: () => new AuthError("Failed to create Supabase client", CreateSupabaseClientError, 500)
88
+ };
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
+ const Errors = {
100
+ ...EnvErrorMap,
101
+ ...AuthErrorMap
102
+ };
61
103
 
62
104
  //#endregion
63
105
  //#region src/core/resolve-env.ts
@@ -138,7 +180,7 @@ function resolveEnv(overrides) {
138
180
  const url = overrides?.url ?? getEnvVar("SUPABASE_URL");
139
181
  if (!url) return {
140
182
  data: null,
141
- error: new EnvError("SUPABASE_URL is required but not set", "MISSING_SUPABASE_URL")
183
+ error: Errors[MissingSupabaseURLError]()
142
184
  };
143
185
  return {
144
186
  data: {
@@ -176,7 +218,7 @@ function createAdminClient(env, keyName) {
176
218
  const name = keyName ?? "default";
177
219
  const keys = resolved.secretKeys;
178
220
  const secretKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
179
- if (!secretKey) throw new EnvError(name === "default" ? "No default secret key found. Set SUPABASE_SECRET_KEY or include a \"default\" entry in SUPABASE_SECRET_KEYS." : `No "${name}" secret key found. Include a "${name}" entry in SUPABASE_SECRET_KEYS.`, "MISSING_SECRET_KEY");
221
+ if (!secretKey) throw name === "default" ? Errors[MissingDefaultSecretKeyError]() : Errors[MissingSecretKeyError](name);
180
222
  return (0, _supabase_supabase_js.createClient)(resolved.url, secretKey, { auth: {
181
223
  persistSession: false,
182
224
  autoRefreshToken: false,
@@ -212,7 +254,7 @@ function createContextClient(token, env, keyName) {
212
254
  const name = keyName ?? "default";
213
255
  const keys = resolved.publishableKeys;
214
256
  const anonKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
215
- if (!anonKey) throw new EnvError(name === "default" ? "No default publishable key found. Set SUPABASE_PUBLISHABLE_KEY or include a \"default\" entry in SUPABASE_PUBLISHABLE_KEYS." : `No "${name}" publishable key found. Include a "${name}" entry in SUPABASE_PUBLISHABLE_KEYS.`, "MISSING_PUBLISHABLE_KEY");
257
+ if (!anonKey) throw name === "default" ? Errors[MissingDefaultPublishableKeyError]() : Errors[MissingPublishableKeyError](name);
216
258
  return (0, _supabase_supabase_js.createClient)(resolved.url, anonKey, {
217
259
  global: { headers: token ? { Authorization: `Bearer ${token}` } : {} },
218
260
  auth: {
@@ -424,7 +466,7 @@ async function tryMode(mode, credentials, env) {
424
466
  * allow: ['user', 'public'],
425
467
  * })
426
468
  * if (error) {
427
- * return Response.json({ error: error.message }, { status: error.status })
469
+ * return Response.json({ message: error.message }, { status: error.status })
428
470
  * }
429
471
  * ```
430
472
  */
@@ -444,7 +486,7 @@ async function verifyCredentials(credentials, options) {
444
486
  }
445
487
  return {
446
488
  data: null,
447
- error: new AuthError("Invalid credentials", "INVALID_CREDENTIALS", 401)
489
+ error: Errors[InvalidCredentialsError]()
448
490
  };
449
491
  }
450
492
 
@@ -473,7 +515,7 @@ async function verifyCredentials(credentials, options) {
473
515
  * })
474
516
  *
475
517
  * if (error) {
476
- * return Response.json({ error: error.message }, { status: error.status })
518
+ * return Response.json({ message: error.message }, { status: error.status })
477
519
  * }
478
520
  *
479
521
  * console.log(auth.userClaims!.id) // "d0f1a2b3-..."
@@ -490,12 +532,72 @@ Object.defineProperty(exports, 'AuthError', {
490
532
  return AuthError;
491
533
  }
492
534
  });
535
+ Object.defineProperty(exports, 'AuthGenericError', {
536
+ enumerable: true,
537
+ get: function () {
538
+ return AuthGenericError;
539
+ }
540
+ });
541
+ Object.defineProperty(exports, 'CreateSupabaseClientError', {
542
+ enumerable: true,
543
+ get: function () {
544
+ return CreateSupabaseClientError;
545
+ }
546
+ });
493
547
  Object.defineProperty(exports, 'EnvError', {
494
548
  enumerable: true,
495
549
  get: function () {
496
550
  return EnvError;
497
551
  }
498
552
  });
553
+ Object.defineProperty(exports, 'EnvGenericError', {
554
+ enumerable: true,
555
+ get: function () {
556
+ return EnvGenericError;
557
+ }
558
+ });
559
+ Object.defineProperty(exports, 'Errors', {
560
+ enumerable: true,
561
+ get: function () {
562
+ return Errors;
563
+ }
564
+ });
565
+ Object.defineProperty(exports, 'InvalidCredentialsError', {
566
+ enumerable: true,
567
+ get: function () {
568
+ return InvalidCredentialsError;
569
+ }
570
+ });
571
+ Object.defineProperty(exports, 'MissingDefaultPublishableKeyError', {
572
+ enumerable: true,
573
+ get: function () {
574
+ return MissingDefaultPublishableKeyError;
575
+ }
576
+ });
577
+ Object.defineProperty(exports, 'MissingDefaultSecretKeyError', {
578
+ enumerable: true,
579
+ get: function () {
580
+ return MissingDefaultSecretKeyError;
581
+ }
582
+ });
583
+ Object.defineProperty(exports, 'MissingPublishableKeyError', {
584
+ enumerable: true,
585
+ get: function () {
586
+ return MissingPublishableKeyError;
587
+ }
588
+ });
589
+ Object.defineProperty(exports, 'MissingSecretKeyError', {
590
+ enumerable: true,
591
+ get: function () {
592
+ return MissingSecretKeyError;
593
+ }
594
+ });
595
+ Object.defineProperty(exports, 'MissingSupabaseURLError', {
596
+ enumerable: true,
597
+ get: function () {
598
+ return MissingSupabaseURLError;
599
+ }
600
+ });
499
601
  Object.defineProperty(exports, 'createAdminClient', {
500
602
  enumerable: true,
501
603
  get: function () {
@@ -5,8 +5,7 @@ import { createLocalJWKSet, jwtVerify } from "jose";
5
5
  /**
6
6
  * Thrown when a required environment variable is missing or malformed.
7
7
  *
8
- * Has a fixed `status` of `500` since environment errors are server-side
9
- * configuration issues, not client errors.
8
+ * Always has `status: 500` environment errors are server-side configuration issues.
10
9
  *
11
10
  * @example
12
11
  * ```ts
@@ -23,13 +22,32 @@ import { createLocalJWKSet, jwtVerify } from "jose";
23
22
  * ```
24
23
  */
25
24
  var EnvError = class extends Error {
26
- constructor(message, code = "ENV_ERROR") {
25
+ constructor(message, code = EnvGenericError) {
27
26
  super(message);
28
27
  this.status = 500;
29
28
  this.name = "EnvError";
30
29
  this.code = code;
31
30
  }
32
31
  };
32
+ /** Generic environment error code. */
33
+ const EnvGenericError = "ENV_ERROR";
34
+ /** `SUPABASE_URL` is not set. */
35
+ const MissingSupabaseURLError = "MISSING_SUPABASE_URL";
36
+ /** Named publishable key not found in `SUPABASE_PUBLISHABLE_KEYS`. */
37
+ const MissingPublishableKeyError = "MISSING_PUBLISHABLE_KEY";
38
+ /** No default publishable key found. */
39
+ const MissingDefaultPublishableKeyError = "MISSING_DEFAULT_PUBLISHABLE_KEY";
40
+ /** Named secret key not found in `SUPABASE_SECRET_KEYS`. */
41
+ const MissingSecretKeyError = "MISSING_SECRET_KEY";
42
+ /** No default secret key found. */
43
+ const MissingDefaultSecretKeyError = "MISSING_DEFAULT_SECRET_KEY";
44
+ const EnvErrorMap = {
45
+ [MissingSupabaseURLError]: () => new EnvError("SUPABASE_URL is required but not set", MissingSupabaseURLError),
46
+ [MissingSecretKeyError]: (name) => new EnvError(`No "${name}" secret key found. Include a "${name}" entry in SUPABASE_SECRET_KEYS.`, MissingSecretKeyError),
47
+ [MissingDefaultSecretKeyError]: () => new EnvError("No default secret key found. Set SUPABASE_SECRET_KEY or include a \"default\" entry in SUPABASE_SECRET_KEYS.", MissingDefaultSecretKeyError),
48
+ [MissingPublishableKeyError]: (name) => new EnvError(`No "${name}" publishable key found. Include a "${name}" entry in SUPABASE_PUBLISHABLE_KEYS.`, MissingPublishableKeyError),
49
+ [MissingDefaultPublishableKeyError]: () => new EnvError("No default publishable key found. Set SUPABASE_PUBLISHABLE_KEY or include a \"default\" entry in SUPABASE_PUBLISHABLE_KEYS.", MissingDefaultPublishableKeyError)
50
+ };
33
51
  /**
34
52
  * Thrown when authentication or authorization fails.
35
53
  *
@@ -44,20 +62,44 @@ var EnvError = class extends Error {
44
62
  * if (error) {
45
63
  * // error is an AuthError
46
64
  * return Response.json(
47
- * { error: error.message, code: error.code },
65
+ * { message: error.message, code: error.code },
48
66
  * { status: error.status },
49
67
  * )
50
68
  * }
51
69
  * ```
52
70
  */
53
71
  var AuthError = class extends Error {
54
- constructor(message, code = "AUTH_ERROR", status = 401) {
72
+ constructor(message, code = AuthGenericError, status = 401) {
55
73
  super(message);
56
74
  this.name = "AuthError";
57
75
  this.code = code;
58
76
  this.status = status;
59
77
  }
60
78
  };
79
+ /** Generic authentication error code. */
80
+ const AuthGenericError = "AUTH_ERROR";
81
+ /** No credential matched any allowed auth mode. */
82
+ const InvalidCredentialsError = "INVALID_CREDENTIALS";
83
+ /** Failed to create a Supabase client after auth succeeded. */
84
+ const CreateSupabaseClientError = "CREATE_SUPABASE_CLIENT_ERROR";
85
+ const AuthErrorMap = {
86
+ [InvalidCredentialsError]: () => new AuthError("Invalid credentials", InvalidCredentialsError, 401),
87
+ [CreateSupabaseClientError]: () => new AuthError("Failed to create Supabase client", CreateSupabaseClientError, 500)
88
+ };
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
+ const Errors = {
100
+ ...EnvErrorMap,
101
+ ...AuthErrorMap
102
+ };
61
103
 
62
104
  //#endregion
63
105
  //#region src/core/resolve-env.ts
@@ -138,7 +180,7 @@ function resolveEnv(overrides) {
138
180
  const url = overrides?.url ?? getEnvVar("SUPABASE_URL");
139
181
  if (!url) return {
140
182
  data: null,
141
- error: new EnvError("SUPABASE_URL is required but not set", "MISSING_SUPABASE_URL")
183
+ error: Errors[MissingSupabaseURLError]()
142
184
  };
143
185
  return {
144
186
  data: {
@@ -176,7 +218,7 @@ function createAdminClient(env, keyName) {
176
218
  const name = keyName ?? "default";
177
219
  const keys = resolved.secretKeys;
178
220
  const secretKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
179
- if (!secretKey) throw new EnvError(name === "default" ? "No default secret key found. Set SUPABASE_SECRET_KEY or include a \"default\" entry in SUPABASE_SECRET_KEYS." : `No "${name}" secret key found. Include a "${name}" entry in SUPABASE_SECRET_KEYS.`, "MISSING_SECRET_KEY");
221
+ if (!secretKey) throw name === "default" ? Errors[MissingDefaultSecretKeyError]() : Errors[MissingSecretKeyError](name);
180
222
  return createClient(resolved.url, secretKey, { auth: {
181
223
  persistSession: false,
182
224
  autoRefreshToken: false,
@@ -212,7 +254,7 @@ function createContextClient(token, env, keyName) {
212
254
  const name = keyName ?? "default";
213
255
  const keys = resolved.publishableKeys;
214
256
  const anonKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
215
- if (!anonKey) throw new EnvError(name === "default" ? "No default publishable key found. Set SUPABASE_PUBLISHABLE_KEY or include a \"default\" entry in SUPABASE_PUBLISHABLE_KEYS." : `No "${name}" publishable key found. Include a "${name}" entry in SUPABASE_PUBLISHABLE_KEYS.`, "MISSING_PUBLISHABLE_KEY");
257
+ if (!anonKey) throw name === "default" ? Errors[MissingDefaultPublishableKeyError]() : Errors[MissingPublishableKeyError](name);
216
258
  return createClient(resolved.url, anonKey, {
217
259
  global: { headers: token ? { Authorization: `Bearer ${token}` } : {} },
218
260
  auth: {
@@ -424,7 +466,7 @@ async function tryMode(mode, credentials, env) {
424
466
  * allow: ['user', 'public'],
425
467
  * })
426
468
  * if (error) {
427
- * return Response.json({ error: error.message }, { status: error.status })
469
+ * return Response.json({ message: error.message }, { status: error.status })
428
470
  * }
429
471
  * ```
430
472
  */
@@ -444,7 +486,7 @@ async function verifyCredentials(credentials, options) {
444
486
  }
445
487
  return {
446
488
  data: null,
447
- error: new AuthError("Invalid credentials", "INVALID_CREDENTIALS", 401)
489
+ error: Errors[InvalidCredentialsError]()
448
490
  };
449
491
  }
450
492
 
@@ -473,7 +515,7 @@ async function verifyCredentials(credentials, options) {
473
515
  * })
474
516
  *
475
517
  * if (error) {
476
- * return Response.json({ error: error.message }, { status: error.status })
518
+ * return Response.json({ message: error.message }, { status: error.status })
477
519
  * }
478
520
  *
479
521
  * console.log(auth.userClaims!.id) // "d0f1a2b3-..."
@@ -484,4 +526,4 @@ async function verifyAuth(request, options) {
484
526
  }
485
527
 
486
528
  //#endregion
487
- export { createAdminClient as a, EnvError as c, createContextClient as i, verifyCredentials as n, resolveEnv as o, extractCredentials as r, AuthError as s, verifyAuth as t };
529
+ export { MissingSecretKeyError as _, createAdminClient as a, AuthGenericError as c, EnvGenericError as d, Errors as f, MissingPublishableKeyError as g, MissingDefaultSecretKeyError as h, createContextClient as i, CreateSupabaseClientError as l, MissingDefaultPublishableKeyError as m, verifyCredentials as n, resolveEnv as o, InvalidCredentialsError as p, extractCredentials as r, AuthError as s, verifyAuth as t, EnvError as u, MissingSupabaseURLError as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/server",
3
- "version": "0.1.1-rc.26",
3
+ "version": "0.1.1-rc.27",
4
4
  "description": "Server-side utilities for Supabase. Handles auth, client creation, and context injection so you write business logic, not boilerplate.",
5
5
  "keywords": [
6
6
  "edge",
@@ -1,78 +0,0 @@
1
- //#region src/errors.d.ts
2
- /**
3
- * Thrown when a required environment variable is missing or malformed.
4
- *
5
- * Has a fixed `status` of `500` since environment errors are server-side
6
- * configuration issues, not client errors.
7
- *
8
- * @example
9
- * ```ts
10
- * import { EnvError } from '@supabase/server'
11
- *
12
- * try {
13
- * const client = createAdminClient()
14
- * } catch (e) {
15
- * if (e instanceof EnvError) {
16
- * console.error(`Config issue [${e.code}]: ${e.message}`)
17
- * // → "Config issue [MISSING_SUPABASE_URL]: SUPABASE_URL is required but not set"
18
- * }
19
- * }
20
- * ```
21
- */
22
- declare class EnvError extends Error {
23
- /** Always `500` — environment errors are server-side issues. */
24
- readonly status = 500;
25
- /**
26
- * Machine-readable error code.
27
- *
28
- * Known codes:
29
- * - `"MISSING_SUPABASE_URL"` — `SUPABASE_URL` not set
30
- * - `"MISSING_PUBLISHABLE_KEY"` — No publishable key found
31
- * - `"MISSING_SECRET_KEY"` — No secret key found
32
- * - `"ENV_ERROR"` — Generic environment error
33
- */
34
- readonly code: string;
35
- constructor(message: string, code?: string);
36
- }
37
- /**
38
- * Thrown when authentication or authorization fails.
39
- *
40
- * Carries an HTTP `status` code suitable for returning directly in a response
41
- * (typically `401` for invalid credentials, `500` for server-side auth failures).
42
- *
43
- * @example
44
- * ```ts
45
- * import { AuthError, createSupabaseContext } from '@supabase/server'
46
- *
47
- * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
48
- * if (error) {
49
- * // error is an AuthError
50
- * return Response.json(
51
- * { error: error.message, code: error.code },
52
- * { status: error.status },
53
- * )
54
- * }
55
- * ```
56
- */
57
- declare class AuthError extends Error {
58
- /**
59
- * HTTP status code.
60
- *
61
- * - `401` — Invalid or missing credentials
62
- * - `500` — Server-side auth failure (e.g., missing JWKS, env misconfiguration)
63
- */
64
- readonly status: number;
65
- /**
66
- * Machine-readable error code.
67
- *
68
- * Known codes:
69
- * - `"INVALID_CREDENTIALS"` — No credential matched any allowed auth mode
70
- * - `"CLIENT_ERROR"` — Failed to create a Supabase client after auth succeeded
71
- * - `"AUTH_ERROR"` — Generic authentication error
72
- * - Any `EnvError` code (propagated when env resolution fails during auth)
73
- */
74
- readonly code: string;
75
- constructor(message: string, code?: string, status?: number);
76
- }
77
- //#endregion
78
- export { EnvError as n, AuthError as t };
@@ -1,78 +0,0 @@
1
- //#region src/errors.d.ts
2
- /**
3
- * Thrown when a required environment variable is missing or malformed.
4
- *
5
- * Has a fixed `status` of `500` since environment errors are server-side
6
- * configuration issues, not client errors.
7
- *
8
- * @example
9
- * ```ts
10
- * import { EnvError } from '@supabase/server'
11
- *
12
- * try {
13
- * const client = createAdminClient()
14
- * } catch (e) {
15
- * if (e instanceof EnvError) {
16
- * console.error(`Config issue [${e.code}]: ${e.message}`)
17
- * // → "Config issue [MISSING_SUPABASE_URL]: SUPABASE_URL is required but not set"
18
- * }
19
- * }
20
- * ```
21
- */
22
- declare class EnvError extends Error {
23
- /** Always `500` — environment errors are server-side issues. */
24
- readonly status = 500;
25
- /**
26
- * Machine-readable error code.
27
- *
28
- * Known codes:
29
- * - `"MISSING_SUPABASE_URL"` — `SUPABASE_URL` not set
30
- * - `"MISSING_PUBLISHABLE_KEY"` — No publishable key found
31
- * - `"MISSING_SECRET_KEY"` — No secret key found
32
- * - `"ENV_ERROR"` — Generic environment error
33
- */
34
- readonly code: string;
35
- constructor(message: string, code?: string);
36
- }
37
- /**
38
- * Thrown when authentication or authorization fails.
39
- *
40
- * Carries an HTTP `status` code suitable for returning directly in a response
41
- * (typically `401` for invalid credentials, `500` for server-side auth failures).
42
- *
43
- * @example
44
- * ```ts
45
- * import { AuthError, createSupabaseContext } from '@supabase/server'
46
- *
47
- * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
48
- * if (error) {
49
- * // error is an AuthError
50
- * return Response.json(
51
- * { error: error.message, code: error.code },
52
- * { status: error.status },
53
- * )
54
- * }
55
- * ```
56
- */
57
- declare class AuthError extends Error {
58
- /**
59
- * HTTP status code.
60
- *
61
- * - `401` — Invalid or missing credentials
62
- * - `500` — Server-side auth failure (e.g., missing JWKS, env misconfiguration)
63
- */
64
- readonly status: number;
65
- /**
66
- * Machine-readable error code.
67
- *
68
- * Known codes:
69
- * - `"INVALID_CREDENTIALS"` — No credential matched any allowed auth mode
70
- * - `"CLIENT_ERROR"` — Failed to create a Supabase client after auth succeeded
71
- * - `"AUTH_ERROR"` — Generic authentication error
72
- * - Any `EnvError` code (propagated when env resolution fails during auth)
73
- */
74
- readonly code: string;
75
- constructor(message: string, code?: string, status?: number);
76
- }
77
- //#endregion
78
- export { EnvError as n, AuthError as t };