iobroker.parcel 0.1.5 → 0.2.0

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 CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "parcel",
4
- "version": "0.1.5",
4
+ "version": "0.2.0",
5
5
  "news": {
6
+ "0.2.0": {
7
+ "en": "Fix for Briefankündigung",
8
+ "de": "Briefankündigung wieder aktiviert"
9
+ },
10
+ "0.1.6": {
11
+ "en": "Fix DHL and UPS",
12
+ "de": "DHL und UPS gefixt"
13
+ },
6
14
  "0.1.5": {
7
15
  "en": "Improve failed Amazon Login",
8
16
  "de": "Verbesserter Amazon Login im Fehlerfall"
@@ -0,0 +1,63 @@
1
+ const crypto = require('crypto');
2
+ const axios = require('axios').default;
3
+ function getUuidFromUrl(url) {
4
+ return (url = (url = url.split('/').pop()).includes('?') ? url.split('?')[0] : url), new TextEncoder().encode(url);
5
+ }
6
+ function getKeySet(keyArray) {
7
+ return {
8
+ secretKey: keyArray.subarray(0, 32),
9
+ iv: keyArray.subarray(32, 44),
10
+ aad: keyArray.subarray(44, 56),
11
+ };
12
+ }
13
+
14
+ async function decryptAdviceWebCrypto(url, requestClient) {
15
+ const decryptImage = await requestClient(url, {
16
+ withCredentials: true,
17
+ method: 'GET',
18
+ responseType: 'arraybuffer',
19
+ })
20
+ .then(async function (response) {
21
+ const uuid = getUuidFromUrl(url);
22
+ return await crypto.subtle
23
+ .digest('SHA-512', uuid)
24
+ .then(function (hashedUuid) {
25
+ return getKeySet(new Uint8Array(hashedUuid));
26
+ })
27
+ .then(async function (keySet) {
28
+ const data = response.data;
29
+ const secretKey = keySet.secretKey;
30
+ return await crypto.subtle
31
+ .importKey('raw', secretKey, 'AES-GCM', false, ['decrypt'])
32
+ .then(async function (importedKey) {
33
+ const decryptionParams = {
34
+ name: 'AES-GCM',
35
+ iv: keySet.iv,
36
+ additionalData: keySet.aad,
37
+ };
38
+ return await crypto.subtle
39
+ .decrypt(decryptionParams, importedKey, data)
40
+ .then(function (decryptedData) {
41
+ return decryptedData;
42
+ // return URL.createObjectURL(new Blob([decryptedData]));
43
+ })
44
+ .catch(function (error) {
45
+ throw error;
46
+ });
47
+ })
48
+ .catch(function (error) {
49
+ throw error;
50
+ });
51
+ })
52
+
53
+ .catch(function (error) {
54
+ throw error;
55
+ });
56
+ })
57
+ .catch(function (error) {
58
+ throw error;
59
+ });
60
+ return decryptImage;
61
+ }
62
+
63
+ module.exports = decryptAdviceWebCrypto;
package/main.js CHANGED
@@ -31,6 +31,7 @@ const { v4: uuidv4 } = require('uuid');
31
31
  const { sep } = require('path');
32
32
  const { tmpdir } = require('os');
33
33
 
34
+ const dhlDecrypt = require('./lib/dhldecrypt');
34
35
  class Parcel extends utils.Adapter {
35
36
  /**
36
37
  * @param {Partial<utils.AdapterOptions>} [options={}]
@@ -180,8 +181,7 @@ class Parcel extends utils.Adapter {
180
181
  url: 'https://login.dhl.de/af5f9bb6-27ad-4af4-9445-008e7a5cddb8/login/authorize',
181
182
  params: {
182
183
  redirect_uri: 'dhllogin://de.deutschepost.dhl/login',
183
- state:
184
- 'eyJycyI6dHJ1ZSwicnYiOmZhbHNlLCJmaWQiOiJhcHAtbG9naW4tbWVoci1mb290ZXIiLCJoaWQiOiJhcHAtbG9naW4tbWVoci1oZWFkZXIiLCJycCI6ZmFsc2V9',
184
+ state: 'eyJycyI6dHJ1ZSwicnYiOmZhbHNlLCJmaWQiOiJhcHAtbG9naW4tbWVoci1mb290ZXIiLCJoaWQiOiJhcHAtbG9naW4tbWVoci1oZWFkZXIiLCJycCI6ZmFsc2V9',
185
185
  client_id: '83471082-5c13-4fce-8dcb-19d2a3fca413',
186
186
  response_type: 'code',
187
187
  scope: 'openid offline_access',
@@ -301,8 +301,7 @@ class Parcel extends utils.Adapter {
301
301
  redirect_uri: 'dhllogin://de.deutschepost.dhl/login',
302
302
  response_type: 'code',
303
303
  scope: 'openid',
304
- state:
305
- 'eyJycyI6dHJ1ZSwicnYiOmZhbHNlLCJmaWQiOiJhcHAtbG9naW4tbWVoci1mb290ZXIiLCJoaWQiOiJhcHAtbG9naW4tbWVoci1oZWFkZXIiLCJycCI6ZmFsc2V9',
304
+ state: 'eyJycyI6dHJ1ZSwicnYiOmZhbHNlLCJmaWQiOiJhcHAtbG9naW4tbWVoci1mb290ZXIiLCJoaWQiOiJhcHAtbG9naW4tbWVoci1oZWFkZXIiLCJycCI6ZmFsc2V9',
306
305
  ui_locales: 'de-DE",',
307
306
  },
308
307
  headers: {
@@ -350,8 +349,7 @@ class Parcel extends utils.Adapter {
350
349
  redirect_uri: 'dhllogin://de.deutschepost.dhl/login',
351
350
  response_type: 'code',
352
351
  scope: 'openid',
353
- state:
354
- 'eyJycyI6dHJ1ZSwicnYiOmZhbHNlLCJmaWQiOiJhcHAtbG9naW4tbWVoci1mb290ZXIiLCJoaWQiOiJhcHAtbG9naW4tbWVoci1oZWFkZXIiLCJycCI6ZmFsc2V9',
352
+ state: 'eyJycyI6dHJ1ZSwicnYiOmZhbHNlLCJmaWQiOiJhcHAtbG9naW4tbWVoci1mb290ZXIiLCJoaWQiOiJhcHAtbG9naW4tbWVoci1oZWFkZXIiLCJycCI6ZmFsc2V9',
355
353
  ui_locales: 'de-DE',
356
354
  },
357
355
  headers: {
@@ -609,8 +607,7 @@ class Parcel extends utils.Adapter {
609
607
  'sec-ch-ua-mobile': '?0',
610
608
  'sec-ch-ua-platform': '"macOS"',
611
609
  'upgrade-insecure-requests': '1',
612
- 'user-agent':
613
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.20 Safari/537.36',
610
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.20 Safari/537.36',
614
611
  accept:
615
612
  '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.9',
616
613
  'sec-fetch-site': 'same-site',
@@ -656,8 +653,7 @@ class Parcel extends utils.Adapter {
656
653
  accept: 'application/json, text/plain, */*',
657
654
  'content-type': 'application/x-www-form-urlencoded',
658
655
  'sec-ch-ua-mobile': '?0',
659
- 'user-agent':
660
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.20 Safari/537.36',
656
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.20 Safari/537.36',
661
657
  'sec-ch-ua-platform': '"macOS"',
662
658
  origin: 'https://login.aliexpress.com',
663
659
  'sec-fetch-site': 'same-site',
@@ -687,9 +683,7 @@ class Parcel extends utils.Adapter {
687
683
  })
688
684
  .then(async (res) => {
689
685
  // this.log.debug(JSON.stringify(res.data));
690
- res.data.indexOf('Session has expired') !== -1
691
- ? this.log.error('Session has expired')
692
- : this.log.info('Login to Aliexpress successful');
686
+ res.data.indexOf('Session has expired') !== -1 ? this.log.error('Session has expired') : this.log.info('Login to Aliexpress successful');
693
687
  })
694
688
  .catch(async (error) => {
695
689
  error.response && this.log.error(JSON.stringify(error.response.data));
@@ -784,7 +778,7 @@ class Parcel extends utils.Adapter {
784
778
  .catch((error) => {
785
779
  this.log.error('Amazon first login step failed');
786
780
  this.log.error(
787
- 'https://www.amazon.de/ap/signin?_encoding=UTF8&accountStatusPolicy=P1&openid.assoc_handle=deflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.de%2Fgp%2Fcss%2Forder-history%3Fie%3DUTF8%26ref_%3Dnav_orders_first&pageId=webcs-yourorder&showRmrMe=1',
781
+ 'https://www.amazon.de/ap/signin?_encoding=UTF8&accountStatusPolicy=P1&openid.assoc_handle=deflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.de%2Fgp%2Fcss%2Forder-history%3Fie%3DUTF8%26ref_%3Dnav_orders_first&pageId=webcs-yourorder&showRmrMe=1'
788
782
  );
789
783
  this.log.error(error);
790
784
  if (error.response) {
@@ -820,7 +814,7 @@ class Parcel extends utils.Adapter {
820
814
  this.log.error(JSON.stringify(error.response.data));
821
815
  }
822
816
  this.log.info(
823
- 'Delete amazon cookie please restart the adapter to trigger relogin. If this is not working please manualy delete parcel.0.auth.cookie',
817
+ 'Delete amazon cookie please restart the adapter to trigger relogin. If this is not working please manualy delete parcel.0.auth.cookie'
824
818
  );
825
819
  delete this.cookieJar.store.idx['amazon.de'];
826
820
  });
@@ -908,11 +902,11 @@ class Parcel extends utils.Adapter {
908
902
  this.log.error('Login to Amazon failed, please login to Amazon manually and check the login');
909
903
  if (res.data.indexOf('captcha-placeholder') !== -1) {
910
904
  this.log.warn(
911
- 'Captcha required. Please login into your account to check the state of the account. If this is not wokring please pause the adapter for 24h.',
905
+ 'Captcha required. Please login into your account to check the state of the account. If this is not wokring please pause the adapter for 24h.'
912
906
  );
913
907
  }
914
908
  this.log.info(
915
- 'Amazon cookie are removed. Please restart the adapter to trigger a relogin. If this is not working please manually delete parcel.0.auth.cookie',
909
+ 'Amazon cookie are removed. Please restart the adapter to trigger a relogin. If this is not working please manually delete parcel.0.auth.cookie'
916
910
  );
917
911
  delete this.cookieJar.store.idx['amazon.de'];
918
912
  this.log.info('Start relogin');
@@ -953,8 +947,7 @@ class Parcel extends utils.Adapter {
953
947
  url: 'https://www.dpd.com/de/de/mydpd-anmelden-und-registrieren/',
954
948
  headers: {
955
949
  'content-type': 'application/x-www-form-urlencoded',
956
- 'user-agent':
957
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.66 Safari/537.36',
950
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.66 Safari/537.36',
958
951
  accept:
959
952
  '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.9',
960
953
  'accept-language': 'de,en;q=0.9',
@@ -1166,7 +1159,7 @@ class Parcel extends utils.Adapter {
1166
1159
  UPSSecurity: {
1167
1160
  UsernameToken: {},
1168
1161
  ServiceAccessToken: {
1169
- AccessLicenseNumber: '2DBACFA7974B3252',
1162
+ AccessLicenseNumber: '3DE112BAD1F163E0',
1170
1163
  },
1171
1164
  },
1172
1165
  LoginSubmitUserIdRequest: {
@@ -1214,6 +1207,9 @@ class Parcel extends utils.Adapter {
1214
1207
  } else {
1215
1208
  this.log.warn('Login to UPS failed');
1216
1209
  this.log.info(JSON.stringify(res.data));
1210
+ if (JSON.stringify(res.data).includes('Legal Agreement Required')) {
1211
+ this.log.warn('Please login into UPS and accept the Legal Agreement');
1212
+ }
1217
1213
  }
1218
1214
 
1219
1215
  return;
@@ -1430,10 +1426,12 @@ class Parcel extends utils.Adapter {
1430
1426
  dataDhl = await this.requestClient({
1431
1427
  method: 'get',
1432
1428
  url: 'https://www.dhl.de/int-verfolgen/data/search?noRedirect=true&language=de&cid=app',
1433
- accept: 'application/json',
1434
- 'content-type': 'application/json',
1435
- 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
1436
- 'accept-language': 'de-de',
1429
+ headers: {
1430
+ accept: 'application/json',
1431
+ 'content-type': 'application/json',
1432
+ 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
1433
+ 'accept-language': 'de-de',
1434
+ },
1437
1435
  })
1438
1436
 
1439
1437
  .then(async (res) => {
@@ -2269,8 +2267,7 @@ class Parcel extends utils.Adapter {
2269
2267
  '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',
2270
2268
  'accept-language': 'de-de',
2271
2269
  'cache-control': 'max-age=0',
2272
- 'user-agent':
2273
- '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',
2270
+ 'user-agent': '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',
2274
2271
  'viewport-width': '1272',
2275
2272
  },
2276
2273
  })
@@ -2289,12 +2286,10 @@ class Parcel extends utils.Adapter {
2289
2286
 
2290
2287
  for (const order of orders) {
2291
2288
  const descHandle = order.querySelector(
2292
- '.a-fixed-right-grid-col.a-col-left .a-fixed-left-grid-col.a-col-right div:first-child .a-link-normal',
2289
+ '.a-fixed-right-grid-col.a-col-left .a-fixed-left-grid-col.a-col-right div:first-child .a-link-normal'
2293
2290
  );
2294
2291
  const desc = descHandle ? descHandle.textContent.replace(/\n */g, '') : '';
2295
- let url = order.querySelector('.track-package-button a')
2296
- ? order.querySelector('.track-package-button a').getAttribute('href')
2297
- : '';
2292
+ let url = order.querySelector('.track-package-button a') ? order.querySelector('.track-package-button a').getAttribute('href') : '';
2298
2293
  if (!url) {
2299
2294
  const allLinks = order.querySelectorAll('.a-button-inner a');
2300
2295
  for (const link of allLinks) {
@@ -2599,11 +2594,18 @@ class Parcel extends utils.Adapter {
2599
2594
  if (id.indexOf('dhl.briefe') !== -1 && id.indexOf('image_url') !== -1 && id.indexOf('oldAdvices') === -1) {
2600
2595
  let imageBase64 = this.images[state.val];
2601
2596
  if (!imageBase64) {
2602
- const image = await this.requestClient({
2603
- method: 'get',
2604
- url: state.val,
2605
- responseType: 'arraybuffer',
2606
- }).catch((error) => {
2597
+ // const image = await this.requestClient({
2598
+ // method: 'get',
2599
+ // url: state.val,
2600
+ // responseType: 'arraybuffer',
2601
+ // }).catch((error) => {
2602
+ // if (error.response && error.response.status === 401) {
2603
+ // this.log.debug(error);
2604
+ // return;
2605
+ // }
2606
+ // this.log.error(state.val + ' ' + error);
2607
+ // });
2608
+ const image = await dhlDecrypt(state.val, this.requestClient).catch((error) => {
2607
2609
  if (error.response && error.response.status === 401) {
2608
2610
  this.log.debug(error);
2609
2611
  return;
@@ -2614,8 +2616,8 @@ class Parcel extends utils.Adapter {
2614
2616
  this.log.debug('No image received for ' + state.val);
2615
2617
  return;
2616
2618
  }
2617
- const imageBuffer = Buffer.from(image.data, 'binary');
2618
- imageBase64 = 'data:' + image.headers['content-type'] + ';base64, ' + imageBuffer.toString('base64');
2619
+ const imageBuffer = Buffer.from(image, 'binary');
2620
+ imageBase64 = 'data:image/png;base64, ' + imageBuffer.toString('base64');
2619
2621
  this.images[state.val] = imageBase64;
2620
2622
  const pathArray = id.split('.');
2621
2623
  pathArray.pop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.parcel",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
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.5.1",
29
+ "axios": "^1.6.0",
30
30
  "http-cookie-agent": "^5.0.4",
31
31
  "jsdom": "^21.1.2",
32
32
  "json2iob": "^2.4.8",
@@ -36,16 +36,16 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@iobroker/testing": "^4.1.0",
39
- "@types/chai": "^4.3.9",
40
- "@types/chai-as-promised": "^7.1.7",
41
- "@types/mocha": "^10.0.2",
42
- "@types/node": "^20.8.6",
43
- "@types/proxyquire": "^1.3.29",
44
- "@types/sinon": "^10.0.19",
45
- "@types/sinon-chai": "^3.2.10",
39
+ "@types/chai": "^4.3.10",
40
+ "@types/chai-as-promised": "^7.1.8",
41
+ "@types/mocha": "^10.0.4",
42
+ "@types/node": "^20.9.0",
43
+ "@types/proxyquire": "^1.3.31",
44
+ "@types/sinon": "^10.0.20",
45
+ "@types/sinon-chai": "^3.2.12",
46
46
  "chai": "^4.3.10",
47
47
  "chai-as-promised": "^7.1.1",
48
- "eslint": "^8.51.0",
48
+ "eslint": "^8.53.0",
49
49
  "mocha": "^10.2.0",
50
50
  "proxyquire": "^2.1.3",
51
51
  "sinon": "^15.2.0",