diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 57fe8317489a..9f7b2443454c 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -127,11 +127,11 @@ jobs: # - name: Build a Meteor cache # run: | # # to do this we can clear the main files and it build the rest - # echo "" > server/main.js - # echo "" > client/main.js + # echo "" > server/main.ts + # echo "" > client/main.ts # sed -i.backup 's/rocketchat:livechat/#rocketchat:livechat/' .meteor/packages # meteor build --server-only --debug --directory /tmp/build-temp - # git checkout -- server/main.js client/main.js .meteor/packages + # git checkout -- server/main.ts client/main.ts .meteor/packages - name: Reset Meteor if: startsWith(github.ref, 'refs/tags/') == 'true' || github.ref == 'refs/heads/develop' @@ -358,11 +358,11 @@ jobs: # - name: Build a Meteor cache # run: | # # to do this we can clear the main files and it build the rest - # echo "" > server/main.js - # echo "" > client/main.js + # echo "" > server/main.ts + # echo "" > client/main.ts # sed -i.backup 's/rocketchat:livechat/#rocketchat:livechat/' .meteor/packages # meteor build --server-only --debug --directory /tmp/build-temp - # git checkout -- server/main.js client/main.js .meteor/packages + # git checkout -- server/main.ts client/main.ts .meteor/packages - name: Build Rocket.Chat run: | diff --git a/app/api/server/v1/banners.ts b/app/api/server/v1/banners.ts index e56b6a5178cb..5dd5089814b4 100644 --- a/app/api/server/v1/banners.ts +++ b/app/api/server/v1/banners.ts @@ -1,4 +1,3 @@ -import { Promise } from 'meteor/promise'; import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; diff --git a/app/api/server/v1/teams.ts b/app/api/server/v1/teams.ts index c3235e703e35..e2a24d08413f 100644 --- a/app/api/server/v1/teams.ts +++ b/app/api/server/v1/teams.ts @@ -1,6 +1,5 @@ import { FilterQuery } from 'mongodb'; import { Meteor } from 'meteor/meteor'; -import { Promise } from 'meteor/promise'; import { Match, check } from 'meteor/check'; import { escapeRegExp } from '@rocket.chat/string-helpers'; @@ -160,6 +159,9 @@ API.v1.addRoute('teams.updateRoom', { authRequired: true }, { const { roomId, isDefault } = this.bodyParams; const team = Promise.await(Team.getOneByRoomId(roomId)); + if (!team) { + return API.v1.failure('team-does-not-exist'); + } if (!hasPermission(this.userId, 'edit-team-channel', team.roomId)) { return API.v1.unauthorized(); @@ -352,6 +354,9 @@ API.v1.addRoute('teams.leave', { authRequired: true }, { const { teamId, teamName, rooms } = this.bodyParams; const team = teamId ? Promise.await(Team.getOneById(teamId)) : Promise.await(Team.getOneByName(teamName)); + if (!team) { + return API.v1.failure('team-does-not-exist'); + } Promise.await(Team.removeMembers(this.userId, team._id, [{ userId: this.userId, diff --git a/app/apps/server/bridges/commands.ts b/app/apps/server/bridges/commands.ts index aed3d2cf72b2..fe57d2ff8bad 100644 --- a/app/apps/server/bridges/commands.ts +++ b/app/apps/server/bridges/commands.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { Promise as MeteorPromise } from 'meteor/promise'; import { SlashCommandContext, ISlashCommand, ISlashCommandPreviewItem } from '@rocket.chat/apps-engine/definition/slashcommands'; import { CommandBridge } from '@rocket.chat/apps-engine/server/bridges/CommandBridge'; @@ -167,7 +166,7 @@ export class AppCommandsBridge extends CommandBridge { triggerId, ); - MeteorPromise.await(this.orch.getManager()?.getCommandManager().executeCommand(command, context)); + Promise.await(this.orch.getManager()?.getCommandManager().executeCommand(command, context)); } private _appCommandPreviewer(command: string, parameters: any, message: IMessage): any { @@ -182,7 +181,7 @@ export class AppCommandsBridge extends CommandBridge { Object.freeze(params), threadId, ); - return MeteorPromise.await(this.orch.getManager()?.getCommandManager().getPreviews(command, context)); + return Promise.await(this.orch.getManager()?.getCommandManager().getPreviews(command, context)); } private async _appCommandPreviewExecutor(command: string, parameters: any, message: IMessage, preview: ISlashCommandPreviewItem, triggerId: string): Promise { @@ -199,6 +198,6 @@ export class AppCommandsBridge extends CommandBridge { triggerId, ); - MeteorPromise.await(this.orch.getManager()?.getCommandManager().executePreview(command, preview, context)); + Promise.await(this.orch.getManager()?.getCommandManager().executePreview(command, preview, context)); } } diff --git a/app/authorization/server/functions/canAccessRoom.ts b/app/authorization/server/functions/canAccessRoom.ts index 5a943ec031a6..d232f890af2e 100644 --- a/app/authorization/server/functions/canAccessRoom.ts +++ b/app/authorization/server/functions/canAccessRoom.ts @@ -1,5 +1,3 @@ -import { Promise } from 'meteor/promise'; - import { Authorization } from '../../../../server/sdk'; import { IAuthorization } from '../../../../server/sdk/types/IAuthorization'; diff --git a/app/lib/server/functions/closeOmnichannelConversations.ts b/app/lib/server/functions/closeOmnichannelConversations.ts index 46be29d8a984..c5cff5081f35 100644 --- a/app/lib/server/functions/closeOmnichannelConversations.ts +++ b/app/lib/server/functions/closeOmnichannelConversations.ts @@ -12,8 +12,9 @@ type SubscribedRooms = { export const closeOmnichannelConversations = (user: IUser, subscribedRooms: SubscribedRooms[]): void => { const roomsInfo = LivechatRooms.findByIds(subscribedRooms.map(({ rid }) => rid)); - const language = settings.get('Language') || 'en'; - roomsInfo.map((room: any) => - Livechat.closeRoom({ user, visitor: {}, room, comment: TAPi18n.__('Agent_deactivated', { lng: language }) }), - ); + const language = settings.get('Language') || 'en'; + const comment = TAPi18n.__('Agent_deactivated', { lng: language }); + roomsInfo.forEach((room: any) => { + Livechat.closeRoom({ user, visitor: {}, room, comment }); + }); }; diff --git a/app/livechat/server/business-hour/BusinessHourManager.ts b/app/livechat/server/business-hour/BusinessHourManager.ts index e1b5558d0acd..04505776f32b 100644 --- a/app/livechat/server/business-hour/BusinessHourManager.ts +++ b/app/livechat/server/business-hour/BusinessHourManager.ts @@ -1,11 +1,11 @@ import moment from 'moment'; import { ILivechatBusinessHour, LivechatBusinessHourTypes } from '../../../../definition/ILivechatBusinessHour'; -import { ICronJobs } from '../../../utils/server/lib/cron/Cronjobs'; import { IBusinessHourBehavior, IBusinessHourType } from './AbstractBusinessHour'; import { settings } from '../../../settings/server'; import { callbacks } from '../../../callbacks/server'; import { Users } from '../../../models/server/raw'; +import { ICronJobs } from '../../../../definition/ICronJobs'; const cronJobDayDict: Record = { Sunday: 0, diff --git a/app/meteor-accounts-saml/server/lib/parsers/Response.ts b/app/meteor-accounts-saml/server/lib/parsers/Response.ts index 89bbc0758093..f92ba7fedef2 100644 --- a/app/meteor-accounts-saml/server/lib/parsers/Response.ts +++ b/app/meteor-accounts-saml/server/lib/parsers/Response.ts @@ -176,7 +176,7 @@ export class ResponseParser { if (typeof encAssertion !== 'undefined') { const options = { key: this.serviceProviderOptions.privateKey }; const encData = encAssertion.getElementsByTagNameNS('*', 'EncryptedData')[0]; - xmlenc.decrypt(encData, options, function(err: Error, result: string) { + xmlenc.decrypt(encData, options, function(err, result) { if (err) { SAMLUtils.error(err); } @@ -318,7 +318,7 @@ export class ResponseParser { if (typeof encSubject !== 'undefined') { const options = { key: this.serviceProviderOptions.privateKey }; - xmlenc.decrypt(encSubject.getElementsByTagNameNS('*', 'EncryptedData')[0], options, function(err: Error, result: string) { + xmlenc.decrypt(encSubject.getElementsByTagNameNS('*', 'EncryptedData')[0], options, (err, result) => { if (err) { SAMLUtils.error(err); } diff --git a/app/meteor-accounts-saml/tests/server.tests.ts b/app/meteor-accounts-saml/tests/server.tests.ts index d8ca3ba2f702..25a512fffe83 100644 --- a/app/meteor-accounts-saml/tests/server.tests.ts +++ b/app/meteor-accounts-saml/tests/server.tests.ts @@ -38,7 +38,6 @@ import { privateKeyCert, privateKey, } from './data'; -import '../../../definition/xml-encryption'; const { expect } = chai; diff --git a/app/models/server/models/_oplogHandle.ts b/app/models/server/models/_oplogHandle.ts index 997da3c34eb7..936881eeecaa 100644 --- a/app/models/server/models/_oplogHandle.ts +++ b/app/models/server/models/_oplogHandle.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { Promise } from 'meteor/promise'; import { MongoInternals, OplogHandle } from 'meteor/mongo'; import semver from 'semver'; import { MongoClient, Cursor, Timestamp, Db } from 'mongodb'; @@ -193,12 +192,12 @@ class CustomOplogHandle { } } -let oplogHandle: Promise; +let oplogHandle: CustomOplogHandle; if (!process.env.DISABLE_DB_WATCH) { - // @ts-ignore - // eslint-disable-next-line no-undef - if (Package['disable-oplog']) { + const disableOplog = !!(global.Package as any)['disable-oplog']; + + if (disableOplog) { try { oplogHandle = Promise.await(new CustomOplogHandle().start()); } catch (e) { diff --git a/app/notifications/server/lib/Notifications.ts b/app/notifications/server/lib/Notifications.ts index 6653cd98c829..214d642d5f41 100644 --- a/app/notifications/server/lib/Notifications.ts +++ b/app/notifications/server/lib/Notifications.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { Promise } from 'meteor/promise'; import { DDPCommon } from 'meteor/ddp-common'; import { NotificationsModule } from '../../../../server/modules/notifications/notifications.module'; diff --git a/app/notifications/server/lib/Presence.ts b/app/notifications/server/lib/Presence.ts index 549c06af110e..19ccba63461a 100644 --- a/app/notifications/server/lib/Presence.ts +++ b/app/notifications/server/lib/Presence.ts @@ -1,7 +1,7 @@ import { Emitter } from '@rocket.chat/emitter'; +import type { IPublication, IStreamerConstructor, Connection, IStreamer } from 'meteor/rocketchat:streamer'; -import { IUser } from '../../../../definition/IUser'; -import { IPublication, IStreamerConstructor, Connection, IStreamer } from '../../../../server/modules/streamer/streamer.module'; +import type { IUser } from '../../../../definition/IUser'; export type UserPresenseStreamProps = { added: IUser['_id'][]; diff --git a/app/utils/server/lib/cron/Cronjobs.ts b/app/utils/server/lib/cron/Cronjobs.ts index 8ab96121e54f..7223330b9639 100644 --- a/app/utils/server/lib/cron/Cronjobs.ts +++ b/app/utils/server/lib/cron/Cronjobs.ts @@ -1,12 +1,6 @@ import { SyncedCron } from 'meteor/littledata:synced-cron'; -type ScheduleType = 'cron' | 'text'; - -export interface ICronJobs { - add(name: string, schedule: string, callback: Function, scheduleType?: ScheduleType): void; - remove(name: string): void; - nextScheduledAtDate(name: string): Date | number | undefined; -} +import { ICronJobs, ScheduleType } from '../../../../../definition/ICronJobs'; class SyncedCronJobs implements ICronJobs { add(name: string, schedule: string, callback: Function, scheduleType: ScheduleType = 'cron'): void { diff --git a/app/webdav/server/lib/webdavClientAdapter.ts b/app/webdav/server/lib/webdavClientAdapter.ts index 038d0907c8fd..59e4b70f3f2f 100644 --- a/app/webdav/server/lib/webdavClientAdapter.ts +++ b/app/webdav/server/lib/webdavClientAdapter.ts @@ -1,6 +1,4 @@ -import { createClient } from 'webdav'; - -import type { WebDavClient, Stat } from '../../../../definition/webdav'; +import { createClient, WebDavClient, Stat } from 'webdav'; export type ServerCredentials = { token?: string; diff --git a/client/lib/meteorCallWrapper.ts b/client/lib/meteorCallWrapper.ts index 4fbb7f4aaeab..622e2df9b5ed 100644 --- a/client/lib/meteorCallWrapper.ts +++ b/client/lib/meteorCallWrapper.ts @@ -35,7 +35,7 @@ function wrapMeteorDDPCalls(): void { ); const restParams = { - message: DDPCommon.stringifyDDP(message), + message: DDPCommon.stringifyDDP({ ...message }), }; const processResult = (_message: any): void => { @@ -51,7 +51,7 @@ function wrapMeteorDDPCalls(): void { .then(({ message: _message }) => { processResult(_message); if (message.method === 'login') { - const parsedMessage = DDPCommon.parseDDP(_message); + const parsedMessage = DDPCommon.parseDDP(_message) as { result?: { token?: string } }; if (parsedMessage.result?.token) { Meteor.loginWithToken(parsedMessage.result.token); } diff --git a/client/providers/ServerProvider.tsx b/client/providers/ServerProvider.tsx index 9fd145054714..89b1c28b9599 100644 --- a/client/providers/ServerProvider.tsx +++ b/client/providers/ServerProvider.tsx @@ -62,18 +62,6 @@ const uploadToEndpoint = (endpoint: string, params: any, formData: any): Promise return APIClient.v1.upload(endpoint, params, formData).promise; }; -declare module 'meteor/meteor' { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace Meteor { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace StreamerCentral { - const instances: { - [name: string]: typeof Meteor.Streamer; - }; - } - } -} - const getStream = ( streamName: string, options: {} = {}, diff --git a/client/types/less-browser.d.ts b/client/types/less-browser.d.ts deleted file mode 100644 index d9bc07eff65b..000000000000 --- a/client/types/less-browser.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare function createLess(window: Window, options: Less.Options): LessStatic; - -declare module 'less/browser' { - export = createLess; -} diff --git a/client/types/main.d.ts b/client/types/main.d.ts deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/client/types/meteor-mongo.d.ts b/client/types/meteor-mongo.d.ts deleted file mode 100644 index fa23ee6be63f..000000000000 --- a/client/types/meteor-mongo.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -declare module 'meteor/mongo' { - namespace Mongo { - // eslint-disable-next-line @typescript-eslint/interface-name-prefix - interface CollectionStatic { - new ( - name: string | null, - options?: { - connection?: object | null; - idGeneration?: string; - transform?: Function | null; - }, - ): Collection; - } - } -} diff --git a/definition/ICronJobs.ts b/definition/ICronJobs.ts new file mode 100644 index 000000000000..cbd83ecbe074 --- /dev/null +++ b/definition/ICronJobs.ts @@ -0,0 +1,7 @@ +export type ScheduleType = 'cron' | 'text'; + +export interface ICronJobs { + add(name: string, schedule: string, callback: Function, scheduleType?: ScheduleType): void; + remove(name: string): void; + nextScheduledAtDate(name: string): Date | number | undefined; +} diff --git a/client/types/global.d.ts b/definition/externals/global.d.ts similarity index 96% rename from client/types/global.d.ts rename to definition/externals/global.d.ts index 9db2a7370da7..7d37c828de77 100644 --- a/client/types/global.d.ts +++ b/definition/externals/global.d.ts @@ -22,4 +22,5 @@ interface Window { interface PromiseConstructor { await(promise: Promise): T; + await(value: T): T; } diff --git a/definition/ldap-escape.d.ts b/definition/externals/ldap-escape.d.ts similarity index 100% rename from definition/ldap-escape.d.ts rename to definition/externals/ldap-escape.d.ts diff --git a/definition/externals/less/browser.d.ts b/definition/externals/less/browser.d.ts new file mode 100644 index 000000000000..c4fd60586556 --- /dev/null +++ b/definition/externals/less/browser.d.ts @@ -0,0 +1,5 @@ +declare module 'less/browser' { + function createLess(window: Window, options: Less.Options): LessStatic; + + export = createLess; +} diff --git a/definition/externals/meteor/accounts-base.d.ts b/definition/externals/meteor/accounts-base.d.ts new file mode 100644 index 000000000000..da689829afa5 --- /dev/null +++ b/definition/externals/meteor/accounts-base.d.ts @@ -0,0 +1,19 @@ +declare module 'meteor/accounts-base' { + namespace Accounts { + function _bcryptRounds(): number; + + function _getLoginToken(connectionId: string): string | undefined; + + function insertUserDoc(options: Record, user: Record): string; + + function _generateStampedLoginToken(): {token: string; when: Date}; + + function _runLoginHandlers(methodInvocation: Function, loginRequest: Record): Record | undefined; + + export class ConfigError extends Error {} + + export class LoginCancelledError extends Error { + public static readonly numericError: number; + } + } +} diff --git a/definition/externals/meteor/ddp-common.d.ts b/definition/externals/meteor/ddp-common.d.ts new file mode 100644 index 000000000000..2dc41a5f819d --- /dev/null +++ b/definition/externals/meteor/ddp-common.d.ts @@ -0,0 +1,6 @@ +declare module 'meteor/ddp-common' { + namespace DDPCommon { + function stringifyDDP(msg: EJSONable): string; + function parseDDP(msg: string): EJSONable; + } +} diff --git a/client/types/meteor-htmljs.d.ts b/definition/externals/meteor/htmljs.d.ts similarity index 100% rename from client/types/meteor-htmljs.d.ts rename to definition/externals/meteor/htmljs.d.ts diff --git a/client/types/kadira-flow-router.d.ts b/definition/externals/meteor/kadira-flow-router.d.ts similarity index 100% rename from client/types/kadira-flow-router.d.ts rename to definition/externals/meteor/kadira-flow-router.d.ts diff --git a/client/types/konecty-user-presence.d.ts b/definition/externals/meteor/konecty-user-presence.d.ts similarity index 100% rename from client/types/konecty-user-presence.d.ts rename to definition/externals/meteor/konecty-user-presence.d.ts diff --git a/definition/externals/meteor/littledata-synced-cron.d.ts b/definition/externals/meteor/littledata-synced-cron.d.ts new file mode 100644 index 000000000000..412fa6f60d7c --- /dev/null +++ b/definition/externals/meteor/littledata-synced-cron.d.ts @@ -0,0 +1,7 @@ +declare module 'meteor/littledata:synced-cron' { + namespace SyncedCron { + function add(params: { name: string; schedule: Function; job: Function }): string; + function remove(name: string): string; + function nextScheduledAtDate(name: string): Date | number | undefined; + } +} diff --git a/definition/externals/meteor/logging.d.ts b/definition/externals/meteor/logging.d.ts new file mode 100644 index 000000000000..f5dedcfa522e --- /dev/null +++ b/definition/externals/meteor/logging.d.ts @@ -0,0 +1,19 @@ +declare module 'meteor/logging' { + namespace Log { + function format(obj: { + time?: Date; + timeInexact?: boolean; + level?: 'debug' | 'info' | 'warn' | 'error'; + file?: string; + line?: number; + app?: string; + originApp?: string; + message?: string; + program?: string; + satellite?: string; + stderr?: string; + }, options: { + color?: boolean; + }): string; + } +} diff --git a/client/types/meteor.d.ts b/definition/externals/meteor/meteor.d.ts similarity index 64% rename from client/types/meteor.d.ts rename to definition/externals/meteor/meteor.d.ts index bc1b77f9bcc4..f4e6c3a65c44 100644 --- a/client/types/meteor.d.ts +++ b/definition/externals/meteor/meteor.d.ts @@ -1,5 +1,24 @@ +/* eslint-disable @typescript-eslint/interface-name-prefix */ + declare module 'meteor/meteor' { namespace Meteor { + interface ErrorStatic { + new (error: string | number, reason?: string, details?: any): Error; + } + + interface Error extends globalThis.Error { + error: string | number; + reason?: string; + } + + const server: any; + + const runAsUser: (userId: string, scope: Function) => any; + + interface MethodThisType { + twoFactorChecked: boolean | undefined; + } + interface IDDPMessage { msg: 'method'; method: string; @@ -36,7 +55,7 @@ declare module 'meteor/meteor' { const connection: IMeteorConnection; - function _relativeToSiteRootUrl(path: string): void; + function _relativeToSiteRootUrl(path: string): string; const _localStorage: Window['localStorage']; } } diff --git a/definition/externals/meteor/meteorhacks-inject-initial.d.ts b/definition/externals/meteor/meteorhacks-inject-initial.d.ts new file mode 100644 index 000000000000..b0498aaf4a0d --- /dev/null +++ b/definition/externals/meteor/meteorhacks-inject-initial.d.ts @@ -0,0 +1,5 @@ +declare module 'meteor/meteorhacks:inject-initial' { + namespace Inject { + function rawBody(key: string, value: string): void; + } +} diff --git a/client/types/mizzao-timesync.d.ts b/definition/externals/meteor/mizzao-timesync.d.ts similarity index 100% rename from client/types/mizzao-timesync.d.ts rename to definition/externals/meteor/mizzao-timesync.d.ts diff --git a/definition/externals/meteor/mongo.d.ts b/definition/externals/meteor/mongo.d.ts new file mode 100644 index 000000000000..7efb5b5b0860 --- /dev/null +++ b/definition/externals/meteor/mongo.d.ts @@ -0,0 +1,44 @@ +/* eslint-disable @typescript-eslint/interface-name-prefix */ +import * as mongodb from 'mongodb'; + +declare module 'meteor/mongo' { + interface RemoteCollectionDriver { + mongo: MongoConnection; + } + + interface OplogHandle { + stop(): void; + onOplogEntry(trigger: Record, callback: Function): void; + onSkippedEntries(callback: Function): void; + waitUntilCaughtUp(): void; + _defineTooFarBehind(value: number): void; + } + + interface MongoConnection { + db: mongodb.Db; + _oplogHandle: OplogHandle; + rawCollection(name: string): mongodb.Collection; + } + + namespace MongoInternals { + function defaultRemoteCollectionDriver(): RemoteCollectionDriver; + + class ConnectionClass {} + + function Connection(): ConnectionClass; + } + + namespace Mongo { + // eslint-disable-next-line @typescript-eslint/interface-name-prefix + interface CollectionStatic { + new ( + name: string | null, + options?: { + connection?: object | null; + idGeneration?: string; + transform?: Function | null; + }, + ): Collection; + } + } +} diff --git a/definition/externals/meteor/random.d.ts b/definition/externals/meteor/random.d.ts new file mode 100644 index 000000000000..4da29740e9cf --- /dev/null +++ b/definition/externals/meteor/random.d.ts @@ -0,0 +1,5 @@ +declare module 'meteor/random' { + namespace Random { + function _randomString(numberOfChars: number, map: string): string; + } +} diff --git a/definition/externals/meteor/rocketchat-streamer.d.ts b/definition/externals/meteor/rocketchat-streamer.d.ts new file mode 100644 index 000000000000..857a8b0daeea --- /dev/null +++ b/definition/externals/meteor/rocketchat-streamer.d.ts @@ -0,0 +1,90 @@ +declare module 'meteor/rocketchat:streamer' { + type Connection = any; + + type Client = { + meteorClient: boolean; + ws: any; + userId?: string; + send: Function; + } + + interface IPublication { + onStop: Function; + stop: Function; + connection: Connection; + _session: { + sendAdded(publicationName: string, id: string, fields: Record): void; + userId?: string; + socket?: { + send: Function; + }; + }; + ready: Function; + userId: string | undefined; + client: Client; + } + + type Rule = (this: IPublication, eventName: string, ...args: any) => Promise; + + interface IRules { + [k: string]: Rule; + } + + type DDPSubscription = { + eventName: string; + subscription: IPublication; + } + + type TransformMessage = (streamer: IStreamer, subscription: DDPSubscription, eventName: string, args: any[], allowed: boolean | object) => string | false; + + interface IStreamer { + serverOnly: boolean; + + subscriptions: Set; + + subscriptionName: string; + + allowEmit(eventName: string | boolean | Rule, fn?: Rule | 'all' | 'none' | 'logged'): void; + + allowWrite(eventName: string | boolean | Rule, fn?: Rule | 'all' | 'none' | 'logged'): void; + + allowRead(eventName: string | boolean | Rule, fn?: Rule | 'all' | 'none' | 'logged'): void; + + emit(event: string, ...data: any[]): void; + + on(event: string, fn: (...data: any[]) => void): void; + + removeSubscription(subscription: DDPSubscription, eventName: string): void; + + removeListener(event: string, fn: (...data: any[]) => void): void; + + __emit(...data: any[]): void; + + _emit(eventName: string, args: any[], origin: Connection | undefined, broadcast: boolean, transform?: TransformMessage): boolean; + + emitWithoutBroadcast(event: string, ...data: any[]): void; + + changedPayload(collection: string, id: string, fields: Record): string | false; + + _publish(publication: IPublication, eventName: string, options: boolean | {useCollection?: boolean; args?: any}): Promise; + } + + interface IStreamerConstructor { + // eslint-disable-next-line @typescript-eslint/no-misused-new + new(name: string, options?: {retransmit?: boolean; retransmitToSelf?: boolean}): IStreamer; + } +} + +declare module 'meteor/meteor' { + import { IStreamerConstructor, IStreamer } from 'meteor/rocketchat:streamer'; + + namespace Meteor { + const Streamer: IStreamerConstructor & IStreamer; + + namespace StreamerCentral { + const instances: { + [name: string]: IStreamer; + }; + } + } +} diff --git a/definition/externals/meteor/rocketchat-tap-i18n.d.ts b/definition/externals/meteor/rocketchat-tap-i18n.d.ts new file mode 100644 index 000000000000..d2c9baf18143 --- /dev/null +++ b/definition/externals/meteor/rocketchat-tap-i18n.d.ts @@ -0,0 +1,31 @@ +declare module 'meteor/rocketchat:tap-i18n' { + import { Tracker } from 'meteor/tracker'; + import i18next from 'i18next'; + + namespace TAPi18n { + function __(s: string | undefined, options?: { + lng?: string; + } & { + [replacements: string]: boolean | number | string; + }): string; + function getLanguages(): { + [language: string]: { + name: string; + en: string; + }; + }; + function setLanguage(language: string): void; + + // eslint-disable-next-line @typescript-eslint/camelcase + const _language_changed_tracker: Tracker.Dependency; + + // eslint-disable-next-line @typescript-eslint/camelcase + const _loaded_lang_session_key: string; + + const conf: { + i18n_files_route: string; + }; + } + + export const TAPi18next: typeof i18next; +} diff --git a/definition/externals/meteor/routepolicy.d.ts b/definition/externals/meteor/routepolicy.d.ts new file mode 100644 index 000000000000..ea6866632d17 --- /dev/null +++ b/definition/externals/meteor/routepolicy.d.ts @@ -0,0 +1,5 @@ +declare module 'meteor/routepolicy' { + export class RoutePolicy { + static declare(urlPrefix: string, type: string): void; + } +} diff --git a/definition/meteor-sha.d.ts b/definition/externals/meteor/sha.d.ts similarity index 100% rename from definition/meteor-sha.d.ts rename to definition/externals/meteor/sha.d.ts diff --git a/client/types/meteor-tracker.d.ts b/definition/externals/meteor/tracker.d.ts similarity index 100% rename from client/types/meteor-tracker.d.ts rename to definition/externals/meteor/tracker.d.ts diff --git a/mongodb.aug.d.ts b/definition/externals/mongodb.d.ts similarity index 100% rename from mongodb.aug.d.ts rename to definition/externals/mongodb.d.ts diff --git a/client/types/fuselage-tokens-colors.d.ts b/definition/externals/rocket.chat/fuselage-tokens/colors.d.ts similarity index 100% rename from client/types/fuselage-tokens-colors.d.ts rename to definition/externals/rocket.chat/fuselage-tokens/colors.d.ts diff --git a/client/types/fuselage-ui-kit.d.ts b/definition/externals/rocket.chat/fuselage-ui-kit.d.ts similarity index 100% rename from client/types/fuselage-ui-kit.d.ts rename to definition/externals/rocket.chat/fuselage-ui-kit.d.ts diff --git a/definition/externals/webdav.d.ts b/definition/externals/webdav.d.ts new file mode 100644 index 000000000000..c44ebda19adb --- /dev/null +++ b/definition/externals/webdav.d.ts @@ -0,0 +1,32 @@ +declare module 'webdav' { + type Stat = { + filename: string; + basename: string; + lastmod: string|null; + size: number; + type: string; + mime: string; + etag: string|null; + props: Record; + } + + type WebDavClient = { + copyFile(remotePath: string, targetRemotePath: string, options?: Record): Promise; + createDirectory(dirPath: string, options?: Record): Promise; + createReadStream(remoteFileName: string, options?: Record): ReadableStream; + createWriteStream(remoteFileName: string, options?: Record, callback?: Function): WritableStream; + customRequest(remotePath: string, requestOptions: Record, options?: Record): Promise; + deleteFile(remotePath: string, options?: Record): Promise; + exists(remotePath: string, options?: Record): Promise; + getDirectoryContents(remotePath: string, options?: Record): Promise>; + getFileContents(remoteFileName: string, options?: Record): Promise; + getFileDownloadLink(remoteFileName: string, options?: Record): string; + getFileUploadLink(remoteFileName: string, options?: Record): string; + getQuota(options?: Record): Promise; + moveFile(remotePath: string, targetRemotePath: string, options?: Record): Promise; + putFileContents(remoteFileName: string, data: string|Buffer, options?: Record): Promise; + stat(remotePath: string, options?: Record): Promise; + } + + export function createClient(remoteURL: string, opts?: Record): WebDavClient; +} diff --git a/definition/xml-encryption.ts b/definition/externals/xml-encryption.d.ts similarity index 100% rename from definition/xml-encryption.ts rename to definition/externals/xml-encryption.d.ts diff --git a/definition/webdav.ts b/definition/webdav.ts deleted file mode 100644 index afc380b8330e..000000000000 --- a/definition/webdav.ts +++ /dev/null @@ -1,32 +0,0 @@ -export type Stat = { - filename: string; - basename: string; - lastmod: string|null; - size: number; - type: string; - mime: string; - etag: string|null; - props: Record; -} - -export type WebDavClient = { - copyFile(remotePath: string, targetRemotePath: string, options?: Record): Promise; - createDirectory(dirPath: string, options?: Record): Promise; - createReadStream(remoteFileName: string, options?: Record): ReadableStream; - createWriteStream(remoteFileName: string, options?: Record, callback?: Function): WritableStream; - customRequest(remotePath: string, requestOptions: Record, options?: Record): Promise; - deleteFile(remotePath: string, options?: Record): Promise; - exists(remotePath: string, options?: Record): Promise; - getDirectoryContents(remotePath: string, options?: Record): Promise>; - getFileContents(remoteFileName: string, options?: Record): Promise; - getFileDownloadLink(remoteFileName: string, options?: Record): string; - getFileUploadLink(remoteFileName: string, options?: Record): string; - getQuota(options?: Record): Promise; - moveFile(remotePath: string, targetRemotePath: string, options?: Record): Promise; - putFileContents(remoteFileName: string, data: string|Buffer, options?: Record): Promise; - stat(remotePath: string, options?: Record): Promise; -} - -declare module 'webdav' { - export function createClient(remoteURL: string, opts?: Record): WebDavClient; -} diff --git a/ee/app/livechat-enterprise/server/api/business-hours.ts b/ee/app/livechat-enterprise/server/api/business-hours.ts index 8044a1509a12..aab6a58bb406 100644 --- a/ee/app/livechat-enterprise/server/api/business-hours.ts +++ b/ee/app/livechat-enterprise/server/api/business-hours.ts @@ -1,5 +1,3 @@ -import { Promise } from 'meteor/promise'; - import { API } from '../../../../../app/api/server'; import { findBusinessHours } from '../business-hour/lib/business-hour'; diff --git a/ee/app/livechat-enterprise/server/lib/QueueInactivityMonitor.ts b/ee/app/livechat-enterprise/server/lib/QueueInactivityMonitor.ts index 7c1f668e7648..69070c0d877d 100644 --- a/ee/app/livechat-enterprise/server/lib/QueueInactivityMonitor.ts +++ b/ee/app/livechat-enterprise/server/lib/QueueInactivityMonitor.ts @@ -42,7 +42,7 @@ export class OmnichannelQueueInactivityMonitorClass { }); this.createIndex(); this.user = Users.findOneById('rocket.cat'); - const language = settings.get('Language') || 'en'; + const language = settings.get('Language') || 'en'; this.message = TAPi18n.__('Closed_automatically_chat_queued_too_long', { lng: language }); this.bindedCloseRoom = Meteor.bindEnvironment(this.closeRoom.bind(this)); } diff --git a/ee/app/livechat-enterprise/server/methods/removeBusinessHour.ts b/ee/app/livechat-enterprise/server/methods/removeBusinessHour.ts index 9498d430e253..76894a1a000e 100644 --- a/ee/app/livechat-enterprise/server/methods/removeBusinessHour.ts +++ b/ee/app/livechat-enterprise/server/methods/removeBusinessHour.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { Promise } from 'meteor/promise'; import { hasPermission } from '../../../../../app/authorization/server'; import { businessHourManager } from '../../../../../app/livechat/server/business-hour'; diff --git a/ee/app/teams-mention/server/index.ts b/ee/app/teams-mention/server/index.ts index 61ddf75230ac..362a0ee1b05b 100644 --- a/ee/app/teams-mention/server/index.ts +++ b/ee/app/teams-mention/server/index.ts @@ -1,5 +1,3 @@ -import { Promise } from 'meteor/promise'; - import { onLicense } from '../../license/server'; import { overwriteClassOnLicense } from '../../license/server/license'; import { SpotlightEnterprise } from './EESpotlight'; diff --git a/ee/server/services/ddp-streamer/Publication.ts b/ee/server/services/ddp-streamer/Publication.ts index 74e152417b4c..94eedc9769d3 100644 --- a/ee/server/services/ddp-streamer/Publication.ts +++ b/ee/server/services/ddp-streamer/Publication.ts @@ -1,9 +1,10 @@ import { EventEmitter } from 'events'; +import type { IPublication } from 'meteor/rocketchat:streamer'; + import { Server } from './Server'; import { Client } from './Client'; import { IPacket } from './types/IPacket'; -import { IPublication } from '../../../../server/modules/streamer/streamer.module'; export class Publication extends EventEmitter implements IPublication { _session: IPublication['_session']; diff --git a/ee/server/services/ddp-streamer/Streamer.ts b/ee/server/services/ddp-streamer/Streamer.ts index 2932b52a0917..387ff123bcf7 100644 --- a/ee/server/services/ddp-streamer/Streamer.ts +++ b/ee/server/services/ddp-streamer/Streamer.ts @@ -1,9 +1,10 @@ import WebSocket from 'ws'; +import type { DDPSubscription, Connection, TransformMessage } from 'meteor/rocketchat:streamer'; import { server } from './configureServer'; import { DDP_EVENTS } from './constants'; import { isEmpty } from './lib/utils'; -import { Streamer, DDPSubscription, Connection, StreamerCentral, TransformMessage } from '../../../../server/modules/streamer/streamer.module'; +import { Streamer, StreamerCentral } from '../../../../server/modules/streamer/streamer.module'; import { api } from '../../../../server/sdk/api'; StreamerCentral.on('broadcast', (name, eventName, args) => { diff --git a/ee/server/services/ddp-streamer/types/ws.d.ts b/ee/server/services/ddp-streamer/types/ws.d.ts deleted file mode 100644 index b71218b72140..000000000000 --- a/ee/server/services/ddp-streamer/types/ws.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-disable no-redeclare */ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import 'ws'; - -type FrameOptions = { - opcode: number; // The opcode - readOnly: boolean; // Specifies whether `data` can be modified - fin: boolean; // Specifies whether or not to set the FIN bit - mask: boolean; // Specifies whether or not to mask `data` - rsv1: boolean; // Specifies whether or not to set the RSV1 bit -} - -declare module 'ws' { - class Sender { - static frame(data: Buffer, options: FrameOptions): Buffer[]; - } -} diff --git a/ee/server/services/definition/externals/ws.d.ts b/ee/server/services/definition/externals/ws.d.ts new file mode 100644 index 000000000000..e6afc68181cb --- /dev/null +++ b/ee/server/services/definition/externals/ws.d.ts @@ -0,0 +1,13 @@ +import 'ws'; + +declare module 'ws' { + namespace Sender { + function frame(data: Buffer, options: { + opcode: number; // The opcode + readOnly: boolean; // Specifies whether `data` can be modified + fin: boolean; // Specifies whether or not to set the FIN bit + mask: boolean; // Specifies whether or not to mask `data` + rsv1: boolean; // Specifies whether or not to set the RSV1 bit + }): Buffer[]; + } +} diff --git a/ee/server/services/package-lock.json b/ee/server/services/package-lock.json index b88d36579b81..3b1cfe814ece 100644 --- a/ee/server/services/package-lock.json +++ b/ee/server/services/package-lock.json @@ -216,6 +216,12 @@ "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.4.tgz", "integrity": "sha512-HLU3NDY6wARrLCEwyGKRBvuWYyvW6mHYv72SJJAH3iJN3a6eVUvkjFkcxah1bcTgGVBBrFdIopBJPhCQFMLyXw==", "dev": true + }, + "ws": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz", + "integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==", + "dev": true } } }, @@ -3127,9 +3133,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "7.5.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.1.tgz", - "integrity": "sha512-2c6faOUH/nhoQN6abwMloF7Iyl0ZS2E9HGtsiLrWn0zOOMWlhtDmdf/uihDt6jnuCxgtwGBNy6Onsoy2s2O2Ow==" + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz", + "integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==" }, "xorshift": { "version": "0.2.1", diff --git a/ee/server/services/package.json b/ee/server/services/package.json index 242fc2c9bfb0..5000e768d23c 100644 --- a/ee/server/services/package.json +++ b/ee/server/services/package.json @@ -37,7 +37,7 @@ "sodium-plus": "^0.9.0", "underscore.string": "^3.3.5", "uuid": "^7.0.3", - "ws": "^7.5.1" + "ws": "^7.5.5" }, "devDependencies": { "@types/cookie": "^0.4.1", @@ -51,5 +51,9 @@ "pm2": "^5.1.1", "ts-node": "^10.0.0", "typescript": "^4.3.5" + }, + "volta": { + "node": "12.22.1", + "npm": "6.14.12" } } diff --git a/ee/server/services/tsconfig.json b/ee/server/services/tsconfig.json index c9da08939693..820685091f9a 100644 --- a/ee/server/services/tsconfig.json +++ b/ee/server/services/tsconfig.json @@ -3,7 +3,6 @@ "module": "CommonJS", "target": "es2018", "lib": ["esnext", "dom"], - "types" : ["node"], "allowJs": true, "checkJs": false, @@ -42,6 +41,9 @@ // "emitDecoratorMetadata": true, // "experimentalDecorators": true, }, + "include": [ + "../../../definition" + ], "exclude": [ "./dist", "./ecosystem.config.js" diff --git a/package-lock.json b/package-lock.json index 9fec1aaf5120..d8bc7e649fd0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9992,9 +9992,9 @@ "dev": true }, "@types/prop-types": { - "version": "15.7.3", - "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz", - "integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==", + "version": "15.7.4", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.4.tgz", + "integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==", "dev": true }, "@types/psl": { @@ -10025,9 +10025,9 @@ } }, "@types/react": { - "version": "17.0.11", - "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.11.tgz", - "integrity": "sha512-yFRQbD+whVonItSk7ZzP/L+gPTJVBkL/7shLEF+i9GC/1cV3JmUxEQz6+9ylhUpWSDuqo1N9qEvqS6vTj4USUA==", + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.32.tgz", + "integrity": "sha512-hAm1pmwA3oZWbkB985RFwNvBRMG0F3KWSiC4/hNmanigKZMiKQoH5Q6etNw8HIDztTGfvXyOjPvdNnvBUCuaPg==", "dev": true, "requires": { "@types/prop-types": "*", @@ -10036,39 +10036,20 @@ }, "dependencies": { "csstype": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.8.tgz", - "integrity": "sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==", + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.9.tgz", + "integrity": "sha512-rpw6JPxK6Rfg1zLOYCSwle2GFOOsnjmDYDaBwEcwoOg4qlsIVCN789VkBZDJAGi4T07gI4YSutR43t9Zz4Lzuw==", "dev": true } } }, "@types/react-dom": { - "version": "17.0.8", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-17.0.8.tgz", - "integrity": "sha512-0ohAiJAx1DAUEcY9UopnfwCE9sSMDGnY/oXjWMax6g3RpzmTt2GMyMVAXcbn0mo8XAff0SbQJl2/SBU+hjSZ1A==", + "version": "17.0.10", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-17.0.10.tgz", + "integrity": "sha512-8oz3NAUId2z/zQdFI09IMhQPNgIbiP8Lslhv39DIDamr846/0spjZK0vnrMak0iB8EKb9QFTTIdg2Wj2zH5a3g==", "dev": true, "requires": { "@types/react": "*" - }, - "dependencies": { - "@types/react": { - "version": "16.14.8", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.8.tgz", - "integrity": "sha512-QN0/Qhmx+l4moe7WJuTxNiTsjBwlBGHqKGvInSQCBdo7Qio0VtOqwsC0Wq7q3PbJlB0cR4Y4CVo1OOe6BOsOmA==", - "dev": true, - "requires": { - "@types/prop-types": "*", - "@types/scheduler": "*", - "csstype": "^3.0.2" - } - }, - "csstype": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.8.tgz", - "integrity": "sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==", - "dev": true - } } }, "@types/react-syntax-highlighter": { @@ -10115,9 +10096,9 @@ "dev": true }, "@types/scheduler": { - "version": "0.16.1", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.1.tgz", - "integrity": "sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==", + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", "dev": true }, "@types/semver": { diff --git a/package.json b/package.json index e7b26de962e2..cdd13b6d6306 100644 --- a/package.json +++ b/package.json @@ -93,8 +93,8 @@ "@types/nodemailer": "^6.4.2", "@types/parseurl": "^1.3.1", "@types/psl": "^1.1.0", - "@types/react": "^17.0.11", - "@types/react-dom": "^17.0.8", + "@types/react": "^17.0.32", + "@types/react-dom": "^17.0.10", "@types/rewire": "^2.5.28", "@types/semver": "^7.3.6", "@types/sharp": "^0.28.3", @@ -304,7 +304,7 @@ "meteor": { "mainModule": { "client": "client/main.ts", - "server": "server/main.js" + "server": "server/main.ts" } }, "houston": { @@ -322,6 +322,7 @@ "last 2 versions" ], "volta": { - "node": "12.22.1" + "node": "12.22.1", + "npm": "6.14.12" } } diff --git a/server/configuration/ldap.ts b/server/configuration/ldap.ts index ea5f3547c95f..5368d5298349 100644 --- a/server/configuration/ldap.ts +++ b/server/configuration/ldap.ts @@ -1,5 +1,4 @@ import { Accounts } from 'meteor/accounts-base'; -import { Promise } from 'meteor/promise'; import { callbacks } from '../../app/callbacks/server'; import { LDAP } from '../sdk'; diff --git a/server/features/EmailInbox/EmailInbox_Incoming.ts b/server/features/EmailInbox/EmailInbox_Incoming.ts index 570a52998cba..c4edb686077f 100644 --- a/server/features/EmailInbox/EmailInbox_Incoming.ts +++ b/server/features/EmailInbox/EmailInbox_Incoming.ts @@ -27,7 +27,7 @@ type FileAttachment = { video_size?: string; } -const language = settings.get('Language') || 'en'; +const language = settings.get('Language') || 'en'; const t = (s: string): string => TAPi18n.__(s, { lng: language }); function getGuestByEmail(email: string, name: string, department?: string): any { diff --git a/server/features/EmailInbox/EmailInbox_Outgoing.ts b/server/features/EmailInbox/EmailInbox_Outgoing.ts index a9f913a2f3f9..f9cf4e1d2140 100644 --- a/server/features/EmailInbox/EmailInbox_Outgoing.ts +++ b/server/features/EmailInbox/EmailInbox_Outgoing.ts @@ -19,7 +19,7 @@ const livechatQuoteRegExp = /^\[\s\]\(https?:\/\/.+\/live\/.+\?msg=(?.+?)\)\ const user: IUser = Users.findOneById('rocket.cat'); -const language = settings.get('Language') || 'en'; +const language = settings.get('Language') || 'en'; const t = (s: string): string => TAPi18n.__(s, { lng: language }); const sendErrorReplyMessage = (error: string, options: any): void => { diff --git a/server/main.d.ts b/server/main.d.ts deleted file mode 100644 index 7bb7db2a2641..000000000000 --- a/server/main.d.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { EJSON } from 'meteor/ejson'; -import { Db, Collection } from 'mongodb'; -import * as mongodb from 'mongodb'; - -import { IStreamer, IStreamerConstructor } from './modules/streamer/streamer.module'; - -/* eslint-disable @typescript-eslint/interface-name-prefix */ -declare module 'meteor/random' { - namespace Random { - function _randomString(numberOfChars: number, map: string): string; - } -} - -declare module 'meteor/mongo' { - namespace MongoInternals { - function defaultRemoteCollectionDriver(): any; - } -} - -declare module 'meteor/accounts-base' { - namespace Accounts { - function _bcryptRounds(): number; - - function _getLoginToken(connectionId: string): string | undefined; - - function insertUserDoc(options: Record, user: Record): string; - - function _generateStampedLoginToken(): {token: string; when: Date}; - - function _runLoginHandlers(methodInvocation: Function, loginRequest: Record): Record | undefined; - - export class ConfigError extends Error {} - - export class LoginCancelledError extends Error { - public static readonly numericError: number; - } - } -} - -declare module 'meteor/meteor' { - type globalError = Error; - namespace Meteor { - interface ErrorStatic { - new (error: string | number, reason?: string, details?: any): Error; - } - interface Error extends globalError { - error: string | number; - reason?: string; - details?: string | undefined | Record; - } - - const Streamer: IStreamerConstructor & IStreamer; - - const server: any; - - const runAsUser: (userId: string, scope: Function) => any; - - interface MethodThisType { - twoFactorChecked: boolean | undefined; - } - } -} - -declare module 'meteor/ddp-common' { - namespace DDPCommon { - function stringifyDDP(msg: EJSON): string; - function parseDDP(msg: string): EJSON; - } -} - -declare module 'meteor/routepolicy' { - export class RoutePolicy { - static declare(urlPrefix: string, type: string): void; - } -} - -declare module 'meteor/rocketchat:tap-i18n' { - namespace TAPi18n { - function __(s: string, options: { lng: string }): string; - } -} - -declare module 'meteor/promise' { - namespace Promise { - function await(): any; - } -} - -declare module 'meteor/littledata:synced-cron' { - interface ICronAddParameters { - name: string; - schedule: Function; - job: Function; - } - namespace SyncedCron { - function add(params: ICronAddParameters): string; - function remove(name: string): string; - } -} - -declare module 'meteor/mongo' { - interface RemoteCollectionDriver { - mongo: MongoConnection; - } - interface OplogHandle { - stop(): void; - onOplogEntry(trigger: Record, callback: Function): void; - onSkippedEntries(callback: Function): void; - waitUntilCaughtUp(): void; - _defineTooFarBehind(value: number): void; - } - interface MongoConnection { - db: Db; - _oplogHandle: OplogHandle; - rawCollection(name: string): Collection; - } - - namespace MongoInternals { - export const NpmModules: { - mongodb: { - version: string; - module: typeof mongodb; - }; - }; - - function defaultRemoteCollectionDriver(): RemoteCollectionDriver; - - class ConnectionClass {} - - function Connection(): ConnectionClass; - } -} - -declare module 'async_hooks' { - export class AsyncLocalStorage { - disable(): void; - - getStore(): T | undefined; - - run(store: T, callback: (...args: any[]) => void, ...args: any[]): void; - - exit(callback: (...args: any[]) => void, ...args: any[]): void; - - runSyncAndReturn(store: T, callback: (...args: any[]) => R, ...args: any[]): R; - - exitSyncAndReturn(callback: (...args: any[]) => R, ...args: any[]): R; - - enterWith(store: T): void; - } -} diff --git a/server/main.js b/server/main.ts similarity index 100% rename from server/main.js rename to server/main.ts diff --git a/server/modules/notifications/notifications.module.ts b/server/modules/notifications/notifications.module.ts index da674daf8ca5..bd057b9304f2 100644 --- a/server/modules/notifications/notifications.module.ts +++ b/server/modules/notifications/notifications.module.ts @@ -1,4 +1,5 @@ -import { IStreamer, IStreamerConstructor, IPublication } from '../streamer/streamer.module'; +import type { IStreamer, IStreamerConstructor, IPublication } from 'meteor/rocketchat:streamer'; + import { Authorization } from '../../sdk'; import { RoomsRaw } from '../../../app/models/server/raw/Rooms'; import { SubscriptionsRaw } from '../../../app/models/server/raw/Subscriptions'; diff --git a/server/modules/streamer/streamer.module.ts b/server/modules/streamer/streamer.module.ts index 4c8ae7f7d812..19745ebaff3d 100644 --- a/server/modules/streamer/streamer.module.ts +++ b/server/modules/streamer/streamer.module.ts @@ -1,4 +1,13 @@ import { EventEmitter } from 'eventemitter3'; +import type { + IPublication, + Rule, + Connection, + DDPSubscription, + IStreamer, + IRules, + TransformMessage, +} from 'meteor/rocketchat:streamer'; import { SystemLogger } from '../../lib/logger/system'; @@ -12,81 +21,6 @@ class StreamerCentralClass extends EventEmitter { export const StreamerCentral = new StreamerCentralClass(); -export type Client = { - meteorClient: boolean; - ws: any; - userId?: string; - send: Function; -} - -export interface IPublication { - onStop: Function; - stop: Function; - connection: Connection; - _session: { - sendAdded(publicationName: string, id: string, fields: Record): void; - userId?: string; - socket?: { - send: Function; - }; - }; - ready: Function; - userId: string | undefined; - client: Client; -} - -type Rule = (this: IPublication, eventName: string, ...args: any) => Promise; - -interface IRules { - [k: string]: Rule; -} - -export type Connection = any; - -export type DDPSubscription = { - eventName: string; - subscription: IPublication; -} - -export interface IStreamer { - serverOnly: boolean; - - subscriptions: Set; - - subscriptionName: string; - - allowEmit(eventName: string | boolean | Rule, fn?: Rule | 'all' | 'none' | 'logged'): void; - - allowWrite(eventName: string | boolean | Rule, fn?: Rule | 'all' | 'none' | 'logged'): void; - - allowRead(eventName: string | boolean | Rule, fn?: Rule | 'all' | 'none' | 'logged'): void; - - emit(event: string, ...data: any[]): void; - - on(event: string, fn: (...data: any[]) => void): void; - - removeSubscription(subscription: DDPSubscription, eventName: string): void; - - removeListener(event: string, fn: (...data: any[]) => void): void; - - __emit(...data: any[]): void; - - _emit(eventName: string, args: any[], origin: Connection | undefined, broadcast: boolean, transform?: TransformMessage): boolean; - - emitWithoutBroadcast(event: string, ...data: any[]): void; - - changedPayload(collection: string, id: string, fields: Record): string | false; - - _publish(publication: IPublication, eventName: string, options: boolean | {useCollection?: boolean; args?: any}): Promise; -} - -export interface IStreamerConstructor { - // eslint-disable-next-line @typescript-eslint/no-misused-new - new(name: string, options?: {retransmit?: boolean; retransmitToSelf?: boolean}): IStreamer; -} - -export type TransformMessage = (streamer: Streamer, subscription: DDPSubscription, eventName: string, args: any[], allowed: boolean | object) => string | false; - export abstract class Streamer extends EventEmitter implements IStreamer { public subscriptions = new Set(); diff --git a/server/sdk/types/ITeamService.ts b/server/sdk/types/ITeamService.ts index a5ec4fa22ec2..ad4a790ab6fe 100644 --- a/server/sdk/types/ITeamService.ts +++ b/server/sdk/types/ITeamService.ts @@ -76,6 +76,7 @@ export interface ITeamService { deleteById(teamId: string): Promise; deleteByName(teamName: string): Promise; unsetTeamIdOfRooms(teamId: string): void; + getOneById(teamId: string, options?: FindOneOptions): Promise; getOneById

(teamId: string, options?: FindOneOptions

): Promise; getOneByName(teamName: string | RegExp, options?: FindOneOptions): Promise; getOneByMainRoomId(teamId: string): Promise | null>; diff --git a/server/services/meteor/service.ts b/server/services/meteor/service.ts index 6d5290673af3..823795c31bdf 100644 --- a/server/services/meteor/service.ts +++ b/server/services/meteor/service.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { Promise } from 'meteor/promise'; import { ServiceConfiguration } from 'meteor/service-configuration'; import { UserPresenceMonitor, UserPresence } from 'meteor/konecty:user-presence'; import { MongoInternals } from 'meteor/mongo'; @@ -50,7 +49,7 @@ type Callbacks = { let processOnChange: (diff: Record, id: string) => void; // eslint-disable-next-line no-undef -const disableOplog = Package['disable-oplog']; +const disableOplog = !!(Package as any)['disable-oplog']; const serviceConfigCallbacks = new Set(); if (disableOplog) { diff --git a/server/services/nps/notification.ts b/server/services/nps/notification.ts index 303470dadfa2..72dd87c80397 100644 --- a/server/services/nps/notification.ts +++ b/server/services/nps/notification.ts @@ -9,7 +9,7 @@ import { IBanner, BannerPlatform } from '../../../definition/IBanner'; import { sendMessagesToAdmins } from '../../lib/sendMessagesToAdmins.js'; export const getBannerForAdmins = Meteor.bindEnvironment((expireAt: Date): Omit => { - const lng = settings.get('Language') || 'en'; + const lng = settings.get('Language') || 'en'; return { platform: [BannerPlatform.Web], diff --git a/server/startup/migrations/v211.js b/server/startup/migrations/v211.js index b79d155aa18f..d5ac34be0f7b 100644 --- a/server/startup/migrations/v211.js +++ b/server/startup/migrations/v211.js @@ -1,5 +1,3 @@ -import { Promise } from 'meteor/promise'; - import { addMigration } from '../../lib/migrations'; import { Sessions } from '../../../app/models/server/raw'; import { getMostImportantRole } from '../../../app/statistics/server/lib/getMostImportantRole'; diff --git a/tsconfig.json b/tsconfig.json index 0be783b373b1..dff6cb6c6ddd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -31,7 +31,7 @@ "moduleResolution": "node", "resolveJsonModule": true, "esModuleInterop": true, - "preserveSymlinks": true, + "preserveSymlinks": true // "sourceMap": true, // "declaration": true, @@ -42,8 +42,11 @@ "exclude": [ "./.meteor/**", "./packages/**", - "./imports/client", + "./imports/client" // "./ee/server/services/**" // "node_modules" - ] + ], + "ts-node": { + "files": true + } } diff --git a/typings.d.ts b/typings.d.ts deleted file mode 100644 index 2f202dc49b0a..000000000000 --- a/typings.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -declare module 'meteor/rocketchat:tap-i18n'; -declare module 'meteor/littledata:synced-cron'; -declare module 'meteor/promise'; -declare module 'meteor/ddp-common'; -declare module 'meteor/routepolicy'; -declare module 'meteor/logging'; -declare module 'xml-encryption'; -declare module 'webdav'; - -declare module 'meteor/konecty:user-presence' { - namespace UserPresenceMonitor { - function processUserSession(userSession: any, event: string): void; - } - - namespace UserPresence { - function removeConnectionsByInstanceId(id: string): void; - } -} - -declare const Package: { - 'disable-oplog': object; -}; - -declare module 'meteor/meteorhacks:inject-initial' { - namespace Inject { - function rawBody(key: string, value: string): void; - } -}