# Emacron Store v1 authentication and ownership

This is an integration contract, not a grant. Current roles, packages, sender/payment readiness and saved policies still apply at each endpoint. The machine-readable authority is `store-api-v1.json`, generated from registered routes. Its per-operation `security` and `x-ownership` describe the exact audience.

| Audience | Proof | Permitted use | Never use |
| --- | --- | --- | --- |
| Public shopper | Saved Store slug, approved exact Origin for browsers | Published catalog, current advertised account methods and supported public policies | Guessed workspace/customer identifiers, staff keys |
| Customer | `X-Store-Customer` opaque session from this Store's verification | Own profile, identities, sessions, addresses, cart, orders, allowed requests, reviews, privacy/history | Another customer's ID/session, employee JWT |
| Checkout | Original `X-Store-Checkout` prepared bearer | Its reviewed checkout/status/placement/release and explicitly supported payment operations | A request UUID as proof, another checkout token |
| Receipt | Versioned unrevoked `X-Store-Tracking` bearer | Explicit receipt/status/payment/shipment reads only | Placement, payment creation, release or customer account authority |
| Merchant server | Private `Authorization: Bearer esm_…` scoped native key | Only advertised read scopes; issuer membership/roles/module/package/scope rechecked | Public browser, cookies, arbitrary staff API calls |
| Staff dashboard | Existing CRM session/workspace/member grants and record scope | Internal registered staff operations | Treating route inventory as merchant-key authorization |
| Provider webhook | Exact provider authentication and saved source identity | Provider's documented event contract | Customer/employee bearer as webhook proof |

Store customer identity is separate from CRM employees. An email/phone string is not ownership proof. Checkout `request_key` and resource IDs identify records/operations, never authenticate a user. Email/WhatsApp OTP requires Store plus the relevant channel package, a connected authorised sender, supported approved template where needed, and enforced budgets. Unknown provider quota is explicit, not unlimited.

## Money, dates and pagination

Use integer minor-unit strings with the returned currency exponent. Keep currencies separate and never infer FX. Dates/timestamps include their documented timezone or UTC offset. Period ends marked `end_date_exclusive` are excluded. Page numbers start at0; use endpoint-specific maximum/page size and `has_more`. Snapshot-paged request history requires the original `as_of` when documented. Do not turn a missing total or unavailable cost into zero.

## Deliberate writes and uncertainty

Prepare and retain the exact payload, private proof and request identity before a deliberate write. Obtain confirmation of the server-reviewed facts. The SDK never automatically retries writes. After timeout, network loss,503 or ambiguous response, read owned saved status/history and deliberately retry the same payload/key if supported. Never generate a fresh order/payment/request identity just because a response was lost.409 means re-read state; some endpoints return `definitive_rejection`, otherwise assume an uncertain result.429 may include Retry-After; respect it without inferring provider allowance.

## Browser and SSR/BFF boundaries

Approved origins are exact canonical HTTPS origins, not URL prefixes/wildcards. Local HTTP development is limited to localhost/127.0.0.1. Shopper requests omit cookies; custom header sessions remain required. CORS is not authentication and server-to-server clients still need the relevant proof. Merchant keys never belong in customer JavaScript, HTML, analytics, localStorage, URLs or shared logs.

A same-origin BFF may hold a customer session in a Secure HttpOnly SameSite cookie, but must implement its own login/session binding, CSRF validation, logout/revocation and no-store responses. Do not expose an unrestricted API proxy, accept a caller's arbitrary upstream URL, forward employee Authorization, or treat Referer as proof. The downloadable example helper accepts only the explicit allowlisted owned read operations and an already-validated server-side customer session; it is not an authentication/session implementation.

## Evolution

Contract major1 is additive. SDK1.3.0 adds owned complaint/thread/photo methods alongside exchange and account-notice methods; existing methods retain semantics. No deprecation is scheduled. Incompatible changes require a new major with published migration/sunset information. Staff/provider inventories are separate from the supported shopper/server API surface. Unsupported carriers, digital entitlements, store credit or FX are never enabled by a schema or a UI label.


## Store complaints and CRM references

A current same-Store customer session and confirmed owned order are required. New complaints require Store and CRM packages; customer identity fields in a request never authorise another record. Complaint messages and evidence remain private, and internal CRM notes never enter customer responses. Staff require both current Support ticket and Store order scope. An explicit uniquely verified contact and optional Inbox reference preserve existing owner/category/campaign facts. The optional reference is stored separately from channel ticket routing: it never changes chat AI state or copies channel messages into a Store thread. Customer replies do not automatically send email/WhatsApp.

## Customer-owned Store credit

`GET /api/shop/{slug}/customer/credit` and `GET .../credit/{id}/entries` require the current same-Store customer session. `POST .../credit/redeem` settles a whole owned unpaid manual order with sufficient same-currency unexpired credit and the saved order version. Prepare one `request_key` before submission. After uncertainty retain that exact identity, read the order and ledger, and explicitly retry only the original operation. The SDK methods are `customerCredit`, `customerCreditEntries`, `prepareCreditPayment`, and `payWithCredit`. Credit is merchant-issued to a verified customer; transferable/purchasable gift codes, mixed tender and cash withdrawal are unavailable. Refunds use the original credit debit and account; they never invoke a payment-provider refund or restock automatically.
