apify-client 2.24.1-beta.0 → 2.24.1-beta.2

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/bundle.js CHANGED
@@ -18029,6 +18029,23 @@ const MIN_COMPRESS_BYTES = 1024;
18029
18029
  const uint8Array = encoder.encode(webhooksJson);
18030
18030
  return btoa(String.fromCharCode(...uint8Array));
18031
18031
  }
18032
+ let brotliCompressPromisified;
18033
+ /**
18034
+ * Brotli-compress the provided value.
18035
+ */ async function brotliValue(value) {
18036
+ if (!brotliCompressPromisified) {
18037
+ const { promisify } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 6029, 23));
18038
+ const { brotliCompress, constants } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 1134, 23));
18039
+ const compress = promisify(brotliCompress);
18040
+ const options = {
18041
+ params: {
18042
+ [constants.BROTLI_PARAM_QUALITY]: 6
18043
+ }
18044
+ };
18045
+ brotliCompressPromisified = async (input)=>compress(input, options);
18046
+ }
18047
+ return brotliCompressPromisified(value);
18048
+ }
18032
18049
  let gzipPromisified;
18033
18050
  /**
18034
18051
  * Gzip-compress the provided value.
@@ -18040,34 +18057,9 @@ let gzipPromisified;
18040
18057
  }
18041
18058
  return gzipPromisified(value);
18042
18059
  }
18043
- // null = confirmed unavailable; undefined = not yet checked
18044
- let brotliCompressPromisified;
18045
- /**
18046
- * Brotli-compress the provided value, or return undefined if brotli is unavailable
18047
- * (Node.js < v10.16.0), this is a strict defensive guard.
18048
- */ async function maybeBrotliValue(value) {
18049
- if (brotliCompressPromisified === undefined) {
18050
- const { promisify } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 6029, 23));
18051
- const { brotliCompress, constants } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 1134, 23));
18052
- if (typeof brotliCompress === 'function') {
18053
- const compress = promisify(brotliCompress);
18054
- brotliCompressPromisified = async (value)=>compress(value, {
18055
- params: {
18056
- [constants.BROTLI_PARAM_QUALITY]: 6
18057
- }
18058
- });
18059
- } else {
18060
- brotliCompressPromisified = null;
18061
- }
18062
- }
18063
- if (brotliCompressPromisified !== null) {
18064
- return brotliCompressPromisified(value);
18065
- }
18066
- return undefined;
18067
- }
18068
18060
  /**
18069
- * Compress the passed value using brotli if available or using gzip as a fallback. Returns undefined
18070
- * if the data is too small / wrong type.
18061
+ * Compress the passed value using brotli, falling back to gzip. Returns undefined if the data is
18062
+ * too small / wrong type, or if neither algorithm is available.
18071
18063
  */ async function maybeCompressValue(value) {
18072
18064
  if (!isNode()) return undefined;
18073
18065
  // Request compression is not that important so let's
@@ -18075,16 +18067,25 @@ let brotliCompressPromisified;
18075
18067
  if (typeof value !== 'string' && !Buffer.isBuffer(value)) return undefined;
18076
18068
  const areDataLargeEnough = Buffer.byteLength(value) >= MIN_COMPRESS_BYTES;
18077
18069
  if (!areDataLargeEnough) return undefined;
18078
- const brotli = await maybeBrotliValue(value);
18079
- if (brotli) return {
18080
- data: brotli,
18081
- encoding: 'br'
18082
- };
18083
- const gzipped = await gzipValue(value);
18084
- return {
18085
- data: gzipped,
18086
- encoding: 'gzip'
18087
- };
18070
+ try {
18071
+ return {
18072
+ data: await brotliValue(value),
18073
+ encoding: 'br'
18074
+ };
18075
+ } catch {
18076
+ // Runtimes that only provide a partial `node:zlib` (bundler polyfills, edge runtimes with
18077
+ // Node compatibility shims) may not implement brotli, but usually do implement gzip.
18078
+ }
18079
+ try {
18080
+ return {
18081
+ data: await gzipValue(value),
18082
+ encoding: 'gzip'
18083
+ };
18084
+ } catch {
18085
+ // Same reasoning as above: compression is a best-effort optimization, so skip it instead
18086
+ // of failing the request.
18087
+ return undefined;
18088
+ }
18088
18089
  }
18089
18090
  /**
18090
18091
  * Helper function slice the items from array to fit the max byte length.
@@ -18122,7 +18123,7 @@ function isStream(value) {
18122
18123
  function getVersionData() {
18123
18124
  if (true) {
18124
18125
  return {
18125
- version: "2.24.1-beta.0"
18126
+ version: "2.24.1-beta.2"
18126
18127
  };
18127
18128
  }
18128
18129
  // eslint-disable-next-line