# JAUS Event-Ready — five Shopify Flow recipes

All five use the free Shopify Flow app. Where a step says "Send email", use Shopify Email, Klaviyo (Flow connector) or a plain "Send internal email" action. Metafields referenced are in the `jaus` namespace (see `metafield-definitions.json`).

---

## 1. Back-in-size alert

**Goal:** when a variant that customers asked for comes back in stock, tell them — same day, once.

**Capture (theme):** the "notify me" link on a sold-out size (Fit Confidence block / Finder empty state) opens a Shopify Forms form with hidden fields `variant_id`, `product_handle`, `size`. Forms creates a customer (or updates one) and applies the tag `bis:<variant_id>`.

**Flow**
1. Trigger: *Inventory quantity changed*.
2. Condition: `inventoryLevel.quantityAfterChange > 0` **and** `inventoryLevel.quantityBeforeChange <= 0` (restock, not a sale).
3. Action: *Get customer data* — query `tag:bis:{{ inventoryLevel.item.variant.id }}`, max 100.
4. For each customer: *Send marketing email* (Shopify Email) or *Klaviyo → Track event* `Back in size` with `product_title`, `size`, `product_url`, `price`.
5. Action: *Remove customer tags* → `bis:{{ variant.id }}` so the alert fires once.
6. Action: *Add product tags* → `restocked` (feeds the Back in Stock collection) — remove it with recipe 3 after 14 days.

---

## 2. Try-on hold → boutique staff

**Goal:** an online shopper reserves a size at 311 E Maple for 48 hours; staff get one message with everything they need.

**Capture (theme):** the "Hold my size in Birmingham" button opens a Shopify Forms form: name, phone/email, product (hidden), size (hidden), preferred day. Forms creates the customer with tag `hold-request` and stores the fields as customer metafields (`custom.hold_product`, `custom.hold_size`, `custom.hold_day`).

**Flow**
1. Trigger: *Customer tags added* → contains `hold-request`.
2. Action: *Get inventory level* for the variant at the location `Birmingham boutique` (POS location).
3. Condition: available at boutique ≥ 1.
   - Yes → *Send internal email* (or Slack via webhook) to boutique@: "Hold {{ product }} size {{ size }} for {{ customer.name }} until {{ scheduledAt + 48h }}. Boutique stock: {{ quantity }}." Then *Send email to customer*: "We're holding size {{ size }} for you until {{ date }}. 311 E Maple Rd, Mon–Sat 10:30–6:30, Sun 12–5."
   - No → *Send internal email*: "Hold request for {{ product }} size {{ size }} — not at the boutique; {{ warehouse_qty }} at warehouse. Offer transfer or ship-to-store." Customer email: "We're checking the boutique for your size and will confirm within the hour."
4. Action: *Wait* 48 hours → *Remove customer tags* `hold-request` → internal email "Hold for {{ customer.name }} expires today."

---

## 3. Low-size alert to the buyer (and tag hygiene)

**Goal:** the buyer knows when a style is down to one size — before the listing becomes a dead end — and "restocked"/"new arrivals" tags expire on their own.

**Flow A — last size**
1. Trigger: *Inventory quantity changed*.
2. Action: *Get product data* for the variant's product, including all variants' `inventoryQuantity`.
3. Condition: count of variants with quantity > 0 equals 1.
4. Action: *Send internal email* to buying@: "{{ product.title }} is down to one size ({{ size }}, {{ qty }} left). Reorder or move to Outlet?" Add product tag `last-size` (used by a "Last chance" collection and to demote the style in the Finder sort).
5. Condition: count of variants with quantity > 0 equals 0 → *Remove product tags* `new arrivals, restocked, last-size`; *Add product tags* `sold-out`.

**Flow B — expire "new arrivals"** (scheduled)
1. Trigger: *Scheduled time* — daily 03:00.
2. Action: *Get product data* — query `tag:'new arrivals' AND created_at:<{{ scheduledAt | date_minus: 30 days }}`.
3. For each: *Remove product tags* `new arrivals`, `NEW`, `new`.
(Repeat with `restocked` and 14 days.)

---

## 4. "How did it fit?" — the fit feedback loop

**Goal:** every delivered dress asks one question; the answers roll into `jaus.fit_feedback` and, at a threshold, correct `jaus.fit_note`.

**Capture:** Stamped review request (already installed) with one custom question: *How did it fit?* — Small / True to size / Large. Stamped's Flow connector (or a webhook → Shopify Forms) posts the answer with the product id.

**Flow**
1. Trigger: *Stamped review created* (or *Form submitted*).
2. Action: *Get product data* → read `metafields.jaus.fit_feedback` (JSON `{"small":n,"true":n,"large":n}`).
3. Action: *Run code* (Flow's JavaScript step): increment the matching key; return the JSON and the new majority if total ≥ 10 and one answer ≥ 60%.
4. Action: *Update product metafield* `jaus.fit_feedback` with the JSON.
5. Condition: majority present and differs from `jaus.fit_note` → *Update product metafield* `jaus.fit_note` (`runs small` / `true to size` / `runs large`) and *Send internal email* to merchandising: "Fit note for {{ product.title }} changed to {{ new }} after {{ total }} answers."

---

## 5. New-product enrichment

**Goal:** the 4–5 products added every day get fit metafields without anyone remembering to add them.

**Flow**
1. Trigger: *Product created* (and *Product updated* where `descriptionHtml` changed — use a condition on `product.updatedAt` vs `createdAt` within 1 minute to avoid loops).
2. Action: *Send HTTP request* → `POST https://<worker-or-cron-host>/enrich` with `{ "id": "{{ product.id }}" }`. The endpoint runs `enrich.js`'s `parse()` on that one product and writes metafields via `metafieldsSet` (the script is already written to accept a single product).
3. Condition (response JSON): `fit_note` empty → *Add product tags* `needs-fit-note` → daily digest to merchandising via Flow B pattern above.
4. Nightly safety net: *Scheduled time* 02:00 → HTTP request `POST /enrich?since={{ scheduledAt | date_minus: 1 day }}` (bulk path in `enrich.js --since`).

---

### Notes
- All five flows are idempotent: tags are removed after use and metafields are overwritten, not appended.
- Nothing above sends a marketing message to a customer who did not ask for it: back-in-size and holds are opt-in forms; the fit question rides on the existing review request.
- Flow's *Run code* step limits: 5 s, 1 MB — the fit-feedback JSON is a few bytes.
