@visa/cli 4.1.0-rc.13 → 4.1.0-rc.130

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