@openfeature/flagd-provider 0.13.3 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright [yyyy] [name of copyright owner]
190
+ Copyright OpenFeature Maintainers
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -28,17 +28,26 @@ Options can be defined in the constructor or as environment variables. Construct
28
28
  ### Available Configuration Options
29
29
 
30
30
  | Option name | Environment variable name | Type | Default | Supported values |
31
- | -------------------------------------- | ------------------------------ | ------- |----------------------------------------------------------------| ---------------- |
31
+ | -------------------------------------- | ------------------------------ | ------- |----------------------------------------------------------------|------------------|
32
32
  | host | FLAGD_HOST | string | localhost | |
33
33
  | port | FLAGD_PORT | number | [resolver specific defaults](#resolver-type-specific-defaults) | |
34
34
  | tls | FLAGD_TLS | boolean | false | |
35
35
  | socketPath | FLAGD_SOCKET_PATH | string | - | |
36
+ | certPath | FLAGD_SERVER_CERT_PATH | string | - | |
36
37
  | resolverType | FLAGD_RESOLVER | string | rpc | rpc, in-process |
37
38
  | offlineFlagSourcePath | FLAGD_OFFLINE_FLAG_SOURCE_PATH | string | - | |
38
- | selector | FLAGD_SOURCE_SELECTOR | string | - | |
39
+ | selector | FLAGD_SOURCE_SELECTOR | string | - | rpc & in-process (see [Selector](#selector)) |
39
40
  | cache | FLAGD_CACHE | string | lru | lru, disabled |
40
41
  | maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |
41
42
  | defaultAuthority | FLAGD_DEFAULT_AUTHORITY | string | - | rpc, in-process |
43
+ | keepAliveTime | FLAGD_KEEP_ALIVE_TIME_MS | number | 0 | rpc, in-process |
44
+ | retryBackoffMs | FLAGD_RETRY_BACKOFF_MS | int | 1000 | in-process |
45
+ | retryBackoffMaxMs | FLAGD_RETRY_BACKOFF_MAX_MS | int | 120000 | in-process |
46
+ | retryGracePeriod | FLAGD_RETRY_GRACE_PERIOD | int | 5 | |
47
+ | fatalStatusCodes | FLAGD_FATAL_STATUS_CODES | string[]| - | |
48
+
49
+ > [!NOTE]
50
+ > The `selector` option automatically uses the `flagd-selector` header (the preferred approach per [flagd#1814](https://github.com/open-feature/flagd/issues/1814)) while maintaining backward compatibility with older flagd versions. See [Selector](#selector) for details.
42
51
 
43
52
  #### Resolver type-specific Defaults
44
53
 
@@ -94,6 +103,46 @@ To enable this mode, you should provide a valid flag configuration file with the
94
103
  Offline mode uses `fs.watchFile` and polls every 5 seconds for changes to the file.
95
104
  This mode is useful for local development, test cases, and for offline applications.
96
105
 
106
+ ### Selector
107
+
108
+ The `selector` option allows filtering flag configurations and evaluations based on flag sets or sources. This is useful when multiple flag configurations are available and you want to target a specific subset.
109
+
110
+ **RPC mode:**
111
+ ```ts
112
+ OpenFeature.setProvider(new FlagdProvider({
113
+ selector: 'flagSetId=payment-flags',
114
+ }))
115
+ ```
116
+
117
+ **In-process mode:**
118
+ ```ts
119
+ OpenFeature.setProvider(new FlagdProvider({
120
+ resolverType: 'in-process',
121
+ selector: 'flagSetId=app-flags',
122
+ }))
123
+ ```
124
+
125
+ Or via environment variable:
126
+
127
+ ```bash
128
+ export FLAGD_SOURCE_SELECTOR="flagSetId=app-flags"
129
+ ```
130
+
131
+ > [!IMPORTANT]
132
+ > **Selector normalization ([flagd#1814](https://github.com/open-feature/flagd/issues/1814))**
133
+ >
134
+ > As part of [flagd#1814](https://github.com/open-feature/flagd/issues/1814), the flagd project is normalizing selector handling across all services (sync, evaluation, and OFREP) to use the `flagd-selector` gRPC metadata header.
135
+ >
136
+ > **Current implementation:**
137
+ > - The JS SDK **automatically passes the selector via the `flagd-selector` header** for both RPC and in-process modes
138
+ > - For in-process mode backward compatibility with older flagd versions, the selector is **also sent in the request body**
139
+ > - Both methods work with current flagd versions
140
+ > - In a future major version of flagd, the request body selector field may be removed
141
+ >
142
+ > **No migration needed:**
143
+ >
144
+ > Users do not need to make any code changes. The SDK handles selector normalization automatically.
145
+
97
146
  ### Default Authority usage (optional)
98
147
 
99
148
  This is useful for complex routing or service-discovery use cases that involve a proxy (e.g., Envoy).
@@ -106,6 +155,40 @@ Please refer to this [GitHub issue](https://github.com/open-feature/js-sdk-contr
106
155
  }))
107
156
  ```
108
157
 
158
+ ### Keepalive Configuration (optional)
159
+
160
+ gRPC keepalive prevents idle connections from being closed.
161
+ This option only applies to RPC and in-process resolvers (streaming connections).
162
+ Set to `0` to disable keepalive (default).
163
+
164
+ ```ts
165
+ OpenFeature.setProvider(new FlagdProvider({
166
+ resolverType: 'in-process',
167
+ keepAliveTime: 30000, // Send keepalive ping every 30 seconds
168
+ }))
169
+ ```
170
+
171
+ ### Retry Grace Period (optional)
172
+
173
+ The `retryGracePeriod` controls how long (in seconds) the provider will retry reconnecting before transitioning from `STALE` to `ERROR` state:
174
+
175
+ ```ts
176
+ OpenFeature.setProvider(new FlagdProvider({
177
+ retryGracePeriod: 5, // Retry for 5 seconds before moving to ERROR state
178
+ }))
179
+ ```
180
+
181
+ ### Fatal Status Codes (optional)
182
+
183
+ Configure which gRPC status codes should be treated as fatal errors on the first connection attempt.
184
+ When a fatal status code is encountered during initial connection, the provider will not retry and will emit a `PROVIDER_FATAL` error.
185
+
186
+ ```ts
187
+ OpenFeature.setProvider(new FlagdProvider({
188
+ fatalStatusCodes: ['UNAUTHENTICATED', 'PERMISSION_DENIED']
189
+ }))
190
+ ```
191
+
109
192
  ### Supported Events
110
193
 
111
194
  The flagd provider emits `PROVIDER_READY`, `PROVIDER_ERROR` and `PROVIDER_CONFIGURATION_CHANGED` events.