avo-inspector 1.3.0 → 1.4.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.eslintrc.json +24 -0
  2. package/CHANGELOG.md +3 -0
  3. package/README.md +8 -5
  4. package/dist/AvoBatcher.d.ts +5 -5
  5. package/dist/AvoDeduplicator.d.ts +6 -22
  6. package/dist/AvoInspector.d.ts +3 -7
  7. package/dist/AvoInspectorEnv.d.ts +2 -2
  8. package/dist/AvoNetworkCallsHandler.d.ts +6 -6
  9. package/dist/AvoSchemaParser.d.ts +1 -3
  10. package/dist/AvoSessionTracker.d.ts +3 -3
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/package.json +23 -26
  14. package/webpack.browserConfig.js +26 -0
  15. package/webpack.config.js +26 -0
  16. package/.github/workflows/test_browser.yml +0 -45
  17. package/.vscode/launch.json +0 -15
  18. package/dist/main.js +0 -1
  19. package/dist-native/AvoBatcher.d.ts +0 -24
  20. package/dist-native/AvoBatcher.js +0 -82
  21. package/dist-native/AvoDeduplicator.d.ts +0 -36
  22. package/dist-native/AvoDeduplicator.js +0 -142
  23. package/dist-native/AvoGuid.d.ts +0 -3
  24. package/dist-native/AvoGuid.js +0 -14
  25. package/dist-native/AvoInspector.d.ts +0 -53
  26. package/dist-native/AvoInspector.js +0 -220
  27. package/dist-native/AvoInspectorEnv.d.ts +0 -7
  28. package/dist-native/AvoInspectorEnv.js +0 -8
  29. package/dist-native/AvoInstallationId.d.ts +0 -5
  30. package/dist-native/AvoInstallationId.js +0 -36
  31. package/dist-native/AvoNetworkCallsHandler.d.ts +0 -48
  32. package/dist-native/AvoNetworkCallsHandler.js +0 -142
  33. package/dist-native/AvoSchemaParser.d.ts +0 -11
  34. package/dist-native/AvoSchemaParser.js +0 -95
  35. package/dist-native/AvoSessionTracker.d.ts +0 -15
  36. package/dist-native/AvoSessionTracker.js +0 -104
  37. package/dist-native/AvoStorage.d.ts +0 -22
  38. package/dist-native/AvoStorage.js +0 -343
  39. package/dist-native/__mocks__/xhr.d.ts +0 -12
  40. package/dist-native/__mocks__/xhr.js +0 -14
  41. package/dist-native/__mocks__/xhrError.d.ts +0 -12
  42. package/dist-native/__mocks__/xhrError.js +0 -14
  43. package/dist-native/__tests__/AvoInspector.d.ts +0 -1
  44. package/dist-native/__tests__/AvoInspector.js +0 -207
  45. package/dist-native/__tests__/Batcher.d.ts +0 -1
  46. package/dist-native/__tests__/Batcher.js +0 -278
  47. package/dist-native/__tests__/BatcherPublic.d.ts +0 -1
  48. package/dist-native/__tests__/BatcherPublic.js +0 -82
  49. package/dist-native/__tests__/Deduplicator.d.ts +0 -1
  50. package/dist-native/__tests__/Deduplicator.js +0 -111
  51. package/dist-native/__tests__/InstallationId.d.ts +0 -1
  52. package/dist-native/__tests__/InstallationId.js +0 -40
  53. package/dist-native/__tests__/NetworkCallsHandler.d.ts +0 -1
  54. package/dist-native/__tests__/NetworkCallsHandler.js +0 -135
  55. package/dist-native/__tests__/Parsing.d.ts +0 -1
  56. package/dist-native/__tests__/Parsing.js +0 -174
  57. package/dist-native/__tests__/Sessions.d.ts +0 -1
  58. package/dist-native/__tests__/Sessions.js +0 -179
  59. package/dist-native/__tests__/Storage.d.ts +0 -1
  60. package/dist-native/__tests__/Storage.js +0 -173
  61. package/dist-native/__tests__/constants.d.ts +0 -36
  62. package/dist-native/__tests__/constants.js +0 -47
  63. package/dist-native/index.d.ts +0 -2
  64. package/dist-native/index.js +0 -7
  65. package/dist-native/utils.d.ts +0 -3
  66. package/dist-native/utils.js +0 -42
package/.eslintrc.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true
5
+ },
6
+ "extends": ["standard-with-typescript"],
7
+ "overrides": [
8
+ {
9
+ "env": { "node": true },
10
+ "files": [".eslintrc.{js,cjs,json}"],
11
+ "parserOptions": { "sourceType": "script" }
12
+ }
13
+ ],
14
+ "parserOptions": {
15
+ "ecmaVersion": "latest",
16
+ "sourceType": "module"
17
+ },
18
+ "rules": {
19
+ "semi": ["error", "always"],
20
+ "quotes": ["error", "double"],
21
+ "@typescript-eslint/semi": ["error", "always"],
22
+ "@typescript-eslint/quotes": ["error", "double"]
23
+ }
24
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 1.3.0
2
+
3
+ Multiple Avo Inspector instances support, with the optional `suffix` constructor parameter
package/README.md CHANGED
@@ -5,10 +5,12 @@
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/implementation/inspector/sdk/web).
8
+ For more information about Inspector project please read [Avo documentation](https://www.avo.app/docs/implementation/inspector/sdk/web).
9
9
 
10
10
  # Installation
11
11
 
12
+ > If you are using SSR or web workers switch to [this library build](https://github.com/avohq/ssr-web-avo-inspector)
13
+
12
14
  > If you are looking for React Native library please switch to [this branch](https://github.com/avohq/js-avo-inspector/tree/react-native-node-package) and use `react-native-avo-inspector` npm package.
13
15
 
14
16
  The library is distributed with npm
@@ -35,6 +37,7 @@ let inspector = new Inspector.AvoInspector({
35
37
  env: Inspector.AvoInspectorEnv.Dev,
36
38
  version: "1.0.0",
37
39
  appName: "My app",
40
+ suffix: "unique-string" // optional, if you have more than 1 instance of Avo Inspector in same project
38
41
  });
39
42
  ```
40
43
 
@@ -46,13 +49,13 @@ Logs are enabled by default in the dev mode and disabled in prod mode.
46
49
  inspector.enableLogging(true);
47
50
  ```
48
51
 
49
- # Integrating with Avo Functions (Avo generated code)
52
+ # Integrating with Avo Codegen
50
53
 
51
54
  The setup is lightweight and is covered [in this guide](https://www.avo.app/docs/implementation/start-using-inspector-with-avo-functions).
52
55
 
53
- Every event sent with Avo Function after this integration will automatically be sent to the Avo Inspector.
56
+ Every event sent with Avo Function after this integration will automatically be sent to Inspector.
54
57
 
55
- # Sending event schemas for events reported outside of Avo Functions
58
+ # Sending event schemas for events reported outside of Codegen
56
59
 
57
60
  Whenever you send tracking event call one of the following methods:
58
61
 
@@ -60,7 +63,7 @@ Read more in the [Avo documentation](https://www.avo.app/docs/implementation/dev
60
63
 
61
64
  ### 1.
62
65
 
63
- This method gets actual tracking event parameters, extracts schema automatically and sends it to the Avo Inspector backend.
66
+ This method gets actual tracking event parameters, extracts schema automatically and sends it to the Inspector backend.
64
67
  It is the easiest way to use the library, just call this method at the same place you call your analytics tools' track methods with the same parameters.
65
68
 
66
69
  ```javascript
@@ -1,16 +1,16 @@
1
- import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
1
+ import { type AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
2
2
  export interface AvoBatcherType {
3
- handleSessionStarted(): void;
4
- handleTrackSchema(eventName: string, schema: Array<{
3
+ handleSessionStarted: () => void;
4
+ handleTrackSchema: (eventName: string, schema: Array<{
5
5
  propertyName: string;
6
6
  propertyType: string;
7
7
  children?: any;
8
- }>, eventId: string | null, eventHash: string | null): void;
8
+ }>, eventId: string | null, eventHash: string | null) => void;
9
9
  }
10
10
  export declare class AvoBatcher implements AvoBatcherType {
11
11
  private events;
12
12
  private batchFlushAttemptTimestamp;
13
- private networkCallsHandler;
13
+ private readonly networkCallsHandler;
14
14
  constructor(networkCallsHandler: AvoNetworkCallsHandler);
15
15
  handleSessionStarted(): void;
16
16
  handleTrackSchema(eventName: string, schema: Array<{
@@ -1,28 +1,12 @@
1
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;
2
+ avoFunctionsEvents: Record<number, string>;
3
+ manualEvents: Record<number, string>;
4
+ avoFunctionsEventsParams: Record<string, Record<string, any>>;
5
+ manualEventsParams: Record<string, Record<string, any>>;
6
+ shouldRegisterEvent(eventName: string, params: Record<string, any>, fromAvoFunction: boolean): boolean;
21
7
  private hasSameEventAs;
22
8
  private lookForEventIn;
23
- hasSeenEventParams(params: {
24
- [propName: string]: any;
25
- }, checkInAvoFunctions: boolean): boolean;
9
+ hasSeenEventParams(params: Record<string, any>, checkInAvoFunctions: boolean): boolean;
26
10
  private lookForEventParamsIn;
27
11
  shouldRegisterSchemaFromManually(eventName: string, eventSchema: Array<{
28
12
  propertyName: string;
@@ -1,4 +1,4 @@
1
- import { AvoInspectorEnvValueType } from "./AvoInspectorEnv";
1
+ import { type AvoInspectorEnvValueType } from "./AvoInspectorEnv";
2
2
  import { AvoSessionTracker } from "./AvoSessionTracker";
3
3
  import { AvoBatcher } from "./AvoBatcher";
4
4
  import { AvoStorage } from "./AvoStorage";
@@ -26,9 +26,7 @@ export declare class AvoInspector {
26
26
  appName?: string;
27
27
  suffix?: string;
28
28
  });
29
- trackSchemaFromEvent(eventName: string, eventProperties: {
30
- [propName: string]: any;
31
- }): Array<{
29
+ trackSchemaFromEvent(eventName: string, eventProperties: Record<string, any>): Array<{
32
30
  propertyName: string;
33
31
  propertyType: string;
34
32
  children?: any;
@@ -41,9 +39,7 @@ export declare class AvoInspector {
41
39
  }>): void;
42
40
  private trackSchemaInternal;
43
41
  enableLogging(enable: boolean): void;
44
- extractSchema(eventProperties: {
45
- [propName: string]: any;
46
- }, shouldLogIfEnabled?: boolean): Array<{
42
+ extractSchema(eventProperties: Record<string, any>, shouldLogIfEnabled?: boolean): Array<{
47
43
  propertyName: string;
48
44
  propertyType: string;
49
45
  children?: any;
@@ -3,5 +3,5 @@ export declare const AvoInspectorEnv: {
3
3
  readonly Dev: "dev";
4
4
  readonly Staging: "staging";
5
5
  };
6
- export declare type AvoInspectorEnvType = typeof AvoInspectorEnv;
7
- export declare type AvoInspectorEnvValueType = AvoInspectorEnvType[keyof AvoInspectorEnvType];
6
+ export type AvoInspectorEnvType = typeof AvoInspectorEnv;
7
+ export type AvoInspectorEnvValueType = AvoInspectorEnvType[keyof AvoInspectorEnvType];
@@ -27,14 +27,14 @@ export interface EventSchemaBody extends BaseBody {
27
27
  eventHash: string | null;
28
28
  }
29
29
  export declare class AvoNetworkCallsHandler {
30
- private apiKey;
31
- private envName;
32
- private appName;
33
- private appVersion;
34
- private libVersion;
30
+ private readonly apiKey;
31
+ private readonly envName;
32
+ private readonly appName;
33
+ private readonly appVersion;
34
+ private readonly libVersion;
35
35
  private samplingRate;
36
36
  private sending;
37
- private static trackingEndpoint;
37
+ private static readonly trackingEndpoint;
38
38
  constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string);
39
39
  callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: string | null) => any): void;
40
40
  private fixSessionAndTrackingIds;
@@ -1,7 +1,5 @@
1
1
  export declare class AvoSchemaParser {
2
- static extractSchema(eventProperties: {
3
- [propName: string]: any;
4
- }): Array<{
2
+ static extractSchema(eventProperties: Record<string, any>): Array<{
5
3
  propertyName: string;
6
4
  propertyType: string;
7
5
  children?: any;
@@ -1,12 +1,12 @@
1
- import { AvoBatcherType } from "./AvoBatcher";
1
+ import { type AvoBatcherType } from "./AvoBatcher";
2
2
  export declare class AvoSessionTracker {
3
3
  private static _sessionId;
4
4
  static get sessionId(): string;
5
5
  private _lastSessionTimestamp;
6
6
  get lastSessionTimestamp(): number;
7
- private _sessionLengthMillis;
7
+ private readonly _sessionLengthMillis;
8
8
  get sessionLengthMillis(): number;
9
- private avoBatcher;
9
+ private readonly avoBatcher;
10
10
  constructor(avoBatcher: AvoBatcherType);
11
11
  startOrProlongSession(atTime: number): void;
12
12
  private static updateSessionId;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { AvoInspector } from "./AvoInspector";
2
- export { AvoInspectorEnv } from "./AvoInspectorEnv";
2
+ export { AvoInspectorEnv, type AvoInspectorEnvType, type AvoInspectorEnvValueType } from "./AvoInspectorEnv";
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 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"]}')}])}));
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]}}(self,(()=>(()=>{"use strict";var e={669:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoBatcher=void 0;var o=n(611),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},492:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoDeduplicator=void 0;var o=n(924),r=n(185),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&&(0,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&&(0,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&&(0,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)&&e-(Number(t)||0)>300){var n=this.avoFunctionsEvents[t];delete this.avoFunctionsEvents[t],delete this.avoFunctionsEventsParams[n]}for(var t in this.manualEvents)this.manualEvents.hasOwnProperty(t)&&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},249:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=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=n},611:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspector=void 0;var o=n(844),r=n(924),s=n(948),i=n(669),a=n(243),c=n(491),l=n(492),u=n(185),p=n(330).rE,v=function(){function e(t){var n=this;if((0,u.isValueEmpty)(t.env)?(this.environment=o.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] No environment provided. Defaulting to dev.")):Object.values(o.AvoInspectorEnv).includes(t.env)?this.environment=t.env:(this.environment=o.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.")),(0,u.isValueEmpty)(t.apiKey))throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");if(this.apiKey=t.apiKey,(0,u.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 l.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 Codegen. 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},844:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv=void 0,t.AvoInspectorEnv={Prod:"prod",Dev:"dev",Staging:"staging"}},661:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInstallationId=void 0;var o=n(249),r=n(611),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},243:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoNetworkCallsHandler=void 0;var o=n(249),r=n(948),s=n(611),i=n(661),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 ".concat(i.status,": ").concat(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},924:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoSchemaParser=void 0;var n=function(e){return"[object Array]"===Object.prototype.toString.call(e)},o=function(){function e(){}return e.extractSchema=function(e){var t=this;if(null==e)return[];var o=function(e){if(n(e)){var r=e.map((function(e){return o(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=o(a)),s.push(c)}return s}return t.getPropValueType(e)};return o(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.includes(e)&&n.push(e)}))},e.getPropValueType=function(e){var t=typeof e;return null==e?"null":"string"===t?"string":"number"===t||"bigint"===t?(e+"").includes(".")?"float":"int":"boolean"===t?"boolean":"object"===t?n(e)?"list":"object":"unknown"},e}();t.AvoSchemaParser=o},948:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoSessionTracker=void 0;var o=n(249),r=n(611),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},491:function(e,t){var n,o=this&&this.__extends||(n=function(e,t){return n=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])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),r=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,o,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,o=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((r=(r=i.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){i.label=a[1];break}if(6===a[0]&&i.label<r[1]){i.label=r[1],r=a;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(a);break}r[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.AvoStorage=void 0;var i=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 o(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,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){return r(this,void 0,void 0,(function(){var t=this;return s(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n,o){t.runAfterInit((function(){if(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)}))}))];case 1:return[2,n.sent()]}}))}))},t.prototype.getItem=function(e){var t;if(this.storageInitialized){if(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)}}else t=null;return this.parseJson(t)},t.prototype.setItem=function(e,t){var n=this;this.runAfterInit((function(){if(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(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){this.storageInitialized?e():this.onStorageInitFuncs.push(e)},t}(function(){function e(){}return e.prototype.parseJson=function(e){return null!=e?JSON.parse(e):null},e}()),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 r(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storageImpl.getItemAsync(e)];case 1:return[2,t.sent()]}}))}))},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},185:(e,t)=>{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}},330:e=>{e.exports=JSON.parse('{"rE":"1.4.1-beta.1"}')}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,n),s.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.AvoInspectorEnv=e.AvoInspector=void 0;var t=n(611);Object.defineProperty(e,"AvoInspector",{enumerable:!0,get:function(){return t.AvoInspector}});var r=n(844);Object.defineProperty(e,"AvoInspectorEnv",{enumerable:!0,get:function(){return r.AvoInspectorEnv}})})(),o})()));
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "avo-inspector",
3
- "version": "1.3.0",
3
+ "version": "1.4.1-beta.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/index.js",
7
- "react-native": "dist-native/index.js",
8
7
  "types": "dist/index.d.ts",
9
8
  "scripts": {
10
- "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",
11
- "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",
12
- "build-native": "tsc --outDir dist-native",
9
+ "build": "tsc --emitDeclarationOnly && webpack --config webpack.config.js",
10
+ "build-for-script-tag": "tsc --outDir dist-browser --emitDeclarationOnly && webpack --config webpack.browserConfig.js",
11
+ "lint": "eslint ./src --ext .js,.ts",
13
12
  "test": "jest",
14
13
  "test:browser": "BROWSER=1 jest",
15
14
  "typecheck": "tsc --noEmit"
@@ -19,6 +18,7 @@
19
18
  "url": "git+https://github.com/avohq/web-avo-inspector.git"
20
19
  },
21
20
  "jest": {
21
+ "testEnvironment": "jsdom",
22
22
  "transform": {
23
23
  "^.+\\.[j]sx?$": "babel-jest",
24
24
  "^.+\\.[t]sx?$": "ts-jest"
@@ -42,7 +42,6 @@
42
42
  "analytics",
43
43
  "avo",
44
44
  "react",
45
- "react-native",
46
45
  "node",
47
46
  "javascript"
48
47
  ],
@@ -53,24 +52,22 @@
53
52
  },
54
53
  "homepage": "https://github.com/avohq/web-avo-inspector#readme",
55
54
  "devDependencies": {
56
- "@babel/core": "7.12.10",
57
- "@babel/preset-env": "7.12.11",
58
- "@types/jest": "26.0.19",
59
- "@types/node": "14.14.16",
60
- "babel-preset-es2015": "6.24.1",
61
- "babel-preset-react": "6.24.1",
62
- "eslint": "7.16.0",
63
- "eslint-plugin-react": "7.21.5",
64
- "jest": "26.6.3",
65
- "prettier": "2.2.1",
66
- "prettier-eslint": "12.0.0",
67
- "ts-jest": "26.4.4",
68
- "ts-loader": "8.0.12",
69
- "typescript": "4.1.3",
70
- "webpack": "4.44.2",
71
- "webpack-cli": "3.3.12"
72
- },
73
- "externals": [
74
- "react-native"
75
- ]
55
+ "@babel/core": "^7.25.2",
56
+ "@babel/preset-env": "^7.25.3",
57
+ "@types/jest": "^29.5.12",
58
+ "@types/node": "^22.3.0",
59
+ "@typescript-eslint/eslint-plugin": "^8.1.0",
60
+ "eslint": "^9.9.0",
61
+ "eslint-config-standard-with-typescript": "^43.0.1",
62
+ "eslint-plugin-import": "^2.29.1",
63
+ "eslint-plugin-n": "^17.10.2",
64
+ "eslint-plugin-promise": "^7.1.0",
65
+ "jest": "^29.7.0",
66
+ "jest-environment-jsdom": "^29.7.0",
67
+ "ts-jest": "^29.2.4",
68
+ "ts-loader": "^9.5.1",
69
+ "typescript": "*",
70
+ "webpack": "^5.93.0",
71
+ "webpack-cli": "^5.1.4"
72
+ }
76
73
  }
@@ -0,0 +1,26 @@
1
+ const webpack = require('webpack');
2
+
3
+ module.exports = {
4
+ mode: 'production',
5
+ entry: './src/browser.js',
6
+ resolve: {
7
+ extensions: [".ts"],
8
+ },
9
+ module: {
10
+ rules: [
11
+ {
12
+ test: /\.ts$/,
13
+ use: "ts-loader",
14
+ },
15
+ ],
16
+ },
17
+ plugins: [
18
+ new webpack.DefinePlugin({
19
+ 'process.env.BROWSER': JSON.stringify(1),
20
+ }),
21
+ ],
22
+ output: {
23
+ filename: "browser.js",
24
+ libraryTarget: "umd",
25
+ },
26
+ };
@@ -0,0 +1,26 @@
1
+ const webpack = require('webpack');
2
+
3
+ module.exports = {
4
+ mode: 'production',
5
+ entry: './src/index.ts',
6
+ resolve: {
7
+ extensions: [".ts"],
8
+ },
9
+ module: {
10
+ rules: [
11
+ {
12
+ test: /\.ts$/,
13
+ use: "ts-loader",
14
+ },
15
+ ],
16
+ },
17
+ plugins: [
18
+ new webpack.DefinePlugin({
19
+ 'process.env.BROWSER': JSON.stringify(1),
20
+ }),
21
+ ],
22
+ output: {
23
+ filename: "index.js",
24
+ libraryTarget: "umd",
25
+ },
26
+ };
@@ -1,45 +0,0 @@
1
- name: Avo Inspector
2
-
3
- on:
4
- pull_request:
5
- types: [opened, reopened, unlocked, synchronize]
6
- paths:
7
- - 'src/**'
8
-
9
- jobs:
10
- test:
11
- name: Test
12
- runs-on: macos-latest
13
-
14
- strategy:
15
- matrix:
16
- node-version: [10.x, 12.x]
17
-
18
- steps:
19
- - name: Checkout repository
20
- uses: actions/checkout@v2
21
-
22
- - name: Set up Node version
23
- uses: actions/setup-node@v1
24
- with:
25
- node-version: ${{ matrix.node-version }}
26
-
27
- - name: Set up Node cache for Avo Inspector
28
- uses: actions/cache@v1
29
- id: yarn-cache-avo-inspector
30
- with:
31
- path: node_modules
32
- key: ${{ runner.os }}-inspector-node-modules-${{ hashFiles('yarn.lock') }}
33
- restore-keys: |
34
- ${{ runner.os }}-inspector-node-modules-${{ hashFiles('yarn.lock') }}
35
-
36
- - name: Install yarn dependencies
37
- if: steps.yarn-cache-avo-inspector.outputs.cache-hit != 'true'
38
- run: yarn install --frozen-lockfile --network-timeout 1000000
39
-
40
- - name: Build Avo Inspector package
41
- run: yarn build
42
-
43
- - name: Test Source
44
- run: |
45
- yarn test:browser src/ --silent
@@ -1,15 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "pwa-chrome",
9
- "request": "launch",
10
- "name": "Launch Chrome against localhost",
11
- "url": "http://localhost:8080",
12
- "webRoot": "${workspaceFolder}"
13
- }
14
- ]
15
- }
package/dist/main.js DELETED
@@ -1 +0,0 @@
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"]}')}])}));