@catena/sdk 0.0.0-bootstrap.0 → 0.4.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/dist/mpp.d.mts ADDED
@@ -0,0 +1,327 @@
1
+ import { J as WalletCounterpartyRail, N as IntentResult, i as FetchLike, n as CatenaClient } from "./client-B_Gi0aqH.mjs";
2
+ import { Method, z } from "mppx";
3
+ //#region src/mpp.d.ts
4
+ /**
5
+ * CAIP-2 network carried by an EVM MPP charge. Known values provide editor
6
+ * hints, while other strings remain representable because the server decides
7
+ * which networks are payable.
8
+ */
9
+ export type MppNetwork = "eip155:8453" | "eip155:84532" | "eip155:5042" | (string & {});
10
+ declare const evmCharge: {
11
+ readonly name: "evm";
12
+ readonly intent: "charge";
13
+ readonly schema: {
14
+ credential: {
15
+ payload: z.ZodMiniObject<{
16
+ type: z.ZodMiniLiteral<"authorization">;
17
+ from: z.ZodMiniString<string>;
18
+ to: z.ZodMiniString<string>;
19
+ value: z.ZodMiniString<string>;
20
+ validAfter: z.ZodMiniString<string>;
21
+ validBefore: z.ZodMiniString<string>;
22
+ nonce: z.ZodMiniString<string>;
23
+ signature: z.ZodMiniString<string>;
24
+ }, z.core.$strip>;
25
+ };
26
+ request: z.ZodMiniObject<{
27
+ amount: z.ZodMiniString<string>;
28
+ currency: z.ZodMiniString<string>;
29
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
30
+ externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
31
+ recipient: z.ZodMiniString<string>;
32
+ methodDetails: z.ZodMiniObject<{
33
+ chainId: z.ZodMiniNumber<number>;
34
+ credentialTypes: z.ZodMiniArray<z.ZodMiniLiteral<"authorization">>;
35
+ decimals: z.ZodMiniLiteral<6>;
36
+ permit2Address: z.ZodMiniOptional<z.ZodMiniString<string>>;
37
+ splits: z.ZodMiniOptional<z.ZodMiniNever>;
38
+ }, z.core.$strip>;
39
+ }, z.core.$strip>;
40
+ };
41
+ };
42
+ declare const usdcCharge: {
43
+ readonly name: "usdc";
44
+ readonly intent: "charge";
45
+ readonly schema: {
46
+ credential: {
47
+ payload: z.ZodMiniObject<{
48
+ type: z.ZodMiniLiteral<"authorization">;
49
+ from: z.ZodMiniString<string>;
50
+ to: z.ZodMiniString<string>;
51
+ value: z.ZodMiniString<string>;
52
+ validAfter: z.ZodMiniString<string>;
53
+ validBefore: z.ZodMiniString<string>;
54
+ nonce: z.ZodMiniString<string>;
55
+ signature: z.ZodMiniString<string>;
56
+ }, z.core.$strip>;
57
+ };
58
+ request: z.ZodMiniObject<{
59
+ amount: z.ZodMiniString<string>;
60
+ currency: z.ZodMiniString<string>;
61
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
62
+ externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
63
+ recipient: z.ZodMiniString<string>;
64
+ methodDetails: z.ZodMiniObject<{
65
+ type: z.ZodMiniLiteral<"evm">;
66
+ evm: z.ZodMiniObject<{
67
+ chainId: z.ZodMiniNumber<number>;
68
+ credentialTypes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniLiteral<"authorization">>>;
69
+ decimals: z.ZodMiniLiteral<6>;
70
+ permit2Address: z.ZodMiniOptional<z.ZodMiniString<string>>;
71
+ splits: z.ZodMiniOptional<z.ZodMiniNever>;
72
+ }, z.core.$strip>;
73
+ }, z.core.$strip>;
74
+ }, z.core.$strip>;
75
+ };
76
+ };
77
+ /**
78
+ * Parameters shared by both Catena MPP charge methods.
79
+ */
80
+ export interface CatenaMppParameters {
81
+ /**
82
+ * A linked Catena SDK client used to submit the payment intent.
83
+ */
84
+ readonly client: CatenaClient;
85
+ /**
86
+ * Catena account whose wallet will authorize the charge.
87
+ */
88
+ readonly accountId: string;
89
+ /**
90
+ * Price ceiling in atomic USDC units (6 decimals). Challenges asking for
91
+ * more are refused before any intent is created.
92
+ */
93
+ readonly maxAtomicAmount?: bigint;
94
+ }
95
+ /**
96
+ * Catena-backed `evm/charge` mppx client method.
97
+ */
98
+ export type CatenaEvmChargeMethod = Method.Client<typeof evmCharge>;
99
+ /**
100
+ * Catena-backed `usdc/charge` mppx client method.
101
+ */
102
+ export type CatenaUsdcChargeMethod = Method.Client<typeof usdcCharge>;
103
+ /**
104
+ * Both Catena methods registered by the factory.
105
+ */
106
+ export type CatenaMppMethods = readonly [CatenaEvmChargeMethod, CatenaUsdcChargeMethod];
107
+ /**
108
+ * Callable Catena MPP factory, with the conventional charge alias.
109
+ */
110
+ export interface CatenaMppFactory {
111
+ (parameters: CatenaMppParameters): CatenaMppMethods;
112
+ charge(parameters: CatenaMppParameters): CatenaMppMethods;
113
+ }
114
+ /**
115
+ * Status of a Catena MPP intent that did not yield a usable credential.
116
+ */
117
+ export type MppPaymentStatus = IntentResult["status"];
118
+ /**
119
+ * A Catena MPP intent completed without a usable credential or stopped in a
120
+ * non-completed state. Inspect `status` to choose a recovery path and
121
+ * `intentId` to reconcile the payment with `client.getIntent(intentId)`.
122
+ */
123
+ export declare class MppPaymentError extends Error {
124
+ readonly intentId: string;
125
+ readonly status: MppPaymentStatus;
126
+ readonly reasons: readonly string[];
127
+ readonly expiresAt: string | null;
128
+ constructor(message: string, details: {
129
+ readonly intentId: string;
130
+ readonly status: MppPaymentStatus;
131
+ readonly reasons: readonly string[];
132
+ readonly expiresAt: string | null;
133
+ });
134
+ }
135
+ /**
136
+ * Credential-free record of an MPP payment completed by the managed fetch
137
+ * wrapper.
138
+ */
139
+ export interface MppPaymentReceipt {
140
+ /**
141
+ * Catena intent that completed the payment.
142
+ */
143
+ readonly intentId: string;
144
+ /**
145
+ * Validated MPP method selected from the seller's challenge.
146
+ */
147
+ readonly method: "evm" | "usdc";
148
+ /**
149
+ * Paid amount in atomic USDC units (6 decimals).
150
+ */
151
+ readonly atomicAmount: string;
152
+ /**
153
+ * CAIP-2 network on which the payment was authorized.
154
+ */
155
+ readonly network: MppNetwork;
156
+ /**
157
+ * EVM address that received the payment authorization.
158
+ */
159
+ readonly recipient: string;
160
+ /**
161
+ * Canonical final URL of the resource that was paid.
162
+ */
163
+ readonly resourceUrl: string;
164
+ }
165
+ /**
166
+ * Base error for managed MPP negotiation failures. `intentId` is present only
167
+ * after Catena created an intent; `reasons` carries server recovery detail
168
+ * without exposing the payment credential.
169
+ */
170
+ export declare class MppFetchPaymentError extends Error {
171
+ /**
172
+ * Catena intent to reconcile, when one was created.
173
+ */
174
+ readonly intentId: string | undefined;
175
+ /**
176
+ * Stable recovery detail returned by Catena.
177
+ */
178
+ readonly reasons: readonly string[];
179
+ constructor(message: string, details?: {
180
+ readonly intentId?: string;
181
+ readonly reasons?: readonly string[];
182
+ readonly cause?: unknown;
183
+ });
184
+ }
185
+ /**
186
+ * None of the offered MPP networks can be funded by the selected account.
187
+ */
188
+ export declare class MppNetworkMismatchError extends MppFetchPaymentError {
189
+ /**
190
+ * Account that needs a wallet on one of the required networks.
191
+ */
192
+ readonly accountId: string;
193
+ /**
194
+ * Offered networks that Catena reported as mismatches.
195
+ */
196
+ readonly requiredNetworks: readonly MppNetwork[];
197
+ constructor(accountId: string, requiredNetworks: readonly MppNetwork[], reasons: readonly string[]);
198
+ }
199
+ /**
200
+ * The selected MPP recipient is not saved as a usable Catena counterparty
201
+ * rail.
202
+ */
203
+ export declare class MppCounterpartyNotFoundError extends MppFetchPaymentError {
204
+ /**
205
+ * Recipient address that must be added.
206
+ */
207
+ readonly recipient: string;
208
+ /**
209
+ * Network on which the recipient was offered.
210
+ */
211
+ readonly network: MppNetwork;
212
+ /**
213
+ * Server-resolved Catena rail that can be passed to a
214
+ * `create_counterparty` intent. Absent when the server sends no valid rail,
215
+ * or when the rail names a different recipient than the challenge.
216
+ */
217
+ readonly requiredRail: WalletCounterpartyRail | undefined;
218
+ constructor(recipient: string, network: MppNetwork, reasons: readonly string[], requiredRail?: WalletCounterpartyRail);
219
+ }
220
+ /**
221
+ * The MPP payment is parked for human approval. Retry the original request
222
+ * after approval so a fresh challenge can consume the grant.
223
+ */
224
+ export declare class MppApprovalPendingError extends MppFetchPaymentError {
225
+ /**
226
+ * Time at which the pending approval expires, when supplied by Catena.
227
+ */
228
+ readonly expiresAt: string | null;
229
+ constructor(intentId: string, reasons: readonly string[], expiresAt: string | null);
230
+ }
231
+ /**
232
+ * Catena terminally blocked or failed the selected MPP payment.
233
+ */
234
+ export declare class MppPaymentDeclinedError extends MppFetchPaymentError {
235
+ /**
236
+ * Terminal intent disposition.
237
+ */
238
+ readonly status: "blocked" | "failed";
239
+ constructor(intentId: string, status: "blocked" | "failed", reasons: readonly string[]);
240
+ }
241
+ /**
242
+ * Submission failed where Catena may already have acted. Reconcile the intent
243
+ * before authorizing another payment.
244
+ */
245
+ export declare class MppSubmitInterruptedError extends MppFetchPaymentError {
246
+ /**
247
+ * Validated MPP method whose submission became ambiguous.
248
+ */
249
+ readonly method: "evm" | "usdc";
250
+ /**
251
+ * Potentially paid amount in atomic USDC units.
252
+ */
253
+ readonly atomicAmount: string;
254
+ /**
255
+ * Network on which submission may have occurred.
256
+ */
257
+ readonly network: MppNetwork;
258
+ /**
259
+ * Recipient whose payment may have been submitted.
260
+ */
261
+ readonly recipient: string;
262
+ /**
263
+ * Canonical resource URL bound to the ambiguous intent.
264
+ */
265
+ readonly resourceUrl: string;
266
+ constructor(intentId: string, terms: {
267
+ readonly method: "evm" | "usdc";
268
+ readonly atomicAmount: string;
269
+ readonly network: MppNetwork;
270
+ readonly recipient: string;
271
+ }, resourceUrl: string, cause: unknown);
272
+ }
273
+ /**
274
+ * Payment completed but `onPayment` or the single paid retry failed. The
275
+ * credential-free receipt identifies the settled intent for reconciliation.
276
+ */
277
+ export declare class MppRetryFailedError extends MppFetchPaymentError {
278
+ /**
279
+ * Completed payment that must not be paid a second time.
280
+ */
281
+ readonly receipt: MppPaymentReceipt;
282
+ constructor(receipt: MppPaymentReceipt, cause: unknown);
283
+ }
284
+ /**
285
+ * Options for the managed MPP fetch wrapper.
286
+ */
287
+ export interface MppFetchOptions {
288
+ /**
289
+ * Catena account whose wallet authorizes payments.
290
+ */
291
+ readonly accountId: string;
292
+ /**
293
+ * Custom fetch transport, defaulting to `globalThis.fetch`.
294
+ */
295
+ readonly baseFetch?: FetchLike;
296
+ /**
297
+ * Maximum acceptable price in atomic USDC units (6 decimals).
298
+ */
299
+ readonly maxAtomicAmount?: bigint;
300
+ /**
301
+ * Called once after payment completes and before the paid retry. The receipt
302
+ * deliberately excludes the MPP credential.
303
+ */
304
+ readonly onPayment?: (receipt: MppPaymentReceipt) => void | Promise<void>;
305
+ }
306
+ /**
307
+ * Create Catena-backed mppx EVM charge methods. The Catena server decides
308
+ * which networks and token contracts are payable. Pass the returned tuple
309
+ * directly in `Mppx.create({ methods: [...] })`.
310
+ */
311
+ export declare const catena: CatenaMppFactory;
312
+ /**
313
+ * Wrap `fetch` with one managed MPP payment attempt. Ordinary responses and
314
+ * 402s without a decodable MPP challenge pass through unchanged. For a
315
+ * supported challenge, the wrapper binds the payment to the final same-origin
316
+ * resource URL, submits one Catena intent at a time, calls `onPayment`, and
317
+ * retries the original request exactly once through the configured Fetch
318
+ * transport with Mppx's credential transport.
319
+ *
320
+ * Stream and consumed `Request` bodies are rejected before payment because
321
+ * they cannot be replayed safely. Once an intent completes, continuation
322
+ * failures throw `MppRetryFailedError`; do not run the payment loop again
323
+ * without first reconciling that receipt's intent.
324
+ */
325
+ export declare function wrapFetchWithMppPayment(client: CatenaClient, options: MppFetchOptions): FetchLike;
326
+ //#endregion
327
+ export type { WalletCounterpartyRail };