@onefootprint/footprint-js
Advanced tools
Comparing version 2.3.0 to 3.0.0
import * as CSS from 'csstype'; | ||
type FootprintShowParams = { | ||
publicKey: string; | ||
onCompleted: (validationToken: string) => void; | ||
onCanceled: () => void; | ||
}; | ||
type FootprintAppearanceVariables = Partial<{ | ||
type AppearanceVariables = Partial<{ | ||
borderRadius: CSS.Property.BorderRadius; | ||
@@ -111,4 +106,4 @@ colorError: CSS.Property.Color; | ||
}>; | ||
type FootprintAppearanceTheme = 'light' | 'dark'; | ||
type FootprintAppearanceRules = Partial<{ | ||
type AppearanceTheme = 'light' | 'dark'; | ||
type AppearanceRules = Partial<{ | ||
button: CSS.Properties; | ||
@@ -136,31 +131,10 @@ 'button:hover': CSS.Properties; | ||
}>; | ||
type FootprintAppearance = { | ||
variant?: 'dialog' | 'drawer'; | ||
type Appearance = { | ||
variant?: 'modal' | 'drawer' | 'inline'; | ||
fontSrc?: string; | ||
rules?: FootprintAppearanceRules; | ||
theme?: FootprintAppearanceTheme; | ||
variables?: FootprintAppearanceVariables; | ||
rules?: AppearanceRules; | ||
theme?: AppearanceTheme; | ||
variables?: AppearanceVariables; | ||
}; | ||
type OpenFootprint = { | ||
appearance?: FootprintAppearance; | ||
onCanceled?: () => void; | ||
onCompleted?: (validationToken: string) => void; | ||
publicKey?: string; | ||
userData?: FootprintUserData; | ||
options?: FootprintOptions; | ||
}; | ||
type Footprint = { | ||
open: (options: OpenFootprint) => Promise<void>; | ||
close: () => Promise<void>; | ||
}; | ||
declare enum FootprintPublicEvent { | ||
closed = "closed", | ||
completed = "completed", | ||
canceled = "canceled" | ||
} | ||
declare enum FootprintInternalEvent { | ||
bootstrapDataReceived = "bootstrapDataReceived", | ||
optionsReceived = "optionsReceived", | ||
started = "started" | ||
} | ||
type FootprintUserData = Partial<{ | ||
@@ -182,15 +156,108 @@ 'id.email': string; | ||
}>; | ||
type FootprintOptions = { | ||
interface Footprint { | ||
init: (props: Props) => Component; | ||
} | ||
interface Component { | ||
render: () => Promise<void>; | ||
destroy: () => void; | ||
} | ||
type Props = FormProps | VerifyProps | VerifyButtonProps | RenderProps; | ||
declare enum ComponentKind { | ||
Verify = "verify", | ||
Form = "form", | ||
Render = "render", | ||
VerifyButton = "verify-button" | ||
} | ||
type Variant = 'modal' | 'drawer' | 'inline'; | ||
interface PropsBase { | ||
kind: ComponentKind; | ||
appearance?: Appearance; | ||
variant?: Variant; | ||
containerId?: string; | ||
} | ||
type VerifyOptions = { | ||
showCompletionPage?: boolean; | ||
showLogo?: boolean; | ||
}; | ||
interface VerifyProps extends PropsBase { | ||
kind: ComponentKind.Verify; | ||
variant?: 'modal' | 'drawer'; | ||
publicKey: string; | ||
userData?: FootprintUserData; | ||
options?: VerifyOptions; | ||
onComplete?: (validationToken: string) => void; | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
} | ||
interface VerifyButtonProps extends PropsBase { | ||
kind: ComponentKind.VerifyButton; | ||
variant: 'inline'; | ||
containerId: string; | ||
dialogVariant?: 'modal' | 'drawer'; | ||
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
label?: string; | ||
publicKey?: string; | ||
userData?: FootprintUserData; | ||
options?: VerifyOptions; | ||
onComplete?: (validationToken: string) => void; | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
} | ||
interface RenderProps extends PropsBase { | ||
kind: ComponentKind.Render; | ||
authToken: string; | ||
id: string; | ||
label?: string; | ||
canCopy?: boolean; | ||
showHiddenToggle?: boolean; | ||
defaultHidden?: boolean; | ||
variant: 'inline'; | ||
containerId: string; | ||
} | ||
declare enum FormType { | ||
cardOnly = "cardOnly", | ||
cardAndName = "cardAndName", | ||
cardAndNameAndAddress = "cardAndNameAndAddress", | ||
cardAndZip = "cardAndZip" | ||
} | ||
type FormOptions = { | ||
hideFootprintLogo?: boolean; | ||
}; | ||
interface FormProps extends PropsBase { | ||
kind: ComponentKind.Form; | ||
authToken: string; | ||
title?: string; | ||
type?: FormType; | ||
containerId?: string; | ||
variant?: Variant; | ||
options?: FormOptions; | ||
onComplete?: () => void; | ||
onCancel?: () => void; | ||
onClose?: () => void; | ||
} | ||
declare const identifyUser: (userData?: FootprintUserData) => Promise<any>; | ||
declare const footprint: Footprint; | ||
declare const footprint: { | ||
open: ({ appearance, onCanceled, onCompleted, publicKey, userData, options, }: OpenFootprint) => Promise<void>; | ||
close: () => Promise<void>; | ||
createButton: (container?: HTMLElement | undefined) => HTMLButtonElement; | ||
declare enum PublicEvent { | ||
closed = "closed", | ||
canceled = "canceled", | ||
completed = "completed", | ||
clicked = "clicked" | ||
} | ||
declare enum PrivateEvent { | ||
propsReceived = "propsReceived", | ||
started = "started" | ||
} | ||
type IdentifyRequest = { | ||
identifier: { | ||
email: string; | ||
} | { | ||
phone_number: string; | ||
}; | ||
}; | ||
export { Footprint, FootprintAppearance, FootprintAppearanceRules, FootprintAppearanceTheme, FootprintAppearanceVariables, FootprintInternalEvent, FootprintOptions, FootprintPublicEvent, FootprintShowParams, FootprintUserData, OpenFootprint, footprint as default, identifyUser }; | ||
declare const identifyUser: (userData?: FootprintUserData) => Promise<any>; | ||
export { Footprint, Appearance as FootprintAppearance, AppearanceRules as FootprintAppearanceRules, AppearanceTheme as FootprintAppearanceTheme, AppearanceVariables as FootprintAppearanceVariables, Component as FootprintComponent, ComponentKind as FootprintComponentKind, FormOptions as FootprintFormOptions, FormProps as FootprintFormProps, FormType as FootprintFormType, IdentifyRequest as FootprintIdentifyRequest, PrivateEvent as FootprintPrivateEvent, Props as FootprintProps, PropsBase as FootprintPropsBase, PublicEvent as FootprintPublicEvent, RenderProps as FootprintRenderProps, FootprintUserData, Variant as FootprintVariant, VerifyButtonProps as FootprintVerifyButtonProps, VerifyOptions as FootprintVerifyOptions, VerifyProps as FootprintVerifyProps, footprint as default, identifyUser as identifyFootprintUser }; |
@@ -1,2 +0,2 @@ | ||
var c=(e,o,t)=>new Promise((r,n)=>{var i=p=>{try{s(t.next(p));}catch(d){n(d);}},a=p=>{try{s(t.throw(p));}catch(d){n(d);}},s=p=>p.done?r(p.value):Promise.resolve(p.value).then(i,a);s((t=t.apply(e,o)).next());});var E=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(E||{}),w=(r=>(r.bootstrapDataReceived="bootstrapDataReceived",r.optionsReceived="optionsReceived",r.started="started",r))(w||{}),O=["showCompletionPage"],F=["id.email","id.phone_number","id.first_name","id.last_name","id.dob","id.address_line1","id.address_line2","id.city","id.state","id.country","id.zip","id.ssn9","id.ssn4"];var u="application/x-postmate-v1+json",Y=5,z=0,J=function(){return ++z};var Z=function(o){var t=document.createElement("a");t.href=o;var r=t.protocol.length>4?t.protocol:window.location.protocol,n=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||r+"//"+n},G={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},v=function(o,t){return !(typeof t=="string"&&o.origin!==t||!o.data||typeof o.data=="object"&&!("postmate"in o.data)||o.data.type!==u||!G[o.data.postmate])},Q=function(o,t){var r=typeof o[t]=="function"?o[t]():o[t];return S.Promise.resolve(r)},X=function(){function e(t){var r=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(n){if(!v(n,r.childOrigin))return !1;var i=((n||{}).data||{}).value||{},a=i.data,s=i.name;n.data.postmate==="emit"&&s in r.events&&r.events[s].forEach(function(p){p.call(r,a);});},this.parent.addEventListener("message",this.listener,!1);}var o=e.prototype;return o.get=function(r){var n=this;return new S.Promise(function(i){var a=J(),s=function p(d){d.data.uid===a&&d.data.postmate==="reply"&&(n.parent.removeEventListener("message",p,!1),i(d.data.value));};n.parent.addEventListener("message",s,!1),n.child.postMessage({postmate:"request",type:u,property:r,uid:a},n.childOrigin);})},o.call=function(r,n){this.child.postMessage({postmate:"call",type:u,property:r,data:n},this.childOrigin);},o.on=function(r,n){this.events[r]||(this.events[r]=[]),this.events[r].push(n);},o.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),tt=function(){function e(t){var r=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(n){if(v(n,r.parentOrigin)){var i=n.data,a=i.property,s=i.uid,p=i.data;if(n.data.postmate==="call"){a in r.model&&typeof r.model[a]=="function"&&r.model[a](p);return}Q(r.model,a).then(function(d){return n.source.postMessage({property:a,postmate:"reply",type:u,uid:s,value:d},n.origin)});}});}var o=e.prototype;return o.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:u,value:{name:r,data:n}},this.parentOrigin);},e}(),S=function(){function e(t){var r=t.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,i=t.model,a=t.url,s=t.name,p=s===void 0?"":s,d=t.allow,l=t.classListArray,y=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,y),d&&(this.frame.allow=d),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var o=e.prototype;return o.sendHandshake=function(r){var n=this,i=Z(r),a=0,s;return new e.Promise(function(p,d){var l=function h(m){return v(m,i)?m.data.postmate==="handshake-reply"?(clearInterval(s),n.parent.removeEventListener("message",h,!1),n.childOrigin=m.origin,p(new X(n))):d("Failed handshake"):!1};n.parent.addEventListener("message",l,!1);var y=function(){a++,n.child.postMessage({postmate:"handshake",type:u,model:n.model},i),a===Y&&clearInterval(s);},f=function(){y(),s=setInterval(y,500);};n.frame.attachEvent?n.frame.attachEvent("onload",f):n.frame.addEventListener("load",f),n.frame.src=r;})},e}();S.debug=!1;S.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();S.Model=function(){function e(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var o=e.prototype;return o.sendHandshakeReply=function(){var r=this;return new S.Promise(function(n,i){var a=function s(p){if(p.data.postmate){if(p.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),p.source.postMessage({postmate:"handshake-reply",type:u},p.origin),r.parentOrigin=p.origin;var d=p.data.model;return d&&Object.keys(d).forEach(function(l){r.model[l]=d[l];}),n(new tt(r))}return i("Handshake Reply Failed")}};r.child.addEventListener("message",a,!1);})},e}();var k=S;var A="footprint-container",_="footprint-overlay",L="footprint-loading-indicator",g=e=>{if(!e)throw new Error("A container is required to create a Footprint button");let o=P();return e.appendChild(o),o},x=e=>{document.body.classList.add("footprint-body-locked");let o=document.createElement("div");o.setAttribute("id",_);let t=ot(L);o.appendChild(t),o.classList.add("footprint-overlay"),e.appendChild(o);},I=()=>{let e=document.getElementById(L);e&&e.remove();},R=()=>{document.body.classList.remove("footprint-body-locked");let e=document.getElementById(_);e&&e.remove();},N=()=>{let e=document.getElementById(A);if(e)return e;let o=document.createElement("div");return o.setAttribute("id",A),document.body.appendChild(o),o},ot=e=>{let o=document.createElement("div");o.setAttribute("id",e),o.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.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),t.appendChild(r),o.appendChild(t),o},et=()=>{let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width","24px"),e.setAttribute("height","24px"),e.setAttribute("fill","none"),e.setAttribute("aria-hidden","true");let o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M14.66 14h2.666v-2.36a2.666 2.666 0 1 1 0-4.614V4H6.66v16h4.666v-2.666A3.333 3.333 0 0 1 14.66 14Z"),o.setAttribute("fill","#76fb8f"),e.appendChild(o),e},P=()=>{let e=et(),o=document.createElement("button");o.appendChild(e);let t=document.createElement("span");return t.innerText="Verify with Footprint",o.appendChild(t),o.classList.add("footprint-button"),o};var B=class{constructor(){this.child=null;this.handleIframeLoaded=()=>{var o,t;I(),(o=this.child)==null||o.frame.classList.remove("footprint-modal-loading"),(t=this.child)==null||t.frame.classList.add("footprint-modal-loaded");};}sendOptions(o){var t;o&&((t=this.child)==null||t.call("optionsReceived",o));}bootstrap(o){var t;o&&((t=this.child)==null||t.call("bootstrapDataReceived",o));}open(o,t,r){return c(this,null,function*(){let n=N();x(n),this.child=yield new k({classListArray:["footprint-modal","footprint-modal-loading"],container:n,name:"footprint-iframe",url:o,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;"}),this.handleIframeLoaded(),this.child.on("started",()=>{this.bootstrap(t),this.sendOptions(r);});})}on(o,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(o,t)}close(){R(),this.child&&this.child.destroy();}createButton(o){let t=P();return o.appendChild(t),t}},D=B;var H=e=>{let o="https://id.onefootprint.com",{publicKey:t,variables:r,rules:n,fontSrc:i,variant:a}=e,s=new URLSearchParams;return t&&s.append("public_key",t),r&&s.append("variables",r),n&&s.append("rules",n),a&&s.append("variant",a),i&&s.append("font_src",i),`${o}?${s.toString()}`},T=({fontSrc:e,variables:o={},rules:t={},variant:r}={})=>{let n=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0,i=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:e,variables:n(),rules:i(),variant:r}};var C=new D,b=!1,rt=()=>{let e=i=>C.on("completed",a=>{a&&typeof a=="string"&&(i==null||i(a));}),o=i=>C.on("canceled",i),t=i=>C.on("closed",i),r=y=>c(void 0,[y],function*({appearance:i,onCanceled:a,onCompleted:s,publicKey:p,userData:d,options:l}){if(b)return;b=!0;let{fontSrc:f,rules:h,variables:m,variant:K}=T(i),$=H({fontSrc:f,publicKey:p,rules:h,variables:m,variant:K});yield C.open($,d,l),e(s),o(()=>{a==null||a(),n();}),t(n);}),n=()=>c(void 0,null,function*(){yield C.close(),b=!1;});return {open:r,close:n,createButton:g}},V=rt;var nt=e=>{window.setTimeout(e,0);},U=e=>typeof e=="function",it=e=>typeof e=="object"&&!!e,at=e=>{if(typeof window=="undefined")return;let o=()=>{let i=window.footprintAppearance;if(!(!i||!it(i)))return {fontSrc:i.fontSrc,rules:i.rules,theme:i.theme,variables:i.variables}},t=(i,a)=>{let s={};F.forEach(d=>{let l=a.getAttribute(`footprint-user-data-${d}`);l&&(s[d]=l);});let p={};O.forEach(d=>{let l=a.getAttribute(`footprint-option-${d}`);l&&(s[d]=l);}),e.open({publicKey:i,appearance:o(),onCanceled:()=>{var d;U(window.onFootprintCanceled)&&((d=window.onFootprintCanceled)==null||d.call(window));},onCompleted:d=>{var l;U(window.onFootprintCompleted)&&((l=window.onFootprintCompleted)==null||l.call(window,d));},userData:s,options:p});},r=()=>{let i=document.getElementById("footprint-button");if(!i)return;let a=i.getAttribute("data-public-key");if(!a)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(a,i);},n=(i,a)=>{nt(()=>{g(a).addEventListener("click",()=>{t(i,a);});});};document.addEventListener("DOMContentLoaded",()=>r());},M=at;var j=e=>c(void 0,null,function*(){let o=yield fetch("https://api.onefootprint.com/hosted/identify",{method:"POST",body:JSON.stringify(e)});if(!o.ok)throw Error(o.statusText);return (yield o.json()).user_found}),st=e=>c(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let o=e["id.email"],t=e["id.phone_number"];return o&&(yield j({identifier:{email:o}}))?!0:t?yield j({identifier:{phone_number:t}}):!1}),W=st;var q=V();M(q);var Dt=q;/*! Bundled license information: | ||
var ye=Object.defineProperty,ve=Object.defineProperties;var ge=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var $=(e,r,t)=>r in e?ye(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,C=(e,r)=>{for(var t in r||(r={}))U.call(r,t)&&$(e,t,r[t]);if(O)for(var t of O(r))j.call(r,t)&&$(e,t,r[t]);return e},x=(e,r)=>ve(e,ge(r));var L=(e,r)=>{var t={};for(var n in e)U.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&O)for(var n of O(e))r.indexOf(n)<0&&j.call(e,n)&&(t[n]=e[n]);return t};var m=(e,r,t)=>new Promise((n,o)=>{var a=i=>{try{c(t.next(i));}catch(s){o(s);}},d=i=>{try{c(t.throw(i));}catch(s){o(s);}},c=i=>i.done?n(i.value):Promise.resolve(i.value).then(a,d);c((t=t.apply(e,r)).next());});var h="application/x-postmate-v1+json",he=5,Pe=0,Ee=function(){return ++Pe};var Ce=function(r){var t=document.createElement("a");t.href=r;var n=t.protocol.length>4?t.protocol:window.location.protocol,o=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||n+"//"+o},we={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},N=function(r,t){return !(typeof t=="string"&&r.origin!==t||!r.data||typeof r.data=="object"&&!("postmate"in r.data)||r.data.type!==h||!we[r.data.postmate])},Ie=function(r,t){var n=typeof r[t]=="function"?r[t]():r[t];return P.Promise.resolve(n)},be=function(){function e(t){var n=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(o){if(!N(o,n.childOrigin))return !1;var a=((o||{}).data||{}).value||{},d=a.data,c=a.name;o.data.postmate==="emit"&&c in n.events&&n.events[c].forEach(function(i){i.call(n,d);});},this.parent.addEventListener("message",this.listener,!1);}var r=e.prototype;return r.get=function(n){var o=this;return new P.Promise(function(a){var d=Ee(),c=function i(s){s.data.uid===d&&s.data.postmate==="reply"&&(o.parent.removeEventListener("message",i,!1),a(s.data.value));};o.parent.addEventListener("message",c,!1),o.child.postMessage({postmate:"request",type:h,property:n,uid:d},o.childOrigin);})},r.call=function(n,o){this.child.postMessage({postmate:"call",type:h,property:n,data:o},this.childOrigin);},r.on=function(n,o){this.events[n]||(this.events[n]=[]),this.events[n].push(o);},r.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),Oe=function(){function e(t){var n=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(o){if(N(o,n.parentOrigin)){var a=o.data,d=a.property,c=a.uid,i=a.data;if(o.data.postmate==="call"){d in n.model&&typeof n.model[d]=="function"&&n.model[d](i);return}Ie(n.model,d).then(function(s){return o.source.postMessage({property:d,postmate:"reply",type:h,uid:c,value:s},o.origin)});}});}var r=e.prototype;return r.emit=function(n,o){this.parent.postMessage({postmate:"emit",type:h,value:{name:n,data:o}},this.parentOrigin);},e}(),P=function(){function e(t){var n=t.container,o=n===void 0?typeof o!="undefined"?o:document.body:n,a=t.model,d=t.url,c=t.name,i=c===void 0?"":c,s=t.allow,p=t.classListArray,f=p===void 0?[]:p;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=i||"",this.frame.classList.add.apply(this.frame.classList,f),s&&(this.frame.allow=s),o.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(d)}var r=e.prototype;return r.sendHandshake=function(n){var o=this,a=Ce(n),d=0,c;return new e.Promise(function(i,s){var p=function u(I){return N(I,a)?I.data.postmate==="handshake-reply"?(clearInterval(c),o.parent.removeEventListener("message",u,!1),o.childOrigin=I.origin,i(new be(o))):s("Failed handshake"):!1};o.parent.addEventListener("message",p,!1);var f=function(){d++,o.child.postMessage({postmate:"handshake",type:h,model:o.model},a),d===he&&clearInterval(c);},g=function(){f(),c=setInterval(f,500);};o.frame.attachEvent?o.frame.attachEvent("onload",g):o.frame.addEventListener("load",g),o.frame.src=n;})},e}();P.debug=!1;P.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();P.Model=function(){function e(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var r=e.prototype;return r.sendHandshakeReply=function(){var n=this;return new P.Promise(function(o,a){var d=function c(i){if(i.data.postmate){if(i.data.postmate==="handshake"){n.child.removeEventListener("message",c,!1),i.source.postMessage({postmate:"handshake-reply",type:h},i.origin),n.parentOrigin=i.origin;var s=i.data.model;return s&&Object.keys(s).forEach(function(p){n.model[p]=s[p];}),o(new Oe(n))}return a("Handshake Reply Failed")}};n.child.addEventListener("message",d,!1);})},e}();var q=P;var V=(o=>(o.closed="closed",o.canceled="canceled",o.completed="completed",o.clicked="clicked",o))(V||{}),H=(t=>(t.propsReceived="propsReceived",t.started="started",t))(H||{});var z="footprint-inline-container",J="footprint-body-locked",X="footprint-overlay",Y="footprint-overlay-container",Z=z,W=X,G="footprint-loading-indicator",y=(e,r)=>`${e}-${r}`,Q=e=>m(void 0,null,function*(){F(e),ke(e),yield Ve(e);}),ee=e=>{let r=y(Y,e),t=document.getElementById(r);if(t)return t;let n=document.createElement("div");return n.setAttribute("id",r),document.body.appendChild(n),n},Ve=e=>m(void 0,null,function*(){let r=y(Y,e),t=document.getElementById(r);if(!t)return;let n=t.querySelector("iframe.footprint-drawer");n&&(n==null||n.classList.add("footprint-drawer-closing"),yield new Promise(c=>{setTimeout(c,300);}));let o=t.querySelector("iframe.footprint-modal");o&&(o==null||o.classList.add("footprint-modal-closing"),yield new Promise(c=>{setTimeout(c,100);}));let a=y(W,e),d=document.getElementById(a);d&&(d.classList.add("footprint-overlay-fading"),yield new Promise(c=>{setTimeout(c,200);}),t.remove(),d.remove(),document.body.classList.remove(J));}),te=(e,r)=>{let t=y(Z,e),n=document.createElement("div");return n.classList.add(z),n.setAttribute("id",t),r.appendChild(n),n},ke=e=>{let r=y(Z,e),t=document.getElementById(r);t&&t.remove();},F=e=>{let r=y(G,e),t=document.getElementById(r);t&&t.remove();},S=(e,r)=>{let t=y(G,r),n=Ae(t);e.appendChild(n);},re=(e,r)=>{document.body.classList.add(J);let t=document.createElement("div"),n=y(W,r);return t.setAttribute("id",n),t.classList.add(X),e.appendChild(t),t},Ae=e=>{let r=document.createElement("div");r.setAttribute("id",e),r.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.classList.add("footprint-loading-spin");let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","24px"),n.setAttribute("height","24px"),n.setAttribute("fill","none"),n.setAttribute("aria-hidden","true");let o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(o),t.appendChild(n),r.appendChild(t),r};var Re=()=>`${Math.floor(Math.random()*1e3)}`,k=Re;var b=(o=>(o.Verify="verify",o.Form="form",o.Render="render",o.VerifyButton="verify-button",o))(b||{}),ne=(o=>(o.cardOnly="cardOnly",o.cardAndName="cardAndName",o.cardAndNameAndAddress="cardAndNameAndAddress",o.cardAndZip="cardAndZip",o))(ne||{});var _={["form"]:{["closed"]:"onClose",["canceled"]:"onCancel",["completed"]:"onComplete"},["verify"]:{["closed"]:"onClose",["canceled"]:"onCancel",["completed"]:"onComplete"},["verify-button"]:{["clicked"]:"onClick"},["render"]:{}},oe={["form"]:[],["verify"]:[],["render"]:[],["verify-button"]:[]};var ae={["verify"]:["modal","drawer"],["verify-button"]:["inline"],["form"]:["inline","modal","drawer"],["render"]:["inline"]},D=(e,r)=>{var o;if(!r)return;let t=(o=ae[e])!=null?o:[];if(!t.includes(r))throw new Error(`Invalid variant: ${JSON.stringify(r)}. Valid variants for ${e} are ${t.join(", ")}`)},w=e=>{var t;let r=(t=ae[e])!=null?t:[];if(!r.length)throw new Error(`Invalid kind: ${e}`);return r[0]},B=e=>{if(!e)throw new Error("Kind is required");if(!Object.values(b).includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${Object.values(b).join(", ")}}`)},xe=(e,r)=>{if(e==="inline"&&!r)throw new Error(`Inline component requires a containerId. Received ${r}`)},Le=e=>{let{kind:r}=e;if(r==="verify-button"){let t=e,{kind:n,appearance:o,variant:a,dialogVariant:d,onClick:c,label:i,containerId:s}=t,p=L(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return x(C({},p),{variant:d,kind:"verify"})}},ie=(e,r,t)=>{var d;let{kind:n}=e,o=(d=_[n])!=null?d:{},a={};return Object.entries(o).forEach(([c,i])=>{let s=c;if(!Object.values(V).includes(s))return;let p=e[i];(!p||typeof p!="function")&&(p=()=>{});let f=s==="closed"||s==="canceled",g=n==="verify-button"&&s==="clicked";a[s]=()=>{p(),f&&(r==null||r());let u=Le(e);g&&u&&(t==null||t(u));};}),a},se=e=>{var s;let i=e,{kind:r,appearance:t,containerId:n}=i,o=L(i,["kind","appearance","containerId"]),a=(s=_[r])!=null?s:{},d=Object.values(a);return Object.fromEntries(Object.entries(o).filter(([p])=>!d.includes(p)))},A=e=>{let{kind:r,variant:t,containerId:n}=e;B(r),D(r,t);let o=t||w(r);return xe(o,n),x(C({},e),{variant:o})};var Ne=e=>typeof e=="object"&&!!e,K=({fontSrc:e,variables:r={},rules:t={},variant:n}={})=>{let o=()=>Object.keys(r).length?encodeURIComponent(JSON.stringify(r)):void 0,a=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:e,variables:o(),rules:a(),variant:n}},de=()=>{let e=window.footprintAppearance;return !e||!Ne(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var Fe=e=>{let{kind:r}=e;return r==="verify"?Se(e):_e(e)},Se=e=>{let{appearance:r,publicKey:t,variant:n,kind:o}=e,{fontSrc:a,rules:d,variables:c}=K(r),i="https://id.onefootprint.com",s=new URLSearchParams;t&&s.append("public_key",t),c&&s.append("variables",c),d&&s.append("rules",d),a&&s.append("font_src",a),s.append("variant",n!=null?n:w(o));let p=s.toString();return `${i}?${p}`},_e=e=>{let{appearance:r,kind:t,variant:n}=e,{fontSrc:o,rules:a,variables:d}=K(r),c="https://components.onefootprint.com",i=new URLSearchParams;d&&i.append("variables",d),a&&i.append("rules",a),o&&i.append("font_src",o),i.append("variant",n!=null?n:w(t));let s=i.toString();return `${c}/${t}?${s}`},ce=Fe;var De=e=>{let r=null,t=!1,n=A(e),{variant:o,containerId:a}=n,d=o==="modal"||o==="drawer",c,i,s=k(),p=()=>{if(!r)throw new Error("Footprint should be initialized in order to listen events");let l=ie(n,c,i);Object.entries(l).forEach(([E,R])=>{r==null||r.on(E,R);});},f=()=>{if(!r)throw new Error("Footprint should be initialized in order to receive props");r.call("propsReceived",se(n));},g=()=>{if(d)return ee(s);if(!a)throw new Error("containerId is required when rendering inline");let l=document.getElementById(a);if(!l)throw new Error(`Could not find container with id ${a} while rendering footprint`);return te(s,l)},u=(l,E)=>{if(!E){F(s),r==null||r.frame.classList.remove(`footprint-${o}-loading`),r==null||r.frame.classList.add(`footprint-${o}-loaded`);return}if(d){let R=re(l,s);S(R,s);}else S(l,s);};return {props:n,isRendered:t,render:()=>m(void 0,null,function*(){if(t)return;let l=g();l&&(l.hasChildNodes()&&(l.innerHTML=""),t=!0,u(l,!0),r=yield new q({classListArray:[`footprint-${o}`,`footprint-${o}-loading`],container:l,name:`footprint-iframe-${s}`,url:ce(n),allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;"}),p(),u(l,!1),r.on("started",()=>{f();}));}),destroy:()=>m(void 0,null,function*(){t&&(t=!1,yield Q(s),r&&(r.destroy(),r=null));}),registerEvent:(l,E)=>{l==="renderSecondary"&&(i=E),l==="destroy"&&(c=E);}}},M=De;var v=e=>{let r=A(e);return JSON.stringify(r)},Be=()=>{let e={};return {getOrCreate:a=>{let d=v(a.props),c=Object.values(e).find(i=>v(i.iframe.props)===d);return c?c.iframe:(e[d]={iframe:a,secondaryIframes:{}},a)},remove:a=>{let d=v(a.props),c=e[d];c&&(Object.keys(c.secondaryIframes).forEach(i=>{c.secondaryIframes[i].destroy();}),delete e[d]);},getOrCreateSecondary:(a,d)=>{let c=v(a.props),i=v(d.props);if(!e[c])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:s}=e[c],p=Object.values(s).find(f=>v(f.props)===i);return p||(s[i]=d,d)},removeSecondary:(a,d)=>{let c=v(a.props),i=v(d.props);if(!e[c])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:s}=e[c],p=s[i];p&&(p.destroy(),delete s[i]);}}},pe=Be;var Ke=()=>{let e=pe();return {init:t=>{let n=M(t),o=()=>m(void 0,null,function*(){e.remove(n),yield n.destroy();}),a=i=>m(void 0,null,function*(){e.removeSecondary(n,i),yield i.destroy();}),d=i=>m(void 0,null,function*(){let s=M(i);s=e.getOrCreateSecondary(n,s),s.registerEvent("destroy",()=>{a(s);}),s.render();});return {render:()=>m(void 0,null,function*(){n=e.getOrCreate(n),n.registerEvent("destroy",o),n.registerEvent("renderSecondary",d),yield n.render();}),destroy:o}}}},Me=Ke(),T=Me;var Te=e=>{window.setTimeout(e,0);},le=e=>typeof e=="object"&&!!e,$e=e=>{if(typeof window=="undefined")return;let r=o=>{var c;let a=(c=window.footprintCallbacks)!=null?c:{};if(!le(a))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return oe[o].forEach(i=>{if(!a[i])throw Error(`Callback '${i}' must be defined in window.footprintCallbacks`)}),a},t=o=>{var u;let a=o.getAttribute("data-kind");B(a);let d=(u=o.getAttribute("data-variant"))!=null?u:w(a);D(a,d);let c=de(),i=r(a),s=o.getAttribute("data-props")||"",p;try{p=JSON.parse(s);}catch(I){throw Error("Could not parse `data-props` for footprint.")}if(!le(p))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let f=k();o.setAttribute("id",f),e.init(C(C({kind:a,variant:d,appearance:c,containerId:o.id},i),p)).render();},n=()=>{let o=document.querySelectorAll("[data-footprint]");o.length&&o.forEach(a=>{t(a);});};document.addEventListener("DOMContentLoaded",()=>Te(n));},me=$e;var fe=e=>m(void 0,null,function*(){let r=yield fetch("https://api.onefootprint.com/hosted/identify",{method:"POST",body:JSON.stringify(e)});if(!r.ok)throw Error(r.statusText);return (yield r.json()).user_found}),Ue=e=>m(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let r=e["id.email"],t=e["id.phone_number"];return r&&(yield fe({identifier:{email:r}}))?!0:t?yield fe({identifier:{phone_number:t}}):!1}),ue=Ue;var Mt=T;me(T);/*! Bundled license information: | ||
@@ -13,2 +13,2 @@ @onefootprint/postmate/build/postmate.es.js: | ||
export { w as FootprintInternalEvent, E as FootprintPublicEvent, Dt as default, W as identifyUser }; | ||
export { b as FootprintComponentKind, ne as FootprintFormType, H as FootprintPrivateEvent, V as FootprintPublicEvent, Mt as default, ue as identifyFootprintUser }; |
(function (exports) { | ||
'use strict'; | ||
var c=(e,o,t)=>new Promise((r,n)=>{var i=p=>{try{s(t.next(p));}catch(d){n(d);}},a=p=>{try{s(t.throw(p));}catch(d){n(d);}},s=p=>p.done?r(p.value):Promise.resolve(p.value).then(i,a);s((t=t.apply(e,o)).next());});var E=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(E||{}),w=(r=>(r.bootstrapDataReceived="bootstrapDataReceived",r.optionsReceived="optionsReceived",r.started="started",r))(w||{}),O=["showCompletionPage"],F=["id.email","id.phone_number","id.first_name","id.last_name","id.dob","id.address_line1","id.address_line2","id.city","id.state","id.country","id.zip","id.ssn9","id.ssn4"];var u="application/x-postmate-v1+json",Y=5,z=0,J=function(){return ++z};var Z=function(o){var t=document.createElement("a");t.href=o;var r=t.protocol.length>4?t.protocol:window.location.protocol,n=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||r+"//"+n},G={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},v=function(o,t){return !(typeof t=="string"&&o.origin!==t||!o.data||typeof o.data=="object"&&!("postmate"in o.data)||o.data.type!==u||!G[o.data.postmate])},Q=function(o,t){var r=typeof o[t]=="function"?o[t]():o[t];return S.Promise.resolve(r)},X=function(){function e(t){var r=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(n){if(!v(n,r.childOrigin))return !1;var i=((n||{}).data||{}).value||{},a=i.data,s=i.name;n.data.postmate==="emit"&&s in r.events&&r.events[s].forEach(function(p){p.call(r,a);});},this.parent.addEventListener("message",this.listener,!1);}var o=e.prototype;return o.get=function(r){var n=this;return new S.Promise(function(i){var a=J(),s=function p(d){d.data.uid===a&&d.data.postmate==="reply"&&(n.parent.removeEventListener("message",p,!1),i(d.data.value));};n.parent.addEventListener("message",s,!1),n.child.postMessage({postmate:"request",type:u,property:r,uid:a},n.childOrigin);})},o.call=function(r,n){this.child.postMessage({postmate:"call",type:u,property:r,data:n},this.childOrigin);},o.on=function(r,n){this.events[r]||(this.events[r]=[]),this.events[r].push(n);},o.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),tt=function(){function e(t){var r=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(n){if(v(n,r.parentOrigin)){var i=n.data,a=i.property,s=i.uid,p=i.data;if(n.data.postmate==="call"){a in r.model&&typeof r.model[a]=="function"&&r.model[a](p);return}Q(r.model,a).then(function(d){return n.source.postMessage({property:a,postmate:"reply",type:u,uid:s,value:d},n.origin)});}});}var o=e.prototype;return o.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:u,value:{name:r,data:n}},this.parentOrigin);},e}(),S=function(){function e(t){var r=t.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,i=t.model,a=t.url,s=t.name,p=s===void 0?"":s,d=t.allow,l=t.classListArray,y=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,y),d&&(this.frame.allow=d),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var o=e.prototype;return o.sendHandshake=function(r){var n=this,i=Z(r),a=0,s;return new e.Promise(function(p,d){var l=function h(m){return v(m,i)?m.data.postmate==="handshake-reply"?(clearInterval(s),n.parent.removeEventListener("message",h,!1),n.childOrigin=m.origin,p(new X(n))):d("Failed handshake"):!1};n.parent.addEventListener("message",l,!1);var y=function(){a++,n.child.postMessage({postmate:"handshake",type:u,model:n.model},i),a===Y&&clearInterval(s);},f=function(){y(),s=setInterval(y,500);};n.frame.attachEvent?n.frame.attachEvent("onload",f):n.frame.addEventListener("load",f),n.frame.src=r;})},e}();S.debug=!1;S.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();S.Model=function(){function e(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var o=e.prototype;return o.sendHandshakeReply=function(){var r=this;return new S.Promise(function(n,i){var a=function s(p){if(p.data.postmate){if(p.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),p.source.postMessage({postmate:"handshake-reply",type:u},p.origin),r.parentOrigin=p.origin;var d=p.data.model;return d&&Object.keys(d).forEach(function(l){r.model[l]=d[l];}),n(new tt(r))}return i("Handshake Reply Failed")}};r.child.addEventListener("message",a,!1);})},e}();var k=S;var A="footprint-container",_="footprint-overlay",L="footprint-loading-indicator",g=e=>{if(!e)throw new Error("A container is required to create a Footprint button");let o=P();return e.appendChild(o),o},x=e=>{document.body.classList.add("footprint-body-locked");let o=document.createElement("div");o.setAttribute("id",_);let t=ot(L);o.appendChild(t),o.classList.add("footprint-overlay"),e.appendChild(o);},I=()=>{let e=document.getElementById(L);e&&e.remove();},R=()=>{document.body.classList.remove("footprint-body-locked");let e=document.getElementById(_);e&&e.remove();},N=()=>{let e=document.getElementById(A);if(e)return e;let o=document.createElement("div");return o.setAttribute("id",A),document.body.appendChild(o),o},ot=e=>{let o=document.createElement("div");o.setAttribute("id",e),o.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.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),t.appendChild(r),o.appendChild(t),o},et=()=>{let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width","24px"),e.setAttribute("height","24px"),e.setAttribute("fill","none"),e.setAttribute("aria-hidden","true");let o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M14.66 14h2.666v-2.36a2.666 2.666 0 1 1 0-4.614V4H6.66v16h4.666v-2.666A3.333 3.333 0 0 1 14.66 14Z"),o.setAttribute("fill","#76fb8f"),e.appendChild(o),e},P=()=>{let e=et(),o=document.createElement("button");o.appendChild(e);let t=document.createElement("span");return t.innerText="Verify with Footprint",o.appendChild(t),o.classList.add("footprint-button"),o};var B=class{constructor(){this.child=null;this.handleIframeLoaded=()=>{var o,t;I(),(o=this.child)==null||o.frame.classList.remove("footprint-modal-loading"),(t=this.child)==null||t.frame.classList.add("footprint-modal-loaded");};}sendOptions(o){var t;o&&((t=this.child)==null||t.call("optionsReceived",o));}bootstrap(o){var t;o&&((t=this.child)==null||t.call("bootstrapDataReceived",o));}open(o,t,r){return c(this,null,function*(){let n=N();x(n),this.child=yield new k({classListArray:["footprint-modal","footprint-modal-loading"],container:n,name:"footprint-iframe",url:o,allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;"}),this.handleIframeLoaded(),this.child.on("started",()=>{this.bootstrap(t),this.sendOptions(r);});})}on(o,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(o,t)}close(){R(),this.child&&this.child.destroy();}createButton(o){let t=P();return o.appendChild(t),t}},D=B;var H=e=>{let o="https://id.onefootprint.com",{publicKey:t,variables:r,rules:n,fontSrc:i,variant:a}=e,s=new URLSearchParams;return t&&s.append("public_key",t),r&&s.append("variables",r),n&&s.append("rules",n),a&&s.append("variant",a),i&&s.append("font_src",i),`${o}?${s.toString()}`},T=({fontSrc:e,variables:o={},rules:t={},variant:r}={})=>{let n=()=>Object.keys(o).length?encodeURIComponent(JSON.stringify(o)):void 0,i=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:e,variables:n(),rules:i(),variant:r}};var C=new D,b=!1,rt=()=>{let e=i=>C.on("completed",a=>{a&&typeof a=="string"&&(i==null||i(a));}),o=i=>C.on("canceled",i),t=i=>C.on("closed",i),r=y=>c(void 0,[y],function*({appearance:i,onCanceled:a,onCompleted:s,publicKey:p,userData:d,options:l}){if(b)return;b=!0;let{fontSrc:f,rules:h,variables:m,variant:K}=T(i),$=H({fontSrc:f,publicKey:p,rules:h,variables:m,variant:K});yield C.open($,d,l),e(s),o(()=>{a==null||a(),n();}),t(n);}),n=()=>c(void 0,null,function*(){yield C.close(),b=!1;});return {open:r,close:n,createButton:g}},V=rt;var nt=e=>{window.setTimeout(e,0);},U=e=>typeof e=="function",it=e=>typeof e=="object"&&!!e,at=e=>{if(typeof window=="undefined")return;let o=()=>{let i=window.footprintAppearance;if(!(!i||!it(i)))return {fontSrc:i.fontSrc,rules:i.rules,theme:i.theme,variables:i.variables}},t=(i,a)=>{let s={};F.forEach(d=>{let l=a.getAttribute(`footprint-user-data-${d}`);l&&(s[d]=l);});let p={};O.forEach(d=>{let l=a.getAttribute(`footprint-option-${d}`);l&&(s[d]=l);}),e.open({publicKey:i,appearance:o(),onCanceled:()=>{var d;U(window.onFootprintCanceled)&&((d=window.onFootprintCanceled)==null||d.call(window));},onCompleted:d=>{var l;U(window.onFootprintCompleted)&&((l=window.onFootprintCompleted)==null||l.call(window,d));},userData:s,options:p});},r=()=>{let i=document.getElementById("footprint-button");if(!i)return;let a=i.getAttribute("data-public-key");if(!a)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(a,i);},n=(i,a)=>{nt(()=>{g(a).addEventListener("click",()=>{t(i,a);});});};document.addEventListener("DOMContentLoaded",()=>r());},M=at;var j=e=>c(void 0,null,function*(){let o=yield fetch("https://api.onefootprint.com/hosted/identify",{method:"POST",body:JSON.stringify(e)});if(!o.ok)throw Error(o.statusText);return (yield o.json()).user_found}),st=e=>c(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let o=e["id.email"],t=e["id.phone_number"];return o&&(yield j({identifier:{email:o}}))?!0:t?yield j({identifier:{phone_number:t}}):!1}),W=st;var q=V();M(q);var Dt=q;/*! Bundled license information: | ||
var ye=Object.defineProperty,ve=Object.defineProperties;var ge=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var $=(e,r,t)=>r in e?ye(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,C=(e,r)=>{for(var t in r||(r={}))U.call(r,t)&&$(e,t,r[t]);if(O)for(var t of O(r))j.call(r,t)&&$(e,t,r[t]);return e},x=(e,r)=>ve(e,ge(r));var L=(e,r)=>{var t={};for(var n in e)U.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&O)for(var n of O(e))r.indexOf(n)<0&&j.call(e,n)&&(t[n]=e[n]);return t};var m=(e,r,t)=>new Promise((n,o)=>{var a=i=>{try{c(t.next(i));}catch(s){o(s);}},d=i=>{try{c(t.throw(i));}catch(s){o(s);}},c=i=>i.done?n(i.value):Promise.resolve(i.value).then(a,d);c((t=t.apply(e,r)).next());});var h="application/x-postmate-v1+json",he=5,Pe=0,Ee=function(){return ++Pe};var Ce=function(r){var t=document.createElement("a");t.href=r;var n=t.protocol.length>4?t.protocol:window.location.protocol,o=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||n+"//"+o},we={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},N=function(r,t){return !(typeof t=="string"&&r.origin!==t||!r.data||typeof r.data=="object"&&!("postmate"in r.data)||r.data.type!==h||!we[r.data.postmate])},Ie=function(r,t){var n=typeof r[t]=="function"?r[t]():r[t];return P.Promise.resolve(n)},be=function(){function e(t){var n=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(o){if(!N(o,n.childOrigin))return !1;var a=((o||{}).data||{}).value||{},d=a.data,c=a.name;o.data.postmate==="emit"&&c in n.events&&n.events[c].forEach(function(i){i.call(n,d);});},this.parent.addEventListener("message",this.listener,!1);}var r=e.prototype;return r.get=function(n){var o=this;return new P.Promise(function(a){var d=Ee(),c=function i(s){s.data.uid===d&&s.data.postmate==="reply"&&(o.parent.removeEventListener("message",i,!1),a(s.data.value));};o.parent.addEventListener("message",c,!1),o.child.postMessage({postmate:"request",type:h,property:n,uid:d},o.childOrigin);})},r.call=function(n,o){this.child.postMessage({postmate:"call",type:h,property:n,data:o},this.childOrigin);},r.on=function(n,o){this.events[n]||(this.events[n]=[]),this.events[n].push(o);},r.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),Oe=function(){function e(t){var n=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(o){if(N(o,n.parentOrigin)){var a=o.data,d=a.property,c=a.uid,i=a.data;if(o.data.postmate==="call"){d in n.model&&typeof n.model[d]=="function"&&n.model[d](i);return}Ie(n.model,d).then(function(s){return o.source.postMessage({property:d,postmate:"reply",type:h,uid:c,value:s},o.origin)});}});}var r=e.prototype;return r.emit=function(n,o){this.parent.postMessage({postmate:"emit",type:h,value:{name:n,data:o}},this.parentOrigin);},e}(),P=function(){function e(t){var n=t.container,o=n===void 0?typeof o!="undefined"?o:document.body:n,a=t.model,d=t.url,c=t.name,i=c===void 0?"":c,s=t.allow,p=t.classListArray,f=p===void 0?[]:p;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=i||"",this.frame.classList.add.apply(this.frame.classList,f),s&&(this.frame.allow=s),o.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(d)}var r=e.prototype;return r.sendHandshake=function(n){var o=this,a=Ce(n),d=0,c;return new e.Promise(function(i,s){var p=function u(I){return N(I,a)?I.data.postmate==="handshake-reply"?(clearInterval(c),o.parent.removeEventListener("message",u,!1),o.childOrigin=I.origin,i(new be(o))):s("Failed handshake"):!1};o.parent.addEventListener("message",p,!1);var f=function(){d++,o.child.postMessage({postmate:"handshake",type:h,model:o.model},a),d===he&&clearInterval(c);},g=function(){f(),c=setInterval(f,500);};o.frame.attachEvent?o.frame.attachEvent("onload",g):o.frame.addEventListener("load",g),o.frame.src=n;})},e}();P.debug=!1;P.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();P.Model=function(){function e(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var r=e.prototype;return r.sendHandshakeReply=function(){var n=this;return new P.Promise(function(o,a){var d=function c(i){if(i.data.postmate){if(i.data.postmate==="handshake"){n.child.removeEventListener("message",c,!1),i.source.postMessage({postmate:"handshake-reply",type:h},i.origin),n.parentOrigin=i.origin;var s=i.data.model;return s&&Object.keys(s).forEach(function(p){n.model[p]=s[p];}),o(new Oe(n))}return a("Handshake Reply Failed")}};n.child.addEventListener("message",d,!1);})},e}();var q=P;var V=(o=>(o.closed="closed",o.canceled="canceled",o.completed="completed",o.clicked="clicked",o))(V||{}),H=(t=>(t.propsReceived="propsReceived",t.started="started",t))(H||{});var z="footprint-inline-container",J="footprint-body-locked",X="footprint-overlay",Y="footprint-overlay-container",Z=z,W=X,G="footprint-loading-indicator",y=(e,r)=>`${e}-${r}`,Q=e=>m(void 0,null,function*(){F(e),ke(e),yield Ve(e);}),ee=e=>{let r=y(Y,e),t=document.getElementById(r);if(t)return t;let n=document.createElement("div");return n.setAttribute("id",r),document.body.appendChild(n),n},Ve=e=>m(void 0,null,function*(){let r=y(Y,e),t=document.getElementById(r);if(!t)return;let n=t.querySelector("iframe.footprint-drawer");n&&(n==null||n.classList.add("footprint-drawer-closing"),yield new Promise(c=>{setTimeout(c,300);}));let o=t.querySelector("iframe.footprint-modal");o&&(o==null||o.classList.add("footprint-modal-closing"),yield new Promise(c=>{setTimeout(c,100);}));let a=y(W,e),d=document.getElementById(a);d&&(d.classList.add("footprint-overlay-fading"),yield new Promise(c=>{setTimeout(c,200);}),t.remove(),d.remove(),document.body.classList.remove(J));}),te=(e,r)=>{let t=y(Z,e),n=document.createElement("div");return n.classList.add(z),n.setAttribute("id",t),r.appendChild(n),n},ke=e=>{let r=y(Z,e),t=document.getElementById(r);t&&t.remove();},F=e=>{let r=y(G,e),t=document.getElementById(r);t&&t.remove();},S=(e,r)=>{let t=y(G,r),n=Ae(t);e.appendChild(n);},re=(e,r)=>{document.body.classList.add(J);let t=document.createElement("div"),n=y(W,r);return t.setAttribute("id",n),t.classList.add(X),e.appendChild(t),t},Ae=e=>{let r=document.createElement("div");r.setAttribute("id",e),r.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.classList.add("footprint-loading-spin");let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","24px"),n.setAttribute("height","24px"),n.setAttribute("fill","none"),n.setAttribute("aria-hidden","true");let o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(o),t.appendChild(n),r.appendChild(t),r};var Re=()=>`${Math.floor(Math.random()*1e3)}`,k=Re;var b=(o=>(o.Verify="verify",o.Form="form",o.Render="render",o.VerifyButton="verify-button",o))(b||{}),ne=(o=>(o.cardOnly="cardOnly",o.cardAndName="cardAndName",o.cardAndNameAndAddress="cardAndNameAndAddress",o.cardAndZip="cardAndZip",o))(ne||{});var _={["form"]:{["closed"]:"onClose",["canceled"]:"onCancel",["completed"]:"onComplete"},["verify"]:{["closed"]:"onClose",["canceled"]:"onCancel",["completed"]:"onComplete"},["verify-button"]:{["clicked"]:"onClick"},["render"]:{}},oe={["form"]:[],["verify"]:[],["render"]:[],["verify-button"]:[]};var ae={["verify"]:["modal","drawer"],["verify-button"]:["inline"],["form"]:["inline","modal","drawer"],["render"]:["inline"]},D=(e,r)=>{var o;if(!r)return;let t=(o=ae[e])!=null?o:[];if(!t.includes(r))throw new Error(`Invalid variant: ${JSON.stringify(r)}. Valid variants for ${e} are ${t.join(", ")}`)},w=e=>{var t;let r=(t=ae[e])!=null?t:[];if(!r.length)throw new Error(`Invalid kind: ${e}`);return r[0]},B=e=>{if(!e)throw new Error("Kind is required");if(!Object.values(b).includes(e))throw new Error(`Invalid kind: ${e}. Valid kinds are: ${Object.values(b).join(", ")}}`)},xe=(e,r)=>{if(e==="inline"&&!r)throw new Error(`Inline component requires a containerId. Received ${r}`)},Le=e=>{let{kind:r}=e;if(r==="verify-button"){let t=e,{kind:n,appearance:o,variant:a,dialogVariant:d,onClick:c,label:i,containerId:s}=t,p=L(t,["kind","appearance","variant","dialogVariant","onClick","label","containerId"]);return x(C({},p),{variant:d,kind:"verify"})}},ie=(e,r,t)=>{var d;let{kind:n}=e,o=(d=_[n])!=null?d:{},a={};return Object.entries(o).forEach(([c,i])=>{let s=c;if(!Object.values(V).includes(s))return;let p=e[i];(!p||typeof p!="function")&&(p=()=>{});let f=s==="closed"||s==="canceled",g=n==="verify-button"&&s==="clicked";a[s]=()=>{p(),f&&(r==null||r());let u=Le(e);g&&u&&(t==null||t(u));};}),a},se=e=>{var s;let i=e,{kind:r,appearance:t,containerId:n}=i,o=L(i,["kind","appearance","containerId"]),a=(s=_[r])!=null?s:{},d=Object.values(a);return Object.fromEntries(Object.entries(o).filter(([p])=>!d.includes(p)))},A=e=>{let{kind:r,variant:t,containerId:n}=e;B(r),D(r,t);let o=t||w(r);return xe(o,n),x(C({},e),{variant:o})};var Ne=e=>typeof e=="object"&&!!e,K=({fontSrc:e,variables:r={},rules:t={},variant:n}={})=>{let o=()=>Object.keys(r).length?encodeURIComponent(JSON.stringify(r)):void 0,a=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:e,variables:o(),rules:a(),variant:n}},de=()=>{let e=window.footprintAppearance;return !e||!Ne(e)?{}:{fontSrc:e.fontSrc,rules:e.rules,theme:e.theme,variables:e.variables}};var Fe=e=>{let{kind:r}=e;return r==="verify"?Se(e):_e(e)},Se=e=>{let{appearance:r,publicKey:t,variant:n,kind:o}=e,{fontSrc:a,rules:d,variables:c}=K(r),i="https://id.onefootprint.com",s=new URLSearchParams;t&&s.append("public_key",t),c&&s.append("variables",c),d&&s.append("rules",d),a&&s.append("font_src",a),s.append("variant",n!=null?n:w(o));let p=s.toString();return `${i}?${p}`},_e=e=>{let{appearance:r,kind:t,variant:n}=e,{fontSrc:o,rules:a,variables:d}=K(r),c="https://components.onefootprint.com",i=new URLSearchParams;d&&i.append("variables",d),a&&i.append("rules",a),o&&i.append("font_src",o),i.append("variant",n!=null?n:w(t));let s=i.toString();return `${c}/${t}?${s}`},ce=Fe;var De=e=>{let r=null,t=!1,n=A(e),{variant:o,containerId:a}=n,d=o==="modal"||o==="drawer",c,i,s=k(),p=()=>{if(!r)throw new Error("Footprint should be initialized in order to listen events");let l=ie(n,c,i);Object.entries(l).forEach(([E,R])=>{r==null||r.on(E,R);});},f=()=>{if(!r)throw new Error("Footprint should be initialized in order to receive props");r.call("propsReceived",se(n));},g=()=>{if(d)return ee(s);if(!a)throw new Error("containerId is required when rendering inline");let l=document.getElementById(a);if(!l)throw new Error(`Could not find container with id ${a} while rendering footprint`);return te(s,l)},u=(l,E)=>{if(!E){F(s),r==null||r.frame.classList.remove(`footprint-${o}-loading`),r==null||r.frame.classList.add(`footprint-${o}-loaded`);return}if(d){let R=re(l,s);S(R,s);}else S(l,s);};return {props:n,isRendered:t,render:()=>m(void 0,null,function*(){if(t)return;let l=g();l&&(l.hasChildNodes()&&(l.innerHTML=""),t=!0,u(l,!0),r=yield new q({classListArray:[`footprint-${o}`,`footprint-${o}-loading`],container:l,name:`footprint-iframe-${s}`,url:ce(n),allow:"otp-credentials; publickey-credentials-get *; camera *; clipboard-write;"}),p(),u(l,!1),r.on("started",()=>{f();}));}),destroy:()=>m(void 0,null,function*(){t&&(t=!1,yield Q(s),r&&(r.destroy(),r=null));}),registerEvent:(l,E)=>{l==="renderSecondary"&&(i=E),l==="destroy"&&(c=E);}}},M=De;var v=e=>{let r=A(e);return JSON.stringify(r)},Be=()=>{let e={};return {getOrCreate:a=>{let d=v(a.props),c=Object.values(e).find(i=>v(i.iframe.props)===d);return c?c.iframe:(e[d]={iframe:a,secondaryIframes:{}},a)},remove:a=>{let d=v(a.props),c=e[d];c&&(Object.keys(c.secondaryIframes).forEach(i=>{c.secondaryIframes[i].destroy();}),delete e[d]);},getOrCreateSecondary:(a,d)=>{let c=v(a.props),i=v(d.props);if(!e[c])throw new Error("iframe manager: primary iframe does not exist while adding secondary");let{secondaryIframes:s}=e[c],p=Object.values(s).find(f=>v(f.props)===i);return p||(s[i]=d,d)},removeSecondary:(a,d)=>{let c=v(a.props),i=v(d.props);if(!e[c])throw new Error("iframe manager: primary iframe does not exist while removing secondary");let{secondaryIframes:s}=e[c],p=s[i];p&&(p.destroy(),delete s[i]);}}},pe=Be;var Ke=()=>{let e=pe();return {init:t=>{let n=M(t),o=()=>m(void 0,null,function*(){e.remove(n),yield n.destroy();}),a=i=>m(void 0,null,function*(){e.removeSecondary(n,i),yield i.destroy();}),d=i=>m(void 0,null,function*(){let s=M(i);s=e.getOrCreateSecondary(n,s),s.registerEvent("destroy",()=>{a(s);}),s.render();});return {render:()=>m(void 0,null,function*(){n=e.getOrCreate(n),n.registerEvent("destroy",o),n.registerEvent("renderSecondary",d),yield n.render();}),destroy:o}}}},Me=Ke(),T=Me;var Te=e=>{window.setTimeout(e,0);},le=e=>typeof e=="object"&&!!e,$e=e=>{if(typeof window=="undefined")return;let r=o=>{var c;let a=(c=window.footprintCallbacks)!=null?c:{};if(!le(a))throw Error("`window.footprintCallbacks` must be a valid mapping from callback names to functions.");return oe[o].forEach(i=>{if(!a[i])throw Error(`Callback '${i}' must be defined in window.footprintCallbacks`)}),a},t=o=>{var u;let a=o.getAttribute("data-kind");B(a);let d=(u=o.getAttribute("data-variant"))!=null?u:w(a);D(a,d);let c=de(),i=r(a),s=o.getAttribute("data-props")||"",p;try{p=JSON.parse(s);}catch(I){throw Error("Could not parse `data-props` for footprint.")}if(!le(p))throw Error("`data-props` on the footprint element has to be a valid JSON object stringified.");let f=k();o.setAttribute("id",f),e.init(C(C({kind:a,variant:d,appearance:c,containerId:o.id},i),p)).render();},n=()=>{let o=document.querySelectorAll("[data-footprint]");o.length&&o.forEach(a=>{t(a);});};document.addEventListener("DOMContentLoaded",()=>Te(n));},me=$e;var fe=e=>m(void 0,null,function*(){let r=yield fetch("https://api.onefootprint.com/hosted/identify",{method:"POST",body:JSON.stringify(e)});if(!r.ok)throw Error(r.statusText);return (yield r.json()).user_found}),Ue=e=>m(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let r=e["id.email"],t=e["id.phone_number"];return r&&(yield fe({identifier:{email:r}}))?!0:t?yield fe({identifier:{phone_number:t}}):!1}),ue=Ue;var Mt=T;me(T);/*! Bundled license information: | ||
@@ -16,6 +16,8 @@ @onefootprint/postmate/build/postmate.es.js: | ||
exports.FootprintInternalEvent = w; | ||
exports.FootprintPublicEvent = E; | ||
exports.default = Dt; | ||
exports.identifyUser = W; | ||
exports.FootprintComponentKind = b; | ||
exports.FootprintFormType = ne; | ||
exports.FootprintPrivateEvent = H; | ||
exports.FootprintPublicEvent = V; | ||
exports.default = Mt; | ||
exports.identifyFootprintUser = ue; | ||
@@ -22,0 +24,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"main": "./dist/footprint-js.umd.js", | ||
@@ -8,0 +8,0 @@ "module": "./dist/footprint-js.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
59792
480