@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.
@@ -1,209 +1,7 @@
1
+ import { a as ConfigDirectorLoggingLevel, i as ConfigDirectorLogger, n as ConfigDirectorClient, o as ConfigValueType, r as ConfigDirectorContext, s as ConnectionMode, t as ClientHooks } from "./types-3Pw7bIUn.cjs";
1
2
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
2
3
  import { Component, PropsWithChildren, ReactNode } from "react";
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
- 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
- //#endregion
71
- //#region ../js-client-core/src/types.d.ts
72
- type ClientHooks = {
73
- clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
74
- configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
75
- contextUpdated?: HookHandler<"contextUpdated"> | HookHandler<"contextUpdated">[];
76
- configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
77
- connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
78
- };
79
- type ClientConnectAction = "initialization" | "context update" | "network resume";
80
- type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
81
- type ClientEvents = {
82
- configsUpdated: {
83
- keys: string[];
84
- };
85
- clientReady: {
86
- action: ClientConnectAction;
87
- };
88
- contextUpdated: {
89
- context: ConfigDirectorContext | undefined;
90
- };
91
- configEvaluated: {
92
- evaluation: ConfigEvaluation;
93
- };
94
- connectionError: {
95
- error: Error;
96
- };
97
- };
98
- type WatchHandler<T extends ConfigValueType> = (message: T) => void;
99
- /**
100
- * The ConfigDirector SDK client object.
101
- *
102
- * Applications should create a single instance of `ConfigDirectorClient`, and call
103
- * {@link initialize} during application initialization.
104
- *
105
- * After initialization, to update the user's context, so that targeting rules are evaluated
106
- * with the updated context, call {@link updateContext}.
107
- */
108
- interface ConfigDirectorClient extends EventProvider<ClientEvents> {
109
- /**
110
- * Initializes the connection to ConfigDirector to retrieve config evaluations. Until
111
- * initialization is successful, all flags will return their default value provided to
112
- * {@link watch} or {@link getValue}.
113
- *
114
- * If the connection fails or is interrupted with a transient error (network error,
115
- * internal server error, etc) the client will continue to attempt to connect. However,
116
- * if the connection fails with a persistent error, like an invalid SDK key, the client will
117
- * not attempt to re-connect and an error will be logged to the console or the provided
118
- * logger.
119
- *
120
- * @param context The current user's context to be used for evaluating targeting rules (optional).
121
- */
122
- initialize(context?: ConfigDirectorContext): Promise<void>;
123
- /**
124
- * Updates the user's context and re-evaluates all config and flag values based on the new context.
125
- *
126
- * @param context The current user's context to be used for evaluating targeting rules (required).
127
- */
128
- updateContext(context: ConfigDirectorContext): Promise<void>;
129
- /**
130
- * Returns the current context the client is configured with, or undefined if there is no context.
131
- *
132
- * Note that the value returned does not updated immediately after calling {@link updateContext}. Only
133
- * once the underlying connection was successful or timed out, the current context is updated. This is
134
- * because while the context update is in progress, configs are still evaluated on the previous context.
135
- *
136
- */
137
- get context(): ConfigDirectorContext | undefined;
138
- /**
139
- * Returns whether or not the client is ready after calling {@link initialize} or {@link updateContext}
140
- *
141
- * The definition of ready is that the connection to the server was successful, and config state
142
- * was received.
143
- */
144
- get isReady(): boolean;
145
- /**
146
- * Returns whether or not the client is currently initializing. Upon client creation, it is `false`.
147
- * It is `true` after calling `initialize` and becomes `false` again once initialization is completed.
148
- */
149
- get isInitializing(): boolean;
150
- /**
151
- * Evaluates a config and returns its value based on the current context and targeting rules
152
- *
153
- * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
154
- * @param configKey The config key to evaluate
155
- * @param defaultValue The default value to be returned if the config state is unavailable. For
156
- * example, if the client cannot connect to the server due to network conditions, or if getValue
157
- * is called before initialization is done.
158
- */
159
- getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
160
- /**
161
- * Watches for changes to a a config evaluation value. Whenever the config value changes, the
162
- * provided callback function will be called with the new value. Changes can happen due to updates
163
- * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
164
- *
165
- * @returns An 'unwatch' function that can be called to remove the subscriber
166
- *
167
- * @param configKey The config key to watch
168
- * @param defaultValue The default value to be referenced if the config state is unavailable
169
- * @param callback The callback function to be called whenever the config value is updated
170
- */
171
- watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>): () => void;
172
- /**
173
- * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
174
- * is provided.
175
- *
176
- * @param configKey The config key to remove subscribers from
177
- * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
178
- * the given `configKey`.
179
- */
180
- unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
181
- /**
182
- * Removes all subscribers from all config keys
183
- */
184
- unwatchAll(): void;
185
- /**
186
- * Pauses the network connection without clearing event handlers, watch handlers, or config
187
- * state. Intended for mobile environments where the OS may kill background connections (e.g.
188
- * when the app is backgrounded on iOS/Android).
189
- *
190
- * Call {@link resumeNetwork} to re-establish the connection.
191
- */
192
- pauseNetwork(): void;
193
- /**
194
- * Resumes a connection that was paused via {@link pauseNetwork}, using the last context that
195
- * was provided to {@link initialize} or {@link updateContext}.
196
- */
197
- resumeNetwork(): Promise<void>;
198
- /**
199
- * Disposes of the client. All connections are closed, and all event and config key subscribers
200
- * are removed.
201
- *
202
- * Intended to be called when your application shuts down
203
- */
204
- dispose(): void;
205
- }
206
- //#endregion
207
5
  //#region src/types.d.ts
208
6
  type ClientStatus = "loading" | "ready" | "default";
209
7
  interface ConfigDirectorContextData {
@@ -218,10 +16,48 @@ type ConfigDirectorProviderOptions = {
218
16
  appVersion?: string;
219
17
  url?: string;
220
18
  timeout?: number;
19
+ /**
20
+ * The connection mode, one of `streaming` or `polling`. In `streaming` mode the connection stays
21
+ * open and receives config updates as they happen. In `polling` mode configs are fetched once during
22
+ * initialization and then again on every `pollingInterval`.
23
+ *
24
+ * Defaults to `streaming`.
25
+ */
26
+ mode?: ConnectionMode;
27
+ /**
28
+ * The polling interval in seconds when `mode` is `polling`. Has no effect in `streaming` mode.
29
+ *
30
+ * Defaults to 60 seconds. A value below the minimum of 30 seconds is raised to 30 seconds and a
31
+ * warning is logged.
32
+ */
33
+ pollingInterval?: number;
221
34
  context?: ConfigDirectorContext;
222
35
  logger?: ConfigDirectorLogger;
223
36
  hooks?: ClientHooks;
224
37
  };
38
+ /**
39
+ * Props of a `ConfigDirectorProvider` given an existing client instead of the options to build one,
40
+ * for example a test client's `client`.
41
+ */
42
+ type ConfigDirectorProviderClientProps = {
43
+ /**
44
+ * The client to provide. The provider never disposes it. If the client is not ready and not
45
+ * initializing, the provider initializes it with `context`; if it is ready and `context` is given
46
+ * and differs from the client's context, the provider updates the context; otherwise it leaves the
47
+ * client as it is and reports ready as soon as the client is.
48
+ */
49
+ client: ConfigDirectorClient;
50
+ context?: ConfigDirectorContext;
51
+ /**
52
+ * Event handlers registered on the client while the provider is mounted, and removed when it
53
+ * unmounts.
54
+ */
55
+ hooks?: ClientHooks;
56
+ };
57
+ /**
58
+ * Props of `ConfigDirectorProvider`: either the options to build a client from, or an existing client.
59
+ */
60
+ type ConfigDirectorProviderProps = ConfigDirectorProviderOptions | ConfigDirectorProviderClientProps;
225
61
  //#endregion
226
62
  //#region src/withProvider.d.ts
227
63
  declare const withProvider: (options: ConfigDirectorProviderOptions) => Promise<({
@@ -231,10 +67,14 @@ declare const withProvider: (options: ConfigDirectorProviderOptions) => Promise<
231
67
  }) => _$react_jsx_runtime0.JSX.Element>;
232
68
  //#endregion
233
69
  //#region src/provider.d.ts
234
- declare class ConfigDirectorProvider extends Component<PropsWithChildren<ConfigDirectorProviderOptions>, ConfigDirectorProviderState> {
235
- constructor(props: ConfigDirectorProviderOptions);
70
+ declare class ConfigDirectorProvider extends Component<PropsWithChildren<ConfigDirectorProviderProps>, ConfigDirectorProviderState> {
71
+ private readonly ownsClient;
72
+ private disposedOwnClient;
73
+ private handlers;
74
+ constructor(props: ConfigDirectorProviderProps);
236
75
  componentDidMount(): Promise<void>;
237
- componentDidUpdate(prevProps: PropsWithChildren<ConfigDirectorProviderOptions>): Promise<void>;
76
+ private connect;
77
+ componentDidUpdate(prevProps: PropsWithChildren<ConfigDirectorProviderProps>): Promise<void>;
238
78
  componentWillUnmount(): void;
239
79
  render(): _$react_jsx_runtime0.JSX.Element;
240
80
  }
@@ -255,5 +95,5 @@ declare const useClient: () => {
255
95
  //#region src/logger.d.ts
256
96
  declare const createConsoleLogger: (level: ConfigDirectorLoggingLevel) => ConfigDirectorLogger;
257
97
  //#endregion
258
- export { ConfigDirectorProvider, createConsoleLogger, useClient, useConfigValue, useContext, withProvider };
98
+ export { type ClientStatus, type ConfigDirectorClient, type ConfigDirectorContext, ConfigDirectorProvider, type ConfigDirectorProviderClientProps, type ConfigDirectorProviderOptions, type ConfigDirectorProviderProps, type ConnectionMode, createConsoleLogger, useClient, useConfigValue, useContext, withProvider };
259
99
  //# sourceMappingURL=configdirector-react-client.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configdirector-react-client.d.cts","names":[],"sources":["../../js-client-core/src/Emitter.ts","../../shared/src/types.ts","../../js-client-core/src/types.ts","../src/types.ts","../src/withProvider.tsx","../src/provider.tsx","../src/hooks.tsx","../src/logger.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,CAA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B,QAAA,EAAU,SAAA;AAAA,MAAW,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cCV1D,sBAAA,SAA+B,SAAA,CAC1C,iBAAA,CAAkB,6BAAA,GAClB,2BAAA;cAEY,KAAA,EAAO,6BAAA;EAaJ,iBAAA,CAAA,GAAqB,OAAA;EAarB,kBAAA,CACb,SAAA,EAAW,iBAAA,CAAkB,6BAAA,IAC5B,OAAA;EAUM,oBAAA,CAAA;EAIA,MAAA,CAAA,GAAM,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA;;;cCrCX,cAAA,aAA4B,eAAA,EAChC,GAAA,UACA,YAAA,EAAc,CAAA;EAEd,KAAA,EAAO,CAAA;EACP,WAAA,EAAa,YAAA;EACb,OAAA;AAAA;AAAA,cAYI,UAAA;2BAMkC,qBAAA,KAAqB,OAAA;AAAA;AAAA,cAOvD,SAAA;UAOL,oBAAA;AAAA;;;cCvCY,mBAAA,GAAuB,KAAA,EAAO,0BAAA,KAA6B,oBAAA"}
1
+ {"version":3,"file":"configdirector-react-client.d.cts","names":[],"sources":["../src/types.ts","../src/withProvider.tsx","../src/provider.tsx","../src/hooks.tsx","../src/logger.ts"],"mappings":";;;;;KAQY,YAAA;AAAA,UAEK,yBAAA;EACf,MAAA,GAAS,oBAAA;EACT,SAAA,GAAY,IAAA;EACZ,MAAA,EAAQ,YAAA;AAAA;AAAA,KAGE,2BAAA,GAA8B,yBAAA;AAAA,KAE9B,6BAAA;EACV,MAAA;EACA,OAAA;EACA,UAAA;EACA,GAAA;EACA,OAAA;EAXY;;;;;;;EAmBZ,IAAA,GAAO,cAAA;EAlBP;;;;AAGF;;EAsBE,eAAA;EACA,OAAA,GAAU,qBAAA;EACV,MAAA,GAAS,oBAAA;EACT,KAAA,GAAQ,WAAA;AAAA;;;;;KAOE,iCAAA;EAPS;;;;;;EAcnB,MAAA,EAAQ,oBAAA;EACR,OAAA,GAAU,qBAAA;EAzBH;;;;EA8BP,KAAA,GAAQ,WAAA;AAAA;;;;KAME,2BAAA,GAA8B,6BAAA,GAAgC,iCAAA;;;cC1D7D,YAAA,GAAsB,OAAA,EAAS,6BAAA,KAA6B,OAAA;EAAA;AAAA;EAcvB,QAAA,EAAU,SAAA;AAAA,MAAW,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cCb1D,sBAAA,SAA+B,SAAA,CAC1C,iBAAA,CAAkB,2BAAA,GAClB,2BAAA;EAAA,iBAEiB,UAAA;EAAA,QACT,iBAAA;EAAA,QACA,QAAA;cAEI,KAAA,EAAO,2BAAA;EAOJ,iBAAA,CAAA,GAAqB,OAAA;EAAA,QAoBtB,OAAA;EAiBC,kBAAA,CAAmB,SAAA,EAAW,iBAAA,CAAkB,2BAAA,IAA+B,OAAA;EAerF,oBAAA,CAAA;EASA,MAAA,CAAA,GAAM,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA;;;cCvEX,cAAA,aAA4B,eAAA,EAChC,GAAA,UACA,YAAA,EAAc,CAAA;EAEd,KAAA,EAAO,CAAA;EACP,WAAA,EAAa,YAAA;EACb,OAAA;AAAA;AAAA,cAYI,UAAA;2BAMkC,qBAAA,KAAqB,OAAA;AAAA;AAAA,cAOvD,SAAA;UAOL,oBAAA;AAAA;;;cCvCY,mBAAA,GAAuB,KAAA,EAAO,0BAAA,KAA6B,oBAAA"}
@@ -1,209 +1,7 @@
1
+ import { a as ConfigDirectorLoggingLevel, i as ConfigDirectorLogger, n as ConfigDirectorClient, o as ConfigValueType, r as ConfigDirectorContext, s as ConnectionMode, t as ClientHooks } from "./types-CU9VmelO.mjs";
1
2
  import { Component, PropsWithChildren, ReactNode } 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
- 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
- //#endregion
71
- //#region ../js-client-core/src/types.d.ts
72
- type ClientHooks = {
73
- clientReady?: HookHandler<"clientReady"> | HookHandler<"clientReady">[];
74
- configsUpdated?: HookHandler<"configsUpdated"> | HookHandler<"configsUpdated">[];
75
- contextUpdated?: HookHandler<"contextUpdated"> | HookHandler<"contextUpdated">[];
76
- configEvaluated?: HookHandler<"configEvaluated"> | HookHandler<"configEvaluated">[];
77
- connectionError?: HookHandler<"connectionError"> | HookHandler<"connectionError">[];
78
- };
79
- type ClientConnectAction = "initialization" | "context update" | "network resume";
80
- type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEvent]) => void;
81
- type ClientEvents = {
82
- configsUpdated: {
83
- keys: string[];
84
- };
85
- clientReady: {
86
- action: ClientConnectAction;
87
- };
88
- contextUpdated: {
89
- context: ConfigDirectorContext | undefined;
90
- };
91
- configEvaluated: {
92
- evaluation: ConfigEvaluation;
93
- };
94
- connectionError: {
95
- error: Error;
96
- };
97
- };
98
- type WatchHandler<T extends ConfigValueType> = (message: T) => void;
99
- /**
100
- * The ConfigDirector SDK client object.
101
- *
102
- * Applications should create a single instance of `ConfigDirectorClient`, and call
103
- * {@link initialize} during application initialization.
104
- *
105
- * After initialization, to update the user's context, so that targeting rules are evaluated
106
- * with the updated context, call {@link updateContext}.
107
- */
108
- interface ConfigDirectorClient extends EventProvider<ClientEvents> {
109
- /**
110
- * Initializes the connection to ConfigDirector to retrieve config evaluations. Until
111
- * initialization is successful, all flags will return their default value provided to
112
- * {@link watch} or {@link getValue}.
113
- *
114
- * If the connection fails or is interrupted with a transient error (network error,
115
- * internal server error, etc) the client will continue to attempt to connect. However,
116
- * if the connection fails with a persistent error, like an invalid SDK key, the client will
117
- * not attempt to re-connect and an error will be logged to the console or the provided
118
- * logger.
119
- *
120
- * @param context The current user's context to be used for evaluating targeting rules (optional).
121
- */
122
- initialize(context?: ConfigDirectorContext): Promise<void>;
123
- /**
124
- * Updates the user's context and re-evaluates all config and flag values based on the new context.
125
- *
126
- * @param context The current user's context to be used for evaluating targeting rules (required).
127
- */
128
- updateContext(context: ConfigDirectorContext): Promise<void>;
129
- /**
130
- * Returns the current context the client is configured with, or undefined if there is no context.
131
- *
132
- * Note that the value returned does not updated immediately after calling {@link updateContext}. Only
133
- * once the underlying connection was successful or timed out, the current context is updated. This is
134
- * because while the context update is in progress, configs are still evaluated on the previous context.
135
- *
136
- */
137
- get context(): ConfigDirectorContext | undefined;
138
- /**
139
- * Returns whether or not the client is ready after calling {@link initialize} or {@link updateContext}
140
- *
141
- * The definition of ready is that the connection to the server was successful, and config state
142
- * was received.
143
- */
144
- get isReady(): boolean;
145
- /**
146
- * Returns whether or not the client is currently initializing. Upon client creation, it is `false`.
147
- * It is `true` after calling `initialize` and becomes `false` again once initialization is completed.
148
- */
149
- get isInitializing(): boolean;
150
- /**
151
- * Evaluates a config and returns its value based on the current context and targeting rules
152
- *
153
- * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
154
- * @param configKey The config key to evaluate
155
- * @param defaultValue The default value to be returned if the config state is unavailable. For
156
- * example, if the client cannot connect to the server due to network conditions, or if getValue
157
- * is called before initialization is done.
158
- */
159
- getValue<T extends ConfigValueType>(configKey: string, defaultValue: T): T;
160
- /**
161
- * Watches for changes to a a config evaluation value. Whenever the config value changes, the
162
- * provided callback function will be called with the new value. Changes can happen due to updates
163
- * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
164
- *
165
- * @returns An 'unwatch' function that can be called to remove the subscriber
166
- *
167
- * @param configKey The config key to watch
168
- * @param defaultValue The default value to be referenced if the config state is unavailable
169
- * @param callback The callback function to be called whenever the config value is updated
170
- */
171
- watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>): () => void;
172
- /**
173
- * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
174
- * is provided.
175
- *
176
- * @param configKey The config key to remove subscribers from
177
- * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
178
- * the given `configKey`.
179
- */
180
- unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
181
- /**
182
- * Removes all subscribers from all config keys
183
- */
184
- unwatchAll(): void;
185
- /**
186
- * Pauses the network connection without clearing event handlers, watch handlers, or config
187
- * state. Intended for mobile environments where the OS may kill background connections (e.g.
188
- * when the app is backgrounded on iOS/Android).
189
- *
190
- * Call {@link resumeNetwork} to re-establish the connection.
191
- */
192
- pauseNetwork(): void;
193
- /**
194
- * Resumes a connection that was paused via {@link pauseNetwork}, using the last context that
195
- * was provided to {@link initialize} or {@link updateContext}.
196
- */
197
- resumeNetwork(): Promise<void>;
198
- /**
199
- * Disposes of the client. All connections are closed, and all event and config key subscribers
200
- * are removed.
201
- *
202
- * Intended to be called when your application shuts down
203
- */
204
- dispose(): void;
205
- }
206
- //#endregion
207
5
  //#region src/types.d.ts
208
6
  type ClientStatus = "loading" | "ready" | "default";
209
7
  interface ConfigDirectorContextData {
@@ -218,10 +16,48 @@ type ConfigDirectorProviderOptions = {
218
16
  appVersion?: string;
219
17
  url?: string;
220
18
  timeout?: number;
19
+ /**
20
+ * The connection mode, one of `streaming` or `polling`. In `streaming` mode the connection stays
21
+ * open and receives config updates as they happen. In `polling` mode configs are fetched once during
22
+ * initialization and then again on every `pollingInterval`.
23
+ *
24
+ * Defaults to `streaming`.
25
+ */
26
+ mode?: ConnectionMode;
27
+ /**
28
+ * The polling interval in seconds when `mode` is `polling`. Has no effect in `streaming` mode.
29
+ *
30
+ * Defaults to 60 seconds. A value below the minimum of 30 seconds is raised to 30 seconds and a
31
+ * warning is logged.
32
+ */
33
+ pollingInterval?: number;
221
34
  context?: ConfigDirectorContext;
222
35
  logger?: ConfigDirectorLogger;
223
36
  hooks?: ClientHooks;
224
37
  };
38
+ /**
39
+ * Props of a `ConfigDirectorProvider` given an existing client instead of the options to build one,
40
+ * for example a test client's `client`.
41
+ */
42
+ type ConfigDirectorProviderClientProps = {
43
+ /**
44
+ * The client to provide. The provider never disposes it. If the client is not ready and not
45
+ * initializing, the provider initializes it with `context`; if it is ready and `context` is given
46
+ * and differs from the client's context, the provider updates the context; otherwise it leaves the
47
+ * client as it is and reports ready as soon as the client is.
48
+ */
49
+ client: ConfigDirectorClient;
50
+ context?: ConfigDirectorContext;
51
+ /**
52
+ * Event handlers registered on the client while the provider is mounted, and removed when it
53
+ * unmounts.
54
+ */
55
+ hooks?: ClientHooks;
56
+ };
57
+ /**
58
+ * Props of `ConfigDirectorProvider`: either the options to build a client from, or an existing client.
59
+ */
60
+ type ConfigDirectorProviderProps = ConfigDirectorProviderOptions | ConfigDirectorProviderClientProps;
225
61
  //#endregion
226
62
  //#region src/withProvider.d.ts
227
63
  declare const withProvider: (options: ConfigDirectorProviderOptions) => Promise<({
@@ -231,10 +67,14 @@ declare const withProvider: (options: ConfigDirectorProviderOptions) => Promise<
231
67
  }) => _$react_jsx_runtime0.JSX.Element>;
232
68
  //#endregion
233
69
  //#region src/provider.d.ts
234
- declare class ConfigDirectorProvider extends Component<PropsWithChildren<ConfigDirectorProviderOptions>, ConfigDirectorProviderState> {
235
- constructor(props: ConfigDirectorProviderOptions);
70
+ declare class ConfigDirectorProvider extends Component<PropsWithChildren<ConfigDirectorProviderProps>, ConfigDirectorProviderState> {
71
+ private readonly ownsClient;
72
+ private disposedOwnClient;
73
+ private handlers;
74
+ constructor(props: ConfigDirectorProviderProps);
236
75
  componentDidMount(): Promise<void>;
237
- componentDidUpdate(prevProps: PropsWithChildren<ConfigDirectorProviderOptions>): Promise<void>;
76
+ private connect;
77
+ componentDidUpdate(prevProps: PropsWithChildren<ConfigDirectorProviderProps>): Promise<void>;
238
78
  componentWillUnmount(): void;
239
79
  render(): _$react_jsx_runtime0.JSX.Element;
240
80
  }
@@ -255,5 +95,5 @@ declare const useClient: () => {
255
95
  //#region src/logger.d.ts
256
96
  declare const createConsoleLogger: (level: ConfigDirectorLoggingLevel) => ConfigDirectorLogger;
257
97
  //#endregion
258
- export { ConfigDirectorProvider, createConsoleLogger, useClient, useConfigValue, useContext, withProvider };
98
+ export { type ClientStatus, type ConfigDirectorClient, type ConfigDirectorContext, ConfigDirectorProvider, type ConfigDirectorProviderClientProps, type ConfigDirectorProviderOptions, type ConfigDirectorProviderProps, type ConnectionMode, createConsoleLogger, useClient, useConfigValue, useContext, withProvider };
259
99
  //# sourceMappingURL=configdirector-react-client.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configdirector-react-client.d.mts","names":[],"sources":["../../js-client-core/src/Emitter.ts","../../shared/src/types.ts","../../js-client-core/src/types.ts","../src/types.ts","../src/withProvider.tsx","../src/provider.tsx","../src/hooks.tsx","../src/logger.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,OA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A;UAOL,oBAAA;AAAA;;;cCvCY,mBAAA,GAAuB,KAAA,EAAO,0BAAA,KAA6B,oBAAA"}
1
+ {"version":3,"file":"configdirector-react-client.d.mts","names":[],"sources":["../src/types.ts","../src/withProvider.tsx","../src/provider.tsx","../src/hooks.tsx","../src/logger.ts"],"mappings":";;;;;KAQY,YAAA;AAAA,UAEK,yBAAA;EACf,MAAA,GAAS,oBAAA;EACT,SAAA,GAAY,IAAA;EACZ,MAAA,EAAQ,YAAA;AAAA;AAAA,KAGE,2BAAA,GAA8B,yBAAA;AAAA,KAE9B,6BAAA;EACV,MAAA;EACA,OAAA;EACA,UAAA;EACA,GAAA;EACA,OAAA;EAXY;;;;;;;EAmBZ,IAAA,GAAO,cAAA;EAlBP;;;;AAGF;;EAsBE,eAAA;EACA,OAAA,GAAU,qBAAA;EACV,MAAA,GAAS,oBAAA;EACT,KAAA,GAAQ,WAAA;AAAA;;;;;KAOE,iCAAA;EAPS;;;;;;EAcnB,MAAA,EAAQ,oBAAA;EACR,OAAA,GAAU,qBAAA;EAzBH;;;;EA8BP,KAAA,GAAQ,WAAA;AAAA;;;;KAME,2BAAA,GAA8B,6BAAA,GAAgC,iCAAA;;;cC1D7D,YAAA,GAAsB,OAAA,EAAS,6BAAA,KAA6B,OAAA;EAAA;AAAA;EAcvB,QAAA,EAAU,SAAA;AAAA,MAAW,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cCb1D,sBAAA,SAA+B,SAAA,CAC1C,iBAAA,CAAkB,2BAAA,GAClB,2BAAA;EAAA,iBAEiB,UAAA;EAAA,QACT,iBAAA;EAAA,QACA,QAAA;cAEI,KAAA,EAAO,2BAAA;EAOJ,iBAAA,CAAA,GAAqB,OAAA;EAAA,QAoBtB,OAAA;EAiBC,kBAAA,CAAmB,SAAA,EAAW,iBAAA,CAAkB,2BAAA,IAA+B,OAAA;EAerF,oBAAA,CAAA;EASA,MAAA,CAAA,GAAM,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA;;;c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