@machinemetrics/mm-erp-sdk 0.1.5-beta.0 → 0.1.6-beta.0

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 (94) hide show
  1. package/README.md +1 -1
  2. package/dist/{config-2l5vnNkA.js → config-CWRevSxh.js} +6 -6
  3. package/dist/{config-2l5vnNkA.js.map → config-CWRevSxh.js.map} +1 -1
  4. package/dist/{connector-factory-CQ8e7Tae.js → connector-factory-76kTjfE8.js} +12 -3
  5. package/dist/connector-factory-76kTjfE8.js.map +1 -0
  6. package/dist/{hashed-cache-manager-Ci59eC75.js → hashed-cache-manager-DW2y4SFu.js} +5 -4
  7. package/dist/{hashed-cache-manager-Ci59eC75.js.map → hashed-cache-manager-DW2y4SFu.js.map} +1 -1
  8. package/dist/{index-CXbOvFyf.js → index-DdqBliMK.js} +7 -7
  9. package/dist/{index-CXbOvFyf.js.map → index-DdqBliMK.js.map} +1 -1
  10. package/dist/index.d.ts +16 -6
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/{logger-QG73MndU.js → logger-nJCE--ZL.js} +51 -45
  13. package/dist/{logger-QG73MndU.js.map → logger-nJCE--ZL.js.map} +1 -1
  14. package/dist/mm-erp-sdk.js +14220 -135
  15. package/dist/mm-erp-sdk.js.map +1 -1
  16. package/dist/services/data-sync-service/index.d.ts +1 -1
  17. package/dist/services/data-sync-service/index.d.ts.map +1 -1
  18. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.d.ts +2 -0
  19. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.d.ts.map +1 -1
  20. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +42 -41
  21. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js.map +1 -1
  22. package/dist/services/data-sync-service/jobs/from-erp.d.ts.map +1 -1
  23. package/dist/services/data-sync-service/jobs/from-erp.js +11 -5
  24. package/dist/services/data-sync-service/jobs/from-erp.js.map +1 -1
  25. package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.d.ts +2 -0
  26. package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.d.ts.map +1 -1
  27. package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js +39 -40
  28. package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js.map +1 -1
  29. package/dist/services/data-sync-service/jobs/run-migrations.d.ts.map +1 -1
  30. package/dist/services/data-sync-service/jobs/run-migrations.js +4 -3
  31. package/dist/services/data-sync-service/jobs/run-migrations.js.map +1 -1
  32. package/dist/services/data-sync-service/jobs/to-erp.d.ts.map +1 -1
  33. package/dist/services/data-sync-service/jobs/to-erp.js +15 -5
  34. package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
  35. package/dist/services/erp-api-services/index.d.ts +5 -1
  36. package/dist/services/erp-api-services/index.d.ts.map +1 -1
  37. package/dist/services/mm-api-service/index.d.ts +3 -2
  38. package/dist/services/mm-api-service/index.d.ts.map +1 -1
  39. package/dist/services/mm-api-service/mm-api-service.d.ts +20 -0
  40. package/dist/services/mm-api-service/mm-api-service.d.ts.map +1 -1
  41. package/dist/services/psql-erp-service/configuration.d.ts +10 -0
  42. package/dist/services/psql-erp-service/configuration.d.ts.map +1 -0
  43. package/dist/services/psql-erp-service/index.d.ts +19 -0
  44. package/dist/services/psql-erp-service/index.d.ts.map +1 -0
  45. package/dist/services/psql-erp-service/internal/psql-config.d.ts +28 -0
  46. package/dist/services/psql-erp-service/internal/psql-config.d.ts.map +1 -0
  47. package/dist/services/psql-erp-service/internal/psql-labor-ticket-operations.d.ts +40 -0
  48. package/dist/services/psql-erp-service/internal/psql-labor-ticket-operations.d.ts.map +1 -0
  49. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts +15 -0
  50. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts.map +1 -0
  51. package/dist/services/psql-erp-service/psql-helpers.d.ts +32 -0
  52. package/dist/services/psql-erp-service/psql-helpers.d.ts.map +1 -0
  53. package/dist/services/psql-erp-service/psql-service.d.ts +49 -0
  54. package/dist/services/psql-erp-service/psql-service.d.ts.map +1 -0
  55. package/dist/utils/connector-factory.d.ts.map +1 -1
  56. package/dist/utils/connector-log/log-deduper.d.ts +56 -0
  57. package/dist/utils/connector-log/log-deduper.d.ts.map +1 -0
  58. package/dist/utils/connector-log/mm-connector-logger-example.d.ts +1 -0
  59. package/dist/utils/connector-log/mm-connector-logger-example.d.ts.map +1 -0
  60. package/dist/utils/connector-log/mm-connector-logger.d.ts +74 -0
  61. package/dist/utils/connector-log/mm-connector-logger.d.ts.map +1 -0
  62. package/dist/utils/error-utils.d.ts +2 -0
  63. package/dist/utils/error-utils.d.ts.map +1 -0
  64. package/dist/utils/index.d.ts +10 -1
  65. package/dist/utils/index.d.ts.map +1 -1
  66. package/dist/utils/standard-process-drivers/index.d.ts +2 -1
  67. package/dist/utils/standard-process-drivers/index.d.ts.map +1 -1
  68. package/package.json +2 -1
  69. package/src/index.ts +43 -7
  70. package/src/services/data-sync-service/index.ts +1 -4
  71. package/src/services/data-sync-service/jobs/clean-up-expired-cache.ts +19 -7
  72. package/src/services/data-sync-service/jobs/from-erp.ts +12 -5
  73. package/src/services/data-sync-service/jobs/retry-failed-labor-tickets.ts +15 -5
  74. package/src/services/data-sync-service/jobs/run-migrations.ts +5 -2
  75. package/src/services/data-sync-service/jobs/to-erp.ts +17 -5
  76. package/src/services/erp-api-services/index.ts +9 -1
  77. package/src/services/mm-api-service/index.ts +1 -1
  78. package/src/services/mm-api-service/mm-api-service.ts +28 -0
  79. package/src/services/psql-erp-service/configuration.ts +9 -0
  80. package/src/services/psql-erp-service/index.ts +28 -0
  81. package/src/services/psql-erp-service/internal/psql-config.ts +13 -0
  82. package/src/services/psql-erp-service/internal/psql-labor-ticket-operations.ts +58 -0
  83. package/src/services/psql-erp-service/internal/types/psql-types.ts +17 -0
  84. package/src/services/psql-erp-service/psql-helpers.ts +90 -0
  85. package/src/services/psql-erp-service/psql-service.ts +215 -0
  86. package/src/utils/application-initializer.ts +1 -1
  87. package/src/utils/connector-factory.ts +14 -3
  88. package/src/utils/connector-log/log-deduper.ts +284 -0
  89. package/src/utils/connector-log/mm-connector-logger-example.ts +97 -0
  90. package/src/utils/connector-log/mm-connector-logger.ts +177 -0
  91. package/src/utils/error-utils.ts +18 -0
  92. package/src/utils/index.ts +11 -4
  93. package/src/utils/standard-process-drivers/index.ts +2 -4
  94. package/dist/connector-factory-CQ8e7Tae.js.map +0 -1
@@ -52,8 +52,8 @@ export type {
52
52
  /**
53
53
  * Types related of labor tickets received from the MM API
54
54
  */
55
+ export { MMReceiveLaborTicket } from "./types/receive-types";
55
56
  export type {
56
- MMReceiveLaborTicket,
57
57
  MMReceiveLaborTicketReason,
58
58
  MMReceiveLaborTicketWorkOrderOperation,
59
59
  };
@@ -646,6 +646,34 @@ export class MMApiClient {
646
646
  );
647
647
  }
648
648
 
649
+ /**
650
+ * Send connector logs to the MM API
651
+ * @param logEntry Single log entry to send
652
+ * @returns Promise with the API response
653
+ */
654
+ async sendConnectorLog(logEntry: { source: string; level: string; message: string }): Promise<MMApiBaseResponse> {
655
+ return await this.postData(
656
+ '/connector/logs',
657
+ logEntry,
658
+ {},
659
+ { baseUrl: UrlBase.ApiBase }
660
+ );
661
+ }
662
+
663
+ /**
664
+ * Send bulk connector logs to the MM API
665
+ * @param logs Array of log entries to send
666
+ * @returns Promise with the API response
667
+ */
668
+ async sendBulkConnectorLogs(logs: { source: string; level: string; message: string }[]): Promise<MMApiBaseResponse> {
669
+ return await this.postData(
670
+ '/connector/logs',
671
+ { logs },
672
+ {},
673
+ { baseUrl: UrlBase.ApiBase }
674
+ );
675
+ }
676
+
649
677
  async deleteFailedLaborTicketIds(
650
678
  system: ERPType,
651
679
  laborTicketRefs: string[]
@@ -0,0 +1,9 @@
1
+ export interface PsqlConfiguration {
2
+ host: string;
3
+ port: string;
4
+ database: string;
5
+ username: string;
6
+ password: string;
7
+ connectionTimeout?: string;
8
+ requestTimeout?: string;
9
+ }
@@ -0,0 +1,28 @@
1
+ import { PsqlService } from "./psql-service";
2
+ import { PsqlLaborTicketOperations } from "./internal/psql-labor-ticket-operations";
3
+
4
+ /**
5
+ * A class to manage interactions with PSQL (Pervasive) databases via ODBC
6
+ */
7
+ export { PsqlService };
8
+
9
+ /**
10
+ * Labor ticket operations for PSQL (Phase 2)
11
+ */
12
+ export { PsqlLaborTicketOperations };
13
+
14
+ /**
15
+ * Configuration interface for PSQL connections
16
+ */
17
+ export type { PsqlConfiguration } from "./configuration";
18
+
19
+ /**
20
+ * Helper functions for PSQL data formatting
21
+ */
22
+ export {
23
+ formatPsqlDate,
24
+ formatPsqlTime,
25
+ combinePsqlDateTime,
26
+ isPsqlDateEmpty,
27
+ cleanPsqlCharField,
28
+ } from "./psql-helpers";
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ export const PsqlConfigSchema = z.object({
4
+ host: z.string().nonempty("Host is required."),
5
+ port: z.string().nonempty("Port is required."),
6
+ database: z.string().nonempty("Database name is required."),
7
+ username: z.string().nonempty("Username is required."),
8
+ password: z.string().nonempty("Password is required."),
9
+ connectionTimeout: z.string().optional().default("15000"),
10
+ requestTimeout: z.string().optional().default("15000"),
11
+ });
12
+
13
+ export type PsqlConfig = z.infer<typeof PsqlConfigSchema>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * PSQL Labor Ticket Operations
3
+ *
4
+ * Phase 2: This will handle INSERT/UPDATE/DELETE operations for labor tickets
5
+ * Phase 1: Placeholder - throws errors if called
6
+ */
7
+
8
+ import { PsqlService } from "../psql-service";
9
+ import { MMReceiveLaborTicket } from "../../../services/mm-api-service";
10
+ import logger from "../../reporting-service/logger";
11
+
12
+ export class PsqlLaborTicketOperations {
13
+ constructor(private service: PsqlService) {}
14
+
15
+ /**
16
+ * Create labor ticket in START_LABOR table
17
+ *
18
+ * Phase 2 Implementation Notes:
19
+ * - Will use prepared statements with parameter binding
20
+ * - Insert into START_LABOR table
21
+ * - Return GUID as erpUid
22
+ *
23
+ * @param laborTicket Labor ticket from MachineMetrics
24
+ * @returns Labor ticket and ERP unique ID
25
+ */
26
+ async createLaborTicket(
27
+ laborTicket: MMReceiveLaborTicket
28
+ ): Promise<{ laborTicket: MMReceiveLaborTicket; erpUid: string }> {
29
+ logger.warn(
30
+ "PsqlLaborTicketOperations.createLaborTicket not yet implemented (Phase 2)"
31
+ );
32
+ throw new Error(
33
+ "Labor ticket creation not implemented for PSQL. This is a Phase 2 feature."
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Update labor ticket (move from START_LABOR to COMPLETED_LABOR)
39
+ *
40
+ * Phase 2 Implementation Notes:
41
+ * - Insert into COMPLETED_LABOR
42
+ * - Delete from START_LABOR
43
+ * - Should be done in a transaction
44
+ *
45
+ * @param laborTicket Labor ticket to update
46
+ * @returns Updated labor ticket
47
+ */
48
+ async updateLaborTicket(
49
+ laborTicket: MMReceiveLaborTicket
50
+ ): Promise<MMReceiveLaborTicket> {
51
+ logger.warn(
52
+ "PsqlLaborTicketOperations.updateLaborTicket not yet implemented (Phase 2)"
53
+ );
54
+ throw new Error(
55
+ "Labor ticket update not implemented for PSQL. This is a Phase 2 feature."
56
+ );
57
+ }
58
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * PSQL-specific type definitions
3
+ */
4
+
5
+ export interface PsqlConnectionOptions {
6
+ connectionString: string;
7
+ }
8
+
9
+ export interface OdbcError {
10
+ state: string;
11
+ message: string;
12
+ code?: number;
13
+ }
14
+
15
+ export interface OdbcErrorResponse extends Error {
16
+ odbcErrors?: OdbcError[];
17
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Helper functions for PSQL/Pervasive database operations
3
+ */
4
+
5
+ /**
6
+ * Formats a date from PSQL YYMMDD format to ISO date string
7
+ * @param psqlDate Date in YYMMDD format (e.g., "250105" for Jan 5, 2025)
8
+ * @returns ISO date string (e.g., "2025-01-05") or null if invalid
9
+ */
10
+ export function formatPsqlDate(psqlDate: string): string | null {
11
+ if (!psqlDate || psqlDate === "000000" || psqlDate.trim() === "") {
12
+ return null;
13
+ }
14
+
15
+ try {
16
+ const year = parseInt(psqlDate.substring(0, 2), 10);
17
+ const month = parseInt(psqlDate.substring(2, 4), 10);
18
+ const day = parseInt(psqlDate.substring(4, 6), 10);
19
+
20
+ // Convert 2-digit year to 4-digit (assuming 2000s)
21
+ const fullYear = year + 2000;
22
+
23
+ // Basic validation
24
+ if (month < 1 || month > 12 || day < 1 || day > 31) {
25
+ return null;
26
+ }
27
+
28
+ const date = new Date(fullYear, month - 1, day);
29
+ return date.toISOString().split("T")[0];
30
+ } catch (error) {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Formats a time from PSQL HHMM format to HH:MM:SS
37
+ * @param psqlTime Time in HHMM format (e.g., "1430" for 2:30 PM)
38
+ * @returns Time string in HH:MM:SS format or null if invalid
39
+ */
40
+ export function formatPsqlTime(psqlTime: string): string | null {
41
+ if (!psqlTime || psqlTime.trim() === "") {
42
+ return null;
43
+ }
44
+
45
+ try {
46
+ const hours = psqlTime.substring(0, 2);
47
+ const minutes = psqlTime.substring(2, 4);
48
+ return `${hours}:${minutes}:00`;
49
+ } catch (error) {
50
+ return null;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Combines PSQL date and time into ISO datetime string
56
+ * @param psqlDate Date in YYMMDD format
57
+ * @param psqlTime Time in HHMM format
58
+ * @returns ISO datetime string or null if invalid
59
+ */
60
+ export function combinePsqlDateTime(
61
+ psqlDate: string,
62
+ psqlTime: string
63
+ ): string | null {
64
+ const date = formatPsqlDate(psqlDate);
65
+ const time = formatPsqlTime(psqlTime);
66
+
67
+ if (!date || !time) {
68
+ return null;
69
+ }
70
+
71
+ return `${date}T${time}`;
72
+ }
73
+
74
+ /**
75
+ * Helper to check if a PSQL date is "empty" (000000 or blank)
76
+ */
77
+ export function isPsqlDateEmpty(psqlDate: string): boolean {
78
+ return !psqlDate || psqlDate === "000000" || psqlDate.trim() === "";
79
+ }
80
+
81
+ /**
82
+ * Clean and trim PSQL CHAR field (removes trailing spaces)
83
+ * PSQL CHAR fields are fixed-width and padded with spaces
84
+ */
85
+ export function cleanPsqlCharField(value: string | null | undefined): string {
86
+ if (value === null || value === undefined) {
87
+ return "";
88
+ }
89
+ return String(value).trim();
90
+ }
@@ -0,0 +1,215 @@
1
+ import odbc from "odbc";
2
+ import { PsqlConfiguration } from "./configuration";
3
+ import { ERPResponse } from "../../types/erp-types";
4
+ import { OdbcErrorResponse } from "./internal/types/psql-types";
5
+ import logger from "../reporting-service/logger";
6
+
7
+ type PagingParams = {
8
+ limit?: number;
9
+ offset?: number;
10
+ };
11
+
12
+ export class PsqlService {
13
+ private connection: odbc.Connection | null = null;
14
+ private config: PsqlConfiguration;
15
+
16
+ constructor(config: PsqlConfiguration) {
17
+ this.config = config;
18
+ }
19
+
20
+ async dispose() {
21
+ await this.closeConnection();
22
+ }
23
+
24
+ /**
25
+ * Build PSQL ODBC connection string
26
+ * CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
27
+ */
28
+ private buildConnectionString(): string {
29
+ // PSQL requires ServerName in format IP.PORT (not IP:PORT)
30
+ const serverName = `${this.config.host}.${this.config.port}`;
31
+
32
+ return (
33
+ [
34
+ "Driver={Pervasive ODBC Interface}",
35
+ `ServerName=${serverName}`,
36
+ `DBQ=${this.config.database}`,
37
+ `UID=${this.config.username}`,
38
+ `PWD=${this.config.password}`,
39
+ "AutoDoubleQuote=0",
40
+ ].join(";") + ";"
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Execute a query and return the results
46
+ * Interface matches SqlServerService for consistency
47
+ *
48
+ * @param query The SQL query to execute
49
+ * @param params Query parameters (currently unused for PSQL read operations)
50
+ * @param paging Optional paging parameters
51
+ * @returns The entities fetched from the database, along with paging information
52
+ */
53
+ public async executePreparedStatement(
54
+ query: string,
55
+ params: Record<string, string> = {},
56
+ paging?: PagingParams
57
+ ): Promise<ERPResponse | undefined> {
58
+ const connection = await this.openConnection();
59
+
60
+ let records;
61
+ try {
62
+ // For Phase 1 (read-only), we execute queries directly
63
+ // Phase 2 will add proper parameter binding for INSERT/UPDATE/DELETE
64
+ if (Object.keys(params).length > 0) {
65
+ logger.warn(
66
+ "PsqlService: Query parameters provided but parameter binding not yet implemented. " +
67
+ "Using direct query execution. This is acceptable for Phase 1 read operations."
68
+ );
69
+ }
70
+
71
+ records = await connection.query(query);
72
+ } catch (error) {
73
+ const errorInfo = error as OdbcErrorResponse;
74
+ logger.error("Error fetching data from PSQL", {
75
+ error: errorInfo.message,
76
+ odbcErrors: errorInfo.odbcErrors,
77
+ });
78
+
79
+ throw this.handleOdbcError(errorInfo);
80
+ }
81
+
82
+ const allRecords = PsqlService.recordsetToRecords(records);
83
+ const rowsFetched = allRecords.length;
84
+
85
+ // Apply paging if requested
86
+ const pagedData =
87
+ paging?.offset !== undefined || paging?.limit !== undefined
88
+ ? allRecords.slice(
89
+ paging.offset || 0,
90
+ (paging.offset || 0) + (paging.limit || allRecords.length)
91
+ )
92
+ : allRecords;
93
+
94
+ return {
95
+ data: pagedData,
96
+ paging: {
97
+ count: rowsFetched,
98
+ limit: paging?.limit || 0,
99
+ offset: paging?.offset || 0,
100
+ nextPage:
101
+ paging?.limit && (paging.offset || 0) + paging.limit < rowsFetched
102
+ ? String((paging.offset || 0) + paging.limit)
103
+ : undefined,
104
+ previousPage: paging?.offset
105
+ ? String(Math.max(0, (paging.offset || 0) - (paging.limit || 10)))
106
+ : undefined,
107
+ },
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Opens a connection to PSQL database
113
+ * Caches the connection so that it can be reused.
114
+ * On failure to connect, throws
115
+ */
116
+ async openConnection(): Promise<odbc.Connection> {
117
+ // If we have a connection, reuse it
118
+ // Note: ODBC connections don't have a .connected property like SQL Server
119
+ // We'll keep it simple and reuse if not null
120
+ if (this.connection) {
121
+ logger.debug("Reusing existing PSQL connection");
122
+ return this.connection;
123
+ }
124
+
125
+ try {
126
+ const connStr = this.buildConnectionString();
127
+ logger.info("Opening new PSQL connection");
128
+ logger.debug(
129
+ "Connection string (password hidden):",
130
+ connStr.replace(/PWD=[^;]+/, "PWD=***")
131
+ );
132
+
133
+ this.connection = await odbc.connect(connStr);
134
+ logger.info("Successfully connected to PSQL database");
135
+ return this.connection;
136
+ } catch (error) {
137
+ logger.error("PsqlService>>openConnection>> Connection failed", {
138
+ error,
139
+ });
140
+ throw this.handleOdbcError(error as OdbcErrorResponse);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Transform ODBC result set to array of Record<string, string> instances.
146
+ * IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
147
+ *
148
+ * @param recordset Result set from ODBC query
149
+ * @returns array of Record<string, string> instances
150
+ */
151
+ public static recordsetToRecords(recordset: any[]): Record<string, string>[] {
152
+ if (!Array.isArray(recordset)) {
153
+ return [];
154
+ }
155
+
156
+ const data: Record<string, string>[] = recordset.map((row) => {
157
+ const transformedRow: Record<string, string> = {};
158
+ Object.keys(row).forEach((key) => {
159
+ const value = row[key];
160
+ // Convert to string and trim (PSQL CHAR fields have trailing spaces)
161
+ transformedRow[key] =
162
+ value !== null && value !== undefined ? String(value).trim() : "";
163
+ });
164
+ return transformedRow;
165
+ });
166
+
167
+ return data;
168
+ }
169
+
170
+ /**
171
+ * Handle ODBC errors and provide meaningful messages
172
+ */
173
+ private handleOdbcError(error: OdbcErrorResponse): Error {
174
+ const odbcError = error.odbcErrors?.[0];
175
+ const errorCode = odbcError?.state;
176
+ const message = odbcError?.message || error.message;
177
+
178
+ switch (errorCode) {
179
+ case "08S01":
180
+ return new Error(
181
+ "PSQL connection failed. Check: " +
182
+ "1) PVSW environment variable set to /usr/local/psql/etc/pvsw.ini, " +
183
+ "2) Network connectivity to ports 1583/3351, " +
184
+ "3) ODBC configuration files in /usr/local/psql/etc/ and /etc/. " +
185
+ `Original error: ${message}`
186
+ );
187
+ case "28000":
188
+ return new Error(
189
+ `PSQL authentication failed. Check username/password. Original error: ${message}`
190
+ );
191
+ case "42000":
192
+ return new Error(`PSQL SQL syntax error. Original error: ${message}`);
193
+ case "42S02":
194
+ return new Error(
195
+ `PSQL table or view not found. Check table names in query. Original error: ${message}`
196
+ );
197
+ default:
198
+ return new Error(`PSQL error (${errorCode || "unknown"}): ${message}`);
199
+ }
200
+ }
201
+
202
+ private async closeConnection(): Promise<void> {
203
+ if (this.connection) {
204
+ logger.info("Closing PSQL connection");
205
+ try {
206
+ await this.connection.close();
207
+ } catch (error) {
208
+ logger.error("PsqlService::closeConnection: Error closing connection", {
209
+ error,
210
+ });
211
+ }
212
+ this.connection = null;
213
+ }
214
+ }
215
+ }
@@ -41,7 +41,7 @@ export class ApplicationInitializer {
41
41
  );
42
42
  } catch (error) {
43
43
  logger.error("Critical initialization failure. Exiting.", error);
44
- process.exit(1);
44
+ process.exitCode = 1;
45
45
  }
46
46
  }
47
47
 
@@ -1,5 +1,6 @@
1
1
  import { IERPConnector } from "../types/erp-connector";
2
2
  import logger from "../services/reporting-service/logger";
3
+ import { pathToFileURL } from "url";
3
4
 
4
5
  /**
5
6
  * Helper function to dynamically import and create connector instance from a file path
@@ -10,8 +11,18 @@ export const createConnectorFromPath = async (
10
11
  connectorPath: string
11
12
  ): Promise<IERPConnector> => {
12
13
  try {
13
- // Dynamic import the connector module
14
- const connectorModule = await import(connectorPath);
14
+ // Some detailed debug logging to help with troubleshooting multi-platform connector paths
15
+ const pathParts = connectorPath.split('/');
16
+ const filename = pathParts[pathParts.length - 1];
17
+
18
+ logger.debug("createConnectorFromPath:", {
19
+ connectorPath,
20
+ pathParts,
21
+ filename,
22
+ finalImport: pathToFileURL(connectorPath).href,
23
+ });
24
+
25
+ const connectorModule = await import(pathToFileURL(connectorPath).href);
15
26
 
16
27
  // Get the default export or named export
17
28
  const ConnectorClass =
@@ -31,4 +42,4 @@ export const createConnectorFromPath = async (
31
42
  );
32
43
  throw error;
33
44
  }
34
- };
45
+ };