@agent-cards/sdk 0.23.28 → 0.24.1
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/CHANGELOG.md +84 -0
- package/PREFLIGHT.md +7 -1
- package/README.md +197 -102
- package/dist/aci.d.ts +52 -22
- package/dist/aci.js +79 -15
- package/dist/adyen-merchant-hosted.generated.d.ts +2 -2
- package/dist/adyen-merchant-hosted.generated.js +586 -55
- package/dist/agent-amount.generated.js +1 -1
- package/dist/agentcard.d.ts +4 -5
- package/dist/agentcard.js +4 -5
- package/dist/amadeus.d.ts +9 -3
- package/dist/amadeus.js +33 -4
- package/dist/api-module.d.ts +1 -7
- package/dist/api-module.js +3 -5
- package/dist/{voice-retry.js → api-retry.js} +1 -1
- package/dist/api-types.d.ts +53 -0
- package/dist/{voice-types.js → api-types.js} +7 -2
- package/dist/approvals.d.ts +166 -0
- package/dist/approvals.js +213 -0
- package/dist/aurus.d.ts +33 -0
- package/dist/aurus.js +75 -0
- package/dist/builtin-registry.generated.js +1 -1
- package/dist/buy.d.ts +20 -101
- package/dist/buy.js +19 -74
- package/dist/capabilities.generated.js +1 -1
- package/dist/card-fields.generated.js +2864 -249
- package/dist/cardlink-vpos.d.ts +43 -0
- package/dist/cardlink-vpos.js +90 -0
- package/dist/cdp.d.ts +3 -13
- package/dist/cdp.js +244 -175
- package/dist/checkout-com.generated.js +5 -1
- package/dist/client.d.ts +170 -22
- package/dist/client.js +281 -40
- package/dist/creditguard.generated.d.ts +4 -4
- package/dist/cybersource-flex.generated.d.ts +39 -1
- package/dist/cybersource-flex.generated.js +100 -11
- package/dist/datatrans.generated.js +22 -1
- package/dist/eghl.d.ts +40 -0
- package/dist/eghl.js +72 -0
- package/dist/elavon-converge.generated.js +5 -3
- package/dist/gmo.generated.js +7 -2
- package/dist/hold.d.ts +8 -0
- package/dist/hold.js +43 -2
- package/dist/hosted-entry.js +4 -0
- package/dist/index.d.ts +9 -15
- package/dist/index.js +6 -10
- package/dist/lifecycle.d.ts +9 -61
- package/dist/lifecycle.js +24 -10
- package/dist/merchant-card-endpoints.generated.d.ts +6 -1
- package/dist/merchant-card-endpoints.generated.js +344 -19
- package/dist/merchant-hosted.d.ts +8 -1
- package/dist/nike-order.d.ts +51 -0
- package/dist/nike-order.js +81 -0
- package/dist/oceanpayment.d.ts +38 -0
- package/dist/oceanpayment.js +70 -0
- package/dist/paddle-tokenex.generated.js +111 -11
- package/dist/payplug.d.ts +41 -0
- package/dist/payplug.js +71 -0
- package/dist/payrails.generated.js +33 -8
- package/dist/pre-claim.d.ts +11 -0
- package/dist/pre-claim.js +130 -7
- package/dist/preflight-capabilities.generated.d.ts +0 -4
- package/dist/preflight-capabilities.generated.js +0 -5
- package/dist/preflight-catalog.json +200 -6
- package/dist/preflight-playwright.d.ts +2 -2
- package/dist/preflight-playwright.js +63 -14
- package/dist/preflight-schemas.json +18 -0
- package/dist/preflight.generated.d.ts +5 -4
- package/dist/preflight.generated.js +63 -3
- package/dist/preparation.d.ts +7 -0
- package/dist/preparation.js +21 -0
- package/dist/prepared-processor.d.ts +18 -5
- package/dist/prepared-processor.js +48 -8
- package/dist/primer.generated.js +2889 -268
- package/dist/processout.generated.d.ts +61 -0
- package/dist/processout.generated.js +577 -0
- package/dist/requests.js +1 -1
- package/dist/shiji-sts.generated.js +111 -11
- package/dist/stripe-checkout.generated.js +2761 -319
- package/dist/substitutions.generated.js +553 -26
- package/dist/tap-payments.generated.js +111 -11
- package/dist/twoc2p.generated.js +111 -11
- package/dist/url-masks/bluesnap.d.ts +2 -0
- package/dist/url-masks/bluesnap.js +15 -0
- package/dist/url-masks/oceanpayment.d.ts +2 -0
- package/dist/url-masks/oceanpayment.js +13 -0
- package/dist/url-masks/payplug.d.ts +2 -0
- package/dist/url-masks/payplug.js +13 -0
- package/dist/url-masks/vtex_payments.d.ts +2 -0
- package/dist/url-masks/vtex_payments.js +12 -0
- package/dist/url-masks.generated.d.ts +1 -1
- package/dist/url-masks.generated.js +6 -2
- package/dist/verifone.generated.js +42 -2
- package/dist/vtex-payments.generated.d.ts +127 -0
- package/dist/vtex-payments.generated.js +544 -0
- package/dist/webhooks.d.ts +2 -2
- package/dist/webhooks.js +2 -2
- package/examples/preflight/kernel-native/inventory.json +1 -1
- package/package.json +6 -8
- package/dist/languages.d.ts +0 -23
- package/dist/languages.js +0 -76
- package/dist/voice-pkce.d.ts +0 -49
- package/dist/voice-pkce.js +0 -147
- package/dist/voice-stream.generated.d.ts +0 -118
- package/dist/voice-stream.generated.js +0 -170
- package/dist/voice-types.d.ts +0 -735
- package/dist/voice.d.ts +0 -373
- package/dist/voice.js +0 -815
- package/readme.test.mjs +0 -53
- /package/dist/{voice-retry.d.ts → api-retry.d.ts} +0 -0
package/dist/buy.js
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The buy module of the SDK: `agentcard.buy.*`. The Purchase API from the
|
|
3
|
-
* same client the
|
|
3
|
+
* same client the checkout module uses: one pair of client credentials, one
|
|
4
4
|
* token. A business asks for a cart on behalf of a person it connected,
|
|
5
5
|
* confirms the cart by its hash, and, when it already holds an approval the
|
|
6
|
-
* person gave
|
|
6
|
+
* person gave, names that approval on the confirm so the API places
|
|
7
7
|
* against it and asks the person for nothing a second time (decision 234).
|
|
8
|
-
* With `approval: 'voice'` the confirm asks the API to mint the purchase's
|
|
9
|
-
* own approval instead of an approval page, the business runs the key word
|
|
10
|
-
* in its app on that id, and the same confirm placed again completes the
|
|
11
|
-
* order (decision 237).
|
|
12
8
|
*
|
|
13
9
|
* Every call names `user_id`, the person the connect exchange returned, so a
|
|
14
10
|
* server serving many people never buys for the wrong one. A person who is
|
|
15
11
|
* not connected to this client is refused with `user_not_connected`.
|
|
16
12
|
*/
|
|
17
13
|
import { ApiModule } from './api-module.js';
|
|
18
|
-
import { AgentcardError } from './
|
|
19
|
-
/** The one refusal a store makes under `approval: 'voice'`: its connector cannot place under a voice verdict, and the business takes its own path. A 409, as `BuyError.code`. */
|
|
20
|
-
export const VOICE_EXECUTION_UNSUPPORTED = 'voice_execution_unsupported';
|
|
14
|
+
import { AgentcardError } from './api-types.js';
|
|
21
15
|
/** True for a turn the API declined; `decline_code` says why (it is null when the loop refused in prose only). */
|
|
22
16
|
export function isBuyDeclined(turn) { return turn.status === 'declined'; }
|
|
23
|
-
/** True for a confirm waiting for the person's verdict by voice; `authorization_id` is the id your app runs the key word on. */
|
|
24
|
-
export function isBuyNeedsApproval(turn) { return turn.status === 'needs_approval' && typeof turn.authorization_id === 'string'; }
|
|
25
|
-
/** True when the store could not place under a voice verdict; `error` is the refusal. */
|
|
26
|
-
export function isBuyVoiceUnsupported(turn) { return turn.status === VOICE_EXECUTION_UNSUPPORTED; }
|
|
27
17
|
/**
|
|
28
18
|
* A refusal from the Purchase API, as an `AgentcardError` whose `code` is the
|
|
29
19
|
* API's (`user_not_connected`, `authorization_not_approved`,
|
|
30
20
|
* `authorization_mismatch`, `authorization_spent`, `turn_in_progress`,
|
|
31
21
|
* `delivery_address_changed`, `cart_changed`, `nothing_to_confirm`,
|
|
32
|
-
* `conversation_not_found`, `conversation_closed
|
|
33
|
-
* `voice_execution_unsupported`) or the client's own before any call
|
|
22
|
+
* `conversation_not_found`, `conversation_closed`) or the client's own before any call
|
|
34
23
|
* (`not_connected`, `invalid_ask`, `invalid_cart_hash`,
|
|
35
|
-
* `invalid_authorization_id`, `invalid_payment_source`,
|
|
36
|
-
* `missing_conversation_id
|
|
24
|
+
* `invalid_authorization_id`, `invalid_payment_source`,
|
|
25
|
+
* `missing_conversation_id`). `carts` carries the
|
|
37
26
|
* carts as they stand when the refusal named them, so a confirm of a changed
|
|
38
27
|
* cart reads the fresh hash from the error.
|
|
39
28
|
*/
|
|
@@ -69,13 +58,21 @@ function cartOf(v) {
|
|
|
69
58
|
merchant_name: typeof c.merchant_name === 'string' ? c.merchant_name : c.merchant,
|
|
70
59
|
store: storeOf(c.store),
|
|
71
60
|
items: Array.isArray(c.items) ? c.items : [],
|
|
72
|
-
|
|
61
|
+
...feesOf(c),
|
|
73
62
|
tipCents: typeof c.tipCents === 'number' ? c.tipCents : 0,
|
|
74
63
|
totalCents: typeof c.totalCents === 'number' ? c.totalCents : 0,
|
|
75
64
|
approvedCeilingCents: typeof c.approvedCeilingCents === 'number' ? c.approvedCeilingCents : null,
|
|
76
65
|
hash: c.hash,
|
|
77
66
|
};
|
|
78
67
|
}
|
|
68
|
+
/** A pending or unreadable fee stays null with its status, so it never reads as a genuine zero. */
|
|
69
|
+
function feesOf(c) {
|
|
70
|
+
const amount = typeof c.serviceFeesCents === 'number' ? c.serviceFeesCents : null;
|
|
71
|
+
const status = c.merchantFeesPending === true || c.serviceFeesStatus === 'pending' ? 'pending'
|
|
72
|
+
: (c.serviceFeesStatus === undefined || c.serviceFeesStatus === 'known')
|
|
73
|
+
&& amount !== null && Number.isSafeInteger(amount) && amount >= 0 ? 'known' : 'unknown';
|
|
74
|
+
return { serviceFeesCents: status === 'known' ? amount : null, serviceFeesStatus: status };
|
|
75
|
+
}
|
|
79
76
|
function storeOf(v) {
|
|
80
77
|
if (!v || typeof v !== 'object')
|
|
81
78
|
return null;
|
|
@@ -113,7 +110,7 @@ function outcomeOf(a) {
|
|
|
113
110
|
authorization_id: str(a.authorization_id),
|
|
114
111
|
};
|
|
115
112
|
}
|
|
116
|
-
const STATUSES = new Set(['needs_input', '
|
|
113
|
+
const STATUSES = new Set(['needs_input', 'order_placed', 'partially_placed', 'declined', 'approved_not_charged']);
|
|
117
114
|
function statusOf(v) { return typeof v === 'string' && STATUSES.has(v) ? v : 'needs_input'; }
|
|
118
115
|
function placementsOf(v) {
|
|
119
116
|
if (!Array.isArray(v))
|
|
@@ -215,8 +212,8 @@ export class BuyModule extends ApiModule {
|
|
|
215
212
|
}
|
|
216
213
|
/**
|
|
217
214
|
* Places the cart the person saw, by its hash, for the person `user_id`
|
|
218
|
-
* names. With `authorization_id`, the approval the person already gave
|
|
219
|
-
*
|
|
215
|
+
* names. With `authorization_id`, the approval the person already gave
|
|
216
|
+
* for this purchase, the API places against that approval and asks
|
|
220
217
|
* for nothing a second time; the answer carries `authorization_id` back.
|
|
221
218
|
* Without it the confirm runs as before: the person's rules, or the
|
|
222
219
|
* approval the API asks for on `approval_url`. A cart that changed since
|
|
@@ -232,11 +229,9 @@ export class BuyModule extends ApiModule {
|
|
|
232
229
|
if (hashes.length === 0 || hashes.some((h) => typeof h !== 'string' || !CART_HASH.test(h)))
|
|
233
230
|
refuse('invalid_cart_hash', 'confirm must be a cart hash from a previous turn (turn.cart.hash), or a list of them.');
|
|
234
231
|
if (input.authorization_id !== undefined && (typeof input.authorization_id !== 'string' || !/^cauth_/.test(input.authorization_id)))
|
|
235
|
-
refuse('invalid_authorization_id', 'authorization_id must be the approval
|
|
232
|
+
refuse('invalid_authorization_id', 'authorization_id must be the approval you hold for this purchase (cauth_…).');
|
|
236
233
|
if (input.payment_source !== undefined && input.payment_source !== 'vault')
|
|
237
234
|
refuse('invalid_payment_source', "payment_source must be 'vault' when named.");
|
|
238
|
-
if (input.approval !== undefined && input.approval !== 'voice' && input.approval !== 'page')
|
|
239
|
-
refuse('invalid_approval', "approval must be 'voice' or 'page' when named.");
|
|
240
235
|
const body = {
|
|
241
236
|
user_id,
|
|
242
237
|
conversation_id,
|
|
@@ -244,60 +239,10 @@ export class BuyModule extends ApiModule {
|
|
|
244
239
|
...(input.authorization_id ? { authorization_id: input.authorization_id } : {}),
|
|
245
240
|
...(input.delivery_address ? { delivery_address: input.delivery_address } : {}),
|
|
246
241
|
...(input.payment_source ? { payment_source: input.payment_source } : {}),
|
|
247
|
-
...(input.approval ? { approval: input.approval } : {}),
|
|
248
242
|
...(input.wait === true ? { wait: true } : {}),
|
|
249
243
|
};
|
|
250
244
|
return this.turn(body, input.timeout_ms);
|
|
251
245
|
}
|
|
252
|
-
/**
|
|
253
|
-
* The whole approval by voice, for a business whose app holds the person:
|
|
254
|
-
* confirms the cart with the person's own card and `approval: 'voice'`,
|
|
255
|
-
* hands the `authorization_id` the API minted to your `challenge` (your
|
|
256
|
-
* app runs the key word on it; you resolve when the verdict is in), then
|
|
257
|
-
* sends the same confirm again and returns what it answered:
|
|
258
|
-
* `order_placed` with `order_id`, `declined` with `voice_declined` or
|
|
259
|
-
* `approval_expired`, or `needs_approval` again when the verdict was still
|
|
260
|
-
* out. A store whose connector cannot place under a voice verdict is
|
|
261
|
-
* returned as `status: 'voice_execution_unsupported'`, not thrown, so the
|
|
262
|
-
* business falls back to its own path; every other refusal throws as
|
|
263
|
-
* `buy.confirm` does. A first confirm the API completes without asking (a
|
|
264
|
-
* rule took it, or it declined outright) is returned as it came and
|
|
265
|
-
* `challenge` is never called. Two confirms at most; nothing is polled.
|
|
266
|
-
*/
|
|
267
|
-
async approveByVoice(input) {
|
|
268
|
-
if (typeof input?.challenge !== 'function')
|
|
269
|
-
refuse('invalid_challenge', 'Name challenge: the function that runs the key word in your app on the authorization_id and resolves when the verdict is in.');
|
|
270
|
-
const confirm = {
|
|
271
|
-
user_id: input.user_id, conversation_id: input.conversation_id, confirm: input.confirm,
|
|
272
|
-
...(input.delivery_address ? { delivery_address: input.delivery_address } : {}),
|
|
273
|
-
payment_source: 'vault', approval: 'voice', ...(input.timeout_ms !== undefined ? { timeout_ms: input.timeout_ms } : {}),
|
|
274
|
-
};
|
|
275
|
-
const unsupported = (err, authorization_id) => err instanceof BuyError && err.code === VOICE_EXECUTION_UNSUPPORTED ? { status: VOICE_EXECUTION_UNSUPPORTED, conversation_id: err.conversation_id ?? input.conversation_id, authorization_id, error: err } : null;
|
|
276
|
-
let first;
|
|
277
|
-
try {
|
|
278
|
-
first = await this.confirm(confirm);
|
|
279
|
-
}
|
|
280
|
-
catch (err) {
|
|
281
|
-
const u = unsupported(err, null);
|
|
282
|
-
if (u)
|
|
283
|
-
return u;
|
|
284
|
-
throw err;
|
|
285
|
-
}
|
|
286
|
-
if (first.status !== 'needs_approval')
|
|
287
|
-
return first;
|
|
288
|
-
if (!isBuyNeedsApproval(first))
|
|
289
|
-
refuse('missing_authorization_id', 'The API asked for an approval by voice but named no authorization_id to run it on.');
|
|
290
|
-
await input.challenge(first.authorization_id, first);
|
|
291
|
-
try {
|
|
292
|
-
return await this.confirm(confirm);
|
|
293
|
-
}
|
|
294
|
-
catch (err) {
|
|
295
|
-
const u = unsupported(err, first.authorization_id);
|
|
296
|
-
if (u)
|
|
297
|
-
return u;
|
|
298
|
-
throw err;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
246
|
/**
|
|
302
247
|
* One read of a conversation, with no wait: whether a turn is still
|
|
303
248
|
* running, the last checkout attempt, every order it placed from the
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Written by scripts/generate-capabilities.mjs from capabilities.json. Do not edit; git ignores it.
|
|
2
2
|
/** capabilities.json's list, sorted; client.ts exports it as SUPPORTED_CAPABILITIES. */
|
|
3
|
-
export const DECLARED_CAPABILITIES = ["aci_split_card.v1", "amadeus_checkout_actions.v1", "aps_custom_merchant_page", "authorize_net_dpm_form", "barion_hosted_payment_page", "capture_context", "clover_card_token", "comgate_hosted_payment_page", "converge_hpp_process", "creditguard_pps_process", "cybersource_sa_token_create", "datatrans_secure_fields_tokenize", "ekashu_hosted_payment_page", "eximbay_hosted_payment_page", "fastspring_card_payment", "fiserv_card_capture", "gmo_shared_pk", "gopay_card_form", "gravy_session_fields_put", "hipay_vault_token", "juspay_txns.v1", "lyra_krypton_payment", "makecommerce_card_frame", "midtrans_card_token", "moneris_hosted_tokenization", "nexi_checkout_pay", "omise_card_token", "openpay_tokenizer", "paddle_tokenex_pay", "paddle_vgs_cards", "pay_nl_card_token", "payfast_card_pay", "paygent_token", "paymob_checkout_pay", "paymongo_checkout_pay", "paypal_card_fields", "payrails_device_encrypt", "payrexx_card_frame", "paytrail_hosted_payment_page", "payu_latam_webcheckout_card", "pelecard_transaction", "pin_payments_card_token", "poynt_collect_nonce", "primer_payment_instruments", "przelewy24_hosted_payment_page", "quickpay_hosted_payment_page", "redsys_hosted_payment_page", "revolut_card_field", "sbps_token_jsonp", "shiji_sts_pinned_key", "sumup_checkout_process", "tap_card_sdk_token", "toast_pinned_key", "tokenex_iframe_tokenize", "transbank_webpay_hosted_payment_page", "twoc2p_secure_pay", "verifone_card_capture", "wix_payments_tokenize", "worldline_mycheckout_form", "worldpay_eprotect_jsonp", "wspay_confirm", "xendit_card_token"];
|
|
3
|
+
export const DECLARED_CAPABILITIES = ["aci_split_card.v1", "amadeus_checkout_actions.v1", "aps_custom_merchant_page", "aurus_one_time_token", "authorize_net_dpm_form", "barion_hosted_payment_page", "bluesnap_hosted_payment_fields", "capture_context", "cardlink_vpos_hosted_payment_page", "clover_card_token", "comgate_hosted_payment_page", "converge_hpp_process", "creditguard_pps_process", "cybersource_sa_token_create", "datatrans_secure_fields_tokenize", "eghl_hosted_payment_page", "ekashu_hosted_payment_page", "eximbay_hosted_payment_page", "fastspring_card_payment", "fiserv_card_capture", "frisbii_card_token", "gmo_shared_pk", "gopay_card_form", "gravy_session_fields_put", "hipay_vault_token", "iyzico_checkout_form", "juspay_txns.v1", "lyra_krypton_payment", "makecommerce_card_frame", "midtrans_card_token", "monei_card_token", "moneris_hosted_tokenization", "nexi_checkout_pay", "oceanpayment_hosted_payment_page", "omise_card_token", "openpay_tokenizer", "paddle_tokenex_pay", "paddle_vgs_cards", "pay_nl_card_token", "payfast_card_pay", "paygent_token", "paymentwall_card_token", "paymob_checkout_pay", "paymongo_checkout_pay", "paypal_card_fields", "payplug_hosted_payment_page", "payrails_device_encrypt", "payrexx_card_frame", "paystack_pinned_key", "paytrail_hosted_payment_page", "payu_latam_webcheckout_card", "pelecard_transaction", "pin_payments_card_token", "poynt_collect_nonce", "primer_payment_instruments", "processout_card_token", "przelewy24_hosted_payment_page", "quickpay_hosted_payment_page", "redsys_hosted_payment_page", "revolut_card_field", "sbps_token_jsonp", "shiji_sts_pinned_key", "sumup_checkout_process", "tap_card_sdk_token", "toast_pinned_key", "tokenex_iframe_tokenize", "transbank_webpay_hosted_payment_page", "twoc2p_secure_pay", "usaepay_payment_key", "verifone_card_capture", "viva_smart_checkout_chargetoken", "vtex_payments_card_payment", "wix_payments_tokenize", "worldline_mycheckout_form", "worldpay_eprotect_jsonp", "wspay_confirm", "xendit_card_token"];
|