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/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
+ };
@@ -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
- /** Test the connection to Teslemetry */
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
- /** Get details about your Teslemetry account */
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
- /** Get your approved Tesla scopes */
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
@@ -1,3 +1,11 @@
1
+ export interface CommandResponse {
2
+ response: {
3
+ result: boolean;
4
+ reason: string;
5
+ };
6
+ error: string;
7
+ }
8
+
1
9
  export type Scope =
2
10
  | "user_data"
3
11
  | "vehicle_device_data"
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<Record<string, any>> {
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<Record<string, any>> {
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<Record<string, any>> {
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<Record<string, any>> {
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<Record<string, any>> {
32
+ async region(): Promise<CommandResponse> {
32
33
  return this.parent._request("GET", "api/1/users/region");
33
34
  }
34
35
  }