From fd4b08dfba548fff185ddd1b6a6d995ca4d96b13 Mon Sep 17 00:00:00 2001 From: skyflow-himanshu Date: Fri, 6 Feb 2026 13:07:57 +0530 Subject: [PATCH 1/3] SK-2528: update jwt-decode library for Node SDK --- package-lock.json | 26 +++++++++++++------------- package.json | 2 +- src/utils/jwt-utils/index.ts | 6 +++--- test/vault/utils/jwt-utils/jwt.test.js | 8 ++++---- test/vault/utils/utils.test.js | 10 +++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 104f270a..e5119427 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "skyflow-node", - "version": "2.0.2", + "version": "2.0.2-dev.2a81ccd", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "skyflow-node", - "version": "2.0.2", + "version": "2.0.2-dev.2a81ccd", "license": "MIT", "dependencies": { "@babel/runtime": "^7.27.1", @@ -16,7 +16,7 @@ "formdata-node": "^6.0.3", "js-base64": "3.7.7", "jsonwebtoken": "^9.0.3", - "jwt-decode": "^2.2.0", + "jwt-decode": "^4.0.0", "node-fetch": "^2.7.0", "qs": "^6.14.1", "readable-stream": "^4.5.2", @@ -3061,11 +3061,10 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "18.19.100", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.100.tgz", - "integrity": "sha512-ojmMP8SZBKprc3qGrGk8Ujpo80AXkrP7G2tOT4VWr5jlr5DHjsJF+emXJz+Wm0glmy4Js62oKMdZZ6B9Y+tEcA==", + "version": "18.19.130", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.130.tgz", + "integrity": "sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==", "dev": true, - "license": "MIT", "dependencies": { "undici-types": "~5.26.4" } @@ -6448,10 +6447,12 @@ } }, "node_modules/jwt-decode": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", - "integrity": "sha512-86GgN2vzfUu7m9Wcj63iUkuDzFNYFVmjeDm2GzWpUk+opB0pEpMsw6ePCMrhYkumz2C1ihqtZzOMAg7FiXcNoQ==", - "license": "MIT" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", + "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", + "engines": { + "node": ">=18" + } }, "node_modules/kleur": { "version": "3.0.3", @@ -8081,8 +8082,7 @@ "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true, - "license": "MIT" + "dev": true }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.1", diff --git a/package.json b/package.json index ba2b35e2..1605567b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "formdata-node": "^6.0.3", "js-base64": "3.7.7", "jsonwebtoken": "^9.0.3", - "jwt-decode": "^2.2.0", + "jwt-decode": "^4.0.0", "node-fetch": "^2.7.0", "qs": "^6.14.1", "readable-stream": "^4.5.2", diff --git a/src/utils/jwt-utils/index.ts b/src/utils/jwt-utils/index.ts index 489f812c..2ffa2aa3 100644 --- a/src/utils/jwt-utils/index.ts +++ b/src/utils/jwt-utils/index.ts @@ -1,4 +1,4 @@ -import jwt_decode, { JwtPayload } from 'jwt-decode'; +import { JwtPayload, jwtDecode } from 'jwt-decode'; import { MessageType, printLog } from '..'; import logs from '../logs'; @@ -9,7 +9,7 @@ function isExpired(token: string) { return true; } let isJwtExpired = false; - const decoded: JwtPayload = jwt_decode(token); + const decoded: JwtPayload = jwtDecode(token); const currentTime = (new Date().getTime() / 1000); const expiryTime = decoded.exp; if (expiryTime && currentTime > expiryTime) { @@ -26,7 +26,7 @@ function isTokenValid(token: string) { try { if (token === "") return false let isJwtExpired = false; - const decoded: JwtPayload = jwt_decode(token); + const decoded: JwtPayload = jwtDecode(token); const currentTime = (new Date().getTime() / 1000); const expiryTime = decoded.exp; if (expiryTime && currentTime > expiryTime) { diff --git a/test/vault/utils/jwt-utils/jwt.test.js b/test/vault/utils/jwt-utils/jwt.test.js index 14c397b8..de756ebc 100644 --- a/test/vault/utils/jwt-utils/jwt.test.js +++ b/test/vault/utils/jwt-utils/jwt.test.js @@ -1,4 +1,4 @@ -import jwt_decode from 'jwt-decode'; +import { jwtDecode } from 'jwt-decode'; import { isTokenValid, isExpired } from '../../../../src/utils/jwt-utils'; jest.mock('jwt-decode'); @@ -7,7 +7,7 @@ describe('isTokenValid Tests', () => { const mockDecodedPayload = { sub: '12345', name: 'John Doe', exp: 1609459200 }; beforeEach(() => { - jwt_decode.mockReturnValue(mockDecodedPayload); + jwtDecode.mockReturnValue(mockDecodedPayload); }); test('should return false for an invalid token', () => { @@ -21,7 +21,7 @@ describe('isTokenValid Tests', () => { }); test('should return false in catch', () => { - jwt_decode.mockImplementation(() => { + jwtDecode.mockImplementation(() => { throw new Error("Invalid Token"); }); const isValid = isTokenValid("TOKEN"); @@ -29,7 +29,7 @@ describe('isTokenValid Tests', () => { }); test('should return false in catch for isExpired', () => { - jwt_decode.mockImplementation(() => { + jwtDecode.mockImplementation(() => { throw new Error("Invalid Token"); }); const isValid = isExpired("TOKEN"); diff --git a/test/vault/utils/utils.test.js b/test/vault/utils/utils.test.js index ffea9c3d..f16817c8 100644 --- a/test/vault/utils/utils.test.js +++ b/test/vault/utils/utils.test.js @@ -1,6 +1,6 @@ import errorMessages from "../../../src/error/messages"; import { Env, getConnectionBaseURL, getVaultURL, validateToken, isValidURL, fillUrlWithPathAndQueryParams, generateSDKMetrics, printLog, getToken, getBearerToken, MessageType, LogLevel } from "../../../src/utils"; -import jwt_decode from 'jwt-decode'; +import { jwtDecode } from 'jwt-decode'; import os from 'os'; import { generateBearerTokenFromCreds, generateBearerToken } from '../../../src/service-account'; import sdkDetails from '../../../package.json'; @@ -69,7 +69,7 @@ describe('Validate Token Helper', () => { beforeEach(() => { jest.clearAllMocks(); - jwt_decode.mockReturnValue(mockPrevDecodedPayload); + jwtDecode.mockReturnValue(mockPrevDecodedPayload); }); test('should throw an error for invalid token', () => { @@ -78,13 +78,13 @@ describe('Validate Token Helper', () => { }); test('should throw an error for invalid token', () => { - jwt_decode.mockReturnValue(mockFutureDecodedPayload); + jwtDecode.mockReturnValue(mockFutureDecodedPayload); expect(validateToken("connectionId")) .toBeTruthy(); }); test('should throw an error for invalid token', () => { - jwt_decode.mockReturnValue(mockDecodedPayload); + jwtDecode.mockReturnValue(mockDecodedPayload); expect(validateToken("connectionId")) .toBeTruthy(); }); @@ -493,7 +493,7 @@ describe('getBearerToken', () => { const credentials = { token: 'validToken' }; - jwt_decode.mockReturnValue({ exp: Date.now() / 1000 + 3600 }); // Valid for 1 hour + jwtDecode.mockReturnValue({ exp: Date.now() / 1000 + 3600 }); // Valid for 1 hour const result = await getBearerToken(credentials, logLevel); From e1b78bed883cc7d4e07ad50f3288d7aeb579be5c Mon Sep 17 00:00:00 2001 From: skyflow-himanshu Date: Mon, 9 Feb 2026 13:48:12 +0530 Subject: [PATCH 2/3] SK-2528: update jwt-decode library to v3.1.2 as v4.0.0 is ESM only --- package-lock.json | 11 ++++------- package.json | 2 +- src/utils/jwt-utils/index.ts | 6 +++--- test/vault/utils/jwt-utils/jwt.test.js | 8 ++++---- test/vault/utils/utils.test.js | 10 +++++----- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index e5119427..64d619e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "formdata-node": "^6.0.3", "js-base64": "3.7.7", "jsonwebtoken": "^9.0.3", - "jwt-decode": "^4.0.0", + "jwt-decode": "^3.1.2", "node-fetch": "^2.7.0", "qs": "^6.14.1", "readable-stream": "^4.5.2", @@ -6447,12 +6447,9 @@ } }, "node_modules/jwt-decode": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", - "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", - "engines": { - "node": ">=18" - } + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" }, "node_modules/kleur": { "version": "3.0.3", diff --git a/package.json b/package.json index 1605567b..c4a03296 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "formdata-node": "^6.0.3", "js-base64": "3.7.7", "jsonwebtoken": "^9.0.3", - "jwt-decode": "^4.0.0", + "jwt-decode": "^3.1.2", "node-fetch": "^2.7.0", "qs": "^6.14.1", "readable-stream": "^4.5.2", diff --git a/src/utils/jwt-utils/index.ts b/src/utils/jwt-utils/index.ts index 2ffa2aa3..45757ff7 100644 --- a/src/utils/jwt-utils/index.ts +++ b/src/utils/jwt-utils/index.ts @@ -1,4 +1,4 @@ -import { JwtPayload, jwtDecode } from 'jwt-decode'; +import jwt_decode from 'jwt-decode'; import { MessageType, printLog } from '..'; import logs from '../logs'; @@ -9,7 +9,7 @@ function isExpired(token: string) { return true; } let isJwtExpired = false; - const decoded: JwtPayload = jwtDecode(token); + const decoded: any = jwt_decode(token); const currentTime = (new Date().getTime() / 1000); const expiryTime = decoded.exp; if (expiryTime && currentTime > expiryTime) { @@ -26,7 +26,7 @@ function isTokenValid(token: string) { try { if (token === "") return false let isJwtExpired = false; - const decoded: JwtPayload = jwtDecode(token); + const decoded: any = jwt_decode(token); const currentTime = (new Date().getTime() / 1000); const expiryTime = decoded.exp; if (expiryTime && currentTime > expiryTime) { diff --git a/test/vault/utils/jwt-utils/jwt.test.js b/test/vault/utils/jwt-utils/jwt.test.js index de756ebc..14c397b8 100644 --- a/test/vault/utils/jwt-utils/jwt.test.js +++ b/test/vault/utils/jwt-utils/jwt.test.js @@ -1,4 +1,4 @@ -import { jwtDecode } from 'jwt-decode'; +import jwt_decode from 'jwt-decode'; import { isTokenValid, isExpired } from '../../../../src/utils/jwt-utils'; jest.mock('jwt-decode'); @@ -7,7 +7,7 @@ describe('isTokenValid Tests', () => { const mockDecodedPayload = { sub: '12345', name: 'John Doe', exp: 1609459200 }; beforeEach(() => { - jwtDecode.mockReturnValue(mockDecodedPayload); + jwt_decode.mockReturnValue(mockDecodedPayload); }); test('should return false for an invalid token', () => { @@ -21,7 +21,7 @@ describe('isTokenValid Tests', () => { }); test('should return false in catch', () => { - jwtDecode.mockImplementation(() => { + jwt_decode.mockImplementation(() => { throw new Error("Invalid Token"); }); const isValid = isTokenValid("TOKEN"); @@ -29,7 +29,7 @@ describe('isTokenValid Tests', () => { }); test('should return false in catch for isExpired', () => { - jwtDecode.mockImplementation(() => { + jwt_decode.mockImplementation(() => { throw new Error("Invalid Token"); }); const isValid = isExpired("TOKEN"); diff --git a/test/vault/utils/utils.test.js b/test/vault/utils/utils.test.js index f16817c8..ffea9c3d 100644 --- a/test/vault/utils/utils.test.js +++ b/test/vault/utils/utils.test.js @@ -1,6 +1,6 @@ import errorMessages from "../../../src/error/messages"; import { Env, getConnectionBaseURL, getVaultURL, validateToken, isValidURL, fillUrlWithPathAndQueryParams, generateSDKMetrics, printLog, getToken, getBearerToken, MessageType, LogLevel } from "../../../src/utils"; -import { jwtDecode } from 'jwt-decode'; +import jwt_decode from 'jwt-decode'; import os from 'os'; import { generateBearerTokenFromCreds, generateBearerToken } from '../../../src/service-account'; import sdkDetails from '../../../package.json'; @@ -69,7 +69,7 @@ describe('Validate Token Helper', () => { beforeEach(() => { jest.clearAllMocks(); - jwtDecode.mockReturnValue(mockPrevDecodedPayload); + jwt_decode.mockReturnValue(mockPrevDecodedPayload); }); test('should throw an error for invalid token', () => { @@ -78,13 +78,13 @@ describe('Validate Token Helper', () => { }); test('should throw an error for invalid token', () => { - jwtDecode.mockReturnValue(mockFutureDecodedPayload); + jwt_decode.mockReturnValue(mockFutureDecodedPayload); expect(validateToken("connectionId")) .toBeTruthy(); }); test('should throw an error for invalid token', () => { - jwtDecode.mockReturnValue(mockDecodedPayload); + jwt_decode.mockReturnValue(mockDecodedPayload); expect(validateToken("connectionId")) .toBeTruthy(); }); @@ -493,7 +493,7 @@ describe('getBearerToken', () => { const credentials = { token: 'validToken' }; - jwtDecode.mockReturnValue({ exp: Date.now() / 1000 + 3600 }); // Valid for 1 hour + jwt_decode.mockReturnValue({ exp: Date.now() / 1000 + 3600 }); // Valid for 1 hour const result = await getBearerToken(credentials, logLevel); From ee58b89c9913cd2c6d2ed09b0d94f4b95afae5fb Mon Sep 17 00:00:00 2001 From: skyflow-himanshu Date: Mon, 9 Feb 2026 14:00:36 +0530 Subject: [PATCH 3/3] SK-2528: added jwt_decode type --- src/utils/jwt-utils/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/jwt-utils/index.ts b/src/utils/jwt-utils/index.ts index 45757ff7..489f812c 100644 --- a/src/utils/jwt-utils/index.ts +++ b/src/utils/jwt-utils/index.ts @@ -1,4 +1,4 @@ -import jwt_decode from 'jwt-decode'; +import jwt_decode, { JwtPayload } from 'jwt-decode'; import { MessageType, printLog } from '..'; import logs from '../logs'; @@ -9,7 +9,7 @@ function isExpired(token: string) { return true; } let isJwtExpired = false; - const decoded: any = jwt_decode(token); + const decoded: JwtPayload = jwt_decode(token); const currentTime = (new Date().getTime() / 1000); const expiryTime = decoded.exp; if (expiryTime && currentTime > expiryTime) { @@ -26,7 +26,7 @@ function isTokenValid(token: string) { try { if (token === "") return false let isJwtExpired = false; - const decoded: any = jwt_decode(token); + const decoded: JwtPayload = jwt_decode(token); const currentTime = (new Date().getTime() / 1000); const expiryTime = decoded.exp; if (expiryTime && currentTime > expiryTime) {