@visa/cli 4.1.0-rc.167 → 4.1.0-rc.169

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.
@@ -10,6 +10,27 @@ export interface CheckoutAdapter {
10
10
  }
11
11
  export declare function resolveLocator(page: Page, entry: FieldEntry): Locator;
12
12
  export declare function scrubFillErrorMessage(message: string, value: string): string;
13
+ /**
14
+ * A fill failure in a few words, for a message a human reads.
15
+ *
16
+ * Playwright's error is a multi-line call log — useful in the evidence file,
17
+ * unreadable in a refusal message and in the receipt an operator opens a week
18
+ * later. The refusal names WHICH fields refused; without this it never says
19
+ * WHY, so diagnosing a merchant we cannot drive means either reproducing it or
20
+ * reading someone's evidence JSON. Each cause maps to a different fix:
21
+ *
22
+ * not editable — the input exists but is readonly/disabled at fill time
23
+ * (a custom widget owning the value, or a not-yet-ready
24
+ * form). Typing will not help; the field needs an adapter
25
+ * or a longer wait.
26
+ * not a text field — a non-input element pretending to be one. Needs an
27
+ * adapter that drives the widget.
28
+ * not visible /
29
+ * detached — a re-render race. The reveal loop is the lever.
30
+ *
31
+ * Input is already scrubbed by scrubFillErrorMessage; this only ever shortens.
32
+ */
33
+ export declare function summarizeFillFailure(error: string | undefined): string;
13
34
  /**
14
35
  * The contact record and the page rarely agree on name shape: the record may
15
36
  * carry fullName while the page wants first/last inputs, or vice versa. Derive
@@ -74,6 +74,51 @@ export function scrubFillErrorMessage(message, value) {
74
74
  scrubbed = scrubbed.split(value).join('<redacted>');
75
75
  return scrubbed;
76
76
  }
77
+ /**
78
+ * A fill failure in a few words, for a message a human reads.
79
+ *
80
+ * Playwright's error is a multi-line call log — useful in the evidence file,
81
+ * unreadable in a refusal message and in the receipt an operator opens a week
82
+ * later. The refusal names WHICH fields refused; without this it never says
83
+ * WHY, so diagnosing a merchant we cannot drive means either reproducing it or
84
+ * reading someone's evidence JSON. Each cause maps to a different fix:
85
+ *
86
+ * not editable — the input exists but is readonly/disabled at fill time
87
+ * (a custom widget owning the value, or a not-yet-ready
88
+ * form). Typing will not help; the field needs an adapter
89
+ * or a longer wait.
90
+ * not a text field — a non-input element pretending to be one. Needs an
91
+ * adapter that drives the widget.
92
+ * not visible /
93
+ * detached — a re-render race. The reveal loop is the lever.
94
+ *
95
+ * Input is already scrubbed by scrubFillErrorMessage; this only ever shortens.
96
+ */
97
+ export function summarizeFillFailure(error) {
98
+ if (!error)
99
+ return 'no reason recorded';
100
+ if (/not an? <input>|not.*\[contenteditable\]/i.test(error))
101
+ return 'not a text field';
102
+ if (/element is not visible/i.test(error))
103
+ return 'not visible';
104
+ if (/not attached to the DOM|detached/i.test(error))
105
+ return 'detached from the page';
106
+ if (/element is not enabled/i.test(error))
107
+ return 'disabled';
108
+ if (/not editable/i.test(error)) {
109
+ const timeout = /Timeout (\d+)ms exceeded/i.exec(error);
110
+ return timeout
111
+ ? `not editable within ${Math.round(Number(timeout[1]) / 1000)}s`
112
+ : 'not editable';
113
+ }
114
+ if (/Timeout (\d+)ms exceeded/i.test(error)) {
115
+ const timeout = /Timeout (\d+)ms exceeded/i.exec(error);
116
+ return `timed out after ${Math.round(Number(timeout[1]) / 1000)}s`;
117
+ }
118
+ // Unrecognized: the first line, bounded. Better a clipped real message than a
119
+ // confident wrong summary.
120
+ return error.split('\n')[0].slice(0, 120);
121
+ }
77
122
  const DEFAULT_FILL_TIMEOUT_MS = 5000;
78
123
  async function fillOne(page, role, entry, value, displayValue, fillTimeoutMs) {
79
124
  const base = {
@@ -22,6 +22,7 @@ import { checkMandate, checkMandatePreFill } from './mandate.js';
22
22
  import { EvidenceLog, maskOtp } from './evidence.js';
23
23
  import { observeOutcome } from './outcome.js';
24
24
  import { selectAdapter } from './adapters/index.js';
25
+ import { summarizeFillFailure } from './adapters/generic.js';
25
26
  import { traceHandleFields } from './trace-handles.js';
26
27
  import { readGenericPageAmount } from './amount.js';
27
28
  import { webBotAuthHeadersOrNone } from './web-bot-auth.js';
@@ -1210,7 +1211,23 @@ export async function submitApprovedCheckout(reviewId, opts, store = defaultPrep
1210
1211
  // retryably instead of dangerously.
1211
1212
  if (failedFillRoles.length > 0) {
1212
1213
  evidence.setSnapshotSummary(await snapshotSummary(page));
1213
- return makeResult('partial-fill', state.fields, evidence, requiresAdapter, `required field fill failed: ${failedFillRoles.join(', ')} — not submitting an incomplete form. Nothing was charged.`, undefined, 'required-field-unfillable');
1214
+ // Name the CAUSE per field, not just the field. The refusal is the only
1215
+ // artifact that survives to the operator (a v2 receipt carries no evidence
1216
+ // log), and "city, postalCode refused" without a reason means the next
1217
+ // person has to reproduce a live merchant to learn anything. Each cause
1218
+ // points at a different fix — see summarizeFillFailure.
1219
+ //
1220
+ // Last attempt wins: a role that failed differently across reveal passes
1221
+ // is best described by how it failed when we finally gave up on it.
1222
+ const lastFillError = (role) => {
1223
+ const errors = evidence
1224
+ .getSteps()
1225
+ .filter((step) => step.type === 'field-fill' && step.data.ok === false && step.data.role === role)
1226
+ .map((step) => (typeof step.data.error === 'string' ? step.data.error : undefined));
1227
+ return errors[errors.length - 1];
1228
+ };
1229
+ const reasons = failedFillRoles.map((role) => `${role} (${summarizeFillFailure(lastFillError(role))})`);
1230
+ return makeResult('partial-fill', state.fields, evidence, requiresAdapter, `required field fill failed: ${reasons.join(', ')} — not submitting an incomplete form. Nothing was charged.`, undefined, 'required-field-unfillable');
1214
1231
  }
1215
1232
  if (!submit) {
1216
1233
  evidence.setSnapshotSummary(await snapshotSummary(page));
@@ -58,9 +58,11 @@ const defaultSleep = (ms) => new Promise((r) => {
58
58
  function defaultOpenUrl(url) {
59
59
  // Best-effort convenience only — the URL is always surfaced via `log`/
60
60
  // `onApprovalUrl`, so this must never throw or hang if there is no browser.
61
- // `CHECKOUT_SKIP_BROWSER_OPEN=1` disables it (headless/agent hosts where
62
- // launching a browser on the WRONG machine is pointless or noisy).
63
- if (process.env.CHECKOUT_SKIP_BROWSER_OPEN === '1')
61
+ // `CHECKOUT_SKIP_BROWSER_OPEN=1` or `VISA_SUPPRESS_BROWSER=true|1` disables it
62
+ // (headless/agent hosts where launching a browser on the WRONG machine is pointless or noisy).
63
+ if (process.env.CHECKOUT_SKIP_BROWSER_OPEN === '1' ||
64
+ process.env.VISA_SUPPRESS_BROWSER === '1' ||
65
+ process.env.VISA_SUPPRESS_BROWSER === 'true')
64
66
  return;
65
67
  // Platform-appropriate opener; unknown platforms just skip (the URL is logged).
66
68
  const opener = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start ""' : 'xdg-open';
@@ -44,7 +44,12 @@ export function buildReceipt(input) {
44
44
  // retry.
45
45
  'The charge may have gone through. Confirm with the merchant before retrying.'
46
46
  : result.outcome === 'partial-fill'
47
- ? 'Nothing was submitted and nothing was charged. Safe to try again once the checkout can be filled.'
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.`
48
53
  : 'Review this outcome before retrying.';
49
54
  const recoveryActions = reconciliation.reasons.length > 0 ? reconciliation.reasons : [fallbackAction];
50
55
  const cardLast4 = input.cardLast4 && /^\d{4}$/.test(input.cardLast4) ? input.cardLast4 : null;