diff --git a/lib/basic_signup_allowlist.ex b/lib/basic_signup_allowlist.ex index 263e372..e531593 100644 --- a/lib/basic_signup_allowlist.ex +++ b/lib/basic_signup_allowlist.ex @@ -10,6 +10,7 @@ defmodule BasicSignupAllowlist do @doc """ Returns the name of the environment variable used for the signup allowlist. """ + @spec signup_allowlist_emails() :: String.t() def signup_allowlist_emails, do: @signup_allowlist_emails @doc """ @@ -28,11 +29,12 @@ defmodule BasicSignupAllowlist do iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS") iex> BasicSignupAllowlist.signup_allowed?("joe@example.com") false - iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*") + iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS", "*") iex> BasicSignupAllowlist.signup_allowed?("joe@example.com") true """ + @spec signup_allowed?(String.t()) :: boolean() def signup_allowed?(email) do env_value = System.get_env(@signup_allowlist_emails) signup_allowed_fun(env_value, email) diff --git a/lib/fun_core/basic_signup_allowlist.ex b/lib/fun_core/basic_signup_allowlist.ex index 8e8f2e4..11865b5 100644 --- a/lib/fun_core/basic_signup_allowlist.ex +++ b/lib/fun_core/basic_signup_allowlist.ex @@ -1,14 +1,30 @@ defmodule FunCore.BasicSignupAllowlist do + @moduledoc """ + Functional core for email allowlist checking logic. + """ + + @doc """ + Normalizes an email address by trimming whitespace and converting to lowercase. + """ + @spec normalize(String.t()) :: String.t() def normalize(email) do email |> String.trim() |> String.downcase() end + @doc """ + Converts a comma-separated string of email addresses into a normalized list. + """ + @spec addresses_as_list(String.t()) :: [String.t()] def addresses_as_list(addresses_str) do addresses_str |> String.split(",") |> Enum.map(&normalize/1) end + @doc """ + Checks if an email is allowed based on the allowlist configuration. + """ + @spec signup_allowed_fun(String.t() | nil, String.t()) :: boolean() def signup_allowed_fun(signups_allowed, email_received) do case signups_allowed do nil -> false