@onebullex-group/cli 1.1.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.
@@ -0,0 +1,44 @@
1
+ import { ConfigFile, Profile, ResolvedConfig } from './types.js';
2
+
3
+ /** 默认配置文件路径:~/.onebullex/config.json */
4
+ declare const DEFAULT_CONFIG_PATH: string;
5
+ /**
6
+ * 读取并解析配置文件。
7
+ * @throws 若文件不存在、JSON 无效或 version !== 1 则抛出 Error
8
+ */
9
+ declare function readConfigFile(path: string): ConfigFile;
10
+ /**
11
+ * 原子写入配置文件:先写临时文件再 rename,父目录权限 0o700,文件权限 0o600。
12
+ */
13
+ declare function writeConfigFile(path: string, cfg: ConfigFile): void;
14
+ /**
15
+ * 检查配置文件权限(仅非 win32)。
16
+ * 若文件 mode 不是 0o600,则发出警告并尝试修复。
17
+ */
18
+ declare function checkConfigPermissions(path: string, warn: (m: string) => void): void;
19
+ /** resolveConfig 的输入接口 */
20
+ interface ResolveInput {
21
+ configPath: string;
22
+ flags: {
23
+ profile?: string;
24
+ 'api-key'?: string;
25
+ secret?: string;
26
+ 'base-url'?: string;
27
+ debug?: boolean;
28
+ timeout?: number;
29
+ };
30
+ env: Record<string, string | undefined>;
31
+ }
32
+ /**
33
+ * 解析最终运行时配置,优先级:CLI flags > env vars > config file > error。
34
+ * @throws 若无法解析 baseUrl 则抛出包含 "config init" 的 Error
35
+ */
36
+ declare function resolveConfig(input: ResolveInput): ResolvedConfig;
37
+ /**
38
+ * 对 Profile 中的敏感字段进行脱敏:
39
+ * - api-key:调用 redactSecret
40
+ * - secret:替换为 '****'
41
+ */
42
+ declare function redactProfile(p: Profile): Profile;
43
+
44
+ export { DEFAULT_CONFIG_PATH, type ResolveInput, checkConfigPermissions, readConfigFile, redactProfile, resolveConfig, writeConfigFile };
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DEFAULT_CONFIG_PATH,
4
+ checkConfigPermissions,
5
+ readConfigFile,
6
+ redactProfile,
7
+ resolveConfig,
8
+ writeConfigFile
9
+ } from "../chunk-AKGCHJPQ.js";
10
+ import "../chunk-OOLZIYXS.js";
11
+ import "../chunk-ZYO5P4DH.js";
12
+ export {
13
+ DEFAULT_CONFIG_PATH,
14
+ checkConfigPermissions,
15
+ readConfigFile,
16
+ redactProfile,
17
+ resolveConfig,
18
+ writeConfigFile
19
+ };
@@ -0,0 +1,23 @@
1
+ declare const EXIT: {
2
+ readonly OK: 0;
3
+ readonly GENERIC: 1;
4
+ readonly API_ERROR: 2;
5
+ readonly NETWORK: 3;
6
+ readonly DRY_RUN: 4;
7
+ };
8
+ declare class OneBullExError extends Error {
9
+ readonly returnCode: string | number;
10
+ readonly httpStatus?: number | undefined;
11
+ readonly endpoint?: string | undefined;
12
+ readonly requestId?: string | undefined;
13
+ constructor(message: string, returnCode: string | number, httpStatus?: number | undefined, endpoint?: string | undefined, requestId?: string | undefined);
14
+ }
15
+ declare class DryRunInterception extends Error {
16
+ readonly preview: unknown;
17
+ constructor(preview: unknown);
18
+ }
19
+ declare class ConfigError extends Error {
20
+ constructor(message: string);
21
+ }
22
+
23
+ export { ConfigError, DryRunInterception, EXIT, OneBullExError };
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ ConfigError,
4
+ DryRunInterception,
5
+ EXIT,
6
+ OneBullExError
7
+ } from "../chunk-JRUFIHU7.js";
8
+ export {
9
+ ConfigError,
10
+ DryRunInterception,
11
+ EXIT,
12
+ OneBullExError
13
+ };
@@ -0,0 +1,29 @@
1
+ import { ResolvedConfig } from './types.js';
2
+
3
+ type Query = Record<string, string | number | boolean>;
4
+ /** fetch 函数签名,与全局 fetch 兼容,便于测试注入 */
5
+ type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
6
+ /**
7
+ * 从 body 中提取顶层 string/number/boolean 字段用于签名。
8
+ *
9
+ * - null/undefined 跳过
10
+ * - 嵌套 object/array 抛错(防止 JS Object.toString() 产生 "[object Object]"
11
+ * 与 Java 行为不一致导致签名漂移)
12
+ */
13
+ declare function flattenForSign(body: Record<string, unknown> | undefined): Query;
14
+ declare class HttpClient {
15
+ private readonly cfg;
16
+ private readonly fetch;
17
+ constructor(cfg: ResolvedConfig, fetchFn?: FetchFn);
18
+ getPublic<T>(path: string, query?: Query): Promise<T>;
19
+ getPrivate<T>(path: string, query?: Query): Promise<T>;
20
+ postPrivate<T>(path: string, body?: Record<string, unknown>): Promise<T>;
21
+ /**
22
+ * GET 请求重试包装:网络错误最多重试 2 次(共 3 次尝试),延迟 300ms / 900ms。
23
+ * OneBullExError(业务错误)不重试。
24
+ */
25
+ private withRetry;
26
+ private send;
27
+ }
28
+
29
+ export { type FetchFn, HttpClient, type Query, flattenForSign };
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ HttpClient,
4
+ flattenForSign
5
+ } from "../chunk-CVOY2SOS.js";
6
+ import "../chunk-JRUFIHU7.js";
7
+ import "../chunk-OOLZIYXS.js";
8
+ import "../chunk-ZYO5P4DH.js";
9
+ import "../chunk-LVNSFQXS.js";
10
+ export {
11
+ HttpClient,
12
+ flattenForSign
13
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 对单个字符串值进行脱敏处理。
3
+ * - 长度 < 8:返回 '****'
4
+ * - 长度 >= 8:返回前 2 位 + '****' + 后 4 位
5
+ */
6
+ declare function redactSecret(value: string): string;
7
+ /**
8
+ * 递归遍历对象,对 SENSITIVE_KEYS 中的字段进行脱敏:
9
+ * - key 为 'secret':值替换为 '****'
10
+ * - 其他敏感 key:对字符串值调用 redactSecret
11
+ * - 非敏感 key:递归处理子对象
12
+ */
13
+ declare function redactObject<T>(obj: T): T;
14
+
15
+ export { redactObject, redactSecret };
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ redactObject,
4
+ redactSecret
5
+ } from "../chunk-OOLZIYXS.js";
6
+ import "../chunk-ZYO5P4DH.js";
7
+ export {
8
+ redactObject,
9
+ redactSecret
10
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 签名参数接口,对齐 SignatureUtilsV2.java
3
+ */
4
+ interface SignParams {
5
+ /** 业务参数(不含 nonce/timestamp,sign() 内部合并) */
6
+ params: Record<string, string | number | boolean>;
7
+ /** UUID v4 去横线,32 位十六进制小写 */
8
+ nonce: string;
9
+ /** 秒级时间戳(10 位) */
10
+ timestamp: number;
11
+ /** HMAC-SHA256 密钥 */
12
+ secret: string;
13
+ }
14
+ /**
15
+ * 将参数按 key 字母序排序后拼接成 `key=value&key=value` 格式。
16
+ * 不做 URL 编码,与 Java SignatureUtilsV2.buildSortedQueryString 行为一致。
17
+ *
18
+ * @param params 参数对象(key 为字符串,value 为 string | number | boolean)
19
+ * @returns 排序后的查询字符串,空参数返回 ""
20
+ */
21
+ declare function buildSortedQueryString(params: Record<string, string | number | boolean>): string;
22
+ /**
23
+ * 生成 HMAC-SHA256 签名。
24
+ *
25
+ * 流程:
26
+ * 1. 合并业务 params + { nonce, timestamp }
27
+ * 2. 按 key 字母序排序拼接成查询字符串
28
+ * 3. HMAC-SHA256(secret, queryString, UTF-8) → 十六进制小写
29
+ *
30
+ * 对齐 Java SignatureUtilsV2.generateHmacSha256Signature。
31
+ */
32
+ declare function sign(p: SignParams): string;
33
+ /**
34
+ * 生成随机 nonce:UUID v4 去横线,32 位十六进制小写。
35
+ * 对齐 Java SignatureUtilsV2.generateNonce()。
36
+ */
37
+ declare function generateNonce(): string;
38
+
39
+ export { type SignParams, buildSortedQueryString, generateNonce, sign };
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ buildSortedQueryString,
4
+ generateNonce,
5
+ sign
6
+ } from "../chunk-LVNSFQXS.js";
7
+ export {
8
+ buildSortedQueryString,
9
+ generateNonce,
10
+ sign
11
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * CLI 全局类型定义
3
+ */
4
+ /** 配置文件中单个 profile 的结构 */
5
+ interface Profile {
6
+ 'base-url': string;
7
+ 'api-key'?: string;
8
+ secret?: string;
9
+ identify?: string | null;
10
+ env?: 'test' | 'prod';
11
+ }
12
+ /** ~/.onebullex/config.json 的顶层结构 */
13
+ interface ConfigFile {
14
+ version: 1;
15
+ 'default-profile': string;
16
+ profiles: Record<string, Profile>;
17
+ }
18
+ /** 运行时解析后的配置(已合并 CLI flags、env vars、profile) */
19
+ interface ResolvedConfig {
20
+ baseUrl: string;
21
+ apiKey?: string;
22
+ secret?: string;
23
+ identify?: string | null;
24
+ profileName: string;
25
+ env?: 'test' | 'prod';
26
+ debug: boolean;
27
+ timeoutMs: number;
28
+ }
29
+ /** 命令注册表条目 */
30
+ interface CommandRegEntry {
31
+ command: string;
32
+ method: 'GET' | 'POST';
33
+ path: string;
34
+ isWrite: boolean;
35
+ needsAuth: boolean;
36
+ implFile: string;
37
+ }
38
+ /** 输出格式 */
39
+ type OutputFormat = 'table' | 'json';
40
+ /**
41
+ * 需要脱敏的敏感字段 key 集合。
42
+ * 包含 HTTP header 名称和配置字段名称的常见变体。
43
+ */
44
+ declare const SENSITIVE_KEYS: ReadonlySet<string>;
45
+
46
+ export { type CommandRegEntry, type ConfigFile, type OutputFormat, type Profile, type ResolvedConfig, SENSITIVE_KEYS };
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ SENSITIVE_KEYS
4
+ } from "../chunk-ZYO5P4DH.js";
5
+ export {
6
+ SENSITIVE_KEYS
7
+ };
@@ -0,0 +1,45 @@
1
+ import { Command } from 'commander';
2
+ import { OutputFormat, ResolvedConfig } from './core/types.js';
3
+ import { FetchFn, HttpClient } from './core/http-client.js';
4
+
5
+ interface CliContext {
6
+ stdout: (s: string) => void;
7
+ stderr: (s: string) => void;
8
+ env: Record<string, string | undefined>;
9
+ cwd: string;
10
+ isTTY: boolean;
11
+ outputFormat?: OutputFormat;
12
+ confirm?: boolean;
13
+ /** Returns the active config file path, honoring ONEBULLEX_CONFIG_PATH env override. */
14
+ getConfigPath: () => string;
15
+ /** The CLI flags parsed from the root program (filled in preAction). */
16
+ flags: {
17
+ profile?: string;
18
+ output?: OutputFormat;
19
+ debug?: boolean;
20
+ timeout?: number;
21
+ confirm?: boolean;
22
+ baseUrl?: string;
23
+ reveal?: boolean;
24
+ };
25
+ resolveConfig: (opts: {
26
+ requireAuth: boolean;
27
+ }) => ResolvedConfig;
28
+ /** Construct an HttpClient using the resolved config + injected fetch (for testing). */
29
+ http: (opts: {
30
+ requireAuth: boolean;
31
+ }) => HttpClient;
32
+ }
33
+ interface BuildOpts {
34
+ stdout?: (s: string) => void;
35
+ stderr?: (s: string) => void;
36
+ env?: Record<string, string | undefined>;
37
+ cwd?: string;
38
+ isTTY?: boolean;
39
+ /** Override fetch (used by integration tests to stub HTTP). */
40
+ fetch?: FetchFn;
41
+ }
42
+ declare function buildProgram(opts?: BuildOpts): Command;
43
+ declare function main(argv: string[]): Promise<number>;
44
+
45
+ export { type BuildOpts, type CliContext, OutputFormat, ResolvedConfig, buildProgram, main };