nets-service-sdk 1.1.16 → 1.1.18
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/index.js +115 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,16 +12,15 @@ var require_utils_helper = __commonJS({
|
|
|
12
12
|
return String(num).padStart(totalLength, "0");
|
|
13
13
|
};
|
|
14
14
|
module2.exports.xorCalculation = (value) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return response.toUpperCase();
|
|
15
|
+
if (!value) return "00";
|
|
16
|
+
const splitted_arr = value.match(/[0-9A-Fa-f]{2}/g);
|
|
17
|
+
if (!splitted_arr) return "00";
|
|
18
|
+
let res = Buffer.from(splitted_arr[0], "hex");
|
|
19
|
+
for (let i = 1; i < splitted_arr.length; i++) {
|
|
20
|
+
const nextByte = Buffer.from(splitted_arr[i], "hex");
|
|
21
|
+
res[0] ^= nextByte[0];
|
|
22
|
+
}
|
|
23
|
+
return res.toString("hex").toUpperCase();
|
|
25
24
|
};
|
|
26
25
|
String.prototype.toHexString = function() {
|
|
27
26
|
var res = [];
|
|
@@ -32,12 +31,6 @@ var require_utils_helper = __commonJS({
|
|
|
32
31
|
}
|
|
33
32
|
return res.join("").toUpperCase();
|
|
34
33
|
};
|
|
35
|
-
function xor(hex1, hex2) {
|
|
36
|
-
const buf1 = Buffer.from(hex1, "hex");
|
|
37
|
-
const buf2 = Buffer.from(hex2, "hex");
|
|
38
|
-
const bufResult = buf1.map((b, i) => b ^ buf2[i]);
|
|
39
|
-
return bufResult.toString("hex");
|
|
40
|
-
}
|
|
41
34
|
String.prototype.toAsciiString = function() {
|
|
42
35
|
return this.match(/.{1,2}/g).map(function(v) {
|
|
43
36
|
return String.fromCharCode(parseInt(v, 16));
|
|
@@ -75,9 +68,10 @@ var require_winston = __commonJS({
|
|
|
75
68
|
const parts = callingModule.filename.split(path.sep);
|
|
76
69
|
return path.join(parts[parts.length - 1], parts.pop());
|
|
77
70
|
};
|
|
78
|
-
var myFormat = printf(
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
var myFormat = printf(({ level, message, label: label2, timestamp: timestamp2 }) => {
|
|
72
|
+
const versionPrefix = global.appVersion ? `[v${global.appVersion}] ` : "";
|
|
73
|
+
return `${timestamp2} [${label2}] ${versionPrefix}${level}: ${message}`;
|
|
74
|
+
});
|
|
81
75
|
var logger = (module3) => createLogger({
|
|
82
76
|
format: combine(label({ label: getLabel(module3) }), timestamp(), myFormat),
|
|
83
77
|
transports: [
|
|
@@ -190,7 +184,25 @@ var require_queue = __commonJS({
|
|
|
190
184
|
var require_sendMessage = __commonJS({
|
|
191
185
|
"src/sendMessage.js"(exports2, module2) {
|
|
192
186
|
var logger = require_winston()(module2);
|
|
187
|
+
var path = require("path");
|
|
188
|
+
var fs = require("fs");
|
|
189
|
+
var sdkVersion = "unknown";
|
|
190
|
+
try {
|
|
191
|
+
const pkgPath = path.resolve(__dirname, "../package.json");
|
|
192
|
+
if (fs.existsSync(pkgPath)) {
|
|
193
|
+
const pkg2 = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
194
|
+
sdkVersion = pkg2.version;
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
logger.error({ level: "error", message: `Error reading SDK package.json: ${err.message}` });
|
|
198
|
+
}
|
|
193
199
|
module2.exports.sendMessage = (room = "clientRoom", tag, msg) => {
|
|
200
|
+
if (typeof msg === "object" && msg !== null) {
|
|
201
|
+
msg.sdkVersion = sdkVersion;
|
|
202
|
+
if (global.appVersion) {
|
|
203
|
+
msg.appVersion = global.appVersion;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
194
206
|
logger.log({
|
|
195
207
|
level: "info",
|
|
196
208
|
message: JSON.stringify(msg)
|
|
@@ -898,9 +910,17 @@ var require_responseHandler = __commonJS({
|
|
|
898
910
|
if (!hexValue || hexValue.length < 4) return false;
|
|
899
911
|
const value = hexValue.substring(2, hexValue.length - 2);
|
|
900
912
|
const xor = xorCalculation(value).toUpperCase();
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
|
|
913
|
+
const lrcReceived = hexValue.substring(hexValue.length - 2, hexValue.length).toUpperCase();
|
|
914
|
+
const isMatch = xor === lrcReceived;
|
|
915
|
+
if (!isMatch) {
|
|
916
|
+
logger.error({
|
|
917
|
+
level: "error",
|
|
918
|
+
message: `LRC Mismatch! Calculated: ${xor}, Received: ${lrcReceived}. Checked range (hex): ${value.substring(0, 20)}...${value.substring(value.length - 10)}`
|
|
919
|
+
});
|
|
920
|
+
} else {
|
|
921
|
+
logger.info({ level: "info", message: `LRC Correct: ${xor}` });
|
|
922
|
+
}
|
|
923
|
+
return isMatch;
|
|
904
924
|
};
|
|
905
925
|
}
|
|
906
926
|
});
|
|
@@ -1068,7 +1088,7 @@ var require_communication = __commonJS({
|
|
|
1068
1088
|
};
|
|
1069
1089
|
module2.exports.processIncomingData = () => {
|
|
1070
1090
|
while (dataBuffer.length > 0) {
|
|
1071
|
-
if (dataBuffer[0] === 6 || dataBuffer[0] === 21) {
|
|
1091
|
+
if ((dataBuffer[0] === 6 || dataBuffer[0] === 21) && (dataBuffer.length === 1 || dataBuffer[1] !== 2)) {
|
|
1072
1092
|
const byte = dataBuffer[0];
|
|
1073
1093
|
ackOrNack = Buffer.from([byte]);
|
|
1074
1094
|
dataBuffer = dataBuffer.slice(1);
|
|
@@ -1103,10 +1123,26 @@ var require_communication = __commonJS({
|
|
|
1103
1123
|
}
|
|
1104
1124
|
}
|
|
1105
1125
|
if (dataBuffer.length < 3) break;
|
|
1106
|
-
const
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1109
|
-
|
|
1126
|
+
const bcdLenStr = dataBuffer.slice(1, 3).toString("hex");
|
|
1127
|
+
const bcdLen = parseInt(bcdLenStr, 10);
|
|
1128
|
+
const binLen = dataBuffer.readUInt16BE(1);
|
|
1129
|
+
let bodyLen = bcdLen;
|
|
1130
|
+
let expectedFrameSize = 1 + 2 + bodyLen + 2;
|
|
1131
|
+
if (dataBuffer.length >= expectedFrameSize && dataBuffer[3 + bodyLen] === 3) {
|
|
1132
|
+
} else if (dataBuffer.length >= 1 + 2 + binLen + 2 && dataBuffer[3 + binLen] === 3) {
|
|
1133
|
+
bodyLen = binLen;
|
|
1134
|
+
expectedFrameSize = 1 + 2 + bodyLen + 2;
|
|
1135
|
+
}
|
|
1136
|
+
if (dataBuffer.length < expectedFrameSize) {
|
|
1137
|
+
const etxIndex = dataBuffer.indexOf(3, 3);
|
|
1138
|
+
if (etxIndex !== -1 && dataBuffer.length > etxIndex + 1) {
|
|
1139
|
+
const frame = dataBuffer.slice(0, etxIndex + 2);
|
|
1140
|
+
dataBuffer = dataBuffer.slice(etxIndex + 2);
|
|
1141
|
+
exports2.handleFullMessage(frame);
|
|
1142
|
+
continue;
|
|
1143
|
+
}
|
|
1144
|
+
break;
|
|
1145
|
+
}
|
|
1110
1146
|
if (dataBuffer[3 + bodyLen] === 3) {
|
|
1111
1147
|
const frame = dataBuffer.slice(0, expectedFrameSize);
|
|
1112
1148
|
dataBuffer = dataBuffer.slice(expectedFrameSize);
|
|
@@ -1251,6 +1287,56 @@ var require_communication = __commonJS({
|
|
|
1251
1287
|
}
|
|
1252
1288
|
});
|
|
1253
1289
|
|
|
1290
|
+
// package.json
|
|
1291
|
+
var require_package = __commonJS({
|
|
1292
|
+
"package.json"(exports2, module2) {
|
|
1293
|
+
module2.exports = {
|
|
1294
|
+
name: "nets-service-sdk",
|
|
1295
|
+
version: "1.1.18",
|
|
1296
|
+
description: "Utility functions for Nets Service",
|
|
1297
|
+
source: "src/index.js",
|
|
1298
|
+
main: "dist/index.js",
|
|
1299
|
+
module: "dist/index.module.js",
|
|
1300
|
+
unpkg: "dist/index.umd.js",
|
|
1301
|
+
scripts: {
|
|
1302
|
+
build: "esbuild src/index.js --bundle --platform=node --packages=external --outfile=dist/index.js",
|
|
1303
|
+
watch: "microbundle watch",
|
|
1304
|
+
test: 'echo "Error: no test specified" && exit 1'
|
|
1305
|
+
},
|
|
1306
|
+
keywords: [
|
|
1307
|
+
"nets",
|
|
1308
|
+
"payment",
|
|
1309
|
+
"terminal",
|
|
1310
|
+
"pos",
|
|
1311
|
+
"sqlite",
|
|
1312
|
+
"transaction",
|
|
1313
|
+
"serial",
|
|
1314
|
+
"payment-gateway"
|
|
1315
|
+
],
|
|
1316
|
+
author: "dineshhv",
|
|
1317
|
+
license: "ISC",
|
|
1318
|
+
files: [
|
|
1319
|
+
"dist"
|
|
1320
|
+
],
|
|
1321
|
+
dependencies: {
|
|
1322
|
+
"better-sqlite3": "^12.5.0",
|
|
1323
|
+
"dollars-to-cents": "^1.0.3",
|
|
1324
|
+
lodash: "^4.17.21",
|
|
1325
|
+
moment: "^2.29.4",
|
|
1326
|
+
"node-cron": "^4.2.1",
|
|
1327
|
+
request: "^2.88.2",
|
|
1328
|
+
serialport: "^10.5.0",
|
|
1329
|
+
"socket.io-client": "^4.7.2",
|
|
1330
|
+
winston: "^3.8.2"
|
|
1331
|
+
},
|
|
1332
|
+
devDependencies: {
|
|
1333
|
+
esbuild: "^0.27.0",
|
|
1334
|
+
microbundle: "^0.15.1"
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1339
|
+
|
|
1254
1340
|
// src/index.js
|
|
1255
1341
|
var utilsHelper = require_utils_helper();
|
|
1256
1342
|
var winston = require_winston();
|
|
@@ -1262,7 +1348,9 @@ var hexRequest = require_hexRequest();
|
|
|
1262
1348
|
var httpRequest = require_httpRequest();
|
|
1263
1349
|
var parser = require_parser();
|
|
1264
1350
|
var responseHandler = require_responseHandler();
|
|
1351
|
+
var pkg = require_package();
|
|
1265
1352
|
module.exports = {
|
|
1353
|
+
version: pkg.version,
|
|
1266
1354
|
...utilsHelper,
|
|
1267
1355
|
logger: winston,
|
|
1268
1356
|
manageConfig,
|