my-singbox 0.0.0-stage → 2.0.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.
@@ -0,0 +1,39 @@
1
+ export declare const ENV_KEYS: readonly ['SING_BOX_VERSION', 'VLESS_UUID', 'REALITY_PRIVATE_KEY', 'REALITY_PUBLIC_KEY', 'REALITY_SHORT_ID', 'SS_PASSWORD', 'SERVER_ADDRESS', 'ISP_SOCKS_ADDR', 'ISP_SOCKS_USER', 'ISP_SOCKS_PASS', 'ISP_SOCKS_EGRESS_IP'];
2
+ export type EnvKey = (typeof ENV_KEYS)[number];
3
+ export interface Env {
4
+ values: Partial<Record<EnvKey, string>>;
5
+ keys: Set<EnvKey>;
6
+ }
7
+ export declare class EnvError extends Error {
8
+ name: string;
9
+ }
10
+ export declare class FileExistsError extends Error {
11
+ name: string;
12
+ constructor();
13
+ }
14
+ export declare function envQuote(v: string): string;
15
+ export declare function envUnquote(raw: string): string | null;
16
+ export declare function parseEnv(text: string, label?: string): Env;
17
+ export declare function loadEnvFile(path: string): Env;
18
+ export declare const ENV_HEADER = "# ISP outbound (managed by scripts/isp-outbound.sh)";
19
+ export declare const ENV_HEADER_NOEOL: string;
20
+ export declare function envWithoutIsp(text: string): string;
21
+ export declare function envWithIsp(text: string, isp: {
22
+ addr: string;
23
+ user: string;
24
+ pass: string;
25
+ egressIp: string;
26
+ }): string;
27
+ export declare function renderGeneratedEnv(v: {
28
+ singBoxVersion: string;
29
+ vlessUuid: string;
30
+ realityPrivateKey: string;
31
+ realityPublicKey: string;
32
+ realityShortId: string;
33
+ ssPassword: string;
34
+ serverAddress: string;
35
+ }): string;
36
+ export declare function writeFileAtomic(path: string, data: string | Uint8Array, options?: {
37
+ exclusive?: boolean;
38
+ }): void;
39
+ export declare function writeEnvFile(path: string, text: string): void;
@@ -0,0 +1,33 @@
1
+ import type { IspSocks } from '../model.js';
2
+ export interface IspServiceIO {
3
+ projectDir: string;
4
+ env?: NodeJS.ProcessEnv;
5
+ sleep?(ms: number): Promise<void>;
6
+ stdout(text: string): void;
7
+ stderr(text: string): void;
8
+ signal?: AbortSignal;
9
+ }
10
+ export type DockerInfo = 'ok' | 'permission-denied' | 'down';
11
+ export type ListenerStatus = boolean | 'unknown';
12
+ /** External commands use this run's environment, including its PATH. */
13
+ export declare class IspService {
14
+ private readonly io;
15
+ constructor(io: IspServiceIO);
16
+ private warn;
17
+ private command;
18
+ private compose;
19
+ private pause;
20
+ dockerInfo(): Promise<DockerInfo>;
21
+ composeAvailable(): Promise<boolean>;
22
+ containerImage(): Promise<string>;
23
+ containerStatus(): Promise<string>;
24
+ recreate(): Promise<boolean>;
25
+ composeExecCheck(): Promise<boolean>;
26
+ showLogs(): Promise<void>;
27
+ checkCandidate(image: string, candidatePath: string): Promise<boolean>;
28
+ portListening(proto: 'tcp' | 'udp', port: number): Promise<ListenerStatus>;
29
+ waitListening(proto: 'tcp' | 'udp', port: number): Promise<boolean>;
30
+ portsFree(): Promise<void>;
31
+ verifyService(expectIsp: boolean): Promise<boolean>;
32
+ socksEgressIp(isp: IspSocks): Promise<string | undefined>;
33
+ }
@@ -0,0 +1,21 @@
1
+ import { type IspSocks } from '../model.js';
2
+ import type { SingboxConfig } from './render-config.js';
3
+ export declare const ISP_BACKUP_DIR = ".isp-backup", ISP_LOCK_FILE = ".isp.lock", ISP_TMP_PREFIX = ".isp-tmp.", GROUP_MAIN = "Proxy";
4
+ export declare const MANAGED_FILES: readonly ['config.json', 'clash.yaml', '.env'];
5
+ export declare class IspError extends Error {
6
+ name: string;
7
+ }
8
+ export declare function envGet(text: string, key: string): string | undefined;
9
+ export declare function envHasIsp(text: string): boolean;
10
+ export declare function checkIspConfig(config: unknown): asserts config is SingboxConfig;
11
+ export declare function configHasIsp(config: SingboxConfig): boolean;
12
+ export declare function addIspToConfig(config: SingboxConfig, isp: IspSocks): SingboxConfig;
13
+ export declare function clashHasIsp(text: string): boolean;
14
+ export declare function addIspToClash(text: string, realityPrivateKey?: string): string;
15
+ export declare function makeTmpPath(projectDir: string): string;
16
+ export declare function installFile(dest: string, data: string | Uint8Array, projectDir: string): void;
17
+ export declare function makeBackup(projectDir: string): string;
18
+ export declare function findCleanBackup(projectDir: string): string | undefined;
19
+ export declare function restoreBackup(projectDir: string, backupDir: string): void;
20
+ export declare function sweepStaleTmp(projectDir: string): void;
21
+ export declare function withLock<T>(projectDir: string, fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,20 @@
1
+ export interface KeyDeps {
2
+ runSingbox(args: string[]): Promise<string>;
3
+ randomUuid(): string;
4
+ randomShortId(): string;
5
+ }
6
+ export declare function generateKeys(deps: KeyDeps): Promise<{
7
+ vlessUuid: string;
8
+ realityPrivateKey: string;
9
+ realityPublicKey: string;
10
+ realityShortId: string;
11
+ ssPassword: string;
12
+ }>;
13
+ export type DockerRun = (file: string, args: string[]) => Promise<string>;
14
+ export declare function defaultKeyDeps(image: string): KeyDeps;
15
+ export declare function dockerAvailable(run?: DockerRun): Promise<boolean>;
16
+ export declare function dockerDaemonUp(run?: DockerRun): Promise<boolean>;
17
+ export interface PublicIpDeps {
18
+ httpGet(url: string, family: 4 | 6): Promise<string>;
19
+ }
20
+ export declare function detectPublicIp(deps?: PublicIpDeps): Promise<string | null>;
@@ -0,0 +1,2 @@
1
+ import type { Model } from '../model.js';
2
+ export declare function renderClash(model: Model, templateText: string): string;
@@ -0,0 +1,13 @@
1
+ import type { Model } from '../model.js';
2
+ export interface SingboxConfig {
3
+ inbounds: Record<string, unknown>[];
4
+ outbounds?: Record<string, unknown>[];
5
+ route?: {
6
+ rules?: unknown[];
7
+ [key: string]: unknown;
8
+ };
9
+ [key: string]: unknown;
10
+ }
11
+ export declare function renderSingbox(model: Model, template: unknown): SingboxConfig;
12
+ export declare function serializeSingbox(config: SingboxConfig): string;
13
+ export declare function loadSingboxTemplate(projectDir?: string): unknown;
@@ -0,0 +1,23 @@
1
+ export declare function parseListenPorts(configText: string): number[];
2
+ export declare function secretValues(envText: string): string[];
3
+ export declare function redact(text: string, secrets: string[]): string;
4
+ export declare function composeImageTag(text: string): string;
5
+ export declare function firewallPorts(configText: string): string[];
6
+ export interface StartDeps {
7
+ run(file: string, args: string[]): Promise<{
8
+ code: number;
9
+ stdout: string;
10
+ stderr: string;
11
+ }>;
12
+ tcpOpen(port: number): Promise<boolean>;
13
+ sleep(ms: number): Promise<void>;
14
+ }
15
+ export declare function realStartDeps(): StartDeps;
16
+ export declare function startNode(opts: {
17
+ project: string;
18
+ deps: StartDeps;
19
+ dockerAvailable(): Promise<boolean>;
20
+ dockerDaemonUp(): Promise<boolean>;
21
+ stdout(t: string): void;
22
+ stderr(t: string): void;
23
+ }): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export declare function findTemplate(name: string, projectDir?: string): string;
2
+ export declare function findPackageFile(name: string): string;
3
+ export declare function readTemplate(name: string, projectDir?: string): string;
@@ -0,0 +1,17 @@
1
+ export declare const UUID_RE: RegExp;
2
+ export declare const PRIVATE_KEY_RE: RegExp;
3
+ export declare const PUBLIC_KEY_RE: RegExp;
4
+ export declare const SHORT_ID_RE: RegExp;
5
+ export declare const SS_PASSWORD_RE: RegExp;
6
+ export declare function isIpv4(s: string): boolean;
7
+ export declare function isIpv6(s: string): boolean;
8
+ export declare function isIpv6Strict(s: string): boolean;
9
+ export declare function isHostname(s: string): boolean;
10
+ export declare function isValidServerAddress(s: string): boolean;
11
+ export declare function isPublicIp(s: string): boolean;
12
+ export declare function parseIspAddr(value: string): {
13
+ host: string;
14
+ port: number;
15
+ addr: string;
16
+ } | null;
17
+ export declare function validCred(value: string): boolean;
@@ -0,0 +1,14 @@
1
+ import type { System } from './system.js';
2
+ export type Status = 'OK' | 'WARN' | 'FAIL';
3
+ export interface Check {
4
+ name: string;
5
+ status: Status;
6
+ message: string;
7
+ }
8
+ export declare function checkNode(s: System): Check;
9
+ export declare function checkPlatform(s: System): Check;
10
+ export declare function checkArch(s: System): Check;
11
+ export declare function checkCompose(s: System): Promise<Check>;
12
+ export declare function checkSocket(s: System): Check;
13
+ export declare function dockerAccessGuidance(s: System): Promise<string>;
14
+ export declare function runDoctor(s: System, write: (text: string) => void): Promise<number>;
@@ -0,0 +1,10 @@
1
+ export interface System {
2
+ nodeVersion: string;
3
+ platform: string;
4
+ arch: string;
5
+ glibcVersionRuntime?: string;
6
+ exec(file: string, args: string[]): Promise<string>;
7
+ socketAccessible(): boolean;
8
+ username(): string;
9
+ }
10
+ export declare function realSystem(): System;
@@ -0,0 +1,12 @@
1
+ export * from './doctor/checks.js';
2
+ export { type System } from './doctor/system.js';
3
+ export * from './core/validate.js';
4
+ export * from './core/env.js';
5
+ export * from './core/keys.js';
6
+ export * from './model.js';
7
+ export * from './core/templates.js';
8
+ export * from './core/render-config.js';
9
+ export * from './core/render-clash.js';
10
+ export * from './core/isp-service.js';
11
+ export * from './core/isp.js';
12
+ export * from './core/start.js';