arky-sdk 0.3.2 → 0.3.4
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/index.cjs +10 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -28
- package/dist/index.d.ts +26 -28
- package/dist/index.js +10 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1629,7 +1629,7 @@ function createHttpClient(cfg) {
|
|
|
1629
1629
|
"Content-Type": "application/json",
|
|
1630
1630
|
...options?.headers || {}
|
|
1631
1631
|
};
|
|
1632
|
-
let { accessToken, refreshToken, provider, expiresAt } = await cfg.
|
|
1632
|
+
let { accessToken, refreshToken, provider, expiresAt } = await cfg.getToken();
|
|
1633
1633
|
const nowSec = Date.now() / 1e3;
|
|
1634
1634
|
if (expiresAt && nowSec > expiresAt) {
|
|
1635
1635
|
if (refreshToken) {
|
|
@@ -1640,23 +1640,17 @@ function createHttpClient(cfg) {
|
|
|
1640
1640
|
});
|
|
1641
1641
|
if (refRes.ok) {
|
|
1642
1642
|
const data2 = await refRes.json();
|
|
1643
|
-
cfg.
|
|
1643
|
+
cfg.setToken(data2);
|
|
1644
1644
|
accessToken = data2.accessToken;
|
|
1645
1645
|
} else {
|
|
1646
|
-
cfg.
|
|
1647
|
-
if (cfg.loginFallbackPath) {
|
|
1648
|
-
cfg.navigate?.(cfg.loginFallbackPath);
|
|
1649
|
-
}
|
|
1646
|
+
cfg.logout();
|
|
1650
1647
|
const err = new Error("Error refreshing token");
|
|
1651
1648
|
err.name = "ApiError";
|
|
1652
1649
|
err.statusCode = 401;
|
|
1653
1650
|
throw err;
|
|
1654
1651
|
}
|
|
1655
1652
|
} else {
|
|
1656
|
-
cfg.
|
|
1657
|
-
if (cfg.loginFallbackPath) {
|
|
1658
|
-
cfg.navigate?.(cfg.loginFallbackPath);
|
|
1659
|
-
}
|
|
1653
|
+
cfg.logout();
|
|
1660
1654
|
const err = new Error("No refresh token");
|
|
1661
1655
|
err.name = "ApiError";
|
|
1662
1656
|
err.statusCode = 401;
|
|
@@ -1709,7 +1703,7 @@ function createHttpClient(cfg) {
|
|
|
1709
1703
|
}
|
|
1710
1704
|
|
|
1711
1705
|
// src/index.ts
|
|
1712
|
-
var SDK_VERSION = "0.3.
|
|
1706
|
+
var SDK_VERSION = "0.3.4";
|
|
1713
1707
|
var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
|
|
1714
1708
|
function createArkySDK(config) {
|
|
1715
1709
|
const httpClient = createHttpClient(config);
|
|
@@ -1720,8 +1714,8 @@ function createArkySDK(config) {
|
|
|
1720
1714
|
storageUrl,
|
|
1721
1715
|
baseUrl: config.baseUrl,
|
|
1722
1716
|
market: config.market || "US",
|
|
1723
|
-
setTokens: config.
|
|
1724
|
-
getTokens: config.
|
|
1717
|
+
setTokens: config.setToken,
|
|
1718
|
+
getTokens: config.getToken
|
|
1725
1719
|
};
|
|
1726
1720
|
const userApi = createUserApi(apiConfig);
|
|
1727
1721
|
const autoGuest = config.autoGuest !== void 0 ? config.autoGuest : true;
|
|
@@ -1743,9 +1737,8 @@ function createArkySDK(config) {
|
|
|
1743
1737
|
},
|
|
1744
1738
|
getBusinessId: () => apiConfig.businessId,
|
|
1745
1739
|
isAuthenticated: config.isAuthenticated || (() => false),
|
|
1746
|
-
logout: config.logout
|
|
1747
|
-
|
|
1748
|
-
}),
|
|
1740
|
+
logout: config.logout,
|
|
1741
|
+
setToken: config.setToken,
|
|
1749
1742
|
utils: {
|
|
1750
1743
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
|
|
1751
1744
|
thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
|
|
@@ -1764,7 +1757,7 @@ function createArkySDK(config) {
|
|
|
1764
1757
|
if (autoGuest) {
|
|
1765
1758
|
Promise.resolve().then(async () => {
|
|
1766
1759
|
try {
|
|
1767
|
-
const tokens = await config.
|
|
1760
|
+
const tokens = await config.getToken();
|
|
1768
1761
|
if (!tokens.accessToken && !tokens.refreshToken) {
|
|
1769
1762
|
const guestToken = await userApi.getGuestToken({});
|
|
1770
1763
|
console.log("[SDK Init] Created guest token:", guestToken ? "Success" : "Failed");
|