@secret-momo/utils 1.7.0 → 1.8.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/lib/index.d.ts +2 -0
- package/lib/index.js +1 -1
- package/lib/mihomo/cache.d.ts +9 -0
- package/lib/mihomo/cache.js +1 -0
- package/lib/mihomo/client.d.ts +25 -0
- package/lib/mihomo/client.js +1 -0
- package/lib/mihomo/configs.d.ts +28 -0
- package/lib/mihomo/configs.js +1 -0
- package/lib/mihomo/connections.d.ts +13 -0
- package/lib/mihomo/connections.js +1 -0
- package/lib/mihomo/debug.d.ts +9 -0
- package/lib/mihomo/debug.js +1 -0
- package/lib/mihomo/dns.d.ts +7 -0
- package/lib/mihomo/dns.js +1 -0
- package/lib/mihomo/groups.d.ts +11 -0
- package/lib/mihomo/groups.js +1 -0
- package/lib/mihomo/index.d.ts +39 -0
- package/lib/mihomo/index.js +1 -0
- package/lib/mihomo/logs.d.ts +13 -0
- package/lib/mihomo/logs.js +1 -0
- package/lib/mihomo/memory.d.ts +7 -0
- package/lib/mihomo/memory.js +1 -0
- package/lib/mihomo/proxies.d.ts +20 -0
- package/lib/mihomo/proxies.js +1 -0
- package/lib/mihomo/proxy-providers.d.ts +19 -0
- package/lib/mihomo/proxy-providers.js +1 -0
- package/lib/mihomo/rule-providers.d.ts +9 -0
- package/lib/mihomo/rule-providers.js +1 -0
- package/lib/mihomo/rules.d.ts +9 -0
- package/lib/mihomo/rules.js +1 -0
- package/lib/mihomo/storage.d.ts +11 -0
- package/lib/mihomo/storage.js +1 -0
- package/lib/mihomo/traffic.d.ts +7 -0
- package/lib/mihomo/traffic.js +1 -0
- package/lib/mihomo/types.d.ts +143 -0
- package/lib/mihomo/upgrade.d.ts +14 -0
- package/lib/mihomo/upgrade.js +1 -0
- package/lib/mihomo/version.d.ts +7 -0
- package/lib/mihomo/version.js +1 -0
- package/lib/public-ip.d.ts +4 -0
- package/lib/public-ip.js +1 -0
- package/package.json +15 -9
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{downloadImage as r,downloadVideo as t}from"./download/index.js";import{dateTimeToNow as f,dateToNow as
|
|
1
|
+
import{downloadImage as r,downloadVideo as t}from"./download/index.js";import{dateTimeToNow as f,dateToNow as p,timestampToDate as a,yesterdayDate as d}from"./date-time.js";import{findRepoRoot as x,getNodeName as l}from"./env.js";import{fetch as g,fetchHtml as s,fetchJson as c,fetchText as h,mobileUserAgent as u,userAgent as w}from"./fetch.js";import{fileSize as N}from"./file.js";import{fixed2 as D,fixed4 as I,toPercentage as M}from"./num.js";import{logger as R}from"./pino.js";import{getPublicIp as v}from"./public-ip.js";import{sleep as H,sleep_random as U}from"./sleep.js";import{genId as z,uuidv4 as C}from"./uuid.js";import{getRedirectUrl as J,removeQueryParams as Q}from"./url.js";import{createMihomo as _}from"./mihomo/index.js";import{MihomoClient as k,MihomoHttpError as q}from"./mihomo/client.js";import{aria2DownloadVideo as F}from"./download/aria2.js";import{default as K}from"pino";export{k as MihomoClient,q as MihomoHttpError,F as aria2DownloadVideo,_ as createMihomo,f as dateTimeToNow,p as dateToNow,r as downloadImage,t as downloadVideo,g as fetch,s as fetchHtml,c as fetchJson,h as fetchText,N as fileSize,x as findRepoRoot,D as fixed2,I as fixed4,z as genId,l as getNodeName,v as getPublicIp,J as getRedirectUrl,R as logger,u as mobileUserAgent,K as pino,Q as removeQueryParams,H as sleep,U as sleep_random,a as timestampToDate,M as toPercentage,w as userAgent,C as uuidv4,d as yesterdayDate};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoCacheModule {
|
|
4
|
+
/** POST `/cache/fakeip/flush`:清除 fake-ip 缓存,成功时返回 HTTP 204。 */
|
|
5
|
+
flushFakeIp(options?: MihomoRequestOptions): Promise<void>;
|
|
6
|
+
/** POST `/cache/dns/flush`:清除 DNS 缓存,成功时返回 HTTP 204。 */
|
|
7
|
+
flushDns(options?: MihomoRequestOptions): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createCache(client: MihomoClient): MihomoCacheModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function h(c){return{flushFakeIp:e=>c.empty("POST","/cache/fakeip/flush",e),flushDns:e=>c.empty("POST","/cache/dns/flush",e)}}export{h as createCache};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MihomoOptions, MihomoRequestOptions } from './types';
|
|
2
|
+
export declare class MihomoHttpError extends Error {
|
|
3
|
+
readonly response: Response;
|
|
4
|
+
readonly body: string;
|
|
5
|
+
constructor(response: Response, body: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class MihomoClient {
|
|
8
|
+
private readonly baseUrl;
|
|
9
|
+
private readonly secret?;
|
|
10
|
+
constructor(options: MihomoOptions);
|
|
11
|
+
url(path: string, query?: Record<string, string | number | boolean | undefined>): string;
|
|
12
|
+
response(method: string, path: string, options?: MihomoRequestOptions & {
|
|
13
|
+
body?: unknown;
|
|
14
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
15
|
+
}): Promise<Response>;
|
|
16
|
+
json<T>(method: string, path: string, options?: MihomoRequestOptions & {
|
|
17
|
+
body?: unknown;
|
|
18
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
19
|
+
}): Promise<T>;
|
|
20
|
+
empty(method: string, path: string, options?: MihomoRequestOptions & {
|
|
21
|
+
body?: unknown;
|
|
22
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function encodePathSegment(value: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class a extends Error{constructor(t,s){super(`Mihomo request failed: ${t.status} ${t.statusText}`),this.response=t,this.body=s,this.name="MihomoHttpError"}response;body}class h{baseUrl;secret;constructor(t){const s=new URL(t.baseUrl?.toString()??"http://127.0.0.1:9090");s.search="",s.hash="";const e=s.toString().replace(/\/+$/,"");this.baseUrl=e,this.secret=t.secret}url(t,s){const e=new URL(`${this.baseUrl}${t}`);for(const[r,o]of Object.entries(s??{}))o!==void 0&&e.searchParams.set(r,String(o));return e.toString()}async response(t,s,e={}){const r=new Headers(e.headers);this.secret&&!r.has("Authorization")&&r.set("Authorization",`Bearer ${this.secret}`);let o;e.body!==void 0&&(o=JSON.stringify(e.body),r.has("Content-Type")||r.set("Content-Type","application/json"));const n=await globalThis.fetch(this.url(s,e.query),{method:t,headers:r,body:o,signal:e.signal??void 0});if(!n.ok)throw new a(n,await n.text());return n}async json(t,s,e){return(await this.response(t,s,e)).json()}async empty(t,s,e){await this.response(t,s,e)}}function c(i){return encodeURIComponent(i)}export{h as MihomoClient,a as MihomoHttpError,c as encodePathSegment};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoMode, MihomoPathPayload, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoConfig {
|
|
4
|
+
port?: number;
|
|
5
|
+
'socks-port'?: number;
|
|
6
|
+
'mixed-port'?: number;
|
|
7
|
+
mode?: MihomoMode;
|
|
8
|
+
'log-level'?: string;
|
|
9
|
+
'allow-lan'?: boolean;
|
|
10
|
+
ipv6?: boolean;
|
|
11
|
+
tun?: Record<string, unknown> | boolean;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface MihomoConfigsModule {
|
|
15
|
+
/** GET `/configs`:获取当前运行配置,例如端口、模式、日志级别、IPv6 与 TUN 配置。 */
|
|
16
|
+
get(options?: MihomoRequestOptions): Promise<MihomoConfig>;
|
|
17
|
+
/** PUT `/configs`:重新加载基本配置;`force: true` 会附加 `?force=true`。 */
|
|
18
|
+
reload(payload?: MihomoPathPayload, options?: MihomoRequestOptions & {
|
|
19
|
+
force?: boolean;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
/** PATCH `/configs`:更新基本配置,例如 `{ 'mixed-port': 7890 }`,成功时返回 HTTP 204。 */
|
|
22
|
+
patch(config: Partial<MihomoConfig>, options?: MihomoRequestOptions): Promise<void>;
|
|
23
|
+
/** POST `/configs/geo`:使用 `path` 或 `payload` 更新 GEO 数据库,成功时返回 HTTP 204。 */
|
|
24
|
+
updateGeo(payload?: MihomoPathPayload, options?: MihomoRequestOptions): Promise<void>;
|
|
25
|
+
/** POST `/restart`:重启 mihomo 内核,可选地提供新的配置 `path` 或 `payload`。 */
|
|
26
|
+
restart(payload?: MihomoPathPayload, options?: MihomoRequestOptions): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare function createConfigs(client: MihomoClient): MihomoConfigsModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(t){return{get:e=>t.json("GET","/configs",e),reload:(e,o={})=>t.empty("PUT","/configs",{...o,body:e,query:{force:o.force}}),patch:(e,o)=>t.empty("PATCH","/configs",{...o,body:e}),updateGeo:(e,o)=>t.empty("POST","/configs/geo",{...o,body:e}),restart:(e,o)=>t.empty("POST","/restart",{...o,body:e})}}export{r as createConfigs};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type MihomoClient } from './client';
|
|
2
|
+
import type { MihomoConnections, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoConnectionsModule {
|
|
4
|
+
/** GET `/connections`:获取累计流量、内存使用量及活跃连接;可用 `interval` 指定 WS 刷新间隔。 */
|
|
5
|
+
list(options?: MihomoRequestOptions & {
|
|
6
|
+
interval?: number;
|
|
7
|
+
}): Promise<MihomoConnections>;
|
|
8
|
+
/** DELETE `/connections`:关闭所有活跃连接,成功时返回 HTTP 204。 */
|
|
9
|
+
closeAll(options?: MihomoRequestOptions): Promise<void>;
|
|
10
|
+
/** DELETE `/connections/:id`:关闭指定 ID 的连接,成功时返回 HTTP 204。 */
|
|
11
|
+
close(id: string, options?: MihomoRequestOptions): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createConnections(client: MihomoClient): MihomoConnectionsModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodePathSegment as o}from"./client.js";function c(e){return{list:(n={})=>e.json("GET","/connections",{...n,query:{interval:n.interval}}),closeAll:n=>e.empty("DELETE","/connections",n),close:(n,t)=>e.empty("DELETE",`/connections/${o(n)}`,t)}}export{c as createConnections};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoDebugModule {
|
|
4
|
+
/** PUT `/debug/gc`:主动触发 Go GC;仅在内核日志级别为 `debug` 时可用。 */
|
|
5
|
+
gc(options?: MihomoRequestOptions): Promise<void>;
|
|
6
|
+
/** 返回 `/debug/pprof` 的完整 URL,可在浏览器中打开查看原始 pprof 调试信息。 */
|
|
7
|
+
pprofUrl(): string;
|
|
8
|
+
}
|
|
9
|
+
export declare function createDebug(client: MihomoClient): MihomoDebugModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function p(e){return{gc:r=>e.empty("PUT","/debug/gc",r),pprofUrl:()=>e.url("/debug/pprof")}}export{p as createDebug};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoDnsResponse, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoDnsModule {
|
|
4
|
+
/** GET `/dns/query`:查询指定域名和记录类型,返回 DNS Rcode、问题及解析记录。 */
|
|
5
|
+
query(name: string, type: string, options?: MihomoRequestOptions): Promise<MihomoDnsResponse>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createDns(client: MihomoClient): MihomoDnsModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function u(e){return{query:(n,r,t)=>e.json("GET","/dns/query",{...t,query:{name:n,type:r}})}}export{u as createDns};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type MihomoClient } from './client';
|
|
2
|
+
import type { MihomoDelayOptions, MihomoProxy, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoGroupsModule {
|
|
4
|
+
/** GET `/group`:获取全部策略组,返回的每项字段与单个代理信息相同。 */
|
|
5
|
+
list(options?: MihomoRequestOptions): Promise<MihomoProxy[]>;
|
|
6
|
+
/** GET `/group/:name`:获取指定策略组的信息。 */
|
|
7
|
+
get(name: string, options?: MihomoRequestOptions): Promise<MihomoProxy>;
|
|
8
|
+
/** GET `/group/:name/delay`:测试组内节点/策略组延迟,并清除自动策略组的 fixed 选择。 */
|
|
9
|
+
delay(name: string, options: MihomoDelayOptions): Promise<Record<string, number>>;
|
|
10
|
+
}
|
|
11
|
+
export declare function createGroups(client: MihomoClient): MihomoGroupsModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodePathSegment as o}from"./client.js";function u(r){return{list:async t=>(await r.json("GET","/group",t)).proxies,get:(t,e)=>r.json("GET",`/group/${o(t)}`,e),delay:(t,e)=>r.json("GET",`/group/${o(t)}/delay`,{...e,query:{url:e.url,timeout:e.timeout,expected:e.expected}})}}export{u as createGroups};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type MihomoCacheModule } from './cache';
|
|
2
|
+
import { type MihomoConfigsModule } from './configs';
|
|
3
|
+
import { type MihomoConnectionsModule } from './connections';
|
|
4
|
+
import { type MihomoDebugModule } from './debug';
|
|
5
|
+
import { type MihomoDnsModule } from './dns';
|
|
6
|
+
import { type MihomoGroupsModule } from './groups';
|
|
7
|
+
import { type MihomoLogsModule } from './logs';
|
|
8
|
+
import { type MihomoMemoryModule } from './memory';
|
|
9
|
+
import { type MihomoProxiesModule } from './proxies';
|
|
10
|
+
import { type MihomoProxyProvidersModule } from './proxy-providers';
|
|
11
|
+
import { type MihomoRuleProvidersModule } from './rule-providers';
|
|
12
|
+
import { type MihomoRulesModule } from './rules';
|
|
13
|
+
import { type MihomoStorageModule } from './storage';
|
|
14
|
+
import { type MihomoTrafficModule } from './traffic';
|
|
15
|
+
import type { MihomoOptions } from './types';
|
|
16
|
+
import { type MihomoUpgradeModule } from './upgrade';
|
|
17
|
+
import { type MihomoVersionModule } from './version';
|
|
18
|
+
export interface Mihomo {
|
|
19
|
+
cache: MihomoCacheModule;
|
|
20
|
+
configs: MihomoConfigsModule;
|
|
21
|
+
connections: MihomoConnectionsModule;
|
|
22
|
+
debug: MihomoDebugModule;
|
|
23
|
+
dns: MihomoDnsModule;
|
|
24
|
+
groups: MihomoGroupsModule;
|
|
25
|
+
logs: MihomoLogsModule;
|
|
26
|
+
memory: MihomoMemoryModule;
|
|
27
|
+
proxies: MihomoProxiesModule;
|
|
28
|
+
proxyProviders: MihomoProxyProvidersModule;
|
|
29
|
+
ruleProviders: MihomoRuleProvidersModule;
|
|
30
|
+
rules: MihomoRulesModule;
|
|
31
|
+
storage: MihomoStorageModule;
|
|
32
|
+
traffic: MihomoTrafficModule;
|
|
33
|
+
upgrade: MihomoUpgradeModule;
|
|
34
|
+
version: MihomoVersionModule;
|
|
35
|
+
}
|
|
36
|
+
/** Creates a typed client for mihomo's external-controller HTTP API. */
|
|
37
|
+
export declare function createMihomo(options: MihomoOptions): Mihomo;
|
|
38
|
+
export { MihomoClient, MihomoHttpError } from './client';
|
|
39
|
+
export type * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MihomoClient as o}from"./client.js";import{MihomoHttpError as A}from"./client.js";import{createCache as t}from"./cache.js";import{createConfigs as m}from"./configs.js";import{createConnections as i}from"./connections.js";import{createDebug as c}from"./debug.js";import{createDns as p}from"./dns.js";import{createGroups as a}from"./groups.js";import{createLogs as f}from"./logs.js";import{createMemory as s}from"./memory.js";import{createProxies as n}from"./proxies.js";import{createProxyProviders as g}from"./proxy-providers.js";import{createRuleProviders as u}from"./rule-providers.js";import{createRules as d}from"./rules.js";import{createStorage as l}from"./storage.js";import{createTraffic as x}from"./traffic.js";import{createUpgrade as P}from"./upgrade.js";import{createVersion as h}from"./version.js";function v(e){const r=new o(e);return{cache:t(r),configs:m(r),connections:i(r),debug:c(r),dns:p(r),groups:a(r),logs:f(r),memory:s(r),proxies:n(r),proxyProviders:g(r),ruleProviders:u(r),rules:d(r),storage:l(r),traffic:x(r),upgrade:P(r),version:h(r)}}export{o as MihomoClient,A as MihomoHttpError,v as createMihomo};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoLogLevel, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoLogsModule {
|
|
4
|
+
/**
|
|
5
|
+
* GET `/logs`:获取实时日志 HTTP 流;逐行读取 `response.body`。
|
|
6
|
+
* `level` 可为 info、warning、error 或 debug;`structured` 会返回包含 time、level、message、fields 的结构化日志。
|
|
7
|
+
*/
|
|
8
|
+
stream(options?: MihomoRequestOptions & {
|
|
9
|
+
level?: MihomoLogLevel;
|
|
10
|
+
structured?: boolean;
|
|
11
|
+
}): Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createLogs(client: MihomoClient): MihomoLogsModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(r){return{stream:(e={})=>r.response("GET","/logs",{...e,query:{level:e.level,format:e.structured?"structured":void 0}})}}export{t as createLogs};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoMemoryModule {
|
|
4
|
+
/** GET `/memory`:获取实时内存占用 HTTP 流,数据包含 `inuse` 和固定为 0 的 `oslimit`(单位:字节)。 */
|
|
5
|
+
stream(options?: MihomoRequestOptions): Promise<Response>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createMemory(client: MihomoClient): MihomoMemoryModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(e){return{stream:r=>e.response("GET","/memory",r)}}export{o as createMemory};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type MihomoClient } from './client';
|
|
2
|
+
import type { MihomoDelayOptions, MihomoProxy, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoProxiesModule {
|
|
4
|
+
/** GET `/proxies`:获取所有代理及策略组;以名称为键,包含类型、可用性与延迟历史等信息。 */
|
|
5
|
+
list(options?: MihomoRequestOptions): Promise<Record<string, MihomoProxy>>;
|
|
6
|
+
/** GET `/proxies/:name`:获取指定代理或策略组的详细信息。 */
|
|
7
|
+
get(name: string, options?: MihomoRequestOptions): Promise<MihomoProxy>;
|
|
8
|
+
/**
|
|
9
|
+
* PUT `/proxies/:groupName`:为策略组选择指定代理,发送体为 `{ name: proxyName }`,成功时返回 HTTP 204。
|
|
10
|
+
* `groupName` 是策略组名,`proxyName` 是该策略组要选中的节点名。
|
|
11
|
+
*/
|
|
12
|
+
select(groupName: string, proxyName: string, options?: MihomoRequestOptions): Promise<void>;
|
|
13
|
+
/** DELETE `/proxies/:name`:清除非 Selector 策略组的 fixed 固定选择,成功时返回 HTTP 204。 */
|
|
14
|
+
clearFixed(name: string, options?: MihomoRequestOptions): Promise<void>;
|
|
15
|
+
/** GET `/proxies/:name/delay`:测试指定代理并返回最新延迟(毫秒);`expected` 支持如 `200-299` 的状态码范围。 */
|
|
16
|
+
delay(name: string, options: MihomoDelayOptions): Promise<{
|
|
17
|
+
delay: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare function createProxies(client: MihomoClient): MihomoProxiesModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodePathSegment as o}from"./client.js";function p(r){return{list:async t=>(await r.json("GET","/proxies",t)).proxies,get:(t,e)=>r.json("GET",`/proxies/${o(t)}`,e),select:(t,e,s)=>r.empty("PUT",`/proxies/${o(t)}`,{...s,body:{name:e}}),clearFixed:(t,e)=>r.empty("DELETE",`/proxies/${o(t)}`,e),delay:(t,e)=>r.json("GET",`/proxies/${o(t)}/delay`,{...e,query:{url:e.url,timeout:e.timeout,expected:e.expected}})}}export{p as createProxies};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type MihomoClient } from './client';
|
|
2
|
+
import type { MihomoDelayOptions, MihomoProxy, MihomoProxyProvider, MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoProxyProvidersModule {
|
|
4
|
+
/** GET `/providers/proxies`:获取全部代理集合及其元信息和代理列表。 */
|
|
5
|
+
list(options?: MihomoRequestOptions): Promise<Record<string, MihomoProxyProvider>>;
|
|
6
|
+
/** GET `/providers/proxies/:name`:获取特定代理集合的信息及其代理列表。 */
|
|
7
|
+
get(name: string, options?: MihomoRequestOptions): Promise<MihomoProxyProvider>;
|
|
8
|
+
/** PUT `/providers/proxies/:name`:更新指定代理集合,成功时返回 HTTP 204。 */
|
|
9
|
+
update(name: string, options?: MihomoRequestOptions): Promise<void>;
|
|
10
|
+
/** GET `/providers/proxies/:name/healthcheck`:触发指定代理集合的健康检查。 */
|
|
11
|
+
healthcheck(name: string, options?: MihomoRequestOptions): Promise<void>;
|
|
12
|
+
/** GET `/providers/proxies/:provider/:name`:获取代理集合中指定代理的信息。 */
|
|
13
|
+
getProxy(provider: string, name: string, options?: MihomoRequestOptions): Promise<MihomoProxy>;
|
|
14
|
+
/** GET `/providers/proxies/:provider/:name/healthcheck`:测试集合内指定代理,并返回新的延迟信息。 */
|
|
15
|
+
healthcheckProxy(provider: string, name: string, options: Omit<MihomoDelayOptions, 'expected'>): Promise<{
|
|
16
|
+
delay: number;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createProxyProviders(client: MihomoClient): MihomoProxyProvidersModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodePathSegment as h}from"./client.js";function i(t){const r=e=>`/providers/proxies/${h(e)}`;return{list:async e=>(await t.json("GET","/providers/proxies",e)).providers,get:(e,o)=>t.json("GET",r(e),o),update:(e,o)=>t.empty("PUT",r(e),o),healthcheck:(e,o)=>t.empty("GET",`${r(e)}/healthcheck`,o),getProxy:(e,o,c)=>t.json("GET",`${r(e)}/${h(o)}`,c),healthcheckProxy:(e,o,c)=>t.json("GET",`${r(e)}/${h(o)}/healthcheck`,{...c,query:{url:c.url,timeout:c.timeout}})}}export{i as createProxyProviders};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions, MihomoRuleProvider } from './types';
|
|
3
|
+
export interface MihomoRuleProvidersModule {
|
|
4
|
+
/** GET `/providers/rules`:获取全部规则集合,并以集合名称为键返回。 */
|
|
5
|
+
list(options?: MihomoRequestOptions): Promise<Record<string, MihomoRuleProvider>>;
|
|
6
|
+
/** PUT `/providers/rules/:name`:更新指定规则集合,成功时返回 HTTP 204。 */
|
|
7
|
+
update(name: string, options?: MihomoRequestOptions): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createRuleProviders(client: MihomoClient): MihomoRuleProvidersModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodePathSegment as o}from"./client.js";function s(r){return{list:async e=>(await r.json("GET","/providers/rules",e)).providers,update:(e,t)=>r.empty("PUT",`/providers/rules/${o(e)}`,t)}}export{s as createRuleProviders};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions, MihomoRule } from './types';
|
|
3
|
+
export interface MihomoRulesModule {
|
|
4
|
+
/** GET `/rules`:获取规则数组,包括索引、类型、匹配内容、目标代理和命中统计。 */
|
|
5
|
+
list(options?: MihomoRequestOptions): Promise<MihomoRule[]>;
|
|
6
|
+
/** PATCH `/rules/disable`:按规则索引临时启用或禁用规则;内核重启后该设置会失效。 */
|
|
7
|
+
setDisabled(values: Record<number, boolean>, options?: MihomoRequestOptions): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createRules(client: MihomoClient): MihomoRulesModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function l(s){return{list:async e=>(await s.json("GET","/rules",e)).rules,setDisabled:(e,t)=>s.empty("PATCH","/rules/disable",{...t,body:e})}}export{l as createRules};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoStorageModule {
|
|
4
|
+
/** GET `/storage/:key`:读取指定 key 的 JSON 值;不存在时返回 `null`。 */
|
|
5
|
+
get<T = unknown>(key: string, options?: MihomoRequestOptions): Promise<T | null>;
|
|
6
|
+
/** PUT `/storage/:key`:写入合法 JSON 值(最大 1 MB),成功时返回 HTTP 204。 */
|
|
7
|
+
set(key: string, value: unknown, options?: MihomoRequestOptions): Promise<void>;
|
|
8
|
+
/** DELETE `/storage/:key`:删除指定 key 的存储值,成功时返回 HTTP 204。 */
|
|
9
|
+
delete(key: string, options?: MihomoRequestOptions): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function createStorage(client: MihomoClient): MihomoStorageModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodePathSegment as m}from"./client.js";function a(o){const r=e=>`/storage/${m(e)}`;return{get:(e,t)=>o.json("GET",r(e),t),set:(e,t,n)=>o.empty("PUT",r(e),{...n,body:t}),delete:(e,t)=>o.empty("DELETE",r(e),t)}}export{a as createStorage};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions } from './types';
|
|
3
|
+
export interface MihomoTrafficModule {
|
|
4
|
+
/** GET `/traffic`:获取实时流量 HTTP 流;数据含每秒 up/down 及累计 upTotal/downTotal(单位:字节)。 */
|
|
5
|
+
stream(options?: MihomoRequestOptions): Promise<Response>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createTraffic(client: MihomoClient): MihomoTrafficModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(r){return{stream:e=>r.response("GET","/traffic",e)}}export{t as createTraffic};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/** Options accepted by every mihomo API method. */
|
|
2
|
+
export interface MihomoRequestOptions {
|
|
3
|
+
signal?: AbortSignal | null;
|
|
4
|
+
headers?: RequestInit['headers'];
|
|
5
|
+
}
|
|
6
|
+
export interface MihomoOptions {
|
|
7
|
+
/** External controller address. Defaults to `http://127.0.0.1:9090`. */
|
|
8
|
+
baseUrl?: string | URL;
|
|
9
|
+
/** The `secret` configured for mihomo's external controller. */
|
|
10
|
+
secret?: string;
|
|
11
|
+
}
|
|
12
|
+
export type MihomoMode = 'rule' | 'global' | 'direct' | string;
|
|
13
|
+
export type MihomoLogLevel = 'info' | 'warning' | 'error' | 'debug';
|
|
14
|
+
export interface MihomoVersion {
|
|
15
|
+
meta: boolean;
|
|
16
|
+
version: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MihomoDelayHistory {
|
|
19
|
+
time: string;
|
|
20
|
+
delay: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MihomoProxy {
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
udp?: boolean;
|
|
26
|
+
uot?: boolean;
|
|
27
|
+
xudp?: boolean;
|
|
28
|
+
tfo?: boolean;
|
|
29
|
+
mptcp?: boolean;
|
|
30
|
+
smux?: boolean;
|
|
31
|
+
alive?: boolean;
|
|
32
|
+
history?: MihomoDelayHistory[];
|
|
33
|
+
extra?: Record<string, MihomoDelayHistory[]>;
|
|
34
|
+
interface?: string;
|
|
35
|
+
'routing-mark'?: number;
|
|
36
|
+
'provider-name'?: string;
|
|
37
|
+
'dialer-proxy'?: string;
|
|
38
|
+
now?: string;
|
|
39
|
+
all?: string[];
|
|
40
|
+
testUrl?: string;
|
|
41
|
+
hidden?: boolean;
|
|
42
|
+
icon?: string;
|
|
43
|
+
emptyFallback?: string;
|
|
44
|
+
expectedStatus?: string;
|
|
45
|
+
fixed?: string;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
export interface MihomoProxyProvider {
|
|
49
|
+
name?: string;
|
|
50
|
+
type?: string;
|
|
51
|
+
vehicleType?: string;
|
|
52
|
+
updatedAt?: string;
|
|
53
|
+
subscriptionInfo?: Record<string, unknown>;
|
|
54
|
+
proxies: MihomoProxy[];
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface MihomoRuleExtra {
|
|
58
|
+
disabled: boolean;
|
|
59
|
+
hitCount: number;
|
|
60
|
+
hitAt: string;
|
|
61
|
+
missCount: number;
|
|
62
|
+
missAt: string;
|
|
63
|
+
}
|
|
64
|
+
export interface MihomoRule {
|
|
65
|
+
index: number;
|
|
66
|
+
type: string;
|
|
67
|
+
payload: string;
|
|
68
|
+
proxy: string;
|
|
69
|
+
size: number;
|
|
70
|
+
extra?: MihomoRuleExtra;
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
export interface MihomoRuleProvider {
|
|
74
|
+
name?: string;
|
|
75
|
+
type?: string;
|
|
76
|
+
updatedAt?: string;
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
}
|
|
79
|
+
export interface MihomoConnectionMetadata {
|
|
80
|
+
network?: string;
|
|
81
|
+
type?: string;
|
|
82
|
+
sourceIP?: string;
|
|
83
|
+
sourcePort?: string;
|
|
84
|
+
destinationIP?: string;
|
|
85
|
+
destinationPort?: string;
|
|
86
|
+
host?: string;
|
|
87
|
+
dnsMode?: string;
|
|
88
|
+
process?: string;
|
|
89
|
+
processPath?: string;
|
|
90
|
+
specialProxy?: string;
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
}
|
|
93
|
+
export interface MihomoConnection {
|
|
94
|
+
id: string;
|
|
95
|
+
metadata: MihomoConnectionMetadata;
|
|
96
|
+
upload: number;
|
|
97
|
+
download: number;
|
|
98
|
+
start: string;
|
|
99
|
+
chains: string[];
|
|
100
|
+
providerChains: string[];
|
|
101
|
+
rule: string;
|
|
102
|
+
rulePayload: string;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
}
|
|
105
|
+
export interface MihomoConnections {
|
|
106
|
+
downloadTotal: number;
|
|
107
|
+
uploadTotal: number;
|
|
108
|
+
memory: number;
|
|
109
|
+
connections: MihomoConnection[];
|
|
110
|
+
}
|
|
111
|
+
export interface MihomoDnsRecord {
|
|
112
|
+
name: string;
|
|
113
|
+
type: number;
|
|
114
|
+
TTL: number;
|
|
115
|
+
data: string;
|
|
116
|
+
}
|
|
117
|
+
export interface MihomoDnsResponse {
|
|
118
|
+
Status: number;
|
|
119
|
+
Question: Array<{
|
|
120
|
+
name: string;
|
|
121
|
+
qtype: number;
|
|
122
|
+
}>;
|
|
123
|
+
TC: boolean;
|
|
124
|
+
RD: boolean;
|
|
125
|
+
RA: boolean;
|
|
126
|
+
AD: boolean;
|
|
127
|
+
CD: boolean;
|
|
128
|
+
Answer?: MihomoDnsRecord[];
|
|
129
|
+
Authority?: MihomoDnsRecord[];
|
|
130
|
+
Additional?: MihomoDnsRecord[];
|
|
131
|
+
}
|
|
132
|
+
export interface MihomoUpgradeResult {
|
|
133
|
+
status: 'ok';
|
|
134
|
+
}
|
|
135
|
+
export interface MihomoPathPayload {
|
|
136
|
+
path?: string;
|
|
137
|
+
payload?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface MihomoDelayOptions extends MihomoRequestOptions {
|
|
140
|
+
url: string;
|
|
141
|
+
timeout: number;
|
|
142
|
+
expected?: string;
|
|
143
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoPathPayload, MihomoRequestOptions, MihomoUpgradeResult } from './types';
|
|
3
|
+
export interface MihomoUpgradeModule {
|
|
4
|
+
/** POST `/upgrade`:更新 mihomo 内核;可用 `channel` 指定通道、`force` 强制更新,成功返回 `{ status: 'ok' }`。 */
|
|
5
|
+
core(payload?: MihomoPathPayload, options?: MihomoRequestOptions & {
|
|
6
|
+
channel?: string;
|
|
7
|
+
force?: boolean;
|
|
8
|
+
}): Promise<MihomoUpgradeResult>;
|
|
9
|
+
/** POST `/upgrade/ui`:更新 external-ui 面板;须已设置 `external-ui`,成功返回 `{ status: 'ok' }`。 */
|
|
10
|
+
ui(options?: MihomoRequestOptions): Promise<MihomoUpgradeResult>;
|
|
11
|
+
/** POST `/upgrade/geo`:使用 `path` 或 `payload` 更新 GEO 数据库,成功时返回 HTTP 204。 */
|
|
12
|
+
geo(payload?: MihomoPathPayload, options?: MihomoRequestOptions): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createUpgrade(client: MihomoClient): MihomoUpgradeModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(o){return{core:(e,r={})=>o.json("POST","/upgrade",{...r,body:e,query:{channel:r.channel,force:r.force}}),ui:e=>o.json("POST","/upgrade/ui",e),geo:(e,r)=>o.empty("POST","/upgrade/geo",{...r,body:e})}}export{n as createUpgrade};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MihomoClient } from './client';
|
|
2
|
+
import type { MihomoRequestOptions, MihomoVersion } from './types';
|
|
3
|
+
export interface MihomoVersionModule {
|
|
4
|
+
/** GET `/version`:获取 mihomo 版本号,以及是否为 Meta 版本的标识。 */
|
|
5
|
+
get(options?: MihomoRequestOptions): Promise<MihomoVersion>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createVersion(client: MihomoClient): MihomoVersionModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(e){return{get:n=>e.json("GET","/version",n)}}export{r as createVersion};
|
package/lib/public-ip.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function e(){const t=await globalThis.fetch("https://api.ipify.org?format=json",{headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`Failed to get public IP: ${t.status} ${t.statusText}`);const i=await t.json();if(typeof i.ip!="string"||i.ip.length===0)throw new TypeError("Public IP service returned an invalid response");return i.ip}export{e as getPublicIp};
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"module": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": "24.19.0"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
10
|
+
"access": "public",
|
|
11
|
+
"registry": "https://registry.npmjs.org/"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/secretmomo/utils.git"
|
|
11
16
|
},
|
|
12
17
|
"files": [
|
|
13
18
|
"lib"
|
|
@@ -31,25 +36,26 @@
|
|
|
31
36
|
},
|
|
32
37
|
"scripts": {
|
|
33
38
|
"prepublishOnly": "bun run build",
|
|
34
|
-
"build": "rm -rf lib && rollup -c && tsc -p tsconfig.build.json"
|
|
39
|
+
"build": "rm -rf lib && rollup -c && tsc -p tsconfig.build.json",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
37
43
|
"@eslint/config-helpers": "0.7.0",
|
|
38
44
|
"@eslint/js": "10.0.1",
|
|
39
|
-
"@types/bun": "1.4.
|
|
40
|
-
"eslint": "10.
|
|
45
|
+
"@types/bun": "1.4.2",
|
|
46
|
+
"eslint": "10.11.0",
|
|
41
47
|
"eslint-plugin-import-x": "4.17.1",
|
|
42
48
|
"eslint-plugin-react": "7.37.5",
|
|
43
49
|
"eslint-plugin-react-hooks": "7.1.1",
|
|
44
50
|
"eslint-plugin-unused-imports": "4.4.1",
|
|
45
51
|
"husky": "9.1.7",
|
|
46
52
|
"jiti": "2.7.0",
|
|
47
|
-
"lint-staged": "17.
|
|
48
|
-
"prettier": "3.9.
|
|
49
|
-
"rollup": "4.63.
|
|
53
|
+
"lint-staged": "17.5.1",
|
|
54
|
+
"prettier": "3.9.8",
|
|
55
|
+
"rollup": "4.63.4",
|
|
50
56
|
"rollup-plugin-esbuild": "6.2.1",
|
|
51
57
|
"typescript": "6.0.3",
|
|
52
|
-
"typescript-eslint": "8.
|
|
58
|
+
"typescript-eslint": "8.70.0"
|
|
53
59
|
},
|
|
54
60
|
"dependencies": {
|
|
55
61
|
"dayjs": "1.11.23",
|