@unboundcx/sdk 1.0.7 → 1.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/base.js CHANGED
@@ -32,6 +32,7 @@ export class BaseSDK {
32
32
  }
33
33
 
34
34
  this.transports = new Map();
35
+ this.debugMode = false;
35
36
  this._initializeEnvironment();
36
37
  }
37
38
 
@@ -73,6 +74,11 @@ export class BaseSDK {
73
74
  }
74
75
  }
75
76
 
77
+ debug(enabled = true) {
78
+ this.debugMode = enabled;
79
+ return this;
80
+ }
81
+
76
82
  addTransport(transport) {
77
83
  if (!transport || typeof transport.request !== 'function') {
78
84
  throw new Error('Transport must have a request method');
@@ -172,8 +178,19 @@ export class BaseSDK {
172
178
  fwRequestId: this.fwRequestId,
173
179
  baseURL: this.baseURL || this.fullUrl,
174
180
  });
181
+
182
+ // Debug logging for transport plugins
183
+ if (this.debugMode) {
184
+ const status = result?.status || 200;
185
+ console.log(`API :: ${transport.name} :: ${method.toUpperCase()} :: ${endpoint} :: ${status}`);
186
+ }
187
+
175
188
  return result;
176
189
  } catch (err) {
190
+ // Debug logging for transport plugin failures
191
+ if (this.debugMode) {
192
+ console.log(`API :: ${transport.name} :: ${method.toUpperCase()} :: ${endpoint} :: ERROR :: ${err.message}`);
193
+ }
177
194
  console.warn(
178
195
  `Transport ${transport.name} failed, falling back to HTTP:`,
179
196
  err.message,
@@ -256,6 +273,11 @@ export class BaseSDK {
256
273
  responseHeaders?.['x-request-id'];
257
274
 
258
275
  if (!response.ok) {
276
+ // Debug logging for HTTP errors
277
+ if (this.debugMode) {
278
+ console.log(`API :: https :: ${method.toUpperCase()} :: ${endpoint} :: ${response?.status}`);
279
+ }
280
+
259
281
  throw {
260
282
  name: `API :: Error :: https :: ${method} :: ${endpoint} :: ${responseRequestId} :: ${response?.status} :: ${response?.statusText}`,
261
283
  message: bodyResponse?.message || `API Error occured.`,
@@ -266,9 +288,11 @@ export class BaseSDK {
266
288
  };
267
289
  }
268
290
 
269
- console.log(
270
- `API :: https :: ${method} :: ${endpoint} :: ${responseRequestId}`,
271
- );
291
+ // Debug logging for successful HTTP requests
292
+ if (this.debugMode) {
293
+ console.log(`API :: https :: ${method.toUpperCase()} :: ${endpoint} :: ${response?.status}`);
294
+ }
295
+
272
296
  return bodyResponse;
273
297
  }
274
298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
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) {
@@ -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
- formData = Buffer.concat([
416
- headerBuffer,
417
- fileBuffer,
418
- fieldsBuffer,
419
- endBoundary,
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) {