This commit is contained in:
zbatte committed 2026-07-02 15:54:39 -06:00
commit 9883323161
17470 files changed
+4470592

No files matched your search

@@ -0,0 +1,25 @@
/**
* Gather w.js anonymous cookie, tk_ai
*
* @return {?string} The anonymous cookie value, or null if it doesn't exist
*/
export declare const readAnonCookie: () => string | null;
/**
* Initializes the anonId:
* - Polls for AnonId receival
* - Should only be called once at startup
* - Happens to be safe to call multiple times if it is necessary to reset the anonId - something like this was necessary for testing.
*
* This purely for boot-time initialization, in usual circumstances it will be retrieved within 100-300ms, it happens in parallel booting
* so should only delay experiment loading that much for boot-time experiments. In some circumstances such as a very slow connection this
* can take a lot longer.
*
* The state of initializeAnonIdPromise should be used rather than the return of this function.
* The return is only avaliable to make this easier to test.
*
* Throws on error.
*
* @return {Promise<string | null>} The anonymous cookie value, or null if it doesn't exist
*/
export declare const initializeAnonId: () => Promise<string | null>;
export declare const getAnonId: () => Promise<string | null>;
@@ -0,0 +1,8 @@
export declare const fetchExperimentAssignmentAnonymously: ({ experimentName, anonId, }: {
experimentName: string;
anonId: string | null;
}) => Promise<unknown>;
export declare const fetchExperimentAssignmentWithAuth: ({ experimentName, anonId, }: {
experimentName: string;
anonId: string | null;
}) => Promise<unknown>;
@@ -0,0 +1,3 @@
export declare const logError: (error: Record<string, string> & {
message: string;
}) => void;
@@ -0,0 +1,31 @@
/**
* External dependencies
*/
import { createExPlatClient } from '@automattic/explat-client';
import debugFactory from 'debug';
export { createExPlatClient };
export declare const initializeExPlat: () => Promise<string | null | void>;
export declare const loadExperimentAssignment: (experimentName: string) => Promise<import("@automattic/explat-client").ExperimentAssignment>, dangerouslyGetExperimentAssignment: (experimentName: string) => import("@automattic/explat-client").ExperimentAssignment;
export declare const useExperiment: (experimentName: string, options?: import("@automattic/explat-client-react-helpers").ExperimentOptions) => [boolean, import("@automattic/explat-client").ExperimentAssignment | null], Experiment: (props: {
name: string;
defaultExperience: debugFactory;
treatmentExperience: debugFactory;
loadingExperience: debugFactory;
options?: import("@automattic/explat-client-react-helpers").ExperimentOptions;
}) => JSX.Element, ProvideExperimentData: (props: {
children: (isLoading: boolean, experimentAssignment: import("@automattic/explat-client").ExperimentAssignment | null) => JSX.Element;
name: string;
options?: import("@automattic/explat-client-react-helpers").ExperimentOptions;
}) => JSX.Element;
export declare const loadExperimentAssignmentWithAuth: (experimentName: string) => Promise<import("@automattic/explat-client").ExperimentAssignment>, dangerouslyGetExperimentAssignmentWithAuth: (experimentName: string) => import("@automattic/explat-client").ExperimentAssignment;
export declare const useExperimentWithAuth: (experimentName: string, options?: import("@automattic/explat-client-react-helpers").ExperimentOptions) => [boolean, import("@automattic/explat-client").ExperimentAssignment | null], ExperimentWithAuth: (props: {
name: string;
defaultExperience: debugFactory;
treatmentExperience: debugFactory;
loadingExperience: debugFactory;
options?: import("@automattic/explat-client-react-helpers").ExperimentOptions;
}) => JSX.Element, ProvideExperimentDataWithAuth: (props: {
children: (isLoading: boolean, experimentAssignment: import("@automattic/explat-client").ExperimentAssignment | null) => JSX.Element;
name: string;
options?: import("@automattic/explat-client-react-helpers").ExperimentOptions;
}) => JSX.Element;
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-url'), 'version' => 'd909fec2f1655c5db20c');
@@ -0,0 +1 @@
(()=>{var e={792(e,t,n){"use strict";n.d(t,{A:()=>i});var r=n(790),o=n(609);const s={isEligible:!0};function i(e){const t=(t,n={})=>{const r={...s,...n},[,i]=(0,o.useReducer)(e=>e+1,0),a=(0,o.useRef)(t);if((0,o.useEffect)(()=>{let n=!0;return r.isEligible&&e.loadExperimentAssignment(t).then(()=>{n&&i()}),()=>{n=!1}},[t,r.isEligible]),t===a.current||a.current.startsWith("explat_test")||e.config.logError({message:"[ExPlat] useExperiment: experimentName should never change between renders!"}),!r.isEligible)return[!1,null];const c=e.dangerouslyGetMaybeLoadedExperimentAssignment(t);return[!c,c]};return{useExperiment:t,Experiment:({defaultExperience:e,treatmentExperience:n,loadingExperience:o,name:s,options:i})=>{const[a,c]=t(s,i);return a?(0,r.jsx)(r.Fragment,{children:o}):c?.variationName?(0,r.jsx)(r.Fragment,{children:n}):(0,r.jsx)(r.Fragment,{children:e})},ProvideExperimentData:({children:e,name:n,options:r})=>{const[o,s]=t(n,r);return e(o,s)}}}},517(e,t,n){"use strict";n.d(t,{kU:()=>c,pg:()=>u});var r=n(689),o=n(808),s=n(738),i=n(762),a=n(626);Error;function c(e){if("undefined"==typeof window)throw new Error("Running outside of a browser context.");const t={},n=(...t)=>{try{e.logError(...t)}catch(e){}};try{(0,r.bZ)()}catch(e){n({message:e.message,source:"removeExpiredExperimentAssignments-error"})}return{loadExperimentAssignment:async c=>{try{if(!a.Eo(c))throw new Error(`Invalid experimentName: "${c}"`);const n=(0,r.B1)(c);if(n&&o.H2(n))return n;void 0===t[c]&&(t[c]=(t=>i.MC(async()=>{const n=await s.FI(e,t);return(0,r.a2)(n),n}))(c));let u=1e4;Math.random()>.5&&(u=5e3);const l=await i.BK(t[c](),u);if(!l)throw new Error("Could not fetch ExperimentAssignment");return l}catch(e){n({message:e.message,experimentName:c,source:"loadExperimentAssignment-initialError"})}try{const e=(0,r.B1)(c);if(e)return e;const t=(0,o.fj)(c);return(0,r.a2)(t),t}catch(e){return n({message:e.message,experimentName:c,source:"loadExperimentAssignment-fallbackError"}),(0,o.fj)(c)}},dangerouslyGetExperimentAssignment:t=>{try{if(!a.Eo(t))throw new Error(`Invalid experimentName: ${t}`);const o=(0,r.B1)(t);if(!o)throw new Error("Trying to dangerously get an ExperimentAssignment that hasn't loaded.");return e.isDevelopmentMode&&o&&i.XZ()-o.retrievedTimestamp<1e3&&n({message:"Warning: Trying to dangerously get an ExperimentAssignment too soon after loading it.",experimentName:t,source:"dangerouslyGetExperimentAssignment"}),o}catch(r){return e.isDevelopmentMode&&n({message:r.message,experimentName:t,source:"dangerouslyGetExperimentAssignment-error"}),(0,o.fj)(t)}},dangerouslyGetMaybeLoadedExperimentAssignment:t=>{try{if(!a.Eo(t))throw new Error(`Invalid experimentName: ${t}`);const e=(0,r.B1)(t);return e||null}catch(r){return e.isDevelopmentMode&&n({message:r.message,experimentName:t,source:"dangerouslyGetMaybeLoadedExperimentAssignment-error"}),(0,o.fj)(t)}},config:e}}function u(e){return{loadExperimentAssignment:async t=>(e.logError({message:"Attempting to load ExperimentAssignment in SSR context",experimentName:t}),(0,o.fj)(t)),dangerouslyGetExperimentAssignment:t=>(e.logError({message:"Attempting to dangerously get ExperimentAssignment in SSR context",experimentName:t}),(0,o.fj)(t)),dangerouslyGetMaybeLoadedExperimentAssignment:t=>(e.logError({message:"Attempting to dangerously get ExperimentAssignment in SSR context",experimentName:t}),(0,o.fj)(t)),config:e}}},226(e,t,n){"use strict";n.d(t,{k:()=>o});var r=n(517);const o="undefined"==typeof window?r.pg:r.kU},689(e,t,n){"use strict";n.d(t,{B1:()=>u,a2:()=>c,bZ:()=>p});var r=n(808),o=n(765),s=n(626);const i="explat-experiment-",a=e=>`${i}-${e}`;function c(e){s.zV(e);const t=u(e.experimentName);if(t&&e.retrievedTimestamp<t.retrievedTimestamp)throw new Error("Trying to store an older experiment assignment than is present in the store, likely a race condition.");o.A.setItem(a(e.experimentName),JSON.stringify(e))}function u(e){const t=o.A.getItem(a(e));if(t)return s.zV(JSON.parse(t))}function l(){return(e=o.A.length,[...Array(e).keys()]).map(e=>o.A.key(e));var e}function d(e){return e.startsWith(i)}function m(e){return e.slice(19)}function p(){l().filter(d).map(m).filter(e=>{try{if(r.H2(u(e)))return!1}catch(e){}return!0}).map(a).map(e=>o.A.removeItem(e))}},808(e,t,n){"use strict";n.d(t,{H2:()=>o,fj:()=>i,fn:()=>s});var r=n(762);function o(e){return r.XZ()<e.ttl*r.If+e.retrievedTimestamp}const s=60,i=(e,t=s)=>({experimentName:e,variationName:null,retrievedTimestamp:r.XZ(),ttl:Math.max(s,t),isFallbackExperimentAssignment:!0})},765(e,t,n){"use strict";n.d(t,{A:()=>o});let r={_data:{},setItem:function(e,t){this._data[e]=t},getItem:function(e){return this._data.hasOwnProperty(e)?this._data[e]:null},removeItem:function(e){delete this._data[e]},clear:function(){this._data={}},get length(){return Object.keys(this._data).length},key:function(e){const t=Object.keys(this._data);return e in t?t[e]:null}};try{window.localStorage&&(r=window.localStorage)}catch(e){}const o=r},738(e,t,n){"use strict";n.d(t,{Line truncated
@@ -0,0 +1,4 @@
/**
* Boolean determining if environment is development.
*/
export declare const isDevelopmentMode: boolean;