liveperson-functions-cli
Version:
LivePerson Functions CLI
107 lines • 4.87 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FaasContextServiceClient = void 0;
const lib_1 = require("../context-service-sdk/lib");
const secretClient_1 = require("../secret-storage/secretClient");
class FaasContextServiceClient {
constructor(config) {
const { apiKey, accountId } = config;
this.accountId = accountId;
// TODO: when a default secret is available for the context service,
// enter the name here and make the apiKey param optional. Also adjust JSDOC in index.ts
this.apiKeySecretName = undefined;
this.baseUrl = getBaseUrl();
this.apiKey = apiKey;
this.contextServiceClient = undefined;
}
/* istanbul ignore next */
async initContextServiceClient() {
if (!this.apiKey) {
this.apiKey = await this.getApiKey(this.apiKeySecretName);
}
if (!this.contextServiceClient) {
this.contextServiceClient = new lib_1.ContextServiceClient(this.baseUrl, this.apiKey);
}
}
/* istanbul ignore next */
async getApiKey(secretName) {
const secretClient = new secretClient_1.VaultSecretClient();
const { value } = await secretClient.readSecret(secretName);
return value;
}
/* istanbul ignore next */
async createNamespace(namespace, options) {
await this.initContextServiceClient();
return this.contextServiceClient.createNamespace(this.accountId, namespace, options);
}
/* istanbul ignore next */
async deleteNamespace(namespace) {
await this.initContextServiceClient();
return this.contextServiceClient.deleteNamespace(this.accountId, namespace);
}
/* istanbul ignore next */
async getListOfNamespaces() {
await this.initContextServiceClient();
return this.contextServiceClient.getListOfNamespaces(this.accountId);
}
/* istanbul ignore next */
async setPropertiesInNamespace(namespace, properties, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.setPropertiesInNamespace(this.accountId, namespace, properties, sessionId);
}
/* istanbul ignore next */
async updatePropertiesInNamespace(namespace, properties, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.updatePropertiesInNamespace(this.accountId, namespace, properties, sessionId);
}
/* istanbul ignore next */
async getAllPropertiesInSession(namespace, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.getAllPropertiesInSession(this.accountId, namespace, sessionId);
}
/* istanbul ignore next */
async getSelectedPropertiesInSession(namespace, propertyNames, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.getSelectedPropertiesInSession(this.accountId, namespace, propertyNames, sessionId);
}
/* istanbul ignore next */
async getPropertyInSession(namespace, propertyName, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.getPropertyInSession(this.accountId, namespace, propertyName, sessionId);
}
/* istanbul ignore next */
async deletePropertyInSession(namespace, propertyName, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.deletePropertyInSession(this.accountId, namespace, propertyName, sessionId);
}
/* istanbul ignore next */
async deleteSession(namespace, sessionId) {
await this.initContextServiceClient();
return this.contextServiceClient.deleteSession(this.accountId, namespace, sessionId);
}
/* istanbul ignore next */
async getListOfSessions(namespace) {
await this.initContextServiceClient();
return this.contextServiceClient.getListOfSessions(this.accountId, namespace);
}
}
exports.FaasContextServiceClient = FaasContextServiceClient;
function getBaseUrl() {
// TODO: Base-Url determination should be handled by the CSDS-Client as soon as the Service has its CSDS-Entry
const vaultServiceEnv = process.env['CONTEXT_SERVICE_ENVIRONMENT'];
switch (vaultServiceEnv) {
case 'qa':
return 'lp-mavencontext-qa.dev.lprnd.net';
case 'z1-a':
return 'va-a.context.liveperson.net';
case 'z1':
return lib_1.DOMAINS.US;
case 'z2':
return lib_1.DOMAINS.EMEA;
case 'z3':
return lib_1.DOMAINS.APAC;
default:
throw new Error('Could not determine ContextService environment. Please make sure to set CONTEXT_SERVICE_ENVIRONMENT (qa, z1-a, z1, z2 or z3) as env variable in your config.json!');
}
}
//# sourceMappingURL=contextServiceClient.js.map