@shipengine/js-api 2.4.0 → 2.5.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/account-settings/api.d.ts +4 -4
- package/account-settings/types.d.ts +1 -1
- package/client.d.ts +12 -1
- package/index.js +170 -13
- package/index.mjs +170 -13
- package/package.json +3 -2
- package/sellers/api.d.ts +16 -2
- package/sellers/types.d.ts +18 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { AccountImage, AccountImageResponse, AccountImagesResponse,
|
|
2
|
+
import { AccountImage, AccountImageResponse, AccountImagesResponse, ShipEngineAccountSettings, UpdateAccountImage } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* # Account Settings API module - /v1/account/settings
|
|
5
5
|
*/
|
|
@@ -9,13 +9,13 @@ export declare class AccountSettingsAPI {
|
|
|
9
9
|
/**
|
|
10
10
|
* The `get` method retrieves the account settings for a given user.
|
|
11
11
|
*/
|
|
12
|
-
get: () => Promise<import("axios").AxiosResponse<
|
|
12
|
+
get: () => Promise<import("axios").AxiosResponse<ShipEngineAccountSettings, any>>;
|
|
13
13
|
/**
|
|
14
14
|
* The `update` method updates specific account settings for a given user.
|
|
15
15
|
*
|
|
16
|
-
* @params Partial<
|
|
16
|
+
* @params Partial<ShipEngineAccountSettings> The account settings to update.
|
|
17
17
|
*/
|
|
18
|
-
update: (settings: Partial<
|
|
18
|
+
update: (settings: Partial<ShipEngineAccountSettings>) => Promise<import("axios").AxiosResponse<ShipEngineAccountSettings, any>>;
|
|
19
19
|
/**
|
|
20
20
|
* The `createImage` method creates an image that can be used in your printed labels.
|
|
21
21
|
*/
|
|
@@ -2,7 +2,7 @@ import { DimensionUnit } from "../dimensions";
|
|
|
2
2
|
import { LabelLayout } from "../labels";
|
|
3
3
|
import { PageableResult } from "../resources";
|
|
4
4
|
import { WeightUnit } from "../weight";
|
|
5
|
-
export interface
|
|
5
|
+
export interface ShipEngineAccountSettings {
|
|
6
6
|
defaultLabelLayout: LabelLayout;
|
|
7
7
|
dimensionsUnit: DimensionUnit;
|
|
8
8
|
taxIdentifier?: string;
|
package/client.d.ts
CHANGED
|
@@ -72,12 +72,23 @@ export interface ShipEngineAPIConfig {
|
|
|
72
72
|
*/
|
|
73
73
|
export declare class ShipEngineAPI {
|
|
74
74
|
private client;
|
|
75
|
-
private
|
|
75
|
+
private getSandboxToken?;
|
|
76
|
+
sandboxToken?: string;
|
|
76
77
|
constructor(token: string, { baseURL, headers, getToken, getSandboxToken, onApiError }: ShipEngineAPIConfig);
|
|
77
78
|
/**
|
|
78
79
|
* The `token` method takes in a string and sets it as the Authorization header for all requests.
|
|
79
80
|
*/
|
|
80
81
|
set token(token: string);
|
|
82
|
+
get token(): string;
|
|
83
|
+
/**
|
|
84
|
+
* The `getTenant` method get the current token (based on `isSandbox` prop) and will get the Tenant ID from
|
|
85
|
+
* that token (also known as Seller ID)
|
|
86
|
+
*/
|
|
87
|
+
getTenant(isSandbox?: boolean): Promise<string | null>;
|
|
88
|
+
/**
|
|
89
|
+
* The `getTenantFromToken` method receives a token and returns the Tenant ID associated with it.
|
|
90
|
+
*/
|
|
91
|
+
private getTenantFromToken;
|
|
81
92
|
/**
|
|
82
93
|
* The `accountSettings` method provides access to the Account Settings endpoints
|
|
83
94
|
* in ShipEngine API.
|
package/index.js
CHANGED
|
@@ -180,7 +180,7 @@ class AccountSettingsAPI {
|
|
|
180
180
|
/**
|
|
181
181
|
* The `update` method updates specific account settings for a given user.
|
|
182
182
|
*
|
|
183
|
-
* @params Partial<
|
|
183
|
+
* @params Partial<ShipEngineAccountSettings> The account settings to update.
|
|
184
184
|
*/
|
|
185
185
|
this.update = (settings) => {
|
|
186
186
|
return this.client.put("/v1/account/settings", settings);
|
|
@@ -975,7 +975,7 @@ var ipaddr = {
|
|
|
975
975
|
}).call(commonjsGlobal);
|
|
976
976
|
} (ipaddr));
|
|
977
977
|
|
|
978
|
-
var __async$
|
|
978
|
+
var __async$6 = (__this, __arguments, generator) => {
|
|
979
979
|
return new Promise((resolve, reject) => {
|
|
980
980
|
var fulfilled = (value) => {
|
|
981
981
|
try {
|
|
@@ -995,7 +995,7 @@ var __async$5 = (__this, __arguments, generator) => {
|
|
|
995
995
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
996
996
|
});
|
|
997
997
|
};
|
|
998
|
-
const getEndUserIpAddress = () => __async$
|
|
998
|
+
const getEndUserIpAddress = () => __async$6(void 0, null, function* () {
|
|
999
999
|
try {
|
|
1000
1000
|
const response = yield axios.get("https://api.ipify.org/?format=json");
|
|
1001
1001
|
if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
|
|
@@ -1038,7 +1038,7 @@ var __objRest = (source, exclude) => {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
return target;
|
|
1040
1040
|
};
|
|
1041
|
-
var __async$
|
|
1041
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
1042
1042
|
return new Promise((resolve, reject) => {
|
|
1043
1043
|
var fulfilled = (value) => {
|
|
1044
1044
|
try {
|
|
@@ -1078,7 +1078,7 @@ class CarriersAPI {
|
|
|
1078
1078
|
/**
|
|
1079
1079
|
* The `connect` method connects a carrier account to a user's ShipEngine account.
|
|
1080
1080
|
*/
|
|
1081
|
-
this.connect = (_a) => __async$
|
|
1081
|
+
this.connect = (_a) => __async$5(this, null, function* () {
|
|
1082
1082
|
var _b = _a, { carrierCode } = _b, connection = __objRest(_b, ["carrierCode"]);
|
|
1083
1083
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
1084
1084
|
if (!endUserIpAddress)
|
|
@@ -1169,7 +1169,7 @@ class CarriersAPI {
|
|
|
1169
1169
|
}
|
|
1170
1170
|
}
|
|
1171
1171
|
|
|
1172
|
-
var __async$
|
|
1172
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
1173
1173
|
return new Promise((resolve, reject) => {
|
|
1174
1174
|
var fulfilled = (value) => {
|
|
1175
1175
|
try {
|
|
@@ -1211,7 +1211,7 @@ class ConnectionsAPI {
|
|
|
1211
1211
|
/**
|
|
1212
1212
|
* The `connectCarrier` method connects a carrier to account.
|
|
1213
1213
|
*/
|
|
1214
|
-
this.connectCarrier = (carrierName, formData) => __async$
|
|
1214
|
+
this.connectCarrier = (carrierName, formData) => __async$4(this, null, function* () {
|
|
1215
1215
|
return yield this.client.post(
|
|
1216
1216
|
`/v1/connections/carriers/${carrierName}`,
|
|
1217
1217
|
formData,
|
|
@@ -1397,6 +1397,64 @@ var humps = {
|
|
|
1397
1397
|
})(commonjsGlobal);
|
|
1398
1398
|
} (humps));
|
|
1399
1399
|
|
|
1400
|
+
class InvalidTokenError extends Error {
|
|
1401
|
+
}
|
|
1402
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
1403
|
+
function b64DecodeUnicode(str) {
|
|
1404
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
1405
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
1406
|
+
if (code.length < 2) {
|
|
1407
|
+
code = "0" + code;
|
|
1408
|
+
}
|
|
1409
|
+
return "%" + code;
|
|
1410
|
+
}));
|
|
1411
|
+
}
|
|
1412
|
+
function base64UrlDecode(str) {
|
|
1413
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
1414
|
+
switch (output.length % 4) {
|
|
1415
|
+
case 0:
|
|
1416
|
+
break;
|
|
1417
|
+
case 2:
|
|
1418
|
+
output += "==";
|
|
1419
|
+
break;
|
|
1420
|
+
case 3:
|
|
1421
|
+
output += "=";
|
|
1422
|
+
break;
|
|
1423
|
+
default:
|
|
1424
|
+
throw new Error("base64 string is not of the correct length");
|
|
1425
|
+
}
|
|
1426
|
+
try {
|
|
1427
|
+
return b64DecodeUnicode(output);
|
|
1428
|
+
}
|
|
1429
|
+
catch (err) {
|
|
1430
|
+
return atob(output);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
function jwtDecode(token, options) {
|
|
1434
|
+
if (typeof token !== "string") {
|
|
1435
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
1436
|
+
}
|
|
1437
|
+
options || (options = {});
|
|
1438
|
+
const pos = options.header === true ? 0 : 1;
|
|
1439
|
+
const part = token.split(".")[pos];
|
|
1440
|
+
if (typeof part !== "string") {
|
|
1441
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
1442
|
+
}
|
|
1443
|
+
let decoded;
|
|
1444
|
+
try {
|
|
1445
|
+
decoded = base64UrlDecode(part);
|
|
1446
|
+
}
|
|
1447
|
+
catch (e) {
|
|
1448
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
|
1449
|
+
}
|
|
1450
|
+
try {
|
|
1451
|
+
return JSON.parse(decoded);
|
|
1452
|
+
}
|
|
1453
|
+
catch (e) {
|
|
1454
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1400
1458
|
/* eslint complexity: [2, 18], max-statements: [2, 33] */
|
|
1401
1459
|
var shams = function hasSymbols() {
|
|
1402
1460
|
if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
|
@@ -3482,7 +3540,7 @@ var __spreadValues$3 = (a, b) => {
|
|
|
3482
3540
|
}
|
|
3483
3541
|
return a;
|
|
3484
3542
|
};
|
|
3485
|
-
var __async$
|
|
3543
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
3486
3544
|
return new Promise((resolve, reject) => {
|
|
3487
3545
|
var fulfilled = (value) => {
|
|
3488
3546
|
try {
|
|
@@ -3521,7 +3579,7 @@ class FundingSourcesAPI {
|
|
|
3521
3579
|
* The `create` method creates a new funding source for a given user. This requires
|
|
3522
3580
|
* payment information to be collected from the user.
|
|
3523
3581
|
*/
|
|
3524
|
-
this.create = (createFundingSource) => __async$
|
|
3582
|
+
this.create = (createFundingSource) => __async$3(this, null, function* () {
|
|
3525
3583
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
3526
3584
|
if (!endUserIpAddress) {
|
|
3527
3585
|
return Promise.reject([new CodedError("Unable to get IP address")]);
|
|
@@ -3535,7 +3593,7 @@ class FundingSourcesAPI {
|
|
|
3535
3593
|
* user to update the billing address or payment information associated with the
|
|
3536
3594
|
* funding source.
|
|
3537
3595
|
*/
|
|
3538
|
-
this.update = (billingInfo, creditCardInfo, fundingSourceId) => __async$
|
|
3596
|
+
this.update = (billingInfo, creditCardInfo, fundingSourceId) => __async$3(this, null, function* () {
|
|
3539
3597
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
3540
3598
|
if (!endUserIpAddress) {
|
|
3541
3599
|
return Promise.reject([new CodedError("Unable to get IP address")]);
|
|
@@ -3553,7 +3611,7 @@ class FundingSourcesAPI {
|
|
|
3553
3611
|
* The `registerCarrier` method registers a carrier account and associates
|
|
3554
3612
|
* it with a given funding source.
|
|
3555
3613
|
*/
|
|
3556
|
-
this.registerCarrier = (carrier) => __async$
|
|
3614
|
+
this.registerCarrier = (carrier) => __async$3(this, null, function* () {
|
|
3557
3615
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
3558
3616
|
if (!endUserIpAddress) {
|
|
3559
3617
|
return Promise.reject([new CodedError("Unable to get IP address")]);
|
|
@@ -3565,7 +3623,7 @@ class FundingSourcesAPI {
|
|
|
3565
3623
|
/**
|
|
3566
3624
|
* The `addFunds` method allows you to add funds to a funding source.
|
|
3567
3625
|
*/
|
|
3568
|
-
this.addFunds = (amount, fundingSourceId) => __async$
|
|
3626
|
+
this.addFunds = (amount, fundingSourceId) => __async$3(this, null, function* () {
|
|
3569
3627
|
return yield this.client.put(
|
|
3570
3628
|
`/v1/funding_sources/${fundingSourceId}/add_funds`,
|
|
3571
3629
|
amount
|
|
@@ -3575,7 +3633,7 @@ class FundingSourcesAPI {
|
|
|
3575
3633
|
* The `metadata` method returns seller-specific requirements for creating funding sources
|
|
3576
3634
|
* and attaching carriers
|
|
3577
3635
|
*/
|
|
3578
|
-
this.metadata = () => __async$
|
|
3636
|
+
this.metadata = () => __async$3(this, null, function* () {
|
|
3579
3637
|
return yield this.client.get("/v1/funding_sources/metadata");
|
|
3580
3638
|
});
|
|
3581
3639
|
/**
|
|
@@ -3874,6 +3932,26 @@ class SalesOrdersAPI {
|
|
|
3874
3932
|
}
|
|
3875
3933
|
}
|
|
3876
3934
|
|
|
3935
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
3936
|
+
return new Promise((resolve, reject) => {
|
|
3937
|
+
var fulfilled = (value) => {
|
|
3938
|
+
try {
|
|
3939
|
+
step(generator.next(value));
|
|
3940
|
+
} catch (e) {
|
|
3941
|
+
reject(e);
|
|
3942
|
+
}
|
|
3943
|
+
};
|
|
3944
|
+
var rejected = (value) => {
|
|
3945
|
+
try {
|
|
3946
|
+
step(generator.throw(value));
|
|
3947
|
+
} catch (e) {
|
|
3948
|
+
reject(e);
|
|
3949
|
+
}
|
|
3950
|
+
};
|
|
3951
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
3952
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
3953
|
+
});
|
|
3954
|
+
};
|
|
3877
3955
|
class SellersAPI {
|
|
3878
3956
|
constructor(client) {
|
|
3879
3957
|
/**
|
|
@@ -3882,6 +3960,55 @@ class SellersAPI {
|
|
|
3882
3960
|
this.listSandboxSellerIds = ({ sellerId }) => {
|
|
3883
3961
|
return this.client.get(`/v1/sellers/sandbox_sellers/${sellerId}`);
|
|
3884
3962
|
};
|
|
3963
|
+
/**
|
|
3964
|
+
* Given a seller ID, returns a list of API Keys created for that seller.
|
|
3965
|
+
*/
|
|
3966
|
+
this.listSellerApiKeys = (props) => {
|
|
3967
|
+
return this.client.get(`/v1/sellers/api_keys?sellerId=${props.sellerId}`, {
|
|
3968
|
+
isSandbox: props.isSandbox
|
|
3969
|
+
});
|
|
3970
|
+
};
|
|
3971
|
+
/**
|
|
3972
|
+
* Creates an API Key for a Seller ID
|
|
3973
|
+
*/
|
|
3974
|
+
this.createSellerApiKey = ({
|
|
3975
|
+
description,
|
|
3976
|
+
sellerId,
|
|
3977
|
+
isSandbox
|
|
3978
|
+
}) => {
|
|
3979
|
+
return this.client.post(
|
|
3980
|
+
"/v1/sellers/create_key",
|
|
3981
|
+
{
|
|
3982
|
+
description,
|
|
3983
|
+
sellerId
|
|
3984
|
+
},
|
|
3985
|
+
{
|
|
3986
|
+
isSandbox
|
|
3987
|
+
}
|
|
3988
|
+
);
|
|
3989
|
+
};
|
|
3990
|
+
/**
|
|
3991
|
+
* Deletes an API Key
|
|
3992
|
+
*/
|
|
3993
|
+
this.deleteSellerApiKey = (_0) => __async$2(this, [_0], function* ({
|
|
3994
|
+
encryptedApiKey,
|
|
3995
|
+
sellerId,
|
|
3996
|
+
isSandbox
|
|
3997
|
+
}) {
|
|
3998
|
+
const sellerApiKeys = yield this.listSellerApiKeys({ isSandbox, sellerId });
|
|
3999
|
+
if (!sellerApiKeys.data.find((sellerApiKey) => sellerApiKey.encryptedApiKey === encryptedApiKey)) {
|
|
4000
|
+
return Promise.reject([
|
|
4001
|
+
new CodedError("Missing Seller ID from Token", {
|
|
4002
|
+
errorCode: "unauthorized",
|
|
4003
|
+
errorSource: "client",
|
|
4004
|
+
errorType: "security"
|
|
4005
|
+
})
|
|
4006
|
+
]);
|
|
4007
|
+
}
|
|
4008
|
+
return this.client.delete("/v1/sellers", {
|
|
4009
|
+
data: encryptedApiKey
|
|
4010
|
+
});
|
|
4011
|
+
});
|
|
3885
4012
|
/**
|
|
3886
4013
|
* Creates a sandbox seller account for a given seller ID
|
|
3887
4014
|
* you can pass in a flag to try to reuse the carrier connection.
|
|
@@ -21445,6 +21572,7 @@ const logger = E({
|
|
|
21445
21572
|
});
|
|
21446
21573
|
class ShipEngineAPI {
|
|
21447
21574
|
constructor(token, { baseURL, headers, getToken, getSandboxToken, onApiError }) {
|
|
21575
|
+
this.getSandboxToken = getSandboxToken;
|
|
21448
21576
|
const client = axios.create({
|
|
21449
21577
|
baseURL,
|
|
21450
21578
|
headers: __spreadProps(__spreadValues({}, headers), {
|
|
@@ -21548,6 +21676,35 @@ class ShipEngineAPI {
|
|
|
21548
21676
|
set token(token) {
|
|
21549
21677
|
this.client.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
21550
21678
|
}
|
|
21679
|
+
get token() {
|
|
21680
|
+
return this.client.defaults.headers.common["Authorization"];
|
|
21681
|
+
}
|
|
21682
|
+
/**
|
|
21683
|
+
* The `getTenant` method get the current token (based on `isSandbox` prop) and will get the Tenant ID from
|
|
21684
|
+
* that token (also known as Seller ID)
|
|
21685
|
+
*/
|
|
21686
|
+
getTenant(isSandbox) {
|
|
21687
|
+
return __async(this, null, function* () {
|
|
21688
|
+
var _a;
|
|
21689
|
+
if (!isSandbox) {
|
|
21690
|
+
return this.getTenantFromToken(this.token);
|
|
21691
|
+
}
|
|
21692
|
+
if (!this.sandboxToken) {
|
|
21693
|
+
this.sandboxToken = yield (_a = this.getSandboxToken) == null ? void 0 : _a.call(this);
|
|
21694
|
+
}
|
|
21695
|
+
return this.getTenantFromToken(this.sandboxToken);
|
|
21696
|
+
});
|
|
21697
|
+
}
|
|
21698
|
+
/**
|
|
21699
|
+
* The `getTenantFromToken` method receives a token and returns the Tenant ID associated with it.
|
|
21700
|
+
*/
|
|
21701
|
+
getTenantFromToken(token) {
|
|
21702
|
+
try {
|
|
21703
|
+
return jwtDecode(token).tenant;
|
|
21704
|
+
} catch (e) {
|
|
21705
|
+
return null;
|
|
21706
|
+
}
|
|
21707
|
+
}
|
|
21551
21708
|
/**
|
|
21552
21709
|
* The `accountSettings` method provides access to the Account Settings endpoints
|
|
21553
21710
|
* in ShipEngine API.
|
package/index.mjs
CHANGED
|
@@ -176,7 +176,7 @@ class AccountSettingsAPI {
|
|
|
176
176
|
/**
|
|
177
177
|
* The `update` method updates specific account settings for a given user.
|
|
178
178
|
*
|
|
179
|
-
* @params Partial<
|
|
179
|
+
* @params Partial<ShipEngineAccountSettings> The account settings to update.
|
|
180
180
|
*/
|
|
181
181
|
this.update = (settings) => {
|
|
182
182
|
return this.client.put("/v1/account/settings", settings);
|
|
@@ -971,7 +971,7 @@ var ipaddr = {
|
|
|
971
971
|
}).call(commonjsGlobal);
|
|
972
972
|
} (ipaddr));
|
|
973
973
|
|
|
974
|
-
var __async$
|
|
974
|
+
var __async$6 = (__this, __arguments, generator) => {
|
|
975
975
|
return new Promise((resolve, reject) => {
|
|
976
976
|
var fulfilled = (value) => {
|
|
977
977
|
try {
|
|
@@ -991,7 +991,7 @@ var __async$5 = (__this, __arguments, generator) => {
|
|
|
991
991
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
992
992
|
});
|
|
993
993
|
};
|
|
994
|
-
const getEndUserIpAddress = () => __async$
|
|
994
|
+
const getEndUserIpAddress = () => __async$6(void 0, null, function* () {
|
|
995
995
|
try {
|
|
996
996
|
const response = yield axios.get("https://api.ipify.org/?format=json");
|
|
997
997
|
if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
|
|
@@ -1034,7 +1034,7 @@ var __objRest = (source, exclude) => {
|
|
|
1034
1034
|
}
|
|
1035
1035
|
return target;
|
|
1036
1036
|
};
|
|
1037
|
-
var __async$
|
|
1037
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
1038
1038
|
return new Promise((resolve, reject) => {
|
|
1039
1039
|
var fulfilled = (value) => {
|
|
1040
1040
|
try {
|
|
@@ -1074,7 +1074,7 @@ class CarriersAPI {
|
|
|
1074
1074
|
/**
|
|
1075
1075
|
* The `connect` method connects a carrier account to a user's ShipEngine account.
|
|
1076
1076
|
*/
|
|
1077
|
-
this.connect = (_a) => __async$
|
|
1077
|
+
this.connect = (_a) => __async$5(this, null, function* () {
|
|
1078
1078
|
var _b = _a, { carrierCode } = _b, connection = __objRest(_b, ["carrierCode"]);
|
|
1079
1079
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
1080
1080
|
if (!endUserIpAddress)
|
|
@@ -1165,7 +1165,7 @@ class CarriersAPI {
|
|
|
1165
1165
|
}
|
|
1166
1166
|
}
|
|
1167
1167
|
|
|
1168
|
-
var __async$
|
|
1168
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
1169
1169
|
return new Promise((resolve, reject) => {
|
|
1170
1170
|
var fulfilled = (value) => {
|
|
1171
1171
|
try {
|
|
@@ -1207,7 +1207,7 @@ class ConnectionsAPI {
|
|
|
1207
1207
|
/**
|
|
1208
1208
|
* The `connectCarrier` method connects a carrier to account.
|
|
1209
1209
|
*/
|
|
1210
|
-
this.connectCarrier = (carrierName, formData) => __async$
|
|
1210
|
+
this.connectCarrier = (carrierName, formData) => __async$4(this, null, function* () {
|
|
1211
1211
|
return yield this.client.post(
|
|
1212
1212
|
`/v1/connections/carriers/${carrierName}`,
|
|
1213
1213
|
formData,
|
|
@@ -1393,6 +1393,64 @@ var humps = {
|
|
|
1393
1393
|
})(commonjsGlobal);
|
|
1394
1394
|
} (humps));
|
|
1395
1395
|
|
|
1396
|
+
class InvalidTokenError extends Error {
|
|
1397
|
+
}
|
|
1398
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
1399
|
+
function b64DecodeUnicode(str) {
|
|
1400
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
1401
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
1402
|
+
if (code.length < 2) {
|
|
1403
|
+
code = "0" + code;
|
|
1404
|
+
}
|
|
1405
|
+
return "%" + code;
|
|
1406
|
+
}));
|
|
1407
|
+
}
|
|
1408
|
+
function base64UrlDecode(str) {
|
|
1409
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
1410
|
+
switch (output.length % 4) {
|
|
1411
|
+
case 0:
|
|
1412
|
+
break;
|
|
1413
|
+
case 2:
|
|
1414
|
+
output += "==";
|
|
1415
|
+
break;
|
|
1416
|
+
case 3:
|
|
1417
|
+
output += "=";
|
|
1418
|
+
break;
|
|
1419
|
+
default:
|
|
1420
|
+
throw new Error("base64 string is not of the correct length");
|
|
1421
|
+
}
|
|
1422
|
+
try {
|
|
1423
|
+
return b64DecodeUnicode(output);
|
|
1424
|
+
}
|
|
1425
|
+
catch (err) {
|
|
1426
|
+
return atob(output);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
function jwtDecode(token, options) {
|
|
1430
|
+
if (typeof token !== "string") {
|
|
1431
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
1432
|
+
}
|
|
1433
|
+
options || (options = {});
|
|
1434
|
+
const pos = options.header === true ? 0 : 1;
|
|
1435
|
+
const part = token.split(".")[pos];
|
|
1436
|
+
if (typeof part !== "string") {
|
|
1437
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
1438
|
+
}
|
|
1439
|
+
let decoded;
|
|
1440
|
+
try {
|
|
1441
|
+
decoded = base64UrlDecode(part);
|
|
1442
|
+
}
|
|
1443
|
+
catch (e) {
|
|
1444
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
|
1445
|
+
}
|
|
1446
|
+
try {
|
|
1447
|
+
return JSON.parse(decoded);
|
|
1448
|
+
}
|
|
1449
|
+
catch (e) {
|
|
1450
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1396
1454
|
/* eslint complexity: [2, 18], max-statements: [2, 33] */
|
|
1397
1455
|
var shams = function hasSymbols() {
|
|
1398
1456
|
if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
|
@@ -3478,7 +3536,7 @@ var __spreadValues$3 = (a, b) => {
|
|
|
3478
3536
|
}
|
|
3479
3537
|
return a;
|
|
3480
3538
|
};
|
|
3481
|
-
var __async$
|
|
3539
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
3482
3540
|
return new Promise((resolve, reject) => {
|
|
3483
3541
|
var fulfilled = (value) => {
|
|
3484
3542
|
try {
|
|
@@ -3517,7 +3575,7 @@ class FundingSourcesAPI {
|
|
|
3517
3575
|
* The `create` method creates a new funding source for a given user. This requires
|
|
3518
3576
|
* payment information to be collected from the user.
|
|
3519
3577
|
*/
|
|
3520
|
-
this.create = (createFundingSource) => __async$
|
|
3578
|
+
this.create = (createFundingSource) => __async$3(this, null, function* () {
|
|
3521
3579
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
3522
3580
|
if (!endUserIpAddress) {
|
|
3523
3581
|
return Promise.reject([new CodedError("Unable to get IP address")]);
|
|
@@ -3531,7 +3589,7 @@ class FundingSourcesAPI {
|
|
|
3531
3589
|
* user to update the billing address or payment information associated with the
|
|
3532
3590
|
* funding source.
|
|
3533
3591
|
*/
|
|
3534
|
-
this.update = (billingInfo, creditCardInfo, fundingSourceId) => __async$
|
|
3592
|
+
this.update = (billingInfo, creditCardInfo, fundingSourceId) => __async$3(this, null, function* () {
|
|
3535
3593
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
3536
3594
|
if (!endUserIpAddress) {
|
|
3537
3595
|
return Promise.reject([new CodedError("Unable to get IP address")]);
|
|
@@ -3549,7 +3607,7 @@ class FundingSourcesAPI {
|
|
|
3549
3607
|
* The `registerCarrier` method registers a carrier account and associates
|
|
3550
3608
|
* it with a given funding source.
|
|
3551
3609
|
*/
|
|
3552
|
-
this.registerCarrier = (carrier) => __async$
|
|
3610
|
+
this.registerCarrier = (carrier) => __async$3(this, null, function* () {
|
|
3553
3611
|
const endUserIpAddress = yield getEndUserIpAddress();
|
|
3554
3612
|
if (!endUserIpAddress) {
|
|
3555
3613
|
return Promise.reject([new CodedError("Unable to get IP address")]);
|
|
@@ -3561,7 +3619,7 @@ class FundingSourcesAPI {
|
|
|
3561
3619
|
/**
|
|
3562
3620
|
* The `addFunds` method allows you to add funds to a funding source.
|
|
3563
3621
|
*/
|
|
3564
|
-
this.addFunds = (amount, fundingSourceId) => __async$
|
|
3622
|
+
this.addFunds = (amount, fundingSourceId) => __async$3(this, null, function* () {
|
|
3565
3623
|
return yield this.client.put(
|
|
3566
3624
|
`/v1/funding_sources/${fundingSourceId}/add_funds`,
|
|
3567
3625
|
amount
|
|
@@ -3571,7 +3629,7 @@ class FundingSourcesAPI {
|
|
|
3571
3629
|
* The `metadata` method returns seller-specific requirements for creating funding sources
|
|
3572
3630
|
* and attaching carriers
|
|
3573
3631
|
*/
|
|
3574
|
-
this.metadata = () => __async$
|
|
3632
|
+
this.metadata = () => __async$3(this, null, function* () {
|
|
3575
3633
|
return yield this.client.get("/v1/funding_sources/metadata");
|
|
3576
3634
|
});
|
|
3577
3635
|
/**
|
|
@@ -3870,6 +3928,26 @@ class SalesOrdersAPI {
|
|
|
3870
3928
|
}
|
|
3871
3929
|
}
|
|
3872
3930
|
|
|
3931
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
3932
|
+
return new Promise((resolve, reject) => {
|
|
3933
|
+
var fulfilled = (value) => {
|
|
3934
|
+
try {
|
|
3935
|
+
step(generator.next(value));
|
|
3936
|
+
} catch (e) {
|
|
3937
|
+
reject(e);
|
|
3938
|
+
}
|
|
3939
|
+
};
|
|
3940
|
+
var rejected = (value) => {
|
|
3941
|
+
try {
|
|
3942
|
+
step(generator.throw(value));
|
|
3943
|
+
} catch (e) {
|
|
3944
|
+
reject(e);
|
|
3945
|
+
}
|
|
3946
|
+
};
|
|
3947
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
3948
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
3949
|
+
});
|
|
3950
|
+
};
|
|
3873
3951
|
class SellersAPI {
|
|
3874
3952
|
constructor(client) {
|
|
3875
3953
|
/**
|
|
@@ -3878,6 +3956,55 @@ class SellersAPI {
|
|
|
3878
3956
|
this.listSandboxSellerIds = ({ sellerId }) => {
|
|
3879
3957
|
return this.client.get(`/v1/sellers/sandbox_sellers/${sellerId}`);
|
|
3880
3958
|
};
|
|
3959
|
+
/**
|
|
3960
|
+
* Given a seller ID, returns a list of API Keys created for that seller.
|
|
3961
|
+
*/
|
|
3962
|
+
this.listSellerApiKeys = (props) => {
|
|
3963
|
+
return this.client.get(`/v1/sellers/api_keys?sellerId=${props.sellerId}`, {
|
|
3964
|
+
isSandbox: props.isSandbox
|
|
3965
|
+
});
|
|
3966
|
+
};
|
|
3967
|
+
/**
|
|
3968
|
+
* Creates an API Key for a Seller ID
|
|
3969
|
+
*/
|
|
3970
|
+
this.createSellerApiKey = ({
|
|
3971
|
+
description,
|
|
3972
|
+
sellerId,
|
|
3973
|
+
isSandbox
|
|
3974
|
+
}) => {
|
|
3975
|
+
return this.client.post(
|
|
3976
|
+
"/v1/sellers/create_key",
|
|
3977
|
+
{
|
|
3978
|
+
description,
|
|
3979
|
+
sellerId
|
|
3980
|
+
},
|
|
3981
|
+
{
|
|
3982
|
+
isSandbox
|
|
3983
|
+
}
|
|
3984
|
+
);
|
|
3985
|
+
};
|
|
3986
|
+
/**
|
|
3987
|
+
* Deletes an API Key
|
|
3988
|
+
*/
|
|
3989
|
+
this.deleteSellerApiKey = (_0) => __async$2(this, [_0], function* ({
|
|
3990
|
+
encryptedApiKey,
|
|
3991
|
+
sellerId,
|
|
3992
|
+
isSandbox
|
|
3993
|
+
}) {
|
|
3994
|
+
const sellerApiKeys = yield this.listSellerApiKeys({ isSandbox, sellerId });
|
|
3995
|
+
if (!sellerApiKeys.data.find((sellerApiKey) => sellerApiKey.encryptedApiKey === encryptedApiKey)) {
|
|
3996
|
+
return Promise.reject([
|
|
3997
|
+
new CodedError("Missing Seller ID from Token", {
|
|
3998
|
+
errorCode: "unauthorized",
|
|
3999
|
+
errorSource: "client",
|
|
4000
|
+
errorType: "security"
|
|
4001
|
+
})
|
|
4002
|
+
]);
|
|
4003
|
+
}
|
|
4004
|
+
return this.client.delete("/v1/sellers", {
|
|
4005
|
+
data: encryptedApiKey
|
|
4006
|
+
});
|
|
4007
|
+
});
|
|
3881
4008
|
/**
|
|
3882
4009
|
* Creates a sandbox seller account for a given seller ID
|
|
3883
4010
|
* you can pass in a flag to try to reuse the carrier connection.
|
|
@@ -21441,6 +21568,7 @@ const logger = E({
|
|
|
21441
21568
|
});
|
|
21442
21569
|
class ShipEngineAPI {
|
|
21443
21570
|
constructor(token, { baseURL, headers, getToken, getSandboxToken, onApiError }) {
|
|
21571
|
+
this.getSandboxToken = getSandboxToken;
|
|
21444
21572
|
const client = axios.create({
|
|
21445
21573
|
baseURL,
|
|
21446
21574
|
headers: __spreadProps(__spreadValues({}, headers), {
|
|
@@ -21544,6 +21672,35 @@ class ShipEngineAPI {
|
|
|
21544
21672
|
set token(token) {
|
|
21545
21673
|
this.client.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
21546
21674
|
}
|
|
21675
|
+
get token() {
|
|
21676
|
+
return this.client.defaults.headers.common["Authorization"];
|
|
21677
|
+
}
|
|
21678
|
+
/**
|
|
21679
|
+
* The `getTenant` method get the current token (based on `isSandbox` prop) and will get the Tenant ID from
|
|
21680
|
+
* that token (also known as Seller ID)
|
|
21681
|
+
*/
|
|
21682
|
+
getTenant(isSandbox) {
|
|
21683
|
+
return __async(this, null, function* () {
|
|
21684
|
+
var _a;
|
|
21685
|
+
if (!isSandbox) {
|
|
21686
|
+
return this.getTenantFromToken(this.token);
|
|
21687
|
+
}
|
|
21688
|
+
if (!this.sandboxToken) {
|
|
21689
|
+
this.sandboxToken = yield (_a = this.getSandboxToken) == null ? void 0 : _a.call(this);
|
|
21690
|
+
}
|
|
21691
|
+
return this.getTenantFromToken(this.sandboxToken);
|
|
21692
|
+
});
|
|
21693
|
+
}
|
|
21694
|
+
/**
|
|
21695
|
+
* The `getTenantFromToken` method receives a token and returns the Tenant ID associated with it.
|
|
21696
|
+
*/
|
|
21697
|
+
getTenantFromToken(token) {
|
|
21698
|
+
try {
|
|
21699
|
+
return jwtDecode(token).tenant;
|
|
21700
|
+
} catch (e) {
|
|
21701
|
+
return null;
|
|
21702
|
+
}
|
|
21703
|
+
}
|
|
21547
21704
|
/**
|
|
21548
21705
|
* The `accountSettings` method provides access to the Account Settings endpoints
|
|
21549
21706
|
* in ShipEngine API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipengine/js-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"tsconfig": "./tsconfig.lib.json"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"axios": "^0.26.1"
|
|
20
|
+
"axios": "^0.26.1",
|
|
21
|
+
"jwt-decode": "^4.0.0"
|
|
21
22
|
}
|
|
22
23
|
}
|
package/sellers/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { SandboxableMutation } from "../resources";
|
|
3
|
-
import type { ListSandboxSellersParams, SandboxMethodParams } from "./types";
|
|
2
|
+
import { SandboxableMutation, SandboxableQuery } from "../resources";
|
|
3
|
+
import type { CreateSellerApiKeyParams, DeleteSellerApiKeyParams, ListSandboxSellersParams, SandboxMethodParams, SellerApiKey } from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* Sellers API endpoints
|
|
6
6
|
*/
|
|
@@ -11,6 +11,20 @@ export declare class SellersAPI {
|
|
|
11
11
|
* Given a seller ID, returns a list of sandbox seller IDs for that seller.
|
|
12
12
|
*/
|
|
13
13
|
listSandboxSellerIds: ({ sellerId }: ListSandboxSellersParams) => Promise<import("axios").AxiosResponse<string[], any>>;
|
|
14
|
+
/**
|
|
15
|
+
* Given a seller ID, returns a list of API Keys created for that seller.
|
|
16
|
+
*/
|
|
17
|
+
listSellerApiKeys: (props: SandboxableQuery<{
|
|
18
|
+
sellerId: string;
|
|
19
|
+
}>) => Promise<import("axios").AxiosResponse<SellerApiKey[], any>>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an API Key for a Seller ID
|
|
22
|
+
*/
|
|
23
|
+
createSellerApiKey: ({ description, sellerId, isSandbox, }: SandboxableMutation<CreateSellerApiKeyParams>) => Promise<import("axios").AxiosResponse<SellerApiKey, any>>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes an API Key
|
|
26
|
+
*/
|
|
27
|
+
deleteSellerApiKey: ({ encryptedApiKey, sellerId, isSandbox, }: SandboxableMutation<DeleteSellerApiKeyParams>) => Promise<import("axios").AxiosResponse<void, any>>;
|
|
14
28
|
/**
|
|
15
29
|
* Creates a sandbox seller account for a given seller ID
|
|
16
30
|
* you can pass in a flag to try to reuse the carrier connection.
|
package/sellers/types.d.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
export type ListSandboxSellersParams = {
|
|
2
2
|
sellerId: string;
|
|
3
3
|
};
|
|
4
|
+
export type ListSellerApiKeysParams = {
|
|
5
|
+
sellerId: string;
|
|
6
|
+
};
|
|
4
7
|
export type SandboxMethodParams = {
|
|
5
8
|
sellerId: string;
|
|
6
9
|
tryReuseCarrierConnection?: boolean;
|
|
7
10
|
};
|
|
11
|
+
export type DeleteSellerApiKeyParams = {
|
|
12
|
+
encryptedApiKey: string;
|
|
13
|
+
sellerId: string;
|
|
14
|
+
};
|
|
15
|
+
export type CreateSellerApiKeyParams = {
|
|
16
|
+
description?: string;
|
|
17
|
+
sellerId: string;
|
|
18
|
+
};
|
|
19
|
+
export type SellerApiKey = {
|
|
20
|
+
accountId: number;
|
|
21
|
+
apiKeyId: number;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
encryptedApiKey: string;
|
|
25
|
+
};
|