UNPKG

channelape-sdk

Version:
67 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const channelape_logger_1 = require("channelape-logger"); const request = require("request"); const _1 = require("."); const RequestClientWrapper_1 = require("./RequestClientWrapper"); const ActionsService_1 = require("./actions/service/ActionsService"); const ChannelsService_1 = require("./channels/service/ChannelsService"); const OrdersService_1 = require("./orders/service/OrdersService"); const INVALID_CONFIGURATION_ERROR_MESSAGE = 'Invalid configuration. sessionId is required.'; const THREE_MINUTES_IN_MS = 180000; const TWO_SECONDS_IN_MS = 2000; class ChannelApeClient { constructor(clientConfiguration) { if (clientConfiguration.sessionId.length === 0) { throw new Error(INVALID_CONFIGURATION_ERROR_MESSAGE); } this.sessionId = clientConfiguration.sessionId; this.endpoint = (clientConfiguration.endpoint == null) ? _1.Environment.PRODUCTION : clientConfiguration.endpoint; this.timeout = (clientConfiguration.timeout == null || clientConfiguration.timeout < TWO_SECONDS_IN_MS) ? THREE_MINUTES_IN_MS : clientConfiguration.timeout; this.maximumRequestRetryTimeout = (clientConfiguration.maximumRequestRetryTimeout == null || clientConfiguration.maximumRequestRetryTimeout < TWO_SECONDS_IN_MS) ? THREE_MINUTES_IN_MS : clientConfiguration.maximumRequestRetryTimeout; this.logLevel = (clientConfiguration.logLevel == null) ? channelape_logger_1.LogLevel.OFF : clientConfiguration.logLevel; const client = request.defaults({ baseUrl: this.endpoint, timeout: this.timeout, json: true, headers: { 'X-Channel-Ape-Authorization-Token': this.sessionId } }); this.requestClientWrapper = new RequestClientWrapper_1.default(client, this.logLevel, this.endpoint, this.maximumRequestRetryTimeout); this.actionsService = new ActionsService_1.default(this.requestClientWrapper); this.channelsService = new ChannelsService_1.default(this.requestClientWrapper); this.ordersService = new OrdersService_1.default(this.requestClientWrapper); } get SessionId() { return this.sessionId; } get Timeout() { return this.timeout; } get MaximumRequestRetryTimeout() { return this.maximumRequestRetryTimeout; } get Endpoint() { return this.endpoint; } get LogLevel() { return this.logLevel; } channels() { return this.channelsService; } actions() { return this.actionsService; } orders() { return this.ordersService; } } exports.default = ChannelApeClient; //# sourceMappingURL=ChannelApeClient.js.map