@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.
- package/LICENSE +21 -0
- package/README.md +532 -4
- package/dist/MppSessionHandler-1EL8QBAn.d.cts +215 -0
- package/dist/MppSessionHandler-Bq4S-JTE.d.ts +215 -0
- package/dist/ProviderRegistry-CA_TdREG.d.ts +142 -0
- package/dist/ProviderRegistry-D-0rqK0N.d.cts +142 -0
- package/dist/RouteDockClient-Bh86bVly.d.ts +469 -0
- package/dist/RouteDockClient-go9aopfF.d.cts +469 -0
- package/dist/SessionReconciler-Bw-PoBVl.d.ts +134 -0
- package/dist/SessionReconciler-Cz2nuOlJ.d.cts +134 -0
- package/dist/SessionStore-B4-Hi4H8.d.cts +143 -0
- package/dist/SessionStore-BaYiegP0.d.ts +143 -0
- package/dist/client.cjs +2746 -217
- package/dist/client.d.cts +51 -81
- package/dist/client.d.ts +51 -81
- package/dist/client.js +2690 -218
- package/dist/index.cjs +3634 -420
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +3569 -419
- package/dist/logger-D8_Q2ytp.d.cts +467 -0
- package/dist/logger-D8_Q2ytp.d.ts +467 -0
- package/dist/provider/fastify.cjs +1099 -0
- package/dist/provider/fastify.d.cts +40 -0
- package/dist/provider/fastify.d.ts +40 -0
- package/dist/provider/fastify.js +1097 -0
- package/dist/provider/hono.cjs +1152 -0
- package/dist/provider/hono.d.cts +101 -0
- package/dist/provider/hono.d.ts +101 -0
- package/dist/provider/hono.js +1142 -0
- package/dist/provider.cjs +1105 -147
- package/dist/provider.d.cts +38 -27
- package/dist/provider.d.ts +38 -27
- package/dist/provider.js +1079 -148
- package/dist/react.cjs +2931 -0
- package/dist/react.d.cts +107 -0
- package/dist/react.d.ts +107 -0
- package/dist/react.js +2924 -0
- package/dist/routedockMiddleware-57gUaEMf.d.ts +64 -0
- package/dist/routedockMiddleware-DlyLrxp7.d.cts +64 -0
- package/dist/schema.cjs +404 -0
- package/dist/schema.d.cts +3 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +399 -0
- package/dist/sign-AKH67sft.d.cts +53 -0
- package/dist/sign-BEq-OsSq.d.ts +53 -0
- package/dist/testing.cjs +59 -0
- package/dist/testing.d.cts +114 -0
- package/dist/testing.d.ts +114 -0
- package/dist/testing.js +56 -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
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
+
import { j as RouteDockClient, k as RouteDockClientConfig, M as ModeSelectOptions } from './RouteDockClient-go9aopfF.cjs';
|
|
5
|
+
import { c as PaymentResult, m as SessionHandle, j as SessionCloseResult } from './logger-D8_Q2ytp.cjs';
|
|
6
|
+
import '@stellar/stellar-sdk';
|
|
7
|
+
import '@x402/stellar';
|
|
8
|
+
import '@stellar/stellar-sdk/contract';
|
|
9
|
+
import '@routedock/nulth-sdk';
|
|
10
|
+
import 'mppx';
|
|
11
|
+
|
|
12
|
+
interface RouteDockContextValue {
|
|
13
|
+
client: RouteDockClient;
|
|
14
|
+
supabase?: SupabaseClient;
|
|
15
|
+
}
|
|
16
|
+
interface RouteDockProviderProps extends RouteDockContextValue {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wraps an app with RouteDock client + optional Supabase instance.
|
|
21
|
+
* Child hooks (`usePay`, `useSession`, `useTxLog`) read from this context.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const client = useRouteDockClient({ wallet: secret, network: 'testnet' })
|
|
25
|
+
* return <RouteDockProvider client={client} supabase={supabase}>{children}</RouteDockProvider>
|
|
26
|
+
*/
|
|
27
|
+
declare function RouteDockProvider(props: RouteDockProviderProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
declare function useRouteDockContext(): RouteDockContextValue;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns a memoized RouteDockClient. Re-creates only when wallet / network /
|
|
32
|
+
* spendCap / commitmentSecret / retryPolicy identity changes.
|
|
33
|
+
*
|
|
34
|
+
* The client runs in the browser, so the wallet secret is visible to anyone who
|
|
35
|
+
* loads the page. Never source it from a public environment variable or use a
|
|
36
|
+
* funded key.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const THROWAWAY_TESTNET_SECRET = 'S...'
|
|
40
|
+
* const client = useRouteDockClient({
|
|
41
|
+
* wallet: THROWAWAY_TESTNET_SECRET,
|
|
42
|
+
* network: 'testnet',
|
|
43
|
+
* spendCap: { daily: '1.00', asset: 'USDC' },
|
|
44
|
+
* })
|
|
45
|
+
*/
|
|
46
|
+
declare function useRouteDockClient(config: RouteDockClientConfig): RouteDockClient;
|
|
47
|
+
|
|
48
|
+
interface UsePayResult {
|
|
49
|
+
pay: () => Promise<PaymentResult | null>;
|
|
50
|
+
result: PaymentResult | null;
|
|
51
|
+
loading: boolean;
|
|
52
|
+
error: Error | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Calls `client.pay(url, options)` on demand. Aborts state updates after unmount.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const { pay, result, loading, error } = usePay('https://provider.example.com/price')
|
|
59
|
+
* return <button onClick={pay} disabled={loading}>Pay</button>
|
|
60
|
+
*/
|
|
61
|
+
declare function usePay(url: string, options?: ModeSelectOptions): UsePayResult;
|
|
62
|
+
|
|
63
|
+
type SessionStatus = 'idle' | 'opening' | 'open' | 'closing' | 'closed' | 'error';
|
|
64
|
+
interface UseSessionResult {
|
|
65
|
+
session: SessionHandle | null;
|
|
66
|
+
status: SessionStatus;
|
|
67
|
+
vouchers: number;
|
|
68
|
+
cumulative: string;
|
|
69
|
+
error: Error | null;
|
|
70
|
+
open: () => Promise<SessionHandle | null>;
|
|
71
|
+
close: () => Promise<SessionCloseResult | null>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Manages MPP session lifecycle. On unmount, fires session.close() in the
|
|
75
|
+
* background if status === 'open' (best-effort settlement).
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const { session, open, close, vouchers, cumulative, status } = useSession(streamUrl)
|
|
79
|
+
* useEffect(() => { open() }, [])
|
|
80
|
+
*/
|
|
81
|
+
declare function useSession(url: string): UseSessionResult;
|
|
82
|
+
|
|
83
|
+
interface TxLogRow {
|
|
84
|
+
id: string;
|
|
85
|
+
tx_hash: string;
|
|
86
|
+
mode: string;
|
|
87
|
+
amount: string;
|
|
88
|
+
channel_id: string | null;
|
|
89
|
+
created_at: string;
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
interface UseTxLogFilter {
|
|
93
|
+
channelId?: string;
|
|
94
|
+
mode?: 'x402' | 'mpp-charge' | 'mpp-session';
|
|
95
|
+
limit?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Subscribes to Supabase Realtime on the `tx_log` table. Returns a live array
|
|
99
|
+
* of rows ordered newest-first. Requires <RouteDockProvider supabase={...}>.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const txLog = useTxLog({ channelId, limit: 50 })
|
|
103
|
+
* return <ul>{txLog.map(r => <li key={r.id}>{r.tx_hash}</li>)}</ul>
|
|
104
|
+
*/
|
|
105
|
+
declare function useTxLog(filter?: UseTxLogFilter): TxLogRow[];
|
|
106
|
+
|
|
107
|
+
export { type RouteDockContextValue, RouteDockProvider, type RouteDockProviderProps, type SessionStatus, type TxLogRow, type UsePayResult, type UseSessionResult, type UseTxLogFilter, usePay, useRouteDockClient, useRouteDockContext, useSession, useTxLog };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
+
import { j as RouteDockClient, k as RouteDockClientConfig, M as ModeSelectOptions } from './RouteDockClient-Bh86bVly.js';
|
|
5
|
+
import { c as PaymentResult, m as SessionHandle, j as SessionCloseResult } from './logger-D8_Q2ytp.js';
|
|
6
|
+
import '@stellar/stellar-sdk';
|
|
7
|
+
import '@x402/stellar';
|
|
8
|
+
import '@stellar/stellar-sdk/contract';
|
|
9
|
+
import '@routedock/nulth-sdk';
|
|
10
|
+
import 'mppx';
|
|
11
|
+
|
|
12
|
+
interface RouteDockContextValue {
|
|
13
|
+
client: RouteDockClient;
|
|
14
|
+
supabase?: SupabaseClient;
|
|
15
|
+
}
|
|
16
|
+
interface RouteDockProviderProps extends RouteDockContextValue {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wraps an app with RouteDock client + optional Supabase instance.
|
|
21
|
+
* Child hooks (`usePay`, `useSession`, `useTxLog`) read from this context.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const client = useRouteDockClient({ wallet: secret, network: 'testnet' })
|
|
25
|
+
* return <RouteDockProvider client={client} supabase={supabase}>{children}</RouteDockProvider>
|
|
26
|
+
*/
|
|
27
|
+
declare function RouteDockProvider(props: RouteDockProviderProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
declare function useRouteDockContext(): RouteDockContextValue;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns a memoized RouteDockClient. Re-creates only when wallet / network /
|
|
32
|
+
* spendCap / commitmentSecret / retryPolicy identity changes.
|
|
33
|
+
*
|
|
34
|
+
* The client runs in the browser, so the wallet secret is visible to anyone who
|
|
35
|
+
* loads the page. Never source it from a public environment variable or use a
|
|
36
|
+
* funded key.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const THROWAWAY_TESTNET_SECRET = 'S...'
|
|
40
|
+
* const client = useRouteDockClient({
|
|
41
|
+
* wallet: THROWAWAY_TESTNET_SECRET,
|
|
42
|
+
* network: 'testnet',
|
|
43
|
+
* spendCap: { daily: '1.00', asset: 'USDC' },
|
|
44
|
+
* })
|
|
45
|
+
*/
|
|
46
|
+
declare function useRouteDockClient(config: RouteDockClientConfig): RouteDockClient;
|
|
47
|
+
|
|
48
|
+
interface UsePayResult {
|
|
49
|
+
pay: () => Promise<PaymentResult | null>;
|
|
50
|
+
result: PaymentResult | null;
|
|
51
|
+
loading: boolean;
|
|
52
|
+
error: Error | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Calls `client.pay(url, options)` on demand. Aborts state updates after unmount.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const { pay, result, loading, error } = usePay('https://provider.example.com/price')
|
|
59
|
+
* return <button onClick={pay} disabled={loading}>Pay</button>
|
|
60
|
+
*/
|
|
61
|
+
declare function usePay(url: string, options?: ModeSelectOptions): UsePayResult;
|
|
62
|
+
|
|
63
|
+
type SessionStatus = 'idle' | 'opening' | 'open' | 'closing' | 'closed' | 'error';
|
|
64
|
+
interface UseSessionResult {
|
|
65
|
+
session: SessionHandle | null;
|
|
66
|
+
status: SessionStatus;
|
|
67
|
+
vouchers: number;
|
|
68
|
+
cumulative: string;
|
|
69
|
+
error: Error | null;
|
|
70
|
+
open: () => Promise<SessionHandle | null>;
|
|
71
|
+
close: () => Promise<SessionCloseResult | null>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Manages MPP session lifecycle. On unmount, fires session.close() in the
|
|
75
|
+
* background if status === 'open' (best-effort settlement).
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const { session, open, close, vouchers, cumulative, status } = useSession(streamUrl)
|
|
79
|
+
* useEffect(() => { open() }, [])
|
|
80
|
+
*/
|
|
81
|
+
declare function useSession(url: string): UseSessionResult;
|
|
82
|
+
|
|
83
|
+
interface TxLogRow {
|
|
84
|
+
id: string;
|
|
85
|
+
tx_hash: string;
|
|
86
|
+
mode: string;
|
|
87
|
+
amount: string;
|
|
88
|
+
channel_id: string | null;
|
|
89
|
+
created_at: string;
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
interface UseTxLogFilter {
|
|
93
|
+
channelId?: string;
|
|
94
|
+
mode?: 'x402' | 'mpp-charge' | 'mpp-session';
|
|
95
|
+
limit?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Subscribes to Supabase Realtime on the `tx_log` table. Returns a live array
|
|
99
|
+
* of rows ordered newest-first. Requires <RouteDockProvider supabase={...}>.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const txLog = useTxLog({ channelId, limit: 50 })
|
|
103
|
+
* return <ul>{txLog.map(r => <li key={r.id}>{r.tx_hash}</li>)}</ul>
|
|
104
|
+
*/
|
|
105
|
+
declare function useTxLog(filter?: UseTxLogFilter): TxLogRow[];
|
|
106
|
+
|
|
107
|
+
export { type RouteDockContextValue, RouteDockProvider, type RouteDockProviderProps, type SessionStatus, type TxLogRow, type UsePayResult, type UseSessionResult, type UseTxLogFilter, usePay, useRouteDockClient, useRouteDockContext, useSession, useTxLog };
|