feat(editor): Add HTTP request nodes for credentials without a node (#7157)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Elias Meire
2023-11-13 12:11:16 +01:00
committed by GitHub
parent 460ac85fda
commit 14035e1244
62 changed files with 665 additions and 146 deletions

View File

@@ -1,7 +1,5 @@
import * as path from 'path';
import { readFile } from 'fs/promises';
import glob from 'fast-glob';
import { jsonParse, getVersionedNodeTypeAll, LoggerProxy as Logger } from 'n8n-workflow';
import { readFile } from 'fs/promises';
import type {
CodexData,
DocumentationLink,
@@ -9,15 +7,22 @@ import type {
ICredentialTypeData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
INodeTypeData,
INodeTypeDescription,
INodeTypeNameVersion,
IVersionedNodeType,
KnownNodesAndCredentials,
} from 'n8n-workflow';
import {
LoggerProxy as Logger,
getCredentialsForNode,
getVersionedNodeTypeAll,
jsonParse,
} from 'n8n-workflow';
import * as path from 'path';
import { loadClassInIsolation } from './ClassLoader';
import { CUSTOM_NODES_CATEGORY } from './Constants';
import type { n8n } from './Interfaces';
import { loadClassInIsolation } from './ClassLoader';
function toJSON(this: ICredentialType) {
return {
@@ -44,6 +49,8 @@ export abstract class DirectoryLoader {
types: Types = { nodes: [], credentials: [] };
protected nodesByCredential: Record<string, string[]> = {};
constructor(
readonly directory: string,
protected readonly excludeNodes: string[] = [],
@@ -140,6 +147,13 @@ export abstract class DirectoryLoader {
getVersionedNodeTypeAll(tempNode).forEach(({ description }) => {
this.types.nodes.push(description);
});
for (const credential of getCredentialsForNode(tempNode)) {
if (!this.nodesByCredential[credential.name]) {
this.nodesByCredential[credential.name] = [];
}
this.nodesByCredential[credential.name].push(fullNodeName);
}
}
protected loadCredentialFromFile(credentialName: string, filePath: string): void {
@@ -168,6 +182,7 @@ export abstract class DirectoryLoader {
className: credentialName,
sourcePath: filePath,
extends: tempCredential.extends,
supportedNodes: this.nodesByCredential[tempCredential.name],
};
this.credentialTypes[tempCredential.name] = {
@@ -276,19 +291,24 @@ export class CustomDirectoryLoader extends DirectoryLoader {
packageName = 'CUSTOM';
override async loadAll() {
const filePaths = await glob('**/*.@(node|credentials).js', {
const nodes = await glob('**/*.node.js', {
cwd: this.directory,
absolute: true,
});
for (const filePath of filePaths) {
const [fileName, type] = path.parse(filePath).name.split('.');
for (const nodePath of nodes) {
const [fileName] = path.parse(nodePath).name.split('.');
this.loadNodeFromFile(fileName, nodePath);
}
if (type === 'node') {
this.loadNodeFromFile(fileName, filePath);
} else if (type === 'credentials') {
this.loadCredentialFromFile(fileName, filePath);
}
const credentials = await glob('**/*.credentials.js', {
cwd: this.directory,
absolute: true,
});
for (const credentialPath of credentials) {
const [fileName] = path.parse(credentialPath).name.split('.');
this.loadCredentialFromFile(fileName, credentialPath);
}
}
}
@@ -315,15 +335,6 @@ export class PackageDirectoryLoader extends DirectoryLoader {
const { nodes, credentials } = n8n;
if (Array.isArray(credentials)) {
for (const credential of credentials) {
const filePath = this.resolvePath(credential);
const [credentialName] = path.parse(credential).name.split('.');
this.loadCredentialFromFile(credentialName, filePath);
}
}
if (Array.isArray(nodes)) {
for (const node of nodes) {
const filePath = this.resolvePath(node);
@@ -333,6 +344,15 @@ export class PackageDirectoryLoader extends DirectoryLoader {
}
}
if (Array.isArray(credentials)) {
for (const credential of credentials) {
const filePath = this.resolvePath(credential);
const [credentialName] = path.parse(credential).name.split('.');
this.loadCredentialFromFile(credentialName, filePath);
}
}
Logger.debug(`Loaded all credentials and nodes from ${this.packageName}`, {
credentials: credentials?.length ?? 0,
nodes: nodes?.length ?? 0,