@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.
@@ -0,0 +1,292 @@
1
+ //#region ../shared/src/types.d.ts
2
+ declare const ConfigTypeList: readonly ["custom", "boolean", "string", "integer", "float", "enum", "url", "json"];
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 300 seconds (5 minutes). The minimum is 60 seconds. A value below the minimum is
107
+ * raised to the minimum and a warning is logged.
108
+ */
109
+ pollingInterval?: number;
110
+ /**
111
+ * The timeout, in milliseconds, to be used in initialization and when updating the context.
112
+ * If streaming is enabled, the operation (initialization or context update) may still succeed
113
+ * after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
114
+ * If streaming is disabled, if the operation times out, it will not be retried.
115
+ *
116
+ * Defaults to 3,000 milliseconds (3 seconds)
117
+ */
118
+ timeout?: number;
119
+ /**
120
+ * The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
121
+ * proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
122
+ * a proxy for the client SDK.
123
+ */
124
+ url?: string;
125
+ };
126
+ /**
127
+ * A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
128
+ * logger set to 'warn' level.
129
+ *
130
+ * The log level of the default logger can be adjusted by creating a default logger with the desired
131
+ * level and providing it in this property:
132
+ * @example
133
+ * import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
134
+ * const client = createClient(
135
+ * "YOUR-SERVER-SDK-KEY",
136
+ * { logger: createConsoleLogger("debug") },
137
+ * );
138
+ */
139
+ logger?: ConfigDirectorLogger;
140
+ /**
141
+ * Telemetry tunning. It is unlikely these settings need to be adjusted. However, in cases where
142
+ * your application has a large number of evaluations per second, you can adjust these settings
143
+ * to tune the memory footprint and frequency of telemetry requests.
144
+ * Keep in mind that ConfigDirector relies on these telemetry events to provide insights and features
145
+ * related to the configs being used.
146
+ */
147
+ telemetry?: {
148
+ /**
149
+ * The size limit of telemetry event queues. If the size limit is reached before the events are
150
+ * flushed to the network, older events will be dropped.
151
+ *
152
+ * ConfigDirector keeps a count of dropped events. If the number of dropped events is higher than
153
+ * 50% of the total events, ConfigDirector will issue a notification alert in the dashboard.
154
+ *
155
+ * A number between 100 and 100,000. Defaults to 5,000.
156
+ */
157
+ eventQueueLimit?: number;
158
+ /**
159
+ * How often events are flushed and sent over the network in milliseconds.
160
+ *
161
+ * Decrease this number if your application consistently captures a large number of events in short
162
+ * periods of time in order to reduce memory footprint from a large event queue.
163
+ *
164
+ * Defaults to 30,000 milliseconds (30 seconds)
165
+ */
166
+ flushInterval?: number;
167
+ };
168
+ /**
169
+ * Handlers for hooks/events emitted by the client. Each hook accepts either a single event handler or
170
+ * an array of event handlers.
171
+ *
172
+ * @example
173
+ * import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
174
+ * const client = createClient(
175
+ * "YOUR-SERVER-SDK-KEY",
176
+ * {
177
+ * hooks: {
178
+ * configEvaluated: (event) => { console.log(event.evaluation); }
179
+ * },
180
+ * },
181
+ * );
182
+ */
183
+ hooks?: ClientHooks;
184
+ };
185
+ type ClientEvents = {
186
+ configsUpdated: {
187
+ keys: string[];
188
+ removedKeys: string[];
189
+ };
190
+ clientReady: undefined;
191
+ configEvaluated: {
192
+ evaluation: ConfigEvaluation;
193
+ };
194
+ connectionError: {
195
+ error: Error;
196
+ };
197
+ };
198
+ type ClientHooks = {
199
+ clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
200
+ configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
201
+ configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
202
+ connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
203
+ };
204
+ type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
205
+ type WatchHandler<T extends ConfigValueType> = (message: T) => void;
206
+ /**
207
+ * The ConfigDirector SDK client object.
208
+ *
209
+ * Applications should create a single instance of `ConfigDirectorClient`, and call
210
+ * {@link initialize} during application initialization.
211
+ */
212
+ interface ConfigDirectorClient {
213
+ /**
214
+ * Initializes the connection to ConfigDirector to retrieve config definitions. Until
215
+ * initialization is successful, all flags will return their default value provided to
216
+ * {@link watch} or {@link getValue}.
217
+ *
218
+ * If the connection fails or is interrupted with a transient error (network error,
219
+ * internal server error, etc) the client will continue to attempt to connect. However,
220
+ * if the connection fails with a persistent error, like an invalid SDK key, the client will
221
+ * not attempt to re-connect and an error will be logged to the console or the provided
222
+ * logger.
223
+ */
224
+ initialize(): Promise<void>;
225
+ /**
226
+ * Returns whether or not the client is ready after calling {@link initialize}
227
+ *
228
+ * The definition of ready is that the connection to the server was successful, and config definitions
229
+ * were received.
230
+ */
231
+ get isReady(): boolean;
232
+ /**
233
+ * Evaluates a config and returns its value based on the current context and targeting rules
234
+ *
235
+ * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
236
+ * @param configKey The config key to evaluate
237
+ * @param defaultValue The default value to be returned if the config state is unavailable. For
238
+ * example, if the client cannot connect to the server due to network conditions, or if getValue
239
+ * is called before initialization is done.
240
+ * @param context The user's context to be used for targeting rules evaluation (optional)
241
+ */
242
+ getValue<T extends ConfigValueType>(configKey: string, defaultValue: T, context?: ConfigDirectorContext): T;
243
+ /**
244
+ * Watches for changes to a a config evaluation value. Whenever the config value changes, the
245
+ * provided callback function will be called with the new value. Changes can happen due to updates
246
+ * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
247
+ *
248
+ * @returns An 'unwatch' function that can be called to remove the subscriber
249
+ *
250
+ * @param configKey The config key to watch
251
+ * @param defaultValue The default value to be referenced if the config state is unavailable
252
+ * @param callback The callback function to be called whenever the config value is updated
253
+ * @param context The user's context to be used for targeting rules evaluation (optional)
254
+ */
255
+ watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>, context?: ConfigDirectorContext): () => void;
256
+ /**
257
+ * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
258
+ * is provided.
259
+ *
260
+ * @param configKey The config key to remove subscribers from
261
+ * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
262
+ * the given `configKey`.
263
+ */
264
+ unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
265
+ /**
266
+ * Removes all subscribers from all config keys
267
+ */
268
+ unwatchAll(): void;
269
+ /**
270
+ * Returns the evaluated {@link ConfigState} for every known config key, or only the keys
271
+ * listed in `configKeys` when provided.
272
+ *
273
+ * Intended for SSR hydration — does NOT record telemetry events. Returns an empty object
274
+ * when the client is not yet ready.
275
+ */
276
+ getAllConfigs(options?: {
277
+ context?: ConfigDirectorContext;
278
+ configKeys?: string[];
279
+ }): Record<string, ConfigState>;
280
+ on<T extends keyof ClientEvents>(eventName: T, handler: (args: ClientEvents[T]) => void): void;
281
+ off<T extends keyof ClientEvents>(eventName: T, handler?: (args: ClientEvents[T]) => void): void;
282
+ /**
283
+ * Disposes of the client. All connections are closed, and all event and config key subscribers
284
+ * are removed.
285
+ *
286
+ * Intended to be called when your application shuts down
287
+ */
288
+ dispose(): void;
289
+ }
290
+ //#endregion
291
+ export { ConfigDirectorLogger as a, ConfigValueType as c, ConfigDirectorLogMessageDecorator as i, ConfigDirectorClientOptions as n, ConfigDirectorLoggingLevel as o, ConfigDirectorContext as r, ConfigDirectorMetaContext as s, ConfigDirectorClient as t };
292
+ //# sourceMappingURL=types-BqIJGXWv.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-BqIJGXWv.d.mts","names":[],"sources":["../../shared/src/types.ts","../src/types.ts"],"mappings":";cAAa,cAAA;AAAA,KAUD,UAAA,WAAqB,cAAA;AAAA,KAErB,kBAAA;EAAA,CAAwB,GAAA;AAAA;AAAA,KAExB,eAAA,wCAAuD,kBAAA;AAAA,KAEvD,WAAA;EACV,EAAA;EACA,GAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,OAAA;AAAA;AAAA,KAQU,0BAAA;AAAA,UAEK,oBAAA;EACf,KAAA,CAAM,OAAA,aAAoB,IAAA;EAE1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,KAAA,CAAM,OAAA,aAAoB,IAAA;AAAA;AAAA,UAGX,iCAAA;EACf,eAAA,CAAgB,OAAA;AAAA;AAAA,KAGN,gBAAA;AAAA,KAUA,gBAAA;EACV,GAAA;EACA,KAAA,EAAO,eAAA;EACP,OAAA;EACA,cAAA;EACA,MAAA,EAAQ,gBAAA;EACR,OAAA,GAAU,qBAAA;AAAA;;;AA9BZ;;KAoCY,qBAAA;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;;AAGjC;;;;EAHiC,IAwC3B,OAAA;EAnCa;;;;;;;;;;EA+CjB,QAAA,WAAmB,eAAA,EAAiB,SAAA,UAAmB,YAAA,EAAc,CAAA,EAAG,OAAA,GAAU,qBAAA,GAAwB,CAAA;EA/C1G;;;;;;;;;;;AAKF;EAwDE,KAAA,WAAgB,eAAA,EACd,SAAA,UACA,YAAA,EAAc,CAAA,EACd,QAAA,EAAU,YAAA,CAAa,CAAA,GACvB,OAAA,GAAU,qBAAA;EA5DS;;;;;;;;EAuErB,OAAA,WAAkB,eAAA,EAAiB,SAAA,UAAmB,QAAA,GAAW,YAAA,CAAa,CAAA;EAvEI;;;EA4ElF,UAAA;EA1EU;;;;;;;EAmFV,aAAA,CAAc,OAAA;IACZ,OAAA,GAAU,qBAAA;IACV,UAAA;EAAA,IACE,MAAA,SAAe,WAAA;EAEnB,EAAA,iBAAmB,YAAA,EAAc,SAAA,EAAW,CAAA,EAAG,OAAA,GAAU,IAAA,EAAM,YAAA,CAAa,CAAA;EAE5E,GAAA,iBAAoB,YAAA,EAAc,SAAA,EAAW,CAAA,EAAG,OAAA,IAAW,IAAA,EAAM,YAAA,CAAa,CAAA;EAtEhE;;;;;;EA8Ed,OAAA;AAAA"}
@@ -0,0 +1,292 @@
1
+ //#region ../shared/src/types.d.ts
2
+ declare const ConfigTypeList: readonly ["custom", "boolean", "string", "integer", "float", "enum", "url", "json"];
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 300 seconds (5 minutes). The minimum is 60 seconds. A value below the minimum is
107
+ * raised to the minimum and a warning is logged.
108
+ */
109
+ pollingInterval?: number;
110
+ /**
111
+ * The timeout, in milliseconds, to be used in initialization and when updating the context.
112
+ * If streaming is enabled, the operation (initialization or context update) may still succeed
113
+ * after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
114
+ * If streaming is disabled, if the operation times out, it will not be retried.
115
+ *
116
+ * Defaults to 3,000 milliseconds (3 seconds)
117
+ */
118
+ timeout?: number;
119
+ /**
120
+ * The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
121
+ * proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
122
+ * a proxy for the client SDK.
123
+ */
124
+ url?: string;
125
+ };
126
+ /**
127
+ * A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
128
+ * logger set to 'warn' level.
129
+ *
130
+ * The log level of the default logger can be adjusted by creating a default logger with the desired
131
+ * level and providing it in this property:
132
+ * @example
133
+ * import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
134
+ * const client = createClient(
135
+ * "YOUR-SERVER-SDK-KEY",
136
+ * { logger: createConsoleLogger("debug") },
137
+ * );
138
+ */
139
+ logger?: ConfigDirectorLogger;
140
+ /**
141
+ * Telemetry tunning. It is unlikely these settings need to be adjusted. However, in cases where
142
+ * your application has a large number of evaluations per second, you can adjust these settings
143
+ * to tune the memory footprint and frequency of telemetry requests.
144
+ * Keep in mind that ConfigDirector relies on these telemetry events to provide insights and features
145
+ * related to the configs being used.
146
+ */
147
+ telemetry?: {
148
+ /**
149
+ * The size limit of telemetry event queues. If the size limit is reached before the events are
150
+ * flushed to the network, older events will be dropped.
151
+ *
152
+ * ConfigDirector keeps a count of dropped events. If the number of dropped events is higher than
153
+ * 50% of the total events, ConfigDirector will issue a notification alert in the dashboard.
154
+ *
155
+ * A number between 100 and 100,000. Defaults to 5,000.
156
+ */
157
+ eventQueueLimit?: number;
158
+ /**
159
+ * How often events are flushed and sent over the network in milliseconds.
160
+ *
161
+ * Decrease this number if your application consistently captures a large number of events in short
162
+ * periods of time in order to reduce memory footprint from a large event queue.
163
+ *
164
+ * Defaults to 30,000 milliseconds (30 seconds)
165
+ */
166
+ flushInterval?: number;
167
+ };
168
+ /**
169
+ * Handlers for hooks/events emitted by the client. Each hook accepts either a single event handler or
170
+ * an array of event handlers.
171
+ *
172
+ * @example
173
+ * import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
174
+ * const client = createClient(
175
+ * "YOUR-SERVER-SDK-KEY",
176
+ * {
177
+ * hooks: {
178
+ * configEvaluated: (event) => { console.log(event.evaluation); }
179
+ * },
180
+ * },
181
+ * );
182
+ */
183
+ hooks?: ClientHooks;
184
+ };
185
+ type ClientEvents = {
186
+ configsUpdated: {
187
+ keys: string[];
188
+ removedKeys: string[];
189
+ };
190
+ clientReady: undefined;
191
+ configEvaluated: {
192
+ evaluation: ConfigEvaluation;
193
+ };
194
+ connectionError: {
195
+ error: Error;
196
+ };
197
+ };
198
+ type ClientHooks = {
199
+ clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
200
+ configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
201
+ configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
202
+ connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
203
+ };
204
+ type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
205
+ type WatchHandler<T extends ConfigValueType> = (message: T) => void;
206
+ /**
207
+ * The ConfigDirector SDK client object.
208
+ *
209
+ * Applications should create a single instance of `ConfigDirectorClient`, and call
210
+ * {@link initialize} during application initialization.
211
+ */
212
+ interface ConfigDirectorClient {
213
+ /**
214
+ * Initializes the connection to ConfigDirector to retrieve config definitions. Until
215
+ * initialization is successful, all flags will return their default value provided to
216
+ * {@link watch} or {@link getValue}.
217
+ *
218
+ * If the connection fails or is interrupted with a transient error (network error,
219
+ * internal server error, etc) the client will continue to attempt to connect. However,
220
+ * if the connection fails with a persistent error, like an invalid SDK key, the client will
221
+ * not attempt to re-connect and an error will be logged to the console or the provided
222
+ * logger.
223
+ */
224
+ initialize(): Promise<void>;
225
+ /**
226
+ * Returns whether or not the client is ready after calling {@link initialize}
227
+ *
228
+ * The definition of ready is that the connection to the server was successful, and config definitions
229
+ * were received.
230
+ */
231
+ get isReady(): boolean;
232
+ /**
233
+ * Evaluates a config and returns its value based on the current context and targeting rules
234
+ *
235
+ * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
236
+ * @param configKey The config key to evaluate
237
+ * @param defaultValue The default value to be returned if the config state is unavailable. For
238
+ * example, if the client cannot connect to the server due to network conditions, or if getValue
239
+ * is called before initialization is done.
240
+ * @param context The user's context to be used for targeting rules evaluation (optional)
241
+ */
242
+ getValue<T extends ConfigValueType>(configKey: string, defaultValue: T, context?: ConfigDirectorContext): T;
243
+ /**
244
+ * Watches for changes to a a config evaluation value. Whenever the config value changes, the
245
+ * provided callback function will be called with the new value. Changes can happen due to updates
246
+ * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
247
+ *
248
+ * @returns An 'unwatch' function that can be called to remove the subscriber
249
+ *
250
+ * @param configKey The config key to watch
251
+ * @param defaultValue The default value to be referenced if the config state is unavailable
252
+ * @param callback The callback function to be called whenever the config value is updated
253
+ * @param context The user's context to be used for targeting rules evaluation (optional)
254
+ */
255
+ watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>, context?: ConfigDirectorContext): () => void;
256
+ /**
257
+ * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
258
+ * is provided.
259
+ *
260
+ * @param configKey The config key to remove subscribers from
261
+ * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
262
+ * the given `configKey`.
263
+ */
264
+ unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
265
+ /**
266
+ * Removes all subscribers from all config keys
267
+ */
268
+ unwatchAll(): void;
269
+ /**
270
+ * Returns the evaluated {@link ConfigState} for every known config key, or only the keys
271
+ * listed in `configKeys` when provided.
272
+ *
273
+ * Intended for SSR hydration — does NOT record telemetry events. Returns an empty object
274
+ * when the client is not yet ready.
275
+ */
276
+ getAllConfigs(options?: {
277
+ context?: ConfigDirectorContext;
278
+ configKeys?: string[];
279
+ }): Record<string, ConfigState>;
280
+ on<T extends keyof ClientEvents>(eventName: T, handler: (args: ClientEvents[T]) => void): void;
281
+ off<T extends keyof ClientEvents>(eventName: T, handler?: (args: ClientEvents[T]) => void): void;
282
+ /**
283
+ * Disposes of the client. All connections are closed, and all event and config key subscribers
284
+ * are removed.
285
+ *
286
+ * Intended to be called when your application shuts down
287
+ */
288
+ dispose(): void;
289
+ }
290
+ //#endregion
291
+ export { ConfigDirectorLogger as a, ConfigValueType as c, ConfigDirectorLogMessageDecorator as i, ConfigDirectorClientOptions as n, ConfigDirectorLoggingLevel as o, ConfigDirectorContext as r, ConfigDirectorMetaContext as s, ConfigDirectorClient as t };
292
+ //# sourceMappingURL=types-CcUNxeqN.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CcUNxeqN.d.cts","names":[],"sources":["../../shared/src/types.ts","../src/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OAAA,GAAU,IAAA,EAAM,YAAA,CAAa,CAAA;EAE5E,GAAA,iBAAoB,YAAA,EAAc,SAAA,EAAW,CAAA,EAAG,OAAA,IAAW,IAAA,EAAM,YAAA,CAAa,CAAA;EAtEhE;;;;;;EA8Ed,OAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configdirector/server-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Javascript server SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
5
5
  "license": "MIT",
6
6
  "author": "ConfigDirector",
@@ -30,10 +30,27 @@
30
30
  "types": "./dist/configdirector-server.d.mts",
31
31
  "default": "./dist/configdirector-server.mjs"
32
32
  }
33
+ },
34
+ "./testing": {
35
+ "require": {
36
+ "types": "./dist/configdirector-server-testing.d.cts",
37
+ "default": "./dist/configdirector-server-testing.cjs"
38
+ },
39
+ "default": {
40
+ "types": "./dist/configdirector-server-testing.d.mts",
41
+ "default": "./dist/configdirector-server-testing.mjs"
42
+ }
43
+ }
44
+ },
45
+ "typesVersions": {
46
+ "*": {
47
+ "testing": [
48
+ "./dist/configdirector-server-testing.d.mts"
49
+ ]
33
50
  }
34
51
  },
35
52
  "files": [
36
- "dist/*server.*"
53
+ "dist"
37
54
  ],
38
55
  "types": "dist/configdirector-server.d.mts",
39
56
  "module": "dist/configdirector-server.mjs",
@@ -73,7 +90,6 @@
73
90
  "vitest": "^4.1.8"
74
91
  },
75
92
  "dependencies": {
76
- "@jsonjoy.com/json-pointer": "^18.1.0",
77
93
  "luxon": ">=1.28.0 <4.0.0",
78
94
  "rapidhash-js": "^3.0.0",
79
95
  "semver": "^7.7.4"