zentao-api 0.6.8 → 0.6.9

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.
@@ -92,6 +92,35 @@ export function applyBuiltinOverrides() {
92
92
  }
93
93
  return action;
94
94
  });
95
+ // 需求创建和变更时,根据评审人决定是否进入评审流程。
96
+ ['story', 'requirement', 'epic'].forEach((moduleName) => {
97
+ ['create', 'change'].forEach((actionName) => {
98
+ extendModuleAction(moduleName, actionName, (action) => {
99
+ const schema = action.requestBody.schema;
100
+ // 补齐 requirement/change 的评审人字段,并允许未传评审人时执行回调。
101
+ schema.properties.reviewer ??= {
102
+ type: 'array',
103
+ items: { type: 'string' },
104
+ description: '评审人员',
105
+ };
106
+ if (schema.required) {
107
+ schema.required = schema.required.filter(name => name !== 'reviewer');
108
+ }
109
+ action.beforeRequest = async ({ data = {} }) => {
110
+ const hasReviewer = Array.isArray(data.reviewer)
111
+ && data.reviewer.some(reviewer => typeof reviewer === 'string' && reviewer.trim() !== '');
112
+ if (hasReviewer) {
113
+ data.status = 'reviewing';
114
+ }
115
+ else {
116
+ data.needNotReview = '1';
117
+ }
118
+ return { data };
119
+ };
120
+ return action;
121
+ });
122
+ });
123
+ });
95
124
  // 修改 acl 字段默认值为 open
96
125
  [
97
126
  ['product', 'create'],
@@ -156,6 +156,9 @@ export function validateAction(action) {
156
156
  if (action.resultType !== undefined && typeof action.resultType !== 'string') {
157
157
  throw new ZentaoError('E_INVALID_ACTION_DEFINITION');
158
158
  }
159
+ if (action.beforeRequest !== undefined && typeof action.beforeRequest !== 'function') {
160
+ throw new ZentaoError('E_INVALID_ACTION_DEFINITION');
161
+ }
159
162
  if (action.request !== undefined && typeof action.request !== 'function') {
160
163
  throw new ZentaoError('E_INVALID_ACTION_DEFINITION');
161
164
  }
@@ -25,6 +25,7 @@ export type RequestResultFor<Name extends BuiltinRequestName> = ActionMetaOf<Nam
25
25
  * 按模块名或模块动作名请求禅道 API。
26
26
  *
27
27
  * 选项优先级为:本次调用 options > 全局 options > 客户端默认值。
28
+ * 动作的 beforeRequest 在参数解析后、请求体准备前执行,返回值浅合并到解析后的请求描述中。
28
29
  * 当响应 `status` 为 `"fail"` 时,默认按原样返回;若 `options.throwOnFail`
29
30
  * 或全局 `throwOnFail` 为真,则改为抛出 `E_API_FAILED`。
30
31
  * 请求前按 Action 的 `minVersion` 检查服务器版本;全局 `version` 可避免配置探测,
@@ -231,6 +231,9 @@ async function requestInternal(name, params, options, version) {
231
231
  ? await autoFillUpdateParams(module, action, mergedParams, { ...options, client }, version)
232
232
  : mergedParams;
233
233
  const command = resolveActionRequest(module, actionName, finalParams);
234
+ if (command.action.beforeRequest) {
235
+ Object.assign(command, await command.action.beforeRequest(command));
236
+ }
234
237
  const preparedBody = await prepareActionBody(command, {
235
238
  maxUploadBytes: options.maxUploadBytes,
236
239
  });
@@ -87,6 +87,14 @@ export type ModuleActionResultFieldMap = Readonly<Record<string, string>>;
87
87
  * @param options 本次请求的数据处理选项;直接调用 getter 时可以省略。
88
88
  */
89
89
  export type ModuleActionGetterFn<T, O = RequestProcessOptions> = (data: unknown, params: Record<string, unknown>, options?: O) => T;
90
+ /**
91
+ * 请求发送前的回调,在版本检查、autoFill 和参数解析完成后、请求体准备前调用。
92
+ * 可直接修改本次请求,或返回 `path`、`query`、`data`、`params`、`id` 的部分字段作为补丁。
93
+ * 返回值浅合并到解析后的请求描述中,同名字段以返回值为准;对象字段整体替换。
94
+ * 合并后的请求用于请求体准备、请求发送和响应处理,不会重新执行版本检查、autoFill 或参数解析。
95
+ * 回调抛出或拒绝时终止本次请求,错误原样传递。
96
+ */
97
+ export type ModuleActionBeforeRequestCallback = (request: ModuleActionRequest) => Promise<Partial<Omit<ModuleActionRequest, 'module' | 'action'>>>;
90
98
  /**
91
99
  * 自定义动作的请求发送逻辑,在版本检查、参数解析和请求体准备完成后调用。
92
100
  * 返回原始响应数据,后续仍按动作定义提取结果、分页并应用请求选项;抛出的错误原样传递。
@@ -149,6 +157,8 @@ export interface ModuleAction {
149
157
  * 字符串为字段路径(支持 `a.b` 嵌套)、对象为字段映射、函数则接收原始响应与调用参数。
150
158
  */
151
159
  resultGetter?: string | ModuleActionResultFieldMap | ModuleActionGetterFn<unknown>;
160
+ /** 请求体准备前执行的回调,可修改解析后的请求并返回请求描述的部分字段作为补丁。 */
161
+ beforeRequest?: ModuleActionBeforeRequestCallback;
152
162
  /** 自定义请求回调;省略时通过 ZentaoClient.request 发送请求,返回值沿用相同的响应处理流程。 */
153
163
  request?: ModuleActionRequestCallback;
154
164
  }
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
- const fallbackBuild = "2026-09-06T14:52:03.785Z";
2
- const fallbackVersion = "0.6.8";
1
+ const fallbackBuild = "2026-09-12T05:43:34.253Z";
2
+ const fallbackVersion = "0.6.9";
3
3
  /**
4
4
  * 构建标识,由构建脚本通过 `__ZENTAO_API_BUILD__` 注入。
5
5
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zentao-api",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "type": "module",
5
5
  "description": "Browser and Node.js SDK for ZenTao API",
6
6
  "license": "MIT",