@singbox-iac/cli 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 +265 -0
- package/dist/cli/command-helpers.d.ts +6 -0
- package/dist/cli/command-helpers.js +34 -0
- package/dist/cli/command-helpers.js.map +1 -0
- package/dist/cli/commands/apply.d.ts +2 -0
- package/dist/cli/commands/apply.js +32 -0
- package/dist/cli/commands/apply.js.map +1 -0
- package/dist/cli/commands/author.d.ts +2 -0
- package/dist/cli/commands/author.js +194 -0
- package/dist/cli/commands/author.js.map +1 -0
- package/dist/cli/commands/build.d.ts +2 -0
- package/dist/cli/commands/build.js +198 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/check.d.ts +2 -0
- package/dist/cli/commands/check.js +23 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +2 -0
- package/dist/cli/commands/doctor.js +35 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +23 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/reload.d.ts +2 -0
- package/dist/cli/commands/reload.js +21 -0
- package/dist/cli/commands/reload.js.map +1 -0
- package/dist/cli/commands/run.d.ts +2 -0
- package/dist/cli/commands/run.js +25 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/commands/schedule.d.ts +2 -0
- package/dist/cli/commands/schedule.js +77 -0
- package/dist/cli/commands/schedule.js.map +1 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +34 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/commands/update.d.ts +2 -0
- package/dist/cli/commands/update.js +52 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/commands/verify.d.ts +2 -0
- package/dist/cli/commands/verify.js +49 -0
- package/dist/cli/commands/verify.js.map +1 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +55 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config/load-config.d.ts +2 -0
- package/dist/config/load-config.js +29 -0
- package/dist/config/load-config.js.map +1 -0
- package/dist/config/schema.d.ts +548 -0
- package/dist/config/schema.js +92 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/domain/config.d.ts +8 -0
- package/dist/domain/config.js +2 -0
- package/dist/domain/config.js.map +1 -0
- package/dist/domain/node.d.ts +11 -0
- package/dist/domain/node.js +2 -0
- package/dist/domain/node.js.map +1 -0
- package/dist/domain/outbound.d.ts +15 -0
- package/dist/domain/outbound.js +2 -0
- package/dist/domain/outbound.js.map +1 -0
- package/dist/domain/subscription.d.ts +6 -0
- package/dist/domain/subscription.js +2 -0
- package/dist/domain/subscription.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/authoring/index.d.ts +41 -0
- package/dist/modules/authoring/index.js +596 -0
- package/dist/modules/authoring/index.js.map +1 -0
- package/dist/modules/build/index.d.ts +13 -0
- package/dist/modules/build/index.js +39 -0
- package/dist/modules/build/index.js.map +1 -0
- package/dist/modules/compiler/index.d.ts +10 -0
- package/dist/modules/compiler/index.js +305 -0
- package/dist/modules/compiler/index.js.map +1 -0
- package/dist/modules/doctor/index.d.ts +17 -0
- package/dist/modules/doctor/index.js +89 -0
- package/dist/modules/doctor/index.js.map +1 -0
- package/dist/modules/fetcher/index.d.ts +4 -0
- package/dist/modules/fetcher/index.js +42 -0
- package/dist/modules/fetcher/index.js.map +1 -0
- package/dist/modules/init/index.d.ts +12 -0
- package/dist/modules/init/index.js +41 -0
- package/dist/modules/init/index.js.map +1 -0
- package/dist/modules/manager/index.d.ts +29 -0
- package/dist/modules/manager/index.js +133 -0
- package/dist/modules/manager/index.js.map +1 -0
- package/dist/modules/natural-language/index.d.ts +54 -0
- package/dist/modules/natural-language/index.js +458 -0
- package/dist/modules/natural-language/index.js.map +1 -0
- package/dist/modules/parser/index.d.ts +10 -0
- package/dist/modules/parser/index.js +113 -0
- package/dist/modules/parser/index.js.map +1 -0
- package/dist/modules/preview/index.d.ts +22 -0
- package/dist/modules/preview/index.js +141 -0
- package/dist/modules/preview/index.js.map +1 -0
- package/dist/modules/rule-templates/index.d.ts +15 -0
- package/dist/modules/rule-templates/index.js +200 -0
- package/dist/modules/rule-templates/index.js.map +1 -0
- package/dist/modules/schedule/index.d.ts +32 -0
- package/dist/modules/schedule/index.js +155 -0
- package/dist/modules/schedule/index.js.map +1 -0
- package/dist/modules/update/index.d.ts +22 -0
- package/dist/modules/update/index.js +38 -0
- package/dist/modules/update/index.js.map +1 -0
- package/dist/modules/user-rules/index.d.ts +18 -0
- package/dist/modules/user-rules/index.js +98 -0
- package/dist/modules/user-rules/index.js.map +1 -0
- package/dist/modules/verification/index.d.ts +49 -0
- package/dist/modules/verification/index.js +432 -0
- package/dist/modules/verification/index.js.map +1 -0
- package/dist/shared/errors.d.ts +3 -0
- package/dist/shared/errors.js +7 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/logger.d.ts +2 -0
- package/dist/shared/logger.js +5 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/result.d.ts +11 -0
- package/dist/shared/result.js +7 -0
- package/dist/shared/result.js.map +1 -0
- package/docs/antigravity-endpoints.md +77 -0
- package/docs/competitive-landscape.md +45 -0
- package/docs/development-workflow.md +80 -0
- package/docs/natural-language-authoring.md +376 -0
- package/docs/positioning.md +42 -0
- package/docs/releasing.md +72 -0
- package/docs/rule-templates.md +122 -0
- package/docs/rules-dsl.md +107 -0
- package/docs/runtime-on-macos.md +42 -0
- package/docs/sing-box-config-primer.md +39 -0
- package/docs/subscription-format.md +38 -0
- package/examples/builder.config.yaml +220 -0
- package/examples/custom.rules.yaml +18 -0
- package/package.json +51 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { access, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { buildConfigArtifact } from "../build/index.js";
|
|
7
|
+
import { applyPlanToBuilderConfig, renderGeneratedRules, renderUpdatedBuilderConfig, } from "../natural-language/index.js";
|
|
8
|
+
export async function generateAuthoringPreview(input) {
|
|
9
|
+
const [currentConfigRaw, currentRulesRaw] = await Promise.all([
|
|
10
|
+
readFile(input.configPath, "utf8"),
|
|
11
|
+
readFileIfExists(input.rulesPath),
|
|
12
|
+
]);
|
|
13
|
+
const proposedRules = renderGeneratedRules(input.plan);
|
|
14
|
+
const proposedConfig = renderUpdatedBuilderConfig({
|
|
15
|
+
rawConfig: currentConfigRaw,
|
|
16
|
+
rulesPath: input.rulesPath,
|
|
17
|
+
...(input.plan.scheduleIntervalMinutes
|
|
18
|
+
? { intervalMinutes: input.plan.scheduleIntervalMinutes }
|
|
19
|
+
: {}),
|
|
20
|
+
...(input.plan.groupDefaults ? { groupDefaults: input.plan.groupDefaults } : {}),
|
|
21
|
+
...(input.plan.verificationOverrides
|
|
22
|
+
? { verificationOverrides: input.plan.verificationOverrides }
|
|
23
|
+
: {}),
|
|
24
|
+
});
|
|
25
|
+
const effectiveConfig = applyPlanToBuilderConfig(input.config, {
|
|
26
|
+
rulesPath: input.rulesPath,
|
|
27
|
+
plan: input.plan,
|
|
28
|
+
});
|
|
29
|
+
const rulesDiff = await createUnifiedDiff("rules", currentRulesRaw ?? "", proposedRules);
|
|
30
|
+
const configDiff = await createUnifiedDiff("builder-config", currentConfigRaw, proposedConfig);
|
|
31
|
+
if (input.buildStaging === false) {
|
|
32
|
+
return {
|
|
33
|
+
rulesDiff,
|
|
34
|
+
configDiff,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const runDir = await mkdtemp(path.join(tmpdir(), "singbox-iac-author-preview-"));
|
|
38
|
+
try {
|
|
39
|
+
const tempRulesPath = path.join(runDir, "custom.rules.yaml");
|
|
40
|
+
const tempStagingPath = path.join(runDir, "config.staging.json");
|
|
41
|
+
await writeFile(tempRulesPath, proposedRules, "utf8");
|
|
42
|
+
await buildConfigArtifact({
|
|
43
|
+
config: {
|
|
44
|
+
...effectiveConfig,
|
|
45
|
+
output: {
|
|
46
|
+
...effectiveConfig.output,
|
|
47
|
+
stagingPath: tempStagingPath,
|
|
48
|
+
},
|
|
49
|
+
rules: {
|
|
50
|
+
...effectiveConfig.rules,
|
|
51
|
+
userRulesFile: tempRulesPath,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
...(input.subscriptionFile ? { subscriptionFile: input.subscriptionFile } : {}),
|
|
55
|
+
...(input.subscriptionUrl ? { subscriptionUrl: input.subscriptionUrl } : {}),
|
|
56
|
+
});
|
|
57
|
+
const [currentStagingRaw, proposedStagingRaw] = await Promise.all([
|
|
58
|
+
readFileIfExists(input.config.output.stagingPath),
|
|
59
|
+
readFile(tempStagingPath, "utf8"),
|
|
60
|
+
]);
|
|
61
|
+
return {
|
|
62
|
+
rulesDiff,
|
|
63
|
+
configDiff,
|
|
64
|
+
stagingDiff: await createUnifiedDiff("staging-config", currentStagingRaw ?? "", proposedStagingRaw),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await rm(runDir, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function readFileIfExists(filePath) {
|
|
72
|
+
try {
|
|
73
|
+
await access(filePath, constants.F_OK);
|
|
74
|
+
return readFile(filePath, "utf8");
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function createUnifiedDiff(label, currentContent, nextContent) {
|
|
81
|
+
const currentNormalized = ensureTrailingNewline(currentContent);
|
|
82
|
+
const nextNormalized = ensureTrailingNewline(nextContent);
|
|
83
|
+
if (currentNormalized === nextNormalized) {
|
|
84
|
+
return {
|
|
85
|
+
label,
|
|
86
|
+
changed: false,
|
|
87
|
+
diff: `(no changes in ${label})`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const runDir = await mkdtemp(path.join(tmpdir(), "singbox-iac-diff-"));
|
|
91
|
+
try {
|
|
92
|
+
const beforePath = path.join(runDir, "before.txt");
|
|
93
|
+
const afterPath = path.join(runDir, "after.txt");
|
|
94
|
+
await Promise.all([
|
|
95
|
+
writeFile(beforePath, currentNormalized, "utf8"),
|
|
96
|
+
writeFile(afterPath, nextNormalized, "utf8"),
|
|
97
|
+
]);
|
|
98
|
+
const diff = await runDiff(label, beforePath, afterPath);
|
|
99
|
+
return {
|
|
100
|
+
label,
|
|
101
|
+
changed: true,
|
|
102
|
+
diff,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await rm(runDir, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function runDiff(label, beforePath, afterPath) {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const child = spawn("/usr/bin/diff", [
|
|
112
|
+
"-u",
|
|
113
|
+
"-L",
|
|
114
|
+
`current:${label}`,
|
|
115
|
+
"-L",
|
|
116
|
+
`proposed:${label}`,
|
|
117
|
+
beforePath,
|
|
118
|
+
afterPath,
|
|
119
|
+
]);
|
|
120
|
+
let stdout = "";
|
|
121
|
+
let stderr = "";
|
|
122
|
+
child.stdout.on("data", (chunk) => {
|
|
123
|
+
stdout += chunk.toString();
|
|
124
|
+
});
|
|
125
|
+
child.stderr.on("data", (chunk) => {
|
|
126
|
+
stderr += chunk.toString();
|
|
127
|
+
});
|
|
128
|
+
child.on("error", reject);
|
|
129
|
+
child.on("close", (code) => {
|
|
130
|
+
if (code === 0 || code === 1) {
|
|
131
|
+
resolve(stdout.trimEnd());
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
reject(new Error(stderr.trim() || `diff failed for ${label}`));
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function ensureTrailingNewline(content) {
|
|
139
|
+
return content.endsWith("\n") ? content : `${content}\n`;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/preview/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAwBtC,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,KAAoC;IAEpC,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC5D,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC;QAClC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC;KAClC,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,cAAc,GAAG,0BAA0B,CAAC;QAChD,SAAS,EAAE,gBAAgB;QAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,uBAAuB;YACpC,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,u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4
|
+
readonly title: string;
|
|
5
|
+
readonly summary: string;
|
|
6
|
+
readonly beforeBuiltins: readonly UserRouteRule[];
|
|
7
|
+
readonly afterBuiltins: readonly UserRouteRule[];
|
|
8
|
+
readonly tags: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function listRuleTemplates(): readonly RuleTemplate[];
|
|
11
|
+
export declare function getRuleTemplate(id: string): RuleTemplate | undefined;
|
|
12
|
+
export declare function mergeRuleTemplates(templateIds: readonly string[]): {
|
|
13
|
+
readonly beforeBuiltins: readonly UserRouteRule[];
|
|
14
|
+
readonly afterBuiltins: readonly UserRouteRule[];
|
|
15
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
const templateCatalog = [
|
|
2
|
+
{
|
|
3
|
+
id: "developer-ai-sites",
|
|
4
|
+
title: "Developer AI Sites",
|
|
5
|
+
summary: "Route common third-party AI sites like OpenRouter and Perplexity to AI-Out.",
|
|
6
|
+
tags: ["developer", "ai"],
|
|
7
|
+
beforeBuiltins: [
|
|
8
|
+
{
|
|
9
|
+
name: "OpenRouter uses the AI selector",
|
|
10
|
+
domainSuffix: ["openrouter.ai"],
|
|
11
|
+
route: "AI-Out",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "Perplexity uses the AI selector",
|
|
15
|
+
domainSuffix: ["perplexity.ai"],
|
|
16
|
+
route: "AI-Out",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
afterBuiltins: [],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "developer-common-sites",
|
|
23
|
+
title: "Developer Common Sites",
|
|
24
|
+
summary: "Route common third-party developer sites like GitLab, npm, Vercel, Docker Hub, and Stack Overflow to Dev-Common-Out.",
|
|
25
|
+
tags: ["developer", "tools"],
|
|
26
|
+
beforeBuiltins: [
|
|
27
|
+
{
|
|
28
|
+
name: "Common third-party developer sites use Dev-Common-Out",
|
|
29
|
+
domainSuffix: [
|
|
30
|
+
"gitlab.com",
|
|
31
|
+
"npmjs.com",
|
|
32
|
+
"registry.npmjs.org",
|
|
33
|
+
"vercel.com",
|
|
34
|
+
"cloudflare.com",
|
|
35
|
+
"docker.com",
|
|
36
|
+
"hub.docker.com",
|
|
37
|
+
"stackoverflow.com",
|
|
38
|
+
"huggingface.co",
|
|
39
|
+
],
|
|
40
|
+
route: "Dev-Common-Out",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
afterBuiltins: [],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "video-us",
|
|
47
|
+
title: "Video Streaming via US",
|
|
48
|
+
summary: "Route popular US-oriented video sites to the US selector.",
|
|
49
|
+
tags: ["video", "streaming", "us"],
|
|
50
|
+
beforeBuiltins: [
|
|
51
|
+
{
|
|
52
|
+
name: "US video streaming uses US",
|
|
53
|
+
domainSuffix: [
|
|
54
|
+
"youtube.com",
|
|
55
|
+
"youtu.be",
|
|
56
|
+
"netflix.com",
|
|
57
|
+
"nflxvideo.net",
|
|
58
|
+
"primevideo.com",
|
|
59
|
+
"amazonvideo.com",
|
|
60
|
+
"disneyplus.com",
|
|
61
|
+
"disney-plus.net",
|
|
62
|
+
"tv.apple.com",
|
|
63
|
+
"hulu.com",
|
|
64
|
+
"max.com",
|
|
65
|
+
],
|
|
66
|
+
route: "US",
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
afterBuiltins: [],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "video-hk",
|
|
73
|
+
title: "Video Streaming via HK",
|
|
74
|
+
summary: "Route popular international video sites to the HK selector.",
|
|
75
|
+
tags: ["video", "streaming", "hk"],
|
|
76
|
+
beforeBuiltins: [
|
|
77
|
+
{
|
|
78
|
+
name: "International video streaming uses HK",
|
|
79
|
+
domainSuffix: [
|
|
80
|
+
"youtube.com",
|
|
81
|
+
"youtu.be",
|
|
82
|
+
"netflix.com",
|
|
83
|
+
"nflxvideo.net",
|
|
84
|
+
"primevideo.com",
|
|
85
|
+
"amazonvideo.com",
|
|
86
|
+
"disneyplus.com",
|
|
87
|
+
"disney-plus.net",
|
|
88
|
+
"tv.apple.com",
|
|
89
|
+
"hulu.com",
|
|
90
|
+
"max.com",
|
|
91
|
+
"twitch.tv",
|
|
92
|
+
],
|
|
93
|
+
route: "HK",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
afterBuiltins: [],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "video-sg",
|
|
100
|
+
title: "Video Streaming via SG",
|
|
101
|
+
summary: "Route popular international video sites to the SG selector.",
|
|
102
|
+
tags: ["video", "streaming", "sg"],
|
|
103
|
+
beforeBuiltins: [
|
|
104
|
+
{
|
|
105
|
+
name: "International video streaming uses SG",
|
|
106
|
+
domainSuffix: [
|
|
107
|
+
"youtube.com",
|
|
108
|
+
"youtu.be",
|
|
109
|
+
"netflix.com",
|
|
110
|
+
"nflxvideo.net",
|
|
111
|
+
"primevideo.com",
|
|
112
|
+
"amazonvideo.com",
|
|
113
|
+
"disneyplus.com",
|
|
114
|
+
"disney-plus.net",
|
|
115
|
+
"tv.apple.com",
|
|
116
|
+
"hulu.com",
|
|
117
|
+
"max.com",
|
|
118
|
+
"twitch.tv",
|
|
119
|
+
],
|
|
120
|
+
route: "SG",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
afterBuiltins: [],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "video-jp",
|
|
127
|
+
title: "Video Streaming via JP",
|
|
128
|
+
summary: "Route Japan-oriented video services to the JP selector.",
|
|
129
|
+
tags: ["video", "streaming", "jp"],
|
|
130
|
+
beforeBuiltins: [
|
|
131
|
+
{
|
|
132
|
+
name: "JP video streaming uses JP",
|
|
133
|
+
domainSuffix: ["abema.tv", "niconico.jp", "dmm.com", "lemino.docomo.ne.jp"],
|
|
134
|
+
route: "JP",
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
afterBuiltins: [],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "cn-video-direct",
|
|
141
|
+
title: "China Video Direct",
|
|
142
|
+
summary: "Keep common mainland video sites on direct routing.",
|
|
143
|
+
tags: ["video", "cn", "direct"],
|
|
144
|
+
beforeBuiltins: [],
|
|
145
|
+
afterBuiltins: [
|
|
146
|
+
{
|
|
147
|
+
name: "Mainland video sites stay direct",
|
|
148
|
+
domainSuffix: [
|
|
149
|
+
"bilibili.com",
|
|
150
|
+
"bilibili.tv",
|
|
151
|
+
"iqiyi.com",
|
|
152
|
+
"iq.com",
|
|
153
|
+
"youku.com",
|
|
154
|
+
"mgtv.com",
|
|
155
|
+
],
|
|
156
|
+
route: "direct",
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
export function listRuleTemplates() {
|
|
162
|
+
return templateCatalog;
|
|
163
|
+
}
|
|
164
|
+
export function getRuleTemplate(id) {
|
|
165
|
+
return templateCatalog.find((template) => template.id === id);
|
|
166
|
+
}
|
|
167
|
+
export function mergeRuleTemplates(templateIds) {
|
|
168
|
+
const resolved = templateIds.map((id) => {
|
|
169
|
+
const template = getRuleTemplate(id);
|
|
170
|
+
if (!template) {
|
|
171
|
+
throw new Error(`Unknown rule template "${id}".`);
|
|
172
|
+
}
|
|
173
|
+
return template;
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
beforeBuiltins: dedupeRules(resolved.flatMap((template) => template.beforeBuiltins)),
|
|
177
|
+
afterBuiltins: dedupeRules(resolved.flatMap((template) => template.afterBuiltins)),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function dedupeRules(rules) {
|
|
181
|
+
const byKey = new Map();
|
|
182
|
+
for (const rule of rules) {
|
|
183
|
+
byKey.set(stableRuleKey(rule), rule);
|
|
184
|
+
}
|
|
185
|
+
return [...byKey.values()];
|
|
186
|
+
}
|
|
187
|
+
function stableRuleKey(rule) {
|
|
188
|
+
return JSON.stringify({
|
|
189
|
+
inbound: rule.inbound ?? [],
|
|
190
|
+
protocol: rule.protocol ?? null,
|
|
191
|
+
network: rule.network ?? null,
|
|
192
|
+
port: rule.port ?? null,
|
|
193
|
+
domain: rule.domain ?? [],
|
|
194
|
+
domainSuffix: rule.domainSuffix ?? [],
|
|
195
|
+
ruleSet: rule.ruleSet ?? [],
|
|
196
|
+
route: rule.route ?? null,
|
|
197
|
+
action: rule.action ?? null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/rule-templates/index.ts"],"names":[],"mappings":"AAWA,MAAM,eAAe,GAA4B;IAC/C;QACE,EAAE,EAAE,oBAAoB;QACxB,KAAK,EAAE,oBAAoB;QAC3B,OAAO,EAAE,6EAA6E;QACtF,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;QACzB,cAAc,EAAE;YACd;gBACE,IAAI,EAAE,iCAAiC;gBACvC,YAAY,EAAE,CAAC,eAAe,CAAC;gBAC/B,KAAK,EAAE,QAAQ;aAChB;YACD;gBACE,IAAI,EAAE,iCAAiC;gBACvC,YAAY,EAAE,CAAC,eAAe,CAAC;gBAC/B,KAAK,EAAE,QAAQ;aAChB;SACF;QACD,aAAa,EAAE,EAAE;KAClB;IACD;QACE,EAAE,EAAE,wBAAwB;QAC5B,KAAK,EAAE,wBAAwB;QAC/B,OAAO,EACL,sHAAsH;QACxH,IAAI,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;QAC5B,cAAc,EAAE;YACd;gBACE,IAAI,EAAE,uDAAuD;gBAC7D,YAAY,EAAE;oBACZ,YAAY;oBACZ,WAAW;oBACX,oBAAoB;oBACpB,YAAY;oBACZ,gBAAgB;oBAChB,YAAY;oBACZ,gBAAgB;oBAChB,mBAAmB;oBACnB,gBAAgB;iBACjB;gBACD,KAAK,EAAE,gBAAgB;aACxB;SACF;QACD,aAAa,EAAE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32 @@
|
|
|
1
|
+
export interface ScheduleInstallInput {
|
|
2
|
+
readonly configPath: string;
|
|
3
|
+
readonly intervalMinutes: number;
|
|
4
|
+
readonly cliEntrypoint: string;
|
|
5
|
+
readonly label?: string;
|
|
6
|
+
readonly launchAgentsDir?: string;
|
|
7
|
+
readonly workingDirectory?: string;
|
|
8
|
+
readonly logsDir?: string;
|
|
9
|
+
readonly force?: boolean;
|
|
10
|
+
readonly load?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ScheduleInstallResult {
|
|
13
|
+
readonly label: string;
|
|
14
|
+
readonly plistPath: string;
|
|
15
|
+
readonly stdoutPath: string;
|
|
16
|
+
readonly stderrPath: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ScheduleRemoveInput {
|
|
19
|
+
readonly label?: string;
|
|
20
|
+
readonly launchAgentsDir?: string;
|
|
21
|
+
readonly unload?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function installLaunchdSchedule(input: ScheduleInstallInput): Promise<ScheduleInstallResult>;
|
|
24
|
+
export declare function removeLaunchdSchedule(input: ScheduleRemoveInput): Promise<string>;
|
|
25
|
+
export declare function renderLaunchAgentPlist(input: {
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly intervalMinutes: number;
|
|
28
|
+
readonly workingDirectory: string;
|
|
29
|
+
readonly stdoutPath: string;
|
|
30
|
+
readonly stderrPath: string;
|
|
31
|
+
readonly programArguments: readonly string[];
|
|
32
|
+
}): string;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { access, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
const defaultLaunchAgentLabel = "org.singbox-iac.update";
|
|
7
|
+
export async function installLaunchdSchedule(input) {
|
|
8
|
+
const label = input.label ?? defaultLaunchAgentLabel;
|
|
9
|
+
const launchAgentsDir = input.launchAgentsDir ?? path.join(homedir(), "Library", "LaunchAgents");
|
|
10
|
+
const logsDir = input.logsDir ?? path.join(homedir(), ".config", "singbox-iac", "logs");
|
|
11
|
+
const plistPath = path.join(launchAgentsDir, `${label}.plist`);
|
|
12
|
+
const stdoutPath = path.join(logsDir, `${label}.stdout.log`);
|
|
13
|
+
const stderrPath = path.join(logsDir, `${label}.stderr.log`);
|
|
14
|
+
if (input.force !== true && (await pathExists(plistPath))) {
|
|
15
|
+
throw new Error(`LaunchAgent already exists: ${plistPath}`);
|
|
16
|
+
}
|
|
17
|
+
await mkdir(launchAgentsDir, { recursive: true });
|
|
18
|
+
await mkdir(logsDir, { recursive: true });
|
|
19
|
+
if (input.load !== false) {
|
|
20
|
+
await runLaunchctl(["bootout", launchctlDomainService(label)], true);
|
|
21
|
+
}
|
|
22
|
+
const workingDirectory = input.workingDirectory ?? process.cwd();
|
|
23
|
+
const programArguments = resolveProgramArguments({
|
|
24
|
+
cliEntrypoint: path.resolve(input.cliEntrypoint),
|
|
25
|
+
configPath: path.resolve(input.configPath),
|
|
26
|
+
workingDirectory,
|
|
27
|
+
});
|
|
28
|
+
const plist = renderLaunchAgentPlist({
|
|
29
|
+
label,
|
|
30
|
+
intervalMinutes: input.intervalMinutes,
|
|
31
|
+
workingDirectory,
|
|
32
|
+
stdoutPath,
|
|
33
|
+
stderrPath,
|
|
34
|
+
programArguments,
|
|
35
|
+
});
|
|
36
|
+
await writeFile(plistPath, plist, "utf8");
|
|
37
|
+
if (input.load !== false) {
|
|
38
|
+
await runLaunchctl(["bootstrap", launchctlDomain(), plistPath]);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
label,
|
|
42
|
+
plistPath,
|
|
43
|
+
stdoutPath,
|
|
44
|
+
stderrPath,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export async function removeLaunchdSchedule(input) {
|
|
48
|
+
const label = input.label ?? defaultLaunchAgentLabel;
|
|
49
|
+
const launchAgentsDir = input.launchAgentsDir ?? path.join(homedir(), "Library", "LaunchAgents");
|
|
50
|
+
const plistPath = path.join(launchAgentsDir, `${label}.plist`);
|
|
51
|
+
if (input.unload !== false) {
|
|
52
|
+
await runLaunchctl(["bootout", launchctlDomainService(label)], true);
|
|
53
|
+
}
|
|
54
|
+
await rm(plistPath, { force: true });
|
|
55
|
+
return plistPath;
|
|
56
|
+
}
|
|
57
|
+
export function renderLaunchAgentPlist(input) {
|
|
58
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
59
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
60
|
+
<plist version="1.0">
|
|
61
|
+
<dict>
|
|
62
|
+
<key>Label</key>
|
|
63
|
+
<string>${escapeXml(input.label)}</string>
|
|
64
|
+
<key>ProgramArguments</key>
|
|
65
|
+
<array>
|
|
66
|
+
${input.programArguments
|
|
67
|
+
.map((argument) => ` <string>${escapeXml(argument)}</string>`)
|
|
68
|
+
.join("\n")}
|
|
69
|
+
</array>
|
|
70
|
+
<key>WorkingDirectory</key>
|
|
71
|
+
<string>${escapeXml(input.workingDirectory)}</string>
|
|
72
|
+
<key>StartInterval</key>
|
|
73
|
+
<integer>${input.intervalMinutes * 60}</integer>
|
|
74
|
+
<key>RunAtLoad</key>
|
|
75
|
+
<true/>
|
|
76
|
+
<key>StandardOutPath</key>
|
|
77
|
+
<string>${escapeXml(input.stdoutPath)}</string>
|
|
78
|
+
<key>StandardErrorPath</key>
|
|
79
|
+
<string>${escapeXml(input.stderrPath)}</string>
|
|
80
|
+
<key>EnvironmentVariables</key>
|
|
81
|
+
<dict>
|
|
82
|
+
<key>PATH</key>
|
|
83
|
+
<string>${escapeXml(resolveLaunchdPath())}</string>
|
|
84
|
+
</dict>
|
|
85
|
+
</dict>
|
|
86
|
+
</plist>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
async function pathExists(filePath) {
|
|
90
|
+
try {
|
|
91
|
+
await access(filePath, constants.F_OK);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function launchctlDomain() {
|
|
99
|
+
if (typeof process.getuid !== "function") {
|
|
100
|
+
throw new Error("launchd scheduling requires process.getuid(), which is unavailable here.");
|
|
101
|
+
}
|
|
102
|
+
return `gui/${process.getuid()}`;
|
|
103
|
+
}
|
|
104
|
+
function launchctlDomainService(label) {
|
|
105
|
+
return `${launchctlDomain()}/${label}`;
|
|
106
|
+
}
|
|
107
|
+
async function runLaunchctl(args, allowFailure = false) {
|
|
108
|
+
await new Promise((resolve, reject) => {
|
|
109
|
+
const child = spawn("/bin/launchctl", args, {
|
|
110
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
111
|
+
});
|
|
112
|
+
let stdout = "";
|
|
113
|
+
let stderr = "";
|
|
114
|
+
child.stdout.on("data", (chunk) => {
|
|
115
|
+
stdout += chunk.toString();
|
|
116
|
+
});
|
|
117
|
+
child.stderr.on("data", (chunk) => {
|
|
118
|
+
stderr += chunk.toString();
|
|
119
|
+
});
|
|
120
|
+
child.on("error", reject);
|
|
121
|
+
child.on("close", (code) => {
|
|
122
|
+
if (code === 0 || allowFailure) {
|
|
123
|
+
resolve();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const details = [stdout.trim(), stderr.trim()].filter((value) => value.length > 0).join("\n");
|
|
127
|
+
reject(new Error(details || `launchctl ${args.join(" ")} failed`));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function resolveLaunchdPath() {
|
|
132
|
+
const entries = [
|
|
133
|
+
process.env.PATH,
|
|
134
|
+
"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
|
|
135
|
+
]
|
|
136
|
+
.filter((value) => typeof value === "string" && value.length > 0)
|
|
137
|
+
.flatMap((value) => value.split(path.delimiter));
|
|
138
|
+
return [...new Set(entries)].join(path.delimiter);
|
|
139
|
+
}
|
|
140
|
+
function resolveProgramArguments(input) {
|
|
141
|
+
if (path.extname(input.cliEntrypoint) === ".ts") {
|
|
142
|
+
const tsxBinary = path.resolve(input.workingDirectory, "node_modules", ".bin", "tsx");
|
|
143
|
+
return [tsxBinary, input.cliEntrypoint, "update", "--config", input.configPath];
|
|
144
|
+
}
|
|
145
|
+
return [process.execPath, input.cliEntrypoint, "update", "--config", input.configPath];
|
|
146
|
+
}
|
|
147
|
+
function escapeXml(value) {
|
|
148
|
+
return value
|
|
149
|
+
.replaceAll("&", "&")
|
|
150
|
+
.replaceAll("<", "<")
|
|
151
|
+
.replaceAll(">", ">")
|
|
152
|
+
.replaceAll('"', """)
|
|
153
|
+
.replaceAll("'", "'");
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/schedule/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AA2B7B,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAA2B;IAE3B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,uBAAuB,CAAC;IACrD,MAAM,eAAe,GAAG,KAAK,CAAC,eAAe,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IACjG,MAAM,OAAO,GAAG,KAAK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AC,CAAC;AACpD,CAAC;AAED,SAAS,uBAAuB,CAAC,KAIhC;IACC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,KAAK,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QACtF,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACzF,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,KAAK;SACT,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BuilderConfig } from "../../config/schema.js";
|
|
2
|
+
import type { BuiltConfigArtifact } from "../build/index.js";
|
|
3
|
+
import { type VerificationReport } from "../verification/index.js";
|
|
4
|
+
export interface RunUpdateInput {
|
|
5
|
+
readonly config: BuilderConfig;
|
|
6
|
+
readonly outputPath?: string;
|
|
7
|
+
readonly livePath?: string;
|
|
8
|
+
readonly backupPath?: string;
|
|
9
|
+
readonly subscriptionFile?: string;
|
|
10
|
+
readonly subscriptionUrl?: string;
|
|
11
|
+
readonly singBoxBinary?: string;
|
|
12
|
+
readonly chromeBinary?: string;
|
|
13
|
+
readonly verify?: boolean;
|
|
14
|
+
readonly reload?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface UpdateResult {
|
|
17
|
+
readonly build: BuiltConfigArtifact;
|
|
18
|
+
readonly verification?: VerificationReport;
|
|
19
|
+
readonly livePath: string;
|
|
20
|
+
readonly backupPath?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function runUpdate(input: RunUpdateInput): Promise<UpdateResult>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { buildConfigArtifact } from "../build/index.js";
|
|
2
|
+
import { applyConfig } from "../manager/index.js";
|
|
3
|
+
import { assertVerificationReportPassed, verifyConfigRoutes, } from "../verification/index.js";
|
|
4
|
+
export async function runUpdate(input) {
|
|
5
|
+
const build = await buildConfigArtifact({
|
|
6
|
+
config: input.config,
|
|
7
|
+
...(input.outputPath ? { outputPath: input.outputPath } : {}),
|
|
8
|
+
...(input.subscriptionFile ? { subscriptionFile: input.subscriptionFile } : {}),
|
|
9
|
+
...(input.subscriptionUrl ? { subscriptionUrl: input.subscriptionUrl } : {}),
|
|
10
|
+
});
|
|
11
|
+
let verification;
|
|
12
|
+
if (input.verify !== false) {
|
|
13
|
+
verification = await verifyConfigRoutes({
|
|
14
|
+
configPath: build.outputPath,
|
|
15
|
+
...(input.singBoxBinary ? { singBoxBinary: input.singBoxBinary } : {}),
|
|
16
|
+
...(input.chromeBinary ? { chromeBinary: input.chromeBinary } : {}),
|
|
17
|
+
configuredScenarios: input.config.verification.scenarios,
|
|
18
|
+
});
|
|
19
|
+
assertVerificationReportPassed(verification);
|
|
20
|
+
}
|
|
21
|
+
const livePath = input.livePath ?? input.config.output.livePath;
|
|
22
|
+
const backupPath = input.backupPath ?? input.config.output.backupPath;
|
|
23
|
+
await applyConfig({
|
|
24
|
+
stagingPath: build.outputPath,
|
|
25
|
+
livePath,
|
|
26
|
+
...(backupPath ? { backupPath } : {}),
|
|
27
|
+
...(input.singBoxBinary ? { singBoxBinary: input.singBoxBinary } : {}),
|
|
28
|
+
reload: input.reload ?? false,
|
|
29
|
+
runtime: input.config.runtime.reload,
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
build,
|
|
33
|
+
...(verification ? { verification } : {}),
|
|
34
|
+
livePath,
|
|
35
|
+
...(backupPath ? { backupPath } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/update/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAsBlC,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAqB;IACnD,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC;QACtC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7E,CAAC,CAAC;IAEH,IAAI,YAA4C,CAAC;IACjD,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC3B,YAAY,GAAG,MAAM,kBAAkB,CAAC;YACtC,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAA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interface UserRouteRule {
|
|
2
|
+
readonly name?: string;
|
|
3
|
+
readonly inbound?: readonly string[];
|
|
4
|
+
readonly protocol?: string;
|
|
5
|
+
readonly network?: "tcp" | "udp";
|
|
6
|
+
readonly port?: number;
|
|
7
|
+
readonly domain?: readonly string[];
|
|
8
|
+
readonly domainSuffix?: readonly string[];
|
|
9
|
+
readonly ruleSet?: readonly string[];
|
|
10
|
+
readonly route?: string;
|
|
11
|
+
readonly action?: "reject";
|
|
12
|
+
}
|
|
13
|
+
export interface LoadedUserRules {
|
|
14
|
+
readonly beforeBuiltins: readonly UserRouteRule[];
|
|
15
|
+
readonly afterBuiltins: readonly UserRouteRule[];
|
|
16
|
+
readonly warnings: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function loadUserRules(filePath: string): Promise<LoadedUserRules>;
|