@machinemetrics/mm-erp-sdk 0.1.4-beta.7 → 0.1.5-beta.0
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/README.md +1 -1
- package/dist/{config-WKwu1mMo.js → config-2l5vnNkA.js} +6 -6
- package/dist/{config-WKwu1mMo.js.map → config-2l5vnNkA.js.map} +1 -1
- package/dist/{connector-factory-DHmMYsRs.js → connector-factory-CQ8e7Tae.js} +3 -12
- package/dist/connector-factory-CQ8e7Tae.js.map +1 -0
- package/dist/{hashed-cache-manager-CtDhFqj6.js → hashed-cache-manager-Ci59eC75.js} +4 -5
- package/dist/{hashed-cache-manager-CtDhFqj6.js.map → hashed-cache-manager-Ci59eC75.js.map} +1 -1
- package/dist/{index-aci_wdcn.js → index-CXbOvFyf.js} +7 -7
- package/dist/{index-aci_wdcn.js.map → index-CXbOvFyf.js.map} +1 -1
- package/dist/index.d.ts +6 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/{logger-hqtl8hFM.js → logger-QG73MndU.js} +6 -6
- package/dist/{logger-hqtl8hFM.js.map → logger-QG73MndU.js.map} +1 -1
- package/dist/mm-erp-sdk.js +9 -397
- package/dist/mm-erp-sdk.js.map +1 -1
- package/dist/services/data-sync-service/index.d.ts +1 -1
- package/dist/services/data-sync-service/index.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/clean-up-expired-cache.d.ts +0 -2
- package/dist/services/data-sync-service/jobs/clean-up-expired-cache.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +41 -42
- package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js.map +1 -1
- package/dist/services/data-sync-service/jobs/from-erp.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/from-erp.js +5 -11
- package/dist/services/data-sync-service/jobs/from-erp.js.map +1 -1
- package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.d.ts +0 -2
- package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js +40 -39
- package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js.map +1 -1
- package/dist/services/data-sync-service/jobs/run-migrations.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/run-migrations.js +3 -4
- package/dist/services/data-sync-service/jobs/run-migrations.js.map +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 +5 -15
- package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
- package/dist/services/erp-api-services/index.d.ts +1 -5
- package/dist/services/erp-api-services/index.d.ts.map +1 -1
- package/dist/services/mm-api-service/index.d.ts +2 -3
- package/dist/services/mm-api-service/index.d.ts.map +1 -1
- package/dist/services/mm-api-service/mm-api-service.d.ts +0 -20
- package/dist/services/mm-api-service/mm-api-service.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/dist/utils/connector-factory.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -10
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/standard-process-drivers/index.d.ts +1 -2
- package/dist/utils/standard-process-drivers/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -19
- package/src/services/data-sync-service/index.ts +4 -1
- package/src/services/data-sync-service/jobs/clean-up-expired-cache.ts +7 -19
- package/src/services/data-sync-service/jobs/from-erp.ts +5 -12
- package/src/services/data-sync-service/jobs/retry-failed-labor-tickets.ts +5 -15
- package/src/services/data-sync-service/jobs/run-migrations.ts +2 -5
- package/src/services/data-sync-service/jobs/to-erp.ts +5 -17
- package/src/services/erp-api-services/index.ts +1 -9
- package/src/services/mm-api-service/index.ts +1 -1
- package/src/services/mm-api-service/mm-api-service.ts +0 -28
- package/src/types/erp-types.ts +1 -0
- package/src/utils/application-initializer.ts +1 -1
- package/src/utils/connector-factory.ts +3 -14
- package/src/utils/index.ts +4 -11
- package/src/utils/standard-process-drivers/index.ts +4 -2
- package/dist/connector-factory-DHmMYsRs.js.map +0 -1
- package/dist/utils/connector-log/log-deduper.d.ts +0 -56
- package/dist/utils/connector-log/log-deduper.d.ts.map +0 -1
- package/dist/utils/connector-log/mm-connector-logger-example.d.ts +0 -1
- package/dist/utils/connector-log/mm-connector-logger-example.d.ts.map +0 -1
- package/dist/utils/connector-log/mm-connector-logger.d.ts +0 -74
- package/dist/utils/connector-log/mm-connector-logger.d.ts.map +0 -1
- package/dist/utils/error-utils.d.ts +0 -2
- package/dist/utils/error-utils.d.ts.map +0 -1
- package/src/utils/connector-log/log-deduper.ts +0 -282
- package/src/utils/connector-log/mm-connector-logger-example.ts +0 -97
- package/src/utils/connector-log/mm-connector-logger.ts +0 -177
- package/src/utils/error-utils.ts +0 -18
package/src/index.ts
CHANGED
|
@@ -9,15 +9,15 @@ export { ERPType, ERPObjType } from "./types/erp-types";
|
|
|
9
9
|
export type { ERPPagination, ERPResponse, ERPObject } from "./types/erp-types";
|
|
10
10
|
|
|
11
11
|
// Configuration interfaces
|
|
12
|
-
export { ErpApiConnectionParams } from "./services/data-sync-service/configuration-manager";
|
|
12
|
+
export type { ErpApiConnectionParams } from "./services/data-sync-service/configuration-manager";
|
|
13
13
|
export { getErpApiConnectionParams } from "./services/data-sync-service/configuration-manager";
|
|
14
14
|
export { buildLogicalCondition } from "./services/erp-api-services/rest/get-query-params";
|
|
15
15
|
export type { ERPApiConfig } from "./services/erp-api-services/types";
|
|
16
16
|
|
|
17
17
|
// MM API client and types
|
|
18
18
|
export { MMApiClient } from "./services/mm-api-service";
|
|
19
|
-
export { MMReceiveLaborTicket } from "./services/mm-api-service";
|
|
20
19
|
export type {
|
|
20
|
+
MMReceiveLaborTicket,
|
|
21
21
|
MMReceiveLaborTicketReason,
|
|
22
22
|
MMReceiveLaborTicketWorkOrderOperation,
|
|
23
23
|
IToRESTApiObject,
|
|
@@ -48,7 +48,6 @@ export {
|
|
|
48
48
|
formatDateWithTZOffset,
|
|
49
49
|
applyTimezoneOffsetsToFields,
|
|
50
50
|
convertToLocalTime,
|
|
51
|
-
getErrorType,
|
|
52
51
|
} from "./utils";
|
|
53
52
|
|
|
54
53
|
// Local data store
|
|
@@ -56,8 +55,7 @@ export { getInitialLoadComplete, setInitialLoadComplete } from "./utils";
|
|
|
56
55
|
|
|
57
56
|
// HTTP client factory and types for custom API integrations
|
|
58
57
|
export { HTTPClientFactory } from "./utils/http-client";
|
|
59
|
-
export {
|
|
60
|
-
export type { HTTPResponse, HTTPClient, HTTPRequestConfig } from "./utils/http-client";
|
|
58
|
+
export type { HTTPResponse } from "./utils/http-client";
|
|
61
59
|
|
|
62
60
|
// Application initialization utilities
|
|
63
61
|
export { ApplicationInitializer } from "./utils/application-initializer";
|
|
@@ -73,13 +71,11 @@ export type { IERPLaborTicketHandler } from "./types/erp-connector";
|
|
|
73
71
|
|
|
74
72
|
// Process drivers and utilities
|
|
75
73
|
export { StandardProcessDrivers, getCachedTimezoneOffset } from "./utils";
|
|
76
|
-
export type {
|
|
77
|
-
export { MMBatchValidationError } from "./utils";
|
|
74
|
+
export type { WriteEntitiesToMMResult, MMBatchValidationError } from "./utils";
|
|
78
75
|
|
|
79
76
|
// API services
|
|
80
|
-
export type { APIResponse } from './services/erp-api-services/types';
|
|
81
77
|
export { RestAPIService } from "./services/erp-api-services/rest/rest-api-service";
|
|
82
|
-
export { ErrorHandler
|
|
78
|
+
export { ErrorHandler } from "./services/erp-api-services/errors";
|
|
83
79
|
export type {
|
|
84
80
|
QueryParams,
|
|
85
81
|
PaginatedAPIResponse,
|
|
@@ -104,13 +100,3 @@ export {
|
|
|
104
100
|
SqlServerHelper,
|
|
105
101
|
} from "./services/sql-server-erp-service";
|
|
106
102
|
export type { SQLInput } from "./services/sql-server-erp-service";
|
|
107
|
-
|
|
108
|
-
// Record tracking services
|
|
109
|
-
export { RecordTrackingManager } from "./services/caching-service/record-tracking-manager";
|
|
110
|
-
export type { RecordTrackingObject } from "./services/caching-service/record-tracking-manager";
|
|
111
|
-
|
|
112
|
-
// Knex services
|
|
113
|
-
export { default as knexDatabaseConfig } from "./knexfile";
|
|
114
|
-
|
|
115
|
-
// MM Connector Logging
|
|
116
|
-
export { MMConnectorLogger, FileLogDeduper, LogEntry, type LogLevelString, type LogResponse } from './utils';
|
|
@@ -8,4 +8,7 @@ export { runDataSyncService } from "./data-sync-service";
|
|
|
8
8
|
*/
|
|
9
9
|
export { getSQLServerConfiguration } from "./configuration-manager";
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
ErpApiConnectionParams,
|
|
13
|
+
getErpApiConnectionParams,
|
|
14
|
+
} from "./configuration-manager";
|
|
@@ -3,9 +3,6 @@ import { HashedCacheManager } from "../../caching-service/hashed-cache-manager";
|
|
|
3
3
|
import { SQLiteCoordinator } from "../../sqlite-service";
|
|
4
4
|
import logger from "../../../services/reporting-service/logger";
|
|
5
5
|
|
|
6
|
-
// Configure the logger with the correct log level
|
|
7
|
-
logger.level = process.env.LOG_LEVEL || "info";
|
|
8
|
-
|
|
9
6
|
const main = async () => {
|
|
10
7
|
const cacheManager = new HashedCacheManager();
|
|
11
8
|
try {
|
|
@@ -32,22 +29,13 @@ const main = async () => {
|
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
31
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
// Linux/Mac: both use forward slashes, so this normalization is safe
|
|
38
|
-
const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');
|
|
39
|
-
const fileUrl = normalizedArgv1.startsWith('/') ?
|
|
40
|
-
`file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path
|
|
41
|
-
`file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
|
|
42
|
-
const isMainModule = import.meta.url === fileUrl;
|
|
43
|
-
|
|
44
|
-
if (isMainModule) {
|
|
32
|
+
// For Bree compatibility - check if this is running as a worker
|
|
33
|
+
if (require.main === module) {
|
|
45
34
|
// This is called when Bree runs this file as a worker
|
|
46
|
-
|
|
35
|
+
(async () => {
|
|
47
36
|
await main();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
})();
|
|
38
|
+
} else {
|
|
39
|
+
// Export for potential testing or direct usage
|
|
40
|
+
module.exports = main;
|
|
51
41
|
}
|
|
52
|
-
|
|
53
|
-
export default main;
|
|
@@ -4,9 +4,6 @@ import logger from "../../../services/reporting-service/logger";
|
|
|
4
4
|
import { SQLiteCoordinator } from "../../sqlite-service";
|
|
5
5
|
import { createConnectorFromPath } from "../../../utils/connector-factory";
|
|
6
6
|
|
|
7
|
-
// Configure the logger with the correct log level
|
|
8
|
-
logger.level = process.env.LOG_LEVEL || "info";
|
|
9
|
-
|
|
10
7
|
const main = async () => {
|
|
11
8
|
try {
|
|
12
9
|
logger.info('Worker for job "from-erp" online');
|
|
@@ -14,7 +11,8 @@ const main = async () => {
|
|
|
14
11
|
|
|
15
12
|
// Get the connector path from the environment variable
|
|
16
13
|
const connectorPath = process.env.CONNECTOR_PATH;
|
|
17
|
-
|
|
14
|
+
|
|
15
|
+
|
|
18
16
|
if (!connectorPath) {
|
|
19
17
|
throw new Error("Connector path not provided in environment variables");
|
|
20
18
|
}
|
|
@@ -43,14 +41,9 @@ const main = async () => {
|
|
|
43
41
|
}
|
|
44
42
|
};
|
|
45
43
|
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');
|
|
50
|
-
const fileUrl = normalizedArgv1.startsWith('/') ?
|
|
51
|
-
`file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path
|
|
52
|
-
`file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
|
|
53
|
-
const isMainModule = import.meta.url === fileUrl;
|
|
44
|
+
// For Bree compatibility - check if this is running as a worker
|
|
45
|
+
// In ES modules, we need to check import.meta.url instead of require.main
|
|
46
|
+
const isMainModule = import.meta.url === `file://${process.argv[1]}`;
|
|
54
47
|
|
|
55
48
|
if (isMainModule) {
|
|
56
49
|
// This is called when Bree runs this file as a worker
|
|
@@ -3,9 +3,6 @@ import "dotenv/config";
|
|
|
3
3
|
import logger from "../../../services/reporting-service/logger";
|
|
4
4
|
import { createConnectorFromPath } from "../../../utils/connector-factory";
|
|
5
5
|
|
|
6
|
-
// Configure the logger with the correct log level
|
|
7
|
-
logger.level = process.env.LOG_LEVEL || "info";
|
|
8
|
-
|
|
9
6
|
const main = async () => {
|
|
10
7
|
try {
|
|
11
8
|
logger.info('Worker for job "retry-failed-labor-tickets" online');
|
|
@@ -37,20 +34,13 @@ const main = async () => {
|
|
|
37
34
|
}
|
|
38
35
|
};
|
|
39
36
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
// Linux/Mac: both use forward slashes, so this normalization is safe
|
|
43
|
-
const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');
|
|
44
|
-
const fileUrl = normalizedArgv1.startsWith('/') ?
|
|
45
|
-
`file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path
|
|
46
|
-
`file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
|
|
47
|
-
const isMainModule = import.meta.url === fileUrl;
|
|
48
|
-
|
|
49
|
-
if (isMainModule) {
|
|
37
|
+
// For Bree compatibility - check if this is running as a worker
|
|
38
|
+
if (require.main === module) {
|
|
50
39
|
// This is called when Bree runs this file as a worker
|
|
51
40
|
main().catch(() => {
|
|
52
41
|
process.exitCode = 1;
|
|
53
42
|
});
|
|
43
|
+
} else {
|
|
44
|
+
// Export for potential testing or direct usage
|
|
45
|
+
module.exports = main;
|
|
54
46
|
}
|
|
55
|
-
|
|
56
|
-
export default main;
|
|
@@ -2,9 +2,6 @@ import knex, { Knex } from "knex";
|
|
|
2
2
|
import logger from "../../reporting-service/logger";
|
|
3
3
|
import config from "../../../knexfile";
|
|
4
4
|
|
|
5
|
-
// Configure the logger with the correct log level
|
|
6
|
-
logger.level = process.env.LOG_LEVEL || "info";
|
|
7
|
-
|
|
8
5
|
// MLW TODO Consider the location of knexfile
|
|
9
6
|
const db: Knex = knex(config.local);
|
|
10
7
|
|
|
@@ -15,7 +12,7 @@ export default async function runMigrations() {
|
|
|
15
12
|
logger.info("Migrations complete!");
|
|
16
13
|
} catch (error) {
|
|
17
14
|
logger.error("Error running migrations:", error);
|
|
18
|
-
process.
|
|
15
|
+
process.exit(1);
|
|
19
16
|
} finally {
|
|
20
17
|
await db.destroy();
|
|
21
18
|
}
|
|
@@ -25,6 +22,6 @@ const isMainModule = import.meta.url === `file://${process.argv[1]}`;
|
|
|
25
22
|
if (isMainModule) {
|
|
26
23
|
runMigrations().catch(err => {
|
|
27
24
|
logger.error("Top-level error running migrations:", err);
|
|
28
|
-
process.
|
|
25
|
+
process.exit(1);
|
|
29
26
|
});
|
|
30
27
|
}
|
|
@@ -3,9 +3,6 @@ import "dotenv/config";
|
|
|
3
3
|
import logger from "../../reporting-service/logger";
|
|
4
4
|
import { createConnectorFromPath } from "../../../utils/connector-factory";
|
|
5
5
|
|
|
6
|
-
// Configure the logger with the correct log level
|
|
7
|
-
logger.level = process.env.LOG_LEVEL || "info";
|
|
8
|
-
|
|
9
6
|
const main = async () => {
|
|
10
7
|
try {
|
|
11
8
|
logger.info('Worker for job "to-erp" online');
|
|
@@ -44,22 +41,13 @@ const main = async () => {
|
|
|
44
41
|
}
|
|
45
42
|
};
|
|
46
43
|
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');
|
|
51
|
-
const fileUrl = normalizedArgv1.startsWith('/') ?
|
|
52
|
-
`file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path
|
|
53
|
-
`file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
|
|
54
|
-
const isMainModule = import.meta.url === fileUrl;
|
|
55
|
-
|
|
44
|
+
// For Bree compatibility - check if this is running as a worker
|
|
45
|
+
// In ES modules, we need to check import.meta.url instead of require.main
|
|
46
|
+
const isMainModule = import.meta.url === `file://${process.argv[1]}`;
|
|
56
47
|
if (isMainModule) {
|
|
57
48
|
// This is called when Bree runs this file as a worker
|
|
58
|
-
|
|
59
|
-
await main();
|
|
60
|
-
} catch {
|
|
61
|
-
process.exitCode = 1; // prefer exitCode so stdout/stderr can flush
|
|
62
|
-
}
|
|
49
|
+
main();
|
|
63
50
|
}
|
|
64
51
|
|
|
52
|
+
// Export for potential testing or direct usage (ES module default export)
|
|
65
53
|
export default main;
|
|
@@ -9,14 +9,6 @@ export type { QueryParams } from "./rest/get-query-params";
|
|
|
9
9
|
|
|
10
10
|
// GraphQL Service
|
|
11
11
|
export { GraphQLService } from "./graphql/graphql-service";
|
|
12
|
-
export type { GraphQLServerError } from './graphql/types';
|
|
13
12
|
|
|
14
13
|
// OAuth Client
|
|
15
|
-
export { OAuthClient } from
|
|
16
|
-
export type { OAuthConfig } from './oauth-client';
|
|
17
|
-
|
|
18
|
-
// API Response
|
|
19
|
-
export type { APIResponse } from './types';
|
|
20
|
-
|
|
21
|
-
// Error classes
|
|
22
|
-
export { ErrorHandler, GraphQLError } from './errors';
|
|
14
|
+
export { OAuthClient } from "./oauth-client";
|
|
@@ -52,8 +52,8 @@ export type {
|
|
|
52
52
|
/**
|
|
53
53
|
* Types related of labor tickets received from the MM API
|
|
54
54
|
*/
|
|
55
|
-
export { MMReceiveLaborTicket } from "./types/receive-types";
|
|
56
55
|
export type {
|
|
56
|
+
MMReceiveLaborTicket,
|
|
57
57
|
MMReceiveLaborTicketReason,
|
|
58
58
|
MMReceiveLaborTicketWorkOrderOperation,
|
|
59
59
|
};
|
|
@@ -646,34 +646,6 @@ export class MMApiClient {
|
|
|
646
646
|
);
|
|
647
647
|
}
|
|
648
648
|
|
|
649
|
-
/**
|
|
650
|
-
* Send connector logs to the MM API
|
|
651
|
-
* @param logEntry Single log entry to send
|
|
652
|
-
* @returns Promise with the API response
|
|
653
|
-
*/
|
|
654
|
-
async sendConnectorLog(logEntry: { source: string; level: string; message: string }): Promise<MMApiBaseResponse> {
|
|
655
|
-
return await this.postData(
|
|
656
|
-
'/connector/logs',
|
|
657
|
-
logEntry,
|
|
658
|
-
{},
|
|
659
|
-
{ baseUrl: UrlBase.ApiBase }
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Send bulk connector logs to the MM API
|
|
665
|
-
* @param logs Array of log entries to send
|
|
666
|
-
* @returns Promise with the API response
|
|
667
|
-
*/
|
|
668
|
-
async sendBulkConnectorLogs(logs: { source: string; level: string; message: string }[]): Promise<MMApiBaseResponse> {
|
|
669
|
-
return await this.postData(
|
|
670
|
-
'/connector/logs',
|
|
671
|
-
{ logs },
|
|
672
|
-
{},
|
|
673
|
-
{ baseUrl: UrlBase.ApiBase }
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
649
|
async deleteFailedLaborTicketIds(
|
|
678
650
|
system: ERPType,
|
|
679
651
|
laborTicketRefs: string[]
|
package/src/types/erp-types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IERPConnector } from "../types/erp-connector";
|
|
2
2
|
import logger from "../services/reporting-service/logger";
|
|
3
|
-
import { pathToFileURL } from "url";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Helper function to dynamically import and create connector instance from a file path
|
|
@@ -11,18 +10,8 @@ export const createConnectorFromPath = async (
|
|
|
11
10
|
connectorPath: string
|
|
12
11
|
): Promise<IERPConnector> => {
|
|
13
12
|
try {
|
|
14
|
-
//
|
|
15
|
-
const
|
|
16
|
-
const filename = pathParts[pathParts.length - 1];
|
|
17
|
-
|
|
18
|
-
logger.debug("createConnectorFromPath:", {
|
|
19
|
-
connectorPath,
|
|
20
|
-
pathParts,
|
|
21
|
-
filename,
|
|
22
|
-
finalImport: pathToFileURL(connectorPath).href,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const connectorModule = await import(pathToFileURL(connectorPath).href);
|
|
13
|
+
// Dynamic import the connector module
|
|
14
|
+
const connectorModule = await import(connectorPath);
|
|
26
15
|
|
|
27
16
|
// Get the default export or named export
|
|
28
17
|
const ConnectorClass =
|
|
@@ -42,4 +31,4 @@ export const createConnectorFromPath = async (
|
|
|
42
31
|
);
|
|
43
32
|
throw error;
|
|
44
33
|
}
|
|
45
|
-
};
|
|
34
|
+
};
|
package/src/utils/index.ts
CHANGED
|
@@ -31,8 +31,10 @@ export { BatchCacheManager } from "../services/caching-service/batch-cache-manag
|
|
|
31
31
|
* Process and data transformation utilities
|
|
32
32
|
*/
|
|
33
33
|
export { StandardProcessDrivers } from "./standard-process-drivers/";
|
|
34
|
-
export type {
|
|
35
|
-
|
|
34
|
+
export type {
|
|
35
|
+
WriteEntitiesToMMResult,
|
|
36
|
+
MMBatchValidationError,
|
|
37
|
+
} from "./standard-process-drivers/";
|
|
36
38
|
export { getCachedTimezoneOffset } from "./local-data-store/jobs-shared-data";
|
|
37
39
|
|
|
38
40
|
// Local data store
|
|
@@ -52,20 +54,11 @@ export { getERPAPITypeFromEntity } from "./erp-type-from-entity";
|
|
|
52
54
|
* HTTP Client utilities
|
|
53
55
|
*/
|
|
54
56
|
export { HTTPClientFactory } from "./http-client";
|
|
55
|
-
export { HTTPError } from "./http-client";
|
|
56
|
-
export type { HTTPClient, HTTPRequestConfig, HTTPResponse } from "./http-client";
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* MM Labor Ticket utilities
|
|
60
60
|
*/
|
|
61
61
|
export * from "./mm-labor-ticket-helpers";
|
|
62
|
-
export { getErrorType } from './error-utils';
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* MM Connector Logger utilities
|
|
66
|
-
*/
|
|
67
|
-
export { MMConnectorLogger, LogEntry, type LogResponse, type LogLevelString } from './connector-log/mm-connector-logger';
|
|
68
|
-
export { FileLogDeduper } from './connector-log/log-deduper';
|
|
69
62
|
|
|
70
63
|
/**
|
|
71
64
|
* Application initializer
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Public exports for standard-process-drivers
|
|
2
2
|
export { StandardProcessDrivers } from "./standard-process-drivers";
|
|
3
|
-
export type {
|
|
4
|
-
|
|
3
|
+
export type {
|
|
4
|
+
WriteEntitiesToMMResult,
|
|
5
|
+
MMBatchValidationError,
|
|
6
|
+
} from "./standard-process-drivers";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connector-factory-DHmMYsRs.js","sources":["../src/utils/connector-factory.ts"],"sourcesContent":["import { IERPConnector } from \"../types/erp-connector\";\nimport logger from \"../services/reporting-service/logger\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * Helper function to dynamically import and create connector instance from a file path\n * @param connectorPath - The file path to the connector module\n * @returns A new instance of the IERPConnector\n */\nexport const createConnectorFromPath = async (\n connectorPath: string\n): Promise<IERPConnector> => {\n try {\n // Some detailed debug logging to help with troubleshooting multi-platform connector paths\n const pathParts = connectorPath.split('/');\n const filename = pathParts[pathParts.length - 1];\n\n logger.debug(\"createConnectorFromPath:\", {\n connectorPath,\n pathParts,\n filename,\n finalImport: pathToFileURL(connectorPath).href,\n });\n\n const connectorModule = await import(pathToFileURL(connectorPath).href);\n\n // Get the default export or named export\n const ConnectorClass =\n connectorModule.default ||\n connectorModule[Object.keys(connectorModule)[0]];\n\n if (!ConnectorClass) {\n throw new Error(`No connector class found in module: ${connectorPath}`);\n }\n\n // Create new instance of the connector\n return new ConnectorClass();\n } catch (error) {\n logger.error(\n `Failed to create connector instance from path: ${connectorPath}`,\n { error }\n );\n throw error;\n }\n};"],"names":[],"mappings":";;AASO,MAAM,0BAA0B,OACrC,kBAC2B;AAC3B,MAAI;AAEF,UAAM,YAAY,cAAc,MAAM,GAAG;AACzC,UAAM,WAAW,UAAU,UAAU,SAAS,CAAC;AAE/C,WAAO,MAAM,4BAA4B;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,cAAc,aAAa,EAAE;AAAA,IAAA,CAC3C;AAED,UAAM,kBAAkB,MAAM,OAAO,cAAc,aAAa,EAAE;AAGlE,UAAM,iBACJ,gBAAgB,WAChB,gBAAgB,OAAO,KAAK,eAAe,EAAE,CAAC,CAAC;AAEjD,QAAI,CAAC,gBAAgB;AACnB,YAAM,IAAI,MAAM,uCAAuC,aAAa,EAAE;AAAA,IACxE;AAGA,WAAO,IAAI,eAAA;AAAA,EACb,SAAS,OAAO;AACd,WAAO;AAAA,MACL,kDAAkD,aAAa;AAAA,MAC/D,EAAE,MAAA;AAAA,IAAM;AAEV,UAAM;AAAA,EACR;AACF;"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { LogEntry } from './mm-connector-logger';
|
|
2
|
-
/**
|
|
3
|
-
* Implement a custom LogDeduper or use the provided FileLogDeduper
|
|
4
|
-
*/
|
|
5
|
-
export interface LogDeduper {
|
|
6
|
-
decide(entry: LogEntry, now: number): Promise<string | null>;
|
|
7
|
-
onSuccess(entry: LogEntry, now: number): Promise<void>;
|
|
8
|
-
retryFailedTransmissions?(send: (entry: LogEntry, message: string) => Promise<void>): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* FileLogDeduper implements the LogDeduper interface to deduplicate
|
|
12
|
-
* logs by storing them in a file; this allows deduping across jobs.
|
|
13
|
-
*/
|
|
14
|
-
export declare class FileLogDeduper implements LogDeduper {
|
|
15
|
-
private readonly storeFilePath;
|
|
16
|
-
private readonly windowMs;
|
|
17
|
-
private readonly ttlMs;
|
|
18
|
-
private readonly sweepIntervalMs;
|
|
19
|
-
private lastSweepTsMs;
|
|
20
|
-
private readonly DEFAULT_WINDOW_TEN_MINS;
|
|
21
|
-
private readonly DEFAULT_TTL_ONE_HOUR;
|
|
22
|
-
private readonly DEFAULT_SWEEP_INTERVAL_FIVE_MINS;
|
|
23
|
-
private readonly DEFAULT_STORE_FILE_PATH;
|
|
24
|
-
/**
|
|
25
|
-
* Ctor.
|
|
26
|
-
* @param storeFilePath: The path to the file where the deduplication store is stored; recommended is to use the default
|
|
27
|
-
* @param windowSeconds: Suppression window. Duplicates within this period are suppressed.
|
|
28
|
-
* @param ttlSeconds: Eviction TTL. Store entries for keys inactive beyond this are removed. Enforced to be ≥ windowSeconds.
|
|
29
|
-
* @param sweepIntervalSeconds: Efficiency parameter. How often (min interval) to run opportunistic eviction; retry always sweeps
|
|
30
|
-
* The sweep is lazy, used only when the store is accessed
|
|
31
|
-
*/
|
|
32
|
-
constructor({ storeFilePath, windowSeconds, ttlSeconds, sweepIntervalSeconds }?: {
|
|
33
|
-
storeFilePath?: string;
|
|
34
|
-
windowSeconds?: number;
|
|
35
|
-
ttlSeconds?: number;
|
|
36
|
-
sweepIntervalSeconds?: number;
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Deduplication gating function
|
|
40
|
-
* Returns the formatted message to send, or null to suppress
|
|
41
|
-
* Decision is based on the dedupeKey and the time of the entry
|
|
42
|
-
*/
|
|
43
|
-
decide(entry: LogEntry, now: number): Promise<string | null>;
|
|
44
|
-
onSuccess(entry: LogEntry, now: number): Promise<void>;
|
|
45
|
-
retryFailedTransmissions(send: (entry: LogEntry, message: string) => Promise<void>): Promise<void>;
|
|
46
|
-
private ensureStoreFileExists;
|
|
47
|
-
private readStore;
|
|
48
|
-
private writeStore;
|
|
49
|
-
private formatMessage;
|
|
50
|
-
private withLock;
|
|
51
|
-
/**
|
|
52
|
-
* Evict expired entries from the store based on the TTL and the key's last transmitted time
|
|
53
|
-
*/
|
|
54
|
-
private evictExpiredInStore;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=log-deduper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log-deduper.d.ts","sourceRoot":"","sources":["../../../src/utils/connector-log/log-deduper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,uBAAuB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7D,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,wBAAwB,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrG;AAkBD;;;GAGG;AACH,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAO;IAC/C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAQ;IAC7C,OAAO,CAAC,QAAQ,CAAC,gCAAgC,CAAO;IACxD,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA+C;IAEvF;;;;;;;OAOG;gBACS,EACV,aAA4C,EAC5C,aAA4C,EAC5C,UAAsC,EACtC,oBAA4D,EAC7D,GAAG;QACF,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC1B;IAWN;;;;MAIE;IACI,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA4D5D,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBtD,wBAAwB,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAyCxG,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,aAAa;YAUP,QAAQ;IA2BtB;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAW5B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=mm-connector-logger-example.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mm-connector-logger-example.d.ts","sourceRoot":"","sources":["../../../src/utils/connector-log/mm-connector-logger-example.ts"],"names":[],"mappings":""}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { LogDeduper } from './log-deduper';
|
|
2
|
-
export type LogLevelString = 'info' | 'warn' | 'error';
|
|
3
|
-
/**
|
|
4
|
-
* dedupeKey - key used to deduplicate log entries when a LogDeduper is injected into the MMConnectorLogger
|
|
5
|
-
*
|
|
6
|
-
* A recommended practice is to use a meaningful unique identifier for this log entry type.
|
|
7
|
-
* Examples: SyncFromERPCompleted
|
|
8
|
-
* SyncFromERPError:HTTPError
|
|
9
|
-
*/
|
|
10
|
-
export declare class LogEntry {
|
|
11
|
-
level: LogLevelString;
|
|
12
|
-
message: string;
|
|
13
|
-
dedupeKey: string;
|
|
14
|
-
eventTime: number;
|
|
15
|
-
constructor(params: {
|
|
16
|
-
level: LogLevelString;
|
|
17
|
-
message: string;
|
|
18
|
-
dedupeKey: string;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The response from the MM connector logging API
|
|
23
|
-
*/
|
|
24
|
-
export interface LogResponse {
|
|
25
|
-
message: string;
|
|
26
|
-
processed?: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* MM Connector Logger for sending progress and error updates to the MM cloud
|
|
30
|
-
*
|
|
31
|
-
* This class provides helper methods to send individual logs to the
|
|
32
|
-
* MM connector logging API, providing support for validation, retries, and error handling
|
|
33
|
-
* according to the API specification.
|
|
34
|
-
*
|
|
35
|
-
* By injecting a LogDeduper, the log entries are deduplicated across jobs over a specified time window
|
|
36
|
-
*/
|
|
37
|
-
export declare class MMConnectorLogger {
|
|
38
|
-
private readonly MAX_MSG_LEN;
|
|
39
|
-
private mmApiClient;
|
|
40
|
-
private readonly deduper?;
|
|
41
|
-
private readonly source;
|
|
42
|
-
constructor(source: string, deduper?: LogDeduper);
|
|
43
|
-
/**
|
|
44
|
-
* Send a single log entry to the MM cloud with deduplication.
|
|
45
|
-
*
|
|
46
|
-
* The deduplication is handled by the injected LogDeduper.
|
|
47
|
-
* If no deduper is injected, the log entry is sent without deduplication.
|
|
48
|
-
*
|
|
49
|
-
* The standard deduper, FileLogDeduper, stores the deduplication state in a file,
|
|
50
|
-
* allowing deduplication across jobs,
|
|
51
|
-
*
|
|
52
|
-
* @param logEntry - The log entry to send
|
|
53
|
-
* @returns Promise resolving to the API response or null if suppressed
|
|
54
|
-
* @throws HTTPError if the request fails or Error if the log entry is invalid
|
|
55
|
-
*/
|
|
56
|
-
sendLog(logEntry: LogEntry): Promise<LogResponse | null>;
|
|
57
|
-
/**
|
|
58
|
-
* @throws Error if validation fails
|
|
59
|
-
*/
|
|
60
|
-
private validateLogEntry;
|
|
61
|
-
/**
|
|
62
|
-
* Retry all failed transmissions silently
|
|
63
|
-
* This method attempts to retry all messages that failed to transmit
|
|
64
|
-
* and removes them from the failed list if successful, else leaves them for the client to retry
|
|
65
|
-
*
|
|
66
|
-
* Expected usage is by a client to call this as part of its own retry mechanism
|
|
67
|
-
*/
|
|
68
|
-
retryFailedTransmissions(): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Clean up resources
|
|
71
|
-
*/
|
|
72
|
-
destroy(): Promise<void>;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=mm-connector-logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mm-connector-logger.d.ts","sourceRoot":"","sources":["../../../src/utils/connector-log/mm-connector-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,QAAQ;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;gBAEN,MAAM,EAAE;QAAE,KAAK,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC;CAMjF;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IAEpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU;IAYhD;;;;;;;;;;;;OAYG;IACG,OAAO,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAsC9D;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;;;;;OAMG;IACG,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAQA,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASnD"}
|