@hostlink/light 3.3.2 → 3.5.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 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
@@ -426,8 +458,6 @@ import type {
426
458
  CreateUserFields,
427
459
  QueryUserFieldsUserFields,
428
460
  RoleFields,
429
- FileFields,
430
- FolderFields,
431
461
  GraphQLQuery
432
462
  } from '@hostlink/light';
433
463
  ```
@@ -446,4 +476,3 @@ MIT
446
476
 
447
477
 
448
478
 
449
-
@@ -1,5 +1,4 @@
1
1
  import { createAuth } from './auth';
2
- import { createDrive } from './drive';
3
2
  import { default as axios } from 'axios';
4
3
  import { createMutation } from './mutation';
5
4
  import { createQuery } from './query';
@@ -10,10 +9,17 @@ import { createRoles } from './role';
10
9
  import { default as createCollection } from './createCollection';
11
10
  import { default as createList } from './createList';
12
11
  import { createUsers } from './users';
12
+ export type AccessTokenProvider = () => Promise<string>;
13
13
  type ClientType = {
14
14
  post: typeof axios.post;
15
15
  baseURL: string;
16
16
  axios: ReturnType<typeof axios.create>;
17
+ setAccessToken: (token: string | null) => void;
18
+ getAccessToken: () => string | null;
19
+ clearAccessToken: () => void;
20
+ setAccessTokenProvider: (provider: AccessTokenProvider | null) => void;
21
+ onAuthChange: (listener: () => void) => () => void;
22
+ useAudience: (authClient: ClientType, audience: string) => void;
17
23
  auth: ReturnType<typeof createAuth>;
18
24
  mutation: ReturnType<typeof createMutation>;
19
25
  query: ReturnType<typeof createQuery>;
@@ -29,7 +35,6 @@ type ClientType = {
29
35
  /**
30
36
  * @deprecated Use `fs.*` from `filesystem` instead.
31
37
  */
32
- drive: ReturnType<typeof createDrive>;
33
38
  collects: (collections: {
34
39
  [key: string]: any;
35
40
  }) => Promise<{
package/dist/index.d.ts CHANGED
@@ -4,13 +4,10 @@ export * from './permission';
4
4
  export * as webAuthn from './webauthn';
5
5
  export * from './auth';
6
6
  export { default as auth } from './auth';
7
- export * from './drive';
8
- export * from './folder';
9
7
  export * from './users';
10
8
  export * from './config';
11
9
  export * from './role';
12
10
  export * from './model';
13
- export * from './file';
14
11
  export * from './mail';
15
12
  export * from './fileUtils';
16
13
  export * as fs from './filesystem';