@growthbook/edge-utils 0.0.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.
- package/LICENSE +21 -0
- package/dist/app.d.ts +3 -0
- package/dist/app.js +171 -0
- package/dist/app.js.map +1 -0
- package/dist/attributes.d.ts +5 -0
- package/dist/attributes.js +76 -0
- package/dist/attributes.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +91 -0
- package/dist/config.js.map +1 -0
- package/dist/domMutations.d.ts +6 -0
- package/dist/domMutations.js +151 -0
- package/dist/domMutations.js.map +1 -0
- package/dist/generated/sdkWrapper.d.ts +1 -0
- package/dist/generated/sdkWrapper.js +5 -0
- package/dist/generated/sdkWrapper.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/inject.d.ts +16 -0
- package/dist/inject.js +136 -0
- package/dist/inject.js.map +1 -0
- package/dist/redirect.d.ts +11 -0
- package/dist/redirect.js +43 -0
- package/dist/redirect.js.map +1 -0
- package/dist/routing.d.ts +2 -0
- package/dist/routing.js +47 -0
- package/dist/routing.js.map +1 -0
- package/dist/stickyBucketService.d.ts +14 -0
- package/dist/stickyBucketService.js +49 -0
- package/dist/stickyBucketService.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +31 -0
- package/scripts/generate-sdk-wrapper.js +22 -0
- package/src/app.ts +210 -0
- package/src/attributes.ts +97 -0
- package/src/config.ts +166 -0
- package/src/domMutations.ts +157 -0
- package/src/generated/sdkWrapper.ts +2 -0
- package/src/index.ts +13 -0
- package/src/inject.ts +230 -0
- package/src/redirect.ts +53 -0
- package/src/routing.ts +44 -0
- package/src/stickyBucketService.ts +48 -0
- package/src/types.ts +98 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sdkWrapper = "var _growthbook=function(){\"use strict\";function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)t[i]=n[i]}return t}var e=function e(n,i){function r(e,r,s){if(\"undefined\"!=typeof document){\"number\"==typeof(s=t({},i,s)).expires&&(s.expires=new Date(Date.now()+864e5*s.expires)),s.expires&&(s.expires=s.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o=\"\";for(var u in s)s[u]&&(o+=\"; \"+u,!0!==s[u]&&(o+=\"=\"+s[u].split(\";\")[0]));return document.cookie=e+\"=\"+n.write(r,e)+o}}return Object.create({set:r,get:function(t){if(\"undefined\"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split(\"; \"):[],i={},r=0;r<e.length;r++){var s=e[r].split(\"=\"),o=s.slice(1).join(\"=\");try{var u=decodeURIComponent(s[0]);if(i[u]=n.read(o,u),t===u)break}catch(t){}}return t?i[t]:i}},remove:function(e,n){r(e,\"\",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}({read:function(t){return'\"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:\"/\"}),n=/^[a-zA-Z:_][a-zA-Z0-9:_.-]*$/,i={revert:function(){}},r=new Map,s=new Set;function o(t){var e=r.get(t);return e||r.set(t,e={element:t,attributes:{}}),e}function u(t,e,n,i,r){var s=n(t),o={isDirty:!1,originalValue:s,virtualValue:s,mutations:[],el:t,t:null,observer:new MutationObserver((function(){if(\"position\"!==e||!o.t){\"position\"===e&&(o.t=setTimeout((function(){o.t=null}),1e3));var i=n(t);\"position\"===e&&i.parentNode===o.virtualValue.parentNode&&i.insertBeforeNode===o.virtualValue.insertBeforeNode||i!==o.virtualValue&&(o.originalValue=i,r(o))}})),mutationRunner:r,setValue:i,getCurrentValue:n};return\"position\"===e&&t.parentNode?o.observer.observe(t.parentNode,{childList:!0,subtree:!0,attributes:!1,characterData:!1}):o.observer.observe(t,function(t){return\"html\"===t?{childList:!0,subtree:!0,attributes:!0,characterData:!0}:{childList:!1,subtree:!1,attributes:!0,attributeFilter:[t]}}(e)),o}function c(t,e){var n=e.getCurrentValue(e.el);e.virtualValue=t,t&&\"string\"!=typeof t?n&&t.parentNode===n.parentNode&&t.insertBeforeNode===n.insertBeforeNode||(e.isDirty=!0,C()):t!==n&&(e.isDirty=!0,C())}function a(t){var e=t.originalValue;t.mutations.forEach((function(t){return e=t.mutate(e)})),c(function(t){return g||(g=document.createElement(\"div\")),g.innerHTML=t,g.innerHTML}(e),t)}function h(t){var e=new Set(t.originalValue.split(/\\s+/).filter(Boolean));t.mutations.forEach((function(t){return t.mutate(e)})),c(Array.from(e).filter(Boolean).join(\" \"),t)}function l(t){var e=t.originalValue;t.mutations.forEach((function(t){return e=t.mutate(e)})),c(e,t)}function f(t){var e=t.originalValue;t.mutations.forEach((function(t){var n=function(t){var e=t.insertBeforeSelector,n=document.querySelector(t.parentSelector);if(!n)return null;var i=e?document.querySelector(e):null;return e&&!i?null:{parentNode:n,insertBeforeNode:i}}(t.mutate());e=n||e})),c(e,t)}var d=function(t){return t.innerHTML},w=function(t,e){return t.innerHTML=e};function y(t){var e=o(t);return e.html||(e.html=u(t,\"html\",d,w,a)),e.html}var p=function(t){return{parentNode:t.parentElement,insertBeforeNode:t.nextElementSibling}},v=function(t,e){e.insertBeforeNode&&!e.parentNode.contains(e.insertBeforeNode)||e.parentNode.insertBefore(t,e.insertBeforeNode)};function m(t){var e=o(t);return e.position||(e.position=u(t,\"position\",p,v,f)),e.position}var g,b,k=function(t,e){return e?t.className=e:t.removeAttribute(\"class\")},S=function(t){return t.className};function A(t){var e=o(t);return e.classes||(e.classes=u(t,\"class\",S,k,h)),e.classes}function _(t,e){var n,i=o(t);return i.attributes[e]||(i.attributes[e]=u(t,e,(n=e,function(t){var e;return null!=(e=t.getAttribute(n))?e:null}),function(t){return function(e,n){return null!==n?e.setAttribute(t,n):e.removeAttribute(t)}}(e),l)),i.attributes[e]}function x(t,e,n){if(n.isDirty){n.isDirty=!1;var i=n.virtualValue;n.mutations.length||function(t,e){var n,i,s=r.get(t);if(s)if(\"html\"===e)null==(n=s.html)||null==(i=n.observer)||i.disconnect(),delete s.html;else if(\"class\"===e){var o,u;null==(o=s.classes)||null==(u=o.observer)||u.disconnect(),delete s.classes}else if(\"position\"===e){var c,a;null==(c=s.position)||null==(a=c.observer)||a.disconnect(),delete s.position}else{var h,l,f;null==(h=s.attributes)||null==(l=h[e])||null==(f=l.observer)||f.disconnect(),delete s.attributes[e]}}(t,e),n.setValue(t,i)}}function E(t,e){t.html&&x(e,\"html\",t.html),t.classes&&x(e,\"class\",t.classes),t.position&&x(e,\"position\",t.position),Object.keys(t.attributes).forEach((function(n){x(e,n,t.attributes[n])}))}function C(){r.forEach(E)}function O(t){if(\"position\"!==t.kind||1!==t.elements.size){var e=new Set(t.elements);document.querySelectorAll(t.selector).forEach((function(n){e.has(n)||(t.elements.add(n),function(t,e){var n=null;\"html\"===t.kind?n=y(e):\"class\"===t.kind?n=A(e):\"attribute\"===t.kind?n=_(e,t.attribute):\"position\"===t.kind&&(n=m(e)),n&&(n.mutations.push(t),n.mutationRunner(n))}(t,n))}))}}function $(){s.forEach(O)}function R(t){return\"undefined\"==typeof document?i:(s.add(t),O(t),{revert:function(){var e;(e=t).elements.forEach((function(t){return function(t,e){var n=null;if(\"html\"===t.kind?n=y(e):\"class\"===t.kind?n=A(e):\"attribute\"===t.kind?n=_(e,t.attribute):\"position\"===t.kind&&(n=m(e)),n){var i=n.mutations.indexOf(t);-1!==i&&n.mutations.splice(i,1),n.mutationRunner(n)}}(e,t)})),e.elements.clear(),s.delete(e)}})}function B(t,e){return R({kind:\"html\",elements:new Set,mutate:e,selector:t})}function F(t,e){return R({kind:\"class\",elements:new Set,mutate:e,selector:t})}function T(t,e,r){return n.test(e)?\"class\"===e||\"className\"===e?F(t,(function(t){var e=r(Array.from(t).join(\" \"));t.clear(),e&&e.split(/\\s+/g).filter(Boolean).forEach((function(e){return t.add(e)}))})):R({kind:\"attribute\",attribute:e,elements:new Set,mutate:r,selector:t}):i}\"undefined\"!=typeof document&&(b||(b=new MutationObserver((function(){$()}))),$(),b.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1,characterData:!1}));const N={fetch:globalThis.fetch?globalThis.fetch.bind(globalThis):void 0,SubtleCrypto:globalThis.crypto?globalThis.crypto.subtle:void 0,EventSource:globalThis.EventSource};function M(t){let e=2166136261;const n=t.length;for(let i=0;i<n;i++)e^=t.charCodeAt(i),e+=(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24);return e>>>0}function U(t,e,n){return 2===n?M(M(t+e)+\"\")%1e4/1e4:1===n?M(e+t)%1e3/1e3:null}function V(t,e){return t>=e[0]&&t<e[1]}function I(t){try{const e=t.replace(/([^\\\\])\\//g,\"$1\\\\/\");return new RegExp(e)}catch(t){return void console.error(t)}}function D(t,e){if(!e.length)return!1;let n=!1,i=!1;for(let r=0;r<e.length;r++){const s=J(t,e[r].type,e[r].pattern);if(!1===e[r].include){if(s)return!1}else n=!0,s&&(i=!0)}return i||!n}function J(t,e,n){try{const i=new URL(t,\"https://_\");if(\"regex\"===e){const t=I(n);return!!t&&(t.test(i.href)||t.test(i.href.substring(i.origin.length)))}return\"simple\"===e&&function(t,e){try{const n=new URL(e.replace(/^([^:/?]*)\\./i,\"https://$1.\").replace(/\\*/g,\"_____\"),\"https://_____\"),i=[[t.host,n.host,!1],[t.pathname,n.pathname,!0]];return n.hash&&i.push([t.hash,n.hash,!1]),n.searchParams.forEach(((e,n)=>{i.push([t.searchParams.get(n)||\"\",e,!1])})),!i.some((t=>!function(t,e,n){try{let i=e.replace(/[*.+?^${}()|[\\]\\\\]/g,\"\\\\$&\").replace(/_____/g,\".*\");return n&&(i=\"\\\\/?\"+i.replace(/(^\\/|\\/$)/g,\"\")+\"\\\\/?\"),new RegExp(\"^\"+i+\"$\",\"i\").test(t)}catch(t){return!1}}(t[0],t[1],t[2])))}catch(t){return!1}}(i,n)}catch(t){return!1}}const j=t=>Uint8Array.from(atob(t),(t=>t.charCodeAt(0)));async function K(t,e,n){if(e=e||\"\",!(n=n||globalThis.crypto&&globalThis.crypto.subtle||N.SubtleCrypto))throw new Error(\"No SubtleCrypto implementation found\");try{const i=await n.importKey(\"raw\",j(e),{name:\"AES-CBC\",length:128},!0,[\"encrypt\",\"decrypt\"]),[r,s]=t.split(\".\"),o=await n.decrypt({name:\"AES-CBC\",iv:j(r)},i,j(s));return(new TextDecoder).decode(o)}catch(t){throw new Error(\"Failed to decrypt\")}}function L(t){return\"string\"==typeof t?t:JSON.stringify(t)}function H(t){\"number\"==typeof t&&(t+=\"\"),t&&\"string\"==typeof t||(t=\"0\");const e=t.replace(/(^v|\\+.*$)/g,\"\").split(/[-.]/);return 3===e.length&&e.push(\"~\"),e.map((t=>t.match(/^[0-9]+$/)?t.padStart(5,\" \"):t)).join(\"-\")}function q(t){return\"object\"==typeof t&&null!==t}function P(t){return t.urlPatterns&&t.variations.some((t=>q(t)&&\"urlRedirect\"in t))?\"redirect\":t.variations.some((t=>q(t)&&(t.domMutations||\"js\"in t||\"css\"in t)))?\"visual\":\"unknown\"}const z={};function G(t,e){if(\"$or\"in e)return tt(t,e.$or);if(\"$nor\"in e)return!tt(t,e.$nor);if(\"$and\"in e)return function(t,e){for(let n=0;n<e.length;n++)if(!G(t,e[n]))return!1;return!0}(t,e.$and);if(\"$not\"in e)return!G(t,e.$not);for(const[n,i]of Object.entries(e))if(!Q(i,Z(t,n)))return!1;return!0}function Z(t,e){const n=e.split(\".\");let i=t;for(let t=0;t<n.length;t++){if(!i||\"object\"!=typeof i||!(n[t]in i))return null;i=i[n[t]]}return i}function Q(t,e){if(\"string\"==typeof t)return e+\"\"===t;if(\"number\"==typeof t)return 1*e===t;if(\"boolean\"==typeof t)return!!e===t;if(null===t)return null===e;if(Array.isArray(t)||!W(t))return JSON.stringify(e)===JSON.stringify(t);for(const n in t)if(!Y(n,e,t[n]))return!1;return!0}function W(t){const e=Object.keys(t);return e.length>0&&e.filter((t=>\"$\"===t[0])).length===e.length}function X(t,e){return Array.isArray(t)?t.some((t=>e.includes(t))):e.includes(t)}function Y(t,e,n){switch(t){case\"$veq\":return H(e)===H(n);case\"$vne\":return H(e)!==H(n);case\"$vgt\":return H(e)>H(n);case\"$vgte\":return H(e)>=H(n);case\"$vlt\":return H(e)<H(n);case\"$vlte\":return H(e)<=H(n);case\"$eq\":return e===n;case\"$ne\":return e!==n;case\"$lt\":return e<n;case\"$lte\":return e<=n;case\"$gt\":return e>n;case\"$gte\":return e>=n;case\"$exists\":return n?null!=e:null==e;case\"$in\":return!!Array.isArray(n)&&X(e,n);case\"$nin\":return!!Array.isArray(n)&&!X(e,n);case\"$not\":return!Q(n,e);case\"$size\":return!!Array.isArray(e)&&Q(n,e.length);case\"$elemMatch\":return function(t,e){if(!Array.isArray(t))return!1;const n=W(e)?t=>Q(e,t):t=>G(t,e);for(let e=0;e<t.length;e++)if(t[e]&&n(t[e]))return!0;return!1}(e,n);case\"$all\":if(!Array.isArray(e))return!1;for(let t=0;t<n.length;t++){let i=!1;for(let r=0;r<e.length;r++)if(Q(n[t],e[r])){i=!0;break}if(!i)return!1}return!0;case\"$regex\":try{return(i=n,z[i]||(z[i]=new RegExp(i.replace(/([^\\\\])\\//g,\"$1\\\\/\"))),z[i]).test(e)}catch(t){return!1}case\"$type\":return function(t){if(null===t)return\"null\";if(Array.isArray(t))return\"array\";const e=typeof t;return[\"string\",\"number\",\"boolean\",\"object\",\"undefined\"].includes(e)?e:\"unknown\"}(e)===n;default:return console.error(\"Unknown operator: \"+t),!1}var i}function tt(t,e){if(!e.length)return!0;for(let n=0;n<e.length;n++)if(G(t,e[n]))return!0;return!1}const et=\"undefined\"!=typeof window&&\"undefined\"!=typeof document,nt=function(){let t;try{t=\"1.0.0\"}catch(e){t=\"\"}return t}(),it={staleTTL:6e4,maxAge:864e5,cacheKey:\"gbFeaturesCache\",backgroundSync:!0,maxEntries:10,disableIdleStreams:!1,idleStreamInterval:2e4,disableCache:!1},rt=N,st={fetchFeaturesCall:t=>{let{host:e,clientKey:n,headers:i}=t;return rt.fetch(\"\".concat(e,\"/api/features/\").concat(n),{headers:i})},fetchRemoteEvalCall:t=>{let{host:e,clientKey:n,payload:i,headers:r}=t;const s={method:\"POST\",headers:{\"Content-Type\":\"application/json\",...r},body:JSON.stringify(i)};return rt.fetch(\"\".concat(e,\"/api/eval/\").concat(n),s)},eventSourceCall:t=>{let{host:e,clientKey:n,headers:i}=t;return i?new rt.EventSource(\"\".concat(e,\"/sub/\").concat(n),{headers:i}):new rt.EventSource(\"\".concat(e,\"/sub/\").concat(n))},startIdleListener:()=>{let t;if(\"undefined\"==typeof window||\"undefined\"==typeof document)return;const e=()=>{\"visible\"===document.visibilityState?(window.clearTimeout(t),ht.forEach((t=>{t&&\"idle\"===t.state&&At(t)}))):\"hidden\"===document.visibilityState&&(t=window.setTimeout(dt,it.idleStreamInterval))};return document.addEventListener(\"visibilitychange\",e),()=>document.removeEventListener(\"visibilitychange\",e)},stopIdleListener:()=>{}};try{globalThis.localStorage&&(rt.localStorage=globalThis.localStorage)}catch(t){}const ot=new Map;let ut=!1;const ct=new Map,at=new Map,ht=new Map,lt=new Set;function ft(t){const e=yt(t),n=ot.get(e)||new Set;n.add(t),ot.set(e,n)}function dt(){ht.forEach((t=>{t&&(t.state=\"idle\",St(t))}))}async function wt(){try{if(!rt.localStorage)return;await rt.localStorage.setItem(it.cacheKey,JSON.stringify(Array.from(ct.entries())))}catch(t){}}function yt(t){const[e,n]=t.getApiInfo();return\"\".concat(e,\"||\").concat(n)}function pt(t){const e=yt(t);if(!t.isRemoteEval())return e;const n=t.getAttributes(),i=t.getCacheKeyAttributes()||Object.keys(t.getAttributes()),r={};i.forEach((t=>{r[t]=n[t]}));const s=t.getForcedVariations(),o=t.getUrl();return\"\".concat(e,\"||\").concat(JSON.stringify({ca:r,fv:s,url:o}))}function vt(){const t=Array.from(ct.entries()).map((t=>{let[e,n]=t;return{key:e,staleAt:n.staleAt.getTime()}})).sort(((t,e)=>t.staleAt-e.staleAt)),e=Math.min(Math.max(0,ct.size-it.maxEntries),ct.size);for(let n=0;n<e;n++)ct.delete(t[n].key)}function mt(t,e,n){const i=n.dateUpdated||\"\",r=new Date(Date.now()+it.staleTTL),s=ct.get(e);if(s&&i&&s.version===i)return s.staleAt=r,void wt();ct.set(e,{data:n,version:i,staleAt:r,sse:lt.has(t)}),vt(),wt();const o=ot.get(t);o&&o.forEach((t=>async function(t,e){await t.setPayload(e||t.getPayload())}(t,n)))}async function gt(t){const{apiHost:e,apiRequestHeaders:n}=t.getApiHosts(),i=t.getClientKey(),r=t.isRemoteEval(),s=yt(t),o=pt(t);let u=at.get(o);return u||(u=(r?st.fetchRemoteEvalCall({host:e,clientKey:i,payload:{attributes:t.getAttributes(),forcedVariations:t.getForcedVariations(),forcedFeatures:Array.from(t.getForcedFeatures().entries()),url:t.getUrl()},headers:n}):st.fetchFeaturesCall({host:e,clientKey:i,headers:n})).then((t=>{if(!t.ok)throw new Error(\"HTTP error: \".concat(t.status));return\"enabled\"===t.headers.get(\"x-sse-support\")&<.add(s),t.json()})).then((e=>(mt(s,o,e),bt(t),at.delete(o),{data:e,success:!0,source:\"network\"}))).catch((t=>(at.delete(o),{data:null,source:\"error\",success:!1,error:t}))),at.set(o,u)),u}function bt(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=yt(t),i=pt(t),{streamingHost:r,streamingHostRequestHeaders:s}=t.getApiHosts(),o=t.getClientKey();if(e&<.add(n),it.backgroundSync&<.has(n)&&rt.EventSource){if(ht.has(n))return;const t={src:null,host:r,clientKey:o,headers:s,cb:e=>{try{if(\"features-updated\"===e.type){const t=ot.get(n);t&&t.forEach((t=>{gt(t)}))}else if(\"features\"===e.type){const t=JSON.parse(e.data);mt(n,i,t)}t.errors=0}catch(e){kt(t)}},errors:0,state:\"active\"};ht.set(n,t),At(t)}}function kt(t){if(\"idle\"!==t.state&&(t.errors++,t.errors>3||t.src&&2===t.src.readyState)){const e=Math.pow(3,t.errors-3)*(1e3+1e3*Math.random());St(t),setTimeout((()=>{[\"idle\",\"active\"].includes(t.state)||At(t)}),Math.min(e,3e5))}}function St(t){t.src&&(t.src.onopen=null,t.src.onerror=null,t.src.close(),t.src=null,\"active\"===t.state&&(t.state=\"disabled\"))}function At(t){t.src=st.eventSourceCall({host:t.host,clientKey:t.clientKey,headers:t.headers}),t.state=\"active\",t.src.addEventListener(\"features\",t.cb),t.src.addEventListener(\"features-updated\",t.cb),t.src.onerror=()=>kt(t),t.src.onopen=()=>{t.errors=0}}class _t{async getAllAssignments(t){const e={};return(await Promise.all(Object.entries(t).map((t=>{let[e,n]=t;return this.getAssignments(e,n)})))).forEach((t=>{if(t){const n=\"\".concat(t.attributeName,\"||\").concat(t.attributeValue);e[n]=t}})),e}}window.dataLayer=window.dataLayer||[];const xt=document.currentScript,Et=xt?xt.dataset:{},Ct=window.growthbook_config||{};function Ot(t){const e=(\"; \"+document.cookie).split(\"; \".concat(t,\"=\"));return 2===e.length?e[1].split(\";\")[0]:\"\"}function $t(){return window.crypto&&crypto.randomUUID?crypto.randomUUID():\"10000000-1000-4000-8000-100000000000\".replace(/[018]/g,(t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)))}const Rt=Ct.uuidCookieName||Et.uuidCookieName||\"gbuuid\",Bt=Ct.uuidKey||Et.uuidKey||\"id\";let Ft,Tt=Ct.uuid||Et.uuid||\"\";function Nt(){!function(t,e){const n=new Date;n.setTime(n.getTime()+3456e7),document.cookie=t+\"=\"+e+\";path=/;expires=\"+n.toUTCString()}(Rt,Tt)}function Mt(){let t={};try{const e=sessionStorage.getItem(\"utm_params\");if(e&&(t=JSON.parse(e)),location.search){const e=new URLSearchParams(location.search);let n=!1;[\"source\",\"medium\",\"campaign\",\"term\",\"content\"].forEach((i=>{const r=\"utm_\".concat(i),s=\"utm\"+i[0].toUpperCase()+i.slice(1);e.has(r)&&(t[s]=e.get(r)||\"\",n=!0)})),n&&sessionStorage.setItem(\"utm_params\",JSON.stringify(t))}}catch(t){}return t}function Ut(){if(!window.dataLayer||!window.dataLayer.forEach)return{};const t={};return window.dataLayer.forEach((e=>{e&&\"object\"==typeof e&&!(\"length\"in e)&&(\"event\"in e||Object.keys(e).forEach((n=>{if(\"string\"!=typeof n||n.match(/^(gtm)/))return;const i=e[n];[\"string\",\"number\",\"boolean\"].includes(typeof i)&&(t[n]=i)})))})),t}function Vt(){const t=Et.noAutoAttributes?{}:function(t,e){const n=null==t.noAutoCookies,i=navigator.userAgent,r=i.match(/Edg/)?\"edge\":i.match(/Chrome/)?\"chrome\":i.match(/Firefox/)?\"firefox\":i.match(/Safari/)?\"safari\":\"unknown\",s=function(){let t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return Tt||(Tt=Ot(Rt),Tt||(Tt=$t(),t&&Nt(),Tt))}(n);return(e.persistUuidOnLoad||t.persistUuidOnLoad)&&n&&Nt(),{...Ut(),[Bt]:s,url:location.href,path:location.pathname,host:location.host,query:location.search,pageTitle:document&&document.title,deviceType:i.match(/Mobi/)?\"mobile\":\"desktop\",browser:r,...Mt()}}(Et,Ct);return Ct.attributes&&Object.assign(t,Ct.attributes),t}\"cookie\"===Ct.useStickyBucketService||\"cookie\"===Et.useStickyBucketService?Ft=new class extends _t{constructor(t){let{prefix:e=\"gbStickyBuckets__\",jsCookie:n,cookieAttributes:i={}}=t;super(),this.prefix=e,this.jsCookie=n,this.cookieAttributes=i}async getAssignments(t,e){const n=\"\".concat(t,\"||\").concat(e);let i=null;if(!this.jsCookie)return i;try{const t=this.jsCookie.get(this.prefix+n),e=JSON.parse(t||\"{}\");e.attributeName&&e.attributeValue&&e.assignments&&(i=e)}catch(t){}return i}async saveAssignments(t){const e=\"\".concat(t.attributeName,\"||\").concat(t.attributeValue);if(!this.jsCookie)return;const n=JSON.stringify(t);this.jsCookie.set(this.prefix+e,n,this.cookieAttributes)}}({prefix:Ct.stickyBucketPrefix||Et.stickyBucketPrefix||void 0,jsCookie:e}):\"localStorage\"!==Ct.useStickyBucketService&&\"localStorage\"!==Et.useStickyBucketService||(Ft=new class extends _t{constructor(t){t=t||{},super(),this.prefix=t.prefix||\"gbStickyBuckets__\";try{this.localStorage=t.localStorage||globalThis.localStorage}catch(t){}}async getAssignments(t,e){const n=\"\".concat(t,\"||\").concat(e);let i=null;if(!this.localStorage)return i;try{const t=await this.localStorage.getItem(this.prefix+n)||\"{}\",e=JSON.parse(t);e.attributeName&&e.attributeValue&&e.assignments&&(i=e)}catch(t){}return i}async saveAssignments(t){const e=\"\".concat(t.attributeName,\"||\").concat(t.attributeValue);if(this.localStorage)try{await this.localStorage.setItem(this.prefix+e,JSON.stringify(t))}catch(t){}}}({prefix:Ct.stickyBucketPrefix||Et.stickyBucketPrefix||void 0}));const It=new class{constructor(t){if(t=t||{},this.version=nt,this.i=this.context=t,this.o=t.renderer||null,this.u=new Set,this.h=new Set,this.l={},this.debug=!!t.debug,this.p=new Set,this.v=[],this.m=0,this.ready=!1,this.g=new Map,this.k=new Map,this.S={},this.A=new Map,this._=new Set,this.C=!1,this.O=\"\",this.$=new Map,this.R=!t.disableExperimentsOnLoad,t.remoteEval){if(t.decryptionKey)throw new Error(\"Encryption is not available for remoteEval\");if(!t.clientKey)throw new Error(\"Missing clientKey\");let e=!1;try{e=!!new URL(t.apiHost||\"\").hostname.match(/growthbook\\.io$/i)}catch(t){}if(e)throw new Error(\"Cannot use remoteEval on GrowthBook Cloud\")}else if(t.cacheKeyAttributes)throw new Error(\"cacheKeyAttributes are only used for remoteEval\");if(t.features&&(this.ready=!0),et&&t.enableDevMode&&(window._growthbook=this,document.dispatchEvent(new Event(\"gbloaded\"))),t.experiments?(this.ready=!0,this.B()):t.antiFlicker&&this.F(),this.i.stickyBucketService&&this.i.stickyBucketAssignmentDocs)for(const t in this.i.stickyBucketAssignmentDocs){const e=this.i.stickyBucketAssignmentDocs[t];e&&this.i.stickyBucketService.saveAssignments(e).catch((()=>{}))}this.ready&&this.refreshStickyBuckets(this.getPayload())}async setPayload(t){this.T=t;const e=await this.decryptPayload(t);this.N=e,await this.refreshStickyBuckets(e),e.features&&(this.i.features=e.features),e.experiments&&(this.i.experiments=e.experiments,this.B()),this.ready=!0,this.M()}initSync(t){this.C=!0;const e=t.payload;if(e.encryptedExperiments||e.encryptedFeatures)throw new Error(\"initSync does not support encrypted payloads\");if(this.i.stickyBucketService&&!this.i.stickyBucketAssignmentDocs)throw new Error(\"initSync requires you to pass stickyBucketAssignmentDocs into the GrowthBook constructor\");if(this.T=e,this.N=e,e.features&&(this.i.features=e.features),e.experiments&&(this.i.experiments=e.experiments,this.B()),this.ready=!0,t.streaming){if(!this.i.clientKey)throw new Error(\"Must specify clientKey to enable streaming\");bt(this,!0),ft(this)}return this}async init(t){if(this.C=!0,(t=t||{}).payload){if(await this.setPayload(t.payload),t.streaming){if(!this.i.clientKey)throw new Error(\"Must specify clientKey to enable streaming\");bt(this,!0),ft(this)}return{success:!0,source:\"init\"}}{const{data:e,...n}=await this.U({...t,allowStale:!0});return t.streaming&&ft(this),await this.setPayload(e||{}),n}}async loadFeatures(t){this.C=!0,(t=t||{}).autoRefresh&&(this.i.subscribeToChanges=!0);const{data:e}=await this.U({...t,allowStale:!0});await this.setPayload(e||{}),this.V()&&ft(this)}async refreshFeatures(t){const e=await this.U({...t||{},allowStale:!1});e.data&&await this.setPayload(e.data)}getApiInfo(){return[this.getApiHosts().apiHost,this.getClientKey()]}getApiHosts(){const t=this.i.apiHost||\"https://cdn.growthbook.io\";return{apiHost:t.replace(/\\/*$/,\"\"),streamingHost:(this.i.streamingHost||t).replace(/\\/*$/,\"\"),apiRequestHeaders:this.i.apiHostRequestHeaders,streamingHostRequestHeaders:this.i.streamingHostRequestHeaders}}getClientKey(){return this.i.clientKey||\"\"}getPayload(){return this.T||{features:this.getFeatures(),experiments:this.getExperiments()}}getDecryptedPayload(){return this.N||this.getPayload()}isRemoteEval(){return this.i.remoteEval||!1}getCacheKeyAttributes(){return this.i.cacheKeyAttributes}async U(t){var e;let{timeout:n,skipCache:i,allowStale:r,streaming:s}=t;if(!this.i.clientKey)throw new Error(\"Missing clientKey\");return async function(t){let{instance:e,timeout:n,skipCache:i,allowStale:r,backgroundSync:s}=t;return s||(it.backgroundSync=!1),async function(t){let{instance:e,allowStale:n,timeout:i,skipCache:r}=t;const s=yt(e),o=pt(e),u=new Date,c=new Date(u.getTime()-it.maxAge+it.staleTTL);await async function(){if(!ut){ut=!0;try{if(rt.localStorage){const t=await rt.localStorage.getItem(it.cacheKey);if(!it.disableCache&&t){const e=JSON.parse(t);e&&Array.isArray(e)&&e.forEach((t=>{let[e,n]=t;ct.set(e,{...n,staleAt:new Date(n.staleAt)})})),vt()}}}catch(t){}{const t=st.startIdleListener();t&&(st.stopIdleListener=t)}}}();const a=it.disableCache||r?void 0:ct.get(o);if(a&&(n||a.staleAt>u)&&a.staleAt>c)return a.sse&<.add(s),a.staleAt<u?gt(e):bt(e),{data:a.data,success:!0,source:\"cache\"};{const t=await function(t,e){return new Promise((n=>{let i,r=!1;const s=t=>{r||(r=!0,i&&clearTimeout(i),n(t||null))};e&&(i=setTimeout((()=>s()),e)),t.then((t=>s(t))).catch((()=>s()))}))}(gt(e),i);return t||{data:null,success:!1,source:\"timeout\",error:new Error(\"Timeout\")}}}({instance:e,allowStale:r,timeout:n,skipCache:i})}({instance:this,timeout:n,skipCache:i||this.i.disableCache,allowStale:r,backgroundSync:null===(e=null!=s?s:this.i.backgroundSync)||void 0===e||e})}M(){if(this.o)try{this.o()}catch(t){console.error(\"Failed to render\",t)}}setFeatures(t){this.i.features=t,this.ready=!0,this.M()}async setEncryptedFeatures(t,e,n){const i=await K(t,e||this.i.decryptionKey,n);this.setFeatures(JSON.parse(i))}setExperiments(t){this.i.experiments=t,this.ready=!0,this.B()}async setEncryptedExperiments(t,e,n){const i=await K(t,e||this.i.decryptionKey,n);this.setExperiments(JSON.parse(i))}async decryptPayload(t,e,n){return(t={...t}).encryptedFeatures&&(t.features=JSON.parse(await K(t.encryptedFeatures,e||this.i.decryptionKey,n)),delete t.encryptedFeatures),t.encryptedExperiments&&(t.experiments=JSON.parse(await K(t.encryptedExperiments,e||this.i.decryptionKey,n)),delete t.encryptedExperiments),t}async setAttributes(t){this.i.attributes=t,this.i.stickyBucketService&&await this.refreshStickyBuckets(),this.i.remoteEval?await this.I():(this.M(),this.B())}async updateAttributes(t){return this.setAttributes({...this.i.attributes,...t})}async setAttributeOverrides(t){this.S=t,this.i.stickyBucketService&&await this.refreshStickyBuckets(),this.i.remoteEval?await this.I():(this.M(),this.B())}async setForcedVariations(t){this.i.forcedVariations=t||{},this.i.remoteEval?await this.I():(this.M(),this.B())}setForcedFeatures(t){this.k=t,this.M()}async setURL(t){if(this.i.url=t,this.O=\"\",this.i.remoteEval)return await this.I(),void this.B(!0);this.B(!0)}getAttributes(){return{...this.i.attributes,...this.S}}getForcedVariations(){return this.i.forcedVariations||{}}getForcedFeatures(){return this.k||new Map}getStickyBucketAssignmentDocs(){return this.i.stickyBucketAssignmentDocs||{}}getUrl(){return this.i.url||\"\"}getFeatures(){return this.i.features||{}}getExperiments(){return this.i.experiments||[]}getCompletedChangeIds(){return Array.from(this.h)}subscribe(t){return this.p.add(t),()=>{this.p.delete(t)}}V(){var t;return(null===(t=this.i.backgroundSync)||void 0===t||t)&&this.i.subscribeToChanges}async I(){if(!this.i.remoteEval)return;if(!this.C)return;const t=await this.U({allowStale:!1});t.data&&await this.setPayload(t.data)}getAllResults(){return new Map(this.g)}destroy(){var t;this.p.clear(),this.g.clear(),this.u.clear(),this.h.clear(),this.$.clear(),this.l={},this.v=[],this.T=void 0,this.m&&clearTimeout(this.m),t=this,ot.forEach((e=>e.delete(t))),et&&window._growthbook===this&&delete window._growthbook,this.A.forEach((t=>{t.undo()})),this.A.clear(),this._.clear()}setRenderer(t){this.o=t}forceVariation(t,e){this.i.forcedVariations=this.i.forcedVariations||{},this.i.forcedVariations[t]=e,this.i.remoteEval?this.I():(this.B(),this.M())}run(t){const e=this.D(t,null);return this.J(t,e),e}triggerExperiment(t){return this._.add(t),this.i.experiments?this.i.experiments.filter((e=>e.key===t)).map((t=>this.j(t))).filter((t=>null!==t)):null}triggerAutoExperiments(){this.R=!0,this.B(!0)}j(t,e){const n=this.A.get(t);if(t.manual&&!this._.has(t.key)&&!n)return null;const i=this.K(t)?this.L(t,-1,!1,\"\"):this.run(t),r=JSON.stringify(i.value);if(!e&&i.inExperiment&&n&&n.valueHash===r)return i;if(n&&this.H(t),i.inExperiment){const e=P(t);if(\"redirect\"===e&&i.value.urlRedirect&&t.urlPatterns){const e=t.persistQueryString?function(t,e){let n,i;try{n=new URL(t),i=new URL(e)}catch(t){return console.error(\"Unable to merge query strings: \".concat(t)),e}return n.searchParams.forEach(((t,e)=>{i.searchParams.has(e)||i.searchParams.set(e,t)})),i.toString()}(this.q(),i.value.urlRedirect):i.value.urlRedirect;if(D(e,t.urlPatterns))return this.log(\"Skipping redirect because original URL matches redirect URL\",{id:t.key}),i;this.O=e;const n=this.P();var s;if(n)if(et)this.F(),window.setTimeout((()=>{try{n(e)}catch(t){console.error(t)}}),null!==(s=this.i.navigateDelay)&&void 0!==s?s:100);else try{n(e)}catch(t){console.error(t)}}else if(\"visual\"===e){const e=this.i.applyDomChangesCallback?this.i.applyDomChangesCallback(i.value):this.G(i.value);e&&this.A.set(t,{undo:e,valueHash:r})}}return i}H(t){const e=this.A.get(t);e&&(e.undo(),this.A.delete(t))}B(t){if(!this.R)return;const e=this.i.experiments||[],n=new Set(e);this.A.forEach(((t,e)=>{n.has(e)||(t.undo(),this.A.delete(e))}));for(const n of e){const e=this.j(n,t);if(null!=e&&e.inExperiment&&\"redirect\"===P(n))break}}J(t,e){const n=t.key,i=this.g.get(n);i&&i.result.inExperiment===e.inExperiment&&i.result.variationId===e.variationId||(this.g.set(n,{experiment:t,result:e}),this.p.forEach((n=>{try{n(t,e)}catch(t){console.error(t)}})))}Z(t,e){if(\"override\"===e.source)return;const n=JSON.stringify(e.value);if(this.l[t]!==n){if(this.l[t]=n,this.i.onFeatureUsage)try{this.i.onFeatureUsage(t,e)}catch(t){}et&&window.fetch&&(this.v.push({key:t,on:e.on}),this.m||(this.m=window.setTimeout((()=>{this.m=0;const t=[...this.v];this.v=[],this.i.realtimeKey&&window.fetch(\"https://rt.growthbook.io/?key=\".concat(this.i.realtimeKey,\"&events=\").concat(encodeURIComponent(JSON.stringify(t))),{cache:\"no-cache\",mode:\"no-cors\"}).catch((()=>{}))}),this.i.realtimeInterval||2e3)))}}W(t,e,n,i,r,s){const o={value:e,on:!!e,off:!e,source:n,ruleId:i||\"\"};return r&&(o.experiment=r),s&&(o.experimentResult=s),this.Z(t,o),o}isOn(t){return this.evalFeature(t).on}isOff(t){return this.evalFeature(t).off}getFeatureValue(t,e){const n=this.evalFeature(t).value;return null===n?e:n}feature(t){return this.evalFeature(t)}evalFeature(t){return this.X(t)}X(t,e){if((e=e||{evaluatedFeatures:new Set}).evaluatedFeatures.has(t))return this.W(t,null,\"cyclicPrerequisite\");if(e.evaluatedFeatures.add(t),e.id=t,this.k.has(t))return this.W(t,this.k.get(t),\"override\");if(!this.i.features||!this.i.features[t])return this.W(t,null,\"unknownFeature\");const n=this.i.features[t];if(n.rules)t:for(const i of n.rules){if(i.parentConditions)for(const n of i.parentConditions){const i=this.X(n.id,e);if(\"cyclicPrerequisite\"===i.source)return this.W(t,null,\"cyclicPrerequisite\");if(!G({value:i.value},n.condition||{})){if(n.gate)return this.W(t,null,\"prerequisite\");continue t}}if(i.filters&&this.Y(i.filters))continue;if(\"force\"in i){if(i.condition&&!this.tt(i.condition))continue;if(!this.et(i.seed||t,i.hashAttribute,this.i.stickyBucketService&&!i.disableStickyBucketing?i.fallbackAttribute:void 0,i.range,i.coverage,i.hashVersion))continue;return i.tracks&&i.tracks.forEach((t=>{this.nt(t.experiment,t.result)})),this.W(t,i.force,\"force\",i.id)}if(!i.variations)continue;const n={variations:i.variations,key:i.key||t};\"coverage\"in i&&(n.coverage=i.coverage),i.weights&&(n.weights=i.weights),i.hashAttribute&&(n.hashAttribute=i.hashAttribute),i.fallbackAttribute&&(n.fallbackAttribute=i.fallbackAttribute),i.disableStickyBucketing&&(n.disableStickyBucketing=i.disableStickyBucketing),void 0!==i.bucketVersion&&(n.bucketVersion=i.bucketVersion),void 0!==i.minBucketVersion&&(n.minBucketVersion=i.minBucketVersion),i.namespace&&(n.namespace=i.namespace),i.meta&&(n.meta=i.meta),i.ranges&&(n.ranges=i.ranges),i.name&&(n.name=i.name),i.phase&&(n.phase=i.phase),i.seed&&(n.seed=i.seed),i.hashVersion&&(n.hashVersion=i.hashVersion),i.filters&&(n.filters=i.filters),i.condition&&(n.condition=i.condition);const r=this.D(n,t);if(this.J(n,r),r.inExperiment&&!r.passthrough)return this.W(t,r.value,\"experiment\",i.id,n,r)}return this.W(t,void 0===n.defaultValue?null:n.defaultValue,\"defaultValue\")}et(t,e,n,i,r,s){if(!i&&void 0===r)return!0;if(!i&&0===r)return!1;const{hashValue:o}=this.it(e,n);if(!o)return!1;const u=U(t,o,s||1);return null!==u&&(i?V(u,i):void 0===r||u<=r)}tt(t){return G(this.getAttributes(),t)}Y(t){return t.some((t=>{const{hashValue:e}=this.it(t.attribute);if(!e)return!0;const n=U(t.seed,e,t.hashVersion||2);return null===n||!t.ranges.some((t=>V(n,t)))}))}D(t,e){const n=t.key,i=t.variations.length;if(i<2)return this.L(t,-1,!1,e);if(!1===this.i.enabled)return this.L(t,-1,!1,e);if((t=this.rt(t)).urlPatterns&&!D(this.q(),t.urlPatterns))return this.L(t,-1,!1,e);const r=function(t,e,n){if(!e)return null;const i=e.split(\"?\")[1];if(!i)return null;const r=i.replace(/#.*/,\"\").split(\"&\").map((t=>t.split(\"=\",2))).filter((e=>{let[n]=e;return n===t})).map((t=>{let[,e]=t;return parseInt(e)}));return r.length>0&&r[0]>=0&&r[0]<n?r[0]:null}(n,this.q(),i);if(null!==r)return this.L(t,r,!1,e);if(this.i.forcedVariations&&n in this.i.forcedVariations)return this.L(t,this.i.forcedVariations[n],!1,e);if(\"draft\"===t.status||!1===t.active)return this.L(t,-1,!1,e);const{hashAttribute:s,hashValue:o}=this.it(t.hashAttribute,this.i.stickyBucketService&&!t.disableStickyBucketing?t.fallbackAttribute:void 0);if(!o)return this.L(t,-1,!1,e);let u=-1,c=!1,a=!1;if(this.i.stickyBucketService&&!t.disableStickyBucketing){const{variation:e,versionIsBlocked:n}=this.st({expKey:t.key,expBucketVersion:t.bucketVersion,expHashAttribute:t.hashAttribute,expFallbackAttribute:t.fallbackAttribute,expMinBucketVersion:t.minBucketVersion,expMeta:t.meta});c=e>=0,u=e,a=!!n}if(!c){if(t.filters){if(this.Y(t.filters))return this.L(t,-1,!1,e)}else if(t.namespace&&!function(t,e){const n=U(\"__\"+e[0],t,1);return null!==n&&n>=e[1]&&n<e[2]}(o,t.namespace))return this.L(t,-1,!1,e);if(t.include&&!function(t){try{return t()}catch(t){return console.error(t),!1}}(t.include))return this.L(t,-1,!1,e);if(t.condition&&!this.tt(t.condition))return this.L(t,-1,!1,e);if(t.parentConditions)for(const n of t.parentConditions){const i=this.X(n.id);if(\"cyclicPrerequisite\"===i.source)return this.L(t,-1,!1,e);if(!G({value:i.value},n.condition||{}))return this.L(t,-1,!1,e)}if(t.groups&&!this.ot(t.groups))return this.L(t,-1,!1,e)}if(t.url&&!this.ut(t.url))return this.L(t,-1,!1,e);const h=U(t.seed||n,o,t.hashVersion||1);if(null===h)return this.L(t,-1,!1,e);if(c||(u=function(t,e){for(let n=0;n<e.length;n++)if(V(t,e[n]))return n;return-1}(h,t.ranges||function(t,e,n){(e=void 0===e?1:e)<0?e=0:e>1&&(e=1);const i=(r=t)<=0?[]:new Array(r).fill(1/r);var r;(n=n||i).length!==t&&(n=i);const s=n.reduce(((t,e)=>e+t),0);(s<.99||s>1.01)&&(n=i);let o=0;return n.map((t=>{const n=o;return o+=t,[n,n+e*t]}))}(i,void 0===t.coverage?1:t.coverage,t.weights))),a)return this.L(t,-1,!1,e,void 0,!0);if(u<0)return this.L(t,-1,!1,e);if(\"force\"in t)return this.L(t,void 0===t.force?-1:t.force,!1,e);if(this.i.qaMode)return this.L(t,-1,!1,e);if(\"stopped\"===t.status)return this.L(t,-1,!1,e);const l=this.L(t,u,!0,e,h,c);if(this.i.stickyBucketService&&!t.disableStickyBucketing){const{changed:e,key:n,doc:i}=this.ct(s,L(o),{[this.ht(t.key,t.bucketVersion)]:l.key});e&&(this.i.stickyBucketAssignmentDocs=this.i.stickyBucketAssignmentDocs||{},this.i.stickyBucketAssignmentDocs[n]=i,this.i.stickyBucketService.saveAssignments(i))}return this.nt(t,l),\"changeId\"in t&&t.changeId&&this.h.add(t.changeId),l}log(t,e){this.debug&&(this.i.log?this.i.log(t,e):console.log(t,e))}getDeferredTrackingCalls(){return Array.from(this.$.values())}setDeferredTrackingCalls(t){this.$=new Map(t.filter((t=>t&&t.experiment&&t.result)).map((t=>[this.lt(t.experiment,t.result),t])))}fireDeferredTrackingCalls(){this.i.trackingCallback&&(this.$.forEach((t=>{t&&t.experiment&&t.result?this.nt(t.experiment,t.result):console.error(\"Invalid deferred tracking call\",{call:t})})),this.$.clear())}setTrackingCallback(t){this.i.trackingCallback=t,this.fireDeferredTrackingCalls()}lt(t,e){return e.hashAttribute+e.hashValue+t.key+e.variationId}nt(t,e){const n=this.lt(t,e);if(this.i.trackingCallback){if(!this.u.has(n)){this.u.add(n);try{this.i.trackingCallback(t,e)}catch(t){console.error(t)}}}else this.$.has(n)||this.$.set(n,{experiment:t,result:e})}rt(t){const e=t.key,n=this.i.overrides;return n&&n[e]&&\"string\"==typeof(t=Object.assign({},t,n[e])).url&&(t.url=I(t.url)),t}it(t,e){let n=t||\"id\",i=\"\";return this.S[n]?i=this.S[n]:this.i.attributes?i=this.i.attributes[n]||\"\":this.i.user&&(i=this.i.user[n]||\"\"),!i&&e&&(this.S[e]?i=this.S[e]:this.i.attributes?i=this.i.attributes[e]||\"\":this.i.user&&(i=this.i.user[e]||\"\"),i&&(n=e)),{hashAttribute:n,hashValue:i}}L(t,e,n,i,r,s){let o=!0;(e<0||e>=t.variations.length)&&(e=0,o=!1);const{hashAttribute:u,hashValue:c}=this.it(t.hashAttribute,this.i.stickyBucketService&&!t.disableStickyBucketing?t.fallbackAttribute:void 0),a=t.meta?t.meta[e]:{},h={key:a.key||\"\"+e,featureId:i,inExperiment:o,hashUsed:n,variationId:e,value:t.variations[e],hashAttribute:u,hashValue:c,stickyBucketUsed:!!s};return a.name&&(h.name=a.name),void 0!==r&&(h.bucket=r),a.passthrough&&(h.passthrough=a.passthrough),h}q(){return this.i.url||(et?window.location.href:\"\")}ut(t){const e=this.q();if(!e)return!1;const n=e.replace(/^https?:\\/\\//,\"\").replace(/^[^/]*\\//,\"/\");return!!t.test(e)||!!t.test(n)}ot(t){const e=this.i.groups||{};for(let n=0;n<t.length;n++)if(e[t[n]])return!0;return!1}K(t){const e=P(t);if(\"visual\"===e){if(this.i.disableVisualExperiments)return!0;if(this.i.disableJsInjection&&t.variations.some((t=>t.js)))return!0}else{if(\"redirect\"!==e)return!0;if(this.i.disableUrlRedirectExperiments)return!0;try{const e=new URL(this.q());for(const n of t.variations){if(!n||!n.urlRedirect)continue;const t=new URL(n.urlRedirect);if(this.i.disableCrossOriginUrlRedirectExperiments){if(t.protocol!==e.protocol)return!0;if(t.host!==e.host)return!0}}}catch(e){return this.log(\"Error parsing current or redirect URL\",{id:t.key,error:e}),!0}}return!(!t.changeId||!(this.i.blockedChangeIds||[]).includes(t.changeId))}getRedirectUrl(){return this.O}P(){return this.i.navigate?this.i.navigate:et?t=>{window.location.replace(t)}:null}F(){if(this.i.antiFlicker&&et)try{var t;const e=document.createElement(\"style\");e.innerHTML=\".gb-anti-flicker { opacity: 0 !important; pointer-events: none; }\",document.head.appendChild(e),document.documentElement.classList.add(\"gb-anti-flicker\"),setTimeout((()=>{document.documentElement.classList.remove(\"gb-anti-flicker\")}),null!==(t=this.i.antiFlickerTimeout)&&void 0!==t?t:3500)}catch(t){console.error(t)}}G(t){if(!et)return;const e=[];if(t.css){const n=document.createElement(\"style\");n.innerHTML=t.css,document.head.appendChild(n),e.push((()=>n.remove()))}if(t.js){const n=document.createElement(\"script\");n.innerHTML=t.js,this.i.jsInjectionNonce&&(n.nonce=this.i.jsInjectionNonce),document.head.appendChild(n),e.push((()=>n.remove()))}return t.domMutations&&t.domMutations.forEach((t=>{e.push(function(t){var e=t.selector,n=t.action,r=t.value,s=t.attribute,o=t.parentSelector,u=t.insertBeforeSelector;if(\"html\"===s){if(\"append\"===n)return B(e,(function(t){return t+(null!=r?r:\"\")}));if(\"set\"===n)return B(e,(function(){return null!=r?r:\"\"}))}else if(\"class\"===s){if(\"append\"===n)return F(e,(function(t){r&&t.add(r)}));if(\"remove\"===n)return F(e,(function(t){r&&t.delete(r)}));if(\"set\"===n)return F(e,(function(t){t.clear(),r&&t.add(r)}))}else if(\"position\"===s){if(\"set\"===n&&o)return function(t,e){return R({kind:\"position\",elements:new Set,mutate:function(){return{insertBeforeSelector:u,parentSelector:o}},selector:t})}(e)}else{if(\"append\"===n)return T(e,s,(function(t){return null!==t?t+(null!=r?r:\"\"):null!=r?r:\"\"}));if(\"set\"===n)return T(e,s,(function(){return null!=r?r:\"\"}));if(\"remove\"===n)return T(e,s,(function(){return null}))}return i}(t).revert)})),()=>{e.forEach((t=>t()))}}ft(t){const e=new Set,n=t&&t.features?t.features:this.getFeatures(),i=t&&t.experiments?t.experiments:this.getExperiments();return Object.keys(n).forEach((t=>{const i=n[t];if(i.rules)for(const t of i.rules)t.variations&&(e.add(t.hashAttribute||\"id\"),t.fallbackAttribute&&e.add(t.fallbackAttribute))})),i.map((t=>{e.add(t.hashAttribute||\"id\"),t.fallbackAttribute&&e.add(t.fallbackAttribute)})),Array.from(e)}async refreshStickyBuckets(t){if(this.i.stickyBucketService){const e=this.dt(t);this.i.stickyBucketAssignmentDocs=await this.i.stickyBucketService.getAllAssignments(e)}}wt(t,e){if(!this.i.stickyBucketAssignmentDocs)return{};const{hashAttribute:n,hashValue:i}=this.it(t),r=\"\".concat(n,\"||\").concat(L(i)),{hashAttribute:s,hashValue:o}=this.it(e),u=o?\"\".concat(s,\"||\").concat(L(o)):null,c={};return u&&this.i.stickyBucketAssignmentDocs[u]&&Object.assign(c,this.i.stickyBucketAssignmentDocs[u].assignments||{}),this.i.stickyBucketAssignmentDocs[r]&&Object.assign(c,this.i.stickyBucketAssignmentDocs[r].assignments||{}),c}st(t){let{expKey:e,expBucketVersion:n,expHashAttribute:i,expFallbackAttribute:r,expMinBucketVersion:s,expMeta:o}=t;n=n||0,s=s||0,i=i||\"id\",o=o||[];const u=this.ht(e,n),c=this.wt(i,r);if(s>0)for(let t=0;t<=s;t++)if(void 0!==c[this.ht(e,t)])return{variation:-1,versionIsBlocked:!0};const a=c[u];if(void 0===a)return{variation:-1};const h=o.findIndex((t=>t.key===a));return h<0?{variation:-1}:{variation:h}}ht(t,e){return e=e||0,\"\".concat(t,\"__\").concat(e)}dt(t){const e={};return this.i.stickyBucketIdentifierAttributes=this.i.stickyBucketIdentifierAttributes?this.i.stickyBucketIdentifierAttributes:this.ft(t),this.i.stickyBucketIdentifierAttributes.forEach((t=>{const{hashValue:n}=this.it(t);e[t]=L(n)})),e}ct(t,e,n){const i=\"\".concat(t,\"||\").concat(e),r=this.i.stickyBucketAssignmentDocs&&this.i.stickyBucketAssignmentDocs[i]&&this.i.stickyBucketAssignmentDocs[i].assignments||{},s={...r,...n};return{key:i,doc:{attributeName:t,attributeValue:e,assignments:s},changed:JSON.stringify(r)!==JSON.stringify(s)}}}({...Et,remoteEval:!!Et.remoteEval,trackingCallback:(t,e)=>{const n={experiment_id:t.key,variation_id:e.key};window.gtag&&window.gtag(\"event\",\"experiment_viewed\",n),window.dataLayer&&window.dataLayer.push({event:\"experiment_viewed\",...n}),window.analytics&&window.analytics.track&&window.analytics.track(\"Experiment Viewed\",n)},...Ct,attributes:Vt(),stickyBucketService:Ft});It.setRenderer((()=>{document.dispatchEvent(new CustomEvent(\"growthbookdata\"))})),It.init({payload:Ct.payload,streaming:!(Ct.noStreaming||Et.noStreaming||!1===Ct.backgroundSync)});let Dt=location.href;setInterval((()=>{location.href!==Dt&&(Dt=location.href,It.setURL(Dt),It.updateAttributes(Vt()))}),500),document.addEventListener(\"growthbookrefresh\",(()=>{location.href!==Dt&&(Dt=location.href,It.setURL(Dt)),It.updateAttributes(Vt())})),document.addEventListener(\"growthbookpersist\",(()=>{Nt()}));const Jt=t=>{try{t&&t(It)}catch(t){console.error(\"Uncaught growthbook_queue error\",t)}};return window.growthbook_queue&&Array.isArray(window.growthbook_queue)&&window.growthbook_queue.forEach((t=>{Jt(t)})),window.growthbook_queue={push:t=>{Jt(t)}},It}();\n//# sourceMappingURL=auto.min.js.map\n";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sdkWrapper = void 0;
|
|
4
|
+
exports.sdkWrapper = "var _growthbook=function(){\"use strict\";function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)t[i]=n[i]}return t}var e=function e(n,i){function r(e,r,s){if(\"undefined\"!=typeof document){\"number\"==typeof(s=t({},i,s)).expires&&(s.expires=new Date(Date.now()+864e5*s.expires)),s.expires&&(s.expires=s.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o=\"\";for(var u in s)s[u]&&(o+=\"; \"+u,!0!==s[u]&&(o+=\"=\"+s[u].split(\";\")[0]));return document.cookie=e+\"=\"+n.write(r,e)+o}}return Object.create({set:r,get:function(t){if(\"undefined\"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split(\"; \"):[],i={},r=0;r<e.length;r++){var s=e[r].split(\"=\"),o=s.slice(1).join(\"=\");try{var u=decodeURIComponent(s[0]);if(i[u]=n.read(o,u),t===u)break}catch(t){}}return t?i[t]:i}},remove:function(e,n){r(e,\"\",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}({read:function(t){return\'\"\'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:\"/\"}),n=/^[a-zA-Z:_][a-zA-Z0-9:_.-]*$/,i={revert:function(){}},r=new Map,s=new Set;function o(t){var e=r.get(t);return e||r.set(t,e={element:t,attributes:{}}),e}function u(t,e,n,i,r){var s=n(t),o={isDirty:!1,originalValue:s,virtualValue:s,mutations:[],el:t,t:null,observer:new MutationObserver((function(){if(\"position\"!==e||!o.t){\"position\"===e&&(o.t=setTimeout((function(){o.t=null}),1e3));var i=n(t);\"position\"===e&&i.parentNode===o.virtualValue.parentNode&&i.insertBeforeNode===o.virtualValue.insertBeforeNode||i!==o.virtualValue&&(o.originalValue=i,r(o))}})),mutationRunner:r,setValue:i,getCurrentValue:n};return\"position\"===e&&t.parentNode?o.observer.observe(t.parentNode,{childList:!0,subtree:!0,attributes:!1,characterData:!1}):o.observer.observe(t,function(t){return\"html\"===t?{childList:!0,subtree:!0,attributes:!0,characterData:!0}:{childList:!1,subtree:!1,attributes:!0,attributeFilter:[t]}}(e)),o}function c(t,e){var n=e.getCurrentValue(e.el);e.virtualValue=t,t&&\"string\"!=typeof t?n&&t.parentNode===n.parentNode&&t.insertBeforeNode===n.insertBeforeNode||(e.isDirty=!0,C()):t!==n&&(e.isDirty=!0,C())}function a(t){var e=t.originalValue;t.mutations.forEach((function(t){return e=t.mutate(e)})),c(function(t){return g||(g=document.createElement(\"div\")),g.innerHTML=t,g.innerHTML}(e),t)}function h(t){var e=new Set(t.originalValue.split(/\\s+/).filter(Boolean));t.mutations.forEach((function(t){return t.mutate(e)})),c(Array.from(e).filter(Boolean).join(\" \"),t)}function l(t){var e=t.originalValue;t.mutations.forEach((function(t){return e=t.mutate(e)})),c(e,t)}function f(t){var e=t.originalValue;t.mutations.forEach((function(t){var n=function(t){var e=t.insertBeforeSelector,n=document.querySelector(t.parentSelector);if(!n)return null;var i=e?document.querySelector(e):null;return e&&!i?null:{parentNode:n,insertBeforeNode:i}}(t.mutate());e=n||e})),c(e,t)}var d=function(t){return t.innerHTML},w=function(t,e){return t.innerHTML=e};function y(t){var e=o(t);return e.html||(e.html=u(t,\"html\",d,w,a)),e.html}var p=function(t){return{parentNode:t.parentElement,insertBeforeNode:t.nextElementSibling}},v=function(t,e){e.insertBeforeNode&&!e.parentNode.contains(e.insertBeforeNode)||e.parentNode.insertBefore(t,e.insertBeforeNode)};function m(t){var e=o(t);return e.position||(e.position=u(t,\"position\",p,v,f)),e.position}var g,b,k=function(t,e){return e?t.className=e:t.removeAttribute(\"class\")},S=function(t){return t.className};function A(t){var e=o(t);return e.classes||(e.classes=u(t,\"class\",S,k,h)),e.classes}function _(t,e){var n,i=o(t);return i.attributes[e]||(i.attributes[e]=u(t,e,(n=e,function(t){var e;return null!=(e=t.getAttribute(n))?e:null}),function(t){return function(e,n){return null!==n?e.setAttribute(t,n):e.removeAttribute(t)}}(e),l)),i.attributes[e]}function x(t,e,n){if(n.isDirty){n.isDirty=!1;var i=n.virtualValue;n.mutations.length||function(t,e){var n,i,s=r.get(t);if(s)if(\"html\"===e)null==(n=s.html)||null==(i=n.observer)||i.disconnect(),delete s.html;else if(\"class\"===e){var o,u;null==(o=s.classes)||null==(u=o.observer)||u.disconnect(),delete s.classes}else if(\"position\"===e){var c,a;null==(c=s.position)||null==(a=c.observer)||a.disconnect(),delete s.position}else{var h,l,f;null==(h=s.attributes)||null==(l=h[e])||null==(f=l.observer)||f.disconnect(),delete s.attributes[e]}}(t,e),n.setValue(t,i)}}function E(t,e){t.html&&x(e,\"html\",t.html),t.classes&&x(e,\"class\",t.classes),t.position&&x(e,\"position\",t.position),Object.keys(t.attributes).forEach((function(n){x(e,n,t.attributes[n])}))}function C(){r.forEach(E)}function O(t){if(\"position\"!==t.kind||1!==t.elements.size){var e=new Set(t.elements);document.querySelectorAll(t.selector).forEach((function(n){e.has(n)||(t.elements.add(n),function(t,e){var n=null;\"html\"===t.kind?n=y(e):\"class\"===t.kind?n=A(e):\"attribute\"===t.kind?n=_(e,t.attribute):\"position\"===t.kind&&(n=m(e)),n&&(n.mutations.push(t),n.mutationRunner(n))}(t,n))}))}}function $(){s.forEach(O)}function R(t){return\"undefined\"==typeof document?i:(s.add(t),O(t),{revert:function(){var e;(e=t).elements.forEach((function(t){return function(t,e){var n=null;if(\"html\"===t.kind?n=y(e):\"class\"===t.kind?n=A(e):\"attribute\"===t.kind?n=_(e,t.attribute):\"position\"===t.kind&&(n=m(e)),n){var i=n.mutations.indexOf(t);-1!==i&&n.mutations.splice(i,1),n.mutationRunner(n)}}(e,t)})),e.elements.clear(),s.delete(e)}})}function B(t,e){return R({kind:\"html\",elements:new Set,mutate:e,selector:t})}function F(t,e){return R({kind:\"class\",elements:new Set,mutate:e,selector:t})}function T(t,e,r){return n.test(e)?\"class\"===e||\"className\"===e?F(t,(function(t){var e=r(Array.from(t).join(\" \"));t.clear(),e&&e.split(/\\s+/g).filter(Boolean).forEach((function(e){return t.add(e)}))})):R({kind:\"attribute\",attribute:e,elements:new Set,mutate:r,selector:t}):i}\"undefined\"!=typeof document&&(b||(b=new MutationObserver((function(){$()}))),$(),b.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1,characterData:!1}));const N={fetch:globalThis.fetch?globalThis.fetch.bind(globalThis):void 0,SubtleCrypto:globalThis.crypto?globalThis.crypto.subtle:void 0,EventSource:globalThis.EventSource};function M(t){let e=2166136261;const n=t.length;for(let i=0;i<n;i++)e^=t.charCodeAt(i),e+=(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24);return e>>>0}function U(t,e,n){return 2===n?M(M(t+e)+\"\")%1e4/1e4:1===n?M(e+t)%1e3/1e3:null}function V(t,e){return t>=e[0]&&t<e[1]}function I(t){try{const e=t.replace(/([^\\\\])\\//g,\"$1\\\\/\");return new RegExp(e)}catch(t){return void console.error(t)}}function D(t,e){if(!e.length)return!1;let n=!1,i=!1;for(let r=0;r<e.length;r++){const s=J(t,e[r].type,e[r].pattern);if(!1===e[r].include){if(s)return!1}else n=!0,s&&(i=!0)}return i||!n}function J(t,e,n){try{const i=new URL(t,\"https://_\");if(\"regex\"===e){const t=I(n);return!!t&&(t.test(i.href)||t.test(i.href.substring(i.origin.length)))}return\"simple\"===e&&function(t,e){try{const n=new URL(e.replace(/^([^:/?]*)\\./i,\"https://$1.\").replace(/\\*/g,\"_____\"),\"https://_____\"),i=[[t.host,n.host,!1],[t.pathname,n.pathname,!0]];return n.hash&&i.push([t.hash,n.hash,!1]),n.searchParams.forEach(((e,n)=>{i.push([t.searchParams.get(n)||\"\",e,!1])})),!i.some((t=>!function(t,e,n){try{let i=e.replace(/[*.+?^${}()|[\\]\\\\]/g,\"\\\\$&\").replace(/_____/g,\".*\");return n&&(i=\"\\\\/?\"+i.replace(/(^\\/|\\/$)/g,\"\")+\"\\\\/?\"),new RegExp(\"^\"+i+\"$\",\"i\").test(t)}catch(t){return!1}}(t[0],t[1],t[2])))}catch(t){return!1}}(i,n)}catch(t){return!1}}const j=t=>Uint8Array.from(atob(t),(t=>t.charCodeAt(0)));async function K(t,e,n){if(e=e||\"\",!(n=n||globalThis.crypto&&globalThis.crypto.subtle||N.SubtleCrypto))throw new Error(\"No SubtleCrypto implementation found\");try{const i=await n.importKey(\"raw\",j(e),{name:\"AES-CBC\",length:128},!0,[\"encrypt\",\"decrypt\"]),[r,s]=t.split(\".\"),o=await n.decrypt({name:\"AES-CBC\",iv:j(r)},i,j(s));return(new TextDecoder).decode(o)}catch(t){throw new Error(\"Failed to decrypt\")}}function L(t){return\"string\"==typeof t?t:JSON.stringify(t)}function H(t){\"number\"==typeof t&&(t+=\"\"),t&&\"string\"==typeof t||(t=\"0\");const e=t.replace(/(^v|\\+.*$)/g,\"\").split(/[-.]/);return 3===e.length&&e.push(\"~\"),e.map((t=>t.match(/^[0-9]+$/)?t.padStart(5,\" \"):t)).join(\"-\")}function q(t){return\"object\"==typeof t&&null!==t}function P(t){return t.urlPatterns&&t.variations.some((t=>q(t)&&\"urlRedirect\"in t))?\"redirect\":t.variations.some((t=>q(t)&&(t.domMutations||\"js\"in t||\"css\"in t)))?\"visual\":\"unknown\"}const z={};function G(t,e){if(\"$or\"in e)return tt(t,e.$or);if(\"$nor\"in e)return!tt(t,e.$nor);if(\"$and\"in e)return function(t,e){for(let n=0;n<e.length;n++)if(!G(t,e[n]))return!1;return!0}(t,e.$and);if(\"$not\"in e)return!G(t,e.$not);for(const[n,i]of Object.entries(e))if(!Q(i,Z(t,n)))return!1;return!0}function Z(t,e){const n=e.split(\".\");let i=t;for(let t=0;t<n.length;t++){if(!i||\"object\"!=typeof i||!(n[t]in i))return null;i=i[n[t]]}return i}function Q(t,e){if(\"string\"==typeof t)return e+\"\"===t;if(\"number\"==typeof t)return 1*e===t;if(\"boolean\"==typeof t)return!!e===t;if(null===t)return null===e;if(Array.isArray(t)||!W(t))return JSON.stringify(e)===JSON.stringify(t);for(const n in t)if(!Y(n,e,t[n]))return!1;return!0}function W(t){const e=Object.keys(t);return e.length>0&&e.filter((t=>\"$\"===t[0])).length===e.length}function X(t,e){return Array.isArray(t)?t.some((t=>e.includes(t))):e.includes(t)}function Y(t,e,n){switch(t){case\"$veq\":return H(e)===H(n);case\"$vne\":return H(e)!==H(n);case\"$vgt\":return H(e)>H(n);case\"$vgte\":return H(e)>=H(n);case\"$vlt\":return H(e)<H(n);case\"$vlte\":return H(e)<=H(n);case\"$eq\":return e===n;case\"$ne\":return e!==n;case\"$lt\":return e<n;case\"$lte\":return e<=n;case\"$gt\":return e>n;case\"$gte\":return e>=n;case\"$exists\":return n?null!=e:null==e;case\"$in\":return!!Array.isArray(n)&&X(e,n);case\"$nin\":return!!Array.isArray(n)&&!X(e,n);case\"$not\":return!Q(n,e);case\"$size\":return!!Array.isArray(e)&&Q(n,e.length);case\"$elemMatch\":return function(t,e){if(!Array.isArray(t))return!1;const n=W(e)?t=>Q(e,t):t=>G(t,e);for(let e=0;e<t.length;e++)if(t[e]&&n(t[e]))return!0;return!1}(e,n);case\"$all\":if(!Array.isArray(e))return!1;for(let t=0;t<n.length;t++){let i=!1;for(let r=0;r<e.length;r++)if(Q(n[t],e[r])){i=!0;break}if(!i)return!1}return!0;case\"$regex\":try{return(i=n,z[i]||(z[i]=new RegExp(i.replace(/([^\\\\])\\//g,\"$1\\\\/\"))),z[i]).test(e)}catch(t){return!1}case\"$type\":return function(t){if(null===t)return\"null\";if(Array.isArray(t))return\"array\";const e=typeof t;return[\"string\",\"number\",\"boolean\",\"object\",\"undefined\"].includes(e)?e:\"unknown\"}(e)===n;default:return console.error(\"Unknown operator: \"+t),!1}var i}function tt(t,e){if(!e.length)return!0;for(let n=0;n<e.length;n++)if(G(t,e[n]))return!0;return!1}const et=\"undefined\"!=typeof window&&\"undefined\"!=typeof document,nt=function(){let t;try{t=\"1.0.0\"}catch(e){t=\"\"}return t}(),it={staleTTL:6e4,maxAge:864e5,cacheKey:\"gbFeaturesCache\",backgroundSync:!0,maxEntries:10,disableIdleStreams:!1,idleStreamInterval:2e4,disableCache:!1},rt=N,st={fetchFeaturesCall:t=>{let{host:e,clientKey:n,headers:i}=t;return rt.fetch(\"\".concat(e,\"/api/features/\").concat(n),{headers:i})},fetchRemoteEvalCall:t=>{let{host:e,clientKey:n,payload:i,headers:r}=t;const s={method:\"POST\",headers:{\"Content-Type\":\"application/json\",...r},body:JSON.stringify(i)};return rt.fetch(\"\".concat(e,\"/api/eval/\").concat(n),s)},eventSourceCall:t=>{let{host:e,clientKey:n,headers:i}=t;return i?new rt.EventSource(\"\".concat(e,\"/sub/\").concat(n),{headers:i}):new rt.EventSource(\"\".concat(e,\"/sub/\").concat(n))},startIdleListener:()=>{let t;if(\"undefined\"==typeof window||\"undefined\"==typeof document)return;const e=()=>{\"visible\"===document.visibilityState?(window.clearTimeout(t),ht.forEach((t=>{t&&\"idle\"===t.state&&At(t)}))):\"hidden\"===document.visibilityState&&(t=window.setTimeout(dt,it.idleStreamInterval))};return document.addEventListener(\"visibilitychange\",e),()=>document.removeEventListener(\"visibilitychange\",e)},stopIdleListener:()=>{}};try{globalThis.localStorage&&(rt.localStorage=globalThis.localStorage)}catch(t){}const ot=new Map;let ut=!1;const ct=new Map,at=new Map,ht=new Map,lt=new Set;function ft(t){const e=yt(t),n=ot.get(e)||new Set;n.add(t),ot.set(e,n)}function dt(){ht.forEach((t=>{t&&(t.state=\"idle\",St(t))}))}async function wt(){try{if(!rt.localStorage)return;await rt.localStorage.setItem(it.cacheKey,JSON.stringify(Array.from(ct.entries())))}catch(t){}}function yt(t){const[e,n]=t.getApiInfo();return\"\".concat(e,\"||\").concat(n)}function pt(t){const e=yt(t);if(!t.isRemoteEval())return e;const n=t.getAttributes(),i=t.getCacheKeyAttributes()||Object.keys(t.getAttributes()),r={};i.forEach((t=>{r[t]=n[t]}));const s=t.getForcedVariations(),o=t.getUrl();return\"\".concat(e,\"||\").concat(JSON.stringify({ca:r,fv:s,url:o}))}function vt(){const t=Array.from(ct.entries()).map((t=>{let[e,n]=t;return{key:e,staleAt:n.staleAt.getTime()}})).sort(((t,e)=>t.staleAt-e.staleAt)),e=Math.min(Math.max(0,ct.size-it.maxEntries),ct.size);for(let n=0;n<e;n++)ct.delete(t[n].key)}function mt(t,e,n){const i=n.dateUpdated||\"\",r=new Date(Date.now()+it.staleTTL),s=ct.get(e);if(s&&i&&s.version===i)return s.staleAt=r,void wt();ct.set(e,{data:n,version:i,staleAt:r,sse:lt.has(t)}),vt(),wt();const o=ot.get(t);o&&o.forEach((t=>async function(t,e){await t.setPayload(e||t.getPayload())}(t,n)))}async function gt(t){const{apiHost:e,apiRequestHeaders:n}=t.getApiHosts(),i=t.getClientKey(),r=t.isRemoteEval(),s=yt(t),o=pt(t);let u=at.get(o);return u||(u=(r?st.fetchRemoteEvalCall({host:e,clientKey:i,payload:{attributes:t.getAttributes(),forcedVariations:t.getForcedVariations(),forcedFeatures:Array.from(t.getForcedFeatures().entries()),url:t.getUrl()},headers:n}):st.fetchFeaturesCall({host:e,clientKey:i,headers:n})).then((t=>{if(!t.ok)throw new Error(\"HTTP error: \".concat(t.status));return\"enabled\"===t.headers.get(\"x-sse-support\")&<.add(s),t.json()})).then((e=>(mt(s,o,e),bt(t),at.delete(o),{data:e,success:!0,source:\"network\"}))).catch((t=>(at.delete(o),{data:null,source:\"error\",success:!1,error:t}))),at.set(o,u)),u}function bt(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=yt(t),i=pt(t),{streamingHost:r,streamingHostRequestHeaders:s}=t.getApiHosts(),o=t.getClientKey();if(e&<.add(n),it.backgroundSync&<.has(n)&&rt.EventSource){if(ht.has(n))return;const t={src:null,host:r,clientKey:o,headers:s,cb:e=>{try{if(\"features-updated\"===e.type){const t=ot.get(n);t&&t.forEach((t=>{gt(t)}))}else if(\"features\"===e.type){const t=JSON.parse(e.data);mt(n,i,t)}t.errors=0}catch(e){kt(t)}},errors:0,state:\"active\"};ht.set(n,t),At(t)}}function kt(t){if(\"idle\"!==t.state&&(t.errors++,t.errors>3||t.src&&2===t.src.readyState)){const e=Math.pow(3,t.errors-3)*(1e3+1e3*Math.random());St(t),setTimeout((()=>{[\"idle\",\"active\"].includes(t.state)||At(t)}),Math.min(e,3e5))}}function St(t){t.src&&(t.src.onopen=null,t.src.onerror=null,t.src.close(),t.src=null,\"active\"===t.state&&(t.state=\"disabled\"))}function At(t){t.src=st.eventSourceCall({host:t.host,clientKey:t.clientKey,headers:t.headers}),t.state=\"active\",t.src.addEventListener(\"features\",t.cb),t.src.addEventListener(\"features-updated\",t.cb),t.src.onerror=()=>kt(t),t.src.onopen=()=>{t.errors=0}}class _t{async getAllAssignments(t){const e={};return(await Promise.all(Object.entries(t).map((t=>{let[e,n]=t;return this.getAssignments(e,n)})))).forEach((t=>{if(t){const n=\"\".concat(t.attributeName,\"||\").concat(t.attributeValue);e[n]=t}})),e}}window.dataLayer=window.dataLayer||[];const xt=document.currentScript,Et=xt?xt.dataset:{},Ct=window.growthbook_config||{};function Ot(t){const e=(\"; \"+document.cookie).split(\"; \".concat(t,\"=\"));return 2===e.length?e[1].split(\";\")[0]:\"\"}function $t(){return window.crypto&&crypto.randomUUID?crypto.randomUUID():\"10000000-1000-4000-8000-100000000000\".replace(/[018]/g,(t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)))}const Rt=Ct.uuidCookieName||Et.uuidCookieName||\"gbuuid\",Bt=Ct.uuidKey||Et.uuidKey||\"id\";let Ft,Tt=Ct.uuid||Et.uuid||\"\";function Nt(){!function(t,e){const n=new Date;n.setTime(n.getTime()+3456e7),document.cookie=t+\"=\"+e+\";path=/;expires=\"+n.toUTCString()}(Rt,Tt)}function Mt(){let t={};try{const e=sessionStorage.getItem(\"utm_params\");if(e&&(t=JSON.parse(e)),location.search){const e=new URLSearchParams(location.search);let n=!1;[\"source\",\"medium\",\"campaign\",\"term\",\"content\"].forEach((i=>{const r=\"utm_\".concat(i),s=\"utm\"+i[0].toUpperCase()+i.slice(1);e.has(r)&&(t[s]=e.get(r)||\"\",n=!0)})),n&&sessionStorage.setItem(\"utm_params\",JSON.stringify(t))}}catch(t){}return t}function Ut(){if(!window.dataLayer||!window.dataLayer.forEach)return{};const t={};return window.dataLayer.forEach((e=>{e&&\"object\"==typeof e&&!(\"length\"in e)&&(\"event\"in e||Object.keys(e).forEach((n=>{if(\"string\"!=typeof n||n.match(/^(gtm)/))return;const i=e[n];[\"string\",\"number\",\"boolean\"].includes(typeof i)&&(t[n]=i)})))})),t}function Vt(){const t=Et.noAutoAttributes?{}:function(t,e){const n=null==t.noAutoCookies,i=navigator.userAgent,r=i.match(/Edg/)?\"edge\":i.match(/Chrome/)?\"chrome\":i.match(/Firefox/)?\"firefox\":i.match(/Safari/)?\"safari\":\"unknown\",s=function(){let t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return Tt||(Tt=Ot(Rt),Tt||(Tt=$t(),t&&Nt(),Tt))}(n);return(e.persistUuidOnLoad||t.persistUuidOnLoad)&&n&&Nt(),{...Ut(),[Bt]:s,url:location.href,path:location.pathname,host:location.host,query:location.search,pageTitle:document&&document.title,deviceType:i.match(/Mobi/)?\"mobile\":\"desktop\",browser:r,...Mt()}}(Et,Ct);return Ct.attributes&&Object.assign(t,Ct.attributes),t}\"cookie\"===Ct.useStickyBucketService||\"cookie\"===Et.useStickyBucketService?Ft=new class extends _t{constructor(t){let{prefix:e=\"gbStickyBuckets__\",jsCookie:n,cookieAttributes:i={}}=t;super(),this.prefix=e,this.jsCookie=n,this.cookieAttributes=i}async getAssignments(t,e){const n=\"\".concat(t,\"||\").concat(e);let i=null;if(!this.jsCookie)return i;try{const t=this.jsCookie.get(this.prefix+n),e=JSON.parse(t||\"{}\");e.attributeName&&e.attributeValue&&e.assignments&&(i=e)}catch(t){}return i}async saveAssignments(t){const e=\"\".concat(t.attributeName,\"||\").concat(t.attributeValue);if(!this.jsCookie)return;const n=JSON.stringify(t);this.jsCookie.set(this.prefix+e,n,this.cookieAttributes)}}({prefix:Ct.stickyBucketPrefix||Et.stickyBucketPrefix||void 0,jsCookie:e}):\"localStorage\"!==Ct.useStickyBucketService&&\"localStorage\"!==Et.useStickyBucketService||(Ft=new class extends _t{constructor(t){t=t||{},super(),this.prefix=t.prefix||\"gbStickyBuckets__\";try{this.localStorage=t.localStorage||globalThis.localStorage}catch(t){}}async getAssignments(t,e){const n=\"\".concat(t,\"||\").concat(e);let i=null;if(!this.localStorage)return i;try{const t=await this.localStorage.getItem(this.prefix+n)||\"{}\",e=JSON.parse(t);e.attributeName&&e.attributeValue&&e.assignments&&(i=e)}catch(t){}return i}async saveAssignments(t){const e=\"\".concat(t.attributeName,\"||\").concat(t.attributeValue);if(this.localStorage)try{await this.localStorage.setItem(this.prefix+e,JSON.stringify(t))}catch(t){}}}({prefix:Ct.stickyBucketPrefix||Et.stickyBucketPrefix||void 0}));const It=new class{constructor(t){if(t=t||{},this.version=nt,this.i=this.context=t,this.o=t.renderer||null,this.u=new Set,this.h=new Set,this.l={},this.debug=!!t.debug,this.p=new Set,this.v=[],this.m=0,this.ready=!1,this.g=new Map,this.k=new Map,this.S={},this.A=new Map,this._=new Set,this.C=!1,this.O=\"\",this.$=new Map,this.R=!t.disableExperimentsOnLoad,t.remoteEval){if(t.decryptionKey)throw new Error(\"Encryption is not available for remoteEval\");if(!t.clientKey)throw new Error(\"Missing clientKey\");let e=!1;try{e=!!new URL(t.apiHost||\"\").hostname.match(/growthbook\\.io$/i)}catch(t){}if(e)throw new Error(\"Cannot use remoteEval on GrowthBook Cloud\")}else if(t.cacheKeyAttributes)throw new Error(\"cacheKeyAttributes are only used for remoteEval\");if(t.features&&(this.ready=!0),et&&t.enableDevMode&&(window._growthbook=this,document.dispatchEvent(new Event(\"gbloaded\"))),t.experiments?(this.ready=!0,this.B()):t.antiFlicker&&this.F(),this.i.stickyBucketService&&this.i.stickyBucketAssignmentDocs)for(const t in this.i.stickyBucketAssignmentDocs){const e=this.i.stickyBucketAssignmentDocs[t];e&&this.i.stickyBucketService.saveAssignments(e).catch((()=>{}))}this.ready&&this.refreshStickyBuckets(this.getPayload())}async setPayload(t){this.T=t;const e=await this.decryptPayload(t);this.N=e,await this.refreshStickyBuckets(e),e.features&&(this.i.features=e.features),e.experiments&&(this.i.experiments=e.experiments,this.B()),this.ready=!0,this.M()}initSync(t){this.C=!0;const e=t.payload;if(e.encryptedExperiments||e.encryptedFeatures)throw new Error(\"initSync does not support encrypted payloads\");if(this.i.stickyBucketService&&!this.i.stickyBucketAssignmentDocs)throw new Error(\"initSync requires you to pass stickyBucketAssignmentDocs into the GrowthBook constructor\");if(this.T=e,this.N=e,e.features&&(this.i.features=e.features),e.experiments&&(this.i.experiments=e.experiments,this.B()),this.ready=!0,t.streaming){if(!this.i.clientKey)throw new Error(\"Must specify clientKey to enable streaming\");bt(this,!0),ft(this)}return this}async init(t){if(this.C=!0,(t=t||{}).payload){if(await this.setPayload(t.payload),t.streaming){if(!this.i.clientKey)throw new Error(\"Must specify clientKey to enable streaming\");bt(this,!0),ft(this)}return{success:!0,source:\"init\"}}{const{data:e,...n}=await this.U({...t,allowStale:!0});return t.streaming&&ft(this),await this.setPayload(e||{}),n}}async loadFeatures(t){this.C=!0,(t=t||{}).autoRefresh&&(this.i.subscribeToChanges=!0);const{data:e}=await this.U({...t,allowStale:!0});await this.setPayload(e||{}),this.V()&&ft(this)}async refreshFeatures(t){const e=await this.U({...t||{},allowStale:!1});e.data&&await this.setPayload(e.data)}getApiInfo(){return[this.getApiHosts().apiHost,this.getClientKey()]}getApiHosts(){const t=this.i.apiHost||\"https://cdn.growthbook.io\";return{apiHost:t.replace(/\\/*$/,\"\"),streamingHost:(this.i.streamingHost||t).replace(/\\/*$/,\"\"),apiRequestHeaders:this.i.apiHostRequestHeaders,streamingHostRequestHeaders:this.i.streamingHostRequestHeaders}}getClientKey(){return this.i.clientKey||\"\"}getPayload(){return this.T||{features:this.getFeatures(),experiments:this.getExperiments()}}getDecryptedPayload(){return this.N||this.getPayload()}isRemoteEval(){return this.i.remoteEval||!1}getCacheKeyAttributes(){return this.i.cacheKeyAttributes}async U(t){var e;let{timeout:n,skipCache:i,allowStale:r,streaming:s}=t;if(!this.i.clientKey)throw new Error(\"Missing clientKey\");return async function(t){let{instance:e,timeout:n,skipCache:i,allowStale:r,backgroundSync:s}=t;return s||(it.backgroundSync=!1),async function(t){let{instance:e,allowStale:n,timeout:i,skipCache:r}=t;const s=yt(e),o=pt(e),u=new Date,c=new Date(u.getTime()-it.maxAge+it.staleTTL);await async function(){if(!ut){ut=!0;try{if(rt.localStorage){const t=await rt.localStorage.getItem(it.cacheKey);if(!it.disableCache&&t){const e=JSON.parse(t);e&&Array.isArray(e)&&e.forEach((t=>{let[e,n]=t;ct.set(e,{...n,staleAt:new Date(n.staleAt)})})),vt()}}}catch(t){}{const t=st.startIdleListener();t&&(st.stopIdleListener=t)}}}();const a=it.disableCache||r?void 0:ct.get(o);if(a&&(n||a.staleAt>u)&&a.staleAt>c)return a.sse&<.add(s),a.staleAt<u?gt(e):bt(e),{data:a.data,success:!0,source:\"cache\"};{const t=await function(t,e){return new Promise((n=>{let i,r=!1;const s=t=>{r||(r=!0,i&&clearTimeout(i),n(t||null))};e&&(i=setTimeout((()=>s()),e)),t.then((t=>s(t))).catch((()=>s()))}))}(gt(e),i);return t||{data:null,success:!1,source:\"timeout\",error:new Error(\"Timeout\")}}}({instance:e,allowStale:r,timeout:n,skipCache:i})}({instance:this,timeout:n,skipCache:i||this.i.disableCache,allowStale:r,backgroundSync:null===(e=null!=s?s:this.i.backgroundSync)||void 0===e||e})}M(){if(this.o)try{this.o()}catch(t){console.error(\"Failed to render\",t)}}setFeatures(t){this.i.features=t,this.ready=!0,this.M()}async setEncryptedFeatures(t,e,n){const i=await K(t,e||this.i.decryptionKey,n);this.setFeatures(JSON.parse(i))}setExperiments(t){this.i.experiments=t,this.ready=!0,this.B()}async setEncryptedExperiments(t,e,n){const i=await K(t,e||this.i.decryptionKey,n);this.setExperiments(JSON.parse(i))}async decryptPayload(t,e,n){return(t={...t}).encryptedFeatures&&(t.features=JSON.parse(await K(t.encryptedFeatures,e||this.i.decryptionKey,n)),delete t.encryptedFeatures),t.encryptedExperiments&&(t.experiments=JSON.parse(await K(t.encryptedExperiments,e||this.i.decryptionKey,n)),delete t.encryptedExperiments),t}async setAttributes(t){this.i.attributes=t,this.i.stickyBucketService&&await this.refreshStickyBuckets(),this.i.remoteEval?await this.I():(this.M(),this.B())}async updateAttributes(t){return this.setAttributes({...this.i.attributes,...t})}async setAttributeOverrides(t){this.S=t,this.i.stickyBucketService&&await this.refreshStickyBuckets(),this.i.remoteEval?await this.I():(this.M(),this.B())}async setForcedVariations(t){this.i.forcedVariations=t||{},this.i.remoteEval?await this.I():(this.M(),this.B())}setForcedFeatures(t){this.k=t,this.M()}async setURL(t){if(this.i.url=t,this.O=\"\",this.i.remoteEval)return await this.I(),void this.B(!0);this.B(!0)}getAttributes(){return{...this.i.attributes,...this.S}}getForcedVariations(){return this.i.forcedVariations||{}}getForcedFeatures(){return this.k||new Map}getStickyBucketAssignmentDocs(){return this.i.stickyBucketAssignmentDocs||{}}getUrl(){return this.i.url||\"\"}getFeatures(){return this.i.features||{}}getExperiments(){return this.i.experiments||[]}getCompletedChangeIds(){return Array.from(this.h)}subscribe(t){return this.p.add(t),()=>{this.p.delete(t)}}V(){var t;return(null===(t=this.i.backgroundSync)||void 0===t||t)&&this.i.subscribeToChanges}async I(){if(!this.i.remoteEval)return;if(!this.C)return;const t=await this.U({allowStale:!1});t.data&&await this.setPayload(t.data)}getAllResults(){return new Map(this.g)}destroy(){var t;this.p.clear(),this.g.clear(),this.u.clear(),this.h.clear(),this.$.clear(),this.l={},this.v=[],this.T=void 0,this.m&&clearTimeout(this.m),t=this,ot.forEach((e=>e.delete(t))),et&&window._growthbook===this&&delete window._growthbook,this.A.forEach((t=>{t.undo()})),this.A.clear(),this._.clear()}setRenderer(t){this.o=t}forceVariation(t,e){this.i.forcedVariations=this.i.forcedVariations||{},this.i.forcedVariations[t]=e,this.i.remoteEval?this.I():(this.B(),this.M())}run(t){const e=this.D(t,null);return this.J(t,e),e}triggerExperiment(t){return this._.add(t),this.i.experiments?this.i.experiments.filter((e=>e.key===t)).map((t=>this.j(t))).filter((t=>null!==t)):null}triggerAutoExperiments(){this.R=!0,this.B(!0)}j(t,e){const n=this.A.get(t);if(t.manual&&!this._.has(t.key)&&!n)return null;const i=this.K(t)?this.L(t,-1,!1,\"\"):this.run(t),r=JSON.stringify(i.value);if(!e&&i.inExperiment&&n&&n.valueHash===r)return i;if(n&&this.H(t),i.inExperiment){const e=P(t);if(\"redirect\"===e&&i.value.urlRedirect&&t.urlPatterns){const e=t.persistQueryString?function(t,e){let n,i;try{n=new URL(t),i=new URL(e)}catch(t){return console.error(\"Unable to merge query strings: \".concat(t)),e}return n.searchParams.forEach(((t,e)=>{i.searchParams.has(e)||i.searchParams.set(e,t)})),i.toString()}(this.q(),i.value.urlRedirect):i.value.urlRedirect;if(D(e,t.urlPatterns))return this.log(\"Skipping redirect because original URL matches redirect URL\",{id:t.key}),i;this.O=e;const n=this.P();var s;if(n)if(et)this.F(),window.setTimeout((()=>{try{n(e)}catch(t){console.error(t)}}),null!==(s=this.i.navigateDelay)&&void 0!==s?s:100);else try{n(e)}catch(t){console.error(t)}}else if(\"visual\"===e){const e=this.i.applyDomChangesCallback?this.i.applyDomChangesCallback(i.value):this.G(i.value);e&&this.A.set(t,{undo:e,valueHash:r})}}return i}H(t){const e=this.A.get(t);e&&(e.undo(),this.A.delete(t))}B(t){if(!this.R)return;const e=this.i.experiments||[],n=new Set(e);this.A.forEach(((t,e)=>{n.has(e)||(t.undo(),this.A.delete(e))}));for(const n of e){const e=this.j(n,t);if(null!=e&&e.inExperiment&&\"redirect\"===P(n))break}}J(t,e){const n=t.key,i=this.g.get(n);i&&i.result.inExperiment===e.inExperiment&&i.result.variationId===e.variationId||(this.g.set(n,{experiment:t,result:e}),this.p.forEach((n=>{try{n(t,e)}catch(t){console.error(t)}})))}Z(t,e){if(\"override\"===e.source)return;const n=JSON.stringify(e.value);if(this.l[t]!==n){if(this.l[t]=n,this.i.onFeatureUsage)try{this.i.onFeatureUsage(t,e)}catch(t){}et&&window.fetch&&(this.v.push({key:t,on:e.on}),this.m||(this.m=window.setTimeout((()=>{this.m=0;const t=[...this.v];this.v=[],this.i.realtimeKey&&window.fetch(\"https://rt.growthbook.io/?key=\".concat(this.i.realtimeKey,\"&events=\").concat(encodeURIComponent(JSON.stringify(t))),{cache:\"no-cache\",mode:\"no-cors\"}).catch((()=>{}))}),this.i.realtimeInterval||2e3)))}}W(t,e,n,i,r,s){const o={value:e,on:!!e,off:!e,source:n,ruleId:i||\"\"};return r&&(o.experiment=r),s&&(o.experimentResult=s),this.Z(t,o),o}isOn(t){return this.evalFeature(t).on}isOff(t){return this.evalFeature(t).off}getFeatureValue(t,e){const n=this.evalFeature(t).value;return null===n?e:n}feature(t){return this.evalFeature(t)}evalFeature(t){return this.X(t)}X(t,e){if((e=e||{evaluatedFeatures:new Set}).evaluatedFeatures.has(t))return this.W(t,null,\"cyclicPrerequisite\");if(e.evaluatedFeatures.add(t),e.id=t,this.k.has(t))return this.W(t,this.k.get(t),\"override\");if(!this.i.features||!this.i.features[t])return this.W(t,null,\"unknownFeature\");const n=this.i.features[t];if(n.rules)t:for(const i of n.rules){if(i.parentConditions)for(const n of i.parentConditions){const i=this.X(n.id,e);if(\"cyclicPrerequisite\"===i.source)return this.W(t,null,\"cyclicPrerequisite\");if(!G({value:i.value},n.condition||{})){if(n.gate)return this.W(t,null,\"prerequisite\");continue t}}if(i.filters&&this.Y(i.filters))continue;if(\"force\"in i){if(i.condition&&!this.tt(i.condition))continue;if(!this.et(i.seed||t,i.hashAttribute,this.i.stickyBucketService&&!i.disableStickyBucketing?i.fallbackAttribute:void 0,i.range,i.coverage,i.hashVersion))continue;return i.tracks&&i.tracks.forEach((t=>{this.nt(t.experiment,t.result)})),this.W(t,i.force,\"force\",i.id)}if(!i.variations)continue;const n={variations:i.variations,key:i.key||t};\"coverage\"in i&&(n.coverage=i.coverage),i.weights&&(n.weights=i.weights),i.hashAttribute&&(n.hashAttribute=i.hashAttribute),i.fallbackAttribute&&(n.fallbackAttribute=i.fallbackAttribute),i.disableStickyBucketing&&(n.disableStickyBucketing=i.disableStickyBucketing),void 0!==i.bucketVersion&&(n.bucketVersion=i.bucketVersion),void 0!==i.minBucketVersion&&(n.minBucketVersion=i.minBucketVersion),i.namespace&&(n.namespace=i.namespace),i.meta&&(n.meta=i.meta),i.ranges&&(n.ranges=i.ranges),i.name&&(n.name=i.name),i.phase&&(n.phase=i.phase),i.seed&&(n.seed=i.seed),i.hashVersion&&(n.hashVersion=i.hashVersion),i.filters&&(n.filters=i.filters),i.condition&&(n.condition=i.condition);const r=this.D(n,t);if(this.J(n,r),r.inExperiment&&!r.passthrough)return this.W(t,r.value,\"experiment\",i.id,n,r)}return this.W(t,void 0===n.defaultValue?null:n.defaultValue,\"defaultValue\")}et(t,e,n,i,r,s){if(!i&&void 0===r)return!0;if(!i&&0===r)return!1;const{hashValue:o}=this.it(e,n);if(!o)return!1;const u=U(t,o,s||1);return null!==u&&(i?V(u,i):void 0===r||u<=r)}tt(t){return G(this.getAttributes(),t)}Y(t){return t.some((t=>{const{hashValue:e}=this.it(t.attribute);if(!e)return!0;const n=U(t.seed,e,t.hashVersion||2);return null===n||!t.ranges.some((t=>V(n,t)))}))}D(t,e){const n=t.key,i=t.variations.length;if(i<2)return this.L(t,-1,!1,e);if(!1===this.i.enabled)return this.L(t,-1,!1,e);if((t=this.rt(t)).urlPatterns&&!D(this.q(),t.urlPatterns))return this.L(t,-1,!1,e);const r=function(t,e,n){if(!e)return null;const i=e.split(\"?\")[1];if(!i)return null;const r=i.replace(/#.*/,\"\").split(\"&\").map((t=>t.split(\"=\",2))).filter((e=>{let[n]=e;return n===t})).map((t=>{let[,e]=t;return parseInt(e)}));return r.length>0&&r[0]>=0&&r[0]<n?r[0]:null}(n,this.q(),i);if(null!==r)return this.L(t,r,!1,e);if(this.i.forcedVariations&&n in this.i.forcedVariations)return this.L(t,this.i.forcedVariations[n],!1,e);if(\"draft\"===t.status||!1===t.active)return this.L(t,-1,!1,e);const{hashAttribute:s,hashValue:o}=this.it(t.hashAttribute,this.i.stickyBucketService&&!t.disableStickyBucketing?t.fallbackAttribute:void 0);if(!o)return this.L(t,-1,!1,e);let u=-1,c=!1,a=!1;if(this.i.stickyBucketService&&!t.disableStickyBucketing){const{variation:e,versionIsBlocked:n}=this.st({expKey:t.key,expBucketVersion:t.bucketVersion,expHashAttribute:t.hashAttribute,expFallbackAttribute:t.fallbackAttribute,expMinBucketVersion:t.minBucketVersion,expMeta:t.meta});c=e>=0,u=e,a=!!n}if(!c){if(t.filters){if(this.Y(t.filters))return this.L(t,-1,!1,e)}else if(t.namespace&&!function(t,e){const n=U(\"__\"+e[0],t,1);return null!==n&&n>=e[1]&&n<e[2]}(o,t.namespace))return this.L(t,-1,!1,e);if(t.include&&!function(t){try{return t()}catch(t){return console.error(t),!1}}(t.include))return this.L(t,-1,!1,e);if(t.condition&&!this.tt(t.condition))return this.L(t,-1,!1,e);if(t.parentConditions)for(const n of t.parentConditions){const i=this.X(n.id);if(\"cyclicPrerequisite\"===i.source)return this.L(t,-1,!1,e);if(!G({value:i.value},n.condition||{}))return this.L(t,-1,!1,e)}if(t.groups&&!this.ot(t.groups))return this.L(t,-1,!1,e)}if(t.url&&!this.ut(t.url))return this.L(t,-1,!1,e);const h=U(t.seed||n,o,t.hashVersion||1);if(null===h)return this.L(t,-1,!1,e);if(c||(u=function(t,e){for(let n=0;n<e.length;n++)if(V(t,e[n]))return n;return-1}(h,t.ranges||function(t,e,n){(e=void 0===e?1:e)<0?e=0:e>1&&(e=1);const i=(r=t)<=0?[]:new Array(r).fill(1/r);var r;(n=n||i).length!==t&&(n=i);const s=n.reduce(((t,e)=>e+t),0);(s<.99||s>1.01)&&(n=i);let o=0;return n.map((t=>{const n=o;return o+=t,[n,n+e*t]}))}(i,void 0===t.coverage?1:t.coverage,t.weights))),a)return this.L(t,-1,!1,e,void 0,!0);if(u<0)return this.L(t,-1,!1,e);if(\"force\"in t)return this.L(t,void 0===t.force?-1:t.force,!1,e);if(this.i.qaMode)return this.L(t,-1,!1,e);if(\"stopped\"===t.status)return this.L(t,-1,!1,e);const l=this.L(t,u,!0,e,h,c);if(this.i.stickyBucketService&&!t.disableStickyBucketing){const{changed:e,key:n,doc:i}=this.ct(s,L(o),{[this.ht(t.key,t.bucketVersion)]:l.key});e&&(this.i.stickyBucketAssignmentDocs=this.i.stickyBucketAssignmentDocs||{},this.i.stickyBucketAssignmentDocs[n]=i,this.i.stickyBucketService.saveAssignments(i))}return this.nt(t,l),\"changeId\"in t&&t.changeId&&this.h.add(t.changeId),l}log(t,e){this.debug&&(this.i.log?this.i.log(t,e):console.log(t,e))}getDeferredTrackingCalls(){return Array.from(this.$.values())}setDeferredTrackingCalls(t){this.$=new Map(t.filter((t=>t&&t.experiment&&t.result)).map((t=>[this.lt(t.experiment,t.result),t])))}fireDeferredTrackingCalls(){this.i.trackingCallback&&(this.$.forEach((t=>{t&&t.experiment&&t.result?this.nt(t.experiment,t.result):console.error(\"Invalid deferred tracking call\",{call:t})})),this.$.clear())}setTrackingCallback(t){this.i.trackingCallback=t,this.fireDeferredTrackingCalls()}lt(t,e){return e.hashAttribute+e.hashValue+t.key+e.variationId}nt(t,e){const n=this.lt(t,e);if(this.i.trackingCallback){if(!this.u.has(n)){this.u.add(n);try{this.i.trackingCallback(t,e)}catch(t){console.error(t)}}}else this.$.has(n)||this.$.set(n,{experiment:t,result:e})}rt(t){const e=t.key,n=this.i.overrides;return n&&n[e]&&\"string\"==typeof(t=Object.assign({},t,n[e])).url&&(t.url=I(t.url)),t}it(t,e){let n=t||\"id\",i=\"\";return this.S[n]?i=this.S[n]:this.i.attributes?i=this.i.attributes[n]||\"\":this.i.user&&(i=this.i.user[n]||\"\"),!i&&e&&(this.S[e]?i=this.S[e]:this.i.attributes?i=this.i.attributes[e]||\"\":this.i.user&&(i=this.i.user[e]||\"\"),i&&(n=e)),{hashAttribute:n,hashValue:i}}L(t,e,n,i,r,s){let o=!0;(e<0||e>=t.variations.length)&&(e=0,o=!1);const{hashAttribute:u,hashValue:c}=this.it(t.hashAttribute,this.i.stickyBucketService&&!t.disableStickyBucketing?t.fallbackAttribute:void 0),a=t.meta?t.meta[e]:{},h={key:a.key||\"\"+e,featureId:i,inExperiment:o,hashUsed:n,variationId:e,value:t.variations[e],hashAttribute:u,hashValue:c,stickyBucketUsed:!!s};return a.name&&(h.name=a.name),void 0!==r&&(h.bucket=r),a.passthrough&&(h.passthrough=a.passthrough),h}q(){return this.i.url||(et?window.location.href:\"\")}ut(t){const e=this.q();if(!e)return!1;const n=e.replace(/^https?:\\/\\//,\"\").replace(/^[^/]*\\//,\"/\");return!!t.test(e)||!!t.test(n)}ot(t){const e=this.i.groups||{};for(let n=0;n<t.length;n++)if(e[t[n]])return!0;return!1}K(t){const e=P(t);if(\"visual\"===e){if(this.i.disableVisualExperiments)return!0;if(this.i.disableJsInjection&&t.variations.some((t=>t.js)))return!0}else{if(\"redirect\"!==e)return!0;if(this.i.disableUrlRedirectExperiments)return!0;try{const e=new URL(this.q());for(const n of t.variations){if(!n||!n.urlRedirect)continue;const t=new URL(n.urlRedirect);if(this.i.disableCrossOriginUrlRedirectExperiments){if(t.protocol!==e.protocol)return!0;if(t.host!==e.host)return!0}}}catch(e){return this.log(\"Error parsing current or redirect URL\",{id:t.key,error:e}),!0}}return!(!t.changeId||!(this.i.blockedChangeIds||[]).includes(t.changeId))}getRedirectUrl(){return this.O}P(){return this.i.navigate?this.i.navigate:et?t=>{window.location.replace(t)}:null}F(){if(this.i.antiFlicker&&et)try{var t;const e=document.createElement(\"style\");e.innerHTML=\".gb-anti-flicker { opacity: 0 !important; pointer-events: none; }\",document.head.appendChild(e),document.documentElement.classList.add(\"gb-anti-flicker\"),setTimeout((()=>{document.documentElement.classList.remove(\"gb-anti-flicker\")}),null!==(t=this.i.antiFlickerTimeout)&&void 0!==t?t:3500)}catch(t){console.error(t)}}G(t){if(!et)return;const e=[];if(t.css){const n=document.createElement(\"style\");n.innerHTML=t.css,document.head.appendChild(n),e.push((()=>n.remove()))}if(t.js){const n=document.createElement(\"script\");n.innerHTML=t.js,this.i.jsInjectionNonce&&(n.nonce=this.i.jsInjectionNonce),document.head.appendChild(n),e.push((()=>n.remove()))}return t.domMutations&&t.domMutations.forEach((t=>{e.push(function(t){var e=t.selector,n=t.action,r=t.value,s=t.attribute,o=t.parentSelector,u=t.insertBeforeSelector;if(\"html\"===s){if(\"append\"===n)return B(e,(function(t){return t+(null!=r?r:\"\")}));if(\"set\"===n)return B(e,(function(){return null!=r?r:\"\"}))}else if(\"class\"===s){if(\"append\"===n)return F(e,(function(t){r&&t.add(r)}));if(\"remove\"===n)return F(e,(function(t){r&&t.delete(r)}));if(\"set\"===n)return F(e,(function(t){t.clear(),r&&t.add(r)}))}else if(\"position\"===s){if(\"set\"===n&&o)return function(t,e){return R({kind:\"position\",elements:new Set,mutate:function(){return{insertBeforeSelector:u,parentSelector:o}},selector:t})}(e)}else{if(\"append\"===n)return T(e,s,(function(t){return null!==t?t+(null!=r?r:\"\"):null!=r?r:\"\"}));if(\"set\"===n)return T(e,s,(function(){return null!=r?r:\"\"}));if(\"remove\"===n)return T(e,s,(function(){return null}))}return i}(t).revert)})),()=>{e.forEach((t=>t()))}}ft(t){const e=new Set,n=t&&t.features?t.features:this.getFeatures(),i=t&&t.experiments?t.experiments:this.getExperiments();return Object.keys(n).forEach((t=>{const i=n[t];if(i.rules)for(const t of i.rules)t.variations&&(e.add(t.hashAttribute||\"id\"),t.fallbackAttribute&&e.add(t.fallbackAttribute))})),i.map((t=>{e.add(t.hashAttribute||\"id\"),t.fallbackAttribute&&e.add(t.fallbackAttribute)})),Array.from(e)}async refreshStickyBuckets(t){if(this.i.stickyBucketService){const e=this.dt(t);this.i.stickyBucketAssignmentDocs=await this.i.stickyBucketService.getAllAssignments(e)}}wt(t,e){if(!this.i.stickyBucketAssignmentDocs)return{};const{hashAttribute:n,hashValue:i}=this.it(t),r=\"\".concat(n,\"||\").concat(L(i)),{hashAttribute:s,hashValue:o}=this.it(e),u=o?\"\".concat(s,\"||\").concat(L(o)):null,c={};return u&&this.i.stickyBucketAssignmentDocs[u]&&Object.assign(c,this.i.stickyBucketAssignmentDocs[u].assignments||{}),this.i.stickyBucketAssignmentDocs[r]&&Object.assign(c,this.i.stickyBucketAssignmentDocs[r].assignments||{}),c}st(t){let{expKey:e,expBucketVersion:n,expHashAttribute:i,expFallbackAttribute:r,expMinBucketVersion:s,expMeta:o}=t;n=n||0,s=s||0,i=i||\"id\",o=o||[];const u=this.ht(e,n),c=this.wt(i,r);if(s>0)for(let t=0;t<=s;t++)if(void 0!==c[this.ht(e,t)])return{variation:-1,versionIsBlocked:!0};const a=c[u];if(void 0===a)return{variation:-1};const h=o.findIndex((t=>t.key===a));return h<0?{variation:-1}:{variation:h}}ht(t,e){return e=e||0,\"\".concat(t,\"__\").concat(e)}dt(t){const e={};return this.i.stickyBucketIdentifierAttributes=this.i.stickyBucketIdentifierAttributes?this.i.stickyBucketIdentifierAttributes:this.ft(t),this.i.stickyBucketIdentifierAttributes.forEach((t=>{const{hashValue:n}=this.it(t);e[t]=L(n)})),e}ct(t,e,n){const i=\"\".concat(t,\"||\").concat(e),r=this.i.stickyBucketAssignmentDocs&&this.i.stickyBucketAssignmentDocs[i]&&this.i.stickyBucketAssignmentDocs[i].assignments||{},s={...r,...n};return{key:i,doc:{attributeName:t,attributeValue:e,assignments:s},changed:JSON.stringify(r)!==JSON.stringify(s)}}}({...Et,remoteEval:!!Et.remoteEval,trackingCallback:(t,e)=>{const n={experiment_id:t.key,variation_id:e.key};window.gtag&&window.gtag(\"event\",\"experiment_viewed\",n),window.dataLayer&&window.dataLayer.push({event:\"experiment_viewed\",...n}),window.analytics&&window.analytics.track&&window.analytics.track(\"Experiment Viewed\",n)},...Ct,attributes:Vt(),stickyBucketService:Ft});It.setRenderer((()=>{document.dispatchEvent(new CustomEvent(\"growthbookdata\"))})),It.init({payload:Ct.payload,streaming:!(Ct.noStreaming||Et.noStreaming||!1===Ct.backgroundSync)});let Dt=location.href;setInterval((()=>{location.href!==Dt&&(Dt=location.href,It.setURL(Dt),It.updateAttributes(Vt()))}),500),document.addEventListener(\"growthbookrefresh\",(()=>{location.href!==Dt&&(Dt=location.href,It.setURL(Dt)),It.updateAttributes(Vt())})),document.addEventListener(\"growthbookpersist\",(()=>{Nt()}));const Jt=t=>{try{t&&t(It)}catch(t){console.error(\"Uncaught growthbook_queue error\",t)}};return window.growthbook_queue&&Array.isArray(window.growthbook_queue)&&window.growthbook_queue.forEach((t=>{Jt(t)})),window.growthbook_queue={push:t=>{Jt(t)}},It}();\n//# sourceMappingURL=auto.min.js.map\n";
|
|
5
|
+
//# sourceMappingURL=sdkWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkWrapper.js","sourceRoot":"","sources":["../../src/generated/sdkWrapper.ts"],"names":[],"mappings":";;;AACa,QAAA,UAAU,GAAG,uj0CAAuj0C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Context, Config, Helpers, ExperimentRunEnvironment, Route, } from "./types";
|
|
2
|
+
export { ConfigEnv, defaultContext, getConfig } from "./config";
|
|
3
|
+
export { edgeApp, getOriginUrl } from "./app";
|
|
4
|
+
export { getUserAttributes, getUUID, getAutoAttributes } from "./attributes";
|
|
5
|
+
export { applyDomMutations } from "./domMutations";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyDomMutations = exports.getAutoAttributes = exports.getUUID = exports.getUserAttributes = exports.getOriginUrl = exports.edgeApp = exports.getConfig = exports.defaultContext = void 0;
|
|
4
|
+
var config_1 = require("./config");
|
|
5
|
+
Object.defineProperty(exports, "defaultContext", { enumerable: true, get: function () { return config_1.defaultContext; } });
|
|
6
|
+
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
7
|
+
var app_1 = require("./app");
|
|
8
|
+
Object.defineProperty(exports, "edgeApp", { enumerable: true, get: function () { return app_1.edgeApp; } });
|
|
9
|
+
Object.defineProperty(exports, "getOriginUrl", { enumerable: true, get: function () { return app_1.getOriginUrl; } });
|
|
10
|
+
var attributes_1 = require("./attributes");
|
|
11
|
+
Object.defineProperty(exports, "getUserAttributes", { enumerable: true, get: function () { return attributes_1.getUserAttributes; } });
|
|
12
|
+
Object.defineProperty(exports, "getUUID", { enumerable: true, get: function () { return attributes_1.getUUID; } });
|
|
13
|
+
Object.defineProperty(exports, "getAutoAttributes", { enumerable: true, get: function () { return attributes_1.getAutoAttributes; } });
|
|
14
|
+
var domMutations_1 = require("./domMutations");
|
|
15
|
+
Object.defineProperty(exports, "applyDomMutations", { enumerable: true, get: function () { return domMutations_1.applyDomMutations; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAOA,mCAAgE;AAA5C,wGAAA,cAAc,OAAA;AAAE,mGAAA,SAAS,OAAA;AAE7C,6BAA8C;AAArC,8FAAA,OAAO,OAAA;AAAE,mGAAA,YAAY,OAAA;AAE9B,2CAA6E;AAApE,+GAAA,iBAAiB,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AACtD,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA"}
|
package/dist/inject.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Attributes, GrowthBook } from "@growthbook/growthbook";
|
|
2
|
+
import { Context } from "./types";
|
|
3
|
+
export declare function injectScript({ context, body, nonce, growthbook, attributes, preRedirectChangeIds, url, oldUrl, }: {
|
|
4
|
+
context: Context;
|
|
5
|
+
body: string;
|
|
6
|
+
nonce?: string;
|
|
7
|
+
growthbook: GrowthBook;
|
|
8
|
+
attributes: Attributes;
|
|
9
|
+
preRedirectChangeIds: string[];
|
|
10
|
+
url: string;
|
|
11
|
+
oldUrl: string;
|
|
12
|
+
}): string;
|
|
13
|
+
export declare function getCspInfo(context: Context): {
|
|
14
|
+
csp?: string;
|
|
15
|
+
nonce?: string;
|
|
16
|
+
};
|
package/dist/inject.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCspInfo = exports.injectScript = void 0;
|
|
4
|
+
const growthbook_1 = require("@growthbook/growthbook");
|
|
5
|
+
const sdkWrapper_1 = require("./generated/sdkWrapper");
|
|
6
|
+
function injectScript({ context, body, nonce, growthbook, attributes, preRedirectChangeIds, url, oldUrl, }) {
|
|
7
|
+
if (context.config.disableInjections)
|
|
8
|
+
return body;
|
|
9
|
+
const sdkPayload = growthbook.getPayload();
|
|
10
|
+
const experiments = growthbook.getExperiments();
|
|
11
|
+
const deferredTrackingCalls = growthbook.getDeferredTrackingCalls();
|
|
12
|
+
const completedChangeIds = growthbook.getCompletedChangeIds();
|
|
13
|
+
const uuidCookieName = context.config.uuidCookieName;
|
|
14
|
+
const uuidKey = context.config.uuidKey;
|
|
15
|
+
const uuid = attributes[uuidKey];
|
|
16
|
+
const trackingCallback = context.config.growthbook.trackingCallback;
|
|
17
|
+
const blockedChangeIds = getBlockedExperiments({
|
|
18
|
+
context,
|
|
19
|
+
experiments,
|
|
20
|
+
completedChangeIds,
|
|
21
|
+
preRedirectChangeIds,
|
|
22
|
+
});
|
|
23
|
+
const injectRedirectUrlScript = context.config.injectRedirectUrlScript;
|
|
24
|
+
const enableStreaming = context.config.enableStreaming;
|
|
25
|
+
const enableStickyBucketing = context.config.enableStickyBucketing;
|
|
26
|
+
const stickyAssignments = growthbook.getStickyBucketAssignmentDocs();
|
|
27
|
+
const gbContext = {
|
|
28
|
+
uuidCookieName,
|
|
29
|
+
uuidKey,
|
|
30
|
+
uuid,
|
|
31
|
+
persistUuidOnLoad: true,
|
|
32
|
+
attributes,
|
|
33
|
+
trackingCallback: "__TRACKING_CALLBACK__",
|
|
34
|
+
payload: sdkPayload,
|
|
35
|
+
disableVisualExperiments: ["skip", "edge"].includes(context.config.runVisualEditorExperiments),
|
|
36
|
+
disableJsInjection: context.config.disableJsInjection,
|
|
37
|
+
disableUrlRedirectExperiments: ["skip", "edge"].includes(context.config.runUrlRedirectExperiments),
|
|
38
|
+
disableCrossOriginUrlRedirectExperiments: ["skip", "edge"].includes(context.config.runCrossOriginUrlRedirectExperiments),
|
|
39
|
+
jsInjectionNonce: nonce,
|
|
40
|
+
blockedChangeIds,
|
|
41
|
+
noStreaming: !enableStreaming,
|
|
42
|
+
useStickyBucketService: enableStickyBucketing ? "cookie" : undefined,
|
|
43
|
+
stickyBucketPrefix: context.config.stickyBucketPrefix,
|
|
44
|
+
stickyBucketAssignmentDocs: stickyAssignments,
|
|
45
|
+
};
|
|
46
|
+
let scriptTag = `
|
|
47
|
+
<script
|
|
48
|
+
data-api-host="${context.config.growthbook.apiHost}"
|
|
49
|
+
data-client-key="${context.config.growthbook.clientKey}"${context.config.growthbook.decryptionKey
|
|
50
|
+
? `\n data-decryption-key="${context.config.growthbook.decryptionKey}"`
|
|
51
|
+
: ""}${nonce ? `\n nonce="${nonce}"` : ""}
|
|
52
|
+
>
|
|
53
|
+
window.growthbook_config = ${JSON.stringify(gbContext)};
|
|
54
|
+
${(deferredTrackingCalls === null || deferredTrackingCalls === void 0 ? void 0 : deferredTrackingCalls.length)
|
|
55
|
+
? `
|
|
56
|
+
window.growthbook_queue = [
|
|
57
|
+
(gb) => {
|
|
58
|
+
gb.setDeferredTrackingCalls(${JSON.stringify(scrubInvalidTrackingCalls(deferredTrackingCalls, preRedirectChangeIds))});
|
|
59
|
+
gb.fireDeferredTrackingCalls();
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
`
|
|
63
|
+
: ""}
|
|
64
|
+
${sdkWrapper_1.sdkWrapper}
|
|
65
|
+
${url !== oldUrl && injectRedirectUrlScript
|
|
66
|
+
? `window.history.replaceState(undefined, undefined, ${JSON.stringify(url)})`
|
|
67
|
+
: ""}
|
|
68
|
+
</script>
|
|
69
|
+
`;
|
|
70
|
+
scriptTag = scriptTag.replace(`"__TRACKING_CALLBACK__"`, trackingCallback || "undefined");
|
|
71
|
+
const index = body.indexOf(context.config.scriptInjectionPattern);
|
|
72
|
+
if (index >= 0) {
|
|
73
|
+
body = body.slice(0, index) + scriptTag + body.slice(index);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
body += scriptTag;
|
|
77
|
+
}
|
|
78
|
+
return body;
|
|
79
|
+
}
|
|
80
|
+
exports.injectScript = injectScript;
|
|
81
|
+
function getCspInfo(context) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
// get nonce from CSP
|
|
84
|
+
let csp = context.config.contentSecurityPolicy;
|
|
85
|
+
let nonce = undefined;
|
|
86
|
+
if (csp) {
|
|
87
|
+
if ((csp.indexOf("__NONCE__") || -1) >= 0 &&
|
|
88
|
+
((_b = (_a = context.config) === null || _a === void 0 ? void 0 : _a.crypto) === null || _b === void 0 ? void 0 : _b.getRandomValues)) {
|
|
89
|
+
// Generate nonce
|
|
90
|
+
nonce = btoa(context.config.crypto.getRandomValues(new Uint32Array(2)));
|
|
91
|
+
csp = csp === null || csp === void 0 ? void 0 : csp.replace(/__NONCE__/g, nonce);
|
|
92
|
+
}
|
|
93
|
+
else if ((_c = context.config) === null || _c === void 0 ? void 0 : _c.nonce) {
|
|
94
|
+
// Use passed-in nonce
|
|
95
|
+
nonce = context.config.nonce;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// todo: support reading csp from meta tag?
|
|
99
|
+
return { csp, nonce };
|
|
100
|
+
}
|
|
101
|
+
exports.getCspInfo = getCspInfo;
|
|
102
|
+
function getBlockedExperiments({ context, experiments, completedChangeIds, preRedirectChangeIds, }) {
|
|
103
|
+
const runUrlRedirectExperimentsEverywhere = context.config.runUrlRedirectExperiments === "everywhere";
|
|
104
|
+
const runVisualEditorExperimentsEverywhere = context.config.runVisualEditorExperiments === "everywhere";
|
|
105
|
+
const blockedChangeIds = [];
|
|
106
|
+
if (runUrlRedirectExperimentsEverywhere) {
|
|
107
|
+
blockedChangeIds.concat(...completedChangeIds.filter((changeId) => {
|
|
108
|
+
// only block hybrid redirect experiments if they've already been run on edge
|
|
109
|
+
const exp = experiments.find((exp) => (0, growthbook_1.getAutoExperimentChangeType)(exp) === "redirect" &&
|
|
110
|
+
exp.changeId === changeId);
|
|
111
|
+
return !!((exp === null || exp === void 0 ? void 0 : exp.changeId) && completedChangeIds.includes(exp.changeId));
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
if (runVisualEditorExperimentsEverywhere) {
|
|
115
|
+
blockedChangeIds.concat(...preRedirectChangeIds.filter((changeId) => {
|
|
116
|
+
// only block hybrid visual experiments if they've already been run on edge as part of the pre-redirect loop
|
|
117
|
+
const exp = experiments.find((exp) => (0, growthbook_1.getAutoExperimentChangeType)(exp) === "visual" &&
|
|
118
|
+
exp.changeId === changeId);
|
|
119
|
+
return !!((exp === null || exp === void 0 ? void 0 : exp.changeId) && completedChangeIds.includes(exp.changeId));
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
return blockedChangeIds.length ? blockedChangeIds : undefined;
|
|
123
|
+
}
|
|
124
|
+
function scrubInvalidTrackingCalls(deferredTrackingCalls, preRedirectChangeIds) {
|
|
125
|
+
return deferredTrackingCalls.filter((data) => {
|
|
126
|
+
const exp = data.experiment;
|
|
127
|
+
// remove tracking for any visual experiments that ran during the redirect loop
|
|
128
|
+
if ((0, growthbook_1.getAutoExperimentChangeType)(exp) === "visual" &&
|
|
129
|
+
exp.changeId &&
|
|
130
|
+
preRedirectChangeIds.includes(exp.changeId)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GrowthBook } from "@growthbook/growthbook";
|
|
2
|
+
import { Context } from "./types";
|
|
3
|
+
export default function redirect({ context, req, setCookie, growthbook, previousUrl, resetDomChanges, setPreRedirectChangeIds, }: {
|
|
4
|
+
context: Context;
|
|
5
|
+
req: unknown;
|
|
6
|
+
setCookie: (key: string, value: string) => void;
|
|
7
|
+
growthbook: GrowthBook;
|
|
8
|
+
previousUrl: string;
|
|
9
|
+
resetDomChanges: () => void;
|
|
10
|
+
setPreRedirectChangeIds: (changeIds: string[]) => void;
|
|
11
|
+
}): Promise<string>;
|
package/dist/redirect.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const attributes_1 = require("./attributes");
|
|
13
|
+
function redirect({ context, req, setCookie, growthbook, previousUrl, resetDomChanges, setPreRedirectChangeIds, }) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const disableUrlRedirectExperiments = ["skip", "browser"].includes(context.config.runUrlRedirectExperiments);
|
|
16
|
+
if (disableUrlRedirectExperiments)
|
|
17
|
+
return previousUrl;
|
|
18
|
+
const maxRedirects = context.config.maxRedirects || 5;
|
|
19
|
+
let redirectCount = 0;
|
|
20
|
+
let newUrl = growthbook.getRedirectUrl();
|
|
21
|
+
// no redirect
|
|
22
|
+
if (!newUrl)
|
|
23
|
+
return previousUrl;
|
|
24
|
+
while (previousUrl != newUrl) {
|
|
25
|
+
newUrl = previousUrl;
|
|
26
|
+
if (redirectCount >= maxRedirects)
|
|
27
|
+
return previousUrl;
|
|
28
|
+
// clear visual experiment effects since we're no longer on the same page
|
|
29
|
+
resetDomChanges();
|
|
30
|
+
// keep track of experiments that triggered prior to final redirect
|
|
31
|
+
setPreRedirectChangeIds(growthbook.getCompletedChangeIds());
|
|
32
|
+
// change the URL to trigger the experiment
|
|
33
|
+
yield growthbook.setAttributes((0, attributes_1.getUserAttributes)(context, req, newUrl, setCookie));
|
|
34
|
+
yield growthbook.setURL(newUrl);
|
|
35
|
+
previousUrl = newUrl;
|
|
36
|
+
newUrl = growthbook.getRedirectUrl();
|
|
37
|
+
redirectCount++;
|
|
38
|
+
}
|
|
39
|
+
return newUrl;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.default = redirect;
|
|
43
|
+
//# sourceMappingURL=redirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,6CAAiD;AAEjD,SAA8B,QAAQ,CAAC,EACrC,OAAO,EACP,GAAG,EACH,SAAS,EACT,UAAU,EACV,WAAW,EACX,eAAe,EACf,uBAAuB,GASxB;;QACC,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,QAAQ,CAChE,OAAO,CAAC,MAAM,CAAC,yBAAyB,CACzC,CAAC;QACF,IAAI,6BAA6B;YAAE,OAAO,WAAW,CAAC;QAEtD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC;QACtD,IAAI,aAAa,GAAG,CAAC,CAAC;QAEtB,IAAI,MAAM,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;QACzC,cAAc;QACd,IAAI,CAAC,MAAM;YAAE,OAAO,WAAW,CAAC;QAEhC,OAAO,WAAW,IAAI,MAAM,EAAE;YAC5B,MAAM,GAAG,WAAW,CAAC;YACrB,IAAI,aAAa,IAAI,YAAY;gBAAE,OAAO,WAAW,CAAC;YAEtD,yEAAyE;YACzE,eAAe,EAAE,CAAC;YAClB,mEAAmE;YACnE,uBAAuB,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC,CAAC;YAE5D,2CAA2C;YAC3C,MAAM,UAAU,CAAC,aAAa,CAC5B,IAAA,8BAAiB,EAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,CACnD,CAAC;YACF,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,WAAW,GAAG,MAAM,CAAC;YACrB,MAAM,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;YACrC,aAAa,EAAE,CAAC;SACjB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AAhDD,2BAgDC"}
|
package/dist/routing.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRoute = void 0;
|
|
4
|
+
const growthbook_1 = require("@growthbook/growthbook");
|
|
5
|
+
function getRoute(context, url) {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
const routes = context.config.routes || [];
|
|
8
|
+
for (const route of routes) {
|
|
9
|
+
route.type = (_a = route.type) !== null && _a !== void 0 ? _a : "simple";
|
|
10
|
+
route.behavior = (_b = route.behavior) !== null && _b !== void 0 ? _b : "intercept";
|
|
11
|
+
route.includeFileExtensions = !!route.includeFileExtensions;
|
|
12
|
+
if (route.behavior === "error") {
|
|
13
|
+
route.statusCode = (_c = route.statusCode) !== null && _c !== void 0 ? _c : 404;
|
|
14
|
+
}
|
|
15
|
+
const target = {
|
|
16
|
+
include: true,
|
|
17
|
+
type: (_d = route.type) !== null && _d !== void 0 ? _d : "simple",
|
|
18
|
+
pattern: route.pattern,
|
|
19
|
+
};
|
|
20
|
+
const targeted = (0, growthbook_1.isURLTargeted)(url, [target]);
|
|
21
|
+
if (targeted) {
|
|
22
|
+
if (route.includeFileExtensions) {
|
|
23
|
+
return route;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const urlObj = new URL(url);
|
|
27
|
+
const path = urlObj.pathname;
|
|
28
|
+
if (path.includes(".")) {
|
|
29
|
+
// extensions will proxy if not explicitly included
|
|
30
|
+
return Object.assign(Object.assign({}, route), { behavior: "proxy" });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// ignore
|
|
35
|
+
}
|
|
36
|
+
return route;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Default route is intercept & process
|
|
40
|
+
return {
|
|
41
|
+
pattern: "*",
|
|
42
|
+
type: "simple",
|
|
43
|
+
behavior: "intercept",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.getRoute = getRoute;
|
|
47
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AAGvD,SAAgB,QAAQ,CAAC,OAAgB,EAAE,GAAW;;IACpD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,KAAK,CAAC,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,mCAAI,QAAQ,CAAC;QACpC,KAAK,CAAC,QAAQ,GAAG,MAAA,KAAK,CAAC,QAAQ,mCAAI,WAAW,CAAC;QAC/C,KAAK,CAAC,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;QAC5D,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE;YAC9B,KAAK,CAAC,UAAU,GAAG,MAAA,KAAK,CAAC,UAAU,mCAAI,GAAG,CAAC;SAC5C;QAED,MAAM,MAAM,GAAG;YACb,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,MAAA,KAAK,CAAC,IAAI,mCAAI,QAAQ;YAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC;QACF,MAAM,QAAQ,GAAG,IAAA,0BAAa,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAE9C,IAAI,QAAQ,EAAE;YACZ,IAAI,KAAK,CAAC,qBAAqB,EAAE;gBAC/B,OAAO,KAAK,CAAC;aACd;YACD,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;gBAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC;gBAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBACtB,mDAAmD;oBACnD,uCAAY,KAAK,KAAE,QAAQ,EAAE,OAAO,IAAG;iBACxC;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,SAAS;aACV;YACD,OAAO,KAAK,CAAC;SACd;KACF;IACD,uCAAuC;IACvC,OAAO;QACL,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,WAAW;KACtB,CAAC;AACJ,CAAC;AAxCD,4BAwCC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StickyAssignmentsDocument, StickyBucketService } from "@growthbook/growthbook";
|
|
2
|
+
import { Context } from "./types";
|
|
3
|
+
export declare class EdgeStickyBucketService<Req, Res> extends StickyBucketService {
|
|
4
|
+
private context;
|
|
5
|
+
private prefix;
|
|
6
|
+
private req;
|
|
7
|
+
constructor({ context, prefix, req, }: {
|
|
8
|
+
context: Context<Req, Res>;
|
|
9
|
+
prefix?: string;
|
|
10
|
+
req: Req;
|
|
11
|
+
});
|
|
12
|
+
getAssignments(attributeName: string, attributeValue: string): Promise<StickyAssignmentsDocument | null>;
|
|
13
|
+
saveAssignments(_: StickyAssignmentsDocument): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EdgeStickyBucketService = void 0;
|
|
13
|
+
const growthbook_1 = require("@growthbook/growthbook");
|
|
14
|
+
class EdgeStickyBucketService extends growthbook_1.StickyBucketService {
|
|
15
|
+
constructor({ context, prefix = "gbStickyBuckets__", req, }) {
|
|
16
|
+
super();
|
|
17
|
+
this.context = context;
|
|
18
|
+
this.prefix = prefix;
|
|
19
|
+
this.req = req;
|
|
20
|
+
}
|
|
21
|
+
getAssignments(attributeName, attributeValue) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const key = `${attributeName}||${attributeValue}`;
|
|
25
|
+
let doc = null;
|
|
26
|
+
if (!this.req)
|
|
27
|
+
return doc;
|
|
28
|
+
try {
|
|
29
|
+
// const raw = this.req.cookies[this.prefix + key] || "{}";
|
|
30
|
+
const raw = ((_b = (_a = this.context.helpers) === null || _a === void 0 ? void 0 : _a.getCookie) === null || _b === void 0 ? void 0 : _b.call(_a, this.req, this.prefix + key)) || "{}";
|
|
31
|
+
const data = JSON.parse(raw);
|
|
32
|
+
if (data.attributeName && data.attributeValue && data.assignments) {
|
|
33
|
+
doc = data;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
// Ignore cookie errors
|
|
38
|
+
}
|
|
39
|
+
return doc;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
saveAssignments(_) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
// Do nothing. User assignments will be hydrated from the SDK directly.
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.EdgeStickyBucketService = EdgeStickyBucketService;
|
|
49
|
+
//# sourceMappingURL=stickyBucketService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stickyBucketService.js","sourceRoot":"","sources":["../src/stickyBucketService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAGgC;AAGhC,MAAa,uBAAkC,SAAQ,gCAAmB;IAKxE,YAAY,EACV,OAAO,EACP,MAAM,GAAG,mBAAmB,EAC5B,GAAG,GAKJ;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAEK,cAAc,CAAC,aAAqB,EAAE,cAAsB;;;YAChE,MAAM,GAAG,GAAG,GAAG,aAAa,KAAK,cAAc,EAAE,CAAC;YAClD,IAAI,GAAG,GAAqC,IAAI,CAAC;YACjD,IAAI,CAAC,IAAI,CAAC,GAAG;gBAAE,OAAO,GAAG,CAAC;YAC1B,IAAI;gBACF,2DAA2D;gBAC3D,MAAM,GAAG,GACP,CAAA,MAAA,MAAA,IAAI,CAAC,OAAO,CAAC,OAAO,0CAAE,SAAS,mDAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAI,IAAI,CAAC;gBACzE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC7B,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,EAAE;oBACjE,GAAG,GAAG,IAAI,CAAC;iBACZ;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,uBAAuB;aACxB;YACD,OAAO,GAAG,CAAC;;KACZ;IAEK,eAAe,CAAC,CAA4B;;YAChD,uEAAuE;QACzE,CAAC;KAAA;CACF;AAzCD,0DAyCC"}
|