@shipengine/js-api 1.1.0 → 1.2.0
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/errors/utils.d.ts +5 -2
- package/index.js +18 -2
- package/index.mjs +18 -3
- package/package.json +1 -1
- package/themes/types.d.ts +2 -0
package/errors/utils.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { SE } from "..";
|
|
2
|
+
import { ApiError } from "../client";
|
|
1
3
|
import { CodedError } from "./types";
|
|
2
|
-
export declare const isCodedErrors: (errs: any) => errs is CodedError[];
|
|
3
|
-
export declare const isCodedError: (err: any) => err is CodedError;
|
|
4
|
+
export declare const isCodedErrors: (errs: any) => errs is SE.CodedError[];
|
|
5
|
+
export declare const isCodedError: (err: any) => err is SE.CodedError;
|
|
4
6
|
export declare const isDataCodedErrors: (data: any) => data is {
|
|
5
7
|
errors: CodedError[];
|
|
6
8
|
};
|
|
7
9
|
export declare const parseError: (err: any) => CodedError[];
|
|
10
|
+
export declare const isInvalidTokenError: (err: ApiError) => boolean;
|
package/index.js
CHANGED
|
@@ -244,6 +244,21 @@ const parseError = (err) => {
|
|
|
244
244
|
return [new CodedError(err.message)];
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
|
+
const nonTokenRelatedErrors = [
|
|
248
|
+
"The JWT `scope` claim is invalid.",
|
|
249
|
+
"Missing required scopes for this request.",
|
|
250
|
+
"Your Stamps.com username or password are invalid",
|
|
251
|
+
"Authorization has been denied for this request."
|
|
252
|
+
];
|
|
253
|
+
const isInvalidTokenError = (err) => {
|
|
254
|
+
var _a;
|
|
255
|
+
const response = err.response;
|
|
256
|
+
const responseData = (_a = err.response) == null ? void 0 : _a.data;
|
|
257
|
+
if ((response == null ? void 0 : response.status) === 401 && responseData.errorSource === "shipengine" && responseData.errorType === "security" && !nonTokenRelatedErrors.includes(responseData.message)) {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
};
|
|
247
262
|
|
|
248
263
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
249
264
|
|
|
@@ -3991,7 +4006,7 @@ class ShipEngineAPI {
|
|
|
3991
4006
|
return res;
|
|
3992
4007
|
},
|
|
3993
4008
|
(err) => __async(this, null, function* () {
|
|
3994
|
-
var _a, _b, _c, _d, _e
|
|
4009
|
+
var _a, _b, _c, _d, _e;
|
|
3995
4010
|
logger.error(
|
|
3996
4011
|
{ err, req: err.config, res: err.response },
|
|
3997
4012
|
"%s %s: %s %s - %s",
|
|
@@ -4001,7 +4016,7 @@ class ShipEngineAPI {
|
|
|
4001
4016
|
(_e = err.response) == null ? void 0 : _e.statusText,
|
|
4002
4017
|
err.message
|
|
4003
4018
|
);
|
|
4004
|
-
if ((
|
|
4019
|
+
if (isInvalidTokenError(err)) {
|
|
4005
4020
|
const token2 = yield getToken();
|
|
4006
4021
|
const config = err.config;
|
|
4007
4022
|
if (config) {
|
|
@@ -4218,4 +4233,5 @@ exports.getEndUserIpAddress = getEndUserIpAddress;
|
|
|
4218
4233
|
exports.isCodedError = isCodedError;
|
|
4219
4234
|
exports.isCodedErrors = isCodedErrors;
|
|
4220
4235
|
exports.isDataCodedErrors = isDataCodedErrors;
|
|
4236
|
+
exports.isInvalidTokenError = isInvalidTokenError;
|
|
4221
4237
|
exports.parseError = parseError;
|
package/index.mjs
CHANGED
|
@@ -240,6 +240,21 @@ const parseError = (err) => {
|
|
|
240
240
|
return [new CodedError(err.message)];
|
|
241
241
|
}
|
|
242
242
|
};
|
|
243
|
+
const nonTokenRelatedErrors = [
|
|
244
|
+
"The JWT `scope` claim is invalid.",
|
|
245
|
+
"Missing required scopes for this request.",
|
|
246
|
+
"Your Stamps.com username or password are invalid",
|
|
247
|
+
"Authorization has been denied for this request."
|
|
248
|
+
];
|
|
249
|
+
const isInvalidTokenError = (err) => {
|
|
250
|
+
var _a;
|
|
251
|
+
const response = err.response;
|
|
252
|
+
const responseData = (_a = err.response) == null ? void 0 : _a.data;
|
|
253
|
+
if ((response == null ? void 0 : response.status) === 401 && responseData.errorSource === "shipengine" && responseData.errorType === "security" && !nonTokenRelatedErrors.includes(responseData.message)) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
};
|
|
243
258
|
|
|
244
259
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
245
260
|
|
|
@@ -3987,7 +4002,7 @@ class ShipEngineAPI {
|
|
|
3987
4002
|
return res;
|
|
3988
4003
|
},
|
|
3989
4004
|
(err) => __async(this, null, function* () {
|
|
3990
|
-
var _a, _b, _c, _d, _e
|
|
4005
|
+
var _a, _b, _c, _d, _e;
|
|
3991
4006
|
logger.error(
|
|
3992
4007
|
{ err, req: err.config, res: err.response },
|
|
3993
4008
|
"%s %s: %s %s - %s",
|
|
@@ -3997,7 +4012,7 @@ class ShipEngineAPI {
|
|
|
3997
4012
|
(_e = err.response) == null ? void 0 : _e.statusText,
|
|
3998
4013
|
err.message
|
|
3999
4014
|
);
|
|
4000
|
-
if ((
|
|
4015
|
+
if (isInvalidTokenError(err)) {
|
|
4001
4016
|
const token2 = yield getToken();
|
|
4002
4017
|
const config = err.config;
|
|
4003
4018
|
if (config) {
|
|
@@ -4180,4 +4195,4 @@ class ShipEngineAPI {
|
|
|
4180
4195
|
}
|
|
4181
4196
|
}
|
|
4182
4197
|
|
|
4183
|
-
export { AccountSettingsAPI, AddressesAPI, CarriersAPI, CodedError, ConfirmationType, ConnectionsAPI, CreditCardVendor, Currency, CustomPackagesAPI, CustomsContentsType, CustomsNonDeliveryType, FundingSourcesAPI, InsuranceAPI, InsuranceProviderType, LabelsAPI, MetadataCapability, MetadataRequirement, MetadataSatisfyingFormTypes, OrderSourcesAPI, RateCardStatus, RateCardsAPI, RatesAPI, types as SE, SalesOrderShipmentsAPI, SalesOrdersAPI, ShipEngineAPI, ShipmentsAPI, ShippingRulesAPI, ThemesAPI, WarehousesAPI, getEndUserIpAddress, isCodedError, isCodedErrors, isDataCodedErrors, parseError };
|
|
4198
|
+
export { AccountSettingsAPI, AddressesAPI, CarriersAPI, CodedError, ConfirmationType, ConnectionsAPI, CreditCardVendor, Currency, CustomPackagesAPI, CustomsContentsType, CustomsNonDeliveryType, FundingSourcesAPI, InsuranceAPI, InsuranceProviderType, LabelsAPI, MetadataCapability, MetadataRequirement, MetadataSatisfyingFormTypes, OrderSourcesAPI, RateCardStatus, RateCardsAPI, RatesAPI, types as SE, SalesOrderShipmentsAPI, SalesOrdersAPI, ShipEngineAPI, ShipmentsAPI, ShippingRulesAPI, ThemesAPI, WarehousesAPI, getEndUserIpAddress, isCodedError, isCodedErrors, isDataCodedErrors, isInvalidTokenError, parseError };
|
package/package.json
CHANGED
package/themes/types.d.ts
CHANGED