SaltDns.Registrar.Rules (Salt v1.0.0)

The pure rules of the money path of SaltDns.Registrar, kept apart from the database so that they are tested in the plain test run:

  • guard/2 - the price ceiling and the premium rule;
  • completed?/2 - whether an order went through, going by what the registrar holds now (true, false, or :unknown when it cannot be shown either way: then nothing is ordered and the operation stays open);
  • order_result/1, price_result/1, lookup_result/1, call_result/1 - what an adapter answered, made well-formed: anything that is not what the behaviour promises becomes a non-final {:error, {:provider, message}}, so that a bad adapter leaves an operation open and never crashes the caller with a match error;
  • definite?/1 - whether an error kind is a final refusal (nothing was bought and asking again with the same reference cannot work).

Summary

Functions

Any other adapter answer: :ok, {:ok, term} or a well-formed error ({:error, {kind, message}}, the message a string or a map with a string :message). Everything else is a provider error.

Did the order of operation (a map with :kind and, for a renewal, :expires_before, the expiry the name had when it was ordered) go through, going by found, the registrar's state of the name now?

The error kinds that are final refusals.

True for a final refusal. :rate_limited, :unauthorized and server trouble are not final.

True when the reference is burned: a new reference is needed to try again. That is a final refusal, or the reference having been used for another request.

The price guard. req has :ceiling_minor, :currency and :allow_premium; price is what price/4 of the adapter answered.

A lookup answer: a state with a usable registrar id, or nil when the account does not hold the name. A found name without an id is not a completion (the same rule as order_result/1): the operation stays open.

The largest max_cost_minor accepted: far above any price, far below what the database holds.

A registration, transfer, renewal or restore answer: a state with a domain id and a state.

A price answer.

Types

error()

@type error() :: {:error, {atom(), String.t() | map()}}

Functions

call_result(ok)

@spec call_result(term()) :: :ok | {:ok, term()} | error()

Any other adapter answer: :ok, {:ok, term} or a well-formed error ({:error, {kind, message}}, the message a string or a map with a string :message). Everything else is a provider error.

completed?(arg1, arg2)

@spec completed?(map(), map()) :: boolean() | :unknown

Did the order of operation (a map with :kind and, for a renewal, :expires_before, the expiry the name had when it was ordered) go through, going by found, the registrar's state of the name now?

A renewal is told by the expiry: later than before means it went through. Without the expiry before, or without one in the registrar's answer, it cannot be told, and the answer is :unknown.

definite()

@spec definite() :: [atom()]

The error kinds that are final refusals.

definite?(kind)

@spec definite?(atom()) :: boolean()

True for a final refusal. :rate_limited, :unauthorized and server trouble are not final.

final?(kind)

@spec final?(atom()) :: boolean()

True when the reference is burned: a new reference is needed to try again. That is a final refusal, or the reference having been used for another request.

guard(req, map)

@spec guard(map(), map()) :: :ok | error()

The price guard. req has :ceiling_minor, :currency and :allow_premium; price is what price/4 of the adapter answered.

lookup_result(other)

@spec lookup_result(term()) :: {:ok, map() | nil} | error()

A lookup answer: a state with a usable registrar id, or nil when the account does not hold the name. A found name without an id is not a completion (the same rule as order_result/1): the operation stays open.

max_minor()

@spec max_minor() :: pos_integer()

The largest max_cost_minor accepted: far above any price, far below what the database holds.

order_result(other)

@spec order_result(term()) :: {:ok, map()} | error()

A registration, transfer, renewal or restore answer: a state with a domain id and a state.

price_result(other)

@spec price_result(term()) :: {:ok, map()} | error()

A price answer.