@fun-xyz/fiat-contract 0.39.0 → 0.42.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.js CHANGED
@@ -20,12 +20,42 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- AuthChallengeSchema: () => AuthChallengeSchema,
24
23
  BlockedReasonSchema: () => BlockedReasonSchema,
25
24
  BlockedStateSchema: () => BlockedStateSchema,
25
+ COINBASE_ENDPOINTS: () => COINBASE_ENDPOINTS,
26
+ COINBASE_TERMS: () => COINBASE_TERMS,
26
27
  COUNTRY_NAMES: () => COUNTRY_NAMES,
27
28
  COUNTRY_TO_CURRENCY: () => COUNTRY_TO_CURRENCY,
28
29
  ClientExecutedDeliverySchema: () => ClientExecutedDeliverySchema,
30
+ CoinbaseCheckoutSchema: () => CoinbaseCheckoutSchema,
31
+ CoinbaseConsentNextActionSchema: () => CoinbaseConsentNextActionSchema,
32
+ CoinbaseConsentRequestSchema: () => CoinbaseConsentRequestSchema,
33
+ CoinbaseDoneSchema: () => CoinbaseDoneSchema,
34
+ CoinbaseErrorBodySchema: () => CoinbaseErrorBodySchema,
35
+ CoinbaseFaultSchema: () => CoinbaseFaultSchema,
36
+ CoinbaseKycNextActionSchema: () => CoinbaseKycNextActionSchema,
37
+ CoinbaseKycRequestSchema: () => CoinbaseKycRequestSchema,
38
+ CoinbaseNextActionSchema: () => CoinbaseNextActionSchema,
39
+ CoinbaseNextRequestSchema: () => CoinbaseNextRequestSchema,
40
+ CoinbaseObserveRequestSchema: () => CoinbaseObserveRequestSchema,
41
+ CoinbaseOrderPendingNextActionSchema: () => CoinbaseOrderPendingNextActionSchema,
42
+ CoinbaseOrderRequestSchema: () => CoinbaseOrderRequestSchema,
43
+ CoinbaseOrderResponseSchema: () => CoinbaseOrderResponseSchema,
44
+ CoinbaseOtpNextActionSchema: () => CoinbaseOtpNextActionSchema,
45
+ CoinbaseOtpRequestSchema: () => CoinbaseOtpRequestSchema,
46
+ CoinbasePayNextActionSchema: () => CoinbasePayNextActionSchema,
47
+ CoinbasePlaceOrderNextActionSchema: () => CoinbasePlaceOrderNextActionSchema,
48
+ CoinbasePlaceOrderRequestSchema: () => CoinbasePlaceOrderRequestSchema,
49
+ CoinbasePriceSchema: () => CoinbasePriceSchema,
50
+ CoinbaseReaskSchema: () => CoinbaseReaskSchema,
51
+ CoinbaseRefusedSchema: () => CoinbaseRefusedSchema,
52
+ CoinbaseRequestContextSchema: () => CoinbaseRequestContextSchema,
53
+ CoinbaseRequestSchema: () => CoinbaseRequestSchema,
54
+ CoinbaseResponseSchemaFor: () => CoinbaseResponseSchemaFor,
55
+ CoinbaseSessionNextActionSchema: () => CoinbaseSessionNextActionSchema,
56
+ CoinbaseSessionRequestSchema: () => CoinbaseSessionRequestSchema,
57
+ CoinbaseStepResponseSchema: () => CoinbaseStepResponseSchema,
58
+ CoinbaseWaitNextActionSchema: () => CoinbaseWaitNextActionSchema,
29
59
  ContractViolation: () => ContractViolation,
30
60
  CountryCode: () => CountryCode,
31
61
  CryptoAmountSchema: () => CryptoAmountSchema,
@@ -38,10 +68,16 @@ __export(index_exports, {
38
68
  FIELD_SPEC_TYPES: () => FIELD_SPEC_TYPES,
39
69
  FIXTURES: () => FIXTURES,
40
70
  FIXTURE_COVERAGE_GAPS: () => FIXTURE_COVERAGE_GAPS,
71
+ FUN_AUTH_ERROR_CODES: () => FUN_AUTH_ERROR_CODES,
41
72
  FUN_KYC_CONSENT_DOCUMENTS: () => FUN_KYC_CONSENT_DOCUMENTS,
42
73
  FailureReasonSchema: () => FailureReasonSchema,
43
74
  FeeLineSchema: () => FeeLineSchema,
44
75
  FiatAmountSchema: () => FiatAmountSchema,
76
+ FiatAuthRefreshRequestSchema: () => FiatAuthRefreshRequestSchema,
77
+ FiatAuthRefreshResponseSchema: () => FiatAuthRefreshResponseSchema,
78
+ FiatAuthRevokeRequestSchema: () => FiatAuthRevokeRequestSchema,
79
+ FiatAuthStartRequestSchema: () => FiatAuthStartRequestSchema,
80
+ FiatAuthVerifyRequestSchema: () => FiatAuthVerifyRequestSchema,
45
81
  FiatCurrencyCode: () => FiatCurrencyCode,
46
82
  FiatEndpointSchema: () => FiatEndpointSchema,
47
83
  FiatGeoSchema: () => FiatGeoSchema,
@@ -53,6 +89,7 @@ __export(index_exports, {
53
89
  FiatRoutingTableErrorBodySchema: () => FiatRoutingTableErrorBodySchema,
54
90
  FiatRoutingTableRequestSchema: () => FiatRoutingTableRequestSchema,
55
91
  FiatRoutingTableResponseSchema: () => FiatRoutingTableResponseSchema,
92
+ FiatSessionSchema: () => FiatSessionSchema,
56
93
  FiatStepResponseSchema: () => FiatStepResponseSchema,
57
94
  FiatTermsErrorBodySchema: () => FiatTermsErrorBodySchema,
58
95
  FiatTermsRequestSchema: () => FiatTermsRequestSchema,
@@ -891,8 +928,6 @@ var $preparedPayment = obj({
891
928
  transition: $clientSurfaceTransition
892
929
  });
893
930
  var PreparedPaymentSchema = $preparedPayment;
894
- var $authChallenge = import_zod.z.record(import_zod.z.string(), JsonSchema);
895
- var AuthChallengeSchema = $authChallenge;
896
931
  var $quoteState = obj({
897
932
  kind: import_zod.z.literal("QUOTE"),
898
933
  quote: $quote,
@@ -905,10 +940,20 @@ var $quoteState = obj({
905
940
  var QuoteStateSchema = $quoteState;
906
941
  var $funAuthState = obj({
907
942
  kind: import_zod.z.literal("FUN_AUTH"),
908
- challenge: $authChallenge,
943
+ channel: import_zod.z.enum(["EMAIL_OTP", "SMS_OTP"]),
944
+ phase: import_zod.z.enum(["IDENTIFIER", "CODE", "VERIFIED"]),
945
+ expiresAtMs: import_zod.z.number().int().nonnegative().optional(),
946
+ resendAvailableAtMs: import_zod.z.number().int().nonnegative().optional(),
947
+ attemptsRemaining: import_zod.z.number().int().nonnegative().optional(),
909
948
  error: $failureReason.optional()
910
949
  });
911
950
  var FunAuthStateSchema = $funAuthState;
951
+ var $fiatSession = obj({
952
+ accessToken: import_zod.z.string().min(1),
953
+ refreshHandle: import_zod.z.string().min(1),
954
+ expiresAtMs: import_zod.z.number().int().nonnegative()
955
+ });
956
+ var FiatSessionSchema = $fiatSession;
912
957
  var $sessionAuthState = obj({
913
958
  kind: import_zod.z.literal("SESSION_AUTH"),
914
959
  channel: import_zod.z.enum(["EMAIL_OTP", "SMS_OTP", "PROVIDER_RENDERED"]),
@@ -1014,7 +1059,6 @@ var $deliveryState = import_zod.z.discriminatedUnion("state", [
1014
1059
  var DeliveryStateSchema = $deliveryState;
1015
1060
  var $providerBoundFlowState = import_zod.z.union([
1016
1061
  $quoteState,
1017
- $funAuthState,
1018
1062
  $sessionAuthState,
1019
1063
  $kycCaptureState,
1020
1064
  $kycInputRequiredState,
@@ -1026,7 +1070,7 @@ var $providerBoundFlowState = import_zod.z.union([
1026
1070
  $orderCreatedState,
1027
1071
  $deliveryState
1028
1072
  ]);
1029
- var $flowState = import_zod.z.union([$providerBoundFlowState, $blockedState]);
1073
+ var $flowState = import_zod.z.union([$providerBoundFlowState, $funAuthState, $blockedState]);
1030
1074
  var FlowStateSchema = $flowState;
1031
1075
  var $nonBlank = import_zod.z.string().refine((value) => value.trim().length > 0, "must not be blank");
1032
1076
  var $isoInstant = import_zod.z.string().datetime({ offset: true });
@@ -1233,12 +1277,18 @@ var $fiatGeo = obj({ alpha2: import_zod.z.string().regex(/^[A-Z]{2}$/), region:
1233
1277
  var FiatGeoSchema = $fiatGeo;
1234
1278
  var $nextRequest = import_zod.z.object({ provider: $provider, action: $nonBlank, geo: $fiatGeo, destinationAsset: $destinationAsset.optional() }).catchall(import_zod.z.unknown());
1235
1279
  var FiatNextRequestSchema = $nextRequest;
1236
- var $providerBoundStepResponse = obj({
1237
- state: $providerBoundFlowState,
1238
- provider: $provider,
1280
+ var $authStartRequest = import_zod.z.union([obj({ email: $nonBlank }), obj({ verificationRef: $nonBlank })]);
1281
+ var FiatAuthStartRequestSchema = $authStartRequest;
1282
+ var $authVerifyRequest = obj({ verificationRef: $nonBlank, otpCode: import_zod.z.string().regex(/^\d{6}$/, "must be six digits") });
1283
+ var FiatAuthVerifyRequestSchema = $authVerifyRequest;
1284
+ var $authRefreshRequest = obj({ refreshHandle: $nonBlank });
1285
+ var FiatAuthRefreshRequestSchema = $authRefreshRequest;
1286
+ var $authRefreshResponse = obj({ session: $fiatSession });
1287
+ var FiatAuthRefreshResponseSchema = $authRefreshResponse;
1288
+ var $authRevokeRequest = obj({ refreshHandle: $nonBlank });
1289
+ var FiatAuthRevokeRequestSchema = $authRevokeRequest;
1290
+ var $stepResponseBase = {
1239
1291
  transitions: import_zod.z.array($transition),
1240
- preparedPayment: $preparedPayment.optional(),
1241
- handoff: obj({ provider: $provider }).optional(),
1242
1292
  routingSessionRef: import_zod.z.string().optional(),
1243
1293
  providerAuthToken: obj({
1244
1294
  clientSecret: import_zod.z.string(),
@@ -1246,6 +1296,13 @@ var $providerBoundStepResponse = obj({
1246
1296
  }).optional(),
1247
1297
  orderId: import_zod.z.string().optional(),
1248
1298
  refreshLimits: import_zod.z.literal(true).optional()
1299
+ };
1300
+ var $providerBoundStepResponse = obj({
1301
+ ...$stepResponseBase,
1302
+ state: $providerBoundFlowState,
1303
+ provider: $provider,
1304
+ preparedPayment: $preparedPayment.optional(),
1305
+ handoff: obj({ provider: $provider }).optional()
1249
1306
  }).superRefine((response, context) => {
1250
1307
  if (response.preparedPayment !== void 0 && response.preparedPayment.surface.provider !== response.provider) {
1251
1308
  context.addIssue({
@@ -1277,22 +1334,41 @@ var $providerBoundStepResponse = obj({
1277
1334
  }
1278
1335
  });
1279
1336
  var $blockedStepResponse = obj({
1337
+ ...$stepResponseBase,
1280
1338
  state: $blockedState,
1339
+ provider: $provider.optional()
1340
+ });
1341
+ var FUN_AUTH_TRANSITIONS_BY_PHASE = {
1342
+ IDENTIFIER: ["start"],
1343
+ CODE: ["verify", "resend"],
1344
+ VERIFIED: []
1345
+ };
1346
+ var $funAuthStepResponse = obj({
1347
+ ...$stepResponseBase,
1348
+ state: $funAuthState,
1281
1349
  provider: $provider.optional(),
1282
- transitions: import_zod.z.array($transition),
1283
- routingSessionRef: import_zod.z.string().optional(),
1284
- providerAuthToken: obj({
1285
- clientSecret: import_zod.z.string(),
1286
- expiresAt: import_zod.z.string()
1287
- }).optional(),
1288
- orderId: import_zod.z.string().optional(),
1289
- refreshLimits: import_zod.z.literal(true).optional()
1350
+ session: $fiatSession.optional()
1351
+ }).superRefine((response, context) => {
1352
+ const { phase } = response.state;
1353
+ if (response.session !== void 0 && phase !== "VERIFIED") {
1354
+ context.addIssue({ code: "custom", path: ["session"], message: "only a FUN_AUTH response in phase VERIFIED carries session" });
1355
+ }
1356
+ const allowed = FUN_AUTH_TRANSITIONS_BY_PHASE[phase];
1357
+ response.transitions.forEach((transition, index) => {
1358
+ if (!allowed.includes(transition.id)) {
1359
+ context.addIssue({
1360
+ code: "custom",
1361
+ path: ["transitions", index, "id"],
1362
+ message: `FUN_AUTH phase ${phase} offers ${allowed.join(" or ") || "no transitions"}, not "${transition.id}"`
1363
+ });
1364
+ }
1365
+ });
1290
1366
  });
1291
- var $stepResponse = import_zod.z.union([$providerBoundStepResponse, $blockedStepResponse]);
1367
+ var $stepResponse = import_zod.z.union([$providerBoundStepResponse, $funAuthStepResponse, $blockedStepResponse]);
1292
1368
  var FiatStepResponseSchema = $stepResponse;
1293
1369
 
1294
1370
  // package.json
1295
- var version = "0.39.0";
1371
+ var version = "0.42.0";
1296
1372
 
1297
1373
  // src/table.ts
1298
1374
  var TABLE_VERSION = version;
@@ -1303,6 +1379,13 @@ var TERMINAL_ORDER_STATUSES = [
1303
1379
  "FAILED",
1304
1380
  "REFUNDED"
1305
1381
  ];
1382
+ var FUN_AUTH_ERROR_CODES = [
1383
+ "INVALID_EMAIL",
1384
+ "BAD_CODE",
1385
+ "CODE_EXPIRED",
1386
+ "TOO_MANY_ATTEMPTS",
1387
+ "OTP_DISPATCH_THROTTLED"
1388
+ ];
1306
1389
  var KYC_ANY = [
1307
1390
  "KYC/CAPTURE",
1308
1391
  "KYC/INPUT_REQUIRED",
@@ -1337,12 +1420,6 @@ var TRANSITION_TABLE = {
1337
1420
  when: "returning user, session + KYC valid, order-first rail \u2014 the quote screen doubles as review",
1338
1421
  note: "Narrowed to the order-first rail: on a capture-first method the order cannot be created before the payment is authorised, so the sibling payment-session entry is the one that applies."
1339
1422
  },
1340
- {
1341
- id: "continue",
1342
- mode: "SUBMIT",
1343
- endpoint: "POST /fiat/auth",
1344
- when: "no ambient Fun identity (non-fomo surfaces only)"
1345
- },
1346
1423
  {
1347
1424
  id: "capture",
1348
1425
  mode: "CLIENT_SURFACE",
@@ -1380,12 +1457,31 @@ var TRANSITION_TABLE = {
1380
1457
  key: "FUN_AUTH",
1381
1458
  kind: "FUN_AUTH",
1382
1459
  screens: [],
1383
- docStatus: "UNSPECIFIED",
1384
- allowedTransitions: [],
1460
+ docStatus: "SPECIFIED",
1461
+ allowedTransitions: [
1462
+ { id: "start", mode: "SUBMIT", endpoint: "POST /fiat/auth", when: "phase IDENTIFIER \u2014 inputs { email: TEXT }" },
1463
+ {
1464
+ id: "verify",
1465
+ mode: "SUBMIT",
1466
+ endpoint: "POST /fiat/auth/verify",
1467
+ when: "phase CODE \u2014 params { verificationRef }, inputs { otpCode: TEXT length 6, regex ^\\d{6}$ }"
1468
+ },
1469
+ {
1470
+ id: "resend",
1471
+ mode: "SUBMIT",
1472
+ endpoint: "POST /fiat/auth",
1473
+ when: "phase CODE, once resendAvailableAtMs has passed \u2014 params { verificationRef }"
1474
+ }
1475
+ ],
1476
+ mayReturn: ["FUN_AUTH"],
1385
1477
  terminal: false,
1386
1478
  notes: [
1387
- "TODO(open-decision): shape and transitions owned by the auth spike (contract \xA7Auth & ref binding, item 5).",
1388
- "Never renders in fomo \u2014 identity is ambient, so the FE doc gives it no screen and no bindings row."
1479
+ "Answered, in phase IDENTIFIER with the start transition, to the entry quote request (POST /fiat/routing/quote or POST /fiat/quote) of a Fun-run login that holds no session; no state returns it, and a customer-asserted identity never sees it.",
1480
+ "VERIFIED carries no transitions. A Fun-run login also carries `session` on the envelope; the SDK then starts the flow at QUOTE with `accessToken` as Bearer.",
1481
+ "Not in the FE doc, so no screen number: the client renders it on its contact and OTP screens.",
1482
+ "Every FUN_AUTH error is category USER_ERROR with a code from FUN_AUTH_ERROR_CODES. A wrong code re-enters CODE with BAD_CODE and a lower attemptsRemaining; TOO_MANY_ATTEMPTS and CODE_EXPIRED drop the challenge and offer resend; OTP_DISPATCH_THROTTLED re-enters with resendAvailableAtMs set.",
1483
+ "resend carries the verificationRef the client holds, even one the server has dropped (expired, too many attempts); the server starts a fresh challenge for the same email while it still remembers the challenge (its code expiry plus a short grace); once it is forgotten the answer is IDENTIFIER with CODE_EXPIRED.",
1484
+ "POST /fiat/auth/refresh and /revoke are called by the SDK session store, never offered as transitions."
1389
1485
  ]
1390
1486
  },
1391
1487
  SESSION_AUTH: {
@@ -1748,6 +1844,9 @@ var DOCUMENTED_ENDPOINTS = [
1748
1844
  "GET /fiat/payment-methods",
1749
1845
  "POST /fiat/quote",
1750
1846
  "POST /fiat/auth",
1847
+ "POST /fiat/auth/verify",
1848
+ "POST /fiat/auth/refresh",
1849
+ "POST /fiat/auth/revoke",
1751
1850
  "POST /fiat/payment-session",
1752
1851
  "POST /fiat/session",
1753
1852
  "POST /fiat/session/verify",
@@ -1771,6 +1870,14 @@ var UNOFFERED_ENDPOINTS = [
1771
1870
  endpoint: "GET /fiat/payment-methods",
1772
1871
  reason: "Discovery, called before any flow state exists \u2014 there is no state to hang it off."
1773
1872
  },
1873
+ {
1874
+ endpoint: "POST /fiat/auth/refresh",
1875
+ reason: "SDK session store, not a transition."
1876
+ },
1877
+ {
1878
+ endpoint: "POST /fiat/auth/revoke",
1879
+ reason: "SDK session store, not a transition."
1880
+ },
1774
1881
  {
1775
1882
  endpoint: "POST /fiat/kyc/document",
1776
1883
  reason: "FILE fields use it for a direct provider/vendor upload handshake and completion report; the harness owns that auxiliary path and it is not a transition (see KYC/INPUT_REQUIRED notes)."
@@ -1791,7 +1898,7 @@ var UNOFFERED_ENDPOINTS = [
1791
1898
  var UNREACHABLE_STATES = [
1792
1899
  {
1793
1900
  stateKey: "FUN_AUTH",
1794
- reason: "No bindings row published (docStatus UNSPECIFIED) and never rendered in fomo, where identity is ambient. Entered out-of-band, not by a mayReturn edge."
1901
+ reason: "Answered to the entry quote request of a Fun-run login with no session, before any state exists; no state returns it."
1795
1902
  }
1796
1903
  ];
1797
1904
  function unofferedEndpoints() {
@@ -1891,6 +1998,79 @@ var FIXTURE_DATA = {
1891
1998
  "provider": "MOONPAY",
1892
1999
  "transitions": []
1893
2000
  },
2001
+ "fun-auth-01-identifier": {
2002
+ "state": {
2003
+ "kind": "FUN_AUTH",
2004
+ "channel": "EMAIL_OTP",
2005
+ "phase": "IDENTIFIER",
2006
+ "error": {
2007
+ "category": "USER_ERROR",
2008
+ "retryable": true,
2009
+ "recovery": "NONE",
2010
+ "code": "INVALID_EMAIL"
2011
+ }
2012
+ },
2013
+ "transitions": [
2014
+ {
2015
+ "id": "start",
2016
+ "mode": "SUBMIT",
2017
+ "endpoint": "POST /fiat/auth",
2018
+ "inputs": {
2019
+ "email": {
2020
+ "type": "TEXT"
2021
+ }
2022
+ }
2023
+ }
2024
+ ]
2025
+ },
2026
+ "fun-auth-02-code": {
2027
+ "state": {
2028
+ "kind": "FUN_AUTH",
2029
+ "channel": "EMAIL_OTP",
2030
+ "phase": "CODE",
2031
+ "expiresAtMs": 17600006e5,
2032
+ "resendAvailableAtMs": 176000006e4,
2033
+ "attemptsRemaining": 3
2034
+ },
2035
+ "transitions": [
2036
+ {
2037
+ "id": "verify",
2038
+ "mode": "SUBMIT",
2039
+ "endpoint": "POST /fiat/auth/verify",
2040
+ "params": {
2041
+ "verificationRef": "vr_7c1"
2042
+ },
2043
+ "inputs": {
2044
+ "otpCode": {
2045
+ "type": "TEXT",
2046
+ "length": 6,
2047
+ "regex": "^\\d{6}$"
2048
+ }
2049
+ }
2050
+ },
2051
+ {
2052
+ "id": "resend",
2053
+ "mode": "SUBMIT",
2054
+ "endpoint": "POST /fiat/auth",
2055
+ "params": {
2056
+ "verificationRef": "vr_7c1"
2057
+ }
2058
+ }
2059
+ ]
2060
+ },
2061
+ "fun-auth-03-verified": {
2062
+ "state": {
2063
+ "kind": "FUN_AUTH",
2064
+ "channel": "EMAIL_OTP",
2065
+ "phase": "VERIFIED"
2066
+ },
2067
+ "transitions": [],
2068
+ "session": {
2069
+ "accessToken": "<access-token>",
2070
+ "refreshHandle": "<refresh-handle>",
2071
+ "expiresAtMs": 176e10
2072
+ }
2073
+ },
1894
2074
  "screen-01-quote": {
1895
2075
  "state": {
1896
2076
  "kind": "QUOTE",
@@ -2718,6 +2898,36 @@ var FIXTURES = [
2718
2898
  screen: 2,
2719
2899
  stateKey: "SESSION_AUTH"
2720
2900
  },
2901
+ {
2902
+ id: "fun-auth-01-identifier",
2903
+ file: "fun-auth-01-identifier.json",
2904
+ source: "IDENTITY_DOC",
2905
+ docRef: "Fiat identity design doc (2026-10-20) \xB7 Contract changes",
2906
+ stateKey: "FUN_AUTH",
2907
+ notes: [
2908
+ "The server re-asks for the email after a start that failed with a user-correctable error. The first IDENTIFIER is entered client-side.",
2909
+ "No provider: FUN_AUTH runs before any provider is chosen."
2910
+ ]
2911
+ },
2912
+ {
2913
+ id: "fun-auth-02-code",
2914
+ file: "fun-auth-02-code.json",
2915
+ source: "IDENTITY_DOC",
2916
+ docRef: "Fiat identity design doc (2026-10-20) \xB7 Contract changes",
2917
+ stateKey: "FUN_AUTH",
2918
+ notes: ["verify and resend carry the same verificationRef; resend is usable once resendAvailableAtMs has passed."]
2919
+ },
2920
+ {
2921
+ id: "fun-auth-03-verified",
2922
+ file: "fun-auth-03-verified.json",
2923
+ source: "IDENTITY_DOC",
2924
+ docRef: "Fiat identity design doc (2026-10-20) \xB7 Contract changes",
2925
+ stateKey: "FUN_AUTH",
2926
+ notes: [
2927
+ "A Fun-run login: the envelope carries the Fun session and no transitions. The SDK then starts the flow at QUOTE with accessToken as Bearer.",
2928
+ "accessToken and refreshHandle are placeholders."
2929
+ ]
2930
+ },
2721
2931
  {
2722
2932
  id: "screen-03-kyc-input-required",
2723
2933
  file: "screen-03-kyc-input-required.json",
@@ -2908,12 +3118,7 @@ var FIXTURES = [
2908
3118
  ]
2909
3119
  }
2910
3120
  ];
2911
- var FIXTURE_COVERAGE_GAPS = [
2912
- {
2913
- stateKey: "FUN_AUTH",
2914
- reason: "No step response exists in either doc \u2014 shape owned by the auth spike, and FUN_AUTH never renders in fomo. TODO(open-decision): contract \xA7Auth & ref binding, item 5."
2915
- }
2916
- ];
3121
+ var FIXTURE_COVERAGE_GAPS = [];
2917
3122
  var fixtureMeta = (id) => {
2918
3123
  const meta = FIXTURES.find((f) => f.id === id);
2919
3124
  if (!meta) throw new Error(`unknown fixture: ${id}`);
@@ -3351,3 +3556,195 @@ var $fault = obj2($faultFields);
3351
3556
  var MoonPayFaultSchema = $fault;
3352
3557
  var $errorBody = obj2({ ...$faultFields, errorCode: $nonEmpty, errorMsg: import_zod2.z.string(), reqId: import_zod2.z.string().optional() });
3353
3558
  var MoonPayErrorBodySchema = $errorBody;
3559
+
3560
+ // src/providers/coinbase.ts
3561
+ var COINBASE_ENDPOINTS = {
3562
+ next: "POST /fiat/next"
3563
+ };
3564
+ var COINBASE_TERMS = {
3565
+ id: "COINBASE_TERMS",
3566
+ kind: "PROVIDER_TERMS",
3567
+ stage: "CHECKOUT",
3568
+ version: "2026-01",
3569
+ contentDigest: "22db1a8292d9ecd60b53adf640c8748ad8477646c26a31971a83f7a43457f1fe",
3570
+ links: [{ label: "Coinbase User Agreement", url: "https://www.coinbase.com/legal/user_agreement" }]
3571
+ };
3572
+
3573
+ // src/providers/coinbase.schemas.ts
3574
+ var import_zod3 = require("zod");
3575
+ var obj3 = (shape) => import_zod3.z.object(shape).strict();
3576
+ var $nonEmpty2 = import_zod3.z.string().refine((value) => value.trim().length > 0, "must not be blank");
3577
+ var hasUniqueIds3 = (ids) => new Set(ids).size === ids.length;
3578
+ var $retryAfterMs = import_zod3.z.number().int().positive().max(6e4);
3579
+ var $positiveAmount = import_zod3.z.string().regex(/^(?:0|[1-9]\d*)(?:\.\d+)?$/, "must be a decimal string").refine((amount) => Number(amount) > 0, "must be positive");
3580
+ var $checkout2 = obj3({
3581
+ amount: obj3({ currency: import_zod3.z.literal("USD"), amount: $positiveAmount }),
3582
+ destination: obj3({ asset: $nonEmpty2, network: $nonEmpty2 }),
3583
+ paymentMethod: import_zod3.z.literal("apple_pay")
3584
+ });
3585
+ var CoinbaseCheckoutSchema = $checkout2;
3586
+ var contextFields = { checkout: $checkout2, destinationAsset: DestinationAssetSchema.optional() };
3587
+ var $requestContext2 = obj3(contextFields);
3588
+ var CoinbaseRequestContextSchema = $requestContext2;
3589
+ var observeFields = { action: import_zod3.z.literal("observe") };
3590
+ var consentFields = {
3591
+ action: import_zod3.z.literal("consent"),
3592
+ acceptances: import_zod3.z.array(TermsDocumentAcceptanceSchema).min(1).refine((acceptances) => hasUniqueIds3(acceptances.map((acceptance) => acceptance.documentId)), "each document is accepted once")
3593
+ };
3594
+ var sessionPhoneFields = { action: import_zod3.z.literal("session"), phoneNumber: import_zod3.z.string().regex(/^\+[1-9]\d{1,14}$/) };
3595
+ var sessionResendFields = { action: import_zod3.z.literal("session"), resend: $nonEmpty2 };
3596
+ var otpFields = { action: import_zod3.z.literal("otp"), verificationRef: $nonEmpty2, otpCode: import_zod3.z.string().regex(/^\d{6}$/) };
3597
+ var $kycValues = import_zod3.z.record(KycFieldIdSchema, import_zod3.z.string());
3598
+ var kycFields = { action: import_zod3.z.literal("kyc"), values: $kycValues };
3599
+ var $mintedOrderId = import_zod3.z.string().regex(/^cbo_[A-Za-z0-9_-]{22}$/, "must be an order id a placeOrder answer minted");
3600
+ var placeOrderFields = { action: import_zod3.z.literal("placeOrder"), orderId: $mintedOrderId };
3601
+ var orderFields = { action: import_zod3.z.literal("order"), orderId: $mintedOrderId };
3602
+ var $observeRequest2 = obj3({ ...contextFields, ...observeFields });
3603
+ var $consentRequest2 = obj3({ ...contextFields, ...consentFields });
3604
+ var $sessionRequest2 = import_zod3.z.union([obj3({ ...contextFields, ...sessionPhoneFields }), obj3({ ...contextFields, ...sessionResendFields })]);
3605
+ var $otpRequest = obj3({ ...contextFields, ...otpFields });
3606
+ var $kycRequest2 = obj3({ ...contextFields, ...kycFields });
3607
+ var $placeOrderRequest = obj3({ ...contextFields, ...placeOrderFields });
3608
+ var $orderRequest2 = obj3({ ...contextFields, ...orderFields });
3609
+ var CoinbaseObserveRequestSchema = $observeRequest2;
3610
+ var CoinbaseConsentRequestSchema = $consentRequest2;
3611
+ var CoinbaseSessionRequestSchema = $sessionRequest2;
3612
+ var CoinbaseOtpRequestSchema = $otpRequest;
3613
+ var CoinbaseKycRequestSchema = $kycRequest2;
3614
+ var CoinbasePlaceOrderRequestSchema = $placeOrderRequest;
3615
+ var CoinbaseOrderRequestSchema = $orderRequest2;
3616
+ var $request2 = import_zod3.z.union([$observeRequest2, $consentRequest2, $sessionRequest2, $otpRequest, $kycRequest2, $placeOrderRequest, $orderRequest2]);
3617
+ var CoinbaseRequestSchema = $request2;
3618
+ var envelope = { provider: import_zod3.z.literal("COINBASE"), geo: FiatGeoSchema, ...contextFields };
3619
+ var $nextRequest3 = import_zod3.z.union([
3620
+ obj3({ ...envelope, ...observeFields }),
3621
+ obj3({ ...envelope, ...consentFields }),
3622
+ obj3({ ...envelope, ...sessionPhoneFields }),
3623
+ obj3({ ...envelope, ...sessionResendFields }),
3624
+ obj3({ ...envelope, ...otpFields }),
3625
+ obj3({ ...envelope, ...kycFields }),
3626
+ obj3({ ...envelope, ...placeOrderFields }),
3627
+ obj3({ ...envelope, ...orderFields })
3628
+ ]);
3629
+ var CoinbaseNextRequestSchema = $nextRequest3;
3630
+ var $price = obj3({ total: FiatAmountSchema, fees: import_zod3.z.array(FeeLineSchema), cryptoAmount: $nonEmpty2 });
3631
+ var CoinbasePriceSchema = $price;
3632
+ var $reask2 = obj3({
3633
+ requirements: import_zod3.z.array(KycFieldIdSchema).min(1).refine(hasUniqueIds3, "requirements must be unique"),
3634
+ reason: import_zod3.z.enum(["REJECTED"]).nullable()
3635
+ });
3636
+ var CoinbaseReaskSchema = $reask2;
3637
+ var $consentShape2 = obj3({ next: import_zod3.z.literal("consent"), documents: import_zod3.z.array(TermsDocumentSchema).min(1) });
3638
+ var $sessionNextAction2 = obj3({ next: import_zod3.z.literal("session"), error: import_zod3.z.literal("CODE_EXPIRED").nullable() });
3639
+ var $otpNextAction = obj3({
3640
+ next: import_zod3.z.literal("otp"),
3641
+ verificationRef: $nonEmpty2,
3642
+ expiresAt: import_zod3.z.string().datetime({ offset: true }),
3643
+ error: import_zod3.z.literal("CODE_INVALID").nullable()
3644
+ });
3645
+ var $kycShape2 = obj3({
3646
+ next: import_zod3.z.literal("kyc"),
3647
+ fields: import_zod3.z.array(FormFieldSchema),
3648
+ fieldErrors: import_zod3.z.array(obj3({ fieldId: $nonEmpty2, message: $nonEmpty2 })).min(1).optional(),
3649
+ reask: $reask2.nullable()
3650
+ });
3651
+ var $waitNextAction2 = obj3({ next: import_zod3.z.literal("wait"), retryAfterMs: $retryAfterMs });
3652
+ var $placeOrderNextAction = obj3({ next: import_zod3.z.literal("placeOrder"), price: $price, orderId: $nonEmpty2 });
3653
+ var $payNextAction = obj3({
3654
+ next: import_zod3.z.literal("pay"),
3655
+ orderId: $nonEmpty2,
3656
+ price: $price,
3657
+ // As the shared links are checked: `z.string().url()` would also take `http:` and `javascript:`.
3658
+ paymentLink: obj3({ url: import_zod3.z.string().regex(/^https:\/\/\S+$/, "must be an https URL") }),
3659
+ environment: import_zod3.z.enum(["sandbox", "production"])
3660
+ });
3661
+ var $orderPendingNextAction2 = obj3({
3662
+ next: import_zod3.z.literal("orderPending"),
3663
+ orderId: $nonEmpty2,
3664
+ retryAfterMs: $retryAfterMs,
3665
+ order: FiatStepResponseSchema.nullable()
3666
+ });
3667
+ var checkConsent2 = (nextAction, context) => {
3668
+ if (!hasUniqueIds3(nextAction.documents.map((document) => document.id))) {
3669
+ context.addIssue({ code: "custom", path: ["documents"], message: "document ids must be unique" });
3670
+ }
3671
+ };
3672
+ var checkKyc2 = (nextAction, context) => {
3673
+ const fieldIds = nextAction.fields.map((field) => field.id);
3674
+ if (!hasUniqueIds3(fieldIds)) {
3675
+ context.addIssue({ code: "custom", path: ["fields"], message: "field ids must be unique" });
3676
+ }
3677
+ if (nextAction.fieldErrors?.some((error) => !fieldIds.includes(error.fieldId))) {
3678
+ context.addIssue({ code: "custom", path: ["fieldErrors"], message: "a field error must name a field in this next action" });
3679
+ }
3680
+ if (nextAction.reask?.requirements.some((requirement) => !fieldIds.includes(requirement))) {
3681
+ context.addIssue({ code: "custom", path: ["reask"], message: "a kyc reask must name fields in this next action" });
3682
+ }
3683
+ };
3684
+ var CoinbaseConsentNextActionSchema = $consentShape2.superRefine(checkConsent2);
3685
+ var CoinbaseSessionNextActionSchema = $sessionNextAction2;
3686
+ var CoinbaseOtpNextActionSchema = $otpNextAction;
3687
+ var CoinbaseKycNextActionSchema = $kycShape2.superRefine(checkKyc2);
3688
+ var CoinbaseWaitNextActionSchema = $waitNextAction2;
3689
+ var CoinbasePlaceOrderNextActionSchema = $placeOrderNextAction;
3690
+ var CoinbasePayNextActionSchema = $payNextAction;
3691
+ var CoinbaseOrderPendingNextActionSchema = $orderPendingNextAction2;
3692
+ var checkNextAction2 = (response, context) => {
3693
+ if (response.next === "consent") checkConsent2(response, context);
3694
+ if (response.next === "kyc") checkKyc2(response, context);
3695
+ };
3696
+ var $nextActionOptions2 = [
3697
+ $consentShape2,
3698
+ $sessionNextAction2,
3699
+ $otpNextAction,
3700
+ $kycShape2,
3701
+ $waitNextAction2,
3702
+ $placeOrderNextAction,
3703
+ $payNextAction,
3704
+ $orderPendingNextAction2
3705
+ ];
3706
+ var $nextAction2 = import_zod3.z.discriminatedUnion("next", [...$nextActionOptions2]).superRefine(checkNextAction2);
3707
+ var CoinbaseNextActionSchema = $nextAction2;
3708
+ var $done2 = obj3({ next: import_zod3.z.literal("done"), order: FiatStepResponseSchema });
3709
+ var CoinbaseDoneSchema = $done2;
3710
+ var $refused = import_zod3.z.union([
3711
+ obj3({
3712
+ next: import_zod3.z.literal("refused"),
3713
+ reason: import_zod3.z.enum(["NOT_ELIGIBLE", "KYC_UPGRADE_REJECTED", "FINAL_REJECTION", "TOTAL_MISMATCH"]),
3714
+ recovery: import_zod3.z.enum(["REQUOTE", "NONE"])
3715
+ }),
3716
+ obj3({
3717
+ next: import_zod3.z.literal("refused"),
3718
+ reason: import_zod3.z.literal("LIMITS_EXCEEDED"),
3719
+ recovery: import_zod3.z.literal("REQUOTE"),
3720
+ maxAmount: FiatAmountSchema.nullable()
3721
+ })
3722
+ ]);
3723
+ var CoinbaseRefusedSchema = $refused;
3724
+ var $stepResponse3 = import_zod3.z.union([import_zod3.z.discriminatedUnion("next", [...$nextActionOptions2, $done2]), $refused]).superRefine(checkNextAction2);
3725
+ var CoinbaseStepResponseSchema = $stepResponse3;
3726
+ var $orderResponse2 = import_zod3.z.discriminatedUnion("next", [$done2, $orderPendingNextAction2]);
3727
+ var CoinbaseOrderResponseSchema = $orderResponse2;
3728
+ var CoinbaseResponseSchemaFor = {
3729
+ observe: CoinbaseStepResponseSchema,
3730
+ consent: CoinbaseStepResponseSchema,
3731
+ session: CoinbaseStepResponseSchema,
3732
+ otp: CoinbaseStepResponseSchema,
3733
+ kyc: CoinbaseStepResponseSchema,
3734
+ placeOrder: CoinbaseStepResponseSchema,
3735
+ order: CoinbaseOrderResponseSchema
3736
+ };
3737
+ var faultFields = {
3738
+ reason: import_zod3.z.enum(["SESSION_BUDGET_SPENT", "RATE_LIMITED", "PROVIDER_UNAVAILABLE", "KYC_PROVIDER_UNAVAILABLE", "SERVICE_UNAVAILABLE", "INVALID_REQUEST"]),
3739
+ recovery: import_zod3.z.enum(["RETRY", "REQUOTE", "NONE"])
3740
+ };
3741
+ var $fault2 = obj3(faultFields);
3742
+ var CoinbaseFaultSchema = $fault2;
3743
+ var $errorBody2 = obj3({
3744
+ ...faultFields,
3745
+ errorCode: $nonEmpty2,
3746
+ errorMsg: import_zod3.z.string(),
3747
+ reqId: import_zod3.z.string().optional(),
3748
+ retryAfterSeconds: import_zod3.z.number().int().positive().optional()
3749
+ });
3750
+ var CoinbaseErrorBodySchema = $errorBody2;