@routedock/routedock 0.1.2 → 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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +532 -4
  3. package/dist/MppSessionHandler-1EL8QBAn.d.cts +215 -0
  4. package/dist/MppSessionHandler-Bq4S-JTE.d.ts +215 -0
  5. package/dist/ProviderRegistry-CA_TdREG.d.ts +142 -0
  6. package/dist/ProviderRegistry-D-0rqK0N.d.cts +142 -0
  7. package/dist/RouteDockClient-Bh86bVly.d.ts +469 -0
  8. package/dist/RouteDockClient-go9aopfF.d.cts +469 -0
  9. package/dist/SessionReconciler-Bw-PoBVl.d.ts +134 -0
  10. package/dist/SessionReconciler-Cz2nuOlJ.d.cts +134 -0
  11. package/dist/SessionStore-B4-Hi4H8.d.cts +143 -0
  12. package/dist/SessionStore-BaYiegP0.d.ts +143 -0
  13. package/dist/client.cjs +2746 -217
  14. package/dist/client.d.cts +51 -81
  15. package/dist/client.d.ts +51 -81
  16. package/dist/client.js +2690 -218
  17. package/dist/index.cjs +3634 -420
  18. package/dist/index.d.cts +12 -3
  19. package/dist/index.d.ts +12 -3
  20. package/dist/index.js +3569 -419
  21. package/dist/logger-D8_Q2ytp.d.cts +467 -0
  22. package/dist/logger-D8_Q2ytp.d.ts +467 -0
  23. package/dist/provider/fastify.cjs +1099 -0
  24. package/dist/provider/fastify.d.cts +40 -0
  25. package/dist/provider/fastify.d.ts +40 -0
  26. package/dist/provider/fastify.js +1097 -0
  27. package/dist/provider/hono.cjs +1152 -0
  28. package/dist/provider/hono.d.cts +101 -0
  29. package/dist/provider/hono.d.ts +101 -0
  30. package/dist/provider/hono.js +1142 -0
  31. package/dist/provider.cjs +1105 -147
  32. package/dist/provider.d.cts +38 -27
  33. package/dist/provider.d.ts +38 -27
  34. package/dist/provider.js +1079 -148
  35. package/dist/react.cjs +2931 -0
  36. package/dist/react.d.cts +107 -0
  37. package/dist/react.d.ts +107 -0
  38. package/dist/react.js +2924 -0
  39. package/dist/routedockMiddleware-57gUaEMf.d.ts +64 -0
  40. package/dist/routedockMiddleware-DlyLrxp7.d.cts +64 -0
  41. package/dist/schema.cjs +404 -0
  42. package/dist/schema.d.cts +3 -0
  43. package/dist/schema.d.ts +3 -0
  44. package/dist/schema.js +399 -0
  45. package/dist/sign-AKH67sft.d.cts +53 -0
  46. package/dist/sign-BEq-OsSq.d.ts +53 -0
  47. package/dist/testing.cjs +59 -0
  48. package/dist/testing.d.cts +114 -0
  49. package/dist/testing.d.ts +114 -0
  50. package/dist/testing.js +56 -0
  51. package/package.json +143 -23
  52. package/PUBLISH_CHECKLIST.md +0 -70
  53. package/dist/SessionStore-CCVO0PHM.d.cts +0 -152
  54. package/dist/SessionStore-CCVO0PHM.d.ts +0 -152
  55. package/dist/routedockMiddleware-B7WTB3LT.d.cts +0 -53
  56. package/dist/routedockMiddleware-DRgdrycG.d.ts +0 -53
  57. package/src/client/ModeRouter.ts +0 -104
  58. package/src/client/MppChargeClient.ts +0 -44
  59. package/src/client/MppSessionClient.ts +0 -144
  60. package/src/client/RouteDockClient.ts +0 -124
  61. package/src/client/index.ts +0 -8
  62. package/src/client/x402Client.ts +0 -84
  63. package/src/index.ts +0 -9
  64. package/src/provider/MppChargeHandler.ts +0 -90
  65. package/src/provider/MppSessionHandler.ts +0 -157
  66. package/src/provider/index.ts +0 -7
  67. package/src/provider/routedockMiddleware.ts +0 -154
  68. package/src/provider/x402Handler.ts +0 -164
  69. package/src/schemas/routedock.schema.json +0 -159
  70. package/src/store/SessionStore.ts +0 -90
  71. package/src/tests/smoke.test.ts +0 -228
  72. package/src/types.ts +0 -165
  73. package/tsconfig.json +0 -14
  74. package/tsup.config.ts +0 -15
@@ -0,0 +1,101 @@
1
+ import { MiddlewareHandler } from 'hono';
2
+ import { Store } from '@stellar/mpp/channel/server';
3
+ import { P as PaymentMode, h as RouteDockManifest, g as RouteDockLogger } from '../logger-D8_Q2ytp.cjs';
4
+ import { O as OrphanedSessionInfo, S as SeenTxStore } from '../MppSessionHandler-1EL8QBAn.cjs';
5
+ export { I as InMemorySeenTxStore, a as SettlementRecord } from '../MppSessionHandler-1EL8QBAn.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-Cz2nuOlJ.cjs';
7
+ export { s as signManifest } from '../sign-AKH67sft.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
+ /** Log sink for internal error paths. Defaults to a console-backed logger. */
60
+ logger?: RouteDockLogger;
61
+ }
62
+ /**
63
+ * Context key set by the mpp-session-ws middleware after a request's payment
64
+ * credential has been verified, so the app's WebSocket upgrade route can
65
+ * refuse to upgrade unauthenticated handshakes.
66
+ */
67
+ declare const MPP_SESSION_WS_VERIFIED = "routedock.mppSessionWs.verified";
68
+ /**
69
+ * True when the routedockHono mpp-session-ws middleware verified the
70
+ * handshake request's Payment credential (see {@link MPP_SESSION_WS_VERIFIED}).
71
+ * WebSocket upgrade routes should refuse to upgrade when this is false.
72
+ */
73
+ declare function mppSessionWsVerified(c: {
74
+ get: (key: string) => unknown;
75
+ }): boolean;
76
+ /**
77
+ * Hono middleware factory for RouteDock provider endpoints.
78
+ *
79
+ * **Workers-safe entry point.** This module uses only Web-standard APIs
80
+ * (`atob`/`TextDecoder` via {@link base64ToUtf8}, {@link hexToBytes}, and the
81
+ * request `AbortSignal`) and runs on Cloudflare Workers, Bun, Deno Deploy, and
82
+ * any Hono deployment target. The Express `routedock()` middleware
83
+ * (`@routedock/routedock/provider`) is Node.js-only — it relies on Node's
84
+ * `Buffer` and `req.on('close')`.
85
+ *
86
+ * Exposes the same configuration surface as the Express `routedock()` middleware.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { routedockHono } from '@routedock/sdk/provider/hono'
91
+ *
92
+ * app.use('/price', routedockHono({
93
+ * modes: ['x402', 'mpp-charge'],
94
+ * pricing: { x402: '0.001', 'mpp-charge': '0.0008' },
95
+ * ...
96
+ * }))
97
+ * ```
98
+ */
99
+ declare function routedockHono(opts: RouteDockHonoOptions): MiddlewareHandler;
100
+
101
+ export { MPP_SESSION_WS_VERIFIED, type RouteDockHonoOptions, SeenTxStore, mppSessionWsVerified, routedockHono };
@@ -0,0 +1,101 @@
1
+ import { MiddlewareHandler } from 'hono';
2
+ import { Store } from '@stellar/mpp/channel/server';
3
+ import { P as PaymentMode, h as RouteDockManifest, g as RouteDockLogger } from '../logger-D8_Q2ytp.js';
4
+ import { O as OrphanedSessionInfo, S as SeenTxStore } from '../MppSessionHandler-Bq4S-JTE.js';
5
+ export { I as InMemorySeenTxStore, a as SettlementRecord } from '../MppSessionHandler-Bq4S-JTE.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-Bw-PoBVl.js';
7
+ export { s as signManifest } from '../sign-BEq-OsSq.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
+ /** Log sink for internal error paths. Defaults to a console-backed logger. */
60
+ logger?: RouteDockLogger;
61
+ }
62
+ /**
63
+ * Context key set by the mpp-session-ws middleware after a request's payment
64
+ * credential has been verified, so the app's WebSocket upgrade route can
65
+ * refuse to upgrade unauthenticated handshakes.
66
+ */
67
+ declare const MPP_SESSION_WS_VERIFIED = "routedock.mppSessionWs.verified";
68
+ /**
69
+ * True when the routedockHono mpp-session-ws middleware verified the
70
+ * handshake request's Payment credential (see {@link MPP_SESSION_WS_VERIFIED}).
71
+ * WebSocket upgrade routes should refuse to upgrade when this is false.
72
+ */
73
+ declare function mppSessionWsVerified(c: {
74
+ get: (key: string) => unknown;
75
+ }): boolean;
76
+ /**
77
+ * Hono middleware factory for RouteDock provider endpoints.
78
+ *
79
+ * **Workers-safe entry point.** This module uses only Web-standard APIs
80
+ * (`atob`/`TextDecoder` via {@link base64ToUtf8}, {@link hexToBytes}, and the
81
+ * request `AbortSignal`) and runs on Cloudflare Workers, Bun, Deno Deploy, and
82
+ * any Hono deployment target. The Express `routedock()` middleware
83
+ * (`@routedock/routedock/provider`) is Node.js-only — it relies on Node's
84
+ * `Buffer` and `req.on('close')`.
85
+ *
86
+ * Exposes the same configuration surface as the Express `routedock()` middleware.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { routedockHono } from '@routedock/sdk/provider/hono'
91
+ *
92
+ * app.use('/price', routedockHono({
93
+ * modes: ['x402', 'mpp-charge'],
94
+ * pricing: { x402: '0.001', 'mpp-charge': '0.0008' },
95
+ * ...
96
+ * }))
97
+ * ```
98
+ */
99
+ declare function routedockHono(opts: RouteDockHonoOptions): MiddlewareHandler;
100
+
101
+ export { MPP_SESSION_WS_VERIFIED, type RouteDockHonoOptions, SeenTxStore, mppSessionWsVerified, routedockHono };