@microsoft/omnichannel-chat-sdk
Version:
Microsoft Omnichannel Chat SDK
29 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var requiredOmnichannelConfigParams = ["orgUrl", "orgId", "widgetId"];
var validateOmnichannelConfig = function (omnichannelConfig) {
if (!omnichannelConfig) {
throw new Error("OmnichannelConfiguration not found");
}
for (var _i = 0, requiredOmnichannelConfigParams_1 = requiredOmnichannelConfigParams; _i < requiredOmnichannelConfigParams_1.length; _i++) {
var key = requiredOmnichannelConfigParams_1[_i];
//check for they key present in the map, if not present or value is undefined then throw error
var isPresent = Reflect.has(omnichannelConfig, key);
if (!isPresent) {
throw new Error("Missing '".concat(key, "' in OmnichannelConfiguration"));
}
/**
* Since we know the keys that are required and we know those values are string,
* there is no point in make a generic function to validate the object and different
* types of values based on its type. We can just check for the keys and check if the value is empty or not.
*/
var propertyValue = Reflect.get(omnichannelConfig, key);
if (!propertyValue ||
(typeof propertyValue === "string" && propertyValue.trim().length === 0) ||
propertyValue.length === 0) {
throw new Error("Empty '".concat(key, "' in OmnichannelConfiguration"));
}
}
};
exports.default = validateOmnichannelConfig;
//# sourceMappingURL=OmnichannelConfigValidator.js.map