@openfeature/flagd-provider 0.8.0 → 0.8.2
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/README.md +21 -15
- package/index.cjs +13 -4
- package/index.js +13 -4
- package/package.json +1 -1
- package/src/lib/flagd-provider.d.ts +1 -1
- /package/src/lib/service/grpc/{service.d.ts → grpc-service.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Server-
|
|
1
|
+
# Server-Side flagd Provider
|
|
2
2
|
|
|
3
3
|
Flagd is a simple daemon for evaluating feature flags.
|
|
4
4
|
It is designed to conform to OpenFeature schema for flag definitions.
|
|
@@ -21,19 +21,19 @@ $ npm install @openfeature/js-sdk
|
|
|
21
21
|
The `FlagdProvider` supports multiple configuration options that determine now the SDK communicates with flagd.
|
|
22
22
|
Options can be defined in the constructor or as environment variables, with constructor options having the highest precedence.
|
|
23
23
|
|
|
24
|
-
### Available
|
|
24
|
+
### Available Options
|
|
25
25
|
|
|
26
|
-
| Option name | Environment variable name
|
|
27
|
-
| --------------------- |
|
|
28
|
-
| host | FLAGD_HOST
|
|
29
|
-
| port | FLAGD_PORT
|
|
30
|
-
| tls | FLAGD_TLS
|
|
31
|
-
| socketPath | FLAGD_SOCKET_PATH
|
|
32
|
-
| cache | FLAGD_CACHE
|
|
33
|
-
| maxCacheSize | FLAGD_MAX_CACHE_SIZE
|
|
34
|
-
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES
|
|
26
|
+
| Option name | Environment variable name | Type | Default | Values |
|
|
27
|
+
| --------------------- | ------------------------------ | ------- | --------- | ------------ |
|
|
28
|
+
| host | FLAGD_HOST | string | localhost | |
|
|
29
|
+
| port | FLAGD_PORT | number | 8013 | |
|
|
30
|
+
| tls | FLAGD_TLS | boolean | false | |
|
|
31
|
+
| socketPath | FLAGD_SOCKET_PATH | string | - | |
|
|
32
|
+
| cache | FLAGD_CACHE | string | lru | lru,disabled |
|
|
33
|
+
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |
|
|
34
|
+
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | 5 | |
|
|
35
35
|
|
|
36
|
-
### Example
|
|
36
|
+
### Example Using TCP
|
|
37
37
|
|
|
38
38
|
```
|
|
39
39
|
OpenFeature.setProvider(new FlagdProvider({
|
|
@@ -42,7 +42,7 @@ Options can be defined in the constructor or as environment variables, with cons
|
|
|
42
42
|
}))
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
### Example
|
|
45
|
+
### Example Using a Unix Socket
|
|
46
46
|
|
|
47
47
|
```
|
|
48
48
|
OpenFeature.setProvider(new FlagdProvider({
|
|
@@ -50,7 +50,7 @@ Options can be defined in the constructor or as environment variables, with cons
|
|
|
50
50
|
}))
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
### Supported
|
|
53
|
+
### Supported Events
|
|
54
54
|
|
|
55
55
|
The flagd provider emits `PROVIDER_READY`, `PROVIDER_ERROR` and `PROVIDER_CONFIGURATION_CHANGED` events.
|
|
56
56
|
|
|
@@ -62,12 +62,18 @@ The flagd provider emits `PROVIDER_READY`, `PROVIDER_ERROR` and `PROVIDER_CONFIG
|
|
|
62
62
|
|
|
63
63
|
For general information on events, see the [official documentation](https://openfeature.dev/docs/reference/concepts/events).
|
|
64
64
|
|
|
65
|
+
### Flag Metadata
|
|
66
|
+
|
|
67
|
+
| Field | Type | Value |
|
|
68
|
+
| ------- | ------ | ------------------------------------------------- |
|
|
69
|
+
| `scope` | string | "selector" set for the associated source in flagd |
|
|
70
|
+
|
|
65
71
|
## Building
|
|
66
72
|
|
|
67
73
|
Run `nx package providers-flagd` to build the library.
|
|
68
74
|
|
|
69
75
|
> NOTE: [Buf](https://docs.buf.build/installation) must be installed to build locally.
|
|
70
76
|
|
|
71
|
-
## Running
|
|
77
|
+
## Running Unit Tests
|
|
72
78
|
|
|
73
79
|
Run `nx test providers-flagd` to execute the unit tests via [Jest](https://jestjs.io).
|
package/index.cjs
CHANGED
|
@@ -5888,7 +5888,9 @@ class GRPCService {
|
|
|
5888
5888
|
disconnect() {
|
|
5889
5889
|
var _a;
|
|
5890
5890
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5891
|
-
|
|
5891
|
+
// cancel the stream and close the connection
|
|
5892
|
+
(_a = this._stream) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
5893
|
+
this._client.close();
|
|
5892
5894
|
});
|
|
5893
5895
|
}
|
|
5894
5896
|
resolveBoolean(flagKey, context, logger) {
|
|
@@ -5915,9 +5917,15 @@ class GRPCService {
|
|
|
5915
5917
|
return new Promise((resolve, reject) => {
|
|
5916
5918
|
var _a;
|
|
5917
5919
|
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: connecting stream, attempt ${this._streamConnectAttempt}...`);
|
|
5918
|
-
const stream = this._client.eventStream({});
|
|
5919
|
-
stream.on('error', () => {
|
|
5920
|
-
|
|
5920
|
+
const stream = this._client.eventStream({}, {});
|
|
5921
|
+
stream.on('error', (err) => {
|
|
5922
|
+
var _a;
|
|
5923
|
+
if ((err === null || err === void 0 ? void 0 : err.code) === grpcJs.status.CANCELLED) {
|
|
5924
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: stream cancelled, will not be re-established`);
|
|
5925
|
+
}
|
|
5926
|
+
else {
|
|
5927
|
+
this.handleError(reject, connectCallback, changedCallback, disconnectCallback);
|
|
5928
|
+
}
|
|
5921
5929
|
});
|
|
5922
5930
|
stream.on('close', () => {
|
|
5923
5931
|
this.handleClose();
|
|
@@ -6007,6 +6015,7 @@ class GRPCService {
|
|
|
6007
6015
|
value: parser.call(this, response.value),
|
|
6008
6016
|
reason: response.reason,
|
|
6009
6017
|
variant: response.variant,
|
|
6018
|
+
flagMetadata: response.metadata,
|
|
6010
6019
|
};
|
|
6011
6020
|
logger.debug(`${FlagdProvider.name}: resolved flag with key: ${resolved.value}, variant: ${response.variant}, reason: ${response.reason}`);
|
|
6012
6021
|
if (this._cacheActive && response.reason === jsSdk.StandardResolutionReasons.STATIC) {
|
package/index.js
CHANGED
|
@@ -5884,7 +5884,9 @@ class GRPCService {
|
|
|
5884
5884
|
disconnect() {
|
|
5885
5885
|
var _a;
|
|
5886
5886
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5887
|
-
|
|
5887
|
+
// cancel the stream and close the connection
|
|
5888
|
+
(_a = this._stream) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
5889
|
+
this._client.close();
|
|
5888
5890
|
});
|
|
5889
5891
|
}
|
|
5890
5892
|
resolveBoolean(flagKey, context, logger) {
|
|
@@ -5911,9 +5913,15 @@ class GRPCService {
|
|
|
5911
5913
|
return new Promise((resolve, reject) => {
|
|
5912
5914
|
var _a;
|
|
5913
5915
|
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: connecting stream, attempt ${this._streamConnectAttempt}...`);
|
|
5914
|
-
const stream = this._client.eventStream({});
|
|
5915
|
-
stream.on('error', () => {
|
|
5916
|
-
|
|
5916
|
+
const stream = this._client.eventStream({}, {});
|
|
5917
|
+
stream.on('error', (err) => {
|
|
5918
|
+
var _a;
|
|
5919
|
+
if ((err === null || err === void 0 ? void 0 : err.code) === status.CANCELLED) {
|
|
5920
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${FlagdProvider.name}: stream cancelled, will not be re-established`);
|
|
5921
|
+
}
|
|
5922
|
+
else {
|
|
5923
|
+
this.handleError(reject, connectCallback, changedCallback, disconnectCallback);
|
|
5924
|
+
}
|
|
5917
5925
|
});
|
|
5918
5926
|
stream.on('close', () => {
|
|
5919
5927
|
this.handleClose();
|
|
@@ -6003,6 +6011,7 @@ class GRPCService {
|
|
|
6003
6011
|
value: parser.call(this, response.value),
|
|
6004
6012
|
reason: response.reason,
|
|
6005
6013
|
variant: response.variant,
|
|
6014
|
+
flagMetadata: response.metadata,
|
|
6006
6015
|
};
|
|
6007
6016
|
logger.debug(`${FlagdProvider.name}: resolved flag with key: ${resolved.value}, variant: ${response.variant}, reason: ${response.reason}`);
|
|
6008
6017
|
if (this._cacheActive && response.reason === StandardResolutionReasons.STATIC) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/flagd-provider",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public; fi",
|
|
6
6
|
"current-version": "echo $npm_package_version"
|
|
@@ -2,7 +2,7 @@ import { EvaluationContext, JsonValue, Logger, OpenFeatureEventEmitter, Provider
|
|
|
2
2
|
import { FlagdProviderOptions } from './configuration';
|
|
3
3
|
import { Service } from './service/service';
|
|
4
4
|
export declare class FlagdProvider implements Provider {
|
|
5
|
-
private logger?;
|
|
5
|
+
private readonly logger?;
|
|
6
6
|
metadata: {
|
|
7
7
|
name: string;
|
|
8
8
|
};
|
|
File without changes
|