Skip to content

Conversation

@hallvardastark
Copy link
Collaborator

@hallvardastark hallvardastark commented Oct 7, 2025

Behov / Bakgrunn

vite-plugin-node-polyfills har sårbare dependencies og er ikke oppdatert. Det ser ut til at vi bruker dette biblioteket for å støtte node-cache. node-cache brukes i en hjemmelaget cache-håndtering av etags. Denne cachingen ser heller ikke ut til å fungere som tiltenkt og er brukt få steder. Ved overgang til genererte endepunkter vil dette håndteres automatisk.

Løsning

Fjerner hjemmelaget cachehåndtering og pakkene den var avhengig av.

Andre endringer

Skjermbilder (hvis relevant)

@hallvardastark hallvardastark changed the title Bytter ut hjemmelaget håndtering av etag-caching med bibliotek Forbedre håndtering av etag-caching Oct 7, 2025
@hallvardastark hallvardastark requested a review from Copilot October 7, 2025 12:20
Copy link
Contributor

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

This PR removes the vulnerable vite-plugin-node-polyfills dependency and its requirement by replacing the node-cache dependency with a custom TypeScript-based etag cache implementation for axios HTTP requests.

  • Replaced node-cache with a native JavaScript Map-based cache implementation in axiosEtag.ts
  • Removed vite-plugin-node-polyfills from all package configurations
  • Enhanced type safety by removing the file from loosely type-checked files

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/rest-api/src/axios/axiosEtag.ts Implemented custom etag cache with TTL and size limits, replacing node-cache dependency
packages/rest-api/package.json Removed node-cache dependency
packages/*/vite.config.js Removed vite-plugin-node-polyfills from all Vite configurations
packages/*/package.json Removed vite-plugin-node-polyfills from all package dependencies
package.json Removed node-cache from root dependencies
loosely-type-checked-files.json Removed axiosEtag.ts from loosely typed files list

static get(uuid: string): CacheValue | undefined {
return this.getInstance().cache.get(uuid);
private isExpired(entry: CacheValue) {
return !!this.ttlMs && Date.now() - entry.t > this.ttlMs;
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

The double negation !!this.ttlMs is unnecessary. Since this.ttlMs is typed as number | null, you can directly check this.ttlMs !== null for better readability.

Suggested change
return !!this.ttlMs && Date.now() - entry.t > this.ttlMs;
return this.ttlMs !== null && Date.now() - entry.t > this.ttlMs;

Copilot uses AI. Check for mistakes.
Comment on lines 67 to 70
if (this.maxEntries && this.cache.size > this.maxEntries) {
// Simple FIFO eviction; can be upgraded to true LRU if necessary
const firstKey = this.cache.keys().next().value;
if (firstKey) this.cache.delete(firstKey);
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

The eviction logic only removes one entry when the cache exceeds maxEntries, but should remove entries until the cache size is within the limit. The condition should be >= instead of >, and it should loop until cache.size < maxEntries.

Suggested change
if (this.maxEntries && this.cache.size > this.maxEntries) {
// Simple FIFO eviction; can be upgraded to true LRU if necessary
const firstKey = this.cache.keys().next().value;
if (firstKey) this.cache.delete(firstKey);
if (this.maxEntries) {
// Simple FIFO eviction; can be upgraded to true LRU if necessary
while (this.cache.size > this.maxEntries) {
const firstKey = this.cache.keys().next().value;
if (firstKey) this.cache.delete(firstKey);
}

Copilot uses AI. Check for mistakes.
@hallvardastark hallvardastark changed the title Forbedre håndtering av etag-caching Fjerner håndtering av etag-caching som ikke fungerer Oct 8, 2025
@hallvardastark hallvardastark marked this pull request as ready for review October 8, 2025 11:14
@hallvardastark hallvardastark requested a review from a team as a code owner October 8, 2025 11:14
@hallvardastark hallvardastark enabled auto-merge (squash) October 27, 2025 13:36
@hallvardastark hallvardastark merged commit 5456ba6 into master Oct 27, 2025
6 checks passed
@hallvardastark hallvardastark deleted the feat/axios-etag branch October 27, 2025 13:44
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.

3 participants