@routedock/routedock 0.2.0 → 0.3.0
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 +305 -0
- package/dist/MppSessionHandler-1EL8QBAn.d.cts +215 -0
- package/dist/MppSessionHandler-Bq4S-JTE.d.ts +215 -0
- package/dist/{ProviderRegistry-C50nyhaF.d.ts → ProviderRegistry-CA_TdREG.d.ts} +2 -2
- package/dist/{ProviderRegistry-BJ9oJLVz.d.cts → ProviderRegistry-D-0rqK0N.d.cts} +2 -2
- package/dist/{RouteDockClient-B1roCa8h.d.cts → RouteDockClient-Bh86bVly.d.ts} +23 -9
- package/dist/{RouteDockClient-BbkqjhMG.d.ts → RouteDockClient-go9aopfF.d.cts} +23 -9
- package/dist/{SessionReconciler-Dscw43F3.d.ts → SessionReconciler-Bw-PoBVl.d.ts} +14 -5
- package/dist/{SessionReconciler-bi0z2qtN.d.cts → SessionReconciler-Cz2nuOlJ.d.cts} +14 -5
- package/dist/{SessionStore-DvkZv8-E.d.ts → SessionStore-B4-Hi4H8.d.cts} +34 -2
- package/dist/{SessionStore-BpK8vv0L.d.cts → SessionStore-BaYiegP0.d.ts} +34 -2
- package/dist/client.cjs +429 -117
- package/dist/client.d.cts +9 -8
- package/dist/client.d.ts +9 -8
- package/dist/client.js +421 -119
- package/dist/index.cjs +652 -220
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +643 -221
- package/dist/{types-DmhmfLzP.d.cts → logger-D8_Q2ytp.d.cts} +58 -1
- package/dist/{types-DmhmfLzP.d.ts → logger-D8_Q2ytp.d.ts} +58 -1
- package/dist/provider/fastify.cjs +306 -89
- package/dist/provider/fastify.d.cts +9 -4
- package/dist/provider/fastify.d.ts +9 -4
- package/dist/provider/fastify.js +305 -88
- package/dist/provider/hono.cjs +286 -82
- package/dist/provider/hono.d.cts +9 -7
- package/dist/provider/hono.d.ts +9 -7
- package/dist/provider/hono.js +282 -78
- package/dist/provider.cjs +326 -98
- package/dist/provider.d.cts +14 -10
- package/dist/provider.d.ts +14 -10
- package/dist/provider.js +318 -98
- package/dist/react.cjs +407 -117
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +408 -118
- package/dist/{routedockMiddleware-BlDsHuPl.d.ts → routedockMiddleware-57gUaEMf.d.ts} +9 -4
- package/dist/{routedockMiddleware-D97A5ptQ.d.cts → routedockMiddleware-DlyLrxp7.d.cts} +9 -4
- package/dist/schema.cjs +40 -0
- package/dist/schema.js +40 -0
- package/dist/{sign-Dpj2Mp7k.d.ts → sign-AKH67sft.d.cts} +1 -1
- package/dist/{sign-CUf3rhTx.d.cts → sign-BEq-OsSq.d.ts} +1 -1
- package/dist/testing.cjs +6 -4
- package/dist/testing.d.cts +32 -13
- package/dist/testing.d.ts +32 -13
- package/dist/testing.js +6 -4
- package/package.json +2 -2
- package/dist/MppSessionHandler-B4TyD7Xg.d.cts +0 -121
- package/dist/MppSessionHandler-CLB5SzgN.d.ts +0 -121
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { g as RouteDockLogger, h as RouteDockManifest } from './logger-D8_Q2ytp.js';
|
|
2
|
+
import { RequestHandler } from 'express';
|
|
3
|
+
import { Store } from 'mppx';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Idempotency store for payment settlement.
|
|
7
|
+
*
|
|
8
|
+
* `x402Handler` and `MppChargeHandler` settle on every request carrying a
|
|
9
|
+
* payment header. An agent that retries after a post-settlement network
|
|
10
|
+
* timeout resends the *same* signed payment, which would settle a second time
|
|
11
|
+
* and invoke `onSettled` twice — double-counting in billing.
|
|
12
|
+
*
|
|
13
|
+
* Before settling, a handler derives an idempotency key from the inbound
|
|
14
|
+
* payment header(s) *together with the resource being paid for* and checks
|
|
15
|
+
* this store. On a hit it replays the cached settlement response and skips
|
|
16
|
+
* both the on-chain settle and `onSettled`. A hit older than
|
|
17
|
+
* {@link SETTLEMENT_REPLAY_WINDOW_MS}, or one replayed more than
|
|
18
|
+
* {@link MAX_SETTLEMENT_REPLAYS} times, is rejected instead of replayed so a
|
|
19
|
+
* leaked header cannot buy unlimited requests.
|
|
20
|
+
*
|
|
21
|
+
* `claimReplay` and {@link SettlementRecord.createdAt} are optional so a
|
|
22
|
+
* custom store written against the original two-method (`get`/`set`) contract
|
|
23
|
+
* keeps compiling. See {@link checkSettlementReplay} for how a store that
|
|
24
|
+
* supplies neither bounds a replay.
|
|
25
|
+
*
|
|
26
|
+
* The default {@link InMemorySeenTxStore} is per-handler and per-process. For
|
|
27
|
+
* multi-instance deployments, supply a shared implementation backed by Redis,
|
|
28
|
+
* Supabase, etc.
|
|
29
|
+
*/
|
|
30
|
+
/** The resource a settlement idempotency key is scoped to. */
|
|
31
|
+
interface SettlementScope {
|
|
32
|
+
/** HTTP method of the paid request (e.g. `GET`). */
|
|
33
|
+
method: string;
|
|
34
|
+
/** Path of the paid request, without query string (e.g. `/price`). */
|
|
35
|
+
path: string;
|
|
36
|
+
/** Charge amount as declared by the route's requirements. */
|
|
37
|
+
amount: string;
|
|
38
|
+
/** Payee address the route settles to. */
|
|
39
|
+
payTo: string;
|
|
40
|
+
}
|
|
41
|
+
/** Cached outcome of a settlement, replayed on a duplicate payment. */
|
|
42
|
+
interface SettlementRecord {
|
|
43
|
+
/** On-chain transaction hash (or settlement reference), if known. */
|
|
44
|
+
txHash: string | null;
|
|
45
|
+
/** Response headers to re-apply on a replay (e.g. `X-Payment-Response`). */
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Epoch milliseconds at which the settlement was recorded. Optional for
|
|
49
|
+
* backwards compatibility with custom stores that predate the replay bound;
|
|
50
|
+
* a record without it can only be bounded by the replay count.
|
|
51
|
+
*/
|
|
52
|
+
createdAt?: number;
|
|
53
|
+
}
|
|
54
|
+
interface SeenTxStore {
|
|
55
|
+
/** Returns the cached settlement for a key, or `undefined` if unseen. */
|
|
56
|
+
get(key: string): Promise<SettlementRecord | undefined> | SettlementRecord | undefined;
|
|
57
|
+
/** Records the settlement outcome for a key. */
|
|
58
|
+
set(key: string, record: SettlementRecord): Promise<void> | void;
|
|
59
|
+
/**
|
|
60
|
+
* Optionally, atomically record one replay of `key` and return the new
|
|
61
|
+
* replay count. Returns `Infinity` when the key is unknown (e.g. evicted
|
|
62
|
+
* between a `get` and this call), so the caller treats the payment as spent
|
|
63
|
+
* rather than replaying an unbounded number of times.
|
|
64
|
+
*
|
|
65
|
+
* Optional so a custom store written against the original two-method
|
|
66
|
+
* (`get`/`set`) contract keeps compiling. A store that omits it is still
|
|
67
|
+
* bounded by {@link SETTLEMENT_REPLAY_WINDOW_MS} when its records carry
|
|
68
|
+
* {@link SettlementRecord.createdAt}.
|
|
69
|
+
*/
|
|
70
|
+
claimReplay?(key: string): Promise<number> | number;
|
|
71
|
+
}
|
|
72
|
+
interface InMemorySeenTxStoreOptions {
|
|
73
|
+
/** Maximum number of entries before FIFO eviction. Defaults to 10,000. */
|
|
74
|
+
maxEntries?: number;
|
|
75
|
+
/** Log a startup warning about non-durability. Defaults to true. */
|
|
76
|
+
warn?: boolean;
|
|
77
|
+
/** Log sink for the non-durability warning. Defaults to a console-backed logger. */
|
|
78
|
+
logger?: RouteDockLogger;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* How long after a settlement a byte-identical retry may still replay the
|
|
82
|
+
* cached response. Matches the `maxTimeoutSeconds: 60` both x402 requirement
|
|
83
|
+
* objects declare, so past this point the payment is expired anyway.
|
|
84
|
+
*/
|
|
85
|
+
declare const SETTLEMENT_REPLAY_WINDOW_MS = 60000;
|
|
86
|
+
/**
|
|
87
|
+
* How many times one settled payment may be replayed beyond the original
|
|
88
|
+
* settlement. The SDK's own clients never resend a byte-identical header —
|
|
89
|
+
* they re-sign on every retry — so a tight limit costs nothing while stopping
|
|
90
|
+
* a leaked header from buying unlimited requests.
|
|
91
|
+
*/
|
|
92
|
+
declare const MAX_SETTLEMENT_REPLAYS = 1;
|
|
93
|
+
/** Outcome of checking whether an idempotency key may replay a settlement. */
|
|
94
|
+
type SettlementReplayCheck = {
|
|
95
|
+
kind: 'miss';
|
|
96
|
+
} | {
|
|
97
|
+
kind: 'replay';
|
|
98
|
+
record: SettlementRecord;
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'spent';
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Decide what a payment bearing `key` should do.
|
|
104
|
+
*
|
|
105
|
+
* - `miss` — no cached settlement; fall through to decode and settle.
|
|
106
|
+
* - `replay`— a fresh settlement within the replay window and under the replay
|
|
107
|
+
* limit; re-apply the recorded headers and skip settling.
|
|
108
|
+
* - `spent` — the settlement is older than the replay window, or has already
|
|
109
|
+
* been replayed the maximum number of times; respond 402 without
|
|
110
|
+
* decoding, settling, or invoking callbacks.
|
|
111
|
+
*
|
|
112
|
+
* The age check runs first so an expired record never touches the replay
|
|
113
|
+
* counter.
|
|
114
|
+
*
|
|
115
|
+
* Custom stores may predate this function and implement only `get`/`set`:
|
|
116
|
+
*
|
|
117
|
+
* - a record that carries `createdAt` but a store without `claimReplay` is
|
|
118
|
+
* bounded by {@link SETTLEMENT_REPLAY_WINDOW_MS} alone;
|
|
119
|
+
* - a record without `createdAt` offers no window to check, so a store's own
|
|
120
|
+
* `claimReplay` is the only bound available; a store that supplies neither
|
|
121
|
+
* replays as it did before this function existed.
|
|
122
|
+
*/
|
|
123
|
+
declare function checkSettlementReplay(store: SeenTxStore, key: string, now?: number): Promise<SettlementReplayCheck>;
|
|
124
|
+
/**
|
|
125
|
+
* Default in-memory {@link SeenTxStore}. Bounded by `maxEntries` with FIFO
|
|
126
|
+
* eviction so a long-running process cannot grow without limit.
|
|
127
|
+
*
|
|
128
|
+
* **Not durable.** On serverless/edge runtimes each request may land on a
|
|
129
|
+
* fresh isolate with an empty cache, which causes duplicate settlements.
|
|
130
|
+
* Supply a persistent implementation (Supabase, Redis, …) in production.
|
|
131
|
+
*/
|
|
132
|
+
declare class InMemorySeenTxStore implements SeenTxStore {
|
|
133
|
+
private readonly map;
|
|
134
|
+
private readonly replayCounts;
|
|
135
|
+
private readonly order;
|
|
136
|
+
constructor(maxEntriesOrOptions?: number | InMemorySeenTxStoreOptions);
|
|
137
|
+
private readonly maxEntries;
|
|
138
|
+
get(key: string): SettlementRecord | undefined;
|
|
139
|
+
set(key: string, record: SettlementRecord): void;
|
|
140
|
+
claimReplay(key: string): number;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Derive a collision-resistant idempotency key from the inbound
|
|
144
|
+
* payment-bearing headers, scoped to the resource being paid for. Uses
|
|
145
|
+
* SHA-256 instead of 32-bit FNV-1a (which has a 2^32 keyspace — birthday
|
|
146
|
+
* collisions become likely well before the 10_000-entry default store is
|
|
147
|
+
* full).
|
|
148
|
+
*
|
|
149
|
+
* x402 clients send the signed payment in `payment-signature` / `x-payment`;
|
|
150
|
+
* mppx clients send it in `authorization` (the `Payment` scheme). A retry
|
|
151
|
+
* resends byte-identical headers, so hashing the first present one yields a
|
|
152
|
+
* stable key.
|
|
153
|
+
*
|
|
154
|
+
* The `scope` (method, path, amount, payTo) is hashed alongside the header so
|
|
155
|
+
* a payment settled for one route can never replay against another route,
|
|
156
|
+
* even when the same store is shared across routes. Returns `null` when no
|
|
157
|
+
* payment header is present (nothing to dedupe — e.g. the initial 402
|
|
158
|
+
* challenge request).
|
|
159
|
+
*/
|
|
160
|
+
declare function paymentIdempotencyKey(getHeader: (name: string) => string | undefined, scope: SettlementScope): Promise<string | null>;
|
|
161
|
+
|
|
162
|
+
/** Store shape extended with optional atomic update operation. */
|
|
163
|
+
type ChannelStore = Store.Store & {
|
|
164
|
+
update?: (key: string, fn: (prev: unknown) => unknown) => Promise<unknown>;
|
|
165
|
+
};
|
|
166
|
+
/** Expected payload shape for voucher cumulative amount entries. */
|
|
167
|
+
interface VoucherStoreValue {
|
|
168
|
+
amount: string;
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
/** Validates that a stored store value is an object containing a numeric string amount. */
|
|
172
|
+
declare function isVoucherStoreValue(value: unknown): value is VoucherStoreValue;
|
|
173
|
+
type Network = 'testnet' | 'mainnet';
|
|
174
|
+
/** Why a live session was flagged as orphaned (never cleanly closed). */
|
|
175
|
+
type OrphanReason = 'connection-closed' | 'idle-timeout';
|
|
176
|
+
/** Latest signed state of an orphaned session, enough for the reconciler to settle. */
|
|
177
|
+
interface OrphanedSessionInfo {
|
|
178
|
+
/** Cumulative amount of the highest voucher seen (human-readable, 7 dp). */
|
|
179
|
+
cumulativeAmount: string;
|
|
180
|
+
/** Hex-encoded signature of the highest voucher seen. */
|
|
181
|
+
lastSignature: string;
|
|
182
|
+
/** Number of vouchers received before teardown. */
|
|
183
|
+
voucherCount: number;
|
|
184
|
+
/** What triggered the orphan flag. */
|
|
185
|
+
reason: OrphanReason;
|
|
186
|
+
}
|
|
187
|
+
interface MppSessionHandlerOptions {
|
|
188
|
+
payeeSecretKey: string;
|
|
189
|
+
network: Network;
|
|
190
|
+
channelFactory: string;
|
|
191
|
+
rate: string;
|
|
192
|
+
assetContract?: string;
|
|
193
|
+
manifest: RouteDockManifest;
|
|
194
|
+
commitmentPublicKey: string;
|
|
195
|
+
onSettled?: (txHash: string, totalPaid: string, mode: string, payer: string | null) => Promise<void>;
|
|
196
|
+
onSessionOpen?: (channelId: string, payer: string | null) => Promise<void>;
|
|
197
|
+
onVoucher?: (channelId: string, voucherIndex: number, cumulativeAmount: string, signature: string) => Promise<void>;
|
|
198
|
+
onCallbackError?: (err: unknown, cb: string) => void;
|
|
199
|
+
/**
|
|
200
|
+
* Called when the client connection drops mid-session or the session goes
|
|
201
|
+
* idle, before a clean close. Persist the session as `closing` so the
|
|
202
|
+
* SessionReconciler can settle it with the latest signed voucher.
|
|
203
|
+
*/
|
|
204
|
+
onOrphaned?: (channelId: string, info: OrphanedSessionInfo) => Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Flag the session orphaned after this many milliseconds with no voucher
|
|
207
|
+
* activity. Disabled when unset.
|
|
208
|
+
*/
|
|
209
|
+
idleTimeoutMs?: number;
|
|
210
|
+
/** Log sink for internal error paths. Defaults to a console-backed logger. */
|
|
211
|
+
logger?: RouteDockLogger;
|
|
212
|
+
}
|
|
213
|
+
declare function createMppSessionHandler(opts: MppSessionHandlerOptions): RequestHandler;
|
|
214
|
+
|
|
215
|
+
export { type ChannelStore as C, InMemorySeenTxStore as I, MAX_SETTLEMENT_REPLAYS as M, type OrphanedSessionInfo as O, type SeenTxStore as S, type VoucherStoreValue as V, type SettlementRecord as a, type InMemorySeenTxStoreOptions as b, type MppSessionHandlerOptions as c, type OrphanReason as d, SETTLEMENT_REPLAY_WINDOW_MS as e, type SettlementReplayCheck as f, type SettlementScope as g, checkSettlementReplay as h, createMppSessionHandler as i, isVoucherStoreValue as j, paymentIdempotencyKey as p };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usdcToStroops } from '@routedock/nulth-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { l as SpendStore, a as DailySpend, R as RetryPolicy } from './RouteDockClient-Bh86bVly.js';
|
|
3
3
|
import { ClientStellarSigner } from '@x402/stellar';
|
|
4
|
-
import {
|
|
4
|
+
import { h as RouteDockManifest, c as PaymentResult } from './logger-D8_Q2ytp.js';
|
|
5
5
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
6
6
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usdcToStroops } from '@routedock/nulth-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { l as SpendStore, a as DailySpend, R as RetryPolicy } from './RouteDockClient-go9aopfF.cjs';
|
|
3
3
|
import { ClientStellarSigner } from '@x402/stellar';
|
|
4
|
-
import {
|
|
4
|
+
import { h as RouteDockManifest, c as PaymentResult } from './logger-D8_Q2ytp.cjs';
|
|
5
5
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
6
6
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
2
|
-
import { P as PaymentMode,
|
|
2
|
+
import { g as RouteDockLogger, P as PaymentMode, h as RouteDockManifest, d as PreflightResult, c as PaymentResult, b as EstimateCostResult, n as SessionOptions, m as SessionHandle } from './logger-D8_Q2ytp.js';
|
|
3
3
|
import { ClientStellarSigner } from '@x402/stellar';
|
|
4
4
|
import { SignAuthEntry } from '@stellar/stellar-sdk/contract';
|
|
5
5
|
import { usdcToStroops } from '@routedock/nulth-sdk';
|
|
@@ -18,8 +18,13 @@ interface RetryPolicy {
|
|
|
18
18
|
* aborting the retry loop.
|
|
19
19
|
*/
|
|
20
20
|
onRetry?: (attempt: number, error: Error, nextDelayMs: number) => void | Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Log sink for internal diagnostics (an `onRetry` hook that throws).
|
|
23
|
+
* Defaults to a console-backed logger.
|
|
24
|
+
*/
|
|
25
|
+
logger?: RouteDockLogger;
|
|
21
26
|
}
|
|
22
|
-
declare const DEFAULT_RETRY_POLICY: Required<Omit<RetryPolicy, 'onRetry'>>;
|
|
27
|
+
declare const DEFAULT_RETRY_POLICY: Required<Omit<RetryPolicy, 'onRetry' | 'logger'>>;
|
|
23
28
|
/**
|
|
24
29
|
* Full jitter exponential backoff delay.
|
|
25
30
|
* Delay range: 0..min(maxDelayMs, baseDelayMs * 2 ** attempt).
|
|
@@ -42,7 +47,10 @@ declare function withRetry<T>(fn: () => Promise<T>, policy?: RetryPolicy): Promi
|
|
|
42
47
|
declare function assertEndpointActive(manifest: RouteDockManifest, url: string, logger?: RouteDockLogger): void;
|
|
43
48
|
/**
|
|
44
49
|
* Validate semantic constraints for manifest fields beyond JSON schema syntax.
|
|
45
|
-
* Enforces
|
|
50
|
+
* Enforces:
|
|
51
|
+
* - All keys in `latency_hints` must be a subset of declared `regions`.
|
|
52
|
+
* - If `assets` is defined, it must be a non-empty array whose first entry
|
|
53
|
+
* (`assets[0]`) matches the root-level `asset` and `asset_contract`.
|
|
46
54
|
*/
|
|
47
55
|
declare function assertManifestValid(manifest: RouteDockManifest, baseUrl?: string): void;
|
|
48
56
|
/**
|
|
@@ -62,7 +70,7 @@ declare function configureManifestCache(maxSize: number): void;
|
|
|
62
70
|
* to the origin before calling this.
|
|
63
71
|
*/
|
|
64
72
|
declare function invalidateManifest(baseUrl: string): void;
|
|
65
|
-
|
|
73
|
+
|
|
66
74
|
interface ModeSelectOptions {
|
|
67
75
|
/** Force mpp-session if the provider supports it */
|
|
68
76
|
sustained?: boolean;
|
|
@@ -153,6 +161,8 @@ interface NulthClientConfig {
|
|
|
153
161
|
prover?: 'mock';
|
|
154
162
|
policy: NulthPolicyState;
|
|
155
163
|
verifierContract?: string;
|
|
164
|
+
/** Log sink for the mock-prover warning. Defaults to a console-backed logger. */
|
|
165
|
+
logger?: RouteDockLogger;
|
|
156
166
|
}
|
|
157
167
|
declare class NulthPolicyError extends Error {
|
|
158
168
|
readonly code: 'payee_not_allowed' | 'daily_cap_exceeded' | 'session_expired' | 'auth_entry_mismatch';
|
|
@@ -235,6 +245,8 @@ interface SpendStore {
|
|
|
235
245
|
interface InMemorySpendStoreOptions {
|
|
236
246
|
/** Log a startup warning about non-durability. Defaults to true. */
|
|
237
247
|
warn?: boolean;
|
|
248
|
+
/** Log sink for the non-durability warning. Defaults to a console-backed logger. */
|
|
249
|
+
logger?: RouteDockLogger;
|
|
238
250
|
}
|
|
239
251
|
/**
|
|
240
252
|
* Default, non-durable {@link SpendStore}. Holds the accumulator on the heap, so
|
|
@@ -274,7 +286,7 @@ interface RouteDockClientConfig {
|
|
|
274
286
|
/** Stellar keypair or raw secret key (S...) — fee payer / fallback signer */
|
|
275
287
|
wallet: Keypair | string;
|
|
276
288
|
network: 'testnet' | 'mainnet';
|
|
277
|
-
/** Optional local daily spend cap — checked before every payment
|
|
289
|
+
/** Optional local daily spend cap — checked before every payment, nulth vault payments included */
|
|
278
290
|
spendCap?: SpendCap;
|
|
279
291
|
/**
|
|
280
292
|
* Ed25519 secret key (S...) for signing channel commitments. Required for mpp-session.
|
|
@@ -367,7 +379,7 @@ declare class RouteDockClient {
|
|
|
367
379
|
* call before committing to a payment — for approval gates and manual
|
|
368
380
|
* trustline remediation.
|
|
369
381
|
*/
|
|
370
|
-
preflight(manifest: RouteDockManifest): Promise<PreflightResult>;
|
|
382
|
+
preflight(manifest: RouteDockManifest, mode?: PaymentMode, endpoint?: string): Promise<PreflightResult>;
|
|
371
383
|
/**
|
|
372
384
|
* Verify via Horizon that the payer account has a trustline for the
|
|
373
385
|
* payment asset declared in the manifest. Throws RouteDockTrustlineError
|
|
@@ -380,8 +392,10 @@ declare class RouteDockClient {
|
|
|
380
392
|
* Pay for one request at `url`. Fetches manifest, selects payment mode,
|
|
381
393
|
* runs trustline preflight, reserves local spend cap BEFORE executing the
|
|
382
394
|
* payment, then commits the spend record on success. Rolls back the
|
|
383
|
-
* reservation if the on-chain payment fails
|
|
384
|
-
*
|
|
395
|
+
* reservation if the on-chain payment fails, and also when the call
|
|
396
|
+
* completes without paying anything (an x402 endpoint answering a plain
|
|
397
|
+
* 200 with no challenge). Concurrent pay() calls are serialized through a
|
|
398
|
+
* per-instance mutex to prevent spend-cap overrun.
|
|
385
399
|
*/
|
|
386
400
|
pay(url: string, options?: ModeSelectOptions): Promise<PaymentResult>;
|
|
387
401
|
/** Nulth ZK vault path — proof built off-chain, attached as auth signature */
|
|
@@ -452,4 +466,4 @@ declare class RouteDockClient {
|
|
|
452
466
|
private _rollbackSpend;
|
|
453
467
|
}
|
|
454
468
|
|
|
455
|
-
export {
|
|
469
|
+
export { selectMode as A, setNulthPaymentContext as B, usdcToMicros as C, DEFAULT_RETRY_POLICY as D, withRetry as E, InMemorySpendStore as I, type ModeSelectOptions as M, type NulthAuthSignature as N, type PaymentAuthContext as P, type RetryPolicy as R, type SpendCap as S, type VaultConfig as V, type DailySpend as a, type InMemorySpendStoreOptions as b, type NulthClientConfig as c, NulthPolicyError as d, type NulthPolicyState as e, type NulthProof as f, type NulthSignerConfig as g, type NulthStellarSigner as h, type NulthVaultConfig as i, RouteDockClient as j, type RouteDockClientConfig as k, type SpendStore as l, assertEndpointActive as m, assertManifestValid as n, assertNulthVaultManifest as o, backoffDelayMs as p, configureManifestCache as q, createNulthSigner as r, createPolicyState as s, decodeAuthSignature as t, fetchLedgerSequence as u, fetchManifest as v, invalidateManifest as w, paymentContextFromManifest as x, prepareNulthSigner as y, rankProvidersByLatency as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
2
|
-
import { P as PaymentMode,
|
|
2
|
+
import { g as RouteDockLogger, P as PaymentMode, h as RouteDockManifest, d as PreflightResult, c as PaymentResult, b as EstimateCostResult, n as SessionOptions, m as SessionHandle } from './logger-D8_Q2ytp.cjs';
|
|
3
3
|
import { ClientStellarSigner } from '@x402/stellar';
|
|
4
4
|
import { SignAuthEntry } from '@stellar/stellar-sdk/contract';
|
|
5
5
|
import { usdcToStroops } from '@routedock/nulth-sdk';
|
|
@@ -18,8 +18,13 @@ interface RetryPolicy {
|
|
|
18
18
|
* aborting the retry loop.
|
|
19
19
|
*/
|
|
20
20
|
onRetry?: (attempt: number, error: Error, nextDelayMs: number) => void | Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Log sink for internal diagnostics (an `onRetry` hook that throws).
|
|
23
|
+
* Defaults to a console-backed logger.
|
|
24
|
+
*/
|
|
25
|
+
logger?: RouteDockLogger;
|
|
21
26
|
}
|
|
22
|
-
declare const DEFAULT_RETRY_POLICY: Required<Omit<RetryPolicy, 'onRetry'>>;
|
|
27
|
+
declare const DEFAULT_RETRY_POLICY: Required<Omit<RetryPolicy, 'onRetry' | 'logger'>>;
|
|
23
28
|
/**
|
|
24
29
|
* Full jitter exponential backoff delay.
|
|
25
30
|
* Delay range: 0..min(maxDelayMs, baseDelayMs * 2 ** attempt).
|
|
@@ -42,7 +47,10 @@ declare function withRetry<T>(fn: () => Promise<T>, policy?: RetryPolicy): Promi
|
|
|
42
47
|
declare function assertEndpointActive(manifest: RouteDockManifest, url: string, logger?: RouteDockLogger): void;
|
|
43
48
|
/**
|
|
44
49
|
* Validate semantic constraints for manifest fields beyond JSON schema syntax.
|
|
45
|
-
* Enforces
|
|
50
|
+
* Enforces:
|
|
51
|
+
* - All keys in `latency_hints` must be a subset of declared `regions`.
|
|
52
|
+
* - If `assets` is defined, it must be a non-empty array whose first entry
|
|
53
|
+
* (`assets[0]`) matches the root-level `asset` and `asset_contract`.
|
|
46
54
|
*/
|
|
47
55
|
declare function assertManifestValid(manifest: RouteDockManifest, baseUrl?: string): void;
|
|
48
56
|
/**
|
|
@@ -62,7 +70,7 @@ declare function configureManifestCache(maxSize: number): void;
|
|
|
62
70
|
* to the origin before calling this.
|
|
63
71
|
*/
|
|
64
72
|
declare function invalidateManifest(baseUrl: string): void;
|
|
65
|
-
|
|
73
|
+
|
|
66
74
|
interface ModeSelectOptions {
|
|
67
75
|
/** Force mpp-session if the provider supports it */
|
|
68
76
|
sustained?: boolean;
|
|
@@ -153,6 +161,8 @@ interface NulthClientConfig {
|
|
|
153
161
|
prover?: 'mock';
|
|
154
162
|
policy: NulthPolicyState;
|
|
155
163
|
verifierContract?: string;
|
|
164
|
+
/** Log sink for the mock-prover warning. Defaults to a console-backed logger. */
|
|
165
|
+
logger?: RouteDockLogger;
|
|
156
166
|
}
|
|
157
167
|
declare class NulthPolicyError extends Error {
|
|
158
168
|
readonly code: 'payee_not_allowed' | 'daily_cap_exceeded' | 'session_expired' | 'auth_entry_mismatch';
|
|
@@ -235,6 +245,8 @@ interface SpendStore {
|
|
|
235
245
|
interface InMemorySpendStoreOptions {
|
|
236
246
|
/** Log a startup warning about non-durability. Defaults to true. */
|
|
237
247
|
warn?: boolean;
|
|
248
|
+
/** Log sink for the non-durability warning. Defaults to a console-backed logger. */
|
|
249
|
+
logger?: RouteDockLogger;
|
|
238
250
|
}
|
|
239
251
|
/**
|
|
240
252
|
* Default, non-durable {@link SpendStore}. Holds the accumulator on the heap, so
|
|
@@ -274,7 +286,7 @@ interface RouteDockClientConfig {
|
|
|
274
286
|
/** Stellar keypair or raw secret key (S...) — fee payer / fallback signer */
|
|
275
287
|
wallet: Keypair | string;
|
|
276
288
|
network: 'testnet' | 'mainnet';
|
|
277
|
-
/** Optional local daily spend cap — checked before every payment
|
|
289
|
+
/** Optional local daily spend cap — checked before every payment, nulth vault payments included */
|
|
278
290
|
spendCap?: SpendCap;
|
|
279
291
|
/**
|
|
280
292
|
* Ed25519 secret key (S...) for signing channel commitments. Required for mpp-session.
|
|
@@ -367,7 +379,7 @@ declare class RouteDockClient {
|
|
|
367
379
|
* call before committing to a payment — for approval gates and manual
|
|
368
380
|
* trustline remediation.
|
|
369
381
|
*/
|
|
370
|
-
preflight(manifest: RouteDockManifest): Promise<PreflightResult>;
|
|
382
|
+
preflight(manifest: RouteDockManifest, mode?: PaymentMode, endpoint?: string): Promise<PreflightResult>;
|
|
371
383
|
/**
|
|
372
384
|
* Verify via Horizon that the payer account has a trustline for the
|
|
373
385
|
* payment asset declared in the manifest. Throws RouteDockTrustlineError
|
|
@@ -380,8 +392,10 @@ declare class RouteDockClient {
|
|
|
380
392
|
* Pay for one request at `url`. Fetches manifest, selects payment mode,
|
|
381
393
|
* runs trustline preflight, reserves local spend cap BEFORE executing the
|
|
382
394
|
* payment, then commits the spend record on success. Rolls back the
|
|
383
|
-
* reservation if the on-chain payment fails
|
|
384
|
-
*
|
|
395
|
+
* reservation if the on-chain payment fails, and also when the call
|
|
396
|
+
* completes without paying anything (an x402 endpoint answering a plain
|
|
397
|
+
* 200 with no challenge). Concurrent pay() calls are serialized through a
|
|
398
|
+
* per-instance mutex to prevent spend-cap overrun.
|
|
385
399
|
*/
|
|
386
400
|
pay(url: string, options?: ModeSelectOptions): Promise<PaymentResult>;
|
|
387
401
|
/** Nulth ZK vault path — proof built off-chain, attached as auth signature */
|
|
@@ -452,4 +466,4 @@ declare class RouteDockClient {
|
|
|
452
466
|
private _rollbackSpend;
|
|
453
467
|
}
|
|
454
468
|
|
|
455
|
-
export {
|
|
469
|
+
export { selectMode as A, setNulthPaymentContext as B, usdcToMicros as C, DEFAULT_RETRY_POLICY as D, withRetry as E, InMemorySpendStore as I, type ModeSelectOptions as M, type NulthAuthSignature as N, type PaymentAuthContext as P, type RetryPolicy as R, type SpendCap as S, type VaultConfig as V, type DailySpend as a, type InMemorySpendStoreOptions as b, type NulthClientConfig as c, NulthPolicyError as d, type NulthPolicyState as e, type NulthProof as f, type NulthSignerConfig as g, type NulthStellarSigner as h, type NulthVaultConfig as i, RouteDockClient as j, type RouteDockClientConfig as k, type SpendStore as l, assertEndpointActive as m, assertManifestValid as n, assertNulthVaultManifest as o, backoffDelayMs as p, configureManifestCache as q, createNulthSigner as r, createPolicyState as s, decodeAuthSignature as t, fetchLedgerSequence as u, fetchManifest as v, invalidateManifest as w, paymentContextFromManifest as x, prepareNulthSigner as y, rankProvidersByLatency as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { S as SeenTxStore, a as SettlementRecord } from './MppSessionHandler-
|
|
3
|
-
import {
|
|
2
|
+
import { S as SeenTxStore, a as SettlementRecord } from './MppSessionHandler-Bq4S-JTE.js';
|
|
3
|
+
import { h as RouteDockManifest, g as RouteDockLogger } from './logger-D8_Q2ytp.js';
|
|
4
4
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -16,7 +16,9 @@ import { Keypair } from '@stellar/stellar-sdk';
|
|
|
16
16
|
* would not, since a retry can outrun propagation and reintroduce the double
|
|
17
17
|
* settle.
|
|
18
18
|
*
|
|
19
|
-
* Requires the `settlements` table from migration `003_settlement_idempotency
|
|
19
|
+
* Requires the `settlements` table from migration `003_settlement_idempotency`
|
|
20
|
+
* and the `claim_settlement_replay` function from migration
|
|
21
|
+
* `006_settlement_replay_limit`:
|
|
20
22
|
*
|
|
21
23
|
* ```sql
|
|
22
24
|
* CREATE TABLE settlements (
|
|
@@ -29,7 +31,7 @@ import { Keypair } from '@stellar/stellar-sdk';
|
|
|
29
31
|
*
|
|
30
32
|
* @example
|
|
31
33
|
* ```ts
|
|
32
|
-
* import { SupabaseSeenTxStore } from '@routedock/routedock/
|
|
34
|
+
* import { SupabaseSeenTxStore } from '@routedock/routedock/provider/hono'
|
|
33
35
|
* import { createClient } from '@supabase/supabase-js'
|
|
34
36
|
*
|
|
35
37
|
* const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_SERVICE_KEY!)
|
|
@@ -43,6 +45,13 @@ declare class SupabaseSeenTxStore implements SeenTxStore {
|
|
|
43
45
|
constructor(supabase: SupabaseClient);
|
|
44
46
|
get(key: string): Promise<SettlementRecord | undefined>;
|
|
45
47
|
set(key: string, record: SettlementRecord): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Atomically increment the settlement's replay counter through the
|
|
50
|
+
* `claim_settlement_replay` Postgres function (migration 006). The UPDATE's
|
|
51
|
+
* row lock gives concurrent claims distinct counts. Returns `Infinity` when
|
|
52
|
+
* the key no longer exists, so the caller treats it as spent.
|
|
53
|
+
*/
|
|
54
|
+
claimReplay(key: string): Promise<number>;
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
interface RegisterProviderOptions {
|
|
@@ -120,6 +129,6 @@ declare function reconcileAbandonedSessions(opts: SessionReconcilerOptions): Pro
|
|
|
120
129
|
* Run reconciliation on provider startup.
|
|
121
130
|
* Logs results and recovers orphaned sessions before accepting new connections.
|
|
122
131
|
*/
|
|
123
|
-
declare function runStartupReconciliation(opts: SessionReconcilerOptions, logger?:
|
|
132
|
+
declare function runStartupReconciliation(opts: SessionReconcilerOptions, logger?: RouteDockLogger): Promise<void>;
|
|
124
133
|
|
|
125
134
|
export { type ReconciliationStats as R, type SessionReconcilerOptions as S, type RegisterProviderOptions as a, SupabaseSeenTxStore as b, registerProvider as c, decimalToStroops as d, runStartupReconciliation as e, reconcileAbandonedSessions as r };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { S as SeenTxStore, a as SettlementRecord } from './MppSessionHandler-
|
|
3
|
-
import {
|
|
2
|
+
import { S as SeenTxStore, a as SettlementRecord } from './MppSessionHandler-1EL8QBAn.cjs';
|
|
3
|
+
import { h as RouteDockManifest, g as RouteDockLogger } from './logger-D8_Q2ytp.cjs';
|
|
4
4
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -16,7 +16,9 @@ import { Keypair } from '@stellar/stellar-sdk';
|
|
|
16
16
|
* would not, since a retry can outrun propagation and reintroduce the double
|
|
17
17
|
* settle.
|
|
18
18
|
*
|
|
19
|
-
* Requires the `settlements` table from migration `003_settlement_idempotency
|
|
19
|
+
* Requires the `settlements` table from migration `003_settlement_idempotency`
|
|
20
|
+
* and the `claim_settlement_replay` function from migration
|
|
21
|
+
* `006_settlement_replay_limit`:
|
|
20
22
|
*
|
|
21
23
|
* ```sql
|
|
22
24
|
* CREATE TABLE settlements (
|
|
@@ -29,7 +31,7 @@ import { Keypair } from '@stellar/stellar-sdk';
|
|
|
29
31
|
*
|
|
30
32
|
* @example
|
|
31
33
|
* ```ts
|
|
32
|
-
* import { SupabaseSeenTxStore } from '@routedock/routedock/
|
|
34
|
+
* import { SupabaseSeenTxStore } from '@routedock/routedock/provider/hono'
|
|
33
35
|
* import { createClient } from '@supabase/supabase-js'
|
|
34
36
|
*
|
|
35
37
|
* const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_SERVICE_KEY!)
|
|
@@ -43,6 +45,13 @@ declare class SupabaseSeenTxStore implements SeenTxStore {
|
|
|
43
45
|
constructor(supabase: SupabaseClient);
|
|
44
46
|
get(key: string): Promise<SettlementRecord | undefined>;
|
|
45
47
|
set(key: string, record: SettlementRecord): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Atomically increment the settlement's replay counter through the
|
|
50
|
+
* `claim_settlement_replay` Postgres function (migration 006). The UPDATE's
|
|
51
|
+
* row lock gives concurrent claims distinct counts. Returns `Infinity` when
|
|
52
|
+
* the key no longer exists, so the caller treats it as spent.
|
|
53
|
+
*/
|
|
54
|
+
claimReplay(key: string): Promise<number>;
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
interface RegisterProviderOptions {
|
|
@@ -120,6 +129,6 @@ declare function reconcileAbandonedSessions(opts: SessionReconcilerOptions): Pro
|
|
|
120
129
|
* Run reconciliation on provider startup.
|
|
121
130
|
* Logs results and recovers orphaned sessions before accepting new connections.
|
|
122
131
|
*/
|
|
123
|
-
declare function runStartupReconciliation(opts: SessionReconcilerOptions, logger?:
|
|
132
|
+
declare function runStartupReconciliation(opts: SessionReconcilerOptions, logger?: RouteDockLogger): Promise<void>;
|
|
124
133
|
|
|
125
134
|
export { type ReconciliationStats as R, type SessionReconcilerOptions as S, type RegisterProviderOptions as a, SupabaseSeenTxStore as b, registerProvider as c, decimalToStroops as d, runStartupReconciliation as e, reconcileAbandonedSessions as r };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { h as RouteDockManifest, P as PaymentMode, A as AssetConfig, p as SessionState } from './logger-D8_Q2ytp.cjs';
|
|
1
2
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { m as SessionState } from './types-DmhmfLzP.js';
|
|
3
3
|
|
|
4
4
|
/** Stable error codes for programmatic handling. */
|
|
5
5
|
type RouteDockErrorCode = 'MANIFEST' | 'MANIFEST_TIMEOUT' | 'MANIFEST_SUNSET' | 'NO_SUPPORTED_MODE' | 'FACILITATOR' | 'NETWORK' | 'SIGNATURE' | 'VOUCHER_MONOTONICITY' | 'POLICY_REJECT' | 'CHANNEL_STATE' | 'DISPUTE' | 'REFUND_WINDOW' | 'CLIENT_VERSION_TOO_OLD' | 'TRUSTLINE';
|
|
@@ -90,6 +90,38 @@ declare function parseRetryAfterMs(response: Response): number | undefined;
|
|
|
90
90
|
declare function httpStatusToError(message: string, status: number, response?: Response): RouteDockError;
|
|
91
91
|
/** Wrap a low-level fetch failure; preserves existing RouteDockErrors. */
|
|
92
92
|
declare function wrapFetchError(err: unknown, context: string): RouteDockError;
|
|
93
|
+
/**
|
|
94
|
+
* Wrap an mppx failure; differentiates network transport errors from signing/credential errors.
|
|
95
|
+
* Real transport failures (fetch TypeError, AbortError, TimeoutError) are wrapped as retryable
|
|
96
|
+
* RouteDockNetworkError, while signing and challenge failures are wrapped as non-retryable
|
|
97
|
+
* RouteDockSignatureError.
|
|
98
|
+
*/
|
|
99
|
+
declare function wrapMppError(err: unknown, context: string): RouteDockError;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Normalizes a manifest to always have an assets array.
|
|
103
|
+
* Handles backward compatibility with root asset/asset_contract fields.
|
|
104
|
+
*/
|
|
105
|
+
declare function normalizeManifestAssets(manifest: RouteDockManifest): AssetConfig[];
|
|
106
|
+
/**
|
|
107
|
+
* Finds eligible assets for a given mode and optional endpoint.
|
|
108
|
+
* Returns all assets that match the criteria.
|
|
109
|
+
*/
|
|
110
|
+
declare function getEligibleAssets(manifest: RouteDockManifest, mode: PaymentMode, endpoint?: string): AssetConfig[];
|
|
111
|
+
/**
|
|
112
|
+
* Resolves the asset contract for a mode and optional endpoint.
|
|
113
|
+
* Honors manifest.assets when defined; falls back to explicitContract or root asset_contract.
|
|
114
|
+
*/
|
|
115
|
+
declare function resolveAssetContract(manifest: RouteDockManifest, mode: PaymentMode, endpoint?: string, explicitContract?: string): string;
|
|
116
|
+
/**
|
|
117
|
+
* Selects a single asset for payment, given a mode and optional endpoint.
|
|
118
|
+
* Returns the first eligible asset, or throws if none are available.
|
|
119
|
+
*/
|
|
120
|
+
declare function selectAsset(manifest: RouteDockManifest, mode: PaymentMode, endpoint?: string): AssetConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a specific asset (by ticker or contract address) is eligible for a mode/endpoint.
|
|
123
|
+
*/
|
|
124
|
+
declare function isAssetEligible(manifest: RouteDockManifest, assetIdentifier: string, mode: PaymentMode, endpoint?: string): boolean;
|
|
93
125
|
|
|
94
126
|
interface SessionStore {
|
|
95
127
|
get(channelId: string): Promise<SessionState | null>;
|
|
@@ -108,4 +140,4 @@ declare class SupabaseSessionStore implements SessionStore {
|
|
|
108
140
|
close(channelId: string): Promise<void>;
|
|
109
141
|
}
|
|
110
142
|
|
|
111
|
-
export { RouteDockChannelStateError as R, type SessionStore as S, RouteDockClientVersionError as a, RouteDockDisputeError as b, RouteDockError as c, type RouteDockErrorCode as d, type RouteDockErrorOptions as e, RouteDockFacilitatorError as f, RouteDockManifestError as g, RouteDockManifestSunsetError as h, RouteDockManifestTimeoutError as i, RouteDockNetworkError as j, RouteDockNoSupportedModeError as k, RouteDockPolicyRejectError as l, RouteDockPolicyRejectedError as m, RouteDockRefundWindowError as n, RouteDockSessionError as o, RouteDockSignatureError as p, RouteDockTrustlineError as q, RouteDockVoucherMonotonicityError as r, SupabaseSessionStore as s,
|
|
143
|
+
export { wrapFetchError as A, wrapMppError as B, RouteDockChannelStateError as R, type SessionStore as S, RouteDockClientVersionError as a, RouteDockDisputeError as b, RouteDockError as c, type RouteDockErrorCode as d, type RouteDockErrorOptions as e, RouteDockFacilitatorError as f, RouteDockManifestError as g, RouteDockManifestSunsetError as h, RouteDockManifestTimeoutError as i, RouteDockNetworkError as j, RouteDockNoSupportedModeError as k, RouteDockPolicyRejectError as l, RouteDockPolicyRejectedError as m, RouteDockRefundWindowError as n, RouteDockSessionError as o, RouteDockSignatureError as p, RouteDockTrustlineError as q, RouteDockVoucherMonotonicityError as r, SupabaseSessionStore as s, getEligibleAssets as t, httpStatusToError as u, isAssetEligible as v, normalizeManifestAssets as w, parseRetryAfterMs as x, resolveAssetContract as y, selectAsset as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { h as RouteDockManifest, P as PaymentMode, A as AssetConfig, p as SessionState } from './logger-D8_Q2ytp.js';
|
|
1
2
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { m as SessionState } from './types-DmhmfLzP.cjs';
|
|
3
3
|
|
|
4
4
|
/** Stable error codes for programmatic handling. */
|
|
5
5
|
type RouteDockErrorCode = 'MANIFEST' | 'MANIFEST_TIMEOUT' | 'MANIFEST_SUNSET' | 'NO_SUPPORTED_MODE' | 'FACILITATOR' | 'NETWORK' | 'SIGNATURE' | 'VOUCHER_MONOTONICITY' | 'POLICY_REJECT' | 'CHANNEL_STATE' | 'DISPUTE' | 'REFUND_WINDOW' | 'CLIENT_VERSION_TOO_OLD' | 'TRUSTLINE';
|
|
@@ -90,6 +90,38 @@ declare function parseRetryAfterMs(response: Response): number | undefined;
|
|
|
90
90
|
declare function httpStatusToError(message: string, status: number, response?: Response): RouteDockError;
|
|
91
91
|
/** Wrap a low-level fetch failure; preserves existing RouteDockErrors. */
|
|
92
92
|
declare function wrapFetchError(err: unknown, context: string): RouteDockError;
|
|
93
|
+
/**
|
|
94
|
+
* Wrap an mppx failure; differentiates network transport errors from signing/credential errors.
|
|
95
|
+
* Real transport failures (fetch TypeError, AbortError, TimeoutError) are wrapped as retryable
|
|
96
|
+
* RouteDockNetworkError, while signing and challenge failures are wrapped as non-retryable
|
|
97
|
+
* RouteDockSignatureError.
|
|
98
|
+
*/
|
|
99
|
+
declare function wrapMppError(err: unknown, context: string): RouteDockError;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Normalizes a manifest to always have an assets array.
|
|
103
|
+
* Handles backward compatibility with root asset/asset_contract fields.
|
|
104
|
+
*/
|
|
105
|
+
declare function normalizeManifestAssets(manifest: RouteDockManifest): AssetConfig[];
|
|
106
|
+
/**
|
|
107
|
+
* Finds eligible assets for a given mode and optional endpoint.
|
|
108
|
+
* Returns all assets that match the criteria.
|
|
109
|
+
*/
|
|
110
|
+
declare function getEligibleAssets(manifest: RouteDockManifest, mode: PaymentMode, endpoint?: string): AssetConfig[];
|
|
111
|
+
/**
|
|
112
|
+
* Resolves the asset contract for a mode and optional endpoint.
|
|
113
|
+
* Honors manifest.assets when defined; falls back to explicitContract or root asset_contract.
|
|
114
|
+
*/
|
|
115
|
+
declare function resolveAssetContract(manifest: RouteDockManifest, mode: PaymentMode, endpoint?: string, explicitContract?: string): string;
|
|
116
|
+
/**
|
|
117
|
+
* Selects a single asset for payment, given a mode and optional endpoint.
|
|
118
|
+
* Returns the first eligible asset, or throws if none are available.
|
|
119
|
+
*/
|
|
120
|
+
declare function selectAsset(manifest: RouteDockManifest, mode: PaymentMode, endpoint?: string): AssetConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a specific asset (by ticker or contract address) is eligible for a mode/endpoint.
|
|
123
|
+
*/
|
|
124
|
+
declare function isAssetEligible(manifest: RouteDockManifest, assetIdentifier: string, mode: PaymentMode, endpoint?: string): boolean;
|
|
93
125
|
|
|
94
126
|
interface SessionStore {
|
|
95
127
|
get(channelId: string): Promise<SessionState | null>;
|
|
@@ -108,4 +140,4 @@ declare class SupabaseSessionStore implements SessionStore {
|
|
|
108
140
|
close(channelId: string): Promise<void>;
|
|
109
141
|
}
|
|
110
142
|
|
|
111
|
-
export { RouteDockChannelStateError as R, type SessionStore as S, RouteDockClientVersionError as a, RouteDockDisputeError as b, RouteDockError as c, type RouteDockErrorCode as d, type RouteDockErrorOptions as e, RouteDockFacilitatorError as f, RouteDockManifestError as g, RouteDockManifestSunsetError as h, RouteDockManifestTimeoutError as i, RouteDockNetworkError as j, RouteDockNoSupportedModeError as k, RouteDockPolicyRejectError as l, RouteDockPolicyRejectedError as m, RouteDockRefundWindowError as n, RouteDockSessionError as o, RouteDockSignatureError as p, RouteDockTrustlineError as q, RouteDockVoucherMonotonicityError as r, SupabaseSessionStore as s,
|
|
143
|
+
export { wrapFetchError as A, wrapMppError as B, RouteDockChannelStateError as R, type SessionStore as S, RouteDockClientVersionError as a, RouteDockDisputeError as b, RouteDockError as c, type RouteDockErrorCode as d, type RouteDockErrorOptions as e, RouteDockFacilitatorError as f, RouteDockManifestError as g, RouteDockManifestSunsetError as h, RouteDockManifestTimeoutError as i, RouteDockNetworkError as j, RouteDockNoSupportedModeError as k, RouteDockPolicyRejectError as l, RouteDockPolicyRejectedError as m, RouteDockRefundWindowError as n, RouteDockSessionError as o, RouteDockSignatureError as p, RouteDockTrustlineError as q, RouteDockVoucherMonotonicityError as r, SupabaseSessionStore as s, getEligibleAssets as t, httpStatusToError as u, isAssetEligible as v, normalizeManifestAssets as w, parseRetryAfterMs as x, resolveAssetContract as y, selectAsset as z };
|