@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
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ import { createClient } from "@lovrabet/sdk";
|
|
|
61
61
|
// 使用 accessKey 认证(推荐)
|
|
62
62
|
const client = createClient({
|
|
63
63
|
appCode: "your-app-code",
|
|
64
|
+
authMode: "openapi", // 使用 accessKey 时必须显式声明;缺省 authMode 一律走 cookie,accessKey 会被忽略
|
|
64
65
|
accessKey: process.env.LOVRABET_ACCESS_KEY,
|
|
65
66
|
models: [
|
|
66
67
|
{ tableName: "users", datasetCode: "abc123def456", alias: "users" },
|
|
@@ -107,6 +108,7 @@ const { token, timestamp } = await fetch("/api/token").then((r) => r.json());
|
|
|
107
108
|
// 创建客户端
|
|
108
109
|
const client = createClient({
|
|
109
110
|
appCode: "your-app-code",
|
|
111
|
+
authMode: "openapi", // 使用 token 时必须显式声明;缺省 authMode 一律走 cookie,token 会被忽略
|
|
110
112
|
token: token,
|
|
111
113
|
timestamp: timestamp,
|
|
112
114
|
models: [
|
|
@@ -551,20 +553,40 @@ interface ClientConfig {
|
|
|
551
553
|
secretKey?: string; // 密钥(可选)
|
|
552
554
|
token?: string; // 预生成 token(浏览器)
|
|
553
555
|
timestamp?: number; // token 时间戳
|
|
554
|
-
env?: "online" | "daily"; // 环境
|
|
556
|
+
env?: "production" | "online" | "daily" | "development"; // 环境
|
|
557
|
+
region?: "cn" | "id"; // 官方节点,默认 cn
|
|
558
|
+
runtimeDomain?: string; // 企业独立部署覆盖,优先于 region
|
|
555
559
|
models?: ModelsConfig; // 模型配置
|
|
556
560
|
}
|
|
557
561
|
```
|
|
558
562
|
|
|
563
|
+
官方印尼节点:
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
const client = createClient({
|
|
567
|
+
appCode: "app-xxx",
|
|
568
|
+
region: "id",
|
|
569
|
+
env: "production"
|
|
570
|
+
});
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
企业独立部署直接传入 `runtimeDomain`。解析优先级为:`runtimeDomain` →
|
|
574
|
+
兼容字段 `serverUrl` → 页面注入的 `RUNTIME_API_DOMAIN` → `region + env`
|
|
575
|
+
→ 默认 CN Production。
|
|
576
|
+
|
|
577
|
+
SDK 会对显式 Runtime 地址去除首尾空白和尾斜杠,并拒绝非法 URL、凭证、
|
|
578
|
+
query 或 fragment。未传 `region` 时默认 `cn`;显式传入 `cn` / `id` 以外的值
|
|
579
|
+
会抛出 `INVALID_REGION`,不会静默请求其他区域。
|
|
580
|
+
|
|
559
581
|
### CRUD 操作
|
|
560
582
|
|
|
561
583
|
```typescript
|
|
562
|
-
// 查询列表(返回 tableData/
|
|
584
|
+
// 查询列表(返回 tableData 与 paging: totalCount/currentPage/pageSize)
|
|
563
585
|
const response = await client.models.users.getList({
|
|
564
586
|
currentPage: 1,
|
|
565
587
|
pageSize: 20,
|
|
566
588
|
});
|
|
567
|
-
console.log(response.
|
|
589
|
+
console.log(response.paging.totalCount); // 总数量
|
|
568
590
|
console.log(response.tableData); // 数据列表
|
|
569
591
|
|
|
570
592
|
// 查询列表(带排序)
|
|
@@ -641,8 +663,8 @@ const result = await client.models.users.filter({
|
|
|
641
663
|
pageSize: 20
|
|
642
664
|
});
|
|
643
665
|
|
|
644
|
-
console.log(result.tableData);
|
|
645
|
-
console.log(result.
|
|
666
|
+
console.log(result.tableData); // 数据列表
|
|
667
|
+
console.log(result.paging.totalCount); // 总数量
|
|
646
668
|
```
|
|
647
669
|
|
|
648
670
|
#### 复杂条件组合
|
|
@@ -679,12 +701,15 @@ const result = await client.models.users.filter({
|
|
|
679
701
|
|--------|------|------|
|
|
680
702
|
| `$eq` | 等于 | `{ status: { $eq: 'active' } }` |
|
|
681
703
|
| `$ne` | 不等于 | `{ status: { $ne: 'deleted' } }` |
|
|
682
|
-
| `$
|
|
683
|
-
| `$
|
|
704
|
+
| `$gt` | 大于 | `{ age: { $gt: 18 } }` |
|
|
705
|
+
| `$lt` | 小于 | `{ age: { $lt: 65 } }` |
|
|
706
|
+
| `$gte`(推荐)/ `$gteq`(兼容旧写法) | 大于等于 | `{ age: { $gte: 18 } }` |
|
|
707
|
+
| `$lte`(推荐)/ `$lteq`(兼容旧写法) | 小于等于 | `{ age: { $lte: 65 } }` |
|
|
684
708
|
| `$in` | 在集合内 | `{ country: { $in: ['中国', '美国'] } }` |
|
|
685
709
|
| `$contain` | 包含(模糊匹配) | `{ name: { $contain: 'test' } }` |
|
|
686
710
|
| `$startWith` | 以...开头 | `{ name: { $startWith: 'Mr.' } }` |
|
|
687
711
|
| `$endWith` | 以...结尾 | `{ email: { $endWith: '@example.com' } }` |
|
|
712
|
+
| `$notNull` | 非空判断 | `{ app_code: { $notNull: true } }` |
|
|
688
713
|
|
|
689
714
|
#### 逻辑连接符
|
|
690
715
|
|
|
@@ -747,8 +772,8 @@ const result = await client.models.users.filter({
|
|
|
747
772
|
|
|
748
773
|
**OpenAPI 模式暂不支持以下操作:**
|
|
749
774
|
|
|
750
|
-
- ❌ `delete()` -
|
|
751
|
-
- ❌ `getSelectOptions()` -
|
|
775
|
+
- ❌ `delete()` - 删除操作(OpenAPI 不支持;WebAPI 与 Client AK 模式可用)
|
|
776
|
+
- ❌ `getSelectOptions()` - 获取下拉选项(OpenAPI 不支持;WebAPI 与 Client AK 模式可用)
|
|
752
777
|
|
|
753
778
|
```typescript
|
|
754
779
|
// OpenAPI 模式调用 delete 会抛出错误
|
|
@@ -777,6 +802,7 @@ await webApiClient.models.users.delete("user-id"); // ✅ 可以使用
|
|
|
777
802
|
```typescript
|
|
778
803
|
// 绝不要在客户端代码中硬编码 accessKey
|
|
779
804
|
const client = createClient({
|
|
805
|
+
authMode: "openapi",
|
|
780
806
|
accessKey: "sk_live_xxx", // 危险!会暴露密钥
|
|
781
807
|
});
|
|
782
808
|
```
|
|
@@ -788,6 +814,7 @@ const client = createClient({
|
|
|
788
814
|
```typescript
|
|
789
815
|
// 使用环境变量存储敏感信息
|
|
790
816
|
const client = createClient({
|
|
817
|
+
authMode: "openapi", // 使用 accessKey 时必须显式声明;缺省 authMode 一律走 cookie,accessKey 会被忽略
|
|
791
818
|
accessKey: process.env.LOVRABET_ACCESS_KEY,
|
|
792
819
|
});
|
|
793
820
|
```
|
|
@@ -795,9 +822,9 @@ const client = createClient({
|
|
|
795
822
|
**客户端:**
|
|
796
823
|
|
|
797
824
|
```typescript
|
|
798
|
-
// 使用服务端生成的 token
|
|
799
|
-
const { token } = await fetch("/api/token").then((r) => r.json());
|
|
800
|
-
const client = createClient({ token });
|
|
825
|
+
// 使用服务端生成的 token(OpenAPI 预计算 token 必须配对 timestamp)
|
|
826
|
+
const { token, timestamp } = await fetch("/api/token").then((r) => r.json());
|
|
827
|
+
const client = createClient({ authMode: "openapi", token, timestamp });
|
|
801
828
|
```
|
|
802
829
|
|
|
803
830
|
## 🎯 选择正确的认证模式
|
|
@@ -939,6 +966,7 @@ const client = createClient({ token });
|
|
|
939
966
|
```typescript
|
|
940
967
|
const client = createClient({
|
|
941
968
|
appCode: "your-app-code",
|
|
969
|
+
authMode: "openapi", // 使用 accessKey 时必须显式声明;缺省 authMode 一律走 cookie
|
|
942
970
|
accessKey: process.env.LOVRABET_ACCESS_KEY, // OpenAPI 模式下使用 filter(v1.1.22+)
|
|
943
971
|
models: [
|
|
944
972
|
{ tableName: "users", datasetCode: "abc123def456", alias: "users" },
|
|
@@ -1135,6 +1163,7 @@ const client = createClient({ token });
|
|
|
1135
1163
|
```typescript
|
|
1136
1164
|
const client = createClient({
|
|
1137
1165
|
appCode: "your-app",
|
|
1166
|
+
authMode: "openapi", // 使用 accessKey 时必须显式声明;缺省 authMode 一律走 cookie
|
|
1138
1167
|
accessKey: process.env.ACCESS_KEY,
|
|
1139
1168
|
options: {
|
|
1140
1169
|
debug: true, // 启用调试日志
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createClient } from "./src/client/index";
|
|
2
2
|
export { registerModels, getRegisteredModels, getRegisteredConfigNames, unregisterModels, clearAllRegistrations, } from "./src/config/model-registry";
|
|
3
|
-
export { getApiEndpoint, getAvailableEnvironments, } from "./src/config/endpoints";
|
|
4
|
-
export { CONFIG_NAMES, ENVIRONMENTS, DEFAULTS, HTTP_STATUS, ERROR_MESSAGES, API_PATHS, } from "./src/config/constants";
|
|
3
|
+
export { getApiEndpoint, getAvailableEnvironments, getAvailableRegions, } from "./src/config/endpoints";
|
|
4
|
+
export { CONFIG_NAMES, ENVIRONMENTS, REGIONS, DEFAULTS, HTTP_STATUS, ERROR_MESSAGES, API_PATHS, } from "./src/config/constants";
|
|
5
5
|
export { LovrabetError } from "./src/utils/errors";
|
|
6
6
|
export { safe } from "./src/utils/safe";
|
|
7
7
|
export type { SafeResult } from "./src/utils/safe";
|
|
@@ -11,9 +11,11 @@ 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 { PersonalNamespace, PersonalBffClient, } from "./src/personal/index";
|
|
15
|
+
export type { LovrabetPersonal, PersonalBffExecuteRequest, PersonalBffService, PersonalRequestOptions, } from "./src/personal/index";
|
|
14
16
|
export { AuthManager, } from "./src/auth/index";
|
|
15
17
|
export { generateOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type TokenResult } from "./src/auth/index";
|
|
16
|
-
export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, AuthMode, } from "./src/types/index";
|
|
18
|
+
export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, AuthMode, Region, } from "./src/types/index";
|
|
17
19
|
export type { ListParams, ListResponse, FilterParams, WhereCondition, FieldCondition, ConditionOperator, Environment, BaseModelMethods, SortList, SelectOption, SelectOptionsParams, AggregateParams, AggregateField, HavingCondition, } from "./src/types/index";
|
|
18
20
|
export type { SqlExecuteRequest, SqlExecuteResult, } from "./src/api/types";
|
|
19
21
|
export { SortOrder, } from "./src/types/index";
|