mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 17:14:05 -08:00
6dcdb30bf4
* ✏️ Alphabetize lint rules * 🔥 Remove duplicates * ⚡ Update `lintfix` script * 👕 Apply `node-param-operation-without-no-data-expression` (#3329) * 👕 Apply `node-param-operation-without-no-data-expression` * 👕 Add exceptions * 👕 Apply `node-param-description-weak` (#3328) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-option-value-duplicate` (#3331) * 👕 Apply `node-param-description-miscased-json` (#3337) * 👕 Apply `node-param-display-name-excess-inner-whitespace` (#3335) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-type-options-missing-from-limit` (#3336) * Rule workig as intended * ✏️ Uncomment rules Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-option-name-duplicate` (#3338) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-description-wrong-for-simplify` (#3334) * ⚡ fix * ⚡ exceptions * ⚡ changed rule ignoring from file to line * 👕 Apply `node-param-resource-without-no-data-expression` (#3339) * 👕 Apply `node-param-display-name-untrimmed` (#3341) * 👕 Apply `node-param-display-name-miscased-id` (#3340) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-resource-with-plural-option` (#3342) * 👕 Apply `node-param-description-wrong-for-upsert` (#3333) * ⚡ fix * ⚡ replaced record with contact in description * ⚡ fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-option-description-identical-to-name` (#3343) * 👕 Apply `node-param-option-name-containing-star` (#3347) * 👕 Apply `node-param-display-name-wrong-for-update-fields` (#3348) * 👕 Apply `node-param-option-name-wrong-for-get-all` (#3345) * ⚡ fix * ⚡ exceptions * 👕 Apply node-param-display-name-wrong-for-simplify (#3344) * Rule working as intended * Uncomented other rules * 👕 Undo and add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * ⚡ Alphabetize lint rules * ⚡ Restore `lintfix` script Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com>
232 lines
5 KiB
TypeScript
232 lines
5 KiB
TypeScript
import {
|
|
ICredentialsDecrypted,
|
|
ICredentialTestFunctions,
|
|
IDataObject,
|
|
INodeCredentialTestResult,
|
|
INodeExecutionData,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
taskFields,
|
|
taskOperations,
|
|
} from './descriptions/TaskDescription';
|
|
|
|
import {
|
|
IExecuteFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
destinationFields,
|
|
destinationOperations,
|
|
} from './descriptions/DestinationDescription';
|
|
|
|
import {
|
|
resourceLoaders,
|
|
} from './GenericFunctions';
|
|
|
|
import {
|
|
recipientFields,
|
|
recipientOperations,
|
|
} from './descriptions/RecipientDescription';
|
|
|
|
import {
|
|
organizationFields,
|
|
organizationOperations,
|
|
} from './descriptions/OrganizationDescription';
|
|
|
|
import {
|
|
adminFields,
|
|
adminOperations,
|
|
} from './descriptions/AdministratorDescription';
|
|
|
|
import {
|
|
hubFields,
|
|
hubOperations,
|
|
} from './descriptions/HubDescription';
|
|
|
|
import {
|
|
workerFields,
|
|
workerOperations,
|
|
} from './descriptions/WorkerDescription';
|
|
|
|
// import {
|
|
// webhookFields,
|
|
// webhookOperations,
|
|
// } from './descriptions/WebhookDescription';
|
|
|
|
import {
|
|
containerFields,
|
|
containerOperations,
|
|
} from './descriptions/ContainerDescription';
|
|
|
|
import {
|
|
teamFields,
|
|
teamOperations,
|
|
} from './descriptions/TeamDescription';
|
|
|
|
import {
|
|
OptionsWithUri,
|
|
} from 'request';
|
|
|
|
import { Onfleet as OnfleetMethods } from './Onfleet';
|
|
export class Onfleet implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Onfleet',
|
|
name: 'onfleet',
|
|
icon: 'file:Onfleet.svg',
|
|
group: ['input'],
|
|
version: 1,
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
description: 'Consume Onfleet API',
|
|
defaults: {
|
|
color: '#AA81F3',
|
|
name: 'Onfleet',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'onfleetApi',
|
|
required: true,
|
|
testedBy: 'onfleetApiTest',
|
|
},
|
|
],
|
|
properties: [
|
|
// List of option resources
|
|
{
|
|
displayName: 'Resource',
|
|
name: 'resource',
|
|
type: 'options',
|
|
noDataExpression: true,
|
|
options: [
|
|
{
|
|
name: 'Admin',
|
|
value: 'admin',
|
|
},
|
|
{
|
|
name: 'Container',
|
|
value: 'container',
|
|
},
|
|
{
|
|
name: 'Destination',
|
|
value: 'destination',
|
|
},
|
|
{
|
|
name: 'Hub',
|
|
value: 'hub',
|
|
},
|
|
{
|
|
name: 'Organization',
|
|
value: 'organization',
|
|
},
|
|
{
|
|
name: 'Recipient',
|
|
value: 'recipient',
|
|
},
|
|
{
|
|
name: 'Task',
|
|
value: 'task',
|
|
},
|
|
{
|
|
name: 'Team',
|
|
value: 'team',
|
|
},
|
|
// {
|
|
// name: 'Webhook',
|
|
// value: 'webhook',
|
|
// },
|
|
{
|
|
name: 'Worker',
|
|
value: 'worker',
|
|
},
|
|
],
|
|
default: 'task',
|
|
description: 'The resource to perform operations on',
|
|
},
|
|
// Operations & fields
|
|
...adminOperations,
|
|
...adminFields,
|
|
...containerOperations,
|
|
...containerFields,
|
|
...destinationOperations,
|
|
...destinationFields,
|
|
...hubOperations,
|
|
...hubFields,
|
|
...organizationOperations,
|
|
...organizationFields,
|
|
...recipientOperations,
|
|
...recipientFields,
|
|
...taskOperations,
|
|
...taskFields,
|
|
...teamOperations,
|
|
...teamFields,
|
|
// ...webhookOperations,
|
|
// ...webhookFields,
|
|
...workerOperations,
|
|
...workerFields,
|
|
],
|
|
};
|
|
|
|
methods = {
|
|
credentialTest: {
|
|
async onfleetApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
|
|
const credentials = credential.data as IDataObject;
|
|
|
|
const options: OptionsWithUri = {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'User-Agent': 'n8n-onfleet',
|
|
},
|
|
auth: {
|
|
user: credentials.apiKey as string,
|
|
pass: '',
|
|
},
|
|
method: 'GET',
|
|
uri: 'https://onfleet.com/api/v2/auth/test',
|
|
json: true,
|
|
};
|
|
|
|
try {
|
|
await this.helpers.request(options);
|
|
return {
|
|
status: 'OK',
|
|
message: 'Authentication successful',
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
status: 'Error',
|
|
message: `Auth settings are not valid: ${error}`,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
loadOptions: resourceLoaders,
|
|
};
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
const items = this.getInputData();
|
|
|
|
const operations: { [key: string]: Function } = {
|
|
task: OnfleetMethods.executeTaskOperations,
|
|
destination: OnfleetMethods.executeDestinationOperations,
|
|
organization: OnfleetMethods.executeOrganizationOperations,
|
|
admin: OnfleetMethods.executeAdministratorOperations,
|
|
recipient: OnfleetMethods.executeRecipientOperations,
|
|
hub: OnfleetMethods.executeHubOperations,
|
|
worker: OnfleetMethods.executeWorkerOperations,
|
|
webhook: OnfleetMethods.executeWebhookOperations,
|
|
container: OnfleetMethods.executeContainerOperations,
|
|
team: OnfleetMethods.executeTeamOperations,
|
|
};
|
|
|
|
const responseData = await operations[resource].call(this, `${resource}s`, operation, items);
|
|
|
|
// Map data to n8n data
|
|
return [this.helpers.returnJsonArray(responseData)];
|
|
}
|
|
}
|