@unboundcx/sdk 1.0.6 → 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/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.6",
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",
@@ -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
- fieldsBuffer = Buffer.concat([
164
- fieldsBuffer,
165
- Buffer.from(fieldData, 'utf8'),
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
- formData = Buffer.concat([
174
- headerBuffer,
175
- fileBuffer,
176
- fieldsBuffer,
177
- endBoundary,
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) {
@@ -351,11 +361,7 @@ export class StorageService {
351
361
  return result;
352
362
  }
353
363
 
354
- async uploadProfileImage({
355
- file,
356
- classification = 'user_images',
357
- fileName,
358
- }) {
364
+ async uploadProfileImage({ file, classification = 'user_images', fileName }) {
359
365
  this.sdk.validateParams(
360
366
  { file, classification },
361
367
  {
@@ -368,7 +374,9 @@ export class StorageService {
368
374
  // Validate classification
369
375
  const validClassifications = ['user_images', 'account_logo'];
370
376
  if (!validClassifications.includes(classification)) {
371
- throw new Error('Invalid classification. Must be "user_images" or "account_logo"');
377
+ throw new Error(
378
+ 'Invalid classification. Must be "user_images" or "account_logo"',
379
+ );
372
380
  }
373
381
 
374
382
  const isNode = typeof window === 'undefined';
@@ -377,7 +385,9 @@ export class StorageService {
377
385
 
378
386
  if (isNode) {
379
387
  // Node.js environment
380
- const boundary = `----formdata-${Date.now()}-${Math.random().toString(36)}`;
388
+ const boundary = `----formdata-${Date.now()}-${Math.random().toString(
389
+ 36,
390
+ )}`;
381
391
  const CRLF = '\r\n';
382
392
  let body = '';
383
393
 
@@ -396,33 +406,47 @@ export class StorageService {
396
406
  }
397
407
 
398
408
  body += `--${boundary}${CRLF}`;
399
- body += `Content-Disposition: form-data; name="files"; filename="${fileName || 'profile-image.jpg'}"${CRLF}`;
409
+ body += `Content-Disposition: form-data; name="files"; filename="${
410
+ fileName || 'profile-image.jpg'
411
+ }"${CRLF}`;
400
412
  body += `Content-Type: ${contentType}${CRLF}${CRLF}`;
401
413
 
402
- const headerBuffer = Buffer.from(body, 'utf8');
403
- 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));
404
416
 
405
417
  // Add classification field
406
418
  const classificationField = `${CRLF}--${boundary}${CRLF}Content-Disposition: form-data; name="classification"${CRLF}${CRLF}${classification}`;
407
- const fieldsBuffer = Buffer.from(classificationField, 'utf8');
419
+ const fieldsBuffer = (typeof Buffer !== 'undefined') ? Buffer.from(classificationField, 'utf8') : new TextEncoder().encode(classificationField);
408
420
 
409
421
  // Final boundary
410
- 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}`);
411
423
 
412
424
  // Combine all parts
413
- formData = Buffer.concat([headerBuffer, fileBuffer, fieldsBuffer, endBoundary]);
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
+ }
414
436
  headers['content-type'] = `multipart/form-data; boundary=${boundary}`;
415
437
  } else {
416
438
  // Browser environment
417
439
  formData = new FormData();
418
-
419
- if (Buffer.isBuffer(file)) {
440
+
441
+ if ((typeof Buffer !== 'undefined') && Buffer.isBuffer && Buffer.isBuffer(file)) {
420
442
  const blob = new Blob([file]);
421
443
  formData.append('files', blob, fileName || 'profile-image.jpg');
422
444
  } else if (file instanceof File) {
423
445
  formData.append('files', file);
424
446
  } else {
425
- throw new Error('In browser environment, file must be a Buffer or File object');
447
+ throw new Error(
448
+ 'In browser environment, file must be a Buffer or File object',
449
+ );
426
450
  }
427
451
 
428
452
  formData.append('classification', classification);
@@ -433,7 +457,12 @@ export class StorageService {
433
457
  headers,
434
458
  };
435
459
 
436
- const result = await this.sdk._fetch('/storage/upload-profile-image', 'POST', params, true);
460
+ const result = await this.sdk._fetch(
461
+ '/storage/upload-profile-image',
462
+ 'POST',
463
+ params,
464
+ true,
465
+ );
437
466
  return result;
438
467
  }
439
468