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

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.
@@ -0,0 +1,78 @@
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 };
@@ -0,0 +1,78 @@
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 };
package/dist/index.cjs CHANGED
@@ -1,14 +1,34 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_verify_auth = require('./verify-auth-6a1UPrFz.cjs');
3
- const require_create_supabase_context = require('./create-supabase-context-DNWor6i_.cjs');
2
+ const require_verify_auth = require('./verify-auth-DvRVnjdq.cjs');
3
+ const require_create_supabase_context = require('./create-supabase-context-DcVorGKG.cjs');
4
4
  let _supabase_supabase_js_cors = require("@supabase/supabase-js/cors");
5
5
 
6
6
  //#region src/cors.ts
7
+ /**
8
+ * Builds the CORS headers object based on the given configuration.
9
+ *
10
+ * @param config - The CORS configuration.
11
+ * @returns A headers record to include in the response. Empty object if CORS is disabled.
12
+ *
13
+ * @internal
14
+ */
7
15
  function buildCorsHeaders(config) {
8
16
  if (config === false) return {};
9
17
  if (typeof config === "object") return config;
10
18
  return _supabase_supabase_js_cors.corsHeaders;
11
19
  }
20
+ /**
21
+ * Returns a new `Response` with CORS headers appended.
22
+ *
23
+ * Creates a clone of the original response and sets each CORS header on it.
24
+ * If CORS is disabled (`config === false`), returns the original response unchanged.
25
+ *
26
+ * @param response - The original response to augment.
27
+ * @param config - The CORS configuration.
28
+ * @returns A new `Response` with CORS headers set, or the original response if CORS is disabled.
29
+ *
30
+ * @internal
31
+ */
12
32
  function addCorsHeaders(response, config) {
13
33
  if (config === false) return response;
14
34
  const corsHeaders = buildCorsHeaders(config);
@@ -19,6 +39,29 @@ function addCorsHeaders(response, config) {
19
39
 
20
40
  //#endregion
21
41
  //#region src/with-supabase.ts
42
+ /**
43
+ * Wraps a request handler with Supabase auth, client creation, and CORS handling.
44
+ *
45
+ * Built for the Web API `Request`/`Response` standard that all modern runtimes
46
+ * implement natively. Handles CORS preflight, credential verification,
47
+ * context creation, and error responses. Your handler only runs on successful auth.
48
+ *
49
+ * @param config - Auth modes, CORS, and environment overrides. See {@link WithSupabaseConfig}.
50
+ * @param handler - Receives the `Request` and a fully-initialized {@link SupabaseContext}.
51
+ * @returns A `(req: Request) => Promise<Response>` fetch handler.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { withSupabase } from '@supabase/server'
56
+ *
57
+ * export default {
58
+ * fetch: withSupabase({ allow: 'user' }, async (req, ctx) => {
59
+ * const { data } = await ctx.supabase.rpc('get_my_profile')
60
+ * return Response.json(data)
61
+ * }),
62
+ * }
63
+ * ```
64
+ */
22
65
  function withSupabase(config, handler) {
23
66
  return async (req) => {
24
67
  if (config.cors !== false && req.method === "OPTIONS") return new Response(null, {
@@ -42,11 +85,5 @@ function withSupabase(config, handler) {
42
85
  //#endregion
43
86
  exports.AuthError = require_verify_auth.AuthError;
44
87
  exports.EnvError = require_verify_auth.EnvError;
45
- exports.createAdminClient = require_verify_auth.createAdminClient;
46
- exports.createContextClient = require_verify_auth.createContextClient;
47
88
  exports.createSupabaseContext = require_create_supabase_context.createSupabaseContext;
48
- exports.extractCredentials = require_verify_auth.extractCredentials;
49
- exports.resolveEnv = require_verify_auth.resolveEnv;
50
- exports.verifyAuth = require_verify_auth.verifyAuth;
51
- exports.verifyCredentials = require_verify_auth.verifyCredentials;
52
89
  exports.withSupabase = withSupabase;
package/dist/index.d.cts CHANGED
@@ -1,10 +1,53 @@
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-C9J9JcPD.cjs";
2
- import { a as extractCredentials, c as EnvError, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, s as AuthError, t as createAdminClient } from "./create-admin-client-CnuiHPpV.cjs";
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";
3
3
 
4
4
  //#region src/with-supabase.d.ts
5
+ /**
6
+ * Wraps a request handler with Supabase auth, client creation, and CORS handling.
7
+ *
8
+ * Built for the Web API `Request`/`Response` standard that all modern runtimes
9
+ * implement natively. Handles CORS preflight, credential verification,
10
+ * context creation, and error responses. Your handler only runs on successful auth.
11
+ *
12
+ * @param config - Auth modes, CORS, and environment overrides. See {@link WithSupabaseConfig}.
13
+ * @param handler - Receives the `Request` and a fully-initialized {@link SupabaseContext}.
14
+ * @returns A `(req: Request) => Promise<Response>` fetch handler.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { withSupabase } from '@supabase/server'
19
+ *
20
+ * export default {
21
+ * fetch: withSupabase({ allow: 'user' }, async (req, ctx) => {
22
+ * const { data } = await ctx.supabase.rpc('get_my_profile')
23
+ * return Response.json(data)
24
+ * }),
25
+ * }
26
+ * ```
27
+ */
5
28
  declare function withSupabase<Database = unknown>(config: WithSupabaseConfig, handler: (req: Request, ctx: SupabaseContext<Database>) => Promise<Response>): (req: Request) => Promise<Response>;
6
29
  //#endregion
7
30
  //#region src/create-supabase-context.d.ts
31
+ /**
32
+ * Creates a {@link SupabaseContext} directly from a request.
33
+ *
34
+ * Use this when you need the context without the full {@link withSupabase} wrapper —
35
+ * e.g., inside framework route handlers or custom middleware. Returns a result tuple
36
+ * instead of producing a `Response`.
37
+ *
38
+ * @param request - The incoming HTTP request.
39
+ * @param options - Auth modes, environment overrides. The `cors` option is ignored here.
40
+ * @returns `{ data: SupabaseContext, error: null }` on success, `{ data: null, error: AuthError }` on failure.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
45
+ * if (error) {
46
+ * return Response.json({ error: error.message }, { status: error.status })
47
+ * }
48
+ * const { data } = await ctx.supabase.rpc('get_my_items')
49
+ * ```
50
+ */
8
51
  declare function createSupabaseContext<Database = unknown>(request: Request, options?: WithSupabaseConfig): Promise<{
9
52
  data: SupabaseContext<Database>;
10
53
  error: null;
@@ -13,4 +56,4 @@ declare function createSupabaseContext<Database = unknown>(request: Request, opt
13
56
  error: AuthError;
14
57
  }>;
15
58
  //#endregion
16
- export { type Allow, type AllowWithKey, AuthError, type AuthResult, type Credentials, EnvError, type JWTClaims, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createAdminClient, createContextClient, createSupabaseContext, extractCredentials, resolveEnv, verifyAuth, verifyCredentials, withSupabase };
59
+ export { type Allow, type AllowWithKey, AuthError, type AuthResult, type Credentials, EnvError, type JWTClaims, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createSupabaseContext, withSupabase };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,53 @@
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-Ceetds5F.mjs";
2
- import { a as extractCredentials, c as EnvError, i as verifyCredentials, n as createContextClient, o as resolveEnv, r as verifyAuth, s as AuthError, t as createAdminClient } from "./create-admin-client-BQEHqeFW.mjs";
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";
3
3
 
4
4
  //#region src/with-supabase.d.ts
5
+ /**
6
+ * Wraps a request handler with Supabase auth, client creation, and CORS handling.
7
+ *
8
+ * Built for the Web API `Request`/`Response` standard that all modern runtimes
9
+ * implement natively. Handles CORS preflight, credential verification,
10
+ * context creation, and error responses. Your handler only runs on successful auth.
11
+ *
12
+ * @param config - Auth modes, CORS, and environment overrides. See {@link WithSupabaseConfig}.
13
+ * @param handler - Receives the `Request` and a fully-initialized {@link SupabaseContext}.
14
+ * @returns A `(req: Request) => Promise<Response>` fetch handler.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { withSupabase } from '@supabase/server'
19
+ *
20
+ * export default {
21
+ * fetch: withSupabase({ allow: 'user' }, async (req, ctx) => {
22
+ * const { data } = await ctx.supabase.rpc('get_my_profile')
23
+ * return Response.json(data)
24
+ * }),
25
+ * }
26
+ * ```
27
+ */
5
28
  declare function withSupabase<Database = unknown>(config: WithSupabaseConfig, handler: (req: Request, ctx: SupabaseContext<Database>) => Promise<Response>): (req: Request) => Promise<Response>;
6
29
  //#endregion
7
30
  //#region src/create-supabase-context.d.ts
31
+ /**
32
+ * Creates a {@link SupabaseContext} directly from a request.
33
+ *
34
+ * Use this when you need the context without the full {@link withSupabase} wrapper —
35
+ * e.g., inside framework route handlers or custom middleware. Returns a result tuple
36
+ * instead of producing a `Response`.
37
+ *
38
+ * @param request - The incoming HTTP request.
39
+ * @param options - Auth modes, environment overrides. The `cors` option is ignored here.
40
+ * @returns `{ data: SupabaseContext, error: null }` on success, `{ data: null, error: AuthError }` on failure.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const { data: ctx, error } = await createSupabaseContext(request, { allow: 'user' })
45
+ * if (error) {
46
+ * return Response.json({ error: error.message }, { status: error.status })
47
+ * }
48
+ * const { data } = await ctx.supabase.rpc('get_my_items')
49
+ * ```
50
+ */
8
51
  declare function createSupabaseContext<Database = unknown>(request: Request, options?: WithSupabaseConfig): Promise<{
9
52
  data: SupabaseContext<Database>;
10
53
  error: null;
@@ -13,4 +56,4 @@ declare function createSupabaseContext<Database = unknown>(request: Request, opt
13
56
  error: AuthError;
14
57
  }>;
15
58
  //#endregion
16
- export { type Allow, type AllowWithKey, AuthError, type AuthResult, type Credentials, EnvError, type JWTClaims, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createAdminClient, createContextClient, createSupabaseContext, extractCredentials, resolveEnv, verifyAuth, verifyCredentials, withSupabase };
59
+ export { type Allow, type AllowWithKey, AuthError, type AuthResult, type Credentials, EnvError, type JWTClaims, type SupabaseContext, type SupabaseEnv, type UserClaims, type WithSupabaseConfig, createSupabaseContext, withSupabase };
package/dist/index.mjs CHANGED
@@ -1,13 +1,33 @@
1
- import { a as createAdminClient, c as EnvError, i as createContextClient, n as verifyCredentials, o as resolveEnv, r as extractCredentials, s as AuthError, t as verifyAuth } from "./verify-auth-DxUT0XoT.mjs";
2
- import { t as createSupabaseContext } from "./create-supabase-context-BrSIe29v.mjs";
1
+ import { c as EnvError, s as AuthError } from "./verify-auth-2S7zFfR-.mjs";
2
+ import { t as createSupabaseContext } from "./create-supabase-context-CmWaH3s6.mjs";
3
3
  import { corsHeaders } from "@supabase/supabase-js/cors";
4
4
 
5
5
  //#region src/cors.ts
6
+ /**
7
+ * Builds the CORS headers object based on the given configuration.
8
+ *
9
+ * @param config - The CORS configuration.
10
+ * @returns A headers record to include in the response. Empty object if CORS is disabled.
11
+ *
12
+ * @internal
13
+ */
6
14
  function buildCorsHeaders(config) {
7
15
  if (config === false) return {};
8
16
  if (typeof config === "object") return config;
9
17
  return corsHeaders;
10
18
  }
19
+ /**
20
+ * Returns a new `Response` with CORS headers appended.
21
+ *
22
+ * Creates a clone of the original response and sets each CORS header on it.
23
+ * If CORS is disabled (`config === false`), returns the original response unchanged.
24
+ *
25
+ * @param response - The original response to augment.
26
+ * @param config - The CORS configuration.
27
+ * @returns A new `Response` with CORS headers set, or the original response if CORS is disabled.
28
+ *
29
+ * @internal
30
+ */
11
31
  function addCorsHeaders(response, config) {
12
32
  if (config === false) return response;
13
33
  const corsHeaders = buildCorsHeaders(config);
@@ -18,6 +38,29 @@ function addCorsHeaders(response, config) {
18
38
 
19
39
  //#endregion
20
40
  //#region src/with-supabase.ts
41
+ /**
42
+ * Wraps a request handler with Supabase auth, client creation, and CORS handling.
43
+ *
44
+ * Built for the Web API `Request`/`Response` standard that all modern runtimes
45
+ * implement natively. Handles CORS preflight, credential verification,
46
+ * context creation, and error responses. Your handler only runs on successful auth.
47
+ *
48
+ * @param config - Auth modes, CORS, and environment overrides. See {@link WithSupabaseConfig}.
49
+ * @param handler - Receives the `Request` and a fully-initialized {@link SupabaseContext}.
50
+ * @returns A `(req: Request) => Promise<Response>` fetch handler.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { withSupabase } from '@supabase/server'
55
+ *
56
+ * export default {
57
+ * fetch: withSupabase({ allow: 'user' }, async (req, ctx) => {
58
+ * const { data } = await ctx.supabase.rpc('get_my_profile')
59
+ * return Response.json(data)
60
+ * }),
61
+ * }
62
+ * ```
63
+ */
21
64
  function withSupabase(config, handler) {
22
65
  return async (req) => {
23
66
  if (config.cors !== false && req.method === "OPTIONS") return new Response(null, {
@@ -39,4 +82,4 @@ function withSupabase(config, handler) {
39
82
  }
40
83
 
41
84
  //#endregion
42
- export { AuthError, EnvError, createAdminClient, createContextClient, createSupabaseContext, extractCredentials, resolveEnv, verifyAuth, verifyCredentials, withSupabase };
85
+ export { AuthError, EnvError, createSupabaseContext, withSupabase };
@@ -0,0 +1,227 @@
1
+ import { SupabaseClient } from "@supabase/supabase-js";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * Authentication mode that determines what credentials a request must provide.
6
+ *
7
+ * - `"always"` — No credentials required. Every request is accepted.
8
+ * - `"public"` — Requires a valid publishable key in the `apikey` header.
9
+ * - `"secret"` — Requires a valid secret key in the `apikey` header (timing-safe comparison).
10
+ * - `"user"` — Requires a valid JWT in the `Authorization: Bearer <token>` header.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Single mode
15
+ * withSupabase({ allow: 'user' }, handler)
16
+ *
17
+ * // Multiple modes — the first match wins
18
+ * withSupabase({ allow: ['user', 'public'] }, handler)
19
+ * ```
20
+ */
21
+ type Allow = 'always' | 'public' | 'secret' | 'user';
22
+ /**
23
+ * Extended auth mode that supports targeting a specific named key.
24
+ *
25
+ * Use the colon syntax (`"public:web_app"`) to require a specific named key
26
+ * from the `SUPABASE_PUBLISHABLE_KEYS` or `SUPABASE_SECRET_KEYS` JSON object.
27
+ * Use `"public:*"` or `"secret:*"` to accept any key in the set.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Accept only the "mobile" publishable key
32
+ * withSupabase({ allow: 'public:mobile' }, handler)
33
+ *
34
+ * // Accept any secret key
35
+ * withSupabase({ allow: 'secret:*' }, handler)
36
+ *
37
+ * // Mix named keys with other modes
38
+ * withSupabase({ allow: ['user', 'public:web_app'] }, handler)
39
+ * ```
40
+ */
41
+ type AllowWithKey = Allow | `public:${string}` | `secret:${string}`;
42
+ /**
43
+ * Resolved Supabase environment configuration.
44
+ *
45
+ * Holds the project URL, API keys, and JWKS needed by every other primitive.
46
+ * Typically resolved automatically from environment variables by {@link resolveEnv},
47
+ * but can be passed explicitly via the `env` option.
48
+ *
49
+ * @see {@link resolveEnv} for how each field maps to environment variables.
50
+ */
51
+ interface SupabaseEnv {
52
+ /** Supabase project URL (e.g. `"https://<ref>.supabase.co"`). Sourced from `SUPABASE_URL`. */
53
+ url: string;
54
+ /**
55
+ * Named publishable (anon) keys. Sourced from `SUPABASE_PUBLISHABLE_KEYS` (JSON object)
56
+ * or `SUPABASE_PUBLISHABLE_KEY` (single key, stored as `{ default: "<value>" }`).
57
+ */
58
+ publishableKeys: Record<string, string>;
59
+ /**
60
+ * Named secret (service-role) keys. Sourced from `SUPABASE_SECRET_KEYS` (JSON object)
61
+ * or `SUPABASE_SECRET_KEY` (single key, stored as `{ default: "<value>" }`).
62
+ */
63
+ secretKeys: Record<string, string>;
64
+ /**
65
+ * JSON Web Key Set used for JWT verification. Sourced from `SUPABASE_JWKS`.
66
+ * Accepts both `{ keys: [...] }` and bare `[...]` array formats.
67
+ * `null` when no JWKS is configured (JWT verification will be unavailable).
68
+ */
69
+ jwks: JsonWebKeySet | null;
70
+ }
71
+ /**
72
+ * A JSON Web Key Set as defined by RFC 7517.
73
+ *
74
+ * @see https://datatracker.ietf.org/doc/html/rfc7517
75
+ */
76
+ interface JsonWebKeySet {
77
+ /** Array of JSON Web Keys. */
78
+ keys: JsonWebKey[];
79
+ }
80
+ /**
81
+ * Raw credentials extracted from an incoming HTTP request.
82
+ *
83
+ * Produced by {@link extractCredentials} from the `Authorization` and `apikey` headers.
84
+ *
85
+ * @see {@link extractCredentials}
86
+ */
87
+ interface Credentials {
88
+ /** Bearer token from the `Authorization: Bearer <token>` header, or `null` if absent. */
89
+ token: string | null;
90
+ /** API key from the `apikey` header, or `null` if absent. */
91
+ apikey: string | null;
92
+ }
93
+ /**
94
+ * Result of credential verification.
95
+ *
96
+ * Contains the resolved auth mode, the verified token (for `"user"` mode),
97
+ * decoded JWT claims, and the matched key name (for `"public"` / `"secret"` modes).
98
+ *
99
+ * @see {@link verifyCredentials}
100
+ * @see {@link verifyAuth}
101
+ */
102
+ interface AuthResult {
103
+ /** The auth mode that was successfully matched. */
104
+ authType: Allow;
105
+ /** The verified JWT, or `null` for non-user auth modes. */
106
+ token: string | null;
107
+ /** Normalized user identity derived from the JWT, or `null` when no JWT is present. */
108
+ userClaims: UserClaims | null;
109
+ /** Raw JWT payload, or `null` when no JWT is present. */
110
+ claims: JWTClaims | null;
111
+ /** Name of the matched key (e.g. `"default"`, `"mobile"`), or `null` for `"user"` / `"always"` modes. */
112
+ keyName?: string | null;
113
+ }
114
+ /**
115
+ * Standard JWT claims as defined by RFC 7519, extended with Supabase-specific fields.
116
+ *
117
+ * This is the raw JWT payload — use {@link UserClaims} for a normalized, camelCase view.
118
+ *
119
+ * @see https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
120
+ */
121
+ interface JWTClaims {
122
+ /** Subject — the user's unique ID. */
123
+ sub: string;
124
+ /** Issuer — typically your Supabase project URL. */
125
+ iss?: string;
126
+ /** Audience — who the token is intended for. */
127
+ aud?: string | string[];
128
+ /** Expiration time (seconds since epoch). */
129
+ exp?: number;
130
+ /** Issued at (seconds since epoch). */
131
+ iat?: number;
132
+ /** Supabase role (e.g. `"authenticated"`, `"anon"`). */
133
+ role?: string;
134
+ /** User's email address from Supabase Auth. */
135
+ email?: string;
136
+ /** Application-level metadata set via Supabase Auth admin APIs. */
137
+ app_metadata?: Record<string, unknown>;
138
+ /** User-editable metadata set via Supabase Auth. */
139
+ user_metadata?: Record<string, unknown>;
140
+ /** Additional custom claims. */
141
+ [key: string]: unknown;
142
+ }
143
+ /**
144
+ * Normalized, camelCase view of the authenticated user's identity.
145
+ *
146
+ * Derived from {@link JWTClaims}. For the full Supabase `User` object
147
+ * (including email confirmation status, providers, etc.), call
148
+ * `supabase.auth.getUser()` using the context client.
149
+ */
150
+ interface UserClaims {
151
+ /** User's unique ID (same as `JWTClaims.sub`). */
152
+ id: string;
153
+ /** Supabase role (e.g. `"authenticated"`). */
154
+ role?: string;
155
+ /** User's email address. */
156
+ email?: string;
157
+ /** Application-level metadata (e.g. roles, permissions). */
158
+ appMetadata?: Record<string, unknown>;
159
+ /** User-editable profile metadata (e.g. display name, avatar). */
160
+ userMetadata?: Record<string, unknown>;
161
+ }
162
+ /**
163
+ * Configuration for {@link withSupabase} and {@link createSupabaseContext}.
164
+ *
165
+ * Controls which auth modes are accepted, environment overrides, and CORS behavior.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * // Require authenticated users, auto-CORS enabled (default)
170
+ * const config: WithSupabaseConfig = { allow: 'user' }
171
+ *
172
+ * // Accept users or service-to-service calls, custom CORS headers
173
+ * const config: WithSupabaseConfig = {
174
+ * allow: ['user', 'secret'],
175
+ * cors: { 'Access-Control-Allow-Origin': 'https://myapp.com' },
176
+ * }
177
+ *
178
+ * // No auth required, CORS disabled
179
+ * const config: WithSupabaseConfig = { allow: 'always', cors: false }
180
+ * ```
181
+ */
182
+ interface WithSupabaseConfig {
183
+ /**
184
+ * Auth mode(s) to accept. Modes are tried in order — the first match wins.
185
+ *
186
+ * @defaultValue `"user"`
187
+ */
188
+ allow?: AllowWithKey | AllowWithKey[];
189
+ /**
190
+ * Override auto-detected environment variables. Useful for testing
191
+ * or when running in environments without standard env var support.
192
+ */
193
+ env?: Partial<SupabaseEnv>;
194
+ /**
195
+ * CORS configuration for the `withSupabase` wrapper.
196
+ *
197
+ * - `true` (default) — uses `@supabase/supabase-js` default CORS headers.
198
+ * - `false` — disables CORS handling entirely.
199
+ * - `Record<string, string>` — custom CORS headers.
200
+ *
201
+ * @remarks Only applies to the top-level {@link withSupabase} wrapper.
202
+ * The Hono adapter handles CORS separately via Hono's own middleware.
203
+ *
204
+ * @defaultValue `true`
205
+ */
206
+ cors?: boolean | Record<string, string>;
207
+ }
208
+ /**
209
+ * The Supabase context created for each authenticated request.
210
+ *
211
+ * Contains pre-configured Supabase clients and the caller's identity.
212
+ * Identical regardless of which layer or adapter produced it.
213
+ */
214
+ interface SupabaseContext<Database = unknown> {
215
+ /** Supabase client scoped to the caller's identity. RLS policies apply. */
216
+ supabase: SupabaseClient<Database>;
217
+ /** Admin Supabase client that bypasses Row-Level Security. */
218
+ supabaseAdmin: SupabaseClient<Database>;
219
+ /** JWT-derived identity. For the full Supabase User object, call `supabase.auth.getUser()`. */
220
+ userClaims: UserClaims | null;
221
+ /** Raw JWT payload. `null` for non-user auth modes. */
222
+ claims: JWTClaims | null;
223
+ /** The auth mode that was used for this request. */
224
+ authType: Allow;
225
+ }
226
+ //#endregion
227
+ export { JWTClaims as a, UserClaims as c, Credentials as i, WithSupabaseConfig as l, AllowWithKey as n, SupabaseContext as o, AuthResult as r, SupabaseEnv as s, Allow as t };