@shipengine/js-api 1.0.1 → 1.1.1
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 +27 -2
- package/index.mjs +27 -3
- package/insurance/api.d.ts +4 -0
- package/package.json +1 -1
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
|
|
|
@@ -3501,6 +3516,15 @@ class InsuranceAPI {
|
|
|
3501
3516
|
this.get = (insuranceProvider) => {
|
|
3502
3517
|
return this.client.get(`/v1/insurance/${insuranceProvider}/balance`);
|
|
3503
3518
|
};
|
|
3519
|
+
/**
|
|
3520
|
+
* The `addFunds` method add funds to the account balance of the given `insuranceProvider`.
|
|
3521
|
+
*/
|
|
3522
|
+
this.addFunds = (insuranceProvider, params) => {
|
|
3523
|
+
return this.client.patch(
|
|
3524
|
+
`/v1/insurance/${insuranceProvider}/add_funds`,
|
|
3525
|
+
params
|
|
3526
|
+
);
|
|
3527
|
+
};
|
|
3504
3528
|
this.client = client;
|
|
3505
3529
|
}
|
|
3506
3530
|
}
|
|
@@ -3982,7 +4006,7 @@ class ShipEngineAPI {
|
|
|
3982
4006
|
return res;
|
|
3983
4007
|
},
|
|
3984
4008
|
(err) => __async(this, null, function* () {
|
|
3985
|
-
var _a, _b, _c, _d, _e
|
|
4009
|
+
var _a, _b, _c, _d, _e;
|
|
3986
4010
|
logger.error(
|
|
3987
4011
|
{ err, req: err.config, res: err.response },
|
|
3988
4012
|
"%s %s: %s %s - %s",
|
|
@@ -3992,7 +4016,7 @@ class ShipEngineAPI {
|
|
|
3992
4016
|
(_e = err.response) == null ? void 0 : _e.statusText,
|
|
3993
4017
|
err.message
|
|
3994
4018
|
);
|
|
3995
|
-
if ((
|
|
4019
|
+
if (isInvalidTokenError(err)) {
|
|
3996
4020
|
const token2 = yield getToken();
|
|
3997
4021
|
const config = err.config;
|
|
3998
4022
|
if (config) {
|
|
@@ -4209,4 +4233,5 @@ exports.getEndUserIpAddress = getEndUserIpAddress;
|
|
|
4209
4233
|
exports.isCodedError = isCodedError;
|
|
4210
4234
|
exports.isCodedErrors = isCodedErrors;
|
|
4211
4235
|
exports.isDataCodedErrors = isDataCodedErrors;
|
|
4236
|
+
exports.isInvalidTokenError = isInvalidTokenError;
|
|
4212
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
|
|
|
@@ -3497,6 +3512,15 @@ class InsuranceAPI {
|
|
|
3497
3512
|
this.get = (insuranceProvider) => {
|
|
3498
3513
|
return this.client.get(`/v1/insurance/${insuranceProvider}/balance`);
|
|
3499
3514
|
};
|
|
3515
|
+
/**
|
|
3516
|
+
* The `addFunds` method add funds to the account balance of the given `insuranceProvider`.
|
|
3517
|
+
*/
|
|
3518
|
+
this.addFunds = (insuranceProvider, params) => {
|
|
3519
|
+
return this.client.patch(
|
|
3520
|
+
`/v1/insurance/${insuranceProvider}/add_funds`,
|
|
3521
|
+
params
|
|
3522
|
+
);
|
|
3523
|
+
};
|
|
3500
3524
|
this.client = client;
|
|
3501
3525
|
}
|
|
3502
3526
|
}
|
|
@@ -3978,7 +4002,7 @@ class ShipEngineAPI {
|
|
|
3978
4002
|
return res;
|
|
3979
4003
|
},
|
|
3980
4004
|
(err) => __async(this, null, function* () {
|
|
3981
|
-
var _a, _b, _c, _d, _e
|
|
4005
|
+
var _a, _b, _c, _d, _e;
|
|
3982
4006
|
logger.error(
|
|
3983
4007
|
{ err, req: err.config, res: err.response },
|
|
3984
4008
|
"%s %s: %s %s - %s",
|
|
@@ -3988,7 +4012,7 @@ class ShipEngineAPI {
|
|
|
3988
4012
|
(_e = err.response) == null ? void 0 : _e.statusText,
|
|
3989
4013
|
err.message
|
|
3990
4014
|
);
|
|
3991
|
-
if ((
|
|
4015
|
+
if (isInvalidTokenError(err)) {
|
|
3992
4016
|
const token2 = yield getToken();
|
|
3993
4017
|
const config = err.config;
|
|
3994
4018
|
if (config) {
|
|
@@ -4171,4 +4195,4 @@ class ShipEngineAPI {
|
|
|
4171
4195
|
}
|
|
4172
4196
|
}
|
|
4173
4197
|
|
|
4174
|
-
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/insurance/api.d.ts
CHANGED
|
@@ -11,4 +11,8 @@ export declare class InsuranceAPI {
|
|
|
11
11
|
* by ID.
|
|
12
12
|
*/
|
|
13
13
|
get: (insuranceProvider: InsuranceProvider) => Promise<import("axios").AxiosResponse<InsuranceAccount, any>>;
|
|
14
|
+
/**
|
|
15
|
+
* The `addFunds` method add funds to the account balance of the given `insuranceProvider`.
|
|
16
|
+
*/
|
|
17
|
+
addFunds: (insuranceProvider: InsuranceProvider, params: InsuranceAccount) => Promise<import("axios").AxiosResponse<InsuranceAccount, any>>;
|
|
14
18
|
}
|