@bluecopa/core 0.1.26 → 0.1.27
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export interface FileDownloadRequest {
|
|
2
2
|
fileId: string;
|
|
3
|
+
contentType?: string;
|
|
4
|
+
method?: 'GET' | 'PUT';
|
|
3
5
|
}
|
|
4
6
|
/**
|
|
5
7
|
* Downloads a file from S3 using presigned URL
|
|
@@ -8,4 +10,4 @@ export interface FileDownloadRequest {
|
|
|
8
10
|
* @returns Promise<any> The file data
|
|
9
11
|
* @throws Error if the request fails
|
|
10
12
|
*/
|
|
11
|
-
export declare function fileDownload({ fileId, }: FileDownloadRequest): Promise<any>;
|
|
13
|
+
export declare function fileDownload({ fileId, contentType, method, }: FileDownloadRequest): Promise<any>;
|
|
@@ -3,7 +3,6 @@ export interface FileUploadRequest {
|
|
|
3
3
|
contentType?: string;
|
|
4
4
|
method?: string;
|
|
5
5
|
data: any;
|
|
6
|
-
uploadType?: string;
|
|
7
6
|
}
|
|
8
7
|
export interface FileUploadResponse {
|
|
9
8
|
fileId: string;
|
|
@@ -15,8 +14,7 @@ export interface FileUploadResponse {
|
|
|
15
14
|
* @param params.contentType - Optional: Content type (defaults to 'application/json')
|
|
16
15
|
* @param params.method - Optional: HTTP method (defaults to 'PUT')
|
|
17
16
|
* @param params.data - Required: The data to upload
|
|
18
|
-
* @param params.uploadType - Optional: Upload type for path generation (defaults to 'DEFINITION')
|
|
19
17
|
* @returns Promise<FileUploadResponse> The file ID/path
|
|
20
18
|
* @throws Error if the request fails
|
|
21
19
|
*/
|
|
22
|
-
export declare function fileUpload({ path, contentType, method, data,
|
|
20
|
+
export declare function fileUpload({ path, contentType, method, data, }: FileUploadRequest): Promise<FileUploadResponse>;
|
package/dist/index.es.js
CHANGED
|
@@ -218,29 +218,32 @@ async function fileUpload({
|
|
|
218
218
|
path,
|
|
219
219
|
contentType,
|
|
220
220
|
method,
|
|
221
|
-
data
|
|
222
|
-
uploadType
|
|
221
|
+
data
|
|
223
222
|
}) {
|
|
224
223
|
var _a, _b, _c;
|
|
225
224
|
try {
|
|
226
|
-
if (!data) {
|
|
225
|
+
if (!data || !path) {
|
|
227
226
|
throw { message: "Data is required", status: 400 };
|
|
228
227
|
}
|
|
229
|
-
const response = await apiClient.post("/file/
|
|
230
|
-
path,
|
|
228
|
+
const response = await apiClient.post("/file/url", {
|
|
229
|
+
key: path,
|
|
231
230
|
contentType,
|
|
232
|
-
method
|
|
233
|
-
data,
|
|
234
|
-
uploadType
|
|
235
|
-
}, {
|
|
236
|
-
headers: {
|
|
237
|
-
"Content-Type": contentType
|
|
238
|
-
}
|
|
231
|
+
method
|
|
239
232
|
});
|
|
240
|
-
if (!response.data || !response.data.
|
|
233
|
+
if (!response.data || !response.data.url) {
|
|
241
234
|
throw { message: "Failed to upload file", status: 500 };
|
|
242
235
|
}
|
|
243
|
-
|
|
236
|
+
const fileUploadUrl = response.data.url;
|
|
237
|
+
const config = {
|
|
238
|
+
method,
|
|
239
|
+
url: fileUploadUrl,
|
|
240
|
+
headers: {
|
|
241
|
+
"Content-Type": contentType
|
|
242
|
+
},
|
|
243
|
+
data
|
|
244
|
+
};
|
|
245
|
+
await axios(config);
|
|
246
|
+
return { fileId: path };
|
|
244
247
|
} catch (error) {
|
|
245
248
|
const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while uploading file";
|
|
246
249
|
const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
|
|
@@ -248,20 +251,24 @@ async function fileUpload({
|
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
253
|
async function fileDownload({
|
|
251
|
-
fileId
|
|
254
|
+
fileId,
|
|
255
|
+
contentType,
|
|
256
|
+
method
|
|
252
257
|
}) {
|
|
253
258
|
var _a, _b, _c;
|
|
254
259
|
try {
|
|
255
260
|
if (!fileId) {
|
|
256
261
|
throw { message: "File ID is required", status: 400 };
|
|
257
262
|
}
|
|
258
|
-
const response = await apiClient.
|
|
259
|
-
|
|
260
|
-
|
|
263
|
+
const response = await apiClient.post("/file/url", {
|
|
264
|
+
key: fileId,
|
|
265
|
+
contentType: contentType || "application/json",
|
|
266
|
+
method: method || "GET"
|
|
267
|
+
});
|
|
261
268
|
if (!response.data || !response.data.data) {
|
|
262
269
|
throw { message: "Failed to download file", status: 500 };
|
|
263
270
|
}
|
|
264
|
-
return response.data.
|
|
271
|
+
return response.data.url;
|
|
265
272
|
} catch (error) {
|
|
266
273
|
const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while downloading file";
|
|
267
274
|
const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
|