@neuralinnovations/dataisland-sdk 0.0.1-dev4 → 0.0.1-dev6
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/README.md +53 -35
- package/package.json +1 -1
- package/src/{appSdk.ts → dataIslandApp.ts} +1 -1
- package/src/index.ts +13 -10
- package/src/internal/app.impl.ts +3 -3
- package/src/internal/createApp.impl.ts +4 -4
- package/src/unitTest.ts +12 -1
- package/test/commands.test.ts +4 -4
- package/test/index.test.ts +16 -16
- package/test/organization.test.ts +2 -2
- package/test/services.test.ts +4 -4
- package/test/setup.ts +6 -6
- package/test/unitTest.test.ts +7 -7
package/README.md
CHANGED
@@ -4,7 +4,7 @@ The DataIsland Client SDK is a TypeScript library designed to seamlessly integra
|
|
4
4
|
|
5
5
|
## Table of contents
|
6
6
|
|
7
|
-
1. [
|
7
|
+
1. [Install](#install)
|
8
8
|
2. [Create app](#create-app)
|
9
9
|
3. [Use organizations](#use-organizations)
|
10
10
|
4. [Use chat](#use-chat)
|
@@ -13,41 +13,49 @@ The DataIsland Client SDK is a TypeScript library designed to seamlessly integra
|
|
13
13
|
7. [Use access groups](#use-access-groups)
|
14
14
|
8. [Use invites](#use-invites)
|
15
15
|
|
16
|
-
###
|
16
|
+
### Install
|
17
17
|
|
18
18
|
For connecting this library to your website project simply install it using npm package manager.
|
19
19
|
|
20
|
-
|
20
|
+
```shell
|
21
|
+
npm i @neuralinnovations/dataisland-sdk
|
22
|
+
```
|
21
23
|
|
22
24
|
### Create app
|
23
25
|
|
24
26
|
You can initialize default app sdk instance using this code example.
|
25
27
|
|
26
|
-
```
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
```typescript
|
29
|
+
// default production app sdk instance
|
30
|
+
const dataIslandSdk = await dataIslandApp()
|
31
|
+
|
32
|
+
// specific app sdk instance
|
33
|
+
// use this if you have more than one app
|
34
|
+
// or using custom api server
|
35
|
+
const yourAppNameSdk = await dataIslandApp('your-app-name', async (builder: AppBuilder) => {
|
36
|
+
builder.useHost(HOST)
|
37
|
+
builder.useCredential(new BearerCredential(TOKEN))
|
38
|
+
})
|
31
39
|
```
|
32
40
|
|
33
|
-
|
41
|
+
_It is immpossible to create more than one app sdk intance with same name._
|
34
42
|
|
35
43
|
**HOST** is a DataIsland API url which can be passed using environment file.
|
36
44
|
|
37
|
-
Second required parameter for builder is Credentials. It is recomended to use Bearer credentials instance and pass your user
|
45
|
+
Second required parameter for builder is Credentials. It is recomended to use Bearer credentials instance and pass your user **TOKEN** in order to get access to API.
|
38
46
|
|
39
47
|
You can also add requests middlewares with builder options.
|
40
48
|
|
41
|
-
```
|
42
|
-
const app = await
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
```typescript
|
50
|
+
const app = await dataIslandApp('your-app-name', async (builder: AppBuilder) => {
|
51
|
+
builder.useHost(YOUR_HOST)
|
52
|
+
builder.useAutomaticDataCollectionEnabled(false)
|
53
|
+
builder.useCredential(new BasicCredential('email', 'password'))
|
54
|
+
builder.registerMiddleware(async (req, next) => {
|
55
|
+
req.headers.set('Your-header-name', 'value')
|
56
|
+
return await next(req)
|
57
|
+
})
|
58
|
+
})
|
51
59
|
```
|
52
60
|
|
53
61
|
### Use organizations
|
@@ -61,12 +69,12 @@ By default all user organizations are fetched with user profile during app sdk s
|
|
61
69
|
|
62
70
|
Default organization creation code example:
|
63
71
|
|
64
|
-
```
|
72
|
+
```typescript
|
65
73
|
// create organization
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
74
|
+
const org = await app.organizations.create(
|
75
|
+
'your-organization-name',
|
76
|
+
'your-organization-description'
|
77
|
+
)
|
70
78
|
```
|
71
79
|
|
72
80
|
### Use workspaces
|
@@ -75,16 +83,26 @@ Workspaces are folder-like objects used to store files and controll access to it
|
|
75
83
|
|
76
84
|
Default workspace creation example:
|
77
85
|
|
78
|
-
```
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
```typescript
|
87
|
+
// create workspace
|
88
|
+
// isCreateNewGroup: boolean - "Bool option for new group creation"
|
89
|
+
// newGroupName: string - "New group name"
|
90
|
+
// groupIds: string[] - "Array of selected accessed groups IDs"
|
91
|
+
const workspace = await org.workspaces.create(
|
92
|
+
// name of new workspace
|
93
|
+
'your-workspace-name',
|
94
|
+
// description of new workspace
|
95
|
+
'your-workspace-description',
|
96
|
+
// regulation options
|
97
|
+
{
|
98
|
+
// create new group for this workspace
|
99
|
+
isCreateNewGroup: true,
|
100
|
+
// new group name
|
101
|
+
newGroupName: 'your-new-group-name',
|
102
|
+
// array of selected groups IDs
|
103
|
+
groupIds: []
|
104
|
+
}
|
105
|
+
)
|
88
106
|
```
|
89
107
|
|
90
108
|
### Use files
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import { version } from "../package.json"
|
2
2
|
import { _createApp } from "./internal/createApp.impl"
|
3
3
|
import { type AppBuilder } from "./appBuilder"
|
4
|
-
import { type
|
4
|
+
import { type DataIslandApp } from "./dataIslandApp"
|
5
5
|
|
6
6
|
export * from "./events"
|
7
7
|
export * from "./disposable"
|
8
8
|
export * from "./credentials"
|
9
|
-
export * from "./
|
9
|
+
export * from "./dataIslandApp"
|
10
10
|
export * from "./storages/organizations"
|
11
11
|
export * from "./storages/organization"
|
12
12
|
export * from "./storages/workspaces"
|
@@ -19,8 +19,8 @@ export * from "./storages/filesPage"
|
|
19
19
|
export * from "./storages/chats"
|
20
20
|
export * from "./storages/chat"
|
21
21
|
|
22
|
-
const _appsNotReady = new Map<string, Promise<
|
23
|
-
const _appsReady = new Map<string,
|
22
|
+
const _appsNotReady = new Map<string, Promise<DataIslandApp>>()
|
23
|
+
const _appsReady = new Map<string, DataIslandApp>()
|
24
24
|
|
25
25
|
/**
|
26
26
|
* Current SDK version.
|
@@ -37,7 +37,10 @@ export const DEFAULT_NAME = "[DEFAULT]"
|
|
37
37
|
*/
|
38
38
|
export const DEFAULT_HOST = "https://api.dataisland.com.ua"
|
39
39
|
|
40
|
-
|
40
|
+
/**
|
41
|
+
* Returns a list of DataIsland App instances.
|
42
|
+
*/
|
43
|
+
export function dataIslandInstances(): DataIslandApp[] {
|
41
44
|
return Array.from(_appsReady.values())
|
42
45
|
}
|
43
46
|
|
@@ -48,19 +51,19 @@ export function sdks(): AppSdk[] {
|
|
48
51
|
* @returns A DataIsland App instance.
|
49
52
|
* @example
|
50
53
|
* ```js
|
51
|
-
* import {
|
54
|
+
* import { dataIslandApp, DEFAULT_NAME } from '@neuralinnovations/dataisland-sdk'
|
52
55
|
*
|
53
|
-
* const app = await
|
56
|
+
* const app = await dataIslandApp(DEFAULT_NAME, builder => {
|
54
57
|
* builder.useHost("https://dataisland.com.ua")
|
55
58
|
* builder.useAutomaticDataCollectionEnabled(true)
|
56
59
|
* builder.useCredential(new BasicCredential("email", "password"))
|
57
60
|
* })
|
58
61
|
* ```
|
59
62
|
*/
|
60
|
-
export async function
|
63
|
+
export async function dataIslandApp(
|
61
64
|
name?: string,
|
62
65
|
setup?: (builder: AppBuilder) => Promise<void>
|
63
|
-
): Promise<
|
66
|
+
): Promise<DataIslandApp> {
|
64
67
|
name = name ?? DEFAULT_NAME
|
65
68
|
|
66
69
|
let appPromise = _appsNotReady.get(name)
|
@@ -78,7 +81,7 @@ export async function appSdk(
|
|
78
81
|
} else {
|
79
82
|
if (setup !== undefined) {
|
80
83
|
throw new Error(
|
81
|
-
`
|
84
|
+
`DataIsland ${name} is initializing. You can't setup the same again.`
|
82
85
|
)
|
83
86
|
}
|
84
87
|
}
|
package/src/internal/app.impl.ts
CHANGED
@@ -8,7 +8,7 @@ import { type Service, ServiceContext } from "../services/service"
|
|
8
8
|
import { CredentialService } from "../services/credentialService"
|
9
9
|
import { MiddlewareService } from "../services/middlewareService"
|
10
10
|
import { type CredentialBase } from "../credentials"
|
11
|
-
import {
|
11
|
+
import { DataIslandApp } from "../dataIslandApp"
|
12
12
|
import { RpcService } from "../services/rpcService"
|
13
13
|
import { CommandService } from "../services/commandService"
|
14
14
|
import {
|
@@ -21,7 +21,7 @@ import { Organizations } from "../storages/organizations"
|
|
21
21
|
import { UserProfile } from "../storages/userProfile"
|
22
22
|
import { isUnitTest, UnitTest } from "../unitTest"
|
23
23
|
|
24
|
-
export class
|
24
|
+
export class DataIslandAppImpl extends DataIslandApp {
|
25
25
|
readonly name: string
|
26
26
|
private _host: string = DEFAULT_HOST
|
27
27
|
private _automaticDataCollectionEnabled: boolean = true
|
@@ -178,7 +178,7 @@ export class AppImplementation extends AppSdk {
|
|
178
178
|
|
179
179
|
// log app initialized
|
180
180
|
if (!isUnitTest(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)) {
|
181
|
-
console.log(`
|
181
|
+
console.log(`DataIsland ${this.name} initialized`)
|
182
182
|
}
|
183
183
|
}
|
184
184
|
}
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { DataIslandAppImpl } from "./app.impl"
|
2
2
|
import { type AppBuilder } from "../appBuilder"
|
3
|
-
import {
|
3
|
+
import { DataIslandApp } from "../dataIslandApp"
|
4
4
|
|
5
5
|
export async function _createApp(
|
6
6
|
name: string,
|
7
7
|
setup?: (builder: AppBuilder) => Promise<void>
|
8
|
-
): Promise<
|
9
|
-
const app = new
|
8
|
+
): Promise<DataIslandApp> {
|
9
|
+
const app = new DataIslandAppImpl(name)
|
10
10
|
await app.initialize(setup)
|
11
11
|
return app
|
12
12
|
}
|
package/src/unitTest.ts
CHANGED
@@ -9,7 +9,7 @@ export enum UnitTest {
|
|
9
9
|
export type UnitTestProfileSyncAction = () => void
|
10
10
|
export type UnitTestProfileAsyncAction = () => Promise<void>
|
11
11
|
|
12
|
-
|
12
|
+
class AppSdkUnitTest {
|
13
13
|
private static _stack: UnitTest[] = [UnitTest.DO_NOTHING]
|
14
14
|
|
15
15
|
public static get current(): UnitTest {
|
@@ -37,6 +37,17 @@ export class AppSdkUnitTest {
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
+
export const appTest = async (
|
41
|
+
unitTest: UnitTest = UnitTest.DEFAULT,
|
42
|
+
func: UnitTestProfileSyncAction | UnitTestProfileAsyncAction
|
43
|
+
): Promise<void> => {
|
44
|
+
await AppSdkUnitTest.test(unitTest, func)
|
45
|
+
}
|
46
|
+
|
47
|
+
export const appTestCurrent = (): UnitTest => {
|
48
|
+
return AppSdkUnitTest.current
|
49
|
+
}
|
50
|
+
|
40
51
|
export const isUnitTest = (mask: UnitTest): boolean => {
|
41
52
|
return (AppSdkUnitTest.current & mask) == mask
|
42
53
|
}
|
package/test/commands.test.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Command, CommandHandler } from "../src/services/commandService"
|
2
|
-
import {
|
3
|
-
import {
|
2
|
+
import { dataIslandApp } from "../src"
|
3
|
+
import { appTest, UnitTest } from "../src/unitTest"
|
4
4
|
|
5
5
|
class Cmd extends Command {
|
6
6
|
constructor(public readonly name: string = "test") {
|
@@ -15,8 +15,8 @@ class CmdHandler extends CommandHandler<Cmd> {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
test("Commands test", async () => {
|
18
|
-
await
|
19
|
-
const app = await
|
18
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
19
|
+
const app = await dataIslandApp("test-commands", async builder => {
|
20
20
|
builder.registerCommand(Cmd, context => new CmdHandler(context))
|
21
21
|
})
|
22
22
|
expect(app.context.execute(new Cmd("test-command"))).toBeDefined()
|
package/test/index.test.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { version } from "../package.json"
|
2
2
|
import {
|
3
|
-
|
3
|
+
DataIslandApp,
|
4
4
|
BasicCredential,
|
5
|
-
|
5
|
+
dataIslandApp,
|
6
6
|
SDK_VERSION,
|
7
7
|
DEFAULT_NAME,
|
8
8
|
DebugCredential
|
@@ -11,7 +11,7 @@ import { MiddlewareService } from "../src/services/middlewareService"
|
|
11
11
|
import { CredentialService } from "../src/services/credentialService"
|
12
12
|
import { RpcService } from "../src/services/rpcService"
|
13
13
|
import { AppBuilder } from "../src/appBuilder"
|
14
|
-
import { UnitTest,
|
14
|
+
import { UnitTest, appTest } from "../src/unitTest"
|
15
15
|
import { HOST, randomHash, TOKEN } from "./setup"
|
16
16
|
|
17
17
|
test("SDK_VERSION", () => {
|
@@ -20,7 +20,7 @@ test("SDK_VERSION", () => {
|
|
20
20
|
|
21
21
|
test("Default SDK", async () => {
|
22
22
|
// default
|
23
|
-
const app = await
|
23
|
+
const app = await dataIslandApp(DEFAULT_NAME, async (builder: AppBuilder) => {
|
24
24
|
builder.useHost(HOST)
|
25
25
|
builder.useCredential(new DebugCredential(TOKEN))
|
26
26
|
})
|
@@ -28,8 +28,8 @@ test("Default SDK", async () => {
|
|
28
28
|
})
|
29
29
|
|
30
30
|
test("SDK, middleware", async () => {
|
31
|
-
await
|
32
|
-
const app = await
|
31
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
32
|
+
const app = await dataIslandApp("test-settings", async (builder: AppBuilder) => {
|
33
33
|
builder.useHost("https://test.com")
|
34
34
|
builder.useAutomaticDataCollectionEnabled(false)
|
35
35
|
builder.useCredential(new BasicCredential("email", "password"))
|
@@ -45,8 +45,8 @@ test("SDK, middleware", async () => {
|
|
45
45
|
})
|
46
46
|
|
47
47
|
test("SDK, services", async () => {
|
48
|
-
await
|
49
|
-
const app = await
|
48
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
49
|
+
const app = await dataIslandApp("test-sdk")
|
50
50
|
const middlewareService = app.resolve(MiddlewareService)
|
51
51
|
expect(middlewareService).not.toBeUndefined()
|
52
52
|
expect(app.resolve(MiddlewareService)).toBe(middlewareService)
|
@@ -57,8 +57,8 @@ test("SDK, services", async () => {
|
|
57
57
|
})
|
58
58
|
|
59
59
|
test("SDK, middleware", async () => {
|
60
|
-
await
|
61
|
-
const app = await
|
60
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
61
|
+
const app = await dataIslandApp("test-middleware")
|
62
62
|
const middlewareService = app.resolve(MiddlewareService)
|
63
63
|
expect(middlewareService).not.toBeUndefined()
|
64
64
|
expect(app.resolve(MiddlewareService)).toBe(middlewareService)
|
@@ -93,15 +93,15 @@ test("SDK, middleware", async () => {
|
|
93
93
|
})
|
94
94
|
|
95
95
|
test("SDK, it is impossible to setup the same application", async () => {
|
96
|
-
await
|
96
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
97
97
|
// this test is not stable if you run all tests at once
|
98
98
|
// because the app is cached all app instances
|
99
99
|
// we use a random identifier every time
|
100
100
|
const testId = `test-setup-${randomHash()}`
|
101
|
-
const promise =
|
101
|
+
const promise = dataIslandApp(testId).then(() => {
|
102
102
|
})
|
103
103
|
await expect(
|
104
|
-
|
104
|
+
dataIslandApp(testId, async () => {
|
105
105
|
})
|
106
106
|
).rejects.toThrow()
|
107
107
|
await promise
|
@@ -109,14 +109,14 @@ test("SDK, it is impossible to setup the same application", async () => {
|
|
109
109
|
})
|
110
110
|
|
111
111
|
test("SDK, setup and get this app", async () => {
|
112
|
-
await
|
112
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
113
113
|
// this test is not stable if you run all tests at once
|
114
114
|
// because the app is cached all app instances
|
115
115
|
// we use a random identifier every time
|
116
116
|
const testId = `test-get-${randomHash()}`
|
117
|
-
const promise =
|
117
|
+
const promise = dataIslandApp(testId).then(() => {
|
118
118
|
})
|
119
|
-
await expect(
|
119
|
+
await expect(dataIslandApp(testId)).resolves.toBeInstanceOf(DataIslandApp)
|
120
120
|
await promise
|
121
121
|
})
|
122
122
|
})
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { dataIslandApp, DebugCredential } from "../src"
|
2
2
|
import { HOST, randomHash, TOKEN } from "./setup"
|
3
3
|
import { OrganizationImpl } from "../src/storages/organization.impl"
|
4
4
|
|
@@ -7,7 +7,7 @@ test("Organization", async () => {
|
|
7
7
|
const randomName = `org-test-${randomHash()}`
|
8
8
|
|
9
9
|
// create app
|
10
|
-
const app = await
|
10
|
+
const app = await dataIslandApp(randomName, async builder => {
|
11
11
|
builder.useHost(HOST)
|
12
12
|
builder.useCredential(new DebugCredential(TOKEN))
|
13
13
|
})
|
package/test/services.test.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { dataIslandApp, BasicCredential, DefaultCredential } from "../src"
|
2
2
|
import { CredentialService } from "../src/services/credentialService"
|
3
3
|
import { MiddlewareService } from "../src/services/middlewareService"
|
4
|
-
import { UnitTest,
|
4
|
+
import { UnitTest, appTest } from "../src/unitTest"
|
5
5
|
|
6
6
|
test("CredentialService", async () => {
|
7
|
-
await
|
8
|
-
const app = await
|
7
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
8
|
+
const app = await dataIslandApp("test-services", async builder => {
|
9
9
|
builder.env.unitTest = UnitTest.DO_NOT_START
|
10
10
|
})
|
11
11
|
const credentialService = app.resolve(CredentialService)
|
package/test/setup.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { Organization } from "../src
|
3
|
-
import { Workspace } from "../src
|
1
|
+
import { dataIslandApp, DataIslandApp, DebugCredential } from "../src"
|
2
|
+
import { Organization } from "../src"
|
3
|
+
import { Workspace } from "../src"
|
4
4
|
|
5
5
|
export const HOST = <string>process.env.HOST
|
6
6
|
export const TOKEN = <string>process.env.TOKEN
|
@@ -10,13 +10,13 @@ export const randomHash = (length: number = 5) => {
|
|
10
10
|
return `name-${((Math.random() * Math.pow(10, length)) | 0).toString(16)}`
|
11
11
|
}
|
12
12
|
|
13
|
-
export const testInOrganization = async (func: (app:
|
13
|
+
export const testInOrganization = async (func: (app: DataIslandApp, org: Organization) => Promise<void>, config ?: {
|
14
14
|
host: string,
|
15
15
|
token: string
|
16
16
|
}
|
17
17
|
): Promise<void> => {
|
18
18
|
const randomName = `org-name-${randomHash()}`
|
19
|
-
const app = await
|
19
|
+
const app = await dataIslandApp(randomName, async builder => {
|
20
20
|
builder.useHost(config?.host ?? HOST)
|
21
21
|
builder.useCredential(new DebugCredential(config?.token ?? TOKEN))
|
22
22
|
})
|
@@ -35,7 +35,7 @@ export const testInOrganization = async (func: (app: AppSdk, org: Organization)
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
export const testInWorkspace = async (func: (app:
|
38
|
+
export const testInWorkspace = async (func: (app: DataIslandApp, org: Organization, workspace: Workspace)
|
39
39
|
=> Promise<void>, config?: {
|
40
40
|
host: string,
|
41
41
|
token: string,
|
package/test/unitTest.test.ts
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
import {
|
1
|
+
import { appTest, appTestCurrent, UnitTest } from "../src/unitTest"
|
2
2
|
|
3
3
|
test("SDK, unitTest", async () => {
|
4
|
-
expect(
|
4
|
+
expect(appTestCurrent()).toBe(UnitTest.DO_NOTHING)
|
5
5
|
expect(
|
6
|
-
await
|
7
|
-
expect(
|
6
|
+
await appTest(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG, () => {
|
7
|
+
expect(appTestCurrent()).toBe(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)
|
8
8
|
})
|
9
9
|
)
|
10
10
|
expect(
|
11
|
-
await
|
11
|
+
await appTest(
|
12
12
|
UnitTest.DO_NOT_PRINT_INITIALIZED_LOG,
|
13
13
|
async () => {
|
14
|
-
expect(
|
14
|
+
expect(appTestCurrent()).toBe(
|
15
15
|
UnitTest.DO_NOT_PRINT_INITIALIZED_LOG
|
16
16
|
)
|
17
17
|
}
|
18
18
|
)
|
19
19
|
)
|
20
|
-
expect(
|
20
|
+
expect(appTestCurrent()).toBe(UnitTest.DO_NOTHING)
|
21
21
|
})
|