iobroker.parcel 0.0.13 → 0.0.14
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/io-package.json +4 -1
- package/main.js +76 -33
- package/package.json +3 -3
package/io-package.json
CHANGED
package/main.js
CHANGED
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
// The adapter-core module gives you access to the core ioBroker functions
|
|
8
8
|
// you need to create an adapter
|
|
9
|
+
|
|
10
|
+
//disable canvas because of missing rebuild
|
|
11
|
+
var Module = require("module");
|
|
12
|
+
var originalRequire = Module.prototype.require;
|
|
13
|
+
Module.prototype.require = function () {
|
|
14
|
+
if (arguments[0] === "canvas") {
|
|
15
|
+
return { createCanvas: null, createImageData: null, loadImage: null };
|
|
16
|
+
}
|
|
17
|
+
return originalRequire.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
|
|
9
20
|
const utils = require("@iobroker/adapter-core");
|
|
10
21
|
const axios = require("axios");
|
|
11
22
|
const qs = require("qs");
|
|
@@ -16,6 +27,8 @@ const { HttpsCookieAgent } = require("http-cookie-agent");
|
|
|
16
27
|
const { JSDOM } = require("@applitools/jsdom");
|
|
17
28
|
const fs = require("fs");
|
|
18
29
|
const { v4: uuidv4 } = require("uuid");
|
|
30
|
+
const { sep } = require("path");
|
|
31
|
+
const { tmpdir } = require("os");
|
|
19
32
|
|
|
20
33
|
class Parcel extends utils.Adapter {
|
|
21
34
|
/**
|
|
@@ -40,6 +53,7 @@ class Parcel extends utils.Adapter {
|
|
|
40
53
|
this.ignoredPath = [];
|
|
41
54
|
this.firstStart = true;
|
|
42
55
|
this.delivery_status = { ERROR: -1, UNKNOWN: 5, REGISTERED: 10, IN_PREPARATION: 20, IN_TRANSIT: 30, OUT_FOR_DELIVERY: 40, DELIVERED: 1 };
|
|
56
|
+
this.tmpDir = tmpdir();
|
|
43
57
|
}
|
|
44
58
|
|
|
45
59
|
/**
|
|
@@ -448,6 +462,7 @@ class Parcel extends utils.Adapter {
|
|
|
448
462
|
return res.data;
|
|
449
463
|
})
|
|
450
464
|
.catch((error) => {
|
|
465
|
+
this.log.error("Amazon login failed");
|
|
451
466
|
this.log.error(error);
|
|
452
467
|
if (error.response) {
|
|
453
468
|
this.log.error(JSON.stringify(error.response.data));
|
|
@@ -919,7 +934,7 @@ class Parcel extends utils.Adapter {
|
|
|
919
934
|
) {
|
|
920
935
|
this.upsAddressToken = res.data.GetEnrollmentsResponse.MYCEnrollmentSummaries.MYCEnrollmentSummary.AddressToken;
|
|
921
936
|
} else {
|
|
922
|
-
this.log.warn("No UPS address found");
|
|
937
|
+
this.log.warn("No UPS address found. Please activate UPS My Choice in the UPS App");
|
|
923
938
|
this.log.info(JSON.stringify(res.data));
|
|
924
939
|
}
|
|
925
940
|
})
|
|
@@ -1102,7 +1117,7 @@ class Parcel extends utils.Adapter {
|
|
|
1102
1117
|
});
|
|
1103
1118
|
}
|
|
1104
1119
|
if (this.sessions["amz"]) {
|
|
1105
|
-
this.getAmazonPackages();
|
|
1120
|
+
await this.getAmazonPackages();
|
|
1106
1121
|
}
|
|
1107
1122
|
const statusArrays = {
|
|
1108
1123
|
dhl: [
|
|
@@ -1319,6 +1334,11 @@ class Parcel extends utils.Adapter {
|
|
|
1319
1334
|
});
|
|
1320
1335
|
}
|
|
1321
1336
|
}
|
|
1337
|
+
this.log.debug("Write states");
|
|
1338
|
+
this.setState("allProviderJson", JSON.stringify(this.mergedJson), true);
|
|
1339
|
+
this.setState("allProviderObjects", JSON.stringify(this.mergedJsonObject), true);
|
|
1340
|
+
this.setState("inDelivery", JSON.stringify(this.inDelivery), true);
|
|
1341
|
+
this.setState("inDeliveryCount", this.inDelivery.length, true);
|
|
1322
1342
|
}
|
|
1323
1343
|
async cleanupProvider(id, data) {
|
|
1324
1344
|
if (id === "dhl" && data.hasOwnProperty("grantToken")) {
|
|
@@ -1426,19 +1446,19 @@ class Parcel extends utils.Adapter {
|
|
|
1426
1446
|
}
|
|
1427
1447
|
|
|
1428
1448
|
if (id === "dpd" && data && data.sendungen) {
|
|
1429
|
-
|
|
1430
|
-
sendung.
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
if (!sendung.delivery_status) {
|
|
1437
|
-
this.log.warn("Missing status for " + JSON.stringify(sendung));
|
|
1449
|
+
const sendungsArray = data.sendungen.map((sendung) => {
|
|
1450
|
+
const sendungsObject = { id: sendung.id, name: sendung.name, status: sendung.status || "", source: "DPD" };
|
|
1451
|
+
|
|
1452
|
+
sendungsObject.delivery_status = this.deliveryStatusCheck(sendung, id, sendungsObject);
|
|
1453
|
+
if (sendungsObject.delivery_status === this.delivery_status.OUT_FOR_DELIVERY) {
|
|
1454
|
+
sendungsObject.inDelivery = true;
|
|
1455
|
+
this.inDelivery.push(sendungsObject);
|
|
1438
1456
|
}
|
|
1439
|
-
this.mergedJsonObject[sendung.id] =
|
|
1440
|
-
|
|
1441
|
-
|
|
1457
|
+
this.mergedJsonObject[sendung.id] = sendungsObject;
|
|
1458
|
+
|
|
1459
|
+
return sendungsObject;
|
|
1460
|
+
});
|
|
1461
|
+
this.mergedJson = this.mergedJson.concat(sendungsArray);
|
|
1442
1462
|
}
|
|
1443
1463
|
if (id === "amz" && data && data.sendungen) {
|
|
1444
1464
|
const sendungsArray = data.sendungen.map((sendung) => {
|
|
@@ -1495,11 +1515,6 @@ class Parcel extends utils.Adapter {
|
|
|
1495
1515
|
this.mergedJson = this.mergedJson.concat(sendungsArray);
|
|
1496
1516
|
}
|
|
1497
1517
|
|
|
1498
|
-
this.setState("allProviderJson", JSON.stringify(this.mergedJson), true);
|
|
1499
|
-
this.setState("allProviderObjects", JSON.stringify(this.mergedJsonObject), true);
|
|
1500
|
-
this.setState("inDelivery", JSON.stringify(this.inDelivery), true);
|
|
1501
|
-
this.setState("inDeliveryCount", this.inDelivery.length, true);
|
|
1502
|
-
|
|
1503
1518
|
if (this.config.sendToActive) {
|
|
1504
1519
|
const sendungen = this.mergedJsonObject;
|
|
1505
1520
|
const ids = Object.keys(sendungen);
|
|
@@ -1517,10 +1532,18 @@ class Parcel extends utils.Adapter {
|
|
|
1517
1532
|
for (const sendInstance of sendInstances) {
|
|
1518
1533
|
if (sendUser.length > 0) {
|
|
1519
1534
|
for (const user of sendUser) {
|
|
1520
|
-
|
|
1535
|
+
if (sendInstance.includes("pushover")) {
|
|
1536
|
+
await this.sendToAsync(sendInstance, { user: user, message: "📦 " + sendungen[id].name + "\n" + sendungen[id].status, title: "Paketstatus" });
|
|
1537
|
+
} else {
|
|
1538
|
+
await this.sendToAsync(sendInstance, { user: user, text: "📦 " + sendungen[id].name + "\n" + sendungen[id].status });
|
|
1539
|
+
}
|
|
1521
1540
|
}
|
|
1522
1541
|
} else {
|
|
1523
|
-
|
|
1542
|
+
if (sendInstance.includes("pushover")) {
|
|
1543
|
+
await this.sendToAsync(sendInstance, { message: "📦 " + sendungen[id].name + "\n" + sendungen[id].status, title: "Paketstatus" });
|
|
1544
|
+
} else {
|
|
1545
|
+
await this.sendToAsync(sendInstance, "📦 " + sendungen[id].name + "\n" + sendungen[id].status);
|
|
1546
|
+
}
|
|
1524
1547
|
}
|
|
1525
1548
|
}
|
|
1526
1549
|
}
|
|
@@ -1589,17 +1612,32 @@ class Parcel extends utils.Adapter {
|
|
|
1589
1612
|
return hermes_status[sendung.lastStatusId];
|
|
1590
1613
|
}
|
|
1591
1614
|
}
|
|
1592
|
-
if (id === "
|
|
1593
|
-
const
|
|
1615
|
+
if (id === "dpd" && sendung.statusId) {
|
|
1616
|
+
const dpd_status = {
|
|
1594
1617
|
0: this.delivery_status.REGISTERED,
|
|
1595
|
-
1: this.delivery_status.
|
|
1596
|
-
2: this.delivery_status.
|
|
1618
|
+
1: this.delivery_status.IN_PREPARATION,
|
|
1619
|
+
2: this.delivery_status.IN_TRANSIT,
|
|
1597
1620
|
3: this.delivery_status.IN_TRANSIT,
|
|
1598
1621
|
4: this.delivery_status.OUT_FOR_DELIVERY,
|
|
1622
|
+
5: this.delivery_status.OUT_FOR_DELIVERY,
|
|
1623
|
+
6: this.delivery_status.DELIVERED,
|
|
1624
|
+
};
|
|
1625
|
+
if (dpd_status[sendung.statusId] !== undefined) {
|
|
1626
|
+
return dpd_status[sendung.statusId];
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
if (id === "gls" && sendung.status) {
|
|
1630
|
+
const gls_status = {
|
|
1631
|
+
PREADVICE: this.delivery_status.REGISTERED,
|
|
1632
|
+
1: this.delivery_status.REGISTERED,
|
|
1633
|
+
INWAREHOUSE: this.delivery_status.IN_TRANSIT,
|
|
1634
|
+
INTRANSIT: this.delivery_status.IN_TRANSIT,
|
|
1635
|
+
INDELIVERY: this.delivery_status.OUT_FOR_DELIVERY,
|
|
1599
1636
|
DELIVERED: this.delivery_status.DELIVERED,
|
|
1637
|
+
DELIVEREDPS: this.delivery_status.DELIVERED,
|
|
1600
1638
|
};
|
|
1601
|
-
if (gls_status[sendung.
|
|
1602
|
-
return gls_status[sendung.
|
|
1639
|
+
if (gls_status[sendung.status] !== undefined) {
|
|
1640
|
+
return gls_status[sendung.status];
|
|
1603
1641
|
}
|
|
1604
1642
|
}
|
|
1605
1643
|
if (id === "amz" && sendung.detailedState && sendung.detailedState.shortStatus) {
|
|
@@ -1624,7 +1662,7 @@ class Parcel extends utils.Adapter {
|
|
|
1624
1662
|
}
|
|
1625
1663
|
}
|
|
1626
1664
|
|
|
1627
|
-
return this.delivery_status
|
|
1665
|
+
return this.delivery_status.UNKNOWN;
|
|
1628
1666
|
} catch (error) {
|
|
1629
1667
|
this.log.error(error);
|
|
1630
1668
|
return this.delivery_status["ERROR"];
|
|
@@ -1666,10 +1704,15 @@ class Parcel extends utils.Adapter {
|
|
|
1666
1704
|
parcelList.querySelectorAll(".btnSelectParcel").forEach((parcel) => {
|
|
1667
1705
|
const parcelInfo = parcel.firstElementChild;
|
|
1668
1706
|
this.log.debug(parcelInfo.textContent);
|
|
1707
|
+
let statusId = parcelInfo.querySelector("img").src;
|
|
1708
|
+
if (statusId) {
|
|
1709
|
+
statusId = statusId.replace("images/status_", "").replace(".svg", "");
|
|
1710
|
+
}
|
|
1669
1711
|
result.sendungen.push({
|
|
1670
1712
|
id: parcelInfo.querySelector(".parcelNo").textContent,
|
|
1671
1713
|
name: parcelInfo.querySelector(".parcelName").textContent,
|
|
1672
1714
|
status: parcelInfo.querySelector(".parcelDeliveryStatus").textContent,
|
|
1715
|
+
statusId: statusId,
|
|
1673
1716
|
});
|
|
1674
1717
|
});
|
|
1675
1718
|
return result;
|
|
@@ -2103,25 +2146,25 @@ class Parcel extends utils.Adapter {
|
|
|
2103
2146
|
return;
|
|
2104
2147
|
}
|
|
2105
2148
|
const uuid = uuidv4();
|
|
2106
|
-
fs.writeFileSync(
|
|
2149
|
+
fs.writeFileSync(`${this.tmpDir}${sep}${uuid}.jpg`, imageBuffer.toString("base64"), "base64");
|
|
2107
2150
|
const sendInstances = this.config.sendToInstance.replace(/ /g, "").split(",");
|
|
2108
2151
|
const sendUser = this.config.sendToUser.replace(/ /g, "").split(",");
|
|
2109
2152
|
|
|
2110
2153
|
for (const sendInstance of sendInstances) {
|
|
2111
2154
|
if (sendInstance.includes("pushover")) {
|
|
2112
|
-
await this.sendToAsync(sendInstance, { file:
|
|
2155
|
+
await this.sendToAsync(sendInstance, { file: `${this.tmpDir}${sep}${uuid}.jpg`, title: "✉️Briefankündigung" });
|
|
2113
2156
|
} else {
|
|
2114
2157
|
if (sendUser.length > 0) {
|
|
2115
2158
|
for (const user of sendUser) {
|
|
2116
2159
|
await this.sendToAsync(sendInstance, { user: user, text: "✉️Briefankündigung" });
|
|
2117
|
-
await this.sendToAsync(sendInstance, { user: user, text:
|
|
2160
|
+
await this.sendToAsync(sendInstance, { user: user, text: `${this.tmpDir}${sep}${uuid}.jpg` });
|
|
2118
2161
|
}
|
|
2119
2162
|
} else {
|
|
2120
2163
|
await this.sendToAsync(sendInstance, "✉️Briefankündigung");
|
|
2121
|
-
await this.sendToAsync(sendInstance,
|
|
2164
|
+
await this.sendToAsync(sendInstance, `${this.tmpDir}${sep}${uuid}.jpg`);
|
|
2122
2165
|
}
|
|
2123
2166
|
}
|
|
2124
|
-
fs.unlinkSync(
|
|
2167
|
+
fs.unlinkSync(`${this.tmpDir}${sep}${uuid}.jpg`);
|
|
2125
2168
|
}
|
|
2126
2169
|
}
|
|
2127
2170
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.parcel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Parcel tracking",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TA2k",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"url": "https://github.com/TA2k/ioBroker.parcel"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@applitools/jsdom": "^1.0.4",
|
|
29
28
|
"@iobroker/adapter-core": "^2.6.0",
|
|
30
29
|
"axios": "^0.25.0",
|
|
31
30
|
"http-cookie-agent": "^1.0.5",
|
|
31
|
+
"jsdom": "^19.0.0",
|
|
32
32
|
"json-bigint": "^1.0.0",
|
|
33
33
|
"qs": "^6.10.3",
|
|
34
34
|
"tough-cookie": "^4.0.0",
|
|
@@ -76,4 +76,4 @@
|
|
|
76
76
|
"url": "https://github.com/TA2k/ioBroker.parcel/issues"
|
|
77
77
|
},
|
|
78
78
|
"readmeFilename": "README.md"
|
|
79
|
-
}
|
|
79
|
+
}
|