69 lines
3.1 KiB
JavaScript
69 lines
3.1 KiB
JavaScript
exports.__esModule = true;
|
|
exports.IntegrationAPI = void 0;
|
|
var Logger_1 = require("../Logger");
|
|
var ActionAPI_1 = require("./ActionAPI");
|
|
var IntegrationAPI = /** @class */ (function () {
|
|
function IntegrationAPI(settings) {
|
|
this._integrationID = settings.integrationID;
|
|
this._integration = settings.integration;
|
|
this._actions = {};
|
|
this._connectionvalidators = {};
|
|
}
|
|
IntegrationAPI.prototype.registerAction = function (actionID, name, callback) {
|
|
//Backwards compatibility
|
|
if (typeof name == 'function') {
|
|
callback = name;
|
|
name = actionID;
|
|
if (this._integration.integration.actions != undefined)
|
|
for (var i = 0; i < this._integration.integration.actions.length; i++)
|
|
if (this._integration.integration.actions[i].id == actionID) {
|
|
name = this._integration.integration.actions[i].name;
|
|
break;
|
|
}
|
|
}
|
|
if (this._actions[actionID] == undefined) {
|
|
this._actions[actionID] = { api: new ActionAPI_1.ActionAPI({ integrationID: this._integrationID }), name: name };
|
|
callback(this._actions[actionID].api);
|
|
}
|
|
else
|
|
Logger_1.Log('error', "Integration '" + this._integrationID + "' tried to register duplicate action '" + actionID + "'");
|
|
};
|
|
IntegrationAPI.prototype.registerConnectionValidator = function (connectionType, callback) {
|
|
if (this._integration.connectionslist.includes(connectionType)) {
|
|
if (this._connectionvalidators[connectionType] == undefined) {
|
|
this._connectionvalidators[connectionType] = callback;
|
|
}
|
|
else
|
|
Logger_1.Log('error', "Integration '" + this
|
|
._integrationID + "' tried to register duplicate connection validator '" + connectionType + "'");
|
|
}
|
|
else
|
|
Logger_1.Log('error', "Integration '" + this
|
|
._integrationID + "' tried to register non-existing connection validator '" + connectionType + "'");
|
|
};
|
|
IntegrationAPI.prototype.hasAction = function (actionID) {
|
|
return this._actions[actionID] != undefined;
|
|
};
|
|
IntegrationAPI.prototype.getAction = function (actionID) {
|
|
if (this.hasAction(actionID))
|
|
return this._actions[actionID].api;
|
|
return null;
|
|
};
|
|
IntegrationAPI.prototype.getActionList = function () {
|
|
var list = [];
|
|
for (var actionID in this._actions)
|
|
list.push({ id: actionID, name: this._actions[actionID].name });
|
|
return list;
|
|
};
|
|
IntegrationAPI.prototype.hasValidator = function (connectionType) {
|
|
return this._connectionvalidators[connectionType] != undefined;
|
|
};
|
|
IntegrationAPI.prototype.getValidator = function (connectionType) {
|
|
if (this.hasValidator(connectionType))
|
|
return this._connectionvalidators[connectionType];
|
|
return null;
|
|
};
|
|
return IntegrationAPI;
|
|
}());
|
|
exports.IntegrationAPI = IntegrationAPI;
|
|
//# sourceMappingURL=IntegrationApi.js.map
|