@tier0/sdk-v2 0.9.8 → 0.9.10

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 (44) hide show
  1. package/CHANGELOG.md +16 -4
  2. package/README.md +18 -6
  3. package/dist/cjs/connection-diagnostics.d.ts +2 -0
  4. package/dist/cjs/connection-diagnostics.js +20 -0
  5. package/dist/cjs/connection-diagnostics.js.map +1 -0
  6. package/dist/cjs/data/error.d.ts +1 -1
  7. package/dist/cjs/data/error.js +2 -2
  8. package/dist/cjs/data/error.js.map +1 -1
  9. package/dist/cjs/openapi/client.js +3 -2
  10. package/dist/cjs/openapi/client.js.map +1 -1
  11. package/dist/cjs/openapi/types.generated.d.ts +1 -1
  12. package/dist/cjs/openapi/types.generated.js.map +1 -1
  13. package/dist/cjs/uns-v2/client.js +3 -2
  14. package/dist/cjs/uns-v2/client.js.map +1 -1
  15. package/dist/cjs/uns-v2/generated.d.ts +65 -19
  16. package/dist/cjs/uns-v2/generated.js +21 -20
  17. package/dist/cjs/uns-v2/generated.js.map +1 -1
  18. package/dist/esm/connection-diagnostics.d.ts +2 -0
  19. package/dist/esm/connection-diagnostics.js +17 -0
  20. package/dist/esm/connection-diagnostics.js.map +1 -0
  21. package/dist/esm/data/error.d.ts +1 -1
  22. package/dist/esm/data/error.js +2 -2
  23. package/dist/esm/data/error.js.map +1 -1
  24. package/dist/esm/openapi/client.js +3 -2
  25. package/dist/esm/openapi/client.js.map +1 -1
  26. package/dist/esm/openapi/types.generated.d.ts +1 -1
  27. package/dist/esm/openapi/types.generated.js.map +1 -1
  28. package/dist/esm/uns-v2/client.js +3 -2
  29. package/dist/esm/uns-v2/client.js.map +1 -1
  30. package/dist/esm/uns-v2/generated.d.ts +65 -19
  31. package/dist/esm/uns-v2/generated.js +21 -20
  32. package/dist/esm/uns-v2/generated.js.map +1 -1
  33. package/package.json +1 -1
  34. package/skills/tier0-sdk-v2/SKILL.md +2 -0
  35. package/skills/tier0-sdk-v2/references/local-connection.md +61 -0
  36. package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/consistency.md +2 -2
  37. package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/errors.md +4 -2
  38. package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/modeling.md +3 -1
  39. package/skills/tier0-sdk-v2/tier0-sdk-v2-data/references/schema-evolution.md +2 -0
  40. package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/SKILL.md +5 -2
  41. package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/delete.md +51 -19
  42. package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/namespace.md +17 -1
  43. package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/read.md +28 -0
  44. package/skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/restore.md +12 -13
package/CHANGELOG.md CHANGED
@@ -1,12 +1,24 @@
1
1
  # Changelog
2
2
 
3
- ## 0.9.8 (unreleased candidate)
3
+ ## 0.9.10 (2026-11-04)
4
+
5
+ - Add a local connection guide for Personal keys, explicit OpenAPI gateway configuration and reading existing collections without a platform App.
6
+ - Explain non-JSON route, authentication, permission and service errors without exposing credentials or changing error types, execution/retry semantics or request destinations.
7
+ - Align Namespace trash, delete and restore guidance: retained data remains readable, archived targets reject writes, and the legacy record restoration limit does not apply to current collection archive / restore.
8
+
9
+ ## 0.9.9 (2026-11-04)
10
+
11
+ - Clarify workspace Agent/Personal versus App credential query permissions. Keep `namespace()` on OpenAPI; document `dataAppContext` followed by `recordFind` for App keys, with a typed example and 403 troubleshooting. No runtime authorization changes.
12
+
13
+ - Add `client.uns.metadataPurge` for explicit archived Collection IDs. Preserve the asynchronous `accepted` / `jobId` receipt; use `jobs` to inspect completion and per-item results. Preview remains optional.
14
+ - Document Collection deletion with retained records/samples and configuration references, followed by restore or permanent deletion.
15
+ - Preserve App collection directories and Source lifecycle behavior, and pin the combined contract to Backend commit `064cdcdb688b18fb73295ac986380d84daa08188`.
16
+
17
+ ## 0.9.8 (2026-11-02)
4
18
 
5
19
  - Add `directoryPath` to App collection declarations and preserve it through compilation and first-use ensure. New collections use actual business directories; existing aliases retain their location.
6
20
  - Validate and freeze paths, and document known ISA-95 scopes, shared ancestors, and App/module directories within those scopes without forcing five levels.
7
- - Preserve the Source lifecycle changes from 0.9.7 and pin their combined contract with App collection directories to Backend commit `5c77d6f21e6332cb09e3212df9203eb01bf7f129`.
8
-
9
- This candidate is not published to npm; install the verified tarball for integration testing against that backend contract.
21
+ - Preserve the Source lifecycle changes from the unpublished 0.9.7 candidate and pin their combined contract with App collection directories to Backend commit `5c77d6f21e6332cb09e3212df9203eb01bf7f129`.
10
22
 
11
23
  ## 0.9.7 (unreleased candidate)
12
24
 
package/README.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  Tier0 云端统一 TypeScript / JavaScript SDK,数据管理与 App Stream 交互均使用 `@tier0/sdk-v2`。旧 SDK 不再作为依赖。
4
4
 
5
- `0.9.8` 候选版新增 App 集合业务目录声明 `directoryPath`,按已知业务范围创建或复用目录,已有集合保持位置。保留 `0.9.7` 的 Source 生命周期简化:创建后可直接使用,删除后停止后续使用;移除 `client.source.state.update`、启停能力与 `desiredState`。名称和描述修改无需影响确认,连接配置变更或删除存在引用时仍须确认;运行中的 Stream 可直接删除。该版本尚未发布 npm,验收使用下方安装包。
5
+ `0.9.10` 补齐个人 Key 本地接入指南与非 JSON 网关错误提示,并同步 Namespace 回收、删除和恢复说明;保留现有权限、请求地址和重试规则。
6
+
7
+ `0.9.9` 新增 `client.uns.metadataPurge`,通过明确的已归档 Collection ID 提交永久删除,返回 `accepted` / `jobId` 并通过现有 `jobs` 查询逐项完成结果;`dryRun` 可选。集合删除保留 Record/Sample,支持恢复或继续永久清理。
8
+
9
+ 本版同时补齐 Agent / App 凭证的查询说明及 App 读取示例:`namespace()` 仍走 OpenAPI,App Key 使用 `dataAppContext` 和集合数据接口,服务端授权规则保持不变。
10
+
11
+ 保留 `0.9.8` 的 App 集合业务目录声明 `directoryPath`,按已知业务范围创建或复用目录,已有集合保持位置。Source 创建后可直接使用,删除后停止后续使用;不再提供 `client.source.state.update`、启停能力与 `desiredState`。名称和描述修改无需影响确认,连接配置变更或删除存在引用时仍须确认;运行中的 Stream 可直接删除。
6
12
 
7
13
  `0.9.3` 同步集合授权合同:授予既有集合访问权限时无需提供别名,并更新生成类型与使用说明。集合声明的 `name` / `alias` 要求保持不变。
8
14
 
@@ -22,21 +28,21 @@ Collection 声明必须同时提供业务名称 `name`(例如「生产工单
22
28
 
23
29
  ## 安装与初始化
24
30
 
25
- 维护者发布前在本仓库运行 `npm ci`、`npm run check`,并验证生成的 `.tgz`。本分支的功能应使用检查通过的 `tier0-sdk-v2-0.9.8.tgz` 在业务项目中验证:
31
+ 安装正式版本:
26
32
 
27
33
  ```sh
28
- npm install /path/to/tier0-sdk-v2-0.9.8.tgz
34
+ npm install @tier0/sdk-v2@0.9.10
29
35
  ```
30
36
 
31
- `0.9.8` 正式发布后再使用 `npm install @tier0/sdk-v2@0.9.8`。发布前,npm 的既有版本和 `next` 标签不代表本分支的完整功能。
37
+ 维护者发布前在本仓库运行 `npm ci`、`npm run check`,并验证生成的 `.tgz`。
38
+
39
+ 个人 Key 可直接读取已有集合,无需创建平台 App;网关配置、运行示例与排错见[本地连接指南](skills/tier0-sdk-v2/references/local-connection.md)。
32
40
 
33
41
  ```ts
34
42
  import { createClient } from '@tier0/sdk-v2';
35
43
 
36
44
  // 服务端环境注入 TIER0_API_HOST 和 TIER0_API_KEY。
37
45
  const tier0 = createClient();
38
- // 首次接入时确认身份与 Workspace;不需要在每次业务操作前重复调用。
39
- const user = await tier0.system.whoami();
40
46
  ```
41
47
 
42
48
  也可显式配置 `{ apiHost, apiKey, transportTimeoutMs, fetch }`,或提供 `getApiHost` / `getApiKey` 回调。裸域名默认使用 HTTPS;本地 HTTP 测试请显式写 `http://127.0.0.1:端口`。不自动向浏览器注入或读取 `VITE_` API Key。
@@ -74,6 +80,12 @@ const user = await tier0.system.whoami();
74
80
 
75
81
  不保留 UNS v1、旧 Flow、`getCurrentProjectId()`、project 成员查询或 `/gw/reload`。Workspace 成员不等于能使用某个 App 的成员,不可用前者在客户端猜测 App 权限。
76
82
 
83
+ ## SDK 方法与凭证权限
84
+
85
+ 同一 SDK 支持工作空间集成和 App 运行时,方法存在不代表当前凭证可调用。`client.uns.namespace()` 调用的是 `POST /openapi/v2/uns/namespace/query`,属于 OpenAPI;有相应权限且未绑定 App 的 Agent / Personal Key 可以使用,App Key 当前不能使用。App 已知集合 ID 时可直接用 `recordFind` 读取记录;需要发现可访问集合及结构时使用 `client.uns.dataAppContext({})`。`appCollectionsList` 也是管理接口,不能作为 App Key 的替代入口。
86
+
87
+ SDK 不从 Key 前缀推断权限,也不在 403 后换凭证或回退内部接口。Agent 程序、SDK、MCP 都不能扩大所持凭证的权限。身份区别和排错见[命名空间查询与凭证](skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/namespace.md),App 读取示例见[查询集合与记录](skills/tier0-sdk-v2/tier0-sdk-v2-uns/references/read.md)。
88
+
77
89
  ## 本次接口退役
78
90
 
79
91
  HTTP 调用统一使用 `/openapi/v2`。21 个重复 UNS 公共入口及生成方法直接移除,没有旧路由回退;升级 SDK 时需同时部署对应后端。
@@ -0,0 +1,2 @@
1
+ /** Static advice only: never include credentials, response bodies or configured URLs. */
2
+ export declare function invalidResponseHint(status: number): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.invalidResponseHint = invalidResponseHint;
4
+ /** Static advice only: never include credentials, response bodies or configured URLs. */
5
+ function invalidResponseHint(status) {
6
+ if (status === 404 || status === 405) {
7
+ return 'Check apiHost / TIER0_API_HOST: use this environment\'s OpenAPI gateway base URL, not its platform webpage or MCP URL. Confirm that the gateway exposes /openapi/v2 routes; obtain the address from the environment deployment guide or administrator.';
8
+ }
9
+ if (status === 401) {
10
+ return 'Check that apiHost / TIER0_API_HOST targets the intended OpenAPI gateway, then check that the API key is present, valid and belongs to that environment. An intermediary may also require authentication.';
11
+ }
12
+ if (status === 403) {
13
+ return 'Check the credential\'s permissions for this operation and any gateway access restrictions. A non-JSON response alone does not prove the API key is invalid.';
14
+ }
15
+ if (status === 502 || status === 503 || status === 504) {
16
+ return 'The gateway or upstream service may be temporarily unavailable. Check service health; do not replace the API key based on this response. Before repeating a write, check whether it committed.';
17
+ }
18
+ return 'Check apiHost / TIER0_API_HOST and the gateway response format against the environment deployment guide; OpenAPI JSON responses are required.';
19
+ }
20
+ //# sourceMappingURL=connection-diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-diagnostics.js","sourceRoot":"","sources":["../../src/connection-diagnostics.ts"],"names":[],"mappings":";;AACA,kDAcC;AAfD,yFAAyF;AACzF,SAAgB,mBAAmB,CAAC,MAAc;IAChD,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACrC,OAAO,wPAAwP,CAAC;IAClQ,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,2MAA2M,CAAC;IACrN,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,8JAA8J,CAAC;IACxK,CAAC;IACD,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACvD,OAAO,gMAAgM,CAAC;IAC1M,CAAC;IACD,OAAO,+IAA+I,CAAC;AACzJ,CAAC","sourcesContent":["/** Static advice only: never include credentials, response bodies or configured URLs. */\nexport function invalidResponseHint(status: number): string {\n if (status === 404 || status === 405) {\n return 'Check apiHost / TIER0_API_HOST: use this environment\\'s OpenAPI gateway base URL, not its platform webpage or MCP URL. Confirm that the gateway exposes /openapi/v2 routes; obtain the address from the environment deployment guide or administrator.';\n }\n if (status === 401) {\n return 'Check that apiHost / TIER0_API_HOST targets the intended OpenAPI gateway, then check that the API key is present, valid and belongs to that environment. An intermediary may also require authentication.';\n }\n if (status === 403) {\n return 'Check the credential\\'s permissions for this operation and any gateway access restrictions. A non-JSON response alone does not prove the API key is invalid.';\n }\n if (status === 502 || status === 503 || status === 504) {\n return 'The gateway or upstream service may be temporarily unavailable. Check service health; do not replace the API key based on this response. Before repeating a write, check whether it committed.';\n }\n return 'Check apiHost / TIER0_API_HOST and the gateway response format against the environment deployment guide; OpenAPI JSON responses are required.';\n}\n"]}
@@ -16,7 +16,7 @@ import type { UnsV2Error, UnsV2Execution, UnsV2Retry } from '../uns-v2/client.js
16
16
  export declare const ACCESS_REASONS: {
17
17
  /** 403: the collection exists, but this App's grant does not cover it or the operation. */
18
18
  readonly notGranted: "COLLECTION_NOT_GRANTED";
19
- /** 403 or 404: the collection is gone (hard-deleted or archived). */
19
+ /** 403 or 404: the collection is missing, or the write target is archived. */
20
20
  readonly notFound: "COLLECTION_NOT_FOUND";
21
21
  /** 403: the grant covers the operation, the App key lacks `data.missingPermission`. */
22
22
  readonly permissionMissing: "APP_PERMISSION_MISSING";
@@ -11,7 +11,7 @@ exports.toDataError = toDataError;
11
11
  exports.ACCESS_REASONS = {
12
12
  /** 403: the collection exists, but this App's grant does not cover it or the operation. */
13
13
  notGranted: 'COLLECTION_NOT_GRANTED',
14
- /** 403 or 404: the collection is gone (hard-deleted or archived). */
14
+ /** 403 or 404: the collection is missing, or the write target is archived. */
15
15
  notFound: 'COLLECTION_NOT_FOUND',
16
16
  /** 403: the grant covers the operation, the App key lacks `data.missingPermission`. */
17
17
  permissionMissing: 'APP_PERMISSION_MISSING',
@@ -92,7 +92,7 @@ const CODE_HINTS = {
92
92
  VERSION_CONFLICT: 'The record changed since it was read; reload it and retry with the new revision.',
93
93
  APP_GRANT_REVOKED: "A workspace admin revoked this App's access to the collection; it is not re-granted automatically. Ask the admin to restore the grant.",
94
94
  INDEX_QUOTA_EXCEEDED: 'The workspace index quota (200, counting every index that physically exists) is exhausted. Remove unused indexes through the tier0 MCP.',
95
- COLLECTION_TOO_LARGE: 'archive / restore handle at most 2000 records; stop using a large collection in code instead of archiving it.',
95
+ COLLECTION_TOO_LARGE: 'Legacy recordsArchivedAt restoration handles at most 2000 records; current collection archive / restore retains records without that limit.',
96
96
  OVERLOADED: "This workspace's data requests are over their concurrency share; the data layer already waited and retried. Batch page reads with data.queryBatch and avoid per-record loops.",
97
97
  APP_NOT_READY: 'The platform is still preparing this App (e.g. right after an import); retry shortly.',
98
98
  QUERY_TIMEOUT: 'Narrow the query: add an indexed condition, a smaller limit or maxCount.',
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/data/error.ts"],"names":[],"mappings":";;;AAgGA,8BASC;AAmDD,kCAqDC;AAtMD;;;;GAIG;AACU,QAAA,cAAc,GAAG;IAC5B,2FAA2F;IAC3F,UAAU,EAAE,wBAAwB;IACpC,qEAAqE;IACrE,QAAQ,EAAE,sBAAsB;IAChC,uFAAuF;IACvF,iBAAiB,EAAE,wBAAwB;CACnC,CAAC;AAEX,MAAa,SAAU,SAAQ,KAAK;IAClC,gEAAgE;IACvD,MAAM,CAAS;IACxB,kEAAkE;IACzD,IAAI,CAAS;IACtB,mFAAmF;IAC1E,MAAM,CAAU;IACzB,iEAAiE;IACxD,cAAc,CAAS;IACvB,SAAS,CAAU;IAC5B;;;;OAIG;IACM,SAAS,CAAiB;IACnC,0GAA0G;IACjG,KAAK,CAAa;IAC3B,0FAA0F;IACjF,cAAc,CAAU;IACjC,8EAA8E;IACrE,QAAQ,CAAS;IAC1B;;;;OAIG;IACM,cAAc,CAAU;IACjC,0EAA0E;IACjE,OAAO,CAA0B;IAE1C,YAAY,IAaX;QACC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAClF,IAAI,CAAC,IAAI,GA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AY;gBACrC,CAAC,CAAC,0FAA0F,IAAI,KAAK;oBACnG,oGAAoG;gBACtG,CAAC,CAAC,qBAAqB,OAAO,IAAI,CAAC,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,cAAc,wBAAwB,IAAI,2BAA2B,CAAC;IACzK,CAAC;SAAM,IAAI,MAAM,KAAK,sBAAc,CAAC,UAAU,EAAE,CAAC;QAChD,OAAO,GAAG,GAAG,OAAO,2GAA2G,CAAC;IAClI,CAAC;SAAM,IAAI,MAAM,KAAK,sBAAc,CAAC,QAAQ,EAAE,CAAC;QAC9C,OAAO,GAAG,GAAG,OAAO,iGAAiG,CAAC;IACxH,CAAC;SAAM,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QAC9B,OAAO,GAAG,yCAAyC,KAAK,CAAC,SAAS,KAAK,IAAI,2DAA2D,CAAC;IACzI,CAAC;SAAM,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,GAAG,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7I,CAAC","sourcesContent":["/**\n * Runtime failures of a data call, missing credentials included, are a\n * `DataError`. The SDK's UNS client does the HTTP exchange; its `UnsV2Error`\n * (kept as `cause`) is translated here, and the data layer raises its own codes\n * (BATCH_LIMIT_EXCEEDED, WRITE_ERRORS, ...). `status` is the HTTP status the App\n * should answer its own caller with. Writes that fail validation throw\n * `ZodError`; programming or platform errors, such as invalid client options or\n * a malformed data subject from the gateway, throw `TypeError`.\n */\nimport type { UnsV2Error, UnsV2Execution, UnsV2Retry } from '../uns-v2/client.js';\n\n/**\n * Stable `data.reason` codes UNS adds when it refuses App data access; the\n * top-level code stays FORBIDDEN / NOT_FOUND. Only whole-request errors carry\n * them, never per-item results of a batch or transaction.\n */\nexport const ACCESS_REASONS = {\n /** 403: the collection exists, but this App's grant does not cover it or the operation. */\n notGranted: 'COLLECTION_NOT_GRANTED',\n /** 403 or 404: the collection is gone (hard-deleted or archived). */\n notFound: 'COLLECTION_NOT_FOUND',\n /** 403: the grant covers the operation, the App key lacks `data.missingPermission`. */\n permissionMissing: 'APP_PERMISSION_MISSING',\n} as const;\n\nexport class DataError extends Error {\n /** HTTP status the App should answer with (see `appStatus`). */\n readonly status: number;\n /** UNS error code, e.g. `DUPLICATE_KEY`, or a data-layer code. */\n readonly code: string;\n /** Stable `data.reason` code, e.g. `COLLECTION_NOT_FOUND` (see ACCESS_REASONS). */\n readonly reason?: string;\n /** HTTP status UNS answered with; 0 when no response arrived. */\n readonly upstreamStatus: number;\n readonly requestId?: string;\n /**\n * How far the failed request got: `notStarted` / `rolledBack` changed\n * nothing, `committed` took effect, `unknown` (writes only) may have.\n * Data-layer refusals raised before sending are `notStarted`.\n */\n readonly execution: UnsV2Execution;\n /** Whether the same call may be repeated later, and after how long. The data layer already retried it. */\n readonly retry: UnsV2Retry;\n /** `execution === \"unknown\"`: a write may have landed. Read back before writing again. */\n readonly outcomeUnknown: boolean;\n /** Requests sent for this call, retries included; 0 when nothing was sent. */\n readonly attempts: number;\n /**\n * The idempotency key the write was sent with (generated unless the caller\n * gave one). After `outcomeUnknown`, sending the same write with this key\n * again cannot apply it twice.\n */\n readonly idempotencyKey?: string;\n /** The `data` object of the UNS error envelope, or data-layer details. */\n readonly details: Record<string, unknown>;\n\n constructor(init: {\n message: string;\n status: number;\n code: string;\n reason?: string;\n upstreamStatus?: number;\n requestId?: string;\n execution?: UnsV2Execution;\n retry?: UnsV2Retry;\n attempts?: number;\n idempotencyKey?: string;\n details?: Record<string, unknown>;\n cause?: unknown;\n }) {\n super(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n this.name = 'DataError';\n this.status = init.status;\n this.code = init.code;\n this.reason = init.reason;\n this.upstreamStatus = init.upstreamStatus ?? 0;\n this.requestId = init.requestId;\n this.execution = init.execution ?? 'notStarted';\n this.retry = init.retry ?? { safe: false };\n this.outcomeUnknown = this.execution === 'unknown';\n this.attempts = init.attempts ?? 0;\n this.idempotencyKey = init.idempotencyKey;\n this.details = init.details ?? {};\n }\n}\n\n/** Platform states the App's caller cannot fix: they answer 503 whatever UNS answered. */\nconst PLATFORM_CODES = new Set(['APP_NOT_READY', 'DEPENDENCY_UNAVAILABLE', 'CREDENTIAL_CHANGED', 'OUTCOME_UNKNOWN', 'TEMPORARILY_UNAVAILABLE']);\n\n/**\n * Maps an upstream UNS status and code to the status the App answers its own\n * caller with. Credential failures are the platform's problem, not the user's\n * session, so a 401 from UNS becomes 502 instead of looking like a logout;\n * platform states (App not ready yet, a dependency down, the App key changed\n * mid-request) become 503 instead of looking like a denied action or a conflict.\n */\nexport function appStatus(upstream: number, code = ''): number {\n if (upstream === 401) return 502;\n if (PLATFORM_CODES.has(code)) return 503;\n if (upstream === 400 || upstream === 403 || upstream === 404 || upstream === 409 || upstream === 413 || upstream === 422 || upstream === 429) {\n return upstream;\n }\n if (upstream === 502 || upstream === 503 || upstream === 504) return 503;\n if (upstream >= 500) return 502;\n return upstream >= 400 ? 400 : 502;\n}\n\nconst CODE_HINTS: Record<string, string> = {\n UPSERT_REQUIRES_UNIQUE_INDEX:\n 'An upsert filter must contain `_id` or every field of a unique index that is already ready; a newly declared unique index may still be building.',\n DUPLICATE_KEY:\n 'A unique index already holds this value. (From restore: an active record took the value meanwhile; nothing was restored.)',\n VERSION_CONFLICT: 'The record changed since it was read; reload it and retry with the new revision.',\n APP_GRANT_REVOKED:\n \"A workspace admin revoked this App's access to the collection; it is not re-granted automatically. Ask the admin to restore the grant.\",\n INDEX_QUOTA_EXCEEDED:\n 'The workspace index quota (200, counting every index that physically exists) is exhausted. Remove unused indexes through the tier0 MCP.',\n COLLECTION_TOO_LARGE:\n 'archive / restore handle at most 2000 records; stop using a large collection in code instead of archiving it.',\n OVERLOADED:\n \"This workspace's data requests are over their concurrency share; the data layer already waited and retried. Batch page reads with data.queryBatch and avoid per-record loops.\",\n APP_NOT_READY: 'The platform is still preparing this App (e.g. right after an import); retry shortly.',\n QUERY_TIMEOUT: 'Narrow the query: add an indexed condition, a smaller limit or maxCount.',\n OUTCOME_UNKNOWN: 'The write may have committed; read the record back before writing again.',\n};\n\n/** `APP_QUOTA_EXCEEDED` per `data.resource`; each per-App limit is 64. */\nconst QUOTA_HINTS: Record<string, string> = {\n collections: 'This App owns 64 active collections. Archive unused ones through the tier0 MCP.',\n indexes: \"This App's collections hold 64 indexes. Drop unused indexes from the declarations, then apply that with schema:replace through the tier0 MCP.\",\n archivedCollections:\n 'This App keeps 64 archived collections. Restore one, or ask a workspace admin to clean up archived collections.',\n};\n\n/** SDK transport failures: no UNS answer to map, so the data layer names them. */\nconst TRANSPORT_FAILURES: Record<string, { code: string; status: number; message: string }> = {\n UNS_V2_TRANSPORT_TIMEOUT: { code: 'DATA_TIMEOUT', status: 503, message: 'UNS did not answer in time' },\n UNS_V2_TRANSPORT_ERROR: { code: 'DATA_UNREACHABLE', status: 503, message: 'Cannot reach the Tier0 data service' },\n // The business request was aborted while the call was in flight (499: client closed request).\n UNS_V2_TRANSPORT_ABORTED: { code: 'DATA_ABORTED', status: 499, message: 'The data call was aborted' },\n UNS_V2_PROTOCOL_ERROR: { code: 'DATA_BAD_RESPONSE', status: 502, message: 'UNS answered with an invalid response' },\n};\n\nfunction codeHint(code: string, details: Record<string, unknown>): string | undefined {\n if (code === 'APP_QUOTA_EXCEEDED') {\n const resource = typeof details.resource === 'string' ? details.resource : '';\n return QUOTA_HINTS[resource] ?? 'This App reached a collection/index quota. Remove unused collections or indexes through the tier0 MCP.';\n }\n return CODE_HINTS[code];\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Translates a failed UNS call of the SDK client after `attempts` requests, sent with `idempotencyKey`. */\nexport function toDataError(error: UnsV2Error, attempts = 1, idempotencyKey?: string): DataError {\n const common = {\n upstreamStatus: error.status,\n requestId: error.requestId,\n execution: error.execution,\n retry: error.retry,\n attempts,\n idempotencyKey,\n cause: error,\n };\n const unknown = error.outcomeUnknown ? '; the write outcome is unknown' : '';\n // An ingress or load balancer answers 502/503/504 without the UNS envelope during\n // rolling releases and pod restarts, like any unavailable upstream. UNS v2 routes\n // answer every other error with the envelope (401/403/429 included), so other\n // unenveloped responses stay DATA_BAD_RESPONSE.\n if (error.code === 'UNS_V2_PROTOCOL_ERROR' && (error.status === 502 || error.status === 503 || error.status === 504)) {\n return new DataError({\n ...common,\n message: `The Tier0 data gateway answered ${error.operation} with HTTP ${error.status}${unknown}.`,\n status: 503,\n code: `HTTP_${error.status}`,\n });\n }\n const transport = TRANSPORT_FAILURES[error.code];\n if (transport) {\n return new DataError({ ...common, message: `${transport.message} (${error.operation})${unknown}.`, status: transport.status, code: transport.code });\n }\n\n const httpStatus = error.status ?? 0;\n const data = isObject(error.data) ? error.data : {};\n // Only `data.reason` is a code; `error.reason` repeats the message text.\n const reason = typeof data.reason === 'string' ? data.reason : undefined;\n const code = error.code;\n const msg = error.message;\n const hint = codeHint(code, data) ?? error.repair;\n let message = `${msg} (${code})`;\n if (reason === ACCESS_REASONS.permissionMissing) {\n message =\n data.missingPermission === 'uns.delete'\n ? `Deleting records requires the App key to hold uns.delete, and this App's key does not (${code}). ` +\n 'Model removal as a status change such as `archived`, or ask a workspace admin to grant uns.delete.'\n : `The App key lacks ${typeof data.missingPermission === 'string' ? data.missingPermission : 'a permission'} for this operation (${code}); ask a workspace admin.`;\n } else if (reason === ACCESS_REASONS.notGranted) {\n message = `${message} This App's grant does not cover the collection or operation; ask a workspace admin to restore the grant.`;\n } else if (reason === ACCESS_REASONS.notFound) {\n message = `${message} The collection was archived or deleted; the data layer ensures the declared collections again.`;\n } else if (httpStatus === 401) {\n message = `Tier0 rejected the App credential for ${error.operation} (${code}). The platform injects TIER0_API_KEY; do not replace it.`;\n } else if (hint) {\n message = `${message} ${hint}`;\n }\n\n return new DataError({ ...common, message, status: appStatus(httpStatus, code), code, reason, upstreamStatus: httpStatus, details: data });\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/data/error.ts"],"names":[],"mappings":";;;AAgGA,8BASC;AAmDD,kCAqDC;AAtMD;;;;GAIG;AACU,QAAA,cAAc,GAAG;IAC5B,2FAA2F;IAC3F,UAAU,EAAE,wBAAwB;IACpC,8EAA8E;IAC9E,QAAQ,EAAE,sBAAsB;IAChC,uFAAuF;IACvF,iBAAiB,EAAE,wBAAwB;CACnC,CAAC;AAEX,MAAa,SAAU,SAAQ,KAAK;IAClC,gEAAgE;IACvD,MAAM,CAAS;IACxB,kEAAkE;IACzD,IAAI,CAAS;IACtB,mFAAmF;IAC1E,MAAM,CAAU;IACzB,iEAAiE;IACxD,cAAc,CAAS;IACvB,SAAS,CAAU;IAC5B;;;;OAIG;IACM,SAAS,CAAiB;IACnC,0GAA0G;IACjG,KAAK,CAAa;IAC3B,0FAA0F;IACjF,cAAc,CAAU;IACjC,8EAA8E;IACrE,QAAQ,CAAS;IAC1B;;;;OAIG;IACM,cAAc,CAAU;IACjC,0EAA0E;IACjE,OAAO,CAA0B;IAE1C,YAAY,IAaX;QACC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAClF,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CA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B,CAAC,CAAC,CAAC,cAAc,wBAAwB,IAAI,2BAA2B,CAAC;IACzK,CAAC;SAAM,IAAI,MAAM,KAAK,sBAAc,CAAC,UAAU,EAAE,CAAC;QAChD,OAAO,GAAG,GAAG,OAAO,2GAA2G,CAAC;IAClI,CAAC;SAAM,IAAI,MAAM,KAAK,sBAAc,CAAC,QAAQ,EAAE,CAAC;QAC9C,OAAO,GAAG,GAAG,OAAO,iGAAiG,CAAC;IACxH,CAAC;SAAM,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QAC9B,OAAO,GAAG,yCAAyC,KAAK,CAAC,SAAS,KAAK,IAAI,2DAA2D,CAAC;IACzI,CAAC;SAAM,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,GAAG,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7I,CAAC","sourcesContent":["/**\n * Runtime failures of a data call, missing credentials included, are a\n * `DataError`. The SDK's UNS client does the HTTP exchange; its `UnsV2Error`\n * (kept as `cause`) is translated here, and the data layer raises its own codes\n * (BATCH_LIMIT_EXCEEDED, WRITE_ERRORS, ...). `status` is the HTTP status the App\n * should answer its own caller with. Writes that fail validation throw\n * `ZodError`; programming or platform errors, such as invalid client options or\n * a malformed data subject from the gateway, throw `TypeError`.\n */\nimport type { UnsV2Error, UnsV2Execution, UnsV2Retry } from '../uns-v2/client.js';\n\n/**\n * Stable `data.reason` codes UNS adds when it refuses App data access; the\n * top-level code stays FORBIDDEN / NOT_FOUND. Only whole-request errors carry\n * them, never per-item results of a batch or transaction.\n */\nexport const ACCESS_REASONS = {\n /** 403: the collection exists, but this App's grant does not cover it or the operation. */\n notGranted: 'COLLECTION_NOT_GRANTED',\n /** 403 or 404: the collection is missing, or the write target is archived. */\n notFound: 'COLLECTION_NOT_FOUND',\n /** 403: the grant covers the operation, the App key lacks `data.missingPermission`. */\n permissionMissing: 'APP_PERMISSION_MISSING',\n} as const;\n\nexport class DataError extends Error {\n /** HTTP status the App should answer with (see `appStatus`). */\n readonly status: number;\n /** UNS error code, e.g. `DUPLICATE_KEY`, or a data-layer code. */\n readonly code: string;\n /** Stable `data.reason` code, e.g. `COLLECTION_NOT_FOUND` (see ACCESS_REASONS). */\n readonly reason?: string;\n /** HTTP status UNS answered with; 0 when no response arrived. */\n readonly upstreamStatus: number;\n readonly requestId?: string;\n /**\n * How far the failed request got: `notStarted` / `rolledBack` changed\n * nothing, `committed` took effect, `unknown` (writes only) may have.\n * Data-layer refusals raised before sending are `notStarted`.\n */\n readonly execution: UnsV2Execution;\n /** Whether the same call may be repeated later, and after how long. The data layer already retried it. */\n readonly retry: UnsV2Retry;\n /** `execution === \"unknown\"`: a write may have landed. Read back before writing again. */\n readonly outcomeUnknown: boolean;\n /** Requests sent for this call, retries included; 0 when nothing was sent. */\n readonly attempts: number;\n /**\n * The idempotency key the write was sent with (generated unless the caller\n * gave one). After `outcomeUnknown`, sending the same write with this key\n * again cannot apply it twice.\n */\n readonly idempotencyKey?: string;\n /** The `data` object of the UNS error envelope, or data-layer details. */\n readonly details: Record<string, unknown>;\n\n constructor(init: {\n message: string;\n status: number;\n code: string;\n reason?: string;\n upstreamStatus?: number;\n requestId?: string;\n execution?: UnsV2Execution;\n retry?: UnsV2Retry;\n attempts?: number;\n idempotencyKey?: string;\n details?: Record<string, unknown>;\n cause?: unknown;\n }) {\n super(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n this.name = 'DataError';\n this.status = init.status;\n this.code = init.code;\n this.reason = init.reason;\n this.upstreamStatus = init.upstreamStatus ?? 0;\n this.requestId = init.requestId;\n this.execution = init.execution ?? 'notStarted';\n this.retry = init.retry ?? { safe: false };\n this.outcomeUnknown = this.execution === 'unknown';\n this.attempts = init.attempts ?? 0;\n this.idempotencyKey = init.idempotencyKey;\n this.details = init.details ?? {};\n }\n}\n\n/** Platform states the App's caller cannot fix: they answer 503 whatever UNS answered. */\nconst PLATFORM_CODES = new Set(['APP_NOT_READY', 'DEPENDENCY_UNAVAILABLE', 'CREDENTIAL_CHANGED', 'OUTCOME_UNKNOWN', 'TEMPORARILY_UNAVAILABLE']);\n\n/**\n * Maps an upstream UNS status and code to the status the App answers its own\n * caller with. Credential failures are the platform's problem, not the user's\n * session, so a 401 from UNS becomes 502 instead of looking like a logout;\n * platform states (App not ready yet, a dependency down, the App key changed\n * mid-request) become 503 instead of looking like a denied action or a conflict.\n */\nexport function appStatus(upstream: number, code = ''): number {\n if (upstream === 401) return 502;\n if (PLATFORM_CODES.has(code)) return 503;\n if (upstream === 400 || upstream === 403 || upstream === 404 || upstream === 409 || upstream === 413 || upstream === 422 || upstream === 429) {\n return upstream;\n }\n if (upstream === 502 || upstream === 503 || upstream === 504) return 503;\n if (upstream >= 500) return 502;\n return upstream >= 400 ? 400 : 502;\n}\n\nconst CODE_HINTS: Record<string, string> = {\n UPSERT_REQUIRES_UNIQUE_INDEX:\n 'An upsert filter must contain `_id` or every field of a unique index that is already ready; a newly declared unique index may still be building.',\n DUPLICATE_KEY:\n 'A unique index already holds this value. (From restore: an active record took the value meanwhile; nothing was restored.)',\n VERSION_CONFLICT: 'The record changed since it was read; reload it and retry with the new revision.',\n APP_GRANT_REVOKED:\n \"A workspace admin revoked this App's access to the collection; it is not re-granted automatically. Ask the admin to restore the grant.\",\n INDEX_QUOTA_EXCEEDED:\n 'The workspace index quota (200, counting every index that physically exists) is exhausted. Remove unused indexes through the tier0 MCP.',\n COLLECTION_TOO_LARGE:\n 'Legacy recordsArchivedAt restoration handles at most 2000 records; current collection archive / restore retains records without that limit.',\n OVERLOADED:\n \"This workspace's data requests are over their concurrency share; the data layer already waited and retried. Batch page reads with data.queryBatch and avoid per-record loops.\",\n APP_NOT_READY: 'The platform is still preparing this App (e.g. right after an import); retry shortly.',\n QUERY_TIMEOUT: 'Narrow the query: add an indexed condition, a smaller limit or maxCount.',\n OUTCOME_UNKNOWN: 'The write may have committed; read the record back before writing again.',\n};\n\n/** `APP_QUOTA_EXCEEDED` per `data.resource`; each per-App limit is 64. */\nconst QUOTA_HINTS: Record<string, string> = {\n collections: 'This App owns 64 active collections. Archive unused ones through the tier0 MCP.',\n indexes: \"This App's collections hold 64 indexes. Drop unused indexes from the declarations, then apply that with schema:replace through the tier0 MCP.\",\n archivedCollections:\n 'This App keeps 64 archived collections. Restore one, or ask a workspace admin to clean up archived collections.',\n};\n\n/** SDK transport failures: no UNS answer to map, so the data layer names them. */\nconst TRANSPORT_FAILURES: Record<string, { code: string; status: number; message: string }> = {\n UNS_V2_TRANSPORT_TIMEOUT: { code: 'DATA_TIMEOUT', status: 503, message: 'UNS did not answer in time' },\n UNS_V2_TRANSPORT_ERROR: { code: 'DATA_UNREACHABLE', status: 503, message: 'Cannot reach the Tier0 data service' },\n // The business request was aborted while the call was in flight (499: client closed request).\n UNS_V2_TRANSPORT_ABORTED: { code: 'DATA_ABORTED', status: 499, message: 'The data call was aborted' },\n UNS_V2_PROTOCOL_ERROR: { code: 'DATA_BAD_RESPONSE', status: 502, message: 'UNS answered with an invalid response' },\n};\n\nfunction codeHint(code: string, details: Record<string, unknown>): string | undefined {\n if (code === 'APP_QUOTA_EXCEEDED') {\n const resource = typeof details.resource === 'string' ? details.resource : '';\n return QUOTA_HINTS[resource] ?? 'This App reached a collection/index quota. Remove unused collections or indexes through the tier0 MCP.';\n }\n return CODE_HINTS[code];\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Translates a failed UNS call of the SDK client after `attempts` requests, sent with `idempotencyKey`. */\nexport function toDataError(error: UnsV2Error, attempts = 1, idempotencyKey?: string): DataError {\n const common = {\n upstreamStatus: error.status,\n requestId: error.requestId,\n execution: error.execution,\n retry: error.retry,\n attempts,\n idempotencyKey,\n cause: error,\n };\n const unknown = error.outcomeUnknown ? '; the write outcome is unknown' : '';\n // An ingress or load balancer answers 502/503/504 without the UNS envelope during\n // rolling releases and pod restarts, like any unavailable upstream. UNS v2 routes\n // answer every other error with the envelope (401/403/429 included), so other\n // unenveloped responses stay DATA_BAD_RESPONSE.\n if (error.code === 'UNS_V2_PROTOCOL_ERROR' && (error.status === 502 || error.status === 503 || error.status === 504)) {\n return new DataError({\n ...common,\n message: `The Tier0 data gateway answered ${error.operation} with HTTP ${error.status}${unknown}.`,\n status: 503,\n code: `HTTP_${error.status}`,\n });\n }\n const transport = TRANSPORT_FAILURES[error.code];\n if (transport) {\n return new DataError({ ...common, message: `${transport.message} (${error.operation})${unknown}.`, status: transport.status, code: transport.code });\n }\n\n const httpStatus = error.status ?? 0;\n const data = isObject(error.data) ? error.data : {};\n // Only `data.reason` is a code; `error.reason` repeats the message text.\n const reason = typeof data.reason === 'string' ? data.reason : undefined;\n const code = error.code;\n const msg = error.message;\n const hint = codeHint(code, data) ?? error.repair;\n let message = `${msg} (${code})`;\n if (reason === ACCESS_REASONS.permissionMissing) {\n message =\n data.missingPermission === 'uns.delete'\n ? `Deleting records requires the App key to hold uns.delete, and this App's key does not (${code}). ` +\n 'Model removal as a status change such as `archived`, or ask a workspace admin to grant uns.delete.'\n : `The App key lacks ${typeof data.missingPermission === 'string' ? data.missingPermission : 'a permission'} for this operation (${code}); ask a workspace admin.`;\n } else if (reason === ACCESS_REASONS.notGranted) {\n message = `${message} This App's grant does not cover the collection or operation; ask a workspace admin to restore the grant.`;\n } else if (reason === ACCESS_REASONS.notFound) {\n message = `${message} The collection was archived or deleted; the data layer ensures the declared collections again.`;\n } else if (httpStatus === 401) {\n message = `Tier0 rejected the App credential for ${error.operation} (${code}). The platform injects TIER0_API_KEY; do not replace it.`;\n } else if (hint) {\n message = `${message} ${hint}`;\n }\n\n return new DataError({ ...common, message, status: appStatus(httpStatus, code), code, reason, upstreamStatus: httpStatus, details: data });\n}\n"]}
@@ -5,6 +5,7 @@ exports.responseError = responseError;
5
5
  exports.configureClient = configureClient;
6
6
  exports.getClient = getClient;
7
7
  const runtime_env_js_1 = require("../runtime-env.js");
8
+ const connection_diagnostics_js_1 = require("../connection-diagnostics.js");
8
9
  const codec_js_1 = require("../uns-v2/codec.js");
9
10
  class ApiError extends Error {
10
11
  status;
@@ -186,7 +187,7 @@ class HttpClient {
186
187
  }
187
188
  catch {
188
189
  if (!response.ok)
189
- throw new ApiError(response.status, 0, 'Non-JSON API error');
190
+ throw new ApiError(response.status, 0, `Non-JSON API error. ${(0, connection_diagnostics_js_1.invalidResponseHint)(response.status)}`);
190
191
  throw new TransportError('PROTOCOL', !operation.readonly, response.status);
191
192
  }
192
193
  if (!response.ok)
@@ -209,7 +210,7 @@ class HttpClient {
209
210
  value = (0, codec_js_1.decodeUnsV2JSON)(response.text, 'V1_Empty');
210
211
  }
211
212
  catch {
212
- throw new ApiError(response.status, 0, 'Invalid API response');
213
+ throw new ApiError(response.status, 0, `Invalid API response. ${(0, connection_diagnostics_js_1.invalidResponseHint)(response.status)}`);
213
214
  }
214
215
  if (!response.ok || (record(value) && typeof value.code === 'number' && value.code !== 200))
215
216
  throw responseError(response.status, value);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/openapi/client.ts"],"names":[],"mappings":";;;AA4CA,sCAIC;AA6ID,0CAAuG;AACvG,8BAAiE;AA9LjE,sDAA8C;AAC9C,iDAAsE;AAyBtE,MAAa,QAAS,SAAQ,KAAK;IAGZ;IAAyB;IAAuB;IAF5D,SAAS,CAAU;IACnB,cAAc,CAAU;IACjC,YAAqB,MAAc,EAAW,IAAY,EAAW,GAAW,EAC9E,UAA4D,EAAE;QAC9D,KAAK,CAAC,QAAQ,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAA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IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACzI,OAAO,KAAU,CAAC;IACpB,CAAC;IACD,GAAG,CAAI,IAAY,EAAE,OAAwB,IAAgB,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAChH,IAAI,CAAI,IAAY,EAAE,IAAa,EAAE,OAAwB,IAAgB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAC7H;AAtID,gCAsIC;AAED,yFAAyF;AACzF,IAAI,aAAa,GAAG,IAAI,UAAU,EAAE,CAAC;AACrC,SAAgB,eAAe,CAAC,MAAoB,IAAU,aAAa,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvG,SAAgB,SAAS,KAAiB,OAAO,aAAa,CAAC,CAAC,CAAC","sourcesContent":["import { getEnvVar } from '../runtime-env.js';\nimport { decodeUnsV2JSON, encodeUnsV2JSON } from '../uns-v2/codec.js';\n\nexport interface ClientConfig {\n apiHost?: string;\n apiKey?: string;\n getApiHost?: () => string | undefined;\n getApiKey?: () => string | undefined;\n fetch?: typeof globalThis.fetch;\n transportTimeoutMs?: number;\n}\nexport interface RequestOptions { signal?: AbortSignal }\nexport interface Operation {\n method: string;\n path: string;\n readonly pathParams: readonly string[];\n mode: 'envelope' | 'direct' | 'download';\n readonly: boolean;\n requestSchema?: string;\n responseSchema: string;\n}\nexport interface OperationInput {\n params?: Record<string, string>;\n query?: object;\n body?: unknown;\n}\nexport class ApiError extends Error {\n readonly errorCode?: string;\n readonly outcomeUnknown: boolean;\n constructor(readonly status: number, readonly code: number, readonly msg: string,\n details: { errorCode?: string; outcomeUnknown?: boolean } = {}) {\n super(`HTTP ${status}: ${msg}`);\n this.name = 'ApiError';\n this.errorCode = details.errorCode;\n this.outcomeUnknown = details.outcomeUnknown ?? false;\n }\n}\nexport class TransportError extends ApiError {\n constructor(kind: 'TIMEOUT' | 'ABORTED' | 'NETWORK' | 'PROTOCOL', outcomeUnknown: boolean, status = 0) {\n super(status, 0, `Tier0 SDK v2 ${kind.toLowerCase()} error`, { errorCode: `SDK_${kind}`, outcomeUnknown });\n this.name = 'TransportError';\n }\n}\nconst record = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);\nexport function responseError(status: number, value: unknown, fallback = 'Request failed'): ApiError {\n return new ApiError(status, record(value) && typeof value.code === 'number' ? value.code : 0,\n record(value) && typeof value.message === 'string' ? value.message : record(value) && typeof value.msg === 'string' ? value.msg : fallback,\n { errorCode: record(value) && typeof value.errorCode === 'string' ? value.errorCode : undefined });\n}\n\n/** An immutable configuration snapshot. Each request resolves optional credential callbacks once. */\nexport class HttpClient {\n private readonly config: Readonly<ClientConfig>;\n readonly timeoutMs: number;\n constructor(config: ClientConfig = {}) {\n this.config = Object.freeze({ ...config });\n this.timeoutMs = config.transportTimeoutMs ?? 60_000;\n if (!Number.isInteger(this.timeoutMs) || this.timeoutMs < 1 || this.timeoutMs > 2_147_483_647) throw new TypeError('Invalid transportTimeoutMs');\n }\n getBaseURL(): string {\n const host = this.config.apiHost ?? this.config.getApiHost?.() ?? getEnvVar('TIER0_API_HOST');\n if (!host?.trim()) throw new Error('Tier0 SDK v2: apiHost or TIER0_API_HOST is required.');\n const base = host.trim().replace(/\\/+$/, '');\n const url = new URL(/^https?:\\/\\//i.test(base) ? base : `https://${base}`);\n if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new TypeError('Invalid apiHost');\n return url.href.replace(/\\/+$/, '');\n }\n getApiKey(): string | undefined { return this.config.apiKey ?? this.config.getApiKey?.() ?? getEnvVar('TIER0_API_KEY'); }\n getFetch(): typeof globalThis.fetch { return this.config.fetch ?? globalThis.fetch; }\n\n private async exchange(path: string, init: RequestInit, options: RequestOptions, mutation: boolean): Promise<{ text: string; status: number; ok: boolean }> {\n if (!path.startsWith('/') || path.startsWith('//') || path.includes('\\\\')) throw new TypeError('A relative API path is required');\n const url = this.getBaseURL() + path;\n const key = this.getApiKey();\n const headers = new Headers(init.headers);\n headers.set('Content-Type', 'application/json');\n if (key) { headers.set('X-API-Key', key); headers.set('Authorization', `Bearer ${key}`); }\n const controller = new AbortController();\n let expired = false;\n let started = false;\n let response: Response | undefined;\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n let rejectAbort: (error: Error) => void = () => undefined;\n const fail = () => {\n controller.abort();\n void reader?.cancel().catch(() => undefined);\n rejectAbort(new TransportError(expired ? 'TIMEOUT' : 'ABORTED', mutation && started, response?.status));\n };\n const aborted = new Promise<never>((_, reject) => { rejectAbort = reject; });\n const timer = setTimeout(() => { expired = true; fail(); }, this.timeoutMs);\n options.signal?.addEventListener('abort', fail, { once: true });\n try {\n if (options.signal?.aborted) throw new TransportError('ABORTED', false);\n const request = async () => {\n started = true;\n try { response = await this.getFetch()(url, { ...init, headers, redirect: 'manual', signal: controller.signal }); }\n catch { throw new TransportError(expired ? 'TIMEOUT' : controller.signal.aborted ? 'ABORTED' : 'NETWORK', mutation, response?.status); }\n const maxBytes = 20 * 1024 * 1024;\n if (Number(response.headers.get('content-length')) > maxBytes) { await response.body?.cancel(); throw new TransportError('PROTOCOL', mutation, response.status); }\n if (!response.body) return { text: '', status: response.status, ok: response.ok };\n reader = response.body.getReader();\n const decoder = new TextDecoder('utf-8', { fatal: true });\n const chunks: string[] = [];\n let size = 0;\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n size += value.byteLength;\n if (size > maxBytes) { await reader.cancel(); throw new Error('Response too large'); }\n chunks.push(decoder.decode(value, { stream: true }));\n }\n chunks.push(decoder.decode());\n } catch { throw new TransportError('PROTOCOL', mutation, response.status); }\n finally { reader.releaseLock(); reader = undefined; }\n return { text: chunks.join(''), status: response.status, ok: response.ok };\n };\n return await Promise.race([request(), aborted]);\n } finally { clearTimeout(timer); options.signal?.removeEventListener('abort', fail); }\n }\n\n async operation<T>(operation: Operation, input: OperationInput = {}, options: RequestOptions = {}): Promise<T> {\n let path = operation.path;\n for (const name of operation.pathParams) {\n const value = input.params?.[name];\n if (!value || value === '.' || value === '..' || /[/\\\\\\u0000-\\u001f\\u007f]/.test(value)) throw new TypeError(`Invalid path parameter: ${name}`);\n path = path.replace(`{${name}}`, encodeURIComponent(value));\n }\n const query = new URLSearchParams();\n for (const [name, value] of Object.entries(input.query ?? {})) {\n if (value !== undefined) query.set(name, String(value));\n }\n if (query.size) path += `?${query}`;\n if (operation.mode === 'download') {\n // Resolve the signed URL through the JSON endpoint, then fetch without platform credentials.\n const urlPath = path.replace('/files/download', '/files/url');\n const result = await this.get<{ code: number; data?: { fileUrl?: string } }>(urlPath, options);\n if (result.code !== 200 || !result.data?.fileUrl) throw responseError(200, result, 'Invalid download URL response');\n const url = new URL(result.data.fileUrl);\n if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) throw new TypeError('Invalid download URL');\n const response = await this.getFetch()(url, { signal: options.signal, credentials: 'omit' });\n if (!response.ok) throw new ApiError(response.status, 0, 'File download failed');\n return response as T;\n }\n let body = input.body ?? {};\n if (path === '/openapi/v2/notifications/send') {\n if (!record(body)) throw new TypeError('Notification body must be an object');\n const channels = body.channels ?? ['web', 'mobile'];\n if (!Array.isArray(channels) || channels.some(c => c !== 'web' && c !== 'mobile')) throw new TypeError('Notification channels must be web or mobile');\n body = { ...body, channels: [...new Set(channels)] };\n }\n if (path === '/openapi/v2/apps/access-members/list' && record(body) && body.scope === undefined) {\n // The platform injects TIER0_RUNTIME: a Builder preview lists the draft roles, a deployment the production version.\n const runtime = getEnvVar('TIER0_RUNTIME');\n const scope = runtime === 'preview' ? 'draft' : runtime === 'deployed' ? 'production' : undefined;\n if (scope) body = { ...body, scope };\n }\n const serialized = operation.method === 'GET' ? undefined : encodeUnsV2JSON(body, operation.requestSchema ?? 'V1_Empty');\n const response = await this.exchange(path, { method: operation.method, body: serialized }, options, !operation.readonly);\n let value: unknown;\n try { value = decodeUnsV2JSON(response.text, operation.responseSchema); }\n catch {\n if (!response.ok) throw new ApiError(response.status, 0, 'Non-JSON API error');\n throw new TransportError('PROTOCOL', !operation.readonly, response.status);\n }\n if (!response.ok) throw responseError(response.status, value);\n if (operation.mode === 'envelope') {\n if (!record(value) || typeof value.code !== 'number') throw new TransportError('PROTOCOL', !operation.readonly, response.status);\n if (value.code !== 200) throw responseError(response.status, value);\n if (!Object.hasOwn(value, 'data')) throw new TransportError('PROTOCOL', !operation.readonly, response.status);\n return value.data as T;\n }\n return value as T;\n }\n\n private async raw<T>(method: string, path: string, body?: unknown, options: RequestOptions = {}): Promise<T> {\n const response = await this.exchange(path, { method, body: body === undefined ? undefined : encodeUnsV2JSON(body, 'V1_Empty') }, options, method !== 'GET');\n let value: unknown;\n try { value = decodeUnsV2JSON(response.text, 'V1_Empty'); }\n catch { throw new ApiError(response.status, 0, 'Invalid API response'); }\n if (!response.ok || (record(value) && typeof value.code === 'number' && value.code !== 200)) throw responseError(response.status, value);\n return value as T;\n }\n get<T>(path: string, options?: RequestOptions): Promise<T> { return this.raw('GET', path, undefined, options); }\n post<T>(path: string, body: unknown, options?: RequestOptions): Promise<T> { return this.raw('POST', path, body, options); }\n}\n\n// Used by standalone domain clients. createClient() never reads or changes this default.\nlet defaultClient = new HttpClient();\nexport function configureClient(config: ClientConfig): void { defaultClient = new HttpClient(config); }\nexport function getClient(): HttpClient { return defaultClient; }\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/openapi/client.ts"],"names":[],"mappings":";;;AA6CA,sCAIC;AA6ID,0CAAuG;AACvG,8BAAiE;AA/LjE,sDAA8C;AAC9C,4EAAmE;AACnE,iDAAsE;AAyBtE,MAAa,QAAS,SAAQ,K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B,IAAI,CAAC;YAAC,KAAK,GAAG,IAAA,0BAAe,EAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAAC,CAAC;QAC3D,MAAM,CAAC;YAAC,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,yBAAyB,IAAA,+CAAmB,EAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC;QAClH,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACzI,OAAO,KAAU,CAAC;IACpB,CAAC;IACD,GAAG,CAAI,IAAY,EAAE,OAAwB,IAAgB,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAChH,IAAI,CAAI,IAAY,EAAE,IAAa,EAAE,OAAwB,IAAgB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAC7H;AAtID,gCAsIC;AAED,yFAAyF;AACzF,IAAI,aAAa,GAAG,IAAI,UAAU,EAAE,CAAC;AACrC,SAAgB,eAAe,CAAC,MAAoB,IAAU,aAAa,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvG,SAAgB,SAAS,KAAiB,OAAO,aAAa,CAAC,CAAC,CAAC","sourcesContent":["import { getEnvVar } from '../runtime-env.js';\nimport { invalidResponseHint } from '../connection-diagnostics.js';\nimport { decodeUnsV2JSON, encodeUnsV2JSON } from '../uns-v2/codec.js';\n\nexport interface ClientConfig {\n apiHost?: string;\n apiKey?: string;\n getApiHost?: () => string | undefined;\n getApiKey?: () => string | undefined;\n fetch?: typeof globalThis.fetch;\n transportTimeoutMs?: number;\n}\nexport interface RequestOptions { signal?: AbortSignal }\nexport interface Operation {\n method: string;\n path: string;\n readonly pathParams: readonly string[];\n mode: 'envelope' | 'direct' | 'download';\n readonly: boolean;\n requestSchema?: string;\n responseSchema: string;\n}\nexport interface OperationInput {\n params?: Record<string, string>;\n query?: object;\n body?: unknown;\n}\nexport class ApiError extends Error {\n readonly errorCode?: string;\n readonly outcomeUnknown: boolean;\n constructor(readonly status: number, readonly code: number, readonly msg: string,\n details: { errorCode?: string; outcomeUnknown?: boolean } = {}) {\n super(`HTTP ${status}: ${msg}`);\n this.name = 'ApiError';\n this.errorCode = details.errorCode;\n this.outcomeUnknown = details.outcomeUnknown ?? false;\n }\n}\nexport class TransportError extends ApiError {\n constructor(kind: 'TIMEOUT' | 'ABORTED' | 'NETWORK' | 'PROTOCOL', outcomeUnknown: boolean, status = 0) {\n super(status, 0, `Tier0 SDK v2 ${kind.toLowerCase()} error`, { errorCode: `SDK_${kind}`, outcomeUnknown });\n this.name = 'TransportError';\n }\n}\nconst record = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);\nexport function responseError(status: number, value: unknown, fallback = 'Request failed'): ApiError {\n return new ApiError(status, record(value) && typeof value.code === 'number' ? value.code : 0,\n record(value) && typeof value.message === 'string' ? value.message : record(value) && typeof value.msg === 'string' ? value.msg : fallback,\n { errorCode: record(value) && typeof value.errorCode === 'string' ? value.errorCode : undefined });\n}\n\n/** An immutable configuration snapshot. Each request resolves optional credential callbacks once. */\nexport class HttpClient {\n private readonly config: Readonly<ClientConfig>;\n readonly timeoutMs: number;\n constructor(config: ClientConfig = {}) {\n this.config = Object.freeze({ ...config });\n this.timeoutMs = config.transportTimeoutMs ?? 60_000;\n if (!Number.isInteger(this.timeoutMs) || this.timeoutMs < 1 || this.timeoutMs > 2_147_483_647) throw new TypeError('Invalid transportTimeoutMs');\n }\n getBaseURL(): string {\n const host = this.config.apiHost ?? this.config.getApiHost?.() ?? getEnvVar('TIER0_API_HOST');\n if (!host?.trim()) throw new Error('Tier0 SDK v2: apiHost or TIER0_API_HOST is required.');\n const base = host.trim().replace(/\\/+$/, '');\n const url = new URL(/^https?:\\/\\//i.test(base) ? base : `https://${base}`);\n if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new TypeError('Invalid apiHost');\n return url.href.replace(/\\/+$/, '');\n }\n getApiKey(): string | undefined { return this.config.apiKey ?? this.config.getApiKey?.() ?? getEnvVar('TIER0_API_KEY'); }\n getFetch(): typeof globalThis.fetch { return this.config.fetch ?? globalThis.fetch; }\n\n private async exchange(path: string, init: RequestInit, options: RequestOptions, mutation: boolean): Promise<{ text: string; status: number; ok: boolean }> {\n if (!path.startsWith('/') || path.startsWith('//') || path.includes('\\\\')) throw new TypeError('A relative API path is required');\n const url = this.getBaseURL() + path;\n const key = this.getApiKey();\n const headers = new Headers(init.headers);\n headers.set('Content-Type', 'application/json');\n if (key) { headers.set('X-API-Key', key); headers.set('Authorization', `Bearer ${key}`); }\n const controller = new AbortController();\n let expired = false;\n let started = false;\n let response: Response | undefined;\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n let rejectAbort: (error: Error) => void = () => undefined;\n const fail = () => {\n controller.abort();\n void reader?.cancel().catch(() => undefined);\n rejectAbort(new TransportError(expired ? 'TIMEOUT' : 'ABORTED', mutation && started, response?.status));\n };\n const aborted = new Promise<never>((_, reject) => { rejectAbort = reject; });\n const timer = setTimeout(() => { expired = true; fail(); }, this.timeoutMs);\n options.signal?.addEventListener('abort', fail, { once: true });\n try {\n if (options.signal?.aborted) throw new TransportError('ABORTED', false);\n const request = async () => {\n started = true;\n try { response = await this.getFetch()(url, { ...init, headers, redirect: 'manual', signal: controller.signal }); }\n catch { throw new TransportError(expired ? 'TIMEOUT' : controller.signal.aborted ? 'ABORTED' : 'NETWORK', mutation, response?.status); }\n const maxBytes = 20 * 1024 * 1024;\n if (Number(response.headers.get('content-length')) > maxBytes) { await response.body?.cancel(); throw new TransportError('PROTOCOL', mutation, response.status); }\n if (!response.body) return { text: '', status: response.status, ok: response.ok };\n reader = response.body.getReader();\n const decoder = new TextDecoder('utf-8', { fatal: true });\n const chunks: string[] = [];\n let size = 0;\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n size += value.byteLength;\n if (size > maxBytes) { await reader.cancel(); throw new Error('Response too large'); }\n chunks.push(decoder.decode(value, { stream: true }));\n }\n chunks.push(decoder.decode());\n } catch { throw new TransportError('PROTOCOL', mutation, response.status); }\n finally { reader.releaseLock(); reader = undefined; }\n return { text: chunks.join(''), status: response.status, ok: response.ok };\n };\n return await Promise.race([request(), aborted]);\n } finally { clearTimeout(timer); options.signal?.removeEventListener('abort', fail); }\n }\n\n async operation<T>(operation: Operation, input: OperationInput = {}, options: RequestOptions = {}): Promise<T> {\n let path = operation.path;\n for (const name of operation.pathParams) {\n const value = input.params?.[name];\n if (!value || value === '.' || value === '..' || /[/\\\\\\u0000-\\u001f\\u007f]/.test(value)) throw new TypeError(`Invalid path parameter: ${name}`);\n path = path.replace(`{${name}}`, encodeURIComponent(value));\n }\n const query = new URLSearchParams();\n for (const [name, value] of Object.entries(input.query ?? {})) {\n if (value !== undefined) query.set(name, String(value));\n }\n if (query.size) path += `?${query}`;\n if (operation.mode === 'download') {\n // Resolve the signed URL through the JSON endpoint, then fetch without platform credentials.\n const urlPath = path.replace('/files/download', '/files/url');\n const result = await this.get<{ code: number; data?: { fileUrl?: string } }>(urlPath, options);\n if (result.code !== 200 || !result.data?.fileUrl) throw responseError(200, result, 'Invalid download URL response');\n const url = new URL(result.data.fileUrl);\n if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) throw new TypeError('Invalid download URL');\n const response = await this.getFetch()(url, { signal: options.signal, credentials: 'omit' });\n if (!response.ok) throw new ApiError(response.status, 0, 'File download failed');\n return response as T;\n }\n let body = input.body ?? {};\n if (path === '/openapi/v2/notifications/send') {\n if (!record(body)) throw new TypeError('Notification body must be an object');\n const channels = body.channels ?? ['web', 'mobile'];\n if (!Array.isArray(channels) || channels.some(c => c !== 'web' && c !== 'mobile')) throw new TypeError('Notification channels must be web or mobile');\n body = { ...body, channels: [...new Set(channels)] };\n }\n if (path === '/openapi/v2/apps/access-members/list' && record(body) && body.scope === undefined) {\n // The platform injects TIER0_RUNTIME: a Builder preview lists the draft roles, a deployment the production version.\n const runtime = getEnvVar('TIER0_RUNTIME');\n const scope = runtime === 'preview' ? 'draft' : runtime === 'deployed' ? 'production' : undefined;\n if (scope) body = { ...body, scope };\n }\n const serialized = operation.method === 'GET' ? undefined : encodeUnsV2JSON(body, operation.requestSchema ?? 'V1_Empty');\n const response = await this.exchange(path, { method: operation.method, body: serialized }, options, !operation.readonly);\n let value: unknown;\n try { value = decodeUnsV2JSON(response.text, operation.responseSchema); }\n catch {\n if (!response.ok) throw new ApiError(response.status, 0, `Non-JSON API error. ${invalidResponseHint(response.status)}`);\n throw new TransportError('PROTOCOL', !operation.readonly, response.status);\n }\n if (!response.ok) throw responseError(response.status, value);\n if (operation.mode === 'envelope') {\n if (!record(value) || typeof value.code !== 'number') throw new TransportError('PROTOCOL', !operation.readonly, response.status);\n if (value.code !== 200) throw responseError(response.status, value);\n if (!Object.hasOwn(value, 'data')) throw new TransportError('PROTOCOL', !operation.readonly, response.status);\n return value.data as T;\n }\n return value as T;\n }\n\n private async raw<T>(method: string, path: string, body?: unknown, options: RequestOptions = {}): Promise<T> {\n const response = await this.exchange(path, { method, body: body === undefined ? undefined : encodeUnsV2JSON(body, 'V1_Empty') }, options, method !== 'GET');\n let value: unknown;\n try { value = decodeUnsV2JSON(response.text, 'V1_Empty'); }\n catch { throw new ApiError(response.status, 0, `Invalid API response. ${invalidResponseHint(response.status)}`); }\n if (!response.ok || (record(value) && typeof value.code === 'number' && value.code !== 200)) throw responseError(response.status, value);\n return value as T;\n }\n get<T>(path: string, options?: RequestOptions): Promise<T> { return this.raw('GET', path, undefined, options); }\n post<T>(path: string, body: unknown, options?: RequestOptions): Promise<T> { return this.raw('POST', path, body, options); }\n}\n\n// Used by standalone domain clients. createClient() never reads or changes this default.\nlet defaultClient = new HttpClient();\nexport function configureClient(config: ClientConfig): void { defaultClient = new HttpClient(config); }\nexport function getClient(): HttpClient { return defaultClient; }\n"]}
@@ -1018,7 +1018,7 @@ export interface components {
1018
1018
  /** @description 人读显示名(接替废弃的 source),≤100字符 */
1019
1019
  name?: string;
1020
1020
  /**
1021
- * @description 枚举 app/other/system,缺省 other;system=平台内部服务,usage_type=internal 的 API key 可用;工作区系统 Key 须同时声明 sender.id=uns-agent;其他情况 400,建信归 workspace 分组(System tab)
1021
+ * @description 枚举 app/other/system,缺省 other;system 仅平台内部发送方(如 UNS Agent)可用;App 凭证不能使用 system,sender.type=app 时 sender.id 以凭证绑定的 App 为准;建信归 workspace 分组(System tab)
1022
1022
  * @default other
1023
1023
  * @enum {string}
1024
1024
  */