openbyd 0.0.0-stage → 0.1.2
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 +147 -2
- package/dist/client.d.ts +168 -0
- package/dist/client.js +374 -0
- package/dist/functions.d.ts +32 -0
- package/dist/functions.js +48 -0
- package/dist/generated/errors.d.ts +114 -0
- package/dist/generated/errors.js +167 -0
- package/dist/generated/methods.d.ts +461 -0
- package/dist/generated/methods.js +926 -0
- package/dist/generated/models.d.ts +1361 -0
- package/dist/generated/models.js +191 -0
- package/dist/generated/shapes.d.ts +45 -0
- package/dist/generated/shapes.js +164 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +51 -0
- package/dist/native.d.ts +32 -0
- package/dist/native.js +53 -0
- package/dist/testing.d.ts +127 -0
- package/dist/testing.js +140 -0
- package/dist/wire.d.ts +32 -0
- package/dist/wire.js +130 -0
- package/package.json +53 -4
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** What needs no client: the envelope cipher, pyBYD's models by name, the runtime's settings. */
|
|
2
|
+
import type { JsonObject, Models } from "./generated/models.js";
|
|
3
|
+
/** The version of openbyd's core. */
|
|
4
|
+
export declare function version(): string;
|
|
5
|
+
/** Wraps plaintext (text, or bytes) in a Bangcle envelope, as BYD's app does with every request. */
|
|
6
|
+
export declare function encodeEnvelope(plaintext: string | Uint8Array): string;
|
|
7
|
+
/** Opens a Bangcle envelope and returns the plaintext bytes. Throws `BangcleError` for a bad envelope. */
|
|
8
|
+
export declare function decodeEnvelope(envelope: string): Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Parses a raw payload (a reply's `respondData`, an MQTT event's data) as
|
|
11
|
+
* one of pyBYD's reply models: `Model.model_validate(raw).model_dump(mode="json")`.
|
|
12
|
+
* Throws `ValidationError` when it does not validate.
|
|
13
|
+
*
|
|
14
|
+
* @param context - pyBYD's validation context, for the models that take one.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseModel<Name extends keyof Models>(name: Name, raw: JsonObject, context?: JsonObject): Models[Name];
|
|
17
|
+
/** The state of the Rust runtime every client shares. */
|
|
18
|
+
export interface RuntimeInfo {
|
|
19
|
+
/** The runtime's worker threads. */
|
|
20
|
+
readonly worker_threads: number;
|
|
21
|
+
/** Whether the runtime has started: after the first client or call. */
|
|
22
|
+
readonly started: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** The state of the Rust runtime every client shares. */
|
|
25
|
+
export declare function runtimeInfo(): RuntimeInfo;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the worker threads of the Rust runtime (2 by default). Only before
|
|
28
|
+
* the runtime starts, which the first client does.
|
|
29
|
+
*/
|
|
30
|
+
export declare function configureRuntime(options: {
|
|
31
|
+
workerThreads: number;
|
|
32
|
+
}): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** What needs no client: the envelope cipher, pyBYD's models by name, the runtime's settings. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.version = version;
|
|
5
|
+
exports.encodeEnvelope = encodeEnvelope;
|
|
6
|
+
exports.decodeEnvelope = decodeEnvelope;
|
|
7
|
+
exports.parseModel = parseModel;
|
|
8
|
+
exports.runtimeInfo = runtimeInfo;
|
|
9
|
+
exports.configureRuntime = configureRuntime;
|
|
10
|
+
const shapes_js_1 = require("./generated/shapes.js");
|
|
11
|
+
const wire_js_1 = require("./wire.js");
|
|
12
|
+
/** The version of openbyd's core. */
|
|
13
|
+
function version() {
|
|
14
|
+
return (0, wire_js_1.callFunction)("version");
|
|
15
|
+
}
|
|
16
|
+
/** Wraps plaintext (text, or bytes) in a Bangcle envelope, as BYD's app does with every request. */
|
|
17
|
+
function encodeEnvelope(plaintext) {
|
|
18
|
+
if (typeof plaintext === "string")
|
|
19
|
+
return (0, wire_js_1.callFunction)("encode_envelope", { text: plaintext });
|
|
20
|
+
return (0, wire_js_1.callFunction)("encode_envelope", { hex: Buffer.from(plaintext).toString("hex") });
|
|
21
|
+
}
|
|
22
|
+
/** Opens a Bangcle envelope and returns the plaintext bytes. Throws `BangcleError` for a bad envelope. */
|
|
23
|
+
function decodeEnvelope(envelope) {
|
|
24
|
+
const { hex } = (0, wire_js_1.callFunction)("decode_envelope", { envelope });
|
|
25
|
+
return Buffer.from(hex, "hex");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses a raw payload (a reply's `respondData`, an MQTT event's data) as
|
|
29
|
+
* one of pyBYD's reply models: `Model.model_validate(raw).model_dump(mode="json")`.
|
|
30
|
+
* Throws `ValidationError` when it does not validate.
|
|
31
|
+
*
|
|
32
|
+
* @param context - pyBYD's validation context, for the models that take one.
|
|
33
|
+
*/
|
|
34
|
+
function parseModel(name, raw, context) {
|
|
35
|
+
const parsed = (0, wire_js_1.callFunction)("parse_model", { name: shapes_js_1.MODEL_CALLS[name], raw, context });
|
|
36
|
+
return (0, wire_js_1.revive)(parsed.dump, ["struct", name]);
|
|
37
|
+
}
|
|
38
|
+
/** The state of the Rust runtime every client shares. */
|
|
39
|
+
function runtimeInfo() {
|
|
40
|
+
return (0, wire_js_1.callFunction)("runtime");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets the worker threads of the Rust runtime (2 by default). Only before
|
|
44
|
+
* the runtime starts, which the first client does.
|
|
45
|
+
*/
|
|
46
|
+
function configureRuntime(options) {
|
|
47
|
+
(0, wire_js_1.callFunction)("configure", { worker_threads: options.workerThreads });
|
|
48
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** What an error is built from: its fields, whichever its class carries. */
|
|
2
|
+
export interface ErrorDetails {
|
|
3
|
+
readonly kind: string;
|
|
4
|
+
readonly statusCode?: number | null | undefined;
|
|
5
|
+
readonly endpoint?: string | null | undefined;
|
|
6
|
+
readonly code?: string | null | undefined;
|
|
7
|
+
readonly errorType?: string | null | undefined;
|
|
8
|
+
readonly loc?: string[] | null | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base of every error openbyd raises. `kind` is the name of the Python exception class pyBYD
|
|
12
|
+
* raises for the same failure.
|
|
13
|
+
*/
|
|
14
|
+
export declare class OpenBydError extends Error {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** The name of the Python exception class pyBYD raises. */
|
|
17
|
+
readonly kind: string;
|
|
18
|
+
constructor(message: string, details: ErrorDetails);
|
|
19
|
+
}
|
|
20
|
+
/** Base of pyBYD's errors. */
|
|
21
|
+
export declare class BydError extends OpenBydError {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
}
|
|
24
|
+
/** Encryption or decryption failed. */
|
|
25
|
+
export declare class BydCryptoError extends BydError {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
}
|
|
28
|
+
/** A Bangcle envelope could not be encoded or decoded. */
|
|
29
|
+
export declare class BangcleError extends BydCryptoError {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
}
|
|
32
|
+
/** The Bangcle lookup tables could not be loaded. */
|
|
33
|
+
export declare class BangcleTableLoadError extends BangcleError {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
}
|
|
36
|
+
/** HTTP-level failure: the network, a status other than 200, a body that is not JSON. */
|
|
37
|
+
export declare class BydTransportError extends BydError {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
/** The HTTP status, when the server answered. */
|
|
40
|
+
readonly statusCode: number | null;
|
|
41
|
+
/** The endpoint that failed. */
|
|
42
|
+
readonly endpoint: string;
|
|
43
|
+
constructor(message: string, details: ErrorDetails);
|
|
44
|
+
}
|
|
45
|
+
/** The API answered with a code other than 0. */
|
|
46
|
+
export declare class BydApiError extends BydError {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/** The API's code, such as `1005`. */
|
|
49
|
+
readonly code: string;
|
|
50
|
+
/** The endpoint that failed. */
|
|
51
|
+
readonly endpoint: string;
|
|
52
|
+
constructor(message: string, details: ErrorDetails);
|
|
53
|
+
}
|
|
54
|
+
/** Login failed or the session expired. */
|
|
55
|
+
export declare class BydAuthenticationError extends BydApiError {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
}
|
|
58
|
+
/** The server rejected the session token (for example code `1005`). */
|
|
59
|
+
export declare class BydSessionExpiredError extends BydAuthenticationError {
|
|
60
|
+
readonly name: string;
|
|
61
|
+
}
|
|
62
|
+
/** A remote control command failed after the cloud accepted it. */
|
|
63
|
+
export declare class BydRemoteControlError extends BydApiError {
|
|
64
|
+
readonly name: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A remote control command was rejected for an invalid or locked operation password (codes
|
|
68
|
+
* `5005`, `5006`, `5011`).
|
|
69
|
+
*/
|
|
70
|
+
export declare class BydControlPasswordError extends BydApiError {
|
|
71
|
+
readonly name: string;
|
|
72
|
+
}
|
|
73
|
+
/** The endpoint is not supported for this vehicle or region (for example code `1001`). */
|
|
74
|
+
export declare class BydEndpointNotSupportedError extends BydApiError {
|
|
75
|
+
readonly name: string;
|
|
76
|
+
}
|
|
77
|
+
/** The vehicle cannot provide the data right now (for example GPS code `6051`). */
|
|
78
|
+
export declare class BydDataUnavailableError extends BydApiError {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
}
|
|
81
|
+
/** A previous command is still in progress (code `6024`). */
|
|
82
|
+
export declare class BydRateLimitError extends BydApiError {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
}
|
|
85
|
+
/** The backend is busy (code `1008`); keep the last data and back off. */
|
|
86
|
+
export declare class BydServiceBusyError extends BydApiError {
|
|
87
|
+
readonly name: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A value could not be used: an argument, or a reply that is not what it should be. `kind`
|
|
91
|
+
* names the Python built-in exception pyBYD lets through (`ValueError`, `TypeError`,
|
|
92
|
+
* `JSONDecodeError`, ...).
|
|
93
|
+
*/
|
|
94
|
+
export declare class DataError extends OpenBydError {
|
|
95
|
+
readonly name: string;
|
|
96
|
+
}
|
|
97
|
+
/** A reply or a parameter did not validate, where pyBYD raises pydantic's `ValidationError`. */
|
|
98
|
+
export declare class ValidationError extends DataError {
|
|
99
|
+
readonly name: string;
|
|
100
|
+
/** pydantic's error type, such as `int_parsing`. */
|
|
101
|
+
readonly errorType: string;
|
|
102
|
+
/** Where the bad value was, outermost first. */
|
|
103
|
+
readonly loc: string[];
|
|
104
|
+
constructor(message: string, details: ErrorDetails);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A wait for an MQTT push was cut short because the client stopped its MQTT channel, for
|
|
108
|
+
* example when it was closed.
|
|
109
|
+
*/
|
|
110
|
+
export declare class CancelledError extends OpenBydError {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
}
|
|
113
|
+
/** The error class for each Python exception class the core reports. */
|
|
114
|
+
export declare const ERROR_CLASSES: Readonly<Record<string, new (message: string, details: ErrorDetails) => OpenBydError>>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Generated by bindings/generate.py from bindings/spec.py and pyBYD
|
|
3
|
+
// 2c3d80648e8eeec50cd4f68f603abd3a01010fef. Do not edit: change the spec and run the generator.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ERROR_CLASSES = exports.CancelledError = exports.ValidationError = exports.DataError = exports.BydServiceBusyError = exports.BydRateLimitError = exports.BydDataUnavailableError = exports.BydEndpointNotSupportedError = exports.BydControlPasswordError = exports.BydRemoteControlError = exports.BydSessionExpiredError = exports.BydAuthenticationError = exports.BydApiError = exports.BydTransportError = exports.BangcleTableLoadError = exports.BangcleError = exports.BydCryptoError = exports.BydError = exports.OpenBydError = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Base of every error openbyd raises. `kind` is the name of the Python exception class pyBYD
|
|
8
|
+
* raises for the same failure.
|
|
9
|
+
*/
|
|
10
|
+
class OpenBydError extends Error {
|
|
11
|
+
name = "OpenBydError";
|
|
12
|
+
/** The name of the Python exception class pyBYD raises. */
|
|
13
|
+
kind;
|
|
14
|
+
constructor(message, details) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.kind = details.kind;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.OpenBydError = OpenBydError;
|
|
20
|
+
/** Base of pyBYD's errors. */
|
|
21
|
+
class BydError extends OpenBydError {
|
|
22
|
+
name = "BydError";
|
|
23
|
+
}
|
|
24
|
+
exports.BydError = BydError;
|
|
25
|
+
/** Encryption or decryption failed. */
|
|
26
|
+
class BydCryptoError extends BydError {
|
|
27
|
+
name = "BydCryptoError";
|
|
28
|
+
}
|
|
29
|
+
exports.BydCryptoError = BydCryptoError;
|
|
30
|
+
/** A Bangcle envelope could not be encoded or decoded. */
|
|
31
|
+
class BangcleError extends BydCryptoError {
|
|
32
|
+
name = "BangcleError";
|
|
33
|
+
}
|
|
34
|
+
exports.BangcleError = BangcleError;
|
|
35
|
+
/** The Bangcle lookup tables could not be loaded. */
|
|
36
|
+
class BangcleTableLoadError extends BangcleError {
|
|
37
|
+
name = "BangcleTableLoadError";
|
|
38
|
+
}
|
|
39
|
+
exports.BangcleTableLoadError = BangcleTableLoadError;
|
|
40
|
+
/** HTTP-level failure: the network, a status other than 200, a body that is not JSON. */
|
|
41
|
+
class BydTransportError extends BydError {
|
|
42
|
+
name = "BydTransportError";
|
|
43
|
+
/** The HTTP status, when the server answered. */
|
|
44
|
+
statusCode;
|
|
45
|
+
/** The endpoint that failed. */
|
|
46
|
+
endpoint;
|
|
47
|
+
constructor(message, details) {
|
|
48
|
+
super(message, details);
|
|
49
|
+
this.statusCode = details.statusCode ?? null;
|
|
50
|
+
this.endpoint = details.endpoint ?? "";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.BydTransportError = BydTransportError;
|
|
54
|
+
/** The API answered with a code other than 0. */
|
|
55
|
+
class BydApiError extends BydError {
|
|
56
|
+
name = "BydApiError";
|
|
57
|
+
/** The API's code, such as `1005`. */
|
|
58
|
+
code;
|
|
59
|
+
/** The endpoint that failed. */
|
|
60
|
+
endpoint;
|
|
61
|
+
constructor(message, details) {
|
|
62
|
+
super(message, details);
|
|
63
|
+
this.code = details.code ?? "";
|
|
64
|
+
this.endpoint = details.endpoint ?? "";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.BydApiError = BydApiError;
|
|
68
|
+
/** Login failed or the session expired. */
|
|
69
|
+
class BydAuthenticationError extends BydApiError {
|
|
70
|
+
name = "BydAuthenticationError";
|
|
71
|
+
}
|
|
72
|
+
exports.BydAuthenticationError = BydAuthenticationError;
|
|
73
|
+
/** The server rejected the session token (for example code `1005`). */
|
|
74
|
+
class BydSessionExpiredError extends BydAuthenticationError {
|
|
75
|
+
name = "BydSessionExpiredError";
|
|
76
|
+
}
|
|
77
|
+
exports.BydSessionExpiredError = BydSessionExpiredError;
|
|
78
|
+
/** A remote control command failed after the cloud accepted it. */
|
|
79
|
+
class BydRemoteControlError extends BydApiError {
|
|
80
|
+
name = "BydRemoteControlError";
|
|
81
|
+
}
|
|
82
|
+
exports.BydRemoteControlError = BydRemoteControlError;
|
|
83
|
+
/**
|
|
84
|
+
* A remote control command was rejected for an invalid or locked operation password (codes
|
|
85
|
+
* `5005`, `5006`, `5011`).
|
|
86
|
+
*/
|
|
87
|
+
class BydControlPasswordError extends BydApiError {
|
|
88
|
+
name = "BydControlPasswordError";
|
|
89
|
+
}
|
|
90
|
+
exports.BydControlPasswordError = BydControlPasswordError;
|
|
91
|
+
/** The endpoint is not supported for this vehicle or region (for example code `1001`). */
|
|
92
|
+
class BydEndpointNotSupportedError extends BydApiError {
|
|
93
|
+
name = "BydEndpointNotSupportedError";
|
|
94
|
+
}
|
|
95
|
+
exports.BydEndpointNotSupportedError = BydEndpointNotSupportedError;
|
|
96
|
+
/** The vehicle cannot provide the data right now (for example GPS code `6051`). */
|
|
97
|
+
class BydDataUnavailableError extends BydApiError {
|
|
98
|
+
name = "BydDataUnavailableError";
|
|
99
|
+
}
|
|
100
|
+
exports.BydDataUnavailableError = BydDataUnavailableError;
|
|
101
|
+
/** A previous command is still in progress (code `6024`). */
|
|
102
|
+
class BydRateLimitError extends BydApiError {
|
|
103
|
+
name = "BydRateLimitError";
|
|
104
|
+
}
|
|
105
|
+
exports.BydRateLimitError = BydRateLimitError;
|
|
106
|
+
/** The backend is busy (code `1008`); keep the last data and back off. */
|
|
107
|
+
class BydServiceBusyError extends BydApiError {
|
|
108
|
+
name = "BydServiceBusyError";
|
|
109
|
+
}
|
|
110
|
+
exports.BydServiceBusyError = BydServiceBusyError;
|
|
111
|
+
/**
|
|
112
|
+
* A value could not be used: an argument, or a reply that is not what it should be. `kind`
|
|
113
|
+
* names the Python built-in exception pyBYD lets through (`ValueError`, `TypeError`,
|
|
114
|
+
* `JSONDecodeError`, ...).
|
|
115
|
+
*/
|
|
116
|
+
class DataError extends OpenBydError {
|
|
117
|
+
name = "DataError";
|
|
118
|
+
}
|
|
119
|
+
exports.DataError = DataError;
|
|
120
|
+
/** A reply or a parameter did not validate, where pyBYD raises pydantic's `ValidationError`. */
|
|
121
|
+
class ValidationError extends DataError {
|
|
122
|
+
name = "ValidationError";
|
|
123
|
+
/** pydantic's error type, such as `int_parsing`. */
|
|
124
|
+
errorType;
|
|
125
|
+
/** Where the bad value was, outermost first. */
|
|
126
|
+
loc;
|
|
127
|
+
constructor(message, details) {
|
|
128
|
+
super(message, details);
|
|
129
|
+
this.errorType = details.errorType ?? "";
|
|
130
|
+
this.loc = details.loc ?? [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.ValidationError = ValidationError;
|
|
134
|
+
/**
|
|
135
|
+
* A wait for an MQTT push was cut short because the client stopped its MQTT channel, for
|
|
136
|
+
* example when it was closed.
|
|
137
|
+
*/
|
|
138
|
+
class CancelledError extends OpenBydError {
|
|
139
|
+
name = "CancelledError";
|
|
140
|
+
}
|
|
141
|
+
exports.CancelledError = CancelledError;
|
|
142
|
+
/** The error class for each Python exception class the core reports. */
|
|
143
|
+
exports.ERROR_CLASSES = {
|
|
144
|
+
ScriptExhausted: OpenBydError,
|
|
145
|
+
BydError: BydError,
|
|
146
|
+
BydCryptoError: BydCryptoError,
|
|
147
|
+
BangcleError: BangcleError,
|
|
148
|
+
BangcleTableLoadError: BangcleTableLoadError,
|
|
149
|
+
BydTransportError: BydTransportError,
|
|
150
|
+
BydApiError: BydApiError,
|
|
151
|
+
BydAuthenticationError: BydAuthenticationError,
|
|
152
|
+
BydSessionExpiredError: BydSessionExpiredError,
|
|
153
|
+
BydRemoteControlError: BydRemoteControlError,
|
|
154
|
+
BydControlPasswordError: BydControlPasswordError,
|
|
155
|
+
BydEndpointNotSupportedError: BydEndpointNotSupportedError,
|
|
156
|
+
BydDataUnavailableError: BydDataUnavailableError,
|
|
157
|
+
BydRateLimitError: BydRateLimitError,
|
|
158
|
+
BydServiceBusyError: BydServiceBusyError,
|
|
159
|
+
ValueError: DataError,
|
|
160
|
+
TypeError: DataError,
|
|
161
|
+
AttributeError: DataError,
|
|
162
|
+
AssertionError: DataError,
|
|
163
|
+
JSONDecodeError: DataError,
|
|
164
|
+
UnicodeDecodeError: DataError,
|
|
165
|
+
ValidationError: ValidationError,
|
|
166
|
+
CancelledError: CancelledError,
|
|
167
|
+
};
|