@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 CHANGED
@@ -1778,11 +1778,11 @@ var storage = import_localforage.default.createInstance({
1778
1778
  description: "WeBlock Wallet SDK Secure Storage"
1779
1779
  });
1780
1780
  var LocalForage = {
1781
- async save(key, value, expiry) {
1781
+ async save(key, value, expiryEpochMs) {
1782
1782
  try {
1783
1783
  const item = {
1784
1784
  value,
1785
- expiry
1785
+ expiryEpochMs
1786
1786
  };
1787
1787
  await storage.setItem(key, item);
1788
1788
  } catch (err) {
@@ -1792,10 +1792,8 @@ var LocalForage = {
1792
1792
  async get(key) {
1793
1793
  try {
1794
1794
  const item = await storage.getItem(key);
1795
- if (!item) {
1796
- return null;
1797
- }
1798
- if (item.expiry && Date.now() > item.expiry * 1e3) {
1795
+ if (!item) return null;
1796
+ if (item.expiryEpochMs && Date.now() > item.expiryEpochMs) {
1799
1797
  await storage.removeItem(key);
1800
1798
  return null;
1801
1799
  }
@@ -104917,10 +104915,26 @@ var HttpClient = class {
104917
104915
  if (!accessToken) {
104918
104916
  throw new SDKError("No access token found", "AUTH_REQUIRED" /* AUTH_REQUIRED */);
104919
104917
  }
104918
+ ;
104920
104919
  headers["Authorization"] = `Bearer ${accessToken}`;
104921
104920
  }
104922
104921
  return headers;
104923
104922
  }
104923
+ async safeReadErrorDetails(response) {
104924
+ const contentType = response.headers.get("content-type") || "";
104925
+ try {
104926
+ if (contentType.includes("application/json")) {
104927
+ return await response.json();
104928
+ }
104929
+ } catch {
104930
+ }
104931
+ try {
104932
+ const text = await response.text();
104933
+ return text || void 0;
104934
+ } catch {
104935
+ return void 0;
104936
+ }
104937
+ }
104924
104938
  async request(method, path, data, config2 = {}) {
104925
104939
  const headers = await this.getHeaders(config2.needsAccessToken);
104926
104940
  const requestInit = {
@@ -104931,20 +104945,28 @@ var HttpClient = class {
104931
104945
  },
104932
104946
  credentials: config2.credentials
104933
104947
  };
104934
- if (data) {
104948
+ if (data !== void 0) {
104935
104949
  requestInit.body = JSON.stringify(data);
104936
104950
  }
104937
104951
  const response = await fetch(`${this.baseUrl}${path}`, requestInit);
104938
104952
  if (!response.ok) {
104953
+ if (config2.needsAccessToken && (response.status === 401 || response.status === 403)) {
104954
+ await LocalForage.delete(`${this.orgHost}:accessToken`);
104955
+ throw new SDKError(
104956
+ `Authentication required (status: ${response.status})`,
104957
+ "AUTH_REQUIRED" /* AUTH_REQUIRED */,
104958
+ await this.safeReadErrorDetails(response)
104959
+ );
104960
+ }
104939
104961
  throw new SDKError(
104940
104962
  `HTTP error! status: ${response.status}`,
104941
104963
  "REQUEST_FAILED" /* REQUEST_FAILED */,
104942
- await response.json()
104964
+ await this.safeReadErrorDetails(response)
104943
104965
  );
104944
104966
  }
104945
- if (response.status === 200 && response.headers.get("content-length") === "0") {
104946
- return void 0;
104947
- }
104967
+ if (response.status === 204) return void 0;
104968
+ const contentLength = response.headers.get("content-length");
104969
+ if (contentLength === "0") return void 0;
104948
104970
  try {
104949
104971
  return await response.json();
104950
104972
  } catch {