@configdirector/react-native-sdk 1.5.1 → 1.6.1
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 +43 -0
- package/dist/configdirector-react-native-testing.d.mts +157 -0
- package/dist/configdirector-react-native-testing.mjs +398 -0
- package/dist/configdirector-react-native.d.mts +48 -294
- package/dist/configdirector-react-native.mjs +221 -1338
- package/dist/installedTestClient-CTPtIG6o.mjs +1341 -0
- package/dist/types-fcPMBgiX.d.mts +295 -0
- package/package.json +14 -1
|
@@ -1,296 +1,7 @@
|
|
|
1
|
+
import { a as ConfigDirectorLogMessageDecorator, c as ConfigValueType, i as ConfigDirectorContext, l as ConnectionMode, n as ConfigDirectorClient, o as ConfigDirectorLogger, r as ConfigDirectorClientOptions, s as ConfigDirectorLoggingLevel, t as ClientHooks } from "./types-fcPMBgiX.mjs";
|
|
1
2
|
import { Component, PropsWithChildren } from "react";
|
|
2
3
|
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
4
|
|
|
4
|
-
//#region ../js-client-core/src/Emitter.d.ts
|
|
5
|
-
type EventType = string | symbol;
|
|
6
|
-
type EventsRecord = Record<EventType, any>;
|
|
7
|
-
type Handler<TEventsRecord extends EventsRecord, TKey extends keyof TEventsRecord> = (payload: TEventsRecord[TKey]) => void;
|
|
8
|
-
interface EventProvider<TEventsRecord extends EventsRecord> {
|
|
9
|
-
on<TName extends keyof TEventsRecord>(name: TName, handler: Handler<TEventsRecord, TName>): void;
|
|
10
|
-
off<TName extends keyof TEventsRecord>(name: TName, handler?: Handler<TEventsRecord, TName>): void;
|
|
11
|
-
clear(): void;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region ../shared/src/types.d.ts
|
|
15
|
-
type ConfigEnumLikeType = {
|
|
16
|
-
[key: string]: string | number;
|
|
17
|
-
};
|
|
18
|
-
type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
|
|
19
|
-
type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
|
|
20
|
-
interface ConfigDirectorLogger {
|
|
21
|
-
debug(message: string, ...args: any): void;
|
|
22
|
-
info(message: string, ...args: any): void;
|
|
23
|
-
warn(message: string, ...args: any): void;
|
|
24
|
-
error(message: string, ...args: any): void;
|
|
25
|
-
}
|
|
26
|
-
interface ConfigDirectorLogMessageDecorator {
|
|
27
|
-
decorateMessage(message: string): string;
|
|
28
|
-
}
|
|
29
|
-
type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean";
|
|
30
|
-
type ConfigEvaluation = {
|
|
31
|
-
key: string;
|
|
32
|
-
value: ConfigValueType;
|
|
33
|
-
valueId?: string;
|
|
34
|
-
isDefaultValue: boolean;
|
|
35
|
-
reason: EvaluationReason;
|
|
36
|
-
context?: ConfigDirectorContext;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* The user's context to be sent to ConfigDirector. This context will be used for targeting
|
|
40
|
-
* rules evaluation.
|
|
41
|
-
*/
|
|
42
|
-
type ConfigDirectorContext = {
|
|
43
|
-
/**
|
|
44
|
-
* The user's identifier. This should be a value that uniquely identifies an application
|
|
45
|
-
* user.
|
|
46
|
-
* In the case of anonymous users, you could generate a UUID or alternatively not provide
|
|
47
|
-
* the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
|
|
48
|
-
* value is used for segmenting users in percentage rollouts, and changes to the {@link id}
|
|
49
|
-
* could result in the user being assigned to a different percentile.
|
|
50
|
-
*/
|
|
51
|
-
id?: string;
|
|
52
|
-
/**
|
|
53
|
-
* The user's display name. This will be shown in the ConfigDirector dashboard and may be
|
|
54
|
-
* used for targeting rules.
|
|
55
|
-
*/
|
|
56
|
-
name?: string;
|
|
57
|
-
/**
|
|
58
|
-
* Any arbitrary traits for the current user. They will be shown in the ConfigDirector
|
|
59
|
-
* dashboard and may be used for targeting rules.
|
|
60
|
-
*/
|
|
61
|
-
traits?: {
|
|
62
|
-
[key: string]: unknown;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Whether or not to treat the context as anonymous during evaluation. When `true`, the
|
|
66
|
-
* context values will be used for targeting rules evaluation but the context will not be
|
|
67
|
-
* persisted and will not appear in the dashboard.
|
|
68
|
-
*
|
|
69
|
-
* @default false
|
|
70
|
-
*/
|
|
71
|
-
anonymous?: boolean;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Metadata about your application. It is recommended you include these values when configuring
|
|
75
|
-
* a ConfigDirector client so that you can use them in targeting rules.
|
|
76
|
-
*/
|
|
77
|
-
type ConfigDirectorMetaContext = {
|
|
78
|
-
appVersion?: string;
|
|
79
|
-
appName?: string;
|
|
80
|
-
};
|
|
81
|
-
type ConnectionMode = "streaming" | "polling";
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region ../js-client-core/src/types.d.ts
|
|
84
|
-
/**
|
|
85
|
-
* Configuration options for the {@link ConfigDirectorClient}
|
|
86
|
-
*/
|
|
87
|
-
type ConfigDirectorClientOptions = {
|
|
88
|
-
/**
|
|
89
|
-
* Application metadata that remains constant through the lifetime of the connection
|
|
90
|
-
*/
|
|
91
|
-
metadata?: ConfigDirectorMetaContext;
|
|
92
|
-
/**
|
|
93
|
-
* Connection options
|
|
94
|
-
*/
|
|
95
|
-
connection?: {
|
|
96
|
-
/**
|
|
97
|
-
* The connection mode to be used, one of `streaming` (default) or `polling`.
|
|
98
|
-
* If set to `streaming`, the connection will remain open and receive updates whenever
|
|
99
|
-
* config state is updated on the ConfigDirector dashboard.
|
|
100
|
-
* When set to `polling`, there will be an initial request to retrieve config state during
|
|
101
|
-
* initialization, and additional requests on a `pollingInterval`.
|
|
102
|
-
*
|
|
103
|
-
* Defaults to `streaming`
|
|
104
|
-
*/
|
|
105
|
-
mode?: ConnectionMode;
|
|
106
|
-
/**
|
|
107
|
-
* The polling interval in _seconds_ when the `mode` is set to `polling`. This option has no
|
|
108
|
-
* effect when the `mode` is set to `streaming`.
|
|
109
|
-
*
|
|
110
|
-
* Defaults to 300 seconds (5 minutes). Values below the minimum of 60 seconds are raised
|
|
111
|
-
* to 60 seconds.
|
|
112
|
-
*/
|
|
113
|
-
pollingInterval?: number;
|
|
114
|
-
/**
|
|
115
|
-
* The timeout, in _milliseconds_, to be used in initialization and when updating the context.
|
|
116
|
-
* If streaming is enabled, the operation (initialization or context update) may still succeed
|
|
117
|
-
* after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
|
|
118
|
-
* If streaming is disabled, if the operation times out, it will not be retried.
|
|
119
|
-
*/
|
|
120
|
-
timeout?: number;
|
|
121
|
-
/**
|
|
122
|
-
* The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
|
|
123
|
-
* proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
|
|
124
|
-
* a proxy for the client SDK.
|
|
125
|
-
*/
|
|
126
|
-
url?: string;
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
|
|
130
|
-
* logger set to 'warn' level.
|
|
131
|
-
*
|
|
132
|
-
* The log level of the default logger can be adjusted by creating a default logger with the desired
|
|
133
|
-
* level and providing it in this property:
|
|
134
|
-
* @example
|
|
135
|
-
* import { createClient, createConsoleLogger } from "@configdirector/client-sdk";
|
|
136
|
-
* const client = createClient(
|
|
137
|
-
* "YOUR-SDK-KEY",
|
|
138
|
-
* { logger: createConsoleLogger("debug") },
|
|
139
|
-
* );
|
|
140
|
-
*/
|
|
141
|
-
logger?: ConfigDirectorLogger;
|
|
142
|
-
/**
|
|
143
|
-
* Handlers for hooks/events emitted by the client. Each hook accepts either a single event handler or
|
|
144
|
-
* an array of event handlers.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* import { createClient, createConsoleLogger } from "@configdirector/client-sdk";
|
|
148
|
-
* const client = createClient(
|
|
149
|
-
* "YOUR-SDK-KEY",
|
|
150
|
-
* {
|
|
151
|
-
* hooks: {
|
|
152
|
-
* configEvaluated: (event) => { console.log(event.evaluation); }
|
|
153
|
-
* },
|
|
154
|
-
* },
|
|
155
|
-
* );
|
|
156
|
-
*/
|
|
157
|
-
hooks?: ClientHooks;
|
|
158
|
-
};
|
|
159
|
-
type ClientHooks = {
|
|
160
|
-
clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
|
|
161
|
-
configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
|
|
162
|
-
contextUpdated?: HookHandler<"contextUpdated"> | HookHandler<"contextUpdated">[];
|
|
163
|
-
configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
|
|
164
|
-
connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
|
|
165
|
-
};
|
|
166
|
-
type ClientConnectAction = "initialization" | "context update" | "network resume";
|
|
167
|
-
type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
|
|
168
|
-
type ClientEvents = {
|
|
169
|
-
configsUpdated: {
|
|
170
|
-
keys: string[];
|
|
171
|
-
};
|
|
172
|
-
clientReady: {
|
|
173
|
-
action: ClientConnectAction;
|
|
174
|
-
};
|
|
175
|
-
contextUpdated: {
|
|
176
|
-
context: ConfigDirectorContext | undefined;
|
|
177
|
-
};
|
|
178
|
-
configEvaluated: {
|
|
179
|
-
evaluation: ConfigEvaluation;
|
|
180
|
-
};
|
|
181
|
-
connectionError: {
|
|
182
|
-
error: Error;
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
type WatchHandler<T extends ConfigValueType> = (message: T) => void;
|
|
186
|
-
/**
|
|
187
|
-
* The ConfigDirector SDK client object.
|
|
188
|
-
*
|
|
189
|
-
* Applications should create a single instance of `ConfigDirectorClient`, and call
|
|
190
|
-
* {@link initialize} during application initialization.
|
|
191
|
-
*
|
|
192
|
-
* After initialization, to update the user's context, so that targeting rules are evaluated
|
|
193
|
-
* with the updated context, call {@link updateContext}.
|
|
194
|
-
*/
|
|
195
|
-
interface ConfigDirectorClient extends EventProvider<ClientEvents> {
|
|
196
|
-
/**
|
|
197
|
-
* Initializes the connection to ConfigDirector to retrieve config evaluations. Until
|
|
198
|
-
* initialization is successful, all flags will return their default value provided to
|
|
199
|
-
* {@link watch} or {@link getValue}.
|
|
200
|
-
*
|
|
201
|
-
* If the connection fails or is interrupted with a transient error (network error,
|
|
202
|
-
* internal server error, etc) the client will continue to attempt to connect. However,
|
|
203
|
-
* if the connection fails with a persistent error, like an invalid SDK key, the client will
|
|
204
|
-
* not attempt to re-connect and an error will be logged to the console or the provided
|
|
205
|
-
* logger.
|
|
206
|
-
*
|
|
207
|
-
* @param context The current user's context to be used for evaluating targeting rules (optional).
|
|
208
|
-
*/
|
|
209
|
-
initialize(context?: ConfigDirectorContext): Promise<void>;
|
|
210
|
-
/**
|
|
211
|
-
* Updates the user's context and re-evaluates all config and flag values based on the new context.
|
|
212
|
-
*
|
|
213
|
-
* @param context The current user's context to be used for evaluating targeting rules (required).
|
|
214
|
-
*/
|
|
215
|
-
updateContext(context: ConfigDirectorContext): Promise<void>;
|
|
216
|
-
/**
|
|
217
|
-
* Returns the current context the client is configured with, or undefined if there is no context.
|
|
218
|
-
*
|
|
219
|
-
* Note that the value returned does not updated immediately after calling {@link updateContext}. Only
|
|
220
|
-
* once the underlying connection was successful or timed out, the current context is updated. This is
|
|
221
|
-
* because while the context update is in progress, configs are still evaluated on the previous context.
|
|
222
|
-
*
|
|
223
|
-
*/
|
|
224
|
-
get context(): ConfigDirectorContext | undefined;
|
|
225
|
-
/**
|
|
226
|
-
* Returns whether or not the client is ready after calling {@link initialize} or {@link updateContext}
|
|
227
|
-
*
|
|
228
|
-
* The definition of ready is that the connection to the server was successful, and config state
|
|
229
|
-
* was received.
|
|
230
|
-
*/
|
|
231
|
-
get isReady(): boolean;
|
|
232
|
-
/**
|
|
233
|
-
* Returns whether or not the client is currently initializing. Upon client creation, it is `false`.
|
|
234
|
-
* It is `true` after calling `initialize` and becomes `false` again once initialization is completed.
|
|
235
|
-
*/
|
|
236
|
-
get isInitializing(): boolean;
|
|
237
|
-
/**
|
|
238
|
-
* Evaluates a config and returns its value based on the current context and targeting rules
|
|
239
|
-
*
|
|
240
|
-
* @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
|
|
241
|
-
* @param configKey The config key to evaluate
|
|
242
|
-
* @param defaultValue The default value to be returned if the config state is unavailable. For
|
|
243
|
-
* example, if the client cannot connect to the server due to network conditions, or if getValue
|
|
244
|
-
* is called before initialization is done.
|
|
245
|
-
*/
|
|
246
|
-
getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
|
|
247
|
-
/**
|
|
248
|
-
* Watches for changes to a a config evaluation value. Whenever the config value changes, the
|
|
249
|
-
* provided callback function will be called with the new value. Changes can happen due to updates
|
|
250
|
-
* to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
|
|
251
|
-
*
|
|
252
|
-
* @returns An 'unwatch' function that can be called to remove the subscriber
|
|
253
|
-
*
|
|
254
|
-
* @param configKey The config key to watch
|
|
255
|
-
* @param defaultValue The default value to be referenced if the config state is unavailable
|
|
256
|
-
* @param callback The callback function to be called whenever the config value is updated
|
|
257
|
-
*/
|
|
258
|
-
watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>): () => void;
|
|
259
|
-
/**
|
|
260
|
-
* Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
|
|
261
|
-
* is provided.
|
|
262
|
-
*
|
|
263
|
-
* @param configKey The config key to remove subscribers from
|
|
264
|
-
* @param callback The subscriber to be removed. If not provided, all subscribers are removed for
|
|
265
|
-
* the given `configKey`.
|
|
266
|
-
*/
|
|
267
|
-
unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
|
|
268
|
-
/**
|
|
269
|
-
* Removes all subscribers from all config keys
|
|
270
|
-
*/
|
|
271
|
-
unwatchAll(): void;
|
|
272
|
-
/**
|
|
273
|
-
* Pauses the network connection without clearing event handlers, watch handlers, or config
|
|
274
|
-
* state. Intended for mobile environments where the OS may kill background connections (e.g.
|
|
275
|
-
* when the app is backgrounded on iOS/Android).
|
|
276
|
-
*
|
|
277
|
-
* Call {@link resumeNetwork} to re-establish the connection.
|
|
278
|
-
*/
|
|
279
|
-
pauseNetwork(): void;
|
|
280
|
-
/**
|
|
281
|
-
* Resumes a connection that was paused via {@link pauseNetwork}, using the last context that
|
|
282
|
-
* was provided to {@link initialize} or {@link updateContext}.
|
|
283
|
-
*/
|
|
284
|
-
resumeNetwork(): Promise<void>;
|
|
285
|
-
/**
|
|
286
|
-
* Disposes of the client. All connections are closed, and all event and config key subscribers
|
|
287
|
-
* are removed.
|
|
288
|
-
*
|
|
289
|
-
* Intended to be called when your application shuts down
|
|
290
|
-
*/
|
|
291
|
-
dispose(): void;
|
|
292
|
-
}
|
|
293
|
-
//#endregion
|
|
294
5
|
//#region ../shared/src/logger.d.ts
|
|
295
6
|
declare class DefaultConsoleLogger implements ConfigDirectorLogger {
|
|
296
7
|
private readonly level;
|
|
@@ -333,20 +44,63 @@ type ConfigDirectorProviderOptions = {
|
|
|
333
44
|
appVersion?: string;
|
|
334
45
|
url?: string;
|
|
335
46
|
timeout?: number;
|
|
47
|
+
/**
|
|
48
|
+
* The connection mode, one of `streaming` or `polling`. In `streaming` mode the connection stays
|
|
49
|
+
* open and receives config updates as they happen. In `polling` mode configs are fetched once during
|
|
50
|
+
* initialization and then again on every `pollingInterval`.
|
|
51
|
+
*
|
|
52
|
+
* Defaults to `streaming`.
|
|
53
|
+
*/
|
|
54
|
+
mode?: ConnectionMode;
|
|
55
|
+
/**
|
|
56
|
+
* The polling interval in seconds when `mode` is `polling`. Has no effect in `streaming` mode.
|
|
57
|
+
*
|
|
58
|
+
* Defaults to 60 seconds. A value below the minimum of 30 seconds is raised to 30 seconds and a
|
|
59
|
+
* warning is logged.
|
|
60
|
+
*/
|
|
61
|
+
pollingInterval?: number;
|
|
336
62
|
context?: ConfigDirectorContext;
|
|
337
63
|
logger?: ConfigDirectorLogger;
|
|
338
64
|
hooks?: ClientHooks;
|
|
339
65
|
netInfoSubscribe?: NetInfoSubscribe;
|
|
340
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Props of a `ConfigDirectorProvider` given an existing client instead of the options to build one,
|
|
69
|
+
* for example a test client's `client`.
|
|
70
|
+
*/
|
|
71
|
+
type ConfigDirectorProviderClientProps = {
|
|
72
|
+
/**
|
|
73
|
+
* The client to provide. The provider never disposes it. If the client is not ready and not
|
|
74
|
+
* initializing, the provider initializes it with `context`; if it is ready and `context` is given
|
|
75
|
+
* and differs from the client's context, the provider updates the context; otherwise it leaves the
|
|
76
|
+
* client as it is and reports ready as soon as the client is.
|
|
77
|
+
*/
|
|
78
|
+
client: ConfigDirectorClient;
|
|
79
|
+
context?: ConfigDirectorContext;
|
|
80
|
+
/**
|
|
81
|
+
* Event handlers registered on the client while the provider is mounted, and removed when it
|
|
82
|
+
* unmounts.
|
|
83
|
+
*/
|
|
84
|
+
hooks?: ClientHooks;
|
|
85
|
+
netInfoSubscribe?: NetInfoSubscribe;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Props of `ConfigDirectorProvider`: either the options to build a client from, or an existing client.
|
|
89
|
+
*/
|
|
90
|
+
type ConfigDirectorProviderProps = ConfigDirectorProviderOptions | ConfigDirectorProviderClientProps;
|
|
341
91
|
//#endregion
|
|
342
92
|
//#region src/provider.d.ts
|
|
343
|
-
declare class ConfigDirectorProvider extends Component<PropsWithChildren<
|
|
93
|
+
declare class ConfigDirectorProvider extends Component<PropsWithChildren<ConfigDirectorProviderProps>, ConfigDirectorProviderState> {
|
|
344
94
|
private appStateSubscription;
|
|
345
95
|
private netInfoUnsubscribe;
|
|
346
96
|
private wasOffline;
|
|
347
|
-
|
|
97
|
+
private readonly ownsClient;
|
|
98
|
+
private disposedOwnClient;
|
|
99
|
+
private handlers;
|
|
100
|
+
constructor(props: ConfigDirectorProviderProps);
|
|
348
101
|
componentDidMount(): Promise<void>;
|
|
349
|
-
|
|
102
|
+
private connect;
|
|
103
|
+
componentDidUpdate(prevProps: PropsWithChildren<ConfigDirectorProviderProps>): Promise<void>;
|
|
350
104
|
private handleAppStateChange;
|
|
351
105
|
private handleConnectivityChange;
|
|
352
106
|
private reconnect;
|
|
@@ -379,4 +133,4 @@ declare class ConfigDirectorReactContextError extends Error {
|
|
|
379
133
|
//#region src/logger.d.ts
|
|
380
134
|
declare const createConsoleLogger: (level?: ConfigDirectorLoggingLevel) => DefaultConsoleLogger;
|
|
381
135
|
//#endregion
|
|
382
|
-
export { type ClientStatus, type ConfigDirectorClient, type ConfigDirectorClientOptions, type ConfigDirectorContext, type ConfigDirectorLogger, type ConfigDirectorLoggingLevel, ConfigDirectorProvider, type ConfigDirectorProviderOptions, ConfigDirectorReactContextError, type NetInfoSubscribe, createClient, createConsoleLogger, useClient, useConfigValue, useContext };
|
|
136
|
+
export { type ClientStatus, type ConfigDirectorClient, type ConfigDirectorClientOptions, type ConfigDirectorContext, type ConfigDirectorLogger, type ConfigDirectorLoggingLevel, ConfigDirectorProvider, type ConfigDirectorProviderClientProps, type ConfigDirectorProviderOptions, type ConfigDirectorProviderProps, ConfigDirectorReactContextError, type ConnectionMode, type NetInfoSubscribe, createClient, createConsoleLogger, useClient, useConfigValue, useContext };
|