@facto-to/connect 0.0.1-beta.5 → 0.0.1-beta2
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 +1 -84
- 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 +303 -9
- package/dist/server/index.d.ts +303 -9
- 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,228 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { MandatePayment as MandatePayment$1, CreateMandatePaymentRequest as CreateMandatePaymentRequest$1, 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';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* PSP scenario surface (spec 032 FR-021).
|
|
6
|
+
*
|
|
7
|
+
* The wrapper is deliberately thin: there is no per-PSP code anywhere in this
|
|
8
|
+
* package, and everything a PSP sends or receives is a generated
|
|
9
|
+
* `@facto-to/engine-wire` type. What lives here is only what codegen cannot
|
|
10
|
+
* express — the value sets the engine keeps in Rust constants and migration
|
|
11
|
+
* CHECK constraints rather than in `openapi.gen.json`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** The two reviewed PSP capability templates (spec 032 S3). */
|
|
15
|
+
declare const PSP_CAPABILITY_TEMPLATES: readonly ["psp_connect_sandbox", "psp_mandate_sandbox"];
|
|
5
16
|
type PspCapabilityTemplate = (typeof PSP_CAPABILITY_TEMPLATES)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Credential scopes per template, IN ORDER.
|
|
19
|
+
*
|
|
20
|
+
* Order is part of the contract, not a formatting preference. The engine's
|
|
21
|
+
* `external_app_clients_partner_template_check` compares with `=` and Postgres
|
|
22
|
+
* compares arrays element-wise, so a reordered list is rejected at mint time
|
|
23
|
+
* with a bare `23514` and no explanation. Build request payloads from these
|
|
24
|
+
* arrays rather than assembling scope lists by hand.
|
|
25
|
+
*/
|
|
6
26
|
declare const PSP_CREDENTIAL_SCOPES: Record<PspCapabilityTemplate, readonly string[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Which template carries a money verb.
|
|
29
|
+
*
|
|
30
|
+
* FR-003's whole content: the read surface is grantable WITHOUT the ability to
|
|
31
|
+
* move money. `psp_connect_sandbox` carries neither `payments.execute` nor
|
|
32
|
+
* `refunds.execute`.
|
|
33
|
+
*/
|
|
7
34
|
declare function carriesMoneyVerb(template: PspCapabilityTemplate): boolean;
|
|
35
|
+
/** Client-id / client-secret prefixes, per environment. */
|
|
8
36
|
declare const PSP_CREDENTIAL_KEYSPACE: {
|
|
9
37
|
readonly dev: {
|
|
10
38
|
readonly clientIdPrefix: "dev_pspid_";
|
|
11
39
|
readonly clientSecretPrefix: "dev_pspsk_";
|
|
12
40
|
};
|
|
13
|
-
readonly test: {
|
|
14
|
-
readonly clientIdPrefix: "test_pspid_";
|
|
15
|
-
};
|
|
16
41
|
readonly lab: {
|
|
17
42
|
readonly clientIdPrefix: "lab_pspid_";
|
|
18
43
|
};
|
|
19
44
|
};
|
|
45
|
+
/** The value `partnerRoleType` carries for a PSP on the consumer projections. */
|
|
20
46
|
declare const PSP_PARTNER_ROLE_TYPE = "psp";
|
|
47
|
+
/**
|
|
48
|
+
* Attach sub-merchant metadata to a payment request (spec 032 FR-011/FR-012).
|
|
49
|
+
*
|
|
50
|
+
* A helper rather than a note in the docs, because the two fields are NOT
|
|
51
|
+
* interchangeable and the difference is invisible from the type — both are
|
|
52
|
+
* `string`:
|
|
53
|
+
*
|
|
54
|
+
* - `ref` is your reconciliation anchor. It rides the payment webhook, so you
|
|
55
|
+
* can reconcile from webhooks without calling back per event.
|
|
56
|
+
* - `displayName` is what the shopper sees on their billing line. It is
|
|
57
|
+
* deliberately absent from webhook payloads: Facto signs those bodies, and a
|
|
58
|
+
* signature must not vouch for a string a third party wrote. Read it from the
|
|
59
|
+
* authenticated payment GET.
|
|
60
|
+
*
|
|
61
|
+
* Neither is an identifier. Facto never keys, joins, groups or deduplicates on
|
|
62
|
+
* `subMerchantRef` — two payments differing only in it resolve the same mandate
|
|
63
|
+
* and the same route.
|
|
64
|
+
*/
|
|
21
65
|
declare function withSubMerchant(request: CreateMandatePaymentRequest$1, subMerchant: {
|
|
22
66
|
ref?: string;
|
|
23
67
|
displayName?: string;
|
|
24
68
|
}): CreateMandatePaymentRequest$1;
|
|
69
|
+
/**
|
|
70
|
+
* Read the sub-merchant back off a payment.
|
|
71
|
+
*
|
|
72
|
+
* `displayName` is `undefined` on anything sourced from a webhook and present
|
|
73
|
+
* on an authenticated read — see {@link withSubMerchant}. Reading through this
|
|
74
|
+
* helper keeps that asymmetry in one place instead of at every call site.
|
|
75
|
+
*/
|
|
25
76
|
declare function subMerchantOf(payment: MandatePayment$1): {
|
|
26
77
|
ref?: string;
|
|
27
78
|
displayName?: string;
|
|
28
79
|
};
|
|
29
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Customer-facing environment vocabulary (ADR-0077): the published Facto
|
|
83
|
+
* environments are `dev` and `production`, and `'sandbox'` is the documented
|
|
84
|
+
* public name for the dev environment — "sandbox naming, dev interface".
|
|
85
|
+
* `'sandbox'` and `'dev'` are interchangeable selectors for one environment:
|
|
86
|
+
* both resolve the dev endpoints (`https://dev-api.facto.to`, hosted Connect
|
|
87
|
+
* `https://dev.facto.to`) and the `/api/dev/*` route family. `'sandbox'` is
|
|
88
|
+
* the recommended spelling in public documentation; `'dev'` is the
|
|
89
|
+
* infrastructure name passed through unchanged.
|
|
90
|
+
*
|
|
91
|
+
* `staging` and the former `'custom'` selector are retired. Local, private,
|
|
92
|
+
* and staging deployments pass explicit `apiBaseUrl` and `hostedConnectUrl`
|
|
93
|
+
* overrides, which are valid with any environment value and take precedence
|
|
94
|
+
* over the published endpoint tables.
|
|
95
|
+
*/
|
|
30
96
|
type FactoConnectEnvironment = 'dev' | 'production' | 'sandbox';
|
|
97
|
+
/** Canonical infrastructure names keying the published endpoint tables. */
|
|
31
98
|
type PublishedFactoConnectEnvironment = 'dev' | 'production';
|
|
32
99
|
type FactoConnectTransport = (input: string, init?: RequestInit) => Promise<Response>;
|
|
33
100
|
declare const FACTO_CONNECT_API_BASE_URLS: Readonly<Record<PublishedFactoConnectEnvironment, string>>;
|
|
34
101
|
declare const FACTO_CONNECT_HOSTED_URLS: Readonly<Record<PublishedFactoConnectEnvironment, string>>;
|
|
102
|
+
/**
|
|
103
|
+
* Read the published environment a client id belongs to, or `undefined` when
|
|
104
|
+
* the id carries no recognized keyspace.
|
|
105
|
+
*
|
|
106
|
+
* `undefined` covers the internal (`lab_`/`staging_`/`test_`) and legacy
|
|
107
|
+
* (`sandbox_`) keyspaces as well as anything unrecognized. Those never derive
|
|
108
|
+
* an environment: an unrecognized id must not silently resolve to production,
|
|
109
|
+
* which is the failure mode the removed implicit default used to cause.
|
|
110
|
+
*/
|
|
35
111
|
declare function factoConnectEnvironmentFromClientId(clientId: string): PublishedFactoConnectEnvironment | undefined;
|
|
36
112
|
interface FactoConnectServerOptions {
|
|
37
113
|
appId: string;
|
|
38
114
|
clientId: string;
|
|
39
115
|
clientSecret: string;
|
|
116
|
+
/**
|
|
117
|
+
* Optional. `'sandbox'` (the documented public test environment name) and
|
|
118
|
+
* `'dev'` select the same environment and resolve the same published dev
|
|
119
|
+
* endpoints; `'production'` resolves the production endpoints. ADR-0077:
|
|
120
|
+
* "sandbox naming, dev interface". `'staging'` is retired from the
|
|
121
|
+
* customer-facing vocabulary.
|
|
122
|
+
*
|
|
123
|
+
* Omit it and the environment is derived from `clientId`'s keyspace —
|
|
124
|
+
* `dev_mcid_`/`dev_pspid_`/`dev_cpid_` resolve the dev endpoints, bare
|
|
125
|
+
* `mcid_`/`pspid_`/`cpid_` resolve production. This is evidence, not a
|
|
126
|
+
* default: an unrecognized client id derives nothing and still throws at
|
|
127
|
+
* construction rather than silently targeting production, which is what the
|
|
128
|
+
* removed implicit fallback used to do. Passing it explicitly is still
|
|
129
|
+
* supported and is checked against the credential, so a mismatch fails at
|
|
130
|
+
* construction.
|
|
131
|
+
*
|
|
132
|
+
* The former `'custom'` selector is retired. For a local, private, or
|
|
133
|
+
* staging deployment keep any environment value and pass both explicit
|
|
134
|
+
* URL overrides, e.g.:
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* createFactoConnectServer({
|
|
138
|
+
* ...credentials,
|
|
139
|
+
* environment: 'sandbox',
|
|
140
|
+
* apiBaseUrl: 'http://127.0.0.1:8080',
|
|
141
|
+
* hostedConnectUrl: 'http://127.0.0.1:5173',
|
|
142
|
+
* })
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
40
145
|
environment?: FactoConnectEnvironment;
|
|
146
|
+
/**
|
|
147
|
+
* Explicit endpoint overrides for local, private, or staging deployments.
|
|
148
|
+
* Valid with any `environment` value and take precedence over the
|
|
149
|
+
* published endpoint tables (an override naming a *different* published
|
|
150
|
+
* environment's endpoint is still rejected as a conflict).
|
|
151
|
+
*/
|
|
41
152
|
apiBaseUrl?: string;
|
|
42
153
|
hostedConnectUrl?: string;
|
|
154
|
+
/** Injectable server-side transport. Defaults to `globalThis.fetch`. */
|
|
43
155
|
transport?: FactoConnectTransport;
|
|
156
|
+
/** Alias for `transport`, matching the public Dev SDK contract. */
|
|
44
157
|
fetch?: FactoConnectTransport;
|
|
158
|
+
/** Per-request deadline in milliseconds. Omit to leave deadline control to the caller transport. */
|
|
45
159
|
timeoutMs?: number;
|
|
160
|
+
/** Retry policy for safe GET requests and POST requests carrying an idempotency key. */
|
|
46
161
|
retry?: ServerRetryOptions;
|
|
162
|
+
/** Cancels in-flight requests and retry delays. */
|
|
47
163
|
signal?: AbortSignal;
|
|
48
164
|
}
|
|
49
165
|
interface HostedConnectUrlInput {
|
|
50
166
|
appId: string;
|
|
51
167
|
state: string;
|
|
52
168
|
nonce: string;
|
|
169
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
53
170
|
customerEmail?: string;
|
|
171
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
54
172
|
customerUsername?: string;
|
|
173
|
+
/** Hosted Connect origin for the target environment. Required: there is no implicit default. */
|
|
55
174
|
hostedConnectUrl: string;
|
|
56
|
-
merchantOrigin: string;
|
|
57
175
|
}
|
|
58
176
|
interface CreateHostedConnectUrlInput {
|
|
59
177
|
state: string;
|
|
60
178
|
nonce: string;
|
|
179
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
61
180
|
customerEmail?: string;
|
|
181
|
+
/** Display-only merchant identity for the shopper. Not used for authentication or exchange. */
|
|
62
182
|
customerUsername?: string;
|
|
63
183
|
hostedConnectUrl?: string;
|
|
64
|
-
merchantOrigin: string;
|
|
65
184
|
}
|
|
66
185
|
interface ExchangeLinkCodeInput {
|
|
67
186
|
code: string;
|
|
68
187
|
state: string;
|
|
69
188
|
nonce: string;
|
|
70
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Merchant-safe link-code exchange result.
|
|
192
|
+
*
|
|
193
|
+
* This is the pinned engine `ExchangeLinkCodeResponse` verbatim — see
|
|
194
|
+
* `./generated/engine-wire`. New integrations persist `userLinkRef` (and the
|
|
195
|
+
* Dev-only `cardRef` when present); `factoUserId`,
|
|
196
|
+
* `factoServerWalletAddress`, and `cardRef` are transition-only and the wire
|
|
197
|
+
* declares each one independently optional AND nullable, so `null` is a legal
|
|
198
|
+
* value here and must not be narrowed away.
|
|
199
|
+
*/
|
|
71
200
|
type ExchangeLinkCodeResult = ExchangeLinkCodeResponse;
|
|
201
|
+
/**
|
|
202
|
+
* Payment-readiness response. The pinned engine `PaymentCapabilityResponse`
|
|
203
|
+
* verbatim: `notReadyReason` carries the closed
|
|
204
|
+
* `PaymentReadinessNotReadyReason` enum and is optional + nullable, and the
|
|
205
|
+
* legacy identity pair is optional + nullable.
|
|
206
|
+
*/
|
|
72
207
|
type PaymentCapability = PaymentCapabilityResponse;
|
|
73
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Caller-facing shape of the wire `PaymentCapabilityRequest` target. The SDK
|
|
211
|
+
* injects `app_id` from its own configuration, so callers supply the wallet
|
|
212
|
+
* address alone for the legacy shape.
|
|
213
|
+
*/
|
|
74
214
|
interface PaymentCapabilityInputProperties {
|
|
215
|
+
/** GA shape: opaque user-link reference minted by the link-code exchange. */
|
|
75
216
|
userLinkRef?: PaymentCapabilityRequestProperties['userLinkRef'];
|
|
217
|
+
/** Legacy shape: Facto server wallet address of the linked user. */
|
|
76
218
|
factoServerWalletAddress?: PaymentCapabilityRequestProperties['facto_server_wallet_address'];
|
|
77
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Mirrors the wire's INCLUSIVE sibling `anyOf`: legacy-only, GA-only, and the
|
|
222
|
+
* mixed migration shape are all accepted, and only an empty target is rejected.
|
|
223
|
+
* Do not collapse this into an exclusive union with `never` members — the
|
|
224
|
+
* engine contract has no `oneOf` and no `additionalProperties: false`.
|
|
225
|
+
*/
|
|
78
226
|
type PaymentCapabilityInput = PaymentCapabilityInputProperties & (Required<Pick<PaymentCapabilityInputProperties, 'factoServerWalletAddress'>> | Required<Pick<PaymentCapabilityInputProperties, 'userLinkRef'>>);
|
|
79
227
|
type PaymentOptionsInput = ({
|
|
80
228
|
userLinkRef: string;
|
|
@@ -83,6 +231,8 @@ type PaymentOptionsInput = ({
|
|
|
83
231
|
userLinkRef?: never;
|
|
84
232
|
grantRef: string;
|
|
85
233
|
}) & {
|
|
234
|
+
/** Intended charge amount (decimal-USDC string). When set, the engine returns
|
|
235
|
+
* only options that can actually clear this amount (balance/allowance/limits). */
|
|
86
236
|
amount?: string;
|
|
87
237
|
assetSymbol?: string;
|
|
88
238
|
};
|
|
@@ -95,7 +245,14 @@ interface MerchantPaymentOption {
|
|
|
95
245
|
chainLabel: string;
|
|
96
246
|
protocolLabel: string;
|
|
97
247
|
assetSymbol: string;
|
|
248
|
+
/**
|
|
249
|
+
* @deprecated Read `settlementPath`. The engine marks this field a duplicate
|
|
250
|
+
* of the settlement axis kept only for wire compatibility, and it is the
|
|
251
|
+
* field that will be removed. When a response carries only
|
|
252
|
+
* `settlementPath`, this mirrors it.
|
|
253
|
+
*/
|
|
98
254
|
spendMode: string;
|
|
255
|
+
/** How an accepted payment settles. Direct-only on the merchant surface. */
|
|
99
256
|
settlementPath: string;
|
|
100
257
|
blockingReason?: string;
|
|
101
258
|
}
|
|
@@ -142,6 +299,12 @@ interface MandateLimits {
|
|
|
142
299
|
interface CreateMandateAuthorizationSessionRequest {
|
|
143
300
|
appId: string;
|
|
144
301
|
externalCustomerRef: string;
|
|
302
|
+
/**
|
|
303
|
+
* Display-only shopper identity, shown on the consent screens and copied
|
|
304
|
+
* onto the grant if the shopper connects inline (reversed-order flow).
|
|
305
|
+
* Never an identifier: not matched against Facto accounts and not part of
|
|
306
|
+
* any authorization decision. Mirrors the pinned engine wire request.
|
|
307
|
+
*/
|
|
145
308
|
customerEmail?: string;
|
|
146
309
|
customerUsername?: string;
|
|
147
310
|
requestedUseCases: MandateUseCase[];
|
|
@@ -155,6 +318,9 @@ interface MandateAuthorizationSession {
|
|
|
155
318
|
authorizationUrl: string;
|
|
156
319
|
status: MandateAuthorizationSessionStatus;
|
|
157
320
|
mandateId?: string;
|
|
321
|
+
/** Present once a shopper has approved. In the reversed-order flow this
|
|
322
|
+
* poll response is the only channel where the merchant backend learns the
|
|
323
|
+
* link ref — no link-code exchange happens. */
|
|
158
324
|
userLinkRef?: string;
|
|
159
325
|
expiresAt: string;
|
|
160
326
|
state: string;
|
|
@@ -196,21 +362,30 @@ interface MandatePayment {
|
|
|
196
362
|
currency: string;
|
|
197
363
|
useCase: MandateUseCase;
|
|
198
364
|
chargeId?: string;
|
|
365
|
+
/** On-chain settlement tx hash, present once the payment reaches a terminal status. */
|
|
199
366
|
txHash?: string;
|
|
200
367
|
declineReason?: MandateDeclineReason;
|
|
201
368
|
finalityEtaSeconds?: number;
|
|
369
|
+
/** Timestamp the payment reached a terminal status. */
|
|
202
370
|
terminalAt?: string;
|
|
203
371
|
createdAt: string;
|
|
204
372
|
updatedAt?: string;
|
|
205
373
|
}
|
|
206
374
|
type MandatePaymentStatusListener = (payment: MandatePayment) => void;
|
|
207
375
|
interface OnMandatePaymentStatusOptions {
|
|
376
|
+
/** Delay before the first poll and the base for backoff, in ms (default 1000). */
|
|
208
377
|
initialIntervalMs?: number;
|
|
378
|
+
/** Upper bound on the poll delay after backoff, in ms (default 8000). */
|
|
209
379
|
maxIntervalMs?: number;
|
|
380
|
+
/** Multiplier applied to the delay after each poll (default 1.5). */
|
|
210
381
|
backoffFactor?: number;
|
|
382
|
+
/** Hard cap on total polling time, in ms (default 300000). Resolves with the
|
|
383
|
+
* latest (possibly non-terminal) payment when hit. */
|
|
211
384
|
timeoutMs?: number;
|
|
385
|
+
/** Cancels polling; the returned promise rejects with an AbortError. */
|
|
212
386
|
signal?: AbortSignal;
|
|
213
387
|
}
|
|
388
|
+
/** Cursor page envelope shared by every GA list endpoint. */
|
|
214
389
|
interface Page<T> {
|
|
215
390
|
data: T[];
|
|
216
391
|
hasMore: boolean;
|
|
@@ -233,6 +408,7 @@ type RefundReason = 'requested_by_customer' | 'duplicate' | 'fraudulent' | 'othe
|
|
|
233
408
|
type RefundStatus = 'pending' | 'succeeded' | 'failed';
|
|
234
409
|
interface CreateRefundInput {
|
|
235
410
|
paymentId: string;
|
|
411
|
+
/** Omit for a full refund of the remaining amount. */
|
|
236
412
|
amount?: string;
|
|
237
413
|
reason?: RefundReason;
|
|
238
414
|
merchantRefundRef?: string;
|
|
@@ -264,11 +440,13 @@ interface WebhookEndpoint {
|
|
|
264
440
|
createdAt: string;
|
|
265
441
|
}
|
|
266
442
|
interface WebhookEndpointWithSecret extends WebhookEndpoint {
|
|
443
|
+
/** Returned exactly once from create/rotate. Store server-side only. */
|
|
267
444
|
secret: string;
|
|
268
445
|
}
|
|
269
446
|
type DevCapabilityName = 'fixtures' | 'synthetic_identity' | 'faucet' | 'simulation' | 'money_loop' | 'webhook_test_delivery';
|
|
270
447
|
type DevCapabilityStatus = 'unavailable' | 'degraded' | 'ready';
|
|
271
448
|
type DevEvidenceLevel = 'contract' | 'implemented' | 'deployed' | 'verified';
|
|
449
|
+
/** Current public evidence projection for one Dev capability. */
|
|
272
450
|
interface DevCapability {
|
|
273
451
|
name: DevCapabilityName;
|
|
274
452
|
status: DevCapabilityStatus;
|
|
@@ -277,12 +455,14 @@ interface DevCapability {
|
|
|
277
455
|
verifiedAt?: string | null;
|
|
278
456
|
limits?: Record<string, string | number | boolean | null>;
|
|
279
457
|
}
|
|
458
|
+
/** Read-only Dev availability and evidence projection. */
|
|
280
459
|
interface DevCapabilities {
|
|
281
460
|
environment: 'dev';
|
|
282
461
|
contractVersion: '2026-07-09';
|
|
283
462
|
capabilities: DevCapability[];
|
|
284
463
|
checkedAt: string;
|
|
285
464
|
}
|
|
465
|
+
/** Dev endpoints accept USDC decimal strings only. */
|
|
286
466
|
interface DevMoney {
|
|
287
467
|
amount: string;
|
|
288
468
|
currency: 'USDC';
|
|
@@ -303,6 +483,7 @@ interface SimulateDevChargeInput {
|
|
|
303
483
|
merchantReference?: string;
|
|
304
484
|
idempotencyKey: string;
|
|
305
485
|
}
|
|
486
|
+
/** A Dev simulation is not a MerchantPayment and has no production settlement meaning. */
|
|
306
487
|
interface DevSimulation {
|
|
307
488
|
simulationId: string;
|
|
308
489
|
scenario: DevSimulationScenario;
|
|
@@ -333,39 +514,71 @@ interface WebhookTestDeliveryAccepted {
|
|
|
333
514
|
}
|
|
334
515
|
interface FactoConnectServerClient {
|
|
335
516
|
createHostedConnectUrl(input: CreateHostedConnectUrlInput): string;
|
|
517
|
+
/** GA operation name for exchanging a one-time user-link code. */
|
|
336
518
|
exchangeUserLinkCode(input: ExchangeLinkCodeInput): Promise<ExchangeLinkCodeResult>;
|
|
519
|
+
/** GA operation name for reading payment readiness. */
|
|
337
520
|
getPaymentReadiness(input: PaymentCapabilityInput): Promise<PaymentCapability>;
|
|
521
|
+
/** GA operation name for creating a payment authorization session. */
|
|
338
522
|
createAuthorizationSession(input: CreateMandateAuthorizationSessionInput): Promise<MandateAuthorizationSession>;
|
|
523
|
+
/** GA operation name for reading a payment authorization session. */
|
|
339
524
|
getAuthorizationSession(sessionId: string): Promise<MandateAuthorizationSession>;
|
|
525
|
+
/** GA operation name for reading one payment authorization. */
|
|
340
526
|
getPaymentAuthorization(authorizationId: string): Promise<MerchantMandate>;
|
|
527
|
+
/** GA operation name for creating an authorized merchant payment. */
|
|
341
528
|
createMerchantPayment(input: CreateMandatePaymentInput): Promise<MandatePayment>;
|
|
529
|
+
/** GA operation name for reading one merchant payment. */
|
|
342
530
|
getMerchantPayment(paymentId: string): Promise<MandatePayment>;
|
|
531
|
+
/** @deprecated Use `exchangeUserLinkCode`. */
|
|
343
532
|
exchangeLinkCode(input: ExchangeLinkCodeInput): Promise<ExchangeLinkCodeResult>;
|
|
533
|
+
/** @deprecated Use `getPaymentReadiness`. */
|
|
344
534
|
getPaymentCapability(input: PaymentCapabilityInput): Promise<PaymentCapability>;
|
|
345
535
|
createCheckoutSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
|
|
346
536
|
getCheckoutSession(id: string): Promise<CheckoutSessionStatus>;
|
|
537
|
+
/** @deprecated Use `createAuthorizationSession`. */
|
|
347
538
|
createMandateAuthorizationSession(input: CreateMandateAuthorizationSessionInput): Promise<MandateAuthorizationSession>;
|
|
539
|
+
/** @deprecated Use `getAuthorizationSession`. */
|
|
348
540
|
getMandateAuthorizationSession(sessionId: string): Promise<MandateAuthorizationSession>;
|
|
541
|
+
/** @deprecated Use `getPaymentAuthorization`. */
|
|
349
542
|
getMerchantMandate(mandateId: string): Promise<MerchantMandate>;
|
|
350
543
|
listPaymentOptions(input: PaymentOptionsInput): Promise<MerchantPaymentOptions>;
|
|
544
|
+
/** @deprecated Use `createMerchantPayment`. */
|
|
351
545
|
createMandatePayment(input: CreateMandatePaymentInput): Promise<MandatePayment>;
|
|
546
|
+
/** @deprecated Use `getMerchantPayment`. */
|
|
352
547
|
getMandatePayment(paymentId: string): Promise<MandatePayment>;
|
|
548
|
+
/**
|
|
549
|
+
* Short-poll a mandate payment until it reaches a terminal status. `listener`
|
|
550
|
+
* is invoked with the payment on the first poll and on every status change;
|
|
551
|
+
* the returned promise resolves with the terminal payment (or the latest
|
|
552
|
+
* payment if `timeoutMs` elapses first). Polling backs off between requests
|
|
553
|
+
* and stops on terminal status, timeout, or abort.
|
|
554
|
+
*/
|
|
353
555
|
onStatus(paymentId: string, listener: MandatePaymentStatusListener, options?: OnMandatePaymentStatusOptions): Promise<MandatePayment>;
|
|
556
|
+
/** Revoke a user link the merchant no longer needs (GA-only). */
|
|
354
557
|
revokeUserLink(userLinkRef: string): Promise<void>;
|
|
558
|
+
/** List merchant payments (reconciliation source of truth). */
|
|
355
559
|
listMerchantPayments(filter?: MerchantPaymentListFilter): Promise<Page<MandatePayment>>;
|
|
560
|
+
/** List payment authorizations (mandates) for this app. */
|
|
356
561
|
listPaymentAuthorizations(filter?: PaymentAuthorizationListFilter): Promise<Page<MerchantMandate>>;
|
|
562
|
+
/** Create a refund against a succeeded payment (partial-capable). */
|
|
357
563
|
createRefund(input: CreateRefundInput): Promise<Refund>;
|
|
358
564
|
getRefund(refundId: string): Promise<Refund>;
|
|
359
565
|
listRefunds(filter?: RefundListFilter): Promise<Page<Refund>>;
|
|
566
|
+
/** Register a webhook endpoint. The signing secret is returned exactly once. */
|
|
360
567
|
createWebhookEndpoint(input: CreateWebhookEndpointInput): Promise<WebhookEndpointWithSecret>;
|
|
361
568
|
listWebhookEndpoints(): Promise<WebhookEndpoint[]>;
|
|
362
569
|
getWebhookEndpoint(webhookEndpointId: string): Promise<WebhookEndpoint>;
|
|
363
570
|
deleteWebhookEndpoint(webhookEndpointId: string): Promise<void>;
|
|
571
|
+
/** Rotate the signing secret; the previous secret verifies for 24h. */
|
|
364
572
|
rotateWebhookSecret(webhookEndpointId: string): Promise<WebhookEndpointWithSecret>;
|
|
573
|
+
/** Read the Dev capability/evidence projection. Dev environment only. */
|
|
365
574
|
getDevCapabilities(): Promise<DevCapabilities>;
|
|
575
|
+
/** Request test-only USDC for an app-owned synthetic linked user. Dev only. */
|
|
366
576
|
fundDevUser(input: FundDevUserInput): Promise<DevFaucetTransfer>;
|
|
577
|
+
/** Create a Dev simulation, distinct from a MerchantPayment. Dev only. */
|
|
367
578
|
simulateDevCharge(input: SimulateDevChargeInput): Promise<DevSimulation>;
|
|
579
|
+
/** Read an app-owned Dev simulation. Dev only. */
|
|
368
580
|
getDevSimulation(simulationId: string): Promise<DevSimulation>;
|
|
581
|
+
/** Queue a signed no-business-state `test.ping`. Dev environment only. */
|
|
369
582
|
sendWebhookTestDelivery(input: SendWebhookTestDeliveryInput): Promise<WebhookTestDeliveryAccepted>;
|
|
370
583
|
}
|
|
371
584
|
type FactoConnectServerErrorCode = 'FACTO_CONFIG_INVALID' | 'FACTO_ENGINE_REQUEST_FAILED' | 'FACTO_ENGINE_RESPONSE_INVALID' | 'FACTO_REQUEST_ABORTED' | 'FACTO_STATUS_POLL_ABORTED';
|
|
@@ -374,6 +587,7 @@ declare class FactoConnectServerError extends Error {
|
|
|
374
587
|
readonly retryable: boolean;
|
|
375
588
|
readonly status?: number;
|
|
376
589
|
readonly details?: unknown;
|
|
590
|
+
/** Seconds from the `Retry-After` response header on a 429, when present. */
|
|
377
591
|
readonly retryAfterSeconds?: number;
|
|
378
592
|
constructor(code: FactoConnectServerErrorCode, message: string, options: {
|
|
379
593
|
retryable: boolean;
|
|
@@ -382,25 +596,74 @@ declare class FactoConnectServerError extends Error {
|
|
|
382
596
|
retryAfterSeconds?: number;
|
|
383
597
|
});
|
|
384
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Options for {@link withServerRetry} and the server client's safe automatic
|
|
601
|
+
* retry policy. GET calls and idempotency-keyed POST calls use these defaults.
|
|
602
|
+
*/
|
|
385
603
|
interface ServerRetryOptions {
|
|
604
|
+
/** Max retry attempts after the first try (default 2). */
|
|
386
605
|
maxRetries?: number;
|
|
606
|
+
/** Base backoff in ms for the exponential fallback (default 200). */
|
|
387
607
|
baseDelayMs?: number;
|
|
608
|
+
/** Backoff cap in ms (default 5000). */
|
|
388
609
|
maxDelayMs?: number;
|
|
610
|
+
/** Honor the server's `Retry-After` when present (default true). */
|
|
389
611
|
respectRetryAfter?: boolean;
|
|
612
|
+
/** Abort waiting/retrying. */
|
|
390
613
|
signal?: AbortSignal;
|
|
614
|
+
/** Invoked before each retry sleep. */
|
|
391
615
|
onRetry?: (info: {
|
|
392
616
|
attempt: number;
|
|
393
617
|
error: FactoConnectServerError;
|
|
394
618
|
delayMs: number;
|
|
395
619
|
}) => void;
|
|
620
|
+
/** Injectable delay (tests). Defaults to a `setTimeout` sleep that respects `signal`. */
|
|
396
621
|
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
397
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Opt-in retry wrapper for any server-client call. Retries a
|
|
625
|
+
* {@link FactoConnectServerError} whose `retryable` is true (429 / 5xx),
|
|
626
|
+
* honoring `Retry-After` when the server sent it, otherwise exponential backoff
|
|
627
|
+
* with jitter. Non-retryable errors and non-Facto errors are rethrown
|
|
628
|
+
* immediately. The server client applies the same policy only to GET calls and
|
|
629
|
+
* POST calls carrying `Idempotency-Key`; this standalone wrapper remains useful
|
|
630
|
+
* for callers composing their own safe operation:
|
|
631
|
+
*
|
|
632
|
+
* ```ts
|
|
633
|
+
* const payment = await withServerRetry(() => facto.createMandatePayment(input))
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
398
636
|
declare function withServerRetry<T>(fn: () => Promise<T>, options?: ServerRetryOptions): Promise<T>;
|
|
399
637
|
declare function buildHostedConnectUrl(input: HostedConnectUrlInput): string;
|
|
400
638
|
declare function createFactoConnectServer(options: FactoConnectServerOptions): FactoConnectServerClient;
|
|
639
|
+
/** Whether a mandate payment status is terminal (no further transitions). */
|
|
401
640
|
declare function isTerminalMandatePaymentStatus(status: MandatePaymentStatus): boolean;
|
|
641
|
+
/**
|
|
642
|
+
* Sign a raw Facto webhook payload using the same `t/v1` format accepted by
|
|
643
|
+
* {@link verifyWebhookSignature}. This helper is server-only and intended for
|
|
644
|
+
* deterministic fixtures and partner webhook tests.
|
|
645
|
+
*/
|
|
402
646
|
declare function signWebhookPayload(rawBody: string | Uint8Array, secret: string, timestamp?: number): string;
|
|
647
|
+
/**
|
|
648
|
+
* Verify a Facto webhook `Facto-Signature` header against the raw request body
|
|
649
|
+
* (spec 012 webhook contract). Recompute `HMAC-SHA256(secret, "{t}.{raw_body}")`
|
|
650
|
+
* over the EXACT raw bytes, compare in constant time, and reject stale
|
|
651
|
+
* timestamps. Verify BEFORE parsing JSON. During a secret rotation the header
|
|
652
|
+
* may carry two `v1` entries; verification passes if any matches.
|
|
653
|
+
*
|
|
654
|
+
* An empty `secret` is a configuration fault, not a failed verification: Node
|
|
655
|
+
* accepts a zero-length HMAC key, so verifying against `''` would make every
|
|
656
|
+
* forged webhook verify. It throws, matching {@link signWebhookPayload}, rather
|
|
657
|
+
* than returning `false` — a silent `false` reads as "bad signature" and sends
|
|
658
|
+
* the operator hunting the sender instead of their own env.
|
|
659
|
+
*
|
|
660
|
+
* @param rawBody the exact request body bytes (string or Buffer)
|
|
661
|
+
* @param header the `Facto-Signature` header value (`t=..,v1=..[,v1=..]`)
|
|
662
|
+
* @param secret the endpoint signing secret; must be non-empty
|
|
663
|
+
* @param toleranceSeconds max clock skew (default 300s)
|
|
664
|
+
*/
|
|
403
665
|
declare function verifyWebhookSignature(rawBody: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): boolean;
|
|
666
|
+
/** A public Ed25519 JWK (OKP) as served by the Facto connect-hint JWKS. */
|
|
404
667
|
interface FactoCardProgramConnectJwk {
|
|
405
668
|
kty: string;
|
|
406
669
|
crv: string;
|
|
@@ -409,22 +672,44 @@ interface FactoCardProgramConnectJwk {
|
|
|
409
672
|
alg?: string;
|
|
410
673
|
use?: string;
|
|
411
674
|
}
|
|
675
|
+
/**
|
|
676
|
+
* The Facto connect-hint JWK set, served (public, no auth) at
|
|
677
|
+
* `GET /.well-known/facto-card-program-connect/jwks.json`.
|
|
678
|
+
*/
|
|
412
679
|
interface FactoCardProgramConnectJwks {
|
|
413
680
|
keys: FactoCardProgramConnectJwk[];
|
|
414
681
|
}
|
|
682
|
+
/**
|
|
683
|
+
* How the caller supplies the Facto JWKS: an in-memory `{ keys }` set, a JWKS URL
|
|
684
|
+
* string to fetch (public GET, no auth), or a resolver that returns the set.
|
|
685
|
+
*/
|
|
415
686
|
type FactoCardProgramConnectJwksInput = FactoCardProgramConnectJwks | string | (() => FactoCardProgramConnectJwks | Promise<FactoCardProgramConnectJwks>);
|
|
416
687
|
interface VerifyFactoCardProgramConnectHintInput {
|
|
688
|
+
/** The compact EdDSA JWS the Facto user handed the partner. */
|
|
417
689
|
connectHint: string;
|
|
690
|
+
/** The Facto JWKS: an in-memory `{ keys }` set, a JWKS URL to fetch, or a resolver. */
|
|
418
691
|
jwks: FactoCardProgramConnectJwksInput;
|
|
692
|
+
/**
|
|
693
|
+
* The partner's own connection audience — its environment-unique program code.
|
|
694
|
+
* The hint's `aud` MUST equal this; a mismatch is rejected. Required, because a
|
|
695
|
+
* hint is only meaningful for the program it was scoped to.
|
|
696
|
+
*/
|
|
419
697
|
audience: string;
|
|
698
|
+
/** Expected issuer. Defaults to `'facto'`. */
|
|
420
699
|
issuer?: string;
|
|
700
|
+
/** Verification clock (unix milliseconds or `Date`). Defaults to `Date.now()`. */
|
|
421
701
|
now?: number | Date;
|
|
702
|
+
/** Clock-skew tolerance in seconds applied to the expiry check. Defaults to `0`. */
|
|
422
703
|
clockToleranceSeconds?: number;
|
|
423
704
|
}
|
|
424
705
|
interface FactoCardProgramConnectHint {
|
|
706
|
+
/** The opaque program the hint is scoped to (`cprog_...`). */
|
|
425
707
|
programRef: string;
|
|
708
|
+
/** Pairwise-opaque subject (`facto-user:<hex>`); NEVER the raw Facto user id. */
|
|
426
709
|
pairwiseSubject: string;
|
|
710
|
+
/** Single-use nonce; the caller MUST enforce single-use against its own store. */
|
|
427
711
|
nonce: string;
|
|
712
|
+
/** Absolute expiry (`exp`) as an RFC 3339 / ISO-8601 timestamp. */
|
|
428
713
|
expiresAt: string;
|
|
429
714
|
}
|
|
430
715
|
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 +720,15 @@ declare class FactoConnectHintError extends Error {
|
|
|
435
720
|
details?: unknown;
|
|
436
721
|
});
|
|
437
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* Verify a Facto-initiated card-program connect-hint (Feature 020 slice C2).
|
|
725
|
+
*
|
|
726
|
+
* Validates the Ed25519 signature against the Facto JWKS, enforces `iss` / `aud`
|
|
727
|
+
* / `exp`, and returns the safe claims. The returned `pairwiseSubject` is the
|
|
728
|
+
* pairwise-opaque HMAC subject (never the raw Facto user id) the partner binds to
|
|
729
|
+
* its own cardholder; the returned `nonce` MUST be enforced single-use by the
|
|
730
|
+
* caller against its own store.
|
|
731
|
+
*/
|
|
438
732
|
declare function verifyFactoCardProgramConnectHint(input: VerifyFactoCardProgramConnectHintInput): Promise<FactoCardProgramConnectHint>;
|
|
439
733
|
|
|
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,
|
|
734
|
+
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, PSP_CAPABILITY_TEMPLATES, PSP_CREDENTIAL_KEYSPACE, PSP_CREDENTIAL_SCOPES, PSP_PARTNER_ROLE_TYPE, type Page, type PaymentAuthorizationListFilter, type PaymentCapability, type PaymentCapabilityInput, type PaymentOptionsInput, type PspCapabilityTemplate, 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, carriesMoneyVerb, createFactoConnectServer, createFactoConnectServer as default, factoConnectEnvironmentFromClientId, isTerminalMandatePaymentStatus, signWebhookPayload, subMerchantOf, verifyFactoCardProgramConnectHint, verifyWebhookSignature, withServerRetry, withSubMerchant };
|