# Workflow Rescue Demo

This is a small, privacy-safe lead intake quality gate for a local demo. It
normalizes case IDs, email, source, and request text; rejects missing or
malformed input; identifies duplicate `email + request` pairs within one
batch; and returns a next action for every row. It does not send an API
request, write to Google Sheets or a CRM, or send a customer brief.

## Run locally

Run the packaged demo from this directory with Node's standard library only:

```sh
node run-demo.mjs
```

`run-demo.mjs` reads the small `fixture.json`, runs the same normalization and
quality gate contract, and exits non-zero if the output differs from
`expected-results.json`. The CSV is included for spreadsheet inspection; the
deterministic receipt is in `receipt.md`.

## n8n handoff

Import `working-n8n-quality-gate.json` into the user's n8n instance if an n8n
runtime is wanted. It is intentionally `active: false`, has no credentials,
and only uses a webhook, Code node, and Respond to Webhook node. The demo
accepts either one row as the webhook JSON body or `{ "rows": [...] }`.
The user's own webhook URL, Google Sheets/CRM nodes, credentials, activation,
retry policy, and handoff procedure still need to be configured by the user.

The Code node follows the same normalization, validation, batch duplicate key,
safe-export, result categories, and receipt contract as the TypeScript fixture.
code-node fixture checked, n8n import/runtime not verified. This sentence is a
scope boundary: no live n8n engine claim is made.

## Verification level and boundaries

- Verified locally with the packaged Node demo and Python standard-library
  assertions (see `test_workflow_rescue_demo.py` in the repo).
- Synthetic addresses use `example.com`; no customer personal information is
  included.
- Duplicate detection is per batch only and is not permanent idempotency.
- Results are deterministic for the same input and the input rows are not
  mutated; the focused test freezes the Node input and compares it after
  execution.
- This is a code-node fixture demo. It is not proof of customer delivery,
  revenue, a live n8n engine run, CRM/Sheets persistence, or external API
  sending.

## Source provenance

The package preserves the field and follow-up vocabulary from
`public/open/lead-response-template.csv` (`case_id`, `next_action`, ownership
and duplicate handling) and the webhook → Code → response shape from
`gumroad-product/72h-automation-package/sample/lead-quality-gate.n8n.json`.
Those source files were read and used as structural references; neither source
file was modified. The validation rules and batch result contract here are
new demo logic and remain intentionally credential-free.
