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

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 (33) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/mm-erp-sdk.js +227 -0
  4. package/dist/mm-erp-sdk.js.map +1 -1
  5. package/dist/services/data-sync-service/jobs/to-erp.d.ts.map +1 -1
  6. package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
  7. package/dist/services/psql-erp-service/configuration.d.ts +10 -0
  8. package/dist/services/psql-erp-service/configuration.d.ts.map +1 -0
  9. package/dist/services/psql-erp-service/index.d.ts +19 -0
  10. package/dist/services/psql-erp-service/index.d.ts.map +1 -0
  11. package/dist/services/psql-erp-service/internal/psql-config.d.ts +28 -0
  12. package/dist/services/psql-erp-service/internal/psql-config.d.ts.map +1 -0
  13. package/dist/services/psql-erp-service/internal/psql-labor-ticket-operations.d.ts +40 -0
  14. package/dist/services/psql-erp-service/internal/psql-labor-ticket-operations.d.ts.map +1 -0
  15. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts +15 -0
  16. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts.map +1 -0
  17. package/dist/services/psql-erp-service/psql-helpers.d.ts +32 -0
  18. package/dist/services/psql-erp-service/psql-helpers.d.ts.map +1 -0
  19. package/dist/services/psql-erp-service/psql-service.d.ts +36 -0
  20. package/dist/services/psql-erp-service/psql-service.d.ts.map +1 -0
  21. package/dist/types/erp-types.d.ts +2 -1
  22. package/dist/types/erp-types.d.ts.map +1 -1
  23. package/package.json +3 -1
  24. package/src/index.ts +27 -5
  25. package/src/services/data-sync-service/jobs/to-erp.ts +2 -1
  26. package/src/services/psql-erp-service/configuration.ts +9 -0
  27. package/src/services/psql-erp-service/index.ts +28 -0
  28. package/src/services/psql-erp-service/internal/psql-config.ts +13 -0
  29. package/src/services/psql-erp-service/internal/psql-labor-ticket-operations.ts +58 -0
  30. package/src/services/psql-erp-service/internal/types/psql-types.ts +17 -0
  31. package/src/services/psql-erp-service/psql-helpers.ts +90 -0
  32. package/src/services/psql-erp-service/psql-service.ts +178 -0
  33. package/src/types/erp-types.ts +1 -0
@@ -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 +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,19 @@
1
+ import { PsqlService } from "./psql-service";
2
+ import { PsqlLaborTicketOperations } from "./internal/psql-labor-ticket-operations";
3
+ /**
4
+ * A class to manage interactions with PSQL (Pervasive) databases via ODBC
5
+ */
6
+ export { PsqlService };
7
+ /**
8
+ * Labor ticket operations for PSQL (Phase 2)
9
+ */
10
+ export { PsqlLaborTicketOperations };
11
+ /**
12
+ * Configuration interface for PSQL connections
13
+ */
14
+ export type { PsqlConfiguration } from "./configuration";
15
+ /**
16
+ * Helper functions for PSQL data formatting
17
+ */
18
+ export { formatPsqlDate, formatPsqlTime, combinePsqlDateTime, isPsqlDateEmpty, cleanPsqlCharField, } from "./psql-helpers";
19
+ //# 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;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAEpF;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;GAEG;AACH,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC;;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,28 @@
1
+ import { z } from "zod";
2
+ export declare const PsqlConfigSchema: z.ZodObject<{
3
+ host: z.ZodString;
4
+ port: z.ZodString;
5
+ database: z.ZodString;
6
+ username: z.ZodString;
7
+ password: z.ZodString;
8
+ connectionTimeout: z.ZodDefault<z.ZodOptional<z.ZodString>>;
9
+ requestTimeout: z.ZodDefault<z.ZodOptional<z.ZodString>>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ password: string;
12
+ database: string;
13
+ port: string;
14
+ connectionTimeout: string;
15
+ requestTimeout: string;
16
+ host: string;
17
+ username: string;
18
+ }, {
19
+ password: string;
20
+ database: string;
21
+ port: string;
22
+ host: string;
23
+ username: string;
24
+ connectionTimeout?: string | undefined;
25
+ requestTimeout?: string | undefined;
26
+ }>;
27
+ export type PsqlConfig = z.infer<typeof PsqlConfigSchema>;
28
+ //# sourceMappingURL=psql-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psql-config.d.ts","sourceRoot":"","sources":["../../../../src/services/psql-erp-service/internal/psql-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;EAQ3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * PSQL Labor Ticket Operations
3
+ *
4
+ * Phase 2: This will handle INSERT/UPDATE/DELETE operations for labor tickets
5
+ * Phase 1: Placeholder - throws errors if called
6
+ */
7
+ import { PsqlService } from "../psql-service";
8
+ import { MMReceiveLaborTicket } from "../../../services/mm-api-service";
9
+ export declare class PsqlLaborTicketOperations {
10
+ private service;
11
+ constructor(service: PsqlService);
12
+ /**
13
+ * Create labor ticket in START_LABOR table
14
+ *
15
+ * Phase 2 Implementation Notes:
16
+ * - Will use prepared statements with parameter binding
17
+ * - Insert into START_LABOR table
18
+ * - Return GUID as erpUid
19
+ *
20
+ * @param laborTicket Labor ticket from MachineMetrics
21
+ * @returns Labor ticket and ERP unique ID
22
+ */
23
+ createLaborTicket(laborTicket: MMReceiveLaborTicket): Promise<{
24
+ laborTicket: MMReceiveLaborTicket;
25
+ erpUid: string;
26
+ }>;
27
+ /**
28
+ * Update labor ticket (move from START_LABOR to COMPLETED_LABOR)
29
+ *
30
+ * Phase 2 Implementation Notes:
31
+ * - Insert into COMPLETED_LABOR
32
+ * - Delete from START_LABOR
33
+ * - Should be done in a transaction
34
+ *
35
+ * @param laborTicket Labor ticket to update
36
+ * @returns Updated labor ticket
37
+ */
38
+ updateLaborTicket(laborTicket: MMReceiveLaborTicket): Promise<MMReceiveLaborTicket>;
39
+ }
40
+ //# sourceMappingURL=psql-labor-ticket-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psql-labor-ticket-operations.d.ts","sourceRoot":"","sources":["../../../../src/services/psql-erp-service/internal/psql-labor-ticket-operations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAGxE,qBAAa,yBAAyB;IACxB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW;IAExC;;;;;;;;;;OAUG;IACG,iBAAiB,CACrB,WAAW,EAAE,oBAAoB,GAChC,OAAO,CAAC;QAAE,WAAW,EAAE,oBAAoB,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IASjE;;;;;;;;;;OAUG;IACG,iBAAiB,CACrB,WAAW,EAAE,oBAAoB,GAChC,OAAO,CAAC,oBAAoB,CAAC;CAQjC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * PSQL-specific type definitions
3
+ */
4
+ export interface PsqlConnectionOptions {
5
+ connectionString: string;
6
+ }
7
+ export interface OdbcError {
8
+ state: string;
9
+ message: string;
10
+ code?: number;
11
+ }
12
+ export interface OdbcErrorResponse extends Error {
13
+ odbcErrors?: OdbcError[];
14
+ }
15
+ //# 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,qBAAqB;IACpC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,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"}
@@ -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,aAAa;CACtB;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"}
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": "0.1.8-beta.0",
4
+ "version": "0.1.8-beta.1",
5
5
  "license": "MIT",
6
6
  "author": "machinemetrics",
7
7
  "main": "dist/mm-erp-sdk.js",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@azure/msal-node": "^2.12.0",
21
21
  "@ladjs/graceful": "^4.2.0",
22
+ "aws-sdk": "^2.1691.0",
22
23
  "axios": "^1.7.3",
23
24
  "axios-retry": "^4.5.0",
24
25
  "better-sqlite3": "^11.3.0",
@@ -28,6 +29,7 @@
28
29
  "knex": "^3.1.0",
29
30
  "lodash": "^4.17.21",
30
31
  "mssql": "^11.0.1",
32
+ "odbc": "^2.4.8",
31
33
  "winston": "^3.14.0",
32
34
  "winston-daily-rotate-file": "^5.0.0",
33
35
  "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 { 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,18 @@ 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
+ PsqlLaborTicketOperations,
116
+ formatPsqlDate,
117
+ formatPsqlTime,
118
+ combinePsqlDateTime,
119
+ isPsqlDateEmpty,
120
+ cleanPsqlCharField,
121
+ } from "./services/psql-erp-service";
122
+ export type { PsqlConfiguration } from "./services/psql-erp-service";
123
+
108
124
  // Record tracking services
109
125
  export { RecordTrackingManager } from "./services/caching-service/record-tracking-manager";
110
126
  export type { RecordTrackingObject } from "./services/caching-service/record-tracking-manager";
@@ -113,4 +129,10 @@ export type { RecordTrackingObject } from "./services/caching-service/record-tra
113
129
  export { default as knexDatabaseConfig } from "./knexfile";
114
130
 
115
131
  // MM Connector Logging
116
- export { MMConnectorLogger, FileLogDeduper, LogEntry, type LogLevelString, type LogResponse } from './utils';
132
+ export {
133
+ MMConnectorLogger,
134
+ FileLogDeduper,
135
+ LogEntry,
136
+ type LogLevelString,
137
+ type LogResponse,
138
+ } 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,28 @@
1
+ import { PsqlService } from "./psql-service";
2
+ import { PsqlLaborTicketOperations } from "./internal/psql-labor-ticket-operations";
3
+
4
+ /**
5
+ * A class to manage interactions with PSQL (Pervasive) databases via ODBC
6
+ */
7
+ export { PsqlService };
8
+
9
+ /**
10
+ * Labor ticket operations for PSQL (Phase 2)
11
+ */
12
+ export { PsqlLaborTicketOperations };
13
+
14
+ /**
15
+ * Configuration interface for PSQL connections
16
+ */
17
+ export type { PsqlConfiguration } from "./configuration";
18
+
19
+ /**
20
+ * Helper functions for PSQL data formatting
21
+ */
22
+ export {
23
+ formatPsqlDate,
24
+ formatPsqlTime,
25
+ combinePsqlDateTime,
26
+ isPsqlDateEmpty,
27
+ cleanPsqlCharField,
28
+ } from "./psql-helpers";
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ export const PsqlConfigSchema = z.object({
4
+ host: z.string().nonempty("Host is required."),
5
+ port: z.string().nonempty("Port is required."),
6
+ database: z.string().nonempty("Database name is required."),
7
+ username: z.string().nonempty("Username is required."),
8
+ password: z.string().nonempty("Password is required."),
9
+ connectionTimeout: z.string().optional().default("15000"),
10
+ requestTimeout: z.string().optional().default("15000"),
11
+ });
12
+
13
+ export type PsqlConfig = z.infer<typeof PsqlConfigSchema>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * PSQL Labor Ticket Operations
3
+ *
4
+ * Phase 2: This will handle INSERT/UPDATE/DELETE operations for labor tickets
5
+ * Phase 1: Placeholder - throws errors if called
6
+ */
7
+
8
+ import { PsqlService } from "../psql-service";
9
+ import { MMReceiveLaborTicket } from "../../../services/mm-api-service";
10
+ import logger from "../../reporting-service/logger";
11
+
12
+ export class PsqlLaborTicketOperations {
13
+ constructor(private service: PsqlService) {}
14
+
15
+ /**
16
+ * Create labor ticket in START_LABOR table
17
+ *
18
+ * Phase 2 Implementation Notes:
19
+ * - Will use prepared statements with parameter binding
20
+ * - Insert into START_LABOR table
21
+ * - Return GUID as erpUid
22
+ *
23
+ * @param laborTicket Labor ticket from MachineMetrics
24
+ * @returns Labor ticket and ERP unique ID
25
+ */
26
+ async createLaborTicket(
27
+ laborTicket: MMReceiveLaborTicket
28
+ ): Promise<{ laborTicket: MMReceiveLaborTicket; erpUid: string }> {
29
+ logger.warn(
30
+ "PsqlLaborTicketOperations.createLaborTicket not yet implemented (Phase 2)"
31
+ );
32
+ throw new Error(
33
+ "Labor ticket creation not implemented for PSQL. This is a Phase 2 feature."
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Update labor ticket (move from START_LABOR to COMPLETED_LABOR)
39
+ *
40
+ * Phase 2 Implementation Notes:
41
+ * - Insert into COMPLETED_LABOR
42
+ * - Delete from START_LABOR
43
+ * - Should be done in a transaction
44
+ *
45
+ * @param laborTicket Labor ticket to update
46
+ * @returns Updated labor ticket
47
+ */
48
+ async updateLaborTicket(
49
+ laborTicket: MMReceiveLaborTicket
50
+ ): Promise<MMReceiveLaborTicket> {
51
+ logger.warn(
52
+ "PsqlLaborTicketOperations.updateLaborTicket not yet implemented (Phase 2)"
53
+ );
54
+ throw new Error(
55
+ "Labor ticket update not implemented for PSQL. This is a Phase 2 feature."
56
+ );
57
+ }
58
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * PSQL-specific type definitions
3
+ */
4
+
5
+ export interface PsqlConnectionOptions {
6
+ connectionString: string;
7
+ }
8
+
9
+ export interface OdbcError {
10
+ state: string;
11
+ message: string;
12
+ code?: number;
13
+ }
14
+
15
+ export interface OdbcErrorResponse extends Error {
16
+ odbcErrors?: OdbcError[];
17
+ }
@@ -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
+ }