@fun-xyz/fiat-contract 0.25.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -11
- package/dist/{chunk-WEXD7UEE.mjs → chunk-3SZPKXVL.mjs} +2 -2
- package/dist/{chunk-T5JAYOWY.mjs → chunk-F4NRKWF5.mjs} +1 -1
- package/dist/{chunk-CRNKRIKR.mjs → chunk-XKI5XTUO.mjs} +1 -1
- package/dist/{chunk-LHCED3AP.mjs → chunk-YNVLBTT7.mjs} +2 -2
- package/dist/index.js +62 -32
- package/dist/index.mjs +64 -34
- package/dist/providers/moonpay.d.ts +18 -17
- package/dist/providers/moonpay.mjs +1 -1
- package/dist/providers/moonpay.schemas.d.ts +7 -7
- package/dist/routing.d.ts +43 -6
- package/dist/routing.js +1 -1
- package/dist/routing.mjs +1 -1
- package/dist/schemas.d.ts +3 -1
- package/dist/table.js +1 -1
- package/dist/table.mjs +1 -1
- package/dist/terms.d.ts +1 -1
- package/dist/terms.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Four things, zero runtime logic beyond validation:
|
|
|
19
19
|
| --- | --- | --- | --- |
|
|
20
20
|
| `@fun-xyz/fiat-contract/types` | **0.1 KB** (types erase) | every type; no runtime values | production, both repos |
|
|
21
21
|
| `@fun-xyz/fiat-contract/table` | **13.8 KB**, zero deps | `TRANSITION_TABLE`, `stateKey`, `tableEntry`, `isTerminal`, `walkTable`, `TABLE_VERSION`, `TERMINAL_ORDER_STATUSES`, `DOCUMENTED_ENDPOINTS`, `UNOFFERED_ENDPOINTS`, `UNREACHABLE_STATES`, `unofferedEndpoints`, `unreachableStates` | **production frontend** + backend |
|
|
22
|
-
| `@fun-xyz/fiat-contract/moonpay` | zero deps | the MoonPay flow on `POST /fiat/next`: action requests,
|
|
22
|
+
| `@fun-xyz/fiat-contract/moonpay` | zero deps | the MoonPay flow on `POST /fiat/next`: action requests, next actions, responses, fault types, and `MOONPAY_ENDPOINTS` | **production frontend** (MoonPay adapter) + backend |
|
|
23
23
|
| `@fun-xyz/fiat-contract/terms` | zero deps | the platform terms route: `TermsDocument`, `FiatTermsRequest`, `FiatTermsResponse`, fault types, and `FIAT_TERMS_ENDPOINT` | **production frontend** + backend |
|
|
24
24
|
| `@fun-xyz/fiat-contract/routing` | zero deps | the routing table and routing quote: `FiatRoutingTableQuery`, `FiatRoutingTableResponse`, `FiatRoutingQuoteRequest`, both routes' error bodies, and `ROUTING_ENDPOINTS` | **production frontend** + backend |
|
|
25
25
|
| `@fun-xyz/fiat-contract` | 47.6 KB, needs zod | the above + 77 zod schemas + assertions + 18 fixtures | tests, and backend dev/test guards |
|
|
@@ -121,7 +121,8 @@ text. `PROVIDER_CHECKOUT_DOCUMENTS` maps each provider to its current `CHECKOUT`
|
|
|
121
121
|
stays valid: the backend refuses only an unknown version, a wrong digest, or an `acceptedAt` older
|
|
122
122
|
than 5 minutes. A repeat of a version the login already holds writes nothing and returns the ids.
|
|
123
123
|
|
|
124
|
-
**Routing table (`./routing`).** `ROUTING_ENDPOINTS.table` (`
|
|
124
|
+
**Routing table (`./routing`).** `ROUTING_ENDPOINTS.table` (`POST /fiat/routing/table`) takes a
|
|
125
|
+
`FiatRoutingTableRequest` body and answers,
|
|
125
126
|
for each requested method, every amount interval and its providers best first, each with `next`
|
|
126
127
|
(`READY`, `AUTH`, `DECLARATIVE_KYC`, `DOCUMENTARY_KYC`, `PENDING_REVIEW`) and `visibility`. The
|
|
127
128
|
client shows min, max, provider and the Continue label for an amount with no call. A method with no
|
|
@@ -133,14 +134,27 @@ cause is unknown. Refetch the table at `expiresAt`, on `refreshLimits: true`, an
|
|
|
133
134
|
a `REQUOTE`. The schemas hold the table's invariants: each method once, sorted, non-overlapping
|
|
134
135
|
intervals, at least one provider each and none twice, and a reason only on an empty method.
|
|
135
136
|
|
|
137
|
+
`ROUTING_ENDPOINTS.table` (`POST /fiat/routing/table`) accepts `FiatRoutingTableRequest`:
|
|
138
|
+
`cryptoCurrencyCode`, `chainId`, `country`, optional `region` (required for US), `methods` (array),
|
|
139
|
+
optional `fiatCurrencyCode` (default `USD`), and optional `providers`.
|
|
140
|
+
See [`FiatRoutingTableMoonPayInputs`](src/routing.ts) for MoonPay credential handling.
|
|
141
|
+
Blank tokens, malformed inputs and unknown keys return 400: omit unavailable credentials and
|
|
142
|
+
deploy backend support before sending new provider keys.
|
|
143
|
+
`GET /fiat/routing/table` is deprecated but still works without provider inputs.
|
|
144
|
+
|
|
136
145
|
`ROUTING_ENDPOINTS.quote` (`POST /fiat/routing/quote`) takes the `POST /fiat/quote` body
|
|
137
|
-
(`FiatRoutingQuoteTerms`),
|
|
146
|
+
(`FiatRoutingQuoteTerms`), plus one of two forms:
|
|
138
147
|
|
|
139
148
|
- `providers`: the interval's providers, best first. The backend prices them in order, falls
|
|
140
149
|
through on the refusals marked "next provider" below, and answers the first that prices or the
|
|
141
150
|
last provider's refusal.
|
|
142
151
|
- `provider`: one provider only. The client falls through itself.
|
|
143
152
|
|
|
153
|
+
Routing quotes may include `routingOverrides: { providers: [...] }` with the host’s full allowlist.
|
|
154
|
+
The selected `provider` or ordered `providers` must be a subset. The server preserves the allowlist
|
|
155
|
+
through later KYC rerouting; the amount-specific candidate list alone does not restrict rediscovery.
|
|
156
|
+
Omitting the field preserves existing behavior. An empty allowlist permits no quote candidate.
|
|
157
|
+
|
|
144
158
|
It answers the same `FiatStepResponse`, whose `provider` names the one that priced. A refusal is a
|
|
145
159
|
`FiatRoutingQuoteErrorBody`, and it decides whether the next provider may still price:
|
|
146
160
|
|
|
@@ -173,21 +187,21 @@ response), and the provider's own request, which names its `action`. The orchest
|
|
|
173
187
|
`MoonPayNextRequest`, and every MoonPay request also carries the context `checkout` and, after
|
|
174
188
|
`connect`, `credentials` (`customerId`, `accessToken`).
|
|
175
189
|
|
|
176
|
-
Each `MoonPayAction` has one name. A response
|
|
190
|
+
Each `MoonPayAction` has one name. A response names the next action in `next` and carries what the
|
|
177
191
|
client needs; the client's request names it in `action` and carries the result:
|
|
178
192
|
|
|
179
|
-
| Action |
|
|
193
|
+
| Action | Next action carries | Request carries | A repeat |
|
|
180
194
|
| --- | --- | --- | --- |
|
|
181
|
-
| `observe` | no
|
|
195
|
+
| `observe` | no next action of its own: the answer is the current next action | nothing | writes nothing |
|
|
182
196
|
| `consent` | `documents` (at least one, unique ids) | `acceptances`, the `POST /fiat/terms` items | writes nothing new |
|
|
183
197
|
| `connect` | `sessionToken`, `quoteInput`, `resetConnection?` (`true` when the device's MoonPay connection is another buyer's) | `customerId`, `accessToken` | rebinds the same customer |
|
|
184
198
|
| `kyc` | `fields`, `fieldErrors?` (each naming a field in `fields`, with `code?` `PHONE_IN_USE` on `PHONE_NUMBER` or `TAX_ID_IN_USE` on `TAX_IDENTIFIER` when another MoonPay customer holds the value) | `credentials`, `values` keyed by `KycFieldId` (no form id) | drops values MoonPay no longer asks for |
|
|
185
199
|
| `wait` | `retryAfterMs` (at most 60 s) | no request: the client sends `observe` after the delay | |
|
|
186
200
|
| `order` | `orderId`, `quoteInput` | `orderId`, `quotedAmount`, `transactionId?` | returns the recorded order |
|
|
187
201
|
|
|
188
|
-
Every response is the next
|
|
202
|
+
Every response is the next action, `done`, or `refused` (`MoonPayRefused`), and
|
|
189
203
|
`MoonPayResponseFor` maps each request action to its union. `observe`, `consent`, `connect` and `kyc`
|
|
190
|
-
answer a `MoonPayStepResponse`: any `
|
|
204
|
+
answer a `MoonPayStepResponse`: any `MoonPayNextAction`, or `refused` with `reason` (`NOT_ELIGIBLE`,
|
|
191
205
|
`DOCUMENTS_REQUIRED`, `FINAL_REJECTION`, `CUSTOMER_MISMATCH`) and `recovery: REQUOTE | NONE`.
|
|
192
206
|
|
|
193
207
|
`order` runs after every charge attempt, a failed one too, and answers a `MoonPayOrderResponse`:
|
|
@@ -203,10 +217,11 @@ A first-time buyer goes `observe` → `consent` → `connect` → `kyc` → `wai
|
|
|
203
217
|
`test/fixtures/moonpay-next/`.
|
|
204
218
|
|
|
205
219
|
A fault is a 4xx or 5xx with a `MoonPayErrorBody`: the shared `errorCode`, `errorMsg` and `reqId`,
|
|
206
|
-
plus `reason`
|
|
207
|
-
|
|
220
|
+
plus `reason` and `recovery`. The reasons are `SESSION_BUDGET_SPENT`, `RATE_LIMITED`,
|
|
221
|
+
`PROVIDER_UNAVAILABLE` (MoonPay is down), `KYC_PROVIDER_UNAVAILABLE` (Sumsub is down),
|
|
222
|
+
`SERVICE_UNAVAILABLE` (one of Fun's own stores is down) and `INVALID_REQUEST`. The recoveries are
|
|
208
223
|
`RETRY` (send the same request again), `REQUOTE`, or `NONE`. A field error is a `kyc`
|
|
209
|
-
|
|
224
|
+
next action, not a fault. The zod schemas (`MoonPay*Schema`, `FiatGeoSchema`, `FiatNextRequestSchema`,
|
|
210
225
|
`TermsDocumentSchema`, `FiatTerms*Schema`) are exported from the root only.
|
|
211
226
|
|
|
212
227
|
## KYC SDK hints, results, and client delivery
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/routing.ts
|
|
2
2
|
var ROUTING_ENDPOINTS = {
|
|
3
|
-
table: "
|
|
3
|
+
table: "POST /fiat/routing/table",
|
|
4
4
|
/** Temporary: `POST /fiat/next` replaces it for each provider that moves there. */
|
|
5
5
|
quote: "POST /fiat/routing/quote"
|
|
6
6
|
};
|
|
@@ -8,4 +8,4 @@ var ROUTING_ENDPOINTS = {
|
|
|
8
8
|
export {
|
|
9
9
|
ROUTING_ENDPOINTS
|
|
10
10
|
};
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
11
|
+
//# sourceMappingURL=chunk-3SZPKXVL.mjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.28.0";
|
|
3
3
|
|
|
4
4
|
// src/table.ts
|
|
5
5
|
var TABLE_VERSION = version;
|
|
@@ -514,4 +514,4 @@ export {
|
|
|
514
514
|
tableEntry,
|
|
515
515
|
isTerminal
|
|
516
516
|
};
|
|
517
|
-
//# sourceMappingURL=chunk-
|
|
517
|
+
//# sourceMappingURL=chunk-YNVLBTT7.mjs.map
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ __export(index_exports, {
|
|
|
50
50
|
FiatRoutingQuoteTermsSchema: () => FiatRoutingQuoteTermsSchema,
|
|
51
51
|
FiatRoutingTableErrorBodySchema: () => FiatRoutingTableErrorBodySchema,
|
|
52
52
|
FiatRoutingTableQuerySchema: () => FiatRoutingTableQuerySchema,
|
|
53
|
+
FiatRoutingTableRequestSchema: () => FiatRoutingTableRequestSchema,
|
|
53
54
|
FiatRoutingTableResponseSchema: () => FiatRoutingTableResponseSchema,
|
|
54
55
|
FiatStepResponseSchema: () => FiatStepResponseSchema,
|
|
55
56
|
FiatTermsErrorBodySchema: () => FiatTermsErrorBodySchema,
|
|
@@ -75,28 +76,28 @@ __export(index_exports, {
|
|
|
75
76
|
KycSdkResultReportSchema: () => KycSdkResultReportSchema,
|
|
76
77
|
MOONPAY_ENDPOINTS: () => MOONPAY_ENDPOINTS,
|
|
77
78
|
MoonPayCheckoutSchema: () => MoonPayCheckoutSchema,
|
|
78
|
-
|
|
79
|
+
MoonPayConnectNextActionSchema: () => MoonPayConnectNextActionSchema,
|
|
79
80
|
MoonPayConnectRequestSchema: () => MoonPayConnectRequestSchema,
|
|
80
|
-
|
|
81
|
+
MoonPayConsentNextActionSchema: () => MoonPayConsentNextActionSchema,
|
|
81
82
|
MoonPayConsentRequestSchema: () => MoonPayConsentRequestSchema,
|
|
82
83
|
MoonPayDoneSchema: () => MoonPayDoneSchema,
|
|
83
84
|
MoonPayErrorBodySchema: () => MoonPayErrorBodySchema,
|
|
84
85
|
MoonPayFaultSchema: () => MoonPayFaultSchema,
|
|
85
|
-
|
|
86
|
+
MoonPayKycNextActionSchema: () => MoonPayKycNextActionSchema,
|
|
86
87
|
MoonPayKycRequestSchema: () => MoonPayKycRequestSchema,
|
|
88
|
+
MoonPayNextActionSchema: () => MoonPayNextActionSchema,
|
|
87
89
|
MoonPayNextRequestSchema: () => MoonPayNextRequestSchema,
|
|
88
90
|
MoonPayObserveRequestSchema: () => MoonPayObserveRequestSchema,
|
|
89
|
-
|
|
91
|
+
MoonPayOrderNextActionSchema: () => MoonPayOrderNextActionSchema,
|
|
90
92
|
MoonPayOrderRequestSchema: () => MoonPayOrderRequestSchema,
|
|
91
93
|
MoonPayOrderResponseSchema: () => MoonPayOrderResponseSchema,
|
|
92
|
-
MoonPayPromptSchema: () => MoonPayPromptSchema,
|
|
93
94
|
MoonPayQuoteInputSchema: () => MoonPayQuoteInputSchema,
|
|
94
95
|
MoonPayRequestContextSchema: () => MoonPayRequestContextSchema,
|
|
95
96
|
MoonPayRequestSchema: () => MoonPayRequestSchema,
|
|
96
97
|
MoonPayResponseSchemaFor: () => MoonPayResponseSchemaFor,
|
|
97
98
|
MoonPaySdkCredentialsSchema: () => MoonPaySdkCredentialsSchema,
|
|
98
99
|
MoonPayStepResponseSchema: () => MoonPayStepResponseSchema,
|
|
99
|
-
|
|
100
|
+
MoonPayWaitNextActionSchema: () => MoonPayWaitNextActionSchema,
|
|
100
101
|
OrderAwaitingConfirmationStateSchema: () => OrderAwaitingConfirmationStateSchema,
|
|
101
102
|
OrderCreatedStateSchema: () => OrderCreatedStateSchema,
|
|
102
103
|
OrderRefSchema: () => OrderRefSchema,
|
|
@@ -1059,6 +1060,20 @@ var $routingTableQuery = obj({
|
|
|
1059
1060
|
)
|
|
1060
1061
|
}).refine((query) => hasUsRegion(query.country, query.region), { message: US_REGION_REQUIRED, path: ["region"] });
|
|
1061
1062
|
var FiatRoutingTableQuerySchema = $routingTableQuery;
|
|
1063
|
+
var $routingTableProviderInputs = obj({
|
|
1064
|
+
MOONPAY: obj({ accessToken: $nonBlank.optional() }).optional()
|
|
1065
|
+
});
|
|
1066
|
+
var $routingTableRequest = obj({
|
|
1067
|
+
fiatCurrencyCode: import_zod.z.enum(FIAT_CURRENCY_CODES).optional(),
|
|
1068
|
+
cryptoCurrencyCode: $nonBlank,
|
|
1069
|
+
chainId: $nonBlank,
|
|
1070
|
+
country: $countryCode,
|
|
1071
|
+
region: $optionalGeoField,
|
|
1072
|
+
// Duplicates are allowed; the response lists each method once.
|
|
1073
|
+
methods: import_zod.z.array(import_zod.z.enum(PAYMENT_METHOD_CATEGORIES)).min(1),
|
|
1074
|
+
providers: $routingTableProviderInputs.optional()
|
|
1075
|
+
}).refine((request) => hasUsRegion(request.country, request.region), { message: US_REGION_REQUIRED, path: ["region"] });
|
|
1076
|
+
var FiatRoutingTableRequestSchema = $routingTableRequest;
|
|
1062
1077
|
var $routingTableProvider = obj({
|
|
1063
1078
|
provider: $routingProvider,
|
|
1064
1079
|
next: import_zod.z.enum(["READY", "AUTH", "DECLARATIVE_KYC", "DOCUMENTARY_KYC", "PENDING_REVIEW"]),
|
|
@@ -1099,7 +1114,8 @@ var $routingQuoteTermsShape = {
|
|
|
1099
1114
|
(geo) => hasUsRegion(geo.alpha2, geo.region),
|
|
1100
1115
|
{ message: US_REGION_REQUIRED, path: ["region"] }
|
|
1101
1116
|
),
|
|
1102
|
-
prepareSessionAuth: import_zod.z.boolean().optional()
|
|
1117
|
+
prepareSessionAuth: import_zod.z.boolean().optional(),
|
|
1118
|
+
routingOverrides: obj({ providers: import_zod.z.array($routingProvider) }).optional()
|
|
1103
1119
|
};
|
|
1104
1120
|
var $routingQuoteTerms = obj($routingQuoteTermsShape);
|
|
1105
1121
|
var FiatRoutingQuoteTermsSchema = $routingQuoteTerms;
|
|
@@ -1109,7 +1125,14 @@ var $routingQuoteRequest = import_zod.z.union([
|
|
|
1109
1125
|
providers: import_zod.z.array($routingProvider).min(1).refine((providers) => hasUniqueIds(providers), "each provider is listed once")
|
|
1110
1126
|
}),
|
|
1111
1127
|
obj({ ...$routingQuoteTermsShape, provider: $routingProvider })
|
|
1112
|
-
])
|
|
1128
|
+
]).refine(
|
|
1129
|
+
(request) => {
|
|
1130
|
+
const allowed = request.routingOverrides?.providers;
|
|
1131
|
+
const selected = "providers" in request ? request.providers : [request.provider];
|
|
1132
|
+
return allowed === void 0 || selected.every((provider) => allowed.includes(provider));
|
|
1133
|
+
},
|
|
1134
|
+
{ message: "requested providers must be allowed by routingOverrides", path: ["routingOverrides"] }
|
|
1135
|
+
);
|
|
1113
1136
|
var FiatRoutingQuoteRequestSchema = $routingQuoteRequest;
|
|
1114
1137
|
var $routingServiceableRange = obj({ min: $money, max: $money, userMax: $money.nullable().optional() });
|
|
1115
1138
|
var $noRouteFields = {
|
|
@@ -1209,7 +1232,7 @@ var $stepResponse = import_zod.z.union([$providerBoundStepResponse, $blockedStep
|
|
|
1209
1232
|
var FiatStepResponseSchema = $stepResponse;
|
|
1210
1233
|
|
|
1211
1234
|
// package.json
|
|
1212
|
-
var version = "0.
|
|
1235
|
+
var version = "0.28.0";
|
|
1213
1236
|
|
|
1214
1237
|
// src/table.ts
|
|
1215
1238
|
var TABLE_VERSION = version;
|
|
@@ -2814,7 +2837,7 @@ var PUBLISHED_TERMS_DOCUMENTS = [MOONPAY_TERMS, ...Object.values(FUN_KYC_CONSENT
|
|
|
2814
2837
|
|
|
2815
2838
|
// src/routing.ts
|
|
2816
2839
|
var ROUTING_ENDPOINTS = {
|
|
2817
|
-
table: "
|
|
2840
|
+
table: "POST /fiat/routing/table",
|
|
2818
2841
|
/** Temporary: `POST /fiat/next` replaces it for each provider that moves there. */
|
|
2819
2842
|
quote: "POST /fiat/routing/quote"
|
|
2820
2843
|
};
|
|
@@ -2885,44 +2908,44 @@ var MoonPayNextRequestSchema = $nextRequest2;
|
|
|
2885
2908
|
var FIELD_OF_CODE = { PHONE_IN_USE: "PHONE_NUMBER", TAX_ID_IN_USE: "TAX_IDENTIFIER" };
|
|
2886
2909
|
var $fieldError = obj2({ fieldId: $nonEmpty, message: $nonEmpty, code: import_zod2.z.enum(["PHONE_IN_USE", "TAX_ID_IN_USE"]).optional() });
|
|
2887
2910
|
var $consentShape = obj2({ next: import_zod2.z.literal("consent"), documents: import_zod2.z.array(TermsDocumentSchema).min(1) });
|
|
2888
|
-
var $
|
|
2911
|
+
var $connectNextAction = obj2({
|
|
2889
2912
|
next: import_zod2.z.literal("connect"),
|
|
2890
2913
|
sessionToken: $nonEmpty,
|
|
2891
2914
|
quoteInput: $quoteInput,
|
|
2892
2915
|
resetConnection: import_zod2.z.literal(true).optional()
|
|
2893
2916
|
});
|
|
2894
2917
|
var $kycShape = obj2({ next: import_zod2.z.literal("kyc"), fields: import_zod2.z.array(FormFieldSchema).min(1), fieldErrors: import_zod2.z.array($fieldError).min(1).optional() });
|
|
2895
|
-
var $
|
|
2896
|
-
var $
|
|
2897
|
-
var checkConsent = (
|
|
2898
|
-
if (!hasUniqueIds2(
|
|
2918
|
+
var $waitNextAction = obj2({ next: import_zod2.z.literal("wait"), retryAfterMs: import_zod2.z.number().int().positive().max(6e4) });
|
|
2919
|
+
var $orderNextAction = obj2({ next: import_zod2.z.literal("order"), orderId: $nonEmpty, quoteInput: $quoteInput });
|
|
2920
|
+
var checkConsent = (nextAction, context) => {
|
|
2921
|
+
if (!hasUniqueIds2(nextAction.documents.map((document) => document.id))) {
|
|
2899
2922
|
context.addIssue({ code: "custom", path: ["documents"], message: "document ids must be unique" });
|
|
2900
2923
|
}
|
|
2901
2924
|
};
|
|
2902
|
-
var checkKyc = (
|
|
2903
|
-
const fieldIds =
|
|
2925
|
+
var checkKyc = (nextAction, context) => {
|
|
2926
|
+
const fieldIds = nextAction.fields.map((field) => field.id);
|
|
2904
2927
|
if (!hasUniqueIds2(fieldIds)) {
|
|
2905
2928
|
context.addIssue({ code: "custom", path: ["fields"], message: "field ids must be unique" });
|
|
2906
2929
|
}
|
|
2907
|
-
if (
|
|
2908
|
-
context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this
|
|
2930
|
+
if (nextAction.fieldErrors?.some((error) => !fieldIds.includes(error.fieldId))) {
|
|
2931
|
+
context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this next action" });
|
|
2909
2932
|
}
|
|
2910
|
-
if (
|
|
2933
|
+
if (nextAction.fieldErrors?.some((error) => error.code && FIELD_OF_CODE[error.code] !== error.fieldId)) {
|
|
2911
2934
|
context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error code must match its field" });
|
|
2912
2935
|
}
|
|
2913
2936
|
};
|
|
2914
|
-
var
|
|
2915
|
-
var
|
|
2916
|
-
var
|
|
2917
|
-
var
|
|
2918
|
-
var
|
|
2919
|
-
var
|
|
2937
|
+
var MoonPayConsentNextActionSchema = $consentShape.superRefine(checkConsent);
|
|
2938
|
+
var MoonPayConnectNextActionSchema = $connectNextAction;
|
|
2939
|
+
var MoonPayKycNextActionSchema = $kycShape.superRefine(checkKyc);
|
|
2940
|
+
var MoonPayWaitNextActionSchema = $waitNextAction;
|
|
2941
|
+
var MoonPayOrderNextActionSchema = $orderNextAction;
|
|
2942
|
+
var checkNextAction = (response, context) => {
|
|
2920
2943
|
if (response.next === "consent") checkConsent(response, context);
|
|
2921
2944
|
if (response.next === "kyc") checkKyc(response, context);
|
|
2922
2945
|
};
|
|
2923
|
-
var $
|
|
2924
|
-
var $
|
|
2925
|
-
var
|
|
2946
|
+
var $nextActionOptions = [$consentShape, $connectNextAction, $kycShape, $waitNextAction, $orderNextAction];
|
|
2947
|
+
var $nextAction = import_zod2.z.discriminatedUnion("next", [...$nextActionOptions]).superRefine(checkNextAction);
|
|
2948
|
+
var MoonPayNextActionSchema = $nextAction;
|
|
2926
2949
|
var $done = obj2({ next: import_zod2.z.literal("done"), order: FiatStepResponseSchema });
|
|
2927
2950
|
var MoonPayDoneSchema = $done;
|
|
2928
2951
|
var $stepRefused = obj2({
|
|
@@ -2935,9 +2958,9 @@ var $orderRefused = obj2({
|
|
|
2935
2958
|
reason: import_zod2.z.enum(["CUSTOMER_MISMATCH", "WALLET_MISMATCH", "UNRECORDABLE"]),
|
|
2936
2959
|
recovery: import_zod2.z.literal("NONE")
|
|
2937
2960
|
});
|
|
2938
|
-
var $stepResponse2 = import_zod2.z.discriminatedUnion("next", [...$
|
|
2961
|
+
var $stepResponse2 = import_zod2.z.discriminatedUnion("next", [...$nextActionOptions, $stepRefused]).superRefine(checkNextAction);
|
|
2939
2962
|
var MoonPayStepResponseSchema = $stepResponse2;
|
|
2940
|
-
var $orderResponse = import_zod2.z.discriminatedUnion("next", [$done, $
|
|
2963
|
+
var $orderResponse = import_zod2.z.discriminatedUnion("next", [$done, $orderNextAction, $orderRefused]);
|
|
2941
2964
|
var MoonPayOrderResponseSchema = $orderResponse;
|
|
2942
2965
|
var MoonPayResponseSchemaFor = {
|
|
2943
2966
|
observe: MoonPayStepResponseSchema,
|
|
@@ -2947,7 +2970,14 @@ var MoonPayResponseSchemaFor = {
|
|
|
2947
2970
|
order: MoonPayOrderResponseSchema
|
|
2948
2971
|
};
|
|
2949
2972
|
var $faultFields = {
|
|
2950
|
-
reason: import_zod2.z.enum([
|
|
2973
|
+
reason: import_zod2.z.enum([
|
|
2974
|
+
"SESSION_BUDGET_SPENT",
|
|
2975
|
+
"RATE_LIMITED",
|
|
2976
|
+
"PROVIDER_UNAVAILABLE",
|
|
2977
|
+
"KYC_PROVIDER_UNAVAILABLE",
|
|
2978
|
+
"SERVICE_UNAVAILABLE",
|
|
2979
|
+
"INVALID_REQUEST"
|
|
2980
|
+
]),
|
|
2951
2981
|
recovery: import_zod2.z.enum(["RETRY", "REQUOTE", "NONE"])
|
|
2952
2982
|
};
|
|
2953
2983
|
var $fault = obj2($faultFields);
|
package/dist/index.mjs
CHANGED
|
@@ -12,19 +12,19 @@ import {
|
|
|
12
12
|
tableEntry,
|
|
13
13
|
unofferedEndpoints,
|
|
14
14
|
unreachableStates
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-YNVLBTT7.mjs";
|
|
16
16
|
import {
|
|
17
17
|
MOONPAY_ENDPOINTS
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-F4NRKWF5.mjs";
|
|
19
19
|
import {
|
|
20
20
|
FIAT_TERMS_ENDPOINT,
|
|
21
21
|
FUN_KYC_CONSENT_DOCUMENTS,
|
|
22
22
|
PROVIDER_CHECKOUT_DOCUMENTS,
|
|
23
23
|
PUBLISHED_TERMS_DOCUMENTS
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-XKI5XTUO.mjs";
|
|
25
25
|
import {
|
|
26
26
|
ROUTING_ENDPOINTS
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-3SZPKXVL.mjs";
|
|
28
28
|
|
|
29
29
|
// src/codes.ts
|
|
30
30
|
var US_STATE_CODES = [
|
|
@@ -923,6 +923,20 @@ var $routingTableQuery = obj({
|
|
|
923
923
|
)
|
|
924
924
|
}).refine((query) => hasUsRegion(query.country, query.region), { message: US_REGION_REQUIRED, path: ["region"] });
|
|
925
925
|
var FiatRoutingTableQuerySchema = $routingTableQuery;
|
|
926
|
+
var $routingTableProviderInputs = obj({
|
|
927
|
+
MOONPAY: obj({ accessToken: $nonBlank.optional() }).optional()
|
|
928
|
+
});
|
|
929
|
+
var $routingTableRequest = obj({
|
|
930
|
+
fiatCurrencyCode: z.enum(FIAT_CURRENCY_CODES).optional(),
|
|
931
|
+
cryptoCurrencyCode: $nonBlank,
|
|
932
|
+
chainId: $nonBlank,
|
|
933
|
+
country: $countryCode,
|
|
934
|
+
region: $optionalGeoField,
|
|
935
|
+
// Duplicates are allowed; the response lists each method once.
|
|
936
|
+
methods: z.array(z.enum(PAYMENT_METHOD_CATEGORIES)).min(1),
|
|
937
|
+
providers: $routingTableProviderInputs.optional()
|
|
938
|
+
}).refine((request) => hasUsRegion(request.country, request.region), { message: US_REGION_REQUIRED, path: ["region"] });
|
|
939
|
+
var FiatRoutingTableRequestSchema = $routingTableRequest;
|
|
926
940
|
var $routingTableProvider = obj({
|
|
927
941
|
provider: $routingProvider,
|
|
928
942
|
next: z.enum(["READY", "AUTH", "DECLARATIVE_KYC", "DOCUMENTARY_KYC", "PENDING_REVIEW"]),
|
|
@@ -963,7 +977,8 @@ var $routingQuoteTermsShape = {
|
|
|
963
977
|
(geo) => hasUsRegion(geo.alpha2, geo.region),
|
|
964
978
|
{ message: US_REGION_REQUIRED, path: ["region"] }
|
|
965
979
|
),
|
|
966
|
-
prepareSessionAuth: z.boolean().optional()
|
|
980
|
+
prepareSessionAuth: z.boolean().optional(),
|
|
981
|
+
routingOverrides: obj({ providers: z.array($routingProvider) }).optional()
|
|
967
982
|
};
|
|
968
983
|
var $routingQuoteTerms = obj($routingQuoteTermsShape);
|
|
969
984
|
var FiatRoutingQuoteTermsSchema = $routingQuoteTerms;
|
|
@@ -973,7 +988,14 @@ var $routingQuoteRequest = z.union([
|
|
|
973
988
|
providers: z.array($routingProvider).min(1).refine((providers) => hasUniqueIds(providers), "each provider is listed once")
|
|
974
989
|
}),
|
|
975
990
|
obj({ ...$routingQuoteTermsShape, provider: $routingProvider })
|
|
976
|
-
])
|
|
991
|
+
]).refine(
|
|
992
|
+
(request) => {
|
|
993
|
+
const allowed = request.routingOverrides?.providers;
|
|
994
|
+
const selected = "providers" in request ? request.providers : [request.provider];
|
|
995
|
+
return allowed === void 0 || selected.every((provider) => allowed.includes(provider));
|
|
996
|
+
},
|
|
997
|
+
{ message: "requested providers must be allowed by routingOverrides", path: ["routingOverrides"] }
|
|
998
|
+
);
|
|
977
999
|
var FiatRoutingQuoteRequestSchema = $routingQuoteRequest;
|
|
978
1000
|
var $routingServiceableRange = obj({ min: $money, max: $money, userMax: $money.nullable().optional() });
|
|
979
1001
|
var $noRouteFields = {
|
|
@@ -2198,44 +2220,44 @@ var MoonPayNextRequestSchema = $nextRequest2;
|
|
|
2198
2220
|
var FIELD_OF_CODE = { PHONE_IN_USE: "PHONE_NUMBER", TAX_ID_IN_USE: "TAX_IDENTIFIER" };
|
|
2199
2221
|
var $fieldError = obj2({ fieldId: $nonEmpty, message: $nonEmpty, code: z2.enum(["PHONE_IN_USE", "TAX_ID_IN_USE"]).optional() });
|
|
2200
2222
|
var $consentShape = obj2({ next: z2.literal("consent"), documents: z2.array(TermsDocumentSchema).min(1) });
|
|
2201
|
-
var $
|
|
2223
|
+
var $connectNextAction = obj2({
|
|
2202
2224
|
next: z2.literal("connect"),
|
|
2203
2225
|
sessionToken: $nonEmpty,
|
|
2204
2226
|
quoteInput: $quoteInput,
|
|
2205
2227
|
resetConnection: z2.literal(true).optional()
|
|
2206
2228
|
});
|
|
2207
2229
|
var $kycShape = obj2({ next: z2.literal("kyc"), fields: z2.array(FormFieldSchema).min(1), fieldErrors: z2.array($fieldError).min(1).optional() });
|
|
2208
|
-
var $
|
|
2209
|
-
var $
|
|
2210
|
-
var checkConsent = (
|
|
2211
|
-
if (!hasUniqueIds2(
|
|
2230
|
+
var $waitNextAction = obj2({ next: z2.literal("wait"), retryAfterMs: z2.number().int().positive().max(6e4) });
|
|
2231
|
+
var $orderNextAction = obj2({ next: z2.literal("order"), orderId: $nonEmpty, quoteInput: $quoteInput });
|
|
2232
|
+
var checkConsent = (nextAction, context) => {
|
|
2233
|
+
if (!hasUniqueIds2(nextAction.documents.map((document) => document.id))) {
|
|
2212
2234
|
context.addIssue({ code: "custom", path: ["documents"], message: "document ids must be unique" });
|
|
2213
2235
|
}
|
|
2214
2236
|
};
|
|
2215
|
-
var checkKyc = (
|
|
2216
|
-
const fieldIds =
|
|
2237
|
+
var checkKyc = (nextAction, context) => {
|
|
2238
|
+
const fieldIds = nextAction.fields.map((field) => field.id);
|
|
2217
2239
|
if (!hasUniqueIds2(fieldIds)) {
|
|
2218
2240
|
context.addIssue({ code: "custom", path: ["fields"], message: "field ids must be unique" });
|
|
2219
2241
|
}
|
|
2220
|
-
if (
|
|
2221
|
-
context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this
|
|
2242
|
+
if (nextAction.fieldErrors?.some((error) => !fieldIds.includes(error.fieldId))) {
|
|
2243
|
+
context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this next action" });
|
|
2222
2244
|
}
|
|
2223
|
-
if (
|
|
2245
|
+
if (nextAction.fieldErrors?.some((error) => error.code && FIELD_OF_CODE[error.code] !== error.fieldId)) {
|
|
2224
2246
|
context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error code must match its field" });
|
|
2225
2247
|
}
|
|
2226
2248
|
};
|
|
2227
|
-
var
|
|
2228
|
-
var
|
|
2229
|
-
var
|
|
2230
|
-
var
|
|
2231
|
-
var
|
|
2232
|
-
var
|
|
2249
|
+
var MoonPayConsentNextActionSchema = $consentShape.superRefine(checkConsent);
|
|
2250
|
+
var MoonPayConnectNextActionSchema = $connectNextAction;
|
|
2251
|
+
var MoonPayKycNextActionSchema = $kycShape.superRefine(checkKyc);
|
|
2252
|
+
var MoonPayWaitNextActionSchema = $waitNextAction;
|
|
2253
|
+
var MoonPayOrderNextActionSchema = $orderNextAction;
|
|
2254
|
+
var checkNextAction = (response, context) => {
|
|
2233
2255
|
if (response.next === "consent") checkConsent(response, context);
|
|
2234
2256
|
if (response.next === "kyc") checkKyc(response, context);
|
|
2235
2257
|
};
|
|
2236
|
-
var $
|
|
2237
|
-
var $
|
|
2238
|
-
var
|
|
2258
|
+
var $nextActionOptions = [$consentShape, $connectNextAction, $kycShape, $waitNextAction, $orderNextAction];
|
|
2259
|
+
var $nextAction = z2.discriminatedUnion("next", [...$nextActionOptions]).superRefine(checkNextAction);
|
|
2260
|
+
var MoonPayNextActionSchema = $nextAction;
|
|
2239
2261
|
var $done = obj2({ next: z2.literal("done"), order: FiatStepResponseSchema });
|
|
2240
2262
|
var MoonPayDoneSchema = $done;
|
|
2241
2263
|
var $stepRefused = obj2({
|
|
@@ -2248,9 +2270,9 @@ var $orderRefused = obj2({
|
|
|
2248
2270
|
reason: z2.enum(["CUSTOMER_MISMATCH", "WALLET_MISMATCH", "UNRECORDABLE"]),
|
|
2249
2271
|
recovery: z2.literal("NONE")
|
|
2250
2272
|
});
|
|
2251
|
-
var $stepResponse2 = z2.discriminatedUnion("next", [...$
|
|
2273
|
+
var $stepResponse2 = z2.discriminatedUnion("next", [...$nextActionOptions, $stepRefused]).superRefine(checkNextAction);
|
|
2252
2274
|
var MoonPayStepResponseSchema = $stepResponse2;
|
|
2253
|
-
var $orderResponse = z2.discriminatedUnion("next", [$done, $
|
|
2275
|
+
var $orderResponse = z2.discriminatedUnion("next", [$done, $orderNextAction, $orderRefused]);
|
|
2254
2276
|
var MoonPayOrderResponseSchema = $orderResponse;
|
|
2255
2277
|
var MoonPayResponseSchemaFor = {
|
|
2256
2278
|
observe: MoonPayStepResponseSchema,
|
|
@@ -2260,7 +2282,14 @@ var MoonPayResponseSchemaFor = {
|
|
|
2260
2282
|
order: MoonPayOrderResponseSchema
|
|
2261
2283
|
};
|
|
2262
2284
|
var $faultFields = {
|
|
2263
|
-
reason: z2.enum([
|
|
2285
|
+
reason: z2.enum([
|
|
2286
|
+
"SESSION_BUDGET_SPENT",
|
|
2287
|
+
"RATE_LIMITED",
|
|
2288
|
+
"PROVIDER_UNAVAILABLE",
|
|
2289
|
+
"KYC_PROVIDER_UNAVAILABLE",
|
|
2290
|
+
"SERVICE_UNAVAILABLE",
|
|
2291
|
+
"INVALID_REQUEST"
|
|
2292
|
+
]),
|
|
2264
2293
|
recovery: z2.enum(["RETRY", "REQUOTE", "NONE"])
|
|
2265
2294
|
};
|
|
2266
2295
|
var $fault = obj2($faultFields);
|
|
@@ -2298,6 +2327,7 @@ export {
|
|
|
2298
2327
|
FiatRoutingQuoteTermsSchema,
|
|
2299
2328
|
FiatRoutingTableErrorBodySchema,
|
|
2300
2329
|
FiatRoutingTableQuerySchema,
|
|
2330
|
+
FiatRoutingTableRequestSchema,
|
|
2301
2331
|
FiatRoutingTableResponseSchema,
|
|
2302
2332
|
FiatStepResponseSchema,
|
|
2303
2333
|
FiatTermsErrorBodySchema,
|
|
@@ -2323,28 +2353,28 @@ export {
|
|
|
2323
2353
|
KycSdkResultReportSchema,
|
|
2324
2354
|
MOONPAY_ENDPOINTS,
|
|
2325
2355
|
MoonPayCheckoutSchema,
|
|
2326
|
-
|
|
2356
|
+
MoonPayConnectNextActionSchema,
|
|
2327
2357
|
MoonPayConnectRequestSchema,
|
|
2328
|
-
|
|
2358
|
+
MoonPayConsentNextActionSchema,
|
|
2329
2359
|
MoonPayConsentRequestSchema,
|
|
2330
2360
|
MoonPayDoneSchema,
|
|
2331
2361
|
MoonPayErrorBodySchema,
|
|
2332
2362
|
MoonPayFaultSchema,
|
|
2333
|
-
|
|
2363
|
+
MoonPayKycNextActionSchema,
|
|
2334
2364
|
MoonPayKycRequestSchema,
|
|
2365
|
+
MoonPayNextActionSchema,
|
|
2335
2366
|
MoonPayNextRequestSchema,
|
|
2336
2367
|
MoonPayObserveRequestSchema,
|
|
2337
|
-
|
|
2368
|
+
MoonPayOrderNextActionSchema,
|
|
2338
2369
|
MoonPayOrderRequestSchema,
|
|
2339
2370
|
MoonPayOrderResponseSchema,
|
|
2340
|
-
MoonPayPromptSchema,
|
|
2341
2371
|
MoonPayQuoteInputSchema,
|
|
2342
2372
|
MoonPayRequestContextSchema,
|
|
2343
2373
|
MoonPayRequestSchema,
|
|
2344
2374
|
MoonPayResponseSchemaFor,
|
|
2345
2375
|
MoonPaySdkCredentialsSchema,
|
|
2346
2376
|
MoonPayStepResponseSchema,
|
|
2347
|
-
|
|
2377
|
+
MoonPayWaitNextActionSchema,
|
|
2348
2378
|
OrderAwaitingConfirmationStateSchema,
|
|
2349
2379
|
OrderCreatedStateSchema,
|
|
2350
2380
|
OrderRefSchema,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The MoonPay flow on `POST /fiat/next`.
|
|
3
3
|
*
|
|
4
|
-
* Each action has one name and two types. A response
|
|
4
|
+
* Each action has one name and two types. A response names the next action in `next` and carries what
|
|
5
5
|
* the client needs to do it. The client's request names it in `action` and carries the result. Every
|
|
6
|
-
* response is the next
|
|
7
|
-
* result and answers the current
|
|
6
|
+
* response is the next action, `done`, or `refused` (`MoonPayResponseFor`). `observe` carries no
|
|
7
|
+
* result and answers the current next action. `wait` has no request: the client sends `observe` after it.
|
|
8
8
|
*
|
|
9
9
|
* The body is `MoonPayNextRequest`: `provider`, the shared `geo`, the context (`checkout`, and
|
|
10
10
|
* `credentials` after `connect`), and the action's result. Identity and the deposit wallet always
|
|
@@ -69,12 +69,12 @@ export interface MoonPayQuoteInput {
|
|
|
69
69
|
};
|
|
70
70
|
feeBehavior: 'inclusive';
|
|
71
71
|
}
|
|
72
|
-
/** No
|
|
72
|
+
/** No next action of its own: the answer is the current next action. Writes nothing. */
|
|
73
73
|
export type MoonPayObserveRequest = {
|
|
74
74
|
action: 'observe';
|
|
75
75
|
};
|
|
76
76
|
/** MoonPay's terms first. Later, before `kyc`, Fun's KYC consent if the buyer has not accepted it. */
|
|
77
|
-
export type
|
|
77
|
+
export type MoonPayConsentNextAction = {
|
|
78
78
|
next: 'consent';
|
|
79
79
|
documents: TermsDocument[];
|
|
80
80
|
};
|
|
@@ -87,7 +87,7 @@ export type MoonPayConsentRequest = {
|
|
|
87
87
|
* Run MoonPay's connection check with `sessionToken`; it asks for an OTP only if the hidden check
|
|
88
88
|
* fails. `resetConnection`: the device's connection is another buyer's, so reset it first.
|
|
89
89
|
*/
|
|
90
|
-
export type
|
|
90
|
+
export type MoonPayConnectNextAction = {
|
|
91
91
|
next: 'connect';
|
|
92
92
|
sessionToken: string;
|
|
93
93
|
quoteInput: MoonPayQuoteInput;
|
|
@@ -101,7 +101,7 @@ export type MoonPayConnectRequest = {
|
|
|
101
101
|
/** Another MoonPay customer already holds the value; only a different one goes through. */
|
|
102
102
|
export type MoonPayFieldErrorCode = 'PHONE_IN_USE' | 'TAX_ID_IN_USE';
|
|
103
103
|
/**
|
|
104
|
-
* A reason on one field of a `kyc`
|
|
104
|
+
* A reason on one field of a `kyc` next action. `fieldId` names a field in that next action. `code` is set
|
|
105
105
|
* only for a refusal the client words itself: `PHONE_IN_USE` on `PHONE_NUMBER`, `TAX_ID_IN_USE` on `TAX_IDENTIFIER`.
|
|
106
106
|
*/
|
|
107
107
|
export interface MoonPayFieldError {
|
|
@@ -110,24 +110,24 @@ export interface MoonPayFieldError {
|
|
|
110
110
|
code?: MoonPayFieldErrorCode;
|
|
111
111
|
}
|
|
112
112
|
/** Show the shared form. */
|
|
113
|
-
export type
|
|
113
|
+
export type MoonPayKycNextAction = {
|
|
114
114
|
next: 'kyc';
|
|
115
115
|
fields: FormField[];
|
|
116
116
|
fieldErrors?: MoonPayFieldError[];
|
|
117
117
|
};
|
|
118
|
-
/** Keyed by the ids of the
|
|
118
|
+
/** Keyed by the ids of the next action's fields; there is no form id. Needs `credentials`: the backend reads the customer. */
|
|
119
119
|
export type MoonPayKycRequest = {
|
|
120
120
|
action: 'kyc';
|
|
121
121
|
credentials: MoonPaySdkCredentials;
|
|
122
122
|
values: Partial<Record<KycFieldId, string>>;
|
|
123
123
|
};
|
|
124
124
|
/** MoonPay is reviewing. No request of its own: send `observe` after the delay. */
|
|
125
|
-
export type
|
|
125
|
+
export type MoonPayWaitNextAction = {
|
|
126
126
|
next: 'wait';
|
|
127
127
|
retryAfterMs: number;
|
|
128
128
|
};
|
|
129
129
|
/** Get the device quote from `quoteInput`, mount Apple Pay with `externalTransactionId = orderId`. */
|
|
130
|
-
export type
|
|
130
|
+
export type MoonPayOrderNextAction = {
|
|
131
131
|
next: 'order';
|
|
132
132
|
orderId: string;
|
|
133
133
|
quoteInput: MoonPayQuoteInput;
|
|
@@ -157,7 +157,7 @@ export type MoonPayStepRefusal = 'NOT_ELIGIBLE' | 'DOCUMENTS_REQUIRED' | 'FINAL_
|
|
|
157
157
|
* assertion's. `UNRECORDABLE`: a charge no retry can record, held for refund review.
|
|
158
158
|
*/
|
|
159
159
|
export type MoonPayOrderRefusal = 'CUSTOMER_MISMATCH' | 'WALLET_MISMATCH' | 'UNRECORDABLE';
|
|
160
|
-
export type
|
|
160
|
+
export type MoonPayNextAction = MoonPayConsentNextAction | MoonPayConnectNextAction | MoonPayKycNextAction | MoonPayWaitNextAction | MoonPayOrderNextAction;
|
|
161
161
|
/** `order` is the `GET /fiat/orders/:orderId` body; the shared order screen renders it. */
|
|
162
162
|
export type MoonPayDone = {
|
|
163
163
|
next: 'done';
|
|
@@ -170,13 +170,13 @@ export type MoonPayRefused<R, V> = {
|
|
|
170
170
|
recovery: V;
|
|
171
171
|
};
|
|
172
172
|
/** The answer to `observe`, `consent`, `connect` and `kyc`. */
|
|
173
|
-
export type MoonPayStepResponse =
|
|
173
|
+
export type MoonPayStepResponse = MoonPayNextAction | MoonPayRefused<MoonPayStepRefusal, 'REQUOTE' | 'NONE'>;
|
|
174
174
|
/**
|
|
175
175
|
* The answer to `order`. A failed charge is recorded too: `done` with the order in `FAILED`, and the
|
|
176
176
|
* client requotes for a new `orderId`. `order` again while MoonPay does not list the transaction
|
|
177
177
|
* yet. A refusal after a charge never requotes: that would start a second payment.
|
|
178
178
|
*/
|
|
179
|
-
export type MoonPayOrderResponse = MoonPayDone |
|
|
179
|
+
export type MoonPayOrderResponse = MoonPayDone | MoonPayOrderNextAction | MoonPayRefused<MoonPayOrderRefusal, 'NONE'>;
|
|
180
180
|
export type MoonPayResponseFor = {
|
|
181
181
|
observe: MoonPayStepResponse;
|
|
182
182
|
consent: MoonPayStepResponse;
|
|
@@ -188,10 +188,11 @@ export type MoonPayResponseFor = {
|
|
|
188
188
|
export type MoonPayRecovery = 'RETRY' | 'REQUOTE' | 'NONE';
|
|
189
189
|
/**
|
|
190
190
|
* `SESSION_BUDGET_SPENT`: the per-login SDK session mint budget (429). `RATE_LIMITED`: the action's
|
|
191
|
-
* request budget (429). `PROVIDER_UNAVAILABLE`: MoonPay
|
|
192
|
-
*
|
|
191
|
+
* request budget (429). `PROVIDER_UNAVAILABLE`: MoonPay is down (503). `KYC_PROVIDER_UNAVAILABLE`:
|
|
192
|
+
* the KYC provider (Sumsub) is down (503). `SERVICE_UNAVAILABLE`: one of Fun's own stores is down
|
|
193
|
+
* (503). `INVALID_REQUEST`: a bad body (400).
|
|
193
194
|
*/
|
|
194
|
-
export type MoonPayFaultReason = 'SESSION_BUDGET_SPENT' | 'RATE_LIMITED' | 'PROVIDER_UNAVAILABLE' | 'INVALID_REQUEST';
|
|
195
|
+
export type MoonPayFaultReason = 'SESSION_BUDGET_SPENT' | 'RATE_LIMITED' | 'PROVIDER_UNAVAILABLE' | 'KYC_PROVIDER_UNAVAILABLE' | 'SERVICE_UNAVAILABLE' | 'INVALID_REQUEST';
|
|
195
196
|
/** The fields a MoonPay fault adds to the shared error body. */
|
|
196
197
|
export interface MoonPayFault {
|
|
197
198
|
reason: MoonPayFaultReason;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* exported from the package root, never from `./moonpay`, so the production entry stays free of zod.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import type { MoonPayCheckout,
|
|
6
|
+
import type { MoonPayCheckout, MoonPayConnectNextAction, MoonPayConnectRequest, MoonPayConsentNextAction, MoonPayConsentRequest, MoonPayDone, MoonPayErrorBody, MoonPayFault, MoonPayKycNextAction, MoonPayKycRequest, MoonPayNextRequest, MoonPayObserveRequest, MoonPayOrderNextAction, MoonPayOrderRequest, MoonPayOrderResponse, MoonPayNextAction, MoonPayQuoteInput, MoonPayRequest, MoonPayRequestContext, MoonPayResponseFor, MoonPaySdkCredentials, MoonPayStepResponse, MoonPayWaitNextAction } from './moonpay';
|
|
7
7
|
export declare const MoonPayCheckoutSchema: z.ZodType<MoonPayCheckout>;
|
|
8
8
|
export declare const MoonPaySdkCredentialsSchema: z.ZodType<MoonPaySdkCredentials>;
|
|
9
9
|
export declare const MoonPayRequestContextSchema: z.ZodType<MoonPayRequestContext>;
|
|
@@ -15,12 +15,12 @@ export declare const MoonPayKycRequestSchema: z.ZodType<MoonPayRequestContext &
|
|
|
15
15
|
export declare const MoonPayOrderRequestSchema: z.ZodType<MoonPayRequestContext & MoonPayOrderRequest>;
|
|
16
16
|
export declare const MoonPayRequestSchema: z.ZodType<MoonPayRequest>;
|
|
17
17
|
export declare const MoonPayNextRequestSchema: z.ZodType<MoonPayNextRequest>;
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
18
|
+
export declare const MoonPayConsentNextActionSchema: z.ZodType<MoonPayConsentNextAction>;
|
|
19
|
+
export declare const MoonPayConnectNextActionSchema: z.ZodType<MoonPayConnectNextAction>;
|
|
20
|
+
export declare const MoonPayKycNextActionSchema: z.ZodType<MoonPayKycNextAction>;
|
|
21
|
+
export declare const MoonPayWaitNextActionSchema: z.ZodType<MoonPayWaitNextAction>;
|
|
22
|
+
export declare const MoonPayOrderNextActionSchema: z.ZodType<MoonPayOrderNextAction>;
|
|
23
|
+
export declare const MoonPayNextActionSchema: z.ZodType<MoonPayNextAction>;
|
|
24
24
|
export declare const MoonPayDoneSchema: z.ZodType<MoonPayDone>;
|
|
25
25
|
export declare const MoonPayStepResponseSchema: z.ZodType<MoonPayStepResponse>;
|
|
26
26
|
export declare const MoonPayOrderResponseSchema: z.ZodType<MoonPayOrderResponse>;
|
package/dist/routing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The routing table: `
|
|
2
|
+
* The routing table: `POST /fiat/routing/table` and `POST /fiat/routing/quote`.
|
|
3
3
|
*
|
|
4
4
|
* The client loads the table when the sheet opens. For each payment method it lists every amount
|
|
5
5
|
* interval and the providers that serve it, best first, each with what it needs from the buyer next.
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* The table is advisory: every routing quote checks the named provider's eligibility again. Refetch it
|
|
11
11
|
* at `expiresAt`, on `refreshLimits: true`, and after auth, KYC or a `REQUOTE` refusal.
|
|
12
12
|
*
|
|
13
|
+
* Provider inputs are optional; see `FiatRoutingTableMoonPayInputs` for credential handling.
|
|
14
|
+
* Malformed inputs and unknown keys return 400. Deploy backend support before new provider keys.
|
|
15
|
+
*
|
|
13
16
|
* Changes to both routes only add fields and enum values. Map an unknown `next` to the generic
|
|
14
17
|
* Continue label.
|
|
15
18
|
*
|
|
@@ -20,15 +23,45 @@
|
|
|
20
23
|
import type { CountryCode, FiatCurrencyCode, PaymentMethodCategory } from './codes';
|
|
21
24
|
import type { FiatAmount, FiatProvider, QuoteLimitRange } from './types';
|
|
22
25
|
export declare const ROUTING_ENDPOINTS: {
|
|
23
|
-
readonly table: "
|
|
26
|
+
readonly table: "POST /fiat/routing/table";
|
|
24
27
|
/** Temporary: `POST /fiat/next` replaces it for each provider that moves there. */
|
|
25
28
|
readonly quote: "POST /fiat/routing/quote";
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
31
|
+
* MoonPay SDK access token (`client.getCredentials().accessToken`). The backend uses the
|
|
32
|
+
* authenticated quote's remaining limits, bounded by corridor limits. Missing, expired or
|
|
33
|
+
* provider-rejected tokens use corridor limits. Omit blank tokens. Sent in the body; never logged.
|
|
34
|
+
*/
|
|
35
|
+
export interface FiatRoutingTableMoonPayInputs {
|
|
36
|
+
accessToken?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Provider-specific inputs, keyed by `RoutingProvider`. All keys and fields are optional. */
|
|
39
|
+
export interface FiatRoutingTableProviderInputs {
|
|
40
|
+
MOONPAY?: FiatRoutingTableMoonPayInputs;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The body of `POST /fiat/routing/table`. `country` and `region` are the geo endpoint's `alpha2`
|
|
44
|
+
* and `region`, held to the `POST /fiat/quote` geo rules: a US buyer's `region` must be a
|
|
30
45
|
* `UsStateCode`, and an empty `region` counts as absent.
|
|
31
46
|
*/
|
|
47
|
+
export interface FiatRoutingTableRequest {
|
|
48
|
+
/** Defaults to `USD`. */
|
|
49
|
+
fiatCurrencyCode?: FiatCurrencyCode;
|
|
50
|
+
cryptoCurrencyCode: string;
|
|
51
|
+
chainId: string;
|
|
52
|
+
country: CountryCode;
|
|
53
|
+
region?: string;
|
|
54
|
+
/** At least one. The response lists each once, in this order. */
|
|
55
|
+
methods: PaymentMethodCategory[];
|
|
56
|
+
/** Optional provider-specific inputs. */
|
|
57
|
+
providers?: FiatRoutingTableProviderInputs;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The query string of `GET /fiat/routing/table`, which `POST /fiat/routing/table` replaces.
|
|
61
|
+
*
|
|
62
|
+
* @deprecated Send a `FiatRoutingTableRequest` to `ROUTING_ENDPOINTS.table`. The GET route still
|
|
63
|
+
* answers while clients move, with no provider inputs.
|
|
64
|
+
*/
|
|
32
65
|
export interface FiatRoutingTableQuery {
|
|
33
66
|
/** Defaults to `USD`. */
|
|
34
67
|
fiatCurrencyCode?: FiatCurrencyCode;
|
|
@@ -82,7 +115,7 @@ export interface FiatRoutingTableResponse {
|
|
|
82
115
|
/** In request order, duplicates removed. */
|
|
83
116
|
methods: RoutingTableMethod[];
|
|
84
117
|
}
|
|
85
|
-
/** The
|
|
118
|
+
/** The purchase terms and optional host restriction, independent of the current ordered candidates. */
|
|
86
119
|
export interface FiatRoutingQuoteTerms {
|
|
87
120
|
fiatCurrency: FiatCurrencyCode;
|
|
88
121
|
/** A positive decimal string with no leading zero, exponent or sign (`"20"`, `"20.5"`). */
|
|
@@ -101,6 +134,10 @@ export interface FiatRoutingQuoteTerms {
|
|
|
101
134
|
city?: string;
|
|
102
135
|
};
|
|
103
136
|
prepareSessionAuth?: boolean;
|
|
137
|
+
/** Host allowlist, retained for later KYC rerouting. Omitted allows every eligible provider. */
|
|
138
|
+
routingOverrides?: {
|
|
139
|
+
providers: RoutingProvider[];
|
|
140
|
+
};
|
|
104
141
|
}
|
|
105
142
|
/**
|
|
106
143
|
* `POST /fiat/routing/quote`: the terms plus which providers to price, in one of two forms.
|
|
@@ -170,7 +207,7 @@ export type RoutingRateLimitedErrorBody = ErrorBodyFields & {
|
|
|
170
207
|
export type RoutingFaultErrorBody = ErrorBodyFields & {
|
|
171
208
|
errorCode: string;
|
|
172
209
|
};
|
|
173
|
-
/**
|
|
210
|
+
/** Error bodies for the routing table endpoint (POST and deprecated GET). */
|
|
174
211
|
export type FiatRoutingTableErrorBody = RoutingRateLimitedErrorBody | RoutingFaultErrorBody;
|
|
175
212
|
/**
|
|
176
213
|
* `POST /fiat/routing/quote` refusals. A `FiatNoRouteError` (any `reason`) or either amount error is
|
package/dist/routing.js
CHANGED
|
@@ -24,7 +24,7 @@ __export(routing_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(routing_exports);
|
|
26
26
|
var ROUTING_ENDPOINTS = {
|
|
27
|
-
table: "
|
|
27
|
+
table: "POST /fiat/routing/table",
|
|
28
28
|
/** Temporary: `POST /fiat/next` replaces it for each provider that moves there. */
|
|
29
29
|
quote: "POST /fiat/routing/quote"
|
|
30
30
|
};
|
package/dist/routing.mjs
CHANGED
package/dist/schemas.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { z } from 'zod';
|
|
|
30
30
|
import type { UsStateCode } from './codes';
|
|
31
31
|
import type { BlockedReason, CryptoAmount, FailureReason, FeeLine, FiatAmount, FiatEndpoint, FiatProvider, FiatStepResponse, FieldSpec, FlowState, FormDescriptor, FormField, FormFieldType, InstructionField, Instructions, Instrument, JsonValue, KYCProvider, OrderRef, OrderStatus, OrderSummary, PollSpec, PreparedPayment, PaymentSurface, Quote, QuoteLimitRange, QuoteLimits, Recovery, Refund, ReportSpec, SelectOption, StatusHistoryEntry, Surface, PreferredIdentityDocument, KycFieldId, ClientExecutedDelivery, KycSdkResultReport, SurfaceKind, SurfaceProvider, TermsAcceptance, Transition, TransitionInputs, TransitionParams, Tx, FiatGeo, FiatNextRequest } from './types';
|
|
32
32
|
import type { FiatTermsErrorBody, FiatTermsRequest, FiatTermsResponse, TermsDocument, TermsDocumentAcceptance } from './terms';
|
|
33
|
-
import type { FiatRoutingQuoteErrorBody, FiatRoutingQuoteRequest, FiatRoutingQuoteTerms, FiatRoutingTableErrorBody, FiatRoutingTableQuery, FiatRoutingTableResponse } from './routing';
|
|
33
|
+
import type { FiatRoutingQuoteErrorBody, FiatRoutingQuoteRequest, FiatRoutingQuoteTerms, FiatRoutingTableErrorBody, FiatRoutingTableQuery, FiatRoutingTableRequest, FiatRoutingTableResponse } from './routing';
|
|
34
34
|
export declare const JsonSchema: z.ZodType<JsonValue>;
|
|
35
35
|
export declare const HTTP_VERBS: readonly ["GET", "POST"];
|
|
36
36
|
/** `"POST /fiat/session/verify"`, `"GET /fiat/orders/o_31c"` — the verb rides the string. */
|
|
@@ -112,7 +112,9 @@ export declare const TermsDocumentAcceptanceSchema: z.ZodType<TermsDocumentAccep
|
|
|
112
112
|
export declare const FiatTermsRequestSchema: z.ZodType<FiatTermsRequest>;
|
|
113
113
|
export declare const FiatTermsResponseSchema: z.ZodType<FiatTermsResponse>;
|
|
114
114
|
export declare const FiatTermsErrorBodySchema: z.ZodType<FiatTermsErrorBody>;
|
|
115
|
+
/** @deprecated `GET /fiat/routing/table` is replaced by `POST /fiat/routing/table` (`FiatRoutingTableRequestSchema`). */
|
|
115
116
|
export declare const FiatRoutingTableQuerySchema: z.ZodType<FiatRoutingTableQuery>;
|
|
117
|
+
export declare const FiatRoutingTableRequestSchema: z.ZodType<FiatRoutingTableRequest>;
|
|
116
118
|
export declare const FiatRoutingTableResponseSchema: z.ZodType<FiatRoutingTableResponse>;
|
|
117
119
|
export declare const FiatRoutingQuoteTermsSchema: z.ZodType<FiatRoutingQuoteTerms>;
|
|
118
120
|
export declare const FiatRoutingQuoteRequestSchema: z.ZodType<FiatRoutingQuoteRequest>;
|
package/dist/table.js
CHANGED
package/dist/table.mjs
CHANGED
package/dist/terms.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The platform terms route: `POST /fiat/terms`, shared by every provider.
|
|
3
3
|
*
|
|
4
4
|
* A checkout shows the user documents to accept. `CHECKOUT` documents are the constants below;
|
|
5
|
-
* `KYC` documents arrive in a provider flow's consent
|
|
5
|
+
* `KYC` documents arrive in a provider flow's consent next action. The user's Continue tap is the
|
|
6
6
|
* acceptance, and the client records it here before the next provider call. A repeat writes nothing.
|
|
7
7
|
*
|
|
8
8
|
* Zero runtime dependencies, so production React Native code can import it. The zod schemas are
|
package/dist/terms.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fun-xyz/fiat-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Published conformance contract for Fun's headless fiat onramp: FlowState/Transition types, zod schemas, the transition table as data, recorded fixtures, assertion helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|