@machhub-dev/sdk-ts 1.0.5 → 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
  /**
@@ -126,12 +128,20 @@ class SDK {
126
128
  const application_id = config.application_id ||
127
129
  this.extractApplicationIDFromRuntimeID(envCfg.runtimeID);
128
130
  this.applicationID = application_id;
129
- // Determine the hostname - use window.location.hostname in browser, otherwise fallback to localhost
131
+ // Determine the hostname - use window.location in browser, otherwise fallback to localhost
130
132
  const hostname = typeof window !== 'undefined' ? window.location.hostname : 'localhost';
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
- host += `:${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
+ }
135
145
  }
136
146
  else if (envCfg.hostingMode === 'path') {
137
147
  host += envCfg.pathHosted;
@@ -150,6 +160,7 @@ class SDK {
150
160
  this._tag = new tag_js_1.Tag(this.http["httpService"], this.mqtt["mqttService"]);
151
161
  this._flow = new flow_js_1.Flow(this.http["httpService"]);
152
162
  this._auth = new auth_js_1.Auth(this.http["httpService"], this.applicationID);
163
+ this._processes = new processes_js_1.Processes(this.http["httpService"]);
153
164
  }
154
165
  catch (error) {
155
166
  console.error("Failed to initialize:", error);
@@ -202,6 +213,15 @@ class SDK {
202
213
  }
203
214
  return this._flow;
204
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
+ }
205
225
  /**
206
226
  * Creates a collection instance to interact with the specified table/collection.
207
227
  * Throws an error if the SDK is not initialized.
@@ -220,8 +240,9 @@ async function getEnvConfig() {
220
240
  try {
221
241
  // Try to find the configuration endpoint by testing different base paths
222
242
  const configUrl = await findConfigEndpoint();
243
+ // console.log(`Fetching runtime configuration from: ${configUrl}`);
223
244
  const response = await fetchData(configUrl);
224
- // console.log('runtimeID: ', response.runtimeID);
245
+ // console.log('response: ', response);
225
246
  // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
226
247
  return response;
227
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
  /**
@@ -123,12 +125,20 @@ export class SDK {
123
125
  const application_id = config.application_id ||
124
126
  this.extractApplicationIDFromRuntimeID(envCfg.runtimeID);
125
127
  this.applicationID = application_id;
126
- // Determine the hostname - use window.location.hostname in browser, otherwise fallback to localhost
128
+ // Determine the hostname - use window.location in browser, otherwise fallback to localhost
127
129
  const hostname = typeof window !== 'undefined' ? window.location.hostname : 'localhost';
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
- host += `:${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
+ }
132
142
  }
133
143
  else if (envCfg.hostingMode === 'path') {
134
144
  host += envCfg.pathHosted;
@@ -147,6 +157,7 @@ export class SDK {
147
157
  this._tag = new Tag(this.http["httpService"], this.mqtt["mqttService"]);
148
158
  this._flow = new Flow(this.http["httpService"]);
149
159
  this._auth = new Auth(this.http["httpService"], this.applicationID);
160
+ this._processes = new Processes(this.http["httpService"]);
150
161
  }
151
162
  catch (error) {
152
163
  console.error("Failed to initialize:", error);
@@ -199,6 +210,15 @@ export class SDK {
199
210
  }
200
211
  return this._flow;
201
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
+ }
202
222
  /**
203
223
  * Creates a collection instance to interact with the specified table/collection.
204
224
  * Throws an error if the SDK is not initialized.
@@ -216,8 +236,9 @@ async function getEnvConfig() {
216
236
  try {
217
237
  // Try to find the configuration endpoint by testing different base paths
218
238
  const configUrl = await findConfigEndpoint();
239
+ // console.log(`Fetching runtime configuration from: ${configUrl}`);
219
240
  const response = await fetchData(configUrl);
220
- // console.log('runtimeID: ', response.runtimeID);
241
+ // console.log('response: ', response);
221
242
  // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
222
243
  return response;
223
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "1.0.5",
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
  /**
@@ -145,15 +147,22 @@ export class SDK {
145
147
 
146
148
  this.applicationID = application_id;
147
149
 
148
- // Determine the hostname - use window.location.hostname in browser, otherwise fallback to localhost
150
+ // Determine the hostname - use window.location in browser, otherwise fallback to localhost
149
151
  const hostname = typeof window !== 'undefined' ? window.location.hostname : 'localhost';
150
152
  const secured = typeof window !== 'undefined' ? window.location.protocol === 'https:' : false;
151
153
 
152
- let host = hostname
154
+ let host = hostname;
153
155
  if (envCfg.hostingMode === 'port' || !envCfg.hostingMode) {
154
- host += `:${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
+ }
155
164
  } else if (envCfg.hostingMode === 'path') {
156
- host += envCfg.pathHosted
165
+ host += envCfg.pathHosted;
157
166
  }
158
167
 
159
168
  if (!config.httpUrl) {
@@ -175,6 +184,7 @@ export class SDK {
175
184
  this._tag = new Tag(this.http["httpService"], this.mqtt["mqttService"]);
176
185
  this._flow = new Flow(this.http["httpService"]);
177
186
  this._auth = new Auth(this.http["httpService"], this.applicationID);
187
+ this._processes = new Processes(this.http["httpService"]);
178
188
  } catch (error: any) {
179
189
  console.error("Failed to initialize:", error);
180
190
  return false;
@@ -233,6 +243,16 @@ export class SDK {
233
243
  return this._flow;
234
244
  }
235
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
+
236
256
  /**
237
257
  * Creates a collection instance to interact with the specified table/collection.
238
258
  * Throws an error if the SDK is not initialized.
@@ -258,8 +278,9 @@ async function getEnvConfig(): Promise<RUNTIME_CONFIG> {
258
278
  try {
259
279
  // Try to find the configuration endpoint by testing different base paths
260
280
  const configUrl = await findConfigEndpoint();
281
+ // console.log(`Fetching runtime configuration from: ${configUrl}`);
261
282
  const response = await fetchData<RUNTIME_CONFIG>(configUrl);
262
- // console.log('runtimeID: ', response.runtimeID);
283
+ // console.log('response: ', response);
263
284
  // console.log('applicationID: ', response.runtimeID.split('XmchX')[0]);
264
285
  return response;
265
286
  } catch (error) {