diff --git a/services/calendar/pod-calendar/package.json b/services/calendar/pod-calendar/package.json index fd9738742b..40d408acfb 100644 --- a/services/calendar/pod-calendar/package.json +++ b/services/calendar/pod-calendar/package.json @@ -19,6 +19,7 @@ "_phase:docker-staging": "rushx docker:staging", "bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js", "docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/calendar", + "docker:tbuild": "docker build -t hardcoreeng/calendar . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/calendar", "docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/calendar staging", "docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/calendar", "run-local": "cross-env ts-node src/index.ts", @@ -63,6 +64,7 @@ "@hcengineering/setting": "^0.6.17", "@hcengineering/text": "^0.6.5", "@hcengineering/server-client": "^0.6.0", + "@hcengineering/server-token": "^0.6.11", "dotenv": "~16.0.0", "cors": "^2.8.5", "express": "^4.19.2", diff --git a/services/calendar/pod-calendar/src/jwt.ts b/services/calendar/pod-calendar/src/jwt.ts deleted file mode 100644 index a83e4c3001..0000000000 --- a/services/calendar/pod-calendar/src/jwt.ts +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright © 2023 Hardcore Engineering Inc. -// -// Licensed under the Eclipse Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. You may -// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple' - -import config from './config' - -export const encode = (data: any): string => jwtEncode(data, config.Secret) -export const decode = (data: string): any => jwtDecode(data, config.Secret) diff --git a/services/calendar/pod-calendar/src/main.ts b/services/calendar/pod-calendar/src/main.ts index 3d3a050b77..324b2a516b 100644 --- a/services/calendar/pod-calendar/src/main.ts +++ b/services/calendar/pod-calendar/src/main.ts @@ -18,12 +18,12 @@ import { decode64 } from './base64' import { CalendarClient } from './calendar' import { CalendarController } from './calendarController' import config from './config' -import { decode } from './jwt' import { createServer, listen } from './server' import { closeDB, getDB } from './storage' import { type Endpoint, type State } from './types' import { setMetadata } from '@hcengineering/platform' import serverClient from '@hcengineering/server-client' +import serverToken, { decodeToken } from '@hcengineering/server-token' const extractToken = (header: IncomingHttpHeaders): any => { try { @@ -36,6 +36,7 @@ const extractToken = (header: IncomingHttpHeaders): any => { export const main = async (): Promise => { setMetadata(serverClient.metadata.Endpoint, config.AccountsURL) setMetadata(serverClient.metadata.UserAgent, config.ServiceID) + setMetadata(serverToken.metadata.Secret, config.Secret) const db = await getDB() const calendarController = CalendarController.getCalendarController(db) @@ -54,9 +55,9 @@ export const main = async (): Promise => { } const redirectURL = req.query.redirectURL as string - const { email, workspace } = decode(token) - const userId = await calendarController.getUserId(email, workspace) - const url = CalendarClient.getAutUrl(redirectURL, workspace, userId, token) + const { email, workspace } = decodeToken(token) + const userId = await calendarController.getUserId(email, workspace.name) + const url = CalendarClient.getAutUrl(redirectURL, workspace.name, userId, token) res.send(url) } catch (err) { console.log('signin error', err) @@ -93,8 +94,8 @@ export const main = async (): Promise => { const value = req.query.value as string - const { workspace } = decode(token) - await calendarController.signout(workspace, value) + const { workspace } = decodeToken(token) + await calendarController.signout(workspace.name, value) } catch (err) { console.log('signout error', err) } diff --git a/services/calendar/pod-calendar/src/workspaceClient.ts b/services/calendar/pod-calendar/src/workspaceClient.ts index fd846f99e3..d19ca286f7 100644 --- a/services/calendar/pod-calendar/src/workspaceClient.ts +++ b/services/calendar/pod-calendar/src/workspaceClient.ts @@ -33,9 +33,9 @@ import { Collection, type Db } from 'mongodb' import { CalendarClient } from './calendar' import { getClient } from './client' import config from './config' -import { encode } from './jwt' import { SyncHistory, type ProjectCredentials, type User } from './types' import { CalendarController } from './calendarController' +import { generateToken } from '@hcengineering/server-token' export class WorkspaceClient { private readonly txHandlers: ((...tx: Tx[]) => Promise)[] = [] @@ -157,10 +157,7 @@ export class WorkspaceClient { } private async initClient (workspace: string): Promise { - const token = encode({ - email: config.SystemEmail, - workspace - }) + const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) const client = await getClient(token) client.notify = (...tx: Tx[]) => { void this.txHandler(...tx) diff --git a/services/gmail/pod-gmail/package.json b/services/gmail/pod-gmail/package.json index 86eabecc2d..d6d5b6408a 100644 --- a/services/gmail/pod-gmail/package.json +++ b/services/gmail/pod-gmail/package.json @@ -19,6 +19,7 @@ "_phase:docker-staging": "rushx docker:staging", "bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js", "docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/gmail", + "docker:tbuild": "docker build -t hardcoreeng/gmail . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/gmail", "docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/gmail staging", "docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/gmail", "run-local": "cross-env ts-node src/index.ts", @@ -59,6 +60,7 @@ "@hcengineering/contact": "^0.6.24", "@hcengineering/core": "^0.6.32", "@hcengineering/gmail": "^0.6.22", + "@hcengineering/server-token": "^0.6.11", "@hcengineering/platform": "^0.6.11", "@hcengineering/setting": "^0.6.17", "@hcengineering/server-client": "^0.6.0", diff --git a/services/gmail/pod-gmail/src/client.ts b/services/gmail/pod-gmail/src/client.ts index 3720e89cb2..f1635f0188 100644 --- a/services/gmail/pod-gmail/src/client.ts +++ b/services/gmail/pod-gmail/src/client.ts @@ -19,5 +19,6 @@ import { createClient, getTransactorEndpoint } from '@hcengineering/server-clien export async function getClient (token: string): Promise { const endpoint = await getTransactorEndpoint(token) - return await createClient(token, endpoint) + console.log('connecting to', endpoint) + return await createClient(endpoint, token) } diff --git a/services/gmail/pod-gmail/src/gmailController.ts b/services/gmail/pod-gmail/src/gmailController.ts index acd0b827d5..037fa4a15b 100644 --- a/services/gmail/pod-gmail/src/gmailController.ts +++ b/services/gmail/pod-gmail/src/gmailController.ts @@ -111,7 +111,7 @@ export class GmailController { res = await WorkspaceClient.create(this.credentials, this.mongo, workspace) this.workspaces.set(workspace, res) } catch (err) { - console.error(`Couldn't create workspace worker for ${workspace}, reason: ${JSON.stringify(err)}`) + console.error(`Couldn't create workspace worker for ${workspace}, reason: `, err) throw err } } diff --git a/services/gmail/pod-gmail/src/jwt.ts b/services/gmail/pod-gmail/src/jwt.ts deleted file mode 100644 index b7e42523b7..0000000000 --- a/services/gmail/pod-gmail/src/jwt.ts +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright © 2020, 2021 Anticrm Platform Contributors. -// Copyright © 2021 Hardcore Engineering Inc. -// -// Licensed under the Eclipse Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. You may -// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple' - -import config from './config' - -export const encode = (data: any): string => jwtEncode(data, config.Secret) -export const decode = (data: string): any => jwtDecode(data, config.Secret) diff --git a/services/gmail/pod-gmail/src/main.ts b/services/gmail/pod-gmail/src/main.ts index 27d9f7c0f7..afbdb4cead 100644 --- a/services/gmail/pod-gmail/src/main.ts +++ b/services/gmail/pod-gmail/src/main.ts @@ -16,11 +16,11 @@ import { setMetadata } from '@hcengineering/platform' import serverClient from '@hcengineering/server-client' +import serverToken, { decodeToken } from '@hcengineering/server-token' import { type IncomingHttpHeaders } from 'http' import { decode64 } from './base64' import config from './config' import { GmailController } from './gmailController' -import { decode } from './jwt' import { createServer, listen } from './server' import { closeDB, getDB } from './storage' import { type Endpoint, type State } from './types' @@ -36,6 +36,7 @@ const extractToken = (header: IncomingHttpHeaders): any => { export const main = async (): Promise => { setMetadata(serverClient.metadata.Endpoint, config.AccountsURL) setMetadata(serverClient.metadata.UserAgent, config.ServiceID) + setMetadata(serverToken.metadata.Secret, config.Secret) const db = await getDB() const gmailController = GmailController.getGmailController(db) await gmailController.startAll() @@ -53,8 +54,8 @@ export const main = async (): Promise => { } const redirectURL = req.query.redirectURL as string - const { email, workspace } = decode(token) - const gmail = await gmailController.getGmailClient(email, workspace, token) + const { email, workspace } = decodeToken(token) + const gmail = await gmailController.getGmailClient(email, workspace.name, token) const url = gmail.getAutUrl(redirectURL) res.send(url) } catch (err) { @@ -86,8 +87,8 @@ export const main = async (): Promise => { return } - const { email, workspace } = decode(token) - await gmailController.signout(workspace, email) + const { email, workspace } = decodeToken(token) + await gmailController.signout(workspace.name, email) } catch (err) { console.log('signout error', JSON.stringify(err)) } diff --git a/services/gmail/pod-gmail/src/workspaceClient.ts b/services/gmail/pod-gmail/src/workspaceClient.ts index 8f0a46af00..654bb892a2 100644 --- a/services/gmail/pod-gmail/src/workspaceClient.ts +++ b/services/gmail/pod-gmail/src/workspaceClient.ts @@ -28,12 +28,12 @@ import core, { type TxUpdateDoc } from '@hcengineering/core' import gmailP, { type NewMessage } from '@hcengineering/gmail' +import { generateToken } from '@hcengineering/server-token' import { type Db } from 'mongodb' import { getClient } from './client' import config from './config' import { GmailClient } from './gmail' -import { encode } from './jwt' -import { type ProjectCredentials, type User, type Channel } from './types' +import { type Channel, type ProjectCredentials, type User } from './types' export class WorkspaceClient { private messageSubscribed: boolean = false @@ -106,10 +106,8 @@ export class WorkspaceClient { } private async initClient (workspace: string): Promise { - const token = encode({ - email: config.SystemEmail, - workspace - }) + const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) + console.log('token', token, workspace) const client = await getClient(token) client.notify = (...tx: Tx[]) => { void this.txHandler(...tx) diff --git a/services/love/package.json b/services/love/package.json index 8a6f781c8a..13f38de22b 100644 --- a/services/love/package.json +++ b/services/love/package.json @@ -19,6 +19,7 @@ "_phase:docker-staging": "rushx docker:staging", "bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js", "docker:build": "../../common/scripts/docker_build.sh hardcoreeng/love .", + "docker:tbuild": "docker build -t hardcoreeng/love . --platform=linux/amd64 && ../../common/scripts/docker_tag_push.sh hardcoreeng/love", "docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/love staging", "docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/love", "run-local": "cross-env ts-node src/index.ts", @@ -62,6 +63,7 @@ "@hcengineering/client-resources": "^0.6.27", "@hcengineering/platform": "^0.6.11", "@hcengineering/server-client": "^0.6.0", + "@hcengineering/server-token": "^0.6.11", "ws": "^8.18.0", "livekit-server-sdk": "^2.0.10", "jwt-simple": "^0.5.6", diff --git a/services/love/src/jwt.ts b/services/love/src/jwt.ts deleted file mode 100644 index a83e4c3001..0000000000 --- a/services/love/src/jwt.ts +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright © 2023 Hardcore Engineering Inc. -// -// Licensed under the Eclipse Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. You may -// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple' - -import config from './config' - -export const encode = (data: any): string => jwtEncode(data, config.Secret) -export const decode = (data: string): any => jwtDecode(data, config.Secret) diff --git a/services/love/src/main.ts b/services/love/src/main.ts index 699a1e5a98..7530355b4b 100644 --- a/services/love/src/main.ts +++ b/services/love/src/main.ts @@ -13,11 +13,12 @@ // limitations under the License. // -import { MeasureMetricsContext, WorkspaceId, getWorkspaceId, newMetrics, toWorkspaceString } from '@hcengineering/core' +import { MeasureMetricsContext, WorkspaceId, newMetrics, toWorkspaceString } from '@hcengineering/core' import { setMetadata } from '@hcengineering/platform' import serverClient from '@hcengineering/server-client' import { StorageConfig, StorageConfiguration } from '@hcengineering/server-core' import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/server-storage' +import serverToken, { decodeToken } from '@hcengineering/server-token' import cors from 'cors' import express from 'express' import { IncomingHttpHeaders } from 'http' @@ -32,7 +33,6 @@ import { } from 'livekit-server-sdk' import { v4 as uuid } from 'uuid' import config from './config' -import { decode } from './jwt' import { WorkspaceClient } from './workspaceClient' const extractToken = (header: IncomingHttpHeaders): any => { @@ -46,6 +46,7 @@ const extractToken = (header: IncomingHttpHeaders): any => { export const main = async (): Promise => { setMetadata(serverClient.metadata.Endpoint, config.AccountsURL) setMetadata(serverClient.metadata.UserAgent, config.ServiceID) + setMetadata(serverToken.metadata.Secret, config.Secret) const storageConfigs: StorageConfiguration = storageConfigFromEnv() const ctx = new MeasureMetricsContext('love', {}, {}, newMetrics()) @@ -120,14 +121,13 @@ export const main = async (): Promise => { const roomName = req.body.roomName const room = req.body.room - const { workspace, productId } = decode(token) - const workspaceId = getWorkspaceId(workspace, productId) + const { workspace } = decodeToken(token) try { const dateStr = new Date().toISOString().replace('T', '_').slice(0, 19) const name = `${room}_${dateStr}.mp4` - const id = await startRecord(storageConfig, egressClient, roomClient, roomName, workspaceId) - dataByUUID.set(id, { name, workspace, workspaceId }) + const id = await startRecord(storageConfig, egressClient, roomClient, roomName, workspace) + dataByUUID.set(id, { name, workspace: workspace.name, workspaceId: workspace }) res.send() } catch (e) { console.error(e) @@ -144,7 +144,7 @@ export const main = async (): Promise => { return } // just check token - decode(token) + decodeToken(token) await roomClient.updateRoomMetadata(req.body.roomName, JSON.stringify({ recording: false })) void stopEgress(egressClient, req.body.roomName) res.send() diff --git a/services/love/src/workspaceClient.ts b/services/love/src/workspaceClient.ts index 0048edabf1..567eda4520 100644 --- a/services/love/src/workspaceClient.ts +++ b/services/love/src/workspaceClient.ts @@ -15,9 +15,9 @@ import core, { Client, Ref, TxOperations, type Blob } from '@hcengineering/core' import drive, { createFile } from '@hcengineering/drive' import love from '@hcengineering/love' +import { generateToken } from '@hcengineering/server-token' import { getClient } from './client' import config from './config' -import { encode } from './jwt' export class WorkspaceClient { private client!: TxOperations @@ -35,10 +35,7 @@ export class WorkspaceClient { } private async initClient (workspace: string): Promise { - const token = encode({ - email: config.SystemEmail, - workspace - }) + const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) const client = await getClient(token) this.client = new TxOperations(client, core.account.System) return this.client diff --git a/services/sign/pod-sign/package.json b/services/sign/pod-sign/package.json index 62b90f2c40..5876c0335a 100644 --- a/services/sign/pod-sign/package.json +++ b/services/sign/pod-sign/package.json @@ -19,6 +19,7 @@ "_phase:docker-staging": "rushx docker:staging", "bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node --keep-names > bundle/bundle.js", "docker:build": "cross-env DOCKER_EXTRA=--platform=linux/amd64 ../../../common/scripts/docker_build.sh hardcoreeng/sign", + "docker:tbuild": "docker build -t hardcoreeng/sign . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/sign", "docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/sign staging", "docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/sign", "run-local": "cross-env ts-node src/index.ts", diff --git a/services/sign/pod-sign/src/signController.ts b/services/sign/pod-sign/src/signController.ts index 5d627a516a..935b8f39b3 100644 --- a/services/sign/pod-sign/src/signController.ts +++ b/services/sign/pod-sign/src/signController.ts @@ -55,7 +55,7 @@ export class SignController { productId: '' }) const endpoint = await getTransactorEndpoint(token) - const connection = await createClient(token, endpoint) + const connection = await createClient(endpoint, token) console.log(`Platform client has been created (workspace: ${workspace})`) diff --git a/services/telegram/pod-telegram/package.json b/services/telegram/pod-telegram/package.json index c694f3ffad..995c064b94 100644 --- a/services/telegram/pod-telegram/package.json +++ b/services/telegram/pod-telegram/package.json @@ -19,6 +19,7 @@ "_phase:docker-staging": "rushx docker:staging", "bundle": "mkdir -p bundle && esbuild src/index.ts --bundle --platform=node > bundle/bundle.js", "docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/telegram", + "docker:tbuild": "docker build -t hardcoreeng/telegram . --platform=linux/amd64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/telegram", "docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/telegram staging", "docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/telegram", "run-local": "cross-env ts-node src/index.ts", @@ -63,6 +64,7 @@ "@hcengineering/platform": "^0.6.11", "@hcengineering/setting": "^0.6.17", "@hcengineering/telegram": "^0.6.21", + "@hcengineering/server-token": "^0.6.11", "@hcengineering/server-client": "^0.6.0", "big-integer": "^1.6.51", "dotenv": "~16.0.0", diff --git a/services/telegram/pod-telegram/src/jwt.ts b/services/telegram/pod-telegram/src/jwt.ts deleted file mode 100644 index d03a5c8c6f..0000000000 --- a/services/telegram/pod-telegram/src/jwt.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { encode as jwtEncode, decode as jwtDecode } from 'jwt-simple' - -import config from './config' - -export const encode = (data: any): string => jwtEncode(data, config.Secret) -export const decode = (data: string): any => jwtDecode(data, config.Secret) diff --git a/services/telegram/pod-telegram/src/main.ts b/services/telegram/pod-telegram/src/main.ts index 287d477102..8d7c690ce6 100644 --- a/services/telegram/pod-telegram/src/main.ts +++ b/services/telegram/pod-telegram/src/main.ts @@ -1,16 +1,16 @@ import { IncomingHttpHeaders } from 'http' -import { decode } from './jwt' import { PlatformWorker } from './platform' import { createServer, Handler, listen } from './server' import { telegram } from './telegram' import { setMetadata } from '@hcengineering/platform' import serverClient from '@hcengineering/server-client' +import serverToken, { decodeToken, type Token } from '@hcengineering/server-token' import config from './config' -const extractToken = (header: IncomingHttpHeaders): any => { +const extractToken = (header: IncomingHttpHeaders): Token | undefined => { try { - return decode(header.authorization?.slice(7) ?? '') + return decodeToken(header.authorization?.slice(7) ?? '') } catch { return undefined } @@ -19,6 +19,7 @@ const extractToken = (header: IncomingHttpHeaders): any => { export const main = async (): Promise => { setMetadata(serverClient.metadata.Endpoint, config.AccountsURL) setMetadata(serverClient.metadata.UserAgent, config.ServiceID) + setMetadata(serverToken.metadata.Secret, config.Secret) const platformWorker = await PlatformWorker.create() const endpoints: Array<[string, Handler]> = [ @@ -41,7 +42,7 @@ export const main = async (): Promise => { const existingRec = await platformWorker.getUserRecord({ phone, - workspace + workspace: workspace.name }) if (existingRec !== undefined) { @@ -79,7 +80,7 @@ export const main = async (): Promise => { const existingRec = await platformWorker.getUserRecord({ phone, - workspace + workspace: workspace.name }) if (existingRec !== undefined) { @@ -102,7 +103,7 @@ export const main = async (): Promise => { if (conn !== undefined) { await platformWorker.addUser({ email, - workspace, + workspace: workspace.name, phone, conn }) @@ -134,7 +135,7 @@ export const main = async (): Promise => { const existingRec = await platformWorker.getUserRecord({ phone, - workspace + workspace: workspace.name }) if (existingRec !== undefined) { @@ -156,7 +157,7 @@ export const main = async (): Promise => { if (conn !== undefined) { await platformWorker.addUser({ email, - workspace, + workspace: workspace.name, phone, conn }) @@ -177,7 +178,7 @@ export const main = async (): Promise => { } const { email, workspace } = token - await platformWorker.removeUser({ email, workspace }) + await platformWorker.removeUser({ email, workspace: workspace.name }) res.send() } diff --git a/services/telegram/pod-telegram/src/utils.ts b/services/telegram/pod-telegram/src/utils.ts index 52f4f41592..80c4db2064 100644 --- a/services/telegram/pod-telegram/src/utils.ts +++ b/services/telegram/pod-telegram/src/utils.ts @@ -117,7 +117,7 @@ export async function createPlatformClient (token: string): Promise { }) const endpoint = await getTransactorEndpoint(token) - const connection = await createClient(token, endpoint) + const connection = await createClient(endpoint, token) return connection } diff --git a/services/telegram/pod-telegram/src/workspace.ts b/services/telegram/pod-telegram/src/workspace.ts index 96de3776fd..6e7c8b7650 100644 --- a/services/telegram/pod-telegram/src/workspace.ts +++ b/services/telegram/pod-telegram/src/workspace.ts @@ -24,9 +24,9 @@ import core, { TxRemoveDoc, TxUpdateDoc } from '@hcengineering/core' +import { generateToken } from '@hcengineering/server-token' import settingP from '@hcengineering/setting' import telegramP, { NewTelegramMessage } from '@hcengineering/telegram' -import { encode } from 'jwt-simple' import type { Collection } from 'mongodb' import fetch from 'node-fetch' import { Api } from 'telegram' @@ -155,7 +155,7 @@ export class WorkspaceWorker { lastMsgStorage: Collection, channelsStorage: Collection ): Promise { - const token = encode({ email: config.SystemEmail, workspace }, config.Secret) + const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) const client = await createPlatformClient(token) const worker = new WorkspaceWorker(client, token, workspace, userStorage, lastMsgStorage, channelsStorage)