UNPKG

connect-sdk-nodejs

Version:

SDK to communicate with the Worldline Global Collect platform using the Worldline Connect Server API

79 lines 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.newSdkContext = void 0; const authentication_1 = require("./authentication"); const consoleLogger = (level, message) => console[level](message); function toLogger(logger) { return (level, message) => logger[level](message); } function defaultPort(scheme) { return scheme === "https" ? 443 : 80; } class SdkContextImpl { constructor(configuration) { var _a, _b, _c, _d, _e; this.endpoint = { host: configuration.host, scheme: (_a = configuration.scheme) !== null && _a !== void 0 ? _a : "https", port: (_b = configuration.port) !== null && _b !== void 0 ? _b : defaultPort((_c = configuration.scheme) !== null && _c !== void 0 ? _c : "https") }; this.proxy = configuration.proxy; this.connectionOptions = configuration.connectionOptions; this.authenticator = new authentication_1.V1HMACAuthenticator(configuration.apiKeyId, configuration.secretApiKey); this.logger = configuration.logger ? toLogger(configuration.logger) : consoleLogger; this.enableLogging = (_d = configuration.enableLogging) !== null && _d !== void 0 ? _d : false; if (configuration.integrator) { this.integrator = configuration.integrator; } else { throw new Error("integrator is required"); } if (configuration.shoppingCartExtension) { if (configuration.shoppingCartExtension.creator && configuration.shoppingCartExtension.name && configuration.shoppingCartExtension.version) { this.shoppingCartExtension = configuration.shoppingCartExtension; } else { throw new Error("shoppingCartExtension is missing a required property (creator / name / version). Your shoppingCartExtension: " + JSON.stringify(configuration.shoppingCartExtension)); } } this.obfuscationRules = (_e = configuration.obfuscationRules) !== null && _e !== void 0 ? _e : {}; } getEndpoint() { return this.endpoint; } getProxy() { return this.proxy; } getConnectionOptions() { return this.connectionOptions; } getAuthenticator() { return this.authenticator; } getLogger() { return this.logger; } setLogger(logger) { this.logger = logger; } isLoggingEnabled() { return this.enableLogging || false; } setEnableLogging(isLoggingEnabled) { this.enableLogging = isLoggingEnabled; } getIntegrator() { return this.integrator; } getShoppingCartExtension() { return this.shoppingCartExtension; } getObfuscationRules() { return this.obfuscationRules; } } function newSdkContext(configuration) { return new SdkContextImpl(configuration); } exports.newSdkContext = newSdkContext; //# sourceMappingURL=context.js.map