@metamask-previews/ramps-controller 29.0.0-preview-d94a14f45 → 29.0.0-preview-e53b41ba2

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 (35) hide show
  1. package/CHANGELOG.md +0 -16
  2. package/dist/NeoBankService-method-action-types.d.ts +3 -7
  3. package/dist/NeoBankService-method-action-types.d.ts.map +1 -1
  4. package/dist/NeoBankService-method-action-types.js.map +1 -1
  5. package/dist/NeoBankService.d.ts +4 -26
  6. package/dist/NeoBankService.d.ts.map +1 -1
  7. package/dist/NeoBankService.js +9 -72
  8. package/dist/NeoBankService.js.map +1 -1
  9. package/dist/RampsController-method-action-types.d.ts +0 -12
  10. package/dist/RampsController-method-action-types.d.ts.map +1 -1
  11. package/dist/RampsController-method-action-types.js.map +1 -1
  12. package/dist/RampsController.d.ts +1 -23
  13. package/dist/RampsController.d.ts.map +1 -1
  14. package/dist/RampsController.js +7 -100
  15. package/dist/RampsController.js.map +1 -1
  16. package/dist/TransakService.d.ts +5 -18
  17. package/dist/TransakService.d.ts.map +1 -1
  18. package/dist/TransakService.js +114 -293
  19. package/dist/TransakService.js.map +1 -1
  20. package/dist/autoramp-types.d.ts +1 -32
  21. package/dist/autoramp-types.d.ts.map +1 -1
  22. package/dist/autoramp-types.js.map +1 -1
  23. package/dist/autorampAccount.d.ts +0 -3
  24. package/dist/autorampAccount.d.ts.map +1 -1
  25. package/dist/autorampAccount.js +2 -7
  26. package/dist/autorampAccount.js.map +1 -1
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/rampsErrorCodes.d.ts +0 -1
  32. package/dist/rampsErrorCodes.d.ts.map +1 -1
  33. package/dist/rampsErrorCodes.js +0 -1
  34. package/dist/rampsErrorCodes.js.map +1 -1
  35. package/package.json +3 -4
@@ -1,6 +1,4 @@
1
- import { BaseDataService } from '@metamask/base-data-service';
2
- import { HttpError } from '@metamask/controller-utils';
3
- import { any, array, boolean, nullable, number, optional, record, string, type as looseObject, } from '@metamask/superstruct';
1
+ import { createServicePolicy, HttpError } from '@metamask/controller-utils';
4
2
  import packageJson from '../package.json';
5
3
  import { addRampsClientIdentityParams } from './client-identity.js';
6
4
  import { RAMPS_SDK_VERSION } from './RampsService.js';
@@ -161,131 +159,13 @@ export class TransakApiError extends HttpError {
161
159
  this.apiMessage = apiMessage;
162
160
  }
163
161
  }
164
- // === RESPONSE STRUCTS ===
165
- /**
166
- * The structs below are intentionally lenient: they require only the fields
167
- * the service itself depends on, check the type of any other field that is
168
- * present, and ignore extra fields the APIs return. The APIs omit fields for
169
- * incomplete profiles and sparse responses, and responses were not validated
170
- * before, so a missing field must not fail a call.
171
- */
172
- const TransakPaymentDetailsStruct = array(looseObject({
173
- fiatCurrency: string(),
174
- paymentMethod: string(),
175
- fields: array(looseObject({ name: string(), id: string(), value: string() })),
176
- }));
177
- const SendUserOtpResponseStruct = looseObject({
178
- isTncAccepted: boolean(),
179
- stateToken: string(),
180
- email: string(),
181
- expiresIn: number(),
182
- });
183
- const VerifyUserOtpResponseStruct = looseObject({
184
- accessToken: string(),
185
- ttl: number(),
186
- created: string(),
187
- });
188
- const UserDetailsStruct = looseObject({
189
- id: optional(string()),
190
- firstName: optional(string()),
191
- lastName: optional(string()),
192
- email: optional(string()),
193
- mobileNumber: optional(string()),
194
- status: optional(string()),
195
- dob: optional(string()),
196
- kyc: optional(looseObject({
197
- status: optional(string()),
198
- type: optional(string()),
199
- userId: optional(string()),
200
- workFlowRunId: optional(string()),
201
- })),
202
- address: optional(looseObject({
203
- addressLine1: optional(string()),
204
- addressLine2: optional(string()),
205
- state: optional(string()),
206
- city: optional(string()),
207
- postCode: optional(string()),
208
- country: optional(string()),
209
- countryCode: optional(string()),
210
- })),
211
- createdAt: optional(string()),
212
- });
213
- const BuyQuoteStruct = looseObject({
214
- quoteId: string(),
215
- conversionPrice: optional(number()),
216
- marketConversionPrice: optional(number()),
217
- slippage: optional(number()),
218
- fiatCurrency: optional(string()),
219
- cryptoCurrency: optional(string()),
220
- paymentMethod: optional(string()),
221
- fiatAmount: optional(number()),
222
- cryptoAmount: optional(number()),
223
- isBuyOrSell: optional(string()),
224
- network: optional(string()),
225
- feeDecimal: optional(number()),
226
- totalFee: optional(number()),
227
- feeBreakdown: optional(array(record(string(), any()))),
228
- nonce: optional(number()),
229
- cryptoLiquidityProvider: optional(string()),
230
- notes: optional(array(record(string(), any()))),
231
- });
232
- const KycRequirementStruct = looseObject({
233
- status: string(),
234
- kycType: string(),
235
- isAllowedToPlaceOrder: boolean(),
236
- });
237
- const AdditionalRequirementsStruct = looseObject({
238
- formsRequired: array(looseObject({ type: string(), metadata: optional(any()) })),
239
- });
240
- const TransakOrderStruct = looseObject({
241
- orderId: string(),
242
- walletAddress: string(),
243
- paymentDetails: optional(nullable(TransakPaymentDetailsStruct)),
244
- });
245
- const TransakOrderPaymentDetailsStruct = looseObject({
246
- paymentDetails: optional(nullable(TransakPaymentDetailsStruct)),
247
- });
248
- const ActiveOrdersStruct = array(looseObject({ orderId: string(), status: string() }));
249
- const DepositOrderStruct = looseObject({
250
- providerOrderId: string(),
251
- status: string(),
252
- });
253
- const UserLimitsStruct = looseObject({
254
- limits: looseObject({ '1': number(), '30': number(), '365': number() }),
255
- spent: looseObject({ '1': number(), '30': number(), '365': number() }),
256
- remaining: looseObject({ '1': number(), '30': number(), '365': number() }),
257
- exceeded: looseObject({ '1': boolean(), '30': boolean(), '365': boolean() }),
258
- shortage: optional(record(string(), number())),
259
- });
260
- const OttStruct = looseObject({ ott: string() });
261
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
262
- const TranslationStruct = looseObject({
263
- region: optional(string()),
264
- paymentMethod: optional(string()),
265
- cryptoCurrency: string(),
266
- network: string(),
267
- fiatCurrency: string(),
268
- });
269
- const IdProofStatusStruct = looseObject({
270
- status: string(),
271
- kycType: string(),
272
- randomLogIdentifier: optional(string()),
273
- });
274
- const PaymentConfirmationStruct = looseObject({ success: boolean() });
275
- const WidgetUrlResponseStruct = looseObject({ widgetUrl: string() });
276
- /**
277
- * Wraps a struct in the `{ data }` envelope the Transak API gateway uses.
278
- *
279
- * @param dataStruct - The struct for the `data` property.
280
- * @returns The envelope struct.
281
- */
282
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
- function envelope(dataStruct) {
284
- return looseObject({ data: dataStruct });
285
- }
286
162
  // === SERVICE DEFINITION ===
287
- export class TransakService extends BaseDataService {
163
+ export class TransakService {
164
+ name;
165
+ #messenger;
288
166
  #fetch;
167
+ #policy;
168
+ #noRetryPolicy;
289
169
  #environment;
290
170
  #context;
291
171
  #orderRetryDelayMs;
@@ -304,9 +184,15 @@ export class TransakService extends BaseDataService {
304
184
  */
305
185
  #referrerDomain;
306
186
  #clientIdentity;
307
- constructor({ messenger, environment = TransakEnvironment.Staging, context, fetch: fetchFunction, apiKey, policyOptions, orderRetryDelayMs = 2000, rampsApiBaseUrlOverride, referrerDomain = TRANSAK_REFERRER_DOMAIN, clientProduct, clientVersion, }) {
308
- super({ name: serviceName, messenger, policyOptions });
187
+ constructor({ messenger, environment = TransakEnvironment.Staging, context, fetch: fetchFunction, apiKey, policyOptions = {}, orderRetryDelayMs = 2000, rampsApiBaseUrlOverride, referrerDomain = TRANSAK_REFERRER_DOMAIN, clientProduct, clientVersion, }) {
188
+ this.name = serviceName;
189
+ this.#messenger = messenger;
309
190
  this.#fetch = fetchFunction;
191
+ this.#policy = createServicePolicy(policyOptions);
192
+ this.#noRetryPolicy = createServicePolicy({
193
+ ...policyOptions,
194
+ maxRetries: 0,
195
+ });
310
196
  this.#environment = environment;
311
197
  this.#context = context;
312
198
  this.#apiKey = apiKey ?? null;
@@ -317,7 +203,7 @@ export class TransakService extends BaseDataService {
317
203
  clientProduct,
318
204
  clientVersion,
319
205
  };
320
- this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
206
+ this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
321
207
  }
322
208
  setApiKey(apiKey) {
323
209
  this.#apiKey = apiKey;
@@ -384,21 +270,7 @@ export class TransakService extends BaseDataService {
384
270
  }
385
271
  throw new TransakApiError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'${errorBody ? `: ${errorBody}` : ''}`, errorCode, apiMessage);
386
272
  }
387
- /**
388
- * Identifies the current login session without exposing the access token,
389
- * so reads made under different sessions never share a request.
390
- *
391
- * @returns The access token creation time in milliseconds, or `null` when
392
- * logged out.
393
- */
394
- #getSessionId() {
395
- return this.#accessToken
396
- ? new Date(this.#accessToken.created).getTime()
397
- : null;
398
- }
399
- async #transakGet(queryName, path,
400
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
401
- dataStruct, params) {
273
+ async #transakGet(path, params) {
402
274
  const baseUrl = getTransakApiBaseUrl(this.#environment);
403
275
  const url = new URL(path, baseUrl);
404
276
  if (params) {
@@ -410,98 +282,59 @@ export class TransakService extends BaseDataService {
410
282
  }
411
283
  const apiKey = this.#ensureApiKey();
412
284
  url.searchParams.set('apiKey', apiKey);
413
- const response = (await this.fetchQuery({
414
- // The API key is deliberately left out of the key, as keys appear in the
415
- // names of published `cacheUpdated` events.
416
- queryKey: [
417
- `${this.name}:${queryName}`,
418
- path,
419
- params ?? {},
420
- this.#getSessionId(),
421
- ],
422
- staleTime: 0,
423
- gcTime: 0,
424
- responseStruct: envelope(dataStruct),
425
- queryFn: async () => {
426
- const fetchResponse = await this.#fetch(url.toString(), {
427
- method: 'GET',
428
- headers: this.#getHeaders(),
429
- });
430
- if (!fetchResponse.ok) {
431
- await this.#throwTransakApiError(fetchResponse, url);
432
- }
433
- return (await fetchResponse.json());
434
- },
435
- }));
285
+ const response = await this.#policy.execute(async () => {
286
+ const fetchResponse = await this.#fetch(url.toString(), {
287
+ method: 'GET',
288
+ headers: this.#getHeaders(),
289
+ });
290
+ if (!fetchResponse.ok) {
291
+ await this.#throwTransakApiError(fetchResponse, url);
292
+ }
293
+ return fetchResponse.json();
294
+ });
436
295
  return response.data;
437
296
  }
438
- /**
439
- * Sends a request that changes server side data. Mutations are never
440
- * retried, and the mutation key holds only the method name, as keys appear
441
- * in the names of published `cacheUpdated` events.
442
- *
443
- * @param options - The options.
444
- * @param options.mutationName - The name of the public method.
445
- * @param options.url - The request URL.
446
- * @param options.init - The request method, headers and body.
447
- * @param options.responseStruct - The struct for the response body. When
448
- * omitted, the response body is ignored.
449
- * @returns The validated response body, or `null` if it was ignored.
450
- */
451
- async #sendMutation({ mutationName, url, init, responseStruct, }) {
452
- return (await this.executeMutation({
453
- mutationKey: [`${this.name}:${mutationName}`],
454
- // Some responses carry credentials (`verifyUserOtp` returns the access
455
- // token), so do not keep finished mutations in the cache.
456
- gcTime: 0,
457
- responseStruct,
458
- mutationFn: async () => {
459
- const fetchResponse = await this.#fetch(url.toString(), init);
460
- if (!fetchResponse.ok) {
461
- await this.#throwTransakApiError(fetchResponse, url);
462
- }
463
- return responseStruct ? (await fetchResponse.json()) : null;
464
- },
465
- }));
466
- }
467
- async #transakPost(mutationName, path,
468
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
469
- dataStruct, body) {
297
+ async #transakPost(path, body, options = {}) {
470
298
  const apiKey = this.#ensureApiKey();
471
299
  const baseUrl = getTransakApiBaseUrl(this.#environment);
472
300
  const url = new URL(path, baseUrl);
473
- const response = (await this.#sendMutation({
474
- mutationName,
475
- url,
476
- init: {
301
+ const requestBody = {
302
+ ...(body ?? {}),
303
+ apiKey,
304
+ };
305
+ const policy = options.policy ?? this.#policy;
306
+ const response = await policy.execute(async () => {
307
+ const fetchResponse = await this.#fetch(url.toString(), {
477
308
  method: 'POST',
478
309
  headers: this.#getHeaders(),
479
- body: JSON.stringify({ ...(body ?? {}), apiKey }),
480
- },
481
- responseStruct: envelope(dataStruct),
482
- }));
310
+ body: JSON.stringify(requestBody),
311
+ });
312
+ if (!fetchResponse.ok) {
313
+ await this.#throwTransakApiError(fetchResponse, url);
314
+ }
315
+ return fetchResponse.json();
316
+ });
483
317
  return response.data;
484
318
  }
485
- async #transakPatch(mutationName, path,
486
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
487
- dataStruct, body) {
319
+ async #transakPatch(path, body) {
488
320
  const apiKey = this.#ensureApiKey();
489
321
  const baseUrl = getTransakApiBaseUrl(this.#environment);
490
322
  const url = new URL(path, baseUrl);
491
323
  url.searchParams.set('apiKey', apiKey);
492
- const response = (await this.#sendMutation({
493
- mutationName,
494
- url,
495
- init: {
324
+ const response = await this.#policy.execute(async () => {
325
+ const fetchResponse = await this.#fetch(url.toString(), {
496
326
  method: 'PATCH',
497
327
  headers: this.#getHeaders(),
498
328
  body: JSON.stringify(body),
499
- },
500
- responseStruct: envelope(dataStruct),
501
- }));
329
+ });
330
+ if (!fetchResponse.ok) {
331
+ await this.#throwTransakApiError(fetchResponse, url);
332
+ }
333
+ return fetchResponse.json();
334
+ });
502
335
  return response.data;
503
336
  }
504
- async #transakDelete(mutationName, path, params) {
337
+ async #transakDelete(path, params) {
505
338
  const apiKey = this.#ensureApiKey();
506
339
  const baseUrl = getTransakApiBaseUrl(this.#environment);
507
340
  const url = new URL(path, baseUrl);
@@ -513,10 +346,14 @@ export class TransakService extends BaseDataService {
513
346
  }
514
347
  }
515
348
  }
516
- await this.#sendMutation({
517
- mutationName,
518
- url,
519
- init: { method: 'DELETE', headers: this.#getHeaders() },
349
+ await this.#policy.execute(async () => {
350
+ const fetchResponse = await this.#fetch(url.toString(), {
351
+ method: 'DELETE',
352
+ headers: this.#getHeaders(),
353
+ });
354
+ if (!fetchResponse.ok) {
355
+ await this.#throwTransakApiError(fetchResponse, url);
356
+ }
520
357
  });
521
358
  }
522
359
  /**
@@ -543,9 +380,7 @@ export class TransakService extends BaseDataService {
543
380
  // client product / version.
544
381
  addRampsClientIdentityParams(url, this.#clientIdentity);
545
382
  }
546
- async #ordersApiGet(queryName, path,
547
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
548
- dataStruct, params) {
383
+ async #ordersApiGet(path, params) {
549
384
  const baseUrl = this.#getRampsApiBaseUrl();
550
385
  const providerPath = getRampsProviderPath(this.#environment);
551
386
  const url = new URL(`${providerPath}${path}`, baseUrl);
@@ -561,36 +396,29 @@ export class TransakService extends BaseDataService {
561
396
  }
562
397
  }
563
398
  }
564
- return (await this.fetchQuery({
565
- queryKey: [`${this.name}:${queryName}`, path, params ?? {}],
566
- staleTime: 0,
567
- gcTime: 0,
568
- responseStruct: dataStruct,
569
- queryFn: async () => {
570
- const fetchResponse = await this.#fetch(url.toString(), {
571
- method: 'GET',
572
- headers: { Accept: 'application/json' },
573
- });
574
- if (!fetchResponse.ok) {
575
- throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
576
- }
577
- return (await fetchResponse.json());
578
- },
579
- }));
399
+ const response = await this.#policy.execute(async () => {
400
+ const fetchResponse = await this.#fetch(url.toString(), {
401
+ method: 'GET',
402
+ headers: { Accept: 'application/json' },
403
+ });
404
+ if (!fetchResponse.ok) {
405
+ throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
406
+ }
407
+ return fetchResponse.json();
408
+ });
409
+ return response;
580
410
  }
581
411
  // === PUBLIC API METHODS ===
582
412
  async sendUserOtp(email) {
583
- const result = await this.#transakPost('sendUserOtp', '/api/v2/auth/login', SendUserOtpResponseStruct, {
584
- email,
585
- });
413
+ const result = await this.#transakPost('/api/v2/auth/login', { email });
586
414
  return result;
587
415
  }
588
416
  async verifyUserOtp(email, verificationCode, stateToken) {
589
- const responseData = await this.#transakPost('verifyUserOtp', '/api/v2/auth/verify', VerifyUserOtpResponseStruct, {
417
+ const responseData = await this.#transakPost('/api/v2/auth/verify', {
590
418
  email,
591
419
  otp: verificationCode,
592
420
  stateToken,
593
- });
421
+ }, { policy: this.#noRetryPolicy });
594
422
  const accessToken = {
595
423
  accessToken: responseData.accessToken,
596
424
  ttl: responseData.ttl,
@@ -602,7 +430,7 @@ export class TransakService extends BaseDataService {
602
430
  async logout() {
603
431
  this.#ensureAccessToken();
604
432
  try {
605
- const result = await this.#transakPost('logout', '/api/v1/auth/logout', string());
433
+ const result = await this.#transakPost('/api/v1/auth/logout');
606
434
  this.clearAccessToken();
607
435
  return result;
608
436
  }
@@ -616,7 +444,7 @@ export class TransakService extends BaseDataService {
616
444
  }
617
445
  async getUserDetails() {
618
446
  this.#ensureAccessToken();
619
- return this.#transakGet('getUserDetails', '/api/v2/user/', UserDetailsStruct);
447
+ return this.#transakGet('/api/v2/user/');
620
448
  }
621
449
  async getBuyQuote(genericFiatCurrency, genericCryptoCurrency, genericNetwork, genericPaymentMethod, fiatAmount, isFeeExcludedFromFiat = true) {
622
450
  const normalizedPaymentMethod = normalizePaymentMethodForTranslation(genericPaymentMethod || undefined);
@@ -640,7 +468,7 @@ export class TransakService extends BaseDataService {
640
468
  if (translation.paymentMethod) {
641
469
  params.paymentMethod = translation.paymentMethod;
642
470
  }
643
- const quote = await this.#transakGet('getBuyQuote', '/api/v2/lookup/quotes', BuyQuoteStruct, params);
471
+ const quote = await this.#transakGet('/api/v2/lookup/quotes', params);
644
472
  return {
645
473
  ...quote,
646
474
  requestedAssetId: genericCryptoCurrency,
@@ -649,14 +477,14 @@ export class TransakService extends BaseDataService {
649
477
  }
650
478
  async getKycRequirement(quoteId) {
651
479
  this.#ensureAccessToken();
652
- const result = await this.#transakGet('getKycRequirement', '/api/v2/kyc/requirement', KycRequirementStruct, {
480
+ const result = await this.#transakGet('/api/v2/kyc/requirement', {
653
481
  'metadata[quoteId]': quoteId,
654
482
  });
655
483
  return result;
656
484
  }
657
485
  async getAdditionalRequirements(quoteId) {
658
486
  this.#ensureAccessToken();
659
- return this.#transakGet('getAdditionalRequirements', '/api/v2/kyc/additional-requirements', AdditionalRequirementsStruct, { 'metadata[quoteId]': quoteId });
487
+ return this.#transakGet('/api/v2/kyc/additional-requirements', { 'metadata[quoteId]': quoteId });
660
488
  }
661
489
  async createOrder(quoteId, walletAddress, paymentMethodId) {
662
490
  this.#ensureAccessToken();
@@ -666,7 +494,7 @@ export class TransakService extends BaseDataService {
666
494
  });
667
495
  const paymentInstrumentId = translation.paymentMethod ?? normalizedPaymentMethod;
668
496
  try {
669
- const transakOrder = await this.#transakPost('createOrder', '/api/v2/orders', TransakOrderStruct, {
497
+ const transakOrder = await this.#transakPost('/api/v2/orders', {
670
498
  quoteId,
671
499
  walletAddress,
672
500
  paymentInstrumentId,
@@ -680,7 +508,7 @@ export class TransakService extends BaseDataService {
680
508
  error.errorCode === TRANSAK_ERROR_CODES.ORDER_EXISTS) {
681
509
  await this.cancelAllActiveOrders();
682
510
  await new Promise((resolve) => setTimeout(resolve, this.#orderRetryDelayMs));
683
- const retryOrder = await this.#transakPost('createOrder', '/api/v2/orders', TransakOrderStruct, {
511
+ const retryOrder = await this.#transakPost('/api/v2/orders', {
684
512
  quoteId,
685
513
  walletAddress,
686
514
  paymentInstrumentId,
@@ -700,7 +528,7 @@ export class TransakService extends BaseDataService {
700
528
  depositOrderId = TransakOrderIdTransformer.transakOrderIdToDepositOrderId(orderId, this.#environment);
701
529
  }
702
530
  const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(depositOrderId);
703
- const order = await this.#ordersApiGet('getOrder', `/orders/${transakOrderId}`, DepositOrderStruct, { wallet });
531
+ const order = await this.#ordersApiGet(`/orders/${transakOrderId}`, { wallet });
704
532
  const orderWithId = {
705
533
  ...order,
706
534
  id: depositOrderId,
@@ -711,7 +539,7 @@ export class TransakService extends BaseDataService {
711
539
  }
712
540
  if (this.#accessToken?.accessToken) {
713
541
  try {
714
- const transakOrder = await this.#transakGet('getOrderPaymentDetails', `/api/v2/orders/${transakOrderId}`, TransakOrderPaymentDetailsStruct);
542
+ const transakOrder = await this.#transakGet(`/api/v2/orders/${transakOrderId}`);
715
543
  return { ...orderWithId, paymentDetails: transakOrder.paymentDetails };
716
544
  }
717
545
  catch {
@@ -733,7 +561,7 @@ export class TransakService extends BaseDataService {
733
561
  if (translation.paymentMethod) {
734
562
  params.paymentCategory = translation.paymentMethod;
735
563
  }
736
- return this.#transakGet('getUserLimits', '/api/v2/orders/user-limit', UserLimitsStruct, params);
564
+ return this.#transakGet('/api/v2/orders/user-limit', params);
737
565
  }
738
566
  /**
739
567
  * @deprecated Use {@link createWidgetUrl} instead. The OTT flow requires the
@@ -742,7 +570,7 @@ export class TransakService extends BaseDataService {
742
570
  */
743
571
  async requestOtt() {
744
572
  this.#ensureAccessToken();
745
- const result = await this.#transakPost('requestOtt', '/api/v2/auth/request-ott', OttStruct);
573
+ const result = await this.#transakPost('/api/v2/auth/request-ott');
746
574
  return result;
747
575
  }
748
576
  /**
@@ -798,7 +626,7 @@ export class TransakService extends BaseDataService {
798
626
  */
799
627
  async createWidgetUrl(quote, walletAddress, extraParams) {
800
628
  this.#ensureAccessToken();
801
- const bearerToken = await this.messenger.call('AuthenticationController:getBearerToken');
629
+ const bearerToken = await this.#messenger.call('AuthenticationController:getBearerToken');
802
630
  const baseUrl = this.#getRampsApiBaseUrl();
803
631
  const providerPath = getRampsProviderPath(this.#environment);
804
632
  const url = new URL(`${providerPath}/widget-url`, baseUrl);
@@ -825,32 +653,32 @@ export class TransakService extends BaseDataService {
825
653
  if (this.#accessToken?.accessToken) {
826
654
  headers['x-transak-access-token'] = this.#accessToken.accessToken;
827
655
  }
828
- const response = (await this.#sendMutation({
829
- mutationName: 'createWidgetUrl',
830
- url,
831
- init: {
656
+ const response = await this.#policy.execute(async () => {
657
+ const fetchResponse = await this.#fetch(url.toString(), {
832
658
  method: 'POST',
833
659
  headers,
834
660
  body: JSON.stringify({ widgetParams }),
835
- },
836
- responseStruct: WidgetUrlResponseStruct,
837
- }));
661
+ });
662
+ if (!fetchResponse.ok) {
663
+ await this.#throwTransakApiError(fetchResponse, url);
664
+ }
665
+ return fetchResponse.json();
666
+ });
838
667
  return response.widgetUrl;
839
668
  }
840
669
  async submitPurposeOfUsageForm(purpose) {
841
670
  this.#ensureAccessToken();
842
- await this.#transakPost('submitPurposeOfUsageForm', '/api/v2/kyc/purpose-of-usage', any(), { purposeList: purpose });
671
+ await this.#transakPost('/api/v2/kyc/purpose-of-usage', {
672
+ purposeList: purpose,
673
+ });
843
674
  }
844
675
  async patchUser(data) {
845
676
  this.#ensureAccessToken();
846
- return this.#transakPatch('patchUser', '/api/v2/kyc/user', any(), data);
677
+ return this.#transakPatch('/api/v2/kyc/user', data);
847
678
  }
848
679
  async submitSsnDetails(ssn, quoteId) {
849
680
  this.#ensureAccessToken();
850
- return this.#transakPost('submitSsnDetails', '/api/v2/kyc/ssn', any(), {
851
- ssn,
852
- quoteId,
853
- });
681
+ return this.#transakPost('/api/v2/kyc/ssn', { ssn, quoteId });
854
682
  }
855
683
  async confirmPayment(orderId, paymentMethodId) {
856
684
  this.#ensureAccessToken();
@@ -859,7 +687,7 @@ export class TransakService extends BaseDataService {
859
687
  paymentMethod: normalizedPaymentMethod,
860
688
  });
861
689
  const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(orderId);
862
- return this.#transakPost('confirmPayment', '/api/v2/orders/payment-confirmation', PaymentConfirmationStruct, {
690
+ return this.#transakPost('/api/v2/orders/payment-confirmation', {
863
691
  orderId: transakOrderId,
864
692
  paymentMethod: translation.paymentMethod ?? normalizedPaymentMethod,
865
693
  });
@@ -874,38 +702,31 @@ export class TransakService extends BaseDataService {
874
702
  ...translationRequest,
875
703
  paymentMethod: normalizePaymentMethodForTranslation(translationRequest.paymentMethod),
876
704
  };
877
- const params = {};
878
705
  for (const [key, value] of Object.entries(normalizedRequest)) {
879
706
  if (value !== undefined) {
880
707
  url.searchParams.set(key, value);
881
- params[key] = value;
882
708
  }
883
709
  }
884
- return (await this.fetchQuery({
885
- queryKey: [`${this.name}:getTranslation`, params],
886
- staleTime: 0,
887
- gcTime: 0,
888
- responseStruct: TranslationStruct,
889
- queryFn: async () => {
890
- const fetchResponse = await this.#fetch(url.toString(), {
891
- method: 'GET',
892
- headers: { Accept: 'application/json' },
893
- });
894
- if (!fetchResponse.ok) {
895
- throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
896
- }
897
- return (await fetchResponse.json());
898
- },
899
- }));
710
+ const response = await this.#policy.execute(async () => {
711
+ const fetchResponse = await this.#fetch(url.toString(), {
712
+ method: 'GET',
713
+ headers: { Accept: 'application/json' },
714
+ });
715
+ if (!fetchResponse.ok) {
716
+ throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
717
+ }
718
+ return fetchResponse.json();
719
+ });
720
+ return response;
900
721
  }
901
722
  async getIdProofStatus(workFlowRunId) {
902
723
  this.#ensureAccessToken();
903
- return this.#transakGet('getIdProofStatus', '/api/v2/kyc/id-proof-status', IdProofStatusStruct, { workFlowRunId });
724
+ return this.#transakGet('/api/v2/kyc/id-proof-status', { workFlowRunId });
904
725
  }
905
726
  async cancelOrder(depositOrderId) {
906
727
  this.#ensureAccessToken();
907
728
  const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(depositOrderId);
908
- await this.#transakDelete('cancelOrder', `/api/v2/orders/${transakOrderId}`, {
729
+ await this.#transakDelete(`/api/v2/orders/${transakOrderId}`, {
909
730
  cancelReason: 'Creating new order',
910
731
  });
911
732
  }
@@ -926,7 +747,7 @@ export class TransakService extends BaseDataService {
926
747
  }
927
748
  async getActiveOrders() {
928
749
  this.#ensureAccessToken();
929
- return this.#transakGet('getActiveOrders', '/api/v2/active-orders', ActiveOrdersStruct);
750
+ return this.#transakGet('/api/v2/active-orders');
930
751
  }
931
752
  }
932
753
  //# sourceMappingURL=TransakService.js.map