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