@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.
- package/CHANGELOG.md +30 -49
- package/dist/{KycController-method-action-types.d.mts → KycController-method-action-types.d.ts} +35 -7
- package/dist/KycController-method-action-types.d.ts.map +1 -0
- package/dist/{KycController-method-action-types.mjs → KycController-method-action-types.js} +1 -1
- package/dist/KycController-method-action-types.js.map +1 -0
- package/dist/{KycController.d.mts → KycController.d.ts} +87 -45
- package/dist/KycController.d.ts.map +1 -0
- package/dist/KycController.js +1991 -0
- package/dist/KycController.js.map +1 -0
- package/dist/{KycService-method-action-types.d.mts → KycService-method-action-types.d.ts} +16 -16
- package/dist/KycService-method-action-types.d.ts.map +1 -0
- package/dist/{KycService-method-action-types.mjs → KycService-method-action-types.js} +1 -1
- package/dist/KycService-method-action-types.js.map +1 -0
- package/dist/{KycService.d.mts → KycService.d.ts} +23 -23
- package/dist/KycService.d.ts.map +1 -0
- package/dist/{KycService.mjs → KycService.js} +194 -185
- package/dist/KycService.js.map +1 -0
- package/dist/{countryCodes.d.cts → countryCodes.d.ts} +1 -1
- package/dist/countryCodes.d.ts.map +1 -0
- package/dist/{countryCodes.mjs → countryCodes.js} +1 -1
- package/dist/countryCodes.js.map +1 -0
- package/dist/{crypto.d.mts → crypto.d.ts} +1 -1
- package/dist/crypto.d.ts.map +1 -0
- package/dist/{crypto.mjs → crypto.js} +7 -7
- package/dist/crypto.js.map +1 -0
- package/dist/{encoding.d.mts → encoding.d.ts} +1 -1
- package/dist/encoding.d.ts.map +1 -0
- package/dist/{encoding.mjs → encoding.js} +2 -2
- package/dist/encoding.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/{logger.d.cts → logger.d.ts} +2 -3
- package/dist/logger.d.ts.map +1 -0
- package/dist/{logger.mjs → logger.js} +2 -2
- package/dist/logger.js.map +1 -0
- package/dist/{selectors.d.mts → selectors.d.ts} +4 -4
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +2 -2
- package/dist/selectors.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +72 -13
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/dist/ukyc/{constants.d.mts → constants.d.ts} +9 -9
- package/dist/ukyc/constants.d.ts.map +1 -0
- package/dist/ukyc/{constants.mjs → constants.js} +1 -1
- package/dist/ukyc/constants.js.map +1 -0
- package/dist/ukyc/{deriveClientMaterial.d.cts → deriveClientMaterial.d.ts} +1 -1
- package/dist/ukyc/deriveClientMaterial.d.ts.map +1 -0
- package/dist/ukyc/{deriveClientMaterial.mjs → deriveClientMaterial.js} +7 -7
- package/dist/ukyc/deriveClientMaterial.js.map +1 -0
- package/dist/ukyc/{jwtChain.d.mts → jwtChain.d.ts} +1 -1
- package/dist/ukyc/jwtChain.d.ts.map +1 -0
- package/dist/ukyc/{jwtChain.mjs → jwtChain.js} +4 -4
- package/dist/ukyc/jwtChain.js.map +1 -0
- package/dist/ukyc/{localUserSecret.d.mts → localUserSecret.d.ts} +1 -1
- package/dist/ukyc/localUserSecret.d.ts.map +1 -0
- package/dist/ukyc/{localUserSecret.mjs → localUserSecret.js} +4 -4
- package/dist/ukyc/localUserSecret.js.map +1 -0
- package/dist/ukyc/{storageAccessToken.d.mts → storageAccessToken.d.ts} +2 -2
- package/dist/ukyc/storageAccessToken.d.ts.map +1 -0
- package/dist/ukyc/{storageAccessToken.mjs → storageAccessToken.js} +5 -5
- package/dist/ukyc/storageAccessToken.js.map +1 -0
- package/dist/ukyc/{testToken.d.mts → testToken.d.ts} +2 -2
- package/dist/ukyc/testToken.d.ts.map +1 -0
- package/dist/ukyc/{testToken.mjs → testToken.js} +5 -5
- package/dist/ukyc/testToken.js.map +1 -0
- package/dist/ukyc/{wrapEncryptionKey.d.mts → wrapEncryptionKey.d.ts} +1 -1
- package/dist/ukyc/wrapEncryptionKey.d.ts.map +1 -0
- package/dist/ukyc/{wrapEncryptionKey.mjs → wrapEncryptionKey.js} +3 -4
- package/dist/ukyc/wrapEncryptionKey.js.map +1 -0
- package/dist/ukyc/{wrappedRelayPayload.d.mts → wrappedRelayPayload.d.ts} +3 -3
- package/dist/ukyc/wrappedRelayPayload.d.ts.map +1 -0
- package/dist/ukyc/{wrappedRelayPayload.mjs → wrappedRelayPayload.js} +2 -2
- package/dist/ukyc/wrappedRelayPayload.js.map +1 -0
- package/dist/vendorDisclaimerAcceptance.d.ts +39 -0
- package/dist/vendorDisclaimerAcceptance.d.ts.map +1 -0
- package/dist/vendorDisclaimerAcceptance.js +67 -0
- package/dist/vendorDisclaimerAcceptance.js.map +1 -0
- package/dist/vendors/MoonPayFrameHandler.d.ts +74 -0
- package/dist/vendors/MoonPayFrameHandler.d.ts.map +1 -0
- package/dist/vendors/MoonPayFrameHandler.js +218 -0
- package/dist/vendors/MoonPayFrameHandler.js.map +1 -0
- package/package.json +19 -23
- package/dist/KycController-method-action-types.cjs +0 -7
- package/dist/KycController-method-action-types.cjs.map +0 -1
- package/dist/KycController-method-action-types.d.cts +0 -239
- package/dist/KycController-method-action-types.d.cts.map +0 -1
- package/dist/KycController-method-action-types.d.mts.map +0 -1
- package/dist/KycController-method-action-types.mjs.map +0 -1
- package/dist/KycController.cjs +0 -1882
- package/dist/KycController.cjs.map +0 -1
- package/dist/KycController.d.cts +0 -395
- package/dist/KycController.d.cts.map +0 -1
- package/dist/KycController.d.mts.map +0 -1
- package/dist/KycController.mjs +0 -1877
- package/dist/KycController.mjs.map +0 -1
- package/dist/KycService-method-action-types.cjs +0 -7
- package/dist/KycService-method-action-types.cjs.map +0 -1
- package/dist/KycService-method-action-types.d.cts +0 -220
- package/dist/KycService-method-action-types.d.cts.map +0 -1
- package/dist/KycService-method-action-types.d.mts.map +0 -1
- package/dist/KycService-method-action-types.mjs.map +0 -1
- package/dist/KycService.cjs +0 -637
- package/dist/KycService.cjs.map +0 -1
- package/dist/KycService.d.cts +0 -552
- package/dist/KycService.d.cts.map +0 -1
- package/dist/KycService.d.mts.map +0 -1
- package/dist/KycService.mjs.map +0 -1
- package/dist/countryCodes.cjs +0 -274
- package/dist/countryCodes.cjs.map +0 -1
- package/dist/countryCodes.d.cts.map +0 -1
- package/dist/countryCodes.d.mts +0 -18
- package/dist/countryCodes.d.mts.map +0 -1
- package/dist/countryCodes.mjs.map +0 -1
- package/dist/crypto.cjs +0 -154
- package/dist/crypto.cjs.map +0 -1
- package/dist/crypto.d.cts +0 -84
- package/dist/crypto.d.cts.map +0 -1
- package/dist/crypto.d.mts.map +0 -1
- package/dist/crypto.mjs.map +0 -1
- package/dist/encoding.cjs +0 -40
- package/dist/encoding.cjs.map +0 -1
- package/dist/encoding.d.cts +0 -24
- package/dist/encoding.d.cts.map +0 -1
- package/dist/encoding.d.mts.map +0 -1
- package/dist/encoding.mjs.map +0 -1
- package/dist/index.cjs +0 -37
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -19
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -19
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -12
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -9
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -6
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs.map +0 -1
- package/dist/selectors.cjs +0 -30
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -24
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/types.cjs +0 -10
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -217
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/ukyc/constants.cjs +0 -75
- package/dist/ukyc/constants.cjs.map +0 -1
- package/dist/ukyc/constants.d.cts +0 -69
- package/dist/ukyc/constants.d.cts.map +0 -1
- package/dist/ukyc/constants.d.mts.map +0 -1
- package/dist/ukyc/constants.mjs.map +0 -1
- package/dist/ukyc/deriveClientMaterial.cjs +0 -65
- package/dist/ukyc/deriveClientMaterial.cjs.map +0 -1
- package/dist/ukyc/deriveClientMaterial.d.cts.map +0 -1
- package/dist/ukyc/deriveClientMaterial.d.mts +0 -54
- package/dist/ukyc/deriveClientMaterial.d.mts.map +0 -1
- package/dist/ukyc/deriveClientMaterial.mjs.map +0 -1
- package/dist/ukyc/jwtChain.cjs +0 -54
- package/dist/ukyc/jwtChain.cjs.map +0 -1
- package/dist/ukyc/jwtChain.d.cts +0 -40
- package/dist/ukyc/jwtChain.d.cts.map +0 -1
- package/dist/ukyc/jwtChain.d.mts.map +0 -1
- package/dist/ukyc/jwtChain.mjs.map +0 -1
- package/dist/ukyc/localUserSecret.cjs +0 -98
- package/dist/ukyc/localUserSecret.cjs.map +0 -1
- package/dist/ukyc/localUserSecret.d.cts +0 -65
- package/dist/ukyc/localUserSecret.d.cts.map +0 -1
- package/dist/ukyc/localUserSecret.d.mts.map +0 -1
- package/dist/ukyc/localUserSecret.mjs.map +0 -1
- package/dist/ukyc/storageAccessToken.cjs +0 -139
- package/dist/ukyc/storageAccessToken.cjs.map +0 -1
- package/dist/ukyc/storageAccessToken.d.cts +0 -99
- package/dist/ukyc/storageAccessToken.d.cts.map +0 -1
- package/dist/ukyc/storageAccessToken.d.mts.map +0 -1
- package/dist/ukyc/storageAccessToken.mjs.map +0 -1
- package/dist/ukyc/testToken.cjs +0 -61
- package/dist/ukyc/testToken.cjs.map +0 -1
- package/dist/ukyc/testToken.d.cts +0 -50
- package/dist/ukyc/testToken.d.cts.map +0 -1
- package/dist/ukyc/testToken.d.mts.map +0 -1
- package/dist/ukyc/testToken.mjs.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.cjs +0 -31
- package/dist/ukyc/wrapEncryptionKey.cjs.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.d.cts +0 -36
- package/dist/ukyc/wrapEncryptionKey.d.cts.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.d.mts.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.mjs.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.cjs +0 -32
- package/dist/ukyc/wrappedRelayPayload.cjs.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.d.cts +0 -35
- package/dist/ukyc/wrappedRelayPayload.d.cts.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.d.mts.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.mjs.map +0 -1
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
'
|
|
33
|
-
'
|
|
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
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
|
|
194
|
+
this.#fetch = fetchFunction;
|
|
200
195
|
}
|
|
201
196
|
else if (typeof globalThis.fetch === 'function') {
|
|
202
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
// `
|
|
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`,
|
|
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 () =>
|
|
247
|
+
queryFn: async () => this.#requestJson(url, { method: 'GET' }),
|
|
253
248
|
staleTime: inMilliseconds(5, Duration.Minute),
|
|
254
249
|
});
|
|
255
|
-
return
|
|
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',
|
|
265
|
-
const data = await
|
|
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
|
|
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`,
|
|
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
|
|
293
|
+
const data = await this.#requestJson(url, {
|
|
299
294
|
method: 'POST',
|
|
300
295
|
body: JSON.stringify(body),
|
|
301
296
|
});
|
|
302
|
-
const { 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`,
|
|
318
|
-
const data = await
|
|
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
|
|
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`,
|
|
338
|
-
const data = await
|
|
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
|
|
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=`).
|
|
347
|
-
* `
|
|
348
|
-
* {@link
|
|
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
|
|
350
|
+
async fetchSessionDisclaimersByCountry({ country, }) {
|
|
356
351
|
if (country.length !== 3) {
|
|
357
|
-
throw new Error(`KycService.
|
|
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',
|
|
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}:
|
|
363
|
-
queryFn: async () =>
|
|
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
|
|
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
|
|
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
|
|
381
|
-
const url = new URL(`/sessions/${encodeURIComponent(sessionId)}/disclaimers`,
|
|
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}:
|
|
384
|
-
queryFn: async () =>
|
|
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
|
|
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
|
|
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`,
|
|
402
|
-
const data = await
|
|
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
|
|
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',
|
|
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 () =>
|
|
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
|
|
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
|
|
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
|
|
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',
|
|
470
|
-
const data = await
|
|
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
|
|
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`,
|
|
494
|
-
const data = await
|
|
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
|
|
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`,
|
|
512
|
-
const data = await
|
|
513
|
-
return
|
|
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`,
|
|
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 () =>
|
|
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
|
|
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
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
-
|
|
623
|
-
|
|
635
|
+
// DELETE (and similar) endpoints return 204 No Content.
|
|
636
|
+
if (response.status === 204) {
|
|
637
|
+
return null;
|
|
624
638
|
}
|
|
625
|
-
|
|
639
|
+
return (await response.json());
|
|
626
640
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
return (await response.json());
|
|
632
|
-
};
|
|
633
|
-
//# sourceMappingURL=KycService.mjs.map
|
|
641
|
+
}
|
|
642
|
+
//# sourceMappingURL=KycService.js.map
|