UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

86 lines 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.workflowIdLocator = void 0; exports.searchWorkflows = searchWorkflows; const GenericFunctions_1 = require("./GenericFunctions"); /** * A helper to populate workflow lists. It does a pseudo-search by * listing available workflows and matching with the specified query. */ async function searchWorkflows(query) { const searchResults = (await GenericFunctions_1.apiRequestAllItems.call(this, 'GET', 'workflows', {})); // Map the workflows list against a simple name/id filter, and sort // with the latest on top. const workflows = searchResults .map((w) => ({ name: `${w.name} (#${w.id})`, value: w.id, })) .filter((w) => !query || w.name.toLowerCase().includes(query.toLowerCase()) || w.value?.toString() === query) .sort((a, b) => b.value - a.value); return { results: workflows, }; } /** * A resourceLocator to enable looking up workflows by their ID. * This object can be used as a base and then extended as needed. */ exports.workflowIdLocator = { displayName: 'Workflow', name: 'workflowId', type: 'resourceLocator', default: { mode: 'list', value: '' }, description: 'Workflow to filter the executions by', modes: [ { displayName: 'From List', name: 'list', type: 'list', placeholder: 'Select a Workflow...', initType: 'workflow', typeOptions: { searchListMethod: 'searchWorkflows', searchFilterRequired: false, searchable: true, }, }, { displayName: 'By URL', name: 'url', type: 'string', placeholder: 'https://myinstance.app.n8n.cloud/workflow/1', validation: [ { type: 'regex', properties: { regex: '.*/workflow/([0-9a-zA-Z]{1,})', errorMessage: 'Not a valid Workflow URL', }, }, ], extractValue: { type: 'regex', regex: '.*/workflow/([0-9a-zA-Z]{1,})', }, }, { displayName: 'ID', name: 'id', type: 'string', validation: [ { type: 'regex', properties: { regex: '[0-9a-zA-Z]{1,}', errorMessage: 'Not a valid Workflow ID', }, }, ], placeholder: '1', }, ], }; //# sourceMappingURL=WorkflowLocator.js.map