Skip to content

Commit 7e92c12

Browse files
UBERF-11414: Integrations (#9610)
* UBERF-11414: Use common integration kind Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Allow multiple gmail Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Merge with develop Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Refactor integration kinds Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Add integrations package Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Integrations Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Integration state and config Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Add integration events Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Refresh integration states Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Rename to integration-client Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Add filter button Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Add translations for filters Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Synced channels count Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Actions Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Add isLoading for connect Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Create connection and integration Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Use social id from hulygram Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Remove old integrations Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Gmail state Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Gmail state and disconnect all handler Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Add tests Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Formatting Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Gmail sync state Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix rush check Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix gmail tests Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix calendar actions and config Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Calendar state Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Access config Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Github integration state Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix svelte errors Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix formatting Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix typos Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix validate Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Fix translations Signed-off-by: Artem Savchenko <[email protected]> * UBERF-11414: Retry on network issues Signed-off-by: Artem Savchenko <[email protected]> --------- Signed-off-by: Artem Savchenko <[email protected]>
1 parent 39c4009 commit 7e92c12

File tree

175 files changed

+6383
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+6383
-867
lines changed

common/config/rush/pnpm-lock.yaml

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

dev/tool/src/calendar.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type AccountClient } from '@hcengineering/account-client'
2+
import { calendarIntegrationKind } from '@hcengineering/calendar'
23
import {
34
type PersonId,
45
type WorkspaceInfoWithStatus,
@@ -55,8 +56,6 @@ interface WorkspaceInfoProvider {
5556
getWorkspaceInfo: (workspaceUuid: WorkspaceUuid) => Promise<WorkspaceInfoWithStatus | undefined>
5657
}
5758

58-
const CALENDAR_INTEGRATION = 'google-calendar'
59-
6059
export async function performCalendarAccountMigrations (db: Db, region: string | null, kvsUrl: string): Promise<void> {
6160
console.log('Start calendar migrations')
6261
const token = generateToken(systemAccountUuid, undefined, { service: 'tool', admin: 'true' })
@@ -124,22 +123,22 @@ async function migrateCalendarIntegrations (
124123
}
125124
// Check/create integration in account
126125
const existing = await accountClient.getIntegration({
127-
kind: CALENDAR_INTEGRATION,
126+
kind: calendarIntegrationKind,
128127
workspaceUuid: ws.uuid,
129128
socialId: personId
130129
})
131130

132131
if (existing == null) {
133132
await accountClient.createIntegration({
134-
kind: CALENDAR_INTEGRATION,
133+
kind: calendarIntegrationKind,
135134
workspaceUuid: ws.uuid,
136135
socialId: personId
137136
})
138137
}
139138

140139
const existingToken = await accountClient.getIntegrationSecret({
141140
key: token.email,
142-
kind: CALENDAR_INTEGRATION,
141+
kind: calendarIntegrationKind,
143142
socialId: personId,
144143
workspaceUuid: ws.uuid
145144
})
@@ -152,7 +151,7 @@ async function migrateCalendarIntegrations (
152151
if (existingToken == null) {
153152
await accountClient.addIntegrationSecret({
154153
key: newToken.email,
155-
kind: CALENDAR_INTEGRATION,
154+
kind: calendarIntegrationKind,
156155
socialId: personId,
157156
secret: JSON.stringify(newToken),
158157
workspaceUuid: newToken.workspace
@@ -164,7 +163,7 @@ async function migrateCalendarIntegrations (
164163
}
165164
await accountClient.updateIntegrationSecret({
166165
key: newToken.email,
167-
kind: CALENDAR_INTEGRATION,
166+
kind: calendarIntegrationKind,
168167
socialId: personId,
169168
secret: JSON.stringify(updatedToken),
170169
workspaceUuid: newToken.workspace
@@ -194,7 +193,7 @@ async function migrateCalendarHistory (
194193
const calendarHistory = db.collection<OldHistory>('calendarHistories')
195194
const calendarHistories = await calendarHistory.find({}).toArray()
196195

197-
const kvsClient = getKvsClient(CALENDAR_INTEGRATION, kvsUrl, token)
196+
const kvsClient = getKvsClient(calendarIntegrationKind, kvsUrl, token)
198197

199198
for (const history of [...calendarHistories, ...allHistories]) {
200199
try {
@@ -212,8 +211,8 @@ async function migrateCalendarHistory (
212211

213212
const key =
214213
history.calendarId != null
215-
? `${CALENDAR_INTEGRATION}:eventHistory:${ws.uuid}:${personId}:${history.email}:${history.calendarId}`
216-
: `${CALENDAR_INTEGRATION}:calendarsHistory:${ws.uuid}:${personId}:${history.email}`
214+
? `${calendarIntegrationKind}:eventHistory:${ws.uuid}:${personId}:${history.email}:${history.calendarId}`
215+
: `${calendarIntegrationKind}:calendarsHistory:${ws.uuid}:${personId}:${history.email}`
217216

218217
await kvsClient.setValue(key, history.historyId)
219218
} catch (e) {
@@ -229,7 +228,7 @@ async function migrateCalendarHistory (
229228
continue
230229
}
231230

232-
const key = `${CALENDAR_INTEGRATION}:calendarSync:${ws.uuid}`
231+
const key = `${calendarIntegrationKind}:calendarSync:${ws.uuid}`
233232
await kvsClient.setValue(key, history.timestamp)
234233
}
235234
console.log('Finished migrating gmail history, count:', allHistories.length)

dev/tool/src/github.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import core, {
1111
type Ref,
1212
type Tx,
1313
type TxCUD,
14-
type WorkspaceUuid
14+
type WorkspaceUuid,
15+
type IntegrationKind
1516
} from '@hcengineering/core'
1617
import { getAccountsFromTxes, getSocialKeyByOldEmail } from '@hcengineering/model-core'
1718
import { getAccountClient } from '@hcengineering/server-client'
@@ -149,21 +150,23 @@ export async function performGithubAccountMigrations (
149150
}
150151

151152
const sid = socialKeyByAccount[it.accountId]
153+
const kind: IntegrationKind = 'github' as any
154+
const userKind: IntegrationKind = 'github-user' as any
152155

153156
const person = sid !== undefined ? await accountClient.findSocialIdBySocialKey(sid) : undefined
154157
if (person !== undefined) {
155158
// Check/create integeration in account
156159

157160
const existing = await githubAccountClient.getIntegration({
158-
kind: 'github',
161+
kind,
159162
workspaceUuid: ws?.uuid,
160163
socialId: person
161164
})
162165

163166
if (existing == null) {
164167
try {
165168
await githubAccountClient.createIntegration({
166-
kind: 'github',
169+
kind,
167170
workspaceUuid: ws?.uuid,
168171
socialId: person,
169172
data: {
@@ -191,15 +194,15 @@ export async function performGithubAccountMigrations (
191194
const { _id, accounts, ...data } = u
192195

193196
const existing = await githubAccountClient.getIntegration({
194-
kind: 'github-user',
197+
kind: userKind,
195198
workspaceUuid: null,
196199
socialId: person
197200
})
198201

199202
if (existing == null) {
200203
try {
201204
await githubAccountClient.createIntegration({
202-
kind: 'github-user',
205+
kind: userKind,
203206
workspaceUuid: null,
204207
socialId: person,
205208
data: {
@@ -208,7 +211,7 @@ export async function performGithubAccountMigrations (
208211
})
209212
// Check/create integeration in account
210213
await githubAccountClient.addIntegrationSecret({
211-
kind: 'github-user',
214+
kind: userKind,
212215
workspaceUuid: null,
213216
socialId: person,
214217
key: u._id, // github login

dev/tool/src/gmail.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import core, {
22
type AccountUuid,
33
DOMAIN_MODEL_TX,
44
type Doc,
5+
type IntegrationKind,
56
MeasureMetricsContext,
67
type PersonId,
78
type Ref,
@@ -67,7 +68,7 @@ interface WorkspaceInfoProvider {
6768
getWorkspaceInfo: (workspaceUuid: WorkspaceUuid) => Promise<WorkspaceInfoWithStatus | undefined>
6869
}
6970

70-
const GMAIL_INTEGRATION = 'gmail'
71+
const GMAIL_INTEGRATION: IntegrationKind = 'gmail' as any
7172
const TOKEN_TYPE = 'token'
7273

7374
export async function performGmailAccountMigrations (

models/bitrix/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import {
3434
type BitrixEntityMapping,
3535
type BitrixFieldMapping,
3636
type BitrixSyncDoc,
37-
type Fields
37+
type Fields,
38+
bitrixIntegrationKind
3839
} from '@hcengineering/bitrix'
3940
import {
4041
type AnyAttribute,
@@ -112,7 +113,8 @@ export function createModel (builder: Builder): void {
112113
icon: bitrix.component.BitrixIcon,
113114
allowMultiple: false,
114115
createComponent: bitrix.component.BitrixConnect,
115-
configureComponent: bitrix.component.BitrixConfigure
116+
configureComponent: bitrix.component.BitrixConfigure,
117+
kind: bitrixIntegrationKind
116118
},
117119
bitrix.integrationType.Bitrix
118120
)

models/calendar/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { type AnyComponent } from '@hcengineering/ui/src/types'
6969
import workbench from '@hcengineering/model-workbench'
7070
import { WidgetType } from '@hcengineering/workbench'
7171
import preference, { TPreference } from '@hcengineering/model-preference'
72+
import { calendarIntegrationKind } from '@hcengineering/calendar'
7273

7374
import calendar from './plugin'
7475

@@ -248,8 +249,11 @@ export function createModel (builder: Builder): void {
248249
allowMultiple: true,
249250
createComponent: calendar.component.IntegrationConnect,
250251
onDisconnect: calendar.handler.DisconnectHandler,
252+
onDisconnectAll: calendar.handler.DisconnectAllHandler,
251253
reconnectComponent: calendar.component.IntegrationConnect,
252-
configureComponent: calendar.component.IntegrationConfigure
254+
configureComponent: calendar.component.IntegrationConfigure,
255+
stateComponent: calendar.component.IntegrationState,
256+
kind: calendarIntegrationKind
253257
},
254258
calendar.integrationType.Calendar
255259
)

models/gmail/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
import activity from '@hcengineering/activity'
1717
import { type Channel } from '@hcengineering/contact'
1818
import { type Class, type Domain, IndexKind, type Ref, type Timestamp, type Type } from '@hcengineering/core'
19-
import type { Message, NewMessage, SharedMessage, SharedMessages } from '@hcengineering/gmail'
19+
import {
20+
type Message,
21+
type NewMessage,
22+
type SharedMessage,
23+
type SharedMessages,
24+
gmailIntegrationKind
25+
} from '@hcengineering/gmail'
2026
import {
2127
ArrOf,
2228
type Builder,
@@ -154,11 +160,14 @@ export function createModel (builder: Builder): void {
154160
label: gmail.string.IntegrationLabel,
155161
description: gmail.string.IntegrationDescription,
156162
icon: gmail.component.IconGmail,
157-
allowMultiple: false, // enable in future
163+
allowMultiple: true,
158164
createComponent: gmail.component.Connect,
159165
onDisconnect: gmail.handler.DisconnectHandler,
166+
onDisconnectAll: gmail.handler.DisconnectAllHandler,
160167
reconnectComponent: gmail.component.Connect,
161-
configureComponent: gmail.component.Configure
168+
configureComponent: gmail.component.Configure,
169+
stateComponent: gmail.component.IntegrationState,
170+
kind: gmailIntegrationKind
162171
},
163172
gmail.integrationType.Gmail
164173
)

models/setting/src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
type AccountUuid,
2222
type Blob,
2323
type ClassCollaborators,
24-
type Ref
24+
type Ref,
25+
type IntegrationKind
2526
} from '@hcengineering/core'
2627
import exportPlugin from '@hcengineering/export'
2728
import { Mixin, Model, UX, type Builder } from '@hcengineering/model'
@@ -92,6 +93,8 @@ export class TIntegrationType extends TDoc implements IntegrationType {
9293
reconnectComponent?: AnyComponent
9394
onDisconnect!: Handler
9495
configureComponent?: AnyComponent
96+
kind!: IntegrationKind
97+
stateComponent?: AnyComponent
9598
}
9699

97100
@Mixin(setting.mixin.Editable, core.class.Class)
@@ -157,10 +160,6 @@ export function createModel (builder: Builder): void {
157160
fields: ['modifiedBy']
158161
})
159162

160-
builder.mixin(setting.class.Integration, core.class.Class, view.mixin.ObjectPanel, {
161-
component: setting.component.IntegrationPanel
162-
})
163-
164163
builder.createDoc(
165164
setting.class.SettingsCategory,
166165
core.space.Model,

models/setting/src/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export default mergeIds(settingId, setting, {
4646
CreateMixin: '' as AnyComponent,
4747
InviteSetting: '' as AnyComponent,
4848
ArrayEditor: '' as AnyComponent,
49-
IntegrationPanel: '' as AnyComponent,
5049
Configure: '' as AnyComponent,
5150
SettingsWidget: '' as AnyComponent
5251
},

models/telegram/src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ import attachment from '@hcengineering/model-attachment'
3333
import contact from '@hcengineering/model-contact'
3434
import core, { TAttachedDoc } from '@hcengineering/model-core'
3535
import setting from '@hcengineering/setting'
36-
import type {
37-
NewTelegramMessage,
38-
SharedTelegramMessage,
39-
SharedTelegramMessages,
40-
TelegramMessage
36+
import {
37+
type NewTelegramMessage,
38+
type SharedTelegramMessage,
39+
type SharedTelegramMessages,
40+
type TelegramMessage,
41+
telegramIntegrationKind
4142
} from '@hcengineering/telegram'
4243
import templates from '@hcengineering/templates'
4344
import view from '@hcengineering/view'
@@ -158,10 +159,14 @@ export function createModel (builder: Builder): void {
158159
description: telegram.string.TelegramIntegrationDesc,
159160
descriptionComponent: telegram.component.TelegramIntegrationDescription,
160161
icon: telegram.component.IconTelegram,
161-
allowMultiple: false,
162+
allowMultiple: true,
162163
createComponent: telegram.component.Connect,
163164
reconnectComponent: telegram.component.Reconnect,
164-
onDisconnect: telegram.handler.DisconnectHandler
165+
configureComponent: telegram.component.Configure,
166+
stateComponent: telegram.component.StateComponent,
167+
onDisconnect: telegram.handler.DisconnectHandler,
168+
onDisconnectAll: telegram.handler.DisconnectAllHandler,
169+
kind: telegramIntegrationKind
165170
},
166171
telegram.integrationType.Telegram
167172
)

0 commit comments

Comments
 (0)