fix: restore api client functionality (#9292)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov
2025-06-19 11:25:09 +07:00
committed by GitHub
parent 84652d00fd
commit 5c48e72ede
6 changed files with 32 additions and 14 deletions
+19 -7
View File
@@ -15,6 +15,7 @@
import { getClient as getAccountClient } from '@hcengineering/account-client'
import client, { clientId } from '@hcengineering/client'
import {
type Account,
type Class,
type Client,
type Data,
@@ -34,7 +35,6 @@ import {
Mixin,
MixinData,
MixinUpdate,
PersonId,
TxOperations,
WorkspaceUuid,
generateId,
@@ -61,14 +61,22 @@ export async function connect (url: string, options: ConnectOptions): Promise<Pl
const { endpoint, token } = await getWorkspaceToken(url, options, config)
const accountClient = getAccountClient(config.ACCOUNTS_URL, token)
const socialId = pickPrimarySocialId(await accountClient.getSocialIds())
const socialIds = await accountClient.getSocialIds()
const wsLoginInfo = await accountClient.selectWorkspace(options.workspace)
if (wsLoginInfo === undefined) {
throw new Error(`Workspace ${options.workspace} not found`)
}
return await createClient(url, endpoint, token, wsLoginInfo.workspace, socialId._id, config, options)
const account: Account = {
uuid: wsLoginInfo.account,
role: wsLoginInfo.role,
primarySocialId: pickPrimarySocialId(socialIds)._id,
socialIds: socialIds.map((si) => si._id),
fullSocialIds: socialIds
}
return await createClient(url, endpoint, token, wsLoginInfo.workspace, account, config, options)
}
async function createClient (
@@ -76,7 +84,7 @@ async function createClient (
endpoint: string,
token: string,
workspaceUuid: WorkspaceUuid,
user: PersonId,
account: Account,
config: ServerConfig,
options: ConnectOptions
): Promise<PlatformClient> {
@@ -90,7 +98,7 @@ async function createClient (
connectionTimeout
})
return new PlatformClientImpl(url, workspaceUuid, token, config, connection, user)
return new PlatformClientImpl(url, workspaceUuid, token, config, connection, account)
}
class PlatformClientImpl implements PlatformClient {
@@ -103,9 +111,9 @@ class PlatformClientImpl implements PlatformClient {
private readonly token: string,
private readonly config: ServerConfig,
private readonly connection: Client,
private readonly user: PersonId
private readonly account: Account
) {
this.client = new TxOperations(connection, user)
this.client = new TxOperations(connection, account.primarySocialId)
this.markup = createMarkupOperations(url, workspace, token, config)
}
@@ -119,6 +127,10 @@ class PlatformClientImpl implements PlatformClient {
return this.client.getModel()
}
async getAccount (): Promise<Account> {
return this.account
}
async findOne<T extends Doc>(
_class: Ref<Class<T>>,
query: DocumentQuery<T>,
+3
View File
@@ -16,6 +16,7 @@
import { type ClientSocketFactory } from '@hcengineering/client'
import {
CollaborativeDoc,
type Account,
type AttachedData,
type AttachedDoc,
type Class,
@@ -57,6 +58,8 @@ export type PlatformClient = {
getModel: () => ModelDb
getAccount: () => Promise<Account>
close: () => Promise<void>
} & FindOperations &
DocOperations &
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = {
extends: ['./node_modules/@hcengineering/platform-rig/profiles/node/eslint.config.json'],
extends: ['./node_modules/@hcengineering/platform-rig/profiles/default/eslint.config.json'],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json'
+1 -2
View File
@@ -1,5 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
"rigPackageName": "@hcengineering/platform-rig",
"rigProfile": "node"
"rigPackageName": "@hcengineering/platform-rig"
}
+7 -3
View File
@@ -4,16 +4,20 @@
"main": "lib/index.js",
"svelte": "src/index.ts",
"types": "types/index.d.ts",
"files": [
"lib/**/*",
"types/**/*",
"tsconfig.json"
],
"author": "Anticrm Platform Contributors",
"template": "@hcengineering/node-package",
"license": "EPL-2.0",
"scripts": {
"build": "compile",
"build:watch": "compile",
"test": "jest --passWithNoTests --silent --forceExit",
"test": "jest --passWithNoTests --silent",
"format": "format src",
"_phase:build": "compile transpile src",
"_phase:test": "jest --passWithNoTests --silent --forceExit",
"_phase:test": "jest --passWithNoTests --silent",
"_phase:format": "format src",
"_phase:validate": "compile validate"
},
+1 -1
View File
@@ -1,5 +1,5 @@
{
"extends": "./node_modules/@hcengineering/platform-rig/profiles/node/tsconfig.json",
"extends": "./node_modules/@hcengineering/platform-rig/profiles/default/tsconfig.json",
"compilerOptions": {
"rootDir": "./src",