tsvesync 1.3.1 → 1.3.3

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.
@@ -10,8 +10,13 @@ function decodeJwtTimestamps(token) {
10
10
  if (parts.length !== 3)
11
11
  return null;
12
12
  const payload = JSON.parse(Buffer.from(parts[1].replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'));
13
- const iat = typeof payload.iat === 'number' ? payload.iat : undefined;
14
- const exp = typeof payload.exp === 'number' ? payload.exp : undefined;
13
+ let iat = typeof payload.iat === 'number' ? payload.iat : undefined;
14
+ let exp = typeof payload.exp === 'number' ? payload.exp : undefined;
15
+ // Normalize to seconds if values are in milliseconds
16
+ if (iat && iat > 1e11)
17
+ iat = Math.floor(iat / 1000);
18
+ if (exp && exp > 1e11)
19
+ exp = Math.floor(exp / 1000);
15
20
  return { iat, exp };
16
21
  }
17
22
  catch (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "A TypeScript library for interacting with VeSync smart home devices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,11 +25,13 @@ export function decodeJwtTimestamps(token: string): { iat?: number; exp?: number
25
25
  const parts = token.split('.');
26
26
  if (parts.length !== 3) return null;
27
27
  const payload = JSON.parse(Buffer.from(parts[1].replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'));
28
- const iat = typeof payload.iat === 'number' ? payload.iat : undefined;
29
- const exp = typeof payload.exp === 'number' ? payload.exp : undefined;
28
+ let iat = typeof payload.iat === 'number' ? payload.iat : undefined;
29
+ let exp = typeof payload.exp === 'number' ? payload.exp : undefined;
30
+ // Normalize to seconds if values are in milliseconds
31
+ if (iat && iat > 1e11) iat = Math.floor(iat / 1000);
32
+ if (exp && exp > 1e11) exp = Math.floor(exp / 1000);
30
33
  return { iat, exp };
31
34
  } catch {
32
35
  return null;
33
36
  }
34
37
  }
35
-