@unboundcx/sdk 4.13.93 → 4.13.94

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
@@ -16,6 +16,17 @@
16
16
  const requestBySdk = new WeakMap();
17
17
  const SDK_REQUEST = Symbol.for('unbound.sdk.request');
18
18
 
19
+ /**
20
+ * Safely read a process.env var. `process` is an undeclared global in a
21
+ * browser/Vite bundle -- `process?.env?.X` does NOT protect against that
22
+ * (optional chaining only guards property access, not a bare identifier
23
+ * reference), so a browser bundle throws `ReferenceError: process is not
24
+ * defined` the moment `process` is referenced at all. Gate on
25
+ * `typeof process !== 'undefined'` first.
26
+ */
27
+ export const env = (key) =>
28
+ typeof process !== 'undefined' && process.env ? process.env[key] : undefined;
29
+
19
30
  /**
20
31
  * Service-internal request. Not part of the public SDK surface.
21
32
  * Named SDK methods call this; app code must not. Optional transports
@@ -43,14 +54,14 @@ export class BaseSDK {
43
54
  // Support both object and legacy positional parameters for backwards compatibility
44
55
  if (typeof options === 'string') {
45
56
  // Legacy positional parameters: (namespace, callId, token, fwRequestId)
46
- this.namespace = options || process?.env?.namespace;
57
+ this.namespace = options || env('namespace');
47
58
  this.callId = arguments[1];
48
59
  this.token = arguments[2];
49
60
  this.fwRequestId = arguments[3];
50
61
  } else {
51
62
  // New object-based parameters
52
63
  const { namespace, callId, token, fwRequestId, baseURL } = options;
53
- this.namespace = namespace || process?.env?.namespace;
64
+ this.namespace = namespace || env('namespace');
54
65
  this.callId = callId;
55
66
  this.token = token;
56
67
  this.fwRequestId = fwRequestId;
@@ -78,7 +89,7 @@ export class BaseSDK {
78
89
  // Server-side (Node.js)
79
90
  this.environment = 'node';
80
91
  this.baseURL = this._constructorBaseURL || `https://${this.namespace ? this.namespace : 'login'}.${
81
- process.env?.API_BASE_URL || defaultDomain
92
+ env('API_BASE_URL') || defaultDomain
82
93
  }`;
83
94
  } else {
84
95
  // Client-side (browser)
@@ -91,7 +102,7 @@ export class BaseSDK {
91
102
  this.baseUrl = url.hostname.replace(/^[^.]+\./, '');
92
103
  } else {
93
104
  this.baseUrl =
94
- this.baseUrl || process?.env?.API_BASE_URL || defaultDomain;
105
+ this.baseUrl || env('API_BASE_URL') || defaultDomain;
95
106
  if (this.baseUrl && !this.baseUrl.startsWith('api.')) {
96
107
  this.baseUrl = `api.${this.baseUrl}`;
97
108
  }
@@ -111,7 +122,7 @@ export class BaseSDK {
111
122
  if (this.environment === 'node') {
112
123
  if (!this._constructorBaseURL) {
113
124
  this.baseURL = `https://${this.namespace ? this.namespace : 'login'}.${
114
- process.env?.API_BASE_URL || defaultDomain
125
+ env('API_BASE_URL') || defaultDomain
115
126
  }`;
116
127
  }
117
128
  } else if (this._constructorBaseURL && !this.namespace) {
@@ -296,9 +307,9 @@ export class BaseSDK {
296
307
  }
297
308
  } else {
298
309
  // No transport available, fallback to HTTP
299
- if (forceFetch && process.env.AUTH_V3_TOKEN_TYPE_OVERRIDE) {
310
+ if (forceFetch && env('AUTH_V3_TOKEN_TYPE_OVERRIDE')) {
300
311
  params.headers['x-token-type-override'] =
301
- process.env.AUTH_V3_TOKEN_TYPE_OVERRIDE;
312
+ env('AUTH_V3_TOKEN_TYPE_OVERRIDE');
302
313
  }
303
314
  return this._httpRequest(
304
315
  endpoint,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.93",
3
+ "version": "4.13.94",
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",
@@ -1,4 +1,4 @@
1
- import { internalRequest } from '../base.js';
1
+ import { internalRequest, env } from '../base.js';
2
2
  export class StorageService {
3
3
  constructor(sdk) {
4
4
  this.sdk = sdk;
@@ -314,13 +314,12 @@ export class StorageService {
314
314
  headers = result.headers;
315
315
  }
316
316
 
317
- if (process?.env?.AUTH_V3_TOKEN_TYPE_OVERRIDE) {
318
- headers['x-token-type-override'] =
319
- process.env.AUTH_V3_TOKEN_TYPE_OVERRIDE;
317
+ if (env('AUTH_V3_TOKEN_TYPE_OVERRIDE')) {
318
+ headers['x-token-type-override'] = env('AUTH_V3_TOKEN_TYPE_OVERRIDE');
320
319
  }
321
320
 
322
- if (skipClamscan && process?.env?.CLAMSCAN_OVERRIDE_KEY) {
323
- headers['x-clamscan-override-key'] = process.env.CLAMSCAN_OVERRIDE_KEY;
321
+ if (skipClamscan && env('CLAMSCAN_OVERRIDE_KEY')) {
322
+ headers['x-clamscan-override-key'] = env('CLAMSCAN_OVERRIDE_KEY');
324
323
  }
325
324
 
326
325
  const params = {
@@ -408,16 +407,16 @@ export class StorageService {
408
407
  }
409
408
 
410
409
  // Add environment variable override headers
411
- if (process?.env?.AUTH_V3_TOKEN_TYPE_OVERRIDE) {
410
+ if (env('AUTH_V3_TOKEN_TYPE_OVERRIDE')) {
412
411
  xhr.setRequestHeader(
413
412
  'x-token-type-override',
414
- process.env.AUTH_V3_TOKEN_TYPE_OVERRIDE,
413
+ env('AUTH_V3_TOKEN_TYPE_OVERRIDE'),
415
414
  );
416
415
  }
417
- if (skipClamscan && process?.env?.CLAMSCAN_OVERRIDE_KEY) {
416
+ if (skipClamscan && env('CLAMSCAN_OVERRIDE_KEY')) {
418
417
  xhr.setRequestHeader(
419
418
  'x-clamscan-override-key',
420
- process.env.CLAMSCAN_OVERRIDE_KEY,
419
+ env('CLAMSCAN_OVERRIDE_KEY'),
421
420
  );
422
421
  }
423
422
 
@@ -656,8 +655,8 @@ Response:
656
655
  if (metadata) formData.append('metadata', JSON.stringify(metadata));
657
656
  }
658
657
 
659
- if (_options?.skipScan && process?.env?.CLAMSCAN_OVERRIDE_KEY) {
660
- headers['x-clamscan-override-key'] = process.env.CLAMSCAN_OVERRIDE_KEY;
658
+ if (_options?.skipScan && env('CLAMSCAN_OVERRIDE_KEY')) {
659
+ headers['x-clamscan-override-key'] = env('CLAMSCAN_OVERRIDE_KEY');
661
660
  }
662
661
 
663
662
  const params = {