@unboundcx/sdk 1.0.0 → 1.0.1

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 (3) hide show
  1. package/README.md +50 -40
  2. package/base.js +6 -3
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -20,7 +20,7 @@ The official JavaScript SDK for Unbound's comprehensive communication and AI pla
20
20
  ## Installation
21
21
 
22
22
  ```bash
23
- npm install @unbound/sdk
23
+ npm install @unboundcx/sdk
24
24
  ```
25
25
 
26
26
  ### Optional Dependencies
@@ -40,7 +40,7 @@ npm install mime-types
40
40
  ### Basic Usage
41
41
 
42
42
  ```javascript
43
- import SDK from '@unbound/sdk';
43
+ import SDK from '@unboundcx/sdk';
44
44
 
45
45
  // Initialize the SDK
46
46
  const api = new SDK({
@@ -48,7 +48,7 @@ const api = new SDK({
48
48
  token: 'your-jwt-token'
49
49
  });
50
50
 
51
- // Or using legacy positional parameters (backwards compatible)
51
+ // Or using legacy positional parameters (backwards compatible)
52
52
  const api = new SDK('your-namespace', null, 'your-jwt-token');
53
53
 
54
54
  // Login (gets JWT token)
@@ -72,13 +72,16 @@ const meeting = await api.video.createRoom({
72
72
  ### Client-Side Usage (Browser/Svelte)
73
73
 
74
74
  ```javascript
75
- import SDK from '@unbound/sdk';
75
+ import SDK from '@unboundcx/sdk';
76
76
  import { socketAppStore } from './stores/socket.js';
77
77
 
78
- // Initialize with socket transport for optimal performance
79
- const api = new SDK('your-namespace', null, null, null, 'api.yourdomain.com', socketAppStore);
78
+ // Initialize for browser usage
79
+ const api = new SDK({
80
+ namespace: 'your-namespace',
81
+ socketStore: socketAppStore // Optional: for optimized WebSocket transport
82
+ });
80
83
 
81
- // The SDK will automatically use WebSocket when available, HTTP as fallback
84
+ // The SDK automatically connects to your-namespace.api.unbound.cx
82
85
  const objects = await api.objects.query('contacts', {
83
86
  limit: 10,
84
87
  orderBy: 'createdAt'
@@ -88,19 +91,16 @@ const objects = await api.objects.query('contacts', {
88
91
  ### Server-Side Usage (Node.js)
89
92
 
90
93
  ```javascript
91
- import SDK from '@unbound/sdk';
92
-
93
- // Initialize for server-side usage
94
- const api = new SDK('your-namespace', 'call-id', 'jwt-token', 'request-id');
94
+ import SDK from '@unboundcx/sdk';
95
95
 
96
- // Server-side exclusive: Master authentication
97
- await api.buildMasterAuth({
98
- namespace: 'target-namespace',
99
- accountId: 'account-123',
100
- userId: 'user-456'
96
+ // Initialize for server-side usage
97
+ const api = new SDK({
98
+ namespace: 'your-namespace',
99
+ token: 'jwt-token',
100
+ callId: 'call-id' // Optional: for request tracking
101
101
  });
102
102
 
103
- // Use NATS transport automatically when available
103
+ // Automatically connects to your-namespace.api.unbound.cx
104
104
  const result = await api.objects.create('leads', {
105
105
  name: 'John Doe',
106
106
  email: 'john@example.com',
@@ -116,12 +116,11 @@ The SDK constructor supports both object-based and legacy positional parameters:
116
116
 
117
117
  ```javascript
118
118
  const api = new SDK({
119
- namespace: 'your-namespace', // Required: API namespace
119
+ namespace: 'your-namespace', // Required: Your Unbound namespace
120
120
  token: 'jwt-token', // Optional: JWT authentication token
121
121
  callId: 'call-123', // Optional: Call tracking ID
122
122
  fwRequestId: 'request-456', // Optional: Request forwarding ID
123
- url: 'api.example.com', // Optional: Custom API URL (browser only)
124
- socketStore: socketAppStore // Optional: Socket.io store (Svelte/browser)
123
+ socketStore: socketAppStore // Optional: Socket.io store (browser only)
125
124
  });
126
125
  ```
127
126
 
@@ -132,16 +131,14 @@ const api = new SDK(
132
131
  'your-namespace', // namespace
133
132
  'call-123', // callId
134
133
  'jwt-token', // token
135
- 'request-456', // fwRequestId
136
- 'api.example.com', // url (browser only)
137
- socketAppStore // socketStore (browser only)
134
+ 'request-456' // fwRequestId
138
135
  );
139
136
  ```
140
137
 
141
138
  ### Factory Function
142
139
 
143
140
  ```javascript
144
- import { createSDK } from '@unbound/sdk';
141
+ import { createSDK } from '@unboundcx/sdk';
145
142
 
146
143
  const api = createSDK({
147
144
  namespace: 'your-namespace',
@@ -318,7 +315,7 @@ The SDK automatically optimizes transport based on environment:
318
315
  ### Custom Transports
319
316
 
320
317
  ```javascript
321
- import SDK from '@unbound/sdk';
318
+ import SDK from '@unboundcx/sdk';
322
319
 
323
320
  class CustomTransport {
324
321
  constructor(config) {
@@ -338,47 +335,60 @@ class CustomTransport {
338
335
  }
339
336
  }
340
337
 
341
- const api = new SDK('namespace', null, 'token');
338
+ const api = new SDK({ namespace: 'namespace', token: 'token' });
342
339
  api.addTransport(new CustomTransport({}));
343
340
  ```
344
341
 
345
342
  ## Extensions
346
343
 
347
- ### Internal SDK (Server-side only)
344
+ ### Custom Extensions
348
345
 
349
346
  ```javascript
350
- import SDK from '@unbound/sdk';
347
+ import SDK from '@unboundcx/sdk';
348
+
349
+ const api = new SDK({ namespace: 'namespace' });
351
350
 
352
- const api = new SDK('namespace');
351
+ // Add custom functionality via extensions
352
+ api.extend({
353
+ customMethod: function() {
354
+ return this.objects.query('custom', {});
355
+ }
356
+ });
353
357
 
354
- // Now has access to internal APIs
355
- await api.buildMasterAuth({ accountId: '123', userId: '456' });
356
- await api.internal.sip.router('+1234567890', '+0987654321');
358
+ // Use custom method
359
+ await api.customMethod();
357
360
  ```
358
361
 
359
362
  ## Environment Support
360
363
 
361
364
  ### Node.js
362
365
  ```javascript
363
- import SDK from '@unbound/sdk';
366
+ import SDK from '@unboundcx/sdk';
364
367
 
365
368
  // Automatic environment detection
366
- const api = new SDK(process.env.UNBOUND_NAMESPACE);
369
+ const api = new SDK({ namespace: process.env.UNBOUND_NAMESPACE });
367
370
  ```
368
371
 
369
372
  ### Browser/Webpack
370
373
  ```javascript
371
- import SDK from '@unbound/sdk';
374
+ import SDK from '@unboundcx/sdk';
372
375
 
373
- const api = new SDK('namespace', null, null, null, 'api.yourdomain.com');
376
+ const api = new SDK({
377
+ namespace: 'your-namespace'
378
+ });
379
+ // Automatically connects to your-namespace.api.unbound.cx
374
380
  ```
375
381
 
376
382
  ### Svelte
377
383
  ```javascript
378
- import SDK from '@unbound/sdk';
384
+ import SDK from '@unboundcx/sdk';
379
385
  import { socketAppStore } from '$lib/stores/socket.js';
380
386
 
381
- const api = new SDK('namespace', null, null, null, 'api.yourdomain.com', socketAppStore);
387
+ const api = new SDK({
388
+ namespace: 'your-namespace',
389
+ socketStore: socketAppStore // Enables WebSocket transport
390
+ });
391
+ // Automatically connects to your-namespace.api.unbound.cx
382
392
  ```
383
393
 
384
394
  ## Error Handling
@@ -400,9 +410,9 @@ try {
400
410
  The SDK includes TypeScript definitions:
401
411
 
402
412
  ```typescript
403
- import SDK, { MessagingService, VideoService } from '@unbound/sdk';
413
+ import SDK, { MessagingService, VideoService } from '@unboundcx/sdk';
404
414
 
405
- const api: SDK = new SDK('namespace', null, 'token');
415
+ const api: SDK = new SDK({ namespace: 'namespace', token: 'token' });
406
416
 
407
417
  // Full type safety
408
418
  const sms: any = await api.messaging.sms.send({
package/base.js CHANGED
@@ -36,16 +36,18 @@ export class BaseSDK {
36
36
  }
37
37
 
38
38
  _initializeEnvironment() {
39
+ const defaultDomain = 'api.unbound.cx';
40
+
39
41
  if (typeof window === 'undefined') {
40
42
  // Server-side (Node.js)
41
43
  this.environment = 'node';
42
44
  this.baseURL = `https://${this.namespace ? this.namespace : 'login'}.${
43
- process.env?.API_BASE_URL
45
+ process.env?.API_BASE_URL || defaultDomain
44
46
  }`;
45
47
  } else {
46
48
  // Client-side (browser)
47
49
  this.environment = 'browser';
48
- this.baseUrl = this.baseUrl || process?.env?.API_BASE_URL;
50
+ this.baseUrl = this.baseUrl || process?.env?.API_BASE_URL || defaultDomain;
49
51
  if (this.baseUrl && !this.baseUrl.startsWith('api.')) {
50
52
  this.baseUrl = `api.${this.baseUrl}`;
51
53
  }
@@ -59,10 +61,11 @@ export class BaseSDK {
59
61
 
60
62
  setNamespace(namespace) {
61
63
  this.namespace = namespace;
64
+ const defaultDomain = 'api.unbound.cx';
62
65
 
63
66
  if (this.environment === 'node') {
64
67
  this.baseURL = `https://${this.namespace ? this.namespace : 'login'}.${
65
- process.env?.API_BASE_URL
68
+ process.env?.API_BASE_URL || defaultDomain
66
69
  }`;
67
70
  } else {
68
71
  this.fullUrl = `https://${this.namespace}.${this.baseUrl}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",
@@ -85,4 +85,4 @@
85
85
  "registry": "https://registry.npmjs.org/",
86
86
  "access": "public"
87
87
  }
88
- }
88
+ }