nets-service-sdk 1.1.16 → 1.1.17
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 +108 -24
- 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));
|
|
@@ -190,7 +183,22 @@ var require_queue = __commonJS({
|
|
|
190
183
|
var require_sendMessage = __commonJS({
|
|
191
184
|
"src/sendMessage.js"(exports2, module2) {
|
|
192
185
|
var logger = require_winston()(module2);
|
|
186
|
+
var path = require("path");
|
|
187
|
+
var fs = require("fs");
|
|
188
|
+
var sdkVersion = "unknown";
|
|
189
|
+
try {
|
|
190
|
+
const pkgPath = path.resolve(__dirname, "../package.json");
|
|
191
|
+
if (fs.existsSync(pkgPath)) {
|
|
192
|
+
const pkg2 = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
193
|
+
sdkVersion = pkg2.version;
|
|
194
|
+
}
|
|
195
|
+
} catch (err) {
|
|
196
|
+
logger.error({ level: "error", message: `Error reading SDK package.json: ${err.message}` });
|
|
197
|
+
}
|
|
193
198
|
module2.exports.sendMessage = (room = "clientRoom", tag, msg) => {
|
|
199
|
+
if (typeof msg === "object" && msg !== null) {
|
|
200
|
+
msg.sdkVersion = sdkVersion;
|
|
201
|
+
}
|
|
194
202
|
logger.log({
|
|
195
203
|
level: "info",
|
|
196
204
|
message: JSON.stringify(msg)
|
|
@@ -898,9 +906,17 @@ var require_responseHandler = __commonJS({
|
|
|
898
906
|
if (!hexValue || hexValue.length < 4) return false;
|
|
899
907
|
const value = hexValue.substring(2, hexValue.length - 2);
|
|
900
908
|
const xor = xorCalculation(value).toUpperCase();
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
|
|
909
|
+
const lrcReceived = hexValue.substring(hexValue.length - 2, hexValue.length).toUpperCase();
|
|
910
|
+
const isMatch = xor === lrcReceived;
|
|
911
|
+
if (!isMatch) {
|
|
912
|
+
logger.error({
|
|
913
|
+
level: "error",
|
|
914
|
+
message: `LRC Mismatch! Calculated: ${xor}, Received: ${lrcReceived}. Checked range (hex): ${value.substring(0, 20)}...${value.substring(value.length - 10)}`
|
|
915
|
+
});
|
|
916
|
+
} else {
|
|
917
|
+
logger.info({ level: "info", message: `LRC Correct: ${xor}` });
|
|
918
|
+
}
|
|
919
|
+
return isMatch;
|
|
904
920
|
};
|
|
905
921
|
}
|
|
906
922
|
});
|
|
@@ -1068,7 +1084,7 @@ var require_communication = __commonJS({
|
|
|
1068
1084
|
};
|
|
1069
1085
|
module2.exports.processIncomingData = () => {
|
|
1070
1086
|
while (dataBuffer.length > 0) {
|
|
1071
|
-
if (dataBuffer[0] === 6 || dataBuffer[0] === 21) {
|
|
1087
|
+
if ((dataBuffer[0] === 6 || dataBuffer[0] === 21) && (dataBuffer.length === 1 || dataBuffer[1] !== 2)) {
|
|
1072
1088
|
const byte = dataBuffer[0];
|
|
1073
1089
|
ackOrNack = Buffer.from([byte]);
|
|
1074
1090
|
dataBuffer = dataBuffer.slice(1);
|
|
@@ -1103,10 +1119,26 @@ var require_communication = __commonJS({
|
|
|
1103
1119
|
}
|
|
1104
1120
|
}
|
|
1105
1121
|
if (dataBuffer.length < 3) break;
|
|
1106
|
-
const
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1109
|
-
|
|
1122
|
+
const bcdLenStr = dataBuffer.slice(1, 3).toString("hex");
|
|
1123
|
+
const bcdLen = parseInt(bcdLenStr, 10);
|
|
1124
|
+
const binLen = dataBuffer.readUInt16BE(1);
|
|
1125
|
+
let bodyLen = bcdLen;
|
|
1126
|
+
let expectedFrameSize = 1 + 2 + bodyLen + 2;
|
|
1127
|
+
if (dataBuffer.length >= expectedFrameSize && dataBuffer[3 + bodyLen] === 3) {
|
|
1128
|
+
} else if (dataBuffer.length >= 1 + 2 + binLen + 2 && dataBuffer[3 + binLen] === 3) {
|
|
1129
|
+
bodyLen = binLen;
|
|
1130
|
+
expectedFrameSize = 1 + 2 + bodyLen + 2;
|
|
1131
|
+
}
|
|
1132
|
+
if (dataBuffer.length < expectedFrameSize) {
|
|
1133
|
+
const etxIndex = dataBuffer.indexOf(3, 3);
|
|
1134
|
+
if (etxIndex !== -1 && dataBuffer.length > etxIndex + 1) {
|
|
1135
|
+
const frame = dataBuffer.slice(0, etxIndex + 2);
|
|
1136
|
+
dataBuffer = dataBuffer.slice(etxIndex + 2);
|
|
1137
|
+
exports2.handleFullMessage(frame);
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
break;
|
|
1141
|
+
}
|
|
1110
1142
|
if (dataBuffer[3 + bodyLen] === 3) {
|
|
1111
1143
|
const frame = dataBuffer.slice(0, expectedFrameSize);
|
|
1112
1144
|
dataBuffer = dataBuffer.slice(expectedFrameSize);
|
|
@@ -1251,6 +1283,56 @@ var require_communication = __commonJS({
|
|
|
1251
1283
|
}
|
|
1252
1284
|
});
|
|
1253
1285
|
|
|
1286
|
+
// package.json
|
|
1287
|
+
var require_package = __commonJS({
|
|
1288
|
+
"package.json"(exports2, module2) {
|
|
1289
|
+
module2.exports = {
|
|
1290
|
+
name: "nets-service-sdk",
|
|
1291
|
+
version: "1.1.17",
|
|
1292
|
+
description: "Utility functions for Nets Service",
|
|
1293
|
+
source: "src/index.js",
|
|
1294
|
+
main: "dist/index.js",
|
|
1295
|
+
module: "dist/index.module.js",
|
|
1296
|
+
unpkg: "dist/index.umd.js",
|
|
1297
|
+
scripts: {
|
|
1298
|
+
build: "esbuild src/index.js --bundle --platform=node --packages=external --outfile=dist/index.js",
|
|
1299
|
+
watch: "microbundle watch",
|
|
1300
|
+
test: 'echo "Error: no test specified" && exit 1'
|
|
1301
|
+
},
|
|
1302
|
+
keywords: [
|
|
1303
|
+
"nets",
|
|
1304
|
+
"payment",
|
|
1305
|
+
"terminal",
|
|
1306
|
+
"pos",
|
|
1307
|
+
"sqlite",
|
|
1308
|
+
"transaction",
|
|
1309
|
+
"serial",
|
|
1310
|
+
"payment-gateway"
|
|
1311
|
+
],
|
|
1312
|
+
author: "dineshhv",
|
|
1313
|
+
license: "ISC",
|
|
1314
|
+
files: [
|
|
1315
|
+
"dist"
|
|
1316
|
+
],
|
|
1317
|
+
dependencies: {
|
|
1318
|
+
"better-sqlite3": "^12.5.0",
|
|
1319
|
+
"dollars-to-cents": "^1.0.3",
|
|
1320
|
+
lodash: "^4.17.21",
|
|
1321
|
+
moment: "^2.29.4",
|
|
1322
|
+
"node-cron": "^4.2.1",
|
|
1323
|
+
request: "^2.88.2",
|
|
1324
|
+
serialport: "^10.5.0",
|
|
1325
|
+
"socket.io-client": "^4.7.2",
|
|
1326
|
+
winston: "^3.8.2"
|
|
1327
|
+
},
|
|
1328
|
+
devDependencies: {
|
|
1329
|
+
esbuild: "^0.27.0",
|
|
1330
|
+
microbundle: "^0.15.1"
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1254
1336
|
// src/index.js
|
|
1255
1337
|
var utilsHelper = require_utils_helper();
|
|
1256
1338
|
var winston = require_winston();
|
|
@@ -1262,7 +1344,9 @@ var hexRequest = require_hexRequest();
|
|
|
1262
1344
|
var httpRequest = require_httpRequest();
|
|
1263
1345
|
var parser = require_parser();
|
|
1264
1346
|
var responseHandler = require_responseHandler();
|
|
1347
|
+
var pkg = require_package();
|
|
1265
1348
|
module.exports = {
|
|
1349
|
+
version: pkg.version,
|
|
1266
1350
|
...utilsHelper,
|
|
1267
1351
|
logger: winston,
|
|
1268
1352
|
manageConfig,
|