@onefootprint/footprint-js
Advanced tools
Comparing version 3.9.1 to 3.10.0
@@ -14,2 +14,3 @@ import * as CSS from 'csstype'; | ||
containerBorderRadius: CSS.Property.BorderRadius; | ||
containerWidth: CSS.Property.Width; | ||
linkColor: CSS.Property.Color; | ||
@@ -190,8 +191,8 @@ fontFamily: CSS.Property.FontFamily; | ||
type PropsBase = { | ||
appearance?: Appearance; | ||
containerId?: string; | ||
kind: ComponentKind; | ||
l10n?: L10n; | ||
onError?: (error: string) => void; | ||
variant?: Variant; | ||
readonly appearance?: Appearance; | ||
readonly containerId?: string; | ||
readonly kind: ComponentKind; | ||
readonly l10n?: L10n; | ||
readonly onError?: (error: string) => void; | ||
readonly variant?: Variant; | ||
}; | ||
@@ -209,34 +210,36 @@ /** verify */ | ||
type VerifyPropsBase = PropsBase & { | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
onComplete?: (validationToken: string) => void; | ||
options?: Options; | ||
userData?: FootprintUserData; | ||
readonly onAuth?: (authToken: string) => void; | ||
readonly onCancel?: () => void; | ||
readonly onClose?: () => void; | ||
readonly onComplete?: (validationToken: string) => void; | ||
readonly options?: Options; | ||
readonly userData?: FootprintUserData; | ||
} & (VerifyAuthToken | VerifyPublicKey); | ||
type VerifyProps = VerifyPropsBase & { | ||
kind: ComponentKind.Verify; | ||
variant?: VerifyVariant; | ||
readonly kind: ComponentKind.Verify; | ||
readonly variant?: VerifyVariant; | ||
}; | ||
type VerifyDataProps = Pick<VerifyProps, 'publicKey' | 'userData' | 'options' | 'authToken' | 'l10n'>; | ||
type VerifyDataProps = Pick<VerifyProps, VerifyDataKeys>; | ||
type VerifyDataKeys = 'publicKey' | 'userData' | 'options' | 'authToken' | 'l10n'; | ||
/** verify-button */ | ||
type VerifyButtonProps = VerifyPropsBase & { | ||
containerId: string; | ||
dialogVariant?: VerifyVariant; | ||
kind: ComponentKind.VerifyButton; | ||
label?: string; | ||
onClick?: () => void; | ||
variant: 'inline'; | ||
readonly containerId: string; | ||
readonly dialogVariant?: VerifyVariant; | ||
readonly kind: ComponentKind.VerifyButton; | ||
readonly label?: string; | ||
readonly onClick?: () => void; | ||
readonly variant: 'inline'; | ||
}; | ||
type VerifyButtonDataProps = Pick<VerifyButtonProps, 'label'> & VerifyDataProps; | ||
type VerifyButtonDataProps = Pick<VerifyButtonProps, VerifyDataKeys | 'label'>; | ||
/** render */ | ||
type RenderProps = PropsBase & { | ||
authToken: string; | ||
canCopy?: boolean; | ||
containerId: string; | ||
defaultHidden?: boolean; | ||
id: string; | ||
kind: ComponentKind.Render; | ||
label?: string; | ||
showHiddenToggle?: boolean; | ||
variant: 'inline'; | ||
readonly authToken: string; | ||
readonly canCopy?: boolean; | ||
readonly containerId: string; | ||
readonly defaultHidden?: boolean; | ||
readonly id: string; | ||
readonly kind: ComponentKind.Render; | ||
readonly label?: string; | ||
readonly showHiddenToggle?: boolean; | ||
readonly variant: 'inline'; | ||
}; | ||
@@ -249,17 +252,17 @@ type RenderDataProps = Pick<RenderProps, 'authToken' | 'canCopy' | 'defaultHidden' | 'id' | 'label' | 'showHiddenToggle'>; | ||
type FormOptions = { | ||
hideButtons?: boolean; | ||
hideCancelButton?: boolean; | ||
hideFootprintLogo?: boolean; | ||
readonly hideButtons?: boolean; | ||
readonly hideCancelButton?: boolean; | ||
readonly hideFootprintLogo?: boolean; | ||
}; | ||
type FormProps = PropsBase & { | ||
authToken: string; | ||
containerId?: string; | ||
getRef?: (ref: FormRef) => void; | ||
kind: ComponentKind.Form; | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
onComplete?: () => void; | ||
options?: FormOptions; | ||
title?: string; | ||
variant?: Variant; | ||
readonly authToken: string; | ||
readonly containerId?: string; | ||
readonly getRef?: (ref: FormRef) => void; | ||
readonly kind: ComponentKind.Form; | ||
readonly onCancel?: () => void; | ||
readonly onClose?: () => void; | ||
readonly onComplete?: () => void; | ||
readonly options?: FormOptions; | ||
readonly title?: string; | ||
readonly variant?: Variant; | ||
}; | ||
@@ -269,17 +272,15 @@ type FormDataProps = Pick<FormProps, 'authToken' | 'options' | 'title' | 'l10n'>; | ||
type AuthPropsBase = PropsBase & { | ||
kind: ComponentKind.Auth; | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
onComplete?: (validationToken: string) => void; | ||
options?: Pick<Options, 'showLogo'>; | ||
userData?: Pick<FootprintUserData, 'id.email' | 'id.phone_number'>; | ||
variant?: 'modal' | 'drawer'; | ||
readonly kind: ComponentKind.Auth; | ||
readonly onCancel?: () => void; | ||
readonly onClose?: () => void; | ||
readonly onComplete?: (validationToken: string) => void; | ||
readonly options?: Pick<Options, 'showLogo'>; | ||
readonly userData?: Pick<FootprintUserData, 'id.email' | 'id.phone_number'>; | ||
readonly variant?: 'modal' | 'drawer'; | ||
}; | ||
type AuthProps = AuthPropsBase & { | ||
publicKey?: string; | ||
authToken?: string; | ||
/** | ||
* @deprecated after version 3.9.0 | ||
*/ | ||
updateLoginMethods?: true; | ||
readonly publicKey?: string; | ||
readonly authToken?: string; | ||
/** @deprecated after version 3.9.0 */ | ||
readonly updateLoginMethods?: true; | ||
}; | ||
@@ -289,12 +290,12 @@ type AuthDataProps = Pick<AuthProps, 'authToken' | 'updateLoginMethods' | 'publicKey' | 'userData' | 'l10n' | 'options'>; | ||
type UpdateLoginMethodsProps = PropsBase & { | ||
kind: ComponentKind.UpdateLoginMethods; | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
onComplete?: (validationToken: string) => void; | ||
options?: Pick<Options, 'showLogo'>; | ||
userData?: Pick<FootprintUserData, 'id.email' | 'id.phone_number'>; | ||
variant?: 'modal' | 'drawer'; | ||
authToken?: string; | ||
readonly kind: ComponentKind.UpdateLoginMethods; | ||
readonly onCancel?: () => void; | ||
readonly onClose?: () => void; | ||
readonly onComplete?: (validationToken: string) => void; | ||
readonly options?: Pick<Options, 'showLogo'>; | ||
readonly userData?: Pick<FootprintUserData, 'id.email' | 'id.phone_number'>; | ||
readonly variant?: 'modal' | 'drawer'; | ||
readonly authToken?: string; | ||
}; | ||
type UpdateLoginMethodsDataProps = Pick<AuthProps, 'authToken' | 'userData' | 'l10n' | 'options'>; | ||
type UpdateLoginMethodsDataProps = Pick<UpdateLoginMethodsProps, 'authToken' | 'userData' | 'l10n' | 'options'>; | ||
@@ -304,2 +305,3 @@ declare const footprint: Footprint; | ||
declare enum PublicEvent { | ||
auth = "auth", | ||
canceled = "canceled", | ||
@@ -306,0 +308,0 @@ clicked = "clicked", |
import it from '@onefootprint/postmate'; | ||
var Te=Object.defineProperty,Ue=Object.defineProperties;var Me=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var Z=(e,t,o)=>t in e?Te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,C=(e,t)=>{for(var o in t||(t={}))G.call(t,o)&&Z(e,o,t[o]);if(I)for(var o of I(t))Q.call(t,o)&&Z(e,o,t[o]);return e},_=(e,t)=>Ue(e,Me(t));var ee=(e,t)=>{var o={};for(var n in e)G.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&I)for(var n of I(e))t.indexOf(n)<0&&Q.call(e,n)&&(o[n]=e[n]);return o};var f=(e,t,o)=>new Promise((n,r)=>{var i=p=>{try{d(o.next(p));}catch(a){r(a);}},s=p=>{try{d(o.throw(p));}catch(a){r(a);}},d=p=>p.done?n(p.value):Promise.resolve(p.value).then(i,s);d((o=o.apply(e,t)).next());});var R="3.9.1";var A=(s=>(s.Auth="auth",s.Form="form",s.Render="render",s.UpdateLoginMethods="update_login_methods",s.Verify="verify",s.VerifyButton="verify-button",s))(A||{});var F=(r=>(r.canceled="canceled",r.clicked="clicked",r.closed="closed",r.completed="completed",r))(F||{}),L=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i))(L||{});var te="footprint-inline-container",oe="footprint-body-locked",ne="footprint-overlay",re="footprint-overlay-container",ie=te,ae=ne,se="footprint-loading-indicator",P=(e,t)=>`${e}-${t}`,de=e=>f(void 0,null,function*(){$(e),$e(e),yield _e(e);}),pe=e=>{let t=P(re,e),o=document.getElementById(t);if(o)return o;let n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n},_e=e=>f(void 0,null,function*(){let t=P(re,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(d=>{setTimeout(d,300);}));let r=o.querySelector("iframe.footprint-modal");r&&(r==null||r.classList.add("footprint-modal-closing"),yield new Promise(d=>{setTimeout(d,100);}));let i=P(ae,e),s=document.getElementById(i);s&&(s.classList.add("footprint-overlay-fading"),yield new Promise(d=>{setTimeout(d,200);}),o.remove(),s.remove(),document.body.classList.remove(oe));}),ce=(e,t)=>{let o=P(ie,e),n=document.createElement("div");return n.classList.add(te),n.setAttribute("id",o),t.appendChild(n),n},$e=e=>{let t=P(ie,e),o=document.getElementById(t);o&&o.remove();},$=e=>{let t=P(se,e),o=document.getElementById(t);o&&o.remove();},N=(e,t)=>{let o=P(se,t),n=Ne(o);e.appendChild(n);},le=(e,t)=>{document.body.classList.add(oe);let o=document.createElement("div"),n=P(ae,t);return o.setAttribute("id",n),o.classList.add(ne),e.appendChild(o),o},Ne=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};var je=()=>Math.random().toString(36).substring(2),x=je;var E="https://api.onefootprint.com",O=R,D="footprint-js";var K={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["update_login_methods"]:"update_auth_methods_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1"};var qe=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),j=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([n,r])=>{let i;return Array.isArray(r)?i=r.map(j(e)):Object(r)===r?i=j(e)(r):i=r,[e(n),i]});return Object.fromEntries(o)},He=j(qe),T=He;var ze=(e,t,o,n)=>{let r={tenantDomain:n,sdkKind:e,sdkName:D,sdkVersion:O,logLevel:o,logMessage:t};try{fetch(`${E}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T(r))});}catch(i){}},me=ze;var fe=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}me(e,t,"error",n);}return o};var ue={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["update_login_methods"]:{["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"]:[],["update_login_methods"]:[],["verify"]:[],["verify-button"]:[]};var ge={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["update_login_methods"]:["modal","drawer"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},We=Object.values(F),Xe=(...e)=>{},Ye=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},U=(e,t)=>{var r;if(!t)return;let o=(r=ge[e])!=null?r:[];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=ge[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},M=e=>{if(!e)throw new Error("Kind is required");let t=Object.values(A);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:o,appearance:n,variant:r,dialogVariant:i,onClick:s,label:d,containerId:p}=t,a=ee(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return _(C({},a),{variant:i,kind:"verify"})}};var Pe=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Xe,q=(e,t,o)=>{var d;let{kind:n}=e,r=(d=ue[n])!=null?d:{},i={},s=he(e);return Object.entries(r).forEach(([p,a])=>{let l=p;if(!We.includes(l))return;let h=Pe(e,a),b=l==="closed"||l==="canceled",m=n==="verify-button"&&l==="clicked";i[l]=g=>{h(g),b&&(t==null||t()),m&&s&&(o==null||o(s));};}),i},w=e=>{let{kind:t,variant:o,containerId:n}=e,r=o||V(t);return M(t),U(t,o),Ye(r,n),_(C({},e),{variant:r})};var ke=e=>e==="auth",Ze=e=>e==="verify",ve=e=>e==="update_login_methods",H=e=>[ke,Ze,ve].some(t=>t(e)),z=e=>typeof e=="string"&&e.length>0,B=e=>ke(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/tok_/.test(e.authToken),Ge=e=>ve(e.kind)&&!!e.authToken&&/tok_/.test(e.authToken),S=e=>[B,Ge].some(t=>t(e));var Qe=3,et=e=>S(e)?"update_auth_methods_v1":K[e.kind],tt=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==="update_login_methods")return {authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return B(e)?{authToken:e.authToken,updateLoginMethods:e.updateLoginMethods,userData:e.userData,options:e.options,l10n:e.l10n}:{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}},Ce=(e,t)=>f(void 0,null,function*(){return fetch(`${E}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${D} ${O} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>{if(o.ok)return o.json();if(t>0)return Ce(e,t-1)})}),ot=e=>f(void 0,null,function*(){let t=tt(e);if(!t)return;let o=yield Ce({data:T(t),kind:et(e)},Qe);return o?o.token:void 0}),Ve=ot;var nt=e=>typeof e=="object"&&!!e,be=({fontSrc:e,variables:t={},rules:o={},variant:n}={})=>{let r=()=>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:r(),rules:i(),variant:n}},we=()=>{let e=window.footprintAppearance;return !e||!nt(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var Ie=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Se=(e,t)=>{let{appearance:o,kind:n,l10n:r,variant:i}=e,{fontSrc:s,rules:d,variables:p}=be(o),a=new URLSearchParams;return p&&a.append("variables",p),d&&a.append("rules",d),s&&a.append("font_src",s),r!=null&&r.language&&a.append("lng",r.language),a.append("variant",i||V(n)),`${a.toString()}#${t}`},rt=(e,t)=>{let{kind:o}=e,n;switch(o){case"verify":n="https://id.onefootprint.com";break;case"auth":n=S(e)?"https://auth.onefootprint.com/user":"https://auth.onefootprint.com";break;default:n="https://components.onefootprint.com";}if(z(n))return H(o)?`${n}?${Se(e,t)}`.trim():`${n}/${o}?${Se(e,t)}`.trim();throw new Error(`${o}_URL environment variable is not defined.`)},Re=rt;var at=e=>{let t=null,o=!1,n,r,{formSaveComplete:i,formSaved:s,formSaveFailed:d,started:p}=L,a=w(e),{variant:l,containerId:h}=a,b=l==="modal"||l==="drawer",m=x(),g=(c,u)=>{var v;let y=fe(K[a.kind],c);(v=a.onError)==null||v.call(a,y),o&&u&&(n(),o=!1);},Oe=()=>{if(!t){g("Footprint should be initialized in order to register callback props");return}let c=q(a,n,r);Object.entries(c).forEach(([u,y])=>{t==null||t.on(u,y),t==null||t.on(`${m}:${u}`,y);});},De=()=>{if(b)return pe(m);if(!h){g("containerId is required when rendering inline");return}let c=document.getElementById(h);if(!c){g(`Could not find container with id ${h} while rendering footprint`);return}return ce(m,c)},X=(c,u)=>{if(!u){$(m),t==null||t.frame.classList.remove(`footprint-${l}-loading`),t==null||t.frame.classList.add(`footprint-${l}-loaded`);return}if(b){let y=le(c,m);N(y,m);}else N(c,m);},Y=()=>{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,v)=>{t==null||t.on(i,()=>{y();}),t==null||t.on(d,Ke=>{v(Ke);}),t==null||t.on(`${m}:${i}`,y),t==null||t.on(`${m}:${d}`,v),t==null||t.call(s);}))};(u=a.getRef)==null||u.call(a,c);};return {props:a,isRendered:o,render:()=>f(void 0,null,function*(){if(o)return;let c=De();if(!c)return;c.hasChildNodes()&&(c.innerHTML=""),o=!0,X(c,!0);let u=yield Ve(a);if(!u){g("Unable to get SDK args token.",!0);return}let y=Re(a,u||"");try{t=yield new it({classListArray:[`footprint-${l}`,`footprint-${l}-loading`],container:c,name:`footprint-iframe-${m}`,url:y,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{authToken:a.authToken,initId:m,sdkUrl:Ie(),sdkVersion:R||""}});}catch(v){g(`Initializing iframe failed with error ${v}`,!0);return}X(c,!1),Oe(),t==null||t.on(p,()=>Y()),t==null||t.on(`${m}:${p}`,Y);}),destroy:()=>f(void 0,null,function*(){o&&(o=!1,yield de(m),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(n=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(r=c);}}},J=at;var k=e=>{let t=w(e);return JSON.stringify(t)},st=()=>{let e=Object.create(null);return {getOrCreate:i=>{let s=k(i.props),d=Object.values(e).find(p=>k(p.iframe.props)===s);return d?d.iframe:(e[s]={iframe:i,secondaryIframes:{}},i)},getOrCreateSecondary:(i,s)=>{let d=k(i.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:a}=e[d],l=Object.values(a).find(h=>k(h.props)===p);return l||(a[p]=s,s)},remove:i=>{let s=k(i.props),d=e[s];d&&(Object.keys(d.secondaryIframes).forEach(p=>{d.secondaryIframes[p].destroy();}),delete e[s]);},removeSecondary:(i,s)=>{let d=k(i.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:a}=e[d],l=a[p];l&&(l.destroy(),delete a[p]);}}},Ae=st;var dt=()=>{let e=Ae();return {init:o=>{let n=J(o),r=()=>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();}),s=p=>f(void 0,null,function*(){let a=J(p);a=e.getOrCreateSecondary(n,a),a.registerOnDestroy(()=>{i(a);}),a.render();});return {render:()=>f(void 0,null,function*(){n=e.getOrCreate(n),n.registerOnDestroy(r),n.registerOnRenderSecondary(s),yield n.render();}),destroy:r}}}},pt=dt(),W=pt;var ct=e=>{window.setTimeout(e,0);},Fe=e=>typeof e=="object"&&!!e,lt=e=>{if(typeof window=="undefined")return;let t=r=>{var d;let i=(d=window.footprintCallbacks)!=null?d:{};if(!Fe(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return ye[r].forEach(p=>{if(!i[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),i},o=r=>{var m;let i=r.getAttribute("data-kind");M(i);let s=(m=r.getAttribute("data-variant"))!=null?m:V(i);U(i,s);let d=we(),p=t(i),a=r.getAttribute("data-props")||"",l;try{l=JSON.parse(a);}catch(g){throw Error("Could not parse `data-props` for footprint.")}if(!Fe(l))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let h=x();r.setAttribute("id",h),e.init(C(C({kind:i,variant:s,appearance:d,containerId:r.id},p),l)).render();},n=()=>{let r=document.querySelectorAll("[data-footprint]");r.length&&r.forEach(i=>{o(i);});};document.addEventListener("DOMContentLoaded",()=>ct(n));},Le=lt;var mt="http://test",xe=e=>f(void 0,null,function*(){let t=yield fetch(`${mt}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),ft=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 xe({identifier:{email:t}}))?!0:o?yield xe({identifier:{phone_number:o}}):!1}),Ee=ft;var To=W;Le(W); | ||
var Me=Object.defineProperty,Be=Object.defineProperties;var _e=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var Q=(e,t,o)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,C=(e,t)=>{for(var o in t||(t={}))ee.call(t,o)&&Q(e,o,t[o]);if(I)for(var o of I(t))te.call(t,o)&&Q(e,o,t[o]);return e},_=(e,t)=>Be(e,_e(t));var oe=(e,t)=>{var o={};for(var n in e)ee.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&I)for(var n of I(e))t.indexOf(n)<0&&te.call(e,n)&&(o[n]=e[n]);return o};var f=(e,t,o)=>new Promise((n,a)=>{var r=p=>{try{d(o.next(p));}catch(i){a(i);}},s=p=>{try{d(o.throw(p));}catch(i){a(i);}},d=p=>p.done?n(p.value):Promise.resolve(p.value).then(r,s);d((o=o.apply(e,t)).next());});var R="3.10.0";var x=(s=>(s.Auth="auth",s.Form="form",s.Render="render",s.UpdateLoginMethods="update_login_methods",s.Verify="verify",s.VerifyButton="verify-button",s))(x||{});var F=(r=>(r.auth="auth",r.canceled="canceled",r.clicked="clicked",r.closed="closed",r.completed="completed",r))(F||{}),L=(r=>(r.formSaveComplete="formSaveComplete",r.formSaveFailed="formSaveFailed",r.formSaved="formSaved",r.propsReceived="propsReceived",r.started="started",r))(L||{});var ne="footprint-inline-container",re="footprint-body-locked",ae="footprint-overlay",ie="footprint-overlay-container",se=ne,de=ae,pe="footprint-loading-indicator",P=(e,t)=>`${e}-${t}`,ce=e=>f(void 0,null,function*(){$(e),je(e),yield Ne(e);}),le=e=>{let t=P(ie,e),o=document.getElementById(t);if(o)return o;let n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n},Ne=e=>f(void 0,null,function*(){let t=P(ie,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(d=>{setTimeout(d,300);}));let a=o.querySelector("iframe.footprint-modal");a&&(a==null||a.classList.add("footprint-modal-closing"),yield new Promise(d=>{setTimeout(d,100);}));let r=P(de,e),s=document.getElementById(r);s&&(s.classList.add("footprint-overlay-fading"),yield new Promise(d=>{setTimeout(d,200);}),o.remove(),s.remove(),document.body.classList.remove(re));}),me=(e,t)=>{let o=P(se,e),n=document.createElement("div");return n.classList.add(ne),n.setAttribute("id",o),t.appendChild(n),n},je=e=>{let t=P(se,e),o=document.getElementById(t);o&&o.remove();},$=e=>{let t=P(pe,e),o=document.getElementById(t);o&&o.remove();},N=(e,t)=>{let o=P(pe,t),n=qe(o);e.appendChild(n);},fe=(e,t)=>{document.body.classList.add(re);let o=document.createElement("div"),n=P(de,t);return o.setAttribute("id",n),o.classList.add(ae),e.appendChild(o),o},qe=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 a=document.createElementNS("http://www.w3.org/2000/svg","path");return a.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(a),o.appendChild(n),t.appendChild(o),t};var He=()=>Math.random().toString(36).substring(2),E=He;var K="https://api.onefootprint.com",O=R,D="footprint-js";var V={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["update_login_methods"]:"update_auth_methods_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1"};var ze=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),j=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([n,a])=>{let r;return Array.isArray(a)?r=a.map(j(e)):Object(a)===a?r=j(e)(a):r=a,[e(n),r]});return Object.fromEntries(o)},Je=j(ze),T=Je;var We=(e,t,o,n)=>{let a={tenantDomain:n,sdkKind:e,sdkName:D,sdkVersion:O,logLevel:o,logMessage:t};try{fetch(`${K}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T(a))});}catch(r){}},q=We;var H=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(a){}q(e,t,"warn",n);}return o},ue=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(a){}q(e,t,"error",n);}return o};var ge={["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"},["verify-button"]:{["auth"]:"onAuth",["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},he={["auth"]:[],["form"]:[],["render"]:[],["update_login_methods"]:[],["verify"]:[],["verify-button"]:[]};var Pe={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["update_login_methods"]:["modal","drawer"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},Xe=Object.values(F),Ye=(...e)=>{},Ze=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},U=(e,t)=>{var a;if(!t)return;let o=(a=Pe[e])!=null?a:[];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=Pe[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},M=e=>{if(!e)throw new Error("Kind is required");let t=Object.values(x);if(!t.includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${t.join(", ")}`)},ke=e=>{if(e.kind==="verify-button"){let t=e,{kind:o,appearance:n,variant:a,dialogVariant:r,onClick:s,label:d,containerId:p}=t,i=oe(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return _(C({},i),{variant:r,kind:"verify"})}};var ve=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Ye,z=(e,t,o)=>{var d;let{kind:n}=e,a=(d=ge[n])!=null?d:{},r={},s=ke(e);return Object.entries(a).forEach(([p,i])=>{let l=p;if(!Xe.includes(l))return;let h=ve(e,i),w=l==="closed"||l==="canceled",m=n==="verify-button"&&l==="clicked";r[l]=g=>{h(g),w&&(t==null||t()),m&&s&&(o==null||o(s));};}),r},S=e=>{let{kind:t,variant:o,containerId:n}=e,a=o||b(t);return M(t),U(t,o),Ze(a,n),_(C({},e),{variant:a})};var Ce=e=>e==="auth",Ge=e=>e==="verify",Ve=e=>e==="update_login_methods",J=e=>[Ce,Ge,Ve].some(t=>t(e)),W=e=>typeof e=="string"&&e.length>0,B=e=>Ce(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/tok_/.test(e.authToken),Qe=e=>Ve(e.kind)&&!!e.authToken&&/tok_/.test(e.authToken),A=e=>[B,Qe].some(t=>t(e));var et=3,tt=e=>A(e)?"update_auth_methods_v1":V[e.kind],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==="update_login_methods")return {authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return B(e)?{authToken:e.authToken,updateLoginMethods:e.updateLoginMethods,userData:e.userData,options:e.options,l10n:e.l10n}:{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}},be=(e,t)=>f(void 0,null,function*(){return fetch(`${K}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${D} ${O} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>{if(o.ok)return o.json();if(t>0)return be(e,t-1)})}),nt=e=>f(void 0,null,function*(){let t=ot(e);if(!t)return;let o=yield be({data:T(t),kind:tt(e)},et);return o?o.token:void 0}),we=nt;var rt=e=>typeof e=="object"&&!!e,Se=({fontSrc:e,variables:t={},rules:o={},variant:n}={})=>{let a=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,r=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0;return {fontSrc:e,variables:a(),rules:r(),variant:n}},Ae=()=>{let e=window.footprintAppearance;return !e||!rt(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var Re=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Ie=(e,t)=>{let{appearance:o,kind:n,l10n:a,variant:r}=e,{fontSrc:s,rules:d,variables:p}=Se(o),i=new URLSearchParams;return p&&i.append("variables",p),d&&i.append("rules",d),s&&i.append("font_src",s),a!=null&&a.language&&i.append("lng",a.language),i.append("variant",r||b(n)),`${i.toString()}#${t}`},at=(e,t)=>{let{kind:o}=e,n;switch(o){case"verify":n="https://id.onefootprint.com";break;case"auth":n=A(e)?"https://auth.onefootprint.com/user":"https://auth.onefootprint.com";break;default:n="https://components.onefootprint.com";}if(W(n))return J(o)?`${n}?${Ie(e,t)}`.trim():`${n}/${o}?${Ie(e,t)}`.trim();throw new Error(`${o}_URL environment variable is not defined.`)},xe=at;var st=e=>{let t=null,o=!1,n,a,{formSaveComplete:r,formSaved:s,formSaveFailed:d,started:p}=L,i=S(e),{variant:l,containerId:h}=i,w=l==="modal"||l==="drawer",m=E(),g=(c,y)=>{var v;let u=ue(V[i.kind],c);(v=i.onError)==null||v.call(i,u),o&&y&&(n(),o=!1);},De=()=>{if(!t){g("Footprint should be initialized in order to register callback props");return}let c=z(i,n,a);Object.entries(c).forEach(([y,u])=>{t==null||t.on(y,u),t==null||t.on(`${m}:${y}`,u);});},Te=()=>{if(w)return le(m);if(!h){g("containerId is required when rendering inline");return}let c=document.getElementById(h);if(!c){g(`Could not find container with id ${h} while rendering footprint`);return}return me(m,c)},Z=(c,y)=>{if(!y){$(m),t==null||t.frame.classList.remove(`footprint-${l}-loading`),t==null||t.frame.classList.add(`footprint-${l}-loaded`);return}if(w){let u=fe(c,m);N(u,m);}else N(c,m);},G=()=>{var y;if(!t){g("Footprint should be initialized in order to set up refs");return}if(i.kind!=="form"||!i.getRef)return;let c={save:()=>(t||g("Footprint should be initialized to call ref methods"),new Promise((u,v)=>{t==null||t.on(r,()=>{u();}),t==null||t.on(d,Ue=>{v(Ue);}),t==null||t.on(`${m}:${r}`,u),t==null||t.on(`${m}:${d}`,v),t==null||t.call(s);}))};(y=i.getRef)==null||y.call(i,c);};return {props:i,isRendered:o,render:()=>f(void 0,null,function*(){if(o){H(V[i.kind],"Footprint component is already rendered");return}let c=Te();if(!c){H(V[i.kind],"Unable to create container for Footprint component");return}c.hasChildNodes()&&(c.innerHTML=""),o=!0,Z(c,!0);let y=yield we(i);if(!y){g("Unable to get SDK args token.",!0);return}let u=xe(i,y||"");try{t=yield new it({classListArray:[`footprint-${l}`,`footprint-${l}-loading`],container:c,name:`footprint-iframe-${m}`,url:u,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{authToken:i.authToken,initId:m,sdkUrl:Re(),sdkVersion:R||""}});}catch(v){g(`Initializing iframe failed with error ${v}`,!0);return}Z(c,!1),De(),t==null||t.on(p,()=>G()),t==null||t.on(`${m}:${p}`,G);}),destroy:()=>f(void 0,null,function*(){o&&(o=!1,yield ce(m),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(n=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(a=c);}}},X=st;var k=e=>{let t=S(e);return JSON.stringify(t)},dt=()=>{let e=Object.create(null);return {getOrCreate:r=>{let s=k(r.props),d=Object.values(e).find(p=>k(p.iframe.props)===s);return d?d.iframe:(e[s]={iframe:r,secondaryIframes:{}},r)},getOrCreateSecondary:(r,s)=>{let d=k(r.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:i}=e[d],l=Object.values(i).find(h=>k(h.props)===p);return l||(i[p]=s,s)},remove:r=>{let s=k(r.props),d=e[s];d&&(Object.keys(d.secondaryIframes).forEach(p=>{d.secondaryIframes[p].destroy();}),delete e[s]);},removeSecondary:(r,s)=>{let d=k(r.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:i}=e[d],l=i[p];l&&(l.destroy(),delete i[p]);}}},Fe=dt;var pt=()=>{let e=Fe();return {init:o=>{let n=X(o),a=()=>f(void 0,null,function*(){e.remove(n),yield n.destroy();}),r=p=>f(void 0,null,function*(){e.removeSecondary(n,p),yield p.destroy();}),s=p=>f(void 0,null,function*(){let i=X(p);i=e.getOrCreateSecondary(n,i),i.registerOnDestroy(()=>{r(i);}),i.render();});return {render:()=>f(void 0,null,function*(){n=e.getOrCreate(n),n.registerOnDestroy(a),n.registerOnRenderSecondary(s),yield n.render();}),destroy:a}}}},ct=pt(),Y=ct;var lt=e=>{window.setTimeout(e,0);},Le=e=>typeof e=="object"&&!!e,mt=e=>{if(typeof window=="undefined")return;let t=a=>{var d;let r=(d=window.footprintCallbacks)!=null?d:{};if(!Le(r))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return he[a].forEach(p=>{if(!r[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),r},o=a=>{var m;let r=a.getAttribute("data-kind");M(r);let s=(m=a.getAttribute("data-variant"))!=null?m:b(r);U(r,s);let d=Ae(),p=t(r),i=a.getAttribute("data-props")||"",l;try{l=JSON.parse(i);}catch(g){throw Error("Could not parse `data-props` for footprint.")}if(!Le(l))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let h=E();a.setAttribute("id",h),e.init(C(C({kind:r,variant:s,appearance:d,containerId:a.id},p),l)).render();},n=()=>{let a=document.querySelectorAll("[data-footprint]");a.length&&a.forEach(r=>{o(r);});};document.addEventListener("DOMContentLoaded",()=>lt(n));},Ee=mt;var ft="http://test",Ke=e=>f(void 0,null,function*(){let t=yield fetch(`${ft}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),yt=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 Ke({identifier:{email:t}}))?!0:o?yield Ke({identifier:{phone_number:o}}):!1}),Oe=yt;var Uo=Y;Ee(Y); | ||
export { A as FootprintComponentKind, L as FootprintPrivateEvent, F as FootprintPublicEvent, To as default, Ee as identifyFootprintUser }; | ||
export { x as FootprintComponentKind, L as FootprintPrivateEvent, F as FootprintPublicEvent, Uo as default, Oe as identifyFootprintUser }; |
(function (exports) { | ||
'use strict'; | ||
var Ne=Object.defineProperty,Be=Object.defineProperties;var $e=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var ee=(e,t,o)=>t in e?Ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,b=(e,t)=>{for(var o in t||(t={}))te.call(t,o)&&ee(e,o,t[o]);if(I)for(var o of I(t))oe.call(t,o)&&ee(e,o,t[o]);return e},$=(e,t)=>Be(e,$e(t));var ne=(e,t)=>{var o={};for(var n in e)te.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&I)for(var n of I(e))t.indexOf(n)<0&&oe.call(e,n)&&(o[n]=e[n]);return o};var m=(e,t,o)=>new Promise((n,r)=>{var i=p=>{try{d(o.next(p));}catch(a){r(a);}},s=p=>{try{d(o.throw(p));}catch(a){r(a);}},d=p=>p.done?n(p.value):Promise.resolve(p.value).then(i,s);d((o=o.apply(e,t)).next());});var V="application/x-postmate-v1+json",je=5,He=0,qe=function(){return ++He};var ze=function(t){var o=document.createElement("a");o.href=t;var n=o.protocol.length>4?o.protocol:window.location.protocol,r=o.host.length?o.port==="80"||o.port==="443"?o.hostname:o.host:window.location.host;return o.origin||n+"//"+r},Je={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},j=function(t,o){return !(typeof o=="string"&&t.origin!==o||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==V||!Je[t.data.postmate])},We=function(t,o){var n=typeof t[o]=="function"?t[o]():t[o];return w.Promise.resolve(n)},Xe=function(){function e(o){var n=this;this.parent=o.parent,this.frame=o.frame,this.child=o.child,this.childOrigin=o.childOrigin,this.events={},this.listener=function(r){if(!j(r,n.childOrigin))return !1;var i=((r||{}).data||{}).value||{},s=i.data,d=i.name;r.data.postmate==="emit"&&d in n.events&&n.events[d].forEach(function(p){p.call(n,s);});},this.parent.addEventListener("message",this.listener,!1);}var t=e.prototype;return t.get=function(n){var r=this;return new w.Promise(function(i){var s=qe(),d=function p(a){a.data.uid===s&&a.data.postmate==="reply"&&(r.parent.removeEventListener("message",p,!1),i(a.data.value));};r.parent.addEventListener("message",d,!1),r.child.postMessage({postmate:"request",type:V,property:n,uid:s},r.childOrigin);})},t.call=function(n,r){this.child.postMessage({postmate:"call",type:V,property:n,data:r},this.childOrigin);},t.on=function(n,r){this.events[n]||(this.events[n]=[]),this.events[n].push(r);},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),Ye=function(){function e(o){var n=this;this.model=o.model,this.parent=o.parent,this.parentOrigin=o.parentOrigin,this.child=o.child,this.child.addEventListener("message",function(r){if(j(r,n.parentOrigin)){var i=r.data,s=i.property,d=i.uid,p=i.data;if(r.data.postmate==="call"){s in n.model&&typeof n.model[s]=="function"&&n.model[s](p);return}We(n.model,s).then(function(a){return r.source.postMessage({property:s,postmate:"reply",type:V,uid:d,value:a},r.origin)});}});}var t=e.prototype;return t.emit=function(n,r){this.parent.postMessage({postmate:"emit",type:V,value:{name:n,data:r}},this.parentOrigin);},e}(),w=function(){function e(o){var n=o.container,r=n===void 0?typeof r!="undefined"?r:document.body:n,i=o.model,s=o.url,d=o.name,p=d===void 0?"":d,a=o.allow,c=o.classListArray,u=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,u),a&&(this.frame.allow=a),r.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(s)}var t=e.prototype;return t.sendHandshake=function(n){var r=this,i=ze(n),s=0,d;return new e.Promise(function(p,a){var c=function f(y){return j(y,i)?y.data.postmate==="handshake-reply"?(clearInterval(d),r.parent.removeEventListener("message",f,!1),r.childOrigin=y.origin,p(new Xe(r))):a("Failed handshake"):!1};r.parent.addEventListener("message",c,!1);var u=function(){s++,r.child.postMessage({postmate:"handshake",type:V,model:r.model},i),s===je&&clearInterval(d);},v=function(){u(),d=setInterval(u,500);};r.frame.attachEvent?r.frame.attachEvent("onload",v):r.frame.addEventListener("load",v),r.frame.src=n;})},e}();w.debug=!1;w.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();w.Model=function(){function e(o){return this.child=window,this.model=o,this.parent=this.child.parent,this.sendHandshakeReply()}var t=e.prototype;return t.sendHandshakeReply=function(){var n=this;return new w.Promise(function(r,i){var s=function d(p){if(p.data.postmate){if(p.data.postmate==="handshake"){n.child.removeEventListener("message",d,!1),p.source.postMessage({postmate:"handshake-reply",type:V},p.origin),n.parentOrigin=p.origin;var a=p.data.model;return a&&Object.keys(a).forEach(function(c){n.model[c]=a[c];}),r(new Ye(n))}return i("Handshake Reply Failed")}};n.child.addEventListener("message",s,!1);})},e}();var re=w;var L="3.9.1";var R=(s=>(s.Auth="auth",s.Form="form",s.Render="render",s.UpdateLoginMethods="update_login_methods",s.Verify="verify",s.VerifyButton="verify-button",s))(R||{});var A=(r=>(r.canceled="canceled",r.clicked="clicked",r.closed="closed",r.completed="completed",r))(A||{}),D=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i))(D||{});var ie="footprint-inline-container",ae="footprint-body-locked",se="footprint-overlay",de="footprint-overlay-container",pe=ie,ce=se,le="footprint-loading-indicator",P=(e,t)=>`${e}-${t}`,fe=e=>m(void 0,null,function*(){H(e),Qe(e),yield Ge(e);}),me=e=>{let t=P(de,e),o=document.getElementById(t);if(o)return o;let n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n},Ge=e=>m(void 0,null,function*(){let t=P(de,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(d=>{setTimeout(d,300);}));let r=o.querySelector("iframe.footprint-modal");r&&(r==null||r.classList.add("footprint-modal-closing"),yield new Promise(d=>{setTimeout(d,100);}));let i=P(ce,e),s=document.getElementById(i);s&&(s.classList.add("footprint-overlay-fading"),yield new Promise(d=>{setTimeout(d,200);}),o.remove(),s.remove(),document.body.classList.remove(ae));}),ue=(e,t)=>{let o=P(pe,e),n=document.createElement("div");return n.classList.add(ie),n.setAttribute("id",o),t.appendChild(n),n},Qe=e=>{let t=P(pe,e),o=document.getElementById(t);o&&o.remove();},H=e=>{let t=P(le,e),o=document.getElementById(t);o&&o.remove();},q=(e,t)=>{let o=P(le,t),n=et(o);e.appendChild(n);},ye=(e,t)=>{document.body.classList.add(ae);let o=document.createElement("div"),n=P(ce,t);return o.setAttribute("id",n),o.classList.add(se),e.appendChild(o),o},et=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};var tt=()=>Math.random().toString(36).substring(2),x=tt;var F="https://api.onefootprint.com",K=L,_="footprint-js";var T={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["update_login_methods"]:"update_auth_methods_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1"};var ot=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),z=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([n,r])=>{let i;return Array.isArray(r)?i=r.map(z(e)):Object(r)===r?i=z(e)(r):i=r,[e(n),i]});return Object.fromEntries(o)},nt=z(ot),M=nt;var rt=(e,t,o,n)=>{let r={tenantDomain:n,sdkKind:e,sdkName:_,sdkVersion:K,logLevel:o,logMessage:t};try{fetch(`${F}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M(r))});}catch(i){}},ge=rt;var he=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}ge(e,t,"error",n);}return o};var ve={["auth"]:{["canceled"]:"onCancel",["closed"]:"onClose",["completed"]:"onComplete"},["update_login_methods"]:{["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"]:{}},Pe={["auth"]:[],["form"]:[],["render"]:[],["update_login_methods"]:[],["verify"]:[],["verify-button"]:[]};var ke={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["update_login_methods"]:["modal","drawer"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},at=Object.values(A),st=(...e)=>{},dt=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},U=(e,t)=>{var r;if(!t)return;let o=(r=ke[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=ke[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},N=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(", ")}`)},Ce=e=>{if(e.kind==="verify-button"){let t=e,{kind:o,appearance:n,variant:r,dialogVariant:i,onClick:s,label:d,containerId:p}=t,a=ne(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)||st,J=(e,t,o)=>{var d;let{kind:n}=e,r=(d=ve[n])!=null?d:{},i={},s=Ce(e);return Object.entries(r).forEach(([p,a])=>{let c=p;if(!at.includes(c))return;let u=Ve(e,a),v=c==="closed"||c==="canceled",f=n==="verify-button"&&c==="clicked";i[c]=y=>{u(y),v&&(t==null||t()),f&&s&&(o==null||o(s));};}),i},O=e=>{let{kind:t,variant:o,containerId:n}=e,r=o||E(t);return N(t),U(t,o),dt(r,n),$(b({},e),{variant:r})};var we=e=>e==="auth",pt=e=>e==="verify",be=e=>e==="update_login_methods",W=e=>[we,pt,be].some(t=>t(e)),X=e=>typeof e=="string"&&e.length>0,B=e=>we(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/tok_/.test(e.authToken),ct=e=>be(e.kind)&&!!e.authToken&&/tok_/.test(e.authToken),S=e=>[B,ct].some(t=>t(e));var lt=3,ft=e=>S(e)?"update_auth_methods_v1":T[e.kind],mt=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==="update_login_methods")return {authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return B(e)?{authToken:e.authToken,updateLoginMethods:e.updateLoginMethods,userData:e.userData,options:e.options,l10n:e.l10n}:{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}},Ee=(e,t)=>m(void 0,null,function*(){return fetch(`${F}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${_} ${K} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>{if(o.ok)return o.json();if(t>0)return Ee(e,t-1)})}),ut=e=>m(void 0,null,function*(){let t=mt(e);if(!t)return;let o=yield Ee({data:M(t),kind:ft(e)},lt);return o?o.token:void 0}),Oe=ut;var yt=e=>typeof e=="object"&&!!e,Se=({fontSrc:e,variables:t={},rules:o={},variant:n}={})=>{let r=()=>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:r(),rules:i(),variant:n}},Ie=()=>{let e=window.footprintAppearance;return !e||!yt(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var Re=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Le=(e,t)=>{let{appearance:o,kind:n,l10n:r,variant:i}=e,{fontSrc:s,rules:d,variables:p}=Se(o),a=new URLSearchParams;return p&&a.append("variables",p),d&&a.append("rules",d),s&&a.append("font_src",s),r!=null&&r.language&&a.append("lng",r.language),a.append("variant",i||E(n)),`${a.toString()}#${t}`},gt=(e,t)=>{let{kind:o}=e,n;switch(o){case"verify":n="https://id.onefootprint.com";break;case"auth":n=S(e)?"https://auth.onefootprint.com/user":"https://auth.onefootprint.com";break;default:n="https://components.onefootprint.com";}if(X(n))return W(o)?`${n}?${Le(e,t)}`.trim():`${n}/${o}?${Le(e,t)}`.trim();throw new Error(`${o}_URL environment variable is not defined.`)},Ae=gt;var ht=e=>{let t=null,o=!1,n,r,{formSaveComplete:i,formSaved:s,formSaveFailed:d,started:p}=D,a=O(e),{variant:c,containerId:u}=a,v=c==="modal"||c==="drawer",f=x(),y=(l,g)=>{var C;let h=he(T[a.kind],l);(C=a.onError)==null||C.call(a,h),o&&g&&(n(),o=!1);},Te=()=>{if(!t){y("Footprint should be initialized in order to register callback props");return}let l=J(a,n,r);Object.entries(l).forEach(([g,h])=>{t==null||t.on(g,h),t==null||t.on(`${f}:${g}`,h);});},Me=()=>{if(v)return me(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 ue(f,l)},G=(l,g)=>{if(!g){H(f),t==null||t.frame.classList.remove(`footprint-${c}-loading`),t==null||t.frame.classList.add(`footprint-${c}-loaded`);return}if(v){let h=ye(l,f);q(h,f);}else q(l,f);},Q=()=>{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(d,Ue=>{C(Ue);}),t==null||t.on(`${f}:${i}`,h),t==null||t.on(`${f}:${d}`,C),t==null||t.call(s);}))};(g=a.getRef)==null||g.call(a,l);};return {props:a,isRendered:o,render:()=>m(void 0,null,function*(){if(o)return;let l=Me();if(!l)return;l.hasChildNodes()&&(l.innerHTML=""),o=!0,G(l,!0);let g=yield Oe(a);if(!g){y("Unable to get SDK args token.",!0);return}let h=Ae(a,g||"");try{t=yield new re({classListArray:[`footprint-${c}`,`footprint-${c}-loading`],container:l,name:`footprint-iframe-${f}`,url:h,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{authToken:a.authToken,initId:f,sdkUrl:Re(),sdkVersion:L||""}});}catch(C){y(`Initializing iframe failed with error ${C}`,!0);return}G(l,!1),Te(),t==null||t.on(p,()=>Q()),t==null||t.on(`${f}:${p}`,Q);}),destroy:()=>m(void 0,null,function*(){o&&(o=!1,yield fe(f),t&&(t.destroy(),t=null));}),registerOnDestroy:l=>{!l||typeof l!="function"||(n=l);},registerOnRenderSecondary:l=>{!l||typeof l!="function"||(r=l);}}},Y=ht;var k=e=>{let t=O(e);return JSON.stringify(t)},vt=()=>{let e=Object.create(null);return {getOrCreate:i=>{let s=k(i.props),d=Object.values(e).find(p=>k(p.iframe.props)===s);return d?d.iframe:(e[s]={iframe:i,secondaryIframes:{}},i)},getOrCreateSecondary:(i,s)=>{let d=k(i.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:a}=e[d],c=Object.values(a).find(u=>k(u.props)===p);return c||(a[p]=s,s)},remove:i=>{let s=k(i.props),d=e[s];d&&(Object.keys(d.secondaryIframes).forEach(p=>{d.secondaryIframes[p].destroy();}),delete e[s]);},removeSecondary:(i,s)=>{let d=k(i.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:a}=e[d],c=a[p];c&&(c.destroy(),delete a[p]);}}},De=vt;var Pt=()=>{let e=De();return {init:o=>{let n=Y(o),r=()=>m(void 0,null,function*(){e.remove(n),yield n.destroy();}),i=p=>m(void 0,null,function*(){e.removeSecondary(n,p),yield p.destroy();}),s=p=>m(void 0,null,function*(){let a=Y(p);a=e.getOrCreateSecondary(n,a),a.registerOnDestroy(()=>{i(a);}),a.render();});return {render:()=>m(void 0,null,function*(){n=e.getOrCreate(n),n.registerOnDestroy(r),n.registerOnRenderSecondary(s),yield n.render();}),destroy:r}}}},kt=Pt(),Z=kt;var Ct=e=>{window.setTimeout(e,0);},xe=e=>typeof e=="object"&&!!e,Vt=e=>{if(typeof window=="undefined")return;let t=r=>{var d;let i=(d=window.footprintCallbacks)!=null?d:{};if(!xe(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return Pe[r].forEach(p=>{if(!i[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),i},o=r=>{var f;let i=r.getAttribute("data-kind");N(i);let s=(f=r.getAttribute("data-variant"))!=null?f:E(i);U(i,s);let d=Ie(),p=t(i),a=r.getAttribute("data-props")||"",c;try{c=JSON.parse(a);}catch(y){throw Error("Could not parse `data-props` for footprint.")}if(!xe(c))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let u=x();r.setAttribute("id",u),e.init(b(b({kind:i,variant:s,appearance:d,containerId:r.id},p),c)).render();},n=()=>{let r=document.querySelectorAll("[data-footprint]");r.length&&r.forEach(i=>{o(i);});};document.addEventListener("DOMContentLoaded",()=>Ct(n));},Fe=Vt;var wt="http://test",Ke=e=>m(void 0,null,function*(){let t=yield fetch(`${wt}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),bt=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 Ke({identifier:{email:t}}))?!0:o?yield Ke({identifier:{phone_number:o}}):!1}),_e=bt;var Wo=Z;Fe(Z);/*! Bundled license information: | ||
var $e=Object.defineProperty,je=Object.defineProperties;var He=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var oe=(e,t,o)=>t in e?$e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,b=(e,t)=>{for(var o in t||(t={}))ne.call(t,o)&&oe(e,o,t[o]);if(A)for(var o of A(t))re.call(t,o)&&oe(e,o,t[o]);return e},$=(e,t)=>je(e,He(t));var ae=(e,t)=>{var o={};for(var n in e)ne.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&A)for(var n of A(e))t.indexOf(n)<0&&re.call(e,n)&&(o[n]=e[n]);return o};var m=(e,t,o)=>new Promise((n,r)=>{var a=p=>{try{d(o.next(p));}catch(i){r(i);}},s=p=>{try{d(o.throw(p));}catch(i){r(i);}},d=p=>p.done?n(p.value):Promise.resolve(p.value).then(a,s);d((o=o.apply(e,t)).next());});var V="application/x-postmate-v1+json",qe=5,ze=0,We=function(){return ++ze};var Je=function(t){var o=document.createElement("a");o.href=t;var n=o.protocol.length>4?o.protocol:window.location.protocol,r=o.host.length?o.port==="80"||o.port==="443"?o.hostname:o.host:window.location.host;return o.origin||n+"//"+r},Xe={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},j=function(t,o){return !(typeof o=="string"&&t.origin!==o||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==V||!Xe[t.data.postmate])},Ye=function(t,o){var n=typeof t[o]=="function"?t[o]():t[o];return w.Promise.resolve(n)},Ze=function(){function e(o){var n=this;this.parent=o.parent,this.frame=o.frame,this.child=o.child,this.childOrigin=o.childOrigin,this.events={},this.listener=function(r){if(!j(r,n.childOrigin))return !1;var a=((r||{}).data||{}).value||{},s=a.data,d=a.name;r.data.postmate==="emit"&&d in n.events&&n.events[d].forEach(function(p){p.call(n,s);});},this.parent.addEventListener("message",this.listener,!1);}var t=e.prototype;return t.get=function(n){var r=this;return new w.Promise(function(a){var s=We(),d=function p(i){i.data.uid===s&&i.data.postmate==="reply"&&(r.parent.removeEventListener("message",p,!1),a(i.data.value));};r.parent.addEventListener("message",d,!1),r.child.postMessage({postmate:"request",type:V,property:n,uid:s},r.childOrigin);})},t.call=function(n,r){this.child.postMessage({postmate:"call",type:V,property:n,data:r},this.childOrigin);},t.on=function(n,r){this.events[n]||(this.events[n]=[]),this.events[n].push(r);},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),Ge=function(){function e(o){var n=this;this.model=o.model,this.parent=o.parent,this.parentOrigin=o.parentOrigin,this.child=o.child,this.child.addEventListener("message",function(r){if(j(r,n.parentOrigin)){var a=r.data,s=a.property,d=a.uid,p=a.data;if(r.data.postmate==="call"){s in n.model&&typeof n.model[s]=="function"&&n.model[s](p);return}Ye(n.model,s).then(function(i){return r.source.postMessage({property:s,postmate:"reply",type:V,uid:d,value:i},r.origin)});}});}var t=e.prototype;return t.emit=function(n,r){this.parent.postMessage({postmate:"emit",type:V,value:{name:n,data:r}},this.parentOrigin);},e}(),w=function(){function e(o){var n=o.container,r=n===void 0?typeof r!="undefined"?r:document.body:n,a=o.model,s=o.url,d=o.name,p=d===void 0?"":d,i=o.allow,l=o.classListArray,u=l===void 0?[]:l;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=p||"",this.frame.classList.add.apply(this.frame.classList,u),i&&(this.frame.allow=i),r.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(s)}var t=e.prototype;return t.sendHandshake=function(n){var r=this,a=Je(n),s=0,d;return new e.Promise(function(p,i){var l=function f(y){return j(y,a)?y.data.postmate==="handshake-reply"?(clearInterval(d),r.parent.removeEventListener("message",f,!1),r.childOrigin=y.origin,p(new Ze(r))):i("Failed handshake"):!1};r.parent.addEventListener("message",l,!1);var u=function(){s++,r.child.postMessage({postmate:"handshake",type:V,model:r.model},a),s===qe&&clearInterval(d);},v=function(){u(),d=setInterval(u,500);};r.frame.attachEvent?r.frame.attachEvent("onload",v):r.frame.addEventListener("load",v),r.frame.src=n;})},e}();w.debug=!1;w.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();w.Model=function(){function e(o){return this.child=window,this.model=o,this.parent=this.child.parent,this.sendHandshakeReply()}var t=e.prototype;return t.sendHandshakeReply=function(){var n=this;return new w.Promise(function(r,a){var s=function d(p){if(p.data.postmate){if(p.data.postmate==="handshake"){n.child.removeEventListener("message",d,!1),p.source.postMessage({postmate:"handshake-reply",type:V},p.origin),n.parentOrigin=p.origin;var i=p.data.model;return i&&Object.keys(i).forEach(function(l){n.model[l]=i[l];}),r(new Ge(n))}return a("Handshake Reply Failed")}};n.child.addEventListener("message",s,!1);})},e}();var ie=w;var L="3.10.0";var R=(s=>(s.Auth="auth",s.Form="form",s.Render="render",s.UpdateLoginMethods="update_login_methods",s.Verify="verify",s.VerifyButton="verify-button",s))(R||{});var D=(a=>(a.auth="auth",a.canceled="canceled",a.clicked="clicked",a.closed="closed",a.completed="completed",a))(D||{}),x=(a=>(a.formSaveComplete="formSaveComplete",a.formSaveFailed="formSaveFailed",a.formSaved="formSaved",a.propsReceived="propsReceived",a.started="started",a))(x||{});var se="footprint-inline-container",de="footprint-body-locked",pe="footprint-overlay",le="footprint-overlay-container",ce=se,fe=pe,me="footprint-loading-indicator",P=(e,t)=>`${e}-${t}`,ue=e=>m(void 0,null,function*(){H(e),tt(e),yield et(e);}),ye=e=>{let t=P(le,e),o=document.getElementById(t);if(o)return o;let n=document.createElement("div");return n.setAttribute("id",t),document.body.appendChild(n),n},et=e=>m(void 0,null,function*(){let t=P(le,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(d=>{setTimeout(d,300);}));let r=o.querySelector("iframe.footprint-modal");r&&(r==null||r.classList.add("footprint-modal-closing"),yield new Promise(d=>{setTimeout(d,100);}));let a=P(fe,e),s=document.getElementById(a);s&&(s.classList.add("footprint-overlay-fading"),yield new Promise(d=>{setTimeout(d,200);}),o.remove(),s.remove(),document.body.classList.remove(de));}),ge=(e,t)=>{let o=P(ce,e),n=document.createElement("div");return n.classList.add(se),n.setAttribute("id",o),t.appendChild(n),n},tt=e=>{let t=P(ce,e),o=document.getElementById(t);o&&o.remove();},H=e=>{let t=P(me,e),o=document.getElementById(t);o&&o.remove();},q=(e,t)=>{let o=P(me,t),n=ot(o);e.appendChild(n);},he=(e,t)=>{document.body.classList.add(de);let o=document.createElement("div"),n=P(fe,t);return o.setAttribute("id",n),o.classList.add(pe),e.appendChild(o),o},ot=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};var nt=()=>Math.random().toString(36).substring(2),F=nt;var K="https://api.onefootprint.com",_=L,T="footprint-js";var E={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["update_login_methods"]:"update_auth_methods_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1"};var rt=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),z=e=>t=>{if(!t||typeof t!="object")return t;let o=Object.entries(t).map(([n,r])=>{let a;return Array.isArray(r)?a=r.map(z(e)):Object(r)===r?a=z(e)(r):a=r,[e(n),a]});return Object.fromEntries(o)},at=z(rt),M=at;var it=(e,t,o,n)=>{let r={tenantDomain:n,sdkKind:e,sdkName:T,sdkVersion:_,logLevel:o,logMessage:t};try{fetch(`${K}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M(r))});}catch(a){}},W=it;var J=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}W(e,t,"warn",n);}return o},Pe=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let n;try{n=window.location.href;}catch(r){}W(e,t,"error",n);}return o};var ke={["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"},["verify-button"]:{["auth"]:"onAuth",["canceled"]:"onCancel",["clicked"]:"onClick",["closed"]:"onClose",["completed"]:"onComplete"},["render"]:{}},Ce={["auth"]:[],["form"]:[],["render"]:[],["update_login_methods"]:[],["verify"]:[],["verify-button"]:[]};var Ve={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["update_login_methods"]:["modal","drawer"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},st=Object.values(D),dt=(...e)=>{},pt=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},U=(e,t)=>{var r;if(!t)return;let o=(r=Ve[e])!=null?r:[];if(!o.includes(t))throw new Error(`Invalid variant: ${JSON.stringify(t)}. Valid variants for ${e} are ${o.join(", ")}`)},O=e=>{var o;let t=(o=Ve[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},N=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(", ")}`)},we=e=>{if(e.kind==="verify-button"){let t=e,{kind:o,appearance:n,variant:r,dialogVariant:a,onClick:s,label:d,containerId:p}=t,i=ae(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return $(b({},i),{variant:a,kind:"verify"})}};var be=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||dt,X=(e,t,o)=>{var d;let{kind:n}=e,r=(d=ke[n])!=null?d:{},a={},s=we(e);return Object.entries(r).forEach(([p,i])=>{let l=p;if(!st.includes(l))return;let u=be(e,i),v=l==="closed"||l==="canceled",f=n==="verify-button"&&l==="clicked";a[l]=y=>{u(y),v&&(t==null||t()),f&&s&&(o==null||o(s));};}),a},S=e=>{let{kind:t,variant:o,containerId:n}=e,r=o||O(t);return N(t),U(t,o),pt(r,n),$(b({},e),{variant:r})};var Ee=e=>e==="auth",lt=e=>e==="verify",Oe=e=>e==="update_login_methods",Y=e=>[Ee,lt,Oe].some(t=>t(e)),Z=e=>typeof e=="string"&&e.length>0,B=e=>Ee(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/tok_/.test(e.authToken),ct=e=>Oe(e.kind)&&!!e.authToken&&/tok_/.test(e.authToken),I=e=>[B,ct].some(t=>t(e));var ft=3,mt=e=>I(e)?"update_auth_methods_v1":E[e.kind],ut=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==="update_login_methods")return {authToken:e.authToken,userData:e.userData,options:e.options,l10n:e.l10n};if(t==="auth")return B(e)?{authToken:e.authToken,updateLoginMethods:e.updateLoginMethods,userData:e.userData,options:e.options,l10n:e.l10n}:{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}},Se=(e,t)=>m(void 0,null,function*(){return fetch(`${K}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${T} ${_} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>{if(o.ok)return o.json();if(t>0)return Se(e,t-1)})}),yt=e=>m(void 0,null,function*(){let t=ut(e);if(!t)return;let o=yield Se({data:M(t),kind:mt(e)},ft);return o?o.token:void 0}),Ie=yt;var gt=e=>typeof e=="object"&&!!e,Ae=({fontSrc:e,variables:t={},rules:o={},variant:n}={})=>{let r=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0,a=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0;return {fontSrc:e,variables:r(),rules:a(),variant:n}},Le=()=>{let e=window.footprintAppearance;return !e||!gt(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var De=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},Re=(e,t)=>{let{appearance:o,kind:n,l10n:r,variant:a}=e,{fontSrc:s,rules:d,variables:p}=Ae(o),i=new URLSearchParams;return p&&i.append("variables",p),d&&i.append("rules",d),s&&i.append("font_src",s),r!=null&&r.language&&i.append("lng",r.language),i.append("variant",a||O(n)),`${i.toString()}#${t}`},ht=(e,t)=>{let{kind:o}=e,n;switch(o){case"verify":n="https://id.onefootprint.com";break;case"auth":n=I(e)?"https://auth.onefootprint.com/user":"https://auth.onefootprint.com";break;default:n="https://components.onefootprint.com";}if(Z(n))return Y(o)?`${n}?${Re(e,t)}`.trim():`${n}/${o}?${Re(e,t)}`.trim();throw new Error(`${o}_URL environment variable is not defined.`)},xe=ht;var vt=e=>{let t=null,o=!1,n,r,{formSaveComplete:a,formSaved:s,formSaveFailed:d,started:p}=x,i=S(e),{variant:l,containerId:u}=i,v=l==="modal"||l==="drawer",f=F(),y=(c,g)=>{var C;let h=Pe(E[i.kind],c);(C=i.onError)==null||C.call(i,h),o&&g&&(n(),o=!1);},Ue=()=>{if(!t){y("Footprint should be initialized in order to register callback props");return}let c=X(i,n,r);Object.entries(c).forEach(([g,h])=>{t==null||t.on(g,h),t==null||t.on(`${f}:${g}`,h);});},Ne=()=>{if(v)return ye(f);if(!u){y("containerId is required when rendering inline");return}let c=document.getElementById(u);if(!c){y(`Could not find container with id ${u} while rendering footprint`);return}return ge(f,c)},ee=(c,g)=>{if(!g){H(f),t==null||t.frame.classList.remove(`footprint-${l}-loading`),t==null||t.frame.classList.add(`footprint-${l}-loaded`);return}if(v){let h=he(c,f);q(h,f);}else q(c,f);},te=()=>{var g;if(!t){y("Footprint should be initialized in order to set up refs");return}if(i.kind!=="form"||!i.getRef)return;let c={save:()=>(t||y("Footprint should be initialized to call ref methods"),new Promise((h,C)=>{t==null||t.on(a,()=>{h();}),t==null||t.on(d,Be=>{C(Be);}),t==null||t.on(`${f}:${a}`,h),t==null||t.on(`${f}:${d}`,C),t==null||t.call(s);}))};(g=i.getRef)==null||g.call(i,c);};return {props:i,isRendered:o,render:()=>m(void 0,null,function*(){if(o){J(E[i.kind],"Footprint component is already rendered");return}let c=Ne();if(!c){J(E[i.kind],"Unable to create container for Footprint component");return}c.hasChildNodes()&&(c.innerHTML=""),o=!0,ee(c,!0);let g=yield Ie(i);if(!g){y("Unable to get SDK args token.",!0);return}let h=xe(i,g||"");try{t=yield new ie({classListArray:[`footprint-${l}`,`footprint-${l}-loading`],container:c,name:`footprint-iframe-${f}`,url:h,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;",model:{authToken:i.authToken,initId:f,sdkUrl:De(),sdkVersion:L||""}});}catch(C){y(`Initializing iframe failed with error ${C}`,!0);return}ee(c,!1),Ue(),t==null||t.on(p,()=>te()),t==null||t.on(`${f}:${p}`,te);}),destroy:()=>m(void 0,null,function*(){o&&(o=!1,yield ue(f),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(n=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(r=c);}}},G=vt;var k=e=>{let t=S(e);return JSON.stringify(t)},Pt=()=>{let e=Object.create(null);return {getOrCreate:a=>{let s=k(a.props),d=Object.values(e).find(p=>k(p.iframe.props)===s);return d?d.iframe:(e[s]={iframe:a,secondaryIframes:{}},a)},getOrCreateSecondary:(a,s)=>{let d=k(a.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:i}=e[d],l=Object.values(i).find(u=>k(u.props)===p);return l||(i[p]=s,s)},remove:a=>{let s=k(a.props),d=e[s];d&&(Object.keys(d.secondaryIframes).forEach(p=>{d.secondaryIframes[p].destroy();}),delete e[s]);},removeSecondary:(a,s)=>{let d=k(a.props),p=k(s.props);if(!e[d])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:i}=e[d],l=i[p];l&&(l.destroy(),delete i[p]);}}},Fe=Pt;var kt=()=>{let e=Fe();return {init:o=>{let n=G(o),r=()=>m(void 0,null,function*(){e.remove(n),yield n.destroy();}),a=p=>m(void 0,null,function*(){e.removeSecondary(n,p),yield p.destroy();}),s=p=>m(void 0,null,function*(){let i=G(p);i=e.getOrCreateSecondary(n,i),i.registerOnDestroy(()=>{a(i);}),i.render();});return {render:()=>m(void 0,null,function*(){n=e.getOrCreate(n),n.registerOnDestroy(r),n.registerOnRenderSecondary(s),yield n.render();}),destroy:r}}}},Ct=kt(),Q=Ct;var Vt=e=>{window.setTimeout(e,0);},Ke=e=>typeof e=="object"&&!!e,wt=e=>{if(typeof window=="undefined")return;let t=r=>{var d;let a=(d=window.footprintCallbacks)!=null?d:{};if(!Ke(a))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return Ce[r].forEach(p=>{if(!a[p])throw Error(`Callback '${p}' must be defined in window.footprintCallbacks`)}),a},o=r=>{var f;let a=r.getAttribute("data-kind");N(a);let s=(f=r.getAttribute("data-variant"))!=null?f:O(a);U(a,s);let d=Le(),p=t(a),i=r.getAttribute("data-props")||"",l;try{l=JSON.parse(i);}catch(y){throw Error("Could not parse `data-props` for footprint.")}if(!Ke(l))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let u=F();r.setAttribute("id",u),e.init(b(b({kind:a,variant:s,appearance:d,containerId:r.id},p),l)).render();},n=()=>{let r=document.querySelectorAll("[data-footprint]");r.length&&r.forEach(a=>{o(a);});};document.addEventListener("DOMContentLoaded",()=>Vt(n));},_e=wt;var bt="http://test",Te=e=>m(void 0,null,function*(){let t=yield fetch(`${bt}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),Et=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 Te({identifier:{email:t}}))?!0:o?yield Te({identifier:{phone_number:o}}):!1}),Me=Et;var Xo=Q;_e(Q);/*! Bundled license information: | ||
@@ -17,6 +17,6 @@ @onefootprint/postmate/build/postmate.es.js: | ||
exports.FootprintComponentKind = R; | ||
exports.FootprintPrivateEvent = D; | ||
exports.FootprintPublicEvent = A; | ||
exports.default = Wo; | ||
exports.identifyFootprintUser = _e; | ||
exports.FootprintPrivateEvent = x; | ||
exports.FootprintPublicEvent = D; | ||
exports.default = Xo; | ||
exports.identifyFootprintUser = Me; | ||
@@ -23,0 +23,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "3.9.1", | ||
"version": "3.10.0", | ||
"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
66151
544