Skip to content

Commit 880c302

Browse files
UBERF-12966: Send messages from Gmail threads (#9657)
Signed-off-by: Artem Savchenko <[email protected]> Signed-off-by: Artyom Savchenko <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent fa0a0b6 commit 880c302

File tree

21 files changed

+782
-44
lines changed

21 files changed

+782
-44
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 28 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/gmail/pod-gmail/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@hcengineering/client": "^0.6.18",
6666
"@hcengineering/client-resources": "^0.6.27",
6767
"@hcengineering/communication-sdk-types": "^0.1.0",
68+
"@hcengineering/communication-rest-client": "^0.1.0",
6869
"@hcengineering/contact": "^0.6.24",
6970
"@hcengineering/kvs-client": "^0.6.0",
7071
"@hcengineering/mail-common": "^0.6.0",
@@ -77,6 +78,7 @@
7778
"@hcengineering/server-storage": "^0.6.0",
7879
"@hcengineering/server-token": "^0.6.11",
7980
"@hcengineering/integration-client": "^0.6.0",
81+
"@hcengineering/kafka": "^0.6.0",
8082
"cors": "^2.8.5",
8183
"dotenv": "~16.0.0",
8284
"express": "^4.21.2",

services/gmail/pod-gmail/src/__tests__/gmailClient.test.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ jest.mock('@hcengineering/core', () => {
3939
WorkspaceUuid: String,
4040
// Provide missing properties
4141
configUserAccountUuid: 'test-user-id',
42+
systemAccountUuid: 'system-user-id',
4243
core: {
4344
space: {
4445
Workspace: 'workspace'
4546
}
4647
},
48+
// Add toFindResult function to fix the import error
49+
toFindResult: jest.fn().mockImplementation((items: any[]) => ({
50+
items,
51+
total: items.length
52+
})),
53+
// Add withContext decorator mock
54+
withContext: jest.fn().mockImplementation((name: string) => {
55+
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
56+
return descriptor
57+
}
58+
}),
4759
TxOperations: jest.fn().mockImplementation(() => ({
4860
findAll: jest.fn().mockResolvedValue([]),
4961
findOne: jest.fn().mockResolvedValue(undefined),
@@ -60,7 +72,9 @@ jest.mock('@hcengineering/core', () => {
6072
})
6173

6274
jest.mock('@hcengineering/mail-common', () => ({
63-
createMessages: jest.fn().mockResolvedValue(undefined)
75+
createMessages: jest.fn().mockResolvedValue(undefined),
76+
getChannel: jest.fn().mockResolvedValue({ _id: 'test-channel-id' }),
77+
isSyncedMessage: jest.fn().mockReturnValue(false)
6478
}))
6579

6680
jest.mock('googleapis', () => ({
@@ -79,8 +93,12 @@ jest.mock('../tokens')
7993
jest.mock('../message/adapter')
8094
jest.mock('../message/sync')
8195
jest.mock('../message/attachments')
82-
jest.mock('@hcengineering/server-client', () => ({
83-
getAccountClient: jest.fn()
96+
jest.mock('@hcengineering/server-core', () => ({
97+
withContext: jest.fn().mockImplementation((name: string) => {
98+
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
99+
return descriptor
100+
}
101+
})
84102
}))
85103
jest.mock('../accounts', () => ({
86104
getOrCreateSocialId: jest.fn().mockResolvedValue({ _id: 'test-social-id' })
@@ -89,7 +107,7 @@ jest.mock('../gmail/utils', () => ({
89107
getEmail: jest.fn().mockResolvedValue('[email protected]')
90108
}))
91109
jest.mock('../integrations', () => ({
92-
createIntegrationIfNotEsixts: jest.fn().mockResolvedValue({ _id: 'test-integration-id' }),
110+
createIntegrationIfNotExists: jest.fn().mockResolvedValue({ _id: 'test-integration-id' }),
93111
disableIntegration: jest.fn(),
94112
removeIntegration: jest.fn()
95113
}))
@@ -133,6 +151,15 @@ jest.mock('@hcengineering/account-client', () => ({
133151
endpoint: 'wss://test-endpoint.com',
134152
workspace: 'mockWorkspaceId',
135153
token: 'test-token'
154+
}),
155+
getPersonInfo: jest.fn().mockResolvedValue({
156+
socialIds: [
157+
{
158+
_id: 'test-social-id',
159+
160+
type: 'email'
161+
}
162+
]
136163
})
137164
})),
138165
isWorkspaceLoginInfo: jest.fn().mockImplementation(() => true)

services/gmail/pod-gmail/src/client.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,33 @@
1414
// limitations under the License.
1515
//
1616

17-
import { type Client } from '@hcengineering/core'
17+
import { WorkspaceUuid, type Client } from '@hcengineering/core'
1818
import { createClient, getTransactorEndpoint } from '@hcengineering/server-client'
19+
import { generateToken } from '@hcengineering/server-token'
20+
import { systemAccountUuid } from '@hcengineering/core'
21+
import {
22+
createRestClient as createCommunicationRestClient,
23+
RestClient as CommunicationRestClient
24+
} from '@hcengineering/communication-rest-client'
1925

2026
export async function getClient (token: string): Promise<Client> {
2127
const endpoint = await getTransactorEndpoint(token)
2228
console.log('connecting to', endpoint)
2329
return await createClient(endpoint, token)
2430
}
31+
32+
export async function getCommunicationClient (workspace: WorkspaceUuid): Promise<CommunicationRestClient> {
33+
const token = generateToken(systemAccountUuid, workspace, { service: 'gmail' })
34+
const endpoint = toHttpUrl(await getTransactorEndpoint(token))
35+
return createCommunicationRestClient(endpoint, workspace, token)
36+
}
37+
38+
function toHttpUrl (url: string): string {
39+
if (url.startsWith('ws://')) {
40+
return url.replace('ws://', 'http://')
41+
}
42+
if (url.startsWith('wss://')) {
43+
return url.replace('wss://', 'https://')
44+
}
45+
return url
46+
}

0 commit comments

Comments
 (0)