@vention/machine-apps-components 0.2.10 → 0.3.1

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 CHANGED
@@ -304,7 +304,7 @@ type LogType = "error" | "warning" | "info"
304
304
  interface LogEntry {
305
305
  id: string
306
306
  date: string // ISO or locale string parsable by Date
307
- type: LogType
307
+ level: LogType
308
308
  code: string
309
309
  message: string
310
310
  description: string
package/index.esm.js CHANGED
@@ -1063,8 +1063,8 @@ const LogsTable = memo(({
1063
1063
  })
1064
1064
  });
1065
1065
  }
1066
- const getTypeClassName = type => {
1067
- switch (type) {
1066
+ const getTypeClassName = level => {
1067
+ switch (level) {
1068
1068
  case "error":
1069
1069
  return classes.errorType;
1070
1070
  case "warning":
@@ -1075,15 +1075,15 @@ const LogsTable = memo(({
1075
1075
  return "";
1076
1076
  }
1077
1077
  };
1078
- const renderTypeIcon = type => {
1079
- if (type === "error") {
1078
+ const renderTypeIcon = level => {
1079
+ if (level === "error") {
1080
1080
  return jsx(VentionIcon, {
1081
1081
  size: 20,
1082
1082
  type: "alert-circle-filled",
1083
1083
  color: theme.palette.error.main
1084
1084
  });
1085
1085
  }
1086
- if (type === "warning") {
1086
+ if (level === "warning") {
1087
1087
  return jsx(VentionIcon, {
1088
1088
  size: 20,
1089
1089
  type: "alert-triangle-filled",
@@ -1157,7 +1157,7 @@ const LogsTable = memo(({
1157
1157
  className: classes.iconCell,
1158
1158
  children: jsx(Box, {
1159
1159
  className: classes.iconWrapper,
1160
- children: renderTypeIcon(log.type)
1160
+ children: renderTypeIcon(log.level)
1161
1161
  })
1162
1162
  }), jsx(TableCell, {
1163
1163
  children: jsx(Typography, {
@@ -1166,11 +1166,11 @@ const LogsTable = memo(({
1166
1166
  children: formatDate(log.date)
1167
1167
  })
1168
1168
  }), jsx(TableCell, {
1169
- className: cx(classes.typeCell, getTypeClassName(log.type)),
1169
+ className: cx(classes.typeCell, getTypeClassName(log.level)),
1170
1170
  children: jsx(Typography, {
1171
1171
  variant: "heading24Medium",
1172
1172
  className: classes.tableText,
1173
- children: log.type
1173
+ children: log.level
1174
1174
  })
1175
1175
  }), jsx(TableCell, {
1176
1176
  children: jsx(Typography, {
@@ -1708,4 +1708,60 @@ const useStyles = tss.create(({
1708
1708
  }
1709
1709
  }));
1710
1710
 
1711
- export { LogFilterForm, LogsPagination, LogsPanel, LogsTable, NavigationBar, NavigationConfirmationModal, PasswordProtectionModal, Sidebar, StatusTopBar, TimeLabel, formatDateToInput, parseLogDate };
1711
+ /**
1712
+ * This module provides utilities for generating API base URLs for machine apps.
1713
+ * It automatically detects the environment and returns the appropriate URL:
1714
+ * - Local/Edge: http://hostname:8000
1715
+ * - Deployed: Uses passthrough URL for digital twin infrastructure
1716
+ */
1717
+ /**
1718
+ * Gets the execution engine HTTP URL for deployed environments
1719
+ * @param processName - The name of the process/service
1720
+ * @returns The full URL for the execution engine API
1721
+ */
1722
+ function getExecutionEngineHttpUrl(processName) {
1723
+ const {
1724
+ href,
1725
+ port,
1726
+ hostname,
1727
+ origin
1728
+ } = window.location;
1729
+ const pathParts = new URL(href).pathname.split("/").filter(Boolean);
1730
+ const passthroughIndex = pathParts.indexOf("passthrough");
1731
+ const hmiIndex = pathParts.indexOf("hmi");
1732
+ const sessionId = passthroughIndex >= 0 && passthroughIndex < pathParts.length - 1 ? pathParts[passthroughIndex + 1] : hmiIndex > 0 ? pathParts[hmiIndex - 1] : "";
1733
+ const basePath = `/digital-twin/machine-motion/passthrough/${sessionId}/80/v1/machineCode/services/${processName}`;
1734
+ const isDev = port === "5173" || hostname === "localhost";
1735
+ const baseOrigin = isDev ? "https://digital-twin.vention.foo" : origin;
1736
+ return `${baseOrigin}${basePath}`;
1737
+ }
1738
+ /**
1739
+ * Checks if the current environment is running on edge (local controller)
1740
+ * @returns true if running on edge, false otherwise
1741
+ */
1742
+ function isOnEdge() {
1743
+ return window.location.hostname.startsWith("192.168") || window.location.hostname.startsWith("localhost");
1744
+ }
1745
+ /**
1746
+ * Gets the API base URL for the specified process/service
1747
+ * @param options - Configuration options including process name and optional edge port
1748
+ * @returns The API base URL for all backend API calls
1749
+ * @example
1750
+ * ```ts
1751
+ * const apiUrl = getApiBaseUrl({ processName: "ai-operator" })
1752
+ * // Returns: http://192.168.1.100:8000 (on edge)
1753
+ * // or https://digital-twin.../passthrough/.../ai-operator (deployed)
1754
+ * ```
1755
+ */
1756
+ function getApiBaseUrl(options) {
1757
+ const {
1758
+ processName,
1759
+ edgePort = 8000
1760
+ } = options;
1761
+ if (isOnEdge()) {
1762
+ return `http://${window.location.hostname}:${edgePort}`;
1763
+ }
1764
+ return getExecutionEngineHttpUrl(processName);
1765
+ }
1766
+
1767
+ export { LogFilterForm, LogsPagination, LogsPanel, LogsTable, NavigationBar, NavigationConfirmationModal, PasswordProtectionModal, Sidebar, StatusTopBar, TimeLabel, closeCustomUi, formatDateToInput, getApiBaseUrl, isOnEdge, isTouchScreenDevice, navigateControlCenter, parseLogDate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vention/machine-apps-components",
3
- "version": "0.2.10",
3
+ "version": "0.3.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/VentionCo/machine-cloud.git"
@@ -18,7 +18,7 @@
18
18
  "react": "17.0.2",
19
19
  "react-router-dom": "^6.0.0",
20
20
  "@mui/material": "^5.0.0",
21
- "@ventionco/machine-ui": "3.30.3"
21
+ "@ventionco/machine-ui": "3.30.4"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@nx/vite": "21.1.3",
package/src/index.d.ts CHANGED
@@ -10,3 +10,5 @@ export * from "./lib/logs/log-filter-form";
10
10
  export * from "./lib/logs/logs-panel";
11
11
  export * from "./lib/logs/logs-pagination";
12
12
  export type { LogEntry, LogFilterFormValues, SortOrder, LogType, PaginationMode, PaginationConfig, LogsPanelHandle, } from "./lib/logs/logs-panel";
13
+ export * from "./lib/utils/api-config-utils";
14
+ export * from "./lib/utils/device-utils";
@@ -3,7 +3,7 @@ export type LogType = "error" | "warning" | "info";
3
3
  export interface LogEntry {
4
4
  id: string;
5
5
  date: string;
6
- type: LogType;
6
+ level: LogType;
7
7
  code: string;
8
8
  message: string;
9
9
  description: string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * This module provides utilities for generating API base URLs for machine apps.
3
+ * It automatically detects the environment and returns the appropriate URL:
4
+ * - Local/Edge: http://hostname:8000
5
+ * - Deployed: Uses passthrough URL for digital twin infrastructure
6
+ */
7
+ interface ApiConfigOptions {
8
+ /**
9
+ * The name of the process/service (e.g., "ai-operator", "my-service")
10
+ */
11
+ processName: string;
12
+ /**
13
+ * Optional custom port for edge/local development (default: 8000)
14
+ */
15
+ edgePort?: number;
16
+ }
17
+ /**
18
+ * Checks if the current environment is running on edge (local controller)
19
+ * @returns true if running on edge, false otherwise
20
+ */
21
+ export declare function isOnEdge(): boolean;
22
+ /**
23
+ * Gets the API base URL for the specified process/service
24
+ * @param options - Configuration options including process name and optional edge port
25
+ * @returns The API base URL for all backend API calls
26
+ * @example
27
+ * ```ts
28
+ * const apiUrl = getApiBaseUrl({ processName: "ai-operator" })
29
+ * // Returns: http://192.168.1.100:8000 (on edge)
30
+ * // or https://digital-twin.../passthrough/.../ai-operator (deployed)
31
+ * ```
32
+ */
33
+ export declare function getApiBaseUrl(options: ApiConfigOptions): string;
34
+ export {};