leaf-connect 1.0.3 → 1.1.1
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 +7 -3
- package/src/index.js +6 -6
- package/src/lib/retry-until-success.js +6 -7
package/package.json
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "leaf-connect",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.1.1",
|
4
4
|
"description": "Node.js client library for the Nissan Leaf API",
|
5
5
|
"main": "src/index.js",
|
6
6
|
"scripts": {
|
7
|
-
"
|
7
|
+
"lint": "standard src/**/*.js",
|
8
|
+
"lint-fix": "standard --fix src/**/*.js"
|
8
9
|
},
|
9
10
|
"files": [
|
10
11
|
"src/*"
|
@@ -22,6 +23,9 @@
|
|
22
23
|
},
|
23
24
|
"license": "MIT",
|
24
25
|
"dependencies": {
|
25
|
-
"axios": "
|
26
|
+
"axios": "1.4.0"
|
27
|
+
},
|
28
|
+
"devDependencies": {
|
29
|
+
"standard": "17.1.0"
|
26
30
|
}
|
27
31
|
}
|
package/src/index.js
CHANGED
@@ -101,7 +101,7 @@ module.exports = async ({
|
|
101
101
|
|
102
102
|
return {
|
103
103
|
|
104
|
-
sessionInfo: () =>
|
104
|
+
sessionInfo: () => sessionState.info,
|
105
105
|
|
106
106
|
status: async () => {
|
107
107
|
const {data} = await apiInstance({url: 'BatteryStatusCheckRequest.php', data: sessionState.requestOptions})
|
@@ -125,13 +125,13 @@ module.exports = async ({
|
|
125
125
|
cachedStatus: async () => {
|
126
126
|
const {data} = await apiInstance({url: 'BatteryStatusRecordsRequest.php', data: sessionState.requestOptions})
|
127
127
|
|
128
|
-
return
|
128
|
+
return data
|
129
129
|
},
|
130
130
|
|
131
131
|
climateControlStatus: async () => {
|
132
132
|
const {data} = await apiInstance({url: 'RemoteACRecordsRequest.php', data: sessionState.requestOptions})
|
133
133
|
|
134
|
-
return
|
134
|
+
return data
|
135
135
|
},
|
136
136
|
|
137
137
|
climateControlTurnOn: async () => {
|
@@ -174,7 +174,7 @@ module.exports = async ({
|
|
174
174
|
chargingStart: async () => {
|
175
175
|
const {data} = await apiInstance({url: 'BatteryRemoteChargingRequest.php', data: sessionState.requestOptions})
|
176
176
|
|
177
|
-
return
|
177
|
+
return data
|
178
178
|
},
|
179
179
|
|
180
180
|
history: async date => {
|
@@ -186,7 +186,7 @@ module.exports = async ({
|
|
186
186
|
}
|
187
187
|
})
|
188
188
|
|
189
|
-
return
|
189
|
+
return data
|
190
190
|
},
|
191
191
|
|
192
192
|
location: async () => {
|
@@ -211,7 +211,7 @@ module.exports = async ({
|
|
211
211
|
lastLocation: async () => {
|
212
212
|
const {data} = await apiInstance({url: 'MyCarFinderLatLng.php', data: sessionState.requestOptions})
|
213
213
|
|
214
|
-
return
|
214
|
+
return data
|
215
215
|
}
|
216
216
|
|
217
217
|
}
|
@@ -3,10 +3,11 @@ const maxWaitTime = 30000
|
|
3
3
|
module.exports = async (interval, fn) => {
|
4
4
|
const startTime = Date.now()
|
5
5
|
|
6
|
-
return new Promise(resolve => {
|
6
|
+
return new Promise((resolve, reject) => {
|
7
7
|
const retry = async fn => {
|
8
8
|
if (startTime > startTime + maxWaitTime) {
|
9
|
-
|
9
|
+
reject(Error('Timout threshold exceeded.'))
|
10
|
+
return
|
10
11
|
}
|
11
12
|
|
12
13
|
let data = {}
|
@@ -16,16 +17,14 @@ module.exports = async (interval, fn) => {
|
|
16
17
|
|
17
18
|
if (!data.responseFlag) {
|
18
19
|
console.log(data)
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
if (data.responseFlag === '0') {
|
20
|
+
reject(Error('Response did not include response flag'))
|
21
|
+
} else if (data.responseFlag === '0') {
|
23
22
|
setTimeout(() => retry(fn), interval)
|
24
23
|
} else {
|
25
24
|
resolve(JSON.stringify(data, null, 2))
|
26
25
|
}
|
27
26
|
} catch (error) {
|
28
|
-
|
27
|
+
reject(Error(`Failed to get status ${error.message}`))
|
29
28
|
}
|
30
29
|
}
|
31
30
|
|