# Native Store event webhooks v1

These private dashboard endpoints require an active Store package, owner/admin membership, Store and Settings permissions, all-record scope and current workspace/module access. They are not public shopper or Store API-key routes. Use the dashboard's authenticated client; do not put an employee token in your shopper frontend. Shopify/WooCommerce/Razorpay incoming provider callbacks are separate.

Administration base: `/api/store/native/webhooks`.

- GET base: saved endpoints (no signing secret), supported event names, signature/privacy contract.
- POST base: `{id,request_key,version:0,confirmed:true,action:"create",target,events,secret}`. Generate separate UUIDs for endpoint and operation. Secret is cryptographically random32 bytes encoded as64lowercasehex; HMAC uses that64-character string, not the decoded bytes. Preserve the exact request and secret until the outcome is known.
- POST `/:id`: `{request_key,version,confirmed:true,action:"pause"|"resume"|"rotate"}`. Rotation additionally needs a new secret. Version is the current saved version. An uncertain response must retry the identical operation, not create another endpoint or generate another key.
- GET `/deliveries?page=0`: fixed25-row pages with redacted states, attempts, last HTTP status and retry eligibility. No response bodies, contact/address details, order receipt/session tokens or key readback.
- POST `/deliveries/:id/retry`: `{confirmed:true}`. Eligible failed/exhausted/paused receipt, currently active subscription, lifetime20-attempt maximum. Event and delivery identities stay unchanged. Read-only receipt refresh does not resend.

A receiving URL must use public HTTPS443 without embedded credentials, query or fragment. All DNS answers must be public; the validated IP is pinned to the connection. Redirects are never followed. Delivery rechecks the saving administrator's current role, permissions, module and Store package. No historical backfill on subscribe/resume; paused periods do not acquire historical events. Resume/rotation requires explicit current administrator review.

Events: `order.changed`, `payment.changed`, `shipment.changed`, `return.changed`, `refund.changed`, `product.changed`, `stock.changed`. They are recorded state changes, not proof of payment capture, delivery, refund execution or customer communication. Check `data.source_table` and current authorised resource details. A refund request transition does not establish that money moved. Stock changes do not grant access to warehouse balances or connect provider stock. Events include safe resource references/states, and recorded native order currency/total where applicable; never infer a customer identity from them.

Body: `{version:1,id,type,created_at,data}`. The timestamp header is the attempt's Unix timestamp, distinct from original event creation. Headers:

- `X-Emacron-Event-Id`: stable event UUID.
- `X-Emacron-Delivery-Id`: stable subscription/event delivery UUID.
- `X-Emacron-Timestamp`: Unix seconds.
- `X-Emacron-Signature`: `v1=<HMAC-SHA256 hex of timestamp + "." + exact raw body>`.

Receiver: bound raw body size before parsing; compare signatures in constant time, require the timestamp within300seconds, require body/header event IDs to agree, then transactionally deduplicate the event ID before applying business effects. Return2xx only after durable acceptance. Keep event IDs long enough to cover delayed/manual retries; events can be delivered more than once and out of order. Re-read current authorised state when required. Do not reconstruct balances by applying arbitrary status text. Never log signing secrets, customer tokens or raw private payloads.

Automatic failures stop after8attempts with bounded backoff. Manual recovery retains the lifetime budget. A lost acknowledgement may mean the receiver already processed the event. Concurrent leases and crash recovery preserve identity; they cannot promise exactly-once network delivery. Rotate/revoke in coordination with your backend and retain original order/financial histories. The UI never changes a customer order merely by retrying a webhook.

Reservation invalidation events can include an actual `expires_at`. Refresh authorised availability at that deadline even without a later event: passage of time is not a database mutation, so no fabricated expiry transition is emitted. Outbound events are invalidation/state facts, not a complete stock delta ledger.
