UNPKG

@datocms/cma-client

Version:
142 lines 4.02 kB
import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; export default class Workflow extends BaseResource { /** * 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}`, }); } } Workflow.TYPE = 'workflow'; //# sourceMappingURL=Workflow.js.map