zentao-api 0.8.4 → 0.9.0
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 +48 -2
- package/dist/browser/zentao-api.global.js +28 -28
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/misc/errors.d.ts +4 -0
- package/dist/misc/errors.js +4 -0
- package/dist/misc/zentao-version.d.ts +3 -0
- package/dist/misc/zentao-version.js +9 -0
- package/dist/modules/define.d.ts +1 -0
- package/dist/modules/define.js +3 -2
- package/dist/modules/generated.d.ts +402 -0
- package/dist/modules/generated.js +447 -55
- package/dist/modules/object-props.js +212 -36
- package/dist/modules/override.js +101 -9
- package/dist/modules/query.d.ts +2 -0
- package/dist/modules/query.js +6 -0
- package/dist/modules/registry-store.d.ts +4 -4
- package/dist/modules/registry-store.js +15 -8
- package/dist/modules/result-object-type.d.ts +7 -0
- package/dist/modules/result-object-type.js +35 -0
- package/dist/request/html-file-request.d.ts +34 -0
- package/dist/request/html-file-request.js +366 -0
- package/dist/request/html-files.d.ts +28 -0
- package/dist/request/html-files.js +139 -0
- package/dist/request/index.d.ts +3 -3
- package/dist/request/index.js +78 -26
- package/dist/request/prepare-body.d.ts +2 -0
- package/dist/request/prepare-body.js +2 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/link.d.ts +52 -0
- package/dist/types/link.js +1 -0
- package/dist/types/module.d.ts +18 -0
- package/dist/types/options.d.ts +7 -4
- package/dist/types/response.d.ts +16 -0
- package/dist/types/upload.d.ts +64 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/link.d.ts +30 -0
- package/dist/utils/link.js +225 -0
- package/dist/version.js +2 -2
- package/package.json +5 -2
package/dist/request/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { isZentaoConfigFetchError, ZentaoError } from '../misc/errors.js';
|
|
2
|
-
import {
|
|
2
|
+
import { assertSupportedVersion } from '../misc/zentao-version.js';
|
|
3
3
|
import { getGlobalOptions } from '../misc/global-options.js';
|
|
4
4
|
import { getModule, getModuleAction } from '../modules/registry.js';
|
|
5
5
|
import { extractPager, extractResult, resolveActionRequest } from '../modules/resolve.js';
|
|
6
6
|
import { isRecord, processData } from '../utils/index.js';
|
|
7
7
|
import { prepareActionBody } from './prepare-body.js';
|
|
8
|
+
import { resolveResultObjectType } from '../modules/result-object-type.js';
|
|
9
|
+
import { HtmlFileRequest, isFileWriteFailure, setFileUid } from './html-file-request.js';
|
|
8
10
|
/** 将 `moduleName`、`moduleName/methodName` 或 `moduleName/<objectID>` 请求名拆成模块名、动作名和对象 ID。 */
|
|
9
11
|
function splitRequestName(name) {
|
|
10
12
|
const parts = name.split('/');
|
|
@@ -75,6 +77,9 @@ async function autoFillUpdateParams(module, action, params, options, version) {
|
|
|
75
77
|
const explicitDataKeys = getExplicitDataKeys(params.data);
|
|
76
78
|
const filled = { ...params };
|
|
77
79
|
for (const key of Object.keys(properties)) {
|
|
80
|
+
// An upload uid identifies this save and must never be copied from a previous edit.
|
|
81
|
+
if (key === 'uid')
|
|
82
|
+
continue;
|
|
78
83
|
const userProvided = Object.prototype.hasOwnProperty.call(params, key) || explicitDataKeys.has(key);
|
|
79
84
|
if (!userProvided && Object.prototype.hasOwnProperty.call(current, key)) {
|
|
80
85
|
filled[key] = current[key];
|
|
@@ -120,6 +125,8 @@ function hasListProcessing(options) {
|
|
|
120
125
|
* - 其他形态原样返回。
|
|
121
126
|
*/
|
|
122
127
|
function applyProcessing(data, options) {
|
|
128
|
+
if (data instanceof ArrayBuffer)
|
|
129
|
+
return data;
|
|
123
130
|
if (Array.isArray(data)) {
|
|
124
131
|
if (!hasListProcessing(options))
|
|
125
132
|
return data;
|
|
@@ -143,13 +150,21 @@ function applyProcessing(data, options) {
|
|
|
143
150
|
}
|
|
144
151
|
return data;
|
|
145
152
|
}
|
|
153
|
+
function attachResultObjectType(response, command) {
|
|
154
|
+
if (response.status === 'success') {
|
|
155
|
+
const type = resolveResultObjectType(command.action.resultObjectType, command.params, response.data);
|
|
156
|
+
if (type !== undefined)
|
|
157
|
+
response.resultObjectType = type;
|
|
158
|
+
}
|
|
159
|
+
return response;
|
|
160
|
+
}
|
|
146
161
|
/** 将禅道原始响应归一化为稳定的 ResponseData 结构。 */
|
|
147
|
-
function normalizeResponse(command, raw, options) {
|
|
162
|
+
function normalizeResponse(command, raw, options, fileWrite) {
|
|
148
163
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
149
|
-
return { status: 'success', data: raw };
|
|
164
|
+
return attachResultObjectType({ status: 'success', data: raw }, command);
|
|
150
165
|
}
|
|
151
166
|
const record = raw;
|
|
152
|
-
const status = record.status === 'fail' ? 'fail' : 'success';
|
|
167
|
+
const status = (fileWrite ? isFileWriteFailure(record) : record.status === 'fail') ? 'fail' : 'success';
|
|
153
168
|
const data = applyProcessing(extractResult(command.action, record, command.params, options), options);
|
|
154
169
|
const rawMessage = record.message;
|
|
155
170
|
const pager = extractPager(command.action, record, command.params, options);
|
|
@@ -171,13 +186,13 @@ function normalizeResponse(command, raw, options) {
|
|
|
171
186
|
response.apiCode = apiCode;
|
|
172
187
|
if (status === 'fail')
|
|
173
188
|
response.raw = record;
|
|
174
|
-
return response;
|
|
189
|
+
return attachResultObjectType(response, command);
|
|
175
190
|
}
|
|
176
191
|
export async function request(name, params = {}, options = {}) {
|
|
177
192
|
return requestInternal(name, params, options);
|
|
178
193
|
}
|
|
179
194
|
/** version 为 undefined 时解析一次,null 表示本次调用已选择跳过版本检查。 */
|
|
180
|
-
async function requestInternal(name, params, options, version) {
|
|
195
|
+
async function requestInternal(name, params, options, version, processHtmlFiles = true, checkSession) {
|
|
181
196
|
const globals = getGlobalOptions();
|
|
182
197
|
const client = options.client ?? globals.client;
|
|
183
198
|
if (!client) {
|
|
@@ -221,13 +236,7 @@ async function requestInternal(name, params, options, version) {
|
|
|
221
236
|
}
|
|
222
237
|
}
|
|
223
238
|
}
|
|
224
|
-
|
|
225
|
-
throw new ZentaoError('E_UNSUPPORTED_ZENTAO_VERSION', {
|
|
226
|
-
action: `${module.name}/${action.name}`,
|
|
227
|
-
version,
|
|
228
|
-
minVersion: action.minVersion.join(', '),
|
|
229
|
-
}, { action: `${module.name}/${action.name}`, version, minVersion: action.minVersion });
|
|
230
|
-
}
|
|
239
|
+
assertSupportedVersion(version, action.minVersion, `${module.name}/${action.name}`);
|
|
231
240
|
const finalParams = action.type === 'update' && (options.autoFill ?? globals.autoFill)
|
|
232
241
|
? await autoFillUpdateParams(module, action, mergedParams, { ...options, client }, version)
|
|
233
242
|
: mergedParams;
|
|
@@ -235,28 +244,71 @@ async function requestInternal(name, params, options, version) {
|
|
|
235
244
|
if (command.action.beforeRequest) {
|
|
236
245
|
Object.assign(command, await command.action.beforeRequest(command));
|
|
237
246
|
}
|
|
238
|
-
const
|
|
239
|
-
maxUploadBytes: options.maxUploadBytes,
|
|
240
|
-
});
|
|
241
|
-
const requestOptions = {
|
|
242
|
-
...preparedBody,
|
|
247
|
+
const transportOptions = {
|
|
243
248
|
timeout: options.timeout ?? globals.timeout,
|
|
244
249
|
insecure: options.insecure ?? globals.insecure,
|
|
245
250
|
actionAssistant: options.actionAssistant !== undefined ? options.actionAssistant : globals.actionAssistant,
|
|
246
251
|
};
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
const method = String(command.action.method).toUpperCase();
|
|
253
|
+
const isWrite = method === 'POST' || method === 'PUT';
|
|
254
|
+
const isUpload = moduleName === 'file' && actionName === 'create';
|
|
255
|
+
const flatUid = isUpload && command.query?.uid !== undefined ? command.query.uid : command.params.uid;
|
|
256
|
+
const explicitUid = command.data?.uid !== undefined ? command.data.uid : flatUid;
|
|
257
|
+
const uid = isWrite && explicitUid !== undefined ? setFileUid(command, explicitUid, version) : undefined;
|
|
258
|
+
const files = processHtmlFiles && isWrite && !isUpload ? new HtmlFileRequest(command, {
|
|
259
|
+
client, version, ...transportOptions,
|
|
260
|
+
fileResolver: options.fileResolver ?? globals.fileResolver,
|
|
261
|
+
continueOnFileUploadError: options.continueOnFileUploadError ?? globals.continueOnFileUploadError,
|
|
262
|
+
onFileError: options.onFileError ?? globals.onFileError,
|
|
263
|
+
requestFile: async (action, params, fileSession) => {
|
|
264
|
+
const raw = await requestInternal(`file/${action}`, params, {
|
|
265
|
+
client, ...transportOptions, maxUploadBytes: options.maxUploadBytes,
|
|
266
|
+
raw: true, autoFill: false,
|
|
267
|
+
}, version, false, fileSession);
|
|
268
|
+
if (action === 'create' && (typeof raw === 'number' || typeof raw === 'string'))
|
|
269
|
+
return { id: raw };
|
|
270
|
+
const nested = isRecord(raw) && isRecord(raw.data) ? raw.data : undefined;
|
|
271
|
+
const deleteConfirmed = action !== 'delete' || (isRecord(raw) && (raw.status === 'success' || raw.result === 'success'));
|
|
272
|
+
if (!isRecord(raw) || !deleteConfirmed || isFileWriteFailure(raw) || (nested && isFileWriteFailure(nested))) {
|
|
273
|
+
const message = isRecord(raw) ? stringifyMessage(raw.message ?? nested?.message) : undefined;
|
|
274
|
+
throw new ZentaoError('E_API_FAILED', { message: message ?? `Invalid file/${action} response.` }, raw);
|
|
275
|
+
}
|
|
276
|
+
return raw;
|
|
277
|
+
},
|
|
278
|
+
}, uid) : undefined;
|
|
279
|
+
let preparedBody;
|
|
280
|
+
try {
|
|
281
|
+
await files?.prepare();
|
|
282
|
+
preparedBody = await prepareActionBody(command, { maxUploadBytes: options.maxUploadBytes });
|
|
283
|
+
(checkSession ?? files?.checkSession)?.();
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
await files?.cleanup();
|
|
287
|
+
throw files?.errorWithFiles(error) ?? error;
|
|
288
|
+
}
|
|
289
|
+
const requestOptions = { ...preparedBody, ...transportOptions };
|
|
290
|
+
let raw;
|
|
291
|
+
try {
|
|
292
|
+
raw = command.action.request
|
|
293
|
+
? await command.action.request({ request: command, ...requestOptions, client, options })
|
|
294
|
+
: await client.request(command.path, {
|
|
295
|
+
method,
|
|
296
|
+
query: command.query,
|
|
297
|
+
...requestOptions,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
throw files ? await files.saveError(error) : error;
|
|
302
|
+
}
|
|
303
|
+
await files?.complete(raw);
|
|
254
304
|
if (options.raw) {
|
|
255
305
|
return raw;
|
|
256
306
|
}
|
|
257
307
|
// limit 现归入本地处理选项;本次调用优先,缺省回落到全局默认。
|
|
258
308
|
const processOptions = { ...options, limit: options.limit ?? globals.limit };
|
|
259
|
-
const response = normalizeResponse(command, raw, processOptions);
|
|
309
|
+
const response = normalizeResponse(command, raw, processOptions, isUpload || (isWrite && command.data?.uid !== undefined));
|
|
310
|
+
if (files?.warnings.length)
|
|
311
|
+
response.fileWarnings = files.warnings;
|
|
260
312
|
if (response.status === 'fail' && (options.throwOnFail ?? globals.throwOnFail)) {
|
|
261
313
|
throw new ZentaoError('E_API_FAILED', { message: response.message ?? '' }, response);
|
|
262
314
|
}
|
|
@@ -8,5 +8,7 @@ export interface PreparedActionBody {
|
|
|
8
8
|
body: unknown;
|
|
9
9
|
bodyType?: ClientRequestBodyType;
|
|
10
10
|
}
|
|
11
|
+
export declare function inferExtension(contentType: string): string;
|
|
12
|
+
export declare function normalizeFilename(value: string | undefined, fallback: string, field: string): string;
|
|
11
13
|
/** 根据模块动作的媒体类型,把解析后的普通请求体转换为底层客户端可发送的请求体。 */
|
|
12
14
|
export declare function prepareActionBody(command: ModuleActionRequest, options?: PrepareActionBodyOptions): Promise<PreparedActionBody>;
|
|
@@ -38,7 +38,7 @@ function inferContentType(filename) {
|
|
|
38
38
|
const dotIndex = normalized.lastIndexOf('.');
|
|
39
39
|
return dotIndex >= 0 ? MIME_TYPES[normalized.slice(dotIndex)] ?? 'application/octet-stream' : 'application/octet-stream';
|
|
40
40
|
}
|
|
41
|
-
function inferExtension(contentType) {
|
|
41
|
+
export function inferExtension(contentType) {
|
|
42
42
|
const normalized = contentType.split(';', 1)[0]?.trim().toLowerCase();
|
|
43
43
|
const entry = Object.entries(MIME_TYPES).find(([, type]) => type === normalized);
|
|
44
44
|
return entry?.[0] ?? '.bin';
|
|
@@ -56,7 +56,7 @@ function assertUploadSize(size, limit) {
|
|
|
56
56
|
throw new ZentaoError('E_UPLOAD_FILE_TOO_LARGE', { size, limit });
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
function normalizeFilename(value, fallback, field) {
|
|
59
|
+
export function normalizeFilename(value, fallback, field) {
|
|
60
60
|
const requested = value?.trim() || fallback.trim();
|
|
61
61
|
const filename = requested.split(/[\\/]/).at(-1)?.trim() ?? '';
|
|
62
62
|
if (!filename) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* - `response.ts` — 禅道 API 响应与归一化结果类型。
|
|
7
7
|
* - `options.ts` — 进程级全局选项与高阶 `request()` 选项。
|
|
8
8
|
* - `profile.ts` — 本地持久化 profile 类型。
|
|
9
|
+
* - `link.ts` — 禅道页面链接生成与解析类型。
|
|
9
10
|
* - `data.ts` — 本地数据处理(过滤 / 搜索 / 排序 / 摘取)类型。
|
|
10
11
|
* - `module.ts` — 模块 / 动作注册表与命令解析类型。
|
|
11
12
|
*/
|
|
@@ -13,6 +14,7 @@ export * from './client.js';
|
|
|
13
14
|
export * from './response.js';
|
|
14
15
|
export * from './options.js';
|
|
15
16
|
export * from './profile.js';
|
|
17
|
+
export * from './link.js';
|
|
16
18
|
export * from './data.js';
|
|
17
19
|
export * from './module.js';
|
|
18
20
|
export * from './upload.js';
|
package/dist/types/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* - `response.ts` — 禅道 API 响应与归一化结果类型。
|
|
7
7
|
* - `options.ts` — 进程级全局选项与高阶 `request()` 选项。
|
|
8
8
|
* - `profile.ts` — 本地持久化 profile 类型。
|
|
9
|
+
* - `link.ts` — 禅道页面链接生成与解析类型。
|
|
9
10
|
* - `data.ts` — 本地数据处理(过滤 / 搜索 / 排序 / 摘取)类型。
|
|
10
11
|
* - `module.ts` — 模块 / 动作注册表与命令解析类型。
|
|
11
12
|
*/
|
|
@@ -13,6 +14,7 @@ export * from './client.js';
|
|
|
13
14
|
export * from './response.js';
|
|
14
15
|
export * from './options.js';
|
|
15
16
|
export * from './profile.js';
|
|
17
|
+
export * from './link.js';
|
|
16
18
|
export * from './data.js';
|
|
17
19
|
export * from './module.js';
|
|
18
20
|
export * from './upload.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ZentaoProfile } from './profile.js';
|
|
2
|
+
/** 链接处理只使用站点地址与服务器配置,无需账号或 Token。 */
|
|
3
|
+
export type LinkProfile = Pick<ZentaoProfile, 'server' | 'serverConfig'>;
|
|
4
|
+
/** 禅道页面路由模式。 */
|
|
5
|
+
export type LinkRequestType = 'GET' | 'PATH_INFO' | 'PATH_INFO2';
|
|
6
|
+
/** 创建禅道页面链接的参数。参数名和参数值由调用方按需 URL 编码,SDK 不二次编码。 */
|
|
7
|
+
export interface CreateLinkOptions {
|
|
8
|
+
/** 页面模块名,例如 `bug`。 */
|
|
9
|
+
moduleName: string;
|
|
10
|
+
/** 页面方法名,例如 `view`。 */
|
|
11
|
+
methodName: string;
|
|
12
|
+
/** 方法参数,支持 `bugID=1&from=list`、字符串数组或键值对数组;路径模式按顺序使用值。 */
|
|
13
|
+
vars?: string | readonly string[] | readonly (readonly [string, string])[];
|
|
14
|
+
/** 视图类型;默认使用服务器的 `defaultView`,未配置时为 `html`。 */
|
|
15
|
+
viewType?: string;
|
|
16
|
+
/** 锚点,可带前导 `#`;空字符串会添加结尾的 `#`。 */
|
|
17
|
+
hash?: string;
|
|
18
|
+
/** 始终追加到查询字符串的参数;跳过 `$` 开头的键,null/undefined 转为空值。 */
|
|
19
|
+
params?: Record<string, unknown>;
|
|
20
|
+
/** 返回以 `/` 开头的站内路径;优先于全局 relative,均未设置时为 false(完整网址)。 */
|
|
21
|
+
relative?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** 解析禅道页面链接的选项。 */
|
|
24
|
+
export interface ParseLinkOptions {
|
|
25
|
+
/** 默认使用服务器配置;`auto` 优先识别入口和路径路由,仅在站点根路径用查询参数识别 GET。 */
|
|
26
|
+
requestType?: LinkRequestType | 'auto';
|
|
27
|
+
}
|
|
28
|
+
/** 解析得到的禅道链接;空输入和外链仅返回 url 及必要的 external 标记。 */
|
|
29
|
+
export interface ZentaoLink {
|
|
30
|
+
/** 相对链接保留输入;站内完整网址转换为站内路径;外链保留输入。 */
|
|
31
|
+
url?: string;
|
|
32
|
+
/** 页面模块名,缺省为 `index`。 */
|
|
33
|
+
moduleName?: string;
|
|
34
|
+
/** 页面方法名,缺省为 `index`。 */
|
|
35
|
+
methodName?: string;
|
|
36
|
+
/** 是否位于其他 origin,或当前安装目录和显式配置的入口路径之外。 */
|
|
37
|
+
external?: boolean;
|
|
38
|
+
/** 查询参数 `onlybody` 是否为 `yes`。 */
|
|
39
|
+
isOnlyBody?: boolean;
|
|
40
|
+
/** 方法参数;GET 值已解码,路径值保留编码且参数名为空字符串。 */
|
|
41
|
+
vars?: [string, string][];
|
|
42
|
+
/** 不含前导 `#` 的锚点,保留编码。 */
|
|
43
|
+
hash?: string;
|
|
44
|
+
/** 已解码的查询参数,同名值以逗号连接;路径参数另存为 `$1`、`$2` 等,保留编码。 */
|
|
45
|
+
params?: Record<string, string>;
|
|
46
|
+
/** 查询参数 `tid`,缺省为空字符串。 */
|
|
47
|
+
tid?: string;
|
|
48
|
+
/** 视图类型。 */
|
|
49
|
+
viewType?: string;
|
|
50
|
+
/** 实际采用的路由模式。 */
|
|
51
|
+
requestType?: LinkRequestType;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/module.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface ModuleActionParam {
|
|
|
29
29
|
defaultValue?: unknown;
|
|
30
30
|
/** 参数值类型,用于基础类型转换。 */
|
|
31
31
|
type?: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
32
|
+
/** 文本内容格式。 */
|
|
33
|
+
textType?: 'text' | 'html' | 'markdown';
|
|
32
34
|
/** OpenAPI schema format,例如 `binary` 或 `int32`。 */
|
|
33
35
|
format?: string;
|
|
34
36
|
/** OpenAPI 查询参数序列化样式,例如 `deepObject`。 */
|
|
@@ -40,6 +42,16 @@ export interface ModuleActionParam {
|
|
|
40
42
|
}
|
|
41
43
|
/** 模块动作结果形态。 */
|
|
42
44
|
export type ModuleActionResultType = 'text' | 'object' | 'list';
|
|
45
|
+
/**
|
|
46
|
+
* 返回业务对象的 SDK 资源类型,或从调用参数读取类型的可序列化规则。
|
|
47
|
+
* `null` 表示没有统一对象类型;类型名称不要求是已注册的模块名。
|
|
48
|
+
*/
|
|
49
|
+
export type ModuleActionResultObjectType = string | {
|
|
50
|
+
/** 从 `beforeRequest` 执行后的 `params[param]` 读取非空字符串。 */
|
|
51
|
+
readonly param: string;
|
|
52
|
+
/** 参数值到 SDK 类型名的映射;未命中时保留原值。 */
|
|
53
|
+
readonly map?: Readonly<Record<string, string>>;
|
|
54
|
+
} | null;
|
|
43
55
|
/** 列表分页信息别名。 */
|
|
44
56
|
export type ListPagerInfo = Pager;
|
|
45
57
|
/** 高阶请求支持的请求体媒体类型。 */
|
|
@@ -149,6 +161,12 @@ export interface ModuleAction {
|
|
|
149
161
|
* 当 `type` 无法推导出结果形态时抛出 `E_INDETERMINATE_ACTION_RESULT_TYPE`。
|
|
150
162
|
*/
|
|
151
163
|
resultType?: ModuleActionResultType;
|
|
164
|
+
/**
|
|
165
|
+
* 返回的业务对象类型。省略时,`object` / `list` 在注册时补齐为所属模块名,其他形态补齐为 `null`。
|
|
166
|
+
* 显式 `null` 禁用默认推导,适用于状态响应、混合列表或没有业务对象的结果。
|
|
167
|
+
* 返回实体或 `{id}` 的动作可声明类型,包括 `resultType: 'text'` 的动作。
|
|
168
|
+
*/
|
|
169
|
+
resultObjectType?: ModuleActionResultObjectType;
|
|
152
170
|
/**
|
|
153
171
|
* 从原始响应中提取分页信息的位置或函数:
|
|
154
172
|
* 字符串为字段路径(支持 `a.b` 嵌套)、对象为字段映射、函数则接收原始响应与调用参数。
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ZentaoClient } from '../client/index.js';
|
|
2
2
|
import type { ActionAssistant } from './client.js';
|
|
3
3
|
import type { ProcessListOptions, ProcessSingleOptions } from './data.js';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import type { FileHandlingOptions } from './upload.js';
|
|
5
|
+
/** SDK 进程级全局默认选项,供请求和 {@link createLink} 等辅助方法复用。 */
|
|
6
|
+
export interface GlobalOptions extends FileHandlingOptions {
|
|
6
7
|
/** 当前禅道正式版本,例如 `biz13.5`;普通高阶请求直接使用,单次强制刷新时使用实际版本。不会自动写入 profile。 */
|
|
7
8
|
version?: string;
|
|
8
9
|
/** 配置网络或响应获取失败时,允许登录继续或高阶请求跳过版本检查,默认 false;不忽略版本不匹配、格式错误或存储错误。 */
|
|
@@ -15,6 +16,8 @@ export interface GlobalOptions {
|
|
|
15
16
|
recPerPage?: string;
|
|
16
17
|
/** 默认限制返回列表数量,只影响 SDK 归一化后的 `data`。 */
|
|
17
18
|
limit?: string;
|
|
19
|
+
/** createLink 默认返回站内路径;单次调用的 relative 优先,默认 false(完整网址)。 */
|
|
20
|
+
relative?: boolean;
|
|
18
21
|
/** 默认请求超时时间,优先级低于单次请求选项。 */
|
|
19
22
|
timeout?: number;
|
|
20
23
|
/** 默认 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
|
|
@@ -26,12 +29,12 @@ export interface GlobalOptions {
|
|
|
26
29
|
/**
|
|
27
30
|
* 是否在执行 `update` 操作时自动填充未传入的字段,默认 false。
|
|
28
31
|
*
|
|
29
|
-
* 优先级低于单次请求选项;语义见 {@link RequestOptions
|
|
32
|
+
* 优先级低于单次请求选项;语义见 {@link RequestOptions#autoFill}。
|
|
30
33
|
*/
|
|
31
34
|
autoFill?: boolean;
|
|
32
35
|
}
|
|
33
36
|
/** 高阶 `request("moduleName")` / `request("moduleName/methodName")` / `request("moduleName/<objectID>")` 的单次调用选项。 */
|
|
34
|
-
export interface RequestOptions extends ProcessListOptions {
|
|
37
|
+
export interface RequestOptions extends ProcessListOptions, FileHandlingOptions {
|
|
35
38
|
/** 强制刷新服务器配置并用实际版本校验本次请求,优先于全局 version;不会改写全局版本。 */
|
|
36
39
|
forceRefreshConfig?: boolean;
|
|
37
40
|
/** 配置网络或响应获取失败时跳过本次版本检查;优先于全局设置,默认 false,不忽略版本不匹配或格式错误。 */
|
package/dist/types/response.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FileWarning } from './upload.js';
|
|
1
2
|
/** 高阶 `request()` 归一化后的返回数据。 */
|
|
2
3
|
export interface ResponseData<T = unknown> {
|
|
3
4
|
/** 禅道服务端状态;非标准响应会按成功响应包装到 `data`。 */
|
|
@@ -12,6 +13,13 @@ export interface ResponseData<T = unknown> {
|
|
|
12
13
|
raw?: Record<string, unknown>;
|
|
13
14
|
/** 根据模块动作 `resultGetter` 提取后的业务数据。 */
|
|
14
15
|
data?: T;
|
|
16
|
+
/**
|
|
17
|
+
* 成功返回对象或列表时,按 action 声明和最终调用参数解析的 SDK 资源类型;空列表也保留类型。
|
|
18
|
+
* 无统一类型、参数无法解析或失败时省略。类型不随本地筛选、摘取和转换改变。
|
|
19
|
+
*/
|
|
20
|
+
resultObjectType?: string;
|
|
21
|
+
/** 富文本图片解析、上传或清理时产生的警告。 */
|
|
22
|
+
fileWarnings?: FileWarning[];
|
|
15
23
|
/** 统一分页信息。 */
|
|
16
24
|
pager?: {
|
|
17
25
|
/** 总记录数。 */
|
|
@@ -74,6 +82,14 @@ export interface ServerConfig {
|
|
|
74
82
|
methodVar: string;
|
|
75
83
|
viewVar: string;
|
|
76
84
|
sessionVar: string;
|
|
85
|
+
/** 页面根路径,例如 `/zentao/`;链接辅助方法默认从 profile.server 推导。 */
|
|
86
|
+
webRoot?: string;
|
|
87
|
+
/** GET / PATH_INFO2 页面入口路径;默认使用页面根路径下的 `index.php`。 */
|
|
88
|
+
router?: string;
|
|
89
|
+
/** 页面默认视图;链接辅助方法默认使用 `html`。 */
|
|
90
|
+
defaultView?: string;
|
|
91
|
+
/** 可选实例路径,链接辅助方法会避免重复添加已有的实例后缀。 */
|
|
92
|
+
instCode?: string;
|
|
77
93
|
/** 保留服务端返回的其他配置字段。 */
|
|
78
94
|
[key: string]: unknown;
|
|
79
95
|
}
|
package/dist/types/upload.d.ts
CHANGED
|
@@ -27,8 +27,12 @@ export type FileUploadSource = string | Blob | FileUploadPathInput | FileUploadD
|
|
|
27
27
|
/** `request("file/create")` 的参数。 */
|
|
28
28
|
export type FileCreateParams = Record<string, unknown> & {
|
|
29
29
|
file: FileUploadSource;
|
|
30
|
-
objectType
|
|
31
|
-
objectID
|
|
30
|
+
objectType?: 'bug' | 'story' | 'task' | 'testcase' | (string & {});
|
|
31
|
+
objectID?: number;
|
|
32
|
+
/** 上传批次。保存同一对象时在 JSON 体中携带相同 uid,并使用同一个 Token。 */
|
|
33
|
+
uid?: string;
|
|
34
|
+
/** 附件标记,默认 editor(文档编辑器图片),23.0 / biz14.0 / max9.0 / ipd6.0 起支持;显式空字符串用于普通附件,其他值由服务端按空字符串处理。 */
|
|
35
|
+
extra?: string;
|
|
32
36
|
};
|
|
33
37
|
/** `request("file/create")` 归一化后的结果。 */
|
|
34
38
|
export interface FileCreateResult {
|
|
@@ -36,3 +40,61 @@ export interface FileCreateResult {
|
|
|
36
40
|
url?: string;
|
|
37
41
|
[key: string]: unknown;
|
|
38
42
|
}
|
|
43
|
+
/** HTML 图片中的文件引用;路径和名称已解码 HTML 实体。 */
|
|
44
|
+
export interface FileReference {
|
|
45
|
+
/** 图片 src 中的原始路径。 */
|
|
46
|
+
path: string;
|
|
47
|
+
/** 从 alt 或来源路径提取的文件名。 */
|
|
48
|
+
name?: string;
|
|
49
|
+
}
|
|
50
|
+
/** 文件解析器返回的来源;字符串表示路径,未指定名称时沿用输入名称。 */
|
|
51
|
+
export type ResolvedFile = string | {
|
|
52
|
+
path: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
} | {
|
|
55
|
+
blob: Blob;
|
|
56
|
+
name?: string;
|
|
57
|
+
} | {
|
|
58
|
+
url: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* HTML 图片解析器。函数可异步执行;映射依次按路径和文件名查找自身属性。
|
|
63
|
+
* 映射的字符串值以命中的 key 为文件名。未命中、抛错或返回无效来源时终止请求。
|
|
64
|
+
*/
|
|
65
|
+
export type FileResolver = ((reference: FileReference) => ResolvedFile | Promise<ResolvedFile>) | Record<string, ResolvedFile>;
|
|
66
|
+
/** 富文本图片处理中的错误上下文。 */
|
|
67
|
+
export interface FileWarning {
|
|
68
|
+
/** 图片解析、上传或清理阶段。 */
|
|
69
|
+
stage: 'resolve' | 'upload' | 'cleanup';
|
|
70
|
+
/** SDK 或服务端错误码。 */
|
|
71
|
+
code: string;
|
|
72
|
+
/** 可读错误消息。 */
|
|
73
|
+
message: string;
|
|
74
|
+
/** HTML body 字段名。 */
|
|
75
|
+
field?: string;
|
|
76
|
+
/** 原始文件引用路径。 */
|
|
77
|
+
path?: string;
|
|
78
|
+
/** 文件名。 */
|
|
79
|
+
name?: string;
|
|
80
|
+
/** 本次上传产生的禅道文件 ID。 */
|
|
81
|
+
fileID?: number;
|
|
82
|
+
/** 本次对象保存的上传批次。 */
|
|
83
|
+
uid?: string;
|
|
84
|
+
/** 文件应关联的对象类型。 */
|
|
85
|
+
objectType?: string;
|
|
86
|
+
/** 文件应关联的对象 ID。 */
|
|
87
|
+
objectID?: number;
|
|
88
|
+
}
|
|
89
|
+
/** 高阶请求的 HTML 图片处理配置;单次请求优先于全局选项。 */
|
|
90
|
+
export interface FileHandlingOptions {
|
|
91
|
+
/** 解析本地及自定义文件引用;HTTP(S) 和已有禅道文件链接直接保留。 */
|
|
92
|
+
fileResolver?: FileResolver;
|
|
93
|
+
/** 上传或读取本地文件失败后是否标注 HTML 并继续主请求,默认 true;解析器失败始终终止。 */
|
|
94
|
+
continueOnFileUploadError?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* 文件错误通知;支持异步回调,回调异常不改变主请求结果。
|
|
97
|
+
* 普通响应同时提供 fileWarnings;raw 模式仅通过此回调通知,不修改原始响应。
|
|
98
|
+
*/
|
|
99
|
+
onFileError?: (warning: FileWarning) => void | Promise<void>;
|
|
100
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { isRecord, isBlank, getNestedValue } from './object.js';
|
|
2
2
|
export { asArray } from './array.js';
|
|
3
3
|
export { normalizeSiteUrl } from './url.js';
|
|
4
|
+
export { createLink, parseLink } from './link.js';
|
|
4
5
|
export { pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './data.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { isRecord, isBlank, getNestedValue } from './object.js';
|
|
2
2
|
export { asArray } from './array.js';
|
|
3
3
|
export { normalizeSiteUrl } from './url.js';
|
|
4
|
+
export { createLink, parseLink } from './link.js';
|
|
4
5
|
export { pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './data.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CreateLinkOptions, LinkProfile, ParseLinkOptions, ZentaoLink } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* 根据 profile 的服务器配置创建禅道页面链接,同步执行且不访问存储或网络。
|
|
4
|
+
*
|
|
5
|
+
* 支持 GET、PATH_INFO、PATH_INFO2。`relative` 优先级为单次选项 > 全局选项 > false(完整网址);true 返回站内路径。
|
|
6
|
+
* `vars` 和 `params` 沿用页面 helper 的约定:调用方按需编码,SDK 不二次编码;不修改输入。
|
|
7
|
+
*
|
|
8
|
+
* @param profile - 使用 server 与 serverConfig,无需账号或 Token。
|
|
9
|
+
* @param options - 页面模块、方法、参数与输出选项。
|
|
10
|
+
* @returns 完整网址或站内路径。
|
|
11
|
+
* @throws {ZentaoError} `E_MISSING_PARAM`(缺少必要路由配置或页面参数)、
|
|
12
|
+
* `E_INVALID_PARAM`(不支持的路由模式或非法配置路径)、`E_INVALID_BASE_URL`。
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLink(profile: LinkProfile, options: CreateLinkOptions): string;
|
|
15
|
+
/**
|
|
16
|
+
* 解析禅道页面链接,同步执行且不读取浏览器当前位置、存储或网络。
|
|
17
|
+
*
|
|
18
|
+
* 相对链接以 profile 的页面根路径为基准;同源页面目录和显式配置的入口路径属于内部链接。
|
|
19
|
+
* 其他 origin、这些路径之外及非 HTTP(S) 链接标记为外链。
|
|
20
|
+
* 默认使用 serverConfig.requestType,`requestType: 'auto'` 根据路由参数与入口路径识别。
|
|
21
|
+
* GET 查询值会解码,同名值以逗号合并;路径变量保留编码并附加到 params 的 `$1`、`$2` 等键。
|
|
22
|
+
*
|
|
23
|
+
* @param profile - 使用 server 与 serverConfig,无需账号或 Token。
|
|
24
|
+
* @param url - 完整网址或相对链接;空输入直接返回 `{ url }`。
|
|
25
|
+
* @param options - 可覆盖路由模式或启用自动识别。
|
|
26
|
+
* @returns 链接信息;外链仅包含原 url 和 external 标记。
|
|
27
|
+
* @throws {ZentaoError} `E_MISSING_PARAM`(缺少必要路由配置)、`E_INVALID_PARAM`
|
|
28
|
+
* (不支持的路由模式或非法 URL/配置路径)、`E_INVALID_BASE_URL`。
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseLink(profile: LinkProfile, url?: string, options?: ParseLinkOptions): ZentaoLink;
|