@inflowpayai/x402-seller 0.5.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.
@@ -0,0 +1,208 @@
1
+ import { FacilitatorClient } from '@x402/core/server';
2
+ import { Environment, X402ConfigResponse, X402FacilitatorSupportedResponse, PaymentScheme } from '@inflowpayai/x402';
3
+ import { PaymentOption } from '@x402/core/http';
4
+ import { Network, SchemeNetworkServer } from '@x402/core/types';
5
+
6
+ /**
7
+ * Constructor options for {@link createInflowFacilitator}. The authed facilitator drops directly into the foundation V2
8
+ * middleware's `facilitatorClients` array (`@x402/express`, `@x402/hono`).
9
+ */
10
+ interface InflowFacilitatorOptions {
11
+ /** Selects one of the public environments. */
12
+ environment: Environment;
13
+ /**
14
+ * InFlow API key. Sent as `X-API-KEY` on every outbound `verify` / `settle` / `getSupported` request. Required at the
15
+ * type level so a typo or env-var omission that leaves `apiKey` undefined can't silently degrade an authed deployment
16
+ * to facilitator-mode — sellers who want the authless path pick {@link createUnauthenticatedInflowFacilitator}
17
+ * explicitly.
18
+ */
19
+ apiKey: string;
20
+ /** Override the environment-derived URL. Takes precedence over `environment`. */
21
+ baseUrl?: string;
22
+ }
23
+ /**
24
+ * Constructor options for {@link createUnauthenticatedInflowFacilitator}.
25
+ *
26
+ * The unauthenticated factory is the explicit escape hatch for facilitator-only deployments (self-hosted,
27
+ * public-facilitator mode, test harnesses) that don't have a seller account. Sends no `X-API-KEY` header on outbound
28
+ * `verify` / `settle` / `getSupported` requests.
29
+ */
30
+ interface InflowUnauthenticatedFacilitatorOptions {
31
+ /** Selects one of the public environments. */
32
+ environment: Environment;
33
+ /** Override the environment-derived URL. Takes precedence over `environment`. */
34
+ baseUrl?: string;
35
+ }
36
+
37
+ /**
38
+ * Construct an authed InFlow facilitator. The returned object satisfies the foundation V2 `FacilitatorClient` contract
39
+ * from `@x402/core` (`verify` / `settle` / `getSupported` only) and drops directly into the foundation middleware's
40
+ * `facilitatorClients` array (`@x402/express`, `@x402/hono`) — first claimer of a `(scheme, network)` in declaration
41
+ * order wins verify/settle routing.
42
+ *
43
+ * Seller-authed endpoints (`/v1/x402/config`, `getSignerAddresses`) live on the separate
44
+ * {@link createInflowSellerClient} factory; this client carries the seller's API key only for `verify` / `settle` /
45
+ * `getSupported`, where it enables server-side `payTo`-against-wallets validation.
46
+ *
47
+ * `getSupported()` is cached lazily in-memory for 60 minutes after the first call; concurrent callers share an
48
+ * in-flight refresh. There is no priming step — the foundation middleware calls `getSupported()` once at
49
+ * `x402ResourceServer.initialize()` and the cache is populated then.
50
+ *
51
+ * @param options - {@link InflowFacilitatorOptions}.
52
+ * @returns A foundation `FacilitatorClient`.
53
+ */
54
+ declare function createInflowFacilitator(options: InflowFacilitatorOptions): FacilitatorClient;
55
+ /**
56
+ * Anonymous sibling of {@link createInflowFacilitator} — same caches and contract, no `X-API-KEY` header. For
57
+ * facilitator-only deployments (self-hosted, public-facilitator mode, test harnesses).
58
+ */
59
+ declare function createUnauthenticatedInflowFacilitator(options: InflowUnauthenticatedFacilitatorOptions): FacilitatorClient;
60
+
61
+ /**
62
+ * Constructor options for {@link createInflowSellerClient}.
63
+ *
64
+ * `apiKey` is required at the type level. `/v1/x402/config` is a seller-authed endpoint — there's no facilitator-mode
65
+ * equivalent — so an unauthenticated seller client has no useful surface to expose.
66
+ */
67
+ interface InflowSellerClientOptions {
68
+ /** Selects one of the public environments. */
69
+ environment: Environment;
70
+ /** InFlow API key sent on every request as `X-API-KEY`. Required. */
71
+ apiKey: string;
72
+ /** Override the environment-derived URL. Takes precedence over `environment`. */
73
+ baseUrl?: string;
74
+ }
75
+ /**
76
+ * Seller-authed InFlow client. Wraps the `/v1/x402/config` and `/v1/x402/supported` endpoints and surfaces
77
+ * signer-address discovery on top of `getSupported()`. Drives {@link inflowAccepts} and any operator- facing
78
+ * introspection.
79
+ *
80
+ * Construct via {@link createInflowSellerClient}. The factory primes both caches in parallel before resolving, so
81
+ * methods on the returned instance hit in-memory data for the lifetime of the 60-minute TTL.
82
+ *
83
+ * @see createInflowSellerClient
84
+ */
85
+ interface InflowSellerClient {
86
+ /**
87
+ * Fetch the seller config (assets, wallets, payment methods, sellerId). Cached for 60 minutes after the factory's
88
+ * prime call.
89
+ *
90
+ * @returns The current `X402ConfigResponse` (re-exported from `@inflowpayai/x402`).
91
+ */
92
+ config(): Promise<X402ConfigResponse>;
93
+ /**
94
+ * Force a refetch of `GET /v1/x402/config` and replace the cached value.
95
+ *
96
+ * @returns The freshly fetched `X402ConfigResponse` (re-exported from `@inflowpayai/x402`).
97
+ */
98
+ refreshConfig(): Promise<X402ConfigResponse>;
99
+ /**
100
+ * Force a refetch of `GET /v1/x402/supported` and replace the cached value.
101
+ *
102
+ * @returns The freshly fetched `X402FacilitatorSupportedResponse` (re-exported from `@inflowpayai/x402`).
103
+ */
104
+ refreshSupported(): Promise<X402FacilitatorSupportedResponse>;
105
+ /**
106
+ * Signer addresses advertised by the facilitator for the given network.
107
+ *
108
+ * Lookup is exact-match on `network` first; if no entry exists and the input is CAIP-2 shaped
109
+ * (`<namespace>:<reference>`), it falls back to a `<namespace>:*` wildcard key so external facilitators that follow
110
+ * the V2 spec's wildcard form interop. Returns `[]` when nothing matches.
111
+ *
112
+ * @param network - CAIP-2 string (e.g. `'eip155:8453'` or `'inflow:1'`).
113
+ * @returns The configured signer addresses, or `[]` when none match.
114
+ */
115
+ getSignerAddresses(network: string): Promise<readonly string[]>;
116
+ }
117
+ /**
118
+ * Construct an {@link InflowSellerClient}.
119
+ *
120
+ * The factory primes the config and `getSupported()` caches in parallel before resolving, so the first downstream call
121
+ * ({@link inflowAccepts}, `getSignerAddresses`, etc.) is synchronous against in-memory data. Cost: one round trip at
122
+ * startup; benefit: synchronous downstream use.
123
+ *
124
+ * @param options - {@link InflowSellerClientOptions}.
125
+ * @returns A promise resolving to a primed {@link InflowSellerClient}.
126
+ */
127
+ declare function createInflowSellerClient(options: InflowSellerClientOptions): Promise<InflowSellerClient>;
128
+
129
+ /** Price spec accepted by {@link inflowAccepts}. */
130
+ interface PriceSpec {
131
+ /**
132
+ * Amount string. Three accepted forms (all supporting up to 8 decimal places):
133
+ *
134
+ * - `'$<integer>(.<decimals>)?'` — implies USD (e.g. `'$0.01'`, `'$10.00000001'`).
135
+ * - `'<integer>(.<decimals>)? <CURRENCY>'` — currency from suffix (e.g. `'0.01 USDC'`, `'0.5 USDT'`, `'1 USD'`).
136
+ * - `'<integer>(.<decimals>)?'` — bare numeric; the {@link PriceSpec.currency} field is required in this case.
137
+ */
138
+ amount: string;
139
+ /**
140
+ * Currency override. When set, takes precedence over any currency embedded in {@link PriceSpec.amount}. Required when
141
+ * `amount` is in bare numeric form. `'USD'` is a wildcard that matches any stablecoin the seller has configured.
142
+ */
143
+ currency?: 'USD' | 'USDC' | 'USDT' | 'PYUSD' | (string & {});
144
+ }
145
+ /** Options accepted by {@link inflowAccepts}. */
146
+ interface InflowAcceptsOptions {
147
+ /**
148
+ * Price for the protected resource. Either a {@link PriceSpec} or a string in any of the three forms accepted by
149
+ * {@link PriceSpec.amount}.
150
+ */
151
+ price: PriceSpec | string;
152
+ /**
153
+ * Maximum lifetime (seconds) attached to each emitted entry. Defaults to `300` — matches the server-side
154
+ * `X402Constants.INFLOW_MAX_TIMEOUT_SECONDS` constant.
155
+ */
156
+ maxTimeoutSeconds?: number;
157
+ /**
158
+ * Optional filter: emit only entries whose `scheme` is in this list. Combined with
159
+ * {@link InflowAcceptsOptions.networks} as logical AND. Omit (or pass `undefined`) for "any scheme."
160
+ */
161
+ schemes?: PaymentScheme[];
162
+ /**
163
+ * Optional filter: emit only entries whose `network` is in this list. Combined with
164
+ * {@link InflowAcceptsOptions.schemes} as logical AND. Omit (or pass `undefined`) for "any network."
165
+ */
166
+ networks?: string[];
167
+ }
168
+ /**
169
+ * Build the `RouteConfig.accepts` array from the seller's cached `/v1/x402/config`. Each entry's `price` is
170
+ * pre-resolved to `AssetAmount` form (asset contract address + atomic-unit amount), so the foundation middleware never
171
+ * needs to consult the config itself. See
172
+ * {@link https://github.com/inflowpayai/inflow-node/blob/main/docs/x402/architecture.md#inflowaccepts-algorithm | the architecture doc}
173
+ * for the full emission and ordering rules.
174
+ *
175
+ * @throws {@link X402PriceParseError} When `price` matches none of the accepted forms.
176
+ */
177
+ declare function inflowAccepts(client: InflowSellerClient, options: InflowAcceptsOptions): Promise<PaymentOption[]>;
178
+
179
+ /**
180
+ * Structural shape of `@x402/express` and `@x402/hono`'s `SchemeRegistration` interface — `{ network, server }` —
181
+ * declared locally so this package stays platform-neutral. Both adapter packages export a `SchemeRegistration`
182
+ * interface composed of the same `@x402/core/types` types, so {@link InflowSchemeRegistration} is structurally
183
+ * assignable to either.
184
+ */
185
+ interface InflowSchemeRegistration {
186
+ network: Network;
187
+ server: SchemeNetworkServer;
188
+ }
189
+ /**
190
+ * Build the passthrough `SchemeRegistration[]` for every `(scheme, network)` pair the seller's `/v1/x402/config` can
191
+ * emit. Pass the result as the third argument to `paymentMiddlewareFromConfig` — the foundation refuses to boot
192
+ * otherwise (`hasRegisteredScheme` is checked before facilitator support). Deduplicated: multiple assets on the same
193
+ * network collapse to one registration. See the architecture doc for the rationale.
194
+ */
195
+ declare function inflowSchemeRegistrations(client: InflowSellerClient): Promise<InflowSchemeRegistration[]>;
196
+
197
+ /**
198
+ * Thrown by `inflowAccepts` when a price string doesn't match any accepted form. See {@link PriceSpec.amount} for the
199
+ * grammar.
200
+ */
201
+ declare class X402PriceParseError extends Error {
202
+ /** The original input that failed parsing. */
203
+ readonly input: string;
204
+ /** @param input - The {@link PriceSpec.amount} value that failed parsing. */
205
+ constructor(input: string);
206
+ }
207
+
208
+ export { type InflowAcceptsOptions, type InflowFacilitatorOptions, type InflowSchemeRegistration, type InflowSellerClient, type InflowSellerClientOptions, type InflowUnauthenticatedFacilitatorOptions, type PriceSpec, X402PriceParseError, createInflowFacilitator, createInflowSellerClient, createUnauthenticatedInflowFacilitator, inflowAccepts, inflowSchemeRegistrations };
@@ -0,0 +1,208 @@
1
+ import { FacilitatorClient } from '@x402/core/server';
2
+ import { Environment, X402ConfigResponse, X402FacilitatorSupportedResponse, PaymentScheme } from '@inflowpayai/x402';
3
+ import { PaymentOption } from '@x402/core/http';
4
+ import { Network, SchemeNetworkServer } from '@x402/core/types';
5
+
6
+ /**
7
+ * Constructor options for {@link createInflowFacilitator}. The authed facilitator drops directly into the foundation V2
8
+ * middleware's `facilitatorClients` array (`@x402/express`, `@x402/hono`).
9
+ */
10
+ interface InflowFacilitatorOptions {
11
+ /** Selects one of the public environments. */
12
+ environment: Environment;
13
+ /**
14
+ * InFlow API key. Sent as `X-API-KEY` on every outbound `verify` / `settle` / `getSupported` request. Required at the
15
+ * type level so a typo or env-var omission that leaves `apiKey` undefined can't silently degrade an authed deployment
16
+ * to facilitator-mode — sellers who want the authless path pick {@link createUnauthenticatedInflowFacilitator}
17
+ * explicitly.
18
+ */
19
+ apiKey: string;
20
+ /** Override the environment-derived URL. Takes precedence over `environment`. */
21
+ baseUrl?: string;
22
+ }
23
+ /**
24
+ * Constructor options for {@link createUnauthenticatedInflowFacilitator}.
25
+ *
26
+ * The unauthenticated factory is the explicit escape hatch for facilitator-only deployments (self-hosted,
27
+ * public-facilitator mode, test harnesses) that don't have a seller account. Sends no `X-API-KEY` header on outbound
28
+ * `verify` / `settle` / `getSupported` requests.
29
+ */
30
+ interface InflowUnauthenticatedFacilitatorOptions {
31
+ /** Selects one of the public environments. */
32
+ environment: Environment;
33
+ /** Override the environment-derived URL. Takes precedence over `environment`. */
34
+ baseUrl?: string;
35
+ }
36
+
37
+ /**
38
+ * Construct an authed InFlow facilitator. The returned object satisfies the foundation V2 `FacilitatorClient` contract
39
+ * from `@x402/core` (`verify` / `settle` / `getSupported` only) and drops directly into the foundation middleware's
40
+ * `facilitatorClients` array (`@x402/express`, `@x402/hono`) — first claimer of a `(scheme, network)` in declaration
41
+ * order wins verify/settle routing.
42
+ *
43
+ * Seller-authed endpoints (`/v1/x402/config`, `getSignerAddresses`) live on the separate
44
+ * {@link createInflowSellerClient} factory; this client carries the seller's API key only for `verify` / `settle` /
45
+ * `getSupported`, where it enables server-side `payTo`-against-wallets validation.
46
+ *
47
+ * `getSupported()` is cached lazily in-memory for 60 minutes after the first call; concurrent callers share an
48
+ * in-flight refresh. There is no priming step — the foundation middleware calls `getSupported()` once at
49
+ * `x402ResourceServer.initialize()` and the cache is populated then.
50
+ *
51
+ * @param options - {@link InflowFacilitatorOptions}.
52
+ * @returns A foundation `FacilitatorClient`.
53
+ */
54
+ declare function createInflowFacilitator(options: InflowFacilitatorOptions): FacilitatorClient;
55
+ /**
56
+ * Anonymous sibling of {@link createInflowFacilitator} — same caches and contract, no `X-API-KEY` header. For
57
+ * facilitator-only deployments (self-hosted, public-facilitator mode, test harnesses).
58
+ */
59
+ declare function createUnauthenticatedInflowFacilitator(options: InflowUnauthenticatedFacilitatorOptions): FacilitatorClient;
60
+
61
+ /**
62
+ * Constructor options for {@link createInflowSellerClient}.
63
+ *
64
+ * `apiKey` is required at the type level. `/v1/x402/config` is a seller-authed endpoint — there's no facilitator-mode
65
+ * equivalent — so an unauthenticated seller client has no useful surface to expose.
66
+ */
67
+ interface InflowSellerClientOptions {
68
+ /** Selects one of the public environments. */
69
+ environment: Environment;
70
+ /** InFlow API key sent on every request as `X-API-KEY`. Required. */
71
+ apiKey: string;
72
+ /** Override the environment-derived URL. Takes precedence over `environment`. */
73
+ baseUrl?: string;
74
+ }
75
+ /**
76
+ * Seller-authed InFlow client. Wraps the `/v1/x402/config` and `/v1/x402/supported` endpoints and surfaces
77
+ * signer-address discovery on top of `getSupported()`. Drives {@link inflowAccepts} and any operator- facing
78
+ * introspection.
79
+ *
80
+ * Construct via {@link createInflowSellerClient}. The factory primes both caches in parallel before resolving, so
81
+ * methods on the returned instance hit in-memory data for the lifetime of the 60-minute TTL.
82
+ *
83
+ * @see createInflowSellerClient
84
+ */
85
+ interface InflowSellerClient {
86
+ /**
87
+ * Fetch the seller config (assets, wallets, payment methods, sellerId). Cached for 60 minutes after the factory's
88
+ * prime call.
89
+ *
90
+ * @returns The current `X402ConfigResponse` (re-exported from `@inflowpayai/x402`).
91
+ */
92
+ config(): Promise<X402ConfigResponse>;
93
+ /**
94
+ * Force a refetch of `GET /v1/x402/config` and replace the cached value.
95
+ *
96
+ * @returns The freshly fetched `X402ConfigResponse` (re-exported from `@inflowpayai/x402`).
97
+ */
98
+ refreshConfig(): Promise<X402ConfigResponse>;
99
+ /**
100
+ * Force a refetch of `GET /v1/x402/supported` and replace the cached value.
101
+ *
102
+ * @returns The freshly fetched `X402FacilitatorSupportedResponse` (re-exported from `@inflowpayai/x402`).
103
+ */
104
+ refreshSupported(): Promise<X402FacilitatorSupportedResponse>;
105
+ /**
106
+ * Signer addresses advertised by the facilitator for the given network.
107
+ *
108
+ * Lookup is exact-match on `network` first; if no entry exists and the input is CAIP-2 shaped
109
+ * (`<namespace>:<reference>`), it falls back to a `<namespace>:*` wildcard key so external facilitators that follow
110
+ * the V2 spec's wildcard form interop. Returns `[]` when nothing matches.
111
+ *
112
+ * @param network - CAIP-2 string (e.g. `'eip155:8453'` or `'inflow:1'`).
113
+ * @returns The configured signer addresses, or `[]` when none match.
114
+ */
115
+ getSignerAddresses(network: string): Promise<readonly string[]>;
116
+ }
117
+ /**
118
+ * Construct an {@link InflowSellerClient}.
119
+ *
120
+ * The factory primes the config and `getSupported()` caches in parallel before resolving, so the first downstream call
121
+ * ({@link inflowAccepts}, `getSignerAddresses`, etc.) is synchronous against in-memory data. Cost: one round trip at
122
+ * startup; benefit: synchronous downstream use.
123
+ *
124
+ * @param options - {@link InflowSellerClientOptions}.
125
+ * @returns A promise resolving to a primed {@link InflowSellerClient}.
126
+ */
127
+ declare function createInflowSellerClient(options: InflowSellerClientOptions): Promise<InflowSellerClient>;
128
+
129
+ /** Price spec accepted by {@link inflowAccepts}. */
130
+ interface PriceSpec {
131
+ /**
132
+ * Amount string. Three accepted forms (all supporting up to 8 decimal places):
133
+ *
134
+ * - `'$<integer>(.<decimals>)?'` — implies USD (e.g. `'$0.01'`, `'$10.00000001'`).
135
+ * - `'<integer>(.<decimals>)? <CURRENCY>'` — currency from suffix (e.g. `'0.01 USDC'`, `'0.5 USDT'`, `'1 USD'`).
136
+ * - `'<integer>(.<decimals>)?'` — bare numeric; the {@link PriceSpec.currency} field is required in this case.
137
+ */
138
+ amount: string;
139
+ /**
140
+ * Currency override. When set, takes precedence over any currency embedded in {@link PriceSpec.amount}. Required when
141
+ * `amount` is in bare numeric form. `'USD'` is a wildcard that matches any stablecoin the seller has configured.
142
+ */
143
+ currency?: 'USD' | 'USDC' | 'USDT' | 'PYUSD' | (string & {});
144
+ }
145
+ /** Options accepted by {@link inflowAccepts}. */
146
+ interface InflowAcceptsOptions {
147
+ /**
148
+ * Price for the protected resource. Either a {@link PriceSpec} or a string in any of the three forms accepted by
149
+ * {@link PriceSpec.amount}.
150
+ */
151
+ price: PriceSpec | string;
152
+ /**
153
+ * Maximum lifetime (seconds) attached to each emitted entry. Defaults to `300` — matches the server-side
154
+ * `X402Constants.INFLOW_MAX_TIMEOUT_SECONDS` constant.
155
+ */
156
+ maxTimeoutSeconds?: number;
157
+ /**
158
+ * Optional filter: emit only entries whose `scheme` is in this list. Combined with
159
+ * {@link InflowAcceptsOptions.networks} as logical AND. Omit (or pass `undefined`) for "any scheme."
160
+ */
161
+ schemes?: PaymentScheme[];
162
+ /**
163
+ * Optional filter: emit only entries whose `network` is in this list. Combined with
164
+ * {@link InflowAcceptsOptions.schemes} as logical AND. Omit (or pass `undefined`) for "any network."
165
+ */
166
+ networks?: string[];
167
+ }
168
+ /**
169
+ * Build the `RouteConfig.accepts` array from the seller's cached `/v1/x402/config`. Each entry's `price` is
170
+ * pre-resolved to `AssetAmount` form (asset contract address + atomic-unit amount), so the foundation middleware never
171
+ * needs to consult the config itself. See
172
+ * {@link https://github.com/inflowpayai/inflow-node/blob/main/docs/x402/architecture.md#inflowaccepts-algorithm | the architecture doc}
173
+ * for the full emission and ordering rules.
174
+ *
175
+ * @throws {@link X402PriceParseError} When `price` matches none of the accepted forms.
176
+ */
177
+ declare function inflowAccepts(client: InflowSellerClient, options: InflowAcceptsOptions): Promise<PaymentOption[]>;
178
+
179
+ /**
180
+ * Structural shape of `@x402/express` and `@x402/hono`'s `SchemeRegistration` interface — `{ network, server }` —
181
+ * declared locally so this package stays platform-neutral. Both adapter packages export a `SchemeRegistration`
182
+ * interface composed of the same `@x402/core/types` types, so {@link InflowSchemeRegistration} is structurally
183
+ * assignable to either.
184
+ */
185
+ interface InflowSchemeRegistration {
186
+ network: Network;
187
+ server: SchemeNetworkServer;
188
+ }
189
+ /**
190
+ * Build the passthrough `SchemeRegistration[]` for every `(scheme, network)` pair the seller's `/v1/x402/config` can
191
+ * emit. Pass the result as the third argument to `paymentMiddlewareFromConfig` — the foundation refuses to boot
192
+ * otherwise (`hasRegisteredScheme` is checked before facilitator support). Deduplicated: multiple assets on the same
193
+ * network collapse to one registration. See the architecture doc for the rationale.
194
+ */
195
+ declare function inflowSchemeRegistrations(client: InflowSellerClient): Promise<InflowSchemeRegistration[]>;
196
+
197
+ /**
198
+ * Thrown by `inflowAccepts` when a price string doesn't match any accepted form. See {@link PriceSpec.amount} for the
199
+ * grammar.
200
+ */
201
+ declare class X402PriceParseError extends Error {
202
+ /** The original input that failed parsing. */
203
+ readonly input: string;
204
+ /** @param input - The {@link PriceSpec.amount} value that failed parsing. */
205
+ constructor(input: string);
206
+ }
207
+
208
+ export { type InflowAcceptsOptions, type InflowFacilitatorOptions, type InflowSchemeRegistration, type InflowSellerClient, type InflowSellerClientOptions, type InflowUnauthenticatedFacilitatorOptions, type PriceSpec, X402PriceParseError, createInflowFacilitator, createInflowSellerClient, createUnauthenticatedInflowFacilitator, inflowAccepts, inflowSchemeRegistrations };