@metamask/ramps-controller 20.3.0 → 21.0.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.
Files changed (266) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/{NeoBankService-method-action-types.d.mts → NeoBankService-method-action-types.d.ts} +2 -2
  3. package/dist/NeoBankService-method-action-types.d.ts.map +1 -0
  4. package/dist/{NeoBankService-method-action-types.mjs → NeoBankService-method-action-types.js} +1 -1
  5. package/dist/NeoBankService-method-action-types.js.map +1 -0
  6. package/dist/{NeoBankService.d.cts → NeoBankService.d.ts} +8 -8
  7. package/dist/NeoBankService.d.ts.map +1 -0
  8. package/dist/NeoBankService.js +380 -0
  9. package/dist/NeoBankService.js.map +1 -0
  10. package/dist/{RampsController-method-action-types.d.mts → RampsController-method-action-types.d.ts} +2 -2
  11. package/dist/RampsController-method-action-types.d.ts.map +1 -0
  12. package/dist/{TransakService-method-action-types.mjs → RampsController-method-action-types.js} +1 -1
  13. package/dist/RampsController-method-action-types.js.map +1 -0
  14. package/dist/{RampsController.d.cts → RampsController.d.ts} +19 -19
  15. package/dist/RampsController.d.ts.map +1 -0
  16. package/dist/{RampsController.mjs → RampsController.js} +725 -613
  17. package/dist/RampsController.js.map +1 -0
  18. package/dist/{RampsService-method-action-types.d.cts → RampsService-method-action-types.d.ts} +2 -2
  19. package/dist/RampsService-method-action-types.d.ts.map +1 -0
  20. package/dist/{RampsService-method-action-types.mjs → RampsService-method-action-types.js} +1 -1
  21. package/dist/RampsService-method-action-types.js.map +1 -0
  22. package/dist/{RampsService.d.mts → RampsService.d.ts} +5 -5
  23. package/dist/RampsService.d.ts.map +1 -0
  24. package/dist/{RampsService.mjs → RampsService.js} +159 -147
  25. package/dist/RampsService.js.map +1 -0
  26. package/dist/{RequestCache.d.mts → RequestCache.d.ts} +3 -3
  27. package/dist/RequestCache.d.ts.map +1 -0
  28. package/dist/{RequestCache.mjs → RequestCache.js} +1 -1
  29. package/dist/RequestCache.js.map +1 -0
  30. package/dist/{TransakService-method-action-types.d.cts → TransakService-method-action-types.d.ts} +2 -2
  31. package/dist/TransakService-method-action-types.d.ts.map +1 -0
  32. package/dist/{RampsController-method-action-types.mjs → TransakService-method-action-types.js} +1 -1
  33. package/dist/TransakService-method-action-types.js.map +1 -0
  34. package/dist/{TransakService.d.cts → TransakService.d.ts} +6 -6
  35. package/dist/TransakService.d.ts.map +1 -0
  36. package/dist/TransakService.js +746 -0
  37. package/dist/TransakService.js.map +1 -0
  38. package/dist/{autoramp-types.d.cts → autoramp-types.d.ts} +1 -1
  39. package/dist/autoramp-types.d.ts.map +1 -0
  40. package/dist/autoramp-types.js +2 -0
  41. package/dist/autoramp-types.js.map +1 -0
  42. package/dist/{autorampAccount.d.mts → autorampAccount.d.ts} +3 -3
  43. package/dist/autorampAccount.d.ts.map +1 -0
  44. package/dist/{autorampAccount.mjs → autorampAccount.js} +1 -1
  45. package/dist/autorampAccount.js.map +1 -0
  46. package/dist/{client-identity.d.mts → client-identity.d.ts} +1 -1
  47. package/dist/client-identity.d.ts.map +1 -0
  48. package/dist/{client-identity.mjs → client-identity.js} +1 -1
  49. package/dist/client-identity.js.map +1 -0
  50. package/dist/{errorNormalization.d.mts → errorNormalization.d.ts} +1 -1
  51. package/dist/errorNormalization.d.ts.map +1 -0
  52. package/dist/{errorNormalization.mjs → errorNormalization.js} +1 -1
  53. package/dist/errorNormalization.js.map +1 -0
  54. package/dist/{featureFlags.d.mts → featureFlags.d.ts} +2 -2
  55. package/dist/featureFlags.d.ts.map +1 -0
  56. package/dist/{featureFlags.mjs → featureFlags.js} +1 -1
  57. package/dist/featureFlags.js.map +1 -0
  58. package/dist/{index.d.mts → index.d.ts} +35 -35
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +18 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/{orderStatus.d.mts → orderStatus.d.ts} +2 -2
  63. package/dist/orderStatus.d.ts.map +1 -0
  64. package/dist/{orderStatus.mjs → orderStatus.js} +2 -2
  65. package/dist/orderStatus.js.map +1 -0
  66. package/dist/{ownership-message.d.cts → ownership-message.d.ts} +1 -1
  67. package/dist/ownership-message.d.ts.map +1 -0
  68. package/dist/{ownership-message.mjs → ownership-message.js} +1 -1
  69. package/dist/ownership-message.js.map +1 -0
  70. package/dist/{paymentMethodMerge.d.cts → paymentMethodMerge.d.ts} +2 -2
  71. package/dist/paymentMethodMerge.d.ts.map +1 -0
  72. package/dist/{paymentMethodMerge.mjs → paymentMethodMerge.js} +1 -1
  73. package/dist/paymentMethodMerge.js.map +1 -0
  74. package/dist/{providerAvailability.d.cts → providerAvailability.d.ts} +2 -2
  75. package/dist/providerAvailability.d.ts.map +1 -0
  76. package/dist/{providerAvailability.mjs → providerAvailability.js} +1 -1
  77. package/dist/providerAvailability.js.map +1 -0
  78. package/dist/{quoteClassification.d.cts → quoteClassification.d.ts} +2 -2
  79. package/dist/quoteClassification.d.ts.map +1 -0
  80. package/dist/{quoteClassification.mjs → quoteClassification.js} +1 -1
  81. package/dist/quoteClassification.js.map +1 -0
  82. package/dist/{rampsErrorCodes.d.cts → rampsErrorCodes.d.ts} +2 -2
  83. package/dist/rampsErrorCodes.d.ts.map +1 -0
  84. package/dist/{rampsErrorCodes.mjs → rampsErrorCodes.js} +1 -1
  85. package/dist/rampsErrorCodes.js.map +1 -0
  86. package/dist/{selectors.d.mts → selectors.d.ts} +3 -3
  87. package/dist/selectors.d.ts.map +1 -0
  88. package/dist/{selectors.mjs → selectors.js} +2 -2
  89. package/dist/selectors.js.map +1 -0
  90. package/dist/{transakApiErrorUtils.d.cts → transakApiErrorUtils.d.ts} +1 -1
  91. package/dist/transakApiErrorUtils.d.ts.map +1 -0
  92. package/dist/{transakApiErrorUtils.mjs → transakApiErrorUtils.js} +3 -3
  93. package/dist/transakApiErrorUtils.js.map +1 -0
  94. package/dist/{transakErrorCodes.d.cts → transakErrorCodes.d.ts} +3 -3
  95. package/dist/transakErrorCodes.d.ts.map +1 -0
  96. package/dist/{transakErrorCodes.mjs → transakErrorCodes.js} +1 -1
  97. package/dist/transakErrorCodes.js.map +1 -0
  98. package/dist/{wallet-registration-machine.d.cts → wallet-registration-machine.d.ts} +1 -1
  99. package/dist/wallet-registration-machine.d.ts.map +1 -0
  100. package/dist/{wallet-registration-machine.mjs → wallet-registration-machine.js} +1 -1
  101. package/dist/wallet-registration-machine.js.map +1 -0
  102. package/dist/{wallet-registration-service.d.cts → wallet-registration-service.d.ts} +1 -1
  103. package/dist/wallet-registration-service.d.ts.map +1 -0
  104. package/dist/{wallet-registration-service.mjs → wallet-registration-service.js} +60 -69
  105. package/dist/wallet-registration-service.js.map +1 -0
  106. package/package.json +17 -21
  107. package/dist/NeoBankService-method-action-types.cjs +0 -7
  108. package/dist/NeoBankService-method-action-types.cjs.map +0 -1
  109. package/dist/NeoBankService-method-action-types.d.cts +0 -126
  110. package/dist/NeoBankService-method-action-types.d.cts.map +0 -1
  111. package/dist/NeoBankService-method-action-types.d.mts.map +0 -1
  112. package/dist/NeoBankService-method-action-types.mjs.map +0 -1
  113. package/dist/NeoBankService.cjs +0 -387
  114. package/dist/NeoBankService.cjs.map +0 -1
  115. package/dist/NeoBankService.d.cts.map +0 -1
  116. package/dist/NeoBankService.d.mts +0 -191
  117. package/dist/NeoBankService.d.mts.map +0 -1
  118. package/dist/NeoBankService.mjs +0 -379
  119. package/dist/NeoBankService.mjs.map +0 -1
  120. package/dist/RampsController-method-action-types.cjs +0 -7
  121. package/dist/RampsController-method-action-types.cjs.map +0 -1
  122. package/dist/RampsController-method-action-types.d.cts +0 -758
  123. package/dist/RampsController-method-action-types.d.cts.map +0 -1
  124. package/dist/RampsController-method-action-types.d.mts.map +0 -1
  125. package/dist/RampsController-method-action-types.mjs.map +0 -1
  126. package/dist/RampsController.cjs +0 -2799
  127. package/dist/RampsController.cjs.map +0 -1
  128. package/dist/RampsController.d.cts.map +0 -1
  129. package/dist/RampsController.d.mts +0 -968
  130. package/dist/RampsController.d.mts.map +0 -1
  131. package/dist/RampsController.mjs.map +0 -1
  132. package/dist/RampsService-method-action-types.cjs +0 -7
  133. package/dist/RampsService-method-action-types.cjs.map +0 -1
  134. package/dist/RampsService-method-action-types.d.cts.map +0 -1
  135. package/dist/RampsService-method-action-types.d.mts +0 -171
  136. package/dist/RampsService-method-action-types.d.mts.map +0 -1
  137. package/dist/RampsService-method-action-types.mjs.map +0 -1
  138. package/dist/RampsService.cjs +0 -708
  139. package/dist/RampsService.cjs.map +0 -1
  140. package/dist/RampsService.d.cts +0 -944
  141. package/dist/RampsService.d.cts.map +0 -1
  142. package/dist/RampsService.d.mts.map +0 -1
  143. package/dist/RampsService.mjs.map +0 -1
  144. package/dist/RequestCache.cjs +0 -103
  145. package/dist/RequestCache.cjs.map +0 -1
  146. package/dist/RequestCache.d.cts +0 -110
  147. package/dist/RequestCache.d.cts.map +0 -1
  148. package/dist/RequestCache.d.mts.map +0 -1
  149. package/dist/RequestCache.mjs.map +0 -1
  150. package/dist/TransakService-method-action-types.cjs +0 -7
  151. package/dist/TransakService-method-action-types.cjs.map +0 -1
  152. package/dist/TransakService-method-action-types.d.cts.map +0 -1
  153. package/dist/TransakService-method-action-types.d.mts +0 -140
  154. package/dist/TransakService-method-action-types.d.mts.map +0 -1
  155. package/dist/TransakService-method-action-types.mjs.map +0 -1
  156. package/dist/TransakService.cjs +0 -743
  157. package/dist/TransakService.cjs.map +0 -1
  158. package/dist/TransakService.d.cts.map +0 -1
  159. package/dist/TransakService.d.mts +0 -370
  160. package/dist/TransakService.d.mts.map +0 -1
  161. package/dist/TransakService.mjs +0 -734
  162. package/dist/TransakService.mjs.map +0 -1
  163. package/dist/autoramp-types.cjs +0 -3
  164. package/dist/autoramp-types.cjs.map +0 -1
  165. package/dist/autoramp-types.d.cts.map +0 -1
  166. package/dist/autoramp-types.d.mts +0 -22
  167. package/dist/autoramp-types.d.mts.map +0 -1
  168. package/dist/autoramp-types.mjs +0 -2
  169. package/dist/autoramp-types.mjs.map +0 -1
  170. package/dist/autorampAccount.cjs +0 -155
  171. package/dist/autorampAccount.cjs.map +0 -1
  172. package/dist/autorampAccount.d.cts +0 -126
  173. package/dist/autorampAccount.d.cts.map +0 -1
  174. package/dist/autorampAccount.d.mts.map +0 -1
  175. package/dist/autorampAccount.mjs.map +0 -1
  176. package/dist/client-identity.cjs +0 -28
  177. package/dist/client-identity.cjs.map +0 -1
  178. package/dist/client-identity.d.cts +0 -24
  179. package/dist/client-identity.d.cts.map +0 -1
  180. package/dist/client-identity.d.mts.map +0 -1
  181. package/dist/client-identity.mjs.map +0 -1
  182. package/dist/errorNormalization.cjs +0 -84
  183. package/dist/errorNormalization.cjs.map +0 -1
  184. package/dist/errorNormalization.d.cts +0 -56
  185. package/dist/errorNormalization.d.cts.map +0 -1
  186. package/dist/errorNormalization.d.mts.map +0 -1
  187. package/dist/errorNormalization.mjs.map +0 -1
  188. package/dist/featureFlags.cjs +0 -144
  189. package/dist/featureFlags.cjs.map +0 -1
  190. package/dist/featureFlags.d.cts +0 -82
  191. package/dist/featureFlags.d.cts.map +0 -1
  192. package/dist/featureFlags.d.mts.map +0 -1
  193. package/dist/featureFlags.mjs.map +0 -1
  194. package/dist/index.cjs +0 -82
  195. package/dist/index.cjs.map +0 -1
  196. package/dist/index.d.cts +0 -35
  197. package/dist/index.d.cts.map +0 -1
  198. package/dist/index.d.mts.map +0 -1
  199. package/dist/index.mjs +0 -18
  200. package/dist/index.mjs.map +0 -1
  201. package/dist/orderStatus.cjs +0 -34
  202. package/dist/orderStatus.cjs.map +0 -1
  203. package/dist/orderStatus.d.cts +0 -18
  204. package/dist/orderStatus.d.cts.map +0 -1
  205. package/dist/orderStatus.d.mts.map +0 -1
  206. package/dist/orderStatus.mjs.map +0 -1
  207. package/dist/ownership-message.cjs +0 -26
  208. package/dist/ownership-message.cjs.map +0 -1
  209. package/dist/ownership-message.d.cts.map +0 -1
  210. package/dist/ownership-message.d.mts +0 -22
  211. package/dist/ownership-message.d.mts.map +0 -1
  212. package/dist/ownership-message.mjs.map +0 -1
  213. package/dist/paymentMethodMerge.cjs +0 -51
  214. package/dist/paymentMethodMerge.cjs.map +0 -1
  215. package/dist/paymentMethodMerge.d.cts.map +0 -1
  216. package/dist/paymentMethodMerge.d.mts +0 -26
  217. package/dist/paymentMethodMerge.d.mts.map +0 -1
  218. package/dist/paymentMethodMerge.mjs.map +0 -1
  219. package/dist/providerAvailability.cjs +0 -134
  220. package/dist/providerAvailability.cjs.map +0 -1
  221. package/dist/providerAvailability.d.cts.map +0 -1
  222. package/dist/providerAvailability.d.mts +0 -101
  223. package/dist/providerAvailability.d.mts.map +0 -1
  224. package/dist/providerAvailability.mjs.map +0 -1
  225. package/dist/quoteClassification.cjs +0 -44
  226. package/dist/quoteClassification.cjs.map +0 -1
  227. package/dist/quoteClassification.d.cts.map +0 -1
  228. package/dist/quoteClassification.d.mts +0 -33
  229. package/dist/quoteClassification.d.mts.map +0 -1
  230. package/dist/quoteClassification.mjs.map +0 -1
  231. package/dist/rampsErrorCodes.cjs +0 -11
  232. package/dist/rampsErrorCodes.cjs.map +0 -1
  233. package/dist/rampsErrorCodes.d.cts.map +0 -1
  234. package/dist/rampsErrorCodes.d.mts +0 -9
  235. package/dist/rampsErrorCodes.d.mts.map +0 -1
  236. package/dist/rampsErrorCodes.mjs.map +0 -1
  237. package/dist/selectors.cjs +0 -85
  238. package/dist/selectors.cjs.map +0 -1
  239. package/dist/selectors.d.cts +0 -78
  240. package/dist/selectors.d.cts.map +0 -1
  241. package/dist/selectors.d.mts.map +0 -1
  242. package/dist/selectors.mjs.map +0 -1
  243. package/dist/transakApiErrorUtils.cjs +0 -15
  244. package/dist/transakApiErrorUtils.cjs.map +0 -1
  245. package/dist/transakApiErrorUtils.d.cts.map +0 -1
  246. package/dist/transakApiErrorUtils.d.mts +0 -3
  247. package/dist/transakApiErrorUtils.d.mts.map +0 -1
  248. package/dist/transakApiErrorUtils.mjs.map +0 -1
  249. package/dist/transakErrorCodes.cjs +0 -14
  250. package/dist/transakErrorCodes.cjs.map +0 -1
  251. package/dist/transakErrorCodes.d.cts.map +0 -1
  252. package/dist/transakErrorCodes.d.mts +0 -12
  253. package/dist/transakErrorCodes.d.mts.map +0 -1
  254. package/dist/transakErrorCodes.mjs.map +0 -1
  255. package/dist/wallet-registration-machine.cjs +0 -144
  256. package/dist/wallet-registration-machine.cjs.map +0 -1
  257. package/dist/wallet-registration-machine.d.cts.map +0 -1
  258. package/dist/wallet-registration-machine.d.mts +0 -81
  259. package/dist/wallet-registration-machine.d.mts.map +0 -1
  260. package/dist/wallet-registration-machine.mjs.map +0 -1
  261. package/dist/wallet-registration-service.cjs +0 -351
  262. package/dist/wallet-registration-service.cjs.map +0 -1
  263. package/dist/wallet-registration-service.d.cts.map +0 -1
  264. package/dist/wallet-registration-service.d.mts +0 -144
  265. package/dist/wallet-registration-service.d.mts.map +0 -1
  266. package/dist/wallet-registration-service.mjs.map +0 -1
@@ -1,708 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- var _RampsService_instances, _a, _RampsService_messenger, _RampsService_fetch, _RampsService_policy, _RampsService_environment, _RampsService_context, _RampsService_baseUrlOverride, _RampsService_clientIdentity, _RampsService_getBaseUrl, _RampsService_getRequestHeaders, _RampsService_addCommonParams, _RampsService_request, _RampsService_toProviderSegment;
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.RampsService = exports.getDefaultRedirectCallbackUrl = exports.RampsApiService = exports.RampsEnvironment = exports.serviceName = exports.RAMPS_SDK_VERSION = exports.RampsOrderStatus = void 0;
19
- const controller_utils_1 = require("@metamask/controller-utils");
20
- const package_json_1 = __importDefault(require("../package.json"));
21
- const client_identity_js_1 = require("./client-identity.cjs");
22
- // === ORDER TYPES ===
23
- /**
24
- * Possible statuses for a ramps order.
25
- */
26
- var RampsOrderStatus;
27
- (function (RampsOrderStatus) {
28
- RampsOrderStatus["Unknown"] = "UNKNOWN";
29
- RampsOrderStatus["Precreated"] = "PRECREATED";
30
- RampsOrderStatus["Created"] = "CREATED";
31
- RampsOrderStatus["Pending"] = "PENDING";
32
- RampsOrderStatus["Failed"] = "FAILED";
33
- RampsOrderStatus["Completed"] = "COMPLETED";
34
- RampsOrderStatus["Cancelled"] = "CANCELLED";
35
- RampsOrderStatus["IdExpired"] = "ID_EXPIRED";
36
- })(RampsOrderStatus || (exports.RampsOrderStatus = RampsOrderStatus = {}));
37
- /**
38
- * The SDK version to send with API requests. (backwards-compatibility)
39
- */
40
- exports.RAMPS_SDK_VERSION = '2.1.6';
41
- // === GENERAL ===
42
- /**
43
- * The name of the {@link RampsService}, used to namespace the
44
- * service's actions and events.
45
- */
46
- exports.serviceName = 'RampsService';
47
- /**
48
- * The environment to use for API requests.
49
- */
50
- var RampsEnvironment;
51
- (function (RampsEnvironment) {
52
- RampsEnvironment["Production"] = "production";
53
- RampsEnvironment["Staging"] = "staging";
54
- RampsEnvironment["Development"] = "development";
55
- RampsEnvironment["Local"] = "local";
56
- })(RampsEnvironment || (exports.RampsEnvironment = RampsEnvironment = {}));
57
- /**
58
- * The type of ramps API service.
59
- * Determines which base URL to use (cache vs standard).
60
- */
61
- var RampsApiService;
62
- (function (RampsApiService) {
63
- RampsApiService["Regions"] = "regions";
64
- RampsApiService["Orders"] = "orders";
65
- })(RampsApiService || (exports.RampsApiService = RampsApiService = {}));
66
- // === MESSENGER ===
67
- const MESSENGER_EXPOSED_METHODS = [
68
- 'getDefaultRedirectCallbackUrl',
69
- 'getGeolocation',
70
- 'getCountries',
71
- 'getTokens',
72
- 'getProviders',
73
- 'getPaymentMethods',
74
- 'getQuotes',
75
- 'getBuyWidgetUrl',
76
- 'getOrder',
77
- 'getOrderFromCallback',
78
- ];
79
- // === SERVICE DEFINITION ===
80
- /**
81
- * Gets the base URL for API requests based on the environment and service type.
82
- * The Regions service uses a cache hostname in production and staging only;
83
- * development serves regions from the same `on-ramp.dev-api` host (no `-cache`).
84
- *
85
- * @param environment - The environment to use.
86
- * @param service - The API service type (determines if cache URL is used).
87
- * @returns The base URL for API requests.
88
- */
89
- function getBaseUrl(environment, service) {
90
- const cache = service === RampsApiService.Regions &&
91
- environment !== RampsEnvironment.Development
92
- ? '-cache'
93
- : '';
94
- switch (environment) {
95
- case RampsEnvironment.Production:
96
- return `https://on-ramp${cache}.api.cx.metamask.io`;
97
- case RampsEnvironment.Staging:
98
- return `https://on-ramp${cache}.uat-api.cx.metamask.io`;
99
- case RampsEnvironment.Development:
100
- return `https://on-ramp${cache}.dev-api.cx.metamask.io`;
101
- case RampsEnvironment.Local:
102
- return 'http://localhost:3000';
103
- default:
104
- throw new Error(`Invalid environment: ${String(environment)}`);
105
- }
106
- }
107
- /**
108
- * The path served by the ramps content host that redirects back into the
109
- * client once a non-native provider's widget flow completes.
110
- */
111
- const FAKE_CALLBACK_PATH = '/regions/fake-callback';
112
- /**
113
- * Derives the default redirect ("fake callback") URL for the widened Headless
114
- * Buy quote fetch from the ramps environment.
115
- *
116
- * The quotes API only embeds a `buyURL`/`buyWidget` (the WebView page a
117
- * non-native provider needs) when a `redirectUrl` is present, so the widened
118
- * aggregator path supplies this default when the caller omits one. Production
119
- * and staging serve the callback from the `on-ramp-content` CDN hosts;
120
- * development has no `on-ramp-content.dev-api` deployment, so it uses the
121
- * `on-ramp.dev-api` host (which serves `/regions/fake-callback` and returns
122
- * 200). This intentionally does not reuse {@link getBaseUrl}, whose Regions
123
- * host is `on-ramp{-cache}`, not `on-ramp-content`.
124
- *
125
- * This is the canonical environment-to-callback map for the whole package.
126
- * Prefer the `RampsService:getDefaultRedirectCallbackUrl` messenger action at
127
- * runtime so the value always follows the environment the service is actually
128
- * configured with. Call this function directly only where a synchronous,
129
- * messenger-free value is needed (for example client UI that matches the
130
- * callback URL in a WebView), and pass the same environment the service was
131
- * constructed with.
132
- *
133
- * @param environment - The environment to derive the callback URL for.
134
- * @returns The default redirect callback URL for that environment.
135
- */
136
- function getDefaultRedirectCallbackUrl(environment) {
137
- switch (environment) {
138
- case RampsEnvironment.Production:
139
- return `https://on-ramp-content.api.cx.metamask.io${FAKE_CALLBACK_PATH}`;
140
- case RampsEnvironment.Staging:
141
- return `https://on-ramp-content.uat-api.cx.metamask.io${FAKE_CALLBACK_PATH}`;
142
- case RampsEnvironment.Development:
143
- return `https://on-ramp.dev-api.cx.metamask.io${FAKE_CALLBACK_PATH}`;
144
- case RampsEnvironment.Local:
145
- return `http://localhost:3000${FAKE_CALLBACK_PATH}`;
146
- default:
147
- throw new Error(`Invalid environment: ${String(environment)}`);
148
- }
149
- }
150
- exports.getDefaultRedirectCallbackUrl = getDefaultRedirectCallbackUrl;
151
- /**
152
- * Constructs an API path with a version prefix.
153
- *
154
- * @param path - The API endpoint path.
155
- * @param version - The API version prefix. Defaults to 'v2'.
156
- * @returns The versioned API path.
157
- */
158
- function getApiPath(path, version = 'v2') {
159
- return `${version}/${path}`;
160
- }
161
- /**
162
- * This service object is responsible for interacting with the Ramps API.
163
- *
164
- * @example
165
- *
166
- * ``` ts
167
- * import { Messenger } from '@metamask/messenger';
168
- * import type {
169
- * RampsServiceActions,
170
- * RampsServiceEvents,
171
- * } from '@metamask/ramps-controller';
172
- *
173
- * const rootMessenger = new Messenger<
174
- * 'Root',
175
- * RampsServiceActions
176
- * RampsServiceEvents
177
- * >({ namespace: 'Root' });
178
- * const rampsServiceMessenger = new Messenger<
179
- * 'RampsService',
180
- * RampsServiceActions,
181
- * RampsServiceEvents,
182
- * typeof rootMessenger,
183
- * >({
184
- * namespace: 'RampsService',
185
- * parent: rootMessenger,
186
- * });
187
- * // Instantiate the service to register its actions on the messenger
188
- * new RampsService({
189
- * messenger: rampsServiceMessenger,
190
- * environment: RampsEnvironment.Production,
191
- * context: 'mobile-ios',
192
- * fetch,
193
- * });
194
- *
195
- * // Later...
196
- * // Get the user's geolocation
197
- * const geolocation = await rootMessenger.call(
198
- * 'RampsService:getGeolocation',
199
- * );
200
- * // ... Do something with the geolocation ...
201
- * ```
202
- */
203
- class RampsService {
204
- /**
205
- * Constructs a new RampsService object.
206
- *
207
- * @param args - The constructor arguments.
208
- * @param args.messenger - The messenger suited for this service.
209
- * @param args.environment - The environment to use for API requests.
210
- * @param args.context - The context for API requests (e.g., 'mobile-ios', 'mobile-android').
211
- * @param args.fetch - A function that can be used to make an HTTP request. If
212
- * your JavaScript environment supports `fetch` natively, you'll probably want
213
- * to pass that; otherwise you can pass an equivalent (such as `fetch` via
214
- * `node-fetch`).
215
- * @param args.policyOptions - Options to pass to `createServicePolicy`, which
216
- * is used to wrap each request. See {@link CreateServicePolicyOptions}.
217
- * @param args.baseUrlOverride - Optional base URL override for local development.
218
- * @param args.clientProduct - Optional MetaMask product id (`metamask-mobile`).
219
- * @param args.clientVersion - Optional app SemVer (not the ramps-controller package version).
220
- */
221
- constructor({ messenger, environment = RampsEnvironment.Staging, context, fetch: fetchFunction, policyOptions = {}, baseUrlOverride, clientProduct, clientVersion, }) {
222
- _RampsService_instances.add(this);
223
- /**
224
- * The messenger suited for this service.
225
- */
226
- _RampsService_messenger.set(this, void 0);
227
- /**
228
- * A function that can be used to make an HTTP request.
229
- */
230
- _RampsService_fetch.set(this, void 0);
231
- /**
232
- * The policy that wraps the request.
233
- *
234
- * @see {@link createServicePolicy}
235
- */
236
- _RampsService_policy.set(this, void 0);
237
- /**
238
- * The environment used for API requests.
239
- */
240
- _RampsService_environment.set(this, void 0);
241
- /**
242
- * The context for API requests (e.g., 'mobile-ios', 'mobile-android').
243
- */
244
- _RampsService_context.set(this, void 0);
245
- /**
246
- * Optional base URL override for local development.
247
- */
248
- _RampsService_baseUrlOverride.set(this, void 0);
249
- _RampsService_clientIdentity.set(this, void 0);
250
- this.name = exports.serviceName;
251
- __classPrivateFieldSet(this, _RampsService_messenger, messenger, "f");
252
- __classPrivateFieldSet(this, _RampsService_fetch, fetchFunction, "f");
253
- __classPrivateFieldSet(this, _RampsService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
254
- __classPrivateFieldSet(this, _RampsService_environment, environment, "f");
255
- __classPrivateFieldSet(this, _RampsService_context, context, "f");
256
- __classPrivateFieldSet(this, _RampsService_baseUrlOverride, baseUrlOverride, "f");
257
- __classPrivateFieldSet(this, _RampsService_clientIdentity, {
258
- clientProduct,
259
- clientVersion,
260
- }, "f");
261
- __classPrivateFieldGet(this, _RampsService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
262
- }
263
- /**
264
- * Returns the default redirect ("fake callback") URL for this service's
265
- * environment.
266
- *
267
- * The quotes API only embeds a `buyURL`/`buyWidget` (the WebView page a
268
- * non-native provider needs) when a `redirectUrl` is present, so callers
269
- * that omit one (MM Pay's widened Headless Buy fetch) use this value.
270
- * Exposing it here makes the service's environment the single runtime source
271
- * of truth, so the callback can never point at a different environment than
272
- * the one the quotes themselves came from.
273
- *
274
- * `baseUrlOverride` deliberately does not apply. That option overrides the
275
- * ramps API base URL for local development. In production and staging the
276
- * callback lives on a different host (`on-ramp-content` versus
277
- * `on-ramp{-cache}`), so an API override says nothing about where
278
- * `/regions/fake-callback` lives. In development the callback already shares
279
- * the API host family (`on-ramp.dev-api`). The redirect URL is also handed
280
- * to the provider and matched by client UI to detect flow completion, so
281
- * returning an unrelated local API origin here would break completion
282
- * detection rather than help it. Point `environment` at
283
- * {@link RampsEnvironment.Local} for a localhost callback, noting that URL
284
- * is pinned to `http://localhost:3000` and does not follow a non-3000
285
- * `baseUrlOverride`.
286
- *
287
- * @returns The default redirect callback URL for the configured environment.
288
- */
289
- getDefaultRedirectCallbackUrl() {
290
- return getDefaultRedirectCallbackUrl(__classPrivateFieldGet(this, _RampsService_environment, "f"));
291
- }
292
- /**
293
- * Registers a handler that will be called after a request returns a non-500
294
- * response, causing a retry. Primarily useful in tests where timers are being
295
- * mocked.
296
- *
297
- * @param listener - The handler to be called.
298
- * @returns An object that can be used to unregister the handler. See
299
- * {@link CockatielEvent}.
300
- * @see {@link createServicePolicy}
301
- */
302
- onRetry(listener) {
303
- return __classPrivateFieldGet(this, _RampsService_policy, "f").onRetry(listener);
304
- }
305
- /**
306
- * Registers a handler that will be called after a set number of retry rounds
307
- * prove that requests to the API endpoint consistently return a 5xx response.
308
- *
309
- * @param listener - The handler to be called.
310
- * @returns An object that can be used to unregister the handler. See
311
- * {@link CockatielEvent}.
312
- * @see {@link createServicePolicy}
313
- */
314
- onBreak(listener) {
315
- return __classPrivateFieldGet(this, _RampsService_policy, "f").onBreak(listener);
316
- }
317
- /**
318
- * Registers a handler that will be called under one of two circumstances:
319
- *
320
- * 1. After a set number of retries prove that requests to the API
321
- * consistently result in one of the following failures:
322
- * 1. A connection initiation error
323
- * 2. A connection reset error
324
- * 3. A timeout error
325
- * 4. A non-JSON response
326
- * 5. A 502, 503, or 504 response
327
- * 2. After a successful request is made to the API, but the response takes
328
- * longer than a set duration to return.
329
- *
330
- * @param listener - The handler to be called.
331
- * @returns An object that can be used to unregister the handler. See
332
- * {@link CockatielEvent}.
333
- */
334
- onDegraded(listener) {
335
- return __classPrivateFieldGet(this, _RampsService_policy, "f").onDegraded(listener);
336
- }
337
- /**
338
- * Makes a request to the API in order to retrieve the user's geolocation
339
- * based on their IP address.
340
- *
341
- * @returns The user's country/region code (e.g., "US-UT" for Utah, USA).
342
- */
343
- async getGeolocation() {
344
- const textResponse = await __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_request).call(this, RampsApiService.Orders, 'geolocation', { responseType: 'text' });
345
- const trimmedResponse = textResponse.trim();
346
- if (trimmedResponse.length > 0) {
347
- return trimmedResponse;
348
- }
349
- throw new Error('Malformed response received from geolocation API');
350
- }
351
- /**
352
- * Makes a request to the cached API to retrieve the list of supported countries.
353
- * The API returns countries with support information for both buy and sell actions.
354
- * Filters countries based on aggregator support (preserves OnRampSDK logic).
355
- *
356
- * @returns An array of countries filtered by aggregator support.
357
- */
358
- async getCountries() {
359
- const countries = await __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_request).call(this, RampsApiService.Regions, getApiPath('regions/countries'), { responseType: 'json' });
360
- if (!Array.isArray(countries)) {
361
- throw new Error('Malformed response received from countries API');
362
- }
363
- return countries.filter((country) => {
364
- const isCountrySupported = country.supported.buy || country.supported.sell;
365
- if (country.states && country.states.length > 0) {
366
- const hasSupportedState = country.states.some(
367
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- intentionally using || to treat false as unsupported
368
- (state) => state.supported?.buy || state.supported?.sell);
369
- return isCountrySupported || hasSupportedState;
370
- }
371
- return isCountrySupported;
372
- });
373
- }
374
- /**
375
- * Fetches the list of available tokens for a given region and action.
376
- * Supports optional provider filter.
377
- *
378
- * @param region - The region code (e.g., "us", "fr", "us-ny").
379
- * @param action - The ramp action type ('buy' or 'sell').
380
- * @param options - Optional query parameters for filtering tokens.
381
- * @param options.provider - Provider ID(s) to filter by.
382
- * @returns The tokens response containing topTokens and allTokens.
383
- */
384
- async getTokens(region, action = 'buy', options) {
385
- const normalizedRegion = region.toLowerCase().trim();
386
- const url = new URL(getApiPath(`regions/${normalizedRegion}/topTokens`), __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getBaseUrl).call(this, RampsApiService.Regions));
387
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url, action);
388
- if (options?.provider) {
389
- const providerIds = Array.isArray(options.provider)
390
- ? options.provider
391
- : [options.provider];
392
- providerIds.forEach((id) => url.searchParams.append('provider', id));
393
- }
394
- const response = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
395
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url);
396
- if (!fetchResponse.ok) {
397
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
398
- }
399
- return fetchResponse.json();
400
- });
401
- if (!response || typeof response !== 'object') {
402
- throw new Error('Malformed response received from tokens API');
403
- }
404
- if (!Array.isArray(response.topTokens) ||
405
- !Array.isArray(response.allTokens)) {
406
- throw new Error('Malformed response received from tokens API');
407
- }
408
- return response;
409
- }
410
- /**
411
- * Fetches the list of providers for a given region.
412
- * Supports optional query filters: provider, crypto, payments.
413
- * Region local fiat filtering is applied server-side when `fiat` is omitted.
414
- *
415
- * @param regionCode - The region code (e.g., "us", "fr", "us-ny").
416
- * @param options - Optional query parameters for filtering providers.
417
- * @param options.provider - Provider ID(s) to filter by.
418
- * @param options.crypto - Crypto currency ID(s) to filter by.
419
- * @param options.payments - Payment method ID(s) to filter by.
420
- * @returns The providers response containing providers array.
421
- */
422
- async getProviders(regionCode, options) {
423
- const normalizedRegion = regionCode.toLowerCase().trim();
424
- const url = new URL(getApiPath(`regions/${normalizedRegion}/providers`), __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getBaseUrl).call(this, RampsApiService.Regions));
425
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url);
426
- if (options?.provider) {
427
- const providerIds = Array.isArray(options.provider)
428
- ? options.provider
429
- : [options.provider];
430
- providerIds.forEach((id) => url.searchParams.append('provider', id));
431
- }
432
- if (options?.crypto) {
433
- const cryptoIds = Array.isArray(options.crypto)
434
- ? options.crypto
435
- : [options.crypto];
436
- cryptoIds.forEach((id) => url.searchParams.append('crypto', id));
437
- }
438
- if (options?.payments) {
439
- const paymentIds = Array.isArray(options.payments)
440
- ? options.payments
441
- : [options.payments];
442
- paymentIds.forEach((id) => url.searchParams.append('payments', id));
443
- }
444
- const response = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
445
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url);
446
- if (!fetchResponse.ok) {
447
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
448
- }
449
- return fetchResponse.json();
450
- });
451
- if (!response || typeof response !== 'object') {
452
- throw new Error('Malformed response received from providers API');
453
- }
454
- if (!Array.isArray(response.providers)) {
455
- throw new Error('Malformed response received from providers API');
456
- }
457
- return {
458
- providers: response.providers,
459
- sorted: Array.isArray(response.sorted) ? response.sorted : [],
460
- };
461
- }
462
- /**
463
- * Fetches the list of payment methods for a given region, asset, and provider.
464
- *
465
- * Region local fiat filtering is applied server-side when `fiat` is omitted.
466
- *
467
- * @param options - Query parameters for filtering payment methods.
468
- * @param options.region - User's region code (e.g., "us-al").
469
- * @param options.assetId - CAIP-19 cryptocurrency identifier.
470
- * @param options.provider - Provider ID path.
471
- * @returns The payment methods response containing payments array.
472
- */
473
- async getPaymentMethods(options) {
474
- const normalizedRegion = options.region.toLowerCase().trim();
475
- const url = new URL(getApiPath(`regions/${normalizedRegion}/payments`), __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getBaseUrl).call(this, RampsApiService.Regions));
476
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url);
477
- url.searchParams.set('region', options.region.toLowerCase().trim());
478
- url.searchParams.set('crypto', options.assetId);
479
- url.searchParams.set('provider', options.provider);
480
- const response = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
481
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url);
482
- if (!fetchResponse.ok) {
483
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
484
- }
485
- return fetchResponse.json();
486
- });
487
- if (!response || typeof response !== 'object') {
488
- throw new Error('Malformed response received from paymentMethods API');
489
- }
490
- if (!Array.isArray(response.payments)) {
491
- throw new Error('Malformed response received from paymentMethods API');
492
- }
493
- return response;
494
- }
495
- /**
496
- * Fetches quotes from all providers for a given set of parameters.
497
- * Uses the V2 orders API to get quotes for multiple payment methods at once.
498
- *
499
- * @param params - The parameters for fetching quotes.
500
- * @param params.region - User's region code (e.g., "us", "us-ca").
501
- * @param params.paymentMethods - Array of payment method IDs.
502
- * @param params.assetId - CAIP-19 cryptocurrency identifier.
503
- * @param params.fiat - Fiat currency code (e.g., "usd").
504
- * @param params.amount - The amount (in fiat for buy, crypto for sell).
505
- * @param params.walletAddress - The destination wallet address.
506
- * @param params.redirectUrl - Optional redirect URL after order completion.
507
- * @param params.providers - Optional provider IDs to filter quotes.
508
- * @param params.action - The ramp action type. Defaults to 'buy'.
509
- * @returns The quotes response containing success, sorted, error, and customActions.
510
- */
511
- async getQuotes(params) {
512
- const normalizedRegion = params.region.toLowerCase().trim();
513
- const normalizedFiat = params.fiat.toLowerCase().trim();
514
- const action = params.action ?? 'buy';
515
- const url = new URL(getApiPath('quotes'), getBaseUrl(__classPrivateFieldGet(this, _RampsService_environment, "f"), RampsApiService.Orders));
516
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url, action);
517
- // Build region ID in the format expected by the API
518
- url.searchParams.set('region', normalizedRegion);
519
- url.searchParams.set('fiat', normalizedFiat);
520
- url.searchParams.set('crypto', params.assetId);
521
- url.searchParams.set('amount', String(params.amount));
522
- url.searchParams.set('walletAddress', params.walletAddress);
523
- const headers = await __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getRequestHeaders).call(this);
524
- // Add payment methods as array parameters
525
- params.paymentMethods.forEach((paymentMethod) => {
526
- url.searchParams.append('payments', paymentMethod);
527
- });
528
- // Add provider filter if specified
529
- params.providers?.forEach((provider) => {
530
- url.searchParams.append('providers', provider);
531
- });
532
- // Add redirect URL if specified
533
- if (params.redirectUrl) {
534
- url.searchParams.set('redirectUrl', params.redirectUrl);
535
- }
536
- const response = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
537
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url, { headers });
538
- if (!fetchResponse.ok) {
539
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
540
- }
541
- return fetchResponse.json();
542
- });
543
- if (!response || typeof response !== 'object') {
544
- throw new Error('Malformed response received from quotes API');
545
- }
546
- if (!Array.isArray(response.success) ||
547
- !Array.isArray(response.sorted) ||
548
- !Array.isArray(response.error) ||
549
- !Array.isArray(response.customActions)) {
550
- throw new Error('Malformed response received from quotes API');
551
- }
552
- return response;
553
- }
554
- /**
555
- * Fetches the buy widget data from a buy URL endpoint.
556
- * Makes a request to the buyURL (as provided in a quote) to get the actual
557
- * provider widget URL, browser type, and order ID.
558
- *
559
- * @param buyUrl - The full buy URL endpoint to fetch from.
560
- * @returns The buy widget data containing the provider widget URL.
561
- */
562
- async getBuyWidgetUrl(buyUrl) {
563
- const url = new URL(buyUrl);
564
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url);
565
- const headers = await __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getRequestHeaders).call(this);
566
- const response = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
567
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url, { headers });
568
- if (!fetchResponse.ok) {
569
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
570
- }
571
- return fetchResponse.json();
572
- });
573
- if (!response || typeof response !== 'object' || !response.url) {
574
- throw new Error('Malformed response received from buy widget URL API');
575
- }
576
- return response;
577
- }
578
- /**
579
- * Fetches an order from the unified V2 API endpoint.
580
- * This endpoint returns a normalized `RampsOrder` (DepositOrder shape)
581
- * for all provider types, including both aggregator and native providers.
582
- *
583
- * @param providerCode - The provider code (e.g., "transak", "transak-native", "moonpay"),
584
- * with or without the `/providers/` prefix.
585
- * @param orderCode - The order identifier.
586
- * @param wallet - The wallet address associated with the order.
587
- * @returns The unified order data.
588
- */
589
- async getOrder(providerCode, orderCode, wallet) {
590
- const segment = __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_toProviderSegment).call(this, providerCode);
591
- const url = new URL(getApiPath(`providers/${segment}/orders/${orderCode}`), __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getBaseUrl).call(this, RampsApiService.Orders));
592
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url);
593
- if (wallet) {
594
- url.searchParams.set('wallet', wallet);
595
- }
596
- const response = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
597
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url);
598
- if (!fetchResponse.ok) {
599
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
600
- }
601
- return fetchResponse.json();
602
- });
603
- if (!response || typeof response !== 'object') {
604
- throw new Error('Malformed response received from order API');
605
- }
606
- return response;
607
- }
608
- /**
609
- * Extracts an order from a provider callback URL.
610
- * Sends the callback URL to the V2 API backend, which knows how to parse
611
- * each provider's callback format and extract the order ID. Then fetches
612
- * the full order using that ID.
613
- *
614
- * This is the V2 equivalent of the aggregator SDK's `getOrderFromCallback`.
615
- *
616
- * @param providerCode - The provider code (e.g., "transak", "moonpay"),
617
- * with or without the `/providers/` prefix.
618
- * @param callbackUrl - The full callback URL the provider redirected to.
619
- * @param wallet - The wallet address associated with the order.
620
- * @returns The unified order data.
621
- */
622
- async getOrderFromCallback(providerCode, callbackUrl, wallet) {
623
- const segment = __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_toProviderSegment).call(this, providerCode);
624
- // Step 1: Send the callback URL to the backend to extract the order ID.
625
- // The backend parses it using provider-specific logic.
626
- const callbackApiUrl = new URL(getApiPath(`providers/${segment}/callback`), __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getBaseUrl).call(this, RampsApiService.Orders));
627
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, callbackApiUrl);
628
- callbackApiUrl.searchParams.set('url', callbackUrl);
629
- const callbackResponse = await __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
630
- const fetchResponse = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, callbackApiUrl);
631
- if (!fetchResponse.ok) {
632
- throw new controller_utils_1.HttpError(fetchResponse.status, `Fetching '${callbackApiUrl.toString()}' failed with status '${fetchResponse.status}'`);
633
- }
634
- return fetchResponse.json();
635
- });
636
- const rawOrderId = callbackResponse?.id;
637
- if (!rawOrderId) {
638
- throw new Error('Could not extract order ID from callback URL via provider');
639
- }
640
- // The callback response id may be a full resource path like
641
- // "/providers/transak-staging/orders/3ec2e8ac-...".
642
- // Extract just the order code (last segment) so getOrder doesn't
643
- // build a doubled path.
644
- const lastSlash = rawOrderId.lastIndexOf('/');
645
- const orderCode = lastSlash >= 0 ? rawOrderId.slice(lastSlash + 1) : rawOrderId;
646
- // Step 2: Fetch the full order using the extracted order code.
647
- return this.getOrder(providerCode, orderCode, wallet);
648
- }
649
- }
650
- exports.RampsService = RampsService;
651
- _a = RampsService, _RampsService_messenger = new WeakMap(), _RampsService_fetch = new WeakMap(), _RampsService_policy = new WeakMap(), _RampsService_environment = new WeakMap(), _RampsService_context = new WeakMap(), _RampsService_baseUrlOverride = new WeakMap(), _RampsService_clientIdentity = new WeakMap(), _RampsService_instances = new WeakSet(), _RampsService_getBaseUrl = function _RampsService_getBaseUrl(service) {
652
- if (__classPrivateFieldGet(this, _RampsService_baseUrlOverride, "f")) {
653
- return __classPrivateFieldGet(this, _RampsService_baseUrlOverride, "f");
654
- }
655
- return getBaseUrl(__classPrivateFieldGet(this, _RampsService_environment, "f"), service);
656
- }, _RampsService_getRequestHeaders =
657
- /**
658
- * Builds the request headers for authenticated ramps API calls.
659
- *
660
- * Fetches a bearer token from `AuthenticationController` and returns it as
661
- * an `Authorization` header. Throws if the token is unavailable (e.g. the
662
- * wallet is locked or the user is signed out).
663
- *
664
- * @returns Headers containing the `Authorization: Bearer <token>` entry.
665
- */
666
- async function _RampsService_getRequestHeaders() {
667
- const bearerToken = await __classPrivateFieldGet(this, _RampsService_messenger, "f").call('AuthenticationController:getBearerToken');
668
- return {
669
- Authorization: `Bearer ${bearerToken}`,
670
- };
671
- }, _RampsService_addCommonParams = function _RampsService_addCommonParams(url, action) {
672
- if (action) {
673
- url.searchParams.set('action', action);
674
- }
675
- url.searchParams.set('sdk', exports.RAMPS_SDK_VERSION);
676
- url.searchParams.set('controller', package_json_1.default.version);
677
- url.searchParams.set('context', __classPrivateFieldGet(this, _RampsService_context, "f"));
678
- // In the query string (not headers) so CDN-cached responses vary per
679
- // client product / version.
680
- (0, client_identity_js_1.addRampsClientIdentityParams)(url, __classPrivateFieldGet(this, _RampsService_clientIdentity, "f"));
681
- }, _RampsService_request =
682
- /**
683
- * Makes an API request with retry policy and error handling.
684
- *
685
- * @param service - The API service type (determines base URL).
686
- * @param path - The endpoint path.
687
- * @param options - Request options.
688
- * @param options.action - The ramp action type (optional).
689
- * @param options.responseType - How to parse the response ('json' or 'text').
690
- * @returns The parsed response data.
691
- */
692
- async function _RampsService_request(service, path, options) {
693
- return __classPrivateFieldGet(this, _RampsService_policy, "f").execute(async () => {
694
- const baseUrl = __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_getBaseUrl).call(this, service);
695
- const url = new URL(path, baseUrl);
696
- __classPrivateFieldGet(this, _RampsService_instances, "m", _RampsService_addCommonParams).call(this, url, options.action);
697
- const response = await __classPrivateFieldGet(this, _RampsService_fetch, "f").call(this, url);
698
- if (!response.ok) {
699
- throw new controller_utils_1.HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'`);
700
- }
701
- return options.responseType === 'json'
702
- ? response.json()
703
- : response.text();
704
- });
705
- }, _RampsService_toProviderSegment = function _RampsService_toProviderSegment(providerId) {
706
- return providerId.replace(/^\/providers\//u, '');
707
- };
708
- //# sourceMappingURL=RampsService.cjs.map