@facto-to/connect 0.0.1-beta.1 → 0.0.1-beta.14
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 +140 -81
- package/dist/browser/index.cjs +29 -20
- package/dist/browser/index.d.cts +1 -31
- package/dist/browser/index.d.ts +1 -31
- package/dist/browser/index.js +28 -19
- package/dist/card-transport--tl4vJa5.d.cts +73 -0
- package/dist/card-transport--tl4vJa5.d.ts +73 -0
- package/dist/chunk-GJFQH2I6.js +2 -0
- package/dist/chunk-VQJMKCAN.js +1 -0
- package/dist/cli/index.cjs +6 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +5 -0
- package/dist/index.d-oRLzr8gp.d.cts +1124 -0
- package/dist/index.d-oRLzr8gp.d.ts +1124 -0
- package/dist/react/index.cjs +0 -1
- package/dist/react/index.js +0 -1
- package/dist/server/card-connect-admin-client.cjs +2 -0
- package/dist/server/card-connect-admin-client.d.cts +318 -0
- package/dist/server/card-connect-admin-client.d.ts +318 -0
- package/dist/server/card-connect-admin-client.js +1 -0
- package/dist/server/index.cjs +1 -2
- package/dist/server/index.d.cts +1202 -291
- package/dist/server/index.d.ts +1202 -291
- package/dist/server/index.js +1 -2
- package/dist/testing/index.cjs +1 -2
- package/dist/testing/index.d.cts +6 -14
- package/dist/testing/index.d.ts +6 -14
- package/dist/testing/index.js +1 -2
- package/package.json +64 -17
- package/dist/browser/index.cjs.map +0 -1
- package/dist/browser/index.js.map +0 -1
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.js.map +0 -1
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,25 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Facto Connect SDK lets partners bind their users to Facto accounts and payment routes.
|
|
4
4
|
|
|
5
|
+
Card Issuer Providers (CIP) and Stablecoin Card Providers (SCP) receive the separate `@facto-to/card-connect` package, which contains only the Card Connect surface described below, together with its own integration guide.
|
|
6
|
+
|
|
5
7
|
> **Entrypoint status:** the root (browser), `/server`, and `/testing` entrypoints are
|
|
6
8
|
> functional. **`@facto-to/connect/react` is a reserved scaffold — not yet functional**: its
|
|
7
9
|
> only export throws when called. Do not integrate against `/react` yet.
|
|
8
10
|
|
|
9
11
|
## Install
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
operator gate), so `npm install @facto-to/connect` fails with a 404 today. Install
|
|
13
|
-
the vendored tarball Facto ships with your credentials — it is self-contained
|
|
14
|
-
(its `@facto-to/*` runtime dependencies are bundled into `dist/`), so the one file
|
|
15
|
-
is the whole install:
|
|
13
|
+
Install the restricted tarball delivered by Facto. Create an empty directory, copy the supplied `.tgz` and `SHA256SUMS` into it, then run:
|
|
16
14
|
|
|
17
15
|
```sh
|
|
18
|
-
|
|
16
|
+
sha256sum -c SHA256SUMS
|
|
17
|
+
npm init -y
|
|
18
|
+
npm install ./*.tgz
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
installing. Once npm publication opens, `npm install @facto-to/connect` becomes
|
|
23
|
-
the supported path.
|
|
21
|
+
Use `COVER.md` for version and contact information, and `SHA256SUMS` for checksum verification. The tarball includes its runtime dependencies. Its ESM and CommonJS type declarations are included.
|
|
24
22
|
|
|
25
23
|
## Browser
|
|
26
24
|
|
|
@@ -56,6 +54,16 @@ fields `factoUserId`, `factoServerWalletAddress`, and `cardRef` are stripped
|
|
|
56
54
|
before the promise resolves and never reach browser code. Read them on your own
|
|
57
55
|
backend from `@facto-to/connect/server` if a migration still needs them.
|
|
58
56
|
|
|
57
|
+
## Card Connect
|
|
58
|
+
|
|
59
|
+
The server entrypoint provides a scoped Card Connect client, request signing, authorization status polling, delivery verification, event decoding and inbox helpers. The testing entrypoint contains local synthetic fixtures and a non-durable reference store. The `facto-connect` command runs the loopback simulator and integration vectors.
|
|
60
|
+
|
|
61
|
+
Read the separately supplied `docs/README.md` for authentication, idempotency, authorizations, deliveries and reconciliation. Never place machine credentials in browser code. An asynchronous authorization acceptance is not final settlement. Synchronous approval is closed in all environments; an expired synchronous deadline can return a typed 408.
|
|
62
|
+
|
|
63
|
+
Verify delivery signatures over the original bytes before decoding. The inbox delivers events to your handler at least once in arrival order, suppresses duplicates after acknowledgement, and does not guarantee ordering or completeness. Persist business effects and inbox confirmation atomically when effectively-once handling is required. The local simulator and test credentials are synthetic and do not establish production eligibility.
|
|
64
|
+
|
|
65
|
+
For Card Connect errors, distinguish flat and nested Engine envelopes and preserve the original status and reason. See `docs/errors.md` in the delivery for tested recovery guidance.
|
|
66
|
+
|
|
59
67
|
## Server
|
|
60
68
|
|
|
61
69
|
Use the server entrypoint through a subpath export:
|
|
@@ -67,12 +75,13 @@ const facto = createFactoConnectServer({
|
|
|
67
75
|
appId: process.env.FACTO_APP_ID!,
|
|
68
76
|
clientId: process.env.FACTO_CLIENT_ID!,
|
|
69
77
|
clientSecret: process.env.FACTO_CLIENT_SECRET!,
|
|
70
|
-
environment: 'sandbox',
|
|
71
78
|
})
|
|
72
79
|
|
|
73
80
|
const linked = await facto.exchangeUserLinkCode({ code, state, nonce })
|
|
74
81
|
```
|
|
75
82
|
|
|
83
|
+
Credentials are scoped to an environment. Confirm the environment and endpoints with Facto before sending requests.
|
|
84
|
+
|
|
76
85
|
The server entrypoint wraps:
|
|
77
86
|
|
|
78
87
|
- `POST /api/merchant/user-links/exchange`
|
|
@@ -86,85 +95,52 @@ The public GA operation names mirror the OpenAPI contract:
|
|
|
86
95
|
`getAuthorizationSession`, `getPaymentAuthorization`, `createMerchantPayment`, and
|
|
87
96
|
`getMerchantPayment`. The pre-GA names remain as deprecated source-compatible aliases.
|
|
88
97
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`staging` and the former `custom` selector are retired. Local, private, and staging
|
|
105
|
-
deployments keep any `environment` value and pass explicit `apiBaseUrl` and
|
|
106
|
-
`hostedConnectUrl` overrides, which take precedence over the published endpoint tables:
|
|
98
|
+
### Hosted Connect URLs
|
|
99
|
+
|
|
100
|
+
`buildHostedConnectUrl` and `facto.createHostedConnectUrl` take a required
|
|
101
|
+
`merchantOrigin`: the origin of the browsing context that will open the
|
|
102
|
+
returned URL. **Breaking change** — this used to be implicit, resolved by the
|
|
103
|
+
Hosted Connect page from `document.referrer` alone, which `rel="noreferrer"`
|
|
104
|
+
links, a `Referrer-Policy: no-referrer` deployment, or a privacy-mode browser
|
|
105
|
+
all erase silently. The parameter is required so a
|
|
106
|
+
missing value fails your build instead of a shopper's session.
|
|
107
|
+
|
|
108
|
+
Pass the origin of *this specific request's* browsing context — never a
|
|
109
|
+
single static value pinned in server config, since one server can serve
|
|
110
|
+
several merchant origins (custom domains, preview deployments, staging
|
|
111
|
+
mirrors) that would otherwise all get stamped with whichever origin happened
|
|
112
|
+
to be configured last:
|
|
107
113
|
|
|
108
114
|
```ts
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
// Express-style handler: derive merchantOrigin from the request that is
|
|
116
|
+
// actually asking, not from an environment variable.
|
|
117
|
+
app.get('/facto/connect-url', (req, res) => {
|
|
118
|
+
const merchantOrigin = req.get('origin') ?? new URL(req.get('referer')!).origin
|
|
119
|
+
const url = facto.createHostedConnectUrl({ state, nonce, merchantOrigin })
|
|
120
|
+
res.json({ url })
|
|
114
121
|
})
|
|
115
122
|
```
|
|
116
123
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
`merchantOrigin` must be a bare `http(s)` origin — no path, query, fragment,
|
|
125
|
+
or credentials — and is written verbatim into the URL's `external_origin`
|
|
126
|
+
parameter. A value that fails that shape throws
|
|
127
|
+
`merchantOrigin must be an absolute http(s) origin`; omitting it throws
|
|
128
|
+
`merchantOrigin is required and has no implicit default`. Both are
|
|
129
|
+
`FactoConnectServerError` with code `FACTO_CONFIG_INVALID`.
|
|
122
130
|
|
|
123
|
-
|
|
131
|
+
This is the hosted (server-built) URL only. The browser popup leg
|
|
132
|
+
(`createFactoConnect`/`FactoConnectTransportOptions.origin`) already sets its
|
|
133
|
+
own `external_origin` from `window.location.origin` (or an explicit `origin`
|
|
134
|
+
override) and is unchanged by this release.
|
|
124
135
|
|
|
125
|
-
|
|
126
|
-
generated from a byte-pinned snapshot of the Facto Engine OpenAPI document, so
|
|
127
|
-
the SDK carries no second description of the wire:
|
|
136
|
+
### Environment
|
|
128
137
|
|
|
129
|
-
|
|
130
|
-
| --- | --- |
|
|
131
|
-
| Wire snapshot | `specs/openapi/engine/openapi.gen.json` |
|
|
132
|
-
| Provenance (engine commits, byte count, sha256) | `specs/openapi/engine/provenance.json` |
|
|
133
|
-
| Generated declarations | `typescript/packages/connect/src/server/generated/engine-wire.ts` |
|
|
138
|
+
`environment` is optional and accepts `sandbox`, `dev`, or `production`. `sandbox` and `dev` select the same development environment. When omitted, the SDK derives the environment from the issued client ID or an explicitly configured recognized endpoint; it does not silently default to production. Contradictory or unrecognized configurations fail before a credential-bearing request.
|
|
134
139
|
|
|
135
|
-
|
|
136
|
-
# Re-read the snapshot from a local engine checkout at the recorded pin.
|
|
137
|
-
FACTO_ENGINE_DIR=../facto-engine npm run wire:sync
|
|
140
|
+
Use `factoConnectEnvironmentFromClientId(clientId)` to inspect the derived environment. Explicit `apiBaseUrl` and `hostedConnectUrl` overrides support local or private deployments. Facto supplies the applicable environment endpoints during onboarding.
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
FACTO_ENGINE_DIR=../facto-engine npm run wire:sync -- \
|
|
141
|
-
--commit=<integration-sha> --source-commit=<source-sha>
|
|
142
|
+
**Real-funds warning:** Development or sandbox environments may use mainnet chains and real funds. Confirm the environment's scope and funding rules with Facto before any payment, refund or faucet operation. The offline fixture transport and local simulator use synthetic data and do not move funds.
|
|
142
143
|
|
|
143
|
-
# Regenerate the declarations from the snapshot.
|
|
144
|
-
npm run wire:generate
|
|
145
|
-
|
|
146
|
-
# Gates. Both run in `npm run check`.
|
|
147
|
-
npm run wire:check # WIRE_DIGEST_MISMATCH
|
|
148
|
-
npm run wire:check-generated # WIRE_GENERATION_DRIFT
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
The snapshot is only ever read with `git show <pinned-sha>:<path>` from a local
|
|
152
|
-
checkout — never fetched over the network, and never resolved from a floating
|
|
153
|
-
branch such as `dev`. `wire:check` asserts the snapshot bytes, the recorded byte
|
|
154
|
-
count and sha256, and the pinned engine SHAs all agree, and additionally
|
|
155
|
-
reproduces the digest straight from the engine commit when `FACTO_ENGINE_DIR` is
|
|
156
|
-
set. `wire:check-generated` fails if the generated declarations are edited by
|
|
157
|
-
hand.
|
|
158
|
-
|
|
159
|
-
Two contract details are load-bearing and asserted at compile time in
|
|
160
|
-
`src/server/wire-type-assertions.ts`:
|
|
161
|
-
|
|
162
|
-
- `factoUserId`, `factoServerWalletAddress`, and `cardRef` are optional **and**
|
|
163
|
-
nullable on the wire. `null` is a legal server-client value and is preserved,
|
|
164
|
-
not collapsed into `undefined`.
|
|
165
|
-
- The payment-readiness target is shared properties with a sibling, *inclusive*
|
|
166
|
-
`anyOf`. Legacy-only, `userLinkRef`-only, and mixed targets are all valid; only
|
|
167
|
-
an empty or wrong-typed target is rejected. It is not an exclusive union.
|
|
168
144
|
|
|
169
145
|
### Dev helpers
|
|
170
146
|
|
|
@@ -188,11 +164,95 @@ if (capabilities.capabilities.some((item) => item.name === 'faucet' && item.stat
|
|
|
188
164
|
```
|
|
189
165
|
|
|
190
166
|
The server client automatically retries retryable GET calls and POST calls that carry
|
|
191
|
-
an `Idempotency-Key`, honoring `Retry-After
|
|
167
|
+
an `Idempotency-Key`, honoring `Retry-After` up to `retry.maxRetryAfterMs` (default
|
|
168
|
+
60 seconds); a longer requested wait ends retrying and rethrows the error with the
|
|
169
|
+
server's `retryAfterSeconds`. It never retries other POST calls. Set
|
|
192
170
|
`timeoutMs` and/or `signal` to bound a request. These helpers expose contract surfaces
|
|
193
171
|
and fixtures; callers must read the capability response rather than assuming a dev
|
|
194
172
|
endpoint, faucet, simulation, or money loop is deployed or verified.
|
|
195
173
|
|
|
174
|
+
### Enterprise Funds
|
|
175
|
+
|
|
176
|
+
`createEnterpriseFundsServerClient` (also exported as
|
|
177
|
+
`createEnterpriseFundsClient`) is the server-only Enterprise Funds surface. It
|
|
178
|
+
requires a durable atomic CAS journal store, an `ownerScope`, and a monotonic
|
|
179
|
+
caller-context provider; it has no in-memory fallback and never inherits the
|
|
180
|
+
generic POST retry policy.
|
|
181
|
+
|
|
182
|
+
The only public Merchant S2S POST commands are:
|
|
183
|
+
|
|
184
|
+
- `create_or_transition_source_hold` → `/holds`
|
|
185
|
+
- `record_prefund_or_partner_fact` → `/partner-facts`
|
|
186
|
+
- `settle_commercial_reduction` → `/commercial-reductions`
|
|
187
|
+
|
|
188
|
+
The Engine creates `bind_or_transition_guarantee`, `apply_qualified_cash`, and
|
|
189
|
+
`dispatch_or_observe_execution_family` itself from chain observation or
|
|
190
|
+
Partner-confirmed capture. They remain part of the canonical protocol (closure
|
|
191
|
+
targets, recovery, audience projections), but there is no public merchant POST
|
|
192
|
+
route for them. The canonical request types
|
|
193
|
+
(`BindOrTransitionGuaranteeRequest`, `ApplyQualifiedCashRequest`,
|
|
194
|
+
`DispatchOrObserveExecutionFamilyRequest`) remain exported because
|
|
195
|
+
`EnterpriseWireCommandRequest` and recovery/closure decoding use that exact
|
|
196
|
+
protocol shape; no sender is exposed, and
|
|
197
|
+
`canonicalizeAndMapEnterpriseCommand` rejects those three kinds with
|
|
198
|
+
`EnterpriseWireValidationError` before any journal write or request attempt.
|
|
199
|
+
Recover an original through
|
|
200
|
+
`GET /api/merchant/enterprise-funds/purchases/{purchaseRef}/intents/{economicIntentRef}/commands/{commandRef}`
|
|
201
|
+
with `X-Original-Command-Digest`; a 202 response means the journal must be kept.
|
|
202
|
+
|
|
203
|
+
`ENTERPRISE_MERCHANT_COMMAND_ROUTE_TEMPLATES` contains exactly the three public
|
|
204
|
+
templates, and `ENTERPRISE_SERVER_DERIVED_COMMAND_KINDS` names the three
|
|
205
|
+
engine-created kinds.
|
|
206
|
+
|
|
207
|
+
#### Audience read contract
|
|
208
|
+
|
|
209
|
+
`ENTERPRISE_AUDIENCE_READ_ROUTE_TEMPLATES` and `buildAudienceReadPath` define the
|
|
210
|
+
six mounted audience GETs (Partner Workspace order/operation, Consumer
|
|
211
|
+
order/operation, Console purchase/command). The strict parsers and
|
|
212
|
+
`read*Result` helpers validate 200 closed, 202 unknown, 401/403 auth revocation,
|
|
213
|
+
400 `invalid_reference` (malformed/unknown reference; do not rotate the journal),
|
|
214
|
+
and 503 `unavailable` (body `audience_projection_unavailable`,
|
|
215
|
+
`preservePendingCommandJournal: true`; keep the journal and retry the read later).
|
|
216
|
+
They preserve `TrackedDecimalAmount` and progress `unknown` states instead of
|
|
217
|
+
coercing them to `0`; a malformed 503 auth/unavailable body is reported as
|
|
218
|
+
`malformedBody: true`, never as a closed success.
|
|
219
|
+
|
|
220
|
+
This module is deliberately transport- and authentication-free: the Partner
|
|
221
|
+
client keeps its signed Partner session/context, the Consumer client keeps its
|
|
222
|
+
`__Host-facto-consumer` cookie handle, and the Console client keeps its admin
|
|
223
|
+
bearer and target header. The SDK validates their responses; it does not mint or
|
|
224
|
+
hold those credentials.
|
|
225
|
+
|
|
226
|
+
The preparation bridge (`createEnterprisePurchaseServerClient`) calls only
|
|
227
|
+
`POST /api/merchant/enterprise-funds/preparations` and its
|
|
228
|
+
`by-reference/{merchantPaymentRef}` read. `preparePurchaseOnce` is one HTTP
|
|
229
|
+
attempt, not a durable first-send permit; recover an existing purchase with
|
|
230
|
+
`getPreparation(originalRequest)`.
|
|
231
|
+
|
|
232
|
+
The merchant command paths above are the public routes supported by this client.
|
|
233
|
+
|
|
234
|
+
## Link-code mint refusal errors
|
|
235
|
+
|
|
236
|
+
The two refusals below originate on the engine's link-code minting surface and
|
|
237
|
+
need different recovery actions. Their uppercase tokens are prefixes of the
|
|
238
|
+
engine's `error.message`, not SDK error codes. The identity refusal requires a
|
|
239
|
+
forced link reference, as used by the sandbox persona flow; the ordinary Hosted
|
|
240
|
+
Connect flow does not supply that reference.
|
|
241
|
+
|
|
242
|
+
| Message prefix | Engine `error.code` | HTTP | Meaning and recovery |
|
|
243
|
+
| --- | --- | --- | --- |
|
|
244
|
+
| `FACTO_LINK_IDENTITY_MISMATCH` | `conflict` | 409 | The forced link reference on a mint request differs from this user's active grant for the app. Unlink the existing association before reclaiming it. |
|
|
245
|
+
| `FACTO_LINK_MISMATCH` | `permission_denied` | 403 | The mint request's origin is not registered for the app. Register the intended origin; changing the shopper's identity does not fix this refusal. |
|
|
246
|
+
|
|
247
|
+
For non-success HTTP responses, `FactoConnectServerError.code` remains
|
|
248
|
+
`FACTO_ENGINE_REQUEST_FAILED`. Its `status` preserves the HTTP status and its
|
|
249
|
+
`details` preserves the engine error envelope, including `error.code` and
|
|
250
|
+
`error.message`. Both refusals are non-retryable: distinguish their status and
|
|
251
|
+
message prefix instead of treating every link refusal as an origin mismatch.
|
|
252
|
+
The SDK preserves these fields if a server returns such an envelope. This is
|
|
253
|
+
not a claim that the merchant link-code exchange endpoint produces either
|
|
254
|
+
minting refusal, or that the SDK exposes the minting surface.
|
|
255
|
+
|
|
196
256
|
## Offline Fixtures
|
|
197
257
|
|
|
198
258
|
The testing entrypoint provides an in-memory transport that never performs network I/O:
|
|
@@ -250,8 +310,7 @@ import createFactoConnectServer from '@facto-to/connect/server'
|
|
|
250
310
|
import { createFactoTestTransport } from '@facto-to/connect/testing'
|
|
251
311
|
```
|
|
252
312
|
|
|
253
|
-
`@facto-to/connect/react` is a reserved scaffold entrypoint
|
|
254
|
-
React components; the entrypoint's only export throws when called.
|
|
313
|
+
`@facto-to/connect/react` is a reserved scaffold entrypoint; its only export throws when called.
|
|
255
314
|
|
|
256
315
|
## Security Model
|
|
257
316
|
|