@settlemint/dalp-sdk 3.1.17 → 3.1.18-main.33796544973
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 +154 -169
- package/dist/auth/client.d.ts +113 -0
- package/dist/auth/live.d.ts +4366 -0
- package/dist/{auth-permissions.d.ts → auth/permissions.d.ts} +1 -2
- package/dist/{auth-wallet-plugins.d.ts → auth/wallet-plugins.d.ts} +69 -5
- package/dist/auth.d.ts +22 -115
- package/dist/auth.js +329 -0
- package/dist/bundler.d.ts +14 -207
- package/dist/bundler.js +99 -0
- package/dist/chunk-18qmk0m7.js +4 -0
- package/dist/chunk-def7rqy6.js +946 -0
- package/dist/chunk-f4t1bm86.js +67 -0
- package/dist/chunk-fjnq61hj.js +11 -0
- package/dist/chunk-h12fatty.js +63 -0
- package/dist/chunk-r0vsftj4.js +102 -0
- package/dist/chunk-rzmr29dq.js +260 -0
- package/dist/chunk-x0z79vz6.js +33 -0
- package/dist/chunk-y0d2c7kp.js +54 -0
- package/dist/client/conditional-request.d.ts +30 -0
- package/dist/client/factory.d.ts +14 -0
- package/dist/client/query-serializer.d.ts +2 -0
- package/dist/client/request-compression.d.ts +47 -0
- package/dist/client/ssr-fetch.d.ts +12 -0
- package/dist/effect.d.ts +69 -0
- package/dist/effect.js +82 -0
- package/dist/errors/api-error.d.ts +29 -0
- package/dist/errors/find-current-error.d.ts +8 -0
- package/dist/errors/sdk-error.d.ts +52 -0
- package/dist/errors/sdk-error.js +8 -0
- package/dist/generated/api-types.d.ts +41271 -0
- package/dist/generated/response-scalars.d.ts +9 -0
- package/dist/generated/routes.d.ts +12 -0
- package/dist/index.d.ts +28 -40
- package/dist/index.js +131 -96109
- package/dist/proxy/builder.d.ts +47 -0
- package/dist/proxy/client.d.ts +32 -0
- package/dist/proxy/fetch-executor.d.ts +28 -0
- package/dist/proxy/flat-args.d.ts +51 -0
- package/dist/proxy/settlement.d.ts +67 -0
- package/dist/proxy/sse.d.ts +54 -0
- package/dist/proxy/tanstack.d.ts +27 -0
- package/dist/proxy/transport.d.ts +73 -0
- package/dist/react-query.d.ts +16 -0
- package/dist/react-query.js +13 -0
- package/dist/readonly-deep.d.ts +12 -0
- package/dist/reads-as-funding-paused.d.ts +20 -0
- package/dist/routes/index.d.ts +20 -0
- package/dist/routes/index.js +10 -0
- package/dist/routes/types.d.ts +51 -0
- package/dist/runtime-exports.d.ts +20 -0
- package/dist/runtime-exports.js +16 -0
- package/dist/scalars/big-decimal.d.ts +16 -0
- package/dist/scalars/ethereum-address.d.ts +20 -0
- package/dist/scalars/exchange-rates.d.ts +27 -0
- package/dist/scalars/index.d.ts +18 -0
- package/dist/scalars/index.js +86 -0
- package/dist/scalars/organization-id.d.ts +20 -0
- package/dist/secret.d.ts +14 -0
- package/dist/sign-webhook-receipt.d.ts +76 -0
- package/dist/sign-webhook-receipt.js +26 -0
- package/dist/transport/cookie-store.d.ts +9 -0
- package/dist/transport/sse-lifecycle.d.ts +44 -0
- package/dist/types.d.ts +65 -102
- package/dist/url.d.ts +0 -1
- package/dist/verify-webhook.d.ts +17 -28
- package/dist/verify-webhook.js +8 -0
- package/dist/version.d.ts +0 -1
- package/dist/wait-for-transaction.d.ts +54 -81
- package/dist/wait-for-transaction.js +120 -0
- package/dist/webhook-events.d.ts +44 -27
- package/package.json +103 -30
- package/dist/auth-permissions.d.ts.map +0 -1
- package/dist/auth-wallet-plugins.d.ts.map +0 -1
- package/dist/auth.d.ts.map +0 -1
- package/dist/bundler.d.ts.map +0 -1
- package/dist/chunk-xm8h1dzh.js +0 -33
- package/dist/client.d.ts +0 -19
- package/dist/client.d.ts.map +0 -1
- package/dist/contract-errors.d.ts +0 -4156
- package/dist/contract-errors.d.ts.map +0 -1
- package/dist/contract.d.ts +0 -17
- package/dist/contract.d.ts.map +0 -1
- package/dist/cookie-store.d.ts +0 -10
- package/dist/cookie-store.d.ts.map +0 -1
- package/dist/dapi-errors.d.ts +0 -650
- package/dist/dapi-errors.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -633
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/platform.d.ts +0 -41
- package/dist/platform.d.ts.map +0 -1
- package/dist/plugins/index.d.ts +0 -13
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -10
- package/dist/sdk-error.d.ts +0 -74
- package/dist/sdk-error.d.ts.map +0 -1
- package/dist/serializers.d.ts +0 -41
- package/dist/serializers.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/url.d.ts.map +0 -1
- package/dist/verify-webhook.d.ts.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/wait-for-transaction.d.ts.map +0 -1
- package/dist/webhook-events.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-side Better Auth access-control metadata for DALP auth clients.
|
|
3
3
|
*
|
|
4
|
-
* Related: packages/
|
|
4
|
+
* Related: packages/dapi/auth/src/utils/permissions.ts, kit/sdk/src/auth/live.ts
|
|
5
5
|
*
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
@@ -10,4 +10,3 @@ export declare const accessControl: AccessControl;
|
|
|
10
10
|
export declare const adminRole: Role;
|
|
11
11
|
export declare const ownerRole: Role;
|
|
12
12
|
export declare const memberRole: Role;
|
|
13
|
-
//# sourceMappingURL=auth-permissions.d.ts.map
|
|
@@ -1,3 +1,69 @@
|
|
|
1
|
+
import type { DalpAuthResult } from "./client.ts";
|
|
2
|
+
export type WalletAuthOperation<TInput, TData> = (input: TInput, options?: unknown) => Promise<DalpAuthResult<TData>>;
|
|
3
|
+
/** Typed client actions supplied by the three DALP wallet-auth plugins. */
|
|
4
|
+
export interface DalpWalletAuthClient {
|
|
5
|
+
readonly wallet: {
|
|
6
|
+
readonly pincode: {
|
|
7
|
+
readonly enable: WalletAuthOperation<{
|
|
8
|
+
readonly pincode: string;
|
|
9
|
+
readonly password?: string;
|
|
10
|
+
}, {
|
|
11
|
+
readonly success: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
readonly update: WalletAuthOperation<{
|
|
14
|
+
readonly newPincode: string;
|
|
15
|
+
readonly password: string;
|
|
16
|
+
}, {
|
|
17
|
+
readonly success: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
readonly disable: WalletAuthOperation<{
|
|
20
|
+
readonly password: string;
|
|
21
|
+
}, {
|
|
22
|
+
readonly success: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
readonly reset: WalletAuthOperation<{
|
|
25
|
+
readonly newPincode: string;
|
|
26
|
+
readonly recoveryCode: string;
|
|
27
|
+
}, {
|
|
28
|
+
readonly success: boolean;
|
|
29
|
+
readonly recoveryCodes?: ReadonlyArray<string>;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
readonly twoFactor: {
|
|
33
|
+
readonly enable: WalletAuthOperation<{
|
|
34
|
+
readonly issuer?: string;
|
|
35
|
+
readonly password?: string;
|
|
36
|
+
}, {
|
|
37
|
+
readonly totpURI: string;
|
|
38
|
+
}>;
|
|
39
|
+
readonly verify: WalletAuthOperation<{
|
|
40
|
+
readonly code: string;
|
|
41
|
+
}, {
|
|
42
|
+
readonly status: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
readonly disable: WalletAuthOperation<{
|
|
45
|
+
readonly password: string;
|
|
46
|
+
}, {
|
|
47
|
+
readonly status: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
readonly secretCodes: {
|
|
51
|
+
readonly generate: WalletAuthOperation<{
|
|
52
|
+
readonly password?: string;
|
|
53
|
+
}, {
|
|
54
|
+
readonly rotated: boolean;
|
|
55
|
+
readonly secretCodes: ReadonlyArray<string>;
|
|
56
|
+
readonly verificationId: string;
|
|
57
|
+
}>;
|
|
58
|
+
readonly confirm: WalletAuthOperation<{
|
|
59
|
+
readonly stored: boolean;
|
|
60
|
+
readonly verificationId: string;
|
|
61
|
+
}, {
|
|
62
|
+
readonly success: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
1
67
|
export declare const walletPincodeClient: () => {
|
|
2
68
|
id: "wallet-pincode";
|
|
3
69
|
$InferServerPlugin: {
|
|
@@ -78,9 +144,7 @@ export declare const walletSecretCodesClient: () => {
|
|
|
78
144
|
signal: "$sessionSignal";
|
|
79
145
|
}[];
|
|
80
146
|
};
|
|
81
|
-
type StripLeadingSlash<T extends string> = T extends `/${infer Rest}` ? Rest : never;
|
|
82
|
-
type WalletPluginPathMethodKeys = keyof ReturnType<typeof walletPincodeClient>["pathMethods"] | keyof ReturnType<typeof walletTwoFactorClient>["pathMethods"] | keyof ReturnType<typeof walletSecretCodesClient>["pathMethods"];
|
|
147
|
+
export type StripLeadingSlash<T extends string> = T extends `/${infer Rest}` ? Rest : never;
|
|
148
|
+
export type WalletPluginPathMethodKeys = keyof ReturnType<typeof walletPincodeClient>["pathMethods"] | keyof ReturnType<typeof walletTwoFactorClient>["pathMethods"] | keyof ReturnType<typeof walletSecretCodesClient>["pathMethods"];
|
|
83
149
|
/** CLI coverage keys for DALP wallet Better Auth plugin endpoints (no leading slash). */
|
|
84
|
-
export type WalletAuthEndpointPath = StripLeadingSlash<WalletPluginPathMethodKeys
|
|
85
|
-
export {};
|
|
86
|
-
//# sourceMappingURL=auth-wallet-plugins.d.ts.map
|
|
150
|
+
export type WalletAuthEndpointPath = StripLeadingSlash<WalletPluginPathMethodKeys>;
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,115 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Custom `fetch` implementation.
|
|
25
|
-
* Use this to inject logging, proxy configuration, or test doubles.
|
|
26
|
-
*/
|
|
27
|
-
fetch?: typeof globalThis.fetch;
|
|
28
|
-
}
|
|
29
|
-
export interface DalpAuthError {
|
|
30
|
-
code?: string;
|
|
31
|
-
message?: string;
|
|
32
|
-
status?: number;
|
|
33
|
-
statusText?: string;
|
|
34
|
-
[key: string]: unknown;
|
|
35
|
-
}
|
|
36
|
-
export interface DalpAuthResult<TData = unknown, TError = DalpAuthError> {
|
|
37
|
-
data: TData | null;
|
|
38
|
-
error: TError | null;
|
|
39
|
-
}
|
|
40
|
-
export type DalpAuthOperation<TInput = Record<string, unknown>, TData = unknown> = (input?: TInput, options?: unknown) => Promise<DalpAuthResult<TData>>;
|
|
41
|
-
export interface DalpAuthClient {
|
|
42
|
-
signIn: Record<string, DalpAuthOperation> & {
|
|
43
|
-
email: DalpAuthOperation;
|
|
44
|
-
};
|
|
45
|
-
signUp: Record<string, DalpAuthOperation> & {
|
|
46
|
-
email: DalpAuthOperation;
|
|
47
|
-
};
|
|
48
|
-
getSession: DalpAuthOperation;
|
|
49
|
-
listSessions: DalpAuthOperation;
|
|
50
|
-
revokeSession: DalpAuthOperation;
|
|
51
|
-
revokeOtherSessions: DalpAuthOperation;
|
|
52
|
-
apiKey: Record<string, DalpAuthOperation> & {
|
|
53
|
-
create: DalpAuthOperation;
|
|
54
|
-
list: DalpAuthOperation;
|
|
55
|
-
delete: DalpAuthOperation;
|
|
56
|
-
};
|
|
57
|
-
organization: Record<string, DalpAuthOperation> & {
|
|
58
|
-
create: DalpAuthOperation;
|
|
59
|
-
list: DalpAuthOperation;
|
|
60
|
-
setActive: DalpAuthOperation;
|
|
61
|
-
inviteMember: DalpAuthOperation;
|
|
62
|
-
acceptInvitation: DalpAuthOperation;
|
|
63
|
-
listMembers: DalpAuthOperation;
|
|
64
|
-
addMember: DalpAuthOperation;
|
|
65
|
-
removeMember: DalpAuthOperation;
|
|
66
|
-
};
|
|
67
|
-
admin: Record<string, DalpAuthOperation> & {
|
|
68
|
-
listUsers: DalpAuthOperation;
|
|
69
|
-
createUser: DalpAuthOperation;
|
|
70
|
-
removeUser: DalpAuthOperation;
|
|
71
|
-
setRole: DalpAuthOperation;
|
|
72
|
-
};
|
|
73
|
-
device: Record<string, DalpAuthOperation> & {
|
|
74
|
-
code: DalpAuthOperation;
|
|
75
|
-
token: DalpAuthOperation;
|
|
76
|
-
approve: DalpAuthOperation;
|
|
77
|
-
deny: DalpAuthOperation;
|
|
78
|
-
};
|
|
79
|
-
passkey: Record<string, DalpAuthOperation>;
|
|
80
|
-
twoFactor: Record<string, DalpAuthOperation> & {
|
|
81
|
-
enable: DalpAuthOperation;
|
|
82
|
-
disable: DalpAuthOperation;
|
|
83
|
-
verifyTotp: DalpAuthOperation;
|
|
84
|
-
verifyBackupCode: DalpAuthOperation;
|
|
85
|
-
generateBackupCodes: DalpAuthOperation;
|
|
86
|
-
};
|
|
87
|
-
wallet: {
|
|
88
|
-
pincode: {
|
|
89
|
-
enable: DalpAuthOperation;
|
|
90
|
-
disable: DalpAuthOperation;
|
|
91
|
-
update: DalpAuthOperation;
|
|
92
|
-
reset: DalpAuthOperation;
|
|
93
|
-
};
|
|
94
|
-
twoFactor: {
|
|
95
|
-
enable: DalpAuthOperation;
|
|
96
|
-
disable: DalpAuthOperation;
|
|
97
|
-
verify: DalpAuthOperation;
|
|
98
|
-
};
|
|
99
|
-
secretCodes: {
|
|
100
|
-
generate: DalpAuthOperation;
|
|
101
|
-
confirm: DalpAuthOperation;
|
|
102
|
-
};
|
|
103
|
-
passkey: {
|
|
104
|
-
register: DalpAuthOperation;
|
|
105
|
-
complete: DalpAuthOperation;
|
|
106
|
-
disable: DalpAuthOperation;
|
|
107
|
-
challenge: DalpAuthOperation;
|
|
108
|
-
verify: DalpAuthOperation;
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
$fetch: (path: string, options?: Record<string, unknown>) => Promise<unknown>;
|
|
112
|
-
$ERROR_CODES: Record<string, unknown>;
|
|
113
|
-
}
|
|
114
|
-
export declare function createDalpAuthClient(config: DalpAuthClientConfig): DalpAuthClient;
|
|
115
|
-
//# sourceMappingURL=auth.d.ts.map
|
|
1
|
+
/**
|
|
2
|
+
* The DALP Better Auth client, on its own subpath.
|
|
3
|
+
*
|
|
4
|
+
* The generated SDK already exposes every auth REST operation, so nothing here
|
|
5
|
+
* exists to reach an endpoint. This surface exists for the parts a REST call
|
|
6
|
+
* cannot express: the session and cookie state machine, the plugin actions that
|
|
7
|
+
* run in the browser rather than over HTTP — `passkeyClient` drives the WebAuthn
|
|
8
|
+
* ceremony through `navigator.credentials` — and the access-control model that
|
|
9
|
+
* evaluates a permission locally instead of round-tripping `has-permission`.
|
|
10
|
+
*
|
|
11
|
+
* It is held off the package root because it costs roughly 70 KiB of Better
|
|
12
|
+
* Auth that a consumer who only calls operations should never pay.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
export { createDalpAuthClient, makeDalpAuthClient } from "./auth/live.ts";
|
|
17
|
+
export type { DalpAuthClient } from "./auth/live.ts";
|
|
18
|
+
export { decodeDalpAuthClientConfig } from "./auth/client.ts";
|
|
19
|
+
export type { DalpAuthClientConfig,
|
|
20
|
+
/** @deprecated Prefer `DalpAuthClient` — this is the typed operation surface, not a separate client. */
|
|
21
|
+
DalpCliAuthClient, DalpAuthError, DalpAuthOperation, DalpAuthResult, DalpOrganizationInvitation, DalpOrganizationInvitationsQuery, DalpOrganizationMember, DalpOrganizationMembersQuery, DecodedDalpAuthClientConfig, } from "./auth/client.ts";
|
|
22
|
+
export type { WalletAuthEndpointPath } from "./auth/wallet-plugins.ts";
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SDK_USER_AGENT,
|
|
3
|
+
createCookieStoreFetch,
|
|
4
|
+
makeCookieStore
|
|
5
|
+
} from "./chunk-rzmr29dq.js";
|
|
6
|
+
import {
|
|
7
|
+
normalizeDalpBaseUrl,
|
|
8
|
+
secret,
|
|
9
|
+
unwrapSecret
|
|
10
|
+
} from "./chunk-h12fatty.js";
|
|
11
|
+
import {
|
|
12
|
+
createDalpSdkConfigurationError
|
|
13
|
+
} from "./chunk-y0d2c7kp.js";
|
|
14
|
+
|
|
15
|
+
// src/auth/live.ts
|
|
16
|
+
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
17
|
+
import { passkeyClient } from "@better-auth/passkey/client";
|
|
18
|
+
import { createAuthClient as createBetterAuthClient } from "better-auth/client";
|
|
19
|
+
import {
|
|
20
|
+
adminClient,
|
|
21
|
+
customSessionClient,
|
|
22
|
+
deviceAuthorizationClient,
|
|
23
|
+
inferAdditionalFields,
|
|
24
|
+
organizationClient,
|
|
25
|
+
twoFactorClient
|
|
26
|
+
} from "better-auth/client/plugins";
|
|
27
|
+
|
|
28
|
+
// src/auth/client.ts
|
|
29
|
+
class AuthConfigError extends Error {
|
|
30
|
+
constructor(field, requirement) {
|
|
31
|
+
super(`\`${field}\` ${requirement}`);
|
|
32
|
+
this.name = "AuthConfigError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function optionalText(value, field) {
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value !== "string") {
|
|
40
|
+
return handleNonString(field);
|
|
41
|
+
}
|
|
42
|
+
const trimmed = value.trim();
|
|
43
|
+
if (trimmed.length === 0) {
|
|
44
|
+
throw new AuthConfigError(field, "must not be blank");
|
|
45
|
+
}
|
|
46
|
+
return trimmed;
|
|
47
|
+
}
|
|
48
|
+
function handleNonString(field) {
|
|
49
|
+
throw new AuthConfigError(field, "must be a string");
|
|
50
|
+
}
|
|
51
|
+
function requiredUrl(value) {
|
|
52
|
+
if (typeof value !== "string") {
|
|
53
|
+
return handleNonString("url");
|
|
54
|
+
}
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = new URL(value);
|
|
58
|
+
} catch {
|
|
59
|
+
throw new AuthConfigError("url", "must be a valid URL");
|
|
60
|
+
}
|
|
61
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
62
|
+
throw new AuthConfigError("url", "must use http or https");
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function optionalHeaders(value) {
|
|
67
|
+
if (value === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
71
|
+
throw new AuthConfigError("headers", "must be an object of strings");
|
|
72
|
+
}
|
|
73
|
+
const headers = {};
|
|
74
|
+
for (const [name, header] of Object.entries(value)) {
|
|
75
|
+
if (typeof header !== "string") {
|
|
76
|
+
throw new AuthConfigError("headers", "must be an object of strings");
|
|
77
|
+
}
|
|
78
|
+
headers[name] = header;
|
|
79
|
+
}
|
|
80
|
+
return headers;
|
|
81
|
+
}
|
|
82
|
+
function optionalFetch(value) {
|
|
83
|
+
if (value === undefined) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (typeof value !== "function") {
|
|
87
|
+
throw new AuthConfigError("fetch", "must be a function");
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
function optionalCookieStore(value) {
|
|
92
|
+
if (value === undefined) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const store = value;
|
|
96
|
+
if (typeof value !== "object" || value === null || typeof store.header !== "function" || typeof store.storeSetCookieHeaders !== "function") {
|
|
97
|
+
throw new AuthConfigError("cookieStore", "must expose header and storeSetCookieHeaders");
|
|
98
|
+
}
|
|
99
|
+
return store;
|
|
100
|
+
}
|
|
101
|
+
function decodeAuthConfig(input) {
|
|
102
|
+
const raw = input;
|
|
103
|
+
const apiKey = optionalText(raw.apiKey, "apiKey");
|
|
104
|
+
const sessionToken = optionalText(raw.sessionToken, "sessionToken");
|
|
105
|
+
const cookie = optionalText(raw.cookie, "cookie");
|
|
106
|
+
if ([apiKey, sessionToken, cookie].filter((credential) => credential !== undefined).length > 1) {
|
|
107
|
+
throw new AuthConfigError("apiKey/sessionToken/cookie", "configure only one auth credential source");
|
|
108
|
+
}
|
|
109
|
+
const url = requiredUrl(raw.url);
|
|
110
|
+
const cookieStore = optionalCookieStore(raw.cookieStore);
|
|
111
|
+
const organizationId = optionalText(raw.organizationId, "organizationId");
|
|
112
|
+
const headers = optionalHeaders(raw.headers);
|
|
113
|
+
const configuredFetch = optionalFetch(raw.fetch);
|
|
114
|
+
return {
|
|
115
|
+
url,
|
|
116
|
+
...apiKey === undefined ? {} : { apiKey: secret(apiKey) },
|
|
117
|
+
...sessionToken === undefined ? {} : { sessionToken: secret(sessionToken) },
|
|
118
|
+
...cookie === undefined ? {} : { cookie: secret(cookie) },
|
|
119
|
+
...cookieStore === undefined ? {} : { cookieStore },
|
|
120
|
+
...organizationId === undefined ? {} : { organizationId },
|
|
121
|
+
...headers === undefined ? {} : { headers },
|
|
122
|
+
...configuredFetch === undefined ? {} : { fetch: configuredFetch }
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function decodeDalpAuthClientConfig(input) {
|
|
126
|
+
try {
|
|
127
|
+
return decodeAuthConfig(input);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw createDalpSdkConfigurationError({
|
|
130
|
+
message: "DALP SDK: auth client configuration is invalid.",
|
|
131
|
+
why: "The auth client received a malformed URL, credential, header map, fetch seam, or cookie store.",
|
|
132
|
+
fix: "Pass one credential source, an HTTP(S) URL, and valid fetch and cookie-store seams.",
|
|
133
|
+
cause: error
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/auth/permissions.ts
|
|
139
|
+
import { createAccessControl } from "better-auth/plugins/access";
|
|
140
|
+
import { adminAc, defaultStatements as adminDefaultStatements } from "better-auth/plugins/admin/access";
|
|
141
|
+
import {
|
|
142
|
+
memberAc,
|
|
143
|
+
defaultStatements as organizationDefaultStatements,
|
|
144
|
+
ownerAc
|
|
145
|
+
} from "better-auth/plugins/organization/access";
|
|
146
|
+
var dalPermissions = {
|
|
147
|
+
organization: ["update", "delete", "list"],
|
|
148
|
+
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
149
|
+
system: ["read", "list", "create"],
|
|
150
|
+
exchangeRates: ["read", "list"]
|
|
151
|
+
};
|
|
152
|
+
var customPermissions = {
|
|
153
|
+
...adminDefaultStatements,
|
|
154
|
+
...organizationDefaultStatements,
|
|
155
|
+
...dalPermissions
|
|
156
|
+
};
|
|
157
|
+
var narrowAccessControl = createAccessControl(customPermissions);
|
|
158
|
+
var accessControl = createAccessControl({
|
|
159
|
+
...adminDefaultStatements,
|
|
160
|
+
...organizationDefaultStatements,
|
|
161
|
+
...dalPermissions
|
|
162
|
+
});
|
|
163
|
+
var adminRole = narrowAccessControl.newRole({
|
|
164
|
+
...adminAc.statements,
|
|
165
|
+
...ownerAc.statements,
|
|
166
|
+
organization: ["update", "delete", "list"],
|
|
167
|
+
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
168
|
+
system: ["read", "list", "create"],
|
|
169
|
+
exchangeRates: ["read", "list"]
|
|
170
|
+
});
|
|
171
|
+
var ownerRole = narrowAccessControl.newRole({
|
|
172
|
+
...ownerAc.statements,
|
|
173
|
+
user: ["list", "get", "update"],
|
|
174
|
+
setting: ["read", "list", "upsert", "remove"],
|
|
175
|
+
system: ["read", "list", "create"],
|
|
176
|
+
exchangeRates: ["read", "list"]
|
|
177
|
+
});
|
|
178
|
+
var memberRole = narrowAccessControl.newRole({
|
|
179
|
+
...memberAc.statements,
|
|
180
|
+
setting: ["read", "list"],
|
|
181
|
+
system: ["read", "list"],
|
|
182
|
+
exchangeRates: ["read", "list"]
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// src/auth/wallet-plugins.ts
|
|
186
|
+
import { defineErrorCodes } from "better-auth";
|
|
187
|
+
var WALLET_PINCODE_ERROR_CODES = defineErrorCodes({
|
|
188
|
+
WALLET_PINCODE_ALREADY_SET: "Wallet pincode already set",
|
|
189
|
+
WALLET_PINCODE_ALREADY_REMOVED: "Wallet pincode already removed",
|
|
190
|
+
WALLET_PINCODE_PASSWORD_REQUIRED: "Password is required",
|
|
191
|
+
WALLET_PINCODE_INVALID_PASSWORD: "Invalid password"
|
|
192
|
+
});
|
|
193
|
+
var WALLET_TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
194
|
+
WALLET_TWO_FACTOR_PASSWORD_REQUIRED: "Password is required",
|
|
195
|
+
WALLET_TWO_FACTOR_INVALID_PASSWORD: "Invalid password",
|
|
196
|
+
WALLET_TWO_FACTOR_INVALID_CODE: "Invalid two factor code"
|
|
197
|
+
});
|
|
198
|
+
var WALLET_SECRET_CODES_ERROR_CODES = defineErrorCodes({
|
|
199
|
+
WALLET_SECRET_CODES_PASSWORD_REQUIRED: "Password is required",
|
|
200
|
+
WALLET_SECRET_CODES_INVALID_PASSWORD: "Invalid password",
|
|
201
|
+
WALLET_SECRET_CODES_VERIFICATION_MISMATCH: "Secret codes verification mismatch"
|
|
202
|
+
});
|
|
203
|
+
var walletPincodeClient = () => ({
|
|
204
|
+
id: "wallet-pincode",
|
|
205
|
+
$InferServerPlugin: {
|
|
206
|
+
id: "wallet-pincode",
|
|
207
|
+
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
208
|
+
endpoints: {}
|
|
209
|
+
},
|
|
210
|
+
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
211
|
+
pathMethods: {
|
|
212
|
+
"/wallet/pincode/enable": "POST",
|
|
213
|
+
"/wallet/pincode/disable": "POST",
|
|
214
|
+
"/wallet/pincode/update": "POST",
|
|
215
|
+
"/wallet/pincode/reset": "POST"
|
|
216
|
+
},
|
|
217
|
+
atomListeners: [
|
|
218
|
+
{
|
|
219
|
+
matcher: (path) => path.startsWith("/wallet/pincode/"),
|
|
220
|
+
signal: "$sessionSignal"
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
});
|
|
224
|
+
var walletTwoFactorClient = () => ({
|
|
225
|
+
id: "wallet-two-factor",
|
|
226
|
+
$InferServerPlugin: {
|
|
227
|
+
id: "wallet-two-factor",
|
|
228
|
+
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
229
|
+
endpoints: {}
|
|
230
|
+
},
|
|
231
|
+
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
232
|
+
pathMethods: {
|
|
233
|
+
"/wallet/two-factor/enable": "POST",
|
|
234
|
+
"/wallet/two-factor/disable": "POST",
|
|
235
|
+
"/wallet/two-factor/verify": "POST"
|
|
236
|
+
},
|
|
237
|
+
atomListeners: [
|
|
238
|
+
{
|
|
239
|
+
matcher: (path) => path.startsWith("/wallet/two-factor/"),
|
|
240
|
+
signal: "$sessionSignal"
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
});
|
|
244
|
+
var walletSecretCodesClient = () => ({
|
|
245
|
+
id: "wallet-secret-codes",
|
|
246
|
+
$InferServerPlugin: {
|
|
247
|
+
id: "wallet-secret-codes",
|
|
248
|
+
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
249
|
+
endpoints: {}
|
|
250
|
+
},
|
|
251
|
+
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
252
|
+
pathMethods: {
|
|
253
|
+
"/wallet/secret-codes/generate": "POST",
|
|
254
|
+
"/wallet/secret-codes/confirm": "POST"
|
|
255
|
+
},
|
|
256
|
+
atomListeners: [
|
|
257
|
+
{
|
|
258
|
+
matcher: (path) => path.startsWith("/wallet/secret-codes/"),
|
|
259
|
+
signal: "$sessionSignal"
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// src/auth/live.ts
|
|
265
|
+
var reservedHeaders = new Set(["x-api-key", "authorization", "cookie"]);
|
|
266
|
+
function authHeaders(config) {
|
|
267
|
+
const headers = { "User-Agent": SDK_USER_AGENT };
|
|
268
|
+
for (const [name, value] of Object.entries(config.headers ?? {})) {
|
|
269
|
+
if (!reservedHeaders.has(name.toLowerCase())) {
|
|
270
|
+
headers[name] = value;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (config.apiKey !== undefined) {
|
|
274
|
+
headers["x-api-key"] = unwrapSecret(config.apiKey);
|
|
275
|
+
}
|
|
276
|
+
if (config.sessionToken !== undefined) {
|
|
277
|
+
const token = unwrapSecret(config.sessionToken);
|
|
278
|
+
headers.authorization = token.toLowerCase().startsWith("bearer ") ? token : `Bearer ${token}`;
|
|
279
|
+
}
|
|
280
|
+
if (config.organizationId !== undefined) {
|
|
281
|
+
headers["x-organization-id"] = config.organizationId;
|
|
282
|
+
}
|
|
283
|
+
return headers;
|
|
284
|
+
}
|
|
285
|
+
function createConfiguredBetterAuthClient(config, cookieStore) {
|
|
286
|
+
return createBetterAuthClient({
|
|
287
|
+
baseURL: `${normalizeDalpBaseUrl(config.url)}/api/auth`,
|
|
288
|
+
fetchOptions: {
|
|
289
|
+
headers: authHeaders(config),
|
|
290
|
+
customFetchImpl: createCookieStoreFetch(cookieStore, config.fetch),
|
|
291
|
+
credentials: "include"
|
|
292
|
+
},
|
|
293
|
+
plugins: [
|
|
294
|
+
customSessionClient(),
|
|
295
|
+
inferAdditionalFields(),
|
|
296
|
+
adminClient({ ac: accessControl, roles: { admin: adminRole, owner: ownerRole, member: memberRole } }),
|
|
297
|
+
apiKeyClient(),
|
|
298
|
+
passkeyClient(),
|
|
299
|
+
walletPincodeClient(),
|
|
300
|
+
walletTwoFactorClient(),
|
|
301
|
+
walletSecretCodesClient(),
|
|
302
|
+
twoFactorClient({ onTwoFactorRedirect() {} }),
|
|
303
|
+
deviceAuthorizationClient(),
|
|
304
|
+
organizationClient({ ac: accessControl, roles: { owner: ownerRole, member: memberRole } })
|
|
305
|
+
]
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
async function createDalpAuthClient(input) {
|
|
309
|
+
const config = await decodeDalpAuthClientConfig(input);
|
|
310
|
+
const cookieStore = config.cookieStore ?? makeCookieStore();
|
|
311
|
+
if (config.cookie !== undefined) {
|
|
312
|
+
cookieStore.setCookieHeader(unwrapSecret(config.cookie));
|
|
313
|
+
}
|
|
314
|
+
const credentialCount = [config.apiKey, config.sessionToken, cookieStore.isEmpty() ? undefined : true].filter(Boolean).length;
|
|
315
|
+
if (credentialCount > 1) {
|
|
316
|
+
throw createDalpSdkConfigurationError({
|
|
317
|
+
message: "DALP SDK: configure only one auth credential source.",
|
|
318
|
+
why: "The auth client received multiple credential types.",
|
|
319
|
+
fix: "Use an API key, bearer token, or cookie store, not a combination."
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return createConfiguredBetterAuthClient(config, cookieStore);
|
|
323
|
+
}
|
|
324
|
+
var makeDalpAuthClient = createDalpAuthClient;
|
|
325
|
+
export {
|
|
326
|
+
createDalpAuthClient,
|
|
327
|
+
decodeDalpAuthClientConfig,
|
|
328
|
+
makeDalpAuthClient
|
|
329
|
+
};
|