# `Shopifex.TokenRefreshLease`
[🔗](https://github.com/ericdude4/shopifex/blob/main/lib/shopifex/token_refresh_lease.ex#L1)

Cross-node lease used to serialize refreshes of Shopify's one-time-use
offline refresh tokens.

The lease lives in its own `shopifex_token_refresh_leases` table so the
Shopify HTTP request never holds a lock on the consumer's shop row or a
checked-out database connection. A crashed owner is recoverable after the
lease expires. As with any refresh-token rotation, a process crash after
Shopify accepts the token but before the new pair is persisted still
requires a fresh managed-install exchange.

Existing consumers of this branch must create the table before using expiring
offline-token refresh:

    create table(:shopifex_token_refresh_leases, primary_key: false) do
      add :shop_url, :string, primary_key: true
      add :owner, :string, null: false
      add :lease_expires_at, :utc_datetime_usec, null: false
    end

The lease is keyed by Shopify domain rather than the consumer schema's
primary key, so it works with integer IDs, binary IDs, and custom shop
schemas.

# `owner`

```elixir
@type owner() :: String.t()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
