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 appliesevents: Array of actions to take when conditions are met
Optional Fields
facts: Named calculations for reuse in conditions and eventsif-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
Multiple Conditions (AND)
OR Logic
Available Predicates
| Predicate | Description | Example |
|---|---|---|
equal, eq, is | Exact match | "customer.email": { "is": "user@example.com" } |
includes, contains | Array contains value | "customer.tags": { "includes": "VIP" } |
gt, greater | Greater than | "cart.totalAmount": { "gt": 100 } |
gte, greaterEq | Greater than or equal | "cart.totalAmount": { "gte": 100 } |
lt, less | Less than | "cart.lineCount": { "lt": 5 } |
lte, lessEq | Less than or equal | "cart.lineCount": { "lte": 10 } |
exists | Field exists | "customer.id": { "exists": true } |
empty | Array/string is empty | "customer.tags": { "empty": false } |
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
$ 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
Input Data Structure
Function Lab receives cart and customer data from Shopify in a standardized format:Path Notation
Access nested data using dot notation:| Path | Accesses |
|---|---|
customer.email | Customer’s email address |
customer.tags | Array of customer tags |
cart.lines | Array of cart line items |
cart.lines[].merchandise.product.handle | Product handles for all lines |
Array Access
Arrays are automatically traversed:Execution Flow
- Input Received: Shopify sends cart/checkout data
- Facts Computed: Named calculations evaluated once
- Conditions Evaluated: Check if rule should fire
- Events Executed: Generate discounts/operations
- Output Returned: Results sent back to Shopify
Next Steps
- How It Works - Detailed execution model
- Testing - Test and debug your functions
- Common Patterns - Real-world examples
- Function Types - Explore specific function types
