diff --git a/apps/meteor/app/livechat/client/ui.js b/apps/meteor/app/livechat/client/ui.ts similarity index 100% rename from apps/meteor/app/livechat/client/ui.js rename to apps/meteor/app/livechat/client/ui.ts diff --git a/apps/meteor/app/livechat/imports/server/rest/sms.js b/apps/meteor/app/livechat/imports/server/rest/sms.js index 9d2bee13378421b88f415d5916a759ba15c40981..117407807dad567d2ea1fd21082a3b71f833c315 100644 --- a/apps/meteor/app/livechat/imports/server/rest/sms.js +++ b/apps/meteor/app/livechat/imports/server/rest/sms.js @@ -1,5 +1,6 @@ import { OmnichannelIntegration } from '@rocket.chat/core-services'; import { OmnichannelSourceType } from '@rocket.chat/core-typings'; +import { Logger } from '@rocket.chat/logger'; import { LivechatVisitors, LivechatRooms, LivechatDepartment } from '@rocket.chat/models'; import { Random } from '@rocket.chat/random'; import { serverFetch as fetch } from '@rocket.chat/server-fetch'; @@ -8,9 +9,10 @@ import { Meteor } from 'meteor/meteor'; import { API } from '../../../../api/server'; import { FileUpload } from '../../../../file-upload/server'; import { settings } from '../../../../settings/server'; -import { Livechat } from '../../../server/lib/Livechat'; import { Livechat as LivechatTyped } from '../../../server/lib/LivechatTyped'; +const logger = new Logger('SMS'); + const getUploadFile = async (details, fileUrl) => { const response = await fetch(fileUrl); @@ -156,7 +158,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', { attachment.title_link_download = true; } } catch (err) { - Livechat.logger.error({ msg: 'Attachment upload failed', err }); + logger.error({ msg: 'Attachment upload failed', err }); attachment = { fields: [ { diff --git a/apps/meteor/app/livechat/server/api/v1/webhooks.ts b/apps/meteor/app/livechat/server/api/v1/webhooks.ts index e282e2bd548ba0e318bbf915685336cb6cc41344..af7c97d5145cbd1e4ec375a0614d4130751c1505 100644 --- a/apps/meteor/app/livechat/server/api/v1/webhooks.ts +++ b/apps/meteor/app/livechat/server/api/v1/webhooks.ts @@ -1,8 +1,10 @@ +import { Logger } from '@rocket.chat/logger'; import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { API } from '../../../../api/server'; import { settings } from '../../../../settings/server'; -import { Livechat } from '../../lib/Livechat'; + +const logger = new Logger('WebhookTest'); API.v1.addRoute( 'livechat/webhook.test', @@ -70,18 +72,18 @@ API.v1.addRoute( } try { - Livechat.logger.debug(`Testing webhook ${webhookUrl}`); + logger.debug(`Testing webhook ${webhookUrl}`); const request = await fetch(webhookUrl, options); const response = await request.text(); - Livechat.logger.debug({ response }); + logger.debug({ response }); if (request.status === 200) { return API.v1.success(); } throw new Error('Invalid status code'); } catch (error) { - Livechat.logger.error(`Error testing webhook: ${error}`); + logger.error(`Error testing webhook: ${error}`); throw new Error('error-invalid-webhook-response'); } }, diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index 06ad84ec49ac5d87c5933a31359da21133a1b1c9..7b650f5b2963d98f800404d50f88d30e7dd86502 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -76,5 +76,3 @@ import './api'; import './api/rest'; import './externalFrame'; import './methods/saveBusinessHour'; - -export { Livechat } from './lib/Livechat'; diff --git a/apps/meteor/app/livechat/server/lib/Helper.ts b/apps/meteor/app/livechat/server/lib/Helper.ts index 78351cdc66832d058c7bef2ec567342ba33fc7e6..f360004fc77efda7963cf934065fffe0faa762ae 100644 --- a/apps/meteor/app/livechat/server/lib/Helper.ts +++ b/apps/meteor/app/livechat/server/lib/Helper.ts @@ -38,7 +38,6 @@ import { hasRoleAsync } from '../../../authorization/server/functions/hasRole'; import { sendNotification } from '../../../lib/server'; import { sendMessage } from '../../../lib/server/functions/sendMessage'; import { settings } from '../../../settings/server'; -import { Livechat } from './Livechat'; import { Livechat as LivechatTyped } from './LivechatTyped'; import { queueInquiry, saveQueueInquiry } from './QueueManager'; import { RoutingManager } from './RoutingManager'; @@ -296,7 +295,7 @@ export const parseAgentCustomFields = (customFields?: Record<string, any>) => { const parseCustomFields = JSON.parse(accountCustomFields); return Object.keys(parseCustomFields).filter((customFieldKey) => parseCustomFields[customFieldKey].sendToIntegrations === true); } catch (error) { - Livechat.logger.error(error); + logger.error(error); return []; } }; diff --git a/apps/meteor/app/livechat/server/lib/Livechat.js b/apps/meteor/app/livechat/server/lib/Livechat.js deleted file mode 100644 index a47d472f289b31ebf82a3378c9a0e404a3c26cdf..0000000000000000000000000000000000000000 --- a/apps/meteor/app/livechat/server/lib/Livechat.js +++ /dev/null @@ -1,9 +0,0 @@ -// Note: Please don't add any new methods to this file, since its still in js and we are migrating to ts -// Please add new methods to LivechatTyped.ts -import { Logger } from '@rocket.chat/logger'; - -const logger = new Logger('Livechat'); - -export const Livechat = { - logger, -}; diff --git a/apps/meteor/app/livechat/server/methods/getAgentOverviewData.ts b/apps/meteor/app/livechat/server/methods/getAgentOverviewData.ts index 182cd238ec9e89d746db20ba55b1b16ba0df81ec..b5ea8dafe92ca9621d5a0fa77c6a94e08ac29ea1 100644 --- a/apps/meteor/app/livechat/server/methods/getAgentOverviewData.ts +++ b/apps/meteor/app/livechat/server/methods/getAgentOverviewData.ts @@ -6,7 +6,6 @@ import { Meteor } from 'meteor/meteor'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; -import { Livechat } from '../lib/Livechat'; declare module '@rocket.chat/ui-contexts' { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -27,7 +26,6 @@ Meteor.methods<ServerMethods>({ } if (!options.chartOptions?.name) { - Livechat.logger.warn('Incorrect analytics options'); return; } diff --git a/apps/meteor/app/livechat/server/methods/getAnalyticsChartData.ts b/apps/meteor/app/livechat/server/methods/getAnalyticsChartData.ts index b5b1003969f8c4eb29abe4554441f8968b5b626b..85c8e033b8f5eb8536001c8f9b1d1f85605b58b0 100644 --- a/apps/meteor/app/livechat/server/methods/getAnalyticsChartData.ts +++ b/apps/meteor/app/livechat/server/methods/getAnalyticsChartData.ts @@ -5,7 +5,6 @@ import type { ServerMethods } from '@rocket.chat/ui-contexts'; import { Meteor } from 'meteor/meteor'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; -import { Livechat } from '../lib/Livechat'; declare module '@rocket.chat/ui-contexts' { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -24,14 +23,12 @@ Meteor.methods<ServerMethods>({ } if (!options.chartOptions?.name) { - Livechat.logger.error('Incorrect chart options'); return; } const user = await Users.findOneById(userId, { projection: { _id: 1, utcOffset: 1 } }); if (!user) { - Livechat.logger.error('User not found'); return; } diff --git a/apps/meteor/app/livechat/server/methods/getAnalyticsOverviewData.ts b/apps/meteor/app/livechat/server/methods/getAnalyticsOverviewData.ts index 81fe2658301ae246fe3165258c7b9d6af226f68e..c9bb3d163457bc1c0a3151e261805109ed8a604f 100644 --- a/apps/meteor/app/livechat/server/methods/getAnalyticsOverviewData.ts +++ b/apps/meteor/app/livechat/server/methods/getAnalyticsOverviewData.ts @@ -7,7 +7,6 @@ import { Meteor } from 'meteor/meteor'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; import { settings } from '../../../settings/server'; -import { Livechat } from '../lib/Livechat'; declare module '@rocket.chat/ui-contexts' { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -27,7 +26,6 @@ Meteor.methods<ServerMethods>({ } if (!options.analyticsOptions?.name) { - Livechat.logger.error('Incorrect analytics options'); return; } diff --git a/apps/meteor/app/livechat/server/methods/removeAllClosedRooms.ts b/apps/meteor/app/livechat/server/methods/removeAllClosedRooms.ts index 149cd0a5c5c98555cec03999231a6aeabf29ea48..9be699ae05ed70cf8e8b43fe6be2f31a2ffb4386 100644 --- a/apps/meteor/app/livechat/server/methods/removeAllClosedRooms.ts +++ b/apps/meteor/app/livechat/server/methods/removeAllClosedRooms.ts @@ -1,4 +1,5 @@ import type { IOmnichannelRoom } from '@rocket.chat/core-typings'; +import { Logger } from '@rocket.chat/logger'; import { LivechatRooms } from '@rocket.chat/models'; import type { ServerMethods } from '@rocket.chat/ui-contexts'; import { Meteor } from 'meteor/meteor'; @@ -16,6 +17,7 @@ declare module '@rocket.chat/ui-contexts' { Meteor.methods<ServerMethods>({ async 'livechat:removeAllClosedRooms'(departmentIds) { + const logger = new Logger('livechat:removeAllClosedRooms'); const user = Meteor.userId(); if (!user || !(await hasPermissionAsync(user, 'remove-closed-livechat-rooms'))) { @@ -25,7 +27,7 @@ Meteor.methods<ServerMethods>({ } // These are not debug logs since we want to know when the action is performed - Livechat.logger.info(`User ${Meteor.userId()} is removing all closed rooms`); + logger.info(`User ${Meteor.userId()} is removing all closed rooms`); const extraQuery = await callbacks.run('livechat.applyRoomRestrictions', {}); const promises: Promise<void>[] = []; @@ -34,7 +36,7 @@ Meteor.methods<ServerMethods>({ }); await Promise.all(promises); - Livechat.logger.info(`User ${Meteor.userId()} removed ${promises.length} closed rooms`); + logger.info(`User ${Meteor.userId()} removed ${promises.length} closed rooms`); return promises.length; }, }); diff --git a/apps/meteor/app/livechat/server/startup.ts b/apps/meteor/app/livechat/server/startup.ts index c8487f742b3aa7b5486bf2e57eb45361d65c8591..3ea87f3d568fe903bd7c5f604c584e4e7bd6d459 100644 --- a/apps/meteor/app/livechat/server/startup.ts +++ b/apps/meteor/app/livechat/server/startup.ts @@ -1,5 +1,6 @@ import type { IUser } from '@rocket.chat/core-typings'; import { ILivechatAgentStatus, isOmnichannelRoom } from '@rocket.chat/core-typings'; +import { Logger } from '@rocket.chat/logger'; import { LivechatRooms } from '@rocket.chat/models'; import { Accounts } from 'meteor/accounts-base'; import { Meteor } from 'meteor/meteor'; @@ -12,12 +13,13 @@ import { hasPermissionAsync } from '../../authorization/server/functions/hasPerm import { settings } from '../../settings/server'; import { businessHourManager } from './business-hour'; import { createDefaultBusinessHourIfNotExists } from './business-hour/Helper'; -import { Livechat } from './lib/Livechat'; import { Livechat as LivechatTyped } from './lib/LivechatTyped'; import { RoutingManager } from './lib/RoutingManager'; import { LivechatAgentActivityMonitor } from './statistics/LivechatAgentActivityMonitor'; import './roomAccessValidator.internalService'; +const logger = new Logger('LivechatStartup'); + Meteor.startup(async () => { roomCoordinator.setRoomFind('l', (_id) => LivechatRooms.findOneById(_id)); @@ -63,7 +65,7 @@ Meteor.startup(async () => { await createDefaultBusinessHourIfNotExists(); settings.watch<boolean>('Livechat_enable_business_hours', async (value) => { - Livechat.logger.info(`Changing business hour type to ${value}`); + logger.info(`Changing business hour type to ${value}`); if (value) { await businessHourManager.startManager(); return;