Move services to public (#6156)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2024-07-28 14:55:43 +07:00
committed by Andrey Sobolev
parent 9aad4a4561
commit ddecae80dd
578 changed files with 109084 additions and 390 deletions
+50
View File
@@ -0,0 +1,50 @@
//
// Copyright © 2023 Hardcore Engineering Inc.
//
//
import client, { ClientSocket } from '@hcengineering/client'
import clientResources from '@hcengineering/client-resources'
import { Client, ClientConnectEvent } from '@hcengineering/core'
import { setMetadata } from '@hcengineering/platform'
import { getTransactorEndpoint } from '@hcengineering/server-client'
import serverToken, { generateToken } from '@hcengineering/server-token'
import WebSocket from 'ws'
import config from './config'
/**
* @public
*/
export async function createPlatformClient (
workspace: string,
productId: string,
timeout: number,
reconnect?: (event: ClientConnectEvent) => void
): Promise<Client> {
setMetadata(client.metadata.ClientSocketFactory, (url) => {
return new WebSocket(url, {
headers: {
'User-Agent': config.ServiceID
}
}) as never as ClientSocket
})
setMetadata(serverToken.metadata.Secret, config.ServerSecret)
const token = generateToken(
config.SystemEmail,
{
name: workspace,
productId
},
{ mode: 'github' }
)
setMetadata(client.metadata.ConnectionTimeout, timeout)
const endpoint = await getTransactorEndpoint(token)
const connection = await (
await clientResources()
).function.GetClient(token, endpoint, {
onConnect: reconnect
})
return connection
}