@unboundcx/sdk 1.0.7 → 1.0.8
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/package.json +1 -1
- package/services/storage.js +41 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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
|
@@ -153,29 +153,39 @@ export class StorageService {
|
|
|
153
153
|
formFields.push(['accessKeyExpiresIn', accessKeyExpiresIn]);
|
|
154
154
|
|
|
155
155
|
// Convert to buffers and combine
|
|
156
|
-
const headerBuffer = Buffer.from(body, 'utf8');
|
|
157
|
-
const fileBuffer = Buffer.isBuffer(file) ? file : Buffer.from(file);
|
|
156
|
+
const headerBuffer = (typeof Buffer !== 'undefined') ? Buffer.from(body, 'utf8') : new TextEncoder().encode(body);
|
|
157
|
+
const fileBuffer = (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(file)) ? file : ((typeof Buffer !== 'undefined') ? Buffer.from(file) : new TextEncoder().encode(file));
|
|
158
158
|
|
|
159
159
|
// Add form fields
|
|
160
|
-
let fieldsBuffer = Buffer.alloc(0);
|
|
160
|
+
let fieldsBuffer = (typeof Buffer !== 'undefined') ? Buffer.alloc(0) : new Uint8Array(0);
|
|
161
161
|
for (const [name, value] of formFields) {
|
|
162
162
|
const fieldData = `${CRLF}--${boundary}${CRLF}Content-Disposition: form-data; name="${name}"${CRLF}${CRLF}${value}`;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Buffer.
|
|
166
|
-
|
|
163
|
+
const fieldDataBuffer = (typeof Buffer !== 'undefined') ? Buffer.from(fieldData, 'utf8') : new TextEncoder().encode(fieldData);
|
|
164
|
+
if (typeof Buffer !== 'undefined') {
|
|
165
|
+
fieldsBuffer = Buffer.concat([fieldsBuffer, fieldDataBuffer]);
|
|
166
|
+
} else {
|
|
167
|
+
const newBuffer = new Uint8Array(fieldsBuffer.length + fieldDataBuffer.length);
|
|
168
|
+
newBuffer.set(fieldsBuffer);
|
|
169
|
+
newBuffer.set(fieldDataBuffer, fieldsBuffer.length);
|
|
170
|
+
fieldsBuffer = newBuffer;
|
|
171
|
+
}
|
|
167
172
|
}
|
|
168
173
|
|
|
169
174
|
// Final boundary
|
|
170
|
-
const endBoundary = Buffer.from(`${CRLF}--${boundary}--${CRLF}`, 'utf8');
|
|
175
|
+
const endBoundary = (typeof Buffer !== 'undefined') ? Buffer.from(`${CRLF}--${boundary}--${CRLF}`, 'utf8') : new TextEncoder().encode(`${CRLF}--${boundary}--${CRLF}`);
|
|
171
176
|
|
|
172
177
|
// Combine all parts
|
|
173
|
-
|
|
174
|
-
headerBuffer,
|
|
175
|
-
|
|
176
|
-
fieldsBuffer
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
if (typeof Buffer !== 'undefined') {
|
|
179
|
+
formData = Buffer.concat([headerBuffer, fileBuffer, fieldsBuffer, endBoundary]);
|
|
180
|
+
} else {
|
|
181
|
+
const totalLength = headerBuffer.length + fileBuffer.length + fieldsBuffer.length + endBoundary.length;
|
|
182
|
+
formData = new Uint8Array(totalLength);
|
|
183
|
+
let offset = 0;
|
|
184
|
+
formData.set(headerBuffer, offset); offset += headerBuffer.length;
|
|
185
|
+
formData.set(fileBuffer, offset); offset += fileBuffer.length;
|
|
186
|
+
formData.set(fieldsBuffer, offset); offset += fieldsBuffer.length;
|
|
187
|
+
formData.set(endBoundary, offset);
|
|
188
|
+
}
|
|
179
189
|
|
|
180
190
|
// Set proper Content-Type header
|
|
181
191
|
headers['content-type'] = `multipart/form-data; boundary=${boundary}`;
|
|
@@ -184,7 +194,7 @@ export class StorageService {
|
|
|
184
194
|
formData = new FormData();
|
|
185
195
|
|
|
186
196
|
// Add the file - handle both Buffer and File objects
|
|
187
|
-
if (Buffer.isBuffer(file)) {
|
|
197
|
+
if ((typeof Buffer !== 'undefined') && Buffer.isBuffer && Buffer.isBuffer(file)) {
|
|
188
198
|
const blob = new Blob([file]);
|
|
189
199
|
formData.append('files', blob, fileName || 'file');
|
|
190
200
|
} else if (file instanceof File) {
|
|
@@ -401,29 +411,34 @@ export class StorageService {
|
|
|
401
411
|
}"${CRLF}`;
|
|
402
412
|
body += `Content-Type: ${contentType}${CRLF}${CRLF}`;
|
|
403
413
|
|
|
404
|
-
const headerBuffer = Buffer.from(body, 'utf8');
|
|
405
|
-
const fileBuffer = Buffer.isBuffer(file) ? file : Buffer.from(file);
|
|
414
|
+
const headerBuffer = (typeof Buffer !== 'undefined') ? Buffer.from(body, 'utf8') : new TextEncoder().encode(body);
|
|
415
|
+
const fileBuffer = (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(file)) ? file : ((typeof Buffer !== 'undefined') ? Buffer.from(file) : new TextEncoder().encode(file));
|
|
406
416
|
|
|
407
417
|
// Add classification field
|
|
408
418
|
const classificationField = `${CRLF}--${boundary}${CRLF}Content-Disposition: form-data; name="classification"${CRLF}${CRLF}${classification}`;
|
|
409
|
-
const fieldsBuffer = Buffer.from(classificationField, 'utf8');
|
|
419
|
+
const fieldsBuffer = (typeof Buffer !== 'undefined') ? Buffer.from(classificationField, 'utf8') : new TextEncoder().encode(classificationField);
|
|
410
420
|
|
|
411
421
|
// Final boundary
|
|
412
|
-
const endBoundary = Buffer.from(`${CRLF}--${boundary}--${CRLF}`, 'utf8');
|
|
422
|
+
const endBoundary = (typeof Buffer !== 'undefined') ? Buffer.from(`${CRLF}--${boundary}--${CRLF}`, 'utf8') : new TextEncoder().encode(`${CRLF}--${boundary}--${CRLF}`);
|
|
413
423
|
|
|
414
424
|
// Combine all parts
|
|
415
|
-
|
|
416
|
-
headerBuffer,
|
|
417
|
-
|
|
418
|
-
fieldsBuffer
|
|
419
|
-
|
|
420
|
-
|
|
425
|
+
if (typeof Buffer !== 'undefined') {
|
|
426
|
+
formData = Buffer.concat([headerBuffer, fileBuffer, fieldsBuffer, endBoundary]);
|
|
427
|
+
} else {
|
|
428
|
+
const totalLength = headerBuffer.length + fileBuffer.length + fieldsBuffer.length + endBoundary.length;
|
|
429
|
+
formData = new Uint8Array(totalLength);
|
|
430
|
+
let offset = 0;
|
|
431
|
+
formData.set(headerBuffer, offset); offset += headerBuffer.length;
|
|
432
|
+
formData.set(fileBuffer, offset); offset += fileBuffer.length;
|
|
433
|
+
formData.set(fieldsBuffer, offset); offset += fieldsBuffer.length;
|
|
434
|
+
formData.set(endBoundary, offset);
|
|
435
|
+
}
|
|
421
436
|
headers['content-type'] = `multipart/form-data; boundary=${boundary}`;
|
|
422
437
|
} else {
|
|
423
438
|
// Browser environment
|
|
424
439
|
formData = new FormData();
|
|
425
440
|
|
|
426
|
-
if (Buffer.isBuffer(file)) {
|
|
441
|
+
if ((typeof Buffer !== 'undefined') && Buffer.isBuffer && Buffer.isBuffer(file)) {
|
|
427
442
|
const blob = new Blob([file]);
|
|
428
443
|
formData.append('files', blob, fileName || 'profile-image.jpg');
|
|
429
444
|
} else if (file instanceof File) {
|