@apify/utilities 2.15.1 → 2.15.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/cjs/index.cjs CHANGED
@@ -92,12 +92,12 @@ __export(index_exports, {
92
92
  module.exports = __toCommonJS(index_exports);
93
93
 
94
94
  // src/utilities.ts
95
- var import_crypto = __toESM(require("crypto"));
95
+ var import_node_crypto = __toESM(require("crypto"));
96
96
  var import_consts = require("@apify/consts");
97
97
  var import_log = __toESM(require("@apify/log"));
98
98
  function cryptoRandomObjectId(length = 17) {
99
99
  const chars = "abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ0123456789";
100
- const bytes = import_crypto.default.randomBytes(length);
100
+ const bytes = import_node_crypto.default.randomBytes(length);
101
101
  let str = "";
102
102
  for (let i = bytes.length - 1; i >= 0; i--) {
103
103
  str += chars[(bytes[i] | 0) % chars.length];
@@ -106,7 +106,7 @@ function cryptoRandomObjectId(length = 17) {
106
106
  }
107
107
  __name(cryptoRandomObjectId, "cryptoRandomObjectId");
108
108
  function deterministicUniqueId(key, length = 17) {
109
- return import_crypto.default.createHash("sha256").update(key).digest("base64").replace(/(\+|\/|=)/g, "x").substr(0, length);
109
+ return import_node_crypto.default.createHash("sha256").update(key).digest("base64").replace(/(\+|\/|=)/g, "x").substr(0, length);
110
110
  }
111
111
  __name(deterministicUniqueId, "deterministicUniqueId");
112
112
  function getRandomInt(maxExcluded) {
@@ -148,7 +148,8 @@ __name(http404Route, "http404Route");
148
148
  function expressErrorHandler(err, req, res, next) {
149
149
  import_log.default.warning("Client HTTP request failed", { url: req.url, errMsg: err.message });
150
150
  if (res.headersSent) {
151
- return next(err);
151
+ next(err);
152
+ return;
152
153
  }
153
154
  res.status(505);
154
155
  res.send("Internal server error");
@@ -159,7 +160,9 @@ function betterSetInterval(func, delay) {
159
160
  let timeoutId;
160
161
  let isRunning = true;
161
162
  const funcWrapper = /* @__PURE__ */ __name(function() {
162
- void new Promise((resolve) => resolve(func(() => void 0))).finally(scheduleNextRun);
163
+ void new Promise((resolve) => {
164
+ resolve(func(() => void 0));
165
+ }).finally(scheduleNextRun);
163
166
  }, "funcWrapper");
164
167
  scheduleNextRun = /* @__PURE__ */ __name(function() {
165
168
  if (isRunning) timeoutId = setTimeout(funcWrapper, delay);
@@ -1082,7 +1085,10 @@ async function timeoutPromise(promise, timeoutMillis, errorMessage = "Promise ha
1082
1085
  if (hasFulfilled) return;
1083
1086
  clearTimeout(timeout);
1084
1087
  hasFulfilled = true;
1085
- if (err) return reject(err);
1088
+ if (err) {
1089
+ reject(err);
1090
+ return;
1091
+ }
1086
1092
  resolve(result);
1087
1093
  }, "callback");
1088
1094
  promise.then((result) => callback(null, result), callback);
@@ -1213,7 +1219,7 @@ function markedSetNofollowLinks(href, title, text, referrerHostname) {
1213
1219
  let urlParsed;
1214
1220
  try {
1215
1221
  urlParsed = new URL(href);
1216
- } catch (e) {
1222
+ } catch {
1217
1223
  }
1218
1224
  const isApifyLink = urlParsed && /(\.|^)apify\.com$/i.test(urlParsed.hostname);
1219
1225
  const isSameHostname = !referrerHostname || urlParsed && urlParsed.hostname === referrerHostname;
@@ -1532,8 +1538,8 @@ __publicField(_HealthChecker, "CHECK_TYPES", CHECK_TYPES);
1532
1538
  var HealthChecker = _HealthChecker;
1533
1539
 
1534
1540
  // src/parse_jsonl_stream.ts
1535
- var import_stream = require("stream");
1536
- var _ParseJsonlStream = class _ParseJsonlStream extends import_stream.Transform {
1541
+ var import_node_stream = require("stream");
1542
+ var _ParseJsonlStream = class _ParseJsonlStream extends import_node_stream.Transform {
1537
1543
  constructor() {
1538
1544
  super(...arguments);
1539
1545
  __publicField(this, "pendingChunk", null);
@@ -1805,7 +1811,7 @@ __name(_WebhookPayloadTemplate, "WebhookPayloadTemplate");
1805
1811
  var WebhookPayloadTemplate = _WebhookPayloadTemplate;
1806
1812
 
1807
1813
  // src/crypto.ts
1808
- var import_crypto2 = __toESM(require("crypto"));
1814
+ var import_node_crypto2 = __toESM(require("crypto"));
1809
1815
  var ENCRYPTION_ALGORITHM = "aes-256-gcm";
1810
1816
  var ENCRYPTION_KEY_LENGTH = 32;
1811
1817
  var ENCRYPTION_IV_LENGTH = 16;
@@ -1813,13 +1819,13 @@ var ENCRYPTION_AUTH_TAG_LENGTH = 16;
1813
1819
  function publicEncrypt({ publicKey, value }) {
1814
1820
  const key = cryptoRandomObjectId(ENCRYPTION_KEY_LENGTH);
1815
1821
  const initVector = cryptoRandomObjectId(ENCRYPTION_IV_LENGTH);
1816
- const cipher = import_crypto2.default.createCipheriv(ENCRYPTION_ALGORITHM, key, initVector);
1822
+ const cipher = import_node_crypto2.default.createCipheriv(ENCRYPTION_ALGORITHM, key, initVector);
1817
1823
  const bufferFromValue = Buffer.from(value, "utf-8");
1818
1824
  const bufferFromKey = Buffer.from(key, "utf-8");
1819
1825
  const bufferFromInitVector = Buffer.from(initVector, "utf-8");
1820
1826
  const passwordBuffer = Buffer.concat([bufferFromKey, bufferFromInitVector]);
1821
1827
  const encryptedValue = Buffer.concat([cipher.update(bufferFromValue), cipher.final(), cipher.getAuthTag()]);
1822
- const encryptedPassword = import_crypto2.default.publicEncrypt(publicKey, passwordBuffer);
1828
+ const encryptedPassword = import_node_crypto2.default.publicEncrypt(publicKey, passwordBuffer);
1823
1829
  return {
1824
1830
  encryptedPassword: encryptedPassword.toString("base64"),
1825
1831
  encryptedValue: encryptedValue.toString("base64")
@@ -1833,7 +1839,7 @@ function privateDecrypt({
1833
1839
  }) {
1834
1840
  const encryptedValueBuffer = Buffer.from(encryptedValue, "base64");
1835
1841
  const encryptedPasswordBuffer = Buffer.from(encryptedPassword, "base64");
1836
- const passwordBuffer = import_crypto2.default.privateDecrypt(privateKey, encryptedPasswordBuffer);
1842
+ const passwordBuffer = import_node_crypto2.default.privateDecrypt(privateKey, encryptedPasswordBuffer);
1837
1843
  if (passwordBuffer.length !== ENCRYPTION_KEY_LENGTH + ENCRYPTION_IV_LENGTH) {
1838
1844
  throw new Error("privateDecrypt: Decryption failed, invalid password length!");
1839
1845
  }
@@ -1841,7 +1847,7 @@ function privateDecrypt({
1841
1847
  const encryptedDataBuffer = encryptedValueBuffer.slice(0, encryptedValueBuffer.length - ENCRYPTION_AUTH_TAG_LENGTH);
1842
1848
  const encryptionKeyBuffer = passwordBuffer.slice(0, ENCRYPTION_KEY_LENGTH);
1843
1849
  const initVectorBuffer = passwordBuffer.slice(ENCRYPTION_KEY_LENGTH);
1844
- const decipher = import_crypto2.default.createDecipheriv(ENCRYPTION_ALGORITHM, encryptionKeyBuffer, initVectorBuffer);
1850
+ const decipher = import_node_crypto2.default.createDecipheriv(ENCRYPTION_ALGORITHM, encryptionKeyBuffer, initVectorBuffer);
1845
1851
  decipher.setAuthTag(authTagBuffer);
1846
1852
  return Buffer.concat([decipher.update(encryptedDataBuffer), decipher.final()]).toString("utf-8");
1847
1853
  }
@@ -1858,7 +1864,7 @@ function separateImports(code) {
1858
1864
  __name(separateImports, "separateImports");
1859
1865
 
1860
1866
  // src/code_hash_manager.ts
1861
- var import_node_crypto = require("crypto");
1867
+ var import_node_crypto3 = require("crypto");
1862
1868
  var CodeHashMetaKey = /* @__PURE__ */ ((CodeHashMetaKey2) => {
1863
1869
  CodeHashMetaKey2["VERSION"] = "v";
1864
1870
  CodeHashMetaKey2["USER"] = "u";
@@ -1891,7 +1897,7 @@ var _CodeHashManager = class _CodeHashManager {
1891
1897
  const data = JSON.parse(this.fromBase64(parts[1]).toString());
1892
1898
  const signature = this.fromBase64(parts[2]);
1893
1899
  const expectedSignature = this.generateSignature(dataToSign);
1894
- const isSignatureValid = (0, import_node_crypto.timingSafeEqual)(signature, expectedSignature);
1900
+ const isSignatureValid = (0, import_node_crypto3.timingSafeEqual)(signature, expectedSignature);
1895
1901
  return {
1896
1902
  data,
1897
1903
  meta: {
@@ -1908,7 +1914,7 @@ var _CodeHashManager = class _CodeHashManager {
1908
1914
  return Buffer.from(encoded, "base64url");
1909
1915
  }
1910
1916
  generateSignature(data) {
1911
- return (0, import_node_crypto.createHmac)("sha256", this.secret).update(data).digest();
1917
+ return (0, import_node_crypto3.createHmac)("sha256", this.secret).update(data).digest();
1912
1918
  }
1913
1919
  };
1914
1920
  __name(_CodeHashManager, "CodeHashManager");
@@ -1917,7 +1923,7 @@ __publicField(_CodeHashManager, "VERSION", 1);
1917
1923
  var CodeHashManager = _CodeHashManager;
1918
1924
 
1919
1925
  // src/hmac.ts
1920
- var import_crypto3 = __toESM(require("crypto"));
1926
+ var import_node_crypto4 = __toESM(require("crypto"));
1921
1927
  var CHARSET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
1922
1928
  function encodeBase62(num) {
1923
1929
  if (num === 0n) {
@@ -1932,7 +1938,7 @@ function encodeBase62(num) {
1932
1938
  }
1933
1939
  __name(encodeBase62, "encodeBase62");
1934
1940
  function createHmacSignature(secretKey, message) {
1935
- const signature = import_crypto3.default.createHmac("sha256", secretKey).update(message).digest("hex").substring(0, 30);
1941
+ const signature = import_node_crypto4.default.createHmac("sha256", secretKey).update(message).digest("hex").substring(0, 30);
1936
1942
  return encodeBase62(BigInt(`0x${signature}`));
1937
1943
  }
1938
1944
  __name(createHmacSignature, "createHmacSignature");