@microsoft/omnichannel-chat-sdk
Version:
Microsoft Omnichannel Chat SDK
190 lines • 10.6 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setChatId = exports.setDebugDetailed = exports.setDebug = exports.setRequestId = exports.setRuntimeId = exports.useTelemetry = exports._exceptionDetailPIIKeys = exports._basePIIKeys = void 0;
exports.redactPII = redactPII;
var utilities_1 = require("./utilities");
exports._basePIIKeys = [
"senderDisplayName",
"message",
"content",
"fileName"
]
.map(function (s) { return s.toLowerCase(); });
exports._exceptionDetailPIIKeys = __spreadArray(__spreadArray([], exports._basePIIKeys, true), ["authorization"], false);
var disallowedStrValues = [];
var useTelemetry = function (telemetry, ocSdkLogger, acsClientLogger, acsAdapterLogger, callingSdkLogger, amsClientLogger, ic3ClientLogger) {
if (ic3ClientLogger === void 0) { ic3ClientLogger = null; }
ocSdkLogger.useTelemetry(telemetry);
acsClientLogger.useTelemetry(telemetry);
acsAdapterLogger.useTelemetry(telemetry);
callingSdkLogger.useTelemetry(telemetry);
amsClientLogger.useTelemetry(telemetry);
ic3ClientLogger === null || ic3ClientLogger === void 0 ? void 0 : ic3ClientLogger.useTelemetry(telemetry);
};
exports.useTelemetry = useTelemetry;
var setRuntimeId = function (runtimeId, ocSdkLogger, acsClientLogger, acsAdapterLogger, callingSdkLogger, amsClientLogger, ic3ClientLogger) {
if (ic3ClientLogger === void 0) { ic3ClientLogger = null; }
ocSdkLogger.setRuntimeId(runtimeId);
acsClientLogger.setRuntimeId(runtimeId);
acsAdapterLogger.setRuntimeId(runtimeId);
callingSdkLogger.setRuntimeId(runtimeId);
amsClientLogger.setRuntimeId(runtimeId);
ic3ClientLogger === null || ic3ClientLogger === void 0 ? void 0 : ic3ClientLogger.setRuntimeId(runtimeId);
};
exports.setRuntimeId = setRuntimeId;
var setRequestId = function (requestId, ocSdkLogger, acsClientLogger, acsAdapterLogger, callingSdkLogger, amsClientLogger, ic3ClientLogger) {
if (ic3ClientLogger === void 0) { ic3ClientLogger = null; }
ocSdkLogger === null || ocSdkLogger === void 0 ? void 0 : ocSdkLogger.setRequestId(requestId);
acsClientLogger === null || acsClientLogger === void 0 ? void 0 : acsClientLogger.setRequestId(requestId);
acsAdapterLogger === null || acsAdapterLogger === void 0 ? void 0 : acsAdapterLogger.setRequestId(requestId);
callingSdkLogger === null || callingSdkLogger === void 0 ? void 0 : callingSdkLogger.setRequestId(requestId);
amsClientLogger === null || amsClientLogger === void 0 ? void 0 : amsClientLogger.setRequestId(requestId);
ic3ClientLogger === null || ic3ClientLogger === void 0 ? void 0 : ic3ClientLogger.setRequestId(requestId);
};
exports.setRequestId = setRequestId;
var setDebug = function (flag, ocSdkLogger, acsClientLogger, acsAdapterLogger, callingSdkLogger, amsClientLogger, ic3ClientLogger) {
if (ic3ClientLogger === void 0) { ic3ClientLogger = null; }
ocSdkLogger === null || ocSdkLogger === void 0 ? void 0 : ocSdkLogger.setDebug(flag);
acsClientLogger === null || acsClientLogger === void 0 ? void 0 : acsClientLogger.setDebug(flag);
acsAdapterLogger === null || acsAdapterLogger === void 0 ? void 0 : acsAdapterLogger.setDebug(flag);
callingSdkLogger === null || callingSdkLogger === void 0 ? void 0 : callingSdkLogger.setDebug(flag);
amsClientLogger === null || amsClientLogger === void 0 ? void 0 : amsClientLogger.setDebug(flag);
ic3ClientLogger === null || ic3ClientLogger === void 0 ? void 0 : ic3ClientLogger.setDebug(flag);
};
exports.setDebug = setDebug;
var setDebugDetailed = function (flag, flagAcs, flagAttachment, ocSdkLogger, acsClientLogger, acsAdapterLogger, callingSdkLogger, amsClientLogger) {
ocSdkLogger === null || ocSdkLogger === void 0 ? void 0 : ocSdkLogger.setDebug(flag);
callingSdkLogger === null || callingSdkLogger === void 0 ? void 0 : callingSdkLogger.setDebug(flag);
acsClientLogger === null || acsClientLogger === void 0 ? void 0 : acsClientLogger.setDebug(flagAcs);
acsAdapterLogger === null || acsAdapterLogger === void 0 ? void 0 : acsAdapterLogger.setDebug(flagAcs);
amsClientLogger === null || amsClientLogger === void 0 ? void 0 : amsClientLogger.setDebug(flagAttachment);
};
exports.setDebugDetailed = setDebugDetailed;
var setChatId = function (chatId, ocSdkLogger, acsClientLogger, acsAdapterLogger, callingSdkLogger, amsClientLogger, ic3ClientLogger) {
if (ic3ClientLogger === void 0) { ic3ClientLogger = null; }
ocSdkLogger === null || ocSdkLogger === void 0 ? void 0 : ocSdkLogger.setChatId(chatId);
acsClientLogger === null || acsClientLogger === void 0 ? void 0 : acsClientLogger.setChatId(chatId);
acsAdapterLogger === null || acsAdapterLogger === void 0 ? void 0 : acsAdapterLogger.setChatId(chatId);
callingSdkLogger === null || callingSdkLogger === void 0 ? void 0 : callingSdkLogger.setChatId(chatId);
amsClientLogger === null || amsClientLogger === void 0 ? void 0 : amsClientLogger.setChatId(chatId);
ic3ClientLogger === null || ic3ClientLogger === void 0 ? void 0 : ic3ClientLogger.setChatId(chatId);
};
exports.setChatId = setChatId;
function containsDisallowedValues(targetValue) {
for (var _i = 0, disallowedStrValues_1 = disallowedStrValues; _i < disallowedStrValues_1.length; _i++) {
var disallowedValue = disallowedStrValues_1[_i];
if (targetValue.toLowerCase().includes(disallowedValue.toLowerCase())) {
return disallowedValue;
}
}
return undefined;
}
function redactPII(input, redactAllNested, shouldClone, knownPIIKeys) {
if (redactAllNested === void 0) { redactAllNested = false; }
if (shouldClone === void 0) { shouldClone = true; }
if (knownPIIKeys === void 0) { knownPIIKeys = exports._basePIIKeys; }
if (input === undefined || input === null) {
return input;
}
if (typeof input == "boolean") {
return { result: input };
}
// If stringified JSON, parse it first
if (typeof input == "string") {
if ((0, utilities_1.isJsonObject)(input)) {
input = JSON.parse(input);
}
else {
var disallowedValue = containsDisallowedValues(input);
if (disallowedValue) {
if (input.length > 1) {
input = "".concat(disallowedValue, ":").concat(input.slice(0, 1), "**").concat(input.length - 1, " hidden**");
}
}
}
}
if (input && typeof input == "object") {
try {
// Deep clone the object so we don't modify the original object
// Using JSON.parse(JSON.stringify()) since we know this object will need to be stringified,
// so if clone operation fails, then sending telemetry would fail anyways
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var cloned = void 0;
if (shouldClone) {
cloned = JSON.parse(JSON.stringify(input));
}
else {
cloned = input;
}
for (var _i = 0, _a = Object.entries(cloned); _i < _a.length; _i++) {
var _b = _a[_i], key = _b[0], value = _b[1];
// Convert all keys to lower case to simplify matching
var keyLowerCase = key.toLowerCase();
if (redactAllNested || knownPIIKeys.includes(keyLowerCase)) {
// Found a PII key, redact it. Not currently considering UUID, or number types as PII
// Any key that contains "token" is considered PII
if (typeof value == "string") {
// Even if it is a string, it could be a JSON string, so we need to check that first
if ((0, utilities_1.isJsonObject)(value)) {
cloned[key] = redactPII(JSON.parse(value), true, false, knownPIIKeys);
}
else {
if (value.length > 1) {
cloned[key] = value.slice(0, 1) + "**".concat(value.length - 1, " hidden**");
}
}
}
else if (typeof value == "object") {
// Found a PII key, but it contains an object, redact all nested keys instead
redactPII(value, true, false, knownPIIKeys);
}
}
else if (typeof value == "object") {
redactPII(value, redactAllNested, false, knownPIIKeys);
}
else if (typeof value === "string") {
if ((0, utilities_1.isJsonObject)(value)) {
// Check and redact stringified objects that are not under a known PII key
cloned[key] = redactPII(JSON.parse(value), redactAllNested, false, knownPIIKeys);
}
else {
// if the key or value contains the disallowed values, redact the payload
var disallowedValue = containsDisallowedValues(value);
if (disallowedValue) {
if (value.length > 1) {
cloned[key] = "".concat(key, ":").concat(disallowedValue, ":")
+ value.slice(0, 1) + "**".concat(value.length - 1, " hidden**");
}
}
}
}
}
return cloned;
}
catch (parseError) {
// Can't guarantee that an object which can't be parsed doesn't contain PII, so instead we return the parse error
return { error: parseError, keys: Object.keys(input) };
}
}
// Expect input to be an object, if it's not, return it as-is
return input;
}
exports.default = {
useTelemetry: exports.useTelemetry,
setRuntimeId: exports.setRuntimeId,
setRequestId: exports.setRequestId,
setDebug: exports.setDebug,
setDebugDetailed: exports.setDebugDetailed,
setChatId: exports.setChatId,
redactPII: redactPII
};
//# sourceMappingURL=loggerUtils.js.map