Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions api/8s9Auqlc7RHbpxsJ/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Endpoint from '../endpoint';
import triggerEngine from '../../trigger/trigger';


/**
* api invoke_trigger
*/

class _8s9Auqlc7RHbpxsJ extends Endpoint {
constructor() {
super('8s9Auqlc7RHbpxsJ');
}

/**
* invokes a trigger using provided trigger name
* @param app
* @param req (p0: trigger_name<required>)
* @param res
* @returns {*}
*/
handler(app, req, res) {
let triggerName;

if (!req.body.p0) {
return res.status(400).send({
status : 'fail',
message: 'p0<trigger_name> is required'
});
}
else {
triggerName = req.body.p0;

}

try {
console.log(`[api ${this.endpoint}] Received request to invoke trigger ${triggerName}. Checking if the trigger exists`);

if (!(triggerEngine.checkTriggerExists(triggerName))) {
console.log(`[api ${this.endpoint}] Trigger ${triggerName} does not exist`);
return res.send({
status : 'fail',
message: 'trigger does not exist'
});
}

if (triggerEngine.isTriggerDisabled(triggerName)) {
console.log(`[api ${this.endpoint}] Trigger ${triggerName} cannot be invoked as it is disabled`);
return res.send({
status : 'fail',
message: 'trigger is disabled'
});
}

return triggerEngine.invokeTrigger(triggerName)
.then(_ => {
console.log(`[api ${this.endpoint}] Trigger ${triggerName} successfully invoked`);
return res.send({
status: 'success'
});
})
.catch(err => {
console.log(`[api ${this.endpoint}] Failed to invoke trigger ${triggerName}. Error: ${err}`);
return res.send({
status : 'fail',
message: `Failed to invoke trigger: ${err}`
});
});
}
catch (e) {
console.log(`[api ${this.endpoint}] Error while invoking trigger ${triggerName}: ${e}`);
return res.send({
status : 'fail',
message: 'invoke_trigger_error'
});
}
}
}


export default new _8s9Auqlc7RHbpxsJ();
95 changes: 95 additions & 0 deletions api/GxFK1FzbVyWUx8MR/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import Endpoint from '../endpoint';
import triggerEngine from '../../trigger/trigger';
import {validateTriggerAction} from '../../trigger/validation';


/**
* api add_trigger_action
*/

class _GxFK1FzbVyWUx8MR extends Endpoint {
constructor() {
super('GxFK1FzbVyWUx8MR');
}

/**
* Adds a trigger action for an existing trigger
* @param app
* @param req (p0: trigger_name<required>, p1: trigger_action<required>)
* @param res
* @returns {*}
*/
handler(app, req, res) {
let triggerName;
let triggerAction;

if (!req.body.p0 || !req.body.p1) {
return res.status(400).send({
status : 'fail',
message: 'p0<trigger_name> and p1<trigger_action> are required'
});
}
else {
triggerName = req.body.p0;
triggerAction = req.body.p1;
}

try {
console.log(`[api ${this.endpoint}] Received request to add triger action ${triggerAction.name} to trigger ${triggerName}. Validating trigger action`);

try {
validateTriggerAction(triggerAction);
} catch(err) {
console.log(`[api ${this.endpoint}] Trigger action is invalid`);
return res.send({
status : 'fail',
message: 'trigger action is invalid'
});
}

console.log(`[api ${this.endpoint}] Checking if the trigger exists`);

if (!(triggerEngine.checkTriggerExists(triggerName))) {
console.log(`[api ${this.endpoint}] Trigger ${triggerName} does not exist`);
return res.send({
status : 'fail',
message: 'trigger does not exist'
});
}

console.log(`[api ${this.endpoint}] Checking if trigger action ${triggerAction.name} exists`);
if (triggerEngine.checkActionExists(triggerName, triggerAction.name)) {
console.log(`[api ${this.endpoint}] Trigger action ${triggerAction.name} already exists`);
return res.send({
status : 'fail',
message: 'trigger action already exists'
});
}

return triggerEngine.addTriggerAction(triggerName, triggerAction)
.then(_ => {
console.log(`[api ${this.endpoint}] Trigger action ${triggerAction.name} added. Returning success`);
return res.send({
status: 'success'
});
})
.catch(err => {
console.log(`[api ${this.endpoint}] Error while adding trigger action ${triggerAction.name}: ${err}`);
return res.send({
status : 'failure',
message: `Failed to add action: ${err}`
});
});
}
catch (e) {
console.log(`[api ${this.endpoint}] Error while adding trigger action: ${e}`);
return res.send({
status : 'fail',
message: 'add_trigger_action_error'
});
}
}
}


export default new _GxFK1FzbVyWUx8MR();
108 changes: 108 additions & 0 deletions api/Hehn7N0KBVvuFQHf/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import Endpoint from '../endpoint';
import triggerEngine from '../../trigger/trigger';
import {validateTrigger, validateTriggerAction} from '../../trigger/validation';


/**
* api add_trigger
*/

class _Hehn7N0KBVvuFQHf extends Endpoint {
constructor() {
super('Hehn7N0KBVvuFQHf');
}

/**
* accepts a trigger and trigger actions payload to store a trigger and
* corresponding trigger actions to the database
* @param app
* @param req (p0: trigger<required>, p1: trigger_actions<required>)
* @param res
* @returns {*}
*/
handler(app, req, res) {
let trigger;
let triggerActions;


if (!req.body.p0 || !req.body.p1) {
return res.status(400).send({
status : 'fail',
message: 'p0<trigger> and p1<trigger_actions> are required'
});
}
else {
trigger = req.body.p0;
triggerActions = req.body.p1;
}

try {
console.log(`[api ${this.endpoint}] Received request to add new trigger ${trigger.name}. Validating`);

if (trigger.name === undefined) {
console.log(`[api ${this.endpoint} Missing trigger name`);
return res.send({
status: 'failure',
message: 'Missing trigger name',
});
}

if (triggerEngine.checkTriggerExists(trigger.name)) {
console.log(`[api ${this.endpoint}] Trigger ${trigger.name} already exists`);
return res.send({
status: 'failure',
message: 'Trigger already exists'
});
}

try {
validateTrigger(trigger);
} catch(err) {
console.log(`[api ${this.endpoint} Invalid trigger. Error: ${err}`);
return res.send({
status: 'failure',
message: `Invalid trigger: ${err}`,
});
}

for (let triggerAction of triggerActions) {
try {
validateTriggerAction(triggerAction);
} catch(err) {
console.log(`[api ${this.endpoint}] Invalid trigger action ${triggerAction.name}. Error: ${err}`);
return res.send({
status: 'failure',
message: `Invalid trigger action ${triggerAction.name}: ${err}`
});
}
}

console.log(`[api ${this.endpoint}] Validated trigger and trigger actions`);

return triggerEngine.addTrigger(trigger, triggerActions)
.then(_ => {
console.log(`[api ${this.endpoint}] Trigger added. Returning success`);
return res.send({
status: 'success'
});
})
.catch(err => {
console.log(`[api ${this.endpoint}] Error while adding trigger: ${err}`);
return res.send({
status : 'fail',
message: `Failed to add trigger: ${err}`
});
});
}
catch (e) {
console.log(`[api ${this.endpoint}] error: ${e}`);
return res.send({
status : 'fail',
message: 'add_trigger_error'
});
}
}
}


export default new _Hehn7N0KBVvuFQHf();
81 changes: 81 additions & 0 deletions api/RlUQHxrBmf1ryge3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Endpoint from '../endpoint';
import triggerEngine from '../../trigger/trigger';


/**
* api remove_trigger_action
*/

class _RlUQHxrBmf1ryge3 extends Endpoint {
constructor() {
super('RlUQHxrBmf1ryge3');
}

/**
* removes a trigger action using provided trigger name and action
* @param app
* @param req (p0: trigger_name<required>, p1<trigger_action_name>required)
* @param res
* @returns {*}
*/
handler(app, req, res) {
let triggerName;
let actionName;

if (!req.body.p0 || !req.body.p1) {
return res.status(400).send({
status : 'fail',
message: 'p0<trigger_name> and p1<trigger_action_name> are required'
});
}
else {
triggerName = req.body.p0;
actionName = req.body.p1;
}

try {
console.log(`[api ${this.endpoint}] Received request to remove trigger action ${actionName} for trigger ${triggerName}. Checking if trigger exists`);

if (!(triggerEngine.checkTriggerExists(triggerName))) {
console.log(`[api ${this.endpoint}] Trigger ${triggerName} does not exist`);
return res.send({
status : 'fail',
message: 'trigger does not exist'
});
}

if (!(triggerEngine.checkActionExists(triggerName, actionName))) {
console.log(`[api ${this.endpoint}] Trigger action ${actionName} does not exist`);
return res.send({
status : 'fail',
message: 'trigger action does not exist'
});
}

return triggerEngine.removeTriggerAction(triggerName, actionName)
.then(_ => {
console.log(`[api ${this.endpoint}] Trigger action ${actionName} removed for trigger ${triggerName}. Returning success`);
return res.send({
status: 'success'
});
})
.catch(err => {
console.log(`[api ${this.endpoint}] Failed to remove trigger action ${actionName} for trigger ${triggerName}. Error: ${err}`);
return res.send({
status : 'fail',
message: `Failed to remove trigger action: ${err}`
});
});
}
catch (e) {
console.log(`[api ${this.endpoint}] error: ${e}`);
return res.send({
status : 'fail',
message: 'remove_trigger_action_error'
});
}
}
}


export default new _RlUQHxrBmf1ryge3();
Loading