@agent-cards/checkout 0.18.0 → 0.21.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 (88) hide show
  1. package/README.md +6 -669
  2. package/cdp.d.ts +1 -0
  3. package/cdp.js +2 -0
  4. package/index.d.ts +1 -0
  5. package/index.js +2 -0
  6. package/package.json +33 -33
  7. package/playwright.d.ts +1 -0
  8. package/playwright.js +2 -0
  9. package/preflight.d.ts +1 -0
  10. package/preflight.js +2 -0
  11. package/CHANGELOG.md +0 -124
  12. package/PREFLIGHT.md +0 -308
  13. package/dist/adyen.generated.d.ts +0 -24
  14. package/dist/adyen.generated.js +0 -64
  15. package/dist/attachment.d.ts +0 -11
  16. package/dist/attachment.js +0 -50
  17. package/dist/braintree.d.ts +0 -2
  18. package/dist/braintree.generated.d.ts +0 -10
  19. package/dist/braintree.generated.js +0 -302
  20. package/dist/braintree.js +0 -2
  21. package/dist/builtin-registry.generated.d.ts +0 -2
  22. package/dist/builtin-registry.generated.js +0 -1
  23. package/dist/card-fields.generated.d.ts +0 -3
  24. package/dist/card-fields.generated.js +0 -46
  25. package/dist/cdp.d.ts +0 -189
  26. package/dist/cdp.js +0 -2194
  27. package/dist/checkout-com.generated.d.ts +0 -4
  28. package/dist/checkout-com.generated.js +0 -183
  29. package/dist/client.d.ts +0 -618
  30. package/dist/client.js +0 -1251
  31. package/dist/hosted-form.d.ts +0 -44
  32. package/dist/hosted-form.js +0 -78
  33. package/dist/index.d.ts +0 -13
  34. package/dist/index.js +0 -6
  35. package/dist/lifecycle.d.ts +0 -165
  36. package/dist/lifecycle.js +0 -370
  37. package/dist/mercado-checkout.d.ts +0 -20
  38. package/dist/mercado-checkout.generated.d.ts +0 -52
  39. package/dist/mercado-checkout.generated.js +0 -198
  40. package/dist/mercado-checkout.js +0 -108
  41. package/dist/owned-shop.generated.d.ts +0 -24
  42. package/dist/owned-shop.generated.js +0 -108
  43. package/dist/paysafe.generated.d.ts +0 -12
  44. package/dist/paysafe.generated.js +0 -87
  45. package/dist/playwright.d.ts +0 -3
  46. package/dist/playwright.js +0 -3
  47. package/dist/preflight-capabilities.generated.d.ts +0 -1253
  48. package/dist/preflight-capabilities.generated.js +0 -1929
  49. package/dist/preflight-catalog.json +0 -4595
  50. package/dist/preflight-playwright.d.ts +0 -34
  51. package/dist/preflight-playwright.js +0 -355
  52. package/dist/preflight-schemas.json +0 -1110
  53. package/dist/preflight.d.ts +0 -1
  54. package/dist/preflight.generated.d.ts +0 -1965
  55. package/dist/preflight.generated.js +0 -556
  56. package/dist/preflight.js +0 -2
  57. package/dist/preparation.d.ts +0 -31
  58. package/dist/preparation.js +0 -164
  59. package/dist/prepared-processor.d.ts +0 -10
  60. package/dist/prepared-processor.js +0 -122
  61. package/dist/recurly.generated.d.ts +0 -1
  62. package/dist/recurly.generated.js +0 -87
  63. package/dist/registry.d.ts +0 -76
  64. package/dist/registry.js +0 -296
  65. package/dist/spreedly.generated.d.ts +0 -10
  66. package/dist/spreedly.generated.js +0 -332
  67. package/dist/stripe-checkout.d.ts +0 -81
  68. package/dist/stripe-checkout.generated.d.ts +0 -82
  69. package/dist/stripe-checkout.generated.js +0 -1004
  70. package/dist/stripe-checkout.js +0 -140
  71. package/dist/substitute.d.ts +0 -38
  72. package/dist/substitute.js +0 -23
  73. package/dist/substitutions.generated.d.ts +0 -10
  74. package/dist/substitutions.generated.js +0 -66
  75. package/examples/existing-browser.mjs +0 -63
  76. package/examples/preflight/classify-direct.mjs +0 -21
  77. package/examples/preflight/classify-kernel.mjs +0 -30
  78. package/examples/preflight/inspect-browser.mjs +0 -44
  79. package/examples/preflight/kernel-native/README.md +0 -112
  80. package/examples/preflight/kernel-native/documented-adapters.json +0 -113
  81. package/examples/preflight/kernel-native/inventory.json +0 -233
  82. package/examples/preflight/kernel-native/qualification.mjs +0 -182
  83. package/examples/preflight/kernel-profile.empty.json +0 -11
  84. package/examples/preflight/mollie-hosted.observations.json +0 -23
  85. package/examples/preflight/mollie-hosted.result.json +0 -103
  86. package/examples/preflight/stripe-script.direct.result.json +0 -92
  87. package/examples/preflight/stripe-script.observations.json +0 -16
  88. package/examples/preflight/stripe-script.result.json +0 -87
package/dist/client.d.ts DELETED
@@ -1,618 +0,0 @@
1
- import { type CheckoutMode, type Recognizer } from './registry.js';
2
- import type { Substitutions } from './substitute.js';
3
- import { type PreparationMode, type PreparationProcessor } from './prepared-processor.js';
4
- export interface PausedRequest {
5
- url: string;
6
- method: string;
7
- headers: Record<string, string>;
8
- body: string;
9
- /** Captured native Checkout Pro initialization, validated before use. */
10
- mercado_checkout?: unknown;
11
- }
12
- /**
13
- * The modes this SDK can finish. Asked for on syncRegistry (the API serves
14
- * only recognizers in these modes, so a request this build cannot complete
15
- * is never paused) and sent on every create.
16
- */
17
- export declare const SUPPORTED_MODES: readonly CheckoutMode[];
18
- /**
19
- * Registry features this SDK honours, asked for on syncRegistry next to the
20
- * modes. `card_fields`: it reads a recognizer's cardFields and claims only a
21
- * request whose body carries the card, so the API may serve it recognizers
22
- * whose endpoints also run without a card. `checkout_sessions`: it lets a
23
- * request the recognizer marks as routine without a card (passWithoutCard)
24
- * through ahead of its holds, so the API may serve Stripe's Checkout Session
25
- * confirm, which hosted Checkout sends after an approval.
26
- */
27
- export declare const SUPPORTED_REGISTRY_FEATURES: readonly string[];
28
- /**
29
- * What the amount on an authorization IS: held to a Stripe PaymentIntent
30
- * (read back at create and before the replay), the parked form's own sum
31
- * (hosted_form: the bytes the device submits name the amount), or a display
32
- * fact on a template that carries no amount.
33
- */
34
- /**
35
- * Who named the amount an authorization carries: `processor` (the paused
36
- * request's own bytes, or the Stripe intent it names, read back by Agentcard),
37
- * `agent` (the `amount` you passed), `page` (the total read off the checkout
38
- * page), or `none` (nobody yet; the processor is read right before the card
39
- * is sent).
40
- */
41
- export type AmountAuthority = 'processor' | 'agent' | 'page' | 'none';
42
- /** An integer in the smallest unit, or a decimal string in normal units with a point; nothing else. */
43
- export declare function validAmountInput(amount: unknown): amount is number | string;
44
- /** How an existing authorization is being handled; omitted by older APIs. */
45
- export interface ExecutionMetadata {
46
- executionMode?: 'user_approval' | 'autopilot';
47
- grantId?: string;
48
- }
49
- /**
50
- * The token flow: the cardholder's device called the processor itself, and
51
- * this is the processor's answer to replay into the paused request.
52
- */
53
- export interface TokenReplay extends ExecutionMetadata {
54
- /** Authenticated selected-card metadata; the processor response body stays unchanged. */
55
- processorContext?: unknown;
56
- /** Present only after validating the native TEST Checkout completion. */
57
- checkoutSessionId?: string;
58
- /** Present only after validating the explicit owned-shop purchase receipt. */
59
- shopOrderId?: string;
60
- /** Absent on older API versions; always 'token' here. */
61
- mode?: 'token';
62
- /** The approved authorization (`cauth_…`). */
63
- authorizationId: string;
64
- status: number;
65
- headers: Record<string, string>;
66
- /** Body to hand back to the browser, verbatim. */
67
- body: string;
68
- /**
69
- * Post-replay reconciliation, when the API has it: whether the amount the
70
- * processor reported charging equals the amount the user approved (null
71
- * when there was nothing to compare, e.g. a tokenization request), and the
72
- * charged pair itself. A `false` here means the approval stood (money had
73
- * moved) and Agentcard also sent your server checkout_authorization.amount_mismatch.
74
- */
75
- amountVerified?: boolean | null;
76
- /** What the processor collected, an integer in the currency's smallest unit (Stripe's `amount`). */
77
- chargedAmount?: number | null;
78
- chargedCurrency?: string | null;
79
- /**
80
- * What `chargedAmount` is: 'captured' (the intent succeeded; this is
81
- * amount_received), 'authorized' (requires_capture; amount_capturable, the
82
- * merchant captures later), 'none' (a PaymentIntent was reported but
83
- * nothing is collected yet: processing, requires_action), or null when no
84
- * PaymentIntent was reported at all (a tokenization request).
85
- */
86
- chargedKind?: 'captured' | 'authorized' | 'none' | null;
87
- /** Who named the amount the person approved. */
88
- amountAuthority?: AmountAuthority;
89
- }
90
- /**
91
- * The cse flow (Adyen): the cardholder's device encrypted the card under the
92
- * processor's public key and reported the ciphertext. Nothing was sent to the
93
- * processor yet: write `substitutions` into the paused body
94
- * (substituteEncryptedFields) and let the request CONTINUE from the browser
95
- * that paused it, so its session data, risk data and cookies stay its own.
96
- * The processor's answer then reaches the page as it normally would; the
97
- * merchant's order state is where the outcome shows up.
98
- */
99
- export interface CseReplay extends ExecutionMetadata {
100
- mode: 'cse';
101
- authorizationId: string;
102
- substitutions: Substitutions;
103
- amountAuthority?: AmountAuthority;
104
- }
105
- /**
106
- * The hosted_form flow (Tranzila): the cardholder's device rebuilt the
107
- * processor's own form with the real card and submitted it itself, top-level,
108
- * at `submittedAt`. The processor answered THE DEVICE, not the browser that
109
- * paused the navigation, so there is no response to replay and no outcome
110
- * here: resolve the paused navigation with hostedFormSubmittedPage() (the
111
- * adapters do), never resubmit the form, and confirm the order with the
112
- * merchant, which learns the outcome from the processor.
113
- *
114
- * THIS IS NOT AN APPROVED PAYMENT. `kind` and `outcome` say so in words so
115
- * no caller mistakes it for one: the API finishes such an authorization as
116
- * `submitted_on_device` (never `approved`) and sends your server
117
- * `checkout_authorization.submitted` (never `.approved`). The stamp is the
118
- * cardholder's device attesting that the form left it; Agentcard holds no
119
- * processor evidence on this mode and cannot obtain any. Treat it as "the
120
- * person paid, or tried to, on their own device" and confirm with the merchant.
121
- */
122
- export interface HostedFormReplay extends ExecutionMetadata {
123
- mode: 'hosted_form';
124
- /** What this resolution is: a device-attested submission, not a processor answer. */
125
- kind: 'submitted_on_device';
126
- /** Always 'unverified': no processor evidence exists for a hosted form. */
127
- outcome: 'unverified';
128
- authorizationId: string;
129
- /** When the device reported the form left it (ISO 8601). */
130
- submittedAt: string;
131
- amountAuthority?: AmountAuthority;
132
- }
133
- /** What authorize() resolves with; branch on `mode` (absent means token). */
134
- export type ReplayResponse = TokenReplay | CseReplay | HostedFormReplay;
135
- export interface PrepareCheckoutOptions {
136
- psp: PreparationProcessor;
137
- /** The processor environment, independent of your Agentcard client's mode. */
138
- environment: 'production' | 'sandbox' | 'shared';
139
- signal?: AbortSignal;
140
- }
141
- export interface PrepareCheckoutInput extends PrepareCheckoutOptions {
142
- user: string;
143
- merchant: string;
144
- /** An integer in the currency's smallest unit (2306 for $23.06), or a decimal string in normal units ("23.06"). */
145
- amount: number | string;
146
- currency: string;
147
- cardId?: string;
148
- merchantOrigin: string;
149
- checkoutKey: string;
150
- timeoutMs?: number;
151
- onPreparationCreated?: (id: string) => void;
152
- onApprovalUrl?: (url: string) => void;
153
- }
154
- /** Real user consent and an unlocked device; no processor request or payment yet. */
155
- export interface PreparedCheckout {
156
- readonly id: string;
157
- readonly status: 'ready';
158
- readonly psp: PreparationProcessor;
159
- readonly environment: 'production' | 'sandbox' | 'shared';
160
- /** How the approved card reaches the processor: ciphertext the device produces (Adyen, `cse`) or the device's own request (`token`). */
161
- readonly mode: PreparationMode;
162
- readonly expiresAt: string;
163
- readonly cardId: string;
164
- readonly user: string;
165
- readonly merchant: string;
166
- /** The approved amount, an integer in the currency's smallest unit, as the API confirmed it. */
167
- readonly amount: number;
168
- readonly amountDisplay: string | null;
169
- readonly currency: string;
170
- readonly merchantOrigin: string;
171
- readonly checkoutKey: string;
172
- readonly paymentStatus: 'not_started';
173
- readonly amountAuthority: 'agent';
174
- }
175
- export declare class CheckoutPreparationError extends Error {
176
- preparationId: string | null;
177
- reason: string;
178
- constructor(preparationId: string | null, reason: string);
179
- }
180
- export interface AuthorizeInput extends ExecutionMetadata {
181
- /** Native Checkout defaults to TEST; LIVE requires this explicit opt-in. */
182
- stripeCheckoutEnvironment?: 'test' | 'production';
183
- /** Observed top-level HTTPS merchant origin; a routing hint, never payment authority. */
184
- merchantOrigin?: string;
185
- /** Your identifier for the person whose card should pay. */
186
- user: string;
187
- /** Shown to the user on the approval screen. Judged by nothing: the merchant comes from the checkout page. */
188
- merchant: string;
189
- /**
190
- * Your hint at the amount: an integer in the currency's smallest unit (2306
191
- * for $23.06), or a decimal string in normal units ("23.06"), with its ISO
192
- * 4217 code ("usd"). Optional: the processor's own amount is the higher
193
- * authority, read from the paused request or from the Stripe intent it
194
- * names right before the cardholder's device replays, and the company's
195
- * caps are judged on it. A hint lets a bad purchase be refused the moment
196
- * you open it, and a hint that disagrees with the processor beyond one
197
- * smallest unit is refused with nothing charged (an AmountMismatchError;
198
- * `stage` says which check). Agentcard derives the display string; you
199
- * never send one. Both or neither: one without the other is refused.
200
- */
201
- amount?: number | string;
202
- currency?: string;
203
- /**
204
- * The total read off the checkout page, the lowest authority: used only
205
- * when neither the processor's request nor your hint names an amount. The
206
- * adapters fill it from `[data-agentcard-amount]` when a page carries one.
207
- */
208
- pageAmount?: {
209
- amount: number;
210
- currency: string;
211
- };
212
- /** Milliseconds from the caller's pay click until the SDK caught the card request, measured on one clock. */
213
- payToInterceptMs?: number;
214
- /**
215
- * WHICH stored card should pay — a vault card id from
216
- * GET /api/v2/vault_cards. The approval page preselects it (the human can
217
- * still override). Omitted: the page defaults to the most recently added
218
- * card. An id that isn't in this user's vault fails the create with a 404
219
- * `card_not_found`.
220
- */
221
- cardId?: string;
222
- /**
223
- * The origin of the checkout page the payment form was on
224
- * (https://shop.example.com). The adapters read it from the page; pass it
225
- * yourself when you run your own interception. With the processor identity
226
- * in the paused request this is what names the merchant for the company's
227
- * presets; `merchant` above is shown to the person and judged by nothing.
228
- */
229
- pageOrigin?: string;
230
- request: PausedRequest;
231
- /** Abort if the user has not approved within this many ms. Default 15 min. */
232
- timeoutMs?: number;
233
- /** Stops local polling; it does not revoke a pending approval or undo a payment. */
234
- signal?: AbortSignal;
235
- /** Adapter-owned merchant request lifetime. A failed request retires a pending approval before replay when possible. */
236
- merchantSignal?: AbortSignal;
237
- /** Called before onApprovalUrl; lets a runtime reconcile an interrupted authorization. */
238
- onAuthorizationCreated?: (authorizationId: string) => void;
239
- /** Called once with the URL to surface to the user, if you deliver it yourself. */
240
- onApprovalUrl?: (url: string) => void;
241
- /** One-use preparation returned by this client. Never resumes an older request. */
242
- preparation?: PreparedCheckout;
243
- }
244
- export declare class CardEncryptedError extends Error {
245
- psp: string;
246
- constructor(psp: string);
247
- }
248
- /**
249
- * The registry requests a mode this SDK build cannot finish, before creation.
250
- * A response in an unexpected mode after creation has an unknown payment
251
- * outcome instead and raises PaymentOutcomeUnknownError.
252
- */
253
- export declare class UnsupportedModeError extends Error {
254
- mode: string;
255
- constructor(mode: string);
256
- }
257
- export declare class ApprovalTimeoutError extends Error {
258
- constructor(ms: number);
259
- }
260
- export declare class CheckoutCancelledError extends Error {
261
- constructor();
262
- }
263
- /** The reasons an org runtime may stamp when it retires an authorization; see VaultClient.cancelAuthorization. */
264
- export type RuntimeCancelReason = 'merchant_request_aborted' | 'merchant_never_retried';
265
- export declare const RUNTIME_CANCEL_REASONS: readonly RuntimeCancelReason[];
266
- /** The payment may have reached the processor. Reconcile the merchant order before any new attempt. */
267
- export declare class PaymentOutcomeUnknownError extends Error {
268
- authorizationId: string | null;
269
- reason: string;
270
- constructor(authorizationId: string | null, reason: string);
271
- }
272
- export declare class ApprovalDeclinedError extends Error {
273
- constructor(reason: string);
274
- }
275
- /**
276
- * Agentcard refused the payment because the processor's amount did not match
277
- * the amount the user was (or would have been) asked to approve. Nothing was
278
- * charged. Two stages:
279
- * - 'create': the intent already disagreed when the request was parked. No
280
- * authorization exists (`authorizationId` is null). Per request, not per
281
- * page: the merchant can still update the intent before confirmation, so
282
- * the adapters keep intercepting and the next attempt is judged afresh.
283
- * - 'pre_replay': the intent moved between create and the moment the
284
- * cardholder's device would have sent the card. The authorization is
285
- * `declined` with reason `amount_mismatch`.
286
- *
287
- * A decline in every structural sense (the adapters abort the paused request
288
- * and quiet the page's retry exactly as for a person's "no"), so it extends
289
- * ApprovalDeclinedError: code that already handles declines keeps working,
290
- * and code that wants the numbers reads them here or branches on `code`.
291
- */
292
- export declare class AmountMismatchError extends ApprovalDeclinedError {
293
- /** The declined authorization, or null for a create-time refusal (no row exists). */
294
- authorizationId: string | null;
295
- /** What the user was asked to approve, smallest currency unit. */
296
- expectedCents: number;
297
- /** What the processor reported at the last check. */
298
- actualCents: number;
299
- /** ISO 4217 of the approved amount. */
300
- currency: string;
301
- /** ISO 4217 the processor reported (differs only on a currency change). */
302
- actualCurrency: string;
303
- /** Which check refused it. */
304
- stage: 'create' | 'pre_replay';
305
- readonly code: "amount_mismatch";
306
- constructor(
307
- /** The declined authorization, or null for a create-time refusal (no row exists). */
308
- authorizationId: string | null,
309
- /** What the user was asked to approve, smallest currency unit. */
310
- expectedCents: number,
311
- /** What the processor reported at the last check. */
312
- actualCents: number,
313
- /** ISO 4217 of the approved amount. */
314
- currency: string,
315
- /** ISO 4217 the processor reported (differs only on a currency change). */
316
- actualCurrency?: string,
317
- /** Which check refused it. */
318
- stage?: 'create' | 'pre_replay');
319
- }
320
- /**
321
- * The PaymentIntent behind this checkout can no longer be confirmed: it was
322
- * already charged (succeeded), is being charged (processing), is authorized
323
- * and on hold for the merchant to capture (requires_capture), or was
324
- * canceled. Agentcard refused rather than replay a confirm at it; the
325
- * authorization is `declined` with reason `intent_not_confirmable`.
326
- * Deliberately NOT "nothing was charged": for three of those four, money has
327
- * moved or is moving. Check the intent at Stripe before retrying.
328
- */
329
- export declare class IntentNotConfirmableError extends ApprovalDeclinedError {
330
- authorizationId: string;
331
- readonly code: "intent_not_confirmable";
332
- constructor(authorizationId: string);
333
- }
334
- /** Bounded processor identifiers, never a raw response or free-form description. */
335
- export interface RazorpayProcessorError {
336
- reason?: string;
337
- source?: string;
338
- step?: string;
339
- payment_id?: string;
340
- order_id?: string;
341
- }
342
- /**
343
- * The device reported a processor request rejection. A generic processor
344
- * code does not establish an issuer decline or prove no money moved. Read
345
- * the bounded processor evidence and reconcile the merchant before retrying.
346
- * The authorization remains `declined` with reason `processor_refused` for
347
- * compatibility; no successful processor response is handed to the merchant.
348
- */
349
- export declare class ProcessorRefusedError extends ApprovalDeclinedError {
350
- authorizationId: string;
351
- pspErrorCode: string | null;
352
- readonly code: "processor_refused";
353
- readonly processorError: RazorpayProcessorError | null;
354
- constructor(authorizationId: string, pspErrorCode: string | null, processorError?: RazorpayProcessorError | null);
355
- }
356
- /**
357
- * A non-2xx from the Agentcard API, carrying the status so callers can tell a
358
- * misconfiguration from a blip. The adapters use this to decide whether
359
- * retrying is worth anything: a 404 `connection_not_found` will answer the same
360
- * way forever, while a 429 or a 502 will not.
361
- */
362
- /**
363
- * The company's preset refused the purchase. The company that runs this
364
- * integration put rules on its users' Vault purchases (a merchant list, a
365
- * currency, a spend cap, a time window); this purchase is outside them.
366
- * Nothing was charged. Two stages:
367
- * - 'create': refused before any authorization existed (`authorizationId`
368
- * is null); nobody was asked to approve. Per purchase, not per page: the
369
- * next request on the same page is judged afresh.
370
- * - 'pre_replay': refused right before the cardholder's device would have
371
- * sent the card; the authorization is `declined` with `code` as reason.
372
- * `code` is the rule's reason (merchant_denied, currency_denied,
373
- * spend_rate_exceeded, time_window_denied, ...), `message` the rule's own
374
- * statement with the company's next step, `preset` the version that judged
375
- * it. When several presets refused the same purchase, `code`, `preset`,
376
- * `rule` and `attachment` are the first, and `refusals` names every one. A
377
- * decline in every structural sense (the adapters quiet the page's retry as
378
- * for a person's "no"), so it extends ApprovalDeclinedError.
379
- */
380
- export declare class PresetRefusedError extends ApprovalDeclinedError {
381
- readonly authorizationId: string | null;
382
- readonly code: string;
383
- readonly detail: string | null;
384
- readonly preset: {
385
- id: string;
386
- version: number;
387
- name: string;
388
- } | null;
389
- readonly rule: string | null;
390
- readonly stage: 'create' | 'pre_replay';
391
- /** The stored card the preset that refused is attached to, with its last four digits. */
392
- readonly attachment: PresetAttachment | null;
393
- /** The preset's name. */
394
- readonly presetName: string | null;
395
- /** Every preset that refused, each with its attachment, rule, code and statement; one entry when one refused. */
396
- readonly refusals: readonly PresetRefusal[];
397
- constructor(authorizationId: string | null, code: string, detail: string | null, preset: {
398
- id: string;
399
- version: number;
400
- name: string;
401
- } | null, rule: string | null, stage: 'create' | 'pre_replay',
402
- /** The stored card the preset that refused is attached to, with its last four digits. */
403
- attachment?: PresetAttachment | null, refusals?: readonly PresetRefusal[]);
404
- }
405
- /** The stored card a preset is attached to, with its last four digits. */
406
- export interface PresetAttachment {
407
- kind: 'card';
408
- targetId: string | null;
409
- last4: string | null;
410
- }
411
- /** One preset's refusal of a purchase. */
412
- export interface PresetRefusal {
413
- preset: {
414
- id: string;
415
- version: number;
416
- name: string;
417
- };
418
- attachment: PresetAttachment | null;
419
- rule: string | null;
420
- code: string;
421
- detail: string | null;
422
- }
423
- /** A decline reason only the company presets stamp (see PresetRefusedError). */
424
- export declare const PRESET_REFUSAL_REASONS: ReadonlySet<string>;
425
- export declare class CheckoutApiError extends Error {
426
- status: number;
427
- path: string;
428
- bodyText: string;
429
- /** The API's stable error code (`{ error: { code } }`), or null when the body carried none. */
430
- readonly code: string | null;
431
- /**
432
- * The rest of the error envelope. A 409 `amount_mismatch` from create
433
- * carries `expected_cents`, `actual_cents`, `currency`, `actual_currency`;
434
- * an `amount_unverifiable` carries `reason`; an `intent_not_confirmable`
435
- * carries `intent_status`.
436
- */
437
- readonly details: Record<string, unknown>;
438
- constructor(status: number, path: string, bodyText: string);
439
- /**
440
- * True when repeating this exact call cannot succeed: a misconfiguration
441
- * (4xx other than 429). NOT a 409 `amount_mismatch`: Stripe lets a merchant
442
- * update an intent's amount until it is confirmed, so the next request on
443
- * the same page may well agree. That one is a per-request failure, and
444
- * authorize() surfaces it as AmountMismatchError before an adapter ever
445
- * sees it here. NOT a 409 `duplicate_submission` either: the household
446
- * already has, or already answered, the prompt for this submission, and
447
- * once that prior authorization is declined or expired the same form is a
448
- * new question. The adapters quiet the page's re-post the way they quiet a
449
- * decline instead of latching the attachment.
450
- */
451
- get permanent(): boolean;
452
- }
453
- /**
454
- * A URL as it may appear in an error message: origin + path only. A paused
455
- * request's URL can carry a client secret in its query string, and error
456
- * messages travel further than anyone intends (onEvent, logs, crash reports).
457
- */
458
- export declare function redactUrl(raw: string): string;
459
- export interface VaultClientOptions {
460
- /**
461
- * Your Agentcard OAuth client credentials. The SDK exchanges them for a
462
- * short-lived access token and refreshes it when it expires.
463
- *
464
- * NOT an `sk_` API key: those are retired, and the checkout endpoints reject
465
- * them with `client_credentials_required` because an authorization has to be
466
- * bound to the confidential client that created it.
467
- */
468
- clientId: string;
469
- clientSecret: string;
470
- baseUrl?: string;
471
- /** Override the PSP registry (tests, or pinning). Defaults to the hosted list. */
472
- registry?: Recognizer[];
473
- fetchImpl?: typeof fetch;
474
- /** Receives contained reporting failures that do not change checkout behavior. */
475
- onEvent?: (event: {
476
- type: string;
477
- detail?: unknown;
478
- }) => void;
479
- pollIntervalMs?: number;
480
- /**
481
- * Waits before retrying a create the API answered 502 `amount_unverifiable`
482
- * (Stripe did not answer the amount read-back) or 502 `cse_key_unavailable`
483
- * (Adyen did not answer the public-key fetch). One retry per entry, then
484
- * the error is thrown. Default [500, 1500]; [] disables retries.
485
- */
486
- unverifiableRetryDelaysMs?: number[];
487
- }
488
- export declare class VaultClient {
489
- private readonly opts;
490
- private readonly baseUrl;
491
- private readonly fetch;
492
- private readonly pollIntervalMs;
493
- private readonly unverifiableRetryDelaysMs;
494
- private registry;
495
- private readonly preparations;
496
- private readonly usedPreparations;
497
- constructor(opts: VaultClientOptions);
498
- /** Refresh recognizers from the API so new PSPs work without a redeploy. */
499
- syncRegistry(): Promise<void>;
500
- /** True when this request is a card tokenization we can take over. */
501
- isCardRequest(url: string, method?: string): boolean;
502
- /**
503
- * What happens to a card request (by URL) whose body carries no card: null
504
- * when it carries one, so it is a card request as usual; 'continue' when the
505
- * recognizer marks the endpoint as one where such requests are routine and
506
- * never ours; 'refuse' otherwise, such as a Stripe confirmation paying with
507
- * a method this checkout never approved. The adapters ask only after their
508
- * holds, so a request that would reuse an approved token is refused there
509
- * first. A body that could not be read is not judged here.
510
- */
511
- withoutCard(url: string, body: string | null | undefined): 'continue' | 'refuse' | null;
512
- /**
513
- * How the card would reach the processor on this request (`token`, `cse`
514
- * or `hosted_form`; absent on the entry means `token`), or null when the
515
- * registry does not recognize it. The adapters read it to decide whether an
516
- * approval outlives the page's own request: a hosted form is a navigation
517
- * and cannot.
518
- */
519
- checkoutModeOf(url: string, method?: string): CheckoutMode | null;
520
- /**
521
- * Glob url patterns covering every host the CURRENT registry can send a card
522
- * to — what a raw CDP connection has to hand `Fetch.enable` before any card
523
- * request can be paused. attachToCdp calls this for you.
524
- *
525
- * Call syncRegistry() FIRST: without it these cover only the built-in PSPs,
526
- * and a request the API knows about is never paused at all. Deliberately
527
- * WIDER than the recognizers themselves (a glob cannot express an anchored
528
- * host regex); isCardRequest is the exact check and runs on every request
529
- * these patterns pause.
530
- */
531
- cardUrlPatterns(): string[];
532
- /** Wait for real device approval before the caller starts native tokenization. */
533
- prepareCheckout(input: PrepareCheckoutInput): Promise<PreparedCheckout>;
534
- /** Cancel only an unconsumed preparation; a bound request is reconciled separately. */
535
- cancelPreparation(id: string): Promise<void>;
536
- observePreparation(id: string, guidance: 'presented_not_filled' | 'not_presented', reason?: string): Promise<void>;
537
- reportDuplicateGuard(authorizationId: string): Promise<void>;
538
- /**
539
- * Hand us a paused tokenization request. We ask the cardholder to approve,
540
- * their device supplies the card and calls the merchant, and you get back the
541
- * response to replay into the browser. Your process never sees a card.
542
- */
543
- authorize(input: AuthorizeInput): Promise<ReplayResponse>;
544
- /** A lost bind acknowledgement must never resume the request. Recover metadata only for safe cleanup. */
545
- private retireUncertainPreparation;
546
- /**
547
- * Retire an authorization the runtime is done with. A 409 or missing
548
- * response remains unknown.
549
- *
550
- * `merchant_request_aborted` (the default): the merchant request is gone
551
- * and the row must still be awaiting the person with no replay started; the
552
- * acknowledgement carries `processor_request_started: false`.
553
- *
554
- * `merchant_never_retried`: the page abandoned its request while the person
555
- * decided, the adapter kept the approval for the page's retry, and none
556
- * came. The row may already be `approved` (a token or ciphertext minted on
557
- * the device that this runtime handed to no request), so
558
- * `processor_request_started` says whether the processor was asked; the API
559
- * stamps this reason only where no charge can have been made and answers
560
- * 409 otherwise. The acknowledgement echoes the reason the row actually
561
- * carries: a row retired earlier under the other runtime reason answers
562
- * with that one.
563
- */
564
- cancelAuthorization(authorizationId: string, reason?: RuntimeCancelReason): Promise<{
565
- id: string;
566
- status: 'declined';
567
- reason: RuntimeCancelReason;
568
- cancelled: true;
569
- processor_request_started: boolean;
570
- }>;
571
- /**
572
- * Ask whether the page may pay with the Stripe card token an approval
573
- * produced: a PaymentIntent confirm that carries no card and pays with
574
- * exactly the approved payment method, card token, confirmation token or
575
- * source. The API reads the payment from Stripe and answers only for the
576
- * approved amount and currency on the same Stripe account; any other answer
577
- * rejects with a CheckoutApiError whose code says why (for example
578
- * `continuation_not_bound`, `amount_mismatch`). Nothing is charged here:
579
- * the adapters continue the page's own request once this resolves.
580
- */
581
- checkStripeContinuation(authorizationId: string, request: {
582
- url: string;
583
- method: string;
584
- headers: Record<string, string>;
585
- body: string;
586
- }): Promise<{
587
- paymentIntentId: string;
588
- amount: number;
589
- currency: string;
590
- }>;
591
- /**
592
- * POST the create, with two typed twists: a 502 `amount_unverifiable`
593
- * (Stripe did not answer the read-back) is retried on a short backoff
594
- * instead of being left to the page's own retry loop, and a 409
595
- * `amount_mismatch` becomes an AmountMismatchError at stage 'create' so the
596
- * adapters treat it as an answered request, not a dead page.
597
- */
598
- private createAuthorization;
599
- private token;
600
- private inflight;
601
- /**
602
- * Exchange client credentials for an access token, reusing the cached one
603
- * until it is nearly expired. Concurrent callers share a single in-flight
604
- * exchange rather than each minting their own token.
605
- */
606
- private accessToken;
607
- /**
608
- * A preparation status read may retry two known connection failures, after
609
- * 250ms and 500ms, while keeping its original approval deadline and signal.
610
- * Only fetch and a successful response's body read belong to that retry:
611
- * OAuth, HTTP errors, invalid JSON and every mutation remain outside it.
612
- * The existing one-time 401 refresh carries the remaining read budget.
613
- */
614
- private call;
615
- private post;
616
- private get;
617
- private readPreparation;
618
- }