UNPKG

liveperson-functions-cli

Version:
126 lines 5.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextServiceClient = exports.DOMAINS = void 0; const client_1 = require("./restclient/client"); const sdkError_1 = require("./types/errors/sdkError"); const predicates_1 = require("./util/predicates"); const constants_1 = require("./util/constants"); var constants_2 = require("./util/constants"); Object.defineProperty(exports, "DOMAINS", { enumerable: true, get: function () { return constants_2.DOMAINS; } }); class ContextServiceClient { /** * Instanciate a new client for target baseurl using provided api key * @param baseUrl You can use the DOMAINS constant to choose the correct baseUrl. * @param apiKey */ constructor(baseUrl, apiKey) { // TODO: Maybe replace this with an approach where we get the value from csds (however no entry available yet). this.client = new client_1.RestClient(baseUrl, apiKey); } async createNamespace(accountId, namespace, options) { try { if ((0, predicates_1.isNullOrUndefined)(namespace) || (0, predicates_1.isEmptyString)(namespace)) { throw new sdkError_1.SDKError(constants_1.ErrorCodes.Parameter.Incorrect, 'Namespace can not be null, undefined or empty string'); } if ((0, predicates_1.isBuiltInNamespace)(namespace)) { throw new sdkError_1.SDKError(constants_1.ErrorCodes.Parameter.Incorrect, 'Can not create a built-in namespace'); } if ((options === null || options === void 0 ? void 0 : options.ttl) <= 0) { throw new sdkError_1.SDKError(constants_1.ErrorCodes.Parameter.Incorrect, 'TTL needs to be a positive integer above 0'); } const defaultOption = {}; // Ensuring data is stored permanent return await this.client.createNamespace(accountId, namespace, Object.assign({}, defaultOption, options)); } catch (error) { throw sdkError_1.SDKError.from(error); } } async deleteNamespace(accountId, namespace) { try { if ((0, predicates_1.isNullOrUndefined)(namespace) || (0, predicates_1.isEmptyString)(namespace)) { return; } if ((0, predicates_1.isBuiltInNamespace)(namespace)) { throw new sdkError_1.SDKError(constants_1.ErrorCodes.Parameter.Incorrect, 'Can not delete a built-in namespace'); } return await this.client.deleteNamespace(accountId, namespace); } catch (error) { throw sdkError_1.SDKError.from(error); } } async getListOfNamespaces(accountId) { try { return await this.client.getListOfNamespaces(accountId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async setPropertiesInNamespace(accountId, namespace, properties, sessionId) { try { return await this.client.setOrUpdatePropertiesInNamespace(accountId, namespace, properties, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async updatePropertiesInNamespace(accountId, namespace, properties, sessionId) { try { return await this.client.setOrUpdatePropertiesInNamespace(accountId, namespace, properties, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async getAllPropertiesInSession(accountId, namespace, sessionId) { try { return await this.client.getAllPropertiesInSession(accountId, namespace, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async getSelectedPropertiesInSession(accountId, namespace, propertyNames, sessionId) { try { return await this.client.getSelectedPropertiesInSession(accountId, namespace, propertyNames, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async getPropertyInSession(accountId, namespace, propertyName, sessionId) { try { return await this.client.getPropertyInSession(accountId, namespace, propertyName, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async deletePropertyInSession(accountId, namespace, propertyName, sessionId) { try { return await this.client.deletePropertyInSession(accountId, namespace, propertyName, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async deleteSession(accountId, namespace, sessionId) { try { return await this.client.deleteSession(accountId, namespace, sessionId); } catch (error) { throw sdkError_1.SDKError.from(error); } } async getListOfSessions(accountId, namespace) { try { return await this.client.getListOfSessions(accountId, namespace); } catch (error) { throw sdkError_1.SDKError.from(error); } } } exports.ContextServiceClient = ContextServiceClient; //# sourceMappingURL=lib.js.map