@discomedia/utils 1.0.40 → 1.0.42

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
@@ -1504,8 +1504,8 @@ function pLimit(concurrency) {
1504
1504
  },
1505
1505
  },
1506
1506
  map: {
1507
- async value(array, function_) {
1508
- const promises = array.map((value, index) => this(function_, value, index));
1507
+ async value(iterable, function_) {
1508
+ const promises = Array.from(iterable, (value, index) => this(function_, value, index));
1509
1509
  return Promise.all(promises);
1510
1510
  },
1511
1511
  },
@@ -2451,7 +2451,7 @@ const safeJSON = (text) => {
2451
2451
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2452
2452
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2453
2453
 
2454
- const VERSION = '6.2.0'; // x-release-please-version
2454
+ const VERSION = '6.5.0'; // x-release-please-version
2455
2455
 
2456
2456
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2457
2457
  const isRunningInBrowser = () => {
@@ -6006,19 +6006,6 @@ class ChatKit extends APIResource {
6006
6006
  this.sessions = new Sessions(this._client);
6007
6007
  this.threads = new Threads$1(this._client);
6008
6008
  }
6009
- /**
6010
- * Upload a ChatKit file
6011
- *
6012
- * @example
6013
- * ```ts
6014
- * const response = await client.beta.chatkit.uploadFile({
6015
- * file: fs.createReadStream('path/to/file'),
6016
- * });
6017
- * ```
6018
- */
6019
- uploadFile(body, options) {
6020
- return this._client.post('/chatkit/files', maybeMultipartFormRequestOptions({ body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) }, this._client));
6021
- }
6022
6009
  }
6023
6010
  ChatKit.Sessions = Sessions;
6024
6011
  ChatKit.Threads = Threads$1;
@@ -7340,7 +7327,7 @@ let Files$1 = class Files extends APIResource {
7340
7327
  return this._client.getAPIList('/files', (CursorPage), { query, ...options });
7341
7328
  }
7342
7329
  /**
7343
- * Delete a file.
7330
+ * Delete a file and remove it from all vector stores.
7344
7331
  */
7345
7332
  delete(fileID, options) {
7346
7333
  return this._client.delete(path `/files/${fileID}`, options);
@@ -16710,7 +16697,11 @@ function requireConfig () {
16710
16697
 
16711
16698
  requireConfig();
16712
16699
 
16700
+ const DEBUG_LOGGING = process.env['DEBUG'] === 'true' || false;
16713
16701
  const log = (message, options = { type: 'info' }) => {
16702
+ if (!DEBUG_LOGGING && options.type === 'debug') {
16703
+ return;
16704
+ }
16714
16705
  log$1(message, { ...options, source: 'AlpacaMarketDataAPI' });
16715
16706
  };
16716
16707
  // Default settings for market data API
@@ -16800,7 +16791,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16800
16791
  this.optionWs = ws;
16801
16792
  }
16802
16793
  ws.on('open', () => {
16803
- log(`${streamType} stream connected`, { type: 'info' });
16794
+ log(`${streamType} stream connected`);
16804
16795
  const authMessage = {
16805
16796
  action: 'auth',
16806
16797
  key: process.env.ALPACA_API_KEY,
@@ -16813,7 +16804,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16813
16804
  const messages = JSON.parse(data.toString());
16814
16805
  for (const message of messages) {
16815
16806
  if (message.T === 'success' && message.msg === 'authenticated') {
16816
- log(`${streamType} stream authenticated`, { type: 'info' });
16807
+ log(`${streamType} stream authenticated`);
16817
16808
  this.sendSubscription(streamType);
16818
16809
  }
16819
16810
  else if (message.T === 'error') {
@@ -16963,9 +16954,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16963
16954
  symbols.forEach((symbol) => {
16964
16955
  allBars[symbol] = [];
16965
16956
  });
16966
- log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
16967
- type: 'info',
16968
- });
16957
+ log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
16969
16958
  while (hasMorePages) {
16970
16959
  pageCount++;
16971
16960
  const requestParams = {
@@ -17010,7 +16999,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17010
16999
  const dateRangeStr = earliestTimestamp && latestTimestamp
17011
17000
  ? `${new Date(earliestTimestamp).toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${new Date(latestTimestamp).toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17012
17001
  : 'unknown range';
17013
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`);
17002
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17014
17003
  // Prevent infinite loops
17015
17004
  if (pageCount > 1000) {
17016
17005
  log(`Stopping pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
@@ -17021,7 +17010,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17021
17010
  const symbolsJoined = Object.entries(allBars)
17022
17011
  .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
17023
17012
  .join(', ');
17024
- log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
17013
+ log(`Bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
17025
17014
  return {
17026
17015
  bars: allBars,
17027
17016
  next_page_token: null, // Always null since we fetch all pages
@@ -17216,14 +17205,25 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17216
17205
  `Avg Volume: ${avgVolume.toLocaleString()}`);
17217
17206
  }
17218
17207
  /**
17219
- * Get all assets available for trade and data consumption from Alpaca
17220
- * @param params Optional query params: status (e.g. 'active'), asset_class (e.g. 'us_equity', 'crypto')
17208
+ * Get assets available for trade and data consumption from Alpaca
17209
+ * @param params Optional query params
17210
+ * - status: 'active' | 'inactive' (default 'active')
17211
+ * - asset_class: 'us_equity' | 'us_option' | 'crypto' (default 'us_equity')
17212
+ * - shortable: if true (default), filters to assets with shortable=true and easy_to_borrow=true
17221
17213
  * @returns Array of AlpacaAsset objects
17222
17214
  * @see https://docs.alpaca.markets/reference/get-v2-assets-1
17223
17215
  */
17224
17216
  async getAssets(params) {
17225
17217
  // Endpoint: GET /v2/assets
17226
- return this.makeRequest('/assets', 'GET', params, 'api'); // use apiURL
17218
+ const { status = 'active', asset_class = 'us_equity', shortable = true, } = {
17219
+ status: params?.status ?? 'active',
17220
+ asset_class: params?.asset_class ?? 'us_equity',
17221
+ shortable: params?.shortable ?? true,
17222
+ };
17223
+ const assets = await this.makeRequest('/assets', 'GET', { status, asset_class }, 'api');
17224
+ if (!shortable)
17225
+ return assets;
17226
+ return assets.filter((a) => a.shortable === true && a.easy_to_borrow === true);
17227
17227
  }
17228
17228
  /**
17229
17229
  * Get a single asset by symbol or asset_id
@@ -17291,9 +17291,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17291
17291
  symbols.forEach((symbol) => {
17292
17292
  allBars[symbol] = [];
17293
17293
  });
17294
- log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
17295
- type: 'info',
17296
- });
17294
+ log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
17297
17295
  while (hasMorePages) {
17298
17296
  pageCount++;
17299
17297
  const requestParams = {
@@ -17333,7 +17331,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17333
17331
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17334
17332
  : 'unknown range';
17335
17333
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
17336
- type: 'info',
17334
+ type: 'debug',
17337
17335
  });
17338
17336
  // Prevent infinite loops
17339
17337
  if (pageCount > 1000) {
@@ -17345,9 +17343,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17345
17343
  const symbolCounts = Object.entries(allBars)
17346
17344
  .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
17347
17345
  .join(', ');
17348
- log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
17349
- type: 'info',
17350
- });
17346
+ log(`Options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`);
17351
17347
  return {
17352
17348
  bars: allBars,
17353
17349
  next_page_token: undefined, // Always undefined since we fetch all pages
@@ -17373,9 +17369,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17373
17369
  symbols.forEach((symbol) => {
17374
17370
  allTrades[symbol] = [];
17375
17371
  });
17376
- log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
17377
- type: 'info',
17378
- });
17372
+ log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17379
17373
  while (hasMorePages) {
17380
17374
  pageCount++;
17381
17375
  const requestParams = {
@@ -17415,7 +17409,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17415
17409
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
17416
17410
  : 'unknown range';
17417
17411
  log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
17418
- type: 'info',
17412
+ type: 'debug',
17419
17413
  });
17420
17414
  // Prevent infinite loops
17421
17415
  if (pageCount > 1000) {
@@ -17427,9 +17421,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17427
17421
  const symbolCounts = Object.entries(allTrades)
17428
17422
  .map(([symbol, trades]) => `${symbol}: ${trades.length}`)
17429
17423
  .join(', ');
17430
- log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
17431
- type: 'info',
17432
- });
17424
+ log(`Options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`);
17433
17425
  return {
17434
17426
  trades: allTrades,
17435
17427
  next_page_token: undefined, // Always undefined since we fetch all pages
@@ -17637,7 +17629,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17637
17629
  symbols.forEach((symbol) => {
17638
17630
  allBars[symbol] = [];
17639
17631
  });
17640
- log(`Starting crypto historical bars fetch for ${symbols.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17632
+ log(`Starting crypto historical bars fetch for ${symbols.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`);
17641
17633
  while (hasMorePages) {
17642
17634
  pageCount++;
17643
17635
  const requestParams = {
@@ -17661,14 +17653,14 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17661
17653
  totalBarsCount += pageBarsCount;
17662
17654
  pageToken = response.next_page_token || null;
17663
17655
  hasMorePages = !!pageToken;
17664
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} crypto bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17656
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} crypto bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17665
17657
  // Prevent infinite loops
17666
17658
  if (pageCount > 1000) {
17667
17659
  log(`Stopping crypto bars pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17668
17660
  break;
17669
17661
  }
17670
17662
  }
17671
- log(`Crypto historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages`, { type: 'info' });
17663
+ log(`Crypto historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages`);
17672
17664
  return {
17673
17665
  bars: allBars,
17674
17666
  next_page_token: null, // Always null since we fetch all pages
@@ -17700,7 +17692,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17700
17692
  symbols.forEach((symbol) => {
17701
17693
  allQuotes[symbol] = [];
17702
17694
  });
17703
- log(`Starting crypto historical quotes fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17695
+ log(`Starting crypto historical quotes fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17704
17696
  while (hasMorePages) {
17705
17697
  pageCount++;
17706
17698
  const requestParams = {
@@ -17724,14 +17716,14 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17724
17716
  totalQuotesCount += pageQuotesCount;
17725
17717
  pageToken = response.next_page_token || null;
17726
17718
  hasMorePages = !!pageToken;
17727
- log(`Page ${pageCount}: Fetched ${pageQuotesCount.toLocaleString()} crypto quotes (total: ${totalQuotesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17719
+ log(`Page ${pageCount}: Fetched ${pageQuotesCount.toLocaleString()} crypto quotes (total: ${totalQuotesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17728
17720
  // Prevent infinite loops
17729
17721
  if (pageCount > 1000) {
17730
17722
  log(`Stopping crypto quotes pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17731
17723
  break;
17732
17724
  }
17733
17725
  }
17734
- log(`Crypto historical quotes fetch complete: ${totalQuotesCount.toLocaleString()} total quotes across ${pageCount} pages`, { type: 'info' });
17726
+ log(`Crypto historical quotes fetch complete: ${totalQuotesCount.toLocaleString()} total quotes across ${pageCount} pages`);
17735
17727
  return {
17736
17728
  quotes: allQuotes,
17737
17729
  next_page_token: null, // Always null since we fetch all pages
@@ -17767,7 +17759,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17767
17759
  symbols.forEach((symbol) => {
17768
17760
  allTrades[symbol] = [];
17769
17761
  });
17770
- log(`Starting crypto historical trades fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, { type: 'info' });
17762
+ log(`Starting crypto historical trades fetch for ${symbols.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`);
17771
17763
  while (hasMorePages) {
17772
17764
  pageCount++;
17773
17765
  const requestParams = {
@@ -17791,14 +17783,14 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
17791
17783
  totalTradesCount += pageTradesCount;
17792
17784
  pageToken = response.next_page_token || null;
17793
17785
  hasMorePages = !!pageToken;
17794
- log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} crypto trades (total: ${totalTradesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`);
17786
+ log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} crypto trades (total: ${totalTradesCount.toLocaleString()}) for ${symbols.length} symbols${hasMorePages ? ', more pages available' : ', complete'}`, { type: 'debug' });
17795
17787
  // Prevent infinite loops
17796
17788
  if (pageCount > 1000) {
17797
17789
  log(`Stopping crypto trades pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
17798
17790
  break;
17799
17791
  }
17800
17792
  }
17801
- log(`Crypto historical trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages`, { type: 'info' });
17793
+ log(`Crypto historical trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages`);
17802
17794
  return {
17803
17795
  trades: allTrades,
17804
17796
  next_page_token: null, // Always null since we fetch all pages