@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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -19
  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,142 @@
1
+ import { usdcToStroops } from '@routedock/nulth-sdk';
2
+ import { m as SpendStore, a as DailySpend, R as RetryPolicy } from './RouteDockClient-B1roCa8h.cjs';
3
+ import { ClientStellarSigner } from '@x402/stellar';
4
+ import { R as RouteDockManifest, c as PaymentResult } from './types-DmhmfLzP.cjs';
5
+ import { Keypair } from '@stellar/stellar-sdk';
6
+ import { SupabaseClient } from '@supabase/supabase-js';
7
+
8
+ /**
9
+ * USDC conversion — canonical implementation lives in @routedock/nulth-sdk and is
10
+ * re-exported here so SDK consumers (client, provider) share one converter.
11
+ *
12
+ * @routedock/routedock already depends on @routedock/nulth-sdk, so re-exporting
13
+ * (rather than defining a parallel helper) keeps a single source of truth.
14
+ */
15
+
16
+ /**
17
+ * @deprecated Use {@link usdcToStroops} — the same validated bigint converter.
18
+ * Kept as a thin alias so existing call sites keep working during migration.
19
+ */
20
+ declare const usdcToUnits: typeof usdcToStroops;
21
+
22
+ /**
23
+ * File-backed durable {@link SpendStore}.
24
+ *
25
+ * Persists the daily spend accumulator to a JSON file on disk, preserving
26
+ * cumulative spending totals across process restarts, crashes, and redeploys.
27
+ *
28
+ * ### Error semantics
29
+ * - File absent (ENOENT): returns null — legitimately no spend recorded yet.
30
+ * - File present but unreadable or malformed: throws — a safety control must
31
+ * fail closed, not assume nothing was spent.
32
+ *
33
+ * ### Write atomicity
34
+ * Writes go to `<filePath>.tmp` first, then `fs.rename` onto the target.
35
+ * `rename` is atomic within a filesystem, so there is no window where the
36
+ * target file is truncated but not yet fully written.
37
+ */
38
+ declare class FileSpendStore implements SpendStore {
39
+ readonly filePath: string;
40
+ constructor(filePath: string);
41
+ read(): Promise<DailySpend | null>;
42
+ write(state: DailySpend): Promise<void>;
43
+ }
44
+
45
+ type Network = 'testnet' | 'mainnet';
46
+ declare class X402Client {
47
+ private readonly network;
48
+ private readonly retryPolicy?;
49
+ private readonly httpClient;
50
+ private readonly signer;
51
+ constructor(secretKeyOrSigner: string | ClientStellarSigner, network: Network, retryPolicy?: RetryPolicy | undefined);
52
+ /** Replace signer (e.g. swap to Nulth ZK account payer before pay) */
53
+ withSigner(signer: ClientStellarSigner): X402Client;
54
+ pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
55
+ }
56
+
57
+ declare class MppChargeClient {
58
+ private readonly keypair;
59
+ private readonly network;
60
+ private readonly retryPolicy?;
61
+ constructor(keypair: Keypair, network: 'testnet' | 'mainnet', retryPolicy?: RetryPolicy | undefined);
62
+ pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
63
+ }
64
+
65
+ interface OnChainProviderInfo {
66
+ account: string;
67
+ endpoint: string;
68
+ tags: string[];
69
+ }
70
+ declare class OnChainRegistry {
71
+ private readonly horizon;
72
+ private readonly knownAccounts;
73
+ private readonly timeoutMs;
74
+ constructor(options: {
75
+ horizonUrl: string;
76
+ knownAccounts: string[];
77
+ timeoutMs?: number;
78
+ });
79
+ /**
80
+ * stellar-sdk 14.6.1 has no way to cancel the underlying Horizon request, so
81
+ * we stop waiting on it instead: the promise returned here rejects once
82
+ * `timeoutMs` elapses, even though the request may still be in flight. The
83
+ * timer is always cleared, including on the error path.
84
+ */
85
+ private loadAccountWithTimeout;
86
+ listProviders(): Promise<OnChainProviderInfo[]>;
87
+ }
88
+
89
+ interface ProviderRecord {
90
+ name: string;
91
+ description: string | undefined;
92
+ base_url: string;
93
+ modes: string[];
94
+ tags: string[];
95
+ network: string;
96
+ payee: string;
97
+ source: 'supabase' | 'onchain';
98
+ /**
99
+ * True only when the provider was verified out-of-band — for on-chain
100
+ * records the payee is the account that published the endpoint, for
101
+ * supabase records only rows flagged `verified` are returned.
102
+ */
103
+ verified: boolean;
104
+ }
105
+ interface ProviderRegistryConfig {
106
+ supabase?: SupabaseClient;
107
+ onChain: {
108
+ horizonUrl: string;
109
+ knownAccounts: string[];
110
+ /**
111
+ * Optional explicit network override. When omitted it is derived from the
112
+ * Horizon URL: URLs containing `testnet` map to 'testnet', everything else
113
+ * defaults to 'mainnet'.
114
+ */
115
+ network?: 'testnet' | 'mainnet';
116
+ /**
117
+ * Per-account timeout for on-chain account loads, in milliseconds.
118
+ * Defaults to 10000 ms.
119
+ */
120
+ timeoutMs?: number;
121
+ };
122
+ }
123
+ declare class ProviderRegistry {
124
+ private readonly supabase;
125
+ private readonly onChain;
126
+ private readonly network;
127
+ constructor(config: ProviderRegistryConfig);
128
+ listProviders(): Promise<ProviderRecord[]>;
129
+ private trySupabase;
130
+ private tryOnChain;
131
+ /**
132
+ * Fetch a provider's manifest bound to the record's payee. The record's
133
+ * `payee` (from supabase `verified` rows or the on-chain registry account)
134
+ * is the out-of-band trust anchor: the fetched manifest's `payee` must
135
+ * equal it, otherwise `RouteDockSignatureError` is thrown. This closes the
136
+ * gap where the registry never cross-checked the on-chain payee against
137
+ * the manifest payee.
138
+ */
139
+ fetchProviderManifest(record: ProviderRecord): Promise<RouteDockManifest>;
140
+ }
141
+
142
+ export { FileSpendStore as F, MppChargeClient as M, type OnChainProviderInfo as O, type ProviderRecord as P, X402Client as X, OnChainRegistry as a, ProviderRegistry as b, type ProviderRegistryConfig as c, usdcToUnits as u };
@@ -0,0 +1,142 @@
1
+ import { usdcToStroops } from '@routedock/nulth-sdk';
2
+ import { m as SpendStore, a as DailySpend, R as RetryPolicy } from './RouteDockClient-BbkqjhMG.js';
3
+ import { ClientStellarSigner } from '@x402/stellar';
4
+ import { R as RouteDockManifest, c as PaymentResult } from './types-DmhmfLzP.js';
5
+ import { Keypair } from '@stellar/stellar-sdk';
6
+ import { SupabaseClient } from '@supabase/supabase-js';
7
+
8
+ /**
9
+ * USDC conversion — canonical implementation lives in @routedock/nulth-sdk and is
10
+ * re-exported here so SDK consumers (client, provider) share one converter.
11
+ *
12
+ * @routedock/routedock already depends on @routedock/nulth-sdk, so re-exporting
13
+ * (rather than defining a parallel helper) keeps a single source of truth.
14
+ */
15
+
16
+ /**
17
+ * @deprecated Use {@link usdcToStroops} — the same validated bigint converter.
18
+ * Kept as a thin alias so existing call sites keep working during migration.
19
+ */
20
+ declare const usdcToUnits: typeof usdcToStroops;
21
+
22
+ /**
23
+ * File-backed durable {@link SpendStore}.
24
+ *
25
+ * Persists the daily spend accumulator to a JSON file on disk, preserving
26
+ * cumulative spending totals across process restarts, crashes, and redeploys.
27
+ *
28
+ * ### Error semantics
29
+ * - File absent (ENOENT): returns null — legitimately no spend recorded yet.
30
+ * - File present but unreadable or malformed: throws — a safety control must
31
+ * fail closed, not assume nothing was spent.
32
+ *
33
+ * ### Write atomicity
34
+ * Writes go to `<filePath>.tmp` first, then `fs.rename` onto the target.
35
+ * `rename` is atomic within a filesystem, so there is no window where the
36
+ * target file is truncated but not yet fully written.
37
+ */
38
+ declare class FileSpendStore implements SpendStore {
39
+ readonly filePath: string;
40
+ constructor(filePath: string);
41
+ read(): Promise<DailySpend | null>;
42
+ write(state: DailySpend): Promise<void>;
43
+ }
44
+
45
+ type Network = 'testnet' | 'mainnet';
46
+ declare class X402Client {
47
+ private readonly network;
48
+ private readonly retryPolicy?;
49
+ private readonly httpClient;
50
+ private readonly signer;
51
+ constructor(secretKeyOrSigner: string | ClientStellarSigner, network: Network, retryPolicy?: RetryPolicy | undefined);
52
+ /** Replace signer (e.g. swap to Nulth ZK account payer before pay) */
53
+ withSigner(signer: ClientStellarSigner): X402Client;
54
+ pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
55
+ }
56
+
57
+ declare class MppChargeClient {
58
+ private readonly keypair;
59
+ private readonly network;
60
+ private readonly retryPolicy?;
61
+ constructor(keypair: Keypair, network: 'testnet' | 'mainnet', retryPolicy?: RetryPolicy | undefined);
62
+ pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
63
+ }
64
+
65
+ interface OnChainProviderInfo {
66
+ account: string;
67
+ endpoint: string;
68
+ tags: string[];
69
+ }
70
+ declare class OnChainRegistry {
71
+ private readonly horizon;
72
+ private readonly knownAccounts;
73
+ private readonly timeoutMs;
74
+ constructor(options: {
75
+ horizonUrl: string;
76
+ knownAccounts: string[];
77
+ timeoutMs?: number;
78
+ });
79
+ /**
80
+ * stellar-sdk 14.6.1 has no way to cancel the underlying Horizon request, so
81
+ * we stop waiting on it instead: the promise returned here rejects once
82
+ * `timeoutMs` elapses, even though the request may still be in flight. The
83
+ * timer is always cleared, including on the error path.
84
+ */
85
+ private loadAccountWithTimeout;
86
+ listProviders(): Promise<OnChainProviderInfo[]>;
87
+ }
88
+
89
+ interface ProviderRecord {
90
+ name: string;
91
+ description: string | undefined;
92
+ base_url: string;
93
+ modes: string[];
94
+ tags: string[];
95
+ network: string;
96
+ payee: string;
97
+ source: 'supabase' | 'onchain';
98
+ /**
99
+ * True only when the provider was verified out-of-band — for on-chain
100
+ * records the payee is the account that published the endpoint, for
101
+ * supabase records only rows flagged `verified` are returned.
102
+ */
103
+ verified: boolean;
104
+ }
105
+ interface ProviderRegistryConfig {
106
+ supabase?: SupabaseClient;
107
+ onChain: {
108
+ horizonUrl: string;
109
+ knownAccounts: string[];
110
+ /**
111
+ * Optional explicit network override. When omitted it is derived from the
112
+ * Horizon URL: URLs containing `testnet` map to 'testnet', everything else
113
+ * defaults to 'mainnet'.
114
+ */
115
+ network?: 'testnet' | 'mainnet';
116
+ /**
117
+ * Per-account timeout for on-chain account loads, in milliseconds.
118
+ * Defaults to 10000 ms.
119
+ */
120
+ timeoutMs?: number;
121
+ };
122
+ }
123
+ declare class ProviderRegistry {
124
+ private readonly supabase;
125
+ private readonly onChain;
126
+ private readonly network;
127
+ constructor(config: ProviderRegistryConfig);
128
+ listProviders(): Promise<ProviderRecord[]>;
129
+ private trySupabase;
130
+ private tryOnChain;
131
+ /**
132
+ * Fetch a provider's manifest bound to the record's payee. The record's
133
+ * `payee` (from supabase `verified` rows or the on-chain registry account)
134
+ * is the out-of-band trust anchor: the fetched manifest's `payee` must
135
+ * equal it, otherwise `RouteDockSignatureError` is thrown. This closes the
136
+ * gap where the registry never cross-checked the on-chain payee against
137
+ * the manifest payee.
138
+ */
139
+ fetchProviderManifest(record: ProviderRecord): Promise<RouteDockManifest>;
140
+ }
141
+
142
+ export { FileSpendStore as F, MppChargeClient as M, type OnChainProviderInfo as O, type ProviderRecord as P, X402Client as X, OnChainRegistry as a, ProviderRegistry as b, type ProviderRegistryConfig as c, usdcToUnits as u };