@visa/cli 4.1.0-rc.2 → 4.1.0-rc.200

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 (76) hide show
  1. package/README.md +200 -226
  2. package/dist/checkout-engine/adapters/generic.d.ts +88 -0
  3. package/dist/checkout-engine/adapters/generic.js +526 -0
  4. package/dist/checkout-engine/adapters/index.d.ts +10 -0
  5. package/dist/checkout-engine/adapters/index.js +24 -0
  6. package/dist/checkout-engine/adapters/shopify.d.ts +55 -0
  7. package/dist/checkout-engine/adapters/shopify.js +514 -0
  8. package/dist/checkout-engine/adapters/stripe-like.d.ts +10 -0
  9. package/dist/checkout-engine/adapters/stripe-like.js +21 -0
  10. package/dist/checkout-engine/amount.d.ts +15 -0
  11. package/dist/checkout-engine/amount.js +72 -0
  12. package/dist/checkout-engine/browser-launch.d.ts +46 -0
  13. package/dist/checkout-engine/browser-launch.js +81 -0
  14. package/dist/checkout-engine/ceremony.d.ts +64 -0
  15. package/dist/checkout-engine/ceremony.js +261 -0
  16. package/dist/checkout-engine/cli-engine.d.ts +315 -0
  17. package/dist/checkout-engine/cli-engine.js +996 -0
  18. package/dist/checkout-engine/confirmed-merchants.d.ts +31 -0
  19. package/dist/checkout-engine/confirmed-merchants.js +165 -0
  20. package/dist/checkout-engine/detect.d.ts +61 -0
  21. package/dist/checkout-engine/detect.js +398 -0
  22. package/dist/checkout-engine/evidence.d.ts +25 -0
  23. package/dist/checkout-engine/evidence.js +104 -0
  24. package/dist/checkout-engine/executor.d.ts +215 -0
  25. package/dist/checkout-engine/executor.js +1520 -0
  26. package/dist/checkout-engine/hosted-approval.d.ts +195 -0
  27. package/dist/checkout-engine/hosted-approval.js +498 -0
  28. package/dist/checkout-engine/index.d.ts +9 -0
  29. package/dist/checkout-engine/index.js +11 -0
  30. package/dist/checkout-engine/instrument.d.ts +61 -0
  31. package/dist/checkout-engine/instrument.js +87 -0
  32. package/dist/checkout-engine/known-merchants.d.ts +10 -0
  33. package/dist/checkout-engine/known-merchants.js +38 -0
  34. package/dist/checkout-engine/live-fill-approval.d.ts +37 -0
  35. package/dist/checkout-engine/live-fill-approval.js +76 -0
  36. package/dist/checkout-engine/mandate/card-mandate.d.ts +121 -0
  37. package/dist/checkout-engine/mandate/card-mandate.js +227 -0
  38. package/dist/checkout-engine/mandate/mandate-ledger.d.ts +178 -0
  39. package/dist/checkout-engine/mandate/mandate-ledger.js +395 -0
  40. package/dist/checkout-engine/mandate.d.ts +25 -0
  41. package/dist/checkout-engine/mandate.js +100 -0
  42. package/dist/checkout-engine/outcome.d.ts +30 -0
  43. package/dist/checkout-engine/outcome.js +225 -0
  44. package/dist/checkout-engine/owner-only-file.d.ts +19 -0
  45. package/dist/checkout-engine/owner-only-file.js +41 -0
  46. package/dist/checkout-engine/package.json +3 -0
  47. package/dist/checkout-engine/receipt-dir.d.ts +6 -0
  48. package/dist/checkout-engine/receipt-dir.js +8 -0
  49. package/dist/checkout-engine/receipt.d.ts +121 -0
  50. package/dist/checkout-engine/receipt.js +138 -0
  51. package/dist/checkout-engine/trace-handles.d.ts +8 -0
  52. package/dist/checkout-engine/trace-handles.js +12 -0
  53. package/dist/checkout-engine/types.d.ts +52 -0
  54. package/dist/checkout-engine/types.js +2 -0
  55. package/dist/checkout-engine/unresolved-charges.d.ts +34 -0
  56. package/dist/checkout-engine/unresolved-charges.js +125 -0
  57. package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +101 -0
  58. package/dist/checkout-engine/vgs-gateway/server-mint-client.js +218 -0
  59. package/dist/checkout-engine/vgs-live-instrument.d.ts +144 -0
  60. package/dist/checkout-engine/vgs-live-instrument.js +229 -0
  61. package/dist/checkout-engine/vic-confirmation.d.ts +52 -0
  62. package/dist/checkout-engine/vic-confirmation.js +45 -0
  63. package/dist/checkout-engine/web-bot-auth.d.ts +92 -0
  64. package/dist/checkout-engine/web-bot-auth.js +159 -0
  65. package/dist/cli.js +721 -445
  66. package/dist/mcp-apps/ucp-checkout.html +280 -0
  67. package/dist/mcp-server/index.js +573 -175
  68. package/dist/skills/pair-visa-agent/RUNTIMES.md +93 -0
  69. package/dist/skills/pair-visa-agent/SKILL.md +557 -0
  70. package/dist/skills/pair-visa-agent/scripts/setup.mjs +48 -0
  71. package/dist/subway-direct.mjs +1 -0
  72. package/install.ps1 +5 -43
  73. package/install.sh +5 -37
  74. package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
  75. package/package.json +33 -25
  76. package/server.json +4 -4
@@ -0,0 +1,138 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { KNOWN_MERCHANT_IDENTITIES } from './known-merchants.js';
4
+ import { submitClickedWithoutConfirmation } from './live-fill-approval.js';
5
+ /**
6
+ * What the operator still owes after this run. Empty for a clean dry-run fill
7
+ * and for a definitive submit outcome whose VIC confirmation posted.
8
+ */
9
+ function reconciliationFor(result, vicConfirmation) {
10
+ const reasons = [];
11
+ if (submitClickedWithoutConfirmation(result)) {
12
+ reasons.push('the pay control was clicked but no definitive outcome was observed — ' +
13
+ 'verify the charge with the merchant dashboard before any retry');
14
+ }
15
+ if ((result.outcome === 'confirmed' || result.outcome === 'declined') &&
16
+ vicConfirmation &&
17
+ !vicConfirmation.posted) {
18
+ reasons.push(`the VIC confirmation was not posted (${vicConfirmation.reason}) — ` +
19
+ 'retry it for this intent out-of-band');
20
+ }
21
+ if (result.outcome === 'confirmed' && !result.confirmationRef) {
22
+ reasons.push('confirmed without a merchant confirmation reference — ' +
23
+ 'record the order number from the merchant dashboard');
24
+ }
25
+ if (result.outcome === 'action-required') {
26
+ reasons.push('an issuer verification challenge was shown and not completed — ' +
27
+ 'finish the purchase manually if still wanted, or confirm with the merchant that no order exists');
28
+ }
29
+ return { required: reasons.length > 0, reasons };
30
+ }
31
+ export function buildReceipt(input) {
32
+ const { result } = input;
33
+ const reconciliation = reconciliationFor(result, input.vicConfirmation);
34
+ const fallbackAction = input.mode === 'dry-run'
35
+ ? 'Dry run only — nothing was submitted; safe to run again.'
36
+ : result.outcome === 'confirmed'
37
+ ? 'No action needed.'
38
+ : result.outcome === 'declined'
39
+ ? 'Review the decline before trying again.'
40
+ : result.outcome === 'unverified'
41
+ ? // Defensive: reconciliationFor() already pushes the richer
42
+ // submit-clicked reason for this outcome, so this line is only
43
+ // reached if that ever stops firing. It must still not invite a
44
+ // retry.
45
+ 'The charge may have gone through. Confirm with the merchant before retrying.'
46
+ : result.outcome === 'partial-fill'
47
+ ? // A v2 receipt carries no evidence log, so this line is the only
48
+ // place the CAUSE survives — which field refused and why. An
49
+ // operator opening this a week later can act on it; "could not
50
+ // be filled" alone means reproducing a live merchant to learn
51
+ // anything.
52
+ `${result.detail ?? 'Nothing was submitted and nothing was charged.'} Safe to try again once the checkout can be filled.`
53
+ : 'Review this outcome before retrying.';
54
+ const recoveryActions = reconciliation.reasons.length > 0 ? reconciliation.reasons : [fallbackAction];
55
+ const cardLast4 = input.cardLast4 && /^\d{4}$/.test(input.cardLast4) ? input.cardLast4 : null;
56
+ const checkoutUrl = input.merchant.url && KNOWN_MERCHANT_IDENTITIES[input.merchant.url] ? input.merchant.url : null;
57
+ const networkConfirmation = input.vicConfirmation?.posted === true ? input.vicConfirmation.transactionStatus : null;
58
+ return {
59
+ schema: 'checkout-agent-receipt/v2',
60
+ recordedAt: (input.recordedAt ?? new Date()).toISOString(),
61
+ merchant: { name: input.merchant.name, host: input.merchant.host, checkoutUrl },
62
+ transaction: input.transaction,
63
+ outcome: result.outcome,
64
+ agent: input.agentName ? { name: input.agentName } : null,
65
+ rail: { type: 'card', cardLast4 },
66
+ network: { confirmation: networkConfirmation },
67
+ receiptId: input.reviewId,
68
+ reference: result.confirmationRef ?? null,
69
+ recovery: {
70
+ required: reconciliation.required,
71
+ // A clean dry-run did not submit anything, so repeating inspection is
72
+ // safe. Every submit outcome requires either no retry or owner review.
73
+ retrySafe: input.mode === 'dry-run' && !reconciliation.required,
74
+ action: recoveryActions[0],
75
+ actions: recoveryActions,
76
+ },
77
+ };
78
+ }
79
+ function luhnValid(digits) {
80
+ let sum = 0;
81
+ let double = false;
82
+ for (let i = digits.length - 1; i >= 0; i--) {
83
+ let d = digits.charCodeAt(i) - 48;
84
+ if (double) {
85
+ d *= 2;
86
+ if (d > 9)
87
+ d -= 9;
88
+ }
89
+ sum += d;
90
+ double = !double;
91
+ }
92
+ return sum % 10 === 0;
93
+ }
94
+ /**
95
+ * Defense-in-depth scrub before anything touches disk: any standalone
96
+ * 12–19-digit run that passes Luhn is replaced — contiguous OR separated by
97
+ * single spaces/hyphens between digit groups, the way merchant card-preview
98
+ * widgets render a typed number ("4242 4242 4242 4242") into page text that
99
+ * can reach the snapshot summary. Upstream masking means a hit should be
100
+ * impossible; the count surfaces so the runner can flag a leak.
101
+ */
102
+ export function redactPanLikeDigits(text) {
103
+ let redactions = 0;
104
+ const scrubbed = text.replace(/(?<!\d)(?<!\d[\s-])\d(?:[\s-]?\d){11,18}(?![\s-]?\d)/g, (run) => {
105
+ const digits = run.replace(/[\s-]/g, '');
106
+ if (digits.length < 12 || digits.length > 19 || !luhnValid(digits))
107
+ return run;
108
+ redactions++;
109
+ return '<redacted:pan-like>';
110
+ });
111
+ return { text: scrubbed, redactions };
112
+ }
113
+ export function serializeReceipt(receipt) {
114
+ const { text, redactions } = redactPanLikeDigits(`${JSON.stringify(receipt, null, 2)}\n`);
115
+ return { json: text, panRedactions: redactions };
116
+ }
117
+ export function receiptFileName(receipt) {
118
+ const ts = receipt.recordedAt.replace(/[:.]/g, '-');
119
+ const receiptId = receipt.schema === 'checkout-agent-receipt/v1' ? receipt.reviewId : receipt.receiptId;
120
+ const review = (receiptId ?? 'no-review').replace(/[^A-Za-z0-9-]/g, '');
121
+ return `receipt-${ts}-${review || 'no-review'}.json`;
122
+ }
123
+ /**
124
+ * Persist one receipt as an owner-only file (0600) in an owner-only directory
125
+ * (0700). Refuses to overwrite an existing file (`wx`). Never throws.
126
+ */
127
+ export async function writeReceipt(dir, receipt) {
128
+ try {
129
+ await mkdir(dir, { recursive: true, mode: 0o700 });
130
+ const path = join(dir, receiptFileName(receipt));
131
+ const { json, panRedactions } = serializeReceipt(receipt);
132
+ await writeFile(path, json, { mode: 0o600, flag: 'wx' });
133
+ return { written: true, path, panRedactions };
134
+ }
135
+ catch (err) {
136
+ return { written: false, reason: err.message };
137
+ }
138
+ }
@@ -0,0 +1,8 @@
1
+ export declare function safeTraceHandle(value: unknown): string | undefined;
2
+ export declare function traceHandleFields(value: {
3
+ vgsTraceId?: unknown;
4
+ networkCorrelationId?: unknown;
5
+ }): {
6
+ vgsTraceId?: string;
7
+ networkCorrelationId?: string;
8
+ };
@@ -0,0 +1,12 @@
1
+ const SAFE_TRACE_HANDLE_RE = /^[A-Za-z0-9._:-]{1,128}$/;
2
+ export function safeTraceHandle(value) {
3
+ return typeof value === 'string' && SAFE_TRACE_HANDLE_RE.test(value) ? value : undefined;
4
+ }
5
+ export function traceHandleFields(value) {
6
+ const vgsTraceId = safeTraceHandle(value.vgsTraceId);
7
+ const networkCorrelationId = safeTraceHandle(value.networkCorrelationId);
8
+ return {
9
+ ...(vgsTraceId ? { vgsTraceId } : {}),
10
+ ...(networkCorrelationId ? { networkCorrelationId } : {}),
11
+ };
12
+ }
@@ -0,0 +1,52 @@
1
+ export type PostalAddress = {
2
+ firstName?: string;
3
+ lastName?: string;
4
+ fullName?: string;
5
+ addressLine1?: string;
6
+ addressLine2?: string;
7
+ city?: string;
8
+ state?: string;
9
+ postalCode?: string;
10
+ country?: string;
11
+ };
12
+ export type Contact = PostalAddress & {
13
+ email?: string;
14
+ phone?: string;
15
+ billingAddress?: PostalAddress;
16
+ };
17
+ export type FilledField = {
18
+ role: string;
19
+ locator: string;
20
+ confidence: number;
21
+ source: string;
22
+ frame?: string;
23
+ value: string;
24
+ ok: boolean;
25
+ error?: string;
26
+ /**
27
+ * The detected node was gone by the time this field's turn came (the merchant
28
+ * re-mounted that part of the form mid-fill) and a fresh detection pass was
29
+ * used to find it again. Worth surfacing: a merchant that re-mounts is a
30
+ * merchant whose fills are order-sensitive, which is the first thing to know
31
+ * when one of them later refuses.
32
+ */
33
+ relocated?: boolean;
34
+ };
35
+ export type FillResult = {
36
+ ok: boolean;
37
+ filled: FilledField[];
38
+ detail?: string;
39
+ };
40
+ export type OtpRequest = {
41
+ /** ISO watermark captured BEFORE the click that triggers the OTP email. */
42
+ after: string;
43
+ /** The merchant hostname; the sender's registrable domain must match it. */
44
+ merchantHost: string;
45
+ };
46
+ export type OtpResolution = {
47
+ /** The single-use code. The executor fills it exactly once; never retried. */
48
+ code: string;
49
+ /** The sender's registrable domain — a trust signal, safe to log (no PII). */
50
+ fromDomain: string;
51
+ };
52
+ export type OtpResolver = (req: OtpRequest) => Promise<OtpResolution | null>;
@@ -0,0 +1,2 @@
1
+ // Shared value types used across the engine.
2
+ export {};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Outcomes whose receipt cannot rule out a charge.
3
+ *
4
+ * Both of these record a run where the pay control was clicked and no
5
+ * definitive answer came back:
6
+ * - `unverified` — no confirmation or decline observed before the deadline
7
+ * - `action-required` — an issuer challenge appeared, which happens AFTER the
8
+ * click, so the authorization may already exist
9
+ *
10
+ * Everything else is either definitive (`confirmed`, `declined`) or provably
11
+ * pre-click (`reviewed-dry-run`, `partial-fill`, `failed`, ...). Widening this
12
+ * set blocks legitimate retries; narrowing it lets a double charge through, so
13
+ * an outcome earns a place here only by being genuinely post-click.
14
+ */
15
+ export declare const MAY_HAVE_CHARGED_OUTCOMES: ReadonlySet<string>;
16
+ /** One local attempt that may have taken money and was never resolved. */
17
+ export type UnresolvedCharge = {
18
+ recordedAt: string;
19
+ host: string;
20
+ amount: string;
21
+ amountMinor: number;
22
+ currency: string;
23
+ outcome: string;
24
+ /** Receipt file basename, so a caller can name the evidence a human must check. */
25
+ receiptFile: string;
26
+ };
27
+ /**
28
+ * Local attempts that may have charged, newest first.
29
+ *
30
+ * Never throws: a missing directory (nothing has ever been checked out here)
31
+ * and an unreadable one both read as "no unresolved charges". The caller
32
+ * decides what an empty answer means — see the fail-open note at its call site.
33
+ */
34
+ export declare function readUnresolvedCharges(receiptDir?: string): Promise<UnresolvedCharge[]>;
@@ -0,0 +1,125 @@
1
+ // "Did this device already submit this exact purchase?", read back from the
2
+ // checkout receipts on disk.
3
+ //
4
+ // The engine now reports a submitted-but-unobserved checkout as `unverified`
5
+ // instead of `failed`, and pay_merchant tells the caller not to retry it. This
6
+ // module is the belt to that suspenders: even a caller that ignores the words
7
+ // can be stopped, because the previous attempt left a receipt.
8
+ //
9
+ // It answers one question — which local receipts record an attempt that MAY
10
+ // HAVE CHARGED and was never resolved — and deliberately answers nothing else.
11
+ // The matching (same merchant, same amount, recent enough) lives in the caller,
12
+ // which owns the policy; this side owns only the read.
13
+ //
14
+ // Sibling of confirmed-merchants.ts and loaded through the same seam: it
15
+ // imports node built-ins and types only, so reading receipts never pulls
16
+ // playwright into the CLI process.
17
+ //
18
+ // Reading is best-effort by construction. The receipts directory is an operator
19
+ // artifact that anything on the box can touch, so an unreadable or malformed
20
+ // file is skipped rather than failing the whole read.
21
+ import { readdir, readFile } from 'node:fs/promises';
22
+ import { join } from 'node:path';
23
+ import { RECEIPT_DIR } from './receipt-dir.js';
24
+ /**
25
+ * Outcomes whose receipt cannot rule out a charge.
26
+ *
27
+ * Both of these record a run where the pay control was clicked and no
28
+ * definitive answer came back:
29
+ * - `unverified` — no confirmation or decline observed before the deadline
30
+ * - `action-required` — an issuer challenge appeared, which happens AFTER the
31
+ * click, so the authorization may already exist
32
+ *
33
+ * Everything else is either definitive (`confirmed`, `declined`) or provably
34
+ * pre-click (`reviewed-dry-run`, `partial-fill`, `failed`, ...). Widening this
35
+ * set blocks legitimate retries; narrowing it lets a double charge through, so
36
+ * an outcome earns a place here only by being genuinely post-click.
37
+ */
38
+ export const MAY_HAVE_CHARGED_OUTCOMES = new Set([
39
+ 'unverified',
40
+ 'action-required',
41
+ ]);
42
+ /**
43
+ * Every field this module reads, validated. Deliberately permissive about
44
+ * everything else: older and newer engines only have to carry these.
45
+ *
46
+ * Both receipt schemas expose all of them at the same paths, so unlike
47
+ * confirmed-merchants.ts there is nothing here that needs a per-schema branch.
48
+ */
49
+ function parseUnresolved(json, receiptFile) {
50
+ let parsed;
51
+ try {
52
+ parsed = JSON.parse(json);
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ if (typeof parsed !== 'object' || parsed === null)
58
+ return null;
59
+ const receipt = parsed;
60
+ if (receipt.schema !== 'checkout-agent-receipt/v1' &&
61
+ receipt.schema !== 'checkout-agent-receipt/v2') {
62
+ return null;
63
+ }
64
+ if (typeof receipt.outcome !== 'string' || !MAY_HAVE_CHARGED_OUTCOMES.has(receipt.outcome)) {
65
+ return null;
66
+ }
67
+ if (typeof receipt.recordedAt !== 'string' || Number.isNaN(Date.parse(receipt.recordedAt))) {
68
+ return null;
69
+ }
70
+ const host = receipt.merchant?.host;
71
+ if (typeof host !== 'string' || host.length === 0)
72
+ return null;
73
+ const transaction = receipt.transaction;
74
+ if (typeof transaction?.amount !== 'string')
75
+ return null;
76
+ if (typeof transaction.currency !== 'string')
77
+ return null;
78
+ // A receipt whose amount cannot be compared cannot gate a retry on amount, and
79
+ // a guard that silently matched every amount would be worse than none.
80
+ if (typeof transaction.amountMinor !== 'number' || !Number.isFinite(transaction.amountMinor)) {
81
+ return null;
82
+ }
83
+ return {
84
+ recordedAt: receipt.recordedAt,
85
+ host,
86
+ amount: transaction.amount,
87
+ amountMinor: transaction.amountMinor,
88
+ currency: transaction.currency,
89
+ outcome: receipt.outcome,
90
+ receiptFile,
91
+ };
92
+ }
93
+ /**
94
+ * Local attempts that may have charged, newest first.
95
+ *
96
+ * Never throws: a missing directory (nothing has ever been checked out here)
97
+ * and an unreadable one both read as "no unresolved charges". The caller
98
+ * decides what an empty answer means — see the fail-open note at its call site.
99
+ */
100
+ export async function readUnresolvedCharges(receiptDir = RECEIPT_DIR) {
101
+ let names;
102
+ try {
103
+ names = await readdir(receiptDir);
104
+ }
105
+ catch {
106
+ return [];
107
+ }
108
+ const charges = [];
109
+ for (const name of names) {
110
+ if (!name.endsWith('.json'))
111
+ continue;
112
+ let raw;
113
+ try {
114
+ raw = await readFile(join(receiptDir, name), 'utf8');
115
+ }
116
+ catch {
117
+ continue;
118
+ }
119
+ const charge = parseUnresolved(raw, name);
120
+ if (charge)
121
+ charges.push(charge);
122
+ }
123
+ charges.sort((left, right) => (left.recordedAt < right.recordedAt ? 1 : -1));
124
+ return charges;
125
+ }
@@ -0,0 +1,101 @@
1
+ import type { VgsCheckoutTarget, VgsPaymentCredential } from '../vgs-live-instrument.js';
2
+ export type ServerMintDeps = {
3
+ /** Injectable for tests — defaults to global fetch. */
4
+ fetchImpl?: typeof fetch;
5
+ /** Injectable for tests — never wall-clock-sleep in a unit test. */
6
+ sleep?: (ms: number) => Promise<void>;
7
+ env?: NodeJS.ProcessEnv;
8
+ };
9
+ /**
10
+ * The merchant ORIGIN (scheme + host) — not the full checkout URL. A merchant's
11
+ * identity is its origin; a real checkout URL can carry hundreds of chars of
12
+ * campaign/tracking query params. Confirmed live: an oversized `merchantUrl`
13
+ * (a ~280-char Wikimedia donation URL) makes the cryptogram mint fail downstream
14
+ * with a vague `502 "card network could not complete"`, while the same merchant
15
+ * with a trimmed URL mints fine. Sending the origin is both correct (that IS the
16
+ * merchant) and safely bounded. Falls back to the raw value if it does not parse
17
+ * — the mint must never throw here.
18
+ */
19
+ export declare function merchantOrigin(url: string): string;
20
+ /**
21
+ * A definitive refusal from the cryptogram mint route — the request will not
22
+ * succeed if retried unchanged.
23
+ *
24
+ * `terminal` is the load-bearing field. Draw terminality used to be decided by
25
+ * regex over the error MESSAGE, which made it hostage to text nobody controls:
26
+ * this client now interpolates the provider's own `upstream_codes` into the
27
+ * message for diagnosability, and a provider identifier such as
28
+ * `request_timeout` would match the transient matcher's unanchored
29
+ * `tim(e|ed)-out` alternative — flipping a permanent 422 back to "transient",
30
+ * skipping markUnhonored, and stranding the mandate in the exact retry-forever
31
+ * loop this whole change exists to kill. Terminality is therefore carried
32
+ * structurally, and consumers must consult it BEFORE any message matching.
33
+ */
34
+ export declare class ServerCryptogramRefusedError extends Error {
35
+ readonly status: number;
36
+ readonly terminal: true;
37
+ constructor(status: number, detail: string);
38
+ }
39
+ /**
40
+ * Optional mandate override for serverCreateIntent. Absent → the default
41
+ * intent shape (cap = ceil(amount)+10 min 25, quantity 1, 30-day window).
42
+ * Present → the card-mandate (budget) layer sets a CEILING decline threshold
43
+ * and a multi-draw quantity so one passkey approves a spend ceiling and later
44
+ * draws pull cryptograms under it without a fresh tap. Whether the network
45
+ * honors a ceiling-scoped assurance across multiple sub-amount draws is
46
+ * UNPROVEN — see packages/checkout-engine/src/mandate/.
47
+ */
48
+ export type ServerIntentMandateOverride = {
49
+ /** Wire decline-threshold amount (major-unit decimal string), e.g. "500.00". */
50
+ declineThresholdAmount?: string;
51
+ /** Number of draws the intent may fulfil (VGS mandate `quantity`). */
52
+ quantity?: number;
53
+ /** ISO 8601 mandate validity end. */
54
+ effectiveUntil?: string;
55
+ /** Human-readable consumer prompt describing the ceiling grant. */
56
+ consumerPrompt?: string;
57
+ };
58
+ /**
59
+ * Create a fresh intent via POST {base}/api/vgs/intent. The server holds the VGS
60
+ * credential and calls the gateway; we send the same mandate shape the local
61
+ * path built (cap = ceil(amount)+10, min 25; merchant category Retail/5999) —
62
+ * unless `input.mandate` overrides the threshold/quantity/window for the
63
+ * card-mandate (budget) layer.
64
+ */
65
+ export declare function serverCreateIntent(base: string, mintToken: string, input: {
66
+ tokenId: string;
67
+ assuranceData: unknown;
68
+ transaction: VgsCheckoutTarget;
69
+ mandate?: ServerIntentMandateOverride;
70
+ }, deps?: ServerMintDeps): Promise<{
71
+ intentId: string;
72
+ status: string | null;
73
+ }>;
74
+ /**
75
+ * Mint the FULL payment credential via POST {base}/api/vgs/payment-cryptogram.
76
+ * The server's route does a SINGLE gateway call and 502s on a not-COMPLETED
77
+ * (e.g. PENDING) cryptogram, but live intent approval is asynchronous and the
78
+ * first cryptogram answer can be PENDING (#5709). So we retry the route on any
79
+ * non-2xx up to PENDING_ATTEMPTS, matching fetch-credential.mjs's cadence
80
+ * exactly — a genuinely hard failure just surfaces after the same bounded wait.
81
+ * Re-POSTing for the same intentId is idempotent (mirrors the old client loop).
82
+ */
83
+ export declare function serverFetchCryptogram(base: string, mintToken: string, input: {
84
+ tokenId: string;
85
+ intentId: string;
86
+ transaction: VgsCheckoutTarget;
87
+ }, deps?: ServerMintDeps): Promise<VgsPaymentCredential>;
88
+ /** Report the observed merchant outcome via POST {base}/api/vgs/confirmation. */
89
+ export declare function serverPostConfirmation(base: string, mintToken: string, input: {
90
+ tokenId: string;
91
+ intentId: string;
92
+ transactionStatus: string;
93
+ transactionType: string;
94
+ transactionTimestamp: string;
95
+ transaction: {
96
+ transactionAmount: string;
97
+ transactionCurrencyCode: string;
98
+ };
99
+ }, deps?: ServerMintDeps): Promise<{
100
+ ok: true;
101
+ }>;