@openfeature/flagd-provider 0.10.4 → 0.11.0
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 +2 -1
- package/index.cjs.js +218 -140
- package/index.esm.js +218 -140
- package/package.json +3 -3
- package/src/e2e/constants.d.ts +4 -0
- package/src/lib/service/grpc/grpc-service.d.ts +1 -1
- package/src/lib/service/in-process/grpc/grpc-fetch.d.ts +2 -1
package/README.md
CHANGED
|
@@ -34,8 +34,9 @@ Options can be defined in the constructor or as environment variables. Construct
|
|
|
34
34
|
| tls | FLAGD_TLS | boolean | false | |
|
|
35
35
|
| socketPath | FLAGD_SOCKET_PATH | string | - | |
|
|
36
36
|
| resolverType | FLAGD_SOURCE_RESOLVER | string | rpc | rpc, in-process |
|
|
37
|
+
| offlineFlagSourcePath | FLAGD_OFFLINE_FLAG_SOURCE_PATH | string | - | |
|
|
37
38
|
| selector | FLAGD_SOURCE_SELECTOR | string | - | |
|
|
38
|
-
| cache | FLAGD_CACHE | string | lru | lru,disabled
|
|
39
|
+
| cache | FLAGD_CACHE | string | lru | lru, disabled |
|
|
39
40
|
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |
|
|
40
41
|
|
|
41
42
|
Below are examples of usage patterns.
|
package/index.cjs.js
CHANGED
|
@@ -34,10 +34,11 @@ var ENV_VAR;
|
|
|
34
34
|
ENV_VAR["FLAGD_MAX_CACHE_SIZE"] = "FLAGD_MAX_CACHE_SIZE";
|
|
35
35
|
ENV_VAR["FLAGD_SOURCE_SELECTOR"] = "FLAGD_SOURCE_SELECTOR";
|
|
36
36
|
ENV_VAR["FLAGD_RESOLVER"] = "FLAGD_RESOLVER";
|
|
37
|
+
ENV_VAR["FLAGD_OFFLINE_FLAG_SOURCE_PATH"] = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
|
|
37
38
|
})(ENV_VAR || (ENV_VAR = {}));
|
|
38
39
|
const getEnvVarConfig = () => {
|
|
39
40
|
var _a;
|
|
40
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
41
|
+
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] && {
|
|
41
42
|
host: process.env[ENV_VAR.FLAGD_HOST],
|
|
42
43
|
})), (Number(process.env[ENV_VAR.FLAGD_PORT]) && {
|
|
43
44
|
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
|
|
@@ -53,6 +54,8 @@ const getEnvVarConfig = () => {
|
|
|
53
54
|
selector: process.env[ENV_VAR.FLAGD_SOURCE_SELECTOR],
|
|
54
55
|
})), ((process.env[ENV_VAR.FLAGD_RESOLVER] === 'rpc' || process.env[ENV_VAR.FLAGD_RESOLVER] === 'in-process') && {
|
|
55
56
|
resolverType: process.env[ENV_VAR.FLAGD_RESOLVER],
|
|
57
|
+
})), (process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH] && {
|
|
58
|
+
offlineFlagSourcePath: process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH],
|
|
56
59
|
})));
|
|
57
60
|
};
|
|
58
61
|
function getConfig(options = {}) {
|
|
@@ -5753,7 +5756,7 @@ const EventStreamRequest = {
|
|
|
5753
5756
|
};
|
|
5754
5757
|
const ServiceService = {
|
|
5755
5758
|
resolveAll: {
|
|
5756
|
-
path: "/
|
|
5759
|
+
path: "/flagd.evaluation.v1.Service/ResolveAll",
|
|
5757
5760
|
requestStream: false,
|
|
5758
5761
|
responseStream: false,
|
|
5759
5762
|
requestSerialize: (value) => Buffer.from(ResolveAllRequest.encode(value).finish()),
|
|
@@ -5762,7 +5765,7 @@ const ServiceService = {
|
|
|
5762
5765
|
responseDeserialize: (value) => ResolveAllResponse.decode(value),
|
|
5763
5766
|
},
|
|
5764
5767
|
resolveBoolean: {
|
|
5765
|
-
path: "/
|
|
5768
|
+
path: "/flagd.evaluation.v1.Service/ResolveBoolean",
|
|
5766
5769
|
requestStream: false,
|
|
5767
5770
|
responseStream: false,
|
|
5768
5771
|
requestSerialize: (value) => Buffer.from(ResolveBooleanRequest.encode(value).finish()),
|
|
@@ -5771,7 +5774,7 @@ const ServiceService = {
|
|
|
5771
5774
|
responseDeserialize: (value) => ResolveBooleanResponse.decode(value),
|
|
5772
5775
|
},
|
|
5773
5776
|
resolveString: {
|
|
5774
|
-
path: "/
|
|
5777
|
+
path: "/flagd.evaluation.v1.Service/ResolveString",
|
|
5775
5778
|
requestStream: false,
|
|
5776
5779
|
responseStream: false,
|
|
5777
5780
|
requestSerialize: (value) => Buffer.from(ResolveStringRequest.encode(value).finish()),
|
|
@@ -5780,7 +5783,7 @@ const ServiceService = {
|
|
|
5780
5783
|
responseDeserialize: (value) => ResolveStringResponse.decode(value),
|
|
5781
5784
|
},
|
|
5782
5785
|
resolveFloat: {
|
|
5783
|
-
path: "/
|
|
5786
|
+
path: "/flagd.evaluation.v1.Service/ResolveFloat",
|
|
5784
5787
|
requestStream: false,
|
|
5785
5788
|
responseStream: false,
|
|
5786
5789
|
requestSerialize: (value) => Buffer.from(ResolveFloatRequest.encode(value).finish()),
|
|
@@ -5789,7 +5792,7 @@ const ServiceService = {
|
|
|
5789
5792
|
responseDeserialize: (value) => ResolveFloatResponse.decode(value),
|
|
5790
5793
|
},
|
|
5791
5794
|
resolveInt: {
|
|
5792
|
-
path: "/
|
|
5795
|
+
path: "/flagd.evaluation.v1.Service/ResolveInt",
|
|
5793
5796
|
requestStream: false,
|
|
5794
5797
|
responseStream: false,
|
|
5795
5798
|
requestSerialize: (value) => Buffer.from(ResolveIntRequest.encode(value).finish()),
|
|
@@ -5798,7 +5801,7 @@ const ServiceService = {
|
|
|
5798
5801
|
responseDeserialize: (value) => ResolveIntResponse.decode(value),
|
|
5799
5802
|
},
|
|
5800
5803
|
resolveObject: {
|
|
5801
|
-
path: "/
|
|
5804
|
+
path: "/flagd.evaluation.v1.Service/ResolveObject",
|
|
5802
5805
|
requestStream: false,
|
|
5803
5806
|
responseStream: false,
|
|
5804
5807
|
requestSerialize: (value) => Buffer.from(ResolveObjectRequest.encode(value).finish()),
|
|
@@ -5807,7 +5810,7 @@ const ServiceService = {
|
|
|
5807
5810
|
responseDeserialize: (value) => ResolveObjectResponse.decode(value),
|
|
5808
5811
|
},
|
|
5809
5812
|
eventStream: {
|
|
5810
|
-
path: "/
|
|
5813
|
+
path: "/flagd.evaluation.v1.Service/EventStream",
|
|
5811
5814
|
requestStream: false,
|
|
5812
5815
|
responseStream: true,
|
|
5813
5816
|
requestSerialize: (value) => Buffer.from(EventStreamRequest.encode(value).finish()),
|
|
@@ -5816,7 +5819,7 @@ const ServiceService = {
|
|
|
5816
5819
|
responseDeserialize: (value) => EventStreamResponse.decode(value),
|
|
5817
5820
|
},
|
|
5818
5821
|
};
|
|
5819
|
-
const ServiceClient = grpcJs.makeGenericClientConstructor(ServiceService, "
|
|
5822
|
+
const ServiceClient = grpcJs.makeGenericClientConstructor(ServiceService, "flagd.evaluation.v1.Service");
|
|
5820
5823
|
function longToString(long) {
|
|
5821
5824
|
return long.toString();
|
|
5822
5825
|
}
|
|
@@ -6001,83 +6004,6 @@ class GRPCService {
|
|
|
6001
6004
|
}
|
|
6002
6005
|
|
|
6003
6006
|
/* eslint-disable */
|
|
6004
|
-
/**
|
|
6005
|
-
* Flag definition sync API
|
|
6006
|
-
*
|
|
6007
|
-
* This proto defines a simple API to synchronize a feature flag definition.
|
|
6008
|
-
* It supports establishing a stream for getting notifications about changes in a flag definition.
|
|
6009
|
-
*/
|
|
6010
|
-
/**
|
|
6011
|
-
* SyncState conveys the state of the payload. These states are related to flagd isync.go type definitions but
|
|
6012
|
-
* contains extras to optimize grpc use case. Refer - https://github.com/open-feature/flagd/blob/main/pkg/sync/isync.go
|
|
6013
|
-
*/
|
|
6014
|
-
var SyncState;
|
|
6015
|
-
(function (SyncState) {
|
|
6016
|
-
/** SYNC_STATE_UNSPECIFIED - Value is ignored by the listening flagd */
|
|
6017
|
-
SyncState[SyncState["SYNC_STATE_UNSPECIFIED"] = 0] = "SYNC_STATE_UNSPECIFIED";
|
|
6018
|
-
/**
|
|
6019
|
-
* SYNC_STATE_ALL - All the flags matching the request. This is the default response and other states can be ignored
|
|
6020
|
-
* by the implementation. Flagd internally replaces all existing flags for this response state.
|
|
6021
|
-
*/
|
|
6022
|
-
SyncState[SyncState["SYNC_STATE_ALL"] = 1] = "SYNC_STATE_ALL";
|
|
6023
|
-
/** SYNC_STATE_ADD - Convey an addition of a flag. Flagd internally handles this by combining new flags with existing ones */
|
|
6024
|
-
SyncState[SyncState["SYNC_STATE_ADD"] = 2] = "SYNC_STATE_ADD";
|
|
6025
|
-
/**
|
|
6026
|
-
* SYNC_STATE_UPDATE - Convey an update of a flag. Flagd internally attempts to update if the updated flag already exist OR if it does not,
|
|
6027
|
-
* it will get added
|
|
6028
|
-
*/
|
|
6029
|
-
SyncState[SyncState["SYNC_STATE_UPDATE"] = 3] = "SYNC_STATE_UPDATE";
|
|
6030
|
-
/** SYNC_STATE_DELETE - Convey a deletion of a flag. Flagd internally removes the flag */
|
|
6031
|
-
SyncState[SyncState["SYNC_STATE_DELETE"] = 4] = "SYNC_STATE_DELETE";
|
|
6032
|
-
/** SYNC_STATE_PING - Optional server ping to check client connectivity. Handling is ignored by flagd and is to merely support live check */
|
|
6033
|
-
SyncState[SyncState["SYNC_STATE_PING"] = 5] = "SYNC_STATE_PING";
|
|
6034
|
-
SyncState[SyncState["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
6035
|
-
})(SyncState || (SyncState = {}));
|
|
6036
|
-
function syncStateFromJSON(object) {
|
|
6037
|
-
switch (object) {
|
|
6038
|
-
case 0:
|
|
6039
|
-
case "SYNC_STATE_UNSPECIFIED":
|
|
6040
|
-
return SyncState.SYNC_STATE_UNSPECIFIED;
|
|
6041
|
-
case 1:
|
|
6042
|
-
case "SYNC_STATE_ALL":
|
|
6043
|
-
return SyncState.SYNC_STATE_ALL;
|
|
6044
|
-
case 2:
|
|
6045
|
-
case "SYNC_STATE_ADD":
|
|
6046
|
-
return SyncState.SYNC_STATE_ADD;
|
|
6047
|
-
case 3:
|
|
6048
|
-
case "SYNC_STATE_UPDATE":
|
|
6049
|
-
return SyncState.SYNC_STATE_UPDATE;
|
|
6050
|
-
case 4:
|
|
6051
|
-
case "SYNC_STATE_DELETE":
|
|
6052
|
-
return SyncState.SYNC_STATE_DELETE;
|
|
6053
|
-
case 5:
|
|
6054
|
-
case "SYNC_STATE_PING":
|
|
6055
|
-
return SyncState.SYNC_STATE_PING;
|
|
6056
|
-
case -1:
|
|
6057
|
-
case "UNRECOGNIZED":
|
|
6058
|
-
default:
|
|
6059
|
-
return SyncState.UNRECOGNIZED;
|
|
6060
|
-
}
|
|
6061
|
-
}
|
|
6062
|
-
function syncStateToJSON(object) {
|
|
6063
|
-
switch (object) {
|
|
6064
|
-
case SyncState.SYNC_STATE_UNSPECIFIED:
|
|
6065
|
-
return "SYNC_STATE_UNSPECIFIED";
|
|
6066
|
-
case SyncState.SYNC_STATE_ALL:
|
|
6067
|
-
return "SYNC_STATE_ALL";
|
|
6068
|
-
case SyncState.SYNC_STATE_ADD:
|
|
6069
|
-
return "SYNC_STATE_ADD";
|
|
6070
|
-
case SyncState.SYNC_STATE_UPDATE:
|
|
6071
|
-
return "SYNC_STATE_UPDATE";
|
|
6072
|
-
case SyncState.SYNC_STATE_DELETE:
|
|
6073
|
-
return "SYNC_STATE_DELETE";
|
|
6074
|
-
case SyncState.SYNC_STATE_PING:
|
|
6075
|
-
return "SYNC_STATE_PING";
|
|
6076
|
-
case SyncState.UNRECOGNIZED:
|
|
6077
|
-
default:
|
|
6078
|
-
return "UNRECOGNIZED";
|
|
6079
|
-
}
|
|
6080
|
-
}
|
|
6081
6007
|
function createBaseSyncFlagsRequest() {
|
|
6082
6008
|
return { providerId: "", selector: "" };
|
|
6083
6009
|
}
|
|
@@ -6146,16 +6072,13 @@ const SyncFlagsRequest = {
|
|
|
6146
6072
|
},
|
|
6147
6073
|
};
|
|
6148
6074
|
function createBaseSyncFlagsResponse() {
|
|
6149
|
-
return { flagConfiguration: ""
|
|
6075
|
+
return { flagConfiguration: "" };
|
|
6150
6076
|
}
|
|
6151
6077
|
const SyncFlagsResponse = {
|
|
6152
6078
|
encode(message, writer = minimal.Writer.create()) {
|
|
6153
6079
|
if (message.flagConfiguration !== "") {
|
|
6154
6080
|
writer.uint32(10).string(message.flagConfiguration);
|
|
6155
6081
|
}
|
|
6156
|
-
if (message.state !== 0) {
|
|
6157
|
-
writer.uint32(16).int32(message.state);
|
|
6158
|
-
}
|
|
6159
6082
|
return writer;
|
|
6160
6083
|
},
|
|
6161
6084
|
decode(input, length) {
|
|
@@ -6171,12 +6094,6 @@ const SyncFlagsResponse = {
|
|
|
6171
6094
|
}
|
|
6172
6095
|
message.flagConfiguration = reader.string();
|
|
6173
6096
|
continue;
|
|
6174
|
-
case 2:
|
|
6175
|
-
if (tag !== 16) {
|
|
6176
|
-
break;
|
|
6177
|
-
}
|
|
6178
|
-
message.state = reader.int32();
|
|
6179
|
-
continue;
|
|
6180
6097
|
}
|
|
6181
6098
|
if ((tag & 7) === 4 || tag === 0) {
|
|
6182
6099
|
break;
|
|
@@ -6186,29 +6103,22 @@ const SyncFlagsResponse = {
|
|
|
6186
6103
|
return message;
|
|
6187
6104
|
},
|
|
6188
6105
|
fromJSON(object) {
|
|
6189
|
-
return {
|
|
6190
|
-
flagConfiguration: isSet(object.flagConfiguration) ? String(object.flagConfiguration) : "",
|
|
6191
|
-
state: isSet(object.state) ? syncStateFromJSON(object.state) : 0,
|
|
6192
|
-
};
|
|
6106
|
+
return { flagConfiguration: isSet(object.flagConfiguration) ? String(object.flagConfiguration) : "" };
|
|
6193
6107
|
},
|
|
6194
6108
|
toJSON(message) {
|
|
6195
6109
|
const obj = {};
|
|
6196
6110
|
if (message.flagConfiguration !== "") {
|
|
6197
6111
|
obj.flagConfiguration = message.flagConfiguration;
|
|
6198
6112
|
}
|
|
6199
|
-
if (message.state !== 0) {
|
|
6200
|
-
obj.state = syncStateToJSON(message.state);
|
|
6201
|
-
}
|
|
6202
6113
|
return obj;
|
|
6203
6114
|
},
|
|
6204
6115
|
create(base) {
|
|
6205
6116
|
return SyncFlagsResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6206
6117
|
},
|
|
6207
6118
|
fromPartial(object) {
|
|
6208
|
-
var _a
|
|
6119
|
+
var _a;
|
|
6209
6120
|
const message = createBaseSyncFlagsResponse();
|
|
6210
6121
|
message.flagConfiguration = (_a = object.flagConfiguration) !== null && _a !== void 0 ? _a : "";
|
|
6211
|
-
message.state = (_b = object.state) !== null && _b !== void 0 ? _b : 0;
|
|
6212
6122
|
return message;
|
|
6213
6123
|
},
|
|
6214
6124
|
};
|
|
@@ -6330,9 +6240,160 @@ const FetchAllFlagsResponse = {
|
|
|
6330
6240
|
return message;
|
|
6331
6241
|
},
|
|
6332
6242
|
};
|
|
6243
|
+
function createBaseGetMetadataRequest() {
|
|
6244
|
+
return {};
|
|
6245
|
+
}
|
|
6246
|
+
const GetMetadataRequest = {
|
|
6247
|
+
encode(_, writer = minimal.Writer.create()) {
|
|
6248
|
+
return writer;
|
|
6249
|
+
},
|
|
6250
|
+
decode(input, length) {
|
|
6251
|
+
const reader = input instanceof minimal.Reader ? input : minimal.Reader.create(input);
|
|
6252
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
6253
|
+
const message = createBaseGetMetadataRequest();
|
|
6254
|
+
while (reader.pos < end) {
|
|
6255
|
+
const tag = reader.uint32();
|
|
6256
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
6257
|
+
break;
|
|
6258
|
+
}
|
|
6259
|
+
reader.skipType(tag & 7);
|
|
6260
|
+
}
|
|
6261
|
+
return message;
|
|
6262
|
+
},
|
|
6263
|
+
fromJSON(_) {
|
|
6264
|
+
return {};
|
|
6265
|
+
},
|
|
6266
|
+
toJSON(_) {
|
|
6267
|
+
const obj = {};
|
|
6268
|
+
return obj;
|
|
6269
|
+
},
|
|
6270
|
+
create(base) {
|
|
6271
|
+
return GetMetadataRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6272
|
+
},
|
|
6273
|
+
fromPartial(_) {
|
|
6274
|
+
const message = createBaseGetMetadataRequest();
|
|
6275
|
+
return message;
|
|
6276
|
+
},
|
|
6277
|
+
};
|
|
6278
|
+
function createBaseGetMetadataResponse() {
|
|
6279
|
+
return { metadata: [] };
|
|
6280
|
+
}
|
|
6281
|
+
const GetMetadataResponse = {
|
|
6282
|
+
encode(message, writer = minimal.Writer.create()) {
|
|
6283
|
+
for (const v of message.metadata) {
|
|
6284
|
+
KeyValue.encode(v, writer.uint32(10).fork()).ldelim();
|
|
6285
|
+
}
|
|
6286
|
+
return writer;
|
|
6287
|
+
},
|
|
6288
|
+
decode(input, length) {
|
|
6289
|
+
const reader = input instanceof minimal.Reader ? input : minimal.Reader.create(input);
|
|
6290
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
6291
|
+
const message = createBaseGetMetadataResponse();
|
|
6292
|
+
while (reader.pos < end) {
|
|
6293
|
+
const tag = reader.uint32();
|
|
6294
|
+
switch (tag >>> 3) {
|
|
6295
|
+
case 1:
|
|
6296
|
+
if (tag !== 10) {
|
|
6297
|
+
break;
|
|
6298
|
+
}
|
|
6299
|
+
message.metadata.push(KeyValue.decode(reader, reader.uint32()));
|
|
6300
|
+
continue;
|
|
6301
|
+
}
|
|
6302
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
6303
|
+
break;
|
|
6304
|
+
}
|
|
6305
|
+
reader.skipType(tag & 7);
|
|
6306
|
+
}
|
|
6307
|
+
return message;
|
|
6308
|
+
},
|
|
6309
|
+
fromJSON(object) {
|
|
6310
|
+
return { metadata: Array.isArray(object === null || object === void 0 ? void 0 : object.metadata) ? object.metadata.map((e) => KeyValue.fromJSON(e)) : [] };
|
|
6311
|
+
},
|
|
6312
|
+
toJSON(message) {
|
|
6313
|
+
var _a;
|
|
6314
|
+
const obj = {};
|
|
6315
|
+
if ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.length) {
|
|
6316
|
+
obj.metadata = message.metadata.map((e) => KeyValue.toJSON(e));
|
|
6317
|
+
}
|
|
6318
|
+
return obj;
|
|
6319
|
+
},
|
|
6320
|
+
create(base) {
|
|
6321
|
+
return GetMetadataResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6322
|
+
},
|
|
6323
|
+
fromPartial(object) {
|
|
6324
|
+
var _a;
|
|
6325
|
+
const message = createBaseGetMetadataResponse();
|
|
6326
|
+
message.metadata = ((_a = object.metadata) === null || _a === void 0 ? void 0 : _a.map((e) => KeyValue.fromPartial(e))) || [];
|
|
6327
|
+
return message;
|
|
6328
|
+
},
|
|
6329
|
+
};
|
|
6330
|
+
function createBaseKeyValue() {
|
|
6331
|
+
return { key: "", value: "" };
|
|
6332
|
+
}
|
|
6333
|
+
const KeyValue = {
|
|
6334
|
+
encode(message, writer = minimal.Writer.create()) {
|
|
6335
|
+
if (message.key !== "") {
|
|
6336
|
+
writer.uint32(10).string(message.key);
|
|
6337
|
+
}
|
|
6338
|
+
if (message.value !== "") {
|
|
6339
|
+
writer.uint32(18).string(message.value);
|
|
6340
|
+
}
|
|
6341
|
+
return writer;
|
|
6342
|
+
},
|
|
6343
|
+
decode(input, length) {
|
|
6344
|
+
const reader = input instanceof minimal.Reader ? input : minimal.Reader.create(input);
|
|
6345
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
6346
|
+
const message = createBaseKeyValue();
|
|
6347
|
+
while (reader.pos < end) {
|
|
6348
|
+
const tag = reader.uint32();
|
|
6349
|
+
switch (tag >>> 3) {
|
|
6350
|
+
case 1:
|
|
6351
|
+
if (tag !== 10) {
|
|
6352
|
+
break;
|
|
6353
|
+
}
|
|
6354
|
+
message.key = reader.string();
|
|
6355
|
+
continue;
|
|
6356
|
+
case 2:
|
|
6357
|
+
if (tag !== 18) {
|
|
6358
|
+
break;
|
|
6359
|
+
}
|
|
6360
|
+
message.value = reader.string();
|
|
6361
|
+
continue;
|
|
6362
|
+
}
|
|
6363
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
6364
|
+
break;
|
|
6365
|
+
}
|
|
6366
|
+
reader.skipType(tag & 7);
|
|
6367
|
+
}
|
|
6368
|
+
return message;
|
|
6369
|
+
},
|
|
6370
|
+
fromJSON(object) {
|
|
6371
|
+
return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" };
|
|
6372
|
+
},
|
|
6373
|
+
toJSON(message) {
|
|
6374
|
+
const obj = {};
|
|
6375
|
+
if (message.key !== "") {
|
|
6376
|
+
obj.key = message.key;
|
|
6377
|
+
}
|
|
6378
|
+
if (message.value !== "") {
|
|
6379
|
+
obj.value = message.value;
|
|
6380
|
+
}
|
|
6381
|
+
return obj;
|
|
6382
|
+
},
|
|
6383
|
+
create(base) {
|
|
6384
|
+
return KeyValue.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6385
|
+
},
|
|
6386
|
+
fromPartial(object) {
|
|
6387
|
+
var _a, _b;
|
|
6388
|
+
const message = createBaseKeyValue();
|
|
6389
|
+
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
|
|
6390
|
+
message.value = (_b = object.value) !== null && _b !== void 0 ? _b : "";
|
|
6391
|
+
return message;
|
|
6392
|
+
},
|
|
6393
|
+
};
|
|
6333
6394
|
const FlagSyncServiceService = {
|
|
6334
6395
|
syncFlags: {
|
|
6335
|
-
path: "/sync.v1.FlagSyncService/SyncFlags",
|
|
6396
|
+
path: "/flagd.sync.v1.FlagSyncService/SyncFlags",
|
|
6336
6397
|
requestStream: false,
|
|
6337
6398
|
responseStream: true,
|
|
6338
6399
|
requestSerialize: (value) => Buffer.from(SyncFlagsRequest.encode(value).finish()),
|
|
@@ -6341,7 +6402,7 @@ const FlagSyncServiceService = {
|
|
|
6341
6402
|
responseDeserialize: (value) => SyncFlagsResponse.decode(value),
|
|
6342
6403
|
},
|
|
6343
6404
|
fetchAllFlags: {
|
|
6344
|
-
path: "/sync.v1.FlagSyncService/FetchAllFlags",
|
|
6405
|
+
path: "/flagd.sync.v1.FlagSyncService/FetchAllFlags",
|
|
6345
6406
|
requestStream: false,
|
|
6346
6407
|
responseStream: false,
|
|
6347
6408
|
requestSerialize: (value) => Buffer.from(FetchAllFlagsRequest.encode(value).finish()),
|
|
@@ -6349,8 +6410,17 @@ const FlagSyncServiceService = {
|
|
|
6349
6410
|
responseSerialize: (value) => Buffer.from(FetchAllFlagsResponse.encode(value).finish()),
|
|
6350
6411
|
responseDeserialize: (value) => FetchAllFlagsResponse.decode(value),
|
|
6351
6412
|
},
|
|
6413
|
+
getMetadata: {
|
|
6414
|
+
path: "/flagd.sync.v1.FlagSyncService/GetMetadata",
|
|
6415
|
+
requestStream: false,
|
|
6416
|
+
responseStream: false,
|
|
6417
|
+
requestSerialize: (value) => Buffer.from(GetMetadataRequest.encode(value).finish()),
|
|
6418
|
+
requestDeserialize: (value) => GetMetadataRequest.decode(value),
|
|
6419
|
+
responseSerialize: (value) => Buffer.from(GetMetadataResponse.encode(value).finish()),
|
|
6420
|
+
responseDeserialize: (value) => GetMetadataResponse.decode(value),
|
|
6421
|
+
},
|
|
6352
6422
|
};
|
|
6353
|
-
const FlagSyncServiceClient = grpcJs.makeGenericClientConstructor(FlagSyncServiceService, "sync.v1.FlagSyncService");
|
|
6423
|
+
const FlagSyncServiceClient = grpcJs.makeGenericClientConstructor(FlagSyncServiceService, "flagd.sync.v1.FlagSyncService");
|
|
6354
6424
|
function isSet(value) {
|
|
6355
6425
|
return value !== null && value !== undefined;
|
|
6356
6426
|
}
|
|
@@ -6396,39 +6466,47 @@ class GrpcFetch {
|
|
|
6396
6466
|
var _a;
|
|
6397
6467
|
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug('Starting gRPC sync connection');
|
|
6398
6468
|
closeStreamIfDefined(this._syncStream);
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6469
|
+
try {
|
|
6470
|
+
this._syncStream = this._syncClient.syncFlags(this._request);
|
|
6471
|
+
this._syncStream.on('data', (data) => {
|
|
6472
|
+
var _a, _b, _c, _d;
|
|
6473
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug(`Received sync payload`);
|
|
6474
|
+
try {
|
|
6475
|
+
const changes = dataCallback(data.flagConfiguration);
|
|
6476
|
+
if (this._initialized && changes.length > 0) {
|
|
6477
|
+
changedCallback(changes);
|
|
6478
|
+
}
|
|
6407
6479
|
}
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
this.
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6480
|
+
catch (err) {
|
|
6481
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug('Error processing sync payload: ', (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'unknown error');
|
|
6482
|
+
}
|
|
6483
|
+
if (resolveConnect) {
|
|
6484
|
+
resolveConnect();
|
|
6485
|
+
}
|
|
6486
|
+
else if (!this._isConnected) {
|
|
6487
|
+
// Not the first connection and there's no active connection.
|
|
6488
|
+
(_d = this._logger) === null || _d === void 0 ? void 0 : _d.debug('Reconnected to gRPC sync');
|
|
6489
|
+
reconnectCallback();
|
|
6490
|
+
}
|
|
6491
|
+
this._isConnected = true;
|
|
6492
|
+
});
|
|
6493
|
+
this._syncStream.on('error', (err) => {
|
|
6494
|
+
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6495
|
+
});
|
|
6496
|
+
}
|
|
6497
|
+
catch (err) {
|
|
6498
|
+
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6499
|
+
}
|
|
6500
|
+
}
|
|
6501
|
+
handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect) {
|
|
6502
|
+
var _a, _b, _c;
|
|
6503
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.error('Connection error, attempting to reconnect');
|
|
6504
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug(err);
|
|
6505
|
+
this._isConnected = false;
|
|
6506
|
+
const errorMessage = (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'Failed to connect to syncFlags stream';
|
|
6507
|
+
disconnectCallback(errorMessage);
|
|
6508
|
+
rejectConnect === null || rejectConnect === void 0 ? void 0 : rejectConnect(new serverSdk.GeneralError(errorMessage));
|
|
6509
|
+
this.reconnect(dataCallback, reconnectCallback, changedCallback, disconnectCallback);
|
|
6432
6510
|
}
|
|
6433
6511
|
reconnect(dataCallback, reconnectCallback, changedCallback, disconnectCallback) {
|
|
6434
6512
|
const channel = this._syncClient.getChannel();
|
package/index.esm.js
CHANGED
|
@@ -30,10 +30,11 @@ var ENV_VAR;
|
|
|
30
30
|
ENV_VAR["FLAGD_MAX_CACHE_SIZE"] = "FLAGD_MAX_CACHE_SIZE";
|
|
31
31
|
ENV_VAR["FLAGD_SOURCE_SELECTOR"] = "FLAGD_SOURCE_SELECTOR";
|
|
32
32
|
ENV_VAR["FLAGD_RESOLVER"] = "FLAGD_RESOLVER";
|
|
33
|
+
ENV_VAR["FLAGD_OFFLINE_FLAG_SOURCE_PATH"] = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
|
|
33
34
|
})(ENV_VAR || (ENV_VAR = {}));
|
|
34
35
|
const getEnvVarConfig = () => {
|
|
35
36
|
var _a;
|
|
36
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (process.env[ENV_VAR.FLAGD_HOST] && {
|
|
37
|
+
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] && {
|
|
37
38
|
host: process.env[ENV_VAR.FLAGD_HOST],
|
|
38
39
|
})), (Number(process.env[ENV_VAR.FLAGD_PORT]) && {
|
|
39
40
|
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
|
|
@@ -49,6 +50,8 @@ const getEnvVarConfig = () => {
|
|
|
49
50
|
selector: process.env[ENV_VAR.FLAGD_SOURCE_SELECTOR],
|
|
50
51
|
})), ((process.env[ENV_VAR.FLAGD_RESOLVER] === 'rpc' || process.env[ENV_VAR.FLAGD_RESOLVER] === 'in-process') && {
|
|
51
52
|
resolverType: process.env[ENV_VAR.FLAGD_RESOLVER],
|
|
53
|
+
})), (process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH] && {
|
|
54
|
+
offlineFlagSourcePath: process.env[ENV_VAR.FLAGD_OFFLINE_FLAG_SOURCE_PATH],
|
|
52
55
|
})));
|
|
53
56
|
};
|
|
54
57
|
function getConfig(options = {}) {
|
|
@@ -5749,7 +5752,7 @@ const EventStreamRequest = {
|
|
|
5749
5752
|
};
|
|
5750
5753
|
const ServiceService = {
|
|
5751
5754
|
resolveAll: {
|
|
5752
|
-
path: "/
|
|
5755
|
+
path: "/flagd.evaluation.v1.Service/ResolveAll",
|
|
5753
5756
|
requestStream: false,
|
|
5754
5757
|
responseStream: false,
|
|
5755
5758
|
requestSerialize: (value) => Buffer.from(ResolveAllRequest.encode(value).finish()),
|
|
@@ -5758,7 +5761,7 @@ const ServiceService = {
|
|
|
5758
5761
|
responseDeserialize: (value) => ResolveAllResponse.decode(value),
|
|
5759
5762
|
},
|
|
5760
5763
|
resolveBoolean: {
|
|
5761
|
-
path: "/
|
|
5764
|
+
path: "/flagd.evaluation.v1.Service/ResolveBoolean",
|
|
5762
5765
|
requestStream: false,
|
|
5763
5766
|
responseStream: false,
|
|
5764
5767
|
requestSerialize: (value) => Buffer.from(ResolveBooleanRequest.encode(value).finish()),
|
|
@@ -5767,7 +5770,7 @@ const ServiceService = {
|
|
|
5767
5770
|
responseDeserialize: (value) => ResolveBooleanResponse.decode(value),
|
|
5768
5771
|
},
|
|
5769
5772
|
resolveString: {
|
|
5770
|
-
path: "/
|
|
5773
|
+
path: "/flagd.evaluation.v1.Service/ResolveString",
|
|
5771
5774
|
requestStream: false,
|
|
5772
5775
|
responseStream: false,
|
|
5773
5776
|
requestSerialize: (value) => Buffer.from(ResolveStringRequest.encode(value).finish()),
|
|
@@ -5776,7 +5779,7 @@ const ServiceService = {
|
|
|
5776
5779
|
responseDeserialize: (value) => ResolveStringResponse.decode(value),
|
|
5777
5780
|
},
|
|
5778
5781
|
resolveFloat: {
|
|
5779
|
-
path: "/
|
|
5782
|
+
path: "/flagd.evaluation.v1.Service/ResolveFloat",
|
|
5780
5783
|
requestStream: false,
|
|
5781
5784
|
responseStream: false,
|
|
5782
5785
|
requestSerialize: (value) => Buffer.from(ResolveFloatRequest.encode(value).finish()),
|
|
@@ -5785,7 +5788,7 @@ const ServiceService = {
|
|
|
5785
5788
|
responseDeserialize: (value) => ResolveFloatResponse.decode(value),
|
|
5786
5789
|
},
|
|
5787
5790
|
resolveInt: {
|
|
5788
|
-
path: "/
|
|
5791
|
+
path: "/flagd.evaluation.v1.Service/ResolveInt",
|
|
5789
5792
|
requestStream: false,
|
|
5790
5793
|
responseStream: false,
|
|
5791
5794
|
requestSerialize: (value) => Buffer.from(ResolveIntRequest.encode(value).finish()),
|
|
@@ -5794,7 +5797,7 @@ const ServiceService = {
|
|
|
5794
5797
|
responseDeserialize: (value) => ResolveIntResponse.decode(value),
|
|
5795
5798
|
},
|
|
5796
5799
|
resolveObject: {
|
|
5797
|
-
path: "/
|
|
5800
|
+
path: "/flagd.evaluation.v1.Service/ResolveObject",
|
|
5798
5801
|
requestStream: false,
|
|
5799
5802
|
responseStream: false,
|
|
5800
5803
|
requestSerialize: (value) => Buffer.from(ResolveObjectRequest.encode(value).finish()),
|
|
@@ -5803,7 +5806,7 @@ const ServiceService = {
|
|
|
5803
5806
|
responseDeserialize: (value) => ResolveObjectResponse.decode(value),
|
|
5804
5807
|
},
|
|
5805
5808
|
eventStream: {
|
|
5806
|
-
path: "/
|
|
5809
|
+
path: "/flagd.evaluation.v1.Service/EventStream",
|
|
5807
5810
|
requestStream: false,
|
|
5808
5811
|
responseStream: true,
|
|
5809
5812
|
requestSerialize: (value) => Buffer.from(EventStreamRequest.encode(value).finish()),
|
|
@@ -5812,7 +5815,7 @@ const ServiceService = {
|
|
|
5812
5815
|
responseDeserialize: (value) => EventStreamResponse.decode(value),
|
|
5813
5816
|
},
|
|
5814
5817
|
};
|
|
5815
|
-
const ServiceClient = makeGenericClientConstructor(ServiceService, "
|
|
5818
|
+
const ServiceClient = makeGenericClientConstructor(ServiceService, "flagd.evaluation.v1.Service");
|
|
5816
5819
|
function longToString(long) {
|
|
5817
5820
|
return long.toString();
|
|
5818
5821
|
}
|
|
@@ -5997,83 +6000,6 @@ class GRPCService {
|
|
|
5997
6000
|
}
|
|
5998
6001
|
|
|
5999
6002
|
/* eslint-disable */
|
|
6000
|
-
/**
|
|
6001
|
-
* Flag definition sync API
|
|
6002
|
-
*
|
|
6003
|
-
* This proto defines a simple API to synchronize a feature flag definition.
|
|
6004
|
-
* It supports establishing a stream for getting notifications about changes in a flag definition.
|
|
6005
|
-
*/
|
|
6006
|
-
/**
|
|
6007
|
-
* SyncState conveys the state of the payload. These states are related to flagd isync.go type definitions but
|
|
6008
|
-
* contains extras to optimize grpc use case. Refer - https://github.com/open-feature/flagd/blob/main/pkg/sync/isync.go
|
|
6009
|
-
*/
|
|
6010
|
-
var SyncState;
|
|
6011
|
-
(function (SyncState) {
|
|
6012
|
-
/** SYNC_STATE_UNSPECIFIED - Value is ignored by the listening flagd */
|
|
6013
|
-
SyncState[SyncState["SYNC_STATE_UNSPECIFIED"] = 0] = "SYNC_STATE_UNSPECIFIED";
|
|
6014
|
-
/**
|
|
6015
|
-
* SYNC_STATE_ALL - All the flags matching the request. This is the default response and other states can be ignored
|
|
6016
|
-
* by the implementation. Flagd internally replaces all existing flags for this response state.
|
|
6017
|
-
*/
|
|
6018
|
-
SyncState[SyncState["SYNC_STATE_ALL"] = 1] = "SYNC_STATE_ALL";
|
|
6019
|
-
/** SYNC_STATE_ADD - Convey an addition of a flag. Flagd internally handles this by combining new flags with existing ones */
|
|
6020
|
-
SyncState[SyncState["SYNC_STATE_ADD"] = 2] = "SYNC_STATE_ADD";
|
|
6021
|
-
/**
|
|
6022
|
-
* SYNC_STATE_UPDATE - Convey an update of a flag. Flagd internally attempts to update if the updated flag already exist OR if it does not,
|
|
6023
|
-
* it will get added
|
|
6024
|
-
*/
|
|
6025
|
-
SyncState[SyncState["SYNC_STATE_UPDATE"] = 3] = "SYNC_STATE_UPDATE";
|
|
6026
|
-
/** SYNC_STATE_DELETE - Convey a deletion of a flag. Flagd internally removes the flag */
|
|
6027
|
-
SyncState[SyncState["SYNC_STATE_DELETE"] = 4] = "SYNC_STATE_DELETE";
|
|
6028
|
-
/** SYNC_STATE_PING - Optional server ping to check client connectivity. Handling is ignored by flagd and is to merely support live check */
|
|
6029
|
-
SyncState[SyncState["SYNC_STATE_PING"] = 5] = "SYNC_STATE_PING";
|
|
6030
|
-
SyncState[SyncState["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
6031
|
-
})(SyncState || (SyncState = {}));
|
|
6032
|
-
function syncStateFromJSON(object) {
|
|
6033
|
-
switch (object) {
|
|
6034
|
-
case 0:
|
|
6035
|
-
case "SYNC_STATE_UNSPECIFIED":
|
|
6036
|
-
return SyncState.SYNC_STATE_UNSPECIFIED;
|
|
6037
|
-
case 1:
|
|
6038
|
-
case "SYNC_STATE_ALL":
|
|
6039
|
-
return SyncState.SYNC_STATE_ALL;
|
|
6040
|
-
case 2:
|
|
6041
|
-
case "SYNC_STATE_ADD":
|
|
6042
|
-
return SyncState.SYNC_STATE_ADD;
|
|
6043
|
-
case 3:
|
|
6044
|
-
case "SYNC_STATE_UPDATE":
|
|
6045
|
-
return SyncState.SYNC_STATE_UPDATE;
|
|
6046
|
-
case 4:
|
|
6047
|
-
case "SYNC_STATE_DELETE":
|
|
6048
|
-
return SyncState.SYNC_STATE_DELETE;
|
|
6049
|
-
case 5:
|
|
6050
|
-
case "SYNC_STATE_PING":
|
|
6051
|
-
return SyncState.SYNC_STATE_PING;
|
|
6052
|
-
case -1:
|
|
6053
|
-
case "UNRECOGNIZED":
|
|
6054
|
-
default:
|
|
6055
|
-
return SyncState.UNRECOGNIZED;
|
|
6056
|
-
}
|
|
6057
|
-
}
|
|
6058
|
-
function syncStateToJSON(object) {
|
|
6059
|
-
switch (object) {
|
|
6060
|
-
case SyncState.SYNC_STATE_UNSPECIFIED:
|
|
6061
|
-
return "SYNC_STATE_UNSPECIFIED";
|
|
6062
|
-
case SyncState.SYNC_STATE_ALL:
|
|
6063
|
-
return "SYNC_STATE_ALL";
|
|
6064
|
-
case SyncState.SYNC_STATE_ADD:
|
|
6065
|
-
return "SYNC_STATE_ADD";
|
|
6066
|
-
case SyncState.SYNC_STATE_UPDATE:
|
|
6067
|
-
return "SYNC_STATE_UPDATE";
|
|
6068
|
-
case SyncState.SYNC_STATE_DELETE:
|
|
6069
|
-
return "SYNC_STATE_DELETE";
|
|
6070
|
-
case SyncState.SYNC_STATE_PING:
|
|
6071
|
-
return "SYNC_STATE_PING";
|
|
6072
|
-
case SyncState.UNRECOGNIZED:
|
|
6073
|
-
default:
|
|
6074
|
-
return "UNRECOGNIZED";
|
|
6075
|
-
}
|
|
6076
|
-
}
|
|
6077
6003
|
function createBaseSyncFlagsRequest() {
|
|
6078
6004
|
return { providerId: "", selector: "" };
|
|
6079
6005
|
}
|
|
@@ -6142,16 +6068,13 @@ const SyncFlagsRequest = {
|
|
|
6142
6068
|
},
|
|
6143
6069
|
};
|
|
6144
6070
|
function createBaseSyncFlagsResponse() {
|
|
6145
|
-
return { flagConfiguration: ""
|
|
6071
|
+
return { flagConfiguration: "" };
|
|
6146
6072
|
}
|
|
6147
6073
|
const SyncFlagsResponse = {
|
|
6148
6074
|
encode(message, writer = minimal.Writer.create()) {
|
|
6149
6075
|
if (message.flagConfiguration !== "") {
|
|
6150
6076
|
writer.uint32(10).string(message.flagConfiguration);
|
|
6151
6077
|
}
|
|
6152
|
-
if (message.state !== 0) {
|
|
6153
|
-
writer.uint32(16).int32(message.state);
|
|
6154
|
-
}
|
|
6155
6078
|
return writer;
|
|
6156
6079
|
},
|
|
6157
6080
|
decode(input, length) {
|
|
@@ -6167,12 +6090,6 @@ const SyncFlagsResponse = {
|
|
|
6167
6090
|
}
|
|
6168
6091
|
message.flagConfiguration = reader.string();
|
|
6169
6092
|
continue;
|
|
6170
|
-
case 2:
|
|
6171
|
-
if (tag !== 16) {
|
|
6172
|
-
break;
|
|
6173
|
-
}
|
|
6174
|
-
message.state = reader.int32();
|
|
6175
|
-
continue;
|
|
6176
6093
|
}
|
|
6177
6094
|
if ((tag & 7) === 4 || tag === 0) {
|
|
6178
6095
|
break;
|
|
@@ -6182,29 +6099,22 @@ const SyncFlagsResponse = {
|
|
|
6182
6099
|
return message;
|
|
6183
6100
|
},
|
|
6184
6101
|
fromJSON(object) {
|
|
6185
|
-
return {
|
|
6186
|
-
flagConfiguration: isSet(object.flagConfiguration) ? String(object.flagConfiguration) : "",
|
|
6187
|
-
state: isSet(object.state) ? syncStateFromJSON(object.state) : 0,
|
|
6188
|
-
};
|
|
6102
|
+
return { flagConfiguration: isSet(object.flagConfiguration) ? String(object.flagConfiguration) : "" };
|
|
6189
6103
|
},
|
|
6190
6104
|
toJSON(message) {
|
|
6191
6105
|
const obj = {};
|
|
6192
6106
|
if (message.flagConfiguration !== "") {
|
|
6193
6107
|
obj.flagConfiguration = message.flagConfiguration;
|
|
6194
6108
|
}
|
|
6195
|
-
if (message.state !== 0) {
|
|
6196
|
-
obj.state = syncStateToJSON(message.state);
|
|
6197
|
-
}
|
|
6198
6109
|
return obj;
|
|
6199
6110
|
},
|
|
6200
6111
|
create(base) {
|
|
6201
6112
|
return SyncFlagsResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6202
6113
|
},
|
|
6203
6114
|
fromPartial(object) {
|
|
6204
|
-
var _a
|
|
6115
|
+
var _a;
|
|
6205
6116
|
const message = createBaseSyncFlagsResponse();
|
|
6206
6117
|
message.flagConfiguration = (_a = object.flagConfiguration) !== null && _a !== void 0 ? _a : "";
|
|
6207
|
-
message.state = (_b = object.state) !== null && _b !== void 0 ? _b : 0;
|
|
6208
6118
|
return message;
|
|
6209
6119
|
},
|
|
6210
6120
|
};
|
|
@@ -6326,9 +6236,160 @@ const FetchAllFlagsResponse = {
|
|
|
6326
6236
|
return message;
|
|
6327
6237
|
},
|
|
6328
6238
|
};
|
|
6239
|
+
function createBaseGetMetadataRequest() {
|
|
6240
|
+
return {};
|
|
6241
|
+
}
|
|
6242
|
+
const GetMetadataRequest = {
|
|
6243
|
+
encode(_, writer = minimal.Writer.create()) {
|
|
6244
|
+
return writer;
|
|
6245
|
+
},
|
|
6246
|
+
decode(input, length) {
|
|
6247
|
+
const reader = input instanceof minimal.Reader ? input : minimal.Reader.create(input);
|
|
6248
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
6249
|
+
const message = createBaseGetMetadataRequest();
|
|
6250
|
+
while (reader.pos < end) {
|
|
6251
|
+
const tag = reader.uint32();
|
|
6252
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
6253
|
+
break;
|
|
6254
|
+
}
|
|
6255
|
+
reader.skipType(tag & 7);
|
|
6256
|
+
}
|
|
6257
|
+
return message;
|
|
6258
|
+
},
|
|
6259
|
+
fromJSON(_) {
|
|
6260
|
+
return {};
|
|
6261
|
+
},
|
|
6262
|
+
toJSON(_) {
|
|
6263
|
+
const obj = {};
|
|
6264
|
+
return obj;
|
|
6265
|
+
},
|
|
6266
|
+
create(base) {
|
|
6267
|
+
return GetMetadataRequest.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6268
|
+
},
|
|
6269
|
+
fromPartial(_) {
|
|
6270
|
+
const message = createBaseGetMetadataRequest();
|
|
6271
|
+
return message;
|
|
6272
|
+
},
|
|
6273
|
+
};
|
|
6274
|
+
function createBaseGetMetadataResponse() {
|
|
6275
|
+
return { metadata: [] };
|
|
6276
|
+
}
|
|
6277
|
+
const GetMetadataResponse = {
|
|
6278
|
+
encode(message, writer = minimal.Writer.create()) {
|
|
6279
|
+
for (const v of message.metadata) {
|
|
6280
|
+
KeyValue.encode(v, writer.uint32(10).fork()).ldelim();
|
|
6281
|
+
}
|
|
6282
|
+
return writer;
|
|
6283
|
+
},
|
|
6284
|
+
decode(input, length) {
|
|
6285
|
+
const reader = input instanceof minimal.Reader ? input : minimal.Reader.create(input);
|
|
6286
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
6287
|
+
const message = createBaseGetMetadataResponse();
|
|
6288
|
+
while (reader.pos < end) {
|
|
6289
|
+
const tag = reader.uint32();
|
|
6290
|
+
switch (tag >>> 3) {
|
|
6291
|
+
case 1:
|
|
6292
|
+
if (tag !== 10) {
|
|
6293
|
+
break;
|
|
6294
|
+
}
|
|
6295
|
+
message.metadata.push(KeyValue.decode(reader, reader.uint32()));
|
|
6296
|
+
continue;
|
|
6297
|
+
}
|
|
6298
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
6299
|
+
break;
|
|
6300
|
+
}
|
|
6301
|
+
reader.skipType(tag & 7);
|
|
6302
|
+
}
|
|
6303
|
+
return message;
|
|
6304
|
+
},
|
|
6305
|
+
fromJSON(object) {
|
|
6306
|
+
return { metadata: Array.isArray(object === null || object === void 0 ? void 0 : object.metadata) ? object.metadata.map((e) => KeyValue.fromJSON(e)) : [] };
|
|
6307
|
+
},
|
|
6308
|
+
toJSON(message) {
|
|
6309
|
+
var _a;
|
|
6310
|
+
const obj = {};
|
|
6311
|
+
if ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.length) {
|
|
6312
|
+
obj.metadata = message.metadata.map((e) => KeyValue.toJSON(e));
|
|
6313
|
+
}
|
|
6314
|
+
return obj;
|
|
6315
|
+
},
|
|
6316
|
+
create(base) {
|
|
6317
|
+
return GetMetadataResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6318
|
+
},
|
|
6319
|
+
fromPartial(object) {
|
|
6320
|
+
var _a;
|
|
6321
|
+
const message = createBaseGetMetadataResponse();
|
|
6322
|
+
message.metadata = ((_a = object.metadata) === null || _a === void 0 ? void 0 : _a.map((e) => KeyValue.fromPartial(e))) || [];
|
|
6323
|
+
return message;
|
|
6324
|
+
},
|
|
6325
|
+
};
|
|
6326
|
+
function createBaseKeyValue() {
|
|
6327
|
+
return { key: "", value: "" };
|
|
6328
|
+
}
|
|
6329
|
+
const KeyValue = {
|
|
6330
|
+
encode(message, writer = minimal.Writer.create()) {
|
|
6331
|
+
if (message.key !== "") {
|
|
6332
|
+
writer.uint32(10).string(message.key);
|
|
6333
|
+
}
|
|
6334
|
+
if (message.value !== "") {
|
|
6335
|
+
writer.uint32(18).string(message.value);
|
|
6336
|
+
}
|
|
6337
|
+
return writer;
|
|
6338
|
+
},
|
|
6339
|
+
decode(input, length) {
|
|
6340
|
+
const reader = input instanceof minimal.Reader ? input : minimal.Reader.create(input);
|
|
6341
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
6342
|
+
const message = createBaseKeyValue();
|
|
6343
|
+
while (reader.pos < end) {
|
|
6344
|
+
const tag = reader.uint32();
|
|
6345
|
+
switch (tag >>> 3) {
|
|
6346
|
+
case 1:
|
|
6347
|
+
if (tag !== 10) {
|
|
6348
|
+
break;
|
|
6349
|
+
}
|
|
6350
|
+
message.key = reader.string();
|
|
6351
|
+
continue;
|
|
6352
|
+
case 2:
|
|
6353
|
+
if (tag !== 18) {
|
|
6354
|
+
break;
|
|
6355
|
+
}
|
|
6356
|
+
message.value = reader.string();
|
|
6357
|
+
continue;
|
|
6358
|
+
}
|
|
6359
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
6360
|
+
break;
|
|
6361
|
+
}
|
|
6362
|
+
reader.skipType(tag & 7);
|
|
6363
|
+
}
|
|
6364
|
+
return message;
|
|
6365
|
+
},
|
|
6366
|
+
fromJSON(object) {
|
|
6367
|
+
return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" };
|
|
6368
|
+
},
|
|
6369
|
+
toJSON(message) {
|
|
6370
|
+
const obj = {};
|
|
6371
|
+
if (message.key !== "") {
|
|
6372
|
+
obj.key = message.key;
|
|
6373
|
+
}
|
|
6374
|
+
if (message.value !== "") {
|
|
6375
|
+
obj.value = message.value;
|
|
6376
|
+
}
|
|
6377
|
+
return obj;
|
|
6378
|
+
},
|
|
6379
|
+
create(base) {
|
|
6380
|
+
return KeyValue.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
6381
|
+
},
|
|
6382
|
+
fromPartial(object) {
|
|
6383
|
+
var _a, _b;
|
|
6384
|
+
const message = createBaseKeyValue();
|
|
6385
|
+
message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
|
|
6386
|
+
message.value = (_b = object.value) !== null && _b !== void 0 ? _b : "";
|
|
6387
|
+
return message;
|
|
6388
|
+
},
|
|
6389
|
+
};
|
|
6329
6390
|
const FlagSyncServiceService = {
|
|
6330
6391
|
syncFlags: {
|
|
6331
|
-
path: "/sync.v1.FlagSyncService/SyncFlags",
|
|
6392
|
+
path: "/flagd.sync.v1.FlagSyncService/SyncFlags",
|
|
6332
6393
|
requestStream: false,
|
|
6333
6394
|
responseStream: true,
|
|
6334
6395
|
requestSerialize: (value) => Buffer.from(SyncFlagsRequest.encode(value).finish()),
|
|
@@ -6337,7 +6398,7 @@ const FlagSyncServiceService = {
|
|
|
6337
6398
|
responseDeserialize: (value) => SyncFlagsResponse.decode(value),
|
|
6338
6399
|
},
|
|
6339
6400
|
fetchAllFlags: {
|
|
6340
|
-
path: "/sync.v1.FlagSyncService/FetchAllFlags",
|
|
6401
|
+
path: "/flagd.sync.v1.FlagSyncService/FetchAllFlags",
|
|
6341
6402
|
requestStream: false,
|
|
6342
6403
|
responseStream: false,
|
|
6343
6404
|
requestSerialize: (value) => Buffer.from(FetchAllFlagsRequest.encode(value).finish()),
|
|
@@ -6345,8 +6406,17 @@ const FlagSyncServiceService = {
|
|
|
6345
6406
|
responseSerialize: (value) => Buffer.from(FetchAllFlagsResponse.encode(value).finish()),
|
|
6346
6407
|
responseDeserialize: (value) => FetchAllFlagsResponse.decode(value),
|
|
6347
6408
|
},
|
|
6409
|
+
getMetadata: {
|
|
6410
|
+
path: "/flagd.sync.v1.FlagSyncService/GetMetadata",
|
|
6411
|
+
requestStream: false,
|
|
6412
|
+
responseStream: false,
|
|
6413
|
+
requestSerialize: (value) => Buffer.from(GetMetadataRequest.encode(value).finish()),
|
|
6414
|
+
requestDeserialize: (value) => GetMetadataRequest.decode(value),
|
|
6415
|
+
responseSerialize: (value) => Buffer.from(GetMetadataResponse.encode(value).finish()),
|
|
6416
|
+
responseDeserialize: (value) => GetMetadataResponse.decode(value),
|
|
6417
|
+
},
|
|
6348
6418
|
};
|
|
6349
|
-
const FlagSyncServiceClient = makeGenericClientConstructor(FlagSyncServiceService, "sync.v1.FlagSyncService");
|
|
6419
|
+
const FlagSyncServiceClient = makeGenericClientConstructor(FlagSyncServiceService, "flagd.sync.v1.FlagSyncService");
|
|
6350
6420
|
function isSet(value) {
|
|
6351
6421
|
return value !== null && value !== undefined;
|
|
6352
6422
|
}
|
|
@@ -6392,39 +6462,47 @@ class GrpcFetch {
|
|
|
6392
6462
|
var _a;
|
|
6393
6463
|
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug('Starting gRPC sync connection');
|
|
6394
6464
|
closeStreamIfDefined(this._syncStream);
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6465
|
+
try {
|
|
6466
|
+
this._syncStream = this._syncClient.syncFlags(this._request);
|
|
6467
|
+
this._syncStream.on('data', (data) => {
|
|
6468
|
+
var _a, _b, _c, _d;
|
|
6469
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.debug(`Received sync payload`);
|
|
6470
|
+
try {
|
|
6471
|
+
const changes = dataCallback(data.flagConfiguration);
|
|
6472
|
+
if (this._initialized && changes.length > 0) {
|
|
6473
|
+
changedCallback(changes);
|
|
6474
|
+
}
|
|
6403
6475
|
}
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
this.
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6476
|
+
catch (err) {
|
|
6477
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug('Error processing sync payload: ', (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'unknown error');
|
|
6478
|
+
}
|
|
6479
|
+
if (resolveConnect) {
|
|
6480
|
+
resolveConnect();
|
|
6481
|
+
}
|
|
6482
|
+
else if (!this._isConnected) {
|
|
6483
|
+
// Not the first connection and there's no active connection.
|
|
6484
|
+
(_d = this._logger) === null || _d === void 0 ? void 0 : _d.debug('Reconnected to gRPC sync');
|
|
6485
|
+
reconnectCallback();
|
|
6486
|
+
}
|
|
6487
|
+
this._isConnected = true;
|
|
6488
|
+
});
|
|
6489
|
+
this._syncStream.on('error', (err) => {
|
|
6490
|
+
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6491
|
+
});
|
|
6492
|
+
}
|
|
6493
|
+
catch (err) {
|
|
6494
|
+
this.handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect);
|
|
6495
|
+
}
|
|
6496
|
+
}
|
|
6497
|
+
handleError(err, dataCallback, reconnectCallback, changedCallback, disconnectCallback, rejectConnect) {
|
|
6498
|
+
var _a, _b, _c;
|
|
6499
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.error('Connection error, attempting to reconnect');
|
|
6500
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.debug(err);
|
|
6501
|
+
this._isConnected = false;
|
|
6502
|
+
const errorMessage = (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : 'Failed to connect to syncFlags stream';
|
|
6503
|
+
disconnectCallback(errorMessage);
|
|
6504
|
+
rejectConnect === null || rejectConnect === void 0 ? void 0 : rejectConnect(new GeneralError(errorMessage));
|
|
6505
|
+
this.reconnect(dataCallback, reconnectCallback, changedCallback, disconnectCallback);
|
|
6428
6506
|
}
|
|
6429
6507
|
reconnect(dataCallback, reconnectCallback, changedCallback, disconnectCallback) {
|
|
6430
6508
|
const channel = this._syncClient.getChannel();
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/flagd-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@openfeature/flagd-core": "~0.1.
|
|
9
|
+
"@openfeature/flagd-core": "~0.1.10",
|
|
10
10
|
"@protobuf-ts/runtime-rpc": "2.9.0",
|
|
11
11
|
"lru-cache": "10.0.1",
|
|
12
12
|
"util": "0.12.5"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@grpc/grpc-js": "~1.8.0 || ~1.9.0",
|
|
15
|
+
"@grpc/grpc-js": "~1.8.0 || ~1.9.0 || ~1.10.0",
|
|
16
16
|
"@openfeature/server-sdk": ">=1.8.0"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EvaluationContext, JsonValue, Logger, ResolutionDetails } from '@openfeature/server-sdk';
|
|
2
|
-
import { ServiceClient } from '../../../proto/ts/
|
|
2
|
+
import { ServiceClient } from '../../../proto/ts/flagd/evaluation/v1/evaluation';
|
|
3
3
|
import { Config } from '../../configuration';
|
|
4
4
|
import { Service } from '../service';
|
|
5
5
|
interface FlagChange {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from '@openfeature/core';
|
|
2
|
-
import { FlagSyncServiceClient } from '../../../../proto/ts/sync/v1/
|
|
2
|
+
import { FlagSyncServiceClient } from '../../../../proto/ts/flagd/sync/v1/sync';
|
|
3
3
|
import { Config } from '../../../configuration';
|
|
4
4
|
import { DataFetch } from '../data-fetch';
|
|
5
5
|
/**
|
|
@@ -26,5 +26,6 @@ export declare class GrpcFetch implements DataFetch {
|
|
|
26
26
|
connect(dataCallback: (flags: string) => string[], reconnectCallback: () => void, changedCallback: (flagsChanged: string[]) => void, disconnectCallback: (message: string) => void): Promise<void>;
|
|
27
27
|
disconnect(): Promise<void>;
|
|
28
28
|
private listen;
|
|
29
|
+
private handleError;
|
|
29
30
|
private reconnect;
|
|
30
31
|
}
|