zentao-api 0.8.3 → 0.8.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 +22 -1
- package/dist/browser/zentao-api.global.js +17 -17
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.js +31 -1
- package/dist/modules/override.js +5 -5
- package/dist/request/index.js +2 -0
- package/dist/types/client.d.ts +15 -1
- package/dist/types/module.d.ts +3 -1
- package/dist/types/options.d.ts +5 -0
- package/dist/version.js +2 -2
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class ZentaoClient {
|
|
|
20
20
|
private token?;
|
|
21
21
|
private readonly timeout?;
|
|
22
22
|
private readonly insecure?;
|
|
23
|
+
private readonly actionAssistant?;
|
|
23
24
|
private profileKey?;
|
|
24
25
|
private serverConfig?;
|
|
25
26
|
private serverConfigFetchedAt?;
|
|
@@ -56,8 +57,8 @@ export declare class ZentaoClient {
|
|
|
56
57
|
* @returns 解析后的响应体;当响应为空字符串时返回 `undefined`。
|
|
57
58
|
* @throws {ZentaoError} 可能抛出 `E_HTTP_ERROR`(非 2xx 状态)、`E_NETWORK_ERROR`(底层 fetch 失败)、
|
|
58
59
|
* `E_TIMEOUT`(超过 `timeout`)、`E_ABORTED`(外部信号取消)或
|
|
59
|
-
* `E_INSECURE_BROWSER`(浏览器中开启了 `insecure`);传入 `ReadableStream`
|
|
60
|
-
* `E_INVALID_PARAM`。
|
|
60
|
+
* `E_INSECURE_BROWSER`(浏览器中开启了 `insecure`);传入 `ReadableStream` 请求体或无效的
|
|
61
|
+
* `actionAssistant` 对象时会抛 `E_INVALID_PARAM`。
|
|
61
62
|
*/
|
|
62
63
|
request(path: string, options: ClientRequestOptions & {
|
|
63
64
|
responseType: 'response';
|
|
@@ -83,7 +84,7 @@ export declare class ZentaoClient {
|
|
|
83
84
|
/**
|
|
84
85
|
* 匿名获取禅道站点 `/?mode=getconfig` 配置,只需站点地址,无需登录或 profile。
|
|
85
86
|
*
|
|
86
|
-
* 不发送 API Token
|
|
87
|
+
* 不发送 API Token 或操作辅助工具标记,浏览器请求显式省略 Cookie 等凭据,不受 API Token 过期影响。
|
|
87
88
|
*
|
|
88
89
|
* 默认复用不超过 24 小时的缓存;缺失、过期或时间异常时重新获取。
|
|
89
90
|
* `forceRefresh: true` 忽略缓存。同一客户端的并发刷新共用首次调用的传输选项;
|
package/dist/client/index.js
CHANGED
|
@@ -6,6 +6,22 @@ import { getProfileOrThrow, saveLoginProfile, switchProfile, updateProfileServer
|
|
|
6
6
|
import { isRecord, normalizeSiteUrl } from '../utils/index.js';
|
|
7
7
|
const DEFAULT_TIMEOUT = 10000;
|
|
8
8
|
const CONFIG_MAX_AGE = 24 * 60 * 60 * 1000;
|
|
9
|
+
const ACTION_ASSISTANT_HEADER = 'ZenTao-Action-Assistant';
|
|
10
|
+
function serializeActionAssistant(value) {
|
|
11
|
+
if (typeof value === 'string')
|
|
12
|
+
return value;
|
|
13
|
+
const invalidField = /[<>\u0000-\u001f\u007f-\u009f]/;
|
|
14
|
+
if (!isRecord(value) || typeof value.name !== 'string' || !value.name.trim() || invalidField.test(value.name)
|
|
15
|
+
|| (value.info !== undefined && (typeof value.info !== 'string' || invalidField.test(value.info)))) {
|
|
16
|
+
throw new ZentaoError('E_INVALID_PARAM', {
|
|
17
|
+
param: 'actionAssistant',
|
|
18
|
+
value: 'Expected a non-empty name and optional info without angle brackets or control characters.',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const name = value.name.trim();
|
|
22
|
+
const info = value.info?.trim();
|
|
23
|
+
return info ? `${name} <${info}>` : name;
|
|
24
|
+
}
|
|
9
25
|
function isServerConfig(value) {
|
|
10
26
|
return isRecord(value) && typeof value.version === 'string' && value.version.trim().length > 0;
|
|
11
27
|
}
|
|
@@ -303,6 +319,7 @@ export class ZentaoClient {
|
|
|
303
319
|
token;
|
|
304
320
|
timeout;
|
|
305
321
|
insecure;
|
|
322
|
+
actionAssistant;
|
|
306
323
|
profileKey;
|
|
307
324
|
serverConfig;
|
|
308
325
|
serverConfigFetchedAt;
|
|
@@ -314,6 +331,7 @@ export class ZentaoClient {
|
|
|
314
331
|
this.token = options.token;
|
|
315
332
|
this.timeout = options.timeout;
|
|
316
333
|
this.insecure = options.insecure;
|
|
334
|
+
this.actionAssistant = options.actionAssistant;
|
|
317
335
|
}
|
|
318
336
|
async request(path, options = {}) {
|
|
319
337
|
return this.fetch(buildUrl(this.baseUrl, path, options.query), options, this.token);
|
|
@@ -335,6 +353,17 @@ export class ZentaoClient {
|
|
|
335
353
|
const insecure = options.insecure ?? globals.insecure ?? this.insecure;
|
|
336
354
|
assertInsecureSupported(insecure);
|
|
337
355
|
const headers = new Headers(options.headers);
|
|
356
|
+
const actionAssistant = options.actionAssistant !== undefined
|
|
357
|
+
? options.actionAssistant
|
|
358
|
+
: headers.get(ACTION_ASSISTANT_HEADER)
|
|
359
|
+
?? (globals.actionAssistant !== undefined ? globals.actionAssistant : this.actionAssistant);
|
|
360
|
+
if (actionAssistant !== undefined) {
|
|
361
|
+
const value = serializeActionAssistant(actionAssistant);
|
|
362
|
+
if (value === '')
|
|
363
|
+
headers.delete(ACTION_ASSISTANT_HEADER);
|
|
364
|
+
else
|
|
365
|
+
headers.set(ACTION_ASSISTANT_HEADER, value);
|
|
366
|
+
}
|
|
338
367
|
if (token) {
|
|
339
368
|
headers.set('Token', token);
|
|
340
369
|
}
|
|
@@ -390,7 +419,7 @@ export class ZentaoClient {
|
|
|
390
419
|
/**
|
|
391
420
|
* 匿名获取禅道站点 `/?mode=getconfig` 配置,只需站点地址,无需登录或 profile。
|
|
392
421
|
*
|
|
393
|
-
* 不发送 API Token
|
|
422
|
+
* 不发送 API Token 或操作辅助工具标记,浏览器请求显式省略 Cookie 等凭据,不受 API Token 过期影响。
|
|
394
423
|
*
|
|
395
424
|
* 默认复用不超过 24 小时的缓存;缺失、过期或时间异常时重新获取。
|
|
396
425
|
* `forceRefresh: true` 忽略缓存。同一客户端的并发刷新共用首次调用的传输选项;
|
|
@@ -420,6 +449,7 @@ export class ZentaoClient {
|
|
|
420
449
|
}
|
|
421
450
|
const pending = this.fetch(buildUrl(this.siteUrl, '/', { mode: 'getconfig' }), {
|
|
422
451
|
method: 'GET', timeout: options.timeout, insecure: options.insecure, signal: options.signal,
|
|
452
|
+
actionAssistant: '',
|
|
423
453
|
}, undefined, { cache: 'no-store', credentials: 'omit' }).then(async (config) => {
|
|
424
454
|
if (!isServerConfig(config))
|
|
425
455
|
throw new ZentaoError('E_INVALID_ZENTAO_CONFIG');
|
package/dist/modules/override.js
CHANGED
|
@@ -5,10 +5,10 @@ import { isRecord } from '../utils/index.js';
|
|
|
5
5
|
import { request } from '../request/index.js';
|
|
6
6
|
import { ZentaoError } from '../misc/errors.js';
|
|
7
7
|
/** 这些内置接口要求 JSON,不能把 HTTP 200 的 PHP/SQL 错误文本视为成功。 */
|
|
8
|
-
const requestJSON = async ({ request: command, body, bodyType, client, timeout, insecure }) => {
|
|
8
|
+
const requestJSON = async ({ request: command, body, bodyType, client, timeout, insecure, actionAssistant }) => {
|
|
9
9
|
const response = await client.request(command.path, {
|
|
10
10
|
method: command.action.method.toUpperCase(),
|
|
11
|
-
query: command.query, body, bodyType, timeout, insecure, responseType: 'response',
|
|
11
|
+
query: command.query, body, bodyType, timeout, insecure, actionAssistant, responseType: 'response',
|
|
12
12
|
});
|
|
13
13
|
const responseText = await response.text();
|
|
14
14
|
try {
|
|
@@ -342,13 +342,13 @@ export function applyBuiltinOverrides() {
|
|
|
342
342
|
});
|
|
343
343
|
// 确认表单会重置缺省字段;仅补齐可写字段,不回传详情中的其他属性。
|
|
344
344
|
extendModuleAction('bug', 'confirm', {
|
|
345
|
-
request: async ({ request: command, body, bodyType, client, timeout, insecure, options }) => {
|
|
345
|
+
request: async ({ request: command, body, bodyType, client, timeout, insecure, actionAssistant, options }) => {
|
|
346
346
|
const data = { ...body };
|
|
347
347
|
const fields = ['status', 'assignedTo', 'type', 'pri', 'deadline', 'mailto'];
|
|
348
348
|
const missing = fields.filter(field => data[field] === undefined);
|
|
349
349
|
if (missing.length) {
|
|
350
350
|
const response = await request('bug/get', { id: command.id }, {
|
|
351
|
-
client, timeout, insecure, throwOnFail: true,
|
|
351
|
+
client, timeout, insecure, actionAssistant, throwOnFail: true,
|
|
352
352
|
forceRefreshConfig: options.forceRefreshConfig,
|
|
353
353
|
skipVersionCheckOnConfigError: options.skipVersionCheckOnConfigError,
|
|
354
354
|
});
|
|
@@ -369,7 +369,7 @@ export function applyBuiltinOverrides() {
|
|
|
369
369
|
if (data.assignedTo === 'closed') {
|
|
370
370
|
throw new ZentaoError('E_INVALID_PARAM', { param: 'assignedTo', value: 'closed' });
|
|
371
371
|
}
|
|
372
|
-
return requestJSON({ request: command, body: data, bodyType, client, timeout, insecure, options });
|
|
372
|
+
return requestJSON({ request: command, body: data, bodyType, client, timeout, insecure, actionAssistant, options });
|
|
373
373
|
},
|
|
374
374
|
});
|
|
375
375
|
// 修改 acl 字段默认值为 open
|
package/dist/request/index.js
CHANGED
|
@@ -67,6 +67,7 @@ async function autoFillUpdateParams(module, action, params, options, version) {
|
|
|
67
67
|
client: options.client,
|
|
68
68
|
timeout: options.timeout,
|
|
69
69
|
insecure: options.insecure,
|
|
70
|
+
actionAssistant: options.actionAssistant,
|
|
70
71
|
throwOnFail: true,
|
|
71
72
|
}, version)).data;
|
|
72
73
|
if (!isRecord(current))
|
|
@@ -241,6 +242,7 @@ async function requestInternal(name, params, options, version) {
|
|
|
241
242
|
...preparedBody,
|
|
242
243
|
timeout: options.timeout ?? globals.timeout,
|
|
243
244
|
insecure: options.insecure ?? globals.insecure,
|
|
245
|
+
actionAssistant: options.actionAssistant !== undefined ? options.actionAssistant : globals.actionAssistant,
|
|
244
246
|
};
|
|
245
247
|
const raw = command.action.request
|
|
246
248
|
? await command.action.request({ request: command, ...requestOptions, client, options })
|
package/dist/types/client.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 操作辅助工具标记,对应 `ZenTao-Action-Assistant` 请求头。
|
|
3
|
+
* 字符串直接作为头值;对象去除字段首尾空白后序列化为 `name <info>`,没有详情时只发送名称。
|
|
4
|
+
* 对象名称不能为空,名称和详情不能包含尖括号或控制字符;最终头值仍须符合原生 Headers 的限制。
|
|
5
|
+
* 空字符串表示关闭标记;配置仅运行时有效,不保存到 profile。
|
|
6
|
+
*/
|
|
7
|
+
export type ActionAssistant = string | {
|
|
8
|
+
name: string;
|
|
9
|
+
info?: string;
|
|
10
|
+
};
|
|
1
11
|
/** 从本地 profile 恢复客户端时的选项。 */
|
|
2
12
|
export interface FromProfileOptions {
|
|
3
13
|
/** 是否切换为当前 profile 并更新使用时间,默认 true;false 时恢复过程只读存储。 */
|
|
@@ -9,6 +19,8 @@ export interface ZentaoClientOptions {
|
|
|
9
19
|
baseUrl: string;
|
|
10
20
|
/** 禅道 API Token;未提供时可稍后通过 {@link ZentaoClient.login} 获取并写入实例。 */
|
|
11
21
|
token?: string;
|
|
22
|
+
/** 默认操作辅助工具标记;优先级低于全局和单次请求配置,默认不发送。 */
|
|
23
|
+
actionAssistant?: ActionAssistant;
|
|
12
24
|
/** 默认请求超时时间,单位毫秒。 */
|
|
13
25
|
timeout?: number;
|
|
14
26
|
/** 是否跳过 TLS 证书验证;仅 Node.js 运行时支持,浏览器中会抛错。 */
|
|
@@ -30,8 +42,10 @@ export interface ClientRequestOptions {
|
|
|
30
42
|
bodyType?: ClientRequestBodyType;
|
|
31
43
|
/** 响应体解析方式。默认 `auto`,会优先尝试 JSON,失败后回落为文本;`response` 会让 signal 和 timeout 继续控制响应体。 */
|
|
32
44
|
responseType?: ClientResponseType;
|
|
33
|
-
/** 额外请求头;会与 SDK 自动注入的 `Token` / `Content-Type`
|
|
45
|
+
/** 额外请求头;会与 SDK 自动注入的 `Token` / `Content-Type` 合并,同名助手头优先于全局和客户端默认值。 */
|
|
34
46
|
headers?: HeadersInit;
|
|
47
|
+
/** 本次操作辅助工具标记;优先于 headers 中的同名头、全局和客户端默认值。undefined 表示继承,空字符串表示关闭。 */
|
|
48
|
+
actionAssistant?: ActionAssistant;
|
|
35
49
|
/** URL 查询参数;对象和数组使用 deepObject 风格序列化,`undefined` 值会被跳过。 */
|
|
36
50
|
query?: Record<string, unknown>;
|
|
37
51
|
/** 外部取消信号;会与 SDK 自身的超时控制合并。 */
|
package/dist/types/module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ZentaoClient } from '../client/index.js';
|
|
2
|
-
import type { ClientRequestBodyType, HttpMethod } from './client.js';
|
|
2
|
+
import type { ActionAssistant, ClientRequestBodyType, HttpMethod } from './client.js';
|
|
3
3
|
import type { RequestOptions, RequestProcessOptions } from './options.js';
|
|
4
4
|
import type { Pager } from './response.js';
|
|
5
5
|
/** 模块动作类型:基础 CRUD 或自定义动作。 */
|
|
@@ -110,6 +110,8 @@ export type ModuleActionRequestCallback = (info: {
|
|
|
110
110
|
timeout?: number;
|
|
111
111
|
/** 本次请求的 TLS 选项,未指定时回落到全局选项。 */
|
|
112
112
|
insecure?: boolean;
|
|
113
|
+
/** 操作辅助工具标记,未指定时回落到全局选项;需传给客户端及回调内部的后续请求。 */
|
|
114
|
+
actionAssistant?: ActionAssistant;
|
|
113
115
|
/** 本次调用选定的客户端。 */
|
|
114
116
|
client: ZentaoClient;
|
|
115
117
|
/** 调用方传入的原始请求选项。 */
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ZentaoClient } from '../client/index.js';
|
|
2
|
+
import type { ActionAssistant } from './client.js';
|
|
2
3
|
import type { ProcessListOptions, ProcessSingleOptions } from './data.js';
|
|
3
4
|
/** SDK 进程级全局默认选项,供高阶 {@link request} 调用复用。 */
|
|
4
5
|
export interface GlobalOptions {
|
|
@@ -8,6 +9,8 @@ export interface GlobalOptions {
|
|
|
8
9
|
skipVersionCheckOnConfigError?: boolean;
|
|
9
10
|
/** 默认客户端;通常由 `ZentaoClient.init()` 设置。 */
|
|
10
11
|
client?: ZentaoClient;
|
|
12
|
+
/** 默认操作辅助工具标记;覆盖客户端默认值,可被单次请求覆盖,空字符串表示关闭,不保存到 profile。 */
|
|
13
|
+
actionAssistant?: ActionAssistant;
|
|
11
14
|
/** 默认每页记录数,会映射到模块动作的 `recPerPage` 参数。 */
|
|
12
15
|
recPerPage?: string;
|
|
13
16
|
/** 默认限制返回列表数量,只影响 SDK 归一化后的 `data`。 */
|
|
@@ -35,6 +38,8 @@ export interface RequestOptions extends ProcessListOptions {
|
|
|
35
38
|
skipVersionCheckOnConfigError?: boolean;
|
|
36
39
|
/** 本次调用使用的客户端;优先级高于全局客户端。 */
|
|
37
40
|
client?: ZentaoClient;
|
|
41
|
+
/** 本次操作辅助工具标记;覆盖全局和客户端默认值,对象整体替换,undefined 表示继承,空字符串表示关闭。 */
|
|
42
|
+
actionAssistant?: ActionAssistant;
|
|
38
43
|
/** 本次调用使用的每页记录数,优先级高于全局 `recPerPage`。 */
|
|
39
44
|
recPerPage?: string;
|
|
40
45
|
/** 本次调用超时时间。 */
|
package/dist/version.js
CHANGED