@openfeature/flagd-provider 0.7.4 → 0.7.6

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@openfeature/flagd-provider",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
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
  "peerDependencies": {
9
- "@openfeature/js-sdk": "^1.0.0"
9
+ "@openfeature/js-sdk": "^1.1.0"
10
10
  },
11
11
  "module": "./index.js",
12
12
  "main": "./index.cjs",
@@ -20,8 +20,10 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@protobuf-ts/grpc-transport": "2.8.2",
24
- "@protobuf-ts/runtime-rpc": "2.8.2",
25
- "@grpc/grpc-js": "1.8.0"
23
+ "@grpc/grpc-js": "1.8.13",
24
+ "@protobuf-ts/grpc-transport": "2.8.3",
25
+ "@protobuf-ts/runtime": "2.8.3",
26
+ "@protobuf-ts/runtime-rpc": "2.8.3",
27
+ "lru-cache": "8.0.5"
26
28
  }
27
29
  }
@@ -1,3 +1,4 @@
1
+ export type CacheOption = 'lru' | 'disabled';
1
2
  export interface Config {
2
3
  /**
3
4
  * The domain name or IP address of flagd.
@@ -23,6 +24,24 @@ export interface Config {
23
24
  * @example "/tmp/flagd.socks"
24
25
  */
25
26
  socketPath?: string;
27
+ /**
28
+ * Cache implementation to use (or disabled).
29
+ *
30
+ * @default 'lru'
31
+ */
32
+ cache?: CacheOption;
33
+ /**
34
+ * Max cache size (items).
35
+ *
36
+ * @default 1000
37
+ */
38
+ maxCacheSize?: number;
39
+ /**
40
+ * Amount of times to attempt to reconnect to the event stream.
41
+ *
42
+ * @default 5
43
+ */
44
+ maxEventStreamRetries?: number;
26
45
  }
27
46
  export type FlagdProviderOptions = Partial<Config>;
28
47
  export declare function getConfig(options?: FlagdProviderOptions): {
@@ -30,4 +49,7 @@ export declare function getConfig(options?: FlagdProviderOptions): {
30
49
  port: number;
31
50
  tls: boolean;
32
51
  socketPath?: string | undefined;
52
+ cache?: CacheOption | undefined;
53
+ maxCacheSize?: number | undefined;
54
+ maxEventStreamRetries?: number | undefined;
33
55
  };
@@ -0,0 +1,5 @@
1
+ export declare const BASE_EVENT_STREAM_RETRY_BACKOFF_MS = 1000;
2
+ export declare const DEFAULT_MAX_EVENT_STREAM_RETRIES = 5;
3
+ export declare const EVENT_CONFIGURATION_CHANGE = "configuration_change";
4
+ export declare const EVENT_PROVIDER_READY = "provider_ready";
5
+ export declare const DEFAULT_MAX_CACHE_SIZE = 1000;
@@ -2,11 +2,21 @@ import { EvaluationContext, JsonValue, Logger, Provider, ResolutionDetails } fro
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
6
  metadata: {
6
7
  name: string;
7
8
  };
8
9
  private readonly _service;
9
- constructor(options?: FlagdProviderOptions, service?: Service);
10
+ /**
11
+ * Promise indicating the gRPC stream is connected.
12
+ *
13
+ * Can be used in instances where the provider being connected to the event stream is a prerequisite
14
+ * to execution (e.g. testing). Not necessary for standard usage.
15
+ *
16
+ * @returns true if stream connected successfully, false if connection not enabled.
17
+ */
18
+ get streamConnection(): Promise<boolean>;
19
+ constructor(options?: FlagdProviderOptions, service?: Service, logger?: Logger | undefined);
10
20
  resolveBooleanEvaluation(flagKey: string, _: boolean, transformedContext: EvaluationContext, logger: Logger): Promise<ResolutionDetails<boolean>>;
11
21
  resolveStringEvaluation(flagKey: string, _: string, transformedContext: EvaluationContext, logger: Logger): Promise<ResolutionDetails<string>>;
12
22
  resolveNumberEvaluation(flagKey: string, _: number, transformedContext: EvaluationContext, logger: Logger): Promise<ResolutionDetails<number>>;
@@ -2,6 +2,16 @@ import { EvaluationContext, JsonValue, Logger, ResolutionDetails } from '@openfe
2
2
  import { ServiceClient } from '../../../proto/ts/schema/v1/schema.client';
3
3
  import { Config } from '../../configuration';
4
4
  import { Service } from '../service';
5
+ interface FlagChange {
6
+ type: 'delete' | 'write' | 'update';
7
+ source: string;
8
+ flagKey: string;
9
+ }
10
+ export interface FlagChangeMessage {
11
+ flags?: {
12
+ [key: string]: FlagChange;
13
+ };
14
+ }
5
15
  export declare const Codes: {
6
16
  readonly InvalidArgument: "INVALID_ARGUMENT";
7
17
  readonly NotFound: "NOT_FOUND";
@@ -9,13 +19,32 @@ export declare const Codes: {
9
19
  readonly Unavailable: "UNAVAILABLE";
10
20
  };
11
21
  export declare class GRPCService implements Service {
12
- client: ServiceClient;
13
- constructor(config: Config, client?: ServiceClient);
22
+ private logger?;
23
+ private _client;
24
+ private _cache;
25
+ private _cacheEnabled;
26
+ private _streamAlive;
27
+ private _streamConnectAttempt;
28
+ private _streamConnectBackoff;
29
+ private _maxEventStreamRetries;
30
+ private get _cacheActive();
31
+ readonly streamConnection: Promise<boolean>;
32
+ constructor(config: Config, client?: ServiceClient, logger?: Logger | undefined);
14
33
  resolveBoolean(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<boolean>>;
15
34
  resolveString(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<string>>;
16
35
  resolveNumber(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<number>>;
17
36
  resolveObject<T extends JsonValue>(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<T>>;
37
+ private connectStream;
38
+ private handleProviderReady;
39
+ private handleFlagsChanged;
40
+ private handleError;
41
+ private handleComplete;
42
+ private objectParser;
43
+ private booleanParser;
44
+ private stringParser;
45
+ private numberParser;
46
+ private resolve;
18
47
  private convertContext;
19
- private onFulfilled;
20
48
  private onRejected;
21
49
  }
50
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { EvaluationContext, JsonValue, Logger, ResolutionDetails } from '@openfeature/js-sdk';
2
2
  export interface Service {
3
+ readonly streamConnection: Promise<boolean>;
3
4
  resolveBoolean(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<boolean>>;
4
5
  resolveString(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<string>>;
5
6
  resolveNumber(flagKey: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<number>>;
@@ -0,0 +1,46 @@
1
+ import type { RpcTransport } from "@protobuf-ts/runtime-rpc";
2
+ import type { ServiceInfo } from "@protobuf-ts/runtime-rpc";
3
+ import type { FetchAllFlagsResponse } from "./sync_service";
4
+ import type { FetchAllFlagsRequest } from "./sync_service";
5
+ import type { UnaryCall } from "@protobuf-ts/runtime-rpc";
6
+ import type { SyncFlagsResponse } from "./sync_service";
7
+ import type { SyncFlagsRequest } from "./sync_service";
8
+ import type { ServerStreamingCall } from "@protobuf-ts/runtime-rpc";
9
+ import type { RpcOptions } from "@protobuf-ts/runtime-rpc";
10
+ /**
11
+ * FlagService implements a server streaming to provide realtime flag configurations
12
+ *
13
+ * @generated from protobuf service sync.v1.FlagSyncService
14
+ */
15
+ export interface IFlagSyncServiceClient {
16
+ /**
17
+ * @generated from protobuf rpc: SyncFlags(sync.v1.SyncFlagsRequest) returns (stream sync.v1.SyncFlagsResponse);
18
+ */
19
+ syncFlags(input: SyncFlagsRequest, options?: RpcOptions): ServerStreamingCall<SyncFlagsRequest, SyncFlagsResponse>;
20
+ /**
21
+ * @generated from protobuf rpc: FetchAllFlags(sync.v1.FetchAllFlagsRequest) returns (sync.v1.FetchAllFlagsResponse);
22
+ */
23
+ fetchAllFlags(input: FetchAllFlagsRequest, options?: RpcOptions): UnaryCall<FetchAllFlagsRequest, FetchAllFlagsResponse>;
24
+ }
25
+ /**
26
+ * FlagService implements a server streaming to provide realtime flag configurations
27
+ *
28
+ * @generated from protobuf service sync.v1.FlagSyncService
29
+ */
30
+ export declare class FlagSyncServiceClient implements IFlagSyncServiceClient, ServiceInfo {
31
+ private readonly _transport;
32
+ typeName: string;
33
+ methods: import("@protobuf-ts/runtime-rpc").MethodInfo<any, any>[];
34
+ options: {
35
+ [extensionName: string]: import("@protobuf-ts/runtime").JsonValue;
36
+ };
37
+ constructor(_transport: RpcTransport);
38
+ /**
39
+ * @generated from protobuf rpc: SyncFlags(sync.v1.SyncFlagsRequest) returns (stream sync.v1.SyncFlagsResponse);
40
+ */
41
+ syncFlags(input: SyncFlagsRequest, options?: RpcOptions): ServerStreamingCall<SyncFlagsRequest, SyncFlagsResponse>;
42
+ /**
43
+ * @generated from protobuf rpc: FetchAllFlags(sync.v1.FetchAllFlagsRequest) returns (sync.v1.FetchAllFlagsResponse);
44
+ */
45
+ fetchAllFlags(input: FetchAllFlagsRequest, options?: RpcOptions): UnaryCall<FetchAllFlagsRequest, FetchAllFlagsResponse>;
46
+ }
@@ -0,0 +1,183 @@
1
+ import { ServiceType } from "@protobuf-ts/runtime-rpc";
2
+ import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
3
+ import type { IBinaryWriter } from "@protobuf-ts/runtime";
4
+ import type { BinaryReadOptions } from "@protobuf-ts/runtime";
5
+ import type { IBinaryReader } from "@protobuf-ts/runtime";
6
+ import type { PartialMessage } from "@protobuf-ts/runtime";
7
+ import { MessageType } from "@protobuf-ts/runtime";
8
+ /**
9
+ * SyncFlagsRequest is the request initiating the sever-streaming rpc. Flagd sends this request, acting as the client
10
+ *
11
+ * @generated from protobuf message sync.v1.SyncFlagsRequest
12
+ */
13
+ export interface SyncFlagsRequest {
14
+ /**
15
+ * Optional: A unique identifier for flagd(grpc client) initiating the request. The server implementations may
16
+ * utilize this identifier to uniquely identify, validate(ex:- enforce authentication/authorization) and filter
17
+ * flag configurations that it can expose to this request. This field is intended to be optional. However server
18
+ * implementations may enforce it.
19
+ * ex:- provider_id: flagd-weatherapp-sidecar
20
+ *
21
+ * @generated from protobuf field: string provider_id = 1;
22
+ */
23
+ providerId: string;
24
+ /**
25
+ * Optional: A selector for the flag configuration request. The server implementation may utilize this to select
26
+ * flag configurations from a collection, select the source of the flag or combine this to any desired underlying
27
+ * filtering mechanism.
28
+ * ex:- selector: 'source=database,app=weatherapp'
29
+ *
30
+ * @generated from protobuf field: string selector = 2;
31
+ */
32
+ selector: string;
33
+ }
34
+ /**
35
+ * SyncFlagsResponse is the server response containing feature flag configurations and the state
36
+ *
37
+ * @generated from protobuf message sync.v1.SyncFlagsResponse
38
+ */
39
+ export interface SyncFlagsResponse {
40
+ /**
41
+ * flagd feature flag configuration. Must be validated to schema - https://raw.githubusercontent.com/open-feature/schemas/main/json/flagd-definitions.json
42
+ *
43
+ * @generated from protobuf field: string flag_configuration = 1;
44
+ */
45
+ flagConfiguration: string;
46
+ /**
47
+ * State conveying the operation to be performed by flagd. See the descriptions of SyncState for an explanation of
48
+ * supported values
49
+ *
50
+ * @generated from protobuf field: sync.v1.SyncState state = 2;
51
+ */
52
+ state: SyncState;
53
+ }
54
+ /**
55
+ * FetchAllFlagsRequest is the request to fetch all flags. Flagd sends this request as the client in order to resync its internal state
56
+ *
57
+ * @generated from protobuf message sync.v1.FetchAllFlagsRequest
58
+ */
59
+ export interface FetchAllFlagsRequest {
60
+ /**
61
+ * Optional: A unique identifier for flagd(grpc client) initiating the request. The server implementations may
62
+ * utilize this identifier to uniquely identify, validate(ex:- enforce authentication/authorization) and filter
63
+ * flag configurations that it can expose to this request. This field is intended to be optional. However server
64
+ * implementations may enforce it.
65
+ * ex:- provider_id: flagd-weatherapp-sidecar
66
+ *
67
+ * @generated from protobuf field: string provider_id = 1;
68
+ */
69
+ providerId: string;
70
+ /**
71
+ * Optional: A selector for the flag configuration request. The server implementation may utilize this to select
72
+ * flag configurations from a collection, select the source of the flag or combine this to any desired underlying
73
+ * filtering mechanism.
74
+ * ex:- selector: 'source=database,app=weatherapp'
75
+ *
76
+ * @generated from protobuf field: string selector = 2;
77
+ */
78
+ selector: string;
79
+ }
80
+ /**
81
+ * FetchAllFlagsResponse is the server response containing feature flag configurations
82
+ *
83
+ * @generated from protobuf message sync.v1.FetchAllFlagsResponse
84
+ */
85
+ export interface FetchAllFlagsResponse {
86
+ /**
87
+ * flagd feature flag configuration. Must be validated to schema - https://raw.githubusercontent.com/open-feature/schemas/main/json/flagd-definitions.json
88
+ *
89
+ * @generated from protobuf field: string flag_configuration = 1;
90
+ */
91
+ flagConfiguration: string;
92
+ }
93
+ /**
94
+ * SyncState conveys the state of the payload. These states are related to flagd isync.go type definitions but
95
+ * contains extras to optimize grpc use case. Refer - https://github.com/open-feature/flagd/blob/main/pkg/sync/isync.go
96
+ *
97
+ * @generated from protobuf enum sync.v1.SyncState
98
+ */
99
+ export declare enum SyncState {
100
+ /**
101
+ * Value is ignored by the listening flagd
102
+ *
103
+ * @generated from protobuf enum value: SYNC_STATE_UNSPECIFIED = 0;
104
+ */
105
+ UNSPECIFIED = 0,
106
+ /**
107
+ * All the flags matching the request. This is the default response and other states can be ignored
108
+ * by the implementation. Flagd internally replaces all existing flags for this response state.
109
+ *
110
+ * @generated from protobuf enum value: SYNC_STATE_ALL = 1;
111
+ */
112
+ ALL = 1,
113
+ /**
114
+ * Convey an addition of a flag. Flagd internally handles this by combining new flags with existing ones
115
+ *
116
+ * @generated from protobuf enum value: SYNC_STATE_ADD = 2;
117
+ */
118
+ ADD = 2,
119
+ /**
120
+ * Convey an update of a flag. Flagd internally attempts to update if the updated flag already exist OR if it does not,
121
+ * it will get added
122
+ *
123
+ * @generated from protobuf enum value: SYNC_STATE_UPDATE = 3;
124
+ */
125
+ UPDATE = 3,
126
+ /**
127
+ * Convey a deletion of a flag. Flagd internally removes the flag
128
+ *
129
+ * @generated from protobuf enum value: SYNC_STATE_DELETE = 4;
130
+ */
131
+ DELETE = 4,
132
+ /**
133
+ * Optional server ping to check client connectivity. Handling is ignored by flagd and is to merely support live check
134
+ *
135
+ * @generated from protobuf enum value: SYNC_STATE_PING = 5;
136
+ */
137
+ PING = 5
138
+ }
139
+ declare class SyncFlagsRequest$Type extends MessageType<SyncFlagsRequest> {
140
+ constructor();
141
+ create(value?: PartialMessage<SyncFlagsRequest>): SyncFlagsRequest;
142
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SyncFlagsRequest): SyncFlagsRequest;
143
+ internalBinaryWrite(message: SyncFlagsRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
144
+ }
145
+ /**
146
+ * @generated MessageType for protobuf message sync.v1.SyncFlagsRequest
147
+ */
148
+ export declare const SyncFlagsRequest: SyncFlagsRequest$Type;
149
+ declare class SyncFlagsResponse$Type extends MessageType<SyncFlagsResponse> {
150
+ constructor();
151
+ create(value?: PartialMessage<SyncFlagsResponse>): SyncFlagsResponse;
152
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SyncFlagsResponse): SyncFlagsResponse;
153
+ internalBinaryWrite(message: SyncFlagsResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
154
+ }
155
+ /**
156
+ * @generated MessageType for protobuf message sync.v1.SyncFlagsResponse
157
+ */
158
+ export declare const SyncFlagsResponse: SyncFlagsResponse$Type;
159
+ declare class FetchAllFlagsRequest$Type extends MessageType<FetchAllFlagsRequest> {
160
+ constructor();
161
+ create(value?: PartialMessage<FetchAllFlagsRequest>): FetchAllFlagsRequest;
162
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FetchAllFlagsRequest): FetchAllFlagsRequest;
163
+ internalBinaryWrite(message: FetchAllFlagsRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
164
+ }
165
+ /**
166
+ * @generated MessageType for protobuf message sync.v1.FetchAllFlagsRequest
167
+ */
168
+ export declare const FetchAllFlagsRequest: FetchAllFlagsRequest$Type;
169
+ declare class FetchAllFlagsResponse$Type extends MessageType<FetchAllFlagsResponse> {
170
+ constructor();
171
+ create(value?: PartialMessage<FetchAllFlagsResponse>): FetchAllFlagsResponse;
172
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FetchAllFlagsResponse): FetchAllFlagsResponse;
173
+ internalBinaryWrite(message: FetchAllFlagsResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
174
+ }
175
+ /**
176
+ * @generated MessageType for protobuf message sync.v1.FetchAllFlagsResponse
177
+ */
178
+ export declare const FetchAllFlagsResponse: FetchAllFlagsResponse$Type;
179
+ /**
180
+ * @generated ServiceType for protobuf service sync.v1.FlagSyncService
181
+ */
182
+ export declare const FlagSyncService: ServiceType;
183
+ export {};