@machhub-dev/sdk-ts 1.0.6 → 1.0.7

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.
@@ -0,0 +1,12 @@
1
+ import { HTTPService } from "../services/http.service.js";
2
+ export declare class Processes {
3
+ private httpService;
4
+ constructor(httpService: HTTPService);
5
+ /**
6
+ * Executes a process by name with optional input data
7
+ * @param name - The name of the process to execute
8
+ * @param input - Optional input data to pass to the process
9
+ * @returns The result of the process execution
10
+ */
11
+ execute(name: string, input?: Record<string, any>): Promise<any>;
12
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Processes = void 0;
4
+ class Processes {
5
+ constructor(httpService) {
6
+ this.httpService = httpService;
7
+ }
8
+ /**
9
+ * Executes a process by name with optional input data
10
+ * @param name - The name of the process to execute
11
+ * @param input - Optional input data to pass to the process
12
+ * @returns The result of the process execution
13
+ */
14
+ async execute(name, input) {
15
+ const payload = {
16
+ name,
17
+ input: input || {}
18
+ };
19
+ return await this.httpService.request.withJSON(payload).post("processes/execute");
20
+ }
21
+ }
22
+ exports.Processes = Processes;
@@ -3,6 +3,7 @@ import { Historian } from "./classes/historian.js";
3
3
  import { Tag } from "./classes/tag.js";
4
4
  import { Flow } from "./classes/flow.js";
5
5
  import { Auth } from "./classes/auth.js";
6
+ import { Processes } from "./classes/processes.js";
6
7
  export interface SDKConfig {
7
8
  application_id: string;
8
9
  developer_key?: string;
@@ -17,6 +18,7 @@ export declare class SDK {
17
18
  private _function;
18
19
  private _flow;
19
20
  private _auth;
21
+ private _processes;
20
22
  private applicationID;
21
23
  /**
22
24
  * Extracts the application ID from a runtime ID.
@@ -66,6 +68,10 @@ export declare class SDK {
66
68
  * Getter for `flow`. Ensures `flow` is accessed only after initialization.
67
69
  */
68
70
  get flow(): Flow;
71
+ /**
72
+ * Getter for `processes`. Ensures `processes` is accessed only after initialization.
73
+ */
74
+ get processes(): Processes;
69
75
  /**
70
76
  * Creates a collection instance to interact with the specified table/collection.
71
77
  * Throws an error if the SDK is not initialized.
@@ -8,6 +8,7 @@ const historian_js_1 = require("./classes/historian.js");
8
8
  const tag_js_1 = require("./classes/tag.js");
9
9
  const flow_js_1 = require("./classes/flow.js");
10
10
  const auth_js_1 = require("./classes/auth.js");
11
+ const processes_js_1 = require("./classes/processes.js");
11
12
  const MACHHUB_SDK_PATH = "machhub";
12
13
  // Core HTTP client class
13
14
  class HTTPClient {
@@ -76,6 +77,7 @@ class SDK {
76
77
  this._function = null;
77
78
  this._flow = null;
78
79
  this._auth = null;
80
+ this._processes = null;
79
81
  this.applicationID = "";
80
82
  }
81
83
  /**
@@ -131,10 +133,15 @@ class SDK {
131
133
  const secured = typeof window !== 'undefined' ? window.location.protocol === 'https:' : false;
132
134
  let host = hostname;
133
135
  if (envCfg.hostingMode === 'port' || !envCfg.hostingMode) {
134
- // In browser, use window.location.host which includes the port only when non-standard
135
- // (e.g. "localhost:6190" for local dev, "machhub.dev" when behind a reverse proxy on 443)
136
- // In non-browser environments, fall back to hostname:envCfg.port
137
- host = typeof window !== 'undefined' ? window.location.host : `${hostname}:${envCfg.port}`;
136
+ if (typeof window !== 'undefined' && envCfg.port !== '61888') {
137
+ // Behind a reverse proxy (e.g. Caddy on :443): use window.location.host which correctly
138
+ // omits the internal port (e.g. "machhub.dev" instead of "machhub.dev:6190")
139
+ host = window.location.host;
140
+ }
141
+ else {
142
+ // Dev server (default port 61888) or non-browser: use explicit hostname:port
143
+ host = `${hostname}:${envCfg.port}`;
144
+ }
138
145
  }
139
146
  else if (envCfg.hostingMode === 'path') {
140
147
  host += envCfg.pathHosted;
@@ -153,6 +160,7 @@ class SDK {
153
160
  this._tag = new tag_js_1.Tag(this.http["httpService"], this.mqtt["mqttService"]);
154
161
  this._flow = new flow_js_1.Flow(this.http["httpService"]);
155
162
  this._auth = new auth_js_1.Auth(this.http["httpService"], this.applicationID);
163
+ this._processes = new processes_js_1.Processes(this.http["httpService"]);
156
164
  }
157
165
  catch (error) {
158
166
  console.error("Failed to initialize:", error);
@@ -205,6 +213,15 @@ class SDK {
205
213
  }
206
214
  return this._flow;
207
215
  }
216
+ /**
217
+ * Getter for `processes`. Ensures `processes` is accessed only after initialization.
218
+ */
219
+ get processes() {
220
+ if (!this._processes) {
221
+ throw new Error("SDK is not initialized. Call `Initialize` before accessing `processes`.");
222
+ }
223
+ return this._processes;
224
+ }
208
225
  /**
209
226
  * Creates a collection instance to interact with the specified table/collection.
210
227
  * Throws an error if the SDK is not initialized.
@@ -223,8 +240,9 @@ async function getEnvConfig() {
223
240
  try {
224
241
  // Try to find the configuration endpoint by testing different base paths
225
242
  const configUrl = await findConfigEndpoint();
243
+ // console.log(`Fetching runtime configuration from: ${configUrl}`);
226
244
  const response = await fetchData(configUrl);
227
- // console.log('runtimeID: ', response.runtimeID);
245
+ // console.log('response: ', response);
228
246
  // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
229
247
  return response;
230
248
  }
@@ -0,0 +1,12 @@
1
+ import { HTTPService } from "../services/http.service.js";
2
+ export declare class Processes {
3
+ private httpService;
4
+ constructor(httpService: HTTPService);
5
+ /**
6
+ * Executes a process by name with optional input data
7
+ * @param name - The name of the process to execute
8
+ * @param input - Optional input data to pass to the process
9
+ * @returns The result of the process execution
10
+ */
11
+ execute(name: string, input?: Record<string, any>): Promise<any>;
12
+ }
@@ -0,0 +1,18 @@
1
+ export class Processes {
2
+ constructor(httpService) {
3
+ this.httpService = httpService;
4
+ }
5
+ /**
6
+ * Executes a process by name with optional input data
7
+ * @param name - The name of the process to execute
8
+ * @param input - Optional input data to pass to the process
9
+ * @returns The result of the process execution
10
+ */
11
+ async execute(name, input) {
12
+ const payload = {
13
+ name,
14
+ input: input || {}
15
+ };
16
+ return await this.httpService.request.withJSON(payload).post("processes/execute");
17
+ }
18
+ }
package/dist/sdk-ts.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Historian } from "./classes/historian.js";
3
3
  import { Tag } from "./classes/tag.js";
4
4
  import { Flow } from "./classes/flow.js";
5
5
  import { Auth } from "./classes/auth.js";
6
+ import { Processes } from "./classes/processes.js";
6
7
  export interface SDKConfig {
7
8
  application_id: string;
8
9
  developer_key?: string;
@@ -17,6 +18,7 @@ export declare class SDK {
17
18
  private _function;
18
19
  private _flow;
19
20
  private _auth;
21
+ private _processes;
20
22
  private applicationID;
21
23
  /**
22
24
  * Extracts the application ID from a runtime ID.
@@ -66,6 +68,10 @@ export declare class SDK {
66
68
  * Getter for `flow`. Ensures `flow` is accessed only after initialization.
67
69
  */
68
70
  get flow(): Flow;
71
+ /**
72
+ * Getter for `processes`. Ensures `processes` is accessed only after initialization.
73
+ */
74
+ get processes(): Processes;
69
75
  /**
70
76
  * Creates a collection instance to interact with the specified table/collection.
71
77
  * Throws an error if the SDK is not initialized.
package/dist/sdk-ts.js CHANGED
@@ -5,6 +5,7 @@ import { Historian } from "./classes/historian.js";
5
5
  import { Tag } from "./classes/tag.js";
6
6
  import { Flow } from "./classes/flow.js";
7
7
  import { Auth } from "./classes/auth.js";
8
+ import { Processes } from "./classes/processes.js";
8
9
  const MACHHUB_SDK_PATH = "machhub";
9
10
  // Core HTTP client class
10
11
  class HTTPClient {
@@ -73,6 +74,7 @@ export class SDK {
73
74
  this._function = null;
74
75
  this._flow = null;
75
76
  this._auth = null;
77
+ this._processes = null;
76
78
  this.applicationID = "";
77
79
  }
78
80
  /**
@@ -128,10 +130,15 @@ export class SDK {
128
130
  const secured = typeof window !== 'undefined' ? window.location.protocol === 'https:' : false;
129
131
  let host = hostname;
130
132
  if (envCfg.hostingMode === 'port' || !envCfg.hostingMode) {
131
- // In browser, use window.location.host which includes the port only when non-standard
132
- // (e.g. "localhost:6190" for local dev, "machhub.dev" when behind a reverse proxy on 443)
133
- // In non-browser environments, fall back to hostname:envCfg.port
134
- host = typeof window !== 'undefined' ? window.location.host : `${hostname}:${envCfg.port}`;
133
+ if (typeof window !== 'undefined' && envCfg.port !== '61888') {
134
+ // Behind a reverse proxy (e.g. Caddy on :443): use window.location.host which correctly
135
+ // omits the internal port (e.g. "machhub.dev" instead of "machhub.dev:6190")
136
+ host = window.location.host;
137
+ }
138
+ else {
139
+ // Dev server (default port 61888) or non-browser: use explicit hostname:port
140
+ host = `${hostname}:${envCfg.port}`;
141
+ }
135
142
  }
136
143
  else if (envCfg.hostingMode === 'path') {
137
144
  host += envCfg.pathHosted;
@@ -150,6 +157,7 @@ export class SDK {
150
157
  this._tag = new Tag(this.http["httpService"], this.mqtt["mqttService"]);
151
158
  this._flow = new Flow(this.http["httpService"]);
152
159
  this._auth = new Auth(this.http["httpService"], this.applicationID);
160
+ this._processes = new Processes(this.http["httpService"]);
153
161
  }
154
162
  catch (error) {
155
163
  console.error("Failed to initialize:", error);
@@ -202,6 +210,15 @@ export class SDK {
202
210
  }
203
211
  return this._flow;
204
212
  }
213
+ /**
214
+ * Getter for `processes`. Ensures `processes` is accessed only after initialization.
215
+ */
216
+ get processes() {
217
+ if (!this._processes) {
218
+ throw new Error("SDK is not initialized. Call `Initialize` before accessing `processes`.");
219
+ }
220
+ return this._processes;
221
+ }
205
222
  /**
206
223
  * Creates a collection instance to interact with the specified table/collection.
207
224
  * Throws an error if the SDK is not initialized.
@@ -219,8 +236,9 @@ async function getEnvConfig() {
219
236
  try {
220
237
  // Try to find the configuration endpoint by testing different base paths
221
238
  const configUrl = await findConfigEndpoint();
239
+ // console.log(`Fetching runtime configuration from: ${configUrl}`);
222
240
  const response = await fetchData(configUrl);
223
- // console.log('runtimeID: ', response.runtimeID);
241
+ // console.log('response: ', response);
224
242
  // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
225
243
  return response;
226
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -0,0 +1,23 @@
1
+ import { HTTPService } from "../services/http.service.js";
2
+
3
+ export class Processes {
4
+ private httpService: HTTPService;
5
+
6
+ constructor(httpService: HTTPService) {
7
+ this.httpService = httpService;
8
+ }
9
+
10
+ /**
11
+ * Executes a process by name with optional input data
12
+ * @param name - The name of the process to execute
13
+ * @param input - Optional input data to pass to the process
14
+ * @returns The result of the process execution
15
+ */
16
+ public async execute(name: string, input?: Record<string, any>): Promise<any> {
17
+ const payload = {
18
+ name,
19
+ input: input || {}
20
+ };
21
+ return await this.httpService.request.withJSON(payload).post("processes/execute");
22
+ }
23
+ }
package/src/sdk-ts.ts CHANGED
@@ -5,6 +5,7 @@ import { Historian } from "./classes/historian.js";
5
5
  import { Tag } from "./classes/tag.js";
6
6
  import { Flow } from "./classes/flow.js";
7
7
  import { Auth } from "./classes/auth.js";
8
+ import { Processes } from "./classes/processes.js";
8
9
 
9
10
  const MACHHUB_SDK_PATH = "machhub";
10
11
 
@@ -92,6 +93,7 @@ export class SDK {
92
93
  private _function: Function | null = null;
93
94
  private _flow: Flow | null = null;
94
95
  private _auth: Auth | null = null;
96
+ private _processes: Processes | null = null;
95
97
  private applicationID: string = "";
96
98
 
97
99
  /**
@@ -151,10 +153,14 @@ export class SDK {
151
153
 
152
154
  let host = hostname;
153
155
  if (envCfg.hostingMode === 'port' || !envCfg.hostingMode) {
154
- // In browser, use window.location.host which includes the port only when non-standard
155
- // (e.g. "localhost:6190" for local dev, "machhub.dev" when behind a reverse proxy on 443)
156
- // In non-browser environments, fall back to hostname:envCfg.port
157
- host = typeof window !== 'undefined' ? window.location.host : `${hostname}:${envCfg.port}`;
156
+ if (typeof window !== 'undefined' && envCfg.port !== '61888') {
157
+ // Behind a reverse proxy (e.g. Caddy on :443): use window.location.host which correctly
158
+ // omits the internal port (e.g. "machhub.dev" instead of "machhub.dev:6190")
159
+ host = window.location.host;
160
+ } else {
161
+ // Dev server (default port 61888) or non-browser: use explicit hostname:port
162
+ host = `${hostname}:${envCfg.port}`;
163
+ }
158
164
  } else if (envCfg.hostingMode === 'path') {
159
165
  host += envCfg.pathHosted;
160
166
  }
@@ -178,6 +184,7 @@ export class SDK {
178
184
  this._tag = new Tag(this.http["httpService"], this.mqtt["mqttService"]);
179
185
  this._flow = new Flow(this.http["httpService"]);
180
186
  this._auth = new Auth(this.http["httpService"], this.applicationID);
187
+ this._processes = new Processes(this.http["httpService"]);
181
188
  } catch (error: any) {
182
189
  console.error("Failed to initialize:", error);
183
190
  return false;
@@ -236,6 +243,16 @@ export class SDK {
236
243
  return this._flow;
237
244
  }
238
245
 
246
+ /**
247
+ * Getter for `processes`. Ensures `processes` is accessed only after initialization.
248
+ */
249
+ public get processes(): Processes {
250
+ if (!this._processes) {
251
+ throw new Error("SDK is not initialized. Call `Initialize` before accessing `processes`.");
252
+ }
253
+ return this._processes;
254
+ }
255
+
239
256
  /**
240
257
  * Creates a collection instance to interact with the specified table/collection.
241
258
  * Throws an error if the SDK is not initialized.
@@ -261,8 +278,9 @@ async function getEnvConfig(): Promise<RUNTIME_CONFIG> {
261
278
  try {
262
279
  // Try to find the configuration endpoint by testing different base paths
263
280
  const configUrl = await findConfigEndpoint();
281
+ // console.log(`Fetching runtime configuration from: ${configUrl}`);
264
282
  const response = await fetchData<RUNTIME_CONFIG>(configUrl);
265
- // console.log('runtimeID: ', response.runtimeID);
283
+ // console.log('response: ', response);
266
284
  // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
267
285
  return response;
268
286
  } catch (error) {