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);