@settlemint/dalp-sdk 3.1.18-main.33808370488 → 3.1.18
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 +169 -154
- package/dist/{auth/permissions.d.ts → auth-permissions.d.ts} +2 -1
- package/dist/auth-permissions.d.ts.map +1 -0
- package/dist/{auth/wallet-plugins.d.ts → auth-wallet-plugins.d.ts} +5 -69
- package/dist/auth-wallet-plugins.d.ts.map +1 -0
- package/dist/auth.d.ts +115 -22
- package/dist/auth.d.ts.map +1 -0
- package/dist/bundler.d.ts +207 -14
- 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 +17 -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 +650 -0
- package/dist/dapi-errors.d.ts.map +1 -0
- package/dist/errors.d.ts +633 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +40 -28
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96109 -131
- 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 +102 -65
- 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 +1 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/wait-for-transaction.d.ts +81 -54
- package/dist/wait-for-transaction.d.ts.map +1 -0
- package/dist/webhook-events.d.ts +27 -44
- package/dist/webhook-events.d.ts.map +1 -0
- package/package.json +30 -103
- package/dist/auth/client.d.ts +0 -113
- package/dist/auth/live.d.ts +0 -4366
- package/dist/auth.js +0 -329
- package/dist/bundler.js +0 -99
- package/dist/chunk-9k284df4.js +0 -4
- package/dist/chunk-def7rqy6.js +0 -946
- package/dist/chunk-f4t1bm86.js +0 -67
- package/dist/chunk-fjnq61hj.js +0 -11
- package/dist/chunk-h12fatty.js +0 -63
- package/dist/chunk-qp5ty384.js +0 -260
- package/dist/chunk-r0vsftj4.js +0 -102
- package/dist/chunk-tmk1f2yb.js +0 -33
- package/dist/chunk-y0d2c7kp.js +0 -54
- package/dist/client/conditional-request.d.ts +0 -30
- package/dist/client/factory.d.ts +0 -14
- package/dist/client/query-serializer.d.ts +0 -2
- package/dist/client/request-compression.d.ts +0 -47
- package/dist/client/ssr-fetch.d.ts +0 -12
- package/dist/effect.d.ts +0 -69
- package/dist/effect.js +0 -82
- package/dist/errors/api-error.d.ts +0 -29
- package/dist/errors/find-current-error.d.ts +0 -8
- 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 -41271
- package/dist/generated/response-scalars.d.ts +0 -9
- package/dist/generated/routes.d.ts +0 -12
- package/dist/proxy/builder.d.ts +0 -47
- package/dist/proxy/client.d.ts +0 -32
- package/dist/proxy/fetch-executor.d.ts +0 -28
- package/dist/proxy/flat-args.d.ts +0 -51
- package/dist/proxy/settlement.d.ts +0 -67
- package/dist/proxy/sse.d.ts +0 -54
- package/dist/proxy/tanstack.d.ts +0 -27
- package/dist/proxy/transport.d.ts +0 -73
- package/dist/react-query.d.ts +0 -16
- package/dist/react-query.js +0 -13
- package/dist/readonly-deep.d.ts +0 -12
- package/dist/reads-as-funding-paused.d.ts +0 -20
- package/dist/routes/index.d.ts +0 -20
- package/dist/routes/index.js +0 -10
- package/dist/routes/types.d.ts +0 -51
- package/dist/runtime-exports.d.ts +0 -20
- package/dist/runtime-exports.js +0 -16
- package/dist/scalars/big-decimal.d.ts +0 -16
- package/dist/scalars/ethereum-address.d.ts +0 -20
- package/dist/scalars/exchange-rates.d.ts +0 -27
- package/dist/scalars/index.d.ts +0 -18
- package/dist/scalars/index.js +0 -86
- package/dist/scalars/organization-id.d.ts +0 -20
- package/dist/secret.d.ts +0 -14
- package/dist/sign-webhook-receipt.d.ts +0 -76
- 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 -44
- package/dist/verify-webhook.js +0 -8
- package/dist/wait-for-transaction.js +0 -120
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rich-scalar decoding for the exchange-rates list response.
|
|
3
|
-
*
|
|
4
|
-
* The wire carries a contract-faithful decimal string and a lowercase address.
|
|
5
|
-
* This turns them into a `dnum` amount and a checksummed address. It reads the
|
|
6
|
-
* shape structurally rather than through a schema library: the SDK ships no
|
|
7
|
-
* runtime validator, because the platform validated the body on the way out and
|
|
8
|
-
* a second copy of every schema would reach every consumer for no added
|
|
9
|
-
* guarantee.
|
|
10
|
-
*
|
|
11
|
-
* @module
|
|
12
|
-
*/
|
|
13
|
-
import { type BigDecimalValue } from "./big-decimal.ts";
|
|
14
|
-
import { type EthereumAddressValue } from "./ethereum-address.ts";
|
|
15
|
-
export interface ExchangeRateRow {
|
|
16
|
-
readonly rate: BigDecimalValue | null;
|
|
17
|
-
readonly feedAddress: EthereumAddressValue | null;
|
|
18
|
-
readonly [key: string]: unknown;
|
|
19
|
-
}
|
|
20
|
-
export interface ExchangeRatesListResponse {
|
|
21
|
-
readonly data: ReadonlyArray<ExchangeRateRow>;
|
|
22
|
-
readonly [key: string]: unknown;
|
|
23
|
-
}
|
|
24
|
-
/** Decode a list response, converting its scalar columns. */
|
|
25
|
-
export declare function decodeExchangeRatesListResponse(payload: unknown): ExchangeRatesListResponse;
|
|
26
|
-
/** Kept for callers that spread this as a response transformer. */
|
|
27
|
-
export declare const exchangeRatesListTransformer: (data: unknown) => Promise<ExchangeRatesListResponse>;
|
package/dist/scalars/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rich-scalar decoders.
|
|
3
|
-
*
|
|
4
|
-
* The route table names which fields carry a scalar, keyed by dotted path, so a
|
|
5
|
-
* caller applies these where the declaration says a scalar lives rather than
|
|
6
|
-
* guessing from a field name. They are plain functions: the SDK ships no
|
|
7
|
-
* runtime schema library, because the platform validates on the way out.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
export { decodeBigDecimal, encodeBigDecimal } from "./big-decimal.ts";
|
|
12
|
-
export type { BigDecimalValue } from "./big-decimal.ts";
|
|
13
|
-
export { decodeEthereumAddress, tryDecodeEthereumAddress } from "./ethereum-address.ts";
|
|
14
|
-
export type { EthereumAddressValue } from "./ethereum-address.ts";
|
|
15
|
-
export { decodeOrganizationId, tryDecodeOrganizationId } from "./organization-id.ts";
|
|
16
|
-
export type { OrganizationIdValue } from "./organization-id.ts";
|
|
17
|
-
export { decodeExchangeRatesListResponse, exchangeRatesListTransformer } from "./exchange-rates.ts";
|
|
18
|
-
export type { ExchangeRateRow, ExchangeRatesListResponse } from "./exchange-rates.ts";
|
package/dist/scalars/index.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DalpSdkError
|
|
3
|
-
} from "../chunk-y0d2c7kp.js";
|
|
4
|
-
|
|
5
|
-
// src/scalars/big-decimal.ts
|
|
6
|
-
import * as dn from "dnum";
|
|
7
|
-
var DECIMAL_WIRE = /^-?\d+(?:\.\d+)?$/u;
|
|
8
|
-
function decodeBigDecimal(wire) {
|
|
9
|
-
if (!DECIMAL_WIRE.test(wire)) {
|
|
10
|
-
throw new DalpSdkError({
|
|
11
|
-
code: "sdk.scalar.BIG_DECIMAL_INVALID",
|
|
12
|
-
category: "sdk.configuration",
|
|
13
|
-
retryable: false,
|
|
14
|
-
message: `\`${wire}\` is not a plain decimal string.`,
|
|
15
|
-
why: "A BigDecimal field carries an unscaled decimal, with no exponent and no separators.",
|
|
16
|
-
fix: "Pass the value exactly as the API returned it."
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return dn.from(wire);
|
|
20
|
-
}
|
|
21
|
-
var encodeBigDecimal = (value) => dn.toString(value);
|
|
22
|
-
// src/scalars/ethereum-address.ts
|
|
23
|
-
import { getAddress, isAddress } from "viem";
|
|
24
|
-
function decodeEthereumAddress(wire) {
|
|
25
|
-
if (!isAddress(wire, { strict: false })) {
|
|
26
|
-
throw new DalpSdkError({
|
|
27
|
-
code: "sdk.scalar.EVM_ADDRESS_INVALID",
|
|
28
|
-
category: "sdk.configuration",
|
|
29
|
-
retryable: false,
|
|
30
|
-
message: `\`${wire}\` is not an EVM address.`,
|
|
31
|
-
why: "An EVM address is 42 characters starting with 0x.",
|
|
32
|
-
fix: "Pass the address exactly as the API returned it."
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return getAddress(wire);
|
|
36
|
-
}
|
|
37
|
-
function tryDecodeEthereumAddress(wire) {
|
|
38
|
-
if (typeof wire !== "string" || !isAddress(wire, { strict: false })) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
return getAddress(wire);
|
|
42
|
-
}
|
|
43
|
-
// src/scalars/organization-id.ts
|
|
44
|
-
function decodeOrganizationId(wire) {
|
|
45
|
-
if (wire.length === 0) {
|
|
46
|
-
throw new DalpSdkError({
|
|
47
|
-
code: "sdk.scalar.ORGANIZATION_ID_INVALID",
|
|
48
|
-
category: "sdk.configuration",
|
|
49
|
-
retryable: false,
|
|
50
|
-
message: "An organization id cannot be empty.",
|
|
51
|
-
why: "The organization id scopes every tenant-owned request.",
|
|
52
|
-
fix: "Pass the id the platform returned for the active organization."
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return wire;
|
|
56
|
-
}
|
|
57
|
-
function tryDecodeOrganizationId(wire) {
|
|
58
|
-
return typeof wire === "string" && wire.length > 0 ? wire : undefined;
|
|
59
|
-
}
|
|
60
|
-
// src/scalars/exchange-rates.ts
|
|
61
|
-
function decodeRow(row) {
|
|
62
|
-
const source = row !== null && typeof row === "object" ? row : { rate: null, feedAddress: null };
|
|
63
|
-
const rate = Reflect.get(source, "rate");
|
|
64
|
-
const feedAddress = Reflect.get(source, "feedAddress");
|
|
65
|
-
return {
|
|
66
|
-
...source,
|
|
67
|
-
rate: typeof rate === "string" ? decodeBigDecimal(rate) : null,
|
|
68
|
-
feedAddress: typeof feedAddress === "string" ? decodeEthereumAddress(feedAddress) : null
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function decodeExchangeRatesListResponse(payload) {
|
|
72
|
-
const source = payload !== null && typeof payload === "object" ? payload : { data: [] };
|
|
73
|
-
const rows = Reflect.get(source, "data");
|
|
74
|
-
return { ...source, data: Array.isArray(rows) ? rows.map(decodeRow) : [] };
|
|
75
|
-
}
|
|
76
|
-
var exchangeRatesListTransformer = async (data) => decodeExchangeRatesListResponse(data);
|
|
77
|
-
export {
|
|
78
|
-
decodeBigDecimal,
|
|
79
|
-
decodeEthereumAddress,
|
|
80
|
-
decodeExchangeRatesListResponse,
|
|
81
|
-
decodeOrganizationId,
|
|
82
|
-
encodeBigDecimal,
|
|
83
|
-
exchangeRatesListTransformer,
|
|
84
|
-
tryDecodeEthereumAddress,
|
|
85
|
-
tryDecodeOrganizationId
|
|
86
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Branded organization id: the only entity id branded end to end across the
|
|
3
|
-
* platform. Runtime validation is minimal; the brand is the type-level
|
|
4
|
-
* contract.
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
export type OrganizationIdValue = string & {
|
|
9
|
-
readonly __brand: "OrganizationId";
|
|
10
|
-
};
|
|
11
|
-
/** Brand a non-empty organization id. */
|
|
12
|
-
export declare function decodeOrganizationId(wire: string): OrganizationIdValue;
|
|
13
|
-
/**
|
|
14
|
-
* Brand an organization id, or return nothing when it is not one.
|
|
15
|
-
*
|
|
16
|
-
* The mirror of {@link decodeOrganizationId} for callers that need a verdict
|
|
17
|
-
* rather than an exception, which is what the previous schema's `safeParse`
|
|
18
|
-
* gave them.
|
|
19
|
-
*/
|
|
20
|
-
export declare function tryDecodeOrganizationId(wire: unknown): OrganizationIdValue | undefined;
|
package/dist/secret.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const SECRET_REDACTION_MARKER = "[REDACTED]";
|
|
2
|
-
declare const inspectSymbol: unique symbol;
|
|
3
|
-
/** Opaque secret value which cannot leak through common serialization paths. */
|
|
4
|
-
export declare class Secret {
|
|
5
|
-
private constructor();
|
|
6
|
-
static from(value: string): Secret;
|
|
7
|
-
toString(): string;
|
|
8
|
-
toJSON(): string;
|
|
9
|
-
[inspectSymbol](): string;
|
|
10
|
-
}
|
|
11
|
-
export declare const secret: (value: string) => Secret;
|
|
12
|
-
/** Reveal a secret only at the transport header-injection boundary. */
|
|
13
|
-
export declare const unwrapSecret: (value: Secret) => string;
|
|
14
|
-
export {};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Counter-sign a DALP webhook delivery receipt.
|
|
3
|
-
*
|
|
4
|
-
* The inbound half of webhook signing (`verifyWebhook`) proves a delivery
|
|
5
|
-
* DALP sent is authentic. This is the return half: after a consumer verifies
|
|
6
|
-
* and accepts a delivery, it counter-signs a receipt so the platform has
|
|
7
|
-
* non-repudiation proof the consumer received and acknowledged that specific
|
|
8
|
-
* delivery. Submit the result to `POST /api/v2/webhook-receipts`.
|
|
9
|
-
*
|
|
10
|
-
* The canonical signing string and HMAC mirror the server-side implementation,
|
|
11
|
-
* which a published package cannot import. A shared golden test vector pins the
|
|
12
|
-
* output of both so the two copies cannot drift.
|
|
13
|
-
*
|
|
14
|
-
* @module
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Scheme tag prefixed to the counter-signed receipt signing string. It
|
|
18
|
-
* domain-separates receipt signatures from inbound delivery signatures and
|
|
19
|
-
* reserves room for a future scheme revision.
|
|
20
|
-
*/
|
|
21
|
-
export declare const RECEIPT_SIGNING_SCHEME = "dalp.whr.v1";
|
|
22
|
-
/** The delivery tuple a receipt signature binds. */
|
|
23
|
-
export interface ReceiptSigningTuple {
|
|
24
|
-
/** The delivery being acknowledged. A retry allocates a fresh `deliveryId`. */
|
|
25
|
-
deliveryId: string;
|
|
26
|
-
/** The endpoint that received the delivery. */
|
|
27
|
-
endpointId: string;
|
|
28
|
-
/** The event identifier carried by the delivery (`evt_*`). */
|
|
29
|
-
evtId: string;
|
|
30
|
-
/** The hash of the delivered event body (`sha256:<hex>`). */
|
|
31
|
-
innerEventHash: string;
|
|
32
|
-
}
|
|
33
|
-
export interface SignWebhookReceiptInput extends ReceiptSigningTuple {
|
|
34
|
-
/** The endpoint signing secret (`dalp_whsk_...`); the prefix is stripped for you. */
|
|
35
|
-
secret: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Build the canonical string a consumer HMACs to counter-sign a receipt.
|
|
39
|
-
*
|
|
40
|
-
* Binding the signature to the full delivery tuple, not just the event body
|
|
41
|
-
* hash, is what closes the receipt-replay window: a retry allocates a fresh
|
|
42
|
-
* `deliveryId` for the same event, so a signature minted for one attempt
|
|
43
|
-
* produces a different signing string than another attempt and no longer
|
|
44
|
-
* verifies against it.
|
|
45
|
-
*
|
|
46
|
-
* Newline-joined is unambiguous because every field carries no newline:
|
|
47
|
-
* `deliveryId`/`endpointId` are UUIDs, `evtId` is the server-issued `evt_*`
|
|
48
|
-
* identifier, and `innerEventHash` is `sha256:<hex>`.
|
|
49
|
-
*/
|
|
50
|
-
export declare function buildReceiptSigningString(tuple: Readonly<ReceiptSigningTuple>): string;
|
|
51
|
-
/**
|
|
52
|
-
* Counter-sign a webhook delivery receipt.
|
|
53
|
-
*
|
|
54
|
-
* Returns the lowercase hex `HMAC-SHA256(key, signingString)` to submit as the
|
|
55
|
-
* receipt's `consumerSignature`. The key is the base64-decoded prefix-stripped
|
|
56
|
-
* secret, the same derivation the Standard Webhooks library uses for inbound
|
|
57
|
-
* delivery verification (`verifyWebhook`) and that the dispatcher signs with —
|
|
58
|
-
* so the receipt and the delivery share key material.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* const consumerSignature = signWebhookReceipt({
|
|
63
|
-
* deliveryId,
|
|
64
|
-
* endpointId,
|
|
65
|
-
* evtId,
|
|
66
|
-
* innerEventHash,
|
|
67
|
-
* secret, // the endpoint's dalp_whsk_... signing secret
|
|
68
|
-
* });
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare function signWebhookReceipt({ secret, ...tuple }: Readonly<SignWebhookReceiptInput>): string;
|
|
72
|
-
export interface VerifyWebhookReceiptInput extends SignWebhookReceiptInput {
|
|
73
|
-
readonly signature: string;
|
|
74
|
-
}
|
|
75
|
-
/** Verify a counter-signed receipt without leaking signature timing. */
|
|
76
|
-
export declare function verifyWebhookReceipt({ signature, ...input }: Readonly<VerifyWebhookReceiptInput>): boolean;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
toStandardWebhookSecret
|
|
3
|
-
} from "./chunk-r0vsftj4.js";
|
|
4
|
-
|
|
5
|
-
// src/sign-webhook-receipt.ts
|
|
6
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
7
|
-
var RECEIPT_SIGNING_SCHEME = "dalp.whr.v1";
|
|
8
|
-
function buildReceiptSigningString(tuple) {
|
|
9
|
-
return [RECEIPT_SIGNING_SCHEME, tuple.deliveryId, tuple.endpointId, tuple.evtId, tuple.innerEventHash].join(`
|
|
10
|
-
`);
|
|
11
|
-
}
|
|
12
|
-
function signWebhookReceipt({ secret, ...tuple }) {
|
|
13
|
-
const key = Buffer.from(toStandardWebhookSecret(secret), "base64");
|
|
14
|
-
return createHmac("sha256", key).update(buildReceiptSigningString(tuple), "utf8").digest("hex");
|
|
15
|
-
}
|
|
16
|
-
function verifyWebhookReceipt({ signature, ...input }) {
|
|
17
|
-
const expected = Buffer.from(signWebhookReceipt(input), "hex");
|
|
18
|
-
const received = Buffer.from(signature, "hex");
|
|
19
|
-
return expected.length === received.length && timingSafeEqual(expected, received);
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
RECEIPT_SIGNING_SCHEME,
|
|
23
|
-
buildReceiptSigningString,
|
|
24
|
-
signWebhookReceipt,
|
|
25
|
-
verifyWebhookReceipt
|
|
26
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type CookieStoreFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
|
-
export interface CookieStoreShape {
|
|
3
|
-
readonly header: () => string;
|
|
4
|
-
readonly isEmpty: () => boolean;
|
|
5
|
-
readonly setCookieHeader: (header: string) => void;
|
|
6
|
-
readonly storeSetCookieHeaders: (headers: ReadonlyArray<string>) => void;
|
|
7
|
-
}
|
|
8
|
-
export declare function makeCookieStore(initialHeader?: string): CookieStoreShape;
|
|
9
|
-
export declare function createCookieStoreFetch(cookieStore: CookieStoreShape, fetchImpl?: CookieStoreFetch): CookieStoreFetch;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export type SseEventDisposition = "continue" | "success" | "failure";
|
|
2
|
-
export interface SseStreamResult<T> {
|
|
3
|
-
readonly stream: AsyncIterable<T>;
|
|
4
|
-
}
|
|
5
|
-
export interface SseLifecycleOptions<T> {
|
|
6
|
-
readonly connect: (signal: AbortSignal) => Promise<SseStreamResult<T>>;
|
|
7
|
-
readonly classify: (event: T) => SseEventDisposition;
|
|
8
|
-
readonly signal?: AbortSignal;
|
|
9
|
-
readonly onEvent?: (event: T) => void;
|
|
10
|
-
/**
|
|
11
|
-
* Opt into a bounded attempt count instead of the wall-clock window. Only
|
|
12
|
-
* for callers that genuinely want "n tries and stop" — a count is a poor
|
|
13
|
-
* budget when every failure is instant, because a single multi-second
|
|
14
|
-
* backend stall spends it all in a few hundred milliseconds.
|
|
15
|
-
*/
|
|
16
|
-
readonly maxReconnects?: number;
|
|
17
|
-
/**
|
|
18
|
-
* How long to keep reconnecting through an unbroken run of failures, in
|
|
19
|
-
* wall-clock milliseconds. The window is anchored at the first failure of a
|
|
20
|
-
* streak and restarts only after a connection stays up for
|
|
21
|
-
* `healthyConnectionMs`, so a long-lived stream that dies late still gets a
|
|
22
|
-
* full window.
|
|
23
|
-
*/
|
|
24
|
-
readonly reconnectWindowMs?: number;
|
|
25
|
-
/**
|
|
26
|
-
* How long a connection must stay up to count as recovered and clear the
|
|
27
|
-
* failure streak. Receiving events is deliberately *not* the test: a stream
|
|
28
|
-
* that replays its opening frame on every subscription would clear the
|
|
29
|
-
* streak on each attempt and reconnect forever.
|
|
30
|
-
*/
|
|
31
|
-
readonly healthyConnectionMs?: number;
|
|
32
|
-
readonly initialBackoffMs?: number;
|
|
33
|
-
readonly maxBackoffMs?: number;
|
|
34
|
-
readonly sleep?: (milliseconds: number) => Promise<void>;
|
|
35
|
-
readonly now?: () => number;
|
|
36
|
-
}
|
|
37
|
-
export type SseLifecycleFailureReason = "aborted" | "terminal-failure" | "transport-failure";
|
|
38
|
-
export declare class SseLifecycleError<T = unknown> extends Error {
|
|
39
|
-
readonly reason: SseLifecycleFailureReason;
|
|
40
|
-
readonly lastEvent?: T;
|
|
41
|
-
constructor(reason: SseLifecycleFailureReason, lastEvent?: T, options?: ErrorOptions);
|
|
42
|
-
}
|
|
43
|
-
/** Add terminal-state semantics to a generated Hey API SSE stream. */
|
|
44
|
-
export declare function consumeSseUntilTerminal<T>(options: SseLifecycleOptions<T>): Promise<T>;
|
package/dist/verify-webhook.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PAUSED_POLL_INTERVAL_MAX_MS,
|
|
3
|
-
readsAsFundingPaused
|
|
4
|
-
} from "./chunk-fjnq61hj.js";
|
|
5
|
-
|
|
6
|
-
// src/wait-for-transaction.ts
|
|
7
|
-
var failedStates = new Set(["FAILED", "DEAD_LETTER", "CANCELLED"]);
|
|
8
|
-
var isWaitForTransactionSuccess = (status) => status.status === "COMPLETED";
|
|
9
|
-
|
|
10
|
-
class DalpTransactionWaitError extends Error {
|
|
11
|
-
code = "sdk.transaction.WAIT_FAILED";
|
|
12
|
-
category = "operational";
|
|
13
|
-
transactionId;
|
|
14
|
-
reason;
|
|
15
|
-
lastStatus;
|
|
16
|
-
elapsedMs;
|
|
17
|
-
constructor(transactionId, reason, lastStatus, elapsedMs) {
|
|
18
|
-
let message;
|
|
19
|
-
if (reason === "terminal-failure") {
|
|
20
|
-
message = `Transaction ${transactionId} reached terminal state ${lastStatus?.status ?? "UNKNOWN"}`;
|
|
21
|
-
} else if (reason === "timeout") {
|
|
22
|
-
message = `Transaction ${transactionId} did not reach a terminal state within ${elapsedMs ?? 0}ms`;
|
|
23
|
-
} else if (reason === "funding-paused") {
|
|
24
|
-
message = `Transaction ${transactionId} is paused waiting for a gas funding payment`;
|
|
25
|
-
} else {
|
|
26
|
-
message = `Transaction status observation was aborted for transaction ${transactionId}`;
|
|
27
|
-
}
|
|
28
|
-
super(message);
|
|
29
|
-
this.name = "DalpTransactionWaitError";
|
|
30
|
-
this.transactionId = transactionId;
|
|
31
|
-
this.reason = reason;
|
|
32
|
-
this.lastStatus = lastStatus;
|
|
33
|
-
this.elapsedMs = elapsedMs;
|
|
34
|
-
}
|
|
35
|
-
get status() {
|
|
36
|
-
return this.lastStatus?.status ?? "UNKNOWN";
|
|
37
|
-
}
|
|
38
|
-
get subStatus() {
|
|
39
|
-
return this.lastStatus?.subStatus ?? null;
|
|
40
|
-
}
|
|
41
|
-
get retryable() {
|
|
42
|
-
return this.reason === "timeout" || this.reason === "funding-paused";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
var isDalpTransactionWaitError = (error) => error instanceof DalpTransactionWaitError;
|
|
46
|
-
var defaultSleep = (milliseconds, signal) => new Promise((resolve, reject) => {
|
|
47
|
-
if (signal?.aborted === true) {
|
|
48
|
-
reject(signal.reason);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const onAbort = () => {
|
|
52
|
-
clearTimeout(timeout);
|
|
53
|
-
reject(signal?.reason);
|
|
54
|
-
};
|
|
55
|
-
const timeout = setTimeout(() => {
|
|
56
|
-
signal?.removeEventListener("abort", onAbort);
|
|
57
|
-
resolve();
|
|
58
|
-
}, milliseconds);
|
|
59
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
60
|
-
});
|
|
61
|
-
var routeStatusReader = (client) => async (transactionId, signal) => {
|
|
62
|
-
const result = await client.execute("transaction/status", { transactionId }, signal === undefined ? undefined : { signal });
|
|
63
|
-
const body = result !== null && typeof result === "object" ? Reflect.get(result, "data") ?? result : result;
|
|
64
|
-
return body;
|
|
65
|
-
};
|
|
66
|
-
async function waitForTransaction(client, transactionId, options = {}) {
|
|
67
|
-
const timeoutMs = options.timeoutMs ?? 120000;
|
|
68
|
-
const pollIntervalMs = options.pollIntervalMs ?? 1000;
|
|
69
|
-
const now = options.now ?? Date.now;
|
|
70
|
-
const sleep = options.sleep ?? defaultSleep;
|
|
71
|
-
const readStatus = options.readStatus ?? routeStatusReader(client);
|
|
72
|
-
const holdWhilePaused = options.holdWhilePaused ?? true;
|
|
73
|
-
const waitStartedAt = now();
|
|
74
|
-
let budgetStartedAt = waitStartedAt;
|
|
75
|
-
let pollDelayMs = pollIntervalMs;
|
|
76
|
-
let lastStatus;
|
|
77
|
-
const isAborted = () => options.signal?.aborted === true;
|
|
78
|
-
while (true) {
|
|
79
|
-
if (isAborted()) {
|
|
80
|
-
throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
|
|
81
|
-
}
|
|
82
|
-
if (now() - budgetStartedAt >= timeoutMs) {
|
|
83
|
-
throw new DalpTransactionWaitError(transactionId, "timeout", lastStatus, now() - waitStartedAt);
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
lastStatus = await readStatus(transactionId, options.signal);
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (isAborted()) {
|
|
89
|
-
throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
|
|
90
|
-
}
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
options.onStatus?.(lastStatus);
|
|
94
|
-
if (failedStates.has(lastStatus.status)) {
|
|
95
|
-
throw new DalpTransactionWaitError(transactionId, "terminal-failure", lastStatus);
|
|
96
|
-
}
|
|
97
|
-
if (isWaitForTransactionSuccess(lastStatus)) {
|
|
98
|
-
return lastStatus;
|
|
99
|
-
}
|
|
100
|
-
if (readsAsFundingPaused(lastStatus)) {
|
|
101
|
-
if (!holdWhilePaused) {
|
|
102
|
-
throw new DalpTransactionWaitError(transactionId, "funding-paused", lastStatus, now() - waitStartedAt);
|
|
103
|
-
}
|
|
104
|
-
budgetStartedAt = now();
|
|
105
|
-
pollDelayMs = Math.min(pollDelayMs * 2, Math.max(pollIntervalMs, PAUSED_POLL_INTERVAL_MAX_MS));
|
|
106
|
-
} else {
|
|
107
|
-
pollDelayMs = pollIntervalMs;
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
await sleep(Math.min(pollDelayMs, Math.max(0, timeoutMs - (now() - budgetStartedAt))), options.signal);
|
|
111
|
-
} catch {
|
|
112
|
-
throw new DalpTransactionWaitError(transactionId, "aborted", lastStatus);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export {
|
|
117
|
-
DalpTransactionWaitError,
|
|
118
|
-
isDalpTransactionWaitError,
|
|
119
|
-
waitForTransaction
|
|
120
|
-
};
|