Skip to content

SK-2528: update jwt-decode library for Node SDK#282

Open
skyflow-himanshu wants to merge 1 commit intomainfrom
himanshu/SK-2528-update-libraries-for-node-sdk
Open

SK-2528: update jwt-decode library for Node SDK#282
skyflow-himanshu wants to merge 1 commit intomainfrom
himanshu/SK-2528-update-libraries-for-node-sdk

Conversation

@skyflow-himanshu
Copy link
Contributor

Why:
Update libraries for Node SDK

Goal:
Upgrade jwt-decode to v4.0.0.
Attempt upgrade of @types/node to v25.2.0 and node-fetch to v3.3.0 and identify compatibility issues with generated files. so we are keeping the versions unchanged for now.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the Node SDK’s JWT decoding dependency to jwt-decode@4 and updates internal/test imports accordingly.

Changes:

  • Bumped jwt-decode from ^2.2.0 to ^4.0.0
  • Switched code and tests from default import (jwt_decode) to named import (jwtDecode)
  • Updated jwt utility implementation to use the new import

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.

File Description
test/vault/utils/utils.test.js Updates test imports and mocks to align with jwtDecode named export.
test/vault/utils/jwt-utils/jwt.test.js Updates jwt-utils tests to use jwtDecode named export and related mocks.
src/utils/jwt-utils/index.ts Updates implementation to call jwtDecode instead of default import.
package.json Bumps jwt-decode dependency to ^4.0.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"js-base64": "3.7.7",
"jsonwebtoken": "^9.0.3",
"jwt-decode": "^2.2.0",
"jwt-decode": "^4.0.0",
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jwt-decode@4 is ESM-only. If this Node SDK is published/compiled to CommonJS (common for TS SDKs without \"type\": \"module\"), consumers will hit runtime errors when requiring the SDK (e.g., ERR_REQUIRE_ESM). If the SDK isn't ESM end-to-end, consider keeping jwt-decode on a CJS-compatible major (or switching the SDK build/publish output to ESM) before merging this dependency bump.

Suggested change
"jwt-decode": "^4.0.0",
"jwt-decode": "^3.1.2",

Copilot uses AI. Check for mistakes.
import { jwtDecode } from 'jwt-decode';
import { isTokenValid, isExpired } from '../../../../src/utils/jwt-utils';

jest.mock('jwt-decode');
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.

Suggested change
jest.mock('jwt-decode');
jest.mock('jwt-decode', () => ({
__esModule: true,
jwtDecode: jest.fn(),
}));

Copilot uses AI. Check for mistakes.

beforeEach(() => {
jwt_decode.mockReturnValue(mockDecodedPayload);
jwtDecode.mockReturnValue(mockDecodedPayload);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.

Copilot uses AI. Check for mistakes.

test('should return false in catch', () => {
jwt_decode.mockImplementation(() => {
jwtDecode.mockImplementation(() => {
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.

Copilot uses AI. Check for mistakes.

test('should return false in catch for isExpired', () => {
jwt_decode.mockImplementation(() => {
jwtDecode.mockImplementation(() => {
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.

Copilot uses AI. Check for mistakes.
}
let isJwtExpired = false;
const decoded: JwtPayload = jwt_decode(token);
const decoded: JwtPayload = jwtDecode(token);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the generic type parameter on jwtDecode (e.g., jwtDecode<JwtPayload>(token)) instead of annotating the variable as JwtPayload. This keeps the type aligned with the function’s return type and avoids masking type incompatibilities if the library typings change.

Copilot uses AI. Check for mistakes.
if (token === "") return false
let isJwtExpired = false;
const decoded: JwtPayload = jwt_decode(token);
const decoded: JwtPayload = jwtDecode(token);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the generic type parameter on jwtDecode (e.g., jwtDecode<JwtPayload>(token)) instead of annotating the variable as JwtPayload. This keeps the type aligned with the function’s return type and avoids masking type incompatibilities if the library typings change.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants