@discomedia/utils 1.0.35 → 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
@@ -774,6 +774,22 @@ function getNYTimeZone(date) {
774
774
  const offset = getNYOffset(date || new Date());
775
775
  return offset === -4 ? '-04:00' : '-05:00';
776
776
  }
777
+ /**
778
+ * Converts any date to the market time zone (America/New_York, Eastern Time).
779
+ * Returns a new Date object representing the same moment in time but adjusted to NY/Eastern timezone.
780
+ * Automatically handles daylight saving time transitions (EST/EDT).
781
+ *
782
+ * @param date - Date object to convert to market time zone
783
+ * @returns Date object in NY/Eastern time zone
784
+ * @example
785
+ * ```typescript
786
+ * const utcDate = new Date('2024-01-15T15:30:00Z'); // 3:30 PM UTC
787
+ * const nyDate = convertDateToMarketTimeZone(utcDate); // 10:30 AM EST (winter) or 11:30 AM EDT (summer)
788
+ * ```
789
+ */
790
+ function convertDateToMarketTimeZone(date) {
791
+ return toNYTime(date);
792
+ }
777
793
  /**
778
794
  * Returns the current market status for a given date.
779
795
  * @param options - { date?: Date }
@@ -2395,7 +2411,7 @@ const safeJSON = (text) => {
2395
2411
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2396
2412
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2397
2413
 
2398
- const VERSION = '5.22.0'; // x-release-please-version
2414
+ const VERSION = '6.1.0'; // x-release-please-version
2399
2415
 
2400
2416
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2401
2417
  const isRunningInBrowser = () => {
@@ -6902,23 +6918,23 @@ class Conversations extends APIResource {
6902
6918
  /**
6903
6919
  * Create a conversation.
6904
6920
  */
6905
- create(body, options) {
6921
+ create(body = {}, options) {
6906
6922
  return this._client.post('/conversations', { body, ...options });
6907
6923
  }
6908
6924
  /**
6909
- * Get a conversation with the given ID.
6925
+ * Get a conversation
6910
6926
  */
6911
6927
  retrieve(conversationID, options) {
6912
6928
  return this._client.get(path `/conversations/${conversationID}`, options);
6913
6929
  }
6914
6930
  /**
6915
- * Update a conversation's metadata with the given ID.
6931
+ * Update a conversation
6916
6932
  */
6917
6933
  update(conversationID, body, options) {
6918
6934
  return this._client.post(path `/conversations/${conversationID}`, { body, ...options });
6919
6935
  }
6920
6936
  /**
6921
- * Delete a conversation with the given ID.
6937
+ * Delete a conversation. Items in the conversation will not be deleted.
6922
6938
  */
6923
6939
  delete(conversationID, options) {
6924
6940
  return this._client.delete(path `/conversations/${conversationID}`, options);
@@ -7513,10 +7529,84 @@ class Moderations extends APIResource {
7513
7529
  }
7514
7530
  }
7515
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
+
7516
7600
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
7517
7601
  class ClientSecrets extends APIResource {
7518
7602
  /**
7519
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
+ * ```
7520
7610
  */
7521
7611
  create(body, options) {
7522
7612
  return this._client.post('/realtime/client_secrets', { body, ...options });
@@ -7528,9 +7618,11 @@ class Realtime extends APIResource {
7528
7618
  constructor() {
7529
7619
  super(...arguments);
7530
7620
  this.clientSecrets = new ClientSecrets(this._client);
7621
+ this.calls = new Calls(this._client);
7531
7622
  }
7532
7623
  }
7533
7624
  Realtime.ClientSecrets = ClientSecrets;
7625
+ Realtime.Calls = Calls;
7534
7626
 
7535
7627
  function maybeParseResponse(response, params) {
7536
7628
  if (!params || !hasAutoParseableInput(params)) {
@@ -15845,7 +15937,7 @@ var config = {};
15845
15937
 
15846
15938
  var main = {exports: {}};
15847
15939
 
15848
- var version = "17.2.2";
15940
+ var version = "17.2.3";
15849
15941
  var require$$4 = {
15850
15942
  version: version};
15851
15943
 
@@ -15867,9 +15959,12 @@ function requireMain () {
15867
15959
  '🔐 encrypt with Dotenvx: https://dotenvx.com',
15868
15960
  '🔐 prevent committing .env to code: https://dotenvx.com/precommit',
15869
15961
  '🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
15870
- '📡 observe env with Radar: https://dotenvx.com/radar',
15871
- '📡 auto-backup env with Radar: https://dotenvx.com/radar',
15872
- '📡 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',
15873
15968
  '🛠️ run anywhere with `dotenvx run -- yourcommand`',
15874
15969
  '⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
15875
15970
  '⚙️ enable debug logging with { debug: true }',
@@ -17569,6 +17664,7 @@ class AlpacaTradingAPI {
17569
17664
  reconnectTimeout = null;
17570
17665
  messageHandlers = new Map();
17571
17666
  debugLogging = false;
17667
+ manualDisconnect = false;
17572
17668
  /**
17573
17669
  * Constructor for AlpacaTradingAPI
17574
17670
  * @param credentials - Alpaca credentials,
@@ -17658,6 +17754,8 @@ class AlpacaTradingAPI {
17658
17754
  }
17659
17755
  }
17660
17756
  connectWebsocket() {
17757
+ // Reset manual disconnect flag to allow reconnection logic
17758
+ this.manualDisconnect = false;
17661
17759
  if (this.connecting) {
17662
17760
  this.log('Connection attempt skipped - already connecting');
17663
17761
  return;
@@ -17708,13 +17806,52 @@ class AlpacaTradingAPI {
17708
17806
  clearTimeout(this.reconnectTimeout);
17709
17807
  this.reconnectTimeout = null;
17710
17808
  }
17711
- // Schedule reconnection
17712
- this.reconnectTimeout = setTimeout(() => {
17713
- this.log('Attempting to reconnect...');
17714
- this.connectWebsocket();
17715
- }, 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
+ }
17716
17816
  });
17717
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
+ }
17718
17855
  async authenticate() {
17719
17856
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
17720
17857
  throw new Error('WebSocket not ready for authentication');
@@ -18981,6 +19118,7 @@ const disco = {
18981
19118
  calculateFibonacciLevels: calculateFibonacciLevels,
18982
19119
  },
18983
19120
  time: {
19121
+ convertDateToMarketTimeZone: convertDateToMarketTimeZone,
18984
19122
  getStartAndEndDates: getStartAndEndDates,
18985
19123
  getMarketOpenClose: getMarketOpenClose,
18986
19124
  getLastFullTradingDate: getLastFullTradingDate,