@aigne/afs-dns 1.11.0-beta.6

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.md ADDED
@@ -0,0 +1,26 @@
1
+ # Proprietary License
2
+
3
+ Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
4
+
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. Unauthorized copying, modification, distribution, or use of
7
+ this Software, via any medium, is strictly prohibited.
8
+
9
+ The Software is provided for internal use only within ArcBlock, Inc. and its
10
+ authorized affiliates.
11
+
12
+ ## No License Granted
13
+
14
+ No license, express or implied, is granted to any party for any purpose.
15
+ All rights are reserved by ArcBlock, Inc.
16
+
17
+ ## Public Artifact Distribution
18
+
19
+ Portions of this Software may be released publicly under separate open-source
20
+ licenses (such as MIT License) through designated public repositories. Such
21
+ public releases are governed by their respective licenses and do not affect
22
+ the proprietary nature of this repository.
23
+
24
+ ## Contact
25
+
26
+ For licensing inquiries, contact: legal@arcblock.io
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # @aigne/afs-dns
2
+
3
+ AFS DNS Provider - 统一的 DNS 管理接口,支持多种 DNS 服务商。
4
+
5
+ ## 支持的 Provider
6
+
7
+ | Provider | 配置值 | 说明 |
8
+ |----------|--------|------|
9
+ | AWS Route53 | `route53` | 默认 Provider,完整支持 |
10
+ | Google Cloud DNS | `clouddns` | Google Cloud 托管 DNS |
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ pnpm add @aigne/afs-dns
16
+
17
+ # Route53 需要 AWS SDK(已包含)
18
+ # Cloud DNS 需要额外安装:
19
+ pnpm add @google-cloud/dns
20
+ ```
21
+
22
+ ## 配置示例
23
+
24
+ ### Route53 (AWS)
25
+
26
+ ```toml
27
+ [[mounts]]
28
+ path = "/dns/aws"
29
+ uri = "dns://example.com"
30
+ access_mode = "readwrite"
31
+
32
+ [mounts.options]
33
+ provider = "route53"
34
+ region = "us-east-1"
35
+
36
+ [mounts.options.credentials]
37
+ accessKeyId = "${AWS_ACCESS_KEY_ID}"
38
+ secretAccessKey = "${AWS_SECRET_ACCESS_KEY}"
39
+
40
+ [mounts.options.permissions]
41
+ preset = "standard" # safe | standard | full
42
+ ```
43
+
44
+ ### Cloud DNS (Google Cloud)
45
+
46
+ ```toml
47
+ [[mounts]]
48
+ path = "/dns/gcp"
49
+ uri = "dns://example.com"
50
+ access_mode = "readwrite"
51
+
52
+ [mounts.options]
53
+ provider = "clouddns"
54
+ projectId = "my-gcp-project"
55
+ keyFilename = "/path/to/service-account.json"
56
+
57
+ [mounts.options.permissions]
58
+ preset = "standard"
59
+ ```
60
+
61
+ ### LocalStack (本地测试)
62
+
63
+ ```toml
64
+ [[mounts]]
65
+ path = "/dns/local"
66
+ uri = "dns://test.local"
67
+ access_mode = "readwrite"
68
+
69
+ [mounts.options]
70
+ provider = "route53"
71
+ endpoint = "http://localhost:4566"
72
+ region = "us-east-1"
73
+
74
+ [mounts.options.credentials]
75
+ accessKeyId = "test"
76
+ secretAccessKey = "test"
77
+ ```
78
+
79
+ ## 使用方式
80
+
81
+ ### CLI
82
+
83
+ ```bash
84
+ # 列出所有记录
85
+ afs ls /dns/aws
86
+
87
+ # 读取记录
88
+ afs read /dns/aws/www
89
+
90
+ # 读取 Zone 元数据
91
+ afs read /dns/aws/_zone
92
+
93
+ # 创建/更新记录
94
+ afs write /dns/aws/api --content '{"type":"A","ttl":300,"values":["1.2.3.4"]}'
95
+
96
+ # 删除记录
97
+ afs rm /dns/aws/old-record
98
+
99
+ # 删除特定类型
100
+ afs rm /dns/aws/www?type=AAAA
101
+ ```
102
+
103
+ ### 编程式使用
104
+
105
+ ```typescript
106
+ import { DNSProvider, Route53Adapter, CloudDNSAdapter } from "@aigne/afs-dns";
107
+
108
+ // Route53
109
+ const route53 = new Route53Adapter({
110
+ region: "us-east-1",
111
+ credentials: {
112
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
113
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
114
+ },
115
+ });
116
+
117
+ // Cloud DNS
118
+ const cloudDNS = new CloudDNSAdapter({
119
+ projectId: "my-project",
120
+ keyFilename: "/path/to/service-account.json",
121
+ });
122
+
123
+ // 创建 Provider
124
+ const provider = new DNSProvider({
125
+ zone: "example.com",
126
+ adapter: route53, // 或 cloudDNS
127
+ accessMode: "readwrite",
128
+ permissions: { preset: "standard" },
129
+ });
130
+
131
+ // 列出记录
132
+ const records = await provider.list("/");
133
+
134
+ // 读取记录
135
+ const www = await provider.read("/www");
136
+
137
+ // 写入记录
138
+ await provider.write("/api", {
139
+ content: { type: "A", ttl: 300, values: ["1.2.3.4"] },
140
+ });
141
+ ```
142
+
143
+ ## 目录结构
144
+
145
+ ```
146
+ /dns/example.com/
147
+ ├── @ # 根域名记录 (apex)
148
+ ├── www # www.example.com
149
+ ├── api # api.example.com
150
+ ├── *.staging # 通配符记录
151
+ ├── _dmarc # DMARC 记录
152
+ └── _zone # Zone 元数据(只读)
153
+ ```
154
+
155
+ ## 支持的记录类型
156
+
157
+ | 类型 | 值格式 | 示例 |
158
+ |------|--------|------|
159
+ | A | `string[]` | `["1.2.3.4", "5.6.7.8"]` |
160
+ | AAAA | `string[]` | `["2001:db8::1"]` |
161
+ | CNAME | `string` | `"alias.example.com"` |
162
+ | MX | `{priority, value}[]` | `[{"priority": 10, "value": "mail.example.com"}]` |
163
+ | TXT | `string[]` | `["v=spf1 include:..."]` |
164
+ | NS | `string[]` | `["ns1.example.com"]` |
165
+ | SRV | `{priority, weight, port, target}[]` | `[{"priority": 10, "weight": 5, "port": 443, "target": "..."}]` |
166
+ | CAA | `{flags, tag, value}[]` | `[{"flags": 0, "tag": "issue", "value": "letsencrypt.org"}]` |
167
+ | PTR | `string` | `"host.example.com"` |
168
+ | SOA | (只读) | 区域授权记录 |
169
+
170
+ ## 权限模型
171
+
172
+ 危险操作默认禁止,需要显式配置开启:
173
+
174
+ | 操作 | 默认 | 说明 |
175
+ |------|------|------|
176
+ | `read` | 允许 | 读取任何记录 |
177
+ | `write` | 按 access_mode | 普通记录写入 |
178
+ | `delete` | 按 access_mode | 普通记录删除 |
179
+ | `modify_root` | 禁止 | 修改根域名 (@) |
180
+ | `modify_ns` | 禁止 | 修改 NS 记录 |
181
+ | `modify_wildcard` | 禁止 | 修改通配符 (*) |
182
+ | `delete_zone` | 禁止 | 删除整个 Zone |
183
+
184
+ ### 预设模式
185
+
186
+ ```toml
187
+ [mounts.options.permissions]
188
+ preset = "standard" # 选择预设
189
+ ```
190
+
191
+ | 预设 | write | delete | modify_root | modify_ns |
192
+ |------|-------|--------|-------------|-----------|
193
+ | `safe` | ✓ | ✗ | ✗ | ✗ |
194
+ | `standard` | ✓ | ✓ | ✗ | ✗ |
195
+ | `full` | ✓ | ✓ | ✓ | ✓ |
196
+
197
+ ### 显式开启危险操作
198
+
199
+ ```toml
200
+ [mounts.options.permissions]
201
+ preset = "standard"
202
+
203
+ [mounts.options.permissions.dangerous]
204
+ modify_root = true # 允许修改根域名
205
+ modify_wildcard = true # 允许修改通配符
206
+ ```
207
+
208
+ ## E2E 测试
209
+
210
+ 使用 LocalStack 进行本地测试:
211
+
212
+ ```bash
213
+ # 启动 LocalStack
214
+ docker run -d --name localstack-dns \
215
+ -p 4566:4566 \
216
+ -e SERVICES=route53 \
217
+ localstack/localstack
218
+
219
+ # 运行测试
220
+ cd providers/dns
221
+ pnpm test:e2e:full
222
+ ```
223
+
224
+ ## 依赖
225
+
226
+ - `@aws-sdk/client-route-53` - AWS Route53 SDK(内置)
227
+ - `@google-cloud/dns` - Google Cloud DNS SDK(可选,peer dependency)
228
+
229
+ ## 注意事项
230
+
231
+ - Route53 API 有请求限制(5 requests/second),内置 rate limiting
232
+ - DNS 变更是最终一致的,写入后可能需要等待传播
233
+ - Zone 创建/删除不在 AFS 范围内(通过云控制台或 IaC 工具管理)