# Clover events discovery — THROWAWAY

This folder is **not part of the regular test suite** and will be **deleted**
after we've captured the discovery output we need. Its sole purpose is to drive
Clover's iframe fields through scripted interactions while spying on:

- Every `change` / `blur` event the Clover SDK fires on each `CloverElement`,
  capturing **all enumerable keys** on the event object (not just `touched` /
  `error`) so we discover any `complete`, `empty`, `brand`, etc. flags.
- Every `postMessage` that reaches the parent window from a Clover iframe, so
  we see whether there's a richer internal channel we're not subscribing to.

## How to run

You need a working Clover sandbox PAKMS key + merchant UUID. The easiest source
is the WP plugin's connected dev environment — pull the values from the running
WP admin (the IntegrationSettings DB options) or from the dev-env vault.

```bash
cd packages/payment-fields

CLOVER_PAKMS=<your-sandbox-pakms-key> \
CLOVER_MERCHANT_ID=<your-merchant-uuid> \
  npx playwright test \
    -c tests/_discovery/playwright.config.ts \
    --reporter=list \
    --headed
```

`--headed` opens a browser window so you can watch the interactions — useful
the first time to confirm focus / typing actually lands in each iframe.

Optional: override the SDK URL with `CLOVER_SDK_URL` (defaults to
`https://checkout.sandbox.dev.clover.com/sdk.js`).

## Output

Each scripted step prints its own block to stdout:

```
══ FIELD: cardNumber
── STEP: type "4" ──
{"ts":...,"category":"change","field":"cardNumber","payload":{...}}
{"ts":...,"category":"postmsg","origin":"https://...","data":{...}}
```

Paste the full output back into the Claude conversation; we use it to:

1. Design the deferred-error logic in `ValidationMachine`.
2. Decide whether we can natively validate `cardName` / `cardEmail`.
3. Write the "Events & Validation" section of `README.md`.

## Cleanup

Once we've captured what we need:

```bash
rm -rf tests/_discovery
```

`git status` should show no remaining discovery artifacts before committing.
