posthog-js 1.184.2 → 1.185.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.full.es5.js +1 -1
- package/dist/array.full.es5.js.map +1 -1
- package/dist/array.full.js +1 -1
- package/dist/array.full.js.map +1 -1
- package/dist/array.full.no-external.js +1 -1
- package/dist/array.full.no-external.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.full.js +1 -1
- package/dist/module.full.js.map +1 -1
- package/dist/module.full.no-external.js +1 -1
- package/dist/module.full.no-external.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags.d.ts +2 -0
- package/dist/src/utils/event-utils.d.ts +1 -0
- package/lib/package.json +1 -1
- package/lib/src/config.js +2 -2
- package/lib/src/config.js.map +1 -1
- package/lib/src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags.d.ts +2 -0
- package/lib/src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags.js +13 -0
- package/lib/src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags.js.map +1 -0
- package/lib/src/utils/event-utils.d.ts +1 -0
- package/lib/src/utils/event-utils.js +18 -0
- package/lib/src/utils/event-utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(){"use strict";const e={DEBUG:!1,LIB_VERSION:"1.184.2"},t=Array.isArray,i=Object.prototype,s=i.hasOwnProperty,n=i.toString,r=t||function(e){return"[object Array]"===n.call(e)},o=function(e){return"function"==typeof e},a=function(e){return e===Object(e)&&!r(e)},l=function(e){if(a(e)){for(const t in e)if(s.call(e,t))return!1;return!0}return!1},c=function(e){return void 0===e},u=function(e){return"[object String]"==n.call(e)},d=function(e){return u(e)&&0===e.trim().length},h=function(e){return null===e},_=function(e){return c(e)||h(e)},p=function(e){return"[object Number]"==n.call(e)},g=function(e){return"[object Boolean]"===n.call(e)},f=e=>e instanceof FormData,v="undefined"!=typeof window?window:void 0,m="undefined"!=typeof globalThis?globalThis:v,y=Array.prototype,b=y.forEach,w=y.indexOf,S=null==m?void 0:m.navigator,k=null==m?void 0:m.document,E=null==m?void 0:m.location,x=null==m?void 0:m.fetch,I=null!=m&&m.XMLHttpRequest&&"withCredentials"in new m.XMLHttpRequest?m.XMLHttpRequest:void 0,R=null==m?void 0:m.AbortController,F=null==S?void 0:S.userAgent,P=null!=v?v:{},C="[PostHog.js]",T={_log:function(t){if(v&&(e.DEBUG||P.POSTHOG_DEBUG)&&!c(v.console)&&v.console){const e="__rrweb_original__"in v.console[t]?v.console[t].__rrweb_original__:v.console[t];for(var i=arguments.length,s=new Array(i>1?i-1:0),n=1;n<i;n++)s[n-1]=arguments[n];e(C,...s)}},info:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];T._log("log",...t)},warn:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];T._log("warn",...t)},error:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];T._log("error",...t)},critical:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];console.error(C,...t)},uninitializedWarning:e=>{T.error(`You must initialize PostHog before calling ${e}`)}},$={},A=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function M(e,t,i){if(r(e))if(b&&e.forEach===b)e.forEach(t,i);else if("length"in e&&e.length===+e.length)for(let s=0,n=e.length;s<n;s++)if(s in e&&t.call(i,e[s],s)===$)return}function L(e,t,i){if(!_(e)){if(r(e))return M(e,t,i);if(f(e)){for(const s of e.entries())if(t.call(i,s[1],s[0])===$)return}else for(const n in e)if(s.call(e,n)&&t.call(i,e[n],n)===$)return}}const D=function(e){for(var t=arguments.length,i=new Array(t>1?t-1:0),s=1;s<t;s++)i[s-1]=arguments[s];return M(i,(function(t){for(const i in t)void 0!==t[i]&&(e[i]=t[i])})),e};function O(e,t){return-1!==e.indexOf(t)}function N(e){const t=Object.keys(e);let i=t.length;const s=new Array(i);for(;i--;)s[i]=[t[i],e[t[i]]];return s}const q=function(e){try{return e()}catch{return}},B=function(e){return function(){try{for(var t=arguments.length,i=new Array(t),s=0;s<t;s++)i[s]=arguments[s];return e.apply(this,i)}catch(e){T.critical("Implementation error. Please turn on debug mode and open a ticket on https://app.posthog.com/home#panel=support%3Asupport%3A."),T.critical(e)}}},H=function(e){const t={};return L(e,(function(e,i){u(e)&&e.length>0&&(t[i]=e)})),t},U=function(e){return e.replace(/^\$/,"")};function W(e,t){return function(e,t){const i=new Set;return function e(s,n){if(s!==Object(s))return t?t(s,n):s;if(i.has(s))return;let o;return i.add(s),r(s)?(o=[],M(s,(t=>{o.push(e(t))}))):(o={},L(s,((t,s)=>{i.has(t)||(o[s]=e(t,s))}))),o}(e)}(e,(e=>u(e)&&!h(t)?e.slice(0,t):e))}const z=function(e){let t,i,s,n="",r=0;for(t=i=0,r=(e=(e+"").replace(/\r\n/g,"\n").replace(/\r/g,"\n")).length,s=0;s<r;s++){const r=e.charCodeAt(s);let o=null;r<128?i++:o=r>127&&r<2048?String.fromCharCode(r>>6|192,63&r|128):String.fromCharCode(r>>12|224,r>>6&63|128,63&r|128),h(o)||(i>t&&(n+=e.substring(t,i)),n+=o,t=i=s+1)}return i>t&&(n+=e.substring(t,e.length)),n},V=function(){function e(t){return t&&(t.preventDefault=e.preventDefault,t.stopPropagation=e.stopPropagation),t}return e.preventDefault=function(){this.returnValue=!1},e.stopPropagation=function(){this.cancelBubble=!0},function(t,i,s,n,r){if(t)if(t.addEventListener&&!n)t.addEventListener(i,s,!!r);else{const n="on"+i,r=t[n];t[n]=function(t,i,s){return function(n){if(!(n=n||e(null==v?void 0:v.event)))return;let r,a=!0;o(s)&&(r=s(n));const l=i.call(t,n);return!1!==r&&!1!==l||(a=!1),a}}(t,s,r)}else T.error("No valid element provided to register_event")}}();function G(e){const t=null==e?void 0:e.hostname;return!!u(t)&&"herokuapp.com"!==t.split(".").slice(-2).join(".")}function j(e,t){for(let i=0;i<e.length;i++)if(t(e[i]))return e[i]}let Q;!function(e){e.GZipJS="gzip-js",e.Base64="base64"}(Q||(Q={}));const J="$people_distinct_id",Y="__alias",X="__timers",K="$autocapture_disabled_server_side",Z="$heatmaps_enabled_server_side",ee="$exception_capture_enabled_server_side",te="$exception_capture_endpoint_suffix",ie="$web_vitals_enabled_server_side",se="$dead_clicks_enabled_server_side",ne="$web_vitals_allowed_metrics",re="$session_recording_enabled_server_side",oe="$console_log_recording_enabled_server_side",ae="$session_recording_network_payload_capture",le="$session_recording_canvas_recording",ce="$replay_sample_rate",ue="$replay_minimum_duration",de="$sesid",he="$session_is_sampled",_e="$session_recording_url_trigger_activated_session",pe="$session_recording_url_trigger_status",ge="$enabled_feature_flags",fe="$early_access_features",ve="$stored_person_properties",me="$stored_group_properties",ye="$surveys",be="$surveys_activated",we="$flag_call_reported",Se="$user_state",ke="$client_session_props",Ee="$capture_rate_limit",xe="$initial_campaign_params",Ie="$initial_referrer_info",Re="$initial_person_info",Fe="$epp",Pe="__POSTHOG_TOOLBAR__",Ce=[J,Y,"__cmpns",X,re,Z,de,ge,Se,fe,me,ve,ye,we,ke,Ee,xe,Ie,Fe],Te="$active_feature_flags",$e="$override_feature_flags",Ae="$feature_flag_payloads",Me=e=>{const t={};for(const[i,s]of N(e||{}))s&&(t[i]=s);return t};class Le{constructor(e){this.instance=e,this._override_warning=!1,this.featureFlagEventHandlers=[],this.reloadFeatureFlagsQueued=!1,this.reloadFeatureFlagsInAction=!1}getFlags(){return Object.keys(this.getFlagVariants())}getFlagVariants(){const e=this.instance.get_property(ge),t=this.instance.get_property($e);if(!t)return e||{};const i=D({},e),s=Object.keys(t);for(let e=0;e<s.length;e++)i[s[e]]=t[s[e]];return this._override_warning||(T.warn(" Overriding feature flags!",{enabledFlags:e,overriddenFlags:t,finalFlags:i}),this._override_warning=!0),i}getFlagPayloads(){return this.instance.get_property(Ae)||{}}reloadFeatureFlags(){this.reloadFeatureFlagsQueued||(this.reloadFeatureFlagsQueued=!0,this._startReloadTimer())}setAnonymousDistinctId(e){this.$anon_distinct_id=e}setReloadingPaused(e){this.reloadFeatureFlagsInAction=e}resetRequestQueue(){this.reloadFeatureFlagsQueued=!1}_startReloadTimer(){this.reloadFeatureFlagsQueued&&!this.reloadFeatureFlagsInAction&&setTimeout((()=>{!this.reloadFeatureFlagsInAction&&this.reloadFeatureFlagsQueued&&(this.reloadFeatureFlagsQueued=!1,this._reloadFeatureFlagsRequest())}),5)}_reloadFeatureFlagsRequest(){if(this.instance.config.advanced_disable_feature_flags)return;this.setReloadingPaused(!0);const e=this.instance.config.token,t=this.instance.get_property(ve),i=this.instance.get_property(me),s={token:e,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),$anon_distinct_id:this.$anon_distinct_id,person_properties:t,group_properties:i,disable_flags:this.instance.config.advanced_disable_feature_flags||void 0};this.instance._send_request({method:"POST",url:this.instance.requestRouter.endpointFor("api","/decide/?v=3"),data:s,compression:this.instance.config.disable_compression?void 0:Q.Base64,timeout:this.instance.config.feature_flag_request_timeout_ms,callback:e=>{var t;this.setReloadingPaused(!1);let i=!0;200===e.statusCode&&(this.$anon_distinct_id=void 0,i=!1),this.receivedFeatureFlags(null!==(t=e.json)&&void 0!==t?t:{},i),this._startReloadTimer()}})}getFeatureFlag(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0))return void T.warn('getFeatureFlag for key "'+e+"\" failed. Feature flags didn't load in time.");const i=this.getFlagVariants()[e],s=`${i}`,n=this.instance.get_property(we)||{};var o;!t.send_event&&"send_event"in t||(e in n&&n[e].includes(s)||(r(n[e])?n[e].push(s):n[e]=[s],null===(o=this.instance.persistence)||void 0===o||o.register({[we]:n}),this.instance.capture("$feature_flag_called",{$feature_flag:e,$feature_flag_response:i})));return i}getFeatureFlagPayload(e){return this.getFlagPayloads()[e]}isFeatureEnabled(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0)return!!this.getFeatureFlag(e,t);T.warn('isFeatureEnabled for key "'+e+"\" failed. Feature flags didn't load in time.")}addFeatureFlagsHandler(e){this.featureFlagEventHandlers.push(e)}removeFeatureFlagsHandler(e){this.featureFlagEventHandlers=this.featureFlagEventHandlers.filter((t=>t!==e))}receivedFeatureFlags(e,t){if(!this.instance.persistence)return;this.instance.decideEndpointWasHit=!0;const i=this.getFlagVariants(),s=this.getFlagPayloads();!function(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};const n=e.featureFlags,o=e.featureFlagPayloads;if(!n)return;if(r(n)){const e={};if(n)for(let t=0;t<n.length;t++)e[n[t]]=!0;return void(t&&t.register({[Te]:n,[ge]:e}))}let a=n,l=o;e.errorsWhileComputingFlags&&(a={...i,...a},l={...s,...l}),t&&t.register({[Te]:Object.keys(Me(a)),[ge]:a||{},[Ae]:l||{}})}(e,this.instance.persistence,i,s),this._fireFeatureFlagsCallbacks(t)}override(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.instance.__loaded||!this.instance.persistence)return T.uninitializedWarning("posthog.feature_flags.override");if(this._override_warning=t,!1===e)this.instance.persistence.unregister($e);else if(r(e)){const t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;this.instance.persistence.register({[$e]:t})}else this.instance.persistence.register({[$e]:e})}onFeatureFlags(e){if(this.addFeatureFlagsHandler(e),this.instance.decideEndpointWasHit){const{flags:t,flagVariants:i}=this._prepareFeatureFlagsForCallbacks();e(t,i)}return()=>this.removeFeatureFlagsHandler(e)}updateEarlyAccessFeatureEnrollment(e,t){var i;const s={[`$feature_enrollment/${e}`]:t};this.instance.capture("$feature_enrollment_update",{$feature_flag:e,$feature_enrollment:t,$set:s}),this.setPersonPropertiesForFlags(s,!1);const n={...this.getFlagVariants(),[e]:t};null===(i=this.instance.persistence)||void 0===i||i.register({[Te]:Object.keys(Me(n)),[ge]:n}),this._fireFeatureFlagsCallbacks()}getEarlyAccessFeatures(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.instance.get_property(fe);if(i&&!t)return e(i);this.instance._send_request({transport:"XHR",url:this.instance.requestRouter.endpointFor("api",`/api/early_access_features/?token=${this.instance.config.token}`),method:"GET",callback:t=>{var i;if(!t.json)return;const s=t.json.earlyAccessFeatures;return null===(i=this.instance.persistence)||void 0===i||i.register({[fe]:s}),e(s)}})}_prepareFeatureFlagsForCallbacks(){const e=this.getFlags(),t=this.getFlagVariants();return{flags:e.filter((e=>t[e])),flagVariants:Object.keys(t).filter((e=>t[e])).reduce(((e,i)=>(e[i]=t[i],e)),{})}}_fireFeatureFlagsCallbacks(e){const{flags:t,flagVariants:i}=this._prepareFeatureFlagsForCallbacks();this.featureFlagEventHandlers.forEach((s=>s(t,i,{errorsLoading:e})))}setPersonPropertiesForFlags(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const i=this.instance.get_property(ve)||{};this.instance.register({[ve]:{...i,...e}}),t&&this.instance.reloadFeatureFlags()}resetPersonPropertiesForFlags(){this.instance.unregister(ve)}setGroupPropertiesForFlags(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const i=this.instance.get_property(me)||{};0!==Object.keys(i).length&&Object.keys(i).forEach((t=>{i[t]={...i[t],...e[t]},delete e[t]})),this.instance.register({[me]:{...i,...e}}),t&&this.instance.reloadFeatureFlags()}resetGroupPropertiesForFlags(e){if(e){const t=this.instance.get_property(me)||{};this.instance.register({[me]:{...t,[e]:{}}})}else this.instance.unregister(me)}}
|
|
1
|
+
!function(){"use strict";const e={DEBUG:!1,LIB_VERSION:"1.185.0"},t=Array.isArray,i=Object.prototype,s=i.hasOwnProperty,n=i.toString,r=t||function(e){return"[object Array]"===n.call(e)},o=function(e){return"function"==typeof e},a=function(e){return e===Object(e)&&!r(e)},l=function(e){if(a(e)){for(const t in e)if(s.call(e,t))return!1;return!0}return!1},c=function(e){return void 0===e},u=function(e){return"[object String]"==n.call(e)},d=function(e){return u(e)&&0===e.trim().length},h=function(e){return null===e},_=function(e){return c(e)||h(e)},p=function(e){return"[object Number]"==n.call(e)},g=function(e){return"[object Boolean]"===n.call(e)},f=e=>e instanceof FormData,v="undefined"!=typeof window?window:void 0,m="undefined"!=typeof globalThis?globalThis:v,y=Array.prototype,b=y.forEach,w=y.indexOf,S=null==m?void 0:m.navigator,k=null==m?void 0:m.document,E=null==m?void 0:m.location,x=null==m?void 0:m.fetch,I=null!=m&&m.XMLHttpRequest&&"withCredentials"in new m.XMLHttpRequest?m.XMLHttpRequest:void 0,R=null==m?void 0:m.AbortController,F=null==S?void 0:S.userAgent,P=null!=v?v:{},C="[PostHog.js]",T={_log:function(t){if(v&&(e.DEBUG||P.POSTHOG_DEBUG)&&!c(v.console)&&v.console){const e="__rrweb_original__"in v.console[t]?v.console[t].__rrweb_original__:v.console[t];for(var i=arguments.length,s=new Array(i>1?i-1:0),n=1;n<i;n++)s[n-1]=arguments[n];e(C,...s)}},info:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];T._log("log",...t)},warn:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];T._log("warn",...t)},error:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];T._log("error",...t)},critical:function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];console.error(C,...t)},uninitializedWarning:e=>{T.error(`You must initialize PostHog before calling ${e}`)}},$={},A=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function M(e,t,i){if(r(e))if(b&&e.forEach===b)e.forEach(t,i);else if("length"in e&&e.length===+e.length)for(let s=0,n=e.length;s<n;s++)if(s in e&&t.call(i,e[s],s)===$)return}function L(e,t,i){if(!_(e)){if(r(e))return M(e,t,i);if(f(e)){for(const s of e.entries())if(t.call(i,s[1],s[0])===$)return}else for(const n in e)if(s.call(e,n)&&t.call(i,e[n],n)===$)return}}const D=function(e){for(var t=arguments.length,i=new Array(t>1?t-1:0),s=1;s<t;s++)i[s-1]=arguments[s];return M(i,(function(t){for(const i in t)void 0!==t[i]&&(e[i]=t[i])})),e};function O(e,t){return-1!==e.indexOf(t)}function N(e){const t=Object.keys(e);let i=t.length;const s=new Array(i);for(;i--;)s[i]=[t[i],e[t[i]]];return s}const q=function(e){try{return e()}catch{return}},B=function(e){return function(){try{for(var t=arguments.length,i=new Array(t),s=0;s<t;s++)i[s]=arguments[s];return e.apply(this,i)}catch(e){T.critical("Implementation error. Please turn on debug mode and open a ticket on https://app.posthog.com/home#panel=support%3Asupport%3A."),T.critical(e)}}},H=function(e){const t={};return L(e,(function(e,i){u(e)&&e.length>0&&(t[i]=e)})),t},U=function(e){return e.replace(/^\$/,"")};function W(e,t){return function(e,t){const i=new Set;return function e(s,n){if(s!==Object(s))return t?t(s,n):s;if(i.has(s))return;let o;return i.add(s),r(s)?(o=[],M(s,(t=>{o.push(e(t))}))):(o={},L(s,((t,s)=>{i.has(t)||(o[s]=e(t,s))}))),o}(e)}(e,(e=>u(e)&&!h(t)?e.slice(0,t):e))}const z=function(e){let t,i,s,n="",r=0;for(t=i=0,r=(e=(e+"").replace(/\r\n/g,"\n").replace(/\r/g,"\n")).length,s=0;s<r;s++){const r=e.charCodeAt(s);let o=null;r<128?i++:o=r>127&&r<2048?String.fromCharCode(r>>6|192,63&r|128):String.fromCharCode(r>>12|224,r>>6&63|128,63&r|128),h(o)||(i>t&&(n+=e.substring(t,i)),n+=o,t=i=s+1)}return i>t&&(n+=e.substring(t,e.length)),n},V=function(){function e(t){return t&&(t.preventDefault=e.preventDefault,t.stopPropagation=e.stopPropagation),t}return e.preventDefault=function(){this.returnValue=!1},e.stopPropagation=function(){this.cancelBubble=!0},function(t,i,s,n,r){if(t)if(t.addEventListener&&!n)t.addEventListener(i,s,!!r);else{const n="on"+i,r=t[n];t[n]=function(t,i,s){return function(n){if(!(n=n||e(null==v?void 0:v.event)))return;let r,a=!0;o(s)&&(r=s(n));const l=i.call(t,n);return!1!==r&&!1!==l||(a=!1),a}}(t,s,r)}else T.error("No valid element provided to register_event")}}();function G(e){const t=null==e?void 0:e.hostname;return!!u(t)&&"herokuapp.com"!==t.split(".").slice(-2).join(".")}function j(e,t){for(let i=0;i<e.length;i++)if(t(e[i]))return e[i]}let Q;!function(e){e.GZipJS="gzip-js",e.Base64="base64"}(Q||(Q={}));const J="$people_distinct_id",Y="__alias",X="__timers",K="$autocapture_disabled_server_side",Z="$heatmaps_enabled_server_side",ee="$exception_capture_enabled_server_side",te="$exception_capture_endpoint_suffix",ie="$web_vitals_enabled_server_side",se="$dead_clicks_enabled_server_side",ne="$web_vitals_allowed_metrics",re="$session_recording_enabled_server_side",oe="$console_log_recording_enabled_server_side",ae="$session_recording_network_payload_capture",le="$session_recording_canvas_recording",ce="$replay_sample_rate",ue="$replay_minimum_duration",de="$sesid",he="$session_is_sampled",_e="$session_recording_url_trigger_activated_session",pe="$session_recording_url_trigger_status",ge="$enabled_feature_flags",fe="$early_access_features",ve="$stored_person_properties",me="$stored_group_properties",ye="$surveys",be="$surveys_activated",we="$flag_call_reported",Se="$user_state",ke="$client_session_props",Ee="$capture_rate_limit",xe="$initial_campaign_params",Ie="$initial_referrer_info",Re="$initial_person_info",Fe="$epp",Pe="__POSTHOG_TOOLBAR__",Ce=[J,Y,"__cmpns",X,re,Z,de,ge,Se,fe,me,ve,ye,we,ke,Ee,xe,Ie,Fe],Te="$active_feature_flags",$e="$override_feature_flags",Ae="$feature_flag_payloads",Me=e=>{const t={};for(const[i,s]of N(e||{}))s&&(t[i]=s);return t};class Le{constructor(e){this.instance=e,this._override_warning=!1,this.featureFlagEventHandlers=[],this.reloadFeatureFlagsQueued=!1,this.reloadFeatureFlagsInAction=!1}getFlags(){return Object.keys(this.getFlagVariants())}getFlagVariants(){const e=this.instance.get_property(ge),t=this.instance.get_property($e);if(!t)return e||{};const i=D({},e),s=Object.keys(t);for(let e=0;e<s.length;e++)i[s[e]]=t[s[e]];return this._override_warning||(T.warn(" Overriding feature flags!",{enabledFlags:e,overriddenFlags:t,finalFlags:i}),this._override_warning=!0),i}getFlagPayloads(){return this.instance.get_property(Ae)||{}}reloadFeatureFlags(){this.reloadFeatureFlagsQueued||(this.reloadFeatureFlagsQueued=!0,this._startReloadTimer())}setAnonymousDistinctId(e){this.$anon_distinct_id=e}setReloadingPaused(e){this.reloadFeatureFlagsInAction=e}resetRequestQueue(){this.reloadFeatureFlagsQueued=!1}_startReloadTimer(){this.reloadFeatureFlagsQueued&&!this.reloadFeatureFlagsInAction&&setTimeout((()=>{!this.reloadFeatureFlagsInAction&&this.reloadFeatureFlagsQueued&&(this.reloadFeatureFlagsQueued=!1,this._reloadFeatureFlagsRequest())}),5)}_reloadFeatureFlagsRequest(){if(this.instance.config.advanced_disable_feature_flags)return;this.setReloadingPaused(!0);const e=this.instance.config.token,t=this.instance.get_property(ve),i=this.instance.get_property(me),s={token:e,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),$anon_distinct_id:this.$anon_distinct_id,person_properties:t,group_properties:i,disable_flags:this.instance.config.advanced_disable_feature_flags||void 0};this.instance._send_request({method:"POST",url:this.instance.requestRouter.endpointFor("api","/decide/?v=3"),data:s,compression:this.instance.config.disable_compression?void 0:Q.Base64,timeout:this.instance.config.feature_flag_request_timeout_ms,callback:e=>{var t;this.setReloadingPaused(!1);let i=!0;200===e.statusCode&&(this.$anon_distinct_id=void 0,i=!1),this.receivedFeatureFlags(null!==(t=e.json)&&void 0!==t?t:{},i),this._startReloadTimer()}})}getFeatureFlag(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0))return void T.warn('getFeatureFlag for key "'+e+"\" failed. Feature flags didn't load in time.");const i=this.getFlagVariants()[e],s=`${i}`,n=this.instance.get_property(we)||{};var o;!t.send_event&&"send_event"in t||(e in n&&n[e].includes(s)||(r(n[e])?n[e].push(s):n[e]=[s],null===(o=this.instance.persistence)||void 0===o||o.register({[we]:n}),this.instance.capture("$feature_flag_called",{$feature_flag:e,$feature_flag_response:i})));return i}getFeatureFlagPayload(e){return this.getFlagPayloads()[e]}isFeatureEnabled(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.instance.decideEndpointWasHit||this.getFlags()&&this.getFlags().length>0)return!!this.getFeatureFlag(e,t);T.warn('isFeatureEnabled for key "'+e+"\" failed. Feature flags didn't load in time.")}addFeatureFlagsHandler(e){this.featureFlagEventHandlers.push(e)}removeFeatureFlagsHandler(e){this.featureFlagEventHandlers=this.featureFlagEventHandlers.filter((t=>t!==e))}receivedFeatureFlags(e,t){if(!this.instance.persistence)return;this.instance.decideEndpointWasHit=!0;const i=this.getFlagVariants(),s=this.getFlagPayloads();!function(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};const n=e.featureFlags,o=e.featureFlagPayloads;if(!n)return;if(r(n)){const e={};if(n)for(let t=0;t<n.length;t++)e[n[t]]=!0;return void(t&&t.register({[Te]:n,[ge]:e}))}let a=n,l=o;e.errorsWhileComputingFlags&&(a={...i,...a},l={...s,...l}),t&&t.register({[Te]:Object.keys(Me(a)),[ge]:a||{},[Ae]:l||{}})}(e,this.instance.persistence,i,s),this._fireFeatureFlagsCallbacks(t)}override(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!this.instance.__loaded||!this.instance.persistence)return T.uninitializedWarning("posthog.feature_flags.override");if(this._override_warning=t,!1===e)this.instance.persistence.unregister($e);else if(r(e)){const t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;this.instance.persistence.register({[$e]:t})}else this.instance.persistence.register({[$e]:e})}onFeatureFlags(e){if(this.addFeatureFlagsHandler(e),this.instance.decideEndpointWasHit){const{flags:t,flagVariants:i}=this._prepareFeatureFlagsForCallbacks();e(t,i)}return()=>this.removeFeatureFlagsHandler(e)}updateEarlyAccessFeatureEnrollment(e,t){var i;const s={[`$feature_enrollment/${e}`]:t};this.instance.capture("$feature_enrollment_update",{$feature_flag:e,$feature_enrollment:t,$set:s}),this.setPersonPropertiesForFlags(s,!1);const n={...this.getFlagVariants(),[e]:t};null===(i=this.instance.persistence)||void 0===i||i.register({[Te]:Object.keys(Me(n)),[ge]:n}),this._fireFeatureFlagsCallbacks()}getEarlyAccessFeatures(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const i=this.instance.get_property(fe);if(i&&!t)return e(i);this.instance._send_request({transport:"XHR",url:this.instance.requestRouter.endpointFor("api",`/api/early_access_features/?token=${this.instance.config.token}`),method:"GET",callback:t=>{var i;if(!t.json)return;const s=t.json.earlyAccessFeatures;return null===(i=this.instance.persistence)||void 0===i||i.register({[fe]:s}),e(s)}})}_prepareFeatureFlagsForCallbacks(){const e=this.getFlags(),t=this.getFlagVariants();return{flags:e.filter((e=>t[e])),flagVariants:Object.keys(t).filter((e=>t[e])).reduce(((e,i)=>(e[i]=t[i],e)),{})}}_fireFeatureFlagsCallbacks(e){const{flags:t,flagVariants:i}=this._prepareFeatureFlagsForCallbacks();this.featureFlagEventHandlers.forEach((s=>s(t,i,{errorsLoading:e})))}setPersonPropertiesForFlags(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const i=this.instance.get_property(ve)||{};this.instance.register({[ve]:{...i,...e}}),t&&this.instance.reloadFeatureFlags()}resetPersonPropertiesForFlags(){this.instance.unregister(ve)}setGroupPropertiesForFlags(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const i=this.instance.get_property(me)||{};0!==Object.keys(i).length&&Object.keys(i).forEach((t=>{i[t]={...i[t],...e[t]},delete e[t]})),this.instance.register({[me]:{...i,...e}}),t&&this.instance.reloadFeatureFlags()}resetGroupPropertiesForFlags(e){if(e){const t=this.instance.get_property(me)||{};this.instance.register({[me]:{...t,[e]:{}}})}else this.instance.unregister(me)}}
|
|
2
2
|
/**
|
|
3
3
|
* uuidv7: An experimental implementation of the proposed UUID Version 7
|
|
4
4
|
*
|