snizu function init
Write a function that works, in Rust or JavaScript, with a sample of the input its target reads. A function changes discounts, delivery options, payment methods or which branch ships an order.
Node 22+1 min read
Usage
snizu function init <dir> --target discount|delivery|payment|routing --lang rust|js [--title "…"]Flags
<dir>pathrequiredWhere to write it. Made when it doesn't exist.--targetdiscount | delivery | payment | routingrequiredWhat it changes: discounts on the cart, the delivery options shown, the payment methods shown, or the branch an order ships from.--langrust | jsrequiredRust, built with Cargo, or JavaScript, built with Javy.--titletextIts name in the admin. The folder's name by default.
What it writes
snizu.function.jsonIts title, target and language, which the otherfunctioncommands read.sample.jsonAn input its target reads: an Egyptian cart in EGP, with the delivery options, payment methods or branches the target gets.src/main.rs, Cargo.tomlFor Rust:serde_json, and a release profile that keeps the module small.index.jsFor JavaScript: reads standard input with Javy and writes the answer.
How a function runs
A function reads JSON on standard input and writes JSON on standard output. It has no network, files, clock or randomness, so everything it needs is in its input. Amounts are in minor units: subtotal: 30000 is 300.00 EGP.
The discount function it writes takes 10% off orders over 200.00:
function run(input) {
// 10% off an order over 200.00.
const discounts = input.cart.subtotal >= 20000
? [{ title: "10% off", value: { percentage: 10 }, target: "order" }]
: [];
return { discounts };
}The other targets start with { "operations": [] }, which changes nothing: hide, rename or move options, methods or branches by their id there.
Examples
$ snizu function init big-basket --target discount --lang js
✓ Wrote a discount function in /home/salma/big-basket.
Next: snizu function build, then snizu function run --input sample.jsonWas this page helpful?
Updated 25 Nov 2026