@droz-js/sdk 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/README.md +50 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -23,22 +23,65 @@ DrozSdk.forTenant('dev');
23
23
  DrozSdk.withAuthentication('Basic', 'username', 'password');
24
24
  ```
25
25
 
26
- ## Sample Sdks
26
+ ## Websocket
27
+
28
+ For websockets we use `graphql-ws` protocol with `AsyncIterator` to handle the subscriptions. The sdk will automatically
29
+ handle the connection and reconnection for you,
30
+ see https://the-guild.dev/graphql/ws/recipes#client-usage-with-asynciterator
31
+ on how to use the `AsyncIterator`.
32
+
33
+ ### Example with `AsyncIterator`
34
+
35
+ ```typescript
36
+ import { DrozSdk } from '@droz-js/sdk';
37
+ import { DrozChat } from '@droz-js/sdk/drozchat';
38
+
39
+ DrozSdk.forTenant('dev');
40
+
41
+ const chat = new DrozChat();
42
+ const iterable = chat.onTicketInQueue();
43
+ for await (const result of iterable) {
44
+ console.log(result);
45
+ }
46
+ ```
47
+
48
+ #### For the React developers
49
+
50
+ ```typescript
51
+ import { DrozSdk } from '@droz-js/sdk';
52
+ import { DrozChat } from '@droz-js/sdk/drozchat';
53
+
54
+ DrozSdk.forTenant('dev');
55
+
56
+ function useOnTicketInQueue() {
57
+ const chat = new DrozChat();
58
+ const [tickets, setTickets] = useState<Ticket[]>([]);
59
+
60
+ useEffect(() => {
61
+ const subscription = chat.onTicketInQueue();
62
+
63
+ // YES I KNOW, REACT SUCKS
64
+ (async () => {
65
+ // attention! this is just an example what you do with the result is up to you
66
+ for await (const each of subscription) setTickets(tickets => [...tickets, each]);
67
+ })();
68
+
69
+ // this is required to close the subscription when the component unmounts
70
+ return () => subscription.return();
71
+ }, []);
72
+ }
73
+ ```
74
+
75
+ ## Available Sdks
27
76
 
28
77
  ### Droz Nexo
29
78
 
30
79
  ```typescript
31
80
  import { DrozNexo } from '@droz-js/sdk/droznexo';
32
-
33
- const nexo = new DrozNexo();
34
- const res = await nexo.getAgent({ id: 'agentId' });
35
81
  ```
36
82
 
37
83
  ### Droz Chat
38
84
 
39
85
  ```typescript
40
86
  import { DrozChat } from '@droz-js/sdk/drozchat';
41
-
42
- const chat = new DrozChat();
43
- const res = await chat.listTicketsMine();
44
87
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@droz-js/sdk",
3
3
  "description": "Droz SDK",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "private": false,
6
6
  "exports": {
7
7
  ".": "./src/index.js",