@seaverse/utils-sdk 0.1.0 → 0.1.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 +170 -160
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -8
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +45 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +45 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
1
|
# @seaverse/utils-sdk
|
|
2
2
|
|
|
3
|
-
SeaVerse Utils SDK -
|
|
3
|
+
SeaVerse Utils SDK - A utility toolkit including file upload, image compression, and more.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@seaverse/utils-sdk)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Features
|
|
9
9
|
|
|
10
|
-
- 📤
|
|
11
|
-
- 🖼️
|
|
12
|
-
- 📊
|
|
13
|
-
- ✅
|
|
14
|
-
- ⚡ **TypeScript** -
|
|
15
|
-
- 🌍
|
|
10
|
+
- 📤 **File Upload** - Two-step upload with presigned URLs, secure and efficient
|
|
11
|
+
- 🖼️ **Image Compression** - Auto compress to 1080p, configurable quality and dimensions
|
|
12
|
+
- 📊 **Upload Progress** - Real-time progress callback with speed and remaining time
|
|
13
|
+
- ✅ **File Validation** - Size and type validation
|
|
14
|
+
- ⚡ **TypeScript** - Complete type definitions
|
|
15
|
+
- 🌍 **Environment Config** - Support for multiple environment switching
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Installation
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
npm install @seaverse/utils-sdk
|
|
21
|
-
#
|
|
21
|
+
# or
|
|
22
22
|
pnpm add @seaverse/utils-sdk
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Quick Start
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### Basic Usage
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
30
|
import { UtilsClient } from '@seaverse/utils-sdk';
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// Initialize client
|
|
33
33
|
const client = new UtilsClient({
|
|
34
34
|
token: 'your-bearer-token',
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// Upload file
|
|
38
38
|
const file = document.querySelector('input[type="file"]').files[0];
|
|
39
39
|
const result = await client.uploadFile(file);
|
|
40
40
|
|
|
41
41
|
console.log('CDN URL:', result.cdnUrl);
|
|
42
|
-
console.log('
|
|
43
|
-
console.log('
|
|
42
|
+
console.log('File size:', result.fileSize);
|
|
43
|
+
console.log('Compressed:', result.compressed);
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
###
|
|
46
|
+
### With Progress Callback
|
|
47
47
|
|
|
48
48
|
```typescript
|
|
49
49
|
const result = await client.uploadFile(file, {
|
|
50
50
|
onProgress: (progress) => {
|
|
51
|
-
console.log(
|
|
52
|
-
console.log(
|
|
53
|
-
console.log(
|
|
54
|
-
console.log(
|
|
51
|
+
console.log(`Progress: ${progress.percent}%`);
|
|
52
|
+
console.log(`Stage: ${progress.stage}`);
|
|
53
|
+
console.log(`Speed: ${progress.speed} bytes/sec`);
|
|
54
|
+
console.log(`Remaining time: ${progress.remainingTime} sec`);
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### Disable Image Compression
|
|
60
60
|
|
|
61
61
|
```typescript
|
|
62
62
|
const result = await client.uploadFile(file, {
|
|
63
|
-
compress: false, //
|
|
63
|
+
compress: false, // Disable compression
|
|
64
64
|
});
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
###
|
|
67
|
+
### Custom Compression Config
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
70
|
const client = new UtilsClient({
|
|
71
71
|
token: 'your-bearer-token',
|
|
72
72
|
compress: {
|
|
73
73
|
enabled: true,
|
|
74
|
-
maxWidth: 1920, //
|
|
75
|
-
maxHeight: 1080, //
|
|
76
|
-
quality: 0.9, //
|
|
74
|
+
maxWidth: 1920, // Custom max width
|
|
75
|
+
maxHeight: 1080, // Custom max height
|
|
76
|
+
quality: 0.9, // Custom compression quality
|
|
77
77
|
},
|
|
78
78
|
});
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
## API
|
|
81
|
+
## API Reference
|
|
82
82
|
|
|
83
83
|
### UtilsClient
|
|
84
84
|
|
|
85
|
-
####
|
|
85
|
+
#### Constructor
|
|
86
86
|
|
|
87
87
|
```typescript
|
|
88
88
|
new UtilsClient(options: UtilsClientOptions)
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
**Parameters:**
|
|
92
92
|
|
|
93
|
-
- `token` (string,
|
|
94
|
-
- `baseURL` (string,
|
|
95
|
-
- `timeout` (number,
|
|
96
|
-
- `compress` (CompressionConfig,
|
|
93
|
+
- `token` (string, required): Bearer Token
|
|
94
|
+
- `baseURL` (string, optional): API base URL, default `https://resource.seaverse.ai`
|
|
95
|
+
- `timeout` (number, optional): Request timeout (ms), default 60000
|
|
96
|
+
- `compress` (CompressionConfig, optional): Image compression config
|
|
97
97
|
|
|
98
98
|
**CompressionConfig:**
|
|
99
99
|
|
|
100
|
-
- `enabled` (boolean):
|
|
101
|
-
- `maxWidth` (number):
|
|
102
|
-
- `maxHeight` (number):
|
|
103
|
-
- `quality` (number):
|
|
100
|
+
- `enabled` (boolean): Enable compression, default `true`
|
|
101
|
+
- `maxWidth` (number): Max width, default `1080`
|
|
102
|
+
- `maxHeight` (number): Max height, default `1080`
|
|
103
|
+
- `quality` (number): Compression quality (0-1), default `0.8`
|
|
104
104
|
|
|
105
105
|
#### uploadFile()
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
Upload file with automatic compression, validation, and upload flow.
|
|
108
108
|
|
|
109
109
|
```typescript
|
|
110
110
|
async uploadFile(file: File, options?: UploadOptions): Promise<UploadResult>
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
**Parameters:**
|
|
114
114
|
|
|
115
|
-
- `file`:
|
|
116
|
-
- `options` (
|
|
117
|
-
- `onProgress`:
|
|
118
|
-
- `compress`:
|
|
119
|
-
- `metadata`:
|
|
115
|
+
- `file`: File object to upload
|
|
116
|
+
- `options` (optional):
|
|
117
|
+
- `onProgress`: Progress callback function
|
|
118
|
+
- `compress`: Whether to compress (overrides global config)
|
|
119
|
+
- `metadata`: Custom metadata
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
**Returns:**
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
124
|
{
|
|
125
|
-
fileName: string //
|
|
126
|
-
originalFileName: string //
|
|
127
|
-
cdnUrl: string // CDN
|
|
128
|
-
objectPath: string //
|
|
129
|
-
fileSize: number //
|
|
130
|
-
originalSize: number //
|
|
131
|
-
compressed: boolean //
|
|
132
|
-
contentType: string // MIME
|
|
133
|
-
duration: number //
|
|
134
|
-
expiresAt: string //
|
|
125
|
+
fileName: string // File name
|
|
126
|
+
originalFileName: string // Original file name
|
|
127
|
+
cdnUrl: string // CDN access URL
|
|
128
|
+
objectPath: string // Storage path
|
|
129
|
+
fileSize: number // File size (bytes)
|
|
130
|
+
originalSize: number // Original size (bytes)
|
|
131
|
+
compressed: boolean // Whether compressed
|
|
132
|
+
contentType: string // MIME type
|
|
133
|
+
duration: number // Upload duration (ms)
|
|
134
|
+
expiresAt: string // Expiration time
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
**Errors:**
|
|
139
139
|
|
|
140
|
-
-
|
|
140
|
+
- Throws `UtilsAPIError` on failure
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
**Example:**
|
|
143
143
|
|
|
144
144
|
```typescript
|
|
145
145
|
try {
|
|
@@ -148,17 +148,17 @@ try {
|
|
|
148
148
|
updateProgressBar(progress.percent);
|
|
149
149
|
},
|
|
150
150
|
});
|
|
151
|
-
console.log('
|
|
151
|
+
console.log('Upload successful:', result.cdnUrl);
|
|
152
152
|
} catch (error) {
|
|
153
153
|
if (error instanceof UtilsAPIError) {
|
|
154
|
-
console.error(
|
|
154
|
+
console.error(`Upload failed [${error.code}]: ${error.message}`);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
#### setToken()
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
Update Bearer Token.
|
|
162
162
|
|
|
163
163
|
```typescript
|
|
164
164
|
setToken(token: string): void
|
|
@@ -166,7 +166,7 @@ setToken(token: string): void
|
|
|
166
166
|
|
|
167
167
|
#### setBaseURL()
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
Update base URL.
|
|
170
170
|
|
|
171
171
|
```typescript
|
|
172
172
|
setBaseURL(baseURL: string): void
|
|
@@ -174,17 +174,17 @@ setBaseURL(baseURL: string): void
|
|
|
174
174
|
|
|
175
175
|
#### updateCompressionConfig()
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
Update compression config.
|
|
178
178
|
|
|
179
179
|
```typescript
|
|
180
180
|
updateCompressionConfig(config: Partial<CompressionConfig>): void
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
-
##
|
|
183
|
+
## Utility Functions
|
|
184
184
|
|
|
185
185
|
### validateFile()
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
Validate file size and type.
|
|
188
188
|
|
|
189
189
|
```typescript
|
|
190
190
|
import { validateFile } from '@seaverse/utils-sdk';
|
|
@@ -195,13 +195,13 @@ const result = validateFile(file, {
|
|
|
195
195
|
});
|
|
196
196
|
|
|
197
197
|
if (!result.valid) {
|
|
198
|
-
console.error('
|
|
198
|
+
console.error('Validation failed:', result.errors);
|
|
199
199
|
}
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
### compressImage()
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
Manually compress image.
|
|
205
205
|
|
|
206
206
|
```typescript
|
|
207
207
|
import { compressImage } from '@seaverse/utils-sdk';
|
|
@@ -212,13 +212,13 @@ const result = await compressImage(file, {
|
|
|
212
212
|
quality: 0.8,
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
-
console.log('
|
|
216
|
-
console.log('
|
|
215
|
+
console.log('Compression ratio:', result.compressionRatio);
|
|
216
|
+
console.log('Compressed size:', result.compressedSize);
|
|
217
217
|
```
|
|
218
218
|
|
|
219
219
|
### formatBytes()
|
|
220
220
|
|
|
221
|
-
|
|
221
|
+
Format bytes to human-readable string.
|
|
222
222
|
|
|
223
223
|
```typescript
|
|
224
224
|
import { formatBytes } from '@seaverse/utils-sdk';
|
|
@@ -228,7 +228,7 @@ console.log(formatBytes(1048576)); // "1 MB"
|
|
|
228
228
|
console.log(formatBytes(1073741824)); // "1 GB"
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
##
|
|
231
|
+
## Error Handling
|
|
232
232
|
|
|
233
233
|
```typescript
|
|
234
234
|
import { UtilsAPIError, ErrorCode } from '@seaverse/utils-sdk';
|
|
@@ -239,65 +239,75 @@ try {
|
|
|
239
239
|
if (error instanceof UtilsAPIError) {
|
|
240
240
|
switch (error.code) {
|
|
241
241
|
case ErrorCode.FILE_TOO_LARGE:
|
|
242
|
-
alert('
|
|
242
|
+
alert('File too large, please select a file smaller than 100MB');
|
|
243
243
|
break;
|
|
244
244
|
case ErrorCode.INVALID_FILE_TYPE:
|
|
245
|
-
alert('
|
|
245
|
+
alert('Unsupported file type');
|
|
246
246
|
break;
|
|
247
247
|
case ErrorCode.NETWORK_ERROR:
|
|
248
|
-
alert('
|
|
248
|
+
alert('Network error, please check your connection');
|
|
249
249
|
break;
|
|
250
250
|
default:
|
|
251
|
-
alert(
|
|
251
|
+
alert(`Upload failed: ${error.message}`);
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
##
|
|
257
|
+
## Error Codes
|
|
258
258
|
|
|
259
|
-
|
|
|
260
|
-
|
|
261
|
-
| `FILE_TOO_LARGE` |
|
|
262
|
-
| `INVALID_FILE_TYPE` |
|
|
263
|
-
| `PRESIGNED_URL_FAILED` |
|
|
264
|
-
| `UPLOAD_FAILED` |
|
|
265
|
-
| `COMPRESSION_FAILED` |
|
|
266
|
-
| `NETWORK_ERROR` |
|
|
267
|
-
| `TIMEOUT` |
|
|
268
|
-
| `VALIDATION_FAILED` |
|
|
259
|
+
| Error Code | Description |
|
|
260
|
+
|------------|-------------|
|
|
261
|
+
| `FILE_TOO_LARGE` | File size exceeds limit |
|
|
262
|
+
| `INVALID_FILE_TYPE` | Unsupported file type |
|
|
263
|
+
| `PRESIGNED_URL_FAILED` | Failed to get presigned URL |
|
|
264
|
+
| `UPLOAD_FAILED` | Upload failed |
|
|
265
|
+
| `COMPRESSION_FAILED` | Image compression failed |
|
|
266
|
+
| `NETWORK_ERROR` | Network error |
|
|
267
|
+
| `TIMEOUT` | Request timeout |
|
|
268
|
+
| `VALIDATION_FAILED` | File validation failed |
|
|
269
269
|
|
|
270
|
-
##
|
|
270
|
+
## Environment Configuration
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
The SDK provides predefined environment URLs:
|
|
273
273
|
|
|
274
274
|
```typescript
|
|
275
|
-
|
|
276
|
-
const client = new UtilsClient({
|
|
277
|
-
token: devToken,
|
|
278
|
-
// baseURL 默认为 'https://resource.seaverse.ai'
|
|
279
|
-
});
|
|
275
|
+
import { UtilsClient, ENVIRONMENT_URLS } from '@seaverse/utils-sdk';
|
|
280
276
|
|
|
281
|
-
//
|
|
277
|
+
// Production environment (default)
|
|
282
278
|
const client = new UtilsClient({
|
|
283
|
-
baseURL: 'https://resource.sg.seaverse.dev',
|
|
284
279
|
token: prodToken,
|
|
280
|
+
// baseURL defaults to 'https://resource.seaverse.ai'
|
|
285
281
|
});
|
|
286
282
|
|
|
287
|
-
//
|
|
288
|
-
const
|
|
289
|
-
baseURL: '
|
|
283
|
+
// Staging/Test environment
|
|
284
|
+
const stagingClient = new UtilsClient({
|
|
285
|
+
baseURL: ENVIRONMENT_URLS.STAGING, // 'https://resource.sg.seaverse.dev'
|
|
286
|
+
token: stagingToken,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Local development
|
|
290
|
+
const localClient = new UtilsClient({
|
|
291
|
+
baseURL: ENVIRONMENT_URLS.LOCAL, // 'http://localhost:8003'
|
|
290
292
|
token: localToken,
|
|
291
293
|
});
|
|
292
294
|
```
|
|
293
295
|
|
|
294
|
-
|
|
296
|
+
### Available Environment URLs
|
|
297
|
+
|
|
298
|
+
| Environment | URL | Constant |
|
|
299
|
+
|-------------|-----|----------|
|
|
300
|
+
| Production | `https://resource.seaverse.ai` | `ENVIRONMENT_URLS.PRODUCTION` |
|
|
301
|
+
| Staging | `https://resource.sg.seaverse.dev` | `ENVIRONMENT_URLS.STAGING` |
|
|
302
|
+
| Local | `http://localhost:8003` | `ENVIRONMENT_URLS.LOCAL` |
|
|
303
|
+
|
|
304
|
+
## Integration with Auth SDK
|
|
295
305
|
|
|
296
306
|
```typescript
|
|
297
307
|
import { SeaVerseBackendAPIClient } from '@seaverse/auth-sdk';
|
|
298
308
|
import { UtilsClient } from '@seaverse/utils-sdk';
|
|
299
309
|
|
|
300
|
-
// 1.
|
|
310
|
+
// 1. Login with Auth SDK
|
|
301
311
|
const authClient = new SeaVerseBackendAPIClient({
|
|
302
312
|
appId: 'your-app-id',
|
|
303
313
|
});
|
|
@@ -307,91 +317,91 @@ const loginResult = await authClient.login({
|
|
|
307
317
|
password: 'password',
|
|
308
318
|
});
|
|
309
319
|
|
|
310
|
-
// 2.
|
|
320
|
+
// 2. Initialize Utils SDK with the same token
|
|
311
321
|
const utilsClient = new UtilsClient({
|
|
312
322
|
token: loginResult.token,
|
|
313
323
|
});
|
|
314
324
|
|
|
315
|
-
// 3.
|
|
325
|
+
// 3. Upload file
|
|
316
326
|
const result = await utilsClient.uploadFile(file);
|
|
317
327
|
```
|
|
318
328
|
|
|
319
|
-
##
|
|
329
|
+
## Upload Flow
|
|
320
330
|
|
|
321
|
-
SDK
|
|
331
|
+
The SDK uses presigned URL two-step upload mode:
|
|
322
332
|
|
|
323
333
|
```
|
|
324
|
-
1.
|
|
334
|
+
1. Get presigned URL
|
|
325
335
|
POST /api/v1/resources/presign-upload
|
|
326
|
-
→
|
|
336
|
+
→ Returns upload_url and cdn_url
|
|
327
337
|
|
|
328
|
-
2.
|
|
338
|
+
2. Upload to GCS
|
|
329
339
|
PUT {upload_url}
|
|
330
|
-
→
|
|
340
|
+
→ Direct upload to Google Cloud Storage
|
|
331
341
|
|
|
332
|
-
3.
|
|
333
|
-
|
|
342
|
+
3. Return CDN URL
|
|
343
|
+
Use cdn_url to access the file
|
|
334
344
|
```
|
|
335
345
|
|
|
336
|
-
|
|
346
|
+
**Advantages:**
|
|
337
347
|
|
|
338
|
-
- ✅
|
|
339
|
-
- ✅
|
|
340
|
-
- ✅
|
|
348
|
+
- ✅ Secure: Token not exposed to third-party storage
|
|
349
|
+
- ✅ Efficient: Direct upload to GCS, no backend proxy
|
|
350
|
+
- ✅ Reliable: GCS provides high availability guarantee
|
|
341
351
|
|
|
342
|
-
##
|
|
352
|
+
## Image Compression
|
|
343
353
|
|
|
344
|
-
###
|
|
354
|
+
### Compression Strategy
|
|
345
355
|
|
|
346
|
-
-
|
|
347
|
-
-
|
|
348
|
-
-
|
|
349
|
-
-
|
|
356
|
+
- Max size: 1080×1080 pixels (default config)
|
|
357
|
+
- Maintains aspect ratio with auto scaling
|
|
358
|
+
- Configurable compression quality (0-1)
|
|
359
|
+
- Supports custom max width/height (maxWidth, maxHeight)
|
|
350
360
|
|
|
351
|
-
###
|
|
361
|
+
### Compression Trigger Conditions
|
|
352
362
|
|
|
353
|
-
|
|
363
|
+
Compression only occurs when all conditions are met:
|
|
354
364
|
|
|
355
|
-
1.
|
|
356
|
-
2.
|
|
357
|
-
3.
|
|
365
|
+
1. File is an image type (MIME type starts with `image/`)
|
|
366
|
+
2. Compression is enabled (`compress.enabled === true`)
|
|
367
|
+
3. Not explicitly disabled in upload options (`options.compress !== false`)
|
|
358
368
|
|
|
359
|
-
###
|
|
369
|
+
### Skip Compression
|
|
360
370
|
|
|
361
371
|
```typescript
|
|
362
|
-
//
|
|
372
|
+
// Method 1: Disable globally
|
|
363
373
|
const client = new UtilsClient({
|
|
364
374
|
token: 'xxx',
|
|
365
375
|
compress: { enabled: false },
|
|
366
376
|
});
|
|
367
377
|
|
|
368
|
-
//
|
|
378
|
+
// Method 2: Disable for single upload
|
|
369
379
|
const result = await client.uploadFile(file, {
|
|
370
380
|
compress: false,
|
|
371
381
|
});
|
|
372
382
|
```
|
|
373
383
|
|
|
374
|
-
##
|
|
384
|
+
## FAQ
|
|
375
385
|
|
|
376
|
-
### Q1:
|
|
386
|
+
### Q1: How to get token?
|
|
377
387
|
|
|
378
|
-
**A**:
|
|
388
|
+
**A**: Get Bearer Token by logging in with `@seaverse/auth-sdk`
|
|
379
389
|
|
|
380
|
-
### Q2:
|
|
390
|
+
### Q2: What file types are supported?
|
|
381
391
|
|
|
382
392
|
**A**:
|
|
383
|
-
-
|
|
384
|
-
-
|
|
385
|
-
-
|
|
393
|
+
- **Images**: JPEG, PNG, GIF, WebP
|
|
394
|
+
- **Documents**: PDF, TXT, MD
|
|
395
|
+
- **Others**: Depends on backend configuration
|
|
386
396
|
|
|
387
|
-
### Q3:
|
|
397
|
+
### Q3: What's the file size limit?
|
|
388
398
|
|
|
389
399
|
**A**:
|
|
390
|
-
-
|
|
391
|
-
-
|
|
392
|
-
-
|
|
400
|
+
- Default limit: 100MB
|
|
401
|
+
- Can be customized via validation rules
|
|
402
|
+
- Images are auto-compressed to reduce transfer size
|
|
393
403
|
|
|
394
|
-
### Q4:
|
|
404
|
+
### Q4: How to handle upload failures?
|
|
395
405
|
|
|
396
406
|
**A**:
|
|
397
407
|
```typescript
|
|
@@ -399,48 +409,48 @@ try {
|
|
|
399
409
|
await client.uploadFile(file);
|
|
400
410
|
} catch (error) {
|
|
401
411
|
if (error instanceof UtilsAPIError) {
|
|
402
|
-
//
|
|
412
|
+
// Handle based on error code
|
|
403
413
|
if (error.code === ErrorCode.NETWORK_ERROR) {
|
|
404
|
-
//
|
|
414
|
+
// Retry logic
|
|
405
415
|
}
|
|
406
416
|
}
|
|
407
417
|
}
|
|
408
418
|
```
|
|
409
419
|
|
|
410
|
-
### Q5:
|
|
420
|
+
### Q5: Does compression affect image quality?
|
|
411
421
|
|
|
412
422
|
**A**:
|
|
413
|
-
-
|
|
414
|
-
-
|
|
415
|
-
-
|
|
423
|
+
- Default quality is 0.8, balancing file size and image quality
|
|
424
|
+
- Adjustable via `quality` parameter (0-1)
|
|
425
|
+
- Recommended range: 0.7-0.9
|
|
416
426
|
|
|
417
|
-
##
|
|
427
|
+
## Development
|
|
418
428
|
|
|
419
429
|
```bash
|
|
420
|
-
#
|
|
430
|
+
# Install dependencies
|
|
421
431
|
pnpm install
|
|
422
432
|
|
|
423
|
-
#
|
|
433
|
+
# Build
|
|
424
434
|
pnpm build
|
|
425
435
|
|
|
426
|
-
#
|
|
436
|
+
# Development mode
|
|
427
437
|
pnpm dev
|
|
428
438
|
|
|
429
|
-
#
|
|
439
|
+
# Type check
|
|
430
440
|
pnpm typecheck
|
|
431
441
|
```
|
|
432
442
|
|
|
433
|
-
##
|
|
443
|
+
## License
|
|
434
444
|
|
|
435
445
|
MIT © [SeaVerse Team](mailto:support@seaverse.com)
|
|
436
446
|
|
|
437
|
-
##
|
|
447
|
+
## Changelog
|
|
438
448
|
|
|
439
449
|
### v0.1.0 (2026-01-07)
|
|
440
450
|
|
|
441
|
-
- 🎉
|
|
442
|
-
- ✨
|
|
443
|
-
- ✨
|
|
444
|
-
- ✨
|
|
445
|
-
- ✨
|
|
446
|
-
- ✨
|
|
451
|
+
- 🎉 Initial release
|
|
452
|
+
- ✨ Support file upload (presigned URL mode)
|
|
453
|
+
- ✨ Support auto image compression (1080p)
|
|
454
|
+
- ✨ Support upload progress callback
|
|
455
|
+
- ✨ Support file validation
|
|
456
|
+
- ✨ Complete TypeScript type definitions
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,cAAc,EAEd,qBAAqB,EACrB,iBAAiB,EAGlB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,cAAc,EAEd,qBAAqB,EACrB,iBAAiB,EAGlB,MAAM,aAAa,CAAC;AAerB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,iBAAiB,CAA8B;gBAE3C,OAAO,EAAE,kBAAkB;IA4BvC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IA8F5E;;;;;;OAMG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAgC1E;;;;;;;;;OASG;IACG,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,IAAI,EACV,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,GAC9C,OAAO,CAAC,IAAI,CAAC;IAgEhB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIjC;;;;OAIG;IACH,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI;CAMlE"}
|
package/dist/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import axios from 'axios';
|
|
|
5
5
|
import { UtilsAPIError, ErrorCode, } from './models.js';
|
|
6
6
|
import { compressImage, shouldCompress } from './compress.js';
|
|
7
7
|
import { validateFile, isImageFile, handleAxiosError, createUploadError, ProgressTracker, } from './utils.js';
|
|
8
|
+
import { DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_COMPRESSION_CONFIG, } from './config.js';
|
|
8
9
|
/**
|
|
9
10
|
* SeaVerse Utils API Client
|
|
10
11
|
*
|
|
@@ -31,21 +32,21 @@ import { validateFile, isImageFile, handleAxiosError, createUploadError, Progres
|
|
|
31
32
|
*/
|
|
32
33
|
export class UtilsClient {
|
|
33
34
|
constructor(options) {
|
|
34
|
-
//
|
|
35
|
+
// Initialize axios instance
|
|
35
36
|
this.axios = axios.create({
|
|
36
|
-
baseURL: options.baseURL ||
|
|
37
|
-
timeout: options.timeout ||
|
|
37
|
+
baseURL: options.baseURL || DEFAULT_BASE_URL,
|
|
38
|
+
timeout: options.timeout || DEFAULT_TIMEOUT,
|
|
38
39
|
headers: {
|
|
39
40
|
'Content-Type': 'application/json',
|
|
40
41
|
Authorization: `Bearer ${options.token}`,
|
|
41
42
|
},
|
|
42
43
|
});
|
|
43
|
-
//
|
|
44
|
+
// Initialize compression config
|
|
44
45
|
this.compressionConfig = {
|
|
45
|
-
enabled: options.compress?.enabled ??
|
|
46
|
-
maxWidth: options.compress?.maxWidth ??
|
|
47
|
-
maxHeight: options.compress?.maxHeight ??
|
|
48
|
-
quality: options.compress?.quality ??
|
|
46
|
+
enabled: options.compress?.enabled ?? DEFAULT_COMPRESSION_CONFIG.enabled,
|
|
47
|
+
maxWidth: options.compress?.maxWidth ?? DEFAULT_COMPRESSION_CONFIG.maxWidth,
|
|
48
|
+
maxHeight: options.compress?.maxHeight ?? DEFAULT_COMPRESSION_CONFIG.maxHeight,
|
|
49
|
+
quality: options.compress?.quality ?? DEFAULT_COMPRESSION_CONFIG.quality,
|
|
49
50
|
};
|
|
50
51
|
// 响应拦截器:统一错误处理
|
|
51
52
|
this.axios.interceptors.response.use((response) => response, (error) => {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAQL,aAAa,EACb,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,EAQL,aAAa,EACb,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,WAAW;IAItB,YAAY,OAA2B;QACrC,4BAA4B;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC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,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAC;IAC1E,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,OAAe;QACxB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,uBAAuB,CAAC,MAAkC;QACxD,IAAI,CAAC,iBAAiB,GAAG;YACvB,GAAG,IAAI,CAAC,iBAAiB;YACzB,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;CACF"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SeaVerse Utils SDK Configuration
|
|
3
|
+
*
|
|
4
|
+
* Environment-specific URLs and default configurations
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Environment URLs for different deployment environments
|
|
8
|
+
*/
|
|
9
|
+
export declare const ENVIRONMENT_URLS: {
|
|
10
|
+
/**
|
|
11
|
+
* Production environment URL
|
|
12
|
+
* @default
|
|
13
|
+
*/
|
|
14
|
+
readonly PRODUCTION: "https://resource.seaverse.ai";
|
|
15
|
+
/**
|
|
16
|
+
* Staging/Test environment URL
|
|
17
|
+
*/
|
|
18
|
+
readonly STAGING: "https://resource.sg.seaverse.dev";
|
|
19
|
+
/**
|
|
20
|
+
* Local development URL
|
|
21
|
+
*/
|
|
22
|
+
readonly LOCAL: "http://localhost:8003";
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Default base URL (production)
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_BASE_URL: "https://resource.seaverse.ai";
|
|
28
|
+
/**
|
|
29
|
+
* Default timeout in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
export declare const DEFAULT_TIMEOUT = 60000;
|
|
32
|
+
/**
|
|
33
|
+
* Default compression configuration
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_COMPRESSION_CONFIG: {
|
|
36
|
+
readonly enabled: true;
|
|
37
|
+
readonly maxWidth: 1080;
|
|
38
|
+
readonly maxHeight: 1080;
|
|
39
|
+
readonly quality: 0.8;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Default maximum file size (100MB)
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_MAX_FILE_SIZE: number;
|
|
45
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;OAGG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEK,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,gBAAgB,gCAA8B,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;CAK7B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAAoB,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SeaVerse Utils SDK Configuration
|
|
3
|
+
*
|
|
4
|
+
* Environment-specific URLs and default configurations
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Environment URLs for different deployment environments
|
|
8
|
+
*/
|
|
9
|
+
export const ENVIRONMENT_URLS = {
|
|
10
|
+
/**
|
|
11
|
+
* Production environment URL
|
|
12
|
+
* @default
|
|
13
|
+
*/
|
|
14
|
+
PRODUCTION: 'https://resource.seaverse.ai',
|
|
15
|
+
/**
|
|
16
|
+
* Staging/Test environment URL
|
|
17
|
+
*/
|
|
18
|
+
STAGING: 'https://resource.sg.seaverse.dev',
|
|
19
|
+
/**
|
|
20
|
+
* Local development URL
|
|
21
|
+
*/
|
|
22
|
+
LOCAL: 'http://localhost:8003',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Default base URL (production)
|
|
26
|
+
*/
|
|
27
|
+
export const DEFAULT_BASE_URL = ENVIRONMENT_URLS.PRODUCTION;
|
|
28
|
+
/**
|
|
29
|
+
* Default timeout in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_TIMEOUT = 60000;
|
|
32
|
+
/**
|
|
33
|
+
* Default compression configuration
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_COMPRESSION_CONFIG = {
|
|
36
|
+
enabled: true,
|
|
37
|
+
maxWidth: 1080,
|
|
38
|
+
maxHeight: 1080,
|
|
39
|
+
quality: 0.8,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Default maximum file size (100MB)
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024;
|
|
45
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,UAAU,EAAE,8BAA8B;IAE1C;;OAEG;IACH,OAAO,EAAE,kCAAkC;IAE3C;;OAEG;IACH,KAAK,EAAE,uBAAuB;CACtB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,UAAU,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,GAAG;CACJ,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SeaVerse Utils SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* A utility toolkit including file upload, image compression, and more.
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
@@ -10,4 +10,5 @@ export type { UtilsClientOptions, CompressionConfig, UploadOptions, UploadProgre
|
|
|
10
10
|
export { UtilsAPIError, ErrorCode } from './models.js';
|
|
11
11
|
export { validateFile, formatBytes, isImageFile, getFileExtension, } from './utils.js';
|
|
12
12
|
export { compressImage, shouldCompress } from './compress.js';
|
|
13
|
+
export { ENVIRONMENT_URLS, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_COMPRESSION_CONFIG, DEFAULT_MAX_FILE_SIZE, } from './config.js';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SeaVerse Utils SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* A utility toolkit including file upload, image compression, and more.
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
|
-
//
|
|
8
|
+
// Export core client
|
|
9
9
|
export { UtilsClient } from './client.js';
|
|
10
|
-
//
|
|
10
|
+
// Export error class and error codes
|
|
11
11
|
export { UtilsAPIError, ErrorCode } from './models.js';
|
|
12
|
-
//
|
|
12
|
+
// Export utility functions
|
|
13
13
|
export { validateFile, formatBytes, isImageFile, getFileExtension, } from './utils.js';
|
|
14
|
-
//
|
|
14
|
+
// Export compression functions
|
|
15
15
|
export { compressImage, shouldCompress } from './compress.js';
|
|
16
|
+
// Export environment configuration
|
|
17
|
+
export { ENVIRONMENT_URLS, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_COMPRESSION_CONFIG, DEFAULT_MAX_FILE_SIZE, } from './config.js';
|
|
16
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAqB;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAkB1C,qCAAqC;AACrC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD,2BAA2B;AAC3B,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,+BAA+B;AAC/B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9D,mCAAmC;AACnC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seaverse/utils-sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "SeaVerse Utils SDK -
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "SeaVerse Utils SDK - Utility toolkit including file upload, image compression, and more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|