AshDispatch.Resources.EmailEvent (AshDispatch v0.5.1)

View Source

Read-only Ash resource exposing email event metadata via RPC.

This resource provides structured access to all email events in the system without requiring a database table. It reads from the :ash_dispatch :event_modules config.

Features

  • Lists all registered email events with metadata
  • Provides template previews (HTML/text) in development
  • Exposes channel configuration (subject, timing, audience)
  • Shows event metadata (domain, category, user preferences)

Usage

Add this resource to your domain and configure RPC + authorization:

defmodule MyApp.Emails do
  use Ash.Domain,
    extensions: [AshTypescript.Rpc]

  typescript_rpc do
    resource AshDispatch.Resources.EmailEvent do
      rpc_action :list_email_events, :list
      rpc_action :get_email_event, :get
    end
  end

  resources do
    resource AshDispatch.Resources.EmailEvent do
      define :list_email_events, action: :list
      define :get_email_event, action: :get, args: [:id], get?: true
    end
  end
end

Note: Add authorization policies in your app's domain configuration.

Summary

Functions

Runs authorization checks for AshDispatch.Resources.EmailEvent.get See Ash.can/3 for more information

Runs authorization checks for AshDispatch.Resources.EmailEvent.get, returning a boolean. See Ash.can?/3 for more information

Runs authorization checks for AshDispatch.Resources.EmailEvent.list See Ash.can/3 for more information

Runs authorization checks for AshDispatch.Resources.EmailEvent.list, returning a boolean. See Ash.can?/3 for more information

Get a specific email event by ID

Get a specific email event by ID Raises any errors instead of returning them

Validates that the keys in the provided input are valid for at least one action on the resource.

Same as input/1, except restricts the keys to values accepted by the action provided.

List all email events

List all email events Raises any errors instead of returning them

Returns the query corresponding to the action.

Returns the query corresponding to the action.

Types

t()

@type t() :: %AshDispatch.Resources.EmailEvent{
  __lateral_join_source__: term(),
  __meta__: term(),
  __metadata__: term(),
  __order__: term(),
  action_required: term(),
  aggregates: term(),
  calculations: term(),
  category: term(),
  channel_count: term(),
  channels: term(),
  domain: term(),
  email_channel_count: term(),
  id: term(),
  module: term(),
  notification_type: term(),
  user_configurable: term()
}

Functions

can_get(actor, id, params_or_opts \\ %{}, opts \\ [])

Runs authorization checks for AshDispatch.Resources.EmailEvent.get See Ash.can/3 for more information

Options

  • :maybe_is (term/0) - If the actor may be able to perform the action, what value should be returned. The default value is :maybe.
  • :filter_with - If set to :error, the query will raise an error on a match. If set to :filter the query will filter out unauthorized access. Valid values are :filter, :error The default value is :filter.
  • :validate? (boolean/0) - Whether or not to treat an invalid action as a non-allowed action. The default value is false.
  • :reuse_values? (boolean/0) - Whether or not loaded data like aggregates, calculations and relationships should be checked in memory if possible, instead of querying. No effect if pre_flight? is false. The default value is false.
  • :pre_flight? (boolean/0) - Whether or not this is a pre_flight check (which may perform optimized in-memory checks) or the final proper check. The default value is true.
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol. Will overwrite any actor, tenant or context provided. See Ash.Context for more.
  • :run_queries? (boolean/0) - Whether or not to run queries. If set to true, :maybe will not be returned. The default value is true.
  • :data - The record or records specifically attempting to be acted upon.
  • :tenant (value that implements the Ash.ToTenant protocol) - The tenant to use for authorization
  • :alter_source? (boolean/0) - If set to true, the source being authorized is returned so it can be run. The default value is false.
  • :base_query (term/0) - A base query on which to apply an generated filters
  • :no_check? (boolean/0) - Whether or not authorization must pass at the strict/filter step, or if post-checks are allowed to be run The default value is false.
  • :on_must_pass_strict_check (term/0) - Override the value returned when no_check? is true but a check must be run.
  • :atomic_changeset (term/0) - A base query on which to apply an generated filters
  • :return_forbidden_error? (boolean/0) - Whether or not to return a forbidden error in cases of not being authorized. The default value is false.
  • :log? (boolean/0) - Whether or not to log the authorization result. The default value is false.

can_get?(actor, id, params_or_opts \\ %{}, opts \\ [])

Runs authorization checks for AshDispatch.Resources.EmailEvent.get, returning a boolean. See Ash.can?/3 for more information

Options

  • :maybe_is (term/0) - If the actor may be able to perform the action, what value should be returned. The default value is true.
  • :filter_with - If set to :error, the query will raise an error on a match. If set to :filter the query will filter out unauthorized access. Valid values are :filter, :error The default value is :filter.
  • :validate? (boolean/0) - Whether or not to treat an invalid action as a non-allowed action. The default value is false.
  • :reuse_values? (boolean/0) - Whether or not loaded data like aggregates, calculations and relationships should be checked in memory if possible, instead of querying. No effect if pre_flight? is false. The default value is false.
  • :pre_flight? (boolean/0) - Whether or not this is a pre_flight check (which may perform optimized in-memory checks) or the final proper check. The default value is true.
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol. Will overwrite any actor, tenant or context provided. See Ash.Context for more.
  • :run_queries? (boolean/0) - Whether or not to run queries. If set to true, :maybe will not be returned. The default value is true.
  • :data - The record or records specifically attempting to be acted upon.
  • :tenant (value that implements the Ash.ToTenant protocol) - The tenant to use for authorization
  • :alter_source? (boolean/0) - If set to true, the source being authorized is returned so it can be run. The default value is false.
  • :base_query (term/0) - A base query on which to apply an generated filters
  • :no_check? (boolean/0) - Whether or not authorization must pass at the strict/filter step, or if post-checks are allowed to be run The default value is false.
  • :on_must_pass_strict_check (term/0) - Override the value returned when no_check? is true but a check must be run.
  • :atomic_changeset (term/0) - A base query on which to apply an generated filters
  • :return_forbidden_error? (boolean/0) - Whether or not to return a forbidden error in cases of not being authorized. The default value is false.
  • :log? (boolean/0) - Whether or not to log the authorization result. The default value is false.

can_list(actor, params_or_opts \\ %{}, opts \\ [])

Runs authorization checks for AshDispatch.Resources.EmailEvent.list See Ash.can/3 for more information

Options

  • :maybe_is (term/0) - If the actor may be able to perform the action, what value should be returned. The default value is :maybe.
  • :filter_with - If set to :error, the query will raise an error on a match. If set to :filter the query will filter out unauthorized access. Valid values are :filter, :error The default value is :filter.
  • :validate? (boolean/0) - Whether or not to treat an invalid action as a non-allowed action. The default value is false.
  • :reuse_values? (boolean/0) - Whether or not loaded data like aggregates, calculations and relationships should be checked in memory if possible, instead of querying. No effect if pre_flight? is false. The default value is false.
  • :pre_flight? (boolean/0) - Whether or not this is a pre_flight check (which may perform optimized in-memory checks) or the final proper check. The default value is true.
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol. Will overwrite any actor, tenant or context provided. See Ash.Context for more.
  • :run_queries? (boolean/0) - Whether or not to run queries. If set to true, :maybe will not be returned. The default value is true.
  • :data - The record or records specifically attempting to be acted upon.
  • :tenant (value that implements the Ash.ToTenant protocol) - The tenant to use for authorization
  • :alter_source? (boolean/0) - If set to true, the source being authorized is returned so it can be run. The default value is false.
  • :base_query (term/0) - A base query on which to apply an generated filters
  • :no_check? (boolean/0) - Whether or not authorization must pass at the strict/filter step, or if post-checks are allowed to be run The default value is false.
  • :on_must_pass_strict_check (term/0) - Override the value returned when no_check? is true but a check must be run.
  • :atomic_changeset (term/0) - A base query on which to apply an generated filters
  • :return_forbidden_error? (boolean/0) - Whether or not to return a forbidden error in cases of not being authorized. The default value is false.
  • :log? (boolean/0) - Whether or not to log the authorization result. The default value is false.

can_list?(actor, params_or_opts \\ %{}, opts \\ [])

Runs authorization checks for AshDispatch.Resources.EmailEvent.list, returning a boolean. See Ash.can?/3 for more information

Options

  • :maybe_is (term/0) - If the actor may be able to perform the action, what value should be returned. The default value is true.
  • :filter_with - If set to :error, the query will raise an error on a match. If set to :filter the query will filter out unauthorized access. Valid values are :filter, :error The default value is :filter.
  • :validate? (boolean/0) - Whether or not to treat an invalid action as a non-allowed action. The default value is false.
  • :reuse_values? (boolean/0) - Whether or not loaded data like aggregates, calculations and relationships should be checked in memory if possible, instead of querying. No effect if pre_flight? is false. The default value is false.
  • :pre_flight? (boolean/0) - Whether or not this is a pre_flight check (which may perform optimized in-memory checks) or the final proper check. The default value is true.
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol. Will overwrite any actor, tenant or context provided. See Ash.Context for more.
  • :run_queries? (boolean/0) - Whether or not to run queries. If set to true, :maybe will not be returned. The default value is true.
  • :data - The record or records specifically attempting to be acted upon.
  • :tenant (value that implements the Ash.ToTenant protocol) - The tenant to use for authorization
  • :alter_source? (boolean/0) - If set to true, the source being authorized is returned so it can be run. The default value is false.
  • :base_query (term/0) - A base query on which to apply an generated filters
  • :no_check? (boolean/0) - Whether or not authorization must pass at the strict/filter step, or if post-checks are allowed to be run The default value is false.
  • :on_must_pass_strict_check (term/0) - Override the value returned when no_check? is true but a check must be run.
  • :atomic_changeset (term/0) - A base query on which to apply an generated filters
  • :return_forbidden_error? (boolean/0) - Whether or not to return a forbidden error in cases of not being authorized. The default value is false.
  • :log? (boolean/0) - Whether or not to log the authorization result. The default value is false.

default_short_name()

get(id, params \\ nil, opts \\ nil)

Get a specific email event by ID

Arguments

  • id

Options

  • :page - Pagination options, see Ash.read/2 for more.
  • :load (term/0) - A load statement to add onto the query
  • :max_concurrency (non_neg_integer/0) - The maximum number of processes allowed to be started for parallel loading of relationships and calculations. Defaults to System.schedulers_online() * 2
  • :lock (term/0) - A lock statement to add onto the query
  • :return_query? (boolean/0) - If true, the query that was ultimately used is returned as a third tuple element.
    The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value is false.
  • :skip_unknown_inputs - A list of inputs that, if provided, will be ignored if they are not recognized by the action. Use :* to indicate all unknown keys.
  • :reuse_values? (boolean/0) - Whether calculations are allowed to reuse values that have already been loaded, or must refetch them from the data layer. The default value is false.
  • :strict? (boolean/0) - If set to true, only specified attributes will be loaded when passing a list of fields to fetch on a relationship, which allows for more optimized data-fetching.
    See Ash.Query.load/2. The default value is false.
  • :authorize_with - If set to :error, instead of applying authorization filters as a filter, any records not matching the authorization filter will cause an error to be returned. Valid values are :filter, :error The default value is :filter.
  • :timeout (timeout/0) - A positive integer, or :infinity. If none is provided, the timeout configured on the domain is used.
  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.
  • :action (term/0) - The action to use, either an Action struct or the name of the action
  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.
  • :context (map/0) - Context to set on the query, changeset, or input
  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset
  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.
  • :query - A query to seed the action with.
  • :not_found_error? (boolean/0) - Whether or not to return or raise a NotFound error or to return nil when a get? action/interface is called.
  • :stream? (boolean/0) - If true, a stream of the results will be returned The default value is false.
  • :stream_options (keyword/0) - Options passed to Ash.stream!, if stream?: true is given
    • :batch_size (integer/0) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.
    • :allow_stream_with - The 'worst' strategy allowed to be used to fetch records. See Ash.stream!/2 docs for more. The default value is :keyset.
    • :stream_with - The specific strategy to use to fetch records. See Ash.stream!/2 docs for more.

get!(id, params \\ nil, opts \\ nil)

Get a specific email event by ID Raises any errors instead of returning them

Arguments

  • id

Options

  • :page - Pagination options, see Ash.read/2 for more.
  • :load (term/0) - A load statement to add onto the query
  • :max_concurrency (non_neg_integer/0) - The maximum number of processes allowed to be started for parallel loading of relationships and calculations. Defaults to System.schedulers_online() * 2
  • :lock (term/0) - A lock statement to add onto the query
  • :return_query? (boolean/0) - If true, the query that was ultimately used is returned as a third tuple element.
    The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value is false.
  • :skip_unknown_inputs - A list of inputs that, if provided, will be ignored if they are not recognized by the action. Use :* to indicate all unknown keys.
  • :reuse_values? (boolean/0) - Whether calculations are allowed to reuse values that have already been loaded, or must refetch them from the data layer. The default value is false.
  • :strict? (boolean/0) - If set to true, only specified attributes will be loaded when passing a list of fields to fetch on a relationship, which allows for more optimized data-fetching.
    See Ash.Query.load/2. The default value is false.
  • :authorize_with - If set to :error, instead of applying authorization filters as a filter, any records not matching the authorization filter will cause an error to be returned. Valid values are :filter, :error The default value is :filter.
  • :timeout (timeout/0) - A positive integer, or :infinity. If none is provided, the timeout configured on the domain is used.
  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.
  • :action (term/0) - The action to use, either an Action struct or the name of the action
  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.
  • :context (map/0) - Context to set on the query, changeset, or input
  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset
  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.
  • :query - A query to seed the action with.
  • :not_found_error? (boolean/0) - Whether or not to return or raise a NotFound error or to return nil when a get? action/interface is called.
  • :stream? (boolean/0) - If true, a stream of the results will be returned The default value is false.
  • :stream_options (keyword/0) - Options passed to Ash.stream!, if stream?: true is given
    • :batch_size (integer/0) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.
    • :allow_stream_with - The 'worst' strategy allowed to be used to fetch records. See Ash.stream!/2 docs for more. The default value is :keyset.
    • :stream_with - The specific strategy to use to fetch records. See Ash.stream!/2 docs for more.

input(opts)

@spec input(values :: map() | Keyword.t()) :: map() | no_return()

Validates that the keys in the provided input are valid for at least one action on the resource.

Raises a KeyError error at compile time if not. This exists because generally a struct should only ever be created by Ash as a result of a successful action. You should not be creating records manually in code, e.g %MyResource{value: 1, value: 2}. Generally that is fine, but often with embedded resources it is nice to be able to validate the keys that are being provided, e.g

Resource
|> Ash.Changeset.for_create(:create, %{embedded: EmbeddedResource.input(foo: 1, bar: 2)})
|> Ash.create()

input(opts, action)

@spec input(values :: map() | Keyword.t(), action :: atom()) :: map() | no_return()

Same as input/1, except restricts the keys to values accepted by the action provided.

list(params \\ nil, opts \\ nil)

List all email events

Options

  • :page - Pagination options, see Ash.read/2 for more.
  • :load (term/0) - A load statement to add onto the query
  • :max_concurrency (non_neg_integer/0) - The maximum number of processes allowed to be started for parallel loading of relationships and calculations. Defaults to System.schedulers_online() * 2
  • :lock (term/0) - A lock statement to add onto the query
  • :return_query? (boolean/0) - If true, the query that was ultimately used is returned as a third tuple element.
    The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value is false.
  • :skip_unknown_inputs - A list of inputs that, if provided, will be ignored if they are not recognized by the action. Use :* to indicate all unknown keys.
  • :reuse_values? (boolean/0) - Whether calculations are allowed to reuse values that have already been loaded, or must refetch them from the data layer. The default value is false.
  • :strict? (boolean/0) - If set to true, only specified attributes will be loaded when passing a list of fields to fetch on a relationship, which allows for more optimized data-fetching.
    See Ash.Query.load/2. The default value is false.
  • :authorize_with - If set to :error, instead of applying authorization filters as a filter, any records not matching the authorization filter will cause an error to be returned. Valid values are :filter, :error The default value is :filter.
  • :timeout (timeout/0) - A positive integer, or :infinity. If none is provided, the timeout configured on the domain is used.
  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.
  • :action (term/0) - The action to use, either an Action struct or the name of the action
  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.
  • :context (map/0) - Context to set on the query, changeset, or input
  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset
  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.
  • :query - A query to seed the action with.
  • :not_found_error? (boolean/0) - Whether or not to return or raise a NotFound error or to return nil when a get? action/interface is called.
  • :stream? (boolean/0) - If true, a stream of the results will be returned The default value is false.
  • :stream_options (keyword/0) - Options passed to Ash.stream!, if stream?: true is given
    • :batch_size (integer/0) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.
    • :allow_stream_with - The 'worst' strategy allowed to be used to fetch records. See Ash.stream!/2 docs for more. The default value is :keyset.
    • :stream_with - The specific strategy to use to fetch records. See Ash.stream!/2 docs for more.

list!(params \\ nil, opts \\ nil)

List all email events Raises any errors instead of returning them

Options

  • :page - Pagination options, see Ash.read/2 for more.
  • :load (term/0) - A load statement to add onto the query
  • :max_concurrency (non_neg_integer/0) - The maximum number of processes allowed to be started for parallel loading of relationships and calculations. Defaults to System.schedulers_online() * 2
  • :lock (term/0) - A lock statement to add onto the query
  • :return_query? (boolean/0) - If true, the query that was ultimately used is returned as a third tuple element.
    The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value is false.
  • :skip_unknown_inputs - A list of inputs that, if provided, will be ignored if they are not recognized by the action. Use :* to indicate all unknown keys.
  • :reuse_values? (boolean/0) - Whether calculations are allowed to reuse values that have already been loaded, or must refetch them from the data layer. The default value is false.
  • :strict? (boolean/0) - If set to true, only specified attributes will be loaded when passing a list of fields to fetch on a relationship, which allows for more optimized data-fetching.
    See Ash.Query.load/2. The default value is false.
  • :authorize_with - If set to :error, instead of applying authorization filters as a filter, any records not matching the authorization filter will cause an error to be returned. Valid values are :filter, :error The default value is :filter.
  • :timeout (timeout/0) - A positive integer, or :infinity. If none is provided, the timeout configured on the domain is used.
  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.
  • :action (term/0) - The action to use, either an Action struct or the name of the action
  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.
  • :context (map/0) - Context to set on the query, changeset, or input
  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset
  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.
  • :query - A query to seed the action with.
  • :not_found_error? (boolean/0) - Whether or not to return or raise a NotFound error or to return nil when a get? action/interface is called.
  • :stream? (boolean/0) - If true, a stream of the results will be returned The default value is false.
  • :stream_options (keyword/0) - Options passed to Ash.stream!, if stream?: true is given
    • :batch_size (integer/0) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.
    • :allow_stream_with - The 'worst' strategy allowed to be used to fetch records. See Ash.stream!/2 docs for more. The default value is :keyset.
    • :stream_with - The specific strategy to use to fetch records. See Ash.stream!/2 docs for more.

primary_key_matches?(left, right)

query_to_get(id, params_or_opts \\ %{}, opts \\ [])

Returns the query corresponding to the action.

Options

  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.
  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.
  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset
  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.
  • :query - A query to seed the action with.

query_to_list(params_or_opts \\ %{}, opts \\ [])

Returns the query corresponding to the action.

Options

  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.
  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.
  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset
  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.
  • :query - A query to seed the action with.