mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
chore: add pre-built dist folder for npx usage
This commit is contained in:
committed by
Romuald Członkowski
parent
a70d96a373
commit
5057481e70
35
dist/parsers/node-parser.d.ts
vendored
Normal file
35
dist/parsers/node-parser.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { NodeClass } from '../types/node-types';
|
||||
export interface ParsedNode {
|
||||
style: 'declarative' | 'programmatic';
|
||||
nodeType: string;
|
||||
displayName: string;
|
||||
description?: string;
|
||||
category?: string;
|
||||
properties: any[];
|
||||
credentials: any[];
|
||||
isAITool: boolean;
|
||||
isTrigger: boolean;
|
||||
isWebhook: boolean;
|
||||
operations: any[];
|
||||
version?: string;
|
||||
isVersioned: boolean;
|
||||
packageName: string;
|
||||
documentation?: string;
|
||||
outputs?: any[];
|
||||
outputNames?: string[];
|
||||
}
|
||||
export declare class NodeParser {
|
||||
private propertyExtractor;
|
||||
private currentNodeClass;
|
||||
parse(nodeClass: NodeClass, packageName: string): ParsedNode;
|
||||
private getNodeDescription;
|
||||
private detectStyle;
|
||||
private extractNodeType;
|
||||
private extractCategory;
|
||||
private detectTrigger;
|
||||
private detectWebhook;
|
||||
private extractVersion;
|
||||
private detectVersioned;
|
||||
private extractOutputs;
|
||||
}
|
||||
//# sourceMappingURL=node-parser.d.ts.map
|
||||
1
dist/parsers/node-parser.d.ts.map
vendored
Normal file
1
dist/parsers/node-parser.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"node-parser.d.ts","sourceRoot":"","sources":["../../src/parsers/node-parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,qBAAqB,CAAC;AAQ7B,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,aAAa,GAAG,cAAc,CAAC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,gBAAgB,CAA0B;IAElD,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU;IA0B5D,OAAO,CAAC,kBAAkB;IAoD1B,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,cAAc;IA0FtB,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,cAAc;CAsDvB"}
|
||||
250
dist/parsers/node-parser.js
vendored
Normal file
250
dist/parsers/node-parser.js
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NodeParser = void 0;
|
||||
const property_extractor_1 = require("./property-extractor");
|
||||
const node_types_1 = require("../types/node-types");
|
||||
class NodeParser {
|
||||
constructor() {
|
||||
this.propertyExtractor = new property_extractor_1.PropertyExtractor();
|
||||
this.currentNodeClass = null;
|
||||
}
|
||||
parse(nodeClass, packageName) {
|
||||
this.currentNodeClass = nodeClass;
|
||||
const description = this.getNodeDescription(nodeClass);
|
||||
const outputInfo = this.extractOutputs(description);
|
||||
return {
|
||||
style: this.detectStyle(nodeClass),
|
||||
nodeType: this.extractNodeType(description, packageName),
|
||||
displayName: description.displayName || description.name,
|
||||
description: description.description,
|
||||
category: this.extractCategory(description),
|
||||
properties: this.propertyExtractor.extractProperties(nodeClass),
|
||||
credentials: this.propertyExtractor.extractCredentials(nodeClass),
|
||||
isAITool: this.propertyExtractor.detectAIToolCapability(nodeClass),
|
||||
isTrigger: this.detectTrigger(description),
|
||||
isWebhook: this.detectWebhook(description),
|
||||
operations: this.propertyExtractor.extractOperations(nodeClass),
|
||||
version: this.extractVersion(nodeClass),
|
||||
isVersioned: this.detectVersioned(nodeClass),
|
||||
packageName: packageName,
|
||||
outputs: outputInfo.outputs,
|
||||
outputNames: outputInfo.outputNames
|
||||
};
|
||||
}
|
||||
getNodeDescription(nodeClass) {
|
||||
let description;
|
||||
if ((0, node_types_1.isVersionedNodeClass)(nodeClass)) {
|
||||
try {
|
||||
const instance = new nodeClass();
|
||||
const inst = instance;
|
||||
description = inst.description || (inst.nodeVersions ? inst.baseDescription : undefined);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
else if (typeof nodeClass === 'function') {
|
||||
try {
|
||||
const instance = new nodeClass();
|
||||
description = instance.description;
|
||||
if (!description || !description.name) {
|
||||
const inst = instance;
|
||||
if (inst.baseDescription?.name) {
|
||||
description = inst.baseDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
description = nodeClass.description;
|
||||
}
|
||||
}
|
||||
else {
|
||||
description = nodeClass.description;
|
||||
if (!description || !description.name) {
|
||||
const inst = nodeClass;
|
||||
if (inst.baseDescription?.name) {
|
||||
description = inst.baseDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
return description || {};
|
||||
}
|
||||
detectStyle(nodeClass) {
|
||||
const desc = this.getNodeDescription(nodeClass);
|
||||
return desc.routing ? 'declarative' : 'programmatic';
|
||||
}
|
||||
extractNodeType(description, packageName) {
|
||||
const name = description.name;
|
||||
if (!name) {
|
||||
throw new Error('Node is missing name property');
|
||||
}
|
||||
if (name.includes('.')) {
|
||||
return name;
|
||||
}
|
||||
const packagePrefix = packageName.replace('@n8n/', '').replace('n8n-', '');
|
||||
return `${packagePrefix}.${name}`;
|
||||
}
|
||||
extractCategory(description) {
|
||||
return description.group?.[0] ||
|
||||
description.categories?.[0] ||
|
||||
description.category ||
|
||||
'misc';
|
||||
}
|
||||
detectTrigger(description) {
|
||||
const desc = description;
|
||||
if (description.group && Array.isArray(description.group)) {
|
||||
if (description.group.includes('trigger')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return desc.polling === true ||
|
||||
desc.trigger === true ||
|
||||
desc.eventTrigger === true ||
|
||||
description.name?.toLowerCase().includes('trigger');
|
||||
}
|
||||
detectWebhook(description) {
|
||||
const desc = description;
|
||||
return (desc.webhooks?.length > 0) ||
|
||||
desc.webhook === true ||
|
||||
description.name?.toLowerCase().includes('webhook');
|
||||
}
|
||||
extractVersion(nodeClass) {
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
const inst = instance;
|
||||
if (inst?.currentVersion !== undefined) {
|
||||
return inst.currentVersion.toString();
|
||||
}
|
||||
if (inst?.description?.defaultVersion) {
|
||||
return inst.description.defaultVersion.toString();
|
||||
}
|
||||
if (inst?.nodeVersions) {
|
||||
const versions = Object.keys(inst.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const maxVersion = Math.max(...versions);
|
||||
if (!isNaN(maxVersion)) {
|
||||
return maxVersion.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inst?.description?.version) {
|
||||
const version = inst.description.version;
|
||||
if (Array.isArray(version)) {
|
||||
const numericVersions = version.map((v) => parseFloat(v.toString()));
|
||||
if (numericVersions.length > 0) {
|
||||
const maxVersion = Math.max(...numericVersions);
|
||||
if (!isNaN(maxVersion)) {
|
||||
return maxVersion.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof version === 'number' || typeof version === 'string') {
|
||||
return version.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
const nodeClassAny = nodeClass;
|
||||
if (nodeClassAny.description?.defaultVersion) {
|
||||
return nodeClassAny.description.defaultVersion.toString();
|
||||
}
|
||||
if (nodeClassAny.nodeVersions) {
|
||||
const versions = Object.keys(nodeClassAny.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const maxVersion = Math.max(...versions);
|
||||
if (!isNaN(maxVersion)) {
|
||||
return maxVersion.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
const description = this.getNodeDescription(nodeClass);
|
||||
const desc = description;
|
||||
if (desc?.version) {
|
||||
if (Array.isArray(desc.version)) {
|
||||
const numericVersions = desc.version.map((v) => parseFloat(v.toString()));
|
||||
if (numericVersions.length > 0) {
|
||||
const maxVersion = Math.max(...numericVersions);
|
||||
if (!isNaN(maxVersion)) {
|
||||
return maxVersion.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof desc.version === 'number' || typeof desc.version === 'string') {
|
||||
return desc.version.toString();
|
||||
}
|
||||
}
|
||||
return '1';
|
||||
}
|
||||
detectVersioned(nodeClass) {
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
const inst = instance;
|
||||
if (inst?.baseDescription?.defaultVersion) {
|
||||
return true;
|
||||
}
|
||||
if (inst?.nodeVersions) {
|
||||
return true;
|
||||
}
|
||||
if (inst?.description?.version && Array.isArray(inst.description.version)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
const nodeClassAny = nodeClass;
|
||||
if (nodeClassAny.nodeVersions || nodeClassAny.baseDescription?.defaultVersion) {
|
||||
return true;
|
||||
}
|
||||
const description = this.getNodeDescription(nodeClass);
|
||||
const desc = description;
|
||||
if (desc?.version && Array.isArray(desc.version)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
extractOutputs(description) {
|
||||
const result = {};
|
||||
const desc = description;
|
||||
if (desc.outputs) {
|
||||
result.outputs = Array.isArray(desc.outputs) ? desc.outputs : [desc.outputs];
|
||||
}
|
||||
if (desc.outputNames) {
|
||||
result.outputNames = Array.isArray(desc.outputNames) ? desc.outputNames : [desc.outputNames];
|
||||
}
|
||||
if (!result.outputs && !result.outputNames) {
|
||||
const nodeClass = this.currentNodeClass;
|
||||
if (nodeClass) {
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
const inst = instance;
|
||||
if (inst.nodeVersions) {
|
||||
const versions = Object.keys(inst.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const latestVersion = Math.max(...versions);
|
||||
if (!isNaN(latestVersion)) {
|
||||
const versionedDescription = inst.nodeVersions[latestVersion]?.description;
|
||||
if (versionedDescription) {
|
||||
if (versionedDescription.outputs) {
|
||||
result.outputs = Array.isArray(versionedDescription.outputs)
|
||||
? versionedDescription.outputs
|
||||
: [versionedDescription.outputs];
|
||||
}
|
||||
if (versionedDescription.outputNames) {
|
||||
result.outputNames = Array.isArray(versionedDescription.outputNames)
|
||||
? versionedDescription.outputNames
|
||||
: [versionedDescription.outputNames];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
exports.NodeParser = NodeParser;
|
||||
//# sourceMappingURL=node-parser.js.map
|
||||
1
dist/parsers/node-parser.js.map
vendored
Normal file
1
dist/parsers/node-parser.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
11
dist/parsers/property-extractor.d.ts
vendored
Normal file
11
dist/parsers/property-extractor.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { NodeClass } from '../types/node-types';
|
||||
export declare class PropertyExtractor {
|
||||
extractProperties(nodeClass: NodeClass): any[];
|
||||
private getNodeDescription;
|
||||
extractOperations(nodeClass: NodeClass): any[];
|
||||
private extractOperationsFromDescription;
|
||||
detectAIToolCapability(nodeClass: NodeClass): boolean;
|
||||
extractCredentials(nodeClass: NodeClass): any[];
|
||||
private normalizeProperties;
|
||||
}
|
||||
//# sourceMappingURL=property-extractor.d.ts.map
|
||||
1
dist/parsers/property-extractor.d.ts.map
vendored
Normal file
1
dist/parsers/property-extractor.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"property-extractor.d.ts","sourceRoot":"","sources":["../../src/parsers/property-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,iBAAiB;IAI5B,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,GAAG,EAAE;IAqC9C,OAAO,CAAC,kBAAkB;IA6B1B,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,GAAG,EAAE;IAiC9C,OAAO,CAAC,gCAAgC;IAmDxC,sBAAsB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IA4BrD,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,GAAG,EAAE;IAqC/C,OAAO,CAAC,mBAAmB;CAgB5B"}
|
||||
172
dist/parsers/property-extractor.js
vendored
Normal file
172
dist/parsers/property-extractor.js
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PropertyExtractor = void 0;
|
||||
class PropertyExtractor {
|
||||
extractProperties(nodeClass) {
|
||||
const properties = [];
|
||||
let instance;
|
||||
try {
|
||||
instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
if (instance?.nodeVersions) {
|
||||
const versions = Object.keys(instance.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const latestVersion = Math.max(...versions);
|
||||
if (!isNaN(latestVersion)) {
|
||||
const versionedNode = instance.nodeVersions[latestVersion];
|
||||
if (versionedNode?.description?.properties) {
|
||||
return this.normalizeProperties(versionedNode.description.properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const description = instance?.description || instance?.baseDescription ||
|
||||
this.getNodeDescription(nodeClass);
|
||||
if (description?.properties) {
|
||||
return this.normalizeProperties(description.properties);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
getNodeDescription(nodeClass) {
|
||||
let description;
|
||||
if (typeof nodeClass === 'function') {
|
||||
try {
|
||||
const instance = new nodeClass();
|
||||
const inst = instance;
|
||||
description = inst.description || inst.baseDescription || {};
|
||||
}
|
||||
catch (e) {
|
||||
const nodeClassAny = nodeClass;
|
||||
description = nodeClassAny.description || {};
|
||||
}
|
||||
}
|
||||
else {
|
||||
const inst = nodeClass;
|
||||
description = inst.description || {};
|
||||
}
|
||||
return description;
|
||||
}
|
||||
extractOperations(nodeClass) {
|
||||
const operations = [];
|
||||
let instance;
|
||||
try {
|
||||
instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
if (instance?.nodeVersions) {
|
||||
const versions = Object.keys(instance.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const latestVersion = Math.max(...versions);
|
||||
if (!isNaN(latestVersion)) {
|
||||
const versionedNode = instance.nodeVersions[latestVersion];
|
||||
if (versionedNode?.description) {
|
||||
return this.extractOperationsFromDescription(versionedNode.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const description = instance?.description || instance?.baseDescription ||
|
||||
this.getNodeDescription(nodeClass);
|
||||
return this.extractOperationsFromDescription(description);
|
||||
}
|
||||
extractOperationsFromDescription(description) {
|
||||
const operations = [];
|
||||
if (!description)
|
||||
return operations;
|
||||
if (description.routing) {
|
||||
const routing = description.routing;
|
||||
if (routing.request?.resource) {
|
||||
const resources = routing.request.resource.options || [];
|
||||
const operationOptions = routing.request.operation?.options || {};
|
||||
resources.forEach((resource) => {
|
||||
const resourceOps = operationOptions[resource.value] || [];
|
||||
resourceOps.forEach((op) => {
|
||||
operations.push({
|
||||
resource: resource.value,
|
||||
operation: op.value,
|
||||
name: `${resource.name} - ${op.name}`,
|
||||
action: op.action
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
if (description.properties && Array.isArray(description.properties)) {
|
||||
const operationProp = description.properties.find((p) => p.name === 'operation' || p.name === 'action');
|
||||
if (operationProp?.options) {
|
||||
operationProp.options.forEach((op) => {
|
||||
operations.push({
|
||||
operation: op.value,
|
||||
name: op.name,
|
||||
description: op.description
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
detectAIToolCapability(nodeClass) {
|
||||
const description = this.getNodeDescription(nodeClass);
|
||||
if (description?.usableAsTool === true)
|
||||
return true;
|
||||
if (description?.actions?.some((a) => a.usableAsTool === true))
|
||||
return true;
|
||||
const nodeClassAny = nodeClass;
|
||||
if (nodeClassAny.nodeVersions) {
|
||||
for (const version of Object.values(nodeClassAny.nodeVersions)) {
|
||||
if (version.description?.usableAsTool === true)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const aiIndicators = ['openai', 'anthropic', 'huggingface', 'cohere', 'ai'];
|
||||
const nodeName = description?.name?.toLowerCase() || '';
|
||||
return aiIndicators.some(indicator => nodeName.includes(indicator));
|
||||
}
|
||||
extractCredentials(nodeClass) {
|
||||
const credentials = [];
|
||||
let instance;
|
||||
try {
|
||||
instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
if (instance?.nodeVersions) {
|
||||
const versions = Object.keys(instance.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const latestVersion = Math.max(...versions);
|
||||
if (!isNaN(latestVersion)) {
|
||||
const versionedNode = instance.nodeVersions[latestVersion];
|
||||
if (versionedNode?.description?.credentials) {
|
||||
return versionedNode.description.credentials;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const description = instance?.description || instance?.baseDescription ||
|
||||
this.getNodeDescription(nodeClass);
|
||||
if (description?.credentials) {
|
||||
return description.credentials;
|
||||
}
|
||||
return credentials;
|
||||
}
|
||||
normalizeProperties(properties) {
|
||||
return properties.map(prop => ({
|
||||
displayName: prop.displayName,
|
||||
name: prop.name,
|
||||
type: prop.type,
|
||||
default: prop.default,
|
||||
description: prop.description,
|
||||
options: prop.options,
|
||||
required: prop.required,
|
||||
displayOptions: prop.displayOptions,
|
||||
typeOptions: prop.typeOptions,
|
||||
modes: prop.modes,
|
||||
noDataExpression: prop.noDataExpression
|
||||
}));
|
||||
}
|
||||
}
|
||||
exports.PropertyExtractor = PropertyExtractor;
|
||||
//# sourceMappingURL=property-extractor.js.map
|
||||
1
dist/parsers/property-extractor.js.map
vendored
Normal file
1
dist/parsers/property-extractor.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
25
dist/parsers/simple-parser.d.ts
vendored
Normal file
25
dist/parsers/simple-parser.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { NodeClass } from '../types/node-types';
|
||||
export interface ParsedNode {
|
||||
style: 'declarative' | 'programmatic';
|
||||
nodeType: string;
|
||||
displayName: string;
|
||||
description?: string;
|
||||
category?: string;
|
||||
properties: any[];
|
||||
credentials: string[];
|
||||
isAITool: boolean;
|
||||
isTrigger: boolean;
|
||||
isWebhook: boolean;
|
||||
operations: any[];
|
||||
version?: string;
|
||||
isVersioned: boolean;
|
||||
}
|
||||
export declare class SimpleParser {
|
||||
parse(nodeClass: NodeClass): ParsedNode;
|
||||
private detectTrigger;
|
||||
private extractOperations;
|
||||
private extractProgrammaticOperations;
|
||||
private extractVersion;
|
||||
private isVersionedNode;
|
||||
}
|
||||
//# sourceMappingURL=simple-parser.d.ts.map
|
||||
1
dist/parsers/simple-parser.d.ts.map
vendored
Normal file
1
dist/parsers/simple-parser.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"simple-parser.d.ts","sourceRoot":"","sources":["../../src/parsers/simple-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,qBAAqB,CAAC;AAO7B,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,aAAa,GAAG,cAAc,CAAC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,qBAAa,YAAY;IACvB,KAAK,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU;IA0FvC,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,iBAAiB;IAsCzB,OAAO,CAAC,6BAA6B;IA+DrC,OAAO,CAAC,cAAc;IA2DtB,OAAO,CAAC,eAAe;CAqCxB"}
|
||||
212
dist/parsers/simple-parser.js
vendored
Normal file
212
dist/parsers/simple-parser.js
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SimpleParser = void 0;
|
||||
const node_types_1 = require("../types/node-types");
|
||||
class SimpleParser {
|
||||
parse(nodeClass) {
|
||||
let description;
|
||||
let isVersioned = false;
|
||||
try {
|
||||
if ((0, node_types_1.isVersionedNodeClass)(nodeClass)) {
|
||||
const instance = new nodeClass();
|
||||
const inst = instance;
|
||||
description = inst.description || (inst.nodeVersions ? inst.baseDescription : undefined);
|
||||
if (!description) {
|
||||
description = {};
|
||||
}
|
||||
isVersioned = true;
|
||||
if (inst.nodeVersions && inst.currentVersion) {
|
||||
const currentVersionNode = inst.nodeVersions[inst.currentVersion];
|
||||
if (currentVersionNode && currentVersionNode.description) {
|
||||
description = { ...description, ...currentVersionNode.description };
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof nodeClass === 'function') {
|
||||
try {
|
||||
const instance = new nodeClass();
|
||||
description = instance.description;
|
||||
if (!description || !description.name) {
|
||||
const inst = instance;
|
||||
if (inst.baseDescription?.name) {
|
||||
description = inst.baseDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
description = {};
|
||||
}
|
||||
}
|
||||
else {
|
||||
description = nodeClass.description;
|
||||
if (!description || !description.name) {
|
||||
const inst = nodeClass;
|
||||
if (inst.baseDescription?.name) {
|
||||
description = inst.baseDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
description = nodeClass.description || {};
|
||||
}
|
||||
const desc = description;
|
||||
const isDeclarative = !!desc.routing;
|
||||
if (!description.name) {
|
||||
throw new Error('Node is missing name property');
|
||||
}
|
||||
return {
|
||||
style: isDeclarative ? 'declarative' : 'programmatic',
|
||||
nodeType: description.name,
|
||||
displayName: description.displayName || description.name,
|
||||
description: description.description,
|
||||
category: description.group?.[0] || desc.categories?.[0],
|
||||
properties: desc.properties || [],
|
||||
credentials: desc.credentials || [],
|
||||
isAITool: desc.usableAsTool === true,
|
||||
isTrigger: this.detectTrigger(description),
|
||||
isWebhook: desc.webhooks?.length > 0,
|
||||
operations: isDeclarative ? this.extractOperations(desc.routing) : this.extractProgrammaticOperations(desc),
|
||||
version: this.extractVersion(nodeClass),
|
||||
isVersioned: isVersioned || this.isVersionedNode(nodeClass) || Array.isArray(desc.version) || desc.defaultVersion !== undefined
|
||||
};
|
||||
}
|
||||
detectTrigger(description) {
|
||||
if (description.group && Array.isArray(description.group)) {
|
||||
if (description.group.includes('trigger')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const desc = description;
|
||||
return desc.polling === true ||
|
||||
desc.trigger === true ||
|
||||
desc.eventTrigger === true ||
|
||||
description.name?.toLowerCase().includes('trigger');
|
||||
}
|
||||
extractOperations(routing) {
|
||||
const operations = [];
|
||||
if (routing?.request) {
|
||||
const resources = routing.request.resource?.options || [];
|
||||
resources.forEach((resource) => {
|
||||
operations.push({
|
||||
resource: resource.value,
|
||||
name: resource.name
|
||||
});
|
||||
});
|
||||
const operationOptions = routing.request.operation?.options || [];
|
||||
operationOptions.forEach((operation) => {
|
||||
operations.push({
|
||||
operation: operation.value,
|
||||
name: operation.name || operation.displayName
|
||||
});
|
||||
});
|
||||
}
|
||||
if (routing?.operations) {
|
||||
Object.entries(routing.operations).forEach(([key, value]) => {
|
||||
operations.push({
|
||||
operation: key,
|
||||
name: value.displayName || key
|
||||
});
|
||||
});
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
extractProgrammaticOperations(description) {
|
||||
const operations = [];
|
||||
if (!description.properties || !Array.isArray(description.properties)) {
|
||||
return operations;
|
||||
}
|
||||
const resourceProp = description.properties.find((p) => p.name === 'resource' && p.type === 'options');
|
||||
if (resourceProp && resourceProp.options) {
|
||||
resourceProp.options.forEach((resource) => {
|
||||
operations.push({
|
||||
type: 'resource',
|
||||
resource: resource.value,
|
||||
name: resource.name
|
||||
});
|
||||
});
|
||||
}
|
||||
const operationProps = description.properties.filter((p) => p.name === 'operation' && p.type === 'options' && p.displayOptions);
|
||||
operationProps.forEach((opProp) => {
|
||||
if (opProp.options) {
|
||||
opProp.options.forEach((operation) => {
|
||||
const resourceCondition = opProp.displayOptions?.show?.resource;
|
||||
const resources = Array.isArray(resourceCondition) ? resourceCondition : [resourceCondition];
|
||||
operations.push({
|
||||
type: 'operation',
|
||||
operation: operation.value,
|
||||
name: operation.name,
|
||||
action: operation.action,
|
||||
resources: resources
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
return operations;
|
||||
}
|
||||
extractVersion(nodeClass) {
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
const inst = instance;
|
||||
if (inst?.currentVersion !== undefined) {
|
||||
return inst.currentVersion.toString();
|
||||
}
|
||||
if (inst?.description?.defaultVersion) {
|
||||
return inst.description.defaultVersion.toString();
|
||||
}
|
||||
if (inst?.nodeVersions) {
|
||||
const versions = Object.keys(inst.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const maxVersion = Math.max(...versions);
|
||||
if (!isNaN(maxVersion)) {
|
||||
return maxVersion.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inst?.description?.version) {
|
||||
return inst.description.version.toString();
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
const nodeClassAny = nodeClass;
|
||||
if (nodeClassAny.description?.defaultVersion) {
|
||||
return nodeClassAny.description.defaultVersion.toString();
|
||||
}
|
||||
if (nodeClassAny.nodeVersions) {
|
||||
const versions = Object.keys(nodeClassAny.nodeVersions).map(Number);
|
||||
if (versions.length > 0) {
|
||||
const maxVersion = Math.max(...versions);
|
||||
if (!isNaN(maxVersion)) {
|
||||
return maxVersion.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return nodeClassAny.description?.version || '1';
|
||||
}
|
||||
isVersionedNode(nodeClass) {
|
||||
const nodeClassAny = nodeClass;
|
||||
if (nodeClassAny.baseDescription && nodeClassAny.nodeVersions) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
const inst = instance;
|
||||
if (inst.baseDescription && inst.nodeVersions) {
|
||||
return true;
|
||||
}
|
||||
const description = inst.description || {};
|
||||
if (Array.isArray(description.version)) {
|
||||
return true;
|
||||
}
|
||||
if (description.defaultVersion !== undefined) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.SimpleParser = SimpleParser;
|
||||
//# sourceMappingURL=simple-parser.js.map
|
||||
1
dist/parsers/simple-parser.js.map
vendored
Normal file
1
dist/parsers/simple-parser.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user