UNPKG

@microsoft/omnichannel-chat-sdk

Version:
542 lines 26.3 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 loggerUtils_1 = require("./loggerUtils"); var LogLevel_1 = require("../telemetry/LogLevel"); var ScenarioMarker_1 = require("../telemetry/ScenarioMarker"); var ScenarioType_1 = require("../telemetry/ScenarioType"); 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][".concat(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][".concat(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), { RequestHeaders: event.RequestHeaders ? JSON.stringify(event.RequestHeaders) : '', RequestPayload: event.RequestPayload ? JSON.stringify(event.RequestPayload) : '', 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][".concat(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)); }; ACSClientLogger.prototype.recordIndividualEvent = function (event, source, additionalProperties) { var _a; var baseProperties = { RequestId: this.requestId, ChatId: this.chatId, CustomProperties: JSON.stringify(additionalProperties), Source: source }; (_a = this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.singleRecord(event, __assign({}, baseProperties)); }; 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][".concat(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 }; if (event.CustomProperties) { event.CustomProperties = JSON.stringify((0, loggerUtils_1.redactPII)(event.CustomProperties, false)); } if (event.ExceptionDetails) { event.ExceptionDetails = JSON.stringify((0, loggerUtils_1.redactPII)(event.ExceptionDetails, false, true, loggerUtils_1._exceptionDetailPIIKeys)); } if (event.Description) { event.Description = JSON.stringify((0, loggerUtils_1.redactPII)(event.Description, false, true)); } var additionalProperties = __assign(__assign({}, event), { ExceptionDetails: 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 }; if (additionalProperties.CustomProperties) { additionalProperties.CustomProperties = JSON.stringify((0, loggerUtils_1.redactPII)(additionalProperties.CustomProperties, false)); } if (additionalProperties.ExceptionDetails) { // Handle Error objects properly by converting to serializable format var exceptionDetails = additionalProperties.ExceptionDetails; if (exceptionDetails instanceof Error) { exceptionDetails = __assign(__assign({}, exceptionDetails), { name: exceptionDetails.name, message: exceptionDetails.message }); } additionalProperties.ExceptionDetails = JSON.stringify((0, loggerUtils_1.redactPII)(exceptionDetails, false, true, loggerUtils_1._exceptionDetailPIIKeys)); } if (additionalProperties.Description) { additionalProperties.Description = JSON.stringify((0, loggerUtils_1.redactPII)(additionalProperties.Description, false, true)); } (_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.logScenarioOperation = function (operationName, startTime, endTime, isSuccess, retryCount, data) { // empty on purpose. return; }; CallingSDKLogger.prototype.logCallingSdkTelemetryEvent = function (logLevel, event) { var _a, _b, _c, _d; /* istanbul ignore next */ this.debug && console.log("[CallingSDKLogger][logClientSdkTelemetryEvent][".concat(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][".concat(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; var createIC3ClientLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new IC3ClientLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createIC3ClientLogger = createIC3ClientLogger; var createOCSDKLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new OCSDKLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createOCSDKLogger = createOCSDKLogger; var createACSClientLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new ACSClientLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createACSClientLogger = createACSClientLogger; var createACSAdapterLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new ACSAdapterLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createACSAdapterLogger = createACSAdapterLogger; var createCallingSDKLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new CallingSDKLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createCallingSDKLogger = createCallingSDKLogger; var createAMSClientLogger = function (omnichannelConfig, debug) { if (debug === void 0) { debug = false; } var logger = new AMSClientLogger(omnichannelConfig); logger.setDebug(debug); return logger; }; exports.createAMSClientLogger = createAMSClientLogger; //# sourceMappingURL=loggers.js.map