tesla-fleet-api 0.0.13 → 0.0.14
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/teslafleetapi.d.ts +14 -1
- package/dist/teslafleetapi.js +15 -1
- package/dist/teslafleetapi.js.map +1 -1
- package/package.json +1 -1
- package/src/teslafleetapi.ts +19 -2
package/dist/teslafleetapi.d.ts
CHANGED
|
@@ -3,9 +3,13 @@ import Energy from "./energy.js";
|
|
|
3
3
|
import Partner from "./partner.js";
|
|
4
4
|
import User from "./user.js";
|
|
5
5
|
import Vehicle from "./vehicle.js";
|
|
6
|
-
import { ProductsResponse } from "./types/products.js";
|
|
6
|
+
import { EnergyProduct, ProductsResponse, VehicleProduct } from "./types/products.js";
|
|
7
7
|
type Region = "na" | "eu" | "cn";
|
|
8
8
|
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
|
9
|
+
export type ProductsByType = {
|
|
10
|
+
vehicles: VehicleProduct[];
|
|
11
|
+
energy_sites: EnergyProduct[];
|
|
12
|
+
};
|
|
9
13
|
export default class TeslaFleetApi {
|
|
10
14
|
server: string | null;
|
|
11
15
|
accessToken: string | null;
|
|
@@ -33,6 +37,15 @@ export default class TeslaFleetApi {
|
|
|
33
37
|
* @returns
|
|
34
38
|
*/
|
|
35
39
|
_request(method: Method, path: string, params?: Record<string, any> | null, json?: Record<string, any> | null): Promise<any>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns products mapped to user.
|
|
42
|
+
* @returns An array of products including both vehicles and energy sites.
|
|
43
|
+
*/
|
|
36
44
|
products(): Promise<ProductsResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Return Tesla products separated into vehicles and energy_sites
|
|
47
|
+
* @returns A dictionary of vehicles and energy sites, each with an array of those products
|
|
48
|
+
*/
|
|
49
|
+
products_by_type(): Promise<ProductsByType>;
|
|
37
50
|
}
|
|
38
51
|
export {};
|
package/dist/teslafleetapi.js
CHANGED
|
@@ -84,8 +84,22 @@ export default class TeslaFleetApi {
|
|
|
84
84
|
throw new Error(`Not JSON ${res.status}`);
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns products mapped to user.
|
|
89
|
+
* @returns An array of products including both vehicles and energy sites.
|
|
90
|
+
*/
|
|
87
91
|
async products() {
|
|
88
|
-
return this._request("GET", "api/1/products").then((
|
|
92
|
+
return this._request("GET", "api/1/products").then((data) => data.response);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Return Tesla products separated into vehicles and energy_sites
|
|
96
|
+
* @returns A dictionary of vehicles and energy sites, each with an array of those products
|
|
97
|
+
*/
|
|
98
|
+
async products_by_type() {
|
|
99
|
+
return this.products().then((products) => ({
|
|
100
|
+
vehicles: products.filter((product) => "vin" in product),
|
|
101
|
+
energy_sites: products.filter((product) => "energy_site_id" in product),
|
|
102
|
+
}));
|
|
89
103
|
}
|
|
90
104
|
}
|
|
91
105
|
//# sourceMappingURL=teslafleetapi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"teslafleetapi.js","sourceRoot":"","sources":["../src/teslafleetapi.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AAOnC,MAAM,OAAO,GAA2B;IACpC,EAAE,EAAE,6CAA6C;IACjD,EAAE,EAAE,6CAA6C;IACjD,EAAE,EAAE,4CAA4C;CACnD,CAAC;
|
|
1
|
+
{"version":3,"file":"teslafleetapi.js","sourceRoot":"","sources":["../src/teslafleetapi.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO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CAAC,gBAAgB;QAClB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACvC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAA6B,EAAE,CAAC,KAAK,IAAI,OAAO,CAAC;YACnF,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAA4B,EAAE,CAAC,gBAAgB,IAAI,OAAO,CAAC;SACpG,CAAC,CAAC,CAAC;IACR,CAAC;CACJ"}
|
package/package.json
CHANGED
package/src/teslafleetapi.ts
CHANGED
|
@@ -4,7 +4,7 @@ import Partner from "./partner.js";
|
|
|
4
4
|
import User from "./user.js";
|
|
5
5
|
import Vehicle from "./vehicle.js";
|
|
6
6
|
|
|
7
|
-
import { ProductsResponse } from "./types/products.js";
|
|
7
|
+
import { EnergyProduct, ProductsResponse, VehicleProduct } from "./types/products.js";
|
|
8
8
|
|
|
9
9
|
type Region = "na" | "eu" | "cn";
|
|
10
10
|
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
|
@@ -15,6 +15,8 @@ const servers: Record<Region, string> = {
|
|
|
15
15
|
cn: "https://fleet-api.prd.cn.vn.cloud.tesla.cn",
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
export type ProductsByType = { vehicles: VehicleProduct[]; energy_sites: EnergyProduct[] };
|
|
19
|
+
|
|
18
20
|
export default class TeslaFleetApi {
|
|
19
21
|
server: string | null = null;
|
|
20
22
|
accessToken: string | null;
|
|
@@ -117,7 +119,22 @@ export default class TeslaFleetApi {
|
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Returns products mapped to user.
|
|
124
|
+
* @returns An array of products including both vehicles and energy sites.
|
|
125
|
+
*/
|
|
120
126
|
async products(): Promise<ProductsResponse> {
|
|
121
|
-
return this._request("GET", "api/1/products").then((
|
|
127
|
+
return this._request("GET", "api/1/products").then((data) => data.response);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Return Tesla products separated into vehicles and energy_sites
|
|
132
|
+
* @returns A dictionary of vehicles and energy sites, each with an array of those products
|
|
133
|
+
*/
|
|
134
|
+
async products_by_type(): Promise<ProductsByType> {
|
|
135
|
+
return this.products().then((products) => ({
|
|
136
|
+
vehicles: products.filter((product): product is VehicleProduct => "vin" in product),
|
|
137
|
+
energy_sites: products.filter((product): product is EnergyProduct => "energy_site_id" in product),
|
|
138
|
+
}));
|
|
122
139
|
}
|
|
123
140
|
}
|