@onefootprint/footprint-js
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,5 +0,5 @@ | ||
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 || {}); | ||
var k = Object.defineProperty; | ||
var C = (a, t, e) => t in a ? k(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e; | ||
var b = (a, t, e) => (C(a, typeof t != "symbol" ? t + "" : t, e), e); | ||
var u = /* @__PURE__ */ ((a) => (a.closed = "closed", a.completed = "completed", a.canceled = "canceled", a))(u || {}); | ||
/** | ||
@@ -12,13 +12,10 @@ postmate - A powerful, simple, promise-based postMessage library | ||
**/ | ||
var h = "application/x-postmate-v1+json", I = 5, P = 0, k = function() { | ||
var l = "application/x-postmate-v1+json", O = 5, P = 0, M = function() { | ||
return ++P; | ||
}, d = function() { | ||
var t; | ||
return p.debug ? (t = console).log.apply(t, arguments) : null; | ||
}, D = function(t) { | ||
}, _ = 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; | ||
}, V = { | ||
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; | ||
}, F = { | ||
handshake: 1, | ||
@@ -30,62 +27,61 @@ "handshake-reply": 1, | ||
request: 1 | ||
}, 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 || !V[t.data.postmate]); | ||
}, R = function(t, e) { | ||
}, g = function(t, e) { | ||
return !(typeof e == "string" && t.origin !== e || !t.data || typeof t.data == "object" && !("postmate" in t.data) || t.data.type !== l || !F[t.data.postmate]); | ||
}, N = function(t, e) { | ||
var r = typeof t[e] == "function" ? t[e]() : t[e]; | ||
return p.Promise.resolve(r); | ||
}, M = /* @__PURE__ */ function() { | ||
function n(e) { | ||
}, x = /* @__PURE__ */ function() { | ||
function a(e) { | ||
var r = this; | ||
this.parent = e.parent, this.frame = e.frame, this.child = e.child, this.childOrigin = e.childOrigin, this.events = {}, process.env.NODE_ENV !== "production" && (d("Parent: Registering API"), d("Parent: Awaiting messages...")), this.listener = function(o) { | ||
if (!y(o, r.childOrigin)) | ||
this.parent = e.parent, this.frame = e.frame, this.child = e.child, this.childOrigin = e.childOrigin, this.events = {}, this.listener = function(n) { | ||
if (!g(n, 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 o = ((n || {}).data || {}).value || {}, i = o.data, s = o.name; | ||
n.data.postmate === "emit" && s in r.events && r.events[s].call(r, i); | ||
}, this.parent.addEventListener("message", this.listener, !1); | ||
} | ||
var t = n.prototype; | ||
var t = a.prototype; | ||
return t.get = function(r) { | ||
var o = this; | ||
return new p.Promise(function(i) { | ||
var a = k(), s = function c(l) { | ||
l.data.uid === a && l.data.postmate === "reply" && (o.parent.removeEventListener("message", c, !1), i(l.data.value)); | ||
var n = this; | ||
return new p.Promise(function(o) { | ||
var i = M(), s = function d(c) { | ||
c.data.uid === i && c.data.postmate === "reply" && (n.parent.removeEventListener("message", d, !1), o(c.data.value)); | ||
}; | ||
o.parent.addEventListener("message", s, !1), o.child.postMessage({ | ||
n.parent.addEventListener("message", s, !1), n.child.postMessage({ | ||
postmate: "request", | ||
type: h, | ||
type: l, | ||
property: r, | ||
uid: a | ||
}, o.childOrigin); | ||
uid: i | ||
}, n.childOrigin); | ||
}); | ||
}, t.call = function(r, o) { | ||
}, t.call = function(r, n) { | ||
this.child.postMessage({ | ||
postmate: "call", | ||
type: h, | ||
type: l, | ||
property: r, | ||
data: o | ||
data: n | ||
}, this.childOrigin); | ||
}, t.on = function(r, o) { | ||
this.events[r] = o; | ||
}, t.on = function(r, n) { | ||
this.events[r] = n; | ||
}, t.destroy = function() { | ||
process.env.NODE_ENV !== "production" && d("Parent: Destroying Postmate instance"), window.removeEventListener("message", this.listener, !1), this.frame.parentNode.removeChild(this.frame); | ||
}, n; | ||
window.removeEventListener("message", this.listener, !1), this.frame.parentNode.removeChild(this.frame); | ||
}, a; | ||
}(), B = /* @__PURE__ */ function() { | ||
function n(e) { | ||
function a(e) { | ||
var r = this; | ||
this.model = e.model, this.parent = e.parent, this.parentOrigin = e.parentOrigin, this.child = e.child, process.env.NODE_ENV !== "production" && (d("Child: Registering API"), d("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; | ||
if (o.data.postmate === "call") { | ||
a in r.model && typeof r.model[a] == "function" && r.model[a](c); | ||
this.model = e.model, this.parent = e.parent, this.parentOrigin = e.parentOrigin, this.child = e.child, this.child.addEventListener("message", function(n) { | ||
if (!!g(n, r.parentOrigin)) { | ||
var o = n.data, i = o.property, s = o.uid, d = o.data; | ||
if (n.data.postmate === "call") { | ||
i in r.model && typeof r.model[i] == "function" && r.model[i](d); | ||
return; | ||
} | ||
R(r.model, a).then(function(l) { | ||
return o.source.postMessage({ | ||
property: a, | ||
N(r.model, i).then(function(c) { | ||
return n.source.postMessage({ | ||
property: i, | ||
postmate: "reply", | ||
type: h, | ||
type: l, | ||
uid: s, | ||
value: l | ||
}, o.origin); | ||
value: c | ||
}, n.origin); | ||
}); | ||
@@ -95,42 +91,38 @@ } | ||
} | ||
var t = n.prototype; | ||
return t.emit = function(r, o) { | ||
process.env.NODE_ENV !== "production" && d('Child: Emitting Event "' + r + '"', o), this.parent.postMessage({ | ||
var t = a.prototype; | ||
return t.emit = function(r, n) { | ||
this.parent.postMessage({ | ||
postmate: "emit", | ||
type: h, | ||
type: l, | ||
value: { | ||
name: r, | ||
data: o | ||
data: n | ||
} | ||
}, this.parentOrigin); | ||
}, n; | ||
}, a; | ||
}(), p = /* @__PURE__ */ function() { | ||
function n(e) { | ||
var r = e.container, o = r === void 0 ? typeof o < "u" ? o : document.body : r, i = e.model, a = e.url, s = e.name, c = e.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 a(e) { | ||
var r = e.container, n = r === void 0 ? typeof n < "u" ? n : document.body : r, o = e.model, i = e.url, s = e.name, d = e.classListArray, c = 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, c), n.appendChild(this.frame), this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow, this.model = o || {}, this.sendHandshake(i); | ||
} | ||
var t = n.prototype; | ||
var t = a.prototype; | ||
return t.sendHandshake = function(r) { | ||
var o = this, i = D(r), a = 0, s; | ||
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 M(o))) : (process.env.NODE_ENV !== "production" && d("Parent: Invalid handshake reply"), l("Failed handshake")) : !1; | ||
var n = this, o = _(r), i = 0, s; | ||
return new a.Promise(function(d, c) { | ||
var h = function m(f) { | ||
return g(f, o) ? f.data.postmate === "handshake-reply" ? (clearInterval(s), n.parent.removeEventListener("message", m, !1), n.childOrigin = f.origin, d(new x(n))) : c("Failed handshake") : !1; | ||
}; | ||
o.parent.addEventListener("message", u, !1); | ||
var E = function() { | ||
a++, process.env.NODE_ENV !== "production" && d("Parent: Sending handshake attempt " + a, { | ||
childOrigin: i | ||
}), o.child.postMessage({ | ||
n.parent.addEventListener("message", h, !1); | ||
var y = function() { | ||
i++, n.child.postMessage({ | ||
postmate: "handshake", | ||
type: h, | ||
model: o.model | ||
}, i), a === I && clearInterval(s); | ||
type: l, | ||
model: n.model | ||
}, o), i === O && clearInterval(s); | ||
}, w = function() { | ||
E(), s = setInterval(E, 500); | ||
y(), s = setInterval(y, 500); | ||
}; | ||
o.frame.attachEvent ? o.frame.attachEvent("onload", w) : o.frame.onload = w, process.env.NODE_ENV !== "production" && d("Parent: Loading frame", { | ||
url: r | ||
}), o.frame.src = r; | ||
n.frame.attachEvent ? n.frame.attachEvent("onload", w) : n.frame.onload = w, n.frame.src = r; | ||
}); | ||
}, n; | ||
}, a; | ||
}(); | ||
@@ -146,53 +138,53 @@ p.debug = !1; | ||
p.Model = /* @__PURE__ */ function() { | ||
function n(e) { | ||
function a(e) { | ||
return this.child = window, this.model = e, this.parent = this.child.parent, this.sendHandshakeReply(); | ||
} | ||
var t = n.prototype; | ||
var t = a.prototype; | ||
return t.sendHandshakeReply = function() { | ||
var r = this; | ||
return new p.Promise(function(o, i) { | ||
var a = function s(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({ | ||
return new p.Promise(function(n, o) { | ||
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: h | ||
}, c.origin), r.parentOrigin = c.origin; | ||
var l = c.data.model; | ||
return l && (Object.keys(l).forEach(function(u) { | ||
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 B(r)); | ||
type: l | ||
}, d.origin), r.parentOrigin = d.origin; | ||
var c = d.data.model; | ||
return c && Object.keys(c).forEach(function(h) { | ||
r.model[h] = c[h]; | ||
}), n(new B(r)); | ||
} | ||
return i("Handshake Reply Failed"); | ||
return o("Handshake Reply Failed"); | ||
} | ||
}; | ||
r.child.addEventListener("message", a, !1); | ||
r.child.addEventListener("message", i, !1); | ||
}); | ||
}, n; | ||
}, a; | ||
}(); | ||
const N = "footprint-container", O = "footprint-overlay", C = "footprint-loading-indicator", F = (n) => { | ||
const t = _(); | ||
return n.appendChild(t), t; | ||
}, S = (n) => { | ||
const A = "footprint-container", L = "footprint-overlay", E = "footprint-loading-indicator", H = (a) => { | ||
const t = I(); | ||
return a.appendChild(t), t; | ||
}, R = (a) => { | ||
document.body.classList.add("footprint-body-locked"); | ||
const t = document.createElement("div"); | ||
t.setAttribute("id", O); | ||
const e = $(C); | ||
t.appendChild(e), t.classList.add("footprint-overlay"), n.appendChild(t); | ||
}, x = () => { | ||
const n = document.getElementById(C); | ||
n && n.remove(); | ||
}, T = () => { | ||
t.setAttribute("id", L); | ||
const e = T(E); | ||
t.appendChild(e), t.classList.add("footprint-overlay"), a.appendChild(t); | ||
}, D = () => { | ||
const a = document.getElementById(E); | ||
a && a.remove(); | ||
}, S = () => { | ||
document.body.classList.remove("footprint-body-locked"); | ||
const n = document.getElementById(O); | ||
n && n.remove(); | ||
}, H = () => { | ||
const n = document.getElementById(N); | ||
if (n) | ||
return n; | ||
const a = document.getElementById(L); | ||
a && a.remove(); | ||
}, V = () => { | ||
const a = document.getElementById(A); | ||
if (a) | ||
return a; | ||
const t = document.createElement("div"); | ||
return t.setAttribute("id", N), document.body.appendChild(t), t; | ||
}, $ = (n) => { | ||
return t.setAttribute("id", A), document.body.appendChild(t), t; | ||
}, T = (a) => { | ||
const t = document.createElement("div"); | ||
t.setAttribute("id", n), t.classList.add("footprint-loading-indicator"); | ||
t.setAttribute("id", a), t.classList.add("footprint-loading-indicator"); | ||
const e = document.createElement("div"); | ||
@@ -202,7 +194,7 @@ e.classList.add("footprint-loading-spin"); | ||
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), 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 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"), n.setAttribute("fill", "#FFFFFF"), r.appendChild(n), e.appendChild(r), t.appendChild(e), t; | ||
}, $ = () => { | ||
const a = document.createElementNS("http://www.w3.org/2000/svg", "svg"); | ||
a.setAttribute("width", "24px"), a.setAttribute("height", "24px"), a.setAttribute("fill", "none"), a.setAttribute("aria-hidden", "true"); | ||
const t = document.createElementNS("http://www.w3.org/2000/svg", "path"); | ||
@@ -212,10 +204,10 @@ return t.setAttribute( | ||
"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"), n.appendChild(t), n; | ||
}, _ = () => { | ||
const n = j(), t = document.createElement("button"); | ||
t.appendChild(n); | ||
), t.setAttribute("fill", "#76fb8f"), a.appendChild(t), a; | ||
}, I = () => { | ||
const a = $(), t = document.createElement("button"); | ||
t.appendChild(a); | ||
const e = document.createElement("span"); | ||
return e.innerText = "Verify with Footprint", t.appendChild(e), t.classList.add("footprint-button"), t; | ||
}; | ||
class q { | ||
class j { | ||
constructor() { | ||
@@ -226,15 +218,15 @@ b(this, "child", null); | ||
const { url: e } = t, r = () => { | ||
x(); | ||
}, o = H(); | ||
S(o); | ||
const i = await new p({ | ||
D(); | ||
}, n = V(); | ||
R(n); | ||
const o = await new p({ | ||
classListArray: ["footprint-modal"], | ||
container: o, | ||
container: n, | ||
name: "footprint-iframe", | ||
url: e | ||
}); | ||
i.frame.setAttribute( | ||
o.frame.setAttribute( | ||
"allow", | ||
"otp-credentials; publickey-credentials-get *; camera *;" | ||
), r(), i.on(f.closed, () => this.hide()), this.child = i; | ||
), r(), o.on(u.closed, () => this.hide()), this.child = o; | ||
} | ||
@@ -247,64 +239,59 @@ on(t, e) { | ||
hide() { | ||
T(), this.child && this.child.destroy(); | ||
S(), this.child && this.child.destroy(); | ||
} | ||
createButton(t) { | ||
const e = _(); | ||
const e = I(); | ||
return t.appendChild(e), e; | ||
} | ||
} | ||
const g = new q(), U = (n) => { | ||
const t = (r) => g.on(f.completed, (o) => { | ||
o && typeof o == "string" && r(o); | ||
}), e = (r) => g.on(f.canceled, r); | ||
const v = new j(), q = (a) => { | ||
const t = (r) => v.on(u.completed, (n) => { | ||
n && typeof n == "string" && r(n); | ||
}), e = (r) => v.on(u.canceled, r); | ||
return { | ||
show: async ({ publicKey: r, onCompleted: o, onCanceled: i }) => { | ||
await g.show({ | ||
url: r ? `${n}?public_key=${r}` : n | ||
}), o && t(o), i && e(i); | ||
show: async ({ publicKey: r, onCompleted: n, onCanceled: o }) => { | ||
await v.show({ | ||
url: r ? `${a}?public_key=${r}` : a | ||
}), n && t(n), o && e(o); | ||
} | ||
}; | ||
}, z = typeof window > "u", G = (n) => { | ||
window.setTimeout(n, 0); | ||
}, W = (n) => { | ||
const t = async (i) => { | ||
await n.show({ | ||
publicKey: i, | ||
}, z = (a) => { | ||
window.setTimeout(a, 0); | ||
}, W = (a) => { | ||
if (typeof window > "u") | ||
return; | ||
const t = async (n) => { | ||
await a.show({ | ||
publicKey: n, | ||
onCanceled: () => { | ||
var a; | ||
(a = window.onFootprintCanceled) == null || a.call(window); | ||
var o; | ||
(o = window.onFootprintCanceled) == null || o.call(window); | ||
}, | ||
onCompleted: (a) => { | ||
var s; | ||
(s = window.onFootprintCompleted) == null || s.call(window, a); | ||
onCompleted: (o) => { | ||
var i; | ||
(i = window.onFootprintCompleted) == null || i.call(window, o); | ||
} | ||
}); | ||
}, e = () => { | ||
const i = document.getElementById("footprint-button"); | ||
if (!i) | ||
const n = document.getElementById("footprint-button"); | ||
if (!n) | ||
return; | ||
const a = i.getAttribute("data-public-key"); | ||
if (!a) | ||
const o = n.getAttribute("data-public-key"); | ||
if (!o) | ||
throw Error( | ||
"A public key must be passed as `data-public-key` in the #footprint-button element" | ||
); | ||
r(a, i); | ||
}, r = (i, a) => { | ||
G(() => { | ||
F(a).addEventListener("click", () => { | ||
t(i); | ||
r(o, n); | ||
}, r = (n, o) => { | ||
z(() => { | ||
H(o).addEventListener("click", () => { | ||
t(n); | ||
}); | ||
}); | ||
}, o = () => { | ||
z || document.addEventListener("DOMContentLoaded", () => e()); | ||
}; | ||
return () => { | ||
o(); | ||
}; | ||
}, X = (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", Z = X( | ||
process.env.NEXT_PUBLIC_VERCEL_ENV, | ||
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF | ||
), Y = U(Z); | ||
W(Y)(); | ||
document.addEventListener("DOMContentLoaded", () => e()); | ||
}, Z = () => "https://id.onefootprint.com", G = Z(), U = q(G); | ||
W(U); | ||
export { | ||
Y as default | ||
U 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.0.4", | ||
"version": "0.0.5", | ||
"main": "./dist/footprint-js.umd.cjs", | ||
@@ -12,4 +12,4 @@ "module": "./dist/footprint-js.js", | ||
".": { | ||
"require": "./dist/footprint-js.umd.cjs", | ||
"import": "./dist/footprint-js.js", | ||
"require": "./dist/footprint-js.umd.cjs", | ||
"types": "./dist/footprint-js.d.ts" | ||
@@ -16,0 +16,0 @@ }, |
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
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
0
25164
385