@cloudglab/yapi-cli 0.0.1

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +131 -0
  3. package/dist/bin/yapi.d.ts +2 -0
  4. package/dist/bin/yapi.js +8 -0
  5. package/dist/bin/yapi.js.map +1 -0
  6. package/dist/cli.d.ts +1 -0
  7. package/dist/cli.js +203 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/core/changelog.d.ts +17 -0
  10. package/dist/core/changelog.js +117 -0
  11. package/dist/core/changelog.js.map +1 -0
  12. package/dist/core/cli-output.d.ts +13 -0
  13. package/dist/core/cli-output.js +65 -0
  14. package/dist/core/cli-output.js.map +1 -0
  15. package/dist/core/cli-registry.d.ts +38 -0
  16. package/dist/core/cli-registry.js +189 -0
  17. package/dist/core/cli-registry.js.map +1 -0
  18. package/dist/core/completion.d.ts +3 -0
  19. package/dist/core/completion.js +94 -0
  20. package/dist/core/completion.js.map +1 -0
  21. package/dist/core/doctor.d.ts +13 -0
  22. package/dist/core/doctor.js +124 -0
  23. package/dist/core/doctor.js.map +1 -0
  24. package/dist/core/errors.d.ts +38 -0
  25. package/dist/core/errors.js +74 -0
  26. package/dist/core/errors.js.map +1 -0
  27. package/dist/core/output.d.ts +27 -0
  28. package/dist/core/output.js +208 -0
  29. package/dist/core/output.js.map +1 -0
  30. package/dist/core/update-probe.d.ts +14 -0
  31. package/dist/core/update-probe.js +67 -0
  32. package/dist/core/update-probe.js.map +1 -0
  33. package/dist/core/write-guard.d.ts +25 -0
  34. package/dist/core/write-guard.js +36 -0
  35. package/dist/core/write-guard.js.map +1 -0
  36. package/dist/index.d.ts +4 -0
  37. package/dist/index.js +4 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/install.d.ts +13 -0
  40. package/dist/install.js +201 -0
  41. package/dist/install.js.map +1 -0
  42. package/dist/services/yapi/api.d.ts +696 -0
  43. package/dist/services/yapi/api.js +700 -0
  44. package/dist/services/yapi/api.js.map +1 -0
  45. package/dist/services/yapi/auth.d.ts +37 -0
  46. package/dist/services/yapi/auth.js +143 -0
  47. package/dist/services/yapi/auth.js.map +1 -0
  48. package/dist/services/yapi/authCache.d.ts +25 -0
  49. package/dist/services/yapi/authCache.js +80 -0
  50. package/dist/services/yapi/authCache.js.map +1 -0
  51. package/dist/services/yapi/cache.d.ts +27 -0
  52. package/dist/services/yapi/cache.js +88 -0
  53. package/dist/services/yapi/cache.js.map +1 -0
  54. package/dist/services/yapi/config.d.ts +12 -0
  55. package/dist/services/yapi/config.js +66 -0
  56. package/dist/services/yapi/config.js.map +1 -0
  57. package/dist/services/yapi/index.d.ts +6 -0
  58. package/dist/services/yapi/index.js +6 -0
  59. package/dist/services/yapi/index.js.map +1 -0
  60. package/dist/services/yapi/logger.d.ts +6 -0
  61. package/dist/services/yapi/logger.js +36 -0
  62. package/dist/services/yapi/logger.js.map +1 -0
  63. package/dist/services/yapi/types.d.ts +176 -0
  64. package/dist/services/yapi/types.js +2 -0
  65. package/dist/services/yapi/types.js.map +1 -0
  66. package/dist/tools/index.d.ts +2 -0
  67. package/dist/tools/index.js +5 -0
  68. package/dist/tools/index.js.map +1 -0
  69. package/dist/tools/shared.d.ts +33 -0
  70. package/dist/tools/shared.js +46 -0
  71. package/dist/tools/shared.js.map +1 -0
  72. package/dist/tools/yapi/docs-sync.d.ts +29 -0
  73. package/dist/tools/yapi/docs-sync.js +243 -0
  74. package/dist/tools/yapi/docs-sync.js.map +1 -0
  75. package/dist/tools/yapi/index.d.ts +6 -0
  76. package/dist/tools/yapi/index.js +7 -0
  77. package/dist/tools/yapi/index.js.map +1 -0
  78. package/dist/tools/yapi/register-auth.d.ts +2 -0
  79. package/dist/tools/yapi/register-auth.js +182 -0
  80. package/dist/tools/yapi/register-auth.js.map +1 -0
  81. package/dist/tools/yapi/register-group.d.ts +2 -0
  82. package/dist/tools/yapi/register-group.js +178 -0
  83. package/dist/tools/yapi/register-group.js.map +1 -0
  84. package/dist/tools/yapi/register-interface.d.ts +2 -0
  85. package/dist/tools/yapi/register-interface.js +359 -0
  86. package/dist/tools/yapi/register-interface.js.map +1 -0
  87. package/dist/tools/yapi/register-project.d.ts +2 -0
  88. package/dist/tools/yapi/register-project.js +300 -0
  89. package/dist/tools/yapi/register-project.js.map +1 -0
  90. package/dist/tools/yapi/register-test.d.ts +2 -0
  91. package/dist/tools/yapi/register-test.js +267 -0
  92. package/dist/tools/yapi/register-test.js.map +1 -0
  93. package/dist/tools/yapi/register-util.d.ts +2 -0
  94. package/dist/tools/yapi/register-util.js +565 -0
  95. package/dist/tools/yapi/register-util.js.map +1 -0
  96. package/dist/tools/yapi/register.d.ts +6 -0
  97. package/dist/tools/yapi/register.js +19 -0
  98. package/dist/tools/yapi/register.js.map +1 -0
  99. package/dist/tools/yapi/utils.d.ts +11 -0
  100. package/dist/tools/yapi/utils.js +28 -0
  101. package/dist/tools/yapi/utils.js.map +1 -0
  102. package/dist/version.d.ts +1 -0
  103. package/dist/version.js +2 -0
  104. package/dist/version.js.map +1 -0
  105. package/package.json +38 -0
  106. package/skills/yapi-cli/SKILL.md +126 -0
  107. package/skills/yapi-cli/reference/auth.md +106 -0
  108. package/skills/yapi-cli/reference/cli.md +60 -0
  109. package/skills/yapi-cli/reference/commands.md +152 -0
  110. package/skills/yapi-cli/reference/group.md +77 -0
  111. package/skills/yapi-cli/reference/install.md +82 -0
  112. package/skills/yapi-cli/reference/interface.md +185 -0
  113. package/skills/yapi-cli/reference/overview.md +52 -0
  114. package/skills/yapi-cli/reference/project.md +115 -0
  115. package/skills/yapi-cli/reference/test.md +130 -0
@@ -0,0 +1,185 @@
1
+ # 接口
2
+
3
+ ## 强制判断
4
+
5
+ 先确认用户意图:
6
+ - **搜索接口** → 关键词搜索,可选 `projectId` 收窄范围
7
+ - **接口列表** → 按项目查询,支持 status/method 过滤
8
+ - **接口详情** → 需要 `interfaceId`
9
+ - **创建 / 更新 / 删除** → 写操作,需要 `--confirm true`
10
+ - **分类(Category)** → 项目的接口分组
11
+ - **Mock** → 接口级 Mock 开关和自定义脚本
12
+ - **日志** → 接口变更历史
13
+ - **导出** → 按项目导出接口定义
14
+ - **集合(Collection)** → 测试集合和用例
15
+
16
+ ## 搜索
17
+
18
+ ### 接口搜索
19
+
20
+ ```bash
21
+ yapi search --q <keyword> [--projectId <id>] [--page 1] [--limit 50]
22
+ ```
23
+
24
+ 全局关键词搜索,支持按项目收窄范围。
25
+
26
+ ### 接口列表
27
+
28
+ ```bash
29
+ yapi interface-list --projectId <id> [--status <s>] [--method <m>] [--page <n>] [--limit <n>]
30
+ ```
31
+
32
+ `--status`:`done`(已完成)、`undone`(未完成)
33
+ `--method`:`GET`、`POST`、`PUT`、`DELETE`
34
+
35
+ ### 接口详情
36
+
37
+ ```bash
38
+ yapi interface-get --interfaceId <id>
39
+ ```
40
+
41
+ 返回接口完整定义:路径、方法、请求参数、响应示例、Mock 状态等。
42
+
43
+ ## 分类
44
+
45
+ ### 分类列表
46
+
47
+ ```bash
48
+ yapi category-list --projectId <id>
49
+ ```
50
+
51
+ ### 分类排序
52
+
53
+ ```bash
54
+ yapi interface-up-cat-index --catid <id> --index <n> --confirm true
55
+ ```
56
+
57
+ ## CRUD
58
+
59
+ ### 创建接口
60
+
61
+ ```bash
62
+ yapi interface-create --projectId <id> --catId <id> --title <title> --path <path> [--method GET] [--desc <desc>] --confirm true
63
+ ```
64
+
65
+ ### 更新接口
66
+
67
+ ```bash
68
+ yapi interface-update --interfaceId <id> [--title <t>] [--path <p>] [--method <m>] --confirm true
69
+ ```
70
+
71
+ ### 删除接口
72
+
73
+ ```bash
74
+ yapi interface-delete --interfaceId <id> --confirm true
75
+ ```
76
+
77
+ ## Mock
78
+
79
+ ### Mock 开关
80
+
81
+ ```bash
82
+ yapi interface-mock-toggle --interfaceId <id> [--open true] --confirm true
83
+ ```
84
+
85
+ ### Mock 脚本
86
+
87
+ ```bash
88
+ yapi interface-mock-script --interfaceId <id> --script <script> --confirm true
89
+ ```
90
+
91
+ YApi Mock 脚本在沙箱中执行,支持:
92
+ - `mockJson` — 修改 Mock 返回 JSON
93
+ - `httpCode` — 修改状态码(默认 200)
94
+ - `resHeader` — 修改响应头
95
+ - `delay` — 设置延迟(毫秒)
96
+
97
+ 示例脚本:
98
+
99
+ ```js
100
+ mockJson = { code: 0, data: { id: 1, name: 'mock' }, message: 'success' };
101
+ httpCode = 200;
102
+ delay = 500;
103
+ ```
104
+
105
+ ## 其他
106
+
107
+ ### 原始请求
108
+
109
+ ```bash
110
+ yapi request --path /api/endpoint [--method GET] [--body <json>]
111
+ ```
112
+
113
+ 走 YApi 认证,发送任意 HTTP 请求。
114
+
115
+ ### 日志
116
+
117
+ ```bash
118
+ yapi log --interfaceId <id> [--projectId <id>]
119
+ ```
120
+
121
+ 接口变更历史记录。
122
+
123
+ ### 导出
124
+
125
+ ```bash
126
+ yapi export --projectId <id> [--type json]
127
+ ```
128
+
129
+ `--type`:`json`、`swagger`、`openapi3`
130
+
131
+ ### 下载 CRX
132
+
133
+ ```bash
134
+ yapi interface-download-crx
135
+ ```
136
+
137
+ 下载 YApi 跨域请求插件。
138
+
139
+ ## 集合
140
+
141
+ ### 集合列表
142
+
143
+ ```bash
144
+ yapi col-list --projectId <id>
145
+ ```
146
+
147
+ ### 集合用例
148
+
149
+ ```bash
150
+ yapi col-cases --projectId <id> --colId <id>
151
+ ```
152
+
153
+ ## 参数对照
154
+
155
+ | 参数名 | 类型 | 必填 | 说明 |
156
+ |--------|------|------|------|
157
+ | `interfaceId` | number | get/update/delete/log/toggle/script | 接口 ID |
158
+ | `projectId` | number | list/create/export/col | 项目 ID |
159
+ | `catId` | number | interface-create | 分类 ID |
160
+ | `catid` | number | up-cat-index | 分类 ID |
161
+ | `title` | string | create/update | 接口标题 |
162
+ | `path` | string | create | 接口路径 |
163
+ | `method` | string | 否 | HTTP 方法 |
164
+ | `q` | string | search | 搜索关键词 |
165
+ | `confirm` | boolean | 写操作 | 确认执行 |
166
+
167
+ ## 常见链路
168
+
169
+ ```bash
170
+ # 搜索 → 查详情 → 看日志
171
+ yapi search --q <keyword> --limit 10
172
+ yapi interface-get --interfaceId <id>
173
+ yapi log --interfaceId <id>
174
+
175
+ # 创建接口步骤
176
+ yapi category-list --projectId <id>
177
+ yapi interface-create --projectId <id> --catId <cid> --title <t> --path <p> --confirm true
178
+ yapi interface-mock-script --interfaceId <id> --script <s> --confirm true
179
+ yapi interface-list --projectId <id>
180
+
181
+ # 接口完整上下文
182
+ yapi interface-get --interfaceId <id>
183
+ yapi interface-mock-toggle --interfaceId <id>
184
+ yapi log --interfaceId <id>
185
+ ```
@@ -0,0 +1,52 @@
1
+ # Overview
2
+
3
+ yapi-cli 是 YApi 的命令行客户端,基于 InMemoryCliRegistry + Zod schema + jsonResult 模式构建。
4
+
5
+ ## 架构
6
+
7
+ ```
8
+ src/
9
+ bin/yapi.js — 入口脚本
10
+ cli.ts — CLI 运行器(内置命令:help/version/doctor/changelog/completion)
11
+ core/
12
+ cli-registry.ts — InMemoryCliRegistry(命令注册 + 参数解析)
13
+ cli-output.ts — 帮助输出渲染
14
+ errors.ts — CliError 分层错误
15
+ output.ts — OutputFormatter(pretty / json 双模式)
16
+ write-guard.ts — 写保护(YAPI_DISABLE_WRITE + confirm)
17
+ doctor.ts — 自检命令
18
+ changelog.ts — 版本变更解析
19
+ completion.ts — Shell 补全生成
20
+ update-probe.ts — npm 版本探测
21
+ install.ts — 安装/更新/卸载
22
+ services/yapi/ — YApi 服务层
23
+ api.ts — YApi API 客户端(101 路由端点全覆盖)
24
+ auth.ts — 认证管理(Token + JWT Cookie + LDAP)
25
+ config.ts — 配置管理(JSON)
26
+ cache.ts — 缓存
27
+ authCache.ts — 认证缓存持久化
28
+ logger.ts — 日志
29
+ types.ts — 类型定义
30
+ tools/yapi/
31
+ register.ts — 命令注册组合器
32
+ register-auth.ts — 认证/配置命令
33
+ register-group.ts — 分组命令
34
+ register-project.ts — 项目命令
35
+ register-interface.ts — 接口命令
36
+ register-util.ts — 用户/集合/工具命令
37
+ register-test.ts — 测试命令
38
+ utils.ts — 工具函数
39
+ docs-sync.ts — 文档同步
40
+ ```
41
+
42
+ ## 认证方式
43
+
44
+ - **Token 认证**:通过 `login --token <t>` 或 `config-init --token <t>` 设置
45
+ - **JWT Cookie 认证**:通过 `login --email <e> --password <p>` 密码登录(支持 LDAP/本地账号)
46
+ - **LDAP 专用**:`login --email <e> --password <p>`,YApi 服务端自动识别 LDAP 并处理 PBKDF2 加密
47
+
48
+ ## 配置位置
49
+
50
+ - CLI 配置:`~/.yapi/config.json`
51
+ - 认证缓存:`~/.yapi/.yapi-auth`
52
+ - API 缓存:`~/.yapi/.yapi-cache/cache.json`
@@ -0,0 +1,115 @@
1
+ # 项目
2
+
3
+ ## 强制判断
4
+
5
+ 先确认用户想查什么维度的项目信息:
6
+ - **项目列表** → 查全量或按分组过滤
7
+ - **项目详情** → 需要 `projectId`
8
+ - **环境配置** → 需要 `projectId`
9
+ - **项目成员** → 需要 `projectId`
10
+ - **关注项目** → 查我关注的,不需要参数
11
+ - **Mock 配置** → 项目级 Mock 开关和脚本
12
+
13
+ ## 查询
14
+
15
+ ### 项目列表
16
+
17
+ ```bash
18
+ yapi project-list [--groupId <id>] [--page 1] [--limit 50]
19
+ ```
20
+
21
+ `--groupId` 可选,不传时查全部可见项目。
22
+
23
+ ### 项目详情
24
+
25
+ ```bash
26
+ yapi project-get --projectId <id>
27
+ ```
28
+
29
+ 返回项目基本信息、分组、创建时间、统计等。
30
+
31
+ ### 项目 Token
32
+
33
+ ```bash
34
+ yapi project-token --projectId <id>
35
+ ```
36
+
37
+ 获取项目的 API Token。
38
+
39
+ ### 环境配置
40
+
41
+ ```bash
42
+ yapi env --projectId <id>
43
+ ```
44
+
45
+ 列出项目环境变量(域名、header 等)。
46
+
47
+ ### 项目成员
48
+
49
+ ```bash
50
+ yapi member --projectId <id>
51
+ ```
52
+
53
+ ### 修改成员角色
54
+
55
+ ```bash
56
+ yapi member-change-role --projectId <id> --memberUid <uid> --role <role> --confirm true
57
+ ```
58
+
59
+ `--role` 支持:`owner`、`dev`、`guest`、`developer`、`viewer`
60
+
61
+ ### 关注项目
62
+
63
+ ```bash
64
+ yapi follow
65
+ ```
66
+
67
+ 列出当前用户关注的项目。
68
+
69
+ ## 写入
70
+
71
+ ### Mock 开关
72
+
73
+ ```bash
74
+ yapi project-mock-toggle --projectId <id> [--open true] --confirm true
75
+ ```
76
+
77
+ ### Mock 脚本
78
+
79
+ ```bash
80
+ yapi project-mock-script --projectId <id> --script <script> --confirm true
81
+ ```
82
+
83
+ 设置项目级全局 Mock 脚本。脚本在沙箱中执行,可操控 `mockJson`、`httpCode`、`resHeader`、`delay`。
84
+
85
+ ## 参数对照
86
+
87
+ | 参数名 | 类型 | 必填 | 说明 |
88
+ |--------|------|------|------|
89
+ | `projectId` | number | 大多数操作 | 项目 ID |
90
+ | `groupId` | number | project-list 筛选 | 分组 ID |
91
+ | `page` | number | 否 | 页码(默认 1) |
92
+ | `limit` | number | 否 | 每页数(默认 50) |
93
+ | `memberUid` | number | member-change-role | 成员用户 ID |
94
+ | `role` | string | member-change-role | 角色枚举 |
95
+ | `open` | boolean | mock-toggle | 是否开启 |
96
+ | `script` | string | mock-script | Mock 脚本内容 |
97
+ | `confirm` | boolean | 写操作 | 确认执行 |
98
+
99
+ ## 常见链路
100
+
101
+ ```bash
102
+ # 查项目完整信息
103
+ yapi project-get --projectId <id>
104
+ yapi env --projectId <id>
105
+ yapi member --projectId <id>
106
+ yapi interface-list --projectId <id> --limit 50
107
+
108
+ # 配置 Mock
109
+ yapi project-mock-toggle --projectId <id> --open true --confirm true
110
+ yapi project-mock-script --projectId <id> --script 'mockJson={code:0}' --confirm true
111
+
112
+ # 分组成员管理
113
+ yapi member --projectId <id>
114
+ yapi member-change-role --projectId <id> --memberUid <uid> --role dev --confirm true
115
+ ```
@@ -0,0 +1,130 @@
1
+ # 测试
2
+
3
+ ## 强制判断
4
+
5
+ 测试命令用于发送 HTTP 请求并查看响应,主要用于接口调试和验证:
6
+
7
+ - **标准 HTTP 测试** → 测试 GET/POST/PUT/DELETE/HEAD/OPTIONS/PATCH
8
+ - **上传测试** → 单文件或多文件上传
9
+ - **响应分析** → 检查状态码、原始响应、响应结构
10
+ - **自动测试** → 运行项目预设的自动测试
11
+
12
+ 所有测试命令都接受 `--url <url>` 参数(完整 URL,不是路径),不需要 YApi 认证。
13
+
14
+ ## HTTP 方法测试
15
+
16
+ ### GET
17
+
18
+ ```bash
19
+ yapi test-get --url https://api.example.com/endpoint [--params '{"key":"value"}']
20
+ ```
21
+
22
+ `--params` 为 JSON 字符串,转为查询参数。
23
+
24
+ ### POST
25
+
26
+ ```bash
27
+ yapi test-post --url https://api.example.com/endpoint [--body '{"key":"value"}']
28
+ ```
29
+
30
+ `--body` 为 JSON 字符串,作为请求体。
31
+
32
+ ### PUT / DELETE / PATCH
33
+
34
+ ```bash
35
+ yapi test-put --url https://api.example.com/endpoint [--body <json>]
36
+ yapi test-delete --url https://api.example.com/endpoint
37
+ yapi test-patch --url https://api.example.com/endpoint [--body <json>]
38
+ ```
39
+
40
+ ### HEAD / OPTIONS
41
+
42
+ ```bash
43
+ yapi test-head --url https://api.example.com/endpoint
44
+ yapi test-options --url https://api.example.com/endpoint
45
+ ```
46
+
47
+ ## 上传测试
48
+
49
+ ### 单文件上传
50
+
51
+ ```bash
52
+ yapi test-single-upload --url https://api.example.com/upload --filePath /path/to/file
53
+ ```
54
+
55
+ ### 多文件上传
56
+
57
+ ```bash
58
+ yapi test-files-upload --url https://api.example.com/upload --filePaths /path/a --filePaths /path/b [--params <json>]
59
+ ```
60
+
61
+ ## 响应分析
62
+
63
+ ### 状态码检查
64
+
65
+ ```bash
66
+ yapi test-http-code --url https://api.example.com/endpoint
67
+ ```
68
+
69
+ 只返回 HTTP 状态码。
70
+
71
+ ### 原始响应
72
+
73
+ ```bash
74
+ yapi test-raw --url https://api.example.com/endpoint
75
+ ```
76
+
77
+ 查看原始文本响应,不解析 JSON。
78
+
79
+ ### 响应结构
80
+
81
+ ```bash
82
+ yapi test-response --url https://api.example.com/endpoint
83
+ ```
84
+
85
+ 查看完整响应结构(状态码、头、体)。
86
+
87
+ ## 自动测试
88
+
89
+ ### 运行自动测试
90
+
91
+ ```bash
92
+ yapi run-auto-test --projectId <id> [--format json]
93
+ ```
94
+
95
+ 调用 YApi 项目的自动测试功能。
96
+
97
+ ### 项目接口数据
98
+
99
+ ```bash
100
+ yapi project-interface-data --projectId <id>
101
+ ```
102
+
103
+ 查询项目接口测试数据。
104
+
105
+ ## 参数对照
106
+
107
+ | 参数名 | 类型 | 必填 | 说明 |
108
+ |--------|------|------|------|
109
+ | `url` | string | 全部测试命令 | 完整 URL |
110
+ | `body` | string | post/put/patch | JSON 请求体 |
111
+ | `params` | string | get/files-upload | JSON 查询参数 |
112
+ | `filePath` | string | single-upload | 上传文件路径 |
113
+ | `filePaths` | string[] | files-upload | 多文件上传路径 |
114
+ | `projectId` | number | run-auto-test | 项目 ID |
115
+ | `format` | string | 否 | 输出格式(json) |
116
+
117
+ ## 常见链路
118
+
119
+ ```bash
120
+ # 先查接口定义,再测试
121
+ yapi interface-get --interfaceId <id>
122
+ yapi test-get --url https://api.example.com/path
123
+
124
+ # 调试上传
125
+ yapi test-single-upload --url https://api.example.com/upload --filePath ./test.png
126
+
127
+ # 全链路验证
128
+ yapi test-http-code --url https://api.example.com/health
129
+ yapi test-response --url https://api.example.com/health
130
+ ```