Skip to content

TypeScript code

TypeScript is the default language of the Code box. Type annotations are stripped at compile time, then the code runs in the QuickJS engine.

SymbolRole
inputThe value received on the input port
varsA read-only snapshot of the run variables
__varsA read / write view: get, set, has, delete, clear, keys, toObject
console.log / .info / .warn / .errorWrites to the execution log
fetch(...)An HTTP call, routed by the firewall
returnThe value returned leaves on the result port

The body is wrapped in an async function: return and await work at the top level.

interface Commande {
id: number;
montant: number;
statut: 'payee' | 'attente' | 'annulee';
}
const commandes = input as Commande[];
const payees = commandes.filter((c) => c.statut === 'payee');
const total = payees.reduce((s, c) => s + c.montant, 0);
console.log(`${payees.length} commandes payées, total ${total}`);
__vars.set('totalPaye', total);
return { nombre: payees.length, total };

Available as a global variable and through require(), with nothing to declare in packages:

GlobalPackage
_, lodashlodash
momentmoment
uuiduuid
nanoidnanoid
CryptoJScrypto-js
Ajvajv
ajvFormatsajv-formats
chai, expect, assertchai
cheeriocheerio
xml2jsxml2js
const signature = CryptoJS.HmacSHA256(input.corps, vars.secret).toString();
return { signature };

A require() on a module that is not available raises an explicit error.

const reponse = await fetch(`${vars.baseUrl}/sante`);
const corps = await reponse.json();
if (corps.statut !== 'ok') throw new Error(`état ${corps.statut}`);
return corps;

The call goes through the firewall like any other traffic, and it is interrupted when the run is stopped or when the timeout is exceeded.

Declare them in packages (npm); they are bundled once then mounted offline.

The same environment exposes the pm.* and bru.* layers — see JavaScript code.