zipari-cx
Version:
Zipari CX library
76 lines • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = require("axios");
var cx_constants_1 = require("./cx_constants");
exports.CxCallbacks = cx_constants_1.CxCallbacks;
exports.CxCallBody = cx_constants_1.CxCallBody;
exports.CxCallerConfig = cx_constants_1.CxCallerConfig;
exports.CxCallerInitData = cx_constants_1.CxCallerInitData;
exports.CxContext = cx_constants_1.CxContext;
var CXCaller = (function () {
function CXCaller(config, initData) {
if (initData === void 0) { initData = null; }
this._internalData = {};
this.config = config;
if (initData) {
this.internalData = initData;
}
}
Object.defineProperty(CXCaller.prototype, "internalData", {
get: function () {
return this._internalData;
},
set: function (initData) {
this._internalData = new cx_constants_1.CxCallerInitData(this.config, initData);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CXCaller.prototype, "config", {
get: function () {
return this._config;
},
set: function (config) {
this._config = new cx_constants_1.CxCallerConfig(config);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CXCaller.prototype, "context", {
get: function () {
return this._internalData.context;
},
set: function (context) {
this._internalData.context = context;
},
enumerable: true,
configurable: true
});
CXCaller.prototype.dispatchCXEvent = function (event, body, callbacks) {
var _this = this;
if (callbacks === void 0) { callbacks = {}; }
var validBody = new cx_constants_1.CxCallBody(this.config, body, this.internalData);
if (validBody.context) {
validBody.context = Object.assign({}, this.context, new cx_constants_1.CxContext(this.config, validBody.context));
}
else {
validBody.context = this.context;
}
var validCallbacks = new cx_constants_1.CxCallbacks(callbacks);
axios_1.default.post(this.config.endpoint, validBody)
.then(function (response) {
_this.runCallbackIfExists(validCallbacks.success, response);
})
.catch(function (error) {
_this.runCallbackIfExists(validCallbacks.failure, error);
});
};
CXCaller.prototype.runCallbackIfExists = function (func, body) {
if (func) {
func(body);
}
};
return CXCaller;
}());
exports.CXCaller = CXCaller;
//# sourceMappingURL=index.js.map