avo-inspector 2.2.0-alpha.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/CHANGELOG.md +1 -1
  3. package/dist/index.js +1 -1
  4. package/package.json +1 -1
  5. package/dist-native/AvoBatcher.d.ts +0 -24
  6. package/dist-native/AvoBatcher.js +0 -82
  7. package/dist-native/AvoDeduplicator.d.ts +0 -36
  8. package/dist-native/AvoDeduplicator.js +0 -142
  9. package/dist-native/AvoGuid.d.ts +0 -3
  10. package/dist-native/AvoGuid.js +0 -14
  11. package/dist-native/AvoInspector.d.ts +0 -52
  12. package/dist-native/AvoInspector.js +0 -220
  13. package/dist-native/AvoInspectorEnv.d.ts +0 -7
  14. package/dist-native/AvoInspectorEnv.js +0 -8
  15. package/dist-native/AvoInstallationId.d.ts +0 -5
  16. package/dist-native/AvoInstallationId.js +0 -36
  17. package/dist-native/AvoNetworkCallsHandler.d.ts +0 -48
  18. package/dist-native/AvoNetworkCallsHandler.js +0 -142
  19. package/dist-native/AvoSchemaParser.d.ts +0 -11
  20. package/dist-native/AvoSchemaParser.js +0 -95
  21. package/dist-native/AvoSessionTracker.d.ts +0 -15
  22. package/dist-native/AvoSessionTracker.js +0 -104
  23. package/dist-native/AvoStorage.d.ts +0 -22
  24. package/dist-native/AvoStorage.js +0 -336
  25. package/dist-native/__mocks__/xhr.d.ts +0 -12
  26. package/dist-native/__mocks__/xhr.js +0 -14
  27. package/dist-native/__mocks__/xhrError.d.ts +0 -12
  28. package/dist-native/__mocks__/xhrError.js +0 -14
  29. package/dist-native/__tests__/AvoInspector.d.ts +0 -1
  30. package/dist-native/__tests__/AvoInspector.js +0 -207
  31. package/dist-native/__tests__/Batcher.d.ts +0 -1
  32. package/dist-native/__tests__/Batcher.js +0 -280
  33. package/dist-native/__tests__/BatcherPublic.d.ts +0 -1
  34. package/dist-native/__tests__/BatcherPublic.js +0 -82
  35. package/dist-native/__tests__/Deduplicator.d.ts +0 -1
  36. package/dist-native/__tests__/Deduplicator.js +0 -111
  37. package/dist-native/__tests__/InstallationId.d.ts +0 -1
  38. package/dist-native/__tests__/InstallationId.js +0 -40
  39. package/dist-native/__tests__/NetworkCallsHandler.d.ts +0 -1
  40. package/dist-native/__tests__/NetworkCallsHandler.js +0 -132
  41. package/dist-native/__tests__/Parsing.d.ts +0 -1
  42. package/dist-native/__tests__/Parsing.js +0 -115
  43. package/dist-native/__tests__/Sessions.d.ts +0 -1
  44. package/dist-native/__tests__/Sessions.js +0 -179
  45. package/dist-native/__tests__/Storage.d.ts +0 -1
  46. package/dist-native/__tests__/Storage.js +0 -173
  47. package/dist-native/__tests__/constants.d.ts +0 -36
  48. package/dist-native/__tests__/constants.js +0 -47
  49. package/dist-native/index.d.ts +0 -2
  50. package/dist-native/index.js +0 -7
  51. package/dist-native/utils.d.ts +0 -3
  52. package/dist-native/utils.js +0 -42
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm test)"
5
+ ],
6
+ "deny": [],
7
+ "ask": []
8
+ }
9
+ }
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 2.2.0-alpha.1
1
+ ## 2.2.0
2
2
 
3
3
  - Add anonymous ID support to track events without user identification
4
4
 
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 o=t();for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(self,(()=>(()=>{"use strict";var e={470:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoAnonymousId=void 0;var n=o(249),r=o(611),s=function(){function e(){}return Object.defineProperty(e,"anonymousId",{get:function(){if(null!==e._anonymousId)return e._anonymousId;if(!r.AvoInspector.avoStorage.isInitialized())return"unknown";var t=null;try{t=r.AvoInspector.avoStorage.getItem(e.storageKey)}catch(e){console.error("Avo Inspector: Error reading anonymous ID from storage. Please report to support@avo.app.",e)}if(null==t){e._anonymousId=n.default.newGuid();try{r.AvoInspector.avoStorage.setItem(e.storageKey,e._anonymousId)}catch(e){console.error("Avo Inspector: Error saving anonymous ID to storage. Please report to support@avo.app.",e)}}else e._anonymousId=t;return e._anonymousId},enumerable:!1,configurable:!0}),Object.defineProperty(e,"storageKey",{get:function(){return"AvoInspectorAnonymousId"},enumerable:!1,configurable:!0}),e.clearCache=function(){e._anonymousId=null},e._anonymousId=null,e}();t.AvoAnonymousId=s},669:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoBatcher=void 0;var n=o(611),r=function(){function e(t){var o=this;this.events=[],this.networkCallsHandler=t,this.batchFlushAttemptTimestamp=Date.now(),n.AvoInspector.avoStorage.getItemAsync(e.cacheKey).then((function(e){if(null!==e){var t=e.filter((function(e){return null!==e}));o.events=o.events.concat(t),o.checkIfBatchNeedsToBeSent()}})).catch((function(e){console.error("Avo Inspector: error getting events from cache",e)}))}return e.prototype.handleSessionStarted=function(){this.events.push(this.networkCallsHandler.bodyForSessionStartedCall()),this.saveEvents(),this.checkIfBatchNeedsToBeSent()},e.prototype.handleTrackSchema=function(e,t,o,r){this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(e,t,o,r)),this.saveEvents(),n.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(),o=t-this.batchFlushAttemptTimestamp,r=e%n.AvoInspector.batchSize==0,s=o>=1e3*n.AvoInspector.batchFlushSeconds,a=this;if(r||s){this.batchFlushAttemptTimestamp=t;var i=a.events;a.events=[],this.networkCallsHandler.callInspectorWithBatchBody(i,(function(e){null!=e?(a.events=a.events.concat(i),n.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sending failed: "+e.message+". We will attempt to send your schemas with next batch")):n.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sent successfully."),a.saveEvents()}))}},e.prototype.saveEvents=function(){if(this.events.length>1e3){var t=this.events.length-1e3;this.events.splice(0,t)}n.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,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoDeduplicator=void 0;var n=o(924),r=o(185),s=function(){function e(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}}return e.prototype.shouldRegisterEvent=function(e,t,o){this.clearOldEvents(),o?(this.avoFunctionsEvents[Date.now()]=e,this.avoFunctionsEventsParams[e]=t):(this.manualEvents[Date.now()]=e,this.manualEventsParams[e]=t);var n=!o;return!this.hasSameEventAs(e,t,n)},e.prototype.hasSameEventAs=function(e,t,o){var n=!1;return o?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},e.prototype.lookForEventIn=function(e,t,o){for(var n in o)if(o.hasOwnProperty(n)&&n===e){var s=o[e];if(s&&(0,r.deepEquals)(t,s))return!0}return!1},e.prototype.hasSeenEventParams=function(e,t){var o=!1;return t?this.lookForEventParamsIn(e,this.avoFunctionsEventsParams)&&(o=!0):this.lookForEventParamsIn(e,this.manualEventsParams)&&(o=!0),o},e.prototype.lookForEventParamsIn=function(e,t){for(var o in t)if(t.hasOwnProperty(o)){var n=t[o];if(n&&(0,r.deepEquals)(e,n))return!0}return!1},e.prototype.shouldRegisterSchemaFromManually=function(e,t){return this.clearOldEvents(),!this.hasSameShapeInAvoFunctionsAs(e,t)},e.prototype.hasSameShapeInAvoFunctionsAs=function(e,t){var o=!1;return this.lookForEventSchemaIn(e,t,this.avoFunctionsEventsParams)&&(o=!0),o&&delete this.avoFunctionsEventsParams[e],o},e.prototype.lookForEventSchemaIn=function(e,t,o){for(var s in o)if(o.hasOwnProperty(s)&&s===e){var a=n.AvoSchemaParser.extractSchema(o[e]);if(a&&(0,r.deepEquals)(t,a))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 o=this.avoFunctionsEvents[t];delete this.avoFunctionsEvents[t],delete this.avoFunctionsEventsParams[o]}for(var t in this.manualEvents)this.manualEvents.hasOwnProperty(t)&&e-(Number(t)||0)>300&&(o=this.manualEvents[t],delete this.manualEvents[t],delete this.manualEventsParams[o])},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 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},611:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspector=void 0;var n=o(844),r=o(924),s=o(669),a=o(243),i=o(491),u=o(492),c=o(185),l=o(330).rE,p=function(){function e(t){if((0,c.isValueEmpty)(t.env)?(this.environment=n.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] No environment provided. Defaulting to dev.")):Object.values(n.AvoInspectorEnv).includes(t.env)?this.environment=t.env:(this.environment=n.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.")),(0,c.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,c.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===n.AvoInspectorEnv.Dev?(e._batchSize=1,e._shouldLog=!0):(e._batchSize=30,e._batchFlushSeconds=30,e._shouldLog=!1),e.avoStorage=new i.AvoStorage(e._shouldLog,null!=t.suffix?t.suffix:"");var o=new a.AvoNetworkCallsHandler(this.apiKey,this.environment.toString(),t.appName||"",this.version,l);this.avoBatcher=new s.AvoBatcher(o),this.avoDeduplicator=new u.AvoDeduplicator}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}),Object.defineProperty(e,"networkTimeout",{get:function(){return this._networkTimeout},set:function(e){this._networkTimeout=e},enumerable:!1,configurable:!0}),e.prototype.trackSchemaFromEvent=function(t,o){try{if(this.avoDeduplicator.shouldRegisterEvent(t,o,!1)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(o));var n=this.extractSchema(o,!1);return this.trackSchemaInternal(t,n,null,null),n}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,o,n,r){try{if(this.avoDeduplicator.shouldRegisterEvent(t,o,!0)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(o));var s=this.extractSchema(o,!1);return this.trackSchemaInternal(t,s,n,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,o){try{this.avoDeduplicator.shouldRegisterSchemaFromManually(t,o)?(e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with schema "+JSON.stringify(o)),this.trackSchemaInternal(t,o,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,o,n){try{this.avoBatcher.handleTrackSchema(e,t,o,n)}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,o){void 0===o&&(o=!0);try{return this.avoDeduplicator.hasSeenEventParams(t,!0)&&o&&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._networkTimeout=2e3,e}();t.AvoInspector=p},844:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv=void 0,t.AvoInspectorEnv={Prod:"prod",Dev:"dev",Staging:"staging"}},243:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoNetworkCallsHandler=void 0;var n=o(249),r=o(611),s=o(470),a=function(){function e(e,t,o,n,r){this.samplingRate=1,this.sending=!1,this.apiKey=e,this.envName=t,this.appName=o,this.appVersion=n,this.libVersion=r}return e.prototype.callInspectorWithBatchBody=function(t,o){var n=this;if(this.sending)o(new Error("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.fixAnonymousIds(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 a=new XMLHttpRequest;a.open("POST",e.trackingEndpoint,!0),a.setRequestHeader("Content-Type","text/plain"),a.timeout=r.AvoInspector.networkTimeout,a.send(JSON.stringify(s)),a.onload=function(){if(200!==a.status)o(new Error("Error ".concat(a.status,": ").concat(a.statusText)));else{var e=JSON.parse(a.response).samplingRate;void 0!==e&&(n.samplingRate=e),o(null)}n.sending=!1},a.onerror=function(){o(new Error("Request failed")),n.sending=!1},a.ontimeout=function(){o(new Error("Request timed out")),n.sending=!1}}}},e.prototype.fixAnonymousIds=function(e){var t=null;e.forEach((function(e){null!==e.anonymousId&&void 0!==e.anonymousId&&"unknown"!==e.anonymousId&&(t=e.anonymousId)})),e.forEach((function(e){"unknown"===e.anonymousId&&(e.anonymousId=null!=t?t:s.AvoAnonymousId.anonymousId)}))},e.prototype.bodyForSessionStartedCall=function(){var e=this.createBaseCallBody();return e.type="sessionStarted",e},e.prototype.bodyForEventSchemaCall=function(e,t,o,n){var r=this.createBaseCallBody();return r.type="event",r.eventName=e,r.eventProperties=t,null!=o?(r.avoFunction=!0,r.eventId=o,r.eventHash=n):(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:n.default.newGuid(),trackingId:"",createdAt:(new Date).toISOString(),sessionId:"",anonymousId:s.AvoAnonymousId.anonymousId,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 o=function(e){return"[object Array]"===Object.prototype.toString.call(e)},n=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 a in e)if(e.hasOwnProperty(a)){var i=e[a],u={propertyName:a,propertyType:t.getPropValueType(i)};"object"==typeof i&&null!=i&&(u.children=n(i)),s.push(u)}return s}return t.getPropValueType(e)};return n(e)},e.removeDuplicates=function(e){var t={boolean:{},number:{},string:{}},o=[];return e.filter((function(e){var n=typeof e;return n in t?!t[n].hasOwnProperty(e)&&(t[n][e]=!0):!o.includes(e)&&o.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?o(e)?"list":"object":"unknown"},e}();t.AvoSchemaParser=n},491:function(e,t){var o,n=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 o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(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 n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),r=this&&this.__awaiter||function(e,t,o,n){return new(o||(o=Promise))((function(r,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function i(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,i)}u((n=n.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var o,n,r,s,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(u){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(a=0)),a;)try{if(o=1,n&&(r=2&i[0]?n.return:i[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,i[1])).done)return r;switch(n=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{o=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.AvoStorage=void 0;var a=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 n(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(o){switch(o.label){case 0:return[4,new Promise((function(o,n){t.runAfterInit((function(){if(t.useFallbackStorage){var n=t.fallbackStorage[e+t.suffix];o(t.parseJson(n))}else if("undefined"!=typeof window){n=void 0;try{n=window.localStorage.getItem(e+t.suffix)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage getItemAsync error:",e),o(null)}o(t.parseJson(n))}else o(null)}))}))];case 1:return[2,o.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 o=this;this.runAfterInit((function(){if(o.useFallbackStorage)o.fallbackStorage[e+o.suffix]=JSON.stringify(t);else if("undefined"!=typeof window)try{window.localStorage.setItem(e+o.suffix,JSON.stringify(t))}catch(e){o.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}()),i=function(){function e(e,t){void 0===t&&(t=""),this.Platform=null,this.Platform="browser",this.storageImpl=new a,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=i},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,o){if(t===o)return!0;if(!(t instanceof Object&&o instanceof Object))return!1;if(t.constructor!==o.constructor)return!1;for(var n in t)if(t.hasOwnProperty(n)){if(!o.hasOwnProperty(n))return!1;if(t[n]!==o[n]){if("object"!=typeof t[n])return!1;if(!e(t[n],o[n]))return!1}}for(n in o)if(o.hasOwnProperty(n)&&!t.hasOwnProperty(n))return!1;return!0}},330:e=>{e.exports=JSON.parse('{"rE":"2.2.0-alpha.1"}')}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,o),s.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.AvoInspectorEnv=e.AvoInspector=void 0;var t=o(611);Object.defineProperty(e,"AvoInspector",{enumerable:!0,get:function(){return t.AvoInspector}});var r=o(844);Object.defineProperty(e,"AvoInspectorEnv",{enumerable:!0,get:function(){return r.AvoInspectorEnv}})})(),n})()));
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 o=t();for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(self,(()=>(()=>{"use strict";var e={470:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoAnonymousId=void 0;var n=o(249),r=o(611),s=function(){function e(){}return Object.defineProperty(e,"anonymousId",{get:function(){if(null!==e._anonymousId)return e._anonymousId;if(!r.AvoInspector.avoStorage.isInitialized())return"unknown";var t=null;try{t=r.AvoInspector.avoStorage.getItem(e.storageKey)}catch(e){console.error("Avo Inspector: Error reading anonymous ID from storage. Please report to support@avo.app.",e)}if(null==t){e._anonymousId=n.default.newGuid();try{r.AvoInspector.avoStorage.setItem(e.storageKey,e._anonymousId)}catch(e){console.error("Avo Inspector: Error saving anonymous ID to storage. Please report to support@avo.app.",e)}}else e._anonymousId=t;return e._anonymousId},enumerable:!1,configurable:!0}),Object.defineProperty(e,"storageKey",{get:function(){return"AvoInspectorAnonymousId"},enumerable:!1,configurable:!0}),e.clearCache=function(){e._anonymousId=null},e._anonymousId=null,e}();t.AvoAnonymousId=s},669:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoBatcher=void 0;var n=o(611),r=function(){function e(t){var o=this;this.events=[],this.networkCallsHandler=t,this.batchFlushAttemptTimestamp=Date.now(),n.AvoInspector.avoStorage.getItemAsync(e.cacheKey).then((function(e){if(null!==e){var t=e.filter((function(e){return null!==e}));o.events=o.events.concat(t),o.checkIfBatchNeedsToBeSent()}})).catch((function(e){console.error("Avo Inspector: error getting events from cache",e)}))}return e.prototype.handleSessionStarted=function(){this.events.push(this.networkCallsHandler.bodyForSessionStartedCall()),this.saveEvents(),this.checkIfBatchNeedsToBeSent()},e.prototype.handleTrackSchema=function(e,t,o,r){this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(e,t,o,r)),this.saveEvents(),n.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(),o=t-this.batchFlushAttemptTimestamp,r=e%n.AvoInspector.batchSize==0,s=o>=1e3*n.AvoInspector.batchFlushSeconds,a=this;if(r||s){this.batchFlushAttemptTimestamp=t;var i=a.events;a.events=[],this.networkCallsHandler.callInspectorWithBatchBody(i,(function(e){null!=e?(a.events=a.events.concat(i),n.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sending failed: "+e.message+". We will attempt to send your schemas with next batch")):n.AvoInspector.shouldLog&&console.log("Avo Inspector: batch sent successfully."),a.saveEvents()}))}},e.prototype.saveEvents=function(){if(this.events.length>1e3){var t=this.events.length-1e3;this.events.splice(0,t)}n.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,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoDeduplicator=void 0;var n=o(924),r=o(185),s=function(){function e(){this.avoFunctionsEvents={},this.manualEvents={},this.avoFunctionsEventsParams={},this.manualEventsParams={}}return e.prototype.shouldRegisterEvent=function(e,t,o){this.clearOldEvents(),o?(this.avoFunctionsEvents[Date.now()]=e,this.avoFunctionsEventsParams[e]=t):(this.manualEvents[Date.now()]=e,this.manualEventsParams[e]=t);var n=!o;return!this.hasSameEventAs(e,t,n)},e.prototype.hasSameEventAs=function(e,t,o){var n=!1;return o?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},e.prototype.lookForEventIn=function(e,t,o){for(var n in o)if(o.hasOwnProperty(n)&&n===e){var s=o[e];if(s&&(0,r.deepEquals)(t,s))return!0}return!1},e.prototype.hasSeenEventParams=function(e,t){var o=!1;return t?this.lookForEventParamsIn(e,this.avoFunctionsEventsParams)&&(o=!0):this.lookForEventParamsIn(e,this.manualEventsParams)&&(o=!0),o},e.prototype.lookForEventParamsIn=function(e,t){for(var o in t)if(t.hasOwnProperty(o)){var n=t[o];if(n&&(0,r.deepEquals)(e,n))return!0}return!1},e.prototype.shouldRegisterSchemaFromManually=function(e,t){return this.clearOldEvents(),!this.hasSameShapeInAvoFunctionsAs(e,t)},e.prototype.hasSameShapeInAvoFunctionsAs=function(e,t){var o=!1;return this.lookForEventSchemaIn(e,t,this.avoFunctionsEventsParams)&&(o=!0),o&&delete this.avoFunctionsEventsParams[e],o},e.prototype.lookForEventSchemaIn=function(e,t,o){for(var s in o)if(o.hasOwnProperty(s)&&s===e){var a=n.AvoSchemaParser.extractSchema(o[e]);if(a&&(0,r.deepEquals)(t,a))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 o=this.avoFunctionsEvents[t];delete this.avoFunctionsEvents[t],delete this.avoFunctionsEventsParams[o]}for(var t in this.manualEvents)this.manualEvents.hasOwnProperty(t)&&e-(Number(t)||0)>300&&(o=this.manualEvents[t],delete this.manualEvents[t],delete this.manualEventsParams[o])},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 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},611:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspector=void 0;var n=o(844),r=o(924),s=o(669),a=o(243),i=o(491),u=o(492),c=o(185),l=o(330).rE,p=function(){function e(t){if((0,c.isValueEmpty)(t.env)?(this.environment=n.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] No environment provided. Defaulting to dev.")):Object.values(n.AvoInspectorEnv).includes(t.env)?this.environment=t.env:(this.environment=n.AvoInspectorEnv.Dev,console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.")),(0,c.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,c.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===n.AvoInspectorEnv.Dev?(e._batchSize=1,e._shouldLog=!0):(e._batchSize=30,e._batchFlushSeconds=30,e._shouldLog=!1),e.avoStorage=new i.AvoStorage(e._shouldLog,null!=t.suffix?t.suffix:"");var o=new a.AvoNetworkCallsHandler(this.apiKey,this.environment.toString(),t.appName||"",this.version,l);this.avoBatcher=new s.AvoBatcher(o),this.avoDeduplicator=new u.AvoDeduplicator}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}),Object.defineProperty(e,"networkTimeout",{get:function(){return this._networkTimeout},set:function(e){this._networkTimeout=e},enumerable:!1,configurable:!0}),e.prototype.trackSchemaFromEvent=function(t,o){try{if(this.avoDeduplicator.shouldRegisterEvent(t,o,!1)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(o));var n=this.extractSchema(o,!1);return this.trackSchemaInternal(t,n,null,null),n}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,o,n,r){try{if(this.avoDeduplicator.shouldRegisterEvent(t,o,!0)){e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with params "+JSON.stringify(o));var s=this.extractSchema(o,!1);return this.trackSchemaInternal(t,s,n,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,o){try{this.avoDeduplicator.shouldRegisterSchemaFromManually(t,o)?(e.shouldLog&&console.log("Avo Inspector: supplied event "+t+" with schema "+JSON.stringify(o)),this.trackSchemaInternal(t,o,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,o,n){try{this.avoBatcher.handleTrackSchema(e,t,o,n)}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,o){void 0===o&&(o=!0);try{return this.avoDeduplicator.hasSeenEventParams(t,!0)&&o&&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._networkTimeout=2e3,e}();t.AvoInspector=p},844:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoInspectorEnv=void 0,t.AvoInspectorEnv={Prod:"prod",Dev:"dev",Staging:"staging"}},243:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AvoNetworkCallsHandler=void 0;var n=o(249),r=o(611),s=o(470),a=function(){function e(e,t,o,n,r){this.samplingRate=1,this.sending=!1,this.apiKey=e,this.envName=t,this.appName=o,this.appVersion=n,this.libVersion=r}return e.prototype.callInspectorWithBatchBody=function(t,o){var n=this;if(this.sending)o(new Error("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.fixAnonymousIds(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 a=new XMLHttpRequest;a.open("POST",e.trackingEndpoint,!0),a.setRequestHeader("Content-Type","text/plain"),a.timeout=r.AvoInspector.networkTimeout,a.send(JSON.stringify(s)),a.onload=function(){if(200!==a.status)o(new Error("Error ".concat(a.status,": ").concat(a.statusText)));else{var e=JSON.parse(a.response).samplingRate;void 0!==e&&(n.samplingRate=e),o(null)}n.sending=!1},a.onerror=function(){o(new Error("Request failed")),n.sending=!1},a.ontimeout=function(){o(new Error("Request timed out")),n.sending=!1}}}},e.prototype.fixAnonymousIds=function(e){var t=null;e.forEach((function(e){null!==e.anonymousId&&void 0!==e.anonymousId&&"unknown"!==e.anonymousId&&(t=e.anonymousId)})),e.forEach((function(e){"unknown"===e.anonymousId&&(e.anonymousId=null!=t?t:s.AvoAnonymousId.anonymousId)}))},e.prototype.bodyForSessionStartedCall=function(){var e=this.createBaseCallBody();return e.type="sessionStarted",e},e.prototype.bodyForEventSchemaCall=function(e,t,o,n){var r=this.createBaseCallBody();return r.type="event",r.eventName=e,r.eventProperties=t,null!=o?(r.avoFunction=!0,r.eventId=o,r.eventHash=n):(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:n.default.newGuid(),trackingId:"",createdAt:(new Date).toISOString(),sessionId:"",anonymousId:s.AvoAnonymousId.anonymousId,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 o=function(e){return"[object Array]"===Object.prototype.toString.call(e)},n=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 a in e)if(e.hasOwnProperty(a)){var i=e[a],u={propertyName:a,propertyType:t.getPropValueType(i)};"object"==typeof i&&null!=i&&(u.children=n(i)),s.push(u)}return s}return t.getPropValueType(e)};return n(e)},e.removeDuplicates=function(e){var t={boolean:{},number:{},string:{}},o=[];return e.filter((function(e){var n=typeof e;return n in t?!t[n].hasOwnProperty(e)&&(t[n][e]=!0):!o.includes(e)&&o.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?o(e)?"list":"object":"unknown"},e}();t.AvoSchemaParser=n},491:function(e,t){var o,n=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 o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(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 n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),r=this&&this.__awaiter||function(e,t,o,n){return new(o||(o=Promise))((function(r,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function i(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,i)}u((n=n.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var o,n,r,s,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(u){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(a=0)),a;)try{if(o=1,n&&(r=2&i[0]?n.return:i[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,i[1])).done)return r;switch(n=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{o=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.AvoStorage=void 0;var a=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 n(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(o){switch(o.label){case 0:return[4,new Promise((function(o,n){t.runAfterInit((function(){if(t.useFallbackStorage){var n=t.fallbackStorage[e+t.suffix];o(t.parseJson(n))}else if("undefined"!=typeof window){n=void 0;try{n=window.localStorage.getItem(e+t.suffix)}catch(e){t.shouldLog&&console.error("Avo Inspector Storage getItemAsync error:",e),o(null)}o(t.parseJson(n))}else o(null)}))}))];case 1:return[2,o.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 o=this;this.runAfterInit((function(){if(o.useFallbackStorage)o.fallbackStorage[e+o.suffix]=JSON.stringify(t);else if("undefined"!=typeof window)try{window.localStorage.setItem(e+o.suffix,JSON.stringify(t))}catch(e){o.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}()),i=function(){function e(e,t){void 0===t&&(t=""),this.Platform=null,this.Platform="browser",this.storageImpl=new a,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=i},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,o){if(t===o)return!0;if(!(t instanceof Object&&o instanceof Object))return!1;if(t.constructor!==o.constructor)return!1;for(var n in t)if(t.hasOwnProperty(n)){if(!o.hasOwnProperty(n))return!1;if(t[n]!==o[n]){if("object"!=typeof t[n])return!1;if(!e(t[n],o[n]))return!1}}for(n in o)if(o.hasOwnProperty(n)&&!t.hasOwnProperty(n))return!1;return!0}},330:e=>{e.exports={rE:"2.2.0"}}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,o),s.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.AvoInspectorEnv=e.AvoInspector=void 0;var t=o(611);Object.defineProperty(e,"AvoInspector",{enumerable:!0,get:function(){return t.AvoInspector}});var r=o(844);Object.defineProperty(e,"AvoInspectorEnv",{enumerable:!0,get:function(){return r.AvoInspectorEnv}})})(),n})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avo-inspector",
3
- "version": "2.2.0-alpha.1",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/index.js",
@@ -1,24 +0,0 @@
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
- }
@@ -1,82 +0,0 @@
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;
@@ -1,36 +0,0 @@
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
- }
@@ -1,142 +0,0 @@
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 && (0, 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 && (0, 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 && (0, 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;
@@ -1,3 +0,0 @@
1
- export default class AvoGuid {
2
- static newGuid(): string;
3
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var AvoGuid = /** @class */ (function () {
4
- function AvoGuid() {
5
- }
6
- AvoGuid.newGuid = function () {
7
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
8
- var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
9
- return v.toString(16);
10
- });
11
- };
12
- return AvoGuid;
13
- }());
14
- exports.default = AvoGuid;
@@ -1,52 +0,0 @@
1
- import { AvoInspectorEnvValueType } from "./AvoInspectorEnv";
2
- import { AvoSessionTracker } from "./AvoSessionTracker";
3
- import { AvoBatcher } from "./AvoBatcher";
4
- import { AvoStorage } from "./AvoStorage";
5
- import { AvoDeduplicator } from "./AvoDeduplicator";
6
- export declare class AvoInspector {
7
- environment: AvoInspectorEnvValueType;
8
- avoBatcher: AvoBatcher;
9
- avoDeduplicator: AvoDeduplicator;
10
- sessionTracker: AvoSessionTracker;
11
- apiKey: string;
12
- version: string;
13
- static avoStorage: AvoStorage;
14
- private static _batchSize;
15
- static get batchSize(): number;
16
- static set batchSize(newSize: number);
17
- private static _batchFlushSeconds;
18
- static get batchFlushSeconds(): number;
19
- private static _shouldLog;
20
- static get shouldLog(): boolean;
21
- static set shouldLog(enable: boolean);
22
- constructor(options: {
23
- apiKey: string;
24
- env: AvoInspectorEnvValueType;
25
- version: string;
26
- appName?: string;
27
- });
28
- trackSchemaFromEvent(eventName: string, eventProperties: {
29
- [propName: string]: any;
30
- }): Array<{
31
- propertyName: string;
32
- propertyType: string;
33
- children?: any;
34
- }>;
35
- private _avoFunctionTrackSchemaFromEvent;
36
- trackSchema(eventName: string, eventSchema: Array<{
37
- propertyName: string;
38
- propertyType: string;
39
- children?: any;
40
- }>): void;
41
- private trackSchemaInternal;
42
- enableLogging(enable: boolean): void;
43
- extractSchema(eventProperties: {
44
- [propName: string]: any;
45
- }, shouldLogIfEnabled?: boolean): Array<{
46
- propertyName: string;
47
- propertyType: string;
48
- children?: any;
49
- }>;
50
- setBatchSize(newBatchSize: number): void;
51
- setBatchFlushSeconds(newBatchFlushSeconds: number): void;
52
- }