diff --git a/packages/forestadmin-client/package.json b/packages/forestadmin-client/package.json index 107560488a..8d3e9c9477 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": "^9.1.1", "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..817cfdeadb 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,10 +66,10 @@ 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), - ]); + ])) as [RenderingPermission, UserPermissionV4]; const collectionPermissions = permissions?.collections?.[collectionName]; @@ -125,9 +125,9 @@ export default class RenderingPermissionService { segmentQuery: string; allowRetry: boolean; }): Promise { - const permissions: RenderingPermission = await this.permissionsByRendering.fetch( + const permissions = (await this.permissionsByRendering.fetch( `${renderingId}`, - ); + )) as RenderingPermission; const collectionPermissions = permissions?.collections?.[collectionName]; @@ -210,10 +210,10 @@ export default class RenderingPermissionService { chartHash: string; allowRetry: boolean; }): Promise { - const [userInfo, permissions] = await Promise.all([ + const [userInfo, permissions] = (await Promise.all([ this.userPermissions.getUserInfo(userId), this.permissionsByRendering.fetch(`${renderingId}`), - ]); + ])) as [UserPermissionV4, RenderingPermission]; if ( [PermissionLevel.Admin, PermissionLevel.Developer, PermissionLevel.Editor].includes( @@ -266,9 +266,9 @@ export default class RenderingPermissionService { } public async getTeam(renderingId: number | string): Promise { - const permissions: RenderingPermission = await this.permissionsByRendering.fetch( + const permissions = (await this.permissionsByRendering.fetch( `${renderingId}`, - ); + )) as RenderingPermission; return permissions.team; } diff --git a/yarn.lock b/yarn.lock index 35c044fc7c..23af10ca65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3562,13 +3562,6 @@ dependencies: "@types/koa" "*" -"@types/lru-cache@^7.10.10": - version "7.10.10" - resolved "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-7.10.10.tgz" - integrity sha512-nEpVRPWW9EBmx2SCfNn3ClYxPL7IktPX12HhIoSc/H5mMjdeW3+YsXIpseLQ2xF35+OcpwKQbEUw5VtqE4PDNA== - dependencies: - lru-cache "*" - "@types/luxon@^3.2.0": version "3.2.0" resolved "https://registry.npmjs.org/@types/luxon/-/luxon-3.2.0.tgz" @@ -8585,11 +8578,6 @@ longest-streak@^2.0.0: resolved "https://registry.npmjs.org/longest-streak/-/longest-streak-2.0.4.tgz" integrity sha512-vM6rUVCVUJJt33bnmHiZEvr7wPT78ztX7rojL+LW51bHtLh6HTjx84LA5W4+oa6aKEJA7jJu5LR6vQRBpA5DVg== -lru-cache@*, lru-cache@^7.14.0, lru-cache@^7.14.1, lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1: - version "7.14.1" - resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz" - integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA== - lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz" @@ -8604,6 +8592,16 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +lru-cache@^7.14.0, lru-cache@^7.14.1, lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1: + version "7.14.1" + resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz" + integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA== + +lru-cache@^9.1.1: + version "9.1.1" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-9.1.1.tgz#c58a93de58630b688de39ad04ef02ef26f1902f1" + integrity sha512-65/Jky17UwSb0BuB9V+MyDpsOtXKmYwzhyl+cOa9XUiI4uV2Ouy/2voFP3+al0BjZbJgMBD8FojMpAf+Z+qn4A== + lunr@^2.3.9: version "2.3.9" resolved "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz"