0.6.15 • Published 4 days ago

@droz-js/sdk v0.6.15

Weekly downloads
-
License
-
Repository
-
Last release
4 days ago

@droz-js/sdk

Setup (required)

To set up the sdk you need to tell the tenant and the authentication method, the tenant is required. You must run this first before making any sdk calls. The sdk will fail if you don't set up the tenant.

import { DrozSdk } from '@droz-js/sdk';

DrozSdk.forTenant('dev').withAuthorization('Basic', 'username', 'password');

You can also split the setup in two steps

import { DrozSdk } from '@droz-js/sdk';

// first step (required)
DrozSdk.forTenant('dev');

// (optional) later when you have the authentication token you can set it and it will automatically be used in the new requests
DrozSdk.withAuthorization('Basic', 'username', 'password');

Global Error Handling

The sdk will throw an error on every request that fails, but you can also catch the error globally by using the on method.

import { DrozSdk } from '@droz-js/sdk';

DrozSdk.on('error', (error) => {
  console.log(error);
});

Every error sent is of type SdkError and contains the following properties:

  • message: the original error message sent from the server;
  • statusCode: similar to the http status codes and indicates the class of the error, 400 bad request, 403 forbidden, 404 not found...;
  • errorCode: a unique identifier for the error, this is useful to for i18n friendly messages;

Websocket

For websockets we use graphql-ws protocol with AsyncIterator to handle the subscriptions. The sdk will automatically handle the connection and reconnection for you, see https://the-guild.dev/graphql/ws/recipes#client-usage-with-asynciterator on how to use the AsyncIterator.

Example with AsyncIterator

import { DrozSdk } from '@droz-js/sdk';
import { DrozChat } from '@droz-js/sdk/drozchat';

DrozSdk.forTenant('dev');

const chat = new DrozChat();
const iterable = chat.onTicketInQueue();
for await (const result of iterable) {
  console.log(result);
}

For the React developers

import { DrozSdk } from '@droz-js/sdk';
import { DrozChat } from '@droz-js/sdk/drozchat';

DrozSdk.forTenant('dev');

function useOnTicketInQueue() {
  const chat = new DrozChat();
  const [tickets, setTickets] = useState<Ticket[]>([]);

  useEffect(() => {
    const subscription = chat.onTicketInQueue();

    // YES I KNOW, REACT SUCKS
    (async () => {
      // attention! this is just an example what you do with the result is up to you
      for await (const each of subscription) setTickets(tickets => [...tickets, each]);
    })();

    // this is required to close the subscription when the component unmounts
    return () => subscription.return();
  }, []);
}

Available Sdks

Droz Nexo

import { DrozNexo } from '@droz-js/sdk/droznexo';

Droz Chat

import { DrozChat } from '@droz-js/sdk/drozchat';
0.6.12

5 days ago

0.6.14

4 days ago

0.6.13

4 days ago

0.6.15

4 days ago

0.6.11

7 days ago

0.6.9

9 days ago

0.6.10

9 days ago

0.6.8

12 days ago

0.6.7

12 days ago

0.6.6

14 days ago

0.6.5

14 days ago

0.6.4

15 days ago

0.6.3

18 days ago

0.6.2

19 days ago

0.6.1

19 days ago

0.6.0

21 days ago

0.5.27

22 days ago

0.5.26

25 days ago

0.5.25

26 days ago

0.5.24

28 days ago

0.5.23

29 days ago

0.5.21

1 month ago

0.5.22

1 month ago

0.5.20

1 month ago

0.5.19

1 month ago

0.5.18

1 month ago

0.5.16

1 month ago

0.5.17

1 month ago

0.5.15

1 month ago

0.5.14

1 month ago

0.5.13

2 months ago

0.5.12

2 months ago

0.5.11

2 months ago

0.5.10

2 months ago

0.5.9

2 months ago

0.5.8

2 months ago

0.5.7

2 months ago

0.5.6

2 months ago

0.5.5

2 months ago

0.5.4

2 months ago

0.5.3

2 months ago

0.5.2

2 months ago

0.5.1

2 months ago

0.5.0

2 months ago

0.4.27

3 months ago

0.4.26

3 months ago

0.4.25

3 months ago

0.4.24

3 months ago

0.4.23

3 months ago

0.4.22

3 months ago

0.4.21

3 months ago

0.4.20

3 months ago

0.4.19

4 months ago

0.4.18

4 months ago

0.4.17

4 months ago

0.4.15

4 months ago

0.4.16

4 months ago

0.4.13

4 months ago

0.4.14

4 months ago

0.4.9

4 months ago

0.4.8

4 months ago

0.4.10

4 months ago

0.4.11

4 months ago

0.4.12

4 months ago

0.4.7

4 months ago

0.4.6

5 months ago

0.4.5

5 months ago

0.4.4

5 months ago

0.3.21

5 months ago

0.4.1

5 months ago

0.4.0

5 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.3.20

5 months ago

0.3.19

5 months ago

0.3.17

5 months ago

0.3.16

5 months ago

0.3.15

5 months ago

0.3.14

5 months ago

0.3.18

5 months ago

0.3.13

5 months ago

0.3.12

5 months ago

0.3.11

6 months ago

0.3.9

6 months ago

0.3.10

6 months ago

0.3.8

6 months ago

0.3.7

6 months ago

0.3.6

6 months ago

0.3.5

6 months ago

0.3.4

6 months ago

0.3.3

6 months ago

0.3.2

6 months ago

0.3.1

6 months ago

0.3.0

7 months ago

0.2.17

7 months ago

0.2.16

7 months ago

0.2.15

7 months ago

0.2.14

7 months ago

0.2.13

7 months ago

0.2.12

7 months ago

0.2.11

7 months ago

0.2.10

7 months ago

0.2.9

8 months ago

0.2.8

8 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago