Skip to main content

Core Concepts

Understanding the fundamental building blocks of Function Lab.

Overview

Function Lab configurations consist of rules that evaluate conditions and execute events. Optional facts enable complex data transformations.

Rules

A rule is the basic unit of logic in Function Lab.

Structure

Required Fields

  • conditions: Object defining when the rule applies
  • events: Array of actions to take when conditions are met

Optional Fields

  • facts: Named calculations for reuse in conditions and events
  • if-not-events: Alternative events when conditions don’t match

Conditions

Conditions determine when a rule should fire. They query the input data using dot notation and predicates.

Simple Condition

Checks if customer tags array includes “VIP”.

Multiple Conditions (AND)

Both conditions must be true (implicit AND).

OR Logic

Available Predicates

See Predicates Reference for complete list.

Events

Events define what happens when conditions match. Event structure depends on the function type.

Product Discount Event

Multiple Events

A rule can have multiple events:

Facts

Facts are named calculations that transform input data for reuse in conditions and events.

Basic Fact

The $ prefix references a fact in conditions.

Why Use Facts?

  • Reusability: Calculate once, use everywhere
  • Readability: Name complex expressions
  • Performance: Avoid redundant calculations
  • Power: Use JMESPath or custom filters for complex queries

Example: Collection Filtering

See Facts System for deep dive.

Input Data Structure

Function Lab receives cart and customer data from Shopify in a standardized format:
See Input Structure Reference for complete schema.

Path Notation

Access nested data using dot notation:

Array Access

Arrays are automatically traversed:
Checks if any tag equals “VIP” (automatic ANY semantics).

Execution Flow

  1. Input Received: Shopify sends cart/checkout data
  2. Facts Computed: Named calculations evaluated once
  3. Conditions Evaluated: Check if rule should fire
  4. Events Executed: Generate discounts/operations
  5. Output Returned: Results sent back to Shopify

Next Steps