@lovrabet/sdk 1.3.8 → 1.4.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/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/src/api/client-ak-bff-client.d.ts +31 -0
- package/dist/src/api/client-ak-sql-client.d.ts +19 -0
- package/dist/src/auth/auth-manager.d.ts +4 -8
- package/dist/src/auth/client-ak-auth.d.ts +13 -0
- package/dist/src/auth/index.d.ts +1 -0
- package/dist/src/client/client.d.ts +8 -7
- package/dist/src/models/abstract-base-model.d.ts +1 -0
- package/dist/src/models/client-ak-model.d.ts +14 -0
- package/dist/src/models/index.d.ts +1 -0
- package/dist/src/models/model-factory.d.ts +6 -14
- package/dist/src/models/openapi-model.d.ts +1 -1
- package/dist/src/types/index.d.ts +20 -1
- package/package.json +2 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
/**
|
|
3
|
+
* BFF 客户端请求参数
|
|
4
|
+
*/
|
|
5
|
+
export interface ClientAkBffExecuteRequest {
|
|
6
|
+
/** 脚本名称(endpoint 函数名) */
|
|
7
|
+
scriptName: string;
|
|
8
|
+
/** 请求体参数(可选),序列化为 JSON 作为 POST body */
|
|
9
|
+
params?: Record<string, any>;
|
|
10
|
+
/** Fetch 请求选项(可选) */
|
|
11
|
+
options?: RequestInit;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Client AK BFF 客户端 ——「执行 BFF 独立端点」(client-ak 模式)。
|
|
15
|
+
*
|
|
16
|
+
* **与自定义 SQL 无关**(SQL 见 `ClientAkSqlClient` / `client.sql.execute` → `POST /client/sql/execute`)。
|
|
17
|
+
*
|
|
18
|
+
* 与服务端约定一致(路径中拼写为 **excute**,非 execute):
|
|
19
|
+
* `POST /client/bff/excute/{appCode}/{scriptName}`
|
|
20
|
+
* - Header:`X-User-AK`、`Content-Type: application/json`(由 HttpClient 注入)
|
|
21
|
+
* - Body:业务 JSON,例如 `{ "testCase": "basic_insert" }` → 对应本类 `params`
|
|
22
|
+
*
|
|
23
|
+
* 示例:`appCode=app-cf50ad43`,`scriptName=sqlTest` →
|
|
24
|
+
* `POST .../client/bff/excute/app-cf50ad43/sqlTest`,body `{ "testCase": "basic_insert" }`。
|
|
25
|
+
*/
|
|
26
|
+
export declare class ClientAkBffClient {
|
|
27
|
+
private httpClient;
|
|
28
|
+
private appCode;
|
|
29
|
+
constructor(httpClient: HttpClient, appCode: string);
|
|
30
|
+
execute<T = any>(request: ClientAkBffExecuteRequest): Promise<T>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
import type { SqlExecuteResult } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Client AK SQL 客户端 - 执行自定义 SQL 查询(client-ak 模式)
|
|
5
|
+
*
|
|
6
|
+
* 端点:`POST /client/sql/execute`,请求体:`{ sqlCode, params? }`(与运行态技术文档 curl 一致)。
|
|
7
|
+
* 鉴权:X-User-AK(由 HttpClient 通过 AuthManager 自动注入)。
|
|
8
|
+
*
|
|
9
|
+
* BFF 调用请使用 `ClientAkBffClient`,勿与本类混用。
|
|
10
|
+
*/
|
|
11
|
+
export declare class ClientAkSqlClient {
|
|
12
|
+
private httpClient;
|
|
13
|
+
constructor(httpClient: HttpClient);
|
|
14
|
+
execute<T = Record<string, any>>(sqlCode: string | number, params?: Record<string, string | number>): Promise<SqlExecuteResult<T>>;
|
|
15
|
+
execute<T = Record<string, any>>(options: {
|
|
16
|
+
sqlCode: string | number;
|
|
17
|
+
params?: Record<string, string | number>;
|
|
18
|
+
}): Promise<SqlExecuteResult<T>>;
|
|
19
|
+
}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import type { ClientConfig, AuthHeaders
|
|
2
|
-
export declare class AuthManager
|
|
1
|
+
import type { ClientConfig, AuthHeaders } from '../types';
|
|
2
|
+
export declare class AuthManager {
|
|
3
3
|
private config;
|
|
4
4
|
private openApiAuth?;
|
|
5
5
|
private cookieAuth?;
|
|
6
|
+
private clientAkAuth?;
|
|
6
7
|
constructor(config: ClientConfig);
|
|
7
8
|
private initAuthMethods;
|
|
8
9
|
getAuthHeaders(appCode?: string, datasetCode?: string): Promise<AuthHeaders>;
|
|
9
10
|
validateAuth(): Promise<boolean>;
|
|
10
|
-
/**
|
|
11
|
-
* Check if we're using cookie-based authentication
|
|
12
|
-
*/
|
|
13
11
|
isCookieAuth(): boolean;
|
|
14
|
-
|
|
15
|
-
* Check if an explicit cookie string was provided (vs browser auto-cookie)
|
|
16
|
-
*/
|
|
12
|
+
isClientAkAuth(): boolean;
|
|
17
13
|
hasExplicitCookie(): boolean;
|
|
18
14
|
setToken(token: string, timestamp?: number): void;
|
|
19
15
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AuthHeaders } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Client AK 认证
|
|
4
|
+
*
|
|
5
|
+
* 使用 X-User-AK 请求头进行鉴权,无需签名。
|
|
6
|
+
* 适用于运行态 /client/ 接口。
|
|
7
|
+
*/
|
|
8
|
+
export declare class ClientAkAuth {
|
|
9
|
+
private accessKey;
|
|
10
|
+
constructor(accessKey: string);
|
|
11
|
+
getAuthHeaders(): Promise<AuthHeaders>;
|
|
12
|
+
isValid(): boolean;
|
|
13
|
+
}
|
package/dist/src/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AuthManager } from './auth-manager';
|
|
2
2
|
export { OpenApiAuth } from './openapi-auth';
|
|
3
|
+
export { ClientAkAuth } from './client-ak-auth';
|
|
3
4
|
export type { AuthHeaders, OpenApiAuthConfig } from '../types';
|
|
4
5
|
export { generateOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type TokenResult } from './token-generator';
|
|
@@ -2,7 +2,9 @@ import type { ClientConfig, LovrabetClient as ILovrabetClient, Environment, Base
|
|
|
2
2
|
import { ApiNamespace } from '../api';
|
|
3
3
|
import { SqlClient } from '../api/sql-client';
|
|
4
4
|
import { OpenApiSqlClient } from '../api/openapi-sql-client';
|
|
5
|
+
import { ClientAkSqlClient } from '../api/client-ak-sql-client';
|
|
5
6
|
import { BffClient } from '../api/bff-client';
|
|
7
|
+
import { ClientAkBffClient } from '../api/client-ak-bff-client';
|
|
6
8
|
import { UserClient } from '../api/user-client';
|
|
7
9
|
/**
|
|
8
10
|
* Lovrabet SDK 核心客户端类
|
|
@@ -34,11 +36,11 @@ export declare class LovrabetClient implements ILovrabetClient {
|
|
|
34
36
|
* - OpenAPI 模式:使用 OpenApiSqlClient(/openapi/data/custom-sql)
|
|
35
37
|
* - WebAPI 模式:使用 SqlClient(/api/custom/executeSql)
|
|
36
38
|
*/
|
|
37
|
-
readonly sql: SqlClient | OpenApiSqlClient;
|
|
39
|
+
readonly sql: SqlClient | OpenApiSqlClient | ClientAkSqlClient;
|
|
38
40
|
/**
|
|
39
41
|
* BFF 客户端 - 调用 Backend For Frontend 端点
|
|
40
42
|
*/
|
|
41
|
-
readonly bff: BffClient;
|
|
43
|
+
readonly bff: BffClient | ClientAkBffClient;
|
|
42
44
|
/**
|
|
43
45
|
* User 客户端 - 用户信息相关 API
|
|
44
46
|
*/
|
|
@@ -130,11 +132,10 @@ export declare class LovrabetClient implements ILovrabetClient {
|
|
|
130
132
|
getModel(indexOrName: number | string): BaseModelMethods;
|
|
131
133
|
/**
|
|
132
134
|
* 检查当前是否为 OpenAPI 模式
|
|
133
|
-
* 为什么提供这个方法:
|
|
134
|
-
* 1. 让用户能够了解当前使用的认证和API模式
|
|
135
|
-
* 2. 支持根据模式执行不同的业务逻辑
|
|
136
|
-
* 3. 便于调试和排查问题
|
|
137
|
-
* 4. 与 BaseModel 的逻辑保持一致
|
|
138
135
|
*/
|
|
139
136
|
isOpenApiMode(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* 解析鉴权模式。无 authMode → cookie;有则严格遵循。
|
|
139
|
+
*/
|
|
140
|
+
private resolveAuthMode;
|
|
140
141
|
}
|
|
@@ -36,6 +36,7 @@ export declare abstract class AbstractBaseModel implements BaseModelMethods {
|
|
|
36
36
|
id: string | number;
|
|
37
37
|
}): Promise<T>;
|
|
38
38
|
create<T = any>(data: Record<string, any>): Promise<T>;
|
|
39
|
+
batchCreate<T = any>(items: Record<string, any>[]): Promise<T>;
|
|
39
40
|
/**
|
|
40
41
|
* 更新记录,支持单条和批量。
|
|
41
42
|
*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractBaseModel } from './abstract-base-model';
|
|
2
|
+
import type { SortList } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Client AK 模型实现
|
|
5
|
+
*
|
|
6
|
+
* 路由到 /client/{appCode}/{datasetCode}/ 前缀,
|
|
7
|
+
* 鉴权使用 X-User-AK(由 AuthManager 在 HttpClient 层自动注入)。
|
|
8
|
+
*
|
|
9
|
+
* 请求体策略:直接透传(不包装 paramMap)。
|
|
10
|
+
*/
|
|
11
|
+
export declare class ClientAkModel extends AbstractBaseModel {
|
|
12
|
+
protected getApiPath(sdkMethod: string): string;
|
|
13
|
+
protected buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
14
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { AbstractBaseModel } from './abstract-base-model';
|
|
2
2
|
export { OpenApiModel } from './openapi-model';
|
|
3
3
|
export { WebApiModel } from './webapi-model';
|
|
4
|
+
export { ClientAkModel } from './client-ak-model';
|
|
4
5
|
export { ModelFactory } from './model-factory';
|
|
5
6
|
export { ModelManager } from './model-manager';
|
|
6
7
|
export type { BaseModelMethods, ModelManager as IModelManager } from '../types';
|
|
@@ -2,23 +2,15 @@ import type { BaseModelMethods, ClientConfig, ModelConfig } from '../types';
|
|
|
2
2
|
import type { HttpClient } from '../http/http-client';
|
|
3
3
|
/**
|
|
4
4
|
* 模型工厂类
|
|
5
|
-
* 根据配置决定创建 OpenAPI 或
|
|
5
|
+
* 根据配置决定创建 OpenAPI、WebAPI 或 ClientAK 模型实例
|
|
6
|
+
*
|
|
7
|
+
* 规则:无 authMode → cookie(即 webapi);有 authMode 则严格遵循。
|
|
6
8
|
*/
|
|
7
9
|
export declare class ModelFactory {
|
|
8
|
-
/**
|
|
9
|
-
* 创建模型实例
|
|
10
|
-
* @param datasetCode 数据集代码(作为模型标识)
|
|
11
|
-
* @param httpClient HTTP 客户端
|
|
12
|
-
* @param globalConfig 全局配置
|
|
13
|
-
* @param modelConfig 模型配置(直接传入,不再从 globalConfig 中查找)
|
|
14
|
-
*/
|
|
15
10
|
static createModel(datasetCode: string, httpClient: HttpClient, globalConfig: ClientConfig, modelConfig: ModelConfig): BaseModelMethods;
|
|
16
11
|
/**
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
private static isOpenApiMode;
|
|
20
|
-
/**
|
|
21
|
-
* 获取当前模式名称(用于调试)
|
|
12
|
+
* 无 authMode → cookie(webapi);有 authMode 则严格遵循
|
|
22
13
|
*/
|
|
23
|
-
static
|
|
14
|
+
private static resolveAuthMode;
|
|
15
|
+
static getModeName(config: ClientConfig): 'OpenAPI' | 'WebAPI' | 'ClientAK';
|
|
24
16
|
}
|
|
@@ -12,7 +12,7 @@ export declare class OpenApiModel extends AbstractBaseModel {
|
|
|
12
12
|
/**
|
|
13
13
|
* OpenAPI 模式的请求体构建策略
|
|
14
14
|
* 认证信息(token、timeStamp)由 HttpClient 自动添加到请求头(Header)中
|
|
15
|
-
* 请求体格式:{ appCode, datasetCode, paramMap }
|
|
15
|
+
* 请求体格式:{ appCode, datasetCode, paramMap };batchCreate 为数组体,使用 paramList(与 paramMap 互斥语义)
|
|
16
16
|
*/
|
|
17
17
|
protected buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
18
18
|
/**
|
|
@@ -109,8 +109,9 @@ export interface ListResponse<T> {
|
|
|
109
109
|
* - $contain: 包含(模糊匹配)
|
|
110
110
|
* - $startWith: 以...开头
|
|
111
111
|
* - $endWith: 以...结尾
|
|
112
|
+
* - $notNull: 非空判断
|
|
112
113
|
*/
|
|
113
|
-
export type ConditionOperator = "$eq" | "$ne" | "$gte" | "$gteq" | "$lte" | "$lteq" | "$in" | "$contain" | "$startWith" | "$endWith";
|
|
114
|
+
export type ConditionOperator = "$eq" | "$ne" | "$gte" | "$gteq" | "$lte" | "$lteq" | "$in" | "$contain" | "$startWith" | "$endWith" | "$notNull";
|
|
114
115
|
/**
|
|
115
116
|
* 字段条件类型
|
|
116
117
|
* @description 单个字段的查询条件
|
|
@@ -124,6 +125,8 @@ export type ConditionOperator = "$eq" | "$ne" | "$gte" | "$gteq" | "$lte" | "$lt
|
|
|
124
125
|
* { country: { $in: ['中国', '美国', '日本'] } }
|
|
125
126
|
* // 模糊匹配
|
|
126
127
|
* { name: { $contain: 'hello' } }
|
|
128
|
+
* // 非空判断
|
|
129
|
+
* { app_code: { $notNull: true } }
|
|
127
130
|
* ```
|
|
128
131
|
*/
|
|
129
132
|
export type FieldCondition = {
|
|
@@ -383,6 +386,13 @@ export interface ModelsConfig {
|
|
|
383
386
|
* };
|
|
384
387
|
* ```
|
|
385
388
|
*/
|
|
389
|
+
/**
|
|
390
|
+
* 鉴权模式类型
|
|
391
|
+
* - "openapi": OpenAPI 签名模式(accessKey + secretKey),走 /openapi/ 前缀
|
|
392
|
+
* - "client-ak": Client AK 模式(仅 accessKey),走 /client/ 前缀,X-User-AK 鉴权
|
|
393
|
+
* - "cookie": Cookie 模式,走 /api/ 前缀
|
|
394
|
+
*/
|
|
395
|
+
export type AuthMode = "openapi" | "client-ak" | "cookie";
|
|
386
396
|
export interface ClientConfig {
|
|
387
397
|
/** 应用代码,用于标识不同的应用 */
|
|
388
398
|
appCode?: string;
|
|
@@ -416,6 +426,8 @@ export interface ClientConfig {
|
|
|
416
426
|
cookie?: string;
|
|
417
427
|
/** 是否需要认证,默认为 true */
|
|
418
428
|
requiresAuth?: boolean;
|
|
429
|
+
/** 显式声明鉴权模式,优先于字段组合推断。向下兼容:未设置时保持旧推断逻辑 */
|
|
430
|
+
authMode?: AuthMode;
|
|
419
431
|
/**
|
|
420
432
|
* 模型配置
|
|
421
433
|
* - 数组格式(推荐):直接使用 datasetCode 访问
|
|
@@ -522,6 +534,13 @@ export interface BaseModelMethods {
|
|
|
522
534
|
* @returns 返回创建后的数据
|
|
523
535
|
*/
|
|
524
536
|
create<T = any>(data: Record<string, any>): Promise<T>;
|
|
537
|
+
/**
|
|
538
|
+
* 批量创建数据
|
|
539
|
+
* @template T 返回数据的类型
|
|
540
|
+
* @param items 要创建的数据对象数组,最多 1000 条
|
|
541
|
+
* @returns 返回创建后的数据
|
|
542
|
+
*/
|
|
543
|
+
batchCreate<T = any>(items: Record<string, any>[]): Promise<T>;
|
|
525
544
|
/**
|
|
526
545
|
* 更新数据,支持单条和批量
|
|
527
546
|
* @template T 返回数据的类型
|
package/package.json
CHANGED