@onefootprint/footprint-js
Advanced tools
Comparing version 3.9.0 to 3.9.1
@@ -161,9 +161,10 @@ import * as CSS from 'csstype'; | ||
type Footprint = { | ||
init: (props: Props) => Component; | ||
}; | ||
type Component = { | ||
destroy: () => void; | ||
render: () => Promise<void>; | ||
}; | ||
declare enum ComponentKind { | ||
Auth = "auth", | ||
Form = "form", | ||
Render = "render", | ||
UpdateLoginMethods = "update_login_methods", | ||
Verify = "verify", | ||
VerifyButton = "verify-button" | ||
} | ||
type SupportedLocale = 'en-US' | 'es-MX'; | ||
@@ -175,11 +176,15 @@ type SupportedLanguage = 'en' | 'es'; | ||
}; | ||
type Options = { | ||
showCompletionPage?: boolean; | ||
showLogo?: boolean; | ||
}; | ||
type Variant = 'modal' | 'drawer' | 'inline'; | ||
type Props = AuthProps | FormProps | RenderProps | VerifyButtonProps | VerifyProps; | ||
declare enum ComponentKind { | ||
Auth = "auth", | ||
Form = "form", | ||
Render = "render", | ||
Verify = "verify", | ||
VerifyButton = "verify-button" | ||
} | ||
type Component = { | ||
destroy: () => void; | ||
render: () => Promise<void>; | ||
}; | ||
type Footprint = { | ||
init: (props: Props) => Component; | ||
}; | ||
type Props = AuthProps | FormProps | RenderProps | UpdateLoginMethodsProps | VerifyButtonProps | VerifyProps; | ||
type PropsBase = { | ||
@@ -190,9 +195,6 @@ appearance?: Appearance; | ||
l10n?: L10n; | ||
onError?: (error: string) => void; | ||
variant?: Variant; | ||
onError?: (error: string) => void; | ||
}; | ||
type Options = { | ||
showCompletionPage?: boolean; | ||
showLogo?: boolean; | ||
}; | ||
/** verify */ | ||
type VerifyAuthToken = { | ||
@@ -206,3 +208,4 @@ authToken: string; | ||
}; | ||
type VerifySharedProps = (VerifyAuthToken | VerifyPublicKey) & { | ||
type VerifyVariant = 'modal' | 'drawer'; | ||
type VerifyPropsBase = PropsBase & { | ||
onCancel?: () => void; | ||
@@ -212,13 +215,13 @@ onClose?: () => void; | ||
options?: Options; | ||
publicKey: string; | ||
userData?: FootprintUserData; | ||
}; | ||
type VerifyProps = PropsBase & VerifySharedProps & { | ||
} & (VerifyAuthToken | VerifyPublicKey); | ||
type VerifyProps = VerifyPropsBase & { | ||
kind: ComponentKind.Verify; | ||
variant?: 'modal' | 'drawer'; | ||
variant?: VerifyVariant; | ||
}; | ||
type VerifyDataProps = Pick<VerifyProps, 'publicKey' | 'userData' | 'options' | 'authToken' | 'l10n'>; | ||
type VerifyButtonProps = PropsBase & Partial<VerifySharedProps> & { | ||
/** verify-button */ | ||
type VerifyButtonProps = VerifyPropsBase & { | ||
containerId: string; | ||
dialogVariant?: 'modal' | 'drawer'; | ||
dialogVariant?: VerifyVariant; | ||
kind: ComponentKind.VerifyButton; | ||
@@ -230,2 +233,3 @@ label?: string; | ||
type VerifyButtonDataProps = Pick<VerifyButtonProps, 'label'> & VerifyDataProps; | ||
/** render */ | ||
type RenderProps = PropsBase & { | ||
@@ -243,2 +247,6 @@ authToken: string; | ||
type RenderDataProps = Pick<RenderProps, 'authToken' | 'canCopy' | 'defaultHidden' | 'id' | 'label' | 'showHiddenToggle'>; | ||
/** form */ | ||
type FormRef = { | ||
save: () => Promise<void>; | ||
}; | ||
type FormOptions = { | ||
@@ -249,5 +257,2 @@ hideButtons?: boolean; | ||
}; | ||
type FormRef = { | ||
save: () => Promise<void>; | ||
}; | ||
type FormProps = PropsBase & { | ||
@@ -266,2 +271,3 @@ authToken: string; | ||
type FormDataProps = Pick<FormProps, 'authToken' | 'options' | 'title' | 'l10n'>; | ||
/** auth */ | ||
type AuthPropsBase = PropsBase & { | ||
@@ -279,5 +285,20 @@ kind: ComponentKind.Auth; | ||
authToken?: string; | ||
/** | ||
* @deprecated after version 3.9.0 | ||
*/ | ||
updateLoginMethods?: true; | ||
}; | ||
type AuthDataProps = Pick<AuthProps, 'authToken' | 'updateLoginMethods' | 'publicKey' | 'userData' | 'l10n' | 'options'>; | ||
/** update_login_methods */ | ||
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; | ||
}; | ||
type UpdateLoginMethodsDataProps = Pick<AuthProps, 'authToken' | 'userData' | 'l10n' | 'options'>; | ||
@@ -293,5 +314,5 @@ declare const footprint: Footprint; | ||
declare enum PrivateEvent { | ||
formSaveComplete = "formSaveComplete", | ||
formSaveFailed = "formSaveFailed", | ||
formSaved = "formSaved", | ||
formSaveComplete = "formSaveComplete",// triggered by form when save is complete, to resolve the promise | ||
formSaveFailed = "formSaveFailed",// triggered by form when save fails, to reject the promise | ||
formSaved = "formSaved",// triggered by tenant to save the form via ref | ||
propsReceived = "propsReceived", | ||
@@ -311,2 +332,2 @@ started = "started" | ||
export { Footprint, Appearance as FootprintAppearance, AppearanceRules as FootprintAppearanceRules, AppearanceTheme as FootprintAppearanceTheme, AppearanceVariables as FootprintAppearanceVariables, AuthDataProps as FootprintAuthDataProps, AuthProps as FootprintAuthProps, Component as FootprintComponent, ComponentKind as FootprintComponentKind, FormDataProps as FootprintFormDataProps, FormOptions as FootprintFormOptions, FormProps as FootprintFormProps, FormRef as FootprintFormRef, IdentifyRequest as FootprintIdentifyRequest, Options as FootprintOptions, PrivateEvent as FootprintPrivateEvent, Props as FootprintProps, PropsBase as FootprintPropsBase, PublicEvent as FootprintPublicEvent, RenderDataProps as FootprintRenderDataProps, RenderProps as FootprintRenderProps, FootprintUserData, Variant as FootprintVariant, VerifyAuthToken as FootprintVerifyAuthToken, VerifyButtonDataProps as FootprintVerifyButtonDataProps, VerifyButtonProps as FootprintVerifyButtonProps, VerifyDataProps as FootprintVerifyDataProps, VerifyProps as FootprintVerifyProps, VerifyPublicKey as FootprintVerifyPublicKey, L10n, SupportedLocale, footprint as default, identifyUser as identifyFootprintUser }; | ||
export { Footprint, Appearance as FootprintAppearance, AppearanceRules as FootprintAppearanceRules, AppearanceTheme as FootprintAppearanceTheme, AppearanceVariables as FootprintAppearanceVariables, AuthDataProps as FootprintAuthDataProps, AuthProps as FootprintAuthProps, Component as FootprintComponent, ComponentKind as FootprintComponentKind, FormDataProps as FootprintFormDataProps, FormOptions as FootprintFormOptions, FormProps as FootprintFormProps, FormRef as FootprintFormRef, IdentifyRequest as FootprintIdentifyRequest, Options as FootprintOptions, PrivateEvent as FootprintPrivateEvent, Props as FootprintProps, PropsBase as FootprintPropsBase, PublicEvent as FootprintPublicEvent, RenderDataProps as FootprintRenderDataProps, RenderProps as FootprintRenderProps, UpdateLoginMethodsDataProps as FootprintUpdateLoginMethodsDataProps, UpdateLoginMethodsProps as FootprintUpdateLoginMethodsProps, FootprintUserData, Variant as FootprintVariant, VerifyAuthToken as FootprintVerifyAuthToken, VerifyButtonDataProps as FootprintVerifyButtonDataProps, VerifyButtonProps as FootprintVerifyButtonProps, VerifyDataProps as FootprintVerifyDataProps, VerifyProps as FootprintVerifyProps, VerifyPublicKey as FootprintVerifyPublicKey, L10n, SupportedLocale, footprint as default, identifyUser as identifyFootprintUser }; |
@@ -1,5 +0,5 @@ | ||
import ot from '@onefootprint/postmate'; | ||
import it from '@onefootprint/postmate'; | ||
var De=Object.defineProperty,Le=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var Y=(e,t,o)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,C=(e,t)=>{for(var o in t||(t={}))Z.call(t,o)&&Y(e,o,t[o]);if(I)for(var o of I(t))G.call(t,o)&&Y(e,o,t[o]);return e},U=(e,t)=>Le(e,Te(t));var Q=(e,t)=>{var o={};for(var r in e)Z.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&I)for(var r of I(e))t.indexOf(r)<0&&G.call(e,r)&&(o[r]=e[r]);return o};var f=(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 R="3.9.0";var A=(i=>(i.Auth="auth",i.Form="form",i.Render="render",i.Verify="verify",i.VerifyButton="verify-button",i))(A||{});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 ee="footprint-inline-container",te="footprint-body-locked",oe="footprint-overlay",re="footprint-overlay-container",ne=ee,ie=oe,ae="footprint-loading-indicator",h=(e,t)=>`${e}-${t}`,se=e=>f(void 0,null,function*(){M(e),Ue(e),yield _e(e);}),de=e=>{let t=h(re,e),o=document.getElementById(t);if(o)return o;let r=document.createElement("div");return r.setAttribute("id",t),document.body.appendChild(r),r},_e=e=>f(void 0,null,function*(){let t=h(re,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=h(ie,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(te));}),pe=(e,t)=>{let o=h(ne,e),r=document.createElement("div");return r.classList.add(ee),r.setAttribute("id",o),t.appendChild(r),r},Ue=e=>{let t=h(ne,e),o=document.getElementById(t);o&&o.remove();},M=e=>{let t=h(ae,e),o=document.getElementById(t);o&&o.remove();},$=(e,t)=>{let o=h(ae,t),r=Me(o);e.appendChild(r);},ce=(e,t)=>{document.body.classList.add(te);let o=document.createElement("div"),r=h(ie,t);return o.setAttribute("id",r),o.classList.add(oe),e.appendChild(o),o},Me=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 $e=()=>Math.random().toString(36).substring(2),x=$e;var O="https://api.onefootprint.com",K=R,D="footprint-js";var L={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1"};var Ne=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),N=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(N(e)):Object(n)===n?i=N(e)(n):i=n,[e(r),i]});return Object.fromEntries(o)},je=N(Ne),T=je;var qe=(e,t,o,r)=>{let n={tenantDomain:r,sdkKind:e,sdkName:D,sdkVersion:K,logLevel:o,logMessage:t};try{fetch(`${O}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T(n))});}catch(i){}},le=qe;var me=(e,t)=>{let o=`@onefootprint/footprint-js: ${t}`;{let r;try{r=window.location.href;}catch(n){}le(e,t,"error",r);}return o};var fe={["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"]:{}},ue={["auth"]:[],["form"]:[],["render"]:[],["verify"]:[],["verify-button"]:[]};var ye={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},ze=Object.values(F),Je=(...e)=>{},We=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},B=(e,t)=>{var n;if(!t)return;let o=(n=ye[e])!=null?n:[];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=ye[e])!=null?o:[];if(!t.length)throw new Error(`Invalid kind: ${e}`);return t[0]},_=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(", ")}`)},ge=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=Q(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return U(C({},a),{variant:i,kind:"verify"})}};var Pe=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||Je,j=(e,t,o)=>{var s;let{kind:r}=e,n=(s=fe[r])!=null?s:{},i={},p=ge(e);return Object.entries(n).forEach(([d,a])=>{let l=d;if(!ze.includes(l))return;let P=Pe(e,a),w=l==="closed"||l==="canceled",m=r==="verify-button"&&l==="clicked";i[l]=g=>{P(g),w&&(t==null||t()),m&&p&&(o==null||o(p));};}),i},S=e=>{let{kind:t,variant:o,containerId:r}=e,n=o||V(t);return _(t),B(t,o),We(n,r),U(C({},e),{variant:n})};var he=e=>e==="auth",Xe=e=>e==="verify",q=e=>[he,Xe].some(t=>t(e)),H=e=>typeof e=="string"&&e.length>0,b=e=>he(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/^tok_/.test(e.authToken);var Ye=3,Ze=e=>b(e)?"update_auth_methods_v1":L[e.kind],Ge=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 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}},ke=(e,t)=>f(void 0,null,function*(){return fetch(`${O}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${D} ${K} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>{if(o.ok)return o.json();if(t>0)return ke(e,t-1)})}),Qe=e=>f(void 0,null,function*(){let t=Ge(e);if(!t)return;let o=yield ke({data:T(t),kind:Ze(e)},Ye);return o?o.token:void 0}),ve=Qe;var et=e=>typeof e=="object"&&!!e,Ce=({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||!et(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var we=()=>{var e;return typeof window!="undefined"?((e=window.location)==null?void 0:e.href)||window.location.toString():""},be=(e,t)=>{let{appearance:o,kind:r,l10n:n,variant:i}=e,{fontSrc:p,rules:s,variables:d}=Ce(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||V(r)),`${a.toString()}#${t}`},tt=(e,t)=>{let{kind:o}=e,r;switch(o){case"verify":r="https://id.onefootprint.com";break;case"auth":r=b(e)?"https://auth.onefootprint.com/user":"https://auth.onefootprint.com";break;default:r="https://components.onefootprint.com";}if(H(r))return q(o)?`${r}?${be(e,t)}`.trim():`${r}/${o}?${be(e,t)}`.trim();throw new Error(`${o}_URL environment variable is not defined.`)},Se=tt;var rt=e=>{let t=null,o=!1,r,n,{formSaveComplete:i,formSaved:p,formSaveFailed:s,started:d}=E,a=S(e),{variant:l,containerId:P}=a,w=l==="modal"||l==="drawer",m=x(),g=(c,u)=>{var v;let y=me(L[a.kind],c);(v=a.onError)==null||v.call(a,y),o&&u&&(r(),o=!1);},xe=()=>{if(!t){g("Footprint should be initialized in order to register callback props");return}let c=j(a,r,n);Object.entries(c).forEach(([u,y])=>{t==null||t.on(u,y),t==null||t.on(`${m}:${u}`,y);});},Oe=()=>{if(w)return de(m);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 pe(m,c)},W=(c,u)=>{if(!u){M(m),t==null||t.frame.classList.remove(`footprint-${l}-loading`),t==null||t.frame.classList.add(`footprint-${l}-loaded`);return}if(w){let y=ce(c,m);$(y,m);}else $(c,m);},X=()=>{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(s,Ke=>{v(Ke);}),t==null||t.on(`${m}:${i}`,y),t==null||t.on(`${m}:${s}`,v),t==null||t.call(p);}))};(u=a.getRef)==null||u.call(a,c);};return {props:a,isRendered:o,render:()=>f(void 0,null,function*(){if(o)return;let c=Oe();if(!c)return;c.hasChildNodes()&&(c.innerHTML=""),o=!0,W(c,!0);let u=yield ve(a);if(!u){g("Unable to get SDK args token.",!0);return}let y=Se(a,u||"");try{t=yield new ot({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:we(),sdkVersion:R||""}});}catch(v){g(`Initializing iframe failed with error ${v}`,!0);return}W(c,!1),xe(),t==null||t.on(d,()=>X()),t==null||t.on(`${m}:${d}`,X);}),destroy:()=>f(void 0,null,function*(){o&&(o=!1,yield se(m),t&&(t.destroy(),t=null));}),registerOnDestroy:c=>{!c||typeof c!="function"||(r=c);},registerOnRenderSecondary:c=>{!c||typeof c!="function"||(n=c);}}},z=rt;var k=e=>{let t=S(e);return JSON.stringify(t)},nt=()=>{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]);}}},Ie=nt;var it=()=>{let e=Ie();return {init:o=>{let r=z(o),n=()=>f(void 0,null,function*(){e.remove(r),yield r.destroy();}),i=d=>f(void 0,null,function*(){e.removeSecondary(r,d),yield d.destroy();}),p=d=>f(void 0,null,function*(){let a=z(d);a=e.getOrCreateSecondary(r,a),a.registerOnDestroy(()=>{i(a);}),a.render();});return {render:()=>f(void 0,null,function*(){r=e.getOrCreate(r),r.registerOnDestroy(n),r.registerOnRenderSecondary(p),yield r.render();}),destroy:n}}}},at=it(),J=at;var st=e=>{window.setTimeout(e,0);},Re=e=>typeof e=="object"&&!!e,dt=e=>{if(typeof window=="undefined")return;let t=n=>{var s;let i=(s=window.footprintCallbacks)!=null?s:{};if(!Re(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return ue[n].forEach(d=>{if(!i[d])throw Error(`Callback '${d}' must be defined in window.footprintCallbacks`)}),i},o=n=>{var m;let i=n.getAttribute("data-kind");_(i);let p=(m=n.getAttribute("data-variant"))!=null?m:V(i);B(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(!Re(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",()=>st(r));},Ae=dt;var pt="https://api.onefootprint.com",Fe=e=>f(void 0,null,function*(){let t=yield fetch(`${pt}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),ct=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 Fe({identifier:{email:t}}))?!0:o?yield Fe({identifier:{phone_number:o}}):!1}),Ee=ct;var Ko=J;Ae(J); | ||
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); | ||
export { A as FootprintComponentKind, E as FootprintPrivateEvent, F as FootprintPublicEvent, Ko as default, Ee as identifyFootprintUser }; | ||
export { A as FootprintComponentKind, L as FootprintPrivateEvent, F as FootprintPublicEvent, To as default, Ee as identifyFootprintUser }; |
(function (exports) { | ||
'use strict'; | ||
var Ne=Object.defineProperty,Be=Object.defineProperties;var Me=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var Q=(e,t,n)=>t in e?Ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))ee.call(t,n)&&Q(e,n,t[n]);if(I)for(var n of I(t))te.call(t,n)&&Q(e,n,t[n]);return e},$=(e,t)=>Be(e,Me(t));var ne=(e,t)=>{var n={};for(var o in e)ee.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&I)for(var o of I(e))t.indexOf(o)<0&&te.call(e,o)&&(n[o]=e[o]);return n};var m=(e,t,n)=>new Promise((o,r)=>{var i=d=>{try{s(n.next(d));}catch(a){r(a);}},p=d=>{try{s(n.throw(d));}catch(a){r(a);}},s=d=>d.done?o(d.value):Promise.resolve(d.value).then(i,p);s((n=n.apply(e,t)).next());});var V="application/x-postmate-v1+json",$e=5,Ue=0,je=function(){return ++Ue};var He=function(t){var n=document.createElement("a");n.href=t;var o=n.protocol.length>4?n.protocol:window.location.protocol,r=n.host.length?n.port==="80"||n.port==="443"?n.hostname:n.host:window.location.host;return n.origin||o+"//"+r},qe={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},U=function(t,n){return !(typeof n=="string"&&t.origin!==n||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==V||!qe[t.data.postmate])},ze=function(t,n){var o=typeof t[n]=="function"?t[n]():t[n];return w.Promise.resolve(o)},Je=function(){function e(n){var o=this;this.parent=n.parent,this.frame=n.frame,this.child=n.child,this.childOrigin=n.childOrigin,this.events={},this.listener=function(r){if(!U(r,o.childOrigin))return !1;var i=((r||{}).data||{}).value||{},p=i.data,s=i.name;r.data.postmate==="emit"&&s in o.events&&o.events[s].forEach(function(d){d.call(o,p);});},this.parent.addEventListener("message",this.listener,!1);}var t=e.prototype;return t.get=function(o){var r=this;return new w.Promise(function(i){var p=je(),s=function d(a){a.data.uid===p&&a.data.postmate==="reply"&&(r.parent.removeEventListener("message",d,!1),i(a.data.value));};r.parent.addEventListener("message",s,!1),r.child.postMessage({postmate:"request",type:V,property:o,uid:p},r.childOrigin);})},t.call=function(o,r){this.child.postMessage({postmate:"call",type:V,property:o,data:r},this.childOrigin);},t.on=function(o,r){this.events[o]||(this.events[o]=[]),this.events[o].push(r);},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),We=function(){function e(n){var o=this;this.model=n.model,this.parent=n.parent,this.parentOrigin=n.parentOrigin,this.child=n.child,this.child.addEventListener("message",function(r){if(U(r,o.parentOrigin)){var i=r.data,p=i.property,s=i.uid,d=i.data;if(r.data.postmate==="call"){p in o.model&&typeof o.model[p]=="function"&&o.model[p](d);return}ze(o.model,p).then(function(a){return r.source.postMessage({property:p,postmate:"reply",type:V,uid:s,value:a},r.origin)});}});}var t=e.prototype;return t.emit=function(o,r){this.parent.postMessage({postmate:"emit",type:V,value:{name:o,data:r}},this.parentOrigin);},e}(),w=function(){function e(n){var o=n.container,r=o===void 0?typeof r!="undefined"?r:document.body:o,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),r.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(o){var r=this,i=He(o),p=0,s;return new e.Promise(function(d,a){var c=function f(y){return U(y,i)?y.data.postmate==="handshake-reply"?(clearInterval(s),r.parent.removeEventListener("message",f,!1),r.childOrigin=y.origin,d(new Je(r))):a("Failed handshake"):!1};r.parent.addEventListener("message",c,!1);var u=function(){p++,r.child.postMessage({postmate:"handshake",type:V,model:r.model},i),p===$e&&clearInterval(s);},v=function(){u(),s=setInterval(u,500);};r.frame.attachEvent?r.frame.attachEvent("onload",v):r.frame.addEventListener("load",v),r.frame.src=o;})},e}();w.debug=!1;w.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();w.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 o=this;return new w.Promise(function(r,i){var p=function s(d){if(d.data.postmate){if(d.data.postmate==="handshake"){o.child.removeEventListener("message",s,!1),d.source.postMessage({postmate:"handshake-reply",type:V},d.origin),o.parentOrigin=d.origin;var a=d.data.model;return a&&Object.keys(a).forEach(function(c){o.model[c]=a[c];}),r(new We(o))}return i("Handshake Reply Failed")}};o.child.addEventListener("message",p,!1);})},e}();var oe=w;var R="3.9.0";var A=(i=>(i.Auth="auth",i.Form="form",i.Render="render",i.Verify="verify",i.VerifyButton="verify-button",i))(A||{});var D=(r=>(r.canceled="canceled",r.clicked="clicked",r.closed="closed",r.completed="completed",r))(D||{}),x=(i=>(i.formSaveComplete="formSaveComplete",i.formSaveFailed="formSaveFailed",i.formSaved="formSaved",i.propsReceived="propsReceived",i.started="started",i))(x||{});var re="footprint-inline-container",ie="footprint-body-locked",ae="footprint-overlay",se="footprint-overlay-container",de=re,pe=ae,ce="footprint-loading-indicator",P=(e,t)=>`${e}-${t}`,le=e=>m(void 0,null,function*(){j(e),Ze(e),yield Ye(e);}),fe=e=>{let t=P(se,e),n=document.getElementById(t);if(n)return n;let o=document.createElement("div");return o.setAttribute("id",t),document.body.appendChild(o),o},Ye=e=>m(void 0,null,function*(){let t=P(se,e),n=document.getElementById(t);if(!n)return;let o=n.querySelector("iframe.footprint-drawer");o&&(o==null||o.classList.add("footprint-drawer-closing"),yield new Promise(s=>{setTimeout(s,300);}));let r=n.querySelector("iframe.footprint-modal");r&&(r==null||r.classList.add("footprint-modal-closing"),yield new Promise(s=>{setTimeout(s,100);}));let i=P(pe,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(ie));}),me=(e,t)=>{let n=P(de,e),o=document.createElement("div");return o.classList.add(re),o.setAttribute("id",n),t.appendChild(o),o},Ze=e=>{let t=P(de,e),n=document.getElementById(t);n&&n.remove();},j=e=>{let t=P(ce,e),n=document.getElementById(t);n&&n.remove();},H=(e,t)=>{let n=P(ce,t),o=Ge(n);e.appendChild(o);},ue=(e,t)=>{document.body.classList.add(ie);let n=document.createElement("div"),o=P(pe,t);return n.setAttribute("id",o),n.classList.add(ae),e.appendChild(n),n},Ge=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 o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width","24px"),o.setAttribute("height","24px"),o.setAttribute("fill","none"),o.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"),o.appendChild(r),n.appendChild(o),t.appendChild(n),t};var Qe=()=>Math.random().toString(36).substring(2),F=Qe;var K="https://api.onefootprint.com",L=R,_="footprint-js";var T={["auth"]:"auth_v1",["form"]:"form_v1",["render"]:"render_v1",["verify"]:"verify_v1",["verify-button"]:"verify_button_v1"};var et=e=>e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`),q=e=>t=>{if(!t||typeof t!="object")return t;let n=Object.entries(t).map(([o,r])=>{let i;return Array.isArray(r)?i=r.map(q(e)):Object(r)===r?i=q(e)(r):i=r,[e(o),i]});return Object.fromEntries(n)},tt=q(et),N=tt;var nt=(e,t,n,o)=>{let r={tenantDomain:o,sdkKind:e,sdkName:_,sdkVersion:L,logLevel:n,logMessage:t};try{fetch(`${K}/org/sdk_telemetry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N(r))});}catch(i){}},ye=nt;var ge=(e,t)=>{let n=`@onefootprint/footprint-js: ${t}`;{let o;try{o=window.location.href;}catch(r){}ye(e,t,"error",o);}return n};var he={["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"]:{}},ve={["auth"]:[],["form"]:[],["render"]:[],["verify"]:[],["verify-button"]:[]};var Pe={["auth"]:["modal","drawer"],["form"]:["inline","modal","drawer"],["render"]:["inline"],["verify"]:["modal","drawer"],["verify-button"]:["inline"]},rt=Object.values(D),it=(...e)=>{},at=(e,t)=>{if(e==="inline"&&!t)throw new Error(`Inline component requires a containerId. Received ${t}`)},B=(e,t)=>{var r;if(!t)return;let n=(r=Pe[e])!=null?r:[];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=Pe[e])!=null?n:[];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(", ")}`)},ke=e=>{if(e.kind==="verify-button"){let t=e,{kind:n,appearance:o,variant:r,dialogVariant:i,onClick:p,label:s,containerId:d}=t,a=ne(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return $(b({},a),{variant:i,kind:"verify"})}};var Ce=(e,t)=>(Object.prototype.hasOwnProperty.call(e,t)&&typeof e[t]=="function"?e[t]:void 0)||it,z=(e,t,n)=>{var s;let{kind:o}=e,r=(s=he[o])!=null?s:{},i={},p=ke(e);return Object.entries(r).forEach(([d,a])=>{let c=d;if(!rt.includes(c))return;let u=Ce(e,a),v=c==="closed"||c==="canceled",f=o==="verify-button"&&c==="clicked";i[c]=y=>{u(y),v&&(t==null||t()),f&&p&&(n==null||n(p));};}),i},S=e=>{let{kind:t,variant:n,containerId:o}=e,r=n||E(t);return M(t),B(t,n),at(r,o),$(b({},e),{variant:r})};var Ve=e=>e==="auth",st=e=>e==="verify",J=e=>[Ve,st].some(t=>t(e)),W=e=>typeof e=="string"&&e.length>0,O=e=>Ve(e.kind)&&!!("updateLoginMethods"in e&&e.updateLoginMethods)&&!!e.authToken&&/^tok_/.test(e.authToken);var dt=3,pt=e=>O(e)?"update_auth_methods_v1":T[e.kind],ct=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 O(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}},we=(e,t)=>m(void 0,null,function*(){return fetch(`${K}/org/sdk_args`,{method:"POST",headers:{"x-fp-client-version":`${_} ${L} ${e.kind}`.trim(),"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n=>{if(n.ok)return n.json();if(t>0)return we(e,t-1)})}),lt=e=>m(void 0,null,function*(){let t=ct(e);if(!t)return;let n=yield we({data:N(t),kind:pt(e)},dt);return n?n.token:void 0}),be=lt;var ft=e=>typeof e=="object"&&!!e,Ee=({fontSrc:e,variables:t={},rules:n={},variant:o}={})=>{let r=()=>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:r(),rules:i(),variant:o}},Oe=()=>{let e=window.footprintAppearance;return !e||!ft(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:n,kind:o,l10n:r,variant:i}=e,{fontSrc:p,rules:s,variables:d}=Ee(n),a=new URLSearchParams;return d&&a.append("variables",d),s&&a.append("rules",s),p&&a.append("font_src",p),r!=null&&r.language&&a.append("lng",r.language),a.append("variant",i||E(o)),`${a.toString()}#${t}`},mt=(e,t)=>{let{kind:n}=e,o;switch(n){case"verify":o="https://id.onefootprint.com";break;case"auth":o=O(e)?"https://auth.onefootprint.com/user":"https://auth.onefootprint.com";break;default:o="https://components.onefootprint.com";}if(W(o))return J(n)?`${o}?${Se(e,t)}`.trim():`${o}/${n}?${Se(e,t)}`.trim();throw new Error(`${n}_URL environment variable is not defined.`)},Re=mt;var ut=e=>{let t=null,n=!1,o,r,{formSaveComplete:i,formSaved:p,formSaveFailed:s,started:d}=x,a=S(e),{variant:c,containerId:u}=a,v=c==="modal"||c==="drawer",f=F(),y=(l,g)=>{var C;let h=ge(T[a.kind],l);(C=a.onError)==null||C.call(a,h),n&&g&&(o(),n=!1);},Le=()=>{if(!t){y("Footprint should be initialized in order to register callback props");return}let l=z(a,o,r);Object.entries(l).forEach(([g,h])=>{t==null||t.on(g,h),t==null||t.on(`${f}:${g}`,h);});},_e=()=>{if(v)return fe(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 me(f,l)},Z=(l,g)=>{if(!g){j(f),t==null||t.frame.classList.remove(`footprint-${c}-loading`),t==null||t.frame.classList.add(`footprint-${c}-loaded`);return}if(v){let h=ue(l,f);H(h,f);}else H(l,f);},G=()=>{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,Te=>{C(Te);}),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=_e();if(!l)return;l.hasChildNodes()&&(l.innerHTML=""),n=!0,Z(l,!0);let g=yield be(a);if(!g){y("Unable to get SDK args token.",!0);return}let h=Re(a,g||"");try{t=yield new oe({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:Ie(),sdkVersion:R||""}});}catch(C){y(`Initializing iframe failed with error ${C}`,!0);return}Z(l,!1),Le(),t==null||t.on(d,()=>G()),t==null||t.on(`${f}:${d}`,G);}),destroy:()=>m(void 0,null,function*(){n&&(n=!1,yield le(f),t&&(t.destroy(),t=null));}),registerOnDestroy:l=>{!l||typeof l!="function"||(o=l);},registerOnRenderSecondary:l=>{!l||typeof l!="function"||(r=l);}}},X=ut;var k=e=>{let t=S(e);return JSON.stringify(t)},yt=()=>{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]);}}},Ae=yt;var gt=()=>{let e=Ae();return {init:n=>{let o=X(n),r=()=>m(void 0,null,function*(){e.remove(o),yield o.destroy();}),i=d=>m(void 0,null,function*(){e.removeSecondary(o,d),yield d.destroy();}),p=d=>m(void 0,null,function*(){let a=X(d);a=e.getOrCreateSecondary(o,a),a.registerOnDestroy(()=>{i(a);}),a.render();});return {render:()=>m(void 0,null,function*(){o=e.getOrCreate(o),o.registerOnDestroy(r),o.registerOnRenderSecondary(p),yield o.render();}),destroy:r}}}},ht=gt(),Y=ht;var vt=e=>{window.setTimeout(e,0);},De=e=>typeof e=="object"&&!!e,Pt=e=>{if(typeof window=="undefined")return;let t=r=>{var s;let i=(s=window.footprintCallbacks)!=null?s:{};if(!De(i))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return ve[r].forEach(d=>{if(!i[d])throw Error(`Callback '${d}' must be defined in window.footprintCallbacks`)}),i},n=r=>{var f;let i=r.getAttribute("data-kind");M(i);let p=(f=r.getAttribute("data-variant"))!=null?f:E(i);B(i,p);let s=Oe(),d=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(!De(c))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:i,variant:p,appearance:s,containerId:r.id},d),c)).render();},o=()=>{let r=document.querySelectorAll("[data-footprint]");r.length&&r.forEach(i=>{n(i);});};document.addEventListener("DOMContentLoaded",()=>vt(o));},xe=Pt;var kt="https://api.onefootprint.com",Fe=e=>m(void 0,null,function*(){let t=yield fetch(`${kt}/hosted/identify`,{method:"POST",body:JSON.stringify(e)});if(!t.ok)throw Error(t.statusText);return (yield t.json()).user_found}),Ct=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 Fe({identifier:{email:t}}))?!0:n?yield Fe({identifier:{phone_number:n}}):!1}),Ke=Ct;var qn=Y;xe(Y);/*! Bundled license information: | ||
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: | ||
@@ -16,7 +16,7 @@ @onefootprint/postmate/build/postmate.es.js: | ||
exports.FootprintComponentKind = A; | ||
exports.FootprintPrivateEvent = x; | ||
exports.FootprintPublicEvent = D; | ||
exports.default = qn; | ||
exports.identifyFootprintUser = Ke; | ||
exports.FootprintComponentKind = R; | ||
exports.FootprintPrivateEvent = D; | ||
exports.FootprintPublicEvent = A; | ||
exports.default = Wo; | ||
exports.identifyFootprintUser = _e; | ||
@@ -23,0 +23,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "3.9.0", | ||
"version": "3.9.1", | ||
"main": "./dist/footprint-js.cjs", | ||
@@ -22,5 +22,5 @@ "module": "./dist/footprint-js.js", | ||
"scripts": { | ||
"test": "jest", | ||
"test:ci": "jest --ci --bail --runInBand", | ||
"test:watch": "jest --watch", | ||
"test": "bun test --bail", | ||
"test:ci:bun": "bun test --bail", | ||
"test:watch": "bun test --watch", | ||
"dev": "tsup --watch", | ||
@@ -38,16 +38,13 @@ "build": "tsup", | ||
"devDependencies": { | ||
"@onefootprint/jest-presets": "*", | ||
"bun-types": "^1.0.25", | ||
"csstype": "^3.1.2", | ||
"eslint-config-footprint": "*", | ||
"msw": "^2.1.2", | ||
"tsconfig": "*", | ||
"tsup": "^6.5.0", | ||
"typescript": "4.9.5", | ||
"jest-fetch-mock": "^3.0.3" | ||
"typescript": "^5" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"jest": { | ||
"preset": "@onefootprint/jest-presets/jest/web" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
64567
537