@lark-apaas/coding-steering 0.1.86 → 0.1.87-alpha.20261108113022
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/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-steering",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.87-alpha.20261108113022",
|
|
4
4
|
"description": "Stack-specific steering content for miaoda-coding templates",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"steering"
|
|
8
8
|
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint:md": "markdownlint 'steering/**/*.md' --ignore 'steering/**/skills/**' --ignore 'steering/**/skills_common/**' --ignore 'steering/**/skills_local/**'"
|
|
11
|
+
},
|
|
9
12
|
"devDependencies": {
|
|
10
13
|
"markdownlint-cli": "^0.47.0"
|
|
11
14
|
},
|
|
@@ -17,8 +20,5 @@
|
|
|
17
20
|
"miaoda",
|
|
18
21
|
"coding-steering"
|
|
19
22
|
],
|
|
20
|
-
"license": "MIT"
|
|
21
|
-
|
|
22
|
-
"lint:md": "markdownlint 'steering/**/*.md' --ignore 'steering/**/skills/**' --ignore 'steering/**/skills_common/**' --ignore 'steering/**/skills_local/**'"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: anycross-forward
|
|
3
|
-
description: "Use when
|
|
3
|
+
description: "Use when 在妙搭应用中通过 HttpForwarderService 或平台内置 /api/__platform__/http-forward 接入客户内网、企业自建系统的 HTTP/HTTPS API,例如 ERP、OA、内部订单服务,或用户明确要求 anycross/http-forward。目标平台已有专用接入指南时,先按该指南确定鉴权与请求通路。触发词:客户内网、企业自建系统、anycross、http-forward、HttpForwarderService。"
|
|
4
4
|
steering: true
|
|
5
5
|
steering-topic: anycross_forward
|
|
6
6
|
steering-inclusion: manual
|
|
@@ -16,6 +16,8 @@ unavailable-agents:
|
|
|
16
16
|
|
|
17
17
|
# anycross-forward 内网请求转发指南
|
|
18
18
|
|
|
19
|
+
适用于客户内网和企业自建系统的通用 HTTP 转发。目标平台有专用的代理或身份接入指南时,先按该指南选择请求通路和鉴权方式。
|
|
20
|
+
|
|
19
21
|
通过平台内置的 http-forwarder 把请求转发到客户内网地址。后端 SDK 通过 `PlatformModule.forRoot()` **自动装配**,业务零接入。**默认在 node 侧用 `HttpForwarderService.fetch()` 调用**;前端 `axiosForBackend` 直调 `/api/__platform__/http-forward` 只用于"无凭证、只读、URL 可暴露"的例外场景。
|
|
20
22
|
|
|
21
23
|
> SDK 不感知代理 / 鉴权 / 隧道。实际通路由部署环境(沙箱 mihomo + iptables)处理,生成代码里**不要**拼 `proxy_group_id` / `jwtToken` / `anycross-host`。
|
|
@@ -24,6 +26,9 @@ unavailable-agents:
|
|
|
24
26
|
|
|
25
27
|
```text
|
|
26
28
|
需要请求一个 HTTP 接口?
|
|
29
|
+
│
|
|
30
|
+
├─ 目标平台已有专用代理或身份接入指南?
|
|
31
|
+
│ └─ 是 ──→ 按专用指南选择通路与鉴权
|
|
27
32
|
│
|
|
28
33
|
├─ 目标是平台内置 capability / Dataloom?
|
|
29
34
|
│ └─ 是 ──→ 用对应 SDK,不走 forwarder
|
|
@@ -107,13 +112,13 @@ export class CorpApiService {
|
|
|
107
112
|
- `fetch()` 返回 Web `Response`(`.json()` / `.text()` / `.arrayBuffer()`);上游 4xx/5xx 返回 `ok=false` **不抛**;forwarder 自身错(非法 URL / 上游不可达 / 超时 / 非法 header / 不支持的 body)抛 `HttpException`,`getResponse()` 为 `{ code, message }`。
|
|
108
113
|
- body 仅 `string` / JSON-able object / `null`;Buffer / FormData / URLSearchParams / Blob / 流会被拒绝为 400 `INVALID_REQUEST`。
|
|
109
114
|
- 不需要响应内容时 `await res.body?.cancel()`,否则连接占用到超时。
|
|
110
|
-
- **低层路径**:`forward(dto)` 返回 `{ status, headers, body: Readable }`,配 `toWebResponse(out)` 转成 Web `Response`。仅在自定义 controller 需要把上游流 pipe
|
|
115
|
+
- **低层路径**:`forward(dto)` 返回 `{ status, headers, body: Readable }`,配 `toWebResponse(out)` 转成 Web `Response`。仅在自定义 controller 需要把上游流 pipe 给下游等流式场景使用,客户内网通用转发的普通业务使用 `fetch()`。
|
|
111
116
|
|
|
112
|
-
|
|
117
|
+
**客户内网的通用转发请求统一使用 `HttpForwarderService.fetch()`**,它提供以下能力:
|
|
113
118
|
|
|
114
|
-
1.
|
|
115
|
-
2.
|
|
116
|
-
3.
|
|
119
|
+
1. 通过部署环境配置的客户内网通路发出请求;
|
|
120
|
+
2. 在首次 `forward()` / `fetch()` 时初始化客户内网代理鉴权;
|
|
121
|
+
3. 自动携带 `x-miaoda-ctx` 审计上下文。
|
|
117
122
|
|
|
118
123
|
## 四、前端直调(例外:无凭证、只读、URL 可暴露)
|
|
119
124
|
|
|
@@ -221,12 +226,12 @@ export async function safeForward(targetUrl: string) {
|
|
|
221
226
|
|
|
222
227
|
`user_id` 匿名访问为 `""`;trigger / 定时任务场景 `is_system_account` 为 `true`。内容是 **app 自述、SDK 不签名**,下游只用于审计("是哪个 app / 租户 / 用户发起的"),**权威 app 身份以代理层鉴权结果为准**,不要拿此 header 做授权决策。业务代码对它完全透明:不需要读、不能改。
|
|
223
228
|
|
|
224
|
-
##
|
|
229
|
+
## 七、客户内网通用转发的代码约定
|
|
225
230
|
|
|
226
|
-
1.
|
|
231
|
+
1. **客户内网转发默认在 node 侧**:注入 `HttpForwarderService` 用 `fetch()`,URL 写死在 service、凭证只从 `process.env` 读;前端直调仅限无凭证只读接口。
|
|
227
232
|
2. **前端直调路径恒为 `/api/__platform__/http-forward`**,`targetUrl` 永远放 `params`,不要拼到 URL 字符串里、不要放 body、不要放 header。
|
|
228
233
|
3. **服务端零接入**——`PlatformModule.forRoot()` 已自动装配 `HttpForwarderModule` 并全局导出 service,**不要**在用户 `AppModule` 里再写 `HttpForwarderModule.forRoot()`。
|
|
229
|
-
4. **前端只用 `axiosForBackend`**,它已带 401 → `x-login-url`
|
|
234
|
+
4. **前端只用 `axiosForBackend`**,它已带 401 → `x-login-url` 自动跳转拦截器,**不要**再实现登录跳转;**客户内网的 node 侧转发使用 `HttpForwarderService`**。
|
|
230
235
|
5. **响应原样投射**:`res.status` / `res.headers` / `res.data` 都来自上游真实响应,上游 4xx/5xx 不是转发失败。forwarder 自身错在前端被模板 `GlobalExceptionFilter` 包成 `error.response.data.error`,业务码需从 `error.details`(JSON 字符串)里 parse 出来,详见第五节。
|
|
231
236
|
6. **headers 直接走 `headers: {...}`**,无需手剔 `host` / `content-length` / hop-by-hop,service 端会处理。
|
|
232
237
|
7. **不要手动设置 `x-miaoda-ctx`**,SDK 会无条件覆盖;也不要在业务代码里读它做授权。
|
|
@@ -235,7 +240,7 @@ export async function safeForward(targetUrl: string) {
|
|
|
235
240
|
|
|
236
241
|
| ❌ 错误 | ✅ 正确 |
|
|
237
242
|
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
238
|
-
| node 侧用裸 `fetch(url)` / `axios.get(url)`
|
|
243
|
+
| 客户内网通用转发在 node 侧用裸 `fetch(url)` / `axios.get(url)` | 注入 `HttpForwarderService` 用 `fetch()`(裸 fetch 不走代理、无鉴权、无审计头) |
|
|
239
244
|
| 前端直调带内网 API key / token,或让用户输入 `targetUrl` | 改 node 侧 `fetch()`:URL 写死在 service,凭证从 `process.env` 读 |
|
|
240
245
|
| `axiosForBackend.post('/api/__platform__/http-forward?targetUrl=...')` 手拼 query | `params: { targetUrl }`,让 axios 做 URL 编码 |
|
|
241
246
|
| `axiosForBackend.post(targetUrl, body)` 把 targetUrl 当路径 | 路径永远 `/api/__platform__/http-forward`,targetUrl 走 `params` |
|