diff --git a/packages/forestadmin-client/package.json b/packages/forestadmin-client/package.json index 330793b95c..19bf22ebe8 100644 --- a/packages/forestadmin-client/package.json +++ b/packages/forestadmin-client/package.json @@ -15,7 +15,7 @@ "eventsource": "2.0.2", "json-api-serializer": "^2.6.6", "jsonwebtoken": "^9.0.0", - "lru-cache": "^7.14.1", + "lru-cache": "^10.0.0", "object-hash": "^3.0.0", "openid-client": "^5.3.1", "superagent": "^8.0.6" @@ -35,7 +35,6 @@ "@forestadmin/datasource-toolkit": "1.5.0", "@types/json-api-serializer": "^2.6.3", "@types/jsonwebtoken": "^9.0.1", - "@types/lru-cache": "^7.10.10", "@types/superagent": "^4.1.16" } } diff --git a/packages/forestadmin-client/src/permissions/rendering-permission.ts b/packages/forestadmin-client/src/permissions/rendering-permission.ts index f17d8cee1e..26961ab994 100644 --- a/packages/forestadmin-client/src/permissions/rendering-permission.ts +++ b/packages/forestadmin-client/src/permissions/rendering-permission.ts @@ -1,4 +1,4 @@ -import LruCache from 'lru-cache'; +import { LRUCache } from 'lru-cache'; import { hashChartRequest, hashServerCharts } from './hash-chart'; import isSegmentQueryAllowed from './is-segment-query-authorized'; @@ -23,17 +23,17 @@ export type RenderingPermission = { }; export default class RenderingPermissionService { - private readonly permissionsByRendering: LruCache; + private readonly permissionsByRendering: LRUCache; constructor( private readonly options: ForestAdminClientOptionsWithDefaults, private readonly userPermissions: UserPermissionService, private readonly forestAdminServerInterface: ForestAdminServerInterface, ) { - this.permissionsByRendering = new LruCache({ + this.permissionsByRendering = new LRUCache({ max: 256, ttl: this.options.permissionsCacheDurationInSeconds * 1000, - fetchMethod: renderingId => this.loadPermissions(Number(renderingId)), + fetchMethod: async renderingId => this.loadPermissions(Number(renderingId)), }); } @@ -66,7 +66,7 @@ export default class RenderingPermissionService { userId: number | string; allowRetry: boolean; }): Promise { - const [permissions, userInfo]: [RenderingPermission, UserPermissionV4] = await Promise.all([ + const [permissions, userInfo] = await Promise.all([ this.permissionsByRendering.fetch(`${renderingId}`), this.userPermissions.getUserInfo(userId), ]); @@ -125,9 +125,7 @@ export default class RenderingPermissionService { segmentQuery: string; allowRetry: boolean; }): Promise { - const permissions: RenderingPermission = await this.permissionsByRendering.fetch( - `${renderingId}`, - ); + const permissions = await this.permissionsByRendering.fetch(`${renderingId}`); const collectionPermissions = permissions?.collections?.[collectionName]; @@ -266,9 +264,7 @@ export default class RenderingPermissionService { } public async getTeam(renderingId: number | string): Promise { - const permissions: RenderingPermission = await this.permissionsByRendering.fetch( - `${renderingId}`, - ); + const permissions = await this.permissionsByRendering.fetch(`${renderingId}`); return permissions.team; } diff --git a/yarn.lock b/yarn.lock index 9c382b2dd9..4439e6bf44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3305,13 +3305,6 @@ dependencies: "@types/koa" "*" -"@types/lru-cache@^7.10.10": - version "7.10.10" - resolved "https://registry.yarnpkg.com/@types/lru-cache/-/lru-cache-7.10.10.tgz#3fa937c35ff4b3f6753d5737915c9bf8e693a713" - integrity sha512-nEpVRPWW9EBmx2SCfNn3ClYxPL7IktPX12HhIoSc/H5mMjdeW3+YsXIpseLQ2xF35+OcpwKQbEUw5VtqE4PDNA== - dependencies: - lru-cache "*" - "@types/luxon@^3.2.0": version "3.3.0" resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.3.0.tgz#a61043a62c0a72696c73a0a305c544c96501e006" @@ -8675,10 +8668,10 @@ longest-streak@^2.0.0: resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-2.0.4.tgz#b8599957da5b5dab64dee3fe316fa774597d90e4" integrity sha512-vM6rUVCVUJJt33bnmHiZEvr7wPT78ztX7rojL+LW51bHtLh6HTjx84LA5W4+oa6aKEJA7jJu5LR6vQRBpA5DVg== -lru-cache@*, lru-cache@^9.1.1: - version "9.1.2" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-9.1.2.tgz#255fdbc14b75589d6d0e73644ca167a8db506835" - integrity sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ== +lru-cache@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.0.0.tgz#b9e2a6a72a129d81ab317202d93c7691df727e61" + integrity sha512-svTf/fzsKHffP42sujkO/Rjs37BCIsQVRCeNYIm9WN8rgT7ffoUnRtZCqU+6BqcSBdv8gwJeTz8knJpgACeQMw== lru-cache@^5.1.1: version "5.1.1" @@ -8704,6 +8697,11 @@ lru-cache@^8.0.0: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-8.0.5.tgz#983fe337f3e176667f8e567cfcce7cb064ea214e" integrity sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA== +lru-cache@^9.1.1: + version "9.1.2" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-9.1.2.tgz#255fdbc14b75589d6d0e73644ca167a8db506835" + integrity sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ== + lunr@^2.3.9: version "2.3.9" resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1"