@openfeature/flagd-provider 0.13.2 → 0.13.3
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 +13 -0
- package/index.cjs.js +36 -7
- package/index.esm.js +36 -7
- package/package.json +1 -1
- package/src/lib/configuration.d.ts +6 -0
- package/src/proto/ts/flagd/evaluation/v1/evaluation.d.ts +5 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ Options can be defined in the constructor or as environment variables. Construct
|
|
|
38
38
|
| selector | FLAGD_SOURCE_SELECTOR | string | - | |
|
|
39
39
|
| cache | FLAGD_CACHE | string | lru | lru, disabled |
|
|
40
40
|
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |
|
|
41
|
+
| defaultAuthority | FLAGD_DEFAULT_AUTHORITY | string | - | rpc, in-process |
|
|
41
42
|
|
|
42
43
|
#### Resolver type-specific Defaults
|
|
43
44
|
|
|
@@ -93,6 +94,18 @@ To enable this mode, you should provide a valid flag configuration file with the
|
|
|
93
94
|
Offline mode uses `fs.watchFile` and polls every 5 seconds for changes to the file.
|
|
94
95
|
This mode is useful for local development, test cases, and for offline applications.
|
|
95
96
|
|
|
97
|
+
### Default Authority usage (optional)
|
|
98
|
+
|
|
99
|
+
This is useful for complex routing or service-discovery use cases that involve a proxy (e.g., Envoy).
|
|
100
|
+
Please refer to this [GitHub issue](https://github.com/open-feature/js-sdk-contrib/issues/1187) for more information.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
OpenFeature.setProvider(new FlagdProvider({
|
|
104
|
+
resolverType: 'in-process',
|
|
105
|
+
defaultAuthority: 'b-target-api.service',
|
|
106
|
+
}))
|
|
107
|
+
```
|
|
108
|
+
|
|
96
109
|
### Supported Events
|
|
97
110
|
|
|
98
111
|
The flagd provider emits `PROVIDER_READY`, `PROVIDER_ERROR` and `PROVIDER_CONFIGURATION_CHANGED` events.
|
package/index.cjs.js
CHANGED
|
@@ -64,10 +64,11 @@ var ENV_VAR;
|
|
|
64
64
|
ENV_VAR["FLAGD_SOURCE_SELECTOR"] = "FLAGD_SOURCE_SELECTOR";
|
|
65
65
|
ENV_VAR["FLAGD_RESOLVER"] = "FLAGD_RESOLVER";
|
|
66
66
|
ENV_VAR["FLAGD_OFFLINE_FLAG_SOURCE_PATH"] = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
|
|
67
|
+
ENV_VAR["FLAGD_DEFAULT_AUTHORITY"] = "FLAGD_DEFAULT_AUTHORITY";
|
|
67
68
|
})(ENV_VAR || (ENV_VAR = {}));
|
|
68
69
|
const getEnvVarConfig = () => {
|
|
69
70
|
var _a;
|
|
70
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
71
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
71
72
|
host: process.env[ENV_VAR.FLAGD_HOST],
|
|
72
73
|
})), (Number(process.env[ENV_VAR.FLAGD_PORT]) && {
|
|
73
74
|
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
|
|
@@ -85,6 +86,8 @@ const getEnvVarConfig = () => {
|
|
|
85
86
|
resolverType: process.env[ENV_VAR.FLAGD_RESOLVER],
|
|
86
87
|
})), (process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH] && {
|
|
87
88
|
offlineFlagSourcePath: process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH],
|
|
89
|
+
})), (process.env[ENV_VAR.FLAGD_DEFAULT_AUTHORITY] && {
|
|
90
|
+
defaultAuthority: process.env[ENV_VAR.FLAGD_DEFAULT_AUTHORITY],
|
|
88
91
|
})));
|
|
89
92
|
};
|
|
90
93
|
function getConfig(options = {}) {
|
|
@@ -4793,13 +4796,16 @@ const ResolveAllRequest = {
|
|
|
4793
4796
|
},
|
|
4794
4797
|
};
|
|
4795
4798
|
function createBaseResolveAllResponse() {
|
|
4796
|
-
return { flags: {} };
|
|
4799
|
+
return { flags: {}, metadata: undefined };
|
|
4797
4800
|
}
|
|
4798
4801
|
const ResolveAllResponse = {
|
|
4799
4802
|
encode(message, writer = _m0.Writer.create()) {
|
|
4800
4803
|
Object.entries(message.flags).forEach(([key, value]) => {
|
|
4801
4804
|
ResolveAllResponse_FlagsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
|
|
4802
4805
|
});
|
|
4806
|
+
if (message.metadata !== undefined) {
|
|
4807
|
+
Struct.encode(Struct.wrap(message.metadata), writer.uint32(18).fork()).ldelim();
|
|
4808
|
+
}
|
|
4803
4809
|
return writer;
|
|
4804
4810
|
},
|
|
4805
4811
|
decode(input, length) {
|
|
@@ -4818,6 +4824,12 @@ const ResolveAllResponse = {
|
|
|
4818
4824
|
message.flags[entry1.key] = entry1.value;
|
|
4819
4825
|
}
|
|
4820
4826
|
continue;
|
|
4827
|
+
case 2:
|
|
4828
|
+
if (tag !== 18) {
|
|
4829
|
+
break;
|
|
4830
|
+
}
|
|
4831
|
+
message.metadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
4832
|
+
continue;
|
|
4821
4833
|
}
|
|
4822
4834
|
if ((tag & 7) === 4 || tag === 0) {
|
|
4823
4835
|
break;
|
|
@@ -4834,6 +4846,7 @@ const ResolveAllResponse = {
|
|
|
4834
4846
|
return acc;
|
|
4835
4847
|
}, {})
|
|
4836
4848
|
: {},
|
|
4849
|
+
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
4837
4850
|
};
|
|
4838
4851
|
},
|
|
4839
4852
|
toJSON(message) {
|
|
@@ -4847,13 +4860,16 @@ const ResolveAllResponse = {
|
|
|
4847
4860
|
});
|
|
4848
4861
|
}
|
|
4849
4862
|
}
|
|
4863
|
+
if (message.metadata !== undefined) {
|
|
4864
|
+
obj.metadata = message.metadata;
|
|
4865
|
+
}
|
|
4850
4866
|
return obj;
|
|
4851
4867
|
},
|
|
4852
4868
|
create(base) {
|
|
4853
4869
|
return ResolveAllResponse.fromPartial(base !== null && base !== undefined ? base : {});
|
|
4854
4870
|
},
|
|
4855
4871
|
fromPartial(object) {
|
|
4856
|
-
var _a;
|
|
4872
|
+
var _a, _b;
|
|
4857
4873
|
const message = createBaseResolveAllResponse();
|
|
4858
4874
|
message.flags = Object.entries((_a = object.flags) !== null && _a !== undefined ? _a : {}).reduce((acc, [key, value]) => {
|
|
4859
4875
|
if (value !== undefined) {
|
|
@@ -4861,6 +4877,7 @@ const ResolveAllResponse = {
|
|
|
4861
4877
|
}
|
|
4862
4878
|
return acc;
|
|
4863
4879
|
}, {});
|
|
4880
|
+
message.metadata = (_b = object.metadata) !== null && _b !== undefined ? _b : undefined;
|
|
4864
4881
|
return message;
|
|
4865
4882
|
},
|
|
4866
4883
|
};
|
|
@@ -6109,10 +6126,16 @@ class GRPCService {
|
|
|
6109
6126
|
throw new serverSdk.GeneralError(err === null || err === undefined ? undefined : err.details);
|
|
6110
6127
|
}
|
|
6111
6128
|
};
|
|
6112
|
-
const { host, port, tls, socketPath } = config;
|
|
6129
|
+
const { host, port, tls, socketPath, defaultAuthority } = config;
|
|
6130
|
+
let clientOptions;
|
|
6131
|
+
if (defaultAuthority) {
|
|
6132
|
+
clientOptions = {
|
|
6133
|
+
'grpc.default_authority': defaultAuthority,
|
|
6134
|
+
};
|
|
6135
|
+
}
|
|
6113
6136
|
this._client = client
|
|
6114
6137
|
? client
|
|
6115
|
-
: new ServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? grpcJs.credentials.createSsl() : grpcJs.credentials.createInsecure());
|
|
6138
|
+
: new ServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? grpcJs.credentials.createSsl() : grpcJs.credentials.createInsecure(), clientOptions);
|
|
6116
6139
|
if (config.cache === 'lru') {
|
|
6117
6140
|
this._cacheEnabled = true;
|
|
6118
6141
|
this._cache = new lruCache.LRUCache({ maxSize: config.maxCacheSize || DEFAULT_MAX_CACHE_SIZE, sizeCalculation: () => 1 });
|
|
@@ -6670,10 +6693,16 @@ class GrpcFetch {
|
|
|
6670
6693
|
* false if the connection is lost.
|
|
6671
6694
|
*/
|
|
6672
6695
|
this._isConnected = false;
|
|
6673
|
-
const { host, port, tls, socketPath, selector } = config;
|
|
6696
|
+
const { host, port, tls, socketPath, selector, defaultAuthority } = config;
|
|
6697
|
+
let clientOptions;
|
|
6698
|
+
if (defaultAuthority) {
|
|
6699
|
+
clientOptions = {
|
|
6700
|
+
'grpc.default_authority': defaultAuthority,
|
|
6701
|
+
};
|
|
6702
|
+
}
|
|
6674
6703
|
this._syncClient = syncServiceClient
|
|
6675
6704
|
? syncServiceClient
|
|
6676
|
-
: new FlagSyncServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? grpcJs.credentials.createSsl() : grpcJs.credentials.createInsecure());
|
|
6705
|
+
: new FlagSyncServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? grpcJs.credentials.createSsl() : grpcJs.credentials.createInsecure(), clientOptions);
|
|
6677
6706
|
this._logger = logger;
|
|
6678
6707
|
this._request = { providerId: '', selector: selector ? selector : '' };
|
|
6679
6708
|
}
|
package/index.esm.js
CHANGED
|
@@ -62,10 +62,11 @@ var ENV_VAR;
|
|
|
62
62
|
ENV_VAR["FLAGD_SOURCE_SELECTOR"] = "FLAGD_SOURCE_SELECTOR";
|
|
63
63
|
ENV_VAR["FLAGD_RESOLVER"] = "FLAGD_RESOLVER";
|
|
64
64
|
ENV_VAR["FLAGD_OFFLINE_FLAG_SOURCE_PATH"] = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
|
|
65
|
+
ENV_VAR["FLAGD_DEFAULT_AUTHORITY"] = "FLAGD_DEFAULT_AUTHORITY";
|
|
65
66
|
})(ENV_VAR || (ENV_VAR = {}));
|
|
66
67
|
const getEnvVarConfig = () => {
|
|
67
68
|
var _a;
|
|
68
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
69
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
69
70
|
host: process.env[ENV_VAR.FLAGD_HOST],
|
|
70
71
|
})), (Number(process.env[ENV_VAR.FLAGD_PORT]) && {
|
|
71
72
|
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
|
|
@@ -83,6 +84,8 @@ const getEnvVarConfig = () => {
|
|
|
83
84
|
resolverType: process.env[ENV_VAR.FLAGD_RESOLVER],
|
|
84
85
|
})), (process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH] && {
|
|
85
86
|
offlineFlagSourcePath: process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH],
|
|
87
|
+
})), (process.env[ENV_VAR.FLAGD_DEFAULT_AUTHORITY] && {
|
|
88
|
+
defaultAuthority: process.env[ENV_VAR.FLAGD_DEFAULT_AUTHORITY],
|
|
86
89
|
})));
|
|
87
90
|
};
|
|
88
91
|
function getConfig(options = {}) {
|
|
@@ -4791,13 +4794,16 @@ const ResolveAllRequest = {
|
|
|
4791
4794
|
},
|
|
4792
4795
|
};
|
|
4793
4796
|
function createBaseResolveAllResponse() {
|
|
4794
|
-
return { flags: {} };
|
|
4797
|
+
return { flags: {}, metadata: undefined };
|
|
4795
4798
|
}
|
|
4796
4799
|
const ResolveAllResponse = {
|
|
4797
4800
|
encode(message, writer = _m0.Writer.create()) {
|
|
4798
4801
|
Object.entries(message.flags).forEach(([key, value]) => {
|
|
4799
4802
|
ResolveAllResponse_FlagsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
|
|
4800
4803
|
});
|
|
4804
|
+
if (message.metadata !== undefined) {
|
|
4805
|
+
Struct.encode(Struct.wrap(message.metadata), writer.uint32(18).fork()).ldelim();
|
|
4806
|
+
}
|
|
4801
4807
|
return writer;
|
|
4802
4808
|
},
|
|
4803
4809
|
decode(input, length) {
|
|
@@ -4816,6 +4822,12 @@ const ResolveAllResponse = {
|
|
|
4816
4822
|
message.flags[entry1.key] = entry1.value;
|
|
4817
4823
|
}
|
|
4818
4824
|
continue;
|
|
4825
|
+
case 2:
|
|
4826
|
+
if (tag !== 18) {
|
|
4827
|
+
break;
|
|
4828
|
+
}
|
|
4829
|
+
message.metadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
|
4830
|
+
continue;
|
|
4819
4831
|
}
|
|
4820
4832
|
if ((tag & 7) === 4 || tag === 0) {
|
|
4821
4833
|
break;
|
|
@@ -4832,6 +4844,7 @@ const ResolveAllResponse = {
|
|
|
4832
4844
|
return acc;
|
|
4833
4845
|
}, {})
|
|
4834
4846
|
: {},
|
|
4847
|
+
metadata: isObject$1(object.metadata) ? object.metadata : undefined,
|
|
4835
4848
|
};
|
|
4836
4849
|
},
|
|
4837
4850
|
toJSON(message) {
|
|
@@ -4845,13 +4858,16 @@ const ResolveAllResponse = {
|
|
|
4845
4858
|
});
|
|
4846
4859
|
}
|
|
4847
4860
|
}
|
|
4861
|
+
if (message.metadata !== undefined) {
|
|
4862
|
+
obj.metadata = message.metadata;
|
|
4863
|
+
}
|
|
4848
4864
|
return obj;
|
|
4849
4865
|
},
|
|
4850
4866
|
create(base) {
|
|
4851
4867
|
return ResolveAllResponse.fromPartial(base !== null && base !== undefined ? base : {});
|
|
4852
4868
|
},
|
|
4853
4869
|
fromPartial(object) {
|
|
4854
|
-
var _a;
|
|
4870
|
+
var _a, _b;
|
|
4855
4871
|
const message = createBaseResolveAllResponse();
|
|
4856
4872
|
message.flags = Object.entries((_a = object.flags) !== null && _a !== undefined ? _a : {}).reduce((acc, [key, value]) => {
|
|
4857
4873
|
if (value !== undefined) {
|
|
@@ -4859,6 +4875,7 @@ const ResolveAllResponse = {
|
|
|
4859
4875
|
}
|
|
4860
4876
|
return acc;
|
|
4861
4877
|
}, {});
|
|
4878
|
+
message.metadata = (_b = object.metadata) !== null && _b !== undefined ? _b : undefined;
|
|
4862
4879
|
return message;
|
|
4863
4880
|
},
|
|
4864
4881
|
};
|
|
@@ -6107,10 +6124,16 @@ class GRPCService {
|
|
|
6107
6124
|
throw new GeneralError(err === null || err === undefined ? undefined : err.details);
|
|
6108
6125
|
}
|
|
6109
6126
|
};
|
|
6110
|
-
const { host, port, tls, socketPath } = config;
|
|
6127
|
+
const { host, port, tls, socketPath, defaultAuthority } = config;
|
|
6128
|
+
let clientOptions;
|
|
6129
|
+
if (defaultAuthority) {
|
|
6130
|
+
clientOptions = {
|
|
6131
|
+
'grpc.default_authority': defaultAuthority,
|
|
6132
|
+
};
|
|
6133
|
+
}
|
|
6111
6134
|
this._client = client
|
|
6112
6135
|
? client
|
|
6113
|
-
: new ServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? credentials.createSsl() : credentials.createInsecure());
|
|
6136
|
+
: new ServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? credentials.createSsl() : credentials.createInsecure(), clientOptions);
|
|
6114
6137
|
if (config.cache === 'lru') {
|
|
6115
6138
|
this._cacheEnabled = true;
|
|
6116
6139
|
this._cache = new LRUCache({ maxSize: config.maxCacheSize || DEFAULT_MAX_CACHE_SIZE, sizeCalculation: () => 1 });
|
|
@@ -6668,10 +6691,16 @@ class GrpcFetch {
|
|
|
6668
6691
|
* false if the connection is lost.
|
|
6669
6692
|
*/
|
|
6670
6693
|
this._isConnected = false;
|
|
6671
|
-
const { host, port, tls, socketPath, selector } = config;
|
|
6694
|
+
const { host, port, tls, socketPath, selector, defaultAuthority } = config;
|
|
6695
|
+
let clientOptions;
|
|
6696
|
+
if (defaultAuthority) {
|
|
6697
|
+
clientOptions = {
|
|
6698
|
+
'grpc.default_authority': defaultAuthority,
|
|
6699
|
+
};
|
|
6700
|
+
}
|
|
6672
6701
|
this._syncClient = syncServiceClient
|
|
6673
6702
|
? syncServiceClient
|
|
6674
|
-
: new FlagSyncServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? credentials.createSsl() : credentials.createInsecure());
|
|
6703
|
+
: new FlagSyncServiceClient(socketPath ? `unix://${socketPath}` : `${host}:${port}`, tls ? credentials.createSsl() : credentials.createInsecure(), clientOptions);
|
|
6675
6704
|
this._logger = logger;
|
|
6676
6705
|
this._request = { providerId: '', selector: selector ? selector : '' };
|
|
6677
6706
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/flagd-provider",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"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",
|
|
@@ -57,6 +57,11 @@ export interface Config {
|
|
|
57
57
|
* @default 1000
|
|
58
58
|
*/
|
|
59
59
|
maxCacheSize?: number;
|
|
60
|
+
/**
|
|
61
|
+
* The target host (authority) when routing requests through a proxy (e.g. Envoy)
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
defaultAuthority?: string;
|
|
60
65
|
}
|
|
61
66
|
export type FlagdProviderOptions = Partial<Config>;
|
|
62
67
|
export declare function getConfig(options?: FlagdProviderOptions): {
|
|
@@ -69,4 +74,5 @@ export declare function getConfig(options?: FlagdProviderOptions): {
|
|
|
69
74
|
selector?: string;
|
|
70
75
|
cache?: CacheOption;
|
|
71
76
|
maxCacheSize?: number;
|
|
77
|
+
defaultAuthority?: string;
|
|
72
78
|
};
|
|
@@ -21,6 +21,10 @@ export interface ResolveAllResponse {
|
|
|
21
21
|
flags: {
|
|
22
22
|
[key: string]: AnyFlag;
|
|
23
23
|
};
|
|
24
|
+
/** Metadata for the bulk evaluation */
|
|
25
|
+
metadata: {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
} | undefined;
|
|
24
28
|
}
|
|
25
29
|
export interface ResolveAllResponse_FlagsEntry {
|
|
26
30
|
key: string;
|
|
@@ -38,7 +42,7 @@ export interface AnyFlag {
|
|
|
38
42
|
objectValue?: {
|
|
39
43
|
[key: string]: any;
|
|
40
44
|
} | undefined;
|
|
41
|
-
/** Metadata
|
|
45
|
+
/** Metadata for this evaluation */
|
|
42
46
|
metadata: {
|
|
43
47
|
[key: string]: any;
|
|
44
48
|
} | undefined;
|