@featbit/js-client-sdk 3.0.13 → 3.0.14

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.
Files changed (113) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +301 -301
  3. package/dist/esm/IFbClientCore.d.ts +1 -1
  4. package/dist/esm/IFbClientCore.d.ts.map +1 -1
  5. package/dist/esm/version.d.ts +1 -1
  6. package/dist/esm/version.js +1 -1
  7. package/dist/umd/{featbit-js-client-sdk-3.0.13.js → featbit-js-client-sdk-3.0.14.js} +2 -2
  8. package/dist/umd/featbit-js-client-sdk-3.0.14.js.map +1 -0
  9. package/dist/umd/featbit-js-client-sdk.js +1 -1
  10. package/dist/umd/featbit-js-client-sdk.js.map +1 -1
  11. package/package.json +46 -46
  12. package/src/Configuration.ts +232 -232
  13. package/src/Context.ts +61 -61
  14. package/src/FbClientBuilder.ts +167 -167
  15. package/src/FbClientCore.ts +405 -405
  16. package/src/IContextProperty.ts +3 -3
  17. package/src/IDataKind.ts +11 -11
  18. package/src/IFbClient.ts +29 -29
  19. package/src/IFbClientCore.ts +290 -290
  20. package/src/IVersionedData.ts +18 -18
  21. package/src/bootstrap/IBootstrapProvider.ts +4 -4
  22. package/src/bootstrap/JsonBootstrapProvider.ts +34 -34
  23. package/src/bootstrap/NullBootstrapProvider.ts +20 -20
  24. package/src/bootstrap/index.ts +2 -2
  25. package/src/constants.ts +1 -1
  26. package/src/data-sources/DataSourceUpdates.ts +116 -116
  27. package/src/data-sources/createStreamListeners.ts +67 -67
  28. package/src/data-sources/index.ts +1 -1
  29. package/src/data-sync/DataSyncMode.ts +3 -3
  30. package/src/data-sync/IDataSynchronizer.ts +15 -15
  31. package/src/data-sync/IRequestor.ts +10 -10
  32. package/src/data-sync/NullDataSynchronizer.ts +14 -14
  33. package/src/data-sync/PollingDataSynchronizer.ts +125 -125
  34. package/src/data-sync/Requestor.ts +61 -61
  35. package/src/data-sync/WebSocketDataSynchronizer.ts +77 -77
  36. package/src/data-sync/index.ts +8 -8
  37. package/src/data-sync/types.ts +19 -19
  38. package/src/data-sync/utils.ts +31 -31
  39. package/src/errors.ts +47 -47
  40. package/src/evaluation/EvalResult.ts +35 -35
  41. package/src/evaluation/Evaluator.ts +26 -26
  42. package/src/evaluation/IEvalDetail.ts +23 -23
  43. package/src/evaluation/ReasonKinds.ts +9 -9
  44. package/src/evaluation/data/IFlag.ts +29 -29
  45. package/src/evaluation/index.ts +4 -4
  46. package/src/events/DefaultEventProcessor.ts +83 -83
  47. package/src/events/DefaultEventQueue.ts +49 -49
  48. package/src/events/DefaultEventSender.ts +73 -73
  49. package/src/events/DefaultEventSerializer.ts +11 -11
  50. package/src/events/EventDispatcher.ts +127 -127
  51. package/src/events/EventSerializer.ts +4 -4
  52. package/src/events/IEventProcessor.ts +8 -8
  53. package/src/events/IEventQueue.ts +16 -16
  54. package/src/events/IEventSender.ts +13 -13
  55. package/src/events/NullEventProcessor.ts +15 -15
  56. package/src/events/event.ts +129 -129
  57. package/src/events/index.ts +11 -11
  58. package/src/index.ts +21 -21
  59. package/src/integrations/TestLogger.ts +24 -24
  60. package/src/integrations/index.ts +1 -1
  61. package/src/integrations/test_data/FlagBuilder.ts +59 -59
  62. package/src/integrations/test_data/TestData.ts +57 -57
  63. package/src/integrations/test_data/TestDataSynchronizer.ts +49 -49
  64. package/src/integrations/test_data/index.ts +4 -4
  65. package/src/logging/BasicLogger.ts +108 -108
  66. package/src/logging/IBasicLoggerOptions.ts +46 -46
  67. package/src/logging/ILogger.ts +49 -49
  68. package/src/logging/LogLevel.ts +8 -8
  69. package/src/logging/SafeLogger.ts +69 -69
  70. package/src/logging/format.ts +154 -154
  71. package/src/logging/index.ts +5 -5
  72. package/src/options/ClientContext.ts +39 -39
  73. package/src/options/IClientContext.ts +53 -53
  74. package/src/options/IOptions.ts +123 -123
  75. package/src/options/IUser.ts +6 -6
  76. package/src/options/IValidatedOptions.ts +29 -29
  77. package/src/options/OptionMessages.ts +35 -35
  78. package/src/options/UserBuilder.ts +35 -35
  79. package/src/options/Validators.ts +300 -300
  80. package/src/options/index.ts +7 -7
  81. package/src/platform/IInfo.ts +102 -102
  82. package/src/platform/IPlatform.ts +20 -20
  83. package/src/platform/IStore.ts +112 -112
  84. package/src/platform/IWebSocket.ts +22 -22
  85. package/src/platform/browser/BrowserInfo.ts +24 -24
  86. package/src/platform/browser/BrowserPlatform.ts +19 -19
  87. package/src/platform/browser/BrowserRequests.ts +6 -6
  88. package/src/platform/browser/BrowserWebSocket.ts +147 -147
  89. package/src/platform/browser/FbClient.ts +65 -65
  90. package/src/platform/browser/LocalStorageStore.ts +59 -59
  91. package/src/platform/index.ts +11 -11
  92. package/src/platform/requests.ts +76 -76
  93. package/src/store/BaseStore.ts +125 -125
  94. package/src/store/DataKinds.ts +6 -6
  95. package/src/store/IDataSourceUpdates.ts +68 -68
  96. package/src/store/InMemoryStore.ts +36 -36
  97. package/src/store/index.ts +5 -5
  98. package/src/store/serialization.ts +52 -52
  99. package/src/store/store.ts +37 -37
  100. package/src/utils/Emits.ts +75 -75
  101. package/src/utils/EventEmitter.ts +128 -128
  102. package/src/utils/IEventEmitter.ts +14 -14
  103. package/src/utils/Regex.ts +21 -21
  104. package/src/utils/ValueConverters.ts +55 -55
  105. package/src/utils/canonicalizeUri.ts +3 -3
  106. package/src/utils/debounce.ts +33 -33
  107. package/src/utils/http.ts +40 -40
  108. package/src/utils/index.ts +5 -5
  109. package/src/utils/isNullOrUndefined.ts +2 -2
  110. package/src/utils/serializeUser.ts +27 -27
  111. package/src/utils/sleep.ts +5 -5
  112. package/src/version.ts +1 -1
  113. package/dist/umd/featbit-js-client-sdk-3.0.13.js.map +0 -1
package/src/Context.ts CHANGED
@@ -1,62 +1,62 @@
1
- import { IUser } from "./options/IUser";
2
-
3
- export default class Context {
4
- private _user?: IUser;
5
- /**
6
- * Is this a valid context. If a valid context cannot be created, then this flag will be true.
7
- * The validity of a context should be tested before it is used.
8
- */
9
- public readonly valid: boolean;
10
-
11
- public readonly message?: string;
12
-
13
- /**
14
- * Contexts should be created using the static factory method {@link Context.fromUser}.
15
- *
16
- * The factory methods are static functions within the class because they access private
17
- * implementation details, so they cannot be free functions.
18
- */
19
- private constructor(valid: boolean, message?: string) {
20
- this.valid = valid;
21
- this.message = message;
22
- }
23
-
24
- public static fromUser(user: IUser): Context {
25
- if (!user) {
26
- return Context.contextForError('No user specified');
27
- }
28
-
29
- const {keyId, name} = user;
30
-
31
- if (keyId === undefined || keyId === null || keyId.trim() === '') {
32
- return Context.contextForError('key is mandatory');
33
- }
34
-
35
- const context = new Context(true);
36
- context._user = user;
37
-
38
- return context;
39
- }
40
-
41
- get user(): IUser {
42
- return this._user!;
43
- }
44
-
45
- get keyId(): string {
46
- return this._user!.keyId;
47
- }
48
-
49
- value(property: string): any {
50
- if (property === 'keyId') {
51
- return this._user?.keyId;
52
- } else if (property === 'name') {
53
- return this._user?.name;
54
- } else {
55
- return this._user?.customizedProperties?.find(x => x.name === property)?.value;
56
- }
57
- }
58
-
59
- private static contextForError(message: string) {
60
- return new Context(false, message);
61
- }
1
+ import { IUser } from "./options/IUser";
2
+
3
+ export default class Context {
4
+ private _user?: IUser;
5
+ /**
6
+ * Is this a valid context. If a valid context cannot be created, then this flag will be true.
7
+ * The validity of a context should be tested before it is used.
8
+ */
9
+ public readonly valid: boolean;
10
+
11
+ public readonly message?: string;
12
+
13
+ /**
14
+ * Contexts should be created using the static factory method {@link Context.fromUser}.
15
+ *
16
+ * The factory methods are static functions within the class because they access private
17
+ * implementation details, so they cannot be free functions.
18
+ */
19
+ private constructor(valid: boolean, message?: string) {
20
+ this.valid = valid;
21
+ this.message = message;
22
+ }
23
+
24
+ public static fromUser(user: IUser): Context {
25
+ if (!user) {
26
+ return Context.contextForError('No user specified');
27
+ }
28
+
29
+ const {keyId, name} = user;
30
+
31
+ if (keyId === undefined || keyId === null || keyId.trim() === '') {
32
+ return Context.contextForError('key is mandatory');
33
+ }
34
+
35
+ const context = new Context(true);
36
+ context._user = user;
37
+
38
+ return context;
39
+ }
40
+
41
+ get user(): IUser {
42
+ return this._user!;
43
+ }
44
+
45
+ get keyId(): string {
46
+ return this._user!.keyId;
47
+ }
48
+
49
+ value(property: string): any {
50
+ if (property === 'keyId') {
51
+ return this._user?.keyId;
52
+ } else if (property === 'name') {
53
+ return this._user?.name;
54
+ } else {
55
+ return this._user?.customizedProperties?.find(x => x.name === property)?.value;
56
+ }
57
+ }
58
+
59
+ private static contextForError(message: string) {
60
+ return new Context(false, message);
61
+ }
62
62
  }
@@ -1,168 +1,168 @@
1
- import { IFbClient } from "./IFbClient";
2
- import { IOptions } from "./options/IOptions";
3
- import FbClient from "./platform/browser/FbClient";
4
- import { IDataSynchronizer } from "./data-sync/IDataSynchronizer";
5
- import { IClientContext } from "./options/IClientContext";
6
- import { IDataSourceUpdates } from "./store/IDataSourceUpdates";
7
- import { VoidFunction } from "./utils/VoidFunction";
8
- import { ILogger } from "./logging/ILogger";
9
- import { DataSyncModeEnum } from "./data-sync/DataSyncMode";
10
- import { IUser } from "./options/IUser";
11
- import { IFlagBase } from "./evaluation";
12
- import { IPlatform } from "./platform";
13
-
14
- /**
15
- * Creates an instance of the FeatBit client.
16
- *
17
- * Applications should instantiate a single instance for the lifetime of the application.
18
- * The client will begin attempting to connect to FeatBit as soon as it is created. To
19
- * determine when it is ready to use, call {@link IFbClient.waitForInitialization}, or register an
20
- * event listener for the `"ready"` event using {@link IFbClient.on}.
21
- *
22
- * **Important:** Do **not** try to instantiate `FbClient` with its constructor
23
- * (`new FbClientNode()`); the SDK does not currently support
24
- * this.
25
- *
26
- * @return
27
- * The new {@link IFbClient} instance.
28
- */
29
- export class FbClientBuilder {
30
- private _options: IOptions;
31
- private _platform: IPlatform | undefined;
32
-
33
- constructor(options?: IOptions) {
34
- this._options = options ?? {};
35
- }
36
-
37
- /**
38
- * Creates a new instance of the FeatBit client.
39
- */
40
- build(): IFbClient {
41
- return new FbClient(this._options, this._platform);
42
- }
43
-
44
- platform(platform: IPlatform | undefined): FbClientBuilder {
45
- this._platform = platform;
46
- return this;
47
- }
48
-
49
- /**
50
- * Refer to {@link IOptions.startWaitTime}.
51
- */
52
- startWaitTime(startWaitTime: number): FbClientBuilder {
53
- this._options.startWaitTime = startWaitTime;
54
- return this;
55
- }
56
-
57
- /**
58
- * Refer to {@link IOptions.sdkKey}.
59
- */
60
- sdkKey(sdkKey: string): FbClientBuilder {
61
- this._options.sdkKey = sdkKey;
62
- return this;
63
- }
64
-
65
- /**
66
- * Refer to {@link IOptions.user}.
67
- */
68
- user(user: IUser): FbClientBuilder {
69
- this._options.user = user;
70
- return this;
71
- }
72
-
73
- /**
74
- * Refer to {@link IOptions.streamingUri}.
75
- */
76
- streamingUri(streamingUri: string): FbClientBuilder {
77
- this._options.streamingUri = streamingUri;
78
- return this;
79
- }
80
-
81
- /**
82
- * Refer to {@link IOptions.pollingUri}.
83
- */
84
- pollingUri(pollingUri: string): FbClientBuilder {
85
- this._options.pollingUri = pollingUri;
86
- return this;
87
- }
88
-
89
- /**
90
- * Refer to {@link IOptions.eventsUri}.
91
- */
92
- eventsUri(eventsUri: string): FbClientBuilder {
93
- this._options.eventsUri = eventsUri;
94
- return this;
95
- }
96
-
97
- /**
98
- * Refer to {@link IOptions.dataSyncMode}.
99
- */
100
- dataSyncMode(mode: DataSyncModeEnum): FbClientBuilder {
101
- this._options.dataSyncMode = mode;
102
- return this;
103
- }
104
-
105
- /**
106
- * Refer to {@link IOptions.pollingInterval}.
107
- */
108
- pollingInterval(pollingInterval: number): FbClientBuilder {
109
- this._options.pollingInterval = pollingInterval;
110
- return this;
111
- }
112
-
113
- /**
114
- * Refer to {@link IOptions.flushInterval}.
115
- */
116
- flushInterval(flushInterval: number): FbClientBuilder {
117
- this._options.flushInterval = flushInterval;
118
- return this;
119
- }
120
-
121
- /**
122
- * Refer to {@link IOptions.maxEventsInQueue}.
123
- */
124
- maxEventsInQueue(maxEventsInQueue: number): FbClientBuilder {
125
- this._options.maxEventsInQueue = maxEventsInQueue;
126
- return this;
127
- }
128
-
129
- /**
130
- * Refer to {@link IOptions.logger}.
131
- */
132
- logger(logger: ILogger): FbClientBuilder {
133
- this._options.logger = logger;
134
- return this;
135
- }
136
-
137
- /**
138
- * Refer to {@link IOptions.offline}.
139
- */
140
- offline(offline: boolean): FbClientBuilder {
141
- this._options.offline = offline;
142
- return this;
143
- }
144
-
145
- /**
146
- * Use the JsonBootstrapProvider.
147
- */
148
- bootstrap(flags: IFlagBase[]): FbClientBuilder {
149
- this._options.bootstrap = flags;
150
- return this;
151
- }
152
-
153
- /**
154
- * Refer to {@link IOptions.dataSynchronizer}.
155
- */
156
- dataSynchronizer(
157
- dataSynchronizer: IDataSynchronizer |
158
- ((
159
- clientContext: IClientContext,
160
- dataSourceUpdates: IDataSourceUpdates,
161
- initSuccessHandler: VoidFunction,
162
- errorHandler?: (e: Error) => void,
163
- ) => IDataSynchronizer)
164
- ): FbClientBuilder {
165
- this._options.dataSynchronizer = dataSynchronizer;
166
- return this;
167
- }
1
+ import { IFbClient } from "./IFbClient";
2
+ import { IOptions } from "./options/IOptions";
3
+ import FbClient from "./platform/browser/FbClient";
4
+ import { IDataSynchronizer } from "./data-sync/IDataSynchronizer";
5
+ import { IClientContext } from "./options/IClientContext";
6
+ import { IDataSourceUpdates } from "./store/IDataSourceUpdates";
7
+ import { VoidFunction } from "./utils/VoidFunction";
8
+ import { ILogger } from "./logging/ILogger";
9
+ import { DataSyncModeEnum } from "./data-sync/DataSyncMode";
10
+ import { IUser } from "./options/IUser";
11
+ import { IFlagBase } from "./evaluation";
12
+ import { IPlatform } from "./platform";
13
+
14
+ /**
15
+ * Creates an instance of the FeatBit client.
16
+ *
17
+ * Applications should instantiate a single instance for the lifetime of the application.
18
+ * The client will begin attempting to connect to FeatBit as soon as it is created. To
19
+ * determine when it is ready to use, call {@link IFbClient.waitForInitialization}, or register an
20
+ * event listener for the `"ready"` event using {@link IFbClient.on}.
21
+ *
22
+ * **Important:** Do **not** try to instantiate `FbClient` with its constructor
23
+ * (`new FbClientNode()`); the SDK does not currently support
24
+ * this.
25
+ *
26
+ * @return
27
+ * The new {@link IFbClient} instance.
28
+ */
29
+ export class FbClientBuilder {
30
+ private _options: IOptions;
31
+ private _platform: IPlatform | undefined;
32
+
33
+ constructor(options?: IOptions) {
34
+ this._options = options ?? {};
35
+ }
36
+
37
+ /**
38
+ * Creates a new instance of the FeatBit client.
39
+ */
40
+ build(): IFbClient {
41
+ return new FbClient(this._options, this._platform);
42
+ }
43
+
44
+ platform(platform: IPlatform | undefined): FbClientBuilder {
45
+ this._platform = platform;
46
+ return this;
47
+ }
48
+
49
+ /**
50
+ * Refer to {@link IOptions.startWaitTime}.
51
+ */
52
+ startWaitTime(startWaitTime: number): FbClientBuilder {
53
+ this._options.startWaitTime = startWaitTime;
54
+ return this;
55
+ }
56
+
57
+ /**
58
+ * Refer to {@link IOptions.sdkKey}.
59
+ */
60
+ sdkKey(sdkKey: string): FbClientBuilder {
61
+ this._options.sdkKey = sdkKey;
62
+ return this;
63
+ }
64
+
65
+ /**
66
+ * Refer to {@link IOptions.user}.
67
+ */
68
+ user(user: IUser): FbClientBuilder {
69
+ this._options.user = user;
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * Refer to {@link IOptions.streamingUri}.
75
+ */
76
+ streamingUri(streamingUri: string): FbClientBuilder {
77
+ this._options.streamingUri = streamingUri;
78
+ return this;
79
+ }
80
+
81
+ /**
82
+ * Refer to {@link IOptions.pollingUri}.
83
+ */
84
+ pollingUri(pollingUri: string): FbClientBuilder {
85
+ this._options.pollingUri = pollingUri;
86
+ return this;
87
+ }
88
+
89
+ /**
90
+ * Refer to {@link IOptions.eventsUri}.
91
+ */
92
+ eventsUri(eventsUri: string): FbClientBuilder {
93
+ this._options.eventsUri = eventsUri;
94
+ return this;
95
+ }
96
+
97
+ /**
98
+ * Refer to {@link IOptions.dataSyncMode}.
99
+ */
100
+ dataSyncMode(mode: DataSyncModeEnum): FbClientBuilder {
101
+ this._options.dataSyncMode = mode;
102
+ return this;
103
+ }
104
+
105
+ /**
106
+ * Refer to {@link IOptions.pollingInterval}.
107
+ */
108
+ pollingInterval(pollingInterval: number): FbClientBuilder {
109
+ this._options.pollingInterval = pollingInterval;
110
+ return this;
111
+ }
112
+
113
+ /**
114
+ * Refer to {@link IOptions.flushInterval}.
115
+ */
116
+ flushInterval(flushInterval: number): FbClientBuilder {
117
+ this._options.flushInterval = flushInterval;
118
+ return this;
119
+ }
120
+
121
+ /**
122
+ * Refer to {@link IOptions.maxEventsInQueue}.
123
+ */
124
+ maxEventsInQueue(maxEventsInQueue: number): FbClientBuilder {
125
+ this._options.maxEventsInQueue = maxEventsInQueue;
126
+ return this;
127
+ }
128
+
129
+ /**
130
+ * Refer to {@link IOptions.logger}.
131
+ */
132
+ logger(logger: ILogger): FbClientBuilder {
133
+ this._options.logger = logger;
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Refer to {@link IOptions.offline}.
139
+ */
140
+ offline(offline: boolean): FbClientBuilder {
141
+ this._options.offline = offline;
142
+ return this;
143
+ }
144
+
145
+ /**
146
+ * Use the JsonBootstrapProvider.
147
+ */
148
+ bootstrap(flags: IFlagBase[]): FbClientBuilder {
149
+ this._options.bootstrap = flags;
150
+ return this;
151
+ }
152
+
153
+ /**
154
+ * Refer to {@link IOptions.dataSynchronizer}.
155
+ */
156
+ dataSynchronizer(
157
+ dataSynchronizer: IDataSynchronizer |
158
+ ((
159
+ clientContext: IClientContext,
160
+ dataSourceUpdates: IDataSourceUpdates,
161
+ initSuccessHandler: VoidFunction,
162
+ errorHandler?: (e: Error) => void,
163
+ ) => IDataSynchronizer)
164
+ ): FbClientBuilder {
165
+ this._options.dataSynchronizer = dataSynchronizer;
166
+ return this;
167
+ }
168
168
  }