@onefootprint/footprint-js
Version:
12 lines (8 loc) • 25.6 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var lt=Object.defineProperty,ct=Object.defineProperties;var mt=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var xe=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var be=(e,t,o)=>t in e?lt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))xe.call(t,o)&&be(e,o,t[o]);if(M)for(var o of M(t))Se.call(t,o)&&be(e,o,t[o]);return e},P=(e,t)=>ct(e,mt(t));var Ve=(e,t)=>{var o={};for(var n in e)xe.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&M)for(var n of M(e))t.indexOf(n)<0&&Se.call(e,n)&&(o[n]=e[n]);return o};var f=(e,t,o)=>new Promise((n,r)=>{var s=p=>{try{a(o.next(p));}catch(d){r(d);}},i=p=>{try{a(o.throw(p));}catch(d){r(d);}},a=p=>p.done?n(p.value):Promise.resolve(p.value).then(s,i);a((o=o.apply(e,t)).next());});var Ie="fp-session-id",Oe=typeof window!="undefined",ee="xfpsessionid",te=()=>{let e=Date.now(),t=Math.floor(Math.random()*1e9);return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,o=>{let n=(e+t)*Math.random()*16%16|0;return (o==="x"?n:n&3|8).toString(16)})},Ae=(e,t)=>new URL(t).searchParams.get(e),ft=e=>{var t,o;try{let n=(o=(t=window==null?void 0:window.top)==null?void 0:t.location)==null?void 0:o.href;return n?Ae(e,n):null}catch(n){return null}},_=()=>Oe?Ae(ee,window.location.href)||ft(ee):null,Ee=()=>{if((!Oe||!window.sessionStorage))return !1;try{let e="test";return sessionStorage.setItem(e,e),sessionStorage.removeItem(e),!0}catch(e){return !1}},yt=()=>{let e=_()||te();if(Ee())try{sessionStorage.setItem(Ie,e);}catch(t){console.error("Failed to create session id",t);}return e},ht=()=>{let e=_();return e||(Ee()?sessionStorage.getItem(Ie):null)},Le=()=>ht()||yt(),K=(e,t=Le())=>{let o=new URL(e);return o.searchParams.set(ee,t),o.toString()};var U=Le;var T="3.15.4";var $=(a=>(a.Auth="auth",a.Components="components",a.Form="form",a.Render="render",a.UpdateLoginMethods="update_login_methods",a.Verify="verify",a.VerifyButton="verify-button",a))($||{});var D=(i=>(i.auth="auth",i.canceled="canceled",i.clicked="clicked",i.closed="closed",i.completed="completed",i.relayToComponents="relayToComponents",i))(D||{}),N=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i.relayFromComponents="relayFromComponents",i))(N||{});var Re="footprint-inline-container",Fe="footprint-body-locked",Ke="footprint-overlay",Ct="footprint-overlay-container",Te=Re,De=Ke,Be="footprint-loading-indicator",j=e=>`${Ct}-${e}`,A=(e,t)=>`${e}-${t}`,Me=e=>f(void 0,null,function*(){oe(e),vt(e),yield Pt(e);}),_e=e=>{let t=j(e),o=document.getElementById(t);if(o)return o;let n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n},Pt=e=>f(void 0,null,function*(){let t=j(e),o=document.getElementById(t);if(!o)return;let n=o.querySelector("iframe.footprint-drawer");n&&(n==null||n.classList.add("footprint-drawer-closing"),yield new Promise(a=>{setTimeout(a,300);}));let r=o.querySelector("iframe.footprint-modal");r&&(r==null||r.classList.add("footprint-modal-closing"),yield new Promise(a=>{setTimeout(a,100);}));let s=A(De,e),i=document.getElementById(s);i&&(i.classList.add("footprint-overlay-fading"),yield new Promise(a=>{setTimeout(a,200);}),o.remove(),i.remove(),document.body.classList.remove(Fe));}),Ue=(e,t)=>{let o=A(Te,e),n=document.createElement("div");return n.classList.add(Re),n.setAttribute("id",o),t.appendChild(n),n},vt=e=>{let t=A(Te,e),o=document.getElementById(t);o&&o.remove();},oe=e=>{let t=A(Be,e),o=document.getElementById(t);o&&o.remove();},ne=(e,t)=>{let o=A(Be,t),n=wt(o);e.appendChild(n);},$e=(e,t)=>{document.body.classList.add(Fe);let o=document.createElement("div"),n=A(De,t);return o.setAttribute("id",n),o.classList.add(Ke),e.appendChild(o),o},wt=e=>{let t=document.createElement("div");t.setAttribute("id",e),t.classList.add("footprint-loading-indicator");let o=document.createElement("div");o.classList.add("footprint-loading-spin");let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","24px"),n.setAttribute("height","24px"),n.setAttribute("fill","none"),n.setAttribute("aria-hidden","true");let r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(r),o.appendChild(n),t.appendChild(o),t},Ne=e=>{let t=document.getElementById(j(e));t&&(t.style.opacity="1",t.style.display="block");},je=e=>{let t=document.getElementById(j(e));t&&(t.style.opacity="0",t.style.display="none");},re=(e,t="It looks like there was an issue loading the page. Try reloading and we'll get things back on track.")=>{let o=document.createElement("div");o.classList.add("modal-error-container"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.setAttribute("aria-label","Oops! Something's not quite right.");let n=document.createElement("div");n.classList.add("modal-error");let r=document.createElement("button");r.setAttribute("aria-label","Close"),r.classList.add("modal-error-close-button"),r.addEventListener("click",()=>{e.remove();});let s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("xmlns","http://www.w3.org/2000/svg"),s.setAttribute("width","20"),s.setAttribute("height","20"),s.setAttribute("viewBox","0 0 20 20"),s.setAttribute("fill","none");let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M5 5L15 15M15 5L5 15"),i.setAttribute("stroke","black"),i.setAttribute("stroke-width","1.5"),i.setAttribute("stroke-linecap","round"),s.appendChild(i),r.appendChild(s);let a=document.createElementNS("http://www.w3.org/2000/svg","svg");a.setAttribute("xmlns","http://www.w3.org/2000/svg"),a.setAttribute("width","40"),a.setAttribute("height","40"),a.setAttribute("viewBox","0 0 40 40"),a.setAttribute("fill","none"),a.setAttribute("class","error-icon");let p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d","M25 15L15 25M25 25L15 15M35 20C35 28.2843 28.2843 35 20 35C11.7157 35 5 28.2843 5 20C5 11.7157 11.7157 5 20 5C28.2843 5 35 11.7157 35 20Z"),p.setAttribute("stroke","black"),p.setAttribute("stroke-width","3.33333"),p.setAttribute("stroke-linecap","round"),p.setAttribute("stroke-linejoin","round"),a.appendChild(p);let d=document.createElement("h2");d.textContent="Oops! Something's not quite right.";let l=document.createElement("p");l.textContent=t,n.appendChild(r),n.appendChild(a),n.appendChild(d),n.appendChild(l),o.appendChild(n),e.appendChild(o);};var bt=()=>Math.random().toString(36).substring(2),H=bt;var q="https://api.onefootprint.com",z=T,J="footprint-js";var b={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["update_login_methods"]:"update_auth_methods_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1",["components"]:"verify_v1"};var xt=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),se=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([n,r])=>{let s;return Array.isArray(r)?s=r.map(se(e)):Object(r)===r?s=se(e)(r):s=r,[e(n),s]});return Object.fromEntries(o)},St=se(xt),He=(e,t="")=>Object.entries(e).flatMap(([o,n])=>{let r=t?`${t}.${o}`:o;return n&&typeof n=="object"&&!Array.isArray(n)?He(n,r):n?[r]:[]}),qe=e=>!e||typeof e!="object"?"":He(e).join(", "),W=St;var Vt=(e,t,o,n)=>{let r={tenantDomain:n,sdkKind:e,sdkName:J,sdkVersion:z,logLevel:o,logMessage:t,sessionId:U()};try{fetch(`${q}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(W(r))});}catch(s){}},Q=Vt;var S=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}Q(e,t,"info",n);}return o},ae=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}Q(e,t,"warn",n);}return o},ze=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}Q(e,t,"error",n);}return o};var Je={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["update_login_methods"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["form"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify"]:{["auth"]:"onAuth",["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["components"]:{["auth"]:"onAuth",["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete",["relayToComponents"]:"onRelayToComponents"},["verify-button"]:{["auth"]:"onAuth",["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},We={["auth"]:[],["form"]:[],["render"]:[],["update_login_methods"]:[],["verify"]:[],["components"]:[],["verify-button"]:[]};var Qe={["auth"]:["modal","drawer"],["components"]:["modal"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["update_login_methods"]:["modal","drawer"],["verify"]:["modal","drawer","inline"],["verify-button"]:["inline"]},It=Object.values(D),Ot=(...e)=>{},x=e=>e!=null&&typeof e=="object"&&!Array.isArray(e),de=e=>x(e)&&Object.keys(e).length>0,At=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},X=(e,t)=>{var r;if(!t)return;let o=(r=Qe[e])!=null?r:[];if(!o.includes(t))throw new Error(`Invalid variant: ${JSON.stringify(t)}. Valid variants for ${e} are ${o.join(", ")}`)},E=e=>{var o;let t=(o=Qe[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},Y=e=>{if(!e)throw new Error("Kind is required");let t=Object.values($);if(!t.includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${t.join(", ")}`)},Xe=e=>{if(e.kind==="verify-button"){let t=e,{kind:o,appearance:n,variant:r,dialogVariant:s,onClick:i,label:a,containerId:p}=t,d=Ve(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return P(g({},d),{variant:s,kind:"verify"})}};var Ye=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Ot,pe=(e,t,o)=>{var a;let{kind:n}=e,r=(a=Je[n])!=null?a:{},s={},i=Xe(e);return Object.entries(r).forEach(([p,d])=>{let l=p;if(!It.includes(l))return;let v=Ye(e,d),L=l==="closed"||l==="canceled",m=n==="verify-button"&&l==="clicked";s[l]=C=>{v(C),L&&(t==null||t()),m&&i&&(o==null||o(i));};}),s},B=e=>{let{kind:t,variant:o,containerId:n}=e,r=o||E(t);return Y(t),X(t,o),At(r,n),de(e==null?void 0:e.userData)&&console.warn("userData is deprecated and will be removed in the next major version. Please use bootstrapData instead."),P(g({},e),{variant:r})},V=e=>de(e==null?void 0:e.bootstrapData)?{userData:e.bootstrapData}:de(e==null?void 0:e.userData)?{userData:e.userData}:void 0;var Et=e=>e==="auth";var Lt=e=>e==="update_login_methods";var le=e=>e.kind==="components";var ce=e=>typeof e=="string"&&e.length>0,Z=e=>Et(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/tok_/.test(e.authToken),Rt=e=>Lt(e.kind)&&!!e.authToken&&/tok_/.test(e.authToken),me=e=>[Z,Rt].some(t=>t(e));var Ft=!1,Kt=e=>me(e)?"update_auth_methods_v1":b[e.kind],Tt=e=>{var o,n;let{kind:t}=e;if(t==="verify"||t==="components")return P(g({},V(e)),{publicKey:e.publicKey,authToken:e.authToken,options:e.options,l10n:e.l10n,fixtureResult:(o=e.sandboxOutcome)==null?void 0:o.overallOutcome,documentFixtureResult:(n=e.sandboxOutcome)==null?void 0:n.documentOutcome,sandboxId:e.sandboxId,isComponentsSdk:t==="components",shouldRelayToComponents:t==="components"?e.shouldRelayToComponents:void 0});if(t==="update_login_methods")return P(g({},V(e)),{authToken:e.authToken,options:e.options,l10n:e.l10n});if(t==="auth")return Z(e)?P(g({},V(e)),{authToken:e.authToken,updateLoginMethods:e.updateLoginMethods,options:e.options,l10n:e.l10n}):e.authToken&&Ft?P(g({},V(e)),{authToken:e.authToken,options:e.options,l10n:e.l10n}):P(g({},V(e)),{publicKey:e.publicKey,options:e.options,l10n:e.l10n});if(t==="form")return {authToken:e.authToken,options:e.options,title:e.title,l10n:e.l10n};if(t==="render")return {authToken:e.authToken,canCopy:e.canCopy,defaultHidden:e.defaultHidden,id:e.id,label:e.label,showHiddenToggle:e.showHiddenToggle,l10n:e.l10n};if(t==="verify-button")return P(g({},V(e)),{publicKey:e.publicKey,options:e.options,authToken:e.authToken,label:e.label,l10n:e.l10n});throw new Error("Invalid kind provided")},Dt=e=>f(void 0,null,function*(){let t=Kt(e),o=Tt(e);S(t,`Sending SDK args: ${qe(o)}`);let n=yield fetch(`${q}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${J} ${z} ${t}`.trim(),"Content-Type":"application/json"},body:JSON.stringify({data:W(o),kind:t})});if(!n.ok){let s=yield n.json();throw s.message&&s.support_id?new Error(`${s.message} (Support ID: ${s.support_id})`):new Error("An error occurred while sending SDK args. Please try again later.")}let r=yield n.json();if((r==null?void 0:r.token)===void 0)throw new Error("Token is undefined");return r.token}),Ze=Dt;var Ge=({fontSrc:e,variables:t={},rules:o={},variant:n}={})=>{let r=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,s=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0;return {fontSrc:e,variables:r(),rules:s(),variant:n}},et=()=>{let e=window.footprintAppearance;return !e||!x(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,variables:e.variables}};var tt=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Bt=(e,t)=>{let{appearance:o,kind:n,l10n:r,variant:s}=e,{fontSrc:i,rules:a,variables:p}=Ge(o),d=new URLSearchParams;return p&&d.append("variables",p),a&&d.append("rules",a),i&&d.append("font_src",i),r!=null&&r.language&&d.append("lng",r.language),d.append("variant",s||E(n)),`${d.toString()}#${t}`},Mt=(e,t)=>{let{kind:o}=e,n=Bt(e,t),r=`https://components.onefootprint.com/${o}`,s=`https://components2.onefootprint.com/${o}`;if(o==="update_login_methods"&&(r="https://auth.onefootprint.com/user",s="https://auth2.onefootprint.com/user"),o==="auth"&&(r="https://auth.onefootprint.com",s="https://auth2.onefootprint.com"),(o==="verify"||o==="verify-button"||o==="components")&&(r="https://id.onefootprint.com",s="https://id2.onefootprint.com"),!ce(r))throw new Error(`${o}_URL environment variable is not defined.`);return r+=`?${n}`.trim(),s+=`?${n}`.trim(),{url:r,fallbackUrl:s}},ot=Mt;var O="application/x-postmate-v1+json",_t=5,Ut=0,$t=()=>++Ut,y=(...e)=>{S(k.sdkKind,e.map(t=>typeof t=="object"?JSON.stringify(t):t.toString()).join(" "));},Nt=e=>{let t=document.createElement("a");t.href=e;let o=t.protocol.length>4?t.protocol:window.location.protocol,n=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||`${o}//${n}`},jt={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},ye=(e,t)=>!(typeof t=="string"&&e.origin!==t||!e.data||typeof e.data=="object"&&!("postmate"in e.data)||e.data.type!==O||!jt[e.data.postmate]),Ht=(e,t)=>{let o=typeof e[t]=="function"?e[t]():e[t];return k.Promise.resolve(o)},ue=class{constructor(t){this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},y("Parent: Registering API"),y("Parent: Awaiting messages..."),this.listener=o=>{if(!ye(o,this.childOrigin))return !1;let{data:n,name:r}=((o||{}).data||{}).value||{};o.data.postmate==="emit"&&(y(`Parent: Received event emission: ${r}`),r in this.events&&this.events[r].forEach(s=>{s.call(this,n);}));},this.parent.addEventListener("message",this.listener,!1),y("Parent: Awaiting event emissions from Child");}get(t){return new k.Promise(o=>{let n=$t(),r=s=>{s.data.uid===n&&s.data.postmate==="reply"&&(this.parent.removeEventListener("message",r,!1),o(s.data.value));};this.parent.addEventListener("message",r,!1),this.child.postMessage({postmate:"request",type:O,property:t,uid:n},this.childOrigin);})}call(t,o){this.child.postMessage({postmate:"call",type:O,property:t,data:o},this.childOrigin);}on(t,o){this.events[t]||(this.events[t]=[]),this.events[t].push(o);}destroy(){y("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);}},fe=class{constructor(t){this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,y("Child: Registering API"),y("Child: Awaiting messages..."),this.child.addEventListener("message",o=>{if(!ye(o,this.parentOrigin))return;y("Child: Received request",o.data);let{property:n,uid:r,data:s}=o.data;if(o.data.postmate==="call"){n in this.model&&typeof this.model[n]=="function"&&this.model[n](s);return}Ht(this.model,n).then(i=>o.source.postMessage({property:n,postmate:"reply",type:O,uid:r,value:i},o.origin));});}emit(t,o){y(`Child: Emitting Event "${t}"`,o),this.parent.postMessage({postmate:"emit",type:O,value:{name:t,data:o}},this.parentOrigin);}},he=class{constructor({container:t=typeof t!="undefined"?t:document.body,model:o,url:n,name:r="",allow:s,id:i,classListArray:a=[]}){return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=r||"",this.frame.classList.add.apply(this.frame.classList,a),s&&(this.frame.allow=s),i&&(this.frame.id=i),t.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=o||{},this.sendHandshake(n)}sendHandshake(t){let o=Nt(t),n=0,r;return new he.Promise((s,i)=>{let a=l=>ye(l,o)?l.data.postmate==="handshake-reply"?(clearInterval(r),y("Parent: Received handshake reply from Child"),this.parent.removeEventListener("message",a,!1),this.childOrigin=l.origin,y("Parent: Saving Child origin",this.childOrigin),s(new ue(this))):(y("Parent: Invalid handshake reply"),i("Failed handshake")):!1;this.parent.addEventListener("message",a,!1);let p=()=>{if(n++,y(`Parent: Sending handshake attempt ${n}`,{childOrigin:o}),this.child.postMessage({postmate:"handshake",type:O,model:this.model},o),n===_t)return clearInterval(r),i("Failed to handshake")},d=()=>{p(),r=setInterval(p,500);};this.frame.attachEvent?this.frame.attachEvent("onload",d):this.frame.addEventListener("load",d),y("Parent: Loading frame",{url:t}),this.frame.src=t;})}},k=he;k.Promise=(()=>{try{return window?window.Promise:Promise}catch(t){return null}})();k.Model=class{constructor(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}sendHandshakeReply(){return new k.Promise((t,o)=>{let n=r=>{if(r.data.postmate){if(r.data.postmate==="handshake"){y("Child: Received handshake from Parent"),this.child.removeEventListener("message",n,!1),y("Child: Sending handshake reply to Parent"),r.source.postMessage({postmate:"handshake-reply",type:O},r.origin),this.parentOrigin=r.origin;let s=r.data.model;return s&&(Object.keys(s).forEach(i=>{this.model[i]=s[i];}),y("Child: Inherited and extended model from Parent")),y("Child: Saving Parent origin",this.parentOrigin),t(new fe(this))}return o("Handshake Reply Failed")}};this.child.addEventListener("message",n,!1);})}};var qt=e=>{let t=null,o=!1,n,r,{formSaveComplete:s,formSaved:i,formSaveFailed:a,started:p}=N,d=B(e),{variant:l,containerId:v}=d,L=l==="modal"||l==="drawer",m=H();S(b[d.kind],zt(d)),k.sdkKind=b[d.kind];let C=(c,u)=>{var w;let h=ze(b[d.kind],c);(w=d.onError)==null||w.call(d,h),o&&u&&(n(),o=!1);},at=()=>{if(!t){C("Footprint should be initialized in order to register callback props");return}let c=pe(d,n,r);Object.entries(c).forEach(([u,h])=>{t==null||t.on(u,h),t==null||t.on(`${m}:${u}`,h);});},dt=()=>{if(L)return _e(m);if(!v){C("containerId is required when rendering inline");return}let c=document.getElementById(v);if(!c){C(`Could not find container with id ${v} while rendering footprint`);return}return Ue(m,c)},G=(c,u)=>{if(!u){oe(m),t==null||t.frame.classList.remove("fp-hide"),t==null||t.frame.classList.remove(`footprint-${l}-loading`),t==null||t.frame.classList.add(`footprint-${l}-loaded`);return}if(L){let h=$e(c,m);ne(h,m);}else ne(c,m);},Ce=()=>{var u;if(!t){C("Footprint should be initialized in order to set up refs");return}if(d.kind!=="form"||!d.getRef)return;let c={save:()=>(t||C("Footprint should be initialized to call ref methods"),new Promise((h,w)=>{t==null||t.on(s,()=>{h();}),t==null||t.on(a,R=>{w(R);}),t==null||t.on(`${m}:${s}`,h),t==null||t.on(`${m}:${a}`,w),t==null||t.call(i,void 0);}))};(u=d.getRef)==null||u.call(d,c);},Pe=(c,u)=>f(void 0,null,function*(){let h=d.kind==="verify"&&d.variant==="inline"?["footprint-inline-verify"]:[];try{return t=yield new k({classListArray:[`footprint-${l}`,`footprint-${l}-loading`,"fp-hide",...h],container:c,name:`footprint-iframe-${m}`,url:u,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{authToken:d.authToken,initId:m,sdkUrl:tt(),sdkVersion:T||""}}),{success:!0,parentApi:t}}catch(w){return C(`Initializing iframe with ${new URL(u).host} failed with error ${w}`),{success:!1}}}),pt=(w,R)=>f(void 0,[w,R],function*(c,{url:u,fallbackUrl:h}){let F=b[d.kind];S(F,`Initializing iframe with ${new URL(u).host}`);let ve=yield Pe(c,u);if(ve.success)return ve.parentApi;S(F,`Initializing iframe with ${new URL(h).host} as fallback`);let we=yield Pe(c,h);if(!we.success)throw new Error("Failed to initialize iframe");return we.parentApi});return {relayFromComponents:()=>{t&&(t.call("relayFromComponents",void 0),Ne(m));},props:d,isRendered:o,render:()=>f(void 0,null,function*(){if(o){ae(b[d.kind],"Footprint component is already rendered");return}o=!0;let c=dt();if(!c){ae(b[d.kind],"Unable to create container for Footprint component");return}c.hasChildNodes()&&(c.innerHTML=""),G(c,!0);let u;try{u=yield Ze(d);}catch(R){let F=`${R instanceof Error?R.message:"Unknown error"}`;G(c,!1),re(c,F),C(`Unable to get SDK args token: ${F}`,!1);return}let{url:h,fallbackUrl:w}=ot(d,u||"");try{yield pt(c,{url:K(h),fallbackUrl:K(w)}),at();}catch(R){re(c),o=!1;}G(c,!1),t==null||t.on(p,()=>Ce()),t==null||t.on(`${m}:${p}`,Ce),d.kind==="components"&&(t==null||t.on(`${m}:${"relayToComponents"}`,()=>{je(m);}));}),destroy:()=>f(void 0,null,function*(){o&&(o=!1,yield Me(m),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(n=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(r=c);}}},zt=e=>{let{variant:t="-",kind:o="-",l10n:n,authToken:r,publicKey:s}=e;return [`variant: ${t}`,`kind: ${o}`,n&&`l10n: ${JSON.stringify(n)}`,`hasAuthToken: ${!!r}`,`publicKey: ${s!=null?s:"-"}`,`sdkVersion: ${T}`].filter(Boolean).join(", ")},ge=qt;var I=e=>{let t=B(e);return JSON.stringify(t)},Jt=()=>{let e=Object.create(null);return {getOrCreate:s=>{let i=I(s.props),a=Object.values(e).find(p=>I(p.iframe.props)===i);return a?a.iframe:(e[i]={iframe:s,secondaryIframes:{}},s)},getOrCreateSecondary:(s,i)=>{let a=I(s.props),p=I(i.props);if(!e[a])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:d}=e[a],l=Object.values(d).find(v=>I(v.props)===p);return l||(d[p]=i,i)},remove:s=>{let i=I(s.props),a=e[i];a&&(Object.keys(a.secondaryIframes).forEach(p=>{a.secondaryIframes[p].destroy();}),delete e[i]);},removeSecondary:(s,i)=>{let a=I(s.props),p=I(i.props);if(!e[a])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:d}=e[a],l=d[p];l&&(l.destroy(),delete d[p]);}}},nt=Jt;var Wt=()=>{let e=nt();return {init:o=>{let n=ge(o),r=()=>f(void 0,null,function*(){e.remove(n),yield n.destroy();}),s=d=>f(void 0,null,function*(){e.removeSecondary(n,d),yield d.destroy();}),i=d=>f(void 0,null,function*(){let l=ge(d);l=e.getOrCreateSecondary(n,l),l.registerOnDestroy(()=>{s(l);}),l.render();}),a=()=>f(void 0,null,function*(){n=e.getOrCreate(n),n.registerOnDestroy(r),n.registerOnRenderSecondary(i),yield n.render();}),p={};return le(o)&&(p={relayFromComponents:()=>{n.relayFromComponents();}}),g({render:a,destroy:r},p)}}},Qt=Wt(),ke=Qt;var Xt=e=>{window.setTimeout(e,0);},Yt=e=>{if(typeof window=="undefined")return;let t=r=>{var a;let s=(a=window.footprintCallbacks)!=null?a:{};if(!x(s))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return We[r].forEach(p=>{if(!s[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),s},o=r=>{var m;let s=r.getAttribute("data-kind");Y(s);let i=(m=r.getAttribute("data-variant"))!=null?m:E(s);X(s,i);let a=et(),p=t(s),d=r.getAttribute("data-props")||"",l;try{l=JSON.parse(d);}catch(C){throw Error("Could not parse `data-props` for footprint.")}if(!x(l))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let v=H();r.setAttribute("id",v),e.init(g(g({kind:s,variant:i,appearance:a,containerId:r.id},p),l)).render();},n=()=>{let r=document.querySelectorAll("[data-footprint]");r.length&&r.forEach(s=>{o(s);});};document.addEventListener("DOMContentLoaded",()=>Xt(n));},rt=Yt;var Zt="http://test",st=e=>f(void 0,null,function*(){let t=yield fetch(`${Zt}/hosted/identify/lite`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),Gt=e=>f(void 0,null,function*(){if(!x(e))throw new Error("User data must be passed in order to identify an user");let t=e["id.email"],o=e["id.phone_number"];return t&&(yield st({email:t}))?!0:o?yield st({phone_number:o}):!1}),it=Gt;var Nn=ke;rt(ke);
exports.FootprintComponentKind = $;
exports.FootprintPrivateEvent = N;
exports.FootprintPublicEvent = D;
exports.default = Nn;
exports.identifyFootprintUser = it;