@deepkey/sdk 1.0.0 → 1.2.0
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 +132 -2
- package/dist/chunk-J4IK2N4V.js +61 -0
- package/dist/chunk-J4IK2N4V.js.map +1 -0
- package/dist/{constants-BQhswdms.d.cts → constants-ByCalul7.d.cts} +34 -1
- package/dist/{constants-BQhswdms.d.ts → constants-ByCalul7.d.ts} +34 -1
- package/dist/index.cjs +52 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.js +42 -34
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +100 -28
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +36 -7
- package/dist/server.d.ts +36 -7
- package/dist/server.js +65 -29
- package/dist/server.js.map +1 -1
- package/package.json +8 -7
- package/dist/chunk-IFNRLMVX.js +0 -23
- package/dist/chunk-IFNRLMVX.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -1,42 +1,78 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthError,
|
|
3
3
|
DEEPKEY_API_URL,
|
|
4
|
+
request,
|
|
4
5
|
resolveBaseUrl
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J4IK2N4V.js";
|
|
6
7
|
|
|
7
8
|
// src/server.ts
|
|
8
9
|
var createServerClient = (secretKey, options = {}) => {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const base = { apikey: secretKey, baseUrl: resolveBaseUrl(options.__internalBaseUrl), fetchImpl: options.fetch };
|
|
11
|
+
const connection = (id) => `/auth/v1/connections/${encodeURIComponent(id)}`;
|
|
11
12
|
return {
|
|
12
13
|
auth: {
|
|
13
14
|
async getUser(jwt) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
const { data, error } = await request({ ...base, method: "GET", path: "/auth/v1/user", accessToken: jwt });
|
|
16
|
+
return { data: { user: data }, error };
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
connections: {
|
|
20
|
+
async list({ userId }) {
|
|
21
|
+
const { data, error } = await request({
|
|
22
|
+
...base,
|
|
23
|
+
method: "GET",
|
|
24
|
+
path: `/auth/v1/connections?user_id=${encodeURIComponent(userId)}`
|
|
25
|
+
});
|
|
26
|
+
return { data: { connections: data?.connections ?? [] }, error };
|
|
27
|
+
},
|
|
28
|
+
async issueAccessToken(connectionId) {
|
|
29
|
+
return request({
|
|
30
|
+
...base,
|
|
31
|
+
method: "POST",
|
|
32
|
+
path: `${connection(connectionId)}/token`,
|
|
33
|
+
body: {}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
async revoke(connectionId) {
|
|
37
|
+
const { error } = await request({ ...base, method: "DELETE", path: connection(connectionId) });
|
|
38
|
+
return { error };
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
apiKeys: {
|
|
42
|
+
async create({ userId, name }) {
|
|
43
|
+
const { data, error } = await request({
|
|
44
|
+
...base,
|
|
45
|
+
method: "POST",
|
|
46
|
+
path: "/auth/v1/api-keys",
|
|
47
|
+
body: { user_id: userId, name }
|
|
48
|
+
});
|
|
49
|
+
return { data: { apiKey: data?.api_key ?? null, key: data?.key ?? null }, error };
|
|
50
|
+
},
|
|
51
|
+
async list({ userId }) {
|
|
52
|
+
const { data, error } = await request({
|
|
53
|
+
...base,
|
|
54
|
+
method: "GET",
|
|
55
|
+
path: `/auth/v1/api-keys?user_id=${encodeURIComponent(userId)}`
|
|
56
|
+
});
|
|
57
|
+
return { data: { apiKeys: data?.api_keys ?? [] }, error };
|
|
58
|
+
},
|
|
59
|
+
async revoke(apiKeyId) {
|
|
60
|
+
const { error } = await request({
|
|
61
|
+
...base,
|
|
62
|
+
method: "DELETE",
|
|
63
|
+
path: `/auth/v1/api-keys/${encodeURIComponent(apiKeyId)}`
|
|
64
|
+
});
|
|
65
|
+
return { error };
|
|
66
|
+
},
|
|
67
|
+
// The key travels in the request body so it never reaches a URL or an access log.
|
|
68
|
+
async verify(apiKey) {
|
|
69
|
+
const { data, error } = await request({
|
|
70
|
+
...base,
|
|
71
|
+
method: "POST",
|
|
72
|
+
path: "/auth/v1/api-keys/verify",
|
|
73
|
+
body: { api_key: apiKey }
|
|
74
|
+
});
|
|
75
|
+
return { data: { user: data?.user ?? null, apiKey: data?.api_key ?? null }, error };
|
|
40
76
|
}
|
|
41
77
|
}
|
|
42
78
|
};
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { resolveBaseUrl } from './constants'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { resolveBaseUrl } from './constants'\nimport { request } from './fetch'\nimport type {\n AuthError,\n AuthResponse,\n ProviderAccessToken,\n ProviderConnection,\n ServerClientOptions,\n User,\n UserApiKey,\n} from './types'\n\nexport interface ServerAuthClient {\n auth: {\n // Mirrors `supabase.auth.getUser(jwt)` server-side: validates the access token\n // against the auth service and returns the user.\n getUser(jwt: string): Promise<AuthResponse<{ user: User | null }>>\n }\n // Provider connections a user granted through the browser SDK. The secret key acts\n // for the whole project; provider access tokens are issued only here, never to browsers.\n connections: {\n list(params: { userId: string }): Promise<AuthResponse<{ connections: ProviderConnection[] }>>\n issueAccessToken(connectionId: string): Promise<AuthResponse<ProviderAccessToken | null>>\n revoke(connectionId: string): Promise<{ error: AuthError | null }>\n }\n // Long-lived keys your application issues to its own users. Every call uses the secret\n // key; `verify` is the API-key counterpart of `auth.getUser(jwt)` and returns the same user.\n apiKeys: {\n // `key` is the plaintext. It is returned here once and cannot be read again.\n create(params: {\n userId: string\n name?: string\n }): Promise<AuthResponse<{ apiKey: UserApiKey | null; key: string | null }>>\n list(params: { userId: string }): Promise<AuthResponse<{ apiKeys: UserApiKey[] }>>\n revoke(apiKeyId: string): Promise<{ error: AuthError | null }>\n verify(apiKey: string): Promise<AuthResponse<{ user: User | null; apiKey: UserApiKey | null }>>\n }\n}\n\n// Runs anywhere with global fetch (Bun, Node >= 18). `secretKey` is the project's\n// bt_secret_... key. Requests target the hosted DeepKey API; the internal\n// override is reserved for DeepKey's console and tests.\nexport const createServerClient = (secretKey: string, options: ServerClientOptions = {}): ServerAuthClient => {\n const base = { apikey: secretKey, baseUrl: resolveBaseUrl(options.__internalBaseUrl), fetchImpl: options.fetch }\n const connection = (id: string) => `/auth/v1/connections/${encodeURIComponent(id)}`\n\n return {\n auth: {\n async getUser(jwt: string) {\n const { data, error } = await request<User>({ ...base, method: 'GET', path: '/auth/v1/user', accessToken: jwt })\n return { data: { user: data }, error }\n },\n },\n connections: {\n async list({ userId }) {\n const { data, error } = await request<{ connections: ProviderConnection[] }>({\n ...base,\n method: 'GET',\n path: `/auth/v1/connections?user_id=${encodeURIComponent(userId)}`,\n })\n return { data: { connections: data?.connections ?? [] }, error }\n },\n async issueAccessToken(connectionId) {\n return request<ProviderAccessToken>({\n ...base,\n method: 'POST',\n path: `${connection(connectionId)}/token`,\n body: {},\n })\n },\n async revoke(connectionId) {\n const { error } = await request({ ...base, method: 'DELETE', path: connection(connectionId) })\n return { error }\n },\n },\n apiKeys: {\n async create({ userId, name }) {\n const { data, error } = await request<{ api_key: UserApiKey; key: string }>({\n ...base,\n method: 'POST',\n path: '/auth/v1/api-keys',\n body: { user_id: userId, name },\n })\n return { data: { apiKey: data?.api_key ?? null, key: data?.key ?? null }, error }\n },\n async list({ userId }) {\n const { data, error } = await request<{ api_keys: UserApiKey[] }>({\n ...base,\n method: 'GET',\n path: `/auth/v1/api-keys?user_id=${encodeURIComponent(userId)}`,\n })\n return { data: { apiKeys: data?.api_keys ?? [] }, error }\n },\n async revoke(apiKeyId) {\n const { error } = await request({\n ...base,\n method: 'DELETE',\n path: `/auth/v1/api-keys/${encodeURIComponent(apiKeyId)}`,\n })\n return { error }\n },\n // The key travels in the request body so it never reaches a URL or an access log.\n async verify(apiKey) {\n const { data, error } = await request<{ user: User; api_key: UserApiKey }>({\n ...base,\n method: 'POST',\n path: '/auth/v1/api-keys/verify',\n body: { api_key: apiKey },\n })\n return { data: { user: data?.user ?? null, apiKey: data?.api_key ?? null }, error }\n },\n },\n }\n}\n\nexport { DEEPKEY_API_URL } from './constants'\nexport {\n AuthError,\n type AuthResponse,\n type ProviderAccessToken,\n type ProviderConnection,\n type ServerClientOptions,\n type User,\n type UserApiKey,\n} from './types'\n"],"mappings":";;;;;;;;AA0CO,IAAM,qBAAqB,CAAC,WAAmB,UAA+B,CAAC,MAAwB;AAC5G,QAAM,OAAO,EAAE,QAAQ,WAAW,SAAS,eAAe,QAAQ,iBAAiB,GAAG,WAAW,QAAQ,MAAM;AAC/G,QAAM,aAAa,CAAC,OAAe,wBAAwB,mBAAmB,EAAE,CAAC;AAEjF,SAAO;AAAA,IACL,MAAM;AAAA,MACJ,MAAM,QAAQ,KAAa;AACzB,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,QAAc,EAAE,GAAG,MAAM,QAAQ,OAAO,MAAM,iBAAiB,aAAa,IAAI,CAAC;AAC/G,eAAO,EAAE,MAAM,EAAE,MAAM,KAAK,GAAG,MAAM;AAAA,MACvC;AAAA,IACF;AAAA,IACA,aAAa;AAAA,MACX,MAAM,KAAK,EAAE,OAAO,GAAG;AACrB,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,QAA+C;AAAA,UAC3E,GAAG;AAAA,UACH,QAAQ;AAAA,UACR,MAAM,gCAAgC,mBAAmB,MAAM,CAAC;AAAA,QAClE,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AACD,eAAO,EAAE,MAAM;AAAA,MACjB;AAAA;AAAA,MAEA,MAAM,OAAO,QAAQ;AACnB,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,QAA6C;AAAA,UACzE,GAAG;AAAA,UACH,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,MAAM,EAAE,SAAS,OAAO;AAAA,QAC1B,CAAC;AACD,eAAO,EAAE,MAAM,EAAE,MAAM,MAAM,QAAQ,MAAM,QAAQ,MAAM,WAAW,KAAK,GAAG,MAAM;AAAA,MACpF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepkey/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "DeepKey authentication SDK for the browser and server — a supabase-js compatible auth surface",
|
|
5
5
|
"homepage": "https://deepkey.dev/sdk",
|
|
6
6
|
"keywords": [
|
|
@@ -31,6 +31,12 @@
|
|
|
31
31
|
"main": "./dist/index.cjs",
|
|
32
32
|
"module": "./dist/index.js",
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"prepublishOnly": "pnpm build"
|
|
39
|
+
},
|
|
34
40
|
"publishConfig": {
|
|
35
41
|
"access": "public"
|
|
36
42
|
},
|
|
@@ -39,10 +45,5 @@
|
|
|
39
45
|
"tsup": "^8.5.0",
|
|
40
46
|
"typescript": "^5.9.3",
|
|
41
47
|
"vitest": "^4.0.18"
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "tsup",
|
|
45
|
-
"typecheck": "tsc --noEmit",
|
|
46
|
-
"test": "vitest run"
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
+
}
|
package/dist/chunk-IFNRLMVX.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// src/constants.ts
|
|
2
|
-
var DEEPKEY_API_URL = "https://deepkey.dev/api";
|
|
3
|
-
var resolveBaseUrl = (url) => {
|
|
4
|
-
const candidate = typeof url === "string" ? url.trim() : "";
|
|
5
|
-
return (candidate || DEEPKEY_API_URL).replace(/\/+$/, "");
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/types.ts
|
|
9
|
-
var AuthError = class extends Error {
|
|
10
|
-
constructor(message, status, code) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "AuthError";
|
|
13
|
-
this.status = status;
|
|
14
|
-
this.code = code;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
DEEPKEY_API_URL,
|
|
20
|
-
resolveBaseUrl,
|
|
21
|
-
AuthError
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=chunk-IFNRLMVX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/types.ts"],"sourcesContent":["// The hosted DeepKey API. Every client talks to this origin; only DeepKey's own\n// console and test suites replace it through the internal override.\nexport const DEEPKEY_API_URL = 'https://deepkey.dev/api'\n\n// Resolves the base URL used for every request. An absent or blank internal\n// override keeps the hosted API; a provided value has any trailing slash removed\n// so path joins stay predictable.\nexport const resolveBaseUrl = (url?: string | null): string => {\n const candidate = typeof url === 'string' ? url.trim() : ''\n return (candidate || DEEPKEY_API_URL).replace(/\\/+$/, '')\n}\n","export interface UserIdentity {\n identity_id: string\n id: string\n user_id: string\n provider: string\n identity_data: Record<string, unknown>\n last_sign_in_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface User {\n id: string\n aud: string\n role: string\n email: string | null\n email_confirmed_at: string | null\n app_metadata: { provider?: string | null; providers?: string[]; [key: string]: unknown }\n user_metadata: {\n name?: string\n full_name?: string\n avatar_url?: string\n picture?: string\n email?: string\n [key: string]: unknown\n }\n identities?: UserIdentity[]\n created_at: string\n updated_at?: string\n last_sign_in_at?: string | null\n}\n\nexport interface Session {\n access_token: string\n refresh_token: string\n token_type: 'bearer'\n expires_in: number\n expires_at: number\n user: User\n}\n\nexport class AuthError extends Error {\n status?: number\n code?: string\n\n constructor(message: string, status?: number, code?: string) {\n super(message)\n this.name = 'AuthError'\n this.status = status\n this.code = code\n }\n}\n\nexport type AuthChangeEvent = 'INITIAL_SESSION' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED'\n\nexport interface Subscription {\n id: string\n unsubscribe: () => void\n}\n\nexport interface StorageAdapter {\n getItem(key: string): string | null\n setItem(key: string, value: string): void\n removeItem(key: string): void\n}\n\nexport interface AuthClientOptions {\n /**\n * @internal Replaces the hosted DeepKey API origin. Used only by DeepKey's own\n * console and test suites; not supported for consumers and stripped from the\n * published type declarations.\n */\n __internalBaseUrl?: string\n storageKey?: string\n autoRefreshToken?: boolean\n detectSessionInUrl?: boolean\n persistSession?: boolean\n storage?: StorageAdapter\n fetch?: typeof fetch\n}\n\nexport interface ServerClientOptions {\n /**\n * @internal Replaces the hosted DeepKey API origin. Used only by DeepKey's own\n * console and test suites; not supported for consumers and stripped from the\n * published type declarations.\n */\n __internalBaseUrl?: string\n fetch?: typeof fetch\n}\n\nexport interface SignInWithOtpCredentials {\n email: string\n options?: {\n emailRedirectTo?: string\n shouldCreateUser?: boolean\n data?: Record<string, unknown>\n }\n}\n\nexport interface VerifyOtpParams {\n email: string\n token: string\n type: 'email' | 'magiclink'\n}\n\nexport interface SignInWithOAuthCredentials {\n provider: string\n options?: {\n redirectTo?: string\n scopes?: string\n queryParams?: Record<string, string>\n skipBrowserRedirect?: boolean\n }\n}\n\nexport interface AuthResponse<T> {\n data: T\n error: AuthError | null\n}\n"],"mappings":";AAEO,IAAM,kBAAkB;AAKxB,IAAM,iBAAiB,CAAC,QAAgC;AAC7D,QAAM,YAAY,OAAO,QAAQ,WAAW,IAAI,KAAK,IAAI;AACzD,UAAQ,aAAa,iBAAiB,QAAQ,QAAQ,EAAE;AAC1D;;;AC+BO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAInC,YAAY,SAAiB,QAAiB,MAAe;AAC3D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|