@discomedia/utils 1.0.36 → 1.0.37

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.
@@ -267,7 +267,7 @@ const safeJSON = (text) => {
267
267
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
268
268
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
269
269
 
270
- const VERSION = '5.23.1'; // x-release-please-version
270
+ const VERSION = '6.1.0'; // x-release-please-version
271
271
 
272
272
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
273
273
  const isRunningInBrowser = () => {
@@ -5385,10 +5385,84 @@ class Moderations extends APIResource {
5385
5385
  }
5386
5386
  }
5387
5387
 
5388
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5389
+ class Calls extends APIResource {
5390
+ /**
5391
+ * Accept an incoming SIP call and configure the realtime session that will handle
5392
+ * it.
5393
+ *
5394
+ * @example
5395
+ * ```ts
5396
+ * await client.realtime.calls.accept('call_id', {
5397
+ * type: 'realtime',
5398
+ * });
5399
+ * ```
5400
+ */
5401
+ accept(callID, body, options) {
5402
+ return this._client.post(path `/realtime/calls/${callID}/accept`, {
5403
+ body,
5404
+ ...options,
5405
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5406
+ });
5407
+ }
5408
+ /**
5409
+ * End an active Realtime API call, whether it was initiated over SIP or WebRTC.
5410
+ *
5411
+ * @example
5412
+ * ```ts
5413
+ * await client.realtime.calls.hangup('call_id');
5414
+ * ```
5415
+ */
5416
+ hangup(callID, options) {
5417
+ return this._client.post(path `/realtime/calls/${callID}/hangup`, {
5418
+ ...options,
5419
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5420
+ });
5421
+ }
5422
+ /**
5423
+ * Transfer an active SIP call to a new destination using the SIP REFER verb.
5424
+ *
5425
+ * @example
5426
+ * ```ts
5427
+ * await client.realtime.calls.refer('call_id', {
5428
+ * target_uri: 'tel:+14155550123',
5429
+ * });
5430
+ * ```
5431
+ */
5432
+ refer(callID, body, options) {
5433
+ return this._client.post(path `/realtime/calls/${callID}/refer`, {
5434
+ body,
5435
+ ...options,
5436
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5437
+ });
5438
+ }
5439
+ /**
5440
+ * Decline an incoming SIP call by returning a SIP status code to the caller.
5441
+ *
5442
+ * @example
5443
+ * ```ts
5444
+ * await client.realtime.calls.reject('call_id');
5445
+ * ```
5446
+ */
5447
+ reject(callID, body = {}, options) {
5448
+ return this._client.post(path `/realtime/calls/${callID}/reject`, {
5449
+ body,
5450
+ ...options,
5451
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5452
+ });
5453
+ }
5454
+ }
5455
+
5388
5456
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5389
5457
  class ClientSecrets extends APIResource {
5390
5458
  /**
5391
5459
  * Create a Realtime client secret with an associated session configuration.
5460
+ *
5461
+ * @example
5462
+ * ```ts
5463
+ * const clientSecret =
5464
+ * await client.realtime.clientSecrets.create();
5465
+ * ```
5392
5466
  */
5393
5467
  create(body, options) {
5394
5468
  return this._client.post('/realtime/client_secrets', { body, ...options });
@@ -5400,9 +5474,11 @@ class Realtime extends APIResource {
5400
5474
  constructor() {
5401
5475
  super(...arguments);
5402
5476
  this.clientSecrets = new ClientSecrets(this._client);
5477
+ this.calls = new Calls(this._client);
5403
5478
  }
5404
5479
  }
5405
5480
  Realtime.ClientSecrets = ClientSecrets;
5481
+ Realtime.Calls = Calls;
5406
5482
 
5407
5483
  function maybeParseResponse(response, params) {
5408
5484
  if (!params || !hasAutoParseableInput(params)) {
@@ -13086,7 +13162,7 @@ var config = {};
13086
13162
 
13087
13163
  var main = {exports: {}};
13088
13164
 
13089
- var version = "17.2.2";
13165
+ var version = "17.2.3";
13090
13166
  var require$$4 = {
13091
13167
  version: version};
13092
13168
 
@@ -13108,9 +13184,12 @@ function requireMain () {
13108
13184
  '🔐 encrypt with Dotenvx: https://dotenvx.com',
13109
13185
  '🔐 prevent committing .env to code: https://dotenvx.com/precommit',
13110
13186
  '🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
13111
- '📡 observe env with Radar: https://dotenvx.com/radar',
13112
- '📡 auto-backup env with Radar: https://dotenvx.com/radar',
13113
- '📡 version env with Radar: https://dotenvx.com/radar',
13187
+ '📡 add observability to secrets: https://dotenvx.com/ops',
13188
+ '👥 sync secrets across teammates & machines: https://dotenvx.com/ops',
13189
+ '🗂️ backup and recover secrets: https://dotenvx.com/ops',
13190
+ '✅ audit secrets and track compliance: https://dotenvx.com/ops',
13191
+ '🔄 add secrets lifecycle management: https://dotenvx.com/ops',
13192
+ '🔑 add access controls to secrets: https://dotenvx.com/ops',
13114
13193
  '🛠️ run anywhere with `dotenvx run -- yourcommand`',
13115
13194
  '⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
13116
13195
  '⚙️ enable debug logging with { debug: true }',
@@ -15149,6 +15228,7 @@ class AlpacaTradingAPI {
15149
15228
  reconnectTimeout = null;
15150
15229
  messageHandlers = new Map();
15151
15230
  debugLogging = false;
15231
+ manualDisconnect = false;
15152
15232
  /**
15153
15233
  * Constructor for AlpacaTradingAPI
15154
15234
  * @param credentials - Alpaca credentials,
@@ -15238,6 +15318,8 @@ class AlpacaTradingAPI {
15238
15318
  }
15239
15319
  }
15240
15320
  connectWebsocket() {
15321
+ // Reset manual disconnect flag to allow reconnection logic
15322
+ this.manualDisconnect = false;
15241
15323
  if (this.connecting) {
15242
15324
  this.log('Connection attempt skipped - already connecting');
15243
15325
  return;
@@ -15288,13 +15370,52 @@ class AlpacaTradingAPI {
15288
15370
  clearTimeout(this.reconnectTimeout);
15289
15371
  this.reconnectTimeout = null;
15290
15372
  }
15291
- // Schedule reconnection
15292
- this.reconnectTimeout = setTimeout(() => {
15293
- this.log('Attempting to reconnect...');
15294
- this.connectWebsocket();
15295
- }, this.reconnectDelay);
15373
+ // Schedule reconnection unless this was a manual disconnect
15374
+ if (!this.manualDisconnect) {
15375
+ this.reconnectTimeout = setTimeout(() => {
15376
+ this.log('Attempting to reconnect...');
15377
+ this.connectWebsocket();
15378
+ }, this.reconnectDelay);
15379
+ }
15296
15380
  });
15297
15381
  }
15382
+ /**
15383
+ * Cleanly disconnect from the WebSocket and stop auto-reconnects
15384
+ */
15385
+ disconnect() {
15386
+ // Prevent auto-reconnect scheduling
15387
+ this.manualDisconnect = true;
15388
+ // Clear any scheduled reconnect
15389
+ if (this.reconnectTimeout) {
15390
+ clearTimeout(this.reconnectTimeout);
15391
+ this.reconnectTimeout = null;
15392
+ }
15393
+ if (this.ws) {
15394
+ this.log('Disconnecting WebSocket...');
15395
+ // Remove listeners first to avoid duplicate handlers after reconnects
15396
+ this.ws.removeAllListeners();
15397
+ try {
15398
+ // Attempt graceful close
15399
+ if (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING) {
15400
+ this.ws.close(1000, 'Client disconnect');
15401
+ }
15402
+ else {
15403
+ this.ws.terminate();
15404
+ }
15405
+ }
15406
+ catch {
15407
+ // Fallback terminate on any error
15408
+ try {
15409
+ this.ws.terminate();
15410
+ }
15411
+ catch { /* no-op */ }
15412
+ }
15413
+ this.ws = null;
15414
+ }
15415
+ this.authenticated = false;
15416
+ this.connecting = false;
15417
+ this.log('WebSocket disconnected');
15418
+ }
15298
15419
  async authenticate() {
15299
15420
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
15300
15421
  throw new Error('WebSocket not ready for authentication');