@discomedia/utils 1.0.13 → 1.0.15

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
@@ -309,12 +309,10 @@ class TimeFormatter {
309
309
  */
310
310
  class MarketTimeCalculator {
311
311
  calendar;
312
- formatter;
313
312
  timezone;
314
313
  constructor(timezone = MARKET_CONFIG.TIMEZONE) {
315
314
  this.timezone = timezone;
316
315
  this.calendar = new MarketCalendar(timezone);
317
- this.formatter = new TimeFormatter(timezone);
318
316
  }
319
317
  /**
320
318
  * Get market open/close times for a date
@@ -804,7 +802,7 @@ function getTradingStartAndEndDates(options = {}) {
804
802
  }
805
803
  return { startDate, endDate: endMarketClose };
806
804
  }
807
- // Export the old MARKET_TIMES constant for backward compatibility
805
+ // Export the MARKET_TIMES constant for backward compatibility
808
806
  const MARKET_TIMES = {
809
807
  TIMEZONE: MARKET_CONFIG.TIMEZONE,
810
808
  PRE: {
@@ -2260,7 +2258,7 @@ const safeJSON = (text) => {
2260
2258
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2261
2259
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2262
2260
 
2263
- const VERSION = '5.8.3'; // x-release-please-version
2261
+ const VERSION = '5.9.0'; // x-release-please-version
2264
2262
 
2265
2263
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2266
2264
  const isRunningInBrowser = () => {
@@ -8333,7 +8331,7 @@ class OpenAI {
8333
8331
  * Create a new client instance re-using the same options given to the current client with optional overriding.
8334
8332
  */
8335
8333
  withOptions(options) {
8336
- return new this.constructor({
8334
+ const client = new this.constructor({
8337
8335
  ...this._options,
8338
8336
  baseURL: this.baseURL,
8339
8337
  maxRetries: this.maxRetries,
@@ -8348,6 +8346,7 @@ class OpenAI {
8348
8346
  webhookSecret: this.webhookSecret,
8349
8347
  ...options,
8350
8348
  });
8349
+ return client;
8351
8350
  }
8352
8351
  defaultQuery() {
8353
8352
  return this._options.defaultQuery;
@@ -8355,7 +8354,7 @@ class OpenAI {
8355
8354
  validateHeaders({ values, nulls }) {
8356
8355
  return;
8357
8356
  }
8358
- authHeaders(opts) {
8357
+ async authHeaders(opts) {
8359
8358
  return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
8360
8359
  }
8361
8360
  stringifyQuery(query) {
@@ -8425,7 +8424,9 @@ class OpenAI {
8425
8424
  retriesRemaining = maxRetries;
8426
8425
  }
8427
8426
  await this.prepareOptions(options);
8428
- const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
8427
+ const { req, url, timeout } = await this.buildRequest(options, {
8428
+ retryCount: maxRetries - retriesRemaining,
8429
+ });
8429
8430
  await this.prepareRequest(req, { url, options });
8430
8431
  /** Not an API request ID, just for correlating local log entries. */
8431
8432
  const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
@@ -8483,7 +8484,7 @@ class OpenAI {
8483
8484
  .join('');
8484
8485
  const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
8485
8486
  if (!response.ok) {
8486
- const shouldRetry = this.shouldRetry(response);
8487
+ const shouldRetry = await this.shouldRetry(response);
8487
8488
  if (retriesRemaining && shouldRetry) {
8488
8489
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
8489
8490
  // We don't need the body of this response.
@@ -8557,7 +8558,7 @@ class OpenAI {
8557
8558
  clearTimeout(timeout);
8558
8559
  }
8559
8560
  }
8560
- shouldRetry(response) {
8561
+ async shouldRetry(response) {
8561
8562
  // Note this is not a standard header.
8562
8563
  const shouldRetryHeader = response.headers.get('x-should-retry');
8563
8564
  // If the server explicitly says whether or not to retry, obey.
@@ -8619,7 +8620,7 @@ class OpenAI {
8619
8620
  const jitter = 1 - Math.random() * 0.25;
8620
8621
  return sleepSeconds * jitter * 1000;
8621
8622
  }
8622
- buildRequest(inputOptions, { retryCount = 0 } = {}) {
8623
+ async buildRequest(inputOptions, { retryCount = 0 } = {}) {
8623
8624
  const options = { ...inputOptions };
8624
8625
  const { method, path, query, defaultBaseURL } = options;
8625
8626
  const url = this.buildURL(path, query, defaultBaseURL);
@@ -8627,7 +8628,7 @@ class OpenAI {
8627
8628
  validatePositiveInteger('timeout', options.timeout);
8628
8629
  options.timeout = options.timeout ?? this.timeout;
8629
8630
  const { bodyHeaders, body } = this.buildBody({ options });
8630
- const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
8631
+ const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
8631
8632
  const req = {
8632
8633
  method,
8633
8634
  headers: reqHeaders,
@@ -8640,7 +8641,7 @@ class OpenAI {
8640
8641
  };
8641
8642
  return { req, url, timeout: options.timeout };
8642
8643
  }
8643
- buildHeaders({ options, method, bodyHeaders, retryCount, }) {
8644
+ async buildHeaders({ options, method, bodyHeaders, retryCount, }) {
8644
8645
  let idempotencyHeaders = {};
8645
8646
  if (this.idempotencyHeader && method !== 'get') {
8646
8647
  if (!options.idempotencyKey)
@@ -8658,7 +8659,7 @@ class OpenAI {
8658
8659
  'OpenAI-Organization': this.organization,
8659
8660
  'OpenAI-Project': this.project,
8660
8661
  },
8661
- this.authHeaders(options),
8662
+ await this.authHeaders(options),
8662
8663
  this._options.defaultHeaders,
8663
8664
  bodyHeaders,
8664
8665
  options.headers,
@@ -15398,7 +15399,7 @@ var config = {};
15398
15399
 
15399
15400
  var main = {exports: {}};
15400
15401
 
15401
- var version = "17.1.0";
15402
+ var version = "17.2.0";
15402
15403
  var require$$4 = {
15403
15404
  version: version};
15404
15405
 
@@ -15434,6 +15435,13 @@ function requireMain () {
15434
15435
  return TIPS[Math.floor(Math.random() * TIPS.length)]
15435
15436
  }
15436
15437
 
15438
+ function parseBoolean (value) {
15439
+ if (typeof value === 'string') {
15440
+ return !['false', '0', 'no', 'off', ''].includes(value.toLowerCase())
15441
+ }
15442
+ return Boolean(value)
15443
+ }
15444
+
15437
15445
  function supportsAnsi () {
15438
15446
  return process.stdout.isTTY // && process.env.TERM !== 'dumb'
15439
15447
  }
@@ -15625,8 +15633,8 @@ function requireMain () {
15625
15633
  }
15626
15634
 
15627
15635
  function _configVault (options) {
15628
- const debug = Boolean(options && options.debug);
15629
- const quiet = Boolean(options && options.quiet);
15636
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || (options && options.debug));
15637
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || (options && options.quiet));
15630
15638
 
15631
15639
  if (debug || !quiet) {
15632
15640
  _log('Loading env from encrypted .env.vault');
@@ -15647,8 +15655,12 @@ function requireMain () {
15647
15655
  function configDotenv (options) {
15648
15656
  const dotenvPath = path.resolve(process.cwd(), '.env');
15649
15657
  let encoding = 'utf8';
15650
- const debug = Boolean(options && options.debug);
15651
- const quiet = Boolean(options && options.quiet);
15658
+ let processEnv = process.env;
15659
+ if (options && options.processEnv != null) {
15660
+ processEnv = options.processEnv;
15661
+ }
15662
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || (options && options.debug));
15663
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || (options && options.quiet));
15652
15664
 
15653
15665
  if (options && options.encoding) {
15654
15666
  encoding = options.encoding;
@@ -15688,13 +15700,12 @@ function requireMain () {
15688
15700
  }
15689
15701
  }
15690
15702
 
15691
- let processEnv = process.env;
15692
- if (options && options.processEnv != null) {
15693
- processEnv = options.processEnv;
15694
- }
15695
-
15696
15703
  const populated = DotenvModule.populate(processEnv, parsedAll, options);
15697
15704
 
15705
+ // handle user settings DOTENV_CONFIG_ options inside .env file(s)
15706
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
15707
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
15708
+
15698
15709
  if (debug || !quiet) {
15699
15710
  const keysCount = Object.keys(populated).length;
15700
15711
  const shortPaths = [];