@ustorage/sdk 0.1.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/LICENSE +21 -0
- package/README.md +343 -0
- package/dist/browser/index.cjs +483 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +37 -0
- package/dist/browser/index.d.ts +37 -0
- package/dist/browser/index.js +445 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/core/index.cjs +397 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +273 -0
- package/dist/core/index.d.ts +273 -0
- package/dist/core/index.js +363 -0
- package/dist/core/index.js.map +1 -0
- package/dist/node/index.cjs +555 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +59 -0
- package/dist/node/index.d.ts +59 -0
- package/dist/node/index.js +514 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
type BrowserAuth = {
|
|
2
|
+
bearerToken: string | (() => string | Promise<string>);
|
|
3
|
+
uploadToken?: never;
|
|
4
|
+
} | {
|
|
5
|
+
uploadToken: string | (() => string | Promise<string>);
|
|
6
|
+
bearerToken?: never;
|
|
7
|
+
};
|
|
8
|
+
interface NodeCredentialAuth {
|
|
9
|
+
accessKey: string;
|
|
10
|
+
secretKey: string;
|
|
11
|
+
}
|
|
12
|
+
interface BearerAuth {
|
|
13
|
+
bearerToken: string | (() => string | Promise<string>);
|
|
14
|
+
}
|
|
15
|
+
declare function resolveToken(value: string | (() => string | Promise<string>)): Promise<string>;
|
|
16
|
+
|
|
17
|
+
type HeaderValue = string | undefined | null;
|
|
18
|
+
interface HttpRequestOptions {
|
|
19
|
+
method: string;
|
|
20
|
+
path: string;
|
|
21
|
+
headers?: Record<string, HeaderValue>;
|
|
22
|
+
query?: Record<string, string | number | boolean | undefined | null>;
|
|
23
|
+
body?: unknown;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
interface HttpClient {
|
|
27
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
28
|
+
}
|
|
29
|
+
type AuthHeadersProvider = (request?: {
|
|
30
|
+
method: string;
|
|
31
|
+
path: string;
|
|
32
|
+
body?: BodyInit;
|
|
33
|
+
}) => Record<string, string> | Promise<Record<string, string>>;
|
|
34
|
+
declare class FetchHttpClient implements HttpClient {
|
|
35
|
+
private readonly baseUrl;
|
|
36
|
+
private readonly authHeaders?;
|
|
37
|
+
private readonly fetchImpl;
|
|
38
|
+
constructor(options: {
|
|
39
|
+
baseUrl: string;
|
|
40
|
+
authHeaders?: AuthHeadersProvider;
|
|
41
|
+
fetchImpl?: typeof fetch;
|
|
42
|
+
});
|
|
43
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
44
|
+
private url;
|
|
45
|
+
private pathWithQuery;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type UploadBody = BodyInit | ArrayBufferView;
|
|
49
|
+
interface UploadChunk {
|
|
50
|
+
body: UploadBody;
|
|
51
|
+
size: number;
|
|
52
|
+
}
|
|
53
|
+
interface UploadSource {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly size: number;
|
|
56
|
+
readonly type?: string;
|
|
57
|
+
fingerprint(key?: string): string | Promise<string>;
|
|
58
|
+
slice(start: number, end: number): UploadChunk | Promise<UploadChunk>;
|
|
59
|
+
}
|
|
60
|
+
interface ResumeStore {
|
|
61
|
+
get(key: string): Promise<string | undefined> | string | undefined;
|
|
62
|
+
set(key: string, uploadId: string): Promise<void> | void;
|
|
63
|
+
delete(key: string): Promise<void> | void;
|
|
64
|
+
}
|
|
65
|
+
declare class MemoryResumeStore implements ResumeStore {
|
|
66
|
+
private readonly values;
|
|
67
|
+
get(key: string): string | undefined;
|
|
68
|
+
set(key: string, uploadId: string): void;
|
|
69
|
+
delete(key: string): void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
73
|
+
[key: string]: JsonValue;
|
|
74
|
+
};
|
|
75
|
+
type UploadStatus = 'uploading' | 'completed' | 'failed' | 'canceled' | 'expired' | string;
|
|
76
|
+
interface CreateUploadTokenRequest {
|
|
77
|
+
bucket_name: string;
|
|
78
|
+
key: string;
|
|
79
|
+
workspace_name?: string | null;
|
|
80
|
+
mime_type?: string | null;
|
|
81
|
+
max_file_size?: number | null;
|
|
82
|
+
expires_in?: number | null;
|
|
83
|
+
}
|
|
84
|
+
interface CreateUploadTokenResponse {
|
|
85
|
+
token: string;
|
|
86
|
+
bucket_name: string;
|
|
87
|
+
key: string;
|
|
88
|
+
expires_at: string;
|
|
89
|
+
}
|
|
90
|
+
interface CreateUploadSessionRequest {
|
|
91
|
+
bucket_name: string;
|
|
92
|
+
key: string;
|
|
93
|
+
workspace_name?: string | null;
|
|
94
|
+
mime_type?: string | null;
|
|
95
|
+
file_size: number;
|
|
96
|
+
chunk_size: number;
|
|
97
|
+
total_chunks: number;
|
|
98
|
+
checksum?: string | null;
|
|
99
|
+
metadata?: JsonValue;
|
|
100
|
+
overwrite?: boolean | null;
|
|
101
|
+
visibility?: 'public' | 'private' | null;
|
|
102
|
+
}
|
|
103
|
+
interface CreateUploadSessionResponse {
|
|
104
|
+
upload_id: string;
|
|
105
|
+
file_id: string;
|
|
106
|
+
workspace_id: string;
|
|
107
|
+
bucket_id: string;
|
|
108
|
+
chunk_size: number;
|
|
109
|
+
total_chunks: number;
|
|
110
|
+
expires_at: string;
|
|
111
|
+
}
|
|
112
|
+
interface UploadChunkResponse {
|
|
113
|
+
upload_id: string;
|
|
114
|
+
chunk_index: number;
|
|
115
|
+
status: string;
|
|
116
|
+
uploaded_chunks: number;
|
|
117
|
+
total_chunks: number;
|
|
118
|
+
uploaded_size: number;
|
|
119
|
+
file_size: number;
|
|
120
|
+
progress: number;
|
|
121
|
+
}
|
|
122
|
+
interface UploadStatusResponse {
|
|
123
|
+
upload_id: string;
|
|
124
|
+
file_id: string;
|
|
125
|
+
status: UploadStatus;
|
|
126
|
+
uploaded_chunks: number[];
|
|
127
|
+
missing_chunks: number[];
|
|
128
|
+
total_chunks: number;
|
|
129
|
+
uploaded_size: number;
|
|
130
|
+
file_size: number;
|
|
131
|
+
progress: number;
|
|
132
|
+
error?: JsonValue;
|
|
133
|
+
expires_at: string;
|
|
134
|
+
}
|
|
135
|
+
interface CompleteUploadRequest {
|
|
136
|
+
checksum?: string | null;
|
|
137
|
+
}
|
|
138
|
+
interface CompleteUploadResponse {
|
|
139
|
+
upload_id: string;
|
|
140
|
+
file_id: string;
|
|
141
|
+
status: string;
|
|
142
|
+
public_id?: string;
|
|
143
|
+
visibility?: 'public' | 'private' | string;
|
|
144
|
+
url?: string;
|
|
145
|
+
expires_at?: string | null;
|
|
146
|
+
}
|
|
147
|
+
interface CreateFileUrlRequest {
|
|
148
|
+
file_id?: string | null;
|
|
149
|
+
bucket?: string | null;
|
|
150
|
+
bucket_id?: string | null;
|
|
151
|
+
key?: string | null;
|
|
152
|
+
path?: string | null;
|
|
153
|
+
expires_in?: number | null;
|
|
154
|
+
}
|
|
155
|
+
interface CreateFileUrlResponse {
|
|
156
|
+
file_id: string;
|
|
157
|
+
public_id: string;
|
|
158
|
+
visibility: 'public' | 'private' | string;
|
|
159
|
+
url: string;
|
|
160
|
+
expires_at: string | null;
|
|
161
|
+
}
|
|
162
|
+
interface GetObjectUrlInput {
|
|
163
|
+
fileId?: string;
|
|
164
|
+
bucket?: string;
|
|
165
|
+
bucketId?: string;
|
|
166
|
+
key?: string;
|
|
167
|
+
path?: string;
|
|
168
|
+
expiresIn?: number;
|
|
169
|
+
}
|
|
170
|
+
interface GetObjectUrlResult {
|
|
171
|
+
fileId: string;
|
|
172
|
+
publicId: string;
|
|
173
|
+
visibility: 'public' | 'private' | string;
|
|
174
|
+
url: string;
|
|
175
|
+
expiresAt: string | null;
|
|
176
|
+
}
|
|
177
|
+
interface ErrorResponse {
|
|
178
|
+
error: {
|
|
179
|
+
code: string;
|
|
180
|
+
message: string;
|
|
181
|
+
details?: unknown;
|
|
182
|
+
};
|
|
183
|
+
request_id?: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare class UploadApi {
|
|
187
|
+
private readonly http;
|
|
188
|
+
constructor(http: HttpClient);
|
|
189
|
+
createUploadToken(request: CreateUploadTokenRequest): Promise<CreateUploadTokenResponse>;
|
|
190
|
+
createSession(request: CreateUploadSessionRequest): Promise<CreateUploadSessionResponse>;
|
|
191
|
+
createFileUrl(request: CreateFileUrlRequest): Promise<CreateFileUrlResponse>;
|
|
192
|
+
uploadChunk(uploadId: string, index: number, body: UploadBody, checksum?: string, signal?: AbortSignal): Promise<UploadChunkResponse>;
|
|
193
|
+
getStatus(uploadId: string): Promise<UploadStatusResponse>;
|
|
194
|
+
complete(uploadId: string, request?: CompleteUploadRequest): Promise<CompleteUploadResponse>;
|
|
195
|
+
cancel(uploadId: string): Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface PutObjectOptions {
|
|
199
|
+
bucketName: string;
|
|
200
|
+
key: string;
|
|
201
|
+
workspaceName?: string;
|
|
202
|
+
contentType?: string | null;
|
|
203
|
+
metadata?: JsonValue;
|
|
204
|
+
checksum?: false | 'sha256' | {
|
|
205
|
+
file?: string;
|
|
206
|
+
chunks?: Record<number, string>;
|
|
207
|
+
};
|
|
208
|
+
resume?: boolean;
|
|
209
|
+
resumeKey?: string;
|
|
210
|
+
overwrite?: boolean;
|
|
211
|
+
visibility?: 'public' | 'private';
|
|
212
|
+
chunkSize?: number;
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
onProgress?: (event: UploadProgressEvent) => void;
|
|
215
|
+
}
|
|
216
|
+
interface UploadFileOptions extends Omit<PutObjectOptions, 'key'> {
|
|
217
|
+
key?: string;
|
|
218
|
+
}
|
|
219
|
+
interface UploadProgressEvent {
|
|
220
|
+
uploadId: string;
|
|
221
|
+
chunkIndex?: number;
|
|
222
|
+
uploadedChunks: number;
|
|
223
|
+
totalChunks: number;
|
|
224
|
+
uploadedSize: number;
|
|
225
|
+
fileSize: number;
|
|
226
|
+
progress: number;
|
|
227
|
+
}
|
|
228
|
+
interface UploadObjectResult extends CompleteUploadResponse {
|
|
229
|
+
uploadId: string;
|
|
230
|
+
fileId: string;
|
|
231
|
+
publicId?: string;
|
|
232
|
+
visibility?: 'public' | 'private' | string;
|
|
233
|
+
url?: string;
|
|
234
|
+
expiresAt?: string | null;
|
|
235
|
+
}
|
|
236
|
+
declare class Uploader {
|
|
237
|
+
private readonly uploads;
|
|
238
|
+
private readonly resumeStore?;
|
|
239
|
+
constructor(uploads: UploadApi, resumeStore?: ResumeStore | undefined);
|
|
240
|
+
putObject(source: UploadSource, options: PutObjectOptions): Promise<UploadObjectResult>;
|
|
241
|
+
private chunkChecksum;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface UStorageClientOptions {
|
|
245
|
+
uploadBaseUrl: string;
|
|
246
|
+
authHeaders?: AuthHeadersProvider;
|
|
247
|
+
uploadHttpClient?: HttpClient;
|
|
248
|
+
resumeStore?: ResumeStore;
|
|
249
|
+
}
|
|
250
|
+
declare class UStorageCoreClient {
|
|
251
|
+
readonly uploads: UploadApi;
|
|
252
|
+
private readonly uploader;
|
|
253
|
+
constructor(options: UStorageClientOptions);
|
|
254
|
+
getObjectUrl(input: GetObjectUrlInput): Promise<GetObjectUrlResult>;
|
|
255
|
+
getSignedUrl(input: GetObjectUrlInput): Promise<GetObjectUrlResult>;
|
|
256
|
+
protected uploadSource(source: UploadSource, options: PutObjectOptions): Promise<UploadObjectResult>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
declare class UStorageError extends Error {
|
|
260
|
+
readonly code: string;
|
|
261
|
+
readonly status: number;
|
|
262
|
+
readonly requestId?: string;
|
|
263
|
+
readonly details?: unknown;
|
|
264
|
+
constructor(message: string, options: {
|
|
265
|
+
code: string;
|
|
266
|
+
status: number;
|
|
267
|
+
requestId?: string;
|
|
268
|
+
details?: unknown;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
declare function toUStorageError(status: number, body: unknown): UStorageError;
|
|
272
|
+
|
|
273
|
+
export { type AuthHeadersProvider, type BearerAuth, type BrowserAuth, type CompleteUploadRequest, type CompleteUploadResponse, type CreateFileUrlRequest, type CreateFileUrlResponse, type CreateUploadSessionRequest, type CreateUploadSessionResponse, type CreateUploadTokenRequest, type CreateUploadTokenResponse, type ErrorResponse, FetchHttpClient, type GetObjectUrlInput, type GetObjectUrlResult, type HeaderValue, type HttpClient, type HttpRequestOptions, type JsonValue, MemoryResumeStore, type NodeCredentialAuth, type PutObjectOptions, type ResumeStore, type UStorageClientOptions, UStorageCoreClient, UStorageError, UploadApi, type UploadBody, type UploadChunk, type UploadChunkResponse, type UploadFileOptions, type UploadObjectResult, type UploadProgressEvent, type UploadSource, type UploadStatus, type UploadStatusResponse, Uploader, resolveToken, toUStorageError };
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
type BrowserAuth = {
|
|
2
|
+
bearerToken: string | (() => string | Promise<string>);
|
|
3
|
+
uploadToken?: never;
|
|
4
|
+
} | {
|
|
5
|
+
uploadToken: string | (() => string | Promise<string>);
|
|
6
|
+
bearerToken?: never;
|
|
7
|
+
};
|
|
8
|
+
interface NodeCredentialAuth {
|
|
9
|
+
accessKey: string;
|
|
10
|
+
secretKey: string;
|
|
11
|
+
}
|
|
12
|
+
interface BearerAuth {
|
|
13
|
+
bearerToken: string | (() => string | Promise<string>);
|
|
14
|
+
}
|
|
15
|
+
declare function resolveToken(value: string | (() => string | Promise<string>)): Promise<string>;
|
|
16
|
+
|
|
17
|
+
type HeaderValue = string | undefined | null;
|
|
18
|
+
interface HttpRequestOptions {
|
|
19
|
+
method: string;
|
|
20
|
+
path: string;
|
|
21
|
+
headers?: Record<string, HeaderValue>;
|
|
22
|
+
query?: Record<string, string | number | boolean | undefined | null>;
|
|
23
|
+
body?: unknown;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
interface HttpClient {
|
|
27
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
28
|
+
}
|
|
29
|
+
type AuthHeadersProvider = (request?: {
|
|
30
|
+
method: string;
|
|
31
|
+
path: string;
|
|
32
|
+
body?: BodyInit;
|
|
33
|
+
}) => Record<string, string> | Promise<Record<string, string>>;
|
|
34
|
+
declare class FetchHttpClient implements HttpClient {
|
|
35
|
+
private readonly baseUrl;
|
|
36
|
+
private readonly authHeaders?;
|
|
37
|
+
private readonly fetchImpl;
|
|
38
|
+
constructor(options: {
|
|
39
|
+
baseUrl: string;
|
|
40
|
+
authHeaders?: AuthHeadersProvider;
|
|
41
|
+
fetchImpl?: typeof fetch;
|
|
42
|
+
});
|
|
43
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
44
|
+
private url;
|
|
45
|
+
private pathWithQuery;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type UploadBody = BodyInit | ArrayBufferView;
|
|
49
|
+
interface UploadChunk {
|
|
50
|
+
body: UploadBody;
|
|
51
|
+
size: number;
|
|
52
|
+
}
|
|
53
|
+
interface UploadSource {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly size: number;
|
|
56
|
+
readonly type?: string;
|
|
57
|
+
fingerprint(key?: string): string | Promise<string>;
|
|
58
|
+
slice(start: number, end: number): UploadChunk | Promise<UploadChunk>;
|
|
59
|
+
}
|
|
60
|
+
interface ResumeStore {
|
|
61
|
+
get(key: string): Promise<string | undefined> | string | undefined;
|
|
62
|
+
set(key: string, uploadId: string): Promise<void> | void;
|
|
63
|
+
delete(key: string): Promise<void> | void;
|
|
64
|
+
}
|
|
65
|
+
declare class MemoryResumeStore implements ResumeStore {
|
|
66
|
+
private readonly values;
|
|
67
|
+
get(key: string): string | undefined;
|
|
68
|
+
set(key: string, uploadId: string): void;
|
|
69
|
+
delete(key: string): void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
73
|
+
[key: string]: JsonValue;
|
|
74
|
+
};
|
|
75
|
+
type UploadStatus = 'uploading' | 'completed' | 'failed' | 'canceled' | 'expired' | string;
|
|
76
|
+
interface CreateUploadTokenRequest {
|
|
77
|
+
bucket_name: string;
|
|
78
|
+
key: string;
|
|
79
|
+
workspace_name?: string | null;
|
|
80
|
+
mime_type?: string | null;
|
|
81
|
+
max_file_size?: number | null;
|
|
82
|
+
expires_in?: number | null;
|
|
83
|
+
}
|
|
84
|
+
interface CreateUploadTokenResponse {
|
|
85
|
+
token: string;
|
|
86
|
+
bucket_name: string;
|
|
87
|
+
key: string;
|
|
88
|
+
expires_at: string;
|
|
89
|
+
}
|
|
90
|
+
interface CreateUploadSessionRequest {
|
|
91
|
+
bucket_name: string;
|
|
92
|
+
key: string;
|
|
93
|
+
workspace_name?: string | null;
|
|
94
|
+
mime_type?: string | null;
|
|
95
|
+
file_size: number;
|
|
96
|
+
chunk_size: number;
|
|
97
|
+
total_chunks: number;
|
|
98
|
+
checksum?: string | null;
|
|
99
|
+
metadata?: JsonValue;
|
|
100
|
+
overwrite?: boolean | null;
|
|
101
|
+
visibility?: 'public' | 'private' | null;
|
|
102
|
+
}
|
|
103
|
+
interface CreateUploadSessionResponse {
|
|
104
|
+
upload_id: string;
|
|
105
|
+
file_id: string;
|
|
106
|
+
workspace_id: string;
|
|
107
|
+
bucket_id: string;
|
|
108
|
+
chunk_size: number;
|
|
109
|
+
total_chunks: number;
|
|
110
|
+
expires_at: string;
|
|
111
|
+
}
|
|
112
|
+
interface UploadChunkResponse {
|
|
113
|
+
upload_id: string;
|
|
114
|
+
chunk_index: number;
|
|
115
|
+
status: string;
|
|
116
|
+
uploaded_chunks: number;
|
|
117
|
+
total_chunks: number;
|
|
118
|
+
uploaded_size: number;
|
|
119
|
+
file_size: number;
|
|
120
|
+
progress: number;
|
|
121
|
+
}
|
|
122
|
+
interface UploadStatusResponse {
|
|
123
|
+
upload_id: string;
|
|
124
|
+
file_id: string;
|
|
125
|
+
status: UploadStatus;
|
|
126
|
+
uploaded_chunks: number[];
|
|
127
|
+
missing_chunks: number[];
|
|
128
|
+
total_chunks: number;
|
|
129
|
+
uploaded_size: number;
|
|
130
|
+
file_size: number;
|
|
131
|
+
progress: number;
|
|
132
|
+
error?: JsonValue;
|
|
133
|
+
expires_at: string;
|
|
134
|
+
}
|
|
135
|
+
interface CompleteUploadRequest {
|
|
136
|
+
checksum?: string | null;
|
|
137
|
+
}
|
|
138
|
+
interface CompleteUploadResponse {
|
|
139
|
+
upload_id: string;
|
|
140
|
+
file_id: string;
|
|
141
|
+
status: string;
|
|
142
|
+
public_id?: string;
|
|
143
|
+
visibility?: 'public' | 'private' | string;
|
|
144
|
+
url?: string;
|
|
145
|
+
expires_at?: string | null;
|
|
146
|
+
}
|
|
147
|
+
interface CreateFileUrlRequest {
|
|
148
|
+
file_id?: string | null;
|
|
149
|
+
bucket?: string | null;
|
|
150
|
+
bucket_id?: string | null;
|
|
151
|
+
key?: string | null;
|
|
152
|
+
path?: string | null;
|
|
153
|
+
expires_in?: number | null;
|
|
154
|
+
}
|
|
155
|
+
interface CreateFileUrlResponse {
|
|
156
|
+
file_id: string;
|
|
157
|
+
public_id: string;
|
|
158
|
+
visibility: 'public' | 'private' | string;
|
|
159
|
+
url: string;
|
|
160
|
+
expires_at: string | null;
|
|
161
|
+
}
|
|
162
|
+
interface GetObjectUrlInput {
|
|
163
|
+
fileId?: string;
|
|
164
|
+
bucket?: string;
|
|
165
|
+
bucketId?: string;
|
|
166
|
+
key?: string;
|
|
167
|
+
path?: string;
|
|
168
|
+
expiresIn?: number;
|
|
169
|
+
}
|
|
170
|
+
interface GetObjectUrlResult {
|
|
171
|
+
fileId: string;
|
|
172
|
+
publicId: string;
|
|
173
|
+
visibility: 'public' | 'private' | string;
|
|
174
|
+
url: string;
|
|
175
|
+
expiresAt: string | null;
|
|
176
|
+
}
|
|
177
|
+
interface ErrorResponse {
|
|
178
|
+
error: {
|
|
179
|
+
code: string;
|
|
180
|
+
message: string;
|
|
181
|
+
details?: unknown;
|
|
182
|
+
};
|
|
183
|
+
request_id?: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare class UploadApi {
|
|
187
|
+
private readonly http;
|
|
188
|
+
constructor(http: HttpClient);
|
|
189
|
+
createUploadToken(request: CreateUploadTokenRequest): Promise<CreateUploadTokenResponse>;
|
|
190
|
+
createSession(request: CreateUploadSessionRequest): Promise<CreateUploadSessionResponse>;
|
|
191
|
+
createFileUrl(request: CreateFileUrlRequest): Promise<CreateFileUrlResponse>;
|
|
192
|
+
uploadChunk(uploadId: string, index: number, body: UploadBody, checksum?: string, signal?: AbortSignal): Promise<UploadChunkResponse>;
|
|
193
|
+
getStatus(uploadId: string): Promise<UploadStatusResponse>;
|
|
194
|
+
complete(uploadId: string, request?: CompleteUploadRequest): Promise<CompleteUploadResponse>;
|
|
195
|
+
cancel(uploadId: string): Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface PutObjectOptions {
|
|
199
|
+
bucketName: string;
|
|
200
|
+
key: string;
|
|
201
|
+
workspaceName?: string;
|
|
202
|
+
contentType?: string | null;
|
|
203
|
+
metadata?: JsonValue;
|
|
204
|
+
checksum?: false | 'sha256' | {
|
|
205
|
+
file?: string;
|
|
206
|
+
chunks?: Record<number, string>;
|
|
207
|
+
};
|
|
208
|
+
resume?: boolean;
|
|
209
|
+
resumeKey?: string;
|
|
210
|
+
overwrite?: boolean;
|
|
211
|
+
visibility?: 'public' | 'private';
|
|
212
|
+
chunkSize?: number;
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
onProgress?: (event: UploadProgressEvent) => void;
|
|
215
|
+
}
|
|
216
|
+
interface UploadFileOptions extends Omit<PutObjectOptions, 'key'> {
|
|
217
|
+
key?: string;
|
|
218
|
+
}
|
|
219
|
+
interface UploadProgressEvent {
|
|
220
|
+
uploadId: string;
|
|
221
|
+
chunkIndex?: number;
|
|
222
|
+
uploadedChunks: number;
|
|
223
|
+
totalChunks: number;
|
|
224
|
+
uploadedSize: number;
|
|
225
|
+
fileSize: number;
|
|
226
|
+
progress: number;
|
|
227
|
+
}
|
|
228
|
+
interface UploadObjectResult extends CompleteUploadResponse {
|
|
229
|
+
uploadId: string;
|
|
230
|
+
fileId: string;
|
|
231
|
+
publicId?: string;
|
|
232
|
+
visibility?: 'public' | 'private' | string;
|
|
233
|
+
url?: string;
|
|
234
|
+
expiresAt?: string | null;
|
|
235
|
+
}
|
|
236
|
+
declare class Uploader {
|
|
237
|
+
private readonly uploads;
|
|
238
|
+
private readonly resumeStore?;
|
|
239
|
+
constructor(uploads: UploadApi, resumeStore?: ResumeStore | undefined);
|
|
240
|
+
putObject(source: UploadSource, options: PutObjectOptions): Promise<UploadObjectResult>;
|
|
241
|
+
private chunkChecksum;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface UStorageClientOptions {
|
|
245
|
+
uploadBaseUrl: string;
|
|
246
|
+
authHeaders?: AuthHeadersProvider;
|
|
247
|
+
uploadHttpClient?: HttpClient;
|
|
248
|
+
resumeStore?: ResumeStore;
|
|
249
|
+
}
|
|
250
|
+
declare class UStorageCoreClient {
|
|
251
|
+
readonly uploads: UploadApi;
|
|
252
|
+
private readonly uploader;
|
|
253
|
+
constructor(options: UStorageClientOptions);
|
|
254
|
+
getObjectUrl(input: GetObjectUrlInput): Promise<GetObjectUrlResult>;
|
|
255
|
+
getSignedUrl(input: GetObjectUrlInput): Promise<GetObjectUrlResult>;
|
|
256
|
+
protected uploadSource(source: UploadSource, options: PutObjectOptions): Promise<UploadObjectResult>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
declare class UStorageError extends Error {
|
|
260
|
+
readonly code: string;
|
|
261
|
+
readonly status: number;
|
|
262
|
+
readonly requestId?: string;
|
|
263
|
+
readonly details?: unknown;
|
|
264
|
+
constructor(message: string, options: {
|
|
265
|
+
code: string;
|
|
266
|
+
status: number;
|
|
267
|
+
requestId?: string;
|
|
268
|
+
details?: unknown;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
declare function toUStorageError(status: number, body: unknown): UStorageError;
|
|
272
|
+
|
|
273
|
+
export { type AuthHeadersProvider, type BearerAuth, type BrowserAuth, type CompleteUploadRequest, type CompleteUploadResponse, type CreateFileUrlRequest, type CreateFileUrlResponse, type CreateUploadSessionRequest, type CreateUploadSessionResponse, type CreateUploadTokenRequest, type CreateUploadTokenResponse, type ErrorResponse, FetchHttpClient, type GetObjectUrlInput, type GetObjectUrlResult, type HeaderValue, type HttpClient, type HttpRequestOptions, type JsonValue, MemoryResumeStore, type NodeCredentialAuth, type PutObjectOptions, type ResumeStore, type UStorageClientOptions, UStorageCoreClient, UStorageError, UploadApi, type UploadBody, type UploadChunk, type UploadChunkResponse, type UploadFileOptions, type UploadObjectResult, type UploadProgressEvent, type UploadSource, type UploadStatus, type UploadStatusResponse, Uploader, resolveToken, toUStorageError };
|