UNPKG

@microsoft/omnichannel-chat-sdk

Version:
498 lines 23.7 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createAMSClientLogger = exports.createCallingSDKLogger = exports.createACSAdapterLogger = exports.createACSClientLogger = exports.createOCSDKLogger = exports.createIC3ClientLogger = exports.AMSClientLogger = exports.CallingSDKLogger = exports.ACSAdapterLogger = exports.ACSClientLogger = exports.OCSDKLogger = exports.IC3ClientLogger = void 0; var LogLevel_1 = require("../telemetry/LogLevel"); var ScenarioType_1 = require("../telemetry/ScenarioType"); var ScenarioMarker_1 = require("../telemetry/ScenarioMarker"); var IC3ClientLogger = /** @class */ (function () { function IC3ClientLogger(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.debug = false; this.runtimeId = ''; this.requestId = ''; this.chatId = ''; this.telemetry = null; this.debug = false; } /* istanbul ignore next */ IC3ClientLogger.prototype.setDebug = function (flag) { this.debug = flag; }; IC3ClientLogger.prototype.setRuntimeId = function (runtimeId) { this.runtimeId = runtimeId; }; IC3ClientLogger.prototype.setRequestId = function (requestId) { this.requestId = requestId; }; IC3ClientLogger.prototype.setChatId = function (chatId) { this.chatId = chatId; }; IC3ClientLogger.prototype.useTelemetry = function (telemetry) { /* istanbul ignore next */ this.debug && console.log("[IC3ClientLogger][useTelemetry]"); this.telemetry = telemetry; }; IC3ClientLogger.prototype.logClientSdkTelemetryEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[IC3ClientLogger][logClientSdkTelemetryEvent][" + logLevel + "]"); /* istanbul ignore next */ this.debug && console.log(event); var baseProperties = { ChatSDKRuntimeId: this.runtimeId, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, RequestId: this.requestId, ChatId: this.chatId }; var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: event.ExceptionDetails ? JSON.stringify(event.ExceptionDetails) : '' }); switch (logLevel) { case LogLevel_1.default.DEBUG: (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.debug(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.IC3CLIENT); break; case LogLevel_1.default.WARN: (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.warn(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.IC3CLIENT); break; case LogLevel_1.default.ERROR: (_c = this.telemetry) === null || _c === void 0 ? void 0 : _c.error(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.IC3CLIENT); break; case LogLevel_1.default.INFO: default: (_d = this.telemetry) === null || _d === void 0 ? void 0 : _d.info(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.IC3CLIENT); break; } }; return IC3ClientLogger; }()); exports.IC3ClientLogger = IC3ClientLogger; var OCSDKLogger = /** @class */ (function () { function OCSDKLogger(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.debug = false; this.runtimeId = ''; this.requestId = ''; this.chatId = ''; this.telemetry = null; this.debug = false; } /* istanbul ignore next */ OCSDKLogger.prototype.setDebug = function (flag) { this.debug = flag; }; OCSDKLogger.prototype.setRuntimeId = function (runtimeId) { this.runtimeId = runtimeId; }; OCSDKLogger.prototype.setRequestId = function (requestId) { this.requestId = requestId; }; OCSDKLogger.prototype.setChatId = function (chatId) { this.chatId = chatId; }; OCSDKLogger.prototype.useTelemetry = function (telemetry) { /* istanbul ignore next */ this.debug && console.log("[OCSDKLogger][useTelemetry]"); this.telemetry = telemetry; }; OCSDKLogger.prototype.logClientSdkTelemetryEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[OCSDKLogger][logClientSdkTelemetryEvent][" + logLevel + "]"); /* istanbul ignore next */ this.debug && console.log(event); var baseProperties = { ChatSDKRuntimeId: this.runtimeId, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, RequestId: this.requestId, ChatId: this.chatId }; var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: event.ExceptionDetails ? JSON.stringify(event.ExceptionDetails) : '' }); switch (logLevel) { case LogLevel_1.default.DEBUG: (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.debug(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.OCSDK); break; case LogLevel_1.default.WARN: (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.warn(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.OCSDK); break; case LogLevel_1.default.ERROR: (_c = this.telemetry) === null || _c === void 0 ? void 0 : _c.error(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.OCSDK); break; case LogLevel_1.default.INFO: default: (_d = this.telemetry) === null || _d === void 0 ? void 0 : _d.info(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.OCSDK); break; } }; return OCSDKLogger; }()); exports.OCSDKLogger = OCSDKLogger; var ACSClientLogger = /** @class */ (function () { function ACSClientLogger(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.debug = false; this.runtimeId = ''; this.requestId = ''; this.chatId = ''; this.telemetry = null; this.scenarioMarker = null; this.debug = false; this.scenarioMarker = new ScenarioMarker_1.default(omnichannelConfig); this.scenarioMarker.setScenarioType(ScenarioType_1.default.ACSCLIENT); } /* istanbul ignore next */ ACSClientLogger.prototype.setDebug = function (flag) { var _a; this.debug = flag; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.setDebug(flag); }; ACSClientLogger.prototype.setRuntimeId = function (runtimeId) { var _a; this.runtimeId = runtimeId; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.setRuntimeId(runtimeId); }; ACSClientLogger.prototype.setRequestId = function (requestId) { this.requestId = requestId; }; ACSClientLogger.prototype.setChatId = function (chatId) { this.chatId = chatId; }; ACSClientLogger.prototype.useTelemetry = function (telemetry) { var _a; /* istanbul ignore next */ this.debug && console.log("[ACSClientLogger][useTelemetry]"); this.telemetry = telemetry; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.useTelemetry(this.telemetry); }; ACSClientLogger.prototype.logClientSdkTelemetryEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[ACSClientLogger][logClientSdkTelemetryEvent][" + logLevel + "]"); /* istanbul ignore next */ this.debug && console.log(event); var baseProperties = { ChatSDKRuntimeId: this.runtimeId, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, RequestId: this.requestId, ChatId: this.chatId }; var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: event.ExceptionDetails ? JSON.stringify(event.ExceptionDetails) : '' }); switch (logLevel) { case LogLevel_1.default.DEBUG: (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.debug(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSCLIENT); break; case LogLevel_1.default.WARN: (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.warn(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSCLIENT); break; case LogLevel_1.default.ERROR: (_c = this.telemetry) === null || _c === void 0 ? void 0 : _c.error(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSCLIENT); break; case LogLevel_1.default.INFO: default: (_d = this.telemetry) === null || _d === void 0 ? void 0 : _d.info(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSCLIENT); break; } }; ACSClientLogger.prototype.startScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } var baseProperties = { RequestId: this.requestId, ChatId: this.chatId }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.startScenario(event, __assign(__assign({}, baseProperties), additionalProperties)); }; ACSClientLogger.prototype.failScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } var baseProperties = { RequestId: this.requestId, ChatId: this.chatId }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.failScenario(event, __assign(__assign({}, baseProperties), additionalProperties)); }; ACSClientLogger.prototype.completeScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } var baseProperties = { RequestId: this.requestId, ChatId: this.chatId }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.completeScenario(event, __assign(__assign({}, baseProperties), additionalProperties)); }; return ACSClientLogger; }()); exports.ACSClientLogger = ACSClientLogger; var ACSAdapterLogger = /** @class */ (function () { function ACSAdapterLogger(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.debug = false; this.runtimeId = ''; this.requestId = ''; this.chatId = ''; this.telemetry = null; this.scenarioMarker = null; this.debug = false; this.scenarioMarker = new ScenarioMarker_1.default(omnichannelConfig); this.scenarioMarker.setScenarioType(ScenarioType_1.default.ACSADAPTER); } /* istanbul ignore next */ ACSAdapterLogger.prototype.setDebug = function (flag) { var _a; this.debug = flag; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.setDebug(flag); }; ACSAdapterLogger.prototype.setRuntimeId = function (runtimeId) { var _a; this.runtimeId = runtimeId; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.setRuntimeId(this.runtimeId); }; ACSAdapterLogger.prototype.setRequestId = function (requestId) { this.requestId = requestId; }; ACSAdapterLogger.prototype.setChatId = function (chatId) { this.chatId = chatId; }; ACSAdapterLogger.prototype.useTelemetry = function (telemetry) { var _a; /* istanbul ignore next */ this.debug && console.log("[ACSAdapterLogger][useTelemetry]"); this.telemetry = telemetry; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.useTelemetry(this.telemetry); }; ACSAdapterLogger.prototype.logEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[ACSAdapterLogger][logClientSdkTelemetryEvent][" + logLevel + "]"); /* istanbul ignore next */ this.debug && console.log(event); var baseProperties = { ChatSDKRuntimeId: this.runtimeId, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, RequestId: this.requestId, ChatId: this.chatId }; var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: event.ExceptionDetails ? JSON.stringify(event.ExceptionDetails) : '' }); switch (logLevel) { case LogLevel_1.default.DEBUG: (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.debug(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSADAPTER); break; case LogLevel_1.default.WARN: (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.warn(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSADAPTER); break; case LogLevel_1.default.ERROR: (_c = this.telemetry) === null || _c === void 0 ? void 0 : _c.error(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSADAPTER); break; case LogLevel_1.default.INFO: default: (_d = this.telemetry) === null || _d === void 0 ? void 0 : _d.info(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.ACSADAPTER); break; } }; ACSAdapterLogger.prototype.startScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } var baseProperties = { RequestId: this.requestId, ChatId: this.chatId }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.startScenario(event, __assign(__assign({}, baseProperties), additionalProperties)); }; ACSAdapterLogger.prototype.failScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } var baseProperties = { RequestId: this.requestId, ChatId: this.chatId }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.failScenario(event, __assign(__assign({}, baseProperties), additionalProperties)); }; ACSAdapterLogger.prototype.completeScenario = function (event, additionalProperties) { var _a; if (additionalProperties === void 0) { additionalProperties = {}; } var baseProperties = { RequestId: this.requestId, ChatId: this.chatId }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.completeScenario(event, __assign(__assign({}, baseProperties), additionalProperties)); }; return ACSAdapterLogger; }()); exports.ACSAdapterLogger = ACSAdapterLogger; var CallingSDKLogger = /** @class */ (function () { function CallingSDKLogger(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.debug = false; this.runtimeId = ''; this.requestId = ''; this.chatId = ''; this.telemetry = null; this.debug = false; } /* istanbul ignore next */ CallingSDKLogger.prototype.setDebug = function (flag) { this.debug = flag; }; CallingSDKLogger.prototype.setRuntimeId = function (runtimeId) { this.runtimeId = runtimeId; }; CallingSDKLogger.prototype.setRequestId = function (requestId) { this.requestId = requestId; }; CallingSDKLogger.prototype.setChatId = function (chatId) { this.chatId = chatId; }; CallingSDKLogger.prototype.useTelemetry = function (telemetry) { /* istanbul ignore next */ this.debug && console.log("[CallingSDKLogger][useTelemetry]"); this.telemetry = telemetry; }; CallingSDKLogger.prototype.logCallingSdkTelemetryEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[CallingSDKLogger][logClientSdkTelemetryEvent][" + logLevel + "]"); /* istanbul ignore next */ this.debug && console.log(event); var baseProperties = { ChatSDKRuntimeId: this.runtimeId, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, RequestId: this.requestId, ChatId: this.chatId }; var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: event.ExceptionDetails ? JSON.stringify(event.ExceptionDetails) : '' }); switch (logLevel) { case LogLevel_1.default.DEBUG: (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.debug(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.CALLINGSDK); break; case LogLevel_1.default.WARN: (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.warn(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.CALLINGSDK); break; case LogLevel_1.default.ERROR: (_c = this.telemetry) === null || _c === void 0 ? void 0 : _c.error(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.CALLINGSDK); break; case LogLevel_1.default.INFO: default: (_d = this.telemetry) === null || _d === void 0 ? void 0 : _d.info(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.CALLINGSDK); break; } }; return CallingSDKLogger; }()); exports.CallingSDKLogger = CallingSDKLogger; var AMSClientLogger = /** @class */ (function () { function AMSClientLogger(omnichannelConfig) { this.omnichannelConfig = omnichannelConfig; this.debug = false; this.runtimeId = ''; this.requestId = ''; this.chatId = ''; this.telemetry = null; this.debug = false; } /* istanbul ignore next */ AMSClientLogger.prototype.setDebug = function (flag) { this.debug = flag; }; AMSClientLogger.prototype.setRuntimeId = function (runtimeId) { this.runtimeId = runtimeId; }; AMSClientLogger.prototype.setRequestId = function (requestId) { this.requestId = requestId; }; AMSClientLogger.prototype.setChatId = function (chatId) { this.chatId = chatId; }; AMSClientLogger.prototype.useTelemetry = function (telemetry) { /* istanbul ignore next */ this.debug && console.log("[AMSClientLogger][useTelemetry]"); this.telemetry = telemetry; }; AMSClientLogger.prototype.logClientSdkTelemetryEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[AMSClientLogger][logClientSdkTelemetryEvent][" + logLevel + "]"); /* istanbul ignore next */ this.debug && console.log(event); var baseProperties = { ChatSDKRuntimeId: this.runtimeId, OrgId: this.omnichannelConfig.orgId, OrgUrl: this.omnichannelConfig.orgUrl, WidgetId: this.omnichannelConfig.widgetId, RequestId: this.requestId, ChatId: this.chatId }; var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: event.ExceptionDetails ? JSON.stringify(event.ExceptionDetails) : '' }); switch (logLevel) { case LogLevel_1.default.DEBUG: (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.debug(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.AMSCLIENT); break; case LogLevel_1.default.WARN: (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.warn(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.AMSCLIENT); break; case LogLevel_1.default.ERROR: (_c = this.telemetry) === null || _c === void 0 ? void 0 : _c.error(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.AMSCLIENT); break; case LogLevel_1.default.INFO: default: (_d = this.telemetry) === null || _d === void 0 ? void 0 : _d.info(__assign(__assign({}, baseProperties), additionalProperties), ScenarioType_1.default.AMSCLIENT); break; } }; return AMSClientLogger; }()); exports.AMSClientLogger = AMSClientLogger; exports.createIC3ClientLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new IC3ClientLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createOCSDKLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new OCSDKLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createACSClientLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new ACSClientLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createACSAdapterLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new ACSAdapterLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createCallingSDKLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new CallingSDKLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createAMSClientLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new AMSClientLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; //# sourceMappingURL=loggers.js.map