@routedock/routedock 0.2.0 → 0.3.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/README.md +305 -0
- package/dist/MppSessionHandler-1EL8QBAn.d.cts +215 -0
- package/dist/MppSessionHandler-Bq4S-JTE.d.ts +215 -0
- package/dist/{ProviderRegistry-BJ9oJLVz.d.cts → ProviderRegistry-CyZ5eryO.d.cts} +2 -2
- package/dist/{ProviderRegistry-C50nyhaF.d.ts → ProviderRegistry-w4_hkI_1.d.ts} +2 -2
- package/dist/{RouteDockClient-BbkqjhMG.d.ts → RouteDockClient-CXvWXix5.d.cts} +25 -9
- package/dist/{RouteDockClient-B1roCa8h.d.cts → RouteDockClient-CjM2VyOd.d.ts} +25 -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 +432 -125
- package/dist/client.d.cts +9 -8
- package/dist/client.d.ts +9 -8
- package/dist/client.js +424 -127
- package/dist/index.cjs +655 -228
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +646 -229
- 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 +410 -125
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +411 -126
- 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
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { RequestHandler } from 'express';
|
|
2
|
-
import { Store } from 'mppx';
|
|
3
|
-
import { R as RouteDockManifest } from './types-DmhmfLzP.js';
|
|
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) and checks this store. On a hit it replays the cached
|
|
15
|
-
* settlement response and skips both the on-chain settle and `onSettled`.
|
|
16
|
-
*
|
|
17
|
-
* The default {@link InMemorySeenTxStore} is per-handler and per-process. For
|
|
18
|
-
* multi-instance deployments, supply a shared implementation backed by Redis,
|
|
19
|
-
* Supabase, etc.
|
|
20
|
-
*/
|
|
21
|
-
/** Cached outcome of a settlement, replayed on a duplicate payment. */
|
|
22
|
-
interface SettlementRecord {
|
|
23
|
-
/** On-chain transaction hash (or settlement reference), if known. */
|
|
24
|
-
txHash: string | null;
|
|
25
|
-
/** Response headers to re-apply on a replay (e.g. `X-Payment-Response`). */
|
|
26
|
-
headers?: Record<string, string>;
|
|
27
|
-
}
|
|
28
|
-
interface SeenTxStore {
|
|
29
|
-
/** Returns the cached settlement for a key, or `undefined` if unseen. */
|
|
30
|
-
get(key: string): Promise<SettlementRecord | undefined> | SettlementRecord | undefined;
|
|
31
|
-
/** Records the settlement outcome for a key. */
|
|
32
|
-
set(key: string, record: SettlementRecord): Promise<void> | void;
|
|
33
|
-
}
|
|
34
|
-
interface InMemorySeenTxStoreOptions {
|
|
35
|
-
/** Maximum number of entries before FIFO eviction. Defaults to 10,000. */
|
|
36
|
-
maxEntries?: number;
|
|
37
|
-
/** Log a startup warning about non-durability. Defaults to true. */
|
|
38
|
-
warn?: boolean;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Default in-memory {@link SeenTxStore}. Bounded by `maxEntries` with FIFO
|
|
42
|
-
* eviction so a long-running process cannot grow without limit.
|
|
43
|
-
*
|
|
44
|
-
* **Not durable.** On serverless/edge runtimes each request may land on a
|
|
45
|
-
* fresh isolate with an empty cache, which causes duplicate settlements.
|
|
46
|
-
* Supply a persistent implementation (Supabase, Redis, …) in production.
|
|
47
|
-
*/
|
|
48
|
-
declare class InMemorySeenTxStore implements SeenTxStore {
|
|
49
|
-
private readonly map;
|
|
50
|
-
private readonly order;
|
|
51
|
-
constructor(maxEntriesOrOptions?: number | InMemorySeenTxStoreOptions);
|
|
52
|
-
private readonly maxEntries;
|
|
53
|
-
get(key: string): SettlementRecord | undefined;
|
|
54
|
-
set(key: string, record: SettlementRecord): void;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Derive a collision-resistant idempotency key from the inbound
|
|
58
|
-
* payment-bearing headers. Uses SHA-256 instead of 32-bit FNV-1a
|
|
59
|
-
* (which has a 2^32 keyspace — birthday collisions become likely
|
|
60
|
-
* well before the 10_000-entry default store is full).
|
|
61
|
-
*
|
|
62
|
-
* x402 clients send the signed payment in `payment-signature` / `x-payment`;
|
|
63
|
-
* mppx clients send it in `authorization` (the `Payment` scheme). A retry
|
|
64
|
-
* resends byte-identical headers, so hashing the first present one yields a
|
|
65
|
-
* stable key. Returns `null` when no payment header is present (nothing to
|
|
66
|
-
* dedupe — e.g. the initial 402 challenge request).
|
|
67
|
-
*/
|
|
68
|
-
declare function paymentIdempotencyKey(getHeader: (name: string) => string | undefined): Promise<string | null>;
|
|
69
|
-
|
|
70
|
-
/** Store shape extended with optional atomic update operation. */
|
|
71
|
-
type ChannelStore = Store.Store & {
|
|
72
|
-
update?: (key: string, fn: (prev: unknown) => unknown) => Promise<unknown>;
|
|
73
|
-
};
|
|
74
|
-
/** Expected payload shape for voucher cumulative amount entries. */
|
|
75
|
-
interface VoucherStoreValue {
|
|
76
|
-
amount: string;
|
|
77
|
-
[key: string]: unknown;
|
|
78
|
-
}
|
|
79
|
-
/** Validates that a stored store value is an object containing a numeric string amount. */
|
|
80
|
-
declare function isVoucherStoreValue(value: unknown): value is VoucherStoreValue;
|
|
81
|
-
type Network = 'testnet' | 'mainnet';
|
|
82
|
-
/** Why a live session was flagged as orphaned (never cleanly closed). */
|
|
83
|
-
type OrphanReason = 'connection-closed' | 'idle-timeout';
|
|
84
|
-
/** Latest signed state of an orphaned session, enough for the reconciler to settle. */
|
|
85
|
-
interface OrphanedSessionInfo {
|
|
86
|
-
/** Cumulative amount of the highest voucher seen (human-readable, 7 dp). */
|
|
87
|
-
cumulativeAmount: string;
|
|
88
|
-
/** Hex-encoded signature of the highest voucher seen. */
|
|
89
|
-
lastSignature: string;
|
|
90
|
-
/** Number of vouchers received before teardown. */
|
|
91
|
-
voucherCount: number;
|
|
92
|
-
/** What triggered the orphan flag. */
|
|
93
|
-
reason: OrphanReason;
|
|
94
|
-
}
|
|
95
|
-
interface MppSessionHandlerOptions {
|
|
96
|
-
payeeSecretKey: string;
|
|
97
|
-
network: Network;
|
|
98
|
-
channelFactory: string;
|
|
99
|
-
rate: string;
|
|
100
|
-
assetContract: string;
|
|
101
|
-
manifest: RouteDockManifest;
|
|
102
|
-
commitmentPublicKey: string;
|
|
103
|
-
onSettled?: (txHash: string, totalPaid: string, mode: string, payer: string | null) => Promise<void>;
|
|
104
|
-
onSessionOpen?: (channelId: string, payer: string | null) => Promise<void>;
|
|
105
|
-
onVoucher?: (channelId: string, voucherIndex: number, cumulativeAmount: string, signature: string) => Promise<void>;
|
|
106
|
-
onCallbackError?: (err: unknown, cb: string) => void;
|
|
107
|
-
/**
|
|
108
|
-
* Called when the client connection drops mid-session or the session goes
|
|
109
|
-
* idle, before a clean close. Persist the session as `closing` so the
|
|
110
|
-
* SessionReconciler can settle it with the latest signed voucher.
|
|
111
|
-
*/
|
|
112
|
-
onOrphaned?: (channelId: string, info: OrphanedSessionInfo) => Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Flag the session orphaned after this many milliseconds with no voucher
|
|
115
|
-
* activity. Disabled when unset.
|
|
116
|
-
*/
|
|
117
|
-
idleTimeoutMs?: number;
|
|
118
|
-
}
|
|
119
|
-
declare function createMppSessionHandler(opts: MppSessionHandlerOptions): RequestHandler;
|
|
120
|
-
|
|
121
|
-
export { type ChannelStore as C, InMemorySeenTxStore as I, type MppSessionHandlerOptions as M, type OrphanedSessionInfo as O, type SeenTxStore as S, type VoucherStoreValue as V, type SettlementRecord as a, type InMemorySeenTxStoreOptions as b, type OrphanReason as c, createMppSessionHandler as d, isVoucherStoreValue as i, paymentIdempotencyKey as p };
|