iobroker.parcel 0.1.6 → 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,12 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "parcel",
4
- "version": "0.1.6",
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
+ },
6
10
  "0.1.6": {
7
11
  "en": "Fix DHL and UPS",
8
12
  "de": "DHL und UPS gefixt"
@@ -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={}]
@@ -1206,6 +1207,9 @@ class Parcel extends utils.Adapter {
1206
1207
  } else {
1207
1208
  this.log.warn('Login to UPS failed');
1208
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
+ }
1209
1213
  }
1210
1214
 
1211
1215
  return;
@@ -2590,11 +2594,18 @@ class Parcel extends utils.Adapter {
2590
2594
  if (id.indexOf('dhl.briefe') !== -1 && id.indexOf('image_url') !== -1 && id.indexOf('oldAdvices') === -1) {
2591
2595
  let imageBase64 = this.images[state.val];
2592
2596
  if (!imageBase64) {
2593
- const image = await this.requestClient({
2594
- method: 'get',
2595
- url: state.val,
2596
- responseType: 'arraybuffer',
2597
- }).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) => {
2598
2609
  if (error.response && error.response.status === 401) {
2599
2610
  this.log.debug(error);
2600
2611
  return;
@@ -2605,8 +2616,8 @@ class Parcel extends utils.Adapter {
2605
2616
  this.log.debug('No image received for ' + state.val);
2606
2617
  return;
2607
2618
  }
2608
- const imageBuffer = Buffer.from(image.data, 'binary');
2609
- 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');
2610
2621
  this.images[state.val] = imageBase64;
2611
2622
  const pathArray = id.split('.');
2612
2623
  pathArray.pop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.parcel",
3
- "version": "0.1.6",
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.3",
42
- "@types/node": "^20.8.7",
43
- "@types/proxyquire": "^1.3.30",
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
44
  "@types/sinon": "^10.0.20",
45
- "@types/sinon-chai": "^3.2.11",
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",