YepCode Coding Rules
This file provides guidelines for LLMs to write JavaScript and Python code using YepCode's helpers
General Rules
- Follow the language-specific code style guidelines
- Handle errors appropriately and provide meaningful error messages (errors may be thrown for failed executions)
- Use logging for debugging and tracking execution state
- Validate input parameters when needed
- Use environment variables for sensitive data
- Use appropriate status codes for responses
YepCode processes parameters
- Each YepCode process has one script (index.js or main.py) and also a JSON Schema to define the dynamic input parameters (parametersSchema.json).
- During the execution, parameters can be accessed using the
yepcode.context.parameters
object. - If you see some hardcoded values in the code, suggest to change it to input parameters or to env vars.
JavaScript Rules
Code Structure (JavaScript)
- Use NodeJS v20 features
- Wrap code in async function for await support
- Export functions using module.exports for modules
- Use ES6+ features when appropriate
Code Template (JavaScript)
async function main() {
// Access input parameters
const { parameters } = yepcode.context;
// Your code here
// Return result
return { "message": "Success!" };
}
module.exports = { main };
Helpers Usage (JavaScript)
- Access execution info:
const { id, comment } = yepcode.execution;
- Access process info:
const { id: processId, name: processName } = yepcode.execution.process;
- Access schedule info:
const { id: scheduleId, comment: scheduleComment } = yepcode.execution.schedule;
- Access team timezone:
const timezone = yepcode.execution.timezone;
- Use environment variables:
const apiKey = process.env.API_KEY // (or yepcode.env.API_KEY);
- Import modules:
const { myFunc } = yepcode.import("module-name");
- Import specific version:
const { myFunc } = yepcode.import("module-name", "v1.0");
- Run another process:
await yepcode.processes.run("process-identifier", options);
Logging (JavaScript)
console.log('INFO message');
console.debug('DEBUG message');
console.info('INFO message');
console.warn('WARNING message');
console.error('ERROR message');
Dependencies Management (JavaScript)
- You may use external npm packages
- Just add the require statement to the code and the package will be installed automatically
- If package import name is different than the package name, you must use the the add-package comment:
// @add-package axios
const axios = require('axios');
Return Values (JavaScript)
Standard Return
// JavaScript
return { "message": "Success!" };
Custom HTTP Status Codes
- This is the format for custom HTTP status codes:
// JavaScript
return {
status: 404,
body: { "message": "Not found" },
headers: { "Content-Type": "application/json" }
Transient Results (JavaScript)
// JavaScript
return {
transient: true,
data: sensitiveData
};
Python Rules
Code Structure (Python)
- Use Python 3.12 features
- Define main() function for debugging support
- Use type hints when appropriate
- Follow PEP 8 style guidelines
Code Template (Python)
def main():
# Access input parameters
parameters = yepcode.context.parameters
# Your code here
# Return result
return { "message": "Success!" }
Helpers Usage (Python)
- Access execution info:
id, comment = yepcode.execution.id, yepcode.execution.comment
- Access process info:
processId, processName = yepcode.execution.process.id, yepcode.execution.process.name
- Access schedule info:
scheduleId, scheduleComment = yepcode.execution.get("schedule", {}).values()
- Access team timezone:
timezone = yepcode.execution.timezone
- Use environment variables:
api_key = os.getenv("API_KEY") # (or yepcode.env.API_KEY)
- Import modules:
my_func = yepcode.import_module("module-name")
- Import specific version:
my_func = yepcode.import_module("module-name", "v1.0")
- Run another process:
yepcode.processes.run("process-identifier", options)
Logging (Python)
print("INFO message") # Generates INFO level log
logger.debug("DEBUG message")
logger.info("INFO message")
logger.warn("WARNING message")
logger.error("ERROR message")
Dependencies Management (Python)
- You may use external npm packages
- Just add the require statement to the code and the package will be installed automatically
- If package import name is different than the package name, you must use the the add-package comment:
# @add-package requests
import requests
Return Values (Python)
Standard Return
return { "message": "Success!" }
Custom HTTP Status Codes
- This is the format for custom HTTP status codes:
return {
"status": 404,
"body": { "message": "Not found" },
"headers": { "Content-Type": "application/json" }
}
Transient Results (Python)
return {
"transient": True,
"data": sensitive_data
}