@agent-cards/checkout 0.19.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 (106) hide show
  1. package/README.md +6 -753
  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 -132
  12. package/PREFLIGHT.md +0 -312
  13. package/dist/adyen-merchant-hosted.generated.d.ts +0 -277
  14. package/dist/adyen-merchant-hosted.generated.js +0 -1902
  15. package/dist/adyen.generated.d.ts +0 -24
  16. package/dist/adyen.generated.js +0 -64
  17. package/dist/attachment.d.ts +0 -11
  18. package/dist/attachment.js +0 -50
  19. package/dist/braintree.d.ts +0 -2
  20. package/dist/braintree.generated.d.ts +0 -10
  21. package/dist/braintree.generated.js +0 -302
  22. package/dist/braintree.js +0 -2
  23. package/dist/builtin-registry.generated.d.ts +0 -2
  24. package/dist/builtin-registry.generated.js +0 -1
  25. package/dist/card-fields.generated.d.ts +0 -3
  26. package/dist/card-fields.generated.js +0 -46
  27. package/dist/cdp.d.ts +0 -192
  28. package/dist/cdp.js +0 -2393
  29. package/dist/checkout-com.generated.d.ts +0 -4
  30. package/dist/checkout-com.generated.js +0 -183
  31. package/dist/client.d.ts +0 -849
  32. package/dist/client.js +0 -1754
  33. package/dist/cse-body.d.ts +0 -25
  34. package/dist/cse-body.js +0 -41
  35. package/dist/fiserv.d.ts +0 -65
  36. package/dist/fiserv.generated.d.ts +0 -73
  37. package/dist/fiserv.generated.js +0 -830
  38. package/dist/fiserv.js +0 -104
  39. package/dist/hosted-form.d.ts +0 -44
  40. package/dist/hosted-form.js +0 -78
  41. package/dist/index.d.ts +0 -18
  42. package/dist/index.js +0 -10
  43. package/dist/lifecycle.d.ts +0 -179
  44. package/dist/lifecycle.js +0 -395
  45. package/dist/mercado-checkout.d.ts +0 -20
  46. package/dist/mercado-checkout.generated.d.ts +0 -52
  47. package/dist/mercado-checkout.generated.js +0 -198
  48. package/dist/mercado-checkout.js +0 -108
  49. package/dist/merchant-handoff.d.ts +0 -54
  50. package/dist/merchant-handoff.js +0 -100
  51. package/dist/merchant-hosted.d.ts +0 -140
  52. package/dist/merchant-hosted.js +0 -170
  53. package/dist/merchant-total-watch.d.ts +0 -115
  54. package/dist/merchant-total-watch.js +0 -268
  55. package/dist/merchant-total.d.ts +0 -257
  56. package/dist/merchant-total.js +0 -383
  57. package/dist/owned-shop.generated.d.ts +0 -24
  58. package/dist/owned-shop.generated.js +0 -108
  59. package/dist/paysafe.generated.d.ts +0 -12
  60. package/dist/paysafe.generated.js +0 -87
  61. package/dist/playwright.d.ts +0 -3
  62. package/dist/playwright.js +0 -3
  63. package/dist/pre-claim.d.ts +0 -123
  64. package/dist/pre-claim.js +0 -386
  65. package/dist/preflight-capabilities.generated.d.ts +0 -1253
  66. package/dist/preflight-capabilities.generated.js +0 -1929
  67. package/dist/preflight-catalog.json +0 -4727
  68. package/dist/preflight-playwright.d.ts +0 -34
  69. package/dist/preflight-playwright.js +0 -355
  70. package/dist/preflight-schemas.json +0 -1122
  71. package/dist/preflight.d.ts +0 -1
  72. package/dist/preflight.generated.d.ts +0 -1965
  73. package/dist/preflight.generated.js +0 -570
  74. package/dist/preflight.js +0 -2
  75. package/dist/preparation.d.ts +0 -38
  76. package/dist/preparation.js +0 -191
  77. package/dist/prepared-processor.d.ts +0 -43
  78. package/dist/prepared-processor.js +0 -172
  79. package/dist/recurly.generated.d.ts +0 -1
  80. package/dist/recurly.generated.js +0 -87
  81. package/dist/registry.d.ts +0 -121
  82. package/dist/registry.js +0 -310
  83. package/dist/spreedly.generated.d.ts +0 -10
  84. package/dist/spreedly.generated.js +0 -332
  85. package/dist/stripe-checkout.d.ts +0 -81
  86. package/dist/stripe-checkout.generated.d.ts +0 -82
  87. package/dist/stripe-checkout.generated.js +0 -1093
  88. package/dist/stripe-checkout.js +0 -140
  89. package/dist/substitute.d.ts +0 -38
  90. package/dist/substitute.js +0 -23
  91. package/dist/substitutions.generated.d.ts +0 -11
  92. package/dist/substitutions.generated.js +0 -818
  93. package/examples/existing-browser.mjs +0 -63
  94. package/examples/preflight/classify-direct.mjs +0 -21
  95. package/examples/preflight/classify-kernel.mjs +0 -30
  96. package/examples/preflight/inspect-browser.mjs +0 -44
  97. package/examples/preflight/kernel-native/README.md +0 -112
  98. package/examples/preflight/kernel-native/documented-adapters.json +0 -113
  99. package/examples/preflight/kernel-native/inventory.json +0 -233
  100. package/examples/preflight/kernel-native/qualification.mjs +0 -182
  101. package/examples/preflight/kernel-profile.empty.json +0 -11
  102. package/examples/preflight/mollie-hosted.observations.json +0 -23
  103. package/examples/preflight/mollie-hosted.result.json +0 -103
  104. package/examples/preflight/stripe-script.direct.result.json +0 -92
  105. package/examples/preflight/stripe-script.observations.json +0 -16
  106. package/examples/preflight/stripe-script.result.json +0 -87
package/dist/client.d.ts DELETED
@@ -1,849 +0,0 @@
1
- import { type CheckoutMode, type Recognizer } from './registry.js';
2
- import type { Substitutions } from './substitute.js';
3
- import { type MerchantHostedSubstitutions, type MerchantProfile, type SandboxMerchantDeclaration } from './merchant-hosted.js';
4
- import { type MerchantTotalApproved, type MerchantTotalCapture } from './merchant-total.js';
5
- import { type PreparationMode, type PreparationProcessor } from './prepared-processor.js';
6
- export interface PausedRequest {
7
- url: string;
8
- method: string;
9
- headers: Record<string, string>;
10
- body: string;
11
- /** Captured native Checkout Pro initialization, validated before use. */
12
- mercado_checkout?: unknown;
13
- }
14
- /**
15
- * The modes this SDK can finish. Asked for on syncRegistry (the API serves
16
- * only recognizers in these modes, so a request this build cannot complete
17
- * is never paused) and sent on every create.
18
- */
19
- export declare const SUPPORTED_MODES: readonly CheckoutMode[];
20
- /**
21
- * Registry features this SDK honours, asked for on syncRegistry next to the
22
- * modes. `card_fields`: it reads a recognizer's cardFields and claims only a
23
- * request whose body carries the card, so the API may serve it recognizers
24
- * whose endpoints also run without a card. `checkout_sessions`: it lets a
25
- * request the recognizer marks as routine without a card (passWithoutCard)
26
- * through ahead of its holds, so the API may serve Stripe's Checkout Session
27
- * confirm, which hosted Checkout sends after an approval.
28
- */
29
- export declare const SUPPORTED_REGISTRY_FEATURES: readonly string[];
30
- /**
31
- * Dark-launch capabilities this build can finish. Sent on syncRegistry as
32
- * ?capabilities= so the API also serves the recognizers gated behind one of
33
- * these. `fiserv_card_capture`: Fiserv Commerce Hub's Secure Data Capture card
34
- * capture, which this build pauses and pays only through a prepared checkout
35
- * (pre-claim.ts, fiserv.ts). The API serves Fiserv's recognizer only to a build
36
- * that lists it and only for a company Agentcard turned Fiserv on for, so an older
37
- * SDK never pauses a capture it cannot finish and no SDK pauses one for a company
38
- * Fiserv is off for; the API also refuses a Fiserv payment for every such company.
39
- */
40
- export declare const SUPPORTED_CAPABILITIES: readonly string[];
41
- /**
42
- * What the amount on an authorization IS: held to a Stripe PaymentIntent
43
- * (read back at create and before the replay), the parked form's own sum
44
- * (hosted_form: the bytes the device submits name the amount), or a display
45
- * fact on a template that carries no amount.
46
- */
47
- /**
48
- * Who named the amount an authorization carries: `processor` (the paused
49
- * request's own bytes, or the Stripe intent it names, read back by Agentcard),
50
- * `agent` (the `amount` you passed), `page` (the total read off the checkout
51
- * page), or `none` (nobody yet; the processor is read right before the card
52
- * is sent).
53
- */
54
- export type AmountAuthority = 'processor' | 'agent' | 'page' | 'none';
55
- /** An integer in the smallest unit, or a decimal string in normal units with a point; nothing else. */
56
- export declare function validAmountInput(amount: unknown): amount is number | string;
57
- /** How an existing authorization is being handled; omitted by older APIs. */
58
- export interface ExecutionMetadata {
59
- executionMode?: 'user_approval' | 'autopilot';
60
- grantId?: string;
61
- }
62
- /**
63
- * The token flow: the cardholder's device called the processor itself, and
64
- * this is the processor's answer to replay into the paused request.
65
- */
66
- export interface TokenReplay extends ExecutionMetadata {
67
- /** Authenticated selected-card metadata; the processor response body stays unchanged. */
68
- processorContext?: unknown;
69
- /** Present only after validating the native TEST Checkout completion. */
70
- checkoutSessionId?: string;
71
- /** Present only after validating the explicit owned-shop purchase receipt. */
72
- shopOrderId?: string;
73
- /** Absent on older API versions; always 'token' here. */
74
- mode?: 'token';
75
- /** The approved authorization (`cauth_…`). */
76
- authorizationId: string;
77
- status: number;
78
- headers: Record<string, string>;
79
- /** Body to hand back to the browser, verbatim. */
80
- body: string;
81
- /**
82
- * Post-replay reconciliation, when the API has it: whether the amount the
83
- * processor reported charging equals the amount the user approved (null
84
- * when there was nothing to compare, e.g. a tokenization request), and the
85
- * charged pair itself. A `false` here means the approval stood (money had
86
- * moved) and Agentcard also sent your server checkout_authorization.amount_mismatch.
87
- */
88
- amountVerified?: boolean | null;
89
- /** What the processor collected, an integer in the currency's smallest unit (Stripe's `amount`). */
90
- chargedAmount?: number | null;
91
- chargedCurrency?: string | null;
92
- /**
93
- * What `chargedAmount` is: 'captured' (the intent succeeded; this is
94
- * amount_received), 'authorized' (requires_capture; amount_capturable, the
95
- * merchant captures later), 'none' (a PaymentIntent was reported but
96
- * nothing is collected yet: processing, requires_action), or null when no
97
- * PaymentIntent was reported at all (a tokenization request).
98
- */
99
- chargedKind?: 'captured' | 'authorized' | 'none' | null;
100
- /** Who named the amount the person approved. */
101
- amountAuthority?: AmountAuthority;
102
- }
103
- /**
104
- * The cse flow (Adyen): the cardholder's device encrypted the card under the
105
- * processor's public key and reported the ciphertext. Nothing was sent to the
106
- * processor yet: write `substitutions` into the paused body
107
- * (substituteEncryptedFields) and let the request CONTINUE from the browser
108
- * that paused it, so its session data, risk data and cookies stay its own.
109
- * The processor's answer then reaches the page as it normally would; the
110
- * merchant's order state is where the outcome shows up. A Fiserv card capture
111
- * (a prepared checkout only) carries its envelope at `source.encryptionData`:
112
- * write it with substituteFiservEnvelope, never substituteEncryptedFields.
113
- */
114
- export interface CseReplay extends ExecutionMetadata {
115
- mode: 'cse';
116
- /** Absent on a processor-hosted cse approval; see MerchantHostedReplay. */
117
- kind?: undefined;
118
- authorizationId: string;
119
- substitutions: Substitutions;
120
- amountAuthority?: AmountAuthority;
121
- }
122
- /**
123
- * The cse flow at an Adyen merchant's OWN endpoint (a reviewed merchant
124
- * profile, see merchant-hosted.ts): the cardholder's device encrypted the card
125
- * under the key Agentcard reviewed for that merchant, and nothing was sent. The
126
- * paused request continues from this browser with the ciphertext written where
127
- * the profile holds it (substituteMerchantHostedBody), and only when the live
128
- * body still hashes to `bodySha256`, the body the API checked at create. The
129
- * merchant's server charges the card and answers its own page; its order state is
130
- * the outcome. Only a prepared checkout pays one, never Autopilot.
131
- */
132
- export interface MerchantHostedReplay extends ExecutionMetadata {
133
- mode: 'cse';
134
- kind: 'merchant_hosted';
135
- authorizationId: string;
136
- /** The reviewed merchant profile the approval pays. */
137
- profile: string;
138
- substitutions: MerchantHostedSubstitutions;
139
- /** SHA-256 (lowercase hex) of the paused body the API checked at create. */
140
- bodySha256: string;
141
- /** When the API stops serving this ciphertext, if it said. */
142
- substitutionsExpiresAt: string | null;
143
- /** Present when the approval pays this client's own sandbox declaration (VaultClientOptions.sandboxMerchants). */
144
- sandboxDeclaration?: Readonly<{
145
- endpoint: string;
146
- clientKey: string;
147
- }>;
148
- /**
149
- * The merchant's own total this approval was created at, when its profile is priced by
150
- * one: the adapters read it again at release (merchantTotalAtRelease) and hold the card
151
- * request unless it is still this amount, then report what the merchant says it charged.
152
- */
153
- merchantTotal?: MerchantTotalApproved;
154
- amountAuthority?: AmountAuthority;
155
- }
156
- /**
157
- * The hosted_form flow (Tranzila): the cardholder's device rebuilt the
158
- * processor's own form with the real card and submitted it itself, top-level,
159
- * at `submittedAt`. The processor answered THE DEVICE, not the browser that
160
- * paused the navigation, so there is no response to replay and no outcome
161
- * here: resolve the paused navigation with hostedFormSubmittedPage() (the
162
- * adapters do), never resubmit the form, and confirm the order with the
163
- * merchant, which learns the outcome from the processor.
164
- *
165
- * THIS IS NOT AN APPROVED PAYMENT. `kind` and `outcome` say so in words so
166
- * no caller mistakes it for one: the API finishes such an authorization as
167
- * `submitted_on_device` (never `approved`) and sends your server
168
- * `checkout_authorization.submitted` (never `.approved`). The stamp is the
169
- * cardholder's device attesting that the form left it; Agentcard holds no
170
- * processor evidence on this mode and cannot obtain any. Treat it as "the
171
- * person paid, or tried to, on their own device" and confirm with the merchant.
172
- */
173
- export interface HostedFormReplay extends ExecutionMetadata {
174
- mode: 'hosted_form';
175
- /** What this resolution is: a device-attested submission, not a processor answer. */
176
- kind: 'submitted_on_device';
177
- /** Always 'unverified': no processor evidence exists for a hosted form. */
178
- outcome: 'unverified';
179
- authorizationId: string;
180
- /** When the device reported the form left it (ISO 8601). */
181
- submittedAt: string;
182
- amountAuthority?: AmountAuthority;
183
- }
184
- /** What authorize() resolves with; branch on `mode` (absent means token). */
185
- export type ReplayResponse = TokenReplay | CseReplay | MerchantHostedReplay | HostedFormReplay;
186
- export interface PrepareCheckoutOptions {
187
- psp: PreparationProcessor;
188
- /** The processor environment, independent of your Agentcard client's mode. */
189
- environment: 'production' | 'sandbox' | 'shared';
190
- /**
191
- * An Adyen merchant that takes the card on its own server: the id of the
192
- * profile Agentcard reviewed for it (psp 'adyen'; the environment is the
193
- * profile's). The profile must be enabled on this client (syncRegistry); its
194
- * card request is then the one request this preparation pays.
195
- *
196
- * A Fiserv checkout (psp 'fiserv'): the id of the key Agentcard pinned for the
197
- * merchant, `agentcard_sandbox` in the sandbox environment. Required for Fiserv,
198
- * and refused for every processor but Adyen and Fiserv. The cardholder is asked to
199
- * approve a payment to the merchant that key belongs to, so the checkout's `merchant`
200
- * must be that merchant's name (`Agentcard sandbox` for `agentcard_sandbox`), and the
201
- * one card capture this preparation pays must carry an envelope under that key.
202
- */
203
- merchantProfile?: string;
204
- signal?: AbortSignal;
205
- }
206
- export interface PrepareCheckoutInput extends PrepareCheckoutOptions {
207
- user: string;
208
- merchant: string;
209
- /** An integer in the currency's smallest unit (2306 for $23.06), or a decimal string in normal units ("23.06"). */
210
- amount: number | string;
211
- currency: string;
212
- cardId?: string;
213
- merchantOrigin: string;
214
- checkoutKey: string;
215
- timeoutMs?: number;
216
- onPreparationCreated?: (id: string) => void;
217
- onApprovalUrl?: (url: string) => void;
218
- }
219
- /** Real user consent and an unlocked device; no processor request or payment yet. */
220
- export interface PreparedCheckout {
221
- readonly id: string;
222
- readonly status: 'ready';
223
- readonly psp: PreparationProcessor;
224
- readonly environment: 'production' | 'sandbox' | 'shared';
225
- /** How the approved card reaches the processor: ciphertext the device produces (Adyen, `cse`) or the device's own request (`token`). */
226
- readonly mode: PreparationMode;
227
- readonly expiresAt: string;
228
- readonly cardId: string;
229
- readonly user: string;
230
- readonly merchant: string;
231
- /** The approved amount, an integer in the currency's smallest unit, as the API confirmed it. */
232
- readonly amount: number;
233
- readonly amountDisplay: string | null;
234
- readonly currency: string;
235
- readonly merchantOrigin: string;
236
- readonly checkoutKey: string;
237
- readonly paymentStatus: 'not_started';
238
- readonly amountAuthority: 'agent';
239
- /** The reviewed merchant profile this preparation pays, or the Fiserv key pin it pays under; absent for a processor-hosted checkout. */
240
- readonly merchantProfile?: string;
241
- /** The declared test endpoint and key this preparation pays instead of the profile's (VaultClientOptions.sandboxMerchants). */
242
- readonly sandboxDeclaration?: Readonly<{
243
- endpoint: string;
244
- clientKey: string;
245
- }>;
246
- }
247
- export declare class CheckoutPreparationError extends Error {
248
- preparationId: string | null;
249
- reason: string;
250
- constructor(preparationId: string | null, reason: string);
251
- }
252
- export interface AuthorizeInput extends ExecutionMetadata {
253
- /** Native Checkout defaults to TEST; LIVE requires this explicit opt-in. */
254
- stripeCheckoutEnvironment?: 'test' | 'production';
255
- /** Observed top-level HTTPS merchant origin; a routing hint, never payment authority. */
256
- merchantOrigin?: string;
257
- /** Your identifier for the person whose card should pay. */
258
- user: string;
259
- /** Shown to the user on the approval screen. Judged by nothing: the merchant comes from the checkout page. */
260
- merchant: string;
261
- /**
262
- * Your hint at the amount: an integer in the currency's smallest unit (2306
263
- * for $23.06), or a decimal string in normal units ("23.06"), with its ISO
264
- * 4217 code ("usd"). Optional: the processor's own amount is the higher
265
- * authority, read from the paused request or from the Stripe intent it
266
- * names right before the cardholder's device replays, and the company's
267
- * caps are judged on it. A hint lets a bad purchase be refused the moment
268
- * you open it, and a hint that disagrees with the processor beyond one
269
- * smallest unit is refused with nothing charged (an AmountMismatchError;
270
- * `stage` says which check). Agentcard derives the display string; you
271
- * never send one. Both or neither: one without the other is refused.
272
- */
273
- amount?: number | string;
274
- currency?: string;
275
- /**
276
- * The total read off the checkout page, the lowest authority: used only
277
- * when neither the processor's request nor your hint names an amount. The
278
- * adapters fill it from `[data-agentcard-amount]` when a page carries one.
279
- */
280
- pageAmount?: {
281
- amount: number;
282
- currency: string;
283
- };
284
- /** Milliseconds from the caller's pay click until the SDK caught the card request, measured on one clock. */
285
- payToInterceptMs?: number;
286
- /**
287
- * WHICH stored card should pay — a vault card id from
288
- * GET /api/v2/vault_cards. The approval page preselects it (the human can
289
- * still override). Omitted: the page defaults to the most recently added
290
- * card. An id that isn't in this user's vault fails the create with a 404
291
- * `card_not_found`.
292
- */
293
- cardId?: string;
294
- /**
295
- * The origin of the checkout page the payment form was on
296
- * (https://shop.example.com). The adapters read it from the page; pass it
297
- * yourself when you run your own interception. With the processor identity
298
- * in the paused request this is what names the merchant for the company's
299
- * presets; `merchant` above is shown to the person and judged by nothing.
300
- */
301
- pageOrigin?: string;
302
- request: PausedRequest;
303
- /** Abort if the user has not approved within this many ms. Default 15 min. */
304
- timeoutMs?: number;
305
- /** Stops local polling; it does not revoke a pending approval or undo a payment. */
306
- signal?: AbortSignal;
307
- /** Adapter-owned merchant request lifetime. A failed request retires a pending approval before replay when possible. */
308
- merchantSignal?: AbortSignal;
309
- /** Called before onApprovalUrl; lets a runtime reconcile an interrupted authorization. */
310
- onAuthorizationCreated?: (authorizationId: string) => void;
311
- /** Called once with the URL to surface to the user, if you deliver it yourself. */
312
- onApprovalUrl?: (url: string) => void;
313
- /** One-use preparation returned by this client. Never resumes an older request. */
314
- preparation?: PreparedCheckout;
315
- /**
316
- * For a reviewed merchant profile priced by the merchant's own total: when the card
317
- * request paused and the merchant responses this browser recorded (see
318
- * merchant-total.ts). The adapters pass it; a runtime that intercepts on its own builds
319
- * one from its network events, or the payment is refused before any create.
320
- */
321
- merchantTotal?: MerchantTotalCapture;
322
- }
323
- export declare class CardEncryptedError extends Error {
324
- psp: string;
325
- constructor(psp: string);
326
- }
327
- /**
328
- * The registry requests a mode this SDK build cannot finish, before creation.
329
- * A response in an unexpected mode after creation has an unknown payment
330
- * outcome instead and raises PaymentOutcomeUnknownError.
331
- */
332
- export declare class UnsupportedModeError extends Error {
333
- mode: string;
334
- constructor(mode: string);
335
- }
336
- /**
337
- * The recognizer says this processor is preparation-required, and no preparation
338
- * was passed. Its card may be sent only after the cardholder approved a
339
- * prepare(): call prepareCheckout() (or the adapters' preparation gate) before
340
- * this request is intercepted. Thrown locally before any create or prompt, and
341
- * terminal (retrying the same paused request without preparing fails the same
342
- * way). The API answers 409 preparation_required for the same case.
343
- */
344
- export declare class PreparationRequiredError extends Error {
345
- psp: string;
346
- constructor(psp: string);
347
- }
348
- export declare class ApprovalTimeoutError extends Error {
349
- constructor(ms: number);
350
- }
351
- export declare class CheckoutCancelledError extends Error {
352
- constructor();
353
- }
354
- /** The reasons an org runtime may stamp when it retires an authorization; see VaultClient.cancelAuthorization. */
355
- export type RuntimeCancelReason = 'merchant_request_aborted' | 'merchant_never_retried';
356
- export declare const RUNTIME_CANCEL_REASONS: readonly RuntimeCancelReason[];
357
- /** The payment may have reached the processor. Reconcile the merchant order before any new attempt. */
358
- export declare class PaymentOutcomeUnknownError extends Error {
359
- authorizationId: string | null;
360
- reason: string;
361
- constructor(authorizationId: string | null, reason: string);
362
- }
363
- export declare class ApprovalDeclinedError extends Error {
364
- constructor(reason: string);
365
- }
366
- /**
367
- * Agentcard refused the payment because the processor's amount did not match
368
- * the amount the user was (or would have been) asked to approve. Nothing was
369
- * charged. Two stages:
370
- * - 'create': the intent already disagreed when the request was parked. No
371
- * authorization exists (`authorizationId` is null). Per request, not per
372
- * page: the merchant can still update the intent before confirmation, so
373
- * the adapters keep intercepting and the next attempt is judged afresh.
374
- * - 'pre_replay': the intent moved between create and the moment the
375
- * cardholder's device would have sent the card. The authorization is
376
- * `declined` with reason `amount_mismatch`.
377
- *
378
- * A decline in every structural sense (the adapters abort the paused request
379
- * and quiet the page's retry exactly as for a person's "no"), so it extends
380
- * ApprovalDeclinedError: code that already handles declines keeps working,
381
- * and code that wants the numbers reads them here or branches on `code`.
382
- *
383
- * A merchant-hosted checkout (an Adyen merchant whose own server charges the card)
384
- * has no processor read-back: its agent amount is held to the merchant's own
385
- * checkout total, as the agent's browser read it, at stage 'create'. The SDK refuses
386
- * that before any create, and the API refuses the same with 409 `amount_mismatch`, so a
387
- * caller catches this one class either way; `amountSource` says whose number
388
- * `actualCents` is, and the message names it.
389
- */
390
- export declare class AmountMismatchError extends ApprovalDeclinedError {
391
- /** The declined authorization, or null for a create-time refusal (no row exists). */
392
- authorizationId: string | null;
393
- /** What the user was asked to approve, smallest currency unit. */
394
- expectedCents: number;
395
- /** What the processor (or the merchant, see `amountSource`) reported at the last check. */
396
- actualCents: number;
397
- /** ISO 4217 of the approved amount. */
398
- currency: string;
399
- /** ISO 4217 the processor reported (differs only on a currency change). */
400
- actualCurrency: string;
401
- /** Which check refused it. */
402
- stage: 'create' | 'pre_replay';
403
- /**
404
- * Whose number `actualCents` is: the processor's ('processor'), a merchant-hosted
405
- * merchant's own checkout total ('merchant_total'), or the amount its card request
406
- * names ('merchant_request').
407
- */
408
- readonly amountSource: 'processor' | 'merchant_total' | 'merchant_request';
409
- readonly code: "amount_mismatch";
410
- constructor(
411
- /** The declined authorization, or null for a create-time refusal (no row exists). */
412
- authorizationId: string | null,
413
- /** What the user was asked to approve, smallest currency unit. */
414
- expectedCents: number,
415
- /** What the processor (or the merchant, see `amountSource`) reported at the last check. */
416
- actualCents: number,
417
- /** ISO 4217 of the approved amount. */
418
- currency: string,
419
- /** ISO 4217 the processor reported (differs only on a currency change). */
420
- actualCurrency?: string,
421
- /** Which check refused it. */
422
- stage?: 'create' | 'pre_replay',
423
- /**
424
- * Whose number `actualCents` is: the processor's ('processor'), a merchant-hosted
425
- * merchant's own checkout total ('merchant_total'), or the amount its card request
426
- * names ('merchant_request').
427
- */
428
- amountSource?: 'processor' | 'merchant_total' | 'merchant_request');
429
- }
430
- /**
431
- * The PaymentIntent behind this checkout can no longer be confirmed: it was
432
- * already charged (succeeded), is being charged (processing), is authorized
433
- * and on hold for the merchant to capture (requires_capture), or was
434
- * canceled. Agentcard refused rather than replay a confirm at it; the
435
- * authorization is `declined` with reason `intent_not_confirmable`.
436
- * Deliberately NOT "nothing was charged": for three of those four, money has
437
- * moved or is moving. Check the intent at Stripe before retrying.
438
- */
439
- export declare class IntentNotConfirmableError extends ApprovalDeclinedError {
440
- authorizationId: string;
441
- readonly code: "intent_not_confirmable";
442
- constructor(authorizationId: string);
443
- }
444
- /** Bounded processor identifiers, never a raw response or free-form description. */
445
- export interface RazorpayProcessorError {
446
- reason?: string;
447
- source?: string;
448
- step?: string;
449
- payment_id?: string;
450
- order_id?: string;
451
- }
452
- /**
453
- * The device reported a processor request rejection. A generic processor
454
- * code does not establish an issuer decline or prove no money moved. Read
455
- * the bounded processor evidence and reconcile the merchant before retrying.
456
- * The authorization remains `declined` with reason `processor_refused` for
457
- * compatibility; no successful processor response is handed to the merchant.
458
- */
459
- export declare class ProcessorRefusedError extends ApprovalDeclinedError {
460
- authorizationId: string;
461
- pspErrorCode: string | null;
462
- readonly code: "processor_refused";
463
- readonly processorError: RazorpayProcessorError | null;
464
- constructor(authorizationId: string, pspErrorCode: string | null, processorError?: RazorpayProcessorError | null);
465
- }
466
- /** Why Agentcard refused a payment on Adyen's TEST platform; see AdyenTestPlatformRefusedError. */
467
- export type AdyenTestPlatformRefusal = 'adyen_test_environment_refused' | 'adyen_test_platform_requires_documented_test_card';
468
- /**
469
- * Agentcard refused a payment on Adyen's TEST platform, where a test account can
470
- * read whatever is encrypted under its key. Nothing was encrypted and nothing was
471
- * charged. `code` says which rule:
472
- * - 'adyen_test_environment_refused': a live checkout names Adyen's test host or
473
- * a `test_` client key. Stage 'create': the API refused it before anyone was
474
- * asked (`authorizationId` is null) and the page's next request is refused the
475
- * same way, so the adapters stop intercepting. Stage 'pre_replay': the
476
- * authorization was declined right before the card would have been encrypted.
477
- * - 'adyen_test_platform_requires_documented_test_card': a test-mode checkout on
478
- * Adyen's test platform, where the approval page encrypts only Adyen's
479
- * documented test cards and the cardholder's card is not one.
480
- * A decline in every structural sense, so it extends ApprovalDeclinedError.
481
- */
482
- export declare class AdyenTestPlatformRefusedError extends ApprovalDeclinedError {
483
- readonly authorizationId: string | null;
484
- readonly code: AdyenTestPlatformRefusal;
485
- readonly stage: 'create' | 'pre_replay';
486
- constructor(authorizationId: string | null, code: AdyenTestPlatformRefusal, stage: 'create' | 'pre_replay');
487
- }
488
- /** Why a merchant-hosted payment priced by the merchant's own total was refused; see MerchantTotalError. */
489
- export type MerchantTotalRefusal = 'merchant_total_required' | 'merchant_total_refused' | 'merchant_total_changed' | 'merchant_total_stale';
490
- /**
491
- * A reviewed merchant's own checkout total could not stand behind this payment, so the
492
- * card request was held and nothing was charged. The merchant's server picks what it
493
- * charges, so a merchant-hosted payment is priced by the total the merchant's own
494
- * checkout responses named in this browser (the profile's amount source), never by the
495
- * agent's number alone. `code`:
496
- * - 'merchant_total_required': no total was sent (stage 'sdk': this runtime recorded no
497
- * merchant responses; stage 'create': the API got none);
498
- * - 'merchant_total_refused': the responses do not confirm one total for this order
499
- * (`reasonCode`: no_source when none was seen, stale, refused, unreadable,
500
- * mismatch, unbound, invalid); stage 'sdk' before any create, 'create' by the API;
501
- * - 'merchant_total_changed': stage 'release': between the approval and the moment the
502
- * card would have gone out, the merchant's total moved, or a request that could move
503
- * it had not answered. The approval is retired; the card never left this browser;
504
- * - 'merchant_total_stale': stage 'runtime': the approval came after the total was too
505
- * old for its profile, so the API withheld the card.
506
- * A decline in every structural sense, so it extends ApprovalDeclinedError.
507
- */
508
- export declare class MerchantTotalError extends ApprovalDeclinedError {
509
- readonly authorizationId: string | null;
510
- readonly code: MerchantTotalRefusal;
511
- readonly stage: 'sdk' | 'create' | 'release' | 'runtime';
512
- readonly reasonCode: string | null;
513
- constructor(authorizationId: string | null, code: MerchantTotalRefusal, stage: 'sdk' | 'create' | 'release' | 'runtime', reasonCode: string | null, reason: string);
514
- }
515
- /**
516
- * A non-2xx from the Agentcard API, carrying the status so callers can tell a
517
- * misconfiguration from a blip. The adapters use this to decide whether
518
- * retrying is worth anything: a 404 `connection_not_found` will answer the same
519
- * way forever, while a 429 or a 502 will not.
520
- */
521
- /**
522
- * The company's preset refused the purchase. The company that runs this
523
- * integration put rules on its users' Vault purchases (a merchant list, a
524
- * currency, a spend cap, a time window); this purchase is outside them.
525
- * Nothing was charged. Two stages:
526
- * - 'create': refused before any authorization existed (`authorizationId`
527
- * is null); nobody was asked to approve. Per purchase, not per page: the
528
- * next request on the same page is judged afresh.
529
- * - 'pre_replay': refused right before the cardholder's device would have
530
- * sent the card; the authorization is `declined` with `code` as reason.
531
- * `code` is the rule's reason (merchant_denied, currency_denied,
532
- * spend_rate_exceeded, time_window_denied, ...), `message` the rule's own
533
- * statement with the company's next step, `preset` the version that judged
534
- * it. When several presets refused the same purchase, `code`, `preset`,
535
- * `rule` and `attachment` are the first, and `refusals` names every one. A
536
- * decline in every structural sense (the adapters quiet the page's retry as
537
- * for a person's "no"), so it extends ApprovalDeclinedError.
538
- */
539
- export declare class PresetRefusedError extends ApprovalDeclinedError {
540
- readonly authorizationId: string | null;
541
- readonly code: string;
542
- readonly detail: string | null;
543
- readonly preset: {
544
- id: string;
545
- version: number;
546
- name: string;
547
- } | null;
548
- readonly rule: string | null;
549
- readonly stage: 'create' | 'pre_replay';
550
- /** The stored card the preset that refused is attached to, with its last four digits. */
551
- readonly attachment: PresetAttachment | null;
552
- /** The preset's name. */
553
- readonly presetName: string | null;
554
- /** Every preset that refused, each with its attachment, rule, code and statement; one entry when one refused. */
555
- readonly refusals: readonly PresetRefusal[];
556
- constructor(authorizationId: string | null, code: string, detail: string | null, preset: {
557
- id: string;
558
- version: number;
559
- name: string;
560
- } | null, rule: string | null, stage: 'create' | 'pre_replay',
561
- /** The stored card the preset that refused is attached to, with its last four digits. */
562
- attachment?: PresetAttachment | null, refusals?: readonly PresetRefusal[]);
563
- }
564
- /** The stored card a preset is attached to, with its last four digits. */
565
- export interface PresetAttachment {
566
- kind: 'card';
567
- targetId: string | null;
568
- last4: string | null;
569
- }
570
- /** One preset's refusal of a purchase. */
571
- export interface PresetRefusal {
572
- preset: {
573
- id: string;
574
- version: number;
575
- name: string;
576
- };
577
- attachment: PresetAttachment | null;
578
- rule: string | null;
579
- code: string;
580
- detail: string | null;
581
- }
582
- /** A decline reason only the company presets stamp (see PresetRefusedError). */
583
- export declare const PRESET_REFUSAL_REASONS: ReadonlySet<string>;
584
- export declare class CheckoutApiError extends Error {
585
- status: number;
586
- path: string;
587
- bodyText: string;
588
- /** The API's stable error code (`{ error: { code } }`), or null when the body carried none. */
589
- readonly code: string | null;
590
- /**
591
- * The rest of the error envelope. A 409 `amount_mismatch` from create
592
- * carries `expected_cents`, `actual_cents`, `currency`, `actual_currency`;
593
- * an `amount_unverifiable` carries `reason`; an `intent_not_confirmable`
594
- * carries `intent_status`.
595
- */
596
- readonly details: Record<string, unknown>;
597
- constructor(status: number, path: string, bodyText: string);
598
- /**
599
- * True when repeating this exact call cannot succeed: a misconfiguration
600
- * (4xx other than 429). NOT a 409 `amount_mismatch`: Stripe lets a merchant
601
- * update an intent's amount until it is confirmed, so the next request on
602
- * the same page may well agree. That one is a per-request failure, and
603
- * authorize() surfaces it as AmountMismatchError before an adapter ever
604
- * sees it here. NOT a 409 `duplicate_submission` either: the household
605
- * already has, or already answered, the prompt for this submission, and
606
- * once that prior authorization is declined or expired the same form is a
607
- * new question. The adapters quiet the page's re-post the way they quiet a
608
- * decline instead of latching the attachment.
609
- */
610
- get permanent(): boolean;
611
- }
612
- /**
613
- * A URL as it may appear in an error message: origin + path only. A paused
614
- * request's URL can carry a client secret in its query string, and error
615
- * messages travel further than anyone intends (onEvent, logs, crash reports).
616
- */
617
- export declare function redactUrl(raw: string): string;
618
- export interface VaultClientOptions {
619
- /**
620
- * Your Agentcard OAuth client credentials. The SDK exchanges them for a
621
- * short-lived access token and refreshes it when it expires.
622
- *
623
- * NOT an `sk_` API key: those are retired, and the checkout endpoints reject
624
- * them with `client_credentials_required` because an authorization has to be
625
- * bound to the confidential client that created it.
626
- */
627
- clientId: string;
628
- clientSecret: string;
629
- baseUrl?: string;
630
- /** Override the PSP registry (tests, or pinning). Defaults to the hosted list. */
631
- registry?: Recognizer[];
632
- fetchImpl?: typeof fetch;
633
- /** Receives contained reporting failures that do not change checkout behavior. */
634
- onEvent?: (event: {
635
- type: string;
636
- detail?: unknown;
637
- }) => void;
638
- pollIntervalMs?: number;
639
- /**
640
- * Waits before retrying a create the API answered 502 `amount_unverifiable`
641
- * (Stripe did not answer the amount read-back) or 502 `cse_key_unavailable`
642
- * (Adyen did not answer the public-key fetch). One retry per entry, then
643
- * the error is thrown. Default [500, 1500]; [] disables retries.
644
- */
645
- unverifiableRetryDelaysMs?: number[];
646
- /**
647
- * Test mode only: run a merchant-hosted checkout against your own Adyen TEST
648
- * account. Each entry arms your own endpoint as taking the card request of a
649
- * profile Agentcard reviewed (its body rules), encrypted under your own Adyen
650
- * TEST client key; prepare({ psp: 'adyen', environment: 'sandbox',
651
- * merchantProfile: <that profile> }) then pays it. Declare them here, before any
652
- * attach, so every adapter pauses the endpoint. The API accepts a declaration
653
- * only from a test-mode client of an org Agentcard turned declarations on for,
654
- * and the Vault encrypts only Adyen's documented test cards under a test_ key.
655
- * Throws a TypeError at construction for a profile this build did not review, an
656
- * endpoint the API would refuse (see declareSandboxMerchant) or a non-test key.
657
- *
658
- * On this client a declared profile id takes the place of the reviewed profile
659
- * with that id: merchantProfile(id) and prepare({ merchantProfile: id }) name
660
- * the declaration, so this client never prepares the reviewed merchant's own
661
- * checkout. Nothing is lost on a test-mode client, which can never pay a
662
- * reviewed profile on Adyen's live platform; use a separate client for that.
663
- */
664
- sandboxMerchants?: SandboxMerchantDeclaration[];
665
- }
666
- export declare class VaultClient {
667
- private readonly opts;
668
- private readonly baseUrl;
669
- private readonly fetch;
670
- private readonly pollIntervalMs;
671
- private readonly unverifiableRetryDelaysMs;
672
- private registry;
673
- /**
674
- * The reviewed merchant profiles this client arms: every one this build reviewed,
675
- * in 'observe' until a sync reads that the API enabled it (armServedProfiles).
676
- */
677
- private merchantProfiles;
678
- /** This client's own sandbox declarations (sandboxMerchants), armed at construction, one per profile. */
679
- private readonly declaredProfiles;
680
- private readonly preparations;
681
- private readonly usedPreparations;
682
- constructor(opts: VaultClientOptions);
683
- /** Refresh recognizers from the API so new PSPs work without a redeploy. */
684
- syncRegistry(): Promise<void>;
685
- /**
686
- * The reviewed Adyen merchant profile whose card endpoint (or a sibling of it,
687
- * the same path under another query) this URL is, with its status on this
688
- * client; null for any other URL. Every profile this build reviewed is armed,
689
- * in 'observe' until a sync reads that the API enabled it. The adapters pause
690
- * these requests and judge them with classifyMerchantRequest. A raw runtime
691
- * that pauses one must never continue a card body there unless authorize()
692
- * paid it.
693
- */
694
- merchantProfileOf(url: string): MerchantProfile | null;
695
- /** The armed profile with this id, or null. A profile id this client declared (sandboxMerchants) names its declaration, in place of the reviewed profile. */
696
- merchantProfile(id: string): MerchantProfile | null;
697
- /**
698
- * Fetch.enable globs for every armed merchant profile's endpoint and its
699
- * siblings, for a raw CDP runtime to arm beside cardUrlPatterns(). Every profile
700
- * this build reviewed is armed from the start, so these are the same before and
701
- * after syncRegistry; a sync changes only a profile's status.
702
- */
703
- merchantProfileUrlPatterns(): string[];
704
- /** True when this request is a card tokenization we can take over. */
705
- isCardRequest(url: string, method?: string): boolean;
706
- /**
707
- * What happens to a card request (by URL) whose body carries no card: null
708
- * when it carries one, so it is a card request as usual; 'continue' when the
709
- * recognizer marks the endpoint as one where such requests are routine and
710
- * never ours; 'refuse' otherwise, such as a Stripe confirmation paying with
711
- * a method this checkout never approved. The adapters ask only after their
712
- * holds, so a request that would reuse an approved token is refused there
713
- * first. A body that could not be read is not judged here.
714
- */
715
- withoutCard(url: string, body: string | null | undefined): 'continue' | 'refuse' | null;
716
- /**
717
- * How the card would reach the processor on this request (`token`, `cse`
718
- * or `hosted_form`; absent on the entry means `token`), or null when the
719
- * registry does not recognize it. The adapters read it to decide whether an
720
- * approval outlives the page's own request: a hosted form is a navigation
721
- * and cannot.
722
- */
723
- checkoutModeOf(url: string, method?: string): CheckoutMode | null;
724
- /**
725
- * Glob url patterns covering every host the CURRENT registry can send a card
726
- * to — what a raw CDP connection has to hand `Fetch.enable` before any card
727
- * request can be paused. attachToCdp calls this for you.
728
- *
729
- * Call syncRegistry() FIRST: without it these cover only the built-in PSPs,
730
- * and a request the API knows about is never paused at all. Deliberately
731
- * WIDER than the recognizers themselves (a glob cannot express an anchored
732
- * host regex); isCardRequest is the exact check and runs on every request
733
- * these patterns pause.
734
- */
735
- cardUrlPatterns(): string[];
736
- /** Wait for real device approval before the caller starts native tokenization. */
737
- prepareCheckout(input: PrepareCheckoutInput): Promise<PreparedCheckout>;
738
- /** Cancel only an unconsumed preparation; a bound request is reconciled separately. */
739
- cancelPreparation(id: string): Promise<void>;
740
- observePreparation(id: string, guidance: 'presented_not_filled' | 'not_presented', reason?: string): Promise<void>;
741
- reportDuplicateGuard(authorizationId: string): Promise<void>;
742
- /**
743
- * Hand us a paused tokenization request. We ask the cardholder to approve,
744
- * their device supplies the card and calls the merchant, and you get back the
745
- * response to replay into the browser. Your process never sees a card.
746
- */
747
- authorize(input: AuthorizeInput): Promise<ReplayResponse>;
748
- /** A lost bind acknowledgement must never resume the request. Recover metadata only for safe cleanup. */
749
- private retireUncertainPreparation;
750
- /**
751
- * Retire an authorization the runtime is done with. A 409 or missing
752
- * response remains unknown.
753
- *
754
- * `merchant_request_aborted` (the default): the merchant request is gone
755
- * and the row must still be awaiting the person with no replay started; the
756
- * acknowledgement carries `processor_request_started: false`.
757
- *
758
- * `merchant_never_retried`: the page abandoned its request while the person
759
- * decided, the adapter kept the approval for the page's retry, and none
760
- * came. The row may already be `approved` (a token or ciphertext minted on
761
- * the device that this runtime handed to no request), so
762
- * `processor_request_started` says whether the processor was asked; the API
763
- * stamps this reason only where no charge can have been made and answers
764
- * 409 otherwise. The acknowledgement echoes the reason the row actually
765
- * carries: a row retired earlier under the other runtime reason answers
766
- * with that one.
767
- */
768
- cancelAuthorization(authorizationId: string, reason?: RuntimeCancelReason): Promise<{
769
- id: string;
770
- status: 'declined';
771
- reason: RuntimeCancelReason;
772
- cancelled: true;
773
- processor_request_started: boolean;
774
- }>;
775
- /**
776
- * Ask whether the page may pay with the Stripe card token an approval
777
- * produced: a PaymentIntent confirm that carries no card and pays with
778
- * exactly the approved payment method, card token, confirmation token or
779
- * source. The API reads the payment from Stripe and answers only for the
780
- * approved amount and currency on the same Stripe account; any other answer
781
- * rejects with a CheckoutApiError whose code says why (for example
782
- * `continuation_not_bound`, `amount_mismatch`). Nothing is charged here:
783
- * the adapters continue the page's own request once this resolves.
784
- */
785
- checkStripeContinuation(authorizationId: string, request: {
786
- url: string;
787
- method: string;
788
- headers: Record<string, string>;
789
- body: string;
790
- }): Promise<{
791
- paymentIntentId: string;
792
- amount: number;
793
- currency: string;
794
- }>;
795
- /**
796
- * After a merchant-hosted payment priced by the merchant's own total: what the merchant's
797
- * confirmation says it charged (merchant-total.ts merchantChargeReport builds `report`
798
- * from the responses this browser recorded after the card request). The API compares it
799
- * with the approved amount and alerts Agentcard once when the merchant charged more, or
800
- * in another currency. The adapters send it on their own; the verdict is 'equal',
801
- * 'lower', 'higher', 'currency_mismatch', or 'unread' when no response read.
802
- */
803
- reportMerchantCharge(authorizationId: string, report: {
804
- request: {
805
- url: string;
806
- method: string;
807
- body: string;
808
- };
809
- responses: unknown[];
810
- }): Promise<{
811
- verdict: 'equal' | 'lower' | 'higher' | 'currency_mismatch' | 'unread';
812
- alerted: boolean;
813
- }>;
814
- /**
815
- * The merchant's own total for a paused card request whose reviewed profile is priced by
816
- * one: the exchanges the adapter recorded (once every request that can move the total has
817
- * answered), cut to what the profile's rules read, and the same reading the API makes.
818
- * Refused with a MerchantTotalError before any create when nothing recorded them, one is
819
- * still unanswered, or they do not confirm one total for this order.
820
- */
821
- private readMerchantTotal;
822
- /**
823
- * POST the create, with two typed twists: a 502 `amount_unverifiable`
824
- * (Stripe did not answer the read-back) is retried on a short backoff
825
- * instead of being left to the page's own retry loop, and a 409
826
- * `amount_mismatch` becomes an AmountMismatchError at stage 'create' so the
827
- * adapters treat it as an answered request, not a dead page.
828
- */
829
- private createAuthorization;
830
- private token;
831
- private inflight;
832
- /**
833
- * Exchange client credentials for an access token, reusing the cached one
834
- * until it is nearly expired. Concurrent callers share a single in-flight
835
- * exchange rather than each minting their own token.
836
- */
837
- private accessToken;
838
- /**
839
- * A preparation status read may retry two known connection failures, after
840
- * 250ms and 500ms, while keeping its original approval deadline and signal.
841
- * Only fetch and a successful response's body read belong to that retry:
842
- * OAuth, HTTP errors, invalid JSON and every mutation remain outside it.
843
- * The existing one-time 401 refresh carries the remaining read budget.
844
- */
845
- private call;
846
- private post;
847
- private get;
848
- private readPreparation;
849
- }