@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.
@@ -251,7 +251,7 @@ const safeJSON = (text) => {
251
251
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
252
252
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
253
253
 
254
- const VERSION = '5.8.3'; // x-release-please-version
254
+ const VERSION = '5.9.0'; // x-release-please-version
255
255
 
256
256
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
257
257
  const isRunningInBrowser = () => {
@@ -6324,7 +6324,7 @@ class OpenAI {
6324
6324
  * Create a new client instance re-using the same options given to the current client with optional overriding.
6325
6325
  */
6326
6326
  withOptions(options) {
6327
- return new this.constructor({
6327
+ const client = new this.constructor({
6328
6328
  ...this._options,
6329
6329
  baseURL: this.baseURL,
6330
6330
  maxRetries: this.maxRetries,
@@ -6339,6 +6339,7 @@ class OpenAI {
6339
6339
  webhookSecret: this.webhookSecret,
6340
6340
  ...options,
6341
6341
  });
6342
+ return client;
6342
6343
  }
6343
6344
  defaultQuery() {
6344
6345
  return this._options.defaultQuery;
@@ -6346,7 +6347,7 @@ class OpenAI {
6346
6347
  validateHeaders({ values, nulls }) {
6347
6348
  return;
6348
6349
  }
6349
- authHeaders(opts) {
6350
+ async authHeaders(opts) {
6350
6351
  return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
6351
6352
  }
6352
6353
  stringifyQuery(query) {
@@ -6416,7 +6417,9 @@ class OpenAI {
6416
6417
  retriesRemaining = maxRetries;
6417
6418
  }
6418
6419
  await this.prepareOptions(options);
6419
- const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
6420
+ const { req, url, timeout } = await this.buildRequest(options, {
6421
+ retryCount: maxRetries - retriesRemaining,
6422
+ });
6420
6423
  await this.prepareRequest(req, { url, options });
6421
6424
  /** Not an API request ID, just for correlating local log entries. */
6422
6425
  const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
@@ -6474,7 +6477,7 @@ class OpenAI {
6474
6477
  .join('');
6475
6478
  const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
6476
6479
  if (!response.ok) {
6477
- const shouldRetry = this.shouldRetry(response);
6480
+ const shouldRetry = await this.shouldRetry(response);
6478
6481
  if (retriesRemaining && shouldRetry) {
6479
6482
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
6480
6483
  // We don't need the body of this response.
@@ -6548,7 +6551,7 @@ class OpenAI {
6548
6551
  clearTimeout(timeout);
6549
6552
  }
6550
6553
  }
6551
- shouldRetry(response) {
6554
+ async shouldRetry(response) {
6552
6555
  // Note this is not a standard header.
6553
6556
  const shouldRetryHeader = response.headers.get('x-should-retry');
6554
6557
  // If the server explicitly says whether or not to retry, obey.
@@ -6610,7 +6613,7 @@ class OpenAI {
6610
6613
  const jitter = 1 - Math.random() * 0.25;
6611
6614
  return sleepSeconds * jitter * 1000;
6612
6615
  }
6613
- buildRequest(inputOptions, { retryCount = 0 } = {}) {
6616
+ async buildRequest(inputOptions, { retryCount = 0 } = {}) {
6614
6617
  const options = { ...inputOptions };
6615
6618
  const { method, path, query, defaultBaseURL } = options;
6616
6619
  const url = this.buildURL(path, query, defaultBaseURL);
@@ -6618,7 +6621,7 @@ class OpenAI {
6618
6621
  validatePositiveInteger('timeout', options.timeout);
6619
6622
  options.timeout = options.timeout ?? this.timeout;
6620
6623
  const { bodyHeaders, body } = this.buildBody({ options });
6621
- const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
6624
+ const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
6622
6625
  const req = {
6623
6626
  method,
6624
6627
  headers: reqHeaders,
@@ -6631,7 +6634,7 @@ class OpenAI {
6631
6634
  };
6632
6635
  return { req, url, timeout: options.timeout };
6633
6636
  }
6634
- buildHeaders({ options, method, bodyHeaders, retryCount, }) {
6637
+ async buildHeaders({ options, method, bodyHeaders, retryCount, }) {
6635
6638
  let idempotencyHeaders = {};
6636
6639
  if (this.idempotencyHeader && method !== 'get') {
6637
6640
  if (!options.idempotencyKey)
@@ -6649,7 +6652,7 @@ class OpenAI {
6649
6652
  'OpenAI-Organization': this.organization,
6650
6653
  'OpenAI-Project': this.project,
6651
6654
  },
6652
- this.authHeaders(options),
6655
+ await this.authHeaders(options),
6653
6656
  this._options.defaultHeaders,
6654
6657
  bodyHeaders,
6655
6658
  options.headers,
@@ -12874,7 +12877,7 @@ var config = {};
12874
12877
 
12875
12878
  var main = {exports: {}};
12876
12879
 
12877
- var version = "17.1.0";
12880
+ var version = "17.2.0";
12878
12881
  var require$$4 = {
12879
12882
  version: version};
12880
12883
 
@@ -12910,6 +12913,13 @@ function requireMain () {
12910
12913
  return TIPS[Math.floor(Math.random() * TIPS.length)]
12911
12914
  }
12912
12915
 
12916
+ function parseBoolean (value) {
12917
+ if (typeof value === 'string') {
12918
+ return !['false', '0', 'no', 'off', ''].includes(value.toLowerCase())
12919
+ }
12920
+ return Boolean(value)
12921
+ }
12922
+
12913
12923
  function supportsAnsi () {
12914
12924
  return process.stdout.isTTY // && process.env.TERM !== 'dumb'
12915
12925
  }
@@ -13101,8 +13111,8 @@ function requireMain () {
13101
13111
  }
13102
13112
 
13103
13113
  function _configVault (options) {
13104
- const debug = Boolean(options && options.debug);
13105
- const quiet = Boolean(options && options.quiet);
13114
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || (options && options.debug));
13115
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || (options && options.quiet));
13106
13116
 
13107
13117
  if (debug || !quiet) {
13108
13118
  _log('Loading env from encrypted .env.vault');
@@ -13123,8 +13133,12 @@ function requireMain () {
13123
13133
  function configDotenv (options) {
13124
13134
  const dotenvPath = path.resolve(process.cwd(), '.env');
13125
13135
  let encoding = 'utf8';
13126
- const debug = Boolean(options && options.debug);
13127
- const quiet = Boolean(options && options.quiet);
13136
+ let processEnv = process.env;
13137
+ if (options && options.processEnv != null) {
13138
+ processEnv = options.processEnv;
13139
+ }
13140
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || (options && options.debug));
13141
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || (options && options.quiet));
13128
13142
 
13129
13143
  if (options && options.encoding) {
13130
13144
  encoding = options.encoding;
@@ -13164,13 +13178,12 @@ function requireMain () {
13164
13178
  }
13165
13179
  }
13166
13180
 
13167
- let processEnv = process.env;
13168
- if (options && options.processEnv != null) {
13169
- processEnv = options.processEnv;
13170
- }
13171
-
13172
13181
  const populated = DotenvModule.populate(processEnv, parsedAll, options);
13173
13182
 
13183
+ // handle user settings DOTENV_CONFIG_ options inside .env file(s)
13184
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
13185
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
13186
+
13174
13187
  if (debug || !quiet) {
13175
13188
  const keysCount = Object.keys(populated).length;
13176
13189
  const shortPaths = [];