@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 +5 -2
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.d.cts +1 -1
- package/dist/adapters/hono/index.d.mts +1 -1
- package/dist/adapters/hono/index.mjs +1 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +12 -18
- package/dist/core/index.d.mts +12 -18
- package/dist/core/index.mjs +1 -1
- package/dist/{create-supabase-context-CmWaH3s6.mjs → create-supabase-context-Bmwyha9p.mjs} +18 -7
- package/dist/{create-supabase-context-DcVorGKG.cjs → create-supabase-context-DDIAxA8h.cjs} +18 -7
- package/dist/errors-CAH-RRA3.d.mts +109 -0
- package/dist/errors-O2ugIMec.d.cts +109 -0
- package/dist/index.cjs +13 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{types-ClmJ8pi8.d.mts → types-BmWSIuH7.d.mts} +46 -2
- package/dist/{types-CnKoFCMX.d.cts → types-X7xYi2LN.d.cts} +46 -2
- package/dist/{verify-auth-2S7zFfR-.mjs → verify-auth-Bt2uGltH.mjs} +98 -33
- package/dist/{verify-auth-DvRVnjdq.cjs → verify-auth-DrgvEuKo.cjs} +157 -32
- package/package.json +1 -1
- package/dist/errors-5ivL23qo.d.mts +0 -78
- package/dist/errors-BmSsOAvx.d.cts +0 -78
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({
|
|
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(
|
|
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-
|
|
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 {
|
|
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 {
|
|
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-
|
|
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
|
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_verify_auth = require('../verify-auth-
|
|
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;
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import {
|
|
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({
|
|
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({
|
|
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.
|
|
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(
|
|
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>(
|
|
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
|
-
*
|
|
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>(
|
|
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 };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import {
|
|
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({
|
|
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({
|
|
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.
|
|
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(
|
|
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>(
|
|
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
|
-
*
|
|
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>(
|
|
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 };
|
package/dist/core/index.mjs
CHANGED
|
@@ -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-
|
|
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,
|
|
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({
|
|
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
|
|
35
|
-
|
|
34
|
+
const config = {
|
|
35
|
+
env: options?.env,
|
|
36
|
+
supabaseOptions: options?.supabaseOptions
|
|
37
|
+
};
|
|
36
38
|
return {
|
|
37
39
|
data: {
|
|
38
|
-
supabase
|
|
39
|
-
|
|
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) :
|
|
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-
|
|
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({
|
|
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
|
|
35
|
-
|
|
34
|
+
const config = {
|
|
35
|
+
env: options?.env,
|
|
36
|
+
supabaseOptions: options?.supabaseOptions
|
|
37
|
+
};
|
|
36
38
|
return {
|
|
37
39
|
data: {
|
|
38
|
-
supabase
|
|
39
|
-
|
|
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) :
|
|
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-
|
|
3
|
-
const require_create_supabase_context = require('./create-supabase-context-
|
|
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
|
-
|
|
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
|
|
2
|
-
import {
|
|
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({
|
|
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
|
|
2
|
-
import {
|
|
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({
|
|
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
|
|
2
|
-
import { t as createSupabaseContext } from "./create-supabase-context-
|
|
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
|
-
|
|
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 };
|