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.
@@ -0,0 +1,191 @@
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.SeatMode = exports.SeatLevel = exports.SeatPosition = exports.EnergyType = exports.AirCirculationMode = exports.SeatHeatVentState = exports.StearingWheelHeat = exports.PowerGear = exports.WindowState = exports.LockState = exports.DoorOpenState = exports.TirePressureUnit = exports.SentryStatus = exports.ChargingState = exports.VehicleState = exports.ConnectState = exports.OnlineState = exports.NotificationCategory = exports.HvacWindPosition = exports.HvacWindMode = exports.AirConditioningMode = exports.HvacOverallStatus = exports.AcSwitch = exports.CommandLifecycleStatus = exports.ControlState = exports.RemoteCommand = void 0;
6
+ /** Remote control `commandType` values. */
7
+ exports.RemoteCommand = {
8
+ LOCK: "LOCKDOOR",
9
+ UNLOCK: "OPENDOOR",
10
+ START_CLIMATE: "OPENAIR",
11
+ STOP_CLIMATE: "CLOSEAIR",
12
+ SCHEDULE_CLIMATE: "BOOKINGAIR",
13
+ FIND_CAR: "FINDCAR",
14
+ FLASH_LIGHTS: "FLASHLIGHTNOWHISTLE",
15
+ CLOSE_WINDOWS: "CLOSEWINDOW",
16
+ OPEN_WINDOWS: "OPENWINDOW",
17
+ SEAT_CLIMATE: "VENTILATIONHEATING",
18
+ BATTERY_HEAT: "BATTERYHEAT",
19
+ OPEN_TRUNK: "OPENTRUNK",
20
+ CLOSE_TRUNK: "CLOSETRUNK",
21
+ START_CHARGE: "SMARTCHARGESTART",
22
+ STOP_CHARGE: "SMARTCHARGESTOP",
23
+ };
24
+ /** Control command execution state. */
25
+ exports.ControlState = {
26
+ PENDING: 0,
27
+ SUCCESS: 1,
28
+ FAILURE: 2,
29
+ };
30
+ /** Lifecycle state for deterministic command ACK correlation. */
31
+ exports.CommandLifecycleStatus = {
32
+ REGISTERED: "registered",
33
+ MATCHED: "matched",
34
+ EXPIRED: "expired",
35
+ UNCORRELATED: "uncorrelated",
36
+ };
37
+ /** A/C compressor switch, separate from the overall `HvacOverallStatus`. */
38
+ exports.AcSwitch = {
39
+ UNKNOWN: -1,
40
+ OFF: 1,
41
+ ON: 2,
42
+ };
43
+ /** Overall HVAC on/off status. */
44
+ exports.HvacOverallStatus = {
45
+ UNKNOWN: -1,
46
+ ON: 1,
47
+ OFF: 2,
48
+ };
49
+ /** A/C control mode. */
50
+ exports.AirConditioningMode = {
51
+ UNKNOWN: -1,
52
+ OFF: 0,
53
+ AUTO: 1,
54
+ MANUAL: 2,
55
+ };
56
+ /** Airflow direction (which vents blow). */
57
+ exports.HvacWindMode = {
58
+ UNKNOWN: -1,
59
+ OFF: 0,
60
+ FACE: 1,
61
+ FACE_FOOT: 2,
62
+ FOOT: 3,
63
+ FOOT_DEFROST: 4,
64
+ DEFROST: 5,
65
+ };
66
+ /** Fan speed, 1 (lowest) to 7 (highest). */
67
+ exports.HvacWindPosition = {
68
+ UNKNOWN: -1,
69
+ OFF: 0,
70
+ POSITION_1: 1,
71
+ POSITION_2: 2,
72
+ POSITION_3: 3,
73
+ POSITION_4: 4,
74
+ POSITION_5: 5,
75
+ POSITION_6: 6,
76
+ POSITION_7: 7,
77
+ };
78
+ /** Inbox category, the value is the `messageGroup` sent to the API. */
79
+ exports.NotificationCategory = {
80
+ VEHICLE: 1,
81
+ SYSTEM: 2,
82
+ };
83
+ /** Vehicle online/offline state. */
84
+ exports.OnlineState = {
85
+ UNKNOWN: -1,
86
+ ONLINE: 1,
87
+ OFFLINE: 2,
88
+ };
89
+ /** T-Box connection state. */
90
+ exports.ConnectState = {
91
+ UNKNOWN: -1,
92
+ DISCONNECTED: 0,
93
+ CONNECTED: 1,
94
+ };
95
+ /** Vehicle power state. */
96
+ exports.VehicleState = {
97
+ UNKNOWN: -1,
98
+ OFF: 0,
99
+ ON: 2,
100
+ };
101
+ /** Charging state indicator. */
102
+ exports.ChargingState = {
103
+ UNKNOWN: -1,
104
+ NOT_CHARGING: 0,
105
+ CHARGING: 1,
106
+ CONNECTED: 15,
107
+ };
108
+ /** Sentry mode state. */
109
+ exports.SentryStatus = {
110
+ UNKNOWN: -1,
111
+ ON: 2,
112
+ OFF: 4,
113
+ };
114
+ /** Unit used for tire pressure readings. */
115
+ exports.TirePressureUnit = {
116
+ UNKNOWN: -1,
117
+ BAR: 1,
118
+ PSI: 2,
119
+ KPA: 3,
120
+ };
121
+ /** Door/trunk open/closed state. */
122
+ exports.DoorOpenState = {
123
+ UNKNOWN: -1,
124
+ CLOSED: 0,
125
+ OPEN: 1,
126
+ };
127
+ /** Door lock state. */
128
+ exports.LockState = {
129
+ UNKNOWN: -1,
130
+ UNAVAILABLE: 0,
131
+ UNLOCKED: 1,
132
+ LOCKED: 2,
133
+ };
134
+ /** Window open/closed state. */
135
+ exports.WindowState = {
136
+ UNKNOWN: -1,
137
+ CLOSED: 1,
138
+ OPEN: 2,
139
+ };
140
+ /** Vehicle power state. */
141
+ exports.PowerGear = {
142
+ UNKNOWN: -1,
143
+ OFF: 1,
144
+ ON: 3,
145
+ };
146
+ /** Steering wheel heating state. */
147
+ exports.StearingWheelHeat = {
148
+ ON: -1,
149
+ NO_DATA: 0,
150
+ OFF: 1,
151
+ };
152
+ /** Seat heating / ventilation level. */
153
+ exports.SeatHeatVentState = {
154
+ UNKNOWN: -1,
155
+ NO_DATA: 0,
156
+ OFF: 1,
157
+ LOW: 2,
158
+ HIGH: 3,
159
+ };
160
+ /** Air circulation mode. */
161
+ exports.AirCirculationMode = {
162
+ UNKNOWN: -1,
163
+ UNAVAILABLE: 0,
164
+ EXTERNAL: 1,
165
+ INTERNAL: 2,
166
+ };
167
+ /** Vehicle powertrain type. */
168
+ exports.EnergyType = {
169
+ UNKNOWN: -1,
170
+ EV: 0,
171
+ ICE: 1,
172
+ HYBRID: 2,
173
+ };
174
+ /** Seat position for heat/ventilation commands. */
175
+ exports.SeatPosition = {
176
+ DRIVER: "driver",
177
+ COPILOT: "copilot",
178
+ REAR_LEFT: "rear_left",
179
+ REAR_RIGHT: "rear_right",
180
+ };
181
+ /** Seat heat/ventilation intensity level. */
182
+ exports.SeatLevel = {
183
+ OFF: 0,
184
+ LOW: 1,
185
+ HIGH: 2,
186
+ };
187
+ /** What a seat can do: heat or ventilate. */
188
+ exports.SeatMode = {
189
+ HEAT: "heat",
190
+ VENTILATION: "ventilation",
191
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Where the floats are inside a value the core returns: a float itself, a list or a map of
3
+ * shapes, or a struct by name. JSON has no NaN and no infinities, so the core writes them as
4
+ * strings; `revive` (wire.ts) follows a shape to turn them back into numbers.
5
+ */
6
+ export type Shape = "float" | readonly ["list", Shape] | readonly ["map", Shape] | readonly ["struct", string];
7
+ /** The fields of each struct that hold a float, with their shapes. */
8
+ export declare const STRUCT_SHAPES: Readonly<Record<string, Readonly<Record<string, Shape>>>>;
9
+ /** The payload of each event that holds a float, by the event's name in the core. */
10
+ export declare const EVENT_SHAPES: Readonly<Record<string, Readonly<Record<string, Shape>>>>;
11
+ /** The core's call name of each pyBYD model, for `parseModel`. */
12
+ export declare const MODEL_CALLS: {
13
+ readonly ClimateBooking: "models.booking.ClimateBooking";
14
+ readonly BookingList: "models.booking.BookingList";
15
+ readonly ChargingStatus: "models.charging.ChargingStatus";
16
+ readonly CommandGateRule: "models.command_gating.CommandGateRule";
17
+ readonly CommandGateVerdict: "models.command_gating.CommandGateVerdict";
18
+ readonly RemoteControlResult: "models.control.RemoteControlResult";
19
+ readonly CommandAck: "models.control.CommandAck";
20
+ readonly ChargeChangeResult: "models.control.ChargeChangeResult";
21
+ readonly CommandAckEvent: "models.control.CommandAckEvent";
22
+ readonly CommandLifecycleEvent: "models.control.CommandLifecycleEvent";
23
+ readonly CommandAckDiagnostics: "models.control.CommandAckDiagnostics";
24
+ readonly VerifyControlPasswordResponse: "models.control.VerifyControlPasswordResponse";
25
+ readonly EnergyConsumptionGraph: "models.energy.EnergyConsumptionGraph";
26
+ readonly CumulativeEnergyConsumption: "models.energy.CumulativeEnergyConsumption";
27
+ readonly NearestEnergyConsumption: "models.energy.NearestEnergyConsumption";
28
+ readonly EnergyConsumption: "models.energy.EnergyConsumption";
29
+ readonly GpsInfo: "models.gps.GpsInfo";
30
+ readonly HvacStatus: "models.hvac.HvacStatus";
31
+ readonly LatestConfigFunction: "models.latest_config.LatestConfigFunction";
32
+ readonly VehicleLatestConfig: "models.latest_config.VehicleLatestConfig";
33
+ readonly VehicleCapabilities: "models.latest_config.VehicleCapabilities";
34
+ readonly VehicleMsgItemInfo: "models.message_center.VehicleMsgItemInfo";
35
+ readonly VehicleMsgListResponse: "models.message_center.VehicleMsgListResponse";
36
+ readonly PushSwitch: "models.push_notification.PushSwitch";
37
+ readonly PushNotificationState: "models.push_notification.PushNotificationState";
38
+ readonly VehicleRealtimeData: "models.realtime.VehicleRealtimeData";
39
+ readonly SmartChargeDto: "models.smart_charging.SmartChargeDto";
40
+ readonly SmartJourneyDto: "models.smart_charging.SmartJourneyDto";
41
+ readonly SmartChargingSchedule: "models.smart_charging.SmartChargingSchedule";
42
+ readonly AcCurrentLimit: "models.smart_charging.AcCurrentLimit";
43
+ readonly EmpowerRange: "models.vehicle.EmpowerRange";
44
+ readonly Vehicle: "models.vehicle.Vehicle";
45
+ };
@@ -0,0 +1,164 @@
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.MODEL_CALLS = exports.EVENT_SHAPES = exports.STRUCT_SHAPES = void 0;
6
+ /** The fields of each struct that hold a float, with their shapes. */
7
+ exports.STRUCT_SHAPES = {
8
+ ClimateBooking: {
9
+ main_setting_temp_new: "float",
10
+ },
11
+ BookingList: {
12
+ bookings: ["list", ["struct", "ClimateBooking"]],
13
+ },
14
+ ChargingStatus: {
15
+ charge_power: "float",
16
+ },
17
+ EnergyConsumptionGraph: {
18
+ energy_consumption: ["list", "float"],
19
+ },
20
+ CumulativeEnergyConsumption: {
21
+ total_mileage: "float",
22
+ avg_ev_consumption: "float",
23
+ avg_oil_consumption: "float",
24
+ },
25
+ NearestEnergyConsumption: {
26
+ avg_ev_consumption: "float",
27
+ ev_consumption: "float",
28
+ avg_oil_consumption: "float",
29
+ oil_consumption: "float",
30
+ avg_eq_oil_consumption: "float",
31
+ },
32
+ EnergyConsumption: {
33
+ self_graph: ["struct", "EnergyConsumptionGraph"],
34
+ cumulative_energy_consumption: ["struct", "CumulativeEnergyConsumption"],
35
+ nearest_energy_consumption: ["struct", "NearestEnergyConsumption"],
36
+ auto_model_graph: ["struct", "EnergyConsumptionGraph"],
37
+ },
38
+ GpsInfo: {
39
+ latitude: "float",
40
+ longitude: "float",
41
+ speed: "float",
42
+ direction: "float",
43
+ },
44
+ HvacStatus: {
45
+ main_setting_temp: "float",
46
+ main_setting_temp_new: "float",
47
+ copilot_setting_temp: "float",
48
+ copilot_setting_temp_new: "float",
49
+ temp_in_car: "float",
50
+ temp_out_car: "float",
51
+ vde_temp_range_min: "float",
52
+ vde_temp_range_max: "float",
53
+ pm: "float",
54
+ pm25_state_out_car: "float",
55
+ },
56
+ VehicleRealtimeData: {
57
+ elec_percent: "float",
58
+ power_battery: "float",
59
+ endurance_mileage: "float",
60
+ ev_endurance: "float",
61
+ endurance_mileage_v2: "float",
62
+ total_mileage: "float",
63
+ total_mileage_v2: "float",
64
+ speed: "float",
65
+ temp_in_car: "float",
66
+ main_setting_temp_new: "float",
67
+ left_front_tire_pressure: "float",
68
+ right_front_tire_pressure: "float",
69
+ left_rear_tire_pressure: "float",
70
+ right_rear_tire_pressure: "float",
71
+ total_power: "float",
72
+ gl: "float",
73
+ oil_endurance: "float",
74
+ oil_percent: "float",
75
+ total_oil: "float",
76
+ rate: "float",
77
+ charge_power: "float",
78
+ energy_consumption_ev: "float",
79
+ energy_consumption_fuel: "float",
80
+ nearest_energy_consumption_ev: "float",
81
+ nearest_energy_consumption_fuel: "float",
82
+ recent_50km_energy_ev: "float",
83
+ recent_50km_energy_fuel: "float",
84
+ total_energy_ev: "float",
85
+ total_energy_fuel: "float",
86
+ total_consumption_ev: "float",
87
+ total_consumption_fuel: "float",
88
+ total_consumption_en_ev: "float",
89
+ total_consumption_en_fuel: "float",
90
+ eq_consumption: "float",
91
+ },
92
+ Vehicle: {
93
+ total_mileage: "float",
94
+ },
95
+ SessionInfo: {
96
+ created_at: "float",
97
+ ttl: "float",
98
+ },
99
+ SessionTokens: {
100
+ ttl_remaining: "float",
101
+ },
102
+ RequestRecord: {
103
+ duration: "float",
104
+ },
105
+ ChargingHomepage: {
106
+ status: ["struct", "ChargingStatus"],
107
+ },
108
+ VehicleSnapshot: {
109
+ vehicle: ["struct", "Vehicle"],
110
+ realtime: ["struct", "VehicleRealtimeData"],
111
+ hvac: ["struct", "HvacStatus"],
112
+ gps: ["struct", "GpsInfo"],
113
+ charging: ["struct", "ChargingStatus"],
114
+ energy: ["struct", "EnergyConsumption"],
115
+ },
116
+ HvacFeatures: {
117
+ temp_offset: "float",
118
+ temp_range: ["list", "float"],
119
+ },
120
+ CarFeatures: {
121
+ hvac: ["struct", "HvacFeatures"],
122
+ },
123
+ };
124
+ /** The payload of each event that holds a float, by the event's name in the core. */
125
+ exports.EVENT_SHAPES = {
126
+ vehicle_info: { data: ["struct", "VehicleRealtimeData"] },
127
+ request: { record: ["struct", "RequestRecord"] },
128
+ state_changed: { state: ["struct", "VehicleSnapshot"] },
129
+ };
130
+ /** The core's call name of each pyBYD model, for `parseModel`. */
131
+ exports.MODEL_CALLS = {
132
+ ClimateBooking: "models.booking.ClimateBooking",
133
+ BookingList: "models.booking.BookingList",
134
+ ChargingStatus: "models.charging.ChargingStatus",
135
+ CommandGateRule: "models.command_gating.CommandGateRule",
136
+ CommandGateVerdict: "models.command_gating.CommandGateVerdict",
137
+ RemoteControlResult: "models.control.RemoteControlResult",
138
+ CommandAck: "models.control.CommandAck",
139
+ ChargeChangeResult: "models.control.ChargeChangeResult",
140
+ CommandAckEvent: "models.control.CommandAckEvent",
141
+ CommandLifecycleEvent: "models.control.CommandLifecycleEvent",
142
+ CommandAckDiagnostics: "models.control.CommandAckDiagnostics",
143
+ VerifyControlPasswordResponse: "models.control.VerifyControlPasswordResponse",
144
+ EnergyConsumptionGraph: "models.energy.EnergyConsumptionGraph",
145
+ CumulativeEnergyConsumption: "models.energy.CumulativeEnergyConsumption",
146
+ NearestEnergyConsumption: "models.energy.NearestEnergyConsumption",
147
+ EnergyConsumption: "models.energy.EnergyConsumption",
148
+ GpsInfo: "models.gps.GpsInfo",
149
+ HvacStatus: "models.hvac.HvacStatus",
150
+ LatestConfigFunction: "models.latest_config.LatestConfigFunction",
151
+ VehicleLatestConfig: "models.latest_config.VehicleLatestConfig",
152
+ VehicleCapabilities: "models.latest_config.VehicleCapabilities",
153
+ VehicleMsgItemInfo: "models.message_center.VehicleMsgItemInfo",
154
+ VehicleMsgListResponse: "models.message_center.VehicleMsgListResponse",
155
+ PushSwitch: "models.push_notification.PushSwitch",
156
+ PushNotificationState: "models.push_notification.PushNotificationState",
157
+ VehicleRealtimeData: "models.realtime.VehicleRealtimeData",
158
+ SmartChargeDto: "models.smart_charging.SmartChargeDto",
159
+ SmartJourneyDto: "models.smart_charging.SmartJourneyDto",
160
+ SmartChargingSchedule: "models.smart_charging.SmartChargingSchedule",
161
+ AcCurrentLimit: "models.smart_charging.AcCurrentLimit",
162
+ EmpowerRange: "models.vehicle.EmpowerRange",
163
+ Vehicle: "models.vehicle.Vehicle",
164
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * openbyd: an unofficial client for the BYD overseas app API, with a Rust core.
3
+ *
4
+ * - {@link Client}: pyBYD's `BydClient`.
5
+ * - {@link Car}: pyBYD's `BydCar`, from `client.getCar(vin)`.
6
+ * - pyBYD's exception hierarchy as error classes ({@link BydError}, {@link BydApiError}, ...).
7
+ * - pyBYD's reply models and enums as types, and {@link parseModel} to parse a raw payload as one.
8
+ * - The envelope cipher: {@link encodeEnvelope}, {@link decodeEnvelope}.
9
+ *
10
+ * This project is not affiliated with, endorsed by or supported by BYD.
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ export { Car, Client } from "./client.js";
15
+ export type { ClientHooks, ClientOptions, GatePolicy, GetCarOptions, PinResolver, ReloginPolicy } from "./client.js";
16
+ export * from "./generated/errors.js";
17
+ export { BatteryFeature, FinderFeature, HvacFeature, LockFeature, SeatFeature, SteeringFeature, TrunkFeature, WindowsFeature, } from "./generated/methods.js";
18
+ export * from "./generated/models.js";
19
+ export { configureRuntime, decodeEnvelope, encodeEnvelope, parseModel, runtimeInfo, version } from "./functions.js";
20
+ export type { RuntimeInfo } from "./functions.js";
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * openbyd: an unofficial client for the BYD overseas app API, with a Rust core.
4
+ *
5
+ * - {@link Client}: pyBYD's `BydClient`.
6
+ * - {@link Car}: pyBYD's `BydCar`, from `client.getCar(vin)`.
7
+ * - pyBYD's exception hierarchy as error classes ({@link BydError}, {@link BydApiError}, ...).
8
+ * - pyBYD's reply models and enums as types, and {@link parseModel} to parse a raw payload as one.
9
+ * - The envelope cipher: {@link encodeEnvelope}, {@link decodeEnvelope}.
10
+ *
11
+ * This project is not affiliated with, endorsed by or supported by BYD.
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.version = exports.runtimeInfo = exports.parseModel = exports.encodeEnvelope = exports.decodeEnvelope = exports.configureRuntime = exports.WindowsFeature = exports.TrunkFeature = exports.SteeringFeature = exports.SeatFeature = exports.LockFeature = exports.HvacFeature = exports.FinderFeature = exports.BatteryFeature = exports.Client = exports.Car = void 0;
31
+ var client_js_1 = require("./client.js");
32
+ Object.defineProperty(exports, "Car", { enumerable: true, get: function () { return client_js_1.Car; } });
33
+ Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
34
+ __exportStar(require("./generated/errors.js"), exports);
35
+ var methods_js_1 = require("./generated/methods.js");
36
+ Object.defineProperty(exports, "BatteryFeature", { enumerable: true, get: function () { return methods_js_1.BatteryFeature; } });
37
+ Object.defineProperty(exports, "FinderFeature", { enumerable: true, get: function () { return methods_js_1.FinderFeature; } });
38
+ Object.defineProperty(exports, "HvacFeature", { enumerable: true, get: function () { return methods_js_1.HvacFeature; } });
39
+ Object.defineProperty(exports, "LockFeature", { enumerable: true, get: function () { return methods_js_1.LockFeature; } });
40
+ Object.defineProperty(exports, "SeatFeature", { enumerable: true, get: function () { return methods_js_1.SeatFeature; } });
41
+ Object.defineProperty(exports, "SteeringFeature", { enumerable: true, get: function () { return methods_js_1.SteeringFeature; } });
42
+ Object.defineProperty(exports, "TrunkFeature", { enumerable: true, get: function () { return methods_js_1.TrunkFeature; } });
43
+ Object.defineProperty(exports, "WindowsFeature", { enumerable: true, get: function () { return methods_js_1.WindowsFeature; } });
44
+ __exportStar(require("./generated/models.js"), exports);
45
+ var functions_js_1 = require("./functions.js");
46
+ Object.defineProperty(exports, "configureRuntime", { enumerable: true, get: function () { return functions_js_1.configureRuntime; } });
47
+ Object.defineProperty(exports, "decodeEnvelope", { enumerable: true, get: function () { return functions_js_1.decodeEnvelope; } });
48
+ Object.defineProperty(exports, "encodeEnvelope", { enumerable: true, get: function () { return functions_js_1.encodeEnvelope; } });
49
+ Object.defineProperty(exports, "parseModel", { enumerable: true, get: function () { return functions_js_1.parseModel; } });
50
+ Object.defineProperty(exports, "runtimeInfo", { enumerable: true, get: function () { return functions_js_1.runtimeInfo; } });
51
+ Object.defineProperty(exports, "version", { enumerable: true, get: function () { return functions_js_1.version; } });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Loads the compiled add-on (`crates/openbyd-node`).
3
+ *
4
+ * It is looked for in two places:
5
+ *
6
+ * 1. `native/openbyd.<platform>.node` inside this package: a build from
7
+ * source (`npm run build:native`).
8
+ * 2. The package `@openbyd/<platform>`: the prebuilt add-on for this
9
+ * platform, installed as an optional dependency.
10
+ *
11
+ * `<platform>` is Node's platform and architecture with the C library where
12
+ * it matters: `win32-x64-msvc`, `linux-x64-gnu`, `linux-arm64-musl`,
13
+ * `darwin-arm64`.
14
+ *
15
+ * @internal
16
+ */
17
+ /** The add-on's client: methods by name, JSON text in and out. */
18
+ export interface NativeClient {
19
+ callSync(method: string, args?: string): string;
20
+ call(method: string, args?: string): Promise<string>;
21
+ }
22
+ /** What the add-on exports. */
23
+ export interface Native {
24
+ readonly ERROR_PREFIX: string;
25
+ call(name: string, args?: string): string;
26
+ testingCall(name: string, args?: string): string;
27
+ readonly NativeClient: new (config: string, options: string | undefined, onEvent: (name: string, payload: string) => void) => NativeClient;
28
+ }
29
+ /** This platform's name in the add-on's file and package names. */
30
+ export declare function platformName(): string;
31
+ /** The add-on. */
32
+ export declare const native: Native;
package/dist/native.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * Loads the compiled add-on (`crates/openbyd-node`).
4
+ *
5
+ * It is looked for in two places:
6
+ *
7
+ * 1. `native/openbyd.<platform>.node` inside this package: a build from
8
+ * source (`npm run build:native`).
9
+ * 2. The package `@openbyd/<platform>`: the prebuilt add-on for this
10
+ * platform, installed as an optional dependency.
11
+ *
12
+ * `<platform>` is Node's platform and architecture with the C library where
13
+ * it matters: `win32-x64-msvc`, `linux-x64-gnu`, `linux-arm64-musl`,
14
+ * `darwin-arm64`.
15
+ *
16
+ * @internal
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.native = void 0;
20
+ exports.platformName = platformName;
21
+ const node_path_1 = require("node:path");
22
+ /** Whether this Linux runs on musl (Alpine) instead of glibc. */
23
+ function isMusl() {
24
+ const report = process.report?.getReport();
25
+ return report?.header?.glibcVersionRuntime === undefined;
26
+ }
27
+ /** This platform's name in the add-on's file and package names. */
28
+ function platformName() {
29
+ const base = `${process.platform}-${process.arch}`;
30
+ if (process.platform === "win32")
31
+ return `${base}-msvc`;
32
+ if (process.platform === "linux")
33
+ return `${base}-${isMusl() ? "musl" : "gnu"}`;
34
+ return base;
35
+ }
36
+ function load() {
37
+ const platform = platformName();
38
+ const local = (0, node_path_1.join)(__dirname, "..", "native", `openbyd.${platform}.node`);
39
+ const failures = [];
40
+ for (const candidate of [local, `@openbyd/${platform}`]) {
41
+ try {
42
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
43
+ return require(candidate);
44
+ }
45
+ catch (error) {
46
+ failures.push(`${candidate}: ${error instanceof Error ? error.message : String(error)}`);
47
+ }
48
+ }
49
+ throw new Error(`openbyd has no compiled add-on for ${platform}. Install the package @openbyd/${platform}, ` +
50
+ `or build it from source (npm run build:native).\n${failures.join("\n")}`);
51
+ }
52
+ /** The add-on. */
53
+ exports.native = load();