UNPKG

n8n

Version:

n8n Workflow Automation Tool

141 lines • 8.01 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImportOrchestrator = void 0; const di_1 = require("@n8n/di"); const node_types_1 = require("../../../node-types"); const import_blocked_error_1 = require("./import-blocked.error"); const credential_importer_1 = require("../entities/credential/credential-importer"); const credential_missing_mode_1 = require("../entities/credential/credential-missing-mode"); const data_table_importer_1 = require("../entities/data-table/data-table-importer"); const folder_importer_1 = require("../entities/folder/folder-importer"); const variable_importer_1 = require("../entities/variable/variable-importer"); const missing_node_type_mode_1 = require("../entities/workflow/missing-node-type-mode"); const workflow_importer_1 = require("../entities/workflow/workflow-importer"); const workflow_publisher_1 = require("../entities/workflow/workflow-publisher"); const n8n_packages_types_1 = require("../n8n-packages.types"); let ImportOrchestrator = class ImportOrchestrator { constructor(credentialImporter, dataTableImporter, variableImporter, folderImporter, workflowImporter, workflowPublisher, nodeTypes) { this.credentialImporter = credentialImporter; this.dataTableImporter = dataTableImporter; this.variableImporter = variableImporter; this.folderImporter = folderImporter; this.workflowImporter = workflowImporter; this.workflowPublisher = workflowPublisher; this.nodeTypes = nodeTypes; } async import(input) { const plan = await this.plan(input); if (plan.blockingIssues.length > 0) { throw (0, import_blocked_error_1.toImportBlockedError)(plan.blockingIssues); } return await this.apply(plan); } async plan(input) { const { context, folders, workflows, credentialRequest, dataTableRequest, variableRequest, options, } = input; await this.workflowPublisher.assertCanPublish(context.user, context.projectId, options.workflowPublishingPolicy, input.projectPendingCreation); const credentialPlan = await this.credentialImporter.plan(context, credentialRequest); const dataTablePlan = await this.dataTableImporter.plan(context, dataTableRequest); const variablePlan = await this.variableImporter.plan(context, variableRequest); const workflowPlan = await this.workflowImporter.plan(context, workflows, options); const folderContext = { ...context, folderConflictPolicy: options.folderConflictPolicy }; const folderPlan = await this.folderImporter.plan(folderContext, folders); const missingNodeTypes = (0, missing_node_type_mode_1.collectMissingNodeTypes)(workflowPlan.items.filter((item) => item.action !== 'skip'), (nodeType) => this.nodeTypes.getSupportedVersions(nodeType)); const blockingIssues = this.collectBlockingIssues({ workflowPlan, credentialPlan, credentialRequest, folderPlan, dataTablePlan, variableRequest, variablePlan, missingNodeTypes, missingNodeTypeMode: options.missingNodeTypeMode, }); return { input, folderContext, credentialPlan, workflowPlan, folderPlan, dataTablePlan, variablePlan, missingNodeTypes, blockingIssues, }; } async apply(plan) { const { input, folderContext, credentialPlan, workflowPlan, folderPlan, dataTablePlan, variablePlan, } = plan; const { context, credentialRequest, options } = input; const folderSummaries = await this.folderImporter.apply(folderContext, folderPlan); const credentialResult = await this.credentialImporter.apply(context, credentialRequest, credentialPlan); await this.dataTableImporter.apply(context, dataTablePlan); const publishBlocked = new Map(); for (const sourceWorkflowId of (0, credential_missing_mode_1.workflowsBlockedFromPublish)(credentialRequest.requirements, new Set(credentialResult.stubbed))) { publishBlocked.set(sourceWorkflowId, 'stub-credential'); } for (const sourceWorkflowId of (0, missing_node_type_mode_1.workflowsWithMissingNodeTypes)(plan.missingNodeTypes)) { publishBlocked.set(sourceWorkflowId, 'missing-node-type'); } const { outcomes, bindings } = await this.workflowImporter.apply({ ...context, publishingPolicy: options.workflowPublishingPolicy, publishBlocked, }, workflowPlan, (0, n8n_packages_types_1.createBindings)({ credentials: credentialResult.bindings })); return { workflowOutcomes: outcomes, folderSummaries, bindings, credentialResult, dataTablePlan, variablePlan, }; } collectBlockingIssues({ workflowPlan, credentialPlan, credentialRequest, folderPlan, dataTablePlan, variableRequest, variablePlan, missingNodeTypes, missingNodeTypeMode, }) { return [ ...workflowPlan.conflicts.map((conflict) => ({ type: 'workflow-conflict', ...conflict })), ...workflowPlan.idConflicts.map((conflict) => ({ type: 'workflow-id-conflict', ...conflict })), ...workflowPlan.folderConflicts.map((conflict) => ({ type: 'workflow-folder-conflict', ...conflict })), ...folderPlan.conflicts.map((conflict) => ({ type: 'folder-conflict', ...conflict })), ...dataTablePlan.failures.map((failure) => ({ type: 'data-table-unresolved', ...failure })), ...this.credentialImporter .blockingFailures(credentialRequest, credentialPlan) .map(toCredentialBlockingIssue), ...this.variableImporter .blockingFailures(variableRequest, variablePlan) .map((failure) => ({ type: 'variable-unresolved', ...failure })), ...(0, missing_node_type_mode_1.missingNodeTypeBlockingFailures)(missingNodeTypeMode, missingNodeTypes).map(({ type, typeVersion, usedByWorkflows }) => ({ type: 'missing-node-type', nodeType: type, typeVersion, usedByWorkflows, })), ]; } }; exports.ImportOrchestrator = ImportOrchestrator; exports.ImportOrchestrator = ImportOrchestrator = __decorate([ (0, di_1.Service)(), __metadata("design:paramtypes", [credential_importer_1.CredentialImporter, data_table_importer_1.DataTableImporter, variable_importer_1.VariableImporter, folder_importer_1.FolderImporter, workflow_importer_1.WorkflowImporter, workflow_publisher_1.WorkflowPublisher, node_types_1.NodeTypes]) ], ImportOrchestrator); function toCredentialBlockingIssue(failure) { const { kind, sourceId, targetId, expectedType, actualType, usedByWorkflows } = failure; return { type: 'credential-unresolved', kind, sourceId, ...(targetId ? { targetId } : {}), ...(expectedType ? { expectedType } : {}), ...(actualType ? { actualType } : {}), usedByWorkflows, }; } //# sourceMappingURL=import-orchestrator.js.map