UNPKG

@apify/n8n-nodes-apify

Version:
151 lines 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.overrideActorProperties = overrideActorProperties; exports.listActors = listActors; const genericFunctions_1 = require("./genericFunctions"); const resourceLocatorProperty = { displayName: 'Actor', name: 'actorId', type: 'resourceLocator', default: { mode: 'list', value: '' }, modes: [ { displayName: 'From list', name: 'list', type: 'list', placeholder: 'Choose...', typeOptions: { searchListMethod: 'listActors', searchFilterRequired: false, searchable: true, }, }, { displayName: 'By URL', name: 'url', type: 'string', placeholder: 'https://console.apify.com/actors/AtBpiepuIUNs2k2ku/input', validation: [ { type: 'regex', properties: { regex: 'https://console.apify.com/actors/([a-zA-Z0-9]+).*', errorMessage: 'Not a valid Actor URL', }, }, ], extractValue: { type: 'regex', regex: `https://console.apify.com/actors/([a-zA-Z0-9]+).*`, }, }, { displayName: 'ID', name: 'id', type: 'string', validation: [ { type: 'regex', properties: { regex: '[a-zA-Z0-9]+', errorMessage: 'Not a valid Actor ID', }, }, ], placeholder: 'NVCnbrChXaPbhVs8bISltEhngFg', url: '=http:/console.apify.com/actors/{{ $value }}/input', }, ], }; const actorSourceProperty = { displayName: 'Actor Source', name: 'actorSource', type: 'options', options: [ { name: 'Recently Used Actors', value: 'recentlyUsed', }, { name: 'Apify Store Actors', value: 'store', }, ], default: 'recentlyUsed', description: 'Choose whether to select from your recently used Actors or browse Apify Store', displayOptions: { show: { resource: ['actor'] } }, }; function mapProperty(property) { return { ...property, ...resourceLocatorProperty, }; } function createActorSourceProperty(displayOptions) { return { ...actorSourceProperty, displayOptions, }; } function overrideActorProperties(properties) { const result = []; for (const property of properties) { if (property.name === 'actorId') { result.push(createActorSourceProperty(property.displayOptions)); result.push(mapProperty(property)); } else { result.push(property); } } return result; } async function listActors(searchTerm) { const actorSource = this.getNodeParameter('actorSource', 'recentlyUsed'); const mapToN8nSelectOption = (actor) => { const optionName = actor.title ? `${actor.title} (${actor.username}/${actor.name})` : `${actor.username}/${actor.name}`; return { name: optionName, value: actor.id, url: `https://console.apify.com/actors/${actor.id}/input`, description: actor.description || actor.name, }; }; const { data: { items: recentActors }, } = await genericFunctions_1.apiRequestAllItems.call(this, { method: 'GET', uri: '/v2/acts', qs: { limit: 1000, offset: 0, sortBy: 'stats.lastRunStartedAt', desc: true, }, }); if (actorSource === 'recentlyUsed') { if (searchTerm) { const regex = new RegExp(searchTerm, 'i'); const filteredActors = recentActors.filter((actor) => regex.test(actor.title || '') || regex.test(actor.name || '')); return { results: filteredActors.map(mapToN8nSelectOption), }; } return { results: recentActors.map(mapToN8nSelectOption), }; } const { data: { items: storeActors }, } = await genericFunctions_1.apiRequestAllItems.call(this, { method: 'GET', uri: '/v2/store', qs: { limit: 200, offset: 0, search: searchTerm, }, }); return { results: storeActors.map(mapToN8nSelectOption), }; } //# sourceMappingURL=actorResourceLocator.js.map