mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 12:35:02 +02:00
fix: restore api client functionality (#9292)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -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>,
|
||||
|
||||
@@ -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,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,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"
|
||||
}
|
||||
|
||||
@@ -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,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",
|
||||
|
||||
Reference in New Issue
Block a user