Skip to content

Commit ffec2b8

Browse files
feat: Publish landscape-types package (#172)
1 parent ee5d9a2 commit ffec2b8

File tree

157 files changed

+406
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+406
-194
lines changed

.github/workflows/build-and-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ jobs:
301301
run: |
302302
mkdir -p output
303303
pnpm install --frozen-lockfile
304-
pnpm --filter landscape-types generate
304+
pnpm --filter @landscape-router/types generate
305305
pnpm --filter landscape-webui build
306306
cd landscape-webui
307307
mkdir static && mv dist/* static/
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Publish Types to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- npm
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version to publish (e.g. 0.14.0)'
11+
required: true
12+
13+
jobs:
14+
publish-types:
15+
runs-on: ubuntu-22.04-arm
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v5
20+
21+
- name: Cache OpenAPI spec
22+
if: github.event_name == 'push'
23+
id: cache-openapi
24+
uses: actions/cache@v4
25+
with:
26+
path: landscape-types/openapi.json
27+
key: openapi-spec-${{ hashFiles('Cargo.lock') }}-${{ github.sha }}
28+
restore-keys: |
29+
openapi-spec-${{ hashFiles('Cargo.lock') }}-
30+
openapi-spec-
31+
32+
- name: Install system dependencies
33+
if: steps.cache-openapi.outputs.cache-hit != 'true'
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y cmake clang curl gcc llvm make pkg-config libelf-dev libclang-dev zlib1g-dev
37+
38+
- name: Setup Rust
39+
if: steps.cache-openapi.outputs.cache-hit != 'true'
40+
uses: dtolnay/rust-toolchain@stable
41+
42+
- name: Generate OpenAPI spec
43+
if: steps.cache-openapi.outputs.cache-hit != 'true'
44+
run: cargo test -p landscape-webserver export_openapi_json -- --nocapture
45+
46+
- name: Setup pnpm
47+
uses: pnpm/action-setup@v4
48+
49+
- name: Setup Node.js
50+
uses: actions/setup-node@v6
51+
with:
52+
node-version: 22
53+
54+
- name: Install dependencies & generate types
55+
run: |
56+
pnpm install --frozen-lockfile
57+
pnpm --filter @landscape-router/types generate
58+
59+
- name: Set version
60+
run: |
61+
if [ -n "${{ github.event.inputs.version }}" ]; then
62+
VERSION="${{ github.event.inputs.version }}"
63+
else
64+
BASE=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "landscape-webserver") | .version')
65+
VERSION="${BASE}-build.${{ github.run_id }}"
66+
fi
67+
cd landscape-types
68+
pnpm pkg set version="$VERSION"
69+
70+
- name: Publish to npm
71+
run: |
72+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
73+
pnpm --filter @landscape-router/types publish --no-git-checks --access public
74+
env:
75+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

gen_ts_bindings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ rm -rf "$API_DIR"
1515

1616
# 3. Regenerate via orval
1717
echo "Running orval..."
18-
cd "$SCRIPT_DIR" && pnpm --filter landscape-types generate
18+
cd "$SCRIPT_DIR" && pnpm --filter @landscape-router/types generate
1919

2020
echo "Done."

landscape-types/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ node_modules
88
# generated from Rust OpenAPI spec — regenerate via gen_ts_bindings.sh
99
openapi.json
1010

11-
# orval generated files — regenerate via `pnpm generate`
11+
# orval generated files — regenerate via gen_ts_bindings.sh
1212
src/api/

landscape-types/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
openapi.json
3+
orval.config.ts

landscape-types/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# @landscape-router/types
2+
3+
TypeScript API client and type definitions for [Landscape Router](https://github.com/ThisSeanZhang/landscape), auto-generated from OpenAPI spec via [orval](https://orval.dev/).
4+
5+
## Install
6+
7+
```bash
8+
npm install @landscape-router/types
9+
# or
10+
pnpm add @landscape-router/types
11+
```
12+
13+
Requires `axios` as a peer dependency:
14+
15+
```bash
16+
npm install axios
17+
```
18+
19+
## Usage
20+
21+
### 1. Configure axios instance
22+
23+
Before calling any API function, you must set up the axios instance:
24+
25+
```ts
26+
import axios from "axios";
27+
import { setAxiosInstance } from "@landscape-router/types/mutator";
28+
29+
const instance = axios.create({
30+
baseURL: "https://your-landscape-router:6443",
31+
timeout: 30000,
32+
});
33+
34+
setAxiosInstance(instance);
35+
```
36+
37+
### 2. Call API functions
38+
39+
```ts
40+
import { getFlowRules } from "@landscape-router/types/api/flow-rules/flow-rules";
41+
import { getDnsRule } from "@landscape-router/types/api/dns-rules/dns-rules";
42+
43+
// Fetch all flow rules
44+
const flows = await getFlowRules();
45+
46+
// Fetch a specific DNS rule
47+
const rule = await getDnsRule("my-rule-id");
48+
```
49+
50+
### 3. Use type definitions
51+
52+
```ts
53+
import type { FlowConfig, DnsUpstreamConfig } from "@landscape-router/types/api/schemas";
54+
```
55+
56+
## Available API Modules
57+
58+
| Module | Import Path |
59+
|--------|-------------|
60+
| Auth | `@landscape-router/types/api/auth/auth` |
61+
| DNS Rules | `@landscape-router/types/api/dns-rules/dns-rules` |
62+
| DNS Redirects | `@landscape-router/types/api/dns-redirects/dns-redirects` |
63+
| DNS Service | `@landscape-router/types/api/dns-service/dns-service` |
64+
| DNS Upstreams | `@landscape-router/types/api/dns-upstreams/dns-upstreams` |
65+
| DHCPv4 | `@landscape-router/types/api/dhcpv4/dhcpv4` |
66+
| Docker | `@landscape-router/types/api/docker/docker` |
67+
| Docker Images | `@landscape-router/types/api/docker-images/docker-images` |
68+
| Docker Networks | `@landscape-router/types/api/docker-networks/docker-networks` |
69+
| Enrolled Devices | `@landscape-router/types/api/enrolled-devices/enrolled-devices` |
70+
| Firewall Blacklists | `@landscape-router/types/api/firewall-blacklists/firewall-blacklists` |
71+
| Firewall Service | `@landscape-router/types/api/firewall-service/firewall-service` |
72+
| Flow Rules | `@landscape-router/types/api/flow-rules/flow-rules` |
73+
| Geo IPs | `@landscape-router/types/api/geo-ips/geo-ips` |
74+
| Geo Sites | `@landscape-router/types/api/geo-sites/geo-sites` |
75+
| ICMPv6 RA | `@landscape-router/types/api/icmpv6-ra/icmpv6-ra` |
76+
| Interfaces | `@landscape-router/types/api/interfaces/interfaces` |
77+
| IP Config | `@landscape-router/types/api/ip-config/ip-config` |
78+
| IPv6 PD | `@landscape-router/types/api/ipv6-pd/ipv6-pd` |
79+
| Metric | `@landscape-router/types/api/metric/metric` |
80+
| MSS Clamp | `@landscape-router/types/api/mss-clamp/mss-clamp` |
81+
| NAT Service | `@landscape-router/types/api/nat-service/nat-service` |
82+
| PPPoE | `@landscape-router/types/api/pppo-e/pppo-e` |
83+
| Route | `@landscape-router/types/api/route/route` |
84+
| Route LAN | `@landscape-router/types/api/route-lan/route-lan` |
85+
| Route WAN | `@landscape-router/types/api/route-wan/route-wan` |
86+
| Static NAT Mappings | `@landscape-router/types/api/static-nat-mappings/static-nat-mappings` |
87+
| System Config | `@landscape-router/types/api/system-config/system-config` |
88+
| System Info | `@landscape-router/types/api/system-info/system-info` |
89+
| Wi-Fi | `@landscape-router/types/api/wi-fi/wi-fi` |
90+
| Destination IP Rules | `@landscape-router/types/api/destination-ip-rules/destination-ip-rules` |
91+
| Schemas (types only) | `@landscape-router/types/api/schemas` |
92+
93+
## License
94+
95+
[MIT](https://github.com/ThisSeanZhang/landscape/blob/main/LICENSE)

landscape-types/package.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
{
2-
"name": "landscape-types",
2+
"name": "@landscape-router/types",
33
"version": "0.13.1",
4-
"private": true,
4+
"description": "TypeScript API client and type definitions for Landscape Router, auto-generated from OpenAPI spec.",
55
"type": "module",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/ThisSeanZhang/landscape.git",
10+
"directory": "landscape-types"
11+
},
12+
"homepage": "https://github.com/ThisSeanZhang/landscape",
13+
"keywords": [
14+
"landscape",
15+
"router",
16+
"api-client",
17+
"openapi",
18+
"typescript"
19+
],
620
"exports": {
721
"./*": "./src/*"
822
},
@@ -15,8 +29,12 @@
1529
]
1630
}
1731
},
32+
"files": [
33+
"src"
34+
],
1835
"scripts": {
19-
"generate": "orval"
36+
"generate": "orval",
37+
"prepublishOnly": "echo 'Run gen_ts_bindings.sh before publishing' && test -f src/api/schemas/index.ts"
2038
},
2139
"peerDependencies": {
2240
"axios": ">=1.0.0"

landscape-webui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"axios": "^1.6.8",
2222
"ip-num": "^1.5.1",
2323
"is-ip": "^5.0.1",
24-
"landscape-types": "workspace:*",
24+
"@landscape-router/types": "workspace:*",
2525
"pinia": "^3.0.0",
2626
"pinia-plugin-persistedstate": "^4.3.0",
2727
"vue": "^3.4.21",

landscape-webui/src/api/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { LoginInfo } from "landscape-types/api/schemas";
2-
import { loginHandler } from "landscape-types/api/auth/auth";
1+
import type { LoginInfo } from "@landscape-router/types/api/schemas";
2+
import { loginHandler } from "@landscape-router/types/api/auth/auth";
33

44
export async function do_login(login: LoginInfo) {
55
return loginHandler(login);

landscape-webui/src/api/dns_rule/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
addDnsRules,
66
delDnsRules,
77
addManyDnsRules,
8-
} from "landscape-types/api/dns-rules/dns-rules";
8+
} from "@landscape-router/types/api/dns-rules/dns-rules";
99

1010
export async function get_flow_dns_rules(flow_id: number): Promise<DnsRule[]> {
1111
const data = await getFlowDnsRules(flow_id);

0 commit comments

Comments
 (0)