@discomedia/utils 1.0.12 → 1.0.14

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