Skip to content

Commit 248f95d

Browse files
authored
Merge pull request #3 from yepcode/feature/add-input-context
Add input data to execution context
2 parents 3715e27 + 3549c99 commit 248f95d

File tree

7 files changed

+474
-135
lines changed

7 files changed

+474
-135
lines changed

README.md

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,59 @@ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes
2020

2121
## Operations
2222

23-
1. Run a YepCode Process: Execute a specific YepCode process by selecting it from your YepCode workspace. Supports passing parameters, version selection, and advanced options such as synchronous/asynchronous execution.
24-
2. Run Code: Directly execute custom code in YepCode from your n8n workflow, with full support for dependencies and secrets.
23+
### 1. Run a YepCode Process
24+
25+
Execute a specific YepCode process by selecting it from your YepCode workspace. This operation allows you to run pre-built processes with parameter mapping and advanced execution options.
26+
27+
**Key Features:**
28+
- **Process Selection**: Choose from your available YepCode processes with searchable dropdown
29+
- **Parameter Mapping**: Map n8n input data to process parameters using a visual resource mapper
30+
- **Version Control**: Select specific process versions or use the current version
31+
- **Execution Modes**:
32+
- **Run Once for All Items**: Execute the process once with all input items
33+
- **Run Once for Each Item**: Execute the process separately for each input item
34+
- **Synchronous/Asynchronous**: Choose whether to wait for execution completion
35+
- **n8n Context Integration**: Automatically pass n8n workflow data to your process
36+
37+
**Advanced Options:**
38+
- **Version Selection**: Run specific published versions of your process
39+
- **Synchronous Execution**: Wait for completion and get results immediately
40+
- **Metadata**: Add execution comments and initiator information
41+
- **n8n Context**: Include workflow metadata, environment variables, and execution info
42+
43+
**Example Use Cases:**
44+
- AI/ML model inference
45+
- Data transformation processes
46+
- API integrations with complex logic
47+
- File processing workflows
48+
- Database operations
49+
50+
### 2. Run Code
51+
52+
Directly execute custom JavaScript or Python code in YepCode from your n8n workflow. This operation provides maximum flexibility for custom logic execution.
53+
54+
**Key Features:**
55+
- **Multi-language Support**: Write code in JavaScript (Node.js) or Python
56+
- **Auto-dependency Management**: Import any NPM or PyPI package - YepCode installs them automatically
57+
- **n8n Integration**: Access n8n input items and workflow metadata directly in your code
58+
- **Execution Modes**:
59+
- **Run Once for All Items**: Process all input items in a single execution
60+
- **Run Once for Each Item**: Execute code separately for each input item
61+
- **Secure Environment**: Code runs in YepCode's isolated, secure environment
62+
63+
**Advanced Options:**
64+
- **Language Detection**: Auto-detect code language or specify manually
65+
- **Code Cleanup**: Option to remove code after execution
66+
- **Metadata**: Add execution comments and initiator information
67+
- **n8n Context**: Include workflow data and metadata in your code execution
68+
69+
**Example Use Cases:**
70+
- Custom data transformations
71+
- Complex calculations
72+
- API aggregations
73+
- Data validation
74+
- Custom business logic
75+
- Integration with external services
2576

2677
## Credentials
2778

@@ -34,9 +85,106 @@ Authentication is required to use this node. You'll need your YepCode API token,
3485

3586
## Usage
3687

37-
To use this node, add it to your n8n workflow and configure the required fields, such as selecting the YepCode process or entering your custom code. Make sure your credentials are set up as described above. For more information on using n8n community nodes, see the [n8n documentation](https://docs.n8n.io/integrations/#community-nodes). If you are new to n8n, you can get started with the [Try it out](https://docs.n8n.io/try-it-out/) guide.
88+
### Setting Up Credentials
89+
90+
1. In your YepCode workspace, go to `Settings > API credentials`
91+
2. Copy your API token
92+
3. In n8n, create a new credential for the YepCode node
93+
4. Paste your API token
94+
5. (Optional) Set a custom API host for YepCode On-Premise
95+
96+
### Using Run Process Operation
97+
98+
1. **Add the YepCode node** to your workflow
99+
2. **Select "Run Process"** as the operation
100+
3. **Choose your process** from the dropdown (searchable)
101+
4. **Configure parameters** using the resource mapper to map n8n data to process inputs
102+
5. **Set execution mode**:
103+
- **Run Once for All Items**: Process all items together
104+
- **Run Once for Each Item**: Process each item individually
105+
6. **Configure advanced options** (optional):
106+
- Enable/disable n8n context integration
107+
- Select specific process version
108+
- Set synchronous/asynchronous execution
109+
110+
### Using Run Code Operation
111+
112+
1. **Add the YepCode node** to your workflow
113+
2. **Select "Run Code"** as the operation
114+
3. **Write your code** in the code editor (JavaScript or Python)
115+
4. **Set execution mode**:
116+
- **Run Once for All Items**: Process all items together
117+
- **Run Once for Each Item**: Process each item individually
118+
5. **Configure advanced options** (optional):
119+
- Specify language (auto-detected by default)
120+
- Enable/disable n8n context integration
121+
- Set code cleanup options
122+
123+
**Example JavaScript Code:**
124+
```javascript
125+
// Import any npm package - YepCode will install it automatically
126+
const { DateTime } = require("luxon");
127+
128+
const { n8n } = yepcode.context.parameters;
129+
130+
const results = [];
131+
for (const item of n8n.items) {
132+
results.push({
133+
...item.json,
134+
processedAt: DateTime.now().toISO(),
135+
transformed: item.json.data * 2
136+
});
137+
}
138+
139+
// Access n8n metadata
140+
console.log("Environment:", n8n.metadata);
141+
142+
return results;
143+
```
144+
145+
**Example Python Code:**
146+
```python
147+
# Import any PyPI package - YepCode will install it automatically
148+
from datetime import datetime
149+
150+
# Access n8n context
151+
n8n = yepcode.context.parameters['n8n']
152+
153+
results = []
154+
for item in n8n['items']:
155+
# Process each item
156+
processed_item = {
157+
**item['json'],
158+
'processed_at': datetime.now().isoformat(),
159+
'status': 'completed'
160+
}
161+
results.append(processed_item)
162+
163+
# Access n8n metadata
164+
print("Environment:", n8n['metadata'])
165+
print("Execution ID:", n8n['metadata']['$execution']['id'])
166+
167+
return results
168+
```
169+
170+
### Accessing n8n Context
171+
172+
Both operations can include n8n context data in your YepCode execution:
173+
174+
- **Input Items**: All data from previous nodes in your workflow
175+
- **Workflow Metadata**: Environment variables, execution information, and workflow details
176+
- **Execution Context**: Current execution ID, resume URLs, and other runtime information
177+
178+
### Error Handling
179+
180+
- **Continue on Fail**: Enable this option to continue workflow execution even if YepCode operations fail
181+
- **Error Information**: Failed executions return detailed error information in the output
182+
- **Logs**: Access execution logs through the YepCode dashboard or API
183+
184+
For more information on using n8n community nodes, see the [n8n documentation](https://docs.n8n.io/integrations/#community-nodes). If you are new to n8n, you can get started with the [Try it out](https://docs.n8n.io/try-it-out/) guide.
38185

39186
## Resources
40187

41188
* [n8n community nodes documentation](https://docs.n8n.io/integrations/#community-nodes)
42189
* [YepCode official docs](https://docs.yepcode.io/)
190+
* [YepCode Coding Rules](https://yepcode.io/docs/yepcode-coding-rules)

nodes/YepCode/YepCode.node.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ export class YepCode implements INodeType {
6565
methods = { loadOptions, resourceMapping };
6666

6767
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
68-
const items = this.getInputData();
6968
let returnData: INodeExecutionData[] = [];
7069
const operation = this.getNodeParameter('operation', 0);
7170

7271
switch (operation) {
7372
case 'run_process':
74-
returnData = await runProcess.execute.call(this, items);
73+
returnData = await runProcess.execute.call(this);
7574
break;
7675
case 'run_code':
77-
returnData = await runCode.execute.call(this, items);
76+
returnData = await runCode.execute.call(this);
7877
break;
7978
default:
8079
throw new NodeOperationError(

0 commit comments

Comments
 (0)