defmodule MapkitJS do @moduledoc """ Elixir client for Apple MapKit JS token generation. MapKit JS uses an ES256 JWT that your web app passes to `mapkit.init/1`. This library focuses on generating and caching that JWT. The public surface is intentionally small: MapkitJS.token() MapkitJS.generate_token(origin: "https://example.com") MapkitJS.authorization_callback_payload() ## Configuration config :mapkit_js, team_id: System.get_env("APPLE_TEAM_ID"), key_id: System.get_env("MAPKIT_KEY_ID"), private_key: System.get_env("MAPKIT_PRIVATE_KEY"), origin: System.get_env("MAPKIT_ORIGIN") Every function also accepts per-call `opts` that override the application config. """ alias MapkitJS.{Config, Token} @type opts :: keyword() @doc "Return a MapKit JS JWT using the configured token cache behavior." @spec token(opts) :: {:ok, String.t()} | {:error, term()} def token(opts \\ []) do Token.access_token(opts) end @doc "Generate a new MapKit JS JWT." @spec generate_token(opts) :: {:ok, String.t()} | {:error, term()} def generate_token(opts \\ []) do Token.generate_jwt(opts) end @doc "Return the payload commonly passed into a browser-side `authorizationCallback`." @spec authorization_callback_payload(opts) :: {:ok, map()} | {:error, term()} def authorization_callback_payload(opts \\ []) do config = Config.load(opts) with {:ok, token} <- token(opts) do {:ok, %{ token: token, expires_in: config.token_ttl_seconds, origin: config.origin }} end end end