@mparticle/web-sdk 2.19.1 → 2.19.3
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.
- package/dist/mparticle.common.js +13 -13
- package/dist/mparticle.esm.js +13 -13
- package/dist/mparticle.js +114 -85
- package/package.json +3 -2
- package/src/batchUploader.ts +77 -77
- package/src/forwarders.js +40 -20
- package/src/helpers.js +5 -0
- package/src/identity.js +10 -6
- package/src/vault.ts +21 -74
package/src/identity.js
CHANGED
|
@@ -904,7 +904,8 @@ export default function Identity(mpInstance) {
|
|
|
904
904
|
self.IdentityAPI.getCurrentUser().getUserIdentities(),
|
|
905
905
|
mpInstance._APIClient.prepareForwardingStats
|
|
906
906
|
);
|
|
907
|
-
mpInstance._Forwarders.
|
|
907
|
+
mpInstance._Forwarders.handleForwarderUserAttributes(
|
|
908
|
+
'setUserAttribute',
|
|
908
909
|
key,
|
|
909
910
|
newValue
|
|
910
911
|
);
|
|
@@ -990,9 +991,10 @@ export default function Identity(mpInstance) {
|
|
|
990
991
|
self.IdentityAPI.getCurrentUser().getUserIdentities(),
|
|
991
992
|
mpInstance._APIClient.prepareForwardingStats
|
|
992
993
|
);
|
|
993
|
-
mpInstance._Forwarders.
|
|
994
|
+
mpInstance._Forwarders.handleForwarderUserAttributes(
|
|
994
995
|
'removeUserAttribute',
|
|
995
|
-
key
|
|
996
|
+
key,
|
|
997
|
+
null
|
|
996
998
|
);
|
|
997
999
|
}
|
|
998
1000
|
},
|
|
@@ -1098,7 +1100,8 @@ export default function Identity(mpInstance) {
|
|
|
1098
1100
|
self.IdentityAPI.getCurrentUser().getUserIdentities(),
|
|
1099
1101
|
mpInstance._APIClient.prepareForwardingStats
|
|
1100
1102
|
);
|
|
1101
|
-
mpInstance._Forwarders.
|
|
1103
|
+
mpInstance._Forwarders.handleForwarderUserAttributes(
|
|
1104
|
+
'setUserAttribute',
|
|
1102
1105
|
key,
|
|
1103
1106
|
arrayCopy
|
|
1104
1107
|
);
|
|
@@ -1127,9 +1130,10 @@ export default function Identity(mpInstance) {
|
|
|
1127
1130
|
if (userAttributes) {
|
|
1128
1131
|
for (var prop in userAttributes) {
|
|
1129
1132
|
if (userAttributes.hasOwnProperty(prop)) {
|
|
1130
|
-
mpInstance._Forwarders.
|
|
1133
|
+
mpInstance._Forwarders.handleForwarderUserAttributes(
|
|
1131
1134
|
'removeUserAttribute',
|
|
1132
|
-
prop
|
|
1135
|
+
prop,
|
|
1136
|
+
null
|
|
1133
1137
|
);
|
|
1134
1138
|
}
|
|
1135
1139
|
this.removeUserAttribute(prop);
|
package/src/vault.ts
CHANGED
|
@@ -6,12 +6,10 @@ interface IVaultOptions {
|
|
|
6
6
|
offlineStorageEnabled?: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export default class Vault<StorableItem
|
|
10
|
-
public contents:
|
|
9
|
+
export default class Vault<StorableItem> {
|
|
10
|
+
public contents: StorableItem;
|
|
11
11
|
private readonly _storageKey: string;
|
|
12
|
-
private readonly _itemKey: keyof StorableItem;
|
|
13
12
|
private logger?: Logger;
|
|
14
|
-
private offlineStorageEnabled: boolean = false;
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
*
|
|
@@ -19,16 +17,9 @@ export default class Vault<StorableItem extends Dictionary> {
|
|
|
19
17
|
* @param {string} itemKey an element within your StorableItem to use as a key
|
|
20
18
|
* @param {IVaultOptions} options A Dictionary of IVaultOptions
|
|
21
19
|
*/
|
|
22
|
-
constructor(
|
|
23
|
-
storageKey: string,
|
|
24
|
-
itemKey: keyof StorableItem,
|
|
25
|
-
options?: IVaultOptions
|
|
26
|
-
) {
|
|
20
|
+
constructor(storageKey: string, options?: IVaultOptions) {
|
|
27
21
|
this._storageKey = storageKey;
|
|
28
|
-
this.
|
|
29
|
-
this.contents = this.getItems() || {};
|
|
30
|
-
|
|
31
|
-
this.offlineStorageEnabled = options?.offlineStorageEnabled;
|
|
22
|
+
this.contents = this.getFromLocalStorage();
|
|
32
23
|
|
|
33
24
|
// Add a fake logger in case one is not provided or needed
|
|
34
25
|
this.logger = options?.logger || {
|
|
@@ -39,51 +30,16 @@ export default class Vault<StorableItem extends Dictionary> {
|
|
|
39
30
|
}
|
|
40
31
|
|
|
41
32
|
/**
|
|
42
|
-
* Stores a
|
|
33
|
+
* Stores a StorableItem to Local Storage
|
|
43
34
|
* @method storeItem
|
|
44
|
-
* @param item {StorableItem}
|
|
45
|
-
*/
|
|
46
|
-
public storeItem(item: StorableItem): void {
|
|
47
|
-
this.contents = this.getItems();
|
|
48
|
-
|
|
49
|
-
if (item[this._itemKey]) {
|
|
50
|
-
this.contents[item[this._itemKey]] = item;
|
|
51
|
-
this.logger.verbose(
|
|
52
|
-
`Saved items to vault with key: ${item[this._itemKey]}`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.saveItems(this.contents);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Stores Items using `itemId` as an index
|
|
61
|
-
* @method storeItems
|
|
62
|
-
* @param {StorableItem[]} an Array of StorableItems
|
|
63
|
-
*/
|
|
64
|
-
public storeItems(items: StorableItem[]): void {
|
|
65
|
-
items.forEach((item) => this.storeItem(item));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Removes a single StorableItem based on `indexId`
|
|
70
|
-
* @method removeItem
|
|
71
|
-
* @param {String} indexId
|
|
35
|
+
* @param item {StorableItem}
|
|
72
36
|
*/
|
|
73
|
-
public
|
|
74
|
-
this.
|
|
75
|
-
this.contents = this.getItems() || {};
|
|
37
|
+
public store(item: StorableItem): void {
|
|
38
|
+
this.contents = item;
|
|
76
39
|
|
|
77
|
-
|
|
78
|
-
delete this.contents[indexId];
|
|
40
|
+
this.logger.verbose(`Saved to local storage: ${item}`);
|
|
79
41
|
|
|
80
|
-
|
|
81
|
-
} catch (error) {
|
|
82
|
-
this.logger.error(
|
|
83
|
-
`Unable to remove item without a matching ID ${indexId}`
|
|
84
|
-
);
|
|
85
|
-
this.logger.error(error as string);
|
|
86
|
-
}
|
|
42
|
+
this.saveToLocalStorage(this.contents);
|
|
87
43
|
}
|
|
88
44
|
|
|
89
45
|
/**
|
|
@@ -91,10 +47,10 @@ export default class Vault<StorableItem extends Dictionary> {
|
|
|
91
47
|
* @method retrieveItems
|
|
92
48
|
* @returns {StorableItem[]} an array of Items
|
|
93
49
|
*/
|
|
94
|
-
public
|
|
95
|
-
this.contents = this.
|
|
50
|
+
public retrieve(): StorableItem {
|
|
51
|
+
this.contents = this.getFromLocalStorage();
|
|
96
52
|
|
|
97
|
-
return
|
|
53
|
+
return this.contents;
|
|
98
54
|
}
|
|
99
55
|
|
|
100
56
|
/**
|
|
@@ -102,14 +58,11 @@ export default class Vault<StorableItem extends Dictionary> {
|
|
|
102
58
|
* @method purge
|
|
103
59
|
*/
|
|
104
60
|
public purge(): void {
|
|
105
|
-
this.contents =
|
|
106
|
-
this.
|
|
61
|
+
this.contents = null;
|
|
62
|
+
this.removeFromLocalStorage();
|
|
107
63
|
}
|
|
108
64
|
|
|
109
|
-
private
|
|
110
|
-
if (!this.offlineStorageEnabled) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
65
|
+
private saveToLocalStorage(items: StorableItem): void {
|
|
113
66
|
try {
|
|
114
67
|
window.localStorage.setItem(
|
|
115
68
|
this._storageKey,
|
|
@@ -121,21 +74,15 @@ export default class Vault<StorableItem extends Dictionary> {
|
|
|
121
74
|
}
|
|
122
75
|
}
|
|
123
76
|
|
|
124
|
-
private
|
|
125
|
-
if (!this.offlineStorageEnabled) {
|
|
126
|
-
return this.contents;
|
|
127
|
-
}
|
|
77
|
+
private getFromLocalStorage(): StorableItem | null {
|
|
128
78
|
// TODO: Handle cases where Local Storage is unavailable
|
|
129
79
|
// https://go.mparticle.com/work/SQDSDKS-5022
|
|
130
|
-
const
|
|
80
|
+
const item: string = window.localStorage.getItem(this._storageKey);
|
|
131
81
|
|
|
132
|
-
return
|
|
82
|
+
return item ? JSON.parse(item) : null;
|
|
133
83
|
}
|
|
134
84
|
|
|
135
|
-
private
|
|
136
|
-
if (!this.offlineStorageEnabled) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
85
|
+
private removeFromLocalStorage(): void {
|
|
139
86
|
window.localStorage.removeItem(this._storageKey);
|
|
140
87
|
}
|
|
141
|
-
}
|
|
88
|
+
}
|