zentao-api 0.3.1 → 0.3.3

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.
@@ -1,359 +1,17 @@
1
- import type { ZentaoClient } from '../client/index.js';
2
- /** 创建 {@link ZentaoClient} 时使用的配置。 */
3
- export interface ZentaoClientOptions {
4
- /** 禅道站点根地址,例如 `https://zentao.example.com`;SDK 会自动拼接 `/api.php/v2`。 */
5
- baseUrl: string;
6
- /** 禅道 API Token;未提供时可稍后通过 {@link ZentaoClient.login} 获取并写入实例。 */
7
- token?: string;
8
- /** 默认请求超时时间,单位毫秒。 */
9
- timeout?: number;
10
- /** 是否跳过 TLS 证书验证;仅 Node.js 运行时支持,浏览器中会抛错。 */
11
- insecure?: boolean;
12
- }
13
- /** SDK 进程级全局默认选项,供高阶 {@link request} 调用复用。 */
14
- export interface GlobalOptions {
15
- /** 默认客户端;通常由 `ZentaoClient.init()` 设置。 */
16
- client?: ZentaoClient;
17
- /** 默认每页记录数,会映射到模块动作的 `recPerPage` 参数。 */
18
- recPerPage?: string;
19
- /** 默认限制返回列表数量,只影响 SDK 归一化后的 `data`。 */
20
- limit?: string;
21
- /** 默认请求超时时间,优先级低于单次请求选项。 */
22
- timeout?: number;
23
- /** 默认 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
24
- insecure?: boolean;
25
- /** 是否在登录成功后把账号、Token 和配置持久化为本地 profile。 */
26
- persistProfiles?: boolean;
27
- /** 当禅道服务端返回 `{ status: "fail" }` 时是否抛出 `E_API_FAILED`,默认 false。 */
28
- throwOnFail?: boolean;
29
- }
30
- /** SDK 支持的 HTTP 方法。 */
31
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
32
- /** 请求体序列化方式。 */
33
- export type ClientRequestBodyType = 'json' | 'form' | 'raw';
34
- /** 响应体解析方式。 */
35
- export type ClientResponseType = 'auto' | 'json' | 'text' | 'arrayBuffer' | 'blob' | 'response';
36
- /** `ZentaoClient.request()` 的单次请求选项。 */
37
- export interface ClientRequestOptions {
38
- /** HTTP 方法,默认 `GET`。 */
39
- method?: HttpMethod;
40
- /** 请求体;`GET` 请求会忽略该字段。普通对象默认按 JSON 发送,`FormData` / `Blob` / `ArrayBuffer` 等会原样发送。 */
41
- body?: unknown;
42
- /** 请求体序列化方式。默认 `json`;传入 `FormData` 等原生 body 时会自动按 `raw` 处理。 */
43
- bodyType?: ClientRequestBodyType;
44
- /** 响应体解析方式。默认 `auto`,会优先尝试 JSON,失败后回落为文本。 */
45
- responseType?: ClientResponseType;
46
- /** 额外请求头;会与 SDK 自动注入的 `Token` / `Content-Type` 合并。 */
47
- headers?: HeadersInit;
48
- /** URL 查询参数;`undefined` 值会被跳过。 */
49
- query?: Record<string, string | number | boolean | undefined>;
50
- /** 外部取消信号;会与 SDK 自身的超时控制合并。 */
51
- signal?: AbortSignal;
52
- /** 单次请求超时时间,优先级高于全局和客户端默认值。 */
53
- timeout?: number;
54
- /** 单次请求 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
55
- insecure?: boolean;
56
- }
57
- /** 高阶 `request("moduleName")` / `request("moduleName/methodName")` / `request("moduleName/<objectID>")` 的单次调用选项。 */
58
- export interface RequestOptions extends ProcessListOptions {
59
- /** 本次调用使用的客户端;优先级高于全局客户端。 */
60
- client?: ZentaoClient;
61
- /** 本次调用使用的每页记录数,优先级高于全局 `recPerPage`。 */
62
- recPerPage?: string;
63
- /** 本次调用超时时间。 */
64
- timeout?: number;
65
- /** 本次调用 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
66
- insecure?: boolean;
67
- /**
68
- * 当禅道服务端返回 `{ status: "fail" }` 时是否抛出 `E_API_FAILED`。
69
- * 不传时回落到全局 `throwOnFail`,默认 false(保留原始失败响应)。
70
- */
71
- throwOnFail?: boolean;
72
- }
73
- /** 高阶 `request()` 归一化后的返回数据。 */
74
- export interface ResponseData<T = unknown> {
75
- /** 禅道服务端状态;非标准响应会按成功响应包装到 `data`。 */
76
- status: 'success' | 'fail';
77
- /** 禅道服务端返回的消息。 */
78
- message?: string;
79
- /** 原始消息字段;当服务端返回对象/数组等非字符串消息时保留在这里。 */
80
- rawMessage?: unknown;
81
- /** 服务端返回的业务错误码或状态码字段。 */
82
- apiCode?: string | number;
83
- /** 失败响应的原始对象,便于上层展示服务端返回的完整上下文。 */
84
- raw?: Record<string, unknown>;
85
- /** 根据模块动作 `resultGetter` 提取后的业务数据。 */
86
- data?: T;
87
- /** 统一分页信息。 */
88
- pager?: {
89
- /** 总记录数。 */
90
- total: number;
91
- /** 当前页码。 */
92
- page: number;
93
- /** 每页记录数。 */
94
- recPerPage: number;
95
- };
96
- }
97
- /** 禅道 API 原始分页结构。 */
98
- export interface Pager {
99
- /** 总记录数。 */
100
- recTotal: number;
101
- /** 每页记录数。 */
102
- recPerPage: number;
103
- /** 总页数,部分接口不返回。 */
104
- pageTotal?: number;
105
- /** 当前页码。 */
106
- pageID: number;
107
- }
108
- /** 禅道 API 通用响应结构,允许携带任意业务字段。 */
109
- export interface ApiResponse {
110
- /** 服务端返回状态。 */
111
- status: 'success' | 'fail';
112
- /** 服务端消息,可能是字符串、对象或数组。 */
113
- message?: unknown;
114
- /** 其他业务字段。 */
115
- [key: string]: unknown;
116
- }
117
- /** 禅道 API 列表响应结构。 */
118
- export interface ApiListResponse extends ApiResponse {
119
- /** 原始分页信息。 */
120
- pager?: Pager;
121
- }
122
- /** 登录接口响应结构。 */
123
- export interface LoginResponse extends ApiResponse {
124
- /** 登录成功后返回的 API Token。 */
125
- token?: string;
126
- /** 部分禅道环境会随登录响应返回用户信息。 */
127
- user?: Record<string, unknown>;
128
- /** 部分禅道环境会随登录响应返回服务端配置。 */
129
- serverConfig?: ServerConfig;
130
- }
131
- /** 禅道 `?mode=getconfig` 返回的服务端配置。 */
132
- export interface ServerConfig {
133
- version: string;
134
- systemMode: string;
135
- sprintConcept: string;
136
- requestType: string;
137
- requestFix: string;
138
- moduleVar: string;
139
- methodVar: string;
140
- viewVar: string;
141
- sessionVar: string;
142
- }
143
- /** 保存到本地 profile 中的客户端偏好配置。 */
144
- export interface ZentaoProfileConfig {
145
- /** 默认输出格式,供 CLI 等上层应用复用。 */
146
- defaultOutputFormat?: 'markdown' | 'json' | 'raw';
147
- /** 界面语言。 */
148
- lang?: string;
149
- /** 默认分页大小。 */
150
- defaultRecPerPage?: number;
151
- /** 是否跳过 TLS 证书验证;仅 Node.js 运行时支持。 */
152
- insecure?: boolean;
153
- /** 请求超时时间,单位毫秒。 */
154
- timeout?: number;
155
- /** 是否在批量操作出错时停止执行后续操作。 */
156
- batchFailFast?: boolean;
157
- /** JSON 格式化时是否添加缩进。 */
158
- jsonPretty?: boolean;
159
- /** 模块级分页偏好。 */
160
- pagers?: Record<string, number>;
161
- /** 允许上层应用保存自定义配置。 */
162
- [key: string]: unknown;
163
- }
164
- /** 本地持久化的禅道账号 profile。 */
165
- export interface ZentaoProfile {
166
- /** 禅道站点根地址,不包含 `/api.php/v2`。 */
167
- server: string;
168
- /** 用户账号。 */
169
- account: string;
170
- /** 禅道 API Token。 */
171
- token: string;
172
- /** 登录验证通过后得到的用户信息。 */
173
- user?: Record<string, unknown>;
174
- /** 登录时间。 */
175
- loginTime?: string;
176
- /** 最后使用时间。 */
177
- lastUsedTime?: string;
178
- /** 禅道服务端配置。 */
179
- serverConfig?: ServerConfig;
180
- /** 客户端自定义配置。 */
181
- config?: ZentaoProfileConfig;
182
- /** 允许上层应用保存额外字段。 */
183
- [key: string]: unknown;
184
- }
185
- /** 运行时返回的 profile,会额外带上 `account@server` 形式的 key。 */
186
- export interface ZentaoProfileRecord extends ZentaoProfile {
187
- key: string;
188
- }
189
- /** 本地 profile 存储文件或浏览器 localStorage 中的 JSON 结构。 */
190
- export interface ZentaoProfilesStore {
191
- /** 当前使用的 profile key。 */
192
- currentProfile?: string;
193
- /** 保存的 profile 列表。 */
194
- profiles: ZentaoProfile[];
195
- }
196
- /** 模块动作类型:基础 CRUD 或自定义动作。 */
197
- export type ModuleActionType = 'list' | 'get' | 'create' | 'update' | 'delete' | 'action';
198
- /** 模块动作使用的 HTTP 方法;兼容生成定义中的小写方法。 */
199
- export type ModuleActionMethod = HttpMethod | Lowercase<HttpMethod>;
200
- /** 模块动作名称,允许除基础动作外的自定义名称。 */
201
- export type ModuleActionName = ModuleActionType | (string & {});
202
- /** 模块动作参数可选项。 */
203
- export type ModuleActionParamOption = {
204
- readonly value: unknown;
205
- readonly label: string;
206
- };
207
- /** 模块动作的查询参数定义。 */
208
- export interface ModuleActionParam {
209
- /** 参数名称。 */
210
- name: string;
211
- /** 参数说明。 */
212
- description?: string;
213
- /** 是否必填。 */
214
- required?: boolean;
215
- /** 未显式传入时使用的默认值。 */
216
- defaultValue?: unknown;
217
- /** 参数值类型,用于基础类型转换。 */
218
- type?: 'string' | 'number' | 'boolean';
219
- /** 参数可选值。 */
220
- options?: readonly ModuleActionParamOption[];
221
- }
222
- /** 模块动作结果形态。 */
223
- export type ModuleActionResultType = 'text' | 'object' | 'list';
224
- /** 列表分页信息别名。 */
225
- export type ListPagerInfo = Pager;
226
- /** 模块动作请求体定义。 */
227
- export interface ModuleActionRequestBody {
228
- /** 请求体类型。 */
229
- type?: 'object' | 'string';
230
- /** 请求体是否必填。 */
231
- required?: boolean;
232
- /** OpenAPI 风格 schema,用于从 params 组装 body。 */
233
- schema: Readonly<Record<string, unknown>>;
234
- /** 请求体示例。 */
235
- example?: unknown;
236
- }
237
- /** 模块动作响应定义。 */
238
- export interface ModuleActionResponse {
239
- /** 响应说明。 */
240
- description?: string;
241
- /** 响应 schema。 */
242
- schema: Readonly<Record<string, unknown>>;
243
- /** 响应示例。 */
244
- example?: unknown;
245
- }
246
- /** 模块动作渲染目标类型;保留给 CLI 等上层应用使用。 */
247
- export type ModuleActionResultRenderType = 'markdown' | 'json' | 'raw';
248
- /** 模块动作自定义渲染函数类型;SDK 本身不直接渲染终端输出。 */
249
- export type ModuleActionResultRender = (result: unknown, type: ModuleActionResultRenderType, action: ModuleAction) => string;
250
- /** 从原始响应中提取分页字段时使用的字段映射。 */
251
- export interface ModuleActionPagerGetterMap {
252
- /** 当前页码字段名。 */
253
- pageID: string;
254
- /** 每页记录数字段名。 */
255
- recPerPage: string;
256
- /** 总记录数字段名。 */
257
- recTotal: string;
258
- }
259
- /** 禅道模块中的单个 API 动作定义。 */
260
- export interface ModuleAction {
261
- /** 动作名称,例如 `list`、`get`、`close`。 */
262
- name: ModuleActionName;
263
- /** 动作类型,决定高阶 request 的路径/参数解析策略。 */
264
- type: ModuleActionType;
265
- /** 面向用户展示的动作名称。 */
266
- display?: string;
267
- /** 动作说明。 */
268
- description?: string;
269
- /** HTTP 方法。 */
270
- method: ModuleActionMethod;
271
- /** API 路径模板,可包含 `{productID}` 等路径参数。 */
272
- path: string;
273
- /** 路径参数定义;字符串为说明,对象可携带默认值和可选项。 */
274
- pathParams?: Readonly<Record<string, string | Omit<ModuleActionParam, 'name'>>>;
275
- /** 查询参数定义。 */
276
- params?: readonly ModuleActionParam[];
277
- /** 请求体定义。 */
278
- requestBody?: ModuleActionRequestBody;
279
- /** 结果形态。 */
280
- resultType: ModuleActionResultType;
281
- /** 从原始响应中提取分页信息的位置或函数。 */
282
- pagerGetter?: string | ModuleActionPagerGetterMap | ((data: unknown, params: Record<string, unknown>) => ListPagerInfo);
283
- /** 从原始响应中提取业务数据的位置或函数。 */
284
- resultGetter?: string | Record<string, string> | ((data: unknown, params: Record<string, unknown>) => unknown);
285
- /** 供上层应用使用的渲染配置。 */
286
- render?: string | ModuleActionResultRender | Record<ModuleActionResultRenderType, ModuleActionResultRender>;
287
- }
288
- /** 内置模块名称,同时允许用户扩展自定义模块名。 */
289
- export type ModuleName = 'user' | 'program' | 'product' | 'project' | 'execution' | 'productplan' | 'story' | 'epic' | 'requirement' | 'bug' | 'testcase' | 'task' | 'feedback' | 'ticket' | 'system' | 'build' | 'testtask' | 'release' | 'file' | (string & {});
290
- /** 禅道模块定义,由多个动作组成。 */
291
- export interface ModuleDefinition {
292
- /** 模块名称,例如 `product`、`bug`。 */
293
- name: ModuleName;
294
- /** 面向用户展示的模块名称。 */
295
- display?: string;
296
- /** 模块说明。 */
297
- description?: string;
298
- /** 模块支持的动作集合。 */
299
- actions: readonly ModuleAction[];
300
- }
301
- /** 本地数据处理的基础记录类型,对应一条对象数据。 */
302
- export type DataRecord = Record<string, unknown>;
303
- /** 单条过滤条件,字段名支持 `.` 访问子字段。 */
304
- export interface DataRecordFilter {
305
- /** 字段路径,例如 `status` 或 `assignedTo.id`。 */
306
- key: string;
307
- /** 比较运算符。 */
308
- operator: '=' | '!=' | '>' | '<' | '>=' | '<=' | '~' | '!~';
309
- /** 比较值;数组用于 `=`/`!=`/`~`/`!~` 的“任一/全不”匹配。 */
310
- value: string | number | boolean | string[];
311
- }
312
- /** 一组过滤条件,组内按 `operator` 组合;多组之间按 AND 组合。 */
313
- export interface DataRecordFilterGroup {
314
- /** 组内条件的组合方式。 */
315
- operator: 'AND' | 'OR';
316
- /** 组内条件列表。 */
317
- conditions: DataRecordFilter[];
318
- }
319
- /** 排序表达式,格式为 `字段:asc|desc`。 */
320
- export type SortExpr = `${string}:${'asc' | 'desc'}`;
321
- /** 自定义排序比较函数。 */
322
- export type SortFn = (a: DataRecord, b: DataRecord) => number;
323
- /** {@link processData} 处理列表时的选项;执行顺序为 过滤 → 搜索 → 排序 → 限制数量 → 摘取。 */
324
- export interface ProcessListOptions {
325
- /** 过滤表达式列表,例如 `["status=active", "pri>=2"]`,多条之间按 AND 组合。 */
326
- filter?: string[];
327
- /** 模糊搜索关键词组,组内空格分隔为 OR,多组之间按 AND 组合。 */
328
- search?: string[];
329
- /** 限定搜索字段,缺省时搜索全部字段。 */
330
- searchFields?: string[];
331
- /** 排序表达式,多个字段以英文逗号分隔,例如 `pri:desc,id:asc`。 */
332
- sort?: string;
333
- /** 限制返回列表数量,在排序后、摘取前截断;不改变服务端页大小。 */
334
- limit?: string;
335
- /** 摘取字段路径列表。 */
336
- pick?: string[];
337
- }
338
- /** {@link processData} 处理单条对象时的选项。 */
339
- export interface ProcessSingleOptions {
340
- /** 摘取字段路径列表。 */
341
- pick?: string[];
342
- }
343
- /** 将模块动作和参数解析后的可执行请求描述。 */
344
- export interface ResolvedModuleCommand {
345
- /** 模块名称。 */
346
- module: string;
347
- /** 匹配到的动作定义。 */
348
- action: ModuleAction;
349
- /** 原始调用参数。 */
350
- params: Record<string, unknown>;
351
- /** 已替换路径参数后的 API 路径。 */
352
- path: string;
353
- /** 已组装的查询参数。 */
354
- query?: Record<string, string | number>;
355
- /** 已组装的请求体。 */
356
- data?: Record<string, unknown>;
357
- /** 从 `id` 或 `{module}ID` 推断出的对象 ID。 */
358
- id?: number;
359
- }
1
+ /**
2
+ * 公共类型入口(barrel)。
3
+ *
4
+ * 实际定义按领域拆分在同目录下的独立文件中:
5
+ * - `client.ts` — 客户端配置与底层 HTTP 请求类型。
6
+ * - `response.ts` — 禅道 API 响应与归一化结果类型。
7
+ * - `options.ts` — 进程级全局选项与高阶 `request()` 选项。
8
+ * - `profile.ts` — 本地持久化 profile 类型。
9
+ * - `data.ts` — 本地数据处理(过滤 / 搜索 / 排序 / 摘取)类型。
10
+ * - `module.ts` — 模块 / 动作注册表与命令解析类型。
11
+ */
12
+ export * from './client.js';
13
+ export * from './response.js';
14
+ export * from './options.js';
15
+ export * from './profile.js';
16
+ export * from './data.js';
17
+ export * from './module.js';
@@ -1 +1,17 @@
1
- export {};
1
+ /**
2
+ * 公共类型入口(barrel)。
3
+ *
4
+ * 实际定义按领域拆分在同目录下的独立文件中:
5
+ * - `client.ts` — 客户端配置与底层 HTTP 请求类型。
6
+ * - `response.ts` — 禅道 API 响应与归一化结果类型。
7
+ * - `options.ts` — 进程级全局选项与高阶 `request()` 选项。
8
+ * - `profile.ts` — 本地持久化 profile 类型。
9
+ * - `data.ts` — 本地数据处理(过滤 / 搜索 / 排序 / 摘取)类型。
10
+ * - `module.ts` — 模块 / 动作注册表与命令解析类型。
11
+ */
12
+ export * from './client.js';
13
+ export * from './response.js';
14
+ export * from './options.js';
15
+ export * from './profile.js';
16
+ export * from './data.js';
17
+ export * from './module.js';
@@ -0,0 +1,143 @@
1
+ import type { HttpMethod } from './client.js';
2
+ import type { Pager } from './response.js';
3
+ /** 模块动作类型:基础 CRUD 或自定义动作。 */
4
+ export type ModuleActionType = 'list' | 'get' | 'create' | 'update' | 'delete' | 'action';
5
+ /** 模块动作使用的 HTTP 方法;兼容生成定义中的小写方法。 */
6
+ export type ModuleActionMethod = HttpMethod | Lowercase<HttpMethod>;
7
+ /** 模块动作名称,允许除基础动作外的自定义名称。 */
8
+ export type ModuleActionName = ModuleActionType | (string & {});
9
+ /** 模块动作参数可选项。 */
10
+ export type ModuleActionParamOption = {
11
+ readonly value: unknown;
12
+ readonly label: string;
13
+ };
14
+ /** 模块动作的查询参数定义。 */
15
+ export interface ModuleActionParam {
16
+ /** 参数名称。 */
17
+ name: string;
18
+ /** 参数说明。 */
19
+ description?: string;
20
+ /** 是否必填。 */
21
+ required?: boolean;
22
+ /** 未显式传入时使用的默认值。 */
23
+ defaultValue?: unknown;
24
+ /** 参数值类型,用于基础类型转换。 */
25
+ type?: 'string' | 'number' | 'boolean';
26
+ /** 参数可选值。 */
27
+ options?: readonly ModuleActionParamOption[];
28
+ }
29
+ /** 模块动作结果形态。 */
30
+ export type ModuleActionResultType = 'text' | 'object' | 'list';
31
+ /** 列表分页信息别名。 */
32
+ export type ListPagerInfo = Pager;
33
+ /** 模块动作请求体定义。 */
34
+ export interface ModuleActionRequestBody {
35
+ /** 请求体类型。 */
36
+ type?: 'object' | 'string';
37
+ /** 请求体是否必填。 */
38
+ required?: boolean;
39
+ /** OpenAPI 风格 schema,用于从 params 组装 body。 */
40
+ schema: Readonly<Record<string, unknown>>;
41
+ /** 请求体示例。 */
42
+ example?: unknown;
43
+ }
44
+ /** 模块动作响应定义。 */
45
+ export interface ModuleActionResponse {
46
+ /** 响应说明。 */
47
+ description?: string;
48
+ /** 响应 schema。 */
49
+ schema: Readonly<Record<string, unknown>>;
50
+ /** 响应示例。 */
51
+ example?: unknown;
52
+ }
53
+ /** 从原始响应中提取分页字段时使用的字段映射,值为原始响应中的字段路径(支持 `a.b` 嵌套)。 */
54
+ export interface ModuleActionPagerGetterMap {
55
+ /** 当前页码字段路径。 */
56
+ pageID: string;
57
+ /** 每页记录数字段路径。 */
58
+ recPerPage: string;
59
+ /** 总记录数字段路径。 */
60
+ recTotal: string;
61
+ }
62
+ /**
63
+ * 从原始响应中重映射业务数据字段的映射表。
64
+ * 键为输出字段名,值为原始响应中的字段路径(支持 `a.b` 嵌套)。
65
+ */
66
+ export type ModuleActionResultFieldMap = Readonly<Record<string, string>>;
67
+ /**
68
+ * 从原始响应中提取数据时使用的函数形态。
69
+ * @param data 原始响应对象。
70
+ * @param params 触发本次请求的原始调用参数。
71
+ */
72
+ export type ModuleActionGetterFn<T> = (data: unknown, params: Record<string, unknown>) => T;
73
+ /** 禅道模块中的单个 API 动作定义。 */
74
+ export interface ModuleAction {
75
+ /** 动作名称,例如 `list`、`get`、`close`。 */
76
+ name: ModuleActionName;
77
+ /** 动作类型,决定高阶 request 的路径/参数解析策略,并在 `method`、`resultType` 省略时作为推导依据。 */
78
+ type: ModuleActionType;
79
+ /** 面向用户展示的动作名称。 */
80
+ display?: string;
81
+ /** 动作说明。 */
82
+ description?: string;
83
+ /**
84
+ * HTTP 方法;省略时按 {@link type} 自动推导:
85
+ * `list`/`get` → `GET`、`create`/`action` → `POST`、`update` → `PUT`、`delete` → `DELETE`。
86
+ * 当 `type` 无法推导出方法时抛出 `E_INDETERMINATE_ACTION_METHOD`。
87
+ */
88
+ method?: ModuleActionMethod;
89
+ /** API 路径模板,可包含 `{productID}` 等路径参数。 */
90
+ path: string;
91
+ /** 路径参数定义;字符串为说明,对象可携带默认值和可选项。 */
92
+ pathParams?: Readonly<Record<string, string | Omit<ModuleActionParam, 'name'>>>;
93
+ /** 查询参数定义。 */
94
+ params?: readonly ModuleActionParam[];
95
+ /** 请求体定义。 */
96
+ requestBody?: ModuleActionRequestBody;
97
+ /**
98
+ * 结果形态;省略时按 {@link type} 自动推导:
99
+ * `list` → `list`、`get`/`create`/`update` → `object`、`delete`/`action` → `text`。
100
+ * 当 `type` 无法推导出结果形态时抛出 `E_INDETERMINATE_ACTION_RESULT_TYPE`。
101
+ */
102
+ resultType?: ModuleActionResultType;
103
+ /**
104
+ * 从原始响应中提取分页信息的位置或函数:
105
+ * 字符串为字段路径(支持 `a.b` 嵌套)、对象为字段映射、函数则接收原始响应与调用参数。
106
+ */
107
+ pagerGetter?: string | ModuleActionPagerGetterMap | ModuleActionGetterFn<ListPagerInfo>;
108
+ /**
109
+ * 从原始响应中提取业务数据的位置或函数:
110
+ * 字符串为字段路径(支持 `a.b` 嵌套)、对象为字段映射、函数则接收原始响应与调用参数。
111
+ */
112
+ resultGetter?: string | ModuleActionResultFieldMap | ModuleActionGetterFn<unknown>;
113
+ }
114
+ /** 内置模块名称,同时允许用户扩展自定义模块名。 */
115
+ export type ModuleName = 'user' | 'program' | 'product' | 'project' | 'execution' | 'productplan' | 'story' | 'epic' | 'requirement' | 'bug' | 'testcase' | 'task' | 'feedback' | 'ticket' | 'system' | 'build' | 'testtask' | 'release' | 'file' | (string & {});
116
+ /** 禅道模块定义,由多个动作组成。 */
117
+ export interface ModuleDefinition {
118
+ /** 模块名称,例如 `product`、`bug`。 */
119
+ name: ModuleName;
120
+ /** 面向用户展示的模块名称。 */
121
+ display?: string;
122
+ /** 模块说明。 */
123
+ description?: string;
124
+ /** 模块支持的动作集合。 */
125
+ actions: readonly ModuleAction[];
126
+ }
127
+ /** 将模块动作和参数解析后的可执行请求描述。 */
128
+ export interface ResolvedModuleCommand {
129
+ /** 模块名称。 */
130
+ module: string;
131
+ /** 匹配到的动作定义。 */
132
+ action: ModuleAction;
133
+ /** 原始调用参数。 */
134
+ params: Record<string, unknown>;
135
+ /** 已替换路径参数后的 API 路径。 */
136
+ path: string;
137
+ /** 已组装的查询参数。 */
138
+ query?: Record<string, string | number>;
139
+ /** 已组装的请求体。 */
140
+ data?: Record<string, unknown>;
141
+ /** 从 `id` 或 `{module}ID` 推断出的对象 ID。 */
142
+ id?: number;
143
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import type { ZentaoClient } from '../client/index.js';
2
+ import type { ProcessListOptions } from './data.js';
3
+ /** SDK 进程级全局默认选项,供高阶 {@link request} 调用复用。 */
4
+ export interface GlobalOptions {
5
+ /** 默认客户端;通常由 `ZentaoClient.init()` 设置。 */
6
+ client?: ZentaoClient;
7
+ /** 默认每页记录数,会映射到模块动作的 `recPerPage` 参数。 */
8
+ recPerPage?: string;
9
+ /** 默认限制返回列表数量,只影响 SDK 归一化后的 `data`。 */
10
+ limit?: string;
11
+ /** 默认请求超时时间,优先级低于单次请求选项。 */
12
+ timeout?: number;
13
+ /** 默认 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
14
+ insecure?: boolean;
15
+ /** 是否在登录成功后把账号、Token 和配置持久化为本地 profile。 */
16
+ persistProfiles?: boolean;
17
+ /** 当禅道服务端返回 `{ status: "fail" }` 时是否抛出 `E_API_FAILED`,默认 false。 */
18
+ throwOnFail?: boolean;
19
+ /**
20
+ * 是否在执行 `update` 操作时自动填充未传入的字段,默认 false。
21
+ *
22
+ * 优先级低于单次请求选项;语义见 {@link RequestOptions.autoFill}。
23
+ */
24
+ autoFill?: boolean;
25
+ }
26
+ /** 高阶 `request("moduleName")` / `request("moduleName/methodName")` / `request("moduleName/<objectID>")` 的单次调用选项。 */
27
+ export interface RequestOptions extends ProcessListOptions {
28
+ /** 本次调用使用的客户端;优先级高于全局客户端。 */
29
+ client?: ZentaoClient;
30
+ /** 本次调用使用的每页记录数,优先级高于全局 `recPerPage`。 */
31
+ recPerPage?: string;
32
+ /** 本次调用超时时间。 */
33
+ timeout?: number;
34
+ /** 本次调用 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
35
+ insecure?: boolean;
36
+ /**
37
+ * 当禅道服务端返回 `{ status: "fail" }` 时是否抛出 `E_API_FAILED`。
38
+ * 不传时回落到全局 `throwOnFail`,默认 false(保留原始失败响应)。
39
+ */
40
+ throwOnFail?: boolean;
41
+ /**
42
+ * 是否在执行 `update` 操作时自动填充未传入的字段。
43
+ *
44
+ * 设为 `true` 后,会先 GET 当前对象,把用户未显式传入(含 `params.data`)且
45
+ * 动作 body schema 中声明的字段用现值补齐,再发起 PUT,避免禅道用空值覆盖未提交字段。
46
+ * 因此只需传想修改的字段即可。仅对 `type: 'update'` 且模块存在 `type: 'get'` 动作时生效。
47
+ *
48
+ * 不传时回落到全局 `autoFill`,默认 false。
49
+ */
50
+ autoFill?: boolean;
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ import type { ServerConfig } from './response.js';
2
+ /** 保存到本地 profile 中的客户端偏好配置。 */
3
+ export interface ZentaoProfileConfig {
4
+ /** 默认输出格式,供 CLI 等上层应用复用。 */
5
+ defaultOutputFormat?: 'markdown' | 'json' | 'raw';
6
+ /** 界面语言。 */
7
+ lang?: string;
8
+ /** 默认分页大小。 */
9
+ defaultRecPerPage?: number;
10
+ /** 是否跳过 TLS 证书验证;仅 Node.js 运行时支持。 */
11
+ insecure?: boolean;
12
+ /** 请求超时时间,单位毫秒。 */
13
+ timeout?: number;
14
+ /** 是否在批量操作出错时停止执行后续操作。 */
15
+ batchFailFast?: boolean;
16
+ /** JSON 格式化时是否添加缩进。 */
17
+ jsonPretty?: boolean;
18
+ /** 模块级分页偏好。 */
19
+ pagers?: Record<string, number>;
20
+ /** 允许上层应用保存自定义配置。 */
21
+ [key: string]: unknown;
22
+ }
23
+ /** 本地持久化的禅道账号 profile。 */
24
+ export interface ZentaoProfile {
25
+ /** 禅道站点根地址,不包含 `/api.php/v2`。 */
26
+ server: string;
27
+ /** 用户账号。 */
28
+ account: string;
29
+ /** 禅道 API Token。 */
30
+ token: string;
31
+ /** 登录验证通过后得到的用户信息。 */
32
+ user?: Record<string, unknown>;
33
+ /** 登录时间。 */
34
+ loginTime?: string;
35
+ /** 最后使用时间。 */
36
+ lastUsedTime?: string;
37
+ /** 禅道服务端配置。 */
38
+ serverConfig?: ServerConfig;
39
+ /** 客户端自定义配置。 */
40
+ config?: ZentaoProfileConfig;
41
+ /** 允许上层应用保存额外字段。 */
42
+ [key: string]: unknown;
43
+ }
44
+ /** 运行时返回的 profile,会额外带上 `account@server` 形式的 key。 */
45
+ export interface ZentaoProfileRecord extends ZentaoProfile {
46
+ key: string;
47
+ }
48
+ /** 本地 profile 存储文件或浏览器 localStorage 中的 JSON 结构。 */
49
+ export interface ZentaoProfilesStore {
50
+ /** 当前使用的 profile key。 */
51
+ currentProfile?: string;
52
+ /** 保存的 profile 列表。 */
53
+ profiles: ZentaoProfile[];
54
+ }
@@ -0,0 +1 @@
1
+ export {};