From 7aae6a868c1b4603226abdb7d3e53f08e8f9c333 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Date: Thu, 21 Mar 2024 14:00:10 -0300 Subject: [PATCH 1/4] fix --- apps/meteor/app/api/server/v1/settings.ts | 2 +- apps/meteor/app/apps/server/bridges/listeners.js | 1 + apps/meteor/app/authorization/lib/AuthorizationUtils.ts | 2 +- apps/meteor/app/cors/server/cors.ts | 3 +-- .../lib/server/functions/getAvatarSuggestionForUser.ts | 2 +- .../gazzodown/src/elements/Timestamp/ErrorBoundary.tsx | 6 +++--- packages/livechat/src/components/Composer/index.tsx | 8 ++++---- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/meteor/app/api/server/v1/settings.ts b/apps/meteor/app/api/server/v1/settings.ts index 011988f5ba2e..bccfc8d91fc7 100644 --- a/apps/meteor/app/api/server/v1/settings.ts +++ b/apps/meteor/app/api/server/v1/settings.ts @@ -106,7 +106,7 @@ API.v1.addRoute( { authRequired: true, twoFactorRequired: true }, { async post() { - if (!this.bodyParams.name || !this.bodyParams.name.trim()) { + if (!this.bodyParams.name?.trim()) { throw new Meteor.Error('error-name-param-not-provided', 'The parameter "name" is required'); } diff --git a/apps/meteor/app/apps/server/bridges/listeners.js b/apps/meteor/app/apps/server/bridges/listeners.js index b1ee4fd14521..ab2632c912b0 100644 --- a/apps/meteor/app/apps/server/bridges/listeners.js +++ b/apps/meteor/app/apps/server/bridges/listeners.js @@ -7,6 +7,7 @@ export class AppListenerBridge { } async handleEvent(event, ...payload) { + // eslint-disable-next-line complexity const method = (() => { switch (event) { case AppInterface.IPreMessageSentPrevent: diff --git a/apps/meteor/app/authorization/lib/AuthorizationUtils.ts b/apps/meteor/app/authorization/lib/AuthorizationUtils.ts index 41c96bd6fd3a..6ad5cab04720 100644 --- a/apps/meteor/app/authorization/lib/AuthorizationUtils.ts +++ b/apps/meteor/app/authorization/lib/AuthorizationUtils.ts @@ -31,7 +31,7 @@ export const AuthorizationUtils = class { } const rules = restrictedRolePermissions.get(roleId); - if (!rules || !rules.size) { + if (!rules?.size) { return false; } diff --git a/apps/meteor/app/cors/server/cors.ts b/apps/meteor/app/cors/server/cors.ts index 2a862635e1cd..ad4b5633a62f 100644 --- a/apps/meteor/app/cors/server/cors.ts +++ b/apps/meteor/app/cors/server/cors.ts @@ -7,7 +7,6 @@ import { Logger } from '@rocket.chat/logger'; import { Meteor } from 'meteor/meteor'; import type { StaticFiles } from 'meteor/webapp'; import { WebApp, WebAppInternals } from 'meteor/webapp'; -import _ from 'underscore'; import { settings } from '../../settings/server'; @@ -158,7 +157,7 @@ WebApp.httpServer.addListener('request', (req, res, ...args) => { const isLocal = localhostRegexp.test(remoteAddress) && - (!req.headers['x-forwarded-for'] || _.all((req.headers['x-forwarded-for'] as string).split(','), localhostTest)); + (!req.headers['x-forwarded-for'] || (req.headers['x-forwarded-for'] as string).split(',').every(localhostTest)); // @ts-expect-error - `pair` is valid, but doesnt exists on types const isSsl = req.connection.pair || (req.headers['x-forwarded-proto'] && req.headers['x-forwarded-proto'].indexOf('https') !== -1); diff --git a/apps/meteor/app/lib/server/functions/getAvatarSuggestionForUser.ts b/apps/meteor/app/lib/server/functions/getAvatarSuggestionForUser.ts index a54704cf8862..2560d2f08b7d 100644 --- a/apps/meteor/app/lib/server/functions/getAvatarSuggestionForUser.ts +++ b/apps/meteor/app/lib/server/functions/getAvatarSuggestionForUser.ts @@ -167,7 +167,7 @@ export async function getAvatarSuggestionForUser( let blob = `data:${response.headers.get('content-type')};base64,`; blob += Buffer.from(await response.arrayBuffer()).toString('base64'); newAvatar.blob = blob; - newAvatar.contentType = response.headers.get('content-type')!; + newAvatar.contentType = response.headers.get('content-type') as string; validAvatars[avatar.service] = newAvatar; } } catch (error) { diff --git a/packages/gazzodown/src/elements/Timestamp/ErrorBoundary.tsx b/packages/gazzodown/src/elements/Timestamp/ErrorBoundary.tsx index 55ef57ad1dee..453853275f8a 100644 --- a/packages/gazzodown/src/elements/Timestamp/ErrorBoundary.tsx +++ b/packages/gazzodown/src/elements/Timestamp/ErrorBoundary.tsx @@ -1,4 +1,4 @@ -import { Component } from 'react'; +import React, { Component, ReactNode } from 'react'; export class ErrorBoundary extends Component<{ fallback: React.ReactNode }, { hasError: boolean }> { constructor(props: { fallback: React.ReactNode }) { @@ -6,11 +6,11 @@ export class ErrorBoundary extends Component<{ fallback: React.ReactNode }, { ha this.state = { hasError: false }; } - static getDerivedStateFromError() { + static getDerivedStateFromError(): { hasError: boolean } { return { hasError: true }; } - render() { + render(): ReactNode { if (this.state.hasError) { // You can render any custom fallback UI return this.props.fallback; diff --git a/packages/livechat/src/components/Composer/index.tsx b/packages/livechat/src/components/Composer/index.tsx index 2562a40debdc..30d38fc1f09e 100644 --- a/packages/livechat/src/components/Composer/index.tsx +++ b/packages/livechat/src/components/Composer/index.tsx @@ -26,7 +26,7 @@ const replaceCaret = (el: Element) => { const target = findLastTextNode(el); // do not move caret if element was not focused const isTargetFocused = document.activeElement === el; - if (target !== null && target.nodeValue !== null && isTargetFocused) { + if (target?.nodeValue != null && isTargetFocused) { const range = document.createRange(); const sel = window.getSelection(); range.setStart(target, target.nodeValue.length); @@ -241,7 +241,7 @@ export class Composer extends Component { } if (typeof win.getSelection !== 'undefined' && (win.getSelection()?.rangeCount ?? 0) > 0) { - const range = win.getSelection()!.getRangeAt(0); + const range = win.getSelection()?.getRangeAt(0) as Range; const preCaretRange = range.cloneRange(); preCaretRange.selectNodeContents(element); preCaretRange.setEnd(range.endContainer, range.endOffset); @@ -249,10 +249,10 @@ export class Composer extends Component { } if (doc.selection && doc.selection.type !== 'Control') { - const textRange = doc.selection.createRange!(); + const textRange = doc.selection.createRange?.(); const preCaretTextRange = doc.body.createTextRange?.(); preCaretTextRange?.moveToElementText?.(element); - preCaretTextRange?.setEndPoint?.('EndToEnd', textRange); + preCaretTextRange?.setEndPoint?.('EndToEnd', textRange as Range); return preCaretTextRange?.text?.length ?? 0; } From 3ff698e17d73532aa08a01d9770ee99f01269187 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Thu, 4 Apr 2024 10:23:09 -0300 Subject: [PATCH 2/4] Update packages/livechat/src/components/Composer/index.tsx Co-authored-by: Marcos Spessatto Defendi --- packages/livechat/src/components/Composer/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/livechat/src/components/Composer/index.tsx b/packages/livechat/src/components/Composer/index.tsx index 30d38fc1f09e..cc21a40eb06d 100644 --- a/packages/livechat/src/components/Composer/index.tsx +++ b/packages/livechat/src/components/Composer/index.tsx @@ -26,7 +26,7 @@ const replaceCaret = (el: Element) => { const target = findLastTextNode(el); // do not move caret if element was not focused const isTargetFocused = document.activeElement === el; - if (target?.nodeValue != null && isTargetFocused) { + if (target?.nodeValue !== null && isTargetFocused) { const range = document.createRange(); const sel = window.getSelection(); range.setStart(target, target.nodeValue.length); From 1d2361f1b2e90468947896424cd2b03e14e68441 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Date: Mon, 8 Apr 2024 15:24:47 -0300 Subject: [PATCH 3/4] fix typecheck Text -> Node --- packages/livechat/src/components/Composer/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/livechat/src/components/Composer/index.tsx b/packages/livechat/src/components/Composer/index.tsx index 30d38fc1f09e..56a380c5a137 100644 --- a/packages/livechat/src/components/Composer/index.tsx +++ b/packages/livechat/src/components/Composer/index.tsx @@ -6,9 +6,9 @@ import { createClassName } from '../../helpers/createClassName'; import { parse } from '../../helpers/parse'; import styles from './styles.scss'; -const findLastTextNode = (node: Node): Text | null => { +const findLastTextNode = (node: Node): Node | null => { if (node.nodeType === Node.TEXT_NODE) { - return node as Text; + return node; } const children = node.childNodes; for (let i = children.length - 1; i >= 0; i--) { From 5176521ceaf2d66bc3175b71b4dec63a7b2b8adf Mon Sep 17 00:00:00 2001 From: Tasso Date: Mon, 8 Apr 2024 19:15:16 -0300 Subject: [PATCH 4/4] Fix null check --- packages/livechat/src/components/Composer/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/livechat/src/components/Composer/index.tsx b/packages/livechat/src/components/Composer/index.tsx index 679f165a0cae..1f1ce3b7369d 100644 --- a/packages/livechat/src/components/Composer/index.tsx +++ b/packages/livechat/src/components/Composer/index.tsx @@ -26,7 +26,7 @@ const replaceCaret = (el: Element) => { const target = findLastTextNode(el); // do not move caret if element was not focused const isTargetFocused = document.activeElement === el; - if (target?.nodeValue !== null && isTargetFocused) { + if (!!target?.nodeValue && isTargetFocused) { const range = document.createRange(); const sel = window.getSelection(); range.setStart(target, target.nodeValue.length);