@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.
Files changed (83) hide show
  1. package/README.md +202 -46
  2. package/dist/checkout-engine/adapters/generic.d.ts +69 -0
  3. package/dist/checkout-engine/adapters/generic.js +383 -58
  4. package/dist/checkout-engine/adapters/index.d.ts +4 -1
  5. package/dist/checkout-engine/adapters/index.js +10 -3
  6. package/dist/checkout-engine/adapters/shopify.d.ts +80 -0
  7. package/dist/checkout-engine/adapters/shopify.js +688 -0
  8. package/dist/checkout-engine/amount.d.ts +15 -0
  9. package/dist/checkout-engine/amount.js +72 -0
  10. package/dist/checkout-engine/browser-launch.d.ts +9 -4
  11. package/dist/checkout-engine/browser-launch.js +19 -4
  12. package/dist/checkout-engine/browserbase-browser.d.ts +24 -0
  13. package/dist/checkout-engine/browserbase-browser.js +186 -0
  14. package/dist/checkout-engine/cli-engine.d.ts +206 -32
  15. package/dist/checkout-engine/cli-engine.js +772 -216
  16. package/dist/checkout-engine/confirmed-merchants.d.ts +31 -0
  17. package/dist/checkout-engine/confirmed-merchants.js +165 -0
  18. package/dist/checkout-engine/detect.d.ts +1 -1
  19. package/dist/checkout-engine/detect.js +6 -0
  20. package/dist/checkout-engine/evidence.d.ts +1 -1
  21. package/dist/checkout-engine/executor.d.ts +61 -3
  22. package/dist/checkout-engine/executor.js +550 -144
  23. package/dist/checkout-engine/hosted-approval.d.ts +69 -9
  24. package/dist/checkout-engine/hosted-approval.js +211 -21
  25. package/dist/checkout-engine/index.d.ts +6 -2
  26. package/dist/checkout-engine/index.js +5 -1
  27. package/dist/checkout-engine/instrument.d.ts +6 -0
  28. package/dist/checkout-engine/known-merchants.d.ts +10 -0
  29. package/dist/checkout-engine/known-merchants.js +38 -0
  30. package/dist/checkout-engine/live-fill-approval.d.ts +5 -11
  31. package/dist/checkout-engine/live-fill-approval.js +20 -34
  32. package/dist/checkout-engine/mandate/card-mandate.d.ts +6 -2
  33. package/dist/checkout-engine/mandate/card-mandate.js +10 -5
  34. package/dist/checkout-engine/mandate/mandate-ledger.d.ts +63 -23
  35. package/dist/checkout-engine/mandate/mandate-ledger.js +124 -17
  36. package/dist/checkout-engine/receipt-dir.d.ts +6 -0
  37. package/dist/checkout-engine/receipt-dir.js +8 -0
  38. package/dist/checkout-engine/receipt.d.ts +56 -2
  39. package/dist/checkout-engine/receipt.js +55 -16
  40. package/dist/checkout-engine/shopify-primary-domain.d.ts +25 -0
  41. package/dist/checkout-engine/shopify-primary-domain.js +96 -0
  42. package/dist/checkout-engine/trace-handles.d.ts +8 -0
  43. package/dist/checkout-engine/trace-handles.js +12 -0
  44. package/dist/checkout-engine/types.d.ts +15 -2
  45. package/dist/checkout-engine/unresolved-charges.d.ts +34 -0
  46. package/dist/checkout-engine/unresolved-charges.js +134 -0
  47. package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +26 -7
  48. package/dist/checkout-engine/vgs-gateway/server-mint-client.js +43 -3
  49. package/dist/checkout-engine/vgs-live-instrument.d.ts +11 -35
  50. package/dist/checkout-engine/vgs-live-instrument.js +14 -74
  51. package/dist/checkout-engine/vic-confirmation.d.ts +18 -0
  52. package/dist/checkout-engine/vic-confirmation.js +9 -3
  53. package/dist/checkout-engine/web-bot-auth.d.ts +98 -0
  54. package/dist/checkout-engine/web-bot-auth.js +218 -0
  55. package/dist/cli.js +899 -387
  56. package/dist/mcp-apps/ucp-checkout.html +280 -0
  57. package/dist/mcp-server/index.js +725 -254
  58. package/dist/merchant-ucp-mcp/index.js +6 -0
  59. package/dist/skills/pair-visa-agent/RUNTIMES.md +122 -79
  60. package/dist/skills/pair-visa-agent/SKILL.md +433 -318
  61. package/dist/skills/pair-visa-agent/scripts/__tests__/setup.test.mjs +407 -0
  62. package/dist/skills/pair-visa-agent/scripts/setup.mjs +310 -30
  63. package/dist/skills/visa-shopify-checkout/SKILL.md +122 -0
  64. package/dist/skills/visa-shopify-checkout/references/evidence-and-states.md +37 -0
  65. package/dist/skills/visa-ucp-shopping/SKILL.md +86 -0
  66. package/dist/subway-direct.mjs +1 -0
  67. package/install.ps1 +7 -6
  68. package/install.sh +3 -3
  69. package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
  70. package/package.json +31 -28
  71. package/server.json +4 -4
  72. package/dist/checkout-engine/inline-target.d.ts +0 -13
  73. package/dist/checkout-engine/inline-target.js +0 -37
  74. package/dist/checkout-engine/pay-args.d.ts +0 -14
  75. package/dist/checkout-engine/pay-args.js +0 -44
  76. package/dist/checkout-engine/pay.d.ts +0 -1
  77. package/dist/checkout-engine/pay.js +0 -13
  78. package/dist/checkout-engine/repo-env.d.ts +0 -11
  79. package/dist/checkout-engine/repo-env.js +0 -23
  80. package/dist/checkout-engine/run-live-fill.d.ts +0 -1
  81. package/dist/checkout-engine/run-live-fill.js +0 -493
  82. package/dist/checkout-engine/vgs-gateway/fetch-credential.d.mts +0 -74
  83. package/dist/checkout-engine/vgs-gateway/fetch-credential.mjs +0 -248
@@ -1,248 +0,0 @@
1
- // ⚠️ RETIRED CLIENT-SECRET PATH — used ONLY by the local `pnpm fill:live` spike
2
- // (run-live-fill.ts) and the older pay.ts dev entrypoints, NOT by the shipped
3
- // pay_merchant CLI. The productionized CLI (cli-engine.ts) mints SERVER-SIDE via
4
- // a scoped mint token (vgs-gateway/server-mint-client.ts) and never holds
5
- // VGS_USERNAME/VGS_PASSWORD. This module (and its spike callers) are slated for
6
- // deletion in the Phase-1 follow-up; do NOT add new callers. The
7
- // no-client-vgs-secret gate keeps the shipped path clear of everything below.
8
- //
9
- // Real credential fetch — NO mocks. Calls the live VGS agentic gateway to mint a
10
- // fresh, intent-scoped payment credential (DPAN + expiry + the 3-digit DAVV) and
11
- // returns it in memory. Same wire calls the enrollment harness (../server-e2e.mjs)
12
- // uses; this just returns the FULL values (for the form-filler) instead of masking.
13
- //
14
- // Nothing here persists or logs the credential — it is returned to the caller
15
- // (fillCheckout), and must never be written to disk or passed through an
16
- // LLM/agent context.
17
- //
18
- // Requires env: VGS_USERNAME, VGS_PASSWORD (the VGS service-account client id/secret),
19
- // and either VGS_ENVIRONMENT=live (+ optional VGS_GATEWAY_URL) or sandbox.
20
-
21
- const TOKEN_URL = 'https://auth.verygoodsecurity.com/auth/realms/vgs/protocol/openid-connect/token'
22
-
23
- function gatewayBase(env = process.env) {
24
- if (env.VGS_GATEWAY_URL) return env.VGS_GATEWAY_URL.replace(/\/$/, '')
25
- return env.VGS_ENVIRONMENT === 'live'
26
- ? 'https://gw-01-live.vgsapi.com'
27
- : 'https://gw-01-sandbox.vgsapi.com'
28
- }
29
-
30
- async function mintOauthToken(env = process.env) {
31
- const clientId = env.VGS_USERNAME
32
- const clientSecret = env.VGS_PASSWORD
33
- if (!clientId || !clientSecret) {
34
- throw new Error('Set VGS_USERNAME and VGS_PASSWORD (the VGS service-account client id/secret).')
35
- }
36
- const body = new URLSearchParams({
37
- client_id: clientId,
38
- client_secret: clientSecret,
39
- grant_type: 'client_credentials',
40
- })
41
- const r = await fetch(TOKEN_URL, {
42
- method: 'POST',
43
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
44
- body,
45
- })
46
- if (!r.ok) throw new Error(`VGS token grant failed (${r.status}).`)
47
- return (await r.json()).access_token
48
- }
49
-
50
- async function postJsonApi(url, type, attributes, env = process.env) {
51
- const token = await mintOauthToken(env)
52
- const r = await fetch(url, {
53
- method: 'POST',
54
- headers: {
55
- Authorization: `Bearer ${token}`,
56
- 'Content-Type': 'application/vnd.api+json',
57
- },
58
- body: JSON.stringify({ data: { ...(type ? { type } : {}), attributes } }),
59
- })
60
- const text = await r.text()
61
- let doc = {}
62
- try {
63
- doc = JSON.parse(text)
64
- } catch {
65
- /* non-json error body */
66
- }
67
- // Support trace handles VGS asked for on the #5713 decline thread: trace_id
68
- // keys the request on VGS's side, network_correlation_id on the Visa network
69
- // side. Routing metadata only — never credential material — and logged even
70
- // on error responses so any run stays traceable after the fact.
71
- const obs = doc?.meta?.observability
72
- if (obs && typeof obs === 'object') {
73
- console.info(
74
- JSON.stringify({
75
- op: 'vgs_observability',
76
- type,
77
- status: r.status,
78
- trace_id: obs.trace_id,
79
- vault_id: obs.vault_id,
80
- network_correlation_id: obs.network_correlation_id,
81
- })
82
- )
83
- }
84
- if (!r.ok) {
85
- // Never echo the full body (can carry ids); surface status + a short detail.
86
- const detail = doc?.errors?.[0]?.detail || doc?.errors?.[0]?.title || ''
87
- throw new Error(`VGS ${type} POST failed (${r.status})${detail ? `: ${detail}` : ''}.`)
88
- }
89
- return doc
90
- }
91
-
92
- const txnData = (t) => [
93
- {
94
- merchant_name: t.merchantName,
95
- merchant_url: t.merchantUrl,
96
- merchant_country_code: t.merchantCountryCode,
97
- transaction_amount: {
98
- transaction_amount: t.transactionAmount,
99
- transaction_currency_code: t.transactionCurrencyCode,
100
- },
101
- },
102
- ]
103
-
104
- /**
105
- * Create a fresh intent scoped to `transaction`, bound to the passkey assurance.
106
- * Needs `assuranceData` from a device-binding passkey ceremony run for THIS
107
- * purchase (merchant + amount + currency aligned) — replaying enrollment-time
108
- * assurance mints an intent that 201s but whose cryptogram never completes
109
- * (#5709, confirmed live 2026-07-17).
110
- * @returns {Promise<{intentId: string, status: string | null}>} the fresh
111
- * intent id plus the creation-time status attribute (null when VGS omits it) —
112
- * callers surface the status when a later cryptogram fails, since HTTP 201
113
- * alone does not mean the intent is authorized.
114
- */
115
- export async function createIntent({ tokenId, assuranceData, transaction }, env = process.env) {
116
- const effectiveUntil = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString()
117
- const cap = Math.max(Math.ceil(Number(transaction.transactionAmount) || 0) + 10, 25)
118
- const doc = await postJsonApi(
119
- `${gatewayBase(env)}/agentic-tokens/${encodeURIComponent(tokenId)}/intents`,
120
- 'intents',
121
- {
122
- consumer_prompt: `Buy an item from ${transaction.merchantName} for ${transaction.transactionCurrencyCode} ${transaction.transactionAmount}`,
123
- assurance_data: assuranceData,
124
- mandates: [
125
- {
126
- description: `Purchase at ${transaction.merchantName}`,
127
- decline_threshold: { amount: cap, currency_code: transaction.transactionCurrencyCode },
128
- effective_until: effectiveUntil,
129
- merchant_category: 'Retail',
130
- merchant_category_code: '5999',
131
- preferred_merchant_name: transaction.merchantName,
132
- quantity: 1,
133
- },
134
- ],
135
- },
136
- env
137
- )
138
- const intentId = doc.data?.id
139
- if (!intentId) throw new Error('createIntent: response missing data.id')
140
- const status = doc.data?.attributes?.status
141
- return { intentId, status: typeof status === 'string' && status ? status : null }
142
- }
143
-
144
- /**
145
- * Mint the FULL payment credential for an existing intent. Real VGS call — the
146
- * DAVV is single-use and expires in hours, so call this immediately before fill.
147
- * @returns {Promise<{networkToken,expMonth,expYear,cryptogramType,cryptogramValue}>}
148
- */
149
- export async function fetchCryptogram({ tokenId, intentId, transaction }, env = process.env) {
150
- // Intent approval can be asynchronous on live: creation returns PENDING and
151
- // the first cryptogram answer can be PENDING too (observed 2026-07-17,
152
- // donate.stripe.com run). Poll briefly on PENDING only — every other
153
- // non-COMPLETED status still fails fast on the first answer. Both knobs are
154
- // env-tunable (and injectable for tests, which must not sleep wall-clock).
155
- const PENDING_ATTEMPTS = Math.max(1, Number(env.VGS_CRYPTOGRAM_PENDING_ATTEMPTS) || 4)
156
- const PENDING_WAIT_MS = Number.isFinite(Number(env.VGS_CRYPTOGRAM_PENDING_WAIT_MS))
157
- ? Number(env.VGS_CRYPTOGRAM_PENDING_WAIT_MS)
158
- : 5000
159
- let a = {}
160
- for (let attempt = 1; ; attempt++) {
161
- const doc = await postJsonApi(
162
- `${gatewayBase(env)}/agentic-tokens/${encodeURIComponent(tokenId)}/intents/${encodeURIComponent(intentId)}/cryptograms`,
163
- 'cryptograms',
164
- { transaction_data: txnData(transaction) },
165
- env
166
- )
167
- a = doc.data?.attributes ?? {}
168
- const s = typeof a.status === 'string' ? a.status.toUpperCase() : ''
169
- if (s !== 'PENDING' || attempt >= PENDING_ATTEMPTS) break
170
- console.info(
171
- JSON.stringify({ op: 'cryptogram_pending_retry', attempt, waitMs: PENDING_WAIT_MS })
172
- )
173
- await new Promise((resolve) => setTimeout(resolve, PENDING_WAIT_MS))
174
- }
175
- // A network_token can come back while the cryptogram is still pending/failed —
176
- // mirror lib/server/vgs.ts and reject anything not COMPLETED, so we never key a
177
- // not-yet-valid credential (which would decline and read as a fill bug).
178
- const status = a.status
179
- if (typeof status === 'string' && status && status.toUpperCase() !== 'COMPLETED') {
180
- throw new Error(`cryptogram not completed (status ${status})`)
181
- }
182
- const networkToken = a.network_token
183
- const value = a.cryptogram?.value
184
- if (typeof networkToken !== 'string' || !networkToken) {
185
- throw new Error('cryptogram response missing network_token')
186
- }
187
- if (typeof value !== 'string' || !value) {
188
- throw new Error('cryptogram response missing cryptogram value')
189
- }
190
- return {
191
- networkToken,
192
- expMonth: typeof a.exp_month === 'number' ? a.exp_month : Number(a.exp_month) || 0,
193
- expYear: typeof a.exp_year === 'number' ? a.exp_year : Number(a.exp_year) || 0,
194
- cryptogramType: a.cryptogram?.type ?? '',
195
- cryptogramValue: value,
196
- cryptogramExpiresAt:
197
- typeof a.cryptogram?.expires_at === 'string' ? a.cryptogram.expires_at : undefined,
198
- }
199
- }
200
-
201
- /**
202
- * Full path: create the intent (needs fresh passkey assurance) then mint the
203
- * credential. Use fetchCryptogram directly if you already have an intentId.
204
- */
205
- export async function getCredential({ tokenId, assuranceData, transaction }, env = process.env) {
206
- const { intentId, status } = await createIntent({ tokenId, assuranceData, transaction }, env)
207
- try {
208
- return await fetchCryptogram({ tokenId, intentId, transaction }, env)
209
- } catch (err) {
210
- // HTTP 201 on intent creation does not mean the intent was authorized —
211
- // surface its creation-time status so a not-completed cryptogram is
212
- // diagnosable (#5709) instead of an opaque failure.
213
- throw new Error(`${err.message} (intent status at creation: ${status ?? 'unknown'})`)
214
- }
215
- }
216
-
217
- /**
218
- * Report the observed merchant outcome back to VIC for a consumed intent.
219
- * Mirrors lib/server/vgs.ts postConfirmation exactly: same endpoint, same
220
- * JSON:API envelope, and the guide's quoted Unix-epoch-seconds timestamp
221
- * (callers pass ISO 8601; converted here).
222
- */
223
- export async function postConfirmation(
224
- { tokenId, intentId, transactionStatus, transactionType, transactionTimestamp, transaction },
225
- env = process.env
226
- ) {
227
- await postJsonApi(
228
- `${gatewayBase(env)}/agentic-tokens/${encodeURIComponent(tokenId)}/intents/${encodeURIComponent(intentId)}/confirmations`,
229
- 'confirmations',
230
- {
231
- confirmation_data: [
232
- {
233
- payment_confirmation_data: {
234
- transaction_status: transactionStatus,
235
- transaction_type: transactionType,
236
- transaction_timestamp: String(Math.floor(Date.parse(transactionTimestamp) / 1000)),
237
- transaction_amount: {
238
- transaction_amount: transaction.transactionAmount,
239
- transaction_currency_code: transaction.transactionCurrencyCode,
240
- },
241
- },
242
- },
243
- ],
244
- },
245
- env
246
- )
247
- return { ok: true }
248
- }