@baclet/sdk 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -419,9 +419,19 @@ export class BacletClient {
419
419
  accessToken,
420
420
  }).then((result) => result.user);
421
421
  }
422
- storageRequest(path, options = {}) {
423
- const accessToken = options.accessToken ?? this.readTokens()?.access_token;
424
- return this.request(path, { ...options, accessToken });
422
+ async storageRequest(path, options = {}) {
423
+ const tokens = this.readTokens();
424
+ const accessToken = options.accessToken ?? tokens?.access_token;
425
+ try {
426
+ return await this.request(path, { ...options, accessToken });
427
+ }
428
+ catch (error) {
429
+ if (!hasStatus(error, 401) || options.accessToken || !this.autoRefresh || !tokens?.refresh_token) {
430
+ throw error;
431
+ }
432
+ const session = await this.refreshSession(tokens.refresh_token);
433
+ return this.request(path, { ...options, accessToken: session.tokens.access_token });
434
+ }
425
435
  }
426
436
  async request(path, options = {}) {
427
437
  const headers = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baclet/sdk",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "BACLET users database SDK for browsers and servers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",