@picked/client 0.0.1-dev.1773719715758 → 0.0.1-dev.1773729274420
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/{api-CvcUdfN8.cjs → api-47L967ES.cjs} +1 -1
- package/dist/{api-2fO41mZd.js → api-DuHeVrL4.js} +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
- package/dist/esm/index.js +450 -474
- package/dist/esm/plugins/create-experience/index.js +1 -1
- package/dist/esm/plugins/dynamic-experiences/index.js +2 -2
- package/dist/types/entities/field/field.d.ts +1 -1
- package/dist/types/entities/field/field.d.ts.map +1 -1
- package/dist/types/exports.d.ts +0 -1
- package/dist/types/exports.d.ts.map +1 -1
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +4 -0
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/package.json +4 -2
- package/dist/types/utils/get-step-fields.d.ts +0 -5
- package/dist/types/utils/get-step-fields.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const a="Picked-Client",d="Picked-Version";function s(e,t){return{[a]:e,[d]:t}}const o=()=>"0.0.1-dev.
|
|
1
|
+
"use strict";const a="Picked-Client",d="Picked-Version";function s(e,t){return{[a]:e,[d]:t}}const o=()=>"0.0.1-dev.1773729274420",E="v1";function c(e,t){return new URL(`/api/${E}/${t}`,e).toString()}function i(e){return{...s("sdk",o()),...e}}async function f(e,t,n){const r=c(e,t);return fetch(r,{headers:i(n)})}async function l(e,t,n,r){const u=c(e,t);return fetch(u,{method:"POST",headers:{"Content-Type":"application/json",...i(r)},body:JSON.stringify(n)})}exports.createClientHeaders=s;exports.get=f;exports.getVersion=o;exports.post=l;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("effector"),S=require("@withease/factories"),I=require("../experience-instance-BX0aqKsC.cjs"),E=require("../logger-BsmHUUw1.cjs"),b=require("../storage-58NoTSsc.cjs"),V=require("../api-CvcUdfN8.cjs"),W=require("../id-BKIWbSTy.cjs"),J=require("../object-mwaxtjLG.cjs"),k=require("../supports-YvpQZxbh.cjs"),N=g.createDomain("experience"),Y=S.createFactory(({client:t,experience:e})=>{const r=N.store(e),s=g.createApi(r,{merge(l,h){return{...l,...h.experience}}}),o=r.map(l=>({name:l.name,decisionLogic:l.condition,targetSelectors:l.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(l=>(e.componentName?l.find(h=>h.name===e.componentName):void 0)||l.find(h=>h.name===`experience:${e.id}`)||l.find(h=>h.name==="experience"),{skipVoid:!1}),p=r.map(l=>({steps:l.steps,nodes:l.nodes,edges:l.edges,conditionals:l.conditionals})),u=r.map(l=>l.fields),f=e.actions??[];return{id:e.id,configStore:o,treeStore:p,fieldsStore:u,componentStore:d,actions:f,merge:s.merge}});function Q(t){return S.invoke(Y,t)}const X=S.createFactory(({client:t})=>{const e=N.store({}),r=g.createApi(e,{register(f,l){return{...f,[l.id]:l}}});function s(f){const l=e.getState()[f.id];if(l){l.merge({experience:f,strategy:"override"});return}const h=Q({client:t,experience:f});r.register(h)}const o=e.map(f=>Object.values(f));function d(f){return e.map(l=>l[f],{skipVoid:!1})}const p=g.attach({source:e,effect:async(f,{id:l,options:h})=>{const v=f[l];if(!v){E.logger("warn",`Experience with id '${l}' not found.`);return}if(h?.bypassCondition){D(t,v,h);return}await T(t,v)&&D(t,v,h)}}),u=g.attach({source:t.experienceInstances.listStore,effect:(f,{id:l,options:h})=>{const v=f.filter(y=>y.experienceId===l);if(v.length>0)for(const y of v)y.open();else p({id:l,options:{...h,initialiseOpen:!0}})}});return{register:s,get:d,getById:d,launch:p,open:u,listStore:o}});function Z(t){return S.invoke(X,t)}const ee=(t,e)=>{e.register(t)},D=(t,e,r)=>{const{targetSelectors:s}=e.configStore.getState(),o=I.getTargetElements(s,e.id);o.forEach(({elements:p})=>p.forEach(u=>I.tagTargetElement(u,e.id))),I.createAppHosts(o,e.id).forEach(p=>{r?t.experienceInstances.spawn(e,p,r):t.experienceInstances.spawn(e,p)})},z=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await T(t,e)&&D(t,e)}))},T=async(t,e)=>{if(!t.preconditionPassed||!t.session?.isUser)return!1;const{decisionLogic:r,targetSelectors:s}=e.configStore.getState();return I.getTargetElements(s,e.id).length<1||s.length===0?!1:r===void 0?!0:I.isRulesLogic(r)?await I.evaluateRuleLogic(t,r)===!0:!0},te=(t,e,r)=>{const s=e.name,o=e.setup(t);if(o){const d=r[s]??{};r[s]=Object.freeze({...d,...o})}},re=g.createDomain("component"),ne=S.createFactory(({client:t,component:e,name:r})=>{const s=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:s}});function se(t){return S.invoke(ne,t)}const oe=S.createFactory(({client:t})=>{const e=re.store({}),r=g.createApi(e,{register(p,u){return{...p,[u.name]:u}}});function s(p,u){e.getState()[p]&&E.logger("warn",`Component '${p}' already registered. Registering again will override the previous registration.`);const l=se({client:t,name:p,component:u});r.register(l)}const o=e.map(p=>Object.values(p));function d(p){return e.map(u=>u[p],{skipVoid:!1})}return{register:s,getByName:d,listStore:o}});function ie(t){return S.invoke(oe,t)}const M=(t,e,r)=>{r.register(t,e)},ae=g.createDomain("framework"),ce=S.createFactory(({client:t})=>{const e=ae.store({}),r=g.createApi(e,{register(p,u){return{...p,[u.name]:u.framework}}});function s(p,u){e.getState()[p]&&E.logger("warn",`Framework '${p}' already registered. Registering again will override the previous registration.`),r.register({name:p,framework:u})}const o=e.map(p=>Object.values(p));function d(p){return e.map(u=>u[p],{skipVoid:!1})}return{register:s,getByName:d,listStore:o}});function ue(t){return S.invoke(ce,t)}const le=(t,e)=>{e.register(t.name,t)},de=6e3,pe=b.createStorageKey("last_ping","global"),fe=async t=>{try{const e=Date.now(),r=b.localStore.get(pe);let s=0;if(r.isSet()&&(s=r.json()??0),s&&e-s<de)return!0;const o={projectId:t.projectId,path:window.location.pathname},d={},u=document.getElementById("picked_script")?.dataset.verceltoken;u&&(d["x-vercel-protection-bypass"]=u);const l=(await V.post(t.apiUrl,"ping",o,d)).ok;return l&&r.set(e),l}catch(e){return E.logger("error",e),!1}};function _(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 ge=g.createDomain("predicate"),me=S.createFactory(({client:t})=>{const e=ge.store({}),r=g.createApi(e,{register(u,f){return{...u,[f.name]:{name:f.name,predicate:f.predicate}}}});function s(u,f){e.getState()[u]&&E.logger("warn",`Predicate '${u}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:u,predicate:f}))}const o=e.map(u=>Object.values(u));function d(u){return e.map(f=>f[u]?.predicate,{skipVoid:!1})}function p(u){const f=g.createStore(()=>{},{skipVoid:!1}),l=g.createEffect(async()=>{const h=d(u).getState();if(!h)return;const v=_(t);return(...y)=>h({...v,args:y})});return g.sample({source:{responses:t.responses.listStore,fields:t.fields.listStore},target:l}),g.sample({clock:l.doneData,filter:h=>h!==void 0,target:f}),l(),f}return{register:s,getByName:d,listStore:o,getEvokablePredicate:p}});function ye(t){return S.invoke(me,t)}const he=(t,e,r)=>{r.register(t,e)},O=g.createDomain("feature"),Se=S.createFactory(({client:t})=>{const e=O.store({}),r=O.store([]),s=g.createApi(e,{register(c,n){return{...c,[n.id]:n.feature}}});function o(c,n){e.getState()[c]&&E.logger("warn",`Feature '${c}' already registered. Registering again will override the previous registration.`);const a={id:c,feature:{...n,id:c}};s.register(Object.freeze({id:c,feature:a}))}const d=g.createEffect(async({id:c,key:n,storage:i="local"})=>{const a=b.createStorageKey(`feature:${c}:${n}`,"global"),w=(i==="session"?b.sessionStore:b.localStore).get(a).boolean();return w===null?null:{id:c,key:n,bucket:w,storage:i}}),p=g.createEffect(c=>{if(!c)return null;const n=b.createStorageKey(`feature:${c.id}:${c.key}`,"global");(c.storage==="session"?b.sessionStore:b.localStore).set(n,c.bucket)}),u=new Map,f=g.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:c,resolvedFeaturesStore:n},{id:i,decide:a,key:m})=>{const w=n.find(P=>P.id===i&&P.key===m);if(w)return w;const F=c[i];if(!F)throw new Error(`Feature with id '${i}' not found`);const j=u.get(`${i}:${m}`);if(j!==void 0){const P=await j;return{id:F.id,bucket:P,key:m,storage:F.feature.storage}}const x=a();u.set(`${i}:${m}`,x);const G=await x;return{id:F.id,bucket:G,key:m,storage:F.feature.storage}}});g.sample({clock:s.register,fn:c=>{const{id:n,feature:i}=c;return{id:n,key:i.feature.key,storage:i.feature.storage}},target:d}),g.sample({source:e,clock:f.doneData,fn:(c,n)=>{const{id:i,bucket:a,storage:m}=n,w=c[i]?.feature.key;return w?{key:w,id:i,bucket:a,storage:m}:null},target:p});const l=g.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:c,resolvedFeaturesStore:n})=>Object.values(c).map(i=>{const a=n.find(m=>m.id===i.id&&m.key===i.feature.key);return a?{id:i.id,name:i.feature.name,key:i.feature.key,getBucket:()=>({id:i.id,bucket:a.bucket}),isResolved:!0}:{id:i.id,name:i.feature.name,key:i.feature.key,getBucket:async()=>await f(i.feature),isResolved:!1}}));g.sample({clock:f.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:c},{id:n,key:i})=>!c.some(m=>m.id===n&&m.key===i),fn:(c,n)=>n,target:t.eventBus.prepend(c=>({type:"feature_decide",feature:c}))}),g.sample({clock:[d.doneData,f.doneData],source:r,fn:(c,n)=>!n||c.some(a=>a.id===n.id&&a.key===n.key)?c:[...c,n],target:r});function h(c){return l.map(n=>n.find(i=>i.id===c))}function v(c){return e.map(n=>n[c],{skipVoid:!1})}function y(c){const n=g.createStore(async()=>{},{skipVoid:!1}),i=g.createEffect(async()=>{const a=h(c).getState();if(a)return async()=>(await a.getBucket()).bucket});return g.sample({source:r,filter:a=>a.some(m=>m.id===c),target:i}),g.sample({clock:i.doneData,filter:a=>a!==void 0,target:n}),i(),n}return{register:o,getById:h,getByName:v,listStore:l,getEvokableFeature:y}});function ve(t){return S.invoke(Se,t)}const ke=(t,e,r)=>{r.register(t,e)},A=g.createDomain("history");function U(t,e){return{id:W.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const we=S.createFactory(()=>{const t=A.store({entries:[]}),e=A.event(),r=A.event(),s=A.event(),o=A.event();t.on(e,(p,u)=>({entries:[...p.entries,U(u.experienceId,u.node)]})),t.on(r,(p,u)=>({entries:[...p.entries.slice(0,-1),U(u.experienceId,u.node)]})),t.on(o,(p,u)=>u);function d(p,u){const f={lastStepIndex:-1,secondLastStepIndex:-1};for(let l=p.length-1;l>=0;l--){const h=p[l],v=h?.node;if(!(!v||!I.isStepNode(v))&&!(u&&h.experienceId!==u))if(f.lastStepIndex===-1)f.lastStepIndex=l;else{f.secondLastStepIndex=l;break}}return f}return t.on(s,(p,u)=>{const{secondLastStepIndex:f}=d(p.entries,u.experienceId),l=f!==-1?p.entries.slice(0,f+1):p.entries;return{...p,entries:l}}),{push:e,replace:r,back:s,restore:o,entriesStore:t.map(p=>p.entries)}});function be(){return S.invoke(we)}let Ie=0;const Fe=t=>{const e=g.createStore([]);return g.sample({clock:t,source:e,fn:(r,s)=>[...r,{id:Ie++,at:new Date,payload:s}],target:e}),e},C=g.createDomain("field");function xe(t){return Array.isArray(t)&&t.every(e=>typeof e=="object"&&e!==null&&"id"in e&&"label"in e&&"value"in e)}function $(t,e){const r=e??{status:"idle",options:Array.isArray(t.options)?t.options:null};return{...t,...r,options:r.options??(Array.isArray(t.options)?t.options:null)}}const Ee=S.createFactory(({client:t})=>{const e=C.store({}),r=g.createApi(e,{register(n,i){return{...n,[i.field.id]:i.field}},updateById(n,i){const a=n[i.fieldId];return a?{...n,[i.fieldId]:Object.assign({},a,i.updates)}:n}});function s(n){r.register({field:n})}function o(n,i){r.updateById({fieldId:n,updates:i})}const d=C.store({}),p=g.combine(e,d,(n,i)=>Object.values(n).map(a=>$(a,i[a.id])));function u(n){return g.combine(e,d,(i,a)=>{const m=i[n];return m?$(m,a[n]):null})}function f(n){return g.combine(e,d,(i,a)=>{const m=Object.values(i).find(w=>w.name===n);return m?$(m,a[m.id]):null})}const l=C.effect(async({fieldId:n,fieldOptions:i,context:a})=>{if(t&&!Array.isArray(i)&&i!==null){const m=await I.evaluateRuleLogic(t,i,a);return xe(m)?{fieldId:n,options:m}:{fieldId:n,options:null}}return{fieldId:n,options:Array.isArray(i)?i:null}});d.on(l,(n,{fieldId:i})=>{const a=n[i];return{...n,[i]:{status:"loading",options:a?.status==="resolved"?a.options:null}}}),d.on(l.doneData,(n,{fieldId:i,options:a})=>({...n,[i]:{status:"resolved",options:a}})),d.on(l.fail,(n,{params:{fieldId:i}})=>({...n,[i]:{status:"error",options:null,error:"Failed to resolve field options"}}));const h=g.createEvent();d.on(h,(n,i)=>({...n,[i]:{status:"waiting",options:null}}));const v=g.createEvent();t&&g.sample({clock:v,source:{states:d,fields:e},filter:({states:n},{fieldId:i,force:a})=>{if(a)return!0;const m=n[i];return!m||m.status==="idle"},fn:({fields:n},{fieldId:i,context:a})=>{const m=n[i]??null;return{fieldId:i,fieldOptions:m?.options??null,context:a}},target:l});function y(n,i){v({fieldId:n,force:i?.force,context:i?.context})}function c(n,i){for(const a of n)v({fieldId:a,force:i?.force,context:i?.context})}return{register:s,update:o,getById:u,listStore:p,getByName:f,resolve:y,resolveAll:c,setWaiting:h}});function Ae(t){return S.invoke(Ee,t??{})}const je=(t,e)=>{e.register(t)},Pe=g.createDomain("action"),Re=S.createFactory(({client:t})=>{const e=Pe.store({}),r=g.createApi(e,{register(u,f){return{...u,[f.name]:{name:f.name,action:f.action}}}});function s(u,f){r.register({name:u,action:f})}const o=e.map(u=>Object.values(u));function d(u){return e.map(f=>f[u],{skipVoid:!1})}function p(u){return e.map(f=>{const l=f[u];return l?l.action:void 0},{skipVoid:!1})}return{register:s,getByName:d,listStore:o,getEvokableAction:p}});function Ce(t){return S.invoke(Re,t)}const $e=(t,e,r)=>{r.register(t,e)};function B(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}function Be(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null}function L(t){try{return JSON.stringify(t),!0}catch{return!1}}const De=g.createDomain("response"),ze=S.createFactory(({client:t})=>{const e=De.store({}),r=g.createEvent(),s=g.createEvent(),o=g.createApi(e,{register(y,c){return{...y,[c.fieldId]:c.response}},registerBatch(y,c){return{...y,...c}},clear(y,c){const{[c]:n,...i}=y;return i},clearAll(){return{}}});function d(y,c){if(typeof y=="string"){if(c===void 0)throw new Error("Response is required when registering a single field");o.register({fieldId:y,response:c})}else o.registerBatch(y)}async function p(y){const c=[];return await Promise.allSettled(Object.entries(y).map(async([n,i])=>{let a=i;const m=t.fields.getById(n).getState();if(!m){c.push({fieldId:n,userMessage:`Field '${n}' not found`,systemMessage:`No field with ID '${n}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:a});return}if(m.multiple&&(typeof a=="string"||typeof a=="number"||typeof a=="boolean")&&(a=[a]),m.validation&&!J.isEmpty(m.validation)&&!B(a)){const w={...e.getState(),...y},F=await I.evaluateRuleLogic(t,m.validation,{$input:a,responses:w});if(typeof F=="string"){c.push({fieldId:n,userMessage:F,systemMessage:`Field validation resulted in an error: ${F}.`,value:a});return}if(F===!1){c.push({fieldId:n,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:a});return}}if(m.required&&B(a)){c.push({fieldId:n,userMessage:"This field is required",systemMessage:"Field is required.",value:a});return}if(!m.multiple&&Array.isArray(a)&&a.length>1){c.push({fieldId:n,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:a});return}if(m.type==="object"&&!B(a))if(m.multiple){if(!Array.isArray(a)){c.push({fieldId:n,userMessage:"This field expects multiple values",systemMessage:"Field expects an array of objects.",value:a});return}for(const w of a){if(typeof w!="object"||w===null){c.push({fieldId:n,userMessage:"This field expects object values",systemMessage:"Field expects an array of objects, but received non-object value.",value:a});return}if(!L(w)){c.push({fieldId:n,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:a});return}}}else{if(Array.isArray(a)){c.push({fieldId:n,userMessage:"This field expects a single value",systemMessage:"Field expects a single object, not an array.",value:a});return}if(typeof a!="object"||a===null){c.push({fieldId:n,userMessage:"This field expects an object value",systemMessage:"Field expects an object value.",value:a});return}if(!L(a)){c.push({fieldId:n,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:a});return}}if(Array.isArray(m.options)&&m.options.length>0){const w=Array.isArray(a)?a:[a];if(m.type==="object"){const F=m.options.map(x=>JSON.stringify(x.value));w.every(x=>F.includes(JSON.stringify(x)))||c.push({fieldId:n,userMessage:"This field expects a valid option",systemMessage:"Field expects a valid option from the defined choices.",value:a})}else{const F=m.options.map(x=>x.value);w.every(x=>!Be(x)||x===null?!1:F.includes(x))||c.push({fieldId:n,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${F.join(", ")}`,value:a})}}})),{responsesToCommit:y,validationErrors:c}}async function u(y){const{responsesToCommit:c,validationErrors:n}=await p(y);return n.length?{errors:n}:(o.registerBatch(c),{errors:[]})}const f=e.map(y=>y),l=e.map(y=>Object.keys(y).map(n=>({fieldId:n,value:y[n]})));function h(y){const c=t.fields.getById(y),n=e.map(i=>i[y]||null);return g.combine({f:c,r:n},({f:i,r:a})=>a||(i?.defaultValue?i.defaultValue:null))}function v(y){const c=t.fields.getByName(y);return g.combine({f:c,s:e},({f:n,s:i})=>{const a=n&&i[n.id]||null;return a||(n?.defaultValue?n.defaultValue:null)})}return g.sample({clock:r,target:o.clearAll}),g.sample({clock:s,target:o.clear}),{register:d,clearAll:r,clear:s,commit:u,getResponsesToCommit:p,listStore:l,getAllStore:f,getByFieldId:h,getByFieldName:v}});function Me(t){return S.invoke(ze,t)}function Oe(){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 Ue(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[o]of t.entries())o.startsWith("picked-")&&r.add(o);for(const o of r){const d=o.replace("picked-","");e[d]=t.getAll(o)}const s=b.createStorageKey("s");if(r.size>0)b.sessionStore.set(s,e);else{const o=b.sessionStore.get(s);if(o)return o.json()||{}}return e}function Le(){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=b.createStorageKey("session","global"),Ne=()=>{const t=b.localStore.get(Ve);let e;t.isSet()&&(e=t.json());const r=o=>t.set({id:o.id,isUser:o.isUser,identifiers:o.identifiers}),s={id:e?.id??Le(),isUser:e?.isUser??void 0,identifiers:e?.identifiers??void 0,setIsUser(o){this.isUser=o,r(this)},setIdentifier(o,d){this.identifiers={...this.identifiers,[o]:d},r(this)},removeIdentifier(o){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([d])=>d!==o)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(s),s},Te=()=>k.supportsLocalStorage()?Ne():null;function q(){if(k.supportsWindow())return globalThis.window.pickedConfig}function _e(){if(!k.supportsWindow())return;const t=q(),e=t?.organizationId,r=t?.projectId;return e&&r?{organizationId:e,projectId:r}:void 0}function qe(){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 He(t){const{organizationId:e,projectId:r}=t;if(e&&r)return{organizationId:e,projectId:r};const s=_e();if(s)return s;const o=qe();if(o)return o;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 g=require("effector"),S=require("@withease/factories"),F=require("../experience-instance-BX0aqKsC.cjs"),E=require("../logger-BsmHUUw1.cjs"),w=require("../storage-58NoTSsc.cjs"),L=require("../api-47L967ES.cjs"),G=require("../id-BKIWbSTy.cjs"),W=require("../object-mwaxtjLG.cjs"),k=require("../supports-YvpQZxbh.cjs"),N=g.createDomain("experience"),J=S.createFactory(({client:t,experience:e})=>{const r=N.store(e),n=g.createApi(r,{merge(l,h){return{...l,...h.experience}}}),a=r.map(l=>({name:l.name,decisionLogic:l.condition,targetSelectors:l.targets,initializeOpenLogic:e.initializeOpen})),d=t.components.listStore.map(l=>(e.componentName?l.find(h=>h.name===e.componentName):void 0)||l.find(h=>h.name===`experience:${e.id}`)||l.find(h=>h.name==="experience"),{skipVoid:!1}),p=r.map(l=>({steps:l.steps,nodes:l.nodes,edges:l.edges,conditionals:l.conditionals})),u=r.map(l=>l.fields),f=e.actions??[];return{id:e.id,configStore:a,treeStore:p,fieldsStore:u,componentStore:d,actions:f,merge:n.merge}});function Y(t){return S.invoke(J,t)}const Q=S.createFactory(({client:t})=>{const e=N.store({}),r=g.createApi(e,{register(f,l){return{...f,[l.id]:l}}});function n(f){const l=e.getState()[f.id];if(l){l.merge({experience:f,strategy:"override"});return}const h=Y({client:t,experience:f});r.register(h)}const a=e.map(f=>Object.values(f));function d(f){return e.map(l=>l[f],{skipVoid:!1})}const p=g.attach({source:e,effect:async(f,{id:l,options:h})=>{const v=f[l];if(!v){E.logger("warn",`Experience with id '${l}' not found.`);return}if(h?.bypassCondition){z(t,v,h);return}await T(t,v)&&z(t,v,h)}}),u=g.attach({source:t.experienceInstances.listStore,effect:(f,{id:l,options:h})=>{const v=f.filter(y=>y.experienceId===l);if(v.length>0)for(const y of v)y.open();else p({id:l,options:{...h,initialiseOpen:!0}})}});return{register:n,get:d,getById:d,launch:p,open:u,listStore:a}});function X(t){return S.invoke(Q,t)}const Z=(t,e)=>{e.register(t)},z=(t,e,r)=>{const{targetSelectors:n}=e.configStore.getState(),a=F.getTargetElements(n,e.id);a.forEach(({elements:p})=>p.forEach(u=>F.tagTargetElement(u,e.id))),F.createAppHosts(a,e.id).forEach(p=>{r?t.experienceInstances.spawn(e,p,r):t.experienceInstances.spawn(e,p)})},C=async t=>{await Promise.all(t.experiences.listStore.getState().map(async e=>{await T(t,e)&&z(t,e)}))},T=async(t,e)=>{if(!t.preconditionPassed||!t.session?.isUser)return!1;const{decisionLogic:r,targetSelectors:n}=e.configStore.getState();return F.getTargetElements(n,e.id).length<1||n.length===0?!1:r===void 0?!0:F.isRulesLogic(r)?await F.evaluateRuleLogic(t,r)===!0:!0},ee=(t,e,r)=>{const n=e.name,a=e.setup(t);if(a){const d=r[n]??{};r[n]=Object.freeze({...d,...a})}},te=g.createDomain("component"),re=S.createFactory(({client:t,component:e,name:r})=>{const n=t.frameworks.getByName(e.frameworkName);return{name:r,component:e,frameworkStore:n}});function se(t){return S.invoke(re,t)}const ne=S.createFactory(({client:t})=>{const e=te.store({}),r=g.createApi(e,{register(p,u){return{...p,[u.name]:u}}});function n(p,u){e.getState()[p]&&E.logger("warn",`Component '${p}' already registered. Registering again will override the previous registration.`);const l=se({client:t,name:p,component:u});r.register(l)}const a=e.map(p=>Object.values(p));function d(p){return e.map(u=>u[p],{skipVoid:!1})}return{register:n,getByName:d,listStore:a}});function oe(t){return S.invoke(ne,t)}const M=(t,e,r)=>{r.register(t,e)},ie=g.createDomain("framework"),ae=S.createFactory(({client:t})=>{const e=ie.store({}),r=g.createApi(e,{register(p,u){return{...p,[u.name]:u.framework}}});function n(p,u){e.getState()[p]&&E.logger("warn",`Framework '${p}' already registered. Registering again will override the previous registration.`),r.register({name:p,framework:u})}const a=e.map(p=>Object.values(p));function d(p){return e.map(u=>u[p],{skipVoid:!1})}return{register:n,getByName:d,listStore:a}});function ce(t){return S.invoke(ae,t)}const ue=(t,e)=>{e.register(t.name,t)},le=6e3,de=w.createStorageKey("last_ping","global"),pe=async t=>{try{const e=Date.now(),r=w.localStore.get(de);let n=0;if(r.isSet()&&(n=r.json()??0),n&&e-n<le)return!0;const a={projectId:t.projectId,path:window.location.pathname},d={},u=document.getElementById("picked_script")?.dataset.verceltoken;u&&(d["x-vercel-protection-bypass"]=u);const l=(await L.post(t.apiUrl,"ping",a,d)).ok;return l&&r.set(e),l}catch(e){return E.logger("error",e),!1}};function _(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 fe=g.createDomain("predicate"),ge=S.createFactory(({client:t})=>{const e=fe.store({}),r=g.createApi(e,{register(u,f){return{...u,[f.name]:{name:f.name,predicate:f.predicate}}}});function n(u,f){e.getState()[u]&&E.logger("warn",`Predicate '${u}' already registered. Registering again will override the previous registration.`),r.register(Object.freeze({name:u,predicate:f}))}const a=e.map(u=>Object.values(u));function d(u){return e.map(f=>f[u]?.predicate,{skipVoid:!1})}function p(u){const f=g.createStore(()=>{},{skipVoid:!1}),l=g.createEffect(async()=>{const h=d(u).getState();if(!h)return;const v=_(t);return(...y)=>h({...v,args:y})});return g.sample({source:{responses:t.responses.listStore,fields:t.fields.listStore},target:l}),g.sample({clock:l.doneData,filter:h=>h!==void 0,target:f}),l(),f}return{register:n,getByName:d,listStore:a,getEvokablePredicate:p}});function me(t){return S.invoke(ge,t)}const ye=(t,e,r)=>{r.register(t,e)},O=g.createDomain("feature"),he=S.createFactory(({client:t})=>{const e=O.store({}),r=O.store([]),n=g.createApi(e,{register(c,s){return{...c,[s.id]:s.feature}}});function a(c,s){e.getState()[c]&&E.logger("warn",`Feature '${c}' already registered. Registering again will override the previous registration.`);const i={id:c,feature:{...s,id:c}};n.register(Object.freeze({id:c,feature:i}))}const d=g.createEffect(async({id:c,key:s,storage:o="local"})=>{const i=w.createStorageKey(`feature:${c}:${s}`,"global"),b=(o==="session"?w.sessionStore:w.localStore).get(i).boolean();return b===null?null:{id:c,key:s,bucket:b,storage:o}}),p=g.createEffect(c=>{if(!c)return null;const s=w.createStorageKey(`feature:${c.id}:${c.key}`,"global");(c.storage==="session"?w.sessionStore:w.localStore).set(s,c.bucket)}),u=new Map,f=g.attach({source:{allFeaturesStore:e,resolvedFeaturesStore:r},effect:async({allFeaturesStore:c,resolvedFeaturesStore:s},{id:o,decide:i,key:m})=>{const b=s.find(P=>P.id===o&&P.key===m);if(b)return b;const I=c[o];if(!I)throw new Error(`Feature with id '${o}' not found`);const A=u.get(`${o}:${m}`);if(A!==void 0){const P=await A;return{id:I.id,bucket:P,key:m,storage:I.feature.storage}}const x=i();u.set(`${o}:${m}`,x);const K=await x;return{id:I.id,bucket:K,key:m,storage:I.feature.storage}}});g.sample({clock:n.register,fn:c=>{const{id:s,feature:o}=c;return{id:s,key:o.feature.key,storage:o.feature.storage}},target:d}),g.sample({source:e,clock:f.doneData,fn:(c,s)=>{const{id:o,bucket:i,storage:m}=s,b=c[o]?.feature.key;return b?{key:b,id:o,bucket:i,storage:m}:null},target:p});const l=g.combine({allFeaturesStore:e,resolvedFeaturesStore:r}).map(({allFeaturesStore:c,resolvedFeaturesStore:s})=>Object.values(c).map(o=>{const i=s.find(m=>m.id===o.id&&m.key===o.feature.key);return i?{id:o.id,name:o.feature.name,key:o.feature.key,getBucket:()=>({id:o.id,bucket:i.bucket}),isResolved:!0}:{id:o.id,name:o.feature.name,key:o.feature.key,getBucket:async()=>await f(o.feature),isResolved:!1}}));g.sample({clock:f.doneData,source:{resolvedFeatures:r},filter:({resolvedFeatures:c},{id:s,key:o})=>!c.some(m=>m.id===s&&m.key===o),fn:(c,s)=>s,target:t.eventBus.prepend(c=>({type:"feature_decide",feature:c}))}),g.sample({clock:[d.doneData,f.doneData],source:r,fn:(c,s)=>!s||c.some(i=>i.id===s.id&&i.key===s.key)?c:[...c,s],target:r});function h(c){return l.map(s=>s.find(o=>o.id===c))}function v(c){return e.map(s=>s[c],{skipVoid:!1})}function y(c){const s=g.createStore(async()=>{},{skipVoid:!1}),o=g.createEffect(async()=>{const i=h(c).getState();if(i)return async()=>(await i.getBucket()).bucket});return g.sample({source:r,filter:i=>i.some(m=>m.id===c),target:o}),g.sample({clock:o.doneData,filter:i=>i!==void 0,target:s}),o(),s}return{register:a,getById:h,getByName:v,listStore:l,getEvokableFeature:y}});function Se(t){return S.invoke(he,t)}const ve=(t,e,r)=>{r.register(t,e)},j=g.createDomain("history");function U(t,e){return{id:G.generateId(`history-entry-${Date.now()}-${Math.random()}}`),node:e,at:Date.now(),experienceId:t}}const ke=S.createFactory(()=>{const t=j.store({entries:[]}),e=j.event(),r=j.event(),n=j.event(),a=j.event();t.on(e,(p,u)=>({entries:[...p.entries,U(u.experienceId,u.node)]})),t.on(r,(p,u)=>({entries:[...p.entries.slice(0,-1),U(u.experienceId,u.node)]})),t.on(a,(p,u)=>u);function d(p,u){const f={lastStepIndex:-1,secondLastStepIndex:-1};for(let l=p.length-1;l>=0;l--){const h=p[l],v=h?.node;if(!(!v||!F.isStepNode(v))&&!(u&&h.experienceId!==u))if(f.lastStepIndex===-1)f.lastStepIndex=l;else{f.secondLastStepIndex=l;break}}return f}return t.on(n,(p,u)=>{const{secondLastStepIndex:f}=d(p.entries,u.experienceId),l=f!==-1?p.entries.slice(0,f+1):p.entries;return{...p,entries:l}}),{push:e,replace:r,back:n,restore:a,entriesStore:t.map(p=>p.entries)}});function be(){return S.invoke(ke)}let we=0;const Ie=t=>{const e=g.createStore([]);return g.sample({clock:t,source:e,fn:(r,n)=>[...r,{id:we++,at:new Date,payload:n}],target:e}),e},$=g.createDomain("field");function Fe(t){return Array.isArray(t)&&t.every(e=>typeof e=="object"&&e!==null&&"id"in e&&"label"in e&&"value"in e)}function B(t,e){const r=Array.isArray(t.options)?t.options:null,n=e??{status:"idle",options:r};return{...t,...n,options:n.options??r}}const xe=S.createFactory(({client:t})=>{const e=$.store({}),r=g.createApi(e,{register(s,o){return{...s,[o.field.id]:o.field}},updateById(s,o){const i=s[o.fieldId];return i?{...s,[o.fieldId]:Object.assign({},i,o.updates)}:s}});function n(s){r.register({field:s})}function a(s,o){r.updateById({fieldId:s,updates:o})}const d=$.store({}),p=g.combine(e,d,(s,o)=>Object.values(s).map(i=>B(i,o[i.id])));function u(s){return g.combine(e,d,(o,i)=>{const m=o[s];return m?B(m,i[s]):null})}function f(s){return g.combine(e,d,(o,i)=>{const m=Object.values(o).find(b=>b.name===s);return m?B(m,i[m.id]):null})}const l=$.effect(async({fieldId:s,fieldOptions:o,context:i})=>{if(t&&!Array.isArray(o)&&o!==null){const m=await F.evaluateRuleLogic(t,o,i);return Fe(m)?{fieldId:s,options:m}:{fieldId:s,options:null}}return{fieldId:s,options:Array.isArray(o)?o:null}});d.on(l,(s,{fieldId:o})=>{const i=s[o];return{...s,[o]:{status:"loading",options:i?.status==="resolved"?i.options:null}}}),d.on(l.doneData,(s,{fieldId:o,options:i})=>({...s,[o]:{status:"resolved",options:i}})),d.on(l.fail,(s,{params:{fieldId:o}})=>({...s,[o]:{status:"error",options:null,error:"Failed to resolve field options"}}));const h=g.createEvent();d.on(h,(s,o)=>({...s,[o]:{status:"waiting",options:null}}));const v=g.createEvent();t&&g.sample({clock:v,source:{states:d,fields:e},filter:({states:s},{fieldId:o,force:i})=>{if(i)return!0;const m=s[o];return!m||m.status==="idle"},fn:({fields:s},{fieldId:o,context:i})=>{const m=s[o]??null;return{fieldId:o,fieldOptions:m?.options??null,context:i}},target:l});function y(s,o){v({fieldId:s,force:o?.force,context:o?.context})}function c(s,o){for(const i of s)v({fieldId:i,force:o?.force,context:o?.context})}return{register:n,update:a,getById:u,listStore:p,getByName:f,resolve:y,resolveAll:c,setWaiting:h}});function Ee(t){return S.invoke(xe,t??{})}const je=(t,e)=>{e.register(t)},Ae=g.createDomain("action"),Pe=S.createFactory(({client:t})=>{const e=Ae.store({}),r=g.createApi(e,{register(u,f){return{...u,[f.name]:{name:f.name,action:f.action}}}});function n(u,f){r.register({name:u,action:f})}const a=e.map(u=>Object.values(u));function d(u){return e.map(f=>f[u],{skipVoid:!1})}function p(u){return e.map(f=>{const l=f[u];return l?l.action:void 0},{skipVoid:!1})}return{register:n,getByName:d,listStore:a,getEvokableAction:p}});function Re(t){return S.invoke(Pe,t)}const $e=(t,e,r)=>{r.register(t,e)};function D(t){return typeof t>"u"||t===null||t===""||Array.isArray(t)&&!t.length}function Be(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||t===null}function V(t){try{return JSON.stringify(t),!0}catch{return!1}}const De=g.createDomain("response"),ze=S.createFactory(({client:t})=>{const e=De.store({}),r=g.createEvent(),n=g.createEvent(),a=g.createApi(e,{register(y,c){return{...y,[c.fieldId]:c.response}},registerBatch(y,c){return{...y,...c}},clear(y,c){const{[c]:s,...o}=y;return o},clearAll(){return{}}});function d(y,c){if(typeof y=="string"){if(c===void 0)throw new Error("Response is required when registering a single field");a.register({fieldId:y,response:c})}else a.registerBatch(y)}async function p(y){const c=[];return await Promise.allSettled(Object.entries(y).map(async([s,o])=>{let i=o;const m=t.fields.getById(s).getState();if(!m){c.push({fieldId:s,userMessage:`Field '${s}' not found`,systemMessage:`No field with ID '${s}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,value:i});return}if(m.multiple&&(typeof i=="string"||typeof i=="number"||typeof i=="boolean")&&(i=[i]),m.validation&&!W.isEmpty(m.validation)&&!D(i)){const b={...e.getState(),...y},I=await F.evaluateRuleLogic(t,m.validation,{$input:i,responses:b});if(typeof I=="string"){c.push({fieldId:s,userMessage:I,systemMessage:`Field validation resulted in an error: ${I}.`,value:i});return}if(I===!1){c.push({fieldId:s,userMessage:"This field is invalid",systemMessage:"Field validation resulted in an unspecified error.",value:i});return}}if(m.required&&D(i)){c.push({fieldId:s,userMessage:"This field is required",systemMessage:"Field is required.",value:i});return}if(!m.multiple&&Array.isArray(i)&&i.length>1){c.push({fieldId:s,userMessage:"This field expects a single response",systemMessage:"Field expects a single response.",value:i});return}if(m.type==="object"&&!D(i))if(m.multiple){if(!Array.isArray(i)){c.push({fieldId:s,userMessage:"This field expects multiple values",systemMessage:"Field expects an array of objects.",value:i});return}for(const b of i){if(typeof b!="object"||b===null){c.push({fieldId:s,userMessage:"This field expects object values",systemMessage:"Field expects an array of objects, but received non-object value.",value:i});return}if(!V(b)){c.push({fieldId:s,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:i});return}}}else{if(Array.isArray(i)){c.push({fieldId:s,userMessage:"This field expects a single value",systemMessage:"Field expects a single object, not an array.",value:i});return}if(typeof i!="object"||i===null){c.push({fieldId:s,userMessage:"This field expects an object value",systemMessage:"Field expects an object value.",value:i});return}if(!V(i)){c.push({fieldId:s,userMessage:"This field contains non-serializable data",systemMessage:"Field value contains non-JSON-serializable data (functions, circular references, etc.).",value:i});return}}if(Array.isArray(m.options)&&m.options.length>0){const b=Array.isArray(i)?i:[i];if(m.type==="object"){const I=m.options.map(x=>JSON.stringify(x.value));b.every(x=>I.includes(JSON.stringify(x)))||c.push({fieldId:s,userMessage:"This field expects a valid option",systemMessage:"Field expects a valid option from the defined choices.",value:i})}else{const I=m.options.map(x=>x.value);b.every(x=>!Be(x)||x===null?!1:I.includes(x))||c.push({fieldId:s,userMessage:"This field expects a valid option",systemMessage:`Field expects a valid option. Valid options are: ${I.join(", ")}`,value:i})}}})),{responsesToCommit:y,validationErrors:c}}async function u(y){const{responsesToCommit:c,validationErrors:s}=await p(y);return s.length?{errors:s}:(a.registerBatch(c),{errors:[]})}const f=e.map(y=>y),l=e.map(y=>Object.keys(y).map(s=>({fieldId:s,value:y[s]})));function h(y){const c=t.fields.getById(y),s=e.map(o=>o[y]||null);return g.combine({f:c,r:s},({f:o,r:i})=>i||(o?.defaultValue?o.defaultValue:null))}function v(y){const c=t.fields.getByName(y);return g.combine({f:c,s:e},({f:s,s:o})=>{const i=s&&o[s.id]||null;return i||(s?.defaultValue?s.defaultValue:null)})}return g.sample({clock:r,target:a.clearAll}),g.sample({clock:n,target:a.clear}),{register:d,clearAll:r,clear:n,commit:u,getResponsesToCommit:p,listStore:l,getAllStore:f,getByFieldId:h,getByFieldName:v}});function Ce(t){return S.invoke(ze,t)}function Me(){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 Oe(){if(!k.supportsWindow())return{};const t=new URLSearchParams(window.location.search),e={},r=new Set;for(const[a]of t.entries())a.startsWith("picked-")&&r.add(a);for(const a of r){const d=a.replace("picked-","");e[d]=t.getAll(a)}const n=w.createStorageKey("s");if(r.size>0)w.sessionStore.set(n,e);else{const a=w.sessionStore.get(n);if(a)return a.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),n=Math.random().toString(36).substring(2,15);return`${t}-${e}-${r}-${n}`}const Ve=w.createStorageKey("session","global"),Le=()=>{const t=w.localStore.get(Ve);let e;t.isSet()&&(e=t.json());const r=a=>t.set({id:a.id,isUser:a.isUser,identifiers:a.identifiers}),n={id:e?.id??Ue(),isUser:e?.isUser??void 0,identifiers:e?.identifiers??void 0,setIsUser(a){this.isUser=a,r(this)},setIdentifier(a,d){this.identifiers={...this.identifiers,[a]:d},r(this)},removeIdentifier(a){this.identifiers&&(this.identifiers=Object.fromEntries(Object.entries(this.identifiers).filter(([d])=>d!==a)),this.identifiers=Object.keys(this.identifiers).length?this.identifiers:void 0,r(this))}};return r(n),n},Ne=()=>k.supportsLocalStorage()?Le():null;function q(){if(k.supportsWindow())return globalThis.window.pickedConfig}function Te(){if(!k.supportsWindow())return;const t=q(),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 n=Te();if(n)return n;const a=_e();if(a)return a;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
|
|
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 He={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(([n,a])=>`${n}: ${a}`);return e.format(r)}return t instanceof Set?e.format(Array.from(t).map(String)):t}};function Ke(t){return typeof t=="object"&&t!==null}function Ge(t,e){let r=e;for(const n of t.split("."))if(Ke(r)&&n in r)r=r[n];else return;return typeof r=="function"?r():r}function We(t,e){const r=t.split("|").map(d=>d.trim()),n=r.shift()??"";let a=Ge(n,e);for(const d of r){const[p,...u]=d.split(":"),f=p?.trim()??"",l=u.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g,""),h=He[f];h&&(a=h(a,l))}return R(a)?"":typeof a=="object"?JSON.stringify(a):String(a)}function Je(t,e){let r="",n=0;for(;n<t.length;)if(t[n]==="{"&&t[n+1]==="{"){n+=2;let a="";for(;n<t.length;){if(t[n]==="}"&&t[n+1]==="}"){n+=2;break}a+=t[n++]}r+=We(a.trim(),e)}else r+=t[n++];return r}class H{static logger=E.logger;options;isReady=!1;project;plugins={};pluginStartHooks=[];eventBus=g.createEvent();events;organizationId;projectId;apiUrl;dashboardUrl;documentationSiteUrl;session;precondition;condition;preconditionPassed;searchParams=Oe();history=be();components=oe({client:this});experienceInstances=F.createExperienceInstanceIndex({client:this});experiences=X({client:this});frameworks=ce({client:this});predicates=me({client:this});features=Se({client:this});responses=Ce({client:this});fields=Ee({client:this});actions=Re({client:this});constructor(e){E.logger("info","Picked client initializing."),this.events=Ie(this.eventBus);const{organizationId:r,projectId:n}=qe(e);this.organizationId=r,this.projectId=n,this.options=Object.freeze(e),this.apiUrl=e.apiUrl||Me(),this.dashboardUrl=e.dashboardUrl??"https://dashboard.picked.app",this.documentationSiteUrl=e.documentationSiteUrl??"https://docs.picked.app",this.session=Ne(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.setupComponents(),this.precondition=e.precondition,this.condition=e.condition,this.eventBus({type:"load",version:L.getVersion()}),E.logger("info","Picked client initialized.")}start=()=>{pe(this),(async()=>{if(!k.supportsDocument())return;await this.runPluginStartHooks();const r=await this.evaluateGate(this.precondition);this.preconditionPassed=r;let n;r&&(n=await this.evaluateGate(this.condition));const a=r&&n===!0;if(typeof n=="boolean"&&this.session){const d=n;this.session.setIsUser(d),this.eventBus({type:"user_decide",value:d})}if(this.eventBus({type:"initialize"}),a&&C(this),await F.domInteractive(),a&&C(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session){const{id:d,isUser:p,identifiers:u}=this.session;this.eventBus({type:"session",id:d,isUser:p,identifiers:u})}})()};registerFramework=e=>{ue(e,this.frameworks)};registerComponent=(e,r)=>{M(e,r,this.components)};registerPlugin=e=>{ee(this,e,this.plugins);const r=this.plugins[e.name];r?.onStart&&this.pluginStartHooks.push(r.onStart)};registerFeature=(e,r)=>{ve(e,r,this.features)};registerPredicate=(e,r)=>{ye(e,r,this.predicates)};registerField=e=>{je(e,this.fields)};registerAction=(e,r)=>{$e(e,r,this.actions)};registerExperience=e=>{e.component&&M(`experience:${e.id}`,e.component,this.components),Z(e,this.experiences)};getStateSnapshot=()=>_(this);launchExperienceById=async(e,r)=>{this.experiences.launch({id:e,options:r})};openExperienceById=async e=>{this.experiences.open({id:e})};async runPluginStartHooks(){for(const e of this.pluginStartHooks)await e()}async evaluateGate(e){return e===void 0?!0:typeof e=="boolean"?e:await F.evaluateRuleLogic(this,e)===!0}setupPlugins(){this.options.plugins?.forEach(e=>{if(Array.isArray(e)){e.forEach(n=>{this.registerPlugin(n)});return}const r=typeof e=="function"?e():e;if(Array.isArray(r)){r.forEach(n=>this.registerPlugin(n));return}this.registerPlugin(r)})}setupFeatures(){const e=this.options.features;e&&(Object.entries(e).forEach(([r,n])=>{const a=typeof n=="function"?n():n;this.registerFeature(r,a)}),this.searchParams.feature&&this.searchParams.feature.forEach(r=>{try{const[n,a]=r.split(":");if(!n||!a)return;let d=a;d==="true"&&(d=!0),d==="false"&&(d=!1),this.registerFeature(n,{key:`${d}`,name:n,decide:()=>d,storage:"session"})}catch{}}))}setupPredicates(){const e=this.options.predicates;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){E.logger("warn",`Predicate "${r}" is not a function.`);return}this.registerPredicate(r,n)})}setupActions(){const e=this.options.actions;e&&Object.entries(e).forEach(([r,n])=>{if(typeof n!="function"){E.logger("warn",`Action "${r}" is not a function.`);return}this.registerAction(r,n)})}setupComponents(){const e=this.options.components;e&&Object.entries(e).forEach(([r,n])=>{this.registerComponent(r,n)})}getPluginConfig=e=>this.plugins[e]??{};renderString=(e,r)=>{const n=this.responses.listStore.getState().reduce((a,d)=>(a[d.fieldId]=d.value,a),{});return Je(e,{...r,responses:n})}}function Ye(t){return{$$type:"lazy-component",load:t}}function Qe(t){return typeof t=="object"&&t!==null&&"$$type"in t&&t.$$type==="lazy-component"}const Xe=t=>{const e=new H(t);return k.bindClient(e),e};exports.evaluateRuleLogic=F.evaluateRuleLogic;exports.isPickedRoot=F.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=H;exports.createClient=Xe;exports.getPickedConfig=q;exports.isLazyLoader=Qe;exports.lazyComponent=Ye;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../../../id-BKIWbSTy.cjs"),l={serialize(e){return JSON.stringify(e)},deserialize(e){return JSON.parse(e)}},y=e=>({name:"create-experience",setup:d=>{e.experiences.forEach(o=>{const s=o.serialize(),r=l.deserialize(s);r.component=o.component,d.registerExperience(r),r.fields.forEach(f=>{d.registerField(f)})})}}),z=(e,d)=>({id:p.generateId("node"),experience:d,type:"action",action:e.action,addNext(s){if(!s.node)throw new Error("Cannot connect to node");const r=c({sourceNode:this,destinationNode:s.node,sourceNodeHandle:null},d);d.edges.push(r)},onSuccess(s){if(!s.node)throw new Error("Cannot connect to node");const r=c({sourceNode:this,destinationNode:s.node,sourceNodeHandle:"true"},d);d.edges.push(r)},onFail(s){if(!s.node)throw new Error("Cannot connect to node");const r=c({sourceNode:this,destinationNode:s.node,sourceNodeHandle:"false"},d);d.edges.push(r)},serialize(){return l.serialize({id:this.id,type:this.type,action:this.action})}}),m=e=>({id:e.id??p.generateId("step"),label:e.label,fields:e.fields??[],addField(d){const o="serialize"in d?d:g(d);return this.fields.includes(o)||this.fields.push(o),o}}),b=(e,d)=>{const o={id:e.id??p.generateId("step"),label:e.label,experience:d,fields:e.fields??[],node:null,nextStep(s){return this.experience.addStep(s,this)},nextConditional(s){return this.experience.addConditional(s,this)},addNextExperience(s){return this.experience.addExperience(s,this)},addField(s){return this.experience.addField(s,this)},serialize(){return l.serialize({id:this.id,label:this.label,fieldIds:this.fields.map(s=>s.id)})}};return h({step:o,type:"step"},d),o},h=(e,d)=>{const o={id:p.generateId("node"),experience:d};if(e.type==="step"){const r={...o,type:"step",connectedStep:e.step,serialize(){return l.serialize({id:this.id,type:this.type,stepId:this.connectedStep.id,label:this.connectedStep.label})}};return r.connectedStep.node=r,r}if(e.type==="conditional"){const r={...o,type:"conditional",connectedConditional:e.conditional,serialize(){return l.serialize({id:this.id,type:this.type,conditionalId:this.connectedConditional.id})}};return r.connectedConditional.node=r,r}return e.type==="experience"?{...o,type:"experience",connectedExperience:e.experience,serialize(){return l.serialize({id:this.id,type:this.type,experienceId:this.connectedExperience.id})}}:{...o,type:"origin",serialize(){return l.serialize({id:this.id,type:this.type})}}},c=(e,d)=>({id:p.generateId("edge"),sourceNode:e.sourceNode,sourceNodeHandle:e.sourceNodeHandle,destinationNode:e.destinationNode,experience:d,serialize(){return l.serialize({id:this.id,sourceNodeHandle:this.sourceNodeHandle??void 0,sourceNodeId:this.sourceNode.id,destinationNodeId:this.destinationNode.id})}}),N=(e,d)=>{const o={id:p.generateId("conditional"),label:e.label,condition:e.condition,node:null,experience:d,addTrue(s){if(!this.node||!s.node)throw new Error("todo no node");const r=c({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"true"},this.experience);this.experience.edges.push(r)},addFalse(s){if(!this.node||!s.node)throw new Error("todo no node");const r=c({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"false"},this.experience);this.experience.edges.push(r)},serialize(){return l.serialize({id:this.id,label:this.label,condition:this.condition})}};return h({conditional:o,type:"conditional"},d),o},g=e=>({id:e.id,name:e.name,type:e.type,label:e.label,placeholder:e.placeholder,description:e.description,helpText:e.helpText,defaultValue:e.defaultValue??null,multiple:e.multiple,validation:e.validation??{},condition:e.condition,required:e.required,options:Array.isArray(e.options)?e.options.map(({id:o,...s})=>({id:o??p.generateId("option"),...s})):e.options??null,dependsOn:e.dependsOn,policies:e.policies,serialize(){const o={id:this.id,name:this.name,label:this.label,placeholder:this.placeholder,required:this.required,description:this.description,helpText:this.helpText,validation:this.validation,condition:this.condition,dependsOn:this.dependsOn,policies:this.policies},s=typeof this.defaultValue=="string"?this.defaultValue:void 0,r=typeof this.defaultValue=="number"?this.defaultValue:void 0,f=typeof this.defaultValue=="boolean"?this.defaultValue:void 0,n=t=>this.options?Array.isArray(this.options)?this.options.map(i=>({id:i.id,label:i.label,description:i.description,value:t(i.value),condition:i.condition})):this.options:null;switch(this.type){case"text":if(this.multiple){let t;if(Array.isArray(this.defaultValue)){t=[];for(const i of this.defaultValue)typeof i=="string"&&t.push(i);t.length===0&&(t=void 0)}return l.serialize({...o,type:"text",multiple:!0,defaultValue:t,options:n(i=>`${i}`)})}return l.serialize({...o,type:"text",multiple:!1,defaultValue:s,options:n(t=>`${t}`)});case"number":if(this.multiple){let t;if(Array.isArray(this.defaultValue)){t=[];for(const i of this.defaultValue)typeof i=="number"&&t.push(i);t.length===0&&(t=void 0)}return l.serialize({...o,type:"number",multiple:!0,defaultValue:t,options:n(i=>Number(i))})}return l.serialize({...o,type:"number",multiple:!1,defaultValue:r,options:n(t=>Number(t))});case"boolean":if(this.multiple){let t;if(Array.isArray(this.defaultValue)){t=[];for(const i of this.defaultValue)typeof i=="boolean"&&t.push(i);t.length===0&&(t=void 0)}return l.serialize({...o,type:"boolean",multiple:!0,defaultValue:t,options:n(i=>!!i)})}return l.serialize({...o,type:"boolean",multiple:!1,defaultValue:f,options:n(t=>!!t)});case"object":return this.multiple?l.serialize({...o,type:"object",multiple:!0,defaultValue:this.defaultValue,options:n(t=>t)}):l.serialize({...o,type:"object",multiple:!1,defaultValue:this.defaultValue,options:n(t=>t)});default:throw new Error("Unsupported field type")}}}),x=e=>{const d=[],o=[],s=[],r=[],f=[];return{id:e.id,component:e.component,name:e.name,initializeOpen:e.initializeOpen,condition:e.condition,targets:e.targets,steps:d,nodes:o,edges:s,fields:f,conditionals:r,addStep(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a="serialize"in n?n:b(n,this);if(i){if(!a.node)throw new Error("todo no node");const u=c({sourceNode:i,destinationNode:a.node,sourceNodeHandle:null},this);this.edges.push(u)}return a.fields.length>0&&a.fields.forEach(u=>{this.fields.includes(u)||this.fields.push(u)}),this.steps.includes(a)||(this.steps.push(a),a.node&&this.nodes.push(a.node)),a},addAction(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a="serialize"in n?n:z(n,this);if(i){const u=c({sourceNode:i,destinationNode:a,sourceNodeHandle:null},this);this.edges.push(u)}return this.nodes.push(a),a},addConditional(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a="serialize"in n?n:N(n,this);if(i){if(!a.node)throw new Error("todo no node");const u=c({sourceNode:i,destinationNode:a.node,sourceNodeHandle:null},this);this.edges.push(u)}return this.conditionals.includes(a)||(this.conditionals.push(a),a.node&&this.nodes.push(a.node)),a},addExperience(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a=h({type:"experience",experience:n},this);if(this.nodes.push(a),i){const u=c({sourceNode:i,destinationNode:a,sourceNodeHandle:null},this);this.edges.push(u)}return n},addField(n,t){const i="serialize"in n?n:g(n);return t&&t.fields.push(i),this.fields.includes(i)||this.fields.push(i),i},serialize(){return l.serialize({id:this.id,component:this.component,name:this.name,initializeOpen:this.initializeOpen,condition:this.condition,targets:this.targets,steps:this.steps.map(n=>l.deserialize(n.serialize())),nodes:this.nodes.map(n=>l.deserialize(n.serialize())),edges:this.edges.map(n=>l.deserialize(n.serialize())),conditionals:this.conditionals.map(n=>l.deserialize(n.serialize())),fields:this.fields.map(n=>l.deserialize(n.serialize()))})}}};exports.createConditional=N;exports.createEdge=c;exports.createExperience=x;exports.createExperiencePlugin=y;exports.createField=g;exports.createNode=h;exports.createStep=m;exports.serialization=l;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../../../id-BKIWbSTy.cjs"),l={serialize(e){return JSON.stringify(e)},deserialize(e){return JSON.parse(e)}},y=e=>({name:"create-experience",setup:d=>{e.experiences.forEach(o=>{const s=o.serialize(),r=l.deserialize(s);r.component=o.component,d.registerExperience(r),r.fields.forEach(f=>{d.registerField(f)})})}}),z=(e,d)=>({id:p.generateId("node"),experience:d,type:"action",action:e.action,addNext(s){if(!s.node)throw new Error("Cannot connect to node");const r=c({sourceNode:this,destinationNode:s.node,sourceNodeHandle:null},d);d.edges.push(r)},onSuccess(s){if(!s.node)throw new Error("Cannot connect to node");const r=c({sourceNode:this,destinationNode:s.node,sourceNodeHandle:"true"},d);d.edges.push(r)},onFail(s){if(!s.node)throw new Error("Cannot connect to node");const r=c({sourceNode:this,destinationNode:s.node,sourceNodeHandle:"false"},d);d.edges.push(r)},serialize(){return l.serialize({id:this.id,type:this.type,action:this.action})}}),m=e=>({id:e.id??p.generateId("step"),label:e.label,fields:e.fields??[],addField(d){const o="serialize"in d?d:g(d);return this.fields.includes(o)||this.fields.push(o),o}}),b=(e,d)=>{const o={id:e.id??p.generateId("step"),label:e.label,experience:d,fields:e.fields??[],node:null,nextStep(s){return this.experience.addStep(s,this)},nextConditional(s){return this.experience.addConditional(s,this)},addNextExperience(s){return this.experience.addExperience(s,this)},addField(s){return this.experience.addField(s,this)},serialize(){return l.serialize({id:this.id,label:this.label,fieldIds:this.fields.map(s=>s.id)})}};return h({step:o,type:"step"},d),o},h=(e,d)=>{const o={id:p.generateId("node"),experience:d};if(e.type==="step"){const r={...o,type:"step",connectedStep:e.step,serialize(){return l.serialize({id:this.id,type:this.type,stepId:this.connectedStep.id,label:this.connectedStep.label})}};return r.connectedStep.node=r,r}if(e.type==="conditional"){const r={...o,type:"conditional",connectedConditional:e.conditional,serialize(){return l.serialize({id:this.id,type:this.type,conditionalId:this.connectedConditional.id})}};return r.connectedConditional.node=r,r}return e.type==="experience"?{...o,type:"experience",connectedExperience:e.experience,serialize(){return l.serialize({id:this.id,type:this.type,experienceId:this.connectedExperience.id})}}:{...o,type:"origin",serialize(){return l.serialize({id:this.id,type:this.type})}}},c=(e,d)=>({id:p.generateId("edge"),sourceNode:e.sourceNode,sourceNodeHandle:e.sourceNodeHandle,destinationNode:e.destinationNode,experience:d,serialize(){return l.serialize({id:this.id,sourceNodeHandle:this.sourceNodeHandle??void 0,sourceNodeId:this.sourceNode.id,destinationNodeId:this.destinationNode.id})}}),N=(e,d)=>{const o={id:p.generateId("conditional"),label:e.label,condition:e.condition,node:null,experience:d,addTrue(s){if(!this.node||!s.node)throw new Error("todo no node");const r=c({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"true"},this.experience);this.experience.edges.push(r)},addFalse(s){if(!this.node||!s.node)throw new Error("todo no node");const r=c({sourceNode:this.node,destinationNode:s.node,sourceNodeHandle:"false"},this.experience);this.experience.edges.push(r)},serialize(){return l.serialize({id:this.id,label:this.label,condition:this.condition})}};return h({conditional:o,type:"conditional"},d),o},g=e=>({id:e.id,name:e.name,type:e.type,label:e.label,placeholder:e.placeholder,description:e.description,helpText:e.helpText,defaultValue:e.defaultValue??null,multiple:e.multiple,validation:e.validation??{},condition:e.condition,required:e.required,options:Array.isArray(e.options)?e.options.map(({id:o,...s})=>({id:o??p.generateId("option"),...s})):e.options??null,dependsOn:e.dependsOn,policies:e.policies,serialize(){const o={id:this.id,name:this.name,label:this.label,placeholder:this.placeholder,required:this.required,description:this.description,helpText:this.helpText,validation:this.validation,condition:this.condition,dependsOn:this.dependsOn,policies:this.policies},s=typeof this.defaultValue=="string"?this.defaultValue:void 0,r=typeof this.defaultValue=="number"?this.defaultValue:void 0,f=typeof this.defaultValue=="boolean"?this.defaultValue:void 0,n=t=>this.options?Array.isArray(this.options)?this.options.map(i=>({id:i.id,label:i.label,description:i.description,value:t(i.value),condition:i.condition})):this.options:null;switch(this.type){case"text":if(this.multiple){let t;if(Array.isArray(this.defaultValue)){t=[];for(const i of this.defaultValue)typeof i=="string"&&t.push(i);t.length===0&&(t=void 0)}return l.serialize({...o,type:"text",multiple:!0,defaultValue:t,options:n(i=>`${i}`)})}return l.serialize({...o,type:"text",multiple:!1,defaultValue:s,options:n(t=>`${t}`)});case"number":if(this.multiple){let t;if(Array.isArray(this.defaultValue)){t=[];for(const i of this.defaultValue)typeof i=="number"&&t.push(i);t.length===0&&(t=void 0)}return l.serialize({...o,type:"number",multiple:!0,defaultValue:t,options:n(i=>Number(i))})}return l.serialize({...o,type:"number",multiple:!1,defaultValue:r,options:n(t=>Number(t))});case"boolean":if(this.multiple){let t;if(Array.isArray(this.defaultValue)){t=[];for(const i of this.defaultValue)typeof i=="boolean"&&t.push(i);t.length===0&&(t=void 0)}return l.serialize({...o,type:"boolean",multiple:!0,defaultValue:t,options:n(i=>!!i)})}return l.serialize({...o,type:"boolean",multiple:!1,defaultValue:f,options:n(t=>!!t)});case"object":return this.multiple?l.serialize({...o,type:"object",multiple:!0,defaultValue:this.defaultValue,options:n(t=>t)}):l.serialize({...o,type:"object",multiple:!1,defaultValue:this.defaultValue,options:n(t=>t)});default:throw new Error("Unsupported field type")}}}),x=e=>{const d=[],o=[],s=[],r=[],f=[];return{id:e.id,component:e.component,name:e.name,initializeOpen:e.initializeOpen,condition:e.decide??e.condition,targets:e.targets,steps:d,nodes:o,edges:s,fields:f,conditionals:r,addStep(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a="serialize"in n?n:b(n,this);if(i){if(!a.node)throw new Error("todo no node");const u=c({sourceNode:i,destinationNode:a.node,sourceNodeHandle:null},this);this.edges.push(u)}return a.fields.length>0&&a.fields.forEach(u=>{this.fields.includes(u)||this.fields.push(u)}),this.steps.includes(a)||(this.steps.push(a),a.node&&this.nodes.push(a.node)),a},addAction(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a="serialize"in n?n:z(n,this);if(i){const u=c({sourceNode:i,destinationNode:a,sourceNodeHandle:null},this);this.edges.push(u)}return this.nodes.push(a),a},addConditional(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a="serialize"in n?n:N(n,this);if(i){if(!a.node)throw new Error("todo no node");const u=c({sourceNode:i,destinationNode:a.node,sourceNodeHandle:null},this);this.edges.push(u)}return this.conditionals.includes(a)||(this.conditionals.push(a),a.node&&this.nodes.push(a.node)),a},addExperience(n,t){let i=t?.node;this.nodes.length===0&&(i=h({type:"origin"},this),this.nodes.push(i));const a=h({type:"experience",experience:n},this);if(this.nodes.push(a),i){const u=c({sourceNode:i,destinationNode:a,sourceNodeHandle:null},this);this.edges.push(u)}return n},addField(n,t){const i="serialize"in n?n:g(n);return t&&t.fields.push(i),this.fields.includes(i)||this.fields.push(i),i},serialize(){return l.serialize({id:this.id,component:this.component,name:this.name,initializeOpen:this.initializeOpen,condition:this.condition,targets:this.targets,steps:this.steps.map(n=>l.deserialize(n.serialize())),nodes:this.nodes.map(n=>l.deserialize(n.serialize())),edges:this.edges.map(n=>l.deserialize(n.serialize())),conditionals:this.conditionals.map(n=>l.deserialize(n.serialize())),fields:this.fields.map(n=>l.deserialize(n.serialize()))})}}};exports.createConditional=N;exports.createEdge=c;exports.createExperience=x;exports.createExperiencePlugin=y;exports.createField=g;exports.createNode=h;exports.createStep=m;exports.serialization=l;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../../api-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../../api-47L967ES.cjs"),a=require("../../../logger-BsmHUUw1.cjs");function d(e){let r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=Math.imul(r,16777619);return r>>>0}function g(e){return d(e)%100}function p(e,r){return r<=0?!1:r>=100?!0:e<r}function h(e){return typeof e!="object"||e===null||!("id"in e&&"name"in e&&"enabled"in e&&"weight"in e&&"version"in e)?!1:typeof e.id=="string"&&typeof e.name=="string"&&typeof e.enabled=="boolean"&&typeof e.weight=="number"&&typeof e.version=="number"}function l(e){return typeof e!="object"||e===null||!("features"in e)||!Array.isArray(e.features)?!1:e.features.every(h)}function y(e){const r=e.searchParams["preview-token"];if(r&&r.length>0)return r[0]}function m(e){const r=new Set,n=e.searchParams.feature;if(!n)return r;for(const i of n){const t=i.indexOf(":");t>0&&r.add(i.substring(0,t))}return r}function c(e,r,n){const i=m(e),t=e.session?.id;if(!t)throw new Error("Session ID is required for feature registration");const o=g(t);for(const s of r.features)i.has(s.id)||v(e,s,n,o)}function v(e,r,n,i){e.registerFeature(r.id,{key:`v${r.version}`,name:r.name,storage:n?"session":"local",decide:()=>r.enabled?p(i,r.weight):!1})}function w(){let e;try{e=__PICKED_PROJECT_CONFIG__}catch{return}if(e===void 0)return;let r;if(typeof e=="string")try{r=JSON.parse(e)}catch{a.logger("warn","Build-time project config is not valid JSON");return}else r=e;if(l(r))return r;a.logger("warn","Build-time project config has invalid shape, falling back to runtime fetch")}function j(e){try{const r=new URL(e).hostname;return r==="localhost"||r==="127.0.0.1"||r==="::1"}catch{return!1}}function b(e){if(typeof e!="object"||e===null||!("cause"in e))return!1;const{cause:r}=e;return typeof r!="object"||r===null||!("code"in r)?!1:r.code==="ECONNREFUSED"}async function u(e,r,n){const i=n?.previewToken?`projects/${r}?preview_token=${encodeURIComponent(n.previewToken)}`:`projects/${r}`;let t;try{t=await f.get(e,i,n?.headers)}catch(s){return j(e)&&b(s)||a.logger("warn","Failed to fetch project config",s),null}if(!t.ok)return a.logger("warn",`Project config request failed with status ${t.status.toString()}`),null;let o;try{o=await t.json()}catch{return a.logger("warn","Failed to parse project config response"),null}return l(o)?o:(a.logger("warn","Invalid project config response shape"),null)}function P(e){return{name:"dynamic-experiences",setup:r=>{const n=e?.apiUrl??r.apiUrl;return{onStart:async()=>{const i=y(r);if(i){const s=await u(n,r.projectId,{previewToken:i});s&&c(r,s,!0);return}const t=e?.projectConfig??w();if(t){c(r,t,!1);return}const o=await u(n,r.projectId);o&&c(r,o,!1)}}}}}exports.createClientHeaders=f.createClientHeaders;exports.dynamicExperiencesPlugin=P;exports.fetchProject=u;
|