@featbit/js-client-sdk 3.0.11 → 3.0.13

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 (147) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +301 -301
  3. package/dist/esm/FbClientCore.d.ts.map +1 -1
  4. package/dist/esm/FbClientCore.js +1 -1
  5. package/dist/esm/FbClientCore.js.map +1 -1
  6. package/dist/esm/data-sources/DataSourceUpdates.d.ts +2 -2
  7. package/dist/esm/data-sources/DataSourceUpdates.d.ts.map +1 -1
  8. package/dist/esm/data-sources/DataSourceUpdates.js +55 -51
  9. package/dist/esm/data-sources/DataSourceUpdates.js.map +1 -1
  10. package/dist/esm/data-sources/createStreamListeners.d.ts +0 -9
  11. package/dist/esm/data-sources/createStreamListeners.d.ts.map +1 -1
  12. package/dist/esm/data-sources/createStreamListeners.js +10 -10
  13. package/dist/esm/data-sources/createStreamListeners.js.map +1 -1
  14. package/dist/esm/data-sync/IDataSynchronizer.d.ts +1 -1
  15. package/dist/esm/data-sync/IDataSynchronizer.d.ts.map +1 -1
  16. package/dist/esm/data-sync/NullDataSynchronizer.d.ts +1 -1
  17. package/dist/esm/data-sync/NullDataSynchronizer.d.ts.map +1 -1
  18. package/dist/esm/data-sync/NullDataSynchronizer.js +11 -0
  19. package/dist/esm/data-sync/NullDataSynchronizer.js.map +1 -1
  20. package/dist/esm/data-sync/PollingDataSynchronizer.d.ts +1 -1
  21. package/dist/esm/data-sync/PollingDataSynchronizer.d.ts.map +1 -1
  22. package/dist/esm/data-sync/PollingDataSynchronizer.js +42 -17
  23. package/dist/esm/data-sync/PollingDataSynchronizer.js.map +1 -1
  24. package/dist/esm/data-sync/WebSocketDataSynchronizer.d.ts +2 -1
  25. package/dist/esm/data-sync/WebSocketDataSynchronizer.d.ts.map +1 -1
  26. package/dist/esm/data-sync/WebSocketDataSynchronizer.js +20 -6
  27. package/dist/esm/data-sync/WebSocketDataSynchronizer.js.map +1 -1
  28. package/dist/esm/data-sync/types.d.ts +1 -1
  29. package/dist/esm/data-sync/types.d.ts.map +1 -1
  30. package/dist/esm/integrations/test_data/TestDataSynchronizer.d.ts +1 -1
  31. package/dist/esm/integrations/test_data/TestDataSynchronizer.d.ts.map +1 -1
  32. package/dist/esm/integrations/test_data/TestDataSynchronizer.js +3 -1
  33. package/dist/esm/integrations/test_data/TestDataSynchronizer.js.map +1 -1
  34. package/dist/esm/platform/browser/BrowserWebSocket.d.ts.map +1 -1
  35. package/dist/esm/platform/browser/BrowserWebSocket.js +4 -0
  36. package/dist/esm/platform/browser/BrowserWebSocket.js.map +1 -1
  37. package/dist/esm/store/IDataSourceUpdates.d.ts +2 -2
  38. package/dist/esm/store/IDataSourceUpdates.d.ts.map +1 -1
  39. package/dist/esm/version.d.ts +1 -1
  40. package/dist/esm/version.js +1 -1
  41. package/dist/umd/{featbit-js-client-sdk-3.0.11.js → featbit-js-client-sdk-3.0.13.js} +2 -2
  42. package/dist/umd/featbit-js-client-sdk-3.0.13.js.map +1 -0
  43. package/dist/umd/featbit-js-client-sdk.js +1 -1
  44. package/dist/umd/featbit-js-client-sdk.js.map +1 -1
  45. package/package.json +46 -46
  46. package/src/Configuration.ts +232 -232
  47. package/src/Context.ts +61 -61
  48. package/src/FbClientBuilder.ts +167 -167
  49. package/src/FbClientCore.ts +405 -401
  50. package/src/IContextProperty.ts +3 -3
  51. package/src/IDataKind.ts +11 -11
  52. package/src/IFbClient.ts +29 -29
  53. package/src/IFbClientCore.ts +290 -290
  54. package/src/IVersionedData.ts +18 -18
  55. package/src/bootstrap/IBootstrapProvider.ts +4 -4
  56. package/src/bootstrap/JsonBootstrapProvider.ts +34 -34
  57. package/src/bootstrap/NullBootstrapProvider.ts +20 -20
  58. package/src/bootstrap/index.ts +2 -2
  59. package/src/constants.ts +1 -1
  60. package/src/data-sources/DataSourceUpdates.ts +116 -116
  61. package/src/data-sources/createStreamListeners.ts +67 -66
  62. package/src/data-sources/index.ts +1 -1
  63. package/src/data-sync/DataSyncMode.ts +3 -3
  64. package/src/data-sync/IDataSynchronizer.ts +15 -15
  65. package/src/data-sync/IRequestor.ts +10 -10
  66. package/src/data-sync/NullDataSynchronizer.ts +14 -14
  67. package/src/data-sync/PollingDataSynchronizer.ts +125 -111
  68. package/src/data-sync/Requestor.ts +61 -61
  69. package/src/data-sync/WebSocketDataSynchronizer.ts +77 -73
  70. package/src/data-sync/index.ts +8 -8
  71. package/src/data-sync/types.ts +19 -19
  72. package/src/data-sync/utils.ts +31 -31
  73. package/src/errors.ts +47 -47
  74. package/src/evaluation/EvalResult.ts +35 -35
  75. package/src/evaluation/Evaluator.ts +26 -26
  76. package/src/evaluation/IEvalDetail.ts +23 -23
  77. package/src/evaluation/ReasonKinds.ts +9 -9
  78. package/src/evaluation/data/IFlag.ts +29 -29
  79. package/src/evaluation/index.ts +4 -4
  80. package/src/events/DefaultEventProcessor.ts +83 -83
  81. package/src/events/DefaultEventQueue.ts +49 -49
  82. package/src/events/DefaultEventSender.ts +73 -73
  83. package/src/events/DefaultEventSerializer.ts +11 -11
  84. package/src/events/EventDispatcher.ts +127 -127
  85. package/src/events/EventSerializer.ts +4 -4
  86. package/src/events/IEventProcessor.ts +8 -8
  87. package/src/events/IEventQueue.ts +16 -16
  88. package/src/events/IEventSender.ts +13 -13
  89. package/src/events/NullEventProcessor.ts +15 -15
  90. package/src/events/event.ts +129 -129
  91. package/src/events/index.ts +11 -11
  92. package/src/index.ts +21 -21
  93. package/src/integrations/TestLogger.ts +24 -24
  94. package/src/integrations/index.ts +1 -1
  95. package/src/integrations/test_data/FlagBuilder.ts +59 -59
  96. package/src/integrations/test_data/TestData.ts +57 -57
  97. package/src/integrations/test_data/TestDataSynchronizer.ts +49 -49
  98. package/src/integrations/test_data/index.ts +4 -4
  99. package/src/logging/BasicLogger.ts +108 -108
  100. package/src/logging/IBasicLoggerOptions.ts +46 -46
  101. package/src/logging/ILogger.ts +49 -49
  102. package/src/logging/LogLevel.ts +8 -8
  103. package/src/logging/SafeLogger.ts +69 -69
  104. package/src/logging/format.ts +154 -154
  105. package/src/logging/index.ts +5 -5
  106. package/src/options/ClientContext.ts +39 -39
  107. package/src/options/IClientContext.ts +53 -53
  108. package/src/options/IOptions.ts +123 -123
  109. package/src/options/IUser.ts +6 -6
  110. package/src/options/IValidatedOptions.ts +29 -29
  111. package/src/options/OptionMessages.ts +35 -35
  112. package/src/options/UserBuilder.ts +35 -35
  113. package/src/options/Validators.ts +300 -300
  114. package/src/options/index.ts +7 -7
  115. package/src/platform/IInfo.ts +102 -102
  116. package/src/platform/IPlatform.ts +20 -20
  117. package/src/platform/IStore.ts +112 -112
  118. package/src/platform/IWebSocket.ts +22 -22
  119. package/src/platform/browser/BrowserInfo.ts +24 -24
  120. package/src/platform/browser/BrowserPlatform.ts +19 -19
  121. package/src/platform/browser/BrowserRequests.ts +6 -6
  122. package/src/platform/browser/BrowserWebSocket.ts +147 -142
  123. package/src/platform/browser/FbClient.ts +65 -65
  124. package/src/platform/browser/LocalStorageStore.ts +59 -59
  125. package/src/platform/index.ts +11 -11
  126. package/src/platform/requests.ts +76 -76
  127. package/src/store/BaseStore.ts +125 -125
  128. package/src/store/DataKinds.ts +6 -6
  129. package/src/store/IDataSourceUpdates.ts +68 -68
  130. package/src/store/InMemoryStore.ts +36 -36
  131. package/src/store/index.ts +5 -5
  132. package/src/store/serialization.ts +52 -52
  133. package/src/store/store.ts +37 -37
  134. package/src/utils/Emits.ts +75 -75
  135. package/src/utils/EventEmitter.ts +128 -128
  136. package/src/utils/IEventEmitter.ts +14 -14
  137. package/src/utils/Regex.ts +21 -21
  138. package/src/utils/ValueConverters.ts +55 -55
  139. package/src/utils/canonicalizeUri.ts +3 -3
  140. package/src/utils/debounce.ts +33 -33
  141. package/src/utils/http.ts +40 -40
  142. package/src/utils/index.ts +5 -5
  143. package/src/utils/isNullOrUndefined.ts +2 -2
  144. package/src/utils/serializeUser.ts +27 -27
  145. package/src/utils/sleep.ts +5 -5
  146. package/src/version.ts +1 -1
  147. package/dist/umd/featbit-js-client-sdk-3.0.11.js.map +0 -1
@@ -1,77 +1,77 @@
1
- // These are not full specifications of the interface, but instead subsets
2
- // based on the functionality needed by the SDK. Exposure of the full standard
3
- // would require much more per platform implementation for platforms that do not
4
- // natively support fetch.
5
-
6
- /**
7
- * Interface for headers that are part of a fetch response.
8
- */
9
- export interface IHeaders {
10
- /**
11
- * Get a header by name.
12
- *
13
- * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
14
- *
15
- * @param name The name of the header to get.
16
- */
17
- get(name: string): string | null;
18
-
19
- /**
20
- * Returns an iterator allowing iteration of all the keys contained
21
- * in this object.
22
- *
23
- * https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys
24
- *
25
- */
26
- keys(): Iterable<string>;
27
-
28
- /**
29
- * Returns an iterator allowing iteration of all the values contained
30
- * in this object.
31
- *
32
- * https://developer.mozilla.org/en-US/docs/Web/API/Headers/values
33
- */
34
- values(): Iterable<string>;
35
-
36
- /**
37
- * Returns an iterator allowing iteration of all the key-value pairs in
38
- * the object.
39
- *
40
- * https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries
41
- */
42
- entries(): Iterable<[string, string]>;
43
-
44
- /**
45
- * Returns true if the header is present.
46
- * @param name The name of the header to check.
47
- */
48
- has(name: string): boolean;
49
- }
50
-
51
- /**
52
- * Interface for fetch responses.
53
- */
54
- export interface IResponse {
55
- status: number;
56
-
57
- /**
58
- * Read the response and provide it as a string.
59
- */
60
- text(): Promise<string>;
61
-
62
- /**
63
- * Read the response and provide it as decoded json.
64
- */
65
- json(): Promise<any>;
66
- }
67
-
68
- export interface IRequestOptions {
69
- headers?: Record<string, string>;
70
- method?: string;
71
- body?: string;
72
- timeout?: number;
73
- }
74
-
75
- export interface IRequests {
76
- fetch(url: string, options?: IRequestOptions): Promise<IResponse>;
1
+ // These are not full specifications of the interface, but instead subsets
2
+ // based on the functionality needed by the SDK. Exposure of the full standard
3
+ // would require much more per platform implementation for platforms that do not
4
+ // natively support fetch.
5
+
6
+ /**
7
+ * Interface for headers that are part of a fetch response.
8
+ */
9
+ export interface IHeaders {
10
+ /**
11
+ * Get a header by name.
12
+ *
13
+ * https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
14
+ *
15
+ * @param name The name of the header to get.
16
+ */
17
+ get(name: string): string | null;
18
+
19
+ /**
20
+ * Returns an iterator allowing iteration of all the keys contained
21
+ * in this object.
22
+ *
23
+ * https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys
24
+ *
25
+ */
26
+ keys(): Iterable<string>;
27
+
28
+ /**
29
+ * Returns an iterator allowing iteration of all the values contained
30
+ * in this object.
31
+ *
32
+ * https://developer.mozilla.org/en-US/docs/Web/API/Headers/values
33
+ */
34
+ values(): Iterable<string>;
35
+
36
+ /**
37
+ * Returns an iterator allowing iteration of all the key-value pairs in
38
+ * the object.
39
+ *
40
+ * https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries
41
+ */
42
+ entries(): Iterable<[string, string]>;
43
+
44
+ /**
45
+ * Returns true if the header is present.
46
+ * @param name The name of the header to check.
47
+ */
48
+ has(name: string): boolean;
49
+ }
50
+
51
+ /**
52
+ * Interface for fetch responses.
53
+ */
54
+ export interface IResponse {
55
+ status: number;
56
+
57
+ /**
58
+ * Read the response and provide it as a string.
59
+ */
60
+ text(): Promise<string>;
61
+
62
+ /**
63
+ * Read the response and provide it as decoded json.
64
+ */
65
+ json(): Promise<any>;
66
+ }
67
+
68
+ export interface IRequestOptions {
69
+ headers?: Record<string, string>;
70
+ method?: string;
71
+ body?: string;
72
+ timeout?: number;
73
+ }
74
+
75
+ export interface IRequests {
76
+ fetch(url: string, options?: IRequestOptions): Promise<IResponse>;
77
77
  }
@@ -1,126 +1,126 @@
1
- import { IStore } from "../platform";
2
- import { IKeyedStoreItem, IStoreDataStorage, IStoreItem, IStoreKindData } from "./store";
3
- import { IUser } from "../options";
4
- import { IDataKind } from "../IDataKind";
5
-
6
- export class BaseStore implements IStore {
7
- protected store: IStoreDataStorage = {} as IStoreDataStorage;
8
-
9
- protected initCalled = false;
10
-
11
- protected _user: IUser = {} as IUser;
12
-
13
- constructor() {
14
- }
15
-
16
- async identify(user: IUser) {
17
- this._user = {...user};
18
-
19
- await this.saveUser();
20
- await this.loadStoreFromStorage();
21
- }
22
-
23
- get user(): IUser {
24
- return this._user;
25
- }
26
-
27
- protected async addItem(kind: IDataKind, key: string, item: IStoreItem) {
28
- let items = this.store[kind.namespace];
29
- if (!items) {
30
- items = {};
31
- this.store[kind.namespace] = items;
32
- }
33
- if (Object.hasOwnProperty.call(items, key)) {
34
- const old = items[key];
35
- // we use <= here, the reason is that when a segment is changed, the upstream service would push the flag
36
- // to client SDK with flag timestamp (version) instead of segment timestamp, so to ensure that the new flag value
37
- // is saved, we need to use <=
38
- if (!old || old.version <= item.version) {
39
- items[key] = item;
40
- }
41
- } else {
42
- items[key] = item;
43
- }
44
-
45
- if (item.version > this.store.version) {
46
- this.store.version = item.version;
47
- }
48
-
49
- await this.dumpStoreToStorage();
50
- }
51
-
52
- get(kind: IDataKind, key: string): IStoreItem | null {
53
- const items = this.store[kind.namespace];
54
- if (items) {
55
- if (Object.prototype.hasOwnProperty.call(items, key)) {
56
- const item = items[key];
57
- if (item) {
58
- return item;
59
- }
60
- }
61
- }
62
- return null;
63
- }
64
-
65
- all(kind: IDataKind): [IStoreKindData, number] {
66
- const result: IStoreKindData = {};
67
- const items = this.store[kind.namespace] ?? {};
68
- Object.entries(items).forEach(([key, item]) => {
69
- if (item) {
70
- result[key] = <IStoreItem>item;
71
- }
72
- });
73
-
74
- return [result, this.store.version];
75
- }
76
-
77
- async init(allData: IStoreDataStorage) {
78
- this.store = allData as IStoreDataStorage;
79
-
80
- Object.keys(allData).map(namespace => {
81
- Object.entries(allData[namespace]).forEach(([_, item]) => {
82
- const ele = item as IStoreItem;
83
- if (ele.version > this.store.version) {
84
- this.store.version = ele.version;
85
- }
86
- })
87
- });
88
-
89
- await this.dumpStoreToStorage();
90
- this.initCalled = true;
91
- }
92
-
93
- async upsert(kind: IDataKind, data: IKeyedStoreItem) {
94
- await this.addItem(kind, data.key, data);
95
- }
96
-
97
- initialized(): boolean {
98
- return this.initCalled;
99
- }
100
-
101
- /* eslint-disable class-methods-use-this */
102
- close(): void {
103
- // For the LocalStorage store this is a no-op.
104
- }
105
-
106
- get version(): number {
107
- return this.store.version;
108
- }
109
-
110
- // This getter needs to be overridden in the child class
111
- get description(): string {
112
- return '';
113
- }
114
-
115
- // This method needs to be overridden in the child class
116
- protected async saveUser(): Promise<void> {
117
- }
118
-
119
- // This method needs to be overridden in the child class
120
- protected async loadStoreFromStorage(): Promise<void> {
121
- }
122
-
123
- // This method needs to be overridden in the child class
124
- protected async dumpStoreToStorage(): Promise<void> {
125
- }
1
+ import { IStore } from "../platform";
2
+ import { IKeyedStoreItem, IStoreDataStorage, IStoreItem, IStoreKindData } from "./store";
3
+ import { IUser } from "../options";
4
+ import { IDataKind } from "../IDataKind";
5
+
6
+ export class BaseStore implements IStore {
7
+ protected store: IStoreDataStorage = {} as IStoreDataStorage;
8
+
9
+ protected initCalled = false;
10
+
11
+ protected _user: IUser = {} as IUser;
12
+
13
+ constructor() {
14
+ }
15
+
16
+ async identify(user: IUser) {
17
+ this._user = {...user};
18
+
19
+ await this.saveUser();
20
+ await this.loadStoreFromStorage();
21
+ }
22
+
23
+ get user(): IUser {
24
+ return this._user;
25
+ }
26
+
27
+ protected async addItem(kind: IDataKind, key: string, item: IStoreItem) {
28
+ let items = this.store[kind.namespace];
29
+ if (!items) {
30
+ items = {};
31
+ this.store[kind.namespace] = items;
32
+ }
33
+ if (Object.hasOwnProperty.call(items, key)) {
34
+ const old = items[key];
35
+ // we use <= here, the reason is that when a segment is changed, the upstream service would push the flag
36
+ // to client SDK with flag timestamp (version) instead of segment timestamp, so to ensure that the new flag value
37
+ // is saved, we need to use <=
38
+ if (!old || old.version <= item.version) {
39
+ items[key] = item;
40
+ }
41
+ } else {
42
+ items[key] = item;
43
+ }
44
+
45
+ if (item.version > this.store.version) {
46
+ this.store.version = item.version;
47
+ }
48
+
49
+ await this.dumpStoreToStorage();
50
+ }
51
+
52
+ get(kind: IDataKind, key: string): IStoreItem | null {
53
+ const items = this.store[kind.namespace];
54
+ if (items) {
55
+ if (Object.prototype.hasOwnProperty.call(items, key)) {
56
+ const item = items[key];
57
+ if (item) {
58
+ return item;
59
+ }
60
+ }
61
+ }
62
+ return null;
63
+ }
64
+
65
+ all(kind: IDataKind): [IStoreKindData, number] {
66
+ const result: IStoreKindData = {};
67
+ const items = this.store[kind.namespace] ?? {};
68
+ Object.entries(items).forEach(([key, item]) => {
69
+ if (item) {
70
+ result[key] = <IStoreItem>item;
71
+ }
72
+ });
73
+
74
+ return [result, this.store.version];
75
+ }
76
+
77
+ async init(allData: IStoreDataStorage) {
78
+ this.store = allData as IStoreDataStorage;
79
+
80
+ Object.keys(allData).map(namespace => {
81
+ Object.entries(allData[namespace]).forEach(([_, item]) => {
82
+ const ele = item as IStoreItem;
83
+ if (ele.version > this.store.version) {
84
+ this.store.version = ele.version;
85
+ }
86
+ })
87
+ });
88
+
89
+ await this.dumpStoreToStorage();
90
+ this.initCalled = true;
91
+ }
92
+
93
+ async upsert(kind: IDataKind, data: IKeyedStoreItem) {
94
+ await this.addItem(kind, data.key, data);
95
+ }
96
+
97
+ initialized(): boolean {
98
+ return this.initCalled;
99
+ }
100
+
101
+ /* eslint-disable class-methods-use-this */
102
+ close(): void {
103
+ // For the LocalStorage store this is a no-op.
104
+ }
105
+
106
+ get version(): number {
107
+ return this.store.version;
108
+ }
109
+
110
+ // This getter needs to be overridden in the child class
111
+ get description(): string {
112
+ return '';
113
+ }
114
+
115
+ // This method needs to be overridden in the child class
116
+ protected async saveUser(): Promise<void> {
117
+ }
118
+
119
+ // This method needs to be overridden in the child class
120
+ protected async loadStoreFromStorage(): Promise<void> {
121
+ }
122
+
123
+ // This method needs to be overridden in the child class
124
+ protected async dumpStoreToStorage(): Promise<void> {
125
+ }
126
126
  }
@@ -1,7 +1,7 @@
1
- import { IDataKind } from "../IDataKind";
2
-
3
- export default class DataKinds {
4
- static readonly Flags: IDataKind = {
5
- namespace: 'flags'
6
- };
1
+ import { IDataKind } from "../IDataKind";
2
+
3
+ export default class DataKinds {
4
+ static readonly Flags: IDataKind = {
5
+ namespace: 'flags'
6
+ };
7
7
  }
@@ -1,68 +1,68 @@
1
- import { IDataKind } from "../IDataKind";
2
- import { IStoreDataStorage, IKeyedStoreItem } from "./store";
3
-
4
- /**
5
- * Interface that a data source implementation will use to push data into the SDK.
6
- *
7
- * The data source interacts with this object, rather than manipulating the data store directly, so
8
- * that the SDK can perform any other necessary operations that must happen when data is updated.
9
- */
10
- export interface IDataSourceUpdates {
11
- /**
12
- * Completely overwrites the current contents of the data store with a set of items for each
13
- * collection.
14
- *
15
- * @param userKeyId
16
- * The key ID of the user whose data is being updated.
17
- *
18
- * @param allData
19
- * An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
20
- * the value is an object that maps keys to entities. The actual type of this parameter is
21
- * `interfaces.FullDataSet<VersionedData>`.
22
- *
23
- * @param callback
24
- * Will be called when the store has been initialized.
25
- */
26
- init(userKeyId: string, allData: IStoreDataStorage, callback?: () => void): void;
27
-
28
- /**
29
- * Compare old and new data, check if any update exists
30
- * If update exists, send onUpdate events
31
- *
32
- * @param oldData
33
- * An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
34
- * the value is an object that maps keys to entities. The actual type of this parameter is
35
- * `interfaces.FullDataSet<VersionedData>`.
36
- *
37
- * @param newData
38
- * An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
39
- * the value is an object that maps keys to entities. The actual type of this parameter is
40
- * `interfaces.FullDataSet<VersionedData>`.
41
- *
42
- * @param callback
43
- * Will be called when the store has been initialized.
44
- */
45
- checkUpdates(oldData: IStoreDataStorage, newData: IStoreDataStorage, callback?: () => void): void;
46
-
47
- /**
48
- * Updates or inserts an item in the specified collection. For updates, the object will only be
49
- * updated if the existing version is less than the new version.
50
- *
51
- * @param userKeyId
52
- * The key ID of the user whose data is being updated.
53
- *
54
- * @param kind
55
- * The type of data to be accessed. The actual type of this parameter is
56
- * {@link IDataKind}.
57
- *
58
- * @param data
59
- * The contents of the entity, as an object that can be converted to JSON. The store
60
- * should check the `version` property of this object, and should *not* overwrite any
61
- * existing data if the existing `version` is greater than or equal to that value.
62
- * The actual type of this parameter is {@link IKeyedStoreItem}.
63
- *
64
- * @param callback
65
- * Will be called after the upsert operation is complete.
66
- */
67
- upsert(userKeyId: string, kind: IDataKind, data: IKeyedStoreItem, callback: () => void): void;
68
- }
1
+ import { IDataKind } from "../IDataKind";
2
+ import { IStoreDataStorage, IKeyedStoreItem } from "./store";
3
+
4
+ /**
5
+ * Interface that a data source implementation will use to push data into the SDK.
6
+ *
7
+ * The data source interacts with this object, rather than manipulating the data store directly, so
8
+ * that the SDK can perform any other necessary operations that must happen when data is updated.
9
+ */
10
+ export interface IDataSourceUpdates {
11
+ /**
12
+ * Completely overwrites the current contents of the data store with a set of items for each
13
+ * collection.
14
+ *
15
+ * @param userKeyId
16
+ * The key ID of the user whose data is being updated.
17
+ *
18
+ * @param allData
19
+ * An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
20
+ * the value is an object that maps keys to entities. The actual type of this parameter is
21
+ * `interfaces.FullDataSet<VersionedData>`.
22
+ *
23
+ * @param callback
24
+ * Will be called when the store has been initialized.
25
+ */
26
+ init(userKeyId: string, allData: IStoreDataStorage, callback?: () => void): Promise<void>;
27
+
28
+ /**
29
+ * Compare old and new data, check if any update exists
30
+ * If update exists, send onUpdate events
31
+ *
32
+ * @param oldData
33
+ * An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
34
+ * the value is an object that maps keys to entities. The actual type of this parameter is
35
+ * `interfaces.FullDataSet<VersionedData>`.
36
+ *
37
+ * @param newData
38
+ * An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
39
+ * the value is an object that maps keys to entities. The actual type of this parameter is
40
+ * `interfaces.FullDataSet<VersionedData>`.
41
+ *
42
+ * @param callback
43
+ * Will be called when the store has been initialized.
44
+ */
45
+ checkUpdates(oldData: IStoreDataStorage, newData: IStoreDataStorage, callback?: () => void): void;
46
+
47
+ /**
48
+ * Updates or inserts an item in the specified collection. For updates, the object will only be
49
+ * updated if the existing version is less than the new version.
50
+ *
51
+ * @param userKeyId
52
+ * The key ID of the user whose data is being updated.
53
+ *
54
+ * @param kind
55
+ * The type of data to be accessed. The actual type of this parameter is
56
+ * {@link IDataKind}.
57
+ *
58
+ * @param data
59
+ * The contents of the entity, as an object that can be converted to JSON. The store
60
+ * should check the `version` property of this object, and should *not* overwrite any
61
+ * existing data if the existing `version` is greater than or equal to that value.
62
+ * The actual type of this parameter is {@link IKeyedStoreItem}.
63
+ *
64
+ * @param callback
65
+ * Will be called after the upsert operation is complete.
66
+ */
67
+ upsert(userKeyId: string, kind: IDataKind, data: IKeyedStoreItem, callback: () => void): Promise<void>;
68
+ }
@@ -1,37 +1,37 @@
1
- import {
2
- StoreStorageKey,
3
- IStoreDataStorage
4
- } from "./store";
5
- import { BaseStore } from "./BaseStore";
6
-
7
- export default class InMemoryStore extends BaseStore {
8
- private allStores: { [DataStoreStorageKey: string]: IStoreDataStorage } = {};
9
-
10
- constructor() {
11
- super();
12
- }
13
-
14
- /* eslint-disable class-methods-use-this */
15
- close(): void {
16
- // For the LocalStorage store this is a no-op.
17
- }
18
-
19
- get description(): string {
20
- return 'in-memory-store'
21
- }
22
-
23
- protected async saveUser(): Promise<void> {
24
- // For in-memory store, this is a no-op.
25
- }
26
-
27
- protected override async dumpStoreToStorage() {
28
- const storageKey = `${StoreStorageKey}-${this._user.keyId}`;
29
- this.allStores[storageKey] = {...this.store};
30
- }
31
-
32
- protected override async loadStoreFromStorage() {
33
- const storageKey = `${StoreStorageKey}-${this._user.keyId}`;
34
-
35
- this.store = this.allStores[storageKey] ?? { flags: {}, version: 0 };
36
- }
1
+ import {
2
+ StoreStorageKey,
3
+ IStoreDataStorage
4
+ } from "./store";
5
+ import { BaseStore } from "./BaseStore";
6
+
7
+ export default class InMemoryStore extends BaseStore {
8
+ private allStores: { [DataStoreStorageKey: string]: IStoreDataStorage } = {};
9
+
10
+ constructor() {
11
+ super();
12
+ }
13
+
14
+ /* eslint-disable class-methods-use-this */
15
+ close(): void {
16
+ // For the LocalStorage store this is a no-op.
17
+ }
18
+
19
+ get description(): string {
20
+ return 'in-memory-store'
21
+ }
22
+
23
+ protected async saveUser(): Promise<void> {
24
+ // For in-memory store, this is a no-op.
25
+ }
26
+
27
+ protected override async dumpStoreToStorage() {
28
+ const storageKey = `${StoreStorageKey}-${this._user.keyId}`;
29
+ this.allStores[storageKey] = {...this.store};
30
+ }
31
+
32
+ protected override async loadStoreFromStorage() {
33
+ const storageKey = `${StoreStorageKey}-${this._user.keyId}`;
34
+
35
+ this.store = this.allStores[storageKey] ?? { flags: {}, version: 0 };
36
+ }
37
37
  }
@@ -1,6 +1,6 @@
1
- export * from './DataKinds';
2
- export * from './IDataSourceUpdates';
3
- export * from './InMemoryStore';
4
- export * from './serialization';
5
- export * from './store';
1
+ export * from './DataKinds';
2
+ export * from './IDataSourceUpdates';
3
+ export * from './InMemoryStore';
4
+ export * from './serialization';
5
+ export * from './store';
6
6
  export * from './BaseStore';