@machhub-dev/sdk-ts 0.0.2 → 0.0.4

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 (43) hide show
  1. package/dist/cjs/classes/auth.d.ts +2 -2
  2. package/dist/cjs/classes/collection.d.ts +2 -2
  3. package/dist/cjs/classes/collection.js +9 -0
  4. package/dist/cjs/classes/flow.d.ts +1 -1
  5. package/dist/cjs/classes/function.d.ts +2 -2
  6. package/dist/cjs/classes/historian.d.ts +3 -3
  7. package/dist/cjs/classes/tag.d.ts +2 -2
  8. package/dist/cjs/example/functions.js +2 -2
  9. package/dist/cjs/sdk-ts.d.ts +9 -8
  10. package/dist/cjs/sdk-ts.js +79 -37
  11. package/dist/cjs/services/http.service.d.ts +7 -2
  12. package/dist/cjs/services/http.service.js +32 -3
  13. package/dist/cjs/services/mqtt.service.d.ts +1 -1
  14. package/dist/cjs/services/mqtt.service.js +9 -2
  15. package/dist/cjs/types/auth.models.d.ts +2 -2
  16. package/dist/classes/auth.d.ts +2 -2
  17. package/dist/classes/collection.d.ts +2 -2
  18. package/dist/classes/collection.js +9 -0
  19. package/dist/classes/flow.d.ts +1 -1
  20. package/dist/classes/function.d.ts +2 -2
  21. package/dist/classes/historian.d.ts +3 -3
  22. package/dist/classes/tag.d.ts +2 -2
  23. package/dist/example/functions.js +1 -1
  24. package/dist/sdk-ts.d.ts +9 -8
  25. package/dist/sdk-ts.js +72 -30
  26. package/dist/services/http.service.d.ts +7 -2
  27. package/dist/services/http.service.js +32 -3
  28. package/dist/services/mqtt.service.d.ts +1 -1
  29. package/dist/services/mqtt.service.js +9 -2
  30. package/dist/types/auth.models.d.ts +2 -2
  31. package/package.json +1 -1
  32. package/src/classes/auth.ts +2 -2
  33. package/src/classes/collection.ts +11 -2
  34. package/src/classes/flow.ts +1 -1
  35. package/src/classes/function.ts +2 -2
  36. package/src/classes/historian.ts +3 -3
  37. package/src/classes/tag.ts +2 -2
  38. package/src/example/functions.ts +1 -1
  39. package/src/sdk-ts.ts +87 -31
  40. package/src/services/http.service.ts +50 -15
  41. package/src/services/mqtt.service.ts +9 -2
  42. package/src/types/auth.models.ts +2 -2
  43. package/src/utils/appConfig.ts +0 -30
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
3
3
  export declare class Auth {
4
4
  private httpService;
5
5
  constructor(httpService: HTTPService);
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { MQTTService } from "../services/mqtt.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { MQTTService } from "../services/mqtt.service.js";
3
3
  export declare class Collection {
4
4
  protected httpService: HTTPService;
5
5
  protected mqttService: MQTTService | null;
@@ -28,15 +28,24 @@ class Collection {
28
28
  return this.httpService.request.get(this.collectionName + "/all", this.queryParams);
29
29
  }
30
30
  async getOne(id) {
31
+ if (!id) {
32
+ throw new Error("ID must be provided");
33
+ }
31
34
  return this.httpService.request.get(id);
32
35
  }
33
36
  async create(data) {
34
37
  return this.httpService.request.withJSON(data).post(this.collectionName);
35
38
  }
36
39
  async update(id, data) {
40
+ if (!id) {
41
+ throw new Error("ID must be provided");
42
+ }
37
43
  return this.httpService.request.withJSON(data).put(id);
38
44
  }
39
45
  async delete(id) {
46
+ if (!id) {
47
+ throw new Error("ID must be provided");
48
+ }
40
49
  return this.httpService.request.delete(id);
41
50
  }
42
51
  }
@@ -1,4 +1,4 @@
1
- import { HTTPService } from "../services/http.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
2
  export declare class Flow {
3
3
  private httpService;
4
4
  constructor(httpService: HTTPService);
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { NATSService } from "../services/nats.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { NATSService } from "../services/nats.service.js";
3
3
  export declare class Function {
4
4
  private httpService;
5
5
  private natsService;
@@ -1,6 +1,6 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { MQTTService } from "../services/mqtt.service";
3
- import { HistorizedData } from "../types/tag.models";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { MQTTService } from "../services/mqtt.service.js";
3
+ import { HistorizedData } from "../types/tag.models.js";
4
4
  export declare class Historian {
5
5
  private httpService;
6
6
  private mqttService;
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { MQTTService } from "../services/mqtt.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { MQTTService } from "../services/mqtt.service.js";
3
3
  export declare class Tag {
4
4
  private httpService;
5
5
  private mqttService;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_1 = require("../index");
4
- let sdk = new index_1.SDK();
3
+ const index_js_1 = require("../index.js");
4
+ let sdk = new index_js_1.SDK();
5
5
  let config = {
6
6
  application_id: "machhub_admin",
7
7
  natsUrl: "nats://localhost:4222",
@@ -1,11 +1,12 @@
1
- import { Collection } from "./classes/collection";
2
- import { Historian } from "./classes/historian";
3
- import { Tag } from "./classes/tag";
4
- import { Function } from "./classes/function";
5
- import { Flow } from "./classes/flow";
6
- import { Auth } from "./classes/auth";
1
+ import { Collection } from "./classes/collection.js";
2
+ import { Historian } from "./classes/historian.js";
3
+ import { Tag } from "./classes/tag.js";
4
+ import { Function } from "./classes/function.js";
5
+ import { Flow } from "./classes/flow.js";
6
+ import { Auth } from "./classes/auth.js";
7
7
  export interface SDKConfig {
8
8
  application_id: string;
9
+ developer_key?: string;
9
10
  httpUrl?: string;
10
11
  mqttUrl?: string;
11
12
  natsUrl?: string;
@@ -28,7 +29,7 @@ export declare class SDK {
28
29
  *
29
30
  * const config: SDKConfig = {
30
31
  * application_id: 'your-app-id',
31
- * httpUrl: 'http://localhost:80', // optional (default = http://localhost:80)
32
+ * httpUrl: 'http://localhost:6188', // optional (default = http://localhost:6188)
32
33
  * mqttUrl: 'ws://localhost:180', // optional (default = ws://localhost:180)
33
34
  * natsUrl: 'ws://localhost:7500', // optional (default = ws://localhost:7500)
34
35
  * };
@@ -40,7 +41,7 @@ export declare class SDK {
40
41
  * @param config {SDKConfig} The configuration object containing initialization parameters. See SDKConfig for details.
41
42
  * @returns {Promise<boolean>} Resolves to true if initialization is successful.
42
43
  */
43
- Initialize(config: SDKConfig): Promise<boolean>;
44
+ Initialize(config?: SDKConfig): Promise<boolean>;
44
45
  /**
45
46
  * Getter for `auth`. Ensures `auth` is accessed only after initialization.
46
47
  */
@@ -1,38 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK = void 0;
4
- const http_service_1 = require("./services/http.service");
5
- const mqtt_service_1 = require("./services/mqtt.service");
6
- const nats_service_1 = require("./services/nats.service");
7
- const appConfig_1 = require("./utils/appConfig");
8
- const collection_1 = require("./classes/collection");
9
- const historian_1 = require("./classes/historian");
10
- const tag_1 = require("./classes/tag");
11
- const function_1 = require("./classes/function");
12
- const flow_1 = require("./classes/flow");
13
- const auth_1 = require("./classes/auth");
4
+ const http_service_js_1 = require("./services/http.service.js");
5
+ const mqtt_service_js_1 = require("./services/mqtt.service.js");
6
+ const nats_service_js_1 = require("./services/nats.service.js");
7
+ const collection_js_1 = require("./classes/collection.js");
8
+ const historian_js_1 = require("./classes/historian.js");
9
+ const tag_js_1 = require("./classes/tag.js");
10
+ const function_js_1 = require("./classes/function.js");
11
+ const flow_js_1 = require("./classes/flow.js");
12
+ const auth_js_1 = require("./classes/auth.js");
14
13
  const MACHHUB_SDK_PATH = "machhub";
15
14
  // Core HTTP client class
16
15
  class HTTPClient {
17
16
  /**
18
17
  * Creates a new HTTPClient instance
19
18
  * @param applicationID The ID for your application (required)
20
- * @param httpUrl The base URL for HTTP connection (default = http://localhost:80)
19
+ * @param httpUrl The base URL for HTTP connection (default = http://localhost:6188)
21
20
  */
22
- constructor(applicationID, httpUrl = "http://localhost:80") {
23
- if (!applicationID) {
24
- const config = (0, appConfig_1.getAppConfig)();
25
- if (config != undefined) {
26
- applicationID = config.application_id;
27
- }
28
- else {
29
- throw new Error("Failed to get Configuration.");
30
- }
31
- if (!applicationID) {
32
- throw new Error("Application ID is required. Set it via the APP_ID environment variable or pass it as a parameter.");
33
- }
34
- }
35
- this.httpService = new http_service_1.HTTPService(httpUrl, MACHHUB_SDK_PATH, applicationID);
21
+ constructor(applicationID, httpUrl, developerKey) {
22
+ this.httpService = new http_service_js_1.HTTPService(httpUrl, MACHHUB_SDK_PATH, applicationID, developerKey);
36
23
  }
37
24
  /**
38
25
  * Gets server info
@@ -51,7 +38,7 @@ class MQTTClient {
51
38
  * @param applicationID The ID for your application
52
39
  * @param mqttUrl The base URL for MQTT connection (default = ws://localhost:180)
53
40
  */
54
- static async getInstance(applicationID, mqttUrl = "ws://localhost:180") {
41
+ static async getInstance(applicationID, mqttUrl = "ws://localhost:180", developerKey) {
55
42
  // if (!applicationID) {
56
43
  // applicationID = process.env.APP_ID;
57
44
  // if (!applicationID) {
@@ -59,7 +46,7 @@ class MQTTClient {
59
46
  // }
60
47
  // }
61
48
  if (!this.instance) {
62
- const mqttService = await mqtt_service_1.MQTTService.getInstance(mqttUrl);
49
+ const mqttService = await mqtt_service_js_1.MQTTService.getInstance(mqttUrl, developerKey);
63
50
  this.instance = new MQTTClient(mqttService); // Use the constructor to initialize the instance
64
51
  }
65
52
  return this.instance;
@@ -93,7 +80,7 @@ class NATSClient {
93
80
  */
94
81
  static async getInstance(applicationID, natsUrl = "ws://localhost:7500") {
95
82
  if (!this.instance) {
96
- const natsService = await nats_service_1.NATSService.getInstance(natsUrl);
83
+ const natsService = await nats_service_js_1.NATSService.getInstance(natsUrl);
97
84
  this.instance = new NATSClient(natsService);
98
85
  }
99
86
  return this.instance;
@@ -136,7 +123,7 @@ class SDK {
136
123
  *
137
124
  * const config: SDKConfig = {
138
125
  * application_id: 'your-app-id',
139
- * httpUrl: 'http://localhost:80', // optional (default = http://localhost:80)
126
+ * httpUrl: 'http://localhost:6188', // optional (default = http://localhost:6188)
140
127
  * mqttUrl: 'ws://localhost:180', // optional (default = ws://localhost:180)
141
128
  * natsUrl: 'ws://localhost:7500', // optional (default = ws://localhost:7500)
142
129
  * };
@@ -150,15 +137,37 @@ class SDK {
150
137
  */
151
138
  async Initialize(config) {
152
139
  try {
140
+ console.log("Initializing SDK with config:", config);
141
+ // Methods to initialize config
142
+ // 1. Via application_id + URLs + developer key passed in config parameter
143
+ // 2. Via development server - Set via Extension/
144
+ // API to get Config (All SDK URLs default to localhost with port from querying current window or 61888)
145
+ if (config === undefined)
146
+ config = { application_id: "" };
147
+ if (!config.application_id)
148
+ config = { application_id: "" };
149
+ console.log("Using application_id:", config.application_id);
150
+ const PORT = await getEnvPort();
151
+ console.log("Using port:", PORT);
152
+ if (!config.httpUrl) {
153
+ config.httpUrl = "http://localhost:" + PORT;
154
+ }
155
+ if (!config.mqttUrl) {
156
+ config.mqttUrl = "ws://localhost:" + PORT + "/mqtt";
157
+ }
158
+ if (!config.natsUrl) {
159
+ config.natsUrl = "ws://localhost:" + PORT + "/nats";
160
+ }
153
161
  const { application_id, httpUrl, mqttUrl, natsUrl } = config;
154
- this.http = new HTTPClient(application_id, httpUrl);
155
- this.mqtt = await MQTTClient.getInstance(application_id, mqttUrl);
162
+ console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
163
+ this.http = new HTTPClient(application_id, httpUrl, config.developer_key);
164
+ this.mqtt = await MQTTClient.getInstance(application_id, mqttUrl, config.developer_key);
156
165
  this.nats = await NATSClient.getInstance(application_id, natsUrl);
157
- this._historian = new historian_1.Historian(this.http["httpService"], this.mqtt["mqttService"]);
158
- this._tag = new tag_1.Tag(this.http["httpService"], this.mqtt["mqttService"]);
159
- this._function = new function_1.Function(this.http["httpService"], this.nats["natsService"]);
160
- this._flow = new flow_1.Flow(this.http["httpService"]);
161
- this._auth = new auth_1.Auth(this.http["httpService"]);
166
+ this._historian = new historian_js_1.Historian(this.http["httpService"], this.mqtt["mqttService"]);
167
+ this._tag = new tag_js_1.Tag(this.http["httpService"], this.mqtt["mqttService"]);
168
+ this._function = new function_js_1.Function(this.http["httpService"], this.nats["natsService"]);
169
+ this._flow = new flow_js_1.Flow(this.http["httpService"]);
170
+ this._auth = new auth_js_1.Auth(this.http["httpService"]);
162
171
  }
163
172
  catch (error) {
164
173
  console.error("Failed to initialize:", error);
@@ -221,7 +230,40 @@ class SDK {
221
230
  if (!this.http) {
222
231
  throw new Error("SDK is not initialized. Call `Initialize` before accessing collection.");
223
232
  }
224
- return new collection_1.Collection(this.http["httpService"], this.mqtt ? this.mqtt["mqttService"] : null, collectionName);
233
+ return new collection_js_1.Collection(this.http["httpService"], this.mqtt ? this.mqtt["mqttService"] : null, collectionName);
225
234
  }
226
235
  }
227
236
  exports.SDK = SDK;
237
+ async function getEnvPort() {
238
+ console.log(window.location.origin);
239
+ try {
240
+ const response = await fetchData(window.location.origin + "/_cfg");
241
+ // console.log('Response:', response);
242
+ // console.log('runtimeID: ', response.runtimeID);
243
+ // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
244
+ return response.port;
245
+ }
246
+ catch (error) {
247
+ // console.log('No configured runtime ID:', error);
248
+ // TODO: Use DevPort from SDK Config or default to 61888
249
+ return "61888";
250
+ }
251
+ }
252
+ async function fetchData(url) {
253
+ try {
254
+ const response = await fetch(url, {
255
+ method: 'GET',
256
+ headers: {
257
+ 'Accept': 'application/json',
258
+ },
259
+ });
260
+ if (!response.ok) {
261
+ throw new Error(`HTTP error! status: ${response.status}`);
262
+ }
263
+ const data = await response.json();
264
+ return data;
265
+ }
266
+ catch (error) {
267
+ throw error;
268
+ }
269
+ }
@@ -8,16 +8,20 @@ export declare class HTTPException extends Error {
8
8
  export declare class HTTPService {
9
9
  private url;
10
10
  private applicationID;
11
- constructor(url: string, prefix?: string, applicationID?: string);
11
+ private developerKey?;
12
+ constructor(url: string, prefix: string, applicationID: string, developerKey?: string);
12
13
  get request(): RequestParameters;
14
+ private addRuntimeHeaders;
15
+ private getCookie;
13
16
  }
14
17
  declare class RequestParameters {
15
18
  private base;
16
19
  private applicationID;
20
+ private developerKey?;
17
21
  query?: Record<string, string>;
18
22
  init?: RequestInit;
19
23
  headers?: Record<string, string>;
20
- constructor(base: URL, applicationID: string, query?: Record<string, string>);
24
+ constructor(base: URL, applicationID: string, developerKey?: string, query?: Record<string, string>);
21
25
  private withQuery;
22
26
  private parseInit;
23
27
  withBody(body: BodyInit): RequestParameters;
@@ -30,6 +34,7 @@ declare class RequestParameters {
30
34
  setBearerToken(token: string): RequestParameters;
31
35
  withAccessToken(): RequestParameters;
32
36
  withDomain(): RequestParameters;
37
+ withDeveloperKey(): RequestParameters;
33
38
  withContentType(mime: string): RequestParameters;
34
39
  withJSON(body: Record<string, unknown>): RequestParameters;
35
40
  get<ReturnType>(path: string, query?: Record<string, string>): Promise<ReturnType>;
@@ -14,24 +14,47 @@ class HTTPException extends Error {
14
14
  }
15
15
  exports.HTTPException = HTTPException;
16
16
  class HTTPService {
17
- constructor(url, prefix, applicationID) {
17
+ constructor(url, prefix, applicationID, developerKey) {
18
18
  if (prefix == null)
19
19
  prefix = "";
20
20
  this.url = new URL(prefix, url);
21
21
  this.applicationID = "domains:" + applicationID;
22
+ this.developerKey = developerKey;
22
23
  }
23
24
  get request() {
24
- return new RequestParameters(this.url, this.applicationID);
25
+ return new RequestParameters(this.url, this.applicationID, this.developerKey);
26
+ }
27
+ addRuntimeHeaders(headers = {}) {
28
+ // Add runtime ID from cookie if available (for hosted applications)
29
+ if (typeof document !== 'undefined') {
30
+ const runtimeID = this.getCookie('machhub_runtime_id');
31
+ if (runtimeID) {
32
+ headers['X-MachHub-Runtime-ID'] = runtimeID;
33
+ }
34
+ }
35
+ return headers;
36
+ }
37
+ getCookie(name) {
38
+ if (typeof document === 'undefined')
39
+ return null;
40
+ const value = `; ${document.cookie}`;
41
+ const parts = value.split(`; ${name}=`);
42
+ if (parts.length === 2) {
43
+ return parts.pop()?.split(';').shift() || null;
44
+ }
45
+ return null;
25
46
  }
26
47
  }
27
48
  exports.HTTPService = HTTPService;
28
49
  class RequestParameters {
29
- constructor(base, applicationID, query) {
50
+ constructor(base, applicationID, developerKey, query) {
30
51
  this.base = base;
31
52
  this.applicationID = applicationID;
53
+ this.developerKey = developerKey;
32
54
  this.query = query;
33
55
  this.withDomain(); // Ensure withDomain() is called by default
34
56
  this.withAccessToken(); // Ensure withAccessToken() is called by default
57
+ this.withDeveloperKey(); // Ensure withDeveloperKey() is called by default
35
58
  }
36
59
  withQuery(path, query) {
37
60
  const newPath = [this.base.pathname, path].map(pathPart => pathPart.replace(/(^\/|\/$)/g, "")).join("/");
@@ -119,6 +142,12 @@ class RequestParameters {
119
142
  this.setHeader("Domain", this.applicationID);
120
143
  return this;
121
144
  }
145
+ withDeveloperKey() {
146
+ if (!this.developerKey)
147
+ return this;
148
+ this.setHeader("X-Machhub-Api-Key", this.developerKey);
149
+ return this;
150
+ }
122
151
  withContentType(mime) {
123
152
  this.setHeader("Content-Type", mime);
124
153
  return this;
@@ -5,7 +5,7 @@ export declare class MQTTService {
5
5
  private static instance;
6
6
  private subscribedTopics;
7
7
  constructor(url: string);
8
- static getInstance(url?: string): Promise<MQTTService>;
8
+ static getInstance(url?: string, developerKey?: string): Promise<MQTTService>;
9
9
  static resetInstance(): void;
10
10
  addTopicHandler(topic: string, handler: (message: unknown) => void): void;
11
11
  clearTopics(): void;
@@ -10,13 +10,20 @@ class MQTTService {
10
10
  this.subscribedTopics = [];
11
11
  this.url = url;
12
12
  }
13
- static async getInstance(url = "ws://localhost:180") {
13
+ static async getInstance(url = "ws://localhost:180", developerKey) {
14
14
  if (!this.instance || !this.instance.client) {
15
15
  this.instance = new MQTTService(url);
16
16
  // Ensure the URL is set correctly
17
17
  this.instance.url = url;
18
18
  // Initialize the MQTT client
19
- this.instance.client = mqtt_1.default.connect(this.instance.url, { protocolVersion: 5 });
19
+ const connectOptions = {
20
+ protocolVersion: 5,
21
+ ...(developerKey && {
22
+ username: "mch_developer_key",
23
+ password: developerKey,
24
+ })
25
+ };
26
+ this.instance.client = mqtt_1.default.connect(this.instance.url, connectOptions);
20
27
  this.instance.attachMessageListener();
21
28
  // console.log("MQTT Client initialized with URL:", this.instance.url);
22
29
  }
@@ -1,5 +1,5 @@
1
- import { RecordID } from "./recordID.models";
2
- import { BaseResponse } from "./response.models";
1
+ import { RecordID } from "./recordID.models.js";
2
+ import { BaseResponse } from "./response.models.js";
3
3
  export interface LoginResponse extends BaseResponse {
4
4
  tkn: string;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
3
3
  export declare class Auth {
4
4
  private httpService;
5
5
  constructor(httpService: HTTPService);
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { MQTTService } from "../services/mqtt.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { MQTTService } from "../services/mqtt.service.js";
3
3
  export declare class Collection {
4
4
  protected httpService: HTTPService;
5
5
  protected mqttService: MQTTService | null;
@@ -25,15 +25,24 @@ export class Collection {
25
25
  return this.httpService.request.get(this.collectionName + "/all", this.queryParams);
26
26
  }
27
27
  async getOne(id) {
28
+ if (!id) {
29
+ throw new Error("ID must be provided");
30
+ }
28
31
  return this.httpService.request.get(id);
29
32
  }
30
33
  async create(data) {
31
34
  return this.httpService.request.withJSON(data).post(this.collectionName);
32
35
  }
33
36
  async update(id, data) {
37
+ if (!id) {
38
+ throw new Error("ID must be provided");
39
+ }
34
40
  return this.httpService.request.withJSON(data).put(id);
35
41
  }
36
42
  async delete(id) {
43
+ if (!id) {
44
+ throw new Error("ID must be provided");
45
+ }
37
46
  return this.httpService.request.delete(id);
38
47
  }
39
48
  }
@@ -1,4 +1,4 @@
1
- import { HTTPService } from "../services/http.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
2
  export declare class Flow {
3
3
  private httpService;
4
4
  constructor(httpService: HTTPService);
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { NATSService } from "../services/nats.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { NATSService } from "../services/nats.service.js";
3
3
  export declare class Function {
4
4
  private httpService;
5
5
  private natsService;
@@ -1,6 +1,6 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { MQTTService } from "../services/mqtt.service";
3
- import { HistorizedData } from "../types/tag.models";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { MQTTService } from "../services/mqtt.service.js";
3
+ import { HistorizedData } from "../types/tag.models.js";
4
4
  export declare class Historian {
5
5
  private httpService;
6
6
  private mqttService;
@@ -1,5 +1,5 @@
1
- import { HTTPService } from "../services/http.service";
2
- import { MQTTService } from "../services/mqtt.service";
1
+ import { HTTPService } from "../services/http.service.js";
2
+ import { MQTTService } from "../services/mqtt.service.js";
3
3
  export declare class Tag {
4
4
  private httpService;
5
5
  private mqttService;
@@ -1,4 +1,4 @@
1
- import { SDK } from "../index";
1
+ import { SDK } from "../index.js";
2
2
  let sdk = new SDK();
3
3
  let config = {
4
4
  application_id: "machhub_admin",
package/dist/sdk-ts.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { Collection } from "./classes/collection";
2
- import { Historian } from "./classes/historian";
3
- import { Tag } from "./classes/tag";
4
- import { Function } from "./classes/function";
5
- import { Flow } from "./classes/flow";
6
- import { Auth } from "./classes/auth";
1
+ import { Collection } from "./classes/collection.js";
2
+ import { Historian } from "./classes/historian.js";
3
+ import { Tag } from "./classes/tag.js";
4
+ import { Function } from "./classes/function.js";
5
+ import { Flow } from "./classes/flow.js";
6
+ import { Auth } from "./classes/auth.js";
7
7
  export interface SDKConfig {
8
8
  application_id: string;
9
+ developer_key?: string;
9
10
  httpUrl?: string;
10
11
  mqttUrl?: string;
11
12
  natsUrl?: string;
@@ -28,7 +29,7 @@ export declare class SDK {
28
29
  *
29
30
  * const config: SDKConfig = {
30
31
  * application_id: 'your-app-id',
31
- * httpUrl: 'http://localhost:80', // optional (default = http://localhost:80)
32
+ * httpUrl: 'http://localhost:6188', // optional (default = http://localhost:6188)
32
33
  * mqttUrl: 'ws://localhost:180', // optional (default = ws://localhost:180)
33
34
  * natsUrl: 'ws://localhost:7500', // optional (default = ws://localhost:7500)
34
35
  * };
@@ -40,7 +41,7 @@ export declare class SDK {
40
41
  * @param config {SDKConfig} The configuration object containing initialization parameters. See SDKConfig for details.
41
42
  * @returns {Promise<boolean>} Resolves to true if initialization is successful.
42
43
  */
43
- Initialize(config: SDKConfig): Promise<boolean>;
44
+ Initialize(config?: SDKConfig): Promise<boolean>;
44
45
  /**
45
46
  * Getter for `auth`. Ensures `auth` is accessed only after initialization.
46
47
  */