@settlemint/dalp-sdk 3.1.25 → 3.1.26-main.37113215468

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.
Files changed (123) hide show
  1. package/README.md +239 -172
  2. package/dist/auth/client.d.ts +103 -0
  3. package/dist/auth/invite-step-up.d.ts +2 -0
  4. package/dist/auth/live.d.ts +47 -0
  5. package/dist/auth/native-passkey.d.ts +9 -0
  6. package/dist/{auth-permissions.d.ts → auth/permissions.d.ts} +0 -8
  7. package/dist/{auth-wallet-plugins.d.ts → auth/wallet-plugins.d.ts} +68 -6
  8. package/dist/auth-surface.d.ts +2 -0
  9. package/dist/auth.d.ts +8 -115
  10. package/dist/auth.js +525 -0
  11. package/dist/chunk-16xvy8xj.js +271 -0
  12. package/dist/chunk-4f4kjtt0.js +149 -0
  13. package/dist/chunk-b03ycwb7.js +68 -0
  14. package/dist/chunk-ghgcmyhk.js +5 -0
  15. package/dist/chunk-h241xecg.js +1625 -0
  16. package/dist/chunk-hqz56e6q.js +4 -0
  17. package/dist/chunk-k3ntysxx.js +57 -0
  18. package/dist/chunk-pjjrxre1.js +36 -0
  19. package/dist/chunk-qvtjb3dz.js +102 -0
  20. package/dist/chunk-w361dpdk.js +5 -0
  21. package/dist/client/conditional-request.d.ts +8 -0
  22. package/dist/client/factory.d.ts +4 -0
  23. package/dist/client/query-serializer.d.ts +1 -0
  24. package/dist/client/request-compression.d.ts +12 -0
  25. package/dist/client/ssr-fetch.d.ts +10 -0
  26. package/dist/client/step-up-challenge.d.ts +10 -0
  27. package/dist/effect.d.ts +38 -0
  28. package/dist/effect.js +87 -0
  29. package/dist/errors/api-error.d.ts +35 -0
  30. package/dist/errors/error-codes.d.ts +21 -0
  31. package/dist/errors/find-current-error.d.ts +2 -0
  32. package/dist/errors/sdk-error.d.ts +52 -0
  33. package/dist/errors/sdk-error.js +8 -0
  34. package/dist/generated/api-types.d.ts +69961 -0
  35. package/dist/generated/console-routes.d.ts +12 -0
  36. package/dist/generated/error-catalog.d.ts +9 -0
  37. package/dist/generated/error-codes.d.ts +9 -0
  38. package/dist/generated/response-scalars.d.ts +9 -0
  39. package/dist/generated/response-schemas.d.ts +9 -0
  40. package/dist/generated/route-error-codes.d.ts +9 -0
  41. package/dist/generated/routes.d.ts +12 -0
  42. package/dist/index.d.ts +28 -45
  43. package/dist/index.js +150 -96216
  44. package/dist/proxy/builder.d.ts +17 -0
  45. package/dist/proxy/client-core.d.ts +28 -0
  46. package/dist/proxy/client.d.ts +5 -0
  47. package/dist/proxy/fetch-executor.d.ts +6 -0
  48. package/dist/proxy/flat-args.d.ts +24 -0
  49. package/dist/proxy/response-decode.d.ts +37 -0
  50. package/dist/proxy/sse.d.ts +11 -0
  51. package/dist/proxy/step-up-challenge.d.ts +4 -0
  52. package/dist/proxy/tanstack.d.ts +6 -0
  53. package/dist/proxy/transport.d.ts +63 -0
  54. package/dist/react-query.d.ts +2 -0
  55. package/dist/react-query.js +12 -0
  56. package/dist/readonly-deep.d.ts +3 -0
  57. package/dist/routes/console.d.ts +14 -0
  58. package/dist/routes/console.js +25 -0
  59. package/dist/routes/index.d.ts +4 -0
  60. package/dist/routes/index.js +10 -0
  61. package/dist/routes/types.d.ts +72 -0
  62. package/dist/runtime-exports.d.ts +4 -0
  63. package/dist/runtime-exports.js +16 -0
  64. package/dist/runtime.d.ts +11 -0
  65. package/dist/scalars/big-decimal.d.ts +4 -0
  66. package/dist/scalars/ethereum-address.d.ts +5 -0
  67. package/dist/scalars/exchange-rates.d.ts +13 -0
  68. package/dist/scalars/index.d.ts +10 -0
  69. package/dist/scalars/index.js +102 -0
  70. package/dist/scalars/organization-id.d.ts +5 -0
  71. package/dist/scalars/token-decimals.d.ts +4 -0
  72. package/dist/secret.d.ts +12 -0
  73. package/dist/sign-webhook-receipt.d.ts +16 -0
  74. package/dist/sign-webhook-receipt.js +26 -0
  75. package/dist/transport/cookie-store.d.ts +9 -0
  76. package/dist/transport/sse-lifecycle.d.ts +24 -0
  77. package/dist/types.d.ts +37 -114
  78. package/dist/url.d.ts +0 -1
  79. package/dist/verify-webhook.d.ts +17 -28
  80. package/dist/verify-webhook.js +8 -0
  81. package/dist/version.d.ts +0 -3
  82. package/dist/wait-for-transaction.d.ts +44 -86
  83. package/dist/wait-for-transaction.js +151 -0
  84. package/dist/webhook-events.d.ts +543 -33
  85. package/package.json +110 -34
  86. package/dist/api-types.generated.d.ts +0 -14160
  87. package/dist/api-types.generated.d.ts.map +0 -1
  88. package/dist/auth-permissions.d.ts.map +0 -1
  89. package/dist/auth-wallet-plugins.d.ts.map +0 -1
  90. package/dist/auth.d.ts.map +0 -1
  91. package/dist/bundler.d.ts +0 -217
  92. package/dist/bundler.d.ts.map +0 -1
  93. package/dist/chunk-xm8h1dzh.js +0 -33
  94. package/dist/client.d.ts +0 -19
  95. package/dist/client.d.ts.map +0 -1
  96. package/dist/contract-errors.d.ts +0 -4156
  97. package/dist/contract-errors.d.ts.map +0 -1
  98. package/dist/contract.d.ts +0 -22
  99. package/dist/contract.d.ts.map +0 -1
  100. package/dist/cookie-store.d.ts +0 -10
  101. package/dist/cookie-store.d.ts.map +0 -1
  102. package/dist/dapi-errors.d.ts +0 -654
  103. package/dist/dapi-errors.d.ts.map +0 -1
  104. package/dist/errors.d.ts +0 -637
  105. package/dist/errors.d.ts.map +0 -1
  106. package/dist/index.d.ts.map +0 -1
  107. package/dist/platform.d.ts +0 -41
  108. package/dist/platform.d.ts.map +0 -1
  109. package/dist/plugins/index.d.ts +0 -13
  110. package/dist/plugins/index.d.ts.map +0 -1
  111. package/dist/plugins/index.js +0 -10
  112. package/dist/sdk-error.d.ts +0 -74
  113. package/dist/sdk-error.d.ts.map +0 -1
  114. package/dist/serializers.d.ts +0 -41
  115. package/dist/serializers.d.ts.map +0 -1
  116. package/dist/types.d.ts.map +0 -1
  117. package/dist/url.d.ts.map +0 -1
  118. package/dist/verify-webhook.d.ts.map +0 -1
  119. package/dist/version.d.ts.map +0 -1
  120. package/dist/version.generated.d.ts +0 -8
  121. package/dist/version.generated.d.ts.map +0 -1
  122. package/dist/wait-for-transaction.d.ts.map +0 -1
  123. package/dist/webhook-events.d.ts.map +0 -1
package/dist/auth.js ADDED
@@ -0,0 +1,525 @@
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-16xvy8xj.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
+ };