@kmlckj/licos-platform-sdk 0.2.0 → 0.3.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 +11 -0
- package/package.json +17 -2
- package/src/browser.d.ts +82 -0
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ await download(uploaded.download_url, '/tmp/report-downloaded.pdf');
|
|
|
20
20
|
- 默认走同源相对地址;也可以显式传 `baseUrl`
|
|
21
21
|
- 上传支持 `File` / `Blob` / `ArrayBuffer` / TypedArray / `{ data, fileName, contentType }`
|
|
22
22
|
- `download(url)` 返回 `Blob`
|
|
23
|
+
- TypeScript 前端可显式导入浏览器入口 `@kmlckj/licos-platform-sdk/browser`,拿到浏览器专用类型
|
|
23
24
|
|
|
24
25
|
```js
|
|
25
26
|
import { uploadUser, download } from '@kmlckj/licos-platform-sdk';
|
|
@@ -30,3 +31,13 @@ const uploaded = await uploadUser(fileInput.files[0], {
|
|
|
30
31
|
|
|
31
32
|
const blob = await download(uploaded.download_url);
|
|
32
33
|
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { uploadUser, download } from '@kmlckj/licos-platform-sdk/browser';
|
|
37
|
+
|
|
38
|
+
const uploaded = await uploadUser(fileInput.files![0], {
|
|
39
|
+
token: userJwt,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const blob = await download(uploaded.download_url);
|
|
43
|
+
```
|
package/package.json
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kmlckj/licos-platform-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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": [
|
package/src/browser.d.ts
ADDED
|
@@ -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>;
|