@lovrabet/sdk 1.5.3 → 1.5.4-beta.2

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 CHANGED
@@ -76,6 +76,70 @@ const user = await client.models.users.getOne("user-id");
76
76
  const newUser = await client.models.users.create({ name: "John" });
77
77
  ```
78
78
 
79
+ ### 独立审批 Flow OpenAPI
80
+
81
+ Flow 仅支持 `openapi` 认证,并绑定当前应用与操作人。Node 客户端已经绑定 `appCode`,因此通过 `client.flow(operatorUserId)` 创建审批客户端:
82
+
83
+ ```typescript
84
+ import { createClient } from "@lovrabet/sdk";
85
+
86
+ const client = createClient({
87
+ appCode: "your-app-code",
88
+ authMode: "openapi",
89
+ accessKey: process.env.LOVRABET_ACCESS_KEY!,
90
+ // Runtime dev profile 本地联调:runtimeDomain: "http://127.0.0.1:8081"
91
+ });
92
+
93
+ const flow = client.flow("1001");
94
+
95
+ const started = await flow.start({
96
+ flowCode: "leave",
97
+ formData: { days: 2, reason: "年假" },
98
+ variables: { businessId: "LEAVE-20260821-001" },
99
+ idempotencyKey: "leave-request-001",
100
+ });
101
+
102
+ const todo = await flow.listTodo({
103
+ variables: { businessId: "LEAVE-20260821-001" },
104
+ currentPage: 1,
105
+ pageSize: 20,
106
+ });
107
+
108
+ await flow.approve({
109
+ taskId: todo.records[0].taskId,
110
+ comment: "同意",
111
+ variables: { auditSource: "node-sdk" },
112
+ });
113
+ ```
114
+
115
+ 常用入口包括 `listTodo`、`listDone`、`listSubmitted`、`getTaskDetail`、`getProcessDetail`、`updateVariables`、`approve`、`reject`、`complete`、`transfer`、`withdraw`、`resubmit`、`returnTask`、`ccProcess` 和 `listCc`。应用管理员可使用 `listAppTodo`、`listAppDone`、`listAppSubmitted` 查询当前应用全量数据;服务端仍会校验操作人是否为应用管理员。
116
+
117
+ 浏览器不能保存 `accessKey`。服务端可使用 `generateFlowOpenApiToken()` 为指定操作人生成短期 Token,浏览器必须用同一个 `appCode`、`operatorUserId` 和 `timestamp` 发起请求:
118
+
119
+ ```typescript
120
+ import { generateFlowOpenApiToken } from "@lovrabet/sdk";
121
+
122
+ const auth = await generateFlowOpenApiToken({
123
+ appCode: "your-app-code",
124
+ operatorUserId: "1001",
125
+ accessKey: process.env.LOVRABET_ACCESS_KEY!,
126
+ });
127
+ ```
128
+
129
+ 浏览器拿到 `{ token, timestamp }` 后:
130
+
131
+ ```typescript
132
+ const client = createClient({
133
+ appCode: "your-app-code",
134
+ authMode: "openapi",
135
+ token,
136
+ timestamp,
137
+ });
138
+
139
+ const flow = client.flow("1001"); // 必须与生成 Token 时的 operatorUserId 一致
140
+ const todo = await flow.listTodo();
141
+ ```
142
+
79
143
  ### 浏览器端使用
80
144
 
81
145
  #### 方式 1:使用预生成 Token(推荐)
@@ -490,7 +554,7 @@ import {
490
554
 
491
555
  // 环境配置
492
556
  getApiEndpoint,
493
- getAvailableEnvironments,
557
+ getAvailableRegions,
494
558
 
495
559
  // 错误处理
496
560
  LovrabetError,
@@ -553,7 +617,6 @@ interface ClientConfig {
553
617
  secretKey?: string; // 密钥(可选)
554
618
  token?: string; // 预生成 token(浏览器)
555
619
  timestamp?: number; // token 时间戳
556
- env?: "production" | "online" | "daily" | "development"; // 环境
557
620
  region?: "cn" | "id"; // 官方节点,默认 cn
558
621
  runtimeDomain?: string; // 企业独立部署覆盖,优先于 region
559
622
  models?: ModelsConfig; // 模型配置
@@ -565,19 +628,66 @@ interface ClientConfig {
565
628
  ```typescript
566
629
  const client = createClient({
567
630
  appCode: "app-xxx",
568
- region: "id",
569
- env: "production"
631
+ region: "id"
632
+ });
633
+ ```
634
+
635
+ 企业独立部署直接传入最终 `runtimeDomain`:
636
+
637
+ ```typescript
638
+ const client = createClient({
639
+ appCode: "app-xxx",
640
+ runtimeDomain: "https://runtime.customer.example.com"
570
641
  });
571
642
  ```
572
643
 
573
- 企业独立部署直接传入 `runtimeDomain`。解析优先级为:`runtimeDomain` →
574
- 兼容字段 `serverUrl` → 页面注入的 `RUNTIME_API_DOMAIN` → `region + env`
575
- → 默认 CN Production。
644
+ 解析优先级为:`runtimeDomain` → 兼容字段 `serverUrl` → 页面注入的
645
+ `RUNTIME_API_DOMAIN` → `region` 对应的官方 Runtime Domain → 默认中国大陆节点。
576
646
 
577
647
  SDK 会对显式 Runtime 地址去除首尾空白和尾斜杠,并拒绝非法 URL、凭证、
578
648
  query 或 fragment。未传 `region` 时默认 `cn`;显式传入 `cn` / `id` 以外的值
579
649
  会抛出 `INVALID_REGION`,不会静默请求其他区域。
580
650
 
651
+ ### 路由配置来源
652
+
653
+ SDK 不会在运行时访问 `lovrabet-routing` 仓库,也不会打开 CLI 的企业路由
654
+ JSON 文件。官方国家/地区的 Runtime Domain 在开发阶段由独立
655
+ `lovrabet-routing` 仓库生成到
656
+ `src/config/generated-region-endpoints.ts`,然后随 `@lovrabet/sdk` npm 包一起
657
+ 发布。生成文件包含路由目录 SHA-256,用于检查三个消费者是否来自同一份真源。
658
+
659
+ ```text
660
+ lovrabet-routing/catalog/official-routing.v1.json
661
+ │
662
+ │ npm run generate
663
+ ▼
664
+ src/config/generated-region-endpoints.ts
665
+ │
666
+ │ SDK build and npm publish
667
+ ▼
668
+ createClient({ region })
669
+ ```
670
+
671
+ 官方目录中的 Domain 可以是所有消费者共用的字符串,也可以按消费者覆盖。
672
+ 生成 SDK 快照时固定以 `lovrabet-node-sdk` 身份解析,优先读取 SDK 专属值,
673
+ 否则读取 `default`;两者都没有则生成失败。
674
+
675
+ SDK 只消费 `runtimeDomain`。`userDomain`、`apiDomain`、`skillDomain`、
676
+ `kbDomain` 和 `appDomain` 属于 CLI 或其他平台能力,不应在 SDK 内复制路由
677
+ 判断。
678
+
679
+ 企业部署由应用或上游工具把最终 `runtimeDomain` 传给 SDK。Rabetbase 生成的
680
+ 前端项目可通过 `sdk-config.ts` 注入该值;SDK 本身不依赖 Node.js 文件系统,
681
+ 因此同一行为可用于浏览器和 Node.js。企业清单中的 `lovrabet-node-sdk` 专属值
682
+ 只有在上游以 SDK 身份解析后才会生效,不能仅把清单文件放在项目中。
683
+
684
+ ### 路由维护与发布
685
+
686
+ 维护者不得直接编辑 `src/config/generated-region-endpoints.ts`。新增或调整官方
687
+ 节点时,应在 `lovrabet-routing` 修改真源并执行 `npm run generate`,然后在本仓
688
+ 执行类型检查、完整测试和构建。只发布路由仓不会改变已安装 SDK;生成快照必须
689
+ 随新的 SDK 版本发布,并与两个 CLI 的快照放在同一发布批次。
690
+
581
691
  ### CRUD 操作
582
692
 
583
693
  ```typescript
package/dist/index.d.ts CHANGED
@@ -11,10 +11,12 @@ export { AbstractBaseModel, OpenApiModel, WebApiModel, ClientAkModel, ModelFacto
11
11
  export { ApiNamespace } from "./src/api/index";
12
12
  export { ServicesNamespace, FileClient, OcrClient, OcrType, OCR_TYPES, } from "./src/services/index";
13
13
  export type { LovrabetServices, FileQueryUrlRequest, FileService, FileUploadRequest, FileUploadResponse, FileUrlResponse, OcrRecognizeRequest, OcrRecognizeResponse, OcrService, ServiceRequestOptions, } from "./src/services/index";
14
+ export { LovrabetFlowClient } from "./src/flow/index";
15
+ export type { FlowBatchTaskActionRequest, FlowBatchTransferRequest, FlowCcQuery, FlowCcRequest, FlowDefinitionQuery, FlowPage, FlowPageQuery, FlowProcessReasonRequest, FlowRecord, FlowResubmitRequest, FlowReturnRequest, FlowReturnTarget, FlowStartRequest, FlowSubmittedQuery, FlowTaskActionRequest, FlowTransferRequest, FlowUpdateVariablesRequest, FlowVariableProjectionQuery, FlowVariableQuery, } from "./src/flow/index";
14
16
  export { PersonalNamespace, PersonalBffClient, } from "./src/personal/index";
15
17
  export type { LovrabetPersonal, PersonalBffExecuteRequest, PersonalBffService, PersonalRequestOptions, } from "./src/personal/index";
16
18
  export { AuthManager, } from "./src/auth/index";
17
- export { generateOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type TokenResult } from "./src/auth/index";
19
+ export { generateOpenApiToken, generateFlowOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type GenerateFlowTokenParams, type TokenResult } from "./src/auth/index";
18
20
  export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, AuthMode, Region, } from "./src/types/index";
19
21
  export type { ListParams, ListResponse, FilterParams, WhereCondition, FieldCondition, ConditionOperator, Environment, BaseModelMethods, SortList, SelectOption, SelectOptionsParams, AggregateParams, AggregateField, HavingCondition, } from "./src/types/index";
20
22
  export type { SqlExecuteRequest, SqlExecuteResult, } from "./src/api/types";