@agent-cards/sdk 0.23.28 → 0.24.0
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 +58 -0
- package/PREFLIGHT.md +7 -1
- package/README.md +137 -99
- package/dist/aci.d.ts +52 -22
- package/dist/aci.js +79 -15
- package/dist/adyen-merchant-hosted.generated.d.ts +1 -1
- package/dist/adyen-merchant-hosted.generated.js +459 -21
- 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/buy.d.ts +20 -101
- package/dist/buy.js +19 -74
- package/dist/capabilities.generated.js +1 -1
- package/dist/card-fields.generated.js +1398 -106
- package/dist/cdp.d.ts +3 -13
- package/dist/cdp.js +231 -175
- package/dist/client.d.ts +104 -22
- package/dist/client.js +215 -40
- package/dist/creditguard.generated.d.ts +4 -4
- package/dist/datatrans.generated.js +22 -1
- package/dist/elavon-converge.generated.js +5 -3
- package/dist/hold.d.ts +8 -0
- package/dist/hold.js +43 -2
- package/dist/hosted-entry.js +2 -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 +105 -10
- package/dist/payplug.d.ts +41 -0
- package/dist/payplug.js +71 -0
- package/dist/payrails.generated.js +27 -7
- package/dist/pre-claim.d.ts +9 -0
- package/dist/pre-claim.js +86 -7
- package/dist/preflight-capabilities.generated.d.ts +0 -4
- package/dist/preflight-capabilities.generated.js +0 -5
- package/dist/preflight-catalog.json +46 -5
- package/dist/preflight-playwright.d.ts +2 -2
- package/dist/preflight-playwright.js +63 -14
- package/dist/preflight-schemas.json +4 -0
- package/dist/preflight.generated.d.ts +0 -4
- package/dist/preflight.generated.js +24 -1
- package/dist/prepared-processor.d.ts +18 -5
- package/dist/prepared-processor.js +48 -8
- package/dist/primer.generated.js +1418 -120
- 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 +105 -10
- package/dist/stripe-checkout.generated.js +1405 -234
- package/dist/substitutions.generated.js +460 -26
- package/dist/tap-payments.generated.js +105 -10
- package/dist/twoc2p.generated.js +105 -10
- 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/agentcard.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The one client: `new Agentcard({ clientId, clientSecret,
|
|
2
|
+
* The one client: `new Agentcard({ clientId, clientSecret, sandbox? })`,
|
|
3
3
|
* with two modules. `checkout` pauses a browser purchase or creates one
|
|
4
|
-
* directly and replays the processor's answer; `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* credentials.
|
|
4
|
+
* directly and replays the processor's answer; `buy` asks the Purchase API
|
|
5
|
+
* for a cart and places it. One pair of credentials, one token, one base
|
|
6
|
+
* URL; sandbox and live are decided by the credentials.
|
|
8
7
|
*/
|
|
9
8
|
import { VaultClient } from './client.js';
|
|
10
9
|
import { attachToCdp, attachToPlaywright } from './cdp.js';
|
package/dist/amadeus.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare const WIX_PAYMENTS_SEND_WINDOW_MS = 20000;
|
|
|
6
6
|
export declare const HIPAY_SEND_WINDOW_MS = 12000;
|
|
7
7
|
/** How long after the pause a paused Openpay token create may still be sent, of the 40 seconds openpay.js waits. */
|
|
8
8
|
export declare const OPENPAY_SEND_WINDOW_MS = 30000;
|
|
9
|
+
/** How long after the pause a paused VTEX card post may still be sent, of the 12 seconds Ollie's container waits. */
|
|
10
|
+
export declare const VTEX_PAYMENTS_SEND_WINDOW_MS = 8000;
|
|
11
|
+
/** How long after the pause a paused ProcessOut card request may still be sent, of the 20 seconds the card frame waits. */
|
|
12
|
+
export declare const PROCESSOUT_SEND_WINDOW_MS = 12000;
|
|
9
13
|
/**
|
|
10
14
|
* True when a request the adapters refuse must fail as a network error (ERR_FAILED) rather than as
|
|
11
15
|
* the cancellation (ERR_ABORTED) they use elsewhere. An XMLHttpRequest reports a cancellation only
|
|
@@ -15,14 +19,16 @@ export declare const OPENPAY_SEND_WINDOW_MS = 30000;
|
|
|
15
19
|
*/
|
|
16
20
|
export declare function failsAsNetworkError(url: string): boolean;
|
|
17
21
|
/** The processor a send window's events and stop cause name. */
|
|
18
|
-
export type SendWindowProcessor = 'amadeus' | 'secure_acceptance' | 'wix_payments' | 'hipay' | 'openpay';
|
|
22
|
+
export type SendWindowProcessor = 'amadeus' | 'secure_acceptance' | 'wix_payments' | 'hipay' | 'openpay' | 'vtex_payments' | 'processout';
|
|
19
23
|
/** Why a send window stopped its attempt: the API confirmed the card never left the device and never can. */
|
|
20
24
|
export type SendWindowClosed = `${SendWindowProcessor}_send_window_closed`;
|
|
21
25
|
/**
|
|
22
26
|
* The send window for a request paused under a preparation for `psp`, or null when it has none: a
|
|
23
27
|
* prepared Amadeus SDK add, a prepared CyberSource Secure Acceptance token create and a prepared Wix
|
|
24
|
-
* tokenize request, each 20 seconds, a prepared HiPay token create, 12 seconds,
|
|
25
|
-
* create, on exactly a token URL as openpay.js writes it, 30 seconds
|
|
28
|
+
* tokenize request, each 20 seconds, a prepared HiPay token create, 12 seconds, a prepared Openpay token
|
|
29
|
+
* create, on exactly a token URL as openpay.js writes it, 30 seconds, a prepared VTEX card post to a store's own
|
|
30
|
+
* vault, as Ollie writes it, 8 seconds, and a prepared ProcessOut card request, on exactly a card URL as
|
|
31
|
+
* ProcessOut.js writes it, 12 seconds.
|
|
26
32
|
*/
|
|
27
33
|
export declare function preparedSendWindowMs(psp: string | undefined, url: string): number | null;
|
|
28
34
|
/** The processor a prepared request's send window names in its events, or null when it has none. */
|
package/dist/amadeus.js
CHANGED
|
@@ -30,6 +30,17 @@
|
|
|
30
30
|
// get 20: the cardholder's device sends by 25 seconds after it last saw the checkout unbound (the Vault's own
|
|
31
31
|
// window), and Openpay's answer, about a second, then reaches the page with the rest of those 40 seconds to spare.
|
|
32
32
|
//
|
|
33
|
+
// Ollie's headless checkout, which VTEX stores run, aborts its card post to the store's VTEX vault 12 seconds after it
|
|
34
|
+
// starts it (AbortSignal.timeout(12e3), one signal for the post and its resends), and VTEX's answer has to reach the
|
|
35
|
+
// container in that time. A paused VTEX card post gets an 8 second window: a card sent by then leaves 4 seconds for
|
|
36
|
+
// VTEX's answer, the cardholder's device's report and this SDK's next read of it, every 500 ms.
|
|
37
|
+
//
|
|
38
|
+
// ProcessOut.js gives its card frame 20 seconds from the tokenize message before it calls the page's error callback
|
|
39
|
+
// (CardField.timeout), and the frame sends its card request as soon as its sibling frames hand it the expiry and code,
|
|
40
|
+
// so the pause starts a moment into those 20 seconds. A token ProcessOut mints after the page's error callback reaches a
|
|
41
|
+
// page that may already have given up, so a paused card request gets HiPay's 12 second window of the 20, which leaves
|
|
42
|
+
// about 8 for ProcessOut's answer, the API's record of it and the SDK's half-second read.
|
|
43
|
+
//
|
|
33
44
|
// So when the window closes and no answer is being handed to the page yet, the adapter asks for that
|
|
34
45
|
// cancel. Confirmed: nothing was sent and nothing can be, so the attempt stops, the page's request
|
|
35
46
|
// fails (a Secure Acceptance frame gets the stopped page), and the checkout reads failed. Not
|
|
@@ -43,14 +54,18 @@
|
|
|
43
54
|
// processor: `amadeus_send_window_closed` and `amadeus_send_window_unconfirmed`,
|
|
44
55
|
// `secure_acceptance_send_window_closed` and `secure_acceptance_send_window_unconfirmed`,
|
|
45
56
|
// `wix_payments_send_window_closed` and `wix_payments_send_window_unconfirmed`,
|
|
46
|
-
// `hipay_send_window_closed` and `hipay_send_window_unconfirmed`,
|
|
47
|
-
// `openpay_send_window_closed` and `openpay_send_window_unconfirmed
|
|
57
|
+
// `hipay_send_window_closed` and `hipay_send_window_unconfirmed`,
|
|
58
|
+
// `openpay_send_window_closed` and `openpay_send_window_unconfirmed`,
|
|
59
|
+
// `vtex_payments_send_window_closed` and `vtex_payments_send_window_unconfirmed`, or
|
|
60
|
+
// `processout_send_window_closed` and `processout_send_window_unconfirmed`.
|
|
48
61
|
import { amadeusCardUrl } from './amadeus-checkout.generated.js';
|
|
49
62
|
import { isSecureAcceptanceTokenRequest } from './cybersource-secure-acceptance.generated.js';
|
|
50
63
|
import { SECURE_ACCEPTANCE_PSP, SECURE_ACCEPTANCE_SEND_WINDOW_MS } from './cybersource-secure-acceptance.js';
|
|
51
64
|
import { WIX_PAYMENTS_PSP, isWixPaymentsTokenizeUrl } from './wix-payments.generated.js';
|
|
52
65
|
import { HIPAY_PSP, isHipayTokenUrl } from './hipay.generated.js';
|
|
53
66
|
import { OPENPAY_PSP, isOpenpayTokenUrl } from './openpay.generated.js';
|
|
67
|
+
import { VTEX_PAYMENTS_PSP, isVtexPaymentsCardUrl } from './vtex-payments.generated.js';
|
|
68
|
+
import { PROCESSOUT_PSP, isProcessoutCardUrl } from './processout.generated.js';
|
|
54
69
|
/** How long after the pause a paused Amadeus SDK add may still be sent. */
|
|
55
70
|
export const AMADEUS_SEND_WINDOW_MS = 20_000;
|
|
56
71
|
/** How long after the pause a paused Wix tokenize request may still be sent, of the 30 seconds Wix's widget waits. */
|
|
@@ -59,6 +74,10 @@ export const WIX_PAYMENTS_SEND_WINDOW_MS = 20_000;
|
|
|
59
74
|
export const HIPAY_SEND_WINDOW_MS = 12_000;
|
|
60
75
|
/** How long after the pause a paused Openpay token create may still be sent, of the 40 seconds openpay.js waits. */
|
|
61
76
|
export const OPENPAY_SEND_WINDOW_MS = 30_000;
|
|
77
|
+
/** How long after the pause a paused VTEX card post may still be sent, of the 12 seconds Ollie's container waits. */
|
|
78
|
+
export const VTEX_PAYMENTS_SEND_WINDOW_MS = 8_000;
|
|
79
|
+
/** How long after the pause a paused ProcessOut card request may still be sent, of the 20 seconds the card frame waits. */
|
|
80
|
+
export const PROCESSOUT_SEND_WINDOW_MS = 12_000;
|
|
62
81
|
/**
|
|
63
82
|
* True when a request the adapters refuse must fail as a network error (ERR_FAILED) rather than as
|
|
64
83
|
* the cancellation (ERR_ABORTED) they use elsewhere. An XMLHttpRequest reports a cancellation only
|
|
@@ -72,10 +91,14 @@ export function failsAsNetworkError(url) {
|
|
|
72
91
|
/**
|
|
73
92
|
* The send window for a request paused under a preparation for `psp`, or null when it has none: a
|
|
74
93
|
* prepared Amadeus SDK add, a prepared CyberSource Secure Acceptance token create and a prepared Wix
|
|
75
|
-
* tokenize request, each 20 seconds, a prepared HiPay token create, 12 seconds,
|
|
76
|
-
* create, on exactly a token URL as openpay.js writes it, 30 seconds
|
|
94
|
+
* tokenize request, each 20 seconds, a prepared HiPay token create, 12 seconds, a prepared Openpay token
|
|
95
|
+
* create, on exactly a token URL as openpay.js writes it, 30 seconds, a prepared VTEX card post to a store's own
|
|
96
|
+
* vault, as Ollie writes it, 8 seconds, and a prepared ProcessOut card request, on exactly a card URL as
|
|
97
|
+
* ProcessOut.js writes it, 12 seconds.
|
|
77
98
|
*/
|
|
78
99
|
export function preparedSendWindowMs(psp, url) {
|
|
100
|
+
if (psp === VTEX_PAYMENTS_PSP)
|
|
101
|
+
return isVtexPaymentsCardUrl(url) ? VTEX_PAYMENTS_SEND_WINDOW_MS : null;
|
|
79
102
|
if (psp === 'amadeus_checkout')
|
|
80
103
|
return amadeusCardUrl(url)?.path === 'sdk' ? AMADEUS_SEND_WINDOW_MS : null;
|
|
81
104
|
if (psp === SECURE_ACCEPTANCE_PSP) {
|
|
@@ -94,6 +117,8 @@ export function preparedSendWindowMs(psp, url) {
|
|
|
94
117
|
return isHipayTokenUrl(url) ? HIPAY_SEND_WINDOW_MS : null;
|
|
95
118
|
if (psp === OPENPAY_PSP)
|
|
96
119
|
return isOpenpayTokenUrl(url) ? OPENPAY_SEND_WINDOW_MS : null;
|
|
120
|
+
if (psp === PROCESSOUT_PSP)
|
|
121
|
+
return isProcessoutCardUrl(url) ? PROCESSOUT_SEND_WINDOW_MS : null;
|
|
97
122
|
return null;
|
|
98
123
|
}
|
|
99
124
|
/** The processor a prepared request's send window names in its events, or null when it has none. */
|
|
@@ -104,6 +129,10 @@ export function sendWindowProcessor(psp) {
|
|
|
104
129
|
return 'hipay';
|
|
105
130
|
if (psp === OPENPAY_PSP)
|
|
106
131
|
return 'openpay';
|
|
132
|
+
if (psp === VTEX_PAYMENTS_PSP)
|
|
133
|
+
return 'vtex_payments';
|
|
134
|
+
if (psp === PROCESSOUT_PSP)
|
|
135
|
+
return 'processout';
|
|
107
136
|
return psp === 'amadeus_checkout' ? 'amadeus' : psp === SECURE_ACCEPTANCE_PSP ? 'secure_acceptance' : null;
|
|
108
137
|
}
|
|
109
138
|
/** The send window for a prepared Amadeus SDK add, or null: preparedSendWindowMs for Amadeus alone. */
|
package/dist/api-module.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Languages } from './languages.js';
|
|
2
1
|
/** What the client lends its modules: the shared token, the shared HTTP path, and its settings. */
|
|
3
2
|
export interface ApiTransport {
|
|
4
3
|
/** The client-credentials bearer, cached and refreshed by the client; an `AgentcardError('oauth_failed')` when the exchange is refused. */
|
|
@@ -11,19 +10,14 @@ export interface ApiTransport {
|
|
|
11
10
|
timeoutMs?: number;
|
|
12
11
|
}): Promise<T>;
|
|
13
12
|
pollIntervalMs: number;
|
|
14
|
-
/** Deadline for the await calls. Default 60 s. */
|
|
15
|
-
pollTimeoutMs?: number;
|
|
16
13
|
/** Test seam: the retry pauses. */
|
|
17
14
|
backoffMs?: readonly number[];
|
|
18
15
|
/** The pause between two polls; an app may pass one that also wakes when it returns to the foreground. */
|
|
19
16
|
wait?: (ms: number) => Promise<void>;
|
|
20
|
-
/** The languages Agentcard speaks, shared by every module that names one. */
|
|
21
|
-
languages: Languages;
|
|
22
17
|
}
|
|
23
18
|
export declare abstract class ApiModule {
|
|
24
19
|
protected readonly t: ApiTransport;
|
|
25
20
|
protected readonly backoff: readonly number[];
|
|
26
|
-
protected readonly pollTimeoutMs: number;
|
|
27
21
|
protected readonly wait: (ms: number) => Promise<void>;
|
|
28
22
|
protected constructor(t: ApiTransport);
|
|
29
23
|
/** One call, tried again through a transient failure (no response, 502, 503, 504). */
|
|
@@ -50,5 +44,5 @@ export declare abstract class ApiModule {
|
|
|
50
44
|
* asks between two reads; the client never polls faster than the larger of
|
|
51
45
|
* it and its own `pollIntervalMs`.
|
|
52
46
|
*/
|
|
53
|
-
protected poll<T>(read: () => Promise<T | undefined>, timeoutMs: number
|
|
47
|
+
protected poll<T>(read: () => Promise<T | undefined>, timeoutMs: number, onDeadline: () => T, spacingMs?: () => number | undefined): Promise<T>;
|
|
54
48
|
}
|
package/dist/api-module.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* `slow_down`, and the poll that stops at a deadline. Constructed by the
|
|
5
5
|
* client, never on their own.
|
|
6
6
|
*/
|
|
7
|
-
import { isTransient, RETRY_BACKOFF_MS, sleep, withRetries } from './
|
|
8
|
-
import { AgentcardError } from './
|
|
7
|
+
import { isTransient, RETRY_BACKOFF_MS, sleep, withRetries } from './api-retry.js';
|
|
8
|
+
import { AgentcardError } from './api-types.js';
|
|
9
9
|
/** The longest one `slow_down` wait, whatever interval the API names. */
|
|
10
10
|
const SLOW_DOWN_WAIT_CAP_MS = 30_000;
|
|
11
11
|
/** The longest a single read waits out `slow_down` in all before the refusal is thrown to the caller. */
|
|
@@ -13,12 +13,10 @@ const SLOW_DOWN_TOTAL_CAP_MS = 120_000;
|
|
|
13
13
|
export class ApiModule {
|
|
14
14
|
t;
|
|
15
15
|
backoff;
|
|
16
|
-
pollTimeoutMs;
|
|
17
16
|
wait;
|
|
18
17
|
constructor(t) {
|
|
19
18
|
this.t = t;
|
|
20
19
|
this.backoff = t.backoffMs ?? RETRY_BACKOFF_MS;
|
|
21
|
-
this.pollTimeoutMs = t.pollTimeoutMs ?? 60_000;
|
|
22
20
|
this.wait = t.wait ?? sleep;
|
|
23
21
|
}
|
|
24
22
|
/** One call, tried again through a transient failure (no response, 502, 503, 504). */
|
|
@@ -60,7 +58,7 @@ export class ApiModule {
|
|
|
60
58
|
* it and its own `pollIntervalMs`.
|
|
61
59
|
*/
|
|
62
60
|
async poll(read, timeoutMs, onDeadline, spacingMs = () => undefined) {
|
|
63
|
-
const deadline = Date.now() +
|
|
61
|
+
const deadline = Date.now() + timeoutMs;
|
|
64
62
|
let lastFailure = null;
|
|
65
63
|
for (;;) {
|
|
66
64
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentcardError } from './
|
|
1
|
+
import { AgentcardError } from './api-types.js';
|
|
2
2
|
// A phone's network comes and goes and a gateway can be mid-deploy. One
|
|
3
3
|
// failed request is not a failed step: it is tried again, three times, with a
|
|
4
4
|
// growing pause. A write repeated after a lost response may leave a row behind
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The purchase's wire shapes the webhooks read, and the error every module
|
|
3
|
+
* throws. Spellings are the API's (snake_case), so a response can be handed
|
|
4
|
+
* through untouched.
|
|
5
|
+
*/
|
|
6
|
+
export type AuthorizationStatus = 'awaiting_approval' | 'approved' | 'declined' | 'expired' | 'cancelled' | 'completed' | 'timeout';
|
|
7
|
+
/**
|
|
8
|
+
* The business's own words for withdrawing a purchase it watches, while the person is still deciding: the person
|
|
9
|
+
* closed the sheet, the person changed their mind, or a reason of the business's own. The withdrawal stamps one;
|
|
10
|
+
* it is the request's `terminal_reason` from then on.
|
|
11
|
+
*/
|
|
12
|
+
export type CancelReason = 'person_closed_sheet' | 'person_changed_mind' | 'business_cancelled';
|
|
13
|
+
/**
|
|
14
|
+
* How the approval request ended, as CIBA names it. Null while it awaits the person. `cancelled` is the runtime's
|
|
15
|
+
* withdrawal or a processor refusal; the three `CancelReason` words are the business's own withdrawal. A purchase
|
|
16
|
+
* withdrawn before a decision reads `status: 'cancelled'` (since 2026-09-25); its terminal reason says who withdrew it.
|
|
17
|
+
*/
|
|
18
|
+
export type TerminalReason = 'approved' | 'declined_by_person' | 'expired' | 'refused_by_rule' | 'approval_changed' | 'cancelled' | CancelReason;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the charge settled, read back from the processor by Agentcard itself after the purchase finished: the
|
|
21
|
+
* same object the `checkout_authorization.approved` webhook carries at finish and the `settled` /
|
|
22
|
+
* `settlement_unconfirmed` webhook carries once the read lands. `status` is `settled` (the processor holds a
|
|
23
|
+
* succeeded payment), `not_settled` (no charge was made: `reason` says why), or `unknown` (`reason` names what
|
|
24
|
+
* was seen last, `check_pending` while Agentcard is still reading). `final: false` means one of the two
|
|
25
|
+
* settlement webhooks follows; `true` means Agentcard will not check again. `settled_amount` and
|
|
26
|
+
* `settled_currency` are what the processor reports collected, in the currency's smallest unit; `message` is
|
|
27
|
+
* the answer in one sentence.
|
|
28
|
+
*/
|
|
29
|
+
export interface Settlement {
|
|
30
|
+
status: 'settled' | 'not_settled' | 'unknown';
|
|
31
|
+
reason: string;
|
|
32
|
+
final: boolean;
|
|
33
|
+
processor_reference: string | null;
|
|
34
|
+
processor_status: string | null;
|
|
35
|
+
processor_error_code: string | null;
|
|
36
|
+
settled_amount: number | null;
|
|
37
|
+
settled_currency: string | null;
|
|
38
|
+
checked_at: string | null;
|
|
39
|
+
resolved_at: string | null;
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
export declare class AgentcardError extends Error {
|
|
43
|
+
/** The API's error code (`slow_down`), or the client's own (`oauth_failed`). */
|
|
44
|
+
readonly code: string;
|
|
45
|
+
readonly status?: number | undefined;
|
|
46
|
+
/** The rest of the API's error envelope: `slow_down` carries `interval`. */
|
|
47
|
+
readonly details: Record<string, unknown>;
|
|
48
|
+
constructor(
|
|
49
|
+
/** The API's error code (`slow_down`), or the client's own (`oauth_failed`). */
|
|
50
|
+
code: string, message: string, status?: number | undefined,
|
|
51
|
+
/** The rest of the API's error envelope: `slow_down` carries `interval`. */
|
|
52
|
+
details?: Record<string, unknown>);
|
|
53
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The purchase's wire shapes the webhooks read, and the error every module
|
|
3
|
+
* throws. Spellings are the API's (snake_case), so a response can be handed
|
|
4
|
+
* through untouched.
|
|
5
|
+
*/
|
|
1
6
|
export class AgentcardError extends Error {
|
|
2
7
|
code;
|
|
3
8
|
status;
|
|
4
9
|
details;
|
|
5
10
|
constructor(
|
|
6
|
-
/** The API's error code (`
|
|
11
|
+
/** The API's error code (`slow_down`), or the client's own (`oauth_failed`). */
|
|
7
12
|
code, message, status,
|
|
8
|
-
/** The rest of the API's error envelope: `slow_down` carries `interval
|
|
13
|
+
/** The rest of the API's error envelope: `slow_down` carries `interval`. */
|
|
9
14
|
details = {}) {
|
|
10
15
|
super(message);
|
|
11
16
|
this.code = code;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approvals module of the SDK: `agentcard.approvals.*`. Your server creates
|
|
3
|
+
* a purchase for a person connected to your client, the person approves it on
|
|
4
|
+
* Agentcard's page at `approval_url`, and your server reads the decision or
|
|
5
|
+
* waits for it. Same credentials, same token as the checkout calls.
|
|
6
|
+
*/
|
|
7
|
+
import type { PausedRequest } from './client.js';
|
|
8
|
+
import { ApiModule, type ApiTransport } from './api-module.js';
|
|
9
|
+
import { type AuthorizationStatus, type CancelReason, type Settlement, type TerminalReason } from './api-types.js';
|
|
10
|
+
export interface CreateAuthorizationInput {
|
|
11
|
+
/** The person who approves: the `user_id` of a person connected to your client. Required, so a server serving many people never charges the wrong one. */
|
|
12
|
+
user_id: string;
|
|
13
|
+
merchant: string;
|
|
14
|
+
/** An integer in the currency's smallest unit (599 for $5.99). */
|
|
15
|
+
amount: number;
|
|
16
|
+
/** Lowercase ISO code, `usd`. */
|
|
17
|
+
currency: string;
|
|
18
|
+
/**
|
|
19
|
+
* The processor's card request the purchase pauses on: one a browser purchase paused on, one
|
|
20
|
+
* `checkout.requests.build` made, or `'sandbox'`, which names no processor and which only a sandbox
|
|
21
|
+
* client may send (`sandbox_request_in_live` otherwise).
|
|
22
|
+
*/
|
|
23
|
+
request: PausedRequest | 'sandbox';
|
|
24
|
+
/** The processor the request belongs to, as the recognisers name it (`stripe`, `braintree`, `mercado_pago`, …). Default `stripe`. */
|
|
25
|
+
psp?: string;
|
|
26
|
+
/** How the card reaches the processor. Absent means `token`; `cse` and `hosted_form` are checked against the recogniser by the API. */
|
|
27
|
+
mode?: 'token' | 'cse' | 'hosted_form';
|
|
28
|
+
/** Your own key for this create; the same key creates once. The SDK sends a fresh one when you name none. */
|
|
29
|
+
idempotency_key?: string;
|
|
30
|
+
/** The link the approval page sends the person back to, stored on the request. Exactly one of your registered links. */
|
|
31
|
+
return_url?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The exact https origin your app or checkout page pays from (`https://yourapp.example`): what an
|
|
34
|
+
* auto-approval rule the person confirmed needs to take the purchase. Agentcard stores no `origin` header
|
|
35
|
+
* from the paused request, so without this a rule never applies and the create answers
|
|
36
|
+
* `execution_reason: 'unverified_origin'`. Absent, the SDK sends the paused request's `origin` header when
|
|
37
|
+
* it is such an origin (`stripePaymentIntentConfirm(origin, …)` sets one).
|
|
38
|
+
*/
|
|
39
|
+
checkout_origin?: string;
|
|
40
|
+
/** Pins the card that pays: one of the person's stored cards. Absent, the person's recommended card pays, else their only card, and `card` on the answer says which. */
|
|
41
|
+
card_id?: string;
|
|
42
|
+
}
|
|
43
|
+
/** The card that pays, as every read names it. */
|
|
44
|
+
export interface PayingCard {
|
|
45
|
+
id: string;
|
|
46
|
+
/** How the card is named on screen: its product, else its label, else "Visa ····4242". */
|
|
47
|
+
name: string;
|
|
48
|
+
last4: string | null;
|
|
49
|
+
brand: string | null;
|
|
50
|
+
reason: string | null;
|
|
51
|
+
}
|
|
52
|
+
/** One of the cards the person may pay with instead, while the purchase awaits a decision. */
|
|
53
|
+
export interface ChoosableCard extends PayingCard {
|
|
54
|
+
recommended: boolean;
|
|
55
|
+
auto_approve?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** The fields every read of a purchase carries beside its status. */
|
|
58
|
+
export interface AuthorizationFields {
|
|
59
|
+
/** The request handle (`areq_…`); the webhooks carry it too. */
|
|
60
|
+
request_id?: string | null;
|
|
61
|
+
/** Your own id for the person, as the connect named it. */
|
|
62
|
+
external_user_id?: string | null;
|
|
63
|
+
/** Seconds between two reads; `awaitResult` polls no faster. */
|
|
64
|
+
interval?: number;
|
|
65
|
+
/** The same interval in milliseconds, exactly as the request was configured. */
|
|
66
|
+
poll_interval_ms?: number;
|
|
67
|
+
expires_at?: string;
|
|
68
|
+
/** How the request ended; null while it awaits the person. */
|
|
69
|
+
terminal_reason?: TerminalReason | null;
|
|
70
|
+
/** `user_approval`: the person approves on Agentcard's page. `autopilot`: the person's rule took it, no approval step. */
|
|
71
|
+
execution_mode?: 'user_approval' | 'autopilot' | string;
|
|
72
|
+
/** Why no rule took the purchase when your server could mend it: `unverified_origin`, the create named no `checkout_origin`. `execution_detail` says so in a sentence. */
|
|
73
|
+
execution_reason?: 'unverified_origin' | string;
|
|
74
|
+
execution_detail?: string;
|
|
75
|
+
/** The card that pays: the one your create pinned, else the person's recommended card, else their only card; null when several could pay and none is chosen yet. */
|
|
76
|
+
card?: PayingCard | null;
|
|
77
|
+
/** Every card the person may pay with instead, while the purchase awaits a decision. */
|
|
78
|
+
cards?: ChoosableCard[];
|
|
79
|
+
}
|
|
80
|
+
export interface Authorization extends AuthorizationFields {
|
|
81
|
+
id: string;
|
|
82
|
+
status: AuthorizationStatus;
|
|
83
|
+
/**
|
|
84
|
+
* The purchase's own approval page, while it awaits the person: they approve there with Face ID, Touch ID or
|
|
85
|
+
* their master password. Open it in your app, or send it to them. The link is id-only; where the page sends the
|
|
86
|
+
* person afterwards is the `return_url` stored on the request.
|
|
87
|
+
*/
|
|
88
|
+
approval_url?: string;
|
|
89
|
+
/** The registered link the approval page ends on, as stored on the request. */
|
|
90
|
+
return_url?: string;
|
|
91
|
+
}
|
|
92
|
+
export interface AuthorizationResult extends AuthorizationFields {
|
|
93
|
+
/** The purchase's id (`cauth_…`), as read; absent only on `timeout`, which is the SDK's own answer. */
|
|
94
|
+
id?: string;
|
|
95
|
+
/**
|
|
96
|
+
* `approved`, `declined` (the person said no, or a rule or the processor refused), `cancelled` (withdrawn
|
|
97
|
+
* before a decision, by your server's `approvals.cancel` or by the runtime), `expired`, or `timeout` at the
|
|
98
|
+
* deadline.
|
|
99
|
+
*/
|
|
100
|
+
status: AuthorizationStatus;
|
|
101
|
+
/** The purchase's approval page while it awaits the person; absent otherwise. */
|
|
102
|
+
approval_url?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the charge settled, on a finished purchase: present on `approved`, `null` when there is nothing to read
|
|
105
|
+
* back (the request tokenized a card the merchant charges itself), absent while the purchase is open or on
|
|
106
|
+
* `timeout`. `final: false` means the `checkout_authorization.settled` or `settlement_unconfirmed` webhook follows.
|
|
107
|
+
*/
|
|
108
|
+
settlement?: Settlement | null;
|
|
109
|
+
/** `passkey` or `bearer` for a person's approval; empty when a rule took the purchase. */
|
|
110
|
+
approved_with?: string;
|
|
111
|
+
}
|
|
112
|
+
export interface Cancelled {
|
|
113
|
+
id: string;
|
|
114
|
+
status: 'cancelled';
|
|
115
|
+
/** The reason as stamped; `terminal_reason` is the same word on every later read and on the `checkout_authorization.cancelled` webhook. */
|
|
116
|
+
reason: CancelReason;
|
|
117
|
+
terminal_reason: TerminalReason;
|
|
118
|
+
request_id: string | null;
|
|
119
|
+
}
|
|
120
|
+
/** Your server's words for withdrawing a purchase (`approvals.cancel`); anything else is refused before any call. */
|
|
121
|
+
export declare const CANCEL_REASONS: readonly CancelReason[];
|
|
122
|
+
/**
|
|
123
|
+
* The sandbox request: a first run's purchase, naming no processor. Under a sandbox client
|
|
124
|
+
* `approvals.create({ request: 'sandbox' })` sends this; the sandbox completes it without reaching any
|
|
125
|
+
* processor. A live client refuses it before any call (`sandbox_request_in_live`).
|
|
126
|
+
*/
|
|
127
|
+
export declare const SANDBOX_REQUEST: PausedRequest;
|
|
128
|
+
/** `agentcard.approvals`: constructed by the client, never on its own. */
|
|
129
|
+
export declare class ApprovalsModule extends ApiModule {
|
|
130
|
+
private readonly clientIsSandbox;
|
|
131
|
+
constructor(t: ApiTransport, clientIsSandbox: () => boolean);
|
|
132
|
+
/**
|
|
133
|
+
* Creates the purchase, paused for the person's approval on Agentcard's page, for the person `user_id`
|
|
134
|
+
* names. `execution_mode: 'autopilot'` means the person's rule took it and no approval follows.
|
|
135
|
+
* `request: 'sandbox'` is the first-run form: under a sandbox client (`sandbox: true`, an `sk_test_`
|
|
136
|
+
* credential, or a mode the token exchange named) it sends the sandbox request; a live client refuses it
|
|
137
|
+
* before the create leaves (`sandbox_request_in_live`). Every create carries an idempotency key, so a
|
|
138
|
+
* retried call makes one purchase.
|
|
139
|
+
*/
|
|
140
|
+
create(input: CreateAuthorizationInput): Promise<Authorization>;
|
|
141
|
+
/**
|
|
142
|
+
* One read of a purchase, with no wait: its status, what approved it, the request fields and the settlement
|
|
143
|
+
* once it finished. The way to ask "is it decided yet?" from a handler that cannot wait; `awaitResult` is the
|
|
144
|
+
* way to wait. `slow_down` is waited out.
|
|
145
|
+
*/
|
|
146
|
+
get(authorizationId: string): Promise<AuthorizationResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Withdraws a purchase that still awaits the person, in your server's own words: the person closed the
|
|
149
|
+
* page (`person_closed_sheet`), the person changed their mind (`person_changed_mind`), or a reason of your
|
|
150
|
+
* own (`business_cancelled`). The purchase reads `status: 'cancelled'` from then on, and the reason is its
|
|
151
|
+
* `terminal_reason` on every read and on the `checkout_authorization.cancelled` webhook. Idempotent: a
|
|
152
|
+
* purchase already withdrawn answers what it became. One the person already approved cannot be withdrawn
|
|
153
|
+
* (`409 already_finalized` once it finished, `409 outcome_unknown` while the card is with the processor).
|
|
154
|
+
*/
|
|
155
|
+
cancel(authorizationId: string, opts: {
|
|
156
|
+
reason: CancelReason;
|
|
157
|
+
}): Promise<Cancelled>;
|
|
158
|
+
/**
|
|
159
|
+
* Polls the purchase until it leaves `awaiting_approval`; `{ status: 'timeout' }` at the deadline (60 s unless
|
|
160
|
+
* `timeout_ms` names another). The first read's `interval` (seconds) is the least this waits between reads, and
|
|
161
|
+
* a `slow_down` answer backs off to the interval it names and keeps polling.
|
|
162
|
+
*/
|
|
163
|
+
awaitResult(authorizationId: string, opts?: {
|
|
164
|
+
timeout_ms?: number;
|
|
165
|
+
}): Promise<AuthorizationResult>;
|
|
166
|
+
}
|