@settlemint/dalp-sdk 3.1.33 → 3.2.0-rc.1
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/LICENSE +3 -157
- package/README.md +276 -169
- package/dist/auth/client.d.ts +114 -0
- package/dist/auth/invite-step-up.d.ts +2 -0
- package/dist/auth/live.d.ts +47 -0
- package/dist/auth/native-passkey.d.ts +8 -0
- package/dist/{auth-permissions.d.ts → auth/permissions.d.ts} +0 -8
- package/dist/auth/wallet-plugins.d.ts +196 -0
- package/dist/auth-surface.d.ts +2 -0
- package/dist/auth.d.ts +8 -115
- package/dist/auth.js +540 -0
- package/dist/chunk-6hckdbwt.js +600 -0
- package/dist/chunk-7mvx7xq8.js +4 -0
- package/dist/chunk-b03ycwb7.js +68 -0
- package/dist/chunk-crtb9edj.js +29 -0
- package/dist/chunk-g5j1xky8.js +99 -0
- package/dist/chunk-grdfnbwd.js +1529 -0
- package/dist/chunk-j43gfc9p.js +5 -0
- package/dist/chunk-k3ntysxx.js +57 -0
- package/dist/chunk-ptwkww6j.js +38 -0
- package/dist/chunk-qncpzave.js +185 -0
- package/dist/chunk-t8v94nvb.js +5 -0
- package/dist/chunk-xnarraj7.js +339 -0
- package/dist/client/conditional-request.d.ts +8 -0
- package/dist/client/factory.d.ts +4 -0
- package/dist/client/query-serializer.d.ts +1 -0
- package/dist/client/request-compression.d.ts +12 -0
- package/dist/client/ssr-fetch.d.ts +10 -0
- package/dist/client/step-up-challenge.d.ts +10 -0
- package/dist/effect.d.ts +39 -0
- package/dist/effect.js +110 -0
- package/dist/errors/api-error.d.ts +35 -0
- package/dist/errors/error-codes.d.ts +18 -0
- package/dist/errors/find-current-error.d.ts +2 -0
- package/dist/errors/public-error.d.ts +3 -0
- package/dist/errors/public-error.js +9 -0
- package/dist/errors/sdk-error.d.ts +52 -0
- package/dist/errors/sdk-error.js +8 -0
- package/dist/generated/api-types.d.ts +104535 -0
- package/dist/generated/api-types.ts +111921 -0
- package/dist/generated/console-routes.d.ts +12 -0
- package/dist/generated/error-catalog.d.ts +9 -0
- package/dist/generated/error-codes.d.ts +9 -0
- package/dist/generated/response-scalars.d.ts +9 -0
- package/dist/generated/response-schemas.d.ts +9 -0
- package/dist/generated/route-error-codes.d.ts +9 -0
- package/dist/generated/routes.d.ts +12 -0
- package/dist/index.d.ts +28 -45
- package/dist/index.js +159 -94522
- package/dist/proxy/builder.d.ts +17 -0
- package/dist/proxy/client-core.d.ts +36 -0
- package/dist/proxy/client.d.ts +5 -0
- package/dist/proxy/fetch-executor.d.ts +7 -0
- package/dist/proxy/flat-args.d.ts +24 -0
- package/dist/proxy/response-decode.d.ts +38 -0
- package/dist/proxy/sse.d.ts +11 -0
- package/dist/proxy/step-up-challenge.d.ts +4 -0
- package/dist/proxy/tanstack.d.ts +6 -0
- package/dist/proxy/transport.d.ts +76 -0
- package/dist/react-query.d.ts +2 -0
- package/dist/react-query.js +14 -0
- package/dist/routes/cli-command.d.ts +17 -0
- package/dist/routes/console.d.ts +14 -0
- package/dist/routes/console.js +27 -0
- package/dist/routes/index.d.ts +6 -0
- package/dist/routes/index.js +122 -0
- package/dist/routes/types.d.ts +73 -0
- package/dist/runtime-exports.d.ts +4 -0
- package/dist/runtime-exports.js +38 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/scalars/big-decimal.d.ts +22 -0
- package/dist/scalars/big-int.d.ts +3 -0
- package/dist/scalars/dalp-scalars.d.ts +28 -0
- package/dist/scalars/ethereum-address.d.ts +3 -0
- package/dist/scalars/exchange-rates.d.ts +13 -0
- package/dist/scalars/index.d.ts +14 -0
- package/dist/scalars/index.js +236 -0
- package/dist/scalars/organization-id.d.ts +5 -0
- package/dist/scalars/token-decimals.d.ts +4 -0
- package/dist/secret.d.ts +12 -0
- package/dist/server-proxy.d.ts +39 -0
- package/dist/server-proxy.js +186 -0
- package/dist/sign-webhook-receipt.d.ts +16 -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 +24 -0
- package/dist/types.d.ts +38 -114
- package/dist/url.d.ts +0 -1
- package/dist/verify-webhook.d.ts +18 -28
- package/dist/verify-webhook.js +8 -0
- package/dist/version.d.ts +0 -3
- package/dist/wait-for-transaction.d.ts +46 -86
- package/dist/wait-for-transaction.js +154 -0
- package/dist/webhook-events.d.ts +1360 -35
- package/package.json +176 -36
- package/dist/api-types.generated.d.ts +0 -14160
- package/dist/api-types.generated.d.ts.map +0 -1
- package/dist/auth-permissions.d.ts.map +0 -1
- package/dist/auth-wallet-plugins.d.ts +0 -86
- package/dist/auth-wallet-plugins.d.ts.map +0 -1
- package/dist/auth.d.ts.map +0 -1
- package/dist/bundler.d.ts +0 -217
- package/dist/bundler.d.ts.map +0 -1
- 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 -22
- 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 -656
- package/dist/dapi-errors.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -639
- 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 -8
- 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/version.generated.d.ts +0 -8
- package/dist/version.generated.d.ts.map +0 -1
- package/dist/wait-for-transaction.d.ts.map +0 -1
- package/dist/webhook-events.d.ts.map +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
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 abortReason = (signal) => signal.reason instanceof Error ? signal.reason : new Error("Aborted", { cause: signal.reason });
|
|
45
|
+
var defaultSleep = (milliseconds, signal) => new Promise((resolve, reject) => {
|
|
46
|
+
if (signal?.aborted === true) {
|
|
47
|
+
reject(abortReason(signal));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const onAbort = () => {
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
if (signal !== undefined) {
|
|
53
|
+
reject(abortReason(signal));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const timeout = setTimeout(() => {
|
|
57
|
+
signal?.removeEventListener("abort", onAbort);
|
|
58
|
+
resolve();
|
|
59
|
+
}, milliseconds);
|
|
60
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
61
|
+
});
|
|
62
|
+
var routeStatusReader = (client) => async (transactionId, signal) => {
|
|
63
|
+
const result = await client.execute("transactionsV2.status", { transactionId }, signal === undefined ? undefined : { signal });
|
|
64
|
+
const body = result !== null && typeof result === "object" ? Reflect.get(result, "data") ?? result : result;
|
|
65
|
+
return body;
|
|
66
|
+
};
|
|
67
|
+
var MAX_UNREADABLE_HOLDS = 5;
|
|
68
|
+
var noParks = { fundingPaused: false, indexerRebuild: false };
|
|
69
|
+
var PAUSED_POLL_INTERVAL_MAX_MS = 30000;
|
|
70
|
+
function readParks(status, held) {
|
|
71
|
+
const fundingPaused = status.activeRequirement !== undefined && status.activeRequirement !== null;
|
|
72
|
+
const indexerRebuild = status.indexerRebuild !== undefined && status.indexerRebuild !== null;
|
|
73
|
+
return {
|
|
74
|
+
fundingPaused: fundingPaused || held.fundingPaused && status.activeRequirementUnavailable === true,
|
|
75
|
+
indexerRebuild: indexerRebuild || held.indexerRebuild && status.indexerRebuildUnavailable === true
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function namedPark(parks) {
|
|
79
|
+
if (parks.fundingPaused) {
|
|
80
|
+
return "funding-paused";
|
|
81
|
+
}
|
|
82
|
+
return parks.indexerRebuild ? "indexer-rebuild" : undefined;
|
|
83
|
+
}
|
|
84
|
+
async function waitForTransaction(client, transactionId, options = {}) {
|
|
85
|
+
const timeoutMs = options.timeoutMs ?? 120000;
|
|
86
|
+
const pollIntervalMs = options.pollIntervalMs ?? 1000;
|
|
87
|
+
const now = options.now ?? Date.now;
|
|
88
|
+
const sleep = options.sleep ?? defaultSleep;
|
|
89
|
+
const readStatus = options.readStatus ?? routeStatusReader(client);
|
|
90
|
+
const holdWhilePaused = options.holdWhilePaused ?? true;
|
|
91
|
+
const holdWhileRebuilding = options.holdWhileRebuilding ?? true;
|
|
92
|
+
const waitStartedAt = now();
|
|
93
|
+
let budgetStartedAt = waitStartedAt;
|
|
94
|
+
let pollDelayMs = pollIntervalMs;
|
|
95
|
+
let lastStatus;
|
|
96
|
+
let held = noParks;
|
|
97
|
+
let unreadableHolds = 0;
|
|
98
|
+
const isAborted = () => options.signal?.aborted === true;
|
|
99
|
+
while (true) {
|
|
100
|
+
if (isAborted()) {
|
|
101
|
+
throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
|
|
102
|
+
}
|
|
103
|
+
if (now() - budgetStartedAt >= timeoutMs) {
|
|
104
|
+
const ranOutIn = namedPark(held) ?? "timeout";
|
|
105
|
+
throw new DalpTransactionWaitError(transactionId, ranOutIn, lastStatus, now() - waitStartedAt);
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
lastStatus = await readStatus(transactionId, options.signal);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (isAborted()) {
|
|
111
|
+
throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
options.onStatus?.(lastStatus);
|
|
116
|
+
if (failedStates.has(lastStatus.status) && lastStatus.mayStillLand !== true) {
|
|
117
|
+
throw new DalpTransactionWaitError(transactionId, "terminal-failure", lastStatus);
|
|
118
|
+
}
|
|
119
|
+
if (isWaitForTransactionSuccess(lastStatus)) {
|
|
120
|
+
return lastStatus;
|
|
121
|
+
}
|
|
122
|
+
const ownParks = readParks(lastStatus, noParks);
|
|
123
|
+
held = readParks(lastStatus, held);
|
|
124
|
+
const parkedBy = namedPark(held);
|
|
125
|
+
unreadableHolds = parkedBy === undefined || namedPark(ownParks) !== undefined ? 0 : unreadableHolds + 1;
|
|
126
|
+
let holdsThroughIt = false;
|
|
127
|
+
if (parkedBy === "funding-paused") {
|
|
128
|
+
holdsThroughIt = holdWhilePaused;
|
|
129
|
+
} else if (parkedBy === "indexer-rebuild") {
|
|
130
|
+
holdsThroughIt = holdWhileRebuilding;
|
|
131
|
+
}
|
|
132
|
+
if (parkedBy === undefined) {
|
|
133
|
+
pollDelayMs = pollIntervalMs;
|
|
134
|
+
} else {
|
|
135
|
+
if (!holdsThroughIt) {
|
|
136
|
+
throw new DalpTransactionWaitError(transactionId, parkedBy, lastStatus, now() - waitStartedAt);
|
|
137
|
+
}
|
|
138
|
+
if (unreadableHolds <= MAX_UNREADABLE_HOLDS) {
|
|
139
|
+
budgetStartedAt = now();
|
|
140
|
+
}
|
|
141
|
+
pollDelayMs = Math.min(pollDelayMs * 2, Math.max(pollIntervalMs, PAUSED_POLL_INTERVAL_MAX_MS));
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
await sleep(Math.min(pollDelayMs, Math.max(0, timeoutMs - (now() - budgetStartedAt))), options.signal);
|
|
145
|
+
} catch {
|
|
146
|
+
throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
DalpTransactionWaitError,
|
|
152
|
+
isDalpTransactionWaitError,
|
|
153
|
+
waitForTransaction
|
|
154
|
+
};
|