@cognigy/rest-api-client
Version:
Cognigy REST-Client
66 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TRIGGER_FUNCTION = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
/**
* Node name: 'triggerFunction'
*
* Purpose:
* Starts a new instance of a function. Will use the function-scheduler
* in order to ensure that an instance can actually be started - e.g. there are
* limits on how many function instances can be there at a given moment
* per organization.
*
* If a new instance could be scheduled, the "onScheduled" child will be executed -
* otherwise the "onSchedulingError" child will be executed.
*/
exports.TRIGGER_FUNCTION = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "triggerFunction",
defaultLabel: "Trigger Function",
summary: "UI__NODE_EDITOR__SERVICE__TRIGGER_FUNCTION__SUMMARY",
appearance: {
color: '#4caf50',
showIcon: false
},
dependencies: {
children: ["onScheduled", "onSchedulingError"]
},
constraints: {
collapsable: true,
placement: {
children: {
whitelist: ["onScheduled", "onSchedulingError"]
}
}
},
fields: [
{
key: "functionReferenceId",
type: "function",
label: "UI__NODE_EDITOR__SERVICE__TRIGGER_FUNCTION__FIELDS__FUNCTION_REFERENCE_ID__LABEL",
params: {
required: true
}
},
{
key: "parameters",
type: "json",
label: "UI__NODE_EDITOR__SERVICE__TRIGGER_FUNCTION__FIELDS__PARAMETERS__LABEL",
params: {
required: true
}
}
],
tags: ["service"],
function: async ({ cognigy, config, childConfigs }) => {
const { api } = cognigy;
const scheduled = await api.triggerFunction(config);
const child = childConfigs.find(child => scheduled ? child.type === "onScheduled" : child.type === "onSchedulingError");
if (!child) {
throw new Error("Unable to find child to execute");
}
api.setNextNode(child.id);
}
});
//# sourceMappingURL=triggerFunction.js.map