You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-6Lines changed: 82 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,15 +44,91 @@ Refer to the [SDK reference guide](https://docs.launchdarkly.com/sdk/server-side
44
44
45
45
## OpenFeature Specific Considerations
46
46
47
-
When evaluating an `LDUser` with the LaunchDarkly Node SDK a string `key` attribute would normally be required. When using OpenFeature the `targetingKey` attribute should be used instead of `key`. If a `key` attribute is provided in the `EvaluationContext`, then it will be discarded in favor of `targetingKey`. If a `targetingKey` is not provided, or if the `EvaluationContext` is omitted entirely, then the `defaultValue` will be returned from OpenFeature evaluation methods.
47
+
LaunchDarkly evaluates contexts, and it can either evaluate a single-context, or a multi-context. When using OpenFeature both single and multi-contexts must be encoded into a single `EvaluationContext`. This is accomplished by looking for an attribute named `kind` in the `EvaluationContext`.
48
48
49
-
Other fields normally included in an `LDUser` may be added to the `EvaluationContext`. Any `custom` attributes can
50
-
be added to the top level of the evaluation context, and they will operate as if they were `custom` attributes on an `LDUser`. Attributes which are typically top level on an `LDUser` should be of the same types that are specified for
51
-
an `LDUser` or they will not operate as intended.
49
+
There are 4 different scenarios related to the `kind`:
50
+
1. There is no `kind` attribute. In this case the provider will treat the context as a single context containing a "user" kind.
51
+
2. There is a `kind` attribute, and the value of that attribute is "multi". This will indicate to the provider that the context is a multi-context.
52
+
3. There is a `kind` attribute, and the value of that attribute is a string other than "multi". This will indicate to the provider a single context of the kind specified.
53
+
4. There is a `kind` attribute, and the attribute is not a string. In this case the value of the attribute will be discarded, and the context will be treated as a "user". An error message will be logged.
52
54
53
-
If a top level `custom` attribute is defined on the `EvaluationContext`, then that will be a `custom` attribute inside `custom` for an `LDUser`.
55
+
The `kind` attribute should be a string containing only contain ASCII letters, numbers, `.`, `_` or `-`.
54
56
55
-
If a custom attribute is provided, whose value is an object, then that attribute will be discarded.
57
+
The OpenFeature specification allows for an optional targeting key, but LaunchDarkly requires a key for evaluation. A targeting key must be specified for each context being evaluated. It may be specified using either `targetingKey`, as it is in the OpenFeature specification, or `key`, which is the typical LaunchDarkly identifier for the targeting key. If a `targetingKey` and a `key` are specified, then the `targetingKey` will take precedence.
58
+
59
+
There are several other attributes which have special functionality within a single or multi-context.
60
+
- A key of `privateAttributes`. Must be an array of string values. [Equivalent to '_meta.privateAttributes' in the SDK.](https://launchdarkly.github.io/node-server-sdk/interfaces/_launchdarkly_node_server_sdk_.LDContextMeta.html#privateAttributes)
61
+
- A key of `anonymous`. Must be a boolean value. [Equivalent to 'anonymous' in the SDK.](https://launchdarkly.github.io/node-server-sdk/interfaces/_launchdarkly_node_server_sdk_.LDSingleKindContext.html#anonymous)
62
+
- A key of `name`. Must be a string. [Equivalent to 'name' in the SDK.](https://launchdarkly.github.io/node-server-sdk/interfaces/_launchdarkly_node_server_sdk_.LDSingleKindContext.html#name)
63
+
64
+
### Examples
65
+
66
+
#### A single user context
67
+
68
+
```typescript
69
+
const evaluationContext = {
70
+
targetingKey: 'my-user-key'
71
+
};
72
+
```
73
+
74
+
#### A single context of kind "organization"
75
+
76
+
```typescript
77
+
const evaluationContext = {
78
+
kind: 'organization',
79
+
targetingKey: 'my-org-key'
80
+
};
81
+
```
82
+
83
+
#### A multi-context containing a "user" and an "organization"
84
+
85
+
```typescript
86
+
87
+
const evaluationContext = {
88
+
kind: 'multi',
89
+
organization: {
90
+
targetingKey: 'my-org-key',
91
+
myCustomAttribute: 'myAttributeValue'
92
+
},
93
+
user: {
94
+
targetingKey: 'my-user-key'
95
+
}
96
+
};
97
+
```
98
+
99
+
#### Setting private attributes in a single context
100
+
101
+
```typescript
102
+
const evaluationContext = {
103
+
kind: 'organization',
104
+
name: 'the-org-name',
105
+
targetingKey: 'my-org-key',
106
+
myCustomAttribute: 'myCustomValue',
107
+
privateAttributes: ['myCustomAttribute']
108
+
};
109
+
```
110
+
111
+
#### Setting private attributes in a multi-context
112
+
113
+
```typescript
114
+
const evaluationContext = {
115
+
kind: 'multi',
116
+
organization: {
117
+
targetingKey: 'my-org-key',
118
+
name: 'the-org-name',
119
+
// This will ONLY apply to the "organization" attributes.
0 commit comments