apaas-oapi-client 0.1.37 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -1
- package/package.json +14 -3
- package/skills/apaas-builder/SKILL.md +43 -0
- package/skills/apaas-builder/agents/openai.yaml +4 -0
- package/skills/apaas-exchange-attachment/SKILL.md +59 -0
- package/skills/apaas-exchange-attachment/agents/openai.yaml +4 -0
- package/skills/apaas-function-flow/SKILL.md +50 -0
- package/skills/apaas-function-flow/agents/openai.yaml +4 -0
- package/skills/apaas-global/SKILL.md +43 -0
- package/skills/apaas-global/agents/openai.yaml +4 -0
- package/skills/apaas-object/SKILL.md +99 -0
- package/skills/apaas-object/agents/openai.yaml +4 -0
- package/skills/apaas-schema/SKILL.md +77 -0
- package/skills/apaas-schema/agents/openai.yaml +4 -0
- package/skills/apaas-schema/references/field-schema-rules.md +98 -0
- package/skills/apaas-shared/SKILL.md +56 -0
- package/skills/apaas-shared/agents/openai.yaml +4 -0
- package/.env +0 -5
- package/.github/workflows/publish.yml +0 -36
- package/.vscode/settings.json +0 -9
- package/dist/src/index.d.ts +0 -674
- package/dist/src/limiter.d.ts +0 -17
- package/dist/src/logger.d.ts +0 -11
package/README.md
CHANGED
|
@@ -30,6 +30,42 @@
|
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
|
+
## 🤖 **AI Agent / Skills**
|
|
34
|
+
|
|
35
|
+
本仓库内置面向 AI Agent 的模块化 Skills,路径为 [skills](./skills)。设计采用 `shared + domain skill + references` 的轻量结构:主 `SKILL.md` 负责路由和安全边界,复杂规则放到 `references/` 按需读取。
|
|
36
|
+
|
|
37
|
+
| Skill | 适用场景 |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `apaas-shared` | Client 初始化、凭证安全、namespace、token、日志、分页与错误处理 |
|
|
40
|
+
| `apaas-object` | 对象列表、字段元数据、记录查询/创建/更新/删除、Markdown 导出 |
|
|
41
|
+
| `apaas-schema` | 对象和字段结构管理、字段类型映射、lookup/reference 依赖规则 |
|
|
42
|
+
| `apaas-function-flow` | 云函数调用、自动化流程 v1/v2 执行 |
|
|
43
|
+
| `apaas-builder` | 页面列表、页面详情、页面访问链接 |
|
|
44
|
+
| `apaas-global` | 全局选项、环境变量读取与审计 |
|
|
45
|
+
| `apaas-exchange-attachment` | 用户/部门 ID 交换、附件和头像上传下载 |
|
|
46
|
+
|
|
47
|
+
从仓库根目录安装到 Codex Skill 目录:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
mkdir -p "${CODEX_HOME:-$HOME/.codex}/skills"
|
|
51
|
+
cp -R skills/apaas-* "${CODEX_HOME:-$HOME/.codex}/skills/"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
从 npm 包所在项目安装:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
mkdir -p "${CODEX_HOME:-$HOME/.codex}/skills"
|
|
58
|
+
cp -R node_modules/apaas-oapi-client/skills/apaas-* "${CODEX_HOME:-$HOME/.codex}/skills/"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
使用建议:
|
|
62
|
+
|
|
63
|
+
- 写入前先用 `apaas-object` 读取真实 metadata。
|
|
64
|
+
- Schema 字段变更前先读 `apaas-schema/references/field-schema-rules.md`。
|
|
65
|
+
- 删除、批量写入、流程执行都按写操作处理,先确认目标和影响。
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
33
69
|
## 📦 **安装**
|
|
34
70
|
|
|
35
71
|
```bash
|
|
@@ -38,7 +74,7 @@ npm install apaas-oapi-client
|
|
|
38
74
|
|
|
39
75
|
---
|
|
40
76
|
|
|
41
|
-
##
|
|
77
|
+
## 🚀 **快速开始**
|
|
42
78
|
|
|
43
79
|
### 创建数据对象
|
|
44
80
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apaas-oapi-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -14,8 +14,19 @@
|
|
|
14
14
|
"dev": "tsx src/index.ts",
|
|
15
15
|
"release": "npm run build && npm version patch && git push origin main --follow-tags"
|
|
16
16
|
},
|
|
17
|
-
"keywords": [
|
|
17
|
+
"keywords": [
|
|
18
|
+
"apaas",
|
|
19
|
+
"openapi",
|
|
20
|
+
"nodejs",
|
|
21
|
+
"sdk",
|
|
22
|
+
"ai-agent",
|
|
23
|
+
"codex-skill"
|
|
24
|
+
],
|
|
18
25
|
"author": "",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/ennann/apaas-oapi-node-client"
|
|
29
|
+
},
|
|
19
30
|
"license": "ISC",
|
|
20
31
|
"dependencies": {
|
|
21
32
|
"axios": "^1.10.0",
|
|
@@ -35,5 +46,5 @@
|
|
|
35
46
|
"tsx": "^4.21.0",
|
|
36
47
|
"typescript": "^5.8.3"
|
|
37
48
|
},
|
|
38
|
-
"description": ""
|
|
49
|
+
"description": "aPaaS OpenAPI Node.js 客户端 SDK,内置 AI Agent 友好的模块化 Skills 与 Schema 辅助规则。"
|
|
39
50
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-builder
|
|
3
|
+
description: "Use for aPaaS Node SDK builder page operations: listing pages, paginating page metadata, reading page details, generating page access URLs with pageParams, parentPageParams, navId, or tabId, and verifying page IDs from live metadata."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Builder
|
|
7
|
+
|
|
8
|
+
Use this skill for `client.page.*`.
|
|
9
|
+
|
|
10
|
+
## Resolve Page IDs
|
|
11
|
+
|
|
12
|
+
Start from live page metadata unless the user provides a confirmed page ID.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const { items } = await client.page.listWithIterator({ limit: 100 });
|
|
16
|
+
const target = items.find(page => page.name === "门店详情");
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Use returned `page_id` values in follow-up calls.
|
|
20
|
+
|
|
21
|
+
## Page Detail
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const detail = await client.page.detail({
|
|
25
|
+
page_id: "page_id"
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Use detail reads before generating links that require route parameters.
|
|
30
|
+
|
|
31
|
+
## Page URL
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const url = await client.page.url({
|
|
35
|
+
page_id: "page_id",
|
|
36
|
+
pageParams: { id: "record_id" },
|
|
37
|
+
parentPageParams: {},
|
|
38
|
+
navId: "nav_id",
|
|
39
|
+
tabId: "tab_id"
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Only include optional parameters that are required by the target page. Verify generated URLs by opening them or handing them to the user with the relevant page and record context.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-exchange-attachment
|
|
3
|
+
description: "Use for aPaaS Node SDK identity exchange and attachment operations: department ID exchange, user ID exchange, batch exchange with retry results, file upload/download/delete, avatar image upload/download, and safe handling of IDs and binary payloads."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Exchange Attachment
|
|
7
|
+
|
|
8
|
+
Use this skill for `client.department.*`, `client.user.*`, and `client.attachment.*`.
|
|
9
|
+
|
|
10
|
+
## Department Exchange
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const department = await client.department.exchange({
|
|
14
|
+
department_id_type: "department_id",
|
|
15
|
+
department_id: "1758534140403815"
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const batch = await client.department.batchExchange({
|
|
19
|
+
department_id_type: "external_department_id",
|
|
20
|
+
department_ids: ["dept-a", "dept-b"]
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Check `failedCount` after batch exchange.
|
|
25
|
+
|
|
26
|
+
## User Exchange
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const user = await client.user.exchange({
|
|
30
|
+
user_id_type: "external_open_id",
|
|
31
|
+
user_id: "ou_xxx",
|
|
32
|
+
feishu_app_id: "cli_xxx"
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const batch = await client.user.batchExchange({
|
|
36
|
+
user_id_type: "external_user_id",
|
|
37
|
+
user_ids: ["u1", "u2"],
|
|
38
|
+
feishu_app_id: "cli_xxx"
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Use real `feishu_app_id`; do not guess it from namespace.
|
|
43
|
+
|
|
44
|
+
## Attachments
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const uploaded = await client.attachment.file.upload({ file });
|
|
48
|
+
const data = await client.attachment.file.download({ file_id: "file_token" });
|
|
49
|
+
await client.attachment.file.delete({ file_id: "file_token" });
|
|
50
|
+
|
|
51
|
+
const avatar = await client.attachment.avatar.upload({ image });
|
|
52
|
+
const imageData = await client.attachment.avatar.download({ image_id: "image_token" });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Safety
|
|
56
|
+
|
|
57
|
+
- Confirm deletes before calling `attachment.file.delete`.
|
|
58
|
+
- Do not print binary payloads, raw access tokens, or private file contents.
|
|
59
|
+
- For record attachment fields, read object metadata first and write only the field shape expected by the platform.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-function-flow
|
|
3
|
+
description: "Use for aPaaS Node SDK cloud function and automation flow execution: invoking functions, executing v1/v2 flows, preparing operator payloads, checking returned code/msg/data, and avoiding unsafe repeated workflow submissions."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Function Flow
|
|
7
|
+
|
|
8
|
+
Use this skill for `client.function.*` and `client.automation.*`.
|
|
9
|
+
|
|
10
|
+
## Function Invoke
|
|
11
|
+
|
|
12
|
+
Use when the target is a named cloud function and the caller already knows the function contract.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const res = await client.function.invoke({
|
|
16
|
+
name: "SyncStoreManager",
|
|
17
|
+
params: {
|
|
18
|
+
store_id: "record_id"
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (res.code !== "0") {
|
|
23
|
+
throw new Error(res.msg || "function invoke failed");
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Automation Flow
|
|
28
|
+
|
|
29
|
+
Use `automation.v1.execute` only for v1 flow endpoints and `automation.v2.execute` for v2 endpoints. Always pass an explicit operator object from a real user record or documented service account.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const res = await client.automation.v2.execute({
|
|
33
|
+
flow_api_name: "store_manager_change",
|
|
34
|
+
operator: {
|
|
35
|
+
_id: 123456,
|
|
36
|
+
email: "operator@example.com"
|
|
37
|
+
},
|
|
38
|
+
params: {
|
|
39
|
+
store_id: "record_id",
|
|
40
|
+
new_manager_id: "user_record_id"
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Safety
|
|
46
|
+
|
|
47
|
+
- Treat flow execution as a write operation; confirm before triggering production workflows.
|
|
48
|
+
- Do not resubmit failed flows with `is_resubmit` unless the user explicitly requests it and `pre_instance_id` is known.
|
|
49
|
+
- Log flow/function names and result codes, not secrets or full sensitive payloads.
|
|
50
|
+
- If the flow mutates records, verify the target record after execution with `apaas-object`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-global
|
|
3
|
+
description: "Use for aPaaS Node SDK global data operations: reading global option details, listing global options, reading global variable details, listing global variables, paginating results, and resolving API names from live metadata."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Global
|
|
7
|
+
|
|
8
|
+
Use this skill for `client.global.*`.
|
|
9
|
+
|
|
10
|
+
## Global Options
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const option = await client.global.options.detail({
|
|
14
|
+
api_name: "store_status"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { total, items } = await client.global.options.listWithIterator({
|
|
18
|
+
limit: 100,
|
|
19
|
+
filter: { quickQuery: "status" }
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use global options to validate enum-like values before writing records or schema.
|
|
24
|
+
|
|
25
|
+
## Global Variables
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
const variable = await client.global.variables.detail({
|
|
29
|
+
api_name: "current_region"
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const variables = await client.global.variables.listWithIterator({
|
|
33
|
+
limit: 100
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Do not expose secrets from global variables. When reporting results, summarize key names and operational meaning instead of raw secret values.
|
|
38
|
+
|
|
39
|
+
## Rules
|
|
40
|
+
|
|
41
|
+
- Use `listWithIterator` for inventory or audit tasks.
|
|
42
|
+
- Use `detail` when an exact API name is known.
|
|
43
|
+
- Treat missing global values as configuration problems, not SDK bugs, until live metadata proves otherwise.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-object
|
|
3
|
+
description: "Use for aPaaS Node SDK object metadata and record operations: listing objects, reading fields, exporting metadata to Markdown, querying records, count, create, update, delete, batch operations, pagination, and record-level error recovery."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Object
|
|
7
|
+
|
|
8
|
+
Use this skill for `client.object.*`.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. Initialize the client with `apaas-shared`.
|
|
13
|
+
2. Resolve object and field API names from live metadata.
|
|
14
|
+
3. Read before write when the payload depends on field type or readonly status.
|
|
15
|
+
4. Use iterator helpers for full-result work.
|
|
16
|
+
5. Check SDK response codes and failed item lists.
|
|
17
|
+
|
|
18
|
+
## Metadata
|
|
19
|
+
|
|
20
|
+
Prefer metadata calls before record work:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const objects = await client.object.listWithIterator({
|
|
24
|
+
filter: { type: "custom", quickQuery: "store" },
|
|
25
|
+
limit: 50
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const fields = await client.object.metadata.fields({
|
|
29
|
+
object_name: "object_store"
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const markdown = await client.object.metadata.export2markdown({
|
|
33
|
+
object_names: ["object_store", "_user"]
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Use returned API names, not user-facing labels, in later calls.
|
|
38
|
+
|
|
39
|
+
## Record Reads
|
|
40
|
+
|
|
41
|
+
- Use `search.record` for one known record ID.
|
|
42
|
+
- Use `search.records` for one page.
|
|
43
|
+
- Use `search.recordsWithIterator` for full-table or full-filter tasks.
|
|
44
|
+
- Use `search.count` when only the count is needed.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const { total, items } = await client.object.search.recordsWithIterator({
|
|
48
|
+
object_name: "object_store",
|
|
49
|
+
data: {
|
|
50
|
+
need_total_count: true,
|
|
51
|
+
page_size: 100,
|
|
52
|
+
offset: 0,
|
|
53
|
+
select: ["_id", "store_code", "store_name"],
|
|
54
|
+
use_page_token: true
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Do not answer global max/min/top/count questions from a single page unless the user asked for a sample.
|
|
60
|
+
|
|
61
|
+
## Record Writes
|
|
62
|
+
|
|
63
|
+
Use storage fields only. Re-read metadata when unsure.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
await client.object.create.record({
|
|
67
|
+
object_name: "object_event_log",
|
|
68
|
+
record: {
|
|
69
|
+
name: "sync_started",
|
|
70
|
+
content: "nightly job started"
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await client.object.update.record({
|
|
75
|
+
object_name: "object_store",
|
|
76
|
+
record_id: "record_id",
|
|
77
|
+
record: { store_name: "新门店名称" }
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For large batches, use `recordsWithIterator` helpers and inspect failures:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
const result = await client.object.update.recordsWithIterator({
|
|
85
|
+
object_name: "object_store",
|
|
86
|
+
records,
|
|
87
|
+
limit: 100
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (result.failedCount > 0) {
|
|
91
|
+
console.warn(result.failed);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Delete Rules
|
|
96
|
+
|
|
97
|
+
- Confirm target object and record IDs before delete.
|
|
98
|
+
- Prefer `delete.recordsWithIterator` for large deletes so partial failures are visible.
|
|
99
|
+
- Report `successCount`, `failedCount`, and failed IDs after batch deletion.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-schema
|
|
3
|
+
description: "Use for aPaaS Node SDK schema management: creating objects, updating object labels/settings, adding/replacing/removing fields, deleting objects, field type mapping, lookup/reference field dependencies, and schema change safety checks."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Schema
|
|
7
|
+
|
|
8
|
+
Use this skill for `client.schema.*`.
|
|
9
|
+
|
|
10
|
+
## Required Reference
|
|
11
|
+
|
|
12
|
+
Before creating or updating fields, read `references/field-schema-rules.md`. It contains the verified metadata-to-create type mapping and dependency order.
|
|
13
|
+
|
|
14
|
+
## Workflow
|
|
15
|
+
|
|
16
|
+
1. Use `apaas-shared` to initialize the client.
|
|
17
|
+
2. Read current objects with `client.object.listWithIterator()`.
|
|
18
|
+
3. Read existing fields with `client.object.metadata.fields({ object_name })`.
|
|
19
|
+
4. Build the smallest schema payload that matches the requested change.
|
|
20
|
+
5. For dependency fields, create target objects first, then lookup fields, then reference fields.
|
|
21
|
+
6. After the call, re-read metadata to verify the effective schema.
|
|
22
|
+
|
|
23
|
+
## Create Object
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
await client.schema.create({
|
|
27
|
+
objects: [{
|
|
28
|
+
api_name: "product",
|
|
29
|
+
label: { zh_cn: "产品", en_us: "Product" },
|
|
30
|
+
settings: {
|
|
31
|
+
display_name: "name",
|
|
32
|
+
allow_search_fields: ["_id", "code", "name"],
|
|
33
|
+
search_layout: ["code", "name"]
|
|
34
|
+
},
|
|
35
|
+
fields: [{
|
|
36
|
+
api_name: "code",
|
|
37
|
+
label: { zh_cn: "产品编号", en_us: "Product Code" },
|
|
38
|
+
type: {
|
|
39
|
+
name: "text",
|
|
40
|
+
settings: { required: true, unique: true, max_length: 50 }
|
|
41
|
+
},
|
|
42
|
+
encrypt_type: "none"
|
|
43
|
+
}]
|
|
44
|
+
}]
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Update Object Or Fields
|
|
49
|
+
|
|
50
|
+
- Add field: `operator: "add"` and full field definition.
|
|
51
|
+
- Replace field: `operator: "replace"` and full `type.name + type.settings`.
|
|
52
|
+
- Remove field: `operator: "remove"` and `api_name` only.
|
|
53
|
+
- Update label/settings without field changes by omitting `fields`.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
await client.schema.update({
|
|
57
|
+
objects: [{
|
|
58
|
+
api_name: "product",
|
|
59
|
+
fields: [{
|
|
60
|
+
operator: "add",
|
|
61
|
+
api_name: "description",
|
|
62
|
+
label: { zh_cn: "产品描述", en_us: "Description" },
|
|
63
|
+
type: {
|
|
64
|
+
name: "text",
|
|
65
|
+
settings: { multiline: true, max_length: 100000 }
|
|
66
|
+
},
|
|
67
|
+
encrypt_type: "none"
|
|
68
|
+
}]
|
|
69
|
+
}]
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Delete Rules
|
|
74
|
+
|
|
75
|
+
- Confirm the object API names before `client.schema.delete`.
|
|
76
|
+
- Do not delete objects as a cleanup shortcut if records or references may still depend on them.
|
|
77
|
+
- Remove `reference_field` before removing its lookup field.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Field Schema Rules
|
|
2
|
+
|
|
3
|
+
Use this reference before `client.schema.create` or `client.schema.update` field changes.
|
|
4
|
+
|
|
5
|
+
- Verified source in this repo: `src/FIELD_SCHEMA_RULES.md`
|
|
6
|
+
- Machine-readable source: `src/field-schema-rules.ts`
|
|
7
|
+
- Verification date in source: `2026-02-10`
|
|
8
|
+
|
|
9
|
+
## Metadata To Create Type Mapping
|
|
10
|
+
|
|
11
|
+
| Metadata Type | Create Type | Notes |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `text` | `text` | Single-line text, commonly `max_length=255`. |
|
|
14
|
+
| `text_multiline` | `text` | Use `multiline=true`, commonly `max_length=100000`. |
|
|
15
|
+
| `bigint` | `bigint` | Same type name. |
|
|
16
|
+
| `number` | `float` | `number` create type fails. |
|
|
17
|
+
| `date` | `date` | Same type name. |
|
|
18
|
+
| `datetime` | `datetime` | Same type name. |
|
|
19
|
+
| `option` | `enum` | `option` create type fails. |
|
|
20
|
+
| `boolean` | `boolean` | Same type name. |
|
|
21
|
+
| `lookup` | `lookup` | Single value, `multiple=false`. |
|
|
22
|
+
| `lookup_multi` | `lookup` | Multi value, `multiple=true`. |
|
|
23
|
+
| `referenceField` | `reference_field` | Depends on a single-value lookup field. |
|
|
24
|
+
| `file` | `attachment` | `file` create type fails. |
|
|
25
|
+
| `autoId` | `auto_number` | `autoId` create type fails. |
|
|
26
|
+
| `richText` | `richText` | Same type name. |
|
|
27
|
+
| `mobileNumber` | `phone` | `mobileNumber` create type fails. |
|
|
28
|
+
| `avatarOrLogo` | `avatar` | `avatarOrLogo` create type fails. |
|
|
29
|
+
| `email` | `email` | Same type name. |
|
|
30
|
+
| `region` | `region` | Same type name. |
|
|
31
|
+
| `decimal` | `decimal` | Same type name. |
|
|
32
|
+
| `multilingual` | `multilingual` | Same type name. |
|
|
33
|
+
|
|
34
|
+
## Dependency Rules
|
|
35
|
+
|
|
36
|
+
- Create target objects before lookup fields that reference them.
|
|
37
|
+
- Create `lookup` or `lookup_multi` before `reference_field`.
|
|
38
|
+
- Use only a single-value `lookup` as `reference_field.current_lookup_field_api_name`.
|
|
39
|
+
- Do not use `lookup_multi` as the guide field for `reference_field`.
|
|
40
|
+
- Remove `reference_field` before removing its lookup field.
|
|
41
|
+
|
|
42
|
+
## Batch Update Rules
|
|
43
|
+
|
|
44
|
+
- `add`: use `operator: "add"` and send the full field definition.
|
|
45
|
+
- `replace`: use `operator: "replace"` and send full `type.name` plus `type.settings`.
|
|
46
|
+
- `remove`: use `operator: "remove"` and send only `api_name`.
|
|
47
|
+
- Label-only replace without `type` fails with `k_ec_000015 field type is required`.
|
|
48
|
+
|
|
49
|
+
## Option Colors
|
|
50
|
+
|
|
51
|
+
Allowed option colors:
|
|
52
|
+
|
|
53
|
+
- `blue`
|
|
54
|
+
- `cyan`
|
|
55
|
+
- `green`
|
|
56
|
+
- `yellow`
|
|
57
|
+
- `orange`
|
|
58
|
+
- `red`
|
|
59
|
+
- `magenta`
|
|
60
|
+
- `purple`
|
|
61
|
+
- `blueMagenta`
|
|
62
|
+
- `grey`
|
|
63
|
+
|
|
64
|
+
## Minimal Lookup Example
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
{
|
|
68
|
+
operator: "add",
|
|
69
|
+
api_name: "owner",
|
|
70
|
+
label: { zh_cn: "负责人", en_us: "Owner" },
|
|
71
|
+
type: {
|
|
72
|
+
name: "lookup",
|
|
73
|
+
settings: {
|
|
74
|
+
objectAPIName: "_user",
|
|
75
|
+
multiple: false
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
encrypt_type: "none"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Minimal Reference Field Example
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
{
|
|
86
|
+
operator: "add",
|
|
87
|
+
api_name: "owner_lark_id",
|
|
88
|
+
label: { zh_cn: "负责人飞书 ID", en_us: "Owner Lark ID" },
|
|
89
|
+
type: {
|
|
90
|
+
name: "reference_field",
|
|
91
|
+
settings: {
|
|
92
|
+
current_lookup_field_api_name: "owner",
|
|
93
|
+
target_reference_field_api_name: "_lark_user_id"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
encrypt_type: "none"
|
|
97
|
+
}
|
|
98
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apaas-shared
|
|
3
|
+
description: "Use for aPaaS Node SDK shared setup and safety rules: client initialization, credentials, namespace, token cache, logger level, pagination defaults, retry expectations, write/delete confirmation, and error triage before using module-specific apaas skills."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# aPaaS Shared
|
|
7
|
+
|
|
8
|
+
Use this skill before module-specific aPaaS SDK work.
|
|
9
|
+
|
|
10
|
+
## Baseline
|
|
11
|
+
|
|
12
|
+
- Use the Node SDK package `apaas-oapi-client`.
|
|
13
|
+
- Initialize one `apaas.Client` per namespace.
|
|
14
|
+
- Keep `clientId`, `clientSecret`, access tokens, and app secrets out of logs and final answers.
|
|
15
|
+
- Prefer `client.setLoggerLevel(3)` for normal work, `4` for debugging, and `5` only when inspecting non-sensitive payloads.
|
|
16
|
+
- Treat SDK responses with `code !== "0"` as failed even if the HTTP call succeeded.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { apaas } from "apaas-oapi-client";
|
|
20
|
+
|
|
21
|
+
const client = new apaas.Client({
|
|
22
|
+
clientId: process.env.APAAS_CLIENT_ID!,
|
|
23
|
+
clientSecret: process.env.APAAS_CLIENT_SECRET!,
|
|
24
|
+
namespace: process.env.APAAS_NAMESPACE!
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await client.init();
|
|
28
|
+
client.setLoggerLevel(3);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Safety Rules
|
|
32
|
+
|
|
33
|
+
- Read real metadata before writing records, fields, flows, or pages.
|
|
34
|
+
- Confirm user intent before destructive calls: record delete, batch delete, schema delete, field remove, attachment delete.
|
|
35
|
+
- For batch operations, inspect `failed`, `failedCount`, or per-item success fields before reporting completion.
|
|
36
|
+
- For full-table answers, use iterator methods and verify pagination is exhausted; a single page is only a sample.
|
|
37
|
+
- Do not write system fields, readonly fields, formula outputs, lookup outputs, or reference field outputs as ordinary record values.
|
|
38
|
+
|
|
39
|
+
## Module Routing
|
|
40
|
+
|
|
41
|
+
- Object metadata and record CRUD: use `apaas-object`.
|
|
42
|
+
- Object and field schema changes: use `apaas-schema`.
|
|
43
|
+
- Cloud functions and automation flows: use `apaas-function-flow`.
|
|
44
|
+
- Builder page metadata and links: use `apaas-builder`.
|
|
45
|
+
- Global options and variables: use `apaas-global`.
|
|
46
|
+
- User/department ID exchange and attachments: use `apaas-exchange-attachment`.
|
|
47
|
+
|
|
48
|
+
## Error Triage
|
|
49
|
+
|
|
50
|
+
| Symptom | First action |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| Permission or scope error | Verify app permissions and namespace; do not retry blindly. |
|
|
53
|
+
| Field value type mismatch | Re-read `client.object.metadata.fields({ object_name })`. |
|
|
54
|
+
| Missing field/object | Re-read object list or metadata; use API names from returned data. |
|
|
55
|
+
| Batch partially failed | Report failed items and retry only failed IDs/records when safe. |
|
|
56
|
+
| Rate limit or transient 5xx | Use SDK iterator/batch helpers and retry only idempotent reads or confirmed-safe writes. |
|