@artaio/node-api 0.30.1 → 0.31.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.
@@ -1,5 +1,5 @@
1
- import { HttpClient } from './net/HttpClient';
2
- import { RestClient } from './net/RestClient';
1
+ import type { HttpClient } from './net/HttpClient';
2
+ import type { RestClient } from './net/RestClient';
3
3
  export type ArtaID = number | string;
4
4
  interface ArtaClientConfig {
5
5
  apiKey: string;
@@ -13,9 +13,9 @@ export declare class ArtaClient implements RestClient {
13
13
  private request;
14
14
  private makeReqParams;
15
15
  private makeArtaAuthHeader;
16
- get(path: string, auth?: string): Promise<any>;
17
- post(path: string, payload: any, auth?: string): Promise<any>;
18
- patch(path: string, payload: any, auth?: string): Promise<any>;
16
+ get<T>(path: string, auth?: string): Promise<T>;
17
+ post<U, T>(path: string, payload: U, auth?: string): Promise<T>;
18
+ patch<U, T>(path: string, payload: U, auth?: string): Promise<T>;
19
19
  delete(path: string, auth?: string): Promise<void>;
20
20
  }
21
21
  export {};
@@ -53,6 +53,9 @@ var ArtaClient = /** @class */ (function () {
53
53
  switch (_a.label) {
54
54
  case 0:
55
55
  authValue = this.makeArtaAuthHeader(this.config.apiKey);
56
+ if (params.headers == null) {
57
+ params.headers = {};
58
+ }
56
59
  if (params.headers.Authorization == null) {
57
60
  params.headers.Authorization = authValue;
58
61
  }
@@ -83,6 +86,9 @@ var ArtaClient = /** @class */ (function () {
83
86
  },
84
87
  };
85
88
  if (auth) {
89
+ if (reqParams.headers == null) {
90
+ reqParams.headers = {};
91
+ }
86
92
  reqParams.headers.Authorization = this.makeArtaAuthHeader(auth);
87
93
  }
88
94
  if (body) {
@@ -2,7 +2,7 @@ import { ArtaID } from '../ArtaClient';
2
2
  import { RestClient } from '../net/RestClient';
3
3
  import { Page } from '../pagination';
4
4
  import { AdditionalService, ArtaLocation, ArtaObject, Insurance, PaymentProcessType, QuoteType, QuoteRequestStatus } from '../MetadataTypes';
5
- import { DatedInterface, Nullable, NullableString } from '../utils';
5
+ import { type DatedInterface, type Nullable, type NullableString } from '../utils';
6
6
  import { HostedSessionsSearch } from '../search';
7
7
  export interface HostedSession extends DatedInterface {
8
8
  id: ArtaID;
@@ -13,6 +13,10 @@ export interface InvoicePayment extends DatedInterface {
13
13
  payment_id?: NullableString;
14
14
  shipment_id?: NullableString;
15
15
  }
16
+ export interface UnparsedInvoicePayment extends Omit<InvoicePayment, 'paid_on' | 'amount'> {
17
+ paid_on: string;
18
+ amount: string;
19
+ }
16
20
  export declare class InvoicePaymentsEndpoint {
17
21
  private readonly artaClient;
18
22
  private readonly defaultEndpoint;
@@ -1,6 +1,18 @@
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
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.InvoicePaymentsEndpoint = void 0;
15
+ var utils_1 = require("../utils");
4
16
  var endpoint_1 = require("./endpoint");
5
17
  var InvoicePaymentsEndpoint = /** @class */ (function () {
6
18
  function InvoicePaymentsEndpoint(artaClient) {
@@ -17,9 +29,7 @@ var InvoicePaymentsEndpoint = /** @class */ (function () {
17
29
  return this.defaultEndpoint.list({ page: page, page_size: pageSize }, auth);
18
30
  };
19
31
  InvoicePaymentsEndpoint.prototype.enrichFields = function (resource) {
20
- resource.amount = Number(resource.amount);
21
- resource.paid_on = new Date(resource.paid_on);
22
- return resource;
32
+ return __assign(__assign({}, resource), { amount: Number(resource.amount), paid_on: (0, utils_1.createDateAsUTC)(resource.paid_on) });
23
33
  };
24
34
  return InvoicePaymentsEndpoint;
25
35
  }());
@@ -18,6 +18,10 @@ export interface Log extends DatedInterface {
18
18
  status: number;
19
19
  updated_at: Date;
20
20
  }
21
+ export interface UnparsedLog extends Omit<Log, 'start_at' | 'end_at'> {
22
+ start_at: string;
23
+ end_at: string;
24
+ }
21
25
  export declare class LogsEndpoint {
22
26
  private readonly artaClient;
23
27
  private readonly defaultEndpoint;
@@ -1,4 +1,15 @@
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
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.LogsEndpoint = void 0;
4
15
  var utils_1 = require("../utils");
@@ -18,9 +29,7 @@ var LogsEndpoint = /** @class */ (function () {
18
29
  return this.defaultEndpoint.list({ page: page, page_size: pageSize }, auth);
19
30
  };
20
31
  LogsEndpoint.prototype.enrichFields = function (resource) {
21
- resource.start_at = (0, utils_1.createDateAsUTC)(resource.start_at);
22
- resource.end_at = (0, utils_1.createDateAsUTC)(resource.end_at);
23
- return resource;
32
+ return __assign(__assign({}, resource), { start_at: (0, utils_1.createDateAsUTC)(resource.start_at), end_at: (0, utils_1.createDateAsUTC)(resource.end_at) });
24
33
  };
25
34
  return LogsEndpoint;
26
35
  }());
@@ -10,6 +10,10 @@ export interface Payment extends DatedInterface {
10
10
  context: PaymentContext;
11
11
  paid_on: Date;
12
12
  }
13
+ export interface UnparsedPayment extends Omit<Payment, 'paid_on' | 'amount'> {
14
+ paid_on: string;
15
+ amount: string;
16
+ }
13
17
  export declare class PaymentsEndpoint {
14
18
  private readonly artaClient;
15
19
  private readonly defaultEndpoint;
@@ -1,6 +1,18 @@
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
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.PaymentsEndpoint = void 0;
15
+ var utils_1 = require("../utils");
4
16
  var endpoint_1 = require("./endpoint");
5
17
  var PaymentsEndpoint = /** @class */ (function () {
6
18
  function PaymentsEndpoint(artaClient) {
@@ -17,9 +29,7 @@ var PaymentsEndpoint = /** @class */ (function () {
17
29
  return this.defaultEndpoint.list({ page: page, page_size: pageSize }, auth);
18
30
  };
19
31
  PaymentsEndpoint.prototype.enrichFields = function (resource) {
20
- resource.amount = Number(resource.amount);
21
- resource.paid_on = new Date(resource.paid_on);
22
- return resource;
32
+ return __assign(__assign({}, resource), { amount: Number(resource.amount), paid_on: (0, utils_1.createDateAsUTC)(resource.paid_on) });
23
33
  };
24
34
  return PaymentsEndpoint;
25
35
  }());
@@ -15,10 +15,10 @@ var ShipmentsEndpoint = /** @class */ (function () {
15
15
  r.emissions = Number(r.emissions);
16
16
  }
17
17
  if (r.schedule) {
18
- r.schedule.delivery_end = new Date(r.schedule.delivery_end);
19
- r.schedule.delivery_start = new Date(r.schedule.delivery_start);
20
- r.schedule.pickup_end = new Date(r.schedule.pickup_end);
21
- r.schedule.pickup_start = new Date(r.schedule.pickup_start);
18
+ r.schedule.delivery_end = (0, utils_1.createDateAsUTC)(r.schedule.delivery_end);
19
+ r.schedule.delivery_start = (0, utils_1.createDateAsUTC)(r.schedule.delivery_start);
20
+ r.schedule.pickup_end = (0, utils_1.createDateAsUTC)(r.schedule.pickup_end);
21
+ r.schedule.pickup_start = (0, utils_1.createDateAsUTC)(r.schedule.pickup_start);
22
22
  }
23
23
  if (r.packages) {
24
24
  r.packages.forEach(function (p) {
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -45,16 +56,14 @@ var TrackingsEndpoint = /** @class */ (function () {
45
56
  }
46
57
  TrackingsEndpoint.prototype.getById = function (id, auth) {
47
58
  return __awaiter(this, void 0, void 0, function () {
48
- var tracking;
59
+ var unparsedTracking, parsedEvents;
49
60
  return __generator(this, function (_a) {
50
61
  switch (_a.label) {
51
62
  case 0: return [4 /*yield*/, this.artaClient.get("".concat(this.path, "/").concat(id), auth)];
52
63
  case 1:
53
- tracking = _a.sent();
54
- tracking.events.forEach(function (e) {
55
- e.date = (0, utils_1.createDateAsUTC)(e.date);
56
- });
57
- return [2 /*return*/, tracking];
64
+ unparsedTracking = _a.sent();
65
+ parsedEvents = unparsedTracking.events.map(function (event) { return (__assign(__assign({}, event), { date: (0, utils_1.createDateAsUTC)(event.date) })); });
66
+ return [2 /*return*/, __assign(__assign({}, unparsedTracking), { events: parsedEvents })];
58
67
  }
59
68
  });
60
69
  });
@@ -1,16 +1,19 @@
1
1
  export type HttpMethod = 'get' | 'post' | 'patch' | 'put' | 'delete';
2
+ export interface HttpClientHeaders {
3
+ [key: string]: string | string[] | undefined;
4
+ }
2
5
  export interface HttpClientResponse {
3
6
  statusCode?: number;
4
- headers?: any;
7
+ headers?: HttpClientHeaders;
5
8
  body: () => Promise<string>;
6
- json: () => Promise<any>;
9
+ json: <T>() => Promise<T>;
7
10
  }
8
11
  export interface HttpRequestParameters {
9
12
  protocol: 'http' | 'https';
10
13
  port: number;
11
14
  path: string;
12
15
  method: HttpMethod;
13
- headers: any;
16
+ headers: HttpClientHeaders;
14
17
  requestData: string;
15
18
  timeout: number;
16
19
  }
@@ -10,7 +10,7 @@ export declare class NodeHttpClientResponse implements HttpClientResponse {
10
10
  private rawBody;
11
11
  constructor(res: http.IncomingMessage);
12
12
  body(): Promise<string>;
13
- json(): Promise<any>;
13
+ json<T>(): Promise<T>;
14
14
  }
15
15
  export declare class NodeHttpClient implements HttpClient {
16
16
  private readonly agent?;
@@ -1,6 +1,6 @@
1
1
  export interface RestClient {
2
- get(path: string, auth?: string): Promise<any>;
3
- post(path: string, payload: any, auth?: string): Promise<any>;
4
- patch(path: string, payload: any, auth?: string): Promise<any>;
2
+ get<T>(path: string, auth?: string): Promise<T>;
3
+ post<U, T>(path: string, payload: U, auth?: string): Promise<T>;
4
+ patch<U, T>(path: string, payload: U, auth?: string): Promise<T>;
5
5
  delete(path: string, auth?: string): Promise<void>;
6
6
  }
@@ -1,9 +1,14 @@
1
1
  export interface DatedInterface {
2
2
  updated_at?: Date;
3
- created_at: Date;
3
+ created_at?: Date;
4
4
  }
5
+ export interface UnparsedDatedInterface {
6
+ updated_at?: string;
7
+ created_at?: string;
8
+ }
9
+ export type NotDateParsed<T> = Omit<T, 'updated_at' | 'created_at'> & UnparsedDatedInterface;
5
10
  export declare function createDateAsUTC(dateStr: string): Date;
6
- export declare function convertDatesToUtc(artaResponse: any): any;
11
+ export declare function convertDatesToUtc<T extends DatedInterface>(artaResponse: NotDateParsed<T>): T;
7
12
  export type Nullable<T> = T | null;
8
13
  export type NullableString = Nullable<string>;
9
14
  export declare const parseService: (s: any) => void;
package/dist/lib/utils.js CHANGED
@@ -1,4 +1,15 @@
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
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.parseService = exports.convertDatesToUtc = exports.createDateAsUTC = void 0;
4
15
  function createDateAsUTC(dateStr) {
@@ -8,11 +19,11 @@ function createDateAsUTC(dateStr) {
8
19
  }
9
20
  exports.createDateAsUTC = createDateAsUTC;
10
21
  function convertDatesToUtc(artaResponse) {
11
- if (artaResponse.updated_at) {
12
- artaResponse.updated_at = createDateAsUTC(artaResponse.updated_at);
13
- }
14
- artaResponse.created_at = createDateAsUTC(artaResponse.created_at);
15
- return artaResponse;
22
+ return __assign(__assign({}, artaResponse), { created_at: artaResponse.created_at
23
+ ? createDateAsUTC(artaResponse.created_at)
24
+ : undefined, updated_at: artaResponse.updated_at
25
+ ? createDateAsUTC(artaResponse.updated_at)
26
+ : undefined });
16
27
  }
17
28
  exports.convertDatesToUtc = convertDatesToUtc;
18
29
  var parseService = function (s) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artaio/node-api",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "The Arta Node library provides a seamless integration to Arta API for applications running on Node.js using both Typescript or Javascript.",
5
5
  "scripts": {
6
6
  "build": "tsc -p tsconfig-build.json",
@@ -31,28 +31,31 @@
31
31
  "Selman Uysal <selman@arta.io>"
32
32
  ],
33
33
  "devDependencies": {
34
- "@commitlint/cli": "^17.6.3",
35
- "@commitlint/config-conventional": "^17.6.3",
36
- "@types/jest": "^29.5.1",
34
+ "@commitlint/cli": "^18.2.0",
35
+ "@commitlint/config-conventional": "^18.1.0",
36
+ "@types/jest": "^29.5.7",
37
37
  "@types/nock": "^11.1.0",
38
- "@types/node": "^20.2.1",
39
- "@typescript-eslint/eslint-plugin": "^5.59.6",
40
- "@typescript-eslint/parser": "^5.59.6",
41
- "eslint": "^8.40.0",
42
- "eslint-config-prettier": "^8.8.0",
43
- "eslint-plugin-import": "^2.27.5",
44
- "eslint-plugin-n": "^16.0.0",
38
+ "@types/node": "^20.8.10",
39
+ "@typescript-eslint/eslint-plugin": "^6.9.1",
40
+ "@typescript-eslint/parser": "^6.9.1",
41
+ "eslint": "^8.52.0",
42
+ "eslint-config-prettier": "^9.0.0",
43
+ "eslint-plugin-import": "^2.29.0",
44
+ "eslint-plugin-n": "^16.2.0",
45
45
  "eslint-plugin-promise": "^6.1.1",
46
46
  "husky": "^8.0.3",
47
- "jest": "^29.5.0",
48
- "nock": "^13.3.1",
47
+ "jest": "^29.7.0",
48
+ "nock": "^13.3.8",
49
49
  "pinst": "^3.0.0",
50
- "prettier": "2.8.8",
51
- "ts-jest": "^29.1.0",
52
- "typescript": "^5.0.4"
50
+ "prettier": "3.0.3",
51
+ "ts-jest": "^29.1.1",
52
+ "typescript": "^5.2.2"
53
53
  },
54
54
  "bugs": {
55
55
  "url": "https://github.com/artaio/arta-node-api/issues"
56
56
  },
57
+ "engines": {
58
+ "node": ">=14.x"
59
+ },
57
60
  "license": "MIT"
58
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artaio/node-api",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "The Arta Node library provides a seamless integration to Arta API for applications running on Node.js using both Typescript or Javascript.",
5
5
  "scripts": {
6
6
  "build": "tsc -p tsconfig-build.json",
@@ -31,28 +31,31 @@
31
31
  "Selman Uysal <selman@arta.io>"
32
32
  ],
33
33
  "devDependencies": {
34
- "@commitlint/cli": "^17.6.3",
35
- "@commitlint/config-conventional": "^17.6.3",
36
- "@types/jest": "^29.5.1",
34
+ "@commitlint/cli": "^18.2.0",
35
+ "@commitlint/config-conventional": "^18.1.0",
36
+ "@types/jest": "^29.5.7",
37
37
  "@types/nock": "^11.1.0",
38
- "@types/node": "^20.2.1",
39
- "@typescript-eslint/eslint-plugin": "^5.59.6",
40
- "@typescript-eslint/parser": "^5.59.6",
41
- "eslint": "^8.40.0",
42
- "eslint-config-prettier": "^8.8.0",
43
- "eslint-plugin-import": "^2.27.5",
44
- "eslint-plugin-n": "^16.0.0",
38
+ "@types/node": "^20.8.10",
39
+ "@typescript-eslint/eslint-plugin": "^6.9.1",
40
+ "@typescript-eslint/parser": "^6.9.1",
41
+ "eslint": "^8.52.0",
42
+ "eslint-config-prettier": "^9.0.0",
43
+ "eslint-plugin-import": "^2.29.0",
44
+ "eslint-plugin-n": "^16.2.0",
45
45
  "eslint-plugin-promise": "^6.1.1",
46
46
  "husky": "^8.0.3",
47
- "jest": "^29.5.0",
48
- "nock": "^13.3.1",
47
+ "jest": "^29.7.0",
48
+ "nock": "^13.3.8",
49
49
  "pinst": "^3.0.0",
50
- "prettier": "2.8.8",
51
- "ts-jest": "^29.1.0",
52
- "typescript": "^5.0.4"
50
+ "prettier": "3.0.3",
51
+ "ts-jest": "^29.1.1",
52
+ "typescript": "^5.2.2"
53
53
  },
54
54
  "bugs": {
55
55
  "url": "https://github.com/artaio/arta-node-api/issues"
56
56
  },
57
+ "engines": {
58
+ "node": ">=14.x"
59
+ },
57
60
  "license": "MIT"
58
61
  }