signalk-masterbus 0.1.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.
Files changed (45) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +128 -0
  3. package/bin/darwin-arm64/masterbus-signalk +0 -0
  4. package/bin/darwin-x64/masterbus-signalk +0 -0
  5. package/bin/linux-arm/masterbus-signalk +0 -0
  6. package/bin/linux-arm64/masterbus-signalk +0 -0
  7. package/bin/linux-x64/masterbus-signalk +0 -0
  8. package/bin/win32-x64/masterbus-signalk.exe +0 -0
  9. package/package.json +82 -0
  10. package/plugin/client.d.ts +39 -0
  11. package/plugin/client.d.ts.map +1 -0
  12. package/plugin/client.js +93 -0
  13. package/plugin/client.js.map +1 -0
  14. package/plugin/config.d.ts +146 -0
  15. package/plugin/config.d.ts.map +1 -0
  16. package/plugin/config.js +143 -0
  17. package/plugin/config.js.map +1 -0
  18. package/plugin/daemon.d.ts +63 -0
  19. package/plugin/daemon.d.ts.map +1 -0
  20. package/plugin/daemon.js +223 -0
  21. package/plugin/daemon.js.map +1 -0
  22. package/plugin/index.d.ts +16 -0
  23. package/plugin/index.d.ts.map +1 -0
  24. package/plugin/index.js +199 -0
  25. package/plugin/index.js.map +1 -0
  26. package/plugin/put-bridge.d.ts +47 -0
  27. package/plugin/put-bridge.d.ts.map +1 -0
  28. package/plugin/put-bridge.js +116 -0
  29. package/plugin/put-bridge.js.map +1 -0
  30. package/plugin/router.d.ts +20 -0
  31. package/plugin/router.d.ts.map +1 -0
  32. package/plugin/router.js +38 -0
  33. package/plugin/router.js.map +1 -0
  34. package/plugin/stream-forwarder.d.ts +54 -0
  35. package/plugin/stream-forwarder.d.ts.map +1 -0
  36. package/plugin/stream-forwarder.js +139 -0
  37. package/plugin/stream-forwarder.js.map +1 -0
  38. package/plugin/types.d.ts +136 -0
  39. package/plugin/types.d.ts.map +1 -0
  40. package/plugin/types.js +19 -0
  41. package/plugin/types.js.map +1 -0
  42. package/public/assets/icon.svg +6 -0
  43. package/public/assets/index-D5ZZgo9o.js +49 -0
  44. package/public/assets/index-rkv4IC1b.css +1 -0
  45. package/public/index.html +14 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Kees Verruijt
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # signalk-masterbus
2
+
3
+ Mastervolt **MasterBus** for [Signal K](https://signalk.org): battery,
4
+ charger, inverter and solar values on your Signal K server, a browser
5
+ editor for choosing what publishes where, and switches in Signal K that
6
+ set fields on the bus.
7
+
8
+ The plugin is a thin layer over
9
+ [`masterbus-signalk`](https://github.com/keesverruijt/masterbus), the daemon
10
+ from the masterbus project that speaks the CAN protocol. It runs the daemon
11
+ for you on the machine wired to the bus, or connects to one running
12
+ elsewhere.
13
+
14
+ ## What you need
15
+
16
+ A computer that can reach the bus, exactly as for the masterbus tools:
17
+
18
+ - a **Mastervolt USB Interface** (article 77030200) on Linux, macOS or
19
+ Windows, or
20
+ - a **Linux machine with a CAN adapter** (a CANable stick, a PiCAN HAT on a
21
+ Raspberry Pi) with `can0` up at 250 kbit/s.
22
+
23
+ See the masterbus project's
24
+ [HARDWARE.md](https://github.com/keesverruijt/masterbus/blob/main/HARDWARE.md).
25
+
26
+ ## Install
27
+
28
+ From the Signal K **App Store**, or:
29
+
30
+ ```sh
31
+ cd ~/.signalk
32
+ npm install signalk-masterbus
33
+ ```
34
+
35
+ The package bundles the daemon binary for every supported platform (Linux
36
+ x64/arm64/armv7, macOS, Windows), about 10 MB in all; nothing else to
37
+ download. Enable the plugin under **Server → Plugin Config → MasterBus**.
38
+
39
+ ## Two ways to run it
40
+
41
+ **Bundled** (the default): the plugin starts `masterbus-signalk` on this
42
+ machine and keeps its configuration, the mapping and the device schema
43
+ cache under `~/.signalk/plugin-config-data/signalk-masterbus/masterbus/`.
44
+ With _Transport_ on auto-detect it picks a plugged-in USB link, else the
45
+ only CAN interface; set it explicitly when the machine has several. Nothing
46
+ listens beyond loopback.
47
+
48
+ **External**: the machine on the bus is not the one running Signal K. Run
49
+ `masterbus-signalk` there (its systemd unit is in the masterbus release
50
+ tarball), set `api_listen` and `api_token` in its `config.ini`, and give
51
+ the plugin the host, ports and token. Everything below works the same.
52
+
53
+ A container is not required and not offered: the daemon needs the CAN
54
+ interface or the USB device, which a container only complicates.
55
+
56
+ ## Telling it what to publish
57
+
58
+ Open **MasterBus mapping** from the server's webapp list. It shows every
59
+ device on the bus with its fields and live values. Nothing is published
60
+ until it is mapped:
61
+
62
+ - **Map** a field. The path is pre-filled when the bundled per-model
63
+ database or the name heuristics know the field, and the daemon validates
64
+ it as you type: you see the unit conversion it implies (`°C` becomes
65
+ kelvin), and a path whose units cannot be reconciled is refused rather
66
+ than saved.
67
+ - An enum onto a boolean leaf (`enabled`, a switch's `state`) gets a **truth
68
+ table**; an enum with a label like `Alarm` gets a **notification table**,
69
+ so a Signal K server can sound it rather than show a word.
70
+ - **Accept PUTs** on a writable field, and a switch in Signal K (a dashboard
71
+ toggle, a rule, `PUT /signalk/v1/api/vessels/self/<path>`) sets the field
72
+ on the bus. Writable settings live on a device's _Configuration_ menu;
73
+ the **Load configuration fields** button discovers it.
74
+ - **Apply to same article** copies one device's mapping to every other unit
75
+ of the same model, substituting each one's instance.
76
+ - **Save mapping** writes it; the daemon picks it up at once.
77
+
78
+ The first run seeds a mapping from the bundled heuristics so a fresh
79
+ install is not silent; treat it as a starting point. Diagnostics for the
80
+ saved mapping (a field the device does not have, a firmware that moved
81
+ on) are listed under the table.
82
+
83
+ The file being edited is the daemon's `mapping.json`, the same one
84
+ `masterbus-tui --mapping` edits, so both tools can be used on the same
85
+ install.
86
+
87
+ ## Writes and the installer code
88
+
89
+ A field that is read-only at the device's user level needs a Mastervolt
90
+ installer login. Enter the code in the plugin settings and writes that
91
+ need it log in first. Leave it blank otherwise.
92
+
93
+ ## Development
94
+
95
+ ```sh
96
+ npm install
97
+ npm run build # plugin/ (tsc) and public/ (vite)
98
+ npm test
99
+ npm run lint
100
+ npm run fetch-daemons # bin/<os>-<arch>/ from the masterbus release package.json pins
101
+ ```
102
+
103
+ `fetch-daemons` downloads the release tarballs of the masterbus version
104
+ named by `masterbusDaemon` in `package.json` and unpacks the daemon for
105
+ each platform into `bin/`; `--current` fetches only this machine's. It
106
+ runs automatically before `npm publish`.
107
+
108
+ To run against a daemon without hardware, build masterbus with the
109
+ `fake-bus` feature:
110
+
111
+ ```sh
112
+ cd ../masterbus && cargo build --release -p masterbus-tools --features fake-bus
113
+ ```
114
+
115
+ The plugin passes the daemon its own arguments, so to add `--fake-bus` set
116
+ _masterbus-signalk binary_ in the plugin settings to a wrapper script:
117
+
118
+ ```sh
119
+ #!/bin/sh
120
+ exec /path/to/masterbus/target/release/masterbus-signalk --fake-bus "$@"
121
+ ```
122
+
123
+ The daemon's API is documented in the masterbus repository's
124
+ [`docs/API.md`](https://github.com/keesverruijt/masterbus/blob/main/docs/API.md).
125
+
126
+ ## License
127
+
128
+ Apache-2.0.
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "signalk-masterbus",
3
+ "version": "0.1.0",
4
+ "masterbusDaemon": "0.4.1",
5
+ "description": "Mastervolt MasterBus for Signal K: publish battery, charger and inverter values, edit the mapping in the browser, and switch devices from Signal K",
6
+ "main": "plugin/index.js",
7
+ "type": "module",
8
+ "signalk-plugin-enabled-by-default": true,
9
+ "scripts": {
10
+ "build": "tsc && vite build",
11
+ "build:plugin": "tsc",
12
+ "build:web": "vite build",
13
+ "test": "vitest run",
14
+ "lint": "eslint 'src/**/*.ts' 'test/**/*.ts' 'web/**/*.ts' 'web/**/*.tsx'",
15
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"web/**/*.{ts,tsx,css,html}\" \"**/*.md\" \"*.{json,yml,yaml,mjs,js}\" \".github/**/*.{yml,yaml}\"",
16
+ "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" \"web/**/*.{ts,tsx,css,html}\" \"**/*.md\" \"*.{json,yml,yaml,mjs,js}\" \".github/**/*.{yml,yaml}\"",
17
+ "check": "npm run lint && npm run format:check && npm run build && npm test",
18
+ "prepublishOnly": "npm run fetch-daemons && npm run build",
19
+ "fetch-daemons": "node scripts/fetch-daemons.mjs"
20
+ },
21
+ "keywords": [
22
+ "signalk-node-server-plugin",
23
+ "signalk-webapp",
24
+ "signalk-category-hardware",
25
+ "mastervolt",
26
+ "masterbus",
27
+ "marine",
28
+ "battery",
29
+ "inverter"
30
+ ],
31
+ "signalk": {
32
+ "displayName": "MasterBus",
33
+ "appIcon": "assets/icon.svg",
34
+ "webapp": {
35
+ "name": "MasterBus mapping",
36
+ "description": "Choose which MasterBus fields publish to which Signal K paths",
37
+ "location": "/signalk-masterbus/"
38
+ }
39
+ },
40
+ "files": [
41
+ "plugin/**/*",
42
+ "public/**/*",
43
+ "bin/**/*",
44
+ "docs/**/*"
45
+ ],
46
+ "engines": {
47
+ "node": ">=22",
48
+ "signalk": ">=2.24.0"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "^9.0.0",
52
+ "@signalk/server-api": "^2.33.0",
53
+ "@types/express": "^5.0.0",
54
+ "@types/node": "^22.0.0",
55
+ "@types/react": "^19.0.0",
56
+ "@types/react-dom": "^19.0.0",
57
+ "@vitejs/plugin-react": "^5.0.0",
58
+ "eslint": "^9.0.0",
59
+ "eslint-config-prettier": "^10.0.0",
60
+ "eslint-plugin-prettier": "^5.0.0",
61
+ "prettier": "^3.0.0",
62
+ "react": "^19.0.0",
63
+ "react-dom": "^19.0.0",
64
+ "typescript": "^5.7.0",
65
+ "typescript-eslint": "^8.0.0",
66
+ "vite": "^6.0.0",
67
+ "vitest": "^3.0.0"
68
+ },
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "git+https://github.com/keesverruijt/signalk-masterbus.git"
72
+ },
73
+ "author": "Kees Verruijt",
74
+ "license": "Apache-2.0",
75
+ "publishConfig": {
76
+ "access": "public"
77
+ },
78
+ "homepage": "https://github.com/keesverruijt/signalk-masterbus#readme",
79
+ "bugs": {
80
+ "url": "https://github.com/keesverruijt/signalk-masterbus/issues"
81
+ }
82
+ }
@@ -0,0 +1,39 @@
1
+ import { type ApplyResult, type Device, type Diagnostic, type FieldMapping, type Login, type Mapping, type MappingResult, type Menu, type Status, type Suggestion, type Validation, type WriteResult } from './types.js';
2
+ export interface Endpoint {
3
+ host: string;
4
+ apiPort: number;
5
+ streamPort: number;
6
+ token: string;
7
+ }
8
+ /**
9
+ * A typed client for the daemon's control API. Every method maps to one
10
+ * endpoint in `docs/API.md`; a non-2xx answer becomes a `DaemonError` with
11
+ * the daemon's own message.
12
+ */
13
+ export declare class DaemonClient {
14
+ readonly endpoint: Endpoint;
15
+ private readonly fetchImpl;
16
+ constructor(endpoint: Endpoint, fetchImpl?: typeof fetch);
17
+ get baseUrl(): string;
18
+ /** Raw request, for the router's proxy. Returns the status and body. */
19
+ raw(method: string, path: string, body?: unknown): Promise<{
20
+ status: number;
21
+ body: unknown;
22
+ }>;
23
+ private call;
24
+ /** `GET /api/status`, refusing a daemon whose API version is not ours. */
25
+ status(): Promise<Status>;
26
+ devices(): Promise<Device[]>;
27
+ device(serial: string, menu?: Menu): Promise<Device>;
28
+ readValue(serial: string, field: string): Promise<{
29
+ value: unknown;
30
+ }>;
31
+ writeValue(serial: string, field: string, value: unknown, login?: Login): Promise<WriteResult>;
32
+ mapping(): Promise<Mapping>;
33
+ putMapping(mapping: Mapping): Promise<MappingResult>;
34
+ diagnostics(): Promise<Diagnostic[]>;
35
+ suggest(serial: string, field: string): Promise<Suggestion>;
36
+ validate(serial: string, field: string, entry: FieldMapping): Promise<Validation>;
37
+ applyArticle(serial: string): Promise<ApplyResult>;
38
+ }
39
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,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AAE,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC;IAO9F,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3B,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAIpC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI3D,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjF,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAGnD"}
@@ -0,0 +1,93 @@
1
+ import { API_VERSION, DaemonError } from './types.js';
2
+ /**
3
+ * A typed client for the daemon's control API. Every method maps to one
4
+ * endpoint in `docs/API.md`; a non-2xx answer becomes a `DaemonError` with
5
+ * the daemon's own message.
6
+ */
7
+ export class DaemonClient {
8
+ endpoint;
9
+ fetchImpl;
10
+ constructor(endpoint, fetchImpl = fetch) {
11
+ this.endpoint = endpoint;
12
+ this.fetchImpl = fetchImpl;
13
+ }
14
+ get baseUrl() {
15
+ return `http://${this.endpoint.host}:${this.endpoint.apiPort}`;
16
+ }
17
+ /** Raw request, for the router's proxy. Returns the status and body. */
18
+ async raw(method, path, body) {
19
+ const headers = {};
20
+ if (this.endpoint.token)
21
+ headers.Authorization = `Bearer ${this.endpoint.token}`;
22
+ let payload;
23
+ if (body !== undefined) {
24
+ headers['Content-Type'] = 'application/json';
25
+ payload = typeof body === 'string' ? body : JSON.stringify(body);
26
+ }
27
+ const res = await this.fetchImpl(`${this.baseUrl}${path}`, { method, headers, body: payload });
28
+ const text = await res.text();
29
+ let parsed = null;
30
+ if (text) {
31
+ try {
32
+ parsed = JSON.parse(text);
33
+ }
34
+ catch {
35
+ parsed = { error: text };
36
+ }
37
+ }
38
+ return { status: res.status, body: parsed };
39
+ }
40
+ async call(method, path, body) {
41
+ const { status, body: parsed } = await this.raw(method, path, body);
42
+ if (status < 200 || status >= 300) {
43
+ const e = (parsed ?? {});
44
+ const message = typeof e.error === 'string' ? e.error : `HTTP ${status} from the daemon`;
45
+ throw new DaemonError(status, message, typeof e.needs === 'string' ? e.needs : undefined);
46
+ }
47
+ return parsed;
48
+ }
49
+ /** `GET /api/status`, refusing a daemon whose API version is not ours. */
50
+ async status() {
51
+ const s = await this.call('GET', '/api/status');
52
+ if (s.apiVersion !== API_VERSION) {
53
+ throw new DaemonError(0, `the daemon speaks API version ${s.apiVersion}, this plugin version ${API_VERSION}; ` +
54
+ 'update whichever is older');
55
+ }
56
+ return s;
57
+ }
58
+ devices() {
59
+ return this.call('GET', '/api/devices');
60
+ }
61
+ device(serial, menu) {
62
+ const q = menu ? `?menu=${menu}` : '';
63
+ return this.call('GET', `/api/devices/${encodeURIComponent(serial)}${q}`);
64
+ }
65
+ readValue(serial, field) {
66
+ return this.call('GET', `/api/devices/${encodeURIComponent(serial)}/fields/${field}/value`);
67
+ }
68
+ writeValue(serial, field, value, login) {
69
+ return this.call('PUT', `/api/devices/${encodeURIComponent(serial)}/fields/${field}`, {
70
+ value,
71
+ ...(login ? { login } : {})
72
+ });
73
+ }
74
+ mapping() {
75
+ return this.call('GET', '/api/mapping');
76
+ }
77
+ putMapping(mapping) {
78
+ return this.call('PUT', '/api/mapping', mapping);
79
+ }
80
+ diagnostics() {
81
+ return this.call('GET', '/api/mapping/diagnostics');
82
+ }
83
+ suggest(serial, field) {
84
+ return this.call('POST', '/api/mapping/suggest', { serial, field });
85
+ }
86
+ validate(serial, field, entry) {
87
+ return this.call('POST', '/api/mapping/validate', { serial, field, entry });
88
+ }
89
+ applyArticle(serial) {
90
+ return this.call('POST', '/api/mapping/apply-article', { serial });
91
+ }
92
+ }
93
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","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