leaf-connect 1.0.2 → 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/README.md +1 -1
- package/package.json +7 -3
- package/src/index.js +27 -27
- package/src/lib/retry-until-success.js +6 -7
package/README.md
CHANGED
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
@@ -1,11 +1,11 @@
|
|
1
1
|
const axios = require('axios')
|
2
|
-
const {
|
2
|
+
const {stringify} = require('querystring')
|
3
3
|
const encryptPassword = require('./lib/encrypt-password')
|
4
4
|
const extractData = require('./lib/extract-data')
|
5
5
|
const retryUntilSuccess = require('./lib/retry-until-success')
|
6
6
|
const logger = require('./lib/logger')
|
7
7
|
|
8
|
-
const API_ENDPOINT = 'https://gdcportalgw.its-mo.com/
|
8
|
+
const API_ENDPOINT = 'https://gdcportalgw.its-mo.com/api_v210707_NE/gdc/'
|
9
9
|
const INITIAL_APP_STR = '9s5rfKVuMrT03RtzajWNcA'
|
10
10
|
const RESULT_POLLING_INTERVAL = 20000
|
11
11
|
const REGION_CODES = ['NE', 'NCI', 'NNA', 'NMA', 'NML']
|
@@ -56,7 +56,7 @@ module.exports = async ({
|
|
56
56
|
}
|
57
57
|
|
58
58
|
try {
|
59
|
-
const {
|
59
|
+
const {data} = await apiInstance(
|
60
60
|
{
|
61
61
|
url: 'InitialApp_v2.php',
|
62
62
|
data: {
|
@@ -72,7 +72,7 @@ module.exports = async ({
|
|
72
72
|
throw Error(`Cloud not connect to ${API_ENDPOINT}:\n ${error.message}`)
|
73
73
|
}
|
74
74
|
|
75
|
-
const {
|
75
|
+
const {data} = await apiInstance({
|
76
76
|
url: 'UserLoginRequest.php',
|
77
77
|
data: {
|
78
78
|
initial_app_str: INITIAL_APP_STR,
|
@@ -101,14 +101,14 @@ module.exports = async ({
|
|
101
101
|
|
102
102
|
return {
|
103
103
|
|
104
|
-
sessionInfo: () =>
|
104
|
+
sessionInfo: () => sessionState.info,
|
105
105
|
|
106
106
|
status: async () => {
|
107
|
-
const {
|
108
|
-
const {
|
107
|
+
const {data} = await apiInstance({url: 'BatteryStatusCheckRequest.php', data: sessionState.requestOptions})
|
108
|
+
const {resultKey} = data
|
109
109
|
|
110
110
|
const runStatusResult = async () => {
|
111
|
-
const {
|
111
|
+
const {data} = await apiInstance({
|
112
112
|
url: 'BatteryStatusCheckResultRequest.php',
|
113
113
|
data: {
|
114
114
|
...sessionState.requestOptions,
|
@@ -123,23 +123,23 @@ module.exports = async ({
|
|
123
123
|
},
|
124
124
|
|
125
125
|
cachedStatus: async () => {
|
126
|
-
const {
|
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
|
-
const {
|
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 () => {
|
138
|
-
const {
|
139
|
-
const {
|
138
|
+
const {data} = await apiInstance({url: 'ACRemoteRequest.php', data: sessionState.requestOptions})
|
139
|
+
const {resultKey} = data
|
140
140
|
|
141
141
|
const runClimateControlTurnOnResult = async () => {
|
142
|
-
const {
|
142
|
+
const {data} = await apiInstance({
|
143
143
|
url: 'ACRemoteResult.php',
|
144
144
|
data: {
|
145
145
|
...sessionState.requestOptions,
|
@@ -153,11 +153,11 @@ module.exports = async ({
|
|
153
153
|
},
|
154
154
|
|
155
155
|
climateControlTurnOff: async () => {
|
156
|
-
const {
|
157
|
-
const {
|
156
|
+
const {data} = await apiInstance({url: 'ACRemoteOffRequest.php', data: sessionState.requestOptions})
|
157
|
+
const {resultKey} = data
|
158
158
|
|
159
159
|
const runClimateControlTurnOffResult = async () => {
|
160
|
-
const {
|
160
|
+
const {data} = await apiInstance({
|
161
161
|
url: 'ACRemoteOffResult.php',
|
162
162
|
data: {
|
163
163
|
...sessionState.requestOptions,
|
@@ -172,13 +172,13 @@ module.exports = async ({
|
|
172
172
|
},
|
173
173
|
|
174
174
|
chargingStart: async () => {
|
175
|
-
const {
|
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 => {
|
181
|
-
const {
|
181
|
+
const {data} = await apiInstance({
|
182
182
|
url: 'CarKarteDetailInfoRequest.php',
|
183
183
|
data: {
|
184
184
|
...sessionState.requestOptions,
|
@@ -186,15 +186,15 @@ module.exports = async ({
|
|
186
186
|
}
|
187
187
|
})
|
188
188
|
|
189
|
-
return
|
189
|
+
return data
|
190
190
|
},
|
191
191
|
|
192
192
|
location: async () => {
|
193
|
-
const {
|
194
|
-
const {
|
193
|
+
const {data} = await apiInstance({url: 'MyCarFinderRequest.php', data: sessionState.requestOptions})
|
194
|
+
const {resultKey} = data
|
195
195
|
|
196
196
|
const runLocationResult = async () => {
|
197
|
-
const {
|
197
|
+
const {data} = await apiInstance({
|
198
198
|
url: 'MyCarFinderResultRequest.php',
|
199
199
|
data: {
|
200
200
|
...sessionState.requestOptions,
|
@@ -209,9 +209,9 @@ module.exports = async ({
|
|
209
209
|
},
|
210
210
|
|
211
211
|
lastLocation: async () => {
|
212
|
-
const {
|
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
|
|