Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{
"pattern": "apps/*",
"changeProcessCWD": true
},
{
"pattern": "ee/apps/*",
"changeProcessCWD": true
}
],
"typescript.tsdk": "./node_modules/typescript/lib",
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/.scripts/run-ha.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn, SpawnOptions } from 'child_process';
import type { SpawnOptions } from 'child_process';
import { spawn } from 'child_process';
import * as path from 'path';

enum ModeParam {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/code/EmailCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { IUser } from '@rocket.chat/core-typings';
import { settings } from '../../../settings/server';
import * as Mailer from '../../../mailer';
import { Users } from '../../../models/server';
import { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';
import type { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';

export class EmailCheck implements ICodeCheck {
public readonly name = 'email';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/code/PasswordCheckFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Accounts } from 'meteor/accounts-base';
import type { IUser } from '@rocket.chat/core-typings';

import { settings } from '../../../settings/server';
import { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';
import type { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';

export class PasswordCheckFallback implements ICodeCheck {
public readonly name = 'password';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/code/TOTPCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IUser } from '@rocket.chat/core-typings';

import { TOTP } from '../lib/totp';
import { settings } from '../../../settings/server';
import { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';
import type { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';

export class TOTPCheck implements ICodeCheck {
public readonly name = 'totp';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/server/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { settings } from '../../../settings/server';
import { TOTPCheck } from './TOTPCheck';
import { EmailCheck } from './EmailCheck';
import { PasswordCheckFallback } from './PasswordCheckFallback';
import { ICodeCheck } from './ICodeCheck';
import type { ICodeCheck } from './ICodeCheck';
import { Users } from '../../../models/server';

export interface ITwoFactorOptions {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/2fa/server/twoFactorRequired.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';

import { checkCodeForUser, ITwoFactorOptions } from './code/index';
import type { ITwoFactorOptions } from './code/index';
import { checkCodeForUser } from './code/index';

export function twoFactorRequired<TFunction extends (this: Meteor.MethodThisType, ...args: any[]) => any>(
fn: TFunction,
Expand Down
16 changes: 11 additions & 5 deletions apps/meteor/app/action-links/client/lib/actionLinks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Meteor } from 'meteor/meteor';
import { IMessage } from '@rocket.chat/core-typings';
import type { IMessage } from '@rocket.chat/core-typings';

import { handleError } from '../../../../client/lib/utils/handleError';

// Action Links namespace creation.
export const actionLinks = {
actions: new Map<string, Function>(),
register(name: string, fn: Function): void {
actions: new Map<
string,
(message: IMessage, params: string, instance?: Blaze.TemplateInstance | ((actionId: string, context: string) => void)) => void
>(),
register(
name: string,
fn: (message: IMessage, params: string, instance?: Blaze.TemplateInstance | ((actionId: string, context: string) => void)) => void,
): void {
actionLinks.actions.set(name, fn);
},
// getMessage(name, messageId) {
Expand Down Expand Up @@ -42,8 +48,8 @@ export const actionLinks = {

// return message;
// },
run(method: string, message: IMessage, instance?: Blaze.TemplateInstance | Function): void {
const actionLink = message.actionLinks && message.actionLinks.find((action) => action.method_id === method);
run(method: string, message: IMessage, instance?: Blaze.TemplateInstance | ((actionId: string, context: string) => void)): void {
const actionLink = message.actionLinks?.find((action) => action.method_id === method);

if (!actionLink) {
throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/action-links/server/lib/actionLinks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IMessage } from '@rocket.chat/core-typings';
import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { getMessageForUser } from '../../../../server/lib/messages/getMessageForUser';
Expand Down
11 changes: 6 additions & 5 deletions apps/meteor/app/api/server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { IUser, IMethodConnection, IRoom } from '@rocket.chat/core-typings'
import type { ValidateFunction } from 'ajv';
import type { Request, Response } from 'express';

import { ITwoFactorOptions } from '../../2fa/server/code';
import type { ITwoFactorOptions } from '../../2fa/server/code';

type SuccessResult<T> = {
statusCode: 200;
Expand All @@ -28,8 +28,8 @@ type FailureResult<T, TStack = undefined, TErrorType = undefined, TErrorDetails
stack: TStack;
errorType: TErrorType;
details: TErrorDetails;
} & (undefined extends TErrorType ? {} : { errorType: TErrorType }) &
(undefined extends TErrorDetails ? {} : { details: TErrorDetails extends string ? unknown : TErrorDetails });
} & (undefined extends TErrorType ? object : { errorType: TErrorType }) &
(undefined extends TErrorDetails ? object : { details: TErrorDetails extends string ? unknown : TErrorDetails });
};

type UnauthorizedResult<T> = {
Expand Down Expand Up @@ -80,7 +80,7 @@ type PartialThis = {
type UserInfo = IUser & {
email?: string;
settings: {
profile: {};
profile: object;
preferences: unknown;
};
avatarUrl: string;
Expand Down Expand Up @@ -167,7 +167,7 @@ type Operation<TMethod extends Method, TPathPattern extends PathPattern, TEndpoi
action: Action<TMethod, TPathPattern, TEndpointOptions>;
} & { twoFactorRequired: boolean });

type Operations<TPathPattern extends PathPattern, TOptions extends Options = {}> = {
type Operations<TPathPattern extends PathPattern, TOptions extends Options = object> = {
[M in MethodOf<TPathPattern> as Lowercase<M>]: Operation<Uppercase<M>, TPathPattern, TOptions>;
};

Expand Down Expand Up @@ -252,6 +252,7 @@ export declare const API: {
v1: APIClass<'/v1'>;
default: APIClass;
helperMethods: Map<string, (...args: any[]) => unknown>;
ApiClass: APIClass;
};

export declare const defaultRateLimiterOptions: {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/helpers/addUserToFileObj.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IUpload, IUser } from '@rocket.chat/core-typings';
import type { IUpload, IUser } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';

export async function addUserToFileObj(files: IUpload[]): Promise<(IUpload & { user?: Pick<IUser, '_id' | 'name' | 'username'> })[]> {
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/api/server/helpers/getUserFromParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ API.helperMethods.set('getUserFromParams', function _getUserFromParams(this: any
let user;
const params = this.requestParams();

if (params.userId && params.userId.trim()) {
if (params.userId?.trim()) {
user = Users.findOneById(params.userId) || doesntExist;
} else if (params.username && params.username.trim()) {
} else if (params.username?.trim()) {
user = Users.findOneByUsernameIgnoringCase(params.username) || doesntExist;
} else if (params.user && params.user.trim()) {
} else if (params.user?.trim()) {
user = Users.findOneByUsernameIgnoringCase(params.user) || doesntExist;
} else {
throw new Meteor.Error('error-user-param-not-provided', 'The required "userId" or "username" param was not provided');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/helpers/getUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getUserPreferences = (me: IUser): Record<string, unknown> => {
API.helperMethods.set('getUserInfo', function _getUserInfo(me: IUser) {
const verifiedEmail = isVerifiedEmail(me);

const userPreferences = (me.settings && me.settings.preferences) || {};
const userPreferences = me.settings?.preferences ?? {};

return {
...me,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/helpers/isWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse } from 'cookie';
import { API } from '../api';

API.helperMethods.set('isWidget', function _isWidget() {
// @ts-expect-error
// @ts-expect-error 'this' implicitly has type 'any' because it does not have a type annotation.
const { headers } = this.request;

const { rc_room_type: roomType, rc_is_widget: isWidget } = parse(headers.cookie || '');
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/app/api/server/lib/emailInbox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEmailInbox } from '@rocket.chat/core-typings';
import { InsertOneResult, UpdateResult, WithId } from 'mongodb';
import type { IEmailInbox } from '@rocket.chat/core-typings';
import type { Filter, InsertOneResult, Sort, UpdateResult, WithId } from 'mongodb';
import { EmailInbox } from '@rocket.chat/models';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
Expand All @@ -11,11 +11,11 @@ export const findEmailInboxes = async ({
pagination: { offset, count, sort },
}: {
userId: string;
query?: {};
query?: Filter<IEmailInbox>;
pagination: {
offset: number;
count: number;
sort?: {};
sort?: Sort;
};
}): Promise<{
emailInboxes: IEmailInbox[];
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/lib/emoji-custom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEmojiCustom } from '@rocket.chat/core-typings';
import { Filter, FindOptions } from 'mongodb';
import type { IEmojiCustom } from '@rocket.chat/core-typings';
import type { Filter, FindOptions } from 'mongodb';
import { EmojiCustom } from '@rocket.chat/models';

export async function findEmojisCustom({
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/lib/getUploadFormData.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Readable } from 'stream';
import type { Readable } from 'stream';

import { Meteor } from 'meteor/meteor';
import type { Request } from 'express';
import busboy from 'busboy';
import { ValidateFunction } from 'ajv';
import type { ValidateFunction } from 'ajv';

type UploadResult = {
file: Readable;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/lib/rooms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IRoom, ISubscription } from '@rocket.chat/core-typings';
import type { IRoom, ISubscription } from '@rocket.chat/core-typings';
import { Rooms } from '@rocket.chat/models';

import { hasPermissionAsync, hasAtLeastOnePermissionAsync } from '../../../authorization/server/functions/hasPermission';
Expand Down
13 changes: 6 additions & 7 deletions apps/meteor/app/api/server/lib/users.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { IUser } from '@rocket.chat/core-typings';
import { Filter } from 'mongodb';
import type { IUser } from '@rocket.chat/core-typings';
import type { Filter } from 'mongodb';
import { Users } from '@rocket.chat/models';
import type { Mongo } from 'meteor/mongo';

Expand Down Expand Up @@ -53,9 +53,8 @@ export async function findUsersToAutocomplete({

/**
* Returns a new query object with the inclusive fields only
* @param {Object} query search query for matching rows
*/
export function getInclusiveFields(query: { [k: string]: 1 }): {} {
export function getInclusiveFields(query: Record<string, 1 | 0>): Record<string, 1> {
const newQuery = Object.create(null);

for (const [key, value] of Object.entries(query)) {
Expand All @@ -69,9 +68,9 @@ export function getInclusiveFields(query: { [k: string]: 1 }): {} {

/**
* get the default fields if **fields** are empty (`{}`) or `undefined`/`null`
* @param {Object|null|undefined} fields the fields from parsed jsonQuery
* @param fields the fields from parsed jsonQuery
*/
export function getNonEmptyFields(fields: { [k: string]: 1 | 0 }): { [k: string]: 1 } {
export function getNonEmptyFields(fields: Record<string, 1 | 0>): Record<string, 1 | 0> {
const defaultFields = {
name: 1,
username: 1,
Expand All @@ -93,7 +92,7 @@ export function getNonEmptyFields(fields: { [k: string]: 1 | 0 }): { [k: string]

/**
* get the default query if **query** is empty (`{}`) or `undefined`/`null`
* @param {Object|null|undefined} query the query from parsed jsonQuery
* @param query the query from parsed jsonQuery
*/
export function getNonEmptyQuery<T extends IUser>(query: Mongo.Query<T> | undefined | null, canSeeAllUserInfo?: boolean): Mongo.Query<T> {
const defaultQuery: Mongo.Query<IUser> = {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/middlewares/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response, NextFunction } from 'express';
import type { Request, Response, NextFunction } from 'express';

import { Users } from '../../../models/server';
import { oAuth2ServerAuth } from '../../../oauth2-server-config/server/oauth/oauth2-server';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ API.v1.addRoute(
fields: { 'u._id': 1 },
});

const members = subscriptions.fetch().map((s: ISubscription) => s.u && s.u._id);
const members = subscriptions.fetch().map((s: ISubscription) => s.u?._id);

const teamData = {
team: {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ise2eSetUserPublicAndPrivateKeysParamsPOST,
ise2eUpdateGroupKeyParamsPOST,
} from '@rocket.chat/rest-typings';
import { IUser } from '@rocket.chat/core-typings';
import type { IUser } from '@rocket.chat/core-typings';

import { API } from '../api';

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/integrations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { IIntegration } from '@rocket.chat/core-typings';
import type { IIntegration } from '@rocket.chat/core-typings';
import {
isIntegrationsCreateProps,
isIntegrationsHistoryProps,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/invites.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-hooks/rules-of-hooks */
import { IInvite } from '@rocket.chat/core-typings';
import type { IInvite } from '@rocket.chat/core-typings';
import { isFindOrCreateInviteParams, isUseInviteTokenProps, isValidateInviteTokenProps } from '@rocket.chat/rest-typings';

import { API } from '../api';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
isMethodCallAnonProps,
isMeteorCall,
} from '@rocket.chat/rest-typings';
import { IUser } from '@rocket.chat/core-typings';
import type { IUser } from '@rocket.chat/core-typings';

import { hasPermission } from '../../../authorization/server';
import { Users } from '../../../models/server';
Expand Down
6 changes: 4 additions & 2 deletions apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { ServiceConfiguration } from 'meteor/service-configuration';
import _ from 'underscore';
import { ISetting, ISettingColor, isSettingAction, isSettingColor } from '@rocket.chat/core-typings';
import type { ISetting, ISettingColor } from '@rocket.chat/core-typings';
import { isSettingAction, isSettingColor } from '@rocket.chat/core-typings';
import {
isOauthCustomConfiguration,
isSettingsUpdatePropDefault,
Expand All @@ -12,7 +13,8 @@ import { Settings } from '@rocket.chat/models';
import type { FindOptions } from 'mongodb';

import { hasPermission } from '../../../authorization/server';
import { API, ResultFor } from '../api';
import type { ResultFor } from '../api';
import { API } from '../api';
import { SettingsEvents, settings } from '../../../settings/server';
import { setValue } from '../../../settings/server/raw';

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/v1/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ API.v1.addRoute(
},
{
async get() {
const { roomId }: { [roomId: string]: {} } | Record<string, string> = this.queryParams;
const { roomId } = this.queryParams;

if (!roomId) {
return API.v1.failure("The 'roomId' param is required");
}

return API.v1.success({
subscription: await Subscriptions.findOneByRoomIdAndUserId(roomId as string, this.userId),
subscription: await Subscriptions.findOneByRoomIdAndUserId(roomId, this.userId),
});
},
},
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
isTeamsLeaveProps,
isTeamsUpdateProps,
} from '@rocket.chat/rest-typings';
import { ITeam, TEAM_TYPE } from '@rocket.chat/core-typings';
import type { ITeam } from '@rocket.chat/core-typings';
import { TEAM_TYPE } from '@rocket.chat/core-typings';

import { removeUserFromRoom } from '../../../lib/server/functions/removeUserFromRoom';
import { Users } from '../../../models/server';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { Match, check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { IExportOperation, IPersonalAccessToken, IUser } from '@rocket.chat/core-typings';
import type { IExportOperation, IPersonalAccessToken, IUser } from '@rocket.chat/core-typings';
import { Users as UsersRaw } from '@rocket.chat/models';

import { Users, Subscriptions } from '../../../models/server';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/voip/omnichannel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Match, check } from 'meteor/check';
import { IUser, IVoipExtensionWithAgentInfo } from '@rocket.chat/core-typings';
import type { IUser, IVoipExtensionWithAgentInfo } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';

import { API } from '../../api';
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/apps/client/@types/IOrchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ISetting } from '@rocket.chat/apps-engine/definition/settings/ISetting';
import { App } from '@rocket.chat/core-typings';
import type { ISetting } from '@rocket.chat/apps-engine/definition/settings/ISetting';
import type { App } from '@rocket.chat/core-typings';

export interface IDetailedDescription {
raw: string;
Expand Down
Loading