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