@onefootprint/footprint-js
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,87 +0,1 @@ | ||
"use strict";var w=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var S=(e,t)=>{for(var n in t)w(e,n,{get:t[n],enumerable:!0})},V=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of D(t))!F.call(e,o)&&o!==n&&w(e,o,{get:()=>t[o],enumerable:!(r=M(t,o))||r.enumerable});return e};var R=e=>V(w({},"__esModule",{value:!0}),e);var Q={};S(Q,{default:()=>J});module.exports=R(Q);var E="footprint-container",b="footprint-overlay",C="footprint-loading-indicator",m=typeof window>"u";var T=e=>{window.setTimeout(e,0)},B=e=>{let t=async()=>{await e.show({onUserCanceled:()=>{var i;(i=window.onFootprintCanceled)==null||i.call(window)},onCompleted:i=>{var a;(a=window.onFootprintCompleted)==null||a.call(window,i)}})},n=()=>{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");r(a,i)},r=(i,a)=>{e.init({publicKey:i}),T(()=>{e.createButton(a).addEventListener("click",()=>{t()})})},o=()=>{m||document.addEventListener("DOMContentLoaded",()=>n())};return()=>{o()}},L=B;var h=class{constructor(e,t){this.url=e;this.uiManager=t;this.publicKey=null;this.flow="authentication"}init(e={}){e.publicKey&&(this.flow="onboarding",this.publicKey=e.publicKey)}onAuthenticated(e){return this.uiManager.on("authenticated",t=>{t&&typeof t=="string"&&e(t)})}onCompleted(e){return this.uiManager.on("completed",t=>{t&&typeof t=="string"&&e(t)})}onUserCanceled(e){return this.uiManager.on("userCanceled",e)}async show(e={}){let t=new URLSearchParams;t.append("flow",this.flow),this.publicKey&&t.append("public_key",this.publicKey),await this.uiManager.show({url:`${this.url}?${t.toString()}`}),e.onAuthenticated&&this.onAuthenticated(e.onAuthenticated),e.onCompleted&&this.onCompleted(e.onCompleted),e.onUserCanceled&&this.onUserCanceled(e.onUserCanceled)}createButton(e){return this.uiManager.createButton(e)}};var u="application/x-postmate-v1+json",H=5,U=0,K=function(){return++U},s=function(){var t;return c.debug?(t=console).log.apply(t,arguments):null},j=function(t){var n=document.createElement("a");n.href=t;var r=n.protocol.length>4?n.protocol:window.location.protocol,o=n.host.length?n.port==="80"||n.port==="443"?n.hostname:n.host:window.location.host;return n.origin||r+"//"+o},$={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},I=function(t,n){return!(typeof n=="string"&&t.origin!==n||!t.data||typeof t.data=="object"&&!("postmate"in t.data)||t.data.type!==u||!$[t.data.postmate])},z=function(t,n){var r=typeof t[n]=="function"?t[n]():t[n];return c.Promise.resolve(r)},q=function(){function e(n){var r=this;this.parent=n.parent,this.frame=n.frame,this.child=n.child,this.childOrigin=n.childOrigin,this.events={},process.env.NODE_ENV!=="production"&&(s("Parent: Registering API"),s("Parent: Awaiting messages...")),this.listener=function(o){if(!I(o,r.childOrigin))return!1;var i=((o||{}).data||{}).value||{},a=i.data,d=i.name;o.data.postmate==="emit"&&(process.env.NODE_ENV!=="production"&&s("Parent: Received event emission: "+d),d in r.events&&r.events[d].call(r,a))},this.parent.addEventListener("message",this.listener,!1),process.env.NODE_ENV!=="production"&&s("Parent: Awaiting event emissions from Child")}var t=e.prototype;return t.get=function(r){var o=this;return new c.Promise(function(i){var a=K(),d=function p(l){l.data.uid===a&&l.data.postmate==="reply"&&(o.parent.removeEventListener("message",p,!1),i(l.data.value))};o.parent.addEventListener("message",d,!1),o.child.postMessage({postmate:"request",type:u,property:r,uid:a},o.childOrigin)})},t.call=function(r,o){this.child.postMessage({postmate:"call",type:u,property:r,data:o},this.childOrigin)},t.on=function(r,o){this.events[r]=o},t.destroy=function(){process.env.NODE_ENV!=="production"&&s("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},e}(),G=function(){function e(n){var r=this;this.model=n.model,this.parent=n.parent,this.parentOrigin=n.parentOrigin,this.child=n.child,process.env.NODE_ENV!=="production"&&(s("Child: Registering API"),s("Child: Awaiting messages...")),this.child.addEventListener("message",function(o){if(!!I(o,r.parentOrigin)){process.env.NODE_ENV!=="production"&&s("Child: Received request",o.data);var i=o.data,a=i.property,d=i.uid,p=i.data;if(o.data.postmate==="call"){a in r.model&&typeof r.model[a]=="function"&&r.model[a](p);return}z(r.model,a).then(function(l){return o.source.postMessage({property:a,postmate:"reply",type:u,uid:d,value:l},o.origin)})}})}var t=e.prototype;return t.emit=function(r,o){process.env.NODE_ENV!=="production"&&s('Child: Emitting Event "'+r+'"',o),this.parent.postMessage({postmate:"emit",type:u,value:{name:r,data:o}},this.parentOrigin)},e}(),c=function(){function e(n){var r=n.container,o=r===void 0?typeof o<"u"?o:document.body:r,i=n.model,a=n.url,d=n.name,p=n.classListArray,l=p===void 0?[]:p;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=d||"",this.frame.classList.add.apply(this.frame.classList,l),o.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var t=e.prototype;return t.sendHandshake=function(r){var o=this,i=j(r),a=0,d;return new e.Promise(function(p,l){var f=function g(y){return I(y,i)?y.data.postmate==="handshake-reply"?(clearInterval(d),process.env.NODE_ENV!=="production"&&s("Parent: Received handshake reply from Child"),o.parent.removeEventListener("message",g,!1),o.childOrigin=y.origin,process.env.NODE_ENV!=="production"&&s("Parent: Saving Child origin",o.childOrigin),p(new q(o))):(process.env.NODE_ENV!=="production"&&s("Parent: Invalid handshake reply"),l("Failed handshake")):!1};o.parent.addEventListener("message",f,!1);var O=function(){a++,process.env.NODE_ENV!=="production"&&s("Parent: Sending handshake attempt "+a,{childOrigin:i}),o.child.postMessage({postmate:"handshake",type:u,model:o.model},i),a===H&&clearInterval(d)},x=function(){O(),d=setInterval(O,500)};o.frame.attachEvent?o.frame.attachEvent("onload",x):o.frame.onload=x,process.env.NODE_ENV!=="production"&&s("Parent: Loading frame",{url:r}),o.frame.src=r})},e}();c.debug=!1;c.Promise=function(){try{return window?window.Promise:Promise}catch{return null}}();c.Model=function(){function e(n){return this.child=window,this.model=n,this.parent=this.child.parent,this.sendHandshakeReply()}var t=e.prototype;return t.sendHandshakeReply=function(){var r=this;return new c.Promise(function(o,i){var a=function d(p){if(!!p.data.postmate){if(p.data.postmate==="handshake"){process.env.NODE_ENV!=="production"&&s("Child: Received handshake from Parent"),r.child.removeEventListener("message",d,!1),process.env.NODE_ENV!=="production"&&s("Child: Sending handshake reply to Parent"),p.source.postMessage({postmate:"handshake-reply",type:u},p.origin),r.parentOrigin=p.origin;var l=p.data.model;return l&&(Object.keys(l).forEach(function(f){r.model[f]=l[f]}),process.env.NODE_ENV!=="production"&&s("Child: Inherited and extended model from Parent")),process.env.NODE_ENV!=="production"&&s("Child: Saving Parent origin",r.parentOrigin),o(new G(r))}return i("Handshake Reply Failed")}};r.child.addEventListener("message",a,!1)})},e}();var A=c;var N=()=>{let e=document.createElement("style");e.type="text/css",e.innerHTML=` | ||
.footprint-body-locked { | ||
overflow: hidden; | ||
} | ||
.footprint-overlay { | ||
align-items: center; | ||
background: rgba(0, 0, 0, 0.3); | ||
display: flex; | ||
height: 100%; | ||
justify-content: center; | ||
left: 0; | ||
overflow-y: hidden; | ||
position: fixed; | ||
top: 0; | ||
width: 100%; | ||
z-index: 50000; | ||
} | ||
@keyframes footprint-rotate { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
.footprint-loading-indicator { | ||
background: rgba(0, 0, 0, 0.6); | ||
border-radius: 4px; | ||
padding: 16px; | ||
} | ||
.footprint-loading-spin { | ||
animation: footprint-rotate 0.8s linear infinite; | ||
} | ||
.footprint-modal { | ||
height: 100%; | ||
left: 0; | ||
position: fixed; | ||
top: 0; | ||
width: 100%; | ||
z-index: 50001; | ||
} | ||
.footprint-button { | ||
-webkit-box-align: center; | ||
align-items: center; | ||
background-color: rgb(14, 20, 56); | ||
border-radius: 6px; | ||
border: 0px; | ||
box-shadow: rgb(0 0 0 / 0%) 0px 1px 1px, transparent 0px 0px 0px 1px; | ||
color: rgb(255, 255, 255); | ||
cursor: pointer; | ||
display: flex; | ||
-webkit-box-pack: center; | ||
justify-content: center; | ||
text-decoration: none; | ||
user-select: none; | ||
font-family: "DM Sans"; | ||
font-size: 16px; | ||
font-weight: 500; | ||
line-height: 24px; | ||
padding: 12px 24px; | ||
} | ||
.footprint-button:hover { | ||
background: linear-gradient(rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.14)), linear-gradient(rgb(14, 20, 56), rgb(14, 20, 56)); | ||
} | ||
.footprint-button:active { | ||
background: linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)), linear-gradient(rgb(14, 20, 56), rgb(14, 20, 56)); | ||
} | ||
.footprint-button svg { | ||
margin-right: 8px; | ||
} | ||
`,document.head.appendChild(e)},_=e=>{let t=document.createElement("div");t.setAttribute("id",e),t.classList.add("footprint-loading-indicator");let n=document.createElement("div");n.classList.add("footprint-loading-spin");let r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","24px"),r.setAttribute("height","24px"),r.setAttribute("fill","none"),r.setAttribute("aria-hidden","true");let o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),o.setAttribute("fill","#FFFFFF"),r.appendChild(o),n.appendChild(r),t.appendChild(n),t},W=()=>{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 t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.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"),t.setAttribute("fill","#76fb8f"),e.appendChild(t),e},k=()=>{let e=W(),t=document.createElement("button");t.appendChild(e);let n=document.createElement("span");return n.innerText="Verify with Footprint",t.appendChild(n),t.classList.add("footprint-button"),t};var v=class{constructor(){this.child=null;m||N()}async show({url:e}){let t=()=>{let o=document.getElementById(C);o&&o.remove()},n=this.createContainer();this.showOverlay(n);let r=await new A({classListArray:["footprint-modal"],container:n,name:"footprint-iframe",url:e});r.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *"),t(),r.on("closed",()=>this.hide()),this.child=r}on(e,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(e,t)}hide(){this.hideOverlay(),this.child&&this.child.destroy()}createButton(e){let t=k();return e.appendChild(t),t}showOverlay(e){document.body.classList.add("footprint-body-locked");let t=document.createElement("div");t.setAttribute("id",b);let n=_(C);t.appendChild(n),t.classList.add("footprint-overlay"),e.appendChild(t)}hideOverlay(){document.body.classList.remove("footprint-body-locked");let e=document.getElementById(b);e&&e.remove()}createContainer(){let e=document.getElementById(E);if(e)return e;let t=document.createElement("div");return t.setAttribute("id",E),document.body.appendChild(t),t}};var X=(e="production",t)=>e==="local"?"http://localhost:3000/":e==="development"?"https://id.preview.onefootprint.com":e==="preview"&&t?t==="development"?"https://id.preview.onefootprint.com":`https://bifrost-git-${t.toLowerCase().split("/").join("-")}.preview.onefootprint.com`:"https://id.onefootprint.com",Y=X(process.env.NEXT_PUBLIC_VERCEL_ENV,process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF),Z=new v,P=new h(Y,Z);L(P)();var J=P;0&&(module.exports={}); | ||
/** | ||
postmate - A powerful, simple, promise-based postMessage library | ||
@version v1.5.2 | ||
@link https://github.com/dollarshaveclub/postmate | ||
@author Jacob Kelley <jakie8@gmail.com> | ||
@license MIT | ||
**/ | ||
"use strict";function e(e,t,n,r,i,o,a){try{var s=e[o](a);var u=s.value}catch(l){n(l);return}if(s.done){t(u)}else{Promise.resolve(u).then(r,i)}}function t(t){return function(){var n=this,r=arguments;return new Promise(function(i,o){var a=t.apply(n,r);function s(t){e(a,i,o,s,u,"next",t)}function u(t){e(a,i,o,s,u,"throw",t)}s(undefined)})}}function n(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}function i(e,t,n){if(t)r(e.prototype,t);if(n)r(e,n);return e}var o=function(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e};var a=(this&&this.__generator)||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),"throw":s(1),"return":s(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return u([e,t])}}function u(o){if(n)throw new TypeError("Generator is already executing.");while(a)try{if(n=1,r&&(i=o[0]&2?r["return"]:o[0]?r["throw"]||((i=r["return"])&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;if(r=0,i)o=[o[0]&2,i.value];switch(o[0]){case 0:case 1:i=o;break;case 4:a.label++;return{value:o[1],done:false};case 5:a.label++;r=o[1];o=[0];continue;case 7:o=a.ops.pop();a.trys.pop();continue;default:if(!(i=a.trys,i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){a=0;continue}if(o[0]===3&&(!i||(o[1]>i[0]&&o[1]<i[3]))){a.label=o[1];break}if(o[0]===6&&a.label<i[1]){a.label=i[1];i=o;break}if(i&&a.label<i[2]){a.label=i[2];a.ops.push(o);break}if(i[2])a.ops.pop();a.trys.pop();continue}o=t.call(e,a)}catch(s){o=[6,s];r=0}finally{n=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var c=function(e,t){for(var n in t)s(e,n,{get:t[n],enumerable:!0})},p=function(e,t,n,r){var i=true,o=false,a=undefined;if(t&&typeof t=="object"||typeof t=="function")try{var c=function(){var i=f.value;!d.call(e,i)&&i!==n&&s(e,i,{get:function(){return t[i]},enumerable:!(r=u(t,i))||r.enumerable})};for(var p=l(t)[Symbol.iterator](),f;!(i=(f=p.next()).done);i=true)c()}catch(h){o=true;a=h}finally{try{if(!i&&p.return!=null){p.return()}}finally{if(o){throw a}}}return e};var f=function(e){return p(s({},"__esModule",{value:!0}),e)};var h={};c(h,{default:function(){return q}});module.exports=f(h);var v="footprint-container",g="footprint-overlay",m="footprint-loading-indicator",$=(typeof window==="undefined"?"undefined":o(window))>"u";var y=function(e){window.setTimeout(e,0)},b=function(e){var n=function(){var r=t(function(){var t;return a(this,function(n){switch(n.label){case 0:t={};return[4,e.show((t.onUserCanceled=function(){var e;(e=window.onFootprintCanceled)===null||e===void 0?void 0:e.call(window)},t.onCompleted=function(e){var t;(t=window.onFootprintCompleted)===null||t===void 0?void 0:t.call(window,e)},t))];case 1:n.sent();return[2]}})});return function n(){return r.apply(this,arguments)}}(),r=function(){var e=document.getElementById("footprint-button");if(!e)return;var t=e.getAttribute("data-public-key");if(!t)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");i(t,e)},i=function(t,r){e.init({publicKey:t}),y(function(){e.createButton(r).addEventListener("click",function(){n()})})},o=function(){$||document.addEventListener("DOMContentLoaded",function(){return r()})};return function(){o()}},w=b;var _=function(){function e(t,r){n(this,e);this.url=t;this.uiManager=r;this.publicKey=null;this.flow="authentication"}i(e,[{key:"init",value:function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};t.publicKey&&(this.flow="onboarding",this.publicKey=t.publicKey)}},{key:"onAuthenticated",value:function e(t){return this.uiManager.on("authenticated",function(e){e&&typeof e=="string"&&t(e)})}},{key:"onCompleted",value:function e(t){return this.uiManager.on("completed",function(e){e&&typeof e=="string"&&t(e)})}},{key:"onUserCanceled",value:function e(t){return this.uiManager.on("userCanceled",t)}},{key:"show",value:function e(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};var r=this;return t(function(){var e,t;return a(this,function(i){switch(i.label){case 0:e=new URLSearchParams;e.append("flow",r.flow),r.publicKey&&e.append("public_key",r.publicKey);t={};return[4,r.uiManager.show((t.url="".concat(r.url,"?").concat(e.toString()),t))];case 1:i.sent(),n.onAuthenticated&&r.onAuthenticated(n.onAuthenticated),n.onCompleted&&r.onCompleted(n.onCompleted),n.onUserCanceled&&r.onUserCanceled(n.onUserCanceled);return[2]}})})()}},{key:"createButton",value:function e(t){return this.uiManager.createButton(t)}}]);return e}();var E="application/x-postmate-v1+json",k=5,C=0,x=function x(){return++C},N=function N(){var e;return M.debug?(e=console).log.apply(e,arguments):null},O=function O(e){var t=document.createElement("a");t.href=e;var n=t.protocol.length>4?t.protocol:window.location.protocol,r=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||n+"//"+r},A={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function P(e,t){return!(typeof t=="string"&&e.origin!==t||!e.data||typeof e.data=="object"&&!("postmate"in e.data)||e.data.type!==E||!A[e.data.postmate])},L=function L(e,t){var n=typeof e[t]=="function"?e[t]():e[t];return M.Promise.resolve(n)},V=function(){var e=function e(t){var n=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},process.env.NODE_ENV!=="production"&&(N("Parent: Registering API"),N("Parent: Awaiting messages...")),this.listener=function(e){if(!P(e,n.childOrigin))return!1;var t=((e||{}).data||{}).value||{},r=t.data,i=t.name;e.data.postmate==="emit"&&(process.env.NODE_ENV!=="production"&&N("Parent: Received event emission: "+i),i in n.events&&n.events[i].call(n,r))},this.parent.addEventListener("message",this.listener,!1),process.env.NODE_ENV!=="production"&&N("Parent: Awaiting event emissions from Child")};var t=e.prototype;return t.get=function(e){var t=this;return new M.Promise(function(n){var r=x(),i=function e(i){i.data.uid===r&&i.data.postmate==="reply"&&(t.parent.removeEventListener("message",e,!1),n(i.data.value))};t.parent.addEventListener("message",i,!1),t.child.postMessage({postmate:"request",type:E,property:e,uid:r},t.childOrigin)})},t.call=function(e,t){this.child.postMessage({postmate:"call",type:E,property:e,data:t},this.childOrigin)},t.on=function(e,t){this.events[e]=t},t.destroy=function(){process.env.NODE_ENV!=="production"&&N("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},e}(),D=function(){var e=function e(t){var n=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,process.env.NODE_ENV!=="production"&&(N("Child: Registering API"),N("Child: Awaiting messages...")),this.child.addEventListener("message",function(e){if(!!P(e,n.parentOrigin)){process.env.NODE_ENV!=="production"&&N("Child: Received request",e.data);var t=e.data,r=t.property,i=t.uid,o=t.data;if(e.data.postmate==="call"){r in n.model&&typeof n.model[r]=="function"&&n.model[r](o);return}L(n.model,r).then(function(t){return e.source.postMessage({property:r,postmate:"reply",type:E,uid:i,value:t},e.origin)})}})};var t=e.prototype;return t.emit=function(e,t){process.env.NODE_ENV!=="production"&&N('Child: Emitting Event "'+e+'"',t),this.parent.postMessage({postmate:"emit",type:E,value:{name:e,data:t}},this.parentOrigin)},e}(),M=function(){var e=function e(t){var n=t.container,r=n===void 0?(typeof r==="undefined"?"undefined":o(r))<"u"?r:document.body:n,i=t.model,a=t.url,s=t.name,u=t.classListArray,l=u===void 0?[]:u;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,l),r.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)};var t=e.prototype;return t.sendHandshake=function(t){var n=this,r=O(t),i=0,o;return new e.Promise(function(e,a){var s=function t(i){return P(i,r)?i.data.postmate==="handshake-reply"?(clearInterval(o),process.env.NODE_ENV!=="production"&&N("Parent: Received handshake reply from Child"),n.parent.removeEventListener("message",t,!1),n.childOrigin=i.origin,process.env.NODE_ENV!=="production"&&N("Parent: Saving Child origin",n.childOrigin),e(new V(n))):(process.env.NODE_ENV!=="production"&&N("Parent: Invalid handshake reply"),a("Failed handshake")):!1};n.parent.addEventListener("message",s,!1);var u=function u(){i++,process.env.NODE_ENV!=="production"&&N("Parent: Sending handshake attempt "+i,{childOrigin:r}),n.child.postMessage({postmate:"handshake",type:E,model:n.model},r),i===k&&clearInterval(o)},l=function l(){u(),o=setInterval(u,500)};n.frame.attachEvent?n.frame.attachEvent("onload",l):n.frame.onload=l,process.env.NODE_ENV!=="production"&&N("Parent: Loading frame",{url:t}),n.frame.src=t})},e}();M.debug=!1;M.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}();M.Model=function(){var e=function e(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()};var t=e.prototype;return t.sendHandshakeReply=function(){var e=this;return new M.Promise(function(t,n){var r=function r(i){if(!!i.data.postmate){if(i.data.postmate==="handshake"){process.env.NODE_ENV!=="production"&&N("Child: Received handshake from Parent"),e.child.removeEventListener("message",r,!1),process.env.NODE_ENV!=="production"&&N("Child: Sending handshake reply to Parent"),i.source.postMessage({postmate:"handshake-reply",type:E},i.origin),e.parentOrigin=i.origin;var o=i.data.model;return o&&(Object.keys(o).forEach(function(t){e.model[t]=o[t]}),process.env.NODE_ENV!=="production"&&N("Child: Inherited and extended model from Parent")),process.env.NODE_ENV!=="production"&&N("Child: Saving Parent origin",e.parentOrigin),t(new D(e))}return n("Handshake Reply Failed")}};e.child.addEventListener("message",r,!1)})},e}();var F=M;var I=function(){var e=document.createElement("style");e.type="text/css",e.innerHTML='\n .footprint-body-locked {\n overflow: hidden;\n }\n\n .footprint-overlay {\n align-items: center;\n background: rgba(0, 0, 0, 0.3);\n display: flex;\n height: 100%;\n justify-content: center;\n left: 0;\n overflow-y: hidden;\n position: fixed;\n top: 0;\n width: 100%;\n z-index: 50000;\n }\n\n @keyframes footprint-rotate {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n }\n\n .footprint-loading-indicator {\n background: rgba(0, 0, 0, 0.6);\n border-radius: 4px;\n padding: 16px;\n }\n\n .footprint-loading-spin {\n animation: footprint-rotate 0.8s linear infinite;\n }\n\n .footprint-modal {\n height: 100%;\n left: 0;\n position: fixed;\n top: 0;\n width: 100%;\n z-index: 50001;\n }\n\n .footprint-button {\n -webkit-box-align: center;\n align-items: center;\n background-color: rgb(14, 20, 56);\n border-radius: 6px;\n border: 0px;\n box-shadow: rgb(0 0 0 / 0%) 0px 1px 1px, transparent 0px 0px 0px 1px;\n color: rgb(255, 255, 255);\n cursor: pointer;\n display: flex;\n -webkit-box-pack: center;\n justify-content: center;\n text-decoration: none;\n user-select: none;\n font-family: "DM Sans";\n font-size: 16px;\n font-weight: 500;\n line-height: 24px;\n padding: 12px 24px;\n }\n\n .footprint-button:hover {\n background: linear-gradient(rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.14)), linear-gradient(rgb(14, 20, 56), rgb(14, 20, 56));\n }\n\n .footprint-button:active {\n background: linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)), linear-gradient(rgb(14, 20, 56), rgb(14, 20, 56));\n }\n\n .footprint-button svg {\n margin-right: 8px;\n }\n ',document.head.appendChild(e)},R=function(e){var t=document.createElement("div");t.setAttribute("id",e),t.classList.add("footprint-loading-indicator");var n=document.createElement("div");n.classList.add("footprint-loading-spin");var 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");var i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),i.setAttribute("fill","#FFFFFF"),r.appendChild(i),n.appendChild(r),t.appendChild(n),t},B=function(){var 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");var t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.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"),t.setAttribute("fill","#76fb8f"),e.appendChild(t),e},S=function(){var e=B(),t=document.createElement("button");t.appendChild(e);var n=document.createElement("span");return n.innerText="Verify with Footprint",t.appendChild(n),t.classList.add("footprint-button"),t};var H=function(){function e(){n(this,e);this.child=null;$||I()}i(e,[{key:"show",value:function e(n){var r=n.url;var i=this;return t(function(){var e,t,n,o;return a(this,function(a){switch(a.label){case 0:e=function(){var e=document.getElementById(m);e&&e.remove()},t=i.createContainer();i.showOverlay(t);o={};return[4,new F((o.classListArray=["footprint-modal"],o.container=t,o.name="footprint-iframe",o.url=r,o))];case 1:n=a.sent();n.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *"),e(),n.on("closed",function(){return i.hide()}),i.child=n;return[2]}})})()}},{key:"on",value:function e(t,n){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(t,n)}},{key:"hide",value:function e(){this.hideOverlay(),this.child&&this.child.destroy()}},{key:"createButton",value:function e(t){var n=S();return t.appendChild(n),n}},{key:"showOverlay",value:function e(t){document.body.classList.add("footprint-body-locked");var n=document.createElement("div");n.setAttribute("id",g);var r=R(m);n.appendChild(r),n.classList.add("footprint-overlay"),t.appendChild(n)}},{key:"hideOverlay",value:function e(){document.body.classList.remove("footprint-body-locked");var t=document.getElementById(g);t&&t.remove()}},{key:"createContainer",value:function e(){var t=document.getElementById(v);if(t)return t;var n=document.createElement("div");return n.setAttribute("id",v),document.body.appendChild(n),n}}]);return e}();var K=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"production",t=arguments.length>1?arguments[1]:void 0;return e==="local"?"http://localhost:3000/":e==="development"?"https://id.preview.onefootprint.com":e==="preview"&&t?t==="development"?"https://id.preview.onefootprint.com":"https://bifrost-git-".concat(t.toLowerCase().split("/").join("-"),".preview.onefootprint.com"):"https://id.onefootprint.com"},T=K(process.env.NEXT_PUBLIC_VERCEL_ENV,process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF),U=new H,j=new _(T,U);w(j)();var q=j;0&&(module.exports={}); |
{ | ||
"name": "@onefootprint/footprint-js", | ||
"private": false, | ||
"version": "0.1.0", | ||
"main": "./dist/index.js", | ||
"version": "0.1.1", | ||
"main": "./dist/index.global.js", | ||
"module": "./dist/index.mjs", | ||
@@ -14,4 +14,4 @@ "types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup src/index.ts --format esm,cjs --dts --minify", | ||
"dev": "tsup src/index.ts --format esm,cjs --watch --dts", | ||
"build": "tsup src/index.ts --format esm,iife --dts --minify", | ||
"dev": "tsup src/index.ts --format esm --watch --dts", | ||
"lint": "eslint src --fix", | ||
@@ -18,0 +18,0 @@ "typecheck": "yarn tsc --noEmit", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
39384
6
266
1