@fun-xyz/fiat-contract 0.23.0 → 0.25.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/dist/index.mjs CHANGED
@@ -12,19 +12,19 @@ import {
12
12
  tableEntry,
13
13
  unofferedEndpoints,
14
14
  unreachableStates
15
- } from "./chunk-EI56NQ7K.mjs";
15
+ } from "./chunk-LHCED3AP.mjs";
16
16
  import {
17
17
  MOONPAY_ENDPOINTS
18
- } from "./chunk-3HCZ6JBJ.mjs";
18
+ } from "./chunk-T5JAYOWY.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-5GRPYE2U.mjs";
24
+ } from "./chunk-CRNKRIKR.mjs";
25
25
  import {
26
26
  ROUTING_ENDPOINTS
27
- } from "./chunk-KYE2HYV5.mjs";
27
+ } from "./chunk-WEXD7UEE.mjs";
28
28
 
29
29
  // src/codes.ts
30
30
  var US_STATE_CODES = [
@@ -953,8 +953,7 @@ var $routingTableResponse = obj({
953
953
  methods: z.array($routingTableMethod).refine((methods) => hasUniqueIds(methods.map((entry) => entry.method)), "each method is listed once")
954
954
  });
955
955
  var FiatRoutingTableResponseSchema = $routingTableResponse;
956
- var $routingQuoteRequest = obj({
957
- provider: $routingProvider,
956
+ var $routingQuoteTermsShape = {
958
957
  fiatCurrency: z.enum(FIAT_CURRENCY_CODES),
959
958
  fiatAmount: $decimalAmount.refine((amount) => Number(amount) > 0, "must be positive"),
960
959
  cryptoCurrencyCode: $nonBlank,
@@ -965,7 +964,16 @@ var $routingQuoteRequest = obj({
965
964
  { message: US_REGION_REQUIRED, path: ["region"] }
966
965
  ),
967
966
  prepareSessionAuth: z.boolean().optional()
968
- });
967
+ };
968
+ var $routingQuoteTerms = obj($routingQuoteTermsShape);
969
+ var FiatRoutingQuoteTermsSchema = $routingQuoteTerms;
970
+ var $routingQuoteRequest = z.union([
971
+ obj({
972
+ ...$routingQuoteTermsShape,
973
+ providers: z.array($routingProvider).min(1).refine((providers) => hasUniqueIds(providers), "each provider is listed once")
974
+ }),
975
+ obj({ ...$routingQuoteTermsShape, provider: $routingProvider })
976
+ ]);
969
977
  var FiatRoutingQuoteRequestSchema = $routingQuoteRequest;
970
978
  var $routingServiceableRange = obj({ min: $money, max: $money, userMax: $money.nullable().optional() });
971
979
  var $noRouteFields = {
@@ -1002,6 +1010,10 @@ var $routingTableErrorBody = z.union([$routingRateLimitedErrorBody, $routingFaul
1002
1010
  var FiatRoutingTableErrorBodySchema = $routingTableErrorBody;
1003
1011
  var $routingQuoteErrorBody = z.union([$routingNoRouteErrorBody, $routingAmountErrorBody, $routingFaultErrorBody]);
1004
1012
  var FiatRoutingQuoteErrorBodySchema = $routingQuoteErrorBody;
1013
+ var $fiatGeo = obj({ alpha2: z.string().regex(/^[A-Z]{2}$/), region: $nonBlank.optional(), ip: $nonBlank.optional() });
1014
+ var FiatGeoSchema = $fiatGeo;
1015
+ var $nextRequest = z.object({ provider: $provider, action: $nonBlank, geo: $fiatGeo }).catchall(z.unknown());
1016
+ var FiatNextRequestSchema = $nextRequest;
1005
1017
  var $providerBoundStepResponse = obj({
1006
1018
  state: $providerBoundFlowState,
1007
1019
  provider: $provider,
@@ -2131,33 +2143,17 @@ var FIAT_CURRENCY_CODES2 = Object.keys(FIAT_CURRENCY_NAMES);
2131
2143
  var obj2 = (shape) => z2.object(shape).strict();
2132
2144
  var $nonEmpty = z2.string().refine((value) => value.trim().length > 0, "must not be blank");
2133
2145
  var hasUniqueIds2 = (ids) => new Set(ids).size === ids.length;
2134
- var $geo = obj2({ alpha2: z2.string().regex(/^[A-Z]{2}$/), region: $nonEmpty.optional(), ip: $nonEmpty.optional() });
2135
2146
  var $checkout = obj2({
2136
2147
  amount: FiatAmountSchema,
2137
2148
  destination: obj2({ asset: $nonEmpty, network: $nonEmpty }),
2138
- paymentMethod: z2.literal("apple_pay"),
2139
- geo: $geo
2149
+ paymentMethod: z2.literal("apple_pay")
2140
2150
  });
2141
2151
  var MoonPayCheckoutSchema = $checkout;
2142
2152
  var $credentials = obj2({ customerId: $nonEmpty, accessToken: $nonEmpty });
2143
2153
  var MoonPaySdkCredentialsSchema = $credentials;
2144
- var $intentRequest = z2.discriminatedUnion("kind", [
2145
- obj2({ kind: z2.literal("observe"), checkout: $checkout, credentials: $credentials.optional() }),
2146
- obj2({
2147
- kind: z2.literal("kyc"),
2148
- checkout: $checkout,
2149
- credentials: $credentials,
2150
- values: z2.record(KycFieldIdSchema, z2.string()).refine((values) => Object.keys(values).length > 0, "values must not be empty")
2151
- }),
2152
- obj2({
2153
- kind: z2.literal("order"),
2154
- orderId: $nonEmpty,
2155
- transactionId: $nonEmpty.optional(),
2156
- quotedAmount: FiatAmountSchema,
2157
- geo: $geo.optional()
2158
- })
2159
- ]);
2160
- var MoonPayIntentRequestSchema = $intentRequest;
2154
+ var $context = { checkout: $checkout, credentials: $credentials.optional() };
2155
+ var $requestContext = obj2($context);
2156
+ var MoonPayRequestContextSchema = $requestContext;
2161
2157
  var $quoteInput = obj2({
2162
2158
  source: obj2({ asset: obj2({ code: z2.enum(FIAT_CURRENCY_CODES2) }), amount: $nonEmpty }),
2163
2159
  destination: obj2({ asset: obj2({ code: $nonEmpty }) }),
@@ -2166,50 +2162,103 @@ var $quoteInput = obj2({
2166
2162
  feeBehavior: z2.literal("inclusive")
2167
2163
  });
2168
2164
  var MoonPayQuoteInputSchema = $quoteInput;
2169
- var $stepRefusal = z2.enum(["NOT_ELIGIBLE", "DOCUMENTS_REQUIRED", "FINAL_REJECTION", "CUSTOMER_MISMATCH"]);
2170
- var $orderRefusal = z2.enum(["CUSTOMER_MISMATCH", "WALLET_MISMATCH", "UNRECORDABLE"]);
2165
+ var $observeFields = { action: z2.literal("observe") };
2166
+ var $consentFields = {
2167
+ action: z2.literal("consent"),
2168
+ acceptances: z2.array(TermsDocumentAcceptanceSchema).min(1).refine((acceptances) => hasUniqueIds2(acceptances.map((acceptance) => acceptance.documentId)), "each document is accepted once")
2169
+ };
2170
+ var $connectFields = { action: z2.literal("connect"), customerId: $nonEmpty, accessToken: $nonEmpty };
2171
+ var $kycFields = {
2172
+ action: z2.literal("kyc"),
2173
+ credentials: $credentials,
2174
+ values: z2.record(KycFieldIdSchema, z2.string()).refine((values) => Object.keys(values).length > 0, "values must not be empty")
2175
+ };
2176
+ var $orderFields = { action: z2.literal("order"), orderId: $nonEmpty, quotedAmount: FiatAmountSchema, transactionId: $nonEmpty.optional() };
2177
+ var $observeRequest = obj2({ ...$context, ...$observeFields });
2178
+ var $consentRequest = obj2({ ...$context, ...$consentFields });
2179
+ var $connectRequest = obj2({ ...$context, ...$connectFields });
2180
+ var $kycRequest = obj2({ ...$context, ...$kycFields });
2181
+ var $orderRequest = obj2({ ...$context, ...$orderFields });
2182
+ var MoonPayObserveRequestSchema = $observeRequest;
2183
+ var MoonPayConsentRequestSchema = $consentRequest;
2184
+ var MoonPayConnectRequestSchema = $connectRequest;
2185
+ var MoonPayKycRequestSchema = $kycRequest;
2186
+ var MoonPayOrderRequestSchema = $orderRequest;
2187
+ var $request = z2.discriminatedUnion("action", [$observeRequest, $consentRequest, $connectRequest, $kycRequest, $orderRequest]);
2188
+ var MoonPayRequestSchema = $request;
2189
+ var $envelope = { provider: z2.literal("MOONPAY"), geo: FiatGeoSchema, ...$context };
2190
+ var $nextRequest2 = z2.discriminatedUnion("action", [
2191
+ obj2({ ...$envelope, ...$observeFields }),
2192
+ obj2({ ...$envelope, ...$consentFields }),
2193
+ obj2({ ...$envelope, ...$connectFields }),
2194
+ obj2({ ...$envelope, ...$kycFields }),
2195
+ obj2({ ...$envelope, ...$orderFields })
2196
+ ]);
2197
+ var MoonPayNextRequestSchema = $nextRequest2;
2171
2198
  var FIELD_OF_CODE = { PHONE_IN_USE: "PHONE_NUMBER", TAX_ID_IN_USE: "TAX_IDENTIFIER" };
2172
2199
  var $fieldError = obj2({ fieldId: $nonEmpty, message: $nonEmpty, code: z2.enum(["PHONE_IN_USE", "TAX_ID_IN_USE"]).optional() });
2173
- var $pending = obj2({ status: z2.literal("PENDING"), retryAfterMs: z2.number().int().positive().max(6e4) });
2174
- var $stepStatus = z2.discriminatedUnion("status", [
2175
- obj2({ status: z2.literal("TERMS"), stage: z2.enum(["CHECKOUT", "KYC"]), documents: z2.array(TermsDocumentSchema).min(1) }),
2176
- obj2({ status: z2.literal("SDK_AUTH"), sessionToken: $nonEmpty, quoteInput: $quoteInput, resetConnection: z2.literal(true).optional() }),
2177
- obj2({ status: z2.literal("KYC"), fields: z2.array(FormFieldSchema).min(1), fieldErrors: z2.array($fieldError).min(1).optional() }),
2178
- $pending,
2179
- obj2({ status: z2.literal("READY"), orderId: $nonEmpty, quoteInput: $quoteInput }),
2180
- obj2({ status: z2.literal("REFUSED"), reason: $stepRefusal, recovery: z2.enum(["REQUOTE", "NONE"]) })
2181
- ]);
2182
- var $stepResponse2 = $stepStatus.superRefine((response, context) => {
2183
- if (response.status === "TERMS") {
2184
- if (!hasUniqueIds2(response.documents.map((document) => document.id))) {
2185
- context.addIssue({ code: "custom", path: ["documents"], message: "document ids must be unique" });
2186
- }
2187
- if (response.documents.some((document) => document.stage !== response.stage)) {
2188
- context.addIssue({ code: "custom", path: ["documents"], message: "every document must be at the response stage" });
2189
- }
2200
+ var $consentShape = obj2({ next: z2.literal("consent"), documents: z2.array(TermsDocumentSchema).min(1) });
2201
+ var $connectPrompt = obj2({
2202
+ next: z2.literal("connect"),
2203
+ sessionToken: $nonEmpty,
2204
+ quoteInput: $quoteInput,
2205
+ resetConnection: z2.literal(true).optional()
2206
+ });
2207
+ var $kycShape = obj2({ next: z2.literal("kyc"), fields: z2.array(FormFieldSchema).min(1), fieldErrors: z2.array($fieldError).min(1).optional() });
2208
+ var $waitPrompt = obj2({ next: z2.literal("wait"), retryAfterMs: z2.number().int().positive().max(6e4) });
2209
+ var $orderPrompt = obj2({ next: z2.literal("order"), orderId: $nonEmpty, quoteInput: $quoteInput });
2210
+ var checkConsent = (prompt, context) => {
2211
+ if (!hasUniqueIds2(prompt.documents.map((document) => document.id))) {
2212
+ context.addIssue({ code: "custom", path: ["documents"], message: "document ids must be unique" });
2190
2213
  }
2191
- if (response.status === "KYC") {
2192
- const fieldIds = response.fields.map((field) => field.id);
2193
- if (!hasUniqueIds2(fieldIds)) {
2194
- context.addIssue({ code: "custom", path: ["fields"], message: "field ids must be unique" });
2195
- }
2196
- if (response.fieldErrors?.some((error) => !fieldIds.includes(error.fieldId))) {
2197
- context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this response" });
2198
- }
2199
- if (response.fieldErrors?.some((error) => error.code && FIELD_OF_CODE[error.code] !== error.fieldId)) {
2200
- context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error code must match its field" });
2201
- }
2214
+ };
2215
+ var checkKyc = (prompt, context) => {
2216
+ const fieldIds = prompt.fields.map((field) => field.id);
2217
+ if (!hasUniqueIds2(fieldIds)) {
2218
+ context.addIssue({ code: "custom", path: ["fields"], message: "field ids must be unique" });
2219
+ }
2220
+ if (prompt.fieldErrors?.some((error) => !fieldIds.includes(error.fieldId))) {
2221
+ context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this prompt" });
2202
2222
  }
2223
+ if (prompt.fieldErrors?.some((error) => error.code && FIELD_OF_CODE[error.code] !== error.fieldId)) {
2224
+ context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error code must match its field" });
2225
+ }
2226
+ };
2227
+ var MoonPayConsentPromptSchema = $consentShape.superRefine(checkConsent);
2228
+ var MoonPayConnectPromptSchema = $connectPrompt;
2229
+ var MoonPayKycPromptSchema = $kycShape.superRefine(checkKyc);
2230
+ var MoonPayWaitPromptSchema = $waitPrompt;
2231
+ var MoonPayOrderPromptSchema = $orderPrompt;
2232
+ var checkPrompt = (response, context) => {
2233
+ if (response.next === "consent") checkConsent(response, context);
2234
+ if (response.next === "kyc") checkKyc(response, context);
2235
+ };
2236
+ var $promptOptions = [$consentShape, $connectPrompt, $kycShape, $waitPrompt, $orderPrompt];
2237
+ var $prompt = z2.discriminatedUnion("next", [...$promptOptions]).superRefine(checkPrompt);
2238
+ var MoonPayPromptSchema = $prompt;
2239
+ var $done = obj2({ next: z2.literal("done"), order: FiatStepResponseSchema });
2240
+ var MoonPayDoneSchema = $done;
2241
+ var $stepRefused = obj2({
2242
+ next: z2.literal("refused"),
2243
+ reason: z2.enum(["NOT_ELIGIBLE", "DOCUMENTS_REQUIRED", "FINAL_REJECTION", "CUSTOMER_MISMATCH"]),
2244
+ recovery: z2.enum(["REQUOTE", "NONE"])
2203
2245
  });
2246
+ var $orderRefused = obj2({
2247
+ next: z2.literal("refused"),
2248
+ reason: z2.enum(["CUSTOMER_MISMATCH", "WALLET_MISMATCH", "UNRECORDABLE"]),
2249
+ recovery: z2.literal("NONE")
2250
+ });
2251
+ var $stepResponse2 = z2.discriminatedUnion("next", [...$promptOptions, $stepRefused]).superRefine(checkPrompt);
2204
2252
  var MoonPayStepResponseSchema = $stepResponse2;
2205
- var $orderResponse = z2.discriminatedUnion("status", [
2206
- obj2({ status: z2.literal("DONE"), order: FiatStepResponseSchema }),
2207
- $pending,
2208
- obj2({ status: z2.literal("REFUSED"), reason: $orderRefusal, recovery: z2.literal("NONE") })
2209
- ]);
2253
+ var $orderResponse = z2.discriminatedUnion("next", [$done, $orderPrompt, $orderRefused]);
2210
2254
  var MoonPayOrderResponseSchema = $orderResponse;
2211
- var $intentResponse = z2.union([$stepResponse2, $orderResponse]);
2212
- var MoonPayIntentResponseSchema = $intentResponse;
2255
+ var MoonPayResponseSchemaFor = {
2256
+ observe: MoonPayStepResponseSchema,
2257
+ consent: MoonPayStepResponseSchema,
2258
+ connect: MoonPayStepResponseSchema,
2259
+ kyc: MoonPayStepResponseSchema,
2260
+ order: MoonPayOrderResponseSchema
2261
+ };
2213
2262
  var $faultFields = {
2214
2263
  reason: z2.enum(["SESSION_BUDGET_SPENT", "RATE_LIMITED", "PROVIDER_UNAVAILABLE", "INVALID_REQUEST"]),
2215
2264
  recovery: z2.enum(["RETRY", "REQUOTE", "NONE"])
@@ -2241,9 +2290,12 @@ export {
2241
2290
  FiatAmountSchema,
2242
2291
  FiatCurrencyCode,
2243
2292
  FiatEndpointSchema,
2293
+ FiatGeoSchema,
2294
+ FiatNextRequestSchema,
2244
2295
  FiatProviderSchema,
2245
2296
  FiatRoutingQuoteErrorBodySchema,
2246
2297
  FiatRoutingQuoteRequestSchema,
2298
+ FiatRoutingQuoteTermsSchema,
2247
2299
  FiatRoutingTableErrorBodySchema,
2248
2300
  FiatRoutingTableQuerySchema,
2249
2301
  FiatRoutingTableResponseSchema,
@@ -2271,14 +2323,28 @@ export {
2271
2323
  KycSdkResultReportSchema,
2272
2324
  MOONPAY_ENDPOINTS,
2273
2325
  MoonPayCheckoutSchema,
2326
+ MoonPayConnectPromptSchema,
2327
+ MoonPayConnectRequestSchema,
2328
+ MoonPayConsentPromptSchema,
2329
+ MoonPayConsentRequestSchema,
2330
+ MoonPayDoneSchema,
2274
2331
  MoonPayErrorBodySchema,
2275
2332
  MoonPayFaultSchema,
2276
- MoonPayIntentRequestSchema,
2277
- MoonPayIntentResponseSchema,
2333
+ MoonPayKycPromptSchema,
2334
+ MoonPayKycRequestSchema,
2335
+ MoonPayNextRequestSchema,
2336
+ MoonPayObserveRequestSchema,
2337
+ MoonPayOrderPromptSchema,
2338
+ MoonPayOrderRequestSchema,
2278
2339
  MoonPayOrderResponseSchema,
2340
+ MoonPayPromptSchema,
2279
2341
  MoonPayQuoteInputSchema,
2342
+ MoonPayRequestContextSchema,
2343
+ MoonPayRequestSchema,
2344
+ MoonPayResponseSchemaFor,
2280
2345
  MoonPaySdkCredentialsSchema,
2281
2346
  MoonPayStepResponseSchema,
2347
+ MoonPayWaitPromptSchema,
2282
2348
  OrderAwaitingConfirmationStateSchema,
2283
2349
  OrderCreatedStateSchema,
2284
2350
  OrderRefSchema,
@@ -1,28 +1,31 @@
1
1
  /**
2
- * The MoonPay provider-owned flow: one route, `POST /fiat/providers/moonpay/intent`.
2
+ * The MoonPay flow on `POST /fiat/next`.
3
3
  *
4
- * Each request carries evidence or a user action (`kind`), and each response says what the backend
5
- * needs next (`status`). `observe` and `kyc` answer a `MoonPayStepResponse`, and `order` answers a
6
- * `MoonPayOrderResponse` (`MoonPayIntentResponseFor`). Terms and consents go through
7
- * the platform `POST /fiat/terms` (`./terms`). Identity and the deposit wallet always come from the
8
- * verified partner assertion, never from a request body.
4
+ * Each action has one name and two types. A response's prompt names it in `next` and carries what
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 prompt, `done`, or `refused` (`MoonPayResponseFor`). `observe` carries no
7
+ * result and answers the current prompt. `wait` has no request: the client sends `observe` after it.
8
+ *
9
+ * The body is `MoonPayNextRequest`: `provider`, the shared `geo`, the context (`checkout`, and
10
+ * `credentials` after `connect`), and the action's result. Identity and the deposit wallet always
11
+ * come from the verified partner assertion, never from a request body.
9
12
  *
10
13
  * A retry sends the same request. Each write is idempotent on data the request carries, and every
11
14
  * call, a retry too, returns the current response.
12
15
  *
13
- * A fault is a 4xx/5xx whose body is `MoonPayErrorBody`. Anything the user can act on is a 200
14
- * `MoonPayIntentResponse`.
16
+ * A fault is a 4xx/5xx whose body is `MoonPayErrorBody`. Anything the user can act on is a 200.
15
17
  *
16
18
  * Zero runtime dependencies, so production React Native code can import it. The zod schemas are in
17
19
  * `./moonpay.schemas`, exported from the package root.
18
20
  */
19
21
  import type { FiatCurrencyCode } from '../codes';
20
- import type { TermsDocument, TermsStage } from '../terms';
21
- import type { FiatAmount, FiatStepResponse, FormField, KycFieldId } from '../types';
22
+ import type { FiatTermsRequest, TermsDocument } from '../terms';
23
+ import type { FiatAmount, FiatGeo, FiatStepResponse, FormField, KycFieldId } from '../types';
22
24
  export declare const MOONPAY_ENDPOINTS: {
23
- readonly intent: "POST /fiat/providers/moonpay/intent";
25
+ readonly next: "POST /fiat/next";
24
26
  };
25
- /** The checkout terms. The client holds them and sends them on every `observe` and `kyc`. */
27
+ export type MoonPayAction = 'observe' | 'consent' | 'connect' | 'kyc' | 'wait' | 'order';
28
+ /** The checkout terms. The client holds them and sends them on every request. */
26
29
  export interface MoonPayCheckout {
27
30
  amount: FiatAmount;
28
31
  /** The quote's `crypto.currency` and `crypto.network`, unchanged. */
@@ -31,46 +34,17 @@ export interface MoonPayCheckout {
31
34
  network: string;
32
35
  };
33
36
  paymentMethod: 'apple_pay';
34
- /** The geo endpoint's response, as sent to `POST /fiat/quote`. `alpha2` is ISO 3166-1 alpha-2. */
35
- geo: {
36
- alpha2: string;
37
- region?: string;
38
- ip?: string;
39
- };
40
37
  }
41
38
  /** From the SDK's `active` connection. `accessToken` is a credential: the backend never logs it. */
42
39
  export interface MoonPaySdkCredentials {
43
40
  customerId: string;
44
41
  accessToken: string;
45
42
  }
46
- export type MoonPayIntentRequest =
47
- /** No effect. Without credentials, the answer past the gates is `SDK_AUTH`. */
48
- {
49
- kind: 'observe';
43
+ /** On every request, not part of the result. `credentials` is present after `connect`. */
44
+ export type MoonPayRequestContext = {
50
45
  checkout: MoonPayCheckout;
51
46
  credentials?: MoonPaySdkCredentials;
52
- }
53
- /** Only after a `KYC` response. `values` is keyed by the ids of that response's fields; there is no form id. */
54
- | {
55
- kind: 'kyc';
56
- checkout: MoonPayCheckout;
57
- credentials: MoonPaySdkCredentials;
58
- values: Partial<Record<KycFieldId, string>>;
59
- }
60
- /**
61
- * After every charge attempt, a failed one too. `transactionId` is from the Apple Pay event when it
62
- * has one; without it the backend records the failed charges MoonPay lists for `orderId`.
63
- * `quotedAmount` is the fiat amount the buyer saw on the quote. `geo` is the checkout's, as sent on
64
- * `observe`; the order records its `alpha2`, and no country when it is absent.
65
- */
66
- | {
67
- kind: 'order';
68
- orderId: string;
69
- transactionId?: string;
70
- quotedAmount: FiatAmount;
71
- geo?: MoonPayCheckout['geo'];
72
47
  };
73
- export type MoonPayIntentKind = MoonPayIntentRequest['kind'];
74
48
  /**
75
49
  * The parameters for the device `client.getQuote`, not a quote. The backend builds them because the
76
50
  * wallet must be the verified one and MoonPay's currency codes differ by environment.
@@ -95,18 +69,39 @@ export interface MoonPayQuoteInput {
95
69
  };
96
70
  feeBehavior: 'inclusive';
97
71
  }
98
- /** `REQUOTE` for `NOT_ELIGIBLE` and `DOCUMENTS_REQUIRED`, `NONE` for the others. */
99
- export type MoonPayStepRefusal = 'NOT_ELIGIBLE' | 'DOCUMENTS_REQUIRED' | 'FINAL_REJECTION' | 'CUSTOMER_MISMATCH';
72
+ /** No prompt of its own: the answer is the current prompt. Writes nothing. */
73
+ export type MoonPayObserveRequest = {
74
+ action: 'observe';
75
+ };
76
+ /** MoonPay's terms first. Later, before `kyc`, Fun's KYC consent if the buyer has not accepted it. */
77
+ export type MoonPayConsentPrompt = {
78
+ next: 'consent';
79
+ documents: TermsDocument[];
80
+ };
81
+ /** The `POST /fiat/terms` items, recorded under the same rules. */
82
+ export type MoonPayConsentRequest = {
83
+ action: 'consent';
84
+ acceptances: FiatTermsRequest['acceptances'];
85
+ };
100
86
  /**
101
- * After a charge, always with `recovery: NONE`. `CUSTOMER_MISMATCH`: the transaction's customer is
102
- * not bound to this buyer. `WALLET_MISMATCH`: the transaction pays another wallet than the
103
- * assertion's. `UNRECORDABLE`: a charge no retry can record, held for refund review.
87
+ * Run MoonPay's connection check with `sessionToken`; it asks for an OTP only if the hidden check
88
+ * fails. `resetConnection`: the device's connection is another buyer's, so reset it first.
104
89
  */
105
- export type MoonPayOrderRefusal = 'CUSTOMER_MISMATCH' | 'WALLET_MISMATCH' | 'UNRECORDABLE';
90
+ export type MoonPayConnectPrompt = {
91
+ next: 'connect';
92
+ sessionToken: string;
93
+ quoteInput: MoonPayQuoteInput;
94
+ resetConnection?: true;
95
+ };
96
+ export type MoonPayConnectRequest = {
97
+ action: 'connect';
98
+ customerId: string;
99
+ accessToken: string;
100
+ };
106
101
  /** Another MoonPay customer already holds the value; only a different one goes through. */
107
102
  export type MoonPayFieldErrorCode = 'PHONE_IN_USE' | 'TAX_ID_IN_USE';
108
103
  /**
109
- * A reason on one field of a `KYC` response. `fieldId` names a field in that response. `code` is set
104
+ * A reason on one field of a `kyc` prompt. `fieldId` names a field in that prompt. `code` is set
110
105
  * only for a refusal the client words itself: `PHONE_IN_USE` on `PHONE_NUMBER`, `TAX_ID_IN_USE` on `TAX_IDENTIFIER`.
111
106
  */
112
107
  export interface MoonPayFieldError {
@@ -114,82 +109,85 @@ export interface MoonPayFieldError {
114
109
  message: string;
115
110
  code?: MoonPayFieldErrorCode;
116
111
  }
117
- /** The answer to `observe` and `kyc`. */
118
- export type MoonPayStepResponse =
119
- /** Show `documents` (every one at `stage`), send `POST /fiat/terms`, then `observe`. */
120
- {
121
- status: 'TERMS';
122
- stage: TermsStage;
123
- documents: TermsDocument[];
124
- }
125
- /**
126
- * Run the MoonPay connection check with `sessionToken`, then `observe` with the credentials.
127
- * `resetConnection`: the device's connection is another buyer's, so reset it before the check.
128
- */
129
- | {
130
- status: 'SDK_AUTH';
131
- sessionToken: string;
132
- quoteInput: MoonPayQuoteInput;
133
- resetConnection?: true;
134
- }
135
- /** Show the shared form, then send `kyc`. */
136
- | {
137
- status: 'KYC';
112
+ /** Show the shared form. */
113
+ export type MoonPayKycPrompt = {
114
+ next: 'kyc';
138
115
  fields: FormField[];
139
116
  fieldErrors?: MoonPayFieldError[];
140
- }
141
- /** Send `observe` after the delay. Never `kyc` again: its write is done. */
142
- | {
143
- status: 'PENDING';
117
+ };
118
+ /** Keyed by the ids of the prompt's fields; there is no form id. Needs `credentials`: the backend reads the customer. */
119
+ export type MoonPayKycRequest = {
120
+ action: 'kyc';
121
+ credentials: MoonPaySdkCredentials;
122
+ values: Partial<Record<KycFieldId, string>>;
123
+ };
124
+ /** MoonPay is reviewing. No request of its own: send `observe` after the delay. */
125
+ export type MoonPayWaitPrompt = {
126
+ next: 'wait';
144
127
  retryAfterMs: number;
145
- }
146
- /** Mount Apple Pay with `externalTransactionId = orderId`, then send `order` after the charge. */
147
- | {
148
- status: 'READY';
128
+ };
129
+ /** Get the device quote from `quoteInput`, mount Apple Pay with `externalTransactionId = orderId`. */
130
+ export type MoonPayOrderPrompt = {
131
+ next: 'order';
149
132
  orderId: string;
150
133
  quoteInput: MoonPayQuoteInput;
151
- }
152
- /** Exit the provider flow. `REQUOTE` goes back to `POST /fiat/quote`; `NONE` ends the flow. */
153
- | {
154
- status: 'REFUSED';
155
- reason: MoonPayStepRefusal;
156
- recovery: 'REQUOTE' | 'NONE';
157
134
  };
158
135
  /**
159
- * The answer to `order`, which runs after each charge attempt. A failed charge is recorded too: it
160
- * answers `DONE` with the order in `FAILED`, and the client requotes for a new `orderId`.
136
+ * After every charge attempt, a failed one too. `quotedAmount` is the fiat amount the device quote
137
+ * showed. `transactionId` is from the Apple Pay event when it has one; without it the backend
138
+ * records the failed charges MoonPay lists for `orderId`.
161
139
  */
162
- export type MoonPayOrderResponse =
163
- /** The `GET /fiat/orders/:orderId` response; the shared order screen renders it. */
164
- {
165
- status: 'DONE';
166
- order: FiatStepResponse;
167
- }
140
+ export type MoonPayOrderRequest = {
141
+ action: 'order';
142
+ orderId: string;
143
+ quotedAmount: FiatAmount;
144
+ transactionId?: string;
145
+ };
146
+ export type MoonPayRequest = MoonPayRequestContext & (MoonPayObserveRequest | MoonPayConsentRequest | MoonPayConnectRequest | MoonPayKycRequest | MoonPayOrderRequest);
147
+ /** The wire body. The orchestrator reads `provider` and `geo`; MoonPay's action schemas read the rest. */
148
+ export type MoonPayNextRequest = {
149
+ provider: 'MOONPAY';
150
+ geo: FiatGeo;
151
+ } & MoonPayRequest;
152
+ /** `REQUOTE` for `NOT_ELIGIBLE` and `DOCUMENTS_REQUIRED`, `NONE` for the others. */
153
+ export type MoonPayStepRefusal = 'NOT_ELIGIBLE' | 'DOCUMENTS_REQUIRED' | 'FINAL_REJECTION' | 'CUSTOMER_MISMATCH';
168
154
  /**
169
- * MoonPay does not list the transaction yet. Send the same `order` after the delay. After a failed
170
- * charge with no `transactionId`, the client caps these polls.
155
+ * After a charge, always with `recovery: NONE`. `CUSTOMER_MISMATCH`: the transaction's customer is
156
+ * not bound to this buyer. `WALLET_MISMATCH`: the transaction pays another wallet than the
157
+ * assertion's. `UNRECORDABLE`: a charge no retry can record, held for refund review.
171
158
  */
172
- | {
173
- status: 'PENDING';
174
- retryAfterMs: number;
175
- }
176
- /** Exit the provider flow. A requote after a charge would start a second payment. */
177
- | {
178
- status: 'REFUSED';
179
- reason: MoonPayOrderRefusal;
180
- recovery: 'NONE';
159
+ export type MoonPayOrderRefusal = 'CUSTOMER_MISMATCH' | 'WALLET_MISMATCH' | 'UNRECORDABLE';
160
+ export type MoonPayPrompt = MoonPayConsentPrompt | MoonPayConnectPrompt | MoonPayKycPrompt | MoonPayWaitPrompt | MoonPayOrderPrompt;
161
+ /** `order` is the `GET /fiat/orders/:orderId` body; the shared order screen renders it. */
162
+ export type MoonPayDone = {
163
+ next: 'done';
164
+ order: FiatStepResponse;
181
165
  };
182
- export type MoonPayIntentResponseFor = {
166
+ /** Exit the provider flow. `REQUOTE` goes back to routing; `NONE` ends the flow. */
167
+ export type MoonPayRefused<R, V> = {
168
+ next: 'refused';
169
+ reason: R;
170
+ recovery: V;
171
+ };
172
+ /** The answer to `observe`, `consent`, `connect` and `kyc`. */
173
+ export type MoonPayStepResponse = MoonPayPrompt | MoonPayRefused<MoonPayStepRefusal, 'REQUOTE' | 'NONE'>;
174
+ /**
175
+ * The answer to `order`. A failed charge is recorded too: `done` with the order in `FAILED`, and the
176
+ * client requotes for a new `orderId`. `order` again while MoonPay does not list the transaction
177
+ * yet. A refusal after a charge never requotes: that would start a second payment.
178
+ */
179
+ export type MoonPayOrderResponse = MoonPayDone | MoonPayOrderPrompt | MoonPayRefused<MoonPayOrderRefusal, 'NONE'>;
180
+ export type MoonPayResponseFor = {
183
181
  observe: MoonPayStepResponse;
182
+ consent: MoonPayStepResponse;
183
+ connect: MoonPayStepResponse;
184
184
  kyc: MoonPayStepResponse;
185
185
  order: MoonPayOrderResponse;
186
186
  };
187
- export type MoonPayIntentResponse = MoonPayStepResponse | MoonPayOrderResponse;
188
- export type MoonPayIntentStatus = MoonPayIntentResponse['status'];
189
- /** `RETRY` sends the same request again. `REQUOTE` goes back to `POST /fiat/quote`. `NONE` ends the flow. */
187
+ /** `RETRY` sends the same request again. `REQUOTE` goes back to routing. `NONE` ends the flow. */
190
188
  export type MoonPayRecovery = 'RETRY' | 'REQUOTE' | 'NONE';
191
189
  /**
192
- * `SESSION_BUDGET_SPENT`: the per-login SDK session mint budget (429). `RATE_LIMITED`: the kind's
190
+ * `SESSION_BUDGET_SPENT`: the per-login SDK session mint budget (429). `RATE_LIMITED`: the action's
193
191
  * request budget (429). `PROVIDER_UNAVAILABLE`: MoonPay or Sumsub is down. `INVALID_REQUEST`: a bad
194
192
  * body (400).
195
193
  */
@@ -24,6 +24,6 @@ __export(moonpay_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(moonpay_exports);
26
26
  var MOONPAY_ENDPOINTS = {
27
- intent: "POST /fiat/providers/moonpay/intent"
27
+ next: "POST /fiat/next"
28
28
  };
29
29
  //# sourceMappingURL=moonpay.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MOONPAY_ENDPOINTS
3
- } from "../chunk-3HCZ6JBJ.mjs";
3
+ } from "../chunk-T5JAYOWY.mjs";
4
4
  export {
5
5
  MOONPAY_ENDPOINTS
6
6
  };
@@ -1,16 +1,33 @@
1
1
  /**
2
- * zod schemas for the MoonPay provider-owned flow. Test-time and backend-boundary only: exported from
3
- * the package root, never from `./moonpay`, so the production entry stays free of zod.
2
+ * zod schemas for the MoonPay flow on `POST /fiat/next`. Test-time and backend-boundary only:
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, MoonPayErrorBody, MoonPayFault, MoonPayIntentRequest, MoonPayIntentResponse, MoonPayOrderResponse, MoonPayQuoteInput, MoonPaySdkCredentials, MoonPayStepResponse } from './moonpay';
6
+ import type { MoonPayCheckout, MoonPayConnectPrompt, MoonPayConnectRequest, MoonPayConsentPrompt, MoonPayConsentRequest, MoonPayDone, MoonPayErrorBody, MoonPayFault, MoonPayKycPrompt, MoonPayKycRequest, MoonPayNextRequest, MoonPayObserveRequest, MoonPayOrderPrompt, MoonPayOrderRequest, MoonPayOrderResponse, MoonPayPrompt, MoonPayQuoteInput, MoonPayRequest, MoonPayRequestContext, MoonPayResponseFor, MoonPaySdkCredentials, MoonPayStepResponse, MoonPayWaitPrompt } from './moonpay';
7
7
  export declare const MoonPayCheckoutSchema: z.ZodType<MoonPayCheckout>;
8
8
  export declare const MoonPaySdkCredentialsSchema: z.ZodType<MoonPaySdkCredentials>;
9
- export declare const MoonPayIntentRequestSchema: z.ZodType<MoonPayIntentRequest>;
9
+ export declare const MoonPayRequestContextSchema: z.ZodType<MoonPayRequestContext>;
10
10
  export declare const MoonPayQuoteInputSchema: z.ZodType<MoonPayQuoteInput>;
11
+ export declare const MoonPayObserveRequestSchema: z.ZodType<MoonPayRequestContext & MoonPayObserveRequest>;
12
+ export declare const MoonPayConsentRequestSchema: z.ZodType<MoonPayRequestContext & MoonPayConsentRequest>;
13
+ export declare const MoonPayConnectRequestSchema: z.ZodType<MoonPayRequestContext & MoonPayConnectRequest>;
14
+ export declare const MoonPayKycRequestSchema: z.ZodType<MoonPayRequestContext & MoonPayKycRequest>;
15
+ export declare const MoonPayOrderRequestSchema: z.ZodType<MoonPayRequestContext & MoonPayOrderRequest>;
16
+ export declare const MoonPayRequestSchema: z.ZodType<MoonPayRequest>;
17
+ export declare const MoonPayNextRequestSchema: z.ZodType<MoonPayNextRequest>;
18
+ export declare const MoonPayConsentPromptSchema: z.ZodType<MoonPayConsentPrompt>;
19
+ export declare const MoonPayConnectPromptSchema: z.ZodType<MoonPayConnectPrompt>;
20
+ export declare const MoonPayKycPromptSchema: z.ZodType<MoonPayKycPrompt>;
21
+ export declare const MoonPayWaitPromptSchema: z.ZodType<MoonPayWaitPrompt>;
22
+ export declare const MoonPayOrderPromptSchema: z.ZodType<MoonPayOrderPrompt>;
23
+ export declare const MoonPayPromptSchema: z.ZodType<MoonPayPrompt>;
24
+ export declare const MoonPayDoneSchema: z.ZodType<MoonPayDone>;
11
25
  export declare const MoonPayStepResponseSchema: z.ZodType<MoonPayStepResponse>;
12
26
  export declare const MoonPayOrderResponseSchema: z.ZodType<MoonPayOrderResponse>;
13
- export declare const MoonPayIntentResponseSchema: z.ZodType<MoonPayIntentResponse>;
27
+ /** The response schema for each request action, as `MoonPayResponseFor` types it. */
28
+ export declare const MoonPayResponseSchemaFor: {
29
+ readonly [A in keyof MoonPayResponseFor]: z.ZodType<MoonPayResponseFor[A]>;
30
+ };
14
31
  export declare const MoonPayFaultSchema: z.ZodType<MoonPayFault>;
15
32
  export declare const MoonPayErrorBodySchema: z.ZodType<MoonPayErrorBody>;
16
33
  //# sourceMappingURL=moonpay.schemas.d.ts.map