@machhub-dev/sdk-ts 1.0.15 → 1.0.16
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 +139 -0
- package/dist/cjs/sdk-ts.d.ts +0 -6
- package/dist/cjs/sdk-ts.js +0 -12
- package/dist/sdk-ts.d.ts +0 -6
- package/dist/sdk-ts.js +0 -12
- package/package.json +1 -1
- package/src/sdk-ts.ts +0 -13
- package/src/classes/flow.ts +0 -13
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @machhub-dev/sdk-ts
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the MACHHUB platform by [Intellogic Technology Sdn Bhd](https://intellogic.com.my).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
MACHHUB is an industrial IoT platform for building real-time data-driven applications. This SDK provides a unified TypeScript interface to interact with MACHHUB services, including:
|
|
8
|
+
|
|
9
|
+
- **Authentication** — Login, session management, and permission checks
|
|
10
|
+
- **Collections** — Query and manage structured data with a fluent, chainable API
|
|
11
|
+
- **Tags** — Publish and subscribe to real-time machine/sensor data over MQTT
|
|
12
|
+
- **Historian** — Retrieve historical tag data and run time-series queries
|
|
13
|
+
- **Processes** — Execute named processes defined on the MACHHUB platform
|
|
14
|
+
|
|
15
|
+
The SDK supports both browser and Node.js environments and can be initialized with an explicit config or automatically when used alongside the MACHHUB VS Code Extension.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @machhub-dev/sdk-ts
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
**With explicit config:**
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { SDK, type SDKConfig } from '@machhub-dev/sdk-ts';
|
|
29
|
+
|
|
30
|
+
const config: SDKConfig = {
|
|
31
|
+
application_id: 'your-app-id',
|
|
32
|
+
httpUrl: 'http://localhost:6188', // optional, defaults to http://localhost:6188
|
|
33
|
+
mqttUrl: 'ws://localhost:180', // optional, defaults to ws://localhost:180
|
|
34
|
+
developer_key: 'your-dev-key', // optional
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const sdk = new SDK();
|
|
38
|
+
await sdk.Initialize(config);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**With the MACHHUB VS Code Extension:**
|
|
42
|
+
|
|
43
|
+
When running inside a MACHHUB Extension environment, `Initialize()` can be called without any config. The SDK will automatically resolve the application ID and connection URLs from the Extension context.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { SDK } from '@machhub-dev/sdk-ts';
|
|
47
|
+
|
|
48
|
+
const sdk = new SDK();
|
|
49
|
+
await sdk.Initialize(); // config not required when using the Extension
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Modules
|
|
53
|
+
|
|
54
|
+
### Auth
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// Login
|
|
58
|
+
const session = await sdk.auth.login('username', 'password');
|
|
59
|
+
|
|
60
|
+
// Get current user
|
|
61
|
+
const user = await sdk.auth.getCurrentUser();
|
|
62
|
+
|
|
63
|
+
// Logout
|
|
64
|
+
await sdk.auth.logout();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Collection
|
|
68
|
+
|
|
69
|
+
Query and manage data collections with a fluent builder API.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const results = await sdk.collection('my-collection')
|
|
73
|
+
.filter('status', 'eq', 'active')
|
|
74
|
+
.sort('created_at', 'desc')
|
|
75
|
+
.limit(20)
|
|
76
|
+
.offset(0)
|
|
77
|
+
.expand('related_field')
|
|
78
|
+
.getAll();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Tag
|
|
82
|
+
|
|
83
|
+
Publish and subscribe to real-time tag data over MQTT.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// List all tags
|
|
87
|
+
const tags = await sdk.tag.getAllTags();
|
|
88
|
+
|
|
89
|
+
// Subscribe to live data
|
|
90
|
+
await sdk.tag.subscribe('my/topic', (data, topic) => {
|
|
91
|
+
console.log(topic, data);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Publish data
|
|
95
|
+
await sdk.tag.publish('my/topic', { value: 42 });
|
|
96
|
+
|
|
97
|
+
// Unsubscribe
|
|
98
|
+
await sdk.tag.unsubscribe('my/topic');
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Historian
|
|
102
|
+
|
|
103
|
+
Access historical tag data.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Fetch historical data from a start time
|
|
107
|
+
const history = await sdk.historian.getHistoricalData(
|
|
108
|
+
'my/topic',
|
|
109
|
+
new Date('2024-01-01T00:00:00Z'),
|
|
110
|
+
'1h' // optional range
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Get the last N values (max 100)
|
|
114
|
+
const latest = await sdk.historian.getLastNValues('my/topic', 10);
|
|
115
|
+
|
|
116
|
+
// Subscribe to live historized data
|
|
117
|
+
await sdk.historian.subscribeLiveData('my/topic', (data) => {
|
|
118
|
+
console.log(data);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Raw SurrealQL query
|
|
122
|
+
const result = await sdk.historian.query('SELECT * FROM tag WHERE topic = "my/topic"');
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Processes
|
|
126
|
+
|
|
127
|
+
Execute named processes defined on the MACHHUB platform.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// Execute a process by name
|
|
131
|
+
const result = await sdk.processes.execute('my-process', { key: 'value' });
|
|
132
|
+
|
|
133
|
+
// Execute without input
|
|
134
|
+
const result = await sdk.processes.execute('my-process');
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
[MPL-2.0](LICENSE)
|
package/dist/cjs/sdk-ts.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Collection } from "./classes/collection.js";
|
|
2
2
|
import { Historian } from "./classes/historian.js";
|
|
3
3
|
import { Tag } from "./classes/tag.js";
|
|
4
|
-
import { Flow } from "./classes/flow.js";
|
|
5
4
|
import { Auth } from "./classes/auth.js";
|
|
6
5
|
import { Processes } from "./classes/processes.js";
|
|
7
6
|
export interface SDKConfig {
|
|
@@ -16,7 +15,6 @@ export declare class SDK {
|
|
|
16
15
|
private _historian;
|
|
17
16
|
private _tag;
|
|
18
17
|
private _function;
|
|
19
|
-
private _flow;
|
|
20
18
|
private _auth;
|
|
21
19
|
private _processes;
|
|
22
20
|
private applicationID;
|
|
@@ -64,10 +62,6 @@ export declare class SDK {
|
|
|
64
62
|
* Getter for `function`. Ensures `function` is accessed only after initialization.
|
|
65
63
|
*/
|
|
66
64
|
get function(): Function;
|
|
67
|
-
/**
|
|
68
|
-
* Getter for `flow`. Ensures `flow` is accessed only after initialization.
|
|
69
|
-
*/
|
|
70
|
-
get flow(): Flow;
|
|
71
65
|
/**
|
|
72
66
|
* Getter for `processes`. Ensures `processes` is accessed only after initialization.
|
|
73
67
|
*/
|
package/dist/cjs/sdk-ts.js
CHANGED
|
@@ -6,7 +6,6 @@ const mqtt_service_js_1 = require("./services/mqtt.service.js");
|
|
|
6
6
|
const collection_js_1 = require("./classes/collection.js");
|
|
7
7
|
const historian_js_1 = require("./classes/historian.js");
|
|
8
8
|
const tag_js_1 = require("./classes/tag.js");
|
|
9
|
-
const flow_js_1 = require("./classes/flow.js");
|
|
10
9
|
const auth_js_1 = require("./classes/auth.js");
|
|
11
10
|
const processes_js_1 = require("./classes/processes.js");
|
|
12
11
|
const MACHHUB_SDK_PATH = "machhub";
|
|
@@ -75,7 +74,6 @@ class SDK {
|
|
|
75
74
|
this._historian = null;
|
|
76
75
|
this._tag = null;
|
|
77
76
|
this._function = null;
|
|
78
|
-
this._flow = null;
|
|
79
77
|
this._auth = null;
|
|
80
78
|
this._processes = null;
|
|
81
79
|
this.applicationID = "";
|
|
@@ -158,7 +156,6 @@ class SDK {
|
|
|
158
156
|
this.mqtt = await MQTTClient.getInstance(this.applicationID, mqttUrl, config.developer_key);
|
|
159
157
|
this._historian = new historian_js_1.Historian(this.http["httpService"], this.mqtt["mqttService"]);
|
|
160
158
|
this._tag = new tag_js_1.Tag(this.http["httpService"], this.mqtt["mqttService"]);
|
|
161
|
-
this._flow = new flow_js_1.Flow(this.http["httpService"]);
|
|
162
159
|
this._auth = new auth_js_1.Auth(this.http["httpService"], this.applicationID);
|
|
163
160
|
this._processes = new processes_js_1.Processes(this.http["httpService"]);
|
|
164
161
|
}
|
|
@@ -204,15 +201,6 @@ class SDK {
|
|
|
204
201
|
}
|
|
205
202
|
return this._function;
|
|
206
203
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Getter for `flow`. Ensures `flow` is accessed only after initialization.
|
|
209
|
-
*/
|
|
210
|
-
get flow() {
|
|
211
|
-
if (!this._flow) {
|
|
212
|
-
throw new Error("SDK is not initialized. Call `Initialize` before accessing `flow`.");
|
|
213
|
-
}
|
|
214
|
-
return this._flow;
|
|
215
|
-
}
|
|
216
204
|
/**
|
|
217
205
|
* Getter for `processes`. Ensures `processes` is accessed only after initialization.
|
|
218
206
|
*/
|
package/dist/sdk-ts.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Collection } from "./classes/collection.js";
|
|
2
2
|
import { Historian } from "./classes/historian.js";
|
|
3
3
|
import { Tag } from "./classes/tag.js";
|
|
4
|
-
import { Flow } from "./classes/flow.js";
|
|
5
4
|
import { Auth } from "./classes/auth.js";
|
|
6
5
|
import { Processes } from "./classes/processes.js";
|
|
7
6
|
export interface SDKConfig {
|
|
@@ -16,7 +15,6 @@ export declare class SDK {
|
|
|
16
15
|
private _historian;
|
|
17
16
|
private _tag;
|
|
18
17
|
private _function;
|
|
19
|
-
private _flow;
|
|
20
18
|
private _auth;
|
|
21
19
|
private _processes;
|
|
22
20
|
private applicationID;
|
|
@@ -64,10 +62,6 @@ export declare class SDK {
|
|
|
64
62
|
* Getter for `function`. Ensures `function` is accessed only after initialization.
|
|
65
63
|
*/
|
|
66
64
|
get function(): Function;
|
|
67
|
-
/**
|
|
68
|
-
* Getter for `flow`. Ensures `flow` is accessed only after initialization.
|
|
69
|
-
*/
|
|
70
|
-
get flow(): Flow;
|
|
71
65
|
/**
|
|
72
66
|
* Getter for `processes`. Ensures `processes` is accessed only after initialization.
|
|
73
67
|
*/
|
package/dist/sdk-ts.js
CHANGED
|
@@ -3,7 +3,6 @@ import { MQTTService } from "./services/mqtt.service.js";
|
|
|
3
3
|
import { Collection } from "./classes/collection.js";
|
|
4
4
|
import { Historian } from "./classes/historian.js";
|
|
5
5
|
import { Tag } from "./classes/tag.js";
|
|
6
|
-
import { Flow } from "./classes/flow.js";
|
|
7
6
|
import { Auth } from "./classes/auth.js";
|
|
8
7
|
import { Processes } from "./classes/processes.js";
|
|
9
8
|
const MACHHUB_SDK_PATH = "machhub";
|
|
@@ -72,7 +71,6 @@ export class SDK {
|
|
|
72
71
|
this._historian = null;
|
|
73
72
|
this._tag = null;
|
|
74
73
|
this._function = null;
|
|
75
|
-
this._flow = null;
|
|
76
74
|
this._auth = null;
|
|
77
75
|
this._processes = null;
|
|
78
76
|
this.applicationID = "";
|
|
@@ -155,7 +153,6 @@ export class SDK {
|
|
|
155
153
|
this.mqtt = await MQTTClient.getInstance(this.applicationID, mqttUrl, config.developer_key);
|
|
156
154
|
this._historian = new Historian(this.http["httpService"], this.mqtt["mqttService"]);
|
|
157
155
|
this._tag = new Tag(this.http["httpService"], this.mqtt["mqttService"]);
|
|
158
|
-
this._flow = new Flow(this.http["httpService"]);
|
|
159
156
|
this._auth = new Auth(this.http["httpService"], this.applicationID);
|
|
160
157
|
this._processes = new Processes(this.http["httpService"]);
|
|
161
158
|
}
|
|
@@ -201,15 +198,6 @@ export class SDK {
|
|
|
201
198
|
}
|
|
202
199
|
return this._function;
|
|
203
200
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Getter for `flow`. Ensures `flow` is accessed only after initialization.
|
|
206
|
-
*/
|
|
207
|
-
get flow() {
|
|
208
|
-
if (!this._flow) {
|
|
209
|
-
throw new Error("SDK is not initialized. Call `Initialize` before accessing `flow`.");
|
|
210
|
-
}
|
|
211
|
-
return this._flow;
|
|
212
|
-
}
|
|
213
201
|
/**
|
|
214
202
|
* Getter for `processes`. Ensures `processes` is accessed only after initialization.
|
|
215
203
|
*/
|
package/package.json
CHANGED
package/src/sdk-ts.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { MQTTService } from "./services/mqtt.service.js";
|
|
|
3
3
|
import { Collection } from "./classes/collection.js";
|
|
4
4
|
import { Historian } from "./classes/historian.js";
|
|
5
5
|
import { Tag } from "./classes/tag.js";
|
|
6
|
-
import { Flow } from "./classes/flow.js";
|
|
7
6
|
import { Auth } from "./classes/auth.js";
|
|
8
7
|
import { Processes } from "./classes/processes.js";
|
|
9
8
|
|
|
@@ -91,7 +90,6 @@ export class SDK {
|
|
|
91
90
|
private _historian: Historian | null = null;
|
|
92
91
|
private _tag: Tag | null = null;
|
|
93
92
|
private _function: Function | null = null;
|
|
94
|
-
private _flow: Flow | null = null;
|
|
95
93
|
private _auth: Auth | null = null;
|
|
96
94
|
private _processes: Processes | null = null;
|
|
97
95
|
private applicationID: string = "";
|
|
@@ -182,7 +180,6 @@ export class SDK {
|
|
|
182
180
|
|
|
183
181
|
this._historian = new Historian(this.http["httpService"], this.mqtt["mqttService"]);
|
|
184
182
|
this._tag = new Tag(this.http["httpService"], this.mqtt["mqttService"]);
|
|
185
|
-
this._flow = new Flow(this.http["httpService"]);
|
|
186
183
|
this._auth = new Auth(this.http["httpService"], this.applicationID);
|
|
187
184
|
this._processes = new Processes(this.http["httpService"]);
|
|
188
185
|
} catch (error: any) {
|
|
@@ -233,16 +230,6 @@ export class SDK {
|
|
|
233
230
|
return this._function;
|
|
234
231
|
}
|
|
235
232
|
|
|
236
|
-
/**
|
|
237
|
-
* Getter for `flow`. Ensures `flow` is accessed only after initialization.
|
|
238
|
-
*/
|
|
239
|
-
public get flow(): Flow {
|
|
240
|
-
if (!this._flow) {
|
|
241
|
-
throw new Error("SDK is not initialized. Call `Initialize` before accessing `flow`.");
|
|
242
|
-
}
|
|
243
|
-
return this._flow;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
233
|
/**
|
|
247
234
|
* Getter for `processes`. Ensures `processes` is accessed only after initialization.
|
|
248
235
|
*/
|
package/src/classes/flow.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HTTPService } from "../services/http.service.js";
|
|
2
|
-
|
|
3
|
-
export class Flow {
|
|
4
|
-
private httpService: HTTPService;
|
|
5
|
-
|
|
6
|
-
constructor(httpService: HTTPService) {
|
|
7
|
-
this.httpService = httpService;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public async executeFlow(name: string, payload: any): Promise<any> {
|
|
11
|
-
return await this.httpService.request.withJSON(payload).post("flow/execute/name/" + name);
|
|
12
|
-
}
|
|
13
|
-
}
|