@lovrabet/sdk 1.4.2 → 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 +99 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/src/client/client.d.ts +5 -0
- package/dist/src/http/http-client.d.ts +1 -0
- package/dist/src/http/index.d.ts +1 -0
- package/dist/src/http/post-form.d.ts +2 -0
- package/dist/src/services/file-client.d.ts +13 -0
- package/dist/src/services/index.d.ts +15 -0
- package/dist/src/services/ocr-client.d.ts +17 -0
- package/dist/src/services/types.d.ts +98 -0
- package/dist/src/types/index.d.ts +2 -0
- package/package.json +12 -2
|
@@ -6,6 +6,7 @@ import { ClientAkSqlClient } from '../api/client-ak-sql-client';
|
|
|
6
6
|
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
|
+
import { ServicesNamespace } from '../services';
|
|
9
10
|
/**
|
|
10
11
|
* Lovrabet SDK 核心客户端类
|
|
11
12
|
*
|
|
@@ -45,6 +46,10 @@ export declare class LovrabetClient implements ILovrabetClient {
|
|
|
45
46
|
* User 客户端 - 用户信息相关 API
|
|
46
47
|
*/
|
|
47
48
|
readonly user: UserClient;
|
|
49
|
+
/**
|
|
50
|
+
* 平台服务命名空间 - OCR 等不绑定数据集或 BFF 的通用运行态能力
|
|
51
|
+
*/
|
|
52
|
+
readonly services: ServicesNamespace;
|
|
48
53
|
/**
|
|
49
54
|
* API 命名空间 - 别名入口(向后兼容)
|
|
50
55
|
*
|
|
@@ -26,6 +26,7 @@ export declare class HttpClient {
|
|
|
26
26
|
private makeRequest;
|
|
27
27
|
get<T = any>(url: string, params?: Record<string, any>, options?: RequestInit, datasetCode?: string): Promise<T>;
|
|
28
28
|
post<T = any>(url: string, data?: any, options?: RequestInit, datasetCode?: string): Promise<T>;
|
|
29
|
+
postForm<T = any>(url: string, data: FormData, options?: RequestInit): Promise<T>;
|
|
29
30
|
put<T = any>(url: string, data?: any, options?: RequestInit, datasetCode?: string): Promise<T>;
|
|
30
31
|
delete<T = any>(url: string, options?: RequestInit, datasetCode?: string): Promise<T>;
|
|
31
32
|
request<T = any>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', url: string, data?: any, options?: RequestInit, datasetCode?: string): Promise<T>;
|
package/dist/src/http/index.d.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
import type { AuthMode } from "../types";
|
|
3
|
+
import type { FileQueryUrlRequest, FileService, FileUploadRequest, FileUploadResponse, FileUrlResponse } from "./types";
|
|
4
|
+
/** Runtime file upload and URL service. */
|
|
5
|
+
export declare class FileClient implements FileService {
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
private readonly appCode;
|
|
8
|
+
private readonly authMode;
|
|
9
|
+
constructor(httpClient: HttpClient, appCode: string, authMode: AuthMode);
|
|
10
|
+
upload(request: FileUploadRequest): Promise<FileUploadResponse>;
|
|
11
|
+
queryUrl(request: FileQueryUrlRequest): Promise<FileUrlResponse>;
|
|
12
|
+
private assertSupportedAuthMode;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
import type { AuthMode } from "../types";
|
|
3
|
+
import { OcrClient } from "./ocr-client";
|
|
4
|
+
import { FileClient } from "./file-client";
|
|
5
|
+
import type { LovrabetServices } from "./types";
|
|
6
|
+
/** Namespace for runtime services. */
|
|
7
|
+
export declare class ServicesNamespace implements LovrabetServices {
|
|
8
|
+
readonly ocr: OcrClient;
|
|
9
|
+
readonly file: FileClient;
|
|
10
|
+
constructor(httpClient: HttpClient, appCode: string, authMode: AuthMode);
|
|
11
|
+
}
|
|
12
|
+
export { OcrClient } from "./ocr-client";
|
|
13
|
+
export { FileClient } from "./file-client";
|
|
14
|
+
export { OCR_TYPES, OcrType } from "./types";
|
|
15
|
+
export type { LovrabetServices, OcrRecognizeRequest, OcrRecognizeResponse, OcrService, FileQueryUrlRequest, FileService, FileUploadRequest, FileUploadResponse, FileUrlResponse, ServiceRequestOptions, } from "./types";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client";
|
|
2
|
+
import type { AuthMode } from "../types";
|
|
3
|
+
import { type OcrRecognizeRequest, type OcrRecognizeResponse, type OcrService } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Runtime OCR service.
|
|
6
|
+
*
|
|
7
|
+
* The public method is stable while the transport follows the configured auth mode:
|
|
8
|
+
* - cookie: GET /api/ocr/recognize-text
|
|
9
|
+
* - client-ak: POST /client/ocr
|
|
10
|
+
*/
|
|
11
|
+
export declare class OcrClient implements OcrService {
|
|
12
|
+
private readonly httpClient;
|
|
13
|
+
private readonly appCode;
|
|
14
|
+
private readonly authMode;
|
|
15
|
+
constructor(httpClient: HttpClient, appCode: string, authMode: AuthMode);
|
|
16
|
+
recognize(request: OcrRecognizeRequest): Promise<OcrRecognizeResponse>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Per-request options supported by runtime service clients. */
|
|
2
|
+
export type ServiceRequestOptions = Omit<RequestInit, "method" | "body">;
|
|
3
|
+
/**
|
|
4
|
+
* OCR recognition types supported by the runtime service.
|
|
5
|
+
*
|
|
6
|
+
* This is a runtime value as well as the source of the `OcrType` type, so
|
|
7
|
+
* JavaScript and TypeScript callers can both avoid handwritten strings.
|
|
8
|
+
*/
|
|
9
|
+
export declare const OcrType: Readonly<{
|
|
10
|
+
readonly General: "General";
|
|
11
|
+
readonly Invoice: "Invoice";
|
|
12
|
+
readonly Advanced: "Advanced";
|
|
13
|
+
readonly AdvancedCoordinate: "AdvancedCoordinate";
|
|
14
|
+
readonly AdvancedGeneral: "AdvancedGeneral";
|
|
15
|
+
readonly IdCard: "IdCard";
|
|
16
|
+
readonly BankCard: "BankCard";
|
|
17
|
+
readonly BusinessLicense: "BusinessLicense";
|
|
18
|
+
readonly DrivingLicense: "DrivingLicense";
|
|
19
|
+
readonly CarNumber: "CarNumber";
|
|
20
|
+
readonly Table: "Table";
|
|
21
|
+
}>;
|
|
22
|
+
export type OcrType = (typeof OcrType)[keyof typeof OcrType];
|
|
23
|
+
/** Read-only OCR type list for selects, discovery, and schema generation. */
|
|
24
|
+
export declare const OCR_TYPES: readonly OcrType[];
|
|
25
|
+
/** Input accepted by the public OCR service. */
|
|
26
|
+
export interface OcrRecognizeRequest {
|
|
27
|
+
/** Publicly accessible image or file URL. */
|
|
28
|
+
url: string;
|
|
29
|
+
/** Runtime OCR recognition type. */
|
|
30
|
+
type: OcrType;
|
|
31
|
+
/** Optional fetch settings. The HTTP method and body are controlled by the SDK. */
|
|
32
|
+
options?: ServiceRequestOptions;
|
|
33
|
+
}
|
|
34
|
+
/** OCR result returned by both the WebAPI and Client API routes. */
|
|
35
|
+
export interface OcrRecognizeResponse {
|
|
36
|
+
requestId?: string;
|
|
37
|
+
type?: OcrType;
|
|
38
|
+
text?: string;
|
|
39
|
+
lines?: string[];
|
|
40
|
+
kvData?: Record<string, string>;
|
|
41
|
+
width?: number;
|
|
42
|
+
height?: number;
|
|
43
|
+
pageNo?: number | null;
|
|
44
|
+
subImageCount?: number | null;
|
|
45
|
+
algoVersion?: string | null;
|
|
46
|
+
kvExcelUrl?: string | null;
|
|
47
|
+
xmlResult?: string | null;
|
|
48
|
+
rawData?: string | null;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
export interface OcrService {
|
|
52
|
+
recognize(request: OcrRecognizeRequest): Promise<OcrRecognizeResponse>;
|
|
53
|
+
}
|
|
54
|
+
/** Input accepted by the runtime file upload service. */
|
|
55
|
+
export interface FileUploadRequest {
|
|
56
|
+
/** Browser File or a standards-compatible Blob. */
|
|
57
|
+
file: Blob;
|
|
58
|
+
/** Optional filename for Blob inputs. File.name is used when available. */
|
|
59
|
+
fileName?: string;
|
|
60
|
+
options?: ServiceRequestOptions;
|
|
61
|
+
}
|
|
62
|
+
export interface FileUploadResponse {
|
|
63
|
+
fileName?: string | null;
|
|
64
|
+
filePath?: string | null;
|
|
65
|
+
fileUrl?: string | null;
|
|
66
|
+
downloadFlag?: boolean;
|
|
67
|
+
fileType?: string | null;
|
|
68
|
+
size?: number | null;
|
|
69
|
+
sourceDir?: string | null;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
export interface FileQueryUrlRequest {
|
|
73
|
+
/** Durable filePath returned by upload. */
|
|
74
|
+
filePath: string;
|
|
75
|
+
/** Request a download URL instead of a preview URL. */
|
|
76
|
+
download?: boolean;
|
|
77
|
+
/** Request a long-term URL for URL-only content embedding. */
|
|
78
|
+
longTerm?: boolean;
|
|
79
|
+
options?: ServiceRequestOptions;
|
|
80
|
+
}
|
|
81
|
+
export interface FileUrlResponse {
|
|
82
|
+
fileName?: string | null;
|
|
83
|
+
filePath?: string | null;
|
|
84
|
+
fileUrl?: string | null;
|
|
85
|
+
downloadFlag?: boolean;
|
|
86
|
+
longTerm?: boolean;
|
|
87
|
+
expiresInDays?: number | null;
|
|
88
|
+
[key: string]: unknown;
|
|
89
|
+
}
|
|
90
|
+
export interface FileService {
|
|
91
|
+
upload(request: FileUploadRequest): Promise<FileUploadResponse>;
|
|
92
|
+
queryUrl(request: FileQueryUrlRequest): Promise<FileUrlResponse>;
|
|
93
|
+
}
|
|
94
|
+
/** Runtime services exposed under `client.services`. */
|
|
95
|
+
export interface LovrabetServices {
|
|
96
|
+
readonly ocr: OcrService;
|
|
97
|
+
readonly file: FileService;
|
|
98
|
+
}
|
|
@@ -830,6 +830,8 @@ export interface AuthManager {
|
|
|
830
830
|
* ```
|
|
831
831
|
*/
|
|
832
832
|
export interface LovrabetClient {
|
|
833
|
+
/** 运行态通用服务,如文件与 OCR。 */
|
|
834
|
+
readonly services: import("../services/types").LovrabetServices;
|
|
833
835
|
/**
|
|
834
836
|
* 模型访问接口 - 纯粹的语法糖,支持 client.models.ModelName 访问
|
|
835
837
|
* @description 内部调用 client.getModel() 方法,提供更简洁的访问方式
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovrabet/sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3-beta.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -29,6 +29,13 @@
|
|
|
29
29
|
"test:cookie:quick": "bun run scripts/test-cookie-quick.ts",
|
|
30
30
|
"test:cookie:full": "bun run scripts/test-cookie-full.ts",
|
|
31
31
|
"types": "npx tsc --emitDeclarationOnly --declaration --outDir dist index.ts",
|
|
32
|
+
"test:unit": "vitest run test/unit",
|
|
33
|
+
"test:integration": "vitest run test/integration",
|
|
34
|
+
"test:e2e": "RUN_E2E_TESTS=true vitest run test/e2e",
|
|
35
|
+
"typecheck": "tsc --noEmit --skipLibCheck index.ts src/**/*.ts",
|
|
36
|
+
"typecheck:e2e": "tsc -p tsconfig.e2e.json",
|
|
37
|
+
"lint": "eslint . --ext .ts",
|
|
38
|
+
"ci": "npm run lint && npm run typecheck && npm run typecheck:e2e && npm run test:unit && npm run test:integration && npm run test:coverage && npm run build:dev",
|
|
32
39
|
"beta-release": "bun run build && sh scripts/update-beta-version.sh && git push && git push origin --tag && bun publish --tag beta",
|
|
33
40
|
"release": "bun run build && sh scripts/update-latest-version.sh && git push && git push origin --tag && bun publish"
|
|
34
41
|
},
|
|
@@ -41,10 +48,13 @@
|
|
|
41
48
|
"@vitest/ui": "^2.1.8",
|
|
42
49
|
"c8": "^10.1.2",
|
|
43
50
|
"chokidar-cli": "^3.0.0",
|
|
51
|
+
"eslint": "^9.0.0",
|
|
52
|
+
"@eslint/js": "^9.0.0",
|
|
53
|
+
"typescript-eslint": "^8.0.0",
|
|
44
54
|
"javascript-obfuscator": "^4.1.1",
|
|
45
55
|
"vitest": "^2.1.8"
|
|
46
56
|
},
|
|
47
57
|
"peerDependencies": {
|
|
48
58
|
"typescript": "^5"
|
|
49
59
|
}
|
|
50
|
-
}
|
|
60
|
+
}
|