@lovrabet/sdk 1.5.4-beta.3 → 1.6.1-beta.0

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
@@ -14,6 +14,19 @@
14
14
 
15
15
  ## 🆕 What's New
16
16
 
17
+ ### v1.6.0 (2026-10-23)
18
+ - ✨ **业务域命名空间** - 新增权限、Artifact、审批、应用、数据集元信息、脚本管理能力
19
+ ```typescript
20
+ await client.permit.getRoleList({ currentPage: 1, pageSize: 20 });
21
+ const artifacts = await client.artifact.list({ artifactType: "page" });
22
+ const todo = await client.approval.listTodo();
23
+ ```
24
+ - ✨ **区分 `/api` 与 `/client`** - 双模式能力自动按 `authMode` 选择前缀;单模式能力在不支持的模式下 fail-closed
25
+ - ✨ **数据集可恢复导入** - `ClientAkModel` 新增 `importContract` / `importBatch` / `importReadback` / `importImage` / `importImageReadback`
26
+ - ✨ **SQL 与 BFF 扩展** - 新增 `client.sql.query()` / `client.sql.listSqls()` 与 `client.bff.getEndpoint()` / `listEndpoints()` / `getScript()`
27
+ - ✨ **其余 Client 接口补齐** - `datasetMeta.queryByCode()`、`artifact.updateFavorite()`、`permit.resolveIdentity()`、`permit.appInviteCallback()`
28
+ - ✨ **Personal BFF CRUD** - `client.personal.bff` 新增 `list` / `get` / `create` / `update`
29
+
17
30
  ### v1.3.7 (2026-03-16)
18
31
  - ✨ **批量操作支持** - `update()` 和 `delete()` 现在支持批量操作,最多 1000 条记录
19
32
  ```typescript
@@ -530,6 +543,249 @@ try {
530
543
  }
531
544
  ```
532
545
 
546
+ ## 业务域能力(v1.6.0 新增)
547
+
548
+ SDK 按后端实际注册的路径把能力划分为多个顶级命名空间。双模式能力自动按 `authMode` 选择 `/api` 或 `/client` 前缀;单模式能力在不支持的模式下会直接抛出错误,不会静默请求不存在的路径。
549
+
550
+ ### 模式支持对照
551
+
552
+ | 命名空间 | cookie(`/api`) | client-ak(`/client`) | openapi |
553
+ | --- | --- | --- | --- |
554
+ | `client.permit` | 支持 | 支持 | 抛 `API_AUTH_MODE_UNSUPPORTED` |
555
+ | `client.personal.bff` | 支持 | 支持 | 抛 `PERSONAL_BFF_AUTH_MODE_UNSUPPORTED` |
556
+ | `client.artifact` | 抛 `ARTIFACT_AUTH_MODE_UNSUPPORTED` | 支持 | 抛 `ARTIFACT_AUTH_MODE_UNSUPPORTED` |
557
+ | `client.approval` | 抛 `APPROVAL_AUTH_MODE_UNSUPPORTED` | 支持 | 抛 `APPROVAL_AUTH_MODE_UNSUPPORTED` |
558
+ | `client.app` | 抛 `APP_AUTH_MODE_UNSUPPORTED` | 支持 | 抛 `APP_AUTH_MODE_UNSUPPORTED` |
559
+ | `client.datasetMeta` | 抛 `DATASET_META_AUTH_MODE_UNSUPPORTED` | 支持 | 抛 `DATASET_META_AUTH_MODE_UNSUPPORTED` |
560
+ | `client.management` | 支持 | 抛 `MANAGEMENT_AUTH_MODE_UNSUPPORTED` | 抛 `MANAGEMENT_AUTH_MODE_UNSUPPORTED` |
561
+
562
+ `appCode` 会由 SDK 自动注入请求体或查询参数,调用时无需重复传递。
563
+
564
+ > 例外:`client.permit.resolveIdentity()` 后端只在 `/client` 注册,cookie 模式会抛 `IDENTITY_PERMISSION_AUTH_MODE_UNSUPPORTED`。
565
+
566
+ ```typescript
567
+ const web = createClient({ appCode: "demo" }); // 默认 cookie
568
+
569
+ const ak = createClient({
570
+ appCode: "demo",
571
+ authMode: "client-ak",
572
+ accessKey: "ak_xxx",
573
+ secretKey: "sk_xxx",
574
+ });
575
+ ```
576
+
577
+ ### 权限、角色与成员
578
+
579
+ 适用于 cookie 与 client-ak 两种模式,后端同时提供 `/api/permit/*` 与 `/client/permit/*` 镜像。
580
+
581
+ ```typescript
582
+ // 角色
583
+ const roles = await client.permit.getRoleList({ currentPage: 1, pageSize: 20 });
584
+
585
+ await client.permit.createRole({
586
+ roleName: "店长",
587
+ roleCode: "store_manager",
588
+ permits: { page: ["order-list"], dataset: ["orders"] },
589
+ });
590
+ await client.permit.updateRole({ id: 12, roleName: "新名称" });
591
+ await client.permit.deleteRole(12);
592
+ await client.permit.getRolePermitList({ needSelf: true, needPublic: false });
593
+
594
+ // 角色成员
595
+ await client.permit.getRoleUserList({ roleId: 12 });
596
+ await client.permit.updateRoleUserList({
597
+ roleList: [{ id: 12, userList: [{ userId: "u1" }] }],
598
+ });
599
+
600
+ // 应用成员
601
+ const employees = await client.permit.queryAppUsers();
602
+
603
+ // 页面权限
604
+ await client.permit.getPagePermit(menuId);
605
+ await client.permit.savePagePermit({ menuId, dataCreate: { /* ResourcePermitDTO */ } });
606
+
607
+ // 资源权限
608
+ await client.permit.getResourceMenuList({ roleId: 12 });
609
+ await client.permit.saveMenuPermits({ permitList: [] });
610
+ await client.permit.saveDatasetPermits({ permitList: [] });
611
+
612
+ // 数据集与菜单权限
613
+ await client.permit.getDatasetPermitList(12);
614
+ await client.permit.getDatasetPermitMeta();
615
+ await client.permit.getMenuPermitList();
616
+
617
+ // 当前用户运行态权限快照(仅 client-ak;cookie 模式抛 IDENTITY_PERMISSION_AUTH_MODE_UNSUPPORTED)
618
+ const identity = await client.permit.resolveIdentity();
619
+
620
+ // 应用邀请审批回调(双模式)
621
+ const approved = await client.permit.appInviteCallback({ userId: "u1", approve: "agree" });
622
+ ```
623
+
624
+ ### Artifact(仅 client-ak)
625
+
626
+ ```typescript
627
+ const list = await client.artifact.list({ artifactType: "page", favorite: true });
628
+ const one = await client.artifact.get(3); // 不存在时为 null
629
+
630
+ const created = await client.artifact.create({
631
+ artifactType: "page",
632
+ name: "订单页",
633
+ content: "...",
634
+ metadata: { version: 1 },
635
+ });
636
+ await client.artifact.update(created.id!, { content: "新内容" });
637
+ await client.artifact.updateFavorite(created.id!, true);
638
+ ```
639
+
640
+ ### 审批任务(仅 client-ak)
641
+
642
+ ```typescript
643
+ const todo = await client.approval.listTodo({ currentPage: 1, pageSize: 20 });
644
+ const detail = await client.approval.getTask("task-id");
645
+
646
+ await client.approval.approve({
647
+ taskId: "task-id",
648
+ approved: true,
649
+ comment: "同意",
650
+ formPatch: { amount: 100 }, // 只允许当前节点可编辑的顶层字段
651
+ formDataVersion: detail.formDataVersion, // 必须原样回传 task 详情返回值
652
+ });
653
+ await client.approval.transfer({
654
+ taskId: "task-id",
655
+ targetUserId: "u2",
656
+ comment: "转办",
657
+ });
658
+ ```
659
+
660
+ ### 应用、用户、配置与通知(仅 client-ak)
661
+
662
+ ```typescript
663
+ const apps = await client.app.myApps();
664
+ const me = await client.app.loginUserInfo();
665
+ await client.app.bindAccount({ provider: "dingtalk", accountId: "acc_1" });
666
+
667
+ const flag = await client.app.getConfigByKey<boolean>("feature.newImport");
668
+ const channels = await client.app.listNotificationChannels("DINGTALK");
669
+ ```
670
+
671
+ ### 数据集元信息(仅 client-ak)
672
+
673
+ ```typescript
674
+ const datasets = await client.datasetMeta.list({ code: "orders" });
675
+
676
+ // 按 code 查单个数据集(后端已标记 @Deprecated,优先用 getDrivenData)
677
+ const dataset = await client.datasetMeta.queryByCode("orders");
678
+
679
+ // id 与 code 至少传一个;返回结构随 doVersion 为 v1 / v2
680
+ const driven = await client.datasetMeta.getDrivenData<DoProtocol>({ code: "orders" });
681
+ ```
682
+
683
+ ### 脚本缓存与日志(仅 cookie)
684
+
685
+ ```typescript
686
+ await client.management.clearScriptCache();
687
+
688
+ const logs = await client.management.searchScriptLogs({
689
+ startTime: Date.now() - 3600_000,
690
+ endTime: Date.now(),
691
+ level: "ERROR",
692
+ keyword: "timeout",
693
+ limit: 200,
694
+ });
695
+ ```
696
+
697
+ ### 自定义 SQL 列表查询(仅 client-ak)
698
+
699
+ `client.sql` 是联合类型,`query()` 只由 `ClientAkSqlClient` 提供,需要先用 `instanceof` 收窄。
700
+
701
+ ```typescript
702
+ import { ClientAkSqlClient } from "@lovrabet/sdk";
703
+
704
+ if (client.sql instanceof ClientAkSqlClient) {
705
+ const page = await client.sql.query({
706
+ sqlName: "order",
707
+ currentPage: 1,
708
+ pageSize: 20,
709
+ });
710
+ // page.tableData / page.paging
711
+
712
+ // 不分页,返回应用下全部自定义 SQL
713
+ const sqls = await client.sql.listSqls();
714
+ }
715
+ ```
716
+
717
+ ### BFF 端点查询(仅 client-ak)
718
+
719
+ ```typescript
720
+ import { ClientAkBffClient } from "@lovrabet/sdk";
721
+
722
+ if (client.bff instanceof ClientAkBffClient) {
723
+ // 脚本不存在或为 personalOnly 时返回 null
724
+ const summary = await client.bff.getEndpoint("sqlTest");
725
+
726
+ // 当前应用下全部独立端点脚本
727
+ const endpoints = await client.bff.listEndpoints();
728
+
729
+ // 按脚本主键查询详情(personalOnly 仅创建者本人可读)
730
+ const script = await client.bff.getScript(12);
731
+ }
732
+ ```
733
+
734
+ ### 数据集可恢复导入(仅 client-ak)
735
+
736
+ 导入能力位于 `ClientAkModel`。由于 `client.models.X` 的静态类型是 `BaseModelMethods`,需要显式收窄为 `ClientAkModel`。
737
+
738
+ ```typescript
739
+ import { ClientAkModel } from "@lovrabet/sdk";
740
+
741
+ const model = client.getModel("orders") as ClientAkModel;
742
+
743
+ const contract = await model.importContract<{
744
+ schemaFingerprint: string;
745
+ maxBatchSize: number;
746
+ maxBatchBytes: number;
747
+ }>();
748
+
749
+ const { ids, count } = await model.importBatch({
750
+ schemaFingerprint: contract.schemaFingerprint,
751
+ items: rows, // 1~500 条
752
+ // taskId: "auto-id-task", // 需要后端分配 id 时传入
753
+ });
754
+
755
+ // body 只传 { ids }
756
+ const { items } = await model.importReadback<Order>(ids);
757
+
758
+ // 图片导入为 multipart/form-data
759
+ await model.importImage({
760
+ importId: "imp-1",
761
+ contentHash: "sha256-...",
762
+ file: blob,
763
+ fileName: "logo.png",
764
+ });
765
+ await model.importImageReadback({
766
+ importId: "imp-1",
767
+ contentHash: "sha256-...",
768
+ type: "image/png",
769
+ size: blob.size,
770
+ });
771
+ ```
772
+
773
+ ### Personal BFF 管理(双模式)
774
+
775
+ ```typescript
776
+ const scripts = await client.personal?.bff.list();
777
+ const script = await client.personal?.bff.get(12);
778
+
779
+ await client.personal?.bff.create({
780
+ functionName: "myFn",
781
+ scriptContent: "...",
782
+ description: "说明",
783
+ });
784
+ await client.personal?.bff.update(12, { description: "新说明" });
785
+
786
+ await client.personal?.bff.execute({ scriptId: 12, params: { id: 1 } });
787
+ ```
788
+
533
789
  ## 📖 API 文档
534
790
 
535
791
  ### 主要导出
@@ -562,6 +818,16 @@ import {
562
818
  // API 命名空间
563
819
  ApiNamespace,
564
820
 
821
+ // 业务域命名空间(v1.6.0)
822
+ PermitClient,
823
+ ArtifactClient,
824
+ ApprovalClient,
825
+ AppClient,
826
+ DatasetMetaClient,
827
+ ManagementClient,
828
+ ClientAkSqlClient,
829
+ ClientAkBffClient,
830
+
565
831
  // 运行态服务命名空间
566
832
  ServicesNamespace,
567
833
  FileClient,
@@ -576,6 +842,7 @@ import {
576
842
  AbstractBaseModel,
577
843
  OpenApiModel,
578
844
  WebApiModel,
845
+ ClientAkModel,
579
846
  ModelFactory,
580
847
 
581
848
  // 排序枚举
@@ -599,6 +866,39 @@ import {
599
866
  type SelectOptionsParams,
600
867
  type SqlExecuteRequest,
601
868
  type SqlExecuteResult,
869
+ type CustomSqlQueryRequest,
870
+ type UserCustomSqlDTO,
871
+ type DataList,
872
+ type PageResult,
873
+ type DatasetRequest,
874
+ type DatasetMeta,
875
+ type DatasetDrivenDataQuery,
876
+ type RuntimeArtifactDTO,
877
+ type ArtifactUpsertRequest,
878
+ type ApprovalFlowTaskItem,
879
+ type ApprovalFlowTaskDetail,
880
+ type ApprovalFlowApproveRequest,
881
+ type ApprovalFlowTransferRequest,
882
+ type AppRoleVO,
883
+ type AppRoleCreateParam,
884
+ type AppRoleUpdateParam,
885
+ type RoleUserUpdateParam,
886
+ type ResourcePermitDTO,
887
+ type MenuPermitDTO,
888
+ type RuntimeIdentityPermission,
889
+ type UserAppRelation,
890
+ type EndpointScriptSummary,
891
+ type ScriptDefinition,
892
+ type AppEmployee,
893
+ type LoginUserInfo,
894
+ type SmartApp,
895
+ type NotificationChannelConfig,
896
+ type ScriptLogQuery,
897
+ type DatasetImportBatchRequest,
898
+ type DatasetImportBatchResult,
899
+ type DatasetImportReadbackResult,
900
+ type PersonalBffScript,
901
+ type PersonalBffUpsertRequest,
602
902
  type Environment,
603
903
  type BaseModelMethods,
604
904
  type LovrabetServices,
package/dist/index.d.ts CHANGED
@@ -8,13 +8,15 @@ export type { SafeResult } from "./src/utils/safe";
8
8
  export { sqlSafe } from "./src/utils/sql-safe";
9
9
  export type { SqlSafeResult } from "./src/utils/sql-safe";
10
10
  export { AbstractBaseModel, OpenApiModel, WebApiModel, ClientAkModel, ModelFactory, } from "./src/models/index";
11
- export { ApiNamespace } from "./src/api/index";
11
+ export { ApiNamespace, ClientAkSqlClient, ClientAkBffClient, PermitClient, ArtifactClient, ApprovalClient, AppClient, DatasetMetaClient, ManagementClient, } from "./src/api/index";
12
+ export type { AppRoleRequest, AppRoleCreateParam, AppRoleUpdateParam, AppRolePermitQueryParam, AppRoleVO, UserAppRelationQueryParam, AppUserBaseVO, AppRoleUserVO, RoleUserUpdateParam, AppEmployee, BaseRoleVO, ResourcePermitDTO, MenuPermitDTO, AppResourceMenuParam, ResourcePermitParam, MenuRolePermitListVO, RuntimeIdentityPermission, UserAppRelation, ArtifactUpsertRequest, ArtifactListQuery, RuntimeArtifactDTO, ApprovalTodoQuery, ApprovalFlowTaskItem, ApprovalFlowTaskDetail, ApprovalFlowApproveRequest, ApprovalFlowTransferRequest, LoginUserInfo, SmartApp, UserAccountBindRequest, NotificationChannelConfig, ScriptLogQuery, EndpointScriptSummary, ScriptDefinition, ClientAkBffExecuteRequest, PageResult, Paging, DataList, CustomSqlQueryRequest, UserCustomSqlDTO, DatasetRequest, DatasetMeta, DatasetDrivenDataQuery, } from "./src/api/index";
13
+ export type { DatasetImportBatchRequest, DatasetImportBatchResult, DatasetImportReadbackResult, DatasetImportImageRequest, DatasetImportImageReadbackRequest, } from "./src/models/index";
12
14
  export { ServicesNamespace, FileClient, OcrClient, OcrType, OCR_TYPES, } from "./src/services/index";
13
15
  export type { LovrabetServices, FileQueryUrlRequest, FileService, FileUploadRequest, FileUploadResponse, FileUrlResponse, OcrRecognizeRequest, OcrRecognizeResponse, OcrService, ServiceRequestOptions, } from "./src/services/index";
14
16
  export { LovrabetFlowClient } from "./src/flow/index";
15
17
  export type { FlowBatchTaskActionRequest, FlowBatchTransferRequest, FlowCcQuery, FlowCcRequest, FlowCustomPageCcDetail, FlowCustomPageDefinition, FlowCustomPageStartResponse, FlowCustomPageSubmittedProcess, FlowCustomPageTaskDetail, FlowCustomPageTaskItem, FlowCustomPageTimeline, FlowDefinitionQuery, FlowPage, FlowPageQuery, FlowProcessReasonRequest, FlowRecord, FlowResubmitRequest, FlowReturnRequest, FlowReturnTarget, FlowStartRequest, FlowSubmittedQuery, FlowTaskActionRequest, FlowTransferRequest, FlowUpdateVariablesRequest, FlowVariableProjectionQuery, FlowVariableQuery, } from "./src/flow/index";
16
18
  export { PersonalNamespace, PersonalBffClient, } from "./src/personal/index";
17
- export type { LovrabetPersonal, PersonalBffExecuteRequest, PersonalBffService, PersonalRequestOptions, } from "./src/personal/index";
19
+ export type { LovrabetPersonal, PersonalBffExecuteRequest, PersonalBffScript, PersonalBffService, PersonalBffUpsertRequest, PersonalRequestOptions, } from "./src/personal/index";
18
20
  export { AuthManager, } from "./src/auth/index";
19
21
  export { generateOpenApiToken, generateFlowOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type GenerateFlowTokenParams, type TokenResult } from "./src/auth/index";
20
22
  export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, AuthMode, Region, } from "./src/types/index";