iobroker.parcel 0.2.1 → 0.2.2

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.
Files changed (3) hide show
  1. package/io-package.json +8 -1
  2. package/main.js +97 -57
  3. package/package.json +3 -3
package/io-package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "parcel",
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "news": {
6
+ "0.2.2": {
7
+ "en": "Improvment for Amazon Login and fix for Briefaanündigung Image",
8
+ "de": "Verbesserung für Amazon Login und Fix für Briefankündigung Image State"
9
+ },
6
10
  "0.2.1": {
7
11
  "en": "Fix for Briefankündigung",
8
12
  "de": "Briefankündigung wieder aktiviert"
@@ -166,6 +170,9 @@
166
170
  "native": {
167
171
  "amzusername": "",
168
172
  "amzpassword": "",
173
+ "aliUsername": "",
174
+ "aliPassword": "",
175
+ "aliMfa": "",
169
176
  "glsusername": "",
170
177
  "glspassword": "",
171
178
  "upsusername": "",
package/main.js CHANGED
@@ -18,7 +18,7 @@ Module.prototype.require = function () {
18
18
  };
19
19
 
20
20
  const utils = require('@iobroker/adapter-core');
21
- const axios = require('axios');
21
+ const axios = require('axios').default;
22
22
  const qs = require('qs');
23
23
  const crypto = require('crypto');
24
24
  const Json2iob = require('json2iob');
@@ -64,6 +64,7 @@ class Parcel extends utils.Adapter {
64
64
  DELIVERED: 1,
65
65
  };
66
66
  this.tmpDir = tmpdir();
67
+ this.requestClient = axios.create();
67
68
  }
68
69
 
69
70
  /**
@@ -403,6 +404,10 @@ class Parcel extends utils.Adapter {
403
404
  this.log.error(JSON.stringify(error.response.data));
404
405
  }
405
406
  });
407
+ if (!codeUrl) {
408
+ this.log.error('DHL codeUrl failed');
409
+ return;
410
+ }
406
411
  await this.requestClient({
407
412
  method: 'post',
408
413
  url: 'https://login.dhl.de/af5f9bb6-27ad-4af4-9445-008e7a5cddb8/login/token',
@@ -451,8 +456,6 @@ class Parcel extends utils.Adapter {
451
456
  'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
452
457
  'accept-language': 'de-de',
453
458
  },
454
- jar: this.cookieJar,
455
- withCredentials: true,
456
459
  })
457
460
  .then(async (res) => {
458
461
  this.log.debug(JSON.stringify(res.data));
@@ -482,8 +485,6 @@ class Parcel extends utils.Adapter {
482
485
  force: false,
483
486
  meta: '',
484
487
  }),
485
- jar: this.cookieJar,
486
- withCredentials: true,
487
488
  })
488
489
  .then(async (res) => {
489
490
  this.log.debug(JSON.stringify(res.data));
@@ -620,8 +621,6 @@ class Parcel extends utils.Adapter {
620
621
  referer: 'https://login.aliexpress.com/',
621
622
  'accept-language': 'de',
622
623
  },
623
- jar: this.cookieJar,
624
- withCredentials: true,
625
624
  })
626
625
  .then(async (res) => {
627
626
  this.log.debug(JSON.stringify(res.data));
@@ -699,6 +698,7 @@ class Parcel extends utils.Adapter {
699
698
  } else {
700
699
  this.log.info('Login to AliExpress with MFA token');
701
700
  this.log.debug('MFA: ' + this.config.dhlMfa);
701
+ const mfaToken = '';
702
702
  await this.requestClient({
703
703
  method: 'post',
704
704
  url: 'https://www.dhl.de/int-erkennen/2fa',
@@ -775,8 +775,6 @@ class Parcel extends utils.Adapter {
775
775
  'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
776
776
  'accept-language': 'de-de',
777
777
  },
778
- jar: this.cookieJar,
779
- withCredentials: true,
780
778
  })
781
779
  .then(async (res) => {
782
780
  this.log.debug(JSON.stringify(res.data));
@@ -807,8 +805,6 @@ class Parcel extends utils.Adapter {
807
805
  referer: 'https://www.amazon.de/ap/signin',
808
806
  },
809
807
  data: qs.stringify(form),
810
- jar: this.cookieJar,
811
- withCredentials: true,
812
808
  })
813
809
  .then(async (res) => {
814
810
  this.log.debug(JSON.stringify(res.data));
@@ -841,13 +837,11 @@ class Parcel extends utils.Adapter {
841
837
  referer: 'https://www.amazon.de/ap/signin',
842
838
  },
843
839
  data: qs.stringify(form),
844
- jar: this.cookieJar,
845
- withCredentials: true,
846
840
  })
847
841
  .then(async (res) => {
848
842
  this.log.debug(JSON.stringify(res.data));
849
843
  if (res.data.indexOf('js-yo-main-content') !== -1) {
850
- this.log.info('Login to Amazon successful');
844
+ this.log.info('Relogin to Amazon successful');
851
845
  this.sessions['amz'] = true;
852
846
  this.setState('info.connection', true, true);
853
847
  this.setState('auth.cookie', JSON.stringify(this.cookieJar.toJSON()), true);
@@ -872,8 +866,6 @@ class Parcel extends utils.Adapter {
872
866
  referer: 'https://www.amazon.de/ap/signin',
873
867
  },
874
868
  data: qs.stringify(form),
875
- jar: this.cookieJar,
876
- withCredentials: true,
877
869
  })
878
870
  .then(async (res) => {
879
871
  this.log.debug(JSON.stringify(res.data));
@@ -943,8 +935,6 @@ class Parcel extends utils.Adapter {
943
935
  await this.requestClient({
944
936
  method: 'get',
945
937
  url: 'https://my.dpd.de/logout.aspx',
946
- jar: this.cookieJar,
947
- withCredentials: true,
948
938
  }).catch(async (error) => {
949
939
  error.response && this.log.error(JSON.stringify(error.response.data));
950
940
  this.log.error(error);
@@ -964,8 +954,6 @@ class Parcel extends utils.Adapter {
964
954
  dpg_username: this.config.dpdusername,
965
955
  dpg_password: this.config.dpdpassword,
966
956
  }),
967
- jar: this.cookieJar,
968
- withCredentials: true,
969
957
  maxRedirects: 0,
970
958
  })
971
959
  .then(async (res) => {
@@ -1010,8 +998,6 @@ class Parcel extends utils.Adapter {
1010
998
  await this.requestClient({
1011
999
  method: 'get',
1012
1000
  url: 'https://my.dpd.de/myParcel.aspx?dpd_token=' + this.dpdToken,
1013
- jar: this.cookieJar,
1014
- withCredentials: true,
1015
1001
  }).catch(async (error) => {
1016
1002
  error.response && this.log.error(JSON.stringify(error.response.data));
1017
1003
  this.log.error(error);
@@ -1037,8 +1023,6 @@ class Parcel extends utils.Adapter {
1037
1023
  username: this.config.glsusername,
1038
1024
  password: this.config.glspassword,
1039
1025
  }),
1040
- jar: this.cookieJar,
1041
- withCredentials: true,
1042
1026
  })
1043
1027
  .then(async (res) => {
1044
1028
  this.sessions['gls'] = res.data;
@@ -1066,8 +1050,6 @@ class Parcel extends utils.Adapter {
1066
1050
  'X-Client-Id': 'iOS',
1067
1051
  'X-Auth-Token': this.glstoken,
1068
1052
  },
1069
- jar: this.cookieJar,
1070
- withCredentials: true,
1071
1053
  })
1072
1054
  .then(async (res) => {
1073
1055
  !silent && this.log.info('Login to GLS successful');
@@ -1110,9 +1092,6 @@ class Parcel extends utils.Adapter {
1110
1092
  'accept-language': 'de-de',
1111
1093
  },
1112
1094
  data: { username: this.config.hermesusername, password: this.config.hermespassword },
1113
-
1114
- jar: this.cookieJar,
1115
- withCredentials: true,
1116
1095
  })
1117
1096
  .then(async (res) => {
1118
1097
  this.log.debug(JSON.stringify(res.data));
@@ -1178,8 +1157,6 @@ class Parcel extends utils.Adapter {
1178
1157
  IsMobile: 'true',
1179
1158
  },
1180
1159
  }),
1181
- jar: this.cookieJar,
1182
- withCredentials: true,
1183
1160
  })
1184
1161
  .then(async (res) => {
1185
1162
  this.log.debug(JSON.stringify(res.data));
@@ -1259,8 +1236,6 @@ class Parcel extends utils.Adapter {
1259
1236
  },
1260
1237
  },
1261
1238
  }),
1262
- jar: this.cookieJar,
1263
- withCredentials: true,
1264
1239
  })
1265
1240
  .then(async (res) => {
1266
1241
  this.log.debug(JSON.stringify(res.data));
@@ -1357,8 +1332,6 @@ class Parcel extends utils.Adapter {
1357
1332
  '","Password":"' +
1358
1333
  this.config.t17password +
1359
1334
  '","CaptchaCode":""},"sourcetype":0,"timeZoneOffset":-60}',
1360
- jar: this.cookieJar,
1361
- withCredentials: true,
1362
1335
  })
1363
1336
  .then(async (res) => {
1364
1337
  this.log.debug(JSON.stringify(res.data));
@@ -1695,17 +1668,17 @@ class Parcel extends utils.Adapter {
1695
1668
  async cleanupProvider(id, data) {
1696
1669
  if (id === 'dhl' && data.hasOwnProperty('grantToken')) {
1697
1670
  await this.delObjectAsync('dhl.briefe', { recursive: true });
1698
- // await this.setObjectNotExistsAsync("dhl.briefe.json", {
1699
- // type: "state",
1700
- // common: {
1701
- // name: "Json Briefe",
1702
- // write: false,
1703
- // read: true,
1704
- // type: "string",
1705
- // role: "json",
1706
- // },
1707
- // native: {},
1708
- // });
1671
+ await this.setObjectNotExistsAsync('dhl.briefe.json', {
1672
+ type: 'state',
1673
+ common: {
1674
+ name: 'Json Briefe',
1675
+ write: false,
1676
+ read: true,
1677
+ type: 'string',
1678
+ role: 'json',
1679
+ },
1680
+ native: {},
1681
+ });
1709
1682
  }
1710
1683
  if ((id === 'dhl' || id === 'dpd' || id === 'amz' || id === 'gls' || id === 'ups' || id === 'hermes') && data && data.sendungen) {
1711
1684
  const states = await this.getStatesAsync(id + '.sendungen*.id');
@@ -1738,6 +1711,9 @@ class Parcel extends utils.Adapter {
1738
1711
  if (sendung.sendungsdetails && sendung.sendungsdetails.liveTrackingVerfuegbar && sendung.sendungsdetails.liveTracking) {
1739
1712
  status = status + ' ' + sendung.sendungsdetails.liveTracking.countdown + ' Stopps';
1740
1713
  }
1714
+ if (status === '') {
1715
+ return;
1716
+ }
1741
1717
  const name = sendung.sendungsinfo.sendungsname || 'Unbekannt';
1742
1718
 
1743
1719
  const sendungsObject = { id: sendung.id, name: name, status: status, source: 'DHL' };
@@ -2135,6 +2111,7 @@ class Parcel extends utils.Adapter {
2135
2111
  this.log.debug('Get Amazon Packages');
2136
2112
  const amzResult = { sendungen: [] };
2137
2113
 
2114
+ await this.loginAmz();
2138
2115
  let orders = await this.getAmazonOrders();
2139
2116
  if (!orders) {
2140
2117
  orders = await this.getAmazonOrders();
@@ -2152,13 +2129,38 @@ class Parcel extends utils.Adapter {
2152
2129
  order.url = 'https://www.amazon.de' + order.url;
2153
2130
  }
2154
2131
  this.log.debug(order.url);
2155
- order.url = order.url + '&disableCsd=missing-library';
2132
+ order.url = order.url + '';
2156
2133
  const element = await this.requestClient({
2157
2134
  method: 'get',
2158
2135
  url: order.url,
2159
2136
  headers: {
2160
- accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
2161
- 'accept-language': 'de-de',
2137
+ authority: 'www.amazon.de',
2138
+ accept:
2139
+ 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
2140
+ 'accept-language': 'de,en;q=0.9,es;q=0.8,hi;q=0.7,kn;q=0.6',
2141
+ 'cache-control': 'no-cache',
2142
+ 'device-memory': '8',
2143
+ downlink: '2',
2144
+ dpr: '2',
2145
+ ect: '4g',
2146
+ pragma: 'no-cache',
2147
+ referer: 'https://www.amazon.de/gp/css/order-history?ref_=nav_orders_first',
2148
+ rtt: '50',
2149
+ 'sec-ch-device-memory': '8',
2150
+ 'sec-ch-dpr': '2',
2151
+ 'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
2152
+ 'sec-ch-ua-mobile': '?0',
2153
+ 'sec-ch-ua-platform': '"macOS"',
2154
+ 'sec-ch-ua-platform-version': '"14.1.1"',
2155
+ 'sec-ch-viewport-width': '1264',
2156
+ 'sec-fetch-dest': 'document',
2157
+ 'sec-fetch-mode': 'navigate',
2158
+ 'sec-fetch-site': 'same-origin',
2159
+ 'sec-fetch-user': '?1',
2160
+ 'upgrade-insecure-requests': '1',
2161
+ 'user-agent':
2162
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
2163
+ 'viewport-width': '1264',
2162
2164
  },
2163
2165
  })
2164
2166
  .then(async (res) => {
@@ -2209,6 +2211,18 @@ class Parcel extends utils.Adapter {
2209
2211
  if (!status) {
2210
2212
  status = stateObject.promise?.promiseMessage;
2211
2213
  }
2214
+ if (!status) {
2215
+ const shippingInfo = document.querySelector('.js-shipment-info-container');
2216
+ if (shippingInfo) {
2217
+ status = shippingInfo.textContent.replace(/\n */g, '');
2218
+ }
2219
+ }
2220
+ if (!status) {
2221
+ const returnInfo = document.querySelector('.a-alert-container .a-text-bold');
2222
+ if (returnInfo) {
2223
+ status = returnInfo.textContent.replace(/\n */g, '');
2224
+ }
2225
+ }
2212
2226
  if (!additionalStatus) {
2213
2227
  additionalStatus = stateObject.promise?.pdwHelpIconMessage;
2214
2228
  }
@@ -2226,7 +2240,11 @@ class Parcel extends utils.Adapter {
2226
2240
  if (stopsStatus) {
2227
2241
  status = status + '. ' + stopsStatus;
2228
2242
  }
2229
-
2243
+ if (!status) {
2244
+ this.log.info('No status found for ' + order.url);
2245
+ this.log.debug(res.data);
2246
+ return;
2247
+ }
2230
2248
  return {
2231
2249
  id: document.querySelector('.pt-delivery-card-trackingId')
2232
2250
  ? document.querySelector('.pt-delivery-card-trackingId').textContent.replace('Trackingnummer ', '')
@@ -2268,16 +2286,35 @@ class Parcel extends utils.Adapter {
2268
2286
  async getAmazonOrders() {
2269
2287
  return await this.requestClient({
2270
2288
  method: 'get',
2271
- url: 'https://www.amazon.de/gp/css/order-history?ref_=nav_orders_first&disableCsd=missing-library',
2289
+ url: 'https://www.amazon.de/gp/css/order-history?ref_=nav_orders_first',
2272
2290
  headers: {
2273
2291
  authority: 'www.amazon.de',
2292
+ Connection: 'keep-alive',
2293
+ 'Cache-Control': 'no-cache',
2274
2294
  accept:
2275
2295
  'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
2276
2296
  'accept-language': 'de-de',
2277
- 'cache-control': 'max-age=0',
2278
- 'user-agent':
2279
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
2280
- 'viewport-width': '1272',
2297
+ Pragma: 'no-cache',
2298
+ 'Sec-Fetch-Dest': 'document',
2299
+ 'Sec-Fetch-Mode': 'navigate',
2300
+ 'Sec-Fetch-Site': 'none',
2301
+ 'Sec-Fetch-User': '?1',
2302
+ 'Upgrade-Insecure-Requests': '1',
2303
+ 'User-Agent':
2304
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
2305
+ 'device-memory': '8',
2306
+ downlink: '10',
2307
+ dpr: '2',
2308
+ ect: '4g',
2309
+ rtt: '50',
2310
+ 'sec-ch-device-memory': '8',
2311
+ 'sec-ch-dpr': '2',
2312
+ 'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
2313
+ 'sec-ch-ua-mobile': '?0',
2314
+ 'sec-ch-ua-platform': '"macOS"',
2315
+ 'sec-ch-ua-platform-version': '"14.1.1"',
2316
+ 'sec-ch-viewport-width': '1264',
2317
+ 'viewport-width': '1264',
2281
2318
  },
2282
2319
  })
2283
2320
  .then(async (res) => {
@@ -2286,6 +2323,8 @@ class Parcel extends utils.Adapter {
2286
2323
 
2287
2324
  if (res.data.includes('auth-workflow')) {
2288
2325
  this.log.debug('Amazon Login required');
2326
+
2327
+ this.log.debug(res.data);
2289
2328
  await this.loginAmz();
2290
2329
  return;
2291
2330
  }
@@ -2581,8 +2620,7 @@ class Parcel extends utils.Adapter {
2581
2620
  await this.requestClient({
2582
2621
  method: 'post',
2583
2622
  url: 'https://buyer.17track.net/orderapi/call',
2584
- header: { 'content-type': 'application/x-www-form-urlencoded' },
2585
-
2623
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
2586
2624
  data: JSON.stringify({
2587
2625
  version: '1.0',
2588
2626
  timeZoneOffset: -60,
@@ -2702,6 +2740,8 @@ class Parcel extends utils.Adapter {
2702
2740
  this.log.error(error);
2703
2741
  }
2704
2742
  }
2743
+ } else {
2744
+ this.setState(id.replace('image_url', 'image'), imageBase64, true);
2705
2745
  }
2706
2746
  }
2707
2747
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.parcel",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Parcel tracking",
5
5
  "author": {
6
6
  "name": "TA2k",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@iobroker/adapter-core": "^3.0.4",
29
- "axios": "^1.6.0",
29
+ "axios": "^1.6.2",
30
30
  "http-cookie-agent": "^5.0.4",
31
31
  "jsdom": "^21.1.2",
32
32
  "json2iob": "^2.4.8",
@@ -39,7 +39,7 @@
39
39
  "@types/chai": "^4.3.10",
40
40
  "@types/chai-as-promised": "^7.1.8",
41
41
  "@types/mocha": "^10.0.4",
42
- "@types/node": "^20.9.0",
42
+ "@types/node": "^20.9.1",
43
43
  "@types/proxyquire": "^1.3.31",
44
44
  "@types/sinon": "^10.0.20",
45
45
  "@types/sinon-chai": "^3.2.12",