@shipengine/js-api 0.9.0 → 0.11.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/client.d.ts CHANGED
@@ -3,6 +3,7 @@ import { AccountSettingsAPI } from "./account-settings";
3
3
  import { AddressesAPI } from "./addresses";
4
4
  import { CarriersAPI } from "./carriers";
5
5
  import { CustomPackagesAPI } from "./custom-packages";
6
+ import { FundingSourcesAPI } from "./funding-sources";
6
7
  import { InsuranceAPI } from "./insurance";
7
8
  import { LabelsAPI } from "./labels";
8
9
  import { OrderSourcesAPI } from "./order-sources";
@@ -25,6 +26,7 @@ export declare class ShipEngineAPI {
25
26
  get addresses(): AddressesAPI;
26
27
  get carriers(): CarriersAPI;
27
28
  get customPackages(): CustomPackagesAPI;
29
+ get fundingSources(): FundingSourcesAPI;
28
30
  get insurance(): InsuranceAPI;
29
31
  get labels(): LabelsAPI;
30
32
  get orderSources(): OrderSourcesAPI;
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { BillingInfo, CarrierRegistration, CarrierRegistrationResponse, CreateFundingSourceResponse, FundingSource, ListFundingSourcesResponse, PaymentMethod } from "./types";
3
+ export declare class FundingSourcesAPI {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ list: () => Promise<import("axios").AxiosResponse<ListFundingSourcesResponse, any>>;
7
+ get: (fundingSourceId: string) => Promise<import("axios").AxiosResponse<FundingSource, any>>;
8
+ create: (fundingSource: FundingSource) => Promise<import("axios").AxiosResponse<CreateFundingSourceResponse, any>>;
9
+ update: (billingInfo: BillingInfo, paymentMethod: PaymentMethod, fundingSourceId: string) => Promise<import("axios").AxiosResponse<CreateFundingSourceResponse, any>>;
10
+ registerCarrier: (carrier: CarrierRegistration) => Promise<import("axios").AxiosResponse<CarrierRegistrationResponse, any>>;
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./api";
2
+ export * from "./types";
@@ -0,0 +1,77 @@
1
+ import { CreditCardVendor } from "../payments";
2
+ export type FundingSource = {
3
+ acceptedTerms: Term[];
4
+ agreeToTerms: boolean;
5
+ billingInfo: BillingInfo;
6
+ paymentMethod: PaymentMethod;
7
+ };
8
+ export interface CarrierRegistration {
9
+ carriers: [
10
+ {
11
+ acceptedTerms: Term[];
12
+ agreeToTerms: boolean;
13
+ carrierCode: "stamps_com" | "ups_walleted" | "dhl_express_worldwide";
14
+ fundingSourceId: string;
15
+ }
16
+ ];
17
+ }
18
+ export interface BillingInfo {
19
+ addressLine1: string;
20
+ addressLine2?: string;
21
+ cityLocality: string;
22
+ company: string;
23
+ countryCode: string;
24
+ email: string;
25
+ fullName: string;
26
+ phone: string;
27
+ postalCode: string;
28
+ stateProvince: string;
29
+ }
30
+ export interface CreditCardInfo {
31
+ cardNumber: string;
32
+ cvv: string;
33
+ expirationMonth: number;
34
+ expirationYear: number;
35
+ name: string;
36
+ provider: CreditCardVendor;
37
+ }
38
+ export interface PaymentMethod {
39
+ creditCardInfo: CreditCardInfo;
40
+ }
41
+ export interface Term {
42
+ termType: string;
43
+ version: string;
44
+ }
45
+ export interface CarrierRegistrationResponse {
46
+ carrierAttachmentResults: [
47
+ {
48
+ carrierId: string;
49
+ errorMessage: string;
50
+ fundingSourceId: string;
51
+ isSuccessful: boolean;
52
+ nickname: string;
53
+ }
54
+ ];
55
+ }
56
+ export interface CreateFundingSourceResponse {
57
+ fundingSource: {
58
+ billingInfo: BillingInfo;
59
+ currencyCode: string;
60
+ fundingSourceId: string;
61
+ PaymentMethod: PaymentMethod | {
62
+ creditCardInfo: null;
63
+ };
64
+ };
65
+ }
66
+ export interface ListFundingSourcesResponse {
67
+ fundingSources: [
68
+ {
69
+ billingInfo: BillingInfo;
70
+ currencyCode: string;
71
+ fundingSourceId: string;
72
+ paymentMethod: PaymentMethod | {
73
+ creditCardInfo: null;
74
+ };
75
+ }
76
+ ];
77
+ }
package/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./client";
6
6
  export * from "./custom-packages";
7
7
  export * from "./dimensions";
8
8
  export * from "./errors";
9
+ export * from "./funding-sources";
9
10
  export * from "./insurance";
10
11
  export * from "./labels";
11
12
  export * from "./order-sources";
@@ -16,5 +17,6 @@ export * from "./resources";
16
17
  export * from "./sales-order-shipments";
17
18
  export * from "./sales-orders";
18
19
  export * from "./shipments";
20
+ export * from "./utilities";
19
21
  export * from "./warehouses";
20
22
  export * from "./weight";
package/index.js CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
6
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
7
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
5
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
8
8
  var __objRest$1 = (source, exclude) => {
9
9
  var target = {};
10
10
  for (var prop in source)
11
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
11
+ if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
12
12
  target[prop] = source[prop];
13
- if (source != null && __getOwnPropSymbols$3)
14
- for (var prop of __getOwnPropSymbols$3(source)) {
15
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
13
+ if (source != null && __getOwnPropSymbols$4)
14
+ for (var prop of __getOwnPropSymbols$4(source)) {
15
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
16
16
  target[prop] = source[prop];
17
17
  }
18
18
  return target;
@@ -119,6 +119,9 @@ class AddressesAPI {
119
119
  }
120
120
  }
121
121
 
122
+ const isCodedErrors = (errs) => Array.isArray(errs) && errs.every((err) => isCodedError(err));
123
+ const isCodedError = (err) => !!err.errorCode;
124
+
122
125
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
123
126
 
124
127
  function getDefaultExportFromCjs (x) {
@@ -2787,24 +2790,53 @@ var ipaddr = {
2787
2790
  }).call(commonjsGlobal);
2788
2791
  } (ipaddr));
2789
2792
 
2790
- const isCodedErrors = (errs) => Array.isArray(errs) && errs.every((err) => isCodedError(err));
2791
- const isCodedError = (err) => !!err.errorCode;
2793
+ var __async$4 = (__this, __arguments, generator) => {
2794
+ return new Promise((resolve, reject) => {
2795
+ var fulfilled = (value) => {
2796
+ try {
2797
+ step(generator.next(value));
2798
+ } catch (e) {
2799
+ reject(e);
2800
+ }
2801
+ };
2802
+ var rejected = (value) => {
2803
+ try {
2804
+ step(generator.throw(value));
2805
+ } catch (e) {
2806
+ reject(e);
2807
+ }
2808
+ };
2809
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2810
+ step((generator = generator.apply(__this, __arguments)).next());
2811
+ });
2812
+ };
2813
+ const getEndUserIpAddress = () => __async$4(void 0, null, function* () {
2814
+ try {
2815
+ const response = yield axios.get("https://api.ipify.org/?format=json");
2816
+ if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
2817
+ return ipaddrExports.parse(response.data.ip).toString();
2818
+ }
2819
+ return void 0;
2820
+ } catch (e) {
2821
+ return void 0;
2822
+ }
2823
+ });
2792
2824
 
2793
- var __defProp$2 = Object.defineProperty;
2825
+ var __defProp$3 = Object.defineProperty;
2794
2826
  var __defProps$1 = Object.defineProperties;
2795
2827
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
2796
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
2797
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
2798
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
2799
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2800
- var __spreadValues$2 = (a, b) => {
2828
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
2829
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
2830
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
2831
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2832
+ var __spreadValues$3 = (a, b) => {
2801
2833
  for (var prop in b || (b = {}))
2802
- if (__hasOwnProp$2.call(b, prop))
2803
- __defNormalProp$2(a, prop, b[prop]);
2804
- if (__getOwnPropSymbols$2)
2805
- for (var prop of __getOwnPropSymbols$2(b)) {
2806
- if (__propIsEnum$2.call(b, prop))
2807
- __defNormalProp$2(a, prop, b[prop]);
2834
+ if (__hasOwnProp$3.call(b, prop))
2835
+ __defNormalProp$3(a, prop, b[prop]);
2836
+ if (__getOwnPropSymbols$3)
2837
+ for (var prop of __getOwnPropSymbols$3(b)) {
2838
+ if (__propIsEnum$3.call(b, prop))
2839
+ __defNormalProp$3(a, prop, b[prop]);
2808
2840
  }
2809
2841
  return a;
2810
2842
  };
@@ -2812,16 +2844,16 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2812
2844
  var __objRest = (source, exclude) => {
2813
2845
  var target = {};
2814
2846
  for (var prop in source)
2815
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
2847
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
2816
2848
  target[prop] = source[prop];
2817
- if (source != null && __getOwnPropSymbols$2)
2818
- for (var prop of __getOwnPropSymbols$2(source)) {
2819
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
2849
+ if (source != null && __getOwnPropSymbols$3)
2850
+ for (var prop of __getOwnPropSymbols$3(source)) {
2851
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
2820
2852
  target[prop] = source[prop];
2821
2853
  }
2822
2854
  return target;
2823
2855
  };
2824
- var __async$2 = (__this, __arguments, generator) => {
2856
+ var __async$3 = (__this, __arguments, generator) => {
2825
2857
  return new Promise((resolve, reject) => {
2826
2858
  var fulfilled = (value) => {
2827
2859
  try {
@@ -2841,17 +2873,6 @@ var __async$2 = (__this, __arguments, generator) => {
2841
2873
  step((generator = generator.apply(__this, __arguments)).next());
2842
2874
  });
2843
2875
  };
2844
- const getEndUserIpAddress = () => __async$2(void 0, null, function* () {
2845
- try {
2846
- const response = yield axios.get("https://api.ipify.org/?format=json");
2847
- if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
2848
- return ipaddrExports.parse(response.data.ip).toString();
2849
- }
2850
- return void 0;
2851
- } catch (e) {
2852
- return void 0;
2853
- }
2854
- });
2855
2876
  class CarriersAPI {
2856
2877
  constructor(client) {
2857
2878
  this.client = client;
@@ -2861,12 +2882,12 @@ class CarriersAPI {
2861
2882
  this.get = (carrierId) => {
2862
2883
  return this.client.get(`/v1/carriers/${carrierId}`);
2863
2884
  };
2864
- this.connect = (_a) => __async$2(this, null, function* () {
2885
+ this.connect = (_a) => __async$3(this, null, function* () {
2865
2886
  var _b = _a, { carrierCode } = _b, connection = __objRest(_b, ["carrierCode"]);
2866
2887
  const endUserIpAddress = yield getEndUserIpAddress();
2867
2888
  if (!endUserIpAddress)
2868
2889
  return Promise.reject([new CodedError("Unable to get IP address")]);
2869
- return yield this.client.post(`/v1/registration/${carrierCode}`, __spreadProps$1(__spreadValues$2({}, connection), {
2890
+ return yield this.client.post(`/v1/registration/${carrierCode}`, __spreadProps$1(__spreadValues$3({}, connection), {
2870
2891
  endUserIpAddress
2871
2892
  }));
2872
2893
  });
@@ -5084,6 +5105,80 @@ class CustomPackagesAPI {
5084
5105
  }
5085
5106
  }
5086
5107
 
5108
+ var __defProp$2 = Object.defineProperty;
5109
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
5110
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
5111
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
5112
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5113
+ var __spreadValues$2 = (a, b) => {
5114
+ for (var prop in b || (b = {}))
5115
+ if (__hasOwnProp$2.call(b, prop))
5116
+ __defNormalProp$2(a, prop, b[prop]);
5117
+ if (__getOwnPropSymbols$2)
5118
+ for (var prop of __getOwnPropSymbols$2(b)) {
5119
+ if (__propIsEnum$2.call(b, prop))
5120
+ __defNormalProp$2(a, prop, b[prop]);
5121
+ }
5122
+ return a;
5123
+ };
5124
+ var __async$2 = (__this, __arguments, generator) => {
5125
+ return new Promise((resolve, reject) => {
5126
+ var fulfilled = (value) => {
5127
+ try {
5128
+ step(generator.next(value));
5129
+ } catch (e) {
5130
+ reject(e);
5131
+ }
5132
+ };
5133
+ var rejected = (value) => {
5134
+ try {
5135
+ step(generator.throw(value));
5136
+ } catch (e) {
5137
+ reject(e);
5138
+ }
5139
+ };
5140
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
5141
+ step((generator = generator.apply(__this, __arguments)).next());
5142
+ });
5143
+ };
5144
+ class FundingSourcesAPI {
5145
+ constructor(client) {
5146
+ this.client = client;
5147
+ this.list = () => {
5148
+ return this.client.get("/v1/funding_sources");
5149
+ };
5150
+ this.get = (fundingSourceId) => {
5151
+ return this.client.get(`/v1/funding_sources/${fundingSourceId}`);
5152
+ };
5153
+ this.create = (fundingSource) => __async$2(this, null, function* () {
5154
+ const endUserIpAddress = yield getEndUserIpAddress();
5155
+ if (!endUserIpAddress)
5156
+ return Promise.reject([new CodedError("Unable to get IP address")]);
5157
+ return yield this.client.post("/v1/funding_sources", __spreadValues$2({
5158
+ endUserIpAddress
5159
+ }, fundingSource));
5160
+ });
5161
+ this.update = (billingInfo, paymentMethod, fundingSourceId) => __async$2(this, null, function* () {
5162
+ const endUserIpAddress = yield getEndUserIpAddress();
5163
+ if (!endUserIpAddress)
5164
+ return Promise.reject([new CodedError("Unable to get IP address")]);
5165
+ return yield this.client.put(
5166
+ `/v1/funding_sources/${fundingSourceId}`,
5167
+ { billingInfo, endUserIpAddress, paymentMethod }
5168
+ );
5169
+ });
5170
+ this.registerCarrier = (carrier) => __async$2(this, null, function* () {
5171
+ const endUserIpAddress = yield getEndUserIpAddress();
5172
+ if (!endUserIpAddress)
5173
+ return Promise.reject([new CodedError("Unable to get IP address")]);
5174
+ return yield this.client.post("/v1/registration/funding_source", __spreadValues$2({
5175
+ endUserIpAddress
5176
+ }, carrier));
5177
+ });
5178
+ this.client = client;
5179
+ }
5180
+ }
5181
+
5087
5182
  class InsuranceAPI {
5088
5183
  constructor(client) {
5089
5184
  this.client = client;
@@ -5405,6 +5500,9 @@ class ShipEngineAPI {
5405
5500
  get customPackages() {
5406
5501
  return new CustomPackagesAPI(this.client);
5407
5502
  }
5503
+ get fundingSources() {
5504
+ return new FundingSourcesAPI(this.client);
5505
+ }
5408
5506
  get insurance() {
5409
5507
  return new InsuranceAPI(this.client);
5410
5508
  }
@@ -5441,6 +5539,7 @@ exports.Currency = Currency;
5441
5539
  exports.CustomPackagesAPI = CustomPackagesAPI;
5442
5540
  exports.CustomsContentsType = CustomsContentsType;
5443
5541
  exports.CustomsNonDeliveryType = CustomsNonDeliveryType;
5542
+ exports.FundingSourcesAPI = FundingSourcesAPI;
5444
5543
  exports.InsuranceAPI = InsuranceAPI;
5445
5544
  exports.InsuranceProviderType = InsuranceProviderType;
5446
5545
  exports.LabelsAPI = LabelsAPI;
@@ -5452,5 +5551,6 @@ exports.SalesOrdersAPI = SalesOrdersAPI;
5452
5551
  exports.ShipEngineAPI = ShipEngineAPI;
5453
5552
  exports.ShipmentsAPI = ShipmentsAPI;
5454
5553
  exports.WarehousesAPI = WarehousesAPI;
5554
+ exports.getEndUserIpAddress = getEndUserIpAddress;
5455
5555
  exports.isCodedError = isCodedError;
5456
5556
  exports.isCodedErrors = isCodedErrors;
package/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
2
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
3
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
2
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
3
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
4
4
  var __objRest$1 = (source, exclude) => {
5
5
  var target = {};
6
6
  for (var prop in source)
7
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
7
+ if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
8
8
  target[prop] = source[prop];
9
- if (source != null && __getOwnPropSymbols$3)
10
- for (var prop of __getOwnPropSymbols$3(source)) {
11
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
9
+ if (source != null && __getOwnPropSymbols$4)
10
+ for (var prop of __getOwnPropSymbols$4(source)) {
11
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
12
12
  target[prop] = source[prop];
13
13
  }
14
14
  return target;
@@ -115,6 +115,9 @@ class AddressesAPI {
115
115
  }
116
116
  }
117
117
 
118
+ const isCodedErrors = (errs) => Array.isArray(errs) && errs.every((err) => isCodedError(err));
119
+ const isCodedError = (err) => !!err.errorCode;
120
+
118
121
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
119
122
 
120
123
  function getDefaultExportFromCjs (x) {
@@ -2783,24 +2786,53 @@ var ipaddr = {
2783
2786
  }).call(commonjsGlobal);
2784
2787
  } (ipaddr));
2785
2788
 
2786
- const isCodedErrors = (errs) => Array.isArray(errs) && errs.every((err) => isCodedError(err));
2787
- const isCodedError = (err) => !!err.errorCode;
2789
+ var __async$4 = (__this, __arguments, generator) => {
2790
+ return new Promise((resolve, reject) => {
2791
+ var fulfilled = (value) => {
2792
+ try {
2793
+ step(generator.next(value));
2794
+ } catch (e) {
2795
+ reject(e);
2796
+ }
2797
+ };
2798
+ var rejected = (value) => {
2799
+ try {
2800
+ step(generator.throw(value));
2801
+ } catch (e) {
2802
+ reject(e);
2803
+ }
2804
+ };
2805
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
2806
+ step((generator = generator.apply(__this, __arguments)).next());
2807
+ });
2808
+ };
2809
+ const getEndUserIpAddress = () => __async$4(void 0, null, function* () {
2810
+ try {
2811
+ const response = yield axios.get("https://api.ipify.org/?format=json");
2812
+ if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
2813
+ return ipaddrExports.parse(response.data.ip).toString();
2814
+ }
2815
+ return void 0;
2816
+ } catch (e) {
2817
+ return void 0;
2818
+ }
2819
+ });
2788
2820
 
2789
- var __defProp$2 = Object.defineProperty;
2821
+ var __defProp$3 = Object.defineProperty;
2790
2822
  var __defProps$1 = Object.defineProperties;
2791
2823
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
2792
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
2793
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
2794
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
2795
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2796
- var __spreadValues$2 = (a, b) => {
2824
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
2825
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
2826
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
2827
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2828
+ var __spreadValues$3 = (a, b) => {
2797
2829
  for (var prop in b || (b = {}))
2798
- if (__hasOwnProp$2.call(b, prop))
2799
- __defNormalProp$2(a, prop, b[prop]);
2800
- if (__getOwnPropSymbols$2)
2801
- for (var prop of __getOwnPropSymbols$2(b)) {
2802
- if (__propIsEnum$2.call(b, prop))
2803
- __defNormalProp$2(a, prop, b[prop]);
2830
+ if (__hasOwnProp$3.call(b, prop))
2831
+ __defNormalProp$3(a, prop, b[prop]);
2832
+ if (__getOwnPropSymbols$3)
2833
+ for (var prop of __getOwnPropSymbols$3(b)) {
2834
+ if (__propIsEnum$3.call(b, prop))
2835
+ __defNormalProp$3(a, prop, b[prop]);
2804
2836
  }
2805
2837
  return a;
2806
2838
  };
@@ -2808,16 +2840,16 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2808
2840
  var __objRest = (source, exclude) => {
2809
2841
  var target = {};
2810
2842
  for (var prop in source)
2811
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
2843
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
2812
2844
  target[prop] = source[prop];
2813
- if (source != null && __getOwnPropSymbols$2)
2814
- for (var prop of __getOwnPropSymbols$2(source)) {
2815
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
2845
+ if (source != null && __getOwnPropSymbols$3)
2846
+ for (var prop of __getOwnPropSymbols$3(source)) {
2847
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
2816
2848
  target[prop] = source[prop];
2817
2849
  }
2818
2850
  return target;
2819
2851
  };
2820
- var __async$2 = (__this, __arguments, generator) => {
2852
+ var __async$3 = (__this, __arguments, generator) => {
2821
2853
  return new Promise((resolve, reject) => {
2822
2854
  var fulfilled = (value) => {
2823
2855
  try {
@@ -2837,17 +2869,6 @@ var __async$2 = (__this, __arguments, generator) => {
2837
2869
  step((generator = generator.apply(__this, __arguments)).next());
2838
2870
  });
2839
2871
  };
2840
- const getEndUserIpAddress = () => __async$2(void 0, null, function* () {
2841
- try {
2842
- const response = yield axios.get("https://api.ipify.org/?format=json");
2843
- if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
2844
- return ipaddrExports.parse(response.data.ip).toString();
2845
- }
2846
- return void 0;
2847
- } catch (e) {
2848
- return void 0;
2849
- }
2850
- });
2851
2872
  class CarriersAPI {
2852
2873
  constructor(client) {
2853
2874
  this.client = client;
@@ -2857,12 +2878,12 @@ class CarriersAPI {
2857
2878
  this.get = (carrierId) => {
2858
2879
  return this.client.get(`/v1/carriers/${carrierId}`);
2859
2880
  };
2860
- this.connect = (_a) => __async$2(this, null, function* () {
2881
+ this.connect = (_a) => __async$3(this, null, function* () {
2861
2882
  var _b = _a, { carrierCode } = _b, connection = __objRest(_b, ["carrierCode"]);
2862
2883
  const endUserIpAddress = yield getEndUserIpAddress();
2863
2884
  if (!endUserIpAddress)
2864
2885
  return Promise.reject([new CodedError("Unable to get IP address")]);
2865
- return yield this.client.post(`/v1/registration/${carrierCode}`, __spreadProps$1(__spreadValues$2({}, connection), {
2886
+ return yield this.client.post(`/v1/registration/${carrierCode}`, __spreadProps$1(__spreadValues$3({}, connection), {
2866
2887
  endUserIpAddress
2867
2888
  }));
2868
2889
  });
@@ -5080,6 +5101,80 @@ class CustomPackagesAPI {
5080
5101
  }
5081
5102
  }
5082
5103
 
5104
+ var __defProp$2 = Object.defineProperty;
5105
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
5106
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
5107
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
5108
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5109
+ var __spreadValues$2 = (a, b) => {
5110
+ for (var prop in b || (b = {}))
5111
+ if (__hasOwnProp$2.call(b, prop))
5112
+ __defNormalProp$2(a, prop, b[prop]);
5113
+ if (__getOwnPropSymbols$2)
5114
+ for (var prop of __getOwnPropSymbols$2(b)) {
5115
+ if (__propIsEnum$2.call(b, prop))
5116
+ __defNormalProp$2(a, prop, b[prop]);
5117
+ }
5118
+ return a;
5119
+ };
5120
+ var __async$2 = (__this, __arguments, generator) => {
5121
+ return new Promise((resolve, reject) => {
5122
+ var fulfilled = (value) => {
5123
+ try {
5124
+ step(generator.next(value));
5125
+ } catch (e) {
5126
+ reject(e);
5127
+ }
5128
+ };
5129
+ var rejected = (value) => {
5130
+ try {
5131
+ step(generator.throw(value));
5132
+ } catch (e) {
5133
+ reject(e);
5134
+ }
5135
+ };
5136
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
5137
+ step((generator = generator.apply(__this, __arguments)).next());
5138
+ });
5139
+ };
5140
+ class FundingSourcesAPI {
5141
+ constructor(client) {
5142
+ this.client = client;
5143
+ this.list = () => {
5144
+ return this.client.get("/v1/funding_sources");
5145
+ };
5146
+ this.get = (fundingSourceId) => {
5147
+ return this.client.get(`/v1/funding_sources/${fundingSourceId}`);
5148
+ };
5149
+ this.create = (fundingSource) => __async$2(this, null, function* () {
5150
+ const endUserIpAddress = yield getEndUserIpAddress();
5151
+ if (!endUserIpAddress)
5152
+ return Promise.reject([new CodedError("Unable to get IP address")]);
5153
+ return yield this.client.post("/v1/funding_sources", __spreadValues$2({
5154
+ endUserIpAddress
5155
+ }, fundingSource));
5156
+ });
5157
+ this.update = (billingInfo, paymentMethod, fundingSourceId) => __async$2(this, null, function* () {
5158
+ const endUserIpAddress = yield getEndUserIpAddress();
5159
+ if (!endUserIpAddress)
5160
+ return Promise.reject([new CodedError("Unable to get IP address")]);
5161
+ return yield this.client.put(
5162
+ `/v1/funding_sources/${fundingSourceId}`,
5163
+ { billingInfo, endUserIpAddress, paymentMethod }
5164
+ );
5165
+ });
5166
+ this.registerCarrier = (carrier) => __async$2(this, null, function* () {
5167
+ const endUserIpAddress = yield getEndUserIpAddress();
5168
+ if (!endUserIpAddress)
5169
+ return Promise.reject([new CodedError("Unable to get IP address")]);
5170
+ return yield this.client.post("/v1/registration/funding_source", __spreadValues$2({
5171
+ endUserIpAddress
5172
+ }, carrier));
5173
+ });
5174
+ this.client = client;
5175
+ }
5176
+ }
5177
+
5083
5178
  class InsuranceAPI {
5084
5179
  constructor(client) {
5085
5180
  this.client = client;
@@ -5401,6 +5496,9 @@ class ShipEngineAPI {
5401
5496
  get customPackages() {
5402
5497
  return new CustomPackagesAPI(this.client);
5403
5498
  }
5499
+ get fundingSources() {
5500
+ return new FundingSourcesAPI(this.client);
5501
+ }
5404
5502
  get insurance() {
5405
5503
  return new InsuranceAPI(this.client);
5406
5504
  }
@@ -5427,4 +5525,4 @@ class ShipEngineAPI {
5427
5525
  }
5428
5526
  }
5429
5527
 
5430
- export { AccountSettingsAPI, AddressesAPI, CarriersAPI, CodedError, ConfirmationType, CreditCardVendor, Currency, CustomPackagesAPI, CustomsContentsType, CustomsNonDeliveryType, InsuranceAPI, InsuranceProviderType, LabelsAPI, OrderSourcesAPI, RatesAPI, types as SE, SalesOrderShipmentsAPI, SalesOrdersAPI, ShipEngineAPI, ShipmentsAPI, WarehousesAPI, isCodedError, isCodedErrors };
5528
+ export { AccountSettingsAPI, AddressesAPI, CarriersAPI, CodedError, ConfirmationType, CreditCardVendor, Currency, CustomPackagesAPI, CustomsContentsType, CustomsNonDeliveryType, FundingSourcesAPI, InsuranceAPI, InsuranceProviderType, LabelsAPI, OrderSourcesAPI, RatesAPI, types as SE, SalesOrderShipmentsAPI, SalesOrdersAPI, ShipEngineAPI, ShipmentsAPI, WarehousesAPI, getEndUserIpAddress, isCodedError, isCodedErrors };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipengine/js-api",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -1,5 +1,4 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { SalesOrderShipment } from "../sales-order-shipments";
3
2
  import { Shipment, ShipmentRateResponse } from "./types";
4
3
  export type GetShipmentRatesOptions = {
5
4
  /**
@@ -13,5 +12,7 @@ export declare class ShipmentsAPI {
13
12
  private client;
14
13
  constructor(client: AxiosInstance);
15
14
  getShipmentRates: ({ shipmentId, createdAtStart }: GetShipmentRatesOptions) => Promise<import("axios").AxiosResponse<ShipmentRateResponse, any>>;
16
- create: (shipment: Partial<Omit<Shipment, "items">>) => Promise<import("axios").AxiosResponse<SalesOrderShipment, any>>;
15
+ create: (shipment: Partial<Omit<Shipment, "items">>) => Promise<import("axios").AxiosResponse<{
16
+ shipments: [Shipment];
17
+ }, any>>;
17
18
  }
package/types.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./carriers/types";
4
4
  export * from "./custom-packages/types";
5
5
  export * from "./dimensions/types";
6
6
  export * from "./errors/types";
7
+ export * from "./funding-sources/types";
7
8
  export * from "./insurance/types";
8
9
  export * from "./labels/types";
9
10
  export * from "./order-sources/types";
@@ -0,0 +1 @@
1
+ export * from "./ip-address";
@@ -0,0 +1 @@
1
+ export declare const getEndUserIpAddress: () => Promise<string | undefined>;