@machinemetrics/mm-erp-sdk 0.1.8-beta.4 → 0.1.8-beta.6
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.
- package/dist/{config-qat9zgOl.js → config-152LkbTv.js} +2 -2
- package/dist/{config-qat9zgOl.js.map → config-152LkbTv.js.map} +1 -1
- package/dist/{connector-factory-C2czCs9v.js → connector-factory-wivcyMhC.js} +2 -2
- package/dist/{connector-factory-C2czCs9v.js.map → connector-factory-wivcyMhC.js.map} +1 -1
- package/dist/{hashed-cache-manager-CzyFSt2B.js → hashed-cache-manager-BnviJzB7.js} +4 -4
- package/dist/{hashed-cache-manager-CzyFSt2B.js.map → hashed-cache-manager-BnviJzB7.js.map} +1 -1
- package/dist/{index-B9wo8pld.js → index-DNqHWa8F.js} +2 -2
- package/dist/{index-B9wo8pld.js.map → index-DNqHWa8F.js.map} +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/{logger-Db8CkwR6.js → logger-HAWySEbs.js} +83 -11
- package/dist/{logger-Db8CkwR6.js.map → logger-HAWySEbs.js.map} +1 -1
- package/dist/mm-erp-sdk.js +189 -6
- package/dist/mm-erp-sdk.js.map +1 -1
- package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +4 -4
- package/dist/services/data-sync-service/jobs/from-erp.js +4 -4
- package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js +3 -3
- package/dist/services/data-sync-service/jobs/run-migrations.js +1 -1
- package/dist/services/data-sync-service/jobs/to-erp.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/to-erp.js +3 -3
- package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
- package/dist/services/psql-erp-service/configuration.d.ts +10 -0
- package/dist/services/psql-erp-service/configuration.d.ts.map +1 -0
- package/dist/services/psql-erp-service/index.d.ts +14 -0
- package/dist/services/psql-erp-service/index.d.ts.map +1 -0
- package/dist/services/psql-erp-service/internal/types/psql-types.d.ts +12 -0
- package/dist/services/psql-erp-service/internal/types/psql-types.d.ts.map +1 -0
- package/dist/services/psql-erp-service/psql-helpers.d.ts +32 -0
- package/dist/services/psql-erp-service/psql-helpers.d.ts.map +1 -0
- package/dist/services/psql-erp-service/psql-service.d.ts +36 -0
- package/dist/services/psql-erp-service/psql-service.d.ts.map +1 -0
- package/dist/services/reporting-service/logger.d.ts.map +1 -1
- package/dist/types/erp-types.d.ts +2 -1
- package/dist/types/erp-types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +26 -5
- package/src/services/data-sync-service/jobs/to-erp.ts +2 -1
- package/src/services/psql-erp-service/configuration.ts +9 -0
- package/src/services/psql-erp-service/index.ts +22 -0
- package/src/services/psql-erp-service/internal/types/psql-types.ts +13 -0
- package/src/services/psql-erp-service/psql-helpers.ts +90 -0
- package/src/services/psql-erp-service/psql-service.ts +178 -0
- package/src/services/reporting-service/logger.ts +94 -11
- package/src/types/erp-types.ts +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "../../../config-
|
|
2
|
-
import { H as HashedCacheManager } from "../../../hashed-cache-manager-
|
|
3
|
-
import { S as SQLiteCoordinator } from "../../../index-
|
|
4
|
-
import { l as logger } from "../../../logger-
|
|
1
|
+
import "../../../config-152LkbTv.js";
|
|
2
|
+
import { H as HashedCacheManager } from "../../../hashed-cache-manager-BnviJzB7.js";
|
|
3
|
+
import { S as SQLiteCoordinator } from "../../../index-DNqHWa8F.js";
|
|
4
|
+
import { l as logger } from "../../../logger-HAWySEbs.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-
|
|
2
|
-
import { l as logger } from "../../../logger-
|
|
3
|
-
import { S as SQLiteCoordinator } from "../../../index-
|
|
4
|
-
import { c as createConnectorFromPath } from "../../../connector-factory-
|
|
1
|
+
import "../../../config-152LkbTv.js";
|
|
2
|
+
import { l as logger } from "../../../logger-HAWySEbs.js";
|
|
3
|
+
import { S as SQLiteCoordinator } from "../../../index-DNqHWa8F.js";
|
|
4
|
+
import { c as createConnectorFromPath } from "../../../connector-factory-wivcyMhC.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-
|
|
2
|
-
import { l as logger } from "../../../logger-
|
|
3
|
-
import { c as createConnectorFromPath } from "../../../connector-factory-
|
|
1
|
+
import "../../../config-152LkbTv.js";
|
|
2
|
+
import { l as logger } from "../../../logger-HAWySEbs.js";
|
|
3
|
+
import { c as createConnectorFromPath } from "../../../connector-factory-wivcyMhC.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-
|
|
2
|
+
import { l as logger } from "../../../logger-HAWySEbs.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;
|
|
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-
|
|
2
|
-
import { l as logger } from "../../../logger-
|
|
3
|
-
import { c as createConnectorFromPath } from "../../../connector-factory-
|
|
1
|
+
import "../../../config-152LkbTv.js";
|
|
2
|
+
import { l as logger } from "../../../logger-HAWySEbs.js";
|
|
3
|
+
import { c as createConnectorFromPath } from "../../../connector-factory-wivcyMhC.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 \"
|
|
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 @@
|
|
|
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,36 @@
|
|
|
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
|
+
constructor(config: PsqlConfiguration);
|
|
10
|
+
/**
|
|
11
|
+
* Build PSQL ODBC connection string
|
|
12
|
+
* CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
|
|
13
|
+
*/
|
|
14
|
+
private buildConnectionString;
|
|
15
|
+
/**
|
|
16
|
+
* Execute a query and return the results
|
|
17
|
+
* Creates a fresh connection for each query to avoid handle corruption
|
|
18
|
+
*
|
|
19
|
+
* @param query The SQL query to execute
|
|
20
|
+
* @param params Query parameters (currently unused for PSQL read operations)
|
|
21
|
+
* @param paging Optional paging parameters
|
|
22
|
+
* @returns The entities fetched from the database, along with paging information
|
|
23
|
+
*/
|
|
24
|
+
executePreparedStatement(query: string, params?: Record<string, string>, paging?: PagingParams): Promise<ERPResponse | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Transform ODBC result set to array of Record<string, string> instances.
|
|
27
|
+
* IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
|
|
28
|
+
*/
|
|
29
|
+
static recordsetToRecords(recordset: any[]): Record<string, string>[];
|
|
30
|
+
/**
|
|
31
|
+
* Handle ODBC errors and provide meaningful messages
|
|
32
|
+
*/
|
|
33
|
+
private handleOdbcError;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# 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":"AACA,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;AAEF,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAoB;gBAEtB,MAAM,EAAE,iBAAiB;IASrC;;;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;IAqEnC;;;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;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/services/reporting-service/logger.ts"],"names":[],"mappings":"AA+DA,QAAA,MAAM,MAAM,0BAaV,CAAC;AA+EH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,SAuChE,CAAC;AAKF,eAAe,MAAM,CAAC"}
|
|
@@ -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,aAAa;
|
|
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,aAAa;IACrB,UAAU,eAAe;CAC1B;AAED,oBAAY,UAAU;IACpB,SAAS,IAAA;IACT,KAAK,IAAA;IACL,cAAc,IAAA;IACd,WAAW,IAAA;IACX,qBAAqB,IAAA;IACrB,OAAO,IAAA;IACP,OAAO,IAAA;IACP,aAAa,IAAA;CAEd;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;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"}
|
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": "
|
|
4
|
+
"version": "0.1.8-beta.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "machinemetrics",
|
|
7
7
|
"main": "dist/mm-erp-sdk.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"knex": "^3.1.0",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
30
|
"mssql": "^11.0.1",
|
|
31
|
+
"odbc": "^2.4.8",
|
|
31
32
|
"winston": "^3.14.0",
|
|
32
33
|
"winston-daily-rotate-file": "^5.0.0",
|
|
33
34
|
"xxhashjs": "^0.2.2",
|
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 {
|
|
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
|
|
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 {
|
|
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 "
|
|
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,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,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,178 @@
|
|
|
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 config: PsqlConfiguration;
|
|
14
|
+
|
|
15
|
+
constructor(config: PsqlConfiguration) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// REMOVED: dispose() method - not needed anymore
|
|
20
|
+
// REMOVED: connection property - not needed anymore
|
|
21
|
+
// REMOVED: openConnection() method - not needed anymore
|
|
22
|
+
// REMOVED: closeConnection() method - not needed anymore
|
|
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
|
+
const serverName = `${this.config.host}.${this.config.port}`;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
[
|
|
33
|
+
"Driver={Pervasive ODBC Interface}",
|
|
34
|
+
`ServerName=${serverName}`,
|
|
35
|
+
`DBQ=${this.config.database}`,
|
|
36
|
+
`UID=${this.config.username}`,
|
|
37
|
+
`PWD=${this.config.password}`,
|
|
38
|
+
"AutoDoubleQuote=0",
|
|
39
|
+
].join(";") + ";"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Execute a query and return the results
|
|
45
|
+
* Creates a fresh connection for each query to avoid handle corruption
|
|
46
|
+
*
|
|
47
|
+
* @param query The SQL query to execute
|
|
48
|
+
* @param params Query parameters (currently unused for PSQL read operations)
|
|
49
|
+
* @param paging Optional paging parameters
|
|
50
|
+
* @returns The entities fetched from the database, along with paging information
|
|
51
|
+
*/
|
|
52
|
+
public async executePreparedStatement(
|
|
53
|
+
query: string,
|
|
54
|
+
params: Record<string, string> = {},
|
|
55
|
+
paging?: PagingParams
|
|
56
|
+
): Promise<ERPResponse | undefined> {
|
|
57
|
+
let connection: odbc.Connection | null = null;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Create fresh connection for THIS query only
|
|
61
|
+
const connStr = this.buildConnectionString();
|
|
62
|
+
logger.debug("Creating fresh PSQL connection for query");
|
|
63
|
+
connection = await odbc.connect(connStr);
|
|
64
|
+
|
|
65
|
+
if (Object.keys(params).length > 0) {
|
|
66
|
+
logger.warn(
|
|
67
|
+
"PsqlService: Query parameters provided but parameter binding not yet implemented. " +
|
|
68
|
+
"Using direct query execution."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const records = await connection.query(query);
|
|
73
|
+
const allRecords = PsqlService.recordsetToRecords(records);
|
|
74
|
+
const rowsFetched = allRecords.length;
|
|
75
|
+
|
|
76
|
+
// Apply paging if requested
|
|
77
|
+
const pagedData =
|
|
78
|
+
paging?.offset !== undefined || paging?.limit !== undefined
|
|
79
|
+
? allRecords.slice(
|
|
80
|
+
paging.offset || 0,
|
|
81
|
+
(paging.offset || 0) + (paging.limit || allRecords.length)
|
|
82
|
+
)
|
|
83
|
+
: allRecords;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
data: pagedData,
|
|
87
|
+
paging: {
|
|
88
|
+
count: rowsFetched,
|
|
89
|
+
limit: paging?.limit || 0,
|
|
90
|
+
offset: paging?.offset || 0,
|
|
91
|
+
nextPage:
|
|
92
|
+
paging?.limit && (paging.offset || 0) + paging.limit < rowsFetched
|
|
93
|
+
? String((paging.offset || 0) + paging.limit)
|
|
94
|
+
: undefined,
|
|
95
|
+
previousPage: paging?.offset
|
|
96
|
+
? String(Math.max(0, (paging.offset || 0) - (paging.limit || 10)))
|
|
97
|
+
: undefined,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const errorInfo = error as OdbcErrorResponse;
|
|
102
|
+
logger.error("Error fetching data from PSQL", {
|
|
103
|
+
error: errorInfo.message,
|
|
104
|
+
odbcErrors: errorInfo.odbcErrors,
|
|
105
|
+
query: query.substring(0, 200), // Log first 200 chars of query
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
throw this.handleOdbcError(errorInfo);
|
|
109
|
+
} finally {
|
|
110
|
+
// CRITICAL: Always close connection, even on error
|
|
111
|
+
if (connection) {
|
|
112
|
+
try {
|
|
113
|
+
await connection.close();
|
|
114
|
+
logger.debug("PSQL connection closed successfully");
|
|
115
|
+
} catch (err) {
|
|
116
|
+
// Don't throw on close errors, just log
|
|
117
|
+
logger.warn("Error closing PSQL connection (non-fatal)", {
|
|
118
|
+
error: err,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Transform ODBC result set to array of Record<string, string> instances.
|
|
127
|
+
* IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
|
|
128
|
+
*/
|
|
129
|
+
public static recordsetToRecords(recordset: any[]): Record<string, string>[] {
|
|
130
|
+
if (!Array.isArray(recordset)) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const data: Record<string, string>[] = recordset.map((row) => {
|
|
135
|
+
const transformedRow: Record<string, string> = {};
|
|
136
|
+
Object.keys(row).forEach((key) => {
|
|
137
|
+
const value = row[key];
|
|
138
|
+
transformedRow[key] =
|
|
139
|
+
value !== null && value !== undefined ? String(value).trim() : "";
|
|
140
|
+
});
|
|
141
|
+
return transformedRow;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return data;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Handle ODBC errors and provide meaningful messages
|
|
149
|
+
*/
|
|
150
|
+
private handleOdbcError(error: OdbcErrorResponse): Error {
|
|
151
|
+
const odbcError = error.odbcErrors?.[0];
|
|
152
|
+
const errorCode = odbcError?.state;
|
|
153
|
+
const message = odbcError?.message || error.message;
|
|
154
|
+
|
|
155
|
+
switch (errorCode) {
|
|
156
|
+
case "08S01":
|
|
157
|
+
return new Error(
|
|
158
|
+
"PSQL connection failed. Check: " +
|
|
159
|
+
"1) PVSW environment variable set to /usr/local/psql/etc/pvsw.ini, " +
|
|
160
|
+
"2) Network connectivity to ports 1583/3351, " +
|
|
161
|
+
"3) ODBC configuration files in /usr/local/psql/etc/ and /etc/. " +
|
|
162
|
+
`Original error: ${message}`
|
|
163
|
+
);
|
|
164
|
+
case "28000":
|
|
165
|
+
return new Error(
|
|
166
|
+
`PSQL authentication failed. Check username/password. Original error: ${message}`
|
|
167
|
+
);
|
|
168
|
+
case "42000":
|
|
169
|
+
return new Error(`PSQL SQL syntax error. Original error: ${message}`);
|
|
170
|
+
case "42S02":
|
|
171
|
+
return new Error(
|
|
172
|
+
`PSQL table or view not found. Check table names in query. Original error: ${message}`
|
|
173
|
+
);
|
|
174
|
+
default:
|
|
175
|
+
return new Error(`PSQL error (${errorCode || "unknown"}): ${message}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|