@black-duty/sing-box-schema 1.12.2

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,138 @@
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.12.2](https://img.shields.io/badge/Version-v1.12.2-yellow?style=for-the-badge&logo=task&logoColor=white)](https://github.com/SagerNet/sing-box/tree/v1.12.2) [![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.12.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
+ ## Usage
20
+
21
+ ### JSON Schema / For Users
22
+
23
+ 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:
24
+
25
+ ```json
26
+ {
27
+ "$schema": "https://unpkg.com/@black-duty/sing-box-schema@1.12.2/schema.json"
28
+ }
29
+ ```
30
+
31
+ Or use the Chinese version:
32
+
33
+ ```json
34
+ {
35
+ "$schema": "https://unpkg.com/@black-duty/sing-box-schema@1.12.2/schema.zh.json"
36
+ }
37
+ ```
38
+
39
+ In addition to Unpkg's npm mirror, you can also directly use links from the GitHub repository or GitHub Releases:
40
+
41
+ - GitHub Repository (raw.githubusercontent.com):
42
+
43
+ ```json
44
+ {
45
+ "$schema": "https://raw.githubusercontent.com/BlackDuty/sing-box-schema/refs/tags/v1.12.2/schema.json"
46
+ }
47
+ ```
48
+
49
+ - GitHub Releases (for specific versions):
50
+
51
+ ```json
52
+ {
53
+ "$schema": "https://github.com/BlackDuty/sing-box-schema/releases/download/v1.12.2/schema.json"
54
+ }
55
+ ```
56
+
57
+ ### Zod Schema / For Developers
58
+
59
+ 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.
60
+
61
+ ```typescript
62
+ import { Configuration } from '@black-duty/sing-box-schema';
63
+
64
+ // Your sing-box configuration object
65
+ const myConfig = {
66
+ "log": {
67
+ "level": "info"
68
+ },
69
+ "inbounds": [
70
+ {
71
+ "type": "socks",
72
+ "listen": "127.0.0.1",
73
+ "listen_port": 1080
74
+ }
75
+ ],
76
+ "outbounds": [
77
+ {
78
+ "type": "direct"
79
+ }
80
+ ]
81
+
82
+ // ... more configurations
83
+ };
84
+
85
+ try {
86
+ const validatedConfig = Configuration.parse(myConfig);
87
+ console.log('Configuration is valid!', validatedConfig);
88
+ } catch (error) {
89
+ console.error('Configuration is invalid:', error);
90
+ // 'error' will be a ZodError instance with detailed validation issues.
91
+ }
92
+ ```
93
+
94
+ ## Installation
95
+
96
+ Install this library using your favorite package manager:
97
+
98
+ ```bash
99
+ bun add @black-duty/sing-box-schema
100
+ # or
101
+ npm install @black-duty/sing-box-schema
102
+ # or
103
+ yarn add @black-duty/sing-box-schema
104
+ ```
105
+
106
+ ### Local Development and Contributions
107
+
108
+ If you wish to contribute to the `sing-box-schema` project or develop locally, please follow these steps:
109
+
110
+ 1. **Clone the repository**:
111
+ ```bash
112
+ git clone https://github.com/BlackDuty/sing-box-schema.git
113
+ cd sing-box-schema
114
+ ```
115
+ 2. **Install dependencies**:
116
+ ```bash
117
+ bun install
118
+ ```
119
+ 3. **Build the project**:
120
+ ```bash
121
+ bun run build
122
+ ```
123
+ This will compile the TypeScript code and generate the JSON Schema files in the `dist` directory.
124
+ 4. **Code Linting and Formatting**:
125
+ ```bash
126
+ bun run lint
127
+ ```
128
+ 5. **Manually Generate JSON Schema**:
129
+ ```bash
130
+ bun run generate
131
+ ```
132
+ This command is automatically run during the `build` process, but you can run it manually if needed.
133
+
134
+ Contributions are welcome! Feel free to open an issue or submit a pull request.
135
+
136
+ ## License
137
+
138
+ This project is licensed under the MIT License.