The behaviour an application implements once to run Countersign.
The host owns everything that is about the application rather than about
signing: whether signing is switched on for a scope (a tenant, an account,
or nil in a single-tenant app), how long links live, the name messages
show, rate limiting, auditing, notifications, HTML-to-PDF rendering, the
clock, and the per-subject lock that serialises a send or a signature with
the host's own writers.
Countersign.Requests calls these callbacks; it never reads application
config, so everything it needs comes from here or from Countersign.Config.
Summary
Types
An event Countersign.Requests reports to audit/3 and notify/2.
The host's tenant identifier, or nil in a single-tenant host.
Callbacks
Records an audit event for request. meta carries :ip_address and
:user_agent where a signer's request caused the event, and never the
delivery address.
Counts one hit against key in a window of scale_ms milliseconds.
How many signing codes the scope may send per day, across all its requests.
The name messages and the signing page show for the scope (the sender's organisation).
Whether remote signing is switched on for scope_id. A send for a disabled scope is refused.
Renders HTML (the signing certificate) to a PDF binary.
How many days a signing link stays valid after it is sent.
Takes the host's per-subject lock inside the caller's transaction and
answers :ok.
Tells the host's users that request changed (signed, declined, expired, failed).
The current time. Every timestamp Countersign writes comes from here.
How many days after the last send a pending request gets one reminder; 0 sends none.
Types
@type event() ::
:send
| :resend
| :view
| :consent
| :sign
| :decline
| :revoke
| :supersede
| :expire
| :fail
An event Countersign.Requests reports to audit/3 and notify/2.
@type scope_id() :: Ecto.UUID.t() | nil
The host's tenant identifier, or nil in a single-tenant host.
Callbacks
@callback audit(event(), Countersign.Request.t(), meta :: map()) :: :ok
Records an audit event for request. meta carries :ip_address and
:user_agent where a signer's request caused the event, and never the
delivery address.
@callback check_rate(key :: String.t(), scale_ms :: pos_integer(), limit :: pos_integer()) :: :ok | {:error, :rate_limited}
Counts one hit against key in a window of scale_ms milliseconds.
Answers :ok while the count is at most limit, and
{:error, :rate_limited} once it is over.
@callback codes_per_day(scope_id()) :: pos_integer()
How many signing codes the scope may send per day, across all its requests.
The name messages and the signing page show for the scope (the sender's organisation).
Whether remote signing is switched on for scope_id. A send for a disabled scope is refused.
Renders HTML (the signing certificate) to a PDF binary.
@callback link_days(scope_id()) :: pos_integer()
How many days a signing link stays valid after it is sent.
@callback lock_subject( repo :: module(), scope_id(), subject_type :: String.t(), subject_id :: String.t() ) :: :ok
Takes the host's per-subject lock inside the caller's transaction and
answers :ok.
Countersign.Requests calls it as the first statement of every send,
resend and sign transaction, so the request-row lock always comes after
the host's lock and the two can never be taken in opposite orders. A host
with no writers of its own to serialise may take a transaction-scoped
advisory lock or simply answer :ok.
@callback notify(event(), Countersign.Request.t()) :: :ok
Tells the host's users that request changed (signed, declined, expired, failed).
@callback now() :: DateTime.t()
The current time. Every timestamp Countersign writes comes from here.
@callback reminder_days(scope_id()) :: non_neg_integer()
How many days after the last send a pending request gets one reminder; 0 sends none.