@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.
@@ -14,7 +14,6 @@ import Graceful from "@ladjs/graceful";
14
14
  import { fileURLToPath } from "url";
15
15
  import sql from "mssql";
16
16
  import { z } from "zod";
17
- import odbc from "odbc";
18
17
  var ERPType = /* @__PURE__ */ ((ERPType2) => {
19
18
  ERPType2["INVALID"] = "INVALID";
20
19
  ERPType2["D365"] = "D365";
@@ -3986,9 +3985,40 @@ class SqlServerHelper {
3986
3985
  }
3987
3986
  class PsqlService {
3988
3987
  config;
3988
+ static odbcModule = null;
3989
+ static odbcLoadError = null;
3989
3990
  constructor(config2) {
3990
3991
  this.config = config2;
3991
3992
  }
3993
+ /**
3994
+ * Dynamically load the ODBC module with lazy initialization and caching
3995
+ * @throws Error with helpful message if ODBC package is not installed
3996
+ */
3997
+ static async getOdbc() {
3998
+ if (this.odbcLoadError) {
3999
+ throw this.odbcLoadError;
4000
+ }
4001
+ if (this.odbcModule) {
4002
+ return this.odbcModule;
4003
+ }
4004
+ try {
4005
+ const odbcImport = await import("odbc");
4006
+ const odbc = odbcImport.default || odbcImport;
4007
+ this.odbcModule = odbc;
4008
+ return this.odbcModule;
4009
+ } catch (error) {
4010
+ const errorMessage = error instanceof Error ? error.message : String(error);
4011
+ this.odbcLoadError = new Error(
4012
+ `ODBC package is required for PSQL service but is not installed or failed to load.
4013
+ Install it with: npm install odbc
4014
+ Also install OS-level dependencies, e.g. on Alpine Linux:
4015
+ apk add --no-cache unixodbc unixodbc-dev python3 make g++
4016
+ For other Linux distributions, install unixodbc and unixodbc-dev packages.
4017
+ Original error: ${errorMessage}`
4018
+ );
4019
+ throw this.odbcLoadError;
4020
+ }
4021
+ }
3992
4022
  // REMOVED: dispose() method - not needed anymore
3993
4023
  // REMOVED: connection property - not needed anymore
3994
4024
  // REMOVED: openConnection() method - not needed anymore
@@ -4018,6 +4048,7 @@ class PsqlService {
4018
4048
  * @returns The entities fetched from the database, along with paging information
4019
4049
  */
4020
4050
  async executePreparedStatement(query, params = {}, paging) {
4051
+ const odbc = await PsqlService.getOdbc();
4021
4052
  let connection = null;
4022
4053
  try {
4023
4054
  const connStr = this.buildConnectionString();
@@ -4046,6 +4077,9 @@ class PsqlService {
4046
4077
  }
4047
4078
  };
4048
4079
  } catch (error) {
4080
+ if (error instanceof Error && error.message.includes("ODBC package is required")) {
4081
+ throw error;
4082
+ }
4049
4083
  const errorInfo = error;
4050
4084
  logger.error("Error fetching data from PSQL", {
4051
4085
  error: errorInfo.message,