@configdirector/react-native-sdk 1.6.1 → 1.8.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.
@@ -33,27 +33,40 @@ type ConfigEvaluation = {
33
33
  context?: ConfigDirectorContext;
34
34
  };
35
35
  /**
36
- * The user's context to be sent to ConfigDirector. This context will be used for targeting
37
- * rules evaluation.
36
+ * The context to be sent to ConfigDirector: the user or other entity, such as a device or an
37
+ * organization, that configs are evaluated for. This context will be used for targeting rules
38
+ * evaluation.
38
39
  */
39
40
  type ConfigDirectorContext = {
40
41
  /**
41
- * The user's identifier. This should be a value that uniquely identifies an application
42
- * user.
42
+ * The context's identifier. This should be a value that uniquely identifies the user or other
43
+ * entity among contexts of the same {@link kind}.
43
44
  * In the case of anonymous users, you could generate a UUID or alternatively not provide
44
45
  * 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.
46
+ * value is used for segmenting contexts in percentage rollouts, and changes to the {@link id}
47
+ * could result in the context being assigned to a different percentile.
47
48
  */
48
49
  id?: string;
49
50
  /**
50
- * The user's display name. This will be shown in the ConfigDirector dashboard and may be
51
+ * The kind of entity this context represents, such as `user`, `device`, `organization`,
52
+ * `tenant` or `listing`. You can use any other kind that fits your application. A kind has 1
53
+ * to 64 characters, using only lowercase letters (`a`-`z`), digits, `-` and `_`. It is used
54
+ * exactly as given, without trimming or changing its case.
55
+ *
56
+ * A context with an invalid kind is ignored as a whole: the SDK logs an error and evaluates
57
+ * as if no context had been provided.
58
+ *
59
+ * @default "user"
60
+ */
61
+ kind?: string;
62
+ /**
63
+ * The context's display name. This will be shown in the ConfigDirector dashboard and may be
51
64
  * used for targeting rules.
52
65
  */
53
66
  name?: string;
54
67
  /**
55
- * Any arbitrary traits for the current user. They will be shown in the ConfigDirector
56
- * dashboard and may be used for targeting rules.
68
+ * Any arbitrary traits for the context. They will be shown in the ConfigDirector dashboard
69
+ * and may be used for targeting rules.
57
70
  */
58
71
  traits?: {
59
72
  [key: string]: unknown;
@@ -75,9 +88,76 @@ type ConfigDirectorMetaContext = {
75
88
  appVersion?: string;
76
89
  appName?: string;
77
90
  };
78
- type ConnectionMode = "streaming" | "polling";
91
+ type ConnectionMode = "streaming" | "polling" | "offline";
92
+ //#endregion
93
+ //#region ../shared/src/native-values.d.ts
94
+ type NativeJsonValue = boolean | number | string | null | NativeJsonValue[] | {
95
+ [key: string]: NativeJsonValue;
96
+ };
97
+ type NativeValue = boolean | number | string | NativeJsonValue[] | {
98
+ [key: string]: NativeJsonValue;
99
+ };
100
+ type NativeValues = Record<string, NativeValue>;
79
101
  //#endregion
80
102
  //#region ../js-client-core/src/types.d.ts
103
+ /**
104
+ * One value an offline client serves for a config key. The config type follows from the value: a
105
+ * boolean, an integral number (`integer`), any other number (`float`), a string, or a plain object
106
+ * or array (`json`).
107
+ */
108
+ type OfflineValue = NativeValue;
109
+ /**
110
+ * The values an offline client serves, keyed by config key. See {@link OfflineValue} for how each
111
+ * value's config type is decided. Every context receives the same value.
112
+ */
113
+ type OfflineValues = NativeValues;
114
+ /**
115
+ * Connection options of the {@link ConfigDirectorClient}
116
+ */
117
+ type ConnectionOptions = {
118
+ /**
119
+ * The connection mode to be used, one of `streaming` (default), `polling` or `offline`.
120
+ * If set to `streaming`, the connection will remain open and receive updates whenever
121
+ * config state is updated on the ConfigDirector dashboard.
122
+ * When set to `polling`, there will be an initial request to retrieve config state during
123
+ * initialization, and additional requests on a `pollingInterval`.
124
+ * When set to `offline`, the client never connects to ConfigDirector and sends nothing: it serves
125
+ * the values given in {@link values} to every context, or the in-code default values when none
126
+ * are given. No SDK key is needed.
127
+ *
128
+ * Defaults to `streaming`
129
+ */
130
+ mode?: ConnectionMode;
131
+ /**
132
+ * The values to serve in `offline` mode, keyed by config key. A value such as `null` makes
133
+ * `initialize` reject with a `ConfigDirectorInitializationError`.
134
+ *
135
+ * Can be given only in `offline` mode; otherwise `initialize` rejects.
136
+ */
137
+ values?: OfflineValues;
138
+ /**
139
+ * The polling interval in _seconds_ when the `mode` is set to `polling`. This option has no
140
+ * effect in the other modes.
141
+ *
142
+ * Defaults to 60 seconds. The minimum is 30 seconds. A value below the minimum is raised to the
143
+ * minimum and a warning is logged.
144
+ */
145
+ pollingInterval?: number;
146
+ /**
147
+ * The timeout, in _milliseconds_, to be used in initialization and when updating the context.
148
+ * If streaming is enabled, the operation (initialization or context update) may still succeed
149
+ * after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
150
+ * If streaming is disabled, if the operation times out, it will not be retried. This option has
151
+ * no effect in `offline` mode.
152
+ */
153
+ timeout?: number;
154
+ /**
155
+ * The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
156
+ * proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
157
+ * a proxy for the client SDK. This option has no effect in `offline` mode.
158
+ */
159
+ url?: string;
160
+ };
81
161
  /**
82
162
  * Configuration options for the {@link ConfigDirectorClient}
83
163
  */
@@ -89,39 +169,7 @@ type ConfigDirectorClientOptions = {
89
169
  /**
90
170
  * Connection options
91
171
  */
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
- };
172
+ connection?: ConnectionOptions;
125
173
  /**
126
174
  * A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
127
175
  * logger set to 'warn' level.
@@ -202,17 +250,25 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
202
250
  * not attempt to re-connect and an error will be logged to the console or the provided
203
251
  * logger.
204
252
  *
205
- * @param context The current user's context to be used for evaluating targeting rules (optional).
253
+ * A context whose {@link ConfigDirectorContext.kind} is invalid is ignored as a whole: an error is
254
+ * logged, and the client connects as if no context had been provided.
255
+ *
256
+ * @param context The current context to be used for evaluating targeting rules (optional).
206
257
  */
207
258
  initialize(context?: ConfigDirectorContext): Promise<void>;
208
259
  /**
209
- * Updates the user's context and re-evaluates all config and flag values based on the new context.
260
+ * Updates the context and re-evaluates all config and flag values based on the new context.
261
+ *
262
+ * A context whose {@link ConfigDirectorContext.kind} is invalid is ignored as a whole: an error is
263
+ * logged, the previous context is no longer used, and the client connects as if no context had been
264
+ * provided.
210
265
  *
211
- * @param context The current user's context to be used for evaluating targeting rules (required).
266
+ * @param context The current context to be used for evaluating targeting rules (required).
212
267
  */
213
268
  updateContext(context: ConfigDirectorContext): Promise<void>;
214
269
  /**
215
- * Returns the current context the client is configured with, or undefined if there is no context.
270
+ * Returns the current context the client is configured with, or undefined if there is no context,
271
+ * including after a context with an invalid kind was ignored.
216
272
  *
217
273
  * Note that the value returned does not updated immediately after calling {@link updateContext}. Only
218
274
  * once the underlying connection was successful or timed out, the current context is updated. This is
@@ -292,4 +348,4 @@ interface ConfigDirectorClient extends EventProvider<ClientEvents> {
292
348
  dispose(): void;
293
349
  }
294
350
  //#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 };
351
+ export { OfflineValues as a, NativeValues as c, ConfigDirectorLogger as d, ConfigDirectorLoggingLevel as f, OfflineValue as i, ConfigDirectorContext as l, ConnectionMode as m, ConfigDirectorClient as n, NativeJsonValue as o, ConfigValueType as p, ConfigDirectorClientOptions as r, NativeValue as s, ClientHooks as t, ConfigDirectorLogMessageDecorator as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configdirector/react-native-sdk",
3
- "version": "1.6.1",
3
+ "version": "1.8.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",
@@ -71,7 +71,9 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@babel/core": "^7.29.0",
74
+ "@babel/plugin-transform-dynamic-import": "^7",
74
75
  "@eslint/js": "^10.0.1",
76
+ "@react-native-async-storage/async-storage": "^3.1.1",
75
77
  "@react-native/babel-preset": "^0.85.0",
76
78
  "@react-native/jest-preset": "^0.86.2",
77
79
  "@rollup/plugin-replace": "^6.0.3",
@@ -96,11 +98,15 @@
96
98
  "wtfnode": "^0.10.1"
97
99
  },
98
100
  "peerDependencies": {
101
+ "@react-native-async-storage/async-storage": ">=1.0.0",
99
102
  "expo": ">=52",
100
103
  "react": "*",
101
104
  "react-native": ">=0.75"
102
105
  },
103
106
  "peerDependenciesMeta": {
107
+ "@react-native-async-storage/async-storage": {
108
+ "optional": true
109
+ },
104
110
  "expo": {
105
111
  "optional": true
106
112
  }
@@ -130,7 +136,7 @@
130
136
  "^@eventsource/(.*)$": "<rootDir>/../eventsource/src/$1"
131
137
  },
132
138
  "transformIgnorePatterns": [
133
- "node_modules/(?!((jest-)?react-native|@react-native(-community)?|@noble)/)"
139
+ "node_modules/(?!((jest-)?react-native|@react-native(-community|-async-storage)?|@noble)/)"
134
140
  ]
135
141
  }
136
142
  }