@shieldiot/pulse-lib 1.0.12 → 1.0.13

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 +60 -14
  2. package/package.json +1 -2
package/README.md CHANGED
@@ -3,30 +3,76 @@
3
3
  This package is a typescript client library for the pulse IoT API.
4
4
  The library includes all the types and services exposed the the pulse API.
5
5
 
6
- ## Install
6
+ ###### Install
7
7
 
8
- Install dependencies:
9
- `npm i`
10
-
11
- Build package:
12
- `npm run build`
8
+ Install client library:
9
+ ```typescript
10
+ npm i @shieldiot/pulse-lib
11
+ ```
13
12
 
14
13
 
15
14
  ##### How to use:
15
+ To use the library, first create a PulseClient instance with the API endpoint URL and optionally the API key and Accesss Token.
16
16
 
17
+ > The apiKey and accessToken parameters in the PulseClient constructor are optional since
18
+ it is recomended to use HTTP interceptors to inject the API key and access token instead of constructor injection.
19
+
20
+ > The use of interceptor is the preferred approach since for any API response, the response header includes new access toekn with
21
+ new expiration time. Using the same token without refreshing it will eventually result access denied error after the expiration time of the original token (30 minutes).
22
+ The use of constructor injection of access token is recomended for non-expired tokens only (system-to-system integration).
23
+
24
+
25
+ Example: how to search list of devices:
17
26
  ```typescript
18
- import { Account, PulseClient } from 'pulse-lib'
27
+ import { PulseClient } from '@shieldiot/pulse-lib'
28
+
29
+
30
+ function searchDevices() : void{
31
+
32
+ const apiUrl: string = "http://myaccount-api.pulseiot.io/v1";
33
+ const apiKey: string = "your_api_key";
34
+ const accessToken: string = "your_access_token";
19
35
 
20
- let pc = new PulseClient("https://your-pulse-api-endpoint", "your-api-key", "your-access-token");
21
- pc.UsrRulesService.find("streamId").pipe();
36
+ // It is recomended to use a single instance of PulseClient for the entire application
37
+ let cli = new PulseClient(apiUrl, apiKey, accessToken);
38
+
39
+ // remember to release the subject: sub to avoid memory leaks
40
+ let sub = cli.UsrDevicesService.find("streamId").subscribe({
41
+ next: (res) => console.log("process response", res)
42
+ });
43
+ };
22
44
 
23
45
  ```
24
- The apiKey and accessToken parameters in the PulseClient constructor are optional since
25
- it is recomended to use HTTP interceptors to inject the API key and access token instead of constructor injection.
26
46
 
27
- The use of interceptor is better since for any API response, the response header includes new access toekn with
28
- new expiration time. Using the same token without refreshing it will eventually result access denied error after the expiration time of the original token (30 minutes).
29
- The use of constructor injection of access token is recomended for non-expired tokens only (system-to-system integration).
47
+ Example2: how to add account:
48
+ ```typescript
49
+ import { Account, AccountTypeCode, PulseClient } from '@shieldiot/pulse-lib'
50
+
51
+ function createAccount() : void{
52
+
53
+ const apiUrl: string = "http://myaccount-api.pulseiot.io/v1";
54
+ const apiKey: string = "your_api_key";
55
+ const accessToken: string = "your_access_token";
56
+
57
+ // It is recomended to use a single instance of PulseClient for the entire application
58
+ let cli = new PulseClient(apiUrl, apiKey, accessToken);
59
+
60
+ // Add account
61
+ let account = new Account("id");
62
+ account.name = "new account";
63
+ account.description = "account description";
64
+ account.type = AccountTypeCode.CUSTOMER;
65
+
66
+ // remember to release the subject: sub to avoid memory leaks
67
+ let sub = cli.SysAccountsService.create(account).subscribe({
68
+ next: (res) => console.log("process response", res)
69
+ });
70
+ };
71
+
72
+ ```
30
73
 
74
+ ##### Best Practices
31
75
 
76
+ * Use a single instance of the PulseClient (as a singleton) for the entire application to avoid high memory consumption since this instance initializes all the pulse services that can be access as readonly properties.
77
+ * All the service methods return a generic typed Observable (e.g. `Observable<EntitiesResponse<Device>>`) that can be used in async manner in the UI or with the subscribe method in the code. Always remember to delete the subject of the subscribe to avoid memory leaks.
32
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shieldiot/pulse-lib",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -47,7 +47,6 @@
47
47
  "devDependencies": {
48
48
  "@commitlint/cli": "^19.5.0",
49
49
  "@commitlint/config-conventional": "^19.5.0",
50
- "@types/jest": "^29.5.13",
51
50
  "@typescript-eslint/eslint-plugin": "^8.8.1",
52
51
  "@typescript-eslint/parser": "^8.8.1",
53
52
  "eslint": "^9.12.0",