Alternera.Resource.Domain (alternera_resource_sdk v0.9.0)

Copy Markdown View Source

The Ash domain of a resource package: one per package, and its id names the package everywhere (the Postgres schema resources_<id>, the resource names "<id>.<resource id>", the REST paths).

defmodule Finance.Resources do
  use Alternera.Resource.Domain, id: "finance"

  resources do
    resource Finance.Currency
  end
end

Options:

  • :id (required): ^[a-z][a-z0-9_]{0,30}$, unique in a build.
  • :sdk: the contract major the package is written against, the current one (Alternera.Resource.sdk_version/0) by default. The proxy refuses a package written against another.
  • :docs: the package's page of the user guide, a Markdown file relative to the domain's source file. It is read at compile time and embedded, so the package carries it with no file at run time (__resource_package__/0's docs, nil without one). Its front matter needs title, section: Resource packages, order, summary and verified; the proxy appends a reference generated from the resources, and gates the page with the resources licence.
  • :authorize: whether a call on the package's resources may skip their policies. :always (the default): every call is authorised, and a call that passes authorize?: false is refused with Ash.Error.Forbidden.DomainRequiresAuthorization, so the policies decide whoever calls, the package's own UI included. :by_default: Ash's default, a call is authorised unless it says authorize?: false, for a package whose own code does work on the system's behalf. Work for the system under :always passes the system actor, %{system: true}, which the policy prefix lets through.

use expands to use Ash.Domain with AshJsonApi.Domain and AshPaperTrail.Domain and defines __resource_package__/0. The version resources are listed by Alternera.Resource.DomainExtension, not by AshPaperTrail's include_versions? (see that module for why). A package's domain is never in the proxy's ash_domains, so it does not ask to be.