@apify/n8n-nodes-apify
Version:
n8n nodes for Apify
98 lines • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.overrideActorTaskProperties = overrideActorTaskProperties;
exports.listActorTasks = listActorTasks;
const genericFunctions_1 = require("./genericFunctions");
const resourceLocatorProperty = {
displayName: 'Actor Task',
name: 'actorTaskId',
type: 'resourceLocator',
default: { mode: 'list', value: '' },
modes: [
{
displayName: 'From list',
name: 'list',
type: 'list',
placeholder: 'Choose...',
typeOptions: {
searchListMethod: 'listActorTasks',
searchFilterRequired: false,
searchable: true,
},
},
{
displayName: 'By URL',
name: 'url',
type: 'string',
placeholder: 'https://console.apify.com/actors/tasks/WAtmhr6rhfBnwqKDY/input',
validation: [
{
type: 'regex',
properties: {
regex: 'https://console.apify.com/actors/tasks/([a-zA-Z0-9]+).*',
errorMessage: 'Not a valid Apify Actor Task URL',
},
},
],
extractValue: {
type: 'regex',
regex: 'https://console.apify.com/actors/tasks/([a-zA-Z0-9]+).*',
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
validation: [
{
type: 'regex',
properties: {
regex: '[a-zA-Z0-9]+',
errorMessage: 'Not a valid Apify Actor Task ID',
},
},
],
placeholder: 'WAtmhr6rhfBnwqKDY',
url: '=http:/console.apify.com/actors/tasks/{{ $value }}/input',
},
],
};
function mapProperty(property) {
return {
...property,
...resourceLocatorProperty,
};
}
function overrideActorTaskProperties(properties) {
return properties.map((property) => {
if (property.name === 'actorTaskId') {
return mapProperty(property);
}
return property;
});
}
async function listActorTasks(searchTerm) {
const searchResults = await genericFunctions_1.apiRequestAllItems.call(this, {
method: 'GET',
uri: '/v2/actor-tasks',
qs: {
limit: 100,
offset: 0,
},
});
const { data: { items }, } = searchResults;
let filteredItems = [...items];
if (searchTerm) {
const regex = new RegExp(searchTerm, 'i');
filteredItems = items.filter((b) => regex.test(b.title || '') || regex.test(b.name || ''));
}
return {
results: filteredItems.map((b) => ({
name: b.title || b.name,
value: b.id,
url: `https://console.apify.com/actors/tasks/${b.id}/input`,
description: b.name,
})),
};
}
//# sourceMappingURL=actorTaskResourceLocator.js.map