CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-n8n-workflow

Workflow base code of n8n providing foundational workflow execution engine for automation platform

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

node-execution.mddocs/

Node Execution

Execution contexts and helper functions that provide nodes with access to workflow data, credentials, HTTP requests, and other runtime services required for node operation.

Capabilities

Execution Function Contexts

Different execution contexts for various node types and execution scenarios.

/**
 * Main node execution context interface
 */
interface IExecuteFunctions {
  /**
   * Get execution context for specific type
   * @param type - Context type (node, workflow, etc.)
   * @returns Context object
   */
  getContext(type: string): IContextObject;

  /**
   * Get decrypted credentials for node
   * @param type - Credential type name
   * @returns Decrypted credential data
   */
  getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;

  /**
   * Get input data from connected nodes
   * @param inputIndex - Input connection index (default: 0)
   * @returns Array of input data items
   */
  getInputData(inputIndex?: number): INodeExecutionData[];

  /**
   * Get current node configuration
   * @returns Current node object
   */
  getNode(): INode;

  /**
   * Get current workflow instance
   * @returns Workflow object
   */
  getWorkflow(): Workflow;

  /**
   * Get node parameter value with expression resolution
   * @param parameterName - Parameter name
   * @param itemIndex - Current item index
   * @param fallbackValue - Default value if parameter not found
   * @returns Resolved parameter value
   */
  getNodeParameter(
    parameterName: string,
    itemIndex: number,
    fallbackValue?: any
  ): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[];

  /**
   * Get timezone for execution
   * @returns Timezone string
   */
  getTimezone(): string;

  /**
   * Get current execution mode
   * @returns Execution mode
   */
  getMode(): WorkflowExecuteMode;

  /**
   * Helper functions for common operations
   */
  helpers: IExecuteHelperFunctions;

  /**
   * Continue execution on failure flag
   * @returns Boolean indicating continue on fail
   */
  continueOnFail(): boolean;

  /**
   * Get additional data for execution
   * @returns Additional execution data
   */
  getExecuteData(): IExecuteData;
}

/**
 * Single function execution context
 */
interface IExecuteSingleFunctions {
  getContext(type: string): IContextObject;
  getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
  getInputData(): INodeExecutionData;
  getNode(): INode;
  getWorkflow(): Workflow;
  getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue;
  getTimezone(): string;
  getMode(): WorkflowExecuteMode;
  helpers: IExecuteSingleHelperFunctions;
  continueOnFail(): boolean;
}

/**
 * Pagination-enabled execution context
 */
interface IExecutePaginationFunctions extends IExecuteFunctions {
  /**
   * Make paginated request with automatic continuation
   * @param requestOptions - HTTP request configuration
   * @param itemsPerPage - Items per page limit
   * @returns Paginated response data
   */
  makeRequestWithPagination<T>(
    requestOptions: IHttpRequestOptions,
    itemsPerPage?: number
  ): Promise<T[]>;
}

Helper Functions

Comprehensive helper functions for HTTP requests, data manipulation, and common operations.

interface IExecuteHelperFunctions {
  /**
   * Make HTTP request with credential authentication
   * @param requestOptions - HTTP request configuration
   * @returns HTTP response data
   */
  httpRequest(requestOptions: IHttpRequestOptions): Promise<any>;

  /**
   * Make authenticated HTTP request using credentials
   * @param credentialsType - Type of credentials to use
   * @param requestOptions - HTTP request configuration
   * @returns HTTP response data
   */
  httpRequestWithAuthentication(
    credentialsType: string,
    requestOptions: IHttpRequestOptions
  ): Promise<any>;

  /**
   * Return data as JSON array format
   * @param jsonData - Array of objects to return
   * @returns Formatted execution data
   */
  returnJsonArray(jsonData: IDataObject[]): INodeExecutionData[];

  /**
   * Prepare output data structure
   * @param outputData - Data to prepare for output
   * @returns Prepared node execution data
   */
  prepareOutputData(outputData: INodeExecutionData[]): INodeExecutionData[];

  /**
   * Log message with node context
   * @param message - Message to log
   * @param level - Log level
   */
  logNodeOutput(message: string, level?: LogLevel): void;

  /**
   * Get binary data stream
   * @param itemIndex - Item index for binary data
   * @param propertyName - Binary property name
   * @returns Binary data stream
   */
  getBinaryDataStream(itemIndex: number, propertyName: string): Readable;

  /**
   * Prepare binary data for output
   * @param binaryData - Binary data buffer
   * @param filePath - File path for binary data
   * @param mimeType - MIME type of binary data
   * @returns Binary data configuration
   */
  prepareBinaryData(
    binaryData: Buffer,
    filePath?: string,
    mimeType?: string
  ): Promise<IBinaryData>;

  /**
   * Create deferred promise for async operations
   * @returns Deferred promise instance
   */
  createDeferredPromise<T>(): IDeferredPromise<T>;
}

HTTP Request Configuration

Configuration interfaces for HTTP requests and authentication.

interface IHttpRequestOptions {
  url: string;
  method?: IHttpRequestMethods;
  body?: any;
  qs?: IDataObject;
  headers?: IDataObject;
  auth?: IHttpRequestAuth;
  timeout?: number;
  encoding?: string | null;
  json?: boolean;
  gzip?: boolean;
  resolveWithFullResponse?: boolean;
  simple?: boolean;
  proxy?: string;
  strictSSL?: boolean;
  rejectUnauthorized?: boolean;
  followRedirect?: boolean;
  followAllRedirects?: boolean;
  maxRedirects?: number;
  returnFullResponse?: boolean;
}

type IHttpRequestMethods = 
  | 'DELETE'
  | 'GET' 
  | 'HEAD'
  | 'PATCH'
  | 'POST'
  | 'PUT';

interface IHttpRequestAuth {
  username: string;
  password: string;
  sendImmediately?: boolean;
}

Trigger and Webhook Contexts

Specialized execution contexts for trigger nodes and webhook handling.

/**
 * Trigger function execution context
 */
interface ITriggerFunctions {
  getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
  getNode(): INode;
  getWorkflow(): Workflow;
  getMode(): WorkflowExecuteMode;
  getTimezone(): string;
  
  /**
   * Emit trigger event with data
   * @param data - Trigger data to emit
   * @param responsePromise - Optional response promise
   */
  emit(
    data: INodeExecutionData[][],
    responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>
  ): void;

  helpers: ITriggerHelperFunctions;
}

/**
 * Webhook function execution context
 */
interface IWebhookFunctions {
  getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
  getNode(): INode;
  getWorkflow(): Workflow;
  getMode(): WorkflowExecuteMode;
  
  /**
   * Get webhook request object
   * @returns Express request object
   */
  getRequestObject(): express.Request;

  /**
   * Get webhook response object
   * @returns Express response object
   */
  getResponseObject(): express.Response;

  /**
   * Get request body data
   * @returns Parsed request body
   */
  getBodyData(): IDataObject;

  /**
   * Get request headers
   * @returns Request headers object
   */
  getHeaderData(): IDataObject;

  /**
   * Get URL parameters
   * @returns URL parameters object
   */
  getParamsData(): IDataObject;

  /**
   * Get query parameters
   * @returns Query parameters object
   */
  getQueryData(): IDataObject;

  helpers: IWebhookHelperFunctions;
}

Load Options Context

Context for dynamic option loading in node parameter configuration.

/**
 * Load options function context
 */
interface ILoadOptionsFunctions {
  getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
  getNode(): INode;
  getWorkflow(): Workflow;
  
  /**
   * Get current node parameter values
   * @returns Current parameter values
   */
  getCurrentNodeParameters(): INodeParameters;

  /**
   * Get parameter value by name
   * @param parameterName - Parameter name
   */
  getCurrentNodeParameter(parameterName: string): NodeParameterValue | undefined;

  helpers: ILoadOptionsHelperFunctions;
}

/**
 * Node property options for dynamic loading
 */
interface INodePropertyOptions {
  name: string;
  value: string | number | boolean;
  description?: string;
  action?: string;
}

Usage Examples:

import { IExecuteFunctions, INodeExecutionData, IDataObject } from "n8n-workflow";

// Basic node execution function
export async function execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
  const items = this.getInputData();
  const returnData: INodeExecutionData[] = [];

  for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
    try {
      // Get node parameters
      const apiUrl = this.getNodeParameter('apiUrl', itemIndex) as string;
      const method = this.getNodeParameter('method', itemIndex, 'GET') as string;
      
      // Get credentials
      const credentials = await this.getCredentials('httpBasicAuth');
      
      // Make HTTP request
      const requestOptions = {
        url: apiUrl,
        method: method as IHttpRequestMethods,
        auth: {
          username: credentials.user as string,
          password: credentials.password as string,
        },
        json: true,
      };

      const response = await this.helpers.httpRequest(requestOptions);
      
      // Return data
      returnData.push({
        json: response,
        pairedItem: itemIndex,
      });

    } catch (error) {
      if (this.continueOnFail()) {
        returnData.push({
          json: { error: error.message },
          pairedItem: itemIndex,
        });
      } else {
        throw error;
      }
    }
  }

  return [returnData];
}

// Webhook node example
export async function webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
  const bodyData = this.getBodyData();
  const headerData = this.getHeaderData();
  const queryData = this.getQueryData();

  // Process webhook data
  const responseData: IDataObject = {
    body: bodyData,
    headers: headerData, 
    query: queryData,
    receivedAt: new Date().toISOString(),
  };

  return {
    workflowData: [
      [
        {
          json: responseData,
        },
      ],
    ],
  };
}

// Load options example
export async function loadOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
  const credentials = await this.getCredentials('myApiCredentials');
  
  const requestOptions = {
    url: 'https://api.example.com/options',
    headers: {
      'Authorization': `Bearer ${credentials.apiKey}`,
    },
    json: true,
  };

  const response = await this.helpers.httpRequest!(requestOptions);
  
  return response.options.map((option: any) => ({
    name: option.label,
    value: option.id,
    description: option.description,
  }));
}

docs

constants.md

data-proxy.md

error-handling.md

expression-system.md

extension-system.md

graph-utilities.md

index.md

node-execution.md

specialized-modules.md

type-guards.md

type-validation.md

utilities.md

workflow-management.md

tile.json