@configdirector/server-sdk 1.7.0 → 1.9.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 +29 -0
- package/dist/DefaultConfigDirectorClient-BZu8tv38.cjs +5 -0
- package/dist/DefaultConfigDirectorClient-DbkqrtUI.mjs +6 -0
- package/dist/DefaultConfigDirectorClient-DbkqrtUI.mjs.map +1 -0
- package/dist/configdirector-server-testing.cjs +1 -0
- package/dist/configdirector-server-testing.d.cts +111 -0
- package/dist/configdirector-server-testing.d.cts.map +1 -0
- package/dist/configdirector-server-testing.d.mts +111 -0
- package/dist/configdirector-server-testing.d.mts.map +1 -0
- package/dist/configdirector-server-testing.mjs +2 -0
- package/dist/configdirector-server-testing.mjs.map +1 -0
- package/dist/configdirector-server.cjs +1 -5
- package/dist/configdirector-server.d.cts +2 -288
- package/dist/configdirector-server.d.cts.map +1 -1
- package/dist/configdirector-server.d.mts +2 -288
- package/dist/configdirector-server.d.mts.map +1 -1
- package/dist/configdirector-server.mjs +1 -5
- package/dist/configdirector-server.mjs.map +1 -1
- package/dist/types-BqIJGXWv.d.mts +292 -0
- package/dist/types-BqIJGXWv.d.mts.map +1 -0
- package/dist/types-CcUNxeqN.d.cts +292 -0
- package/dist/types-CcUNxeqN.d.cts.map +1 -0
- package/package.json +19 -3
|
@@ -1,291 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type ConfigType = (typeof ConfigTypeList)[number];
|
|
4
|
-
type ConfigEnumLikeType = {
|
|
5
|
-
[key: string]: string | number;
|
|
6
|
-
};
|
|
7
|
-
type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
|
|
8
|
-
type ConfigState = {
|
|
9
|
-
id: string;
|
|
10
|
-
key: string;
|
|
11
|
-
type: ConfigType;
|
|
12
|
-
value: string | undefined | null;
|
|
13
|
-
valueId?: string | undefined | null;
|
|
14
|
-
};
|
|
15
|
-
type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
|
|
16
|
-
interface ConfigDirectorLogger {
|
|
17
|
-
debug(message: string, ...args: any): void;
|
|
18
|
-
info(message: string, ...args: any): void;
|
|
19
|
-
warn(message: string, ...args: any): void;
|
|
20
|
-
error(message: string, ...args: any): void;
|
|
21
|
-
}
|
|
22
|
-
interface ConfigDirectorLogMessageDecorator {
|
|
23
|
-
decorateMessage(message: string): string;
|
|
24
|
-
}
|
|
25
|
-
type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean";
|
|
26
|
-
type ConfigEvaluation = {
|
|
27
|
-
key: string;
|
|
28
|
-
value: ConfigValueType;
|
|
29
|
-
valueId?: string;
|
|
30
|
-
isDefaultValue: boolean;
|
|
31
|
-
reason: EvaluationReason;
|
|
32
|
-
context?: ConfigDirectorContext;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* The user's context to be sent to ConfigDirector. This context will be used for targeting
|
|
36
|
-
* rules evaluation.
|
|
37
|
-
*/
|
|
38
|
-
type ConfigDirectorContext = {
|
|
39
|
-
/**
|
|
40
|
-
* The user's identifier. This should be a value that uniquely identifies an application
|
|
41
|
-
* user.
|
|
42
|
-
* In the case of anonymous users, you could generate a UUID or alternatively not provide
|
|
43
|
-
* the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
|
|
44
|
-
* value is used for segmenting users in percentage rollouts, and changes to the {@link id}
|
|
45
|
-
* could result in the user being assigned to a different percentile.
|
|
46
|
-
*/
|
|
47
|
-
id?: string;
|
|
48
|
-
/**
|
|
49
|
-
* The user's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
50
|
-
* used for targeting rules.
|
|
51
|
-
*/
|
|
52
|
-
name?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Any arbitrary traits for the current user. They will be shown in the ConfigDirector
|
|
55
|
-
* dashboard and may be used for targeting rules.
|
|
56
|
-
*/
|
|
57
|
-
traits?: {
|
|
58
|
-
[key: string]: unknown;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Whether or not to treat the context as anonymous during evaluation. When `true`, the
|
|
62
|
-
* context values will be used for targeting rules evaluation but the context will not be
|
|
63
|
-
* persisted and will not appear in the dashboard.
|
|
64
|
-
*
|
|
65
|
-
* @default false
|
|
66
|
-
*/
|
|
67
|
-
anonymous?: boolean;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Metadata about your application. It is recommended you include these values when configuring
|
|
71
|
-
* a ConfigDirector client so that you can use them in targeting rules.
|
|
72
|
-
*/
|
|
73
|
-
type ConfigDirectorMetaContext = {
|
|
74
|
-
appVersion?: string;
|
|
75
|
-
appName?: string;
|
|
76
|
-
};
|
|
77
|
-
type ConnectionMode = "streaming" | "polling";
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/types.d.ts
|
|
80
|
-
/**
|
|
81
|
-
* Configuration options for the {@link ConfigDirectorClient}
|
|
82
|
-
*/
|
|
83
|
-
type ConfigDirectorClientOptions = {
|
|
84
|
-
/**
|
|
85
|
-
* Application metadata that remains constant through the lifetime of the connection
|
|
86
|
-
*/
|
|
87
|
-
metadata?: ConfigDirectorMetaContext;
|
|
88
|
-
/**
|
|
89
|
-
* Connection options
|
|
90
|
-
*/
|
|
91
|
-
connection?: {
|
|
92
|
-
/**
|
|
93
|
-
* The connection mode to be used, one of `streaming` (default) or `polling`.
|
|
94
|
-
* If set to `streaming`, the connection will remain open and receive updates whenever
|
|
95
|
-
* config state is updated on the ConfigDirector dashboard.
|
|
96
|
-
* When set to `polling`, there will be an initial request to retrieve config state during
|
|
97
|
-
* initialization, and additional requests on a `pollingInterval`.
|
|
98
|
-
*
|
|
99
|
-
* Defaults to `streaming`
|
|
100
|
-
*/
|
|
101
|
-
mode?: ConnectionMode;
|
|
102
|
-
/**
|
|
103
|
-
* The polling interval in _seconds_ when the `mode` is set to `polling`. This option has no
|
|
104
|
-
* effect when the `mode` is set to `streaming`.
|
|
105
|
-
*
|
|
106
|
-
* Defaults to 60 seconds
|
|
107
|
-
*/
|
|
108
|
-
pollingInterval?: number;
|
|
109
|
-
/**
|
|
110
|
-
* The timeout, in milliseconds, to be used in initialization and when updating the context.
|
|
111
|
-
* If streaming is enabled, the operation (initialization or context update) may still succeed
|
|
112
|
-
* after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
|
|
113
|
-
* If streaming is disabled, if the operation times out, it will not be retried.
|
|
114
|
-
*
|
|
115
|
-
* Defaults to 3,000 milliseconds (3 seconds)
|
|
116
|
-
*/
|
|
117
|
-
timeout?: number;
|
|
118
|
-
/**
|
|
119
|
-
* The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
|
|
120
|
-
* proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
|
|
121
|
-
* a proxy for the client SDK.
|
|
122
|
-
*/
|
|
123
|
-
url?: string;
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
|
|
127
|
-
* logger set to 'warn' level.
|
|
128
|
-
*
|
|
129
|
-
* The log level of the default logger can be adjusted by creating a default logger with the desired
|
|
130
|
-
* level and providing it in this property:
|
|
131
|
-
* @example
|
|
132
|
-
* import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
|
|
133
|
-
* const client = createClient(
|
|
134
|
-
* "YOUR-SERVER-SDK-KEY",
|
|
135
|
-
* { logger: createConsoleLogger("debug") },
|
|
136
|
-
* );
|
|
137
|
-
*/
|
|
138
|
-
logger?: ConfigDirectorLogger;
|
|
139
|
-
/**
|
|
140
|
-
* Telemetry tunning. It is unlikely these settings need to be adjusted. However, in cases where
|
|
141
|
-
* your application has a large number of evaluations per second, you can adjust these settings
|
|
142
|
-
* to tune the memory footprint and frequency of telemetry requests.
|
|
143
|
-
* Keep in mind that ConfigDirector relies on these telemetry events to provide insights and features
|
|
144
|
-
* related to the configs being used.
|
|
145
|
-
*/
|
|
146
|
-
telemetry?: {
|
|
147
|
-
/**
|
|
148
|
-
* The size limit of telemetry event queues. If the size limit is reached before the events are
|
|
149
|
-
* flushed to the network, older events will be dropped.
|
|
150
|
-
*
|
|
151
|
-
* ConfigDirector keeps a count of dropped events. If the number of dropped events is higher than
|
|
152
|
-
* 50% of the total events, ConfigDirector will issue a notification alert in the dashboard.
|
|
153
|
-
*
|
|
154
|
-
* A number between 100 and 100,000. Defaults to 5,000.
|
|
155
|
-
*/
|
|
156
|
-
eventQueueLimit?: number;
|
|
157
|
-
/**
|
|
158
|
-
* How often events are flushed and sent over the network in milliseconds.
|
|
159
|
-
*
|
|
160
|
-
* Decrease this number if your application consistently captures a large number of events in short
|
|
161
|
-
* periods of time in order to reduce memory footprint from a large event queue.
|
|
162
|
-
*
|
|
163
|
-
* Defaults to 30,000 milliseconds (30 seconds)
|
|
164
|
-
*/
|
|
165
|
-
flushInterval?: number;
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Handlers for hooks/events emitted by the client. Each hook accepts either a single event handler or
|
|
169
|
-
* an array of event handlers.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
|
|
173
|
-
* const client = createClient(
|
|
174
|
-
* "YOUR-SERVER-SDK-KEY",
|
|
175
|
-
* {
|
|
176
|
-
* hooks: {
|
|
177
|
-
* configEvaluated: (event) => { console.log(event.evaluation); }
|
|
178
|
-
* },
|
|
179
|
-
* },
|
|
180
|
-
* );
|
|
181
|
-
*/
|
|
182
|
-
hooks?: ClientHooks;
|
|
183
|
-
};
|
|
184
|
-
type ClientEvents = {
|
|
185
|
-
configsUpdated: {
|
|
186
|
-
keys: string[];
|
|
187
|
-
};
|
|
188
|
-
clientReady: undefined;
|
|
189
|
-
configEvaluated: {
|
|
190
|
-
evaluation: ConfigEvaluation;
|
|
191
|
-
};
|
|
192
|
-
connectionError: {
|
|
193
|
-
error: Error;
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
type ClientHooks = {
|
|
197
|
-
clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
|
|
198
|
-
configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
|
|
199
|
-
configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
|
|
200
|
-
connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
|
|
201
|
-
};
|
|
202
|
-
type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
|
|
203
|
-
type WatchHandler<T extends ConfigValueType> = (message: T) => void;
|
|
204
|
-
/**
|
|
205
|
-
* The ConfigDirector SDK client object.
|
|
206
|
-
*
|
|
207
|
-
* Applications should create a single instance of `ConfigDirectorClient`, and call
|
|
208
|
-
* {@link initialize} during application initialization.
|
|
209
|
-
*/
|
|
210
|
-
interface ConfigDirectorClient {
|
|
211
|
-
/**
|
|
212
|
-
* Initializes the connection to ConfigDirector to retrieve config definitions. Until
|
|
213
|
-
* initialization is successful, all flags will return their default value provided to
|
|
214
|
-
* {@link watch} or {@link getValue}.
|
|
215
|
-
*
|
|
216
|
-
* If the connection fails or is interrupted with a transient error (network error,
|
|
217
|
-
* internal server error, etc) the client will continue to attempt to connect. However,
|
|
218
|
-
* if the connection fails with a persistent error, like an invalid SDK key, the client will
|
|
219
|
-
* not attempt to re-connect and an error will be logged to the console or the provided
|
|
220
|
-
* logger.
|
|
221
|
-
*/
|
|
222
|
-
initialize(): Promise<void>;
|
|
223
|
-
/**
|
|
224
|
-
* Returns whether or not the client is ready after calling {@link initialize}
|
|
225
|
-
*
|
|
226
|
-
* The definition of ready is that the connection to the server was successful, and config definitions
|
|
227
|
-
* were received.
|
|
228
|
-
*/
|
|
229
|
-
get isReady(): boolean;
|
|
230
|
-
/**
|
|
231
|
-
* Evaluates a config and returns its value based on the current context and targeting rules
|
|
232
|
-
*
|
|
233
|
-
* @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
|
|
234
|
-
* @param configKey The config key to evaluate
|
|
235
|
-
* @param defaultValue The default value to be returned if the config state is unavailable. For
|
|
236
|
-
* example, if the client cannot connect to the server due to network conditions, or if getValue
|
|
237
|
-
* is called before initialization is done.
|
|
238
|
-
* @param context The user's context to be used for targeting rules evaluation (optional)
|
|
239
|
-
*/
|
|
240
|
-
getValue<T extends ConfigValueType>(configKey: string, defaultValue: T, context?: ConfigDirectorContext): T;
|
|
241
|
-
/**
|
|
242
|
-
* Watches for changes to a a config evaluation value. Whenever the config value changes, the
|
|
243
|
-
* provided callback function will be called with the new value. Changes can happen due to updates
|
|
244
|
-
* to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
|
|
245
|
-
*
|
|
246
|
-
* @returns An 'unwatch' function that can be called to remove the subscriber
|
|
247
|
-
*
|
|
248
|
-
* @param configKey The config key to watch
|
|
249
|
-
* @param defaultValue The default value to be referenced if the config state is unavailable
|
|
250
|
-
* @param callback The callback function to be called whenever the config value is updated
|
|
251
|
-
* @param context The user's context to be used for targeting rules evaluation (optional)
|
|
252
|
-
*/
|
|
253
|
-
watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>, context?: ConfigDirectorContext): () => void;
|
|
254
|
-
/**
|
|
255
|
-
* Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
|
|
256
|
-
* is provided.
|
|
257
|
-
*
|
|
258
|
-
* @param configKey The config key to remove subscribers from
|
|
259
|
-
* @param callback The subscriber to be removed. If not provided, all subscribers are removed for
|
|
260
|
-
* the given `configKey`.
|
|
261
|
-
*/
|
|
262
|
-
unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
|
|
263
|
-
/**
|
|
264
|
-
* Removes all subscribers from all config keys
|
|
265
|
-
*/
|
|
266
|
-
unwatchAll(): void;
|
|
267
|
-
/**
|
|
268
|
-
* Returns the evaluated {@link ConfigState} for every known config key, or only the keys
|
|
269
|
-
* listed in `configKeys` when provided.
|
|
270
|
-
*
|
|
271
|
-
* Intended for SSR hydration — does NOT record telemetry events. Returns an empty object
|
|
272
|
-
* when the client is not yet ready.
|
|
273
|
-
*/
|
|
274
|
-
getAllConfigs(options?: {
|
|
275
|
-
context?: ConfigDirectorContext;
|
|
276
|
-
configKeys?: string[];
|
|
277
|
-
}): Record<string, ConfigState>;
|
|
278
|
-
on<T extends keyof ClientEvents>(eventName: T, handler: (args: ClientEvents[T]) => void): void;
|
|
279
|
-
off<T extends keyof ClientEvents>(eventName: T, handler?: (args: ClientEvents[T]) => void): void;
|
|
280
|
-
/**
|
|
281
|
-
* Disposes of the client. All connections are closed, and all event and config key subscribers
|
|
282
|
-
* are removed.
|
|
283
|
-
*
|
|
284
|
-
* Intended to be called when your application shuts down
|
|
285
|
-
*/
|
|
286
|
-
dispose(): void;
|
|
287
|
-
}
|
|
288
|
-
//#endregion
|
|
1
|
+
import { a as ConfigDirectorLogger, c as ConfigValueType, i as ConfigDirectorLogMessageDecorator, n as ConfigDirectorClientOptions, o as ConfigDirectorLoggingLevel, r as ConfigDirectorContext, s as ConfigDirectorMetaContext, t as ConfigDirectorClient } from "./types-CcUNxeqN.cjs";
|
|
2
|
+
|
|
289
3
|
//#region ../shared/src/logger.d.ts
|
|
290
4
|
declare class DefaultConsoleLogger implements ConfigDirectorLogger {
|
|
291
5
|
private readonly level;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configdirector-server.d.cts","names":[],"sources":["../../shared/src/
|
|
1
|
+
{"version":3,"file":"configdirector-server.d.cts","names":[],"sources":["../../shared/src/logger.ts","../src/api.ts"],"mappings":";;;cA+Ba,oBAAA,YAAgC,oBAAA;EAAA,iBAGd,KAAA;EAAA,iBAAoD,SAAA;EAAA,iBAFhE,aAAA;cAEY,KAAA,EAAO,0BAAA,EAA6C,SAAA,EAAW,iCAAA;EAM5F,KAAA,CAAM,OAAA,aAAoB,IAAA;EAI1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAIzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAIzB,KAAA,CAAM,OAAA,aAAoB,IAAA;EAAA,UAIhB,GAAA,CAAI,cAAA,MAAoB,IAAA,gBAAoB,KAAA,EAAO,0BAAA,EAA4B,OAAA,aAAoB,IAAA;AAAA;;;;AAzB/G;;;;;;;;;;;;;;;;;;;;;;;;cCDa,YAAA,GACX,YAAA,UACA,aAAA,GAAgB,2BAAA,KACf,oBAAA;AAAA,cAQU,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
|
|
@@ -1,291 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type ConfigType = (typeof ConfigTypeList)[number];
|
|
4
|
-
type ConfigEnumLikeType = {
|
|
5
|
-
[key: string]: string | number;
|
|
6
|
-
};
|
|
7
|
-
type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
|
|
8
|
-
type ConfigState = {
|
|
9
|
-
id: string;
|
|
10
|
-
key: string;
|
|
11
|
-
type: ConfigType;
|
|
12
|
-
value: string | undefined | null;
|
|
13
|
-
valueId?: string | undefined | null;
|
|
14
|
-
};
|
|
15
|
-
type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
|
|
16
|
-
interface ConfigDirectorLogger {
|
|
17
|
-
debug(message: string, ...args: any): void;
|
|
18
|
-
info(message: string, ...args: any): void;
|
|
19
|
-
warn(message: string, ...args: any): void;
|
|
20
|
-
error(message: string, ...args: any): void;
|
|
21
|
-
}
|
|
22
|
-
interface ConfigDirectorLogMessageDecorator {
|
|
23
|
-
decorateMessage(message: string): string;
|
|
24
|
-
}
|
|
25
|
-
type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean";
|
|
26
|
-
type ConfigEvaluation = {
|
|
27
|
-
key: string;
|
|
28
|
-
value: ConfigValueType;
|
|
29
|
-
valueId?: string;
|
|
30
|
-
isDefaultValue: boolean;
|
|
31
|
-
reason: EvaluationReason;
|
|
32
|
-
context?: ConfigDirectorContext;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* The user's context to be sent to ConfigDirector. This context will be used for targeting
|
|
36
|
-
* rules evaluation.
|
|
37
|
-
*/
|
|
38
|
-
type ConfigDirectorContext = {
|
|
39
|
-
/**
|
|
40
|
-
* The user's identifier. This should be a value that uniquely identifies an application
|
|
41
|
-
* user.
|
|
42
|
-
* In the case of anonymous users, you could generate a UUID or alternatively not provide
|
|
43
|
-
* the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
|
|
44
|
-
* value is used for segmenting users in percentage rollouts, and changes to the {@link id}
|
|
45
|
-
* could result in the user being assigned to a different percentile.
|
|
46
|
-
*/
|
|
47
|
-
id?: string;
|
|
48
|
-
/**
|
|
49
|
-
* The user's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
50
|
-
* used for targeting rules.
|
|
51
|
-
*/
|
|
52
|
-
name?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Any arbitrary traits for the current user. They will be shown in the ConfigDirector
|
|
55
|
-
* dashboard and may be used for targeting rules.
|
|
56
|
-
*/
|
|
57
|
-
traits?: {
|
|
58
|
-
[key: string]: unknown;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Whether or not to treat the context as anonymous during evaluation. When `true`, the
|
|
62
|
-
* context values will be used for targeting rules evaluation but the context will not be
|
|
63
|
-
* persisted and will not appear in the dashboard.
|
|
64
|
-
*
|
|
65
|
-
* @default false
|
|
66
|
-
*/
|
|
67
|
-
anonymous?: boolean;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Metadata about your application. It is recommended you include these values when configuring
|
|
71
|
-
* a ConfigDirector client so that you can use them in targeting rules.
|
|
72
|
-
*/
|
|
73
|
-
type ConfigDirectorMetaContext = {
|
|
74
|
-
appVersion?: string;
|
|
75
|
-
appName?: string;
|
|
76
|
-
};
|
|
77
|
-
type ConnectionMode = "streaming" | "polling";
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/types.d.ts
|
|
80
|
-
/**
|
|
81
|
-
* Configuration options for the {@link ConfigDirectorClient}
|
|
82
|
-
*/
|
|
83
|
-
type ConfigDirectorClientOptions = {
|
|
84
|
-
/**
|
|
85
|
-
* Application metadata that remains constant through the lifetime of the connection
|
|
86
|
-
*/
|
|
87
|
-
metadata?: ConfigDirectorMetaContext;
|
|
88
|
-
/**
|
|
89
|
-
* Connection options
|
|
90
|
-
*/
|
|
91
|
-
connection?: {
|
|
92
|
-
/**
|
|
93
|
-
* The connection mode to be used, one of `streaming` (default) or `polling`.
|
|
94
|
-
* If set to `streaming`, the connection will remain open and receive updates whenever
|
|
95
|
-
* config state is updated on the ConfigDirector dashboard.
|
|
96
|
-
* When set to `polling`, there will be an initial request to retrieve config state during
|
|
97
|
-
* initialization, and additional requests on a `pollingInterval`.
|
|
98
|
-
*
|
|
99
|
-
* Defaults to `streaming`
|
|
100
|
-
*/
|
|
101
|
-
mode?: ConnectionMode;
|
|
102
|
-
/**
|
|
103
|
-
* The polling interval in _seconds_ when the `mode` is set to `polling`. This option has no
|
|
104
|
-
* effect when the `mode` is set to `streaming`.
|
|
105
|
-
*
|
|
106
|
-
* Defaults to 60 seconds
|
|
107
|
-
*/
|
|
108
|
-
pollingInterval?: number;
|
|
109
|
-
/**
|
|
110
|
-
* The timeout, in milliseconds, to be used in initialization and when updating the context.
|
|
111
|
-
* If streaming is enabled, the operation (initialization or context update) may still succeed
|
|
112
|
-
* after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
|
|
113
|
-
* If streaming is disabled, if the operation times out, it will not be retried.
|
|
114
|
-
*
|
|
115
|
-
* Defaults to 3,000 milliseconds (3 seconds)
|
|
116
|
-
*/
|
|
117
|
-
timeout?: number;
|
|
118
|
-
/**
|
|
119
|
-
* The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
|
|
120
|
-
* proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
|
|
121
|
-
* a proxy for the client SDK.
|
|
122
|
-
*/
|
|
123
|
-
url?: string;
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
|
|
127
|
-
* logger set to 'warn' level.
|
|
128
|
-
*
|
|
129
|
-
* The log level of the default logger can be adjusted by creating a default logger with the desired
|
|
130
|
-
* level and providing it in this property:
|
|
131
|
-
* @example
|
|
132
|
-
* import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
|
|
133
|
-
* const client = createClient(
|
|
134
|
-
* "YOUR-SERVER-SDK-KEY",
|
|
135
|
-
* { logger: createConsoleLogger("debug") },
|
|
136
|
-
* );
|
|
137
|
-
*/
|
|
138
|
-
logger?: ConfigDirectorLogger;
|
|
139
|
-
/**
|
|
140
|
-
* Telemetry tunning. It is unlikely these settings need to be adjusted. However, in cases where
|
|
141
|
-
* your application has a large number of evaluations per second, you can adjust these settings
|
|
142
|
-
* to tune the memory footprint and frequency of telemetry requests.
|
|
143
|
-
* Keep in mind that ConfigDirector relies on these telemetry events to provide insights and features
|
|
144
|
-
* related to the configs being used.
|
|
145
|
-
*/
|
|
146
|
-
telemetry?: {
|
|
147
|
-
/**
|
|
148
|
-
* The size limit of telemetry event queues. If the size limit is reached before the events are
|
|
149
|
-
* flushed to the network, older events will be dropped.
|
|
150
|
-
*
|
|
151
|
-
* ConfigDirector keeps a count of dropped events. If the number of dropped events is higher than
|
|
152
|
-
* 50% of the total events, ConfigDirector will issue a notification alert in the dashboard.
|
|
153
|
-
*
|
|
154
|
-
* A number between 100 and 100,000. Defaults to 5,000.
|
|
155
|
-
*/
|
|
156
|
-
eventQueueLimit?: number;
|
|
157
|
-
/**
|
|
158
|
-
* How often events are flushed and sent over the network in milliseconds.
|
|
159
|
-
*
|
|
160
|
-
* Decrease this number if your application consistently captures a large number of events in short
|
|
161
|
-
* periods of time in order to reduce memory footprint from a large event queue.
|
|
162
|
-
*
|
|
163
|
-
* Defaults to 30,000 milliseconds (30 seconds)
|
|
164
|
-
*/
|
|
165
|
-
flushInterval?: number;
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Handlers for hooks/events emitted by the client. Each hook accepts either a single event handler or
|
|
169
|
-
* an array of event handlers.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
|
|
173
|
-
* const client = createClient(
|
|
174
|
-
* "YOUR-SERVER-SDK-KEY",
|
|
175
|
-
* {
|
|
176
|
-
* hooks: {
|
|
177
|
-
* configEvaluated: (event) => { console.log(event.evaluation); }
|
|
178
|
-
* },
|
|
179
|
-
* },
|
|
180
|
-
* );
|
|
181
|
-
*/
|
|
182
|
-
hooks?: ClientHooks;
|
|
183
|
-
};
|
|
184
|
-
type ClientEvents = {
|
|
185
|
-
configsUpdated: {
|
|
186
|
-
keys: string[];
|
|
187
|
-
};
|
|
188
|
-
clientReady: undefined;
|
|
189
|
-
configEvaluated: {
|
|
190
|
-
evaluation: ConfigEvaluation;
|
|
191
|
-
};
|
|
192
|
-
connectionError: {
|
|
193
|
-
error: Error;
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
type ClientHooks = {
|
|
197
|
-
clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
|
|
198
|
-
configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
|
|
199
|
-
configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
|
|
200
|
-
connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
|
|
201
|
-
};
|
|
202
|
-
type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
|
|
203
|
-
type WatchHandler<T extends ConfigValueType> = (message: T) => void;
|
|
204
|
-
/**
|
|
205
|
-
* The ConfigDirector SDK client object.
|
|
206
|
-
*
|
|
207
|
-
* Applications should create a single instance of `ConfigDirectorClient`, and call
|
|
208
|
-
* {@link initialize} during application initialization.
|
|
209
|
-
*/
|
|
210
|
-
interface ConfigDirectorClient {
|
|
211
|
-
/**
|
|
212
|
-
* Initializes the connection to ConfigDirector to retrieve config definitions. Until
|
|
213
|
-
* initialization is successful, all flags will return their default value provided to
|
|
214
|
-
* {@link watch} or {@link getValue}.
|
|
215
|
-
*
|
|
216
|
-
* If the connection fails or is interrupted with a transient error (network error,
|
|
217
|
-
* internal server error, etc) the client will continue to attempt to connect. However,
|
|
218
|
-
* if the connection fails with a persistent error, like an invalid SDK key, the client will
|
|
219
|
-
* not attempt to re-connect and an error will be logged to the console or the provided
|
|
220
|
-
* logger.
|
|
221
|
-
*/
|
|
222
|
-
initialize(): Promise<void>;
|
|
223
|
-
/**
|
|
224
|
-
* Returns whether or not the client is ready after calling {@link initialize}
|
|
225
|
-
*
|
|
226
|
-
* The definition of ready is that the connection to the server was successful, and config definitions
|
|
227
|
-
* were received.
|
|
228
|
-
*/
|
|
229
|
-
get isReady(): boolean;
|
|
230
|
-
/**
|
|
231
|
-
* Evaluates a config and returns its value based on the current context and targeting rules
|
|
232
|
-
*
|
|
233
|
-
* @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
|
|
234
|
-
* @param configKey The config key to evaluate
|
|
235
|
-
* @param defaultValue The default value to be returned if the config state is unavailable. For
|
|
236
|
-
* example, if the client cannot connect to the server due to network conditions, or if getValue
|
|
237
|
-
* is called before initialization is done.
|
|
238
|
-
* @param context The user's context to be used for targeting rules evaluation (optional)
|
|
239
|
-
*/
|
|
240
|
-
getValue<T extends ConfigValueType>(configKey: string, defaultValue: T, context?: ConfigDirectorContext): T;
|
|
241
|
-
/**
|
|
242
|
-
* Watches for changes to a a config evaluation value. Whenever the config value changes, the
|
|
243
|
-
* provided callback function will be called with the new value. Changes can happen due to updates
|
|
244
|
-
* to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
|
|
245
|
-
*
|
|
246
|
-
* @returns An 'unwatch' function that can be called to remove the subscriber
|
|
247
|
-
*
|
|
248
|
-
* @param configKey The config key to watch
|
|
249
|
-
* @param defaultValue The default value to be referenced if the config state is unavailable
|
|
250
|
-
* @param callback The callback function to be called whenever the config value is updated
|
|
251
|
-
* @param context The user's context to be used for targeting rules evaluation (optional)
|
|
252
|
-
*/
|
|
253
|
-
watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>, context?: ConfigDirectorContext): () => void;
|
|
254
|
-
/**
|
|
255
|
-
* Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
|
|
256
|
-
* is provided.
|
|
257
|
-
*
|
|
258
|
-
* @param configKey The config key to remove subscribers from
|
|
259
|
-
* @param callback The subscriber to be removed. If not provided, all subscribers are removed for
|
|
260
|
-
* the given `configKey`.
|
|
261
|
-
*/
|
|
262
|
-
unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
|
|
263
|
-
/**
|
|
264
|
-
* Removes all subscribers from all config keys
|
|
265
|
-
*/
|
|
266
|
-
unwatchAll(): void;
|
|
267
|
-
/**
|
|
268
|
-
* Returns the evaluated {@link ConfigState} for every known config key, or only the keys
|
|
269
|
-
* listed in `configKeys` when provided.
|
|
270
|
-
*
|
|
271
|
-
* Intended for SSR hydration — does NOT record telemetry events. Returns an empty object
|
|
272
|
-
* when the client is not yet ready.
|
|
273
|
-
*/
|
|
274
|
-
getAllConfigs(options?: {
|
|
275
|
-
context?: ConfigDirectorContext;
|
|
276
|
-
configKeys?: string[];
|
|
277
|
-
}): Record<string, ConfigState>;
|
|
278
|
-
on<T extends keyof ClientEvents>(eventName: T, handler: (args: ClientEvents[T]) => void): void;
|
|
279
|
-
off<T extends keyof ClientEvents>(eventName: T, handler?: (args: ClientEvents[T]) => void): void;
|
|
280
|
-
/**
|
|
281
|
-
* Disposes of the client. All connections are closed, and all event and config key subscribers
|
|
282
|
-
* are removed.
|
|
283
|
-
*
|
|
284
|
-
* Intended to be called when your application shuts down
|
|
285
|
-
*/
|
|
286
|
-
dispose(): void;
|
|
287
|
-
}
|
|
288
|
-
//#endregion
|
|
1
|
+
import { a as ConfigDirectorLogger, c as ConfigValueType, i as ConfigDirectorLogMessageDecorator, n as ConfigDirectorClientOptions, o as ConfigDirectorLoggingLevel, r as ConfigDirectorContext, s as ConfigDirectorMetaContext, t as ConfigDirectorClient } from "./types-BqIJGXWv.mjs";
|
|
2
|
+
|
|
289
3
|
//#region ../shared/src/logger.d.ts
|
|
290
4
|
declare class DefaultConsoleLogger implements ConfigDirectorLogger {
|
|
291
5
|
private readonly level;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configdirector-server.d.mts","names":[],"sources":["../../shared/src/
|
|
1
|
+
{"version":3,"file":"configdirector-server.d.mts","names":[],"sources":["../../shared/src/logger.ts","../src/api.ts"],"mappings":";;;cA+Ba,oBAAA,YAAgC,oBAAA;EAAA,iBAGd,KAAA;EAAA,iBAAoD,SAAA;EAAA,iBAFhE,aAAA;cAEY,KAAA,EAAO,0BAAA,EAA6C,SAAA,EAAW,iCAAA;EAM5F,KAAA,CAAM,OAAA,aAAoB,IAAA;EAI1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAIzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAIzB,KAAA,CAAM,OAAA,aAAoB,IAAA;EAAA,UAIhB,GAAA,CAAI,cAAA,MAAoB,IAAA,gBAAoB,KAAA,EAAO,0BAAA,EAA4B,OAAA,aAAoB,IAAA;AAAA;;;;AAzB/G;;;;;;;;;;;;;;;;;;;;;;;;cCDa,YAAA,GACX,YAAA,UACA,aAAA,GAAgB,2BAAA,KACf,oBAAA;AAAA,cAQU,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
|