@3dverse/api 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +0 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +18 -6
- package/dist/index.mjs.map +2 -2
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
export declare function setApiKey(apiKey: string): void;
|
2
2
|
export declare function setUserToken(userToken: string): void;
|
3
|
-
export declare function setBaseUrl(url: string): void;
|
4
3
|
declare abstract class ServiceError extends Error {
|
5
4
|
errorCode: number;
|
6
5
|
httpCode: number;
|
package/dist/index.js
CHANGED
@@ -98,7 +98,6 @@ __export(library_exports, {
|
|
98
98
|
setApiKey: () => setApiKey,
|
99
99
|
setAssetThumbnail: () => setAssetThumbnail,
|
100
100
|
setBaseURL: () => setBaseURL,
|
101
|
-
setBaseUrl: () => setBaseUrl,
|
102
101
|
setUserToken: () => setUserToken,
|
103
102
|
updateAssetDescription: () => updateAssetDescription,
|
104
103
|
updateEntity: () => updateEntity,
|
@@ -948,6 +947,7 @@ function generateGuestToken({
|
|
948
947
|
}
|
949
948
|
|
950
949
|
// index.ts
|
950
|
+
var import_axios_retry = __toESM(require("axios-retry"));
|
951
951
|
function setApiKey(apiKey) {
|
952
952
|
axiosInstance.defaults.headers.common["api_key"] = apiKey;
|
953
953
|
delete axiosInstance.defaults.headers.common["user_token"];
|
@@ -956,9 +956,6 @@ function setUserToken(userToken) {
|
|
956
956
|
axiosInstance.defaults.headers.common["user_token"] = userToken;
|
957
957
|
delete axiosInstance.defaults.headers.common["api_key"];
|
958
958
|
}
|
959
|
-
function setBaseUrl(url) {
|
960
|
-
axiosInstance.defaults.baseURL = url;
|
961
|
-
}
|
962
959
|
var ServiceError = class extends Error {
|
963
960
|
errorCode;
|
964
961
|
httpCode;
|
@@ -988,6 +985,11 @@ var UnexpectedServiceError = class extends ServiceError {
|
|
988
985
|
function installInterceptors() {
|
989
986
|
const CLIENT_ERROR = 400;
|
990
987
|
const INTERNAL_SERVER_ERROR = 500;
|
988
|
+
(0, import_axios_retry.default)(axiosInstance, {
|
989
|
+
retries: 5,
|
990
|
+
retryDelay: import_axios_retry.default.exponentialDelay,
|
991
|
+
retryCondition: shouldRetryRequest
|
992
|
+
});
|
991
993
|
axiosInstance.interceptors.response.use(
|
992
994
|
(successFulResponse) => {
|
993
995
|
if (successFulResponse.config.responseType === "stream") {
|
@@ -1005,14 +1007,24 @@ function installInterceptors() {
|
|
1005
1007
|
if (!errorData && axiosError.request.method === "HEAD" && status >= CLIENT_ERROR && status < INTERNAL_SERVER_ERROR) {
|
1006
1008
|
return axiosError.response;
|
1007
1009
|
}
|
1008
|
-
if (!errorData ||
|
1010
|
+
if (!errorData || typeof errorData !== "object") {
|
1009
1011
|
return Promise.reject(new UnexpectedServiceError(status, errorData));
|
1010
1012
|
}
|
1011
|
-
const serviceError = errorData
|
1013
|
+
const serviceError = errorData;
|
1012
1014
|
return Promise.reject(new ApiError(serviceError.errorCode, status, serviceError.message, serviceError));
|
1013
1015
|
}
|
1014
1016
|
);
|
1015
1017
|
}
|
1018
|
+
function shouldRetryRequest(error) {
|
1019
|
+
const status = error.response?.status;
|
1020
|
+
switch (status) {
|
1021
|
+
case 403:
|
1022
|
+
case 404:
|
1023
|
+
return true;
|
1024
|
+
default:
|
1025
|
+
return (0, import_axios_retry.isNetworkError)(error) || (0, import_axios_retry.isIdempotentRequestError)(error);
|
1026
|
+
}
|
1027
|
+
}
|
1016
1028
|
installInterceptors();
|
1017
1029
|
// Annotate the CommonJS export names for ESM import in node:
|
1018
1030
|
0 && (module.exports = {
|
@@ -1085,7 +1097,6 @@ installInterceptors();
|
|
1085
1097
|
setApiKey,
|
1086
1098
|
setAssetThumbnail,
|
1087
1099
|
setBaseURL,
|
1088
|
-
setBaseUrl,
|
1089
1100
|
setUserToken,
|
1090
1101
|
updateAssetDescription,
|
1091
1102
|
updateEntity,
|