UNPKG

backendless

Version:

Backendless JavaScript SDK for Node.js and the browser

214 lines (213 loc) 8.85 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _utils = _interopRequireDefault(require("../utils")); var Automations = /*#__PURE__*/function () { function Automations(app) { (0, _classCallCheck2["default"])(this, Automations); this.app = app; } (0, _createClass2["default"])(Automations, [{ key: "activateFlow", value: function () { var _activateFlow = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(flowName, initialData) { return _regenerator["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: if (!(!flowName || typeof flowName !== 'string')) { _context.next = 2; break; } throw new Error('The "flowName" argument must be provided and must be a string.'); case 2: if (!(initialData !== undefined && !_utils["default"].isObject(initialData))) { _context.next = 4; break; } throw new Error('The "initialData" argument must be an object.'); case 4: return _context.abrupt("return", this.app.request.post({ url: "".concat(this.app.urls.automationFlow(), "/activate-by-name"), data: { name: flowName, initialData: initialData } })); case 5: case "end": return _context.stop(); } }, _callee, this); })); function activateFlow(_x, _x2) { return _activateFlow.apply(this, arguments); } return activateFlow; }() }, { key: "loadFlowExecutionContext", value: function () { var _loadFlowExecutionContext = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(executionId) { return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: if (!(!executionId || typeof executionId !== 'string')) { _context2.next = 2; break; } throw new Error('The "executionId" argument must be provided and must be a string.'); case 2: return _context2.abrupt("return", this.app.request.get({ url: this.app.urls.automationFlowExecutionContext(executionId) })); case 3: case "end": return _context2.stop(); } }, _callee2, this); })); function loadFlowExecutionContext(_x3) { return _loadFlowExecutionContext.apply(this, arguments); } return loadFlowExecutionContext; }() }, { key: "activateFlowById", value: function () { var _activateFlowById = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(flowId, initialData) { return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: if (!(!flowId || typeof flowId !== 'string')) { _context3.next = 2; break; } throw new Error('The "flowId" argument must be provided and must be a string.'); case 2: if (!(initialData !== undefined && !_utils["default"].isObject(initialData))) { _context3.next = 4; break; } throw new Error('The "initialData" argument must be an object.'); case 4: return _context3.abrupt("return", this.app.request.post({ url: "".concat(this.app.urls.automationFlow(), "/").concat(flowId, "/activate"), data: initialData || {} })); case 5: case "end": return _context3.stop(); } }, _callee3, this); })); function activateFlowById(_x4, _x5) { return _activateFlowById.apply(this, arguments); } return activateFlowById; }() }, { key: "activateFlowTrigger", value: function () { var _activateFlowTrigger = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(flowName, triggerName, data) { return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: if (!(!flowName || typeof flowName !== 'string')) { _context4.next = 2; break; } throw new Error('The "flowName" argument must be provided and must be a string.'); case 2: if (!(!triggerName || typeof triggerName !== 'string')) { _context4.next = 4; break; } throw new Error('The "triggerName" argument must be provided and must be a string.'); case 4: if (!(data !== undefined && !_utils["default"].isObject(data))) { _context4.next = 6; break; } throw new Error('The "data" argument must be an object.'); case 6: return _context4.abrupt("return", this.app.request.post({ url: "".concat(this.app.urls.automationFlowTrigger(), "/activate-by-name"), query: { flowName: flowName, triggerName: triggerName }, data: data || {} })); case 7: case "end": return _context4.stop(); } }, _callee4, this); })); function activateFlowTrigger(_x6, _x7, _x8) { return _activateFlowTrigger.apply(this, arguments); } return activateFlowTrigger; }() }, { key: "activateFlowTriggerById", value: function () { var _activateFlowTriggerById = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(flowId, triggerId, data, execution) { return _regenerator["default"].wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: if (!(!flowId || typeof flowId !== 'string')) { _context5.next = 2; break; } throw new Error('The "flowId" argument must be provided and must be a string.'); case 2: if (!(!triggerId || typeof triggerId !== 'string')) { _context5.next = 4; break; } throw new Error('The "triggerId" argument must be provided and must be a string.'); case 4: if (!(data !== undefined && !_utils["default"].isObject(data))) { _context5.next = 6; break; } throw new Error('The "data" argument must be an object.'); case 6: if (!(execution !== undefined && (typeof execution !== 'string' || !execution))) { _context5.next = 8; break; } throw new Error( // eslint-disable-next-line 'The "execution" argument must be a non-empty string and must be one of this values: "any", "all" or Execution ID.'); case 8: return _context5.abrupt("return", this.app.request.post({ url: "".concat(this.app.urls.automationFlow(), "/").concat(flowId, "/trigger/").concat(triggerId, "/activate"), data: data || {}, query: { execution: execution } })); case 9: case "end": return _context5.stop(); } }, _callee5, this); })); function activateFlowTriggerById(_x9, _x10, _x11, _x12) { return _activateFlowTriggerById.apply(this, arguments); } return activateFlowTriggerById; }() }]); return Automations; }(); exports["default"] = Automations;