UNPKG

channelape-sdk

Version:
209 lines 9.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const LogLevel_1 = require("./model/LogLevel"); 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 VariantsService_1 = require("./variants/service/VariantsService"); const BusinessesService_1 = require("./businesses/service/BusinessesService"); const Environment_1 = require("./model/Environment"); const SessionsService_1 = require("./sessions/service/SessionsService"); const SubscriptionsService_1 = require("./subscriptions/service/SubscriptionsService"); const AnalyticsService_1 = require("./analytics/service/AnalyticsService"); const SuppliersService_1 = require("./suppliers/service/SuppliersService"); const ProductFiltersService_1 = require("./products/filters/service/ProductFiltersService"); const UsersService_1 = require("./users/service/UsersService"); const InventoriesService_1 = require("./inventories/service/InventoriesService"); const LocationsService_1 = require("./locations/service/LocationsService"); const StepsService_1 = require("./steps/service/StepsService"); const PlaysService_1 = require("./plays/service/PlaysService"); const RecipesService_1 = require("./receipes/service/RecipesService"); const SchedulesService_1 = require("./schedules/service/SchedulesService"); const BatchesService_1 = require("./batches/services/BatchesService"); const LoggingService_1 = require("./logging/service/LoggingService"); const MISSING_SESSION_ID_ERROR_MESSAGE = 'sessionId is required.'; const MINIMUM_REQUEST_RETRY_RANDOM_DELAY_TOO_SMALL_ERROR_MESSAGE = 'minimumRequestRetryRandomDelay must be 1000 or greater'; const MAXIMUM_REQUEST_RETRY_RANDOM_DELAY_TOO_SMALL_ERROR_MESSAGE = 'maximumRequestRetryRandomDelay must be 2000 or greater'; const MINIMUM_REQUEST_RETRY_RANDOM_DELAY_GREATER_THAN_MAXIMUM_REQUEST_RETRY_RANDOM_ERROR_MESSAGE = 'minimumRequestRetryRandomDelay cannot be greater than maximumRequestRetryRandomDelay'; const MAXIMUM_CONCURRENT_CONNECTIONS_MINIMUM_VALUE_MESSAGE = 'maximumConcurrentConnections must be 1 or greater'; const THREE_MINUTES_IN_MS = 180000; const TWO_SECONDS_IN_MS = 2000; const ONE_SECOND_IN_MS = 1000; const FIVE_SECONDS_IN_MS = 5000; class ChannelApeClient { constructor(clientConfiguration) { var _a; const configurationErrors = this.validateConfiguration(clientConfiguration); if (configurationErrors !== undefined) { throw new Error(`Invalid configuration. ${configurationErrors}`); } this.sessionId = clientConfiguration.sessionId; this.refreshToken = (_a = clientConfiguration.refreshToken) !== null && _a !== void 0 ? _a : ''; this.endpoint = clientConfiguration.endpoint == null ? Environment_1.default.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 ? LogLevel_1.default.OFF : clientConfiguration.logLevel; this.minimumRequestRetryRandomDelay = clientConfiguration.minimumRequestRetryRandomDelay ? clientConfiguration.minimumRequestRetryRandomDelay : ONE_SECOND_IN_MS; this.maximumRequestRetryRandomDelay = clientConfiguration.maximumRequestRetryRandomDelay ? clientConfiguration.maximumRequestRetryRandomDelay : FIVE_SECONDS_IN_MS; this.maximumConcurrentConnections = clientConfiguration.maximumConcurrentConnections ? clientConfiguration.maximumConcurrentConnections : 5; this.requestClientWrapper = new RequestClientWrapper_1.default({ timeout: this.timeout, session: this.sessionId, refreshToken: this.refreshToken, logLevel: this.logLevel, endpoint: this.endpoint, maximumRequestRetryTimeout: this.maximumRequestRetryTimeout, minimumRequestRetryRandomDelay: this.minimumRequestRetryRandomDelay, maximumRequestRetryRandomDelay: this.maximumRequestRetryRandomDelay, maximumConcurrentConnections: this.maximumConcurrentConnections, }); this.actionsService = new ActionsService_1.default(this.requestClientWrapper); this.channelsService = new ChannelsService_1.default(this.requestClientWrapper); this.suppliersService = new SuppliersService_1.default(this.requestClientWrapper); this.ordersService = new OrdersService_1.default(this.requestClientWrapper); this.variantsService = new VariantsService_1.default(this.requestClientWrapper); this.businessesService = new BusinessesService_1.default(this.requestClientWrapper); this.sessionsService = new SessionsService_1.default(this.requestClientWrapper); this.subscriptionsService = new SubscriptionsService_1.default(this.requestClientWrapper); this.analyticsService = new AnalyticsService_1.default(this.requestClientWrapper); this.productFiltersService = new ProductFiltersService_1.default(this.requestClientWrapper); this.usersService = new UsersService_1.default(this.requestClientWrapper); this.locationsService = new LocationsService_1.default(this.requestClientWrapper); this.inventoriesService = new InventoriesService_1.default(this.requestClientWrapper, this.locationsService); this.stepsService = new StepsService_1.default(this.requestClientWrapper); this.playsService = new PlaysService_1.default(this.requestClientWrapper, this.stepsService); this.recipesService = new RecipesService_1.default(this.requestClientWrapper); this.schedulesService = new SchedulesService_1.default(this.requestClientWrapper); this.batchesService = new BatchesService_1.BatchesService(this.requestClientWrapper); this.loggingService = new LoggingService_1.default(this.requestClientWrapper); } get SessionId() { return this.sessionId; } get Timeout() { return this.timeout; } get MaximumRequestRetryTimeout() { return this.maximumRequestRetryTimeout; } get MaximumConcurrentConnections() { return this.maximumConcurrentConnections; } get Endpoint() { return this.endpoint; } get LogLevel() { return this.logLevel; } channels() { return this.channelsService; } suppliers() { return this.suppliersService; } actions() { return this.actionsService; } orders() { return this.ordersService; } variants() { return this.variantsService; } businesses() { return this.businessesService; } sessions() { return this.sessionsService; } subscriptions() { return this.subscriptionsService; } analytics() { return this.analyticsService; } productFilters() { return this.productFiltersService; } users() { return this.usersService; } inventories() { return this.inventoriesService; } locations() { return this.locationsService; } steps() { return this.stepsService; } plays() { return this.playsService; } recipes() { return this.recipesService; } schedules() { return this.schedulesService; } batches() { return this.batchesService; } logging() { return this.loggingService; } validateConfiguration(clientConfiguration) { const errors = []; if (clientConfiguration.sessionId.length === 0) { errors.push(MISSING_SESSION_ID_ERROR_MESSAGE); } if (clientConfiguration.minimumRequestRetryRandomDelay && clientConfiguration.minimumRequestRetryRandomDelay < ONE_SECOND_IN_MS) { errors.push(MINIMUM_REQUEST_RETRY_RANDOM_DELAY_TOO_SMALL_ERROR_MESSAGE); } if (clientConfiguration.maximumRequestRetryRandomDelay && clientConfiguration.maximumRequestRetryRandomDelay < TWO_SECONDS_IN_MS) { errors.push(MAXIMUM_REQUEST_RETRY_RANDOM_DELAY_TOO_SMALL_ERROR_MESSAGE); } if (clientConfiguration.maximumRequestRetryRandomDelay && clientConfiguration.minimumRequestRetryRandomDelay && clientConfiguration.minimumRequestRetryRandomDelay > clientConfiguration.maximumRequestRetryRandomDelay) { errors.push(MINIMUM_REQUEST_RETRY_RANDOM_DELAY_GREATER_THAN_MAXIMUM_REQUEST_RETRY_RANDOM_ERROR_MESSAGE); } if (clientConfiguration.maximumConcurrentConnections && clientConfiguration.maximumConcurrentConnections < 1) { errors.push(MAXIMUM_CONCURRENT_CONNECTIONS_MINIMUM_VALUE_MESSAGE); } if (errors.length > 0) { return errors.join('\n'); } return undefined; } } exports.default = ChannelApeClient; //# sourceMappingURL=ChannelApeClient.js.map