@lovrabet/sdk 1.4.2-beta.0 → 1.4.3-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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## ✨ 特性
6
6
 
7
- - 🔐 **三种认证模式** - OpenAPI(服务端)、OpenAPI(浏览器)、WebAPI(Cookie)
7
+ - 🔐 **三种认证模式** - OpenAPI、Client AK、WebAPI(Cookie)
8
8
  - 🎯 **环境自适应** - 根据运行环境自动选择最佳认证方式
9
9
  - 🔑 **Token 生成** - 内置 Token 生成器,支持批量生成
10
10
  - 📦 **TypeScript** - 完整的类型定义和智能提示
@@ -155,6 +155,93 @@ const client = createClient({
155
155
  const users = await client.models.users.getList();
156
156
  ```
157
157
 
158
+ ### 运行态服务:OCR
159
+
160
+ OCR 通过 `client.services.ocr` 提供统一入口。SDK 会根据认证模式选择真实服务端路由:
161
+
162
+ - `cookie`:调用 WebAPI `GET /api/ocr/recognize-text`
163
+ - `client-ak`:调用 Client API `POST /client/ocr`
164
+ - `openapi`:当前没有对应 OCR 契约,会在发送请求前抛出 `OCR_AUTH_MODE_UNSUPPORTED`
165
+
166
+ 浏览器或显式 Cookie 场景:
167
+
168
+ ```typescript
169
+ import { createClient, OCR_TYPES, OcrType } from "@lovrabet/sdk";
170
+
171
+ const client = createClient({
172
+ appCode: "your-app-code",
173
+ authMode: "cookie",
174
+ // 浏览器会自动携带 Cookie;Node.js 可在这里传入 cookie
175
+ });
176
+
177
+ const result = await client.services.ocr.recognize({
178
+ url: "https://example.com/invoice.png",
179
+ type: OcrType.Invoice,
180
+ });
181
+
182
+ console.log(result.text, result.kvData);
183
+ console.log(OCR_TYPES); // 可直接用于下拉框或能力发现
184
+ ```
185
+
186
+ Client AK 场景:
187
+
188
+ ```typescript
189
+ import { createClient, OcrType } from "@lovrabet/sdk";
190
+
191
+ const client = createClient({
192
+ appCode: "your-app-code",
193
+ authMode: "client-ak",
194
+ accessKey: process.env.LOVRABET_ACCESS_KEY,
195
+ });
196
+
197
+ const result = await client.services.ocr.recognize({
198
+ url: "https://example.com/license.png",
199
+ type: OcrType.BusinessLicense,
200
+ });
201
+ ```
202
+
203
+ 当前支持的 OCR 类型为 `General`、`Invoice`、`Advanced`、`AdvancedCoordinate`、
204
+ `AdvancedGeneral`、`IdCard`、`BankCard`、`BusinessLicense`、`DrivingLicense`、
205
+ `CarNumber` 和 `Table`。当前 SDK OCR 接口只接收 URL,不负责本地文件上传。
206
+
207
+ ### 运行态服务:文件
208
+
209
+ 文件上传与访问 URL 查询通过 `client.services.file` 提供。SDK 根据认证模式选择路由:
210
+
211
+ - `cookie`:在 Runtime 域名调用 WebAPI `/api/common/uploadFile`、`/api/common/queryFileUrl`
212
+ - `client-ak`:调用 Client API `/client/uploadFile`、`/client/queryFileUrl`
213
+ - `openapi`:当前没有对应文件接口契约
214
+
215
+ 浏览器上传:
216
+
217
+ ```typescript
218
+ const client = createClient({
219
+ appCode: "your-app-code",
220
+ authMode: "cookie",
221
+ });
222
+
223
+ const uploaded = await client.services.file.upload({ file: input.files[0] });
224
+ const access = await client.services.file.queryUrl({
225
+ filePath: uploaded.filePath!,
226
+ });
227
+ ```
228
+
229
+ Cookie 与 Client AK 模式都使用 `runtimeDomain`。认证模式只决定路由与请求头:
230
+ Cookie 使用 WebAPI 路由并携带 Cookie,Client AK 使用 `/client/*` 路由并携带
231
+ `X-User-AK`。
232
+
233
+ Node.js 可传入标准 `Blob`,并显式提供文件名:
234
+
235
+ ```typescript
236
+ const uploaded = await client.services.file.upload({
237
+ file: new Blob([buffer], { type: "application/pdf" }),
238
+ fileName: "invoice.pdf",
239
+ });
240
+ ```
241
+
242
+ `filePath` 是适合业务字段长期保存的稳定引用。`fileUrl` 默认用于临时预览、OCR
243
+ 或短时间消费;只有 URL-only 内容需要长期展示时才传 `longTerm: true`。
244
+
158
245
  ## 🔑 Token 管理
159
246
 
160
247
  ### 生成单个 Token
@@ -409,6 +496,13 @@ import {
409
496
  // API 命名空间
410
497
  ApiNamespace,
411
498
 
499
+ // 运行态服务命名空间
500
+ ServicesNamespace,
501
+ FileClient,
502
+ OcrClient,
503
+ OcrType,
504
+ OCR_TYPES,
505
+
412
506
  // 认证管理(高级用法)
413
507
  AuthManager,
414
508
 
@@ -441,6 +535,10 @@ import {
441
535
  type SqlExecuteResult,
442
536
  type Environment,
443
537
  type BaseModelMethods,
538
+ type LovrabetServices,
539
+ type OcrService,
540
+ type OcrRecognizeRequest,
541
+ type OcrRecognizeResponse,
444
542
  } from "@lovrabet/sdk";
445
543
  ```
446
544
 
package/dist/index.d.ts CHANGED
@@ -9,6 +9,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
11
  export { ApiNamespace } from "./src/api/index";
12
+ export { ServicesNamespace, FileClient, OcrClient, OcrType, OCR_TYPES, } from "./src/services/index";
13
+ export type { LovrabetServices, FileQueryUrlRequest, FileService, FileUploadRequest, FileUploadResponse, FileUrlResponse, OcrRecognizeRequest, OcrRecognizeResponse, OcrService, ServiceRequestOptions, } from "./src/services/index";
12
14
  export { AuthManager, } from "./src/auth/index";
13
15
  export { generateOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type TokenResult } from "./src/auth/index";
14
16
  export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, AuthMode, } from "./src/types/index";