@nebulahome/integration-sdk 0.0.0-stage → 1.0.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/CHANGELOG.md +19 -0
- package/FILES.md +657 -0
- package/LICENSE +21 -0
- package/README.md +127 -2
- package/dist/chunks/node-dist.js +7866 -0
- package/dist/chunks/node-index.d.ts +2045 -0
- package/dist/chunks/node-project.js +545 -0
- package/dist/chunks/node-rolldown-runtime.js +24 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3783 -0
- package/dist/index.d.ts +1427 -0
- package/dist/index.js +53 -0
- package/dist/schemas.d.ts +693 -0
- package/dist/schemas.js +53 -0
- package/dist/testing.d.ts +267 -0
- package/dist/testing.js +251 -0
- package/package.json +76 -3
- package/schemas/account.schema.json +595 -0
- package/schemas/discovery.schema.json +354 -0
- package/schemas/driver.schema.json +118 -0
- package/schemas/manifest.schema.json +556 -0
- package/schemas/profile.schema.json +1415 -0
- package/schemas/setup.schema.json +1166 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NebulaHome
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nebulahome/integration-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Write a NebulaHome integration: check it, build it, test it and release it for the platform.
|
|
4
|
+
|
|
5
|
+
An integration teaches the platform a brand of devices. It is a **vendor directory** - the same
|
|
6
|
+
files the hub loads - in a repository of its own, `integration-<vendor>`, started from
|
|
7
|
+
[`integration-template`](https://github.com/nebulahome/integration-template), which already
|
|
8
|
+
depends on this package; anywhere else:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install --save-dev @nebulahome/integration-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
integration-acme/
|
|
16
|
+
├── package.json the release's version
|
|
17
|
+
├── src/ the vendor directory, as the hub loads it
|
|
18
|
+
│ ├── manifest.json who the vendor is
|
|
19
|
+
│ ├── logo.svg
|
|
20
|
+
│ ├── discovery.json how its devices are found (optional)
|
|
21
|
+
│ ├── lan/transport.ts a transport of its own, in TypeScript (optional)
|
|
22
|
+
│ └── panels/ one folder per driver
|
|
23
|
+
│ ├── driver.json the models it drives, the transport it speaks
|
|
24
|
+
│ ├── setup.json what adding a device asks
|
|
25
|
+
│ └── profile.json what the device means (or a module of code)
|
|
26
|
+
└── tests/
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Every JSON file names its schema, so the editor checks it as it is typed:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{ "$schema": "../node_modules/@nebulahome/integration-sdk/schemas/manifest.schema.json" }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`FILES.md`, beside this file, says what each of them holds in full - discovery, accounts, setup
|
|
36
|
+
forms, the profile's grammar and its limits, firmware updates, cameras and pictures.
|
|
37
|
+
|
|
38
|
+
## The command
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
nebulahome-integration validate # src/ holds together, the way the hub reads a bundle
|
|
42
|
+
nebulahome-integration build # validate, build src/ into dist/<vendor>/, load it back
|
|
43
|
+
nebulahome-integration pack # dist/<vendor>/ into <vendor>-<version>.tgz
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`validate` runs the hub's own loader over `src/`. `build` copies every file but code - the JSON
|
|
47
|
+
without its `$schema`, the manifest with `version` (from `package.json`) and `sdk` (this SDK's
|
|
48
|
+
range) written in - and builds every module the bundle names, where it names it, in one go:
|
|
49
|
+
`./lan/transport.js` from `src/lan/transport.ts`, what they import bundled in, zod refused (a
|
|
50
|
+
module uses `sdk.z`). `pack` writes the archive a GitHub release carries.
|
|
51
|
+
|
|
52
|
+
## Code
|
|
53
|
+
|
|
54
|
+
A module default-exports a function of the SDK the hub hands over; the helpers only type it:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { defineTransportModule } from '@nebulahome/integration-sdk';
|
|
58
|
+
|
|
59
|
+
export default defineTransportModule((sdk) =>
|
|
60
|
+
sdk.defineTransport({
|
|
61
|
+
id: 'acme/lan',
|
|
62
|
+
configSchema: sdk.z.object({ host: sdk.z.string() }),
|
|
63
|
+
connectionKey: (config) => config.host,
|
|
64
|
+
connect: async (config, context) => {
|
|
65
|
+
/* … */
|
|
66
|
+
},
|
|
67
|
+
async *scan() {},
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`defineDriverModule`, `defineDiscoveryModule`, `defineAccountModule` and `defineStreamModule`
|
|
73
|
+
type the other modules the same way.
|
|
74
|
+
|
|
75
|
+
## Tests
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { driverHarness, loadIntegration } from '@nebulahome/integration-sdk/testing';
|
|
79
|
+
|
|
80
|
+
const integration = await loadIntegration(); // src/, as the hub loads it
|
|
81
|
+
const light = driverHarness(integration.driver('panels'));
|
|
82
|
+
|
|
83
|
+
light.add({ deviceKey: '192.168.1.40', payload: infoJson });
|
|
84
|
+
light.receive(stateJson); // → state reports
|
|
85
|
+
light.command('light.device', 'on_off', { command: 'turn_on' }); // → the HTTP request
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`identify` says what discovery makes of a device heard, and `createFakeSdk` is the SDK handed to
|
|
89
|
+
the code, recording what it logged and sent: its UDP sockets and WebSockets connect to nothing, and
|
|
90
|
+
a test opens, delivers to and drops them.
|
|
91
|
+
|
|
92
|
+
## Releasing
|
|
93
|
+
|
|
94
|
+
Raise `version` in `package.json` and push the tag `v<version>`: the template's workflow
|
|
95
|
+
validates, tests, builds, packs and publishes a GitHub release with `<vendor>-<version>.tgz`, which
|
|
96
|
+
the Community Hub imports from the repository `integration-<vendor>`. To try a build on a running
|
|
97
|
+
platform before it is released, copy the archive into the platform's local folder
|
|
98
|
+
(`infra/local-integrations`) and install it from **Integrations → Install integration**.
|
|
99
|
+
|
|
100
|
+
The SDK's version is the version of the integration contract the platform implements; a bundle
|
|
101
|
+
built with it declares `^<major>.<minor>.0`. The full guide is `INTEGRATIONS_DOCS.md`.
|
|
102
|
+
|
|
103
|
+
## Releasing the SDK
|
|
104
|
+
|
|
105
|
+
For the platform's maintainers. The hub reads the contract's version from this `package.json`, so
|
|
106
|
+
the version is raised by hand - not by changesets, which ignore this package:
|
|
107
|
+
|
|
108
|
+
- **patch** - a fix, or a change to the command, the tests' helpers or the documentation that
|
|
109
|
+
leaves what a bundle can use as it is. Bundles keep declaring `^<major>.<minor>.0`, so it is
|
|
110
|
+
released whenever it is ready.
|
|
111
|
+
- **minor** - the contract grows. Raise it in the first commit that grows it, so a bundle using
|
|
112
|
+
the new part is never loaded by a platform without it; release it with the platform that
|
|
113
|
+
implements it.
|
|
114
|
+
- **major** - the contract breaks: bundles built before are refused until they are built again.
|
|
115
|
+
|
|
116
|
+
Every change of the release goes into `CHANGELOG.md`. Then, from the commit released:
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
git tag integration-sdk@<version> && git push origin integration-sdk@<version>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`.github/workflows/release-integration-sdk.yml` checks the tag says the package's version, runs the
|
|
123
|
+
SDK's gates and publishes a GitHub release with the archive npm will receive. The maintainer
|
|
124
|
+
publishes that archive, signed in to npm:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
npm publish nebulahome-integration-sdk-<version>.tgz
|
|
128
|
+
```
|