UNPKG

n8n

Version:

n8n Workflow Automation Tool

81 lines 4.32 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WorkflowsPublicController = void 0; const api_types_1 = require("@n8n/api-types"); const decorators_1 = require("@n8n/decorators"); const bad_request_error_1 = require("../../../errors/response-errors/bad-request.error"); const not_found_error_1 = require("../../../errors/response-errors/not-found.error"); const shared_workflow_not_found_error_1 = require("../../../errors/shared-workflow-not-found.error"); const pagination_service_1 = require("../../../public-api/v1/shared/services/pagination.service"); const workflow_history_service_1 = require("../../../workflows/workflow-history/workflow-history.service"); let WorkflowsPublicController = class WorkflowsPublicController { constructor(workflowHistoryService) { this.workflowHistoryService = workflowHistoryService; } async getWorkflowHistory(req, _res, workflowId, query) { let { limit, offset } = query; if (query.cursor) { try { const decoded = (0, pagination_service_1.decodeCursor)(query.cursor); if (!('offset' in decoded)) { throw new bad_request_error_1.BadRequestError('An invalid cursor was provided'); } offset = decoded.offset; limit = decoded.limit; } catch (error) { if (error instanceof bad_request_error_1.BadRequestError) throw error; throw new bad_request_error_1.BadRequestError('An invalid cursor was provided'); } } try { const versions = await this.workflowHistoryService.getList(req.user, workflowId, limit + 1, offset); const hasMore = versions.length > limit; const data = hasMore ? versions.slice(0, limit) : versions; return { data, nextCursor: (0, pagination_service_1.encodeNextCursor)({ offset, limit, numberOfTotalRecords: hasMore ? offset + limit + 1 : offset + data.length, }), }; } catch (error) { if (error instanceof shared_workflow_not_found_error_1.SharedWorkflowNotFoundError) { throw new not_found_error_1.NotFoundError('Not Found'); } throw error; } } }; exports.WorkflowsPublicController = WorkflowsPublicController; __decorate([ (0, decorators_1.Get)('/:workflowId/history'), (0, decorators_1.ApiKeyScope)('workflow:read'), (0, decorators_1.ProjectScope)('workflow:read'), (0, decorators_1.ApiResponse)(api_types_1.WorkflowVersionHistoryListPublicDto), __param(2, (0, decorators_1.Param)('workflowId')), __param(3, decorators_1.Query), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.ListWorkflowHistoryQueryDto]), __metadata("design:returntype", Promise) ], WorkflowsPublicController.prototype, "getWorkflowHistory", null); exports.WorkflowsPublicController = WorkflowsPublicController = __decorate([ (0, decorators_1.PublicApiController)('/workflows'), __metadata("design:paramtypes", [workflow_history_service_1.WorkflowHistoryService]) ], WorkflowsPublicController); //# sourceMappingURL=workflows.public.controller.js.map