@settlemint/dalp-sdk 3.1.26-main.37116470199 → 3.1.26
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 +172 -239
- package/dist/api-types.generated.d.ts +14160 -0
- package/dist/api-types.generated.d.ts.map +1 -0
- package/dist/{auth/permissions.d.ts → auth-permissions.d.ts} +8 -0
- package/dist/auth-permissions.d.ts.map +1 -0
- package/dist/{auth/wallet-plugins.d.ts → auth-wallet-plugins.d.ts} +6 -68
- package/dist/auth-wallet-plugins.d.ts.map +1 -0
- package/dist/auth.d.ts +115 -8
- package/dist/auth.d.ts.map +1 -0
- package/dist/bundler.d.ts +217 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/chunk-xm8h1dzh.js +33 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/contract-errors.d.ts +4156 -0
- package/dist/contract-errors.d.ts.map +1 -0
- package/dist/contract.d.ts +22 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/cookie-store.d.ts +10 -0
- package/dist/cookie-store.d.ts.map +1 -0
- package/dist/dapi-errors.d.ts +654 -0
- package/dist/dapi-errors.d.ts.map +1 -0
- package/dist/errors.d.ts +637 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +45 -28
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96216 -150
- package/dist/platform.d.ts +41 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +13 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +10 -0
- package/dist/sdk-error.d.ts +74 -0
- package/dist/sdk-error.d.ts.map +1 -0
- package/dist/serializers.d.ts +41 -0
- package/dist/serializers.d.ts.map +1 -0
- package/dist/types.d.ts +114 -37
- package/dist/types.d.ts.map +1 -0
- package/dist/url.d.ts +1 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/verify-webhook.d.ts +28 -17
- package/dist/verify-webhook.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.generated.d.ts +8 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/wait-for-transaction.d.ts +86 -44
- package/dist/wait-for-transaction.d.ts.map +1 -0
- package/dist/webhook-events.d.ts +33 -543
- package/dist/webhook-events.d.ts.map +1 -0
- package/package.json +34 -110
- package/dist/auth/client.d.ts +0 -103
- package/dist/auth/invite-step-up.d.ts +0 -2
- package/dist/auth/live.d.ts +0 -47
- package/dist/auth/native-passkey.d.ts +0 -9
- package/dist/auth-surface.d.ts +0 -2
- package/dist/auth.js +0 -525
- package/dist/chunk-4f4kjtt0.js +0 -149
- package/dist/chunk-b03ycwb7.js +0 -68
- package/dist/chunk-ghgcmyhk.js +0 -5
- package/dist/chunk-h241xecg.js +0 -1625
- package/dist/chunk-hqz56e6q.js +0 -4
- package/dist/chunk-k3ntysxx.js +0 -57
- package/dist/chunk-pjjrxre1.js +0 -36
- package/dist/chunk-qvtjb3dz.js +0 -102
- package/dist/chunk-v54k7mgr.js +0 -271
- package/dist/chunk-w361dpdk.js +0 -5
- package/dist/client/conditional-request.d.ts +0 -8
- package/dist/client/factory.d.ts +0 -4
- package/dist/client/query-serializer.d.ts +0 -1
- package/dist/client/request-compression.d.ts +0 -12
- package/dist/client/ssr-fetch.d.ts +0 -10
- package/dist/client/step-up-challenge.d.ts +0 -10
- package/dist/effect.d.ts +0 -38
- package/dist/effect.js +0 -87
- package/dist/errors/api-error.d.ts +0 -35
- package/dist/errors/error-codes.d.ts +0 -21
- package/dist/errors/find-current-error.d.ts +0 -2
- package/dist/errors/sdk-error.d.ts +0 -52
- package/dist/errors/sdk-error.js +0 -8
- package/dist/generated/api-types.d.ts +0 -69961
- package/dist/generated/console-routes.d.ts +0 -12
- package/dist/generated/error-catalog.d.ts +0 -9
- package/dist/generated/error-codes.d.ts +0 -9
- package/dist/generated/response-scalars.d.ts +0 -9
- package/dist/generated/response-schemas.d.ts +0 -9
- package/dist/generated/route-error-codes.d.ts +0 -9
- package/dist/generated/routes.d.ts +0 -12
- package/dist/proxy/builder.d.ts +0 -17
- package/dist/proxy/client-core.d.ts +0 -28
- package/dist/proxy/client.d.ts +0 -5
- package/dist/proxy/fetch-executor.d.ts +0 -6
- package/dist/proxy/flat-args.d.ts +0 -24
- package/dist/proxy/response-decode.d.ts +0 -37
- package/dist/proxy/sse.d.ts +0 -11
- package/dist/proxy/step-up-challenge.d.ts +0 -4
- package/dist/proxy/tanstack.d.ts +0 -6
- package/dist/proxy/transport.d.ts +0 -63
- package/dist/react-query.d.ts +0 -2
- package/dist/react-query.js +0 -12
- package/dist/readonly-deep.d.ts +0 -3
- package/dist/routes/console.d.ts +0 -14
- package/dist/routes/console.js +0 -25
- package/dist/routes/index.d.ts +0 -4
- package/dist/routes/index.js +0 -10
- package/dist/routes/types.d.ts +0 -72
- package/dist/runtime-exports.d.ts +0 -4
- package/dist/runtime-exports.js +0 -16
- package/dist/runtime.d.ts +0 -11
- package/dist/scalars/big-decimal.d.ts +0 -4
- package/dist/scalars/ethereum-address.d.ts +0 -5
- package/dist/scalars/exchange-rates.d.ts +0 -13
- package/dist/scalars/index.d.ts +0 -10
- package/dist/scalars/index.js +0 -102
- package/dist/scalars/organization-id.d.ts +0 -5
- package/dist/scalars/token-decimals.d.ts +0 -4
- package/dist/secret.d.ts +0 -12
- package/dist/sign-webhook-receipt.d.ts +0 -16
- package/dist/sign-webhook-receipt.js +0 -26
- package/dist/transport/cookie-store.d.ts +0 -9
- package/dist/transport/sse-lifecycle.d.ts +0 -24
- package/dist/verify-webhook.js +0 -8
- package/dist/wait-for-transaction.js +0 -151
package/dist/auth.js
DELETED
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDalpSdkConfigurationError2
|
|
3
|
-
} from "./chunk-k3ntysxx.js";
|
|
4
|
-
import {
|
|
5
|
-
DALP_AUTH_SURFACE_HEADER2,
|
|
6
|
-
secret2,
|
|
7
|
-
unwrapSecret,
|
|
8
|
-
normalizeDalpBaseUrl,
|
|
9
|
-
detectDalpRuntime,
|
|
10
|
-
refuseBundledApiKey,
|
|
11
|
-
STEP_UP_CHALLENGE_HEADER,
|
|
12
|
-
STEP_UP_CHALLENGE_PATH,
|
|
13
|
-
carriesWalletProof,
|
|
14
|
-
stepUpChallengeRequest
|
|
15
|
-
} from "./chunk-4f4kjtt0.js";
|
|
16
|
-
import {
|
|
17
|
-
makeCookieStore2,
|
|
18
|
-
createCookieStoreFetch2,
|
|
19
|
-
SDK_USER_AGENT2
|
|
20
|
-
} from "./chunk-v54k7mgr.js";
|
|
21
|
-
|
|
22
|
-
// src/auth/live.ts
|
|
23
|
-
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
24
|
-
import { passkeyClient as passkeyClient2 } from "@better-auth/passkey/client";
|
|
25
|
-
import {
|
|
26
|
-
createAuthClient as createBetterAuthClient
|
|
27
|
-
} from "better-auth/client";
|
|
28
|
-
import {
|
|
29
|
-
adminClient,
|
|
30
|
-
customSessionClient,
|
|
31
|
-
deviceAuthorizationClient,
|
|
32
|
-
inferAdditionalFields,
|
|
33
|
-
organizationClient,
|
|
34
|
-
twoFactorClient
|
|
35
|
-
} from "better-auth/client/plugins";
|
|
36
|
-
|
|
37
|
-
// src/auth/client.ts
|
|
38
|
-
class AuthConfigError extends Error {
|
|
39
|
-
constructor(field, requirement) {
|
|
40
|
-
super(`\`${field}\` ${requirement}`);
|
|
41
|
-
this.name = "AuthConfigError";
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function optionalText(value, field) {
|
|
45
|
-
if (value === undefined) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (typeof value !== "string") {
|
|
49
|
-
return handleNonString(field);
|
|
50
|
-
}
|
|
51
|
-
const trimmed = value.trim();
|
|
52
|
-
if (trimmed.length === 0) {
|
|
53
|
-
throw new AuthConfigError(field, "must not be blank");
|
|
54
|
-
}
|
|
55
|
-
return trimmed;
|
|
56
|
-
}
|
|
57
|
-
function handleNonString(field) {
|
|
58
|
-
throw new AuthConfigError(field, "must be a string");
|
|
59
|
-
}
|
|
60
|
-
function requiredUrl(value) {
|
|
61
|
-
if (typeof value !== "string") {
|
|
62
|
-
return handleNonString("url");
|
|
63
|
-
}
|
|
64
|
-
let parsed;
|
|
65
|
-
try {
|
|
66
|
-
parsed = new URL(value);
|
|
67
|
-
} catch {
|
|
68
|
-
throw new AuthConfigError("url", "must be a valid URL");
|
|
69
|
-
}
|
|
70
|
-
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
71
|
-
throw new AuthConfigError("url", "must use http or https");
|
|
72
|
-
}
|
|
73
|
-
return value;
|
|
74
|
-
}
|
|
75
|
-
function optionalHeaders(value) {
|
|
76
|
-
if (value === undefined) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
80
|
-
throw new AuthConfigError("headers", "must be an object of strings");
|
|
81
|
-
}
|
|
82
|
-
const headers = {};
|
|
83
|
-
for (const [name, header] of Object.entries(value)) {
|
|
84
|
-
if (typeof header !== "string") {
|
|
85
|
-
throw new AuthConfigError("headers", "must be an object of strings");
|
|
86
|
-
}
|
|
87
|
-
headers[name] = header;
|
|
88
|
-
}
|
|
89
|
-
return headers;
|
|
90
|
-
}
|
|
91
|
-
function optionalAuthSurface(value) {
|
|
92
|
-
if (value === undefined || value === "console" || value === "portal") {
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
throw new AuthConfigError("authSurface", 'must be "console" or "portal"');
|
|
96
|
-
}
|
|
97
|
-
function optionalFetch(value) {
|
|
98
|
-
if (value === undefined) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (typeof value !== "function") {
|
|
102
|
-
throw new AuthConfigError("fetch", "must be a function");
|
|
103
|
-
}
|
|
104
|
-
return value;
|
|
105
|
-
}
|
|
106
|
-
function optionalRuntime(value) {
|
|
107
|
-
if (value === undefined || value === "browser" || value === "server" || value === "react-native") {
|
|
108
|
-
return value;
|
|
109
|
-
}
|
|
110
|
-
throw new AuthConfigError("runtime", 'must be "browser", "server", or "react-native"');
|
|
111
|
-
}
|
|
112
|
-
function optionalPasskeyCeremony(value) {
|
|
113
|
-
if (value === undefined) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (typeof value !== "object" || value === null || typeof Reflect.get(value, "authenticate") !== "function" || typeof Reflect.get(value, "register") !== "function") {
|
|
117
|
-
throw new AuthConfigError("passkey", "must expose authenticate and register");
|
|
118
|
-
}
|
|
119
|
-
return value;
|
|
120
|
-
}
|
|
121
|
-
function optionalCookieStore(value) {
|
|
122
|
-
if (value === undefined) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const store = value;
|
|
126
|
-
if (typeof value !== "object" || value === null || typeof store.header !== "function" || typeof store.storeSetCookieHeaders !== "function") {
|
|
127
|
-
throw new AuthConfigError("cookieStore", "must expose header and storeSetCookieHeaders");
|
|
128
|
-
}
|
|
129
|
-
return store;
|
|
130
|
-
}
|
|
131
|
-
function decodeAuthConfig(input) {
|
|
132
|
-
const raw = input;
|
|
133
|
-
const apiKey = optionalText(raw.apiKey, "apiKey");
|
|
134
|
-
const cookie = optionalText(raw.cookie, "cookie");
|
|
135
|
-
if ([apiKey, cookie].filter((credential) => credential !== undefined).length > 1) {
|
|
136
|
-
throw new AuthConfigError("apiKey/cookie", "configure only one auth credential source");
|
|
137
|
-
}
|
|
138
|
-
const url = requiredUrl(raw.url);
|
|
139
|
-
const cookieStore = optionalCookieStore(raw.cookieStore);
|
|
140
|
-
const organizationId = optionalText(raw.organizationId, "organizationId");
|
|
141
|
-
const authSurface = optionalAuthSurface(raw.authSurface);
|
|
142
|
-
const headers = optionalHeaders(raw.headers);
|
|
143
|
-
const configuredFetch = optionalFetch(raw.fetch);
|
|
144
|
-
const runtime = optionalRuntime(raw.runtime);
|
|
145
|
-
const passkey = optionalPasskeyCeremony(raw.passkey);
|
|
146
|
-
return {
|
|
147
|
-
url,
|
|
148
|
-
...apiKey === undefined ? {} : { apiKey: secret2(apiKey) },
|
|
149
|
-
...cookie === undefined ? {} : { cookie: secret2(cookie) },
|
|
150
|
-
...cookieStore === undefined ? {} : { cookieStore },
|
|
151
|
-
...organizationId === undefined ? {} : { organizationId },
|
|
152
|
-
...authSurface === undefined ? {} : { authSurface },
|
|
153
|
-
...headers === undefined ? {} : { headers },
|
|
154
|
-
...configuredFetch === undefined ? {} : { fetch: configuredFetch },
|
|
155
|
-
...runtime === undefined ? {} : { runtime },
|
|
156
|
-
...passkey === undefined ? {} : { passkey }
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
async function decodeDalpAuthClientConfig(input) {
|
|
160
|
-
try {
|
|
161
|
-
return decodeAuthConfig(input);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
throw createDalpSdkConfigurationError2({
|
|
164
|
-
message: "DALP SDK: auth client configuration is invalid.",
|
|
165
|
-
why: "The auth client received a malformed URL, credential, header map, runtime, fetch seam, cookie store, or passkey ceremony.",
|
|
166
|
-
fix: "Pass one credential source, an HTTP(S) URL, a known runtime, and valid fetch, cookie-store, and passkey seams.",
|
|
167
|
-
cause: error
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// src/auth/invite-step-up.ts
|
|
173
|
-
var INVITE_MEMBER_PATH = "/api/auth/organization/invite-member";
|
|
174
|
-
var INVITE_MEMBER_OPERATION = `POST ${INVITE_MEMBER_PATH}`;
|
|
175
|
-
function readChallengeId(payload) {
|
|
176
|
-
const data = payload !== null && typeof payload === "object" ? Reflect.get(payload, "data") : undefined;
|
|
177
|
-
const challengeId = data !== null && typeof data === "object" ? Reflect.get(data, "challengeId") : undefined;
|
|
178
|
-
return typeof challengeId === "string" ? challengeId : undefined;
|
|
179
|
-
}
|
|
180
|
-
function invitesWithWalletProof(input, init, baseUrl) {
|
|
181
|
-
const url = input instanceof Request ? input.url : String(input);
|
|
182
|
-
if ((init?.method ?? "GET").toUpperCase() !== "POST" || typeof init?.body !== "string" || new URL(url).pathname !== new URL(`${baseUrl}${INVITE_MEMBER_PATH}`).pathname) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const body = JSON.parse(init.body);
|
|
186
|
-
return carriesWalletProof(body) ? body : undefined;
|
|
187
|
-
}
|
|
188
|
-
function withInviteStepUp(fetchImpl, baseUrl) {
|
|
189
|
-
return async (input, init) => {
|
|
190
|
-
const headers = new Headers(init?.headers);
|
|
191
|
-
const body = invitesWithWalletProof(input, init, baseUrl);
|
|
192
|
-
if (body === undefined || headers.has("x-api-key") || headers.has(STEP_UP_CHALLENGE_HEADER)) {
|
|
193
|
-
return fetchImpl(input, init);
|
|
194
|
-
}
|
|
195
|
-
const challengeHeaders = new Headers(headers);
|
|
196
|
-
challengeHeaders.set("Content-Type", "application/json");
|
|
197
|
-
const issued = await fetchImpl(`${baseUrl}${STEP_UP_CHALLENGE_PATH}`, {
|
|
198
|
-
method: "POST",
|
|
199
|
-
headers: challengeHeaders,
|
|
200
|
-
body: JSON.stringify(await stepUpChallengeRequest(INVITE_MEMBER_OPERATION, null, body)),
|
|
201
|
-
signal: init?.signal ?? null,
|
|
202
|
-
...init?.credentials === undefined ? {} : { credentials: init.credentials }
|
|
203
|
-
});
|
|
204
|
-
if (!issued.ok) {
|
|
205
|
-
return issued;
|
|
206
|
-
}
|
|
207
|
-
const challengeId = readChallengeId(await issued.json());
|
|
208
|
-
if (challengeId !== undefined) {
|
|
209
|
-
headers.set(STEP_UP_CHALLENGE_HEADER, challengeId);
|
|
210
|
-
}
|
|
211
|
-
return fetchImpl(input, { ...init, headers });
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/auth/native-passkey.ts
|
|
216
|
-
import {
|
|
217
|
-
passkeyClient
|
|
218
|
-
} from "@better-auth/passkey/client";
|
|
219
|
-
var ceremonyFailed = (code, error) => ({
|
|
220
|
-
data: null,
|
|
221
|
-
error: {
|
|
222
|
-
code,
|
|
223
|
-
message: error instanceof Error ? error.message : "The passkey ceremony did not complete.",
|
|
224
|
-
status: 400,
|
|
225
|
-
statusText: "BAD_REQUEST"
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
function withExtensions(options, extensions) {
|
|
229
|
-
return options.extensions === undefined && extensions === undefined ? options : { ...options, extensions: { ...options.extensions, ...extensions } };
|
|
230
|
-
}
|
|
231
|
-
function ceremonyPasskeyClient(ceremony) {
|
|
232
|
-
const plugin = passkeyClient();
|
|
233
|
-
return {
|
|
234
|
-
...plugin,
|
|
235
|
-
getActions: ($fetch, $store) => {
|
|
236
|
-
const signIn = async (opts, options) => {
|
|
237
|
-
const generated = await $fetch("/passkey/generate-authenticate-options", {
|
|
238
|
-
method: "GET",
|
|
239
|
-
throw: false
|
|
240
|
-
});
|
|
241
|
-
if (generated.data === null) {
|
|
242
|
-
return generated;
|
|
243
|
-
}
|
|
244
|
-
let response;
|
|
245
|
-
try {
|
|
246
|
-
response = await ceremony.authenticate(withExtensions(generated.data, opts?.extensions));
|
|
247
|
-
} catch (error) {
|
|
248
|
-
return ceremonyFailed("AUTH_CANCELLED", error);
|
|
249
|
-
}
|
|
250
|
-
const { clientExtensionResults, ...responseBody } = response;
|
|
251
|
-
try {
|
|
252
|
-
const verified = await $fetch("/passkey/verify-authentication", {
|
|
253
|
-
body: { response: responseBody },
|
|
254
|
-
...opts?.fetchOptions,
|
|
255
|
-
...options,
|
|
256
|
-
method: "POST",
|
|
257
|
-
throw: false
|
|
258
|
-
});
|
|
259
|
-
$store.notify("$listPasskeys");
|
|
260
|
-
$store.notify("$sessionSignal");
|
|
261
|
-
return opts?.returnWebAuthnResponse === true ? { ...verified, webauthn: { response, clientExtensionResults } } : verified;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
return ceremonyFailed("AUTH_CANCELLED", error);
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
const addPasskey = async (opts, fetchOpts) => {
|
|
267
|
-
const generated = await $fetch("/passkey/generate-register-options", {
|
|
268
|
-
method: "GET",
|
|
269
|
-
query: {
|
|
270
|
-
...opts?.authenticatorAttachment === undefined ? {} : { authenticatorAttachment: opts.authenticatorAttachment },
|
|
271
|
-
...opts?.name === undefined || opts.name === "" ? {} : { name: opts.name },
|
|
272
|
-
...opts?.context === undefined || opts.context === null ? {} : { context: opts.context }
|
|
273
|
-
},
|
|
274
|
-
throw: false
|
|
275
|
-
});
|
|
276
|
-
if (generated.data === null) {
|
|
277
|
-
return generated;
|
|
278
|
-
}
|
|
279
|
-
let response;
|
|
280
|
-
try {
|
|
281
|
-
response = await ceremony.register(withExtensions(generated.data, opts?.extensions));
|
|
282
|
-
} catch (error) {
|
|
283
|
-
return ceremonyFailed("REGISTRATION_CANCELLED", error);
|
|
284
|
-
}
|
|
285
|
-
const { clientExtensionResults, ...responseBody } = response;
|
|
286
|
-
try {
|
|
287
|
-
const verified = await $fetch("/passkey/verify-registration", {
|
|
288
|
-
...opts?.fetchOptions,
|
|
289
|
-
...fetchOpts,
|
|
290
|
-
body: {
|
|
291
|
-
response: responseBody,
|
|
292
|
-
name: opts?.name,
|
|
293
|
-
...opts?.createSession === true ? { createSession: true } : {}
|
|
294
|
-
},
|
|
295
|
-
method: "POST",
|
|
296
|
-
throw: false
|
|
297
|
-
});
|
|
298
|
-
if (verified.data === null) {
|
|
299
|
-
return verified;
|
|
300
|
-
}
|
|
301
|
-
$store.notify("$listPasskeys");
|
|
302
|
-
if (verified.data.session !== undefined) {
|
|
303
|
-
$store.notify("$sessionSignal");
|
|
304
|
-
}
|
|
305
|
-
return opts?.returnWebAuthnResponse === true ? { ...verified, webauthn: { response, clientExtensionResults } } : verified;
|
|
306
|
-
} catch (error) {
|
|
307
|
-
return ceremonyFailed("UNKNOWN_ERROR", error);
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
return { signIn: { passkey: signIn }, passkey: { addPasskey }, $Infer: {} };
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// src/auth/permissions.ts
|
|
316
|
-
import { createAccessControl } from "better-auth/plugins/access";
|
|
317
|
-
import { adminAc, defaultStatements as adminDefaultStatements } from "better-auth/plugins/admin/access";
|
|
318
|
-
import {
|
|
319
|
-
memberAc,
|
|
320
|
-
defaultStatements as organizationDefaultStatements,
|
|
321
|
-
ownerAc
|
|
322
|
-
} from "better-auth/plugins/organization/access";
|
|
323
|
-
var dalPermissions = {
|
|
324
|
-
organization: ["update", "delete", "list"],
|
|
325
|
-
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
326
|
-
system: ["read", "list", "create"],
|
|
327
|
-
exchangeRates: ["read", "list"],
|
|
328
|
-
corporateAction: ["approve"]
|
|
329
|
-
};
|
|
330
|
-
var customPermissions = {
|
|
331
|
-
...adminDefaultStatements,
|
|
332
|
-
...organizationDefaultStatements,
|
|
333
|
-
...dalPermissions
|
|
334
|
-
};
|
|
335
|
-
var narrowAccessControl = createAccessControl(customPermissions);
|
|
336
|
-
var accessControl = createAccessControl({
|
|
337
|
-
...adminDefaultStatements,
|
|
338
|
-
...organizationDefaultStatements,
|
|
339
|
-
...dalPermissions
|
|
340
|
-
});
|
|
341
|
-
var adminRole = narrowAccessControl.newRole({
|
|
342
|
-
...adminAc.statements,
|
|
343
|
-
...ownerAc.statements,
|
|
344
|
-
organization: ["update", "delete", "list"],
|
|
345
|
-
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
346
|
-
system: ["read", "list", "create"],
|
|
347
|
-
exchangeRates: ["read", "list"],
|
|
348
|
-
corporateAction: ["approve"]
|
|
349
|
-
});
|
|
350
|
-
var ownerRole = narrowAccessControl.newRole({
|
|
351
|
-
...ownerAc.statements,
|
|
352
|
-
user: ["list", "get", "update"],
|
|
353
|
-
setting: ["read", "list", "upsert", "remove"],
|
|
354
|
-
system: ["read", "list", "create"],
|
|
355
|
-
exchangeRates: ["read", "list"],
|
|
356
|
-
corporateAction: ["approve"]
|
|
357
|
-
});
|
|
358
|
-
var memberRole = narrowAccessControl.newRole({
|
|
359
|
-
...memberAc.statements,
|
|
360
|
-
setting: ["read", "list"],
|
|
361
|
-
system: ["read", "list"],
|
|
362
|
-
exchangeRates: ["read", "list"]
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
// src/auth/wallet-plugins.ts
|
|
366
|
-
import { defineErrorCodes } from "better-auth";
|
|
367
|
-
var WALLET_PINCODE_ERROR_CODES = defineErrorCodes({
|
|
368
|
-
WALLET_PINCODE_ALREADY_SET: "Wallet pincode already set",
|
|
369
|
-
WALLET_PINCODE_ALREADY_REMOVED: "Wallet pincode already removed",
|
|
370
|
-
WALLET_PINCODE_PASSWORD_REQUIRED: "Password is required",
|
|
371
|
-
WALLET_PINCODE_INVALID_PASSWORD: "Invalid password"
|
|
372
|
-
});
|
|
373
|
-
var WALLET_TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
374
|
-
WALLET_TWO_FACTOR_PASSWORD_REQUIRED: "Password is required",
|
|
375
|
-
WALLET_TWO_FACTOR_INVALID_PASSWORD: "Invalid password",
|
|
376
|
-
WALLET_TWO_FACTOR_INVALID_CODE: "Invalid two factor code"
|
|
377
|
-
});
|
|
378
|
-
var WALLET_SECRET_CODES_ERROR_CODES = defineErrorCodes({
|
|
379
|
-
WALLET_SECRET_CODES_PASSWORD_REQUIRED: "Password is required",
|
|
380
|
-
WALLET_SECRET_CODES_INVALID_PASSWORD: "Invalid password",
|
|
381
|
-
WALLET_SECRET_CODES_VERIFICATION_MISMATCH: "Secret codes verification mismatch"
|
|
382
|
-
});
|
|
383
|
-
var walletPincodeClient = () => ({
|
|
384
|
-
id: "wallet-pincode",
|
|
385
|
-
$InferServerPlugin: {
|
|
386
|
-
id: "wallet-pincode",
|
|
387
|
-
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
388
|
-
endpoints: {}
|
|
389
|
-
},
|
|
390
|
-
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
391
|
-
pathMethods: {
|
|
392
|
-
"/wallet/pincode/enable": "POST",
|
|
393
|
-
"/wallet/pincode/disable": "POST",
|
|
394
|
-
"/wallet/pincode/update": "POST",
|
|
395
|
-
"/wallet/pincode/reset": "POST"
|
|
396
|
-
},
|
|
397
|
-
atomListeners: [
|
|
398
|
-
{
|
|
399
|
-
matcher: (path) => path.startsWith("/wallet/pincode/"),
|
|
400
|
-
signal: "$sessionSignal"
|
|
401
|
-
}
|
|
402
|
-
]
|
|
403
|
-
});
|
|
404
|
-
var walletTwoFactorClient = () => ({
|
|
405
|
-
id: "wallet-two-factor",
|
|
406
|
-
$InferServerPlugin: {
|
|
407
|
-
id: "wallet-two-factor",
|
|
408
|
-
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
409
|
-
endpoints: {}
|
|
410
|
-
},
|
|
411
|
-
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
412
|
-
pathMethods: {
|
|
413
|
-
"/wallet/two-factor/enable": "POST",
|
|
414
|
-
"/wallet/two-factor/disable": "POST",
|
|
415
|
-
"/wallet/two-factor/verify": "POST"
|
|
416
|
-
},
|
|
417
|
-
atomListeners: [
|
|
418
|
-
{
|
|
419
|
-
matcher: (path) => path.startsWith("/wallet/two-factor/"),
|
|
420
|
-
signal: "$sessionSignal"
|
|
421
|
-
}
|
|
422
|
-
]
|
|
423
|
-
});
|
|
424
|
-
var walletSecretCodesClient = () => ({
|
|
425
|
-
id: "wallet-secret-codes",
|
|
426
|
-
$InferServerPlugin: {
|
|
427
|
-
id: "wallet-secret-codes",
|
|
428
|
-
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
429
|
-
endpoints: {}
|
|
430
|
-
},
|
|
431
|
-
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
432
|
-
pathMethods: {
|
|
433
|
-
"/wallet/secret-codes/generate": "POST",
|
|
434
|
-
"/wallet/secret-codes/confirm": "POST"
|
|
435
|
-
},
|
|
436
|
-
atomListeners: [
|
|
437
|
-
{
|
|
438
|
-
matcher: (path) => path.startsWith("/wallet/secret-codes/"),
|
|
439
|
-
signal: "$sessionSignal"
|
|
440
|
-
}
|
|
441
|
-
]
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
// src/auth/live.ts
|
|
445
|
-
var adminPluginOptions = {
|
|
446
|
-
ac: accessControl,
|
|
447
|
-
roles: { admin: adminRole, owner: ownerRole, member: memberRole }
|
|
448
|
-
};
|
|
449
|
-
var organizationPluginOptions = {
|
|
450
|
-
ac: accessControl,
|
|
451
|
-
roles: { owner: ownerRole, member: memberRole }
|
|
452
|
-
};
|
|
453
|
-
var reservedHeaders = new Set(["x-api-key", "authorization", "cookie"]);
|
|
454
|
-
function authHeaders(config, runtime, baseUrl) {
|
|
455
|
-
const headers = { "User-Agent": SDK_USER_AGENT2 };
|
|
456
|
-
if (runtime === "react-native") {
|
|
457
|
-
headers.origin = new URL(baseUrl).origin;
|
|
458
|
-
}
|
|
459
|
-
for (const [name, value] of Object.entries(config.headers ?? {})) {
|
|
460
|
-
if (!reservedHeaders.has(name.toLowerCase())) {
|
|
461
|
-
headers[name.toLowerCase() === "origin" ? "origin" : name] = value;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if (config.apiKey !== undefined) {
|
|
465
|
-
headers["x-api-key"] = unwrapSecret(config.apiKey);
|
|
466
|
-
}
|
|
467
|
-
if (config.organizationId !== undefined) {
|
|
468
|
-
headers["x-organization-id"] = config.organizationId;
|
|
469
|
-
}
|
|
470
|
-
if (config.authSurface !== undefined) {
|
|
471
|
-
headers[DALP_AUTH_SURFACE_HEADER2] = config.authSurface;
|
|
472
|
-
}
|
|
473
|
-
return headers;
|
|
474
|
-
}
|
|
475
|
-
function createConfiguredBetterAuthClient(config, cookieStore) {
|
|
476
|
-
const plugins = [
|
|
477
|
-
customSessionClient(),
|
|
478
|
-
inferAdditionalFields(),
|
|
479
|
-
adminClient(adminPluginOptions),
|
|
480
|
-
apiKeyClient(),
|
|
481
|
-
config.passkey === undefined ? passkeyClient2() : ceremonyPasskeyClient(config.passkey),
|
|
482
|
-
walletPincodeClient(),
|
|
483
|
-
walletTwoFactorClient(),
|
|
484
|
-
walletSecretCodesClient(),
|
|
485
|
-
twoFactorClient({ onTwoFactorRedirect() {} }),
|
|
486
|
-
deviceAuthorizationClient(),
|
|
487
|
-
organizationClient(organizationPluginOptions)
|
|
488
|
-
];
|
|
489
|
-
const baseUrl = normalizeDalpBaseUrl(config.url);
|
|
490
|
-
const runtime = config.runtime ?? detectDalpRuntime();
|
|
491
|
-
if (config.apiKey !== undefined) {
|
|
492
|
-
refuseBundledApiKey(runtime);
|
|
493
|
-
}
|
|
494
|
-
return createBetterAuthClient({
|
|
495
|
-
baseURL: `${baseUrl}/api/auth`,
|
|
496
|
-
fetchOptions: {
|
|
497
|
-
headers: authHeaders(config, runtime, baseUrl),
|
|
498
|
-
customFetchImpl: withInviteStepUp(createCookieStoreFetch2(cookieStore, config.fetch), baseUrl),
|
|
499
|
-
credentials: runtime === "react-native" ? "omit" : "include"
|
|
500
|
-
},
|
|
501
|
-
plugins
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
async function createDalpAuthClient(input) {
|
|
505
|
-
const config = await decodeDalpAuthClientConfig(input);
|
|
506
|
-
const cookieStore = config.cookieStore ?? makeCookieStore2();
|
|
507
|
-
if (config.cookie !== undefined) {
|
|
508
|
-
cookieStore.setCookieHeader(unwrapSecret(config.cookie));
|
|
509
|
-
}
|
|
510
|
-
const credentialCount = [config.apiKey, cookieStore.isEmpty() ? undefined : true].filter(Boolean).length;
|
|
511
|
-
if (credentialCount > 1) {
|
|
512
|
-
throw createDalpSdkConfigurationError2({
|
|
513
|
-
message: "DALP SDK: configure only one auth credential source.",
|
|
514
|
-
why: "The auth client received multiple credential types.",
|
|
515
|
-
fix: "Use an API key or a cookie store, not both."
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
return createConfiguredBetterAuthClient(config, cookieStore);
|
|
519
|
-
}
|
|
520
|
-
var makeDalpAuthClient = createDalpAuthClient;
|
|
521
|
-
export {
|
|
522
|
-
createDalpAuthClient,
|
|
523
|
-
decodeDalpAuthClientConfig,
|
|
524
|
-
makeDalpAuthClient
|
|
525
|
-
};
|
package/dist/chunk-4f4kjtt0.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDalpSdkConfigurationError2
|
|
3
|
-
} from "./chunk-k3ntysxx.js";
|
|
4
|
-
|
|
5
|
-
// src/auth-surface.ts
|
|
6
|
-
var DALP_AUTH_SURFACE_HEADER2 = "X-Dalp-Auth-Surface";
|
|
7
|
-
|
|
8
|
-
// src/secret.ts
|
|
9
|
-
var SECRET_REDACTION_MARKER2 = "[REDACTED]";
|
|
10
|
-
var inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
11
|
-
var secretValue = new WeakMap;
|
|
12
|
-
|
|
13
|
-
class Secret2 {
|
|
14
|
-
constructor(value) {
|
|
15
|
-
secretValue.set(this, value);
|
|
16
|
-
Object.freeze(this);
|
|
17
|
-
}
|
|
18
|
-
static from(value) {
|
|
19
|
-
if (value.trim().length === 0) {
|
|
20
|
-
throw new TypeError("DALP SDK: a secret value must not be empty.");
|
|
21
|
-
}
|
|
22
|
-
return new Secret2(value);
|
|
23
|
-
}
|
|
24
|
-
toString() {
|
|
25
|
-
return SECRET_REDACTION_MARKER2;
|
|
26
|
-
}
|
|
27
|
-
toJSON() {
|
|
28
|
-
return SECRET_REDACTION_MARKER2;
|
|
29
|
-
}
|
|
30
|
-
[inspectSymbol]() {
|
|
31
|
-
return SECRET_REDACTION_MARKER2;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
var secret2 = (value) => Secret2.from(value);
|
|
35
|
-
var unwrapSecret = (value) => {
|
|
36
|
-
const raw = secretValue.get(value);
|
|
37
|
-
if (raw === undefined) {
|
|
38
|
-
throw new TypeError("DALP SDK: cannot unwrap an invalid secret value.");
|
|
39
|
-
}
|
|
40
|
-
return raw;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/url.ts
|
|
44
|
-
function normalizeDalpBaseUrl(url) {
|
|
45
|
-
let parsed;
|
|
46
|
-
try {
|
|
47
|
-
parsed = new URL(url);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
throw createDalpSdkConfigurationError2({
|
|
50
|
-
message: `DALP SDK: invalid url "${url}". Provide a full URL including the protocol (e.g., "https://dalp.example.com").`,
|
|
51
|
-
why: "The SDK could not parse the configured DALP API URL.",
|
|
52
|
-
fix: 'Provide a full http:// or https:// URL, for example "https://dalp.example.com".',
|
|
53
|
-
cause: error
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
57
|
-
throw createDalpSdkConfigurationError2({
|
|
58
|
-
message: `DALP SDK: url must use https:// or http:// protocol, got "${parsed.protocol}".`,
|
|
59
|
-
why: `The SDK received a URL with the unsupported "${parsed.protocol}" protocol.`,
|
|
60
|
-
fix: 'Use a DALP API base URL that starts with "https://" or "http://".'
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return `${parsed.origin}${parsed.pathname.replace(/\/+$/, "")}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/runtime.ts
|
|
67
|
-
var REACT_NATIVE_NAVIGATOR_PRODUCT = "ReactNative";
|
|
68
|
-
function detectDalpRuntime() {
|
|
69
|
-
if (Reflect.get(globalThis, "navigator") !== undefined && Reflect.get(navigator, "product") === REACT_NATIVE_NAVIGATOR_PRODUCT) {
|
|
70
|
-
return "react-native";
|
|
71
|
-
}
|
|
72
|
-
return globalThis.window === undefined ? "server" : "browser";
|
|
73
|
-
}
|
|
74
|
-
function runtimeCredentials(runtime) {
|
|
75
|
-
return runtime === "browser" ? "include" : "omit";
|
|
76
|
-
}
|
|
77
|
-
var WHATWG_FETCH_POLYFILL_FLAG = "polyfill";
|
|
78
|
-
function isBufferingFetch(fetchImpl) {
|
|
79
|
-
return typeof fetchImpl === "function" && Reflect.get(fetchImpl, WHATWG_FETCH_POLYFILL_FLAG) === true;
|
|
80
|
-
}
|
|
81
|
-
function keepBufferingMarker(wrapped, wrapper) {
|
|
82
|
-
return isBufferingFetch(wrapped) ? Object.assign(wrapper, { [WHATWG_FETCH_POLYFILL_FLAG]: true }) : wrapper;
|
|
83
|
-
}
|
|
84
|
-
function refuseBundledApiKey(runtime) {
|
|
85
|
-
if (runtime === "server") {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
throw createDalpSdkConfigurationError2({
|
|
89
|
-
message: `DALP SDK: API keys are server/CLI-only credentials and cannot configure a ${runtime} client.`,
|
|
90
|
-
why: "An API key placed in a browser or app bundle ships the credential to every visitor or device.",
|
|
91
|
-
fix: "Keep the API key on the server or CLI process; browser and app clients authenticate with the session cookie."
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// ../kernel/json/src/step-up-payload-text.ts
|
|
96
|
-
var PROOF_FIELD = "walletVerification";
|
|
97
|
-
var isAbsent = (value) => value === undefined || typeof value === "function" || typeof value === "symbol";
|
|
98
|
-
var byKey = ([left], [right]) => {
|
|
99
|
-
if (left < right) {
|
|
100
|
-
return -1;
|
|
101
|
-
}
|
|
102
|
-
if (left > right) {
|
|
103
|
-
return 1;
|
|
104
|
-
}
|
|
105
|
-
return 0;
|
|
106
|
-
};
|
|
107
|
-
var presentEntries = (fields, omitted) => {
|
|
108
|
-
const entries = [];
|
|
109
|
-
for (const [key, field] of fields) {
|
|
110
|
-
if (key !== omitted && !isAbsent(field)) {
|
|
111
|
-
entries.push([key, field]);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return entries.toSorted(byKey);
|
|
115
|
-
};
|
|
116
|
-
var canonicalText = (value, omitted = null) => {
|
|
117
|
-
if (value === null || isAbsent(value)) {
|
|
118
|
-
return "null";
|
|
119
|
-
}
|
|
120
|
-
if (typeof value !== "object") {
|
|
121
|
-
return JSON.stringify(value);
|
|
122
|
-
}
|
|
123
|
-
if (Array.isArray(value)) {
|
|
124
|
-
return `[${value.map((item) => canonicalText(item)).join(",")}]`;
|
|
125
|
-
}
|
|
126
|
-
return `{${presentEntries(Object.entries(value), omitted).map(([key, field]) => `${JSON.stringify(key)}:${canonicalText(field)}`).join(",")}}`;
|
|
127
|
-
};
|
|
128
|
-
var stepUpPayloadText = (body) => canonicalText(body, PROOF_FIELD);
|
|
129
|
-
|
|
130
|
-
// src/client/step-up-challenge.ts
|
|
131
|
-
import { sha256, stringToBytes } from "viem/utils";
|
|
132
|
-
var STEP_UP_CHALLENGE_HEADER = "X-Step-Up-Challenge";
|
|
133
|
-
var WALLET_VERIFICATION_HEADER = "X-Wallet-Verification";
|
|
134
|
-
var STEP_UP_CHALLENGE_PATH = "/api/v2/step-up-challenges";
|
|
135
|
-
var PROOF_FIELD2 = "walletVerification";
|
|
136
|
-
var HEX_PREFIX = "0x";
|
|
137
|
-
function carriesWalletProof(body) {
|
|
138
|
-
if (body === null || typeof body !== "object" || Array.isArray(body)) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
const proof = Reflect.get(body, PROOF_FIELD2);
|
|
142
|
-
return proof !== null && proof !== undefined;
|
|
143
|
-
}
|
|
144
|
-
async function stepUpChallengeRequest(operation, target, body) {
|
|
145
|
-
const payloadDigest = sha256(stringToBytes(stepUpPayloadText(body))).slice(HEX_PREFIX.length);
|
|
146
|
-
return { operation, target, payloadDigest };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export { DALP_AUTH_SURFACE_HEADER2, SECRET_REDACTION_MARKER2, Secret2, secret2, unwrapSecret, normalizeDalpBaseUrl, detectDalpRuntime, runtimeCredentials, isBufferingFetch, keepBufferingMarker, refuseBundledApiKey, STEP_UP_CHALLENGE_HEADER, WALLET_VERIFICATION_HEADER, STEP_UP_CHALLENGE_PATH, carriesWalletProof, stepUpChallengeRequest };
|