@routedock/routedock 0.1.1 → 0.2.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/LICENSE +21 -0
- package/README.md +281 -19
- package/dist/MppSessionHandler-B4TyD7Xg.d.cts +121 -0
- package/dist/MppSessionHandler-CLB5SzgN.d.ts +121 -0
- package/dist/ProviderRegistry-BJ9oJLVz.d.cts +142 -0
- package/dist/ProviderRegistry-C50nyhaF.d.ts +142 -0
- package/dist/RouteDockClient-B1roCa8h.d.cts +455 -0
- package/dist/RouteDockClient-BbkqjhMG.d.ts +455 -0
- package/dist/SessionReconciler-Dscw43F3.d.ts +125 -0
- package/dist/SessionReconciler-bi0z2qtN.d.cts +125 -0
- package/dist/SessionStore-BpK8vv0L.d.cts +111 -0
- package/dist/SessionStore-DvkZv8-E.d.ts +111 -0
- package/dist/client.cjs +2419 -202
- package/dist/client.d.cts +50 -81
- package/dist/client.d.ts +50 -81
- package/dist/client.js +2373 -203
- package/dist/index.cjs +3080 -298
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +3026 -298
- package/dist/provider/fastify.cjs +882 -0
- package/dist/provider/fastify.d.cts +35 -0
- package/dist/provider/fastify.d.ts +35 -0
- package/dist/provider/fastify.js +880 -0
- package/dist/provider/hono.cjs +948 -0
- package/dist/provider/hono.d.cts +99 -0
- package/dist/provider/hono.d.ts +99 -0
- package/dist/provider/hono.js +938 -0
- package/dist/provider.cjs +827 -97
- package/dist/provider.d.cts +32 -25
- package/dist/provider.d.ts +32 -25
- package/dist/provider.js +810 -99
- package/dist/react.cjs +2641 -0
- package/dist/react.d.cts +107 -0
- package/dist/react.d.ts +107 -0
- package/dist/react.js +2634 -0
- package/dist/routedockMiddleware-BlDsHuPl.d.ts +59 -0
- package/dist/routedockMiddleware-D97A5ptQ.d.cts +59 -0
- package/dist/schema.cjs +364 -0
- package/dist/schema.d.cts +3 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +359 -0
- package/dist/sign-CUf3rhTx.d.cts +53 -0
- package/dist/sign-Dpj2Mp7k.d.ts +53 -0
- package/dist/testing.cjs +57 -0
- package/dist/testing.d.cts +95 -0
- package/dist/testing.d.ts +95 -0
- package/dist/testing.js +54 -0
- package/dist/types-DmhmfLzP.d.cts +410 -0
- package/dist/types-DmhmfLzP.d.ts +410 -0
- package/package.json +143 -23
- package/PUBLISH_CHECKLIST.md +0 -70
- package/dist/SessionStore-CCVO0PHM.d.cts +0 -152
- package/dist/SessionStore-CCVO0PHM.d.ts +0 -152
- package/dist/routedockMiddleware-B7WTB3LT.d.cts +0 -53
- package/dist/routedockMiddleware-DRgdrycG.d.ts +0 -53
- package/src/client/ModeRouter.ts +0 -104
- package/src/client/MppChargeClient.ts +0 -44
- package/src/client/MppSessionClient.ts +0 -144
- package/src/client/RouteDockClient.ts +0 -124
- package/src/client/index.ts +0 -8
- package/src/client/x402Client.ts +0 -84
- package/src/index.ts +0 -9
- package/src/provider/MppChargeHandler.ts +0 -90
- package/src/provider/MppSessionHandler.ts +0 -157
- package/src/provider/index.ts +0 -7
- package/src/provider/routedockMiddleware.ts +0 -154
- package/src/provider/x402Handler.ts +0 -164
- package/src/schemas/routedock.schema.json +0 -159
- package/src/store/SessionStore.ts +0 -90
- package/src/tests/smoke.test.ts +0 -228
- package/src/types.ts +0 -165
- package/tsconfig.json +0 -14
- package/tsup.config.ts +0 -15
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { MiddlewareHandler } from 'hono';
|
|
2
|
+
import { Store } from '@stellar/mpp/channel/server';
|
|
3
|
+
import { P as PaymentMode, R as RouteDockManifest } from '../types-DmhmfLzP.cjs';
|
|
4
|
+
import { O as OrphanedSessionInfo, S as SeenTxStore } from '../MppSessionHandler-B4TyD7Xg.cjs';
|
|
5
|
+
export { I as InMemorySeenTxStore, a as SettlementRecord } from '../MppSessionHandler-B4TyD7Xg.cjs';
|
|
6
|
+
export { R as ReconciliationStats, a as RegisterProviderOptions, S as SessionReconcilerOptions, b as SupabaseSeenTxStore, r as reconcileAbandonedSessions, c as registerProvider, e as runStartupReconciliation } from '../SessionReconciler-bi0z2qtN.cjs';
|
|
7
|
+
export { s as signManifest } from '../sign-CUf3rhTx.cjs';
|
|
8
|
+
import 'mppx';
|
|
9
|
+
import 'express';
|
|
10
|
+
import '@supabase/supabase-js';
|
|
11
|
+
import '@stellar/stellar-sdk';
|
|
12
|
+
|
|
13
|
+
type Network = 'testnet' | 'mainnet';
|
|
14
|
+
interface RouteDockHonoOptions {
|
|
15
|
+
modes: PaymentMode[];
|
|
16
|
+
pricing: {
|
|
17
|
+
x402?: string;
|
|
18
|
+
'mpp-charge'?: string;
|
|
19
|
+
'mpp-session'?: {
|
|
20
|
+
rate: string;
|
|
21
|
+
channelFactory: string;
|
|
22
|
+
};
|
|
23
|
+
/** WebSocket transport variant of mpp-session — same channel, WS streaming */
|
|
24
|
+
'mpp-session-ws'?: {
|
|
25
|
+
rate: string;
|
|
26
|
+
channelFactory: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
asset: string;
|
|
30
|
+
assetContract: string;
|
|
31
|
+
payee: string;
|
|
32
|
+
network: Network;
|
|
33
|
+
payeeSecretKey: string;
|
|
34
|
+
facilitatorApiKey?: string;
|
|
35
|
+
commitmentPublicKey?: string;
|
|
36
|
+
manifest: RouteDockManifest;
|
|
37
|
+
onSettled?: (txHash: string, amount: string, mode: string, payer: string | null) => Promise<void>;
|
|
38
|
+
onSessionOpen?: (channelId: string, payer: string | null) => Promise<void>;
|
|
39
|
+
onVoucher?: (channelId: string, voucherIndex: number, cumulativeAmount: string, signature: string) => Promise<void>;
|
|
40
|
+
onCallbackError?: (err: unknown, cbName: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Called when an mpp-session connection aborts or goes idle before a clean
|
|
43
|
+
* close. Persist the session as `closing` for the SessionReconciler.
|
|
44
|
+
*/
|
|
45
|
+
onOrphaned?: (channelId: string, info: OrphanedSessionInfo) => Promise<void>;
|
|
46
|
+
/** Idle timeout (ms) after which an mpp-session is flagged orphaned. */
|
|
47
|
+
idleTimeoutMs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Idempotency store guarding against duplicate settlement when an agent
|
|
50
|
+
* retries the same payment. Defaults to a per-handler in-memory store.
|
|
51
|
+
*/
|
|
52
|
+
seenTxStore?: SeenTxStore;
|
|
53
|
+
/**
|
|
54
|
+
* Persistent store backing mpp-session channel state and handler state.
|
|
55
|
+
* Defaults to an in-memory store per handler; supply a durable store (e.g.
|
|
56
|
+
* Durable Object storage) so voucher tracking survives isolate eviction.
|
|
57
|
+
*/
|
|
58
|
+
sessionStore?: Store.Store;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Context key set by the mpp-session-ws middleware after a request's payment
|
|
62
|
+
* credential has been verified, so the app's WebSocket upgrade route can
|
|
63
|
+
* refuse to upgrade unauthenticated handshakes.
|
|
64
|
+
*/
|
|
65
|
+
declare const MPP_SESSION_WS_VERIFIED = "routedock.mppSessionWs.verified";
|
|
66
|
+
/**
|
|
67
|
+
* True when the routedockHono mpp-session-ws middleware verified the
|
|
68
|
+
* handshake request's Payment credential (see {@link MPP_SESSION_WS_VERIFIED}).
|
|
69
|
+
* WebSocket upgrade routes should refuse to upgrade when this is false.
|
|
70
|
+
*/
|
|
71
|
+
declare function mppSessionWsVerified(c: {
|
|
72
|
+
get: (key: string) => unknown;
|
|
73
|
+
}): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Hono middleware factory for RouteDock provider endpoints.
|
|
76
|
+
*
|
|
77
|
+
* **Workers-safe entry point.** This module uses only Web-standard APIs
|
|
78
|
+
* (`atob`/`TextDecoder` via {@link base64ToUtf8}, {@link hexToBytes}, and the
|
|
79
|
+
* request `AbortSignal`) and runs on Cloudflare Workers, Bun, Deno Deploy, and
|
|
80
|
+
* any Hono deployment target. The Express `routedock()` middleware
|
|
81
|
+
* (`@routedock/routedock/provider`) is Node.js-only — it relies on Node's
|
|
82
|
+
* `Buffer` and `req.on('close')`.
|
|
83
|
+
*
|
|
84
|
+
* Exposes the same configuration surface as the Express `routedock()` middleware.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { routedockHono } from '@routedock/sdk/provider/hono'
|
|
89
|
+
*
|
|
90
|
+
* app.use('/price', routedockHono({
|
|
91
|
+
* modes: ['x402', 'mpp-charge'],
|
|
92
|
+
* pricing: { x402: '0.001', 'mpp-charge': '0.0008' },
|
|
93
|
+
* ...
|
|
94
|
+
* }))
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function routedockHono(opts: RouteDockHonoOptions): MiddlewareHandler;
|
|
98
|
+
|
|
99
|
+
export { MPP_SESSION_WS_VERIFIED, type RouteDockHonoOptions, SeenTxStore, mppSessionWsVerified, routedockHono };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { MiddlewareHandler } from 'hono';
|
|
2
|
+
import { Store } from '@stellar/mpp/channel/server';
|
|
3
|
+
import { P as PaymentMode, R as RouteDockManifest } from '../types-DmhmfLzP.js';
|
|
4
|
+
import { O as OrphanedSessionInfo, S as SeenTxStore } from '../MppSessionHandler-CLB5SzgN.js';
|
|
5
|
+
export { I as InMemorySeenTxStore, a as SettlementRecord } from '../MppSessionHandler-CLB5SzgN.js';
|
|
6
|
+
export { R as ReconciliationStats, a as RegisterProviderOptions, S as SessionReconcilerOptions, b as SupabaseSeenTxStore, r as reconcileAbandonedSessions, c as registerProvider, e as runStartupReconciliation } from '../SessionReconciler-Dscw43F3.js';
|
|
7
|
+
export { s as signManifest } from '../sign-Dpj2Mp7k.js';
|
|
8
|
+
import 'mppx';
|
|
9
|
+
import 'express';
|
|
10
|
+
import '@supabase/supabase-js';
|
|
11
|
+
import '@stellar/stellar-sdk';
|
|
12
|
+
|
|
13
|
+
type Network = 'testnet' | 'mainnet';
|
|
14
|
+
interface RouteDockHonoOptions {
|
|
15
|
+
modes: PaymentMode[];
|
|
16
|
+
pricing: {
|
|
17
|
+
x402?: string;
|
|
18
|
+
'mpp-charge'?: string;
|
|
19
|
+
'mpp-session'?: {
|
|
20
|
+
rate: string;
|
|
21
|
+
channelFactory: string;
|
|
22
|
+
};
|
|
23
|
+
/** WebSocket transport variant of mpp-session — same channel, WS streaming */
|
|
24
|
+
'mpp-session-ws'?: {
|
|
25
|
+
rate: string;
|
|
26
|
+
channelFactory: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
asset: string;
|
|
30
|
+
assetContract: string;
|
|
31
|
+
payee: string;
|
|
32
|
+
network: Network;
|
|
33
|
+
payeeSecretKey: string;
|
|
34
|
+
facilitatorApiKey?: string;
|
|
35
|
+
commitmentPublicKey?: string;
|
|
36
|
+
manifest: RouteDockManifest;
|
|
37
|
+
onSettled?: (txHash: string, amount: string, mode: string, payer: string | null) => Promise<void>;
|
|
38
|
+
onSessionOpen?: (channelId: string, payer: string | null) => Promise<void>;
|
|
39
|
+
onVoucher?: (channelId: string, voucherIndex: number, cumulativeAmount: string, signature: string) => Promise<void>;
|
|
40
|
+
onCallbackError?: (err: unknown, cbName: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Called when an mpp-session connection aborts or goes idle before a clean
|
|
43
|
+
* close. Persist the session as `closing` for the SessionReconciler.
|
|
44
|
+
*/
|
|
45
|
+
onOrphaned?: (channelId: string, info: OrphanedSessionInfo) => Promise<void>;
|
|
46
|
+
/** Idle timeout (ms) after which an mpp-session is flagged orphaned. */
|
|
47
|
+
idleTimeoutMs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Idempotency store guarding against duplicate settlement when an agent
|
|
50
|
+
* retries the same payment. Defaults to a per-handler in-memory store.
|
|
51
|
+
*/
|
|
52
|
+
seenTxStore?: SeenTxStore;
|
|
53
|
+
/**
|
|
54
|
+
* Persistent store backing mpp-session channel state and handler state.
|
|
55
|
+
* Defaults to an in-memory store per handler; supply a durable store (e.g.
|
|
56
|
+
* Durable Object storage) so voucher tracking survives isolate eviction.
|
|
57
|
+
*/
|
|
58
|
+
sessionStore?: Store.Store;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Context key set by the mpp-session-ws middleware after a request's payment
|
|
62
|
+
* credential has been verified, so the app's WebSocket upgrade route can
|
|
63
|
+
* refuse to upgrade unauthenticated handshakes.
|
|
64
|
+
*/
|
|
65
|
+
declare const MPP_SESSION_WS_VERIFIED = "routedock.mppSessionWs.verified";
|
|
66
|
+
/**
|
|
67
|
+
* True when the routedockHono mpp-session-ws middleware verified the
|
|
68
|
+
* handshake request's Payment credential (see {@link MPP_SESSION_WS_VERIFIED}).
|
|
69
|
+
* WebSocket upgrade routes should refuse to upgrade when this is false.
|
|
70
|
+
*/
|
|
71
|
+
declare function mppSessionWsVerified(c: {
|
|
72
|
+
get: (key: string) => unknown;
|
|
73
|
+
}): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Hono middleware factory for RouteDock provider endpoints.
|
|
76
|
+
*
|
|
77
|
+
* **Workers-safe entry point.** This module uses only Web-standard APIs
|
|
78
|
+
* (`atob`/`TextDecoder` via {@link base64ToUtf8}, {@link hexToBytes}, and the
|
|
79
|
+
* request `AbortSignal`) and runs on Cloudflare Workers, Bun, Deno Deploy, and
|
|
80
|
+
* any Hono deployment target. The Express `routedock()` middleware
|
|
81
|
+
* (`@routedock/routedock/provider`) is Node.js-only — it relies on Node's
|
|
82
|
+
* `Buffer` and `req.on('close')`.
|
|
83
|
+
*
|
|
84
|
+
* Exposes the same configuration surface as the Express `routedock()` middleware.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { routedockHono } from '@routedock/sdk/provider/hono'
|
|
89
|
+
*
|
|
90
|
+
* app.use('/price', routedockHono({
|
|
91
|
+
* modes: ['x402', 'mpp-charge'],
|
|
92
|
+
* pricing: { x402: '0.001', 'mpp-charge': '0.0008' },
|
|
93
|
+
* ...
|
|
94
|
+
* }))
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function routedockHono(opts: RouteDockHonoOptions): MiddlewareHandler;
|
|
98
|
+
|
|
99
|
+
export { MPP_SESSION_WS_VERIFIED, type RouteDockHonoOptions, SeenTxStore, mppSessionWsVerified, routedockHono };
|