@routedock/routedock 0.1.2 → 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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +227 -4
  3. package/dist/MppSessionHandler-B4TyD7Xg.d.cts +121 -0
  4. package/dist/MppSessionHandler-CLB5SzgN.d.ts +121 -0
  5. package/dist/ProviderRegistry-BJ9oJLVz.d.cts +142 -0
  6. package/dist/ProviderRegistry-C50nyhaF.d.ts +142 -0
  7. package/dist/RouteDockClient-B1roCa8h.d.cts +455 -0
  8. package/dist/RouteDockClient-BbkqjhMG.d.ts +455 -0
  9. package/dist/SessionReconciler-Dscw43F3.d.ts +125 -0
  10. package/dist/SessionReconciler-bi0z2qtN.d.cts +125 -0
  11. package/dist/SessionStore-BpK8vv0L.d.cts +111 -0
  12. package/dist/SessionStore-DvkZv8-E.d.ts +111 -0
  13. package/dist/client.cjs +2419 -202
  14. package/dist/client.d.cts +50 -81
  15. package/dist/client.d.ts +50 -81
  16. package/dist/client.js +2373 -203
  17. package/dist/index.cjs +3080 -298
  18. package/dist/index.d.cts +12 -3
  19. package/dist/index.d.ts +12 -3
  20. package/dist/index.js +3026 -298
  21. package/dist/provider/fastify.cjs +882 -0
  22. package/dist/provider/fastify.d.cts +35 -0
  23. package/dist/provider/fastify.d.ts +35 -0
  24. package/dist/provider/fastify.js +880 -0
  25. package/dist/provider/hono.cjs +948 -0
  26. package/dist/provider/hono.d.cts +99 -0
  27. package/dist/provider/hono.d.ts +99 -0
  28. package/dist/provider/hono.js +938 -0
  29. package/dist/provider.cjs +827 -97
  30. package/dist/provider.d.cts +32 -25
  31. package/dist/provider.d.ts +32 -25
  32. package/dist/provider.js +810 -99
  33. package/dist/react.cjs +2641 -0
  34. package/dist/react.d.cts +107 -0
  35. package/dist/react.d.ts +107 -0
  36. package/dist/react.js +2634 -0
  37. package/dist/routedockMiddleware-BlDsHuPl.d.ts +59 -0
  38. package/dist/routedockMiddleware-D97A5ptQ.d.cts +59 -0
  39. package/dist/schema.cjs +364 -0
  40. package/dist/schema.d.cts +3 -0
  41. package/dist/schema.d.ts +3 -0
  42. package/dist/schema.js +359 -0
  43. package/dist/sign-CUf3rhTx.d.cts +53 -0
  44. package/dist/sign-Dpj2Mp7k.d.ts +53 -0
  45. package/dist/testing.cjs +57 -0
  46. package/dist/testing.d.cts +95 -0
  47. package/dist/testing.d.ts +95 -0
  48. package/dist/testing.js +54 -0
  49. package/dist/types-DmhmfLzP.d.cts +410 -0
  50. package/dist/types-DmhmfLzP.d.ts +410 -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,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-B1roCa8h.cjs';
5
+ import { c as PaymentResult, j as SessionHandle, g as SessionCloseResult } from './types-DmhmfLzP.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 };
@@ -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-BbkqjhMG.js';
5
+ import { c as PaymentResult, j as SessionHandle, g as SessionCloseResult } from './types-DmhmfLzP.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 };