@visa/cli 4.1.0-rc.26 → 4.1.0-rc.260
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.
- package/README.md +202 -46
- package/dist/checkout-engine/adapters/generic.d.ts +69 -0
- package/dist/checkout-engine/adapters/generic.js +383 -58
- package/dist/checkout-engine/adapters/index.d.ts +4 -1
- package/dist/checkout-engine/adapters/index.js +10 -3
- package/dist/checkout-engine/adapters/shopify.d.ts +80 -0
- package/dist/checkout-engine/adapters/shopify.js +688 -0
- package/dist/checkout-engine/amount.d.ts +15 -0
- package/dist/checkout-engine/amount.js +72 -0
- package/dist/checkout-engine/browser-launch.d.ts +9 -4
- package/dist/checkout-engine/browser-launch.js +19 -4
- package/dist/checkout-engine/browserbase-browser.d.ts +24 -0
- package/dist/checkout-engine/browserbase-browser.js +186 -0
- package/dist/checkout-engine/cli-engine.d.ts +206 -32
- package/dist/checkout-engine/cli-engine.js +772 -216
- package/dist/checkout-engine/confirmed-merchants.d.ts +31 -0
- package/dist/checkout-engine/confirmed-merchants.js +165 -0
- package/dist/checkout-engine/detect.d.ts +1 -1
- package/dist/checkout-engine/detect.js +6 -0
- package/dist/checkout-engine/evidence.d.ts +1 -1
- package/dist/checkout-engine/executor.d.ts +61 -3
- package/dist/checkout-engine/executor.js +550 -144
- package/dist/checkout-engine/hosted-approval.d.ts +69 -9
- package/dist/checkout-engine/hosted-approval.js +211 -21
- package/dist/checkout-engine/index.d.ts +6 -2
- package/dist/checkout-engine/index.js +5 -1
- package/dist/checkout-engine/instrument.d.ts +6 -0
- package/dist/checkout-engine/known-merchants.d.ts +10 -0
- package/dist/checkout-engine/known-merchants.js +38 -0
- package/dist/checkout-engine/live-fill-approval.d.ts +5 -11
- package/dist/checkout-engine/live-fill-approval.js +20 -34
- package/dist/checkout-engine/mandate/card-mandate.d.ts +6 -2
- package/dist/checkout-engine/mandate/card-mandate.js +10 -5
- package/dist/checkout-engine/mandate/mandate-ledger.d.ts +63 -23
- package/dist/checkout-engine/mandate/mandate-ledger.js +124 -17
- package/dist/checkout-engine/receipt-dir.d.ts +6 -0
- package/dist/checkout-engine/receipt-dir.js +8 -0
- package/dist/checkout-engine/receipt.d.ts +56 -2
- package/dist/checkout-engine/receipt.js +55 -16
- package/dist/checkout-engine/shopify-primary-domain.d.ts +25 -0
- package/dist/checkout-engine/shopify-primary-domain.js +96 -0
- package/dist/checkout-engine/trace-handles.d.ts +8 -0
- package/dist/checkout-engine/trace-handles.js +12 -0
- package/dist/checkout-engine/types.d.ts +15 -2
- package/dist/checkout-engine/unresolved-charges.d.ts +34 -0
- package/dist/checkout-engine/unresolved-charges.js +134 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +26 -7
- package/dist/checkout-engine/vgs-gateway/server-mint-client.js +43 -3
- package/dist/checkout-engine/vgs-live-instrument.d.ts +11 -35
- package/dist/checkout-engine/vgs-live-instrument.js +14 -74
- package/dist/checkout-engine/vic-confirmation.d.ts +18 -0
- package/dist/checkout-engine/vic-confirmation.js +9 -3
- package/dist/checkout-engine/web-bot-auth.d.ts +98 -0
- package/dist/checkout-engine/web-bot-auth.js +218 -0
- package/dist/cli.js +899 -387
- package/dist/mcp-apps/ucp-checkout.html +280 -0
- package/dist/mcp-server/index.js +725 -254
- package/dist/merchant-ucp-mcp/index.js +6 -0
- package/dist/skills/pair-visa-agent/RUNTIMES.md +122 -79
- package/dist/skills/pair-visa-agent/SKILL.md +433 -318
- package/dist/skills/pair-visa-agent/scripts/__tests__/setup.test.mjs +407 -0
- package/dist/skills/pair-visa-agent/scripts/setup.mjs +310 -30
- package/dist/skills/visa-shopify-checkout/SKILL.md +122 -0
- package/dist/skills/visa-shopify-checkout/references/evidence-and-states.md +37 -0
- package/dist/skills/visa-ucp-shopping/SKILL.md +86 -0
- package/dist/subway-direct.mjs +1 -0
- package/install.ps1 +7 -6
- package/install.sh +3 -3
- package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
- package/package.json +31 -28
- package/server.json +4 -4
- package/dist/checkout-engine/inline-target.d.ts +0 -13
- package/dist/checkout-engine/inline-target.js +0 -37
- package/dist/checkout-engine/pay-args.d.ts +0 -14
- package/dist/checkout-engine/pay-args.js +0 -44
- package/dist/checkout-engine/pay.d.ts +0 -1
- package/dist/checkout-engine/pay.js +0 -13
- package/dist/checkout-engine/repo-env.d.ts +0 -11
- package/dist/checkout-engine/repo-env.js +0 -23
- package/dist/checkout-engine/run-live-fill.d.ts +0 -1
- package/dist/checkout-engine/run-live-fill.js +0 -493
- package/dist/checkout-engine/vgs-gateway/fetch-credential.d.mts +0 -74
- package/dist/checkout-engine/vgs-gateway/fetch-credential.mjs +0 -248
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { KNOWN_MERCHANT_IDENTITIES } from './known-merchants.js';
|
|
3
4
|
import { submitClickedWithoutConfirmation } from './live-fill-approval.js';
|
|
4
5
|
/**
|
|
5
6
|
* What the operator still owes after this run. Empty for a clean dry-run fill
|
|
6
7
|
* and for a definitive submit outcome whose VIC confirmation posted.
|
|
7
8
|
*/
|
|
8
|
-
function reconciliationFor(result, vicConfirmation) {
|
|
9
|
+
function reconciliationFor(result, vicConfirmation, mode) {
|
|
9
10
|
const reasons = [];
|
|
10
11
|
if (submitClickedWithoutConfirmation(result)) {
|
|
11
12
|
reasons.push('the pay control was clicked but no definitive outcome was observed — ' +
|
|
@@ -21,7 +22,7 @@ function reconciliationFor(result, vicConfirmation) {
|
|
|
21
22
|
reasons.push('confirmed without a merchant confirmation reference — ' +
|
|
22
23
|
'record the order number from the merchant dashboard');
|
|
23
24
|
}
|
|
24
|
-
if (result.outcome === 'action-required') {
|
|
25
|
+
if (mode === 'submit' && result.outcome === 'action-required') {
|
|
25
26
|
reasons.push('an issuer verification challenge was shown and not completed — ' +
|
|
26
27
|
'finish the purchase manually if still wanted, or confirm with the merchant that no order exists');
|
|
27
28
|
}
|
|
@@ -29,23 +30,60 @@ function reconciliationFor(result, vicConfirmation) {
|
|
|
29
30
|
}
|
|
30
31
|
export function buildReceipt(input) {
|
|
31
32
|
const { result } = input;
|
|
33
|
+
const reconciliation = reconciliationFor(result, input.vicConfirmation, input.mode);
|
|
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
|
+
const capability = result.failureCode || result.requiresAdapter.length > 0
|
|
59
|
+
? {
|
|
60
|
+
failureCode: result.failureCode ?? null,
|
|
61
|
+
detectedRoles: Object.keys(result.fields).sort(),
|
|
62
|
+
requiresAdapter: [...result.requiresAdapter].sort(),
|
|
63
|
+
}
|
|
64
|
+
: null;
|
|
32
65
|
return {
|
|
33
|
-
schema: 'checkout-agent-receipt/
|
|
66
|
+
schema: 'checkout-agent-receipt/v2',
|
|
34
67
|
recordedAt: (input.recordedAt ?? new Date()).toISOString(),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
merchant: { name: input.merchant.name, host: input.merchant.host },
|
|
68
|
+
...(input.observationId ? { observationId: input.observationId } : {}),
|
|
69
|
+
...(input.observationId && input.reviewId === null ? { phase: 'review' } : {}),
|
|
70
|
+
merchant: { name: input.merchant.name, host: input.merchant.host, checkoutUrl },
|
|
38
71
|
transaction: input.transaction,
|
|
39
72
|
outcome: result.outcome,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
73
|
+
agent: input.agentName ? { name: input.agentName } : null,
|
|
74
|
+
rail: { type: 'card', cardLast4 },
|
|
75
|
+
network: { confirmation: networkConfirmation },
|
|
76
|
+
...(capability ? { capability } : {}),
|
|
77
|
+
receiptId: input.reviewId,
|
|
78
|
+
reference: result.confirmationRef ?? null,
|
|
79
|
+
recovery: {
|
|
80
|
+
required: reconciliation.required,
|
|
81
|
+
// A clean dry-run did not submit anything, so repeating inspection is
|
|
82
|
+
// safe. Every submit outcome requires either no retry or owner review.
|
|
83
|
+
retrySafe: input.mode === 'dry-run' && !reconciliation.required,
|
|
84
|
+
action: recoveryActions[0],
|
|
85
|
+
actions: recoveryActions,
|
|
86
|
+
},
|
|
49
87
|
};
|
|
50
88
|
}
|
|
51
89
|
function luhnValid(digits) {
|
|
@@ -88,7 +126,8 @@ export function serializeReceipt(receipt) {
|
|
|
88
126
|
}
|
|
89
127
|
export function receiptFileName(receipt) {
|
|
90
128
|
const ts = receipt.recordedAt.replace(/[:.]/g, '-');
|
|
91
|
-
const
|
|
129
|
+
const receiptId = receipt.schema === 'checkout-agent-receipt/v1' ? receipt.reviewId : receipt.receiptId;
|
|
130
|
+
const review = (receiptId ?? 'no-review').replace(/[^A-Za-z0-9-]/g, '');
|
|
92
131
|
return `receipt-${ts}-${review || 'no-review'}.json`;
|
|
93
132
|
}
|
|
94
133
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Response } from 'playwright-core';
|
|
2
|
+
export type NavigationRedirectEvidence = {
|
|
3
|
+
sourceUrl: string;
|
|
4
|
+
status: number;
|
|
5
|
+
location: string | null;
|
|
6
|
+
redirectReason: string | null;
|
|
7
|
+
poweredBy: string | null;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Resolve Shopify's permanent `*.myshopify.com` identity to its configured
|
|
11
|
+
* primary storefront host using evidence from the navigation redirect chain.
|
|
12
|
+
*
|
|
13
|
+
* This deliberately does not treat a generic redirect, matching HTML, DNS, or
|
|
14
|
+
* a shared Shopify CDN as merchant ownership proof. The only accepted cross-host
|
|
15
|
+
* hop must originate on the mandate-bound `myshopify.com` host over HTTPS and
|
|
16
|
+
* carry Shopify's exact `primary_domain_redirection` response signal directly
|
|
17
|
+
* to the final checkout host.
|
|
18
|
+
*/
|
|
19
|
+
export declare function shopifyPrimaryDomainAlias(args: {
|
|
20
|
+
mandateHost: string | undefined;
|
|
21
|
+
initialUrl: string;
|
|
22
|
+
finalUrl: string;
|
|
23
|
+
redirects: readonly NavigationRedirectEvidence[];
|
|
24
|
+
}): string | null;
|
|
25
|
+
export declare function navigationRedirectEvidence(finalResponse: Response | null): Promise<NavigationRedirectEvidence[]>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const MYSHOPIFY_HOST = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.myshopify\.com$/;
|
|
2
|
+
function hostname(value) {
|
|
3
|
+
try {
|
|
4
|
+
return new URL(value).hostname.toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
try {
|
|
8
|
+
return new URL(`https://${value}`).hostname.toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function redirectTargetHost(redirect) {
|
|
16
|
+
if (!redirect.location)
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
return new URL(redirect.location, redirect.sourceUrl).hostname.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve Shopify's permanent `*.myshopify.com` identity to its configured
|
|
27
|
+
* primary storefront host using evidence from the navigation redirect chain.
|
|
28
|
+
*
|
|
29
|
+
* This deliberately does not treat a generic redirect, matching HTML, DNS, or
|
|
30
|
+
* a shared Shopify CDN as merchant ownership proof. The only accepted cross-host
|
|
31
|
+
* hop must originate on the mandate-bound `myshopify.com` host over HTTPS and
|
|
32
|
+
* carry Shopify's exact `primary_domain_redirection` response signal directly
|
|
33
|
+
* to the final checkout host.
|
|
34
|
+
*/
|
|
35
|
+
export function shopifyPrimaryDomainAlias(args) {
|
|
36
|
+
if (!args.mandateHost)
|
|
37
|
+
return null;
|
|
38
|
+
let initial;
|
|
39
|
+
let final;
|
|
40
|
+
try {
|
|
41
|
+
initial = new URL(args.initialUrl);
|
|
42
|
+
final = new URL(args.finalUrl);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (initial.protocol !== 'https:' || final.protocol !== 'https:')
|
|
48
|
+
return null;
|
|
49
|
+
const mandateHost = hostname(args.mandateHost);
|
|
50
|
+
const initialHost = initial.hostname.toLowerCase();
|
|
51
|
+
const finalHost = final.hostname.toLowerCase();
|
|
52
|
+
if (!mandateHost || mandateHost !== initialHost || !MYSHOPIFY_HOST.test(initialHost))
|
|
53
|
+
return null;
|
|
54
|
+
if (initialHost === finalHost)
|
|
55
|
+
return null;
|
|
56
|
+
const crossHostRedirects = args.redirects.filter((redirect) => {
|
|
57
|
+
const sourceHost = hostname(redirect.sourceUrl);
|
|
58
|
+
const targetHost = redirectTargetHost(redirect);
|
|
59
|
+
return sourceHost !== null && targetHost !== null && sourceHost !== targetHost;
|
|
60
|
+
});
|
|
61
|
+
if (crossHostRedirects.length !== 1)
|
|
62
|
+
return null;
|
|
63
|
+
const redirect = crossHostRedirects[0];
|
|
64
|
+
const source = new URL(redirect.sourceUrl);
|
|
65
|
+
const target = redirect.location ? new URL(redirect.location, source) : null;
|
|
66
|
+
if (source.protocol !== 'https:' ||
|
|
67
|
+
source.hostname.toLowerCase() !== initialHost ||
|
|
68
|
+
!target ||
|
|
69
|
+
target.protocol !== 'https:' ||
|
|
70
|
+
target.hostname.toLowerCase() !== finalHost ||
|
|
71
|
+
![301, 302, 307, 308].includes(redirect.status) ||
|
|
72
|
+
redirect.redirectReason?.toLowerCase() !== 'primary_domain_redirection' ||
|
|
73
|
+
redirect.poweredBy?.toLowerCase() !== 'shopify') {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return finalHost;
|
|
77
|
+
}
|
|
78
|
+
export async function navigationRedirectEvidence(finalResponse) {
|
|
79
|
+
const redirects = [];
|
|
80
|
+
let request = finalResponse?.request().redirectedFrom() ?? null;
|
|
81
|
+
while (request) {
|
|
82
|
+
const response = await request.response();
|
|
83
|
+
if (response) {
|
|
84
|
+
const headers = response.headers();
|
|
85
|
+
redirects.push({
|
|
86
|
+
sourceUrl: request.url(),
|
|
87
|
+
status: response.status(),
|
|
88
|
+
location: headers.location ?? null,
|
|
89
|
+
redirectReason: headers['x-redirect-reason'] ?? null,
|
|
90
|
+
poweredBy: headers['powered-by'] ?? null,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
request = request.redirectedFrom();
|
|
94
|
+
}
|
|
95
|
+
return redirects.reverse();
|
|
96
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export type
|
|
2
|
-
email?: string;
|
|
1
|
+
export type PostalAddress = {
|
|
3
2
|
firstName?: string;
|
|
4
3
|
lastName?: string;
|
|
5
4
|
fullName?: string;
|
|
@@ -10,6 +9,11 @@ export type Contact = {
|
|
|
10
9
|
postalCode?: string;
|
|
11
10
|
country?: string;
|
|
12
11
|
};
|
|
12
|
+
export type Contact = PostalAddress & {
|
|
13
|
+
email?: string;
|
|
14
|
+
phone?: string;
|
|
15
|
+
billingAddress?: PostalAddress;
|
|
16
|
+
};
|
|
13
17
|
export type FilledField = {
|
|
14
18
|
role: string;
|
|
15
19
|
locator: string;
|
|
@@ -19,10 +23,19 @@ export type FilledField = {
|
|
|
19
23
|
value: string;
|
|
20
24
|
ok: boolean;
|
|
21
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;
|
|
22
34
|
};
|
|
23
35
|
export type FillResult = {
|
|
24
36
|
ok: boolean;
|
|
25
37
|
filled: FilledField[];
|
|
38
|
+
detail?: string;
|
|
26
39
|
};
|
|
27
40
|
export type OtpRequest = {
|
|
28
41
|
/** ISO watermark captured BEFORE the click that triggers the OTP email. */
|
|
@@ -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,134 @@
|
|
|
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
|
+
// Terminal review observations are useful capability evidence, but no pay
|
|
65
|
+
// control, credential, or submission exists yet. They must never poison the
|
|
66
|
+
// double-charge ledger even when the observed page showed a Shop Pay or 3DS
|
|
67
|
+
// action-required surface.
|
|
68
|
+
if (receipt.schema === 'checkout-agent-receipt/v2' &&
|
|
69
|
+
(receipt.phase === 'review' ||
|
|
70
|
+
(typeof receipt.observationId === 'string' && receipt.receiptId === null))) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (typeof receipt.outcome !== 'string' || !MAY_HAVE_CHARGED_OUTCOMES.has(receipt.outcome)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (typeof receipt.recordedAt !== 'string' || Number.isNaN(Date.parse(receipt.recordedAt))) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const host = receipt.merchant?.host;
|
|
80
|
+
if (typeof host !== 'string' || host.length === 0)
|
|
81
|
+
return null;
|
|
82
|
+
const transaction = receipt.transaction;
|
|
83
|
+
if (typeof transaction?.amount !== 'string')
|
|
84
|
+
return null;
|
|
85
|
+
if (typeof transaction.currency !== 'string')
|
|
86
|
+
return null;
|
|
87
|
+
// A receipt whose amount cannot be compared cannot gate a retry on amount, and
|
|
88
|
+
// a guard that silently matched every amount would be worse than none.
|
|
89
|
+
if (typeof transaction.amountMinor !== 'number' || !Number.isFinite(transaction.amountMinor)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
recordedAt: receipt.recordedAt,
|
|
94
|
+
host,
|
|
95
|
+
amount: transaction.amount,
|
|
96
|
+
amountMinor: transaction.amountMinor,
|
|
97
|
+
currency: transaction.currency,
|
|
98
|
+
outcome: receipt.outcome,
|
|
99
|
+
receiptFile,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Local attempts that may have charged, newest first.
|
|
104
|
+
*
|
|
105
|
+
* Never throws: a missing directory (nothing has ever been checked out here)
|
|
106
|
+
* and an unreadable one both read as "no unresolved charges". The caller
|
|
107
|
+
* decides what an empty answer means — see the fail-open note at its call site.
|
|
108
|
+
*/
|
|
109
|
+
export async function readUnresolvedCharges(receiptDir = RECEIPT_DIR) {
|
|
110
|
+
let names;
|
|
111
|
+
try {
|
|
112
|
+
names = await readdir(receiptDir);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
const charges = [];
|
|
118
|
+
for (const name of names) {
|
|
119
|
+
if (!name.endsWith('.json'))
|
|
120
|
+
continue;
|
|
121
|
+
let raw;
|
|
122
|
+
try {
|
|
123
|
+
raw = await readFile(join(receiptDir, name), 'utf8');
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const charge = parseUnresolved(raw, name);
|
|
129
|
+
if (charge)
|
|
130
|
+
charges.push(charge);
|
|
131
|
+
}
|
|
132
|
+
charges.sort((left, right) => (left.recordedAt < right.recordedAt ? 1 : -1));
|
|
133
|
+
return charges;
|
|
134
|
+
}
|
|
@@ -18,13 +18,32 @@ export type ServerMintDeps = {
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function merchantOrigin(url: string): string;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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/.
|
|
28
47
|
*/
|
|
29
48
|
export type ServerIntentMandateOverride = {
|
|
30
49
|
/** Wire decline-threshold amount (major-unit decimal string), e.g. "500.00". */
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// Request derivation here mirrors ../fetch-credential.mjs EXACTLY (mandate cap,
|
|
12
12
|
// consumer prompt, PENDING retry cadence) — the only change is the transport:
|
|
13
13
|
// verify-web routes + Bearer mint token, never the VGS gateway + VGS secret.
|
|
14
|
+
import { traceHandleFields } from '../trace-handles.js';
|
|
14
15
|
const defaultSleep = (ms) => new Promise((r) => {
|
|
15
16
|
const t = setTimeout(r, ms);
|
|
16
17
|
t.unref?.();
|
|
@@ -39,10 +40,44 @@ export function merchantOrigin(url) {
|
|
|
39
40
|
return url;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* A definitive refusal from the cryptogram mint route — the request will not
|
|
45
|
+
* succeed if retried unchanged.
|
|
46
|
+
*
|
|
47
|
+
* `terminal` is the load-bearing field. Draw terminality used to be decided by
|
|
48
|
+
* regex over the error MESSAGE, which made it hostage to text nobody controls:
|
|
49
|
+
* this client now interpolates the provider's own `upstream_codes` into the
|
|
50
|
+
* message for diagnosability, and a provider identifier such as
|
|
51
|
+
* `request_timeout` would match the transient matcher's unanchored
|
|
52
|
+
* `tim(e|ed)-out` alternative — flipping a permanent 422 back to "transient",
|
|
53
|
+
* skipping markUnhonored, and stranding the mandate in the exact retry-forever
|
|
54
|
+
* loop this whole change exists to kill. Terminality is therefore carried
|
|
55
|
+
* structurally, and consumers must consult it BEFORE any message matching.
|
|
56
|
+
*/
|
|
57
|
+
export class ServerCryptogramRefusedError extends Error {
|
|
58
|
+
status;
|
|
59
|
+
terminal = true;
|
|
60
|
+
constructor(status, detail) {
|
|
61
|
+
super(`server cryptogram refused (${status}): ${detail}`);
|
|
62
|
+
this.name = 'ServerCryptogramRefusedError';
|
|
63
|
+
this.status = status;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
42
66
|
/** Read a stable, non-secret error message from a route's JSON body. */
|
|
43
67
|
async function routeError(res) {
|
|
44
68
|
const doc = (await res.json().catch(() => null));
|
|
45
|
-
|
|
69
|
+
const base = doc?.error || doc?.error_code || `HTTP ${res.status}`;
|
|
70
|
+
// Carry the provider's own status and rejected-attribute identifiers into the
|
|
71
|
+
// message when the route reflected them. Without this the operator sees only
|
|
72
|
+
// our status and has to go log-diving to learn WHICH field the gateway
|
|
73
|
+
// objected to — the gap that left a live create_intent 422 undiagnosable.
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (typeof doc?.upstream_status === 'number')
|
|
76
|
+
parts.push(`upstream_status=${doc.upstream_status}`);
|
|
77
|
+
if (Array.isArray(doc?.upstream_codes) && doc.upstream_codes.length > 0) {
|
|
78
|
+
parts.push(`upstream_codes=${doc.upstream_codes.join(',')}`);
|
|
79
|
+
}
|
|
80
|
+
return parts.length > 0 ? `${base} [${parts.join(' ')}]` : base;
|
|
46
81
|
}
|
|
47
82
|
function bearer(mintToken) {
|
|
48
83
|
return { 'content-type': 'application/json', authorization: `Bearer ${mintToken}` };
|
|
@@ -144,11 +179,16 @@ export async function serverFetchCryptogram(base, mintToken, input, deps = {}) {
|
|
|
144
179
|
...(typeof c.cryptogramExpiresAt === 'string'
|
|
145
180
|
? { cryptogramExpiresAt: c.cryptogramExpiresAt }
|
|
146
181
|
: {}),
|
|
182
|
+
...traceHandleFields(c),
|
|
147
183
|
};
|
|
148
184
|
}
|
|
149
185
|
// A 4xx (bad request / binding refusal / auth) is terminal — never retry it.
|
|
150
|
-
|
|
151
|
-
|
|
186
|
+
// 429 is the sole exception: it is an explicitly retryable 4xx, and treating
|
|
187
|
+
// it as terminal would let a transient rate limit permanently disable a
|
|
188
|
+
// healthy mandate. The route maps upstream rate limits to 503 today, so this
|
|
189
|
+
// is a guard against a future emitter, not a live path.
|
|
190
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 429) {
|
|
191
|
+
throw new ServerCryptogramRefusedError(res.status, await routeError(res));
|
|
152
192
|
}
|
|
153
193
|
lastError = `${res.status}: ${await routeError(res)}`;
|
|
154
194
|
if (attempt < attempts)
|
|
@@ -42,6 +42,15 @@ export type PurchaseAssurance = {
|
|
|
42
42
|
transactionAmount: string;
|
|
43
43
|
/** ISO 4217 currency the ceremony was scoped to. */
|
|
44
44
|
transactionCurrencyCode: string;
|
|
45
|
+
/**
|
|
46
|
+
* True iff the approval server marked this token passkey-exempt ('otp'
|
|
47
|
+
* cardholder ID&V / 'none' — verified against the owner's account card
|
|
48
|
+
* record at complete-time): no ceremony ran, `assuranceData` is null by
|
|
49
|
+
* design, and the intent is minted without it (the signed mint token
|
|
50
|
+
* carries the same exemption for the server's own check). Absent/false →
|
|
51
|
+
* assuranceData is REQUIRED, exactly the historical contract.
|
|
52
|
+
*/
|
|
53
|
+
assuranceExempt?: boolean;
|
|
45
54
|
};
|
|
46
55
|
/**
|
|
47
56
|
* Our fail-closed freshness bound, matching the runner's 15-minute checkout
|
|
@@ -57,6 +66,8 @@ export type VgsPaymentCredential = {
|
|
|
57
66
|
cryptogramType: string;
|
|
58
67
|
cryptogramValue: string;
|
|
59
68
|
cryptogramExpiresAt?: string;
|
|
69
|
+
vgsTraceId?: string;
|
|
70
|
+
networkCorrelationId?: string;
|
|
60
71
|
};
|
|
61
72
|
export type FetchVgsPaymentCredential = (input: {
|
|
62
73
|
tokenId: string;
|
|
@@ -69,14 +80,6 @@ export type FetchVgsPaymentCredential = (input: {
|
|
|
69
80
|
transactionCurrencyCode: string;
|
|
70
81
|
};
|
|
71
82
|
}) => Promise<VgsPaymentCredential>;
|
|
72
|
-
export type MintFreshVgsPaymentCredential = (input: {
|
|
73
|
-
tokenId: string;
|
|
74
|
-
assuranceData: unknown;
|
|
75
|
-
transaction: VgsCheckoutTarget;
|
|
76
|
-
}) => Promise<{
|
|
77
|
-
payment: VgsPaymentCredential;
|
|
78
|
-
intentId: string;
|
|
79
|
-
}>;
|
|
80
83
|
/** The (token, intent) pair a VIC confirmation is posted against. */
|
|
81
84
|
export type VicConfirmationTarget = {
|
|
82
85
|
tokenId: string;
|
|
@@ -139,30 +142,3 @@ export declare class VgsLiveInstrument implements Instrument {
|
|
|
139
142
|
confirmationTarget(): VicConfirmationTarget | null;
|
|
140
143
|
getCredential(ctx: InstrumentContext): Promise<CardCredential>;
|
|
141
144
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Consumes #5614's claimed CLI enrollment artifact (for the tokenId) plus a
|
|
144
|
-
* FRESH purchase-scoped assurance, and creates a fresh, transaction-scoped VIC
|
|
145
|
-
* intent + credential after checkout approval. This is the production-shaped
|
|
146
|
-
* bridge; unlike VgsLiveInstrument it never needs a pre-created intent ID.
|
|
147
|
-
*
|
|
148
|
-
* The enrollment artifact's stored assuranceData is deliberately never sent:
|
|
149
|
-
* replaying it makes intent creation succeed (HTTP 201) while the cryptogram
|
|
150
|
-
* deterministically never completes — the #5709 dead end. Purchase
|
|
151
|
-
* authorization is the fresh, merchant+amount+currency-scoped assurance,
|
|
152
|
-
* validated against the checkout target BEFORE any intent is minted so a
|
|
153
|
-
* doomed intent is never created.
|
|
154
|
-
*/
|
|
155
|
-
export declare class VgsAssuranceInstrument implements Instrument {
|
|
156
|
-
private readonly enrollment;
|
|
157
|
-
private readonly purchase;
|
|
158
|
-
private readonly target;
|
|
159
|
-
private readonly cardholderName;
|
|
160
|
-
private readonly mintCredential;
|
|
161
|
-
readonly kind: "agentic-token";
|
|
162
|
-
private used;
|
|
163
|
-
private minted;
|
|
164
|
-
constructor(enrollment: CliAgentCredential, purchase: PurchaseAssurance, target: VgsCheckoutTarget, cardholderName: string, mintCredential: MintFreshVgsPaymentCredential);
|
|
165
|
-
/** See VgsLiveInstrument.confirmationTarget — same contract. */
|
|
166
|
-
confirmationTarget(): VicConfirmationTarget | null;
|
|
167
|
-
getCredential(ctx: InstrumentContext): Promise<CardCredential>;
|
|
168
|
-
}
|