@machinemetrics/mm-erp-sdk 0.2.0-beta.1 → 0.2.0-beta.3

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.
@@ -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;AASvB,QAAA,MAAM,IAAI,qBAuCT,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,qBA6CT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
@@ -12,9 +12,13 @@ const main = async () => {
12
12
  throw new Error("Connector path not provided in environment variables");
13
13
  }
14
14
  const connector = await createConnectorFromPath(connectorPath);
15
- await SQLiteCoordinator.executeWithLock("to-erp", async () => {
15
+ if (process.env.NATS_ENABLED === "true") {
16
+ await SQLiteCoordinator.executeWithLock("to-erp", async () => {
17
+ await connector.syncToERP();
18
+ });
19
+ } else {
16
20
  await connector.syncToERP();
17
- });
21
+ }
18
22
  await connector.syncToERPCompleted();
19
23
  logger.info("==========Completed to-erp job cycle==========");
20
24
  } catch (error) {
@@ -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 { 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 SQLiteCoordinator.executeWithLock(\"to-erp\", async () => {\n await connector.syncToERP();\n });\n\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,kBAAkB,gBAAgB,UAAU,YAAY;AAC5D,YAAM,UAAU,UAAA;AAAA,IAClB,CAAC;AAED,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 \"../../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 // Only use lock if NATS is enabled (to prevent concurrent processing)\n // Otherwise, no lock needed - just run directly\n if (process.env.NATS_ENABLED === \"true\") {\n await SQLiteCoordinator.executeWithLock(\"to-erp\", async () => {\n await connector.syncToERP();\n });\n } else {\n await connector.syncToERP();\n }\n\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;AAI7D,QAAI,QAAQ,IAAI,iBAAiB,QAAQ;AACvC,YAAM,kBAAkB,gBAAgB,UAAU,YAAY;AAC5D,cAAM,UAAU,UAAA;AAAA,MAClB,CAAC;AAAA,IACH,OAAO;AACL,YAAM,UAAU,UAAA;AAAA,IAClB;AAEA,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 +1 @@
1
- {"version":3,"file":"nats-labor-ticket-listener.d.ts","sourceRoot":"","sources":["../../../src/services/data-sync-service/nats-labor-ticket-listener.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,WAAW,CAAC,CAAc;gBAEtB,SAAS,EAAE,GAAG;IAI1B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0C5B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAoBlC;;OAEG;IACH,OAAO,CAAC,0BAA0B;IA8GlC;;OAEG;YACW,kBAAkB;IA6FhC;;;OAGG;YACW,gBAAgB;CAyC/B"}
1
+ {"version":3,"file":"nats-labor-ticket-listener.d.ts","sourceRoot":"","sources":["../../../src/services/data-sync-service/nats-labor-ticket-listener.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,WAAW,CAAC,CAAc;gBAEtB,SAAS,EAAE,GAAG;IAI1B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0C5B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAoBlC;;OAEG;IACH,OAAO,CAAC,0BAA0B;IA8GlC;;OAEG;YACW,kBAAkB;IA6FhC;;;OAGG;YACW,gBAAgB;CA0C/B"}
@@ -14,8 +14,8 @@ export interface NatsHandlerRegistration {
14
14
  /**
15
15
  * Subject pattern to subscribe to (supports wildcards: *, >)
16
16
  * Examples:
17
- * - "mm.14.epic01.labor-ticket.*" (single level wildcard)
18
- * - "mm.14.epic01.erp.>" (multi-level wildcard)
17
+ * - "mm.16.epic01.labor-ticket.*" (single level wildcard)
18
+ * - "mm.16.epic01.*" (multi-level wildcard)
19
19
  */
20
20
  subject: string;
21
21
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Simple proof-of-concept NATS subscriber
3
- * Subscribes to mm.14.> and replies with "hello world"
3
+ * Subscribes to mm.16.> and replies with "hello world"
4
4
  */
5
5
  export {};
6
6
  //# sourceMappingURL=test-nats-subscriber.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"labor-ticket-erp-synchronizer.d.ts","sourceRoot":"","sources":["../../../src/utils/standard-process-drivers/labor-ticket-erp-synchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAOnE;;GAEG;AACH,qBAAa,0BAA0B;IACrC;;OAEG;WACU,SAAS,CACpB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC;IA4GhB;;OAEG;WACU,WAAW,CACtB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC;mBA+DK,sBAAsB;mBAetB,kBAAkB;CAkDxC"}
1
+ {"version":3,"file":"labor-ticket-erp-synchronizer.d.ts","sourceRoot":"","sources":["../../../src/utils/standard-process-drivers/labor-ticket-erp-synchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAOnE;;GAEG;AACH,qBAAa,0BAA0B;IACrC;;OAEG;WACU,SAAS,CACpB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC;IA6GhB;;OAEG;WACU,WAAW,CACtB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,sBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC;mBA+DK,sBAAsB;mBAetB,kBAAkB;CAkDxC"}
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.2.0-beta.1",
4
+ "version": "0.2.0-beta.3",
5
5
  "license": "MIT",
6
6
  "author": "machinemetrics",
7
7
  "main": "dist/mm-erp-sdk.js",
@@ -22,9 +22,15 @@ const main = async () => {
22
22
  // Create a new connector instance for this job
23
23
  const connector = await createConnectorFromPath(connectorPath);
24
24
 
25
- await SQLiteCoordinator.executeWithLock("to-erp", async () => {
25
+ // Only use lock if NATS is enabled (to prevent concurrent processing)
26
+ // Otherwise, no lock needed - just run directly
27
+ if (process.env.NATS_ENABLED === "true") {
28
+ await SQLiteCoordinator.executeWithLock("to-erp", async () => {
29
+ await connector.syncToERP();
30
+ });
31
+ } else {
26
32
  await connector.syncToERP();
27
- });
33
+ }
28
34
 
29
35
  await connector.syncToERPCompleted();
30
36
 
@@ -52,7 +52,7 @@ export class NatsLaborTicketListener {
52
52
  await this.natsService.connect();
53
53
 
54
54
  logger.info("NATS listener started successfully", {
55
- subject: `mm.14.${companyInfo.locationRef}.labor-ticket.*`,
55
+ subject: `mm.16.${companyInfo.locationRef}.labor-ticket.*`,
56
56
  });
57
57
  } catch (error) {
58
58
  logger.error("Failed to start NATS listener", { error });
@@ -67,7 +67,7 @@ export class NatsLaborTicketListener {
67
67
  if (!this.natsService) return;
68
68
 
69
69
  this.natsService.registerHandler({
70
- subject: `mm.14.${locationRef}.erp.health`,
70
+ subject: `mm.16.${locationRef}.health`,
71
71
  description: "Health check - responds immediately to indicate connector is online",
72
72
  handler: {
73
73
  handle: async () => {
@@ -90,7 +90,7 @@ export class NatsLaborTicketListener {
90
90
  if (!this.natsService) return;
91
91
 
92
92
  this.natsService.registerHandler({
93
- subject: `mm.14.${locationRef}.labor-ticket.*`,
93
+ subject: `mm.16.${locationRef}.labor-ticket.*`,
94
94
  description: "Process labor tickets in real-time from NATS",
95
95
  handler: {
96
96
  handle: async ({ data }: any, subject: string) => {
@@ -301,6 +301,8 @@ export class NatsLaborTicketListener {
301
301
  result: { laborTicketRef: string; laborTicket: any }
302
302
  ): Promise<void> {
303
303
  const mmApiClient = new MMApiClient();
304
+ const newTimestamp = new Date().toISOString();
305
+
304
306
  const currentCheckpoint = await mmApiClient.getCheckpoint({
305
307
  system: erpType,
306
308
  table: "labor_tickets",
@@ -311,7 +313,6 @@ export class NatsLaborTicketListener {
311
313
  });
312
314
 
313
315
  const currentTimestamp = (currentCheckpoint as any)?.timestamp;
314
- const newTimestamp = result.laborTicket.updatedAt || new Date().toISOString();
315
316
 
316
317
  // Only update checkpoint if new timestamp is later than current (prevents moving backwards)
317
318
  if (!currentTimestamp || new Date(newTimestamp) > new Date(currentTimestamp)) {
@@ -21,8 +21,8 @@ export interface NatsHandlerRegistration {
21
21
  /**
22
22
  * Subject pattern to subscribe to (supports wildcards: *, >)
23
23
  * Examples:
24
- * - "mm.14.epic01.labor-ticket.*" (single level wildcard)
25
- * - "mm.14.epic01.erp.>" (multi-level wildcard)
24
+ * - "mm.16.epic01.labor-ticket.*" (single level wildcard)
25
+ * - "mm.16.epic01.*" (multi-level wildcard)
26
26
  */
27
27
  subject: string;
28
28
 
@@ -279,7 +279,7 @@ export class NatsService {
279
279
  };
280
280
 
281
281
  await this.publish(
282
- `mm.14.${this.config.locationRef}.erp.status`,
282
+ `mm.16.${this.config.locationRef}.status`,
283
283
  status
284
284
  );
285
285
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Simple proof-of-concept NATS subscriber
3
- * Subscribes to mm.14.> and replies with "hello world"
3
+ * Subscribes to mm.16.> and replies with "hello world"
4
4
  */
5
5
 
6
6
  import { connect, StringCodec } from "nats";
@@ -21,10 +21,10 @@ async function startTestSubscriber() {
21
21
  clientId: nc.info?.client_id,
22
22
  });
23
23
 
24
- // Subscribe to all messages on mm.14.>
25
- const sub = nc.subscribe("mm.14.>");
24
+ // Subscribe to all messages on mm.16.>
25
+ const sub = nc.subscribe("mm.16.>");
26
26
 
27
- logger.info("Subscribed to mm.14.> - waiting for messages...");
27
+ logger.info("Subscribed to mm.16.> - waiting for messages...");
28
28
 
29
29
  // Process incoming messages
30
30
  (async () => {
@@ -20,6 +20,7 @@ export class LaborTicketERPSynchronizer {
20
20
  const mmApiClient = new MMApiClient();
21
21
  const failedLaborTicketRefs: string[] = [];
22
22
 
23
+ // Initialize and fetch checkpoint (quick operations, don't need prolonged lock)
23
24
  await mmApiClient.initializeCheckpoint({
24
25
  system: connectorType,
25
26
  table: "labor_tickets",