zentao-api 0.6.6 → 0.6.8
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 +41 -2
- package/dist/browser/zentao-api.global.js +21 -21
- package/dist/client/index.d.ts +45 -5
- package/dist/client/index.js +131 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/misc/errors.d.ts +6 -1
- package/dist/misc/errors.js +9 -1
- package/dist/misc/zentao-version.d.ts +11 -0
- package/dist/misc/zentao-version.js +35 -0
- package/dist/modules/define.d.ts +4 -3
- package/dist/modules/define.js +4 -3
- package/dist/modules/generated.d.ts +228 -0
- package/dist/modules/generated.js +228 -0
- package/dist/modules/override.d.ts +2 -0
- package/dist/modules/override.js +3 -0
- package/dist/modules/query.d.ts +13 -8
- package/dist/modules/query.js +25 -11
- package/dist/modules/registry-store.js +6 -0
- package/dist/profiles/file-lock.d.ts +6 -0
- package/dist/profiles/file-lock.js +127 -0
- package/dist/profiles/index.d.ts +11 -4
- package/dist/profiles/index.js +134 -79
- package/dist/request/index.d.ts +3 -0
- package/dist/request/index.js +47 -11
- package/dist/types/client.d.ts +10 -0
- package/dist/types/module.d.ts +32 -2
- package/dist/types/options.d.ts +8 -0
- package/dist/types/profile.d.ts +14 -8
- package/dist/types/response.d.ts +9 -0
- package/dist/version.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -221,11 +221,35 @@ setGlobalOptions({
|
|
|
221
221
|
});
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
常用全局选项包括 `client`、`recPerPage`、`limit`、`timeout`、`insecure`、`persistProfiles`、`throwOnFail` 和 `autoFill`。优先级通常为:单次调用选项 > 全局选项 > 客户端默认值。
|
|
224
|
+
常用全局选项包括 `client`、`version`、`recPerPage`、`limit`、`timeout`、`insecure`、`persistProfiles`、`skipVersionCheckOnConfigError`、`throwOnFail` 和 `autoFill`。优先级通常为:单次调用选项 > 全局选项 > 客户端默认值。
|
|
225
|
+
|
|
226
|
+
### 禅道版本检查
|
|
227
|
+
|
|
228
|
+
高阶 `request()` 会在发送业务请求前检查 Action 的必填 `minVersion`。四个系列分别比较,例如 `22.5`、`biz13.5`、`max8.5`、`ipd5.5`;支持点分数字正式版本,暂不支持 alpha、beta、rc 等后缀。底层 `client.get/post/request` 不检查 Action 版本。
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
setGlobalOptions({ version: 'biz13.5' });
|
|
232
|
+
await request('story/getGrades'); // 直接使用全局版本,无需获取配置
|
|
233
|
+
await request('story/getGrades', {}, { forceRefreshConfig: true }); // 用服务器实际版本校验本次请求
|
|
234
|
+
|
|
235
|
+
const config = await client.getZentaoConfig(); // 复用有效缓存,缺失或过期时获取
|
|
236
|
+
const freshConfig = await client.getZentaoConfig({ forceRefresh: true });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
`getZentaoConfig()` 只需站点地址,无需登录或 profile;未提供 Token 或 Token 已过期时都可调用。请求不发送 API Token,浏览器中还会显式省略 Cookie 等凭据,因此可以在登录前查询版本:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
const siteClient = new ZentaoClient('https://zentao.example.com');
|
|
243
|
+
const { version } = await siteClient.getZentaoConfig();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
强制刷新不会改写全局 `version`。未指定全局版本时,使用不超过 24 小时的缓存;缓存缺失、过期或时间异常时访问站点根地址的 `/?mode=getconfig`。登录验证成功后也会强制获取一次,即使已设置全局版本。
|
|
247
|
+
|
|
248
|
+
配置获取失败默认停止调用;可以通过全局或单次 `skipVersionCheckOnConfigError: true` 跳过本次检查。该选项不忽略版本不匹配、版本格式错误、取消或 profile 存储错误。版本不匹配抛出 `E_UNSUPPORTED_ZENTAO_VERSION`。
|
|
225
249
|
|
|
226
250
|
### 持久化 Profile
|
|
227
251
|
|
|
228
|
-
Profile
|
|
252
|
+
`login()` 默认不会自动写入 Profile。先启用 `persistProfiles`,登录成功后才会保存站点、账号、token、客户端配置,以及 `serverConfig` 和获取时间 `serverConfigFetchedAt`:
|
|
229
253
|
|
|
230
254
|
```ts
|
|
231
255
|
import { ZentaoClient, setGlobalOptions } from 'zentao-api';
|
|
@@ -249,6 +273,11 @@ setGlobalOptions({ client });
|
|
|
249
273
|
const another = await ZentaoClient.fromProfile(
|
|
250
274
|
'admin@https://zentao.example.com',
|
|
251
275
|
);
|
|
276
|
+
|
|
277
|
+
// 只读取并恢复,不切换当前 Profile、不更新使用时间、不写存储。
|
|
278
|
+
const isolated = await ZentaoClient.fromProfile(
|
|
279
|
+
'admin@https://zentao.example.com', { activate: false },
|
|
280
|
+
);
|
|
252
281
|
```
|
|
253
282
|
|
|
254
283
|
| 环境 | 存储位置 |
|
|
@@ -313,6 +342,7 @@ import { ZentaoClient, request } from 'zentao-api/browser';
|
|
|
313
342
|
|
|
314
343
|
```ts
|
|
315
344
|
import {
|
|
345
|
+
getModule,
|
|
316
346
|
getModuleAction,
|
|
317
347
|
getModuleActionParams,
|
|
318
348
|
getModuleNames,
|
|
@@ -323,8 +353,14 @@ const modules = getModuleNames();
|
|
|
323
353
|
const action = getModuleAction('bug', 'create');
|
|
324
354
|
const params = getModuleActionParams('bug', 'create');
|
|
325
355
|
const labels = getObjectProps('bug');
|
|
356
|
+
|
|
357
|
+
const supported = getModule('story', { version: 'biz13.0' });
|
|
358
|
+
const unavailable = getModuleAction('story', 'getGrades', { version: 'biz13.0' }); // undefined
|
|
359
|
+
const supportedParams = getModuleActionParams('story', 'create', { version: 'biz13.0', roles: ['body'] });
|
|
326
360
|
```
|
|
327
361
|
|
|
362
|
+
模块查询只使用显式传入的 `version`,省略时返回当前完整定义,不受全局版本影响。过滤后没有动作的模块不返回。旧 Action 后续新增的参数仍按当前定义返回,不做参数级版本过滤。
|
|
363
|
+
|
|
328
364
|
未注册的 API 可以新增为自定义模块:
|
|
329
365
|
|
|
330
366
|
```ts
|
|
@@ -335,6 +371,7 @@ defineModules({
|
|
|
335
371
|
actions: [
|
|
336
372
|
{
|
|
337
373
|
name: 'list',
|
|
374
|
+
minVersion: ['22.0', 'biz13.0', 'max8.0', 'ipd5.0'],
|
|
338
375
|
type: 'list',
|
|
339
376
|
path: '/custom',
|
|
340
377
|
resultGetter: 'items',
|
|
@@ -356,6 +393,8 @@ extendModuleAction('task', 'list', {
|
|
|
356
393
|
|
|
357
394
|
`defineModuleActions()` 可追加或整体替换单个动作,`defineModules(module, { replace: true })` 可整体替换同名模块。请确保扩展代码在第一次调用 `request()` 前执行。
|
|
358
395
|
|
|
396
|
+
所有完整 Action 定义都必须包含非空的 `minVersion` 数组,同一系列不能重复;未列出的系列视为不支持。SDK 0.5.5 及之前已有的 Action 最低版本为 `22.0 / biz13.0 / max8.0 / ipd5.0`,之后新增的 Action 为 `22.5 / biz13.5 / max8.5 / ipd5.5`。
|
|
397
|
+
|
|
359
398
|
## 文档
|
|
360
399
|
|
|
361
400
|
- [快速开始](https://github.com/easysoft/zentao-api/blob/main/docs/guide/index.md)
|