@lovrabet/sdk 1.2.6 → 1.2.9-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.
@@ -0,0 +1,44 @@
1
+ import type { HttpClient } from "../http/http-client";
2
+ import type { FxResult } from "./types";
3
+ /**
4
+ * BFF 客户端 - 调用 Backend For Frontend 端点
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // 无参数调用
9
+ * const result = await client.bff.execute('getBundleTemplates');
10
+ * if (result.success) {
11
+ * console.log(result.data);
12
+ * }
13
+ *
14
+ * // 带参数调用
15
+ * const result = await client.bff.execute('calculatePrice', {
16
+ * productId: '123',
17
+ * quantity: 10
18
+ * });
19
+ *
20
+ * // 带类型提示
21
+ * interface BundleTemplate {
22
+ * id: string;
23
+ * name: string;
24
+ * items: string[];
25
+ * }
26
+ * const result = await client.bff.execute<BundleTemplate>('getBundleTemplates');
27
+ * if (result.success && result.data) {
28
+ * result.data.forEach(template => console.log(template.name));
29
+ * }
30
+ * ```
31
+ */
32
+ export declare class BffClient {
33
+ private httpClient;
34
+ private appCode;
35
+ constructor(httpClient: HttpClient, appCode: string);
36
+ /**
37
+ * 调用 Backend For Frontend (BFF) 端点
38
+ *
39
+ * @param scriptName 脚本名称(endpoint 函数名)
40
+ * @param bodyParams 请求体参数(可选)
41
+ * @returns Function 执行结果(包含 success 和 data)
42
+ */
43
+ execute<T = any>(scriptName: string, bodyParams?: Record<string, any>): Promise<FxResult<T>>;
44
+ }
@@ -1,10 +1,4 @@
1
1
  import type { HttpClient } from "../http";
2
+ import type { User } from "./types";
2
3
  export declare function getUserList(httpClient: HttpClient): Promise<User[]>;
3
- export type User = {
4
- code: string;
5
- userName: string;
6
- nickName?: string | null;
7
- mobile: string;
8
- email?: string | null;
9
- avatar?: string | null;
10
- };
4
+ export type { User };
@@ -1,54 +1,87 @@
1
1
  import type { HttpClient } from "../http/http-client";
2
- import type { SqlExecuteResult } from "./types";
2
+ import { SqlClient } from "./sql-client";
3
+ import { BffClient } from "./bff-client";
4
+ import { UserClient } from "./user-client";
3
5
  /**
4
- * API 命名空间 - 管理通用 API 调用(SQL、Function 等)
6
+ * API 命名空间 - 别名入口
5
7
  *
6
- * 设计原则:
7
- * 1. 依赖注入 - 通过构造函数注入 HttpClient
8
- * 2. 类型安全 - 支持泛型,提供 TypeScript 类型推断
9
- * 3. 统一错误处理 - 成功返回数据,失败抛出 LovrabetError
10
- * 4. 风格一致 - 与 Model 的 getList/getOne 保持一致
8
+ * 推荐使用客户端方式:
9
+ * - SQL: `client.sql.execute()`
10
+ * - BFF: `client.bff.execute()`
11
+ * - User: `client.user.getList()`
12
+ *
13
+ * 此命名空间提供向后兼容的别名:
14
+ * - `client.api.sql()` → `client.sql.execute()`
15
+ * - `client.api.bff()` → `client.bff.execute()`
16
+ * - `client.api.getUserList()` → `client.user.getList()`
11
17
  */
12
18
  export declare class ApiNamespace {
13
19
  private httpClient;
14
- constructor(httpClient: HttpClient);
20
+ private appCode;
21
+ constructor(httpClient: HttpClient, appCode: string);
22
+ /**
23
+ * SQL 客户端实例
24
+ */
25
+ private _sql?;
26
+ /**
27
+ * SQL 查询别名 - 推荐使用 `client.sql.execute()`
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // 推荐用法
32
+ * const data = await client.sql.execute('fc8e7777-06e3847d');
33
+ *
34
+ * // 别名用法(兼容)
35
+ * const data = await client.api.sql('fc8e7777-06e3847d');
36
+ * ```
37
+ */
38
+ get sql(): SqlClient["execute"];
15
39
  /**
16
- * 执行自定义 SQL 查询
40
+ * SQL 查询别名(旧名称)- 向后兼容
17
41
  *
18
- * @param sqlCode SQL代码(字符串格式 "appCode-sqlId" 或数字ID)
19
- * @param params SQL参数对象(可选)
20
- * @returns SQL执行结果(包含 execSuccess 和 execResult)
42
+ * @deprecated 使用 `client.sql.execute()` `client.api.sql()`
43
+ */
44
+ get executeSql(): SqlClient["execute"];
45
+ /**
46
+ * BFF 客户端实例
47
+ */
48
+ private _bff?;
49
+ /**
50
+ * BFF 查询别名 - 推荐使用 `client.bff.execute()`
21
51
  *
22
52
  * @example
23
53
  * ```typescript
24
- * // 无参数查询
25
- * const data = await client.api.executeSql('fc8e7777-06e3847d');
26
- * if (data.execSuccess) {
27
- * const results = data.execResult;
28
- * results.forEach(item => console.log(item));
29
- * }
30
- *
31
- * // 参数化查询
32
- * const data = await client.api.executeSql('fc8e7777-xxxxx', {
33
- * userId: '123',
34
- * startDate: '2025-01-01'
35
- * });
36
- *
37
- * // 带类型提示
38
- * interface PageStat {
39
- * creation_date: string;
40
- * page_count: number;
41
- * }
42
- * const data = await client.api.executeSql<PageStat>('fc8e7777-06e3847d');
43
- * if (data.execSuccess && data.execResult) {
44
- * data.execResult.forEach(stat => {
45
- * console.log(stat.creation_date, stat.page_count);
46
- * });
47
- * }
54
+ * // 推荐用法
55
+ * const result = await client.bff.execute('getBundleTemplates');
56
+ *
57
+ * // 别名用法(兼容)
58
+ * const result = await client.api.bff('getBundleTemplates');
48
59
  * ```
49
60
  */
50
- executeSql<T = Record<string, any>>(sqlCode: string | number, params?: Record<string, string | number>): Promise<SqlExecuteResult<T>>;
51
- user: {
52
- getList: () => Promise<import("./get-user-list").User[]>;
61
+ get bff(): BffClient["execute"];
62
+ /**
63
+ * User 客户端实例
64
+ */
65
+ private _user?;
66
+ /**
67
+ * User 查询别名 - 推荐使用 `client.user.getList()`
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // 推荐用法
72
+ * const userList = await client.user.getList();
73
+ *
74
+ * // 别名用法(兼容)
75
+ * const userList = await client.api.getUserList();
76
+ * ```
77
+ */
78
+ get getUserList(): UserClient["getList"];
79
+ /**
80
+ * User 客户端别名 - 推荐使用 `client.user.getList()`
81
+ *
82
+ * @deprecated 使用 `client.user.getList()`
83
+ */
84
+ get user(): {
85
+ getList: UserClient["getList"];
53
86
  };
54
87
  }
@@ -0,0 +1,45 @@
1
+ import type { HttpClient } from "../http/http-client";
2
+ import type { SqlExecuteResult } from "./types";
3
+ /**
4
+ * SQL 客户端 - 执行自定义 SQL 查询
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // 方式1:直接传参(推荐)
9
+ * const data = await client.sql.execute('fc8e7777-06e3847d', {
10
+ * userId: '123',
11
+ * startDate: '2025-01-01'
12
+ * });
13
+ *
14
+ * // 方式2:对象参数(兼容 customSql.execute)
15
+ * const data = await client.sql.execute({
16
+ * sqlCode: 'fc8e7777-06e3847d',
17
+ * params: { userId: '123' }
18
+ * });
19
+ *
20
+ * // 带类型提示
21
+ * interface PageStat {
22
+ * creation_date: string;
23
+ * page_count: number;
24
+ * }
25
+ * const data = await client.sql.execute<PageStat>('fc8e7777-06e3847d');
26
+ * ```
27
+ */
28
+ export declare class SqlClient {
29
+ private httpClient;
30
+ constructor(httpClient: HttpClient);
31
+ /**
32
+ * 执行自定义 SQL 查询
33
+ *
34
+ * 支持两种调用方式:
35
+ * 1. execute(sqlCode, params) - 直接传参(推荐)
36
+ * 2. execute({ sqlCode, params }) - 对象参数(兼容 customSql.execute)
37
+ *
38
+ * @returns SQL执行结果(包含 execSuccess 和 execResult)
39
+ */
40
+ execute<T = Record<string, any>>(sqlCode: string | number, params?: Record<string, string | number>): Promise<SqlExecuteResult<T>>;
41
+ execute<T = Record<string, any>>(options: {
42
+ sqlCode: string | number;
43
+ params?: Record<string, string | number>;
44
+ }): Promise<SqlExecuteResult<T>>;
45
+ }
@@ -16,3 +16,38 @@ export interface SqlExecuteResult<T = Record<string, any>> {
16
16
  /** SQL 查询结果数组 */
17
17
  execResult?: T[];
18
18
  }
19
+ /**
20
+ * Backend Function (独立端点) 请求参数
21
+ */
22
+ export interface FxRequest {
23
+ /** 请求体参数,由调用方传递任意 JSON 数据 */
24
+ [key: string]: any;
25
+ }
26
+ /**
27
+ * Backend Function (独立端点) 执行结果数据
28
+ */
29
+ export interface FxResult<T = any> {
30
+ /** Function 执行是否成功 */
31
+ success: boolean;
32
+ /** Function 返回的业务数据 */
33
+ data?: T;
34
+ /** 错误消息(执行失败时) */
35
+ message?: string;
36
+ }
37
+ /**
38
+ * 用户信息
39
+ */
40
+ export interface User {
41
+ /** 用户代码 */
42
+ code: string;
43
+ /** 用户名 */
44
+ userName: string;
45
+ /** 昵称 */
46
+ nickName?: string | null;
47
+ /** 手机号 */
48
+ mobile: string;
49
+ /** 邮箱 */
50
+ email?: string | null;
51
+ /** 头像 */
52
+ avatar?: string | null;
53
+ }
@@ -0,0 +1,20 @@
1
+ import type { HttpClient } from "../http/http-client";
2
+ /**
3
+ * User 客户端 - 用户信息相关 API
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const userList = await client.user.getList();
8
+ * console.log(userList);
9
+ * ```
10
+ */
11
+ export declare class UserClient {
12
+ private httpClient;
13
+ constructor(httpClient: HttpClient);
14
+ /**
15
+ * 获取用户列表
16
+ *
17
+ * @returns 用户列表数组
18
+ */
19
+ getList: () => Promise<import("./types").User[]>;
20
+ }
@@ -1,5 +1,8 @@
1
1
  import type { ClientConfig, LovrabetClient as ILovrabetClient, Environment, BaseModelMethods } from '../types';
2
2
  import { ApiNamespace } from '../api';
3
+ import { SqlClient } from '../api/sql-client';
4
+ import { BffClient } from '../api/bff-client';
5
+ import { UserClient } from '../api/user-client';
3
6
  /**
4
7
  * Lovrabet SDK 核心客户端类
5
8
  *
@@ -25,7 +28,24 @@ export declare class LovrabetClient implements ILovrabetClient {
25
28
  [modelName: string]: BaseModelMethods;
26
29
  };
27
30
  /**
28
- * API 命名空间 - 提供通用 API 调用(SQL、Function 等)
31
+ * SQL 客户端 - 执行自定义 SQL 查询
32
+ */
33
+ readonly sql: SqlClient;
34
+ /**
35
+ * BFF 客户端 - 调用 Backend For Frontend 端点
36
+ */
37
+ readonly bff: BffClient;
38
+ /**
39
+ * User 客户端 - 用户信息相关 API
40
+ */
41
+ readonly user: UserClient;
42
+ /**
43
+ * API 命名空间 - 别名入口(向后兼容)
44
+ *
45
+ * 推荐使用命名空间方式:
46
+ * - `client.sql.execute()` 而非 `client.api.sql()`
47
+ * - `client.bff.execute()` 而非 `client.api.bff()`
48
+ * - `client.user.getList()` 而非 `client.api.getUserList()`
29
49
  */
30
50
  readonly api: ApiNamespace;
31
51
  constructor(config: ClientConfig);
@@ -54,6 +74,8 @@ export declare class LovrabetClient implements ILovrabetClient {
54
74
  * 1. 用户可能需要知道当前使用的 API 地址用于调试
55
75
  * 2. 某些场景可能需要直接使用基础地址构造 URL
56
76
  * 3. 支持自定义服务器地址的覆盖逻辑
77
+ *
78
+ * 透传调用 HttpClient.getBaseUrl(),确保单一数据源
57
79
  */
58
80
  getBaseUrl(): string;
59
81
  /**
@@ -4,7 +4,11 @@ export declare class HttpClient {
4
4
  private authManager;
5
5
  private errorHandler;
6
6
  constructor(config: ClientConfig, authManager: AuthManager);
7
- private getBaseUrl;
7
+ /**
8
+ * 获取 API 基础地址
9
+ * 优先级:serverUrl > window.__GLOBAL__.deploymentConfig.RUNTIME_API_DOMAIN > getApiEndpoint(env)
10
+ */
11
+ getBaseUrl(): string;
8
12
  private getFullUrl;
9
13
  /**
10
14
  * 准备请求的通用逻辑:认证头、Cookie配置等
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovrabet/sdk",
3
- "version": "1.2.6",
3
+ "version": "1.2.9-beta.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",