@picked/client 0.0.15 → 0.0.16-next.2
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 +5 -5
- 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
|
|
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-X9sLAm_B.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 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.16-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",I());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(),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 v(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;
|
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
|
|
4
|
+
import { c as S, a as x, b as I, d as P, e as v, f as k, 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-CxJHSMaR.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.
|
|
32
|
+
const T = () => W(), V = () => "0.0.16-next.2";
|
|
33
33
|
function G() {
|
|
34
34
|
if (h()) {
|
|
35
35
|
const i = [
|
|
@@ -82,8 +82,8 @@ class g {
|
|
|
82
82
|
n(this, "experienceInstances", K({ client: this }));
|
|
83
83
|
n(this, "experiences", I({ client: this }));
|
|
84
84
|
n(this, "frameworks", P({ client: this }));
|
|
85
|
-
n(this, "predicates",
|
|
86
|
-
n(this, "features",
|
|
85
|
+
n(this, "predicates", v({ client: this }));
|
|
86
|
+
n(this, "features", k({ client: this }));
|
|
87
87
|
n(this, "responses", E({ client: this }));
|
|
88
88
|
n(this, "fields", F());
|
|
89
89
|
n(this, "actions", b());
|
|
@@ -91,7 +91,7 @@ class g {
|
|
|
91
91
|
}
|
|
92
92
|
start() {
|
|
93
93
|
A(this), (async () => {
|
|
94
|
-
h() && (document.body && d(this), await L(),
|
|
94
|
+
h() && (document.body && d(this), await L(), d(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session && this.eventBus({ type: "session", ...this.session }));
|
|
95
95
|
})();
|
|
96
96
|
}
|
|
97
97
|
registerFramework(e) {
|