@frigade/react 1.36.2 → 1.36.3
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/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +2 -2
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var ia=Object.defineProperty,na=Object.defineProperties;var sa=Object.getOwnPropertyDescriptors;var Eo=Object.getOwnPropertySymbols;var si=Object.prototype.hasOwnProperty,li=Object.prototype.propertyIsEnumerable;var ni=(e,t,o)=>t in e?ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,b=(e,t)=>{for(var o in t||(t={}))si.call(t,o)&&ni(e,o,t[o]);if(Eo)for(var o of Eo(t))li.call(t,o)&&ni(e,o,t[o]);return e},j=(e,t)=>na(e,sa(t));var ai=e=>typeof e=="symbol"?e:e+"",Ne=(e,t)=>{var o={};for(var i in e)si.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(e!=null&&Eo)for(var i of Eo(e))t.indexOf(i)<0&&li.call(e,i)&&(o[i]=e[i]);return o};var U=(e,t,o)=>new Promise((i,n)=>{var r=d=>{try{p(o.next(d))}catch(s){n(s)}},l=d=>{try{p(o.throw(d))}catch(s){n(s)}},p=d=>d.done?i(d.value):Promise.resolve(d.value).then(r,l);p((o=o.apply(e,t)).next())});import Et,{createContext as bd,useEffect as Jo,useState as je}from"react";import{ThemeProvider as wd}from"styled-components";import Bt,{useContext as Xp,useEffect as Xt,useState as yo}from"react";import{useCallback as kt,useContext as ya,useEffect as Sa}from"react";import lr,{useMemo as di}from"react";var pi="1.36.2 ";var ot="NOT_STARTED_STEP",R="COMPLETED_FLOW",Ao="ABORTED_FLOW",Ft="STARTED_FLOW",Me="NOT_STARTED_FLOW",De="COMPLETED_STEP",Oo="STARTED_STEP";function Je(){let{publicApiKey:e,userId:t,apiUrl:o}=lr.useContext(J);return{config:di(()=>({headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-Frigade-SDK-Version":pi,"X-Frigade-SDK-Platform":"React"}}),[e,t]),apiUrl:di(()=>`${o}/v1/public/`,[o])}}var la="frigade-last-call-at-",aa="frigade-last-call-data-";function _t(){let{shouldGracefullyDegrade:e,readonly:t}=lr.useContext(J);return(o,i)=>U(this,null,function*(){if(t&&(i.method==="POST"||i.method==="PUT"||i.method==="DELETE"))return zt();if(e)return console.log(`Skipping ${o} call to Frigade due to error`),zt();let n=la+o,r=aa+o;if(typeof window!="undefined"&&window.localStorage&&i&&i.body&&i.method==="POST"){let p=window.localStorage.getItem(n),d=window.localStorage.getItem(r);if(p&&d&&d==i.body){let s=new Date(p);if(new Date().getTime()-s.getTime()<1e3)return zt()}typeof window!="undefined"&&(window.localStorage.setItem(n,new Date().toISOString()),window.localStorage.setItem(r,i.body))}let l;try{l=yield fetch(o,i)}catch(p){return zt(p)}return l?l.ok?l:zt(l.statusText):zt()})}function zt(e){return e&&console.log("Call to Frigade failed",e),{json:()=>({})}}function Ht(){let{publicApiKey:e,shouldGracefullyDegrade:t}=lr.useContext(J);function o(){return t?(console.error("Frigade hooks cannot be used when Frigade SDK has failed to initialize"),!1):e?!0:(console.error("Frigade hooks cannot be used outside the scope of FrigadeProvider"),!1)}return{verifySDKInitiated:o}}import{useContext as ha,useState as ci}from"react";import{useContext as da,useEffect as ca,useState as ma}from"react";import ua from"swr";import{useContext as pa}from"react";function Be(){let{openFlowStates:e,setOpenFlowStates:t,hasActiveFullPageFlow:o,setCompletedFlowsToKeepOpenDuringSession:i,completedFlowsToKeepOpenDuringSession:n}=pa(J);function r(c,g=!1){var y;return(y=e[c])!=null?y:g}function l(c,g){t(y=>j(b({},y),{[c]:g}))}function p(c){t(g=>{let C=g,{[c]:y}=C,T=Ne(C,[ai(c)]);return b({},T)})}function d(c){n.includes(c)||i(g=>[...g,c])}function s(c){return n.includes(c)}function m(c){return Object.entries(e).some(([g,y])=>y&&g!=c)||o}return{getOpenFlowState:r,setOpenFlowState:l,resetOpenFlowState:p,hasOpenModals:m,setKeepCompletedFlowOpenDuringSession:d,shouldKeepCompletedFlowOpenDuringSession:s}}import fa from"swr/immutable";import ao from"core-js-pure/actual/structured-clone";function ar(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function xe(...e){let t=e.shift(),o=e.length===1?e[0]:xe(...e);if(!ar(t)||!ar(o))throw new Error("deepmerge can only merge Objects");let i=ao(t);return Object.entries(o).forEach(([n,r])=>{ar(r)?i[n]!==void 0?Object.assign(i,{[n]:xe(i[n],ao(r))}):Object.assign(i,{[n]:ao(r)}):Array.isArray(r)?i[n]!==void 0?Object.assign(i,{[n]:[...i[n],...ao(r)]}):Object.assign(i,{[n]:ao(r)}):Object.assign(i,{[n]:r})}),i}var ga="unknown";function Ue(){let{config:e,apiUrl:t}=Je(),{publicApiKey:o,userId:i,organizationId:n,flows:r,setShouldGracefullyDegrade:l,readonly:p}=da(J),{resetOpenFlowState:d}=Be(),[s,m]=ma(!1),c={data:r.map(S=>({flowId:S.id,flowState:R,lastStepId:null,userId:i,foreignUserId:i,stepStates:{},shouldTrigger:!1}))},g=S=>fetch(S,e).then(k=>{if(k.ok)return k.json();throw new Error("Failed to fetch user flow states")}).catch(k=>(console.log(`Error fetching ${S}: ${k}. Will gracefully degrade and hide Frigade`),l(!0),c)),y=o&&r&&i?`${t}userFlowStates?foreignUserId=${encodeURIComponent(i)}${n?`&foreignUserGroupId=${encodeURIComponent(n)}`:""}`:null,{data:T,isLoading:C,mutate:h,error:A}=p?fa(y,g):ua(y,g,{revalidateOnFocus:!0,revalidateIfStale:!0,keepPreviousData:!0,revalidateOnMount:!1,errorRetryInterval:1e4,errorRetryCount:3,onError:()=>c,onLoadingSlow:()=>c}),F=T==null?void 0:T.data;ca(()=>{!s&&!C&&F&&m(!0)},[F,s,C]);function P(S){return U(this,null,function*(){if(F&&!p){let k=F.find(L=>L.flowId===S);k&&k.flowState!==R&&(k.flowState=R),yield h(Promise.resolve(xe(T,{data:F})),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}function v(S,k,L){return U(this,null,function*(){if(F){let O=F.find(N=>N.flowId===S);O&&(O.stepStates[k]=L,O.flowState=Ft),yield h(Promise.resolve(xe(T,{data:F})),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}function B(S,k,L){return U(this,null,function*(){if(F){let O=F.find(N=>N.flowId===S);O&&(O.lastStepId=k,O.stepStates[k]=L,O.flowState=Ft),yield h(xe(T,{data:F}),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}function f(S){return U(this,null,function*(){if(F){let k=F.find(L=>L.flowId===S);k&&k.flowState!==Me&&(k.flowState=Me,k.lastStepId=ga,Object.keys(k.stepStates).forEach(L=>{k.stepStates[L].actionType=ot,k.stepStates[L].createdAt=new Date().toISOString()}),yield h(xe(T,{data:F}),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1}),d(S))}})}function I(S,k,L){return U(this,null,function*(){if(F){let O=F.find(N=>N.flowId===S);O&&(O.stepStates[k]=L),yield h(Promise.resolve(xe(T,{data:F})),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}return{userFlowStatesData:F,isLoadingUserFlowStateData:!s,mutateUserFlowState:h,optimisticallyMarkFlowCompleted:P,optimisticallyMarkFlowNotStarted:f,optimisticallyMarkStepCompleted:v,optimisticallyMarkStepNotStarted:I,optimisticallyMarkStepStarted:B,error:A}}function po(){let{config:e,apiUrl:t}=Je(),{userFlowStatesData:o,mutateUserFlowState:i}=Ue(),{failedFlowResponses:n,setFailedFlowResponses:r,flowResponses:l,setFlowResponses:p}=ha(J),[d,s]=ci(new Set),[m,c]=ci(new Set),g=_t();function y(h){let A=JSON.stringify(h);if(d.has(A))return null;d.add(A),s(d),m.add(h),c(m);let F=l==null?void 0:l.find(P=>P.flowSlug===h.flowSlug&&P.stepId===h.stepId&&P.actionType===h.actionType&&P.createdAt===h.createdAt);return g(`${t}flowResponses`,j(b({},e),{method:"POST",body:A})).then(P=>{P.status!==200&&P.status!==201?(console.log("Failed to send flow response for step "+h.stepId+". Will retry again later."),r([...n,h])):F||p(v=>[...v!=null?v:[],h])})}function T(h){return U(this,null,function*(){h.foreignUserId&&(h.actionType===Ft||h.actionType===Me?yield y(h):h.actionType===R?yield y(h):h.actionType===Oo?yield y(h):h.actionType===De?yield y(h):h.actionType===Ao?yield y(h):h.actionType===ot&&(yield y(h)))})}function C(){let h=[];return o==null||o.forEach(A=>{if(A&&A.stepStates&&Object.keys(A.stepStates).length!==0)for(let F in A.stepStates){let P=A.stepStates[F];h.push({foreignUserId:A.foreignUserId,flowSlug:A.flowId,stepId:P.stepId,actionType:P.actionType,data:{},createdAt:new Date(P.createdAt),blocked:P.blocked,hidden:P.hidden})}}),[...h,...l]}return{addResponse:T,setFlowResponses:p,getFlowResponses:C}}import ba from"swr";var xa=/user.flow\(([^\)]+)\) == '?COMPLETED_FLOW'?/gm,mi=e=>{let t=xa.exec(e);if(t===null)return null;let o=null;return t.forEach((i,n)=>{let r=Ca(i,"'","");r.startsWith("flow_")&&(o=r)}),o},Ca=function(e,t,o){return e.replace(new RegExp(t,"g"),o)};function pr(e){try{return JSON.parse(e)}catch(t){return console.error("Failed to parse Frigade config.yml to JSON",t),null}}var dr=(s=>(s.CHECKLIST="CHECKLIST",s.FORM="FORM",s.TOUR="TOUR",s.SUPPORT="SUPPORT",s.CUSTOM="CUSTOM",s.BANNER="BANNER",s.EMBEDDED_TIP="EMBEDDED_TIP",s.NPS_SURVEY="NPS_SURVEY",s.ANNOUNCEMENT="ANNOUNCEMENT",s))(dr||{});function X(){let{config:e,apiUrl:t}=Je(),{flows:o,setFlows:i,userId:n,organizationId:r,publicApiKey:l,customVariables:p,setCustomVariables:d,hasActiveFullPageFlow:s,setHasActiveFullPageFlow:m,setFlowResponses:c,setShouldGracefullyDegrade:g,readonly:y}=ya(J),T={data:[]},{verifySDKInitiated:C}=Ht(),{addResponse:h,getFlowResponses:A}=po(),F=x=>fetch(x,e).then(u=>u.ok?u.json():(console.log(`Error fetching ${x} (${u.status}): ${u.statusText}. Will gracefully degrade and hide Frigade`),g(!0),T)).catch(u=>(console.log(`Error fetching ${x}: ${u}. Will gracefully degrade and hide Frigade`),g(!0),T)),{mutateUserFlowState:P,userFlowStatesData:v,isLoadingUserFlowStateData:B,optimisticallyMarkFlowCompleted:f,optimisticallyMarkFlowNotStarted:I,optimisticallyMarkStepCompleted:S,optimisticallyMarkStepNotStarted:k,optimisticallyMarkStepStarted:L}=Ue(),{data:O,error:N,isLoading:V}=ba(l?`${t}flows${y?"?readonly=true":""}`:null,F,{keepPreviousData:!0});Sa(()=>{if(N){console.error(N);return}O&&O.data&&i(O.data)},[O,N]);function W(x){if(V)return null;let u=o.find(w=>w.slug===x);return!u&&o.length>0&&!B&&!V?(console.log(`Flow with id ${x} not found`),null):(u==null?void 0:u.active)===!1&&!y?null:u}function Y(x){var z,ce;if(!W(x))return[];let u=W(x).data;return u?(u=Q(u),((ce=(z=pr(u))==null?void 0:z.data)!=null?ce:[]).map(ae=>{let wt=ie(ae);return j(b({handleSecondaryButtonClick:()=>{ae.skippable===!0&&re(x,ae.id,{skipped:!0})}},ae),{complete:Fe(x,ae.id)===De||wt>=1,currentlyActive:v==null?void 0:v.some(Tt=>Tt.flowId==x&&Tt.lastStepId===ae.id),blocked:ye(x,ae.id),hidden:$e(x,ae.id),handlePrimaryButtonClick:()=>{(!ae.completionCriteria&&(ae.autoMarkCompleted||ae.autoMarkCompleted===void 0)||ae.completionCriteria&&ae.autoMarkCompleted===!0)&&re(x,ae.id)},progress:wt})}).filter(ae=>ae.hidden!==!0)):[]}function Q(x){return x.replaceAll(/\${(.*?)}/g,(u,w)=>p[w]===void 0?"":String(p[w]).replace(/[\u00A0-\u9999<>\&]/g,function(z){return"&#"+z.charCodeAt(0)+";"}).replaceAll(/[\\]/g,"\\\\").replaceAll(/[\"]/g,'\\"').replaceAll(/[\/]/g,"\\/").replaceAll(/[\b]/g,"\\b").replaceAll(/[\f]/g,"\\f").replaceAll(/[\n]/g,"\\n").replaceAll(/[\r]/g,"\\r").replaceAll(/[\t]/g,"\\t"))}function de(x){var w;if(!W(x))return[];let u=W(x).data;return u?(u=Q(u),(w=JSON.parse(u))!=null?w:{}):[]}function H(x,u){d(w=>j(b({},w),{[x]:u}))}function le(x){!B&&!V&&x&&JSON.stringify(p)!=JSON.stringify(b(b({},p),x))&&Object.keys(x).forEach(u=>{H(u,x[u])})}let fe=kt((x,u,w)=>U(this,null,function*(){if(!C())return;let z={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:u,actionType:Oo,data:w!=null?w:{},createdAt:new Date,blocked:!1,hidden:!1};he(z)&&(yield L(x,u,z),h(z))}),[n,r,v]),Te=kt((x,u,w)=>U(this,null,function*(){if(!C())return;let z={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:u,actionType:ot,data:w!=null?w:{},createdAt:new Date,blocked:!1,hidden:!1};he(z)&&(yield k(x,u,z),h(z))}),[n,r,v]),re=kt((x,u,w)=>U(this,null,function*(){if(!C())return;let z={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:u,actionType:De,data:w!=null?w:{},createdAt:new Date,blocked:!1,hidden:!1};he(z)&&(yield S(x,u,z),h(z))}),[n,r,v]),Z=kt((x,u)=>U(this,null,function*(){if(!C()||Oe(x)===Me)return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:Me,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};yield I(x),he(w)&&h(w)}),[n,r,v]),q=kt((x,u)=>U(this,null,function*(){if(!C())return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:Ft,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};he(w)&&h(w)}),[n,r,v]),_=kt((x,u)=>U(this,null,function*(){if(!C())return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:R,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};he(w)&&(yield f(x),h(w))}),[n,r,v]),Le=kt((x,u)=>U(this,null,function*(){if(!C())return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:Ao,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};he(w)&&(yield f(x),h(w))}),[n,r,v]);function he(x){var u;if(v===void 0)return!1;if(v){let w=v.find(z=>z.flowId===x.flowSlug);if(x.actionType===ot&&(!(w!=null&&w.stepStates[x.stepId])||w.stepStates[x.stepId].actionType===ot))return!1;if(w&&((u=w.stepStates[x.stepId])==null?void 0:u.actionType)===x.actionType){if(x.actionType===De&&(!x.data||JSON.stringify(x.data)===JSON.stringify({})))return!1;let z=Object.keys(w.stepStates).sort((ce,ae)=>{let wt=new Date(w.stepStates[ce].createdAt),Tt=new Date(w.stepStates[ae].createdAt);return wt.getTime()-Tt.getTime()});if(w.stepStates[z[z.length-1]].actionType===x.actionType&&x.stepId===z[z.length-1])return!1}if(w&&w.flowState===R&&x.actionType===R)return!1}return!0}function Fe(x,u){let w=$(x,u);return B?null:w?w.actionType:ot}function ye(x,u){let w=$(x,u);return w?w.blocked:!1}function $e(x,u){let w=$(x,u);return w?w.hidden:!1}function $(x,u){var z;if(B)return null;let w=v==null?void 0:v.find(ce=>ce.flowId===x);return!w||!w.stepStates[u]?null:(z=w.stepStates[u])!=null?z:null}function M(x){var w,z;if(B||!v)return null;if(Oe(x)===Me)return(w=Y(x)[0])!=null?w:null;let u=(z=v.find(ce=>ce.flowId===x))==null?void 0:z.lastStepId;return u?Y(x).find(ce=>ce.id===u):null}function D(x){var z;let u=M(x);if(!u)return 0;let w=(z=Y(x).findIndex(ce=>ce.id===u.id))!=null?z:0;return Fe(x,u.id)===De&&w<Y(x).length-1?w+1:w}function ie(x){if(!x.completionCriteria)return;let u=mi(x.completionCriteria);if(u===null)return;let w=bt(u),z=Ge(u);return z===0?void 0:w/z}function Oe(x){let u=v==null?void 0:v.find(w=>w.flowId===x);return u?u.flowState:null}function bt(x){let u=Y(x);return u.length===0?0:u.filter(z=>Fe(x,z.id)===De).length}function Ge(x){return Y(x).length}function mt(x){let u=o.find(w=>w.slug===x);return u?pr(u.data):null}function Ke(x){if(y)return!1;if(B)return!0;if(x!=null&&x.targetingLogic&&v){let u=v.find(w=>w.flowId===x.slug);if(u)return u.shouldTrigger===!1}return!!(x!=null&&x.targetingLogic&&n&&n.startsWith("guest_"))}function Dt(x){return!Ke(W(x))}function Ut(){n&&P()}function Wt(){return o}return{getAllFlows:Wt,getFlow:W,getFlowData:mt,isLoading:B||V,getStepStatus:Fe,getFlowSteps:Y,getCurrentStepIndex:D,markStepStarted:fe,markStepCompleted:re,markFlowNotStarted:Z,markFlowStarted:q,markFlowCompleted:_,markFlowAborted:Le,markStepNotStarted:Te,getFlowStatus:Oe,getNumberOfStepsCompleted:bt,getNumberOfSteps:Ge,targetingLogicShouldHideFlow:Ke,setCustomVariable:H,updateCustomVariables:le,customVariables:p,getStepOptionalProgress:ie,getFlowMetadata:de,isStepBlocked:ye,isStepHidden:$e,hasActiveFullPageFlow:s,setHasActiveFullPageFlow:m,isFlowAvailableToUser:Dt,refresh:Ut}}import{useCallback as cr,useContext as wa,useEffect as Ta}from"react";var Vt="guest_";function co(){let{userId:e,organizationId:t,setUserId:o,setUserProperties:i,shouldGracefullyDegrade:n}=wa(J),{config:r,apiUrl:l}=Je(),{mutateUserFlowState:p}=Ue(),d=_t(),{verifySDKInitiated:s}=Ht();function m(T){return`frigade-user-registered-${T}`}Ta(()=>{if(e&&!t){if(e.startsWith(Vt))return;let T=m(e);localStorage.getItem(T)||(d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify({foreignId:e})})),localStorage.setItem(T,"true"))}},[e,n,t]);let c=cr(T=>U(this,null,function*(){if(!s())return;let C={foreignId:e,properties:T};yield d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify(C)})),i(h=>b(b({},h),T)),p()}),[e,r,n,p]),g=cr((T,C)=>U(this,null,function*(){if(!s())return;let A={foreignId:e,events:[{event:T,properties:C}]};yield d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify(A)})),p()}),[e,r,p]),y=cr((T,C)=>U(this,null,function*(){if(s())if(C){let h=m(T);localStorage.setItem(h,"true"),o(T);let A={foreignId:T,properties:C};yield d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify(A)})),i(F=>b(b({},F),C)),p()}else o(T)}),[r,n,p]);return{userId:e,setUserId:o,setUserIdWithProperties:y,addPropertiesToUser:c,trackEventForUser:g}}import{v4 as Qp}from"uuid";import Re,{useEffect as hn,useState as qp}from"react";import qe,{useEffect as gr,useState as Na}from"react";import $o from"styled-components";import Fa from"react";import ka from"styled-components";var ui="fr-",mo="cfr-";function a(e,t){let o=`${ui}${e}`;if(!t)return o;if(t.styleOverrides&&t.styleOverrides[e]){if(typeof t.styleOverrides[e]=="string")return o+" "+t.styleOverrides[e];if(typeof t.styleOverrides[e]=="object")return o+" "+mo+e}return o}function E(e){if(!e.className||e.className.indexOf(mo)!==-1)return"";let o=e.className.replace(/\s+/g," ").split(" ");return o.length==1&&o[0].startsWith(ui)?"":`:not(${o.map(i=>`.${i}`).join(", ")})`}function No(e){return e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase()}function ke(e){return e!=null&&e.styleOverrides?Object.keys(e.styleOverrides).map(t=>`${No(t)}: ${e.styleOverrides[t]};`).join(" "):""}function be(...e){return e.filter(Boolean).join(" ")}function uo(e){return e.charAt(0).toUpperCase()+e.slice(1)}var Pa=ka.div`
|
|
2
|
+
var ia=Object.defineProperty,na=Object.defineProperties;var sa=Object.getOwnPropertyDescriptors;var Eo=Object.getOwnPropertySymbols;var si=Object.prototype.hasOwnProperty,li=Object.prototype.propertyIsEnumerable;var ni=(e,t,o)=>t in e?ia(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,b=(e,t)=>{for(var o in t||(t={}))si.call(t,o)&&ni(e,o,t[o]);if(Eo)for(var o of Eo(t))li.call(t,o)&&ni(e,o,t[o]);return e},j=(e,t)=>na(e,sa(t));var ai=e=>typeof e=="symbol"?e:e+"",Ne=(e,t)=>{var o={};for(var i in e)si.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(e!=null&&Eo)for(var i of Eo(e))t.indexOf(i)<0&&li.call(e,i)&&(o[i]=e[i]);return o};var U=(e,t,o)=>new Promise((i,n)=>{var r=d=>{try{p(o.next(d))}catch(s){n(s)}},l=d=>{try{p(o.throw(d))}catch(s){n(s)}},p=d=>d.done?i(d.value):Promise.resolve(d.value).then(r,l);p((o=o.apply(e,t)).next())});import Et,{createContext as bd,useEffect as Jo,useState as je}from"react";import{ThemeProvider as wd}from"styled-components";import Bt,{useContext as Xp,useEffect as Xt,useState as yo}from"react";import{useCallback as kt,useContext as ya,useEffect as Sa}from"react";import lr,{useMemo as di}from"react";var pi="1.36.3 ";var ot="NOT_STARTED_STEP",R="COMPLETED_FLOW",Ao="ABORTED_FLOW",Ft="STARTED_FLOW",Me="NOT_STARTED_FLOW",De="COMPLETED_STEP",Oo="STARTED_STEP";function Je(){let{publicApiKey:e,userId:t,apiUrl:o}=lr.useContext(J);return{config:di(()=>({headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-Frigade-SDK-Version":pi,"X-Frigade-SDK-Platform":"React"}}),[e,t]),apiUrl:di(()=>`${o}/v1/public/`,[o])}}var la="frigade-last-call-at-",aa="frigade-last-call-data-";function _t(){let{shouldGracefullyDegrade:e,readonly:t}=lr.useContext(J);return(o,i)=>U(this,null,function*(){if(t&&(i.method==="POST"||i.method==="PUT"||i.method==="DELETE"))return zt();if(e)return console.log(`Skipping ${o} call to Frigade due to error`),zt();let n=la+o,r=aa+o;if(typeof window!="undefined"&&window.localStorage&&i&&i.body&&i.method==="POST"){let p=window.localStorage.getItem(n),d=window.localStorage.getItem(r);if(p&&d&&d==i.body){let s=new Date(p);if(new Date().getTime()-s.getTime()<1e3)return zt()}typeof window!="undefined"&&(window.localStorage.setItem(n,new Date().toISOString()),window.localStorage.setItem(r,i.body))}let l;try{l=yield fetch(o,i)}catch(p){return zt(p)}return l?l.ok?l:zt(l.statusText):zt()})}function zt(e){return e&&console.log("Call to Frigade failed",e),{json:()=>({})}}function Ht(){let{publicApiKey:e,shouldGracefullyDegrade:t}=lr.useContext(J);function o(){return t?(console.error("Frigade hooks cannot be used when Frigade SDK has failed to initialize"),!1):e?!0:(console.error("Frigade hooks cannot be used outside the scope of FrigadeProvider"),!1)}return{verifySDKInitiated:o}}import{useContext as ha,useState as ci}from"react";import{useContext as da,useEffect as ca,useState as ma}from"react";import ua from"swr";import{useContext as pa}from"react";function Be(){let{openFlowStates:e,setOpenFlowStates:t,hasActiveFullPageFlow:o,setCompletedFlowsToKeepOpenDuringSession:i,completedFlowsToKeepOpenDuringSession:n}=pa(J);function r(c,g=!1){var y;return(y=e[c])!=null?y:g}function l(c,g){t(y=>j(b({},y),{[c]:g}))}function p(c){t(g=>{let C=g,{[c]:y}=C,T=Ne(C,[ai(c)]);return b({},T)})}function d(c){n.includes(c)||i(g=>[...g,c])}function s(c){return n.includes(c)}function m(c){return Object.entries(e).some(([g,y])=>y&&g!=c)||o}return{getOpenFlowState:r,setOpenFlowState:l,resetOpenFlowState:p,hasOpenModals:m,setKeepCompletedFlowOpenDuringSession:d,shouldKeepCompletedFlowOpenDuringSession:s}}import fa from"swr/immutable";import ao from"core-js-pure/actual/structured-clone";function ar(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function xe(...e){let t=e.shift(),o=e.length===1?e[0]:xe(...e);if(!ar(t)||!ar(o))throw new Error("deepmerge can only merge Objects");let i=ao(t);return Object.entries(o).forEach(([n,r])=>{ar(r)?i[n]!==void 0?Object.assign(i,{[n]:xe(i[n],ao(r))}):Object.assign(i,{[n]:ao(r)}):Array.isArray(r)?i[n]!==void 0?Object.assign(i,{[n]:[...i[n],...ao(r)]}):Object.assign(i,{[n]:ao(r)}):Object.assign(i,{[n]:r})}),i}var ga="unknown";function Ue(){let{config:e,apiUrl:t}=Je(),{publicApiKey:o,userId:i,organizationId:n,flows:r,setShouldGracefullyDegrade:l,readonly:p}=da(J),{resetOpenFlowState:d}=Be(),[s,m]=ma(!1),c={data:r.map(S=>({flowId:S.id,flowState:R,lastStepId:null,userId:i,foreignUserId:i,stepStates:{},shouldTrigger:!1}))},g=S=>fetch(S,e).then(k=>{if(k.ok)return k.json();throw new Error("Failed to fetch user flow states")}).catch(k=>(console.log(`Error fetching ${S}: ${k}. Will gracefully degrade and hide Frigade`),l(!0),c)),y=o&&r&&i?`${t}userFlowStates?foreignUserId=${encodeURIComponent(i)}${n?`&foreignUserGroupId=${encodeURIComponent(n)}`:""}`:null,{data:T,isLoading:C,mutate:h,error:A}=p?fa(y,g):ua(y,g,{revalidateOnFocus:!0,revalidateIfStale:!0,keepPreviousData:!0,revalidateOnMount:!1,errorRetryInterval:1e4,errorRetryCount:3,onError:()=>c,onLoadingSlow:()=>c}),F=T==null?void 0:T.data;ca(()=>{!s&&!C&&F&&m(!0)},[F,s,C]);function P(S){return U(this,null,function*(){if(F&&!p){let k=F.find(L=>L.flowId===S);k&&k.flowState!==R&&(k.flowState=R),yield h(Promise.resolve(xe(T,{data:F})),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}function v(S,k,L){return U(this,null,function*(){if(F){let O=F.find(N=>N.flowId===S);O&&(O.stepStates[k]=L,O.flowState=Ft),yield h(Promise.resolve(xe(T,{data:F})),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}function B(S,k,L){return U(this,null,function*(){if(F){let O=F.find(N=>N.flowId===S);O&&(O.lastStepId=k,O.stepStates[k]=L,O.flowState=Ft),yield h(xe(T,{data:F}),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}function f(S){return U(this,null,function*(){if(F){let k=F.find(L=>L.flowId===S);k&&k.flowState!==Me&&(k.flowState=Me,k.lastStepId=ga,Object.keys(k.stepStates).forEach(L=>{k.stepStates[L].actionType=ot,k.stepStates[L].createdAt=new Date().toISOString()}),yield h(xe(T,{data:F}),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1}),d(S))}})}function I(S,k,L){return U(this,null,function*(){if(F){let O=F.find(N=>N.flowId===S);O&&(O.stepStates[k]=L),yield h(Promise.resolve(xe(T,{data:F})),{optimisticData:xe(T,{data:F}),revalidate:!1,rollbackOnError:!1})}})}return{userFlowStatesData:F,isLoadingUserFlowStateData:!s,mutateUserFlowState:h,optimisticallyMarkFlowCompleted:P,optimisticallyMarkFlowNotStarted:f,optimisticallyMarkStepCompleted:v,optimisticallyMarkStepNotStarted:I,optimisticallyMarkStepStarted:B,error:A}}function po(){let{config:e,apiUrl:t}=Je(),{userFlowStatesData:o,mutateUserFlowState:i}=Ue(),{failedFlowResponses:n,setFailedFlowResponses:r,flowResponses:l,setFlowResponses:p}=ha(J),[d,s]=ci(new Set),[m,c]=ci(new Set),g=_t();function y(h){let A=JSON.stringify(h);if(d.has(A))return null;d.add(A),s(d),m.add(h),c(m);let F=l==null?void 0:l.find(P=>P.flowSlug===h.flowSlug&&P.stepId===h.stepId&&P.actionType===h.actionType&&P.createdAt===h.createdAt);return g(`${t}flowResponses`,j(b({},e),{method:"POST",body:A})).then(P=>{P.status!==200&&P.status!==201?(console.log("Failed to send flow response for step "+h.stepId+". Will retry again later."),r([...n,h])):F||p(v=>[...v!=null?v:[],h])})}function T(h){return U(this,null,function*(){h.foreignUserId&&(h.actionType===Ft||h.actionType===Me?yield y(h):h.actionType===R?yield y(h):h.actionType===Oo?yield y(h):h.actionType===De?yield y(h):h.actionType===Ao?yield y(h):h.actionType===ot&&(yield y(h)))})}function C(){let h=[];return o==null||o.forEach(A=>{if(A&&A.stepStates&&Object.keys(A.stepStates).length!==0)for(let F in A.stepStates){let P=A.stepStates[F];h.push({foreignUserId:A.foreignUserId,flowSlug:A.flowId,stepId:P.stepId,actionType:P.actionType,data:{},createdAt:new Date(P.createdAt),blocked:P.blocked,hidden:P.hidden})}}),[...h,...l]}return{addResponse:T,setFlowResponses:p,getFlowResponses:C}}import ba from"swr";var xa=/user.flow\(([^\)]+)\) == '?COMPLETED_FLOW'?/gm,mi=e=>{let t=xa.exec(e);if(t===null)return null;let o=null;return t.forEach((i,n)=>{let r=Ca(i,"'","");r.startsWith("flow_")&&(o=r)}),o},Ca=function(e,t,o){return e.replace(new RegExp(t,"g"),o)};function pr(e){try{return JSON.parse(e)}catch(t){return console.error("Failed to parse Frigade config.yml to JSON",t),null}}var dr=(s=>(s.CHECKLIST="CHECKLIST",s.FORM="FORM",s.TOUR="TOUR",s.SUPPORT="SUPPORT",s.CUSTOM="CUSTOM",s.BANNER="BANNER",s.EMBEDDED_TIP="EMBEDDED_TIP",s.NPS_SURVEY="NPS_SURVEY",s.ANNOUNCEMENT="ANNOUNCEMENT",s))(dr||{});function X(){let{config:e,apiUrl:t}=Je(),{flows:o,setFlows:i,userId:n,organizationId:r,publicApiKey:l,customVariables:p,setCustomVariables:d,hasActiveFullPageFlow:s,setHasActiveFullPageFlow:m,setFlowResponses:c,setShouldGracefullyDegrade:g,readonly:y}=ya(J),T={data:[]},{verifySDKInitiated:C}=Ht(),{addResponse:h,getFlowResponses:A}=po(),F=x=>fetch(x,e).then(u=>u.ok?u.json():(console.log(`Error fetching ${x} (${u.status}): ${u.statusText}. Will gracefully degrade and hide Frigade`),g(!0),T)).catch(u=>(console.log(`Error fetching ${x}: ${u}. Will gracefully degrade and hide Frigade`),g(!0),T)),{mutateUserFlowState:P,userFlowStatesData:v,isLoadingUserFlowStateData:B,optimisticallyMarkFlowCompleted:f,optimisticallyMarkFlowNotStarted:I,optimisticallyMarkStepCompleted:S,optimisticallyMarkStepNotStarted:k,optimisticallyMarkStepStarted:L}=Ue(),{data:O,error:N,isLoading:V}=ba(l?`${t}flows${y?"?readonly=true":""}`:null,F,{keepPreviousData:!0});Sa(()=>{if(N){console.error(N);return}O&&O.data&&i(O.data)},[O,N]);function W(x){if(V)return null;let u=o.find(w=>w.slug===x);return!u&&o.length>0&&!B&&!V?(console.log(`Flow with id ${x} not found`),null):(u==null?void 0:u.active)===!1&&!y?null:u}function Y(x){var z,ce;if(!W(x))return[];let u=W(x).data;return u?(u=Q(u),((ce=(z=pr(u))==null?void 0:z.data)!=null?ce:[]).map(ae=>{let wt=ie(ae);return j(b({handleSecondaryButtonClick:()=>{ae.skippable===!0&&re(x,ae.id,{skipped:!0})}},ae),{complete:Fe(x,ae.id)===De||wt>=1,currentlyActive:v==null?void 0:v.some(Tt=>Tt.flowId==x&&Tt.lastStepId===ae.id),blocked:ye(x,ae.id),hidden:$e(x,ae.id),handlePrimaryButtonClick:()=>{(!ae.completionCriteria&&(ae.autoMarkCompleted||ae.autoMarkCompleted===void 0)||ae.completionCriteria&&ae.autoMarkCompleted===!0)&&re(x,ae.id)},progress:wt})}).filter(ae=>ae.hidden!==!0)):[]}function Q(x){return x.replaceAll(/\${(.*?)}/g,(u,w)=>p[w]===void 0?"":String(p[w]).replace(/[\u00A0-\u9999<>\&]/g,function(z){return"&#"+z.charCodeAt(0)+";"}).replaceAll(/[\\]/g,"\\\\").replaceAll(/[\"]/g,'\\"').replaceAll(/[\/]/g,"\\/").replaceAll(/[\b]/g,"\\b").replaceAll(/[\f]/g,"\\f").replaceAll(/[\n]/g,"\\n").replaceAll(/[\r]/g,"\\r").replaceAll(/[\t]/g,"\\t"))}function de(x){var w;if(!W(x))return[];let u=W(x).data;return u?(u=Q(u),(w=JSON.parse(u))!=null?w:{}):[]}function H(x,u){d(w=>j(b({},w),{[x]:u}))}function le(x){!B&&!V&&x&&JSON.stringify(p)!=JSON.stringify(b(b({},p),x))&&Object.keys(x).forEach(u=>{H(u,x[u])})}let fe=kt((x,u,w)=>U(this,null,function*(){if(!C())return;let z={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:u,actionType:Oo,data:w!=null?w:{},createdAt:new Date,blocked:!1,hidden:!1};he(z)&&(yield L(x,u,z),h(z))}),[n,r,v]),Te=kt((x,u,w)=>U(this,null,function*(){if(!C())return;let z={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:u,actionType:ot,data:w!=null?w:{},createdAt:new Date,blocked:!1,hidden:!1};he(z)&&(yield k(x,u,z),h(z))}),[n,r,v]),re=kt((x,u,w)=>U(this,null,function*(){if(!C())return;let z={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:u,actionType:De,data:w!=null?w:{},createdAt:new Date,blocked:!1,hidden:!1};he(z)&&(yield S(x,u,z),h(z))}),[n,r,v]),Z=kt((x,u)=>U(this,null,function*(){if(!C()||Oe(x)===Me)return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:Me,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};yield I(x),he(w)&&h(w)}),[n,r,v]),q=kt((x,u)=>U(this,null,function*(){if(!C())return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:Ft,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};he(w)&&h(w)}),[n,r,v]),_=kt((x,u)=>U(this,null,function*(){if(!C())return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:R,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};he(w)&&(yield f(x),h(w))}),[n,r,v]),Le=kt((x,u)=>U(this,null,function*(){if(!C())return;let w={foreignUserId:n,foreignUserGroupId:r!=null?r:null,flowSlug:x,stepId:"unknown",actionType:Ao,data:u!=null?u:{},createdAt:new Date,blocked:!1,hidden:!1};he(w)&&(yield f(x),h(w))}),[n,r,v]);function he(x){var u;if(v===void 0)return!1;if(v){let w=v.find(z=>z.flowId===x.flowSlug);if(x.actionType===ot&&(!(w!=null&&w.stepStates[x.stepId])||w.stepStates[x.stepId].actionType===ot))return!1;if(w&&((u=w.stepStates[x.stepId])==null?void 0:u.actionType)===x.actionType){if(x.actionType===De&&(!x.data||JSON.stringify(x.data)===JSON.stringify({})))return!1;let z=Object.keys(w.stepStates).sort((ce,ae)=>{let wt=new Date(w.stepStates[ce].createdAt),Tt=new Date(w.stepStates[ae].createdAt);return wt.getTime()-Tt.getTime()});if(w.stepStates[z[z.length-1]].actionType===x.actionType&&x.stepId===z[z.length-1])return!1}if(w&&w.flowState===R&&x.actionType===R)return!1}return!0}function Fe(x,u){let w=$(x,u);return B?null:w?w.actionType:ot}function ye(x,u){let w=$(x,u);return w?w.blocked:!1}function $e(x,u){let w=$(x,u);return w?w.hidden:!1}function $(x,u){var z;if(B)return null;let w=v==null?void 0:v.find(ce=>ce.flowId===x);return!w||!w.stepStates[u]?null:(z=w.stepStates[u])!=null?z:null}function M(x){var w,z;if(B||!v)return null;if(Oe(x)===Me)return(w=Y(x)[0])!=null?w:null;let u=(z=v.find(ce=>ce.flowId===x))==null?void 0:z.lastStepId;return u?Y(x).find(ce=>ce.id===u):null}function D(x){var z;let u=M(x);if(!u)return 0;let w=(z=Y(x).findIndex(ce=>ce.id===u.id))!=null?z:0;return Fe(x,u.id)===De&&w<Y(x).length-1?w+1:w}function ie(x){if(!x.completionCriteria)return;let u=mi(x.completionCriteria);if(u===null)return;let w=bt(u),z=Ge(u);return z===0?void 0:w/z}function Oe(x){let u=v==null?void 0:v.find(w=>w.flowId===x);return u?u.flowState:null}function bt(x){let u=Y(x);return u.length===0?0:u.filter(z=>Fe(x,z.id)===De).length}function Ge(x){return Y(x).length}function mt(x){let u=o.find(w=>w.slug===x);return u?pr(u.data):null}function Ke(x){if(y)return!1;if(B)return!0;if(x!=null&&x.targetingLogic&&v){let u=v.find(w=>w.flowId===x.slug);if(u)return u.shouldTrigger===!1}return!!(x!=null&&x.targetingLogic&&n&&n.startsWith("guest_"))}function Dt(x){return!Ke(W(x))}function Ut(){n&&P()}function Wt(){return o}return{getAllFlows:Wt,getFlow:W,getFlowData:mt,isLoading:B||V,getStepStatus:Fe,getFlowSteps:Y,getCurrentStepIndex:D,markStepStarted:fe,markStepCompleted:re,markFlowNotStarted:Z,markFlowStarted:q,markFlowCompleted:_,markFlowAborted:Le,markStepNotStarted:Te,getFlowStatus:Oe,getNumberOfStepsCompleted:bt,getNumberOfSteps:Ge,targetingLogicShouldHideFlow:Ke,setCustomVariable:H,updateCustomVariables:le,customVariables:p,getStepOptionalProgress:ie,getFlowMetadata:de,isStepBlocked:ye,isStepHidden:$e,hasActiveFullPageFlow:s,setHasActiveFullPageFlow:m,isFlowAvailableToUser:Dt,refresh:Ut}}import{useCallback as cr,useContext as wa,useEffect as Ta}from"react";var Vt="guest_";function co(){let{userId:e,organizationId:t,setUserId:o,setUserProperties:i,shouldGracefullyDegrade:n}=wa(J),{config:r,apiUrl:l}=Je(),{mutateUserFlowState:p}=Ue(),d=_t(),{verifySDKInitiated:s}=Ht();function m(T){return`frigade-user-registered-${T}`}Ta(()=>{if(e&&!t){if(e.startsWith(Vt))return;let T=m(e);localStorage.getItem(T)||(d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify({foreignId:e})})),localStorage.setItem(T,"true"))}},[e,n,t]);let c=cr(T=>U(this,null,function*(){if(!s())return;let C={foreignId:e,properties:T};yield d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify(C)})),i(h=>b(b({},h),T)),p()}),[e,r,n,p]),g=cr((T,C)=>U(this,null,function*(){if(!s())return;let A={foreignId:e,events:[{event:T,properties:C}]};yield d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify(A)})),p()}),[e,r,p]),y=cr((T,C)=>U(this,null,function*(){if(s())if(C){let h=m(T);localStorage.setItem(h,"true"),o(T);let A={foreignId:T,properties:C};yield d(`${l}users`,j(b({},r),{method:"POST",body:JSON.stringify(A)})),i(F=>b(b({},F),C)),p()}else o(T)}),[r,n,p]);return{userId:e,setUserId:o,setUserIdWithProperties:y,addPropertiesToUser:c,trackEventForUser:g}}import{v4 as Qp}from"uuid";import Re,{useEffect as hn,useState as qp}from"react";import qe,{useEffect as gr,useState as Na}from"react";import $o from"styled-components";import Fa from"react";import ka from"styled-components";var ui="fr-",mo="cfr-";function a(e,t){let o=`${ui}${e}`;if(!t)return o;if(t.styleOverrides&&t.styleOverrides[e]){if(typeof t.styleOverrides[e]=="string")return o+" "+t.styleOverrides[e];if(typeof t.styleOverrides[e]=="object")return o+" "+mo+e}return o}function E(e){if(!e.className||e.className.indexOf(mo)!==-1)return"";let o=e.className.replace(/\s+/g," ").split(" ");return o.length==1&&o[0].startsWith(ui)?"":`:not(${o.map(i=>`.${i}`).join(", ")})`}function No(e){return e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase()}function ke(e){return e!=null&&e.styleOverrides?Object.keys(e.styleOverrides).map(t=>`${No(t)}: ${e.styleOverrides[t]};`).join(" "):""}function be(...e){return e.filter(Boolean).join(" ")}function uo(e){return e.charAt(0).toUpperCase()+e.slice(1)}var Pa=ka.div`
|
|
3
3
|
display: flex;
|
|
4
4
|
justify-content: center;
|
|
5
5
|
position: fixed;
|
|
@@ -684,7 +684,7 @@ var ia=Object.defineProperty,na=Object.defineProperties;var sa=Object.getOwnProp
|
|
|
684
684
|
display: flex;
|
|
685
685
|
align-self: center;
|
|
686
686
|
`;var fn=({stepData:e,setCanContinue:t,onSaveData:o,appearance:i})=>{let n=e.props,[r,l]=Or([]),[p,d]=Or(!1),[s,m]=Or(e.id);return Ar(()=>{r.length==0&&!p&&(d(!0),o({choice:[]}))},[p]),Ar(()=>{s!==e.id&&(m(e.id),l([]))},[e]),Ar(()=>{o({choice:r}),r.length>=n.minChoices?t(!0):t(!1)},[r]),st.createElement(sn,{className:a("selectListContainer",i)},st.createElement(ln,null,st.createElement(an,{className:a("selectListTitle",i)},e.title),st.createElement(pn,{appearance:i,className:a("selectListSubtitle",i)},e.subtitle)),n.options.map((c,g)=>{let y=r.includes(c.id);return st.createElement(dn,{key:`select-item-${g}`,onClick:()=>{if(r.includes(c.id)){l(r.filter(T=>T!==c.id));return}r.length<n.maxChoices?l([...r,c.id]):r.length==1&&n.maxChoices==1&&l([c.id])},hideBottomBorder:g===n.options.length-1,className:a("selectListSelectItem",i)},st.createElement(cn,{className:a("selectListItemImage",i)},c.imageUri&&st.createElement(mn,{src:c.imageUri,alt:`select-icon-${g}`}),st.createElement(un,{appearance:i,className:a("selectListSelectItemText",i)},c.title)),st.createElement(nt,{appearance:i,value:y,primaryColor:i.theme.colorPrimary}))}))};import We,{useEffect as gn,useState as Ko}from"react";var Hp=({children:e,id:t,shouldWrap:o=!1})=>We.createElement(We.Fragment,null,o?We.createElement("div",{key:t,style:{width:"100%",height:"100%",position:"absolute",top:0,left:0,zIndex:1,overflowY:"auto"}},e):e),qo=({appearance:e,steps:t,selectedStep:o,customStepTypes:i,customVariables:n,onButtonClick:r,onStepCompletion:l,flowId:p,type:d,hideOnFlowCompletion:s,onComplete:m,setVisible:c,setShowModal:g,onDismiss:y,showPagination:T=!1,customFormElements:C,allowBackNavigation:h,validationHandler:A,onFormDataChange:F,showFooter:P,prefillData:v,updateUrlOnPageChange:B,repeatable:f})=>{var $e;let S=b(b({},{linkCollection:rn,multiInput:Gi,callToAction:nn,selectList:fn}),i),{primaryCTAClickSideEffects:k,secondaryCTAClickSideEffects:L}=pe(),[O,N]=Ko(!1),[V,W]=Ko({}),[Y,Q]=Ko(!1),[de,H]=Ko(null),le=($e=t[o])!=null?$e:null,{markStepCompleted:fe,markStepStarted:Te,isLoading:re,updateCustomVariables:Z,markFlowCompleted:q}=X();gn(()=>{Z(n)},[n,re]),gn(()=>{F&&F(V,_(),t[o],o)},[V]);function _(){var M;return{data:(M=V[t[o].id])!=null?M:{},stepId:t[o].id,customVariables:n}}function Le($,M,D){let ie=o+1<t.length?t[o+1]:null;return l&&l($,D,ie,V,_()),r?r($,o,M,ie):!0}function he($,M){W(D=>{let ie={};return ie[$.id]=M,b(b({},D),ie)})}function Fe($){return $.selectedStep.imageUri?We.createElement(Qi,{image:$.selectedStep.imageUri,appearance:e,className:a("formContainerSidebarImage",e)}):null}let ye=P&&We.createElement(tn,{step:t[o],canContinue:O&&!Y,formType:d,selectedStep:o,appearance:e,onPrimaryClick:()=>U(void 0,null,function*(){if(Q(!0),A){let D=yield A(t[o],o,t[o+1],V,_());if(D!==!0){H(typeof D=="string"?D:null),Q(!1);return}else H(null)}let $=b({},_());yield fe(p,t[o].id,$),o+1<t.length&&!h&&(yield Te(p,t[o+1].id));let M=Le(t[o],"primary",o);if(o+1>=t.length&&(m&&m(),y&&y(),s&&M&&(c&&c(!1),g(!1)),yield q(p),f&&(yield Te(p,t[0].id),typeof window!="undefined"&&window.localStorage&&Object.keys(window.localStorage).forEach(ie=>{ie.startsWith(vr)&&window.localStorage.removeItem(ie)}))),k(t[o]),Q(!1),typeof window!="undefined"&&!h&&B&&o+1<t.length){let D=new URL(window.location.href);D.searchParams.set("p",t[o+1].id),window.history.pushState({},"",D.toString())}}),onSecondaryClick:()=>{Le(t[o],"secondary",o),L(t[o])},onBack:()=>U(void 0,null,function*(){o-1>=0&&(Q(!0),yield Te(p,t[o-1].id),Q(!1))}),steps:t,allowBackNavigation:h,errorMessage:de,isSaving:Y});return We.createElement(We.Fragment,null,We.createElement(Ji,{className:a("formContainer",e)},We.createElement(Hp,{id:o,shouldWrap:d==="large-modal"},We.createElement(Xi,{key:le.id,type:d,className:a("formContent",e)},t.map($=>{let M=S[$.type];return le.id!==$.id?null:typeof M!="function"?M:We.createElement(M,{key:$.id,stepData:$,canContinue:O,setCanContinue:N,onSaveData:D=>{he($,D)},appearance:e,customFormElements:C,flowId:p,prefillData:v})}),T&&We.createElement(on,{className:a("formPagination",e),appearance:e,stepCount:t.length,currentStep:o}),ye)),d=="large-modal"&&We.createElement(Fe,{selectedStep:t[o]})))};import Co from"react";import{createGlobalStyle as Vp}from"styled-components";var jp=Vp`
|
|
687
|
-
${e=>e.inlineStyles.map(([t,o])=>`.${mo}${t}.${mo}${t} { ${Object.entries(o).map(([i,n])=>typeof n=="object"?`${i} { ${Object.entries(n).map(([l,p])=>`${No(l)}: ${p};`).join(" ")} }`:`${No(i)}: ${n};`).join(" ")} }`).join(" ")}`;function ne({appearance:e}){if(!e||!e.styleOverrides)return Co.createElement(Co.Fragment,null);let t=Object.entries(e.styleOverrides).filter(([o,i])=>typeof i=="object");return t.length===0?Co.createElement(Co.Fragment,null):Co.createElement(jp,{inlineStyles:t})}import{useEffect as Gp,useState as Kp}from"react";function Ve(e){let[t,o]=Kp(!1),{markStepStarted:i,isLoading:n,getFlowStatus:r,getFlowSteps:l,getCurrentStepIndex:p}=X(),d=l(e);function s(){return U(this,null,function*(){!t&&!n&&r(e)===Me&&(o(!0),yield i(e,d[p(e)].id))})}return Gp(()=>{s()},[n,e]),{}}var xn=({flowId:e,customStepTypes:t={},type:o="inline",visible:i,setVisible:n,customVariables:r,customFormElements:l,onComplete:p,appearance:d,hideOnFlowCompletion:s=!0,onStepCompletion:m,onButtonClick:c,dismissible:g=!0,endFlowOnDismiss:y=!1,modalPosition:T="center",repeatable:C=!1,onDismiss:h,showPagination:A=!1,allowBackNavigation:F=!1,validationHandler:P,showFrigadeBranding:v=!1,onFormDataChange:B,showFooter:f=!0,prefillData:I={},updateUrlOnPageChange:S=!1})=>{let{getFlow:k,getFlowSteps:L,isLoading:O,targetingLogicShouldHideFlow:N,getFlowStatus:V,getCurrentStepIndex:W,markFlowCompleted:Y,markFlowNotStarted:Q,markStepStarted:de}=X(),H=W(e),{mergeAppearanceWithDefault:le}=ee(),[fe,Te]=qp(null),{setOpenFlowState:re,getOpenFlowState:Z,hasOpenModals:q}=Be();Ve(e);let _=L(e);d=le(d);let[Le,he]=i!==void 0&&n!==void 0?[i,n]:[Z(e,!0),$=>re(e,$)],Fe=typeof window!="undefined"?window.location.hash:null;if(hn(()=>{var $;if(_&&_.length>0&&F){let M=typeof window!="undefined"&&(($=window==null?void 0:window.location)!=null&&$.hash)?window.location.hash.replace("#",""):"";if(_&&(_==null?void 0:_.length)>0){let D=-1;if(M){let ie=M;D=_.findIndex(Oe=>Oe.id===ie),fe===M&&(D=-1)}D!==-1&&(Te(M),de(e,_[D].id))}}},[Fe]),hn(()=>{!O&&_&&_.length&&typeof window!="undefined"&&F&&(window.location.hash=_[H].id)},[O,H,_]),O)return null;let ye=k(e);if(!ye||N(ye)||!_||i!==void 0&&i===!1||V(e)===R&&s&&!C||(o=="modal"||o=="corner-modal")&&q(e))return null;let $e=()=>{he(!1),h&&h(),y===!0&&Y(e)};if(T=="center"&&o==="modal"||o==="large-modal"){let $={padding:"24px"};return o==="large-modal"?($.width="85%",$.height="90%",$.maxHeight="800px",$.minHeight="500px",$.padding="0"):$.width="400px",Re.createElement(Xe,{appearance:d,onClose:$e,visible:Le,style:$,dismissible:g,showFrigadeBranding:v},Re.createElement(ne,{appearance:d}),Re.createElement(qo,{appearance:d,steps:_,selectedStep:H,customStepTypes:t,customVariables:r,onButtonClick:c,onStepCompletion:m,flowId:e,type:o,hideOnFlowCompletion:s,onComplete:p,setVisible:n,setShowModal:he,onDismiss:h,showPagination:A,customFormElements:l,allowBackNavigation:F,validationHandler:P,onFormDataChange:B,showFooter:f,prefillData:I,updateUrlOnPageChange:S,repeatable:C}))}return o==="modal"&&T!=="center"?Re.createElement(Do,{appearance:d,onClose:$e,visible:Le,modalPosition:T},Re.createElement(ne,{appearance:d}),Re.createElement(qo,{appearance:d,steps:_,selectedStep:H,customStepTypes:t,customVariables:r,onButtonClick:c,onStepCompletion:m,flowId:e,type:o,hideOnFlowCompletion:s,onComplete:p,setVisible:n,setShowModal:he,onDismiss:h,showPagination:A,customFormElements:l,allowBackNavigation:F,validationHandler:P,onFormDataChange:B,showFooter:f,prefillData:I,updateUrlOnPageChange:S,repeatable:C})):Re.createElement(Re.Fragment,null,Re.createElement(ne,{appearance:d}),Re.createElement(qo,{appearance:d,steps:_,selectedStep:H,customStepTypes:t,customVariables:r,onButtonClick:c,onStepCompletion:m,flowId:e,type:o,hideOnFlowCompletion:s,onComplete:p,setVisible:n,setShowModal:he,onDismiss:h,showPagination:A,customFormElements:l,allowBackNavigation:F,validationHandler:P,onFormDataChange:B,showFooter:f,prefillData:I,updateUrlOnPageChange:S,repeatable:C}))},Cn=xn;import{useCallback as Nr,useContext as Yp,useEffect as Jp}from"react";function Ir(){let{organizationId:e,userId:t,setOrganizationId:o}=Yp(J),{mutateUserFlowState:i}=Ue(),{config:n,apiUrl:r}=Je(),l=_t(),{verifySDKInitiated:p}=Ht();function d(g,y){return`frigade-user-group-registered-${g}-${y}`}Jp(()=>{if(t&&e){if(t.startsWith(Vt))return;let g=d(t,e);localStorage.getItem(g)||(l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify({foreignUserId:t,foreignUserGroupId:e})})),localStorage.setItem(g,"true"))}},[t,e]);let s=Nr(g=>U(this,null,function*(){if(!p())return;if(!e||!t){console.error("Cannot add properties to organization: Organization ID and User ID must both be set.",{organizationIdInternal:e,userId:t});return}let y={foreignUserId:t,foreignUserGroupId:e,properties:g};yield l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify(y)})),i()}),[e,t,n,i]),m=Nr((g,y)=>U(this,null,function*(){if(!p())return;if(!e||!t){console.error("Cannot track event for organization: Organization ID and User ID must both be set.",{organizationIdInternal:e,userId:t});return}let C={foreignUserId:t,foreignUserGroupId:e,events:[{event:g,properties:y}]};yield l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify(C)})),i()}),[e,t,n,i]),c=Nr((g,y)=>U(this,null,function*(){if(p())if(y){let T=d(t,g);localStorage.setItem(T,"true"),o(g);let C={foreignUserId:t,foreignUserGroupId:g,properties:y};yield l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify(C)})),i()}else o(g)}),[t,n,i]);return{organizationId:e,setOrganizationId:o,setOrganizationIdWithProperties:c,addPropertiesToOrganization:s,trackEventForOrganization:m}}var yn="frigade-xFrigade_guestUserId",So="frigade-xFrigade_userId",Sn=({})=>{let{setFlowResponses:e}=po(),{userFlowStatesData:t,isLoadingUserFlowStateData:o,mutateUserFlowState:i}=Ue(),{userId:n,setUserId:r}=co(),[l,p]=yo(n),{getFlowStatus:d}=X(),{flows:s,userProperties:m,setIsNewGuestUser:c,flowResponses:g}=Xp(J),[y,T]=yo([]),[C,h]=yo([]),{organizationId:A}=Ir(),[F,P]=yo(A),[v,B]=yo(!1);Xt(()=>{if(!o&&t)for(let k=0;k<t.length;k++){let L=t[k],O=s.find(N=>N.slug===(L==null?void 0:L.flowId));if(O&&L&&L.shouldTrigger===!0&&O.type=="FORM"&&O.triggerType==="AUTOMATIC"&&!C.includes(O.slug)){setTimeout(()=>{f(L.flowId)},500);break}}},[o,t]),Xt(()=>{g.length>0&&i()},[g]),Xt(()=>{v||(B(!0),i())},[o,B]);function f(k){let L=s.find(O=>O.slug===k);L&&L.triggerType==="AUTOMATIC"&&!C.includes(L.slug)&&(h([...C,L.slug]),T([L]))}function I(){if(!n){let k=localStorage.getItem(So);if(k){r(k);return}let L=localStorage.getItem(yn);if(L){r(L);return}c(!0);let O=Vt+Qp();try{localStorage.setItem(yn,O)}catch(N){console.log("Failed to save guest user id locally: Local storage unavailable",N)}r(N=>N||O)}}Xt(()=>{try{if(s){let k=[];s.forEach(L=>{if(L.data){let O=L.data.match(/"imageUri":"(.*?)"/g);O&&O.forEach(N=>{let V=N.replace('"imageUri":"',"").replace('"',"");if(k.includes(V))return;let W=new Image;W.src=V,k.push(V)})}})}}catch(k){}},[s]),Xt(()=>{if(n!==l&&(e([]),i()),p(n),n&&!n.startsWith(Vt))try{localStorage.setItem(So,n)}catch(k){console.log("Failed to save user id locally: Local storage available",k)}n===null&&setTimeout(()=>{n===null&&I()},50)},[n,s,m]),Xt(()=>{A!=F&&(P(A),e([]),i())},[A,F,P]);function S(){return Bt.createElement(Bt.Fragment,null,y.map(k=>d(k.slug)!==Me?null:Bt.createElement("span",{key:k.slug},Bt.createElement(Cn,{flowId:k.slug,type:"modal",modalPosition:"center",endFlowOnDismiss:!0}))))}return Bt.createElement(Bt.Fragment,null,Bt.createElement(S,null))};import{ErrorBoundary as Td}from"react-error-boundary";var bn={colorPrimary:"colors.primary.background",colorText:"colors.neutral.foreground",colorBackground:"colors.neutral.background",colorBackgroundSecondary:"colors.secondary.background",colorTextOnPrimaryBackground:"colors.primary.foreground",colorTextSecondary:"colors.secondary.foreground",colorTextDisabled:"colors.gray700",colorBorder:"colors.gray800",colorTextError:"colors.negative.foreground",borderRadius:"radii.lg"};function Zp(e){if(!e)return;let t={};return Object.entries(e).forEach(([o,i])=>{if(bn[o]){let n=bn[o].split("."),r=t;n.forEach((l,p)=>{r[l]||(r[l]=p===n.length-1?i:{}),r=r[l]})}}),t}function Rp(e){if(!e)return;let t=xe({},e),o={};return Object.keys(t).forEach(i=>{let n=`.fr-${i}`;o[n]=t[i]}),o}function wn(e){let{theme:t,styleOverrides:o}=e,i=Zp(t),n=Rp(o);return{overrides:i,css:n}}import ud from"styled-components";import{compose as fd,variant as Fn}from"styled-system";import Tn from"react";import ed,{ThemeProvider as td,useTheme as od}from"styled-components";import{border as rd,color as id,compose as nd,get as sd,shadow as ld,space as ad,system as pd,typography as dd}from"styled-system";var cd={width:{property:"width",scale:"sizes",transform:(e,t)=>sd(t,e,!(typeof e=="number"&&!isNaN(e))||e>1?e:e*100+"%")},height:{property:"height",scale:"sizes"},minWidth:{property:"minWidth",scale:"sizes"},minHeight:{property:"minHeight",scale:"sizes"},maxWidth:{property:"maxWidth",scale:"sizes"},maxHeight:{property:"maxHeight",scale:"sizes"},overflow:!0,overflowX:!0,overflowY:!0,display:!0,verticalAlign:!0},md=ed("div")(({css:e})=>e,nd(rd,id,ld,ad,dd,pd(cd))),bo=n=>{var r=n,{as:e,children:t,overrides:o}=r,i=Ne(r,["as","children","overrides"]);let l=od(),p={border:"none",boxSizing:"border-box",m:0,p:0},d=()=>Tn.createElement(md,b(b({as:e},p),i),t);if(o!==void 0){let s=xe(l,o);return Tn.createElement(td,{theme:s},d())}return d()};var wo={Primary:{backgroundColor:"primary.background",color:"primary.foreground","&:hover":{backgroundColor:"blue400"}},Secondary:{backgroundColor:"white",border:"1px solid",borderColor:"gray800",color:"neutral.foreground","&:hover":{backgroundColor:"blue900"}},Link:{backgroundColor:"transparent",color:"primary.inverted"},Plain:{backgroundColor:"transparent",color:"neutral.foreground"}},gd={sm:{paddingX:4,paddingY:1},md:{paddingX:6,paddingY:2}},kn=ud(bo)(()=>({whiteSpace:"nowrap"}),fd(Fn({scale:"components.Button",variants:"components.Button"}),Fn({prop:"size",variants:gd})));import hd from"styled-components";import{variant as xd,system as Cd}from"styled-system";var Yo={Display1:{fontSize:"5xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"4xl"},Display2:{fontSize:"4xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"3xl"},H1:{fontSize:"3xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"2xl"},H2:{fontSize:"2xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"xl"},H3:{fontSize:"xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"lg"},H4:{fontSize:"lg",fontWeight:"bold",letterSpacing:"md",lineHeight:"md"},Body1:{fontSize:"md",fontWeight:"regular",letterSpacing:"md",lineHeight:"md"},Body2:{fontSize:"sm",fontWeight:"regular",letterSpacing:"md",lineHeight:"md"},Caption:{fontSize:"xs",fontWeight:"regular",letterSpacing:"md",lineHeight:"sm"}};var Pn=hd(bo)(xd({scale:"components.Text",variants:"components.Text"}),Cd({fontWeight:{property:"fontWeight",scale:"fontWeights"}}));var vn=4,Bn="px",yd=20,Sd=Object.fromEntries(Array.from(Array(yd+1),(e,t)=>t===0?[.5,`${.5*vn}${Bn}`]:[t,`${t*vn}${Bn}`])),Qt={black:"#000000",gray100:"#14161A",gray200:"#181B20",gray300:"#1F2329",gray400:"#2E343D",gray500:"#4C5766",gray600:"#5A6472",gray700:"#C5CBD3",gray800:"#E2E5E9",gray900:"#F1F2F4",white:"#ffffff",blue400:"#015AC6",blue500:"#0171F8",blue800:"#DBECFF",blue900:"#F5F9FF",green400:"#009E37",green500:"#00D149",green800:"#DBFFE8",transparent:"#FFFFFF00",red500:"#c00000"},Lr={colors:j(b({},Qt),{neutral:{foreground:Qt.gray300},primary:{background:Qt.blue500,foreground:Qt.white,inverted:Qt.blue500},negative:{foreground:Qt.red500}}),fonts:{default:"TT Interphases Pro, sans-serif"},fontSizes:{xs:"12px",sm:"14px",md:"16px",lg:"18px",xl:"20px","2xl":"24px","3xl":"30px","4xl":"36px","5xl":"48px"},fontWeights:{regular:400,semibold:500,bold:700},letterSpacings:{md:"0.02em"},lineHeights:{xs:"18px",sm:"22px",md:"24px",lg:"26px",xl:"30px","2xl":"38px","3xl":"46px","4xl":"60px"},radii:{md:"8px",lg:"20px",round:"50%"},shadows:{md:"0px 4px 20px rgba(0, 0, 0, 0.06)"},space:Sd,components:{Button:wo,Text:Yo}};var En="https://api.frigade.com",J=bd({publicApiKey:"",setUserId:()=>{},flows:[],setFlows:()=>{},failedFlowResponses:[],setFailedFlowResponses:()=>{},flowResponses:[],setFlowResponses:()=>{},userProperties:{},setUserProperties:()=>{},openFlowStates:{},setOpenFlowStates:()=>{},completedFlowsToKeepOpenDuringSession:[],setCompletedFlowsToKeepOpenDuringSession:()=>{},customVariables:{},setCustomVariables:()=>{},isNewGuestUser:!1,setIsNewGuestUser:()=>{},hasActiveFullPageFlow:!1,setHasActiveFullPageFlow:()=>{},organizationId:"",setOrganizationId:()=>{},navigate:()=>{},defaultAppearance:it,shouldGracefullyDegrade:!1,setShouldGracefullyDegrade:()=>{},apiUrl:En,readonly:!1,debug:!1});function Fd(){Object.keys(localStorage).forEach(e=>{e.startsWith("frigade-")&&localStorage.removeItem(e)})}var kd=({publicApiKey:e,userId:t,organizationId:o,config:i,children:n})=>{var H,le,fe,Te,re;let[r,l]=je(t||null),[p,d]=je(o||null),[s,m]=je([]),[c,g]=je([]),[y,T]=je([]),[C,h]=je({}),[A,F]=je({}),[P,v]=je([]),[B,f]=je({}),[I,S]=je(!1),[k,L]=je(!1),[O,N]=je(!Y(e)),V=(Z,q)=>{if(q==="_blank"){window.open(Z,"_blank");return}setTimeout(()=>{window.location.href=Z},50)},W={theme:b(b({},it.theme),(le=(H=i==null?void 0:i.defaultAppearance)==null?void 0:H.theme)!=null?le:{}),styleOverrides:b(b({},it.styleOverrides),(Te=(fe=i==null?void 0:i.defaultAppearance)==null?void 0:fe.styleOverrides)!=null?Te:{})};function Y(Z){return!!(Z&&Z.length>10&&Z.substring(0,10)==="api_public")}Jo(()=>{t&&l(t)},[t]),Jo(()=>{r&&typeof window!="undefined"&&window.localStorage&&window.localStorage.getItem(So)&&window.localStorage.getItem(So)!==r&&Fd()},[r]),Jo(()=>{o&&d(o)},[o]),Jo(()=>{if(Y(e))N(!1);else{console.error("Frigade SDK failed to initialize. API key provided is either missing or valid."),N(!0);return}},[e,N]);let Q={publicApiKey:e,userId:r,setUserId:l,setFlows:m,flows:s,failedFlowResponses:c,setFailedFlowResponses:g,flowResponses:y,setFlowResponses:T,userProperties:C,setUserProperties:h,openFlowStates:A,setOpenFlowStates:F,completedFlowsToKeepOpenDuringSession:P,setCompletedFlowsToKeepOpenDuringSession:v,customVariables:B,setCustomVariables:f,isNewGuestUser:I,setIsNewGuestUser:S,hasActiveFullPageFlow:k,setHasActiveFullPageFlow:L,organizationId:p,setOrganizationId:d,navigate:i&&i.navigate?i.navigate:V,defaultAppearance:W,shouldGracefullyDegrade:O,setShouldGracefullyDegrade:N,apiUrl:i&&i.apiUrl?i.apiUrl:En,readonly:i&&i.readonly?i.readonly:!1,debug:i&&i.debug?i.debug:!1};if(O)return Et.createElement(J.Provider,{value:Q},n);let{overrides:de}=wn(W);return Et.createElement(Td,{fallback:Et.createElement(Et.Fragment,null,n)},Et.createElement(J.Provider,{value:Q},Et.createElement(wd,{theme:xe(W.theme,Lr,de!=null?de:{},(re=i==null?void 0:i.theme)!=null?re:{})},n,Et.createElement(Sn,null))))};import fc from"react";import Ce,{useEffect as Vr,useState as rl}from"react";import Ye,{useState as Vd}from"react";import Nt from"styled-components";import Zo from"react";import At from"react";import On from"styled-components";var An=On.span`
|
|
687
|
+
${e=>e.inlineStyles.map(([t,o])=>`.${mo}${t}.${mo}${t} { ${Object.entries(o).map(([i,n])=>typeof n=="object"?`${i} { ${Object.entries(n).map(([l,p])=>`${No(l)}: ${p};`).join(" ")} }`:`${No(i)}: ${n};`).join(" ")} }`).join(" ")}`;function ne({appearance:e}){if(!e||!e.styleOverrides)return Co.createElement(Co.Fragment,null);let t=Object.entries(e.styleOverrides).filter(([o,i])=>typeof i=="object");return t.length===0?Co.createElement(Co.Fragment,null):Co.createElement(jp,{inlineStyles:t})}import{useEffect as Gp,useState as Kp}from"react";function Ve(e){let[t,o]=Kp(!1),{markStepStarted:i,isLoading:n,getFlowStatus:r,getFlowSteps:l,getCurrentStepIndex:p,targetingLogicShouldHideFlow:d,getFlow:s}=X(),m=l(e);function c(){return U(this,null,function*(){!t&&!n&&r(e)===Me&&d(s(e))===!1&&(o(!0),yield i(e,m[p(e)].id))})}return Gp(()=>{c()},[n,e]),{}}var xn=({flowId:e,customStepTypes:t={},type:o="inline",visible:i,setVisible:n,customVariables:r,customFormElements:l,onComplete:p,appearance:d,hideOnFlowCompletion:s=!0,onStepCompletion:m,onButtonClick:c,dismissible:g=!0,endFlowOnDismiss:y=!1,modalPosition:T="center",repeatable:C=!1,onDismiss:h,showPagination:A=!1,allowBackNavigation:F=!1,validationHandler:P,showFrigadeBranding:v=!1,onFormDataChange:B,showFooter:f=!0,prefillData:I={},updateUrlOnPageChange:S=!1})=>{let{getFlow:k,getFlowSteps:L,isLoading:O,targetingLogicShouldHideFlow:N,getFlowStatus:V,getCurrentStepIndex:W,markFlowCompleted:Y,markFlowNotStarted:Q,markStepStarted:de}=X(),H=W(e),{mergeAppearanceWithDefault:le}=ee(),[fe,Te]=qp(null),{setOpenFlowState:re,getOpenFlowState:Z,hasOpenModals:q}=Be();Ve(e);let _=L(e);d=le(d);let[Le,he]=i!==void 0&&n!==void 0?[i,n]:[Z(e,!0),$=>re(e,$)],Fe=typeof window!="undefined"?window.location.hash:null;if(hn(()=>{var $;if(_&&_.length>0&&F){let M=typeof window!="undefined"&&(($=window==null?void 0:window.location)!=null&&$.hash)?window.location.hash.replace("#",""):"";if(_&&(_==null?void 0:_.length)>0){let D=-1;if(M){let ie=M;D=_.findIndex(Oe=>Oe.id===ie),fe===M&&(D=-1)}D!==-1&&(Te(M),de(e,_[D].id))}}},[Fe]),hn(()=>{!O&&_&&_.length&&typeof window!="undefined"&&F&&(window.location.hash=_[H].id)},[O,H,_]),O)return null;let ye=k(e);if(!ye||N(ye)||!_||i!==void 0&&i===!1||V(e)===R&&s&&!C||(o=="modal"||o=="corner-modal")&&q(e))return null;let $e=()=>{he(!1),h&&h(),y===!0&&Y(e)};if(T=="center"&&o==="modal"||o==="large-modal"){let $={padding:"24px"};return o==="large-modal"?($.width="85%",$.height="90%",$.maxHeight="800px",$.minHeight="500px",$.padding="0"):$.width="400px",Re.createElement(Xe,{appearance:d,onClose:$e,visible:Le,style:$,dismissible:g,showFrigadeBranding:v},Re.createElement(ne,{appearance:d}),Re.createElement(qo,{appearance:d,steps:_,selectedStep:H,customStepTypes:t,customVariables:r,onButtonClick:c,onStepCompletion:m,flowId:e,type:o,hideOnFlowCompletion:s,onComplete:p,setVisible:n,setShowModal:he,onDismiss:h,showPagination:A,customFormElements:l,allowBackNavigation:F,validationHandler:P,onFormDataChange:B,showFooter:f,prefillData:I,updateUrlOnPageChange:S,repeatable:C}))}return o==="modal"&&T!=="center"?Re.createElement(Do,{appearance:d,onClose:$e,visible:Le,modalPosition:T},Re.createElement(ne,{appearance:d}),Re.createElement(qo,{appearance:d,steps:_,selectedStep:H,customStepTypes:t,customVariables:r,onButtonClick:c,onStepCompletion:m,flowId:e,type:o,hideOnFlowCompletion:s,onComplete:p,setVisible:n,setShowModal:he,onDismiss:h,showPagination:A,customFormElements:l,allowBackNavigation:F,validationHandler:P,onFormDataChange:B,showFooter:f,prefillData:I,updateUrlOnPageChange:S,repeatable:C})):Re.createElement(Re.Fragment,null,Re.createElement(ne,{appearance:d}),Re.createElement(qo,{appearance:d,steps:_,selectedStep:H,customStepTypes:t,customVariables:r,onButtonClick:c,onStepCompletion:m,flowId:e,type:o,hideOnFlowCompletion:s,onComplete:p,setVisible:n,setShowModal:he,onDismiss:h,showPagination:A,customFormElements:l,allowBackNavigation:F,validationHandler:P,onFormDataChange:B,showFooter:f,prefillData:I,updateUrlOnPageChange:S,repeatable:C}))},Cn=xn;import{useCallback as Nr,useContext as Yp,useEffect as Jp}from"react";function Ir(){let{organizationId:e,userId:t,setOrganizationId:o}=Yp(J),{mutateUserFlowState:i}=Ue(),{config:n,apiUrl:r}=Je(),l=_t(),{verifySDKInitiated:p}=Ht();function d(g,y){return`frigade-user-group-registered-${g}-${y}`}Jp(()=>{if(t&&e){if(t.startsWith(Vt))return;let g=d(t,e);localStorage.getItem(g)||(l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify({foreignUserId:t,foreignUserGroupId:e})})),localStorage.setItem(g,"true"))}},[t,e]);let s=Nr(g=>U(this,null,function*(){if(!p())return;if(!e||!t){console.error("Cannot add properties to organization: Organization ID and User ID must both be set.",{organizationIdInternal:e,userId:t});return}let y={foreignUserId:t,foreignUserGroupId:e,properties:g};yield l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify(y)})),i()}),[e,t,n,i]),m=Nr((g,y)=>U(this,null,function*(){if(!p())return;if(!e||!t){console.error("Cannot track event for organization: Organization ID and User ID must both be set.",{organizationIdInternal:e,userId:t});return}let C={foreignUserId:t,foreignUserGroupId:e,events:[{event:g,properties:y}]};yield l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify(C)})),i()}),[e,t,n,i]),c=Nr((g,y)=>U(this,null,function*(){if(p())if(y){let T=d(t,g);localStorage.setItem(T,"true"),o(g);let C={foreignUserId:t,foreignUserGroupId:g,properties:y};yield l(`${r}userGroups`,j(b({},n),{method:"POST",body:JSON.stringify(C)})),i()}else o(g)}),[t,n,i]);return{organizationId:e,setOrganizationId:o,setOrganizationIdWithProperties:c,addPropertiesToOrganization:s,trackEventForOrganization:m}}var yn="frigade-xFrigade_guestUserId",So="frigade-xFrigade_userId",Sn=({})=>{let{setFlowResponses:e}=po(),{userFlowStatesData:t,isLoadingUserFlowStateData:o,mutateUserFlowState:i}=Ue(),{userId:n,setUserId:r}=co(),[l,p]=yo(n),{getFlowStatus:d}=X(),{flows:s,userProperties:m,setIsNewGuestUser:c,flowResponses:g}=Xp(J),[y,T]=yo([]),[C,h]=yo([]),{organizationId:A}=Ir(),[F,P]=yo(A),[v,B]=yo(!1);Xt(()=>{if(!o&&t)for(let k=0;k<t.length;k++){let L=t[k],O=s.find(N=>N.slug===(L==null?void 0:L.flowId));if(O&&L&&L.shouldTrigger===!0&&O.type=="FORM"&&O.triggerType==="AUTOMATIC"&&!C.includes(O.slug)){setTimeout(()=>{f(L.flowId)},500);break}}},[o,t]),Xt(()=>{g.length>0&&i()},[g]),Xt(()=>{v||(B(!0),i())},[o,B]);function f(k){let L=s.find(O=>O.slug===k);L&&L.triggerType==="AUTOMATIC"&&!C.includes(L.slug)&&(h([...C,L.slug]),T([L]))}function I(){if(!n){let k=localStorage.getItem(So);if(k){r(k);return}let L=localStorage.getItem(yn);if(L){r(L);return}c(!0);let O=Vt+Qp();try{localStorage.setItem(yn,O)}catch(N){console.log("Failed to save guest user id locally: Local storage unavailable",N)}r(N=>N||O)}}Xt(()=>{try{if(s){let k=[];s.forEach(L=>{if(L.data){let O=L.data.match(/"imageUri":"(.*?)"/g);O&&O.forEach(N=>{let V=N.replace('"imageUri":"',"").replace('"',"");if(k.includes(V))return;let W=new Image;W.src=V,k.push(V)})}})}}catch(k){}},[s]),Xt(()=>{if(n!==l&&(e([]),i()),p(n),n&&!n.startsWith(Vt))try{localStorage.setItem(So,n)}catch(k){console.log("Failed to save user id locally: Local storage available",k)}n===null&&setTimeout(()=>{n===null&&I()},50)},[n,s,m]),Xt(()=>{A!=F&&(P(A),e([]),i())},[A,F,P]);function S(){return Bt.createElement(Bt.Fragment,null,y.map(k=>d(k.slug)!==Me?null:Bt.createElement("span",{key:k.slug},Bt.createElement(Cn,{flowId:k.slug,type:"modal",modalPosition:"center",endFlowOnDismiss:!0}))))}return Bt.createElement(Bt.Fragment,null,Bt.createElement(S,null))};import{ErrorBoundary as Td}from"react-error-boundary";var bn={colorPrimary:"colors.primary.background",colorText:"colors.neutral.foreground",colorBackground:"colors.neutral.background",colorBackgroundSecondary:"colors.secondary.background",colorTextOnPrimaryBackground:"colors.primary.foreground",colorTextSecondary:"colors.secondary.foreground",colorTextDisabled:"colors.gray700",colorBorder:"colors.gray800",colorTextError:"colors.negative.foreground",borderRadius:"radii.lg"};function Zp(e){if(!e)return;let t={};return Object.entries(e).forEach(([o,i])=>{if(bn[o]){let n=bn[o].split("."),r=t;n.forEach((l,p)=>{r[l]||(r[l]=p===n.length-1?i:{}),r=r[l]})}}),t}function Rp(e){if(!e)return;let t=xe({},e),o={};return Object.keys(t).forEach(i=>{let n=`.fr-${i}`;o[n]=t[i]}),o}function wn(e){let{theme:t,styleOverrides:o}=e,i=Zp(t),n=Rp(o);return{overrides:i,css:n}}import ud from"styled-components";import{compose as fd,variant as Fn}from"styled-system";import Tn from"react";import ed,{ThemeProvider as td,useTheme as od}from"styled-components";import{border as rd,color as id,compose as nd,get as sd,shadow as ld,space as ad,system as pd,typography as dd}from"styled-system";var cd={width:{property:"width",scale:"sizes",transform:(e,t)=>sd(t,e,!(typeof e=="number"&&!isNaN(e))||e>1?e:e*100+"%")},height:{property:"height",scale:"sizes"},minWidth:{property:"minWidth",scale:"sizes"},minHeight:{property:"minHeight",scale:"sizes"},maxWidth:{property:"maxWidth",scale:"sizes"},maxHeight:{property:"maxHeight",scale:"sizes"},overflow:!0,overflowX:!0,overflowY:!0,display:!0,verticalAlign:!0},md=ed("div")(({css:e})=>e,nd(rd,id,ld,ad,dd,pd(cd))),bo=n=>{var r=n,{as:e,children:t,overrides:o}=r,i=Ne(r,["as","children","overrides"]);let l=od(),p={border:"none",boxSizing:"border-box",m:0,p:0},d=()=>Tn.createElement(md,b(b({as:e},p),i),t);if(o!==void 0){let s=xe(l,o);return Tn.createElement(td,{theme:s},d())}return d()};var wo={Primary:{backgroundColor:"primary.background",color:"primary.foreground","&:hover":{backgroundColor:"blue400"}},Secondary:{backgroundColor:"white",border:"1px solid",borderColor:"gray800",color:"neutral.foreground","&:hover":{backgroundColor:"blue900"}},Link:{backgroundColor:"transparent",color:"primary.inverted"},Plain:{backgroundColor:"transparent",color:"neutral.foreground"}},gd={sm:{paddingX:4,paddingY:1},md:{paddingX:6,paddingY:2}},kn=ud(bo)(()=>({whiteSpace:"nowrap"}),fd(Fn({scale:"components.Button",variants:"components.Button"}),Fn({prop:"size",variants:gd})));import hd from"styled-components";import{variant as xd,system as Cd}from"styled-system";var Yo={Display1:{fontSize:"5xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"4xl"},Display2:{fontSize:"4xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"3xl"},H1:{fontSize:"3xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"2xl"},H2:{fontSize:"2xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"xl"},H3:{fontSize:"xl",fontWeight:"bold",letterSpacing:"md",lineHeight:"lg"},H4:{fontSize:"lg",fontWeight:"bold",letterSpacing:"md",lineHeight:"md"},Body1:{fontSize:"md",fontWeight:"regular",letterSpacing:"md",lineHeight:"md"},Body2:{fontSize:"sm",fontWeight:"regular",letterSpacing:"md",lineHeight:"md"},Caption:{fontSize:"xs",fontWeight:"regular",letterSpacing:"md",lineHeight:"sm"}};var Pn=hd(bo)(xd({scale:"components.Text",variants:"components.Text"}),Cd({fontWeight:{property:"fontWeight",scale:"fontWeights"}}));var vn=4,Bn="px",yd=20,Sd=Object.fromEntries(Array.from(Array(yd+1),(e,t)=>t===0?[.5,`${.5*vn}${Bn}`]:[t,`${t*vn}${Bn}`])),Qt={black:"#000000",gray100:"#14161A",gray200:"#181B20",gray300:"#1F2329",gray400:"#2E343D",gray500:"#4C5766",gray600:"#5A6472",gray700:"#C5CBD3",gray800:"#E2E5E9",gray900:"#F1F2F4",white:"#ffffff",blue400:"#015AC6",blue500:"#0171F8",blue800:"#DBECFF",blue900:"#F5F9FF",green400:"#009E37",green500:"#00D149",green800:"#DBFFE8",transparent:"#FFFFFF00",red500:"#c00000"},Lr={colors:j(b({},Qt),{neutral:{foreground:Qt.gray300},primary:{background:Qt.blue500,foreground:Qt.white,inverted:Qt.blue500},negative:{foreground:Qt.red500}}),fonts:{default:"TT Interphases Pro, sans-serif"},fontSizes:{xs:"12px",sm:"14px",md:"16px",lg:"18px",xl:"20px","2xl":"24px","3xl":"30px","4xl":"36px","5xl":"48px"},fontWeights:{regular:400,semibold:500,bold:700},letterSpacings:{md:"0.02em"},lineHeights:{xs:"18px",sm:"22px",md:"24px",lg:"26px",xl:"30px","2xl":"38px","3xl":"46px","4xl":"60px"},radii:{md:"8px",lg:"20px",round:"50%"},shadows:{md:"0px 4px 20px rgba(0, 0, 0, 0.06)"},space:Sd,components:{Button:wo,Text:Yo}};var En="https://api.frigade.com",J=bd({publicApiKey:"",setUserId:()=>{},flows:[],setFlows:()=>{},failedFlowResponses:[],setFailedFlowResponses:()=>{},flowResponses:[],setFlowResponses:()=>{},userProperties:{},setUserProperties:()=>{},openFlowStates:{},setOpenFlowStates:()=>{},completedFlowsToKeepOpenDuringSession:[],setCompletedFlowsToKeepOpenDuringSession:()=>{},customVariables:{},setCustomVariables:()=>{},isNewGuestUser:!1,setIsNewGuestUser:()=>{},hasActiveFullPageFlow:!1,setHasActiveFullPageFlow:()=>{},organizationId:"",setOrganizationId:()=>{},navigate:()=>{},defaultAppearance:it,shouldGracefullyDegrade:!1,setShouldGracefullyDegrade:()=>{},apiUrl:En,readonly:!1,debug:!1});function Fd(){Object.keys(localStorage).forEach(e=>{e.startsWith("frigade-")&&localStorage.removeItem(e)})}var kd=({publicApiKey:e,userId:t,organizationId:o,config:i,children:n})=>{var H,le,fe,Te,re;let[r,l]=je(t||null),[p,d]=je(o||null),[s,m]=je([]),[c,g]=je([]),[y,T]=je([]),[C,h]=je({}),[A,F]=je({}),[P,v]=je([]),[B,f]=je({}),[I,S]=je(!1),[k,L]=je(!1),[O,N]=je(!Y(e)),V=(Z,q)=>{if(q==="_blank"){window.open(Z,"_blank");return}setTimeout(()=>{window.location.href=Z},50)},W={theme:b(b({},it.theme),(le=(H=i==null?void 0:i.defaultAppearance)==null?void 0:H.theme)!=null?le:{}),styleOverrides:b(b({},it.styleOverrides),(Te=(fe=i==null?void 0:i.defaultAppearance)==null?void 0:fe.styleOverrides)!=null?Te:{})};function Y(Z){return!!(Z&&Z.length>10&&Z.substring(0,10)==="api_public")}Jo(()=>{t&&l(t)},[t]),Jo(()=>{r&&typeof window!="undefined"&&window.localStorage&&window.localStorage.getItem(So)&&window.localStorage.getItem(So)!==r&&Fd()},[r]),Jo(()=>{o&&d(o)},[o]),Jo(()=>{if(Y(e))N(!1);else{console.error("Frigade SDK failed to initialize. API key provided is either missing or valid."),N(!0);return}},[e,N]);let Q={publicApiKey:e,userId:r,setUserId:l,setFlows:m,flows:s,failedFlowResponses:c,setFailedFlowResponses:g,flowResponses:y,setFlowResponses:T,userProperties:C,setUserProperties:h,openFlowStates:A,setOpenFlowStates:F,completedFlowsToKeepOpenDuringSession:P,setCompletedFlowsToKeepOpenDuringSession:v,customVariables:B,setCustomVariables:f,isNewGuestUser:I,setIsNewGuestUser:S,hasActiveFullPageFlow:k,setHasActiveFullPageFlow:L,organizationId:p,setOrganizationId:d,navigate:i&&i.navigate?i.navigate:V,defaultAppearance:W,shouldGracefullyDegrade:O,setShouldGracefullyDegrade:N,apiUrl:i&&i.apiUrl?i.apiUrl:En,readonly:i&&i.readonly?i.readonly:!1,debug:i&&i.debug?i.debug:!1};if(O)return Et.createElement(J.Provider,{value:Q},n);let{overrides:de}=wn(W);return Et.createElement(Td,{fallback:Et.createElement(Et.Fragment,null,n)},Et.createElement(J.Provider,{value:Q},Et.createElement(wd,{theme:xe(W.theme,Lr,de!=null?de:{},(re=i==null?void 0:i.theme)!=null?re:{})},n,Et.createElement(Sn,null))))};import fc from"react";import Ce,{useEffect as Vr,useState as rl}from"react";import Ye,{useState as Vd}from"react";import Nt from"styled-components";import Zo from"react";import At from"react";import On from"styled-components";var An=On.span`
|
|
688
688
|
font-weight: 600;
|
|
689
689
|
font-size: 14px;
|
|
690
690
|
font-style: normal;
|