Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
3bf93e2
Move apps/server to services
d-gubert Jul 21, 2022
64e0dbc
WIP
d-gubert Aug 16, 2022
d63f8ab
Make apps-engine's orchestrator work as a service
thassiov Oct 6, 2022
025892f
refactor: use triggerEvent method
Oct 13, 2022
854fbec
fix: remove Apps export
Oct 13, 2022
8cdb978
refactor: extract app statistics to service
Oct 13, 2022
90e8128
AE-4 feat: adapt management to use service
Oct 18, 2022
cc93ca7
AE-4 feat: move communication folder
Oct 18, 2022
9793f48
AE-4 refactor: remove unnecessary commentaries
Oct 19, 2022
1cf213d
AE-5 feat: add apps video manager service
Oct 20, 2022
9b21d6e
AE-5 refactor: use new service methods
Oct 20, 2022
aa2f88d
AE-5 feat: check if apps-engine is loaded
Oct 20, 2022
23cccd2
Merge pull request #27113 from RocketChat/refactor/AE-5_change-orch-u…
thassiov Oct 21, 2022
369707b
Merge pull request #27095 from RocketChat/refactor/change-apps-to-ser…
thassiov Oct 21, 2022
9d5c250
AE-67 refactor: replace Meteor random for uuid v4
Nov 9, 2022
9222699
AE-67 refactor: throw MeteorError instead of an error from meteor lib
Nov 9, 2022
90ec8e9
AE-67 feat: add new services
Nov 25, 2022
bec5641
AE-67 refactor: use service to avoid Meteor dependency
Nov 25, 2022
98e7341
AE-67 refactor: remove Meteor dependency
Nov 25, 2022
089e1ea
AE-67 fix: pass all params to triggerEvent
Nov 25, 2022
932447c
AE-67 refactor: use service to remove Meteor dependency
Nov 25, 2022
7ae0912
AE-67 refactor: pass db via constructor to avoid Meteor
Nov 25, 2022
5077c25
Merge branch 'develop' into improve/apps-to-service
thassiov Nov 29, 2022
b8c2e43
Add new models and interfaces
thassiov Nov 29, 2022
052378c
Remove references to old apps models
thassiov Nov 29, 2022
fd73e58
Merge branch 'improve/apps-to-service' into improve/remove-meteor-app…
Nov 29, 2022
e017b62
Merge pull request #27380 from RocketChat/improve/remove-meteor-apps-…
thassiov Nov 29, 2022
b9111c3
refactor: remove unnecessary commentary
Nov 29, 2022
a15a3a8
Define methods used by apps engine and its types
thassiov Nov 30, 2022
c08d57e
Merge branch 'improve/apps-to-service' into chore/apps-raw-models
thassiov Dec 2, 2022
7619990
Remove remainder 'Promise.await' instances
thassiov Dec 2, 2022
43b1c42
Update yarn.lock
thassiov Dec 2, 2022
28880dc
Adjust method calls to models
thassiov Dec 2, 2022
a636453
Merge pull request #27401 from RocketChat/chore/apps-raw-models
thassiov Dec 5, 2022
4306795
Add new service for the app listener bridge
thassiov Dec 19, 2022
49d6fd0
Fix faulty index creation for apps_logs col
thassiov Dec 30, 2022
a88bde2
Include method from Subscriptions model
thassiov Jan 2, 2023
ad38db7
Fix typo
thassiov Jan 2, 2023
610e421
Move apps engine to ee
thassiov Jan 2, 2023
25954c0
Updating file references
thassiov Jan 2, 2023
ddc08dd
refactor: update import to ee
Jan 6, 2023
8b29965
change function to handle promises
Jan 10, 2023
f532f1e
Partial commit of converter changes
thassiov Jan 10, 2023
f262697
Updates calls to async functions
thassiov Jan 12, 2023
93cf7fb
Fixes the issue with triggerEvent sending a list instead of object
thassiov Jan 19, 2023
28b143b
Removes meteor code from uikit comm module
thassiov Jan 24, 2023
1bf2924
Merge pull request #27718 from RocketChat/fix/asyncawaitify-app-conve…
thassiov Jan 26, 2023
f176db3
Removing Meteor refs from ee directory
thassiov Feb 1, 2023
8128bd5
[FIX] Use fibers on async calls (#27967)
thassiov Feb 8, 2023
8778156
[NEW] Add internal federation bridge (#27615)
Feb 10, 2023
c1114b1
Remove the listener service
thassiov Feb 10, 2023
1cad2c4
Merge pull request #27990 from RocketChat/chore/remove-async-from-lis…
Feb 10, 2023
27bb6ff
[FIX] Use apps.engine service (#27419)
Feb 10, 2023
73a0cb1
[FIX] Remove meteor dependencies from apps-engine (#27930)
Feb 13, 2023
6270877
[IMPROVE] Remove settings from apps-engine service (#27996)
Feb 13, 2023
c27deef
Merge remote-tracking branch 'origin/improve/apps-to-service' into ch…
d-gubert Feb 13, 2023
b3d989d
Make communicators start outside ee
thassiov Feb 13, 2023
f51041c
Merge branch 'chore/move-apps-to-ee' into chore/remove-communicator-r…
thassiov Feb 14, 2023
49f745b
Merge branch 'chore/move-apps-to-ee' into chore/services-to-meteor-calls
thassiov Feb 14, 2023
3c9214d
Merge pull request #28026 from RocketChat/chore/remove-communicator-r…
Feb 14, 2023
0dc2253
feat: unify startup in a single file
Feb 11, 2023
8a4cc83
Move meteor dependent methods to their services
thassiov Feb 14, 2023
a759158
Merge pull request #27920 from RocketChat/chore/services-to-meteor-calls
Feb 14, 2023
0b39212
Merge pull request #27678 from RocketChat/chore/move-apps-to-ee
Feb 14, 2023
df8e26c
Merge branch 'develop' into improve/apps-to-service
Feb 11, 2023
c45bc04
refactor: change imports to core-services
Feb 15, 2023
54dc4c3
fix: communication startup import
Feb 15, 2023
5426136
Merge branch 'develop' into improve/apps-to-service
Feb 15, 2023
43e709b
feat: extract closeRoom to livechat service
Feb 15, 2023
8a622bb
fix: move import from sdk to core-services package
Feb 15, 2023
3294fe3
fix: change params of MessageService
Feb 15, 2023
85f4cd9
Merge branch 'develop' into improve/apps-to-service
thassiov Mar 9, 2023
c7a3399
Merge branch 'develop' into improve/apps-to-service
thassiov Mar 13, 2023
62df8c7
Merge branch 'develop' into improve/apps-to-service
thassiov Mar 13, 2023
8b24d6a
Merge remote-tracking branch 'origin/develop' into improve/apps-to-se…
Apr 14, 2023
d9e9b7a
fix: remove duplicated code
Apr 14, 2023
829f744
Merge branch 'develop' into improve/apps-to-service
Apr 14, 2023
cdf8f8e
fix: remove old merge symbols
Apr 14, 2023
4f25b36
fix: solve typing issues and use orchestrator as service
Apr 17, 2023
aada98b
fix: remove old settings
Apr 17, 2023
8fb3449
Update apps-engine in all packages
d-gubert Apr 17, 2023
40e1ac8
remove enabled prop from getAppsStatistics
Apr 17, 2023
33fbe0b
fix: update apps.engine services
Apr 17, 2023
ded466a
Move orchestrator back
d-gubert Apr 17, 2023
fd12db6
fix imports
Apr 17, 2023
1910bdc
fix startup files
Apr 18, 2023
2f2481e
fix cron file
Apr 19, 2023
6cf5bdf
fix imports and orchestrator usage
Apr 19, 2023
e5f968c
use orchestrator as service
Apr 19, 2023
5edda46
fix AppsEngineService
Apr 19, 2023
54da4e4
Merge branch 'develop' into improve/apps-to-service
Apr 20, 2023
d3ddacc
fix: load apps engine if isn't loaded
Apr 20, 2023
34392a7
fix: export communication startup
Apr 20, 2023
efd4a38
fix models import
Apr 20, 2023
c38ede5
Merge branch 'develop' into improve/apps-to-service
Apr 20, 2023
edb0847
Merge remote-tracking branch 'origin/develop' into improve/apps-to-se…
Apr 24, 2023
d04ee9f
yarn.lock
Apr 25, 2023
c513521
await to initialize settings
Apr 25, 2023
584a727
remove fetch service
Apr 25, 2023
5ef53b5
yarn lock
Apr 25, 2023
ffc4ca7
move bridges and converters back to outside ee
Apr 25, 2023
d300c7e
change update params
Apr 29, 2023
1d4fc4c
await for promises
Apr 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/meteor/app/apps/server/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import express from 'express';
import { WebApp } from 'meteor/webapp';
import { AppsApiService } from '@rocket.chat/core-services';

import { authenticationMiddleware } from '../../../api/server/middlewares/authentication';

const apiServer = express();

apiServer.disable('x-powered-by');

WebApp.connectHandlers.use(apiServer);

class AppsApiRoutes {
constructor() {
const rejectUnauthorized = false;
apiServer.use('/api/apps/private/:appId/:hash', authenticationMiddleware({ rejectUnauthorized }), AppsApiService.handlePrivateRequest);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [authorization](1), but is not rate-limited. This route handler performs [authorization](2), but is not rate-limited.
apiServer.use('/api/apps/public/:appId', authenticationMiddleware({ rejectUnauthorized }), AppsApiService.handlePublicRequest);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [authorization](1), but is not rate-limited. This route handler performs [authorization](2), but is not rate-limited.
}
}

export const AppsApiRoutesInstance = new AppsApiRoutes();
11 changes: 6 additions & 5 deletions apps/meteor/app/apps/server/bridges/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus';
import { Users } from '@rocket.chat/models';

import type { AppServerOrchestrator } from '../../../../ee/server/apps/orchestrator';
import { AppEvents } from '../../../../ee/server/apps/communication';

export class AppActivationBridge extends ActivationBridge {
// eslint-disable-next-line no-empty-function
Expand All @@ -12,26 +13,26 @@ export class AppActivationBridge extends ActivationBridge {
}

protected async appAdded(app: ProxiedApp): Promise<void> {
await this.orch.getNotifier().appAdded(app.getID());
this.orch.notifyAppEvent(AppEvents.APP_ADDED, app.getID());
}

protected async appUpdated(app: ProxiedApp): Promise<void> {
await this.orch.getNotifier().appUpdated(app.getID());
this.orch.notifyAppEvent(AppEvents.APP_UPDATED, app.getID());
}

protected async appRemoved(app: ProxiedApp): Promise<void> {
await this.orch.getNotifier().appRemoved(app.getID());
this.orch.notifyAppEvent(AppEvents.APP_REMOVED, app.getID());
}

protected async appStatusChanged(app: ProxiedApp, status: AppStatus): Promise<void> {
const userStatus = ['auto_enabled', 'manually_enabled'].includes(status) ? 'online' : 'offline';

await Users.updateStatusByAppId(app.getID(), userStatus);

await this.orch.getNotifier().appStatusUpdated(app.getID(), status);
this.orch.notifyAppEvent(AppEvents.APP_STATUS_CHANGE, app.getID(), status);
}

protected async actionsChanged(): Promise<void> {
await this.orch.getNotifier().actionsChanged();
this.orch.notifyAppEvent(AppEvents.APP_STATUS_CHANGE);
}
}
109 changes: 7 additions & 102 deletions apps/meteor/app/apps/server/bridges/api.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,27 @@
import { Meteor } from 'meteor/meteor';
import type { Response, Request, IRouter, RequestHandler } from 'express';
import express from 'express';
import { WebApp } from 'meteor/webapp';
import { ApiBridge } from '@rocket.chat/apps-engine/server/bridges/ApiBridge';
import type { IApiRequest, IApiEndpoint, IApi } from '@rocket.chat/apps-engine/definition/api';
import type { IApi, IApiEndpoint } from '@rocket.chat/apps-engine/definition/api';
import { ApiBridge } from '@rocket.chat/apps-engine/server/bridges';
import type { AppApi } from '@rocket.chat/apps-engine/server/managers/AppApi';
import type { RequestMethod } from '@rocket.chat/apps-engine/definition/accessors';
import { AppsApiService } from '@rocket.chat/core-services';

import type { AppServerOrchestrator } from '../../../../ee/server/apps/orchestrator';
import { authenticationMiddleware } from '../../../api/server/middlewares/authentication';

const apiServer = express();

apiServer.disable('x-powered-by');

WebApp.connectHandlers.use(apiServer);

interface IRequestWithPrivateHash extends Request {
_privateHash?: string;
content?: any;
}

export class AppApisBridge extends ApiBridge {
appRouters: Map<string, IRouter>;

// eslint-disable-next-line no-empty-function
constructor(private readonly orch: AppServerOrchestrator) {
super();
this.appRouters = new Map();

apiServer.use('/api/apps/private/:appId/:hash', (req: IRequestWithPrivateHash, res: Response) => {
const notFound = (): Response => res.sendStatus(404);

const router = this.appRouters.get(req.params.appId);

if (router) {
req._privateHash = req.params.hash;
return router(req, res, notFound);
}

notFound();
});

apiServer.use('/api/apps/public/:appId', (req: Request, res: Response) => {
const notFound = (): Response => res.sendStatus(404);

const router = this.appRouters.get(req.params.appId);

if (router) {
return router(req, res, notFound);
}

notFound();
});
}

public async registerApi({ api, computedPath, endpoint }: AppApi, appId: string): Promise<void> {
protected async registerApi({ api, computedPath, endpoint }: AppApi, appId: string): Promise<void> {
this.orch.debugLog(`The App ${appId} is registering the api: "${endpoint.path}" (${computedPath})`);

this._verifyApi(api, endpoint);

let router = this.appRouters.get(appId);

if (!router) {
router = express.Router(); // eslint-disable-line new-cap
this.appRouters.set(appId, router);
}

const method = 'all';

let routePath = endpoint.path.trim();
if (!routePath.startsWith('/')) {
routePath = `/${routePath}`;
}

if (router[method] instanceof Function) {
router[method](
routePath,
authenticationMiddleware({ rejectUnauthorized: !!endpoint.authRequired }),
Meteor.bindEnvironment(this._appApiExecutor(endpoint, appId)),
);
}
await AppsApiService.registerApi(endpoint, appId);
}

public async unregisterApis(appId: string): Promise<void> {
protected async unregisterApis(appId: string): Promise<void> {
this.orch.debugLog(`The App ${appId} is unregistering all apis`);

if (this.appRouters.get(appId)) {
this.appRouters.delete(appId);
}
await AppsApiService.unregisterApi(appId);
}

private _verifyApi(api: IApi, endpoint: IApiEndpoint): void {
Expand All @@ -100,32 +33,4 @@ export class AppApisBridge extends ApiBridge {
throw new Error('Invalid Api parameter provided, it must be a valid IApi object.');
}
}

private _appApiExecutor(endpoint: IApiEndpoint, appId: string): RequestHandler {
return (req: IRequestWithPrivateHash, res: Response): void => {
const request: IApiRequest = {
method: req.method.toLowerCase() as RequestMethod,
headers: req.headers as { [key: string]: string },
query: (req.query as { [key: string]: string }) || {},
params: req.params || {},
content: req.body,
privateHash: req._privateHash,
user: req.user && this.orch.getConverters()?.get('users')?.convertToApp(req.user),
};

this.orch
.getManager()
?.getApiManager()
.executeApi(appId, endpoint.path, request)
.then(({ status, headers = {}, content }) => {
res.set(headers);
res.status(status);
res.send(content);
})
.catch((reason) => {
// Should we handle this as an error?
res.status(500).send(reason.message);
});
};
}
}
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/bridges/cloud.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CloudWorkspaceBridge } from '@rocket.chat/apps-engine/server/bridges/CloudWorkspaceBridge';
import type { IWorkspaceToken } from '@rocket.chat/apps-engine/definition/cloud/IWorkspaceToken';

import { getWorkspaceAccessTokenWithScope } from '../../../cloud/server';
import type { AppServerOrchestrator } from '../../../../ee/server/apps/orchestrator';
import { getWorkspaceAccessTokenWithScope } from '../../../cloud/server';

export class AppCloudBridge extends CloudWorkspaceBridge {
// eslint-disable-next-line no-empty-function
Expand Down
Loading