@machinemetrics/mm-erp-sdk 0.1.8-beta.9 → 0.1.8

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 (67) hide show
  1. package/README.md +3 -8
  2. package/dist/{hashed-cache-manager-B1hPBNnF.js → hashed-cache-manager-Ds-HksA0.js} +32 -2
  3. package/dist/hashed-cache-manager-Ds-HksA0.js.map +1 -0
  4. package/dist/{index-DCgheVjV.js → index-DTtmv8Iq.js} +15 -4
  5. package/dist/index-DTtmv8Iq.js.map +1 -0
  6. package/dist/index.d.ts +7 -5
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/mm-erp-sdk.js +254 -26
  9. package/dist/mm-erp-sdk.js.map +1 -1
  10. package/dist/services/data-sync-service/configuration-manager.d.ts +5 -0
  11. package/dist/services/data-sync-service/configuration-manager.d.ts.map +1 -1
  12. package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +2 -2
  13. package/dist/services/data-sync-service/jobs/from-erp.js +1 -1
  14. package/dist/services/mm-api-service/mm-api-service.d.ts +4 -4
  15. package/dist/services/mm-api-service/mm-api-service.d.ts.map +1 -1
  16. package/dist/services/mm-api-service/types/checkpoint.d.ts +1 -2
  17. package/dist/services/mm-api-service/types/checkpoint.d.ts.map +1 -1
  18. package/dist/services/psql-erp-service/configuration.d.ts +8 -0
  19. package/dist/services/psql-erp-service/configuration.d.ts.map +1 -0
  20. package/dist/services/psql-erp-service/index.d.ts +14 -0
  21. package/dist/services/psql-erp-service/index.d.ts.map +1 -0
  22. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts +12 -0
  23. package/dist/services/psql-erp-service/internal/types/psql-types.d.ts.map +1 -0
  24. package/dist/services/psql-erp-service/psql-helpers.d.ts +32 -0
  25. package/dist/services/psql-erp-service/psql-helpers.d.ts.map +1 -0
  26. package/dist/services/psql-erp-service/psql-service.d.ts +50 -0
  27. package/dist/services/psql-erp-service/psql-service.d.ts.map +1 -0
  28. package/dist/types/erp-connector.d.ts +4 -2
  29. package/dist/types/erp-connector.d.ts.map +1 -1
  30. package/dist/types/erp-types.d.ts +0 -9
  31. package/dist/types/erp-types.d.ts.map +1 -1
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/index.d.ts.map +1 -1
  34. package/dist/utils/index.d.ts +1 -1
  35. package/dist/utils/index.d.ts.map +1 -1
  36. package/dist/utils/local-data-store/jobs-shared-data.d.ts +15 -1
  37. package/dist/utils/local-data-store/jobs-shared-data.d.ts.map +1 -1
  38. package/dist/utils/standard-process-drivers/labor-ticket-erp-synchronizer.d.ts +2 -3
  39. package/dist/utils/standard-process-drivers/labor-ticket-erp-synchronizer.d.ts.map +1 -1
  40. package/dist/utils/standard-process-drivers/standard-process-drivers.d.ts +3 -3
  41. package/dist/utils/standard-process-drivers/standard-process-drivers.d.ts.map +1 -1
  42. package/dist/utils/time-utils.d.ts +2 -1
  43. package/dist/utils/time-utils.d.ts.map +1 -1
  44. package/dist/utils/timezone.d.ts +6 -3
  45. package/dist/utils/timezone.d.ts.map +1 -1
  46. package/package.json +4 -1
  47. package/src/index.ts +32 -7
  48. package/src/services/data-sync-service/configuration-manager.ts +33 -0
  49. package/src/services/mm-api-service/mm-api-service.ts +4 -4
  50. package/src/services/mm-api-service/types/checkpoint.ts +1 -3
  51. package/src/services/psql-erp-service/configuration.ts +7 -0
  52. package/src/services/psql-erp-service/index.ts +22 -0
  53. package/src/services/psql-erp-service/internal/types/psql-types.ts +13 -0
  54. package/src/services/psql-erp-service/psql-helpers.ts +114 -0
  55. package/src/services/psql-erp-service/psql-service.ts +247 -0
  56. package/src/types/erp-connector.ts +5 -2
  57. package/src/types/erp-types.ts +0 -11
  58. package/src/types/index.ts +0 -1
  59. package/src/utils/application-initializer.ts +1 -1
  60. package/src/utils/index.ts +4 -1
  61. package/src/utils/local-data-store/jobs-shared-data.ts +24 -1
  62. package/src/utils/standard-process-drivers/labor-ticket-erp-synchronizer.ts +2 -3
  63. package/src/utils/standard-process-drivers/standard-process-drivers.ts +3 -3
  64. package/src/utils/time-utils.ts +11 -6
  65. package/src/utils/timezone.ts +9 -6
  66. package/dist/hashed-cache-manager-B1hPBNnF.js.map +0 -1
  67. package/dist/index-DCgheVjV.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import logger from "../reporting-service/logger";
2
- import { ERPObjType, ERPType } from "../../types/erp-types";
2
+ import { ERPObjType } from "../../types/erp-types";
3
3
  import { MMReceiveLaborTicket } from "./types/receive-types";
4
4
  import { MMTokenManager } from "./token-mgr";
5
5
  import * as MM_SEND_TYPES from "./types/send-types";
@@ -624,7 +624,7 @@ export class MMApiClient {
624
624
  * @returns The response from the MM API
625
625
  */
626
626
  async addFailedLaborTicketRefs(
627
- system: ERPType,
627
+ system: string,
628
628
  failedTicketRefs: string[]
629
629
  ): Promise<MMApiBaseResponse> {
630
630
  return await this.postData(
@@ -635,7 +635,7 @@ export class MMApiClient {
635
635
  }
636
636
 
637
637
  async fetchFailedLaborTickets(
638
- system: ERPType
638
+ system: string
639
639
  ): Promise<MMReceiveLaborTicket[]> {
640
640
  const failedTickets = (await this.getData(
641
641
  `${this.resourceURLs[ERPObjType.LABOR_TICKETS]}/failed`,
@@ -675,7 +675,7 @@ export class MMApiClient {
675
675
  }
676
676
 
677
677
  async deleteFailedLaborTicketIds(
678
- system: ERPType,
678
+ system: string,
679
679
  laborTicketRefs: string[]
680
680
  ): Promise<MMApiBaseResponse> {
681
681
  return await this.postData(
@@ -1,10 +1,8 @@
1
- import { ERPType } from "../../../types/erp-types";
2
-
3
1
  /**
4
2
  * Represents a checkpoint for a specific system, table, and checkpoint type
5
3
  */
6
4
  export type Checkpoint = {
7
- system: ERPType;
5
+ system: string;
8
6
  table: string;
9
7
  checkpointType: "import" | "export";
10
8
  checkpointValue?: {
@@ -0,0 +1,7 @@
1
+ export interface PsqlConfiguration {
2
+ host: string;
3
+ port: string;
4
+ database: string;
5
+ username: string;
6
+ password: string;
7
+ }
@@ -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,114 @@
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.trim().length !== 6 || psqlDate === "000000") {
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
+ // Validate that the constructed date matches the input values
30
+ if (
31
+ date.getFullYear() !== fullYear ||
32
+ date.getMonth() !== (month - 1) ||
33
+ date.getDate() !== day
34
+ ) {
35
+ return null;
36
+ }
37
+ return date.toISOString().split("T")[0];
38
+ } catch (error) {
39
+ return null;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Formats a time from PSQL HHMM format to HH:MM:SS
45
+ * @param psqlTime Time in HHMM format (e.g., "1430" for 2:30 PM)
46
+ * @returns Time string in HH:MM:SS format or null if invalid
47
+ */
48
+ export function formatPsqlTime(psqlTime: string): string | null {
49
+ if (!psqlTime) {
50
+ return null;
51
+ }
52
+ const trimmed = psqlTime.trim();
53
+ if (trimmed.length !== 4) {
54
+ return null;
55
+ }
56
+ try {
57
+ const hours = parseInt(trimmed.substring(0, 2), 10);
58
+ const minutes = parseInt(trimmed.substring(2, 4), 10);
59
+ if (
60
+ isNaN(hours) ||
61
+ isNaN(minutes) ||
62
+ hours < 0 ||
63
+ hours > 23 ||
64
+ minutes < 0 ||
65
+ minutes > 59
66
+ ) {
67
+ return null;
68
+ }
69
+ // Pad hours and minutes to 2 digits
70
+ const hoursStr = hours.toString().padStart(2, "0");
71
+ const minutesStr = minutes.toString().padStart(2, "0");
72
+ return `${hoursStr}:${minutesStr}:00`;
73
+ } catch (error) {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Combines PSQL date and time into ISO datetime string
80
+ * @param psqlDate Date in YYMMDD format
81
+ * @param psqlTime Time in HHMM format
82
+ * @returns ISO datetime string or null if invalid
83
+ */
84
+ export function combinePsqlDateTime(
85
+ psqlDate: string,
86
+ psqlTime: string
87
+ ): string | null {
88
+ const date = formatPsqlDate(psqlDate);
89
+ const time = formatPsqlTime(psqlTime);
90
+
91
+ if (!date || !time) {
92
+ return null;
93
+ }
94
+
95
+ return `${date}T${time}`;
96
+ }
97
+
98
+ /**
99
+ * Helper to check if a PSQL date is "empty" (000000 or blank)
100
+ */
101
+ export function isPsqlDateEmpty(psqlDate: string): boolean {
102
+ return !psqlDate || psqlDate === "000000" || psqlDate.trim() === "";
103
+ }
104
+
105
+ /**
106
+ * Clean and trim PSQL CHAR field (removes trailing spaces)
107
+ * PSQL CHAR fields are fixed-width and padded with spaces
108
+ */
109
+ export function cleanPsqlCharField(value: string | null | undefined): string {
110
+ if (value === null || value === undefined) {
111
+ return "";
112
+ }
113
+ return String(value).trim();
114
+ }
@@ -0,0 +1,247 @@
1
+ import { PsqlConfiguration } from "./configuration";
2
+ import { ERPResponse } from "../../types/erp-types";
3
+ import { OdbcErrorResponse } from "./internal/types/psql-types";
4
+ import logger from "../reporting-service/logger";
5
+
6
+ type PagingParams = {
7
+ limit?: number;
8
+ offset?: number;
9
+ };
10
+
11
+ /**
12
+ * ODBC connection interface for type safety
13
+ */
14
+ interface OdbcConnection {
15
+ query(sql: string): Promise<any[]>;
16
+ close(): Promise<void>;
17
+ }
18
+
19
+ /**
20
+ * ODBC module interface
21
+ */
22
+ interface OdbcModule {
23
+ connect(connectionString: string): Promise<OdbcConnection>;
24
+ }
25
+
26
+ export class PsqlService {
27
+ private config: PsqlConfiguration;
28
+ private static odbcModule: OdbcModule | null = null;
29
+ private static odbcLoadError: Error | null = null;
30
+
31
+ constructor(config: PsqlConfiguration) {
32
+ this.config = config;
33
+ }
34
+
35
+ /**
36
+ * Dynamically load the ODBC module with lazy initialization and caching
37
+ * @throws Error with helpful message if ODBC package is not installed
38
+ */
39
+ private static async getOdbc(): Promise<OdbcModule> {
40
+ // If we've already tried and failed, throw the cached error
41
+ if (this.odbcLoadError) {
42
+ throw this.odbcLoadError;
43
+ }
44
+
45
+ // If already loaded, return cached module
46
+ if (this.odbcModule) {
47
+ return this.odbcModule;
48
+ }
49
+
50
+ try {
51
+ // Dynamic import - only loads when actually needed
52
+ // @ts-ignore - odbc is an optional dependency, may not be installed at build time
53
+ const odbcImport = await import("odbc");
54
+ // Handle both default export and named export patterns
55
+ const odbc = odbcImport.default || odbcImport;
56
+ this.odbcModule = odbc as OdbcModule;
57
+ return this.odbcModule;
58
+ } catch (error) {
59
+ const errorMessage = error instanceof Error ? error.message : String(error);
60
+ this.odbcLoadError = new Error(
61
+ `ODBC package is required for PSQL service but is not installed or failed to load.\n` +
62
+ `Install it with: npm install odbc\n` +
63
+ `Also install OS-level dependencies, e.g. on Alpine Linux:\n` +
64
+ ` apk add --no-cache unixodbc unixodbc-dev python3 make g++\n` +
65
+ `For other Linux distributions, install unixodbc and unixodbc-dev packages.\n` +
66
+ `Original error: ${errorMessage}`
67
+ );
68
+ throw this.odbcLoadError;
69
+ }
70
+ }
71
+
72
+ // REMOVED: dispose() method - not needed anymore
73
+ // REMOVED: connection property - not needed anymore
74
+ // REMOVED: openConnection() method - not needed anymore
75
+ // REMOVED: closeConnection() method - not needed anymore
76
+
77
+ /**
78
+ * Build PSQL ODBC connection string
79
+ * CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
80
+ */
81
+ private buildConnectionString(): string {
82
+ const serverName = `${this.config.host}.${this.config.port}`;
83
+
84
+ return (
85
+ [
86
+ "Driver={Pervasive ODBC Interface}",
87
+ `ServerName=${serverName}`,
88
+ `DBQ=${this.config.database}`,
89
+ `UID=${this.config.username}`,
90
+ `PWD=${this.config.password}`,
91
+ "AutoDoubleQuote=0",
92
+ ].join(";") + ";"
93
+ );
94
+ }
95
+
96
+ /**
97
+ * Execute a query and return the results
98
+ * Creates a fresh connection for each query to avoid handle corruption
99
+ *
100
+ * SECURITY WARNING: This method executes the provided SQL string as-is.
101
+ * - Parameter binding is NOT implemented; the `params` argument is currently ignored.
102
+ * - Never concatenate untrusted/user-supplied input into `query`.
103
+ * - Doing so can result in SQL injection vulnerabilities and data exposure.
104
+ * If dynamic values are required, ensure they are strictly validated/escaped
105
+ * or implement proper parameterized execution before accepting untrusted input.
106
+ *
107
+ * @param query The SQL query to execute
108
+ * @param params Query parameters (currently unused for PSQL read operations)
109
+ * @param paging Optional paging parameters
110
+ * @returns The entities fetched from the database, along with paging information
111
+ */
112
+ public async executePreparedStatement(
113
+ query: string,
114
+ params: Record<string, string> = {},
115
+ paging?: PagingParams
116
+ ): Promise<ERPResponse | undefined> {
117
+ // Dynamically load ODBC module (will throw helpful error if not installed)
118
+ const odbc = await PsqlService.getOdbc();
119
+ let connection: OdbcConnection | null = null;
120
+
121
+ try {
122
+ // Create fresh connection for THIS query only
123
+ const connStr = this.buildConnectionString();
124
+ logger.debug("Creating fresh PSQL connection for query");
125
+ connection = await odbc.connect(connStr);
126
+
127
+ if (Object.keys(params).length > 0) {
128
+ logger.warn(
129
+ "PsqlService: Query parameters provided but parameter binding not yet implemented. " +
130
+ "Using direct query execution."
131
+ );
132
+ }
133
+
134
+ const records = await connection.query(query);
135
+ const allRecords = PsqlService.recordsetToRecords(records);
136
+ const rowsFetched = allRecords.length;
137
+
138
+ // Apply paging if requested
139
+ const pagedData =
140
+ paging?.offset !== undefined || paging?.limit !== undefined
141
+ ? allRecords.slice(
142
+ paging.offset || 0,
143
+ (paging.offset || 0) + (paging.limit || allRecords.length)
144
+ )
145
+ : allRecords;
146
+
147
+ return {
148
+ data: pagedData,
149
+ paging: {
150
+ count: rowsFetched,
151
+ limit: paging?.limit || 0,
152
+ offset: paging?.offset || 0,
153
+ nextPage:
154
+ paging?.limit && (paging.offset || 0) + paging.limit < rowsFetched
155
+ ? String((paging.offset || 0) + paging.limit)
156
+ : undefined,
157
+ previousPage: paging?.offset
158
+ ? String(Math.max(0, (paging.offset || 0) - (paging.limit || 10)))
159
+ : undefined,
160
+ },
161
+ };
162
+ } catch (error) {
163
+ // If this is an ODBC load error (from getOdbc), re-throw it as-is
164
+ // since it already has a helpful error message
165
+ if (error instanceof Error && error.message.includes("ODBC package is required")) {
166
+ throw error;
167
+ }
168
+
169
+ // Otherwise, handle as ODBC runtime error
170
+ const errorInfo = error as OdbcErrorResponse;
171
+ logger.error("Error fetching data from PSQL", {
172
+ error: errorInfo.message,
173
+ odbcErrors: errorInfo.odbcErrors,
174
+ query: query.substring(0, 200), // Log first 200 chars of query
175
+ });
176
+
177
+ throw this.handleOdbcError(errorInfo);
178
+ } finally {
179
+ // CRITICAL: Always close connection, even on error
180
+ if (connection) {
181
+ try {
182
+ await connection.close();
183
+ logger.debug("PSQL connection closed successfully");
184
+ } catch (err) {
185
+ // Don't throw on close errors, just log
186
+ logger.warn("Error closing PSQL connection (non-fatal)", {
187
+ error: err,
188
+ });
189
+ }
190
+ }
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Transform ODBC result set to array of Record<string, string> instances.
196
+ * IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
197
+ */
198
+ public static recordsetToRecords(recordset: any[]): Record<string, string>[] {
199
+ if (!Array.isArray(recordset)) {
200
+ return [];
201
+ }
202
+
203
+ const data: Record<string, string>[] = recordset.map((row) => {
204
+ const transformedRow: Record<string, string> = {};
205
+ Object.keys(row).forEach((key) => {
206
+ const value = row[key];
207
+ transformedRow[key] =
208
+ value !== null && value !== undefined ? String(value).trim() : "";
209
+ });
210
+ return transformedRow;
211
+ });
212
+
213
+ return data;
214
+ }
215
+
216
+ /**
217
+ * Handle ODBC errors and provide meaningful messages
218
+ */
219
+ private handleOdbcError(error: OdbcErrorResponse): Error {
220
+ const odbcError = error.odbcErrors?.[0];
221
+ const errorCode = odbcError?.state;
222
+ const message = odbcError?.message || error.message;
223
+
224
+ switch (errorCode) {
225
+ case "08S01":
226
+ return new Error(
227
+ "PSQL connection failed. Check: " +
228
+ "1) PVSW environment variable set to /usr/local/psql/etc/pvsw.ini, " +
229
+ "2) Network connectivity to ports 1583/3351, " +
230
+ "3) ODBC configuration files in /usr/local/psql/etc/ and /etc/. " +
231
+ `Original error: ${message}`
232
+ );
233
+ case "28000":
234
+ return new Error(
235
+ `PSQL authentication failed. Check username/password. Original error: ${message}`
236
+ );
237
+ case "42000":
238
+ return new Error(`PSQL SQL syntax error. Original error: ${message}`);
239
+ case "42S02":
240
+ return new Error(
241
+ `PSQL table or view not found. Check table names in query. Original error: ${message}`
242
+ );
243
+ default:
244
+ return new Error(`PSQL error (${errorCode || "unknown"}): ${message}`);
245
+ }
246
+ }
247
+ }
@@ -1,5 +1,4 @@
1
1
  import { MMReceiveLaborTicket } from "../services/mm-api-service/types/receive-types";
2
- import { ERPType } from "./erp-types";
3
2
 
4
3
  /**
5
4
  * Interface for ERP connectors.
@@ -7,7 +6,11 @@ import { ERPType } from "./erp-types";
7
6
  * Required for any connector.
8
7
  */
9
8
  export interface IERPConnector {
10
- readonly type: ERPType;
9
+
10
+ /**
11
+ * The type of ERP system this connector is for.
12
+ */
13
+ readonly type: string;
11
14
 
12
15
  /**
13
16
  * Sync data from the ERP system to MM.
@@ -1,14 +1,3 @@
1
- // TO DO: This will change once the SDK is refactored into its own repo
2
- export enum ERPType {
3
- INVALID = "INVALID",
4
- D365 = "D365",
5
- JOB_BOSS = "JOB_BOSS",
6
- PROFITKEY = "PROFITKEY",
7
- PROSHOP = "PROSHOP",
8
- SYTELINE = "SYTELINE",
9
- TEMPLATE = "TEMPLATE",
10
- }
11
-
12
1
  export enum ERPObjType {
13
2
  RESOURCES,
14
3
  PARTS,
@@ -5,7 +5,6 @@
5
5
 
6
6
  export type { IERPConnector } from "./erp-connector";
7
7
  export type {
8
- ERPType,
9
8
  ERPObjType,
10
9
  ERPPagination,
11
10
  ERPResponse,
@@ -21,7 +21,7 @@ export class ApplicationInitializer {
21
21
 
22
22
  // Load and validate core configuration
23
23
  const coreConfig = CoreConfiguration.inst();
24
- logger.info("Core Configuration loaded:", coreConfig);
24
+ logger.info("Core Configuration loaded:", coreConfig.toSafeLogObject());
25
25
 
26
26
  // Perform database startup checks
27
27
  logger.info("Performing database startup checks...");
@@ -33,7 +33,10 @@ export { BatchCacheManager } from "../services/caching-service/batch-cache-manag
33
33
  export { StandardProcessDrivers } from "./standard-process-drivers/";
34
34
  export type { WriteEntitiesToMMResult } from "./standard-process-drivers/";
35
35
  export { MMBatchValidationError } from "./standard-process-drivers/";
36
- export { getCachedTimezoneOffset } from "./local-data-store/jobs-shared-data";
36
+ export {
37
+ getCachedTimezoneOffset,
38
+ getCachedTimezoneName,
39
+ } from "./local-data-store/jobs-shared-data";
37
40
 
38
41
  // Local data store
39
42
  export {
@@ -71,13 +71,17 @@ export const setInitialLoadComplete = (complete: boolean): void => {
71
71
  writeStorage(data);
72
72
  };
73
73
 
74
+ /**
75
+ * Gets the company's cached current timezone offset (e.g., -5)
76
+ * @returns The cached timezone offset or 0 if not found
77
+ */
74
78
  export const getCachedTimezoneOffset = (): number => {
75
79
  const data = readStorage();
76
80
  return (data.timezoneOffset as number) ?? 0;
77
81
  };
78
82
 
79
83
  /**
80
- * Sets the timezone offset in the cache
84
+ * Sets the company's current timezone offset in the cache
81
85
  * @param offset The timezone offset in hours
82
86
  */
83
87
  export const setTimezoneOffsetInCache = (offset: number): void => {
@@ -86,6 +90,25 @@ export const setTimezoneOffsetInCache = (offset: number): void => {
86
90
  writeStorage(data);
87
91
  };
88
92
 
93
+ /**
94
+ * Gets the cached timezone name (e.g., "America/New_York")
95
+ * @returns The cached timezone name or null if not found
96
+ */
97
+ export const getCachedTimezoneName = (): string | null => {
98
+ const data = readStorage();
99
+ return (data.timezoneName as string) ?? null;
100
+ };
101
+
102
+ /**
103
+ * Sets the timezone name in the cache
104
+ * @param timezone The timezone name (e.g., "America/New_York")
105
+ */
106
+ export const setTimezoneNameInCache = (timezone: string): void => {
107
+ const data = readStorage();
108
+ data.timezoneName = timezone;
109
+ writeStorage(data);
110
+ };
111
+
89
112
  interface CachedToken {
90
113
  token: string;
91
114
  expiration: number | null;
@@ -1,4 +1,3 @@
1
- import { ERPType } from "../../types/erp-types";
2
1
  import { IERPLaborTicketHandler } from "../../types/erp-connector";
3
2
  import { MMApiClient } from "../../services/mm-api-service/mm-api-service";
4
3
  import { MMReceiveLaborTicket } from "../../services/mm-api-service/types/receive-types";
@@ -14,7 +13,7 @@ export class LaborTicketERPSynchronizer {
14
13
  * Synchronizes updated labor tickets from MachineMetrics to an ERP system
15
14
  */
16
15
  static async syncToERP(
17
- connectorType: ERPType,
16
+ connectorType: string,
18
17
  connector: IERPLaborTicketHandler
19
18
  ): Promise<void> {
20
19
  try {
@@ -128,7 +127,7 @@ export class LaborTicketERPSynchronizer {
128
127
  * Retries labor tickets that have failed to be created or updated in the ERP during the sync
129
128
  */
130
129
  static async retryFailed(
131
- connectorType: ERPType,
130
+ connectorType: string,
132
131
  connector: IERPLaborTicketHandler
133
132
  ): Promise<void> {
134
133
  try {
@@ -1,4 +1,4 @@
1
- import { ERPType, ERPObjType } from "../../types/erp-types";
1
+ import { ERPObjType } from "../../types/erp-types";
2
2
  import { IERPLaborTicketHandler } from "../../types/erp-connector";
3
3
  import { BatchCacheManager } from "../../services/caching-service/batch-cache-manager";
4
4
  import {
@@ -72,7 +72,7 @@ export class StandardProcessDrivers {
72
72
  * and saves the checkpoint
73
73
  */
74
74
  static async syncLaborTicketsToERP(
75
- connectorType: ERPType,
75
+ connectorType: string,
76
76
  connector: IERPLaborTicketHandler
77
77
  ): Promise<void> {
78
78
  return LaborTicketERPSynchronizer.syncToERP(connectorType, connector);
@@ -86,7 +86,7 @@ export class StandardProcessDrivers {
86
86
  * which are then deleted from the list of failed labor ticket ids.
87
87
  */
88
88
  static async retryFailedLaborTickets(
89
- connectorType: ERPType,
89
+ connectorType: string,
90
90
  connector: IERPLaborTicketHandler
91
91
  ): Promise<void> {
92
92
  return LaborTicketERPSynchronizer.retryFailed(connectorType, connector);
@@ -1,5 +1,8 @@
1
1
  import logger from "../services/reporting-service/logger";
2
- import { setTimezoneOffsetInCache } from "./local-data-store/jobs-shared-data";
2
+ import {
3
+ setTimezoneOffsetInCache,
4
+ setTimezoneNameInCache,
5
+ } from "./local-data-store/jobs-shared-data";
3
6
  import {
4
7
  convertToLocalTime,
5
8
  formatDateWithTZOffset,
@@ -91,8 +94,9 @@ interface TimezoneOffsetParams {
91
94
  }
92
95
 
93
96
  /**
94
- * Gets the timezone offset for the company and sets it in the cache
97
+ * Gets the timezone offset and timezone name for the company and sets them in the cache
95
98
  * The cached offset can be acquired from getCachedTimezoneOffset() in "./local-data-store/jobs-shared-data"
99
+ * The cached timezone name can be acquired from getCachedTimezoneName() in "./local-data-store/jobs-shared-data"
96
100
  *
97
101
  * @param params.maxRetries Maximum number of retry attempts
98
102
  * @param params.retryIntervalMs Time to wait between retries in milliseconds
@@ -106,13 +110,14 @@ export const getTimezoneOffsetAndPersist = async (
106
110
  let success = false;
107
111
  let retries = 0;
108
112
  logger.info(
109
- "Acquiring the timezone offset from MachineMetrics and storing in cache"
113
+ "Acquiring the timezone offset and timezone name from MachineMetrics and storing in cache"
110
114
  );
111
115
  while (!success && retries < params.maxRetries) {
112
116
  try {
113
- const offsetHours = await getTimezoneOffset();
114
- logger.info(`Timezone offset: ${offsetHours} hours`);
115
- setTimezoneOffsetInCache(offsetHours);
117
+ const { offset, timezone } = await getTimezoneOffset();
118
+ logger.info(`Timezone offset: ${offset} hours, timezone: ${timezone}`);
119
+ setTimezoneOffsetInCache(offset);
120
+ setTimezoneNameInCache(timezone);
116
121
  success = true;
117
122
  } catch (error) {
118
123
  logger.error("Error getting timezone offset:", error);