@black-duty/sing-box-schema 1.11.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Black Duty Team
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 ADDED
@@ -0,0 +1,168 @@
1
+ <div align="center">
2
+
3
+ # Sing-box Schema <br> ✍️ 📦
4
+
5
+ > Provides type-safe [**sing-box**](https://sing-box.sagernet.org/) configuration syntax support for code editors / TypeScript projects
6
+
7
+ [![Version - v1.11.1](https://img.shields.io/badge/Version-v1.11.1-yellow?style=for-the-badge&logo=task&logoColor=white)](https://github.com/SagerNet/sing-box/tree/v1.11.1) [![JSON Schema - Draft 2020-12](/badges/JSON_Schema-Draft_2020--12-white.svg)](https://json-schema.org/draft/2020-12) [![Typescript - 5](https://img.shields.io/badge/typescript-5-grey.svg?style=for-the-badge&logo=typescript&logoColor=white&labelColor=007ACC)]([https://](https://www.typescriptlang.org/)) [![Zod - 4](https://img.shields.io/badge/Zod-4-grey.svg?style=for-the-badge&logo=zod&logoColor=white&labelColor=408AFE)](https://zod.dev)
8
+
9
+ **English** | [**中文**](/README_ZH.md)
10
+
11
+ </div>
12
+
13
+ ## Adapted Version
14
+
15
+ Sing-box v1.11.x
16
+
17
+ This project's tags correspond to the `sing-box` project's versions. Switch to different tags to get configuration formats compatible with different `sing-box` versions.
18
+
19
+ ## Branch Description
20
+
21
+ This project has the following branches, each adapted to different versions of `sing-box`:
22
+
23
+ - **main**: The main branch with the latest commits.
24
+ - **stable**: Adapts to the stable version of `sing-box` (currently v1.12.x).
25
+ - **legacy**: Adapts to older versions of `sing-box` (e.g., older versions in the Play Store / App Store that cannot be updated), currently v1.11.x.
26
+ - **🚧 next**: \[WIP\] Adapts to the actively developed version of `sing-box` (currently v1.13.x).
27
+
28
+ Developers can switch between different branches to adapt to their progress. For regular users, it is recommended to use tags to locate specific versions.
29
+
30
+ ## Usage
31
+
32
+ ### JSON Schema / For Users
33
+
34
+ You can use it in Visual Studio Code or other JSON Schema-supported editors. Open the `sing-box` configuration JSON file and add the following at the top of the file:
35
+
36
+ ```json
37
+ {
38
+ "$schema": "https://unpkg.com/@black-duty/sing-box-schema@1.11.1/schema.json"
39
+ }
40
+ ```
41
+
42
+ Or use the Chinese version:
43
+
44
+ ```json
45
+ {
46
+ "$schema": "https://unpkg.com/@black-duty/sing-box-schema@1.11.1/schema.zh.json"
47
+ }
48
+ ```
49
+
50
+ In addition to Unpkg's npm mirror, you can use:
51
+
52
+ <details>
53
+ <summary>GitHub Repository</summary>
54
+
55
+ ```json
56
+ {
57
+ "$schema": "https://raw.githubusercontent.com/BlackDuty/sing-box-schema/refs/tags/v1.11.1/schema.json"
58
+ }
59
+ ```
60
+
61
+ Or use the Chinese version:
62
+
63
+ ```json
64
+ {
65
+ "$schema": "https://raw.githubusercontent.com/BlackDuty/sing-box-schema/refs/tags/v1.11.1/schema.zh.json"
66
+ }
67
+ ```
68
+ </details>
69
+ <details>
70
+ <summary>Github Release</summary>
71
+
72
+ ```json
73
+ {
74
+ "$schema": "https://github.com/BlackDuty/sing-box-schema/releases/download/v1.11.1/schema.json"
75
+ }
76
+ ```
77
+
78
+ Or use the Chinese version:
79
+
80
+ ```json
81
+ {
82
+ "$schema": "https://github.com/BlackDuty/sing-box-schema/releases/download/v1.11.1/schema.zh.json"
83
+ }
84
+ ```
85
+ </details>
86
+
87
+ ### Zod Schema / For Developers
88
+
89
+ If you are a developer working with `sing-box` configurations in a TypeScript or JavaScript project, you can use the `Configuration` Schema to validate your configuration objects programmatically.
90
+
91
+ ```typescript
92
+ import { Configuration } from '@black-duty/sing-box-schema';
93
+
94
+ // Your sing-box configuration object
95
+ const myConfig = {
96
+ "log": {
97
+ "level": "info"
98
+ },
99
+ "inbounds": [
100
+ {
101
+ "type": "socks",
102
+ "listen": "127.0.0.1",
103
+ "listen_port": 1080
104
+ }
105
+ ],
106
+ "outbounds": [
107
+ {
108
+ "type": "direct"
109
+ }
110
+ ]
111
+
112
+ // ... more configurations
113
+ };
114
+
115
+ try {
116
+ const validatedConfig = Configuration.parse(myConfig);
117
+ console.log('Configuration is valid!', validatedConfig);
118
+ } catch (error) {
119
+ console.error('Configuration is invalid:', error);
120
+ // 'error' will be a ZodError instance with detailed validation issues.
121
+ }
122
+ ```
123
+
124
+ ## Installation
125
+
126
+ Install this library using your favorite package manager:
127
+
128
+ ```bash
129
+ bun add @black-duty/sing-box-schema
130
+ # or
131
+ npm install @black-duty/sing-box-schema
132
+ # or
133
+ yarn add @black-duty/sing-box-schema
134
+ ```
135
+
136
+ ### Local Development and Contributions
137
+
138
+ If you wish to contribute to the `sing-box-schema` project or develop locally, please follow these steps:
139
+
140
+ 1. **Clone the repository**:
141
+ ```bash
142
+ git clone https://github.com/BlackDuty/sing-box-schema.git
143
+ cd sing-box-schema
144
+ ```
145
+ 2. **Install dependencies**:
146
+ ```bash
147
+ bun install
148
+ ```
149
+ 3. **Build the project**:
150
+ ```bash
151
+ bun run build
152
+ ```
153
+ This will compile the TypeScript code and generate the JSON Schema files in the `dist` directory.
154
+ 4. **Code Linting and Formatting**:
155
+ ```bash
156
+ bun run lint
157
+ ```
158
+ 5. **Manually Generate JSON Schema**:
159
+ ```bash
160
+ bun run generate
161
+ ```
162
+ This command is automatically run during the `build` process, but you can run it manually if needed.
163
+
164
+ Contributions are welcome! Feel free to open an issue or submit a pull request.
165
+
166
+ ## License
167
+
168
+ This project is licensed under the MIT License.