@poli-digital/n8n-nodes-poli
Version:
Nó para interagir com a API da Poli
139 lines • 5.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListApps = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const transport_1 = require("./transport");
class ListApps {
constructor() {
this.description = {
displayName: 'List Apps',
name: 'listApps',
icon: 'file:poli.svg',
group: ['output'],
version: 1,
description: 'List all applications',
defaults: {
name: 'List Apps',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'poliApi',
required: true,
},
],
properties: [
{
displayName: 'Account ID',
name: 'accountId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Search',
name: 'search',
type: 'string',
default: '',
description: 'Search term to filter the results',
},
{
displayName: 'Order',
name: 'order',
type: 'string',
default: '',
description: 'Ordering of the results (e.g. -created_at)',
},
{
displayName: 'Page',
name: 'page',
type: 'number',
default: 1,
description: 'Page number to fetch',
},
{
displayName: 'Per Page',
name: 'perPage',
type: 'number',
default: 50,
description: 'Number of items per page',
},
{
displayName: 'Include',
name: 'include',
type: 'multiOptions',
options: [
{ name: 'Status', value: 'status' },
{ name: 'Visibility', value: 'visibility' },
{ name: 'Attributes', value: 'attributes' },
{ name: 'Roles', value: 'roles' },
{ name: 'Permissions', value: 'permissions' },
{ name: 'Attachments', value: 'attachments' },
{ name: 'Resources', value: 'resources' },
{ name: 'Settings', value: 'settings' },
{ name: 'Accounts', value: 'accounts' },
{ name: 'Metadata', value: 'metadata' },
],
default: [],
description: 'Additional fields to include in the response',
},
{
displayName: 'Query',
name: 'query',
type: 'string',
default: '',
description: 'Raw query string (e.g. id=18&name=gabriel)',
},
],
},
],
};
}
async execute() {
var _a;
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const accountId = this.getNodeParameter('accountId', i);
const options = this.getNodeParameter('options', i, {});
const params = new URLSearchParams();
if (options.search)
params.append('search', options.search);
if (options.order)
params.append('order', options.order);
if (options.page)
params.append('page', String(options.page));
if (options.perPage)
params.append('perPage', String(options.perPage));
if ((_a = options.include) === null || _a === void 0 ? void 0 : _a.length)
params.append('include', options.include.join(','));
if (options.query) {
for (const part of options.query.split('&')) {
const [key, value] = part.split('=');
if (key && value) {
params.append(key.trim(), value.trim());
}
}
}
const endpoint = `/accounts/${accountId}/applications?${params.toString()}`;
const responseData = await transport_1.apiRequest.call(this, 'GET', endpoint);
returnData.push({ json: responseData });
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
return [returnData];
}
}
exports.ListApps = ListApps;
//# sourceMappingURL=ListApps.operation.js.map