@shieldiot/pulse-lib 1.0.12 → 1.0.14
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 +60 -14
- package/package.json +3 -8
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
|
-
|
|
6
|
+
###### Install
|
|
7
7
|
|
|
8
|
-
Install
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 {
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -32,13 +32,9 @@
|
|
|
32
32
|
],
|
|
33
33
|
"author": "Motty Cohen <motty.cohen@shieldiot.io>",
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"homepage": "https://github.com/shieldiot/pulse-lib-example",
|
|
36
35
|
"repository": {
|
|
37
36
|
"type": "git",
|
|
38
|
-
"url": "git@
|
|
39
|
-
},
|
|
40
|
-
"bugs": {
|
|
41
|
-
"url": "https://github.com/shieldiot/pulse-lib-example/issues"
|
|
37
|
+
"url": "git@bitbucket.org:shieldiot/pulse-dsl.git"
|
|
42
38
|
},
|
|
43
39
|
"dependencies": {
|
|
44
40
|
"axios": "^1.7.7",
|
|
@@ -47,7 +43,6 @@
|
|
|
47
43
|
"devDependencies": {
|
|
48
44
|
"@commitlint/cli": "^19.5.0",
|
|
49
45
|
"@commitlint/config-conventional": "^19.5.0",
|
|
50
|
-
"@types/jest": "^29.5.13",
|
|
51
46
|
"@typescript-eslint/eslint-plugin": "^8.8.1",
|
|
52
47
|
"@typescript-eslint/parser": "^8.8.1",
|
|
53
48
|
"eslint": "^9.12.0",
|
|
@@ -59,4 +54,4 @@
|
|
|
59
54
|
"webpack": "^5.95.0",
|
|
60
55
|
"webpack-cli": "^5.1.4"
|
|
61
56
|
}
|
|
62
|
-
}
|
|
57
|
+
}
|