zipari-cx
Version:
Zipari CX library
219 lines • 8.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function sendWarning(msg) {
if (msg) {
console.warn(msg + ".. Please consult https://cx-engine.readme.io/reference for more information");
}
}
var CxCallerInitData = (function () {
function CxCallerInitData(config, options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxCallerInitData;
}());
exports.CxCallerInitData = CxCallerInitData;
var CxCallerConfig = (function () {
function CxCallerConfig(options) {
if (options === void 0) { options = {}; }
this.endpoint = null;
var configErr = false;
if (!options.hasOwnProperty('messages')) {
options.messages = new CxCallerMessages({});
}
else if (typeof options.messages === 'string') {
var messages_1 = new CxCallerMessages({});
var keys = Object.keys(messages_1);
keys.forEach(function (key) {
messages_1[key] = options.messages;
});
options.messages = messages_1;
}
else {
options.messages = new CxCallerMessages(options.messages);
}
if (!options.endpoint) {
sendWarning(options.messages.no_endpoint);
configErr = true;
}
if (!configErr) {
Object.assign(this, options);
console.log(options.messages.successful_setup);
}
else {
sendWarning(options.messages.unsuccessful_setup);
}
}
return CxCallerConfig;
}());
exports.CxCallerConfig = CxCallerConfig;
var CxContextPage = (function () {
function CxContextPage(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextPage;
}());
exports.CxContextPage = CxContextPage;
var CxContextDevice = (function () {
function CxContextDevice(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextDevice;
}());
exports.CxContextDevice = CxContextDevice;
var CxContextApp = (function () {
function CxContextApp(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextApp;
}());
exports.CxContextApp = CxContextApp;
var CxContextLocation = (function () {
function CxContextLocation(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextLocation;
}());
exports.CxContextLocation = CxContextLocation;
var CxContextNetwork = (function () {
function CxContextNetwork(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextNetwork;
}());
exports.CxContextNetwork = CxContextNetwork;
var CxContextOS = (function () {
function CxContextOS(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextOS;
}());
exports.CxContextOS = CxContextOS;
var CxContextReferrer = (function () {
function CxContextReferrer(options) {
if (options === void 0) { options = {}; }
Object.assign(this, options);
}
return CxContextReferrer;
}());
exports.CxContextReferrer = CxContextReferrer;
var CxContext = (function () {
function CxContext(config, options) {
if (options.timestamp && (typeof options.timestamp === 'string' || typeof options.timestamp === 'number')) {
options.timestamp = new Date();
}
if (options.page) {
options.page = new CxContextPage(options.page);
}
if (options.device) {
options.device = new CxContextDevice(options.device);
}
if (options.app) {
options.app = new CxContextApp(options.app);
}
if (options.location) {
options.location = new CxContextLocation(options.location);
}
if (options.network) {
options.network = new CxContextNetwork(options.network);
}
if (options.os) {
options.os = new CxContextOS(options.os);
}
if (options.referrer) {
options.referrer = new CxContextReferrer(options.referrer);
}
Object.assign(this, options);
}
return CxContext;
}());
exports.CxContext = CxContext;
var CxCallBody = (function () {
function CxCallBody(config, options, previous_data) {
if (previous_data === void 0) { previous_data = {}; }
this.source_system_name = null;
this.authentication_flag = null;
this.name = null;
this.dictionary_attributes = {};
if (options) {
var configErr = false;
if (!options.hasOwnProperty('source_system_name') && !previous_data.hasOwnProperty('source_system_name')) {
sendWarning(config.messages.system_name_not_provided);
configErr = true;
}
else {
options.source_system_name = options.source_system_name || previous_data.source_system_name;
}
if (!options.hasOwnProperty('name') && !previous_data.hasOwnProperty('name')) {
sendWarning(config.messages.name_not_provided);
configErr = true;
}
else {
options.name = options.name || previous_data.name;
}
if (!options.hasOwnProperty('authentication_flag') && !previous_data.hasOwnProperty('authentication_flag')) {
sendWarning(config.messages.authentication_flag_not_provided);
configErr = true;
}
else {
options.authentication_flag = options.hasOwnProperty('authentication_flag') ? options.authentication_flag : options.hasOwnProperty('authentication_flag') ? previous_data.authentication_flag : previous_data.authentication_flag;
}
if (options.context) {
options.context = new CxContext(config, options.context);
}
if (options.consumer_id && typeof options.consumer_id === 'number') {
options.consumer_id = options.consumer_id.toString();
}
if (options.session_id && typeof options.session_id === 'number') {
options.session_id = options.session_id.toString();
}
if (options.consumer_recommendation_id && typeof options.consumer_recommendation_id === 'number') {
options.consumer_recommendation_id = options.consumer_recommendation_id.toString();
}
if (options.transaction_id && typeof options.transaction_id === 'number') {
options.transaction_id = options.transaction_id.toString();
}
if (!configErr) {
Object.assign(this, options);
}
}
else {
sendWarning(config.messages.no_body_provided);
}
}
return CxCallBody;
}());
exports.CxCallBody = CxCallBody;
var CxCallbacks = (function () {
function CxCallbacks(options) {
this.success = function () {
};
this.failure = function () {
};
Object.assign(this, options || {});
}
return CxCallbacks;
}());
exports.CxCallbacks = CxCallbacks;
var CxCallerMessages = (function () {
function CxCallerMessages(options) {
if (options === void 0) { options = null; }
this.no_body_provided = 'Body of CX call not provided';
this.system_name_not_provided = 'System name not provided';
this.name_not_provided = 'Name not provided';
this.authentication_flag_not_provided = 'Authentication flag not provided';
this.unsuccessful_setup = 'Configuration for CX failed';
this.successful_setup = 'Configuration for CX succeeded';
this.no_endpoint = 'Configuration for CX failed because an endpoint was not provided';
Object.assign(this, options || {});
}
return CxCallerMessages;
}());
exports.CxCallerMessages = CxCallerMessages;
//# sourceMappingURL=cx_constants.js.map