@lovrabet/sdk 1.4.3 → 1.5.1-beta.1
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 +41 -12
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1 -1
- package/dist/src/client/client.d.ts +5 -0
- package/dist/src/config/constants.d.ts +9 -0
- package/dist/src/config/endpoints.d.ts +21 -1
- package/dist/src/http/http-client.d.ts +2 -1
- package/dist/src/personal/bff-client.d.ts +11 -0
- package/dist/src/personal/index.d.ts +11 -0
- package/dist/src/personal/types.d.ts +18 -0
- package/dist/src/types/index.d.ts +41 -22
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ import { BffClient } from '../api/bff-client';
|
|
|
7
7
|
import { ClientAkBffClient } from '../api/client-ak-bff-client';
|
|
8
8
|
import { UserClient } from '../api/user-client';
|
|
9
9
|
import { ServicesNamespace } from '../services';
|
|
10
|
+
import { PersonalNamespace } from '../personal';
|
|
10
11
|
/**
|
|
11
12
|
* Lovrabet SDK 核心客户端类
|
|
12
13
|
*
|
|
@@ -50,6 +51,10 @@ export declare class LovrabetClient implements ILovrabetClient {
|
|
|
50
51
|
* 平台服务命名空间 - OCR 等不绑定数据集或 BFF 的通用运行态能力
|
|
51
52
|
*/
|
|
52
53
|
readonly services: ServicesNamespace;
|
|
54
|
+
/**
|
|
55
|
+
* 当前用户拥有的资源,如个人 BFF。
|
|
56
|
+
*/
|
|
57
|
+
readonly personal: PersonalNamespace;
|
|
53
58
|
/**
|
|
54
59
|
* API 命名空间 - 别名入口(向后兼容)
|
|
55
60
|
*
|
|
@@ -28,6 +28,15 @@ export declare const ENVIRONMENTS: {
|
|
|
28
28
|
/** 开发环境 */
|
|
29
29
|
readonly DEVELOPMENT: "development";
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Lovrabet official deployment regions.
|
|
33
|
+
*/
|
|
34
|
+
export declare const REGIONS: {
|
|
35
|
+
/** Mainland China node (default). */
|
|
36
|
+
readonly CN: "cn";
|
|
37
|
+
/** Indonesia node. */
|
|
38
|
+
readonly ID: "id";
|
|
39
|
+
};
|
|
31
40
|
/**
|
|
32
41
|
* HTTP 状态码常量
|
|
33
42
|
*/
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Region } from '../types';
|
|
2
|
+
/** Mainland China endpoints retained as the backward-compatible public export. */
|
|
1
3
|
export declare const API_ENDPOINTS: {
|
|
2
4
|
readonly production: "https://runtime.lovrabet.com";
|
|
3
5
|
readonly online: "https://runtime.lovrabet.com";
|
|
@@ -5,12 +7,30 @@ export declare const API_ENDPOINTS: {
|
|
|
5
7
|
readonly development: "https://dev.lovrabet.com";
|
|
6
8
|
};
|
|
7
9
|
export type Environment = keyof typeof API_ENDPOINTS;
|
|
10
|
+
/** Runtime endpoints selected by official region and environment. */
|
|
11
|
+
export declare const REGION_API_ENDPOINTS: {
|
|
12
|
+
readonly cn: {
|
|
13
|
+
readonly production: "https://runtime.lovrabet.com";
|
|
14
|
+
readonly online: "https://runtime.lovrabet.com";
|
|
15
|
+
readonly daily: "https://daily-runtime.lovrabet.com";
|
|
16
|
+
readonly development: "https://dev.lovrabet.com";
|
|
17
|
+
};
|
|
18
|
+
readonly id: {
|
|
19
|
+
readonly production: "https://runtime.lovrabet.id";
|
|
20
|
+
readonly online: "https://runtime.lovrabet.id";
|
|
21
|
+
readonly daily: "https://daily-runtime.lovrabet.id";
|
|
22
|
+
readonly development: "https://dev.lovrabet.id";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
8
25
|
/**
|
|
9
26
|
* 获取指定环境的 API 端点(支持向下兼容)
|
|
10
27
|
* @param env - 环境名称(支持 "production", "online", "daily", "dev", "development")
|
|
28
|
+
* @param region - 官方节点("cn" 或 "id"),默认 "cn"
|
|
11
29
|
* @returns API 端点 URL
|
|
12
30
|
*/
|
|
13
|
-
export declare function getApiEndpoint(env: Environment | string): string;
|
|
31
|
+
export declare function getApiEndpoint(env: Environment | string, region?: Region | string): string;
|
|
32
|
+
/** Returns official regions supported by the SDK's built-in Runtime mapping. */
|
|
33
|
+
export declare function getAvailableRegions(): Region[];
|
|
14
34
|
/**
|
|
15
35
|
* 获取所有可用的环境
|
|
16
36
|
* @returns 环境列表(返回标准化的环境名)
|
|
@@ -6,7 +6,8 @@ export declare class HttpClient {
|
|
|
6
6
|
constructor(config: ClientConfig, authManager: AuthManager);
|
|
7
7
|
/**
|
|
8
8
|
* 获取 API 基础地址
|
|
9
|
-
* 优先级:runtimeDomain >
|
|
9
|
+
* 优先级:runtimeDomain > serverUrl >
|
|
10
|
+
* window.__GLOBAL__.deploymentConfig.RUNTIME_API_DOMAIN > getApiEndpoint(env, region)
|
|
10
11
|
*
|
|
11
12
|
* 注:serverUrl 为 runtimeDomain 的旧名称,向下兼容保留;两者均设置时以 runtimeDomain 优先。
|
|
12
13
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
import type { AuthMode } from "../types";
|
|
3
|
+
import type { PersonalBffExecuteRequest, PersonalBffService } from "./types";
|
|
4
|
+
/** Personal BFF execution client exposed under `client.personal.bff`. */
|
|
5
|
+
export declare class PersonalBffClient implements PersonalBffService {
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
private readonly appCode;
|
|
8
|
+
private readonly authMode;
|
|
9
|
+
constructor(httpClient: HttpClient, appCode: string, authMode: AuthMode);
|
|
10
|
+
execute<T = unknown>(request: PersonalBffExecuteRequest): Promise<T>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
import type { AuthMode } from "../types";
|
|
3
|
+
import { PersonalBffClient } from "./bff-client";
|
|
4
|
+
import type { LovrabetPersonal } from "./types";
|
|
5
|
+
/** Namespace for resources owned by the current user. */
|
|
6
|
+
export declare class PersonalNamespace implements LovrabetPersonal {
|
|
7
|
+
readonly bff: PersonalBffClient;
|
|
8
|
+
constructor(httpClient: HttpClient, appCode: string, authMode: AuthMode);
|
|
9
|
+
}
|
|
10
|
+
export { PersonalBffClient } from "./bff-client";
|
|
11
|
+
export type { LovrabetPersonal, PersonalBffExecuteRequest, PersonalBffService, PersonalRequestOptions, } from "./types";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Per-request options supported by personal resource clients. */
|
|
2
|
+
export type PersonalRequestOptions = Omit<RequestInit, "method" | "body">;
|
|
3
|
+
/** Input accepted when executing a personal BFF. */
|
|
4
|
+
export interface PersonalBffExecuteRequest {
|
|
5
|
+
/** Positive integer identifier of the personal BFF script. */
|
|
6
|
+
scriptId: number;
|
|
7
|
+
/** Parameters passed to the personal BFF script. */
|
|
8
|
+
params?: Record<string, unknown>;
|
|
9
|
+
/** Optional fetch settings. The HTTP method and body are controlled by the SDK. */
|
|
10
|
+
options?: PersonalRequestOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface PersonalBffService {
|
|
13
|
+
execute<T = unknown>(request: PersonalBffExecuteRequest): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
/** Personal resources exposed under `client.personal`. */
|
|
16
|
+
export interface LovrabetPersonal {
|
|
17
|
+
readonly bff: PersonalBffService;
|
|
18
|
+
}
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* - development: 本地开发环境
|
|
18
18
|
*/
|
|
19
19
|
export type Environment = "production" | "online" | "daily" | "development";
|
|
20
|
+
/** Official Lovrabet Runtime region. Mainland China is the default. */
|
|
21
|
+
export type Region = "cn" | "id";
|
|
20
22
|
/**
|
|
21
23
|
* 排序方向枚举
|
|
22
24
|
* @description 定义数据排序的方向
|
|
@@ -103,15 +105,17 @@ export interface ListResponse<T> {
|
|
|
103
105
|
* 支持的操作符:
|
|
104
106
|
* - $eq: 等于
|
|
105
107
|
* - $ne: 不等于
|
|
106
|
-
* - $
|
|
107
|
-
* - $
|
|
108
|
+
* - $gt: 大于
|
|
109
|
+
* - $lt: 小于
|
|
110
|
+
* - $gte: 大于等于(推荐);$gteq 为兼容旧写法的别名,后端同样映射为 >=
|
|
111
|
+
* - $lte: 小于等于(推荐);$lteq 为兼容旧写法的别名,后端同样映射为 <=
|
|
108
112
|
* - $in: 在集合内
|
|
109
113
|
* - $contain: 包含(模糊匹配)
|
|
110
114
|
* - $startWith: 以...开头
|
|
111
115
|
* - $endWith: 以...结尾
|
|
112
116
|
* - $notNull: 非空判断
|
|
113
117
|
*/
|
|
114
|
-
export type ConditionOperator = "$eq" | "$ne" | "$gte" | "$gteq" | "$lte" | "$lteq" | "$in" | "$contain" | "$startWith" | "$endWith" | "$notNull";
|
|
118
|
+
export type ConditionOperator = "$eq" | "$ne" | "$gt" | "$lt" | "$gte" | "$gteq" | "$lte" | "$lteq" | "$in" | "$contain" | "$startWith" | "$endWith" | "$notNull";
|
|
115
119
|
/**
|
|
116
120
|
* 字段条件类型
|
|
117
121
|
* @description 单个字段的查询条件
|
|
@@ -419,7 +423,9 @@ export interface ClientConfig {
|
|
|
419
423
|
serverUrl?: string;
|
|
420
424
|
/** 运行环境,默认为 'production'(向下兼容 'online') */
|
|
421
425
|
env?: Environment;
|
|
422
|
-
/**
|
|
426
|
+
/** 官方运行节点,默认为 'cn';显式 runtimeDomain 的优先级更高。 */
|
|
427
|
+
region?: Region;
|
|
428
|
+
/** 预计算 OpenAPI token,配合 timestamp 通过 X-Token / X-Time-Stamp 传递,不是 Authorization: Bearer */
|
|
423
429
|
token?: string;
|
|
424
430
|
/** 与 token 配对的时间戳(OpenAPI 模式必需) */
|
|
425
431
|
timestamp?: number;
|
|
@@ -429,9 +435,17 @@ export interface ClientConfig {
|
|
|
429
435
|
secretKey?: string;
|
|
430
436
|
/** Cookie 字符串,用于 Cookie 认证(Node.js 环境专用) */
|
|
431
437
|
cookie?: string;
|
|
432
|
-
/**
|
|
438
|
+
/**
|
|
439
|
+
* 显式要求当前 authMode 下的凭据已经齐全时设为 true。
|
|
440
|
+
* 未设置时不做强制检查(没有默认 true)。
|
|
441
|
+
* 校验按 authMode:client-ak 需要 accessKey;openapi 需要 accessKey,或 token + timestamp;
|
|
442
|
+
* cookie / 缺省不能把 token、accessKey 当成已生效的 Cookie 认证。
|
|
443
|
+
*/
|
|
433
444
|
requiresAuth?: boolean;
|
|
434
|
-
/**
|
|
445
|
+
/**
|
|
446
|
+
* 显式声明鉴权模式。**未设置时固定回退到 cookie 模式**,不会根据 accessKey / token 等字段自动推断;
|
|
447
|
+
* 需要 Client AK / OpenAPI 鉴权时必须显式设置(`"client-ak"` 或 `"openapi"`)。
|
|
448
|
+
*/
|
|
435
449
|
authMode?: AuthMode;
|
|
436
450
|
/**
|
|
437
451
|
* 模型配置
|
|
@@ -488,7 +502,7 @@ export interface BaseModelMethods {
|
|
|
488
502
|
* @template T 返回数据的类型
|
|
489
503
|
* @param params Filter 查询参数,支持复杂条件、字段选择、排序和分页
|
|
490
504
|
* @returns 返回分页数据
|
|
491
|
-
* @description 提供比 getList 更强大的查询能力,支持复杂的 where
|
|
505
|
+
* @description 提供比 getList 更强大的查询能力,支持复杂的 where 条件、字段选择等(filter 在 WebAPI / OpenAPI / Client AK 模式均支持;delete、excelExport、getSelectOptions 当前不支持 OpenAPI 模式,WebAPI 与 Client AK 均支持)
|
|
492
506
|
* @example
|
|
493
507
|
* ```typescript
|
|
494
508
|
* // 使用枚举
|
|
@@ -569,7 +583,7 @@ export interface BaseModelMethods {
|
|
|
569
583
|
update<T = any>(id: string | number | (string | number)[], data: Record<string, any>): Promise<T>;
|
|
570
584
|
/**
|
|
571
585
|
* 删除数据,支持单条和批量
|
|
572
|
-
* @throws Error OpenAPI
|
|
586
|
+
* @throws Error OpenAPI 模式暂不支持此操作;WebAPI 与 Client AK 模式均可用
|
|
573
587
|
*
|
|
574
588
|
* **推荐写法(对象传入)**:
|
|
575
589
|
* ```typescript
|
|
@@ -591,7 +605,7 @@ export interface BaseModelMethods {
|
|
|
591
605
|
* 获取下拉选项
|
|
592
606
|
* @param params 字段映射参数,指定用作 value 和 label 的字段名
|
|
593
607
|
* @returns 返回下拉选项数组
|
|
594
|
-
* @description 用于获取数据表的下拉选项数据,适用于 Select
|
|
608
|
+
* @description 用于获取数据表的下拉选项数据,适用于 Select 组件(WebAPI 与 Client AK 模式支持,OpenAPI 模式不支持)
|
|
595
609
|
* @example
|
|
596
610
|
* ```typescript
|
|
597
611
|
* // 获取用户下拉选项
|
|
@@ -607,7 +621,7 @@ export interface BaseModelMethods {
|
|
|
607
621
|
* 导出数据为 Excel 文件
|
|
608
622
|
* @param params 查询参数(可选),与 getList 参数一致,用于按条件筛选导出数据
|
|
609
623
|
* @returns 返回导出文件的 URL 地址(字符串),可直接用于下载
|
|
610
|
-
* @description 导出当前数据集的数据为 Excel
|
|
624
|
+
* @description 导出当前数据集的数据为 Excel 文件(WebAPI 与 Client AK 模式支持,OpenAPI 模式不支持)
|
|
611
625
|
* @example
|
|
612
626
|
* ```typescript
|
|
613
627
|
* // 导出所有数据
|
|
@@ -734,14 +748,14 @@ export interface ModelManager {
|
|
|
734
748
|
}
|
|
735
749
|
/**
|
|
736
750
|
* 认证请求头接口
|
|
737
|
-
* @description 包含认证信息的 HTTP
|
|
751
|
+
* @description 包含认证信息的 HTTP 请求头。实际字段由 authMode 决定,不是 Authorization: Bearer。
|
|
738
752
|
* @example
|
|
739
753
|
* ```typescript
|
|
740
|
-
* //
|
|
741
|
-
* { "
|
|
754
|
+
* // OpenAPI:预计算 token 或 accessKey 签名
|
|
755
|
+
* { "X-Token": "…", "X-Time-Stamp": "…", "X-App-Code": "app-xxx", "X-Dataset-Code": "…" }
|
|
742
756
|
*
|
|
743
|
-
* //
|
|
744
|
-
* { "X-
|
|
757
|
+
* // Client AK
|
|
758
|
+
* { "X-User-AK": "your-access-key" }
|
|
745
759
|
* ```
|
|
746
760
|
*/
|
|
747
761
|
export interface AuthHeaders {
|
|
@@ -766,16 +780,14 @@ export interface OpenApiAuthConfig {
|
|
|
766
780
|
}
|
|
767
781
|
/**
|
|
768
782
|
* 认证管理器接口
|
|
769
|
-
* @description
|
|
770
|
-
* 认证优先级:Token > OpenAPI密钥 > Cookie
|
|
783
|
+
* @description 按显式 authMode 选择认证策略;未设置 authMode 时固定为 cookie,不会按 token / accessKey 自动升级。
|
|
771
784
|
* @example
|
|
772
785
|
* ```typescript
|
|
773
|
-
* //
|
|
774
|
-
* authManager.setToken('your-token');
|
|
786
|
+
* // OpenAPI 预计算 token 必须配对 timestamp
|
|
787
|
+
* authManager.setToken('your-token', Date.now());
|
|
775
788
|
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
* // 返回: { "Authorization": "Bearer your-token" }
|
|
789
|
+
* const headers = await authManager.getAuthHeaders(appCode, datasetCode);
|
|
790
|
+
* // 返回: { "X-Token": "…", "X-Time-Stamp": "…" }
|
|
779
791
|
* ```
|
|
780
792
|
*/
|
|
781
793
|
export interface AuthManager {
|
|
@@ -832,6 +844,13 @@ export interface AuthManager {
|
|
|
832
844
|
export interface LovrabetClient {
|
|
833
845
|
/** 运行态通用服务,如文件与 OCR。 */
|
|
834
846
|
readonly services: import("../services/types").LovrabetServices;
|
|
847
|
+
/**
|
|
848
|
+
* 当前用户拥有的资源,如个人 BFF。
|
|
849
|
+
*
|
|
850
|
+
* 该公共接口允许兼容旧版或外部注入的 client;createClient() 返回的
|
|
851
|
+
* 具体 LovrabetClient 实例始终提供 personal。
|
|
852
|
+
*/
|
|
853
|
+
readonly personal?: import("../personal/types").LovrabetPersonal;
|
|
835
854
|
/**
|
|
836
855
|
* 模型访问接口 - 纯粹的语法糖,支持 client.models.ModelName 访问
|
|
837
856
|
* @description 内部调用 client.getModel() 方法,提供更简洁的访问方式
|