@machinemetrics/mm-erp-sdk 0.1.8-beta.7 → 0.1.8-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{config-152LkbTv.js → config-cB7h4yvc.js} +2 -2
- package/dist/{config-152LkbTv.js.map → config-cB7h4yvc.js.map} +1 -1
- package/dist/{connector-factory-wivcyMhC.js → connector-factory-CKm74_WZ.js} +2 -2
- package/dist/{connector-factory-wivcyMhC.js.map → connector-factory-CKm74_WZ.js.map} +1 -1
- package/dist/{hashed-cache-manager-BnviJzB7.js → hashed-cache-manager-B1hPBNnF.js} +4 -4
- package/dist/{hashed-cache-manager-BnviJzB7.js.map → hashed-cache-manager-B1hPBNnF.js.map} +1 -1
- package/dist/{index-DNqHWa8F.js → index-DCgheVjV.js} +2 -2
- package/dist/{index-DNqHWa8F.js.map → index-DCgheVjV.js.map} +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/{logger-HAWySEbs.js → logger-CBDNtsMq.js} +18 -39
- package/dist/{logger-HAWySEbs.js.map → logger-CBDNtsMq.js.map} +1 -1
- package/dist/mm-erp-sdk.js +6 -223
- package/dist/mm-erp-sdk.js.map +1 -1
- package/dist/services/data-sync-service/jobs/clean-up-expired-cache.js +4 -4
- package/dist/services/data-sync-service/jobs/from-erp.js +4 -4
- package/dist/services/data-sync-service/jobs/retry-failed-labor-tickets.js +3 -3
- package/dist/services/data-sync-service/jobs/run-migrations.js +1 -1
- package/dist/services/data-sync-service/jobs/to-erp.d.ts.map +1 -1
- package/dist/services/data-sync-service/jobs/to-erp.js +3 -3
- package/dist/services/data-sync-service/jobs/to-erp.js.map +1 -1
- package/dist/services/reporting-service/logger.d.ts.map +1 -1
- package/dist/types/erp-types.d.ts +1 -2
- package/dist/types/erp-types.d.ts.map +1 -1
- package/package.json +1 -4
- package/src/index.ts +5 -26
- package/src/services/data-sync-service/jobs/to-erp.ts +1 -2
- package/src/services/reporting-service/logger.ts +21 -42
- package/src/types/erp-types.ts +0 -1
- package/dist/services/psql-erp-service/configuration.d.ts +0 -10
- package/dist/services/psql-erp-service/configuration.d.ts.map +0 -1
- package/dist/services/psql-erp-service/index.d.ts +0 -14
- package/dist/services/psql-erp-service/index.d.ts.map +0 -1
- package/dist/services/psql-erp-service/internal/types/psql-types.d.ts +0 -12
- package/dist/services/psql-erp-service/internal/types/psql-types.d.ts.map +0 -1
- package/dist/services/psql-erp-service/psql-helpers.d.ts +0 -32
- package/dist/services/psql-erp-service/psql-helpers.d.ts.map +0 -1
- package/dist/services/psql-erp-service/psql-service.d.ts +0 -43
- package/dist/services/psql-erp-service/psql-service.d.ts.map +0 -1
- package/src/services/psql-erp-service/configuration.ts +0 -9
- package/src/services/psql-erp-service/index.ts +0 -22
- package/src/services/psql-erp-service/internal/types/psql-types.ts +0 -13
- package/src/services/psql-erp-service/psql-helpers.ts +0 -90
- package/src/services/psql-erp-service/psql-service.ts +0 -240
package/dist/mm-erp-sdk.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { C as CoreConfiguration, H as HashedCacheManager } from "./hashed-cache-manager-
|
|
2
|
-
import { E, g, a } from "./hashed-cache-manager-
|
|
3
|
-
import { l as logger } from "./logger-
|
|
4
|
-
import { g as getCachedMMToken, s as setCachedMMToken, a as setTimezoneOffsetInCache, b as getCachedTimezoneOffset, S as SQLiteCoordinator } from "./index-
|
|
5
|
-
import { c, d } from "./index-
|
|
1
|
+
import { C as CoreConfiguration, H as HashedCacheManager } from "./hashed-cache-manager-B1hPBNnF.js";
|
|
2
|
+
import { E, g, a } from "./hashed-cache-manager-B1hPBNnF.js";
|
|
3
|
+
import { l as logger } from "./logger-CBDNtsMq.js";
|
|
4
|
+
import { g as getCachedMMToken, s as setCachedMMToken, a as setTimezoneOffsetInCache, b as getCachedTimezoneOffset, S as SQLiteCoordinator } from "./index-DCgheVjV.js";
|
|
5
|
+
import { c, d } from "./index-DCgheVjV.js";
|
|
6
6
|
import axios, { AxiosError } from "axios";
|
|
7
7
|
import knex from "knex";
|
|
8
8
|
import { c as config } from "./knexfile-1qKKIORB.js";
|
|
9
9
|
import fs from "fs";
|
|
10
10
|
import path from "path";
|
|
11
|
-
import "./connector-factory-
|
|
11
|
+
import "./connector-factory-CKm74_WZ.js";
|
|
12
12
|
import Bree from "bree";
|
|
13
13
|
import Graceful from "@ladjs/graceful";
|
|
14
14
|
import { fileURLToPath } from "url";
|
|
@@ -22,7 +22,6 @@ var ERPType = /* @__PURE__ */ ((ERPType2) => {
|
|
|
22
22
|
ERPType2["PROSHOP"] = "PROSHOP";
|
|
23
23
|
ERPType2["SYTELINE"] = "SYTELINE";
|
|
24
24
|
ERPType2["TEMPLATE"] = "TEMPLATE";
|
|
25
|
-
ERPType2["GLOBALSHOP"] = "GLOBALSHOP";
|
|
26
25
|
return ERPType2;
|
|
27
26
|
})(ERPType || {});
|
|
28
27
|
var ERPObjType = /* @__PURE__ */ ((ERPObjType2) => {
|
|
@@ -3983,216 +3982,6 @@ class SqlServerHelper {
|
|
|
3983
3982
|
logger.info("----------------------------------------");
|
|
3984
3983
|
}
|
|
3985
3984
|
}
|
|
3986
|
-
class PsqlService {
|
|
3987
|
-
config;
|
|
3988
|
-
static odbcModule = null;
|
|
3989
|
-
static odbcLoadError = null;
|
|
3990
|
-
constructor(config2) {
|
|
3991
|
-
this.config = config2;
|
|
3992
|
-
}
|
|
3993
|
-
/**
|
|
3994
|
-
* Dynamically load the ODBC module with lazy initialization and caching
|
|
3995
|
-
* @throws Error with helpful message if ODBC package is not installed
|
|
3996
|
-
*/
|
|
3997
|
-
static async getOdbc() {
|
|
3998
|
-
if (this.odbcLoadError) {
|
|
3999
|
-
throw this.odbcLoadError;
|
|
4000
|
-
}
|
|
4001
|
-
if (this.odbcModule) {
|
|
4002
|
-
return this.odbcModule;
|
|
4003
|
-
}
|
|
4004
|
-
try {
|
|
4005
|
-
const odbcImport = await import("odbc");
|
|
4006
|
-
const odbc = odbcImport.default || odbcImport;
|
|
4007
|
-
this.odbcModule = odbc;
|
|
4008
|
-
return this.odbcModule;
|
|
4009
|
-
} catch (error) {
|
|
4010
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4011
|
-
this.odbcLoadError = new Error(
|
|
4012
|
-
`ODBC package is required for PSQL service but is not installed or failed to load.
|
|
4013
|
-
Install it with: npm install odbc
|
|
4014
|
-
Also install OS-level dependencies, e.g. on Alpine Linux:
|
|
4015
|
-
apk add --no-cache unixodbc unixodbc-dev python3 make g++
|
|
4016
|
-
For other Linux distributions, install unixodbc and unixodbc-dev packages.
|
|
4017
|
-
Original error: ${errorMessage}`
|
|
4018
|
-
);
|
|
4019
|
-
throw this.odbcLoadError;
|
|
4020
|
-
}
|
|
4021
|
-
}
|
|
4022
|
-
// REMOVED: dispose() method - not needed anymore
|
|
4023
|
-
// REMOVED: connection property - not needed anymore
|
|
4024
|
-
// REMOVED: openConnection() method - not needed anymore
|
|
4025
|
-
// REMOVED: closeConnection() method - not needed anymore
|
|
4026
|
-
/**
|
|
4027
|
-
* Build PSQL ODBC connection string
|
|
4028
|
-
* CRITICAL: ServerName must use IP.PORT format (e.g., 10.4.0.11.1583)
|
|
4029
|
-
*/
|
|
4030
|
-
buildConnectionString() {
|
|
4031
|
-
const serverName = `${this.config.host}.${this.config.port}`;
|
|
4032
|
-
return [
|
|
4033
|
-
"Driver={Pervasive ODBC Interface}",
|
|
4034
|
-
`ServerName=${serverName}`,
|
|
4035
|
-
`DBQ=${this.config.database}`,
|
|
4036
|
-
`UID=${this.config.username}`,
|
|
4037
|
-
`PWD=${this.config.password}`,
|
|
4038
|
-
"AutoDoubleQuote=0"
|
|
4039
|
-
].join(";") + ";";
|
|
4040
|
-
}
|
|
4041
|
-
/**
|
|
4042
|
-
* Execute a query and return the results
|
|
4043
|
-
* Creates a fresh connection for each query to avoid handle corruption
|
|
4044
|
-
*
|
|
4045
|
-
* @param query The SQL query to execute
|
|
4046
|
-
* @param params Query parameters (currently unused for PSQL read operations)
|
|
4047
|
-
* @param paging Optional paging parameters
|
|
4048
|
-
* @returns The entities fetched from the database, along with paging information
|
|
4049
|
-
*/
|
|
4050
|
-
async executePreparedStatement(query, params = {}, paging) {
|
|
4051
|
-
const odbc = await PsqlService.getOdbc();
|
|
4052
|
-
let connection = null;
|
|
4053
|
-
try {
|
|
4054
|
-
const connStr = this.buildConnectionString();
|
|
4055
|
-
logger.debug("Creating fresh PSQL connection for query");
|
|
4056
|
-
connection = await odbc.connect(connStr);
|
|
4057
|
-
if (Object.keys(params).length > 0) {
|
|
4058
|
-
logger.warn(
|
|
4059
|
-
"PsqlService: Query parameters provided but parameter binding not yet implemented. Using direct query execution."
|
|
4060
|
-
);
|
|
4061
|
-
}
|
|
4062
|
-
const records = await connection.query(query);
|
|
4063
|
-
const allRecords = PsqlService.recordsetToRecords(records);
|
|
4064
|
-
const rowsFetched = allRecords.length;
|
|
4065
|
-
const pagedData = paging?.offset !== void 0 || paging?.limit !== void 0 ? allRecords.slice(
|
|
4066
|
-
paging.offset || 0,
|
|
4067
|
-
(paging.offset || 0) + (paging.limit || allRecords.length)
|
|
4068
|
-
) : allRecords;
|
|
4069
|
-
return {
|
|
4070
|
-
data: pagedData,
|
|
4071
|
-
paging: {
|
|
4072
|
-
count: rowsFetched,
|
|
4073
|
-
limit: paging?.limit || 0,
|
|
4074
|
-
offset: paging?.offset || 0,
|
|
4075
|
-
nextPage: paging?.limit && (paging.offset || 0) + paging.limit < rowsFetched ? String((paging.offset || 0) + paging.limit) : void 0,
|
|
4076
|
-
previousPage: paging?.offset ? String(Math.max(0, (paging.offset || 0) - (paging.limit || 10))) : void 0
|
|
4077
|
-
}
|
|
4078
|
-
};
|
|
4079
|
-
} catch (error) {
|
|
4080
|
-
if (error instanceof Error && error.message.includes("ODBC package is required")) {
|
|
4081
|
-
throw error;
|
|
4082
|
-
}
|
|
4083
|
-
const errorInfo = error;
|
|
4084
|
-
logger.error("Error fetching data from PSQL", {
|
|
4085
|
-
error: errorInfo.message,
|
|
4086
|
-
odbcErrors: errorInfo.odbcErrors,
|
|
4087
|
-
query: query.substring(0, 200)
|
|
4088
|
-
// Log first 200 chars of query
|
|
4089
|
-
});
|
|
4090
|
-
throw this.handleOdbcError(errorInfo);
|
|
4091
|
-
} finally {
|
|
4092
|
-
if (connection) {
|
|
4093
|
-
try {
|
|
4094
|
-
await connection.close();
|
|
4095
|
-
logger.debug("PSQL connection closed successfully");
|
|
4096
|
-
} catch (err) {
|
|
4097
|
-
logger.warn("Error closing PSQL connection (non-fatal)", {
|
|
4098
|
-
error: err
|
|
4099
|
-
});
|
|
4100
|
-
}
|
|
4101
|
-
}
|
|
4102
|
-
}
|
|
4103
|
-
}
|
|
4104
|
-
/**
|
|
4105
|
-
* Transform ODBC result set to array of Record<string, string> instances.
|
|
4106
|
-
* IMPORTANT: PSQL CHAR fields are often padded with spaces - we trim them
|
|
4107
|
-
*/
|
|
4108
|
-
static recordsetToRecords(recordset) {
|
|
4109
|
-
if (!Array.isArray(recordset)) {
|
|
4110
|
-
return [];
|
|
4111
|
-
}
|
|
4112
|
-
const data = recordset.map((row) => {
|
|
4113
|
-
const transformedRow = {};
|
|
4114
|
-
Object.keys(row).forEach((key) => {
|
|
4115
|
-
const value = row[key];
|
|
4116
|
-
transformedRow[key] = value !== null && value !== void 0 ? String(value).trim() : "";
|
|
4117
|
-
});
|
|
4118
|
-
return transformedRow;
|
|
4119
|
-
});
|
|
4120
|
-
return data;
|
|
4121
|
-
}
|
|
4122
|
-
/**
|
|
4123
|
-
* Handle ODBC errors and provide meaningful messages
|
|
4124
|
-
*/
|
|
4125
|
-
handleOdbcError(error) {
|
|
4126
|
-
const odbcError = error.odbcErrors?.[0];
|
|
4127
|
-
const errorCode = odbcError?.state;
|
|
4128
|
-
const message = odbcError?.message || error.message;
|
|
4129
|
-
switch (errorCode) {
|
|
4130
|
-
case "08S01":
|
|
4131
|
-
return new Error(
|
|
4132
|
-
`PSQL connection failed. Check: 1) PVSW environment variable set to /usr/local/psql/etc/pvsw.ini, 2) Network connectivity to ports 1583/3351, 3) ODBC configuration files in /usr/local/psql/etc/ and /etc/. Original error: ${message}`
|
|
4133
|
-
);
|
|
4134
|
-
case "28000":
|
|
4135
|
-
return new Error(
|
|
4136
|
-
`PSQL authentication failed. Check username/password. Original error: ${message}`
|
|
4137
|
-
);
|
|
4138
|
-
case "42000":
|
|
4139
|
-
return new Error(`PSQL SQL syntax error. Original error: ${message}`);
|
|
4140
|
-
case "42S02":
|
|
4141
|
-
return new Error(
|
|
4142
|
-
`PSQL table or view not found. Check table names in query. Original error: ${message}`
|
|
4143
|
-
);
|
|
4144
|
-
default:
|
|
4145
|
-
return new Error(`PSQL error (${errorCode || "unknown"}): ${message}`);
|
|
4146
|
-
}
|
|
4147
|
-
}
|
|
4148
|
-
}
|
|
4149
|
-
function formatPsqlDate(psqlDate) {
|
|
4150
|
-
if (!psqlDate || psqlDate === "000000" || psqlDate.trim() === "") {
|
|
4151
|
-
return null;
|
|
4152
|
-
}
|
|
4153
|
-
try {
|
|
4154
|
-
const year = parseInt(psqlDate.substring(0, 2), 10);
|
|
4155
|
-
const month = parseInt(psqlDate.substring(2, 4), 10);
|
|
4156
|
-
const day = parseInt(psqlDate.substring(4, 6), 10);
|
|
4157
|
-
const fullYear = year + 2e3;
|
|
4158
|
-
if (month < 1 || month > 12 || day < 1 || day > 31) {
|
|
4159
|
-
return null;
|
|
4160
|
-
}
|
|
4161
|
-
const date = new Date(fullYear, month - 1, day);
|
|
4162
|
-
return date.toISOString().split("T")[0];
|
|
4163
|
-
} catch (error) {
|
|
4164
|
-
return null;
|
|
4165
|
-
}
|
|
4166
|
-
}
|
|
4167
|
-
function formatPsqlTime(psqlTime) {
|
|
4168
|
-
if (!psqlTime || psqlTime.trim() === "") {
|
|
4169
|
-
return null;
|
|
4170
|
-
}
|
|
4171
|
-
try {
|
|
4172
|
-
const hours = psqlTime.substring(0, 2);
|
|
4173
|
-
const minutes = psqlTime.substring(2, 4);
|
|
4174
|
-
return `${hours}:${minutes}:00`;
|
|
4175
|
-
} catch (error) {
|
|
4176
|
-
return null;
|
|
4177
|
-
}
|
|
4178
|
-
}
|
|
4179
|
-
function combinePsqlDateTime(psqlDate, psqlTime) {
|
|
4180
|
-
const date = formatPsqlDate(psqlDate);
|
|
4181
|
-
const time = formatPsqlTime(psqlTime);
|
|
4182
|
-
if (!date || !time) {
|
|
4183
|
-
return null;
|
|
4184
|
-
}
|
|
4185
|
-
return `${date}T${time}`;
|
|
4186
|
-
}
|
|
4187
|
-
function isPsqlDateEmpty(psqlDate) {
|
|
4188
|
-
return !psqlDate || psqlDate === "000000" || psqlDate.trim() === "";
|
|
4189
|
-
}
|
|
4190
|
-
function cleanPsqlCharField(value) {
|
|
4191
|
-
if (value === null || value === void 0) {
|
|
4192
|
-
return "";
|
|
4193
|
-
}
|
|
4194
|
-
return String(value).trim();
|
|
4195
|
-
}
|
|
4196
3985
|
export {
|
|
4197
3986
|
ApplicationInitializer,
|
|
4198
3987
|
BatchCacheManager,
|
|
@@ -4220,7 +4009,6 @@ export {
|
|
|
4220
4009
|
MMSendWorkOrder,
|
|
4221
4010
|
MMSendWorkOrderOperation,
|
|
4222
4011
|
OAuthClient,
|
|
4223
|
-
PsqlService,
|
|
4224
4012
|
RecordTrackingManager,
|
|
4225
4013
|
RestAPIService,
|
|
4226
4014
|
SqlServerHelper,
|
|
@@ -4230,13 +4018,9 @@ export {
|
|
|
4230
4018
|
addNewFieldFromLookupField,
|
|
4231
4019
|
applyTimezoneOffsetsToFields,
|
|
4232
4020
|
buildLogicalCondition,
|
|
4233
|
-
cleanPsqlCharField,
|
|
4234
4021
|
cleanupNumbers,
|
|
4235
|
-
combinePsqlDateTime,
|
|
4236
4022
|
convertToLocalTime,
|
|
4237
4023
|
formatDateWithTZOffset,
|
|
4238
|
-
formatPsqlDate,
|
|
4239
|
-
formatPsqlTime,
|
|
4240
4024
|
getCachedTimezoneOffset,
|
|
4241
4025
|
g as getErpApiConnectionParams,
|
|
4242
4026
|
getErrorType,
|
|
@@ -4244,7 +4028,6 @@ export {
|
|
|
4244
4028
|
getPayloadWithoutIDField,
|
|
4245
4029
|
a as getSQLServerConfiguration,
|
|
4246
4030
|
getUniqueRows,
|
|
4247
|
-
isPsqlDateEmpty,
|
|
4248
4031
|
config as knexDatabaseConfig,
|
|
4249
4032
|
logger,
|
|
4250
4033
|
removeExtraneousFields,
|