@onefootprint/footprint-js
Advanced tools
Comparing version 3.8.2 to 3.8.3
@@ -169,4 +169,6 @@ import * as CSS from 'csstype'; | ||
type SupportedLocale = 'en-US' | 'es-MX'; | ||
type SupportedLanguage = 'en' | 'es'; | ||
type L10n = { | ||
locale?: SupportedLocale; | ||
language?: SupportedLanguage; | ||
}; | ||
@@ -188,2 +190,3 @@ type Variant = 'modal' | 'drawer' | 'inline'; | ||
variant?: Variant; | ||
onError?: (error: string) => void; | ||
}; | ||
@@ -190,0 +193,0 @@ type Options = { |
@@ -1,5 +0,5 @@ | ||
import Ne from '@onefootprint/postmate'; | ||
import Qe from '@onefootprint/postmate'; | ||
var ve=Object.defineProperty,he=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var U=(e,t,o)=>t in e?ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,C=(e,t)=>{for(var o in t||(t={}))$.call(t,o)&&U(e,o,t[o]);if(V)for(var o of V(t))N.call(t,o)&&U(e,o,t[o]);return e},x=(e,t)=>he(e,Ce(t));var M=(e,t)=>{var o={};for(var r in e)$.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&V)for(var r of V(e))t.indexOf(r)<0&&N.call(e,r)&&(o[r]=e[r]);return o};var f=(e,t,o)=>new Promise((r,i)=>{var n=p=>{try{s(o.next(p));}catch(a){i(a);}},d=p=>{try{s(o.throw(p));}catch(a){i(a);}},s=p=>p.done?r(p.value):Promise.resolve(p.value).then(n,d);s((o=o.apply(e,t)).next());});var w="3.8.2";var F=(n=>(n.Auth="auth",n.Form="form",n.Render="render",n.Verify="verify",n.VerifyButton="verify-button",n))(F||{});var I=(i=>(i.canceled="canceled",i.clicked="clicked",i.closed="closed",i.completed="completed",i))(I||{}),q=(n=>(n.formSaveComplete="formSaveComplete",n.formSaveFailed="formSaveFailed",n.formSaved="formSaved",n.propsReceived="propsReceived",n.started="started",n))(q||{});var H="footprint-inline-container",z="footprint-body-locked",J="footprint-overlay",W="footprint-overlay-container",X=H,Y=J,Z="footprint-loading-indicator",u=(e,t)=>`${e}-${t}`,G=e=>f(void 0,null,function*(){D(e),Ve(e),yield ke(e);}),Q=e=>{let t=u(W,e),o=document.getElementById(t);if(o)return o;let r=document.createElement("div");return r.setAttribute("id",t),document.body.appendChild(r),r},ke=e=>f(void 0,null,function*(){let t=u(W,e),o=document.getElementById(t);if(!o)return;let r=o.querySelector("iframe.footprint-drawer");r&&(r==null||r.classList.add("footprint-drawer-closing"),yield new Promise(s=>{setTimeout(s,300);}));let i=o.querySelector("iframe.footprint-modal");i&&(i==null||i.classList.add("footprint-modal-closing"),yield new Promise(s=>{setTimeout(s,100);}));let n=u(Y,e),d=document.getElementById(n);d&&(d.classList.add("footprint-overlay-fading"),yield new Promise(s=>{setTimeout(s,200);}),o.remove(),d.remove(),document.body.classList.remove(z));}),ee=(e,t)=>{let o=u(X,e),r=document.createElement("div");return r.classList.add(H),r.setAttribute("id",o),t.appendChild(r),r},Ve=e=>{let t=u(X,e),o=document.getElementById(t);o&&o.remove();},D=e=>{let t=u(Z,e),o=document.getElementById(t);o&&o.remove();},K=(e,t)=>{let o=u(Z,t),r=we(o);e.appendChild(r);},te=(e,t)=>{document.body.classList.add(z);let o=document.createElement("div"),r=u(Y,t);return o.setAttribute("id",r),o.classList.add(J),e.appendChild(o),o},we=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 r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","24px"),r.setAttribute("height","24px"),r.setAttribute("fill","none"),r.setAttribute("aria-hidden","true");let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),r.appendChild(i),o.appendChild(r),t.appendChild(o),t};var Fe=()=>`${Math.floor(Math.random()*1e3)}`,R=Fe;var oe={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["form"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify-button"]:{["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},re={["auth"]:[],["form"]:[],["render"]:[],["verify"]:[],["verify-button"]:[]};var ne={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},Ie=Object.values(I),Re=(...e)=>{},Se=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},S=(e,t)=>{var i;if(!t)return;let o=(i=ne[e])!=null?i:[];if(!o.includes(t))throw new Error(`Invalid variant: ${JSON.stringify(t)}. Valid variants for ${e} are ${o.join(", ")}`)},v=e=>{var o;let t=(o=ne[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},E=e=>{if(!e)throw new Error("Kind is required");let t=Object.values(F);if(!t.includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${t.join(", ")}`)},ie=e=>{if(e.kind==="verify-button"){let t=e,{kind:o,appearance:r,variant:i,dialogVariant:n,onClick:d,label:s,containerId:p}=t,a=M(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return x(C({},a),{variant:n,kind:"verify"})}};var ae=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Re,L=(e,t,o)=>{var s;let{kind:r}=e,i=(s=oe[r])!=null?s:{},n={},d=ie(e);return Object.entries(i).forEach(([p,a])=>{let l=p;if(!Ie.includes(l))return;let g=ae(e,a),b=l==="closed"||l==="canceled",h=r==="verify-button"&&l==="clicked";n[l]=O=>{g(O),b&&(t==null||t()),h&&d&&(o==null||o(d));};}),n},k=e=>{let{kind:t,variant:o,containerId:r}=e,i=o||v(t);return E(t),S(t,o),Se(i,r),x(C({},e),{variant:i})};var Ee="https://api.onefootprint.com",Oe=w,Ae=3;var xe={["verify"]:"verify_v1",["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["verify-button"]:"verify_button_v1"},De=e=>{let{kind:t}=e;if(t==="verify")return {publicKey:e.publicKey,authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return {publicKey:e.publicKey,userData:e.userData,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 {publicKey:e.publicKey,userData:e.userData,options:e.options,authToken:e.authToken,label:e.label,l10n:e.l10n}},Ke=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),B=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([r,i])=>{let n;return Array.isArray(i)?n=i.map(B(e)):Object(i)===i?n=B(e)(i):n=i,[e(r),n]});return Object.fromEntries(o)},Le=B(Ke),Be=e=>fetch(`${Ee}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`footprint-js ${Oe}`,"Content-Type":"application/json"},body:JSON.stringify(e)}),se=(e,t)=>f(void 0,null,function*(){return Be(e).then(o=>{if(o.ok)return o.json();if(t>0)return se(e,t-1);throw new Error(o.statusText)}).catch(o=>console.error(o.message))}),Te=e=>f(void 0,null,function*(){let t=De(e);if(!t){console.error("Footprint: Could not get data payload for sdk args. Please make sure the SDK integration is correct.");return}let o=xe[e.kind],r=yield se({data:Le(t),kind:o},Ae);if(!r){console.error("Footprint: Could not save sdk ars, this could be due to connectivity problems.");return}return r.token}),de=Te;var _e=e=>typeof e=="object"&&!!e,T=({fontSrc:e,variables:t={},rules:o={},variant:r}={})=>{let i=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,n=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0;return {fontSrc:e,variables:i(),rules:n(),variant:r}},pe=()=>{let e=window.footprintAppearance;return !e||!_e(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var ce=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},je=(e,t)=>{let{kind:o}=e;return o==="verify"?Ue(e,t):$e(e,t)},Ue=(e,t)=>{let{appearance:o,variant:r,kind:i}=e,{fontSrc:n,rules:d,variables:s}=T(o),p="https://id.onefootprint.com",a=new URLSearchParams;s&&a.append("variables",s),d&&a.append("rules",d),n&&a.append("font_src",n),a.append("variant",r!=null?r:v(i));let l=a.toString();return `${p}?${l}#${t}`},$e=(e,t)=>{let{appearance:o,kind:r,variant:i}=e,{fontSrc:n,rules:d,variables:s}=T(o),p="https://components.onefootprint.com",a=new URLSearchParams;s&&a.append("variables",s),d&&a.append("rules",d),n&&a.append("font_src",n),a.append("variant",i!=null?i:v(r));let l=a.toString();return `${p}/${r}?${l}#${t}`},le=je;var Me=e=>{let t=null,o=!1,r,i,n=k(e),{variant:d,containerId:s}=n,p=d==="modal"||d==="drawer",a=R(),l=()=>{if(!t)throw new Error("Footprint should be initialized in order to listen events");let c=L(n,r,i);Object.entries(c).forEach(([m,P])=>{t==null||t.on(m,P);});},g=()=>{if(p)return Q(a);if(!s)throw new Error("containerId is required when rendering inline");let c=document.getElementById(s);if(!c)throw new Error(`Could not find container with id ${s} while rendering footprint`);return ee(a,c)},b=(c,m)=>{if(!m){D(a),t==null||t.frame.classList.remove(`footprint-${d}-loading`),t==null||t.frame.classList.add(`footprint-${d}-loaded`);return}if(p){let P=te(c,a);K(P,a);}else K(c,a);},h=()=>{var m;if(!t)throw new Error("Footprint should be initialized in order to set up refs");if(n.kind!=="form"||!n.getRef)return;let c={save:()=>{if(!t)throw new Error("Footprint should be initialized to call ref methods");return new Promise((P,A)=>{t==null||t.on("formSaveComplete",()=>{P();}),t==null||t.on("formSaveFailed",Pe=>{A(Pe);}),t==null||t.call("formSaved");})}};(m=n.getRef)==null||m.call(n,c);};return {props:n,isRendered:o,render:()=>f(void 0,null,function*(){if(o)return;let c=g();if(!c)return;c.hasChildNodes()&&(c.innerHTML=""),o=!0,b(c,!0);let m=yield de(n);if(!m){r();return}let P=le(n,m||"");try{t=yield new Ne({classListArray:[`footprint-${d}`,`footprint-${d}-loading`],container:c,name:`footprint-iframe-${a}`,url:P,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{sdkVersion:w||"",sdkUrl:ce()}});}catch(A){console.error("Initializing Footprint iframe failed with error: ",A),r();return}b(c,!1),l(),t==null||t.on("started",()=>{h();});}),destroy:()=>f(void 0,null,function*(){o&&(o=!1,yield G(a),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(r=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(i=c);}}},_=Me;var y=e=>{let t=k(e);return JSON.stringify(t)},qe=()=>{let e=Object.create(null);return {getOrCreate:n=>{let d=y(n.props),s=Object.values(e).find(p=>y(p.iframe.props)===d);return s?s.iframe:(e[d]={iframe:n,secondaryIframes:{}},n)},getOrCreateSecondary:(n,d)=>{let s=y(n.props),p=y(d.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:a}=e[s],l=Object.values(a).find(g=>y(g.props)===p);return l||(a[p]=d,d)},remove:n=>{let d=y(n.props),s=e[d];s&&(Object.keys(s.secondaryIframes).forEach(p=>{s.secondaryIframes[p].destroy();}),delete e[d]);},removeSecondary:(n,d)=>{let s=y(n.props),p=y(d.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:a}=e[s],l=a[p];l&&(l.destroy(),delete a[p]);}}},fe=qe;var He=()=>{let e=fe();return {init:o=>{let r=_(o),i=()=>f(void 0,null,function*(){e.remove(r),yield r.destroy();}),n=p=>f(void 0,null,function*(){e.removeSecondary(r,p),yield p.destroy();}),d=p=>f(void 0,null,function*(){let a=_(p);a=e.getOrCreateSecondary(r,a),a.registerOnDestroy(()=>{n(a);}),a.render();});return {render:()=>f(void 0,null,function*(){r=e.getOrCreate(r),r.registerOnDestroy(i),r.registerOnRenderSecondary(d),yield r.render();}),destroy:i}}}},ze=He(),j=ze;var Je=e=>{window.setTimeout(e,0);},me=e=>typeof e=="object"&&!!e,We=e=>{if(typeof window=="undefined")return;let t=i=>{var s;let n=(s=window.footprintCallbacks)!=null?s:{};if(!me(n))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return re[i].forEach(p=>{if(!n[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),n},o=i=>{var h;let n=i.getAttribute("data-kind");E(n);let d=(h=i.getAttribute("data-variant"))!=null?h:v(n);S(n,d);let s=pe(),p=t(n),a=i.getAttribute("data-props")||"",l;try{l=JSON.parse(a);}catch(O){throw Error("Could not parse `data-props` for footprint.")}if(!me(l))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let g=R();i.setAttribute("id",g),e.init(C(C({kind:n,variant:d,appearance:s,containerId:i.id},p),l)).render();},r=()=>{let i=document.querySelectorAll("[data-footprint]");i.length&&i.forEach(n=>{o(n);});};document.addEventListener("DOMContentLoaded",()=>Je(r));},ue=We;var Xe="https://api.onefootprint.com",ye=e=>f(void 0,null,function*(){let t=yield fetch(`${Xe}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),Ye=e=>f(void 0,null,function*(){if(!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 ye({identifier:{email:t}}))?!0:o?yield ye({identifier:{phone_number:o}}):!1}),ge=Ye;var Qt=j;ue(j); | ||
var xe=Object.defineProperty,Oe=Object.defineProperties;var Ae=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var J=(e,t,o)=>t in e?xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,C=(e,t)=>{for(var o in t||(t={}))W.call(t,o)&&J(e,o,t[o]);if(S)for(var o of S(t))X.call(t,o)&&J(e,o,t[o]);return e},_=(e,t)=>Oe(e,Ae(t));var Y=(e,t)=>{var o={};for(var r in e)W.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&S)for(var r of S(e))t.indexOf(r)<0&&X.call(e,r)&&(o[r]=e[r]);return o};var m=(e,t,o)=>new Promise((r,n)=>{var i=d=>{try{s(o.next(d));}catch(a){n(a);}},p=d=>{try{s(o.throw(d));}catch(a){n(a);}},s=d=>d.done?r(d.value):Promise.resolve(d.value).then(i,p);s((o=o.apply(e,t)).next());});var I="3.8.3";var R=(i=>(i.Auth="auth",i.Form="form",i.Render="render",i.Verify="verify",i.VerifyButton="verify-button",i))(R||{});var F=(n=>(n.canceled="canceled",n.clicked="clicked",n.closed="closed",n.completed="completed",n))(F||{}),E=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i))(E||{});var Z="footprint-inline-container",G="footprint-body-locked",Q="footprint-overlay",ee="footprint-overlay-container",te=Z,oe=Q,re="footprint-loading-indicator",v=(e,t)=>`${e}-${t}`,ne=e=>m(void 0,null,function*(){$(e),Le(e),yield De(e);}),ie=e=>{let t=v(ee,e),o=document.getElementById(t);if(o)return o;let r=document.createElement("div");return r.setAttribute("id",t),document.body.appendChild(r),r},De=e=>m(void 0,null,function*(){let t=v(ee,e),o=document.getElementById(t);if(!o)return;let r=o.querySelector("iframe.footprint-drawer");r&&(r==null||r.classList.add("footprint-drawer-closing"),yield new Promise(s=>{setTimeout(s,300);}));let n=o.querySelector("iframe.footprint-modal");n&&(n==null||n.classList.add("footprint-modal-closing"),yield new Promise(s=>{setTimeout(s,100);}));let i=v(oe,e),p=document.getElementById(i);p&&(p.classList.add("footprint-overlay-fading"),yield new Promise(s=>{setTimeout(s,200);}),o.remove(),p.remove(),document.body.classList.remove(G));}),ae=(e,t)=>{let o=v(te,e),r=document.createElement("div");return r.classList.add(Z),r.setAttribute("id",o),t.appendChild(r),r},Le=e=>{let t=v(te,e),o=document.getElementById(t);o&&o.remove();},$=e=>{let t=v(re,e),o=document.getElementById(t);o&&o.remove();},j=(e,t)=>{let o=v(re,t),r=Te(o);e.appendChild(r);},se=(e,t)=>{document.body.classList.add(G);let o=document.createElement("div"),r=v(oe,t);return o.setAttribute("id",r),o.classList.add(Q),e.appendChild(o),o},Te=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 r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","24px"),r.setAttribute("height","24px"),r.setAttribute("fill","none"),r.setAttribute("aria-hidden","true");let n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),r.appendChild(n),o.appendChild(r),t.appendChild(o),t};var Be=()=>Math.random().toString(36).substring(2),x=Be;var O="https://api.onefootprint.com",A=I,K="footprint-js";var D={["verify"]:"verify_v1",["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["verify-button"]:"verify_button_v1"};var _e=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),U=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([r,n])=>{let i;return Array.isArray(n)?i=n.map(U(e)):Object(n)===n?i=U(e)(n):i=n,[e(r),i]});return Object.fromEntries(o)},$e=U(_e),L=$e;var je=(e,t,o,r)=>{let n={tenantDomain:r,sdkKind:e,sdkName:K,sdkVersion:A,logLevel:o,logMessage:t};try{fetch(`${O}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(L(n))});}catch(i){}},de=je;var pe=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let r;try{r=window.location.href;}catch(n){}de(e,t,"error",r);}return o};var ce={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["form"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify-button"]:{["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},le={["auth"]:[],["form"]:[],["render"]:[],["verify"]:[],["verify-button"]:[]};var fe={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},Ne=Object.values(F),Me=(...e)=>{},qe=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},T=(e,t)=>{var n;if(!t)return;let o=(n=fe[e])!=null?n:[];if(!o.includes(t))throw new Error(`Invalid variant: ${JSON.stringify(t)}. Valid variants for ${e} are ${o.join(", ")}`)},b=e=>{var o;let t=(o=fe[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},B=e=>{if(!e)throw new Error("Kind is required");let t=Object.values(R);if(!t.includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${t.join(", ")}`)},me=e=>{if(e.kind==="verify-button"){let t=e,{kind:o,appearance:r,variant:n,dialogVariant:i,onClick:p,label:s,containerId:d}=t,a=Y(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return _(C({},a),{variant:i,kind:"verify"})}};var ue=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Me,N=(e,t,o)=>{var s;let{kind:r}=e,n=(s=ce[r])!=null?s:{},i={},p=me(e);return Object.entries(n).forEach(([d,a])=>{let l=d;if(!Ne.includes(l))return;let P=ue(e,a),V=l==="closed"||l==="canceled",f=r==="verify-button"&&l==="clicked";i[l]=g=>{P(g),V&&(t==null||t()),f&&p&&(o==null||o(p));};}),i},w=e=>{let{kind:t,variant:o,containerId:r}=e,n=o||b(t);return B(t),T(t,o),qe(n,r),_(C({},e),{variant:n})};var He=3,ze=e=>{let{kind:t}=e;if(t==="verify")return {publicKey:e.publicKey,authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return {publicKey:e.publicKey,userData:e.userData,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 {publicKey:e.publicKey,userData:e.userData,options:e.options,authToken:e.authToken,label:e.label,l10n:e.l10n}},ye=(e,t)=>m(void 0,null,function*(){return fetch(`${O}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${K} ${A} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>{if(o.ok)return o.json();if(t>0)return ye(e,t-1)})}),Je=e=>m(void 0,null,function*(){let t=ze(e);if(!t)return;let o=D[e.kind],r=yield ye({data:L(t),kind:o},He);return r?r.token:void 0}),ge=Je;var We=e=>typeof e=="object"&&!!e,Pe=({fontSrc:e,variables:t={},rules:o={},variant:r}={})=>{let n=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,i=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0;return {fontSrc:e,variables:n(),rules:i(),variant:r}},ve=()=>{let e=window.footprintAppearance;return !e||!We(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var Xe=e=>e==="auth",Ye=e=>e==="verify",Ze=e=>typeof e=="string"&&e.length>0,he=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},ke=(e,t)=>{let{appearance:o,kind:r,l10n:n,variant:i}=e,{fontSrc:p,rules:s,variables:d}=Pe(o),a=new URLSearchParams;return d&&a.append("variables",d),s&&a.append("rules",s),p&&a.append("font_src",p),n!=null&&n.language&&a.append("lng",n.language),a.append("variant",i||b(r)),`${a.toString()}#${t}`},Ge=(e,t)=>{let{kind:o}=e,r;switch(o){case"verify":r="https://id.onefootprint.com";break;case"auth":r="https://auth.onefootprint.com";break;default:r="https://components.onefootprint.com";}if(Ze(r))return Ye(o)||Xe(o)?`${r}?${ke(e,t)}`.trim():`${r}/${o}?${ke(e,t)}`.trim();throw new Error(`${o}_URL environment variable is not defined.`)},Ce=Ge;var et=e=>{let t=null,o=!1,r,n,{formSaveComplete:i,formSaved:p,formSaveFailed:s,started:d}=E,a=w(e),{variant:l,containerId:P}=a,V=l==="modal"||l==="drawer",f=x(),g=(c,u)=>{var h;let y=pe(D[a.kind],c);(h=a.onError)==null||h.call(a,y),o&&u&&(r(),o=!1);},Re=()=>{if(!t){g("Footprint should be initialized in order to register callback props");return}let c=N(a,r,n);Object.entries(c).forEach(([u,y])=>{t==null||t.on(u,y),t==null||t.on(`${f}:${u}`,y);});},Fe=()=>{if(V)return ie(f);if(!P){g("containerId is required when rendering inline");return}let c=document.getElementById(P);if(!c){g(`Could not find container with id ${P} while rendering footprint`);return}return ae(f,c)},H=(c,u)=>{if(!u){$(f),t==null||t.frame.classList.remove(`footprint-${l}-loading`),t==null||t.frame.classList.add(`footprint-${l}-loaded`);return}if(V){let y=se(c,f);j(y,f);}else j(c,f);},z=()=>{var u;if(!t){g("Footprint should be initialized in order to set up refs");return}if(a.kind!=="form"||!a.getRef)return;let c={save:()=>(t||g("Footprint should be initialized to call ref methods"),new Promise((y,h)=>{t==null||t.on(i,()=>{y();}),t==null||t.on(s,Ee=>{h(Ee);}),t==null||t.on(`${f}:${i}`,y),t==null||t.on(`${f}:${s}`,h),t==null||t.call(p);}))};(u=a.getRef)==null||u.call(a,c);};return {props:a,isRendered:o,render:()=>m(void 0,null,function*(){if(o)return;let c=Fe();if(!c)return;c.hasChildNodes()&&(c.innerHTML=""),o=!0,H(c,!0);let u=yield ge(a);if(!u){g("Unable to get SDK args token.",!0);return}let y=Ce(a,u||"");try{t=yield new Qe({classListArray:[`footprint-${l}`,`footprint-${l}-loading`],container:c,name:`footprint-iframe-${f}`,url:y,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{initId:f,sdkVersion:I||"",sdkUrl:he()}});}catch(h){g(`Initializing iframe failed with error ${h}`,!0);return}H(c,!1),Re(),t==null||t.on(d,()=>z()),t==null||t.on(`${f}:${d}`,z);}),destroy:()=>m(void 0,null,function*(){o&&(o=!1,yield ne(f),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(r=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(n=c);}}},M=et;var k=e=>{let t=w(e);return JSON.stringify(t)},tt=()=>{let e=Object.create(null);return {getOrCreate:i=>{let p=k(i.props),s=Object.values(e).find(d=>k(d.iframe.props)===p);return s?s.iframe:(e[p]={iframe:i,secondaryIframes:{}},i)},getOrCreateSecondary:(i,p)=>{let s=k(i.props),d=k(p.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:a}=e[s],l=Object.values(a).find(P=>k(P.props)===d);return l||(a[d]=p,p)},remove:i=>{let p=k(i.props),s=e[p];s&&(Object.keys(s.secondaryIframes).forEach(d=>{s.secondaryIframes[d].destroy();}),delete e[p]);},removeSecondary:(i,p)=>{let s=k(i.props),d=k(p.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:a}=e[s],l=a[d];l&&(l.destroy(),delete a[d]);}}},be=tt;var ot=()=>{let e=be();return {init:o=>{let r=M(o),n=()=>m(void 0,null,function*(){e.remove(r),yield r.destroy();}),i=d=>m(void 0,null,function*(){e.removeSecondary(r,d),yield d.destroy();}),p=d=>m(void 0,null,function*(){let a=M(d);a=e.getOrCreateSecondary(r,a),a.registerOnDestroy(()=>{i(a);}),a.render();});return {render:()=>m(void 0,null,function*(){r=e.getOrCreate(r),r.registerOnDestroy(n),r.registerOnRenderSecondary(p),yield r.render();}),destroy:n}}}},rt=ot(),q=rt;var nt=e=>{window.setTimeout(e,0);},Ve=e=>typeof e=="object"&&!!e,it=e=>{if(typeof window=="undefined")return;let t=n=>{var s;let i=(s=window.footprintCallbacks)!=null?s:{};if(!Ve(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return le[n].forEach(d=>{if(!i[d])throw Error(`Callback '${d}' must be defined in window.footprintCallbacks`)}),i},o=n=>{var f;let i=n.getAttribute("data-kind");B(i);let p=(f=n.getAttribute("data-variant"))!=null?f:b(i);T(i,p);let s=ve(),d=t(i),a=n.getAttribute("data-props")||"",l;try{l=JSON.parse(a);}catch(g){throw Error("Could not parse `data-props` for footprint.")}if(!Ve(l))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let P=x();n.setAttribute("id",P),e.init(C(C({kind:i,variant:p,appearance:s,containerId:n.id},d),l)).render();},r=()=>{let n=document.querySelectorAll("[data-footprint]");n.length&&n.forEach(i=>{o(i);});};document.addEventListener("DOMContentLoaded",()=>nt(r));},we=it;var at="https://api.onefootprint.com",Se=e=>m(void 0,null,function*(){let t=yield fetch(`${at}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),st=e=>m(void 0,null,function*(){if(!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 Se({identifier:{email:t}}))?!0:o?yield Se({identifier:{phone_number:o}}):!1}),Ie=st;var wo=q;we(q); | ||
export { F as FootprintComponentKind, q as FootprintPrivateEvent, I as FootprintPublicEvent, Qt as default, ge as identifyFootprintUser }; | ||
export { R as FootprintComponentKind, E as FootprintPrivateEvent, F as FootprintPublicEvent, wo as default, Ie as identifyFootprintUser }; |
(function (exports) { | ||
'use strict'; | ||
var ke=Object.defineProperty,Ve=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var $=(e,t,r)=>t in e?ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t)=>{for(var r in t||(t={}))H.call(t,r)&&$(e,r,t[r]);if(O)for(var r of O(t))q.call(t,r)&&$(e,r,t[r]);return e},L=(e,t)=>Ve(e,be(t));var z=(e,t)=>{var r={};for(var n in e)H.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&O)for(var n of O(e))t.indexOf(n)<0&&q.call(e,n)&&(r[n]=e[n]);return r};var f=(e,t,r)=>new Promise((n,o)=>{var i=p=>{try{s(r.next(p));}catch(d){o(d);}},a=p=>{try{s(r.throw(p));}catch(d){o(d);}},s=p=>p.done?n(p.value):Promise.resolve(p.value).then(i,a);s((r=r.apply(e,t)).next());});var w="application/x-postmate-v1+json",Ee=5,Oe=0,Ie=function(){return ++Oe};var Re=function(t){var r=document.createElement("a");r.href=t;var n=r.protocol.length>4?r.protocol:window.location.protocol,o=r.host.length?r.port==="80"||r.port==="443"?r.hostname:r.host:window.location.host;return r.origin||n+"//"+o},Fe={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},_=function(t,r){return !(typeof r=="string"&&t.origin!==r||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==w||!Fe[t.data.postmate])},Se=function(t,r){var n=typeof t[r]=="function"?t[r]():t[r];return k.Promise.resolve(n)},Ae=function(){function e(r){var n=this;this.parent=r.parent,this.frame=r.frame,this.child=r.child,this.childOrigin=r.childOrigin,this.events={},this.listener=function(o){if(!_(o,n.childOrigin))return !1;var i=((o||{}).data||{}).value||{},a=i.data,s=i.name;o.data.postmate==="emit"&&s in n.events&&n.events[s].forEach(function(p){p.call(n,a);});},this.parent.addEventListener("message",this.listener,!1);}var t=e.prototype;return t.get=function(n){var o=this;return new k.Promise(function(i){var a=Ie(),s=function p(d){d.data.uid===a&&d.data.postmate==="reply"&&(o.parent.removeEventListener("message",p,!1),i(d.data.value));};o.parent.addEventListener("message",s,!1),o.child.postMessage({postmate:"request",type:w,property:n,uid:a},o.childOrigin);})},t.call=function(n,o){this.child.postMessage({postmate:"call",type:w,property:n,data:o},this.childOrigin);},t.on=function(n,o){this.events[n]||(this.events[n]=[]),this.events[n].push(o);},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),De=function(){function e(r){var n=this;this.model=r.model,this.parent=r.parent,this.parentOrigin=r.parentOrigin,this.child=r.child,this.child.addEventListener("message",function(o){if(_(o,n.parentOrigin)){var i=o.data,a=i.property,s=i.uid,p=i.data;if(o.data.postmate==="call"){a in n.model&&typeof n.model[a]=="function"&&n.model[a](p);return}Se(n.model,a).then(function(d){return o.source.postMessage({property:a,postmate:"reply",type:w,uid:s,value:d},o.origin)});}});}var t=e.prototype;return t.emit=function(n,o){this.parent.postMessage({postmate:"emit",type:w,value:{name:n,data:o}},this.parentOrigin);},e}(),k=function(){function e(r){var n=r.container,o=n===void 0?typeof o!="undefined"?o:document.body:n,i=r.model,a=r.url,s=r.name,p=s===void 0?"":s,d=r.allow,c=r.classListArray,m=c===void 0?[]:c;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=p||"",this.frame.classList.add.apply(this.frame.classList,m),d&&(this.frame.allow=d),o.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var t=e.prototype;return t.sendHandshake=function(n){var o=this,i=Re(n),a=0,s;return new e.Promise(function(p,d){var c=function u(P){return _(P,i)?P.data.postmate==="handshake-reply"?(clearInterval(s),o.parent.removeEventListener("message",u,!1),o.childOrigin=P.origin,p(new Ae(o))):d("Failed handshake"):!1};o.parent.addEventListener("message",c,!1);var m=function(){a++,o.child.postMessage({postmate:"handshake",type:w,model:o.model},i),a===Ee&&clearInterval(s);},h=function(){m(),s=setInterval(m,500);};o.frame.attachEvent?o.frame.attachEvent("onload",h):o.frame.addEventListener("load",h),o.frame.src=n;})},e}();k.debug=!1;k.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();k.Model=function(){function e(r){return this.child=window,this.model=r,this.parent=this.child.parent,this.sendHandshakeReply()}var t=e.prototype;return t.sendHandshakeReply=function(){var n=this;return new k.Promise(function(o,i){var a=function s(p){if(p.data.postmate){if(p.data.postmate==="handshake"){n.child.removeEventListener("message",s,!1),p.source.postMessage({postmate:"handshake-reply",type:w},p.origin),n.parentOrigin=p.origin;var d=p.data.model;return d&&Object.keys(d).forEach(function(c){n.model[c]=d[c];}),o(new De(n))}return i("Handshake Reply Failed")}};n.child.addEventListener("message",a,!1);})},e}();var J=k;var I="3.8.2";var R=(i=>(i.Auth="auth",i.Form="form",i.Render="render",i.Verify="verify",i.VerifyButton="verify-button",i))(R||{});var F=(o=>(o.canceled="canceled",o.clicked="clicked",o.closed="closed",o.completed="completed",o))(F||{}),W=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i))(W||{});var X="footprint-inline-container",Y="footprint-body-locked",Z="footprint-overlay",G="footprint-overlay-container",Q=X,ee=Z,te="footprint-loading-indicator",g=(e,t)=>`${e}-${t}`,re=e=>f(void 0,null,function*(){K(e),_e(e),yield Le(e);}),ne=e=>{let t=g(G,e),r=document.getElementById(t);if(r)return r;let n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n},Le=e=>f(void 0,null,function*(){let t=g(G,e),r=document.getElementById(t);if(!r)return;let n=r.querySelector("iframe.footprint-drawer");n&&(n==null||n.classList.add("footprint-drawer-closing"),yield new Promise(s=>{setTimeout(s,300);}));let o=r.querySelector("iframe.footprint-modal");o&&(o==null||o.classList.add("footprint-modal-closing"),yield new Promise(s=>{setTimeout(s,100);}));let i=g(ee,e),a=document.getElementById(i);a&&(a.classList.add("footprint-overlay-fading"),yield new Promise(s=>{setTimeout(s,200);}),r.remove(),a.remove(),document.body.classList.remove(Y));}),oe=(e,t)=>{let r=g(Q,e),n=document.createElement("div");return n.classList.add(X),n.setAttribute("id",r),t.appendChild(n),n},_e=e=>{let t=g(Q,e),r=document.getElementById(t);r&&r.remove();},K=e=>{let t=g(te,e),r=document.getElementById(t);r&&r.remove();},N=(e,t)=>{let r=g(te,t),n=Ke(r);e.appendChild(n);},ie=(e,t)=>{document.body.classList.add(Y);let r=document.createElement("div"),n=g(ee,t);return r.setAttribute("id",n),r.classList.add(Z),e.appendChild(r),r},Ke=e=>{let t=document.createElement("div");t.setAttribute("id",e),t.classList.add("footprint-loading-indicator");let r=document.createElement("div");r.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 o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(o),r.appendChild(n),t.appendChild(r),t};var Ne=()=>`${Math.floor(Math.random()*1e3)}`,S=Ne;var ae={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["form"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify-button"]:{["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},se={["auth"]:[],["form"]:[],["render"]:[],["verify"]:[],["verify-button"]:[]};var de={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},Te=Object.values(F),Be=(...e)=>{},je=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},A=(e,t)=>{var o;if(!t)return;let r=(o=de[e])!=null?o:[];if(!r.includes(t))throw new Error(`Invalid variant: ${JSON.stringify(t)}. Valid variants for ${e} are ${r.join(", ")}`)},V=e=>{var r;let t=(r=de[e])!=null?r:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},D=e=>{if(!e)throw new Error("Kind is required");let t=Object.values(R);if(!t.includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${t.join(", ")}`)},pe=e=>{if(e.kind==="verify-button"){let t=e,{kind:r,appearance:n,variant:o,dialogVariant:i,onClick:a,label:s,containerId:p}=t,d=z(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return L(b({},d),{variant:i,kind:"verify"})}};var ce=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Be,T=(e,t,r)=>{var s;let{kind:n}=e,o=(s=ae[n])!=null?s:{},i={},a=pe(e);return Object.entries(o).forEach(([p,d])=>{let c=p;if(!Te.includes(c))return;let m=ce(e,d),h=c==="closed"||c==="canceled",u=n==="verify-button"&&c==="clicked";i[c]=P=>{m(P),h&&(t==null||t()),u&&a&&(r==null||r(a));};}),i},E=e=>{let{kind:t,variant:r,containerId:n}=e,o=r||V(t);return D(t),A(t,r),je(o,n),L(b({},e),{variant:o})};var Ue="https://api.onefootprint.com",Me=I,$e=3;var He={["verify"]:"verify_v1",["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["verify-button"]:"verify_button_v1"},qe=e=>{let{kind:t}=e;if(t==="verify")return {publicKey:e.publicKey,authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return {publicKey:e.publicKey,userData:e.userData,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 {publicKey:e.publicKey,userData:e.userData,options:e.options,authToken:e.authToken,label:e.label,l10n:e.l10n}},ze=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),B=e=>t=>{if(!t||typeof t!="object")return t;let r=Object.entries(t).map(([n,o])=>{let i;return Array.isArray(o)?i=o.map(B(e)):Object(o)===o?i=B(e)(o):i=o,[e(n),i]});return Object.fromEntries(r)},Je=B(ze),We=e=>fetch(`${Ue}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`footprint-js ${Me}`,"Content-Type":"application/json"},body:JSON.stringify(e)}),le=(e,t)=>f(void 0,null,function*(){return We(e).then(r=>{if(r.ok)return r.json();if(t>0)return le(e,t-1);throw new Error(r.statusText)}).catch(r=>console.error(r.message))}),Xe=e=>f(void 0,null,function*(){let t=qe(e);if(!t){console.error("Footprint: Could not get data payload for sdk args. Please make sure the SDK integration is correct.");return}let r=He[e.kind],n=yield le({data:Je(t),kind:r},$e);if(!n){console.error("Footprint: Could not save sdk ars, this could be due to connectivity problems.");return}return n.token}),fe=Xe;var Ye=e=>typeof e=="object"&&!!e,j=({fontSrc:e,variables:t={},rules:r={},variant:n}={})=>{let o=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,i=()=>Object.keys(r).length?encodeURIComponent(JSON.stringify(r)):void 0;return {fontSrc:e,variables:o(),rules:i(),variant:n}},me=()=>{let e=window.footprintAppearance;return !e||!Ye(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var ue=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Ze=(e,t)=>{let{kind:r}=e;return r==="verify"?Ge(e,t):Qe(e,t)},Ge=(e,t)=>{let{appearance:r,variant:n,kind:o}=e,{fontSrc:i,rules:a,variables:s}=j(r),p="https://id.onefootprint.com",d=new URLSearchParams;s&&d.append("variables",s),a&&d.append("rules",a),i&&d.append("font_src",i),d.append("variant",n!=null?n:V(o));let c=d.toString();return `${p}?${c}#${t}`},Qe=(e,t)=>{let{appearance:r,kind:n,variant:o}=e,{fontSrc:i,rules:a,variables:s}=j(r),p="https://components.onefootprint.com",d=new URLSearchParams;s&&d.append("variables",s),a&&d.append("rules",a),i&&d.append("font_src",i),d.append("variant",o!=null?o:V(n));let c=d.toString();return `${p}/${n}?${c}#${t}`},ye=Ze;var et=e=>{let t=null,r=!1,n,o,i=E(e),{variant:a,containerId:s}=i,p=a==="modal"||a==="drawer",d=S(),c=()=>{if(!t)throw new Error("Footprint should be initialized in order to listen events");let l=T(i,n,o);Object.entries(l).forEach(([y,C])=>{t==null||t.on(y,C);});},m=()=>{if(p)return ne(d);if(!s)throw new Error("containerId is required when rendering inline");let l=document.getElementById(s);if(!l)throw new Error(`Could not find container with id ${s} while rendering footprint`);return oe(d,l)},h=(l,y)=>{if(!y){K(d),t==null||t.frame.classList.remove(`footprint-${a}-loading`),t==null||t.frame.classList.add(`footprint-${a}-loaded`);return}if(p){let C=ie(l,d);N(C,d);}else N(l,d);},u=()=>{var y;if(!t)throw new Error("Footprint should be initialized in order to set up refs");if(i.kind!=="form"||!i.getRef)return;let l={save:()=>{if(!t)throw new Error("Footprint should be initialized to call ref methods");return new Promise((C,x)=>{t==null||t.on("formSaveComplete",()=>{C();}),t==null||t.on("formSaveFailed",we=>{x(we);}),t==null||t.call("formSaved");})}};(y=i.getRef)==null||y.call(i,l);};return {props:i,isRendered:r,render:()=>f(void 0,null,function*(){if(r)return;let l=m();if(!l)return;l.hasChildNodes()&&(l.innerHTML=""),r=!0,h(l,!0);let y=yield fe(i);if(!y){n();return}let C=ye(i,y||"");try{t=yield new J({classListArray:[`footprint-${a}`,`footprint-${a}-loading`],container:l,name:`footprint-iframe-${d}`,url:C,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{sdkVersion:I||"",sdkUrl:ue()}});}catch(x){console.error("Initializing Footprint iframe failed with error: ",x),n();return}h(l,!1),c(),t==null||t.on("started",()=>{u();});}),destroy:()=>f(void 0,null,function*(){r&&(r=!1,yield re(d),t&&(t.destroy(),t=null));}),registerOnDestroy:l=>{!l||typeof l!="function"||(n=l);},registerOnRenderSecondary:l=>{!l||typeof l!="function"||(o=l);}}},U=et;var v=e=>{let t=E(e);return JSON.stringify(t)},tt=()=>{let e=Object.create(null);return {getOrCreate:i=>{let a=v(i.props),s=Object.values(e).find(p=>v(p.iframe.props)===a);return s?s.iframe:(e[a]={iframe:i,secondaryIframes:{}},i)},getOrCreateSecondary:(i,a)=>{let s=v(i.props),p=v(a.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:d}=e[s],c=Object.values(d).find(m=>v(m.props)===p);return c||(d[p]=a,a)},remove:i=>{let a=v(i.props),s=e[a];s&&(Object.keys(s.secondaryIframes).forEach(p=>{s.secondaryIframes[p].destroy();}),delete e[a]);},removeSecondary:(i,a)=>{let s=v(i.props),p=v(a.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:d}=e[s],c=d[p];c&&(c.destroy(),delete d[p]);}}},he=tt;var rt=()=>{let e=he();return {init:r=>{let n=U(r),o=()=>f(void 0,null,function*(){e.remove(n),yield n.destroy();}),i=p=>f(void 0,null,function*(){e.removeSecondary(n,p),yield p.destroy();}),a=p=>f(void 0,null,function*(){let d=U(p);d=e.getOrCreateSecondary(n,d),d.registerOnDestroy(()=>{i(d);}),d.render();});return {render:()=>f(void 0,null,function*(){n=e.getOrCreate(n),n.registerOnDestroy(o),n.registerOnRenderSecondary(a),yield n.render();}),destroy:o}}}},nt=rt(),M=nt;var ot=e=>{window.setTimeout(e,0);},ge=e=>typeof e=="object"&&!!e,it=e=>{if(typeof window=="undefined")return;let t=o=>{var s;let i=(s=window.footprintCallbacks)!=null?s:{};if(!ge(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return se[o].forEach(p=>{if(!i[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),i},r=o=>{var u;let i=o.getAttribute("data-kind");D(i);let a=(u=o.getAttribute("data-variant"))!=null?u:V(i);A(i,a);let s=me(),p=t(i),d=o.getAttribute("data-props")||"",c;try{c=JSON.parse(d);}catch(P){throw Error("Could not parse `data-props` for footprint.")}if(!ge(c))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let m=S();o.setAttribute("id",m),e.init(b(b({kind:i,variant:a,appearance:s,containerId:o.id},p),c)).render();},n=()=>{let o=document.querySelectorAll("[data-footprint]");o.length&&o.forEach(i=>{r(i);});};document.addEventListener("DOMContentLoaded",()=>ot(n));},ve=it;var at="https://api.onefootprint.com",Pe=e=>f(void 0,null,function*(){let t=yield fetch(`${at}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),st=e=>f(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let t=e["id.email"],r=e["id.phone_number"];return t&&(yield Pe({identifier:{email:t}}))?!0:r?yield Pe({identifier:{phone_number:r}}):!1}),Ce=st;var lr=M;ve(M);/*! Bundled license information: | ||
var Ke=Object.defineProperty,_e=Object.defineProperties;var Le=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var Y=(e,t,n)=>t in e?Ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))Z.call(t,n)&&Y(e,n,t[n]);if(I)for(var n of I(t))G.call(t,n)&&Y(e,n,t[n]);return e},$=(e,t)=>_e(e,Le(t));var Q=(e,t)=>{var n={};for(var r in e)Z.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&I)for(var r of I(e))t.indexOf(r)<0&&G.call(e,r)&&(n[r]=e[r]);return n};var m=(e,t,n)=>new Promise((r,o)=>{var i=d=>{try{s(n.next(d));}catch(a){o(a);}},p=d=>{try{s(n.throw(d));}catch(a){o(a);}},s=d=>d.done?r(d.value):Promise.resolve(d.value).then(i,p);s((n=n.apply(e,t)).next());});var w="application/x-postmate-v1+json",Ne=5,Te=0,Be=function(){return ++Te};var $e=function(t){var n=document.createElement("a");n.href=t;var r=n.protocol.length>4?n.protocol:window.location.protocol,o=n.host.length?n.port==="80"||n.port==="443"?n.hostname:n.host:window.location.host;return n.origin||r+"//"+o},je={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},j=function(t,n){return !(typeof n=="string"&&t.origin!==n||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==w||!je[t.data.postmate])},Me=function(t,n){var r=typeof t[n]=="function"?t[n]():t[n];return V.Promise.resolve(r)},Ue=function(){function e(n){var r=this;this.parent=n.parent,this.frame=n.frame,this.child=n.child,this.childOrigin=n.childOrigin,this.events={},this.listener=function(o){if(!j(o,r.childOrigin))return !1;var i=((o||{}).data||{}).value||{},p=i.data,s=i.name;o.data.postmate==="emit"&&s in r.events&&r.events[s].forEach(function(d){d.call(r,p);});},this.parent.addEventListener("message",this.listener,!1);}var t=e.prototype;return t.get=function(r){var o=this;return new V.Promise(function(i){var p=Be(),s=function d(a){a.data.uid===p&&a.data.postmate==="reply"&&(o.parent.removeEventListener("message",d,!1),i(a.data.value));};o.parent.addEventListener("message",s,!1),o.child.postMessage({postmate:"request",type:w,property:r,uid:p},o.childOrigin);})},t.call=function(r,o){this.child.postMessage({postmate:"call",type:w,property:r,data:o},this.childOrigin);},t.on=function(r,o){this.events[r]||(this.events[r]=[]),this.events[r].push(o);},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),He=function(){function e(n){var r=this;this.model=n.model,this.parent=n.parent,this.parentOrigin=n.parentOrigin,this.child=n.child,this.child.addEventListener("message",function(o){if(j(o,r.parentOrigin)){var i=o.data,p=i.property,s=i.uid,d=i.data;if(o.data.postmate==="call"){p in r.model&&typeof r.model[p]=="function"&&r.model[p](d);return}Me(r.model,p).then(function(a){return o.source.postMessage({property:p,postmate:"reply",type:w,uid:s,value:a},o.origin)});}});}var t=e.prototype;return t.emit=function(r,o){this.parent.postMessage({postmate:"emit",type:w,value:{name:r,data:o}},this.parentOrigin);},e}(),V=function(){function e(n){var r=n.container,o=r===void 0?typeof o!="undefined"?o:document.body:r,i=n.model,p=n.url,s=n.name,d=s===void 0?"":s,a=n.allow,c=n.classListArray,u=c===void 0?[]:c;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=d||"",this.frame.classList.add.apply(this.frame.classList,u),a&&(this.frame.allow=a),o.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(p)}var t=e.prototype;return t.sendHandshake=function(r){var o=this,i=$e(r),p=0,s;return new e.Promise(function(d,a){var c=function f(y){return j(y,i)?y.data.postmate==="handshake-reply"?(clearInterval(s),o.parent.removeEventListener("message",f,!1),o.childOrigin=y.origin,d(new Ue(o))):a("Failed handshake"):!1};o.parent.addEventListener("message",c,!1);var u=function(){p++,o.child.postMessage({postmate:"handshake",type:w,model:o.model},i),p===Ne&&clearInterval(s);},v=function(){u(),s=setInterval(u,500);};o.frame.attachEvent?o.frame.attachEvent("onload",v):o.frame.addEventListener("load",v),o.frame.src=r;})},e}();V.debug=!1;V.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();V.Model=function(){function e(n){return this.child=window,this.model=n,this.parent=this.child.parent,this.sendHandshakeReply()}var t=e.prototype;return t.sendHandshakeReply=function(){var r=this;return new V.Promise(function(o,i){var p=function s(d){if(d.data.postmate){if(d.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),d.source.postMessage({postmate:"handshake-reply",type:w},d.origin),r.parentOrigin=d.origin;var a=d.data.model;return a&&Object.keys(a).forEach(function(c){r.model[c]=a[c];}),o(new He(r))}return i("Handshake Reply Failed")}};r.child.addEventListener("message",p,!1);})},e}();var ee=V;var S="3.8.3";var R=(i=>(i.Auth="auth",i.Form="form",i.Render="render",i.Verify="verify",i.VerifyButton="verify-button",i))(R||{});var F=(o=>(o.canceled="canceled",o.clicked="clicked",o.closed="closed",o.completed="completed",o))(F||{}),D=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i))(D||{});var te="footprint-inline-container",ne="footprint-body-locked",re="footprint-overlay",oe="footprint-overlay-container",ie=te,ae=re,se="footprint-loading-indicator",P=(e,t)=>`${e}-${t}`,de=e=>m(void 0,null,function*(){M(e),Je(e),yield ze(e);}),pe=e=>{let t=P(oe,e),n=document.getElementById(t);if(n)return n;let r=document.createElement("div");return r.setAttribute("id",t),document.body.appendChild(r),r},ze=e=>m(void 0,null,function*(){let t=P(oe,e),n=document.getElementById(t);if(!n)return;let r=n.querySelector("iframe.footprint-drawer");r&&(r==null||r.classList.add("footprint-drawer-closing"),yield new Promise(s=>{setTimeout(s,300);}));let o=n.querySelector("iframe.footprint-modal");o&&(o==null||o.classList.add("footprint-modal-closing"),yield new Promise(s=>{setTimeout(s,100);}));let i=P(ae,e),p=document.getElementById(i);p&&(p.classList.add("footprint-overlay-fading"),yield new Promise(s=>{setTimeout(s,200);}),n.remove(),p.remove(),document.body.classList.remove(ne));}),ce=(e,t)=>{let n=P(ie,e),r=document.createElement("div");return r.classList.add(te),r.setAttribute("id",n),t.appendChild(r),r},Je=e=>{let t=P(ie,e),n=document.getElementById(t);n&&n.remove();},M=e=>{let t=P(se,e),n=document.getElementById(t);n&&n.remove();},U=(e,t)=>{let n=P(se,t),r=We(n);e.appendChild(r);},le=(e,t)=>{document.body.classList.add(ne);let n=document.createElement("div"),r=P(ae,t);return n.setAttribute("id",r),n.classList.add(re),e.appendChild(n),n},We=e=>{let t=document.createElement("div");t.setAttribute("id",e),t.classList.add("footprint-loading-indicator");let n=document.createElement("div");n.classList.add("footprint-loading-spin");let r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","24px"),r.setAttribute("height","24px"),r.setAttribute("fill","none"),r.setAttribute("aria-hidden","true");let o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),r.appendChild(o),n.appendChild(r),t.appendChild(n),t};var Xe=()=>Math.random().toString(36).substring(2),A=Xe;var x="https://api.onefootprint.com",K=S,_="footprint-js";var L={["verify"]:"verify_v1",["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["verify-button"]:"verify_button_v1"};var Ye=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),H=e=>t=>{if(!t||typeof t!="object")return t;let n=Object.entries(t).map(([r,o])=>{let i;return Array.isArray(o)?i=o.map(H(e)):Object(o)===o?i=H(e)(o):i=o,[e(r),i]});return Object.fromEntries(n)},Ze=H(Ye),N=Ze;var Ge=(e,t,n,r)=>{let o={tenantDomain:r,sdkKind:e,sdkName:_,sdkVersion:K,logLevel:n,logMessage:t};try{fetch(`${x}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N(o))});}catch(i){}},fe=Ge;var me=(e,t)=>{let n=`@onefootprint/footprint-js: ${t}`;{let r;try{r=window.location.href;}catch(o){}fe(e,t,"error",r);}return n};var ue={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["form"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["verify-button"]:{["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},ye={["auth"]:[],["form"]:[],["render"]:[],["verify"]:[],["verify-button"]:[]};var ge={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},et=Object.values(F),tt=(...e)=>{},nt=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},T=(e,t)=>{var o;if(!t)return;let n=(o=ge[e])!=null?o:[];if(!n.includes(t))throw new Error(`Invalid variant: ${JSON.stringify(t)}. Valid variants for ${e} are ${n.join(", ")}`)},E=e=>{var n;let t=(n=ge[e])!=null?n:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},B=e=>{if(!e)throw new Error("Kind is required");let t=Object.values(R);if(!t.includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${t.join(", ")}`)},he=e=>{if(e.kind==="verify-button"){let t=e,{kind:n,appearance:r,variant:o,dialogVariant:i,onClick:p,label:s,containerId:d}=t,a=Q(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return $(b({},a),{variant:i,kind:"verify"})}};var ve=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||tt,q=(e,t,n)=>{var s;let{kind:r}=e,o=(s=ue[r])!=null?s:{},i={},p=he(e);return Object.entries(o).forEach(([d,a])=>{let c=d;if(!et.includes(c))return;let u=ve(e,a),v=c==="closed"||c==="canceled",f=r==="verify-button"&&c==="clicked";i[c]=y=>{u(y),v&&(t==null||t()),f&&p&&(n==null||n(p));};}),i},O=e=>{let{kind:t,variant:n,containerId:r}=e,o=n||E(t);return B(t),T(t,n),nt(o,r),$(b({},e),{variant:o})};var rt=3,ot=e=>{let{kind:t}=e;if(t==="verify")return {publicKey:e.publicKey,authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return {publicKey:e.publicKey,userData:e.userData,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 {publicKey:e.publicKey,userData:e.userData,options:e.options,authToken:e.authToken,label:e.label,l10n:e.l10n}},Pe=(e,t)=>m(void 0,null,function*(){return fetch(`${x}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${_} ${K} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n=>{if(n.ok)return n.json();if(t>0)return Pe(e,t-1)})}),it=e=>m(void 0,null,function*(){let t=ot(e);if(!t)return;let n=L[e.kind],r=yield Pe({data:N(t),kind:n},rt);return r?r.token:void 0}),ke=it;var at=e=>typeof e=="object"&&!!e,Ce=({fontSrc:e,variables:t={},rules:n={},variant:r}={})=>{let o=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,i=()=>Object.keys(n).length?encodeURIComponent(JSON.stringify(n)):void 0;return {fontSrc:e,variables:o(),rules:i(),variant:r}},we=()=>{let e=window.footprintAppearance;return !e||!at(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var st=e=>e==="auth",dt=e=>e==="verify",pt=e=>typeof e=="string"&&e.length>0,be=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Ve=(e,t)=>{let{appearance:n,kind:r,l10n:o,variant:i}=e,{fontSrc:p,rules:s,variables:d}=Ce(n),a=new URLSearchParams;return d&&a.append("variables",d),s&&a.append("rules",s),p&&a.append("font_src",p),o!=null&&o.language&&a.append("lng",o.language),a.append("variant",i||E(r)),`${a.toString()}#${t}`},ct=(e,t)=>{let{kind:n}=e,r;switch(n){case"verify":r="https://id.onefootprint.com";break;case"auth":r="https://auth.onefootprint.com";break;default:r="https://components.onefootprint.com";}if(pt(r))return dt(n)||st(n)?`${r}?${Ve(e,t)}`.trim():`${r}/${n}?${Ve(e,t)}`.trim();throw new Error(`${n}_URL environment variable is not defined.`)},Ee=ct;var lt=e=>{let t=null,n=!1,r,o,{formSaveComplete:i,formSaved:p,formSaveFailed:s,started:d}=D,a=O(e),{variant:c,containerId:u}=a,v=c==="modal"||c==="drawer",f=A(),y=(l,g)=>{var C;let h=me(L[a.kind],l);(C=a.onError)==null||C.call(a,h),n&&g&&(r(),n=!1);},De=()=>{if(!t){y("Footprint should be initialized in order to register callback props");return}let l=q(a,r,o);Object.entries(l).forEach(([g,h])=>{t==null||t.on(g,h),t==null||t.on(`${f}:${g}`,h);});},Ae=()=>{if(v)return pe(f);if(!u){y("containerId is required when rendering inline");return}let l=document.getElementById(u);if(!l){y(`Could not find container with id ${u} while rendering footprint`);return}return ce(f,l)},W=(l,g)=>{if(!g){M(f),t==null||t.frame.classList.remove(`footprint-${c}-loading`),t==null||t.frame.classList.add(`footprint-${c}-loaded`);return}if(v){let h=le(l,f);U(h,f);}else U(l,f);},X=()=>{var g;if(!t){y("Footprint should be initialized in order to set up refs");return}if(a.kind!=="form"||!a.getRef)return;let l={save:()=>(t||y("Footprint should be initialized to call ref methods"),new Promise((h,C)=>{t==null||t.on(i,()=>{h();}),t==null||t.on(s,xe=>{C(xe);}),t==null||t.on(`${f}:${i}`,h),t==null||t.on(`${f}:${s}`,C),t==null||t.call(p);}))};(g=a.getRef)==null||g.call(a,l);};return {props:a,isRendered:n,render:()=>m(void 0,null,function*(){if(n)return;let l=Ae();if(!l)return;l.hasChildNodes()&&(l.innerHTML=""),n=!0,W(l,!0);let g=yield ke(a);if(!g){y("Unable to get SDK args token.",!0);return}let h=Ee(a,g||"");try{t=yield new ee({classListArray:[`footprint-${c}`,`footprint-${c}-loading`],container:l,name:`footprint-iframe-${f}`,url:h,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{initId:f,sdkVersion:S||"",sdkUrl:be()}});}catch(C){y(`Initializing iframe failed with error ${C}`,!0);return}W(l,!1),De(),t==null||t.on(d,()=>X()),t==null||t.on(`${f}:${d}`,X);}),destroy:()=>m(void 0,null,function*(){n&&(n=!1,yield de(f),t&&(t.destroy(),t=null));}),registerOnDestroy:l=>{!l||typeof l!="function"||(r=l);},registerOnRenderSecondary:l=>{!l||typeof l!="function"||(o=l);}}},z=lt;var k=e=>{let t=O(e);return JSON.stringify(t)},ft=()=>{let e=Object.create(null);return {getOrCreate:i=>{let p=k(i.props),s=Object.values(e).find(d=>k(d.iframe.props)===p);return s?s.iframe:(e[p]={iframe:i,secondaryIframes:{}},i)},getOrCreateSecondary:(i,p)=>{let s=k(i.props),d=k(p.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:a}=e[s],c=Object.values(a).find(u=>k(u.props)===d);return c||(a[d]=p,p)},remove:i=>{let p=k(i.props),s=e[p];s&&(Object.keys(s.secondaryIframes).forEach(d=>{s.secondaryIframes[d].destroy();}),delete e[p]);},removeSecondary:(i,p)=>{let s=k(i.props),d=k(p.props);if(!e[s])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:a}=e[s],c=a[d];c&&(c.destroy(),delete a[d]);}}},Oe=ft;var mt=()=>{let e=Oe();return {init:n=>{let r=z(n),o=()=>m(void 0,null,function*(){e.remove(r),yield r.destroy();}),i=d=>m(void 0,null,function*(){e.removeSecondary(r,d),yield d.destroy();}),p=d=>m(void 0,null,function*(){let a=z(d);a=e.getOrCreateSecondary(r,a),a.registerOnDestroy(()=>{i(a);}),a.render();});return {render:()=>m(void 0,null,function*(){r=e.getOrCreate(r),r.registerOnDestroy(o),r.registerOnRenderSecondary(p),yield r.render();}),destroy:o}}}},ut=mt(),J=ut;var yt=e=>{window.setTimeout(e,0);},Ie=e=>typeof e=="object"&&!!e,gt=e=>{if(typeof window=="undefined")return;let t=o=>{var s;let i=(s=window.footprintCallbacks)!=null?s:{};if(!Ie(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return ye[o].forEach(d=>{if(!i[d])throw Error(`Callback '${d}' must be defined in window.footprintCallbacks`)}),i},n=o=>{var f;let i=o.getAttribute("data-kind");B(i);let p=(f=o.getAttribute("data-variant"))!=null?f:E(i);T(i,p);let s=we(),d=t(i),a=o.getAttribute("data-props")||"",c;try{c=JSON.parse(a);}catch(y){throw Error("Could not parse `data-props` for footprint.")}if(!Ie(c))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let u=A();o.setAttribute("id",u),e.init(b(b({kind:i,variant:p,appearance:s,containerId:o.id},d),c)).render();},r=()=>{let o=document.querySelectorAll("[data-footprint]");o.length&&o.forEach(i=>{n(i);});};document.addEventListener("DOMContentLoaded",()=>yt(r));},Se=gt;var ht="https://api.onefootprint.com",Re=e=>m(void 0,null,function*(){let t=yield fetch(`${ht}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),vt=e=>m(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let t=e["id.email"],n=e["id.phone_number"];return t&&(yield Re({identifier:{email:t}}))?!0:n?yield Re({identifier:{phone_number:n}}):!1}),Fe=vt;var Ln=J;Se(J);/*! Bundled license information: | ||
@@ -17,6 +17,6 @@ @onefootprint/postmate/build/postmate.es.js: | ||
exports.FootprintComponentKind = R; | ||
exports.FootprintPrivateEvent = W; | ||
exports.FootprintPrivateEvent = D; | ||
exports.FootprintPublicEvent = F; | ||
exports.default = lr; | ||
exports.identifyFootprintUser = Ce; | ||
exports.default = Ln; | ||
exports.identifyFootprintUser = Fe; | ||
@@ -23,0 +23,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "3.8.2", | ||
"version": "3.8.3", | ||
"main": "./dist/footprint-js.cjs", | ||
@@ -8,0 +8,0 @@ "module": "./dist/footprint-js.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61017
503
9