@openfeature/flagd-provider 0.7.4 → 0.7.5
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 +9 -6
- package/index.cjs +314 -3115
- package/index.js +174 -2978
- package/package.json +5 -3
- package/src/lib/configuration.d.ts +22 -0
- package/src/lib/constants.d.ts +5 -0
- package/src/lib/flagd-provider.d.ts +11 -1
- package/src/lib/service/grpc/service.d.ts +29 -3
- package/src/lib/service/service.d.ts +1 -0
- package/src/proto/ts/sync/v1/sync_service.client.d.ts +46 -0
- package/src/proto/ts/sync/v1/sync_service.d.ts +153 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/flagd-provider",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
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.
|
|
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
|
+
"@grpc/grpc-js": "^1.7.3",
|
|
23
24
|
"@protobuf-ts/grpc-transport": "2.8.2",
|
|
25
|
+
"@protobuf-ts/runtime": "2.8.2",
|
|
24
26
|
"@protobuf-ts/runtime-rpc": "2.8.2",
|
|
25
|
-
"
|
|
27
|
+
"lru-cache": "^7.14.1"
|
|
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
|
-
|
|
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,29 @@ export declare const Codes: {
|
|
|
9
19
|
readonly Unavailable: "UNAVAILABLE";
|
|
10
20
|
};
|
|
11
21
|
export declare class GRPCService implements Service {
|
|
12
|
-
|
|
13
|
-
|
|
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 resolve;
|
|
18
44
|
private convertContext;
|
|
19
|
-
private onFulfilled;
|
|
20
45
|
private onRejected;
|
|
21
46
|
}
|
|
47
|
+
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,153 @@
|
|
|
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 provider (grpc client) initiating the request. The server implementations
|
|
16
|
+
* can utilize this identifier to aggregate flag configurations and stream them to a specific client. This identifier
|
|
17
|
+
* is intended to be optional. However server implementation may enforce it.
|
|
18
|
+
*
|
|
19
|
+
* @generated from protobuf field: string provider_id = 1;
|
|
20
|
+
*/
|
|
21
|
+
providerId: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SyncFlagsResponse is the server response containing feature flag configurations and the state
|
|
25
|
+
*
|
|
26
|
+
* @generated from protobuf message sync.v1.SyncFlagsResponse
|
|
27
|
+
*/
|
|
28
|
+
export interface SyncFlagsResponse {
|
|
29
|
+
/**
|
|
30
|
+
* flagd feature flag configuration. Must be validated to schema - https://raw.githubusercontent.com/open-feature/schemas/main/json/flagd-definitions.json
|
|
31
|
+
*
|
|
32
|
+
* @generated from protobuf field: string flag_configuration = 1;
|
|
33
|
+
*/
|
|
34
|
+
flagConfiguration: string;
|
|
35
|
+
/**
|
|
36
|
+
* State conveying the operation to be performed by flagd. See the descriptions of SyncState for an explanation of
|
|
37
|
+
* supported values
|
|
38
|
+
*
|
|
39
|
+
* @generated from protobuf field: sync.v1.SyncState state = 2;
|
|
40
|
+
*/
|
|
41
|
+
state: SyncState;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* FetchAllFlagsRequest is the request to fetch all flags. Flagd sends this request as the client in order to resync its internal state
|
|
45
|
+
*
|
|
46
|
+
* @generated from protobuf message sync.v1.FetchAllFlagsRequest
|
|
47
|
+
*/
|
|
48
|
+
export interface FetchAllFlagsRequest {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* FetchAllFlagsResponse is the server response containing feature flag configurations
|
|
52
|
+
*
|
|
53
|
+
* @generated from protobuf message sync.v1.FetchAllFlagsResponse
|
|
54
|
+
*/
|
|
55
|
+
export interface FetchAllFlagsResponse {
|
|
56
|
+
/**
|
|
57
|
+
* flagd feature flag configuration. Must be validated to schema - https://raw.githubusercontent.com/open-feature/schemas/main/json/flagd-definitions.json
|
|
58
|
+
*
|
|
59
|
+
* @generated from protobuf field: string flag_configuration = 1;
|
|
60
|
+
*/
|
|
61
|
+
flagConfiguration: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* SyncState conveys the state of the payload. These states are related to flagd isync.go type definitions but
|
|
65
|
+
* contains extras to optimize grpc use case. Refer - https://github.com/open-feature/flagd/blob/main/pkg/sync/isync.go
|
|
66
|
+
*
|
|
67
|
+
* @generated from protobuf enum sync.v1.SyncState
|
|
68
|
+
*/
|
|
69
|
+
export declare enum SyncState {
|
|
70
|
+
/**
|
|
71
|
+
* Value is ignored by the listening flagd
|
|
72
|
+
*
|
|
73
|
+
* @generated from protobuf enum value: SYNC_STATE_UNSPECIFIED = 0;
|
|
74
|
+
*/
|
|
75
|
+
UNSPECIFIED = 0,
|
|
76
|
+
/**
|
|
77
|
+
* All the flags matching the request. This is the default response and other states can be ignored
|
|
78
|
+
* by the implementation. Flagd internally replaces all existing flags for this response state.
|
|
79
|
+
*
|
|
80
|
+
* @generated from protobuf enum value: SYNC_STATE_ALL = 1;
|
|
81
|
+
*/
|
|
82
|
+
ALL = 1,
|
|
83
|
+
/**
|
|
84
|
+
* Convey an addition of a flag. Flagd internally handles this by combining new flags with existing ones
|
|
85
|
+
*
|
|
86
|
+
* @generated from protobuf enum value: SYNC_STATE_ADD = 2;
|
|
87
|
+
*/
|
|
88
|
+
ADD = 2,
|
|
89
|
+
/**
|
|
90
|
+
* Convey an update of a flag. Flagd internally attempts to update if the updated flag already exist OR if it does not,
|
|
91
|
+
* it will get added
|
|
92
|
+
*
|
|
93
|
+
* @generated from protobuf enum value: SYNC_STATE_UPDATE = 3;
|
|
94
|
+
*/
|
|
95
|
+
UPDATE = 3,
|
|
96
|
+
/**
|
|
97
|
+
* Convey a deletion of a flag. Flagd internally removes the flag
|
|
98
|
+
*
|
|
99
|
+
* @generated from protobuf enum value: SYNC_STATE_DELETE = 4;
|
|
100
|
+
*/
|
|
101
|
+
DELETE = 4,
|
|
102
|
+
/**
|
|
103
|
+
* Optional server ping to check client connectivity. Handling is ignored by flagd and is to merely support live check
|
|
104
|
+
*
|
|
105
|
+
* @generated from protobuf enum value: SYNC_STATE_PING = 5;
|
|
106
|
+
*/
|
|
107
|
+
PING = 5
|
|
108
|
+
}
|
|
109
|
+
declare class SyncFlagsRequest$Type extends MessageType<SyncFlagsRequest> {
|
|
110
|
+
constructor();
|
|
111
|
+
create(value?: PartialMessage<SyncFlagsRequest>): SyncFlagsRequest;
|
|
112
|
+
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SyncFlagsRequest): SyncFlagsRequest;
|
|
113
|
+
internalBinaryWrite(message: SyncFlagsRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @generated MessageType for protobuf message sync.v1.SyncFlagsRequest
|
|
117
|
+
*/
|
|
118
|
+
export declare const SyncFlagsRequest: SyncFlagsRequest$Type;
|
|
119
|
+
declare class SyncFlagsResponse$Type extends MessageType<SyncFlagsResponse> {
|
|
120
|
+
constructor();
|
|
121
|
+
create(value?: PartialMessage<SyncFlagsResponse>): SyncFlagsResponse;
|
|
122
|
+
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SyncFlagsResponse): SyncFlagsResponse;
|
|
123
|
+
internalBinaryWrite(message: SyncFlagsResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @generated MessageType for protobuf message sync.v1.SyncFlagsResponse
|
|
127
|
+
*/
|
|
128
|
+
export declare const SyncFlagsResponse: SyncFlagsResponse$Type;
|
|
129
|
+
declare class FetchAllFlagsRequest$Type extends MessageType<FetchAllFlagsRequest> {
|
|
130
|
+
constructor();
|
|
131
|
+
create(value?: PartialMessage<FetchAllFlagsRequest>): FetchAllFlagsRequest;
|
|
132
|
+
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FetchAllFlagsRequest): FetchAllFlagsRequest;
|
|
133
|
+
internalBinaryWrite(message: FetchAllFlagsRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @generated MessageType for protobuf message sync.v1.FetchAllFlagsRequest
|
|
137
|
+
*/
|
|
138
|
+
export declare const FetchAllFlagsRequest: FetchAllFlagsRequest$Type;
|
|
139
|
+
declare class FetchAllFlagsResponse$Type extends MessageType<FetchAllFlagsResponse> {
|
|
140
|
+
constructor();
|
|
141
|
+
create(value?: PartialMessage<FetchAllFlagsResponse>): FetchAllFlagsResponse;
|
|
142
|
+
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FetchAllFlagsResponse): FetchAllFlagsResponse;
|
|
143
|
+
internalBinaryWrite(message: FetchAllFlagsResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @generated MessageType for protobuf message sync.v1.FetchAllFlagsResponse
|
|
147
|
+
*/
|
|
148
|
+
export declare const FetchAllFlagsResponse: FetchAllFlagsResponse$Type;
|
|
149
|
+
/**
|
|
150
|
+
* @generated ServiceType for protobuf service sync.v1.FlagSyncService
|
|
151
|
+
*/
|
|
152
|
+
export declare const FlagSyncService: ServiceType;
|
|
153
|
+
export {};
|