@picked/client 0.0.14-next.2 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var y=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var o=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../user-session-nuW7qzmd.cjs"),d=require("../logger-BsmHUUw1.cjs"),l=require("../experience-instance-B2l_MG7I.cjs"),S=require("effector"),c=require("../supports-YvpQZxbh.cjs"),u=require("../storage-DuRlyFaY.cjs"),w=(i,e,t)=>{const s=e.name,r=e.setup(i);if(r){const a=t[s]??{};t[s]=Object.freeze({...a,...r})}};function I(i){const e=typeof window<"u",t={client:i,responses:i.responses.listStore.getState(),fields:i.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(t)}const v=()=>S.createEvent(),P=()=>"0.0.14-next.2";function x(){if(c.supportsDocument()){const i=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of i)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function k(){if(!c.supportsWindow())return{};const i=new URLSearchParams(window.location.search),e={},t=new Set;for(const[r]of i.entries())r.startsWith("picked-")&&t.add(r);for(const r of t){const a=r.replace("picked-","");e[a]=i.getAll(r)}const s=u.createStorageKey("s");if(t.size>0)u.sessionStore.set(s,e);else{const r=u.sessionStore.get(s);if(r)return r.json()||{}}return e}class h{constructor(e){o(this,"options");o(this,"isReady",!1);o(this,"project");o(this,"plugins",{});o(this,"eventBus",v());o(this,"organizationId");o(this,"projectId");o(this,"apiUrl");o(this,"session");o(this,"searchParams",k());o(this,"history",n.createHistory());o(this,"components",n.createComponentIndex({client:this}));o(this,"experienceInstances",l.createExperienceInstanceIndex({client:this}));o(this,"experiences",n.createExperienceIndex({client:this}));o(this,"frameworks",n.createFrameworkIndex({client:this}));o(this,"predicates",n.createPredicateIndex({client:this}));o(this,"features",n.createFeatureIndex({client:this}));o(this,"responses",n.createResponseIndex({client:this}));o(this,"fields",n.createFieldIndex());o(this,"actions",n.createActionIndex());d.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||x(),this.session=n.initialiseSession(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.eventBus({type:"initialized",version:P()}),d.logger("info","Picked client initialized.")}start(){n.ping(this),(async()=>{c.supportsDocument()&&(document.body&&n.initialiseExperiences(this),await l.domInteractive(),await n.initialiseExperiences(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session}))})()}registerFramework(e){n.setupFramework(e,this.frameworks)}registerComponent(e,t){n.setupComponent(e,t,this.components)}registerPlugin(e){w(this,e,this.plugins)}registerFeature(e,t){n.setupFeature(e,t,this.features)}registerPredicate(e,t){n.setupPredicate(e,t,this.predicates)}registerField(e){n.setupField(e,this.fields)}registerAction(e,t){n.setupAction(e,t,this.actions)}registerExperience(e){e.component&&n.setupComponent(`experience:${e.id}`,e.component,this.components),n.setupExperience(e,this.experiences)}getStateSnapshot(){return I(this)}async launchExperienceById(e){const t=this.experiences.getById(e).getState();if(!t){d.logger("warn",`Experience with id '${e}' not found.`);return}n.initialiseExperience(this,t)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(t=>{if(Array.isArray(t)){t.forEach(r=>{this.registerPlugin(r)});return}const s=typeof t=="function"?t():t;if(Array.isArray(s)){s.forEach(r=>this.registerPlugin(r));return}this.registerPlugin(s)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([t,s])=>{const r=typeof s=="function"?s():s;this.registerFeature(t,r)}),this.searchParams.feature&&this.searchParams.feature.forEach(t=>{try{const[s,r]=t.split(":");if(!s||!r)return;let a=r;a==="true"&&(a=!0),a==="false"&&(a=!1),this.registerFeature(s,{key:`${a}`,name:s,decide:()=>a,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([t,s])=>{if(typeof s!="function"){d.logger("warn",`Predicate "${t}" is not a function.`);return}this.registerPredicate(t,s)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([t,s])=>{if(typeof s!="function"){d.logger("warn",`Action "${t}" is not a function.`);return}this.registerAction(t,s)})}getPluginConfig(e){return this.plugins[e]??{}}}o(h,"logger",d.logger);function f(i){var e;return((e=i.options)==null?void 0:e.some(t=>"condition"in t))??!1}function E(i){return i.some(e=>e.condition||f(e))}async function C(i,e){return e.length===0||!E(e)?e:(await Promise.all(e.map(async s=>{if(!(s.condition?await l.evaluateRuleLogic(i,s.condition):!0))return null;if(!s.options||!f(s))return s;const g=(await Promise.all(s.options.map(async p=>p.condition?await l.evaluateRuleLogic(i,p.condition)?p:null:p))).filter(p=>p!==null);return g.length===s.options.length?s:g.length===0?null:{...s,options:g}}))).filter(s=>s!==null)}const R=i=>{const e=new h(i);return c.bindClient(e),e};exports.evaluateRuleLogic=l.evaluateRuleLogic;exports.isPickedRoot=l.isPickedRoot;exports.supportsCookies=c.supportsCookies;exports.supportsCryptoRandomUUID=c.supportsCryptoRandomUUID;exports.supportsDocument=c.supportsDocument;exports.supportsHistory=c.supportsHistory;exports.supportsIntersectionObserver=c.supportsIntersectionObserver;exports.supportsLocalStorage=c.supportsLocalStorage;exports.supportsLocation=c.supportsLocation;exports.supportsSessionStorage=c.supportsSessionStorage;exports.supportsShadowRoot=c.supportsShadowRoot;exports.supportsWebComponents=c.supportsWebComponents;exports.supportsWindow=c.supportsWindow;exports.createStorageKey=u.createStorageKey;exports.localStore=u.localStore;exports.sessionStore=u.sessionStore;exports.subscribe=u.subscribe;exports.Picked=h;exports.createClient=R;exports.getStepFields=C;
1
+ "use strict";var m=Object.defineProperty;var y=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var o=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../user-session-D-l-VMTb.cjs"),d=require("../logger-BsmHUUw1.cjs"),l=require("../experience-instance-B2l_MG7I.cjs"),S=require("effector"),c=require("../supports-YvpQZxbh.cjs"),u=require("../storage-DuRlyFaY.cjs"),w=(i,e,t)=>{const s=e.name,n=e.setup(i);if(n){const a=t[s]??{};t[s]=Object.freeze({...a,...n})}};function I(i){const e=typeof window<"u",t={client:i,responses:i.responses.listStore.getState(),fields:i.fields.listStore.getState(),location:e?window.location:void 0,document:e?window.document:void 0,sessionStorage:e?window.sessionStorage:void 0,localStorage:e?window.localStorage:void 0};return Object.freeze(t)}const v=()=>S.createEvent(),P=()=>"0.0.14";function k(){if(c.supportsDocument()){const i=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of i)if(e!=null&&e.dataset.api)return e.dataset.api}return"https://api.picked.app"}function x(){if(!c.supportsWindow())return{};const i=new URLSearchParams(window.location.search),e={},t=new Set;for(const[n]of i.entries())n.startsWith("picked-")&&t.add(n);for(const n of t){const a=n.replace("picked-","");e[a]=i.getAll(n)}const s=u.createStorageKey("s");if(t.size>0)u.sessionStore.set(s,e);else{const n=u.sessionStore.get(s);if(n)return n.json()||{}}return e}class h{constructor(e){o(this,"options");o(this,"isReady",!1);o(this,"project");o(this,"plugins",{});o(this,"eventBus",v());o(this,"organizationId");o(this,"projectId");o(this,"apiUrl");o(this,"session");o(this,"searchParams",x());o(this,"history",r.createHistory());o(this,"components",r.createComponentIndex({client:this}));o(this,"experienceInstances",l.createExperienceInstanceIndex({client:this}));o(this,"experiences",r.createExperienceIndex({client:this}));o(this,"frameworks",r.createFrameworkIndex({client:this}));o(this,"predicates",r.createPredicateIndex({client:this}));o(this,"features",r.createFeatureIndex({client:this}));o(this,"responses",r.createResponseIndex({client:this}));o(this,"fields",r.createFieldIndex());o(this,"actions",r.createActionIndex());d.logger("info","Picked client initializing."),this.organizationId=e.organizationId,this.projectId=e.projectId,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||k(),this.session=r.initialiseSession(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.eventBus({type:"initialized",version:P()}),d.logger("info","Picked client initialized.")}start(){r.ping(this),(async()=>{c.supportsDocument()&&(document.body&&r.initialiseExperiences(this),await l.domInteractive(),await r.initialiseExperiences(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session}))})()}registerFramework(e){r.setupFramework(e,this.frameworks)}registerComponent(e,t){r.setupComponent(e,t,this.components)}registerPlugin(e){w(this,e,this.plugins)}registerFeature(e,t){r.setupFeature(e,t,this.features)}registerPredicate(e,t){r.setupPredicate(e,t,this.predicates)}registerField(e){r.setupField(e,this.fields)}registerAction(e,t){r.setupAction(e,t,this.actions)}registerExperience(e){e.component&&r.setupComponent(`experience:${e.id}`,e.component,this.components),r.setupExperience(e,this.experiences)}getStateSnapshot(){return I(this)}async launchExperienceById(e){const t=this.experiences.getById(e).getState();if(!t){d.logger("warn",`Experience with id '${e}' not found.`);return}r.initialiseExperience(this,t)}setupPlugins(){var e;(e=this.options.plugins)==null||e.forEach(t=>{if(Array.isArray(t)){t.forEach(n=>{this.registerPlugin(n)});return}const s=typeof t=="function"?t():t;if(Array.isArray(s)){s.forEach(n=>this.registerPlugin(n));return}this.registerPlugin(s)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([t,s])=>{const n=typeof s=="function"?s():s;this.registerFeature(t,n)}),this.searchParams.feature&&this.searchParams.feature.forEach(t=>{try{const[s,n]=t.split(":");if(!s||!n)return;let a=n;a==="true"&&(a=!0),a==="false"&&(a=!1),this.registerFeature(s,{key:`${a}`,name:s,decide:()=>a,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([t,s])=>{if(typeof s!="function"){d.logger("warn",`Predicate "${t}" is not a function.`);return}this.registerPredicate(t,s)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([t,s])=>{if(typeof s!="function"){d.logger("warn",`Action "${t}" is not a function.`);return}this.registerAction(t,s)})}getPluginConfig(e){return this.plugins[e]??{}}}o(h,"logger",d.logger);function f(i){var e;return((e=i.options)==null?void 0:e.some(t=>"condition"in t))??!1}function E(i){return i.some(e=>e.condition||f(e))}async function C(i,e){return e.length===0||!E(e)?e:(await Promise.all(e.map(async s=>{if(!(s.condition?await l.evaluateRuleLogic(i,s.condition):!0))return null;if(!s.options||!f(s))return s;const g=(await Promise.all(s.options.map(async p=>p.condition?await l.evaluateRuleLogic(i,p.condition)?p:null:p))).filter(p=>p!==null);return g.length===s.options.length?s:g.length===0?null:{...s,options:g}}))).filter(s=>s!==null)}const R=i=>{const e=new h(i);return c.bindClient(e),e};exports.evaluateRuleLogic=l.evaluateRuleLogic;exports.isPickedRoot=l.isPickedRoot;exports.supportsCookies=c.supportsCookies;exports.supportsCryptoRandomUUID=c.supportsCryptoRandomUUID;exports.supportsDocument=c.supportsDocument;exports.supportsHistory=c.supportsHistory;exports.supportsIntersectionObserver=c.supportsIntersectionObserver;exports.supportsLocalStorage=c.supportsLocalStorage;exports.supportsLocation=c.supportsLocation;exports.supportsSessionStorage=c.supportsSessionStorage;exports.supportsShadowRoot=c.supportsShadowRoot;exports.supportsWebComponents=c.supportsWebComponents;exports.supportsWindow=c.supportsWindow;exports.createStorageKey=u.createStorageKey;exports.localStore=u.localStore;exports.sessionStore=u.sessionStore;exports.subscribe=u.subscribe;exports.Picked=h;exports.createClient=R;exports.getStepFields=C;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../../../supports-YvpQZxbh.cjs");require("../../../user-session-nuW7qzmd.cjs");require("../../../experience-instance-B2l_MG7I.cjs");require("effector");function c(){if(r.supportsWindow())return window.pickedConfig}function l(){var e;if(r.supportsWindow())return(e=c())==null?void 0:e.customer}function s(){var e;if(r.supportsWindow())return(e=c())==null?void 0:e.product}function u(){var e;if(r.supportsWindow())return(e=c())==null?void 0:e.collection}function d(){var e;if(r.supportsWindow())return(e=c())==null?void 0:e.experiments}function f(){var e,o;if(r.supportsWindow())return(o=(e=c())==null?void 0:e.storefront_api)==null?void 0:o.token}const t={homepage:/^\/$/,page:/(?:^|\/)pages\/[^/]+$/,blog:/(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,article:/^\/blogs\/[^/]+\/(?<article>[^/]+)\/?$/,cart:/(?:^|\/)cart\/[^/]+$/,checkout:/^\/checkout\/.+/,appProxy:/^\/(?:a|apps|community|tools)\/(?<proxyTarget>[^/]+)/,accountWildcard:/^\/account\/.+/,accountLogin:/^\/account\/login(?:\/|$)/,accountRegister:/^\/account\/register(?:\/|$)/},n=(e,o)=>o?!!e.exec(o.pathname):!1,a=(e,o)=>{if(o){const i=e.exec(o.pathname);if(i)return i[1]}},p=e=>{var o,i;switch(e){case"product":return((o=s())==null?void 0:o.handle)??!1;case"collection":return((i=u())==null?void 0:i.handle)??!1;default:return!1}},h={"is-page":({location:e})=>n(t.page,e),"get-page-handle":({location:e})=>a(t.page,e),"is-product-page":()=>!!p("product"),"get-product-handle":()=>p("product"),"is-collection-page":()=>!!p("collection"),"get-collection-handle":()=>p("collection"),"is-blog-page":({location:e})=>n(t.blog,e),"get-blog-handle":({location:e})=>a(t.blog,e),"is-article-page":({location:e})=>n(t.article,e),"get-article-handle":({location:e})=>a(t.article,e),"is-app-proxy-page":({location:e})=>n(t.appProxy,e),"get-app-proxy-handle":({location:e})=>a(t.appProxy,e),"is-account-page":({location:e})=>n(t.accountWildcard,e),"is-login-page":({location:e})=>n(t.accountLogin,e),"is-register-page":({location:e})=>n(t.accountRegister,e),"is-cart-page":({location:e})=>n(t.cart,e),"is-checkout-page":({location:e})=>n(t.checkout,e),"is-homepage":({location:e})=>n(t.homepage,e)};function g(){if(!r.supportsWindow()||!window.Shopify)throw new Error("Shopify global object not found. This plugin must be used on a Shopify storefront page.");return window.Shopify}function y(e){var o,i;return typeof((i=(o=g())==null?void 0:o.analytics)==null?void 0:i.publish)=="function"}const P=()=>({name:"shopify",setup:e=>{Object.entries(h).forEach(([o,i])=>{e.registerPredicate(`shopify-${o}`,i)}),r.supportsWindow()&&e.eventBus.watch(o=>{y()&&o.type==="session"&&window.Shopify.analytics.publish("picked:session",{id:o.id})})}});exports.getPickedConfig=c;exports.getPickedConfigCollection=u;exports.getPickedConfigCustomer=l;exports.getPickedConfigExperiments=d;exports.getPickedConfigProduct=s;exports.getPickedConfigStorefrontApiToken=f;exports.getShopify=g;exports.shopifyPlugin=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../../../supports-YvpQZxbh.cjs");require("../../../user-session-D-l-VMTb.cjs");require("../../../experience-instance-B2l_MG7I.cjs");require("effector");function c(){if(!r.supportsWindow()||!window.pickedConfig)throw new Error("Picked config not found. Ensure the Picked Script is enabled on your Shopify storefront");return window.pickedConfig}function d(){if(r.supportsWindow())return c().customer}function s(){if(r.supportsWindow())return c().product}function u(){if(r.supportsWindow())return c().collection}function l(){if(r.supportsWindow())return c().experiments}function f(){var e;if(r.supportsWindow())return(e=c().storefront_api)==null?void 0:e.token}const t={homepage:/^\/$/,page:/(?:^|\/)pages\/[^/]+$/,blog:/(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,article:/^\/blogs\/[^/]+\/(?<article>[^/]+)\/?$/,cart:/(?:^|\/)cart\/[^/]+$/,checkout:/^\/checkout\/.+/,appProxy:/^\/(?:a|apps|community|tools)\/(?<proxyTarget>[^/]+)/,accountWildcard:/^\/account\/.+/,accountLogin:/^\/account\/login(?:\/|$)/,accountRegister:/^\/account\/register(?:\/|$)/},n=(e,o)=>o?!!e.exec(o.pathname):!1,a=(e,o)=>{if(o){const i=e.exec(o.pathname);if(i)return i[1]}},p=e=>{var o,i;switch(e){case"product":return((o=s())==null?void 0:o.handle)??!1;case"collection":return((i=u())==null?void 0:i.handle)??!1;default:return!1}},h={"is-page":({location:e})=>n(t.page,e),"get-page-handle":({location:e})=>a(t.page,e),"is-product-page":()=>!!p("product"),"get-product-handle":()=>p("product"),"is-collection-page":()=>!!p("collection"),"get-collection-handle":()=>p("collection"),"is-blog-page":({location:e})=>n(t.blog,e),"get-blog-handle":({location:e})=>a(t.blog,e),"is-article-page":({location:e})=>n(t.article,e),"get-article-handle":({location:e})=>a(t.article,e),"is-app-proxy-page":({location:e})=>n(t.appProxy,e),"get-app-proxy-handle":({location:e})=>a(t.appProxy,e),"is-account-page":({location:e})=>n(t.accountWildcard,e),"is-login-page":({location:e})=>n(t.accountLogin,e),"is-register-page":({location:e})=>n(t.accountRegister,e),"is-cart-page":({location:e})=>n(t.cart,e),"is-checkout-page":({location:e})=>n(t.checkout,e),"is-homepage":({location:e})=>n(t.homepage,e)};function g(){if(!r.supportsWindow()||!window.Shopify)throw new Error("Shopify global object not found. This plugin must be used on a Shopify storefront page.");return window.Shopify}function y(e){var o,i;return typeof((i=(o=g())==null?void 0:o.analytics)==null?void 0:i.publish)=="function"}const P=()=>({name:"shopify",setup:e=>{Object.entries(h).forEach(([o,i])=>{e.registerPredicate(`shopify-${o}`,i)}),r.supportsWindow()&&e.eventBus.watch(o=>{y()&&o.type==="session"&&window.Shopify.analytics.publish("picked:session",{id:o.id})})}});exports.getPickedConfig=c;exports.getPickedConfigCollection=u;exports.getPickedConfigCustomer=d;exports.getPickedConfigExperiments=l;exports.getPickedConfigProduct=s;exports.getPickedConfigStorefrontApiToken=f;exports.getShopify=g;exports.shopifyPlugin=P;
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var y = Object.defineProperty;
2
2
  var w = (i, e, t) => e in i ? y(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
3
  var n = (i, e, t) => w(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { c as S, a as x, b as I, d as P, e as k, f as v, g as E, h as F, i as b, j as C, p as A, s as R, k as u, l as j, m as B, n as z, o as U, q as O, r as $, t as d } from "../user-session-DINAj_Ci.js";
4
+ import { c as S, a as x, b as I, d as P, e as k, f as v, g as E, h as F, i as b, j as C, p as A, s as R, k as u, l as j, m as B, n as z, o as U, q as O, r as $, t as d } from "../user-session-Ht0ayuo5.js";
5
5
  import { l as c } from "../logger-C9a75KZn.js";
6
6
  import { c as K, d as L, e as l } from "../experience-instance-CeuHLrdL.js";
7
7
  import { i as pe } from "../experience-instance-CeuHLrdL.js";
@@ -29,7 +29,7 @@ function N(i) {
29
29
  };
30
30
  return Object.freeze(t);
31
31
  }
32
- const T = () => W(), V = () => "0.0.14-next.2";
32
+ const T = () => W(), V = () => "0.0.14";
33
33
  function G() {
34
34
  if (h()) {
35
35
  const i = [
@@ -1,37 +1,36 @@
1
1
  import { a as r } from "../../../supports-DBMT17KZ.js";
2
- import "../../../user-session-DINAj_Ci.js";
2
+ import "../../../user-session-Ht0ayuo5.js";
3
3
  import "../../../experience-instance-CeuHLrdL.js";
4
4
  import "effector";
5
- function a() {
6
- if (r())
7
- return window.pickedConfig;
5
+ function c() {
6
+ if (!r() || !window.pickedConfig)
7
+ throw new Error(
8
+ "Picked config not found. Ensure the Picked Script is enabled on your Shopify storefront"
9
+ );
10
+ return window.pickedConfig;
8
11
  }
9
- function P() {
10
- var e;
12
+ function w() {
11
13
  if (r())
12
- return (e = a()) == null ? void 0 : e.customer;
14
+ return c().customer;
13
15
  }
14
16
  function s() {
15
- var e;
16
17
  if (r())
17
- return (e = a()) == null ? void 0 : e.product;
18
+ return c().product;
18
19
  }
19
20
  function u() {
20
- var e;
21
21
  if (r())
22
- return (e = a()) == null ? void 0 : e.collection;
22
+ return c().collection;
23
23
  }
24
- function b() {
25
- var e;
24
+ function k() {
26
25
  if (r())
27
- return (e = a()) == null ? void 0 : e.experiments;
26
+ return c().experiments;
28
27
  }
29
- function k() {
30
- var e, t;
28
+ function P() {
29
+ var e;
31
30
  if (r())
32
- return (t = (e = a()) == null ? void 0 : e.storefront_api) == null ? void 0 : t.token;
31
+ return (e = c().storefront_api) == null ? void 0 : e.token;
33
32
  }
34
- const o = {
33
+ const t = {
35
34
  homepage: /^\/$/,
36
35
  page: /(?:^|\/)pages\/[^/]+$/,
37
36
  blog: /(?:^|\/)blogs\/(?<blogHandle>[^/]+)\/?$/,
@@ -42,17 +41,17 @@ const o = {
42
41
  accountWildcard: /^\/account\/.+/,
43
42
  accountLogin: /^\/account\/login(?:\/|$)/,
44
43
  accountRegister: /^\/account\/register(?:\/|$)/
45
- }, n = (e, t) => t ? !!e.exec(t.pathname) : !1, c = (e, t) => {
46
- if (t) {
47
- const i = e.exec(t.pathname);
44
+ }, n = (e, o) => o ? !!e.exec(o.pathname) : !1, a = (e, o) => {
45
+ if (o) {
46
+ const i = e.exec(o.pathname);
48
47
  if (i)
49
48
  return i[1];
50
49
  }
51
50
  }, p = (e) => {
52
- var t, i;
51
+ var o, i;
53
52
  switch (e) {
54
53
  case "product":
55
- return ((t = s()) == null ? void 0 : t.handle) ?? !1;
54
+ return ((o = s()) == null ? void 0 : o.handle) ?? !1;
56
55
  case "collection":
57
56
  return ((i = u()) == null ? void 0 : i.handle) ?? !1;
58
57
  default:
@@ -60,8 +59,8 @@ const o = {
60
59
  }
61
60
  }, g = {
62
61
  // Pages
63
- "is-page": ({ location: e }) => n(o.page, e),
64
- "get-page-handle": ({ location: e }) => c(o.page, e),
62
+ "is-page": ({ location: e }) => n(t.page, e),
63
+ "get-page-handle": ({ location: e }) => a(t.page, e),
65
64
  // Products
66
65
  "is-product-page": () => !!p("product"),
67
66
  "get-product-handle": () => p("product"),
@@ -69,24 +68,24 @@ const o = {
69
68
  "is-collection-page": () => !!p("collection"),
70
69
  "get-collection-handle": () => p("collection"),
71
70
  // Blogs
72
- "is-blog-page": ({ location: e }) => n(o.blog, e),
73
- "get-blog-handle": ({ location: e }) => c(o.blog, e),
71
+ "is-blog-page": ({ location: e }) => n(t.blog, e),
72
+ "get-blog-handle": ({ location: e }) => a(t.blog, e),
74
73
  // Blog Articles
75
- "is-article-page": ({ location: e }) => n(o.article, e),
76
- "get-article-handle": ({ location: e }) => c(o.article, e),
74
+ "is-article-page": ({ location: e }) => n(t.article, e),
75
+ "get-article-handle": ({ location: e }) => a(t.article, e),
77
76
  // Apps
78
- "is-app-proxy-page": ({ location: e }) => n(o.appProxy, e),
79
- "get-app-proxy-handle": ({ location: e }) => c(o.appProxy, e),
77
+ "is-app-proxy-page": ({ location: e }) => n(t.appProxy, e),
78
+ "get-app-proxy-handle": ({ location: e }) => a(t.appProxy, e),
80
79
  // Account
81
- "is-account-page": ({ location: e }) => n(o.accountWildcard, e),
82
- "is-login-page": ({ location: e }) => n(o.accountLogin, e),
83
- "is-register-page": ({ location: e }) => n(o.accountRegister, e),
80
+ "is-account-page": ({ location: e }) => n(t.accountWildcard, e),
81
+ "is-login-page": ({ location: e }) => n(t.accountLogin, e),
82
+ "is-register-page": ({ location: e }) => n(t.accountRegister, e),
84
83
  // Cart
85
- "is-cart-page": ({ location: e }) => n(o.cart, e),
84
+ "is-cart-page": ({ location: e }) => n(t.cart, e),
86
85
  // Checkout
87
- "is-checkout-page": ({ location: e }) => n(o.checkout, e),
86
+ "is-checkout-page": ({ location: e }) => n(t.checkout, e),
88
87
  // Homepage
89
- "is-homepage": ({ location: e }) => n(o.homepage, e)
88
+ "is-homepage": ({ location: e }) => n(t.homepage, e)
90
89
  };
91
90
  function l() {
92
91
  if (!r() || !window.Shopify)
@@ -96,28 +95,28 @@ function l() {
96
95
  return window.Shopify;
97
96
  }
98
97
  function f(e) {
99
- var t, i;
100
- return typeof ((i = (t = l()) == null ? void 0 : t.analytics) == null ? void 0 : i.publish) == "function";
98
+ var o, i;
99
+ return typeof ((i = (o = l()) == null ? void 0 : o.analytics) == null ? void 0 : i.publish) == "function";
101
100
  }
102
- const w = () => ({
101
+ const b = () => ({
103
102
  name: "shopify",
104
103
  setup: (e) => {
105
- Object.entries(g).forEach(([t, i]) => {
106
- e.registerPredicate(`shopify-${t}`, i);
107
- }), r() && e.eventBus.watch((t) => {
108
- f() && t.type === "session" && window.Shopify.analytics.publish("picked:session", {
109
- id: t.id
104
+ Object.entries(g).forEach(([o, i]) => {
105
+ e.registerPredicate(`shopify-${o}`, i);
106
+ }), r() && e.eventBus.watch((o) => {
107
+ f() && o.type === "session" && window.Shopify.analytics.publish("picked:session", {
108
+ id: o.id
110
109
  });
111
110
  });
112
111
  }
113
112
  });
114
113
  export {
115
- a as getPickedConfig,
114
+ c as getPickedConfig,
116
115
  u as getPickedConfigCollection,
117
- P as getPickedConfigCustomer,
118
- b as getPickedConfigExperiments,
116
+ w as getPickedConfigCustomer,
117
+ k as getPickedConfigExperiments,
119
118
  s as getPickedConfigProduct,
120
- k as getPickedConfigStorefrontApiToken,
119
+ P as getPickedConfigStorefrontApiToken,
121
120
  l as getShopify,
122
- w as shopifyPlugin
121
+ b as shopifyPlugin
123
122
  };
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../../src/entities/response/response.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAA;AAkB5E,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAInE,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAA;AAGjC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;CAC5B;AAED,QAAA,MAAM,0BAA0B,eAA8B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;wBA8BnD,K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E,MAAM,CAAA;CAAE;wBA8BnD,KAAK,CAAC,IAAI,CAAC,YAAY,QAAQ,KAAG,IAAI;;;gCA0H5C,eAAe,KACjC,OAAO,CAAC;QAAE,MAAM,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;8CAtHpB,eAAe,KACjC,OAAO,CAAC;QAAE,iBAAiB,EAAE,eAAe,CAAC;QAAC,gBAAgB,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;;;;;;;;4BAgJxD,KAAK,CAAC,IAAI,CAAC;gCAmBP,KAAK,CAAC,MAAM,CAAC;CAwChD,CAAA;AAEF,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC,CAAC,CAAC,EAC5F,MAAM,EAAE,CAAC,GACR,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAE/C;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAA;AAE7D,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;IAGpB,WAAW,EAAE,MAAM,CAAA;IAGnB,aAAa,EAAE,MAAM,CAAA;IAGrB,KAAK,EAAE,UAAU,CAAA;CAClB"}
@@ -66,7 +66,7 @@ declare global {
66
66
  pickedConfig?: Readonly<Partial<CreateClientOptions> & ShopifyPickedConfig>;
67
67
  }
68
68
  }
69
- export declare function getPickedConfig(): Readonly<Partial<CreateClientOptions> & ShopifyPickedConfig> | undefined;
69
+ export declare function getPickedConfig(): Readonly<Partial<CreateClientOptions> & ShopifyPickedConfig>;
70
70
  export declare function getPickedConfigCustomer(): Partial<{
71
71
  accepts_marketing: boolean;
72
72
  email: string;
@@ -1 +1 @@
1
- {"version":3,"file":"picked-config.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shopify/picked-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa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C,GAAG,mBAAmB,CAAC,CAAA;KAC5E;CACF;AAED,wBAAgB,eAAe,iEAQ9B;AAED,wBAAgB,uBAAuB;uBArClB,OAAO;WACnB,MAAM;gBACD,MAAM,GAAG,IAAI;iBACZ,OAAO;QAChB,MAAM;eACC,MAAM,GAAG,IAAI;kBACV,MAAM;WACb,MAAM,GAAG,IAAI;gBACR,OAAO;eAmCpB;AAED,wBAAgB,sBAAsB;eA7DzB,OAAO;iBACL,6BAA6B,EAAE;oBAC5B,MAAM;YACd,MAAM;QACV,MAAM;gBACE,eAAe;WACpB,MAAM;UACP,MAAM,EAAE;WACP,MAAM;UACP,MAAM;SACP,MAAM;cACD,0BAA0B,EAAE;YAC9B,MAAM;eAuDf;AAED,wBAAgB,yBAAyB;WA9FhC,MAAM;QACT,MAAM;YACF,MAAM;eAkGf;AAED,wBAAgB,0BAA0B,yCAMzC;AAED,wBAAgB,iCAAiC,uBAMhD"}
@@ -0,0 +1 @@
1
+ "use strict";const p=require("effector"),y=require("@withease/factories"),w=require("./experience-instance-B2l_MG7I.cjs"),b=require("./logger-BsmHUUw1.cjs"),x=require("./storage-DuRlyFaY.cjs"),P=require("./id-BKIWbSTy.cjs"),M=require("./object-BbFTsGh3.cjs"),B=require("./supports-YvpQZxbh.cjs"),j=p.createDomain("experience"),T=y.createFactory(({client:t,experience:e})=>{const i=j.store(e),g=p.createApi(i,{merge(c,S){return{...c,...S.experience}}}),m=i.map(c=>({name:c.name,decisionLogic:c.decide,targetSelectors:c.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(c=>c.find(S=>S.name===`experience:${e.id}`)||c.find(S=>S.name==="experience"),{skipVoid:!1}),r=i.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),n=e.actions??[];return{id:e.id,configStore:m,treeStore:r,componentStore:d,actions:n,merge:g.merge}});function V(t){return y.invoke(T,t)}const N=y.createFactory(({client:t})=>{const e=j.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.id]:n}}});function g(r){const n=e.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const c=V({client:t,experience:r});i.register(c)}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getById:d,listStore:m}});function C(t){return y.invoke(N,t)}const L=(t,e)=>{e.register(t)},O=(t,e)=>{const{targetSelectors:i}=e.configStore.getState(),g=w.getTargetElements(i,e.id);g.forEach(({elements:d})=>d.forEach(r=>w.tagTargetElement(r,e.id))),w.createAppHosts(g,e.id).forEach(d=>{t.experienceInstances.spawn(e,d)})},q=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await _(t,e)&&O(t,e)}))},_=async(t,e)=>{const{decisionLogic:i,targetSelectors:g}=e.configStore.getState();return w.getTargetElements(g,e.id).length<1||g.length===0?!1:i&&w.isRulesLogic(i)?await w.evaluateRuleLogic(t,i)===!0:!0},U=p.createDomain("component"),H=y.createFactory(({client:t,component:e,name:i})=>{const g=t.frameworks.getByName(e.frameworkName);return{name:i,component:e,frameworkStore:g}});function K(t){return y.invoke(H,t)}const z=y.createFactory(({client:t})=>{const e=U.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:n}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const S=K({client:t,name:r,component:n});i.register(S)}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function G(t){return y.invoke(z,t)}const Y=(t,e,i)=>{i.register(t,e)},J=p.createDomain("framework"),Q=y.createFactory(({client:t})=>{const e=J.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:n.framework}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),i.register({name:r,framework:n})}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function W(t){return y.invoke(Q,t)}const X=(t,e)=>{e.register(t.name,t)},Z=6e3,D=x.createStorageKey("last_ping","global"),ee=t=>`${t}/api/v1/ping`,te=async t=>{try{const e=Date.now(),i=localStorage.getItem(D);if(i&&e-parseInt(i)<Z)return!0;const g=ee(t.apiUrl),m={projectId:t.projectId,path:window.location.pathname},d=JSON.stringify(m),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),c=n==null?void 0:n.dataset.verceltoken;c&&(r["x-vercel-protection-bypass"]=c);const k=(await fetch(g,{method:"POST",headers:r,body:d})).ok;return k&&localStorage.setItem(D,e.toString()),k}catch(e){return b.logger("error",e),!1}},re=p.createDomain("predicate"),ne=y.createFactory(({client:t})=>{const e=re.store({}),i=p.createApi(e,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function g(r,n){e.getState()[r]&&b.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),i.register(Object.freeze({name:r,predicate:n}))}const m=e.map(r=>Object.values(r));function d(r){return e.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function se(t){return y.invoke(ne,t)}const oe=(t,e,i)=>{i.register(t,e)},$=p.createDomain("feature"),ie=y.createFactory(({client:t})=>{const e=$.store({}),i=$.store([]),g=p.createApi(e,{register(a,o){return{...a,[o.id]:o.feature}}});function m(a,o){e.getState()[a]&&b.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const l={id:a,feature:{...o,id:a}};g.register(Object.freeze({id:a,feature:l}))}const d=p.createEffect(async({id:a,key:o,storage:s="local"})=>{const l=x.createStorageKey(`feature:${a}:${o}`,"global"),u=(s==="session"?x.sessionStore:x.localStore).get(l).boolean();return u===null?null:{id:a,key:o,bucket:u}}),r=p.createEffect(a=>{if(!a)return null;const o=x.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?x.sessionStore:x.localStore).set(o,a.bucket)}),n=new Map,c=p.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:i},effect:async({allFeaturesStore:a,resolvedFeaturesStore:o},{id:s,decide:l,key:f})=>{const u=o.find(A=>A.id===s);if(u)return u;const v=a[s];if(!v)throw new Error(`Feature with id '${s}' not found`);const F=n.get(`${s}:${f}`);if(F!==void 0){const A=await F;return{id:v.id,bucket:A,key:f,storage:v.feature.storage}}const E=l();n.set(`${s}:${f}`,E);const I=await E;return{id:v.id,bucket:I,key:f,storage:v.feature.storage}}});p.sample({clock:g.register,fn:a=>{const{id:o,feature:s}=a;return{id:o,key:s.feature.key,storage:s.feature.storage}},target:d}),p.sample({source:e,clock:c.doneData,fn:(a,o)=>{var v;const{id:s,bucket:l,storage:f}=o,u=(v=a[s])==null?void 0:v.feature.key;return u?{key:u,id:s,bucket:l,storage:f}:null},target:r});const S=p.combine({allFeaturesStore:e,resolvedFeaturesStore:i}).map(({allFeaturesStore:a,resolvedFeaturesStore:o})=>Object.values(a).map(s=>{const l=o.find(f=>f.id===s.id);return l?{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:()=>({id:s.id,bucket:l.bucket}),isResolved:!0}:{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:async()=>await c(s.feature),isResolved:!1}}));p.sample({clock:c.doneData,source:{resolvedFeatures:i},filter:({resolvedFeatures:a},{id:o})=>!a.some(s=>s.id===o),fn:(a,o)=>o,target:t.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),p.sample({clock:[d.doneData,c.doneData],source:i,fn:(a,o)=>!o||a.some(s=>s.id===o.id)?a:[...a,o],target:i});function k(a){return e.map(o=>o[a],{skipVoid:!1})}return{register:m,getByName:k,listStore:S}});function ae(t){return y.invoke(ie,t)}const ce=(t,e,i)=>{i.register(t,e)},h=p.createDomain("history");function R(t,e){return{id:P.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ue=y.createFactory(()=>{const t=h.store({entries:[]}),e=h.event(),i=h.event(),g=h.event(),m=h.event();t.on(e,(r,n)=>({entries:[...r.entries,R(n.experienceId,n.node)]})),t.on(i,(r,n)=>({entries:[...r.entries.slice(0,-1),R(n.experienceId,n.node)]})),t.on(m,(r,n)=>n);function d(r,n){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=r.length-1;S>=0;S--){const k=r[S],a=k==null?void 0:k.node;if(!(!a||!w.isStepNode(a))&&!(n&&(k==null?void 0:k.experienceId)!==n))if(c.lastStepIndex===-1)c.lastStepIndex=S;else{c.secondLastStepIndex=S;break}}return c}return t.on(g,(r,n)=>{const{secondLastStepIndex:c}=d(r.entries,n.experienceId),S=c!==-1?r.entries.slice(0,c+1):r.entries;return{...r,entries:S}}),{push:e,replace:i,back:g,restore:m,entriesStore:t.map(r=>r.entries)}});function le(){return y.invoke(ue)}const ge=p.createDomain("field"),de=y.createFactory(()=>{const t=ge.store({}),e=p.createApi(t,{register(r,n){return{...r,[n.field.id]:n.field}}});function i(r){e.register({field:r})}const g=t.map(r=>Object.values(r));function m(r){return t.map(n=>n[r]||null)}function d(r){return t.map(n=>Object.values(n).find(c=>c.name===r)||null)}return{register:i,getById:m,listStore:g,getByName:d}});function pe(){return y.invoke(de)}const me=(t,e)=>{e.register(t)},fe=p.createDomain("action"),ye=y.createFactory(()=>{const t=fe.store({}),e=p.createApi(t,{register(d,r){return{...d,[r.name]:{name:r.name,action:r.action}}}});function i(d,r){e.register({name:d,action:r})}const g=t.map(d=>Object.values(d));function m(d){return t.map(r=>r[d],{skipVoid:!1})}return{register:i,getByName:m,listStore:g}});function Se(){return y.invoke(ye)}const ve=(t,e,i)=>{i.register(t,e)},ke=p.createDomain("response"),Fe=y.createFactory(({client:t})=>{const e=ke.store({}),i=p.createEvent(),g=p.createEvent(),m=p.createApi(e,{register(o,s){return{...o,[s.fieldId]:s.response}},registerBatch(o,s){return{...o,...s}},clear(o,s){const{[s]:l,...f}=o;return f},clearAll(){return{}}});function d(o,s){m.register({fieldId:o,response:s})}async function r(o){const s=[];return await Promise.allSettled(Object.entries(o).map(async([l,f])=>{let u=f;const v=t.fields.getById(l).getState();if(!v){s.push({fieldId:l,userMessage:`Field '${l}' not found`,systemMessage:`No field with ID '${l}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:u});return}if(v.multiple&&(typeof u=="string"||typeof u=="number"||typeof u=="boolean")&&(u=[u]),v.validation&&!M.isEmpty(v.validation)){const F=await w.evaluateRuleLogic(t,v.validation,{$input:u});if(typeof F=="string"){s.push({fieldId:l,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:u});return}if(F===!1){s.push({fieldId:l,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:u});return}}if(v.required&&(typeof u>"u"||u===null||u===""||Array.isArray(u)&&!u.length)){s.push({fieldId:l,userMessage:"This field is required",systemMessage:"Field is required.",value:u});return}if(!v.multiple&&Array.isArray(u)&&u.length>1){s.push({fieldId:l,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:u});return}if(v.options){const F=v.options.map(I=>I.value),E=Array.isArray(u)?u:[u];Array.isArray(u)&&(E.every(I=>F.includes(I))||s.push({fieldId:l,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.join(", ")}`,value:u}))}})),{responsesToCommit:o,validationErrors:s}}async function n(o){const{responsesToCommit:s,validationErrors:l}=await r(o);return l.length?{errors:l}:(m.registerBatch(s),{errors:[]})}const c=e.map(o=>o),S=e.map(o=>Object.keys(o).map(l=>({fieldId:l,value:o[l]})));function k(o){const s=t.fields.getById(o),l=e.map(f=>f[o]||null);return p.combine({f:s,r:l},({f,r:u})=>u||(f!=null&&f.defaultValue?f.defaultValue:null))}function a(o){const s=t.fields.getByName(o);return p.combine({f:s,s:e},({f:l,s:f})=>{const u=l&&f[l.id]||null;return u||(l!=null&&l.defaultValue?l.defaultValue:null)})}return p.sample({clock:i,target:m.clearAll}),p.sample({clock:g,target:m.clear}),{register:d,clearAll:i,clear:g,commit:n,getResponsesToCommit:r,listStore:S,getAllStore:c,getByFieldId:k,getByFieldName:a}});function xe(t){return y.invoke(Fe,t)}function we(){if(B.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),i=Math.random().toString(36).substring(2,15),g=Math.random().toString(36).substring(2,15);return`${t}-${e}-${i}-${g}`}const Ie=()=>({id:we()}),he=x.createStorageKey("session","global"),be=()=>{if(!B.supportsLocalStorage())return null;const t=x.localStore.get(he);let e=t.isSet()?t.json():null;return e||(e=Ie(),t.set(e)),e},Ee=()=>be();exports.createActionIndex=Se;exports.createComponentIndex=G;exports.createExperienceIndex=C;exports.createFeatureIndex=ae;exports.createFieldIndex=pe;exports.createFrameworkIndex=W;exports.createHistory=le;exports.createPredicateIndex=se;exports.createResponseIndex=xe;exports.initialiseExperience=O;exports.initialiseExperiences=q;exports.initialiseSession=Ee;exports.ping=te;exports.setupAction=ve;exports.setupComponent=Y;exports.setupExperience=L;exports.setupFeature=ce;exports.setupField=me;exports.setupFramework=X;exports.setupPredicate=oe;
@@ -1,14 +1,14 @@
1
- import { createDomain as h, createApi as b, createEffect as j, attach as U, sample as x, combine as B, createEvent as O } from "effector";
2
- import { createFactory as k, invoke as v } from "@withease/factories";
3
- import { g as C, t as H, b as q, f as z, e as L, h as G } from "./experience-instance-CeuHLrdL.js";
1
+ import { createDomain as h, createApi as b, createEffect as j, attach as _, sample as x, combine as B, createEvent as O } from "effector";
2
+ import { createFactory as v, invoke as k } from "@withease/factories";
3
+ import { g as N, t as U, b as H, f as q, e as C, h as z } from "./experience-instance-CeuHLrdL.js";
4
4
  import { l as E } from "./logger-C9a75KZn.js";
5
- import { c as R, s as M, l as A } from "./storage-Cb_71y48.js";
6
- import { g as K } from "./id-BW-g3y32.js";
7
- import { i as Y } from "./object-JwZ58NOH.js";
8
- import { e as J, k as Q } from "./supports-DBMT17KZ.js";
9
- const _ = h("experience"), W = k(
10
- ({ client: e, experience: t }) => {
11
- const i = _.store(t), g = b(i, {
5
+ import { c as D, s as M, l as A } from "./storage-Cb_71y48.js";
6
+ import { g as G } from "./id-BW-g3y32.js";
7
+ import { i as K } from "./object-JwZ58NOH.js";
8
+ import { e as Y, k as J } from "./supports-DBMT17KZ.js";
9
+ const L = h("experience"), Q = v(
10
+ ({ client: t, experience: e }) => {
11
+ const i = L.store(e), g = b(i, {
12
12
  merge(c, m) {
13
13
  return {
14
14
  ...c,
@@ -19,18 +19,18 @@ const _ = h("experience"), W = k(
19
19
  name: c.name,
20
20
  decisionLogic: c.decide,
21
21
  targetSelectors: c.targets,
22
- initializeOpenLogic: t.initializeOpen
23
- })), d = e.components.listStore.map(
24
- (c) => c.find((m) => m.name === `experience:${t.id}`) || c.find((m) => m.name === "experience"),
22
+ initializeOpenLogic: e.initializeOpen
23
+ })), d = t.components.listStore.map(
24
+ (c) => c.find((m) => m.name === `experience:${e.id}`) || c.find((m) => m.name === "experience"),
25
25
  { skipVoid: !1 }
26
26
  ), r = i.map((c) => ({
27
27
  steps: c.steps,
28
28
  nodes: c.nodes,
29
29
  edges: c.edges,
30
30
  conditionals: c.conditionals
31
- })), n = t.actions ?? [];
31
+ })), n = e.actions ?? [];
32
32
  return {
33
- id: t.id,
33
+ id: e.id,
34
34
  configStore: p,
35
35
  treeStore: r,
36
36
  componentStore: d,
@@ -39,11 +39,11 @@ const _ = h("experience"), W = k(
39
39
  };
40
40
  }
41
41
  );
42
- function X(e) {
43
- return v(W, e);
42
+ function W(t) {
43
+ return k(Q, t);
44
44
  }
45
- const Z = k(({ client: e }) => {
46
- const t = _.store({}), i = b(t, {
45
+ const X = v(({ client: t }) => {
46
+ const e = L.store({}), i = b(e, {
47
47
  register(r, n) {
48
48
  return {
49
49
  ...r,
@@ -52,17 +52,17 @@ const Z = k(({ client: e }) => {
52
52
  }
53
53
  });
54
54
  function g(r) {
55
- const n = t.getState()[r.id];
55
+ const n = e.getState()[r.id];
56
56
  if (n) {
57
57
  n.merge({ experience: r, strategy: "override" });
58
58
  return;
59
59
  }
60
- const c = X({ client: e, experience: r });
60
+ const c = W({ client: t, experience: r });
61
61
  i.register(c);
62
62
  }
63
- const p = t.map((r) => Object.values(r));
63
+ const p = e.map((r) => Object.values(r));
64
64
  function d(r) {
65
- return t.map((n) => n[r], { skipVoid: !1 });
65
+ return e.map((n) => n[r], { skipVoid: !1 });
66
66
  }
67
67
  return {
68
68
  register: g,
@@ -70,42 +70,42 @@ const Z = k(({ client: e }) => {
70
70
  listStore: p
71
71
  };
72
72
  });
73
- function je(e) {
74
- return v(Z, e);
73
+ function Ae(t) {
74
+ return k(X, t);
75
75
  }
76
- const Oe = (e, t) => {
77
- t.register(e);
78
- }, ee = (e, t) => {
79
- const { targetSelectors: i } = t.configStore.getState(), g = C(i, t.id);
76
+ const je = (t, e) => {
77
+ e.register(t);
78
+ }, Z = (t, e) => {
79
+ const { targetSelectors: i } = e.configStore.getState(), g = N(i, e.id);
80
80
  g.forEach(
81
- ({ elements: d }) => d.forEach((r) => H(r, t.id))
82
- ), q(g, t.id).forEach((d) => {
83
- e.experienceInstances.spawn(t, d);
81
+ ({ elements: d }) => d.forEach((r) => U(r, e.id))
82
+ ), H(g, e.id).forEach((d) => {
83
+ t.experienceInstances.spawn(e, d);
84
84
  });
85
- }, Me = async (e) => {
85
+ }, Oe = async (t) => {
86
86
  await Promise.all(
87
- e.experiences.listStore.getState().map(async (t) => {
88
- await te(e, t) && ee(e, t);
87
+ t.experiences.listStore.getState().map(async (e) => {
88
+ await ee(t, e) && Z(t, e);
89
89
  })
90
90
  );
91
- }, te = async (e, t) => {
92
- const { decisionLogic: i, targetSelectors: g } = t.configStore.getState();
93
- return C(g, t.id).length < 1 || g.length === 0 ? !1 : i && z(i) ? await L(e, i) === !0 : !0;
94
- }, re = h("component"), ne = k(
95
- ({ client: e, component: t, name: i }) => {
96
- const g = e.frameworks.getByName(t.frameworkName);
91
+ }, ee = async (t, e) => {
92
+ const { decisionLogic: i, targetSelectors: g } = e.configStore.getState();
93
+ return N(g, e.id).length < 1 || g.length === 0 ? !1 : i && q(i) ? await C(t, i) === !0 : !0;
94
+ }, te = h("component"), re = v(
95
+ ({ client: t, component: e, name: i }) => {
96
+ const g = t.frameworks.getByName(e.frameworkName);
97
97
  return {
98
98
  name: i,
99
- component: t,
99
+ component: e,
100
100
  frameworkStore: g
101
101
  };
102
102
  }
103
103
  );
104
- function se(e) {
105
- return v(ne, e);
104
+ function ne(t) {
105
+ return k(re, t);
106
106
  }
107
- const oe = k(({ client: e }) => {
108
- const t = re.store({}), i = b(t, {
107
+ const se = v(({ client: t }) => {
108
+ const e = te.store({}), i = b(e, {
109
109
  register(r, n) {
110
110
  return {
111
111
  ...r,
@@ -114,16 +114,16 @@ const oe = k(({ client: e }) => {
114
114
  }
115
115
  });
116
116
  function g(r, n) {
117
- t.getState()[r] && E(
117
+ e.getState()[r] && E(
118
118
  "warn",
119
119
  `Component '${r}' already registered. Registering again will override the previous registration.`
120
120
  );
121
- const m = se({ client: e, name: r, component: n });
121
+ const m = ne({ client: t, name: r, component: n });
122
122
  i.register(m);
123
123
  }
124
- const p = t.map((r) => Object.values(r));
124
+ const p = e.map((r) => Object.values(r));
125
125
  function d(r) {
126
- return t.map((n) => n[r], { skipVoid: !1 });
126
+ return e.map((n) => n[r], { skipVoid: !1 });
127
127
  }
128
128
  return {
129
129
  register: g,
@@ -131,13 +131,13 @@ const oe = k(({ client: e }) => {
131
131
  listStore: p
132
132
  };
133
133
  });
134
- function Pe(e) {
135
- return v(oe, e);
134
+ function Me(t) {
135
+ return k(se, t);
136
136
  }
137
- const Ve = (e, t, i) => {
138
- i.register(e, t);
139
- }, ie = h("framework"), ae = k(({ client: e }) => {
140
- const t = ie.store({}), i = b(t, {
137
+ const Pe = (t, e, i) => {
138
+ i.register(t, e);
139
+ }, oe = h("framework"), ie = v(({ client: t }) => {
140
+ const e = oe.store({}), i = b(e, {
141
141
  register(r, n) {
142
142
  return {
143
143
  ...r,
@@ -146,14 +146,14 @@ const Ve = (e, t, i) => {
146
146
  }
147
147
  });
148
148
  function g(r, n) {
149
- t.getState()[r] && E(
149
+ e.getState()[r] && E(
150
150
  "warn",
151
151
  `Framework '${r}' already registered. Registering again will override the previous registration.`
152
152
  ), i.register({ name: r, framework: n });
153
153
  }
154
- const p = t.map((r) => Object.values(r));
154
+ const p = e.map((r) => Object.values(r));
155
155
  function d(r) {
156
- return t.map((n) => n[r], { skipVoid: !1 });
156
+ return e.map((n) => n[r], { skipVoid: !1 });
157
157
  }
158
158
  return {
159
159
  register: g,
@@ -161,18 +161,18 @@ const Ve = (e, t, i) => {
161
161
  listStore: p
162
162
  };
163
163
  });
164
- function Te(e) {
165
- return v(ae, e);
164
+ function Te(t) {
165
+ return k(ie, t);
166
166
  }
167
- const Ne = (e, t) => {
168
- t.register(e.name, e);
169
- }, ce = 6e3, P = R("last_ping", "global"), ue = (e) => `${e}/api/v1/ping`, Ce = async (e) => {
167
+ const Ve = (t, e) => {
168
+ e.register(t.name, t);
169
+ }, ae = 6e3, P = D("last_ping", "global"), ce = (t) => `${t}/api/v1/ping`, Ne = async (t) => {
170
170
  try {
171
- const t = Date.now(), i = localStorage.getItem(P);
172
- if (i && t - parseInt(i) < ce)
171
+ const e = Date.now(), i = localStorage.getItem(P);
172
+ if (i && e - parseInt(i) < ae)
173
173
  return !0;
174
- const g = ue(e.apiUrl), p = {
175
- projectId: e.projectId,
174
+ const g = ce(t.apiUrl), p = {
175
+ projectId: t.projectId,
176
176
  path: window.location.pathname
177
177
  }, d = JSON.stringify(p), r = {
178
178
  "Content-Type": "application/json"
@@ -183,12 +183,12 @@ const Ne = (e, t) => {
183
183
  headers: r,
184
184
  body: d
185
185
  })).ok;
186
- return S && localStorage.setItem(P, t.toString()), S;
187
- } catch (t) {
188
- return E("error", t), !1;
186
+ return S && localStorage.setItem(P, e.toString()), S;
187
+ } catch (e) {
188
+ return E("error", e), !1;
189
189
  }
190
- }, le = h("predicate"), ge = k(({ client: e }) => {
191
- const t = le.store({}), i = b(t, {
190
+ }, ue = h("predicate"), le = v(({ client: t }) => {
191
+ const e = ue.store({}), i = b(e, {
192
192
  register(r, n) {
193
193
  return {
194
194
  ...r,
@@ -200,14 +200,14 @@ const Ne = (e, t) => {
200
200
  }
201
201
  });
202
202
  function g(r, n) {
203
- t.getState()[r] && E(
203
+ e.getState()[r] && E(
204
204
  "warn",
205
205
  `Predicate '${r}' already registered. Registering again will override the previous registration.`
206
206
  ), i.register(Object.freeze({ name: r, predicate: n }));
207
207
  }
208
- const p = t.map((r) => Object.values(r));
208
+ const p = e.map((r) => Object.values(r));
209
209
  function d(r) {
210
- return t.map((n) => n[r], { skipVoid: !1 });
210
+ return e.map((n) => n[r], { skipVoid: !1 });
211
211
  }
212
212
  return {
213
213
  register: g,
@@ -215,13 +215,13 @@ const Ne = (e, t) => {
215
215
  listStore: p
216
216
  };
217
217
  });
218
- function Le(e) {
219
- return v(ge, e);
218
+ function Ce(t) {
219
+ return k(le, t);
220
220
  }
221
- const _e = (e, t, i) => {
222
- i.register(e, t);
223
- }, V = h("feature"), de = k(({ client: e }) => {
224
- const t = V.store({}), i = V.store([]), g = b(t, {
221
+ const Le = (t, e, i) => {
222
+ i.register(t, e);
223
+ }, T = h("feature"), ge = v(({ client: t }) => {
224
+ const e = T.store({}), i = T.store([]), g = b(e, {
225
225
  register(a, o) {
226
226
  return {
227
227
  ...a,
@@ -230,11 +230,11 @@ const _e = (e, t, i) => {
230
230
  }
231
231
  });
232
232
  function p(a, o) {
233
- t.getState()[a] && E(
233
+ e.getState()[a] && E(
234
234
  "warn",
235
235
  `Feature '${a}' already registered. Registering again will override the previous registration.`
236
236
  );
237
- const u = {
237
+ const l = {
238
238
  id: a,
239
239
  feature: {
240
240
  ...o,
@@ -244,7 +244,7 @@ const _e = (e, t, i) => {
244
244
  g.register(
245
245
  Object.freeze({
246
246
  id: a,
247
- feature: u
247
+ feature: l
248
248
  })
249
249
  );
250
250
  }
@@ -254,29 +254,29 @@ const _e = (e, t, i) => {
254
254
  key: o,
255
255
  storage: s = "local"
256
256
  }) => {
257
- const u = R(`feature:${a}:${o}`, "global"), l = (s === "session" ? M : A).get(u).boolean();
258
- return l === null ? null : { id: a, key: o, bucket: l };
257
+ const l = D(`feature:${a}:${o}`, "global"), u = (s === "session" ? M : A).get(l).boolean();
258
+ return u === null ? null : { id: a, key: o, bucket: u };
259
259
  }
260
260
  ), r = j((a) => {
261
261
  if (!a)
262
262
  return null;
263
- const o = R(`feature:${a.id}:${a.key}`, "global");
263
+ const o = D(`feature:${a.id}:${a.key}`, "global");
264
264
  (a.storage === "session" ? M : A).set(o, a.bucket);
265
- }), n = /* @__PURE__ */ new Map(), c = U({
266
- source: { allFeaturesStore: t, resolvedFeaturesStore: i },
267
- effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide: u, key: f }) => {
268
- const l = o.find((D) => D.id === s);
269
- if (l)
270
- return l;
265
+ }), n = /* @__PURE__ */ new Map(), c = _({
266
+ source: { allFeaturesStore: e, resolvedFeaturesStore: i },
267
+ effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide: l, key: f }) => {
268
+ const u = o.find((R) => R.id === s);
269
+ if (u)
270
+ return u;
271
271
  const y = a[s];
272
272
  if (!y)
273
273
  throw new Error(`Feature with id '${s}' not found`);
274
274
  const w = n.get(`${s}:${f}`);
275
275
  if (w !== void 0) {
276
- const D = await w;
277
- return { id: y.id, bucket: D, key: f, storage: y.feature.storage };
276
+ const R = await w;
277
+ return { id: y.id, bucket: R, key: f, storage: y.feature.storage };
278
278
  }
279
- const $ = u();
279
+ const $ = l();
280
280
  n.set(`${s}:${f}`, $);
281
281
  const F = await $;
282
282
  return { id: y.id, bucket: F, key: f, storage: y.feature.storage };
@@ -290,26 +290,26 @@ const _e = (e, t, i) => {
290
290
  },
291
291
  target: d
292
292
  }), x({
293
- source: t,
293
+ source: e,
294
294
  clock: c.doneData,
295
295
  fn: (a, o) => {
296
296
  var y;
297
- const { id: s, bucket: u, storage: f } = o, l = (y = a[s]) == null ? void 0 : y.feature.key;
298
- return l ? { key: l, id: s, bucket: u, storage: f } : null;
297
+ const { id: s, bucket: l, storage: f } = o, u = (y = a[s]) == null ? void 0 : y.feature.key;
298
+ return u ? { key: u, id: s, bucket: l, storage: f } : null;
299
299
  },
300
300
  target: r
301
301
  });
302
- const m = B({ allFeaturesStore: t, resolvedFeaturesStore: i }).map(
302
+ const m = B({ allFeaturesStore: e, resolvedFeaturesStore: i }).map(
303
303
  ({
304
304
  allFeaturesStore: a,
305
305
  resolvedFeaturesStore: o
306
306
  }) => Object.values(a).map((s) => {
307
- const u = o.find((f) => f.id === s.id);
308
- return u ? {
307
+ const l = o.find((f) => f.id === s.id);
308
+ return l ? {
309
309
  id: s.id,
310
310
  name: s.feature.name,
311
311
  key: s.feature.key,
312
- getBucket: () => ({ id: s.id, bucket: u.bucket }),
312
+ getBucket: () => ({ id: s.id, bucket: l.bucket }),
313
313
  isResolved: !0
314
314
  } : {
315
315
  id: s.id,
@@ -325,7 +325,7 @@ const _e = (e, t, i) => {
325
325
  source: { resolvedFeatures: i },
326
326
  filter: ({ resolvedFeatures: a }, { id: o }) => !a.some((s) => s.id === o),
327
327
  fn: (a, o) => o,
328
- target: e.eventBus.prepend((a) => ({
328
+ target: t.eventBus.prepend((a) => ({
329
329
  type: "feature_decide",
330
330
  feature: a
331
331
  }))
@@ -336,7 +336,7 @@ const _e = (e, t, i) => {
336
336
  target: i
337
337
  });
338
338
  function S(a) {
339
- return t.map((o) => o[a], { skipVoid: !1 });
339
+ return e.map((o) => o[a], { skipVoid: !1 });
340
340
  }
341
341
  return {
342
342
  register: p,
@@ -344,36 +344,36 @@ const _e = (e, t, i) => {
344
344
  listStore: m
345
345
  };
346
346
  });
347
- function Ue(e) {
348
- return v(de, e);
347
+ function _e(t) {
348
+ return k(ge, t);
349
349
  }
350
- const He = (e, t, i) => {
351
- i.register(e, t);
350
+ const Ue = (t, e, i) => {
351
+ i.register(t, e);
352
352
  }, I = h("history");
353
- function T(e, t) {
353
+ function V(t, e) {
354
354
  return {
355
355
  // eslint-disable-next-line sonarjs/pseudo-random
356
- id: K(`history-entry-${Date.now()}-${Math.random()}}`),
357
- node: t,
356
+ id: G(`history-entry-${Date.now()}-${Math.random()}}`),
357
+ node: e,
358
358
  at: Date.now(),
359
- experienceId: e
359
+ experienceId: t
360
360
  };
361
361
  }
362
- const pe = k(() => {
363
- const e = I.store({ entries: [] }), t = I.event(), i = I.event(), g = I.event(), p = I.event();
364
- e.on(t, (r, n) => ({
365
- entries: [...r.entries, T(n.experienceId, n.node)]
366
- })), e.on(i, (r, n) => ({
362
+ const de = v(() => {
363
+ const t = I.store({ entries: [] }), e = I.event(), i = I.event(), g = I.event(), p = I.event();
364
+ t.on(e, (r, n) => ({
365
+ entries: [...r.entries, V(n.experienceId, n.node)]
366
+ })), t.on(i, (r, n) => ({
367
367
  entries: [
368
368
  ...r.entries.slice(0, -1),
369
- T(n.experienceId, n.node)
369
+ V(n.experienceId, n.node)
370
370
  ]
371
- })), e.on(p, (r, n) => n);
371
+ })), t.on(p, (r, n) => n);
372
372
  function d(r, n) {
373
373
  const c = { lastStepIndex: -1, secondLastStepIndex: -1 };
374
374
  for (let m = r.length - 1; m >= 0; m--) {
375
375
  const S = r[m], a = S == null ? void 0 : S.node;
376
- if (!(!a || !G(a)) && !(n && (S == null ? void 0 : S.experienceId) !== n))
376
+ if (!(!a || !z(a)) && !(n && (S == null ? void 0 : S.experienceId) !== n))
377
377
  if (c.lastStepIndex === -1)
378
378
  c.lastStepIndex = m;
379
379
  else {
@@ -383,25 +383,25 @@ const pe = k(() => {
383
383
  }
384
384
  return c;
385
385
  }
386
- return e.on(g, (r, n) => {
386
+ return t.on(g, (r, n) => {
387
387
  const { secondLastStepIndex: c } = d(r.entries, n.experienceId), m = c !== -1 ? r.entries.slice(0, c + 1) : r.entries;
388
388
  return {
389
389
  ...r,
390
390
  entries: m
391
391
  };
392
392
  }), {
393
- push: t,
393
+ push: e,
394
394
  replace: i,
395
395
  back: g,
396
396
  restore: p,
397
- entriesStore: e.map((r) => r.entries)
397
+ entriesStore: t.map((r) => r.entries)
398
398
  };
399
399
  });
400
- function qe() {
401
- return v(pe);
400
+ function He() {
401
+ return k(de);
402
402
  }
403
- const fe = h("field"), me = k(() => {
404
- const e = fe.store({}), t = b(e, {
403
+ const pe = h("field"), fe = v(() => {
404
+ const t = pe.store({}), e = b(t, {
405
405
  register(r, n) {
406
406
  return {
407
407
  ...r,
@@ -410,14 +410,14 @@ const fe = h("field"), me = k(() => {
410
410
  }
411
411
  });
412
412
  function i(r) {
413
- t.register({ field: r });
413
+ e.register({ field: r });
414
414
  }
415
- const g = e.map((r) => Object.values(r));
415
+ const g = t.map((r) => Object.values(r));
416
416
  function p(r) {
417
- return e.map((n) => n[r] || null);
417
+ return t.map((n) => n[r] || null);
418
418
  }
419
419
  function d(r) {
420
- return e.map((n) => Object.values(n).find((c) => c.name === r) || null);
420
+ return t.map((n) => Object.values(n).find((c) => c.name === r) || null);
421
421
  }
422
422
  return {
423
423
  register: i,
@@ -426,13 +426,13 @@ const fe = h("field"), me = k(() => {
426
426
  getByName: d
427
427
  };
428
428
  });
429
- function ze() {
430
- return v(me);
429
+ function qe() {
430
+ return k(fe);
431
431
  }
432
- const Ge = (e, t) => {
433
- t.register(e);
434
- }, ye = h("action"), Se = k(() => {
435
- const e = ye.store({}), t = b(e, {
432
+ const ze = (t, e) => {
433
+ e.register(t);
434
+ }, me = h("action"), ye = v(() => {
435
+ const t = me.store({}), e = b(t, {
436
436
  register(d, r) {
437
437
  return {
438
438
  ...d,
@@ -444,11 +444,11 @@ const Ge = (e, t) => {
444
444
  }
445
445
  });
446
446
  function i(d, r) {
447
- t.register({ name: d, action: r });
447
+ e.register({ name: d, action: r });
448
448
  }
449
- const g = e.map((d) => Object.values(d));
449
+ const g = t.map((d) => Object.values(d));
450
450
  function p(d) {
451
- return e.map((r) => r[d], { skipVoid: !1 });
451
+ return t.map((r) => r[d], { skipVoid: !1 });
452
452
  }
453
453
  return {
454
454
  register: i,
@@ -456,17 +456,13 @@ const Ge = (e, t) => {
456
456
  listStore: g
457
457
  };
458
458
  });
459
- function Ke() {
460
- return v(Se);
461
- }
462
- const Ye = (e, t, i) => {
463
- i.register(e, t);
464
- };
465
- function N(e) {
466
- return typeof e > "u" || e === null || e === "" || Array.isArray(e) && !e.length;
459
+ function Ge() {
460
+ return k(ye);
467
461
  }
468
- const ke = h("response"), ve = k(({ client: e }) => {
469
- const t = ke.store({}), i = O(), g = O(), p = b(t, {
462
+ const Ke = (t, e, i) => {
463
+ i.register(t, e);
464
+ }, Se = h("response"), ve = v(({ client: t }) => {
465
+ const e = Se.store({}), i = O(), g = O(), p = b(e, {
470
466
  register(o, s) {
471
467
  return {
472
468
  ...o,
@@ -480,7 +476,7 @@ const ke = h("response"), ve = k(({ client: e }) => {
480
476
  };
481
477
  },
482
478
  clear(o, s) {
483
- const { [s]: u, ...f } = o;
479
+ const { [s]: l, ...f } = o;
484
480
  return f;
485
481
  },
486
482
  clearAll() {
@@ -493,88 +489,88 @@ const ke = h("response"), ve = k(({ client: e }) => {
493
489
  async function r(o) {
494
490
  const s = [];
495
491
  return await Promise.allSettled(
496
- Object.entries(o).map(async ([u, f]) => {
497
- let l = f;
498
- const y = e.fields.getById(u).getState();
492
+ Object.entries(o).map(async ([l, f]) => {
493
+ let u = f;
494
+ const y = t.fields.getById(l).getState();
499
495
  if (!y) {
500
496
  s.push({
501
- fieldId: u,
502
- userMessage: `Field '${u}' not found`,
503
- systemMessage: `No field with ID '${u}' exists. Available field IDs are: ${Object.keys(e.fields.listStore.getState()).join(",")}.`,
504
- value: l
497
+ fieldId: l,
498
+ userMessage: `Field '${l}' not found`,
499
+ systemMessage: `No field with ID '${l}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
500
+ value: u
505
501
  });
506
502
  return;
507
503
  }
508
- if (y.multiple && (typeof l == "string" || typeof l == "number" || typeof l == "boolean") && (l = [l]), y.validation && !Y(y.validation) && !N(l)) {
509
- const w = await L(e, y.validation, {
510
- $input: l
504
+ if (y.multiple && (typeof u == "string" || typeof u == "number" || typeof u == "boolean") && (u = [u]), y.validation && !K(y.validation)) {
505
+ const w = await C(t, y.validation, {
506
+ $input: u
511
507
  });
512
508
  if (typeof w == "string") {
513
509
  s.push({
514
- fieldId: u,
510
+ fieldId: l,
515
511
  userMessage: w,
516
512
  systemMessage: `Field validation resulted in an error: ${w}.`,
517
- value: l
513
+ value: u
518
514
  });
519
515
  return;
520
516
  }
521
517
  if (w === !1) {
522
518
  s.push({
523
- fieldId: u,
519
+ fieldId: l,
524
520
  userMessage: "This field is invalid",
525
521
  systemMessage: "Field validation resulted in an unspecified error.",
526
- value: l
522
+ value: u
527
523
  });
528
524
  return;
529
525
  }
530
526
  }
531
- if (y.required && N(l)) {
527
+ if (y.required && (typeof u > "u" || u === null || u === "" || Array.isArray(u) && !u.length)) {
532
528
  s.push({
533
- fieldId: u,
529
+ fieldId: l,
534
530
  userMessage: "This field is required",
535
531
  systemMessage: "Field is required.",
536
- value: l
532
+ value: u
537
533
  });
538
534
  return;
539
535
  }
540
- if (!y.multiple && Array.isArray(l) && l.length > 1) {
536
+ if (!y.multiple && Array.isArray(u) && u.length > 1) {
541
537
  s.push({
542
- fieldId: u,
538
+ fieldId: l,
543
539
  userMessage: "This field expects a single response",
544
540
  systemMessage: "Field expects a single response.",
545
- value: l
541
+ value: u
546
542
  });
547
543
  return;
548
544
  }
549
545
  if (y.options) {
550
- const w = y.options.map((F) => F.value), $ = Array.isArray(l) ? l : [l];
551
- Array.isArray(l) && ($.every((F) => w.includes(F)) || s.push({
552
- fieldId: u,
546
+ const w = y.options.map((F) => F.value), $ = Array.isArray(u) ? u : [u];
547
+ Array.isArray(u) && ($.every((F) => w.includes(F)) || s.push({
548
+ fieldId: l,
553
549
  userMessage: "This field expects a valid option",
554
550
  systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
555
- value: l
551
+ value: u
556
552
  }));
557
553
  }
558
554
  })
559
555
  ), { responsesToCommit: o, validationErrors: s };
560
556
  }
561
557
  async function n(o) {
562
- const { responsesToCommit: s, validationErrors: u } = await r(o);
563
- return u.length ? { errors: u } : (p.registerBatch(s), { errors: [] });
558
+ const { responsesToCommit: s, validationErrors: l } = await r(o);
559
+ return l.length ? { errors: l } : (p.registerBatch(s), { errors: [] });
564
560
  }
565
- const c = t.map((o) => o), m = t.map((o) => Object.keys(o).map((u) => ({
566
- fieldId: u,
567
- value: o[u]
561
+ const c = e.map((o) => o), m = e.map((o) => Object.keys(o).map((l) => ({
562
+ fieldId: l,
563
+ value: o[l]
568
564
  })));
569
565
  function S(o) {
570
- const s = e.fields.getById(o), u = t.map((f) => f[o] || null);
571
- return B({ f: s, r: u }, ({ f, r: l }) => l || (f != null && f.defaultValue ? f.defaultValue : null));
566
+ const s = t.fields.getById(o), l = e.map((f) => f[o] || null);
567
+ return B({ f: s, r: l }, ({ f, r: u }) => u || (f != null && f.defaultValue ? f.defaultValue : null));
572
568
  }
573
569
  function a(o) {
574
- const s = e.fields.getByName(o);
575
- return B({ f: s, s: t }, ({ f: u, s: f }) => {
576
- const l = u && f[u.id] || null;
577
- return l || (u != null && u.defaultValue ? u.defaultValue : null);
570
+ const s = t.fields.getByName(o);
571
+ return B({ f: s, s: e }, ({ f: l, s: f }) => {
572
+ const u = l && f[l.id] || null;
573
+ return u || (l != null && l.defaultValue ? l.defaultValue : null);
578
574
  });
579
575
  }
580
576
  return x({
@@ -595,42 +591,42 @@ const ke = h("response"), ve = k(({ client: e }) => {
595
591
  getByFieldName: a
596
592
  };
597
593
  });
598
- function Je(e) {
599
- return v(ve, e);
594
+ function Ye(t) {
595
+ return k(ve, t);
600
596
  }
601
- function we() {
602
- if (Q())
597
+ function ke() {
598
+ if (J())
603
599
  return crypto.randomUUID();
604
- const e = Date.now().toString(36), t = Math.random().toString(36).substring(2, 15), i = Math.random().toString(36).substring(2, 15), g = Math.random().toString(36).substring(2, 15);
605
- return `${e}-${t}-${i}-${g}`;
600
+ const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), i = Math.random().toString(36).substring(2, 15), g = Math.random().toString(36).substring(2, 15);
601
+ return `${t}-${e}-${i}-${g}`;
606
602
  }
607
- const he = () => ({
608
- id: we()
609
- }), be = R("session", "global"), xe = () => {
610
- if (!J()) return null;
611
- const e = A.get(be);
612
- let t = e.isSet() ? e.json() : null;
613
- return t || (t = he(), e.set(t)), t;
614
- }, Qe = () => xe();
603
+ const we = () => ({
604
+ id: ke()
605
+ }), he = D("session", "global"), be = () => {
606
+ if (!Y()) return null;
607
+ const t = A.get(he);
608
+ let e = t.isSet() ? t.json() : null;
609
+ return e || (e = we(), t.set(e)), e;
610
+ }, Je = () => be();
615
611
  export {
616
- Pe as a,
617
- je as b,
618
- qe as c,
612
+ Me as a,
613
+ Ae as b,
614
+ He as c,
619
615
  Te as d,
620
- Le as e,
621
- Ue as f,
622
- Je as g,
623
- ze as h,
624
- Ke as i,
625
- Qe as j,
626
- Ve as k,
627
- He as l,
628
- _e as m,
629
- Ge as n,
630
- Ye as o,
631
- Ce as p,
632
- Oe as q,
633
- ee as r,
634
- Ne as s,
635
- Me as t
616
+ Ce as e,
617
+ _e as f,
618
+ Ye as g,
619
+ qe as h,
620
+ Ge as i,
621
+ Je as j,
622
+ Pe as k,
623
+ Ue as l,
624
+ Le as m,
625
+ ze as n,
626
+ Ke as o,
627
+ Ne as p,
628
+ je as q,
629
+ Z as r,
630
+ Ve as s,
631
+ Oe as t
636
632
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/client",
3
- "version": "0.0.14-next.2",
3
+ "version": "0.0.14",
4
4
  "dependencies": {
5
5
  "@withease/factories": "^1.0.5"
6
6
  },
@@ -1 +0,0 @@
1
- "use strict";const p=require("effector"),y=require("@withease/factories"),w=require("./experience-instance-B2l_MG7I.cjs"),b=require("./logger-BsmHUUw1.cjs"),x=require("./storage-DuRlyFaY.cjs"),M=require("./id-BKIWbSTy.cjs"),T=require("./object-BbFTsGh3.cjs"),j=require("./supports-YvpQZxbh.cjs"),O=p.createDomain("experience"),V=y.createFactory(({client:e,experience:t})=>{const i=O.store(t),g=p.createApi(i,{merge(c,S){return{...c,...S.experience}}}),m=i.map(c=>({name:c.name,decisionLogic:c.decide,targetSelectors:c.targets,initializeOpenLogic:t.initializeOpen})),d=e.components.listStore.map(c=>c.find(S=>S.name===`experience:${t.id}`)||c.find(S=>S.name==="experience"),{skipVoid:!1}),r=i.map(c=>({steps:c.steps,nodes:c.nodes,edges:c.edges,conditionals:c.conditionals})),n=t.actions??[];return{id:t.id,configStore:m,treeStore:r,componentStore:d,actions:n,merge:g.merge}});function N(e){return y.invoke(V,e)}const C=y.createFactory(({client:e})=>{const t=O.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.id]:n}}});function g(r){const n=t.getState()[r.id];if(n){n.merge({experience:r,strategy:"override"});return}const c=N({client:e,experience:r});i.register(c)}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getById:d,listStore:m}});function L(e){return y.invoke(C,e)}const q=(e,t)=>{t.register(e)},P=(e,t)=>{const{targetSelectors:i}=t.configStore.getState(),g=w.getTargetElements(i,t.id);g.forEach(({elements:d})=>d.forEach(r=>w.tagTargetElement(r,t.id))),w.createAppHosts(g,t.id).forEach(d=>{e.experienceInstances.spawn(t,d)})},_=async e=>{await Promise.all(e.experiences.listStore.getState().map(async t=>{await U(e,t)&&P(e,t)}))},U=async(e,t)=>{const{decisionLogic:i,targetSelectors:g}=t.configStore.getState();return w.getTargetElements(g,t.id).length<1||g.length===0?!1:i&&w.isRulesLogic(i)?await w.evaluateRuleLogic(e,i)===!0:!0},H=p.createDomain("component"),K=y.createFactory(({client:e,component:t,name:i})=>{const g=e.frameworks.getByName(t.frameworkName);return{name:i,component:t,frameworkStore:g}});function z(e){return y.invoke(K,e)}const G=y.createFactory(({client:e})=>{const t=H.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.name]:n}}});function g(r,n){t.getState()[r]&&b.logger("warn",`Component '${r}' already registered. Registering again will override the previous registration.`);const S=z({client:e,name:r,component:n});i.register(S)}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function Y(e){return y.invoke(G,e)}const J=(e,t,i)=>{i.register(e,t)},Q=p.createDomain("framework"),W=y.createFactory(({client:e})=>{const t=Q.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.name]:n.framework}}});function g(r,n){t.getState()[r]&&b.logger("warn",`Framework '${r}' already registered. Registering again will override the previous registration.`),i.register({name:r,framework:n})}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function X(e){return y.invoke(W,e)}const Z=(e,t)=>{t.register(e.name,e)},ee=6e3,D=x.createStorageKey("last_ping","global"),te=e=>`${e}/api/v1/ping`,re=async e=>{try{const t=Date.now(),i=localStorage.getItem(D);if(i&&t-parseInt(i)<ee)return!0;const g=te(e.apiUrl),m={projectId:e.projectId,path:window.location.pathname},d=JSON.stringify(m),r={"Content-Type":"application/json"},n=document.getElementById("picked_script"),c=n==null?void 0:n.dataset.verceltoken;c&&(r["x-vercel-protection-bypass"]=c);const v=(await fetch(g,{method:"POST",headers:r,body:d})).ok;return v&&localStorage.setItem(D,t.toString()),v}catch(t){return b.logger("error",t),!1}},ne=p.createDomain("predicate"),se=y.createFactory(({client:e})=>{const t=ne.store({}),i=p.createApi(t,{register(r,n){return{...r,[n.name]:{name:n.name,predicate:n.predicate}}}});function g(r,n){t.getState()[r]&&b.logger("warn",`Predicate '${r}' already registered. Registering again will override the previous registration.`),i.register(Object.freeze({name:r,predicate:n}))}const m=t.map(r=>Object.values(r));function d(r){return t.map(n=>n[r],{skipVoid:!1})}return{register:g,getByName:d,listStore:m}});function oe(e){return y.invoke(se,e)}const ie=(e,t,i)=>{i.register(e,t)},$=p.createDomain("feature"),ae=y.createFactory(({client:e})=>{const t=$.store({}),i=$.store([]),g=p.createApi(t,{register(a,o){return{...a,[o.id]:o.feature}}});function m(a,o){t.getState()[a]&&b.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const u={id:a,feature:{...o,id:a}};g.register(Object.freeze({id:a,feature:u}))}const d=p.createEffect(async({id:a,key:o,storage:s="local"})=>{const u=x.createStorageKey(`feature:${a}:${o}`,"global"),l=(s==="session"?x.sessionStore:x.localStore).get(u).boolean();return l===null?null:{id:a,key:o,bucket:l}}),r=p.createEffect(a=>{if(!a)return null;const o=x.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?x.sessionStore:x.localStore).set(o,a.bucket)}),n=new Map,c=p.attach({source:{allFeaturesStore:t,resolvedFeaturesStore:i},effect:async({allFeaturesStore:a,resolvedFeaturesStore:o},{id:s,decide:u,key:f})=>{const l=o.find(A=>A.id===s);if(l)return l;const k=a[s];if(!k)throw new Error(`Feature with id '${s}' not found`);const F=n.get(`${s}:${f}`);if(F!==void 0){const A=await F;return{id:k.id,bucket:A,key:f,storage:k.feature.storage}}const E=u();n.set(`${s}:${f}`,E);const I=await E;return{id:k.id,bucket:I,key:f,storage:k.feature.storage}}});p.sample({clock:g.register,fn:a=>{const{id:o,feature:s}=a;return{id:o,key:s.feature.key,storage:s.feature.storage}},target:d}),p.sample({source:t,clock:c.doneData,fn:(a,o)=>{var k;const{id:s,bucket:u,storage:f}=o,l=(k=a[s])==null?void 0:k.feature.key;return l?{key:l,id:s,bucket:u,storage:f}:null},target:r});const S=p.combine({allFeaturesStore:t,resolvedFeaturesStore:i}).map(({allFeaturesStore:a,resolvedFeaturesStore:o})=>Object.values(a).map(s=>{const u=o.find(f=>f.id===s.id);return u?{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:()=>({id:s.id,bucket:u.bucket}),isResolved:!0}:{id:s.id,name:s.feature.name,key:s.feature.key,getBucket:async()=>await c(s.feature),isResolved:!1}}));p.sample({clock:c.doneData,source:{resolvedFeatures:i},filter:({resolvedFeatures:a},{id:o})=>!a.some(s=>s.id===o),fn:(a,o)=>o,target:e.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),p.sample({clock:[d.doneData,c.doneData],source:i,fn:(a,o)=>!o||a.some(s=>s.id===o.id)?a:[...a,o],target:i});function v(a){return t.map(o=>o[a],{skipVoid:!1})}return{register:m,getByName:v,listStore:S}});function ce(e){return y.invoke(ae,e)}const ue=(e,t,i)=>{i.register(e,t)},h=p.createDomain("history");function R(e,t){return{id:M.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:t,at:Date.now(),experienceId:e}}const le=y.createFactory(()=>{const e=h.store({entries:[]}),t=h.event(),i=h.event(),g=h.event(),m=h.event();e.on(t,(r,n)=>({entries:[...r.entries,R(n.experienceId,n.node)]})),e.on(i,(r,n)=>({entries:[...r.entries.slice(0,-1),R(n.experienceId,n.node)]})),e.on(m,(r,n)=>n);function d(r,n){const c={lastStepIndex:-1,secondLastStepIndex:-1};for(let S=r.length-1;S>=0;S--){const v=r[S],a=v==null?void 0:v.node;if(!(!a||!w.isStepNode(a))&&!(n&&(v==null?void 0:v.experienceId)!==n))if(c.lastStepIndex===-1)c.lastStepIndex=S;else{c.secondLastStepIndex=S;break}}return c}return e.on(g,(r,n)=>{const{secondLastStepIndex:c}=d(r.entries,n.experienceId),S=c!==-1?r.entries.slice(0,c+1):r.entries;return{...r,entries:S}}),{push:t,replace:i,back:g,restore:m,entriesStore:e.map(r=>r.entries)}});function ge(){return y.invoke(le)}const de=p.createDomain("field"),pe=y.createFactory(()=>{const e=de.store({}),t=p.createApi(e,{register(r,n){return{...r,[n.field.id]:n.field}}});function i(r){t.register({field:r})}const g=e.map(r=>Object.values(r));function m(r){return e.map(n=>n[r]||null)}function d(r){return e.map(n=>Object.values(n).find(c=>c.name===r)||null)}return{register:i,getById:m,listStore:g,getByName:d}});function me(){return y.invoke(pe)}const fe=(e,t)=>{t.register(e)},ye=p.createDomain("action"),Se=y.createFactory(()=>{const e=ye.store({}),t=p.createApi(e,{register(d,r){return{...d,[r.name]:{name:r.name,action:r.action}}}});function i(d,r){t.register({name:d,action:r})}const g=e.map(d=>Object.values(d));function m(d){return e.map(r=>r[d],{skipVoid:!1})}return{register:i,getByName:m,listStore:g}});function ke(){return y.invoke(Se)}const ve=(e,t,i)=>{i.register(e,t)};function B(e){return typeof e>"u"||e===null||e===""||Array.isArray(e)&&!e.length}const Fe=p.createDomain("response"),xe=y.createFactory(({client:e})=>{const t=Fe.store({}),i=p.createEvent(),g=p.createEvent(),m=p.createApi(t,{register(o,s){return{...o,[s.fieldId]:s.response}},registerBatch(o,s){return{...o,...s}},clear(o,s){const{[s]:u,...f}=o;return f},clearAll(){return{}}});function d(o,s){m.register({fieldId:o,response:s})}async function r(o){const s=[];return await Promise.allSettled(Object.entries(o).map(async([u,f])=>{let l=f;const k=e.fields.getById(u).getState();if(!k){s.push({fieldId:u,userMessage:`Field '${u}' not found`,systemMessage:`No field with ID '${u}' exists. Available field IDs are: ${Object.keys(e.fields.listStore.getState()).join(",")}.`,value:l});return}if(k.multiple&&(typeof l=="string"||typeof l=="number"||typeof l=="boolean")&&(l=[l]),k.validation&&!T.isEmpty(k.validation)&&!B(l)){const F=await w.evaluateRuleLogic(e,k.validation,{$input:l});if(typeof F=="string"){s.push({fieldId:u,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:l});return}if(F===!1){s.push({fieldId:u,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:l});return}}if(k.required&&B(l)){s.push({fieldId:u,userMessage:"This field is required",systemMessage:"Field is required.",value:l});return}if(!k.multiple&&Array.isArray(l)&&l.length>1){s.push({fieldId:u,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:l});return}if(k.options){const F=k.options.map(I=>I.value),E=Array.isArray(l)?l:[l];Array.isArray(l)&&(E.every(I=>F.includes(I))||s.push({fieldId:u,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.join(", ")}`,value:l}))}})),{responsesToCommit:o,validationErrors:s}}async function n(o){const{responsesToCommit:s,validationErrors:u}=await r(o);return u.length?{errors:u}:(m.registerBatch(s),{errors:[]})}const c=t.map(o=>o),S=t.map(o=>Object.keys(o).map(u=>({fieldId:u,value:o[u]})));function v(o){const s=e.fields.getById(o),u=t.map(f=>f[o]||null);return p.combine({f:s,r:u},({f,r:l})=>l||(f!=null&&f.defaultValue?f.defaultValue:null))}function a(o){const s=e.fields.getByName(o);return p.combine({f:s,s:t},({f:u,s:f})=>{const l=u&&f[u.id]||null;return l||(u!=null&&u.defaultValue?u.defaultValue:null)})}return p.sample({clock:i,target:m.clearAll}),p.sample({clock:g,target:m.clear}),{register:d,clearAll:i,clear:g,commit:n,getResponsesToCommit:r,listStore:S,getAllStore:c,getByFieldId:v,getByFieldName:a}});function we(e){return y.invoke(xe,e)}function Ie(){if(j.supportsCryptoRandomUUID())return crypto.randomUUID();const e=Date.now().toString(36),t=Math.random().toString(36).substring(2,15),i=Math.random().toString(36).substring(2,15),g=Math.random().toString(36).substring(2,15);return`${e}-${t}-${i}-${g}`}const he=()=>({id:Ie()}),be=x.createStorageKey("session","global"),Ee=()=>{if(!j.supportsLocalStorage())return null;const e=x.localStore.get(be);let t=e.isSet()?e.json():null;return t||(t=he(),e.set(t)),t},Ae=()=>Ee();exports.createActionIndex=ke;exports.createComponentIndex=Y;exports.createExperienceIndex=L;exports.createFeatureIndex=ce;exports.createFieldIndex=me;exports.createFrameworkIndex=X;exports.createHistory=ge;exports.createPredicateIndex=oe;exports.createResponseIndex=we;exports.initialiseExperience=P;exports.initialiseExperiences=_;exports.initialiseSession=Ae;exports.ping=re;exports.setupAction=ve;exports.setupComponent=J;exports.setupExperience=q;exports.setupFeature=ue;exports.setupField=fe;exports.setupFramework=Z;exports.setupPredicate=ie;