@neuralinnovations/dataisland-sdk 0.0.1-dev2 → 0.0.1-dev4
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/.editorconfig +4 -1
- package/.eslintrc.json +1 -1
- package/README.md +91 -2
- package/jest.config.ts +3 -3
- package/jest.setup.ts +2 -2
- package/package.json +3 -2
- package/src/appBuilder.ts +6 -6
- package/src/appSdk.ts +6 -6
- package/src/commands/startCommandHandler.ts +2 -2
- package/src/context.ts +3 -3
- package/src/credentials.ts +29 -7
- package/src/disposable.ts +3 -4
- package/src/dto/accessGroupResponse.ts +35 -0
- package/src/dto/chatResponse.ts +104 -0
- package/src/dto/userInfoResponse.ts +11 -1
- package/src/dto/workspacesResponse.ts +49 -0
- package/src/events.ts +13 -13
- package/src/index.ts +24 -12
- package/src/internal/app.impl.ts +25 -28
- package/src/internal/appBuilder.impl.ts +16 -16
- package/src/internal/createApp.impl.ts +3 -3
- package/src/services/commandService.ts +3 -3
- package/src/services/credentialService.ts +3 -3
- package/src/services/middlewareService.ts +4 -4
- package/src/services/organizationService.ts +18 -116
- package/src/services/requestBuilder.ts +40 -15
- package/src/services/responseUtils.ts +32 -0
- package/src/services/rpcService.ts +28 -11
- package/src/services/service.ts +10 -8
- package/src/services/userProfileService.ts +18 -66
- package/src/storages/chat.ts +21 -0
- package/src/storages/chats.ts +17 -0
- package/src/storages/file.impl.ts +69 -0
- package/src/storages/file.ts +28 -0
- package/src/storages/files.impl.ts +213 -0
- package/src/storages/files.ts +38 -0
- package/src/storages/filesPage.ts +27 -0
- package/src/storages/groups.impl.ts +337 -0
- package/src/storages/groups.ts +43 -0
- package/src/storages/organization.impl.ts +68 -0
- package/src/storages/organization.ts +33 -0
- package/src/storages/organizations.impl.ts +191 -0
- package/src/storages/organizations.ts +8 -28
- package/src/storages/userProfile.impl.ts +56 -0
- package/src/storages/userProfile.ts +2 -2
- package/src/storages/workspace.impl.ts +109 -0
- package/src/storages/workspace.ts +49 -0
- package/src/storages/workspaces.impl.ts +212 -0
- package/src/storages/workspaces.ts +53 -0
- package/test/commands.test.ts +8 -8
- package/test/data/test_file.pdf +0 -0
- package/test/disposable.test.ts +3 -3
- package/test/events.test.ts +4 -4
- package/test/files.test.ts +52 -0
- package/test/index.test.ts +42 -83
- package/test/organization.test.ts +57 -0
- package/test/registry.test.ts +8 -8
- package/test/services.test.ts +15 -15
- package/test/setup.ts +52 -0
- package/test/unitTest.test.ts +2 -2
- package/test/workspace.test.ts +71 -0
- package/src/services/organizationImpl.ts +0 -51
- package/src/services/organizationsImpl.ts +0 -55
- package/src/types.ts +0 -86
package/.editorconfig
CHANGED
@@ -18,5 +18,8 @@ indent_style = space
|
|
18
18
|
indent_size = 2
|
19
19
|
ij_javascript_use_semicolon_after_statement = false
|
20
20
|
ij_typescript_use_semicolon_after_statement = false
|
21
|
+
ij_typescript_use_double_quotes = true
|
22
|
+
ij_javascript_use_double_quotes = true
|
23
|
+
|
21
24
|
# Not currently supported by vscode, but is supported others, e.g. vim.
|
22
|
-
max_line_length = 80
|
25
|
+
max_line_length = 80
|
package/.eslintrc.json
CHANGED
package/README.md
CHANGED
@@ -1,7 +1,96 @@
|
|
1
1
|
# DataIsland Client SDK
|
2
2
|
|
3
|
-
|
3
|
+
The DataIsland Client SDK is a TypeScript library designed to seamlessly integrate DataIsland web services into websites.
|
4
4
|
|
5
|
+
## Table of contents
|
5
6
|
|
7
|
+
1. [Connect](#connect)
|
8
|
+
2. [Create app](#create-app)
|
9
|
+
3. [Use organizations](#use-organizations)
|
10
|
+
4. [Use chat](#use-chat)
|
11
|
+
5. [Use workspaces](#use-workspaces)
|
12
|
+
6. [Use files](#use-files)
|
13
|
+
7. [Use access groups](#use-access-groups)
|
14
|
+
8. [Use invites](#use-invites)
|
6
15
|
|
7
|
-
|
16
|
+
### Connect
|
17
|
+
|
18
|
+
For connecting this library to your website project simply install it using npm package manager.
|
19
|
+
|
20
|
+
`npm i @neuralinnovations/dataisland-sdk`
|
21
|
+
|
22
|
+
### Create app
|
23
|
+
|
24
|
+
You can initialize default app sdk instance using this code example.
|
25
|
+
|
26
|
+
```
|
27
|
+
const app = await appSdk("your-app-name", async (builder: AppBuilder) => {
|
28
|
+
builder.useHost(HOST)
|
29
|
+
builder.useCredential(new BearerCredential(TOKEN))
|
30
|
+
})
|
31
|
+
```
|
32
|
+
|
33
|
+
It is immpossible to create more than one app sdk intance with same name.
|
34
|
+
|
35
|
+
**HOST** is a DataIsland API url which can be passed using environment file.
|
36
|
+
|
37
|
+
Second required parameter for builder is Credentials. It is recomended to use Bearer credentials instance and pass your user Auth0 **TOKEN** in order to get access to API.
|
38
|
+
|
39
|
+
You can also add requests middlewares with builder options.
|
40
|
+
|
41
|
+
```
|
42
|
+
const app = await appSdk("your-app-name", async (builder: AppBuilder) => {
|
43
|
+
builder.useHost(YOUR_HOST)
|
44
|
+
builder.useAutomaticDataCollectionEnabled(false)
|
45
|
+
builder.useCredential(new BasicCredential("email", "password"))
|
46
|
+
builder.registerMiddleware(async (req, next) => {
|
47
|
+
req.headers.set("Your-header-name", "value")
|
48
|
+
return await next(req)
|
49
|
+
})
|
50
|
+
})
|
51
|
+
```
|
52
|
+
|
53
|
+
### Use organizations
|
54
|
+
|
55
|
+
Organization is a top data structure object, which represents a company or some group of people using our services.
|
56
|
+
It contains of users ( admin or regular ), workspaces with files ( folders with access control features ) and chats.
|
57
|
+
|
58
|
+
By default all user organizations are fetched with user profile during app sdk start. But if there are no organizations linked to the user, you should run Create organization flow. This flow requires organization name and description data, and also first workspace name and description data provided by user.
|
59
|
+
|
60
|
+
**NOTE** There are two types of DataIsland web api servers, public and private. On public servers users can create their own organization after first registration, on private servers you must register using invite links.
|
61
|
+
|
62
|
+
Default organization creation code example:
|
63
|
+
|
64
|
+
```
|
65
|
+
// create organization
|
66
|
+
const org = await app.organizations.create(
|
67
|
+
"your-organization-name",
|
68
|
+
"your-organization-description"
|
69
|
+
)
|
70
|
+
```
|
71
|
+
|
72
|
+
### Use workspaces
|
73
|
+
|
74
|
+
Workspaces are folder-like objects used to store files and controll access to it using acces groups. During creation you must pass organization Id, name and description of new workspace and regulation options. You can pass existing group ID or ask to create new group for this workspace in regulation section.
|
75
|
+
|
76
|
+
Default workspace creation example:
|
77
|
+
|
78
|
+
```
|
79
|
+
const wsPromise = org.workspaces.create(
|
80
|
+
"your-workspace-name",
|
81
|
+
"your-workspace-description",
|
82
|
+
regulation: {
|
83
|
+
isCreateNewGroup: boolean - "Bool option for new group creation"
|
84
|
+
newGroupName: string - "New group name"
|
85
|
+
groupIds: string[] - "Array of selected accessed groups IDs"
|
86
|
+
}
|
87
|
+
)
|
88
|
+
```
|
89
|
+
|
90
|
+
### Use files
|
91
|
+
|
92
|
+
### Use chat
|
93
|
+
|
94
|
+
### Use access groups
|
95
|
+
|
96
|
+
### Use Invites
|
package/jest.config.ts
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* https://jestjs.io/docs/configuration
|
4
4
|
*/
|
5
5
|
|
6
|
-
import type { Config } from
|
6
|
+
import type { Config } from "jest"
|
7
7
|
|
8
8
|
const config: Config = {
|
9
9
|
// All imported modules in your tests should be mocked automatically
|
@@ -25,7 +25,7 @@ const config: Config = {
|
|
25
25
|
// collectCoverageFrom: undefined,
|
26
26
|
|
27
27
|
// The directory where Jest should output its coverage files
|
28
|
-
coverageDirectory:
|
28
|
+
coverageDirectory: "coverage",
|
29
29
|
|
30
30
|
// An array of regexp pattern strings used to skip coverage collection
|
31
31
|
// coveragePathIgnorePatterns: [
|
@@ -134,7 +134,7 @@ const config: Config = {
|
|
134
134
|
// runner: "jest-runner",
|
135
135
|
|
136
136
|
// The paths to modules that run some code to configure or set up the testing environment before each test
|
137
|
-
setupFiles: [
|
137
|
+
setupFiles: ["./jest.setup.ts"]
|
138
138
|
|
139
139
|
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
140
140
|
// setupFilesAfterEnv: [],
|
package/jest.setup.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import * as dotenv from
|
2
|
-
dotenv.config({ path:
|
1
|
+
import * as dotenv from "dotenv"
|
2
|
+
dotenv.config({ path: ".env.test" })
|
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-dev4",
|
4
4
|
"description": "SDK for DataIsland project",
|
5
5
|
"licenses": [
|
6
6
|
{
|
@@ -14,7 +14,8 @@
|
|
14
14
|
"scripts": {
|
15
15
|
"build": "tsc",
|
16
16
|
"test": "jest",
|
17
|
-
"lint": "eslint --ext .ts,.tsx src"
|
17
|
+
"lint": "eslint --ext .ts,.tsx src test",
|
18
|
+
"lint:fix": "eslint --fix --ext .ts,.tsx src test"
|
18
19
|
},
|
19
20
|
"author": "Neural Innovations LTD",
|
20
21
|
"license": "Apache-2.0",
|
package/src/appBuilder.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { Middleware } from
|
2
|
-
import type { CredentialBase } from
|
3
|
-
import type { Service, ServiceContext } from
|
4
|
-
import type { Constructor } from
|
5
|
-
import { CommandHandler, Command } from
|
6
|
-
import { Context } from
|
1
|
+
import type { Middleware } from "./middleware"
|
2
|
+
import type { CredentialBase } from "./credentials"
|
3
|
+
import type { Service, ServiceContext } from "./services/service"
|
4
|
+
import type { Constructor } from "./internal/registry"
|
5
|
+
import { CommandHandler, Command } from "./services/commandService"
|
6
|
+
import { Context } from "./context"
|
7
7
|
|
8
8
|
/**
|
9
9
|
* DataIsland App builder.
|
package/src/appSdk.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { Lifetime } from
|
2
|
-
import type { CredentialBase } from
|
3
|
-
import { Context } from
|
4
|
-
import type { Constructor } from
|
5
|
-
import { Organizations } from
|
6
|
-
import { UserProfile } from
|
1
|
+
import type { Lifetime } from "./disposable"
|
2
|
+
import type { CredentialBase } from "./credentials"
|
3
|
+
import { Context } from "./context"
|
4
|
+
import type { Constructor } from "./internal/registry"
|
5
|
+
import { Organizations } from "./storages/organizations"
|
6
|
+
import { UserProfile } from "./storages/userProfile"
|
7
7
|
|
8
8
|
/**
|
9
9
|
* DataIsland App instance.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { CommandHandler, Command } from
|
2
|
-
import { UserProfileService } from
|
1
|
+
import { CommandHandler, Command } from "../services/commandService"
|
2
|
+
import { UserProfileService } from "../services/userProfileService"
|
3
3
|
|
4
4
|
export class StartCommand extends Command {}
|
5
5
|
|
package/src/context.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type Constructor, type Registry } from
|
2
|
-
import { type Lifetime } from
|
3
|
-
import { Command, CommandService } from
|
1
|
+
import { type Constructor, type Registry } from "./internal/registry"
|
2
|
+
import { type Lifetime } from "./disposable"
|
3
|
+
import { Command, CommandService } from "./services/commandService"
|
4
4
|
|
5
5
|
/**
|
6
6
|
* DataIsland App context.
|
package/src/credentials.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { MiddlewareService } from
|
2
|
-
import { type Lifetime } from
|
3
|
-
import { type Context } from
|
1
|
+
import { MiddlewareService } from "./services/middlewareService"
|
2
|
+
import { type Lifetime } from "./disposable"
|
3
|
+
import { type Context } from "./context"
|
4
4
|
|
5
5
|
/**
|
6
6
|
* DataIsland App credential.
|
@@ -29,11 +29,33 @@ export class BasicCredential extends CredentialBase {
|
|
29
29
|
onRegister(lifetime: Lifetime, context: Context): void {
|
30
30
|
const service = context.resolve(MiddlewareService)
|
31
31
|
if (service === undefined) {
|
32
|
-
throw new Error(
|
32
|
+
throw new Error("MiddlewareService is not registered.")
|
33
33
|
}
|
34
34
|
lifetime.add(
|
35
35
|
service.useMiddleware(async (req, next) => {
|
36
|
-
req.headers.set(
|
36
|
+
req.headers.set("Authorization", `Basic ${this.email}:${this.password}`)
|
37
|
+
return await next(req)
|
38
|
+
})
|
39
|
+
)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export class DebugCredential extends CredentialBase {
|
44
|
+
readonly token: string
|
45
|
+
|
46
|
+
constructor(token: string) {
|
47
|
+
super()
|
48
|
+
this.token = token
|
49
|
+
}
|
50
|
+
|
51
|
+
onRegister(lifetime: Lifetime, context: Context): void {
|
52
|
+
const service = context.resolve(MiddlewareService)
|
53
|
+
if (service === undefined) {
|
54
|
+
throw new Error("MiddlewareService is not registered.")
|
55
|
+
}
|
56
|
+
lifetime.add(
|
57
|
+
service.useMiddleware(async (req, next) => {
|
58
|
+
req.headers.set("Authorization", `Debug ${this.token}`)
|
37
59
|
return await next(req)
|
38
60
|
})
|
39
61
|
)
|
@@ -51,11 +73,11 @@ export class BearerCredential extends CredentialBase {
|
|
51
73
|
onRegister(lifetime: Lifetime, context: Context): void {
|
52
74
|
const service = context.resolve(MiddlewareService)
|
53
75
|
if (service === undefined) {
|
54
|
-
throw new Error(
|
76
|
+
throw new Error("MiddlewareService is not registered.")
|
55
77
|
}
|
56
78
|
lifetime.add(
|
57
79
|
service.useMiddleware(async (req, next) => {
|
58
|
-
req.headers.set(
|
80
|
+
req.headers.set("Authorization", `Bearer ${this.token}`)
|
59
81
|
return await next(req)
|
60
82
|
})
|
61
83
|
)
|
package/src/disposable.ts
CHANGED
@@ -9,7 +9,8 @@ export interface Disposable {
|
|
9
9
|
* Represents a lifetime.
|
10
10
|
*/
|
11
11
|
export class Lifetime {
|
12
|
-
constructor(private readonly container: DisposableContainer) {
|
12
|
+
constructor(private readonly container: DisposableContainer) {
|
13
|
+
}
|
13
14
|
|
14
15
|
/**
|
15
16
|
* Define a new nested disposable to this lifetime.
|
@@ -131,7 +132,7 @@ export class DisposableContainer implements Disposable {
|
|
131
132
|
*/
|
132
133
|
private _throwIfDisposed(): void {
|
133
134
|
if (this._isDisposed) {
|
134
|
-
throw new Error(
|
135
|
+
throw new Error("Object disposed")
|
135
136
|
}
|
136
137
|
}
|
137
138
|
}
|
@@ -147,5 +148,3 @@ export function disposable(action: () => void, target: unknown): Disposable {
|
|
147
148
|
action.call(target)
|
148
149
|
})
|
149
150
|
}
|
150
|
-
|
151
|
-
export const eternalLifetime = new DisposableContainer().lifetime
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { UserDto } from "./userInfoResponse"
|
2
|
+
|
3
|
+
|
4
|
+
export interface PermitsDto {
|
5
|
+
isAdmin: boolean;
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface RegulationDto {
|
9
|
+
isRegulateOrganization: boolean;
|
10
|
+
regulateWorkspaceIds: string[];
|
11
|
+
}
|
12
|
+
|
13
|
+
export interface AccessGroupDto {
|
14
|
+
id: string;
|
15
|
+
name: string;
|
16
|
+
type: number;
|
17
|
+
createdAt: number;
|
18
|
+
modifiedAt: number;
|
19
|
+
organizationId: string;
|
20
|
+
permits: PermitsDto;
|
21
|
+
regulation: RegulationDto;
|
22
|
+
membersCount: number;
|
23
|
+
}
|
24
|
+
|
25
|
+
export interface AccessGroupResponse {
|
26
|
+
group: AccessGroupDto;
|
27
|
+
members: UserDto[];
|
28
|
+
}
|
29
|
+
|
30
|
+
export interface AccessGroupsResponse {
|
31
|
+
groups: AccessGroupDto[];
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
export interface SourceDto {
|
3
|
+
id: string;
|
4
|
+
name: string;
|
5
|
+
url: string;
|
6
|
+
content: string;
|
7
|
+
page: number;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface AnswerDto {
|
11
|
+
id: string;
|
12
|
+
chatId: string;
|
13
|
+
question: string;
|
14
|
+
context: string;
|
15
|
+
sources: SourceDto[];
|
16
|
+
timestamp: number;
|
17
|
+
}
|
18
|
+
|
19
|
+
export interface ChatDto {
|
20
|
+
id: string;
|
21
|
+
name: string;
|
22
|
+
createdAt: number;
|
23
|
+
modifiedAt: number;
|
24
|
+
userId: string;
|
25
|
+
organizationId: string;
|
26
|
+
workspaceId: string;
|
27
|
+
answers: AnswerDto[];
|
28
|
+
}
|
29
|
+
|
30
|
+
export interface ChatListResponse {
|
31
|
+
chats: ChatDto[]
|
32
|
+
}
|
33
|
+
|
34
|
+
export enum AnswerStatus {
|
35
|
+
RUNNING = 0,
|
36
|
+
SUCCESS = 1,
|
37
|
+
CANCELED = 2,
|
38
|
+
FAIL = 3,
|
39
|
+
}
|
40
|
+
|
41
|
+
export interface AnswerStepDto{
|
42
|
+
id: string;
|
43
|
+
type: StepType;
|
44
|
+
status: StepStatus;
|
45
|
+
start_at: string;
|
46
|
+
end_at: string;
|
47
|
+
tokens: string[];
|
48
|
+
sources: SourceDto[];
|
49
|
+
}
|
50
|
+
|
51
|
+
export interface FetchAnswerResponse {
|
52
|
+
id: string;
|
53
|
+
status: AnswerStatus;
|
54
|
+
steps: AnswerStepDto[];
|
55
|
+
}
|
56
|
+
|
57
|
+
export interface FetchTokensResponse {
|
58
|
+
id: string;
|
59
|
+
step_id: string;
|
60
|
+
step_status: number;
|
61
|
+
step_tokens: string[];
|
62
|
+
}
|
63
|
+
|
64
|
+
export interface AnswerSourcesResponse {
|
65
|
+
chat_uid: string;
|
66
|
+
uid: string;
|
67
|
+
step_id: string;
|
68
|
+
sources: SourceDto[];
|
69
|
+
}
|
70
|
+
|
71
|
+
export enum StepStatus {
|
72
|
+
RUNNING = 0,
|
73
|
+
SUCCESS = 1,
|
74
|
+
FAIL = 2,
|
75
|
+
CANCELED = 3,
|
76
|
+
}
|
77
|
+
|
78
|
+
export enum StepType {
|
79
|
+
PREPARE = 0,
|
80
|
+
SOURCES = 1,
|
81
|
+
GENERATE_ANSWER = 6,
|
82
|
+
FINALIZE_RESULT = 9,
|
83
|
+
DONE = 10,
|
84
|
+
}
|
85
|
+
|
86
|
+
export class StepTypeInfo {
|
87
|
+
public static hasTokens(type: StepType): boolean {
|
88
|
+
switch (type) {
|
89
|
+
case StepType.GENERATE_ANSWER:
|
90
|
+
case StepType.DONE:
|
91
|
+
case StepType.FINALIZE_RESULT:
|
92
|
+
return true
|
93
|
+
}
|
94
|
+
return false
|
95
|
+
}
|
96
|
+
|
97
|
+
public static hasSources(type: StepType): boolean {
|
98
|
+
switch (type) {
|
99
|
+
case StepType.SOURCES:
|
100
|
+
return true
|
101
|
+
}
|
102
|
+
return false
|
103
|
+
}
|
104
|
+
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { WorkspaceDto } from "./workspacesResponse"
|
2
|
+
|
1
3
|
export interface UserInfoResponse {
|
2
4
|
adminInOrganization: string[]
|
3
5
|
organizations: OrganizationDto[]
|
@@ -10,7 +12,7 @@ export interface UserDto {
|
|
10
12
|
created_at: number
|
11
13
|
modified_at: number
|
12
14
|
profile: ProfileDto
|
13
|
-
settings
|
15
|
+
settings?: UserSettings | null
|
14
16
|
}
|
15
17
|
|
16
18
|
export interface ProfileDto {
|
@@ -35,3 +37,11 @@ export interface OrganizationDto {
|
|
35
37
|
membersCount: number
|
36
38
|
profile: OrganizationProfileDto
|
37
39
|
}
|
40
|
+
|
41
|
+
export interface OrganizationWorkspaces extends OrganizationDto {
|
42
|
+
workspaces: WorkspaceDto[]
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface MembersResponse {
|
46
|
+
members: UserDto
|
47
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { WorkspaceId } from "../storages/workspaces"
|
2
|
+
import { FileId } from "../storages/file"
|
3
|
+
|
4
|
+
export interface WorkspaceProfileDto {
|
5
|
+
name: string
|
6
|
+
description: string
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface WorkspaceDto {
|
10
|
+
id: WorkspaceId
|
11
|
+
createdAt: number
|
12
|
+
modifiedAt: number
|
13
|
+
profile: WorkspaceProfileDto
|
14
|
+
}
|
15
|
+
|
16
|
+
export interface WorkspacesResponse {
|
17
|
+
workspaces: WorkspaceDto[]
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface FileUrlDto {
|
21
|
+
url: string
|
22
|
+
}
|
23
|
+
|
24
|
+
export interface FileProgressDto {
|
25
|
+
file_id: FileId
|
26
|
+
file_parts_count: number
|
27
|
+
completed_parts_count: number
|
28
|
+
success: boolean
|
29
|
+
error?: string
|
30
|
+
}
|
31
|
+
|
32
|
+
export interface FileDto {
|
33
|
+
id: string
|
34
|
+
createdAt: number
|
35
|
+
modifiedAt: number
|
36
|
+
name: string
|
37
|
+
description: string
|
38
|
+
url: string
|
39
|
+
hash: string
|
40
|
+
organizationId: string
|
41
|
+
workspaceId: string
|
42
|
+
isProcessedSuccessfully: boolean
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface FileListResponse {
|
46
|
+
files: FileDto[]
|
47
|
+
totalFilesCount: number
|
48
|
+
filesPerPage: number
|
49
|
+
}
|
package/src/events.ts
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
import { type Disposable, DisposableContainer } from
|
1
|
+
import { type Disposable, DisposableContainer } from "./disposable"
|
2
2
|
|
3
|
-
export interface Input<
|
4
|
-
type?:
|
5
|
-
data:
|
3
|
+
export interface Input<EventType, DataType> {
|
4
|
+
type?: EventType
|
5
|
+
data: DataType
|
6
6
|
}
|
7
7
|
|
8
|
-
export interface Event<
|
8
|
+
export interface Event<EventType, DataType> extends Input<EventType, DataType> {
|
9
9
|
unsubscribe: () => void
|
10
10
|
}
|
11
11
|
|
12
|
-
export interface EventSubscriber<
|
13
|
-
subscribe: (callback: (event: Event<
|
12
|
+
export interface EventSubscriber<EventType, DataType> {
|
13
|
+
subscribe: (callback: (event: Event<EventType, DataType>) => void, type?: EventType) => Disposable
|
14
14
|
}
|
15
15
|
|
16
|
-
export class EventDispatcher<
|
16
|
+
export class EventDispatcher<EventType, DataType> implements EventSubscriber<EventType, DataType> {
|
17
17
|
private _listeners: Array<{
|
18
|
-
callback: (value: Event<
|
18
|
+
callback: (value: Event<EventType, DataType>) => void
|
19
19
|
disposable: Disposable
|
20
20
|
}> = []
|
21
21
|
|
22
|
-
dispatch(input: Input<
|
22
|
+
dispatch(input: Input<EventType, DataType>): void {
|
23
23
|
this._listeners.slice().forEach(it => {
|
24
24
|
const value = {
|
25
25
|
type: input.type,
|
@@ -27,16 +27,16 @@ export class EventDispatcher<ET, DT> implements EventSubscriber<ET, DT> {
|
|
27
27
|
unsubscribe: () => {
|
28
28
|
it.disposable.dispose()
|
29
29
|
}
|
30
|
-
} satisfies Event<
|
30
|
+
} satisfies Event<EventType, DataType>
|
31
31
|
it.callback(value)
|
32
32
|
})
|
33
33
|
}
|
34
34
|
|
35
|
-
subscribe(callback: (event: Event<
|
35
|
+
subscribe(callback: (event: Event<EventType, DataType>) => void, type?: EventType): Disposable {
|
36
36
|
const container = new DisposableContainer()
|
37
37
|
if (type !== undefined) {
|
38
38
|
const cb = callback
|
39
|
-
const listener = (evt: Event<
|
39
|
+
const listener = (evt: Event<EventType, DataType>): void => {
|
40
40
|
if (evt.type === type) {
|
41
41
|
cb(evt)
|
42
42
|
}
|
package/src/index.ts
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
-
import { version } from
|
2
|
-
import { _createApp } from
|
3
|
-
import { type AppBuilder } from
|
4
|
-
import { type AppSdk } from
|
1
|
+
import { version } from "../package.json"
|
2
|
+
import { _createApp } from "./internal/createApp.impl"
|
3
|
+
import { type AppBuilder } from "./appBuilder"
|
4
|
+
import { type AppSdk } from "./appSdk"
|
5
5
|
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export * from
|
9
|
-
export * from
|
10
|
-
export * from
|
11
|
-
export * from
|
6
|
+
export * from "./events"
|
7
|
+
export * from "./disposable"
|
8
|
+
export * from "./credentials"
|
9
|
+
export * from "./appSdk"
|
10
|
+
export * from "./storages/organizations"
|
11
|
+
export * from "./storages/organization"
|
12
|
+
export * from "./storages/workspaces"
|
13
|
+
export * from "./storages/workspace"
|
14
|
+
export * from "./storages/groups"
|
15
|
+
export * from "./storages/userProfile"
|
16
|
+
export * from "./storages/files"
|
17
|
+
export * from "./storages/file"
|
18
|
+
export * from "./storages/filesPage"
|
19
|
+
export * from "./storages/chats"
|
20
|
+
export * from "./storages/chat"
|
12
21
|
|
13
22
|
const _appsNotReady = new Map<string, Promise<AppSdk>>()
|
14
23
|
const _appsReady = new Map<string, AppSdk>()
|
@@ -21,12 +30,12 @@ export const SDK_VERSION = version
|
|
21
30
|
/**
|
22
31
|
* Default DataIsland App name.
|
23
32
|
*/
|
24
|
-
export const DEFAULT_NAME =
|
33
|
+
export const DEFAULT_NAME = "[DEFAULT]"
|
25
34
|
|
26
35
|
/**
|
27
36
|
* Default DataIsland App host.
|
28
37
|
*/
|
29
|
-
export const DEFAULT_HOST =
|
38
|
+
export const DEFAULT_HOST = "https://api.dataisland.com.ua"
|
30
39
|
|
31
40
|
export function sdks(): AppSdk[] {
|
32
41
|
return Array.from(_appsReady.values())
|
@@ -75,3 +84,6 @@ export async function appSdk(
|
|
75
84
|
}
|
76
85
|
return await appPromise
|
77
86
|
}
|
87
|
+
|
88
|
+
export { File } from "./storages/file"
|
89
|
+
export { FilesPage } from "./storages/filesPage"
|