@metamask-previews/kyc-controller 0.0.0-preview-8bfa290fb → 0.2.0-preview-0a30e47

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 (203) hide show
  1. package/CHANGELOG.md +30 -49
  2. package/dist/{KycController-method-action-types.d.mts → KycController-method-action-types.d.ts} +35 -7
  3. package/dist/KycController-method-action-types.d.ts.map +1 -0
  4. package/dist/{KycController-method-action-types.mjs → KycController-method-action-types.js} +1 -1
  5. package/dist/KycController-method-action-types.js.map +1 -0
  6. package/dist/{KycController.d.mts → KycController.d.ts} +87 -45
  7. package/dist/KycController.d.ts.map +1 -0
  8. package/dist/KycController.js +1991 -0
  9. package/dist/KycController.js.map +1 -0
  10. package/dist/{KycService-method-action-types.d.mts → KycService-method-action-types.d.ts} +16 -16
  11. package/dist/KycService-method-action-types.d.ts.map +1 -0
  12. package/dist/{KycService-method-action-types.mjs → KycService-method-action-types.js} +1 -1
  13. package/dist/KycService-method-action-types.js.map +1 -0
  14. package/dist/{KycService.d.mts → KycService.d.ts} +23 -23
  15. package/dist/KycService.d.ts.map +1 -0
  16. package/dist/{KycService.mjs → KycService.js} +194 -185
  17. package/dist/KycService.js.map +1 -0
  18. package/dist/{countryCodes.d.cts → countryCodes.d.ts} +1 -1
  19. package/dist/countryCodes.d.ts.map +1 -0
  20. package/dist/{countryCodes.mjs → countryCodes.js} +1 -1
  21. package/dist/countryCodes.js.map +1 -0
  22. package/dist/{crypto.d.mts → crypto.d.ts} +1 -1
  23. package/dist/crypto.d.ts.map +1 -0
  24. package/dist/{crypto.mjs → crypto.js} +7 -7
  25. package/dist/crypto.js.map +1 -0
  26. package/dist/{encoding.d.mts → encoding.d.ts} +1 -1
  27. package/dist/encoding.d.ts.map +1 -0
  28. package/dist/{encoding.mjs → encoding.js} +2 -2
  29. package/dist/encoding.js.map +1 -0
  30. package/dist/index.d.ts +19 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +12 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/{logger.d.cts → logger.d.ts} +2 -3
  35. package/dist/logger.d.ts.map +1 -0
  36. package/dist/{logger.mjs → logger.js} +2 -2
  37. package/dist/logger.js.map +1 -0
  38. package/dist/{selectors.d.mts → selectors.d.ts} +4 -4
  39. package/dist/selectors.d.ts.map +1 -0
  40. package/dist/{selectors.mjs → selectors.js} +2 -2
  41. package/dist/selectors.js.map +1 -0
  42. package/dist/{types.d.cts → types.d.ts} +72 -13
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/{types.mjs → types.js} +1 -1
  45. package/dist/types.js.map +1 -0
  46. package/dist/ukyc/{constants.d.mts → constants.d.ts} +9 -9
  47. package/dist/ukyc/constants.d.ts.map +1 -0
  48. package/dist/ukyc/{constants.mjs → constants.js} +1 -1
  49. package/dist/ukyc/constants.js.map +1 -0
  50. package/dist/ukyc/{deriveClientMaterial.d.cts → deriveClientMaterial.d.ts} +1 -1
  51. package/dist/ukyc/deriveClientMaterial.d.ts.map +1 -0
  52. package/dist/ukyc/{deriveClientMaterial.mjs → deriveClientMaterial.js} +7 -7
  53. package/dist/ukyc/deriveClientMaterial.js.map +1 -0
  54. package/dist/ukyc/{jwtChain.d.mts → jwtChain.d.ts} +1 -1
  55. package/dist/ukyc/jwtChain.d.ts.map +1 -0
  56. package/dist/ukyc/{jwtChain.mjs → jwtChain.js} +4 -4
  57. package/dist/ukyc/jwtChain.js.map +1 -0
  58. package/dist/ukyc/{localUserSecret.d.mts → localUserSecret.d.ts} +1 -1
  59. package/dist/ukyc/localUserSecret.d.ts.map +1 -0
  60. package/dist/ukyc/{localUserSecret.mjs → localUserSecret.js} +4 -4
  61. package/dist/ukyc/localUserSecret.js.map +1 -0
  62. package/dist/ukyc/{storageAccessToken.d.mts → storageAccessToken.d.ts} +2 -2
  63. package/dist/ukyc/storageAccessToken.d.ts.map +1 -0
  64. package/dist/ukyc/{storageAccessToken.mjs → storageAccessToken.js} +5 -5
  65. package/dist/ukyc/storageAccessToken.js.map +1 -0
  66. package/dist/ukyc/{testToken.d.mts → testToken.d.ts} +2 -2
  67. package/dist/ukyc/testToken.d.ts.map +1 -0
  68. package/dist/ukyc/{testToken.mjs → testToken.js} +5 -5
  69. package/dist/ukyc/testToken.js.map +1 -0
  70. package/dist/ukyc/{wrapEncryptionKey.d.mts → wrapEncryptionKey.d.ts} +1 -1
  71. package/dist/ukyc/wrapEncryptionKey.d.ts.map +1 -0
  72. package/dist/ukyc/{wrapEncryptionKey.mjs → wrapEncryptionKey.js} +3 -4
  73. package/dist/ukyc/wrapEncryptionKey.js.map +1 -0
  74. package/dist/ukyc/{wrappedRelayPayload.d.mts → wrappedRelayPayload.d.ts} +3 -3
  75. package/dist/ukyc/wrappedRelayPayload.d.ts.map +1 -0
  76. package/dist/ukyc/{wrappedRelayPayload.mjs → wrappedRelayPayload.js} +2 -2
  77. package/dist/ukyc/wrappedRelayPayload.js.map +1 -0
  78. package/dist/vendorDisclaimerAcceptance.d.ts +39 -0
  79. package/dist/vendorDisclaimerAcceptance.d.ts.map +1 -0
  80. package/dist/vendorDisclaimerAcceptance.js +67 -0
  81. package/dist/vendorDisclaimerAcceptance.js.map +1 -0
  82. package/dist/vendors/MoonPayFrameHandler.d.ts +74 -0
  83. package/dist/vendors/MoonPayFrameHandler.d.ts.map +1 -0
  84. package/dist/vendors/MoonPayFrameHandler.js +218 -0
  85. package/dist/vendors/MoonPayFrameHandler.js.map +1 -0
  86. package/package.json +19 -23
  87. package/dist/KycController-method-action-types.cjs +0 -7
  88. package/dist/KycController-method-action-types.cjs.map +0 -1
  89. package/dist/KycController-method-action-types.d.cts +0 -239
  90. package/dist/KycController-method-action-types.d.cts.map +0 -1
  91. package/dist/KycController-method-action-types.d.mts.map +0 -1
  92. package/dist/KycController-method-action-types.mjs.map +0 -1
  93. package/dist/KycController.cjs +0 -1882
  94. package/dist/KycController.cjs.map +0 -1
  95. package/dist/KycController.d.cts +0 -395
  96. package/dist/KycController.d.cts.map +0 -1
  97. package/dist/KycController.d.mts.map +0 -1
  98. package/dist/KycController.mjs +0 -1877
  99. package/dist/KycController.mjs.map +0 -1
  100. package/dist/KycService-method-action-types.cjs +0 -7
  101. package/dist/KycService-method-action-types.cjs.map +0 -1
  102. package/dist/KycService-method-action-types.d.cts +0 -220
  103. package/dist/KycService-method-action-types.d.cts.map +0 -1
  104. package/dist/KycService-method-action-types.d.mts.map +0 -1
  105. package/dist/KycService-method-action-types.mjs.map +0 -1
  106. package/dist/KycService.cjs +0 -637
  107. package/dist/KycService.cjs.map +0 -1
  108. package/dist/KycService.d.cts +0 -552
  109. package/dist/KycService.d.cts.map +0 -1
  110. package/dist/KycService.d.mts.map +0 -1
  111. package/dist/KycService.mjs.map +0 -1
  112. package/dist/countryCodes.cjs +0 -274
  113. package/dist/countryCodes.cjs.map +0 -1
  114. package/dist/countryCodes.d.cts.map +0 -1
  115. package/dist/countryCodes.d.mts +0 -18
  116. package/dist/countryCodes.d.mts.map +0 -1
  117. package/dist/countryCodes.mjs.map +0 -1
  118. package/dist/crypto.cjs +0 -154
  119. package/dist/crypto.cjs.map +0 -1
  120. package/dist/crypto.d.cts +0 -84
  121. package/dist/crypto.d.cts.map +0 -1
  122. package/dist/crypto.d.mts.map +0 -1
  123. package/dist/crypto.mjs.map +0 -1
  124. package/dist/encoding.cjs +0 -40
  125. package/dist/encoding.cjs.map +0 -1
  126. package/dist/encoding.d.cts +0 -24
  127. package/dist/encoding.d.cts.map +0 -1
  128. package/dist/encoding.d.mts.map +0 -1
  129. package/dist/encoding.mjs.map +0 -1
  130. package/dist/index.cjs +0 -37
  131. package/dist/index.cjs.map +0 -1
  132. package/dist/index.d.cts +0 -19
  133. package/dist/index.d.cts.map +0 -1
  134. package/dist/index.d.mts +0 -19
  135. package/dist/index.d.mts.map +0 -1
  136. package/dist/index.mjs +0 -12
  137. package/dist/index.mjs.map +0 -1
  138. package/dist/logger.cjs +0 -9
  139. package/dist/logger.cjs.map +0 -1
  140. package/dist/logger.d.cts.map +0 -1
  141. package/dist/logger.d.mts +0 -6
  142. package/dist/logger.d.mts.map +0 -1
  143. package/dist/logger.mjs.map +0 -1
  144. package/dist/selectors.cjs +0 -30
  145. package/dist/selectors.cjs.map +0 -1
  146. package/dist/selectors.d.cts +0 -24
  147. package/dist/selectors.d.cts.map +0 -1
  148. package/dist/selectors.d.mts.map +0 -1
  149. package/dist/selectors.mjs.map +0 -1
  150. package/dist/types.cjs +0 -10
  151. package/dist/types.cjs.map +0 -1
  152. package/dist/types.d.cts.map +0 -1
  153. package/dist/types.d.mts +0 -217
  154. package/dist/types.d.mts.map +0 -1
  155. package/dist/types.mjs.map +0 -1
  156. package/dist/ukyc/constants.cjs +0 -75
  157. package/dist/ukyc/constants.cjs.map +0 -1
  158. package/dist/ukyc/constants.d.cts +0 -69
  159. package/dist/ukyc/constants.d.cts.map +0 -1
  160. package/dist/ukyc/constants.d.mts.map +0 -1
  161. package/dist/ukyc/constants.mjs.map +0 -1
  162. package/dist/ukyc/deriveClientMaterial.cjs +0 -65
  163. package/dist/ukyc/deriveClientMaterial.cjs.map +0 -1
  164. package/dist/ukyc/deriveClientMaterial.d.cts.map +0 -1
  165. package/dist/ukyc/deriveClientMaterial.d.mts +0 -54
  166. package/dist/ukyc/deriveClientMaterial.d.mts.map +0 -1
  167. package/dist/ukyc/deriveClientMaterial.mjs.map +0 -1
  168. package/dist/ukyc/jwtChain.cjs +0 -54
  169. package/dist/ukyc/jwtChain.cjs.map +0 -1
  170. package/dist/ukyc/jwtChain.d.cts +0 -40
  171. package/dist/ukyc/jwtChain.d.cts.map +0 -1
  172. package/dist/ukyc/jwtChain.d.mts.map +0 -1
  173. package/dist/ukyc/jwtChain.mjs.map +0 -1
  174. package/dist/ukyc/localUserSecret.cjs +0 -98
  175. package/dist/ukyc/localUserSecret.cjs.map +0 -1
  176. package/dist/ukyc/localUserSecret.d.cts +0 -65
  177. package/dist/ukyc/localUserSecret.d.cts.map +0 -1
  178. package/dist/ukyc/localUserSecret.d.mts.map +0 -1
  179. package/dist/ukyc/localUserSecret.mjs.map +0 -1
  180. package/dist/ukyc/storageAccessToken.cjs +0 -139
  181. package/dist/ukyc/storageAccessToken.cjs.map +0 -1
  182. package/dist/ukyc/storageAccessToken.d.cts +0 -99
  183. package/dist/ukyc/storageAccessToken.d.cts.map +0 -1
  184. package/dist/ukyc/storageAccessToken.d.mts.map +0 -1
  185. package/dist/ukyc/storageAccessToken.mjs.map +0 -1
  186. package/dist/ukyc/testToken.cjs +0 -61
  187. package/dist/ukyc/testToken.cjs.map +0 -1
  188. package/dist/ukyc/testToken.d.cts +0 -50
  189. package/dist/ukyc/testToken.d.cts.map +0 -1
  190. package/dist/ukyc/testToken.d.mts.map +0 -1
  191. package/dist/ukyc/testToken.mjs.map +0 -1
  192. package/dist/ukyc/wrapEncryptionKey.cjs +0 -31
  193. package/dist/ukyc/wrapEncryptionKey.cjs.map +0 -1
  194. package/dist/ukyc/wrapEncryptionKey.d.cts +0 -36
  195. package/dist/ukyc/wrapEncryptionKey.d.cts.map +0 -1
  196. package/dist/ukyc/wrapEncryptionKey.d.mts.map +0 -1
  197. package/dist/ukyc/wrapEncryptionKey.mjs.map +0 -1
  198. package/dist/ukyc/wrappedRelayPayload.cjs +0 -32
  199. package/dist/ukyc/wrappedRelayPayload.cjs.map +0 -1
  200. package/dist/ukyc/wrappedRelayPayload.d.cts +0 -35
  201. package/dist/ukyc/wrappedRelayPayload.d.cts.map +0 -1
  202. package/dist/ukyc/wrappedRelayPayload.d.mts.map +0 -1
  203. package/dist/ukyc/wrappedRelayPayload.mjs.map +0 -1
@@ -1,21 +1,9 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- 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");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- 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");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _KycService_instances, _KycService_fetch, _KycService_baseUrl, _KycService_idosEnclaveBaseUrl, _KycService_idosRelayBaseUrl, _KycService_fetchWellKnownJwks, _KycService_validateResponse, _KycService_requestJson;
13
- import { BaseDataService } from "@metamask/base-data-service";
14
- import { HttpError } from "@metamask/controller-utils";
15
- import { array, assert, boolean, enums, optional, string, StructError, type } from "@metamask/superstruct";
16
- import { Duration, inMilliseconds } from "@metamask/utils";
17
- import { alpha2ToAlpha3 } from "./countryCodes.mjs";
18
- import { UKYC_JWKS_PATH } from "./ukyc/constants.mjs";
1
+ import { BaseDataService } from '@metamask/base-data-service';
2
+ import { HttpError } from '@metamask/controller-utils';
3
+ import { array, assert, boolean, enums, optional, string, StructError, type, } from '@metamask/superstruct';
4
+ import { Duration, inMilliseconds } from '@metamask/utils';
5
+ import { alpha2ToAlpha3 } from './countryCodes.js';
6
+ import { UKYC_JWKS_PATH } from './ukyc/constants.js';
19
7
  // === GENERAL ===
20
8
  /**
21
9
  * The name of the {@link KycService}, used to namespace the service's actions.
@@ -29,8 +17,8 @@ const MESSENGER_EXPOSED_METHODS = [
29
17
  'checkKycRequired',
30
18
  'createVendorCustomer',
31
19
  'submitVendorDisclaimers',
32
- 'fetchDisclaimersCatalog',
33
- 'fetchSessionDisclaimers',
20
+ 'fetchSessionDisclaimersByCountry',
21
+ 'fetchSessionDisclaimersBySessionId',
34
22
  'submitSessionDisclaimers',
35
23
  'fetchKycStatus',
36
24
  'fetchIdosEnclaveJwks',
@@ -119,22 +107,30 @@ const KycUserStatusResponseStruct = type({
119
107
  sumsubSessionId: optional(string()),
120
108
  errorCode: optional(string()),
121
109
  });
122
- const ConsentDocumentStruct = type({
110
+ const CatalogDocumentFields = {
123
111
  key: string(),
124
112
  version: string(),
125
113
  title: string(),
126
114
  url: string(),
115
+ };
116
+ const CatalogDocumentStruct = type(CatalogDocumentFields);
117
+ // Session documents also report whether that version was already consented to.
118
+ const ConsentDocumentStruct = type({
119
+ ...CatalogDocumentFields,
127
120
  consented: boolean(),
128
121
  });
129
- const DisclaimersCatalogFields = {
130
- idOS: array(ConsentDocumentStruct),
131
- kycProvider: array(ConsentDocumentStruct),
132
- };
133
- /** Global catalog from `GET /disclaimers` (no credential-reuse flag). */
134
- const GlobalDisclaimersResponseStruct = type(DisclaimersCatalogFields);
122
+ /**
123
+ * Global catalog from `GET /disclaimers` (no per-document `consented` flag and
124
+ * no credential-reuse flag).
125
+ */
126
+ const GlobalDisclaimersResponseStruct = type({
127
+ idOS: array(CatalogDocumentStruct),
128
+ kycProvider: array(CatalogDocumentStruct),
129
+ });
135
130
  /** Session catalog from `GET`/`POST /sessions/{id}/disclaimers`. */
136
131
  const SessionDisclaimersResponseStruct = type({
137
- ...DisclaimersCatalogFields,
132
+ idOS: array(ConsentDocumentStruct),
133
+ kycProvider: array(ConsentDocumentStruct),
138
134
  credentialReusabilityConsentGiven: boolean(),
139
135
  });
140
136
  // === SERVICE DEFINITION ===
@@ -162,6 +158,10 @@ const SessionDisclaimersResponseStruct = type({
162
158
  * which also means they are not retried by the service policy.
163
159
  */
164
160
  export class KycService extends BaseDataService {
161
+ #fetch;
162
+ #baseUrl;
163
+ #idosEnclaveBaseUrl;
164
+ #idosRelayBaseUrl;
165
165
  /**
166
166
  * Constructs a new KycService.
167
167
  *
@@ -187,19 +187,14 @@ export class KycService extends BaseDataService {
187
187
  queryClientConfig,
188
188
  policyOptions,
189
189
  });
190
- _KycService_instances.add(this);
191
- _KycService_fetch.set(this, void 0);
192
- _KycService_baseUrl.set(this, void 0);
193
- _KycService_idosEnclaveBaseUrl.set(this, void 0);
194
- _KycService_idosRelayBaseUrl.set(this, void 0);
195
190
  // Fall back to the runtime's native `fetch`, bound to `globalThis` so it
196
191
  // can be invoked as a method of this instance without an illegal-invocation
197
192
  // error on platforms that check the receiver.
198
193
  if (fetchFunction) {
199
- __classPrivateFieldSet(this, _KycService_fetch, fetchFunction, "f");
194
+ this.#fetch = fetchFunction;
200
195
  }
201
196
  else if (typeof globalThis.fetch === 'function') {
202
- __classPrivateFieldSet(this, _KycService_fetch, globalThis.fetch.bind(globalThis), "f");
197
+ this.#fetch = globalThis.fetch.bind(globalThis);
203
198
  }
204
199
  else {
205
200
  throw new Error('KycService: fetch is not available globally and was not provided in options. Please inject a fetch implementation.');
@@ -207,9 +202,9 @@ export class KycService extends BaseDataService {
207
202
  if (!baseUrl) {
208
203
  throw new Error('KycService: baseUrl is required');
209
204
  }
210
- __classPrivateFieldSet(this, _KycService_baseUrl, baseUrl, "f");
211
- __classPrivateFieldSet(this, _KycService_idosEnclaveBaseUrl, idosEnclaveBaseUrl ?? '', "f");
212
- __classPrivateFieldSet(this, _KycService_idosRelayBaseUrl, idosRelayBaseUrl ?? '', "f");
205
+ this.#baseUrl = baseUrl;
206
+ this.#idosEnclaveBaseUrl = idosEnclaveBaseUrl ?? '';
207
+ this.#idosRelayBaseUrl = idosRelayBaseUrl ?? '';
213
208
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
214
209
  }
215
210
  /**
@@ -224,7 +219,7 @@ export class KycService extends BaseDataService {
224
219
  // Guard nullish/empty geolocation with the documented domain error rather
225
220
  // than letting `assert(location, string())` surface a superstruct
226
221
  // assertion error (which would change how the failure reads in
227
- // `disclaimersError`).
222
+ // `vendorError`).
228
223
  const alpha2 = typeof location === 'string' ? location.split('-')[0].toUpperCase() : '';
229
224
  if (!alpha2 || alpha2 === 'UNKNOWN') {
230
225
  throw new Error(`Unable to determine country from geolocation (got "${String(location)}").`);
@@ -245,14 +240,14 @@ export class KycService extends BaseDataService {
245
240
  * @returns The disclaimers.
246
241
  */
247
242
  async fetchVendorDisclaimers({ vendor = 'moonpay', country, }) {
248
- const url = new URL(`/vendors/${vendor}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
243
+ const url = new URL(`/vendors/${vendor}/disclaimers`, this.#baseUrl);
249
244
  url.searchParams.set('country', country);
250
245
  const data = await this.fetchQuery({
251
246
  queryKey: [`${this.name}:fetchVendorDisclaimers`, vendor, country],
252
- queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
247
+ queryFn: async () => this.#requestJson(url, { method: 'GET' }),
253
248
  staleTime: inMilliseconds(5, Duration.Minute),
254
249
  });
255
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, DisclaimersResponseStruct, 'disclaimers');
250
+ return this.#validateResponse(data, DisclaimersResponseStruct, 'disclaimers');
256
251
  }
257
252
  /**
258
253
  * Creates a vendor session via the UKYC backend.
@@ -261,12 +256,12 @@ export class KycService extends BaseDataService {
261
256
  * @returns The created session token.
262
257
  */
263
258
  async createSession(params) {
264
- const url = new URL('/vendors/moonpay/sessions', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
265
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
259
+ const url = new URL('/vendors/moonpay/sessions', this.#baseUrl);
260
+ const data = await this.#requestJson(url, {
266
261
  method: 'POST',
267
262
  body: JSON.stringify(params),
268
263
  });
269
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, CreateSessionResponseStruct, 'sessions');
264
+ return this.#validateResponse(data, CreateSessionResponseStruct, 'sessions');
270
265
  }
271
266
  /**
272
267
  * Checks whether KYC is required for the given vendor, country, and
@@ -277,7 +272,7 @@ export class KycService extends BaseDataService {
277
272
  */
278
273
  async checkKycRequired(params) {
279
274
  const vendor = params.vendor ?? 'moonpay';
280
- const url = new URL(`/vendors/${vendor}/kyc-required`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
275
+ const url = new URL(`/vendors/${vendor}/kyc-required`, this.#baseUrl);
281
276
  const capabilities = params.capabilities ?? [{ product: 'ramps' }];
282
277
  const body = vendor === 'moonpay'
283
278
  ? {
@@ -295,11 +290,11 @@ export class KycService extends BaseDataService {
295
290
  throw new Error('checkKycRequired: country is required for vendor "moonpay".');
296
291
  }
297
292
  }
298
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
293
+ const data = await this.#requestJson(url, {
299
294
  method: 'POST',
300
295
  body: JSON.stringify(body),
301
296
  });
302
- const { required } = __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, KycRequiredResponseStruct, 'kyc-required');
297
+ const { required } = this.#validateResponse(data, KycRequiredResponseStruct, 'kyc-required');
303
298
  return { kycRequired: required };
304
299
  }
305
300
  /**
@@ -314,12 +309,12 @@ export class KycService extends BaseDataService {
314
309
  * @returns The vendor customer record (subset validated for controller use).
315
310
  */
316
311
  async createVendorCustomer(params) {
317
- const url = new URL(`/vendors/${params.vendor}/customers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
318
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
312
+ const url = new URL(`/vendors/${params.vendor}/customers`, this.#baseUrl);
313
+ const data = await this.#requestJson(url, {
319
314
  method: 'POST',
320
315
  body: JSON.stringify({ email: params.email }),
321
316
  });
322
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, VendorCustomerResponseStruct, 'vendor customers');
317
+ return this.#validateResponse(data, VendorCustomerResponseStruct, 'vendor customers');
323
318
  }
324
319
  /**
325
320
  * Records vendor T&C acceptance (`POST /vendors/{vendor}/disclaimers`).
@@ -334,72 +329,72 @@ export class KycService extends BaseDataService {
334
329
  * @returns The vendor signing records.
335
330
  */
336
331
  async submitVendorDisclaimers(params) {
337
- const url = new URL(`/vendors/${encodeURIComponent(params.vendor)}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
338
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
332
+ const url = new URL(`/vendors/${encodeURIComponent(params.vendor)}/disclaimers`, this.#baseUrl);
333
+ const data = await this.#requestJson(url, {
339
334
  method: 'POST',
340
335
  body: JSON.stringify({ disclaimerIds: params.disclaimerIds }),
341
336
  });
342
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, VendorSigningsResponseStruct, 'vendor disclaimers');
337
+ return this.#validateResponse(data, VendorSigningsResponseStruct, 'vendor disclaimers');
343
338
  }
344
339
  /**
345
340
  * Fetches the global idOS + KYC-provider disclaimer catalog
346
- * (`GET /disclaimers?country=`). Does not include
347
- * `credentialReusabilityConsentGiven` — that is session-scoped via
348
- * {@link fetchSessionDisclaimers}. Vendor T&Cs continue to come from
349
- * {@link fetchVendorDisclaimers}.
341
+ * (`GET /disclaimers?country=`). Carries no consent state — per-document
342
+ * `consented` flags and `credentialReusabilityConsentGiven` are
343
+ * session-scoped via {@link fetchSessionDisclaimersBySessionId}. Vendor T&Cs continue to
344
+ * come from {@link fetchVendorDisclaimers}.
350
345
  *
351
346
  * @param params - The parameters.
352
347
  * @param params.country - ISO 3166-1 alpha-3 country code.
353
348
  * @returns The catalog documents.
354
349
  */
355
- async fetchDisclaimersCatalog({ country, }) {
350
+ async fetchSessionDisclaimersByCountry({ country, }) {
356
351
  if (country.length !== 3) {
357
- throw new Error(`KycService.fetchDisclaimersCatalog: country must be an ISO 3166-1 alpha-3 code (received "${country}").`);
352
+ throw new Error(`KycService.fetchSessionDisclaimersByCountry: country must be an ISO 3166-1 alpha-3 code (received "${country}").`);
358
353
  }
359
- const url = new URL('/disclaimers', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
354
+ const url = new URL('/disclaimers', this.#baseUrl);
360
355
  url.searchParams.set('country', country);
361
356
  const data = await this.fetchQuery({
362
- queryKey: [`${this.name}:fetchDisclaimersCatalog`, country],
363
- queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
357
+ queryKey: [`${this.name}:fetchSessionDisclaimersByCountry`, country],
358
+ queryFn: async () => this.#requestJson(url, { method: 'GET' }),
364
359
  staleTime: 0,
365
360
  gcTime: 0,
366
361
  });
367
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, GlobalDisclaimersResponseStruct, 'disclaimers');
362
+ return this.#validateResponse(data, GlobalDisclaimersResponseStruct, 'disclaimers');
368
363
  }
369
364
  /**
370
365
  * Fetches the session-scoped idOS + KYC-provider disclaimer catalog
371
366
  * (`GET /sessions/{sessionId}/disclaimers`), including per-session
372
367
  * `consented` flags and `credentialReusabilityConsentGiven`. For the
373
- * pre-session global catalog use {@link fetchDisclaimersCatalog}. Vendor
374
- * T&Cs continue to come from {@link fetchVendorDisclaimers}.
368
+ * pre-session global catalog use {@link fetchSessionDisclaimersByCountry}.
369
+ * Vendor T&Cs continue to come from {@link fetchVendorDisclaimers}.
375
370
  *
376
371
  * @param params - The parameters.
377
372
  * @param params.sessionId - The UKYC session id.
378
373
  * @returns The catalog, including which documents are already consented.
379
374
  */
380
- async fetchSessionDisclaimers({ sessionId, }) {
381
- const url = new URL(`/sessions/${encodeURIComponent(sessionId)}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
375
+ async fetchSessionDisclaimersBySessionId({ sessionId, }) {
376
+ const url = new URL(`/sessions/${encodeURIComponent(sessionId)}/disclaimers`, this.#baseUrl);
382
377
  const data = await this.fetchQuery({
383
- queryKey: [`${this.name}:fetchSessionDisclaimers`, sessionId],
384
- queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
378
+ queryKey: [`${this.name}:fetchSessionDisclaimersBySessionId`, sessionId],
379
+ queryFn: async () => this.#requestJson(url, { method: 'GET' }),
385
380
  // Consent state can change after a POST, so always re-fetch.
386
381
  staleTime: 0,
387
382
  gcTime: 0,
388
383
  });
389
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionDisclaimersResponseStruct, 'session disclaimers');
384
+ return this.#validateResponse(data, SessionDisclaimersResponseStruct, 'session disclaimers');
390
385
  }
391
386
  /**
392
387
  * Records idOS + KYC-provider consents for a UKYC session
393
388
  * (`POST /sessions/{sessionId}/disclaimers`). `key`/`version` pairs must
394
- * match the current catalog from {@link fetchSessionDisclaimers}. A 409
389
+ * match the current catalog from {@link fetchSessionDisclaimersBySessionId}. A 409
395
390
  * means those document versions were already recorded for the session.
396
391
  *
397
392
  * @param params - The consent parameters.
398
393
  * @returns The updated catalog after recording.
399
394
  */
400
395
  async submitSessionDisclaimers(params) {
401
- const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
402
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
396
+ const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/disclaimers`, this.#baseUrl);
397
+ const data = await this.#requestJson(url, {
403
398
  method: 'POST',
404
399
  body: JSON.stringify({
405
400
  idOS: params.idOS,
@@ -407,7 +402,7 @@ export class KycService extends BaseDataService {
407
402
  credentialReusabilityConsentGiven: params.credentialReusabilityConsentGiven,
408
403
  }),
409
404
  });
410
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionDisclaimersResponseStruct, 'session disclaimers');
405
+ return this.#validateResponse(data, SessionDisclaimersResponseStruct, 'session disclaimers');
411
406
  }
412
407
  /**
413
408
  * Fetches the user-keyed simplified KYC status used by Money toast / banner
@@ -416,15 +411,36 @@ export class KycService extends BaseDataService {
416
411
  * @returns The simplified status payload.
417
412
  */
418
413
  async fetchKycStatus() {
419
- const url = new URL('/kyc/status', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
414
+ const url = new URL('/kyc/status', this.#baseUrl);
420
415
  const data = await this.fetchQuery({
421
416
  queryKey: [`${this.name}:fetchKycStatus`],
422
- queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
417
+ queryFn: async () => this.#requestJson(url, { method: 'GET' }),
423
418
  // Status is polled for toast flips, so it must always be fresh.
424
419
  staleTime: 0,
425
420
  gcTime: 0,
426
421
  });
427
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, KycUserStatusResponseStruct, 'kyc status');
422
+ return this.#validateResponse(data, KycUserStatusResponseStruct, 'kyc status');
423
+ }
424
+ /**
425
+ * Fetches a well-known JWKS from `baseUrl`, caching the result for an hour.
426
+ *
427
+ * @param baseUrl - Host base URL that serves `/.well-known/jwks.json`.
428
+ * @param queryName - Cache query-key segment.
429
+ * @param responseLabel - Label used in malformed-response errors.
430
+ * @param missingConfigMessage - Error thrown when `baseUrl` is empty.
431
+ * @returns The JWKS keys.
432
+ */
433
+ async #fetchWellKnownJwks(baseUrl, queryName, responseLabel, missingConfigMessage) {
434
+ if (!baseUrl) {
435
+ throw new Error(missingConfigMessage);
436
+ }
437
+ const url = new URL(UKYC_JWKS_PATH, baseUrl);
438
+ const data = await this.fetchQuery({
439
+ queryKey: [`${this.name}:${queryName}`, baseUrl],
440
+ queryFn: async () => this.#requestJson(url, { method: 'GET' }, { authenticated: false }),
441
+ staleTime: inMilliseconds(1, Duration.Hour),
442
+ });
443
+ return this.#validateResponse(data, JwksResponseStruct, responseLabel);
428
444
  }
429
445
  /**
430
446
  * Fetches the idOS enclave JWKS used to verify the
@@ -437,7 +453,7 @@ export class KycService extends BaseDataService {
437
453
  * @returns The JWKS keys.
438
454
  */
439
455
  async fetchIdosEnclaveJwks() {
440
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_fetchWellKnownJwks).call(this, __classPrivateFieldGet(this, _KycService_idosEnclaveBaseUrl, "f"), 'fetchIdosEnclaveJwks', 'idOS enclave JWKS', 'KycService: idosEnclaveBaseUrl is not configured; cannot fetch JWKS to verify the encryptionDataKey schema.');
456
+ return this.#fetchWellKnownJwks(this.#idosEnclaveBaseUrl, 'fetchIdosEnclaveJwks', 'idOS enclave JWKS', 'KycService: idosEnclaveBaseUrl is not configured; cannot fetch JWKS to verify the encryptionDataKey schema.');
441
457
  }
442
458
  /**
443
459
  * Fetches the idOS relay JWKS used to verify the `ukycCapabilityToken`
@@ -449,7 +465,7 @@ export class KycService extends BaseDataService {
449
465
  * @returns The JWKS keys.
450
466
  */
451
467
  async fetchIdosRelayJwks() {
452
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_fetchWellKnownJwks).call(this, __classPrivateFieldGet(this, _KycService_idosRelayBaseUrl, "f"), 'fetchIdosRelayJwks', 'idOS relay JWKS', 'KycService: idosRelayBaseUrl is not configured; cannot fetch JWKS to verify the ukycCapabilityToken schema.');
468
+ return this.#fetchWellKnownJwks(this.#idosRelayBaseUrl, 'fetchIdosRelayJwks', 'idOS relay JWKS', 'KycService: idosRelayBaseUrl is not configured; cannot fetch JWKS to verify the ukycCapabilityToken schema.');
453
469
  }
454
470
  /**
455
471
  * Creates a UKYC session for the SumSub document-verification sub-flow.
@@ -466,8 +482,8 @@ export class KycService extends BaseDataService {
466
482
  * @returns The UKYC session id and encryption schemas.
467
483
  */
468
484
  async createUkycSession(params) {
469
- const url = new URL('/sessions', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
470
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
485
+ const url = new URL('/sessions', this.#baseUrl);
486
+ const data = await this.#requestJson(url, {
471
487
  method: 'POST',
472
488
  body: JSON.stringify({
473
489
  vendorId: params.vendor ?? 'moonpay',
@@ -478,7 +494,7 @@ export class KycService extends BaseDataService {
478
494
  vendorMetadata: params.vendorMetadata ?? {},
479
495
  }),
480
496
  });
481
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, UkycSessionResponseStruct, 'UKYC sessions');
497
+ return this.#validateResponse(data, UkycSessionResponseStruct, 'UKYC sessions');
482
498
  }
483
499
  /**
484
500
  * Submits the wrapped `data_encryption_key` and wrapped
@@ -490,15 +506,15 @@ export class KycService extends BaseDataService {
490
506
  * @returns The session status after the authorizations are applied.
491
507
  */
492
508
  async setAuthorizations(params) {
493
- const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/authorizations`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
494
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
509
+ const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/authorizations`, this.#baseUrl);
510
+ const data = await this.#requestJson(url, {
495
511
  method: 'POST',
496
512
  body: JSON.stringify({
497
513
  wrappedEncryptionDataKey: params.wrappedEncryptionDataKey,
498
514
  wrappedUkycCapabilityToken: params.wrappedUkycCapabilityToken,
499
515
  }),
500
516
  });
501
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionStatusResponseStruct, 'authorizations');
517
+ return this.#validateResponse(data, SessionStatusResponseStruct, 'authorizations');
502
518
  }
503
519
  /**
504
520
  * Creates (or refreshes) the SumSub verification journey for a UKYC session,
@@ -508,9 +524,9 @@ export class KycService extends BaseDataService {
508
524
  * @returns The applicant access token and status.
509
525
  */
510
526
  async createJourney(sessionId) {
511
- const url = new URL(`/sessions/${encodeURIComponent(sessionId)}/journey`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
512
- const data = await __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'POST' });
513
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, ApplicantAccessTokenResponseStruct, 'journey');
527
+ const url = new URL(`/sessions/${encodeURIComponent(sessionId)}/journey`, this.#baseUrl);
528
+ const data = await this.#requestJson(url, { method: 'POST' });
529
+ return this.#validateResponse(data, ApplicantAccessTokenResponseStruct, 'journey');
514
530
  }
515
531
  /**
516
532
  * Fetches the current status of a UKYC session. Polled after the SumSub SDK
@@ -521,113 +537,106 @@ export class KycService extends BaseDataService {
521
537
  * @returns The session status.
522
538
  */
523
539
  async getSessionStatus(params) {
524
- const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/status`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
540
+ const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/status`, this.#baseUrl);
525
541
  const data = await this.fetchQuery({
526
542
  queryKey: [`${this.name}:getSessionStatus`, params.sessionId],
527
- queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
543
+ queryFn: async () => this.#requestJson(url, { method: 'GET' }),
528
544
  // Status is polled for a terminal decision, so it must always be fresh.
529
545
  staleTime: 0,
530
546
  gcTime: 0,
531
547
  });
532
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionStatusResponseStruct, 'session status');
533
- }
534
- }
535
- _KycService_fetch = new WeakMap(), _KycService_baseUrl = new WeakMap(), _KycService_idosEnclaveBaseUrl = new WeakMap(), _KycService_idosRelayBaseUrl = new WeakMap(), _KycService_instances = new WeakSet(), _KycService_fetchWellKnownJwks =
536
- /**
537
- * Fetches a well-known JWKS from `baseUrl`, caching the result for an hour.
538
- *
539
- * @param baseUrl - Host base URL that serves `/.well-known/jwks.json`.
540
- * @param queryName - Cache query-key segment.
541
- * @param responseLabel - Label used in malformed-response errors.
542
- * @param missingConfigMessage - Error thrown when `baseUrl` is empty.
543
- * @returns The JWKS keys.
544
- */
545
- async function _KycService_fetchWellKnownJwks(baseUrl, queryName, responseLabel, missingConfigMessage) {
546
- if (!baseUrl) {
547
- throw new Error(missingConfigMessage);
548
+ return this.#validateResponse(data, SessionStatusResponseStruct, 'session status');
548
549
  }
549
- const url = new URL(UKYC_JWKS_PATH, baseUrl);
550
- const data = await this.fetchQuery({
551
- queryKey: [`${this.name}:${queryName}`, baseUrl],
552
- queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }, { authenticated: false }),
553
- staleTime: inMilliseconds(1, Duration.Hour),
554
- });
555
- return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, JwksResponseStruct, responseLabel);
556
- }, _KycService_validateResponse = function _KycService_validateResponse(data, struct, apiName) {
557
- try {
558
- assert(data, struct);
559
- return data;
560
- }
561
- catch (error) {
562
- const detail = error instanceof StructError
563
- ? `${error.message} (received: ${JSON.stringify(data)})`
564
- : // `assert` only ever throws `StructError` for the plain structs used
565
- // here, so this is a defensive fallback that is not exercised.
566
- /* istanbul ignore next */
567
- String(error);
568
- throw new Error(`Malformed response received from ${apiName} API: ${detail}`);
569
- }
570
- }, _KycService_requestJson =
571
- /**
572
- * Performs a single JSON request.
573
- *
574
- * Read endpoints pass this as the `queryFn` to {@link fetchQuery}, which
575
- * wraps it in the shared service policy (retries, circuit breaker). Write
576
- * endpoints call it directly, so they are executed exactly once. Requests
577
- * are authenticated with the wallet bearer token by default; pass
578
- * `{ authenticated: false }` for calls to services that do not expect it
579
- * (e.g. the idOS enclave or idOS relay JWKS endpoints).
580
- *
581
- * @param url - The request URL.
582
- * @param init - The request init (method, body).
583
- * @param options - Request options.
584
- * @param options.authenticated - Whether to attach the bearer token. Defaults
585
- * to `true`.
586
- * @returns The parsed JSON response.
587
- */
588
- async function _KycService_requestJson(url, init, options = {}) {
589
- const { authenticated = true } = options;
590
- const headers = {};
591
- // Only advertise a JSON body when one is actually sent; bodyless requests
592
- // (e.g. `createJourney`) must not carry a `Content-Type`.
593
- if (init.body !== undefined && init.body !== null) {
594
- headers['Content-Type'] = 'application/json';
595
- }
596
- if (authenticated) {
597
- const bearerToken = await this.messenger.call('AuthenticationController:getBearerToken');
598
- if (!bearerToken) {
599
- throw new Error('Unable to obtain an authentication bearer token — is the wallet signed in?');
550
+ /**
551
+ * Validates a parsed API response against a superstruct schema, throwing a
552
+ * descriptive error when the response does not match.
553
+ *
554
+ * Unlike a bare `Struct.is` check, this surfaces exactly which field was
555
+ * missing or had the wrong type, which is essential for diagnosing shape
556
+ * mismatches between the client and the live API.
557
+ *
558
+ * @param data - The parsed response body.
559
+ * @param struct - The superstruct schema the body is expected to satisfy.
560
+ * @param apiName - A human-readable name of the API, used in the error message.
561
+ * @returns The validated, typed response.
562
+ * @throws If `data` does not match `struct`.
563
+ */
564
+ #validateResponse(data, struct, apiName) {
565
+ try {
566
+ assert(data, struct);
567
+ return data;
568
+ }
569
+ catch (error) {
570
+ const detail = error instanceof StructError
571
+ ? `${error.message} (received: ${JSON.stringify(data)})`
572
+ : // `assert` only ever throws `StructError` for the plain structs used
573
+ // here, so this is a defensive fallback that is not exercised.
574
+ /* istanbul ignore next */
575
+ String(error);
576
+ throw new Error(`Malformed response received from ${apiName} API: ${detail}`);
600
577
  }
601
- assert(bearerToken, string());
602
- headers.Authorization = `Bearer ${bearerToken}`;
603
578
  }
604
- const response = await __classPrivateFieldGet(this, _KycService_fetch, "f").call(this, url.toString(), {
605
- ...init,
606
- headers,
607
- });
608
- if (!response.ok) {
609
- let detail = '';
610
- try {
611
- const errorBody = await response.json();
612
- if (errorBody && typeof errorBody === 'object') {
613
- const record = errorBody;
614
- if (typeof record.message === 'string') {
615
- detail = record.message;
616
- }
617
- else if (typeof record.error === 'string') {
618
- detail = record.error;
579
+ /**
580
+ * Performs a single JSON request.
581
+ *
582
+ * Read endpoints pass this as the `queryFn` to {@link fetchQuery}, which
583
+ * wraps it in the shared service policy (retries, circuit breaker). Write
584
+ * endpoints call it directly, so they are executed exactly once. Requests
585
+ * are authenticated with the wallet bearer token by default; pass
586
+ * `{ authenticated: false }` for calls to services that do not expect it
587
+ * (e.g. the idOS enclave or idOS relay JWKS endpoints).
588
+ *
589
+ * @param url - The request URL.
590
+ * @param init - The request init (method, body).
591
+ * @param options - Request options.
592
+ * @param options.authenticated - Whether to attach the bearer token. Defaults
593
+ * to `true`.
594
+ * @returns The parsed JSON response.
595
+ */
596
+ async #requestJson(url, init, options = {}) {
597
+ const { authenticated = true } = options;
598
+ const headers = {};
599
+ // Only advertise a JSON body when one is actually sent; bodyless requests
600
+ // (e.g. `createJourney`) must not carry a `Content-Type`.
601
+ if (init.body !== undefined && init.body !== null) {
602
+ headers['Content-Type'] = 'application/json';
603
+ }
604
+ if (authenticated) {
605
+ const bearerToken = await this.messenger.call('AuthenticationController:getBearerToken');
606
+ if (!bearerToken) {
607
+ throw new Error('Unable to obtain an authentication bearer token — is the wallet signed in?');
608
+ }
609
+ assert(bearerToken, string());
610
+ headers.Authorization = `Bearer ${bearerToken}`;
611
+ }
612
+ const response = await this.#fetch(url.toString(), {
613
+ ...init,
614
+ headers,
615
+ });
616
+ if (!response.ok) {
617
+ let detail = '';
618
+ try {
619
+ const errorBody = await response.json();
620
+ if (errorBody && typeof errorBody === 'object') {
621
+ const record = errorBody;
622
+ if (typeof record.message === 'string') {
623
+ detail = record.message;
624
+ }
625
+ else if (typeof record.error === 'string') {
626
+ detail = record.error;
627
+ }
619
628
  }
620
629
  }
630
+ catch {
631
+ // Ignore body parse failures; status alone is still useful.
632
+ }
633
+ throw new HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'${detail ? `: ${detail}` : ''}`);
621
634
  }
622
- catch {
623
- // Ignore body parse failures; status alone is still useful.
635
+ // DELETE (and similar) endpoints return 204 No Content.
636
+ if (response.status === 204) {
637
+ return null;
624
638
  }
625
- throw new HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'${detail ? `: ${detail}` : ''}`);
639
+ return (await response.json());
626
640
  }
627
- // DELETE (and similar) endpoints return 204 No Content.
628
- if (response.status === 204) {
629
- return null;
630
- }
631
- return (await response.json());
632
- };
633
- //# sourceMappingURL=KycService.mjs.map
641
+ }
642
+ //# sourceMappingURL=KycService.js.map