zentao-api 0.8.5 → 0.9.1

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.
Files changed (48) hide show
  1. package/README.md +48 -2
  2. package/dist/browser/zentao-api.global.js +28 -28
  3. package/dist/client/index.d.ts +4 -0
  4. package/dist/client/index.js +10 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/misc/errors.d.ts +4 -0
  8. package/dist/misc/errors.js +4 -0
  9. package/dist/misc/zentao-version.d.ts +3 -0
  10. package/dist/misc/zentao-version.js +9 -0
  11. package/dist/modules/define.d.ts +1 -0
  12. package/dist/modules/define.js +3 -2
  13. package/dist/modules/generated.d.ts +368 -0
  14. package/dist/modules/generated.js +421 -53
  15. package/dist/modules/object-props.js +212 -36
  16. package/dist/modules/override.js +93 -9
  17. package/dist/modules/query.d.ts +2 -0
  18. package/dist/modules/query.js +6 -0
  19. package/dist/modules/registry-store.d.ts +4 -4
  20. package/dist/modules/registry-store.js +15 -8
  21. package/dist/modules/result-object-type.d.ts +7 -0
  22. package/dist/modules/result-object-type.js +35 -0
  23. package/dist/request/html-file-request.d.ts +34 -0
  24. package/dist/request/html-file-request.js +366 -0
  25. package/dist/request/html-files.d.ts +28 -0
  26. package/dist/request/html-files.js +103 -0
  27. package/dist/request/index.d.ts +3 -3
  28. package/dist/request/index.js +78 -26
  29. package/dist/request/prepare-body.d.ts +2 -0
  30. package/dist/request/prepare-body.js +2 -2
  31. package/dist/types/index.d.ts +2 -0
  32. package/dist/types/index.js +2 -0
  33. package/dist/types/link.d.ts +52 -0
  34. package/dist/types/link.js +1 -0
  35. package/dist/types/module.d.ts +18 -0
  36. package/dist/types/options.d.ts +7 -4
  37. package/dist/types/response.d.ts +16 -0
  38. package/dist/types/upload.d.ts +64 -2
  39. package/dist/utils/html.d.ts +18 -0
  40. package/dist/utils/html.js +55 -0
  41. package/dist/utils/index.d.ts +3 -1
  42. package/dist/utils/index.js +3 -1
  43. package/dist/utils/link.d.ts +30 -0
  44. package/dist/utils/link.js +225 -0
  45. package/dist/utils/url.d.ts +10 -0
  46. package/dist/utils/url.js +51 -0
  47. package/dist/version.js +2 -2
  48. package/package.json +5 -2
@@ -1,4 +1,6 @@
1
1
  import type { ClientRequestOptions, FromProfileOptions, GetZentaoConfigOptions, ServerConfig, ZentaoClientOptions } from '../types/index.js';
2
+ /** @internal */
3
+ export declare const captureFileSession: unique symbol;
2
4
  /**
3
5
  * 禅道 API 客户端,封装一次次原始 HTTP 调用。
4
6
  *
@@ -40,6 +42,8 @@ export declare class ZentaoClient {
40
42
  * @throws {ZentaoError} `E_INVALID_BASE_URL` —— 地址不合法或协议非 http(s)。
41
43
  */
42
44
  constructor(baseUrl: string);
45
+ /** @internal Check that uploads and their object save still use the same Token. */
46
+ [captureFileSession](): () => void;
43
47
  /**
44
48
  * 发起一次原始 API 请求。
45
49
  *
@@ -7,6 +7,8 @@ import { isRecord, normalizeSiteUrl } from '../utils/index.js';
7
7
  const DEFAULT_TIMEOUT = 10000;
8
8
  const CONFIG_MAX_AGE = 24 * 60 * 60 * 1000;
9
9
  const ACTION_ASSISTANT_HEADER = 'ZenTao-Action-Assistant';
10
+ /** @internal */
11
+ export const captureFileSession = Symbol('captureFileSession');
10
12
  function serializeActionAssistant(value) {
11
13
  if (typeof value === 'string')
12
14
  return value;
@@ -333,6 +335,14 @@ export class ZentaoClient {
333
335
  this.insecure = options.insecure;
334
336
  this.actionAssistant = options.actionAssistant;
335
337
  }
338
+ /** @internal Check that uploads and their object save still use the same Token. */
339
+ [captureFileSession]() {
340
+ const token = this.token;
341
+ return () => {
342
+ if (this.token !== token)
343
+ throw new ZentaoError('E_FILE_SESSION_CHANGED');
344
+ };
345
+ }
336
346
  async request(path, options = {}) {
337
347
  return this.fetch(buildUrl(this.baseUrl, path, options.query), options, this.token);
338
348
  }
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@ export { getGlobalOptions, setGlobalOptions } from './misc/global-options.js';
4
4
  export { ZENTAO_PROFILES_STORAGE_KEY, addProfile, deleteProfile, getAllProfiles, getProfile, getProfileKey, switchProfile, } from './profiles/index.js';
5
5
  export { defineModuleActions, defineModules, type DefineModulesOptions, type ExportRegistryOptions, type ExportedModuleAction, type ExportedModuleDefinition, exportRegistry, extendModuleAction, getModuleNames, isModuleName, getModule, getModuleAction, getModuleActionParams, getObjectProps, } from './modules/registry.js';
6
6
  export { request, type BuiltinRequestName, type RequestParamsFor, type RequestResultFor, } from './request/index.js';
7
- export { pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './utils/index.js';
7
+ export { createLink, extractFileIdFromUrl, extractFileIdsFromHtml, parseLink, pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './utils/index.js';
8
8
  export { BUILD, VERSION } from './version.js';
9
9
  export type * from './types/index.js';
package/dist/index.js CHANGED
@@ -4,5 +4,5 @@ export { getGlobalOptions, setGlobalOptions } from './misc/global-options.js';
4
4
  export { ZENTAO_PROFILES_STORAGE_KEY, addProfile, deleteProfile, getAllProfiles, getProfile, getProfileKey, switchProfile, } from './profiles/index.js';
5
5
  export { defineModuleActions, defineModules, exportRegistry, extendModuleAction, getModuleNames, isModuleName, getModule, getModuleAction, getModuleActionParams, getObjectProps, } from './modules/registry.js';
6
6
  export { request, } from './request/index.js';
7
- export { pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './utils/index.js';
7
+ export { createLink, extractFileIdFromUrl, extractFileIdsFromHtml, parseLink, pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './utils/index.js';
8
8
  export { BUILD, VERSION } from './version.js';
@@ -36,6 +36,10 @@ export declare const ERRORS: {
36
36
  readonly E_UPLOAD_FILE_READ_FAILED: "Failed to read upload file: {path}";
37
37
  readonly E_UPLOAD_FILE_TOO_LARGE: "Upload file is {size} bytes and exceeds the {limit} byte limit.";
38
38
  readonly E_INVALID_UPLOAD_SOURCE: "Invalid upload source for field: {field}";
39
+ readonly E_FILE_RESOLVE_FAILED: "Failed to resolve HTML file reference: {path}";
40
+ readonly E_FILE_SAVE_UNCONFIRMED: "The server did not confirm the object save for this upload batch.";
41
+ readonly E_FILE_SESSION_CHANGED: "The client login changed during the image upload batch.";
42
+ readonly E_FILE_UPLOAD_FAILED: "The file upload response does not contain a valid file ID.";
39
43
  };
40
44
  /** SDK 已知错误码,对应 {@link ERRORS} 的 key。 */
41
45
  export type ErrorCode = keyof typeof ERRORS;
@@ -36,6 +36,10 @@ export const ERRORS = {
36
36
  E_UPLOAD_FILE_READ_FAILED: 'Failed to read upload file: {path}',
37
37
  E_UPLOAD_FILE_TOO_LARGE: 'Upload file is {size} bytes and exceeds the {limit} byte limit.',
38
38
  E_INVALID_UPLOAD_SOURCE: 'Invalid upload source for field: {field}',
39
+ E_FILE_RESOLVE_FAILED: 'Failed to resolve HTML file reference: {path}',
40
+ E_FILE_SAVE_UNCONFIRMED: 'The server did not confirm the object save for this upload batch.',
41
+ E_FILE_SESSION_CHANGED: 'The client login changed during the image upload batch.',
42
+ E_FILE_UPLOAD_FAILED: 'The file upload response does not contain a valid file ID.',
39
43
  };
40
44
  /** 仅配置获取失败可选择跳过;取消、版本错误和持久化错误仍须抛出。 @internal */
41
45
  export function isZentaoConfigFetchError(error) {
@@ -1,3 +1,4 @@
1
+ export declare const VERSION_23_MINIMUMS: readonly string[];
1
2
  interface ZentaoVersion {
2
3
  edition: string;
3
4
  parts: number[];
@@ -8,4 +9,6 @@ export declare function parseZentaoVersion(version: string): ZentaoVersion;
8
9
  export declare function validateMinVersion(value: unknown): asserts value is readonly string[];
9
10
  /** 同系列逐段比较,缺少的数字段视为零;未列出的系列不支持。 */
10
11
  export declare function supportsZentaoVersion(version: ZentaoVersion, minimums: readonly string[]): boolean;
12
+ /** null 表示调用方已选择在配置获取失败时跳过版本检查。 */
13
+ export declare function assertSupportedVersion(version: string | null, minimums: readonly string[], action: string): void;
11
14
  export {};
@@ -1,4 +1,5 @@
1
1
  import { ZentaoError } from './errors.js';
2
+ export const VERSION_23_MINIMUMS = Object.freeze(['23.0', 'biz14.0', 'max9.0', 'ipd6.0']);
2
3
  /** 只接受开源版、biz、max、ipd 系列的点分数字正式版本。 */
3
4
  export function parseZentaoVersion(version) {
4
5
  const match = typeof version === 'string' ? version.trim().match(/^(biz|max|ipd)?(\d+(?:\.\d+)*)$/i) : null;
@@ -33,3 +34,11 @@ export function supportsZentaoVersion(version, minimums) {
33
34
  }
34
35
  return true;
35
36
  }
37
+ /** null 表示调用方已选择在配置获取失败时跳过版本检查。 */
38
+ export function assertSupportedVersion(version, minimums, action) {
39
+ if (version === null || supportsZentaoVersion(parseZentaoVersion(version), minimums))
40
+ return;
41
+ throw new ZentaoError('E_UNSUPPORTED_ZENTAO_VERSION', {
42
+ action, version, minVersion: minimums.join(', '),
43
+ }, { action, version, minVersion: minimums });
44
+ }
@@ -31,6 +31,7 @@ export declare function defineModules(input: ModuleDefinition | ModuleDefinition
31
31
  * 不做深度合并:同名动作整体替换,未知动作追加。这避免在 schema、参数数组等字段上出现隐式合并规则。
32
32
  *
33
33
  * `method` / `resultType` 可省略:写入时按动作 `type` 自动推导(见 {@link ModuleAction})。
34
+ * `resultObjectType` 可省略:对象和列表补齐所属模块名,其他形态补齐 `null`。
34
35
  *
35
36
  * @param moduleName - 目标模块名(大小写不敏感)。
36
37
  * @param input - 单个或一组动作定义。
@@ -39,6 +39,7 @@ export function defineModules(input, options = {}) {
39
39
  * 不做深度合并:同名动作整体替换,未知动作追加。这避免在 schema、参数数组等字段上出现隐式合并规则。
40
40
  *
41
41
  * `method` / `resultType` 可省略:写入时按动作 `type` 自动推导(见 {@link ModuleAction})。
42
+ * `resultObjectType` 可省略:对象和列表补齐所属模块名,其他形态补齐 `null`。
42
43
  *
43
44
  * @param moduleName - 目标模块名(大小写不敏感)。
44
45
  * @param input - 单个或一组动作定义。
@@ -56,7 +57,7 @@ export function defineModuleActions(moduleName, input) {
56
57
  for (const action of asArray(input)) {
57
58
  validateAction(action);
58
59
  const index = findActionIndex(actions, String(action.name));
59
- const frozen = freezeAction(deepClone(action));
60
+ const frozen = freezeAction(deepClone(action), module.name);
60
61
  // 同名动作替换,未知动作追加;不做深度合并,避免 schema/数组字段出现隐式规则。
61
62
  if (index >= 0) {
62
63
  actions[index] = frozen;
@@ -104,7 +105,7 @@ export function extendModuleAction(moduleName, actionName, action) {
104
105
  // 对象:作为补丁与原动作深度合并。
105
106
  const next = typeof action === 'function' ? action(deepClone(current)) : deepMerge(current, action);
106
107
  validateAction(next);
107
- actions[actionIndex] = freezeAction(next);
108
+ actions[actionIndex] = freezeAction(next, module.name);
108
109
  const nextModule = freezeModule({ ...module, actions });
109
110
  const modules = getModulesState();
110
111
  const index = modules.findIndex((item) => item.name.toLowerCase() === key);