@picked/client 0.0.1-dev.1769486944066 → 0.0.1-dev.1769554766412
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../user-session-DQh0BBTx.cjs"),d=require("../logger-BsmHUUw1.cjs"),p=require("../experience-instance-CsMhH0DN.cjs"),S=require("effector"),c=require("../supports-YvpQZxbh.cjs"),u=require("../storage-YlR83AWP.cjs"),P=(e,t,i)=>{const n=t.name,o=t.setup(e);if(o){const r=i[n]??{};i[n]=Object.freeze({...r,...o})}},k=()=>S.createEvent(),C=()=>"0.0.1-dev.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../user-session-DQh0BBTx.cjs"),d=require("../logger-BsmHUUw1.cjs"),p=require("../experience-instance-CsMhH0DN.cjs"),S=require("effector"),c=require("../supports-YvpQZxbh.cjs"),u=require("../storage-YlR83AWP.cjs"),P=(e,t,i)=>{const n=t.name,o=t.setup(e);if(o){const r=i[n]??{};i[n]=Object.freeze({...r,...o})}},k=()=>S.createEvent(),C=()=>"0.0.1-dev.1769554766412";function b(){if(c.supportsDocument()){const e=[document.currentScript,document.getElementById("picked_script"),document.getElementById("picked"),document.getElementById("cvly"),document.getElementById("cvly-x")];for(const t of e)if(t?.dataset.api)return t.dataset.api}return"https://api.picked.app"}function j(){if(!c.supportsWindow())return{};const e=new URLSearchParams(window.location.search),t={},i=new Set;for(const[o]of e.entries())o.startsWith("picked-")&&i.add(o);for(const o of i){const r=o.replace("picked-","");t[r]=e.getAll(o)}const n=u.createStorageKey("s");if(i.size>0)u.sessionStore.set(n,t);else{const o=u.sessionStore.get(n);if(o)return o.json()||{}}return t}function y(){if(c.supportsWindow())return globalThis.window.pickedConfig}function E(){if(!c.supportsWindow())return;const e=y(),t=e?.organizationId,i=e?.projectId;return t&&i?{organizationId:t,projectId:i}:void 0}function x(){if(!c.supportsDocument())return;const e=document.getElementById("picked_script")||document.querySelector("script#picked")||document.getElementById("cvly");if(!e)return;const t=e.dataset.organizationid||e.getAttribute("organization-id"),i=e.dataset.projectid||e.getAttribute("project-id");return t&&i?{organizationId:t,projectId:i}:void 0}function z(e){const{organizationId:t,projectId:i}=e;if(t&&i)return{organizationId:t,projectId:i};const n=E();if(n)return n;const o=x();if(o)return o;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
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 f(e){return e==null||e===""||Number.isNaN(e)}const A={default:(e,t)=>f(e)?String(t??""):String(e),append:(e,t)=>t&&!f(e)?`${e} ${t}`:e,prepend:(e,t)=>t&&!f(e)?`${t} ${e}`:e,upper:e=>typeof e=="string"?e.toUpperCase():e,lower:e=>typeof e=="string"?e.toLowerCase():e,capitalize:e=>typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e,list:e=>{if(!e||typeof e!="object")return e;const t=new Intl.ListFormat("en",{style:"long",type:"conjunction"});if(Array.isArray(e))return t.format(e.map(String));if(e instanceof Map){const i=Array.from(e.entries()).map(([n,o])=>`${n}: ${o}`);return t.format(i)}return e instanceof Set?t.format(Array.from(e).map(String)):e}};function R(e){return typeof e=="object"&&e!==null}function v(e,t){let i=t;for(const n of e.split("."))if(R(i)&&n in i)i=i[n];else return;return typeof i=="function"?i():i}function F(e,t){const i=e.split("|").map(r=>r.trim()),n=i.shift()??"";let o=v(n,t);for(const r of i){const[l,...g]=r.split(":"),a=l?.trim()??"",h=g.join(":").trim().replaceAll(/(?:^['"]|['"]$)/g,""),m=A[a];m&&(o=m(o,h))}return f(o)?"":typeof o=="object"?JSON.stringify(o):String(o)}function B(e,t){let i="",n=0;for(;n<e.length;)if(e[n]==="{"&&e[n+1]==="{"){n+=2;let o="";for(;n<e.length;){if(e[n]==="}"&&e[n+1]==="}"){n+=2;break}o+=e[n++]}i+=F(o.trim(),t)}else i+=e[n++];return i}class I{static logger=d.logger;options;isReady=!1;project;plugins={};eventBus=k();organizationId;projectId;apiUrl;session;precondition;condition;searchParams=j();history=s.createHistory();components=s.createComponentIndex({client:this});experienceInstances=p.createExperienceInstanceIndex({client:this});experiences=s.createExperienceIndex({client:this});frameworks=s.createFrameworkIndex({client:this});predicates=s.createPredicateIndex({client:this});features=s.createFeatureIndex({client:this});responses=s.createResponseIndex({client:this});fields=s.createFieldIndex();actions=s.createActionIndex();constructor(t){d.logger("info","Picked client initializing.");const{organizationId:i,projectId:n}=z(t);this.organizationId=i,this.projectId=n,this.options=Object.freeze(t),this.apiUrl=t.apiUrl||b(),this.session=s.initialiseSession(),this.setupPlugins(),this.setupFeatures(),this.setupPredicates(),this.setupActions(),this.precondition=t.precondition,this.condition=t.condition,this.eventBus({type:"load",version:C()}),d.logger("info","Picked client initialized.")}start(){s.ping(this),(async()=>{if(!c.supportsDocument())return;let i;typeof this.precondition>"u"?i=!0:typeof this.precondition=="boolean"?i=this.precondition:i=await p.evaluateRuleLogic(this,this.precondition)===!0;let n;i&&(this.condition===void 0?n=!0:typeof this.condition=="boolean"?n=this.condition:n=await p.evaluateRuleLogic(this,this.condition)===!0);const o=i&&n===!0;if(typeof n=="boolean"&&this.session){const r=n;this.session.setIsUser(r),this.eventBus({type:"user_decide",is_user:r})}this.eventBus({type:"initialize"}),document.body&&o&&s.initialiseExperiences(this),await p.domInteractive(),o&&s.initialiseExperiences(this),this.eventBus({type:"ready"}),this.isReady=!0,this.session&&this.eventBus({type:"session",...this.session})})()}registerFramework(t){s.setupFramework(t,this.frameworks)}registerComponent(t,i){s.setupComponent(t,i,this.components)}registerPlugin(t){P(this,t,this.plugins)}registerFeature(t,i){s.setupFeature(t,i,this.features)}registerPredicate(t,i){s.setupPredicate(t,i,this.predicates)}registerField(t){s.setupField(t,this.fields)}registerAction(t,i){s.setupAction(t,i,this.actions)}registerExperience(t){t.component&&s.setupComponent(`experience:${t.id}`,t.component,this.components),s.setupExperience(t,this.experiences)}getStateSnapshot(){return s.createStateSnapshot(this)}async launchExperienceById(t){const i=this.experiences.getById(t).getState();if(!i){d.logger("warn",`Experience with id '${t}' not found.`);return}s.initialiseExperience(this,i)}setupPlugins(){this.options.plugins?.forEach(t=>{if(Array.isArray(t)){t.forEach(n=>{this.registerPlugin(n)});return}const i=typeof t=="function"?t():t;if(Array.isArray(i)){i.forEach(n=>this.registerPlugin(n));return}this.registerPlugin(i)})}setupFeatures(){const t=this.options.features;t&&(Object.entries(t).forEach(([i,n])=>{const o=typeof n=="function"?n():n;this.registerFeature(i,o)}),this.searchParams.feature&&this.searchParams.feature.forEach(i=>{try{const[n,o]=i.split(":");if(!n||!o)return;let r=o;r==="true"&&(r=!0),r==="false"&&(r=!1),this.registerFeature(n,{key:`${r}`,name:n,decide:()=>r,storage:"session"})}catch{}}))}setupPredicates(){const t=this.options.predicates;t&&Object.entries(t).forEach(([i,n])=>{if(typeof n!="function"){d.logger("warn",`Predicate "${i}" is not a function.`);return}this.registerPredicate(i,n)})}setupActions(){const t=this.options.actions;t&&Object.entries(t).forEach(([i,n])=>{if(typeof n!="function"){d.logger("warn",`Action "${i}" is not a function.`);return}this.registerAction(i,n)})}getPluginConfig(t){return this.plugins[t]??{}}renderString=(t,i)=>{const n=this.responses.listStore.getState().reduce((o,r)=>(o[r.fieldId]=r.value,o),{});return B(t,{...i,responses:n})}}function w(e){return e.options?.some(t=>"condition"in t)??!1}function L(e){return e.some(t=>t.condition||w(t))}async function U(e,t){return t.length===0||!L(t)?t:(await Promise.all(t.map(async n=>{if(!(n.condition?await p.evaluateRuleLogic(e,n.condition):!0))return null;if(!n.options||!w(n))return n;const l=(await Promise.all(n.options.map(async a=>a.condition?await p.evaluateRuleLogic(e,a.condition)?a:null:a))).filter(a=>a!==null);return l.length===n.options.length?n:l.length===0?null:{...n,options:l}}))).filter(n=>n!==null)}const $=e=>{const t=new I(e);return c.bindClient(t),t};exports.evaluateRuleLogic=p.evaluateRuleLogic;exports.isPickedRoot=p.isPickedRoot;exports.supportsCookies=c.supportsCookies;exports.supportsCryptoRandomUUID=c.supportsCryptoRandomUUID;exports.supportsDocument=c.supportsDocument;exports.supportsHistory=c.supportsHistory;exports.supportsIntersectionObserver=c.supportsIntersectionObserver;exports.supportsLocalStorage=c.supportsLocalStorage;exports.supportsLocation=c.supportsLocation;exports.supportsSessionStorage=c.supportsSessionStorage;exports.supportsShadowRoot=c.supportsShadowRoot;exports.supportsWebComponents=c.supportsWebComponents;exports.supportsWindow=c.supportsWindow;exports.createStorageKey=u.createStorageKey;exports.localStore=u.localStore;exports.sessionStore=u.sessionStore;exports.subscribe=u.subscribe;exports.Picked=I;exports.createClient=$;exports.getPickedConfig=y;exports.getStepFields=U;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("effector");require("../../../user-session-DQh0BBTx.cjs");const h=require("../../../supports-YvpQZxbh.cjs");require("../../../experience-instance-CsMhH0DN.cjs");const E=()=>sessionStorage.getItem("cvly_env");function L(e){const t=e?"true":"false";document.cookie=`picked-user=${t}; path=/; max-age=31536000; samesite=none; secure`}function I(e){document.cookie=`picked-id=${e}; path=/; max-age=31536000; samesite=none; secure`}const T=(e,t)=>e.filter(r=>!!t?.fieldIds.includes(r.fieldId)),w=e=>({id:e.experienceId,title:e.configStore.getState().name});function P(e){return e.isResolved}const b=e=>e.flatMap(t=>{if(!P(t))return[];const{bucket:r}=t.getBucket();return[{...t,bucket:r}]}),y=e=>{if("experience"in e&&e.experience){const{experience:t}=e;return{id:t.id,title:t.configStore.getState().name}}if("experienceInstance"in e&&e.experienceInstance){const{experienceInstance:t}=e;return{id:t.experienceId,title:t.configStore.getState().name}}},C=["click","double_click","mouse_over","mouse_out","mouse_down","mouse_up","focus","blur"],D={click:"click",double_click:"dblclick",mouse_over:"mouseover",mouse_out:"mouseout",mouse_down:"mousedown",mouse_up:"mouseup",focus:"focus",blur:"blur"},S=new WeakSet;function F(e,t){if(t&&!S.has(t)){for(const r of C){const c=D[r],o=`data-picked-${r.replace(/_/g,"-")}`;t.addEventListener(c,u=>{const a=u.composedPath().find(d=>d instanceof HTMLElement&&d.hasAttribute(o));if(!a)return;const p=a.getAttribute(o);p&&e(p)})}S.add(t)}}const R="development",$=["experience_open","experience_close","experience_initialize","initialize","step_enter","step_submit"],g=e=>{const{action:t,organizationId:r,projectId:c,features:s,value:o,step:u,form:l,experience:a,responses:p,exception:d,item:n}=e;return{event:"picked_event",picked_action:t,picked_app:{organizationId:r,projectId:c},picked_feature_list:s?b(s):void 0,picked_environment:R,picked_value:o,picked_step:u,picked_form:l,picked_experience:a,picked_responses:p,picked_exception:d,picked_cvly_env:E()??void 0,picked_item:n}};function x(e){if(!h.supportsWindow())return;const t=[];globalThis.dataLayer=globalThis.dataLayer??t,globalThis.dataLayer.push(e)}const q=({featureWatchList:e=["convincely-enabled"],eventListOverride:t=$,eventMappingOverride:r,mappedProductToPicked:c}={})=>({name:"data-layer-plugin",setup:s=>{if(!h.supportsWindow())return;const{organizationId:o,projectId:u}=s;s.eventBus.watch(n=>{n.type==="user_decide"&&L(n.is_user),n.type==="session"&&I(n.id)});const l=v.attach({source:{responses:s.responses.listStore,features:s.features.listStore},effect:async({responses:n,features:f},i)=>{const{type:m}=i,_=r?.[m]||m,k=g({action:_,organizationId:o,projectId:u,features:b(f),step:"step"in i?i.step:void 0,form:"form"in i?i.form:void 0,exception:"exception"in i?i.exception.reason?.[0]:void 0,experience:y(i),responses:"step"in i?T(n,i.step):void 0,value:"value"in i?i.value:void 0,item:c?c():void 0});return x(k)}}),a=v.createEffect(n=>{if(!("feature"in n))return null;const f=g({action:"picked_decision",organizationId:o,projectId:u,value:`${n.feature.id}:${n.feature.bucket}`});return x(f)}),p=new Set(t);v.sample({clock:s.eventBus,filter:n=>p.has(n.type),target:l});const d=new Set(e);v.sample({source:s.eventBus,filter:n=>n.type==="feature_decide"&&d.has(n.feature.id),target:a}),s.experienceInstances.listStore.watch(n=>{n.forEach(f=>{const i=f.target;i&&F(_=>{const k=g({action:"experience_interaction",organizationId:o,projectId:u,experience:w(f),value:_});x(k)},i.shadowRoot)})})}});exports.dataLayerPlugin=q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("effector");require("../../../user-session-DQh0BBTx.cjs");const h=require("../../../supports-YvpQZxbh.cjs");require("../../../experience-instance-CsMhH0DN.cjs");const E=()=>sessionStorage.getItem("cvly_env");function L(e){const t=e?"true":"false";document.cookie=`picked-user=${t}; path=/; max-age=31536000; samesite=none; secure`}function I(e){document.cookie=`picked-id=${e}; path=/; max-age=31536000; samesite=none; secure`}const T=(e,t)=>e.filter(r=>!!t?.fieldIds.includes(r.fieldId)),w=e=>({id:e.experienceId,title:e.configStore.getState().name});function P(e){return e.isResolved}const b=e=>e.flatMap(t=>{if(!P(t))return[];const{bucket:r}=t.getBucket();return[{...t,bucket:r}]}),y=e=>{if("experience"in e&&e.experience){const{experience:t}=e;return{id:t.id,title:t.configStore.getState().name}}if("experienceInstance"in e&&e.experienceInstance){const{experienceInstance:t}=e;return{id:t.experienceId,title:t.configStore.getState().name}}},C=["click","double_click","mouse_over","mouse_out","mouse_down","mouse_up","focus","blur"],D={click:"click",double_click:"dblclick",mouse_over:"mouseover",mouse_out:"mouseout",mouse_down:"mousedown",mouse_up:"mouseup",focus:"focus",blur:"blur"},S=new WeakSet;function F(e,t){if(t&&!S.has(t)){for(const r of C){const c=D[r],o=`data-picked-${r.replace(/_/g,"-")}`;t.addEventListener(c,u=>{const a=u.composedPath().find(d=>d instanceof HTMLElement&&d.hasAttribute(o));if(!a)return;const p=a.getAttribute(o);p&&e(p)},{capture:!0})}S.add(t)}}const R="development",$=["experience_open","experience_close","experience_initialize","initialize","step_enter","step_submit"],g=e=>{const{action:t,organizationId:r,projectId:c,features:s,value:o,step:u,form:l,experience:a,responses:p,exception:d,item:n}=e;return{event:"picked_event",picked_action:t,picked_app:{organizationId:r,projectId:c},picked_feature_list:s?b(s):void 0,picked_environment:R,picked_value:o,picked_step:u,picked_form:l,picked_experience:a,picked_responses:p,picked_exception:d,picked_cvly_env:E()??void 0,picked_item:n}};function x(e){if(!h.supportsWindow())return;const t=[];globalThis.dataLayer=globalThis.dataLayer??t,globalThis.dataLayer.push(e)}const q=({featureWatchList:e=["convincely-enabled"],eventListOverride:t=$,eventMappingOverride:r,mappedProductToPicked:c}={})=>({name:"data-layer-plugin",setup:s=>{if(!h.supportsWindow())return;const{organizationId:o,projectId:u}=s;s.eventBus.watch(n=>{n.type==="user_decide"&&L(n.is_user),n.type==="session"&&I(n.id)});const l=v.attach({source:{responses:s.responses.listStore,features:s.features.listStore},effect:async({responses:n,features:f},i)=>{const{type:m}=i,_=r?.[m]||m,k=g({action:_,organizationId:o,projectId:u,features:b(f),step:"step"in i?i.step:void 0,form:"form"in i?i.form:void 0,exception:"exception"in i?i.exception.reason?.[0]:void 0,experience:y(i),responses:"step"in i?T(n,i.step):void 0,value:"value"in i?i.value:void 0,item:c?c():void 0});return x(k)}}),a=v.createEffect(n=>{if(!("feature"in n))return null;const f=g({action:"picked_decision",organizationId:o,projectId:u,value:`${n.feature.id}:${n.feature.bucket}`});return x(f)}),p=new Set(t);v.sample({clock:s.eventBus,filter:n=>p.has(n.type),target:l});const d=new Set(e);v.sample({source:s.eventBus,filter:n=>n.type==="feature_decide"&&d.has(n.feature.id),target:a}),s.experienceInstances.listStore.watch(n=>{n.forEach(f=>{const i=f.target;i&&F(_=>{const k=g({action:"experience_interaction",organizationId:o,projectId:u,experience:w(f),value:_});x(k)},i.shadowRoot)})})}});exports.dataLayerPlugin=q;
|
package/dist/esm/index.js
CHANGED
|
@@ -64,14 +64,18 @@ function $(e, t) {
|
|
|
64
64
|
if (t && !h.has(t)) {
|
|
65
65
|
for (const r of F) {
|
|
66
66
|
const c = R[r], o = `data-picked-${r.replace(/_/g, "-")}`;
|
|
67
|
-
t.addEventListener(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
t.addEventListener(
|
|
68
|
+
c,
|
|
69
|
+
(u) => {
|
|
70
|
+
const a = u.composedPath().find(
|
|
71
|
+
(d) => d instanceof HTMLElement && d.hasAttribute(o)
|
|
72
|
+
);
|
|
73
|
+
if (!a) return;
|
|
74
|
+
const p = a.getAttribute(o);
|
|
75
|
+
p && e(p);
|
|
76
|
+
},
|
|
77
|
+
{ capture: !0 }
|
|
78
|
+
);
|
|
75
79
|
}
|
|
76
80
|
h.add(t);
|
|
77
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-event.d.ts","sourceRoot":"","sources":["../../../../src/plugins/data-layer/custom-event.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,iBAAiB,0GASb,CAAA;AAEV,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAgBhE,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EAChC,MAAM,EAAE,UAAU,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"custom-event.d.ts","sourceRoot":"","sources":["../../../../src/plugins/data-layer/custom-event.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,iBAAiB,0GASb,CAAA;AAEV,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAgBhE,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EAChC,MAAM,EAAE,UAAU,GAAG,IAAI,QAsC1B"}
|