tesla-fleet-api 0.0.5 → 0.0.6
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/helpers.d.ts +2 -0
- package/dist/helpers.js +10 -0
- package/dist/helpers.js.map +1 -0
- package/dist/teslafleetapi.js.map +1 -1
- package/dist/teslemetry.js.map +1 -1
- package/dist/tessie.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.js.map +1 -1
- package/dist/user.d.ts +6 -5
- package/dist/user.js.map +1 -1
- package/dist/vehicle.d.ts +66 -64
- package/dist/vehicle.js +14 -0
- package/dist/vehicle.js.map +1 -1
- package/dist/vehiclespecific.d.ts +65 -63
- package/dist/vehiclespecific.js +6 -0
- package/dist/vehiclespecific.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers.ts +11 -0
- package/src/teslafleetapi.ts +8 -0
- package/src/teslemetry.ts +7 -2
- package/src/tessie.ts +3 -1
- package/src/types.ts +8 -0
- package/src/user.ts +6 -5
- package/src/vehicle.ts +91 -69
- package/src/vehiclespecific.ts +82 -63
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommandResponse } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export const validate = async (body: CommandResponse): Promise<void> => {
|
|
4
|
+
if (body?.error) {
|
|
5
|
+
return Promise.reject(body.error);
|
|
6
|
+
}
|
|
7
|
+
if (body?.response?.result == false) {
|
|
8
|
+
return Promise.reject(body.response.reason);
|
|
9
|
+
}
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
};
|
package/src/teslafleetapi.ts
CHANGED
|
@@ -63,6 +63,14 @@ export default class TeslaFleetApi {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Make a request to the Tesla Fleet API.
|
|
68
|
+
* @param method
|
|
69
|
+
* @param path
|
|
70
|
+
* @param params
|
|
71
|
+
* @param json
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
66
74
|
async _request(method: Method, path: string, params: Record<string, any> | null = null, json: Record<string, any> | null = null): Promise<any> {
|
|
67
75
|
if (!this.server) {
|
|
68
76
|
throw new Error("Server was not set at init. Call findServer() first.");
|
package/src/teslemetry.ts
CHANGED
|
@@ -7,12 +7,17 @@ export default class Telemetry extends TeslaFleetApi {
|
|
|
7
7
|
super({ accessToken, server: `https://${region}.teslemetry.com`, partnerScope: false, userScope: false });
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Test the connection to Teslemetry
|
|
12
|
+
*/
|
|
11
13
|
async test() {
|
|
12
14
|
return this._request("GET", "/api/test");
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Get details about your Teslemetry account
|
|
19
|
+
* @param update_region Update the server URL based on the region in the metadata
|
|
20
|
+
*/
|
|
16
21
|
async metadata(update_region = true) {
|
|
17
22
|
this._request("GET", "/api/metadata").then((metadata) => {
|
|
18
23
|
if (update_region) {
|
package/src/tessie.ts
CHANGED
|
@@ -6,7 +6,9 @@ export default class Telemetry extends TeslaFleetApi {
|
|
|
6
6
|
super({ accessToken, server: `https://api.tessie.com`, partnerScope: false, userScope: false });
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Get your approved Tesla scopes
|
|
11
|
+
*/
|
|
10
12
|
async tesla_scopes(): Promise<Scope[]> {
|
|
11
13
|
return this._request("GET", "auth/tesla_scopes");
|
|
12
14
|
}
|
package/src/types.ts
CHANGED
package/src/user.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import TeslaFleetApi from "./teslafleetapi.js";
|
|
2
|
+
import { CommandResponse } from "./types.js";
|
|
2
3
|
|
|
3
4
|
export default class User {
|
|
4
5
|
parent: TeslaFleetApi;
|
|
@@ -8,27 +9,27 @@ export default class User {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
/** Returns the public key associated with the user. */
|
|
11
|
-
async backup_key(): Promise<
|
|
12
|
+
async backup_key(): Promise<CommandResponse> {
|
|
12
13
|
return this.parent._request("GET", "api/1/users/backup_key");
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/** Returns any custom feature flag applied to a user. */
|
|
16
|
-
async feature_config(): Promise<
|
|
17
|
+
async feature_config(): Promise<CommandResponse> {
|
|
17
18
|
return this.parent._request("GET", "api/1/users/feature_config");
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/** Returns a summary of a user's account. */
|
|
21
|
-
async me(): Promise<
|
|
22
|
+
async me(): Promise<CommandResponse> {
|
|
22
23
|
return this.parent._request("GET", "api/1/users/me");
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** Returns the active orders for a user. */
|
|
26
|
-
async orders(): Promise<
|
|
27
|
+
async orders(): Promise<CommandResponse> {
|
|
27
28
|
return this.parent._request("GET", "api/1/users/orders");
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/** Returns a user's region and appropriate fleet-api base URL. Accepts no parameters, response is based on the authentication token subject. */
|
|
31
|
-
async region(): Promise<
|
|
32
|
+
async region(): Promise<CommandResponse> {
|
|
32
33
|
return this.parent._request("GET", "api/1/users/region");
|
|
33
34
|
}
|
|
34
35
|
}
|