UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

64 lines 2.16 kB
import { __awaiter } from "tslib"; /* Custom modules */ import { createNodeDescriptor } from "../../../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. */ export const TRIGGER_FUNCTION = 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: ({ cognigy, config, childConfigs }) => __awaiter(void 0, void 0, void 0, function* () { const { api } = cognigy; const scheduled = yield 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