@picked/client 0.0.51-next.1 → 0.0.51-next.10
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-CHy9HcU7.cjs +1 -0
- package/dist/{api-Brluf3C1.js → api-mlYS-lDj.js} +1 -1
- package/dist/cjs/form/index.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/cjs/plugins/responses-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/form/index.js +82 -76
- package/dist/esm/index.js +436 -355
- package/dist/esm/plugins/create-experience/index.js +181 -154
- package/dist/esm/plugins/dynamic-experiences/index.js +52 -30
- package/dist/esm/plugins/responses-browser-storage/index.js +6 -8
- package/dist/esm/plugins/responses-indexeddb/index.js +8 -4
- package/dist/esm/server/index.js +1 -1
- package/dist/experience-instance-DOcd8XI1.cjs +1 -0
- package/dist/{experience-instance-CIbQp9D7.js → experience-instance-NHU1moID.js} +37 -32
- package/dist/{rules-logic-BIkBWZmf.js → rules-logic-CnVktz2l.js} +9 -2
- package/dist/{rules-logic-DDxCiq4P.cjs → rules-logic-nMHNVLn7.cjs} +1 -1
- package/dist/types/client.d.ts +47 -43
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/entities/action/action.d.ts +37 -5
- package/dist/types/entities/action/action.d.ts.map +1 -1
- package/dist/types/entities/condition/condition.d.ts +20 -0
- package/dist/types/entities/condition/condition.d.ts.map +1 -0
- package/dist/types/entities/experience/experience.d.ts +63 -47
- package/dist/types/entities/experience/experience.d.ts.map +1 -1
- package/dist/types/entities/experience-instance/experience-instance.d.ts +22 -2
- package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
- package/dist/types/entities/field/field.d.ts +13 -2
- package/dist/types/entities/field/field.d.ts.map +1 -1
- package/dist/types/entities/response/response-validation.d.ts +74 -0
- package/dist/types/entities/response/response-validation.d.ts.map +1 -0
- package/dist/types/entities/response/response.d.ts +24 -20
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/types/entities/step/step.d.ts +42 -0
- package/dist/types/entities/step/step.d.ts.map +1 -0
- package/dist/types/form/build-responses.d.ts +12 -9
- package/dist/types/form/build-responses.d.ts.map +1 -1
- package/dist/types/form/create-field-evaluator.d.ts +11 -3
- package/dist/types/form/create-field-evaluator.d.ts.map +1 -1
- package/dist/types/form/create-field-validation.d.ts +4 -4
- package/dist/types/form/create-field-validation.d.ts.map +1 -1
- package/dist/types/form/create-form.d.ts +1 -0
- package/dist/types/form/create-form.d.ts.map +1 -1
- package/dist/types/form/create-submit-pipeline.d.ts +19 -7
- package/dist/types/form/create-submit-pipeline.d.ts.map +1 -1
- package/dist/types/form/get-step-fields.d.ts +13 -0
- package/dist/types/form/get-step-fields.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/picked.d.ts +98 -31
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +31 -11
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/index.d.ts +2 -2
- package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts +21 -4
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts +45 -0
- package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
- package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts +13 -0
- package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts.map +1 -1
- package/dist/types/utils/rules-logic.d.ts.map +1 -1
- package/dist/types/utils/state-snaphot.d.ts +11 -1
- package/dist/types/utils/state-snaphot.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/api-A3gUhQJc.cjs +0 -1
- package/dist/experience-instance-Dri5yAp1.cjs +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { n as e, r as t, t as n } from "../../../storage-6Xk0uAxB.js";
|
|
2
2
|
import { attach as r, createEffect as i, sample as a } from "effector";
|
|
3
3
|
//#region src/plugins/responses-browser-storage/plugin.ts
|
|
4
|
-
var o = n("responses", "global")
|
|
5
|
-
|
|
6
|
-
return Object.entries(e).
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}, c = ({ storage: n = "local" } = {}) => ({
|
|
4
|
+
var o = n("responses", "global");
|
|
5
|
+
function s(e, t) {
|
|
6
|
+
return Object.fromEntries(Object.entries(e).flatMap(([e, n]) => t.find((t) => t.key === e)?.policies?.doNotStoreValue ? [] : [[e, n]]));
|
|
7
|
+
}
|
|
8
|
+
var c = ({ storage: n = "local" } = {}) => ({
|
|
10
9
|
name: "responses-browser-storage-plugin",
|
|
11
10
|
setup: (c) => {
|
|
12
11
|
let l = n === "local" ? e : t, u = i(async () => {
|
|
@@ -19,8 +18,7 @@ var o = n("responses", "global"), s = (e, t) => {
|
|
|
19
18
|
fields: c.fields.listStore
|
|
20
19
|
},
|
|
21
20
|
effect: ({ responses: e, fields: t }) => {
|
|
22
|
-
|
|
23
|
-
l.set(o, n);
|
|
21
|
+
l.set(o, s(e, t));
|
|
24
22
|
}
|
|
25
23
|
});
|
|
26
24
|
a({
|
|
@@ -39,12 +39,13 @@ async function s(e, t) {
|
|
|
39
39
|
//#region src/plugins/responses-indexeddb/plugin.ts
|
|
40
40
|
var c = "responses", l = {
|
|
41
41
|
storeName: c,
|
|
42
|
-
keyPath: "
|
|
42
|
+
keyPath: "fieldKey",
|
|
43
|
+
version: 2
|
|
43
44
|
}, u = () => ({
|
|
44
45
|
name: "responses-indexdb-plugin",
|
|
45
46
|
setup: (n) => {
|
|
46
47
|
let u = e(async () => {
|
|
47
|
-
let e = (await i(await r(l), c)).reduce((e, {
|
|
48
|
+
let e = (await i(await r(l), c)).reduce((e, { fieldKey: t, value: n }) => (e[t] = n, e), {});
|
|
48
49
|
await n.responses.commit(e);
|
|
49
50
|
}), d = e(async (e) => {
|
|
50
51
|
await Promise.allSettled(e.map(async (e) => {
|
|
@@ -66,8 +67,11 @@ var c = "responses", l = {
|
|
|
66
67
|
fields: n.fields.listStore
|
|
67
68
|
},
|
|
68
69
|
fn: ({ responses: e, fields: t }) => {
|
|
69
|
-
let n = new Set(t.filter((e) => !e.policies?.doNotStoreValue).map((e) => e.
|
|
70
|
-
return e.filter((e) => n.has(e.
|
|
70
|
+
let n = new Set(t.filter((e) => !e.policies?.doNotStoreValue).map((e) => e.key));
|
|
71
|
+
return e.filter((e) => n.has(e.fieldKey)).map((e) => ({
|
|
72
|
+
fieldKey: e.fieldKey,
|
|
73
|
+
value: e.value
|
|
74
|
+
}));
|
|
71
75
|
},
|
|
72
76
|
target: d
|
|
73
77
|
}), t({
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "../../experience-instance-
|
|
1
|
+
import { t as e } from "../../experience-instance-NHU1moID.js";
|
|
2
2
|
import { attach as t, createEffect as n, createEvent as r, createStore as i, sample as a } from "effector";
|
|
3
3
|
//#region src/server/index.ts
|
|
4
4
|
function o() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./rules-logic-nMHNVLn7.cjs`);require(`./logger-fbvQC40v.cjs`);const t=require(`./supports-Dsjg-82e.cjs`);let n=require(`effector`),r=require(`@withease/factories`);function i(e){return!t.d()||!t.r()?[]:Array.from(window.document.querySelectorAll(e)).filter(e=>e instanceof HTMLElement)}var a=`open`;function o(e){if(!t.l())throw Error(`Shadow DOM is not supported in this environment`);return e.attachShadow({mode:a})}function s(){return new Promise((e,n)=>{if(!t.r()){n();return}document.readyState===`loading`?document.addEventListener(`readystatechange`,()=>e(),{once:!0}):e()})}function c(e,t){let n=new MutationObserver(r=>{document.contains(e)||(n.disconnect(),t())});n.observe(document.body,{childList:!0,subtree:!0})}var l=`picked-root`,u=`picked-target`,d=`picked-root`;function f(e,t){return[...e,{selector:`${d}[experience-id="${t}"]`,placement:`replace`}].flatMap(e=>{let n=i(e.selector).filter(e=>!h(e,t)&&!g(e,t));return{...e,elements:n}})}function p(e,t){return e.flatMap(e=>e.elements.map(n=>v(n,e.placement,t)))}function m(e,t){e.classList.add(u),e.classList.add(`${u}-${t}`)}function h(e,t){return t?e.classList.contains(`${u}-${t}`):e.classList.contains(`${u}`)}function g(e,t){return t?e.classList.contains(`${l}-${t}`):e.classList.contains(l)}function _(e){let t=document.createElement(`div`);return t.style.display=`block`,t.classList.add(l),t.classList.add(`${l}-${e}`),t}function v(e,t,n){let r,i=_(n);if(e instanceof Document)r=e.body.appendChild(i);else{switch(t){case`replace`:e.replaceWith(i);break;case`before`:e.before(i);break;case`after`:e.after(i);break;case`prepend`:e.prepend(i);break;case`append`:e.append(i);break}r=i}return r}function y(e){return e.type===`condition`}function b(e){return e.type===`step`}function x(e){return e.type===`experience`}function S(e){return e.type===`origin`}function C(e){return e.type===`action`}var w=(e,t,n,r,i=new Set)=>i.has(n.id)?[]:(i.add(n.id),b(n)&&!r?[n]:t.filter(e=>e.sourceNodeId===n.id).flatMap(n=>{let r=e.find(e=>e.id===n.destinationNodeId);return r?w(e,t,r,!1,i):[]})),T=(e,t,n)=>w(e,t,n,!0,new Set),E=(e,t,n,r,i=new Set)=>{if(i.has(n.id))return[-1,-1];i.add(n.id);let a=t.filter(e=>e.sourceNodeId===n.id);if(a.length===0)return[0,0];let o=1/0,s=-1/0;for(let n of a){let r=e.find(e=>e.id===n.destinationNodeId);if(!r)continue;let[a,c]=E(e,t,r,!1,new Set(i));a!==-1&&(o=Math.min(o,a+1),s=Math.max(s,c+1))}return o===1/0?[-1,-1]:[o,s]},D=(e,t,n)=>E(e,t,n,!0,new Set),O=(e,t,n,r=new Set)=>{if(r.has(n.id))return[-1,-1];if(r.add(n.id),n.type===`origin`)return[0,0];let i=t.filter(e=>e.destinationNodeId===n.id);if(i.length===0)return[-1,-1];let a=1/0,o=-1/0;for(let n of i){let i=e.find(e=>e.id===n.sourceNodeId);if(!i)continue;let[s,c]=O(e,t,i,new Set(r));s!==-1&&(a=Math.min(a,s+1),o=Math.max(o,c+1))}return a===1/0?[-1,-1]:[a,o]},k=(e,t,n)=>O(e,t,n,new Set),A=e=>e.find(e=>e.type===`origin`)||null,j=(e,t,n)=>{if(!e)return A(t);let r=n.find(t=>t.sourceNodeId===e.id);return r&&t.find(e=>e.id===r.destinationNodeId)||null};async function M(e,t,n,r){let i=e?`true`:`false`,a=r.find(e=>e.sourceHandle===i&&e.sourceNodeId===t);return n.find(e=>e.id===a?.destinationNodeId)}var N=(0,n.createDomain)(`experience-instance`),P=(0,r.createFactory)(({client:t,experience:r,target:i,options:a})=>{let o=(0,n.createEvent)(),s=(0,n.createEvent)(),c=(0,n.createEvent)(),l=(0,n.createEvent)(),u=(0,n.createEvent)(),d=(0,n.createEvent)(),f=r.componentStore,p=N.store(`transitioning`),m=t.history.entriesStore.map(e=>e.filter(e=>e.experienceId===r.id)),h=m.map(e=>e.filter(e=>b(e.node))),g=m.map(e=>e.at(-1)?.node||null),_=(0,n.combine)(t.steps.listStore,g,(e,t)=>e.find(e=>t&&b(t)&&e.id===t.stepId)||null),v=(0,n.combine)(t.steps.listStore,h,(e,t)=>{let n=t.at(-2);if(!n||!b(n.node))return null;let r=n.node;return e.find(e=>e.id===r.stepId)||null}),w=(0,n.combine)(r.treeStore,g,({nodes:e,edges:t},n)=>n?T(e,t,n):[]),E=(0,n.combine)(r.treeStore,g,({nodes:e,edges:t},n)=>n?k(e,t,n):[-1,-1]),O=(0,n.combine)(r.treeStore,g,({nodes:e,edges:t},n)=>n?D(e,t,n):[-1,-1]),P=N.store(!1),F=(0,n.createApi)(P,{open:()=>!0,close:()=>!1,toggle:e=>!e,set:(e,t)=>t}),I=(0,n.createEffect)(async()=>{t.history.back({experienceId:r.id})}),L=(0,n.attach)({source:r.treeStore,effect:async(e,n)=>{let i=e.nodes.find(e=>b(e)&&e.stepId===n);i&&t.history.push({experienceId:r.id,node:i})}}),R=(0,n.attach)({source:g,effect:e=>{}}),z=(0,n.attach)({source:r.treeStore,effect:async({nodes:e})=>A(e)}),B=(0,n.attach)({source:r.treeStore,effect:async({nodes:e,edges:t},n)=>{if(S(n))return j(n,e,t)}}),V=(0,n.attach)({source:r.treeStore,effect:async({nodes:n,edges:r,conditions:i},a)=>{if(!y(a))return;let o=i.find(e=>e.id===a.conditionId)?.logic;return o?M(!!await e.t(t,o),a.id,n,r):void 0}}),H=(0,n.attach)({source:r.treeStore,effect:async({nodes:e,edges:n},r)=>{if(!C(r))return;let i=r.actionKey;if(!i){`${r.id}`;return}let a=t.actions.getByName(i).getState();if(!a){`${i}`;let t=n.find(e=>e.sourceNodeId===r.id&&e.sourceHandle===`false`);return t?e.find(e=>e.id===t.destinationNodeId):null}if(typeof a!=`function`){`${i}`;let t=n.find(e=>e.sourceNodeId===r.id&&e.sourceHandle===`false`);return t?e.find(e=>e.id===t.destinationNodeId):null}try{`${i}`,await a({...t.getStateSnapshot(),args:[]});let o=n.find(e=>e.sourceNodeId===r.id&&e.sourceHandle===`true`);if(!o)return`${r.id}`,null;let s=e.find(e=>e.id===o.destinationNodeId);return`${i}${s?.id}`,s||null}catch{`${i}`;let t=n.find(e=>e.sourceNodeId===r.id&&e.sourceHandle===`false`);if(!t)return`${r.id}`,null;let a=e.find(e=>e.id===t.destinationNodeId);return`${i}${a?.id}`,a||null}}}),U=(0,n.createEffect)(e=>{x(e)&&t.experiences.launch({key:e.experienceKey})}),W=(0,n.attach)({source:[g,r.treeStore],effect:async([e,{nodes:t,edges:n}])=>j(e,t,n)}),G=(0,n.attach)({source:[g,r.treeStore],effect:async([e,{nodes:t,edges:n}])=>j(e,t,n)}),K=(0,n.createEffect)(e=>{t.history.push({experienceId:r.id,node:e})}),q=(0,n.attach)({source:r.configStore,effect:async({initializeOpenLogic:n})=>a?.initialiseOpen===void 0?e.n(n)?!!await e.t(t,n):n??!1:a.initialiseOpen}),J=Object.freeze({id:Math.random().toString(36).substring(7),experienceKey:r.key,experienceId:r.id,configStore:r.configStore,target:i,componentStore:f,stateStore:p,isOpenStore:P,open:F.open,close:F.close,toggleOpen:F.toggle,setOpen:F.set,treeStore:r.treeStore,currentNodeStore:g,currentStepStore:_,previousStepStore:v,nextReachableStepNodesStore:w,stepsToOriginStore:E,stepsToLeafStore:O,goToNextStep:s,goToPreviousStep:c,goToStepById:l,stepsHistoryStore:h}),Y=(0,n.createEvent)(),X=(0,n.createEvent)();return(0,n.sample)({clock:g,target:Y}),(0,n.sample)({clock:Y,filter:e=>e===null,target:z}),(0,n.sample)({clock:Y,filter:e=>e!==null,target:X}),(0,n.split)({source:X,match:e=>y(e)?`condition`:b(e)?`step`:x(e)?`launchExperience`:S(e)?`origin`:C(e)?`action`:`other`,cases:{origin:B,condition:V,step:R,launchExperience:U,action:H,__:(0,n.createEvent)()}}),(0,n.sample)({clock:[V.doneData,B.doneData,z.doneData,G.doneData,W.doneData,H.doneData],filter:Boolean,target:K}),(0,n.sample)({clock:s,target:G}),(0,n.sample)({clock:s,source:_,filter:Boolean,target:t.eventBus.prepend(e=>({type:`step_submit`,step:e,experience:J}))}),(0,n.sample)({clock:G.done,source:_,filter:Boolean,target:t.eventBus.prepend(e=>({type:`step_submit_success`,step:e,experience:J}))}),(0,n.sample)({clock:G.fail,source:_,filter:Boolean,target:t.eventBus.prepend(e=>({type:`step_submit_error`,step:e,experience:J}))}),(0,n.sample)({clock:c,target:I}),(0,n.sample)({clock:l,target:L}),(0,n.sample)({source:(0,n.combine)([V.pending,B.pending,z.pending,G.pending]),fn:e=>e.some(Boolean)?`transitioning`:`ready`,target:p}),(0,n.sample)({clock:R.doneData,source:_,filter:Boolean,target:t.eventBus.prepend(e=>({type:`step_enter`,step:e,experience:J}))}),(0,n.sample)({clock:d,target:q}),(0,n.sample)({source:q.doneData,fn:Boolean,target:P}),(0,n.sample)({source:g,clock:o,filter:e=>e?S(e):!0,target:W}),(0,n.sample)({source:P,filter:Boolean,target:o}),(0,n.sample)({source:P,filter:Boolean,target:t.eventBus.prepend(()=>({type:`experience_open`,experience:J}))}),(0,n.sample)({source:P,filter:e=>!e,target:t.eventBus.prepend(()=>({type:`experience_close`,experience:J}))}),(0,n.sample)({clock:u,target:[d]}),u(),J});function F(e){return(0,r.invoke)(P,e)}var I=(0,r.createFactory)(({client:e})=>{let t=N.store({}),r=(0,n.createEvent)(),i=(0,n.createEvent)(),a=(0,n.createEvent)(),s=(0,n.createApi)(t,{register(e,t){let n=[...e[t.experienceId]??[]];return n.push(t),{...e,[t.experienceId]:n}},unregister(e,t){let n=t.experienceId,r=e[n]?.filter(e=>e!==t);return{...e,[n]:r??[]}}}),l=(0,n.createEffect)(({experience:t,target:n,options:r})=>F({client:e,experience:t,target:n,options:r})),u=(0,n.createEffect)(e=>{s.register(e)}),d=(0,n.createEffect)(e=>{e.target&&c(e.target,()=>{a(e)})}),f=(0,n.createEffect)(e=>{s.unregister(e)}),p=(0,n.createEffect)(t=>{let n=t.componentStore.getState();if(!n)return;let r=n.frameworkStore.getState();if(!r){`${n.name}`;return}let i=t.target;if(!i){`${t.experienceId}`;return}let a=o(i);try{r.render(a,n.component,e,t)}catch{}});(0,n.sample)({clock:r,target:l}),(0,n.sample)({clock:a,target:f}),(0,n.sample)({clock:l.doneData,target:[u,d,i]}),(0,n.sample)({clock:l.doneData,target:e.eventBus.prepend(e=>({type:`experience_initialize`,experience:e}))}),(0,n.sample)({clock:i,target:p});function m(e,t,n){r({experience:e,target:t,options:n})}let h=t.map(e=>Object.values(e).flat());function g(e){return h.map(t=>t.filter(t=>t.experienceKey===e),{skipVoid:!1})}function _(e){return t.map(t=>t[e]||[],{skipVoid:!1})}return{spawn:m,getByExperienceKey:g,getByExperienceId:_,listStore:h}});function L(e){return(0,r.invoke)(I,e)}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return F}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as e, t } from "./rules-logic-
|
|
1
|
+
import { n as e, t } from "./rules-logic-CnVktz2l.js";
|
|
2
2
|
import "./logger-6z_gb4rA.js";
|
|
3
3
|
import { d as n, l as r, r as i } from "./supports-0XIfd4-R.js";
|
|
4
4
|
import { attach as a, combine as o, createApi as s, createDomain as c, createEffect as l, createEvent as u, sample as d, split as f } from "effector";
|
|
@@ -106,7 +106,7 @@ function P(e) {
|
|
|
106
106
|
var F = (e, t, n, r, i = /* @__PURE__ */ new Set()) => i.has(n.id) ? [] : (i.add(n.id), j(n) && !r ? [n] : t.filter((e) => e.sourceNodeId === n.id).flatMap((n) => {
|
|
107
107
|
let r = e.find((e) => e.id === n.destinationNodeId);
|
|
108
108
|
return r ? F(e, t, r, !1, i) : [];
|
|
109
|
-
})),
|
|
109
|
+
})), I = (e, t, n) => F(e, t, n, !0, /* @__PURE__ */ new Set()), L = (e, t, n, r, i = /* @__PURE__ */ new Set()) => {
|
|
110
110
|
if (i.has(n.id)) return [-1, -1];
|
|
111
111
|
i.add(n.id);
|
|
112
112
|
let a = t.filter((e) => e.sourceNodeId === n.id);
|
|
@@ -115,11 +115,11 @@ var F = (e, t, n, r, i = /* @__PURE__ */ new Set()) => i.has(n.id) ? [] : (i.add
|
|
|
115
115
|
for (let n of a) {
|
|
116
116
|
let r = e.find((e) => e.id === n.destinationNodeId);
|
|
117
117
|
if (!r) continue;
|
|
118
|
-
let [a, c] =
|
|
118
|
+
let [a, c] = L(e, t, r, !1, new Set(i));
|
|
119
119
|
a !== -1 && (o = Math.min(o, a + 1), s = Math.max(s, c + 1));
|
|
120
120
|
}
|
|
121
121
|
return o === Infinity ? [-1, -1] : [o, s];
|
|
122
|
-
},
|
|
122
|
+
}, ee = (e, t, n) => L(e, t, n, !0, /* @__PURE__ */ new Set()), R = (e, t, n, r = /* @__PURE__ */ new Set()) => {
|
|
123
123
|
if (r.has(n.id)) return [-1, -1];
|
|
124
124
|
if (r.add(n.id), n.type === "origin") return [0, 0];
|
|
125
125
|
let i = t.filter((e) => e.destinationNodeId === n.id);
|
|
@@ -128,11 +128,11 @@ var F = (e, t, n, r, i = /* @__PURE__ */ new Set()) => i.has(n.id) ? [] : (i.add
|
|
|
128
128
|
for (let n of i) {
|
|
129
129
|
let i = e.find((e) => e.id === n.sourceNodeId);
|
|
130
130
|
if (!i) continue;
|
|
131
|
-
let [s, c] =
|
|
131
|
+
let [s, c] = R(e, t, i, new Set(r));
|
|
132
132
|
s !== -1 && (a = Math.min(a, s + 1), o = Math.max(o, c + 1));
|
|
133
133
|
}
|
|
134
134
|
return a === Infinity ? [-1, -1] : [a, o];
|
|
135
|
-
},
|
|
135
|
+
}, te = (e, t, n) => R(e, t, n, /* @__PURE__ */ new Set()), z = (e) => e.find((e) => e.type === "origin") || null, B = (e, t, n) => {
|
|
136
136
|
if (!e) return z(t);
|
|
137
137
|
let r = n.find((t) => t.sourceNodeId === e.id);
|
|
138
138
|
return r && t.find((e) => e.id === r.destinationNodeId) || null;
|
|
@@ -140,25 +140,25 @@ var F = (e, t, n, r, i = /* @__PURE__ */ new Set()) => i.has(n.id) ? [] : (i.add
|
|
|
140
140
|
//#endregion
|
|
141
141
|
//#region src/utils/node-tree/get-next-node-from-condition.ts
|
|
142
142
|
async function V(e, t, n, r) {
|
|
143
|
-
let i = e ? "true" : "false", a = r.find((e) => e.
|
|
143
|
+
let i = e ? "true" : "false", a = r.find((e) => e.sourceHandle === i && e.sourceNodeId === t);
|
|
144
144
|
return n.find((e) => e.id === a?.destinationNodeId);
|
|
145
145
|
}
|
|
146
146
|
//#endregion
|
|
147
147
|
//#region src/entities/experience-instance/experience-instance.ts
|
|
148
148
|
var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i, options: c }) => {
|
|
149
|
-
let p = u(), m = u(), h = u(), g = u(), _ = u(), v = u(), y = r.componentStore, b = H.store("transitioning"), x = n.history.entriesStore.map((e) => e.filter((e) => e.experienceId === r.id)), S = x.map((e) => e.filter((e) => j(e.node))), C = x.map((e) => e.at(-1)?.node || null), w = o(
|
|
149
|
+
let p = u(), m = u(), h = u(), g = u(), _ = u(), v = u(), y = r.componentStore, b = H.store("transitioning"), x = n.history.entriesStore.map((e) => e.filter((e) => e.experienceId === r.id)), S = x.map((e) => e.filter((e) => j(e.node))), C = x.map((e) => e.at(-1)?.node || null), w = o(n.steps.listStore, C, (e, t) => e.find((e) => t && j(t) && e.id === t.stepId) || null), T = o(n.steps.listStore, S, (e, t) => {
|
|
150
150
|
let n = t.at(-2);
|
|
151
151
|
if (!n || !j(n.node)) return null;
|
|
152
152
|
let r = n.node;
|
|
153
153
|
return e.find((e) => e.id === r.stepId) || null;
|
|
154
|
-
}), E = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ?
|
|
154
|
+
}), E = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ? I(e, t, n) : []), D = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ? te(e, t, n) : [-1, -1]), O = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ? ee(e, t, n) : [-1, -1]), k = H.store(!1), F = s(k, {
|
|
155
155
|
open: () => !0,
|
|
156
156
|
close: () => !1,
|
|
157
157
|
toggle: (e) => !e,
|
|
158
158
|
set: (e, t) => t
|
|
159
|
-
}),
|
|
159
|
+
}), L = l(async () => {
|
|
160
160
|
n.history.back({ experienceId: r.id });
|
|
161
|
-
}),
|
|
161
|
+
}), R = a({
|
|
162
162
|
source: r.treeStore,
|
|
163
163
|
effect: async (e, t) => {
|
|
164
164
|
let i = e.nodes.find((e) => j(e) && e.stepId === t);
|
|
@@ -182,16 +182,14 @@ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i,
|
|
|
182
182
|
source: r.treeStore,
|
|
183
183
|
effect: async ({ nodes: e, edges: r, conditions: i }, a) => {
|
|
184
184
|
if (!A(a)) return;
|
|
185
|
-
let o = i.find((e) => e.id === a.conditionId);
|
|
186
|
-
|
|
187
|
-
let s = a.id;
|
|
188
|
-
return V(!!await t(n, o.condition), s, e, r);
|
|
185
|
+
let o = i.find((e) => e.id === a.conditionId)?.logic;
|
|
186
|
+
return o ? V(!!await t(n, o), a.id, e, r) : void 0;
|
|
189
187
|
}
|
|
190
188
|
}), q = a({
|
|
191
189
|
source: r.treeStore,
|
|
192
190
|
effect: async ({ nodes: e, edges: t }, r) => {
|
|
193
191
|
if (!P(r)) return;
|
|
194
|
-
let i = r.
|
|
192
|
+
let i = r.actionKey;
|
|
195
193
|
if (!i) {
|
|
196
194
|
`${r.id}`;
|
|
197
195
|
return;
|
|
@@ -199,30 +197,33 @@ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i,
|
|
|
199
197
|
let a = n.actions.getByName(i).getState();
|
|
200
198
|
if (!a) {
|
|
201
199
|
`${i}`;
|
|
202
|
-
let n = t.find((e) => e.sourceNodeId === r.id && e.
|
|
200
|
+
let n = t.find((e) => e.sourceNodeId === r.id && e.sourceHandle === "false");
|
|
203
201
|
return n ? e.find((e) => e.id === n.destinationNodeId) : null;
|
|
204
202
|
}
|
|
205
|
-
if (typeof a
|
|
203
|
+
if (typeof a != "function") {
|
|
206
204
|
`${i}`;
|
|
207
|
-
let n = t.find((e) => e.sourceNodeId === r.id && e.
|
|
205
|
+
let n = t.find((e) => e.sourceNodeId === r.id && e.sourceHandle === "false");
|
|
208
206
|
return n ? e.find((e) => e.id === n.destinationNodeId) : null;
|
|
209
207
|
}
|
|
210
208
|
try {
|
|
211
|
-
`${i}`, await a
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
209
|
+
`${i}`, await a({
|
|
210
|
+
...n.getStateSnapshot(),
|
|
211
|
+
args: []
|
|
212
|
+
});
|
|
213
|
+
let o = t.find((e) => e.sourceNodeId === r.id && e.sourceHandle === "true");
|
|
214
|
+
if (!o) return `${r.id}`, null;
|
|
215
|
+
let s = e.find((e) => e.id === o.destinationNodeId);
|
|
216
|
+
return `${i}${s?.id}`, s || null;
|
|
216
217
|
} catch {
|
|
217
218
|
`${i}`;
|
|
218
|
-
let n = t.find((e) => e.sourceNodeId === r.id && e.
|
|
219
|
+
let n = t.find((e) => e.sourceNodeId === r.id && e.sourceHandle === "false");
|
|
219
220
|
if (!n) return `${r.id}`, null;
|
|
220
221
|
let a = e.find((e) => e.id === n.destinationNodeId);
|
|
221
222
|
return `${i}${a?.id}`, a || null;
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
}), ne = l((e) => {
|
|
225
|
-
M(e) && n.experiences.launch({
|
|
226
|
+
M(e) && n.experiences.launch({ key: e.experienceKey });
|
|
226
227
|
}), J = a({
|
|
227
228
|
source: [C, r.treeStore],
|
|
228
229
|
effect: async ([e, { nodes: t, edges: n }]) => B(e, t, n)
|
|
@@ -239,6 +240,7 @@ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i,
|
|
|
239
240
|
effect: async ({ initializeOpenLogic: r }) => c?.initialiseOpen === void 0 ? e(r) ? !!await t(n, r) : r ?? !1 : c.initialiseOpen
|
|
240
241
|
}), Z = Object.freeze({
|
|
241
242
|
id: Math.random().toString(36).substring(7),
|
|
243
|
+
experienceKey: r.key,
|
|
242
244
|
experienceId: r.id,
|
|
243
245
|
configStore: r.configStore,
|
|
244
246
|
target: i,
|
|
@@ -250,7 +252,6 @@ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i,
|
|
|
250
252
|
toggleOpen: F.toggle,
|
|
251
253
|
setOpen: F.set,
|
|
252
254
|
treeStore: r.treeStore,
|
|
253
|
-
fieldsStore: r.fieldsStore,
|
|
254
255
|
currentNodeStore: C,
|
|
255
256
|
currentStepStore: w,
|
|
256
257
|
previousStepStore: T,
|
|
@@ -263,7 +264,7 @@ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i,
|
|
|
263
264
|
stepsHistoryStore: S
|
|
264
265
|
}), Q = u(), $ = u();
|
|
265
266
|
return d({
|
|
266
|
-
|
|
267
|
+
clock: C,
|
|
267
268
|
target: Q
|
|
268
269
|
}), d({
|
|
269
270
|
clock: Q,
|
|
@@ -327,10 +328,10 @@ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i,
|
|
|
327
328
|
}))
|
|
328
329
|
}), d({
|
|
329
330
|
clock: h,
|
|
330
|
-
target:
|
|
331
|
+
target: L
|
|
331
332
|
}), d({
|
|
332
333
|
clock: g,
|
|
333
|
-
target:
|
|
334
|
+
target: R
|
|
334
335
|
}), d({
|
|
335
336
|
source: o([
|
|
336
337
|
K.pending,
|
|
@@ -466,11 +467,15 @@ var G = p(({ client: e }) => {
|
|
|
466
467
|
}
|
|
467
468
|
let g = t.map((e) => Object.values(e).flat());
|
|
468
469
|
function v(e) {
|
|
470
|
+
return g.map((t) => t.filter((t) => t.experienceKey === e), { skipVoid: !1 });
|
|
471
|
+
}
|
|
472
|
+
function b(e) {
|
|
469
473
|
return t.map((t) => t[e] || [], { skipVoid: !1 });
|
|
470
474
|
}
|
|
471
475
|
return {
|
|
472
476
|
spawn: h,
|
|
473
|
-
|
|
477
|
+
getByExperienceKey: v,
|
|
478
|
+
getByExperienceId: b,
|
|
474
479
|
listStore: g
|
|
475
480
|
};
|
|
476
481
|
});
|
|
@@ -478,4 +483,4 @@ function K(e) {
|
|
|
478
483
|
return m(G, e);
|
|
479
484
|
}
|
|
480
485
|
//#endregion
|
|
481
|
-
export {
|
|
486
|
+
export { w as a, D as c, j as i, T as l, K as n, v as o, A as r, C as s, W as t };
|
|
@@ -204,7 +204,13 @@ async function p(e, t, n) {
|
|
|
204
204
|
...r,
|
|
205
205
|
args: e
|
|
206
206
|
})
|
|
207
|
-
}), {}), a = e.
|
|
207
|
+
}), {}), a = e.actions.listStore.getState().reduce((e, t) => ({
|
|
208
|
+
...e,
|
|
209
|
+
[t.name]: (...e) => t.action({
|
|
210
|
+
...r,
|
|
211
|
+
args: e
|
|
212
|
+
})
|
|
213
|
+
}), {}), o = e.features.listStore.getState().reduce((e, t) => ({
|
|
208
214
|
...e,
|
|
209
215
|
[t.id]: async () => {
|
|
210
216
|
let { bucket: e } = await t.getBucket();
|
|
@@ -225,7 +231,8 @@ async function p(e, t, n) {
|
|
|
225
231
|
search: r.location.search
|
|
226
232
|
} : void 0,
|
|
227
233
|
predicates: i,
|
|
228
|
-
|
|
234
|
+
actions: a,
|
|
235
|
+
features: o,
|
|
229
236
|
...n
|
|
230
237
|
});
|
|
231
238
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./object-CUJOjanb.cjs`);function t(e){return typeof e==`number`&&!isNaN(e)}function n(e){return typeof e==`string`}function r(e){return Array.isArray(e)}function i(e){return e instanceof Promise}function a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1}function o(e){if(t(e))return e;let n=parseFloat(`${e}`);return isNaN(n)?0:n}function s(e){return`${e}`}var c={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>o(e)>o(t),">=":(e,t)=>o(e)>=o(t),"<":(e,t,n)=>{let r=o(e),i=o(t);if(n===void 0)return r<i;let a=o(n);return r<i&&i<a},"<=":(e,t,n)=>{let r=o(e),i=o(t);if(n===void 0)return r<=i;let a=o(n);return r<=i&&i<=a},"!!":async e=>await u(e),"!":async e=>!await u(e),"%":(e,t)=>o(e)%o(t),log:e=>(console.log(e),e),in:(e,t)=>t?n(t)?t.indexOf(s(e))!==-1:r(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(s).join(``),substr:(e,t,n)=>{let r=s(e),i=o(t);if(n===void 0)return r.substr(i);let a=o(n);if(a<0){let e=r.substr(i);return e.substr(0,e.length+a)}return r.substr(i,a)},"+":(...e)=>e.reduce((e,t)=>o(e)+o(t),0),"*":(...e)=>e.reduce((e,t)=>o(e)*o(t),1),"-":(e,t)=>{let n=o(e);return t===void 0?-n:n-o(t)},"/":(e,t)=>o(e)/o(t),min:(...e)=>Math.min(...e.map(o)),max:(...e)=>Math.max(...e.map(o)),merge:(...e)=>e.reduce((e,t)=>r(t)?e.concat(t):e.concat([t]),[]),var(e,t){let n=arguments.length>1?t:null;if(e===``||e===`.`||e==null)return this;if(typeof e==`number`&&Array.isArray(this))return e>=0&&e<this.length?this[e]:n;let r=s(e);if(r===``||r===`.`)return this;let i=r.split(`.`),a=this;for(let e of i){if(a==null)return n;if(Array.isArray(a)){let t=parseInt(e,10);a=isNaN(t)?a[e]:a[t]}else a=a[e]}return a===void 0?n:a},async missing(...e){let t=r(e[0])?e[0]:e,n=[];for(let e of t){let t=await l({var:e},this);(t===null||t===``)&&n.push(`${e}`)}return n},async missing_some(e,t){let i=await l({missing:t},this);if(!r(i)||!r(t))return[];let a=i.filter(n);return t.filter(n).length-a.length>=o(e)?[]:a},invoke(...e){let[t,...n]=e;return typeof t==`function`?Reflect.apply(t,null,n):null},startsWith:(e,t)=>n(e)&&n(t)&&e.startsWith(t),endsWith:(e,t)=>n(e)&&n(t)&&e.endsWith(t),regexp_matches(e,t){let i=e,a=``;if(r(e)){let[t,n]=e;i=t,a=n}return!n(i)||!n(a)?!1:new RegExp(i,a).test(s(t))},throw(e){throw Error(s(e))}};async function l(e,t){if(!e)return e;if(i(e))return l(await e,t);if(r(e))return Promise.all(e.map(e=>l(e,t)));if(!a(e))return e;let n=d(e),o=n?e[n]??[]:[];switch(r(o)||(o=[o]),n){case`if`:case`?:`:for(let e=0;e<o.length-1;e+=2)if(await u(await l(o[e],t)))return l(o[e+1],t);return o.length%2==1?l(o[o.length-1],t):null;case`and`:{let e=null;for(let n of o)if(e=await l(n,t),!await u(e))return e;return e}case`or`:{let e=null;for(let n of o)if(e=await l(n,t),await u(e))return e;return e}case`map`:{let e=await l(o[0],t);return r(e)?await Promise.all(e.map(e=>l(o[1],e))):[]}case`filter`:{let e=await l(o[0],t);return r(e)?(await Promise.all(e.map(async e=>({item:e,shouldInclude:await u(await l(o[1],e))})))).filter(({shouldInclude:e})=>e).map(({item:e})=>e):[]}case`reduce`:{let e=await l(o[0],t);if(!r(e))return o.length>2?await l(o[2],t):null;let n=o[1],i=o.length>2?await l(o[2],t):null;for(let t of e)i=await l(n,{current:t,accumulator:i});return i}case`all`:{let e=await l(o[0],t);if(!r(e)||e.length===0)return!1;for(let t of e)if(!await u(await l(o[1],t)))return!1;return!0}case`some`:{let e=await l(o[0],t);if(!r(e))return!1;for(let t of e)if(await u(await l(o[1],t)))return!0;return!1}case`none`:{let e=await l(o[0],t);if(!r(e))return!0;for(let t of e)if(await u(await l(o[1],t)))return!1;return!0}case`catch`:try{return await l(o[0],t)}catch(e){return a(e)?await l(e,t):o[1]?await l(o[1],e):e instanceof Error?e.message:e}}let s=await Promise.all(o.map(e=>l(e,t))),f=n?c[n]:void 0;if(!f)throw Error(`Unrecognized operation ${n}`);return f.apply(t,s)}async function u(e){return i(e)?u(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function d(e){return Object.keys(e)[0]}function f(t){return!e.t(t)}async function p(e,t,n){let r=e.getStateSnapshot(),i=e.predicates.listStore.getState().reduce((e,t)=>({...e,[t.name]:(...e)=>t.predicate({...r,args:e})}),{}),a=e.features.listStore.getState().reduce((e,t)=>({...e,[t.id]:async()=>{let{bucket:e}=await t.getBucket();return e}}),{});return await l(t,{responses:e.responses.getAllStore.getState(),location:typeof r.location==`object`?{hash:r.location.hash,host:r.location.host,hostname:r.location.hostname,href:r.location.href,origin:r.location.origin,pathname:r.location.pathname,port:r.location.port,protocol:r.location.protocol,search:r.location.search}:void 0,predicates:i,features:
|
|
1
|
+
const e=require(`./object-CUJOjanb.cjs`);function t(e){return typeof e==`number`&&!isNaN(e)}function n(e){return typeof e==`string`}function r(e){return Array.isArray(e)}function i(e){return e instanceof Promise}function a(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1}function o(e){if(t(e))return e;let n=parseFloat(`${e}`);return isNaN(n)?0:n}function s(e){return`${e}`}var c={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>o(e)>o(t),">=":(e,t)=>o(e)>=o(t),"<":(e,t,n)=>{let r=o(e),i=o(t);if(n===void 0)return r<i;let a=o(n);return r<i&&i<a},"<=":(e,t,n)=>{let r=o(e),i=o(t);if(n===void 0)return r<=i;let a=o(n);return r<=i&&i<=a},"!!":async e=>await u(e),"!":async e=>!await u(e),"%":(e,t)=>o(e)%o(t),log:e=>(console.log(e),e),in:(e,t)=>t?n(t)?t.indexOf(s(e))!==-1:r(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(s).join(``),substr:(e,t,n)=>{let r=s(e),i=o(t);if(n===void 0)return r.substr(i);let a=o(n);if(a<0){let e=r.substr(i);return e.substr(0,e.length+a)}return r.substr(i,a)},"+":(...e)=>e.reduce((e,t)=>o(e)+o(t),0),"*":(...e)=>e.reduce((e,t)=>o(e)*o(t),1),"-":(e,t)=>{let n=o(e);return t===void 0?-n:n-o(t)},"/":(e,t)=>o(e)/o(t),min:(...e)=>Math.min(...e.map(o)),max:(...e)=>Math.max(...e.map(o)),merge:(...e)=>e.reduce((e,t)=>r(t)?e.concat(t):e.concat([t]),[]),var(e,t){let n=arguments.length>1?t:null;if(e===``||e===`.`||e==null)return this;if(typeof e==`number`&&Array.isArray(this))return e>=0&&e<this.length?this[e]:n;let r=s(e);if(r===``||r===`.`)return this;let i=r.split(`.`),a=this;for(let e of i){if(a==null)return n;if(Array.isArray(a)){let t=parseInt(e,10);a=isNaN(t)?a[e]:a[t]}else a=a[e]}return a===void 0?n:a},async missing(...e){let t=r(e[0])?e[0]:e,n=[];for(let e of t){let t=await l({var:e},this);(t===null||t===``)&&n.push(`${e}`)}return n},async missing_some(e,t){let i=await l({missing:t},this);if(!r(i)||!r(t))return[];let a=i.filter(n);return t.filter(n).length-a.length>=o(e)?[]:a},invoke(...e){let[t,...n]=e;return typeof t==`function`?Reflect.apply(t,null,n):null},startsWith:(e,t)=>n(e)&&n(t)&&e.startsWith(t),endsWith:(e,t)=>n(e)&&n(t)&&e.endsWith(t),regexp_matches(e,t){let i=e,a=``;if(r(e)){let[t,n]=e;i=t,a=n}return!n(i)||!n(a)?!1:new RegExp(i,a).test(s(t))},throw(e){throw Error(s(e))}};async function l(e,t){if(!e)return e;if(i(e))return l(await e,t);if(r(e))return Promise.all(e.map(e=>l(e,t)));if(!a(e))return e;let n=d(e),o=n?e[n]??[]:[];switch(r(o)||(o=[o]),n){case`if`:case`?:`:for(let e=0;e<o.length-1;e+=2)if(await u(await l(o[e],t)))return l(o[e+1],t);return o.length%2==1?l(o[o.length-1],t):null;case`and`:{let e=null;for(let n of o)if(e=await l(n,t),!await u(e))return e;return e}case`or`:{let e=null;for(let n of o)if(e=await l(n,t),await u(e))return e;return e}case`map`:{let e=await l(o[0],t);return r(e)?await Promise.all(e.map(e=>l(o[1],e))):[]}case`filter`:{let e=await l(o[0],t);return r(e)?(await Promise.all(e.map(async e=>({item:e,shouldInclude:await u(await l(o[1],e))})))).filter(({shouldInclude:e})=>e).map(({item:e})=>e):[]}case`reduce`:{let e=await l(o[0],t);if(!r(e))return o.length>2?await l(o[2],t):null;let n=o[1],i=o.length>2?await l(o[2],t):null;for(let t of e)i=await l(n,{current:t,accumulator:i});return i}case`all`:{let e=await l(o[0],t);if(!r(e)||e.length===0)return!1;for(let t of e)if(!await u(await l(o[1],t)))return!1;return!0}case`some`:{let e=await l(o[0],t);if(!r(e))return!1;for(let t of e)if(await u(await l(o[1],t)))return!0;return!1}case`none`:{let e=await l(o[0],t);if(!r(e))return!0;for(let t of e)if(await u(await l(o[1],t)))return!1;return!0}case`catch`:try{return await l(o[0],t)}catch(e){return a(e)?await l(e,t):o[1]?await l(o[1],e):e instanceof Error?e.message:e}}let s=await Promise.all(o.map(e=>l(e,t))),f=n?c[n]:void 0;if(!f)throw Error(`Unrecognized operation ${n}`);return f.apply(t,s)}async function u(e){return i(e)?u(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function d(e){return Object.keys(e)[0]}function f(t){return!e.t(t)}async function p(e,t,n){let r=e.getStateSnapshot(),i=e.predicates.listStore.getState().reduce((e,t)=>({...e,[t.name]:(...e)=>t.predicate({...r,args:e})}),{}),a=e.actions.listStore.getState().reduce((e,t)=>({...e,[t.name]:(...e)=>t.action({...r,args:e})}),{}),o=e.features.listStore.getState().reduce((e,t)=>({...e,[t.id]:async()=>{let{bucket:e}=await t.getBucket();return e}}),{});return await l(t,{responses:e.responses.getAllStore.getState(),location:typeof r.location==`object`?{hash:r.location.hash,host:r.location.host,hostname:r.location.hostname,href:r.location.href,origin:r.location.origin,pathname:r.location.pathname,port:r.location.port,protocol:r.location.protocol,search:r.location.search}:void 0,predicates:i,actions:a,features:o,...n})}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return p}});
|
package/dist/types/client.d.ts
CHANGED
|
@@ -7,34 +7,36 @@ import { LogicRule } from './logic-engine';
|
|
|
7
7
|
export interface CreateClientOptions {
|
|
8
8
|
/**
|
|
9
9
|
* Your organizations unique identifier.
|
|
10
|
-
* If not provided the organizationId will be read from
|
|
10
|
+
* If not provided the organizationId will be read from window.pickedConfig.organizationId or data-organizationid on the script tag.
|
|
11
11
|
*/
|
|
12
12
|
organizationId?: string;
|
|
13
13
|
/**
|
|
14
14
|
* Your projects unique identifier.
|
|
15
|
-
* If not provided the projectId will be read from
|
|
15
|
+
* If not provided the projectId will be read from window.pickedConfig.projectId or data-projectid on the script tag.
|
|
16
16
|
*/
|
|
17
17
|
projectId?: string;
|
|
18
18
|
/**
|
|
19
|
-
* Authentication token for previewing unpublished experiences
|
|
19
|
+
* Authentication token for previewing unpublished experiences.
|
|
20
20
|
*/
|
|
21
21
|
previewToken?: string;
|
|
22
22
|
/**
|
|
23
|
-
* Base URL for the Picked API service
|
|
23
|
+
* Base URL for the Picked API service.
|
|
24
24
|
*/
|
|
25
25
|
apiUrl?: string;
|
|
26
26
|
/**
|
|
27
|
-
* Base URL for the Picked Dashboard
|
|
27
|
+
* Base URL for the Picked Dashboard.
|
|
28
|
+
*
|
|
28
29
|
* @default 'https://dashboard.picked.app'
|
|
29
30
|
*/
|
|
30
31
|
dashboardUrl?: string;
|
|
31
32
|
/**
|
|
32
|
-
* Base URL for the documentation site shown in devtools
|
|
33
|
+
* Base URL for the documentation site shown in devtools.
|
|
34
|
+
*
|
|
33
35
|
* @default 'https://docs.picked.app'
|
|
34
36
|
*/
|
|
35
37
|
documentationSiteUrl?: string;
|
|
36
38
|
/**
|
|
37
|
-
* Register predicates to determine when experiences should be rendered
|
|
39
|
+
* Register predicates to determine when experiences should be rendered.
|
|
38
40
|
*
|
|
39
41
|
* @example
|
|
40
42
|
* ```typescript
|
|
@@ -47,20 +49,24 @@ export interface CreateClientOptions {
|
|
|
47
49
|
*/
|
|
48
50
|
predicates?: Record<string, Predicate>;
|
|
49
51
|
/**
|
|
50
|
-
* Register actions to be invoked in experience trees
|
|
52
|
+
* Register actions to be invoked in experience trees and JSON Logic conditions.
|
|
53
|
+
* Actions receive a state snapshot with full client context.
|
|
51
54
|
*
|
|
52
55
|
* @example
|
|
53
56
|
* ```typescript
|
|
54
57
|
* actions: {
|
|
55
|
-
* logEvent({
|
|
56
|
-
* // custom logic
|
|
58
|
+
* logEvent({ client, responses, location, args }) {
|
|
59
|
+
* // custom logic with access to full state
|
|
60
|
+
* },
|
|
61
|
+
* isLoggedIn({ responses }) {
|
|
62
|
+
* return responses.some(r => r.fieldKey === 'userId' && r.value)
|
|
57
63
|
* }
|
|
58
64
|
* }
|
|
59
65
|
* ```
|
|
60
66
|
*/
|
|
61
67
|
actions?: Record<string, Action>;
|
|
62
68
|
/**
|
|
63
|
-
* Plugins to extend client functionality
|
|
69
|
+
* Plugins to extend client functionality.
|
|
64
70
|
*
|
|
65
71
|
* @example
|
|
66
72
|
* ```typescript
|
|
@@ -73,24 +79,26 @@ export interface CreateClientOptions {
|
|
|
73
79
|
*/
|
|
74
80
|
plugins?: (Plugin | (() => Plugin) | Plugin[] | (() => Plugin[]))[];
|
|
75
81
|
/**
|
|
76
|
-
*
|
|
82
|
+
* Calculate AB test results to decide which experience to show.
|
|
77
83
|
*
|
|
78
84
|
* @example
|
|
79
|
-
```typescript
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
* ```typescript
|
|
86
|
+
* features: {
|
|
87
|
+
* 'summer-sales-experiment': {
|
|
88
|
+
* key: 'summer-sales-experiment-1',
|
|
89
|
+
* name: 'Summer Sales Experiment',
|
|
90
|
+
* decide: async () => {
|
|
91
|
+
* await new Promise((resolve) => setTimeout(resolve, 800))
|
|
92
|
+
* return false
|
|
93
|
+
* },
|
|
94
|
+
* weight: 0.2,
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
90
98
|
*/
|
|
91
99
|
features?: Record<string, Feature | (() => Feature)>;
|
|
92
100
|
/**
|
|
93
|
-
* Register components for use in dynamic experiences
|
|
101
|
+
* Register components for use in dynamic experiences.
|
|
94
102
|
*
|
|
95
103
|
* @example
|
|
96
104
|
* ```typescript
|
|
@@ -102,33 +110,29 @@ export interface CreateClientOptions {
|
|
|
102
110
|
*/
|
|
103
111
|
components?: Record<string, AdaptedComponent>;
|
|
104
112
|
/**
|
|
105
|
-
* Evaluate a condition or boolean expression before initializing the client
|
|
113
|
+
* Evaluate a condition or boolean expression before initializing the client.
|
|
106
114
|
*
|
|
107
115
|
* @example
|
|
108
116
|
* ```typescript
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
+
* precondition: {
|
|
118
|
+
* invoke: {
|
|
119
|
+
* var: 'predicates.shopify-is-product-page',
|
|
120
|
+
* },
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
117
123
|
*/
|
|
118
124
|
precondition?: LogicRule;
|
|
119
125
|
/**
|
|
120
|
-
* Evaluate a condition or boolean expression to determine the user state at initialization
|
|
126
|
+
* Evaluate a condition or boolean expression to determine the user state at initialization.
|
|
121
127
|
*
|
|
122
|
-
*
|
|
128
|
+
* @example
|
|
123
129
|
* ```typescript
|
|
124
|
-
*
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
*
|
|
130
|
+
* condition: {
|
|
131
|
+
* invoke: {
|
|
132
|
+
* var: 'features.convincely-enabled',
|
|
133
|
+
* },
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
132
136
|
*/
|
|
133
137
|
condition?: LogicRule;
|
|
134
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAEtC;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEhC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,EAAE,CAAA;IAEnE;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAA;IAEpD;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAE7C;;;;;;;;;;;OAWG;IACH,YAAY,CAAC,EAAE,SAAS,CAAA;IAExB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB"}
|
|
@@ -1,17 +1,49 @@
|
|
|
1
1
|
import { Store } from 'effector';
|
|
2
|
-
|
|
2
|
+
import { StateSnapshot } from '../../utils/state-snaphot';
|
|
3
|
+
import { Picked } from '../../picked';
|
|
4
|
+
/**
|
|
5
|
+
* A named callable function that receives a state snapshot and optional arguments.
|
|
6
|
+
* Actions can return values (boolean, string, string[]) or execute side effects (void).
|
|
7
|
+
*/
|
|
8
|
+
export type Action = (snapshot: StateSnapshot & {
|
|
9
|
+
args: unknown[];
|
|
10
|
+
}) => boolean | Promise<boolean> | string | Promise<string> | string[] | Promise<string[]> | void | Promise<void> | undefined;
|
|
3
11
|
export type ActionsStore = ReturnType<typeof createActionIndexFactory>;
|
|
4
12
|
export interface ActionIndexItem {
|
|
5
13
|
name: string;
|
|
6
14
|
action: Action;
|
|
7
15
|
}
|
|
8
|
-
declare const createActionIndexFactory: (
|
|
16
|
+
declare const createActionIndexFactory: ({ client }: {
|
|
17
|
+
client: Picked;
|
|
18
|
+
}) => {
|
|
9
19
|
register: (name: string, action: Action) => void;
|
|
10
|
-
getByName: (name: string) => Store<
|
|
20
|
+
getByName: (name: string) => Store<Action | undefined>;
|
|
11
21
|
listStore: Store<ActionIndexItem[]>;
|
|
12
|
-
getEvokableAction: (actionName: string) => Store<(
|
|
22
|
+
getEvokableAction: (actionName: string) => Store<() => ReturnType<Action>>;
|
|
13
23
|
};
|
|
14
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Creates an action index with lifecycle stores and registration logic.
|
|
26
|
+
*
|
|
27
|
+
* @param {object} params - Factory parameters including the client.
|
|
28
|
+
* @returns {ReturnType<typeof createActionIndexFactory>} The action index with register, getByName, listStore, and getEvokableAction methods.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const actions = createActionIndex({ client })
|
|
32
|
+
* actions.register('logEvent', ({ responses }) => { console.log(responses) })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function createActionIndex<T extends Parameters<typeof createActionIndexFactory>[0]>(params: T): ReturnType<typeof createActionIndexFactory>;
|
|
36
|
+
/**
|
|
37
|
+
* Convenience helper that registers a single action on the given store.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} name - Unique name for the action.
|
|
40
|
+
* @param {Action} action - The action function to register.
|
|
41
|
+
* @param {ActionsStore} actions - The actions store to register into.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* setupAction('logEvent', ({ responses }) => { console.log(responses) }, actionsStore)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
15
47
|
export declare const setupAction: (name: string, action: Action, actions: ActionsStore) => void;
|
|
16
48
|
export {};
|
|
17
49
|
//# sourceMappingURL=action.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../../src/entities/action/action.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../../src/entities/action/action.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EAA8D,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AAGjG,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CACnB,QAAQ,EAAE,aAAa,GAAG;IAAE,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,KAE3C,OAAO,GACP,OAAO,CAAC,OAAO,CAAC,GAChB,MAAM,GACN,OAAO,CAAC,MAAM,CAAC,GACf,MAAM,EAAE,GACR,OAAO,CAAC,MAAM,EAAE,CAAC,GACjB,IAAI,GACJ,OAAO,CAAC,IAAI,CAAC,GACb,SAAS,CAAA;AAEb,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEtE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAKD,QAAA,MAAM,wBAAwB,eAA8B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;qBA2BpD,MAAM,UAAU,MAAM,KAAG,IAAI;sBA2B5B,MAAM;;oCAiBQ,MAAM,KAAG,KAAK,CAAC,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;CAuC/E,CAAA;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,EACxF,MAAM,EAAE,CAAC,GACR,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAE7C;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS,YAAY,KAAG,IAEjF,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LogicRule } from '../../logic-engine';
|
|
2
|
+
export type ConditionsStore = ReturnType<typeof createConditionIndex>;
|
|
3
|
+
export interface Condition {
|
|
4
|
+
id: string;
|
|
5
|
+
key: string;
|
|
6
|
+
name: string;
|
|
7
|
+
logic: LogicRule;
|
|
8
|
+
}
|
|
9
|
+
declare const createConditionIndexFactory: () => {
|
|
10
|
+
register: (condition: Condition) => void;
|
|
11
|
+
getById: (id: Condition["id"]) => import('effector').Store<Condition | null>;
|
|
12
|
+
getByKey: (key: Condition["key"]) => import('effector').Store<Condition | null>;
|
|
13
|
+
listStore: import('effector').Store<Condition[]>;
|
|
14
|
+
indexStore: import('effector').StoreWritable<{
|
|
15
|
+
[id: string]: Condition;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
export declare function createConditionIndex(): ReturnType<typeof createConditionIndexFactory>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=condition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../../src/entities/condition/condition.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAIrE,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,SAAS,CAAA;CACjB;AAGD,QAAA,MAAM,2BAA2B;0BAcF,SAAS,KAAG,IAAI;kBAcxB,SAAS,CAAC,IAAI,CAAC;oBAUb,SAAS,CAAC,KAAK,CAAC;;;;;CAgBvC,CAAA;AAEF,wBAAgB,oBAAoB,IAAI,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAErF"}
|