@artaio/node-api 1.9.0 → 1.10.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.
Files changed (36) hide show
  1. package/dist/lib/ArtaClient.js +57 -144
  2. package/dist/lib/arta.d.ts +2 -0
  3. package/dist/lib/arta.js +31 -30
  4. package/dist/lib/endpoint/addressVerifications.js +13 -16
  5. package/dist/lib/endpoint/attachment.js +13 -16
  6. package/dist/lib/endpoint/emailRules.js +16 -19
  7. package/dist/lib/endpoint/emailSubscriptions.js +16 -19
  8. package/dist/lib/endpoint/endpoint.js +44 -160
  9. package/dist/lib/endpoint/hostedSessions.js +19 -70
  10. package/dist/lib/endpoint/importCostEstimates.d.ts +17 -0
  11. package/dist/lib/endpoint/importCostEstimates.js +21 -0
  12. package/dist/lib/endpoint/invoicePayments.js +17 -27
  13. package/dist/lib/endpoint/invoices.js +11 -14
  14. package/dist/lib/endpoint/keys.js +15 -18
  15. package/dist/lib/endpoint/logs.js +17 -27
  16. package/dist/lib/endpoint/metadata.js +63 -64
  17. package/dist/lib/endpoint/organization.js +12 -67
  18. package/dist/lib/endpoint/payments.js +17 -27
  19. package/dist/lib/endpoint/requests.js +35 -113
  20. package/dist/lib/endpoint/selfShipCollectionAvailabilityChecks.js +6 -47
  21. package/dist/lib/endpoint/selfShipCollections.js +13 -16
  22. package/dist/lib/endpoint/shipments.js +21 -23
  23. package/dist/lib/endpoint/tags.js +13 -16
  24. package/dist/lib/endpoint/trackings.js +12 -66
  25. package/dist/lib/endpoint/uploads.js +13 -16
  26. package/dist/lib/endpoint/webhookDeliveries.js +9 -12
  27. package/dist/lib/endpoint/webhooks.js +37 -112
  28. package/dist/lib/error.js +14 -35
  29. package/dist/lib/index.d.ts +1 -0
  30. package/dist/lib/logging.js +18 -48
  31. package/dist/lib/net/FetchHttpClient.js +43 -108
  32. package/dist/lib/queryParams.js +5 -6
  33. package/dist/lib/types.d.ts +47 -0
  34. package/dist/lib/utils.js +10 -17
  35. package/dist/package.json +24 -18
  36. package/package.json +24 -18
@@ -1,79 +1,23 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
2
  Object.defineProperty(exports, "__esModule", { value: true });
50
3
  exports.FetchHttpClient = exports.FetchHttpClientResponse = void 0;
51
- var logging_1 = require("../logging");
52
- var FetchHttpClientResponse = /** @class */ (function () {
53
- function FetchHttpClientResponse(res) {
54
- var _this = this;
4
+ const logging_1 = require("../logging");
5
+ class FetchHttpClientResponse {
6
+ constructor(res) {
55
7
  this.res = res;
56
8
  this.headers = {};
57
9
  this.statusCode = res.status;
58
- res.headers.forEach(function (value, key) {
59
- _this.headers[key] = value;
10
+ res.headers.forEach((value, key) => {
11
+ this.headers[key] = value;
60
12
  });
61
13
  }
62
- FetchHttpClientResponse.prototype.json = function () {
63
- return __awaiter(this, void 0, void 0, function () {
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0: return [4 /*yield*/, this.res.json()];
67
- case 1: return [2 /*return*/, _a.sent()];
68
- }
69
- });
70
- });
71
- };
72
- return FetchHttpClientResponse;
73
- }());
14
+ async json() {
15
+ return await this.res.json();
16
+ }
17
+ }
74
18
  exports.FetchHttpClientResponse = FetchHttpClientResponse;
75
19
  function initParams(params) {
76
- var defaultParams = {
20
+ const defaultParams = {
77
21
  protocol: 'https',
78
22
  port: 443,
79
23
  path: '/',
@@ -82,50 +26,41 @@ function initParams(params) {
82
26
  requestData: null,
83
27
  timeout: 30000,
84
28
  };
85
- return __assign(__assign({}, defaultParams), params);
29
+ return {
30
+ ...defaultParams,
31
+ ...params,
32
+ };
86
33
  }
87
- var FetchHttpClient = /** @class */ (function () {
88
- function FetchHttpClient() {
34
+ class FetchHttpClient {
35
+ constructor() {
89
36
  this.logger = (0, logging_1.getLogger)();
90
37
  }
91
- FetchHttpClient.prototype.request = function (host, params) {
92
- return __awaiter(this, void 0, void 0, function () {
93
- var _a, protocol, port, path, method, timeout, headers, requestData, url, fetchUrl, setTimeoutId, rejectTimeout, response;
94
- return __generator(this, function (_b) {
95
- switch (_b.label) {
96
- case 0:
97
- _a = initParams(params), protocol = _a.protocol, port = _a.port, path = _a.path, method = _a.method, timeout = _a.timeout, headers = _a.headers, requestData = _a.requestData;
98
- url = "".concat(protocol, "://").concat(host, ":").concat(port).concat(path);
99
- this.logger.debug("[".concat(method, "] ").concat(url));
100
- fetchUrl = fetch(url, {
101
- method: method,
102
- headers: headers,
103
- body: requestData,
104
- });
105
- setTimeoutId = null;
106
- rejectTimeout = new Promise(function (_, reject) {
107
- setTimeoutId = setTimeout(function () {
108
- reject(new Error("Request timed out to ".concat(host, ":").concat(port)));
109
- }, timeout);
110
- });
111
- _b.label = 1;
112
- case 1:
113
- _b.trys.push([1, , 3, 4]);
114
- return [4 /*yield*/, Promise.race([
115
- fetchUrl,
116
- rejectTimeout,
117
- ])];
118
- case 2:
119
- response = (_b.sent());
120
- return [2 /*return*/, new FetchHttpClientResponse(response)];
121
- case 3:
122
- setTimeoutId != null && clearTimeout(setTimeoutId);
123
- return [7 /*endfinally*/];
124
- case 4: return [2 /*return*/];
125
- }
126
- });
38
+ async request(host, params) {
39
+ const { protocol, port, path, method, timeout, headers, requestData } = initParams(params);
40
+ const url = `${protocol}://${host}:${port}${path}`;
41
+ this.logger.debug(`[${method}] ${url}`);
42
+ const fetchUrl = fetch(url, {
43
+ method,
44
+ headers,
45
+ body: requestData,
127
46
  });
128
- };
129
- return FetchHttpClient;
130
- }());
47
+ let setTimeoutId = null;
48
+ const rejectTimeout = new Promise((_resolve, reject) => {
49
+ setTimeoutId = setTimeout(() => {
50
+ reject(new Error(`Request timed out to ${host}:${port}`));
51
+ }, timeout);
52
+ });
53
+ try {
54
+ const response = (await Promise.race([
55
+ fetchUrl,
56
+ rejectTimeout,
57
+ ]));
58
+ return new FetchHttpClientResponse(response);
59
+ }
60
+ finally {
61
+ if (setTimeoutId != null)
62
+ clearTimeout(setTimeoutId);
63
+ }
64
+ }
65
+ }
131
66
  exports.FetchHttpClient = FetchHttpClient;
@@ -5,16 +5,15 @@ exports.defaultQueryParams = {
5
5
  page: 1,
6
6
  page_size: 20,
7
7
  };
8
- var parseQueryParams = function (params) {
9
- var parsedParams = '';
10
- for (var _i = 0, _a = Object.entries(params); _i < _a.length; _i++) {
11
- var _b = _a[_i], key = _b[0], value = _b[1];
8
+ const parseQueryParams = (params) => {
9
+ let parsedParams = '';
10
+ for (const [key, value] of Object.entries(params)) {
12
11
  if (key && value) {
13
12
  if (parsedParams === '') {
14
- parsedParams = "?".concat(key, "=").concat(value);
13
+ parsedParams = `?${key}=${value}`;
15
14
  }
16
15
  else {
17
- parsedParams += "&".concat(key, "=").concat(value);
16
+ parsedParams += `&${key}=${value}`;
18
17
  }
19
18
  }
20
19
  }
@@ -494,6 +494,53 @@ export type HostedSession = {
494
494
  public_instructions_confirmation?: (string | null) | undefined;
495
495
  quoting_strategy: "all_rates" | "best_rate" | "compare_carriers";
496
496
  };
497
+ export type ImportCostEstimate = {
498
+ updated_at: Date;
499
+ created_at: Date;
500
+ id: string;
501
+ currency: "CAD" | "CHF" | "EUR" | "GBP" | "HKD" | "USD";
502
+ destination: {
503
+ city?: (string | null) | undefined;
504
+ country: string;
505
+ postal_code?: (string | null) | undefined;
506
+ region?: (string | null) | undefined;
507
+ };
508
+ end_use?: (string | null) | undefined;
509
+ origin: {
510
+ country: string;
511
+ };
512
+ quote_id?: (string | null) | undefined;
513
+ reference?: (string | null) | undefined;
514
+ shortcode: string;
515
+ status: "failed" | "success";
516
+ transport: {
517
+ service_level: string;
518
+ amount: string | number;
519
+ amount_currency?: (string | null) | undefined;
520
+ };
521
+ objects: {
522
+ value: string | number;
523
+ quantity?: (number | null) | undefined;
524
+ value_currency?: (("CAD" | "CHF" | "EUR" | "GBP" | "HKD" | "USD") | null) | undefined;
525
+ hs_code: string;
526
+ reference?: (string | null) | undefined;
527
+ country_of_origin?: (string | null) | undefined;
528
+ }[];
529
+ estimate: {
530
+ line_items: {
531
+ description: string;
532
+ subtype: string;
533
+ type: string;
534
+ amount: string | number;
535
+ }[];
536
+ summary: {
537
+ ddp_service_fees: string | number;
538
+ fees: string | number;
539
+ duties: string | number;
540
+ taxes: string | number;
541
+ };
542
+ };
543
+ };
497
544
  export type InvoicePayment = {
498
545
  updated_at: Date;
499
546
  created_at: Date;
package/dist/lib/utils.js CHANGED
@@ -1,32 +1,25 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.parseService = void 0;
15
4
  exports.createDateAsUTC = createDateAsUTC;
16
5
  exports.convertDatesToUtc = convertDatesToUtc;
17
6
  function createDateAsUTC(dateStr) {
18
- var date = new Date(dateStr);
19
- var timestamp = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
7
+ const date = new Date(dateStr);
8
+ const timestamp = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
20
9
  return new Date(timestamp);
21
10
  }
22
11
  function convertDatesToUtc(artaResponse) {
23
- return __assign(__assign({}, artaResponse), { created_at: artaResponse.created_at
12
+ return {
13
+ ...artaResponse,
14
+ created_at: artaResponse.created_at
24
15
  ? createDateAsUTC(artaResponse.created_at)
25
- : undefined, updated_at: artaResponse.updated_at
16
+ : undefined,
17
+ updated_at: artaResponse.updated_at
26
18
  ? createDateAsUTC(artaResponse.updated_at)
27
- : undefined });
19
+ : undefined,
20
+ };
28
21
  }
29
- var parseService = function (s) {
22
+ const parseService = (s) => {
30
23
  s.amount = Number(s.amount);
31
24
  if (s.included_services) {
32
25
  s.included_services.forEach(exports.parseService);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artaio/node-api",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "The Arta Node library provides a seamless integration to Arta API for backend applications using both Typescript or Javascript.",
5
5
  "scripts": {
6
6
  "build": "npm run build:types && tsc -p tsconfig-build.json",
@@ -35,24 +35,25 @@
35
35
  "Selman Uysal <selman@arta.io>"
36
36
  ],
37
37
  "devDependencies": {
38
- "@commitlint/cli": "^18.2.0",
39
- "@commitlint/config-conventional": "^18.1.0",
40
- "@types/jest": "^29.5.7",
41
- "@typescript-eslint/eslint-plugin": "^6.9.1",
42
- "@typescript-eslint/parser": "^6.9.1",
43
- "eslint": "^8.52.0",
44
- "eslint-config-prettier": "^9.0.0",
45
- "eslint-plugin-import": "^2.29.0",
46
- "eslint-plugin-n": "^16.2.0",
47
- "eslint-plugin-promise": "^6.1.1",
48
- "husky": "^9.0.11",
49
- "jest": "^29.7.0",
50
- "nock": "^14.0.1",
38
+ "@commitlint/cli": "^20.0.0",
39
+ "@commitlint/config-conventional": "^20.0.0",
40
+ "@eslint/js": "^9.0.0",
41
+ "@types/jest": "^30.0.0",
42
+ "@types/node": "^18.19.130",
43
+ "eslint": "^9.0.0",
44
+ "eslint-config-prettier": "^10.0.0",
45
+ "eslint-plugin-import": "^2.32.0",
46
+ "eslint-plugin-n": "^17.0.0",
47
+ "eslint-plugin-promise": "^7.0.0",
48
+ "husky": "^9.1.7",
49
+ "jest": "^30.0.0",
50
+ "nock": "^14.0.12",
51
51
  "pinst": "^3.0.0",
52
- "prettier": "3.0.3",
53
- "ts-jest": "^29.1.1",
52
+ "prettier": "3.8.1",
53
+ "ts-jest": "^29.4.9",
54
54
  "ts-node": "^10.9.2",
55
- "typescript": "^5.2.2",
55
+ "typescript": "^6.0.0",
56
+ "typescript-eslint": "^8.0.0",
56
57
  "zod": "^3.22.4",
57
58
  "zod-to-ts": "^1.2.0"
58
59
  },
@@ -62,5 +63,10 @@
62
63
  "engines": {
63
64
  "node": ">=18.x"
64
65
  },
65
- "license": "MIT"
66
+ "license": "MIT",
67
+ "overrides": {
68
+ "zod-to-ts": {
69
+ "typescript": "$typescript"
70
+ }
71
+ }
66
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artaio/node-api",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "The Arta Node library provides a seamless integration to Arta API for backend applications using both Typescript or Javascript.",
5
5
  "scripts": {
6
6
  "build": "npm run build:types && tsc -p tsconfig-build.json",
@@ -35,24 +35,25 @@
35
35
  "Selman Uysal <selman@arta.io>"
36
36
  ],
37
37
  "devDependencies": {
38
- "@commitlint/cli": "^18.2.0",
39
- "@commitlint/config-conventional": "^18.1.0",
40
- "@types/jest": "^29.5.7",
41
- "@typescript-eslint/eslint-plugin": "^6.9.1",
42
- "@typescript-eslint/parser": "^6.9.1",
43
- "eslint": "^8.52.0",
44
- "eslint-config-prettier": "^9.0.0",
45
- "eslint-plugin-import": "^2.29.0",
46
- "eslint-plugin-n": "^16.2.0",
47
- "eslint-plugin-promise": "^6.1.1",
48
- "husky": "^9.0.11",
49
- "jest": "^29.7.0",
50
- "nock": "^14.0.1",
38
+ "@commitlint/cli": "^20.0.0",
39
+ "@commitlint/config-conventional": "^20.0.0",
40
+ "@eslint/js": "^9.0.0",
41
+ "@types/jest": "^30.0.0",
42
+ "@types/node": "^18.19.130",
43
+ "eslint": "^9.0.0",
44
+ "eslint-config-prettier": "^10.0.0",
45
+ "eslint-plugin-import": "^2.32.0",
46
+ "eslint-plugin-n": "^17.0.0",
47
+ "eslint-plugin-promise": "^7.0.0",
48
+ "husky": "^9.1.7",
49
+ "jest": "^30.0.0",
50
+ "nock": "^14.0.12",
51
51
  "pinst": "^3.0.0",
52
- "prettier": "3.0.3",
53
- "ts-jest": "^29.1.1",
52
+ "prettier": "3.8.1",
53
+ "ts-jest": "^29.4.9",
54
54
  "ts-node": "^10.9.2",
55
- "typescript": "^5.2.2",
55
+ "typescript": "^6.0.0",
56
+ "typescript-eslint": "^8.0.0",
56
57
  "zod": "^3.22.4",
57
58
  "zod-to-ts": "^1.2.0"
58
59
  },
@@ -62,5 +63,10 @@
62
63
  "engines": {
63
64
  "node": ">=18.x"
64
65
  },
65
- "license": "MIT"
66
+ "license": "MIT",
67
+ "overrides": {
68
+ "zod-to-ts": {
69
+ "typescript": "$typescript"
70
+ }
71
+ }
66
72
  }