mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-11-01 23:52:25 -05:00
new folder structure
This commit is contained in:
parent
1b79d21dbd
commit
5831230d13
14 changed files with 262 additions and 96 deletions
|
|
@ -1,6 +1,14 @@
|
|||
// If you see type errors for 'fs' or 'path', install @types/node as a dev dependency.
|
||||
// npm install --save-dev @types/node
|
||||
import { INodeProperties, NodePropertyTypes } from 'n8n-workflow';
|
||||
import * as apiDefinitions from './api-definitions.json';
|
||||
import * as dtoDefinitions from './dto-definitions.json';
|
||||
// Remove fs and path imports
|
||||
// Import all service JSON files directly
|
||||
import generateToken from './actions/authentication/generateToken.json';
|
||||
import getProductCount from './actions/products/getProductCount.json';
|
||||
import getCustomerByDocument from './actions/customers/getCustomerByDocument.json';
|
||||
import createCustomer from './actions/customers/createCustomer.json';
|
||||
import updateCustomer from './actions/customers/updateCustomer.json';
|
||||
|
||||
export interface ApiDefinition {
|
||||
method: string;
|
||||
|
|
@ -42,10 +50,30 @@ export interface DtoDefinition {
|
|||
properties: Record<string, DtoProperty>;
|
||||
}
|
||||
|
||||
// Build static API definitions object
|
||||
const staticApiDefinitions: Record<string, Record<string, ApiDefinition>> = {
|
||||
authentication: {
|
||||
generateToken: generateToken as ApiDefinition,
|
||||
},
|
||||
products: {
|
||||
getProductCount: getProductCount as ApiDefinition,
|
||||
},
|
||||
customers: {
|
||||
getCustomerByDocument: getCustomerByDocument as ApiDefinition,
|
||||
createCustomer: createCustomer as ApiDefinition,
|
||||
updateCustomer: updateCustomer as ApiDefinition,
|
||||
},
|
||||
};
|
||||
|
||||
export class ApiHelper {
|
||||
static getApiDefinitions(): Record<string, Record<string, ApiDefinition>> {
|
||||
return apiDefinitions as any;
|
||||
}
|
||||
// Return the static API definitions
|
||||
static getApiDefinitions(): Record<string, Record<string, ApiDefinition>> {
|
||||
return staticApiDefinitions;
|
||||
}
|
||||
// Return a single API definition
|
||||
static getApiDefinition(group: string, service: string): ApiDefinition | null {
|
||||
return staticApiDefinitions[group]?.[service] || null;
|
||||
}
|
||||
|
||||
static getResources(): INodeProperties[] {
|
||||
const definitions = this.getApiDefinitions();
|
||||
|
|
@ -259,11 +287,6 @@ export class ApiHelper {
|
|||
.trim();
|
||||
}
|
||||
|
||||
static getApiDefinition(resource: string, operation: string): ApiDefinition | null {
|
||||
const definitions = this.getApiDefinitions();
|
||||
return definitions[resource]?.[operation] || null;
|
||||
}
|
||||
|
||||
static getDtoDefinitions(): Record<string, DtoDefinition> {
|
||||
return dtoDefinitions as any;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ export class S4DSMain implements INodeType {
|
|||
const resource = this.getNodeParameter('resource', i) as string;
|
||||
const operation = this.getNodeParameter('operation', i) as string;
|
||||
|
||||
// Obtener definición de la API
|
||||
const apiDefinition = ApiHelper.getApiDefinition(resource, operation);
|
||||
// Get API definition (now async)
|
||||
const apiDefinition = await ApiHelper.getApiDefinition(resource, operation);
|
||||
if (!apiDefinition) {
|
||||
throw new Error(`API definition not found for resource: ${resource}, operation: ${operation}`);
|
||||
}
|
||||
|
|
|
|||
16
nodes/S4DSMain/actions/authentication/generateToken.json
Normal file
16
nodes/S4DSMain/actions/authentication/generateToken.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "generateToken",
|
||||
"method": "POST",
|
||||
"endpoint": "/login/generateToken",
|
||||
"description": "Generate authentication token using credentials.",
|
||||
"parameters": [],
|
||||
"requiresAuth": false,
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"token": "string",
|
||||
"token_type": "string",
|
||||
"expires_in": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
nodes/S4DSMain/actions/customers/createCustomer.json
Normal file
18
nodes/S4DSMain/actions/customers/createCustomer.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "createCustomer",
|
||||
"method": "POST",
|
||||
"endpoint": "/customer",
|
||||
"description": "Create a new customer.",
|
||||
"parameters": [],
|
||||
"requiresAuth": true,
|
||||
"requestBody": {
|
||||
"schema": "SetNewCustomerDTO",
|
||||
"required": true
|
||||
},
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"customer": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
29
nodes/S4DSMain/actions/customers/getCustomerByDocument.json
Normal file
29
nodes/S4DSMain/actions/customers/getCustomerByDocument.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "getCustomerByDocument",
|
||||
"method": "GET",
|
||||
"endpoint": "/customer/specificCustomer",
|
||||
"description": "Get customer information by document ID and type.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "documentId",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "Document ID of the customer.",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"name": "documentType",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "Type of document (e.g., CC, CE, NIT).",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"requiresAuth": true,
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"customer": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
nodes/S4DSMain/actions/customers/updateCustomer.json
Normal file
18
nodes/S4DSMain/actions/customers/updateCustomer.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "updateCustomer",
|
||||
"method": "PATCH",
|
||||
"endpoint": "/customer",
|
||||
"description": "Update an existing customer.",
|
||||
"parameters": [],
|
||||
"requiresAuth": true,
|
||||
"requestBody": {
|
||||
"schema": "SetNewCustomerDTO",
|
||||
"required": true
|
||||
},
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
14
nodes/S4DSMain/actions/products/getProductCount.json
Normal file
14
nodes/S4DSMain/actions/products/getProductCount.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "getProductCount",
|
||||
"method": "GET",
|
||||
"endpoint": "/product/count",
|
||||
"description": "Get the total count of products.",
|
||||
"parameters": [],
|
||||
"requiresAuth": true,
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"count": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +1,34 @@
|
|||
{
|
||||
"authentication": {
|
||||
"generateToken": {
|
||||
"method": "POST",
|
||||
"endpoint": "/login/generateToken",
|
||||
"description": "Generate authentication token using credentials",
|
||||
"parameters": [],
|
||||
"requiresAuth": false,
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"token": "string",
|
||||
"token_type": "string",
|
||||
"expires_in": "number"
|
||||
}
|
||||
"services": [
|
||||
{
|
||||
"name": "generateToken",
|
||||
"file": "actions/authentication/generateToken.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"products": {
|
||||
"getProductCount": {
|
||||
"method": "GET",
|
||||
"endpoint": "/product/count",
|
||||
"description": "Get the total count of products",
|
||||
"parameters": [],
|
||||
"requiresAuth": true,
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"count": "number"
|
||||
}
|
||||
"services": [
|
||||
{
|
||||
"name": "getProductCount",
|
||||
"file": "actions/products/getProductCount.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"customers": {
|
||||
"getCustomerByDocument": {
|
||||
"method": "GET",
|
||||
"endpoint": "/customer/specificCustomer",
|
||||
"description": "Get customer information by document ID and type",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "documentId",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "Document ID of the customer",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"name": "documentType",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "Type of document (e.g., CC, CE, NIT)",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"requiresAuth": true,
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"customer": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"createCustomer": {
|
||||
"method": "POST",
|
||||
"endpoint": "/customer",
|
||||
"description": "Create a new customer",
|
||||
"parameters": [],
|
||||
"requiresAuth": true,
|
||||
"requestBody": {
|
||||
"schema": "SetNewCustomerDTO",
|
||||
"required": true
|
||||
"services": [
|
||||
{
|
||||
"name": "getCustomerByDocument",
|
||||
"file": "actions/customers/getCustomerByDocument.json"
|
||||
},
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"customer": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"updateCustomer": {
|
||||
"method": "PATCH",
|
||||
"endpoint": "/customer",
|
||||
"description": "Update an existing customer",
|
||||
"parameters": [],
|
||||
"requiresAuth": true,
|
||||
"requestBody": {
|
||||
"schema": "SetNewCustomerDTO",
|
||||
"required": true
|
||||
{
|
||||
"name": "createCustomer",
|
||||
"file": "actions/customers/createCustomer.json"
|
||||
},
|
||||
"response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": "object"
|
||||
}
|
||||
{
|
||||
"name": "updateCustomer",
|
||||
"file": "actions/customers/updateCustomer.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue