@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.
package/dist/index.cjs CHANGED
@@ -2411,7 +2411,7 @@ const safeJSON = (text) => {
2411
2411
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2412
2412
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2413
2413
 
2414
- const VERSION = '5.23.1'; // x-release-please-version
2414
+ const VERSION = '6.1.0'; // x-release-please-version
2415
2415
 
2416
2416
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2417
2417
  const isRunningInBrowser = () => {
@@ -7529,10 +7529,84 @@ class Moderations extends APIResource {
7529
7529
  }
7530
7530
  }
7531
7531
 
7532
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
7533
+ class Calls extends APIResource {
7534
+ /**
7535
+ * Accept an incoming SIP call and configure the realtime session that will handle
7536
+ * it.
7537
+ *
7538
+ * @example
7539
+ * ```ts
7540
+ * await client.realtime.calls.accept('call_id', {
7541
+ * type: 'realtime',
7542
+ * });
7543
+ * ```
7544
+ */
7545
+ accept(callID, body, options) {
7546
+ return this._client.post(path `/realtime/calls/${callID}/accept`, {
7547
+ body,
7548
+ ...options,
7549
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
7550
+ });
7551
+ }
7552
+ /**
7553
+ * End an active Realtime API call, whether it was initiated over SIP or WebRTC.
7554
+ *
7555
+ * @example
7556
+ * ```ts
7557
+ * await client.realtime.calls.hangup('call_id');
7558
+ * ```
7559
+ */
7560
+ hangup(callID, options) {
7561
+ return this._client.post(path `/realtime/calls/${callID}/hangup`, {
7562
+ ...options,
7563
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
7564
+ });
7565
+ }
7566
+ /**
7567
+ * Transfer an active SIP call to a new destination using the SIP REFER verb.
7568
+ *
7569
+ * @example
7570
+ * ```ts
7571
+ * await client.realtime.calls.refer('call_id', {
7572
+ * target_uri: 'tel:+14155550123',
7573
+ * });
7574
+ * ```
7575
+ */
7576
+ refer(callID, body, options) {
7577
+ return this._client.post(path `/realtime/calls/${callID}/refer`, {
7578
+ body,
7579
+ ...options,
7580
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
7581
+ });
7582
+ }
7583
+ /**
7584
+ * Decline an incoming SIP call by returning a SIP status code to the caller.
7585
+ *
7586
+ * @example
7587
+ * ```ts
7588
+ * await client.realtime.calls.reject('call_id');
7589
+ * ```
7590
+ */
7591
+ reject(callID, body = {}, options) {
7592
+ return this._client.post(path `/realtime/calls/${callID}/reject`, {
7593
+ body,
7594
+ ...options,
7595
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
7596
+ });
7597
+ }
7598
+ }
7599
+
7532
7600
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
7533
7601
  class ClientSecrets extends APIResource {
7534
7602
  /**
7535
7603
  * Create a Realtime client secret with an associated session configuration.
7604
+ *
7605
+ * @example
7606
+ * ```ts
7607
+ * const clientSecret =
7608
+ * await client.realtime.clientSecrets.create();
7609
+ * ```
7536
7610
  */
7537
7611
  create(body, options) {
7538
7612
  return this._client.post('/realtime/client_secrets', { body, ...options });
@@ -7544,9 +7618,11 @@ class Realtime extends APIResource {
7544
7618
  constructor() {
7545
7619
  super(...arguments);
7546
7620
  this.clientSecrets = new ClientSecrets(this._client);
7621
+ this.calls = new Calls(this._client);
7547
7622
  }
7548
7623
  }
7549
7624
  Realtime.ClientSecrets = ClientSecrets;
7625
+ Realtime.Calls = Calls;
7550
7626
 
7551
7627
  function maybeParseResponse(response, params) {
7552
7628
  if (!params || !hasAutoParseableInput(params)) {
@@ -15861,7 +15937,7 @@ var config = {};
15861
15937
 
15862
15938
  var main = {exports: {}};
15863
15939
 
15864
- var version = "17.2.2";
15940
+ var version = "17.2.3";
15865
15941
  var require$$4 = {
15866
15942
  version: version};
15867
15943
 
@@ -15883,9 +15959,12 @@ function requireMain () {
15883
15959
  '🔐 encrypt with Dotenvx: https://dotenvx.com',
15884
15960
  '🔐 prevent committing .env to code: https://dotenvx.com/precommit',
15885
15961
  '🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
15886
- '📡 observe env with Radar: https://dotenvx.com/radar',
15887
- '📡 auto-backup env with Radar: https://dotenvx.com/radar',
15888
- '📡 version env with Radar: https://dotenvx.com/radar',
15962
+ '📡 add observability to secrets: https://dotenvx.com/ops',
15963
+ '👥 sync secrets across teammates & machines: https://dotenvx.com/ops',
15964
+ '🗂️ backup and recover secrets: https://dotenvx.com/ops',
15965
+ '✅ audit secrets and track compliance: https://dotenvx.com/ops',
15966
+ '🔄 add secrets lifecycle management: https://dotenvx.com/ops',
15967
+ '🔑 add access controls to secrets: https://dotenvx.com/ops',
15889
15968
  '🛠️ run anywhere with `dotenvx run -- yourcommand`',
15890
15969
  '⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
15891
15970
  '⚙️ enable debug logging with { debug: true }',
@@ -17585,6 +17664,7 @@ class AlpacaTradingAPI {
17585
17664
  reconnectTimeout = null;
17586
17665
  messageHandlers = new Map();
17587
17666
  debugLogging = false;
17667
+ manualDisconnect = false;
17588
17668
  /**
17589
17669
  * Constructor for AlpacaTradingAPI
17590
17670
  * @param credentials - Alpaca credentials,
@@ -17674,6 +17754,8 @@ class AlpacaTradingAPI {
17674
17754
  }
17675
17755
  }
17676
17756
  connectWebsocket() {
17757
+ // Reset manual disconnect flag to allow reconnection logic
17758
+ this.manualDisconnect = false;
17677
17759
  if (this.connecting) {
17678
17760
  this.log('Connection attempt skipped - already connecting');
17679
17761
  return;
@@ -17724,13 +17806,52 @@ class AlpacaTradingAPI {
17724
17806
  clearTimeout(this.reconnectTimeout);
17725
17807
  this.reconnectTimeout = null;
17726
17808
  }
17727
- // Schedule reconnection
17728
- this.reconnectTimeout = setTimeout(() => {
17729
- this.log('Attempting to reconnect...');
17730
- this.connectWebsocket();
17731
- }, this.reconnectDelay);
17809
+ // Schedule reconnection unless this was a manual disconnect
17810
+ if (!this.manualDisconnect) {
17811
+ this.reconnectTimeout = setTimeout(() => {
17812
+ this.log('Attempting to reconnect...');
17813
+ this.connectWebsocket();
17814
+ }, this.reconnectDelay);
17815
+ }
17732
17816
  });
17733
17817
  }
17818
+ /**
17819
+ * Cleanly disconnect from the WebSocket and stop auto-reconnects
17820
+ */
17821
+ disconnect() {
17822
+ // Prevent auto-reconnect scheduling
17823
+ this.manualDisconnect = true;
17824
+ // Clear any scheduled reconnect
17825
+ if (this.reconnectTimeout) {
17826
+ clearTimeout(this.reconnectTimeout);
17827
+ this.reconnectTimeout = null;
17828
+ }
17829
+ if (this.ws) {
17830
+ this.log('Disconnecting WebSocket...');
17831
+ // Remove listeners first to avoid duplicate handlers after reconnects
17832
+ this.ws.removeAllListeners();
17833
+ try {
17834
+ // Attempt graceful close
17835
+ if (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING) {
17836
+ this.ws.close(1000, 'Client disconnect');
17837
+ }
17838
+ else {
17839
+ this.ws.terminate();
17840
+ }
17841
+ }
17842
+ catch {
17843
+ // Fallback terminate on any error
17844
+ try {
17845
+ this.ws.terminate();
17846
+ }
17847
+ catch { /* no-op */ }
17848
+ }
17849
+ this.ws = null;
17850
+ }
17851
+ this.authenticated = false;
17852
+ this.connecting = false;
17853
+ this.log('WebSocket disconnected');
17854
+ }
17734
17855
  async authenticate() {
17735
17856
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
17736
17857
  throw new Error('WebSocket not ready for authentication');