@visa/cli 4.1.0-rc.143 → 4.1.0-rc.145

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.
@@ -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 { VgsAssuranceInstrument, VgsLiveInstrument, decimalToMinor, minorToDecimal, } from './vgs-live-instrument.js';
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';
@@ -765,73 +765,31 @@ export function createCliCheckoutEngine(deps = {}) {
765
765
  instrument = new VgsLiveInstrument(reference, session.contact.fullName ?? '', fetchCredential);
766
766
  }
767
767
  else {
768
- // A v4 card grant is aggregate authority, not a credential-only escape
769
- // hatch. Its spend must be represented by a claimed mandate so auth can
770
- // atomically reserve both the card scope and aggregate budget before a
771
- // payable cryptogram is minted. Falling through to the legacy 1:1 tap
772
- // here would create a real card credential with zero canonical draw.
773
- if (isV4CardGrant) {
774
- return {
775
- outcome: 'failed',
776
- confirmationRef: null,
777
- receiptPath: null,
778
- detail: 'this v4 card grant has no active mandate covering the purchase; run ' +
768
+ // #7348 fresh-tap retirement: card spend is mandate-only for EVERY
769
+ // runtime. The legacy 1:1 fresh-tap flow that lived here minted a
770
+ // payable credential outside the grant/mandate ledger invisible to
771
+ // spending controls. The server now refuses non-budget approvals at
772
+ // registration and non-budget mint tokens at verification; this
773
+ // client refusal exists to give the honest remedy up front instead
774
+ // of a mid-flow server error.
775
+ return {
776
+ outcome: 'failed',
777
+ confirmationRef: null,
778
+ receiptPath: null,
779
+ detail: isV4CardGrant
780
+ ? 'this v4 card grant has no active mandate covering the purchase; run ' +
779
781
  '`visa mandate start --ceiling <usd> --per-transaction <usd>` for the selected ' +
780
782
  'agent, approve and claim the mandate, then retry this checkout. No payment ' +
781
- 'credential was requested and no charge was made.',
782
- vicConfirmation: null,
783
- source: null,
784
- remainingMinor: null,
785
- };
786
- }
787
- // --- Legacy 1:1 fresh-tap flow --------------------------------------
788
- // Kept only for a pre-v4 credential-file runtime. A selected v4 grant
789
- // can never reach this parallel, non-canonical accounting path.
790
- source = 'fresh-tap';
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
- });
783
+ 'credential was requested and no charge was made.'
784
+ : 'one-off card approvals are retired (#7348): card spending always runs through ' +
785
+ 'an owner-approved mandate now. Attach card authority to this agent ' +
786
+ '(`visa agent grant-card <agent-id> --ceiling <usd> --per-transaction <usd> --wait`), ' +
787
+ 'then start and claim a mandate (`visa mandate start <usd> --per-transaction <usd>`), ' +
788
+ 'and retry the checkout. No payment credential was requested and no charge was made.',
789
+ vicConfirmation: null,
790
+ source: null,
791
+ remainingMinor: null,
792
+ };
835
793
  }
836
794
  const mode = input.submit ? 'submit' : 'dry-run';
837
795
  const result = await submitApprovedCheckout(input.reviewId, {
@@ -43,7 +43,18 @@ export function merchantOrigin(url) {
43
43
  /** Read a stable, non-secret error message from a route's JSON body. */
44
44
  async function routeError(res) {
45
45
  const doc = (await res.json().catch(() => null));
46
- return doc?.error || doc?.error_code || `HTTP ${res.status}`;
46
+ const base = doc?.error || doc?.error_code || `HTTP ${res.status}`;
47
+ // Carry the provider's own status and rejected-attribute identifiers into the
48
+ // message when the route reflected them. Without this the operator sees only
49
+ // our status and has to go log-diving to learn WHICH field the gateway
50
+ // objected to — the gap that left a live create_intent 422 undiagnosable.
51
+ const parts = [];
52
+ if (typeof doc?.upstream_status === 'number')
53
+ parts.push(`upstream_status=${doc.upstream_status}`);
54
+ if (Array.isArray(doc?.upstream_codes) && doc.upstream_codes.length > 0) {
55
+ parts.push(`upstream_codes=${doc.upstream_codes.join(',')}`);
56
+ }
57
+ return parts.length > 0 ? `${base} [${parts.join(' ')}]` : base;
47
58
  }
48
59
  function bearer(mintToken) {
49
60
  return { 'content-type': 'application/json', authorization: `Bearer ${mintToken}` };
@@ -149,7 +160,11 @@ export async function serverFetchCryptogram(base, mintToken, input, deps = {}) {
149
160
  };
150
161
  }
151
162
  // A 4xx (bad request / binding refusal / auth) is terminal — never retry it.
152
- if (res.status >= 400 && res.status < 500) {
163
+ // 429 is the sole exception: it is an explicitly retryable 4xx, and treating
164
+ // it as terminal would let a transient rate limit permanently disable a
165
+ // healthy mandate. The route maps upstream rate limits to 503 today, so this
166
+ // is a guard against a future emitter, not a live path.
167
+ if (res.status >= 400 && res.status < 500 && res.status !== 429) {
153
168
  throw new Error(`server cryptogram refused (${res.status}): ${await routeError(res)}`);
154
169
  }
155
170
  lastError = `${res.status}: ${await routeError(res)}`;