@artaio/node-api 0.27.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 (66) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +48 -0
  3. package/dist/lib/ArtaClient.d.ts +21 -0
  4. package/dist/lib/ArtaClient.js +155 -0
  5. package/dist/lib/MetadataTypes.d.ts +96 -0
  6. package/dist/lib/MetadataTypes.js +2 -0
  7. package/dist/lib/arta.d.ts +45 -0
  8. package/dist/lib/arta.js +57 -0
  9. package/dist/lib/endpoint/attachment.d.ts +32 -0
  10. package/dist/lib/endpoint/attachment.js +27 -0
  11. package/dist/lib/endpoint/emailRules.d.ts +30 -0
  12. package/dist/lib/endpoint/emailRules.js +33 -0
  13. package/dist/lib/endpoint/emailSubscriptions.d.ts +32 -0
  14. package/dist/lib/endpoint/emailSubscriptions.js +33 -0
  15. package/dist/lib/endpoint/endpoint.d.ts +26 -0
  16. package/dist/lib/endpoint/endpoint.js +168 -0
  17. package/dist/lib/endpoint/hostedSessions.d.ts +53 -0
  18. package/dist/lib/endpoint/hostedSessions.js +81 -0
  19. package/dist/lib/endpoint/invoicePayments.d.ts +24 -0
  20. package/dist/lib/endpoint/invoicePayments.js +26 -0
  21. package/dist/lib/endpoint/invoices.d.ts +27 -0
  22. package/dist/lib/endpoint/invoices.js +27 -0
  23. package/dist/lib/endpoint/keys.d.ts +28 -0
  24. package/dist/lib/endpoint/keys.js +30 -0
  25. package/dist/lib/endpoint/logs.d.ts +29 -0
  26. package/dist/lib/endpoint/logs.js +27 -0
  27. package/dist/lib/endpoint/metadata.d.ts +67 -0
  28. package/dist/lib/endpoint/metadata.js +56 -0
  29. package/dist/lib/endpoint/organization.d.ts +31 -0
  30. package/dist/lib/endpoint/organization.js +84 -0
  31. package/dist/lib/endpoint/payments.d.ts +21 -0
  32. package/dist/lib/endpoint/payments.js +26 -0
  33. package/dist/lib/endpoint/requests.d.ts +80 -0
  34. package/dist/lib/endpoint/requests.js +113 -0
  35. package/dist/lib/endpoint/shipments.d.ts +80 -0
  36. package/dist/lib/endpoint/shipments.js +44 -0
  37. package/dist/lib/endpoint/trackings.d.ts +25 -0
  38. package/dist/lib/endpoint/trackings.js +64 -0
  39. package/dist/lib/endpoint/uploads.d.ts +36 -0
  40. package/dist/lib/endpoint/uploads.js +27 -0
  41. package/dist/lib/endpoint/webhookDeliveries.d.ts +26 -0
  42. package/dist/lib/endpoint/webhookDeliveries.js +21 -0
  43. package/dist/lib/endpoint/webhooks.d.ts +35 -0
  44. package/dist/lib/endpoint/webhooks.js +124 -0
  45. package/dist/lib/error.d.ts +8 -0
  46. package/dist/lib/error.js +54 -0
  47. package/dist/lib/index.d.ts +19 -0
  48. package/dist/lib/index.js +20 -0
  49. package/dist/lib/logging.d.ts +17 -0
  50. package/dist/lib/logging.js +79 -0
  51. package/dist/lib/net/HttpClient.d.ts +19 -0
  52. package/dist/lib/net/HttpClient.js +2 -0
  53. package/dist/lib/net/NodeHttpClient.d.ts +20 -0
  54. package/dist/lib/net/NodeHttpClient.js +203 -0
  55. package/dist/lib/net/RestClient.d.ts +6 -0
  56. package/dist/lib/net/RestClient.js +2 -0
  57. package/dist/lib/pagination.d.ts +9 -0
  58. package/dist/lib/pagination.js +2 -0
  59. package/dist/lib/queryParams.d.ts +7 -0
  60. package/dist/lib/queryParams.js +23 -0
  61. package/dist/lib/search.d.ts +3 -0
  62. package/dist/lib/search.js +2 -0
  63. package/dist/lib/utils.d.ts +9 -0
  64. package/dist/lib/utils.js +24 -0
  65. package/dist/package.json +49 -0
  66. package/package.json +58 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UploadsEndpoint = void 0;
4
+ var endpoint_1 = require("./endpoint");
5
+ var UploadsEndpoint = /** @class */ (function () {
6
+ function UploadsEndpoint(artaClient) {
7
+ this.artaClient = artaClient;
8
+ this.path = '/uploads';
9
+ this.defaultEndpoint = new endpoint_1.DefaultEndpoint(this.path, this.artaClient);
10
+ }
11
+ UploadsEndpoint.prototype.getById = function (id, auth) {
12
+ return this.defaultEndpoint.getById(id, auth);
13
+ };
14
+ UploadsEndpoint.prototype.list = function (page, pageSize, auth) {
15
+ if (page === void 0) { page = 1; }
16
+ if (pageSize === void 0) { pageSize = 20; }
17
+ return this.defaultEndpoint.list({ page: page, page_size: pageSize }, auth);
18
+ };
19
+ UploadsEndpoint.prototype.create = function (payload, auth) {
20
+ return this.defaultEndpoint.create({ upload: payload }, auth);
21
+ };
22
+ UploadsEndpoint.prototype.remove = function (id, auth) {
23
+ return this.defaultEndpoint.remove(id, auth);
24
+ };
25
+ return UploadsEndpoint;
26
+ }());
27
+ exports.UploadsEndpoint = UploadsEndpoint;
@@ -0,0 +1,26 @@
1
+ import { ArtaID } from '../ArtaClient';
2
+ import { WebhookDeliveryStatus, WebhookDeliveryType, WebhookResourceType } from '../MetadataTypes';
3
+ import { RestClient } from '../net/RestClient';
4
+ import { Page } from '../pagination';
5
+ import { DatedInterface, NullableString } from '../utils';
6
+ export interface WebhookDelivery extends DatedInterface {
7
+ id: ArtaID;
8
+ resource_id: number;
9
+ resource_type: WebhookResourceType;
10
+ response_status_code: number;
11
+ status: WebhookDeliveryStatus;
12
+ type: WebhookDeliveryType;
13
+ webhook_id: number;
14
+ webhook_url: string;
15
+ next_retry?: NullableString;
16
+ request_body?: NullableString;
17
+ response_body?: NullableString;
18
+ }
19
+ export declare class WebhookDeliveriesEndpoint {
20
+ private readonly artaClient;
21
+ private readonly defaultEndpoint;
22
+ private readonly path;
23
+ constructor(artaClient: RestClient);
24
+ getById(id: ArtaID, auth?: string): Promise<WebhookDelivery>;
25
+ list(page?: number, pageSize?: number, auth?: string): Promise<Page<WebhookDelivery>>;
26
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookDeliveriesEndpoint = void 0;
4
+ var endpoint_1 = require("./endpoint");
5
+ var WebhookDeliveriesEndpoint = /** @class */ (function () {
6
+ function WebhookDeliveriesEndpoint(artaClient) {
7
+ this.artaClient = artaClient;
8
+ this.path = '/webhook_deliveries';
9
+ this.defaultEndpoint = new endpoint_1.DefaultEndpoint(this.path, this.artaClient);
10
+ }
11
+ WebhookDeliveriesEndpoint.prototype.getById = function (id, auth) {
12
+ return this.defaultEndpoint.getById(id, auth);
13
+ };
14
+ WebhookDeliveriesEndpoint.prototype.list = function (page, pageSize, auth) {
15
+ if (page === void 0) { page = 1; }
16
+ if (pageSize === void 0) { pageSize = 20; }
17
+ return this.defaultEndpoint.list({ page: page, page_size: pageSize }, auth);
18
+ };
19
+ return WebhookDeliveriesEndpoint;
20
+ }());
21
+ exports.WebhookDeliveriesEndpoint = WebhookDeliveriesEndpoint;
@@ -0,0 +1,35 @@
1
+ import { ArtaID } from '../ArtaClient';
2
+ import { RestClient } from '../net/RestClient';
3
+ import { DatedInterface } from '../utils';
4
+ import { Page } from '../pagination';
5
+ export interface Webhook extends DatedInterface {
6
+ id: ArtaID;
7
+ name: string;
8
+ url: string;
9
+ ping: (auth?: string) => Promise<void>;
10
+ getSecret: (auth?: string) => Promise<string>;
11
+ resetSecret: (auth?: string) => Promise<string>;
12
+ }
13
+ export interface WebhookCreateBody {
14
+ name: string;
15
+ url: string;
16
+ }
17
+ export interface WebhookCreate {
18
+ webhook: WebhookCreateBody;
19
+ }
20
+ export declare class WebhooksEndpoint {
21
+ private readonly artaClient;
22
+ private readonly defaultEndpoint;
23
+ private readonly path;
24
+ constructor(artaClient: RestClient);
25
+ private withFunctionCalls;
26
+ getById(id: ArtaID, auth?: string): Promise<Webhook>;
27
+ list(page?: number, pageSize?: number, auth?: string): Promise<Page<Webhook>>;
28
+ listAll(auth?: string): AsyncGenerator<Webhook>;
29
+ create(payload: WebhookCreateBody, auth?: string): Promise<Webhook>;
30
+ update(id: ArtaID, payload: Partial<WebhookCreateBody> | Partial<Webhook>, auth?: string): Promise<Webhook>;
31
+ remove(id: ArtaID, auth?: string): Promise<void>;
32
+ ping(id: ArtaID, auth?: string): Promise<void>;
33
+ getSecret(id: ArtaID, auth?: string): Promise<string>;
34
+ resetSecret(id: ArtaID, auth?: string): Promise<string>;
35
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.WebhooksEndpoint = void 0;
40
+ var endpoint_1 = require("./endpoint");
41
+ var WebhooksEndpoint = /** @class */ (function () {
42
+ function WebhooksEndpoint(artaClient) {
43
+ this.artaClient = artaClient;
44
+ this.path = '/webhooks';
45
+ this.defaultEndpoint = new endpoint_1.DefaultEndpoint(this.path, this.artaClient, this.withFunctionCalls.bind(this));
46
+ }
47
+ WebhooksEndpoint.prototype.withFunctionCalls = function (webhook) {
48
+ var _this = this;
49
+ webhook.ping = function (auth) { return _this.ping(webhook.id, auth); };
50
+ webhook.getSecret = function (auth) { return _this.getSecret(webhook.id, auth); };
51
+ webhook.resetSecret = function (auth) { return _this.resetSecret(webhook.id, auth); };
52
+ return webhook;
53
+ };
54
+ WebhooksEndpoint.prototype.getById = function (id, auth) {
55
+ return __awaiter(this, void 0, void 0, function () {
56
+ return __generator(this, function (_a) {
57
+ return [2 /*return*/, this.defaultEndpoint.getById(id, auth)];
58
+ });
59
+ });
60
+ };
61
+ WebhooksEndpoint.prototype.list = function (page, pageSize, auth) {
62
+ if (page === void 0) { page = 1; }
63
+ if (pageSize === void 0) { pageSize = 20; }
64
+ return this.defaultEndpoint.list({ page: page, page_size: pageSize }, auth);
65
+ };
66
+ WebhooksEndpoint.prototype.listAll = function (auth) {
67
+ return this.defaultEndpoint.listAll(auth);
68
+ };
69
+ WebhooksEndpoint.prototype.create = function (payload, auth) {
70
+ return this.defaultEndpoint.create({ webhook: payload }, auth);
71
+ };
72
+ WebhooksEndpoint.prototype.update = function (id, payload, auth) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var webhookUpdate;
75
+ return __generator(this, function (_a) {
76
+ webhookUpdate = { webhook: payload };
77
+ return [2 /*return*/, this.defaultEndpoint.update(id, webhookUpdate, auth)];
78
+ });
79
+ });
80
+ };
81
+ WebhooksEndpoint.prototype.remove = function (id, auth) {
82
+ return this.defaultEndpoint.remove(id, auth);
83
+ };
84
+ WebhooksEndpoint.prototype.ping = function (id, auth) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0: return [4 /*yield*/, this.artaClient.post("".concat(this.path, "/").concat(id, "/ping"), auth)];
89
+ case 1:
90
+ _a.sent();
91
+ return [2 /*return*/];
92
+ }
93
+ });
94
+ });
95
+ };
96
+ WebhooksEndpoint.prototype.getSecret = function (id, auth) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var secret;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, this.artaClient.get("".concat(this.path, "/").concat(id, "/secret_token"), auth)];
102
+ case 1:
103
+ secret = _a.sent();
104
+ return [2 /*return*/, secret.secret_token];
105
+ }
106
+ });
107
+ });
108
+ };
109
+ WebhooksEndpoint.prototype.resetSecret = function (id, auth) {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var newSecret;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0: return [4 /*yield*/, this.artaClient.patch("".concat(this.path, "/").concat(id, "/secret_token/reset"), auth)];
115
+ case 1:
116
+ newSecret = _a.sent();
117
+ return [2 /*return*/, newSecret.secret_token];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ return WebhooksEndpoint;
123
+ }());
124
+ exports.WebhooksEndpoint = WebhooksEndpoint;
@@ -0,0 +1,8 @@
1
+ export interface ArtaAPIError {
2
+ errors: {
3
+ [key: string]: string | string[];
4
+ };
5
+ }
6
+ export declare class ArtaSDKError extends Error {
7
+ constructor(apiError: ArtaAPIError, status: number);
8
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ArtaSDKError = void 0;
19
+ var parseArtaError = function (apiError) {
20
+ var formattedArtaError = '';
21
+ for (var _i = 0, _a = Object.keys(apiError.errors); _i < _a.length; _i++) {
22
+ var key = _a[_i];
23
+ if (key === 'detail') {
24
+ return "".concat(apiError.errors['detail'], ", ");
25
+ }
26
+ else if (Array.isArray(apiError.errors[key])) {
27
+ for (var _b = 0, _c = apiError.errors[key]; _b < _c.length; _b++) {
28
+ var error = _c[_b];
29
+ formattedArtaError += "".concat(key, " ").concat(error, ", ");
30
+ }
31
+ }
32
+ else {
33
+ formattedArtaError += "".concat(key, " ").concat(apiError.errors[key], ", ");
34
+ }
35
+ }
36
+ return formattedArtaError;
37
+ };
38
+ var ArtaSDKError = /** @class */ (function (_super) {
39
+ __extends(ArtaSDKError, _super);
40
+ function ArtaSDKError(apiError, status) {
41
+ var _this = this;
42
+ var keys = Object.keys(apiError.errors);
43
+ if (keys.length === 0) {
44
+ _this = _super.call(this, "Unknwon API error, HTTP status: ".concat(status)) || this;
45
+ }
46
+ else {
47
+ _this = _super.call(this, "".concat(parseArtaError(apiError), "HTTP status: ").concat(status)) || this;
48
+ }
49
+ Object.setPrototypeOf(_this, ArtaSDKError.prototype);
50
+ return _this;
51
+ }
52
+ return ArtaSDKError;
53
+ }(Error));
54
+ exports.ArtaSDKError = ArtaSDKError;
@@ -0,0 +1,19 @@
1
+ export { Arta } from './arta';
2
+ export { Logger, LoggerVerbosity } from './logging';
3
+ export { Attachment, AttachmentCreateBodyRequest, AttachmentCreateBodyShipment, AttachmentCreateBody, } from './endpoint/attachment';
4
+ export { EmailRule, EmailRuleCreateBody } from './endpoint/emailRules';
5
+ export { EmailSubscription, EmailSubscriptionCreateBody, } from './endpoint/emailSubscriptions';
6
+ export { HostedSession, HostedSessionCreateBody, } from './endpoint/hostedSessions';
7
+ export { InvoicePayment } from './endpoint/invoicePayments';
8
+ export { Invoice } from './endpoint/invoices';
9
+ export { Key, KeyCreateBody } from './endpoint/keys';
10
+ export { Log } from './endpoint/logs';
11
+ export * from './MetadataTypes';
12
+ export { Organization } from './endpoint/organization';
13
+ export { Payment } from './endpoint/payments';
14
+ export { Upload, UploadCreateBody } from './endpoint/uploads';
15
+ export { WebhookDelivery } from './endpoint/webhookDeliveries';
16
+ export { Webhook, WebhookCreate } from './endpoint/webhooks';
17
+ export { Tracking, TrackingEvent, Carrier } from './endpoint/trackings';
18
+ export { Quote, QuoteRequest, QuoteRequestCreateBody, UpdateRequestsContactsBody, CustomQuotePayload, } from './endpoint/requests';
19
+ export { Package, ShipmentSchedule, ShipmentTracking, Shipment, ShipmentCreateBody, } from './endpoint/shipments';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Arta = void 0;
18
+ var arta_1 = require("./arta");
19
+ Object.defineProperty(exports, "Arta", { enumerable: true, get: function () { return arta_1.Arta; } });
20
+ __exportStar(require("./MetadataTypes"), exports);
@@ -0,0 +1,17 @@
1
+ export interface Logger {
2
+ debug(message?: any, ...optionalParams: any[]): void;
3
+ info(message?: any, ...optionalParams: any[]): void;
4
+ warn(message?: any, ...optionalParams: any[]): void;
5
+ error(message?: any, ...optionalParams: any[]): void;
6
+ }
7
+ declare enum LogLevel {
8
+ NONE = 0,
9
+ ERROR = 1,
10
+ WARN = 2,
11
+ INFO = 3,
12
+ DEBUG = 4
13
+ }
14
+ export type LoggerVerbosity = keyof typeof LogLevel;
15
+ export declare const initLogger: (logger: Logger, loggerVerbosity: LoggerVerbosity) => void;
16
+ export declare const getLogger: () => Logger;
17
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getLogger = exports.initLogger = void 0;
13
+ var LogLevel;
14
+ (function (LogLevel) {
15
+ LogLevel[LogLevel["NONE"] = 0] = "NONE";
16
+ LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
17
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
18
+ LogLevel[LogLevel["INFO"] = 3] = "INFO";
19
+ LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
20
+ })(LogLevel || (LogLevel = {}));
21
+ var LoggerWrapper = /** @class */ (function () {
22
+ function LoggerWrapper(logger, loggerVerbosity) {
23
+ this.logger = logger;
24
+ this.verbosity = LogLevel[loggerVerbosity];
25
+ }
26
+ LoggerWrapper.prototype.debug = function (message) {
27
+ var _a;
28
+ var optionalParams = [];
29
+ for (var _i = 1; _i < arguments.length; _i++) {
30
+ optionalParams[_i - 1] = arguments[_i];
31
+ }
32
+ if (this.verbosity >= LogLevel.DEBUG) {
33
+ (_a = this.logger).debug.apply(_a, __spreadArray([message], optionalParams, false));
34
+ }
35
+ };
36
+ LoggerWrapper.prototype.info = function (message) {
37
+ var _a;
38
+ var optionalParams = [];
39
+ for (var _i = 1; _i < arguments.length; _i++) {
40
+ optionalParams[_i - 1] = arguments[_i];
41
+ }
42
+ if (this.verbosity >= LogLevel.INFO) {
43
+ (_a = this.logger).info.apply(_a, __spreadArray([message], optionalParams, false));
44
+ }
45
+ };
46
+ LoggerWrapper.prototype.warn = function (message) {
47
+ var _a;
48
+ var optionalParams = [];
49
+ for (var _i = 1; _i < arguments.length; _i++) {
50
+ optionalParams[_i - 1] = arguments[_i];
51
+ }
52
+ if (this.verbosity >= LogLevel.WARN) {
53
+ (_a = this.logger).warn.apply(_a, __spreadArray([message], optionalParams, false));
54
+ }
55
+ };
56
+ LoggerWrapper.prototype.error = function (message) {
57
+ var _a;
58
+ var optionalParams = [];
59
+ for (var _i = 1; _i < arguments.length; _i++) {
60
+ optionalParams[_i - 1] = arguments[_i];
61
+ }
62
+ if (this.verbosity >= LogLevel.ERROR) {
63
+ (_a = this.logger).error.apply(_a, __spreadArray([message], optionalParams, false));
64
+ }
65
+ };
66
+ return LoggerWrapper;
67
+ }());
68
+ var _logger;
69
+ var initLogger = function (logger, loggerVerbosity) {
70
+ _logger = new LoggerWrapper(logger, loggerVerbosity);
71
+ };
72
+ exports.initLogger = initLogger;
73
+ var getLogger = function () {
74
+ if (!_logger) {
75
+ (0, exports.initLogger)(console, 'ERROR');
76
+ }
77
+ return _logger;
78
+ };
79
+ exports.getLogger = getLogger;
@@ -0,0 +1,19 @@
1
+ export type HttpMethod = 'get' | 'post' | 'patch' | 'put' | 'delete';
2
+ export interface HttpClientResponse {
3
+ statusCode?: number;
4
+ headers?: any;
5
+ body: () => Promise<string>;
6
+ json: () => Promise<any>;
7
+ }
8
+ export interface HttpRequestParameters {
9
+ protocol: 'http' | 'https';
10
+ port: number;
11
+ path: string;
12
+ method: HttpMethod;
13
+ headers: any;
14
+ requestData: string;
15
+ timeout: number;
16
+ }
17
+ export interface HttpClient {
18
+ request: (host: string, params?: Partial<HttpRequestParameters>) => Promise<HttpClientResponse>;
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import * as http from 'http';
4
+ import * as https from 'https';
5
+ import { HttpClient, HttpClientResponse, HttpRequestParameters } from './HttpClient';
6
+ export declare class NodeHttpClientResponse implements HttpClientResponse {
7
+ private readonly res;
8
+ statusCode?: number;
9
+ headers?: http.IncomingHttpHeaders;
10
+ private rawBody;
11
+ constructor(res: http.IncomingMessage);
12
+ body(): Promise<string>;
13
+ json(): Promise<any>;
14
+ }
15
+ export declare class NodeHttpClient implements HttpClient {
16
+ private readonly agent?;
17
+ private readonly logger;
18
+ constructor(agent?: http.Agent | https.Agent | undefined);
19
+ request(host: string, params?: Partial<HttpRequestParameters>): Promise<HttpClientResponse>;
20
+ }