avo-inspector 1.2.5 → 1.3.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/.vscode/launch.json +4 -15
- package/README.md +31 -21
- package/dist/AvoInspector.d.ts +2 -0
- package/dist/AvoStorage.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/main.js +1 -0
- package/dist-native/AvoBatcher.d.ts +24 -0
- package/dist-native/AvoBatcher.js +82 -0
- package/dist-native/AvoDeduplicator.d.ts +36 -0
- package/dist-native/AvoDeduplicator.js +142 -0
- package/dist-native/AvoGuid.d.ts +3 -0
- package/dist-native/AvoGuid.js +14 -0
- package/dist-native/AvoInspector.d.ts +53 -0
- package/dist-native/AvoInspector.js +220 -0
- package/dist-native/AvoInspectorEnv.d.ts +7 -0
- package/dist-native/AvoInspectorEnv.js +8 -0
- package/dist-native/AvoInstallationId.d.ts +5 -0
- package/dist-native/AvoInstallationId.js +36 -0
- package/dist-native/AvoNetworkCallsHandler.d.ts +48 -0
- package/dist-native/AvoNetworkCallsHandler.js +142 -0
- package/dist-native/AvoSchemaParser.d.ts +11 -0
- package/dist-native/AvoSchemaParser.js +95 -0
- package/dist-native/AvoSessionTracker.d.ts +15 -0
- package/dist-native/AvoSessionTracker.js +104 -0
- package/dist-native/AvoStorage.d.ts +22 -0
- package/dist-native/AvoStorage.js +343 -0
- package/dist-native/__mocks__/xhr.d.ts +12 -0
- package/dist-native/__mocks__/xhr.js +14 -0
- package/dist-native/__mocks__/xhrError.d.ts +12 -0
- package/dist-native/__mocks__/xhrError.js +14 -0
- package/dist-native/__tests__/AvoInspector.d.ts +1 -0
- package/dist-native/__tests__/AvoInspector.js +207 -0
- package/dist-native/__tests__/Batcher.d.ts +1 -0
- package/dist-native/__tests__/Batcher.js +278 -0
- package/dist-native/__tests__/BatcherPublic.d.ts +1 -0
- package/dist-native/__tests__/BatcherPublic.js +82 -0
- package/dist-native/__tests__/Deduplicator.d.ts +1 -0
- package/dist-native/__tests__/Deduplicator.js +111 -0
- package/dist-native/__tests__/InstallationId.d.ts +1 -0
- package/dist-native/__tests__/InstallationId.js +40 -0
- package/dist-native/__tests__/NetworkCallsHandler.d.ts +1 -0
- package/dist-native/__tests__/NetworkCallsHandler.js +135 -0
- package/dist-native/__tests__/Parsing.d.ts +1 -0
- package/dist-native/__tests__/Parsing.js +174 -0
- package/dist-native/__tests__/Sessions.d.ts +1 -0
- package/dist-native/__tests__/Sessions.js +179 -0
- package/dist-native/__tests__/Storage.d.ts +1 -0
- package/dist-native/__tests__/Storage.js +173 -0
- package/dist-native/__tests__/constants.d.ts +36 -0
- package/dist-native/__tests__/constants.js +47 -0
- package/dist-native/index.d.ts +2 -0
- package/dist-native/index.js +7 -0
- package/dist-native/utils.d.ts +3 -0
- package/dist-native/utils.js +42 -0
- package/package.json +14 -13
- package/.cache/09/18f5747b8308b0668b57dbe0154ab2.json +0 -1
- package/.cache/0d/2d21007ec7549e0a06c7bd662eeeb9.json +0 -1
- package/.cache/22/eee3664ac508c6144f86dc284c71ea.json +0 -1
- package/.cache/35/cefb6a47ec637299d7e622654ffb6f.json +0 -1
- package/.cache/39/f8cb614eabb2724b53c84803cd11ca.json +0 -1
- package/.cache/45/4f89ce2193890bb9565478ff11eb62.json +0 -1
- package/.cache/74/4a5a54e5bfd162df26d1cb8fdd908b.json +0 -1
- package/.cache/95/477acb3d9bccf1d5a810d32f9d97f7.json +0 -1
- package/.cache/a7/d33f3e58a7d7304b1a94ebb361aa3d.json +0 -1
- package/.cache/b2/3a12b6483c7e57c6d0aaa2075f67ce.json +0 -1
- package/.cache/b3/519bd85a01e1a9d91cd9beb3868a10.json +0 -1
- package/.cache/c1/45b01792e2ef466b52a80a36149e7c.json +0 -1
- package/.cache/c7/a423aca9bb7be775cf8ea5516d84e8.json +0 -1
- package/.cache/f3/2d83490ca733c5619d610330f067ea.json +0 -1
- package/.cache/fc/1e415b8bb6a94f1645aa6a4716d43c.json +0 -1
- package/.vscode/tasks.json +0 -13
package/.vscode/launch.json
CHANGED
|
@@ -4,23 +4,12 @@
|
|
|
4
4
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
5
|
"version": "0.2.0",
|
|
6
6
|
"configurations": [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
7
|
{
|
|
11
|
-
"type": "
|
|
8
|
+
"type": "pwa-chrome",
|
|
12
9
|
"request": "launch",
|
|
13
|
-
"name": "
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"test", "--runInBand", "--no-cache", "--watchAll=false"
|
|
17
|
-
],
|
|
18
|
-
// "preLaunchTask": "build",
|
|
19
|
-
"console": "integratedTerminal",
|
|
20
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
21
|
-
"outFiles": [
|
|
22
|
-
"${workspaceRoot}/dist/**/*"
|
|
23
|
-
],
|
|
10
|
+
"name": "Launch Chrome against localhost",
|
|
11
|
+
"url": "http://localhost:8080",
|
|
12
|
+
"webRoot": "${workspaceFolder}"
|
|
24
13
|
}
|
|
25
14
|
]
|
|
26
15
|
}
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Avo documentation
|
|
6
6
|
|
|
7
7
|
This is a quick start guide.
|
|
8
|
-
For more information about the Inspector project please read [Avo documentation](https://www.avo.app/docs/inspector/sdk/
|
|
8
|
+
For more information about the Inspector project please read [Avo documentation](https://www.avo.app/docs/implementation/inspector/sdk/web).
|
|
9
9
|
|
|
10
10
|
# Installation
|
|
11
11
|
|
|
@@ -16,7 +16,9 @@ The library is distributed with npm
|
|
|
16
16
|
```
|
|
17
17
|
npm i avo-inspector
|
|
18
18
|
```
|
|
19
|
+
|
|
19
20
|
or
|
|
21
|
+
|
|
20
22
|
```
|
|
21
23
|
yarn add avo-inspector
|
|
22
24
|
```
|
|
@@ -29,11 +31,11 @@ Obtain the API key at [Avo.app](https://www.avo.app/welcome)
|
|
|
29
31
|
import * as Inspector from "avo-inspector";
|
|
30
32
|
|
|
31
33
|
let inspector = new Inspector.AvoInspector({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
apiKey: "your api key",
|
|
35
|
+
env: Inspector.AvoInspectorEnv.Dev,
|
|
36
|
+
version: "1.0.0",
|
|
37
|
+
appName: "My app",
|
|
38
|
+
});
|
|
37
39
|
```
|
|
38
40
|
|
|
39
41
|
# Enabling logs
|
|
@@ -44,10 +46,17 @@ Logs are enabled by default in the dev mode and disabled in prod mode.
|
|
|
44
46
|
inspector.enableLogging(true);
|
|
45
47
|
```
|
|
46
48
|
|
|
47
|
-
#
|
|
49
|
+
# Integrating with Avo Functions (Avo generated code)
|
|
50
|
+
|
|
51
|
+
The setup is lightweight and is covered [in this guide](https://www.avo.app/docs/implementation/start-using-inspector-with-avo-functions).
|
|
52
|
+
|
|
53
|
+
Every event sent with Avo Function after this integration will automatically be sent to the Avo Inspector.
|
|
54
|
+
|
|
55
|
+
# Sending event schemas for events reported outside of Avo Functions
|
|
48
56
|
|
|
49
57
|
Whenever you send tracking event call one of the following methods:
|
|
50
|
-
|
|
58
|
+
|
|
59
|
+
Read more in the [Avo documentation](https://www.avo.app/docs/implementation/devs-101#inspecting-events)
|
|
51
60
|
|
|
52
61
|
### 1.
|
|
53
62
|
|
|
@@ -56,10 +65,10 @@ It is the easiest way to use the library, just call this method at the same plac
|
|
|
56
65
|
|
|
57
66
|
```javascript
|
|
58
67
|
inspector.trackSchemaFromEvent("Event name", {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
"String Prop": "Prop Value",
|
|
69
|
+
"Float Prop": 1.0,
|
|
70
|
+
"Boolean Prop": true,
|
|
71
|
+
});
|
|
63
72
|
```
|
|
64
73
|
|
|
65
74
|
### 2.
|
|
@@ -68,21 +77,22 @@ If you prefer to extract data schema manually you would use this method.
|
|
|
68
77
|
|
|
69
78
|
```javascript
|
|
70
79
|
inspector.trackSchema("Event name", [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
{ propertyName: "String prop", propertyType: "string" },
|
|
81
|
+
{ propertyName: "Float prop", propertyType: "float" },
|
|
82
|
+
{ propertyName: "Boolean prop", propertyType: "boolean" },
|
|
83
|
+
]);
|
|
75
84
|
```
|
|
76
85
|
|
|
77
86
|
# Extracting event schema manually
|
|
78
87
|
|
|
79
88
|
```javascript
|
|
80
89
|
let schema = inspector.extractSchema({
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
"String Prop": "Prop Value",
|
|
91
|
+
"Float Prop": 1.0,
|
|
92
|
+
"Boolean Prop": true,
|
|
93
|
+
});
|
|
85
94
|
```
|
|
95
|
+
|
|
86
96
|
You can experiment with this method to see how more complex schemas look, for example with nested lists and objects.
|
|
87
97
|
|
|
88
98
|
# Batching control
|
|
@@ -90,7 +100,7 @@ You can experiment with this method to see how more complex schemas look, for ex
|
|
|
90
100
|
In order to ensure our SDK doesn't have a large impact on performance or battery life it supports event schemas batching.
|
|
91
101
|
|
|
92
102
|
Default batch size is 30 and default batch flush timeout is 30 seconds.
|
|
93
|
-
In development mode
|
|
103
|
+
In development mode batching is disabled.
|
|
94
104
|
|
|
95
105
|
```javascript
|
|
96
106
|
inspector.setBatchSize(15);
|
package/dist/AvoInspector.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class AvoInspector {
|
|
|
13
13
|
static avoStorage: AvoStorage;
|
|
14
14
|
private static _batchSize;
|
|
15
15
|
static get batchSize(): number;
|
|
16
|
+
static set batchSize(newSize: number);
|
|
16
17
|
private static _batchFlushSeconds;
|
|
17
18
|
static get batchFlushSeconds(): number;
|
|
18
19
|
private static _shouldLog;
|
|
@@ -23,6 +24,7 @@ export declare class AvoInspector {
|
|
|
23
24
|
env: AvoInspectorEnvValueType;
|
|
24
25
|
version: string;
|
|
25
26
|
appName?: string;
|
|
27
|
+
suffix?: string;
|
|
26
28
|
});
|
|
27
29
|
trackSchemaFromEvent(eventName: string, eventProperties: {
|
|
28
30
|
[propName: string]: any;
|
package/dist/AvoStorage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare abstract class PlatformAvoStorage {
|
|
2
|
-
abstract init(shouldLog: boolean): void;
|
|
2
|
+
abstract init(shouldLog: boolean, suffix: string): void;
|
|
3
3
|
abstract getItemAsync<T>(key: string): Promise<T | null>;
|
|
4
4
|
abstract getItem<T>(key: string): T | null;
|
|
5
5
|
abstract setItem<T>(key: string, value: T): void;
|
|
@@ -11,7 +11,7 @@ declare abstract class PlatformAvoStorage {
|
|
|
11
11
|
export declare class AvoStorage {
|
|
12
12
|
Platform: string | null;
|
|
13
13
|
storageImpl: PlatformAvoStorage;
|
|
14
|
-
constructor(shouldLog: boolean);
|
|
14
|
+
constructor(shouldLog: boolean, suffix?: string);
|
|
15
15
|
isInitialized(): boolean;
|
|
16
16
|
getItemAsync<T>(key: string): Promise<T | null>;
|
|
17
17
|
getItem<T>(key: string): T | null;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var n in s)("object"==typeof exports?exports:e)[n]=s[n]}}(window,(function(){return function(e){var t={};function s(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,s),o.l=!0,o.exports}return s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)s.d(n,o,function(t){return e[t]}.bind(null,o));return n},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=6)}([function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=s(2),o=s(3),r=s(4),i=s(7),a=s(8),l=s(10),c=s(11),u=s(5),h=s(12).version;class p{constructor(e){if(u.isValueEmpty(e.env)?(this.environment=n.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] No environment provided. Defaulting to dev.")):-1===Object.values(n.AvoInspectorEnv).indexOf(e.env)?(this.environment=n.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.")):this.environment=e.env,u.isValueEmpty(e.apiKey))throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");if(this.apiKey=e.apiKey,u.isValueEmpty(e.version))throw new Error("[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.");this.version=e.version,this.environment===n.AvoInspectorEnv.Dev?(p._batchFlushSeconds=1,p._shouldLog=!0):(p._batchFlushSeconds=30,p._shouldLog=!1),p.avoStorage=new l.AvoStorage(p._shouldLog);let t=new a.AvoNetworkCallsHandler(this.apiKey,this.environment.toString(),e.appName||"",this.version,h);this.avoBatcher=new i.AvoBatcher(t),this.sessionTracker=new r.AvoSessionTracker(this.avoBatcher),this.avoDeduplicator=new c.AvoDeduplicator;try{"undefined"!=typeof window&&window.addEventListener("load",()=>{this.sessionTracker.startOrProlongSession(Date.now())},!1)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}}static get batchSize(){return this._batchSize}static get batchFlushSeconds(){return this._batchFlushSeconds}static get shouldLog(){return this._shouldLog}static set shouldLog(e){this._shouldLog=e}trackSchemaFromEvent(e,t){try{if(this.avoDeduplicator.shouldRegisterEvent(e,t,!1)){p.shouldLog&&console.log("Avo Inspector: supplied event "+e+" with params "+JSON.stringify(t));let s=this.extractSchema(t,!1);return this.trackSchemaInternal(e,s,null,null),s}return p.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+e),[]}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}}_avoFunctionTrackSchemaFromEvent(e,t,s,n){try{if(this.avoDeduplicator.shouldRegisterEvent(e,t,!0)){p.shouldLog&&console.log("Avo Inspector: supplied event "+e+" with params "+JSON.stringify(t));let o=this.extractSchema(t,!1);return this.trackSchemaInternal(e,o,s,n),o}return p.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+e),[]}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}}trackSchema(e,t){try{this.avoDeduplicator.shouldRegisterSchemaFromManually(e,t)?(p.shouldLog&&console.log("Avo Inspector: supplied event "+e+" with schema "+JSON.stringify(t)),this.trackSchemaInternal(e,t,null,null)):p.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+e)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}}trackSchemaInternal(e,t,s,n){try{this.sessionTracker.startOrProlongSession(Date.now()),this.avoBatcher.handleTrackSchema(e,t,s,n)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}}enableLogging(e){p._shouldLog=e}extractSchema(e,t=!0){try{return this.sessionTracker.startOrProlongSession(Date.now()),this.avoDeduplicator.hasSeenEventParams(e,!0)&&t&&p.shouldLog&&console.warn("Avo Inspector: WARNING! You are trying to extract schema shape that was just reported by your Avo functions. This is an indicator of duplicate inspector reporting. Please reach out to support@avo.app for advice if you are not sure how to handle this."),p.shouldLog&&console.log("Avo Inspector: extracting schema from "+JSON.stringify(e)),o.AvoSchemaParser.extractSchema(e)}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}}setBatchSize(e){p._batchSize=e}setBatchFlushSeconds(e){p._batchFlushSeconds=e}}t.AvoInspector=p,p._batchSize=30,p._batchFlushSeconds=30,p._shouldLog=!1},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{static newGuid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv={Prod:"prod",Dev:"dev",Staging:"staging"}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});let n=e=>"[object Array]"===Object.prototype.toString.call(e);t.AvoSchemaParser=class{static extractSchema(e){if(null==e)return[];let t=e=>{if(n(e)){let s=e.map(e=>t(e));return this.removeDuplicates(s)}if("object"==typeof e){let n=[];for(var s in e)if(e.hasOwnProperty(s)){let o=e[s],r={propertyName:s,propertyType:this.getPropValueType(o)};"object"==typeof o&&null!=o&&(r.children=t(o)),n.push(r)}return n}return this.getPropValueType(e)};return t(e)}static removeDuplicates(e){var t={boolean:{},number:{},string:{}},s=[];return e.filter(e=>{var n=typeof e;return n in t?!t[n].hasOwnProperty(e)&&(t[n][e]=!0):!(s.indexOf(e)>=0)&&s.push(e)})}static getPropValueType(e){let t=typeof e;return null==e?"null":"string"===t?"string":"number"===t||"bigint"===t?(e+"").indexOf(".")>=0?"float":"int":"boolean"===t?"boolean":"object"===t?n(e)?"list":"object":"unknown"}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=s(1),o=s(0);class r{constructor(e){this._lastSessionTimestamp=null,this._sessionLengthMillis=3e5,this.avoBatcher=e}static get sessionId(){if(null===r._sessionId){if(!o.AvoInspector.avoStorage.isInitialized())return"unknown";let e=null;try{e=o.AvoInspector.avoStorage.getItem(r.idCacheKey)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}r._sessionId=null==e?this.updateSessionId():e}return r._sessionId}get lastSessionTimestamp(){if(null===this._lastSessionTimestamp||0===this._lastSessionTimestamp){let e=o.AvoInspector.avoStorage.getItem(r.lastSessionTimestampKey);null!=e?(this._lastSessionTimestamp=e,isNaN(this._lastSessionTimestamp)&&(this._lastSessionTimestamp=0)):this._lastSessionTimestamp=0}return this._lastSessionTimestamp}get sessionLengthMillis(){return this._sessionLengthMillis}startOrProlongSession(e){o.AvoInspector.avoStorage.runAfterInit(()=>{e-this.lastSessionTimestamp>this._sessionLengthMillis&&(r.updateSessionId(),this.avoBatcher.handleSessionStarted()),this._lastSessionTimestamp=e,o.AvoInspector.avoStorage.setItem(r.lastSessionTimestampKey,this._lastSessionTimestamp)})}static updateSessionId(){r._sessionId=n.default.newGuid();try{o.AvoInspector.avoStorage.setItem(r.idCacheKey,r.sessionId)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}return r._sessionId}static get lastSessionTimestampKey(){return"AvoInspectorSessionTimestamp"}static get idCacheKey(){return"AvoInspectorSessionId"}}t.AvoSessionTracker=r,r._sessionId=null},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.isValueEmpty=e=>null==e||0==e.trim().length,t.deepEquals=function e(t,s){if(t===s)return!0;if(!(t instanceof Object&&s instanceof Object))return!1;if(t.constructor!==s.constructor)return!1;for(var n in t)if(t.hasOwnProperty(n)){if(!s.hasOwnProperty(n))return!1;if(t[n]!==s[n]){if("object"!=typeof t[n])return!1;if(!e(t[n],s[n]))return!1}}for(n in s)if(s.hasOwnProperty(n)&&!t.hasOwnProperty(n))return!1;return!0}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=s(0);t.AvoInspector=n.AvoInspector;var o=s(2);t.AvoInspectorEnv=o.AvoInspectorEnv},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=s(0);class o{constructor(e){this.events=[],this.networkCallsHandler=e,this.batchFlushAttemptTimestamp=Date.now(),n.AvoInspector.avoStorage.getItemAsync(o.cacheKey).then(e=>{if(null!==e){let t=e.filter(e=>null!==e);this.events=this.events.concat(t),this.checkIfBatchNeedsToBeSent()}})}handleSessionStarted(){this.events.push(this.networkCallsHandler.bodyForSessionStartedCall()),this.saveEvents(),this.checkIfBatchNeedsToBeSent()}handleTrackSchema(e,t,s,o){this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(e,t,s,o)),this.saveEvents(),n.AvoInspector.shouldLog&&console.log("Avo Inspector: saved event "+e+" with schema "+JSON.stringify(t)),this.checkIfBatchNeedsToBeSent()}checkIfBatchNeedsToBeSent(){const e=this.events.length,t=Date.now(),s=t-this.batchFlushAttemptTimestamp,o=e%n.AvoInspector.batchSize==0,r=s>=1e3*n.AvoInspector.batchFlushSeconds,i=this;if(o||r){this.batchFlushAttemptTimestamp=t;const e=i.events;i.events=[],this.networkCallsHandler.callInspectorWithBatchBody(e,(function(t){null!=t?(i.events=i.events.concat(e),n.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sending failed: "+t+". We will attempt to send your schemas with next batch")):n.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sent successfully."),i.saveEvents()}))}}saveEvents(){if(this.events.length>1e3){const e=this.events.length-1e3;this.events.splice(0,e)}n.AvoInspector.avoStorage.setItem(o.cacheKey,this.events)}static get cacheKey(){return"AvoInspectorEvents"}}t.AvoBatcher=o},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=s(1),o=s(4),r=s(0),i=s(9);class a{constructor(e,t,s,n,o){this.samplingRate=1,this.sending=!1,this.apiKey=e,this.envName=t,this.appName=s,this.appVersion=n,this.libVersion=o}callInspectorWithBatchBody(e,t){if(this.sending)return void t("Batch sending cancelled because another batch sending is in progress. Your events will be sent with next batch.");const s=e.filter(e=>null!=e);if(this.fixSessionAndTrackingIds(s),0===s.length)return;if(Math.random()>this.samplingRate)return void(r.AvoInspector.shouldLog&&console.log("Avo Inspector: last event schema dropped due to sampling rate."));r.AvoInspector.shouldLog&&(console.log("Avo Inspector: events",s),s.forEach((function(e){if("sessionStarted"===e.type)console.log("Avo Inspector: sending session started event.");else if("event"===e.type){let t=e;console.log("Avo Inspector: sending event "+t.eventName+" with schema "+JSON.stringify(t.eventProperties))}}))),this.sending=!0;let n=new XMLHttpRequest;n.open("POST",a.trackingEndpoint,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(JSON.stringify(s)),n.onload=()=>{if(200!=n.status)t(`Error ${n.status}: ${n.statusText}`);else{const e=JSON.parse(n.response).samplingRate;void 0!==e&&(this.samplingRate=e),t(null)}},n.onerror=()=>{t("Request failed")},n.ontimeout=()=>{t("Request timed out")},this.sending=!1}fixSessionAndTrackingIds(e){let t=null,s=null;e.forEach((function(e){null!==e.sessionId&&void 0!==e.sessionId&&"unknown"!==e.sessionId&&(t=e.sessionId),null!==e.trackingId&&void 0!==e.trackingId&&"unknown"!==e.trackingId&&(s=e.trackingId)})),e.forEach((function(e){"unknown"===e.sessionId&&(e.sessionId=null!=t?t:o.AvoSessionTracker.sessionId),"unknown"===e.trackingId&&(e.trackingId=null!=s?s:i.AvoInstallationId.getInstallationId())}))}bodyForSessionStartedCall(){let e=this.createBaseCallBody();return e.type="sessionStarted",e}bodyForEventSchemaCall(e,t,s,n){let o=this.createBaseCallBody();return o.type="event",o.eventName=e,o.eventProperties=t,null!=s?(o.avoFunction=!0,o.eventId=s,o.eventHash=n):(o.avoFunction=!1,o.eventId=null,o.eventHash=null),o}createBaseCallBody(){return{apiKey:this.apiKey,appName:this.appName,appVersion:this.appVersion,libVersion:this.libVersion,env:this.envName,libPlatform:"web",messageId:n.default.newGuid(),trackingId:i.AvoInstallationId.getInstallationId(),createdAt:(new Date).toISOString(),sessionId:o.AvoSessionTracker.sessionId,samplingRate:this.samplingRate}}}t.AvoNetworkCallsHandler=a,a.trackingEndpoint="https://api.avo.app/inspector/v1/track"},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=s(1),o=s(0);class r{static getInstallationId(){if(null!==r.installationId)return r.installationId;if(!o.AvoInspector.avoStorage.isInitialized())return"unknown";let e=o.AvoInspector.avoStorage.getItem(r.cacheKey);return null==e?(r.installationId=n.default.newGuid(),o.AvoInspector.avoStorage.setItem(r.cacheKey,r.installationId)):r.installationId=e,r.installationId}static get cacheKey(){return"AvoInstallationId"}}t.AvoInstallationId=r,r.installationId=null},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class n{parseJson(e){return null!=e?JSON.parse(e):null}}class o extends n{constructor(){super(...arguments),this.useFallbackStorage=!1,this.fallbackStorage={},this.storageInitialized=!1,this.onStorageInitFuncs=[],this.shouldLog=!1}init(e){this.shouldLog=e,this.initializeStorageWeb(this.isLocalStorageAvailable())}initializeStorageWeb(e){this.storageInitialized=!0,!1===e&&(this.useFallbackStorage=!0),this.onStorageInitFuncs.forEach(e=>{e()})}isLocalStorageAvailable(){const e=(new Date).toISOString();try{return window.localStorage.setItem(e,e),window.localStorage.getItem(e)===e&&(window.localStorage.removeItem(e),!0)}catch(e){return!1}}isInitialized(){return this.storageInitialized}getItemAsync(e){let t=this;return new Promise((function(s,n){t.runAfterInit(()=>{if(!0===t.useFallbackStorage){let n=t.fallbackStorage[e];s(t.parseJson(n))}else if("undefined"!=typeof window){let n;try{n=window.localStorage.getItem(e)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage getItemAsync error:",e),s(null)}s(t.parseJson(n))}else s(null)})}))}getItem(e){let t;if(!1===this.storageInitialized)t=null;else if(!0===this.useFallbackStorage)t=this.fallbackStorage[e];else if("undefined"!=typeof window)try{t=window.localStorage.getItem(e)}catch(e){this.shouldLog&&console.error("Avo Inspector Storage getItem error:",e)}return this.parseJson(t)}setItem(e,t){this.runAfterInit(()=>{if(!0===this.useFallbackStorage)this.fallbackStorage[e]=JSON.stringify(t);else if("undefined"!=typeof window)try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){this.shouldLog&&console.error("Avo Inspector Storage setItem error:",e)}})}removeItem(e){this.runAfterInit(()=>{if(!0===this.useFallbackStorage)this.fallbackStorage[e]=null;else if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){this.shouldLog&&console.error("Avo Inspector Storage removeItem error:",e)}})}runAfterInit(e){!0===this.storageInitialized?e():this.onStorageInitFuncs.push(e)}}t.AvoStorage=class{constructor(e){this.Platform=null,this.Platform="browser",this.storageImpl=new o,this.storageImpl.init(e)}isInitialized(){return this.storageImpl.isInitialized()}getItemAsync(e){return this.storageImpl.getItemAsync(e)}getItem(e){return this.storageImpl.getItem(e)}setItem(e,t){this.storageImpl.setItem(e,t)}removeItem(e){this.storageImpl.removeItem(e)}runAfterInit(e){this.storageImpl.runAfterInit(e)}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=s(3),o=s(5);t.AvoDeduplicator=class{constructor(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}}shouldRegisterEvent(e,t,s){this.clearOldEvents(),s?(this.avoFunctionsEvents[Date.now()]=e,this.avoFunctionsEventsParams[e]=t):(this.manualEvents[Date.now()]=e,this.manualEventsParams[e]=t);let n=!s;return!this.hasSameEventAs(e,t,n)}hasSameEventAs(e,t,s){let n=!1;return s?this.lookForEventIn(e,t,this.avoFunctionsEventsParams)&&(n=!0):this.lookForEventIn(e,t,this.manualEventsParams)&&(n=!0),n&&(delete this.avoFunctionsEventsParams[e],delete this.manualEventsParams[e]),n}lookForEventIn(e,t,s){for(const n in s)if(s.hasOwnProperty(n)&&n===e){const n=s[e];if(n&&o.deepEquals(t,n))return!0}return!1}hasSeenEventParams(e,t){let s=!1;return t?this.lookForEventParamsIn(e,this.avoFunctionsEventsParams)&&(s=!0):this.lookForEventParamsIn(e,this.manualEventsParams)&&(s=!0),s}lookForEventParamsIn(e,t){for(const s in t)if(t.hasOwnProperty(s)){const n=t[s];if(n&&o.deepEquals(e,n))return!0}return!1}shouldRegisterSchemaFromManually(e,t){return this.clearOldEvents(),!this.hasSameShapeInAvoFunctionsAs(e,t)}hasSameShapeInAvoFunctionsAs(e,t){let s=!1;return this.lookForEventSchemaIn(e,t,this.avoFunctionsEventsParams)&&(s=!0),s&&delete this.avoFunctionsEventsParams[e],s}lookForEventSchemaIn(e,t,s){for(const r in s)if(s.hasOwnProperty(r)&&r===e){const r=n.AvoSchemaParser.extractSchema(s[e]);if(r&&o.deepEquals(t,r))return!0}return!1}clearOldEvents(){const e=Date.now();for(const t in this.avoFunctionsEvents)if(this.avoFunctionsEvents.hasOwnProperty(t)){if(e-(Number(t)||0)>300){const e=this.avoFunctionsEvents[t];delete this.avoFunctionsEvents[t],delete this.avoFunctionsEventsParams[e]}}for(const t in this.manualEvents)if(this.manualEvents.hasOwnProperty(t)){if(e-(Number(t)||0)>300){const e=this.manualEvents[t];delete this.manualEvents[t],delete this.manualEventsParams[e]}}}_clearEvents(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}}}},function(e){e.exports=JSON.parse('{"name":"avo-inspector","version":"1.2.4","description":"","main":"dist/index.js","browser":"dist/index.js","react-native":"dist-native/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc --emitDeclarationOnly && webpack src/index.ts --mode production --resolve-extensions .ts --module-bind ts=ts-loader --define process.env.BROWSER=1 --output-filename index.js --output-library-target umd","build-native":"tsc --outDir dist-native","test":"jest","test:browser":"BROWSER=1 jest","typecheck":"tsc --noEmit"},"repository":{"type":"git","url":"git+https://github.com/avohq/web-avo-inspector.git"},"jest":{"transform":{"^.+\\\\.[j]sx?$":"babel-jest","^.+\\\\.[t]sx?$":"ts-jest"},"testPathIgnorePatterns":["constants","examples","node_modules","dist","dist-native"],"testRegex":"(/__tests__/.*|\\\\.(test|spec))\\\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js"]},"keywords":["web","analytics","avo","react","react-native","node","javascript"],"author":"Avo (https://www.avo.app)","license":"MIT","bugs":{"url":"https://github.com/avohq/web-avo-inspector/issues"},"homepage":"https://github.com/avohq/web-avo-inspector#readme","devDependencies":{"@babel/core":"7.10.4","@babel/preset-env":"7.10.4","@types/jest":"25.2.1","@types/node":"13.13.5","babel-preset-es2015":"6.24.1","babel-preset-react":"6.24.1","eslint":"6.8.0","eslint-plugin-react":"7.18.0","jest":"25.4.0","prettier":"2.0.5","prettier-eslint":"9.0.1","ts-jest":"25.4.0","ts-loader":"8.0.4","typescript":"3.8.3","webpack":"4.44.2","webpack-cli":"3.3.12"},"externals":["react-native"]}')}])}));
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspector=void 0;var o=n(2),r=n(3),s=n(4),i=n(7),a=n(8),c=n(10),u=n(11),l=n(5),p=n(12).version,v=function(){function e(t){var n=this;if(l.isValueEmpty(t.env)?(this.environment=o.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] No environment provided. Defaulting to dev.")):-1===Object.values(o.AvoInspectorEnv).indexOf(t.env)?(this.environment=o.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.")):this.environment=t.env,l.isValueEmpty(t.apiKey))throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");if(this.apiKey=t.apiKey,l.isValueEmpty(t.version))throw new Error("[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.");this.version=t.version,this.environment===o.AvoInspectorEnv.Dev?(e._batchSize=1,e._shouldLog=!0):(e._batchSize=30,e._batchFlushSeconds=30,e._shouldLog=!1),e.avoStorage=new c.AvoStorage(e._shouldLog,null!=t.suffix?t.suffix:"");var r=new a.AvoNetworkCallsHandler(this.apiKey,this.environment.toString(),t.appName||"",this.version,p);this.avoBatcher=new i.AvoBatcher(r),this.sessionTracker=new s.AvoSessionTracker(this.avoBatcher),this.avoDeduplicator=new u.AvoDeduplicator;try{"undefined"!=typeof window&&window.addEventListener("load",(function(){n.sessionTracker.startOrProlongSession(Date.now())}),!1)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}}return Object.defineProperty(e,"batchSize",{get:function(){return this._batchSize},set:function(e){this._batchSize=e<1?1:e},enumerable:!1,configurable:!0}),Object.defineProperty(e,"batchFlushSeconds",{get:function(){return this._batchFlushSeconds},enumerable:!1,configurable:!0}),Object.defineProperty(e,"shouldLog",{get:function(){return this._shouldLog},set:function(e){this._shouldLog=e},enumerable:!1,configurable:!0}),e.prototype.trackSchemaFromEvent=function(t,n){try{if(this.avoDeduplicator.shouldRegisterEvent(t,n,!1)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(n));var o=this.extractSchema(n,!1);return this.trackSchemaInternal(t,o,null,null),o}return e.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+t),[]}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}},e.prototype._avoFunctionTrackSchemaFromEvent=function(t,n,o,r){try{if(this.avoDeduplicator.shouldRegisterEvent(t,n,!0)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(n));var s=this.extractSchema(n,!1);return this.trackSchemaInternal(t,s,o,r),s}return e.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+t),[]}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}},e.prototype.trackSchema=function(t,n){try{this.avoDeduplicator.shouldRegisterSchemaFromManually(t,n)?(e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with schema "+JSON.stringify(n)),this.trackSchemaInternal(t,n,null,null)):e.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+t)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}},e.prototype.trackSchemaInternal=function(e,t,n,o){try{this.sessionTracker.startOrProlongSession(Date.now()),this.avoBatcher.handleTrackSchema(e,t,n,o)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}},e.prototype.enableLogging=function(t){e._shouldLog=t},e.prototype.extractSchema=function(t,n){void 0===n&&(n=!0);try{return this.sessionTracker.startOrProlongSession(Date.now()),this.avoDeduplicator.hasSeenEventParams(t,!0)&&n&&e.shouldLog&&console.warn("Avo Inspector: WARNING! You are trying to extract schema shape that was just reported by your Avo functions. This is an indicator of duplicate inspector reporting. Please reach out to support@avo.app for advice if you are not sure how to handle this."),e.shouldLog&&console.log("Avo Inspector: extracting schema from "+JSON.stringify(t)),r.AvoSchemaParser.extractSchema(t)}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}},e.prototype.setBatchSize=function(t){e._batchSize=t},e.prototype.setBatchFlushSeconds=function(t){e._batchFlushSeconds=t},e._batchSize=30,e._batchFlushSeconds=30,e._shouldLog=!1,e}();t.AvoInspector=v},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(){}return e.newGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},e}();t.default=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv=void 0,t.AvoInspectorEnv={Prod:"prod",Dev:"dev",Staging:"staging"}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoSchemaParser=void 0;var o=function(e){return"[object Array]"===Object.prototype.toString.call(e)},r=function(){function e(){}return e.extractSchema=function(e){var t=this;if(null==e)return[];var n=function(e){if(o(e)){var r=e.map((function(e){return n(e)}));return t.removeDuplicates(r)}if("object"==typeof e){var s=[];for(var i in e)if(e.hasOwnProperty(i)){var a=e[i],c={propertyName:i,propertyType:t.getPropValueType(a)};"object"==typeof a&&null!=a&&(c.children=n(a)),s.push(c)}return s}return t.getPropValueType(e)};return n(e)},e.removeDuplicates=function(e){var t={boolean:{},number:{},string:{}},n=[];return e.filter((function(e){var o=typeof e;return o in t?!t[o].hasOwnProperty(e)&&(t[o][e]=!0):!(n.indexOf(e)>=0)&&n.push(e)}))},e.getPropValueType=function(e){var t=typeof e;return null==e?"null":"string"===t?"string":"number"===t||"bigint"===t?(e+"").indexOf(".")>=0?"float":"int":"boolean"===t?"boolean":"object"===t?o(e)?"list":"object":"unknown"},e}();t.AvoSchemaParser=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoSessionTracker=void 0;var o=n(1),r=n(0),s=function(){function e(e){this._lastSessionTimestamp=null,this._sessionLengthMillis=3e5,this.avoBatcher=e}return Object.defineProperty(e,"sessionId",{get:function(){if(null===e._sessionId){if(!r.AvoInspector.avoStorage.isInitialized())return"unknown";var t=null;try{t=r.AvoInspector.avoStorage.getItem(e.idCacheKey)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}e._sessionId=null==t?this.updateSessionId():t}return e._sessionId},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastSessionTimestamp",{get:function(){if(null===this._lastSessionTimestamp||0===this._lastSessionTimestamp){var t=r.AvoInspector.avoStorage.getItem(e.lastSessionTimestampKey);null!=t?(this._lastSessionTimestamp=t,isNaN(this._lastSessionTimestamp)&&(this._lastSessionTimestamp=0)):this._lastSessionTimestamp=0}return this._lastSessionTimestamp},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sessionLengthMillis",{get:function(){return this._sessionLengthMillis},enumerable:!1,configurable:!0}),e.prototype.startOrProlongSession=function(t){var n=this;r.AvoInspector.avoStorage.runAfterInit((function(){t-n.lastSessionTimestamp>n._sessionLengthMillis&&(e.updateSessionId(),n.avoBatcher.handleSessionStarted()),n._lastSessionTimestamp=t,r.AvoInspector.avoStorage.setItem(e.lastSessionTimestampKey,n._lastSessionTimestamp)}))},e.updateSessionId=function(){e._sessionId=o.default.newGuid();try{r.AvoInspector.avoStorage.setItem(e.idCacheKey,e.sessionId)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}return e._sessionId},Object.defineProperty(e,"lastSessionTimestampKey",{get:function(){return"AvoInspectorSessionTimestamp"},enumerable:!1,configurable:!0}),Object.defineProperty(e,"idCacheKey",{get:function(){return"AvoInspectorSessionId"},enumerable:!1,configurable:!0}),e._sessionId=null,e}();t.AvoSessionTracker=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.deepEquals=t.isValueEmpty=void 0;t.isValueEmpty=function(e){return null==e||0==e.trim().length},t.deepEquals=function e(t,n){if(t===n)return!0;if(!(t instanceof Object&&n instanceof Object))return!1;if(t.constructor!==n.constructor)return!1;for(var o in t)if(t.hasOwnProperty(o)){if(!n.hasOwnProperty(o))return!1;if(t[o]!==n[o]){if("object"!=typeof t[o])return!1;if(!e(t[o],n[o]))return!1}}for(o in n)if(n.hasOwnProperty(o)&&!t.hasOwnProperty(o))return!1;return!0}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv=t.AvoInspector=void 0;var o=n(0);Object.defineProperty(t,"AvoInspector",{enumerable:!0,get:function(){return o.AvoInspector}});var r=n(2);Object.defineProperty(t,"AvoInspectorEnv",{enumerable:!0,get:function(){return r.AvoInspectorEnv}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoBatcher=void 0;var o=n(0),r=function(){function e(t){var n=this;this.events=[],this.networkCallsHandler=t,this.batchFlushAttemptTimestamp=Date.now(),o.AvoInspector.avoStorage.getItemAsync(e.cacheKey).then((function(e){if(null!==e){var t=e.filter((function(e){return null!==e}));n.events=n.events.concat(t),n.checkIfBatchNeedsToBeSent()}}))}return e.prototype.handleSessionStarted=function(){this.events.push(this.networkCallsHandler.bodyForSessionStartedCall()),this.saveEvents(),this.checkIfBatchNeedsToBeSent()},e.prototype.handleTrackSchema=function(e,t,n,r){this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(e,t,n,r)),this.saveEvents(),o.AvoInspector.shouldLog&&console.log("Avo Inspector: saved event "+e+" with schema "+JSON.stringify(t)),this.checkIfBatchNeedsToBeSent()},e.prototype.checkIfBatchNeedsToBeSent=function(){var e=this.events.length,t=Date.now(),n=t-this.batchFlushAttemptTimestamp,r=e%o.AvoInspector.batchSize==0,s=n>=1e3*o.AvoInspector.batchFlushSeconds,i=this;if(r||s){this.batchFlushAttemptTimestamp=t;var a=i.events;i.events=[],this.networkCallsHandler.callInspectorWithBatchBody(a,(function(e){null!=e?(i.events=i.events.concat(a),o.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sending failed: "+e+". We will attempt to send your schemas with next batch")):o.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sent successfully."),i.saveEvents()}))}},e.prototype.saveEvents=function(){if(this.events.length>1e3){var t=this.events.length-1e3;this.events.splice(0,t)}o.AvoInspector.avoStorage.setItem(e.cacheKey,this.events)},Object.defineProperty(e,"cacheKey",{get:function(){return"AvoInspectorEvents"},enumerable:!1,configurable:!0}),e}();t.AvoBatcher=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoNetworkCallsHandler=void 0;var o=n(1),r=n(4),s=n(0),i=n(9),a=function(){function e(e,t,n,o,r){this.samplingRate=1,this.sending=!1,this.apiKey=e,this.envName=t,this.appName=n,this.appVersion=o,this.libVersion=r}return e.prototype.callInspectorWithBatchBody=function(t,n){var o=this;if(this.sending)n("Batch sending cancelled because another batch sending is in progress. Your events will be sent with next batch.");else{var r=t.filter((function(e){return null!=e}));if(this.fixSessionAndTrackingIds(r),0!==r.length)if(Math.random()>this.samplingRate)s.AvoInspector.shouldLog&&console.log("Avo Inspector: last event schema dropped due to sampling rate.");else{s.AvoInspector.shouldLog&&(console.log("Avo Inspector: events",r),r.forEach((function(e){if("sessionStarted"===e.type)console.log("Avo Inspector: sending session started event.");else if("event"===e.type){var t=e;console.log("Avo Inspector: sending event "+t.eventName+" with schema "+JSON.stringify(t.eventProperties))}}))),this.sending=!0;var i=new XMLHttpRequest;i.open("POST",e.trackingEndpoint,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(r)),i.onload=function(){if(200!=i.status)n("Error "+i.status+": "+i.statusText);else{var e=JSON.parse(i.response).samplingRate;void 0!==e&&(o.samplingRate=e),n(null)}},i.onerror=function(){n("Request failed")},i.ontimeout=function(){n("Request timed out")},this.sending=!1}}},e.prototype.fixSessionAndTrackingIds=function(e){var t=null,n=null;e.forEach((function(e){null!==e.sessionId&&void 0!==e.sessionId&&"unknown"!==e.sessionId&&(t=e.sessionId),null!==e.trackingId&&void 0!==e.trackingId&&"unknown"!==e.trackingId&&(n=e.trackingId)})),e.forEach((function(e){"unknown"===e.sessionId&&(e.sessionId=null!=t?t:r.AvoSessionTracker.sessionId),"unknown"===e.trackingId&&(e.trackingId=null!=n?n:i.AvoInstallationId.getInstallationId())}))},e.prototype.bodyForSessionStartedCall=function(){var e=this.createBaseCallBody();return e.type="sessionStarted",e},e.prototype.bodyForEventSchemaCall=function(e,t,n,o){var r=this.createBaseCallBody();return r.type="event",r.eventName=e,r.eventProperties=t,null!=n?(r.avoFunction=!0,r.eventId=n,r.eventHash=o):(r.avoFunction=!1,r.eventId=null,r.eventHash=null),r},e.prototype.createBaseCallBody=function(){return{apiKey:this.apiKey,appName:this.appName,appVersion:this.appVersion,libVersion:this.libVersion,env:this.envName,libPlatform:"web",messageId:o.default.newGuid(),trackingId:i.AvoInstallationId.getInstallationId(),createdAt:(new Date).toISOString(),sessionId:r.AvoSessionTracker.sessionId,samplingRate:this.samplingRate}},e.trackingEndpoint="https://api.avo.app/inspector/v1/track",e}();t.AvoNetworkCallsHandler=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInstallationId=void 0;var o=n(1),r=n(0),s=function(){function e(){}return e.getInstallationId=function(){if(null!==e.installationId)return e.installationId;if(!r.AvoInspector.avoStorage.isInitialized())return"unknown";var t=r.AvoInspector.avoStorage.getItem(e.cacheKey);return null==t?(e.installationId=o.default.newGuid(),r.AvoInspector.avoStorage.setItem(e.cacheKey,e.installationId)):e.installationId=t,e.installationId},Object.defineProperty(e,"cacheKey",{get:function(){return"AvoInstallationId"},enumerable:!1,configurable:!0}),e.installationId=null,e}();t.AvoInstallationId=s},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.AvoStorage=void 0;var s=function(){function e(){}return e.prototype.parseJson=function(e){return null!=e?JSON.parse(e):null},e}(),i=(function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.androidMemoryDataToAvoidAsyncQueries={},t.AsyncStorage=null,t.memoryStorageInitialized=!1,t.onStorageInitFuncs=[],t.reactNative=null,t.shouldLog=!1,t.suffix="",t}r(t,e),t.prototype.init=function(e,t){},t.prototype.loadAndroidDataToMemoryToAvoidAsyncQueries=function(e){var t=this;this.AsyncStorage.getAllKeys().then((function(n){return t.AsyncStorage.multiGet(n).then((function(n){t.shouldLog&&console.log("Avo Inspector: android loaded data from memory"),n.forEach((function(e){var n=e[0];n.endsWith(t.suffix)&&(t.androidMemoryDataToAvoidAsyncQueries[n]=e[1],t.shouldLog&&console.log(n,e[1]))})),e()}))}))},t.prototype.initializeStorageAndroid=function(){this.memoryStorageInitialized=!0,this.onStorageInitFuncs.forEach((function(e){e()}))},t.prototype.isInitialized=function(){return this.reactNative&&this.memoryStorageInitialized},t.prototype.getItemAsync=function(e){return this.AsyncStorage.getItem(e+this.suffix).then((function(e){return null!=e?JSON.parse(e):null}))},t.prototype.getItem=function(e){var t=this.androidMemoryDataToAvoidAsyncQueries[e+this.suffix];return this.parseJson(t)},t.prototype.setItem=function(e,t){this.AsyncStorage.setItem(e+this.suffix,JSON.stringify(t)),this.androidMemoryDataToAvoidAsyncQueries[e+this.suffix]=JSON.stringify(t)},t.prototype.removeItem=function(e){this.AsyncStorage.removeItem(e+this.suffix),this.androidMemoryDataToAvoidAsyncQueries[e+this.suffix]=null},t.prototype.runAfterInit=function(e){!0===this.memoryStorageInitialized?e():this.onStorageInitFuncs.push(e)}}(s),function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.reactNative=null,t.suffix="",t}r(t,e),t.prototype.init=function(e,t){0},t.prototype.isInitialized=function(){return null!=this.reactNative},t.prototype.getItemAsync=function(e){var t=this.reactNative.Settings.get(e+this.suffix);return Promise.resolve(this.parseJson(t))},t.prototype.getItem=function(e){var t=this.reactNative.Settings.get(e+this.suffix);return this.parseJson(t)},t.prototype.setItem=function(e,t){var n;this.reactNative.Settings.set(((n={})[e+this.suffix]=JSON.stringify(t),n))},t.prototype.removeItem=function(e){var t;this.reactNative.Settings.set(((t={})[e+this.suffix]=null,t))},t.prototype.runAfterInit=function(e){e()}}(s),function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.useFallbackStorage=!1,t.fallbackStorage={},t.storageInitialized=!1,t.onStorageInitFuncs=[],t.shouldLog=!1,t.suffix="",t}return r(t,e),t.prototype.init=function(e,t){this.shouldLog=e,this.suffix=t,this.initializeStorageWeb(this.isLocalStorageAvailable())},t.prototype.initializeStorageWeb=function(e){this.storageInitialized=!0,!1===e&&(this.useFallbackStorage=!0),this.onStorageInitFuncs.forEach((function(e){e()}))},t.prototype.isLocalStorageAvailable=function(){var e=(new Date).toISOString();try{return window.localStorage.setItem(e,e),window.localStorage.getItem(e)===e&&(window.localStorage.removeItem(e),!0)}catch(e){return!1}},t.prototype.isInitialized=function(){return this.storageInitialized},t.prototype.getItemAsync=function(e){var t=this;return new Promise((function(n,o){t.runAfterInit((function(){if(!0===t.useFallbackStorage){var o=t.fallbackStorage[e+t.suffix];n(t.parseJson(o))}else if("undefined"!=typeof window){o=void 0;try{o=window.localStorage.getItem(e+t.suffix)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage getItemAsync error:",e),n(null)}n(t.parseJson(o))}else n(null)}))}))},t.prototype.getItem=function(e){var t;if(!1===this.storageInitialized)t=null;else if(!0===this.useFallbackStorage)t=this.fallbackStorage[e+this.suffix];else if("undefined"!=typeof window)try{t=window.localStorage.getItem(e+this.suffix)}catch(e){this.shouldLog&&console.error("Avo Inspector Storage getItem error:",e)}return this.parseJson(t)},t.prototype.setItem=function(e,t){var n=this;this.runAfterInit((function(){if(!0===n.useFallbackStorage)n.fallbackStorage[e+n.suffix]=JSON.stringify(t);else if("undefined"!=typeof window)try{window.localStorage.setItem(e+n.suffix,JSON.stringify(t))}catch(e){n.shouldLog&&console.error("Avo Inspector Storage setItem error:",e)}}))},t.prototype.removeItem=function(e){var t=this;this.runAfterInit((function(){if(!0===t.useFallbackStorage)t.fallbackStorage[e+t.suffix]=null;else if("undefined"!=typeof window)try{window.localStorage.removeItem(e+t.suffix)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage removeItem error:",e)}}))},t.prototype.runAfterInit=function(e){!0===this.storageInitialized?e():this.onStorageInitFuncs.push(e)},t}(s)),a=function(){function e(e,t){void 0===t&&(t=""),this.Platform=null,this.Platform="browser",this.storageImpl=new i,this.storageImpl.init(e,t)}return e.prototype.isInitialized=function(){return this.storageImpl.isInitialized()},e.prototype.getItemAsync=function(e){return this.storageImpl.getItemAsync(e)},e.prototype.getItem=function(e){return this.storageImpl.getItem(e)},e.prototype.setItem=function(e,t){this.storageImpl.setItem(e,t)},e.prototype.removeItem=function(e){this.storageImpl.removeItem(e)},e.prototype.runAfterInit=function(e){this.storageImpl.runAfterInit(e)},e}();t.AvoStorage=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoDeduplicator=void 0;var o=n(3),r=n(5),s=function(){function e(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}}return e.prototype.shouldRegisterEvent=function(e,t,n){this.clearOldEvents(),n?(this.avoFunctionsEvents[Date.now()]=e,this.avoFunctionsEventsParams[e]=t):(this.manualEvents[Date.now()]=e,this.manualEventsParams[e]=t);var o=!n;return!this.hasSameEventAs(e,t,o)},e.prototype.hasSameEventAs=function(e,t,n){var o=!1;return n?this.lookForEventIn(e,t,this.avoFunctionsEventsParams)&&(o=!0):this.lookForEventIn(e,t,this.manualEventsParams)&&(o=!0),o&&(delete this.avoFunctionsEventsParams[e],delete this.manualEventsParams[e]),o},e.prototype.lookForEventIn=function(e,t,n){for(var o in n)if(n.hasOwnProperty(o)&&o===e){var s=n[e];if(s&&r.deepEquals(t,s))return!0}return!1},e.prototype.hasSeenEventParams=function(e,t){var n=!1;return t?this.lookForEventParamsIn(e,this.avoFunctionsEventsParams)&&(n=!0):this.lookForEventParamsIn(e,this.manualEventsParams)&&(n=!0),n},e.prototype.lookForEventParamsIn=function(e,t){for(var n in t)if(t.hasOwnProperty(n)){var o=t[n];if(o&&r.deepEquals(e,o))return!0}return!1},e.prototype.shouldRegisterSchemaFromManually=function(e,t){return this.clearOldEvents(),!this.hasSameShapeInAvoFunctionsAs(e,t)},e.prototype.hasSameShapeInAvoFunctionsAs=function(e,t){var n=!1;return this.lookForEventSchemaIn(e,t,this.avoFunctionsEventsParams)&&(n=!0),n&&delete this.avoFunctionsEventsParams[e],n},e.prototype.lookForEventSchemaIn=function(e,t,n){for(var s in n)if(n.hasOwnProperty(s)&&s===e){var i=o.AvoSchemaParser.extractSchema(n[e]);if(i&&r.deepEquals(t,i))return!0}return!1},e.prototype.clearOldEvents=function(){var e=Date.now();for(var t in this.avoFunctionsEvents){if(this.avoFunctionsEvents.hasOwnProperty(t))if(e-(Number(t)||0)>300){var n=this.avoFunctionsEvents[t];delete this.avoFunctionsEvents[t],delete this.avoFunctionsEventsParams[n]}}for(var t in this.manualEvents){if(this.manualEvents.hasOwnProperty(t))if(e-(Number(t)||0)>300){n=this.manualEvents[t];delete this.manualEvents[t],delete this.manualEventsParams[n]}}},e.prototype._clearEvents=function(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}},e}();t.AvoDeduplicator=s},function(e){e.exports=JSON.parse('{"name":"avo-inspector","version":"1.3.0","description":"","main":"dist/index.js","browser":"dist/index.js","react-native":"dist-native/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc --emitDeclarationOnly && webpack src/index.ts --mode production --resolve-extensions .ts --module-bind ts=ts-loader --define process.env.BROWSER=1 --output-filename index.js --output-library-target umd","build-for-script-tag":"tsc --emitDeclarationOnly && webpack src/browser.js --mode production --resolve-extensions .ts --module-bind ts=ts-loader --define process.env.BROWSER=1 --woutput-filename browser.js --output-library-target umd","build-native":"tsc --outDir dist-native","test":"jest","test:browser":"BROWSER=1 jest","typecheck":"tsc --noEmit"},"repository":{"type":"git","url":"git+https://github.com/avohq/web-avo-inspector.git"},"jest":{"transform":{"^.+\\\\.[j]sx?$":"babel-jest","^.+\\\\.[t]sx?$":"ts-jest"},"testPathIgnorePatterns":["constants","examples","node_modules","dist","dist-native"],"testRegex":"(/__tests__/.*|\\\\.(test|spec))\\\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js"]},"keywords":["web","analytics","avo","react","react-native","node","javascript"],"author":"Avo (https://www.avo.app)","license":"MIT","bugs":{"url":"https://github.com/avohq/web-avo-inspector/issues"},"homepage":"https://github.com/avohq/web-avo-inspector#readme","devDependencies":{"@babel/core":"7.12.10","@babel/preset-env":"7.12.11","@types/jest":"26.0.19","@types/node":"14.14.16","babel-preset-es2015":"6.24.1","babel-preset-react":"6.24.1","eslint":"7.16.0","eslint-plugin-react":"7.21.5","jest":"26.6.3","prettier":"2.2.1","prettier-eslint":"12.0.0","ts-jest":"26.4.4","ts-loader":"8.0.12","typescript":"4.1.3","webpack":"4.44.2","webpack-cli":"3.3.12"},"externals":["react-native"]}')}])}));
|
package/dist/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(o,s,function(t){return e[t]}.bind(null,s));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspector=void 0;var o=n(6),s=n(2),r=n(3),i=n(7),a=n(8),c=n(10),u=n(11),l=n(4),p=n(12).version,v=function(){function e(t){var n=this;if(l.isValueEmpty(t.env)?(this.environment=o.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] No environment provided. Defaulting to dev.")):-1===Object.values(o.AvoInspectorEnv).indexOf(t.env)?(this.environment=o.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.")):this.environment=t.env,l.isValueEmpty(t.apiKey))throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");if(this.apiKey=t.apiKey,l.isValueEmpty(t.version))throw new Error("[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.");this.version=t.version,this.environment===o.AvoInspectorEnv.Dev?(e._batchSize=1,e._shouldLog=!0):(e._batchSize=30,e._batchFlushSeconds=30,e._shouldLog=!1),e.avoStorage=new c.AvoStorage(e._shouldLog,null!=t.suffix?t.suffix:"");var s=new a.AvoNetworkCallsHandler(this.apiKey,this.environment.toString(),t.appName||"",this.version,p);this.avoBatcher=new i.AvoBatcher(s),this.sessionTracker=new r.AvoSessionTracker(this.avoBatcher),this.avoDeduplicator=new u.AvoDeduplicator;try{"undefined"!=typeof window&&window.addEventListener("load",(function(){n.sessionTracker.startOrProlongSession(Date.now())}),!1)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}}return Object.defineProperty(e,"batchSize",{get:function(){return this._batchSize},set:function(e){this._batchSize=e<1?1:e},enumerable:!1,configurable:!0}),Object.defineProperty(e,"batchFlushSeconds",{get:function(){return this._batchFlushSeconds},enumerable:!1,configurable:!0}),Object.defineProperty(e,"shouldLog",{get:function(){return this._shouldLog},set:function(e){this._shouldLog=e},enumerable:!1,configurable:!0}),e.prototype.trackSchemaFromEvent=function(t,n){try{if(this.avoDeduplicator.shouldRegisterEvent(t,n,!1)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(n));var o=this.extractSchema(n,!1);return this.trackSchemaInternal(t,o,null,null),o}return e.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+t),[]}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}},e.prototype._avoFunctionTrackSchemaFromEvent=function(t,n,o,s){try{if(this.avoDeduplicator.shouldRegisterEvent(t,n,!0)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(n));var r=this.extractSchema(n,!1);return this.trackSchemaInternal(t,r,o,s),r}return e.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+t),[]}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}},e.prototype.trackSchema=function(t,n){try{this.avoDeduplicator.shouldRegisterSchemaFromManually(t,n)?(e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with schema "+JSON.stringify(n)),this.trackSchemaInternal(t,n,null,null)):e.shouldLog&&console.log("Avo Inspector: Deduplicated event: "+t)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}},e.prototype.trackSchemaInternal=function(e,t,n,o){try{this.sessionTracker.startOrProlongSession(Date.now()),this.avoBatcher.handleTrackSchema(e,t,n,o)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}},e.prototype.enableLogging=function(t){e._shouldLog=t},e.prototype.extractSchema=function(t,n){void 0===n&&(n=!0);try{return this.sessionTracker.startOrProlongSession(Date.now()),this.avoDeduplicator.hasSeenEventParams(t,!0)&&n&&e.shouldLog&&console.warn("Avo Inspector: WARNING! You are trying to extract schema shape that was just reported by your Avo functions. This is an indicator of duplicate inspector reporting. Please reach out to support@avo.app for advice if you are not sure how to handle this."),e.shouldLog&&console.log("Avo Inspector: extracting schema from "+JSON.stringify(t)),s.AvoSchemaParser.extractSchema(t)}catch(e){return console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e),[]}},e.prototype.setBatchSize=function(t){e._batchSize=t},e.prototype.setBatchFlushSeconds=function(t){e._batchFlushSeconds=t},e._batchSize=30,e._batchFlushSeconds=30,e._shouldLog=!1,e}();t.AvoInspector=v},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(){}return e.newGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},e}();t.default=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoSchemaParser=void 0;var o=function(e){return"[object Array]"===Object.prototype.toString.call(e)},s=function(){function e(){}return e.extractSchema=function(e){var t=this;if(null==e)return[];var n=function(e){if(o(e)){var s=e.map((function(e){return n(e)}));return t.removeDuplicates(s)}if("object"==typeof e){var r=[];for(var i in e)if(e.hasOwnProperty(i)){var a=e[i],c={propertyName:i,propertyType:t.getPropValueType(a)};"object"==typeof a&&null!=a&&(c.children=n(a)),r.push(c)}return r}return t.getPropValueType(e)};return n(e)},e.removeDuplicates=function(e){var t={boolean:{},number:{},string:{}},n=[];return e.filter((function(e){var o=typeof e;return o in t?!t[o].hasOwnProperty(e)&&(t[o][e]=!0):!(n.indexOf(e)>=0)&&n.push(e)}))},e.getPropValueType=function(e){var t=typeof e;return null==e?"null":"string"===t?"string":"number"===t||"bigint"===t?(e+"").indexOf(".")>=0?"float":"int":"boolean"===t?"boolean":"object"===t?o(e)?"list":"object":"unknown"},e}();t.AvoSchemaParser=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoSessionTracker=void 0;var o=n(1),s=n(0),r=function(){function e(e){this._lastSessionTimestamp=null,this._sessionLengthMillis=3e5,this.avoBatcher=e}return Object.defineProperty(e,"sessionId",{get:function(){if(null===e._sessionId){if(!s.AvoInspector.avoStorage.isInitialized())return"unknown";var t=null;try{t=s.AvoInspector.avoStorage.getItem(e.idCacheKey)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}e._sessionId=null==t?this.updateSessionId():t}return e._sessionId},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastSessionTimestamp",{get:function(){if(null===this._lastSessionTimestamp||0===this._lastSessionTimestamp){var t=s.AvoInspector.avoStorage.getItem(e.lastSessionTimestampKey);null!=t?(this._lastSessionTimestamp=t,isNaN(this._lastSessionTimestamp)&&(this._lastSessionTimestamp=0)):this._lastSessionTimestamp=0}return this._lastSessionTimestamp},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sessionLengthMillis",{get:function(){return this._sessionLengthMillis},enumerable:!1,configurable:!0}),e.prototype.startOrProlongSession=function(t){var n=this;s.AvoInspector.avoStorage.runAfterInit((function(){t-n.lastSessionTimestamp>n._sessionLengthMillis&&(e.updateSessionId(),n.avoBatcher.handleSessionStarted()),n._lastSessionTimestamp=t,s.AvoInspector.avoStorage.setItem(e.lastSessionTimestampKey,n._lastSessionTimestamp)}))},e.updateSessionId=function(){e._sessionId=o.default.newGuid();try{s.AvoInspector.avoStorage.setItem(e.idCacheKey,e.sessionId)}catch(e){console.error("Avo Inspector: something went wrong. Please report to support@avo.app.",e)}return e._sessionId},Object.defineProperty(e,"lastSessionTimestampKey",{get:function(){return"AvoInspectorSessionTimestamp"},enumerable:!1,configurable:!0}),Object.defineProperty(e,"idCacheKey",{get:function(){return"AvoInspectorSessionId"},enumerable:!1,configurable:!0}),e._sessionId=null,e}();t.AvoSessionTracker=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.deepEquals=t.isValueEmpty=void 0;t.isValueEmpty=function(e){return null==e||0==e.trim().length},t.deepEquals=function e(t,n){if(t===n)return!0;if(!(t instanceof Object&&n instanceof Object))return!1;if(t.constructor!==n.constructor)return!1;for(var o in t)if(t.hasOwnProperty(o)){if(!n.hasOwnProperty(o))return!1;if(t[o]!==n[o]){if("object"!=typeof t[o])return!1;if(!e(t[o],n[o]))return!1}}for(o in n)if(n.hasOwnProperty(o)&&!t.hasOwnProperty(o))return!1;return!0}},function(e,t,n){"use strict";n.r(t);var o=n(0);if("undefined"!=typeof window){"undefined"!==console&&"dev"==window.inspector.__ENV__&&console.log("Avo Inspector: Loaded. Starting initialization..."),"undefined"!==console&&"MY-API-KEY"==window.inspector.__API_KEY__&&console.error("Avo Inspector: API key not provided");const e=window.inspector;window.inspector=new o.AvoInspector({apiKey:window.inspector.__API_KEY__,env:window.inspector.__ENV__,version:window.inspector.__VERSION__,appName:window.inspector.__APP_NAME__}),e.forEach(e=>{const t=e[0];e.shift(),window.inspector[t](...e)})}else"undefined"!==console&&console.log("Avo Inspector: Window not available. Aborting.")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv=void 0,t.AvoInspectorEnv={Prod:"prod",Dev:"dev",Staging:"staging"}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoBatcher=void 0;var o=n(0),s=function(){function e(t){var n=this;this.events=[],this.networkCallsHandler=t,this.batchFlushAttemptTimestamp=Date.now(),o.AvoInspector.avoStorage.getItemAsync(e.cacheKey).then((function(e){if(null!==e){var t=e.filter((function(e){return null!==e}));n.events=n.events.concat(t),n.checkIfBatchNeedsToBeSent()}}))}return e.prototype.handleSessionStarted=function(){this.events.push(this.networkCallsHandler.bodyForSessionStartedCall()),this.saveEvents(),this.checkIfBatchNeedsToBeSent()},e.prototype.handleTrackSchema=function(e,t,n,s){this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(e,t,n,s)),this.saveEvents(),o.AvoInspector.shouldLog&&console.log("Avo Inspector: saved event "+e+" with schema "+JSON.stringify(t)),this.checkIfBatchNeedsToBeSent()},e.prototype.checkIfBatchNeedsToBeSent=function(){var e=this.events.length,t=Date.now(),n=t-this.batchFlushAttemptTimestamp,s=e%o.AvoInspector.batchSize==0,r=n>=1e3*o.AvoInspector.batchFlushSeconds,i=this;if(s||r){this.batchFlushAttemptTimestamp=t;var a=i.events;i.events=[],this.networkCallsHandler.callInspectorWithBatchBody(a,(function(e){null!=e?(i.events=i.events.concat(a),o.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sending failed: "+e+". We will attempt to send your schemas with next batch")):o.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sent successfully."),i.saveEvents()}))}},e.prototype.saveEvents=function(){if(this.events.length>1e3){var t=this.events.length-1e3;this.events.splice(0,t)}o.AvoInspector.avoStorage.setItem(e.cacheKey,this.events)},Object.defineProperty(e,"cacheKey",{get:function(){return"AvoInspectorEvents"},enumerable:!1,configurable:!0}),e}();t.AvoBatcher=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoNetworkCallsHandler=void 0;var o=n(1),s=n(3),r=n(0),i=n(9),a=function(){function e(e,t,n,o,s){this.samplingRate=1,this.sending=!1,this.apiKey=e,this.envName=t,this.appName=n,this.appVersion=o,this.libVersion=s}return e.prototype.callInspectorWithBatchBody=function(t,n){var o=this;if(this.sending)n("Batch sending cancelled because another batch sending is in progress. Your events will be sent with next batch.");else{var s=t.filter((function(e){return null!=e}));if(this.fixSessionAndTrackingIds(s),0!==s.length)if(Math.random()>this.samplingRate)r.AvoInspector.shouldLog&&console.log("Avo Inspector: last event schema dropped due to sampling rate.");else{r.AvoInspector.shouldLog&&(console.log("Avo Inspector: events",s),s.forEach((function(e){if("sessionStarted"===e.type)console.log("Avo Inspector: sending session started event.");else if("event"===e.type){var t=e;console.log("Avo Inspector: sending event "+t.eventName+" with schema "+JSON.stringify(t.eventProperties))}}))),this.sending=!0;var i=new XMLHttpRequest;i.open("POST",e.trackingEndpoint,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(s)),i.onload=function(){if(200!=i.status)n("Error "+i.status+": "+i.statusText);else{var e=JSON.parse(i.response).samplingRate;void 0!==e&&(o.samplingRate=e),n(null)}},i.onerror=function(){n("Request failed")},i.ontimeout=function(){n("Request timed out")},this.sending=!1}}},e.prototype.fixSessionAndTrackingIds=function(e){var t=null,n=null;e.forEach((function(e){null!==e.sessionId&&void 0!==e.sessionId&&"unknown"!==e.sessionId&&(t=e.sessionId),null!==e.trackingId&&void 0!==e.trackingId&&"unknown"!==e.trackingId&&(n=e.trackingId)})),e.forEach((function(e){"unknown"===e.sessionId&&(e.sessionId=null!=t?t:s.AvoSessionTracker.sessionId),"unknown"===e.trackingId&&(e.trackingId=null!=n?n:i.AvoInstallationId.getInstallationId())}))},e.prototype.bodyForSessionStartedCall=function(){var e=this.createBaseCallBody();return e.type="sessionStarted",e},e.prototype.bodyForEventSchemaCall=function(e,t,n,o){var s=this.createBaseCallBody();return s.type="event",s.eventName=e,s.eventProperties=t,null!=n?(s.avoFunction=!0,s.eventId=n,s.eventHash=o):(s.avoFunction=!1,s.eventId=null,s.eventHash=null),s},e.prototype.createBaseCallBody=function(){return{apiKey:this.apiKey,appName:this.appName,appVersion:this.appVersion,libVersion:this.libVersion,env:this.envName,libPlatform:"web",messageId:o.default.newGuid(),trackingId:i.AvoInstallationId.getInstallationId(),createdAt:(new Date).toISOString(),sessionId:s.AvoSessionTracker.sessionId,samplingRate:this.samplingRate}},e.trackingEndpoint="https://api.avo.app/inspector/v1/track",e}();t.AvoNetworkCallsHandler=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInstallationId=void 0;var o=n(1),s=n(0),r=function(){function e(){}return e.getInstallationId=function(){if(null!==e.installationId)return e.installationId;if(!s.AvoInspector.avoStorage.isInitialized())return"unknown";var t=s.AvoInspector.avoStorage.getItem(e.cacheKey);return null==t?(e.installationId=o.default.newGuid(),s.AvoInspector.avoStorage.setItem(e.cacheKey,e.installationId)):e.installationId=t,e.installationId},Object.defineProperty(e,"cacheKey",{get:function(){return"AvoInstallationId"},enumerable:!1,configurable:!0}),e.installationId=null,e}();t.AvoInstallationId=r},function(e,t,n){"use strict";var o,s=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.AvoStorage=void 0;var r=function(){function e(){}return e.prototype.parseJson=function(e){return null!=e?JSON.parse(e):null},e}(),i=(function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.androidMemoryDataToAvoidAsyncQueries={},t.AsyncStorage=null,t.memoryStorageInitialized=!1,t.onStorageInitFuncs=[],t.reactNative=null,t.shouldLog=!1,t.suffix="",t}s(t,e),t.prototype.init=function(e,t){},t.prototype.loadAndroidDataToMemoryToAvoidAsyncQueries=function(e){var t=this;this.AsyncStorage.getAllKeys().then((function(n){return t.AsyncStorage.multiGet(n).then((function(n){t.shouldLog&&console.log("Avo Inspector: android loaded data from memory"),n.forEach((function(e){var n=e[0];n.endsWith(t.suffix)&&(t.androidMemoryDataToAvoidAsyncQueries[n]=e[1],t.shouldLog&&console.log(n,e[1]))})),e()}))}))},t.prototype.initializeStorageAndroid=function(){this.memoryStorageInitialized=!0,this.onStorageInitFuncs.forEach((function(e){e()}))},t.prototype.isInitialized=function(){return this.reactNative&&this.memoryStorageInitialized},t.prototype.getItemAsync=function(e){return this.AsyncStorage.getItem(e+this.suffix).then((function(e){return null!=e?JSON.parse(e):null}))},t.prototype.getItem=function(e){var t=this.androidMemoryDataToAvoidAsyncQueries[e+this.suffix];return this.parseJson(t)},t.prototype.setItem=function(e,t){this.AsyncStorage.setItem(e+this.suffix,JSON.stringify(t)),this.androidMemoryDataToAvoidAsyncQueries[e+this.suffix]=JSON.stringify(t)},t.prototype.removeItem=function(e){this.AsyncStorage.removeItem(e+this.suffix),this.androidMemoryDataToAvoidAsyncQueries[e+this.suffix]=null},t.prototype.runAfterInit=function(e){!0===this.memoryStorageInitialized?e():this.onStorageInitFuncs.push(e)}}(r),function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.reactNative=null,t.suffix="",t}s(t,e),t.prototype.init=function(e,t){0},t.prototype.isInitialized=function(){return null!=this.reactNative},t.prototype.getItemAsync=function(e){var t=this.reactNative.Settings.get(e+this.suffix);return Promise.resolve(this.parseJson(t))},t.prototype.getItem=function(e){var t=this.reactNative.Settings.get(e+this.suffix);return this.parseJson(t)},t.prototype.setItem=function(e,t){var n;this.reactNative.Settings.set(((n={})[e+this.suffix]=JSON.stringify(t),n))},t.prototype.removeItem=function(e){var t;this.reactNative.Settings.set(((t={})[e+this.suffix]=null,t))},t.prototype.runAfterInit=function(e){e()}}(r),function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.useFallbackStorage=!1,t.fallbackStorage={},t.storageInitialized=!1,t.onStorageInitFuncs=[],t.shouldLog=!1,t.suffix="",t}return s(t,e),t.prototype.init=function(e,t){this.shouldLog=e,this.suffix=t,this.initializeStorageWeb(this.isLocalStorageAvailable())},t.prototype.initializeStorageWeb=function(e){this.storageInitialized=!0,!1===e&&(this.useFallbackStorage=!0),this.onStorageInitFuncs.forEach((function(e){e()}))},t.prototype.isLocalStorageAvailable=function(){var e=(new Date).toISOString();try{return window.localStorage.setItem(e,e),window.localStorage.getItem(e)===e&&(window.localStorage.removeItem(e),!0)}catch(e){return!1}},t.prototype.isInitialized=function(){return this.storageInitialized},t.prototype.getItemAsync=function(e){var t=this;return new Promise((function(n,o){t.runAfterInit((function(){if(!0===t.useFallbackStorage){var o=t.fallbackStorage[e+t.suffix];n(t.parseJson(o))}else if("undefined"!=typeof window){o=void 0;try{o=window.localStorage.getItem(e+t.suffix)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage getItemAsync error:",e),n(null)}n(t.parseJson(o))}else n(null)}))}))},t.prototype.getItem=function(e){var t;if(!1===this.storageInitialized)t=null;else if(!0===this.useFallbackStorage)t=this.fallbackStorage[e+this.suffix];else if("undefined"!=typeof window)try{t=window.localStorage.getItem(e+this.suffix)}catch(e){this.shouldLog&&console.error("Avo Inspector Storage getItem error:",e)}return this.parseJson(t)},t.prototype.setItem=function(e,t){var n=this;this.runAfterInit((function(){if(!0===n.useFallbackStorage)n.fallbackStorage[e+n.suffix]=JSON.stringify(t);else if("undefined"!=typeof window)try{window.localStorage.setItem(e+n.suffix,JSON.stringify(t))}catch(e){n.shouldLog&&console.error("Avo Inspector Storage setItem error:",e)}}))},t.prototype.removeItem=function(e){var t=this;this.runAfterInit((function(){if(!0===t.useFallbackStorage)t.fallbackStorage[e+t.suffix]=null;else if("undefined"!=typeof window)try{window.localStorage.removeItem(e+t.suffix)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage removeItem error:",e)}}))},t.prototype.runAfterInit=function(e){!0===this.storageInitialized?e():this.onStorageInitFuncs.push(e)},t}(r)),a=function(){function e(e,t){void 0===t&&(t=""),this.Platform=null,this.Platform="browser",this.storageImpl=new i,this.storageImpl.init(e,t)}return e.prototype.isInitialized=function(){return this.storageImpl.isInitialized()},e.prototype.getItemAsync=function(e){return this.storageImpl.getItemAsync(e)},e.prototype.getItem=function(e){return this.storageImpl.getItem(e)},e.prototype.setItem=function(e,t){this.storageImpl.setItem(e,t)},e.prototype.removeItem=function(e){this.storageImpl.removeItem(e)},e.prototype.runAfterInit=function(e){this.storageImpl.runAfterInit(e)},e}();t.AvoStorage=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AvoDeduplicator=void 0;var o=n(2),s=n(4),r=function(){function e(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}}return e.prototype.shouldRegisterEvent=function(e,t,n){this.clearOldEvents(),n?(this.avoFunctionsEvents[Date.now()]=e,this.avoFunctionsEventsParams[e]=t):(this.manualEvents[Date.now()]=e,this.manualEventsParams[e]=t);var o=!n;return!this.hasSameEventAs(e,t,o)},e.prototype.hasSameEventAs=function(e,t,n){var o=!1;return n?this.lookForEventIn(e,t,this.avoFunctionsEventsParams)&&(o=!0):this.lookForEventIn(e,t,this.manualEventsParams)&&(o=!0),o&&(delete this.avoFunctionsEventsParams[e],delete this.manualEventsParams[e]),o},e.prototype.lookForEventIn=function(e,t,n){for(var o in n)if(n.hasOwnProperty(o)&&o===e){var r=n[e];if(r&&s.deepEquals(t,r))return!0}return!1},e.prototype.hasSeenEventParams=function(e,t){var n=!1;return t?this.lookForEventParamsIn(e,this.avoFunctionsEventsParams)&&(n=!0):this.lookForEventParamsIn(e,this.manualEventsParams)&&(n=!0),n},e.prototype.lookForEventParamsIn=function(e,t){for(var n in t)if(t.hasOwnProperty(n)){var o=t[n];if(o&&s.deepEquals(e,o))return!0}return!1},e.prototype.shouldRegisterSchemaFromManually=function(e,t){return this.clearOldEvents(),!this.hasSameShapeInAvoFunctionsAs(e,t)},e.prototype.hasSameShapeInAvoFunctionsAs=function(e,t){var n=!1;return this.lookForEventSchemaIn(e,t,this.avoFunctionsEventsParams)&&(n=!0),n&&delete this.avoFunctionsEventsParams[e],n},e.prototype.lookForEventSchemaIn=function(e,t,n){for(var r in n)if(n.hasOwnProperty(r)&&r===e){var i=o.AvoSchemaParser.extractSchema(n[e]);if(i&&s.deepEquals(t,i))return!0}return!1},e.prototype.clearOldEvents=function(){var e=Date.now();for(var t in this.avoFunctionsEvents){if(this.avoFunctionsEvents.hasOwnProperty(t))if(e-(Number(t)||0)>300){var n=this.avoFunctionsEvents[t];delete this.avoFunctionsEvents[t],delete this.avoFunctionsEventsParams[n]}}for(var t in this.manualEvents){if(this.manualEvents.hasOwnProperty(t))if(e-(Number(t)||0)>300){n=this.manualEvents[t];delete this.manualEvents[t],delete this.manualEventsParams[n]}}},e.prototype._clearEvents=function(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}},e}();t.AvoDeduplicator=r},function(e){e.exports=JSON.parse('{"name":"avo-inspector","version":"1.3.0","description":"","main":"dist/index.js","browser":"dist/index.js","react-native":"dist-native/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc --emitDeclarationOnly && webpack src/index.ts --mode production --resolve-extensions .ts --module-bind ts=ts-loader --define process.env.BROWSER=1 --output-filename index.js --output-library-target umd","build-for-script-tag":"tsc --emitDeclarationOnly && webpack src/browser.js --mode production --resolve-extensions .ts --module-bind ts=ts-loader --define process.env.BROWSER=1 --woutput-filename browser.js --output-library-target umd","build-native":"tsc --outDir dist-native","test":"jest","test:browser":"BROWSER=1 jest","typecheck":"tsc --noEmit"},"repository":{"type":"git","url":"git+https://github.com/avohq/web-avo-inspector.git"},"jest":{"transform":{"^.+\\\\.[j]sx?$":"babel-jest","^.+\\\\.[t]sx?$":"ts-jest"},"testPathIgnorePatterns":["constants","examples","node_modules","dist","dist-native"],"testRegex":"(/__tests__/.*|\\\\.(test|spec))\\\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js"]},"keywords":["web","analytics","avo","react","react-native","node","javascript"],"author":"Avo (https://www.avo.app)","license":"MIT","bugs":{"url":"https://github.com/avohq/web-avo-inspector/issues"},"homepage":"https://github.com/avohq/web-avo-inspector#readme","devDependencies":{"@babel/core":"7.12.10","@babel/preset-env":"7.12.11","@types/jest":"26.0.19","@types/node":"14.14.16","babel-preset-es2015":"6.24.1","babel-preset-react":"6.24.1","eslint":"7.16.0","eslint-plugin-react":"7.21.5","jest":"26.6.3","prettier":"2.2.1","prettier-eslint":"12.0.0","ts-jest":"26.4.4","ts-loader":"8.0.12","typescript":"4.1.3","webpack":"4.44.2","webpack-cli":"3.3.12"},"externals":["react-native"]}')}])}));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
|
|
2
|
+
export interface AvoBatcherType {
|
|
3
|
+
handleSessionStarted(): void;
|
|
4
|
+
handleTrackSchema(eventName: string, schema: Array<{
|
|
5
|
+
propertyName: string;
|
|
6
|
+
propertyType: string;
|
|
7
|
+
children?: any;
|
|
8
|
+
}>, eventId: string | null, eventHash: string | null): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class AvoBatcher implements AvoBatcherType {
|
|
11
|
+
private events;
|
|
12
|
+
private batchFlushAttemptTimestamp;
|
|
13
|
+
private networkCallsHandler;
|
|
14
|
+
constructor(networkCallsHandler: AvoNetworkCallsHandler);
|
|
15
|
+
handleSessionStarted(): void;
|
|
16
|
+
handleTrackSchema(eventName: string, schema: Array<{
|
|
17
|
+
propertyName: string;
|
|
18
|
+
propertyType: string;
|
|
19
|
+
children?: any;
|
|
20
|
+
}>, eventId: string | null, eventHash: string | null): void;
|
|
21
|
+
private checkIfBatchNeedsToBeSent;
|
|
22
|
+
private saveEvents;
|
|
23
|
+
static get cacheKey(): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvoBatcher = void 0;
|
|
4
|
+
var AvoInspector_1 = require("./AvoInspector");
|
|
5
|
+
var AvoBatcher = /** @class */ (function () {
|
|
6
|
+
function AvoBatcher(networkCallsHandler) {
|
|
7
|
+
var _this = this;
|
|
8
|
+
this.events = [];
|
|
9
|
+
this.networkCallsHandler = networkCallsHandler;
|
|
10
|
+
this.batchFlushAttemptTimestamp = Date.now();
|
|
11
|
+
AvoInspector_1.AvoInspector.avoStorage
|
|
12
|
+
.getItemAsync(AvoBatcher.cacheKey)
|
|
13
|
+
.then(function (savedEvents) {
|
|
14
|
+
if (savedEvents !== null) {
|
|
15
|
+
var nonNullSavedEvents = savedEvents.filter(function (event) { return event !== null; });
|
|
16
|
+
_this.events = _this.events.concat(nonNullSavedEvents);
|
|
17
|
+
_this.checkIfBatchNeedsToBeSent();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
AvoBatcher.prototype.handleSessionStarted = function () {
|
|
22
|
+
this.events.push(this.networkCallsHandler.bodyForSessionStartedCall());
|
|
23
|
+
this.saveEvents();
|
|
24
|
+
this.checkIfBatchNeedsToBeSent();
|
|
25
|
+
};
|
|
26
|
+
AvoBatcher.prototype.handleTrackSchema = function (eventName, schema, eventId, eventHash) {
|
|
27
|
+
this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(eventName, schema, eventId, eventHash));
|
|
28
|
+
this.saveEvents();
|
|
29
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
30
|
+
console.log("Avo Inspector: saved event " +
|
|
31
|
+
eventName +
|
|
32
|
+
" with schema " +
|
|
33
|
+
JSON.stringify(schema));
|
|
34
|
+
}
|
|
35
|
+
this.checkIfBatchNeedsToBeSent();
|
|
36
|
+
};
|
|
37
|
+
AvoBatcher.prototype.checkIfBatchNeedsToBeSent = function () {
|
|
38
|
+
var batchSize = this.events.length;
|
|
39
|
+
var now = Date.now();
|
|
40
|
+
var timeSinceLastFlushAttempt = now - this.batchFlushAttemptTimestamp;
|
|
41
|
+
var sendBySize = batchSize % AvoInspector_1.AvoInspector.batchSize == 0;
|
|
42
|
+
var sendByTime = timeSinceLastFlushAttempt >= AvoInspector_1.AvoInspector.batchFlushSeconds * 1000;
|
|
43
|
+
var avoBatcher = this;
|
|
44
|
+
if (sendBySize || sendByTime) {
|
|
45
|
+
this.batchFlushAttemptTimestamp = now;
|
|
46
|
+
var sendingEvents_1 = avoBatcher.events;
|
|
47
|
+
avoBatcher.events = [];
|
|
48
|
+
this.networkCallsHandler.callInspectorWithBatchBody(sendingEvents_1, function (error) {
|
|
49
|
+
if (error != null) {
|
|
50
|
+
avoBatcher.events = avoBatcher.events.concat(sendingEvents_1);
|
|
51
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
52
|
+
console.log("Avo Inspector: batch sending failed: " +
|
|
53
|
+
error +
|
|
54
|
+
". We will attempt to send your schemas with next batch");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
59
|
+
console.log("Avo Inspector: batch sent successfully.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
avoBatcher.saveEvents();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
AvoBatcher.prototype.saveEvents = function () {
|
|
67
|
+
if (this.events.length > 1000) {
|
|
68
|
+
var extraElements = this.events.length - 1000;
|
|
69
|
+
this.events.splice(0, extraElements);
|
|
70
|
+
}
|
|
71
|
+
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoBatcher.cacheKey, this.events);
|
|
72
|
+
};
|
|
73
|
+
Object.defineProperty(AvoBatcher, "cacheKey", {
|
|
74
|
+
get: function () {
|
|
75
|
+
return "AvoInspectorEvents";
|
|
76
|
+
},
|
|
77
|
+
enumerable: false,
|
|
78
|
+
configurable: true
|
|
79
|
+
});
|
|
80
|
+
return AvoBatcher;
|
|
81
|
+
}());
|
|
82
|
+
exports.AvoBatcher = AvoBatcher;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class AvoDeduplicator {
|
|
2
|
+
avoFunctionsEvents: {
|
|
3
|
+
[time: number]: string;
|
|
4
|
+
};
|
|
5
|
+
manualEvents: {
|
|
6
|
+
[time: number]: string;
|
|
7
|
+
};
|
|
8
|
+
avoFunctionsEventsParams: {
|
|
9
|
+
[eventName: string]: {
|
|
10
|
+
[propName: string]: any;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
manualEventsParams: {
|
|
14
|
+
[eventName: string]: {
|
|
15
|
+
[propName: string]: any;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
shouldRegisterEvent(eventName: string, params: {
|
|
19
|
+
[propName: string]: any;
|
|
20
|
+
}, fromAvoFunction: boolean): boolean;
|
|
21
|
+
private hasSameEventAs;
|
|
22
|
+
private lookForEventIn;
|
|
23
|
+
hasSeenEventParams(params: {
|
|
24
|
+
[propName: string]: any;
|
|
25
|
+
}, checkInAvoFunctions: boolean): boolean;
|
|
26
|
+
private lookForEventParamsIn;
|
|
27
|
+
shouldRegisterSchemaFromManually(eventName: string, eventSchema: Array<{
|
|
28
|
+
propertyName: string;
|
|
29
|
+
propertyType: string;
|
|
30
|
+
children?: any;
|
|
31
|
+
}>): boolean;
|
|
32
|
+
private hasSameShapeInAvoFunctionsAs;
|
|
33
|
+
private lookForEventSchemaIn;
|
|
34
|
+
private clearOldEvents;
|
|
35
|
+
private _clearEvents;
|
|
36
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvoDeduplicator = void 0;
|
|
4
|
+
var AvoSchemaParser_1 = require("./AvoSchemaParser");
|
|
5
|
+
var utils_1 = require("./utils");
|
|
6
|
+
var AvoDeduplicator = /** @class */ (function () {
|
|
7
|
+
function AvoDeduplicator() {
|
|
8
|
+
this.avoFunctionsEvents = {};
|
|
9
|
+
this.manualEvents = {};
|
|
10
|
+
this.avoFunctionsEventsParams = {};
|
|
11
|
+
this.manualEventsParams = {};
|
|
12
|
+
}
|
|
13
|
+
AvoDeduplicator.prototype.shouldRegisterEvent = function (eventName, params, fromAvoFunction) {
|
|
14
|
+
this.clearOldEvents();
|
|
15
|
+
if (fromAvoFunction) {
|
|
16
|
+
this.avoFunctionsEvents[Date.now()] = eventName;
|
|
17
|
+
this.avoFunctionsEventsParams[eventName] = params;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.manualEvents[Date.now()] = eventName;
|
|
21
|
+
this.manualEventsParams[eventName] = params;
|
|
22
|
+
}
|
|
23
|
+
var checkInAvoFunctions = !fromAvoFunction;
|
|
24
|
+
return !this.hasSameEventAs(eventName, params, checkInAvoFunctions);
|
|
25
|
+
};
|
|
26
|
+
AvoDeduplicator.prototype.hasSameEventAs = function (eventName, params, checkInAvoFunctions) {
|
|
27
|
+
var result = false;
|
|
28
|
+
if (checkInAvoFunctions) {
|
|
29
|
+
if (this.lookForEventIn(eventName, params, this.avoFunctionsEventsParams)) {
|
|
30
|
+
result = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (this.lookForEventIn(eventName, params, this.manualEventsParams)) {
|
|
35
|
+
result = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (result) {
|
|
39
|
+
delete this.avoFunctionsEventsParams[eventName];
|
|
40
|
+
delete this.manualEventsParams[eventName];
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
AvoDeduplicator.prototype.lookForEventIn = function (eventName, params, eventsStorage) {
|
|
45
|
+
for (var otherEventName in eventsStorage) {
|
|
46
|
+
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
47
|
+
if (otherEventName === eventName) {
|
|
48
|
+
var otherParams = eventsStorage[eventName];
|
|
49
|
+
if (otherParams && utils_1.deepEquals(params, otherParams)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
AvoDeduplicator.prototype.hasSeenEventParams = function (params, checkInAvoFunctions) {
|
|
58
|
+
var result = false;
|
|
59
|
+
if (checkInAvoFunctions) {
|
|
60
|
+
if (this.lookForEventParamsIn(params, this.avoFunctionsEventsParams)) {
|
|
61
|
+
result = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (this.lookForEventParamsIn(params, this.manualEventsParams)) {
|
|
66
|
+
result = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
AvoDeduplicator.prototype.lookForEventParamsIn = function (params, eventsStorage) {
|
|
72
|
+
for (var otherEventName in eventsStorage) {
|
|
73
|
+
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
74
|
+
var otherParams = eventsStorage[otherEventName];
|
|
75
|
+
if (otherParams && utils_1.deepEquals(params, otherParams)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
};
|
|
82
|
+
AvoDeduplicator.prototype.shouldRegisterSchemaFromManually = function (eventName, eventSchema) {
|
|
83
|
+
this.clearOldEvents();
|
|
84
|
+
return !this.hasSameShapeInAvoFunctionsAs(eventName, eventSchema);
|
|
85
|
+
};
|
|
86
|
+
AvoDeduplicator.prototype.hasSameShapeInAvoFunctionsAs = function (eventName, eventSchema) {
|
|
87
|
+
var result = false;
|
|
88
|
+
if (this.lookForEventSchemaIn(eventName, eventSchema, this.avoFunctionsEventsParams)) {
|
|
89
|
+
result = true;
|
|
90
|
+
}
|
|
91
|
+
if (result) {
|
|
92
|
+
delete this.avoFunctionsEventsParams[eventName];
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
AvoDeduplicator.prototype.lookForEventSchemaIn = function (eventName, eventSchema, eventsStorage) {
|
|
97
|
+
for (var otherEventName in eventsStorage) {
|
|
98
|
+
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
99
|
+
if (otherEventName === eventName) {
|
|
100
|
+
var otherSchema = AvoSchemaParser_1.AvoSchemaParser.extractSchema(eventsStorage[eventName]);
|
|
101
|
+
if (otherSchema && utils_1.deepEquals(eventSchema, otherSchema)) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
};
|
|
109
|
+
AvoDeduplicator.prototype.clearOldEvents = function () {
|
|
110
|
+
var now = Date.now();
|
|
111
|
+
var msToConsiderOld = 300;
|
|
112
|
+
for (var time in this.avoFunctionsEvents) {
|
|
113
|
+
if (this.avoFunctionsEvents.hasOwnProperty(time)) {
|
|
114
|
+
var timestamp = Number(time) || 0;
|
|
115
|
+
if (now - timestamp > msToConsiderOld) {
|
|
116
|
+
var eventName = this.avoFunctionsEvents[time];
|
|
117
|
+
delete this.avoFunctionsEvents[time];
|
|
118
|
+
delete this.avoFunctionsEventsParams[eventName];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (var time in this.manualEvents) {
|
|
123
|
+
if (this.manualEvents.hasOwnProperty(time)) {
|
|
124
|
+
var timestamp = Number(time) || 0;
|
|
125
|
+
if (now - timestamp > msToConsiderOld) {
|
|
126
|
+
var eventName = this.manualEvents[time];
|
|
127
|
+
delete this.manualEvents[time];
|
|
128
|
+
delete this.manualEventsParams[eventName];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
// used in tests
|
|
134
|
+
AvoDeduplicator.prototype._clearEvents = function () {
|
|
135
|
+
this.avoFunctionsEvents = {};
|
|
136
|
+
this.manualEvents = {};
|
|
137
|
+
this.avoFunctionsEventsParams = {};
|
|
138
|
+
this.manualEventsParams = {};
|
|
139
|
+
};
|
|
140
|
+
return AvoDeduplicator;
|
|
141
|
+
}());
|
|
142
|
+
exports.AvoDeduplicator = AvoDeduplicator;
|