Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
default: true
MD013:
code_blocks: false
tables: false
MD013: false
MD033:
allowed_elements:
- summary
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
proseWrap: always
proseWrap: never
175 changes: 88 additions & 87 deletions specification.json

Large diffs are not rendered by default.

20 changes: 5 additions & 15 deletions specification/evaluation-context/evaluation-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,22 @@

## Overview

The `evaluation context` provides ambient information for the purposes of flag
evaluation. Contextual data may be used as the basis for targeting, including
rule-based evaluation, overrides for specific subjects, or fractional flag
evaluation.
The `evaluation context` provides ambient information for the purposes of flag evaluation. Contextual data may be used as the basis for targeting, including rule-based evaluation, overrides for specific subjects, or fractional flag evaluation.

### Fields

NOTE: Field casing is not specified, and should be chosen in accordance with
language idioms.
NOTE: Field casing is not specified, and should be chosen in accordance with language idioms.

see: [types](../types.md)

##### Requirement 3.1

> The `evaluation context` structure **MUST** define an optional `targeting key`
> field of type string, identifying the subject of the flag evaluation.
> The `evaluation context` structure **MUST** define an optional `targeting key` field of type string, identifying the subject of the flag evaluation.

The targeting key uniquely identifies the subject (end-user, or client service)
of a flag evaluation. Providers may require this field for fractional flag
evaluation, rules, or overrides targeting specific users. Such providers may
behave unpredictably if a targeting key is not specified at flag resolution.
The targeting key uniquely identifies the subject (end-user, or client service) of a flag evaluation. Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users. Such providers may behave unpredictably if a targeting key is not specified at flag resolution.

##### Requirement 3.2

> The evaluation context **MUST** support the inclusion of custom fields, having
> keys of type `string`, and values of type
> `boolean | string | number | datetime | structure`.
> The evaluation context **MUST** support the inclusion of custom fields, having keys of type `string`, and values of type `boolean | string | number | datetime | structure`.

see: [structure](../types.md#structure), [datetime](../types.md#datetime)
172 changes: 60 additions & 112 deletions specification/flag-evaluation/flag-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@

## Overview

The `evaluation API` allows for the evaluation of feature flag values,
independent of any flag control plane or vendor. In the absence of a
[provider](../provider/providers.md) the `evaluation API` uses the "No-op
provider", which simply returns the supplied default flag value.
The `evaluation API` allows for the evaluation of feature flag values, independent of any flag control plane or vendor. In the absence of a [provider](../provider/providers.md) the `evaluation API` uses the "No-op provider", which simply returns the supplied default flag value.

### API Initialization and Configuration

#### Requirement 1.1
#### Requirement 1.1.1

> The `API`, and any state it maintains **SHOULD** exist as a global singleton,
> even in cases wherein multiple versions of the `API` are present at runtime.
> The `API`, and any state it maintains **SHOULD** exist as a global singleton, even in cases wherein multiple versions of the `API` are present at runtime.

It's important that multiple instances of the `API` not be active, so that state
stored therein, such as the registered `provider`, static global
`evaluation context`, and globally configured `hooks` allow the `API` to behave
predictably. This can be difficult in some runtimes or languages, but
implementors should make their best effort to ensure that only a single instance
of the `API` is used.
It's important that multiple instances of the `API` not be active, so that state stored therein, such as the registered `provider`, static global `evaluation context`, and globally configured `hooks` allow the `API` to behave predictably. This can be difficult in some runtimes or languages, but implementors should make their best effort to ensure that only a single instance of the `API` is used.

#### Requirement 1.2
#### Requirement 1.1.2

> The `API` **MUST** provide a function to set the global `provider` singleton,
> which accepts an API-conformant `provider` implementation.
> The `API` **MUST** provide a function to set the global `provider` singleton, which accepts an API-conformant `provider` implementation.

```
// example provider mutator
Expand All @@ -35,11 +25,9 @@ OpenFeature.setProvider(new MyProvider());

See [provider](../provider//providers.md) for details.

#### Requirement 1.3
#### Requirement 1.1.3

> The `API` **MUST** provide a function to add `hooks` which accepts one or more
> API-conformant `hooks`, and appends them to the collection of any previously
> added hooks. When new hooks are added, previously added hooks are not removed.
> The `API` **MUST** provide a function to add `hooks` which accepts one or more API-conformant `hooks`, and appends them to the collection of any previously added hooks. When new hooks are added, previously added hooks are not removed.

```
// example hook attachment
Expand All @@ -48,10 +36,9 @@ OpenFeature.addHooks([new MyHook()]);

See [hooks](./hooks.md) for details.

#### Requirement 1.4
#### Requirement 1.1.4

> The API **MUST** provide a function for retrieving the `provider`
> implementation.
> The API **MUST** provide a function for retrieving the `provider` implementation.

```
// example provider accessor
Expand All @@ -60,10 +47,9 @@ OpenFeature.getProvider();

See [provider](../provider/providers.md) for details.

#### Requirement 1.5
#### Requirement 1.1.5

> The `API` **MUST** provide a function for creating a `client` which accepts
> the following options:
> The `API` **MUST** provide a function for creating a `client` which accepts the following options:
>
> - name (optional): A logical string identifier for the client.

Expand All @@ -78,11 +64,9 @@ The name is a logical identifier for the client.

### Client Usage

#### Requirement 1.6
#### Requirement 1.2.1

> The client **MUST** provide a method to add `hooks` which accepts one or more
> API-conformant `hooks`, and appends them to the collection of any previously
> added hooks. When new hooks are added, previously added hooks are not removed.
> The client **MUST** provide a method to add `hooks` which accepts one or more API-conformant `hooks`, and appends them to the collection of any previously added hooks. When new hooks are added, previously added hooks are not removed.

```
// example hook attachment
Expand All @@ -93,27 +77,22 @@ See [hooks](./hooks.md) for details.

#### Flag Evaluation

##### Requirement 1.7
##### Requirement 1.3.1

> The `client` **MUST** provide methods for flag evaluation, with parameters
> `flag key` (string, required), `default value` (boolean | number | string |
> structure, required), `evaluation context` (optional), and
> `evaluation options` (optional), which returns the flag value.
> The `client` **MUST** provide methods for flag evaluation, with parameters `flag key` (string, required), `default value` (boolean | number | string | structure, required), `evaluation context` (optional), and `evaluation options` (optional), which returns the flag value.

```
// example flag evaluation
var myValue = client.getValue('my-flag', false);
```

##### Condition 1.8
##### Condition 1.3.2

> The language type system differentiates between strings, numbers, booleans and
> structures.
> The language type system differentiates between strings, numbers, booleans and structures.

###### Conditional Requirement 1.8.1
###### Conditional Requirement 1.3.2.1

> The `client` **MUST** provide methods for typed flag evaluation, including
> boolean, numeric, string, and structure.
> The `client` **MUST** provide methods for typed flag evaluation, including boolean, numeric, string, and structure.

```
// example boolean flag evaluation
Expand All @@ -129,26 +108,17 @@ number myNumber = client.getNumberValue('number-flag', 75);
MyStruct myStruct = client.getObjectValue<MyStruct>('structured-flag', { text: 'N/A', percentage: 75 }, evaluationContext, options);
```

See [evaluation context](../evaluation-context/evaluation-context.md) for
details.
See [evaluation context](../evaluation-context/evaluation-context.md) for details.

###### Conditional Requirement 1.8.2
###### Conditional Requirement 1.3.3

> The `client` **SHOULD** guarantee the returned value of any typed flag
> evaluation method is of the expected type. If the value returned by the
> underlying provider implementation does not match the expected type, it's to
> be considered abnormal execution, and the supplied `default value` should be
> returned.
> The `client` **SHOULD** guarantee the returned value of any typed flag evaluation method is of the expected type. If the value returned by the underlying provider implementation does not match the expected type, it's to be considered abnormal execution, and the supplied `default value` should be returned.

#### Detailed Flag Evaluation

##### Requirement 1.9
##### Requirement 1.4.1

> The `client` **MUST** provide methods for detailed flag value evaluation with
> parameters `flag key` (string, required), `default value` (boolean | number |
> string | structure, required), `evaluation context` (optional), and
> `evaluation options` (optional), which returns an `evaluation details`
> structure.
> The `client` **MUST** provide methods for detailed flag value evaluation with parameters `flag key` (string, required), `default value` (boolean | number | string | structure, required), `evaluation context` (optional), and `evaluation options` (optional), which returns an `evaluation details` structure.

```
// example detailed boolean flag evaluation
Expand All @@ -165,90 +135,68 @@ FlagEvaluationDetails<MyStruct> myStructDetails = client.getObjectDetails<MyStru

```

##### Requirement 1.10
##### Requirement 1.4.2

> The `evaluation details` structure's `value` field **MUST** contain the
> evaluated flag value.
> The `evaluation details` structure's `value` field **MUST** contain the evaluated flag value.

##### Condition 1.11
##### Condition 1.4.3

> The language supports generics (or an equivalent feature).

###### Conditional Requirement 1.11.1
###### Conditional Requirement 1.4.3.1

> The `evaluation details` structure **SHOULD** accept a generic argument (or
> use an equivalent language feature) which indicates the type of the wrapped
> `value` field.
> The `evaluation details` structure **SHOULD** accept a generic argument (or use an equivalent language feature) which indicates the type of the wrapped `value` field.

##### Requirement 1.12
##### Requirement 1.4.4

> The `evaluation details` structure's `flag key` field **MUST** contain the
> `flag key` argument passed to the detailed flag evaluation method.
> The `evaluation details` structure's `flag key` field **MUST** contain the `flag key` argument passed to the detailed flag evaluation method.

##### Requirement 1.13
##### Requirement 1.4.5

> In cases of normal execution, the `evaluation details` structure's `variant`
> field **MUST** contain the value of the `variant` field in the
> `flag resolution` structure returned by the configured `provider`, if the
> field is set.
> In cases of normal execution, the `evaluation details` structure's `variant` field **MUST** contain the value of the `variant` field in the `flag resolution` structure returned by the configured `provider`, if the field is set.

##### Requirement 1.14
##### Requirement 1.4.6

> In cases of normal execution, the `evaluation details` structure's `reason`
> field **MUST** contain the value of the `reason` field in the
> `flag resolution` structure returned by the configured `provider`, if the
> field is set.
> In cases of normal execution, the `evaluation details` structure's `reason` field **MUST** contain the value of the `reason` field in the `flag resolution` structure returned by the configured `provider`, if the field is set.

##### Requirement 1.15
##### Requirement 1.4.7

> In cases of abnormal execution, the `evaluation details` structure's
> `error code` field **MUST** identify an error occurred during flag evaluation,
> having possible values `"PROVIDER_NOT_READY"`, `"FLAG_NOT_FOUND"`,
> `"PARSE_ERROR"`, `"TYPE_MISMATCH"`, or `"GENERAL"`.
> In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** identify an error occurred during flag evaluation, having possible values `"PROVIDER_NOT_READY"`, `"FLAG_NOT_FOUND"`, `"PARSE_ERROR"`, `"TYPE_MISMATCH"`, or `"GENERAL"`.

##### Requirement 1.16
##### Requirement 1.4.8

> In cases of abnormal execution (network failure, unhandled error, etc) the
> `reason` field in the `evaluation details` **SHOULD** indicate an error.
> In cases of abnormal execution (network failure, unhandled error, etc) the `reason` field in the `evaluation details` **SHOULD** indicate an error.

##### Requirement 1.17
##### Requirement 1.4.9

> The `evaluation options` structure's `hooks` field denotes a collection of
> hooks that the client **MUST** execute for the respective flag evaluation, in
> addition to those already configured.
> Methods, functions, or operations on the client **MUST NOT** throw exceptions, or otherwise abnormally terminate. Flag evaluation calls must always return the `default value` in the event of abnormal execution. Exceptions include functions or methods for the purposes for configuration or setup.

See [hooks](./hooks.md) for details.
Configuration code includes code to set the provider, instantiate providers, and configure the global API object.

##### Requirement 1.4.10

> In the case of abnormal execution, the client **SHOULD** log an informative error message.

##### Requirement 1.18
Implementations may define a standard logging interface that can be supplied as an optional argument to the client creation function, which may wrap standard logging functionality of the implementation language.

> Methods, functions, or operations on the client **MUST NOT** throw exceptions,
> or otherwise abnormally terminate. Flag evaluation calls must always return
> the `default value` in the event of abnormal execution. Exceptions include
> functions or methods for the purposes for configuration or setup.
##### Requirement 1.4.11

##### Requirement 1.19
> The `client` **SHOULD** provide asynchronous or non-blocking mechanisms for flag evaluation.

> In the case of abnormal execution, the client **SHOULD** log an informative
> error message.
It's recommended to provide non-blocking mechanisms for flag evaluation, particularly in languages or environments wherein there's a single thread of execution.

Implementations may define a standard logging interface that can be supplied as
an optional argument to the client creation function, which may wrap standard
logging functionality of the implementation language.
#### Evaluation Options

##### Requirement 1.20
##### Requirement 1.5.1

> The `client` **SHOULD** provide asynchronous or non-blocking mechanisms for
> flag evaluation.
> The `evaluation options` structure's `hooks` field denotes an ordered collection of hooks that the client **MUST** execute for the respective flag evaluation, in addition to those already configured.

See [hooks](./hooks.md) for details.

It's recommended to provide non-blocking mechanisms for flag evaluation,
particularly in languages or environments wherein there's a single thread of
execution.
#### Context Transformation

##### Requirement 1.21
##### Requirement 1.6.1

> The `client` **SHOULD** transform the `evaluation context` using the
> `provider's` `context transformer` function if one is defined, before passing
> the result of the transformation to the provider's flag resolution functions.
> The `client` **SHOULD** transform the `evaluation context` using the `provider's` `context transformer` function if one is defined, before passing the result of the transformation to the provider's flag resolution functions.

See [context transformation](../provider/providers.md#context-transformation)
for details.
See [context transformation](../provider/providers.md#context-transformation) for details.
Loading