From 8fc92793ffc23b7c1e68fc6fe2b870d7c23a12ea Mon Sep 17 00:00:00 2001 From: Rafael Tapia Date: Wed, 10 Jan 2024 09:26:48 -0300 Subject: [PATCH 1/3] chore: use apps-engine with deno --- apps/meteor/package.json | 2 +- yarn.lock | 52 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/apps/meteor/package.json b/apps/meteor/package.json index 2db612565917..1d0831c12932 100644 --- a/apps/meteor/package.json +++ b/apps/meteor/package.json @@ -224,7 +224,7 @@ "@rocket.chat/account-utils": "workspace:^", "@rocket.chat/agenda": "workspace:^", "@rocket.chat/api-client": "workspace:^", - "@rocket.chat/apps-engine": "1.41.0", + "@rocket.chat/apps-engine": "deno", "@rocket.chat/base64": "workspace:^", "@rocket.chat/cas-validate": "workspace:^", "@rocket.chat/core-services": "workspace:^", diff --git a/yarn.lock b/yarn.lock index b3d14ad61044..bcfafc262ecd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8680,6 +8680,26 @@ __metadata: languageName: node linkType: hard +"@rocket.chat/apps-engine@npm:deno": + version: 1.42.0-deno.485 + resolution: "@rocket.chat/apps-engine@npm:1.42.0-deno.485" + dependencies: + adm-zip: ^0.5.9 + cryptiles: ^4.1.3 + deno-bin: 1.37.1 + jose: ^4.11.1 + jsonrpc-lite: ^2.2.0 + lodash.clonedeep: ^4.5.0 + semver: ^5.7.1 + stack-trace: 0.0.10 + uuid: ~8.3.2 + vm2: ^3.9.19 + peerDependencies: + "@rocket.chat/ui-kit": "*" + checksum: 90cdc4cd45ef0a56c12987f49df0379c79d453de3bd67f6788860bcaa24fb7e714ce95ed098a45fdf6ede6d96b05bda275cb79357f0350d9142030c2ed835d80 + languageName: node + linkType: hard + "@rocket.chat/authorization-service@workspace:ee/apps/authorization-service": version: 0.0.0-use.local resolution: "@rocket.chat/authorization-service@workspace:ee/apps/authorization-service" @@ -9450,7 +9470,7 @@ __metadata: "@rocket.chat/account-utils": "workspace:^" "@rocket.chat/agenda": "workspace:^" "@rocket.chat/api-client": "workspace:^" - "@rocket.chat/apps-engine": 1.41.0 + "@rocket.chat/apps-engine": deno "@rocket.chat/base64": "workspace:^" "@rocket.chat/cas-validate": "workspace:^" "@rocket.chat/core-services": "workspace:^" @@ -20322,6 +20342,19 @@ __metadata: languageName: node linkType: hard +"deno-bin@npm:1.37.1": + version: 1.37.1 + resolution: "deno-bin@npm:1.37.1" + dependencies: + adm-zip: ^0.5.4 + follow-redirects: ^1.10.0 + bin: + deno: bin/deno.js + deno-bin: bin/deno.js + checksum: 1c985611aa67b4b72f68b5608644af73dbff75619ac4fba67fecf036763acf76c66a9bb537cf09865c855313ceec6af1190474fa0163a616620b8af705c82736 + languageName: node + linkType: hard + "depd@npm:2.0.0, depd@npm:~2.0.0": version: 2.0.0 resolution: "depd@npm:2.0.0" @@ -23103,6 +23136,16 @@ __metadata: languageName: node linkType: hard +"follow-redirects@npm:^1.10.0": + version: 1.15.4 + resolution: "follow-redirects@npm:1.15.4" + peerDependenciesMeta: + debug: + optional: true + checksum: e178d1deff8b23d5d24ec3f7a94cde6e47d74d0dc649c35fc9857041267c12ec5d44650a0c5597ef83056ada9ea6ca0c30e7c4f97dbf07d035086be9e6a5b7b6 + languageName: node + linkType: hard + "fontkit@npm:^2.0.2": version: 2.0.2 resolution: "fontkit@npm:2.0.2" @@ -27913,6 +27956,13 @@ __metadata: languageName: node linkType: hard +"jsonrpc-lite@npm:^2.2.0": + version: 2.2.0 + resolution: "jsonrpc-lite@npm:2.2.0" + checksum: 3062101d3c93401d176c1c24b90e0feebdd063546f8ed89c299531dd792c4d37c6766666d160efb83b94f17f7e2deed4346cdd9124b99581ed4620779e8733bb + languageName: node + linkType: hard + "jsonwebtoken@npm:^8.1.0, jsonwebtoken@npm:^8.5.1": version: 8.5.1 resolution: "jsonwebtoken@npm:8.5.1" From 590675101e22c06f0c2b84f576c10ca57b3dd6c4 Mon Sep 17 00:00:00 2001 From: Rafael Tapia Date: Wed, 10 Jan 2024 09:26:57 -0300 Subject: [PATCH 2/3] fix: async operations --- apps/meteor/ee/lib/misc/formatAppInstanceForRest.ts | 4 ++-- .../apps/communication/endpoints/appsCountHandler.ts | 4 ++-- apps/meteor/ee/server/apps/communication/rest.ts | 10 +++++----- apps/meteor/ee/server/apps/cron.ts | 2 +- apps/meteor/server/services/apps-engine/service.ts | 4 +--- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/meteor/ee/lib/misc/formatAppInstanceForRest.ts b/apps/meteor/ee/lib/misc/formatAppInstanceForRest.ts index d76b7ae59aeb..bf096122c50f 100644 --- a/apps/meteor/ee/lib/misc/formatAppInstanceForRest.ts +++ b/apps/meteor/ee/lib/misc/formatAppInstanceForRest.ts @@ -14,10 +14,10 @@ interface IAppInfoRest extends IAppInfo { migrated: boolean; } -export function formatAppInstanceForRest(app: ProxiedApp): IAppInfoRest { +export async function formatAppInstanceForRest(app: ProxiedApp): Promise { const appRest: IAppInfoRest = { ...app.getInfo(), - status: app.getStatus(), + status: await app.getStatus(), languages: app.getStorageItem().languageContent, private: getInstallationSourceFromAppStorageItem(app.getStorageItem()) === 'private', migrated: !!app.getStorageItem().migrated, diff --git a/apps/meteor/ee/server/apps/communication/endpoints/appsCountHandler.ts b/apps/meteor/ee/server/apps/communication/endpoints/appsCountHandler.ts index fc436b8229cf..878dd9aab92c 100644 --- a/apps/meteor/ee/server/apps/communication/endpoints/appsCountHandler.ts +++ b/apps/meteor/ee/server/apps/communication/endpoints/appsCountHandler.ts @@ -19,10 +19,10 @@ export const appsCountHandler = (apiManager: AppsRestApi) => authRequired: false, }, { - get(): SuccessResult { + async get(): Promise> { const manager = apiManager._manager as AppManager; - const apps = manager.get({ enabled: true }); + const apps = await manager.get({ enabled: true }); const { maxMarketplaceApps, maxPrivateApps } = License.getAppsConfig(); return API.v1.success({ diff --git a/apps/meteor/ee/server/apps/communication/rest.ts b/apps/meteor/ee/server/apps/communication/rest.ts index cf7a56e1ebc0..7c79c7096bb3 100644 --- a/apps/meteor/ee/server/apps/communication/rest.ts +++ b/apps/meteor/ee/server/apps/communication/rest.ts @@ -209,7 +209,7 @@ export class AppsRestApi { { authRequired: true }, { async get() { - const apps = manager.get().map(formatAppInstanceForRest); + const apps = (await manager.get()).map(formatAppInstanceForRest); return API.v1.success({ apps }); }, }, @@ -302,7 +302,7 @@ export class AppsRestApi { } apiDeprecationLogger.endpoint(this.request.route, '7.0.0', this.response, 'Use /apps/installed to get the installed apps list.'); - const apps = manager.get().map(formatAppInstanceForRest); + const apps = (await manager.get()).map(formatAppInstanceForRest); return API.v1.success({ apps }); }, @@ -506,8 +506,8 @@ export class AppsRestApi { 'languages', { authRequired: false }, { - get() { - const apps = manager.get().map((prl) => ({ + async get() { + const apps = (await manager.get()).map((prl) => ({ id: prl.getID(), languages: prl.getStorageItem().languageContent, })); @@ -788,7 +788,7 @@ export class AppsRestApi { await manager.remove(prl.getID(), { user }); const info: IAppInfo & { status?: AppStatus } = prl.getInfo(); - info.status = prl.getStatus(); + info.status = await prl.getStatus(); void notifyAppInstall(orchestrator.getMarketplaceUrl() as string, 'uninstall', info); diff --git a/apps/meteor/ee/server/apps/cron.ts b/apps/meteor/ee/server/apps/cron.ts index e58610d2cbf0..f904486bf610 100644 --- a/apps/meteor/ee/server/apps/cron.ts +++ b/apps/meteor/ee/server/apps/cron.ts @@ -57,7 +57,7 @@ const notifyAdminsAboutRenewedApps = async function _notifyAdminsAboutRenewedApp } const renewedApps = apps.filter( - (app) => app.getStatus() === AppStatus.DISABLED && app.getPreviousStatus() === AppStatus.INVALID_LICENSE_DISABLED, + async (app) => (await app.getStatus()) === AppStatus.DISABLED && app.getPreviousStatus() === AppStatus.INVALID_LICENSE_DISABLED, ); if (renewedApps.length === 0) { diff --git a/apps/meteor/server/services/apps-engine/service.ts b/apps/meteor/server/services/apps-engine/service.ts index 1a0a2d4a57a2..98b12ffdea9e 100644 --- a/apps/meteor/server/services/apps-engine/service.ts +++ b/apps/meteor/server/services/apps-engine/service.ts @@ -111,9 +111,7 @@ export class AppsEngineService extends ServiceClassInternal implements IAppsEngi } async getApps(query: IGetAppsFilter): Promise { - return Apps.getManager() - ?.get(query) - .map((app) => app.getApp().getInfo()); + return (await Apps.getManager()?.get(query))?.map((app) => app.getInfo()); } async getAppStorageItemById(appId: string): Promise { From e9e7eb38514bda00673c66632271f98464c305fd Mon Sep 17 00:00:00 2001 From: Rafael Tapia Date: Wed, 10 Jan 2024 10:11:27 -0300 Subject: [PATCH 3/3] fix: async --- apps/meteor/app/statistics/server/lib/getAppsStatistics.js | 4 +--- apps/meteor/ee/server/apps/orchestrator.js | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/statistics/server/lib/getAppsStatistics.js b/apps/meteor/app/statistics/server/lib/getAppsStatistics.js index 0edbb4645079..337ee622dc6d 100644 --- a/apps/meteor/app/statistics/server/lib/getAppsStatistics.js +++ b/apps/meteor/app/statistics/server/lib/getAppsStatistics.js @@ -10,8 +10,6 @@ export async function getAppsStatistics() { totalActive: Apps.isInitialized() && (await Apps.getManager().get({ enabled: true })).length, totalFailed: Apps.isInitialized() && - Apps.getManager() - .get({ disabled: true }) - .filter(({ app: { status } }) => status !== AppStatus.MANUALLY_DISABLED).length, + (await Apps.getManager().get({ disabled: true })).filter(({ app: { status } }) => status !== AppStatus.MANUALLY_DISABLED).length, }; } diff --git a/apps/meteor/ee/server/apps/orchestrator.js b/apps/meteor/ee/server/apps/orchestrator.js index 50a87d489b1a..0c128867efd9 100644 --- a/apps/meteor/ee/server/apps/orchestrator.js +++ b/apps/meteor/ee/server/apps/orchestrator.js @@ -172,8 +172,7 @@ export class AppServerOrchestrator { await this.getManager().load(); // Before enabling each app we verify if there is still room for it - await this.getManager() - .get() + (await this.getManager().get()) // We reduce everything to a promise chain so it runs sequentially .reduce( (control, app) =>