@neuralinnovations/dataisland-sdk 0.0.1-dev27 → 0.0.1-dev29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +4 -1
- package/dist/src/commands/startCommandHandler.d.ts.map +1 -1
- package/dist/src/commands/startCommandHandler.js +12 -2
- package/dist/src/commands/startCommandHandler.js.map +1 -1
- package/dist/src/context.d.ts +3 -2
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +2 -2
- package/dist/src/context.js.map +1 -1
- package/dist/src/credentials.d.ts +5 -0
- package/dist/src/credentials.d.ts.map +1 -1
- package/dist/src/credentials.js +18 -1
- package/dist/src/credentials.js.map +1 -1
- package/dist/src/dto/accessGroupResponse.d.ts.map +1 -1
- package/dist/src/dto/userInfoResponse.d.ts +1 -0
- package/dist/src/dto/userInfoResponse.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal/app.impl.d.ts.map +1 -1
- package/dist/src/internal/app.impl.js +20 -2
- package/dist/src/internal/app.impl.js.map +1 -1
- package/dist/src/middleware.d.ts +1 -0
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/services/anonymousService.d.ts +8 -0
- package/dist/src/services/anonymousService.d.ts.map +1 -0
- package/dist/src/services/anonymousService.js +41 -0
- package/dist/src/services/anonymousService.js.map +1 -0
- package/dist/src/services/commandService.d.ts.map +1 -1
- package/dist/src/services/commandService.js.map +1 -1
- package/dist/src/services/cookieService.d.ts +7 -0
- package/dist/src/services/cookieService.d.ts.map +1 -0
- package/dist/src/services/cookieService.js +18 -0
- package/dist/src/services/cookieService.js.map +1 -0
- package/dist/src/services/httpMethod.d.ts +2 -0
- package/dist/src/services/httpMethod.d.ts.map +1 -0
- package/dist/src/services/httpMethod.js +3 -0
- package/dist/src/services/httpMethod.js.map +1 -0
- package/dist/src/services/middlewareService.d.ts +1 -0
- package/dist/src/services/middlewareService.d.ts.map +1 -1
- package/dist/src/services/middlewareService.js.map +1 -1
- package/dist/src/services/requestBuilder.d.ts.map +1 -1
- package/dist/src/services/requestBuilder.js +8 -7
- package/dist/src/services/requestBuilder.js.map +1 -1
- package/dist/src/services/responseUtils.d.ts +1 -0
- package/dist/src/services/responseUtils.d.ts.map +1 -1
- package/dist/src/services/responseUtils.js.map +1 -1
- package/dist/src/services/rpcService.d.ts.map +1 -1
- package/dist/src/services/rpcService.js.map +1 -1
- package/dist/src/services/userProfileService.d.ts +1 -0
- package/dist/src/services/userProfileService.d.ts.map +1 -1
- package/dist/src/services/userProfileService.js +11 -0
- package/dist/src/services/userProfileService.js.map +1 -1
- package/dist/src/storages/chats/answer.impl.d.ts.map +1 -1
- package/dist/src/storages/chats/answer.impl.js.map +1 -1
- package/dist/src/storages/chats/chat.impl.js.map +1 -1
- package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
- package/dist/src/storages/chats/chats.impl.js.map +1 -1
- package/dist/src/storages/files/file.impl.d.ts.map +1 -1
- package/dist/src/storages/files/file.impl.js.map +1 -1
- package/dist/src/storages/files/files.d.ts +6 -1
- package/dist/src/storages/files/files.d.ts.map +1 -1
- package/dist/src/storages/files/files.impl.d.ts +1 -1
- package/dist/src/storages/files/files.impl.d.ts.map +1 -1
- package/dist/src/storages/files/files.impl.js +9 -1
- package/dist/src/storages/files/files.impl.js.map +1 -1
- package/dist/src/storages/files/files.js.map +1 -1
- package/dist/src/storages/organizations/organization.d.ts.map +1 -1
- package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -1
- package/dist/src/storages/organizations/organization.impl.js.map +1 -1
- package/dist/src/storages/organizations/organization.js.map +1 -1
- package/dist/src/storages/organizations/organizations.impl.d.ts.map +1 -1
- package/dist/src/storages/organizations/organizations.impl.js.map +1 -1
- package/dist/src/storages/user/userProfile.d.ts +4 -0
- package/dist/src/storages/user/userProfile.d.ts.map +1 -1
- package/dist/src/storages/user/userProfile.impl.d.ts +1 -0
- package/dist/src/storages/user/userProfile.impl.d.ts.map +1 -1
- package/dist/src/storages/user/userProfile.impl.js +6 -0
- package/dist/src/storages/user/userProfile.impl.js.map +1 -1
- package/dist/src/storages/user/userProfile.js.map +1 -1
- package/dist/src/storages/workspaces/workspace.impl.js.map +1 -1
- package/dist/src/storages/workspaces/workspaces.d.ts.map +1 -1
- package/dist/src/storages/workspaces/workspaces.impl.d.ts.map +1 -1
- package/dist/src/storages/workspaces/workspaces.impl.js.map +1 -1
- package/dist/src/storages/workspaces/workspaces.js.map +1 -1
- package/dist/src/utils/browserUtils.d.ts +4 -0
- package/dist/src/utils/browserUtils.d.ts.map +1 -0
- package/dist/src/utils/browserUtils.js +68 -0
- package/dist/src/utils/browserUtils.js.map +1 -0
- package/dist/src/utils/request.d.ts +6 -0
- package/dist/src/utils/request.d.ts.map +1 -0
- package/dist/src/utils/request.js +3 -0
- package/dist/src/utils/request.js.map +1 -0
- package/package.json +4 -1
- package/src/commands/startCommandHandler.ts +16 -5
- package/src/context.ts +2 -1
- package/src/credentials.ts +22 -0
- package/src/dto/accessGroupResponse.ts +15 -16
- package/src/dto/userInfoResponse.ts +1 -0
- package/src/index.ts +2 -0
- package/src/internal/app.impl.ts +30 -4
- package/src/middleware.ts +2 -0
- package/src/services/anonymousService.ts +43 -0
- package/src/services/commandService.ts +4 -2
- package/src/services/cookieService.ts +16 -0
- package/src/services/httpMethod.ts +1 -0
- package/src/services/middlewareService.ts +1 -0
- package/src/services/requestBuilder.ts +10 -8
- package/src/services/responseUtils.ts +2 -0
- package/src/services/rpcService.ts +1 -0
- package/src/services/userProfileService.ts +14 -0
- package/src/storages/chats/answer.impl.ts +4 -5
- package/src/storages/chats/chat.impl.ts +1 -1
- package/src/storages/chats/chats.impl.ts +3 -1
- package/src/storages/files/file.impl.ts +4 -2
- package/src/storages/files/files.impl.ts +11 -3
- package/src/storages/files/files.ts +5 -1
- package/src/storages/groups/group.impl.ts +1 -1
- package/src/storages/organizations/organization.impl.ts +4 -2
- package/src/storages/organizations/organization.ts +3 -4
- package/src/storages/organizations/organizations.impl.ts +3 -1
- package/src/storages/user/userProfile.impl.ts +7 -0
- package/src/storages/user/userProfile.ts +5 -0
- package/src/storages/workspaces/workspace.impl.ts +1 -1
- package/src/storages/workspaces/workspaces.impl.ts +3 -1
- package/src/storages/workspaces/workspaces.ts +5 -1
- package/src/utils/browserUtils.ts +72 -0
- package/src/utils/request.ts +6 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"browserUtils.js","sourceRoot":"","sources":["../../../src/utils/browserUtils.ts"],"names":[],"mappings":";;;AAAA,MAAM,WAAW,GAAG,GAAG,EAAE;IACvB,IAAI,CAAE,UAAkB,CAAC,QAAQ,EAAE,CAAC;QACjC,UAAkB,CAAC,QAAQ,GAAG;YAC7B,MAAM,EAAE,EAAE;SACX,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,GAAG,EAAE;IACxB,IAAI,CAAE,UAAkB,CAAC,SAAS,EAAE,CAAC;QAClC,UAAkB,CAAC,SAAS,GAAG;YAC9B,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,EAAE;YACZ,mBAAmB,EAAE,CAAC;YACtB,aAAa,EAAE,KAAK;SACrB,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,QAAQ,GAAG,GAAG,EAAE;IACpB,IAAI,CAAE,UAAkB,CAAC,MAAM,EAAE,CAAC;QAC/B,UAAkB,CAAC,MAAM,GAAG;YAC3B,gBAAgB,EAAE,EAAE,GAAG,GAAG;YAC1B,cAAc,EAAE,EAAE;YAClB,YAAY,EAAE,EAAE;SACjB,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAEM,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAyB,EAAQ,EAAE;IACzE,MAAM,GAAG,GAAG,WAAW,EAAE,CAAA;IACzB,GAAG,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,KAAK,IAAI,EAAE,GAAG,CAAA;AACxC,CAAC,CAAA;AAHY,QAAA,SAAS,aAGrB;AAEM,MAAM,SAAS,GAAG,CAAC,IAAY,EAAsB,EAAE;IAC5D,MAAM,GAAG,GAAG,WAAW,EAAE,CAAA;IACzB,MAAM,aAAa,GAAG,GAAG,IAAI,GAAG,CAAA;IAChC,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAEzC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACxD,IAAI,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;QAE/B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAChC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAC7C,CAAC;QAED,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAC9D,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAlBY,QAAA,SAAS,aAkBrB;AAEM,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,MAAM,GAAG,GAAG,YAAY,EAAE,CAAA;IAC1B,MAAM,GAAG,GAAG,QAAQ,EAAE,CAAA;IACtB,MAAM,WAAW,GAAG,IAAI,GAAG,EAAe,CAAA;IAE1C,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;IAC3C,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACzC,WAAW,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAA;IAChE,WAAW,CAAC,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,aAAa,CAAC,CAAA;IACpD,WAAW,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAA;IACpD,WAAW,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,cAAc,CAAC,CAAA;IACtD,WAAW,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,YAAY,CAAC,CAAA;IAElD,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAdY,QAAA,iBAAiB,qBAc7B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;AACxC,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAA;AAC1C,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;AACxC,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAA;AAC1C,MAAM,MAAM,KAAK,GAAG,OAAO,UAAU,CAAC,KAAK,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@neuralinnovations/dataisland-sdk",
|
3
|
-
"version": "0.0.1-
|
3
|
+
"version": "0.0.1-dev29",
|
4
4
|
"description": "SDK for DataIsland project",
|
5
5
|
"licenses": [
|
6
6
|
{
|
@@ -64,6 +64,8 @@
|
|
64
64
|
"@babel/register": "7.22.5",
|
65
65
|
"@jest/globals": "^29.7.0",
|
66
66
|
"@types/jest": "^29.5.11",
|
67
|
+
"@types/node": "^20.11.27",
|
68
|
+
"@types/node-fetch": "^2.6.11",
|
67
69
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
68
70
|
"@typescript-eslint/parser": "^6.19.0",
|
69
71
|
"babel-jest": "^29.7.0",
|
@@ -80,6 +82,7 @@
|
|
80
82
|
"eslint-plugin-react": "^7.33.2",
|
81
83
|
"glob": "7.2.3",
|
82
84
|
"jest": "^29.7.0",
|
85
|
+
"jest-environment-jsdom": "^29.7.0",
|
83
86
|
"prettier": "2.8.7",
|
84
87
|
"ts-jest": "^29.1.1",
|
85
88
|
"ts-loader": "8.4.0",
|
@@ -1,14 +1,25 @@
|
|
1
1
|
import { CommandHandler, Command } from "../services/commandService"
|
2
2
|
import { UserProfileService } from "../services/userProfileService"
|
3
|
+
import { CookieService } from "../services/cookieService"
|
4
|
+
import { AnonymousCredential } from "../credentials"
|
3
5
|
|
4
|
-
export class StartCommand extends Command {
|
6
|
+
export class StartCommand extends Command {
|
7
|
+
}
|
5
8
|
|
6
9
|
export class StartCommandHandler extends CommandHandler<StartCommand> {
|
7
10
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
8
11
|
async execute(message: StartCommand): Promise<void> {
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
const userService = this.resolve(UserProfileService)!
|
13
|
+
|
14
|
+
// Merge anonymous user if needed
|
15
|
+
if (!(this.context.app.credential instanceof AnonymousCredential)) {
|
16
|
+
const cookie = this.resolve(CookieService)!
|
17
|
+
if (cookie.anonymousTokenIsValid) {
|
18
|
+
await userService.merge(cookie.anonymousToken!)
|
19
|
+
cookie.anonymousToken = undefined
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
await userService.fetch()
|
13
24
|
}
|
14
25
|
}
|
package/src/context.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { type Constructor, type Registry } from "./internal/registry"
|
2
2
|
import { type Lifetime } from "./disposable"
|
3
3
|
import { Command, CommandService } from "./services/commandService"
|
4
|
+
import { DataIslandApp } from "./dataIslandApp"
|
4
5
|
|
5
6
|
/**
|
6
7
|
* DataIsland App context.
|
@@ -9,7 +10,7 @@ export class Context {
|
|
9
10
|
constructor(
|
10
11
|
private readonly registry: Registry,
|
11
12
|
public readonly lifetime: Lifetime,
|
12
|
-
public readonly
|
13
|
+
public readonly app: DataIslandApp
|
13
14
|
) {
|
14
15
|
}
|
15
16
|
|
package/src/credentials.ts
CHANGED
@@ -83,3 +83,25 @@ export class BearerCredential extends CredentialBase {
|
|
83
83
|
)
|
84
84
|
}
|
85
85
|
}
|
86
|
+
|
87
|
+
export class AnonymousCredential extends CredentialBase {
|
88
|
+
readonly token: string
|
89
|
+
|
90
|
+
constructor(token: string) {
|
91
|
+
super()
|
92
|
+
this.token = token
|
93
|
+
}
|
94
|
+
|
95
|
+
onRegister(lifetime: Lifetime, context: Context): void {
|
96
|
+
const service = context.resolve(MiddlewareService)
|
97
|
+
if (service === undefined) {
|
98
|
+
throw new Error("MiddlewareService is not registered.")
|
99
|
+
}
|
100
|
+
lifetime.add(
|
101
|
+
service.useMiddleware(async (req, next) => {
|
102
|
+
req.headers.set("Authorization", `InternalJWT ${this.token}`)
|
103
|
+
return await next(req)
|
104
|
+
})
|
105
|
+
)
|
106
|
+
}
|
107
|
+
}
|
@@ -1,34 +1,33 @@
|
|
1
1
|
import { UserDto } from "./userInfoResponse"
|
2
2
|
|
3
|
-
|
4
3
|
export interface PermitsDto {
|
5
|
-
|
4
|
+
isAdmin: boolean;
|
6
5
|
}
|
7
6
|
|
8
7
|
export interface RegulationDto {
|
9
|
-
|
10
|
-
|
8
|
+
isRegulateOrganization: boolean;
|
9
|
+
regulateWorkspaceIds: string[];
|
11
10
|
}
|
12
11
|
|
13
12
|
export interface AccessGroupDto {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
id: string;
|
14
|
+
name: string;
|
15
|
+
type: number;
|
16
|
+
createdAt: number;
|
17
|
+
modifiedAt: number;
|
18
|
+
organizationId: string;
|
19
|
+
permits: PermitsDto;
|
20
|
+
regulation: RegulationDto;
|
21
|
+
membersCount: number;
|
23
22
|
}
|
24
23
|
|
25
24
|
export interface AccessGroupResponse {
|
26
|
-
|
27
|
-
|
25
|
+
group: AccessGroupDto;
|
26
|
+
members: UserDto[];
|
28
27
|
}
|
29
28
|
|
30
29
|
export interface AccessGroupsResponse {
|
31
|
-
|
30
|
+
groups: AccessGroupDto[];
|
32
31
|
}
|
33
32
|
|
34
33
|
|
package/src/index.ts
CHANGED
@@ -25,6 +25,7 @@ export * from "./storages/files/file"
|
|
25
25
|
export * from "./storages/files/filesPage"
|
26
26
|
export * from "./storages/chats/chats"
|
27
27
|
export * from "./storages/chats/chat"
|
28
|
+
export * from "./storages/chats/answer"
|
28
29
|
|
29
30
|
// map of apps that are not ready to be used
|
30
31
|
const _appsNotReady = new Map<string, Promise<DataIslandApp>>()
|
@@ -96,6 +97,7 @@ export async function dataIslandApp(
|
|
96
97
|
}
|
97
98
|
return await appPromise
|
98
99
|
}
|
100
|
+
|
99
101
|
export { Group } from "./storages/groups/group"
|
100
102
|
export { GroupEvent } from "./storages/groups/group"
|
101
103
|
export { GroupId } from "./storages/groups/group"
|
package/src/internal/app.impl.ts
CHANGED
@@ -7,7 +7,11 @@ import { DisposableContainer, type Lifetime } from "../disposable"
|
|
7
7
|
import { type Service, ServiceContext } from "../services/service"
|
8
8
|
import { CredentialService } from "../services/credentialService"
|
9
9
|
import { MiddlewareService } from "../services/middlewareService"
|
10
|
-
import {
|
10
|
+
import {
|
11
|
+
DefaultCredential,
|
12
|
+
type CredentialBase,
|
13
|
+
AnonymousCredential
|
14
|
+
} from "../credentials"
|
11
15
|
import { DataIslandApp } from "../dataIslandApp"
|
12
16
|
import { RpcService } from "../services/rpcService"
|
13
17
|
import { CommandService } from "../services/commandService"
|
@@ -24,6 +28,8 @@ import {
|
|
24
28
|
DeleteUserFullCommand,
|
25
29
|
DeleteUserFullCommandHandler
|
26
30
|
} from "../commands/deleteUserFullCommandHandler"
|
31
|
+
import { CookieService } from "../services/cookieService"
|
32
|
+
import { AnonymousService } from "../services/anonymousService"
|
27
33
|
|
28
34
|
export class DataIslandAppImpl extends DataIslandApp {
|
29
35
|
readonly name: string
|
@@ -38,7 +44,7 @@ export class DataIslandAppImpl extends DataIslandApp {
|
|
38
44
|
this.name = name
|
39
45
|
this._registry = new Registry()
|
40
46
|
this._disposable = new DisposableContainer()
|
41
|
-
this._context = new Context(this._registry, this._disposable.lifetime,
|
47
|
+
this._context = new Context(this._registry, this._disposable.lifetime, this)
|
42
48
|
|
43
49
|
this._registry.map(Context).asValue(this._context)
|
44
50
|
}
|
@@ -92,6 +98,9 @@ export class DataIslandAppImpl extends DataIslandApp {
|
|
92
98
|
})
|
93
99
|
|
94
100
|
// register services
|
101
|
+
builder.registerService(CookieService, (context: ServiceContext) => {
|
102
|
+
return new CookieService(context)
|
103
|
+
})
|
95
104
|
builder.registerService(CredentialService, (context: ServiceContext) => {
|
96
105
|
return new CredentialService(context)
|
97
106
|
})
|
@@ -110,6 +119,9 @@ export class DataIslandAppImpl extends DataIslandApp {
|
|
110
119
|
builder.registerService(OrganizationService, (context: ServiceContext) => {
|
111
120
|
return new OrganizationService(context)
|
112
121
|
})
|
122
|
+
builder.registerService(AnonymousService, (context: ServiceContext) => {
|
123
|
+
return new AnonymousService(context)
|
124
|
+
})
|
113
125
|
|
114
126
|
// call customer setup
|
115
127
|
if (setup !== undefined) {
|
@@ -146,8 +158,6 @@ export class DataIslandAppImpl extends DataIslandApp {
|
|
146
158
|
this.resolve(CommandService)?.register(command[0], command[1])
|
147
159
|
})
|
148
160
|
|
149
|
-
this.credential = builder.credential
|
150
|
-
|
151
161
|
//-------------------------------------------------------------------------
|
152
162
|
// register services
|
153
163
|
//-------------------------------------------------------------------------
|
@@ -178,6 +188,22 @@ export class DataIslandAppImpl extends DataIslandApp {
|
|
178
188
|
await Promise.all(waitList)
|
179
189
|
//-------------------------------------------------------------------------
|
180
190
|
|
191
|
+
// set credential
|
192
|
+
this.credential = builder.credential
|
193
|
+
|
194
|
+
// Check anonymous authorization
|
195
|
+
if (!isUnitTest(UnitTest.DO_NOT_START) && builder.credential instanceof DefaultCredential) {
|
196
|
+
const anonymous = this.resolve(AnonymousService)!
|
197
|
+
const {
|
198
|
+
token,
|
199
|
+
isValid
|
200
|
+
} = await anonymous.getToken()
|
201
|
+
|
202
|
+
if (isValid) {
|
203
|
+
this.credential = new AnonymousCredential(token)
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
181
207
|
// start app, execute start command
|
182
208
|
if (!isUnitTest(UnitTest.DO_NOT_START)) {
|
183
209
|
await this.context.execute(new StartCommand())
|
package/src/middleware.ts
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Service } from "./service"
|
2
|
+
import { CookieService } from "./cookieService"
|
3
|
+
import { createFingerprint } from "../utils/browserUtils"
|
4
|
+
import { RpcService } from "./rpcService"
|
5
|
+
import { ResponseUtils } from "./responseUtils"
|
6
|
+
|
7
|
+
export class AnonymousService extends Service {
|
8
|
+
|
9
|
+
async getToken(): Promise<{ token: string, isValid: boolean }> {
|
10
|
+
const cookie = this.resolve(CookieService)!
|
11
|
+
let token = cookie.anonymousToken
|
12
|
+
if (token === undefined || token === null || token.length === 0) {
|
13
|
+
const fingerprint = createFingerprint()
|
14
|
+
const response = await this.context
|
15
|
+
.resolve(RpcService)
|
16
|
+
?.requestBuilder("api/v1/Users/anonymous")
|
17
|
+
.sendPutJson({
|
18
|
+
info: {
|
19
|
+
fingerprint: JSON.stringify({
|
20
|
+
userAgent: fingerprint.get("userAgent"),
|
21
|
+
language: fingerprint.get("language"),
|
22
|
+
hardwareConcurrency: fingerprint.get("hardware_concurrency"),
|
23
|
+
cookieEnabled: fingerprint.get("cookie_enabled"),
|
24
|
+
pixelRatio: fingerprint.get("pixel_ratio")
|
25
|
+
})
|
26
|
+
}
|
27
|
+
})
|
28
|
+
|
29
|
+
if (ResponseUtils.isFail(response)) {
|
30
|
+
await ResponseUtils.throwError("Failed to create anonymous token", response)
|
31
|
+
}
|
32
|
+
|
33
|
+
token = (await response!.json() as { token: string }).token
|
34
|
+
|
35
|
+
cookie.anonymousToken = token!
|
36
|
+
}
|
37
|
+
|
38
|
+
return {
|
39
|
+
token: token!,
|
40
|
+
isValid: token !== undefined && token !== null && token.length > 0
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
@@ -3,7 +3,8 @@ import { Context } from "../context"
|
|
3
3
|
import { Constructor } from "../internal/registry"
|
4
4
|
|
5
5
|
export abstract class CommandHandler<T> {
|
6
|
-
constructor(protected readonly context: Context) {
|
6
|
+
constructor(protected readonly context: Context) {
|
7
|
+
}
|
7
8
|
|
8
9
|
resolve<T>(type: Constructor<T>): T | undefined {
|
9
10
|
return this.context.resolve<T>(type)
|
@@ -12,7 +13,8 @@ export abstract class CommandHandler<T> {
|
|
12
13
|
abstract execute(message: T): Promise<void>
|
13
14
|
}
|
14
15
|
|
15
|
-
export abstract class Command {
|
16
|
+
export abstract class Command {
|
17
|
+
}
|
16
18
|
|
17
19
|
export class CommandService extends Service {
|
18
20
|
private readonly _registry: Map<
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { Service } from "./service"
|
2
|
+
import { getCookie, setCookie } from "../utils/browserUtils"
|
3
|
+
|
4
|
+
export class CookieService extends Service {
|
5
|
+
get anonymousToken(): string | undefined {
|
6
|
+
return getCookie("anonymous-token")
|
7
|
+
}
|
8
|
+
|
9
|
+
get anonymousTokenIsValid(): boolean {
|
10
|
+
return this.anonymousToken !== undefined && this.anonymousToken !== null && this.anonymousToken.length > 0
|
11
|
+
}
|
12
|
+
|
13
|
+
set anonymousToken(value: string | undefined) {
|
14
|
+
setCookie("anonymous-token", value)
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export type HttpMethod = "POST" | "GET" | "PUT" | "DELETE" | "PATCH"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Service } from "./service"
|
2
2
|
import { type Middleware } from "../middleware"
|
3
3
|
import { type Disposable } from "../disposable"
|
4
|
+
import { Request, Response } from "../utils/request"
|
4
5
|
|
5
6
|
export class MiddlewareService extends Service {
|
6
7
|
private _middlewares: Middleware[] = []
|
@@ -1,17 +1,19 @@
|
|
1
|
+
// import { Request, Response, Headers, FormData } from "../utils/request"
|
2
|
+
|
1
3
|
export class RequestBuilder {
|
2
|
-
private readonly _headers:
|
4
|
+
private readonly _headers: Record<string, string>
|
3
5
|
private readonly _searchParams: URLSearchParams
|
4
6
|
|
5
7
|
constructor(
|
6
8
|
private readonly _url: URL,
|
7
9
|
private readonly _request: (req: Request) => Promise<Response>
|
8
10
|
) {
|
9
|
-
this._headers =
|
11
|
+
this._headers = {}
|
10
12
|
this._searchParams = new URLSearchParams()
|
11
13
|
}
|
12
14
|
|
13
15
|
public header(name: string, value: string): RequestBuilder {
|
14
|
-
this._headers
|
16
|
+
this._headers[name] = value
|
15
17
|
return this
|
16
18
|
}
|
17
19
|
|
@@ -23,11 +25,11 @@ export class RequestBuilder {
|
|
23
25
|
}
|
24
26
|
if (headers instanceof Headers) {
|
25
27
|
headers.forEach((value, name) => {
|
26
|
-
this._headers
|
28
|
+
this._headers[name] = value
|
27
29
|
})
|
28
30
|
} else {
|
29
31
|
Object.entries(headers).forEach(([name, value]) => {
|
30
|
-
this._headers
|
32
|
+
this._headers[name] = value
|
31
33
|
})
|
32
34
|
}
|
33
35
|
return this
|
@@ -58,7 +60,7 @@ export class RequestBuilder {
|
|
58
60
|
const req = new Request(url, {
|
59
61
|
method: "POST",
|
60
62
|
headers: this._headers,
|
61
|
-
body
|
63
|
+
body: body
|
62
64
|
})
|
63
65
|
|
64
66
|
// discard content type
|
@@ -73,7 +75,7 @@ export class RequestBuilder {
|
|
73
75
|
public async sendPostJson(body: object | null | undefined): Promise<Response> {
|
74
76
|
const url = this._url
|
75
77
|
url.search = this._searchParams.toString()
|
76
|
-
let json: string |
|
78
|
+
let json: string | undefined = undefined
|
77
79
|
if (body !== undefined && body !== null && typeof body === "object") {
|
78
80
|
json = JSON.stringify(body)
|
79
81
|
}
|
@@ -112,7 +114,7 @@ export class RequestBuilder {
|
|
112
114
|
public async sendPutJson(body: object | null | undefined): Promise<Response> {
|
113
115
|
const url = this._url
|
114
116
|
url.search = this._searchParams.toString()
|
115
|
-
let json: string |
|
117
|
+
let json: string | undefined = undefined
|
116
118
|
if (body !== undefined && body !== null && typeof body === "object") {
|
117
119
|
json = JSON.stringify(body)
|
118
120
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Service, type ServiceContext } from "./service"
|
2
2
|
import { MiddlewareService } from "./middlewareService"
|
3
3
|
import { RequestBuilder } from "./requestBuilder"
|
4
|
+
// import { Request, Response, Headers, fetch } from "../utils/request"
|
4
5
|
|
5
6
|
/**
|
6
7
|
* Options for the RpcService.
|
@@ -13,6 +13,20 @@ export class UserProfileService extends Service {
|
|
13
13
|
return this.impl
|
14
14
|
}
|
15
15
|
|
16
|
+
async merge(anonymous_token: string) {
|
17
|
+
const rpc = this.resolve(RpcService) as RpcService
|
18
|
+
const response = await rpc.requestBuilder("api/v1/Users/anonymous/merge")
|
19
|
+
.sendPostJson({
|
20
|
+
anonymousToken: anonymous_token
|
21
|
+
})
|
22
|
+
|
23
|
+
if (ResponseUtils.isFail(response)) {
|
24
|
+
await ResponseUtils.throwError("Failed to merge anonymous user", response)
|
25
|
+
}
|
26
|
+
|
27
|
+
await this.fetch()
|
28
|
+
}
|
29
|
+
|
16
30
|
async fetch() {
|
17
31
|
const rpc = this.resolve(RpcService) as RpcService
|
18
32
|
const response = await rpc.requestBuilder("api/v1/Users/self2").sendGet()
|
@@ -105,12 +105,11 @@ export class AnswerImpl extends Answer {
|
|
105
105
|
// update answer
|
106
106
|
this._status = <AnswerStatus>answer.status
|
107
107
|
this._steps = <AnswerStepDto[]>answer.steps
|
108
|
-
|
109
108
|
|
110
109
|
if (this.getStep(StepType.GENERATE_ANSWER) !== undefined) {
|
111
110
|
const step = this.getStep(StepType.GENERATE_ANSWER)
|
112
111
|
const step_tokens = step?.tokens.join("")
|
113
|
-
if (this._answer !== step_tokens){
|
112
|
+
if (this._answer !== step_tokens) {
|
114
113
|
this._answer = step_tokens
|
115
114
|
|
116
115
|
this.dispatch({
|
@@ -122,15 +121,15 @@ export class AnswerImpl extends Answer {
|
|
122
121
|
|
123
122
|
if (this.getStep(StepType.SOURCES) !== undefined && this._sources === undefined) {
|
124
123
|
const sources_step = this.getStep(StepType.SOURCES)
|
125
|
-
this._sources = sources_step?.sources
|
126
|
-
|
124
|
+
this._sources = sources_step?.sources
|
125
|
+
|
127
126
|
this.dispatch({
|
128
127
|
type: AnswerEvent.UPDATED,
|
129
128
|
data: this
|
130
129
|
})
|
131
130
|
}
|
132
131
|
|
133
|
-
if (this.getStep(StepType.DONE) !== undefined){
|
132
|
+
if (this.getStep(StepType.DONE) !== undefined) {
|
134
133
|
const step = this.getStep(StepType.DONE)
|
135
134
|
this._timestamp = Date.parse(step!.end_at)
|
136
135
|
}
|
@@ -77,7 +77,7 @@ export class ChatImpl extends Chat implements Disposable {
|
|
77
77
|
}
|
78
78
|
|
79
79
|
// parse answer id from the server's response
|
80
|
-
const id = (await response!.json()).id
|
80
|
+
const id = (await response!.json() as { id: string }).id
|
81
81
|
|
82
82
|
// create answer implementation
|
83
83
|
const answer = await new AnswerImpl(this, this.context).initNew(id, message)
|
@@ -84,7 +84,9 @@ export class ChatsImpl extends Chats {
|
|
84
84
|
}
|
85
85
|
|
86
86
|
// parse workspace from the server's response
|
87
|
-
const content = (await response!.json()
|
87
|
+
const content = (await response!.json() as {
|
88
|
+
chat: ChatDto
|
89
|
+
}).chat as ChatDto
|
88
90
|
|
89
91
|
// create workspace implementation
|
90
92
|
const chat = new ChatImpl(this.context, this.organization)
|
@@ -72,7 +72,7 @@ export class FileImpl extends File implements Disposable {
|
|
72
72
|
)
|
73
73
|
}
|
74
74
|
|
75
|
-
return (await response!.json()).url
|
75
|
+
return (await response!.json() as { url: string }).url
|
76
76
|
}
|
77
77
|
|
78
78
|
public fetchAfter() {
|
@@ -93,7 +93,9 @@ export class FileImpl extends File implements Disposable {
|
|
93
93
|
}
|
94
94
|
|
95
95
|
const prev_progress = this._progress
|
96
|
-
this._progress = (await response!.json()
|
96
|
+
this._progress = (await response!.json() as {
|
97
|
+
progress: FileProgressDto
|
98
|
+
}).progress as FileProgressDto
|
97
99
|
|
98
100
|
if (prev_progress === undefined ||
|
99
101
|
(this.progress.success !== null && this.progress.completed_parts_count > prev_progress.completed_parts_count) ||
|
@@ -8,6 +8,7 @@ import { ResponseUtils } from "../../services/responseUtils"
|
|
8
8
|
import { File } from "./file"
|
9
9
|
import { FilesPage } from "./filesPage"
|
10
10
|
import { FilesPageImpl } from "./filesPage.impl"
|
11
|
+
// import { FormData } from "../../utils/request"
|
11
12
|
|
12
13
|
export class FilesImpl extends Files {
|
13
14
|
constructor(
|
@@ -20,7 +21,7 @@ export class FilesImpl extends Files {
|
|
20
21
|
// Object used as files page data, returned by "query"
|
21
22
|
public filesList?: FilesPage
|
22
23
|
|
23
|
-
async upload(files:
|
24
|
+
async upload(files: UploadFile[]): Promise<File[]> {
|
24
25
|
const loaded_files = []
|
25
26
|
for (const file of files) {
|
26
27
|
loaded_files.push(await this.internalUpload(file))
|
@@ -153,12 +154,19 @@ export class FilesImpl extends Files {
|
|
153
154
|
throw new Error("File upload, file is undefined or null")
|
154
155
|
}
|
155
156
|
|
157
|
+
let data: Blob | undefined = undefined
|
158
|
+
if (file instanceof globalThis.File) {
|
159
|
+
data = <Blob>file
|
160
|
+
} else {
|
161
|
+
data = new Blob([file.data])
|
162
|
+
}
|
163
|
+
|
156
164
|
// form data to send
|
157
165
|
const form = new FormData()
|
158
166
|
form.append("organizationId", this.workspace.organization.id)
|
159
167
|
form.append("workspaceId", this.workspace.id)
|
160
168
|
form.append("name", file.name)
|
161
|
-
form.append("file",
|
169
|
+
form.append("file", data!, file.name)
|
162
170
|
|
163
171
|
// send request to the server
|
164
172
|
const response = await this.context
|
@@ -172,7 +180,7 @@ export class FilesImpl extends Files {
|
|
172
180
|
}
|
173
181
|
|
174
182
|
// parse file from the server's response
|
175
|
-
const result = (await response!.json()).file as FileDto
|
183
|
+
const result = (await response!.json() as { file: FileDto }).file as FileDto
|
176
184
|
|
177
185
|
// create file implementation
|
178
186
|
const fileImpl = new FileImpl(this.context)
|
@@ -94,7 +94,9 @@ export class OrganizationImpl extends Organization implements Disposable {
|
|
94
94
|
)
|
95
95
|
}
|
96
96
|
|
97
|
-
return (await response!.json()
|
97
|
+
return (await response!.json() as {
|
98
|
+
members: UserDto[]
|
99
|
+
}).members as UserDto[]
|
98
100
|
}
|
99
101
|
|
100
102
|
async change(name: string, description: string): Promise<void> {
|
@@ -143,7 +145,7 @@ export class OrganizationImpl extends Organization implements Disposable {
|
|
143
145
|
data: this
|
144
146
|
})
|
145
147
|
}
|
146
|
-
|
148
|
+
|
147
149
|
async createInviteLink(emails: string[], accessGroups: string[]): Promise<void> {
|
148
150
|
const response = await this.context
|
149
151
|
.resolve(RpcService)
|