@dynamic-labs-wallet/core 1.1.64 → 1.1.65
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/index.cjs +194 -143
- package/index.esm.js +194 -143
- package/package.json +2 -2
- package/src/eventStream/utils.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -811,6 +811,145 @@ var _Logger;
|
|
|
811
811
|
}
|
|
812
812
|
}, _Logger._instance = new NoopLogger(), _Logger._context = {}, _Logger);
|
|
813
813
|
|
|
814
|
+
class WalletApiError extends Error {
|
|
815
|
+
constructor(status, message, code){
|
|
816
|
+
super(message);
|
|
817
|
+
this.name = 'WalletApiError';
|
|
818
|
+
this.status = status;
|
|
819
|
+
this.code = code;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
const getResponseRecord = (error)=>{
|
|
823
|
+
var _error_response;
|
|
824
|
+
const data = (_error_response = error.response) == null ? void 0 : _error_response.data;
|
|
825
|
+
return data && typeof data === 'object' ? data : undefined;
|
|
826
|
+
};
|
|
827
|
+
// The Key Share Service returns its machine-readable cause under `error_code`; other
|
|
828
|
+
// backends use `code` or a bare `error`. Exported for callers that must skip handleAxiosError's own logging.
|
|
829
|
+
const extractServerErrorCode = (error)=>{
|
|
830
|
+
const record = getResponseRecord(error);
|
|
831
|
+
const candidates = [
|
|
832
|
+
record == null ? void 0 : record['code'],
|
|
833
|
+
record == null ? void 0 : record['error_code'],
|
|
834
|
+
record == null ? void 0 : record['error']
|
|
835
|
+
];
|
|
836
|
+
return candidates.find((value)=>typeof value === 'string');
|
|
837
|
+
};
|
|
838
|
+
const INTERNAL_SERVER_ERROR_MESSAGE = 'Internal server error';
|
|
839
|
+
/**
|
|
840
|
+
* `status` for a request that never received an HTTP response at all — the
|
|
841
|
+
* client lost connectivity, the request was aborted, DNS/TLS failed, or CORS
|
|
842
|
+
* blocked it. 0 matches the XHR/`fetch` convention for "no response".
|
|
843
|
+
*
|
|
844
|
+
* This used to be reported as `500 Internal server error`, which made a
|
|
845
|
+
* client-side network failure indistinguishable from a backend fault: the
|
|
846
|
+
* "Backend 500s" monitor counted 1,395 events on a day when the API returned
|
|
847
|
+
* only 33 real 5xx responses.
|
|
848
|
+
*/ const NETWORK_ERROR_STATUS = 0;
|
|
849
|
+
const NETWORK_ERROR_CODE = 'NETWORK_ERROR';
|
|
850
|
+
const NETWORK_ERROR_MESSAGE = 'Network error - no response received';
|
|
851
|
+
const STATUS_MESSAGES = {
|
|
852
|
+
400: 'Invalid request',
|
|
853
|
+
403: 'Forbidden',
|
|
854
|
+
422: 'Unprocessable content',
|
|
855
|
+
429: 'Rate limited',
|
|
856
|
+
500: INTERNAL_SERVER_ERROR_MESSAGE
|
|
857
|
+
};
|
|
858
|
+
const MISSING_AUTH_MESSAGE = 'Authorization header or cookie missing';
|
|
859
|
+
// A 401 can mean the request carried no credentials, or carried credentials the
|
|
860
|
+
// backend rejected — the two need different messages. The Authorization header
|
|
861
|
+
// is readable so we can confirm its presence; the auth cookie is httpOnly, so we
|
|
862
|
+
// can only report whether cookie mode was enabled (`withCredentials`), not that a
|
|
863
|
+
// cookie was actually attached.
|
|
864
|
+
const getRequestCredentials = (error)=>{
|
|
865
|
+
var _error_config, _error_config1;
|
|
866
|
+
const requestHeaders = (_error_config = error.config) == null ? void 0 : _error_config.headers;
|
|
867
|
+
var _requestHeaders_Authorization;
|
|
868
|
+
const hasAuthorizationHeader = Boolean((_requestHeaders_Authorization = requestHeaders == null ? void 0 : requestHeaders['Authorization']) != null ? _requestHeaders_Authorization : requestHeaders == null ? void 0 : requestHeaders['authorization']);
|
|
869
|
+
const usesCookieAuth = Boolean((_error_config1 = error.config) == null ? void 0 : _error_config1.withCredentials);
|
|
870
|
+
return {
|
|
871
|
+
hasAuthorizationHeader,
|
|
872
|
+
usesCookieAuth
|
|
873
|
+
};
|
|
874
|
+
};
|
|
875
|
+
const resolveUnauthorizedMessage = (error)=>{
|
|
876
|
+
const { hasAuthorizationHeader, usesCookieAuth } = getRequestCredentials(error);
|
|
877
|
+
if (!hasAuthorizationHeader && !usesCookieAuth) {
|
|
878
|
+
return MISSING_AUTH_MESSAGE;
|
|
879
|
+
}
|
|
880
|
+
const credentialDescriptions = [];
|
|
881
|
+
if (hasAuthorizationHeader) {
|
|
882
|
+
credentialDescriptions.push('Authorization header present');
|
|
883
|
+
}
|
|
884
|
+
if (usesCookieAuth) {
|
|
885
|
+
credentialDescriptions.push('withCredentials enabled (cookie auth)');
|
|
886
|
+
}
|
|
887
|
+
return `Unauthorized (${credentialDescriptions.join(', ')})`;
|
|
888
|
+
};
|
|
889
|
+
const resolveStatusMessage = (status, error)=>{
|
|
890
|
+
if (status === 401) {
|
|
891
|
+
return resolveUnauthorizedMessage(error);
|
|
892
|
+
}
|
|
893
|
+
if (status && STATUS_MESSAGES[status]) {
|
|
894
|
+
return STATUS_MESSAGES[status];
|
|
895
|
+
}
|
|
896
|
+
return undefined;
|
|
897
|
+
};
|
|
898
|
+
const handleAxiosError = (error, message, context, /**
|
|
899
|
+
* Optional severity hint from the caller, for failures the caller knows are
|
|
900
|
+
* expected (e.g. a business-rule rejection). It can only *lower* severity to
|
|
901
|
+
* `warn` — a caller must not be able to escalate, and a genuine 5xx has to
|
|
902
|
+
* stay at `error` regardless of what the call site believes.
|
|
903
|
+
*
|
|
904
|
+
* Without this the hint that `logError` accepts was silently discarded for
|
|
905
|
+
* every AxiosError, which is the most common error type in the SDK.
|
|
906
|
+
*/ options)=>{
|
|
907
|
+
var _error_config, _error_config1, _error_response, _error_response1, _error_response2;
|
|
908
|
+
const requestUrl = (_error_config = error.config) == null ? void 0 : _error_config.url;
|
|
909
|
+
const requestBaseUrl = (_error_config1 = error.config) == null ? void 0 : _error_config1.baseURL;
|
|
910
|
+
// The HTTP status MUST NOT be logged as a top-level `status` field: Datadog
|
|
911
|
+
// reserves `status` for the log level and its remapper turns a numeric value
|
|
912
|
+
// into `info`, silently burying every 4xx/5xx we emit here. `http.status_code`
|
|
913
|
+
// is Datadog's standard attribute, so the level survives and these logs join
|
|
914
|
+
// against edge/CDN logs on the same field.
|
|
915
|
+
const logPayload = _extends({
|
|
916
|
+
message,
|
|
917
|
+
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
918
|
+
http: {
|
|
919
|
+
status_code: (_error_response1 = error.response) == null ? void 0 : _error_response1.status
|
|
920
|
+
}
|
|
921
|
+
}, requestBaseUrl && {
|
|
922
|
+
requestBaseUrl
|
|
923
|
+
}, requestUrl && {
|
|
924
|
+
requestUrl
|
|
925
|
+
}, {
|
|
926
|
+
context
|
|
927
|
+
});
|
|
928
|
+
const status = (_error_response2 = error.response) == null ? void 0 : _error_response2.status;
|
|
929
|
+
// A 429 (Too Many Requests) is a transient rate-limit signal, not a code or
|
|
930
|
+
// logic failure — and a request that never got a response is a client-side
|
|
931
|
+
// connectivity problem, not a server fault. Both are logged at `warn` so they
|
|
932
|
+
// don't pollute error dashboards or trigger PagerDuty. The 429 case covers
|
|
933
|
+
// both Cloudflare WAF blocks and application-level rate limiting.
|
|
934
|
+
const inferredLevel = status === 429 || status === undefined ? 'warn' : 'error';
|
|
935
|
+
// A 5xx is a server fault: no call site is entitled to downgrade it, however
|
|
936
|
+
// expected it believes the failure to be. The hint only applies below 500.
|
|
937
|
+
const isServerFault = status !== undefined && status >= 500;
|
|
938
|
+
const logLevel = (options == null ? void 0 : options.level) === 'warn' && !isServerFault ? 'warn' : inferredLevel;
|
|
939
|
+
Logger[logLevel]('[DynamicWaasWalletClient] Axios error: ', logPayload);
|
|
940
|
+
// No response at all: report it as such rather than laundering it into a 500.
|
|
941
|
+
if (status === undefined) {
|
|
942
|
+
throw new WalletApiError(NETWORK_ERROR_STATUS, NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE);
|
|
943
|
+
}
|
|
944
|
+
var _resolveStatusMessage;
|
|
945
|
+
// Preserve the real status. Collapsing every unmapped code to 500 made a 404
|
|
946
|
+
// (backup not found) and a 504 (gateway timeout) both surface as
|
|
947
|
+
// "Internal server error", so neither the caller nor a monitor could tell a
|
|
948
|
+
// missing resource from an outage.
|
|
949
|
+
const resolvedMessage = (_resolveStatusMessage = resolveStatusMessage(status, error)) != null ? _resolveStatusMessage : `Request failed with status ${status}`;
|
|
950
|
+
throw new WalletApiError(status, resolvedMessage, extractServerErrorCode(error));
|
|
951
|
+
};
|
|
952
|
+
|
|
814
953
|
/**
|
|
815
954
|
* Thrown when a signMessage/signTransaction SSE stream ends with `consent_required` instead of
|
|
816
955
|
* completing — the wallet belongs to a business account with an unmet signing-quorum requirement.
|
|
@@ -859,11 +998,19 @@ const getElapsedTime = (startTime)=>{
|
|
|
859
998
|
* Reports a request that failed before any response (e.g. a dropped
|
|
860
999
|
* connection) to `onError` and returns the error to reject with. Axios errors
|
|
861
1000
|
* carry request config (incl. auth headers) on the error itself, so onError
|
|
862
|
-
* only gets a fresh error with the message,
|
|
1001
|
+
* only gets a fresh error with the message, HTTP status and backend code (the
|
|
1002
|
+
* 409 recovery predicates key off `code`), never the raw error object.
|
|
863
1003
|
*/ const reportRequestFailure = (err, onError)=>{
|
|
1004
|
+
var _err_response;
|
|
864
1005
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
1006
|
+
const status = err == null ? void 0 : (_err_response = err.response) == null ? void 0 : _err_response.status;
|
|
1007
|
+
const code = extractServerErrorCode(err);
|
|
865
1008
|
try {
|
|
866
|
-
onError == null ? void 0 : onError(new Error(error.message)
|
|
1009
|
+
onError == null ? void 0 : onError(Object.assign(new Error(error.message), _extends({}, status !== undefined && {
|
|
1010
|
+
status
|
|
1011
|
+
}, code && {
|
|
1012
|
+
code
|
|
1013
|
+
})));
|
|
867
1014
|
} catch (observerError) {
|
|
868
1015
|
Logger.warn('Event stream error observer threw', {
|
|
869
1016
|
observerErrorType: observerError instanceof Error ? observerError.name : typeof observerError
|
|
@@ -921,6 +1068,46 @@ const getElapsedTime = (startTime)=>{
|
|
|
921
1068
|
};
|
|
922
1069
|
return pump();
|
|
923
1070
|
};
|
|
1071
|
+
const parseJsonOrText = (text)=>{
|
|
1072
|
+
try {
|
|
1073
|
+
return JSON.parse(text);
|
|
1074
|
+
} catch (e) {
|
|
1075
|
+
return text;
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
const SERVER_ERROR_CODE_KEYS = [
|
|
1079
|
+
'code',
|
|
1080
|
+
'error_code',
|
|
1081
|
+
'error'
|
|
1082
|
+
];
|
|
1083
|
+
// handleAxiosError logs `response.data` verbatim, so only the machine-readable code fields may survive.
|
|
1084
|
+
const pickServerErrorCodes = (body)=>{
|
|
1085
|
+
if (typeof body !== 'object' || body === null) return undefined;
|
|
1086
|
+
const record = body;
|
|
1087
|
+
return Object.fromEntries(SERVER_ERROR_CODE_KEYS.flatMap((key)=>typeof record[key] === 'string' ? [
|
|
1088
|
+
[
|
|
1089
|
+
key,
|
|
1090
|
+
record[key]
|
|
1091
|
+
]
|
|
1092
|
+
] : []));
|
|
1093
|
+
};
|
|
1094
|
+
/**
|
|
1095
|
+
* With `responseType: 'stream'` an error response's body is an unread stream, so the backend's
|
|
1096
|
+
* `code` never reaches `handleAxiosError`. Replaces it in place with its code fields only.
|
|
1097
|
+
*/ const drainStreamErrorBody = async (err)=>{
|
|
1098
|
+
var _response_data;
|
|
1099
|
+
const response = err == null ? void 0 : err.response;
|
|
1100
|
+
if (!(response == null ? void 0 : (_response_data = response.data) == null ? void 0 : _response_data.getReader)) return;
|
|
1101
|
+
try {
|
|
1102
|
+
Object.assign(response, {
|
|
1103
|
+
data: pickServerErrorCodes(parseJsonOrText(await readStreamToText(response.data.getReader())))
|
|
1104
|
+
});
|
|
1105
|
+
} catch (readError) {
|
|
1106
|
+
Logger.warn('Could not read the error response body', {
|
|
1107
|
+
readError
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
924
1111
|
/**
|
|
925
1112
|
* Creates a promise that resolves when a specific event is received from an event stream.
|
|
926
1113
|
* Adds a timeout to prevent hanging and races the two promises.
|
|
@@ -998,7 +1185,10 @@ const getElapsedTime = (startTime)=>{
|
|
|
998
1185
|
})(response);
|
|
999
1186
|
})// Without onError, a caller that races the ceremony against it (the cached-room
|
|
1000
1187
|
// sign path never awaits this promise) waits out its queue timeout instead.
|
|
1001
|
-
.catch((err)=>
|
|
1188
|
+
.catch(async (err)=>{
|
|
1189
|
+
await drainStreamErrorBody(err);
|
|
1190
|
+
reject(reportRequestFailure(err, onError));
|
|
1191
|
+
});
|
|
1002
1192
|
});
|
|
1003
1193
|
// Add a timeout to prevent hanging
|
|
1004
1194
|
let timeoutId;
|
|
@@ -1297,145 +1487,6 @@ const getElapsedTime = (startTime)=>{
|
|
|
1297
1487
|
}
|
|
1298
1488
|
}
|
|
1299
1489
|
|
|
1300
|
-
class WalletApiError extends Error {
|
|
1301
|
-
constructor(status, message, code){
|
|
1302
|
-
super(message);
|
|
1303
|
-
this.name = 'WalletApiError';
|
|
1304
|
-
this.status = status;
|
|
1305
|
-
this.code = code;
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
const getResponseRecord = (error)=>{
|
|
1309
|
-
var _error_response;
|
|
1310
|
-
const data = (_error_response = error.response) == null ? void 0 : _error_response.data;
|
|
1311
|
-
return data && typeof data === 'object' ? data : undefined;
|
|
1312
|
-
};
|
|
1313
|
-
// The Key Share Service returns its machine-readable cause under `error_code`; other
|
|
1314
|
-
// backends use `code` or a bare `error`. Exported for callers that must skip handleAxiosError's own logging.
|
|
1315
|
-
const extractServerErrorCode = (error)=>{
|
|
1316
|
-
const record = getResponseRecord(error);
|
|
1317
|
-
const candidates = [
|
|
1318
|
-
record == null ? void 0 : record['code'],
|
|
1319
|
-
record == null ? void 0 : record['error_code'],
|
|
1320
|
-
record == null ? void 0 : record['error']
|
|
1321
|
-
];
|
|
1322
|
-
return candidates.find((value)=>typeof value === 'string');
|
|
1323
|
-
};
|
|
1324
|
-
const INTERNAL_SERVER_ERROR_MESSAGE = 'Internal server error';
|
|
1325
|
-
/**
|
|
1326
|
-
* `status` for a request that never received an HTTP response at all — the
|
|
1327
|
-
* client lost connectivity, the request was aborted, DNS/TLS failed, or CORS
|
|
1328
|
-
* blocked it. 0 matches the XHR/`fetch` convention for "no response".
|
|
1329
|
-
*
|
|
1330
|
-
* This used to be reported as `500 Internal server error`, which made a
|
|
1331
|
-
* client-side network failure indistinguishable from a backend fault: the
|
|
1332
|
-
* "Backend 500s" monitor counted 1,395 events on a day when the API returned
|
|
1333
|
-
* only 33 real 5xx responses.
|
|
1334
|
-
*/ const NETWORK_ERROR_STATUS = 0;
|
|
1335
|
-
const NETWORK_ERROR_CODE = 'NETWORK_ERROR';
|
|
1336
|
-
const NETWORK_ERROR_MESSAGE = 'Network error - no response received';
|
|
1337
|
-
const STATUS_MESSAGES = {
|
|
1338
|
-
400: 'Invalid request',
|
|
1339
|
-
403: 'Forbidden',
|
|
1340
|
-
422: 'Unprocessable content',
|
|
1341
|
-
429: 'Rate limited',
|
|
1342
|
-
500: INTERNAL_SERVER_ERROR_MESSAGE
|
|
1343
|
-
};
|
|
1344
|
-
const MISSING_AUTH_MESSAGE = 'Authorization header or cookie missing';
|
|
1345
|
-
// A 401 can mean the request carried no credentials, or carried credentials the
|
|
1346
|
-
// backend rejected — the two need different messages. The Authorization header
|
|
1347
|
-
// is readable so we can confirm its presence; the auth cookie is httpOnly, so we
|
|
1348
|
-
// can only report whether cookie mode was enabled (`withCredentials`), not that a
|
|
1349
|
-
// cookie was actually attached.
|
|
1350
|
-
const getRequestCredentials = (error)=>{
|
|
1351
|
-
var _error_config, _error_config1;
|
|
1352
|
-
const requestHeaders = (_error_config = error.config) == null ? void 0 : _error_config.headers;
|
|
1353
|
-
var _requestHeaders_Authorization;
|
|
1354
|
-
const hasAuthorizationHeader = Boolean((_requestHeaders_Authorization = requestHeaders == null ? void 0 : requestHeaders['Authorization']) != null ? _requestHeaders_Authorization : requestHeaders == null ? void 0 : requestHeaders['authorization']);
|
|
1355
|
-
const usesCookieAuth = Boolean((_error_config1 = error.config) == null ? void 0 : _error_config1.withCredentials);
|
|
1356
|
-
return {
|
|
1357
|
-
hasAuthorizationHeader,
|
|
1358
|
-
usesCookieAuth
|
|
1359
|
-
};
|
|
1360
|
-
};
|
|
1361
|
-
const resolveUnauthorizedMessage = (error)=>{
|
|
1362
|
-
const { hasAuthorizationHeader, usesCookieAuth } = getRequestCredentials(error);
|
|
1363
|
-
if (!hasAuthorizationHeader && !usesCookieAuth) {
|
|
1364
|
-
return MISSING_AUTH_MESSAGE;
|
|
1365
|
-
}
|
|
1366
|
-
const credentialDescriptions = [];
|
|
1367
|
-
if (hasAuthorizationHeader) {
|
|
1368
|
-
credentialDescriptions.push('Authorization header present');
|
|
1369
|
-
}
|
|
1370
|
-
if (usesCookieAuth) {
|
|
1371
|
-
credentialDescriptions.push('withCredentials enabled (cookie auth)');
|
|
1372
|
-
}
|
|
1373
|
-
return `Unauthorized (${credentialDescriptions.join(', ')})`;
|
|
1374
|
-
};
|
|
1375
|
-
const resolveStatusMessage = (status, error)=>{
|
|
1376
|
-
if (status === 401) {
|
|
1377
|
-
return resolveUnauthorizedMessage(error);
|
|
1378
|
-
}
|
|
1379
|
-
if (status && STATUS_MESSAGES[status]) {
|
|
1380
|
-
return STATUS_MESSAGES[status];
|
|
1381
|
-
}
|
|
1382
|
-
return undefined;
|
|
1383
|
-
};
|
|
1384
|
-
const handleAxiosError = (error, message, context, /**
|
|
1385
|
-
* Optional severity hint from the caller, for failures the caller knows are
|
|
1386
|
-
* expected (e.g. a business-rule rejection). It can only *lower* severity to
|
|
1387
|
-
* `warn` — a caller must not be able to escalate, and a genuine 5xx has to
|
|
1388
|
-
* stay at `error` regardless of what the call site believes.
|
|
1389
|
-
*
|
|
1390
|
-
* Without this the hint that `logError` accepts was silently discarded for
|
|
1391
|
-
* every AxiosError, which is the most common error type in the SDK.
|
|
1392
|
-
*/ options)=>{
|
|
1393
|
-
var _error_config, _error_config1, _error_response, _error_response1, _error_response2;
|
|
1394
|
-
const requestUrl = (_error_config = error.config) == null ? void 0 : _error_config.url;
|
|
1395
|
-
const requestBaseUrl = (_error_config1 = error.config) == null ? void 0 : _error_config1.baseURL;
|
|
1396
|
-
// The HTTP status MUST NOT be logged as a top-level `status` field: Datadog
|
|
1397
|
-
// reserves `status` for the log level and its remapper turns a numeric value
|
|
1398
|
-
// into `info`, silently burying every 4xx/5xx we emit here. `http.status_code`
|
|
1399
|
-
// is Datadog's standard attribute, so the level survives and these logs join
|
|
1400
|
-
// against edge/CDN logs on the same field.
|
|
1401
|
-
const logPayload = _extends({
|
|
1402
|
-
message,
|
|
1403
|
-
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
1404
|
-
http: {
|
|
1405
|
-
status_code: (_error_response1 = error.response) == null ? void 0 : _error_response1.status
|
|
1406
|
-
}
|
|
1407
|
-
}, requestBaseUrl && {
|
|
1408
|
-
requestBaseUrl
|
|
1409
|
-
}, requestUrl && {
|
|
1410
|
-
requestUrl
|
|
1411
|
-
}, {
|
|
1412
|
-
context
|
|
1413
|
-
});
|
|
1414
|
-
const status = (_error_response2 = error.response) == null ? void 0 : _error_response2.status;
|
|
1415
|
-
// A 429 (Too Many Requests) is a transient rate-limit signal, not a code or
|
|
1416
|
-
// logic failure — and a request that never got a response is a client-side
|
|
1417
|
-
// connectivity problem, not a server fault. Both are logged at `warn` so they
|
|
1418
|
-
// don't pollute error dashboards or trigger PagerDuty. The 429 case covers
|
|
1419
|
-
// both Cloudflare WAF blocks and application-level rate limiting.
|
|
1420
|
-
const inferredLevel = status === 429 || status === undefined ? 'warn' : 'error';
|
|
1421
|
-
// A 5xx is a server fault: no call site is entitled to downgrade it, however
|
|
1422
|
-
// expected it believes the failure to be. The hint only applies below 500.
|
|
1423
|
-
const isServerFault = status !== undefined && status >= 500;
|
|
1424
|
-
const logLevel = (options == null ? void 0 : options.level) === 'warn' && !isServerFault ? 'warn' : inferredLevel;
|
|
1425
|
-
Logger[logLevel]('[DynamicWaasWalletClient] Axios error: ', logPayload);
|
|
1426
|
-
// No response at all: report it as such rather than laundering it into a 500.
|
|
1427
|
-
if (status === undefined) {
|
|
1428
|
-
throw new WalletApiError(NETWORK_ERROR_STATUS, NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE);
|
|
1429
|
-
}
|
|
1430
|
-
var _resolveStatusMessage;
|
|
1431
|
-
// Preserve the real status. Collapsing every unmapped code to 500 made a 404
|
|
1432
|
-
// (backup not found) and a 504 (gateway timeout) both surface as
|
|
1433
|
-
// "Internal server error", so neither the caller nor a monitor could tell a
|
|
1434
|
-
// missing resource from an outage.
|
|
1435
|
-
const resolvedMessage = (_resolveStatusMessage = resolveStatusMessage(status, error)) != null ? _resolveStatusMessage : `Request failed with status ${status}`;
|
|
1436
|
-
throw new WalletApiError(status, resolvedMessage, extractServerErrorCode(error));
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
1490
|
const getRequiredExternalKeyShareId = (ks)=>{
|
|
1440
1491
|
if (!ks.externalKeyShareId) {
|
|
1441
1492
|
throw new Error(`Missing externalKeyShareId for key share (id: ${ks.id}, keygenId: ${ks.keygenId})`);
|
|
@@ -1450,7 +1501,7 @@ const getRequiredExternalKeyShareId = (ks)=>{
|
|
|
1450
1501
|
* before it is posted and surfaces in Datadog exactly as the recovery path does.
|
|
1451
1502
|
*/ const assertDynamicLocationsHaveExternalKeyShareId = (locations)=>locations.filter((location)=>location.location === BackupLocation.DYNAMIC).forEach((location)=>getRequiredExternalKeyShareId(location));
|
|
1452
1503
|
|
|
1453
|
-
var version = "1.1.
|
|
1504
|
+
var version = "1.1.65";
|
|
1454
1505
|
|
|
1455
1506
|
/**
|
|
1456
1507
|
* Reads the Authorization header off an axios request config, which stores
|
package/index.esm.js
CHANGED
|
@@ -813,6 +813,145 @@ var _Logger;
|
|
|
813
813
|
}
|
|
814
814
|
}, _Logger._instance = new NoopLogger(), _Logger._context = {}, _Logger);
|
|
815
815
|
|
|
816
|
+
class WalletApiError extends Error {
|
|
817
|
+
constructor(status, message, code){
|
|
818
|
+
super(message);
|
|
819
|
+
this.name = 'WalletApiError';
|
|
820
|
+
this.status = status;
|
|
821
|
+
this.code = code;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
const getResponseRecord = (error)=>{
|
|
825
|
+
var _error_response;
|
|
826
|
+
const data = (_error_response = error.response) == null ? void 0 : _error_response.data;
|
|
827
|
+
return data && typeof data === 'object' ? data : undefined;
|
|
828
|
+
};
|
|
829
|
+
// The Key Share Service returns its machine-readable cause under `error_code`; other
|
|
830
|
+
// backends use `code` or a bare `error`. Exported for callers that must skip handleAxiosError's own logging.
|
|
831
|
+
const extractServerErrorCode = (error)=>{
|
|
832
|
+
const record = getResponseRecord(error);
|
|
833
|
+
const candidates = [
|
|
834
|
+
record == null ? void 0 : record['code'],
|
|
835
|
+
record == null ? void 0 : record['error_code'],
|
|
836
|
+
record == null ? void 0 : record['error']
|
|
837
|
+
];
|
|
838
|
+
return candidates.find((value)=>typeof value === 'string');
|
|
839
|
+
};
|
|
840
|
+
const INTERNAL_SERVER_ERROR_MESSAGE = 'Internal server error';
|
|
841
|
+
/**
|
|
842
|
+
* `status` for a request that never received an HTTP response at all — the
|
|
843
|
+
* client lost connectivity, the request was aborted, DNS/TLS failed, or CORS
|
|
844
|
+
* blocked it. 0 matches the XHR/`fetch` convention for "no response".
|
|
845
|
+
*
|
|
846
|
+
* This used to be reported as `500 Internal server error`, which made a
|
|
847
|
+
* client-side network failure indistinguishable from a backend fault: the
|
|
848
|
+
* "Backend 500s" monitor counted 1,395 events on a day when the API returned
|
|
849
|
+
* only 33 real 5xx responses.
|
|
850
|
+
*/ const NETWORK_ERROR_STATUS = 0;
|
|
851
|
+
const NETWORK_ERROR_CODE = 'NETWORK_ERROR';
|
|
852
|
+
const NETWORK_ERROR_MESSAGE = 'Network error - no response received';
|
|
853
|
+
const STATUS_MESSAGES = {
|
|
854
|
+
400: 'Invalid request',
|
|
855
|
+
403: 'Forbidden',
|
|
856
|
+
422: 'Unprocessable content',
|
|
857
|
+
429: 'Rate limited',
|
|
858
|
+
500: INTERNAL_SERVER_ERROR_MESSAGE
|
|
859
|
+
};
|
|
860
|
+
const MISSING_AUTH_MESSAGE = 'Authorization header or cookie missing';
|
|
861
|
+
// A 401 can mean the request carried no credentials, or carried credentials the
|
|
862
|
+
// backend rejected — the two need different messages. The Authorization header
|
|
863
|
+
// is readable so we can confirm its presence; the auth cookie is httpOnly, so we
|
|
864
|
+
// can only report whether cookie mode was enabled (`withCredentials`), not that a
|
|
865
|
+
// cookie was actually attached.
|
|
866
|
+
const getRequestCredentials = (error)=>{
|
|
867
|
+
var _error_config, _error_config1;
|
|
868
|
+
const requestHeaders = (_error_config = error.config) == null ? void 0 : _error_config.headers;
|
|
869
|
+
var _requestHeaders_Authorization;
|
|
870
|
+
const hasAuthorizationHeader = Boolean((_requestHeaders_Authorization = requestHeaders == null ? void 0 : requestHeaders['Authorization']) != null ? _requestHeaders_Authorization : requestHeaders == null ? void 0 : requestHeaders['authorization']);
|
|
871
|
+
const usesCookieAuth = Boolean((_error_config1 = error.config) == null ? void 0 : _error_config1.withCredentials);
|
|
872
|
+
return {
|
|
873
|
+
hasAuthorizationHeader,
|
|
874
|
+
usesCookieAuth
|
|
875
|
+
};
|
|
876
|
+
};
|
|
877
|
+
const resolveUnauthorizedMessage = (error)=>{
|
|
878
|
+
const { hasAuthorizationHeader, usesCookieAuth } = getRequestCredentials(error);
|
|
879
|
+
if (!hasAuthorizationHeader && !usesCookieAuth) {
|
|
880
|
+
return MISSING_AUTH_MESSAGE;
|
|
881
|
+
}
|
|
882
|
+
const credentialDescriptions = [];
|
|
883
|
+
if (hasAuthorizationHeader) {
|
|
884
|
+
credentialDescriptions.push('Authorization header present');
|
|
885
|
+
}
|
|
886
|
+
if (usesCookieAuth) {
|
|
887
|
+
credentialDescriptions.push('withCredentials enabled (cookie auth)');
|
|
888
|
+
}
|
|
889
|
+
return `Unauthorized (${credentialDescriptions.join(', ')})`;
|
|
890
|
+
};
|
|
891
|
+
const resolveStatusMessage = (status, error)=>{
|
|
892
|
+
if (status === 401) {
|
|
893
|
+
return resolveUnauthorizedMessage(error);
|
|
894
|
+
}
|
|
895
|
+
if (status && STATUS_MESSAGES[status]) {
|
|
896
|
+
return STATUS_MESSAGES[status];
|
|
897
|
+
}
|
|
898
|
+
return undefined;
|
|
899
|
+
};
|
|
900
|
+
const handleAxiosError = (error, message, context, /**
|
|
901
|
+
* Optional severity hint from the caller, for failures the caller knows are
|
|
902
|
+
* expected (e.g. a business-rule rejection). It can only *lower* severity to
|
|
903
|
+
* `warn` — a caller must not be able to escalate, and a genuine 5xx has to
|
|
904
|
+
* stay at `error` regardless of what the call site believes.
|
|
905
|
+
*
|
|
906
|
+
* Without this the hint that `logError` accepts was silently discarded for
|
|
907
|
+
* every AxiosError, which is the most common error type in the SDK.
|
|
908
|
+
*/ options)=>{
|
|
909
|
+
var _error_config, _error_config1, _error_response, _error_response1, _error_response2;
|
|
910
|
+
const requestUrl = (_error_config = error.config) == null ? void 0 : _error_config.url;
|
|
911
|
+
const requestBaseUrl = (_error_config1 = error.config) == null ? void 0 : _error_config1.baseURL;
|
|
912
|
+
// The HTTP status MUST NOT be logged as a top-level `status` field: Datadog
|
|
913
|
+
// reserves `status` for the log level and its remapper turns a numeric value
|
|
914
|
+
// into `info`, silently burying every 4xx/5xx we emit here. `http.status_code`
|
|
915
|
+
// is Datadog's standard attribute, so the level survives and these logs join
|
|
916
|
+
// against edge/CDN logs on the same field.
|
|
917
|
+
const logPayload = _extends({
|
|
918
|
+
message,
|
|
919
|
+
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
920
|
+
http: {
|
|
921
|
+
status_code: (_error_response1 = error.response) == null ? void 0 : _error_response1.status
|
|
922
|
+
}
|
|
923
|
+
}, requestBaseUrl && {
|
|
924
|
+
requestBaseUrl
|
|
925
|
+
}, requestUrl && {
|
|
926
|
+
requestUrl
|
|
927
|
+
}, {
|
|
928
|
+
context
|
|
929
|
+
});
|
|
930
|
+
const status = (_error_response2 = error.response) == null ? void 0 : _error_response2.status;
|
|
931
|
+
// A 429 (Too Many Requests) is a transient rate-limit signal, not a code or
|
|
932
|
+
// logic failure — and a request that never got a response is a client-side
|
|
933
|
+
// connectivity problem, not a server fault. Both are logged at `warn` so they
|
|
934
|
+
// don't pollute error dashboards or trigger PagerDuty. The 429 case covers
|
|
935
|
+
// both Cloudflare WAF blocks and application-level rate limiting.
|
|
936
|
+
const inferredLevel = status === 429 || status === undefined ? 'warn' : 'error';
|
|
937
|
+
// A 5xx is a server fault: no call site is entitled to downgrade it, however
|
|
938
|
+
// expected it believes the failure to be. The hint only applies below 500.
|
|
939
|
+
const isServerFault = status !== undefined && status >= 500;
|
|
940
|
+
const logLevel = (options == null ? void 0 : options.level) === 'warn' && !isServerFault ? 'warn' : inferredLevel;
|
|
941
|
+
Logger[logLevel]('[DynamicWaasWalletClient] Axios error: ', logPayload);
|
|
942
|
+
// No response at all: report it as such rather than laundering it into a 500.
|
|
943
|
+
if (status === undefined) {
|
|
944
|
+
throw new WalletApiError(NETWORK_ERROR_STATUS, NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE);
|
|
945
|
+
}
|
|
946
|
+
var _resolveStatusMessage;
|
|
947
|
+
// Preserve the real status. Collapsing every unmapped code to 500 made a 404
|
|
948
|
+
// (backup not found) and a 504 (gateway timeout) both surface as
|
|
949
|
+
// "Internal server error", so neither the caller nor a monitor could tell a
|
|
950
|
+
// missing resource from an outage.
|
|
951
|
+
const resolvedMessage = (_resolveStatusMessage = resolveStatusMessage(status, error)) != null ? _resolveStatusMessage : `Request failed with status ${status}`;
|
|
952
|
+
throw new WalletApiError(status, resolvedMessage, extractServerErrorCode(error));
|
|
953
|
+
};
|
|
954
|
+
|
|
816
955
|
/**
|
|
817
956
|
* Thrown when a signMessage/signTransaction SSE stream ends with `consent_required` instead of
|
|
818
957
|
* completing — the wallet belongs to a business account with an unmet signing-quorum requirement.
|
|
@@ -861,11 +1000,19 @@ const getElapsedTime = (startTime)=>{
|
|
|
861
1000
|
* Reports a request that failed before any response (e.g. a dropped
|
|
862
1001
|
* connection) to `onError` and returns the error to reject with. Axios errors
|
|
863
1002
|
* carry request config (incl. auth headers) on the error itself, so onError
|
|
864
|
-
* only gets a fresh error with the message,
|
|
1003
|
+
* only gets a fresh error with the message, HTTP status and backend code (the
|
|
1004
|
+
* 409 recovery predicates key off `code`), never the raw error object.
|
|
865
1005
|
*/ const reportRequestFailure = (err, onError)=>{
|
|
1006
|
+
var _err_response;
|
|
866
1007
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
1008
|
+
const status = err == null ? void 0 : (_err_response = err.response) == null ? void 0 : _err_response.status;
|
|
1009
|
+
const code = extractServerErrorCode(err);
|
|
867
1010
|
try {
|
|
868
|
-
onError == null ? void 0 : onError(new Error(error.message)
|
|
1011
|
+
onError == null ? void 0 : onError(Object.assign(new Error(error.message), _extends({}, status !== undefined && {
|
|
1012
|
+
status
|
|
1013
|
+
}, code && {
|
|
1014
|
+
code
|
|
1015
|
+
})));
|
|
869
1016
|
} catch (observerError) {
|
|
870
1017
|
Logger.warn('Event stream error observer threw', {
|
|
871
1018
|
observerErrorType: observerError instanceof Error ? observerError.name : typeof observerError
|
|
@@ -923,6 +1070,46 @@ const getElapsedTime = (startTime)=>{
|
|
|
923
1070
|
};
|
|
924
1071
|
return pump();
|
|
925
1072
|
};
|
|
1073
|
+
const parseJsonOrText = (text)=>{
|
|
1074
|
+
try {
|
|
1075
|
+
return JSON.parse(text);
|
|
1076
|
+
} catch (e) {
|
|
1077
|
+
return text;
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
const SERVER_ERROR_CODE_KEYS = [
|
|
1081
|
+
'code',
|
|
1082
|
+
'error_code',
|
|
1083
|
+
'error'
|
|
1084
|
+
];
|
|
1085
|
+
// handleAxiosError logs `response.data` verbatim, so only the machine-readable code fields may survive.
|
|
1086
|
+
const pickServerErrorCodes = (body)=>{
|
|
1087
|
+
if (typeof body !== 'object' || body === null) return undefined;
|
|
1088
|
+
const record = body;
|
|
1089
|
+
return Object.fromEntries(SERVER_ERROR_CODE_KEYS.flatMap((key)=>typeof record[key] === 'string' ? [
|
|
1090
|
+
[
|
|
1091
|
+
key,
|
|
1092
|
+
record[key]
|
|
1093
|
+
]
|
|
1094
|
+
] : []));
|
|
1095
|
+
};
|
|
1096
|
+
/**
|
|
1097
|
+
* With `responseType: 'stream'` an error response's body is an unread stream, so the backend's
|
|
1098
|
+
* `code` never reaches `handleAxiosError`. Replaces it in place with its code fields only.
|
|
1099
|
+
*/ const drainStreamErrorBody = async (err)=>{
|
|
1100
|
+
var _response_data;
|
|
1101
|
+
const response = err == null ? void 0 : err.response;
|
|
1102
|
+
if (!(response == null ? void 0 : (_response_data = response.data) == null ? void 0 : _response_data.getReader)) return;
|
|
1103
|
+
try {
|
|
1104
|
+
Object.assign(response, {
|
|
1105
|
+
data: pickServerErrorCodes(parseJsonOrText(await readStreamToText(response.data.getReader())))
|
|
1106
|
+
});
|
|
1107
|
+
} catch (readError) {
|
|
1108
|
+
Logger.warn('Could not read the error response body', {
|
|
1109
|
+
readError
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
926
1113
|
/**
|
|
927
1114
|
* Creates a promise that resolves when a specific event is received from an event stream.
|
|
928
1115
|
* Adds a timeout to prevent hanging and races the two promises.
|
|
@@ -1000,7 +1187,10 @@ const getElapsedTime = (startTime)=>{
|
|
|
1000
1187
|
})(response);
|
|
1001
1188
|
})// Without onError, a caller that races the ceremony against it (the cached-room
|
|
1002
1189
|
// sign path never awaits this promise) waits out its queue timeout instead.
|
|
1003
|
-
.catch((err)=>
|
|
1190
|
+
.catch(async (err)=>{
|
|
1191
|
+
await drainStreamErrorBody(err);
|
|
1192
|
+
reject(reportRequestFailure(err, onError));
|
|
1193
|
+
});
|
|
1004
1194
|
});
|
|
1005
1195
|
// Add a timeout to prevent hanging
|
|
1006
1196
|
let timeoutId;
|
|
@@ -1299,145 +1489,6 @@ const getElapsedTime = (startTime)=>{
|
|
|
1299
1489
|
}
|
|
1300
1490
|
}
|
|
1301
1491
|
|
|
1302
|
-
class WalletApiError extends Error {
|
|
1303
|
-
constructor(status, message, code){
|
|
1304
|
-
super(message);
|
|
1305
|
-
this.name = 'WalletApiError';
|
|
1306
|
-
this.status = status;
|
|
1307
|
-
this.code = code;
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
const getResponseRecord = (error)=>{
|
|
1311
|
-
var _error_response;
|
|
1312
|
-
const data = (_error_response = error.response) == null ? void 0 : _error_response.data;
|
|
1313
|
-
return data && typeof data === 'object' ? data : undefined;
|
|
1314
|
-
};
|
|
1315
|
-
// The Key Share Service returns its machine-readable cause under `error_code`; other
|
|
1316
|
-
// backends use `code` or a bare `error`. Exported for callers that must skip handleAxiosError's own logging.
|
|
1317
|
-
const extractServerErrorCode = (error)=>{
|
|
1318
|
-
const record = getResponseRecord(error);
|
|
1319
|
-
const candidates = [
|
|
1320
|
-
record == null ? void 0 : record['code'],
|
|
1321
|
-
record == null ? void 0 : record['error_code'],
|
|
1322
|
-
record == null ? void 0 : record['error']
|
|
1323
|
-
];
|
|
1324
|
-
return candidates.find((value)=>typeof value === 'string');
|
|
1325
|
-
};
|
|
1326
|
-
const INTERNAL_SERVER_ERROR_MESSAGE = 'Internal server error';
|
|
1327
|
-
/**
|
|
1328
|
-
* `status` for a request that never received an HTTP response at all — the
|
|
1329
|
-
* client lost connectivity, the request was aborted, DNS/TLS failed, or CORS
|
|
1330
|
-
* blocked it. 0 matches the XHR/`fetch` convention for "no response".
|
|
1331
|
-
*
|
|
1332
|
-
* This used to be reported as `500 Internal server error`, which made a
|
|
1333
|
-
* client-side network failure indistinguishable from a backend fault: the
|
|
1334
|
-
* "Backend 500s" monitor counted 1,395 events on a day when the API returned
|
|
1335
|
-
* only 33 real 5xx responses.
|
|
1336
|
-
*/ const NETWORK_ERROR_STATUS = 0;
|
|
1337
|
-
const NETWORK_ERROR_CODE = 'NETWORK_ERROR';
|
|
1338
|
-
const NETWORK_ERROR_MESSAGE = 'Network error - no response received';
|
|
1339
|
-
const STATUS_MESSAGES = {
|
|
1340
|
-
400: 'Invalid request',
|
|
1341
|
-
403: 'Forbidden',
|
|
1342
|
-
422: 'Unprocessable content',
|
|
1343
|
-
429: 'Rate limited',
|
|
1344
|
-
500: INTERNAL_SERVER_ERROR_MESSAGE
|
|
1345
|
-
};
|
|
1346
|
-
const MISSING_AUTH_MESSAGE = 'Authorization header or cookie missing';
|
|
1347
|
-
// A 401 can mean the request carried no credentials, or carried credentials the
|
|
1348
|
-
// backend rejected — the two need different messages. The Authorization header
|
|
1349
|
-
// is readable so we can confirm its presence; the auth cookie is httpOnly, so we
|
|
1350
|
-
// can only report whether cookie mode was enabled (`withCredentials`), not that a
|
|
1351
|
-
// cookie was actually attached.
|
|
1352
|
-
const getRequestCredentials = (error)=>{
|
|
1353
|
-
var _error_config, _error_config1;
|
|
1354
|
-
const requestHeaders = (_error_config = error.config) == null ? void 0 : _error_config.headers;
|
|
1355
|
-
var _requestHeaders_Authorization;
|
|
1356
|
-
const hasAuthorizationHeader = Boolean((_requestHeaders_Authorization = requestHeaders == null ? void 0 : requestHeaders['Authorization']) != null ? _requestHeaders_Authorization : requestHeaders == null ? void 0 : requestHeaders['authorization']);
|
|
1357
|
-
const usesCookieAuth = Boolean((_error_config1 = error.config) == null ? void 0 : _error_config1.withCredentials);
|
|
1358
|
-
return {
|
|
1359
|
-
hasAuthorizationHeader,
|
|
1360
|
-
usesCookieAuth
|
|
1361
|
-
};
|
|
1362
|
-
};
|
|
1363
|
-
const resolveUnauthorizedMessage = (error)=>{
|
|
1364
|
-
const { hasAuthorizationHeader, usesCookieAuth } = getRequestCredentials(error);
|
|
1365
|
-
if (!hasAuthorizationHeader && !usesCookieAuth) {
|
|
1366
|
-
return MISSING_AUTH_MESSAGE;
|
|
1367
|
-
}
|
|
1368
|
-
const credentialDescriptions = [];
|
|
1369
|
-
if (hasAuthorizationHeader) {
|
|
1370
|
-
credentialDescriptions.push('Authorization header present');
|
|
1371
|
-
}
|
|
1372
|
-
if (usesCookieAuth) {
|
|
1373
|
-
credentialDescriptions.push('withCredentials enabled (cookie auth)');
|
|
1374
|
-
}
|
|
1375
|
-
return `Unauthorized (${credentialDescriptions.join(', ')})`;
|
|
1376
|
-
};
|
|
1377
|
-
const resolveStatusMessage = (status, error)=>{
|
|
1378
|
-
if (status === 401) {
|
|
1379
|
-
return resolveUnauthorizedMessage(error);
|
|
1380
|
-
}
|
|
1381
|
-
if (status && STATUS_MESSAGES[status]) {
|
|
1382
|
-
return STATUS_MESSAGES[status];
|
|
1383
|
-
}
|
|
1384
|
-
return undefined;
|
|
1385
|
-
};
|
|
1386
|
-
const handleAxiosError = (error, message, context, /**
|
|
1387
|
-
* Optional severity hint from the caller, for failures the caller knows are
|
|
1388
|
-
* expected (e.g. a business-rule rejection). It can only *lower* severity to
|
|
1389
|
-
* `warn` — a caller must not be able to escalate, and a genuine 5xx has to
|
|
1390
|
-
* stay at `error` regardless of what the call site believes.
|
|
1391
|
-
*
|
|
1392
|
-
* Without this the hint that `logError` accepts was silently discarded for
|
|
1393
|
-
* every AxiosError, which is the most common error type in the SDK.
|
|
1394
|
-
*/ options)=>{
|
|
1395
|
-
var _error_config, _error_config1, _error_response, _error_response1, _error_response2;
|
|
1396
|
-
const requestUrl = (_error_config = error.config) == null ? void 0 : _error_config.url;
|
|
1397
|
-
const requestBaseUrl = (_error_config1 = error.config) == null ? void 0 : _error_config1.baseURL;
|
|
1398
|
-
// The HTTP status MUST NOT be logged as a top-level `status` field: Datadog
|
|
1399
|
-
// reserves `status` for the log level and its remapper turns a numeric value
|
|
1400
|
-
// into `info`, silently burying every 4xx/5xx we emit here. `http.status_code`
|
|
1401
|
-
// is Datadog's standard attribute, so the level survives and these logs join
|
|
1402
|
-
// against edge/CDN logs on the same field.
|
|
1403
|
-
const logPayload = _extends({
|
|
1404
|
-
message,
|
|
1405
|
-
error: (_error_response = error.response) == null ? void 0 : _error_response.data,
|
|
1406
|
-
http: {
|
|
1407
|
-
status_code: (_error_response1 = error.response) == null ? void 0 : _error_response1.status
|
|
1408
|
-
}
|
|
1409
|
-
}, requestBaseUrl && {
|
|
1410
|
-
requestBaseUrl
|
|
1411
|
-
}, requestUrl && {
|
|
1412
|
-
requestUrl
|
|
1413
|
-
}, {
|
|
1414
|
-
context
|
|
1415
|
-
});
|
|
1416
|
-
const status = (_error_response2 = error.response) == null ? void 0 : _error_response2.status;
|
|
1417
|
-
// A 429 (Too Many Requests) is a transient rate-limit signal, not a code or
|
|
1418
|
-
// logic failure — and a request that never got a response is a client-side
|
|
1419
|
-
// connectivity problem, not a server fault. Both are logged at `warn` so they
|
|
1420
|
-
// don't pollute error dashboards or trigger PagerDuty. The 429 case covers
|
|
1421
|
-
// both Cloudflare WAF blocks and application-level rate limiting.
|
|
1422
|
-
const inferredLevel = status === 429 || status === undefined ? 'warn' : 'error';
|
|
1423
|
-
// A 5xx is a server fault: no call site is entitled to downgrade it, however
|
|
1424
|
-
// expected it believes the failure to be. The hint only applies below 500.
|
|
1425
|
-
const isServerFault = status !== undefined && status >= 500;
|
|
1426
|
-
const logLevel = (options == null ? void 0 : options.level) === 'warn' && !isServerFault ? 'warn' : inferredLevel;
|
|
1427
|
-
Logger[logLevel]('[DynamicWaasWalletClient] Axios error: ', logPayload);
|
|
1428
|
-
// No response at all: report it as such rather than laundering it into a 500.
|
|
1429
|
-
if (status === undefined) {
|
|
1430
|
-
throw new WalletApiError(NETWORK_ERROR_STATUS, NETWORK_ERROR_MESSAGE, NETWORK_ERROR_CODE);
|
|
1431
|
-
}
|
|
1432
|
-
var _resolveStatusMessage;
|
|
1433
|
-
// Preserve the real status. Collapsing every unmapped code to 500 made a 404
|
|
1434
|
-
// (backup not found) and a 504 (gateway timeout) both surface as
|
|
1435
|
-
// "Internal server error", so neither the caller nor a monitor could tell a
|
|
1436
|
-
// missing resource from an outage.
|
|
1437
|
-
const resolvedMessage = (_resolveStatusMessage = resolveStatusMessage(status, error)) != null ? _resolveStatusMessage : `Request failed with status ${status}`;
|
|
1438
|
-
throw new WalletApiError(status, resolvedMessage, extractServerErrorCode(error));
|
|
1439
|
-
};
|
|
1440
|
-
|
|
1441
1492
|
const getRequiredExternalKeyShareId = (ks)=>{
|
|
1442
1493
|
if (!ks.externalKeyShareId) {
|
|
1443
1494
|
throw new Error(`Missing externalKeyShareId for key share (id: ${ks.id}, keygenId: ${ks.keygenId})`);
|
|
@@ -1452,7 +1503,7 @@ const getRequiredExternalKeyShareId = (ks)=>{
|
|
|
1452
1503
|
* before it is posted and surfaces in Datadog exactly as the recovery path does.
|
|
1453
1504
|
*/ const assertDynamicLocationsHaveExternalKeyShareId = (locations)=>locations.filter((location)=>location.location === BackupLocation.DYNAMIC).forEach((location)=>getRequiredExternalKeyShareId(location));
|
|
1454
1505
|
|
|
1455
|
-
var version = "1.1.
|
|
1506
|
+
var version = "1.1.65";
|
|
1456
1507
|
|
|
1457
1508
|
/**
|
|
1458
1509
|
* Reads the Authorization header off an axios request config, which stores
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.65",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@dynamic-labs/sdk-api-core": "0.144.0",
|
|
8
|
-
"@dynamic-labs-wallet/primitives": "1.1.
|
|
8
|
+
"@dynamic-labs-wallet/primitives": "1.1.65",
|
|
9
9
|
"axios": "1.20.0",
|
|
10
10
|
"uuid": "11.1.1"
|
|
11
11
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/eventStream/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/e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