@apify/n8n-nodes-apify
Version:
n8n nodes for Apify
101 lines • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.overrideRunProperties = overrideRunProperties;
exports.listRuns = listRuns;
const genericFunctions_1 = require("./genericFunctions");
const resourceLocatorProperty = {
displayName: 'Run ID',
name: 'runId',
type: 'resourceLocator',
default: { mode: 'list', value: '' },
modes: [
{
displayName: 'From list',
name: 'list',
type: 'list',
placeholder: 'Choose...',
typeOptions: {
searchListMethod: 'listRuns',
searchFilterRequired: false,
searchable: false,
},
},
{
displayName: 'By URL',
name: 'url',
type: 'string',
placeholder: 'https://console.apify.com/actors/runs/RDfcScrqIYHW0jfNF#output',
validation: [
{
type: 'regex',
properties: {
regex: 'https://console.apify.com/actors(/[a-zA-Z0-9]+)?/runs/([a-zA-Z0-9]+).*',
errorMessage: 'Not a valid Apify Actor Run URL',
},
},
],
extractValue: {
type: 'regex',
regex: 'https://console.apify.com/actors(?:/[a-zA-Z0-9]+)?/runs/([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 run ID',
},
},
],
placeholder: 'WAtmhr6rhfBnwqKDY',
url: '=http:/console.apify.com/actors/{{ $value }}/runs/{{ $value }}#log',
},
],
};
function mapProperty(property) {
return {
...property,
...resourceLocatorProperty,
};
}
function overrideRunProperties(properties) {
return properties.map((property) => {
if (property.name === 'runId') {
return mapProperty(property);
}
return property;
});
}
async function listRuns() {
const searchResults = await genericFunctions_1.apiRequestAllItems.call(this, {
method: 'GET',
uri: '/v2/actor-runs',
qs: {
limit: 100,
offset: 0,
desc: 1,
},
});
const { data } = searchResults;
const { items } = data;
return {
results: items.map((b) => {
const url = `https://console.apify.com/runs/${b.id}`;
const readableDateTime = b.finishedAt
? `${new Date(b.finishedAt).toDateString()} ${new Date(b.finishedAt).toLocaleTimeString()}`
: undefined;
return {
name: [readableDateTime, b.status].filter(Boolean).join(' - '),
value: b.id,
url,
description: b.status,
};
}),
};
}
//# sourceMappingURL=runResourceLocator.js.map