@onefootprint/footprint-js
Advanced tools
Comparing version 0.3.1-beta.6 to 0.3.1-experimental.1
@@ -1,4 +0,4 @@ | ||
var I = Object.defineProperty; | ||
var P = (n, e, t) => e in n ? I(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; | ||
var b = (n, e, t) => (P(n, typeof e != "symbol" ? e + "" : e, t), t); | ||
var L = Object.defineProperty; | ||
var A = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e; | ||
var b = (n, t, e) => (A(n, typeof t != "symbol" ? t + "" : t, e), e); | ||
var f = /* @__PURE__ */ ((n) => (n.closed = "closed", n.completed = "completed", n.canceled = "canceled", n))(f || {}); | ||
@@ -12,13 +12,13 @@ /** | ||
**/ | ||
var h = "application/x-postmate-v1+json", k = 5, D = 0, V = function() { | ||
return ++D; | ||
}, d = function() { | ||
var e; | ||
return p.debug ? (e = console).log.apply(e, arguments) : null; | ||
}, R = function(e) { | ||
var t = document.createElement("a"); | ||
t.href = e; | ||
var r = 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 || r + "//" + o; | ||
}, M = { | ||
var h = "application/x-postmate-v1+json", I = 5, P = 0, k = function() { | ||
return ++P; | ||
}, s = function() { | ||
var t; | ||
return p.debug ? (t = console).log.apply(t, arguments) : null; | ||
}, V = function(t) { | ||
var e = document.createElement("a"); | ||
e.href = t; | ||
var r = e.protocol.length > 4 ? e.protocol : window.location.protocol, o = e.host.length ? e.port === "80" || e.port === "443" ? e.hostname : e.host : window.location.host; | ||
return e.origin || r + "//" + o; | ||
}, D = { | ||
handshake: 1, | ||
@@ -30,25 +30,25 @@ "handshake-reply": 1, | ||
request: 1 | ||
}, y = function(e, t) { | ||
return !(typeof t == "string" && e.origin !== t || !e.data || typeof e.data == "object" && !("postmate" in e.data) || e.data.type !== h || !M[e.data.postmate]); | ||
}, B = function(e, t) { | ||
var r = typeof e[t] == "function" ? e[t]() : e[t]; | ||
}, y = function(t, e) { | ||
return !(typeof e == "string" && t.origin !== e || !t.data || typeof t.data == "object" && !("postmate" in t.data) || t.data.type !== h || !D[t.data.postmate]); | ||
}, M = function(t, e) { | ||
var r = typeof t[e] == "function" ? t[e]() : t[e]; | ||
return p.Promise.resolve(r); | ||
}, F = /* @__PURE__ */ function() { | ||
function n(t) { | ||
}, R = /* @__PURE__ */ function() { | ||
function n(e) { | ||
var r = this; | ||
this.parent = t.parent, this.frame = t.frame, this.child = t.child, this.childOrigin = t.childOrigin, this.events = {}, process.env.NODE_ENV !== "production" && (d("Parent: Registering API"), d("Parent: Awaiting messages...")), this.listener = function(o) { | ||
this.parent = e.parent, this.frame = e.frame, this.child = e.child, this.childOrigin = e.childOrigin, this.events = {}, process.env.NODE_ENV !== "production" && (s("Parent: Registering API"), s("Parent: Awaiting messages...")), this.listener = function(o) { | ||
if (!y(o, r.childOrigin)) | ||
return !1; | ||
var i = ((o || {}).data || {}).value || {}, a = i.data, s = i.name; | ||
o.data.postmate === "emit" && (process.env.NODE_ENV !== "production" && d("Parent: Received event emission: " + s), s in r.events && r.events[s].call(r, a)); | ||
}, this.parent.addEventListener("message", this.listener, !1), process.env.NODE_ENV !== "production" && d("Parent: Awaiting event emissions from Child"); | ||
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 e = n.prototype; | ||
return e.get = function(r) { | ||
var t = n.prototype; | ||
return t.get = function(r) { | ||
var o = this; | ||
return new p.Promise(function(i) { | ||
var a = V(), s = function c(l) { | ||
var a = k(), d = function c(l) { | ||
l.data.uid === a && l.data.postmate === "reply" && (o.parent.removeEventListener("message", c, !1), i(l.data.value)); | ||
}; | ||
o.parent.addEventListener("message", s, !1), o.child.postMessage({ | ||
o.parent.addEventListener("message", d, !1), o.child.postMessage({ | ||
postmate: "request", | ||
@@ -60,3 +60,3 @@ type: h, | ||
}); | ||
}, e.call = function(r, o) { | ||
}, t.call = function(r, o) { | ||
this.child.postMessage({ | ||
@@ -68,14 +68,14 @@ postmate: "call", | ||
}, this.childOrigin); | ||
}, e.on = function(r, o) { | ||
}, t.on = function(r, o) { | ||
this.events[r] = o; | ||
}, e.destroy = function() { | ||
process.env.NODE_ENV !== "production" && d("Parent: Destroying Postmate instance"), window.removeEventListener("message", this.listener, !1), this.frame.parentNode.removeChild(this.frame); | ||
}, 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); | ||
}, n; | ||
}(), S = /* @__PURE__ */ function() { | ||
function n(t) { | ||
}(), B = /* @__PURE__ */ function() { | ||
function n(e) { | ||
var r = this; | ||
this.model = t.model, this.parent = t.parent, this.parentOrigin = t.parentOrigin, this.child = t.child, process.env.NODE_ENV !== "production" && (d("Child: Registering API"), d("Child: Awaiting messages...")), this.child.addEventListener("message", function(o) { | ||
this.model = e.model, this.parent = e.parent, this.parentOrigin = e.parentOrigin, this.child = e.child, process.env.NODE_ENV !== "production" && (s("Child: Registering API"), s("Child: Awaiting messages...")), this.child.addEventListener("message", function(o) { | ||
if (!!y(o, r.parentOrigin)) { | ||
process.env.NODE_ENV !== "production" && d("Child: Received request", o.data); | ||
var i = o.data, a = i.property, s = i.uid, c = i.data; | ||
process.env.NODE_ENV !== "production" && s("Child: Received request", o.data); | ||
var i = o.data, a = i.property, d = i.uid, c = i.data; | ||
if (o.data.postmate === "call") { | ||
@@ -85,3 +85,3 @@ a in r.model && typeof r.model[a] == "function" && r.model[a](c); | ||
} | ||
B(r.model, a).then(function(l) { | ||
M(r.model, a).then(function(l) { | ||
return o.source.postMessage({ | ||
@@ -91,3 +91,3 @@ property: a, | ||
type: h, | ||
uid: s, | ||
uid: d, | ||
value: l | ||
@@ -99,5 +99,5 @@ }, o.origin); | ||
} | ||
var e = n.prototype; | ||
return e.emit = function(r, o) { | ||
process.env.NODE_ENV !== "production" && d('Child: Emitting Event "' + r + '"', o), this.parent.postMessage({ | ||
var t = n.prototype; | ||
return t.emit = function(r, o) { | ||
process.env.NODE_ENV !== "production" && s('Child: Emitting Event "' + r + '"', o), this.parent.postMessage({ | ||
postmate: "emit", | ||
@@ -112,16 +112,16 @@ type: h, | ||
}(), p = /* @__PURE__ */ function() { | ||
function n(t) { | ||
var r = t.container, o = r === void 0 ? typeof o < "u" ? o : document.body : r, i = t.model, a = t.url, s = t.name, c = t.classListArray, l = c === void 0 ? [] : c; | ||
return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = s || "", 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); | ||
function n(e) { | ||
var r = e.container, o = r === void 0 ? typeof o < "u" ? o : document.body : r, i = e.model, a = e.url, d = e.name, c = e.classListArray, l = c === void 0 ? [] : c; | ||
return this.parent = window, this.frame = document.createElement("iframe"), this.frame.name = d || "", this.frame.classList.add.apply(this.frame.classList, l), o.appendChild(this.frame), this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow, this.model = i || {}, this.sendHandshake(a); | ||
} | ||
var e = n.prototype; | ||
return e.sendHandshake = function(r) { | ||
var o = this, i = R(r), a = 0, s; | ||
var t = n.prototype; | ||
return t.sendHandshake = function(r) { | ||
var o = this, i = V(r), a = 0, d; | ||
return new n.Promise(function(c, l) { | ||
var u = function m(v) { | ||
return y(v, i) ? v.data.postmate === "handshake-reply" ? (clearInterval(s), process.env.NODE_ENV !== "production" && d("Parent: Received handshake reply from Child"), o.parent.removeEventListener("message", m, !1), o.childOrigin = v.origin, process.env.NODE_ENV !== "production" && d("Parent: Saving Child origin", o.childOrigin), c(new F(o))) : (process.env.NODE_ENV !== "production" && d("Parent: Invalid handshake reply"), l("Failed handshake")) : !1; | ||
return y(v, i) ? v.data.postmate === "handshake-reply" ? (clearInterval(d), process.env.NODE_ENV !== "production" && s("Parent: Received handshake reply from Child"), o.parent.removeEventListener("message", m, !1), o.childOrigin = v.origin, process.env.NODE_ENV !== "production" && s("Parent: Saving Child origin", o.childOrigin), c(new R(o))) : (process.env.NODE_ENV !== "production" && s("Parent: Invalid handshake reply"), l("Failed handshake")) : !1; | ||
}; | ||
o.parent.addEventListener("message", u, !1); | ||
var E = function() { | ||
a++, process.env.NODE_ENV !== "production" && d("Parent: Sending handshake attempt " + a, { | ||
a++, process.env.NODE_ENV !== "production" && s("Parent: Sending handshake attempt " + a, { | ||
childOrigin: i | ||
@@ -132,7 +132,7 @@ }), o.child.postMessage({ | ||
model: o.model | ||
}, i), a === k && clearInterval(s); | ||
}, i), a === I && clearInterval(d); | ||
}, w = function() { | ||
E(), s = setInterval(E, 500); | ||
E(), d = setInterval(E, 500); | ||
}; | ||
o.frame.attachEvent ? o.frame.attachEvent("onload", w) : o.frame.onload = w, process.env.NODE_ENV !== "production" && d("Parent: Loading frame", { | ||
o.frame.attachEvent ? o.frame.attachEvent("onload", w) : o.frame.onload = w, process.env.NODE_ENV !== "production" && s("Parent: Loading frame", { | ||
url: r | ||
@@ -152,13 +152,13 @@ }), o.frame.src = r; | ||
p.Model = /* @__PURE__ */ function() { | ||
function n(t) { | ||
return this.child = window, this.model = t, this.parent = this.child.parent, this.sendHandshakeReply(); | ||
function n(e) { | ||
return this.child = window, this.model = e, this.parent = this.child.parent, this.sendHandshakeReply(); | ||
} | ||
var e = n.prototype; | ||
return e.sendHandshakeReply = function() { | ||
var t = n.prototype; | ||
return t.sendHandshakeReply = function() { | ||
var r = this; | ||
return new p.Promise(function(o, i) { | ||
var a = function s(c) { | ||
var a = function d(c) { | ||
if (!!c.data.postmate) { | ||
if (c.data.postmate === "handshake") { | ||
process.env.NODE_ENV !== "production" && d("Child: Received handshake from Parent"), r.child.removeEventListener("message", s, !1), process.env.NODE_ENV !== "production" && d("Child: Sending handshake reply to Parent"), c.source.postMessage({ | ||
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"), c.source.postMessage({ | ||
postmate: "handshake-reply", | ||
@@ -170,3 +170,3 @@ type: h | ||
r.model[u] = l[u]; | ||
}), process.env.NODE_ENV !== "production" && d("Child: Inherited and extended model from Parent")), process.env.NODE_ENV !== "production" && d("Child: Saving Parent origin", r.parentOrigin), o(new S(r)); | ||
}), 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 B(r)); | ||
} | ||
@@ -180,56 +180,56 @@ return i("Handshake Reply Failed"); | ||
}(); | ||
const N = "footprint-container", O = "footprint-overlay", C = "footprint-loading-indicator", x = (n) => { | ||
const e = _(); | ||
return n.appendChild(e), e; | ||
}, T = (n) => { | ||
const N = "footprint-container", O = "footprint-overlay", C = "footprint-loading-indicator", F = (n) => { | ||
const t = _(); | ||
return n.appendChild(t), t; | ||
}, x = (n) => { | ||
document.body.classList.add("footprint-body-locked"); | ||
const e = document.createElement("div"); | ||
e.setAttribute("id", O); | ||
const t = q(C); | ||
e.appendChild(t), e.classList.add("footprint-overlay"), n.appendChild(e); | ||
}, H = () => { | ||
const t = document.createElement("div"); | ||
t.setAttribute("id", O); | ||
const e = $(C); | ||
t.appendChild(e), t.classList.add("footprint-overlay"), n.appendChild(t); | ||
}, S = () => { | ||
const n = document.getElementById(C); | ||
n && n.remove(); | ||
}, $ = () => { | ||
}, T = () => { | ||
document.body.classList.remove("footprint-body-locked"); | ||
const n = document.getElementById(O); | ||
n && n.remove(); | ||
}, j = () => { | ||
}, H = () => { | ||
const n = document.getElementById(N); | ||
if (n) | ||
return n; | ||
const t = document.createElement("div"); | ||
return t.setAttribute("id", N), document.body.appendChild(t), t; | ||
}, $ = (n) => { | ||
const t = document.createElement("div"); | ||
t.setAttribute("id", n), t.classList.add("footprint-loading-indicator"); | ||
const e = document.createElement("div"); | ||
return e.setAttribute("id", N), document.body.appendChild(e), e; | ||
}, q = (n) => { | ||
const e = document.createElement("div"); | ||
e.setAttribute("id", n), e.classList.add("footprint-loading-indicator"); | ||
const t = document.createElement("div"); | ||
t.classList.add("footprint-loading-spin"); | ||
e.classList.add("footprint-loading-spin"); | ||
const 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"); | ||
const 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), t.appendChild(r), e.appendChild(t), e; | ||
}, U = () => { | ||
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), e.appendChild(r), t.appendChild(e), t; | ||
}, j = () => { | ||
const 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"); | ||
const e = document.createElementNS("http://www.w3.org/2000/svg", "path"); | ||
return e.setAttribute( | ||
const 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" | ||
), e.setAttribute("fill", "#76fb8f"), n.appendChild(e), n; | ||
), t.setAttribute("fill", "#76fb8f"), n.appendChild(t), n; | ||
}, _ = () => { | ||
const n = U(), e = document.createElement("button"); | ||
e.appendChild(n); | ||
const t = document.createElement("span"); | ||
return t.innerText = "Verify with Footprint", e.appendChild(t), e.classList.add("footprint-button"), e; | ||
const n = j(), t = document.createElement("button"); | ||
t.appendChild(n); | ||
const e = document.createElement("span"); | ||
return e.innerText = "Verify with Footprint", t.appendChild(e), t.classList.add("footprint-button"), t; | ||
}; | ||
class z { | ||
class q { | ||
constructor() { | ||
b(this, "child", null); | ||
} | ||
async show(e) { | ||
const { url: t } = e, r = () => { | ||
H(); | ||
}, o = j(); | ||
T(o); | ||
async show(t) { | ||
const { url: e } = t, r = () => { | ||
S(); | ||
}, o = H(); | ||
x(o); | ||
const i = await new p({ | ||
@@ -239,3 +239,3 @@ classListArray: ["footprint-modal"], | ||
name: "footprint-iframe", | ||
url: t | ||
url: e | ||
}); | ||
@@ -247,19 +247,19 @@ i.frame.setAttribute( | ||
} | ||
on(e, t) { | ||
on(t, e) { | ||
if (!this.child) | ||
throw new Error("Footprint should be open in order to listen events"); | ||
return this.child.on(e, t); | ||
return this.child.on(t, e); | ||
} | ||
hide() { | ||
$(), this.child && this.child.destroy(); | ||
T(), this.child && this.child.destroy(); | ||
} | ||
createButton(e) { | ||
const t = _(); | ||
return e.appendChild(t), t; | ||
createButton(t) { | ||
const e = _(); | ||
return t.appendChild(e), e; | ||
} | ||
} | ||
const g = new z(), G = (n) => { | ||
const e = (r) => g.on(f.completed, (o) => { | ||
const g = new q(), U = (n) => { | ||
const t = (r) => g.on(f.completed, (o) => { | ||
o && typeof o == "string" && r(o); | ||
}), t = (r) => g.on(f.canceled, r); | ||
}), e = (r) => g.on(f.canceled, r); | ||
return { | ||
@@ -269,54 +269,48 @@ show: async ({ publicKey: r, onCompleted: o, onCanceled: i }) => { | ||
url: r ? `${n}?public_key=${r}` : n | ||
}), o && e(o), i && t(i); | ||
}), o && t(o), i && e(i); | ||
} | ||
}; | ||
}, W = typeof window > "u", X = (n) => { | ||
}, z = (n) => { | ||
window.setTimeout(n, 0); | ||
}, L = (n) => { | ||
console.log("0"); | ||
const e = async (i) => { | ||
}, G = (n) => { | ||
if (typeof window > "u") | ||
return; | ||
const t = async (o) => { | ||
await n.show({ | ||
publicKey: i, | ||
publicKey: o, | ||
onCanceled: () => { | ||
var i; | ||
(i = window.onFootprintCanceled) == null || i.call(window); | ||
}, | ||
onCompleted: (i) => { | ||
var a; | ||
(a = window.onFootprintCanceled) == null || a.call(window); | ||
}, | ||
onCompleted: (a) => { | ||
var s; | ||
(s = window.onFootprintCompleted) == null || s.call(window, a); | ||
(a = window.onFootprintCompleted) == null || a.call(window, i); | ||
} | ||
}); | ||
}, t = () => { | ||
console.log("4"); | ||
const i = document.getElementById("footprint-button"); | ||
}, e = () => { | ||
console.log("page loaded"); | ||
const o = document.getElementById("footprint-button"); | ||
if (!o) | ||
return; | ||
const i = o.getAttribute("data-public-key"); | ||
if (!i) | ||
return; | ||
console.log("5"); | ||
const 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" | ||
); | ||
console.log("6"), r(a, i); | ||
}, r = (i, a) => { | ||
X(() => { | ||
x(a).addEventListener("click", () => { | ||
e(i); | ||
r(i, o); | ||
}, r = (o, i) => { | ||
z(() => { | ||
F(i).addEventListener("click", () => { | ||
t(o); | ||
}); | ||
}); | ||
}, o = () => { | ||
console.log("2"), !W && (console.log("3"), document.addEventListener("DOMContentLoaded", () => t())); | ||
}; | ||
return () => { | ||
console.log("1"), o(); | ||
}; | ||
}, Z = (n = "production", e) => n === "local" ? "http://localhost:3000/" : n === "development" ? "https://id.preview.onefootprint.com" : n === "preview" && e ? e === "development" ? "https://id.preview.onefootprint.com" : `https://bifrost-git-${e.toLowerCase().split("/").join("-")}.preview.onefootprint.com` : "https://id.onefootprint.com", A = Z( | ||
document.addEventListener("DOMContentLoaded", () => e()); | ||
}, W = (n = "production", t) => n === "local" ? "http://localhost:3000/" : n === "development" ? "https://id.preview.onefootprint.com" : n === "preview" && t ? t === "development" ? "https://id.preview.onefootprint.com" : `https://bifrost-git-${t.toLowerCase().split("/").join("-")}.preview.onefootprint.com` : "https://id.onefootprint.com", X = W( | ||
process.env.NEXT_PUBLIC_VERCEL_ENV, | ||
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF | ||
), Y = G(A); | ||
console.log("url", A); | ||
console.log("vanillaIntegration", L); | ||
L(Y)(); | ||
), Z = U(X); | ||
G(Z); | ||
export { | ||
Y as default | ||
Z as default | ||
}; |
import { Footprint } from '../footprint-types'; | ||
declare const vanillaIntegration: (footprint: Footprint) => () => void; | ||
export default vanillaIntegration; | ||
declare const startVanillaIntegration: (footprint: Footprint) => void; | ||
export default startVanillaIntegration; | ||
//# sourceMappingURL=vanilla-integration.d.ts.map |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "0.3.1-beta.6", | ||
"version": "0.3.1-experimental.1", | ||
"main": "./dist/footprint-js.umd.cjs", | ||
@@ -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
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
28977
405