@machinemetrics/mm-erp-sdk 0.1.6-beta.1 → 0.1.7-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 (25) hide show
  1. package/dist/{config-WKwu1mMo.js → config-qat9zgOl.js} +2 -2
  2. package/dist/{config-WKwu1mMo.js.map → config-qat9zgOl.js.map} +1 -1
  3. package/dist/{connector-factory-DHmMYsRs.js → connector-factory-C2czCs9v.js} +2 -2
  4. package/dist/{connector-factory-DHmMYsRs.js.map → connector-factory-C2czCs9v.js.map} +1 -1
  5. package/dist/{hashed-cache-manager-CtDhFqj6.js → hashed-cache-manager-CzyFSt2B.js} +4 -4
  6. package/dist/{hashed-cache-manager-CtDhFqj6.js.map → hashed-cache-manager-CzyFSt2B.js.map} +1 -1
  7. package/dist/{index-aci_wdcn.js → index-B9wo8pld.js} +2 -2
  8. package/dist/{index-aci_wdcn.js.map → index-B9wo8pld.js.map} +1 -1
  9. package/dist/{logger-hqtl8hFM.js → logger-Db8CkwR6.js} +924 -966
  10. package/dist/logger-Db8CkwR6.js.map +1 -0
  11. package/dist/mm-erp-sdk.js +45 -73
  12. package/dist/mm-erp-sdk.js.map +1 -1
  13. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +4 -4
  14. package/dist/services/data-sync-service/jobs/from-erp.js +4 -4
  15. package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js +3 -3
  16. package/dist/services/data-sync-service/jobs/run-migrations.js +1 -1
  17. package/dist/services/data-sync-service/jobs/to-erp.d.ts.map +1 -1
  18. package/dist/services/data-sync-service/jobs/to-erp.js +3 -3
  19. package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
  20. package/dist/services/psql-erp-service/psql-service.d.ts +1 -14
  21. package/dist/services/psql-erp-service/psql-service.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/src/services/data-sync-service/jobs/to-erp.ts +2 -1
  24. package/src/services/psql-erp-service/psql-service.ts +53 -90
  25. package/dist/logger-hqtl8hFM.js.map +0 -1
@@ -1,14 +1,14 @@
1
- import { C as CoreConfiguration, H as HashedCacheManager } from "./hashed-cache-manager-CtDhFqj6.js";
2
- import { E, g, a } from "./hashed-cache-manager-CtDhFqj6.js";
3
- import { l as logger } from "./logger-hqtl8hFM.js";
4
- import { g as getCachedMMToken, s as setCachedMMToken, a as setTimezoneOffsetInCache, b as getCachedTimezoneOffset, S as SQLiteCoordinator } from "./index-aci_wdcn.js";
5
- import { c, d } from "./index-aci_wdcn.js";
1
+ import { C as CoreConfiguration, H as HashedCacheManager } from "./hashed-cache-manager-CzyFSt2B.js";
2
+ import { E, g, a } from "./hashed-cache-manager-CzyFSt2B.js";
3
+ import { l as logger } from "./logger-Db8CkwR6.js";
4
+ import { g as getCachedMMToken, s as setCachedMMToken, a as setTimezoneOffsetInCache, b as getCachedTimezoneOffset, S as SQLiteCoordinator } from "./index-B9wo8pld.js";
5
+ import { c, d } from "./index-B9wo8pld.js";
6
6
  import axios, { AxiosError } from "axios";
7
7
  import knex from "knex";
8
8
  import { c as config } from "./knexfile-1qKKIORB.js";
9
9
  import fs from "fs";
10
10
  import path from "path";
11
- import "./connector-factory-DHmMYsRs.js";
11
+ import "./connector-factory-C2czCs9v.js";
12
12
  import Bree from "bree";
13
13
  import Graceful from "@ladjs/graceful";
14
14
  import { fileURLToPath } from "url";
@@ -3968,14 +3968,14 @@ class SqlServerHelper {
3968
3968
  }
3969
3969
  }
3970
3970
  class PsqlService {
3971
- connection = null;
3972
3971
  config;
3973
3972
  constructor(config2) {
3974
3973
  this.config = config2;
3975
3974
  }
3976
- async dispose() {
3977
- await this.closeConnection();
3978
- }
3975
+ // REMOVED: dispose() method - not needed anymore
3976
+ // REMOVED: connection property - not needed anymore
3977
+ // REMOVED: openConnection() method - not needed anymore
3978
+ // REMOVED: closeConnection() method - not needed anymore
3979
3979
  /**
3980
3980
  * Build PSQL ODBC connection string
3981
3981
  * CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
@@ -3993,7 +3993,7 @@ class PsqlService {
3993
3993
  }
3994
3994
  /**
3995
3995
  * Execute a query and return the results
3996
- * Interface matches SqlServerService for consistency
3996
+ * Creates a fresh connection for each query to avoid handle corruption
3997
3997
  *
3998
3998
  * @param query The SQL query to execute
3999
3999
  * @param params Query parameters (currently unused for PSQL read operations)
@@ -4001,73 +4001,58 @@ class PsqlService {
4001
4001
  * @returns The entities fetched from the database, along with paging information
4002
4002
  */
4003
4003
  async executePreparedStatement(query, params = {}, paging) {
4004
- const connection = await this.openConnection();
4005
- let records;
4004
+ let connection = null;
4006
4005
  try {
4006
+ const connStr = this.buildConnectionString();
4007
+ logger.debug("Creating fresh PSQL connection for query");
4008
+ connection = await odbc.connect(connStr);
4007
4009
  if (Object.keys(params).length > 0) {
4008
4010
  logger.warn(
4009
4011
  "PsqlService: Query parameters provided but parameter binding not yet implemented. Using direct query execution. This is acceptable for Phase 1 read operations."
4010
4012
  );
4011
4013
  }
4012
- records = await connection.query(query);
4014
+ const records = await connection.query(query);
4015
+ const allRecords = PsqlService.recordsetToRecords(records);
4016
+ const rowsFetched = allRecords.length;
4017
+ const pagedData = paging?.offset !== void 0 || paging?.limit !== void 0 ? allRecords.slice(
4018
+ paging.offset || 0,
4019
+ (paging.offset || 0) + (paging.limit || allRecords.length)
4020
+ ) : allRecords;
4021
+ return {
4022
+ data: pagedData,
4023
+ paging: {
4024
+ count: rowsFetched,
4025
+ limit: paging?.limit || 0,
4026
+ offset: paging?.offset || 0,
4027
+ nextPage: paging?.limit && (paging.offset || 0) + paging.limit < rowsFetched ? String((paging.offset || 0) + paging.limit) : void 0,
4028
+ previousPage: paging?.offset ? String(Math.max(0, (paging.offset || 0) - (paging.limit || 10))) : void 0
4029
+ }
4030
+ };
4013
4031
  } catch (error) {
4014
4032
  const errorInfo = error;
4015
4033
  logger.error("Error fetching data from PSQL", {
4016
4034
  error: errorInfo.message,
4017
- odbcErrors: errorInfo.odbcErrors
4035
+ odbcErrors: errorInfo.odbcErrors,
4036
+ query: query.substring(0, 200)
4037
+ // Log first 200 chars of query
4018
4038
  });
4019
4039
  throw this.handleOdbcError(errorInfo);
4020
- }
4021
- const allRecords = PsqlService.recordsetToRecords(records);
4022
- const rowsFetched = allRecords.length;
4023
- const pagedData = paging?.offset !== void 0 || paging?.limit !== void 0 ? allRecords.slice(
4024
- paging.offset || 0,
4025
- (paging.offset || 0) + (paging.limit || allRecords.length)
4026
- ) : allRecords;
4027
- return {
4028
- data: pagedData,
4029
- paging: {
4030
- count: rowsFetched,
4031
- limit: paging?.limit || 0,
4032
- offset: paging?.offset || 0,
4033
- nextPage: paging?.limit && (paging.offset || 0) + paging.limit < rowsFetched ? String((paging.offset || 0) + paging.limit) : void 0,
4034
- previousPage: paging?.offset ? String(Math.max(0, (paging.offset || 0) - (paging.limit || 10))) : void 0
4040
+ } finally {
4041
+ if (connection) {
4042
+ try {
4043
+ await connection.close();
4044
+ logger.debug("PSQL connection closed successfully");
4045
+ } catch (err) {
4046
+ logger.warn("Error closing PSQL connection (non-fatal)", {
4047
+ error: err
4048
+ });
4049
+ }
4035
4050
  }
4036
- };
4037
- }
4038
- /**
4039
- * Opens a connection to PSQL database
4040
- * Caches the connection so that it can be reused.
4041
- * On failure to connect, throws
4042
- */
4043
- async openConnection() {
4044
- if (this.connection) {
4045
- logger.debug("Reusing existing PSQL connection");
4046
- return this.connection;
4047
- }
4048
- try {
4049
- const connStr = this.buildConnectionString();
4050
- logger.info("Opening new PSQL connection");
4051
- logger.debug(
4052
- "Connection string (password hidden):",
4053
- connStr.replace(/PWD=[^;]+/, "PWD=***")
4054
- );
4055
- this.connection = await odbc.connect(connStr);
4056
- logger.info("Successfully connected to PSQL database");
4057
- return this.connection;
4058
- } catch (error) {
4059
- logger.error("PsqlService>>openConnection>> Connection failed", {
4060
- error
4061
- });
4062
- throw this.handleOdbcError(error);
4063
4051
  }
4064
4052
  }
4065
4053
  /**
4066
4054
  * Transform ODBC result set to array of Record<string, string> instances.
4067
4055
  * IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
4068
- *
4069
- * @param recordset Result set from ODBC query
4070
- * @returns array of Record<string, string> instances
4071
4056
  */
4072
4057
  static recordsetToRecords(recordset) {
4073
4058
  if (!Array.isArray(recordset)) {
@@ -4109,19 +4094,6 @@ class PsqlService {
4109
4094
  return new Error(`PSQL error (${errorCode || "unknown"}): ${message}`);
4110
4095
  }
4111
4096
  }
4112
- async closeConnection() {
4113
- if (this.connection) {
4114
- logger.info("Closing PSQL connection");
4115
- try {
4116
- await this.connection.close();
4117
- } catch (error) {
4118
- logger.error("PsqlService::closeConnection: Error closing connection", {
4119
- error
4120
- });
4121
- }
4122
- this.connection = null;
4123
- }
4124
- }
4125
4097
  }
4126
4098
  class PsqlLaborTicketOperations {
4127
4099
  constructor(service) {