@settlemint/dalp-sdk 3.1.10 → 3.1.11-main.33538712635
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 +111 -177
- package/dist/auth/client.d.ts +115 -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 +248 -0
- package/dist/bundler.d.ts +17 -207
- package/dist/bundler.js +111 -0
- package/dist/chunk-63xjs3xe.js +45725 -0
- package/dist/chunk-cy9b59s6.js +503 -0
- package/dist/chunk-h12fatty.js +63 -0
- package/dist/chunk-nac758dt.js +14542 -0
- package/dist/chunk-p009n1rm.js +255 -0
- package/dist/chunk-r0vsftj4.js +102 -0
- package/dist/chunk-w21k7p99.js +843 -0
- package/dist/chunk-y0d2c7kp.js +54 -0
- package/dist/client/conditional-request.d.ts +16 -0
- package/dist/client/factory.d.ts +39 -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/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/@tanstack/react-query.gen.d.ts +17380 -0
- package/dist/generated/client/client.gen.d.ts +2 -0
- package/dist/generated/client/index.d.ts +10 -0
- package/dist/generated/client/types.gen.d.ts +120 -0
- package/dist/generated/client/utils.gen.d.ts +37 -0
- package/dist/generated/client.gen.d.ts +12 -0
- package/dist/generated/core/auth.gen.d.ts +25 -0
- package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
- package/dist/generated/core/params.gen.d.ts +43 -0
- package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/generated/core/types.gen.d.ts +83 -0
- package/dist/generated/core/utils.gen.d.ts +19 -0
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/sdk.gen.d.ts +5214 -0
- package/dist/generated/types.gen.d.ts +137282 -0
- package/dist/generated/zod.gen.d.ts +181286 -0
- package/dist/index.d.ts +23 -40
- package/dist/index.js +208 -96098
- package/dist/operations.d.ts +12 -0
- package/dist/operations.js +1747 -0
- package/dist/react-query.d.ts +11 -0
- package/dist/react-query.js +16485 -0
- package/dist/readonly-deep.d.ts +12 -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 +8 -0
- package/dist/scalars/exchange-rates.d.ts +36 -0
- package/dist/scalars/index.d.ts +15 -0
- package/dist/scalars/index.js +39 -0
- package/dist/scalars/organization-id.d.ts +8 -0
- package/dist/schemas.d.ts +10 -0
- package/dist/schemas.js +12040 -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 +67 -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 +40 -86
- package/dist/wait-for-transaction.js +112 -0
- package/dist/webhook-events.d.ts +44 -27
- package/package.json +98 -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,248 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SDK_USER_AGENT,
|
|
3
|
+
createCookieStoreFetch,
|
|
4
|
+
makeCookieStore
|
|
5
|
+
} from "./chunk-p009n1rm.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
|
+
import { z } from "zod";
|
|
30
|
+
var authConfigSchema = z.object({
|
|
31
|
+
url: z.string().url().refine((value) => ["http:", "https:"].includes(new URL(value).protocol)),
|
|
32
|
+
apiKey: z.string().trim().min(1).transform(secret).optional(),
|
|
33
|
+
sessionToken: z.string().trim().min(1).transform(secret).optional(),
|
|
34
|
+
cookie: z.string().trim().min(1).transform(secret).optional(),
|
|
35
|
+
cookieStore: z.custom((value) => typeof value === "object" && value !== null && typeof value.header === "function" && typeof value.storeSetCookieHeaders === "function").optional(),
|
|
36
|
+
organizationId: z.string().trim().min(1).optional(),
|
|
37
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
38
|
+
fetch: z.custom((value) => typeof value === "function").optional()
|
|
39
|
+
}).superRefine((value, context) => {
|
|
40
|
+
if ([value.apiKey, value.sessionToken, value.cookie].filter(Boolean).length > 1) {
|
|
41
|
+
context.addIssue({ code: "custom", message: "configure only one auth credential source" });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
async function decodeDalpAuthClientConfig(input) {
|
|
45
|
+
try {
|
|
46
|
+
return await authConfigSchema.parseAsync(input);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw createDalpSdkConfigurationError({
|
|
49
|
+
message: "DALP SDK: auth client configuration is invalid.",
|
|
50
|
+
why: "The auth client received a malformed URL, credential, header map, fetch seam, or cookie store.",
|
|
51
|
+
fix: "Pass one credential source, an HTTP(S) URL, and valid fetch and cookie-store seams.",
|
|
52
|
+
cause: error
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/auth/permissions.ts
|
|
58
|
+
import { createAccessControl } from "better-auth/plugins/access";
|
|
59
|
+
import { adminAc, defaultStatements as adminDefaultStatements } from "better-auth/plugins/admin/access";
|
|
60
|
+
import {
|
|
61
|
+
memberAc,
|
|
62
|
+
defaultStatements as organizationDefaultStatements,
|
|
63
|
+
ownerAc
|
|
64
|
+
} from "better-auth/plugins/organization/access";
|
|
65
|
+
var dalPermissions = {
|
|
66
|
+
organization: ["update", "delete", "list"],
|
|
67
|
+
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
68
|
+
system: ["read", "list", "create"],
|
|
69
|
+
exchangeRates: ["read", "list"]
|
|
70
|
+
};
|
|
71
|
+
var customPermissions = {
|
|
72
|
+
...adminDefaultStatements,
|
|
73
|
+
...organizationDefaultStatements,
|
|
74
|
+
...dalPermissions
|
|
75
|
+
};
|
|
76
|
+
var narrowAccessControl = createAccessControl(customPermissions);
|
|
77
|
+
var accessControl = createAccessControl({
|
|
78
|
+
...adminDefaultStatements,
|
|
79
|
+
...organizationDefaultStatements,
|
|
80
|
+
...dalPermissions
|
|
81
|
+
});
|
|
82
|
+
var adminRole = narrowAccessControl.newRole({
|
|
83
|
+
...adminAc.statements,
|
|
84
|
+
...ownerAc.statements,
|
|
85
|
+
organization: ["update", "delete", "list"],
|
|
86
|
+
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
87
|
+
system: ["read", "list", "create"],
|
|
88
|
+
exchangeRates: ["read", "list"]
|
|
89
|
+
});
|
|
90
|
+
var ownerRole = narrowAccessControl.newRole({
|
|
91
|
+
...ownerAc.statements,
|
|
92
|
+
user: ["list", "get", "update"],
|
|
93
|
+
setting: ["read", "list", "upsert", "remove"],
|
|
94
|
+
system: ["read", "list", "create"],
|
|
95
|
+
exchangeRates: ["read", "list"]
|
|
96
|
+
});
|
|
97
|
+
var memberRole = narrowAccessControl.newRole({
|
|
98
|
+
...memberAc.statements,
|
|
99
|
+
setting: ["read", "list"],
|
|
100
|
+
system: ["read", "list"],
|
|
101
|
+
exchangeRates: ["read", "list"]
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// src/auth/wallet-plugins.ts
|
|
105
|
+
import { defineErrorCodes } from "better-auth";
|
|
106
|
+
var WALLET_PINCODE_ERROR_CODES = defineErrorCodes({
|
|
107
|
+
WALLET_PINCODE_ALREADY_SET: "Wallet pincode already set",
|
|
108
|
+
WALLET_PINCODE_ALREADY_REMOVED: "Wallet pincode already removed",
|
|
109
|
+
WALLET_PINCODE_PASSWORD_REQUIRED: "Password is required",
|
|
110
|
+
WALLET_PINCODE_INVALID_PASSWORD: "Invalid password"
|
|
111
|
+
});
|
|
112
|
+
var WALLET_TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
113
|
+
WALLET_TWO_FACTOR_PASSWORD_REQUIRED: "Password is required",
|
|
114
|
+
WALLET_TWO_FACTOR_INVALID_PASSWORD: "Invalid password",
|
|
115
|
+
WALLET_TWO_FACTOR_INVALID_CODE: "Invalid two factor code"
|
|
116
|
+
});
|
|
117
|
+
var WALLET_SECRET_CODES_ERROR_CODES = defineErrorCodes({
|
|
118
|
+
WALLET_SECRET_CODES_PASSWORD_REQUIRED: "Password is required",
|
|
119
|
+
WALLET_SECRET_CODES_INVALID_PASSWORD: "Invalid password",
|
|
120
|
+
WALLET_SECRET_CODES_VERIFICATION_MISMATCH: "Secret codes verification mismatch"
|
|
121
|
+
});
|
|
122
|
+
var walletPincodeClient = () => ({
|
|
123
|
+
id: "wallet-pincode",
|
|
124
|
+
$InferServerPlugin: {
|
|
125
|
+
id: "wallet-pincode",
|
|
126
|
+
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
127
|
+
endpoints: {}
|
|
128
|
+
},
|
|
129
|
+
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
130
|
+
pathMethods: {
|
|
131
|
+
"/wallet/pincode/enable": "POST",
|
|
132
|
+
"/wallet/pincode/disable": "POST",
|
|
133
|
+
"/wallet/pincode/update": "POST",
|
|
134
|
+
"/wallet/pincode/reset": "POST"
|
|
135
|
+
},
|
|
136
|
+
atomListeners: [
|
|
137
|
+
{
|
|
138
|
+
matcher: (path) => path.startsWith("/wallet/pincode/"),
|
|
139
|
+
signal: "$sessionSignal"
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
var walletTwoFactorClient = () => ({
|
|
144
|
+
id: "wallet-two-factor",
|
|
145
|
+
$InferServerPlugin: {
|
|
146
|
+
id: "wallet-two-factor",
|
|
147
|
+
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
148
|
+
endpoints: {}
|
|
149
|
+
},
|
|
150
|
+
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
151
|
+
pathMethods: {
|
|
152
|
+
"/wallet/two-factor/enable": "POST",
|
|
153
|
+
"/wallet/two-factor/disable": "POST",
|
|
154
|
+
"/wallet/two-factor/verify": "POST"
|
|
155
|
+
},
|
|
156
|
+
atomListeners: [
|
|
157
|
+
{
|
|
158
|
+
matcher: (path) => path.startsWith("/wallet/two-factor/"),
|
|
159
|
+
signal: "$sessionSignal"
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
var walletSecretCodesClient = () => ({
|
|
164
|
+
id: "wallet-secret-codes",
|
|
165
|
+
$InferServerPlugin: {
|
|
166
|
+
id: "wallet-secret-codes",
|
|
167
|
+
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
168
|
+
endpoints: {}
|
|
169
|
+
},
|
|
170
|
+
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
171
|
+
pathMethods: {
|
|
172
|
+
"/wallet/secret-codes/generate": "POST",
|
|
173
|
+
"/wallet/secret-codes/confirm": "POST"
|
|
174
|
+
},
|
|
175
|
+
atomListeners: [
|
|
176
|
+
{
|
|
177
|
+
matcher: (path) => path.startsWith("/wallet/secret-codes/"),
|
|
178
|
+
signal: "$sessionSignal"
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// src/auth/live.ts
|
|
184
|
+
var reservedHeaders = new Set(["x-api-key", "authorization", "cookie"]);
|
|
185
|
+
function authHeaders(config) {
|
|
186
|
+
const headers = { "User-Agent": SDK_USER_AGENT };
|
|
187
|
+
for (const [name, value] of Object.entries(config.headers ?? {})) {
|
|
188
|
+
if (!reservedHeaders.has(name.toLowerCase())) {
|
|
189
|
+
headers[name] = value;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (config.apiKey !== undefined) {
|
|
193
|
+
headers["x-api-key"] = unwrapSecret(config.apiKey);
|
|
194
|
+
}
|
|
195
|
+
if (config.sessionToken !== undefined) {
|
|
196
|
+
const token = unwrapSecret(config.sessionToken);
|
|
197
|
+
headers.authorization = token.toLowerCase().startsWith("bearer ") ? token : `Bearer ${token}`;
|
|
198
|
+
}
|
|
199
|
+
if (config.organizationId !== undefined) {
|
|
200
|
+
headers["x-organization-id"] = config.organizationId;
|
|
201
|
+
}
|
|
202
|
+
return headers;
|
|
203
|
+
}
|
|
204
|
+
function createConfiguredBetterAuthClient(config, cookieStore) {
|
|
205
|
+
return createBetterAuthClient({
|
|
206
|
+
baseURL: `${normalizeDalpBaseUrl(config.url)}/api/auth`,
|
|
207
|
+
fetchOptions: {
|
|
208
|
+
headers: authHeaders(config),
|
|
209
|
+
customFetchImpl: createCookieStoreFetch(cookieStore, config.fetch),
|
|
210
|
+
credentials: "include"
|
|
211
|
+
},
|
|
212
|
+
plugins: [
|
|
213
|
+
customSessionClient(),
|
|
214
|
+
inferAdditionalFields(),
|
|
215
|
+
adminClient({ ac: accessControl, roles: { admin: adminRole, owner: ownerRole, member: memberRole } }),
|
|
216
|
+
apiKeyClient(),
|
|
217
|
+
passkeyClient(),
|
|
218
|
+
walletPincodeClient(),
|
|
219
|
+
walletTwoFactorClient(),
|
|
220
|
+
walletSecretCodesClient(),
|
|
221
|
+
twoFactorClient({ onTwoFactorRedirect() {} }),
|
|
222
|
+
deviceAuthorizationClient(),
|
|
223
|
+
organizationClient({ ac: accessControl, roles: { owner: ownerRole, member: memberRole } })
|
|
224
|
+
]
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async function createDalpAuthClient(input) {
|
|
228
|
+
const config = await decodeDalpAuthClientConfig(input);
|
|
229
|
+
const cookieStore = config.cookieStore ?? makeCookieStore();
|
|
230
|
+
if (config.cookie !== undefined) {
|
|
231
|
+
cookieStore.setCookieHeader(unwrapSecret(config.cookie));
|
|
232
|
+
}
|
|
233
|
+
const credentialCount = [config.apiKey, config.sessionToken, cookieStore.isEmpty() ? undefined : true].filter(Boolean).length;
|
|
234
|
+
if (credentialCount > 1) {
|
|
235
|
+
throw createDalpSdkConfigurationError({
|
|
236
|
+
message: "DALP SDK: configure only one auth credential source.",
|
|
237
|
+
why: "The auth client received multiple credential types.",
|
|
238
|
+
fix: "Use an API key, bearer token, or cookie store, not a combination."
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return createConfiguredBetterAuthClient(config, cookieStore);
|
|
242
|
+
}
|
|
243
|
+
var makeDalpAuthClient = createDalpAuthClient;
|
|
244
|
+
export {
|
|
245
|
+
createDalpAuthClient,
|
|
246
|
+
decodeDalpAuthClientConfig,
|
|
247
|
+
makeDalpAuthClient
|
|
248
|
+
};
|