fleetmap-reports 2.0.3 → 2.0.5
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/package.json +2 -2
- package/src/index.js +2 -3
- package/src/tests/index.js +6 -9
- package/src/zone-report.js +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"country-reverse-geocoding": "^0.2.2",
|
|
19
19
|
"docx": "^7.3.0",
|
|
20
20
|
"file-saver": "^2.0.5",
|
|
21
|
-
"fleetmap-partners": "^1.0.
|
|
21
|
+
"fleetmap-partners": "^1.0.160",
|
|
22
22
|
"json-as-xlsx": "^1.2.1",
|
|
23
23
|
"jspdf": "^2.5.1",
|
|
24
24
|
"jspdf-autotable": "3.6.0",
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function Reports (config, axios
|
|
1
|
+
function Reports (config, axios) {
|
|
2
2
|
const { ReportsApi, PositionsApi, SessionApi, DevicesApi, GroupsApi, DriversApi, GeofencesApi } = require('traccar-api')
|
|
3
3
|
this.traccar = {
|
|
4
4
|
reports: new ReportsApi(config, null, axios),
|
|
@@ -8,8 +8,7 @@ function Reports (config, axios, cookieJar) {
|
|
|
8
8
|
groups: new GroupsApi(config, null, axios),
|
|
9
9
|
drivers: new DriversApi(config, null, axios),
|
|
10
10
|
geofences: new GeofencesApi(config, null, axios),
|
|
11
|
-
axios: axios || require('axios').create({ ...config.baseOptions, baseURL: config.basePath })
|
|
12
|
-
cookieJar
|
|
11
|
+
axios: axios || require('axios').create({ ...config.baseOptions, baseURL: config.basePath })
|
|
13
12
|
}
|
|
14
13
|
this.getUserData = async () => {
|
|
15
14
|
return {
|
package/src/tests/index.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
const { SessionApi } = require('traccar-api')
|
|
2
|
-
const axiosCookieJarSupport = require('axios-cookiejar-support').default
|
|
3
|
-
const tough = require('tough-cookie')
|
|
4
2
|
const Index = require('../index')
|
|
5
|
-
const
|
|
3
|
+
const { isClientSide } = require('../util/utils')
|
|
4
|
+
const { newDomains } = require('fleetmap-partners')
|
|
5
|
+
const serverHost = isClientSide() && newDomains.includes(window.location.hostname) ? window.location.hostname : 'api.pinme.io'
|
|
6
6
|
const traccarConfig = {
|
|
7
|
-
basePath:
|
|
7
|
+
basePath: `https://${serverHost}/api`,
|
|
8
8
|
baseOptions: {
|
|
9
|
-
withCredentials: true
|
|
10
|
-
jar: cookieJar
|
|
9
|
+
withCredentials: true
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
const axios = require('axios').create({ ...traccarConfig.baseOptions, baseURL: traccarConfig.basePath })
|
|
14
13
|
|
|
15
|
-
axiosCookieJarSupport(axios)
|
|
16
|
-
|
|
17
14
|
const getReports = async (email, password) => {
|
|
18
15
|
try {
|
|
19
16
|
console.log('email / pass', process.env.email || email, process.env.password || password)
|
|
20
17
|
await new SessionApi(traccarConfig, null, axios).sessionPost(email || process.env.email, password || process.env.password)
|
|
21
|
-
return new Index(traccarConfig, axios
|
|
18
|
+
return new Index(traccarConfig, axios)
|
|
22
19
|
} catch (e) {
|
|
23
20
|
console.error(e)
|
|
24
21
|
}
|
package/src/zone-report.js
CHANGED
|
@@ -11,7 +11,10 @@ require('jspdf-autotable')
|
|
|
11
11
|
const traccarHelper = require('./util/traccar')
|
|
12
12
|
const { headerFromUser, addTable } = require('./util/pdfDocument')
|
|
13
13
|
const { getStyle } = require('./reportStyle')
|
|
14
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
getUserPartner,
|
|
16
|
+
newDomains
|
|
17
|
+
} = require('fleetmap-partners')
|
|
15
18
|
const { devicesToProcess } = require('./util/device')
|
|
16
19
|
const axios = require('axios')
|
|
17
20
|
const {
|
|
@@ -33,8 +36,12 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
33
36
|
xpert: devices.filter(d => d.attributes.xpert).length > 0
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
const serverHost = isClientSide() && newDomains.includes(window.location.hostname)
|
|
40
|
+
? window.location.hostname
|
|
41
|
+
: process.env.SERVER_HOST
|
|
42
|
+
|
|
36
43
|
if (isClientSide()) {
|
|
37
|
-
const url = `https://${
|
|
44
|
+
const url = `https://${serverHost}/reports/zone-report`
|
|
38
45
|
return axios.post(url, { from, to, userData }, { withCredentials: true })
|
|
39
46
|
.then(d => d.data)
|
|
40
47
|
}
|