Skip to main content

Functions

Functions let your app run custom business logic at well-defined points in the cart → checkout → order-placement pipeline. Unlike Extensions which add UI, functions return declarative JSON — operations, rates, discounts, errors — that the platform applies to the order on your behalf. Functions are sandboxed Javy dynamic-mode WASM modules. You compile them on your own machine with lms function build (which calls Javy / QuickJS) and upload the pre-built .wasm to the platform — the server validates the artifact and runs it during the cart-verify and order-placement phases. See CLI Setup → Local Function Compilation for the full build/test/deploy flow.

Function Types

Cart Transform

Update unit prices, merge lines into bundles, or expand a single line into multiple. Surfaces as cartTransformDiscount + per-entry cartTransformDiscounts[].

Discount

Apply order / line-item / shipping discounts with app-supplied labels. Surfaces as appDiscount + shippingDiscount with per-entry arrays.

Shipping Rate

Add custom shipping options alongside the merchant’s zones. Customer can pick from either.

Payment Customization

Hide, rename, or reorder payment methods. Enforced server-side at order placement.

Delivery Customization

Hide, rename, or reorder the merchant’s shipping zones. Enforced server-side at order placement.

Order Validation

Block the order entirely if it fails your rules — quantity caps, geo restrictions, compliance checks.

Fulfillment Constraints

Restrict which fulfillment locations can ship which lines. Blocks order placement if no location can fulfill a constrained line.

Local Pickup Options

Offer in-store / curbside pickup at merchant-owned locations as a delivery option in checkout.

Pickup Point Options

Offer carrier-operated parcel lockers and partner pickup points (DHL, UPS, InPost) as a delivery option.
There are exactly nine dispatched WASM function types (the cards above). A manifest may also declare declarative fulfillment_location_rule entries for order routing rules — JSON matchers that would pick a fulfillment location — but these are only parsed from the manifest; there is currently no backend dispatcher/consumer, so they do not execute at runtime yet. See Order Routing Rules for the manifest format and match operators.

Cross-cutting capabilities

Input field selection

Declare inputFields on a manifest entry to project the input down to only the REST fields your function needs. Faster dispatch, smaller WASM payloads.

Network access

Opt in with network_access: true plus an allowed_hosts allow-list to call external HTTP services from inside your function.

Function Manifest

Declare functions in your app’s app.json under extensions.functions[]:
lms function deploy reads the entry for --handle from your app.json and sends every field above with the upload, so the stored function always matches your manifest. A field you leave out of the manifest keeps the value already stored for that handle.

Execution Points

Functions that affect cart-time pricing or option lists fire on cart verification (cart/checkout preview) for parity. order_validation also runs at both points — it fires on cart verification (with step: 'cart') and again as the final gate at order placement (with step: 'review'). fulfillment_constraints is a final-gate check at order placement only. At placement the pickup functions run again to confirm the option the buyer chose is still offered and to take its fee from the function, not from the browser. Every dispatch of the same cart gets the same input at cart verification and at order placement (same totals basis, same address shape, same customer), so a rule that passes in the preview passes when the order is placed. When an order is rejected at placement (order_validation, fulfillment_constraints, or a hidden payment method / delivery option), no order is created, the stock it had reserved is released, and no orders/create webhook fires.

Common Input Shape

Every function receives a cart envelope with the same shape:
totalPrice is the merchandise subtotal: the line totals after line-level price changes (cart transforms), before shipping, taxes and order-level discounts, in cart.currency. subtotalPrice, cost.subtotalAmount and cost.totalAmount carry the same value (shipping, taxes and order-level discounts are settled after functions run). It is the same number at cart verification and at order placement, so a threshold rule (“hide COD above ₹5,000”, “free shipping over $50”) decides the same way in the preview and when the order is placed. A cart_transform function sees the subtotal before its own changes. deliveryGroups is present when the buyer has picked a delivery option (always at order placement). It is not sent to shipping_rate and pickup functions — their output is what the buyer chooses from. Different function types receive different extras (destination, paymentMethods, shippingAddress, customer, deliveryOptions, discountCodes) — see each type’s page.
All monetary values are in display currency units, not cents. price: 19.99 means ₹19.99 / $19.99. Same convention for everything your function returns — with one exception: app-provided shipping amounts (shipping_rate output prices, pickup-option fees) are in minor units (cents) per the Carrier-Service contract (price: 599 = ₹5.99). See Shipping Rate.When the buyer pays in another currency, input amounts are already converted: (store price × exchange rate) × (1 + conversion fee), kept at that currency’s own precision (cents; whole units for JPY-style currencies). They are the amounts the checkout charges.
Beyond cart, every function input carries:
  • shop: { id, storeId, domain, storeURL, domainSlug, currency } — the store the dispatch belongs to (currency is the store’s base currency; cart amounts are in cart.currency).
  • settings — the merchant’s configured values for this installation of your app.
  • customer — when the buyer is signed in: { id, gid, email, metafields } (at cart verification as well as at order placement).
shop and settings are always included, even when inputFields projects the rest of the input.
Addresses (shippingAddress, destination) and cart.localization.country carry the country as an ISO-3166-1 alpha-2 code ("IN", "US", "LA"), with countryCode set to the same code and countryName holding the name as the buyer saw it ("India"). A country the platform cannot resolve is passed through as entered.

Output Format

Each function type has its own output. Browse the dedicated pages for the full contract — quick reference:

Persistence

For monetary outputs (cart_transform deltas, discount entries) the platform persists both:
  • Summed scalars on additionalFields (e.g. appDiscount, shippingDiscount, cartTransformDiscount) — backwards compatible.
  • Per-entry arrays on additionalFields (e.g. appDiscounts[], shippingDiscounts[], cartTransformDiscounts[]) — used to render one row per app-supplied label on cart, checkout, order page, and email receipts.
Every entry is stamped with appId so the merchant can attribute revenue back to your app in reporting.

Testing

  1. Local sandbox — lms function test -f src/function.js -t <type> --input-file fixtures/cart.json compiles your source locally and runs it against the hosted sandbox without persisting anything. The fastest way to iterate on cart-transform, shipping, payment, delivery, and order-validation logic.
  2. Pre-built artifact — lms function test --wasm dist/function.wasm uploads a .wasm you’ve already compiled (useful in CI where you build once and reuse).
  3. Live storefront — install your app into the Apps developer portal, then place a real order. The platform runs the same dispatch for both the cart preview and final order placement.

Rate Limits & Constraints

  • Execution timeout (WASM), per function type: HTTP endpoint functions use the entry’s timeout (default 5 s).
  • Daily quota: 10,000 executions per store per function type per day. When the quota is exhausted the dispatch returns 429 and the functions of that type are skipped for the rest of the day (UTC).
  • Function-list cache: the store’s installed-function list is cached for 60 s — a fresh install/uninstall or a new deploy can take up to a minute to be picked up by the dispatch path.
  • WASM size cap: 256 KB compiled.
  • Output size cap: 20 KB of JSON written to stdout. Larger output is a failed run (see below).

Failure mode

A function fails when it times out, throws, exceeds the output cap, or returns output that does not match its type’s contract. A failure affects only that function: every other app’s function of the same type still runs and still applies, and the failure is recorded on the function’s run log (lms function logs <handle>). The buyer never sees the technical error. What the failed function contributes depends on its fallback: In a dispatch response the failed entry carries failed: true and its fallback.
WASM runtime limits. Functions ship as Javy dynamic-mode WASM modules with a 256 KB compiled-WASM cap and a shared QuickJS provider loaded once per worker. The WASM source patterns and bundle-size constraints work for any standard Javy or AssemblyScript build.

HTTP endpoint mode

Instead of a WASM entrypoint, a function entry may declare an endpoint URL — the platform POSTs the same input JSON to it (after inputFields projection, with shop and settings) and applies the returned output exactly as it would a WASM function’s. ${APP_URL} in the endpoint is replaced with your app’s URL; a path starting with / is resolved against the store’s storefront origin. Authenticating the dispatch. Every HTTP dispatch carries: Your endpoint is a public URL — verify the signature before acting on a request, or anyone can POST a synthetic cart and read back the merchant’s rule configuration. Identify the store from shop.storeId (or shop.domainSlug) in the body, load the access token you stored for it, and compare:
Hash the bytes you received — re-serializing the parsed JSON changes them. When the access token rotates (reinstall, token refresh), the signature follows the new token.

Why 256 KB is enough

Functions compile in Javy dynamic mode: your JavaScript is bundled as a thin stub (typically 1–4 KB) that imports the shared QuickJS runtime (“provider”) at execution time. The provider is loaded once per worker and reused across every function, so each compiled function only carries your code — not a copy of the runtime. For comparison: a 500-line discount function compiles to roughly 3 KB, two orders of magnitude under the cap. If your function approaches 256 KB you’re probably bundling unnecessary dependencies — strip them out rather than asking for a higher cap.

Active-Install Caps Per Shop

A store can have at most N active apps contributing functions of the same type. The cap is enforced when an app is installed — both merchant install and the OAuth token exchange reject the install with HTTP 409 if it would push the store over the cap — and when an installed app starts contributing a type it did not have (a new function deployed with lms function deploy, or extensions.functions edited): that change is rejected with 409 if any store the app is installed on is already at the cap for the type. The dispatch site runs every active function of a given type on every cart verification / order placement — without these caps a store could end up with compounded discounts, hidden payment methods, or unbounded cart_transforms. To install a new app of a type that’s already at the cap, uninstall an existing one first. See Function Active Limits.
An app that declares functions across multiple types counts once per type toward the relevant cap. E.g. an app shipping one cart_transform and one discount function consumes one slot of each.

Best Practices

Cart / checkout latency is conversion-critical. Time-bounded work only — no carrier-API calls without aggressive caching.
Functions re-run on every cart change. Derive your output from the current input + config, not from cached deltas — otherwise you’ll double-apply discounts or operations.
Customer-facing labels (message, title, rate name) become the visible row in cart, checkout, and the order page. Use clear, branded text — “VIP: 15% off” beats “Discount applied”.
Function code is not versioned per installation: every store that has your app installed runs the function you deployed last (within the 60 s function-list cache), whatever app version the store is on or pinned to. App versions and pinning govern the extensions deployed to a store (blocks, embeds, admin and checkout extensions), not function code. Test with lms function test and on a development store before lms function deploy.