@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
@@ -1,94 +1,52 @@
1
- /**
2
- * Bounded wait-until-terminal barrier for queued DALP mutations.
3
- *
4
- * A v2 mutation may return a `202`-style async-accepted envelope when its
5
- * synchronous wait window elapses while the execution workflow is still
6
- * confirming. `waitForTransaction` turns that into a deterministic outcome:
7
- * poll the transaction status route at a FIXED interval bounded by a wall-clock
8
- * deadline, resolve on a terminal success, throw a typed error on a terminal
9
- * failure, and throw a loud timeout error if the deadline elapses first.
10
- *
11
- * This is a determinism barrier, not a masking retry — total wait is bounded by
12
- * `timeoutMs` (never exponential), and a never-terminating transaction fails
13
- * loud and bounded instead of hanging.
14
- *
15
- * Related: kit/sdk/src/types.ts
16
- * Related: packages/dalp/api-contract/src/routes/transaction/routes/transaction.status.schema.ts
17
- *
18
- * @module
19
- */
20
- import type { DalpClient } from "./types.js";
21
- /** Outcome shape returned by the transaction status route, narrowed to the fields this helper reads. */
22
- export interface WaitForTransactionResult {
23
- readonly tokenAddress?: unknown;
1
+ import type { DalpClient } from "./proxy/client.ts";
2
+ import type { EvmTransactionStatusOutput } from "./generated/api-types.d.ts";
3
+ export interface WaitForTransactionContractError {
4
+ readonly id: string;
5
+ readonly args: Readonly<Record<string, string>>;
6
+ readonly why: string;
7
+ readonly message: string;
8
+ readonly fix?: string;
24
9
  }
25
10
  export interface WaitForTransactionStatus {
26
- transactionId: string;
27
- status: string;
28
- subStatus: string | null;
29
- transactionHash: string | null;
30
- errorMessage: string | null;
31
- result?: WaitForTransactionResult;
11
+ readonly transactionId: string;
12
+ readonly status: string;
13
+ readonly subStatus: string | null;
14
+ readonly transactionHash: string | null;
15
+ readonly errorMessage: string | null;
16
+ readonly contractError?: WaitForTransactionContractError | null;
17
+ readonly result?: WaitForTransactionResult;
18
+ readonly activeRequirement?: EvmTransactionStatusOutput["activeRequirement"];
19
+ readonly activeRequirementUnavailable?: EvmTransactionStatusOutput["activeRequirementUnavailable"];
20
+ readonly indexerRebuild?: EvmTransactionStatusOutput["indexerRebuild"];
21
+ readonly indexerRebuildUnavailable?: EvmTransactionStatusOutput["indexerRebuildUnavailable"];
22
+ }
23
+ export type WaitForTransactionResult = NonNullable<EvmTransactionStatusOutput["result"]>;
24
+ export interface WaitForTransactionSuccess extends WaitForTransactionStatus {
25
+ readonly status: "COMPLETED";
32
26
  }
33
27
  export interface WaitForTransactionOptions {
34
- /** Wall-clock ceiling for the whole wait, in milliseconds. Default 120_000. */
35
- timeoutMs?: number;
36
- /** Fixed delay between status polls, in milliseconds. Default 2_000. */
37
- intervalMs?: number;
38
- /**
39
- * Resolve (instead of continuing to poll) when the transaction reaches
40
- * `PENDING_APPROVAL` — an external approval gate (DFNS / Fireblocks) that is
41
- * not a stall and may legitimately outlast the deadline. Default `true`.
42
- */
43
- resolveOnPendingApproval?: boolean;
44
- /**
45
- * Cancels the wait when the owning context (React component, request handler,
46
- * workflow step) is torn down. An aborted signal stops the loop on the next
47
- * iteration, cancels the in-flight status request, and surfaces as a
48
- * {@link DalpTransactionWaitError} with `reason: "aborted"`.
49
- */
50
- signal?: AbortSignal;
28
+ readonly timeoutMs?: number;
29
+ readonly pollIntervalMs?: number;
30
+ readonly signal?: AbortSignal;
31
+ readonly onStatus?: (status: WaitForTransactionStatus) => void;
32
+ readonly holdWhilePaused?: boolean;
33
+ readonly holdWhileRebuilding?: boolean;
34
+ readonly now?: () => number;
35
+ readonly sleep?: (milliseconds: number, signal?: AbortSignal) => Promise<void>;
36
+ readonly readStatus?: (transactionId: string, signal?: AbortSignal) => Promise<WaitForTransactionStatus>;
51
37
  }
52
- /**
53
- * Thrown when a transaction reaches a terminal failure state
54
- * (`FAILED` / `DEAD_LETTER` / `CANCELLED`), does not reach any terminal state
55
- * within the deadline (`reason: "timeout"`), or the caller's `AbortSignal`
56
- * fires (`reason: "aborted"`).
57
- */
38
+ export type TransactionWaitFailureReason = "terminal-failure" | "timeout" | "aborted" | "funding-paused" | "indexer-rebuild";
58
39
  export declare class DalpTransactionWaitError extends Error {
40
+ readonly code = "sdk.transaction.WAIT_FAILED";
41
+ readonly category: "operational";
59
42
  readonly transactionId: string;
60
- readonly status: string;
61
- readonly subStatus: string | null;
62
- readonly reason: "terminal-failure" | "timeout" | "aborted";
63
- readonly lastStatus: WaitForTransactionStatus | undefined;
64
- constructor(options: {
65
- message: string;
66
- transactionId: string;
67
- status: string;
68
- subStatus: string | null;
69
- reason: "terminal-failure" | "timeout" | "aborted";
70
- lastStatus?: WaitForTransactionStatus;
71
- cause?: unknown;
72
- });
43
+ readonly reason: TransactionWaitFailureReason;
44
+ readonly lastStatus?: WaitForTransactionStatus;
45
+ readonly elapsedMs?: number;
46
+ constructor(transactionId: string, reason: TransactionWaitFailureReason, lastStatus?: WaitForTransactionStatus, elapsedMs?: number);
47
+ get status(): string;
48
+ get subStatus(): string | null;
49
+ get retryable(): boolean;
73
50
  }
74
- /**
75
- * Poll the transaction status route until the transaction reaches a terminal
76
- * state or the deadline elapses.
77
- *
78
- * - `COMPLETED` → resolves with the final status (the handler already waited for
79
- * the indexer drain, so this is a true read-after-write guarantee).
80
- * - `FAILED` / `DEAD_LETTER` / `CANCELLED` → throws {@link DalpTransactionWaitError}
81
- * (`reason: "terminal-failure"`) carrying `status`, `subStatus`, and
82
- * `errorMessage` — fail fast, do not keep polling.
83
- * - `PENDING_APPROVAL` → resolves as pending (when `resolveOnPendingApproval`,
84
- * the default) so an external approval gate is never treated as a stall.
85
- * - deadline elapsed → throws {@link DalpTransactionWaitError} (`reason: "timeout"`)
86
- * carrying the last observed status — a loud, bounded failure, never an
87
- * indefinite hang.
88
- *
89
- * @param client A DALP API client.
90
- * @param transactionId The queue transaction identifier (UUIDv7) returned in the
91
- * async-accepted envelope.
92
- */
93
- export declare function waitForTransaction(client: DalpClient, transactionId: string, options?: WaitForTransactionOptions): Promise<WaitForTransactionStatus>;
94
- //# sourceMappingURL=wait-for-transaction.d.ts.map
51
+ export declare const isDalpTransactionWaitError: (error: unknown) => error is DalpTransactionWaitError;
52
+ export declare function waitForTransaction(client: DalpClient, transactionId: string, options?: WaitForTransactionOptions): Promise<WaitForTransactionSuccess>;
@@ -0,0 +1,151 @@
1
+ // src/wait-for-transaction.ts
2
+ var failedStates = new Set(["FAILED", "DEAD_LETTER", "CANCELLED"]);
3
+ var isWaitForTransactionSuccess = (status) => status.status === "COMPLETED";
4
+
5
+ class DalpTransactionWaitError extends Error {
6
+ code = "sdk.transaction.WAIT_FAILED";
7
+ category = "operational";
8
+ transactionId;
9
+ reason;
10
+ lastStatus;
11
+ elapsedMs;
12
+ constructor(transactionId, reason, lastStatus, elapsedMs) {
13
+ let message;
14
+ if (reason === "terminal-failure") {
15
+ message = `Transaction ${transactionId} reached terminal state ${lastStatus?.status ?? "UNKNOWN"}`;
16
+ } else if (reason === "timeout") {
17
+ message = `Transaction ${transactionId} did not reach a terminal state within ${elapsedMs ?? 0}ms`;
18
+ } else if (reason === "funding-paused") {
19
+ message = `Transaction ${transactionId} is paused waiting for a gas funding payment`;
20
+ } else if (reason === "indexer-rebuild") {
21
+ const chainId = lastStatus?.indexerRebuild?.chainId;
22
+ message = `Transaction ${transactionId} is on chain, and the platform is still rebuilding its index of chain ${chainId ?? "unknown"} before the write can be read back`;
23
+ } else {
24
+ message = `Transaction status observation was aborted for transaction ${transactionId}`;
25
+ }
26
+ super(message);
27
+ this.name = "DalpTransactionWaitError";
28
+ this.transactionId = transactionId;
29
+ this.reason = reason;
30
+ this.lastStatus = lastStatus;
31
+ this.elapsedMs = elapsedMs;
32
+ }
33
+ get status() {
34
+ return this.lastStatus?.status ?? "UNKNOWN";
35
+ }
36
+ get subStatus() {
37
+ return this.lastStatus?.subStatus ?? null;
38
+ }
39
+ get retryable() {
40
+ return this.reason === "timeout" || this.reason === "funding-paused" || this.reason === "indexer-rebuild";
41
+ }
42
+ }
43
+ var isDalpTransactionWaitError = (error) => error instanceof DalpTransactionWaitError;
44
+ var defaultSleep = (milliseconds, signal) => new Promise((resolve, reject) => {
45
+ if (signal?.aborted === true) {
46
+ reject(signal.reason);
47
+ return;
48
+ }
49
+ const onAbort = () => {
50
+ clearTimeout(timeout);
51
+ reject(signal?.reason);
52
+ };
53
+ const timeout = setTimeout(() => {
54
+ signal?.removeEventListener("abort", onAbort);
55
+ resolve();
56
+ }, milliseconds);
57
+ signal?.addEventListener("abort", onAbort, { once: true });
58
+ });
59
+ var routeStatusReader = (client) => async (transactionId, signal) => {
60
+ const result = await client.execute("transactionsV2.status", { transactionId }, signal === undefined ? undefined : { signal });
61
+ const body = result !== null && typeof result === "object" ? Reflect.get(result, "data") ?? result : result;
62
+ return body;
63
+ };
64
+ var MAX_UNREADABLE_HOLDS = 5;
65
+ var noParks = { fundingPaused: false, indexerRebuild: false };
66
+ var PAUSED_POLL_INTERVAL_MAX_MS = 30000;
67
+ function readParks(status, held) {
68
+ const fundingPaused = status.activeRequirement !== undefined && status.activeRequirement !== null;
69
+ const indexerRebuild = status.indexerRebuild !== undefined && status.indexerRebuild !== null;
70
+ return {
71
+ fundingPaused: fundingPaused || held.fundingPaused && status.activeRequirementUnavailable === true,
72
+ indexerRebuild: indexerRebuild || held.indexerRebuild && status.indexerRebuildUnavailable === true
73
+ };
74
+ }
75
+ function namedPark(parks) {
76
+ if (parks.fundingPaused) {
77
+ return "funding-paused";
78
+ }
79
+ return parks.indexerRebuild ? "indexer-rebuild" : undefined;
80
+ }
81
+ async function waitForTransaction(client, transactionId, options = {}) {
82
+ const timeoutMs = options.timeoutMs ?? 120000;
83
+ const pollIntervalMs = options.pollIntervalMs ?? 1000;
84
+ const now = options.now ?? Date.now;
85
+ const sleep = options.sleep ?? defaultSleep;
86
+ const readStatus = options.readStatus ?? routeStatusReader(client);
87
+ const holdWhilePaused = options.holdWhilePaused ?? true;
88
+ const holdWhileRebuilding = options.holdWhileRebuilding ?? true;
89
+ const waitStartedAt = now();
90
+ let budgetStartedAt = waitStartedAt;
91
+ let pollDelayMs = pollIntervalMs;
92
+ let lastStatus;
93
+ let held = noParks;
94
+ let unreadableHolds = 0;
95
+ const isAborted = () => options.signal?.aborted === true;
96
+ while (true) {
97
+ if (isAborted()) {
98
+ throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
99
+ }
100
+ if (now() - budgetStartedAt >= timeoutMs) {
101
+ const ranOutIn = namedPark(held) ?? "timeout";
102
+ throw new DalpTransactionWaitError(transactionId, ranOutIn, lastStatus, now() - waitStartedAt);
103
+ }
104
+ try {
105
+ lastStatus = await readStatus(transactionId, options.signal);
106
+ } catch (error) {
107
+ if (isAborted()) {
108
+ throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
109
+ }
110
+ throw error;
111
+ }
112
+ options.onStatus?.(lastStatus);
113
+ if (failedStates.has(lastStatus.status)) {
114
+ throw new DalpTransactionWaitError(transactionId, "terminal-failure", lastStatus);
115
+ }
116
+ if (isWaitForTransactionSuccess(lastStatus)) {
117
+ return lastStatus;
118
+ }
119
+ const ownParks = readParks(lastStatus, noParks);
120
+ held = readParks(lastStatus, held);
121
+ const parkedBy = namedPark(held);
122
+ unreadableHolds = parkedBy === undefined || namedPark(ownParks) !== undefined ? 0 : unreadableHolds + 1;
123
+ let holdsThroughIt = false;
124
+ if (parkedBy === "funding-paused") {
125
+ holdsThroughIt = holdWhilePaused;
126
+ } else if (parkedBy === "indexer-rebuild") {
127
+ holdsThroughIt = holdWhileRebuilding;
128
+ }
129
+ if (parkedBy === undefined) {
130
+ pollDelayMs = pollIntervalMs;
131
+ } else {
132
+ if (!holdsThroughIt) {
133
+ throw new DalpTransactionWaitError(transactionId, parkedBy, lastStatus, now() - waitStartedAt);
134
+ }
135
+ if (unreadableHolds <= MAX_UNREADABLE_HOLDS) {
136
+ budgetStartedAt = now();
137
+ }
138
+ pollDelayMs = Math.min(pollDelayMs * 2, Math.max(pollIntervalMs, PAUSED_POLL_INTERVAL_MAX_MS));
139
+ }
140
+ try {
141
+ await sleep(Math.min(pollDelayMs, Math.max(0, timeoutMs - (now() - budgetStartedAt))), options.signal);
142
+ } catch {
143
+ throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
144
+ }
145
+ }
146
+ }
147
+ export {
148
+ DalpTransactionWaitError,
149
+ isDalpTransactionWaitError,
150
+ waitForTransaction
151
+ };