@machinemetrics/mm-erp-sdk 0.1.8-beta.6 → 0.1.8-beta.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.
|
@@ -6,7 +6,14 @@ type PagingParams = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare class PsqlService {
|
|
8
8
|
private config;
|
|
9
|
+
private static odbcModule;
|
|
10
|
+
private static odbcLoadError;
|
|
9
11
|
constructor(config: PsqlConfiguration);
|
|
12
|
+
/**
|
|
13
|
+
* Dynamically load the ODBC module with lazy initialization and caching
|
|
14
|
+
* @throws Error with helpful message if ODBC package is not installed
|
|
15
|
+
*/
|
|
16
|
+
private static getOdbc;
|
|
10
17
|
/**
|
|
11
18
|
* Build PSQL ODBC connection string
|
|
12
19
|
* CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"psql-service.d.ts","sourceRoot":"","sources":["../../../src/services/psql-erp-service/psql-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"psql-service.d.ts","sourceRoot":"","sources":["../../../src/services/psql-erp-service/psql-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAiBF,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAC,UAAU,CAA2B;IACpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAsB;gBAEtC,MAAM,EAAE,iBAAiB;IAIrC;;;OAGG;mBACkB,OAAO;IAsC5B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAe7B;;;;;;;;OAQG;IACU,wBAAwB,CACnC,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACnC,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IA8EnC;;;OAGG;WACW,kBAAkB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IAkB5E;;OAEG;IACH,OAAO,CAAC,eAAe;CA4BxB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@machinemetrics/mm-erp-sdk",
|
|
3
3
|
"description": "A library for syncing data between MachineMetrics and ERP systems",
|
|
4
|
-
"version": "0.1.8-beta.
|
|
4
|
+
"version": "0.1.8-beta.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "machinemetrics",
|
|
7
7
|
"main": "dist/mm-erp-sdk.js",
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
"knex": "^3.1.0",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
30
|
"mssql": "^11.0.1",
|
|
31
|
-
"odbc": "^2.4.8",
|
|
32
31
|
"winston": "^3.14.0",
|
|
33
32
|
"winston-daily-rotate-file": "^5.0.0",
|
|
34
33
|
"xxhashjs": "^0.2.2",
|
|
35
34
|
"zod": "^3.24.1"
|
|
36
35
|
},
|
|
36
|
+
"optionalDependencies": {
|
|
37
|
+
"odbc": "^2.4.8"
|
|
38
|
+
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"@types/json-stable-stringify": "^1.1.0",
|
|
39
41
|
"@types/lodash": "^4.17.10",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import odbc from "odbc";
|
|
2
1
|
import { PsqlConfiguration } from "./configuration";
|
|
3
2
|
import { ERPResponse } from "../../types/erp-types";
|
|
4
3
|
import { OdbcErrorResponse } from "./internal/types/psql-types";
|
|
@@ -9,13 +8,67 @@ type PagingParams = {
|
|
|
9
8
|
offset?: number;
|
|
10
9
|
};
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* ODBC connection interface for type safety
|
|
13
|
+
*/
|
|
14
|
+
interface OdbcConnection {
|
|
15
|
+
query(sql: string): Promise<any[]>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* ODBC module interface
|
|
21
|
+
*/
|
|
22
|
+
interface OdbcModule {
|
|
23
|
+
connect(connectionString: string): Promise<OdbcConnection>;
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
export class PsqlService {
|
|
13
27
|
private config: PsqlConfiguration;
|
|
28
|
+
private static odbcModule: OdbcModule | null = null;
|
|
29
|
+
private static odbcLoadError: Error | null = null;
|
|
14
30
|
|
|
15
31
|
constructor(config: PsqlConfiguration) {
|
|
16
32
|
this.config = config;
|
|
17
33
|
}
|
|
18
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Dynamically load the ODBC module with lazy initialization and caching
|
|
37
|
+
* @throws Error with helpful message if ODBC package is not installed
|
|
38
|
+
*/
|
|
39
|
+
private static async getOdbc(): Promise<OdbcModule> {
|
|
40
|
+
// If we've already tried and failed, throw the cached error
|
|
41
|
+
if (this.odbcLoadError) {
|
|
42
|
+
throw this.odbcLoadError;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If already loaded, return cached module
|
|
46
|
+
if (this.odbcModule) {
|
|
47
|
+
return this.odbcModule;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// Dynamic import - only loads when actually needed
|
|
52
|
+
// @ts-ignore - odbc is an optional dependency, may not be installed at build time
|
|
53
|
+
const odbcImport = await import("odbc");
|
|
54
|
+
// Handle both default export and named export patterns
|
|
55
|
+
const odbc = odbcImport.default || odbcImport;
|
|
56
|
+
this.odbcModule = odbc as OdbcModule;
|
|
57
|
+
return this.odbcModule;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
60
|
+
this.odbcLoadError = new Error(
|
|
61
|
+
`ODBC package is required for PSQL service but is not installed or failed to load.\n` +
|
|
62
|
+
`Install it with: npm install odbc\n` +
|
|
63
|
+
`Also install OS-level dependencies, e.g. on Alpine Linux:\n` +
|
|
64
|
+
` apk add --no-cache unixodbc unixodbc-dev python3 make g++\n` +
|
|
65
|
+
`For other Linux distributions, install unixodbc and unixodbc-dev packages.\n` +
|
|
66
|
+
`Original error: ${errorMessage}`
|
|
67
|
+
);
|
|
68
|
+
throw this.odbcLoadError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
19
72
|
// REMOVED: dispose() method - not needed anymore
|
|
20
73
|
// REMOVED: connection property - not needed anymore
|
|
21
74
|
// REMOVED: openConnection() method - not needed anymore
|
|
@@ -54,7 +107,9 @@ export class PsqlService {
|
|
|
54
107
|
params: Record<string, string> = {},
|
|
55
108
|
paging?: PagingParams
|
|
56
109
|
): Promise<ERPResponse | undefined> {
|
|
57
|
-
|
|
110
|
+
// Dynamically load ODBC module (will throw helpful error if not installed)
|
|
111
|
+
const odbc = await PsqlService.getOdbc();
|
|
112
|
+
let connection: OdbcConnection | null = null;
|
|
58
113
|
|
|
59
114
|
try {
|
|
60
115
|
// Create fresh connection for THIS query only
|
|
@@ -98,6 +153,13 @@ export class PsqlService {
|
|
|
98
153
|
},
|
|
99
154
|
};
|
|
100
155
|
} catch (error) {
|
|
156
|
+
// If this is an ODBC load error (from getOdbc), re-throw it as-is
|
|
157
|
+
// since it already has a helpful error message
|
|
158
|
+
if (error instanceof Error && error.message.includes("ODBC package is required")) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Otherwise, handle as ODBC runtime error
|
|
101
163
|
const errorInfo = error as OdbcErrorResponse;
|
|
102
164
|
logger.error("Error fetching data from PSQL", {
|
|
103
165
|
error: errorInfo.message,
|