Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Nov 18, 2023
1 parent 0818f7d commit 6be4e7b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
3 changes: 3 additions & 0 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
"native": {
"amzusername": "",
"amzpassword": "",
"aliUsername": "",
"aliPassword": "",
"aliMfa": "",
"glsusername": "",
"glspassword": "",
"upsusername": "",
Expand Down
48 changes: 11 additions & 37 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Module.prototype.require = function () {
};

const utils = require('@iobroker/adapter-core');
const axios = require('axios');
const axios = require('axios').default;
const qs = require('qs');
const crypto = require('crypto');
const Json2iob = require('json2iob');
Expand Down Expand Up @@ -64,6 +64,7 @@ class Parcel extends utils.Adapter {
DELIVERED: 1,
};
this.tmpDir = tmpdir();
this.requestClient = axios.create();
}

/**
Expand Down Expand Up @@ -403,6 +404,10 @@ class Parcel extends utils.Adapter {
this.log.error(JSON.stringify(error.response.data));
}
});
if (!codeUrl) {
this.log.error('DHL codeUrl failed');
return;
}
await this.requestClient({
method: 'post',
url: 'https://login.dhl.de/af5f9bb6-27ad-4af4-9445-008e7a5cddb8/login/token',
Expand Down Expand Up @@ -451,8 +456,6 @@ class Parcel extends utils.Adapter {
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'accept-language': 'de-de',
},
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -482,8 +485,6 @@ class Parcel extends utils.Adapter {
force: false,
meta: '',
}),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -620,8 +621,6 @@ class Parcel extends utils.Adapter {
referer: 'https://login.aliexpress.com/',
'accept-language': 'de',
},
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -699,6 +698,7 @@ class Parcel extends utils.Adapter {
} else {
this.log.info('Login to AliExpress with MFA token');
this.log.debug('MFA: ' + this.config.dhlMfa);
const mfaToken = '';
await this.requestClient({
method: 'post',
url: 'https://www.dhl.de/int-erkennen/2fa',
Expand Down Expand Up @@ -775,8 +775,6 @@ class Parcel extends utils.Adapter {
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'accept-language': 'de-de',
},
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -807,8 +805,6 @@ class Parcel extends utils.Adapter {
referer: 'https://www.amazon.de/ap/signin',
},
data: qs.stringify(form),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -841,8 +837,6 @@ class Parcel extends utils.Adapter {
referer: 'https://www.amazon.de/ap/signin',
},
data: qs.stringify(form),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -872,8 +866,6 @@ class Parcel extends utils.Adapter {
referer: 'https://www.amazon.de/ap/signin',
},
data: qs.stringify(form),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -943,8 +935,6 @@ class Parcel extends utils.Adapter {
await this.requestClient({
method: 'get',
url: 'https://my.dpd.de/logout.aspx',
jar: this.cookieJar,
withCredentials: true,
}).catch(async (error) => {
error.response && this.log.error(JSON.stringify(error.response.data));
this.log.error(error);
Expand All @@ -964,8 +954,6 @@ class Parcel extends utils.Adapter {
dpg_username: this.config.dpdusername,
dpg_password: this.config.dpdpassword,
}),
jar: this.cookieJar,
withCredentials: true,
maxRedirects: 0,
})
.then(async (res) => {
Expand Down Expand Up @@ -1010,8 +998,6 @@ class Parcel extends utils.Adapter {
await this.requestClient({
method: 'get',
url: 'https://my.dpd.de/myParcel.aspx?dpd_token=' + this.dpdToken,
jar: this.cookieJar,
withCredentials: true,
}).catch(async (error) => {
error.response && this.log.error(JSON.stringify(error.response.data));
this.log.error(error);
Expand All @@ -1037,8 +1023,6 @@ class Parcel extends utils.Adapter {
username: this.config.glsusername,
password: this.config.glspassword,
}),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.sessions['gls'] = res.data;
Expand Down Expand Up @@ -1066,8 +1050,6 @@ class Parcel extends utils.Adapter {
'X-Client-Id': 'iOS',
'X-Auth-Token': this.glstoken,
},
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
!silent && this.log.info('Login to GLS successful');
Expand Down Expand Up @@ -1110,9 +1092,6 @@ class Parcel extends utils.Adapter {
'accept-language': 'de-de',
},
data: { username: this.config.hermesusername, password: this.config.hermespassword },

jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -1178,8 +1157,6 @@ class Parcel extends utils.Adapter {
IsMobile: 'true',
},
}),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -1259,8 +1236,6 @@ class Parcel extends utils.Adapter {
},
},
}),
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -1357,8 +1332,6 @@ class Parcel extends utils.Adapter {
'","Password":"' +
this.config.t17password +
'","CaptchaCode":""},"sourcetype":0,"timeZoneOffset":-60}',
jar: this.cookieJar,
withCredentials: true,
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
Expand Down Expand Up @@ -2138,6 +2111,7 @@ class Parcel extends utils.Adapter {
this.log.debug('Get Amazon Packages');
const amzResult = { sendungen: [] };

await this.loginAmz();
let orders = await this.getAmazonOrders();
if (!orders) {
orders = await this.getAmazonOrders();
Expand Down Expand Up @@ -2315,7 +2289,6 @@ class Parcel extends utils.Adapter {
url: 'https://www.amazon.de/gp/css/order-history?ref_=nav_orders_first',
headers: {
authority: 'www.amazon.de',

Connection: 'keep-alive',
'Cache-Control': 'no-cache',
accept:
Expand Down Expand Up @@ -2647,8 +2620,7 @@ class Parcel extends utils.Adapter {
await this.requestClient({
method: 'post',
url: 'https://buyer.17track.net/orderapi/call',
header: { 'content-type': 'application/x-www-form-urlencoded' },

headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: JSON.stringify({
version: '1.0',
timeZoneOffset: -60,
Expand Down Expand Up @@ -2768,6 +2740,8 @@ class Parcel extends utils.Adapter {
this.log.error(error);
}
}
} else {
this.setState(id.replace('image_url', 'image'), imageBase64, true);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@iobroker/adapter-core": "^3.0.4",
"axios": "^1.6.0",
"axios": "^1.6.2",
"http-cookie-agent": "^5.0.4",
"jsdom": "^21.1.2",
"json2iob": "^2.4.8",
Expand All @@ -39,7 +39,7 @@
"@types/chai": "^4.3.10",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0",
"@types/node": "^20.9.1",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "^10.0.20",
"@types/sinon-chai": "^3.2.12",
Expand Down

0 comments on commit 6be4e7b

Please sign in to comment.