@configdirector/react-web-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.
@@ -0,0 +1,210 @@
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
+ type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean";
24
+ type ConfigEvaluation = {
25
+ key: string;
26
+ value: ConfigValueType;
27
+ valueId?: string;
28
+ isDefaultValue: boolean;
29
+ reason: EvaluationReason;
30
+ context?: ConfigDirectorContext;
31
+ };
32
+ /**
33
+ * The user's context to be sent to ConfigDirector. This context will be used for targeting
34
+ * rules evaluation.
35
+ */
36
+ type ConfigDirectorContext = {
37
+ /**
38
+ * The user's identifier. This should be a value that uniquely identifies an application
39
+ * user.
40
+ * In the case of anonymous users, you could generate a UUID or alternatively not provide
41
+ * the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
42
+ * value is used for segmenting users in percentage rollouts, and changes to the {@link id}
43
+ * could result in the user being assigned to a different percentile.
44
+ */
45
+ id?: string;
46
+ /**
47
+ * The user's display name. This will be shown in the ConfigDirector dashboard and may be
48
+ * used for targeting rules.
49
+ */
50
+ name?: string;
51
+ /**
52
+ * Any arbitrary traits for the current user. They will be shown in the ConfigDirector
53
+ * dashboard and may be used for targeting rules.
54
+ */
55
+ traits?: {
56
+ [key: string]: unknown;
57
+ };
58
+ /**
59
+ * Whether or not to treat the context as anonymous during evaluation. When `true`, the
60
+ * context values will be used for targeting rules evaluation but the context will not be
61
+ * persisted and will not appear in the dashboard.
62
+ *
63
+ * @default false
64
+ */
65
+ anonymous?: boolean;
66
+ };
67
+ type ConnectionMode = "streaming" | "polling";
68
+ //#endregion
69
+ //#region ../js-client-core/src/types.d.ts
70
+ type ClientHooks = {
71
+ clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
72
+ configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
73
+ contextUpdated?: HookHandler<"contextUpdated"> | HookHandler<"contextUpdated">[];
74
+ configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
75
+ connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
76
+ };
77
+ type ClientConnectAction = "initialization" | "context update" | "network resume";
78
+ type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
79
+ type ClientEvents = {
80
+ configsUpdated: {
81
+ keys: string[];
82
+ removedKeys: string[];
83
+ };
84
+ clientReady: {
85
+ action: ClientConnectAction;
86
+ };
87
+ contextUpdated: {
88
+ context: ConfigDirectorContext | undefined;
89
+ };
90
+ configEvaluated: {
91
+ evaluation: ConfigEvaluation;
92
+ };
93
+ connectionError: {
94
+ error: Error;
95
+ };
96
+ };
97
+ type WatchHandler<T extends ConfigValueType> = (message: T) => void;
98
+ /**
99
+ * The ConfigDirector SDK client object.
100
+ *
101
+ * Applications should create a single instance of `ConfigDirectorClient`, and call
102
+ * {@link initialize} during application initialization.
103
+ *
104
+ * After initialization, to update the user's context, so that targeting rules are evaluated
105
+ * with the updated context, call {@link updateContext}.
106
+ */
107
+ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
108
+ /**
109
+ * Initializes the connection to ConfigDirector to retrieve config evaluations. Until
110
+ * initialization is successful, all flags will return their default value provided to
111
+ * {@link watch} or {@link getValue}.
112
+ *
113
+ * If the connection fails or is interrupted with a transient error (network error,
114
+ * internal server error, etc) the client will continue to attempt to connect. However,
115
+ * if the connection fails with a persistent error, like an invalid SDK key, the client will
116
+ * not attempt to re-connect and an error will be logged to the console or the provided
117
+ * logger.
118
+ *
119
+ * @param context The current user's context to be used for evaluating targeting rules (optional).
120
+ */
121
+ initialize(context?: ConfigDirectorContext): Promise<void>;
122
+ /**
123
+ * Updates the user's context and re-evaluates all config and flag values based on the new context.
124
+ *
125
+ * @param context The current user's context to be used for evaluating targeting rules (required).
126
+ */
127
+ updateContext(context: ConfigDirectorContext): Promise<void>;
128
+ /**
129
+ * Returns the current context the client is configured with, or undefined if there is no context.
130
+ *
131
+ * Note that the value returned does not updated immediately after calling {@link updateContext}. Only
132
+ * once the underlying connection was successful or timed out, the current context is updated. This is
133
+ * because while the context update is in progress, configs are still evaluated on the previous context.
134
+ *
135
+ */
136
+ get context(): ConfigDirectorContext | undefined;
137
+ /**
138
+ * Returns whether or not the client is ready after calling {@link initialize} or {@link updateContext}
139
+ *
140
+ * The definition of ready is that the connection to the server was successful, and config state
141
+ * was received.
142
+ */
143
+ get isReady(): boolean;
144
+ /**
145
+ * Whether the client is trying to get its very first payload from the server. Upon client creation,
146
+ * it is `false`. It becomes `true` when `initialize` is called on a client that has never received a
147
+ * payload, stays `true` through timeouts and retries, and becomes `false` when the first payload
148
+ * arrives, when a fatal connection error stops the retries, or on `close`. `updateContext` and
149
+ * `resumeNetwork` never set it, and once a payload has been received it is never `true` again.
150
+ */
151
+ get isInitializing(): boolean;
152
+ /**
153
+ * Evaluates a config and returns its value based on the current context and targeting rules
154
+ *
155
+ * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
156
+ * @param configKey The config key to evaluate
157
+ * @param defaultValue The default value to be returned if the config state is unavailable. For
158
+ * example, if the client cannot connect to the server due to network conditions, or if getValue
159
+ * is called before initialization is done.
160
+ */
161
+ getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
162
+ /**
163
+ * Watches for changes to a a config evaluation value. Whenever the config value changes, the
164
+ * provided callback function will be called with the new value. Changes can happen due to updates
165
+ * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
166
+ *
167
+ * @returns An 'unwatch' function that can be called to remove the subscriber
168
+ *
169
+ * @param configKey The config key to watch
170
+ * @param defaultValue The default value to be referenced if the config state is unavailable
171
+ * @param callback The callback function to be called whenever the config value is updated
172
+ */
173
+ watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>): () => void;
174
+ /**
175
+ * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
176
+ * is provided.
177
+ *
178
+ * @param configKey The config key to remove subscribers from
179
+ * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
180
+ * the given `configKey`.
181
+ */
182
+ unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
183
+ /**
184
+ * Removes all subscribers from all config keys
185
+ */
186
+ unwatchAll(): void;
187
+ /**
188
+ * Pauses the network connection without clearing event handlers, watch handlers, or config
189
+ * state. Intended for mobile environments where the OS may kill background connections (e.g.
190
+ * when the app is backgrounded on iOS/Android).
191
+ *
192
+ * Call {@link resumeNetwork} to re-establish the connection.
193
+ */
194
+ pauseNetwork(): void;
195
+ /**
196
+ * Resumes a connection that was paused via {@link pauseNetwork}, using the last context that
197
+ * was provided to {@link initialize} or {@link updateContext}.
198
+ */
199
+ resumeNetwork(): Promise<void>;
200
+ /**
201
+ * Disposes of the client. All connections are closed, and all event and config key subscribers
202
+ * are removed.
203
+ *
204
+ * Intended to be called when your application shuts down
205
+ */
206
+ dispose(): void;
207
+ }
208
+ //#endregion
209
+ export { ConfigDirectorLoggingLevel as a, ConfigDirectorLogger as i, ConfigDirectorClient as n, ConfigValueType as o, ConfigDirectorContext as r, ConnectionMode as s, ClientHooks as t };
210
+ //# sourceMappingURL=types-CU9VmelO.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CU9VmelO.d.mts","names":[],"sources":["../../js-client-core/src/Emitter.ts","../../shared/src/types.ts","../../js-client-core/src/types.ts"],"mappings":";KAAK,SAAA;AAAA,KACA,YAAA,GAAe,MAAA,CAAO,SAAA;AAAA,KAEtB,OAAA,uBAA8B,YAAA,qBAAiC,aAAA,KAClE,OAAA,EAAS,aAAA,CAAc,IAAA;AAAA,UAGR,aAAA,uBAAoC,YAAA;EACnD,EAAA,qBAAuB,aAAA,EAAe,IAAA,EAAM,KAAA,EAAO,OAAA,EAAS,OAAA,CAAQ,aAAA,EAAe,KAAA;EACnF,GAAA,qBAAwB,aAAA,EAAe,IAAA,EAAM,KAAA,EAAO,OAAA,GAAU,OAAA,CAAQ,aAAA,EAAe,KAAA;EACrF,KAAA;AAAA;;;KCEU,kBAAA;EAAA,CAAwB,GAAA;AAAA;AAAA,KAExB,eAAA,wCAAuD,kBAAA;AAAA,KAevD,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,KAOhB,gBAAA;AAAA,KAUA,gBAAA;EACV,GAAA;EACA,KAAA,EAAO,eAAA;EACP,OAAA;EACA,cAAA;EACA,MAAA,EAAQ,gBAAA;EACR,OAAA,GAAU,qBAAA;AAAA;;;;;KAMA,qBAAA;ED1D2E;;;;;;;;ECmErF,EAAA;EDpE4C;;;;EC0E5C,IAAA;ED1EmD;;;;ECgFnD,MAAA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CAAa,CAAA;EAxFjE;;;;;;;;EAkG3B,OAAA,WAAkB,eAAA,EAAiB,SAAA,UAAmB,QAAA,GAAW,YAAA,CAAa,CAAA;EAnG/D;;;EAwGf,UAAA;EAvG2B;;;;;;;EAgH3B,YAAA;EA9G+B;AAGjC;;;EAiHE,aAAA,IAAiB,OAAA;EAjHM;;;;;;EAyHvB,OAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configdirector/react-web-sdk",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "description": "React web client SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
5
5
  "license": "MIT",
6
6
  "author": "ConfigDirector",
@@ -31,10 +31,27 @@
31
31
  "types": "./dist/configdirector-react-client.d.mts",
32
32
  "default": "./dist/configdirector-react-client.mjs"
33
33
  }
34
+ },
35
+ "./testing": {
36
+ "require": {
37
+ "types": "./dist/configdirector-react-client-testing.d.cts",
38
+ "default": "./dist/configdirector-react-client-testing.cjs"
39
+ },
40
+ "default": {
41
+ "types": "./dist/configdirector-react-client-testing.d.mts",
42
+ "default": "./dist/configdirector-react-client-testing.mjs"
43
+ }
44
+ }
45
+ },
46
+ "typesVersions": {
47
+ "*": {
48
+ "testing": [
49
+ "./dist/configdirector-react-client-testing.d.mts"
50
+ ]
34
51
  }
35
52
  },
36
53
  "files": [
37
- "dist/*client.*"
54
+ "dist"
38
55
  ],
39
56
  "types": "dist/configdirector-react-client.d.mts",
40
57
  "browser": "dist/configdirector-react-client.mjs",