@qs_cli/polaris-cli 0.2.3 → 0.2.4
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/README.md +155 -19
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,49 +1,185 @@
|
|
|
1
1
|
# Polaris CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
观星台命令行查询工具。用飞书登录后,可以在终端查询网络请求和 Dev/QA 用户资料,不必打开网页。
|
|
4
|
+
|
|
5
|
+
`polaris` 和 `polaris_cli` 是同一个程序,下面的命令把 `polaris` 换成 `polaris_cli` 即可。
|
|
4
6
|
|
|
5
7
|
## 安装
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
需要 Node.js 18 或更高版本。
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
12
|
npm install -g @qs_cli/polaris-cli
|
|
13
|
+
polaris --version
|
|
14
|
+
polaris doctor
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
卸载只删除命令,不删除本机配置和登录凭证:
|
|
14
18
|
|
|
15
19
|
```bash
|
|
16
|
-
|
|
17
|
-
./install.sh
|
|
20
|
+
npm uninstall -g @qs_cli/polaris-cli
|
|
18
21
|
```
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
从源码安装时,在 `polaris_cli` 目录执行 `./install.sh`;对应的卸载命令是 `./uninstall.sh`。
|
|
24
|
+
|
|
25
|
+
## 第一次使用
|
|
26
|
+
|
|
27
|
+
新安装后默认查询线上服务 `https://polaris.yfcenter.com`。本地和线上的登录凭证分开保存。
|
|
21
28
|
|
|
22
29
|
```bash
|
|
23
|
-
|
|
30
|
+
polaris env # 查看当前环境
|
|
31
|
+
polaris login # 浏览器完成飞书登录,等待最多 5 分钟
|
|
32
|
+
polaris whoami # 确认姓名、邮箱、角色和凭证过期时间
|
|
24
33
|
```
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
登录成功后,凭证写入 `~/.polaris/config.json`,文件权限为 `0600`。可以用 `POLARIS_CONFIG=/其他路径` 换配置文件。
|
|
36
|
+
|
|
37
|
+
`polaris logout` 只删除当前环境的本地凭证,不会影响另一个环境。凭证过期后重新执行 `polaris login`。
|
|
38
|
+
|
|
39
|
+
## 全局参数
|
|
40
|
+
|
|
41
|
+
这些参数对后面的查询命令都有效:
|
|
42
|
+
|
|
43
|
+
| 参数 | 作用 |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `--service-env <local\|online>` | 只对这一次命令切换环境,不改配置文件 |
|
|
46
|
+
| `--base <url>` | 只对这一次命令指定服务地址,覆盖环境地址 |
|
|
47
|
+
| `--json` | 以 JSON 输出,适合脚本处理 |
|
|
48
|
+
| `-V, --version` | 显示版本 |
|
|
49
|
+
| `-h, --help` | 显示帮助 |
|
|
27
50
|
|
|
28
51
|
```bash
|
|
29
|
-
polaris
|
|
30
|
-
polaris env
|
|
31
|
-
polaris
|
|
52
|
+
polaris --json whoami
|
|
53
|
+
polaris --service-env local net list --uid 24842
|
|
54
|
+
polaris --base https://polaris.yfcenter.com net get 100
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
直接执行 `polaris` 或 `polaris help` 会显示总帮助。`polaris <命令> --help` 显示该命令的参数。
|
|
58
|
+
|
|
59
|
+
## 环境
|
|
60
|
+
|
|
61
|
+
| 环境 | 地址 | 用途 |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `online` | `https://polaris.yfcenter.com` | 默认环境,查询线上观星台 |
|
|
64
|
+
| `local` | `http://127.0.0.1:8080` | 查询本机后端 |
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
polaris env # 查看当前环境、地址和配置文件
|
|
68
|
+
polaris env online # 切换并保存为线上
|
|
69
|
+
polaris env local # 切换并保存为本地
|
|
70
|
+
polaris env use online # 与 polaris env online 相同
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
已经保存过环境的配置文件会继续使用保存的值。只有没有配置文件,或者配置里没有合法环境时,才使用默认的 `online`。
|
|
74
|
+
|
|
75
|
+
## 登录和诊断
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
polaris login
|
|
32
79
|
polaris whoami
|
|
80
|
+
polaris whoami --json
|
|
81
|
+
polaris logout
|
|
33
82
|
polaris doctor
|
|
34
|
-
|
|
35
|
-
polaris net list --uid 123 --from '2026-11-10 00:00:00'
|
|
36
|
-
polaris net get 100 --curl
|
|
37
|
-
polaris user 123 --env qa
|
|
83
|
+
polaris doctor --json
|
|
38
84
|
```
|
|
39
85
|
|
|
40
|
-
|
|
86
|
+
`whoami` 显示当前环境中的姓名、邮箱、角色和凭证过期时间。角色从低到高是 `viewer`、`developer`、`admin`。
|
|
87
|
+
|
|
88
|
+
`doctor` 检查 CLI 版本、Node.js、配置文件、本地和线上连通性、当前环境的登录凭证,以及用户查询环境是否可用。用户查询环境不可用通常表示还没登录,或者角色低于 `developer`。
|
|
41
89
|
|
|
42
|
-
|
|
90
|
+
登录或查询返回 `401` 时先执行 `polaris login`。返回 `403` 表示当前账号权限不足。
|
|
43
91
|
|
|
44
|
-
|
|
92
|
+
## 查询网络请求
|
|
93
|
+
|
|
94
|
+
网络请求列表和详情需要已登录。列表不返回请求头、请求体、响应头和响应体,这些内容用 `net get` 查看。
|
|
95
|
+
|
|
96
|
+
### 列表
|
|
45
97
|
|
|
46
98
|
```bash
|
|
47
99
|
polaris net list
|
|
48
|
-
|
|
100
|
+
polaris net list --uid 24842
|
|
101
|
+
polaris net list --uid 24842 --page 2 --size 50
|
|
102
|
+
polaris net list --method POST --status 500
|
|
103
|
+
polaris net list --success false
|
|
104
|
+
polaris net list --biz-code nonzero --min-duration 1000
|
|
105
|
+
polaris net list --host api-qa.yfcenter.com --keyword financial_calendar
|
|
106
|
+
polaris net list --from 2026-11-10T00:00:00+08:00 --to 2026-11-11T00:00:00+08:00
|
|
107
|
+
polaris net list --uid 24842 --json
|
|
49
108
|
```
|
|
109
|
+
|
|
110
|
+
| 参数 | 说明 |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `--id <number>` | 按记录 ID 精确查询 |
|
|
113
|
+
| `--uid <string>` | 按用户 UID 查询 |
|
|
114
|
+
| `--device <string>` | 按设备 ID 查询 |
|
|
115
|
+
| `--method <method>` | HTTP 方法,会转成大写 |
|
|
116
|
+
| `--host <string>` | 请求 Host |
|
|
117
|
+
| `--keyword <string>` | 匹配 URL 的关键词 |
|
|
118
|
+
| `--status <number>` | HTTP 状态码 |
|
|
119
|
+
| `--success <true\|false>` | 客户端记录的请求是否成功 |
|
|
120
|
+
| `--biz-code <number\|nonzero>` | 精确业务码;`nonzero` 表示业务码不为 0 |
|
|
121
|
+
| `--min-duration <ms>` | 耗时大于等于该毫秒数 |
|
|
122
|
+
| `--app-id <string>` | App ID,例如 `youfi` |
|
|
123
|
+
| `--app-version <string>` | App 版本 |
|
|
124
|
+
| `--from <time>` | 开始时间 |
|
|
125
|
+
| `--to <time>` | 结束时间 |
|
|
126
|
+
| `--page <number>` | 页码,从 1 开始,默认 1 |
|
|
127
|
+
| `--size <number>` | 每页条数,默认 20,最大 200 |
|
|
128
|
+
|
|
129
|
+
`--from` 和 `--to` 传给服务端时只接受两种格式:RFC3339,例如 `2026-11-10T00:00:00+08:00`;或者毫秒时间戳。其他写法会被忽略,时间条件不会生效。
|
|
130
|
+
|
|
131
|
+
多个条件同时使用时是“并且”关系。表格按列宽截断长路径,完整 URL 在详情里。
|
|
132
|
+
|
|
133
|
+
### 详情
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
polaris net get 1593
|
|
137
|
+
polaris net get 1593 --curl
|
|
138
|
+
polaris net get 1593 --resp-headers
|
|
139
|
+
polaris net get 1593 --all --max-lines 200
|
|
140
|
+
polaris net get 1593 --json
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| 参数 | 说明 |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `--curl` | 根据记录生成可执行的 curl |
|
|
146
|
+
| `--resp-headers` | 额外显示响应头 |
|
|
147
|
+
| `--all` | 同时显示响应头和 curl |
|
|
148
|
+
| `--max-lines <number>` | 响应体最多显示的行数,默认 80,最大 100000 |
|
|
149
|
+
|
|
150
|
+
详情包含方法、URL、状态码、耗时、业务码、设备与应用信息、Query、请求头和请求体。响应体默认折叠到 80 行。客户端上报时单个 body 大约只保留前 16KB,超长内容末尾会带 `truncated` 标记,因此详情不一定是服务端的完整响应。
|
|
151
|
+
|
|
152
|
+
## 查询用户资料
|
|
153
|
+
|
|
154
|
+
用户查询走 Dev 或 QA 的用户中心,不是观星台自己的用户表。调用账号至少要有 `developer` 角色。
|
|
155
|
+
|
|
156
|
+
每次只能使用一种条件:UID、邮箱或手机号。
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
polaris user 24842
|
|
160
|
+
polaris user 24842 --env qa
|
|
161
|
+
polaris user --uid 1051993 --env dev
|
|
162
|
+
polaris user --email user@example.com --reveal
|
|
163
|
+
polaris user --mobile 13600000000 --nation-code 86 --env qa
|
|
164
|
+
polaris user envs
|
|
165
|
+
polaris user 24842 --json
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| 参数 | 说明 |
|
|
169
|
+
| --- | --- |
|
|
170
|
+
| `[uid]` 或 `--uid <uid>` | 按正整数 UID 查询 |
|
|
171
|
+
| `--env <dev\|qa>` | 用户中心环境,默认 `qa` |
|
|
172
|
+
| `--email <email>` | 按邮箱反查 |
|
|
173
|
+
| `--mobile <mobile>` | 按手机号反查 |
|
|
174
|
+
| `--nation-code <code>` | 手机号国家或地区码,只能和 `--mobile` 一起用 |
|
|
175
|
+
| `--reveal` | 显示手机号和邮箱明文;不加时会脱敏 |
|
|
176
|
+
|
|
177
|
+
`polaris user envs` 查看当前后端配置了哪些用户中心环境。查不到用户时返回 404。
|
|
178
|
+
|
|
179
|
+
## 常见问题
|
|
180
|
+
|
|
181
|
+
- 命令提示未登录或 `401`:对当前环境执行 `polaris login`。线上和本地要分别登录。
|
|
182
|
+
- `403`:账号角色不够。网络请求需要登录,用户查询需要 `developer` 或 `admin`。
|
|
183
|
+
- 时间筛选没有效果:改用 RFC3339 或毫秒时间戳。
|
|
184
|
+
- 详情里的响应体不完整:这是客户端上报时的长度限制,不是 CLI 再次截断。
|
|
185
|
+
- 想临时查本地服务:`polaris --service-env local <命令>`。这不改变以后的默认环境。
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { registerEnvCommand } from './commands/env.js';
|
|
|
6
6
|
import { registerNetCommand } from './commands/net.js';
|
|
7
7
|
import { registerUserCommand } from './commands/user.js';
|
|
8
8
|
import { configureHelp } from './help.js';
|
|
9
|
-
const VERSION = '0.2.
|
|
9
|
+
const VERSION = '0.2.4';
|
|
10
10
|
const program = new Command();
|
|
11
11
|
program
|
|
12
12
|
.name('polaris')
|