@weblock-wallet/sdk 0.1.67 → 0.1.68
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 +33 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1733,11 +1733,11 @@ var storage = localforage.createInstance({
|
|
|
1733
1733
|
description: "WeBlock Wallet SDK Secure Storage"
|
|
1734
1734
|
});
|
|
1735
1735
|
var LocalForage = {
|
|
1736
|
-
async save(key, value,
|
|
1736
|
+
async save(key, value, expiryEpochMs) {
|
|
1737
1737
|
try {
|
|
1738
1738
|
const item = {
|
|
1739
1739
|
value,
|
|
1740
|
-
|
|
1740
|
+
expiryEpochMs
|
|
1741
1741
|
};
|
|
1742
1742
|
await storage.setItem(key, item);
|
|
1743
1743
|
} catch (err) {
|
|
@@ -1747,10 +1747,8 @@ var LocalForage = {
|
|
|
1747
1747
|
async get(key) {
|
|
1748
1748
|
try {
|
|
1749
1749
|
const item = await storage.getItem(key);
|
|
1750
|
-
if (!item)
|
|
1751
|
-
|
|
1752
|
-
}
|
|
1753
|
-
if (item.expiry && Date.now() > item.expiry * 1e3) {
|
|
1750
|
+
if (!item) return null;
|
|
1751
|
+
if (item.expiryEpochMs && Date.now() > item.expiryEpochMs) {
|
|
1754
1752
|
await storage.removeItem(key);
|
|
1755
1753
|
return null;
|
|
1756
1754
|
}
|
|
@@ -104872,10 +104870,26 @@ var HttpClient = class {
|
|
|
104872
104870
|
if (!accessToken) {
|
|
104873
104871
|
throw new SDKError("No access token found", "AUTH_REQUIRED" /* AUTH_REQUIRED */);
|
|
104874
104872
|
}
|
|
104873
|
+
;
|
|
104875
104874
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
104876
104875
|
}
|
|
104877
104876
|
return headers;
|
|
104878
104877
|
}
|
|
104878
|
+
async safeReadErrorDetails(response) {
|
|
104879
|
+
const contentType = response.headers.get("content-type") || "";
|
|
104880
|
+
try {
|
|
104881
|
+
if (contentType.includes("application/json")) {
|
|
104882
|
+
return await response.json();
|
|
104883
|
+
}
|
|
104884
|
+
} catch {
|
|
104885
|
+
}
|
|
104886
|
+
try {
|
|
104887
|
+
const text = await response.text();
|
|
104888
|
+
return text || void 0;
|
|
104889
|
+
} catch {
|
|
104890
|
+
return void 0;
|
|
104891
|
+
}
|
|
104892
|
+
}
|
|
104879
104893
|
async request(method, path, data, config2 = {}) {
|
|
104880
104894
|
const headers = await this.getHeaders(config2.needsAccessToken);
|
|
104881
104895
|
const requestInit = {
|
|
@@ -104886,20 +104900,28 @@ var HttpClient = class {
|
|
|
104886
104900
|
},
|
|
104887
104901
|
credentials: config2.credentials
|
|
104888
104902
|
};
|
|
104889
|
-
if (data) {
|
|
104903
|
+
if (data !== void 0) {
|
|
104890
104904
|
requestInit.body = JSON.stringify(data);
|
|
104891
104905
|
}
|
|
104892
104906
|
const response = await fetch(`${this.baseUrl}${path}`, requestInit);
|
|
104893
104907
|
if (!response.ok) {
|
|
104908
|
+
if (config2.needsAccessToken && (response.status === 401 || response.status === 403)) {
|
|
104909
|
+
await LocalForage.delete(`${this.orgHost}:accessToken`);
|
|
104910
|
+
throw new SDKError(
|
|
104911
|
+
`Authentication required (status: ${response.status})`,
|
|
104912
|
+
"AUTH_REQUIRED" /* AUTH_REQUIRED */,
|
|
104913
|
+
await this.safeReadErrorDetails(response)
|
|
104914
|
+
);
|
|
104915
|
+
}
|
|
104894
104916
|
throw new SDKError(
|
|
104895
104917
|
`HTTP error! status: ${response.status}`,
|
|
104896
104918
|
"REQUEST_FAILED" /* REQUEST_FAILED */,
|
|
104897
|
-
await
|
|
104919
|
+
await this.safeReadErrorDetails(response)
|
|
104898
104920
|
);
|
|
104899
104921
|
}
|
|
104900
|
-
if (response.status ===
|
|
104901
|
-
|
|
104902
|
-
|
|
104922
|
+
if (response.status === 204) return void 0;
|
|
104923
|
+
const contentLength = response.headers.get("content-length");
|
|
104924
|
+
if (contentLength === "0") return void 0;
|
|
104903
104925
|
try {
|
|
104904
104926
|
return await response.json();
|
|
104905
104927
|
} catch {
|