@vulog/aima-vehicle 1.1.56 → 1.1.58
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/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +33 -6
- package/dist/index.mjs +31 -5
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/pingVehicle.ts +31 -0
- package/src/wakeUpVehicle.ts +29 -0
package/dist/index.d.mts
CHANGED
|
@@ -249,4 +249,11 @@ declare const getVehicles: (client: Client, pageSize?: number) => Promise<Vehicl
|
|
|
249
249
|
*/
|
|
250
250
|
declare const getVehiclesRealTime: (client: Client, pageSize?: number, lastUpdatedMillis?: number) => Promise<VehicleRealTime[]>;
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Pings a vehicle to check if it is alive (box connected).
|
|
254
|
+
* Returns true if alive (HTTP 200), false if box not connected (code 410, codeStr 'carConnectionProblem'),
|
|
255
|
+
* throws for other errors or invalid id.
|
|
256
|
+
*/
|
|
257
|
+
declare const pingVehicleById: (client: Client, id: string) => Promise<boolean>;
|
|
258
|
+
|
|
259
|
+
export { type Assets, type Model, type Options, type Vehicle, type VehicleRealTime, type Zone, getModelByIdAssets, getModels, getModelsById, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById };
|
package/dist/index.d.ts
CHANGED
|
@@ -249,4 +249,11 @@ declare const getVehicles: (client: Client, pageSize?: number) => Promise<Vehicl
|
|
|
249
249
|
*/
|
|
250
250
|
declare const getVehiclesRealTime: (client: Client, pageSize?: number, lastUpdatedMillis?: number) => Promise<VehicleRealTime[]>;
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Pings a vehicle to check if it is alive (box connected).
|
|
254
|
+
* Returns true if alive (HTTP 200), false if box not connected (code 410, codeStr 'carConnectionProblem'),
|
|
255
|
+
* throws for other errors or invalid id.
|
|
256
|
+
*/
|
|
257
|
+
declare const pingVehicleById: (client: Client, id: string) => Promise<boolean>;
|
|
258
|
+
|
|
259
|
+
export { type Assets, type Model, type Options, type Vehicle, type VehicleRealTime, type Zone, getModelByIdAssets, getModels, getModelsById, getVehicleById, getVehicleByIdAssets, getVehicleRealTimeById, getVehicles, getVehiclesRealTime, pingVehicleById };
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,8 @@ __export(index_exports, {
|
|
|
27
27
|
getVehicleByIdAssets: () => getVehicleByIdAssets,
|
|
28
28
|
getVehicleRealTimeById: () => getVehicleRealTimeById,
|
|
29
29
|
getVehicles: () => getVehicles,
|
|
30
|
-
getVehiclesRealTime: () => getVehiclesRealTime
|
|
30
|
+
getVehiclesRealTime: () => getVehiclesRealTime,
|
|
31
|
+
pingVehicleById: () => pingVehicleById
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(index_exports);
|
|
33
34
|
|
|
@@ -116,10 +117,10 @@ var getVehiclesPage = async (client, page, pageSize) => {
|
|
|
116
117
|
return response.data;
|
|
117
118
|
};
|
|
118
119
|
var getVehicles = async (client, pageSize = 500) => {
|
|
119
|
-
const
|
|
120
|
+
const schema5 = import_zod4.z.object({
|
|
120
121
|
pageSize: import_zod4.z.number().min(1).default(500)
|
|
121
122
|
});
|
|
122
|
-
const result =
|
|
123
|
+
const result = schema5.safeParse({ pageSize });
|
|
123
124
|
if (!result.success) {
|
|
124
125
|
throw new TypeError("Invalid args", {
|
|
125
126
|
cause: result.error.issues
|
|
@@ -156,11 +157,11 @@ var getVehiclesRealTimePage = async (client, page, pageSize, lastUpdatedMillis)
|
|
|
156
157
|
return response.data;
|
|
157
158
|
};
|
|
158
159
|
var getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) => {
|
|
159
|
-
const
|
|
160
|
+
const schema5 = import_zod4.z.object({
|
|
160
161
|
pageSize: import_zod4.z.number().min(1).default(500),
|
|
161
162
|
lastUpdatedMillis: import_zod4.z.number().positive().optional()
|
|
162
163
|
});
|
|
163
|
-
const result =
|
|
164
|
+
const result = schema5.safeParse({ pageSize, lastUpdatedMillis });
|
|
164
165
|
if (!result.success) {
|
|
165
166
|
throw new TypeError("Invalid args", {
|
|
166
167
|
cause: result.error.issues
|
|
@@ -194,6 +195,31 @@ var getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) => {
|
|
|
194
195
|
}
|
|
195
196
|
return allVehicles;
|
|
196
197
|
};
|
|
198
|
+
|
|
199
|
+
// src/pingVehicle.ts
|
|
200
|
+
var import_zod5 = require("zod");
|
|
201
|
+
var schema4 = import_zod5.z.object({
|
|
202
|
+
id: import_zod5.z.string().trim().min(1).uuid()
|
|
203
|
+
});
|
|
204
|
+
var pingVehicleById = async (client, id) => {
|
|
205
|
+
const result = schema4.safeParse({ id });
|
|
206
|
+
if (!result.success) {
|
|
207
|
+
throw new TypeError("Invalid args", {
|
|
208
|
+
cause: result.error.issues
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
await client.post(
|
|
213
|
+
`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/ping`
|
|
214
|
+
);
|
|
215
|
+
return true;
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error?.response?.data?.codeStr === "carConnectionProblem" && error?.response?.data?.code === 410) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
197
223
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
224
|
0 && (module.exports = {
|
|
199
225
|
getModelByIdAssets,
|
|
@@ -203,5 +229,6 @@ var getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) => {
|
|
|
203
229
|
getVehicleByIdAssets,
|
|
204
230
|
getVehicleRealTimeById,
|
|
205
231
|
getVehicles,
|
|
206
|
-
getVehiclesRealTime
|
|
232
|
+
getVehiclesRealTime,
|
|
233
|
+
pingVehicleById
|
|
207
234
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -83,10 +83,10 @@ var getVehiclesPage = async (client, page, pageSize) => {
|
|
|
83
83
|
return response.data;
|
|
84
84
|
};
|
|
85
85
|
var getVehicles = async (client, pageSize = 500) => {
|
|
86
|
-
const
|
|
86
|
+
const schema5 = z4.object({
|
|
87
87
|
pageSize: z4.number().min(1).default(500)
|
|
88
88
|
});
|
|
89
|
-
const result =
|
|
89
|
+
const result = schema5.safeParse({ pageSize });
|
|
90
90
|
if (!result.success) {
|
|
91
91
|
throw new TypeError("Invalid args", {
|
|
92
92
|
cause: result.error.issues
|
|
@@ -123,11 +123,11 @@ var getVehiclesRealTimePage = async (client, page, pageSize, lastUpdatedMillis)
|
|
|
123
123
|
return response.data;
|
|
124
124
|
};
|
|
125
125
|
var getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) => {
|
|
126
|
-
const
|
|
126
|
+
const schema5 = z4.object({
|
|
127
127
|
pageSize: z4.number().min(1).default(500),
|
|
128
128
|
lastUpdatedMillis: z4.number().positive().optional()
|
|
129
129
|
});
|
|
130
|
-
const result =
|
|
130
|
+
const result = schema5.safeParse({ pageSize, lastUpdatedMillis });
|
|
131
131
|
if (!result.success) {
|
|
132
132
|
throw new TypeError("Invalid args", {
|
|
133
133
|
cause: result.error.issues
|
|
@@ -161,6 +161,31 @@ var getVehiclesRealTime = async (client, pageSize = 500, lastUpdatedMillis) => {
|
|
|
161
161
|
}
|
|
162
162
|
return allVehicles;
|
|
163
163
|
};
|
|
164
|
+
|
|
165
|
+
// src/pingVehicle.ts
|
|
166
|
+
import { z as z5 } from "zod";
|
|
167
|
+
var schema4 = z5.object({
|
|
168
|
+
id: z5.string().trim().min(1).uuid()
|
|
169
|
+
});
|
|
170
|
+
var pingVehicleById = async (client, id) => {
|
|
171
|
+
const result = schema4.safeParse({ id });
|
|
172
|
+
if (!result.success) {
|
|
173
|
+
throw new TypeError("Invalid args", {
|
|
174
|
+
cause: result.error.issues
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
await client.post(
|
|
179
|
+
`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/ping`
|
|
180
|
+
);
|
|
181
|
+
return true;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (error?.response?.data?.codeStr === "carConnectionProblem" && error?.response?.data?.code === 410) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
164
189
|
export {
|
|
165
190
|
getModelByIdAssets,
|
|
166
191
|
getModels,
|
|
@@ -169,5 +194,6 @@ export {
|
|
|
169
194
|
getVehicleByIdAssets,
|
|
170
195
|
getVehicleRealTimeById,
|
|
171
196
|
getVehicles,
|
|
172
|
-
getVehiclesRealTime
|
|
197
|
+
getVehiclesRealTime,
|
|
198
|
+
pingVehicleById
|
|
173
199
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-vehicle",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.58",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"author": "Vulog",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.1.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
22
|
+
"@vulog/aima-client": "1.1.58",
|
|
23
|
+
"@vulog/aima-core": "1.1.58"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"zod": "^3.24.2"
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const schema = z.object({
|
|
5
|
+
id: z.string().trim().min(1).uuid(),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Pings a vehicle to check if it is alive (box connected).
|
|
10
|
+
* Returns true if alive (HTTP 200), false if box not connected (code 410, codeStr 'carConnectionProblem'),
|
|
11
|
+
* throws for other errors or invalid id.
|
|
12
|
+
*/
|
|
13
|
+
export const pingVehicleById = async (client: Client, id: string): Promise<boolean> => {
|
|
14
|
+
const result = schema.safeParse({ id });
|
|
15
|
+
if (!result.success) {
|
|
16
|
+
throw new TypeError('Invalid args', {
|
|
17
|
+
cause: result.error.issues,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
await client.post(
|
|
22
|
+
`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/ping`
|
|
23
|
+
);
|
|
24
|
+
return true;
|
|
25
|
+
} catch (error: any) {
|
|
26
|
+
if (error?.response?.data?.codeStr === 'carConnectionProblem' && error?.response?.data?.code === 410) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const schema = z.object({
|
|
5
|
+
id: z.string().trim().min(1).uuid(),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wakes up a vehicle by sending a wakeup command.
|
|
10
|
+
* Returns 'sent' if the wakeup was sent (HTTP 200),
|
|
11
|
+
* 'discarded' if a wakeup was already in progress (HTTP 202),
|
|
12
|
+
* throws for other errors or invalid id.
|
|
13
|
+
*/
|
|
14
|
+
export const wakeUpVehicleById = async (client: Client, id: string): Promise<'sent' | 'discarded'> => {
|
|
15
|
+
const result = schema.safeParse({ id });
|
|
16
|
+
if (!result.success) {
|
|
17
|
+
throw new TypeError('Invalid args', {
|
|
18
|
+
cause: result.error.issues,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const response = await client.post(
|
|
22
|
+
`boapi/proxy/fleetmanager/public/v2/fleets/${client.clientOptions.fleetId}/vehicles/${result.data.id}/wakeup`,
|
|
23
|
+
undefined,
|
|
24
|
+
{ validateStatus: () => true }
|
|
25
|
+
);
|
|
26
|
+
if (response.status === 200) return 'sent';
|
|
27
|
+
if (response.status === 202) return 'discarded';
|
|
28
|
+
throw new Error(`Unexpected status code: ${response.status}`);
|
|
29
|
+
};
|