@unboundcx/sdk 1.0.8 → 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.
Files changed (2) hide show
  1. package/base.js +27 -3
  2. package/package.json +1 -1
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.8",
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",