Skip to main content

Source code

Using the YepCode editor, users can provide the code to implement the process.

Depending on the language selected, the script will be executed in a different engine:

  • JavaScript We use the NodeJS v16 engine, so you can use almost every function that NodeJS supports. Code is wrapped in an `async` function so you can use `await` throughout the function.
  • Python We use the Python v3 engine, so you can use almost every function that Python supports.

The most interesting components to be used in this source code are the integrations. One integration is backed by a NodeJS or Python package that allows to use some external service inside YepCode processes, having some initialization configuration to avoid to have any kind of credentials in your source code.

If you don't like to reinvent the wheel, just have a look to the included libraries to take advantage of them in both languages.

As you shouldn't like the spaghetti code, we have included a module to create and use your own Modules.

The source code editor supports key shortcuts, code formatting and autocomplete features. The autocomplete is configured to take advantage of the included integrations, so if you start to type YepCode..., you'll see some useful snippets.

Snippets code are available

The snippets included in the autocomplete feature are the same ones that are documented in the integrations docs page.

The process source code would be executed in a secuential approach.

tip

In JavaScript versions, every process execution would wait while any active promise is still running

As in any other script, you could define functions and structure your code with good practices, so please use clean code.

Internal helpers

YepCode allows to use some info of the current execution in your process.

Access to execution and process info

The base information, what is available for all executions is the id of the current execution, the comment (if you wrote it) and the id and name of the process what is been executed. The code to obtain them would be this:

const { id, comment } = yepcode.execution;

const { id: processId, name: processName } = yepcode.execution.process;

Access to scheduled process info

When you schedule a process you also have access to the id of the schedule and to its comment (if it exists). The code to obtain them would be this:

const { id: scheduleId, comment: scheduleComment } = yepcode.execution.schedule;

An interestion use case to use this information could be to build the exact execution link in order to send it by email:

const executionLink = `https://cloud.yepcode.io/{your-team-slug}/executions/${yepcode.execution.id}`;

Access to team timezone

You can access the current timezone you have set in your team. The code to do it would be:

note

The team timezone will also be the timezone used for any date manipulation in the execution.

const timezone = yepcode.team.timezone;

Return value

YepCode allows your processes to return a value. This is very insteresting in case that you are starting executions using webhooks or forms, as you could manage this result value in your client. The syntax to return one object would be:

return { message: "Hello from YepCode!" };

You can see it in the execution detail page, and also enjoy it with sync webhooks feature.

Return custom status codes

Custom status code and a custom message are also supported. This is useful in many cases, but the most common one is probably error handling. For example if you want to return a 404 error, but you don't want the execution to end in one error status.

In order to do that, you just need to return an object with the following structure:

try {
// simulate an error
throw new Error("Oops! Something went wrong.");
} catch (e) {
return {
status: 418,
body: {
error: {
message: e.message,
stack: e.stack,
},
},
headers: {
"X-Custom-Header": "I am a custom header",
},
};
}

The magic are in status, body and headers properties.

tip

You can return a json or plain string as body. The Content-Type header will be set automatically.

Transient return values

In some cases you may want to not store the return value of your process. For example, when sensitive data is returned.

For this case, YepCode allows you to set a result as transient, so this result is not stored in database.

For these cases, the stored result will be the [transient] replacement.

tip

If you call your process by a webhook in sync mode you will be able to get the result in that call.

To make a result transient, just follow this structure:

return {
isTransient: true,
body: { foo: "bar" },
};

Of course, you can combine this with previous shown properties. An example:

return {
isTransient: true,
status: 201,
body: { foo: "bar" },
headers: {
"X-Custom-Header": "I am a custom header",
},
};