@unboundcx/sdk 1.0.6 → 1.0.7
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/base.js +1 -1
- package/package.json +1 -1
- package/services/storage.js +26 -12
package/base.js
CHANGED
|
@@ -238,7 +238,7 @@ export class BaseSDK {
|
|
|
238
238
|
body &&
|
|
239
239
|
(body.constructor.name === 'FormData' ||
|
|
240
240
|
typeof body.getBoundary === 'function');
|
|
241
|
-
const isBuffer = Buffer && Buffer.isBuffer && Buffer.isBuffer(body);
|
|
241
|
+
const isBuffer = (typeof Buffer !== 'undefined') && Buffer.isBuffer && Buffer.isBuffer(body);
|
|
242
242
|
|
|
243
243
|
if (isFormData || isBuffer) {
|
|
244
244
|
options.body = body;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/services/storage.js
CHANGED
|
@@ -351,11 +351,7 @@ export class StorageService {
|
|
|
351
351
|
return result;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
async uploadProfileImage({
|
|
355
|
-
file,
|
|
356
|
-
classification = 'user_images',
|
|
357
|
-
fileName,
|
|
358
|
-
}) {
|
|
354
|
+
async uploadProfileImage({ file, classification = 'user_images', fileName }) {
|
|
359
355
|
this.sdk.validateParams(
|
|
360
356
|
{ file, classification },
|
|
361
357
|
{
|
|
@@ -368,7 +364,9 @@ export class StorageService {
|
|
|
368
364
|
// Validate classification
|
|
369
365
|
const validClassifications = ['user_images', 'account_logo'];
|
|
370
366
|
if (!validClassifications.includes(classification)) {
|
|
371
|
-
throw new Error(
|
|
367
|
+
throw new Error(
|
|
368
|
+
'Invalid classification. Must be "user_images" or "account_logo"',
|
|
369
|
+
);
|
|
372
370
|
}
|
|
373
371
|
|
|
374
372
|
const isNode = typeof window === 'undefined';
|
|
@@ -377,7 +375,9 @@ export class StorageService {
|
|
|
377
375
|
|
|
378
376
|
if (isNode) {
|
|
379
377
|
// Node.js environment
|
|
380
|
-
const boundary = `----formdata-${Date.now()}-${Math.random().toString(
|
|
378
|
+
const boundary = `----formdata-${Date.now()}-${Math.random().toString(
|
|
379
|
+
36,
|
|
380
|
+
)}`;
|
|
381
381
|
const CRLF = '\r\n';
|
|
382
382
|
let body = '';
|
|
383
383
|
|
|
@@ -396,7 +396,9 @@ export class StorageService {
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
body += `--${boundary}${CRLF}`;
|
|
399
|
-
body += `Content-Disposition: form-data; name="files"; filename="${
|
|
399
|
+
body += `Content-Disposition: form-data; name="files"; filename="${
|
|
400
|
+
fileName || 'profile-image.jpg'
|
|
401
|
+
}"${CRLF}`;
|
|
400
402
|
body += `Content-Type: ${contentType}${CRLF}${CRLF}`;
|
|
401
403
|
|
|
402
404
|
const headerBuffer = Buffer.from(body, 'utf8');
|
|
@@ -410,19 +412,26 @@ export class StorageService {
|
|
|
410
412
|
const endBoundary = Buffer.from(`${CRLF}--${boundary}--${CRLF}`, 'utf8');
|
|
411
413
|
|
|
412
414
|
// Combine all parts
|
|
413
|
-
formData = Buffer.concat([
|
|
415
|
+
formData = Buffer.concat([
|
|
416
|
+
headerBuffer,
|
|
417
|
+
fileBuffer,
|
|
418
|
+
fieldsBuffer,
|
|
419
|
+
endBoundary,
|
|
420
|
+
]);
|
|
414
421
|
headers['content-type'] = `multipart/form-data; boundary=${boundary}`;
|
|
415
422
|
} else {
|
|
416
423
|
// Browser environment
|
|
417
424
|
formData = new FormData();
|
|
418
|
-
|
|
425
|
+
|
|
419
426
|
if (Buffer.isBuffer(file)) {
|
|
420
427
|
const blob = new Blob([file]);
|
|
421
428
|
formData.append('files', blob, fileName || 'profile-image.jpg');
|
|
422
429
|
} else if (file instanceof File) {
|
|
423
430
|
formData.append('files', file);
|
|
424
431
|
} else {
|
|
425
|
-
throw new Error(
|
|
432
|
+
throw new Error(
|
|
433
|
+
'In browser environment, file must be a Buffer or File object',
|
|
434
|
+
);
|
|
426
435
|
}
|
|
427
436
|
|
|
428
437
|
formData.append('classification', classification);
|
|
@@ -433,7 +442,12 @@ export class StorageService {
|
|
|
433
442
|
headers,
|
|
434
443
|
};
|
|
435
444
|
|
|
436
|
-
const result = await this.sdk._fetch(
|
|
445
|
+
const result = await this.sdk._fetch(
|
|
446
|
+
'/storage/upload-profile-image',
|
|
447
|
+
'POST',
|
|
448
|
+
params,
|
|
449
|
+
true,
|
|
450
|
+
);
|
|
437
451
|
return result;
|
|
438
452
|
}
|
|
439
453
|
|