@picked/client 0.0.1-dev.1763356550607 → 0.0.1-dev.1763357104016
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 +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
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 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 v(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 I=()=>S.createEvent(),P=()=>"0.0.1-dev.
|
|
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 v(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 I=()=>S.createEvent(),P=()=>"0.0.1-dev.1763357104016";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",I());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 v(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;
|
package/dist/esm/index.js
CHANGED