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.
The API
Section titled “The API”| Symbol | Role |
|---|---|
input | The value received on the input port |
vars | A read-only snapshot of the run variables |
__vars | A read / write view: get, set, has, delete, clear, keys, toObject |
console.log / .info / .warn / .error | Writes to the execution log |
fetch(...) | An HTTP call, routed by the firewall |
return | The value returned leaves on the result port |
The body is wrapped in an async function: return and await work at the top
level.
Example
Section titled “Example”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 };Built-in library
Section titled “Built-in library”Available as a global variable and through require(), with nothing to declare
in packages:
| Global | Package |
|---|---|
_, lodash | lodash |
moment | moment |
uuid | uuid |
nanoid | nanoid |
CryptoJS | crypto-js |
Ajv | ajv |
ajvFormats | ajv-formats |
chai, expect, assert | chai |
cheerio | cheerio |
xml2js | xml2js |
const signature = CryptoJS.HmacSHA256(input.corps, vars.secret).toString();return { signature };A require() on a module that is not available raises an explicit error.
Awaiting and calling
Section titled “Awaiting and calling”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.
External packages
Section titled “External packages”Declare them in packages (npm); they are bundled once then mounted offline.
Postman and Bruno compatibility
Section titled “Postman and Bruno compatibility”The same environment exposes the pm.* and bru.* layers — see
JavaScript code.