ExShopifyApp.AppEvents.TokenServer (ex_shopify_app v1.2.0)
Caches a Shopify App Events access token in a supervised GenServer.
It serializes and caches whatever its :fetcher returns, applying an early-refresh
skew so the token is never used at the edge of expiry. By default it caches the App
Events client_credentials JWT via ExShopifyApp.AppEvents.fetch_token/0.
Started automatically under ExShopifyApp.Application, so host apps need no setup.
Because every request goes through this single process, concurrent first-callers
coalesce onto one token fetch rather than each hitting the token endpoint — the
refresh is serialized for free, with no global VM state.
This is the default ExShopifyApp.AppEvents.TokenCache implementation. Host apps that
prefer non-blocking reads can swap in their own (e.g. a Cachex/ETS TTL cache) via
config :ex_shopify_app, :app_events, token_cache: MyApp.TokenCache.
Summary
Types
Fetches a fresh token, returning {:ok, token, expires_in_seconds} or
{:error, reason}.
Functions
Returns a specification to start this module under a supervisor.
Returns a valid cached token, fetching and caching a new one if needed.
Clears the cached token. Primarily useful for resetting state between tests.
Starts the server.
Types
@type fetcher() :: (-> {:ok, String.t(), non_neg_integer()} | {:error, any()})
Fetches a fresh token, returning {:ok, token, expires_in_seconds} or
{:error, reason}.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec fetch(GenServer.server()) :: {:ok, String.t()} | {:error, any()}
Returns a valid cached token, fetching and caching a new one if needed.
@spec reset(GenServer.server()) :: :ok
Clears the cached token. Primarily useful for resetting state between tests.
Starts the server.
Options
:name- the registered name, defaults toExShopifyApp.AppEvents.TokenServer.:fetcher- a 0-arityfetcher/0, defaults to&ExShopifyApp.AppEvents.fetch_token/0.