Packages
unleash_fresha
2.0.0-git-67b2
5.1.4
5.1.3
5.1.2
5.1.1
5.1.0
5.0.0
4.0.0
4.0.0-git-bda3
3.0.1
3.0.0
2.1.0
2.0.1
2.0.0-git-75d8
2.0.0-git-67b2
2.0.0-git-4b61
2.0.0-git-49f4
1.16.0
1.15.0
1.14.1-git-e754
1.14.0
1.14.0-git-71e9
1.13.0
1.13.0-git-4ba6
1.12.0
1.11.0
1.11.0-git-1b62
1.10.2
1.10.2-git-b835
1.10.1
1.10.0
1.9.3-alpha0
1.9.2
1.9.1
1.9.0
An Unleash Feature Flag client for Elixir, forked from [unleash](https://gitlab.com/afontaine/unleash_ex)
Current section
Files
Jump to
Current section
Files
lib/unleash.ex
defmodule Unleash do
@moduledoc """
Unofficial Elixir SDK for the [Unleash Feature Flag System](https://www.getunleash.io/).
Use it to check feature flags and variants via the main usage macros:
require Unleash.Macros, as: Unleash
Unleash.enabled?(:some_feature, fallback: false)
Unleash.get_variant(:some_feature_with_variants)
The SDK additionally provides a bunch of utilities to automatically set some context fields
in Plug applications (see `Unleash.Plug`) and some utilities for propagation of context,
feature flags overrides and impressions across services (see `Unleash.Propagation`).
Note that Propagation is not a standard Unleash mechanism, but a custom extension
defined and developed by [Fresha](https://www.fresha.com/careers).
This module just contains the "interface "of the SDK, meaning the `Unleash` behaviour
and types. For the actual runtime implementation, check `Unleash.Runtime` and related modules.
"""
alias Unleash.Variant
@typedoc """
Type that can be used to reference a feature.
Note that `:feature_a` and `"feature_a"` reference the same feature.
"""
@type feature_name() :: String.t() | atom()
@typedoc """
Option that can be passed to `enabled?/2`.
* `:allow_overrides` - Whether propagated overrides should be considered for the feature flag check.
See `t:Unleash.overrides/0`. The default is `false`.
* `:context` - Context that might be used to evaluate activation strategies. The default is an empty map.
* `:fallback` - Fallback value that will be returned if the feature is not found in the local cache or overrides.
The default is `false`. You can use `nil` if you'd like to handle missing features explicitly.
"""
@type enabled_opt ::
{:allow_overrides, boolean()}
| {:context, Unleash.Context.t()}
| {:fallback, boolean() | nil}
@typedoc """
Option that can be passed to `get_variant/2`.
* `:allow_overrides` - Whether propagated overrides should be considered for the feature flag check.
See `t:Unleash.overrides/0`. The default is `false`.
* `:context` - Context that might be used to evaluate activation strategies. The default is an empty map.
* `:fallback` - Fallback value that will be returned if the feature is not found in the local cache or overrides.
The default is the special "disabled" variant.
You can use `nil` if you'd like to handle missing features explicitly.
"""
@type get_variant_opt ::
{:allow_overrides, boolean()}
| {:context, Unleash.Context.t()}
| {:fallback, Variant.result() | nil}
@typedoc """
The Unleash Context for activation strategies evaluation. See `Unleash.Context`.
"""
@type context :: Unleash.Context.t()
@typedoc """
Represents local feature overrides that can be used to force a feature evaluation value,
bypassing its activation strategies.
These can be inherited from the clients,
see `Unleash.Propagation` for a high-level introduction to the topic.
"""
@type overrides :: %{
String.t() => :on | :off | String.t()
}
@typedoc """
Record of a feature flag activation check.
In other words, whenever a feature flag is queried for status via `enabled?/3`,
an impression represents the feature that was checked and the result of that check.
See https://docs.getunleash.io/reference/impression-data
"""
@type impression :: %{
feature_name: String.t(),
enabled: boolean()
}
# The behaviour that Unleash Runtimes must implement.
@doc """
Checks if the given feature is enabled.
"""
@callback enabled?(Unleash.feature_name(), opts :: [Unleash.enabled_opt()]) :: boolean() | nil
@doc """
Returns the variant for the given feature flag.
"""
@callback get_variant(Unleash.feature_name(), opts :: [Unleash.get_variant_opt()]) :: Variant.result() | nil
end