avo-inspector 2.1.0 → 2.2.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.
- package/.claude/settings.local.json +9 -0
- package/CHANGELOG.md +9 -0
- package/README.md +8 -0
- package/dist/AvoAnonymousId.d.ts +26 -0
- package/dist/AvoInspector.d.ts +0 -2
- package/dist/AvoNetworkCallsHandler.d.ts +2 -1
- package/dist/index.js +1 -1
- package/jest.config.js +23 -0
- package/package.json +1 -21
- package/dist-native/AvoBatcher.d.ts +0 -24
- package/dist-native/AvoBatcher.js +0 -82
- package/dist-native/AvoDeduplicator.d.ts +0 -36
- package/dist-native/AvoDeduplicator.js +0 -142
- package/dist-native/AvoGuid.d.ts +0 -3
- package/dist-native/AvoGuid.js +0 -14
- package/dist-native/AvoInspector.d.ts +0 -52
- package/dist-native/AvoInspector.js +0 -220
- package/dist-native/AvoInspectorEnv.d.ts +0 -7
- package/dist-native/AvoInspectorEnv.js +0 -8
- package/dist-native/AvoInstallationId.d.ts +0 -5
- package/dist-native/AvoInstallationId.js +0 -36
- package/dist-native/AvoNetworkCallsHandler.d.ts +0 -48
- package/dist-native/AvoNetworkCallsHandler.js +0 -142
- package/dist-native/AvoSchemaParser.d.ts +0 -11
- package/dist-native/AvoSchemaParser.js +0 -95
- package/dist-native/AvoSessionTracker.d.ts +0 -15
- package/dist-native/AvoSessionTracker.js +0 -104
- package/dist-native/AvoStorage.d.ts +0 -22
- package/dist-native/AvoStorage.js +0 -336
- package/dist-native/__mocks__/xhr.d.ts +0 -12
- package/dist-native/__mocks__/xhr.js +0 -14
- package/dist-native/__mocks__/xhrError.d.ts +0 -12
- package/dist-native/__mocks__/xhrError.js +0 -14
- package/dist-native/__tests__/AvoInspector.d.ts +0 -1
- package/dist-native/__tests__/AvoInspector.js +0 -207
- package/dist-native/__tests__/Batcher.d.ts +0 -1
- package/dist-native/__tests__/Batcher.js +0 -280
- package/dist-native/__tests__/BatcherPublic.d.ts +0 -1
- package/dist-native/__tests__/BatcherPublic.js +0 -82
- package/dist-native/__tests__/Deduplicator.d.ts +0 -1
- package/dist-native/__tests__/Deduplicator.js +0 -111
- package/dist-native/__tests__/InstallationId.d.ts +0 -1
- package/dist-native/__tests__/InstallationId.js +0 -40
- package/dist-native/__tests__/NetworkCallsHandler.d.ts +0 -1
- package/dist-native/__tests__/NetworkCallsHandler.js +0 -132
- package/dist-native/__tests__/Parsing.d.ts +0 -1
- package/dist-native/__tests__/Parsing.js +0 -115
- package/dist-native/__tests__/Sessions.d.ts +0 -1
- package/dist-native/__tests__/Sessions.js +0 -179
- package/dist-native/__tests__/Storage.d.ts +0 -1
- package/dist-native/__tests__/Storage.js +0 -173
- package/dist-native/__tests__/constants.d.ts +0 -36
- package/dist-native/__tests__/constants.js +0 -47
- package/dist-native/index.d.ts +0 -2
- package/dist-native/index.js +0 -7
- package/dist-native/utils.d.ts +0 -3
- package/dist-native/utils.js +0 -42
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AvoSessionTracker = void 0;
|
|
4
|
-
var AvoGuid_1 = require("./AvoGuid");
|
|
5
|
-
var AvoInspector_1 = require("./AvoInspector");
|
|
6
|
-
var AvoSessionTracker = /** @class */ (function () {
|
|
7
|
-
function AvoSessionTracker(avoBatcher) {
|
|
8
|
-
this._lastSessionTimestamp = null;
|
|
9
|
-
this._sessionLengthMillis = 5 * 60 * 1000;
|
|
10
|
-
this.avoBatcher = avoBatcher;
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(AvoSessionTracker, "sessionId", {
|
|
13
|
-
get: function () {
|
|
14
|
-
if (AvoSessionTracker._sessionId === null) {
|
|
15
|
-
if (!AvoInspector_1.AvoInspector.avoStorage.isInitialized()) {
|
|
16
|
-
return "unknown";
|
|
17
|
-
}
|
|
18
|
-
var maybeSessionId = null;
|
|
19
|
-
try {
|
|
20
|
-
maybeSessionId = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoSessionTracker.idCacheKey);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
24
|
-
}
|
|
25
|
-
if (maybeSessionId === null || maybeSessionId === undefined) {
|
|
26
|
-
AvoSessionTracker._sessionId = this.updateSessionId();
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
AvoSessionTracker._sessionId = maybeSessionId;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return AvoSessionTracker._sessionId;
|
|
33
|
-
},
|
|
34
|
-
enumerable: false,
|
|
35
|
-
configurable: true
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(AvoSessionTracker.prototype, "lastSessionTimestamp", {
|
|
38
|
-
get: function () {
|
|
39
|
-
if (this._lastSessionTimestamp === null ||
|
|
40
|
-
this._lastSessionTimestamp === 0) {
|
|
41
|
-
var maybeLastSessionTimestamp = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoSessionTracker.lastSessionTimestampKey);
|
|
42
|
-
if (maybeLastSessionTimestamp !== null &&
|
|
43
|
-
maybeLastSessionTimestamp !== undefined) {
|
|
44
|
-
this._lastSessionTimestamp = maybeLastSessionTimestamp;
|
|
45
|
-
if (isNaN(this._lastSessionTimestamp)) {
|
|
46
|
-
this._lastSessionTimestamp = 0;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
this._lastSessionTimestamp = 0;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return this._lastSessionTimestamp;
|
|
54
|
-
},
|
|
55
|
-
enumerable: false,
|
|
56
|
-
configurable: true
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(AvoSessionTracker.prototype, "sessionLengthMillis", {
|
|
59
|
-
get: function () {
|
|
60
|
-
return this._sessionLengthMillis;
|
|
61
|
-
},
|
|
62
|
-
enumerable: false,
|
|
63
|
-
configurable: true
|
|
64
|
-
});
|
|
65
|
-
AvoSessionTracker.prototype.startOrProlongSession = function (atTime) {
|
|
66
|
-
var _this = this;
|
|
67
|
-
AvoInspector_1.AvoInspector.avoStorage.runAfterInit(function () {
|
|
68
|
-
var timeSinceLastSession = atTime - _this.lastSessionTimestamp;
|
|
69
|
-
if (timeSinceLastSession > _this._sessionLengthMillis) {
|
|
70
|
-
AvoSessionTracker.updateSessionId();
|
|
71
|
-
_this.avoBatcher.handleSessionStarted();
|
|
72
|
-
}
|
|
73
|
-
_this._lastSessionTimestamp = atTime;
|
|
74
|
-
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoSessionTracker.lastSessionTimestampKey, _this._lastSessionTimestamp);
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
AvoSessionTracker.updateSessionId = function () {
|
|
78
|
-
AvoSessionTracker._sessionId = AvoGuid_1.default.newGuid();
|
|
79
|
-
try {
|
|
80
|
-
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoSessionTracker.idCacheKey, AvoSessionTracker.sessionId);
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
84
|
-
}
|
|
85
|
-
return AvoSessionTracker._sessionId;
|
|
86
|
-
};
|
|
87
|
-
Object.defineProperty(AvoSessionTracker, "lastSessionTimestampKey", {
|
|
88
|
-
get: function () {
|
|
89
|
-
return "AvoInspectorSessionTimestamp";
|
|
90
|
-
},
|
|
91
|
-
enumerable: false,
|
|
92
|
-
configurable: true
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(AvoSessionTracker, "idCacheKey", {
|
|
95
|
-
get: function () {
|
|
96
|
-
return "AvoInspectorSessionId";
|
|
97
|
-
},
|
|
98
|
-
enumerable: false,
|
|
99
|
-
configurable: true
|
|
100
|
-
});
|
|
101
|
-
AvoSessionTracker._sessionId = null;
|
|
102
|
-
return AvoSessionTracker;
|
|
103
|
-
}());
|
|
104
|
-
exports.AvoSessionTracker = AvoSessionTracker;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
declare abstract class PlatformAvoStorage {
|
|
2
|
-
abstract init(shouldLog: boolean): void;
|
|
3
|
-
abstract getItemAsync<T>(key: string): Promise<T | null>;
|
|
4
|
-
abstract getItem<T>(key: string): T | null;
|
|
5
|
-
abstract setItem<T>(key: string, value: T): void;
|
|
6
|
-
abstract removeItem(key: string): void;
|
|
7
|
-
abstract runAfterInit(func: () => void): void;
|
|
8
|
-
abstract isInitialized(): boolean;
|
|
9
|
-
parseJson<T>(maybeItem: string | null | undefined): T | null;
|
|
10
|
-
}
|
|
11
|
-
export declare class AvoStorage {
|
|
12
|
-
Platform: string | null;
|
|
13
|
-
storageImpl: PlatformAvoStorage;
|
|
14
|
-
constructor(shouldLog: boolean);
|
|
15
|
-
isInitialized(): boolean;
|
|
16
|
-
getItemAsync<T>(key: string): Promise<T | null>;
|
|
17
|
-
getItem<T>(key: string): T | null;
|
|
18
|
-
setItem<T>(key: string, value: T): void;
|
|
19
|
-
removeItem(key: string): void;
|
|
20
|
-
runAfterInit(func: () => void): void;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AvoStorage = void 0;
|
|
19
|
-
var PlatformAvoStorage = /** @class */ (function () {
|
|
20
|
-
function PlatformAvoStorage() {
|
|
21
|
-
}
|
|
22
|
-
PlatformAvoStorage.prototype.parseJson = function (maybeItem) {
|
|
23
|
-
if (maybeItem !== null && maybeItem !== undefined) {
|
|
24
|
-
return JSON.parse(maybeItem);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
return PlatformAvoStorage;
|
|
31
|
-
}());
|
|
32
|
-
var AndroidAvoStorage = /** @class */ (function (_super) {
|
|
33
|
-
__extends(AndroidAvoStorage, _super);
|
|
34
|
-
function AndroidAvoStorage() {
|
|
35
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
36
|
-
_this.androidMemoryDataToAvoidAsyncQueries = {};
|
|
37
|
-
_this.storageLib = null;
|
|
38
|
-
_this.AsyncStorage = null;
|
|
39
|
-
_this.memoryStorageInitialized = false;
|
|
40
|
-
_this.onStorageInitFuncs = [];
|
|
41
|
-
_this.shouldLog = false;
|
|
42
|
-
return _this;
|
|
43
|
-
}
|
|
44
|
-
AndroidAvoStorage.prototype.init = function (shouldLog) {
|
|
45
|
-
var _this = this;
|
|
46
|
-
if (!process.env.BROWSER) {
|
|
47
|
-
this.storageLib = require("@react-native-async-storage/async-storage");
|
|
48
|
-
this.shouldLog = shouldLog;
|
|
49
|
-
this.AsyncStorage = this.storageLib.default;
|
|
50
|
-
this.loadAndroidDataToMemoryToAvoidAsyncQueries(function () {
|
|
51
|
-
_this.initializeStorageAndroid();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
AndroidAvoStorage.prototype.loadAndroidDataToMemoryToAvoidAsyncQueries = function (onLoaded) {
|
|
56
|
-
var _this = this;
|
|
57
|
-
this.AsyncStorage.getAllKeys().then(function (keys) {
|
|
58
|
-
return _this.AsyncStorage.multiGet(keys).then(function (keyVals) {
|
|
59
|
-
if (_this.shouldLog) {
|
|
60
|
-
console.log("Avo Inspector: android loaded data from memory");
|
|
61
|
-
}
|
|
62
|
-
keyVals.forEach(function (keyVal) {
|
|
63
|
-
var key = keyVal[0];
|
|
64
|
-
_this.androidMemoryDataToAvoidAsyncQueries[key] = keyVal[1];
|
|
65
|
-
if (_this.shouldLog) {
|
|
66
|
-
console.log(key, keyVal[1]);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
onLoaded();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
AndroidAvoStorage.prototype.initializeStorageAndroid = function () {
|
|
74
|
-
this.memoryStorageInitialized = true;
|
|
75
|
-
this.onStorageInitFuncs.forEach(function (func) {
|
|
76
|
-
func();
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
AndroidAvoStorage.prototype.isInitialized = function () {
|
|
80
|
-
return this.storageLib && this.memoryStorageInitialized;
|
|
81
|
-
};
|
|
82
|
-
AndroidAvoStorage.prototype.getItemAsync = function (key) {
|
|
83
|
-
var maybeItem = this.AsyncStorage.getItem(key);
|
|
84
|
-
return maybeItem.then(function (storedItem) {
|
|
85
|
-
return storedItem != null ? JSON.parse(storedItem) : null;
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
AndroidAvoStorage.prototype.getItem = function (key) {
|
|
89
|
-
var maybeItem = this.androidMemoryDataToAvoidAsyncQueries[key];
|
|
90
|
-
return this.parseJson(maybeItem);
|
|
91
|
-
};
|
|
92
|
-
AndroidAvoStorage.prototype.setItem = function (key, value) {
|
|
93
|
-
this.AsyncStorage.setItem(key, JSON.stringify(value));
|
|
94
|
-
this.androidMemoryDataToAvoidAsyncQueries[key] = JSON.stringify(value);
|
|
95
|
-
};
|
|
96
|
-
AndroidAvoStorage.prototype.removeItem = function (key) {
|
|
97
|
-
this.AsyncStorage.removeItem(key);
|
|
98
|
-
this.androidMemoryDataToAvoidAsyncQueries[key] = null;
|
|
99
|
-
};
|
|
100
|
-
AndroidAvoStorage.prototype.runAfterInit = function (func) {
|
|
101
|
-
if (this.memoryStorageInitialized === true) {
|
|
102
|
-
func();
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
this.onStorageInitFuncs.push(func);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
return AndroidAvoStorage;
|
|
109
|
-
}(PlatformAvoStorage));
|
|
110
|
-
var IosAvoStorage = /** @class */ (function (_super) {
|
|
111
|
-
__extends(IosAvoStorage, _super);
|
|
112
|
-
function IosAvoStorage() {
|
|
113
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
114
|
-
_this.reactNative = null;
|
|
115
|
-
return _this;
|
|
116
|
-
}
|
|
117
|
-
IosAvoStorage.prototype.init = function (_shouldLog) {
|
|
118
|
-
if (!process.env.BROWSER) {
|
|
119
|
-
this.reactNative = require("react-native");
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
IosAvoStorage.prototype.isInitialized = function () {
|
|
123
|
-
return this.reactNative != null;
|
|
124
|
-
};
|
|
125
|
-
IosAvoStorage.prototype.getItemAsync = function (key) {
|
|
126
|
-
var Settings = this.reactNative.Settings;
|
|
127
|
-
var maybeItem = Settings.get(key);
|
|
128
|
-
return Promise.resolve(this.parseJson(maybeItem));
|
|
129
|
-
};
|
|
130
|
-
IosAvoStorage.prototype.getItem = function (key) {
|
|
131
|
-
var Settings = this.reactNative.Settings;
|
|
132
|
-
var maybeItem = Settings.get(key);
|
|
133
|
-
return this.parseJson(maybeItem);
|
|
134
|
-
};
|
|
135
|
-
IosAvoStorage.prototype.setItem = function (key, value) {
|
|
136
|
-
var _a;
|
|
137
|
-
var Settings = this.reactNative.Settings;
|
|
138
|
-
Settings.set((_a = {}, _a[key] = JSON.stringify(value), _a));
|
|
139
|
-
};
|
|
140
|
-
IosAvoStorage.prototype.removeItem = function (key) {
|
|
141
|
-
var _a;
|
|
142
|
-
var Settings = this.reactNative.Settings;
|
|
143
|
-
Settings.set((_a = {}, _a[key] = null, _a));
|
|
144
|
-
};
|
|
145
|
-
IosAvoStorage.prototype.runAfterInit = function (func) {
|
|
146
|
-
func();
|
|
147
|
-
};
|
|
148
|
-
return IosAvoStorage;
|
|
149
|
-
}(PlatformAvoStorage));
|
|
150
|
-
var BrowserAvoStorage = /** @class */ (function (_super) {
|
|
151
|
-
__extends(BrowserAvoStorage, _super);
|
|
152
|
-
function BrowserAvoStorage() {
|
|
153
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
154
|
-
_this.useFallbackStorage = false;
|
|
155
|
-
_this.fallbackStorage = {};
|
|
156
|
-
_this.storageInitialized = false;
|
|
157
|
-
_this.onStorageInitFuncs = [];
|
|
158
|
-
_this.shouldLog = false;
|
|
159
|
-
return _this;
|
|
160
|
-
}
|
|
161
|
-
BrowserAvoStorage.prototype.init = function (shouldLog) {
|
|
162
|
-
this.shouldLog = shouldLog;
|
|
163
|
-
this.initializeStorageWeb(this.isLocalStorageAvailable());
|
|
164
|
-
};
|
|
165
|
-
BrowserAvoStorage.prototype.initializeStorageWeb = function (isLocalStorageAvailable) {
|
|
166
|
-
this.storageInitialized = true;
|
|
167
|
-
if (isLocalStorageAvailable === false) {
|
|
168
|
-
this.useFallbackStorage = true;
|
|
169
|
-
}
|
|
170
|
-
this.onStorageInitFuncs.forEach(function (func) {
|
|
171
|
-
func();
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
BrowserAvoStorage.prototype.isLocalStorageAvailable = function () {
|
|
175
|
-
var uid = new Date().toISOString();
|
|
176
|
-
try {
|
|
177
|
-
window.localStorage.setItem(uid, uid);
|
|
178
|
-
if (window.localStorage.getItem(uid) === uid) {
|
|
179
|
-
window.localStorage.removeItem(uid);
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
BrowserAvoStorage.prototype.isInitialized = function () {
|
|
191
|
-
return this.storageInitialized;
|
|
192
|
-
};
|
|
193
|
-
BrowserAvoStorage.prototype.getItemAsync = function (key) {
|
|
194
|
-
var thisStorage = this;
|
|
195
|
-
return new Promise(function (resolve, _reject) {
|
|
196
|
-
thisStorage.runAfterInit(function () {
|
|
197
|
-
if (thisStorage.useFallbackStorage === true) {
|
|
198
|
-
var maybeItem = thisStorage.fallbackStorage[key];
|
|
199
|
-
resolve(thisStorage.parseJson(maybeItem));
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
if (typeof window !== "undefined") {
|
|
203
|
-
var maybeItem = void 0;
|
|
204
|
-
try {
|
|
205
|
-
maybeItem = window.localStorage.getItem(key);
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
if (thisStorage.shouldLog) {
|
|
209
|
-
console.error("Avo Inspector Storage getItemAsync error:", error);
|
|
210
|
-
}
|
|
211
|
-
resolve(null);
|
|
212
|
-
}
|
|
213
|
-
resolve(thisStorage.parseJson(maybeItem));
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
resolve(null);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
BrowserAvoStorage.prototype.getItem = function (key) {
|
|
223
|
-
var maybeItem;
|
|
224
|
-
if (this.storageInitialized === false) {
|
|
225
|
-
maybeItem = null;
|
|
226
|
-
}
|
|
227
|
-
else if (this.useFallbackStorage === true) {
|
|
228
|
-
maybeItem = this.fallbackStorage[key];
|
|
229
|
-
}
|
|
230
|
-
else if (process.env.BROWSER) {
|
|
231
|
-
if (typeof window !== "undefined") {
|
|
232
|
-
try {
|
|
233
|
-
maybeItem = window.localStorage.getItem(key);
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
if (this.shouldLog) {
|
|
237
|
-
console.error("Avo Inspector Storage getItem error:", error);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return this.parseJson(maybeItem);
|
|
243
|
-
};
|
|
244
|
-
BrowserAvoStorage.prototype.setItem = function (key, value) {
|
|
245
|
-
var _this = this;
|
|
246
|
-
this.runAfterInit(function () {
|
|
247
|
-
if (_this.useFallbackStorage === true) {
|
|
248
|
-
_this.fallbackStorage[key] = JSON.stringify(value);
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
if (typeof window !== "undefined") {
|
|
252
|
-
try {
|
|
253
|
-
window.localStorage.setItem(key, JSON.stringify(value));
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
if (_this.shouldLog) {
|
|
257
|
-
console.error("Avo Inspector Storage setItem error:", error);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
BrowserAvoStorage.prototype.removeItem = function (key) {
|
|
265
|
-
var _this = this;
|
|
266
|
-
this.runAfterInit(function () {
|
|
267
|
-
if (_this.useFallbackStorage === true) {
|
|
268
|
-
_this.fallbackStorage[key] = null;
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
if (typeof window !== "undefined") {
|
|
272
|
-
try {
|
|
273
|
-
window.localStorage.removeItem(key);
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
if (_this.shouldLog) {
|
|
277
|
-
console.error("Avo Inspector Storage removeItem error:", error);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
};
|
|
284
|
-
BrowserAvoStorage.prototype.runAfterInit = function (func) {
|
|
285
|
-
if (this.storageInitialized === true) {
|
|
286
|
-
func();
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
this.onStorageInitFuncs.push(func);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
return BrowserAvoStorage;
|
|
293
|
-
}(PlatformAvoStorage));
|
|
294
|
-
var AvoStorage = /** @class */ (function () {
|
|
295
|
-
function AvoStorage(shouldLog) {
|
|
296
|
-
this.Platform = null;
|
|
297
|
-
if (!process.env.BROWSER) {
|
|
298
|
-
var reactNative = require("react-native");
|
|
299
|
-
this.Platform = reactNative.Platform.OS;
|
|
300
|
-
if (this.Platform === "android") {
|
|
301
|
-
this.storageImpl = new AndroidAvoStorage();
|
|
302
|
-
}
|
|
303
|
-
else if (this.Platform === "ios") {
|
|
304
|
-
this.storageImpl = new IosAvoStorage();
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
throw new Error("Avo Inpector is not supported on " + this.Platform);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
this.Platform = "browser";
|
|
312
|
-
this.storageImpl = new BrowserAvoStorage();
|
|
313
|
-
}
|
|
314
|
-
this.storageImpl.init(shouldLog);
|
|
315
|
-
}
|
|
316
|
-
AvoStorage.prototype.isInitialized = function () {
|
|
317
|
-
return this.storageImpl.isInitialized();
|
|
318
|
-
};
|
|
319
|
-
AvoStorage.prototype.getItemAsync = function (key) {
|
|
320
|
-
return this.storageImpl.getItemAsync(key);
|
|
321
|
-
};
|
|
322
|
-
AvoStorage.prototype.getItem = function (key) {
|
|
323
|
-
return this.storageImpl.getItem(key);
|
|
324
|
-
};
|
|
325
|
-
AvoStorage.prototype.setItem = function (key, value) {
|
|
326
|
-
this.storageImpl.setItem(key, value);
|
|
327
|
-
};
|
|
328
|
-
AvoStorage.prototype.removeItem = function (key) {
|
|
329
|
-
this.storageImpl.removeItem(key);
|
|
330
|
-
};
|
|
331
|
-
AvoStorage.prototype.runAfterInit = function (func) {
|
|
332
|
-
this.storageImpl.runAfterInit(func);
|
|
333
|
-
};
|
|
334
|
-
return AvoStorage;
|
|
335
|
-
}());
|
|
336
|
-
exports.AvoStorage = AvoStorage;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
declare let xhrMock: {
|
|
3
|
-
open: jest.Mock<any, any, any>;
|
|
4
|
-
send: jest.Mock<any, any, any>;
|
|
5
|
-
setRequestHeader: jest.Mock<any, any, any>;
|
|
6
|
-
onload: jest.Mock<any, any, any>;
|
|
7
|
-
onerror: jest.Mock<any, any, any>;
|
|
8
|
-
ontimeout: jest.Mock<any, any, any>;
|
|
9
|
-
status: number;
|
|
10
|
-
response: string;
|
|
11
|
-
};
|
|
12
|
-
export default xhrMock;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var xhrMock = {
|
|
4
|
-
open: jest.fn(),
|
|
5
|
-
send: jest.fn(),
|
|
6
|
-
setRequestHeader: jest.fn(),
|
|
7
|
-
onload: jest.fn(),
|
|
8
|
-
onerror: jest.fn(),
|
|
9
|
-
ontimeout: jest.fn(),
|
|
10
|
-
status: 200,
|
|
11
|
-
response: "{}",
|
|
12
|
-
};
|
|
13
|
-
window.XMLHttpRequest = jest.fn(function () { return xhrMock; });
|
|
14
|
-
exports.default = xhrMock;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
declare let xhrErrorMock: {
|
|
3
|
-
open: jest.Mock<any, any, any>;
|
|
4
|
-
send: jest.Mock<any, any, any>;
|
|
5
|
-
setRequestHeader: jest.Mock<any, any, any>;
|
|
6
|
-
onload: jest.Mock<any, any, any>;
|
|
7
|
-
onerror: jest.Mock<any, any, any>;
|
|
8
|
-
ontimeout: jest.Mock<any, any, any>;
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
11
|
-
};
|
|
12
|
-
export default xhrErrorMock;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var xhrErrorMock = {
|
|
4
|
-
open: jest.fn(),
|
|
5
|
-
send: jest.fn(),
|
|
6
|
-
setRequestHeader: jest.fn(),
|
|
7
|
-
onload: jest.fn(),
|
|
8
|
-
onerror: jest.fn(),
|
|
9
|
-
ontimeout: jest.fn(),
|
|
10
|
-
status: 400,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
};
|
|
13
|
-
window.XMLHttpRequest = jest.fn(function () { return xhrErrorMock; });
|
|
14
|
-
exports.default = xhrErrorMock;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|