@cal.macconnachie/web-components 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/auth.js +31 -23
- package/dist/index.js +31 -23
- package/package.json +1 -1
package/dist/components/auth.js
CHANGED
|
@@ -1663,7 +1663,12 @@ let m = class extends H {
|
|
|
1663
1663
|
}
|
|
1664
1664
|
}
|
|
1665
1665
|
setAuthTokens(e, t, s) {
|
|
1666
|
-
this.cookies.setAuthToken("ACCESS_TOKEN", e), this.cookies.setAuthToken("AUTH_TOKEN", t), this.cookies.setAuthToken("REFRESH_TOKEN", s), this.isLoggedIn = !0
|
|
1666
|
+
this.cookies.setAuthToken("ACCESS_TOKEN", e), this.cookies.setAuthToken("AUTH_TOKEN", t), this.cookies.setAuthToken("REFRESH_TOKEN", s), this.isLoggedIn = !0, this.dispatchEvent(
|
|
1667
|
+
new CustomEvent("auth-success", {
|
|
1668
|
+
bubbles: !0,
|
|
1669
|
+
composed: !0
|
|
1670
|
+
})
|
|
1671
|
+
);
|
|
1667
1672
|
}
|
|
1668
1673
|
async handleSignIn() {
|
|
1669
1674
|
const e = {
|
|
@@ -1709,7 +1714,7 @@ let m = class extends H {
|
|
|
1709
1714
|
this.error = this.baseUrlErrorMessage;
|
|
1710
1715
|
return;
|
|
1711
1716
|
}
|
|
1712
|
-
this.hasHandledOAuthCallback = !0, this.isLoading = !0, this.error = "";
|
|
1717
|
+
this.open = !0, this.isVisible = !0, this.hasHandledOAuthCallback = !0, this.isLoading = !0, this.error = "";
|
|
1713
1718
|
try {
|
|
1714
1719
|
if (a)
|
|
1715
1720
|
throw new Error(c || `OAuth error: ${a}`);
|
|
@@ -1719,7 +1724,7 @@ let m = class extends H {
|
|
|
1719
1724
|
refreshToken: i,
|
|
1720
1725
|
idToken: s
|
|
1721
1726
|
});
|
|
1722
|
-
this.setAuthTokens(h, d, l ?? i);
|
|
1727
|
+
this.setAuthTokens(h, d, l ?? i), this.handleClose();
|
|
1723
1728
|
} else if (r && o) {
|
|
1724
1729
|
if (!this.isOAuthConfigured())
|
|
1725
1730
|
throw new Error("OAuth is not configured correctly. Please try again later.");
|
|
@@ -1733,7 +1738,7 @@ let m = class extends H {
|
|
|
1733
1738
|
refreshToken: d.refresh_token,
|
|
1734
1739
|
idToken: d.id_token
|
|
1735
1740
|
});
|
|
1736
|
-
this.setAuthTokens(l, p, u ?? d.refresh_token);
|
|
1741
|
+
this.setAuthTokens(l, p, u ?? d.refresh_token), this.handleClose();
|
|
1737
1742
|
} else
|
|
1738
1743
|
throw new Error("Missing required OAuth parameters");
|
|
1739
1744
|
} catch (h) {
|
|
@@ -1789,25 +1794,28 @@ let m = class extends H {
|
|
|
1789
1794
|
}
|
|
1790
1795
|
async logout() {
|
|
1791
1796
|
const e = this.cookies.getAuthToken("ACCESS_TOKEN"), t = this.cookies.getAuthToken("AUTH_TOKEN"), s = this.cookies.getAuthToken("REFRESH_TOKEN");
|
|
1792
|
-
|
|
1797
|
+
try {
|
|
1798
|
+
if (e == null || s == null || t == null)
|
|
1799
|
+
return;
|
|
1800
|
+
if (!this.hasApiBaseUrl()) {
|
|
1801
|
+
this.error = this.baseUrlErrorMessage;
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
const i = this.getApiService(), {
|
|
1805
|
+
redirectUrl: r,
|
|
1806
|
+
requiresRedirect: o
|
|
1807
|
+
} = await i.logout({
|
|
1808
|
+
accessToken: e,
|
|
1809
|
+
refreshToken: s,
|
|
1810
|
+
authToken: t
|
|
1811
|
+
});
|
|
1812
|
+
if (o && r) {
|
|
1813
|
+
const a = window.location.host;
|
|
1814
|
+
new URL(r).host !== a ? window.open(r, "newWindow", "width=400,height=500,resizable=yes,scrollbars=yes,status=yes") : window.location.href = r;
|
|
1815
|
+
}
|
|
1816
|
+
} catch {
|
|
1817
|
+
} finally {
|
|
1793
1818
|
this.cookies.clearAllAuthTokens(), this.isLoggedIn = !1;
|
|
1794
|
-
return;
|
|
1795
|
-
}
|
|
1796
|
-
if (!this.hasApiBaseUrl()) {
|
|
1797
|
-
this.error = this.baseUrlErrorMessage;
|
|
1798
|
-
return;
|
|
1799
|
-
}
|
|
1800
|
-
const i = this.getApiService(), {
|
|
1801
|
-
redirectUrl: r,
|
|
1802
|
-
requiresRedirect: o
|
|
1803
|
-
} = await i.logout({
|
|
1804
|
-
accessToken: e,
|
|
1805
|
-
refreshToken: s,
|
|
1806
|
-
authToken: t
|
|
1807
|
-
});
|
|
1808
|
-
if (this.cookies.clearAllAuthTokens(), this.isLoggedIn = !1, o && r) {
|
|
1809
|
-
const a = window.location.host;
|
|
1810
|
-
new URL(r).host !== a ? window.open(r, "newWindow", "width=400,height=400,resizable=yes,scrollbars=yes,status=yes") : window.location.href = r;
|
|
1811
1819
|
}
|
|
1812
1820
|
}
|
|
1813
1821
|
// OAuth handlers
|
|
@@ -1819,7 +1827,7 @@ let m = class extends H {
|
|
|
1819
1827
|
}
|
|
1820
1828
|
handleOAuthSignIn(e) {
|
|
1821
1829
|
if (this.oauthSpaDomain?.trim()) {
|
|
1822
|
-
const t = this.oauthSpaDomain.trim(), s = t.startsWith("http://") || t.startsWith("https://") ? t : `https://${t}`, i = s.endsWith("/") ? s.slice(0, -1) : s, r = window.location.href, o = `${i}?return_url=${encodeURIComponent(r)}&provider=${e}`;
|
|
1830
|
+
const t = this.oauthSpaDomain.trim(), s = t.startsWith("http://") || t.startsWith("https://") ? t : `https://${t}`, i = s.endsWith("/") ? s.slice(0, -1) : s, r = window.location.href, o = `${i}?return_url=${encodeURIComponent(r)}&provider=${e}&theme=${this.theme}`;
|
|
1823
1831
|
window.location.href = o;
|
|
1824
1832
|
return;
|
|
1825
1833
|
}
|
package/dist/index.js
CHANGED
|
@@ -1663,7 +1663,12 @@ let A = class extends ee {
|
|
|
1663
1663
|
}
|
|
1664
1664
|
}
|
|
1665
1665
|
setAuthTokens(t, e, s) {
|
|
1666
|
-
this.cookies.setAuthToken("ACCESS_TOKEN", t), this.cookies.setAuthToken("AUTH_TOKEN", e), this.cookies.setAuthToken("REFRESH_TOKEN", s), this.isLoggedIn = !0
|
|
1666
|
+
this.cookies.setAuthToken("ACCESS_TOKEN", t), this.cookies.setAuthToken("AUTH_TOKEN", e), this.cookies.setAuthToken("REFRESH_TOKEN", s), this.isLoggedIn = !0, this.dispatchEvent(
|
|
1667
|
+
new CustomEvent("auth-success", {
|
|
1668
|
+
bubbles: !0,
|
|
1669
|
+
composed: !0
|
|
1670
|
+
})
|
|
1671
|
+
);
|
|
1667
1672
|
}
|
|
1668
1673
|
async handleSignIn() {
|
|
1669
1674
|
const t = {
|
|
@@ -1709,7 +1714,7 @@ let A = class extends ee {
|
|
|
1709
1714
|
this.error = this.baseUrlErrorMessage;
|
|
1710
1715
|
return;
|
|
1711
1716
|
}
|
|
1712
|
-
this.hasHandledOAuthCallback = !0, this.isLoading = !0, this.error = "";
|
|
1717
|
+
this.open = !0, this.isVisible = !0, this.hasHandledOAuthCallback = !0, this.isLoading = !0, this.error = "";
|
|
1713
1718
|
try {
|
|
1714
1719
|
if (n)
|
|
1715
1720
|
throw new Error(a || `OAuth error: ${n}`);
|
|
@@ -1719,7 +1724,7 @@ let A = class extends ee {
|
|
|
1719
1724
|
refreshToken: r,
|
|
1720
1725
|
idToken: s
|
|
1721
1726
|
});
|
|
1722
|
-
this.setAuthTokens(h, c, u ?? r);
|
|
1727
|
+
this.setAuthTokens(h, c, u ?? r), this.handleClose();
|
|
1723
1728
|
} else if (i && o) {
|
|
1724
1729
|
if (!this.isOAuthConfigured())
|
|
1725
1730
|
throw new Error("OAuth is not configured correctly. Please try again later.");
|
|
@@ -1733,7 +1738,7 @@ let A = class extends ee {
|
|
|
1733
1738
|
refreshToken: c.refresh_token,
|
|
1734
1739
|
idToken: c.id_token
|
|
1735
1740
|
});
|
|
1736
|
-
this.setAuthTokens(u, f, y ?? c.refresh_token);
|
|
1741
|
+
this.setAuthTokens(u, f, y ?? c.refresh_token), this.handleClose();
|
|
1737
1742
|
} else
|
|
1738
1743
|
throw new Error("Missing required OAuth parameters");
|
|
1739
1744
|
} catch (h) {
|
|
@@ -1789,25 +1794,28 @@ let A = class extends ee {
|
|
|
1789
1794
|
}
|
|
1790
1795
|
async logout() {
|
|
1791
1796
|
const t = this.cookies.getAuthToken("ACCESS_TOKEN"), e = this.cookies.getAuthToken("AUTH_TOKEN"), s = this.cookies.getAuthToken("REFRESH_TOKEN");
|
|
1792
|
-
|
|
1797
|
+
try {
|
|
1798
|
+
if (t == null || s == null || e == null)
|
|
1799
|
+
return;
|
|
1800
|
+
if (!this.hasApiBaseUrl()) {
|
|
1801
|
+
this.error = this.baseUrlErrorMessage;
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
const r = this.getApiService(), {
|
|
1805
|
+
redirectUrl: i,
|
|
1806
|
+
requiresRedirect: o
|
|
1807
|
+
} = await r.logout({
|
|
1808
|
+
accessToken: t,
|
|
1809
|
+
refreshToken: s,
|
|
1810
|
+
authToken: e
|
|
1811
|
+
});
|
|
1812
|
+
if (o && i) {
|
|
1813
|
+
const n = window.location.host;
|
|
1814
|
+
new URL(i).host !== n ? window.open(i, "newWindow", "width=400,height=500,resizable=yes,scrollbars=yes,status=yes") : window.location.href = i;
|
|
1815
|
+
}
|
|
1816
|
+
} catch {
|
|
1817
|
+
} finally {
|
|
1793
1818
|
this.cookies.clearAllAuthTokens(), this.isLoggedIn = !1;
|
|
1794
|
-
return;
|
|
1795
|
-
}
|
|
1796
|
-
if (!this.hasApiBaseUrl()) {
|
|
1797
|
-
this.error = this.baseUrlErrorMessage;
|
|
1798
|
-
return;
|
|
1799
|
-
}
|
|
1800
|
-
const r = this.getApiService(), {
|
|
1801
|
-
redirectUrl: i,
|
|
1802
|
-
requiresRedirect: o
|
|
1803
|
-
} = await r.logout({
|
|
1804
|
-
accessToken: t,
|
|
1805
|
-
refreshToken: s,
|
|
1806
|
-
authToken: e
|
|
1807
|
-
});
|
|
1808
|
-
if (this.cookies.clearAllAuthTokens(), this.isLoggedIn = !1, o && i) {
|
|
1809
|
-
const n = window.location.host;
|
|
1810
|
-
new URL(i).host !== n ? window.open(i, "newWindow", "width=400,height=400,resizable=yes,scrollbars=yes,status=yes") : window.location.href = i;
|
|
1811
1819
|
}
|
|
1812
1820
|
}
|
|
1813
1821
|
// OAuth handlers
|
|
@@ -1819,7 +1827,7 @@ let A = class extends ee {
|
|
|
1819
1827
|
}
|
|
1820
1828
|
handleOAuthSignIn(t) {
|
|
1821
1829
|
if (this.oauthSpaDomain?.trim()) {
|
|
1822
|
-
const e = this.oauthSpaDomain.trim(), s = e.startsWith("http://") || e.startsWith("https://") ? e : `https://${e}`, r = s.endsWith("/") ? s.slice(0, -1) : s, i = window.location.href, o = `${r}?return_url=${encodeURIComponent(i)}&provider=${t}`;
|
|
1830
|
+
const e = this.oauthSpaDomain.trim(), s = e.startsWith("http://") || e.startsWith("https://") ? e : `https://${e}`, r = s.endsWith("/") ? s.slice(0, -1) : s, i = window.location.href, o = `${r}?return_url=${encodeURIComponent(i)}&provider=${t}&theme=${this.theme}`;
|
|
1823
1831
|
window.location.href = o;
|
|
1824
1832
|
return;
|
|
1825
1833
|
}
|