@supabase/server 0.1.0-alpha.1 → 0.1.1-rc.25
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 +27 -1
- package/dist/adapters/hono/index.d.cts +27 -1
- package/dist/adapters/hono/index.d.mts +27 -1
- package/dist/adapters/hono/index.mjs +27 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/create-admin-client-Cp7FxI6O.d.cts +271 -0
- package/dist/create-admin-client-ZTnl1zMe.d.mts +271 -0
- package/dist/{create-supabase-context-BrSIe29v.mjs → create-supabase-context-CmWaH3s6.mjs} +21 -1
- package/dist/{create-supabase-context-DNWor6i_.cjs → create-supabase-context-DcVorGKG.cjs} +21 -1
- package/dist/index.cjs +45 -2
- package/dist/index.d.cts +48 -5
- package/dist/index.d.mts +48 -5
- package/dist/index.mjs +45 -2
- package/dist/types-ClmJ8pi8.d.mts +227 -0
- package/dist/types-CnKoFCMX.d.cts +227 -0
- package/dist/{verify-auth-DxUT0XoT.mjs → verify-auth-2S7zFfR-.mjs} +217 -0
- package/dist/{verify-auth-6a1UPrFz.cjs → verify-auth-DvRVnjdq.cjs} +217 -0
- package/dist/wrappers/index.cjs +19 -0
- package/dist/wrappers/index.d.cts +19 -0
- package/dist/wrappers/index.d.mts +19 -0
- package/dist/wrappers/index.mjs +19 -0
- package/package.json +1 -1
- package/dist/create-admin-client-BZ_3qcxI.d.cts +0 -60
- package/dist/create-admin-client-CSX-Q_Fv.d.mts +0 -60
- package/dist/types-BLM5-qA8.d.mts +0 -59
- package/dist/types-DNh3Z1O1.d.cts +0 -59
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
//#region src/wrappers/webhook.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Verifies a webhook signature using HMAC-SHA256 with timing-safe comparison.
|
|
4
|
+
*
|
|
5
|
+
* @param payload - The raw request body as a string.
|
|
6
|
+
* @param signature - The hex-encoded signature from the webhook header.
|
|
7
|
+
* @param secret - The shared secret used to sign webhooks.
|
|
8
|
+
* @returns `true` if the signature is valid, `false` otherwise.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const payload = await req.text()
|
|
13
|
+
* const signature = req.headers.get('x-webhook-signature') ?? ''
|
|
14
|
+
*
|
|
15
|
+
* const isValid = await verifyWebhookSignature(payload, signature, secret)
|
|
16
|
+
* if (!isValid) {
|
|
17
|
+
* return Response.json({ error: 'Invalid signature' }, { status: 401 })
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
2
21
|
declare function verifyWebhookSignature(payload: string, signature: string, secret: string): Promise<boolean>;
|
|
3
22
|
//#endregion
|
|
4
23
|
export { verifyWebhookSignature };
|
package/dist/wrappers/index.mjs
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
//#region src/wrappers/webhook.ts
|
|
2
2
|
const encoder = new TextEncoder();
|
|
3
|
+
/**
|
|
4
|
+
* Verifies a webhook signature using HMAC-SHA256 with timing-safe comparison.
|
|
5
|
+
*
|
|
6
|
+
* @param payload - The raw request body as a string.
|
|
7
|
+
* @param signature - The hex-encoded signature from the webhook header.
|
|
8
|
+
* @param secret - The shared secret used to sign webhooks.
|
|
9
|
+
* @returns `true` if the signature is valid, `false` otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const payload = await req.text()
|
|
14
|
+
* const signature = req.headers.get('x-webhook-signature') ?? ''
|
|
15
|
+
*
|
|
16
|
+
* const isValid = await verifyWebhookSignature(payload, signature, secret)
|
|
17
|
+
* if (!isValid) {
|
|
18
|
+
* return Response.json({ error: 'Invalid signature' }, { status: 401 })
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
3
22
|
async function verifyWebhookSignature(payload, signature, secret) {
|
|
4
23
|
const key = await crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
5
24
|
name: "HMAC",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-rc.25",
|
|
4
4
|
"description": "Server-side utilities for Supabase. Handles auth, client creation, and context injection so you write business logic, not boilerplate.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"edge",
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "./types-DNh3Z1O1.cjs";
|
|
2
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
|
-
|
|
4
|
-
//#region src/errors.d.ts
|
|
5
|
-
declare class EnvError extends Error {
|
|
6
|
-
readonly status = 500;
|
|
7
|
-
readonly code: string;
|
|
8
|
-
constructor(message: string, code?: string);
|
|
9
|
-
}
|
|
10
|
-
declare class AuthError extends Error {
|
|
11
|
-
readonly status: number;
|
|
12
|
-
readonly code: string;
|
|
13
|
-
constructor(message: string, code?: string, status?: number);
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/core/resolve-env.d.ts
|
|
17
|
-
declare function resolveEnv(overrides?: Partial<SupabaseEnv>): {
|
|
18
|
-
data: SupabaseEnv;
|
|
19
|
-
error: null;
|
|
20
|
-
} | {
|
|
21
|
-
data: null;
|
|
22
|
-
error: EnvError;
|
|
23
|
-
};
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/core/extract-credentials.d.ts
|
|
26
|
-
declare function extractCredentials(request: Request): Credentials;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/core/verify-credentials.d.ts
|
|
29
|
-
interface VerifyCredentialsOptions {
|
|
30
|
-
allow: AllowWithKey | AllowWithKey[];
|
|
31
|
-
env?: Partial<SupabaseEnv>;
|
|
32
|
-
}
|
|
33
|
-
declare function verifyCredentials(credentials: Credentials, options: VerifyCredentialsOptions): Promise<{
|
|
34
|
-
data: AuthResult;
|
|
35
|
-
error: null;
|
|
36
|
-
} | {
|
|
37
|
-
data: null;
|
|
38
|
-
error: AuthError;
|
|
39
|
-
}>;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/core/verify-auth.d.ts
|
|
42
|
-
interface VerifyAuthOptions {
|
|
43
|
-
allow: AllowWithKey | AllowWithKey[];
|
|
44
|
-
env?: Partial<SupabaseEnv>;
|
|
45
|
-
}
|
|
46
|
-
declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promise<{
|
|
47
|
-
data: AuthResult;
|
|
48
|
-
error: null;
|
|
49
|
-
} | {
|
|
50
|
-
data: null;
|
|
51
|
-
error: AuthError;
|
|
52
|
-
}>;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/core/create-context-client.d.ts
|
|
55
|
-
declare function createContextClient(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/core/create-admin-client.d.ts
|
|
58
|
-
declare function createAdminClient(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { extractCredentials as a, EnvError as c, verifyCredentials as i, createContextClient as n, resolveEnv as o, verifyAuth as r, AuthError as s, createAdminClient as t };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { i as Credentials, n as AllowWithKey, r as AuthResult, s as SupabaseEnv } from "./types-BLM5-qA8.mjs";
|
|
2
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
|
-
|
|
4
|
-
//#region src/errors.d.ts
|
|
5
|
-
declare class EnvError extends Error {
|
|
6
|
-
readonly status = 500;
|
|
7
|
-
readonly code: string;
|
|
8
|
-
constructor(message: string, code?: string);
|
|
9
|
-
}
|
|
10
|
-
declare class AuthError extends Error {
|
|
11
|
-
readonly status: number;
|
|
12
|
-
readonly code: string;
|
|
13
|
-
constructor(message: string, code?: string, status?: number);
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/core/resolve-env.d.ts
|
|
17
|
-
declare function resolveEnv(overrides?: Partial<SupabaseEnv>): {
|
|
18
|
-
data: SupabaseEnv;
|
|
19
|
-
error: null;
|
|
20
|
-
} | {
|
|
21
|
-
data: null;
|
|
22
|
-
error: EnvError;
|
|
23
|
-
};
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/core/extract-credentials.d.ts
|
|
26
|
-
declare function extractCredentials(request: Request): Credentials;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/core/verify-credentials.d.ts
|
|
29
|
-
interface VerifyCredentialsOptions {
|
|
30
|
-
allow: AllowWithKey | AllowWithKey[];
|
|
31
|
-
env?: Partial<SupabaseEnv>;
|
|
32
|
-
}
|
|
33
|
-
declare function verifyCredentials(credentials: Credentials, options: VerifyCredentialsOptions): Promise<{
|
|
34
|
-
data: AuthResult;
|
|
35
|
-
error: null;
|
|
36
|
-
} | {
|
|
37
|
-
data: null;
|
|
38
|
-
error: AuthError;
|
|
39
|
-
}>;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/core/verify-auth.d.ts
|
|
42
|
-
interface VerifyAuthOptions {
|
|
43
|
-
allow: AllowWithKey | AllowWithKey[];
|
|
44
|
-
env?: Partial<SupabaseEnv>;
|
|
45
|
-
}
|
|
46
|
-
declare function verifyAuth(request: Request, options: VerifyAuthOptions): Promise<{
|
|
47
|
-
data: AuthResult;
|
|
48
|
-
error: null;
|
|
49
|
-
} | {
|
|
50
|
-
data: null;
|
|
51
|
-
error: AuthError;
|
|
52
|
-
}>;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/core/create-context-client.d.ts
|
|
55
|
-
declare function createContextClient(token?: string | null, env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/core/create-admin-client.d.ts
|
|
58
|
-
declare function createAdminClient(env?: Partial<SupabaseEnv>, keyName?: string | null): SupabaseClient;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { extractCredentials as a, EnvError as c, verifyCredentials as i, createContextClient as n, resolveEnv as o, verifyAuth as r, AuthError as s, createAdminClient as t };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
type Allow = 'always' | 'public' | 'secret' | 'user';
|
|
5
|
-
type AllowWithKey = Allow | `public:${string}` | `secret:${string}`;
|
|
6
|
-
interface SupabaseEnv {
|
|
7
|
-
url: string;
|
|
8
|
-
publishableKeys: Record<string, string>;
|
|
9
|
-
secretKeys: Record<string, string>;
|
|
10
|
-
jwks: JsonWebKeySet | null;
|
|
11
|
-
}
|
|
12
|
-
interface JsonWebKeySet {
|
|
13
|
-
keys: JsonWebKey[];
|
|
14
|
-
}
|
|
15
|
-
interface Credentials {
|
|
16
|
-
token: string | null;
|
|
17
|
-
apikey: string | null;
|
|
18
|
-
}
|
|
19
|
-
interface AuthResult {
|
|
20
|
-
authType: Allow;
|
|
21
|
-
token: string | null;
|
|
22
|
-
userClaims: UserClaims | null;
|
|
23
|
-
claims: JWTClaims | null;
|
|
24
|
-
keyName?: string | null;
|
|
25
|
-
}
|
|
26
|
-
interface JWTClaims {
|
|
27
|
-
sub: string;
|
|
28
|
-
iss?: string;
|
|
29
|
-
aud?: string | string[];
|
|
30
|
-
exp?: number;
|
|
31
|
-
iat?: number;
|
|
32
|
-
role?: string;
|
|
33
|
-
email?: string;
|
|
34
|
-
app_metadata?: Record<string, unknown>;
|
|
35
|
-
user_metadata?: Record<string, unknown>;
|
|
36
|
-
[key: string]: unknown;
|
|
37
|
-
}
|
|
38
|
-
interface UserClaims {
|
|
39
|
-
id: string;
|
|
40
|
-
role?: string;
|
|
41
|
-
email?: string;
|
|
42
|
-
appMetadata?: Record<string, unknown>;
|
|
43
|
-
userMetadata?: Record<string, unknown>;
|
|
44
|
-
}
|
|
45
|
-
interface WithSupabaseConfig {
|
|
46
|
-
allow?: AllowWithKey | AllowWithKey[];
|
|
47
|
-
env?: Partial<SupabaseEnv>;
|
|
48
|
-
cors?: boolean | Record<string, string>;
|
|
49
|
-
}
|
|
50
|
-
interface SupabaseContext {
|
|
51
|
-
supabase: SupabaseClient;
|
|
52
|
-
supabaseAdmin: SupabaseClient;
|
|
53
|
-
/** JWT-derived identity. For the full Supabase User object, call `supabase.auth.getUser()`. */
|
|
54
|
-
userClaims: UserClaims | null;
|
|
55
|
-
claims: JWTClaims | null;
|
|
56
|
-
authType: Allow;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
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 };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
type Allow = 'always' | 'public' | 'secret' | 'user';
|
|
5
|
-
type AllowWithKey = Allow | `public:${string}` | `secret:${string}`;
|
|
6
|
-
interface SupabaseEnv {
|
|
7
|
-
url: string;
|
|
8
|
-
publishableKeys: Record<string, string>;
|
|
9
|
-
secretKeys: Record<string, string>;
|
|
10
|
-
jwks: JsonWebKeySet | null;
|
|
11
|
-
}
|
|
12
|
-
interface JsonWebKeySet {
|
|
13
|
-
keys: JsonWebKey[];
|
|
14
|
-
}
|
|
15
|
-
interface Credentials {
|
|
16
|
-
token: string | null;
|
|
17
|
-
apikey: string | null;
|
|
18
|
-
}
|
|
19
|
-
interface AuthResult {
|
|
20
|
-
authType: Allow;
|
|
21
|
-
token: string | null;
|
|
22
|
-
userClaims: UserClaims | null;
|
|
23
|
-
claims: JWTClaims | null;
|
|
24
|
-
keyName?: string | null;
|
|
25
|
-
}
|
|
26
|
-
interface JWTClaims {
|
|
27
|
-
sub: string;
|
|
28
|
-
iss?: string;
|
|
29
|
-
aud?: string | string[];
|
|
30
|
-
exp?: number;
|
|
31
|
-
iat?: number;
|
|
32
|
-
role?: string;
|
|
33
|
-
email?: string;
|
|
34
|
-
app_metadata?: Record<string, unknown>;
|
|
35
|
-
user_metadata?: Record<string, unknown>;
|
|
36
|
-
[key: string]: unknown;
|
|
37
|
-
}
|
|
38
|
-
interface UserClaims {
|
|
39
|
-
id: string;
|
|
40
|
-
role?: string;
|
|
41
|
-
email?: string;
|
|
42
|
-
appMetadata?: Record<string, unknown>;
|
|
43
|
-
userMetadata?: Record<string, unknown>;
|
|
44
|
-
}
|
|
45
|
-
interface WithSupabaseConfig {
|
|
46
|
-
allow?: AllowWithKey | AllowWithKey[];
|
|
47
|
-
env?: Partial<SupabaseEnv>;
|
|
48
|
-
cors?: boolean | Record<string, string>;
|
|
49
|
-
}
|
|
50
|
-
interface SupabaseContext {
|
|
51
|
-
supabase: SupabaseClient;
|
|
52
|
-
supabaseAdmin: SupabaseClient;
|
|
53
|
-
/** JWT-derived identity. For the full Supabase User object, call `supabase.auth.getUser()`. */
|
|
54
|
-
userClaims: UserClaims | null;
|
|
55
|
-
claims: JWTClaims | null;
|
|
56
|
-
authType: Allow;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
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 };
|