pull:初次提交
This commit is contained in:
18
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/Cockpit.node.json
Executable file
18
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/Cockpit.node.json
Executable file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.cockpit",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Marketing", "Development"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/cockpit/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.cockpit/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
168
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/Cockpit.node.ts
Executable file
168
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/Cockpit.node.ts
Executable file
@@ -0,0 +1,168 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { collectionFields, collectionOperations } from './CollectionDescription';
|
||||
import {
|
||||
createCollectionEntry,
|
||||
getAllCollectionEntries,
|
||||
getAllCollectionNames,
|
||||
} from './CollectionFunctions';
|
||||
import { formFields, formOperations } from './FormDescription';
|
||||
import { submitForm } from './FormFunctions';
|
||||
import { createDataFromParameters } from './GenericFunctions';
|
||||
import { singletonFields, singletonOperations } from './SingletonDescription';
|
||||
import { getAllSingletonNames, getSingleton } from './SingletonFunctions';
|
||||
|
||||
export class Cockpit implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Cockpit',
|
||||
name: 'cockpit',
|
||||
icon: { light: 'file:cockpit.svg', dark: 'file:cockpit.dark.svg' },
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}',
|
||||
description: 'Consume Cockpit API',
|
||||
defaults: {
|
||||
name: 'Cockpit',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'cockpitApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'collection',
|
||||
options: [
|
||||
{
|
||||
name: 'Collection',
|
||||
value: 'collection',
|
||||
},
|
||||
{
|
||||
name: 'Form',
|
||||
value: 'form',
|
||||
},
|
||||
{
|
||||
name: 'Singleton',
|
||||
value: 'singleton',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
...collectionOperations,
|
||||
...collectionFields,
|
||||
...formOperations,
|
||||
...formFields,
|
||||
...singletonOperations,
|
||||
...singletonFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getCollections(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const collections = await getAllCollectionNames.call(this);
|
||||
|
||||
return collections.map((itemName) => {
|
||||
return {
|
||||
name: itemName,
|
||||
value: itemName,
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
async getSingletons(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const singletons = await getAllSingletonNames.call(this);
|
||||
|
||||
return singletons.map((itemName) => {
|
||||
return {
|
||||
name: itemName,
|
||||
value: itemName,
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length;
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
let responseData;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'collection') {
|
||||
const collectionName = this.getNodeParameter('collection', i) as string;
|
||||
|
||||
if (operation === 'create') {
|
||||
const data = createDataFromParameters.call(this, i);
|
||||
|
||||
responseData = await createCollectionEntry.call(this, collectionName, data);
|
||||
} else if (operation === 'getAll') {
|
||||
const options = this.getNodeParameter('options', i);
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (!returnAll) {
|
||||
options.limit = this.getNodeParameter('limit', i);
|
||||
}
|
||||
|
||||
responseData = await getAllCollectionEntries.call(this, collectionName, options);
|
||||
} else if (operation === 'update') {
|
||||
const id = this.getNodeParameter('id', i) as string;
|
||||
const data = createDataFromParameters.call(this, i);
|
||||
|
||||
responseData = await createCollectionEntry.call(this, collectionName, data, id);
|
||||
}
|
||||
} else if (resource === 'form') {
|
||||
const formName = this.getNodeParameter('form', i) as string;
|
||||
|
||||
if (operation === 'submit') {
|
||||
const form = createDataFromParameters.call(this, i);
|
||||
|
||||
responseData = await submitForm.call(this, formName, form);
|
||||
}
|
||||
} else if (resource === 'singleton') {
|
||||
const singletonName = this.getNodeParameter('singleton', i) as string;
|
||||
|
||||
if (operation === 'get') {
|
||||
responseData = await getSingleton.call(this, singletonName);
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
249
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts
Executable file
249
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/CollectionDescription.ts
Executable file
@@ -0,0 +1,249 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const collectionOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create an Entry',
|
||||
value: 'create',
|
||||
description: 'Create a collection entry',
|
||||
action: 'Create a collection entry',
|
||||
},
|
||||
{
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-option-name-wrong-for-get-many
|
||||
name: 'Get Many Entries',
|
||||
value: 'getAll',
|
||||
description: 'Get many collection entries',
|
||||
action: 'Get many collection entries',
|
||||
},
|
||||
{
|
||||
name: 'Update an Entry',
|
||||
value: 'update',
|
||||
description: 'Update a collection entry',
|
||||
action: 'Update a collection entry',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
];
|
||||
|
||||
export const collectionFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collection',
|
||||
type: 'options',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description:
|
||||
'Name of the collection to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
|
||||
// Collection:entry:getAll
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['collection'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fields',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '_id,name',
|
||||
description: 'Comma-separated list of fields to get',
|
||||
},
|
||||
{
|
||||
displayName: 'Filter Query',
|
||||
name: 'filter',
|
||||
type: 'json',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
placeholder: '{"name": "Jim"}',
|
||||
description:
|
||||
'Filter query in <a href="https://jeroen.github.io/mongolite/query-data.html">Mongolite format</a>',
|
||||
},
|
||||
{
|
||||
displayName: 'Language',
|
||||
name: 'language',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Return normalized language fields',
|
||||
},
|
||||
{
|
||||
displayName: 'Populate',
|
||||
name: 'populate',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether to resolve linked collection items',
|
||||
},
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
name: 'rawData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return the data exactly in the way it got received from the API',
|
||||
},
|
||||
{
|
||||
displayName: 'Skip',
|
||||
name: 'skip',
|
||||
type: 'number',
|
||||
default: '',
|
||||
description: 'Skip number of entries',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Query',
|
||||
name: 'sort',
|
||||
type: 'json',
|
||||
default: '',
|
||||
placeholder: '{"price": -1}',
|
||||
description:
|
||||
'Sort query in <a href="https://jeroen.github.io/mongolite/query-data.html">Mongolite format</a>',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// Collection:entry:update
|
||||
{
|
||||
displayName: 'Entry ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Collection:entry:create
|
||||
// Collection:entry:update
|
||||
{
|
||||
displayName: 'JSON Data Fields',
|
||||
name: 'jsonDataFields',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['collection'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
description: 'Whether new entry fields should be set via the value-key pair UI or JSON',
|
||||
},
|
||||
{
|
||||
displayName: 'Entry Data',
|
||||
name: 'dataFieldsJson',
|
||||
type: 'json',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [true],
|
||||
resource: ['collection'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
description: 'Entry data to send as JSON',
|
||||
},
|
||||
{
|
||||
displayName: 'Entry Data',
|
||||
name: 'dataFieldsUi',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [false],
|
||||
resource: ['collection'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'field',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the field',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the field',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
description: 'Entry data to send',
|
||||
},
|
||||
];
|
||||
87
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts
Executable file
87
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/CollectionFunctions.ts
Executable file
@@ -0,0 +1,87 @@
|
||||
import type { IExecuteFunctions, ILoadOptionsFunctions, IDataObject } from 'n8n-workflow';
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
|
||||
import type { ICollection } from './CollectionInterface';
|
||||
import { cockpitApiRequest } from './GenericFunctions';
|
||||
|
||||
export async function createCollectionEntry(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
data: IDataObject,
|
||||
id?: string,
|
||||
): Promise<any> {
|
||||
const body: ICollection = {
|
||||
data,
|
||||
};
|
||||
|
||||
if (id) {
|
||||
body.data = {
|
||||
_id: id,
|
||||
...body.data,
|
||||
};
|
||||
}
|
||||
|
||||
return await cockpitApiRequest.call(this, 'POST', `/collections/save/${resourceName}`, body);
|
||||
}
|
||||
|
||||
export async function getAllCollectionEntries(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
options: IDataObject,
|
||||
): Promise<any> {
|
||||
const body: ICollection = {};
|
||||
|
||||
if (options.fields) {
|
||||
const fields = (options.fields as string).split(',').map((field) => field.trim());
|
||||
|
||||
const bodyFields = {
|
||||
_id: false,
|
||||
} as IDataObject;
|
||||
for (const field of fields) {
|
||||
bodyFields[field] = true;
|
||||
}
|
||||
|
||||
body.fields = bodyFields;
|
||||
}
|
||||
|
||||
if (options.filter) {
|
||||
body.filter = jsonParse(options.filter.toString(), {
|
||||
errorMessage: "'Filter' option is not valid JSON",
|
||||
});
|
||||
}
|
||||
|
||||
if (options.limit) {
|
||||
body.limit = options.limit as number;
|
||||
}
|
||||
|
||||
if (options.skip) {
|
||||
body.skip = options.skip as number;
|
||||
}
|
||||
|
||||
if (options.sort) {
|
||||
body.sort = jsonParse(options.sort.toString(), {
|
||||
errorMessage: "'Sort' option is not valid JSON",
|
||||
});
|
||||
}
|
||||
|
||||
if (options.populate) {
|
||||
body.populate = options.populate as boolean;
|
||||
}
|
||||
|
||||
body.simple = true;
|
||||
if (options.rawData) {
|
||||
body.simple = !options.rawData;
|
||||
}
|
||||
|
||||
if (options.language) {
|
||||
body.lang = options.language as string;
|
||||
}
|
||||
|
||||
return await cockpitApiRequest.call(this, 'POST', `/collections/get/${resourceName}`, body);
|
||||
}
|
||||
|
||||
export async function getAllCollectionNames(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
): Promise<string[]> {
|
||||
return await cockpitApiRequest.call(this, 'GET', '/collections/listCollections', {});
|
||||
}
|
||||
11
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/CollectionInterface.ts
Executable file
11
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/CollectionInterface.ts
Executable file
@@ -0,0 +1,11 @@
|
||||
export interface ICollection {
|
||||
fields?: object;
|
||||
filter?: object;
|
||||
limit?: number;
|
||||
skip?: number;
|
||||
sort?: object;
|
||||
populate?: boolean;
|
||||
simple?: boolean;
|
||||
lang?: string;
|
||||
data?: object;
|
||||
}
|
||||
111
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/FormDescription.ts
Executable file
111
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/FormDescription.ts
Executable file
@@ -0,0 +1,111 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const formOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['form'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Submit a Form',
|
||||
value: 'submit',
|
||||
description: 'Store data from a form submission',
|
||||
action: 'Submit a form',
|
||||
},
|
||||
],
|
||||
default: 'submit',
|
||||
},
|
||||
];
|
||||
|
||||
export const formFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Form',
|
||||
name: 'form',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['form'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Name of the form to operate on',
|
||||
},
|
||||
|
||||
// Form:submit
|
||||
{
|
||||
displayName: 'JSON Data Fields',
|
||||
name: 'jsonDataFields',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['form'],
|
||||
operation: ['submit'],
|
||||
},
|
||||
},
|
||||
description: 'Whether form fields should be set via the value-key pair UI or JSON',
|
||||
},
|
||||
{
|
||||
displayName: 'Form Data',
|
||||
name: 'dataFieldsJson',
|
||||
type: 'json',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [true],
|
||||
resource: ['form'],
|
||||
operation: ['submit'],
|
||||
},
|
||||
},
|
||||
description: 'Form data to send as JSON',
|
||||
},
|
||||
{
|
||||
displayName: 'Form Data',
|
||||
name: 'dataFieldsUi',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [false],
|
||||
resource: ['form'],
|
||||
operation: ['submit'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'field',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the field',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the field',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
description: 'Form data to send',
|
||||
},
|
||||
];
|
||||
16
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/FormFunctions.ts
Executable file
16
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/FormFunctions.ts
Executable file
@@ -0,0 +1,16 @@
|
||||
import type { IExecuteFunctions, ILoadOptionsFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import type { IForm } from './FormInterface';
|
||||
import { cockpitApiRequest } from './GenericFunctions';
|
||||
|
||||
export async function submitForm(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
form: IDataObject,
|
||||
) {
|
||||
const body: IForm = {
|
||||
form,
|
||||
};
|
||||
|
||||
return await cockpitApiRequest.call(this, 'POST', `/forms/submit/${resourceName}`, body);
|
||||
}
|
||||
3
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/FormInterface.ts
Executable file
3
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/FormInterface.ts
Executable file
@@ -0,0 +1,3 @@
|
||||
export interface IForm {
|
||||
form: object;
|
||||
}
|
||||
72
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/GenericFunctions.ts
Executable file
72
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/GenericFunctions.ts
Executable file
@@ -0,0 +1,72 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHttpRequestMethods,
|
||||
ILoadOptionsFunctions,
|
||||
IRequestOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { jsonParse, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function cockpitApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('cockpitApi');
|
||||
let options: IRequestOptions = {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
qs: {
|
||||
token: credentials.accessToken,
|
||||
},
|
||||
body,
|
||||
uri: uri || `${credentials.url}/api${resource}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
options = Object.assign({}, options, option);
|
||||
|
||||
if (Object.keys(options.body as IDataObject).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export function createDataFromParameters(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
itemIndex: number,
|
||||
): IDataObject {
|
||||
const dataFieldsAreJson = this.getNodeParameter('jsonDataFields', itemIndex) as boolean;
|
||||
|
||||
if (dataFieldsAreJson) {
|
||||
// Parameters are defined as JSON
|
||||
return jsonParse(this.getNodeParameter('dataFieldsJson', itemIndex, '{}') as string);
|
||||
}
|
||||
|
||||
// Parameters are defined in UI
|
||||
const uiDataFields = this.getNodeParameter('dataFieldsUi', itemIndex, {}) as IDataObject;
|
||||
const unpacked: IDataObject = {};
|
||||
|
||||
if (uiDataFields.field === undefined) {
|
||||
return unpacked;
|
||||
}
|
||||
|
||||
for (const field of uiDataFields.field as IDataObject[]) {
|
||||
unpacked[field.name as string] = field.value;
|
||||
}
|
||||
|
||||
return unpacked;
|
||||
}
|
||||
44
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/SingletonDescription.ts
Executable file
44
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/SingletonDescription.ts
Executable file
@@ -0,0 +1,44 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const singletonOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['singleton'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a singleton',
|
||||
action: 'Get a singleton',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const singletonFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Singleton Name or ID',
|
||||
name: 'singleton',
|
||||
type: 'options',
|
||||
default: '',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSingletons',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['singleton'],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description:
|
||||
'Name of the singleton to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
];
|
||||
16
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/SingletonFunctions.ts
Executable file
16
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/SingletonFunctions.ts
Executable file
@@ -0,0 +1,16 @@
|
||||
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
|
||||
import { cockpitApiRequest } from './GenericFunctions';
|
||||
|
||||
export async function getSingleton(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
): Promise<any> {
|
||||
return await cockpitApiRequest.call(this, 'GET', `/singletons/get/${resourceName}`);
|
||||
}
|
||||
|
||||
export async function getAllSingletonNames(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
): Promise<string[]> {
|
||||
return await cockpitApiRequest.call(this, 'GET', '/singletons/listSingletons', {});
|
||||
}
|
||||
3
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/cockpit.dark.svg
Executable file
3
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/cockpit.dark.svg
Executable file
@@ -0,0 +1,3 @@
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M11.9564 4L17.6629 9.70644L9.05633 18.3127C6.81125 20.558 8.99407 22.7406 11.2392 20.4953L24.0863 7.64837C32.4436 -0.708884 45.696 12.544 37.339 20.9011L33.5036 24.7364L38.9293 30.1621L32.4434 36.6481L21.966 26.1707L31.6326 16.5042C33.4619 14.6749 30.8738 12.0868 29.0445 13.9158L15.5113 27.4493C6.96748 34.8708 -5.00689 23.0211 2.22735 14.1656L11.9564 4Z" fill="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 484 B |
3
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/cockpit.svg
Executable file
3
n8n-n8n-1.109.2/packages/nodes-base/nodes/Cockpit/cockpit.svg
Executable file
@@ -0,0 +1,3 @@
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M11.9564 4L17.6629 9.70644L9.05633 18.3127C6.81125 20.558 8.99407 22.7406 11.2392 20.4953L24.0863 7.64837C32.4436 -0.708884 45.696 12.544 37.339 20.9011L33.5036 24.7364L38.9293 30.1621L32.4434 36.6481L21.966 26.1707L31.6326 16.5042C33.4619 14.6749 30.8738 12.0868 29.0445 13.9158L15.5113 27.4493C6.96748 34.8708 -5.00689 23.0211 2.22735 14.1656L11.9564 4Z" fill="black"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 484 B |
Reference in New Issue
Block a user