diff --git a/.changeset/soft-ducks-build.md b/.changeset/soft-ducks-build.md new file mode 100644 index 000000000000..73e08863d22d --- /dev/null +++ b/.changeset/soft-ducks-build.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': major +--- + +Removes deprecated method `livechat:registerAgent`. Moving forward, use the endpoint `livechat/visitor`. diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index ffe164bc8872..13a1cf7407a9 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -21,7 +21,6 @@ import './methods/changeLivechatStatus'; import './methods/closeRoom'; import './methods/getAnalyticsChartData'; import './methods/getRoutingConfig'; -import './methods/registerGuest'; import './methods/removeAllClosedRooms'; import './methods/removeCustomField'; import './methods/removeRoom'; diff --git a/apps/meteor/app/livechat/server/methods/registerGuest.ts b/apps/meteor/app/livechat/server/methods/registerGuest.ts deleted file mode 100644 index c6a119d91591..000000000000 --- a/apps/meteor/app/livechat/server/methods/registerGuest.ts +++ /dev/null @@ -1,96 +0,0 @@ -import type { ILivechatVisitor, IRoom } from '@rocket.chat/core-typings'; -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { LivechatVisitors, Messages, LivechatRooms } from '@rocket.chat/models'; -import { Meteor } from 'meteor/meteor'; - -import { callbacks } from '../../../../lib/callbacks'; -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; -import { Livechat as LivechatTyped } from '../lib/LivechatTyped'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'livechat:registerGuest'({ - token, - name, - email, - department, - customFields, - }?: { - token?: string; - name?: string; - email?: string; - department?: string; - customFields?: Array<{ key: string; value: string; overwrite: boolean; scope?: unknown }>; - }): { - userId: ILivechatVisitor['_id']; - visitor: Pick; - }; - } -} - -Meteor.methods({ - async 'livechat:registerGuest'({ token, name, email, department, customFields } = {}): Promise<{ - userId: ILivechatVisitor['_id']; - visitor: Pick; - }> { - methodDeprecationLogger.method('livechat:registerGuest', '7.0.0'); - - if (!token) { - throw new Meteor.Error('error-invalid-token', 'Invalid token', { method: 'livechat:registerGuest' }); - } - - const visitor = await LivechatTyped.registerGuest.call(this, { - token, - name, - email, - department, - }); - - // update visited page history to not expire - await Messages.keepHistoryForToken(token); - - if (!visitor) { - throw new Meteor.Error('error-invalid-visitor', 'Invalid visitor', { method: 'livechat:registerGuest' }); - } - - const extraQuery = await callbacks.run('livechat.applyRoomRestrictions', {}); - // If it's updating an existing visitor, it must also update the roomInfo - const rooms: IRoom[] = await LivechatRooms.findOpenByVisitorToken(token, {}, extraQuery).toArray(); - await Promise.all( - rooms.map((room) => - LivechatTyped.saveRoomInfo(room, { - _id: visitor._id, - name: visitor.name, - phone: visitor.phone?.[0]?.phoneNumber, - livechatData: visitor.livechatData as { [k: string]: string }, - }), - ), - ); - - if (customFields && customFields instanceof Array) { - for await (const customField of customFields) { - if (typeof customField !== 'object') { - continue; - } - - if (!customField.scope || customField.scope !== 'room') { - const { key, value, overwrite } = customField; - await LivechatVisitors.updateLivechatDataByToken(token, key, value, overwrite); - } - } - } - - return { - userId: visitor._id, - visitor: { - _id: visitor._id, - token: visitor.token, - name: visitor.name, - username: visitor.username, - visitorEmails: visitor.visitorEmails, - department: visitor.department, - }, - }; - }, -}); diff --git a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts index 31134412b8ec..d3a40999314c 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts @@ -5,7 +5,7 @@ import { before, describe, it, after } from 'mocha'; import moment from 'moment'; import { type Response } from 'supertest'; -import { getCredentials, api, request, credentials, methodCallAnon } from '../../../data/api-data'; +import { getCredentials, api, request, credentials } from '../../../data/api-data'; import { createCustomField, deleteCustomField } from '../../../data/livechat/custom-fields'; import { makeAgentAvailable, @@ -226,19 +226,14 @@ describe('LIVECHAT - visitors', () => { await updateSetting('Livechat_Allow_collect_and_store_HTTP_header_informations', false); }); - // Note: this had to use the meteor method because the endpoint used `req.headers` which we cannot send as empty - // method doesn't pass them to the func allowing us to create a test for it it('should allow to create a visitor without passing connectionData when GDPR setting is enabled', async () => { const token = `${new Date().getTime()}-test`; - const response = await request - .post(methodCallAnon('livechat:registerGuest')) - .send({ message: `{"msg":"method","id":"23","method":"livechat:registerGuest","params":[{ "token": "${token}"}]}` }); - expect(response.body).to.have.property('success', true); - const r = JSON.parse(response.body.message); + const { body } = await request.post(api('livechat/visitor')).send({ visitor: { token } }); - expect(r.result).to.have.property('visitor'); - expect(r.result.visitor).to.have.property('token', token); + expect(body).to.have.property('success', true); + expect(body).to.have.property('visitor'); + expect(body.visitor).to.have.property('token', token); }); }); });