# Price-monitor receiver laboratory (v1)

Node 22, no npm dependencies. Files must remain together. The price and identifiers in the fixture are invented. No command here creates a Scraipe watch or sends an external alert.

1. Run `node --test monitor.test.mjs` (19 tests; temporary loopback listeners).
2. In one terminal run:

```sh
export SCRAIPE_WEBHOOK_SECRET='whsec_PUBLIC_TEACHING_KEY_DO_NOT_USE_IN_PRODUCTION'
node receiver.mjs config.example.json
```

3. In a second terminal in the same directory run `node demo.mjs` twice. The first response records a USD 1.50 drop; the second reports a duplicate. Inspect `inbox.jsonl`. Stop the receiver with Ctrl-C. The fixed fixture's timestamps are illustrative; the demo signs the original fixture bytes using the current clock.

If the journal already contains this fixture, both calls return duplicate. Keep that evidence; use a new empty working directory to repeat the first-acceptance experiment. The key above is public and must never protect real deliveries.

The receiver binds only to 127.0.0.1:8787 and accepts POST /hooks/scraipe. It verifies raw bytes, a five-minute timestamp window, watch identity and header/body correspondence. It records a proposed price-drop outcome, a review item or a no-alert outcome before returning 200. It does not send email, trade, make purchases or push alerts. Duplicate watch/run events do not append again; conflicting replays return 409. A failed append returns 503 and requires inspection/restart. An incomplete journal refuses startup.

This is a bounded single-process example, not a replicated production queue. It loads the journal in memory; it has no retention, rotation, backup, replay worker or downstream delivery system. Keep one writer per journal. For deployment, use an HTTPS ingress preserving raw request bytes, keep the secret in a secret manager, restrict the journal volume, add capacity limits/monitoring and implement a transactional inbox/outbox plus idempotent downstream worker. The local file flush is not a guarantee against host/disk failure. No exactly-once external delivery is claimed.

The policy handles one configured SKU and USD prices expressed as canonical strings such as "19.00". Currency changes, missing/ambiguous prices and row additions/removals require review. This is not a general money parser or exchange-rate converter.

A Scraipe webhook is attempted once. A 503 response does not cause an automatic retry. Inspect authenticated run history and reconcile missed events by watch/run ID; do not re-sign old untrusted bodies or relax the replay window. The API contract and full setup are at https://scraipe.co/learn/build-a-price-monitor-with-webhooks.
