@machinemetrics/mm-erp-sdk 0.1.8-beta.0 → 0.1.8-beta.10

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 (52) hide show
  1. package/dist/{config-CV-KosWV.js → config-cB7h4yvc.js} +2 -2
  2. package/dist/{config-CV-KosWV.js.map → config-cB7h4yvc.js.map} +1 -1
  3. package/dist/{connector-factory-D8v6aQIt.js → connector-factory-CKm74_WZ.js} +2 -2
  4. package/dist/{connector-factory-D8v6aQIt.js.map → connector-factory-CKm74_WZ.js.map} +1 -1
  5. package/dist/{hashed-cache-manager-B6hTDLxU.js → hashed-cache-manager-B1hPBNnF.js} +4 -4
  6. package/dist/{hashed-cache-manager-B6hTDLxU.js.map → hashed-cache-manager-B1hPBNnF.js.map} +1 -1
  7. package/dist/{index-Bg76oouR.js → index-DCgheVjV.js} +2 -2
  8. package/dist/{index-Bg76oouR.js.map → index-DCgheVjV.js.map} +1 -1
  9. package/dist/index.d.ts +5 -3
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/{logger-SqdNut1H.js → logger-CBDNtsMq.js} +969 -1024
  12. package/dist/logger-CBDNtsMq.js.map +1 -0
  13. package/dist/mm-erp-sdk.js +241 -7
  14. package/dist/mm-erp-sdk.js.map +1 -1
  15. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +4 -4
  16. package/dist/services/data-sync-service/jobs/from-erp.js +4 -4
  17. package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js +3 -3
  18. package/dist/services/data-sync-service/jobs/run-migrations.js +1 -1
  19. package/dist/services/data-sync-service/jobs/to-erp.d.ts.map +1 -1
  20. package/dist/services/data-sync-service/jobs/to-erp.js +3 -3
  21. package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
  22. package/dist/services/psql-erp-service/configuration.d.ts +10 -0
  23. package/dist/services/psql-erp-service/configuration.d.ts.map +1 -0
  24. package/dist/services/psql-erp-service/index.d.ts +14 -0
  25. package/dist/services/psql-erp-service/index.d.ts.map +1 -0
  26. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts +12 -0
  27. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts.map +1 -0
  28. package/dist/services/psql-erp-service/psql-helpers.d.ts +32 -0
  29. package/dist/services/psql-erp-service/psql-helpers.d.ts.map +1 -0
  30. package/dist/services/psql-erp-service/psql-service.d.ts +43 -0
  31. package/dist/services/psql-erp-service/psql-service.d.ts.map +1 -0
  32. package/dist/services/reporting-service/logger.d.ts.map +1 -1
  33. package/dist/types/erp-types.d.ts +2 -1
  34. package/dist/types/erp-types.d.ts.map +1 -1
  35. package/dist/utils/index.d.ts +1 -1
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/timezone.d.ts +7 -0
  38. package/dist/utils/timezone.d.ts.map +1 -1
  39. package/package.json +4 -1
  40. package/src/index.ts +26 -5
  41. package/src/services/data-sync-service/jobs/to-erp.ts +2 -1
  42. package/src/services/psql-erp-service/configuration.ts +9 -0
  43. package/src/services/psql-erp-service/index.ts +22 -0
  44. package/src/services/psql-erp-service/internal/types/psql-types.ts +13 -0
  45. package/src/services/psql-erp-service/psql-helpers.ts +90 -0
  46. package/src/services/psql-erp-service/psql-service.ts +240 -0
  47. package/src/services/reporting-service/logger.ts +57 -70
  48. package/src/types/erp-types.ts +1 -0
  49. package/src/utils/index.ts +1 -1
  50. package/src/utils/mm-labor-ticket-helpers.ts +2 -2
  51. package/src/utils/timezone.ts +28 -0
  52. package/dist/logger-SqdNut1H.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { H as HashedCacheManager } from "../../../hashed-cache-manager-B6hTDLxU.js";
3
- import { S as SQLiteCoordinator } from "../../../index-Bg76oouR.js";
4
- import { l as logger } from "../../../logger-SqdNut1H.js";
1
+ import "../../../config-cB7h4yvc.js";
2
+ import { H as HashedCacheManager } from "../../../hashed-cache-manager-B1hPBNnF.js";
3
+ import { S as SQLiteCoordinator } from "../../../index-DCgheVjV.js";
4
+ import { l as logger } from "../../../logger-CBDNtsMq.js";
5
5
  logger.level = process.env.LOG_LEVEL || "info";
6
6
  const main = async () => {
7
7
  const cacheManager = new HashedCacheManager();
@@ -1,7 +1,7 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
3
- import { S as SQLiteCoordinator } from "../../../index-Bg76oouR.js";
4
- import { c as createConnectorFromPath } from "../../../connector-factory-D8v6aQIt.js";
1
+ import "../../../config-cB7h4yvc.js";
2
+ import { l as logger } from "../../../logger-CBDNtsMq.js";
3
+ import { S as SQLiteCoordinator } from "../../../index-DCgheVjV.js";
4
+ import { c as createConnectorFromPath } from "../../../connector-factory-CKm74_WZ.js";
5
5
  logger.level = process.env.LOG_LEVEL || "info";
6
6
  const main = async () => {
7
7
  try {
@@ -1,6 +1,6 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
3
- import { c as createConnectorFromPath } from "../../../connector-factory-D8v6aQIt.js";
1
+ import "../../../config-cB7h4yvc.js";
2
+ import { l as logger } from "../../../logger-CBDNtsMq.js";
3
+ import { c as createConnectorFromPath } from "../../../connector-factory-CKm74_WZ.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
5
  const main = async () => {
6
6
  try {
@@ -1,5 +1,5 @@
1
1
  import knex from "knex";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
2
+ import { l as logger } from "../../../logger-CBDNtsMq.js";
3
3
  import { c as config } from "../../../knexfile-1qKKIORB.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
5
  const db = knex(config.local);
@@ -1 +1 @@
1
- {"version":3,"file":"to-erp.d.ts","sourceRoot":"","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAQvB,QAAA,MAAM,IAAI,qBAoCT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"to-erp.d.ts","sourceRoot":"","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AASvB,QAAA,MAAM,IAAI,qBAoCT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
@@ -1,6 +1,6 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
3
- import { c as createConnectorFromPath } from "../../../connector-factory-D8v6aQIt.js";
1
+ import "../../../config-cB7h4yvc.js";
2
+ import { l as logger } from "../../../logger-CBDNtsMq.js";
3
+ import { c as createConnectorFromPath } from "../../../connector-factory-CKm74_WZ.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
5
  const main = async () => {
6
6
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"to-erp.js","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"sourcesContent":["import \"dotenv/config\";\n\nimport logger from \"../../reporting-service/logger\";\nimport { createConnectorFromPath } from \"../../../utils/connector-factory\";\n\n// Configure the logger with the correct log level\nlogger.level = process.env.LOG_LEVEL || \"info\";\n\nconst main = async () => {\n try {\n logger.info('Worker for job \"to-erp\" online');\n logger.info(\"==========Starting to-erp job cycle==========\");\n\n // Get the connector path from the environment variable\n const connectorPath = process.env.CONNECTOR_PATH;\n\n if (!connectorPath) {\n throw new Error(\"Connector path not provided in environment variables\");\n }\n\n // Create a new connector instance for this job\n const connector = await createConnectorFromPath(connectorPath);\n\n await connector.syncToERP();\n await connector.syncToERPCompleted();\n\n logger.info(\"==========Completed to-erp job cycle==========\");\n } catch (error) {\n const errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n name: error instanceof Error ? error.name : undefined,\n ...(error && typeof error === \"object\" ? error : {}), // Include all enumerable properties if it's an object\n };\n logger.error('Worker for job \"to-erp\" had an error', {\n error: errorDetails,\n connectorPath: process.env.CONNECTOR_PATH,\n });\n\n // Also log to console for immediate visibility\n console.error(\"to-erp job error:\", error);\n\n throw error; // Rethrow so Bree can handle it properly\n }\n};\n\n// Cross-platform module detection fix for Bree compatibility\n// Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes\n// Linux/Mac: both use forward slashes, so this normalization is safe\nconst normalizedArgv1 = process.argv[1].replace(/\\\\/g, '/');\nconst fileUrl = normalizedArgv1.startsWith('/') ? \n `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path\n `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path\nconst isMainModule = import.meta.url === fileUrl;\n\nif (isMainModule) {\n // This is called when Bree runs this file as a worker\n try {\n await main();\n } catch {\n process.exitCode = 1; // prefer exitCode so stdout/stderr can flush\n }\n}\n\nexport default main;\n"],"names":[],"mappings":";;;AAMA,OAAO,QAAQ,QAAQ,IAAI,aAAa;AAExC,MAAM,OAAO,YAAY;AACvB,MAAI;AACF,WAAO,KAAK,gCAAgC;AAC5C,WAAO,KAAK,+CAA+C;AAG3D,UAAM,gBAAgB,QAAQ,IAAI;AAElC,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAGA,UAAM,YAAY,MAAM,wBAAwB,aAAa;AAE7D,UAAM,UAAU,UAAA;AAChB,UAAM,UAAU,mBAAA;AAEhB,WAAO,KAAK,gDAAgD;AAAA,EAC9D,SAAS,OAAO;AACd,UAAM,eAAe;AAAA,MACnB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,MAC9C,MAAM,iBAAiB,QAAQ,MAAM,OAAO;AAAA,MAC5C,GAAI,SAAS,OAAO,UAAU,WAAW,QAAQ,CAAA;AAAA;AAAA,IAAC;AAEpD,WAAO,MAAM,wCAAwC;AAAA,MACnD,OAAO;AAAA,MACP,eAAe,QAAQ,IAAI;AAAA,IAAA,CAC5B;AAGD,YAAQ,MAAM,qBAAqB,KAAK;AAExC,UAAM;AAAA,EACR;AACF;AAKA,MAAM,kBAAkB,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC1D,MAAM,UAAU,gBAAgB,WAAW,GAAG,IAC5C,UAAU,eAAe;AAAA;AAAA,EACzB,WAAW,eAAe;AAAA;AAC5B,MAAM,eAAe,YAAY,QAAQ;AAEzC,IAAI,cAAc;AAEhB,MAAI;AACF,UAAM,KAAA;AAAA,EACR,QAAQ;AACN,YAAQ,WAAW;AAAA,EACrB;AACF;"}
1
+ {"version":3,"file":"to-erp.js","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"sourcesContent":["import \"dotenv/config\";\n\nimport logger from \"../../../services/reporting-service/logger\";\nimport { SQLiteCoordinator } from \"../../sqlite-service\";\nimport { createConnectorFromPath } from \"../../../utils/connector-factory\";\n\n// Configure the logger with the correct log level\nlogger.level = process.env.LOG_LEVEL || \"info\";\n\nconst main = async () => {\n try {\n logger.info('Worker for job \"to-erp\" online');\n logger.info(\"==========Starting to-erp job cycle==========\");\n\n // Get the connector path from the environment variable\n const connectorPath = process.env.CONNECTOR_PATH;\n\n if (!connectorPath) {\n throw new Error(\"Connector path not provided in environment variables\");\n }\n\n // Create a new connector instance for this job\n const connector = await createConnectorFromPath(connectorPath);\n\n await connector.syncToERP();\n await connector.syncToERPCompleted();\n\n logger.info(\"==========Completed to-erp job cycle==========\");\n } catch (error) {\n const errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n name: error instanceof Error ? error.name : undefined,\n ...(error && typeof error === \"object\" ? error : {}), // Include all enumerable properties if it's an object\n };\n logger.error('Worker for job \"to-erp\" had an error', {\n error: errorDetails,\n connectorPath: process.env.CONNECTOR_PATH,\n });\n\n // Also log to console for immediate visibility\n console.error(\"to-erp job error:\", error);\n\n throw error; // Rethrow so Bree can handle it properly\n }\n};\n\n// Cross-platform module detection fix for Bree compatibility\n// Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes\n// Linux/Mac: both use forward slashes, so this normalization is safe\nconst normalizedArgv1 = process.argv[1].replace(/\\\\/g, '/');\nconst fileUrl = normalizedArgv1.startsWith('/') ? \n `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path\n `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path\nconst isMainModule = import.meta.url === fileUrl;\n\nif (isMainModule) {\n // This is called when Bree runs this file as a worker\n try {\n await main();\n } catch {\n process.exitCode = 1; // prefer exitCode so stdout/stderr can flush\n }\n}\n\nexport default main;\n"],"names":[],"mappings":";;;AAOA,OAAO,QAAQ,QAAQ,IAAI,aAAa;AAExC,MAAM,OAAO,YAAY;AACvB,MAAI;AACF,WAAO,KAAK,gCAAgC;AAC5C,WAAO,KAAK,+CAA+C;AAG3D,UAAM,gBAAgB,QAAQ,IAAI;AAElC,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAGA,UAAM,YAAY,MAAM,wBAAwB,aAAa;AAE7D,UAAM,UAAU,UAAA;AAChB,UAAM,UAAU,mBAAA;AAEhB,WAAO,KAAK,gDAAgD;AAAA,EAC9D,SAAS,OAAO;AACd,UAAM,eAAe;AAAA,MACnB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,MAC9C,MAAM,iBAAiB,QAAQ,MAAM,OAAO;AAAA,MAC5C,GAAI,SAAS,OAAO,UAAU,WAAW,QAAQ,CAAA;AAAA;AAAA,IAAC;AAEpD,WAAO,MAAM,wCAAwC;AAAA,MACnD,OAAO;AAAA,MACP,eAAe,QAAQ,IAAI;AAAA,IAAA,CAC5B;AAGD,YAAQ,MAAM,qBAAqB,KAAK;AAExC,UAAM;AAAA,EACR;AACF;AAKA,MAAM,kBAAkB,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC1D,MAAM,UAAU,gBAAgB,WAAW,GAAG,IAC5C,UAAU,eAAe;AAAA;AAAA,EACzB,WAAW,eAAe;AAAA;AAC5B,MAAM,eAAe,YAAY,QAAQ;AAEzC,IAAI,cAAc;AAEhB,MAAI;AACF,UAAM,KAAA;AAAA,EACR,QAAQ;AACN,YAAQ,WAAW;AAAA,EACrB;AACF;"}
@@ -0,0 +1,10 @@
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
+ }
10
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/services/psql-erp-service/configuration.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,14 @@
1
+ import { PsqlService } from "./psql-service";
2
+ /**
3
+ * A class to manage interactions with PSQL (Pervasive) databases via ODBC
4
+ */
5
+ export { PsqlService };
6
+ /**
7
+ * Configuration interface for PSQL connections
8
+ */
9
+ export type { PsqlConfiguration } from "./configuration";
10
+ /**
11
+ * Helper functions for PSQL data formatting
12
+ */
13
+ export { formatPsqlDate, formatPsqlTime, combinePsqlDateTime, isPsqlDateEmpty, cleanPsqlCharField, } from "./psql-helpers";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/psql-erp-service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;GAEG;AACH,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;GAEG;AACH,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * PSQL-specific type definitions
3
+ */
4
+ export interface OdbcError {
5
+ state: string;
6
+ message: string;
7
+ code?: number;
8
+ }
9
+ export interface OdbcErrorResponse extends Error {
10
+ odbcErrors?: OdbcError[];
11
+ }
12
+ //# sourceMappingURL=psql-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psql-types.d.ts","sourceRoot":"","sources":["../../../../../src/services/psql-erp-service/internal/types/psql-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAkB,SAAQ,KAAK;IAC9C,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Helper functions for PSQL/Pervasive database operations
3
+ */
4
+ /**
5
+ * Formats a date from PSQL YYMMDD format to ISO date string
6
+ * @param psqlDate Date in YYMMDD format (e.g., "250105" for Jan 5, 2025)
7
+ * @returns ISO date string (e.g., "2025-01-05") or null if invalid
8
+ */
9
+ export declare function formatPsqlDate(psqlDate: string): string | null;
10
+ /**
11
+ * Formats a time from PSQL HHMM format to HH:MM:SS
12
+ * @param psqlTime Time in HHMM format (e.g., "1430" for 2:30 PM)
13
+ * @returns Time string in HH:MM:SS format or null if invalid
14
+ */
15
+ export declare function formatPsqlTime(psqlTime: string): string | null;
16
+ /**
17
+ * Combines PSQL date and time into ISO datetime string
18
+ * @param psqlDate Date in YYMMDD format
19
+ * @param psqlTime Time in HHMM format
20
+ * @returns ISO datetime string or null if invalid
21
+ */
22
+ export declare function combinePsqlDateTime(psqlDate: string, psqlTime: string): string | null;
23
+ /**
24
+ * Helper to check if a PSQL date is "empty" (000000 or blank)
25
+ */
26
+ export declare function isPsqlDateEmpty(psqlDate: string): boolean;
27
+ /**
28
+ * Clean and trim PSQL CHAR field (removes trailing spaces)
29
+ * PSQL CHAR fields are fixed-width and padded with spaces
30
+ */
31
+ export declare function cleanPsqlCharField(value: string | null | undefined): string;
32
+ //# sourceMappingURL=psql-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psql-helpers.d.ts","sourceRoot":"","sources":["../../../src/services/psql-erp-service/psql-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuB9D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY9D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CASf;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAK3E"}
@@ -0,0 +1,43 @@
1
+ import { PsqlConfiguration } from "./configuration";
2
+ import { ERPResponse } from "../../types/erp-types";
3
+ type PagingParams = {
4
+ limit?: number;
5
+ offset?: number;
6
+ };
7
+ export declare class PsqlService {
8
+ private config;
9
+ private static odbcModule;
10
+ private static odbcLoadError;
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;
17
+ /**
18
+ * Build PSQL ODBC connection string
19
+ * CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
20
+ */
21
+ private buildConnectionString;
22
+ /**
23
+ * Execute a query and return the results
24
+ * Creates a fresh connection for each query to avoid handle corruption
25
+ *
26
+ * @param query The SQL query to execute
27
+ * @param params Query parameters (currently unused for PSQL read operations)
28
+ * @param paging Optional paging parameters
29
+ * @returns The entities fetched from the database, along with paging information
30
+ */
31
+ executePreparedStatement(query: string, params?: Record<string, string>, paging?: PagingParams): Promise<ERPResponse | undefined>;
32
+ /**
33
+ * Transform ODBC result set to array of Record<string, string> instances.
34
+ * IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
35
+ */
36
+ static recordsetToRecords(recordset: any[]): Record<string, string>[];
37
+ /**
38
+ * Handle ODBC errors and provide meaningful messages
39
+ */
40
+ private handleOdbcError;
41
+ }
42
+ export {};
43
+ //# sourceMappingURL=psql-service.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/services/reporting-service/logger.ts"],"names":[],"mappings":"AA+DA,QAAA,MAAM,MAAM,0BAaV,CAAC;AAGH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,SA2GhE,CAAC;AAKF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/services/reporting-service/logger.ts"],"names":[],"mappings":"AA+DA,QAAA,MAAM,MAAM,0BAaV,CAAC;AA0DH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,SAuChE,CAAC;AAKF,eAAe,MAAM,CAAC"}
@@ -5,7 +5,8 @@ export declare enum ERPType {
5
5
  PROFITKEY = "PROFITKEY",
6
6
  PROSHOP = "PROSHOP",
7
7
  SYTELINE = "SYTELINE",
8
- TEMPLATE = "TEMPLATE"
8
+ TEMPLATE = "TEMPLATE",
9
+ GLOBALSHOP = "GLOBALSHOP"
9
10
  }
10
11
  export declare enum ERPObjType {
11
12
  RESOURCES = 0,
@@ -1 +1 @@
1
- {"version":3,"file":"erp-types.d.ts","sourceRoot":"","sources":["../../src/types/erp-types.ts"],"names":[],"mappings":"AACA,oBAAY,OAAO;IACjB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,QAAQ,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IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -11,7 +11,7 @@ export { addNewFieldFromExternalSource, addNewFieldFromLookupField, } from "./da
11
11
  * Timezone and time-related utilities
12
12
  */
13
13
  export { getTimezoneOffsetAndPersist } from "./time-utils";
14
- export { formatDateWithTZOffset, convertToLocalTime } from "./timezone";
14
+ export { formatDateWithTZOffset, convertToLocalTime, toISOWithOffset } from "./timezone";
15
15
  export { applyTimezoneOffsetsToFields } from "./time-utils";
16
16
  export * from "./time-utils";
17
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,cAAc,cAAc,CAAC;AAE7B;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAC5F,YAAY,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAChG,OAAO,EA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,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEjF;;GAEG;AACH,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACzH,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AACH,cAAc,2BAA2B,CAAC;AAE1C;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE;;GAEG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -18,4 +18,11 @@ export declare const convertToLocalTime: (zuluTime: string | Date | null | undef
18
18
  * @returns The formatted date string in format: YYYY-MM-DDTHH:mm:ss+/-HH:MM
19
19
  */
20
20
  export declare const formatDateWithTZOffset: (date: string | null | undefined, timezoneOffset: number) => string | undefined;
21
+ /**
22
+ * Formats a Date object as an ISO string with the specified timezone offset
23
+ * @param date The Date object to format (should be a Date that has been shifted by convertToLocalTime)
24
+ * @param timezoneOffset The timezone offset in hours
25
+ * @returns ISO string with offset in format: YYYY-MM-DDTHH:mm:ss.SSS±HH:MM
26
+ */
27
+ export declare const toISOWithOffset: (date: Date, timezoneOffset: number) => string;
21
28
  //# sourceMappingURL=timezone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../src/utils/timezone.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,MAAM,CA6CxD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,EAC1C,gBAAgB,MAAM,KACrB,IAAI,GAAG,SAIT,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,gBAAgB,MAAM,KACrB,MAAM,GAAG,SAgBX,CAAC"}
1
+ {"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../src/utils/timezone.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,MAAM,CA6CxD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,EAC1C,gBAAgB,MAAM,KACrB,IAAI,GAAG,SAIT,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,gBAAgB,MAAM,KACrB,MAAM,GAAG,SAgBX,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,IAAI,EAAE,gBAAgB,MAAM,KAAG,MAoBpE,CAAC"}
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.0",
4
+ "version": "0.1.8-beta.10",
5
5
  "license": "MIT",
6
6
  "author": "machinemetrics",
7
7
  "main": "dist/mm-erp-sdk.js",
@@ -33,6 +33,9 @@
33
33
  "xxhashjs": "^0.2.2",
34
34
  "zod": "^3.24.1"
35
35
  },
36
+ "optionalDependencies": {
37
+ "odbc": "^2.4.8"
38
+ },
36
39
  "devDependencies": {
37
40
  "@types/json-stable-stringify": "^1.1.0",
38
41
  "@types/lodash": "^4.17.10",
package/src/index.ts CHANGED
@@ -17,13 +17,13 @@ export type { ERPApiConfig } from "./services/erp-api-services/types";
17
17
  // MM API client and types
18
18
  export { MMApiClient } from "./services/mm-api-service";
19
19
  export { MMReceiveLaborTicket } from "./services/mm-api-service";
20
- export type {
20
+ export type {
21
21
  MMReceiveLaborTicketReason,
22
22
  MMReceiveLaborTicketWorkOrderOperation,
23
23
  IToRESTApiObject,
24
24
  } from "./services/mm-api-service";
25
25
 
26
- export {
26
+ export {
27
27
  MMSendPerson,
28
28
  MMSendResource,
29
29
  MMSendPart,
@@ -57,7 +57,11 @@ export { getInitialLoadComplete, setInitialLoadComplete } from "./utils";
57
57
  // HTTP client factory and types for custom API integrations
58
58
  export { HTTPClientFactory } from "./utils/http-client";
59
59
  export { HTTPError } from "./utils/http-client";
60
- export type { HTTPResponse, HTTPClient, HTTPRequestConfig } from "./utils/http-client";
60
+ export type {
61
+ HTTPResponse,
62
+ HTTPClient,
63
+ HTTPRequestConfig,
64
+ } from "./utils/http-client";
61
65
 
62
66
  // Application initialization utilities
63
67
  export { ApplicationInitializer } from "./utils/application-initializer";
@@ -77,7 +81,7 @@ export type { WriteEntitiesToMMResult } from "./utils";
77
81
  export { MMBatchValidationError } from "./utils";
78
82
 
79
83
  // API services
80
- export type { APIResponse } from './services/erp-api-services/types';
84
+ export type { APIResponse } from "./services/erp-api-services/types";
81
85
  export { RestAPIService } from "./services/erp-api-services/rest/rest-api-service";
82
86
  export { ErrorHandler, GraphQLError } from "./services/erp-api-services/errors";
83
87
  export type {
@@ -105,6 +109,17 @@ export {
105
109
  } from "./services/sql-server-erp-service";
106
110
  export type { SQLInput } from "./services/sql-server-erp-service";
107
111
 
112
+ // PSQL (Pervasive) services
113
+ export {
114
+ PsqlService,
115
+ formatPsqlDate,
116
+ formatPsqlTime,
117
+ combinePsqlDateTime,
118
+ isPsqlDateEmpty,
119
+ cleanPsqlCharField,
120
+ } from "./services/psql-erp-service";
121
+ export type { PsqlConfiguration } from "./services/psql-erp-service";
122
+
108
123
  // Record tracking services
109
124
  export { RecordTrackingManager } from "./services/caching-service/record-tracking-manager";
110
125
  export type { RecordTrackingObject } from "./services/caching-service/record-tracking-manager";
@@ -113,4 +128,10 @@ export type { RecordTrackingObject } from "./services/caching-service/record-tra
113
128
  export { default as knexDatabaseConfig } from "./knexfile";
114
129
 
115
130
  // MM Connector Logging
116
- export { MMConnectorLogger, FileLogDeduper, LogEntry, type LogLevelString, type LogResponse } from './utils';
131
+ export {
132
+ MMConnectorLogger,
133
+ FileLogDeduper,
134
+ LogEntry,
135
+ type LogLevelString,
136
+ type LogResponse,
137
+ } from "./utils";
@@ -1,6 +1,7 @@
1
1
  import "dotenv/config";
2
2
 
3
- import logger from "../../reporting-service/logger";
3
+ import logger from "../../../services/reporting-service/logger";
4
+ import { SQLiteCoordinator } from "../../sqlite-service";
4
5
  import { createConnectorFromPath } from "../../../utils/connector-factory";
5
6
 
6
7
  // Configure the logger with the correct log level
@@ -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,22 @@
1
+ import { PsqlService } from "./psql-service";
2
+
3
+ /**
4
+ * A class to manage interactions with PSQL (Pervasive) databases via ODBC
5
+ */
6
+ export { PsqlService };
7
+
8
+ /**
9
+ * Configuration interface for PSQL connections
10
+ */
11
+ export type { PsqlConfiguration } from "./configuration";
12
+
13
+ /**
14
+ * Helper functions for PSQL data formatting
15
+ */
16
+ export {
17
+ formatPsqlDate,
18
+ formatPsqlTime,
19
+ combinePsqlDateTime,
20
+ isPsqlDateEmpty,
21
+ cleanPsqlCharField,
22
+ } from "./psql-helpers";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * PSQL-specific type definitions
3
+ */
4
+
5
+ export interface OdbcError {
6
+ state: string;
7
+ message: string;
8
+ code?: number;
9
+ }
10
+
11
+ export interface OdbcErrorResponse extends Error {
12
+ odbcErrors?: OdbcError[];
13
+ }
@@ -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
+ }