@oxyhq/core 1.11.6 → 1.11.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/core",
3
- "version": "1.11.6",
3
+ "version": "1.11.7",
4
4
  "description": "OxyHQ SDK Foundation — API client, authentication, cryptographic identity, and shared utilities",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -11,6 +11,7 @@ import type { OxyServices } from './OxyServices';
11
11
  import type { HttpService } from './HttpService';
12
12
  import type { SessionLoginResponse, MinimalUserData } from './models/session';
13
13
  import { retryAsync } from './utils/asyncUtils';
14
+ import { jwtDecode } from 'jwt-decode';
14
15
 
15
16
  /**
16
17
  * OxyServices already declares revokeFedCMCredential via mixin type augmentation.
@@ -429,10 +430,29 @@ export class AuthManager {
429
430
  }
430
431
 
431
432
  /**
432
- * Get stored access token.
433
+ * Get a valid access token, refreshing automatically if expired or expiring soon.
433
434
  */
434
435
  async getAccessToken(): Promise<string | null> {
435
- return this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
436
+ const token = await this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
437
+ if (!token) return null;
438
+
439
+ try {
440
+ const decoded = jwtDecode<{ exp?: number }>(token);
441
+ if (decoded.exp) {
442
+ const now = Math.floor(Date.now() / 1000);
443
+ const buffer = 60; // refresh 60 seconds before expiry
444
+ if (decoded.exp - now < buffer) {
445
+ const refreshed = await this.refreshToken();
446
+ if (refreshed) {
447
+ return this.storage.getItem(STORAGE_KEYS.ACCESS_TOKEN);
448
+ }
449
+ }
450
+ }
451
+ } catch {
452
+ // Decode failed — return token as-is, let the server decide
453
+ }
454
+
455
+ return token;
436
456
  }
437
457
 
438
458
  /**