@supabase/server 0.1.1-rc.27 → 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/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 +9 -15
- package/dist/core/index.d.mts +9 -15
- package/dist/core/index.mjs +1 -1
- package/dist/{create-supabase-context--JXiHT_N.mjs → create-supabase-context-Bmwyha9p.mjs} +16 -5
- package/dist/{create-supabase-context-BO7DGfth.cjs → create-supabase-context-DDIAxA8h.cjs} +16 -5
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- 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-mePXRNu9.mjs → verify-auth-Bt2uGltH.mjs} +44 -21
- package/dist/{verify-auth-BjIehuNM.cjs → verify-auth-DrgvEuKo.cjs} +44 -21
- package/package.json +1 -1
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
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
2
|
import { i as EnvError, t as AuthError } from "../errors-O2ugIMec.cjs";
|
|
3
3
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
4
4
|
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
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
2
|
import { i as EnvError, t as AuthError } from "../errors-CAH-RRA3.mjs";
|
|
3
3
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
4
4
|
|
|
@@ -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, f as Errors, i as createContextClient, l as CreateSupabaseClientError, s as AuthError, t as verifyAuth, u as EnvError } from "./verify-auth-
|
|
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
|
/**
|
|
@@ -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
|
|
@@ -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
|
/**
|
|
@@ -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
|
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
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
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
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
|
|
@@ -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, 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 };
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
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
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
|
|
@@ -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, 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 };
|
|
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 { _ 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-
|
|
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
1
|
+
import { SupabaseClient, SupabaseClientOptions } from "@supabase/supabase-js";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/**
|
|
@@ -204,6 +204,50 @@ interface WithSupabaseConfig {
|
|
|
204
204
|
* @defaultValue `true`
|
|
205
205
|
*/
|
|
206
206
|
cors?: boolean | Record<string, string>;
|
|
207
|
+
/**
|
|
208
|
+
* Options forwarded to both internal `createClient()` calls.
|
|
209
|
+
*
|
|
210
|
+
* `accessToken` is stripped, and auth settings (`persistSession`, `autoRefreshToken`,
|
|
211
|
+
* `detectSessionInUrl`) are force-overwritten to server-safe values.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* withSupabase({
|
|
216
|
+
* allow: 'user',
|
|
217
|
+
* supabaseOptions: { db: { schema: 'api' } },
|
|
218
|
+
* }, handler)
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
supabaseOptions?: SupabaseClientOptions<string>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Auth identity for client creation functions.
|
|
225
|
+
*
|
|
226
|
+
* @see {@link verifyAuth}, {@link verifyCredentials}
|
|
227
|
+
*/
|
|
228
|
+
interface ClientAuth {
|
|
229
|
+
/** The caller's JWT, or `null` for anonymous access. */
|
|
230
|
+
token?: string | null;
|
|
231
|
+
/** Name of the API key to use. Falls back to `"default"`, then first available. */
|
|
232
|
+
keyName?: string | null;
|
|
233
|
+
}
|
|
234
|
+
/** Options for {@link createContextClient}. */
|
|
235
|
+
interface CreateContextClientOptions {
|
|
236
|
+
/** Auth identity — token and key name from the verified request. */
|
|
237
|
+
auth?: ClientAuth;
|
|
238
|
+
/** Override auto-detected environment variables. */
|
|
239
|
+
env?: Partial<SupabaseEnv>;
|
|
240
|
+
/** Options forwarded to `createClient()`. `accessToken` is stripped; auth settings are force-overwritten. */
|
|
241
|
+
supabaseOptions?: SupabaseClientOptions<string>;
|
|
242
|
+
}
|
|
243
|
+
/** Options for {@link createAdminClient}. */
|
|
244
|
+
interface CreateAdminClientOptions {
|
|
245
|
+
/** Auth identity — key name from the verified request. */
|
|
246
|
+
auth?: Pick<ClientAuth, 'keyName'>;
|
|
247
|
+
/** Override auto-detected environment variables. */
|
|
248
|
+
env?: Partial<SupabaseEnv>;
|
|
249
|
+
/** Options forwarded to `createClient()`. `accessToken` is stripped; auth settings are force-overwritten. */
|
|
250
|
+
supabaseOptions?: SupabaseClientOptions<string>;
|
|
207
251
|
}
|
|
208
252
|
/**
|
|
209
253
|
* The Supabase context created for each authenticated request.
|
|
@@ -224,4 +268,4 @@ interface SupabaseContext<Database = unknown> {
|
|
|
224
268
|
authType: Allow;
|
|
225
269
|
}
|
|
226
270
|
//#endregion
|
|
227
|
-
export {
|
|
271
|
+
export { CreateAdminClientOptions as a, JWTClaims as c, UserClaims as d, WithSupabaseConfig as f, ClientAuth as i, SupabaseContext as l, AllowWithKey as n, CreateContextClientOptions as o, AuthResult as r, Credentials as s, Allow as t, SupabaseEnv as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
1
|
+
import { SupabaseClient, SupabaseClientOptions } from "@supabase/supabase-js";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/**
|
|
@@ -204,6 +204,50 @@ interface WithSupabaseConfig {
|
|
|
204
204
|
* @defaultValue `true`
|
|
205
205
|
*/
|
|
206
206
|
cors?: boolean | Record<string, string>;
|
|
207
|
+
/**
|
|
208
|
+
* Options forwarded to both internal `createClient()` calls.
|
|
209
|
+
*
|
|
210
|
+
* `accessToken` is stripped, and auth settings (`persistSession`, `autoRefreshToken`,
|
|
211
|
+
* `detectSessionInUrl`) are force-overwritten to server-safe values.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* withSupabase({
|
|
216
|
+
* allow: 'user',
|
|
217
|
+
* supabaseOptions: { db: { schema: 'api' } },
|
|
218
|
+
* }, handler)
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
supabaseOptions?: SupabaseClientOptions<string>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Auth identity for client creation functions.
|
|
225
|
+
*
|
|
226
|
+
* @see {@link verifyAuth}, {@link verifyCredentials}
|
|
227
|
+
*/
|
|
228
|
+
interface ClientAuth {
|
|
229
|
+
/** The caller's JWT, or `null` for anonymous access. */
|
|
230
|
+
token?: string | null;
|
|
231
|
+
/** Name of the API key to use. Falls back to `"default"`, then first available. */
|
|
232
|
+
keyName?: string | null;
|
|
233
|
+
}
|
|
234
|
+
/** Options for {@link createContextClient}. */
|
|
235
|
+
interface CreateContextClientOptions {
|
|
236
|
+
/** Auth identity — token and key name from the verified request. */
|
|
237
|
+
auth?: ClientAuth;
|
|
238
|
+
/** Override auto-detected environment variables. */
|
|
239
|
+
env?: Partial<SupabaseEnv>;
|
|
240
|
+
/** Options forwarded to `createClient()`. `accessToken` is stripped; auth settings are force-overwritten. */
|
|
241
|
+
supabaseOptions?: SupabaseClientOptions<string>;
|
|
242
|
+
}
|
|
243
|
+
/** Options for {@link createAdminClient}. */
|
|
244
|
+
interface CreateAdminClientOptions {
|
|
245
|
+
/** Auth identity — key name from the verified request. */
|
|
246
|
+
auth?: Pick<ClientAuth, 'keyName'>;
|
|
247
|
+
/** Override auto-detected environment variables. */
|
|
248
|
+
env?: Partial<SupabaseEnv>;
|
|
249
|
+
/** Options forwarded to `createClient()`. `accessToken` is stripped; auth settings are force-overwritten. */
|
|
250
|
+
supabaseOptions?: SupabaseClientOptions<string>;
|
|
207
251
|
}
|
|
208
252
|
/**
|
|
209
253
|
* The Supabase context created for each authenticated request.
|
|
@@ -224,4 +268,4 @@ interface SupabaseContext<Database = unknown> {
|
|
|
224
268
|
authType: Allow;
|
|
225
269
|
}
|
|
226
270
|
//#endregion
|
|
227
|
-
export {
|
|
271
|
+
export { CreateAdminClientOptions as a, JWTClaims as c, UserClaims as d, WithSupabaseConfig as f, ClientAuth as i, SupabaseContext as l, AllowWithKey as n, CreateContextClientOptions as o, AuthResult as r, Credentials as s, Allow as t, SupabaseEnv as u };
|
|
@@ -199,11 +199,8 @@ function resolveEnv(overrides) {
|
|
|
199
199
|
* Creates an admin Supabase client that bypasses Row-Level Security.
|
|
200
200
|
*
|
|
201
201
|
* Uses a secret key for authentication, giving full access to all data.
|
|
202
|
-
*
|
|
202
|
+
* Stateless — one client per request.
|
|
203
203
|
*
|
|
204
|
-
* @param env - Optional environment overrides (passed through to {@link resolveEnv}).
|
|
205
|
-
* @param keyName - Name of the secret key to use. Falls back to `"default"`, then first available.
|
|
206
|
-
* @returns A configured {@link SupabaseClient} with admin (service-role) privileges.
|
|
207
204
|
* @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
|
|
208
205
|
*
|
|
209
206
|
* @example
|
|
@@ -212,18 +209,32 @@ function resolveEnv(overrides) {
|
|
|
212
209
|
* const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
|
|
213
210
|
* ```
|
|
214
211
|
*/
|
|
215
|
-
function createAdminClient(
|
|
216
|
-
const { data: resolved, error } = resolveEnv(env);
|
|
212
|
+
function createAdminClient(options) {
|
|
213
|
+
const { data: resolved, error } = resolveEnv(options?.env);
|
|
217
214
|
if (error) throw error;
|
|
215
|
+
const keyName = options?.auth?.keyName;
|
|
216
|
+
const supabaseOptions = options?.supabaseOptions;
|
|
218
217
|
const name = keyName ?? "default";
|
|
219
218
|
const keys = resolved.secretKeys;
|
|
220
219
|
const secretKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
|
|
221
220
|
if (!secretKey) throw name === "default" ? Errors[MissingDefaultSecretKeyError]() : Errors[MissingSecretKeyError](name);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
221
|
+
const safeHeaders = { ...supabaseOptions?.global?.headers };
|
|
222
|
+
delete safeHeaders.Authorization;
|
|
223
|
+
delete safeHeaders.apikey;
|
|
224
|
+
return createClient(resolved.url, secretKey, {
|
|
225
|
+
...supabaseOptions,
|
|
226
|
+
accessToken: void 0,
|
|
227
|
+
global: {
|
|
228
|
+
...supabaseOptions?.global,
|
|
229
|
+
headers: safeHeaders
|
|
230
|
+
},
|
|
231
|
+
auth: {
|
|
232
|
+
...supabaseOptions?.auth,
|
|
233
|
+
persistSession: false,
|
|
234
|
+
autoRefreshToken: false,
|
|
235
|
+
detectSessionInUrl: false
|
|
236
|
+
}
|
|
237
|
+
});
|
|
227
238
|
}
|
|
228
239
|
|
|
229
240
|
//#endregion
|
|
@@ -232,32 +243,44 @@ function createAdminClient(env, keyName) {
|
|
|
232
243
|
* Creates a Supabase client scoped to the caller's context.
|
|
233
244
|
*
|
|
234
245
|
* Configured with a publishable key and (optionally) the caller's JWT,
|
|
235
|
-
* so Row-Level Security policies apply.
|
|
236
|
-
* (stateless, one client per request).
|
|
246
|
+
* so Row-Level Security policies apply. Stateless — one client per request.
|
|
237
247
|
*
|
|
238
|
-
* @param token - The caller's JWT, or `null` for anonymous access.
|
|
239
|
-
* @param env - Optional environment overrides (passed through to {@link resolveEnv}).
|
|
240
|
-
* @param keyName - Name of the publishable key to use. Falls back to `"default"`, then first available.
|
|
241
|
-
* @returns A configured {@link SupabaseClient} with RLS enforced.
|
|
242
248
|
* @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
|
|
243
249
|
*
|
|
244
250
|
* @example
|
|
245
251
|
* ```ts
|
|
246
252
|
* const { data: auth } = await verifyAuth(request, { allow: 'user' })
|
|
247
|
-
* const supabase = createContextClient(
|
|
253
|
+
* const supabase = createContextClient({
|
|
254
|
+
* auth: { token: auth.token, keyName: auth.keyName },
|
|
255
|
+
* })
|
|
248
256
|
* const { data } = await supabase.rpc('get_my_items')
|
|
249
257
|
* ```
|
|
250
258
|
*/
|
|
251
|
-
function createContextClient(
|
|
252
|
-
const { data: resolved, error } = resolveEnv(env);
|
|
259
|
+
function createContextClient(options) {
|
|
260
|
+
const { data: resolved, error } = resolveEnv(options?.env);
|
|
253
261
|
if (error) throw error;
|
|
262
|
+
const token = options?.auth?.token;
|
|
263
|
+
const keyName = options?.auth?.keyName;
|
|
264
|
+
const supabaseOptions = options?.supabaseOptions;
|
|
254
265
|
const name = keyName ?? "default";
|
|
255
266
|
const keys = resolved.publishableKeys;
|
|
256
267
|
const anonKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
|
|
257
268
|
if (!anonKey) throw name === "default" ? Errors[MissingDefaultPublishableKeyError]() : Errors[MissingPublishableKeyError](name);
|
|
269
|
+
const safeHeaders = { ...supabaseOptions?.global?.headers };
|
|
270
|
+
delete safeHeaders.Authorization;
|
|
271
|
+
delete safeHeaders.apikey;
|
|
258
272
|
return createClient(resolved.url, anonKey, {
|
|
259
|
-
|
|
273
|
+
...supabaseOptions,
|
|
274
|
+
accessToken: void 0,
|
|
275
|
+
global: {
|
|
276
|
+
...supabaseOptions?.global,
|
|
277
|
+
headers: {
|
|
278
|
+
...safeHeaders,
|
|
279
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
260
282
|
auth: {
|
|
283
|
+
...supabaseOptions?.auth,
|
|
261
284
|
persistSession: false,
|
|
262
285
|
autoRefreshToken: false,
|
|
263
286
|
detectSessionInUrl: false
|
|
@@ -199,11 +199,8 @@ function resolveEnv(overrides) {
|
|
|
199
199
|
* Creates an admin Supabase client that bypasses Row-Level Security.
|
|
200
200
|
*
|
|
201
201
|
* Uses a secret key for authentication, giving full access to all data.
|
|
202
|
-
*
|
|
202
|
+
* Stateless — one client per request.
|
|
203
203
|
*
|
|
204
|
-
* @param env - Optional environment overrides (passed through to {@link resolveEnv}).
|
|
205
|
-
* @param keyName - Name of the secret key to use. Falls back to `"default"`, then first available.
|
|
206
|
-
* @returns A configured {@link SupabaseClient} with admin (service-role) privileges.
|
|
207
204
|
* @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found.
|
|
208
205
|
*
|
|
209
206
|
* @example
|
|
@@ -212,18 +209,32 @@ function resolveEnv(overrides) {
|
|
|
212
209
|
* const { data } = await supabaseAdmin.from('audit_log').insert({ action: 'user_login' })
|
|
213
210
|
* ```
|
|
214
211
|
*/
|
|
215
|
-
function createAdminClient(
|
|
216
|
-
const { data: resolved, error } = resolveEnv(env);
|
|
212
|
+
function createAdminClient(options) {
|
|
213
|
+
const { data: resolved, error } = resolveEnv(options?.env);
|
|
217
214
|
if (error) throw error;
|
|
215
|
+
const keyName = options?.auth?.keyName;
|
|
216
|
+
const supabaseOptions = options?.supabaseOptions;
|
|
218
217
|
const name = keyName ?? "default";
|
|
219
218
|
const keys = resolved.secretKeys;
|
|
220
219
|
const secretKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
|
|
221
220
|
if (!secretKey) throw name === "default" ? Errors[MissingDefaultSecretKeyError]() : Errors[MissingSecretKeyError](name);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
221
|
+
const safeHeaders = { ...supabaseOptions?.global?.headers };
|
|
222
|
+
delete safeHeaders.Authorization;
|
|
223
|
+
delete safeHeaders.apikey;
|
|
224
|
+
return (0, _supabase_supabase_js.createClient)(resolved.url, secretKey, {
|
|
225
|
+
...supabaseOptions,
|
|
226
|
+
accessToken: void 0,
|
|
227
|
+
global: {
|
|
228
|
+
...supabaseOptions?.global,
|
|
229
|
+
headers: safeHeaders
|
|
230
|
+
},
|
|
231
|
+
auth: {
|
|
232
|
+
...supabaseOptions?.auth,
|
|
233
|
+
persistSession: false,
|
|
234
|
+
autoRefreshToken: false,
|
|
235
|
+
detectSessionInUrl: false
|
|
236
|
+
}
|
|
237
|
+
});
|
|
227
238
|
}
|
|
228
239
|
|
|
229
240
|
//#endregion
|
|
@@ -232,32 +243,44 @@ function createAdminClient(env, keyName) {
|
|
|
232
243
|
* Creates a Supabase client scoped to the caller's context.
|
|
233
244
|
*
|
|
234
245
|
* Configured with a publishable key and (optionally) the caller's JWT,
|
|
235
|
-
* so Row-Level Security policies apply.
|
|
236
|
-
* (stateless, one client per request).
|
|
246
|
+
* so Row-Level Security policies apply. Stateless — one client per request.
|
|
237
247
|
*
|
|
238
|
-
* @param token - The caller's JWT, or `null` for anonymous access.
|
|
239
|
-
* @param env - Optional environment overrides (passed through to {@link resolveEnv}).
|
|
240
|
-
* @param keyName - Name of the publishable key to use. Falls back to `"default"`, then first available.
|
|
241
|
-
* @returns A configured {@link SupabaseClient} with RLS enforced.
|
|
242
248
|
* @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified publishable key is not found.
|
|
243
249
|
*
|
|
244
250
|
* @example
|
|
245
251
|
* ```ts
|
|
246
252
|
* const { data: auth } = await verifyAuth(request, { allow: 'user' })
|
|
247
|
-
* const supabase = createContextClient(
|
|
253
|
+
* const supabase = createContextClient({
|
|
254
|
+
* auth: { token: auth.token, keyName: auth.keyName },
|
|
255
|
+
* })
|
|
248
256
|
* const { data } = await supabase.rpc('get_my_items')
|
|
249
257
|
* ```
|
|
250
258
|
*/
|
|
251
|
-
function createContextClient(
|
|
252
|
-
const { data: resolved, error } = resolveEnv(env);
|
|
259
|
+
function createContextClient(options) {
|
|
260
|
+
const { data: resolved, error } = resolveEnv(options?.env);
|
|
253
261
|
if (error) throw error;
|
|
262
|
+
const token = options?.auth?.token;
|
|
263
|
+
const keyName = options?.auth?.keyName;
|
|
264
|
+
const supabaseOptions = options?.supabaseOptions;
|
|
254
265
|
const name = keyName ?? "default";
|
|
255
266
|
const keys = resolved.publishableKeys;
|
|
256
267
|
const anonKey = keys[name] ?? (keyName == null ? Object.values(keys)[0] : void 0);
|
|
257
268
|
if (!anonKey) throw name === "default" ? Errors[MissingDefaultPublishableKeyError]() : Errors[MissingPublishableKeyError](name);
|
|
269
|
+
const safeHeaders = { ...supabaseOptions?.global?.headers };
|
|
270
|
+
delete safeHeaders.Authorization;
|
|
271
|
+
delete safeHeaders.apikey;
|
|
258
272
|
return (0, _supabase_supabase_js.createClient)(resolved.url, anonKey, {
|
|
259
|
-
|
|
273
|
+
...supabaseOptions,
|
|
274
|
+
accessToken: void 0,
|
|
275
|
+
global: {
|
|
276
|
+
...supabaseOptions?.global,
|
|
277
|
+
headers: {
|
|
278
|
+
...safeHeaders,
|
|
279
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
260
282
|
auth: {
|
|
283
|
+
...supabaseOptions?.auth,
|
|
261
284
|
persistSession: false,
|
|
262
285
|
autoRefreshToken: false,
|
|
263
286
|
detectSessionInUrl: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/server",
|
|
3
|
-
"version": "0.1.1-rc.
|
|
3
|
+
"version": "0.1.1-rc.28",
|
|
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",
|