@hostlink/light 3.3.0 → 3.4.0
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 +32 -1
- package/dist/auth.d.ts +36 -1
- package/dist/config.d.ts +2 -0
- package/dist/createClient.d.ts +26 -16
- package/dist/createClient.test.d.ts +1 -0
- package/dist/createCollection.d.ts +3 -1
- package/dist/createList.d.ts +3 -1
- package/dist/drive.d.ts +40 -4
- package/dist/file.d.ts +2 -1
- package/dist/filesystem.d.ts +1 -1
- package/dist/folder.d.ts +3 -2
- package/dist/light.js +720 -586
- package/dist/light.umd.cjs +1 -1
- package/dist/mail.d.ts +4 -0
- package/dist/model.d.ts +9 -2
- package/dist/mutation.d.ts +3 -0
- package/dist/query.d.ts +2 -0
- package/dist/role.d.ts +6 -0
- package/dist/users.d.ts +7 -0
- package/dist/webauthn.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,38 @@ const users = await api.query({
|
|
|
44
44
|
await api.auth.logout();
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
### Audience tokens for multiple APIs
|
|
48
|
+
|
|
49
|
+
Create one client per API and connect resource clients to the Auth client:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const auth = createClient('https://auth.example.com/graphql');
|
|
53
|
+
const business = createClient('https://business.example.com/graphql');
|
|
54
|
+
const infra = createClient('https://infra.example.com/graphql');
|
|
55
|
+
|
|
56
|
+
business.useAudience(auth, 'business-api');
|
|
57
|
+
infra.useAudience(auth, 'infra-api');
|
|
58
|
+
|
|
59
|
+
await auth.auth.login('username', 'password');
|
|
60
|
+
|
|
61
|
+
// Each first request lazily obtains and attaches its audience token.
|
|
62
|
+
await business.query({ orders: { order_id: true } });
|
|
63
|
+
await infra.query({ servers: { server_id: true } });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Audience tokens are cached independently and renewed shortly before expiry.
|
|
67
|
+
Concurrent requests share the same token request. Login and logout through
|
|
68
|
+
`auth.auth` clear cached audience tokens.
|
|
69
|
+
|
|
70
|
+
Lower-level token methods are also available:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
business.setAccessToken(token);
|
|
74
|
+
business.getAccessToken();
|
|
75
|
+
business.clearAccessToken();
|
|
76
|
+
business.setAccessTokenProvider(async () => obtainToken());
|
|
77
|
+
```
|
|
78
|
+
|
|
47
79
|
## API Reference
|
|
48
80
|
|
|
49
81
|
### Creating a Client
|
|
@@ -446,4 +478,3 @@ MIT
|
|
|
446
478
|
|
|
447
479
|
|
|
448
480
|
|
|
449
|
-
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
import { QueryUserFieldsUserFields } from '.';
|
|
1
|
+
import { mutation, query, QueryUserFieldsUserFields } from '.';
|
|
2
2
|
import * as webAuthn from "./webauthn";
|
|
3
|
+
type QueryFn = typeof query;
|
|
4
|
+
type MutationFn = typeof mutation;
|
|
5
|
+
export declare const createAuth: (queryFn: QueryFn, mutationFn: MutationFn) => {
|
|
6
|
+
getCurrentUser: (fields?: QueryUserFieldsUserFields) => Promise<any>;
|
|
7
|
+
login: (username: string, password: string, code?: string) => Promise<boolean>;
|
|
8
|
+
logout: () => Promise<boolean>;
|
|
9
|
+
changeExpiredPassword: (username: string, oldPassword: string, newPassword: string) => Promise<boolean>;
|
|
10
|
+
updatePassword: (oldPassword: string, newPassword: string) => Promise<boolean>;
|
|
11
|
+
resetPassword: (jwt: string, password: string, code: string) => Promise<boolean>;
|
|
12
|
+
forgetPassword: (username: string, email: string) => Promise<string>;
|
|
13
|
+
verifyCode: (jwt: string, code: string) => Promise<boolean>;
|
|
14
|
+
grantedRights: (rights: string[]) => Promise<string[]>;
|
|
15
|
+
isGranted: (right: string) => Promise<boolean>;
|
|
16
|
+
webAuthn: {
|
|
17
|
+
assertion: () => Promise<PublicKeyCredential>;
|
|
18
|
+
attestation: () => Promise<PublicKeyCredential>;
|
|
19
|
+
login: () => Promise<any>;
|
|
20
|
+
register: () => Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
google: {
|
|
23
|
+
unlink: () => Promise<boolean>;
|
|
24
|
+
login: (credential: string) => Promise<boolean>;
|
|
25
|
+
register: (credential: string) => Promise<boolean>;
|
|
26
|
+
};
|
|
27
|
+
facebook: {
|
|
28
|
+
unlink: () => Promise<boolean>;
|
|
29
|
+
login: (accessToken: string) => Promise<boolean>;
|
|
30
|
+
register: (accessToken: string) => Promise<boolean>;
|
|
31
|
+
};
|
|
32
|
+
microsoft: {
|
|
33
|
+
unlink: () => Promise<boolean>;
|
|
34
|
+
login: (accessToken: string) => Promise<boolean>;
|
|
35
|
+
register: (account_id: string) => Promise<boolean>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
3
38
|
export declare const getCurrentUser: (fields?: QueryUserFieldsUserFields) => Promise<any>;
|
|
4
39
|
export declare const login: (username: string, password: string, code?: string) => Promise<boolean>;
|
|
5
40
|
export declare const logout: () => Promise<boolean>;
|
package/dist/config.d.ts
CHANGED
package/dist/createClient.d.ts
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createAuth } from './auth';
|
|
2
|
+
import { createDrive } from './drive';
|
|
3
3
|
import { default as axios } from 'axios';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { createMutation } from './mutation';
|
|
5
|
+
import { createQuery } from './query';
|
|
6
|
+
import { createConfig } from './config';
|
|
7
|
+
import { createMail } from './mail';
|
|
8
8
|
import { getModel } from './models';
|
|
9
|
-
import {
|
|
9
|
+
import { createRoles } from './role';
|
|
10
10
|
import { default as createCollection } from './createCollection';
|
|
11
11
|
import { default as createList } from './createList';
|
|
12
|
-
import {
|
|
12
|
+
import { createUsers } from './users';
|
|
13
|
+
export type AccessTokenProvider = () => Promise<string>;
|
|
13
14
|
type ClientType = {
|
|
14
15
|
post: typeof axios.post;
|
|
15
16
|
baseURL: string;
|
|
16
17
|
axios: ReturnType<typeof axios.create>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
setAccessToken: (token: string | null) => void;
|
|
19
|
+
getAccessToken: () => string | null;
|
|
20
|
+
clearAccessToken: () => void;
|
|
21
|
+
setAccessTokenProvider: (provider: AccessTokenProvider | null) => void;
|
|
22
|
+
onAuthChange: (listener: () => void) => () => void;
|
|
23
|
+
useAudience: (authClient: ClientType, audience: string) => void;
|
|
24
|
+
auth: ReturnType<typeof createAuth>;
|
|
25
|
+
mutation: ReturnType<typeof createMutation>;
|
|
26
|
+
query: ReturnType<typeof createQuery>;
|
|
27
|
+
config: ReturnType<typeof createConfig>;
|
|
28
|
+
mail: ReturnType<typeof createMail>;
|
|
29
|
+
users: ReturnType<typeof createUsers>;
|
|
23
30
|
model: (name: string) => ReturnType<typeof getModel>;
|
|
24
|
-
roles: ReturnType<typeof
|
|
31
|
+
roles: ReturnType<typeof createRoles>;
|
|
25
32
|
collect: (name: string, fields: Record<string, any>) => ReturnType<typeof createCollection> & {
|
|
26
33
|
data_path: string;
|
|
27
34
|
};
|
|
28
35
|
list: (entity: string, fields: Record<string, any>) => ReturnType<typeof createList>;
|
|
29
|
-
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `fs.*` from `filesystem` instead.
|
|
38
|
+
*/
|
|
39
|
+
drive: ReturnType<typeof createDrive>;
|
|
30
40
|
collects: (collections: {
|
|
31
41
|
[key: string]: any;
|
|
32
42
|
}) => Promise<{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GraphQLQuery } from '.';
|
|
2
|
+
type Query = (query: GraphQLQuery) => Promise<any>;
|
|
1
3
|
type Operator = '==' | '<' | '<=' | '>' | '>=' | '!==';
|
|
2
4
|
interface FilterValue {
|
|
3
5
|
lt?: any;
|
|
@@ -446,5 +448,5 @@ declare class Collection<Item> {
|
|
|
446
448
|
meta: MetaData;
|
|
447
449
|
constructor(fields: Record<string, any>);
|
|
448
450
|
}
|
|
449
|
-
declare const _default: (name: string, fields: Record<string, any
|
|
451
|
+
declare const _default: (name: string, fields: Record<string, any>, queryFn?: Query) => Collection<any>;
|
|
450
452
|
export default _default;
|
package/dist/createList.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { GraphQLQuery } from '.';
|
|
2
|
+
type Query = (query: GraphQLQuery) => Promise<any>;
|
|
1
3
|
type Fields = Record<string, any>;
|
|
2
|
-
export default function createList(entity: string, fields: Fields): {
|
|
4
|
+
export default function createList(entity: string, fields: Fields, queryFn?: Query): {
|
|
3
5
|
first(): Promise<any>;
|
|
4
6
|
all(): Promise<any[]>;
|
|
5
7
|
fetchFirst(): Promise<any>;
|
package/dist/drive.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { query, mutation } from '.';
|
|
1
2
|
/**
|
|
2
3
|
* @deprecated Use `fs.listFolders` / `fs.listFiles` from `filesystem` instead.
|
|
3
4
|
*/
|
|
@@ -17,7 +18,7 @@ export declare const listDrives: () => Promise<any>;
|
|
|
17
18
|
*/
|
|
18
19
|
export declare const getDrive: (index: number) => {
|
|
19
20
|
folders: {
|
|
20
|
-
list: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<
|
|
21
|
+
list: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<any>;
|
|
21
22
|
create: (path: string) => Promise<any>;
|
|
22
23
|
delete: (path: string) => Promise<any>;
|
|
23
24
|
rename: (path: string, name: string) => Promise<any>;
|
|
@@ -39,7 +40,42 @@ export declare const getDrive: (index: number) => {
|
|
|
39
40
|
deleteFile: (path: string) => Promise<any>;
|
|
40
41
|
renameFile: (path: string, name: string) => Promise<any>;
|
|
41
42
|
moveFile: (source: string, destination: string) => Promise<any>;
|
|
42
|
-
listFolders: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<
|
|
43
|
+
listFolders: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<any>;
|
|
44
|
+
createFolder: (path: string) => Promise<any>;
|
|
45
|
+
deleteFolder: (path: string) => Promise<any>;
|
|
46
|
+
renameFolder: (path: string, name: string) => Promise<any>;
|
|
47
|
+
uploadTempFile: (file: File) => Promise<{
|
|
48
|
+
name: string;
|
|
49
|
+
path: string;
|
|
50
|
+
size: number;
|
|
51
|
+
mime: string;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
export declare const createDrive: (queryFn: typeof query, mutationFn: typeof mutation) => (index: number) => {
|
|
55
|
+
folders: {
|
|
56
|
+
list: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<any>;
|
|
57
|
+
create: (path: string) => Promise<any>;
|
|
58
|
+
delete: (path: string) => Promise<any>;
|
|
59
|
+
rename: (path: string, name: string) => Promise<any>;
|
|
60
|
+
};
|
|
61
|
+
files: {
|
|
62
|
+
list: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
|
|
63
|
+
get: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
|
|
64
|
+
readFileAsBase64(path: string): Promise<string>;
|
|
65
|
+
read: (path: string) => Promise<any>;
|
|
66
|
+
write: (path: string, content: string) => Promise<any>;
|
|
67
|
+
delete: (path: string) => Promise<any>;
|
|
68
|
+
rename: (path: string, name: string) => Promise<any>;
|
|
69
|
+
move: (source: string, destination: string) => Promise<any>;
|
|
70
|
+
};
|
|
71
|
+
listFiles: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
|
|
72
|
+
getFile: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
|
|
73
|
+
readFile: (path: string) => Promise<any>;
|
|
74
|
+
writeFile: (path: string, content: string) => Promise<any>;
|
|
75
|
+
deleteFile: (path: string) => Promise<any>;
|
|
76
|
+
renameFile: (path: string, name: string) => Promise<any>;
|
|
77
|
+
moveFile: (source: string, destination: string) => Promise<any>;
|
|
78
|
+
listFolders: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<any>;
|
|
43
79
|
createFolder: (path: string) => Promise<any>;
|
|
44
80
|
deleteFolder: (path: string) => Promise<any>;
|
|
45
81
|
renameFolder: (path: string, name: string) => Promise<any>;
|
|
@@ -57,7 +93,7 @@ declare const _default: () => {
|
|
|
57
93
|
}>>;
|
|
58
94
|
get: (index: number) => {
|
|
59
95
|
folders: {
|
|
60
|
-
list: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<
|
|
96
|
+
list: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<any>;
|
|
61
97
|
create: (path: string) => Promise<any>;
|
|
62
98
|
delete: (path: string) => Promise<any>;
|
|
63
99
|
rename: (path: string, name: string) => Promise<any>;
|
|
@@ -79,7 +115,7 @@ declare const _default: () => {
|
|
|
79
115
|
deleteFile: (path: string) => Promise<any>;
|
|
80
116
|
renameFile: (path: string, name: string) => Promise<any>;
|
|
81
117
|
moveFile: (source: string, destination: string) => Promise<any>;
|
|
82
|
-
listFolders: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<
|
|
118
|
+
listFolders: (path: string, fields?: import('./folder').QueryFolderFields) => Promise<any>;
|
|
83
119
|
createFolder: (path: string) => Promise<any>;
|
|
84
120
|
deleteFolder: (path: string) => Promise<any>;
|
|
85
121
|
renameFolder: (path: string, name: string) => Promise<any>;
|
package/dist/file.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { query, mutation } from '.';
|
|
1
2
|
export type FileFields = {
|
|
2
3
|
name?: string;
|
|
3
4
|
path?: string;
|
|
@@ -18,7 +19,7 @@ export declare const readFileAsBase64: (index: number, path: string) => Promise<
|
|
|
18
19
|
* @deprecated Use `fs.listFiles` from `filesystem` instead.
|
|
19
20
|
* The default export factory function is also deprecated — use `fs.*` directly.
|
|
20
21
|
*/
|
|
21
|
-
declare const _default: (index: number) => {
|
|
22
|
+
declare const _default: (index: number, queryFn?: typeof query, mutationFn?: typeof mutation) => {
|
|
22
23
|
list: (path: string, fields?: QueryFileFields) => Promise<any>;
|
|
23
24
|
get: (path: string, fields?: QueryFileFields) => Promise<any>;
|
|
24
25
|
readFileAsBase64(path: string): Promise<string>;
|
package/dist/filesystem.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const deleteFolder: (location: string) => Promise<any>;
|
|
|
3
3
|
export declare const renameFolder: (location: string, newName: string) => Promise<any>;
|
|
4
4
|
export declare const renameFile: (location: string, newName: string) => Promise<any>;
|
|
5
5
|
export declare const writeFile: (location: string, content: string) => Promise<any>;
|
|
6
|
-
export declare const uploadFile: (location: string, file: File) => Promise<any>;
|
|
6
|
+
export declare const uploadFile: (location: string, file: File, rename?: boolean) => Promise<any>;
|
|
7
7
|
export declare const deleteFile: (location: string) => Promise<any>;
|
|
8
8
|
export declare const move: (from: string, to: string) => Promise<any>;
|
|
9
9
|
export declare const exists: (location: string) => Promise<any>;
|
package/dist/folder.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { query, mutation } from '.';
|
|
1
2
|
export type FolderFields = {
|
|
2
3
|
name?: string;
|
|
3
4
|
path?: string;
|
|
@@ -10,8 +11,8 @@ export declare const listFolders: (index: number, path: string, fields?: QueryFo
|
|
|
10
11
|
/**
|
|
11
12
|
* @deprecated Use `fs.createFolder` / `fs.deleteFolder` / `fs.renameFolder` from `filesystem` instead.
|
|
12
13
|
*/
|
|
13
|
-
declare const _default: (index: number) => {
|
|
14
|
-
list: (path: string, fields?: QueryFolderFields) => Promise<
|
|
14
|
+
declare const _default: (index: number, queryFn?: typeof query, mutationFn?: typeof mutation) => {
|
|
15
|
+
list: (path: string, fields?: QueryFolderFields) => Promise<any>;
|
|
15
16
|
create: (path: string) => Promise<any>;
|
|
16
17
|
delete: (path: string) => Promise<any>;
|
|
17
18
|
rename: (path: string, name: string) => Promise<any>;
|