@visa/cli 4.1.0-rc.144 → 4.1.0-rc.146
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/dist/checkout-engine/cli-engine.js +39 -66
- package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +19 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.js +41 -3
- package/dist/cli.js +312 -304
- package/dist/mcp-server/index.js +244 -236
- package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -16,7 +16,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
16
16
|
import { launchCheckoutBrowser } from './browser-launch.js';
|
|
17
17
|
import { prepareCheckout as realPrepareCheckout, submitApprovedCheckout as realSubmitApprovedCheckout, InMemoryPreparedCheckoutStore, } from './executor.js';
|
|
18
18
|
import { claimMandatePickup as realClaimMandatePickup, runHostedApproval as realRunHostedApproval, } from './hosted-approval.js';
|
|
19
|
-
import {
|
|
19
|
+
import { VgsLiveInstrument, decimalToMinor, minorToDecimal, } from './vgs-live-instrument.js';
|
|
20
20
|
import { serverCreateIntent, serverFetchCryptogram, serverPostConfirmation, } from './vgs-gateway/server-mint-client.js';
|
|
21
21
|
import { createCardMandate, DEFAULT_MANDATE_MAX_DRAWS, drawFromMandate, MandateDrawDeclinedError, } from './mandate/card-mandate.js';
|
|
22
22
|
import { MandateLedger } from './mandate/mandate-ledger.js';
|
|
@@ -33,6 +33,21 @@ export function isTransientDrawFailure(err) {
|
|
|
33
33
|
const msgs = [];
|
|
34
34
|
let e = err;
|
|
35
35
|
for (let i = 0; i < 5 && e; i++) {
|
|
36
|
+
// A refusal that declared itself TERMINAL wins outright, before any message
|
|
37
|
+
// matching. Message text is not a safe carrier for this decision: the mint
|
|
38
|
+
// client interpolates provider-supplied `upstream_codes` into its message
|
|
39
|
+
// for diagnosability, and an identifier like `request_timeout` would match
|
|
40
|
+
// the unanchored `tim(e|ed)-out` alternative below and silently reclassify
|
|
41
|
+
// a permanent 422 as transient — skipping markUnhonored and stranding the
|
|
42
|
+
// mandate in the retry-forever loop this classifier exists to prevent.
|
|
43
|
+
// Duck-typed rather than instanceof so it survives bundling and any
|
|
44
|
+
// re-wrapping across package boundaries. Optional chaining rather than an
|
|
45
|
+
// explicit null guard: the loop condition already proved `e` truthy, so a
|
|
46
|
+
// `e !== null` test is dead code, and `?.` stays safe on a primitive or a
|
|
47
|
+
// nullish link if that guard ever changes.
|
|
48
|
+
if (e?.terminal === true) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
36
51
|
if (e instanceof Error && typeof e.message === 'string')
|
|
37
52
|
msgs.push(e.message);
|
|
38
53
|
e = e.cause;
|
|
@@ -765,73 +780,31 @@ export function createCliCheckoutEngine(deps = {}) {
|
|
|
765
780
|
instrument = new VgsLiveInstrument(reference, session.contact.fullName ?? '', fetchCredential);
|
|
766
781
|
}
|
|
767
782
|
else {
|
|
768
|
-
//
|
|
769
|
-
//
|
|
770
|
-
//
|
|
771
|
-
//
|
|
772
|
-
//
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
783
|
+
// #7348 fresh-tap retirement: card spend is mandate-only for EVERY
|
|
784
|
+
// runtime. The legacy 1:1 fresh-tap flow that lived here minted a
|
|
785
|
+
// payable credential outside the grant/mandate ledger — invisible to
|
|
786
|
+
// spending controls. The server now refuses non-budget approvals at
|
|
787
|
+
// registration and non-budget mint tokens at verification; this
|
|
788
|
+
// client refusal exists to give the honest remedy up front instead
|
|
789
|
+
// of a mid-flow server error.
|
|
790
|
+
return {
|
|
791
|
+
outcome: 'failed',
|
|
792
|
+
confirmationRef: null,
|
|
793
|
+
receiptPath: null,
|
|
794
|
+
detail: isV4CardGrant
|
|
795
|
+
? 'this v4 card grant has no active mandate covering the purchase; run ' +
|
|
779
796
|
'`visa mandate start --ceiling <usd> --per-transaction <usd>` for the selected ' +
|
|
780
797
|
'agent, approve and claim the mandate, then retry this checkout. No payment ' +
|
|
781
|
-
'credential was requested and no charge was made.'
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
// Legacy credential file only. A v4 grant was refused above unless a
|
|
792
|
-
// covering mandate selected the canonical draw path.
|
|
793
|
-
const credential = await resolveCardInstrument(input);
|
|
794
|
-
const assurance = await runHostedApproval({
|
|
795
|
-
baseUrl: input.approvalBaseUrl,
|
|
796
|
-
tokenId: credential.tokenId,
|
|
797
|
-
target: session.target,
|
|
798
|
-
consumerEmail: session.contact.email,
|
|
799
|
-
onApprovalUrl: input.onApprovalUrl ?? deps.onApprovalUrl,
|
|
800
|
-
});
|
|
801
|
-
// Server-side mint (Phase 1): the approval claim releases a scoped mint
|
|
802
|
-
// token; the credential is minted by the verify-web deployment (which
|
|
803
|
-
// holds the VGS secret), never on this machine. No token means the
|
|
804
|
-
// deployment ran the dev-auth stub — refuse loudly rather than reach for
|
|
805
|
-
// a client-held secret (there is none anymore).
|
|
806
|
-
const mintToken = assurance.mintToken;
|
|
807
|
-
if (!mintToken) {
|
|
808
|
-
return {
|
|
809
|
-
outcome: 'failed',
|
|
810
|
-
confirmationRef: null,
|
|
811
|
-
receiptPath: null,
|
|
812
|
-
detail: 'the approval server issued no mint token — server-side minting requires the ' +
|
|
813
|
-
'verify-web deployment to run real/turnkey auth (not the dev stub). Retry once it does.',
|
|
814
|
-
vicConfirmation: null,
|
|
815
|
-
source: 'fresh-tap',
|
|
816
|
-
remainingMinor: null,
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
confirmBase = input.approvalBaseUrl;
|
|
820
|
-
confirmationAuthority = mintToken;
|
|
821
|
-
instrument = new VgsAssuranceInstrument(credential, assurance, session.target, session.contact.fullName ?? '', async (mintInput) => {
|
|
822
|
-
const { intentId, status } = await serverCreateIntent(confirmBase, mintToken, mintInput);
|
|
823
|
-
try {
|
|
824
|
-
const payment = await serverFetchCryptogram(confirmBase, mintToken, {
|
|
825
|
-
tokenId: mintInput.tokenId,
|
|
826
|
-
intentId,
|
|
827
|
-
transaction: mintInput.transaction,
|
|
828
|
-
});
|
|
829
|
-
return { payment, intentId };
|
|
830
|
-
}
|
|
831
|
-
catch (err) {
|
|
832
|
-
throw new Error(`${err.message} (intent status at creation: ${status ?? 'unknown'})`);
|
|
833
|
-
}
|
|
834
|
-
});
|
|
798
|
+
'credential was requested and no charge was made.'
|
|
799
|
+
: 'one-off card approvals are retired (#7348): card spending always runs through ' +
|
|
800
|
+
'an owner-approved mandate now. Attach card authority to this agent ' +
|
|
801
|
+
'(`visa agent grant-card <agent-id> --ceiling <usd> --per-transaction <usd> --wait`), ' +
|
|
802
|
+
'then start and claim a mandate (`visa mandate start <usd> --per-transaction <usd>`), ' +
|
|
803
|
+
'and retry the checkout. No payment credential was requested and no charge was made.',
|
|
804
|
+
vicConfirmation: null,
|
|
805
|
+
source: null,
|
|
806
|
+
remainingMinor: null,
|
|
807
|
+
};
|
|
835
808
|
}
|
|
836
809
|
const mode = input.submit ? 'submit' : 'dry-run';
|
|
837
810
|
const result = await submitApprovedCheckout(input.reviewId, {
|
|
@@ -17,6 +17,25 @@ export type ServerMintDeps = {
|
|
|
17
17
|
* — the mint must never throw here.
|
|
18
18
|
*/
|
|
19
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
|
+
}
|
|
20
39
|
/**
|
|
21
40
|
* Optional mandate override for serverCreateIntent. Absent → the historical
|
|
22
41
|
* 1:1 fresh-tap shape is preserved byte-for-byte (cap = ceil(amount)+10 min 25,
|
|
@@ -40,10 +40,44 @@ export function merchantOrigin(url) {
|
|
|
40
40
|
return url;
|
|
41
41
|
}
|
|
42
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
|
+
}
|
|
43
66
|
/** Read a stable, non-secret error message from a route's JSON body. */
|
|
44
67
|
async function routeError(res) {
|
|
45
68
|
const doc = (await res.json().catch(() => null));
|
|
46
|
-
|
|
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;
|
|
47
81
|
}
|
|
48
82
|
function bearer(mintToken) {
|
|
49
83
|
return { 'content-type': 'application/json', authorization: `Bearer ${mintToken}` };
|
|
@@ -149,8 +183,12 @@ export async function serverFetchCryptogram(base, mintToken, input, deps = {}) {
|
|
|
149
183
|
};
|
|
150
184
|
}
|
|
151
185
|
// A 4xx (bad request / binding refusal / auth) is terminal — never retry it.
|
|
152
|
-
|
|
153
|
-
|
|
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));
|
|
154
192
|
}
|
|
155
193
|
lastError = `${res.status}: ${await routeError(res)}`;
|
|
156
194
|
if (attempt < attempts)
|