@unboundcx/sdk 2.8.10 → 2.8.11

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 +20 -9
  2. package/package.json +1 -1
package/base.js CHANGED
@@ -24,11 +24,12 @@ export class BaseSDK {
24
24
  this.fwRequestId = arguments[3];
25
25
  } else {
26
26
  // New object-based parameters
27
- const { namespace, callId, token, fwRequestId } = options;
27
+ const { namespace, callId, token, fwRequestId, baseURL } = options;
28
28
  this.namespace = namespace || process?.env?.namespace;
29
29
  this.callId = callId;
30
30
  this.token = token;
31
31
  this.fwRequestId = fwRequestId;
32
+ this._constructorBaseURL = baseURL;
32
33
  }
33
34
  this.baseURL;
34
35
  this.transports = new Map();
@@ -42,16 +43,24 @@ export class BaseSDK {
42
43
  if (typeof window === 'undefined') {
43
44
  // Server-side (Node.js)
44
45
  this.environment = 'node';
45
- this.baseURL = `https://${this.namespace ? this.namespace : 'login'}.${
46
+ this.baseURL = this._constructorBaseURL || `https://${this.namespace ? this.namespace : 'login'}.${
46
47
  process.env?.API_BASE_URL || defaultDomain
47
48
  }`;
48
49
  } else {
49
50
  // Client-side (browser)
50
51
  this.environment = 'browser';
51
- this.baseUrl =
52
- this.baseUrl || process?.env?.API_BASE_URL || defaultDomain;
53
- if (this.baseUrl && !this.baseUrl.startsWith('api.')) {
54
- this.baseUrl = `api.${this.baseUrl}`;
52
+ if (this._constructorBaseURL) {
53
+ // Use the baseURL passed to the constructor
54
+ this.baseURL = this._constructorBaseURL;
55
+ // Extract baseUrl for setNamespace compatibility
56
+ const url = new URL(this._constructorBaseURL);
57
+ this.baseUrl = url.hostname.replace(/^[^.]+\./, '');
58
+ } else {
59
+ this.baseUrl =
60
+ this.baseUrl || process?.env?.API_BASE_URL || defaultDomain;
61
+ if (this.baseUrl && !this.baseUrl.startsWith('api.')) {
62
+ this.baseUrl = `api.${this.baseUrl}`;
63
+ }
55
64
  }
56
65
  this.setNamespace(this.namespace);
57
66
  }
@@ -66,9 +75,11 @@ export class BaseSDK {
66
75
  const defaultDomain = 'api.unbound.cx';
67
76
 
68
77
  if (this.environment === 'node') {
69
- this.baseURL = `https://${this.namespace ? this.namespace : 'login'}.${
70
- process.env?.API_BASE_URL || defaultDomain
71
- }`;
78
+ if (!this._constructorBaseURL) {
79
+ this.baseURL = `https://${this.namespace ? this.namespace : 'login'}.${
80
+ process.env?.API_BASE_URL || defaultDomain
81
+ }`;
82
+ }
72
83
  } else {
73
84
  this.fullUrl = `https://${this.namespace}.${this.baseUrl}`;
74
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "2.8.10",
3
+ "version": "2.8.11",
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",