UNPKG

@datocms/cma-client

Version:
171 lines 5.33 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Utils = __importStar(require("@datocms/rest-client-utils")); const BaseResource_1 = __importDefault(require("../../BaseResource")); class Workflow extends BaseResource_1.default { /** * Create a new workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/create * * @throws {ApiError} * @throws {TimeoutError} */ create(body) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'workflow', attributes: ['name', 'api_key', 'stages'], relationships: [], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Create a new workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/create * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate(body) { return this.client.request({ method: 'POST', url: '/workflows', body, }); } /** * Update a workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/update * * @throws {ApiError} * @throws {TimeoutError} */ update(workflowId, body) { return this.rawUpdate(Utils.toId(workflowId), Utils.serializeRequestBody(body, { id: Utils.toId(workflowId), type: 'workflow', attributes: ['name', 'api_key', 'stages'], relationships: [], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Update a workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(workflowId, body) { return this.client.request({ method: 'PUT', url: `/workflows/${workflowId}`, body, }); } /** * List all workflows * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/instances * * @throws {ApiError} * @throws {TimeoutError} */ list() { return this.rawList().then((body) => Utils.deserializeResponseBody(body)); } /** * List all workflows * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList() { return this.client.request({ method: 'GET', url: '/workflows', }); } /** * Retrieve a workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/self * * @throws {ApiError} * @throws {TimeoutError} */ find(workflowId) { return this.rawFind(Utils.toId(workflowId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve a workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(workflowId) { return this.client.request({ method: 'GET', url: `/workflows/${workflowId}`, }); } /** * Delete a workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(workflowId) { return this.rawDestroy(Utils.toId(workflowId)); } /** * Delete a workflow * * Read more: https://www.datocms.com/docs/content-management-api/resources/workflow/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(workflowId) { return this.client.request({ method: 'DELETE', url: `/workflows/${workflowId}`, }); } } exports.default = Workflow; Workflow.TYPE = 'workflow'; //# sourceMappingURL=Workflow.js.map