Skip to main content

Source code

Using the YepCode editor, users can provide the JavaScript code to implement the process. This script will be executed in a NodeJS engine, so you can use almost every function that NodeJS supports.

Of course you can use Vanilla JS 😅, but if you don't like to reinvent the wheel, have a look to the included libraries to take advantage of them.

The most interesting components to be used in this source code are the integrations. One integration is backed by a NodeJS 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.

As you shouldn't like the spaghetti code, we have included a module to create and use your own JS 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, and every process execution would wait until any promise is still running.

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

Internal helpers

You may need to use some info of the current execution in your process.

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. A code to obtain them would be this:

const { id, comment } = yepcode.execution;

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

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

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

An example to use this would be to construct the exact execution link to send it by email:

const executionLink = `https://cloud.yepcode.io/sandbox/executions/${yepcode.execution.id}`;

Return value

YepCode allows your processes to have a return value. If you want your process to return a value you only need to... return a value! An example 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

You can return a custom status code and a custom message. This is useful in many cases, but the most common one is probably error handling.

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 from your process.

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",
},
};