@alchemy-unifi/network 0.0.1 → 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.
- package/LICENSE +21 -0
- package/README.md +92 -1
- package/dist/index.d.mts +929 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2372 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
- package/package.json +74 -1
- package/src/AuthConfig.ts +23 -0
- package/src/AuthProvider.ts +469 -0
- package/src/Connection.ts +185 -0
- package/src/Credentials.ts +85 -0
- package/src/DnsPolicy.ts +181 -0
- package/src/FirewallPolicy.ts +456 -0
- package/src/FirewallPolicyOrdering.ts +286 -0
- package/src/FirewallZone.ts +247 -0
- package/src/HttpClient.ts +138 -0
- package/src/Lookup.ts +34 -0
- package/src/Network.ts +335 -0
- package/src/Providers.ts +59 -0
- package/src/ReadCache.ts +79 -0
- package/src/Site.ts +100 -0
- package/src/SiteManager.ts +68 -0
- package/src/State.ts +607 -0
- package/src/TrafficMatchingList.ts +250 -0
- package/src/WifiBroadcast.ts +318 -0
- package/src/index.ts +17 -0
- package/src/internal/Fields.ts +49 -0
- package/src/internal/Networks.ts +7 -0
- package/src/internal/Plan.ts +22 -0
- package/src/internal/Services.ts +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HamishWHC
|
|
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 +1,92 @@
|
|
|
1
|
-
|
|
1
|
+
# @alchemy-unifi/network
|
|
2
|
+
|
|
3
|
+
[Alchemy](https://alchemy.run) provider for the UniFi Network application: manage a UniFi site's networks, Wi-Fi and zone-based firewall as Effect code. It connects to a console directly or through the ui.com cloud connector, and can keep the stack's state on the console itself.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @alchemy-unifi/network alchemy effect @effect/platform-node
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## What it manages
|
|
10
|
+
|
|
11
|
+
| Resource | What |
|
|
12
|
+
| ------------------------ | ---------------------------------------------------------------------- |
|
|
13
|
+
| `FirewallZone` | Custom zones in the zone-based firewall |
|
|
14
|
+
| `Network` | Networks (VLANs), with DHCP and zone membership |
|
|
15
|
+
| `WifiBroadcast` | Wi-Fi networks (SSIDs), standard or IoT-optimised |
|
|
16
|
+
| `TrafficMatchingList` | Port, IPv4 and IPv6 lists for firewall policies |
|
|
17
|
+
| `FirewallPolicy` | Zone-to-zone firewall policies |
|
|
18
|
+
| `FirewallPolicyOrdering` | The evaluation order of a zone pair's policies |
|
|
19
|
+
| `DnsPolicy` | Local DNS records (A, AAAA, CNAME, MX, SRV, TXT) and forwarded domains |
|
|
20
|
+
|
|
21
|
+
Zones, networks, Wi-Fi, lists and policies also have `lookup`s for things the stack references but doesn't manage, and `FirewallZone.INTERNAL`, `.EXTERNAL`, `.GATEWAY` and so on name the built-in zones. Existing objects can be adopted with `alchemy deploy --adopt`.
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import * as UnifiNetwork from "@alchemy-unifi/network";
|
|
27
|
+
import * as Alchemy from "alchemy";
|
|
28
|
+
import * as Effect from "effect/Effect";
|
|
29
|
+
|
|
30
|
+
export default Alchemy.Stack(
|
|
31
|
+
"HomeNetwork",
|
|
32
|
+
{ providers: UnifiNetwork.providers(), state: UnifiNetwork.state() },
|
|
33
|
+
Effect.gen(function* () {
|
|
34
|
+
const cameras = yield* UnifiNetwork.FirewallZone("cameras", { name: "Cameras" });
|
|
35
|
+
const cctv = yield* UnifiNetwork.Network("cctv", {
|
|
36
|
+
management: "GATEWAY",
|
|
37
|
+
name: "CCTV",
|
|
38
|
+
vlanId: 30,
|
|
39
|
+
enabled: true,
|
|
40
|
+
cellularBackupEnabled: false,
|
|
41
|
+
internetAccessEnabled: false,
|
|
42
|
+
isolationEnabled: true,
|
|
43
|
+
zone: cameras,
|
|
44
|
+
ipv4Configuration: { autoScaleEnabled: false, hostIpAddress: "192.168.30.1", prefixLength: 24 },
|
|
45
|
+
});
|
|
46
|
+
yield* UnifiNetwork.FirewallPolicy("cameras-to-internal", {
|
|
47
|
+
name: "Block cameras to internal",
|
|
48
|
+
enabled: true,
|
|
49
|
+
action: { type: "BLOCK" },
|
|
50
|
+
source: { zone: cameras },
|
|
51
|
+
destination: { zone: UnifiNetwork.FirewallZone.INTERNAL },
|
|
52
|
+
ipProtocolScope: { ipVersion: "IPV4_AND_IPV6" },
|
|
53
|
+
loggingEnabled: false,
|
|
54
|
+
});
|
|
55
|
+
return { cctv: cctv.networkId };
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then `npx alchemy plan` and `npx alchemy deploy`. [Getting started](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/getting-started.md) walks through it, including taking over an existing setup with `--adopt`.
|
|
61
|
+
|
|
62
|
+
## Connecting to a console
|
|
63
|
+
|
|
64
|
+
Add the `UnifiNetwork` provider to Alchemy's default profile:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npx alchemy profile edit --add UnifiNetwork
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
It asks how to reach the console:
|
|
71
|
+
|
|
72
|
+
- **Directly:** the console's URL (e.g. `https://192.168.1.1`) and a Network API key (the Network app's Settings → Integrations). It offers to pin the console's self-signed certificate.
|
|
73
|
+
- **Through ui.com:** a Site Manager API key from unifi.ui.com. It lists your consoles to pick from.
|
|
74
|
+
|
|
75
|
+
Then `npx alchemy profile show` connects and shows the Network version. Use other profiles (`--profile <name>`) for other consoles, sites or connection methods, and in CI set `UNIFI_URL` (or `UNIFI_CONSOLE_ID`) and `UNIFI_API_KEY` instead. See [connecting to a console](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/connecting.md).
|
|
76
|
+
|
|
77
|
+
## State on the console
|
|
78
|
+
|
|
79
|
+
`UnifiNetwork.state()` keeps the stack's state in a disabled firewall policy on the console it manages, so a stack needs nothing but the console: no S3 bucket or other store. Every run locks the stage with a short-lived traffic-matching list. It suits UniFi-only stacks, and holds up to about 7.5 MiB of compressed state through ui.com or 16 MiB directly. Any other Alchemy state store works too. [Details and gotchas](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/state.md).
|
|
80
|
+
|
|
81
|
+
## Requirements
|
|
82
|
+
|
|
83
|
+
- UniFi Network **10.6** (the provider tracks the latest stable release) with the zone-based firewall.
|
|
84
|
+
- Node 22 or later, Alchemy 2 (beta) and Effect 4.
|
|
85
|
+
|
|
86
|
+
## Docs
|
|
87
|
+
|
|
88
|
+
[The docs](https://github.com/HamishWHC/alchemy-unifi/tree/main/docs#readme) cover [getting started](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/getting-started.md), [connecting](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/connecting.md), [concepts](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/concepts.md), each resource with examples, and [the state store](https://github.com/HamishWHC/alchemy-unifi/blob/main/docs/state.md). The raw SDK is [`@alchemy-unifi/network-sdk`](https://www.npmjs.com/package/@alchemy-unifi/network-sdk).
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|