tesla-fleet-api 0.3.0 → 0.5.0
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 +284 -1
- package/dist/_virtual/_rolldown/runtime.cjs +32 -0
- package/dist/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/bluetooth/adapters/shared.cjs +38 -0
- package/dist/bluetooth/adapters/shared.mjs +36 -0
- package/dist/bluetooth/async.cjs +121 -0
- package/dist/bluetooth/async.d.cts +10 -0
- package/dist/bluetooth/async.d.mts +10 -0
- package/dist/bluetooth/async.mjs +116 -0
- package/dist/bluetooth/broadcast.cjs +153 -0
- package/dist/bluetooth/broadcast.d.cts +59 -0
- package/dist/bluetooth/broadcast.d.mts +59 -0
- package/dist/bluetooth/broadcast.mjs +151 -0
- package/dist/bluetooth/constants.cjs +99 -0
- package/dist/bluetooth/constants.d.cts +70 -0
- package/dist/bluetooth/constants.d.mts +70 -0
- package/dist/bluetooth/constants.mjs +72 -0
- package/dist/bluetooth/esphome.cjs +292 -0
- package/dist/bluetooth/esphome.d.cts +83 -0
- package/dist/bluetooth/esphome.d.mts +83 -0
- package/dist/bluetooth/esphome.mjs +291 -0
- package/dist/bluetooth/framing.cjs +125 -0
- package/dist/bluetooth/framing.d.cts +45 -0
- package/dist/bluetooth/framing.d.mts +45 -0
- package/dist/bluetooth/framing.mjs +122 -0
- package/dist/bluetooth/homey.cjs +155 -0
- package/dist/bluetooth/homey.d.cts +75 -0
- package/dist/bluetooth/homey.d.mts +75 -0
- package/dist/bluetooth/homey.mjs +150 -0
- package/dist/bluetooth/names.cjs +24 -0
- package/dist/bluetooth/names.d.cts +10 -0
- package/dist/bluetooth/names.d.mts +10 -0
- package/dist/bluetooth/names.mjs +20 -0
- package/dist/bluetooth/noble.cjs +178 -0
- package/dist/bluetooth/noble.d.cts +58 -0
- package/dist/bluetooth/noble.d.mts +58 -0
- package/dist/bluetooth/noble.mjs +177 -0
- package/dist/bluetooth/streamglue.cjs +157 -0
- package/dist/bluetooth/streamglue.d.cts +37 -0
- package/dist/bluetooth/streamglue.d.mts +37 -0
- package/dist/bluetooth/streamglue.mjs +154 -0
- package/dist/bluetooth/teslabluetooth.cjs +67 -0
- package/dist/bluetooth/teslabluetooth.d.cts +41 -0
- package/dist/bluetooth/teslabluetooth.d.mts +41 -0
- package/dist/bluetooth/teslabluetooth.mjs +66 -0
- package/dist/bluetooth/transport.cjs +10 -0
- package/dist/bluetooth/transport.d.cts +95 -0
- package/dist/bluetooth/transport.d.mts +95 -0
- package/dist/bluetooth/transport.mjs +10 -0
- package/dist/bluetooth/vehiclebluetooth.cjs +1272 -0
- package/dist/bluetooth/vehiclebluetooth.d.cts +495 -0
- package/dist/bluetooth/vehiclebluetooth.d.mts +495 -0
- package/dist/bluetooth/vehiclebluetooth.mjs +1270 -0
- package/dist/bluetooth/verify.cjs +93 -0
- package/dist/bluetooth/verify.d.cts +35 -0
- package/dist/bluetooth/verify.d.mts +35 -0
- package/dist/bluetooth/verify.mjs +91 -0
- package/dist/bluetooth.cjs +53 -0
- package/dist/bluetooth.d.cts +10 -0
- package/dist/bluetooth.d.mts +10 -0
- package/dist/bluetooth.mjs +9 -0
- package/dist/charging.cjs +53 -0
- package/dist/charging.d.cts +31 -0
- package/dist/charging.d.mts +30 -0
- package/dist/charging.mjs +53 -0
- package/dist/commands.cjs +1797 -0
- package/dist/commands.d.cts +881 -0
- package/dist/commands.d.mts +881 -0
- package/dist/commands.mjs +1791 -0
- package/dist/const.cjs +322 -0
- package/dist/const.d.cts +308 -0
- package/dist/const.d.mts +308 -0
- package/dist/const.mjs +282 -0
- package/dist/energy.cjs +142 -0
- package/dist/energy.d.cts +101 -0
- package/dist/energy.d.mts +100 -0
- package/dist/energy.mjs +142 -0
- package/dist/energyisland.cjs +38 -0
- package/dist/energyisland.mjs +37 -0
- package/dist/energyparsers.cjs +118 -0
- package/dist/energyparsers.d.cts +39 -0
- package/dist/energyparsers.d.mts +39 -0
- package/dist/energyparsers.mjs +116 -0
- package/dist/energyspecific.cjs +457 -0
- package/dist/energyspecific.d.cts +258 -0
- package/dist/energyspecific.d.mts +258 -0
- package/dist/energyspecific.mjs +451 -0
- package/dist/exceptions.cjs +1488 -0
- package/dist/exceptions.d.cts +1143 -0
- package/dist/exceptions.d.mts +1143 -0
- package/dist/exceptions.mjs +1325 -0
- package/dist/funnel.cjs +297 -0
- package/dist/funnel.d.cts +118 -0
- package/dist/funnel.d.mts +118 -0
- package/dist/funnel.mjs +292 -0
- package/dist/index.cjs +287 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.mjs +27 -0
- package/dist/log.cjs +75 -0
- package/dist/log.d.cts +4 -0
- package/dist/log.d.mts +4 -0
- package/dist/log.mjs +71 -0
- package/dist/oauth.cjs +143 -0
- package/dist/oauth.d.cts +69 -0
- package/dist/oauth.d.mts +69 -0
- package/dist/oauth.mjs +143 -0
- package/dist/partner.cjs +32 -0
- package/dist/partner.d.cts +24 -0
- package/dist/partner.d.mts +23 -0
- package/dist/partner.mjs +32 -0
- package/dist/powerwall/client.cjs +818 -0
- package/dist/powerwall/client.d.cts +297 -0
- package/dist/powerwall/client.d.mts +297 -0
- package/dist/powerwall/client.mjs +807 -0
- package/dist/powerwall/components.cjs +188 -0
- package/dist/powerwall/components.d.cts +45 -0
- package/dist/powerwall/components.d.mts +45 -0
- package/dist/powerwall/components.mjs +182 -0
- package/dist/powerwall/energysite.cjs +216 -0
- package/dist/powerwall/energysite.d.cts +104 -0
- package/dist/powerwall/energysite.d.mts +104 -0
- package/dist/powerwall/energysite.mjs +214 -0
- package/dist/powerwall/exceptions.cjs +59 -0
- package/dist/powerwall/exceptions.d.cts +38 -0
- package/dist/powerwall/exceptions.d.mts +38 -0
- package/dist/powerwall/exceptions.mjs +51 -0
- package/dist/powerwall/gateway.cjs +102 -0
- package/dist/powerwall/gateway.d.cts +57 -0
- package/dist/powerwall/gateway.d.mts +57 -0
- package/dist/powerwall/gateway.mjs +101 -0
- package/dist/powerwall/merge.cjs +163 -0
- package/dist/powerwall/merge.d.cts +63 -0
- package/dist/powerwall/merge.d.mts +63 -0
- package/dist/powerwall/merge.mjs +159 -0
- package/dist/powerwall/models.d.cts +95 -0
- package/dist/powerwall/models.d.mts +95 -0
- package/dist/powerwall/queries.cjs +17 -0
- package/dist/powerwall/queries.mjs +10 -0
- package/dist/powerwall/transport.cjs +232 -0
- package/dist/powerwall/transport.mjs +227 -0
- package/dist/powerwall.cjs +47 -0
- package/dist/powerwall.d.cts +9 -0
- package/dist/powerwall.d.mts +9 -0
- package/dist/powerwall.mjs +8 -0
- package/dist/router/base.cjs +203 -0
- package/dist/router/base.d.cts +112 -0
- package/dist/router/base.d.mts +112 -0
- package/dist/router/base.mjs +200 -0
- package/dist/router/energysite.cjs +65 -0
- package/dist/router/energysite.d.cts +47 -0
- package/dist/router/energysite.d.mts +47 -0
- package/dist/router/energysite.mjs +60 -0
- package/dist/router.cjs +13 -0
- package/dist/router.d.cts +3 -0
- package/dist/router.d.mts +3 -0
- package/dist/router.mjs +3 -0
- package/dist/signing/crypto.cjs +59 -0
- package/dist/signing/crypto.mjs +52 -0
- package/dist/signing/energy.cjs +123 -0
- package/dist/signing/energy.d.cts +45 -0
- package/dist/signing/energy.d.mts +45 -0
- package/dist/signing/energy.mjs +120 -0
- package/dist/signing/jws.cjs +229 -0
- package/dist/signing/jws.d.cts +45 -0
- package/dist/signing/jws.d.mts +45 -0
- package/dist/signing/jws.mjs +211 -0
- package/dist/signing/keys.cjs +191 -0
- package/dist/signing/keys.d.cts +21 -0
- package/dist/signing/keys.d.mts +21 -0
- package/dist/signing/keys.mjs +182 -0
- package/dist/signing/session.cjs +186 -0
- package/dist/signing/session.d.cts +106 -0
- package/dist/signing/session.d.mts +106 -0
- package/dist/signing/session.mjs +184 -0
- package/dist/tariff.cjs +319 -0
- package/dist/tariff.d.cts +40 -0
- package/dist/tariff.d.mts +40 -0
- package/dist/tariff.mjs +317 -0
- package/dist/teslafleetapi.cjs +326 -0
- package/dist/teslafleetapi.d.cts +160 -0
- package/dist/teslafleetapi.d.mts +160 -0
- package/dist/teslafleetapi.mjs +326 -0
- package/dist/teslemetry.cjs +183 -0
- package/dist/teslemetry.d.cts +113 -0
- package/dist/teslemetry.d.mts +113 -0
- package/dist/teslemetry.mjs +181 -0
- package/dist/teslemetryenergy.cjs +287 -0
- package/dist/teslemetryenergy.d.cts +154 -0
- package/dist/teslemetryenergy.d.mts +154 -0
- package/dist/teslemetryenergy.mjs +282 -0
- package/dist/teslemetryvehicle.cjs +407 -0
- package/dist/teslemetryvehicle.d.cts +238 -0
- package/dist/teslemetryvehicle.d.mts +238 -0
- package/dist/teslemetryvehicle.mjs +405 -0
- package/dist/tessie.cjs +71 -0
- package/dist/tessie.d.cts +69 -0
- package/dist/tessie.d.mts +69 -0
- package/dist/tessie.mjs +71 -0
- package/dist/tessievehicle.cjs +514 -0
- package/dist/tessievehicle.d.cts +333 -0
- package/dist/tessievehicle.d.mts +333 -0
- package/dist/tessievehicle.mjs +513 -0
- package/dist/types/commands.d.cts +28 -0
- package/dist/types/commands.d.mts +28 -0
- package/dist/types/live_status.d.cts +30 -0
- package/dist/types/live_status.d.mts +30 -0
- package/dist/types/products.d.cts +58 -0
- package/dist/types/products.d.mts +58 -0
- package/dist/types/responses.d.cts +13 -0
- package/dist/types/responses.d.mts +13 -0
- package/dist/types/site_info.d.cts +154 -0
- package/dist/types/site_info.d.mts +154 -0
- package/dist/types/vehicle.d.cts +33 -0
- package/dist/types/vehicle.d.mts +33 -0
- package/dist/types/vehicle_data.d.cts +278 -0
- package/dist/types/vehicle_data.d.mts +278 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +9 -0
- package/dist/types.d.mts +9 -0
- package/dist/types.mjs +1 -0
- package/dist/user.cjs +28 -0
- package/dist/user.d.cts +17 -0
- package/dist/user.d.mts +16 -0
- package/dist/user.mjs +28 -0
- package/dist/util.cjs +41 -0
- package/dist/util.d.cts +18 -0
- package/dist/util.d.mts +18 -0
- package/dist/util.mjs +40 -0
- package/dist/vehicle.cjs +847 -0
- package/dist/vehicle.d.cts +566 -0
- package/dist/vehicle.d.mts +565 -0
- package/dist/vehicle.mjs +847 -0
- package/dist/vehiclesigned.cjs +35 -0
- package/dist/vehiclesigned.d.cts +23 -0
- package/dist/vehiclesigned.d.mts +22 -0
- package/dist/vehiclesigned.mjs +35 -0
- package/dist/vehiclespecific.cjs +715 -0
- package/dist/vehiclespecific.d.cts +497 -0
- package/dist/vehiclespecific.d.mts +496 -0
- package/dist/vehiclespecific.mjs +715 -0
- package/package.json +178 -38
- package/dist/charging.d.ts +0 -30
- package/dist/charging.js +0 -51
- package/dist/charging.js.map +0 -1
- package/dist/commands.d.ts +0 -352
- package/dist/commands.js +0 -875
- package/dist/commands.js.map +0 -1
- package/dist/energy.d.ts +0 -94
- package/dist/energy.js +0 -125
- package/dist/energy.js.map +0 -1
- package/dist/energyspecific.d.ts +0 -77
- package/dist/energyspecific.js +0 -97
- package/dist/energyspecific.js.map +0 -1
- package/dist/helpers.d.ts +0 -2
- package/dist/helpers.js +0 -10
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/partner.d.ts +0 -23
- package/dist/partner.js +0 -31
- package/dist/partner.js.map +0 -1
- package/dist/signing/crypto.d.ts +0 -10
- package/dist/signing/crypto.js +0 -26
- package/dist/signing/crypto.js.map +0 -1
- package/dist/signing/errors.d.ts +0 -29
- package/dist/signing/errors.js +0 -40
- package/dist/signing/errors.js.map +0 -1
- package/dist/signing/session.d.ts +0 -69
- package/dist/signing/session.js +0 -102
- package/dist/signing/session.js.map +0 -1
- package/dist/tariff.d.ts +0 -29
- package/dist/tariff.js +0 -302
- package/dist/tariff.js.map +0 -1
- package/dist/teslafleetapi.d.ts +0 -58
- package/dist/teslafleetapi.js +0 -120
- package/dist/teslafleetapi.js.map +0 -1
- package/dist/teslemetry.d.ts +0 -29
- package/dist/teslemetry.js +0 -39
- package/dist/teslemetry.js.map +0 -1
- package/dist/tessie.d.ts +0 -23
- package/dist/tessie.js +0 -28
- package/dist/tessie.js.map +0 -1
- package/dist/types/commands.d.ts +0 -44
- package/dist/types/commands.js +0 -11
- package/dist/types/commands.js.map +0 -1
- package/dist/types/live_status.d.ts +0 -26
- package/dist/types/live_status.js +0 -2
- package/dist/types/live_status.js.map +0 -1
- package/dist/types/products.d.ts +0 -54
- package/dist/types/products.js +0 -2
- package/dist/types/products.js.map +0 -1
- package/dist/types/responses.d.ts +0 -5
- package/dist/types/responses.js +0 -2
- package/dist/types/responses.js.map +0 -1
- package/dist/types/site_info.d.ts +0 -150
- package/dist/types/site_info.js +0 -2
- package/dist/types/site_info.js.map +0 -1
- package/dist/types/vehicle.d.ts +0 -23
- package/dist/types/vehicle.js +0 -10
- package/dist/types/vehicle.js.map +0 -1
- package/dist/types/vehicle_data.d.ts +0 -274
- package/dist/types/vehicle_data.js +0 -2
- package/dist/types/vehicle_data.js.map +0 -1
- package/dist/user.d.ts +0 -16
- package/dist/user.js +0 -26
- package/dist/user.js.map +0 -1
- package/dist/vehicle.d.ts +0 -548
- package/dist/vehicle.js +0 -774
- package/dist/vehicle.js.map +0 -1
- package/dist/vehiclesigned.d.ts +0 -13
- package/dist/vehiclesigned.js +0 -19
- package/dist/vehiclesigned.js.map +0 -1
- package/dist/vehiclespecific.d.ts +0 -432
- package/dist/vehiclespecific.js +0 -601
- package/dist/vehiclespecific.js.map +0 -1
- package/src/charging.ts +0 -66
- package/src/commands.ts +0 -1134
- package/src/energy.ts +0 -217
- package/src/energyspecific.ts +0 -116
- package/src/helpers.ts +0 -11
- package/src/index.ts +0 -21
- package/src/partner.ts +0 -37
- package/src/signing/crypto.ts +0 -29
- package/src/signing/errors.ts +0 -50
- package/src/signing/session.ts +0 -132
- package/src/tariff.ts +0 -375
- package/src/teslafleetapi.ts +0 -182
- package/src/teslemetry.ts +0 -54
- package/src/tessie.ts +0 -42
- package/src/types/commands.ts +0 -62
- package/src/types/live_status.ts +0 -27
- package/src/types/products.ts +0 -61
- package/src/types/responses.ts +0 -1
- package/src/types/site_info.ts +0 -159
- package/src/types/vehicle.ts +0 -33
- package/src/types/vehicle_data.ts +0 -286
- package/src/user.ts +0 -35
- package/src/vehicle.ts +0 -886
- package/src/vehiclesigned.ts +0 -20
- package/src/vehiclespecific.ts +0 -818
package/dist/oauth.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { SERVERS, TOKEN_URLS, is_valid_region } from "./const.mjs";
|
|
2
|
+
import { InvalidResponse, MissingToken, TeslaFleetConnectionError, TeslaFleetError } from "./exceptions.mjs";
|
|
3
|
+
import TeslaFleetApi from "./teslafleetapi.mjs";
|
|
4
|
+
// src/oauth.ts
|
|
5
|
+
function nowSeconds() {
|
|
6
|
+
return Date.now() / 1e3;
|
|
7
|
+
}
|
|
8
|
+
/** The fields every token reply needs; a reply without them must not replace a working token. */
|
|
9
|
+
function tokenFrom(data) {
|
|
10
|
+
if (typeof data?.access_token !== "string" || typeof data.expires_in !== "number") throw new InvalidResponse();
|
|
11
|
+
return {
|
|
12
|
+
access_token: data.access_token,
|
|
13
|
+
expires: Math.floor(nowSeconds()) + data.expires_in
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Tesla Fleet API client that signs a user in with OAuth and keeps its access
|
|
18
|
+
* token fresh. `expires` is in epoch seconds, as in Python, so a stored
|
|
19
|
+
* token works with either library.
|
|
20
|
+
*/
|
|
21
|
+
var TeslaFleetOAuth = class extends TeslaFleetApi {
|
|
22
|
+
client_id;
|
|
23
|
+
redirect_uri;
|
|
24
|
+
refresh_token;
|
|
25
|
+
/** Expiry of the access token, in epoch seconds. */
|
|
26
|
+
expires;
|
|
27
|
+
#client_secret;
|
|
28
|
+
#refreshing = null;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
if (!is_valid_region(options.region)) throw new Error("Invalid region");
|
|
31
|
+
const { region, client_id, client_secret, redirect_uri, access_token, refresh_token, expires, ...rest } = options;
|
|
32
|
+
super({
|
|
33
|
+
...rest,
|
|
34
|
+
region,
|
|
35
|
+
accessToken: access_token
|
|
36
|
+
});
|
|
37
|
+
this.client_id = client_id;
|
|
38
|
+
this.#client_secret = client_secret ?? null;
|
|
39
|
+
this.redirect_uri = redirect_uri ?? null;
|
|
40
|
+
this.refresh_token = refresh_token ?? null;
|
|
41
|
+
this.expires = expires ?? 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The URL to send the user to, built exactly as Python builds it: values are
|
|
45
|
+
* not URL-encoded.
|
|
46
|
+
* @param scopes Scopes to request.
|
|
47
|
+
* @param state Value Tesla echoes back on the redirect.
|
|
48
|
+
*/
|
|
49
|
+
get_login_url(scopes, state = "login") {
|
|
50
|
+
if (this.redirect_uri == null) throw new Error("Redirect URI is missing");
|
|
51
|
+
return `https://${this.region === "cn" ? "auth.tesla.cn" : "auth.tesla.com"}/oauth2/v3/authorize?response_type=code&client_id=${this.client_id}&redirect_uri=${this.redirect_uri}&scope=${scopes.join("+")}&state=${state}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Exchange an authorization code for tokens. A code prefixed with a region
|
|
55
|
+
* (e.g. `NA_...`) also selects that region's server.
|
|
56
|
+
* @param code The code from the login redirect.
|
|
57
|
+
*/
|
|
58
|
+
async get_refresh_token(code) {
|
|
59
|
+
if (this.#client_secret == null) throw new Error("Client secret is missing");
|
|
60
|
+
if (this.redirect_uri == null) throw new Error("Redirect URI is missing");
|
|
61
|
+
this.server ??= SERVERS[this.region ?? "na"];
|
|
62
|
+
const data = await this.#token({
|
|
63
|
+
grant_type: "authorization_code",
|
|
64
|
+
client_id: this.client_id,
|
|
65
|
+
client_secret: this.#client_secret,
|
|
66
|
+
code,
|
|
67
|
+
audience: this.server,
|
|
68
|
+
redirect_uri: this.redirect_uri
|
|
69
|
+
});
|
|
70
|
+
const { access_token, expires } = tokenFrom(data);
|
|
71
|
+
this.refresh_token = data.refresh_token ?? null;
|
|
72
|
+
this.accessToken = access_token;
|
|
73
|
+
this.expires = expires;
|
|
74
|
+
const region = code.split("_")[0].toLowerCase();
|
|
75
|
+
if (is_valid_region(region)) this.server = SERVERS[region];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The current access token, refreshed first when `expires` has passed.
|
|
79
|
+
* @throws MissingToken when there is no token and none can be refreshed.
|
|
80
|
+
*/
|
|
81
|
+
async access_token() {
|
|
82
|
+
if (this.expires < nowSeconds()) await this.refresh_access_token();
|
|
83
|
+
if (this.accessToken && typeof this.accessToken === "string") return this.accessToken;
|
|
84
|
+
throw new MissingToken("Access token is missing");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Refresh the access token if it is missing or expired.
|
|
88
|
+
* @returns The refreshed token to persist, or `null` when none was needed.
|
|
89
|
+
*/
|
|
90
|
+
async check_access_token() {
|
|
91
|
+
if (this.accessToken && this.expires > nowSeconds()) return null;
|
|
92
|
+
return this.refresh_access_token();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Refresh the access token. Tesla rotates the refresh token, so persist what
|
|
96
|
+
* this returns.
|
|
97
|
+
* @throws MissingToken without a refresh token, or the `TeslaFleetError`
|
|
98
|
+
* matching the failure, e.g. `LoginRequired`.
|
|
99
|
+
*/
|
|
100
|
+
refresh_access_token() {
|
|
101
|
+
this.#refreshing ??= this.#refresh().finally(() => {
|
|
102
|
+
this.#refreshing = null;
|
|
103
|
+
});
|
|
104
|
+
return this.#refreshing;
|
|
105
|
+
}
|
|
106
|
+
async #refresh() {
|
|
107
|
+
if (!this.refresh_token) throw new MissingToken("Refresh token is missing");
|
|
108
|
+
const data = await this.#token({
|
|
109
|
+
grant_type: "refresh_token",
|
|
110
|
+
client_id: this.client_id,
|
|
111
|
+
refresh_token: this.refresh_token
|
|
112
|
+
});
|
|
113
|
+
const { access_token, expires } = tokenFrom(data);
|
|
114
|
+
if (typeof data.refresh_token !== "string") throw new InvalidResponse();
|
|
115
|
+
this.accessToken = access_token;
|
|
116
|
+
this.refresh_token = data.refresh_token;
|
|
117
|
+
this.expires = expires;
|
|
118
|
+
return {
|
|
119
|
+
refresh_token: data.refresh_token,
|
|
120
|
+
expires
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** POST a form to the region's token endpoint. Bypasses `_request`, which would log the reply. */
|
|
124
|
+
async #token(form) {
|
|
125
|
+
try {
|
|
126
|
+
const resp = await this._fetch(TOKEN_URLS[this.region ?? "na"], {
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
129
|
+
body: new URLSearchParams(form),
|
|
130
|
+
signal: this.timeout != null ? AbortSignal.timeout(this.timeout) : null
|
|
131
|
+
});
|
|
132
|
+
return await this._response(resp);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof TeslaFleetError) throw error;
|
|
135
|
+
throw new TeslaFleetConnectionError(null, null, { cause: error });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async _request(method, path, params = null, json = null) {
|
|
139
|
+
await this.check_access_token();
|
|
140
|
+
return super._request(method, path, params, json);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
export { TeslaFleetOAuth as default };
|
package/dist/partner.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/partner.ts
|
|
2
|
+
var Partner = class {
|
|
3
|
+
parent;
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
this.parent = parent;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns the public key associated with a domain. It can be used to ensure the registration was successful.
|
|
9
|
+
* @param domain Domain of the partner account.
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
async public_key(domain = null) {
|
|
13
|
+
return this.parent._request("GET", "api/1/partner_accounts/public_key", { domain });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers an existing account before it can be used for general API access. Each application from developer.tesla.com must complete this step.
|
|
17
|
+
* @param domain Domain of the partner account.
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
async register(domain) {
|
|
21
|
+
return this.parent._request("POST", "api/1/partner_accounts", null, { domain });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns recent fleet telemetry errors reported by vehicles after receiving the config.
|
|
25
|
+
* @param domain Domain of the partner account.
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
async fleet_telemetry_errors(domain) {
|
|
29
|
+
return this.parent._request("GET", "api/1/partner_accounts/fleet_telemetry_errors", { domain });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.default = Partner;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.cjs";
|
|
2
|
+
declare class Partner {
|
|
3
|
+
parent: TeslaFleetApi;
|
|
4
|
+
constructor(parent: TeslaFleetApi);
|
|
5
|
+
/**
|
|
6
|
+
* Returns the public key associated with a domain. It can be used to ensure the registration was successful.
|
|
7
|
+
* @param domain Domain of the partner account.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
public_key(domain?: string | null): Promise<Record<string, any>>;
|
|
11
|
+
/**
|
|
12
|
+
* Registers an existing account before it can be used for general API access. Each application from developer.tesla.com must complete this step.
|
|
13
|
+
* @param domain Domain of the partner account.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
register(domain: string): Promise<Record<string, any>>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns recent fleet telemetry errors reported by vehicles after receiving the config.
|
|
19
|
+
* @param domain Domain of the partner account.
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
fleet_telemetry_errors(domain: string): Promise<Record<string, any>>;
|
|
23
|
+
}
|
|
24
|
+
export = Partner;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import TeslaFleetApi from "./teslafleetapi.mjs";
|
|
2
|
+
export default class Partner {
|
|
3
|
+
parent: TeslaFleetApi;
|
|
4
|
+
constructor(parent: TeslaFleetApi);
|
|
5
|
+
/**
|
|
6
|
+
* Returns the public key associated with a domain. It can be used to ensure the registration was successful.
|
|
7
|
+
* @param domain Domain of the partner account.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
public_key(domain?: string | null): Promise<Record<string, any>>;
|
|
11
|
+
/**
|
|
12
|
+
* Registers an existing account before it can be used for general API access. Each application from developer.tesla.com must complete this step.
|
|
13
|
+
* @param domain Domain of the partner account.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
register(domain: string): Promise<Record<string, any>>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns recent fleet telemetry errors reported by vehicles after receiving the config.
|
|
19
|
+
* @param domain Domain of the partner account.
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
fleet_telemetry_errors(domain: string): Promise<Record<string, any>>;
|
|
23
|
+
}
|
package/dist/partner.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/partner.ts
|
|
2
|
+
var Partner = class {
|
|
3
|
+
parent;
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
this.parent = parent;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns the public key associated with a domain. It can be used to ensure the registration was successful.
|
|
9
|
+
* @param domain Domain of the partner account.
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
async public_key(domain = null) {
|
|
13
|
+
return this.parent._request("GET", "api/1/partner_accounts/public_key", { domain });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers an existing account before it can be used for general API access. Each application from developer.tesla.com must complete this step.
|
|
17
|
+
* @param domain Domain of the partner account.
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
async register(domain) {
|
|
21
|
+
return this.parent._request("POST", "api/1/partner_accounts", null, { domain });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns recent fleet telemetry errors reported by vehicles after receiving the config.
|
|
25
|
+
* @param domain Domain of the partner account.
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
async fleet_telemetry_errors(domain) {
|
|
29
|
+
return this.parent._request("GET", "api/1/partner_accounts/fleet_telemetry_errors", { domain });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export { Partner as default };
|