@onefootprint/footprint-js
Advanced tools
Comparing version 0.6.1 to 1.0.0
@@ -133,3 +133,3 @@ import * as CSS from 'csstype'; | ||
}; | ||
declare type ShowFootprint = { | ||
declare type OpenFootprint = { | ||
appearance?: FootprintAppearance; | ||
@@ -139,8 +139,9 @@ onCanceled?: () => void; | ||
publicKey?: string; | ||
userData?: UserData; | ||
}; | ||
declare type Footprint = { | ||
show: (options: ShowFootprint) => Promise<void>; | ||
open: (options: OpenFootprint) => Promise<void>; | ||
close: () => Promise<void>; | ||
}; | ||
declare enum FootprintEvents { | ||
declare enum FootprintPublicEvent { | ||
closed = "closed", | ||
@@ -150,5 +151,9 @@ completed = "completed", | ||
} | ||
declare enum FootprintInternalEvent { | ||
bootstrapDataReceived = "bootstrapDataReceived", | ||
ready = "ready" | ||
} | ||
declare type UserData = { | ||
email?: string; | ||
phoneNumber?: string; | ||
email?: string | null; | ||
phoneNumber?: string | null; | ||
}; | ||
@@ -159,3 +164,3 @@ | ||
declare const footprint: { | ||
show: ({ appearance, publicKey, onCompleted, onCanceled, }: ShowFootprint) => Promise<void>; | ||
open: ({ appearance, onCanceled, onCompleted, publicKey, userData, }: OpenFootprint) => Promise<void>; | ||
close: () => Promise<void>; | ||
@@ -165,2 +170,2 @@ createButton: (container?: HTMLElement | undefined) => HTMLButtonElement; | ||
export { Footprint, FootprintAppearance, FootprintAppearanceParams, FootprintAppearanceRules, FootprintAppearanceTheme, FootprintAppearanceVariables, FootprintEvents, FootprintExternalStyles, FootprintMainStyles, FootprintShowParams, ShowFootprint, UserData, footprint as default, identifyUser }; | ||
export { Footprint, FootprintAppearance, FootprintAppearanceParams, FootprintAppearanceRules, FootprintAppearanceTheme, FootprintAppearanceVariables, FootprintExternalStyles, FootprintInternalEvent, FootprintMainStyles, FootprintPublicEvent, FootprintShowParams, OpenFootprint, UserData, footprint as default, identifyUser }; |
@@ -1,12 +0,12 @@ | ||
var w=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var E=(t,o)=>{var e={};for(var r in t)K.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&w)for(var r of w(t))o.indexOf(r)<0&&J.call(t,r)&&(e[r]=t[r]);return e};var y=(t,o,e)=>new Promise((r,n)=>{var a=d=>{try{s(e.next(d));}catch(p){n(p);}},i=d=>{try{s(e.throw(d));}catch(p){n(p);}},s=d=>d.done?r(d.value):Promise.resolve(d.value).then(a,i);s((e=e.apply(t,o)).next());});var A=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(A||{});var m="application/x-postmate-v1+json",z=5,Y=0,Z=function(){return ++Y};var G=function(o){var e=document.createElement("a");e.href=o;var r=e.protocol.length>4?e.protocol:window.location.protocol,n=e.host.length?e.port==="80"||e.port==="443"?e.hostname:e.host:window.location.host;return e.origin||r+"//"+n},Q={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function(o,e){return !(typeof e=="string"&&o.origin!==e||!o.data||typeof o.data=="object"&&!("postmate"in o.data)||o.data.type!==m||!Q[o.data.postmate])},X=function(o,e){var r=typeof o[e]=="function"?o[e]():o[e];return f.Promise.resolve(r)},tt=function(){function t(e){var r=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},this.listener=function(n){if(!P(n,r.childOrigin))return !1;var a=((n||{}).data||{}).value||{},i=a.data,s=a.name;n.data.postmate==="emit"&&s in r.events&&r.events[s].call(r,i);},this.parent.addEventListener("message",this.listener,!1);}var o=t.prototype;return o.get=function(r){var n=this;return new f.Promise(function(a){var i=Z(),s=function d(p){p.data.uid===i&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",d,!1),a(p.data.value));};n.parent.addEventListener("message",s,!1),n.child.postMessage({postmate:"request",type:m,property:r,uid:i},n.childOrigin);})},o.call=function(r,n){this.child.postMessage({postmate:"call",type:m,property:r,data:n},this.childOrigin);},o.on=function(r,n){this.events[r]=n;},o.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},t}(),et=function(){function t(e){var r=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,this.child.addEventListener("message",function(n){if(!!P(n,r.parentOrigin)){var a=n.data,i=a.property,s=a.uid,d=a.data;if(n.data.postmate==="call"){i in r.model&&typeof r.model[i]=="function"&&r.model[i](d);return}X(r.model,i).then(function(p){return n.source.postMessage({property:i,postmate:"reply",type:m,uid:s,value:p},n.origin)});}});}var o=t.prototype;return o.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:m,value:{name:r,data:n}},this.parentOrigin);},t}(),f=function(){function t(e){var r=e.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,a=e.model,i=e.url,s=e.name,d=e.classListArray,p=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(i)}var o=t.prototype;return o.sendHandshake=function(r){var n=this,a=G(r),i=0,s;return new t.Promise(function(d,p){var c=function l(h){return P(h,a)?h.data.postmate==="handshake-reply"?(clearInterval(s),n.parent.removeEventListener("message",l,!1),n.childOrigin=h.origin,d(new tt(n))):p("Failed handshake"):!1};n.parent.addEventListener("message",c,!1);var u=function(){i++,n.child.postMessage({postmate:"handshake",type:m,model:n.model},a),i===z&&clearInterval(s);},S=function(){u(),s=setInterval(u,500);};n.frame.attachEvent?n.frame.attachEvent("onload",S):n.frame.onload=S,n.frame.src=r;})},t}();f.debug=!1;f.Promise=function(){try{return window?window.Promise:Promise}catch(t){return null}}();f.Model=function(){function t(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}var o=t.prototype;return o.sendHandshakeReply=function(){var r=this;return new f.Promise(function(n,a){var i=function s(d){if(!!d.data.postmate){if(d.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),d.source.postMessage({postmate:"handshake-reply",type:m},d.origin),r.parentOrigin=d.origin;var p=d.data.model;return p&&Object.keys(p).forEach(function(c){r.model[c]=p[c];}),n(new et(r))}return a("Handshake Reply Failed")}};r.child.addEventListener("message",i,!1);})},t}();var F=f;var k="footprint-container",O="footprint-overlay",x="footprint-loading-indicator",ot="footprint-custom-styles",rt=t=>{if(typeof window=="undefined")return;let o=document.getElementById(ot);o&&o.remove();let e=document.createElement("style");e.setAttribute("id","footprint-custom-styles"),e.textContent=t,document.head.append(e);},g=(t,o)=>o?`${t}: ${o}`:"",L=({variables:t={}})=>{rt(` | ||
var w=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var E=(e,o)=>{var t={};for(var r in e)z.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&w)for(var r of w(e))o.indexOf(r)<0&&Y.call(e,r)&&(t[r]=e[r]);return t};var S=(e,o,t)=>new Promise((r,n)=>{var a=s=>{try{d(t.next(s));}catch(p){n(p);}},i=s=>{try{d(t.throw(s));}catch(p){n(p);}},d=s=>s.done?r(s.value):Promise.resolve(s.value).then(a,i);d((t=t.apply(e,o)).next());});var A=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(A||{}),F=(t=>(t.bootstrapDataReceived="bootstrapDataReceived",t.ready="ready",t))(F||{});var h="application/x-postmate-v1+json",Z=5,G=0,Q=function(){return ++G};var X=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},tt={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function(o,t){return !(typeof t=="string"&&o.origin!==t||!o.data||typeof o.data=="object"&&!("postmate"in o.data)||o.data.type!==h||!tt[o.data.postmate])},et=function(o,t){var r=typeof o[t]=="function"?o[t]():o[t];return m.Promise.resolve(r)},ot=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(!P(n,r.childOrigin))return !1;var a=((n||{}).data||{}).value||{},i=a.data,d=a.name;n.data.postmate==="emit"&&d in r.events&&r.events[d].call(r,i);},this.parent.addEventListener("message",this.listener,!1);}var o=e.prototype;return o.get=function(r){var n=this;return new m.Promise(function(a){var i=Q(),d=function s(p){p.data.uid===i&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",s,!1),a(p.data.value));};n.parent.addEventListener("message",d,!1),n.child.postMessage({postmate:"request",type:h,property:r,uid:i},n.childOrigin);})},o.call=function(r,n){this.child.postMessage({postmate:"call",type:h,property:r,data:n},this.childOrigin);},o.on=function(r,n){this.events[r]=n;},o.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),rt=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(!!P(n,r.parentOrigin)){var a=n.data,i=a.property,d=a.uid,s=a.data;if(n.data.postmate==="call"){i in r.model&&typeof r.model[i]=="function"&&r.model[i](s);return}et(r.model,i).then(function(p){return n.source.postMessage({property:i,postmate:"reply",type:h,uid:d,value:p},n.origin)});}});}var o=e.prototype;return o.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:h,value:{name:r,data:n}},this.parentOrigin);},e}(),m=function(){function e(t){var r=t.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,a=t.model,i=t.url,d=t.name,s=t.classListArray,p=s===void 0?[]:s;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=d||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(i)}var o=e.prototype;return o.sendHandshake=function(r){var n=this,a=X(r),i=0,d;return new e.Promise(function(s,p){var l=function c(y){return P(y,a)?y.data.postmate==="handshake-reply"?(clearInterval(d),n.parent.removeEventListener("message",c,!1),n.childOrigin=y.origin,s(new ot(n))):p("Failed handshake"):!1};n.parent.addEventListener("message",l,!1);var g=function(){i++,n.child.postMessage({postmate:"handshake",type:h,model:n.model},a),i===Z&&clearInterval(d);},u=function(){g(),d=setInterval(g,500);};n.frame.attachEvent?n.frame.attachEvent("onload",u):n.frame.onload=u,n.frame.src=r;})},e}();m.debug=!1;m.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();m.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 m.Promise(function(n,a){var i=function d(s){if(!!s.data.postmate){if(s.data.postmate==="handshake"){r.child.removeEventListener("message",d,!1),s.source.postMessage({postmate:"handshake-reply",type:h},s.origin),r.parentOrigin=s.origin;var p=s.data.model;return p&&Object.keys(p).forEach(function(l){r.model[l]=p[l];}),n(new rt(r))}return a("Handshake Reply Failed")}};r.child.addEventListener("message",i,!1);})},e}();var k=m;var O="footprint-container",x="footprint-overlay",L="footprint-loading-indicator",nt="footprint-custom-styles",it=e=>{if(typeof window=="undefined")return;let o=document.getElementById(nt);o&&o.remove();let t=document.createElement("style");t.setAttribute("id","footprint-custom-styles"),t.textContent=e,document.head.append(t);},f=(e,o)=>o?`${e}: ${o}`:"",R=({variables:e={}})=>{it(` | ||
:root { | ||
${g("--fp-fp-button-height",t.fpButtonHeight)} | ||
${g("--fp-fp-button-border-radius",t.fpButtonBorderRadius)} | ||
${g("--fp-loading-bg",t.loadingBg)} | ||
${g("--fp-loading-color",t.loadingColor)} | ||
${g("--fp-loading-border-radius",t.loadingBorderRadius)} | ||
${g("--fp-loading-padding",t.loadingPadding)} | ||
${g("--fp-overlay-bg",t.overlayBg)} | ||
${f("--fp-fp-button-height",e.fpButtonHeight)} | ||
${f("--fp-fp-button-border-radius",e.fpButtonBorderRadius)} | ||
${f("--fp-loading-bg",e.loadingBg)} | ||
${f("--fp-loading-color",e.loadingColor)} | ||
${f("--fp-loading-border-radius",e.loadingBorderRadius)} | ||
${f("--fp-loading-padding",e.loadingPadding)} | ||
${f("--fp-overlay-bg",e.overlayBg)} | ||
} | ||
`);},v=t=>{if(!t)throw new Error("A container is required to create a Footprint button");let o=B();return t.appendChild(o),o},R=t=>{document.body.classList.add("footprint-body-locked");let o=document.createElement("div");o.setAttribute("id",O);let e=nt(x);o.appendChild(e),o.classList.add("footprint-overlay"),t.appendChild(o);},N=()=>{let t=document.getElementById(x);t&&t.remove();},I=()=>{document.body.classList.remove("footprint-body-locked");let t=document.getElementById(O);t&&t.remove();},_=()=>{let t=document.getElementById(k);if(t)return t;let o=document.createElement("div");return o.setAttribute("id",k),document.body.appendChild(o),o},nt=t=>{let o=document.createElement("div");o.setAttribute("id",t),o.classList.add("footprint-loading-indicator");let e=document.createElement("div");e.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),e.appendChild(r),o.appendChild(e),o},it=()=>{let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","24px"),t.setAttribute("height","24px"),t.setAttribute("fill","none"),t.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"),t.appendChild(o),t},B=()=>{let t=it(),o=document.createElement("button");o.appendChild(t);let e=document.createElement("span");return e.innerText="Verify with Footprint",o.appendChild(e),o.classList.add("footprint-button"),o};var b=class{constructor(){this.child=null;}show(o){return y(this,null,function*(){let e=()=>{N();},r=_();R(r);let n=yield new F({classListArray:["footprint-modal"],container:r,name:"footprint-iframe",url:o});n.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),e(),n.on("closed",()=>this.close()),this.child=n;})}on(o,e){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(o,e)}close(){I(),this.child&&this.child.destroy();}createButton(o){let e=B();return o.appendChild(e),e}},D=b;var H=t=>{let o="https://id.onefootprint.com",{publicKey:e,variables:r,rules:n,fontSrc:a}=t,i=new URLSearchParams;return e&&i.append("public_key",e),r&&i.append("tokens",r),n&&i.append("rules",n),a&&i.append("font_src",a),`${o}?${i.toString()}`},V=({fontSrc:t,variables:o={},rules:e={}}={})=>{let l=o,c=E(l,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),u=()=>Object.keys(c).length?encodeURIComponent(JSON.stringify(c)):void 0,S=()=>Object.keys(e).length?encodeURIComponent(JSON.stringify(e)):void 0;return {fontSrc:t,variables:u(),rules:S()}};var C=new D,M=!1,at=()=>{let t=({theme:i="light",variables:s={}}={})=>{let{fpButtonBorderRadius:d,fpButtonHeight:p,loadingBg:c,loadingBorderRadius:u,loadingColor:S,loadingPadding:l,overlayBg:h}=s;L({theme:i,variables:{fpButtonBorderRadius:d,fpButtonHeight:p,loadingBg:c,loadingBorderRadius:u,loadingColor:S,loadingPadding:l,overlayBg:h}});},o=i=>C.on("completed",s=>{s&&typeof s=="string"&&i(s);}),e=i=>C.on("canceled",i),r=i=>C.on("closed",i),n=c=>y(void 0,[c],function*({appearance:i,publicKey:s,onCompleted:d,onCanceled:p}){if(M){console.warn("Cannot open two instances of Footprint at the same time");return}t(i);let{fontSrc:u,rules:S,variables:l}=V(i),h=H({fontSrc:u,publicKey:s,rules:S,variables:l});yield C.show(h),d&&o(d),p&&e(p),r(a);}),a=()=>y(void 0,null,function*(){yield C.close(),M=!1;});return {show:n,close:a,createButton:v}},T=at;var st=t=>{window.setTimeout(t,0);},U=t=>typeof t=="function",dt=t=>typeof t=="object"&&!!t,pt=t=>{if(typeof window=="undefined")return;let o=()=>{let a=window.footprintAppearance;if(!(!a||!dt(a)))return {fontSrc:a.fontSrc,rules:a.rules,theme:a.theme,variables:a.variables}},e=a=>{t.show({publicKey:a,appearance:o(),onCanceled:()=>{var i;U(window.onFootprintCanceled)&&((i=window.onFootprintCanceled)==null||i.call(window));},onCompleted:i=>{var s;U(window.onFootprintCompleted)&&((s=window.onFootprintCompleted)==null||s.call(window,i));}});},r=()=>{let a=document.getElementById("footprint-button");if(!a)return;let i=a.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(i,a);},n=(a,i)=>{st(()=>{v(i).addEventListener("click",()=>{e(a);});});};document.addEventListener("DOMContentLoaded",()=>r());},j=pt;var $=t=>y(void 0,null,function*(){let o=yield fetch("https://api.onefootprint.com/hosted/identify",{method:"POST",body:JSON.stringify(t)});if(!o.ok)throw Error(o.statusText);return (yield o.json()).user_found}),lt=t=>y(void 0,null,function*(){if(!t)throw new Error("User data must be passed in order to identify an user");let{email:o,phoneNumber:e}=t;return o&&(yield $({identifier:{email:o}}))?!0:e?yield $({identifier:{phone_number:e}}):!1}),q=lt;var W=T();j(W);var Ht=W;/** | ||
`);},v=e=>{if(!e)throw new Error("A container is required to create a Footprint button");let o=B();return e.appendChild(o),o},N=e=>{document.body.classList.add("footprint-body-locked");let o=document.createElement("div");o.setAttribute("id",x);let t=at(L);o.appendChild(t),o.classList.add("footprint-overlay"),e.appendChild(o);},D=()=>{let e=document.getElementById(L);e&&e.remove();},I=()=>{document.body.classList.remove("footprint-body-locked");let e=document.getElementById(x);e&&e.remove();},_=()=>{let e=document.getElementById(O);if(e)return e;let o=document.createElement("div");return o.setAttribute("id",O),document.body.appendChild(o),o},at=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},st=()=>{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},B=()=>{let e=st(),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=()=>{D();};}bootstrap(o){var t;o&&((t=this.child)==null||t.call("bootstrapDataReceived",o));}open(o,t){return S(this,null,function*(){let r=_();N(r),this.child=yield new k({classListArray:["footprint-modal"],container:r,name:"footprint-iframe",url:o}),this.handleIframeLoaded(),this.child.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),this.child.on("closed",()=>this.close()),this.child.on("ready",()=>{this.bootstrap(t);});})}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(){I(),this.child&&this.child.destroy();}createButton(o){let t=B();return o.appendChild(t),t}},H=b;var V=e=>{let o="https://id.onefootprint.com",{publicKey:t,variables:r,rules:n,fontSrc:a}=e,i=new URLSearchParams;return t&&i.append("public_key",t),r&&i.append("tokens",r),n&&i.append("rules",n),a&&i.append("font_src",a),`${o}?${i.toString()}`},M=({fontSrc:e,variables:o={},rules:t={}}={})=>{let c=o,l=E(c,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),g=()=>Object.keys(l).length?encodeURIComponent(JSON.stringify(l)):void 0,u=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:e,variables:g(),rules:u()}};var C=new H,T=!1,dt=()=>{let e=({theme:i="light",variables:d={}}={})=>{let{fpButtonBorderRadius:s,fpButtonHeight:p,loadingBg:l,loadingBorderRadius:g,loadingColor:u,loadingPadding:c,overlayBg:y}=d;R({theme:i,variables:{fpButtonBorderRadius:s,fpButtonHeight:p,loadingBg:l,loadingBorderRadius:g,loadingColor:u,loadingPadding:c,overlayBg:y}});},o=i=>C.on("completed",d=>{d&&typeof d=="string"&&i(d);}),t=i=>C.on("canceled",i),r=i=>C.on("closed",i),n=g=>S(void 0,[g],function*({appearance:i,onCanceled:d,onCompleted:s,publicKey:p,userData:l}){if(T){console.warn("Cannot open two instances of Footprint at the same time");return}e(i);let{fontSrc:u,rules:c,variables:y}=M(i),J=V({fontSrc:u,publicKey:p,rules:c,variables:y});yield C.open(J,l),s&&o(s),d&&t(d),r(a);}),a=()=>S(void 0,null,function*(){yield C.close(),T=!1;});return {open:n,close:a,createButton:v}},U=dt;var pt=e=>{window.setTimeout(e,0);},j=e=>typeof e=="function",lt=e=>typeof e=="object"&&!!e,ct=e=>{if(typeof window=="undefined")return;let o=()=>{let a=window.footprintAppearance;if(!(!a||!lt(a)))return {fontSrc:a.fontSrc,rules:a.rules,theme:a.theme,variables:a.variables}},t=(a,i)=>{let d=i.getAttribute("data-user-email"),s=i.getAttribute("data-user-phone-number");e.open({publicKey:a,appearance:o(),onCanceled:()=>{var p;j(window.onFootprintCanceled)&&((p=window.onFootprintCanceled)==null||p.call(window));},onCompleted:p=>{var l;j(window.onFootprintCompleted)&&((l=window.onFootprintCompleted)==null||l.call(window,p));},userData:{email:d,phoneNumber:s}});},r=()=>{let a=document.getElementById("footprint-button");if(!a)return;let i=a.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(i,a);},n=(a,i)=>{pt(()=>{v(i).addEventListener("click",()=>{t(a,i);});});};document.addEventListener("DOMContentLoaded",()=>r());},$=ct;var q=e=>S(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}),ut=e=>S(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let{email:o,phoneNumber:t}=e;return o&&(yield q({identifier:{email:o}}))?!0:t?yield q({identifier:{phone_number:t}}):!1}),W=ut;var K=U();$(K);var Mt=K;/** | ||
postmate - A powerful, simple, promise-based postMessage library | ||
@@ -19,2 +19,2 @@ @version v1.5.2 | ||
export { A as FootprintEvents, Ht as default, q as identifyUser }; | ||
export { F as FootprintInternalEvent, A as FootprintPublicEvent, Mt as default, W as identifyUser }; |
(function (exports) { | ||
'use strict'; | ||
var w=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var E=(t,o)=>{var e={};for(var r in t)K.call(t,r)&&o.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&w)for(var r of w(t))o.indexOf(r)<0&&J.call(t,r)&&(e[r]=t[r]);return e};var y=(t,o,e)=>new Promise((r,n)=>{var a=d=>{try{s(e.next(d));}catch(p){n(p);}},i=d=>{try{s(e.throw(d));}catch(p){n(p);}},s=d=>d.done?r(d.value):Promise.resolve(d.value).then(a,i);s((e=e.apply(t,o)).next());});var A=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(A||{});var m="application/x-postmate-v1+json",z=5,Y=0,Z=function(){return ++Y};var G=function(o){var e=document.createElement("a");e.href=o;var r=e.protocol.length>4?e.protocol:window.location.protocol,n=e.host.length?e.port==="80"||e.port==="443"?e.hostname:e.host:window.location.host;return e.origin||r+"//"+n},Q={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function(o,e){return !(typeof e=="string"&&o.origin!==e||!o.data||typeof o.data=="object"&&!("postmate"in o.data)||o.data.type!==m||!Q[o.data.postmate])},X=function(o,e){var r=typeof o[e]=="function"?o[e]():o[e];return f.Promise.resolve(r)},tt=function(){function t(e){var r=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},this.listener=function(n){if(!P(n,r.childOrigin))return !1;var a=((n||{}).data||{}).value||{},i=a.data,s=a.name;n.data.postmate==="emit"&&s in r.events&&r.events[s].call(r,i);},this.parent.addEventListener("message",this.listener,!1);}var o=t.prototype;return o.get=function(r){var n=this;return new f.Promise(function(a){var i=Z(),s=function d(p){p.data.uid===i&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",d,!1),a(p.data.value));};n.parent.addEventListener("message",s,!1),n.child.postMessage({postmate:"request",type:m,property:r,uid:i},n.childOrigin);})},o.call=function(r,n){this.child.postMessage({postmate:"call",type:m,property:r,data:n},this.childOrigin);},o.on=function(r,n){this.events[r]=n;},o.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},t}(),et=function(){function t(e){var r=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,this.child.addEventListener("message",function(n){if(!!P(n,r.parentOrigin)){var a=n.data,i=a.property,s=a.uid,d=a.data;if(n.data.postmate==="call"){i in r.model&&typeof r.model[i]=="function"&&r.model[i](d);return}X(r.model,i).then(function(p){return n.source.postMessage({property:i,postmate:"reply",type:m,uid:s,value:p},n.origin)});}});}var o=t.prototype;return o.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:m,value:{name:r,data:n}},this.parentOrigin);},t}(),f=function(){function t(e){var r=e.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,a=e.model,i=e.url,s=e.name,d=e.classListArray,p=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(i)}var o=t.prototype;return o.sendHandshake=function(r){var n=this,a=G(r),i=0,s;return new t.Promise(function(d,p){var c=function l(h){return P(h,a)?h.data.postmate==="handshake-reply"?(clearInterval(s),n.parent.removeEventListener("message",l,!1),n.childOrigin=h.origin,d(new tt(n))):p("Failed handshake"):!1};n.parent.addEventListener("message",c,!1);var u=function(){i++,n.child.postMessage({postmate:"handshake",type:m,model:n.model},a),i===z&&clearInterval(s);},S=function(){u(),s=setInterval(u,500);};n.frame.attachEvent?n.frame.attachEvent("onload",S):n.frame.onload=S,n.frame.src=r;})},t}();f.debug=!1;f.Promise=function(){try{return window?window.Promise:Promise}catch(t){return null}}();f.Model=function(){function t(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}var o=t.prototype;return o.sendHandshakeReply=function(){var r=this;return new f.Promise(function(n,a){var i=function s(d){if(!!d.data.postmate){if(d.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),d.source.postMessage({postmate:"handshake-reply",type:m},d.origin),r.parentOrigin=d.origin;var p=d.data.model;return p&&Object.keys(p).forEach(function(c){r.model[c]=p[c];}),n(new et(r))}return a("Handshake Reply Failed")}};r.child.addEventListener("message",i,!1);})},t}();var F=f;var k="footprint-container",O="footprint-overlay",x="footprint-loading-indicator",ot="footprint-custom-styles",rt=t=>{if(typeof window=="undefined")return;let o=document.getElementById(ot);o&&o.remove();let e=document.createElement("style");e.setAttribute("id","footprint-custom-styles"),e.textContent=t,document.head.append(e);},g=(t,o)=>o?`${t}: ${o}`:"",L=({variables:t={}})=>{rt(` | ||
var w=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var E=(e,o)=>{var t={};for(var r in e)z.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&w)for(var r of w(e))o.indexOf(r)<0&&Y.call(e,r)&&(t[r]=e[r]);return t};var S=(e,o,t)=>new Promise((r,n)=>{var a=s=>{try{d(t.next(s));}catch(p){n(p);}},i=s=>{try{d(t.throw(s));}catch(p){n(p);}},d=s=>s.done?r(s.value):Promise.resolve(s.value).then(a,i);d((t=t.apply(e,o)).next());});var A=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(A||{}),F=(t=>(t.bootstrapDataReceived="bootstrapDataReceived",t.ready="ready",t))(F||{});var h="application/x-postmate-v1+json",Z=5,G=0,Q=function(){return ++G};var X=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},tt={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function(o,t){return !(typeof t=="string"&&o.origin!==t||!o.data||typeof o.data=="object"&&!("postmate"in o.data)||o.data.type!==h||!tt[o.data.postmate])},et=function(o,t){var r=typeof o[t]=="function"?o[t]():o[t];return m.Promise.resolve(r)},ot=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(!P(n,r.childOrigin))return !1;var a=((n||{}).data||{}).value||{},i=a.data,d=a.name;n.data.postmate==="emit"&&d in r.events&&r.events[d].call(r,i);},this.parent.addEventListener("message",this.listener,!1);}var o=e.prototype;return o.get=function(r){var n=this;return new m.Promise(function(a){var i=Q(),d=function s(p){p.data.uid===i&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",s,!1),a(p.data.value));};n.parent.addEventListener("message",d,!1),n.child.postMessage({postmate:"request",type:h,property:r,uid:i},n.childOrigin);})},o.call=function(r,n){this.child.postMessage({postmate:"call",type:h,property:r,data:n},this.childOrigin);},o.on=function(r,n){this.events[r]=n;},o.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},e}(),rt=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(!!P(n,r.parentOrigin)){var a=n.data,i=a.property,d=a.uid,s=a.data;if(n.data.postmate==="call"){i in r.model&&typeof r.model[i]=="function"&&r.model[i](s);return}et(r.model,i).then(function(p){return n.source.postMessage({property:i,postmate:"reply",type:h,uid:d,value:p},n.origin)});}});}var o=e.prototype;return o.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:h,value:{name:r,data:n}},this.parentOrigin);},e}(),m=function(){function e(t){var r=t.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,a=t.model,i=t.url,d=t.name,s=t.classListArray,p=s===void 0?[]:s;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=d||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=a||{},this.sendHandshake(i)}var o=e.prototype;return o.sendHandshake=function(r){var n=this,a=X(r),i=0,d;return new e.Promise(function(s,p){var l=function c(y){return P(y,a)?y.data.postmate==="handshake-reply"?(clearInterval(d),n.parent.removeEventListener("message",c,!1),n.childOrigin=y.origin,s(new ot(n))):p("Failed handshake"):!1};n.parent.addEventListener("message",l,!1);var g=function(){i++,n.child.postMessage({postmate:"handshake",type:h,model:n.model},a),i===Z&&clearInterval(d);},u=function(){g(),d=setInterval(g,500);};n.frame.attachEvent?n.frame.attachEvent("onload",u):n.frame.onload=u,n.frame.src=r;})},e}();m.debug=!1;m.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();m.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 m.Promise(function(n,a){var i=function d(s){if(!!s.data.postmate){if(s.data.postmate==="handshake"){r.child.removeEventListener("message",d,!1),s.source.postMessage({postmate:"handshake-reply",type:h},s.origin),r.parentOrigin=s.origin;var p=s.data.model;return p&&Object.keys(p).forEach(function(l){r.model[l]=p[l];}),n(new rt(r))}return a("Handshake Reply Failed")}};r.child.addEventListener("message",i,!1);})},e}();var k=m;var O="footprint-container",x="footprint-overlay",L="footprint-loading-indicator",nt="footprint-custom-styles",it=e=>{if(typeof window=="undefined")return;let o=document.getElementById(nt);o&&o.remove();let t=document.createElement("style");t.setAttribute("id","footprint-custom-styles"),t.textContent=e,document.head.append(t);},f=(e,o)=>o?`${e}: ${o}`:"",R=({variables:e={}})=>{it(` | ||
:root { | ||
${g("--fp-fp-button-height",t.fpButtonHeight)} | ||
${g("--fp-fp-button-border-radius",t.fpButtonBorderRadius)} | ||
${g("--fp-loading-bg",t.loadingBg)} | ||
${g("--fp-loading-color",t.loadingColor)} | ||
${g("--fp-loading-border-radius",t.loadingBorderRadius)} | ||
${g("--fp-loading-padding",t.loadingPadding)} | ||
${g("--fp-overlay-bg",t.overlayBg)} | ||
${f("--fp-fp-button-height",e.fpButtonHeight)} | ||
${f("--fp-fp-button-border-radius",e.fpButtonBorderRadius)} | ||
${f("--fp-loading-bg",e.loadingBg)} | ||
${f("--fp-loading-color",e.loadingColor)} | ||
${f("--fp-loading-border-radius",e.loadingBorderRadius)} | ||
${f("--fp-loading-padding",e.loadingPadding)} | ||
${f("--fp-overlay-bg",e.overlayBg)} | ||
} | ||
`);},v=t=>{if(!t)throw new Error("A container is required to create a Footprint button");let o=B();return t.appendChild(o),o},R=t=>{document.body.classList.add("footprint-body-locked");let o=document.createElement("div");o.setAttribute("id",O);let e=nt(x);o.appendChild(e),o.classList.add("footprint-overlay"),t.appendChild(o);},N=()=>{let t=document.getElementById(x);t&&t.remove();},I=()=>{document.body.classList.remove("footprint-body-locked");let t=document.getElementById(O);t&&t.remove();},_=()=>{let t=document.getElementById(k);if(t)return t;let o=document.createElement("div");return o.setAttribute("id",k),document.body.appendChild(o),o},nt=t=>{let o=document.createElement("div");o.setAttribute("id",t),o.classList.add("footprint-loading-indicator");let e=document.createElement("div");e.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),e.appendChild(r),o.appendChild(e),o},it=()=>{let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","24px"),t.setAttribute("height","24px"),t.setAttribute("fill","none"),t.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"),t.appendChild(o),t},B=()=>{let t=it(),o=document.createElement("button");o.appendChild(t);let e=document.createElement("span");return e.innerText="Verify with Footprint",o.appendChild(e),o.classList.add("footprint-button"),o};var b=class{constructor(){this.child=null;}show(o){return y(this,null,function*(){let e=()=>{N();},r=_();R(r);let n=yield new F({classListArray:["footprint-modal"],container:r,name:"footprint-iframe",url:o});n.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),e(),n.on("closed",()=>this.close()),this.child=n;})}on(o,e){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(o,e)}close(){I(),this.child&&this.child.destroy();}createButton(o){let e=B();return o.appendChild(e),e}},D=b;var H=t=>{let o="https://id.onefootprint.com",{publicKey:e,variables:r,rules:n,fontSrc:a}=t,i=new URLSearchParams;return e&&i.append("public_key",e),r&&i.append("tokens",r),n&&i.append("rules",n),a&&i.append("font_src",a),`${o}?${i.toString()}`},V=({fontSrc:t,variables:o={},rules:e={}}={})=>{let l=o,c=E(l,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),u=()=>Object.keys(c).length?encodeURIComponent(JSON.stringify(c)):void 0,S=()=>Object.keys(e).length?encodeURIComponent(JSON.stringify(e)):void 0;return {fontSrc:t,variables:u(),rules:S()}};var C=new D,M=!1,at=()=>{let t=({theme:i="light",variables:s={}}={})=>{let{fpButtonBorderRadius:d,fpButtonHeight:p,loadingBg:c,loadingBorderRadius:u,loadingColor:S,loadingPadding:l,overlayBg:h}=s;L({theme:i,variables:{fpButtonBorderRadius:d,fpButtonHeight:p,loadingBg:c,loadingBorderRadius:u,loadingColor:S,loadingPadding:l,overlayBg:h}});},o=i=>C.on("completed",s=>{s&&typeof s=="string"&&i(s);}),e=i=>C.on("canceled",i),r=i=>C.on("closed",i),n=c=>y(void 0,[c],function*({appearance:i,publicKey:s,onCompleted:d,onCanceled:p}){if(M){console.warn("Cannot open two instances of Footprint at the same time");return}t(i);let{fontSrc:u,rules:S,variables:l}=V(i),h=H({fontSrc:u,publicKey:s,rules:S,variables:l});yield C.show(h),d&&o(d),p&&e(p),r(a);}),a=()=>y(void 0,null,function*(){yield C.close(),M=!1;});return {show:n,close:a,createButton:v}},T=at;var st=t=>{window.setTimeout(t,0);},U=t=>typeof t=="function",dt=t=>typeof t=="object"&&!!t,pt=t=>{if(typeof window=="undefined")return;let o=()=>{let a=window.footprintAppearance;if(!(!a||!dt(a)))return {fontSrc:a.fontSrc,rules:a.rules,theme:a.theme,variables:a.variables}},e=a=>{t.show({publicKey:a,appearance:o(),onCanceled:()=>{var i;U(window.onFootprintCanceled)&&((i=window.onFootprintCanceled)==null||i.call(window));},onCompleted:i=>{var s;U(window.onFootprintCompleted)&&((s=window.onFootprintCompleted)==null||s.call(window,i));}});},r=()=>{let a=document.getElementById("footprint-button");if(!a)return;let i=a.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(i,a);},n=(a,i)=>{st(()=>{v(i).addEventListener("click",()=>{e(a);});});};document.addEventListener("DOMContentLoaded",()=>r());},j=pt;var $=t=>y(void 0,null,function*(){let o=yield fetch("https://api.onefootprint.com/hosted/identify",{method:"POST",body:JSON.stringify(t)});if(!o.ok)throw Error(o.statusText);return (yield o.json()).user_found}),lt=t=>y(void 0,null,function*(){if(!t)throw new Error("User data must be passed in order to identify an user");let{email:o,phoneNumber:e}=t;return o&&(yield $({identifier:{email:o}}))?!0:e?yield $({identifier:{phone_number:e}}):!1}),q=lt;var W=T();j(W);var Ht=W;/** | ||
`);},v=e=>{if(!e)throw new Error("A container is required to create a Footprint button");let o=B();return e.appendChild(o),o},N=e=>{document.body.classList.add("footprint-body-locked");let o=document.createElement("div");o.setAttribute("id",x);let t=at(L);o.appendChild(t),o.classList.add("footprint-overlay"),e.appendChild(o);},D=()=>{let e=document.getElementById(L);e&&e.remove();},I=()=>{document.body.classList.remove("footprint-body-locked");let e=document.getElementById(x);e&&e.remove();},_=()=>{let e=document.getElementById(O);if(e)return e;let o=document.createElement("div");return o.setAttribute("id",O),document.body.appendChild(o),o},at=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},st=()=>{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},B=()=>{let e=st(),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=()=>{D();};}bootstrap(o){var t;o&&((t=this.child)==null||t.call("bootstrapDataReceived",o));}open(o,t){return S(this,null,function*(){let r=_();N(r),this.child=yield new k({classListArray:["footprint-modal"],container:r,name:"footprint-iframe",url:o}),this.handleIframeLoaded(),this.child.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),this.child.on("closed",()=>this.close()),this.child.on("ready",()=>{this.bootstrap(t);});})}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(){I(),this.child&&this.child.destroy();}createButton(o){let t=B();return o.appendChild(t),t}},H=b;var V=e=>{let o="https://id.onefootprint.com",{publicKey:t,variables:r,rules:n,fontSrc:a}=e,i=new URLSearchParams;return t&&i.append("public_key",t),r&&i.append("tokens",r),n&&i.append("rules",n),a&&i.append("font_src",a),`${o}?${i.toString()}`},M=({fontSrc:e,variables:o={},rules:t={}}={})=>{let c=o,l=E(c,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),g=()=>Object.keys(l).length?encodeURIComponent(JSON.stringify(l)):void 0,u=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:e,variables:g(),rules:u()}};var C=new H,T=!1,dt=()=>{let e=({theme:i="light",variables:d={}}={})=>{let{fpButtonBorderRadius:s,fpButtonHeight:p,loadingBg:l,loadingBorderRadius:g,loadingColor:u,loadingPadding:c,overlayBg:y}=d;R({theme:i,variables:{fpButtonBorderRadius:s,fpButtonHeight:p,loadingBg:l,loadingBorderRadius:g,loadingColor:u,loadingPadding:c,overlayBg:y}});},o=i=>C.on("completed",d=>{d&&typeof d=="string"&&i(d);}),t=i=>C.on("canceled",i),r=i=>C.on("closed",i),n=g=>S(void 0,[g],function*({appearance:i,onCanceled:d,onCompleted:s,publicKey:p,userData:l}){if(T){console.warn("Cannot open two instances of Footprint at the same time");return}e(i);let{fontSrc:u,rules:c,variables:y}=M(i),J=V({fontSrc:u,publicKey:p,rules:c,variables:y});yield C.open(J,l),s&&o(s),d&&t(d),r(a);}),a=()=>S(void 0,null,function*(){yield C.close(),T=!1;});return {open:n,close:a,createButton:v}},U=dt;var pt=e=>{window.setTimeout(e,0);},j=e=>typeof e=="function",lt=e=>typeof e=="object"&&!!e,ct=e=>{if(typeof window=="undefined")return;let o=()=>{let a=window.footprintAppearance;if(!(!a||!lt(a)))return {fontSrc:a.fontSrc,rules:a.rules,theme:a.theme,variables:a.variables}},t=(a,i)=>{let d=i.getAttribute("data-user-email"),s=i.getAttribute("data-user-phone-number");e.open({publicKey:a,appearance:o(),onCanceled:()=>{var p;j(window.onFootprintCanceled)&&((p=window.onFootprintCanceled)==null||p.call(window));},onCompleted:p=>{var l;j(window.onFootprintCompleted)&&((l=window.onFootprintCompleted)==null||l.call(window,p));},userData:{email:d,phoneNumber:s}});},r=()=>{let a=document.getElementById("footprint-button");if(!a)return;let i=a.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(i,a);},n=(a,i)=>{pt(()=>{v(i).addEventListener("click",()=>{t(a,i);});});};document.addEventListener("DOMContentLoaded",()=>r());},$=ct;var q=e=>S(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}),ut=e=>S(void 0,null,function*(){if(!e)throw new Error("User data must be passed in order to identify an user");let{email:o,phoneNumber:t}=e;return o&&(yield q({identifier:{email:o}}))?!0:t?yield q({identifier:{phone_number:t}}):!1}),W=ut;var K=U();$(K);var Mt=K;/** | ||
postmate - A powerful, simple, promise-based postMessage library | ||
@@ -22,5 +22,6 @@ @version v1.5.2 | ||
exports.FootprintEvents = A; | ||
exports.default = Ht; | ||
exports.identifyUser = q; | ||
exports.FootprintInternalEvent = F; | ||
exports.FootprintPublicEvent = A; | ||
exports.default = Mt; | ||
exports.identifyUser = W; | ||
@@ -27,0 +28,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "0.6.1", | ||
"version": "1.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
44420
357
1