@facto-to/card 0.0.0-stage → 0.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +63 -2
- package/dist/card-inbox-DzsHFRPT.d.cts +312 -0
- package/dist/card-inbox-DzsHFRPT.d.ts +312 -0
- package/dist/chunk-52SWPAJL.js +2 -0
- package/dist/cli/index.js +6 -0
- package/dist/docs/README.md +9 -0
- package/dist/docs/authentication.md +96 -0
- package/dist/docs/authorizations.md +182 -0
- package/dist/docs/concepts.md +35 -0
- package/dist/docs/deliveries.md +170 -0
- package/dist/docs/errors.md +100 -0
- package/dist/docs/getting-access.md +56 -0
- package/dist/docs/idempotency.md +78 -0
- package/dist/docs/integration-checklist.md +15 -0
- package/dist/docs/integration.zh.md +59 -0
- package/dist/docs/interlace-adapter-v1.md +87 -0
- package/dist/docs/interlace-adapter-v1.zh.md +87 -0
- package/dist/docs/not-yet-available.md +13 -0
- package/dist/docs/quickstart.md +126 -0
- package/dist/docs/reconciliation.md +86 -0
- package/dist/docs/reference/api.md +1728 -0
- package/dist/docs/reference/events.md +639 -0
- package/dist/docs/reference/schemas.json +5000 -0
- package/dist/docs/reference/schemas.md +865 -0
- package/dist/docs/simulator.md +235 -0
- package/dist/docs/versioning.md +9 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +840 -0
- package/dist/index.d.ts +840 -0
- package/dist/index.js +2 -0
- package/dist/source/build.mjs +5 -0
- package/dist/source/package.json +16 -0
- package/dist/source/src/connect/cli/deliveries.ts +48 -0
- package/dist/source/src/connect/cli/index.ts +57 -0
- package/dist/source/src/connect/server/card-client.ts +834 -0
- package/dist/source/src/connect/server/card-delivery.ts +301 -0
- package/dist/source/src/connect/server/card-events.ts +473 -0
- package/dist/source/src/connect/server/card-idempotency.ts +27 -0
- package/dist/source/src/connect/server/card-inbox.ts +82 -0
- package/dist/source/src/connect/server/card-intent-token.ts +588 -0
- package/dist/source/src/connect/server/card-polling.ts +69 -0
- package/dist/source/src/connect/server/card-signing.ts +115 -0
- package/dist/source/src/connect/server/card-transport.ts +282 -0
- package/dist/source/src/connect/server/errors.ts +280 -0
- package/dist/source/src/connect/server/fixtures/engine/card-events.synthetic.ts +84 -0
- package/dist/source/src/connect/server/retry-after.ts +12 -0
- package/dist/source/src/connect/testing/card-inbox.ts +124 -0
- package/dist/source/src/connect/testing/card-scenarios.ts +243 -0
- package/dist/source/src/connect/testing/card-simulator-vectors.ts +262 -0
- package/dist/source/src/connect/testing/card-simulator.ts +531 -0
- package/dist/source/src/connect/testing/interlace-card-transactions.ts +704 -0
- package/dist/source/src/connect/testing/pure-sha256.ts +123 -0
- package/dist/source/src/connect/wire.d.ts +472 -0
- package/dist/source/src/index.ts +135 -0
- package/dist/source/src/testing-browser.ts +24 -0
- package/dist/source/src/testing.ts +26 -0
- package/dist/source/tsconfig.json +20 -0
- package/dist/testing-browser.d.ts +220 -0
- package/dist/testing-browser.js +5 -0
- package/dist/testing.cjs +6 -0
- package/dist/testing.d.cts +199 -0
- package/dist/testing.d.ts +199 -0
- package/dist/testing.js +5 -0
- package/package.json +60 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.1-beta.1
|
|
4
|
+
|
|
5
|
+
- Initial beta of `@facto-to/card` for Stablecoin Card Providers (SCP) and Card Issuer Providers (CIP) over the hierarchical `/api/card/*` surface.
|
|
6
|
+
- Provide `createCardClient` with single-level resource namespaces (`intents`, `bindings`, `authorizations`, `events`, `deliveries`, `deliveryReplays`, `deadLetters`), explicit `CardApiKeySecret` encoding (`{ encoding: 'hex' | 'utf8', value }` or `Uint8Array`), `signCardRequest`, `verifyCardIntentToken` / `CARD_INTENT_JWKS_PATH`, unified `CardError` with `.outcome` classification (plus deprecated `FactoConnectServerError` alias), purified Envelope v2 `verifyEventDelivery` / `createDeliveryVerifier` / `getBusinessPayloadDigest` / `decodeDeliveryEvent` (`CARD_EVENT_KINDS`, `CARD_REDELIVERY_REASONS`), `receiveEventDelivery`, `pollAuthorization`, `deriveAuthorizationIdempotencyKey`, and the `facto-card` local simulator CLI.
|
|
7
|
+
- Ship a zero-Node-dependency `"browser"` export condition for `@facto-to/card/testing` alongside stateless Interlace `CARD_TRANSACTION` fixtures, deterministic mapper, replay helper, and in-memory sandbox runtime.
|
|
8
|
+
- Pass a Facto-issued `hmac_secret` as `{ encoding: 'utf8', value }`: Engine verifies the UTF-8 bytes of the stored secret string. `hex` is only for keys provisioned out-of-band as hex-encoded raw bytes.
|
|
9
|
+
- `withServerRetry` retries only `CardError`, and `ServerRetryOptions.onRetry` receives the thrown `CardError` (with `.outcome`). `verifyCardIntentToken` accepts `environment: CardEnvironment` (`'dev' | 'production'`) and keeps throwing `FactoIntentTokenError` for local token verification failures.
|
|
10
|
+
- The Interlace mapper and replay helper throw instead of creating a new authorization when a record links to a parent or claims a successor type without the evidence that mapping needs.
|
|
11
|
+
- Document the `getBusinessPayloadDigest` canonicalization with a test vector, and that `409 idempotency_payload_mismatch` always requires `POST /api/card/authorizations/lookup` before allocating a new `external_authorization_id`.
|
|
12
|
+
- Include editable TypeScript source under `dist/source` and bilingual integration guides and JSON schema bundle (`dist/docs/reference/schemas.json`) under `dist/docs`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @facto-to/card
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-only Facto Card SDK for Stablecoin Card Providers (SCP) and Card Issuer Providers (CIP). It contains the signed Card client, request signing, authorization lookup polling, event delivery verification, Envelope v2 event decoding, an inbox helper, local test helpers, and a loopback simulator. It has no runtime dependencies and runs on Node.js 20.9 or later.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install the published beta from npm:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-exact @facto-to/card@0.0.1-beta.1
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Entrypoints
|
|
14
|
+
|
|
15
|
+
| Import | Contents |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `@facto-to/card` | `createCardClient`, `signCardRequest`, `verifyCardIntentToken`, `CARD_INTENT_JWKS_PATH`, `verifyEventDelivery`, `createDeliveryVerifier`, `getBusinessPayloadDigest`, `decodeDeliveryEvent`, `CARD_EVENT_KINDS`, `CARD_REDELIVERY_REASONS`, `receiveEventDelivery`, `pollAuthorization`, `deriveAuthorizationIdempotencyKey`, `CardError` (and deprecated alias `FactoConnectServerError`), `withServerRetry`, `isCardErrorEnvelope`, `isCardNestedErrorEnvelope`, and their types. |
|
|
18
|
+
| `@facto-to/card/testing` | `MemoryDeliveryInboxStore`, synthetic inbox vectors, catalog fixtures, simulator scenarios, browser-safe Interlace `CARD_TRANSACTION` fixtures/replay helpers (`interlaceCardTransactionFixtures`, `mapInterlaceCardTransactionToAuthorization`, `replayInterlaceCardTransaction`, `createCardSandboxRuntime`), plus Node-only `startCardSimulator` and `runCardSimulatorVectors`. The `"browser"` export condition ships only the zero-Node-dependency testing core with its own declarations (`dist/testing-browser.d.ts`, without the Node-only exports). TypeScript applies that condition only when configured, for example `"customConditions": ["browser"]` with `"moduleResolution": "bundler"`; otherwise it type-checks against the Node declarations. |
|
|
19
|
+
| `facto-card` command | `simulator`, `simulator-config`, `vectors`, `deliveries`, and `replay` against a loopback simulator with synthetic credentials. |
|
|
20
|
+
|
|
21
|
+
## Minimal client
|
|
22
|
+
|
|
23
|
+
Always pass an explicit `CardApiKeySecret`; bare strings are rejected with `CardError` (`outcome: 'config_invalid'`). The `hmac_secret` issued by Facto is a base64url string whose UTF-8 bytes are the HMAC key Engine verifies, so pass it as `{ encoding: 'utf8', value }`. Use `{ encoding: 'hex', value }` or raw `Uint8Array` only when your integration contract explicitly provisions hex-encoded or raw key bytes out-of-band. Never trim or re-encode a raw UTF-8 secret, and never log secrets or signatures.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createCardClient, type CardApiKeySecret } from '@facto-to/card'
|
|
27
|
+
|
|
28
|
+
const environment = process.env.FACTO_ENVIRONMENT
|
|
29
|
+
if (environment !== 'dev' && environment !== 'production') {
|
|
30
|
+
throw new Error('FACTO_ENVIRONMENT must be dev or production')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const secret = process.env.FACTO_API_KEY_SECRET
|
|
34
|
+
if (!secret) throw new Error('FACTO_API_KEY_SECRET is required')
|
|
35
|
+
// Facto-issued hmac_secret: Engine verifies the UTF-8 bytes of this exact string.
|
|
36
|
+
const apiKeySecret: CardApiKeySecret = { encoding: 'utf8', value: secret }
|
|
37
|
+
|
|
38
|
+
const card = createCardClient({
|
|
39
|
+
environment,
|
|
40
|
+
apiBaseUrl: process.env.FACTO_API_BASE_URL,
|
|
41
|
+
connectionId: process.env.FACTO_CONNECTION_ID!,
|
|
42
|
+
programId: process.env.FACTO_PROGRAM_ID!,
|
|
43
|
+
apiKeyId: process.env.FACTO_API_KEY_ID!,
|
|
44
|
+
apiKeySecret,
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For Test, set `environment` to `dev` and explicitly set `apiBaseUrl` to `https://test-api.facto.to`. External dev defaults to `https://dev-api.facto.to`. For `production`, provide an explicitly approved `apiBaseUrl`; no production URL is assumed implicitly. Use separate credentials, grants, and delivery registrations for each deployment.
|
|
49
|
+
|
|
50
|
+
Keep credentials in server-side secret storage. Only verify a delivery with `verifyEventDelivery` and pass its successful result, unchanged, to `receiveEventDelivery`; the inbox rejects any other object.
|
|
51
|
+
|
|
52
|
+
## Limits
|
|
53
|
+
|
|
54
|
+
- Each response body is read incrementally and rejected with `FACTO_ENGINE_RESPONSE_INVALID` once it exceeds `maxResponseBytes` (default 1 MiB).
|
|
55
|
+
- `withServerRetry` honors a `Retry-After` of at most `maxRetryAfterMs` (default 60 seconds). A longer requested wait ends retrying and rethrows the error with the server's original `retryAfterSeconds`.
|
|
56
|
+
- The SDK does not read HTTP request bodies for your delivery receiver; bound the body size and request time in your HTTP layer before verification.
|
|
57
|
+
|
|
58
|
+
## Source, guide and support
|
|
59
|
+
|
|
60
|
+
The package includes editable TypeScript in `dist/source` and the integration guide in [dist/docs/README.md](dist/docs/README.md). To rebuild from the source directory, run `npm install` followed by `npm run build` there. Build dependencies are public npm packages; the SDK has no runtime dependencies.
|
|
61
|
+
|
|
62
|
+
For access, support, or confidential security reports contact dev@facto.to.
|
|
63
|
+
|
|
64
|
+
Interlace implementers should read the [Adapter v1 profile](dist/docs/interlace-adapter-v1.md), [Chinese profile](dist/docs/interlace-adapter-v1.zh.md), and [Chinese integration and results](dist/docs/integration.zh.md). Supplier funds writes are at most once, even where generic SDK retry guidance permits retrying a Facto request.
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
interface DeliveryScope {
|
|
2
|
+
readonly connectionId: string;
|
|
3
|
+
readonly environment: 'dev' | 'production';
|
|
4
|
+
readonly programId: string;
|
|
5
|
+
readonly targetRevision: string;
|
|
6
|
+
}
|
|
7
|
+
interface DeliverySigningKey extends DeliveryScope {
|
|
8
|
+
readonly keyId: string;
|
|
9
|
+
readonly secret: Uint8Array;
|
|
10
|
+
readonly signerKeyVersion: number;
|
|
11
|
+
readonly notBefore: string;
|
|
12
|
+
readonly expiresAt: string;
|
|
13
|
+
readonly status: 'active' | 'overlap' | 'revoked' | 'expired';
|
|
14
|
+
readonly eventKinds: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
type DeliveryVerificationFailureReason = 'missing_header' | 'header_invalid' | 'key_not_allowed' | 'timestamp_out_of_window' | 'signature_invalid' | 'envelope_mismatch' | 'scope_mismatch';
|
|
17
|
+
declare const CARD_REDELIVERY_REASONS: readonly ["retry", "approved_replay", "sandbox_replay", "dead_letter_replay"];
|
|
18
|
+
type CardRedeliveryReason = (typeof CARD_REDELIVERY_REASONS)[number];
|
|
19
|
+
interface VerifyEventDeliveryInput {
|
|
20
|
+
readonly rawBody: Uint8Array;
|
|
21
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
22
|
+
readonly registry: readonly DeliverySigningKey[];
|
|
23
|
+
readonly expectedScope: DeliveryScope;
|
|
24
|
+
readonly nowSeconds?: number;
|
|
25
|
+
readonly toleranceSeconds?: number;
|
|
26
|
+
}
|
|
27
|
+
type VerifiedEventDelivery = {
|
|
28
|
+
readonly verified: true;
|
|
29
|
+
readonly scope: Readonly<DeliveryScope>;
|
|
30
|
+
readonly eventId: string;
|
|
31
|
+
readonly eventKind: string;
|
|
32
|
+
readonly bodyDigest: string;
|
|
33
|
+
readonly eventJson: string;
|
|
34
|
+
readonly redeliveryReason?: CardRedeliveryReason;
|
|
35
|
+
};
|
|
36
|
+
type EventDeliveryVerification = {
|
|
37
|
+
readonly verified: false;
|
|
38
|
+
readonly reason: DeliveryVerificationFailureReason;
|
|
39
|
+
} | VerifiedEventDelivery;
|
|
40
|
+
interface CreateDeliveryVerifierOptions {
|
|
41
|
+
readonly registry: readonly DeliverySigningKey[];
|
|
42
|
+
readonly expectedScope: DeliveryScope;
|
|
43
|
+
readonly nowSeconds?: () => number;
|
|
44
|
+
readonly toleranceSeconds?: number;
|
|
45
|
+
}
|
|
46
|
+
interface DeliveryVerifierInput {
|
|
47
|
+
readonly rawBody: Uint8Array;
|
|
48
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
49
|
+
readonly nowSeconds?: number;
|
|
50
|
+
readonly toleranceSeconds?: number;
|
|
51
|
+
}
|
|
52
|
+
type DeliveryVerifier = (input: DeliveryVerifierInput) => EventDeliveryVerification;
|
|
53
|
+
declare function verifyEventDelivery(input: VerifyEventDeliveryInput): EventDeliveryVerification;
|
|
54
|
+
declare function createDeliveryVerifier(options: CreateDeliveryVerifierOptions): DeliveryVerifier;
|
|
55
|
+
declare function getBusinessPayloadDigest(verifiedDelivery: VerifiedEventDelivery): string;
|
|
56
|
+
|
|
57
|
+
declare const CARD_EVENT_KINDS: readonly ["card.binding.linked", "card.binding.relinked", "card.binding.revoked", "card.binding.route_changed", "card.binding.limits_changed", "card.binding.ownership_transferred", "card.charge.finalized", "card.charge.facts_updated", "card.authorization.updated"];
|
|
58
|
+
type CardEventKind = (typeof CARD_EVENT_KINDS)[number];
|
|
59
|
+
type BindingKind = Extract<CardEventKind, `card.binding.${string}`>;
|
|
60
|
+
type JsonObject = Readonly<Record<string, unknown>>;
|
|
61
|
+
type CardUsdcAmount = string;
|
|
62
|
+
interface DeliveredCardDisplay {
|
|
63
|
+
readonly network: string | null;
|
|
64
|
+
readonly type: 'virtual' | 'physical' | 'unknown' | (string & {}) | null;
|
|
65
|
+
readonly last4: string | null;
|
|
66
|
+
}
|
|
67
|
+
interface Envelope<K extends string> {
|
|
68
|
+
readonly envelope_version: 2;
|
|
69
|
+
readonly event_id: string;
|
|
70
|
+
readonly event_kind: K;
|
|
71
|
+
readonly environment: 'dev' | 'production';
|
|
72
|
+
readonly program_id: string;
|
|
73
|
+
readonly origin_connection_id?: string;
|
|
74
|
+
readonly connection_sequence: number | null;
|
|
75
|
+
readonly occurred_at: string;
|
|
76
|
+
}
|
|
77
|
+
type BindingData<K extends BindingKind> = K extends 'card.binding.linked' | 'card.binding.relinked' ? {
|
|
78
|
+
readonly external_card_id: string;
|
|
79
|
+
readonly binding_id: string;
|
|
80
|
+
readonly card: DeliveredCardDisplay;
|
|
81
|
+
readonly intent_id?: string | null;
|
|
82
|
+
readonly environment?: 'dev' | 'production';
|
|
83
|
+
readonly subject_link_id?: string;
|
|
84
|
+
readonly approved_scopes?: readonly string[];
|
|
85
|
+
readonly consent_revision?: string;
|
|
86
|
+
readonly ownership_transfer?: boolean;
|
|
87
|
+
readonly previous_binding_id?: string;
|
|
88
|
+
} : K extends 'card.binding.revoked' ? {
|
|
89
|
+
readonly external_card_id: string;
|
|
90
|
+
readonly binding_id: string;
|
|
91
|
+
readonly card: DeliveredCardDisplay;
|
|
92
|
+
readonly environment?: 'dev' | 'production';
|
|
93
|
+
readonly binding_revision?: number;
|
|
94
|
+
readonly intent_id?: string | null;
|
|
95
|
+
readonly reason_code?: string;
|
|
96
|
+
readonly revocation_source?: string;
|
|
97
|
+
readonly payable_projections_closed?: number;
|
|
98
|
+
readonly routes_detached?: number;
|
|
99
|
+
readonly route_associations_detached?: number;
|
|
100
|
+
} : K extends 'card.binding.route_changed' ? {
|
|
101
|
+
readonly binding_id: string;
|
|
102
|
+
readonly association_status: 'associated' | 'unassociated';
|
|
103
|
+
readonly environment?: 'dev' | 'production';
|
|
104
|
+
readonly binding_revision?: number;
|
|
105
|
+
} : K extends 'card.binding.limits_changed' ? {
|
|
106
|
+
readonly binding_id: string;
|
|
107
|
+
readonly per_tx_limit: CardUsdcAmount;
|
|
108
|
+
readonly period_limit: CardUsdcAmount;
|
|
109
|
+
readonly period: string;
|
|
110
|
+
readonly expires_at: string | null;
|
|
111
|
+
readonly environment?: 'dev' | 'production';
|
|
112
|
+
readonly binding_revision?: number;
|
|
113
|
+
} : {
|
|
114
|
+
readonly previous_binding_id: string;
|
|
115
|
+
readonly new_binding_id: string;
|
|
116
|
+
readonly external_card_id: string;
|
|
117
|
+
readonly card: DeliveredCardDisplay;
|
|
118
|
+
readonly transferred_at: string;
|
|
119
|
+
};
|
|
120
|
+
type CardBindingEvent<K extends BindingKind = BindingKind> = Envelope<K> & {
|
|
121
|
+
readonly binding_id: string;
|
|
122
|
+
readonly binding_revision: number;
|
|
123
|
+
readonly data: BindingData<K>;
|
|
124
|
+
};
|
|
125
|
+
interface ChargeFact {
|
|
126
|
+
readonly kind: string;
|
|
127
|
+
readonly state: string;
|
|
128
|
+
readonly recorded_at: string;
|
|
129
|
+
readonly source_system: string;
|
|
130
|
+
readonly observed_at?: string;
|
|
131
|
+
readonly safe_code?: string;
|
|
132
|
+
}
|
|
133
|
+
interface DeliveredChargeFinalReceipt {
|
|
134
|
+
readonly receipt_event_id: string;
|
|
135
|
+
readonly charge_id: string;
|
|
136
|
+
readonly external_authorization_id: string;
|
|
137
|
+
readonly mapping_revision: string;
|
|
138
|
+
readonly operation_type: string;
|
|
139
|
+
readonly resource_version: string;
|
|
140
|
+
readonly execution_outcome: string;
|
|
141
|
+
readonly terminal_action: string;
|
|
142
|
+
readonly finalized_at: string;
|
|
143
|
+
readonly facts_at_finality: readonly ChargeFact[];
|
|
144
|
+
}
|
|
145
|
+
interface SequencedEnvelope<K extends string> extends Envelope<K> {
|
|
146
|
+
readonly connection_sequence: number;
|
|
147
|
+
readonly origin_connection_id: string;
|
|
148
|
+
}
|
|
149
|
+
type ChargeFinalizedEvent = SequencedEnvelope<'card.charge.finalized'> & {
|
|
150
|
+
readonly data: {
|
|
151
|
+
readonly authorization_revision: number;
|
|
152
|
+
readonly operation_type: string;
|
|
153
|
+
readonly resource_version: string;
|
|
154
|
+
readonly external_authorization_id: string;
|
|
155
|
+
readonly mapping_revision: string;
|
|
156
|
+
readonly final_receipt: DeliveredChargeFinalReceipt;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
type ChargeFactsUpdatedEvent = SequencedEnvelope<'card.charge.facts_updated'> & {
|
|
160
|
+
readonly data: {
|
|
161
|
+
readonly authorization_revision: number;
|
|
162
|
+
readonly operation_type: string;
|
|
163
|
+
readonly resource_version: string;
|
|
164
|
+
readonly external_authorization_id: string;
|
|
165
|
+
readonly mapping_revision: string;
|
|
166
|
+
readonly charge_id: string;
|
|
167
|
+
readonly final_receipt_event_id: string;
|
|
168
|
+
readonly previous_authorization_revision: number;
|
|
169
|
+
readonly facts: readonly ChargeFact[];
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
interface CipLifecycleSummary {
|
|
173
|
+
readonly state: string;
|
|
174
|
+
readonly cleared_amount: CardUsdcAmount;
|
|
175
|
+
readonly reversed_amount: CardUsdcAmount;
|
|
176
|
+
readonly refunded_amount: CardUsdcAmount;
|
|
177
|
+
readonly entry_count: number;
|
|
178
|
+
readonly unlinked_count: number;
|
|
179
|
+
readonly last_recorded_at?: string;
|
|
180
|
+
}
|
|
181
|
+
interface RefundSummary {
|
|
182
|
+
readonly case_count: number;
|
|
183
|
+
readonly status_counts: Readonly<{
|
|
184
|
+
awaiting_charge_final: number;
|
|
185
|
+
awaiting_funds: number;
|
|
186
|
+
payable: number;
|
|
187
|
+
paid: number;
|
|
188
|
+
failed: number;
|
|
189
|
+
not_payable: number;
|
|
190
|
+
}>;
|
|
191
|
+
readonly total_amount: CardUsdcAmount;
|
|
192
|
+
readonly total_paid_amount: CardUsdcAmount;
|
|
193
|
+
readonly total_excess_amount: CardUsdcAmount;
|
|
194
|
+
readonly last_updated_at?: string;
|
|
195
|
+
}
|
|
196
|
+
interface AuthorizationChange {
|
|
197
|
+
readonly type: string;
|
|
198
|
+
readonly at: string;
|
|
199
|
+
readonly ref?: string;
|
|
200
|
+
readonly issuer_fact?: Readonly<{
|
|
201
|
+
operation_type: string;
|
|
202
|
+
resource_version: string;
|
|
203
|
+
amount: CardUsdcAmount;
|
|
204
|
+
currency: string;
|
|
205
|
+
recorded_at: string;
|
|
206
|
+
link_status: string;
|
|
207
|
+
unlinked_reason?: string;
|
|
208
|
+
}>;
|
|
209
|
+
readonly refund_case?: Readonly<{
|
|
210
|
+
case_id: string;
|
|
211
|
+
source_operation_type: string;
|
|
212
|
+
status: string;
|
|
213
|
+
amount: CardUsdcAmount;
|
|
214
|
+
excess_amount: CardUsdcAmount;
|
|
215
|
+
paid_amount?: CardUsdcAmount;
|
|
216
|
+
not_payable_reason?: string;
|
|
217
|
+
updated_at: string;
|
|
218
|
+
refund_payment?: Readonly<{
|
|
219
|
+
chain_id: number;
|
|
220
|
+
tx_hash: string;
|
|
221
|
+
paid_amount: CardUsdcAmount;
|
|
222
|
+
recorded_by: string;
|
|
223
|
+
}>;
|
|
224
|
+
}>;
|
|
225
|
+
}
|
|
226
|
+
interface AuthorizationUpdateData {
|
|
227
|
+
readonly lifecycle_revision: number;
|
|
228
|
+
readonly operation_type: string;
|
|
229
|
+
readonly resource_version: string;
|
|
230
|
+
readonly external_authorization_id: string;
|
|
231
|
+
readonly mapping_revision: string;
|
|
232
|
+
readonly authorization: Readonly<{
|
|
233
|
+
supplier_transaction_id?: string;
|
|
234
|
+
amount: CardUsdcAmount;
|
|
235
|
+
currency: string;
|
|
236
|
+
decision?: string;
|
|
237
|
+
}>;
|
|
238
|
+
readonly charge: Readonly<{
|
|
239
|
+
charge_id: string;
|
|
240
|
+
status: string;
|
|
241
|
+
amount: CardUsdcAmount;
|
|
242
|
+
fee_total: CardUsdcAmount;
|
|
243
|
+
total_debited: CardUsdcAmount;
|
|
244
|
+
currency: string;
|
|
245
|
+
user_payment?: Readonly<{
|
|
246
|
+
chain_id: number;
|
|
247
|
+
asset_symbol?: string;
|
|
248
|
+
tx_hash: string;
|
|
249
|
+
}>;
|
|
250
|
+
failure_code?: string;
|
|
251
|
+
updated_at: string;
|
|
252
|
+
}> | null;
|
|
253
|
+
readonly issuer: CipLifecycleSummary;
|
|
254
|
+
readonly refunds: RefundSummary;
|
|
255
|
+
readonly change: AuthorizationChange;
|
|
256
|
+
}
|
|
257
|
+
type AuthorizationUpdatedEvent = SequencedEnvelope<'card.authorization.updated'> & {
|
|
258
|
+
readonly data: AuthorizationUpdateData;
|
|
259
|
+
};
|
|
260
|
+
type CardKnownEvent = {
|
|
261
|
+
[K in BindingKind]: CardBindingEvent<K>;
|
|
262
|
+
}[BindingKind] | ChargeFinalizedEvent | ChargeFactsUpdatedEvent | AuthorizationUpdatedEvent;
|
|
263
|
+
type DecodedDeliveryEvent = {
|
|
264
|
+
readonly type: 'known';
|
|
265
|
+
readonly event: CardKnownEvent;
|
|
266
|
+
} | {
|
|
267
|
+
readonly type: 'unknown';
|
|
268
|
+
readonly eventKind: string;
|
|
269
|
+
readonly rawJson: string;
|
|
270
|
+
readonly event: JsonObject;
|
|
271
|
+
};
|
|
272
|
+
declare function decodeDeliveryEvent(delivery: Extract<EventDeliveryVerification, {
|
|
273
|
+
verified: true;
|
|
274
|
+
}>): DecodedDeliveryEvent;
|
|
275
|
+
|
|
276
|
+
type Verified = Extract<EventDeliveryVerification, {
|
|
277
|
+
verified: true;
|
|
278
|
+
}>;
|
|
279
|
+
interface DeliveryInboxTransaction<Context = unknown> {
|
|
280
|
+
readonly context: Context;
|
|
281
|
+
readonly fence: number;
|
|
282
|
+
getDigest(eventId: string): Promise<string | undefined>;
|
|
283
|
+
getObservedMaxSequence(): Promise<number | null>;
|
|
284
|
+
markProcessed(eventId: string, digest: string, sequence: number | null): Promise<void>;
|
|
285
|
+
}
|
|
286
|
+
interface DeliveryInboxStore<Context = unknown> {
|
|
287
|
+
withConnection<T>(scope: Readonly<DeliveryScope>, operation: (transaction: DeliveryInboxTransaction<Context>) => Promise<T>): Promise<T>;
|
|
288
|
+
}
|
|
289
|
+
type DeliveryEventRevision = {
|
|
290
|
+
readonly field: 'binding_revision' | 'authorization_revision' | 'lifecycle_revision';
|
|
291
|
+
readonly value: number;
|
|
292
|
+
} | null;
|
|
293
|
+
interface DeliveryInboxMetadata {
|
|
294
|
+
readonly connectionSequence: number | null;
|
|
295
|
+
readonly eventRevision: DeliveryEventRevision;
|
|
296
|
+
}
|
|
297
|
+
interface DeliveryInboxOptions<Context = unknown> {
|
|
298
|
+
readonly store: DeliveryInboxStore<Context>;
|
|
299
|
+
readonly handle: (event: DecodedDeliveryEvent, transaction: DeliveryInboxTransaction<Context>, metadata: DeliveryInboxMetadata) => Promise<void>;
|
|
300
|
+
}
|
|
301
|
+
interface ObservedSequenceGap {
|
|
302
|
+
readonly previousMaxSequence: number;
|
|
303
|
+
readonly currentSequence: number;
|
|
304
|
+
}
|
|
305
|
+
type DeliveryInboxResult = {
|
|
306
|
+
readonly status: 'processed' | 'duplicate_ignored';
|
|
307
|
+
readonly connectionSequence: number | null;
|
|
308
|
+
readonly observedSequenceGap: ObservedSequenceGap | null;
|
|
309
|
+
};
|
|
310
|
+
declare function receiveEventDelivery<Context>(delivery: Verified, options: DeliveryInboxOptions<Context>): Promise<DeliveryInboxResult>;
|
|
311
|
+
|
|
312
|
+
export { type AuthorizationChange as A, createDeliveryVerifier as B, CARD_EVENT_KINDS as C, type DecodedDeliveryEvent as D, type EventDeliveryVerification as E, decodeDeliveryEvent as F, getBusinessPayloadDigest as G, receiveEventDelivery as H, verifyEventDelivery as I, type ObservedSequenceGap as O, type RefundSummary as R, type VerifiedEventDelivery as V, type AuthorizationUpdateData as a, type AuthorizationUpdatedEvent as b, CARD_REDELIVERY_REASONS as c, type CardBindingEvent as d, type CardEventKind as e, type CardKnownEvent as f, type CardRedeliveryReason as g, type ChargeFact as h, type ChargeFactsUpdatedEvent as i, type ChargeFinalizedEvent as j, type CipLifecycleSummary as k, type CreateDeliveryVerifierOptions as l, type DeliveredCardDisplay as m, type DeliveredChargeFinalReceipt as n, type DeliveryEventRevision as o, type DeliveryInboxMetadata as p, type DeliveryInboxOptions as q, type DeliveryInboxResult as r, type DeliveryInboxStore as s, type DeliveryInboxTransaction as t, type DeliveryScope as u, type DeliverySigningKey as v, type DeliveryVerificationFailureReason as w, type DeliveryVerifier as x, type DeliveryVerifierInput as y, type VerifyEventDeliveryInput as z };
|