@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,104 @@
1
+ // Evidence log. A timestamped JSONL trail of everything the executor did:
2
+ // navigation, adapter choice, each field fill (with confidence + source),
3
+ // the mandate verdict, the submit, and the final outcome, plus a compact
4
+ // accessibility snapshot of the end state.
5
+ //
6
+ // Money-adjacent hygiene rule: the full PAN, the cvc, the card expiry, and any
7
+ // one-time verification code NEVER enter the log. PANs are masked to last-4;
8
+ // cvc, expiry, and OTP codes are redacted entirely. maskPan/maskCvc/maskExpiry/
9
+ // maskOtp are the only sanctioned way to put such a value anywhere near a log
10
+ // line. (receipt.ts redactPanLikeDigits only catches 12-19-digit PANs, so a
11
+ // 4-8-digit OTP would slip straight through — maskOtp at the fill site is the
12
+ // load-bearing guarantee it never reaches the evidence log.) Contact PII
13
+ // (cardholder name, email, address, ...) is redacted via redactContact: the
14
+ // log records THAT a field was filled, never the personal value.
15
+ // Mask a PAN to its last four digits. Non-digits are stripped for the count.
16
+ export function maskPan(pan) {
17
+ const digits = (pan || '').replace(/\D/g, '');
18
+ if (digits.length <= 4)
19
+ return '****';
20
+ return `**** **** **** ${digits.slice(-4)}`;
21
+ }
22
+ // The cvc is never displayed, even masked by length.
23
+ export function maskCvc(_cvc) {
24
+ return 'redacted';
25
+ }
26
+ // The expiry is credential material too (one of the three keyable components
27
+ // alongside the DPAN and the DAVV) — it never enters the log, in any format.
28
+ export function maskExpiry() {
29
+ return 'redacted';
30
+ }
31
+ // A merchant one-time verification code is single-use secret material — it
32
+ // never enters the log, in any format. Used at the oneTimeCode fill site so
33
+ // the code is masked exactly as cvc/PAN are (see the header note above).
34
+ export function maskOtp() {
35
+ return 'redacted';
36
+ }
37
+ // The registrable domain (approx eTLD+1) of an email address or hostname, for
38
+ // the caller-side from-domain guard on verification links: before navigating a
39
+ // link parsed from an untrusted OTP email, require the link host to match the
40
+ // message sender's domain. extract.ts guarantees mechanical extraction, NOT
41
+ // navigation safety — this guard is the anti-injection backstop.
42
+ export function hostOf(hostOrEmail) {
43
+ return (hostOrEmail.split('@').pop() ?? '').trim().toLowerCase().replace(/\.$/, '');
44
+ }
45
+ // Strict bidirectional host-suffix match (exact / child / parent). Deliberately
46
+ // NOT approximate eTLD+1 — that collapses shared-tenant hosts (`x.myshopify.com`,
47
+ // `x.co.uk`) to a common suffix and lets a sibling tenant match; siblings never
48
+ // match here. Fails SAFE: an unrelated-but-legitimate sender is skipped, not
49
+ // trusted.
50
+ function hostsRelated(a, b) {
51
+ const x = hostOf(a);
52
+ const y = hostOf(b);
53
+ if (!x || !y)
54
+ return false;
55
+ return x === y || x.endsWith('.' + y) || y.endsWith('.' + x);
56
+ }
57
+ // Whether a verification LINK is safe to navigate: the sender must NOT be the
58
+ // unauthenticated inbound variant (AgentMail marks spoofable inbound with an
59
+ // `.unauthenticated` sub-label), and the link host must belong to the sender's
60
+ // domain. Returns false to SKIP a link that fails either check.
61
+ export function verificationLinkAllowed(link, messageFrom) {
62
+ if (/\.unauthenticated\b/i.test(messageFrom))
63
+ return false;
64
+ let linkHost;
65
+ try {
66
+ linkHost = new URL(link).hostname;
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ return hostsRelated(linkHost, messageFrom);
72
+ }
73
+ // Contact values (cardholder name, email, address, ...) are PII and never
74
+ // enter the log raw either. Email keeps its domain for debuggability;
75
+ // everything else becomes a bare presence marker.
76
+ export function redactContact(role, value) {
77
+ if (!value)
78
+ return '';
79
+ if (role === 'email') {
80
+ const at = value.lastIndexOf('@');
81
+ return at > 0 ? `<redacted>@${value.slice(at + 1)}` : '<redacted>';
82
+ }
83
+ return '<redacted>';
84
+ }
85
+ export class EvidenceLog {
86
+ steps = [];
87
+ snapshotSummary = null;
88
+ step(type, data = {}) {
89
+ this.steps.push({ ts: new Date().toISOString(), type, data });
90
+ }
91
+ setSnapshotSummary(summary) {
92
+ this.snapshotSummary = summary;
93
+ }
94
+ getSteps() {
95
+ return this.steps;
96
+ }
97
+ // Newline-delimited JSON. One object per line.
98
+ toJSONL() {
99
+ return this.steps.map((s) => JSON.stringify(s)).join('\n');
100
+ }
101
+ toObject() {
102
+ return { steps: this.steps, snapshotSummary: this.snapshotSummary };
103
+ }
104
+ }
@@ -0,0 +1,215 @@
1
+ import type { Browser, BrowserContext, Page } from 'playwright-core';
2
+ import { type FieldMap } from './detect.js';
3
+ import { type Mandate } from './mandate.js';
4
+ import type { Instrument } from './instrument.js';
5
+ import type { Contact, OtpResolver } from './types.js';
6
+ import { EvidenceLog } from './evidence.js';
7
+ import { type ObservedOutcome } from './outcome.js';
8
+ import { type WebBotAuthConfig } from './web-bot-auth.js';
9
+ export { minorFromDecimal, pageCurrency } from './amount.js';
10
+ export type CheckoutMode = 'dry-run' | 'submit';
11
+ export type CheckoutOutcome = 'reviewed-dry-run'
12
+ /** Historical receipt value from the credential-disclosing dry-run. */
13
+ | 'filled-dry-run' | 'partial-fill' | 'adapter-required' | 'confirmed' | 'declined' | 'action-required' | 'cancelled' | 'blocked-by-mandate'
14
+ /**
15
+ * KNOWN-NOT-CHARGED. Every `failed` path ends before the pay control was
16
+ * clicked (or before a credential existed at all), so a caller may retry it
17
+ * without risking a second charge.
18
+ */
19
+ | 'failed'
20
+ /**
21
+ * SUBMITTED, OUTCOME UNKNOWN — the pay control WAS clicked and neither a
22
+ * confirmation nor a decline was observed before the deadline. The charge may
23
+ * have captured. NEVER retry this automatically.
24
+ *
25
+ * This case used to be reported as `failed`, and the difference is not
26
+ * academic: on 2026-08-17 a whop.com checkout returned `failed` here, the
27
+ * caller read that as "nothing happened" and re-ran the purchase, and the
28
+ * second run drew a second $5 against the owner's mandate. `outcome.ts`
29
+ * already treats an unrecognized post-submit page as the SAFE direction
30
+ * ('unknown' → operator verification); collapsing it into `failed` at the
31
+ * boundary is what threw that safety away. The distinction has to survive all
32
+ * the way to the value consumers branch on.
33
+ */
34
+ | 'unverified';
35
+ /** Stable machine-readable cause for an expected terminal checkout result. */
36
+ export type CheckoutFailureCode = 'card-number-field-unavailable' | 'human-action-required' | 'mandate-blocked'
37
+ /** A detected, visible field we held a value for refused every fill attempt. */
38
+ | 'required-field-unfillable';
39
+ export type CredentialLifecycle = 'not-requested' | 'minted-not-exposed' | 'partially-exposed' | 'fully-filled';
40
+ export type CredentialTiming = {
41
+ approvedAt?: string;
42
+ credentialMintedAt?: string;
43
+ credentialExpiresAt?: string;
44
+ fillCompletedAt?: string;
45
+ };
46
+ export type CheckoutResult = {
47
+ outcome: CheckoutOutcome;
48
+ fields: FieldMap;
49
+ evidence: EvidenceLog;
50
+ confirmationRef?: string;
51
+ requiresAdapter: string[];
52
+ credentialLifecycle: CredentialLifecycle;
53
+ credentialTiming: CredentialTiming;
54
+ failureCode?: CheckoutFailureCode;
55
+ detail?: string;
56
+ };
57
+ export type PrepareCheckoutOptions = {
58
+ url: string;
59
+ mandate: Mandate;
60
+ browser: Browser;
61
+ contact?: Contact;
62
+ amountMinor?: number;
63
+ currency?: string;
64
+ debugShotsDir?: string;
65
+ webBotAuth?: WebBotAuthConfig | null;
66
+ };
67
+ export type RunCheckoutOptions = PrepareCheckoutOptions & {
68
+ instrument: Instrument;
69
+ contact: Contact;
70
+ mode: CheckoutMode;
71
+ outcomeDeadlineMs?: number;
72
+ resolveEmailOtp?: OtpResolver;
73
+ };
74
+ export type CheckoutReview = {
75
+ id: string;
76
+ url: string;
77
+ merchantHost: string;
78
+ amountMinor: number;
79
+ currency: string;
80
+ mandateMaxAmountMinor: number;
81
+ mandateExpiresAt: string;
82
+ submitTarget: string | null;
83
+ submitTargetFingerprint: Readonly<CheckoutSubmitTargetFingerprint> | null;
84
+ detectedRoles: readonly string[];
85
+ };
86
+ export type CheckoutSubmitTargetFingerprint = {
87
+ kind: 'submit-control' | 'text-button';
88
+ label: string;
89
+ elementTag: string;
90
+ elementId: string | null;
91
+ elementName: string | null;
92
+ elementType: string | null;
93
+ formAction: string | null;
94
+ formMethod: string | null;
95
+ formTarget: string | null;
96
+ };
97
+ export type PreparedCheckout = {
98
+ readonly review: Readonly<CheckoutReview>;
99
+ readonly fields: Readonly<FieldMap>;
100
+ readonly evidence: EvidenceLog;
101
+ readonly requiresAdapter: readonly string[];
102
+ };
103
+ export type PrepareCheckoutResult = {
104
+ status: 'ready';
105
+ checkout: PreparedCheckout;
106
+ } | {
107
+ status: 'finished';
108
+ result: CheckoutResult;
109
+ };
110
+ export type CheckoutApproval = {
111
+ approved: true;
112
+ reviewId: string;
113
+ };
114
+ export type SubmitApprovedCheckoutOptions = {
115
+ approval: CheckoutApproval;
116
+ instrument: Instrument;
117
+ contact: Contact;
118
+ mode: CheckoutMode;
119
+ outcomeDeadlineMs?: number;
120
+ challengeHoldMs?: number;
121
+ onChallengeHold?: (signal: string | null) => void;
122
+ resolveEmailOtp?: OtpResolver;
123
+ };
124
+ export type SubmitCandidateMeta = {
125
+ label: string;
126
+ ariaHidden: boolean;
127
+ tabIndex: number | null;
128
+ visible: boolean;
129
+ area: number;
130
+ };
131
+ export declare function preferredSubmitIndex(cands: readonly SubmitCandidateMeta[], opts?: {
132
+ allowDeferred?: boolean;
133
+ }): number;
134
+ export declare function snapshotOrigin(rawUrl: string): string;
135
+ export type PreparedCheckoutSession = {
136
+ checkout: PreparedCheckout;
137
+ context: BrowserContext;
138
+ page: Page;
139
+ options: PrepareCheckoutOptions;
140
+ evidence: EvidenceLog;
141
+ fields: FieldMap;
142
+ requiresAdapter: Set<string>;
143
+ };
144
+ export type PreparedCheckoutSessionStore = {
145
+ put: (reviewId: string, state: PreparedCheckoutSession) => void;
146
+ take: (reviewId: string) => PreparedCheckoutSession | undefined;
147
+ peek: (reviewId: string) => PreparedCheckoutSession | undefined;
148
+ pendingCleanupReviewIds: () => readonly string[];
149
+ reapExpired: (nowMs?: number) => Promise<number>;
150
+ dispose: () => Promise<void>;
151
+ };
152
+ export type InMemoryPreparedCheckoutStoreOptions = {
153
+ ttlMs?: number;
154
+ cleanupRetryMs?: number;
155
+ now?: () => number;
156
+ };
157
+ export declare const DEFAULT_PREPARED_CHECKOUT_TTL_MS: number;
158
+ export declare const DEFAULT_PREPARED_CHECKOUT_CLEANUP_RETRY_MS = 5000;
159
+ export declare class InMemoryPreparedCheckoutStore implements PreparedCheckoutSessionStore {
160
+ private readonly entries;
161
+ private readonly cleanupPending;
162
+ private readonly ttlMs;
163
+ private readonly cleanupRetryMs;
164
+ private readonly now;
165
+ private reaper;
166
+ constructor(options?: InMemoryPreparedCheckoutStoreOptions);
167
+ put(reviewId: string, state: PreparedCheckoutSession): void;
168
+ take(reviewId: string): PreparedCheckoutSession | undefined;
169
+ peek(reviewId: string): PreparedCheckoutSession | undefined;
170
+ pendingCleanupReviewIds(): readonly string[];
171
+ reapExpired(nowMs?: number): Promise<number>;
172
+ dispose(): Promise<void>;
173
+ private queueCleanup;
174
+ private scheduleReaper;
175
+ private closeState;
176
+ }
177
+ export declare function reconcileHeldOutcome(original: ObservedOutcome, held: ObservedOutcome): ObservedOutcome;
178
+ export declare function debugShotMaskPlan(fields: FieldMap): {
179
+ skipReason: string | null;
180
+ maskLocators: string[];
181
+ maskFrames: {
182
+ frame: string;
183
+ locator: string;
184
+ }[];
185
+ };
186
+ export declare function isStripeLinkConsumerRequest(url: string): boolean;
187
+ export declare function suppressStripeLink(page: Page, evidence: EvidenceLog): Promise<void>;
188
+ export type LinkQuietResult = {
189
+ fired: boolean;
190
+ waitedMs: number;
191
+ };
192
+ /**
193
+ * Wait for the suppressed Stripe Link lookup to fire and settle BEFORE the
194
+ * submit click. Stripe debounces its consumer-session lookup ~300ms after the
195
+ * email input changes; our fill→click gap is single-digit ms, so the (aborted)
196
+ * lookup used to land INSIDE Stripe's in-flight submit chain and kill it
197
+ * silently — the click looked accepted but tokenization never ran and the page
198
+ * sat on the form until the outcome deadline (#5879: three identical live
199
+ * stalls at donate.stripe.com). Verified live A/B on that page: instant click →
200
+ * dead submit, no /v1/payment_methods; lookup settled first → tokenization and
201
+ * the confirm step both reached.
202
+ *
203
+ * If the lookup already fired, only the short settle applies (lets Stripe's
204
+ * abort handling unwind). If it never fires — non-Link page variants, no email
205
+ * field — the bound expires and the click proceeds as before.
206
+ */
207
+ export declare function waitForLinkLookupQuiet(page: Page, opts?: {
208
+ boundMs?: number;
209
+ settleMs?: number;
210
+ delay?: (ms: number) => Promise<void>;
211
+ }): Promise<LinkQuietResult>;
212
+ export declare function prepareCheckout(opts: PrepareCheckoutOptions, store?: PreparedCheckoutSessionStore): Promise<PrepareCheckoutResult>;
213
+ export declare function submitApprovedCheckout(reviewId: string, opts: SubmitApprovedCheckoutOptions, store?: PreparedCheckoutSessionStore): Promise<CheckoutResult>;
214
+ export declare function cancelPreparedCheckout(reviewId: string, detail?: string, store?: PreparedCheckoutSessionStore): Promise<CheckoutResult>;
215
+ export declare function runCheckout(opts: RunCheckoutOptions, store?: PreparedCheckoutSessionStore): Promise<CheckoutResult>;