@facto-to/connect 0.0.1-beta.5 → 0.0.1-beta1
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/README.md +13 -117
- package/dist/browser/index.cjs +5 -5
- package/dist/browser/index.d.cts +31 -1
- package/dist/browser/index.d.ts +31 -1
- package/dist/browser/index.js +4 -4
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.d.cts +233 -33
- package/dist/server/index.d.ts +233 -33
- package/dist/server/index.js +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.d.cts +12 -1
- package/dist/testing/index.d.ts +12 -1
- package/dist/testing/index.js +1 -1
- package/package.json +5 -8
- package/dist/index.d-DE9GmLfU.d.cts +0 -114
- package/dist/index.d-DE9GmLfU.d.ts +0 -114
package/dist/server/index.d.ts
CHANGED
|
@@ -1,80 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
declare const PSP_CAPABILITY_TEMPLATES: readonly ["psp_connect_sandbox", "psp_mandate_sandbox", "psp_billing_sandbox"];
|
|
5
|
-
type PspCapabilityTemplate = (typeof PSP_CAPABILITY_TEMPLATES)[number];
|
|
6
|
-
declare const PSP_CREDENTIAL_SCOPES: Record<PspCapabilityTemplate, readonly string[]>;
|
|
7
|
-
declare function carriesMoneyVerb(template: PspCapabilityTemplate): boolean;
|
|
8
|
-
declare const PSP_CREDENTIAL_KEYSPACE: {
|
|
9
|
-
readonly dev: {
|
|
10
|
-
readonly clientIdPrefix: "dev_pspid_";
|
|
11
|
-
readonly clientSecretPrefix: "dev_pspsk_";
|
|
12
|
-
};
|
|
13
|
-
readonly test: {
|
|
14
|
-
readonly clientIdPrefix: "test_pspid_";
|
|
15
|
-
};
|
|
16
|
-
readonly lab: {
|
|
17
|
-
readonly clientIdPrefix: "lab_pspid_";
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
declare const PSP_PARTNER_ROLE_TYPE = "psp";
|
|
21
|
-
declare function withSubMerchant(request: CreateMandatePaymentRequest$1, subMerchant: {
|
|
22
|
-
ref?: string;
|
|
23
|
-
displayName?: string;
|
|
24
|
-
}): CreateMandatePaymentRequest$1;
|
|
25
|
-
declare function subMerchantOf(payment: MandatePayment$1): {
|
|
26
|
-
ref?: string;
|
|
27
|
-
displayName?: string;
|
|
28
|
-
};
|
|
1
|
+
import { MandateUseCase, MandateLimitPeriod, ExchangeLinkCodeResponse, PaymentCapabilityRequestProperties, PaymentCapabilityResponse, MandateAuthorizationSessionStatus, MandateStatus, MandatePaymentStatus, MandateDeclineReason } from '@facto-to/engine-wire';
|
|
2
|
+
export { MandateAuthorizationSessionStatus as MandateAuthorizationStatus, MandateDeclineReason, MandateLimitPeriod, MandatePaymentStatus, MandateStatus, MandateUseCase, PaymentReadinessNotReadyReason } from '@facto-to/engine-wire';
|
|
29
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Customer-facing environment vocabulary (ADR-0077): the published Facto
|
|
6
|
+
* environments are `dev` and `production`, and `'sandbox'` is the documented
|
|
7
|
+
* public name for the dev environment — "sandbox naming, dev interface".
|
|
8
|
+
* `'sandbox'` and `'dev'` are interchangeable selectors for one environment:
|
|
9
|
+
* both resolve the dev endpoints (`https://dev-api.facto.to`, hosted Connect
|
|
10
|
+
* `https://dev.facto.to`) and the `/api/dev/*` route family. `'sandbox'` is
|
|
11
|
+
* the recommended spelling in public documentation; `'dev'` is the
|
|
12
|
+
* infrastructure name passed through unchanged.
|
|
13
|
+
*
|
|
14
|
+
* `staging` and the former `'custom'` selector are retired. Local, private,
|
|
15
|
+
* and staging deployments pass explicit `apiBaseUrl` and `hostedConnectUrl`
|
|
16
|
+
* overrides, which are valid with any environment value and take precedence
|
|
17
|
+
* over the published endpoint tables.
|
|
18
|
+
*/
|
|
30
19
|
type FactoConnectEnvironment = 'dev' | 'production' | 'sandbox';
|
|
20
|
+
/** Canonical infrastructure names keying the published endpoint tables. */
|
|
31
21
|
type PublishedFactoConnectEnvironment = 'dev' | 'production';
|
|
32
22
|
type FactoConnectTransport = (input: string, init?: RequestInit) => Promise<Response>;
|
|
33
23
|
declare const FACTO_CONNECT_API_BASE_URLS: Readonly<Record<PublishedFactoConnectEnvironment, string>>;
|
|
34
24
|
declare const FACTO_CONNECT_HOSTED_URLS: Readonly<Record<PublishedFactoConnectEnvironment, string>>;
|
|
35
|
-
declare function factoConnectEnvironmentFromClientId(clientId: string): PublishedFactoConnectEnvironment | undefined;
|
|
36
25
|
interface FactoConnectServerOptions {
|
|
37
26
|
appId: string;
|
|
38
27
|
clientId: string;
|
|
39
28
|
clientSecret: string;
|
|
40
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Required. `'sandbox'` (the documented public test environment name) and
|
|
31
|
+
* `'dev'` select the same environment and resolve the same published dev
|
|
32
|
+
* endpoints; `'production'` resolves the production endpoints. ADR-0077:
|
|
33
|
+
* "sandbox naming, dev interface". There is no default: omission throws at
|
|
34
|
+
* construction instead of silently targeting production over the retired
|
|
35
|
+
* legacy `/api/external/*` routes, and `'staging'` is retired from the
|
|
36
|
+
* customer-facing vocabulary.
|
|
37
|
+
*
|
|
38
|
+
* The former `'custom'` selector is retired. For a local, private, or
|
|
39
|
+
* staging deployment keep any environment value and pass both explicit
|
|
40
|
+
* URL overrides, e.g.:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* createFactoConnectServer({
|
|
44
|
+
* ...credentials,
|
|
45
|
+
* environment: 'sandbox',
|
|
46
|
+
* apiBaseUrl: 'http://127.0.0.1:8080',
|
|
47
|
+
* hostedConnectUrl: 'http://127.0.0.1:5173',
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
environment: FactoConnectEnvironment;
|
|
52
|
+
/**
|
|
53
|
+
* Explicit endpoint overrides for local, private, or staging deployments.
|
|
54
|
+
* Valid with any `environment` value and take precedence over the
|
|
55
|
+
* published endpoint tables (an override naming a *different* published
|
|
56
|
+
* environment's endpoint is still rejected as a conflict).
|
|
57
|
+
*/
|
|
41
58
|
apiBaseUrl?: string;
|
|
42
59
|
hostedConnectUrl?: string;
|
|
60
|
+
/** Injectable server-side transport. Defaults to `globalThis.fetch`. */
|
|
43
61
|
transport?: FactoConnectTransport;
|
|
62
|
+
/** Alias for `transport`, matching the public Dev SDK contract. */
|
|
44
63
|
fetch?: FactoConnectTransport;
|
|
64
|
+
/** Per-request deadline in milliseconds. Omit to leave deadline control to the caller transport. */
|
|
45
65
|
timeoutMs?: number;
|
|
66
|
+
/** Retry policy for safe GET requests and POST requests carrying an idempotency key. */
|
|
46
67
|
retry?: ServerRetryOptions;
|
|
68
|
+
/** Cancels in-flight requests and retry delays. */
|
|
47
69
|
signal?: AbortSignal;
|
|
48
70
|
}
|
|
49
71
|
interface HostedConnectUrlInput {
|
|
50
72
|
appId: string;
|
|
51
73
|
state: string;
|
|
52
74
|
nonce: string;
|
|
75
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
53
76
|
customerEmail?: string;
|
|
77
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
54
78
|
customerUsername?: string;
|
|
79
|
+
/** Hosted Connect origin for the target environment. Required: there is no implicit default. */
|
|
55
80
|
hostedConnectUrl: string;
|
|
56
|
-
merchantOrigin: string;
|
|
57
81
|
}
|
|
58
82
|
interface CreateHostedConnectUrlInput {
|
|
59
83
|
state: string;
|
|
60
84
|
nonce: string;
|
|
85
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
61
86
|
customerEmail?: string;
|
|
87
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
62
88
|
customerUsername?: string;
|
|
63
89
|
hostedConnectUrl?: string;
|
|
64
|
-
merchantOrigin: string;
|
|
65
90
|
}
|
|
66
91
|
interface ExchangeLinkCodeInput {
|
|
67
92
|
code: string;
|
|
68
93
|
state: string;
|
|
69
94
|
nonce: string;
|
|
70
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Merchant-safe link-code exchange result.
|
|
98
|
+
*
|
|
99
|
+
* This is the pinned engine `ExchangeLinkCodeResponse` verbatim — see
|
|
100
|
+
* `./generated/engine-wire`. New integrations persist `userLinkRef` (and the
|
|
101
|
+
* Dev-only `cardRef` when present); `factoUserId`,
|
|
102
|
+
* `factoServerWalletAddress`, and `cardRef` are transition-only and the wire
|
|
103
|
+
* declares each one independently optional AND nullable, so `null` is a legal
|
|
104
|
+
* value here and must not be narrowed away.
|
|
105
|
+
*/
|
|
71
106
|
type ExchangeLinkCodeResult = ExchangeLinkCodeResponse;
|
|
107
|
+
/**
|
|
108
|
+
* Payment-readiness response. The pinned engine `PaymentCapabilityResponse`
|
|
109
|
+
* verbatim: `notReadyReason` carries the closed
|
|
110
|
+
* `PaymentReadinessNotReadyReason` enum and is optional + nullable, and the
|
|
111
|
+
* legacy identity pair is optional + nullable.
|
|
112
|
+
*/
|
|
72
113
|
type PaymentCapability = PaymentCapabilityResponse;
|
|
73
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Caller-facing shape of the wire `PaymentCapabilityRequest` target. The SDK
|
|
117
|
+
* injects `app_id` from its own configuration, so callers supply the wallet
|
|
118
|
+
* address alone for the legacy shape.
|
|
119
|
+
*/
|
|
74
120
|
interface PaymentCapabilityInputProperties {
|
|
121
|
+
/** GA shape: opaque user-link reference minted by the link-code exchange. */
|
|
75
122
|
userLinkRef?: PaymentCapabilityRequestProperties['userLinkRef'];
|
|
123
|
+
/** Legacy shape: Facto server wallet address of the linked user. */
|
|
76
124
|
factoServerWalletAddress?: PaymentCapabilityRequestProperties['facto_server_wallet_address'];
|
|
77
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Mirrors the wire's INCLUSIVE sibling `anyOf`: legacy-only, GA-only, and the
|
|
128
|
+
* mixed migration shape are all accepted, and only an empty target is rejected.
|
|
129
|
+
* Do not collapse this into an exclusive union with `never` members — the
|
|
130
|
+
* engine contract has no `oneOf` and no `additionalProperties: false`.
|
|
131
|
+
*/
|
|
78
132
|
type PaymentCapabilityInput = PaymentCapabilityInputProperties & (Required<Pick<PaymentCapabilityInputProperties, 'factoServerWalletAddress'>> | Required<Pick<PaymentCapabilityInputProperties, 'userLinkRef'>>);
|
|
79
133
|
type PaymentOptionsInput = ({
|
|
80
134
|
userLinkRef: string;
|
|
@@ -83,6 +137,8 @@ type PaymentOptionsInput = ({
|
|
|
83
137
|
userLinkRef?: never;
|
|
84
138
|
grantRef: string;
|
|
85
139
|
}) & {
|
|
140
|
+
/** Intended charge amount (decimal-USDC string). When set, the engine returns
|
|
141
|
+
* only options that can actually clear this amount (balance/allowance/limits). */
|
|
86
142
|
amount?: string;
|
|
87
143
|
assetSymbol?: string;
|
|
88
144
|
};
|
|
@@ -95,7 +151,14 @@ interface MerchantPaymentOption {
|
|
|
95
151
|
chainLabel: string;
|
|
96
152
|
protocolLabel: string;
|
|
97
153
|
assetSymbol: string;
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Read `settlementPath`. The engine marks this field a duplicate
|
|
156
|
+
* of the settlement axis kept only for wire compatibility, and it is the
|
|
157
|
+
* field that will be removed. When a response carries only
|
|
158
|
+
* `settlementPath`, this mirrors it.
|
|
159
|
+
*/
|
|
98
160
|
spendMode: string;
|
|
161
|
+
/** How an accepted payment settles. Direct-only on the merchant surface. */
|
|
99
162
|
settlementPath: string;
|
|
100
163
|
blockingReason?: string;
|
|
101
164
|
}
|
|
@@ -142,6 +205,12 @@ interface MandateLimits {
|
|
|
142
205
|
interface CreateMandateAuthorizationSessionRequest {
|
|
143
206
|
appId: string;
|
|
144
207
|
externalCustomerRef: string;
|
|
208
|
+
/**
|
|
209
|
+
* Display-only shopper identity, shown on the consent screens and copied
|
|
210
|
+
* onto the grant if the shopper connects inline (reversed-order flow).
|
|
211
|
+
* Never an identifier: not matched against Facto accounts and not part of
|
|
212
|
+
* any authorization decision. Mirrors the pinned engine wire request.
|
|
213
|
+
*/
|
|
145
214
|
customerEmail?: string;
|
|
146
215
|
customerUsername?: string;
|
|
147
216
|
requestedUseCases: MandateUseCase[];
|
|
@@ -155,6 +224,9 @@ interface MandateAuthorizationSession {
|
|
|
155
224
|
authorizationUrl: string;
|
|
156
225
|
status: MandateAuthorizationSessionStatus;
|
|
157
226
|
mandateId?: string;
|
|
227
|
+
/** Present once a shopper has approved. In the reversed-order flow this
|
|
228
|
+
* poll response is the only channel where the merchant backend learns the
|
|
229
|
+
* link ref — no link-code exchange happens. */
|
|
158
230
|
userLinkRef?: string;
|
|
159
231
|
expiresAt: string;
|
|
160
232
|
state: string;
|
|
@@ -196,21 +268,30 @@ interface MandatePayment {
|
|
|
196
268
|
currency: string;
|
|
197
269
|
useCase: MandateUseCase;
|
|
198
270
|
chargeId?: string;
|
|
271
|
+
/** On-chain settlement tx hash, present once the payment reaches a terminal status. */
|
|
199
272
|
txHash?: string;
|
|
200
273
|
declineReason?: MandateDeclineReason;
|
|
201
274
|
finalityEtaSeconds?: number;
|
|
275
|
+
/** Timestamp the payment reached a terminal status. */
|
|
202
276
|
terminalAt?: string;
|
|
203
277
|
createdAt: string;
|
|
204
278
|
updatedAt?: string;
|
|
205
279
|
}
|
|
206
280
|
type MandatePaymentStatusListener = (payment: MandatePayment) => void;
|
|
207
281
|
interface OnMandatePaymentStatusOptions {
|
|
282
|
+
/** Delay before the first poll and the base for backoff, in ms (default 1000). */
|
|
208
283
|
initialIntervalMs?: number;
|
|
284
|
+
/** Upper bound on the poll delay after backoff, in ms (default 8000). */
|
|
209
285
|
maxIntervalMs?: number;
|
|
286
|
+
/** Multiplier applied to the delay after each poll (default 1.5). */
|
|
210
287
|
backoffFactor?: number;
|
|
288
|
+
/** Hard cap on total polling time, in ms (default 300000). Resolves with the
|
|
289
|
+
* latest (possibly non-terminal) payment when hit. */
|
|
211
290
|
timeoutMs?: number;
|
|
291
|
+
/** Cancels polling; the returned promise rejects with an AbortError. */
|
|
212
292
|
signal?: AbortSignal;
|
|
213
293
|
}
|
|
294
|
+
/** Cursor page envelope shared by every GA list endpoint. */
|
|
214
295
|
interface Page<T> {
|
|
215
296
|
data: T[];
|
|
216
297
|
hasMore: boolean;
|
|
@@ -233,6 +314,7 @@ type RefundReason = 'requested_by_customer' | 'duplicate' | 'fraudulent' | 'othe
|
|
|
233
314
|
type RefundStatus = 'pending' | 'succeeded' | 'failed';
|
|
234
315
|
interface CreateRefundInput {
|
|
235
316
|
paymentId: string;
|
|
317
|
+
/** Omit for a full refund of the remaining amount. */
|
|
236
318
|
amount?: string;
|
|
237
319
|
reason?: RefundReason;
|
|
238
320
|
merchantRefundRef?: string;
|
|
@@ -264,11 +346,13 @@ interface WebhookEndpoint {
|
|
|
264
346
|
createdAt: string;
|
|
265
347
|
}
|
|
266
348
|
interface WebhookEndpointWithSecret extends WebhookEndpoint {
|
|
349
|
+
/** Returned exactly once from create/rotate. Store server-side only. */
|
|
267
350
|
secret: string;
|
|
268
351
|
}
|
|
269
352
|
type DevCapabilityName = 'fixtures' | 'synthetic_identity' | 'faucet' | 'simulation' | 'money_loop' | 'webhook_test_delivery';
|
|
270
353
|
type DevCapabilityStatus = 'unavailable' | 'degraded' | 'ready';
|
|
271
354
|
type DevEvidenceLevel = 'contract' | 'implemented' | 'deployed' | 'verified';
|
|
355
|
+
/** Current public evidence projection for one Dev capability. */
|
|
272
356
|
interface DevCapability {
|
|
273
357
|
name: DevCapabilityName;
|
|
274
358
|
status: DevCapabilityStatus;
|
|
@@ -277,12 +361,14 @@ interface DevCapability {
|
|
|
277
361
|
verifiedAt?: string | null;
|
|
278
362
|
limits?: Record<string, string | number | boolean | null>;
|
|
279
363
|
}
|
|
364
|
+
/** Read-only Dev availability and evidence projection. */
|
|
280
365
|
interface DevCapabilities {
|
|
281
366
|
environment: 'dev';
|
|
282
367
|
contractVersion: '2026-07-09';
|
|
283
368
|
capabilities: DevCapability[];
|
|
284
369
|
checkedAt: string;
|
|
285
370
|
}
|
|
371
|
+
/** Dev endpoints accept USDC decimal strings only. */
|
|
286
372
|
interface DevMoney {
|
|
287
373
|
amount: string;
|
|
288
374
|
currency: 'USDC';
|
|
@@ -303,6 +389,7 @@ interface SimulateDevChargeInput {
|
|
|
303
389
|
merchantReference?: string;
|
|
304
390
|
idempotencyKey: string;
|
|
305
391
|
}
|
|
392
|
+
/** A Dev simulation is not a MerchantPayment and has no production settlement meaning. */
|
|
306
393
|
interface DevSimulation {
|
|
307
394
|
simulationId: string;
|
|
308
395
|
scenario: DevSimulationScenario;
|
|
@@ -333,39 +420,71 @@ interface WebhookTestDeliveryAccepted {
|
|
|
333
420
|
}
|
|
334
421
|
interface FactoConnectServerClient {
|
|
335
422
|
createHostedConnectUrl(input: CreateHostedConnectUrlInput): string;
|
|
423
|
+
/** GA operation name for exchanging a one-time user-link code. */
|
|
336
424
|
exchangeUserLinkCode(input: ExchangeLinkCodeInput): Promise<ExchangeLinkCodeResult>;
|
|
425
|
+
/** GA operation name for reading payment readiness. */
|
|
337
426
|
getPaymentReadiness(input: PaymentCapabilityInput): Promise<PaymentCapability>;
|
|
427
|
+
/** GA operation name for creating a payment authorization session. */
|
|
338
428
|
createAuthorizationSession(input: CreateMandateAuthorizationSessionInput): Promise<MandateAuthorizationSession>;
|
|
429
|
+
/** GA operation name for reading a payment authorization session. */
|
|
339
430
|
getAuthorizationSession(sessionId: string): Promise<MandateAuthorizationSession>;
|
|
431
|
+
/** GA operation name for reading one payment authorization. */
|
|
340
432
|
getPaymentAuthorization(authorizationId: string): Promise<MerchantMandate>;
|
|
433
|
+
/** GA operation name for creating an authorized merchant payment. */
|
|
341
434
|
createMerchantPayment(input: CreateMandatePaymentInput): Promise<MandatePayment>;
|
|
435
|
+
/** GA operation name for reading one merchant payment. */
|
|
342
436
|
getMerchantPayment(paymentId: string): Promise<MandatePayment>;
|
|
437
|
+
/** @deprecated Use `exchangeUserLinkCode`. */
|
|
343
438
|
exchangeLinkCode(input: ExchangeLinkCodeInput): Promise<ExchangeLinkCodeResult>;
|
|
439
|
+
/** @deprecated Use `getPaymentReadiness`. */
|
|
344
440
|
getPaymentCapability(input: PaymentCapabilityInput): Promise<PaymentCapability>;
|
|
345
441
|
createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
|
|
346
442
|
getCheckoutSession(id: string): Promise<CheckoutSessionStatus>;
|
|
443
|
+
/** @deprecated Use `createAuthorizationSession`. */
|
|
347
444
|
createMandateAuthorizationSession(input: CreateMandateAuthorizationSessionInput): Promise<MandateAuthorizationSession>;
|
|
445
|
+
/** @deprecated Use `getAuthorizationSession`. */
|
|
348
446
|
getMandateAuthorizationSession(sessionId: string): Promise<MandateAuthorizationSession>;
|
|
447
|
+
/** @deprecated Use `getPaymentAuthorization`. */
|
|
349
448
|
getMerchantMandate(mandateId: string): Promise<MerchantMandate>;
|
|
350
449
|
listPaymentOptions(input: PaymentOptionsInput): Promise<MerchantPaymentOptions>;
|
|
450
|
+
/** @deprecated Use `createMerchantPayment`. */
|
|
351
451
|
createMandatePayment(input: CreateMandatePaymentInput): Promise<MandatePayment>;
|
|
452
|
+
/** @deprecated Use `getMerchantPayment`. */
|
|
352
453
|
getMandatePayment(paymentId: string): Promise<MandatePayment>;
|
|
454
|
+
/**
|
|
455
|
+
* Short-poll a mandate payment until it reaches a terminal status. `listener`
|
|
456
|
+
* is invoked with the payment on the first poll and on every status change;
|
|
457
|
+
* the returned promise resolves with the terminal payment (or the latest
|
|
458
|
+
* payment if `timeoutMs` elapses first). Polling backs off between requests
|
|
459
|
+
* and stops on terminal status, timeout, or abort.
|
|
460
|
+
*/
|
|
353
461
|
onStatus(paymentId: string, listener: MandatePaymentStatusListener, options?: OnMandatePaymentStatusOptions): Promise<MandatePayment>;
|
|
462
|
+
/** Revoke a user link the merchant no longer needs (GA-only). */
|
|
354
463
|
revokeUserLink(userLinkRef: string): Promise<void>;
|
|
464
|
+
/** List merchant payments (reconciliation source of truth). */
|
|
355
465
|
listMerchantPayments(filter?: MerchantPaymentListFilter): Promise<Page<MandatePayment>>;
|
|
466
|
+
/** List payment authorizations (mandates) for this app. */
|
|
356
467
|
listPaymentAuthorizations(filter?: PaymentAuthorizationListFilter): Promise<Page<MerchantMandate>>;
|
|
468
|
+
/** Create a refund against a succeeded payment (partial-capable). */
|
|
357
469
|
createRefund(input: CreateRefundInput): Promise<Refund>;
|
|
358
470
|
getRefund(refundId: string): Promise<Refund>;
|
|
359
471
|
listRefunds(filter?: RefundListFilter): Promise<Page<Refund>>;
|
|
472
|
+
/** Register a webhook endpoint. The signing secret is returned exactly once. */
|
|
360
473
|
createWebhookEndpoint(input: CreateWebhookEndpointInput): Promise<WebhookEndpointWithSecret>;
|
|
361
474
|
listWebhookEndpoints(): Promise<WebhookEndpoint[]>;
|
|
362
475
|
getWebhookEndpoint(webhookEndpointId: string): Promise<WebhookEndpoint>;
|
|
363
476
|
deleteWebhookEndpoint(webhookEndpointId: string): Promise<void>;
|
|
477
|
+
/** Rotate the signing secret; the previous secret verifies for 24h. */
|
|
364
478
|
rotateWebhookSecret(webhookEndpointId: string): Promise<WebhookEndpointWithSecret>;
|
|
479
|
+
/** Read the Dev capability/evidence projection. Dev environment only. */
|
|
365
480
|
getDevCapabilities(): Promise<DevCapabilities>;
|
|
481
|
+
/** Request test-only USDC for an app-owned synthetic linked user. Dev only. */
|
|
366
482
|
fundDevUser(input: FundDevUserInput): Promise<DevFaucetTransfer>;
|
|
483
|
+
/** Create a Dev simulation, distinct from a MerchantPayment. Dev only. */
|
|
367
484
|
simulateDevCharge(input: SimulateDevChargeInput): Promise<DevSimulation>;
|
|
485
|
+
/** Read an app-owned Dev simulation. Dev only. */
|
|
368
486
|
getDevSimulation(simulationId: string): Promise<DevSimulation>;
|
|
487
|
+
/** Queue a signed no-business-state `test.ping`. Dev environment only. */
|
|
369
488
|
sendWebhookTestDelivery(input: SendWebhookTestDeliveryInput): Promise<WebhookTestDeliveryAccepted>;
|
|
370
489
|
}
|
|
371
490
|
type FactoConnectServerErrorCode = 'FACTO_CONFIG_INVALID' | 'FACTO_ENGINE_REQUEST_FAILED' | 'FACTO_ENGINE_RESPONSE_INVALID' | 'FACTO_REQUEST_ABORTED' | 'FACTO_STATUS_POLL_ABORTED';
|
|
@@ -374,6 +493,7 @@ declare class FactoConnectServerError extends Error {
|
|
|
374
493
|
readonly retryable: boolean;
|
|
375
494
|
readonly status?: number;
|
|
376
495
|
readonly details?: unknown;
|
|
496
|
+
/** Seconds from the `Retry-After` response header on a 429, when present. */
|
|
377
497
|
readonly retryAfterSeconds?: number;
|
|
378
498
|
constructor(code: FactoConnectServerErrorCode, message: string, options: {
|
|
379
499
|
retryable: boolean;
|
|
@@ -382,25 +502,74 @@ declare class FactoConnectServerError extends Error {
|
|
|
382
502
|
retryAfterSeconds?: number;
|
|
383
503
|
});
|
|
384
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Options for {@link withServerRetry} and the server client's safe automatic
|
|
507
|
+
* retry policy. GET calls and idempotency-keyed POST calls use these defaults.
|
|
508
|
+
*/
|
|
385
509
|
interface ServerRetryOptions {
|
|
510
|
+
/** Max retry attempts after the first try (default 2). */
|
|
386
511
|
maxRetries?: number;
|
|
512
|
+
/** Base backoff in ms for the exponential fallback (default 200). */
|
|
387
513
|
baseDelayMs?: number;
|
|
514
|
+
/** Backoff cap in ms (default 5000). */
|
|
388
515
|
maxDelayMs?: number;
|
|
516
|
+
/** Honor the server's `Retry-After` when present (default true). */
|
|
389
517
|
respectRetryAfter?: boolean;
|
|
518
|
+
/** Abort waiting/retrying. */
|
|
390
519
|
signal?: AbortSignal;
|
|
520
|
+
/** Invoked before each retry sleep. */
|
|
391
521
|
onRetry?: (info: {
|
|
392
522
|
attempt: number;
|
|
393
523
|
error: FactoConnectServerError;
|
|
394
524
|
delayMs: number;
|
|
395
525
|
}) => void;
|
|
526
|
+
/** Injectable delay (tests). Defaults to a `setTimeout` sleep that respects `signal`. */
|
|
396
527
|
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
397
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* Opt-in retry wrapper for any server-client call. Retries a
|
|
531
|
+
* {@link FactoConnectServerError} whose `retryable` is true (429 / 5xx),
|
|
532
|
+
* honoring `Retry-After` when the server sent it, otherwise exponential backoff
|
|
533
|
+
* with jitter. Non-retryable errors and non-Facto errors are rethrown
|
|
534
|
+
* immediately. The server client applies the same policy only to GET calls and
|
|
535
|
+
* POST calls carrying `Idempotency-Key`; this standalone wrapper remains useful
|
|
536
|
+
* for callers composing their own safe operation:
|
|
537
|
+
*
|
|
538
|
+
* ```ts
|
|
539
|
+
* const payment = await withServerRetry(() => facto.createMandatePayment(input))
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
398
542
|
declare function withServerRetry<T>(fn: () => Promise<T>, options?: ServerRetryOptions): Promise<T>;
|
|
399
543
|
declare function buildHostedConnectUrl(input: HostedConnectUrlInput): string;
|
|
400
544
|
declare function createFactoConnectServer(options: FactoConnectServerOptions): FactoConnectServerClient;
|
|
545
|
+
/** Whether a mandate payment status is terminal (no further transitions). */
|
|
401
546
|
declare function isTerminalMandatePaymentStatus(status: MandatePaymentStatus): boolean;
|
|
547
|
+
/**
|
|
548
|
+
* Sign a raw Facto webhook payload using the same `t/v1` format accepted by
|
|
549
|
+
* {@link verifyWebhookSignature}. This helper is server-only and intended for
|
|
550
|
+
* deterministic fixtures and partner webhook tests.
|
|
551
|
+
*/
|
|
402
552
|
declare function signWebhookPayload(rawBody: string | Uint8Array, secret: string, timestamp?: number): string;
|
|
553
|
+
/**
|
|
554
|
+
* Verify a Facto webhook `Facto-Signature` header against the raw request body
|
|
555
|
+
* (spec 012 webhook contract). Recompute `HMAC-SHA256(secret, "{t}.{raw_body}")`
|
|
556
|
+
* over the EXACT raw bytes, compare in constant time, and reject stale
|
|
557
|
+
* timestamps. Verify BEFORE parsing JSON. During a secret rotation the header
|
|
558
|
+
* may carry two `v1` entries; verification passes if any matches.
|
|
559
|
+
*
|
|
560
|
+
* An empty `secret` is a configuration fault, not a failed verification: Node
|
|
561
|
+
* accepts a zero-length HMAC key, so verifying against `''` would make every
|
|
562
|
+
* forged webhook verify. It throws, matching {@link signWebhookPayload}, rather
|
|
563
|
+
* than returning `false` — a silent `false` reads as "bad signature" and sends
|
|
564
|
+
* the operator hunting the sender instead of their own env.
|
|
565
|
+
*
|
|
566
|
+
* @param rawBody the exact request body bytes (string or Buffer)
|
|
567
|
+
* @param header the `Facto-Signature` header value (`t=..,v1=..[,v1=..]`)
|
|
568
|
+
* @param secret the endpoint signing secret; must be non-empty
|
|
569
|
+
* @param toleranceSeconds max clock skew (default 300s)
|
|
570
|
+
*/
|
|
403
571
|
declare function verifyWebhookSignature(rawBody: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
572
|
+
/** A public Ed25519 JWK (OKP) as served by the Facto connect-hint JWKS. */
|
|
404
573
|
interface FactoCardProgramConnectJwk {
|
|
405
574
|
kty: string;
|
|
406
575
|
crv: string;
|
|
@@ -409,22 +578,44 @@ interface FactoCardProgramConnectJwk {
|
|
|
409
578
|
alg?: string;
|
|
410
579
|
use?: string;
|
|
411
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* The Facto connect-hint JWK set, served (public, no auth) at
|
|
583
|
+
* `GET /.well-known/facto-card-program-connect/jwks.json`.
|
|
584
|
+
*/
|
|
412
585
|
interface FactoCardProgramConnectJwks {
|
|
413
586
|
keys: FactoCardProgramConnectJwk[];
|
|
414
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* How the caller supplies the Facto JWKS: an in-memory `{ keys }` set, a JWKS URL
|
|
590
|
+
* string to fetch (public GET, no auth), or a resolver that returns the set.
|
|
591
|
+
*/
|
|
415
592
|
type FactoCardProgramConnectJwksInput = FactoCardProgramConnectJwks | string | (() => FactoCardProgramConnectJwks | Promise<FactoCardProgramConnectJwks>);
|
|
416
593
|
interface VerifyFactoCardProgramConnectHintInput {
|
|
594
|
+
/** The compact EdDSA JWS the Facto user handed the partner. */
|
|
417
595
|
connectHint: string;
|
|
596
|
+
/** The Facto JWKS: an in-memory `{ keys }` set, a JWKS URL to fetch, or a resolver. */
|
|
418
597
|
jwks: FactoCardProgramConnectJwksInput;
|
|
598
|
+
/**
|
|
599
|
+
* The partner's own connection audience — its environment-unique program code.
|
|
600
|
+
* The hint's `aud` MUST equal this; a mismatch is rejected. Required, because a
|
|
601
|
+
* hint is only meaningful for the program it was scoped to.
|
|
602
|
+
*/
|
|
419
603
|
audience: string;
|
|
604
|
+
/** Expected issuer. Defaults to `'facto'`. */
|
|
420
605
|
issuer?: string;
|
|
606
|
+
/** Verification clock (unix milliseconds or `Date`). Defaults to `Date.now()`. */
|
|
421
607
|
now?: number | Date;
|
|
608
|
+
/** Clock-skew tolerance in seconds applied to the expiry check. Defaults to `0`. */
|
|
422
609
|
clockToleranceSeconds?: number;
|
|
423
610
|
}
|
|
424
611
|
interface FactoCardProgramConnectHint {
|
|
612
|
+
/** The opaque program the hint is scoped to (`cprog_...`). */
|
|
425
613
|
programRef: string;
|
|
614
|
+
/** Pairwise-opaque subject (`facto-user:<hex>`); NEVER the raw Facto user id. */
|
|
426
615
|
pairwiseSubject: string;
|
|
616
|
+
/** Single-use nonce; the caller MUST enforce single-use against its own store. */
|
|
427
617
|
nonce: string;
|
|
618
|
+
/** Absolute expiry (`exp`) as an RFC 3339 / ISO-8601 timestamp. */
|
|
428
619
|
expiresAt: string;
|
|
429
620
|
}
|
|
430
621
|
type FactoConnectHintErrorCode = 'FACTO_HINT_INPUT_INVALID' | 'FACTO_HINT_JWKS_INVALID' | 'FACTO_HINT_MALFORMED' | 'FACTO_HINT_UNSUPPORTED_ALG' | 'FACTO_HINT_SIGNATURE_INVALID' | 'FACTO_HINT_ISSUER_MISMATCH' | 'FACTO_HINT_AUDIENCE_MISMATCH' | 'FACTO_HINT_EXPIRED' | 'FACTO_HINT_CLAIMS_INVALID';
|
|
@@ -435,6 +626,15 @@ declare class FactoConnectHintError extends Error {
|
|
|
435
626
|
details?: unknown;
|
|
436
627
|
});
|
|
437
628
|
}
|
|
629
|
+
/**
|
|
630
|
+
* Verify a Facto-initiated card-program connect-hint (Feature 020 slice C2).
|
|
631
|
+
*
|
|
632
|
+
* Validates the Ed25519 signature against the Facto JWKS, enforces `iss` / `aud`
|
|
633
|
+
* / `exp`, and returns the safe claims. The returned `pairwiseSubject` is the
|
|
634
|
+
* pairwise-opaque HMAC subject (never the raw Facto user id) the partner binds to
|
|
635
|
+
* its own cardholder; the returned `nonce` MUST be enforced single-use by the
|
|
636
|
+
* caller against its own store.
|
|
637
|
+
*/
|
|
438
638
|
declare function verifyFactoCardProgramConnectHint(input: VerifyFactoCardProgramConnectHintInput): Promise<FactoCardProgramConnectHint>;
|
|
439
639
|
|
|
440
|
-
export { type CheckoutSession, type CheckoutSessionStatus, type CheckoutStatus, type CreateCheckoutSessionInput, type CreateHostedConnectUrlInput, type CreateMandateAuthorizationSessionInput, type CreateMandateAuthorizationSessionRequest, type CreateMandatePaymentInput, type CreateMandatePaymentRequest, type CreateRefundInput, type CreateWebhookEndpointInput, type CursorListFilter, type DevCapabilities, type DevCapability, type DevCapabilityName, type DevCapabilityStatus, type DevEvidenceLevel, type DevFaucetTransfer, type DevMoney, type DevSimulation, type DevSimulationExecutionMode, type DevSimulationScenario, type DevSimulationStatus, type ExchangeLinkCodeInput, type ExchangeLinkCodeResult, FACTO_CONNECT_API_BASE_URLS, FACTO_CONNECT_HOSTED_URLS, type FactoCardProgramConnectHint, type FactoCardProgramConnectJwk, type FactoCardProgramConnectJwks, type FactoCardProgramConnectJwksInput, type FactoConnectEnvironment, FactoConnectHintError, type FactoConnectHintErrorCode, type FactoConnectServerClient, FactoConnectServerError, type FactoConnectServerErrorCode, type FactoConnectServerOptions, type FactoConnectTransport, type FundDevUserInput, type HostedConnectUrlInput, type MandateAuthorizationSession,
|
|
640
|
+
export { type CheckoutSession, type CheckoutSessionStatus, type CheckoutStatus, type CreateCheckoutSessionInput, type CreateHostedConnectUrlInput, type CreateMandateAuthorizationSessionInput, type CreateMandateAuthorizationSessionRequest, type CreateMandatePaymentInput, type CreateMandatePaymentRequest, type CreateRefundInput, type CreateWebhookEndpointInput, type CursorListFilter, type DevCapabilities, type DevCapability, type DevCapabilityName, type DevCapabilityStatus, type DevEvidenceLevel, type DevFaucetTransfer, type DevMoney, type DevSimulation, type DevSimulationExecutionMode, type DevSimulationScenario, type DevSimulationStatus, type ExchangeLinkCodeInput, type ExchangeLinkCodeResult, FACTO_CONNECT_API_BASE_URLS, FACTO_CONNECT_HOSTED_URLS, type FactoCardProgramConnectHint, type FactoCardProgramConnectJwk, type FactoCardProgramConnectJwks, type FactoCardProgramConnectJwksInput, type FactoConnectEnvironment, FactoConnectHintError, type FactoConnectHintErrorCode, type FactoConnectServerClient, FactoConnectServerError, type FactoConnectServerErrorCode, type FactoConnectServerOptions, type FactoConnectTransport, type FundDevUserInput, type HostedConnectUrlInput, type MandateAuthorizationSession, type MandateLimits, type MandatePayment, type MandatePaymentStatusListener, type MerchantMandate, type MerchantPaymentListFilter, type MerchantPaymentOption, type MerchantPaymentOptions, type MerchantPaymentPathProjection, type OnMandatePaymentStatusOptions, type Page, type PaymentAuthorizationListFilter, type PaymentCapability, type PaymentCapabilityInput, type PaymentOptionsInput, type Refund, type RefundListFilter, type RefundReason, type RefundStatus, type SendWebhookTestDeliveryInput, type ServerRetryOptions, type SimulateDevChargeInput, type VerifyFactoCardProgramConnectHintInput, type WebhookEndpoint, type WebhookEndpointWithSecret, type WebhookEventType, type WebhookTestDeliveryAccepted, buildHostedConnectUrl, createFactoConnectServer, createFactoConnectServer as default, isTerminalMandatePaymentStatus, signWebhookPayload, verifyFactoCardProgramConnectHint, verifyWebhookSignature, withServerRetry };
|