Skip to content

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

Usage
snizu function init <dir> --target discount|delivery|payment|routing --lang rust|js [--title "…"]

Flags

  • <dir>pathrequired
    Where to write it. Made when it doesn't exist.
  • --targetdiscount | delivery | payment | routingrequired
    What it changes: discounts on the cart, the delivery options shown, the payment methods shown, or the branch an order ships from.
  • --langrust | jsrequired
    Rust, built with Cargo, or JavaScript, built with Javy.
  • --titletext
    Its name in the admin. The folder's name by default.

What it writes

  • snizu.function.json
    Its title, target and language, which the other function commands read.
  • sample.json
    An input its target reads: an Egyptian cart in EGP, with the delivery options, payment methods or branches the target gets.
  • src/main.rs, Cargo.toml
    For Rust: serde_json, and a release profile that keeps the module small.
  • index.js
    For 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:

index.js
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

Terminal
$ 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.json

Was this page helpful?

Updated 25 Nov 2026