@kmlckj/licos-platform-sdk 0.2.0 → 0.4.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.
package/README.md CHANGED
@@ -5,6 +5,8 @@ LICOS 平台对象存储 SDK,兼容前端和后端调用。
5
5
  ## 后端模式
6
6
 
7
7
  - `baseUrl` / `token` / `userId` / `projectId` 不传时,会回退读取 `LICOS_*` 环境变量
8
+ - 后端默认读取 `LICOS_ORCHESTRATOR_API_BASE_URL`
9
+ - 这些存储接口实际挂在调度器 `/api/v1/storage/*` 和 `/api/v1/public/storage/*`
8
10
  - `uploadUser` / `uploadProject` 支持直接传本地文件路径
9
11
  - `download(url, outputPath)` 会把文件写到本地路径
10
12
 
@@ -20,6 +22,7 @@ await download(uploaded.download_url, '/tmp/report-downloaded.pdf');
20
22
  - 默认走同源相对地址;也可以显式传 `baseUrl`
21
23
  - 上传支持 `File` / `Blob` / `ArrayBuffer` / TypedArray / `{ data, fileName, contentType }`
22
24
  - `download(url)` 返回 `Blob`
25
+ - TypeScript 前端可显式导入浏览器入口 `@kmlckj/licos-platform-sdk/browser`,拿到浏览器专用类型
23
26
 
24
27
  ```js
25
28
  import { uploadUser, download } from '@kmlckj/licos-platform-sdk';
@@ -30,3 +33,13 @@ const uploaded = await uploadUser(fileInput.files[0], {
30
33
 
31
34
  const blob = await download(uploaded.download_url);
32
35
  ```
36
+
37
+ ```ts
38
+ import { uploadUser, download } from '@kmlckj/licos-platform-sdk/browser';
39
+
40
+ const uploaded = await uploadUser(fileInput.files![0], {
41
+ token: userJwt,
42
+ });
43
+
44
+ const blob = await download(uploaded.download_url);
45
+ ```
package/package.json CHANGED
@@ -1,18 +1,33 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "LICOS platform SDK for storage upload, download, and preview in browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",
7
7
  "main": "./src/index.js",
8
8
  "browser": "./src/browser.js",
9
9
  "types": "./src/index.d.ts",
10
+ "typesVersions": {
11
+ "*": {
12
+ "browser": [
13
+ "src/browser.d.ts"
14
+ ]
15
+ }
16
+ },
10
17
  "exports": {
11
18
  ".": {
19
+ "browser": {
20
+ "types": "./src/browser.d.ts",
21
+ "default": "./src/browser.js"
22
+ },
12
23
  "types": "./src/index.d.ts",
13
- "browser": "./src/browser.js",
14
24
  "import": "./src/index.js",
15
25
  "default": "./src/index.js"
26
+ },
27
+ "./browser": {
28
+ "types": "./src/browser.d.ts",
29
+ "import": "./src/browser.js",
30
+ "default": "./src/browser.js"
16
31
  }
17
32
  },
18
33
  "files": [
@@ -0,0 +1,82 @@
1
+ export interface UploadResult {
2
+ bucket: string;
3
+ object_key: string;
4
+ file_name: string;
5
+ content_type: string;
6
+ size_bytes: number;
7
+ preview_url: string;
8
+ download_url: string;
9
+ }
10
+
11
+ export interface BlobLike {
12
+ arrayBuffer(): Promise<ArrayBuffer>;
13
+ readonly size?: number;
14
+ readonly type?: string;
15
+ readonly name?: string;
16
+ }
17
+
18
+ export interface UploadBinaryDescriptor {
19
+ data?: ArrayBuffer | ArrayBufferView | BlobLike;
20
+ file?: ArrayBuffer | ArrayBufferView | BlobLike;
21
+ fileName?: string;
22
+ contentType?: string;
23
+ }
24
+
25
+ export type UploadSource =
26
+ | ArrayBuffer
27
+ | ArrayBufferView
28
+ | BlobLike
29
+ | UploadBinaryDescriptor;
30
+
31
+ export interface StorageClientOptions {
32
+ baseUrl?: string;
33
+ token?: string;
34
+ userId?: string;
35
+ projectId?: string;
36
+ fetch?: typeof fetch;
37
+ headers?: HeadersInit;
38
+ credentials?: RequestCredentials;
39
+ }
40
+
41
+ export interface UploadProjectOptions extends StorageClientOptions {
42
+ userId?: string;
43
+ projectId?: string;
44
+ }
45
+
46
+ export class PlatformSdkError extends Error {
47
+ status?: number;
48
+ code?: number;
49
+ details?: unknown;
50
+ }
51
+
52
+ export class ConfigurationError extends PlatformSdkError {}
53
+ export class ApiError extends PlatformSdkError {}
54
+
55
+ export class StorageClient {
56
+ constructor(options?: StorageClientOptions);
57
+ previewUrl(bucket: string, objectKey: string): string;
58
+ downloadUrl(bucket: string, objectKey: string): string;
59
+ uploadUser(file: UploadSource): Promise<UploadResult>;
60
+ uploadProject(file: UploadSource, options?: UploadProjectOptions): Promise<UploadResult>;
61
+ download(url: string): Promise<Blob>;
62
+ }
63
+
64
+ export function previewUrl(
65
+ bucket: string,
66
+ objectKey: string,
67
+ options?: StorageClientOptions,
68
+ ): string;
69
+ export function downloadUrl(
70
+ bucket: string,
71
+ objectKey: string,
72
+ options?: StorageClientOptions,
73
+ ): string;
74
+ export function uploadUser(
75
+ file: UploadSource,
76
+ options?: StorageClientOptions,
77
+ ): Promise<UploadResult>;
78
+ export function uploadProject(
79
+ file: UploadSource,
80
+ options?: UploadProjectOptions,
81
+ ): Promise<UploadResult>;
82
+ export function download(url: string, options?: StorageClientOptions): Promise<Blob>;
package/src/shared.js CHANGED
@@ -36,7 +36,7 @@ export function normalizeBaseUrl(baseUrl) {
36
36
  return baseUrl.replace(/\/+$/, '');
37
37
  }
38
38
 
39
- const envBaseUrl = readEnv('LICOS_API_BASE_URL');
39
+ const envBaseUrl = readEnv('LICOS_ORCHESTRATOR_API_BASE_URL');
40
40
  if (envBaseUrl) {
41
41
  return envBaseUrl.replace(/\/+$/, '');
42
42
  }
@@ -45,7 +45,9 @@ export function normalizeBaseUrl(baseUrl) {
45
45
  return '';
46
46
  }
47
47
 
48
- throw new ConfigurationError('Missing required environment variable: LICOS_API_BASE_URL');
48
+ throw new ConfigurationError(
49
+ 'Missing required environment variable: LICOS_ORCHESTRATOR_API_BASE_URL',
50
+ );
49
51
  }
50
52
 
51
53
  export function resolveUserId(userId) {