@picked/client 0.0.42-next.2 → 0.0.42
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 +2 -2
- package/dist/esm/index.js +238 -235
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/utils/events.d.ts +2 -3
- package/dist/types/utils/events.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("effector"),S=require("@withease/factories"),b=require("../experience-instance-D8RtqKEZ.cjs"),E=require("../logger-BsmHUUw1.cjs"),w=require("../storage-Be5xWNPC.cjs"),q=require("../id-BKIWbSTy.cjs"),K=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),M=f.createDomain("experience"),H=S.createFactory(({client:t,experience:e})=>{const r=M.store(e),s=f.createApi(r,{merge(p,h){return{...p,...h.experience}}}),i=r.map(p=>({name:p.name,decisionLogic:p.condition??p.decide,targetSelectors:p.targets,initializeOpenLogic:e.initializeOpen})),l=t.components.listStore.map(p=>p.find(h=>h.name===`experience:${e.id}`)||p.find(h=>h.name==="experience"),{skipVoid:!1}),o=r.map(p=>({steps:p.steps,nodes:p.nodes,edges:p.edges,conditionals:p.conditionals})),n=r.map(p=>p.fields),d=e.actions??[];return{id:e.id,configStore:i,treeStore:o,fieldsStore:n,componentStore:l,actions:d,merge:s.merge}});function J(t){return S.invoke(H,t)}const W=S.createFactory(({client:t})=>{const e=M.store({}),r=f.createApi(e,{register(o,n){return{...o,[n.id]:n}}});function s(o){const n=e.getState()[o.id];if(n){n.merge({experience:o,strategy:"override"});return}const d=J({client:t,experience:o});r.register(d)}const i=e.map(o=>Object.values(o));function l(o){return e.map(n=>n[o],{skipVoid:!1})}return{register:s,getById:l,listStore:i}});function G(t){return S.invoke(W,t)}const Y=(t,e)=>{e.register(t)},V=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),s=b.getTargetElements(r,e.id);s.forEach(({elements:l})=>l.forEach(o=>b.tagTargetElement(o,e.id))),b.createAppHosts(s,e.id).forEach(l=>{t.experienceInstances.spawn(e,l)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await Q(t,e)&&V(t,e)}))},Q=async(t,e)=>{const{decisionLogic:r,targetSelectors:s}=e.configStore.getState();return b.getTargetElements(s,e.id).length<1||s.length===0?!1:r&&b.isRulesLogic(r)?await b.evaluateRuleLogic(t,r)===!0:!0},X=(t,e,r)=>{const s=e.name,i=e.setup(t);if(i){const l=r[s]??{};r[s]=Object.freeze({...l,...i})}},Z=f.createDomain("component"),ee=S.createFactory(({client:t,component:e,name:r})=>{const s=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:s}});function te(t){return S.invoke(ee,t)}const re=S.createFactory(({client:t})=>{const e=Z.store({}),r=f.createApi(e,{register(o,n){return{...o,[n.name]:n}}});function s(o,n){e.getState()[o]&&E.logger("warn",`Component '${o}' already registered. Registering again will override the previous registration.`);const p=te({client:t,name:o,component:n});r.register(p)}const i=e.map(o=>Object.values(o));function l(o){return e.map(n=>n[o],{skipVoid:!1})}return{register:s,getByName:l,listStore:i}});function se(t){return S.invoke(re,t)}const C=(t,e,r)=>{r.register(t,e)},ne=f.createDomain("framework"),ie=S.createFactory(({client:t})=>{const e=ne.store({}),r=f.createApi(e,{register(o,n){return{...o,[n.name]:n.framework}}});function s(o,n){e.getState()[o]&&E.logger("warn",`Framework '${o}' already registered. Registering again will override the previous registration.`),r.register({name:o,framework:n})}const i=e.map(o=>Object.values(o));function l(o){return e.map(n=>n[o],{skipVoid:!1})}return{register:s,getByName:l,listStore:i}});function oe(t){return S.invoke(ie,t)}const ae=(t,e)=>{e.register(t.name,t)},ce=6e3,ue=w.createStorageKey("last_ping","global"),le=t=>`${t}/api/v1/ping`,de=async t=>{try{const e=Date.now(),r=w.localStore.get(ue);let s=0;if(r.isSet()&&(s=r.json()??0),s&&e-s<ce)return!0;const i=le(t.apiUrl),l={projectId:t.projectId,path:window.location.pathname},o=JSON.stringify(l),n={"Content-Type":"application/json"},p=document.getElementById("picked_script")?.dataset.verceltoken;p&&(n["x-vercel-protection-bypass"]=p);const I=(await fetch(i,{method:"POST",headers:n,body:o})).ok;return I&&r.set(e),I}catch(e){return E.logger("error",e),!1}};function T(t){const e=typeof window<"u",r={client:t,responses:t.responses.listStore.getState(),fields:t.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(r)}const pe=f.createDomain("predicate"),ge=S.createFactory(({client:t})=>{const e=pe.store({}),r=f.createApi(e,{register(n,d){return{...n,[d.name]:{name:d.name,predicate:d.predicate}}}});function s(n,d){e.getState()[n]&&E.logger("warn",`Predicate '${n}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:n,predicate:d}))}const i=e.map(n=>Object.values(n));function l(n){return e.map(d=>d[n]?.predicate,{skipVoid:!1})}function o(n){const d=f.createStore(()=>{},{skipVoid:!1}),p=f.createEffect(async()=>{const h=l(n).getState();if(!h)return;const I=T(t);return(...y)=>h({...I,args:y})});return f.sample({source:{responses:t.responses.listStore,fields:t.fields.listStore},target:p}),f.sample({clock:p.doneData,filter:h=>h!==void 0,target:d}),p(),d}return{register:s,getByName:l,listStore:i,getEvokablePredicate:o}});function fe(t){return S.invoke(ge,t)}const me=(t,e,r)=>{r.register(t,e)},$=f.createDomain("feature"),ye=S.createFactory(({client:t})=>{const e=$.store({}),r=$.store([]),s=f.createApi(e,{register(a,c){return{...a,[c.id]:c.feature}}});function i(a,c){e.getState()[a]&&E.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const u={id:a,feature:{...c,id:a}};s.register(Object.freeze({id:a,feature:u}))}const l=f.createEffect(async({id:a,key:c,storage:g="local"})=>{const u=w.createStorageKey(`feature:${a}:${c}`,"global"),v=(g==="session"?w.sessionStore:w.localStore).get(u).boolean();return v===null?null:{id:a,key:c,bucket:v,storage:g}}),o=f.createEffect(a=>{if(!a)return null;const c=w.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?w.sessionStore:w.localStore).set(c,a.bucket)}),n=new Map,d=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:a,resolvedFeaturesStore:c},{id:g,decide:u,key:m})=>{const v=c.find(P=>P.id===g&&P.key===m);if(v)return v;const j=a[g];if(!j)throw new Error(`Feature with id '${g}' not found`);const A=n.get(`${g}:${m}`);if(A!==void 0){const P=await A;return{id:j.id,bucket:P,key:m,storage:j.feature.storage}}const F=u();n.set(`${g}:${m}`,F);const _=await F;return{id:j.id,bucket:_,key:m,storage:j.feature.storage}}});f.sample({clock:s.register,fn:a=>{const{id:c,feature:g}=a;return{id:c,key:g.feature.key,storage:g.feature.storage}},target:l}),f.sample({source:e,clock:d.doneData,fn:(a,c)=>{const{id:g,bucket:u,storage:m}=c,v=a[g]?.feature.key;return v?{key:v,id:g,bucket:u,storage:m}:null},target:o});const p=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:a,resolvedFeaturesStore:c})=>Object.values(a).map(g=>{const u=c.find(m=>m.id===g.id&&m.key===g.feature.key);return u?{id:g.id,name:g.feature.name,key:g.feature.key,getBucket:()=>({id:g.id,bucket:u.bucket}),isResolved:!0}:{id:g.id,name:g.feature.name,key:g.feature.key,getBucket:async()=>await d(g.feature),isResolved:!1}}));f.sample({clock:d.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:a},{id:c,key:g})=>!a.some(m=>m.id===c&&m.key===g),fn:(a,c)=>c,target:t.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),f.sample({clock:[l.doneData,d.doneData],source:r,fn:(a,c)=>!c||a.some(u=>u.id===c.id&&u.key===c.key)?a:[...a,c],target:r});function h(a){return p.map(c=>c.find(g=>g.id===a))}function I(a){return e.map(c=>c[a],{skipVoid:!1})}function y(a){const c=f.createStore(async()=>{},{skipVoid:!1}),g=f.createEffect(async()=>{const u=h(a).getState();if(u)return async()=>(await u.getBucket()).bucket});return f.sample({source:r,filter:u=>u.some(m=>m.id===a),target:g}),f.sample({clock:g.doneData,filter:u=>u!==void 0,target:c}),g(),c}return{register:i,getById:h,getByName:I,listStore:p,getEvokableFeature:y}});function he(t){return S.invoke(ye,t)}const Se=(t,e,r)=>{r.register(t,e)},x=f.createDomain("history");function O(t,e){return{id:q.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ve=S.createFactory(()=>{const t=x.store({entries:[]}),e=x.event(),r=x.event(),s=x.event(),i=x.event();t.on(e,(o,n)=>({entries:[...o.entries,O(n.experienceId,n.node)]})),t.on(r,(o,n)=>({entries:[...o.entries.slice(0,-1),O(n.experienceId,n.node)]})),t.on(i,(o,n)=>n);function l(o,n){const d={lastStepIndex:-1,secondLastStepIndex:-1};for(let p=o.length-1;p>=0;p--){const h=o[p],I=h?.node;if(!(!I||!b.isStepNode(I))&&!(n&&h?.experienceId!==n))if(d.lastStepIndex===-1)d.lastStepIndex=p;else{d.secondLastStepIndex=p;break}}return d}return t.on(s,(o,n)=>{const{secondLastStepIndex:d}=l(o.entries,n.experienceId),p=d!==-1?o.entries.slice(0,d+1):o.entries;return{...o,entries:p}}),{push:e,replace:r,back:s,restore:i,entriesStore:t.map(o=>o.entries)}});function ke(){return S.invoke(ve)}let we=0;const be=t=>{const e=f.createStore([]);return f.sample({clock:t,source:e,fn:(r,s)=>[...r,{id:we++,at:new Date,payload:s}],target:e}),e},Fe=f.createDomain("field"),Ie=S.createFactory(()=>{const t=Fe.store({}),e=f.createApi(t,{register(n,d){return{...n,[d.field.id]:d.field}}});function r(n){e.register({field:n})}function s(n,d){const p=l(n).getState();if(!p)return;const h=Object.assign({},p,{...d});e.register({field:{...h}})}const i=t.map(n=>Object.values(n));function l(n){return t.map(d=>d[n]||null)}function o(n){return t.map(d=>Object.values(d).find(p=>p.name===n)||null)}return{register:r,update:s,getById:l,listStore:i,getByName:o}});function Ee(){return S.invoke(Ie)}const je=(t,e)=>{e.register(t)},xe=f.createDomain("action"),Ae=S.createFactory(()=>{const t=xe.store({}),e=f.createApi(t,{register(o,n){return{...o,[n.name]:{name:n.name,action:n.action}}}});function r(o,n){e.register({name:o,action:n})}const s=t.map(o=>Object.values(o));function i(o){return t.map(n=>n[o],{skipVoid:!1})}function l(o){return t.map(n=>{const d=n[o];return d?d.action:void 0},{skipVoid:!1})}return{register:r,getByName:i,listStore:s,getEvokableAction:l}});function Pe(){return S.invoke(Ae)}const Re=(t,e,r)=>{r.register(t,e)};function D(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}function De(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null}function z(t){try{return JSON.stringify(t),!0}catch{return!1}}const Be=f.createDomain("response"),Ce=S.createFactory(({client:t})=>{const e=Be.store({}),r=f.createEvent(),s=f.createEvent(),i=f.createApi(e,{register(y,a){return{...y,[a.fieldId]:a.response}},registerBatch(y,a){return{...y,...a}},clear(y,a){const{[a]:c,...g}=y;return g},clearAll(){return{}}});function l(y,a){if(typeof y=="string"){if(a===void 0)throw new Error("Response is required when registering a single field");i.register({fieldId:y,response:a})}else i.registerBatch(y)}async function o(y){const a=[];return await Promise.allSettled(Object.entries(y).map(async([c,g])=>{let u=g;const m=t.fields.getById(c).getState();if(!m){a.push({fieldId:c,userMessage:`Field '${c}' not found`,systemMessage:`No field with ID '${c}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:u});return}if(m.multiple&&(typeof u=="string"||typeof u=="number"||typeof u=="boolean")&&(u=[u]),m.validation&&!K.isEmpty(m.validation)&&!D(u)){const v=await b.evaluateRuleLogic(t,m.validation,{$input:u});if(typeof v=="string"){a.push({fieldId:c,userMessage:v,systemMessage:`Field validation resulted in an error: ${v}.`,value:u});return}if(v===!1){a.push({fieldId:c,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:u});return}}if(m.required&&D(u)){a.push({fieldId:c,userMessage:"This field is required",systemMessage:"Field is required.",value:u});return}if(!m.multiple&&Array.isArray(u)&&u.length>1){a.push({fieldId:c,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:u});return}if(m.type==="object"&&!D(u))if(m.multiple){if(!Array.isArray(u)){a.push({fieldId:c,userMessage:"This field expects multiple values",systemMessage:"Field expects an array of objects.",value:u});return}for(const v of u){if(typeof v!="object"||v===null){a.push({fieldId:c,userMessage:"This field expects object values",systemMessage:"Field expects an array of objects, but received non-object value.",value:u});return}if(!z(v)){a.push({fieldId:c,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:u});return}}}else{if(Array.isArray(u)){a.push({fieldId:c,userMessage:"This field expects a single value",systemMessage:"Field expects a single object, not an array.",value:u});return}if(typeof u!="object"||u===null){a.push({fieldId:c,userMessage:"This field expects an object value",systemMessage:"Field expects an object value.",value:u});return}if(!z(u)){a.push({fieldId:c,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:u});return}}if(m.options){const v=Array.isArray(u)?u:[u];if(m.type==="object"){const j=m.options.map(F=>JSON.stringify(F.value));v.every(F=>j.includes(JSON.stringify(F)))||a.push({fieldId:c,userMessage:"This field expects a valid option",systemMessage:"Field expects a valid option from the defined choices.",value:u})}else{const j=m.options.map(F=>F.value);v.every(F=>!De(F)||F===null?!1:j.includes(F))||a.push({fieldId:c,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${j.join(", ")}`,value:u})}}})),{responsesToCommit:y,validationErrors:a}}async function n(y){const{responsesToCommit:a,validationErrors:c}=await o(y);return c.length?{errors:c}:(i.registerBatch(a),{errors:[]})}const d=e.map(y=>y),p=e.map(y=>Object.keys(y).map(c=>({fieldId:c,value:y[c]})));function h(y){const a=t.fields.getById(y),c=e.map(g=>g[y]||null);return f.combine({f:a,r:c},({f:g,r:u})=>u||(g?.defaultValue?g.defaultValue:null))}function I(y){const a=t.fields.getByName(y);return f.combine({f:a,s:e},({f:c,s:g})=>{const u=c&&g[c.id]||null;return u||(c?.defaultValue?c.defaultValue:null)})}return f.sample({clock:r,target:i.clearAll}),f.sample({clock:s,target:i.clear}),{register:l,clearAll:r,clear:s,commit:n,getResponsesToCommit:o,listStore:p,getAllStore:d,getByFieldId:h,getByFieldName:I}});function $e(t){return S.invoke(Ce,t)}const Oe=()=>"0.0.42-next.2";function ze(){if(k.supportsDocument()){const t=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of t)if(e?.dataset.api)return e.dataset.api}return"https://api.picked.app"}function Me(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[i]of t.entries())i.startsWith("picked-")&&r.add(i);for(const i of r){const l=i.replace("picked-","");e[l]=t.getAll(i)}const s=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(s,e);else{const i=w.sessionStore.get(s);if(i)return i.json()||{}}return e}function Ve(){if(k.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),r=Math.random().toString(36).substring(2,15),s=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${s}`}const Te=w.createStorageKey("session","global"),Ue=()=>{const t=w.localStore.get(Te);let e;t.isSet()&&(e=t.json());const r=i=>t.set({id:i.id,isUser:i.isUser,identifiers:i.identifiers}),s={id:e?.id??Ve(),isUser:e?.isUser??void 0,identifiers:e?.identifiers??void 0,setIsUser(i){this.isUser=i,r(this)},setIdentifier(i,l){this.identifiers={...this.identifiers,[i]:l},r(this)},removeIdentifier(i){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([l])=>l!==i)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(s),s},Le=()=>k.supportsLocalStorage()?Ue():null;function U(){if(k.supportsWindow())return globalThis.window.pickedConfig}function Ne(){if(!k.supportsWindow())return;const t=U(),e=t?.organizationId,r=t?.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function _e(){if(!k.supportsDocument())return;const t=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!t)return;const e=t.dataset.organizationid||t.getAttribute("organization-id"),r=t.dataset.projectid||t.getAttribute("project-id");return e&&r?{organizationId:e,projectId:r}:void 0}function qe(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const s=Ne();if(s)return s;const i=_e();if(i)return i;throw new Error(`organizationId and projectId are required. You can provide them via one of:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("effector"),S=require("@withease/factories"),b=require("../experience-instance-D8RtqKEZ.cjs"),E=require("../logger-BsmHUUw1.cjs"),w=require("../storage-Be5xWNPC.cjs"),q=require("../id-BKIWbSTy.cjs"),K=require("../object-BbFTsGh3.cjs"),k=require("../supports-YvpQZxbh.cjs"),M=f.createDomain("experience"),H=S.createFactory(({client:t,experience:e})=>{const r=M.store(e),s=f.createApi(r,{merge(p,h){return{...p,...h.experience}}}),i=r.map(p=>({name:p.name,decisionLogic:p.condition??p.decide,targetSelectors:p.targets,initializeOpenLogic:e.initializeOpen})),l=t.components.listStore.map(p=>p.find(h=>h.name===`experience:${e.id}`)||p.find(h=>h.name==="experience"),{skipVoid:!1}),o=r.map(p=>({steps:p.steps,nodes:p.nodes,edges:p.edges,conditionals:p.conditionals})),n=r.map(p=>p.fields),d=e.actions??[];return{id:e.id,configStore:i,treeStore:o,fieldsStore:n,componentStore:l,actions:d,merge:s.merge}});function J(t){return S.invoke(H,t)}const W=S.createFactory(({client:t})=>{const e=M.store({}),r=f.createApi(e,{register(o,n){return{...o,[n.id]:n}}});function s(o){const n=e.getState()[o.id];if(n){n.merge({experience:o,strategy:"override"});return}const d=J({client:t,experience:o});r.register(d)}const i=e.map(o=>Object.values(o));function l(o){return e.map(n=>n[o],{skipVoid:!1})}return{register:s,getById:l,listStore:i}});function G(t){return S.invoke(W,t)}const Y=(t,e)=>{e.register(t)},U=(t,e)=>{const{targetSelectors:r}=e.configStore.getState(),s=b.getTargetElements(r,e.id);s.forEach(({elements:l})=>l.forEach(o=>b.tagTargetElement(o,e.id))),b.createAppHosts(s,e.id).forEach(l=>{t.experienceInstances.spawn(e,l)})},B=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await Q(t,e)&&U(t,e)}))},Q=async(t,e)=>{const{decisionLogic:r,targetSelectors:s}=e.configStore.getState();return b.getTargetElements(s,e.id).length<1||s.length===0?!1:r&&b.isRulesLogic(r)?await b.evaluateRuleLogic(t,r)===!0:!0},X=(t,e,r)=>{const s=e.name,i=e.setup(t);if(i){const l=r[s]??{};r[s]=Object.freeze({...l,...i})}},Z=f.createDomain("component"),ee=S.createFactory(({client:t,component:e,name:r})=>{const s=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:s}});function te(t){return S.invoke(ee,t)}const re=S.createFactory(({client:t})=>{const e=Z.store({}),r=f.createApi(e,{register(o,n){return{...o,[n.name]:n}}});function s(o,n){e.getState()[o]&&E.logger("warn",`Component '${o}' already registered. Registering again will override the previous registration.`);const p=te({client:t,name:o,component:n});r.register(p)}const i=e.map(o=>Object.values(o));function l(o){return e.map(n=>n[o],{skipVoid:!1})}return{register:s,getByName:l,listStore:i}});function se(t){return S.invoke(re,t)}const C=(t,e,r)=>{r.register(t,e)},ne=f.createDomain("framework"),ie=S.createFactory(({client:t})=>{const e=ne.store({}),r=f.createApi(e,{register(o,n){return{...o,[n.name]:n.framework}}});function s(o,n){e.getState()[o]&&E.logger("warn",`Framework '${o}' already registered. Registering again will override the previous registration.`),r.register({name:o,framework:n})}const i=e.map(o=>Object.values(o));function l(o){return e.map(n=>n[o],{skipVoid:!1})}return{register:s,getByName:l,listStore:i}});function oe(t){return S.invoke(ie,t)}const ae=(t,e)=>{e.register(t.name,t)},ce=6e3,ue=w.createStorageKey("last_ping","global"),le=t=>`${t}/api/v1/ping`,de=async t=>{try{const e=Date.now(),r=w.localStore.get(ue);let s=0;if(r.isSet()&&(s=r.json()??0),s&&e-s<ce)return!0;const i=le(t.apiUrl),l={projectId:t.projectId,path:window.location.pathname},o=JSON.stringify(l),n={"Content-Type":"application/json"},p=document.getElementById("picked_script")?.dataset.verceltoken;p&&(n["x-vercel-protection-bypass"]=p);const I=(await fetch(i,{method:"POST",headers:n,body:o})).ok;return I&&r.set(e),I}catch(e){return E.logger("error",e),!1}};function V(t){const e=typeof window<"u",r={client:t,responses:t.responses.listStore.getState(),fields:t.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(r)}const pe=f.createDomain("predicate"),ge=S.createFactory(({client:t})=>{const e=pe.store({}),r=f.createApi(e,{register(n,d){return{...n,[d.name]:{name:d.name,predicate:d.predicate}}}});function s(n,d){e.getState()[n]&&E.logger("warn",`Predicate '${n}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:n,predicate:d}))}const i=e.map(n=>Object.values(n));function l(n){return e.map(d=>d[n]?.predicate,{skipVoid:!1})}function o(n){const d=f.createStore(()=>{},{skipVoid:!1}),p=f.createEffect(async()=>{const h=l(n).getState();if(!h)return;const I=V(t);return(...y)=>h({...I,args:y})});return f.sample({source:{responses:t.responses.listStore,fields:t.fields.listStore},target:p}),f.sample({clock:p.doneData,filter:h=>h!==void 0,target:d}),p(),d}return{register:s,getByName:l,listStore:i,getEvokablePredicate:o}});function fe(t){return S.invoke(ge,t)}const me=(t,e,r)=>{r.register(t,e)},$=f.createDomain("feature"),ye=S.createFactory(({client:t})=>{const e=$.store({}),r=$.store([]),s=f.createApi(e,{register(a,c){return{...a,[c.id]:c.feature}}});function i(a,c){e.getState()[a]&&E.logger("warn",`Feature '${a}' already registered. Registering again will override the previous registration.`);const u={id:a,feature:{...c,id:a}};s.register(Object.freeze({id:a,feature:u}))}const l=f.createEffect(async({id:a,key:c,storage:g="local"})=>{const u=w.createStorageKey(`feature:${a}:${c}`,"global"),v=(g==="session"?w.sessionStore:w.localStore).get(u).boolean();return v===null?null:{id:a,key:c,bucket:v,storage:g}}),o=f.createEffect(a=>{if(!a)return null;const c=w.createStorageKey(`feature:${a.id}:${a.key}`,"global");(a.storage==="session"?w.sessionStore:w.localStore).set(c,a.bucket)}),n=new Map,d=f.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:a,resolvedFeaturesStore:c},{id:g,decide:u,key:m})=>{const v=c.find(P=>P.id===g&&P.key===m);if(v)return v;const j=a[g];if(!j)throw new Error(`Feature with id '${g}' not found`);const A=n.get(`${g}:${m}`);if(A!==void 0){const P=await A;return{id:j.id,bucket:P,key:m,storage:j.feature.storage}}const F=u();n.set(`${g}:${m}`,F);const _=await F;return{id:j.id,bucket:_,key:m,storage:j.feature.storage}}});f.sample({clock:s.register,fn:a=>{const{id:c,feature:g}=a;return{id:c,key:g.feature.key,storage:g.feature.storage}},target:l}),f.sample({source:e,clock:d.doneData,fn:(a,c)=>{const{id:g,bucket:u,storage:m}=c,v=a[g]?.feature.key;return v?{key:v,id:g,bucket:u,storage:m}:null},target:o});const p=f.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:a,resolvedFeaturesStore:c})=>Object.values(a).map(g=>{const u=c.find(m=>m.id===g.id&&m.key===g.feature.key);return u?{id:g.id,name:g.feature.name,key:g.feature.key,getBucket:()=>({id:g.id,bucket:u.bucket}),isResolved:!0}:{id:g.id,name:g.feature.name,key:g.feature.key,getBucket:async()=>await d(g.feature),isResolved:!1}}));f.sample({clock:d.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:a},{id:c,key:g})=>!a.some(m=>m.id===c&&m.key===g),fn:(a,c)=>c,target:t.eventBus.prepend(a=>({type:"feature_decide",feature:a}))}),f.sample({clock:[l.doneData,d.doneData],source:r,fn:(a,c)=>!c||a.some(u=>u.id===c.id&&u.key===c.key)?a:[...a,c],target:r});function h(a){return p.map(c=>c.find(g=>g.id===a))}function I(a){return e.map(c=>c[a],{skipVoid:!1})}function y(a){const c=f.createStore(async()=>{},{skipVoid:!1}),g=f.createEffect(async()=>{const u=h(a).getState();if(u)return async()=>(await u.getBucket()).bucket});return f.sample({source:r,filter:u=>u.some(m=>m.id===a),target:g}),f.sample({clock:g.doneData,filter:u=>u!==void 0,target:c}),g(),c}return{register:i,getById:h,getByName:I,listStore:p,getEvokableFeature:y}});function he(t){return S.invoke(ye,t)}const Se=(t,e,r)=>{r.register(t,e)},x=f.createDomain("history");function O(t,e){return{id:q.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ve=S.createFactory(()=>{const t=x.store({entries:[]}),e=x.event(),r=x.event(),s=x.event(),i=x.event();t.on(e,(o,n)=>({entries:[...o.entries,O(n.experienceId,n.node)]})),t.on(r,(o,n)=>({entries:[...o.entries.slice(0,-1),O(n.experienceId,n.node)]})),t.on(i,(o,n)=>n);function l(o,n){const d={lastStepIndex:-1,secondLastStepIndex:-1};for(let p=o.length-1;p>=0;p--){const h=o[p],I=h?.node;if(!(!I||!b.isStepNode(I))&&!(n&&h?.experienceId!==n))if(d.lastStepIndex===-1)d.lastStepIndex=p;else{d.secondLastStepIndex=p;break}}return d}return t.on(s,(o,n)=>{const{secondLastStepIndex:d}=l(o.entries,n.experienceId),p=d!==-1?o.entries.slice(0,d+1):o.entries;return{...o,entries:p}}),{push:e,replace:r,back:s,restore:i,entriesStore:t.map(o=>o.entries)}});function ke(){return S.invoke(ve)}let we=0;const be=t=>{const e=f.createStore([]);return f.sample({clock:t,source:e,fn:(r,s)=>[...r,{id:we++,at:new Date,payload:s}],target:e}),e},Fe=f.createDomain("field"),Ie=S.createFactory(()=>{const t=Fe.store({}),e=f.createApi(t,{register(n,d){return{...n,[d.field.id]:d.field}}});function r(n){e.register({field:n})}function s(n,d){const p=l(n).getState();if(!p)return;const h=Object.assign({},p,{...d});e.register({field:{...h}})}const i=t.map(n=>Object.values(n));function l(n){return t.map(d=>d[n]||null)}function o(n){return t.map(d=>Object.values(d).find(p=>p.name===n)||null)}return{register:r,update:s,getById:l,listStore:i,getByName:o}});function Ee(){return S.invoke(Ie)}const je=(t,e)=>{e.register(t)},xe=f.createDomain("action"),Ae=S.createFactory(()=>{const t=xe.store({}),e=f.createApi(t,{register(o,n){return{...o,[n.name]:{name:n.name,action:n.action}}}});function r(o,n){e.register({name:o,action:n})}const s=t.map(o=>Object.values(o));function i(o){return t.map(n=>n[o],{skipVoid:!1})}function l(o){return t.map(n=>{const d=n[o];return d?d.action:void 0},{skipVoid:!1})}return{register:r,getByName:i,listStore:s,getEvokableAction:l}});function Pe(){return S.invoke(Ae)}const Re=(t,e,r)=>{r.register(t,e)};function D(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}function De(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null}function z(t){try{return JSON.stringify(t),!0}catch{return!1}}const Be=f.createDomain("response"),Ce=S.createFactory(({client:t})=>{const e=Be.store({}),r=f.createEvent(),s=f.createEvent(),i=f.createApi(e,{register(y,a){return{...y,[a.fieldId]:a.response}},registerBatch(y,a){return{...y,...a}},clear(y,a){const{[a]:c,...g}=y;return g},clearAll(){return{}}});function l(y,a){if(typeof y=="string"){if(a===void 0)throw new Error("Response is required when registering a single field");i.register({fieldId:y,response:a})}else i.registerBatch(y)}async function o(y){const a=[];return await Promise.allSettled(Object.entries(y).map(async([c,g])=>{let u=g;const m=t.fields.getById(c).getState();if(!m){a.push({fieldId:c,userMessage:`Field '${c}' not found`,systemMessage:`No field with ID '${c}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:u});return}if(m.multiple&&(typeof u=="string"||typeof u=="number"||typeof u=="boolean")&&(u=[u]),m.validation&&!K.isEmpty(m.validation)&&!D(u)){const v=await b.evaluateRuleLogic(t,m.validation,{$input:u});if(typeof v=="string"){a.push({fieldId:c,userMessage:v,systemMessage:`Field validation resulted in an error: ${v}.`,value:u});return}if(v===!1){a.push({fieldId:c,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:u});return}}if(m.required&&D(u)){a.push({fieldId:c,userMessage:"This field is required",systemMessage:"Field is required.",value:u});return}if(!m.multiple&&Array.isArray(u)&&u.length>1){a.push({fieldId:c,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:u});return}if(m.type==="object"&&!D(u))if(m.multiple){if(!Array.isArray(u)){a.push({fieldId:c,userMessage:"This field expects multiple values",systemMessage:"Field expects an array of objects.",value:u});return}for(const v of u){if(typeof v!="object"||v===null){a.push({fieldId:c,userMessage:"This field expects object values",systemMessage:"Field expects an array of objects, but received non-object value.",value:u});return}if(!z(v)){a.push({fieldId:c,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:u});return}}}else{if(Array.isArray(u)){a.push({fieldId:c,userMessage:"This field expects a single value",systemMessage:"Field expects a single object, not an array.",value:u});return}if(typeof u!="object"||u===null){a.push({fieldId:c,userMessage:"This field expects an object value",systemMessage:"Field expects an object value.",value:u});return}if(!z(u)){a.push({fieldId:c,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:u});return}}if(m.options){const v=Array.isArray(u)?u:[u];if(m.type==="object"){const j=m.options.map(F=>JSON.stringify(F.value));v.every(F=>j.includes(JSON.stringify(F)))||a.push({fieldId:c,userMessage:"This field expects a valid option",systemMessage:"Field expects a valid option from the defined choices.",value:u})}else{const j=m.options.map(F=>F.value);v.every(F=>!De(F)||F===null?!1:j.includes(F))||a.push({fieldId:c,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${j.join(", ")}`,value:u})}}})),{responsesToCommit:y,validationErrors:a}}async function n(y){const{responsesToCommit:a,validationErrors:c}=await o(y);return c.length?{errors:c}:(i.registerBatch(a),{errors:[]})}const d=e.map(y=>y),p=e.map(y=>Object.keys(y).map(c=>({fieldId:c,value:y[c]})));function h(y){const a=t.fields.getById(y),c=e.map(g=>g[y]||null);return f.combine({f:a,r:c},({f:g,r:u})=>u||(g?.defaultValue?g.defaultValue:null))}function I(y){const a=t.fields.getByName(y);return f.combine({f:a,s:e},({f:c,s:g})=>{const u=c&&g[c.id]||null;return u||(c?.defaultValue?c.defaultValue:null)})}return f.sample({clock:r,target:i.clearAll}),f.sample({clock:s,target:i.clear}),{register:l,clearAll:r,clear:s,commit:n,getResponsesToCommit:o,listStore:p,getAllStore:d,getByFieldId:h,getByFieldName:I}});function $e(t){return S.invoke(Ce,t)}const Oe=()=>"0.0.42";function ze(){if(k.supportsDocument()){const t=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const e of t)if(e?.dataset.api)return e.dataset.api}return"https://api.picked.app"}function Me(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[i]of t.entries())i.startsWith("picked-")&&r.add(i);for(const i of r){const l=i.replace("picked-","");e[l]=t.getAll(i)}const s=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(s,e);else{const i=w.sessionStore.get(s);if(i)return i.json()||{}}return e}function Ue(){if(k.supportsCryptoRandomUUID())return crypto.randomUUID();const t=Date.now().toString(36),e=Math.random().toString(36).substring(2,15),r=Math.random().toString(36).substring(2,15),s=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${s}`}const Ve=w.createStorageKey("session","global"),Te=()=>{const t=w.localStore.get(Ve);let e;t.isSet()&&(e=t.json());const r=i=>t.set({id:i.id,isUser:i.isUser,identifiers:i.identifiers}),s={id:e?.id??Ue(),isUser:e?.isUser??void 0,identifiers:e?.identifiers??void 0,setIsUser(i){this.isUser=i,r(this)},setIdentifier(i,l){this.identifiers={...this.identifiers,[i]:l},r(this)},removeIdentifier(i){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([l])=>l!==i)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(s),s},Le=()=>k.supportsLocalStorage()?Te():null;function T(){if(k.supportsWindow())return globalThis.window.pickedConfig}function Ne(){if(!k.supportsWindow())return;const t=T(),e=t?.organizationId,r=t?.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function _e(){if(!k.supportsDocument())return;const t=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!t)return;const e=t.dataset.organizationid||t.getAttribute("organization-id"),r=t.dataset.projectid||t.getAttribute("project-id");return e&&r?{organizationId:e,projectId:r}:void 0}function qe(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const s=Ne();if(s)return s;const i=_e();if(i)return i;throw new Error(`organizationId and projectId are required. You can provide them via one of:
|
|
2
2
|
(1) createClient({ organizationId, projectId }) options;
|
|
3
3
|
(2) window.pickedConfig = { organizationId, projectId };
|
|
4
|
-
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`)}function R(t){return t==null||t===""||Number.isNaN(t)}const Ke={default:(t,e)=>R(t)?String(e??""):String(t),append:(t,e)=>e&&!R(t)?`${t} ${e}`:t,prepend:(t,e)=>e&&!R(t)?`${e} ${t}`:t,upper:t=>typeof t=="string"?t.toUpperCase():t,lower:t=>typeof t=="string"?t.toLowerCase():t,capitalize:t=>typeof t=="string"?t.charAt(0).toUpperCase()+t.slice(1):t,list:t=>{if(!t||typeof t!="object")return t;const e=new Intl.ListFormat("en",{style:"long",type:"conjunction"});if(Array.isArray(t))return e.format(t.map(String));if(t instanceof Map){const r=Array.from(t.entries()).map(([s,i])=>`${s}: ${i}`);return e.format(r)}return t instanceof Set?e.format(Array.from(t).map(String)):t}};function He(t){return typeof t=="object"&&t!==null}function Je(t,e){let r=e;for(const s of t.split("."))if(He(r)&&s in r)r=r[s];else return;return typeof r=="function"?r():r}function We(t,e){const r=t.split("|").map(l=>l.trim()),s=r.shift()??"";let i=Je(s,e);for(const l of r){const[o,...n]=l.split(":"),d=o?.trim()??"",p=n.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g,""),h=Ke[d];h&&(i=h(i,p))}return R(i)?"":typeof i=="object"?JSON.stringify(i):String(i)}function Ge(t,e){let r="",s=0;for(;s<t.length;)if(t[s]==="{"&&t[s+1]==="{"){s+=2;let i="";for(;s<t.length;){if(t[s]==="}"&&t[s+1]==="}"){s+=2;break}i+=t[s++]}r+=We(i.trim(),e)}else r+=t[s++];return r}class L{static logger=E.logger;options;isReady=!1;project;plugins={};eventBus=f.createEvent();events;organizationId;projectId;apiUrl;session;precondition;condition;searchParams=Me();history=ke();components=se({client:this});experienceInstances=b.createExperienceInstanceIndex({client:this});experiences=G({client:this});frameworks=oe({client:this});predicates=fe({client:this});features=he({client:this});responses=$e({client:this});fields=Ee();actions=Pe();constructor(e){E.logger("info","Picked client initializing."),this.events=be(this.eventBus);const{organizationId:r,projectId:s}=qe(e);this.organizationId=r,this.projectId=s,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||ze(),this.session=Le(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:Oe()}),E.logger("info","Picked client initialized.")}start=()=>{de(this),(async()=>{if(!k.supportsDocument())return;let r;typeof this.precondition>"u"?r=!0:typeof this.precondition=="boolean"?r=this.precondition:r=await b.evaluateRuleLogic(this,this.precondition)===!0;let s;r&&(this.condition===void 0?s=!0:typeof this.condition=="boolean"?s=this.condition:s=await b.evaluateRuleLogic(this,this.condition)===!0);const i=r&&s===!0;if(typeof s=="boolean"&&this.session){const l=s;this.session.setIsUser(l),this.eventBus({type:"user_decide",value:l})}this.eventBus({type:"initialize"}),document.body&&i&&B(this),await b.domInteractive(),i&&B(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session
|
|
4
|
+
(3) a <script> tag with id 'picked_script', 'picked', or 'cvly' that includes data-organizationid/data-projectid (or organization-id/project-id) attributes.`)}function R(t){return t==null||t===""||Number.isNaN(t)}const Ke={default:(t,e)=>R(t)?String(e??""):String(t),append:(t,e)=>e&&!R(t)?`${t} ${e}`:t,prepend:(t,e)=>e&&!R(t)?`${e} ${t}`:t,upper:t=>typeof t=="string"?t.toUpperCase():t,lower:t=>typeof t=="string"?t.toLowerCase():t,capitalize:t=>typeof t=="string"?t.charAt(0).toUpperCase()+t.slice(1):t,list:t=>{if(!t||typeof t!="object")return t;const e=new Intl.ListFormat("en",{style:"long",type:"conjunction"});if(Array.isArray(t))return e.format(t.map(String));if(t instanceof Map){const r=Array.from(t.entries()).map(([s,i])=>`${s}: ${i}`);return e.format(r)}return t instanceof Set?e.format(Array.from(t).map(String)):t}};function He(t){return typeof t=="object"&&t!==null}function Je(t,e){let r=e;for(const s of t.split("."))if(He(r)&&s in r)r=r[s];else return;return typeof r=="function"?r():r}function We(t,e){const r=t.split("|").map(l=>l.trim()),s=r.shift()??"";let i=Je(s,e);for(const l of r){const[o,...n]=l.split(":"),d=o?.trim()??"",p=n.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g,""),h=Ke[d];h&&(i=h(i,p))}return R(i)?"":typeof i=="object"?JSON.stringify(i):String(i)}function Ge(t,e){let r="",s=0;for(;s<t.length;)if(t[s]==="{"&&t[s+1]==="{"){s+=2;let i="";for(;s<t.length;){if(t[s]==="}"&&t[s+1]==="}"){s+=2;break}i+=t[s++]}r+=We(i.trim(),e)}else r+=t[s++];return r}class L{static logger=E.logger;options;isReady=!1;project;plugins={};eventBus=f.createEvent();events;organizationId;projectId;apiUrl;session;precondition;condition;searchParams=Me();history=ke();components=se({client:this});experienceInstances=b.createExperienceInstanceIndex({client:this});experiences=G({client:this});frameworks=oe({client:this});predicates=fe({client:this});features=he({client:this});responses=$e({client:this});fields=Ee();actions=Pe();constructor(e){E.logger("info","Picked client initializing."),this.events=be(this.eventBus);const{organizationId:r,projectId:s}=qe(e);this.organizationId=r,this.projectId=s,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||ze(),this.session=Le(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:Oe()}),E.logger("info","Picked client initialized.")}start=()=>{de(this),(async()=>{if(!k.supportsDocument())return;let r;typeof this.precondition>"u"?r=!0:typeof this.precondition=="boolean"?r=this.precondition:r=await b.evaluateRuleLogic(this,this.precondition)===!0;let s;r&&(this.condition===void 0?s=!0:typeof this.condition=="boolean"?s=this.condition:s=await b.evaluateRuleLogic(this,this.condition)===!0);const i=r&&s===!0;if(typeof s=="boolean"&&this.session){const l=s;this.session.setIsUser(l),this.eventBus({type:"user_decide",value:l})}if(this.eventBus({type:"initialize"}),document.body&&i&&B(this),await b.domInteractive(),i&&B(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session){const{id:l,isUser:o,identifiers:n}=this.session;this.eventBus({type:"session",id:l,isUser:o,identifiers:n})}})()};registerFramework=e=>{ae(e,this.frameworks)};registerComponent=(e,r)=>{C(e,r,this.components)};registerPlugin=e=>{X(this,e,this.plugins)};registerFeature=(e,r)=>{Se(e,r,this.features)};registerPredicate=(e,r)=>{me(e,r,this.predicates)};registerField=e=>{je(e,this.fields)};registerAction=(e,r)=>{Re(e,r,this.actions)};registerExperience=e=>{e.component&&C(`experience:${e.id}`,e.component,this.components),Y(e,this.experiences)};getStateSnapshot=()=>V(this);launchExperienceById=async e=>{const r=this.experiences.getById(e).getState();if(!r){E.logger("warn",`Experience with id '${e}' not found.`);return}U(this,r)};setupPlugins(){this.options.plugins?.forEach(e=>{if(Array.isArray(e)){e.forEach(s=>{this.registerPlugin(s)});return}const r=typeof e=="function"?e():e;if(Array.isArray(r)){r.forEach(s=>this.registerPlugin(s));return}this.registerPlugin(r)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,s])=>{const i=typeof s=="function"?s():s;this.registerFeature(r,i)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[s,i]=r.split(":");if(!s||!i)return;let l=i;l==="true"&&(l=!0),l==="false"&&(l=!1),this.registerFeature(s,{key:`${l}`,name:s,decide:()=>l,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,s])=>{if(typeof s!="function"){E.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,s)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,s])=>{if(typeof s!="function"){E.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,s)})}getPluginConfig=e=>this.plugins[e]??{};renderString=(e,r)=>{const s=this.responses.listStore.getState().reduce((i,l)=>(i[l.fieldId]=l.value,i),{});return Ge(e,{...r,responses:s})}}function N(t){return t.options?.some(e=>"condition"in e)??!1}function Ye(t){return t.some(e=>e.condition||N(e))}async function Qe(t,e){return e.length===0||!Ye(e)?e:(await Promise.all(e.map(async s=>{if(!(s.condition?await b.evaluateRuleLogic(t,s.condition):!0))return null;if(!s.options||!N(s))return s;const o=(await Promise.all(s.options.map(async d=>d.condition?await b.evaluateRuleLogic(t,d.condition)?d:null:d))).filter(d=>d!==null);return o.length===s.options.length?s:o.length===0?null:{...s,options:o}}))).filter(s=>s!==null)}const Xe=t=>{const e=new L(t);return k.bindClient(e),e};exports.evaluateRuleLogic=b.evaluateRuleLogic;exports.isPickedRoot=b.isPickedRoot;exports.createStorageKey=w.createStorageKey;exports.localStore=w.localStore;exports.sessionStore=w.sessionStore;exports.subscribe=w.subscribe;exports.supportsCookies=k.supportsCookies;exports.supportsCryptoRandomUUID=k.supportsCryptoRandomUUID;exports.supportsDocument=k.supportsDocument;exports.supportsHistory=k.supportsHistory;exports.supportsIntersectionObserver=k.supportsIntersectionObserver;exports.supportsLocalStorage=k.supportsLocalStorage;exports.supportsLocation=k.supportsLocation;exports.supportsSessionStorage=k.supportsSessionStorage;exports.supportsShadowRoot=k.supportsShadowRoot;exports.supportsWebComponents=k.supportsWebComponents;exports.supportsWindow=k.supportsWindow;exports.Picked=L;exports.createClient=Xe;exports.getPickedConfig=T;exports.getStepFields=Qe;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createDomain as x, createApi as j, createStore as N, createEffect as $, sample as k, attach as Z, combine as D, createEvent as V } from "effector";
|
|
2
2
|
import { createFactory as b, invoke as I } from "@withease/factories";
|
|
3
|
-
import { g as q, t as ee, c as te, i as re, e as E, a as
|
|
3
|
+
import { g as q, t as ee, c as te, i as re, e as E, a as se, b as ne, d as ie } from "../experience-instance-D0bQ9DzM.js";
|
|
4
4
|
import { f as Bt } from "../experience-instance-D0bQ9DzM.js";
|
|
5
5
|
import { l as w } from "../logger-C9a75KZn.js";
|
|
6
6
|
import { c as A, l as z, s as O } from "../storage-Co_LbKr_.js";
|
|
@@ -11,79 +11,79 @@ import { s as T, a as U, b as ce, c as ue, d as de } from "../supports-8YT4QKI7.
|
|
|
11
11
|
import { e as zt, f as Ot, g as Mt, h as Dt, i as Vt, j as Nt, k as Tt } from "../supports-8YT4QKI7.js";
|
|
12
12
|
const K = x("experience"), le = b(
|
|
13
13
|
({ client: t, experience: e }) => {
|
|
14
|
-
const r = K.store(e),
|
|
15
|
-
merge(
|
|
14
|
+
const r = K.store(e), s = j(r, {
|
|
15
|
+
merge(f, h) {
|
|
16
16
|
return {
|
|
17
|
-
...
|
|
17
|
+
...f,
|
|
18
18
|
...h.experience
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
}), i = r.map((
|
|
22
|
-
name:
|
|
23
|
-
decisionLogic:
|
|
24
|
-
targetSelectors:
|
|
21
|
+
}), i = r.map((f) => ({
|
|
22
|
+
name: f.name,
|
|
23
|
+
decisionLogic: f.condition ?? f.decide,
|
|
24
|
+
targetSelectors: f.targets,
|
|
25
25
|
initializeOpenLogic: e.initializeOpen
|
|
26
26
|
})), d = t.components.listStore.map(
|
|
27
|
-
(
|
|
27
|
+
(f) => f.find((h) => h.name === `experience:${e.id}`) || f.find((h) => h.name === "experience"),
|
|
28
28
|
{ skipVoid: !1 }
|
|
29
|
-
), o = r.map((
|
|
30
|
-
steps:
|
|
31
|
-
nodes:
|
|
32
|
-
edges:
|
|
33
|
-
conditionals:
|
|
34
|
-
})),
|
|
29
|
+
), o = r.map((f) => ({
|
|
30
|
+
steps: f.steps,
|
|
31
|
+
nodes: f.nodes,
|
|
32
|
+
edges: f.edges,
|
|
33
|
+
conditionals: f.conditionals
|
|
34
|
+
})), n = r.map((f) => f.fields), l = e.actions ?? [];
|
|
35
35
|
return {
|
|
36
36
|
id: e.id,
|
|
37
37
|
configStore: i,
|
|
38
38
|
treeStore: o,
|
|
39
|
-
fieldsStore:
|
|
39
|
+
fieldsStore: n,
|
|
40
40
|
componentStore: d,
|
|
41
41
|
actions: l,
|
|
42
|
-
merge:
|
|
42
|
+
merge: s.merge
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
|
-
function
|
|
46
|
+
function fe(t) {
|
|
47
47
|
return I(le, t);
|
|
48
48
|
}
|
|
49
|
-
const
|
|
49
|
+
const pe = b(({ client: t }) => {
|
|
50
50
|
const e = K.store({}), r = j(e, {
|
|
51
|
-
register(o,
|
|
51
|
+
register(o, n) {
|
|
52
52
|
return {
|
|
53
53
|
...o,
|
|
54
|
-
[
|
|
54
|
+
[n.id]: n
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
|
|
58
|
+
function s(o) {
|
|
59
|
+
const n = e.getState()[o.id];
|
|
60
|
+
if (n) {
|
|
61
|
+
n.merge({ experience: o, strategy: "override" });
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
const l =
|
|
64
|
+
const l = fe({ client: t, experience: o });
|
|
65
65
|
r.register(l);
|
|
66
66
|
}
|
|
67
67
|
const i = e.map((o) => Object.values(o));
|
|
68
68
|
function d(o) {
|
|
69
|
-
return e.map((
|
|
69
|
+
return e.map((n) => n[o], { skipVoid: !1 });
|
|
70
70
|
}
|
|
71
71
|
return {
|
|
72
|
-
register:
|
|
72
|
+
register: s,
|
|
73
73
|
getById: d,
|
|
74
74
|
listStore: i
|
|
75
75
|
};
|
|
76
76
|
});
|
|
77
77
|
function ge(t) {
|
|
78
|
-
return I(
|
|
78
|
+
return I(pe, t);
|
|
79
79
|
}
|
|
80
80
|
const me = (t, e) => {
|
|
81
81
|
e.register(t);
|
|
82
82
|
}, W = (t, e) => {
|
|
83
|
-
const { targetSelectors: r } = e.configStore.getState(),
|
|
84
|
-
|
|
83
|
+
const { targetSelectors: r } = e.configStore.getState(), s = q(r, e.id);
|
|
84
|
+
s.forEach(
|
|
85
85
|
({ elements: d }) => d.forEach((o) => ee(o, e.id))
|
|
86
|
-
), te(
|
|
86
|
+
), te(s, e.id).forEach((d) => {
|
|
87
87
|
t.experienceInstances.spawn(e, d);
|
|
88
88
|
});
|
|
89
89
|
}, _ = async (t) => {
|
|
@@ -93,21 +93,21 @@ const me = (t, e) => {
|
|
|
93
93
|
})
|
|
94
94
|
);
|
|
95
95
|
}, he = async (t, e) => {
|
|
96
|
-
const { decisionLogic: r, targetSelectors:
|
|
97
|
-
return q(
|
|
96
|
+
const { decisionLogic: r, targetSelectors: s } = e.configStore.getState();
|
|
97
|
+
return q(s, e.id).length < 1 || s.length === 0 ? !1 : r && re(r) ? await E(t, r) === !0 : !0;
|
|
98
98
|
}, ye = (t, e, r) => {
|
|
99
|
-
const
|
|
99
|
+
const s = e.name, i = e.setup(t);
|
|
100
100
|
if (i) {
|
|
101
|
-
const d = r[
|
|
102
|
-
r[
|
|
101
|
+
const d = r[s] ?? {};
|
|
102
|
+
r[s] = Object.freeze({ ...d, ...i });
|
|
103
103
|
}
|
|
104
104
|
}, Se = x("component"), ve = b(
|
|
105
105
|
({ client: t, component: e, name: r }) => {
|
|
106
|
-
const
|
|
106
|
+
const s = t.frameworks.getByName(e.frameworkName);
|
|
107
107
|
return {
|
|
108
108
|
name: r,
|
|
109
109
|
component: e,
|
|
110
|
-
frameworkStore:
|
|
110
|
+
frameworkStore: s
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
);
|
|
@@ -116,27 +116,27 @@ function ke(t) {
|
|
|
116
116
|
}
|
|
117
117
|
const we = b(({ client: t }) => {
|
|
118
118
|
const e = Se.store({}), r = j(e, {
|
|
119
|
-
register(o,
|
|
119
|
+
register(o, n) {
|
|
120
120
|
return {
|
|
121
121
|
...o,
|
|
122
|
-
[
|
|
122
|
+
[n.name]: n
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
-
function
|
|
126
|
+
function s(o, n) {
|
|
127
127
|
e.getState()[o] && w(
|
|
128
128
|
"warn",
|
|
129
129
|
`Component '${o}' already registered. Registering again will override the previous registration.`
|
|
130
130
|
);
|
|
131
|
-
const
|
|
132
|
-
r.register(
|
|
131
|
+
const f = ke({ client: t, name: o, component: n });
|
|
132
|
+
r.register(f);
|
|
133
133
|
}
|
|
134
134
|
const i = e.map((o) => Object.values(o));
|
|
135
135
|
function d(o) {
|
|
136
|
-
return e.map((
|
|
136
|
+
return e.map((n) => n[o], { skipVoid: !1 });
|
|
137
137
|
}
|
|
138
138
|
return {
|
|
139
|
-
register:
|
|
139
|
+
register: s,
|
|
140
140
|
getByName: d,
|
|
141
141
|
listStore: i
|
|
142
142
|
};
|
|
@@ -148,25 +148,25 @@ const L = (t, e, r) => {
|
|
|
148
148
|
r.register(t, e);
|
|
149
149
|
}, Ie = x("framework"), Fe = b(({ client: t }) => {
|
|
150
150
|
const e = Ie.store({}), r = j(e, {
|
|
151
|
-
register(o,
|
|
151
|
+
register(o, n) {
|
|
152
152
|
return {
|
|
153
153
|
...o,
|
|
154
|
-
[
|
|
154
|
+
[n.name]: n.framework
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
});
|
|
158
|
-
function
|
|
158
|
+
function s(o, n) {
|
|
159
159
|
e.getState()[o] && w(
|
|
160
160
|
"warn",
|
|
161
161
|
`Framework '${o}' already registered. Registering again will override the previous registration.`
|
|
162
|
-
), r.register({ name: o, framework:
|
|
162
|
+
), r.register({ name: o, framework: n });
|
|
163
163
|
}
|
|
164
164
|
const i = e.map((o) => Object.values(o));
|
|
165
165
|
function d(o) {
|
|
166
|
-
return e.map((
|
|
166
|
+
return e.map((n) => n[o], { skipVoid: !1 });
|
|
167
167
|
}
|
|
168
168
|
return {
|
|
169
|
-
register:
|
|
169
|
+
register: s,
|
|
170
170
|
getByName: d,
|
|
171
171
|
listStore: i
|
|
172
172
|
};
|
|
@@ -179,19 +179,19 @@ const je = (t, e) => {
|
|
|
179
179
|
}, Ee = 6e3, Pe = A("last_ping", "global"), Ae = (t) => `${t}/api/v1/ping`, Be = async (t) => {
|
|
180
180
|
try {
|
|
181
181
|
const e = Date.now(), r = z.get(Pe);
|
|
182
|
-
let
|
|
183
|
-
if (r.isSet() && (
|
|
182
|
+
let s = 0;
|
|
183
|
+
if (r.isSet() && (s = r.json() ?? 0), s && e - s < Ee)
|
|
184
184
|
return !0;
|
|
185
185
|
const i = Ae(t.apiUrl), d = {
|
|
186
186
|
projectId: t.projectId,
|
|
187
187
|
path: window.location.pathname
|
|
188
|
-
}, o = JSON.stringify(d),
|
|
188
|
+
}, o = JSON.stringify(d), n = {
|
|
189
189
|
"Content-Type": "application/json"
|
|
190
|
-
},
|
|
191
|
-
|
|
190
|
+
}, f = document.getElementById("picked_script")?.dataset.verceltoken;
|
|
191
|
+
f && (n["x-vercel-protection-bypass"] = f);
|
|
192
192
|
const v = (await fetch(i, {
|
|
193
193
|
method: "POST",
|
|
194
|
-
headers:
|
|
194
|
+
headers: n,
|
|
195
195
|
body: o
|
|
196
196
|
})).ok;
|
|
197
197
|
return v && r.set(e), v;
|
|
@@ -213,9 +213,9 @@ function Y(t) {
|
|
|
213
213
|
}
|
|
214
214
|
const Re = x("predicate"), $e = b(({ client: t }) => {
|
|
215
215
|
const e = Re.store({}), r = j(e, {
|
|
216
|
-
register(
|
|
216
|
+
register(n, l) {
|
|
217
217
|
return {
|
|
218
|
-
...
|
|
218
|
+
...n,
|
|
219
219
|
[l.name]: {
|
|
220
220
|
name: l.name,
|
|
221
221
|
predicate: l.predicate
|
|
@@ -223,22 +223,22 @@ const Re = x("predicate"), $e = b(({ client: t }) => {
|
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
});
|
|
226
|
-
function n
|
|
227
|
-
e.getState()[
|
|
226
|
+
function s(n, l) {
|
|
227
|
+
e.getState()[n] && w(
|
|
228
228
|
"warn",
|
|
229
|
-
`Predicate '${
|
|
230
|
-
), r.register(Object.freeze({ name:
|
|
229
|
+
`Predicate '${n}' already registered. Registering again will override the previous registration.`
|
|
230
|
+
), r.register(Object.freeze({ name: n, predicate: l }));
|
|
231
231
|
}
|
|
232
|
-
const i = e.map((
|
|
233
|
-
function d(
|
|
234
|
-
return e.map((l) => l[
|
|
232
|
+
const i = e.map((n) => Object.values(n));
|
|
233
|
+
function d(n) {
|
|
234
|
+
return e.map((l) => l[n]?.predicate, { skipVoid: !1 });
|
|
235
235
|
}
|
|
236
|
-
function o(
|
|
236
|
+
function o(n) {
|
|
237
237
|
const l = N(() => {
|
|
238
238
|
}, {
|
|
239
239
|
skipVoid: !1
|
|
240
|
-
}),
|
|
241
|
-
const h = d(
|
|
240
|
+
}), f = $(async () => {
|
|
241
|
+
const h = d(n).getState();
|
|
242
242
|
if (!h)
|
|
243
243
|
return;
|
|
244
244
|
const v = Y(t);
|
|
@@ -246,15 +246,15 @@ const Re = x("predicate"), $e = b(({ client: t }) => {
|
|
|
246
246
|
});
|
|
247
247
|
return k({
|
|
248
248
|
source: { responses: t.responses.listStore, fields: t.fields.listStore },
|
|
249
|
-
target:
|
|
249
|
+
target: f
|
|
250
250
|
}), k({
|
|
251
|
-
clock:
|
|
251
|
+
clock: f.doneData,
|
|
252
252
|
filter: (h) => h !== void 0,
|
|
253
253
|
target: l
|
|
254
|
-
}),
|
|
254
|
+
}), f(), l;
|
|
255
255
|
}
|
|
256
256
|
return {
|
|
257
|
-
register:
|
|
257
|
+
register: s,
|
|
258
258
|
getByName: d,
|
|
259
259
|
listStore: i,
|
|
260
260
|
getEvokablePredicate: o
|
|
@@ -266,7 +266,7 @@ function Ce(t) {
|
|
|
266
266
|
const ze = (t, e, r) => {
|
|
267
267
|
r.register(t, e);
|
|
268
268
|
}, J = x("feature"), Oe = b(({ client: t }) => {
|
|
269
|
-
const e = J.store({}), r = J.store([]),
|
|
269
|
+
const e = J.store({}), r = J.store([]), s = j(e, {
|
|
270
270
|
register(a, c) {
|
|
271
271
|
return {
|
|
272
272
|
...a,
|
|
@@ -286,7 +286,7 @@ const ze = (t, e, r) => {
|
|
|
286
286
|
id: a
|
|
287
287
|
}
|
|
288
288
|
};
|
|
289
|
-
|
|
289
|
+
s.register(
|
|
290
290
|
Object.freeze({
|
|
291
291
|
id: a,
|
|
292
292
|
feature: u
|
|
@@ -297,73 +297,73 @@ const ze = (t, e, r) => {
|
|
|
297
297
|
async ({
|
|
298
298
|
id: a,
|
|
299
299
|
key: c,
|
|
300
|
-
storage:
|
|
300
|
+
storage: p = "local"
|
|
301
301
|
}) => {
|
|
302
|
-
const u = A(`feature:${a}:${c}`, "global"), y = (
|
|
303
|
-
return y === null ? null : { id: a, key: c, bucket: y, storage:
|
|
302
|
+
const u = A(`feature:${a}:${c}`, "global"), y = (p === "session" ? O : z).get(u).boolean();
|
|
303
|
+
return y === null ? null : { id: a, key: c, bucket: y, storage: p };
|
|
304
304
|
}
|
|
305
305
|
), o = $((a) => {
|
|
306
306
|
if (!a)
|
|
307
307
|
return null;
|
|
308
308
|
const c = A(`feature:${a.id}:${a.key}`, "global");
|
|
309
309
|
(a.storage === "session" ? O : z).set(c, a.bucket);
|
|
310
|
-
}),
|
|
310
|
+
}), n = /* @__PURE__ */ new Map(), l = Z({
|
|
311
311
|
source: { allFeaturesStore: e, resolvedFeaturesStore: r },
|
|
312
|
-
effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: c }, { id:
|
|
312
|
+
effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: c }, { id: p, decide: u, key: g }) => {
|
|
313
313
|
const y = c.find(
|
|
314
|
-
(R) => R.id ===
|
|
314
|
+
(R) => R.id === p && R.key === g
|
|
315
315
|
);
|
|
316
316
|
if (y)
|
|
317
317
|
return y;
|
|
318
|
-
const F = a[
|
|
318
|
+
const F = a[p];
|
|
319
319
|
if (!F)
|
|
320
|
-
throw new Error(`Feature with id '${
|
|
321
|
-
const B =
|
|
320
|
+
throw new Error(`Feature with id '${p}' not found`);
|
|
321
|
+
const B = n.get(`${p}:${g}`);
|
|
322
322
|
if (B !== void 0) {
|
|
323
323
|
const R = await B;
|
|
324
324
|
return { id: F.id, bucket: R, key: g, storage: F.feature.storage };
|
|
325
325
|
}
|
|
326
326
|
const S = u();
|
|
327
|
-
|
|
327
|
+
n.set(`${p}:${g}`, S);
|
|
328
328
|
const X = await S;
|
|
329
329
|
return { id: F.id, bucket: X, key: g, storage: F.feature.storage };
|
|
330
330
|
}
|
|
331
331
|
});
|
|
332
332
|
k({
|
|
333
|
-
clock:
|
|
333
|
+
clock: s.register,
|
|
334
334
|
fn: (a) => {
|
|
335
|
-
const { id: c, feature:
|
|
336
|
-
return { id: c, key:
|
|
335
|
+
const { id: c, feature: p } = a;
|
|
336
|
+
return { id: c, key: p.feature.key, storage: p.feature.storage };
|
|
337
337
|
},
|
|
338
338
|
target: d
|
|
339
339
|
}), k({
|
|
340
340
|
source: e,
|
|
341
341
|
clock: l.doneData,
|
|
342
342
|
fn: (a, c) => {
|
|
343
|
-
const { id:
|
|
344
|
-
return y ? { key: y, id:
|
|
343
|
+
const { id: p, bucket: u, storage: g } = c, y = a[p]?.feature.key;
|
|
344
|
+
return y ? { key: y, id: p, bucket: u, storage: g } : null;
|
|
345
345
|
},
|
|
346
346
|
target: o
|
|
347
347
|
});
|
|
348
|
-
const
|
|
348
|
+
const f = D({ allFeaturesStore: e, resolvedFeaturesStore: r }).map(
|
|
349
349
|
({
|
|
350
350
|
allFeaturesStore: a,
|
|
351
351
|
resolvedFeaturesStore: c
|
|
352
|
-
}) => Object.values(a).map((
|
|
352
|
+
}) => Object.values(a).map((p) => {
|
|
353
353
|
const u = c.find(
|
|
354
|
-
(g) => g.id ===
|
|
354
|
+
(g) => g.id === p.id && g.key === p.feature.key
|
|
355
355
|
);
|
|
356
356
|
return u ? {
|
|
357
|
-
id:
|
|
358
|
-
name:
|
|
359
|
-
key:
|
|
360
|
-
getBucket: () => ({ id:
|
|
357
|
+
id: p.id,
|
|
358
|
+
name: p.feature.name,
|
|
359
|
+
key: p.feature.key,
|
|
360
|
+
getBucket: () => ({ id: p.id, bucket: u.bucket }),
|
|
361
361
|
isResolved: !0
|
|
362
362
|
} : {
|
|
363
|
-
id:
|
|
364
|
-
name:
|
|
365
|
-
key:
|
|
366
|
-
getBucket: async () => await l(
|
|
363
|
+
id: p.id,
|
|
364
|
+
name: p.feature.name,
|
|
365
|
+
key: p.feature.key,
|
|
366
|
+
getBucket: async () => await l(p.feature),
|
|
367
367
|
isResolved: !1
|
|
368
368
|
};
|
|
369
369
|
})
|
|
@@ -371,8 +371,8 @@ const ze = (t, e, r) => {
|
|
|
371
371
|
k({
|
|
372
372
|
clock: l.doneData,
|
|
373
373
|
source: { resolvedFeatures: r },
|
|
374
|
-
filter: ({ resolvedFeatures: a }, { id: c, key:
|
|
375
|
-
(g) => g.id === c && g.key ===
|
|
374
|
+
filter: ({ resolvedFeatures: a }, { id: c, key: p }) => !a.some(
|
|
375
|
+
(g) => g.id === c && g.key === p
|
|
376
376
|
),
|
|
377
377
|
fn: (a, c) => c,
|
|
378
378
|
target: t.eventBus.prepend((a) => ({
|
|
@@ -388,7 +388,7 @@ const ze = (t, e, r) => {
|
|
|
388
388
|
target: r
|
|
389
389
|
});
|
|
390
390
|
function h(a) {
|
|
391
|
-
return
|
|
391
|
+
return f.map((c) => c.find((p) => p.id === a));
|
|
392
392
|
}
|
|
393
393
|
function v(a) {
|
|
394
394
|
return e.map((c) => c[a], { skipVoid: !1 });
|
|
@@ -398,7 +398,7 @@ const ze = (t, e, r) => {
|
|
|
398
398
|
async () => {
|
|
399
399
|
},
|
|
400
400
|
{ skipVoid: !1 }
|
|
401
|
-
),
|
|
401
|
+
), p = $(async () => {
|
|
402
402
|
const u = h(a).getState();
|
|
403
403
|
if (u)
|
|
404
404
|
return async () => (await u.getBucket()).bucket;
|
|
@@ -406,18 +406,18 @@ const ze = (t, e, r) => {
|
|
|
406
406
|
return k({
|
|
407
407
|
source: r,
|
|
408
408
|
filter: (u) => u.some((g) => g.id === a),
|
|
409
|
-
target:
|
|
409
|
+
target: p
|
|
410
410
|
}), k({
|
|
411
|
-
clock:
|
|
411
|
+
clock: p.doneData,
|
|
412
412
|
filter: (u) => u !== void 0,
|
|
413
413
|
target: c
|
|
414
|
-
}),
|
|
414
|
+
}), p(), c;
|
|
415
415
|
}
|
|
416
416
|
return {
|
|
417
417
|
register: i,
|
|
418
418
|
getById: h,
|
|
419
419
|
getByName: v,
|
|
420
|
-
listStore:
|
|
420
|
+
listStore: f,
|
|
421
421
|
getEvokableFeature: m
|
|
422
422
|
};
|
|
423
423
|
});
|
|
@@ -437,39 +437,39 @@ function H(t, e) {
|
|
|
437
437
|
};
|
|
438
438
|
}
|
|
439
439
|
const Ve = b(() => {
|
|
440
|
-
const t = P.store({ entries: [] }), e = P.event(), r = P.event(),
|
|
441
|
-
t.on(e, (o,
|
|
442
|
-
entries: [...o.entries, H(
|
|
443
|
-
})), t.on(r, (o,
|
|
440
|
+
const t = P.store({ entries: [] }), e = P.event(), r = P.event(), s = P.event(), i = P.event();
|
|
441
|
+
t.on(e, (o, n) => ({
|
|
442
|
+
entries: [...o.entries, H(n.experienceId, n.node)]
|
|
443
|
+
})), t.on(r, (o, n) => ({
|
|
444
444
|
entries: [
|
|
445
445
|
...o.entries.slice(0, -1),
|
|
446
|
-
H(
|
|
446
|
+
H(n.experienceId, n.node)
|
|
447
447
|
]
|
|
448
|
-
})), t.on(i, (o,
|
|
449
|
-
function d(o,
|
|
448
|
+
})), t.on(i, (o, n) => n);
|
|
449
|
+
function d(o, n) {
|
|
450
450
|
const l = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
451
|
-
for (let
|
|
452
|
-
const h = o[
|
|
453
|
-
if (!(!v || !
|
|
451
|
+
for (let f = o.length - 1; f >= 0; f--) {
|
|
452
|
+
const h = o[f], v = h?.node;
|
|
453
|
+
if (!(!v || !se(v)) && !(n && h?.experienceId !== n))
|
|
454
454
|
if (l.lastStepIndex === -1)
|
|
455
|
-
l.lastStepIndex =
|
|
455
|
+
l.lastStepIndex = f;
|
|
456
456
|
else {
|
|
457
|
-
l.secondLastStepIndex =
|
|
457
|
+
l.secondLastStepIndex = f;
|
|
458
458
|
break;
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
return l;
|
|
462
462
|
}
|
|
463
|
-
return t.on(
|
|
464
|
-
const { secondLastStepIndex: l } = d(o.entries,
|
|
463
|
+
return t.on(s, (o, n) => {
|
|
464
|
+
const { secondLastStepIndex: l } = d(o.entries, n.experienceId), f = l !== -1 ? o.entries.slice(0, l + 1) : o.entries;
|
|
465
465
|
return {
|
|
466
466
|
...o,
|
|
467
|
-
entries:
|
|
467
|
+
entries: f
|
|
468
468
|
};
|
|
469
469
|
}), {
|
|
470
470
|
push: e,
|
|
471
471
|
replace: r,
|
|
472
|
-
back:
|
|
472
|
+
back: s,
|
|
473
473
|
restore: i,
|
|
474
474
|
entriesStore: t.map((o) => o.entries)
|
|
475
475
|
};
|
|
@@ -483,47 +483,47 @@ const Ue = (t) => {
|
|
|
483
483
|
return k({
|
|
484
484
|
clock: t,
|
|
485
485
|
source: e,
|
|
486
|
-
fn: (r,
|
|
486
|
+
fn: (r, s) => [
|
|
487
487
|
...r,
|
|
488
488
|
{
|
|
489
489
|
id: Te++,
|
|
490
490
|
at: /* @__PURE__ */ new Date(),
|
|
491
|
-
payload:
|
|
491
|
+
payload: s
|
|
492
492
|
}
|
|
493
493
|
],
|
|
494
494
|
target: e
|
|
495
495
|
}), e;
|
|
496
496
|
}, _e = x("field"), Le = b(() => {
|
|
497
497
|
const t = _e.store({}), e = j(t, {
|
|
498
|
-
register(
|
|
498
|
+
register(n, l) {
|
|
499
499
|
return {
|
|
500
|
-
...
|
|
500
|
+
...n,
|
|
501
501
|
[l.field.id]: l.field
|
|
502
502
|
};
|
|
503
503
|
}
|
|
504
504
|
});
|
|
505
|
-
function r(
|
|
506
|
-
e.register({ field:
|
|
505
|
+
function r(n) {
|
|
506
|
+
e.register({ field: n });
|
|
507
507
|
}
|
|
508
|
-
function n
|
|
509
|
-
const
|
|
510
|
-
if (!
|
|
508
|
+
function s(n, l) {
|
|
509
|
+
const f = d(n).getState();
|
|
510
|
+
if (!f)
|
|
511
511
|
return;
|
|
512
|
-
const h = Object.assign({},
|
|
512
|
+
const h = Object.assign({}, f, {
|
|
513
513
|
...l
|
|
514
514
|
});
|
|
515
515
|
e.register({ field: { ...h } });
|
|
516
516
|
}
|
|
517
|
-
const i = t.map((
|
|
518
|
-
function d(
|
|
519
|
-
return t.map((l) => l[
|
|
517
|
+
const i = t.map((n) => Object.values(n));
|
|
518
|
+
function d(n) {
|
|
519
|
+
return t.map((l) => l[n] || null);
|
|
520
520
|
}
|
|
521
|
-
function o(
|
|
522
|
-
return t.map((l) => Object.values(l).find((
|
|
521
|
+
function o(n) {
|
|
522
|
+
return t.map((l) => Object.values(l).find((f) => f.name === n) || null);
|
|
523
523
|
}
|
|
524
524
|
return {
|
|
525
525
|
register: r,
|
|
526
|
-
update:
|
|
526
|
+
update: s,
|
|
527
527
|
getById: d,
|
|
528
528
|
listStore: i,
|
|
529
529
|
getByName: o
|
|
@@ -536,27 +536,27 @@ const He = (t, e) => {
|
|
|
536
536
|
e.register(t);
|
|
537
537
|
}, Ge = x("action"), qe = b(() => {
|
|
538
538
|
const t = Ge.store({}), e = j(t, {
|
|
539
|
-
register(o,
|
|
539
|
+
register(o, n) {
|
|
540
540
|
return {
|
|
541
541
|
...o,
|
|
542
|
-
[
|
|
543
|
-
name:
|
|
544
|
-
action:
|
|
542
|
+
[n.name]: {
|
|
543
|
+
name: n.name,
|
|
544
|
+
action: n.action
|
|
545
545
|
}
|
|
546
546
|
};
|
|
547
547
|
}
|
|
548
548
|
});
|
|
549
|
-
function r(o,
|
|
550
|
-
e.register({ name: o, action:
|
|
549
|
+
function r(o, n) {
|
|
550
|
+
e.register({ name: o, action: n });
|
|
551
551
|
}
|
|
552
|
-
const
|
|
552
|
+
const s = t.map((o) => Object.values(o));
|
|
553
553
|
function i(o) {
|
|
554
|
-
return t.map((
|
|
554
|
+
return t.map((n) => n[o], { skipVoid: !1 });
|
|
555
555
|
}
|
|
556
556
|
function d(o) {
|
|
557
557
|
return t.map(
|
|
558
|
-
(
|
|
559
|
-
const l =
|
|
558
|
+
(n) => {
|
|
559
|
+
const l = n[o];
|
|
560
560
|
return l ? l.action : void 0;
|
|
561
561
|
},
|
|
562
562
|
{ skipVoid: !1 }
|
|
@@ -565,7 +565,7 @@ const He = (t, e) => {
|
|
|
565
565
|
return {
|
|
566
566
|
register: r,
|
|
567
567
|
getByName: i,
|
|
568
|
-
listStore:
|
|
568
|
+
listStore: s,
|
|
569
569
|
getEvokableAction: d
|
|
570
570
|
};
|
|
571
571
|
});
|
|
@@ -589,7 +589,7 @@ function G(t) {
|
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
591
|
const Qe = x("response"), Xe = b(({ client: t }) => {
|
|
592
|
-
const e = Qe.store({}), r = V(),
|
|
592
|
+
const e = Qe.store({}), r = V(), s = V(), i = j(e, {
|
|
593
593
|
register(m, a) {
|
|
594
594
|
return {
|
|
595
595
|
...m,
|
|
@@ -603,8 +603,8 @@ const Qe = x("response"), Xe = b(({ client: t }) => {
|
|
|
603
603
|
};
|
|
604
604
|
},
|
|
605
605
|
clear(m, a) {
|
|
606
|
-
const { [a]: c, ...
|
|
607
|
-
return
|
|
606
|
+
const { [a]: c, ...p } = m;
|
|
607
|
+
return p;
|
|
608
608
|
},
|
|
609
609
|
clearAll() {
|
|
610
610
|
return {};
|
|
@@ -621,8 +621,8 @@ const Qe = x("response"), Xe = b(({ client: t }) => {
|
|
|
621
621
|
async function o(m) {
|
|
622
622
|
const a = [];
|
|
623
623
|
return await Promise.allSettled(
|
|
624
|
-
Object.entries(m).map(async ([c,
|
|
625
|
-
let u =
|
|
624
|
+
Object.entries(m).map(async ([c, p]) => {
|
|
625
|
+
let u = p;
|
|
626
626
|
const g = t.fields.getById(c).getState();
|
|
627
627
|
if (!g) {
|
|
628
628
|
a.push({
|
|
@@ -757,22 +757,22 @@ const Qe = x("response"), Xe = b(({ client: t }) => {
|
|
|
757
757
|
})
|
|
758
758
|
), { responsesToCommit: m, validationErrors: a };
|
|
759
759
|
}
|
|
760
|
-
async function
|
|
760
|
+
async function n(m) {
|
|
761
761
|
const { responsesToCommit: a, validationErrors: c } = await o(m);
|
|
762
762
|
return c.length ? { errors: c } : (i.registerBatch(a), { errors: [] });
|
|
763
763
|
}
|
|
764
|
-
const l = e.map((m) => m),
|
|
764
|
+
const l = e.map((m) => m), f = e.map((m) => Object.keys(m).map((c) => ({
|
|
765
765
|
fieldId: c,
|
|
766
766
|
value: m[c]
|
|
767
767
|
})));
|
|
768
768
|
function h(m) {
|
|
769
|
-
const a = t.fields.getById(m), c = e.map((
|
|
770
|
-
return D({ f: a, r: c }, ({ f, r: u }) => u || (
|
|
769
|
+
const a = t.fields.getById(m), c = e.map((p) => p[m] || null);
|
|
770
|
+
return D({ f: a, r: c }, ({ f: p, r: u }) => u || (p?.defaultValue ? p.defaultValue : null));
|
|
771
771
|
}
|
|
772
772
|
function v(m) {
|
|
773
773
|
const a = t.fields.getByName(m);
|
|
774
|
-
return D({ f: a, s: e }, ({ f: c, s:
|
|
775
|
-
const u = c &&
|
|
774
|
+
return D({ f: a, s: e }, ({ f: c, s: p }) => {
|
|
775
|
+
const u = c && p[c.id] || null;
|
|
776
776
|
return u || (c?.defaultValue ? c.defaultValue : null);
|
|
777
777
|
});
|
|
778
778
|
}
|
|
@@ -780,15 +780,15 @@ const Qe = x("response"), Xe = b(({ client: t }) => {
|
|
|
780
780
|
clock: r,
|
|
781
781
|
target: i.clearAll
|
|
782
782
|
}), k({
|
|
783
|
-
clock:
|
|
783
|
+
clock: s,
|
|
784
784
|
target: i.clear
|
|
785
785
|
}), {
|
|
786
786
|
register: d,
|
|
787
787
|
clearAll: r,
|
|
788
|
-
clear:
|
|
789
|
-
commit:
|
|
788
|
+
clear: s,
|
|
789
|
+
commit: n,
|
|
790
790
|
getResponsesToCommit: o,
|
|
791
|
-
listStore:
|
|
791
|
+
listStore: f,
|
|
792
792
|
getAllStore: l,
|
|
793
793
|
getByFieldId: h,
|
|
794
794
|
getByFieldName: v
|
|
@@ -797,7 +797,7 @@ const Qe = x("response"), Xe = b(({ client: t }) => {
|
|
|
797
797
|
function Ze(t) {
|
|
798
798
|
return I(Xe, t);
|
|
799
799
|
}
|
|
800
|
-
const et = () => "0.0.42
|
|
800
|
+
const et = () => "0.0.42";
|
|
801
801
|
function tt() {
|
|
802
802
|
if (T()) {
|
|
803
803
|
const t = [
|
|
@@ -823,32 +823,32 @@ function rt() {
|
|
|
823
823
|
const d = i.replace("picked-", "");
|
|
824
824
|
e[d] = t.getAll(i);
|
|
825
825
|
}
|
|
826
|
-
const
|
|
826
|
+
const s = A("s");
|
|
827
827
|
if (r.size > 0)
|
|
828
|
-
O.set(
|
|
828
|
+
O.set(s, e);
|
|
829
829
|
else {
|
|
830
|
-
const i = O.get(
|
|
830
|
+
const i = O.get(s);
|
|
831
831
|
if (i)
|
|
832
832
|
return i.json() || {};
|
|
833
833
|
}
|
|
834
834
|
return e;
|
|
835
835
|
}
|
|
836
|
-
function
|
|
836
|
+
function st() {
|
|
837
837
|
if (ue())
|
|
838
838
|
return crypto.randomUUID();
|
|
839
|
-
const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15),
|
|
840
|
-
return `${t}-${e}-${r}-${
|
|
839
|
+
const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), r = Math.random().toString(36).substring(2, 15), s = Math.random().toString(36).substring(2, 15);
|
|
840
|
+
return `${t}-${e}-${r}-${s}`;
|
|
841
841
|
}
|
|
842
|
-
const
|
|
843
|
-
const t = z.get(
|
|
842
|
+
const nt = A("session", "global"), it = () => {
|
|
843
|
+
const t = z.get(nt);
|
|
844
844
|
let e;
|
|
845
845
|
t.isSet() && (e = t.json());
|
|
846
846
|
const r = (i) => t.set({
|
|
847
847
|
id: i.id,
|
|
848
848
|
isUser: i.isUser,
|
|
849
849
|
identifiers: i.identifiers
|
|
850
|
-
}),
|
|
851
|
-
id: e?.id ??
|
|
850
|
+
}), s = {
|
|
851
|
+
id: e?.id ?? st(),
|
|
852
852
|
isUser: e?.isUser ?? void 0,
|
|
853
853
|
identifiers: e?.identifiers ?? void 0,
|
|
854
854
|
setIsUser(i) {
|
|
@@ -863,7 +863,7 @@ const st = A("session", "global"), it = () => {
|
|
|
863
863
|
), this.identifiers = Object.keys(this.identifiers).length ? this.identifiers : void 0, r(this));
|
|
864
864
|
}
|
|
865
865
|
};
|
|
866
|
-
return r(
|
|
866
|
+
return r(s), s;
|
|
867
867
|
}, ot = () => ce() ? it() : null;
|
|
868
868
|
function at() {
|
|
869
869
|
if (U())
|
|
@@ -889,9 +889,9 @@ function dt(t) {
|
|
|
889
889
|
const { organizationId: e, projectId: r } = t;
|
|
890
890
|
if (e && r)
|
|
891
891
|
return { organizationId: e, projectId: r };
|
|
892
|
-
const
|
|
893
|
-
if (
|
|
894
|
-
return
|
|
892
|
+
const s = ct();
|
|
893
|
+
if (s)
|
|
894
|
+
return s;
|
|
895
895
|
const i = ut();
|
|
896
896
|
if (i)
|
|
897
897
|
return i;
|
|
@@ -919,49 +919,49 @@ const lt = {
|
|
|
919
919
|
if (Array.isArray(t))
|
|
920
920
|
return e.format(t.map(String));
|
|
921
921
|
if (t instanceof Map) {
|
|
922
|
-
const r = Array.from(t.entries()).map(([
|
|
922
|
+
const r = Array.from(t.entries()).map(([s, i]) => `${s}: ${i}`);
|
|
923
923
|
return e.format(r);
|
|
924
924
|
}
|
|
925
925
|
return t instanceof Set ? e.format(Array.from(t).map(String)) : t;
|
|
926
926
|
}
|
|
927
927
|
};
|
|
928
|
-
function
|
|
928
|
+
function ft(t) {
|
|
929
929
|
return typeof t == "object" && t !== null;
|
|
930
930
|
}
|
|
931
|
-
function
|
|
931
|
+
function pt(t, e) {
|
|
932
932
|
let r = e;
|
|
933
|
-
for (const
|
|
934
|
-
if (
|
|
935
|
-
r = r[
|
|
933
|
+
for (const s of t.split("."))
|
|
934
|
+
if (ft(r) && s in r)
|
|
935
|
+
r = r[s];
|
|
936
936
|
else
|
|
937
937
|
return;
|
|
938
938
|
return typeof r == "function" ? r() : r;
|
|
939
939
|
}
|
|
940
940
|
function gt(t, e) {
|
|
941
|
-
const r = t.split("|").map((d) => d.trim()),
|
|
942
|
-
let i =
|
|
941
|
+
const r = t.split("|").map((d) => d.trim()), s = r.shift() ?? "";
|
|
942
|
+
let i = pt(s, e);
|
|
943
943
|
for (const d of r) {
|
|
944
|
-
const [o, ...
|
|
945
|
-
h && (i = h(i,
|
|
944
|
+
const [o, ...n] = d.split(":"), l = o?.trim() ?? "", f = n.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g, ""), h = lt[l];
|
|
945
|
+
h && (i = h(i, f));
|
|
946
946
|
}
|
|
947
947
|
return C(i) ? "" : typeof i == "object" ? JSON.stringify(i) : String(i);
|
|
948
948
|
}
|
|
949
949
|
function mt(t, e) {
|
|
950
|
-
let r = "",
|
|
951
|
-
for (;
|
|
952
|
-
if (t[
|
|
953
|
-
|
|
950
|
+
let r = "", s = 0;
|
|
951
|
+
for (; s < t.length; )
|
|
952
|
+
if (t[s] === "{" && t[s + 1] === "{") {
|
|
953
|
+
s += 2;
|
|
954
954
|
let i = "";
|
|
955
|
-
for (;
|
|
956
|
-
if (t[
|
|
957
|
-
|
|
955
|
+
for (; s < t.length; ) {
|
|
956
|
+
if (t[s] === "}" && t[s + 1] === "}") {
|
|
957
|
+
s += 2;
|
|
958
958
|
break;
|
|
959
959
|
}
|
|
960
|
-
i += t[
|
|
960
|
+
i += t[s++];
|
|
961
961
|
}
|
|
962
962
|
r += gt(i.trim(), e);
|
|
963
963
|
} else
|
|
964
|
-
r += t[
|
|
964
|
+
r += t[s++];
|
|
965
965
|
return r;
|
|
966
966
|
}
|
|
967
967
|
class ht {
|
|
@@ -981,7 +981,7 @@ class ht {
|
|
|
981
981
|
searchParams = rt();
|
|
982
982
|
history = Ne();
|
|
983
983
|
components = be({ client: this });
|
|
984
|
-
experienceInstances =
|
|
984
|
+
experienceInstances = ne({ client: this });
|
|
985
985
|
experiences = ge({ client: this });
|
|
986
986
|
frameworks = xe({ client: this });
|
|
987
987
|
predicates = Ce({ client: this });
|
|
@@ -991,8 +991,8 @@ class ht {
|
|
|
991
991
|
actions = Ke();
|
|
992
992
|
constructor(e) {
|
|
993
993
|
w("info", "Picked client initializing."), this.events = Ue(this.eventBus);
|
|
994
|
-
const { organizationId: r, projectId:
|
|
995
|
-
this.organizationId = r, this.projectId =
|
|
994
|
+
const { organizationId: r, projectId: s } = dt(e);
|
|
995
|
+
this.organizationId = r, this.projectId = s, this.options = Object.freeze(e), this.apiUrl = e.apiUrl || tt(), this.session = ot(), this.setupPlugins(), this.setupFeatures(), this.setupPredicates(), this.setupActions(), this.precondition = e.precondition, this.condition = e.condition, this.eventBus({ type: "load", version: et() }), w("info", "Picked client initialized.");
|
|
996
996
|
}
|
|
997
997
|
start = () => {
|
|
998
998
|
Be(this), (async () => {
|
|
@@ -1000,14 +1000,17 @@ class ht {
|
|
|
1000
1000
|
return;
|
|
1001
1001
|
let r;
|
|
1002
1002
|
typeof this.precondition > "u" ? r = !0 : typeof this.precondition == "boolean" ? r = this.precondition : r = await E(this, this.precondition) === !0;
|
|
1003
|
-
let
|
|
1004
|
-
r && (this.condition === void 0 ?
|
|
1005
|
-
const i = r &&
|
|
1006
|
-
if (typeof
|
|
1007
|
-
const d =
|
|
1003
|
+
let s;
|
|
1004
|
+
r && (this.condition === void 0 ? s = !0 : typeof this.condition == "boolean" ? s = this.condition : s = await E(this, this.condition) === !0);
|
|
1005
|
+
const i = r && s === !0;
|
|
1006
|
+
if (typeof s == "boolean" && this.session) {
|
|
1007
|
+
const d = s;
|
|
1008
1008
|
this.session.setIsUser(d), this.eventBus({ type: "user_decide", value: d });
|
|
1009
1009
|
}
|
|
1010
|
-
this.eventBus({ type: "initialize" }), document.body && i && _(this), await ie(), i && _(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session
|
|
1010
|
+
if (this.eventBus({ type: "initialize" }), document.body && i && _(this), await ie(), i && _(this), this.eventBus({ type: "ready" }), this.isReady = !0, this.session) {
|
|
1011
|
+
const { id: d, isUser: o, identifiers: n } = this.session;
|
|
1012
|
+
this.eventBus({ type: "session", id: d, isUser: o, identifiers: n });
|
|
1013
|
+
}
|
|
1011
1014
|
})();
|
|
1012
1015
|
};
|
|
1013
1016
|
registerFramework = (e) => {
|
|
@@ -1055,14 +1058,14 @@ class ht {
|
|
|
1055
1058
|
setupPlugins() {
|
|
1056
1059
|
this.options.plugins?.forEach((e) => {
|
|
1057
1060
|
if (Array.isArray(e)) {
|
|
1058
|
-
e.forEach((
|
|
1059
|
-
this.registerPlugin(
|
|
1061
|
+
e.forEach((s) => {
|
|
1062
|
+
this.registerPlugin(s);
|
|
1060
1063
|
});
|
|
1061
1064
|
return;
|
|
1062
1065
|
}
|
|
1063
1066
|
const r = typeof e == "function" ? e() : e;
|
|
1064
1067
|
if (Array.isArray(r)) {
|
|
1065
|
-
r.forEach((
|
|
1068
|
+
r.forEach((s) => this.registerPlugin(s));
|
|
1066
1069
|
return;
|
|
1067
1070
|
}
|
|
1068
1071
|
this.registerPlugin(r);
|
|
@@ -1070,19 +1073,19 @@ class ht {
|
|
|
1070
1073
|
}
|
|
1071
1074
|
setupFeatures() {
|
|
1072
1075
|
const e = this.options.features;
|
|
1073
|
-
e && (Object.entries(e).forEach(([r,
|
|
1074
|
-
const i = typeof
|
|
1076
|
+
e && (Object.entries(e).forEach(([r, s]) => {
|
|
1077
|
+
const i = typeof s == "function" ? s() : s;
|
|
1075
1078
|
this.registerFeature(r, i);
|
|
1076
1079
|
}), this.searchParams.feature && this.searchParams.feature.forEach((r) => {
|
|
1077
1080
|
try {
|
|
1078
|
-
const [
|
|
1079
|
-
if (!
|
|
1081
|
+
const [s, i] = r.split(":");
|
|
1082
|
+
if (!s || !i)
|
|
1080
1083
|
return;
|
|
1081
1084
|
let d = i;
|
|
1082
|
-
d === "true" && (d = !0), d === "false" && (d = !1), this.registerFeature(
|
|
1085
|
+
d === "true" && (d = !0), d === "false" && (d = !1), this.registerFeature(s, {
|
|
1083
1086
|
key: `${d}`,
|
|
1084
1087
|
// use the assigned bucket value as the key
|
|
1085
|
-
name:
|
|
1088
|
+
name: s,
|
|
1086
1089
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
1087
1090
|
decide: () => d,
|
|
1088
1091
|
storage: "session"
|
|
@@ -1093,22 +1096,22 @@ class ht {
|
|
|
1093
1096
|
}
|
|
1094
1097
|
setupPredicates() {
|
|
1095
1098
|
const e = this.options.predicates;
|
|
1096
|
-
e && Object.entries(e).forEach(([r,
|
|
1097
|
-
if (typeof
|
|
1099
|
+
e && Object.entries(e).forEach(([r, s]) => {
|
|
1100
|
+
if (typeof s != "function") {
|
|
1098
1101
|
w("warn", `Predicate "${r}" is not a function.`);
|
|
1099
1102
|
return;
|
|
1100
1103
|
}
|
|
1101
|
-
this.registerPredicate(r,
|
|
1104
|
+
this.registerPredicate(r, s);
|
|
1102
1105
|
});
|
|
1103
1106
|
}
|
|
1104
1107
|
setupActions() {
|
|
1105
1108
|
const e = this.options.actions;
|
|
1106
|
-
e && Object.entries(e).forEach(([r,
|
|
1107
|
-
if (typeof
|
|
1109
|
+
e && Object.entries(e).forEach(([r, s]) => {
|
|
1110
|
+
if (typeof s != "function") {
|
|
1108
1111
|
w("warn", `Action "${r}" is not a function.`);
|
|
1109
1112
|
return;
|
|
1110
1113
|
}
|
|
1111
|
-
this.registerAction(r,
|
|
1114
|
+
this.registerAction(r, s);
|
|
1112
1115
|
});
|
|
1113
1116
|
}
|
|
1114
1117
|
getPluginConfig = (e) => this.plugins[e] ?? {};
|
|
@@ -1155,10 +1158,10 @@ class ht {
|
|
|
1155
1158
|
* // => "Fruits: apple, banana, and cherry"
|
|
1156
1159
|
*/
|
|
1157
1160
|
renderString = (e, r) => {
|
|
1158
|
-
const
|
|
1161
|
+
const s = this.responses.listStore.getState().reduce((i, d) => (i[d.fieldId] = d.value, i), {});
|
|
1159
1162
|
return mt(e, {
|
|
1160
1163
|
...r,
|
|
1161
|
-
responses:
|
|
1164
|
+
responses: s
|
|
1162
1165
|
});
|
|
1163
1166
|
};
|
|
1164
1167
|
}
|
|
@@ -1170,17 +1173,17 @@ function yt(t) {
|
|
|
1170
1173
|
}
|
|
1171
1174
|
async function jt(t, e) {
|
|
1172
1175
|
return e.length === 0 || !yt(e) ? e : (await Promise.all(
|
|
1173
|
-
e.map(async (
|
|
1174
|
-
if (!(
|
|
1176
|
+
e.map(async (s) => {
|
|
1177
|
+
if (!(s.condition ? await E(t, s.condition) : !0))
|
|
1175
1178
|
return null;
|
|
1176
|
-
if (!
|
|
1177
|
-
return
|
|
1179
|
+
if (!s.options || !Q(s))
|
|
1180
|
+
return s;
|
|
1178
1181
|
const o = (await Promise.all(
|
|
1179
|
-
|
|
1182
|
+
s.options.map(async (l) => l.condition ? await E(t, l.condition) ? l : null : l)
|
|
1180
1183
|
)).filter((l) => l !== null);
|
|
1181
|
-
return o.length ===
|
|
1184
|
+
return o.length === s.options.length ? s : o.length === 0 ? null : { ...s, options: o };
|
|
1182
1185
|
})
|
|
1183
|
-
)).filter((
|
|
1186
|
+
)).filter((s) => s !== null);
|
|
1184
1187
|
}
|
|
1185
1188
|
const Et = (t) => {
|
|
1186
1189
|
const e = new ht(t);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picked.d.ts","sourceRoot":"","sources":["../../src/picked.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAe,MAAM,0BAA0B,CAAA;AAC3F,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAGtB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,gCAAgC,CAAA;AAGvC,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAKzD,OAAO,EAAsB,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACjG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAOtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK/C,qBAAa,MAAM;IACjB,MAAM,CAAC,QAAQ,CAAC,MAAM,0FAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,OAAO,UAAQ;IAEf,OAAO,CAAC,OAAO,CAAC,CAAS;IA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ASjE;IAYD,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,aAAa;IA8CrB,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,YAAY;IAgBpB,eAAe,GAAI,YAAY,MAAM,KAAG,iBAAiB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE1F;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,YAAY,GAAI,UAAU,MAAM,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,CAY3E;CACF"}
|
|
@@ -3,6 +3,7 @@ import { ValidationError } from '../entities/response/response';
|
|
|
3
3
|
import { ExperienceStep } from '../entities/experience/experience';
|
|
4
4
|
import { ExperienceInstance } from '../entities/experience-instance/experience-instance';
|
|
5
5
|
import { ResolvedFeature } from '../entities/feature/feature';
|
|
6
|
+
import { Session } from './user-session';
|
|
6
7
|
export interface FormPayload {
|
|
7
8
|
id: string;
|
|
8
9
|
title: string;
|
|
@@ -13,9 +14,7 @@ export interface PayloadMap {
|
|
|
13
14
|
version: string;
|
|
14
15
|
};
|
|
15
16
|
initialize: never;
|
|
16
|
-
session:
|
|
17
|
-
id: string;
|
|
18
|
-
};
|
|
17
|
+
session: Session;
|
|
19
18
|
user_decide: {
|
|
20
19
|
value: boolean;
|
|
21
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/utils/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,UAAU,CAAA;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qDA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