@apify/utilities 2.23.0 → 2.23.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/esm/index.mjs CHANGED
@@ -1,6 +1,12 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
4
10
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
11
 
6
12
  // src/utilities.ts
@@ -1870,22 +1876,37 @@ function createHmacSignature(secretKey, message) {
1870
1876
  return encodeBase62(BigInt(`0x${signature}`));
1871
1877
  }
1872
1878
  __name(createHmacSignature, "createHmacSignature");
1873
- var webcrypto = globalThis.crypto?.subtle;
1874
- async function ensureCryptoSubtleExists() {
1875
- webcrypto ?? (webcrypto = (await import("crypto")).webcrypto.subtle);
1879
+ var subtleCrypto = globalThis.crypto?.subtle;
1880
+ async function ensureSubtleCryptoExists() {
1881
+ if (!subtleCrypto) {
1882
+ try {
1883
+ subtleCrypto = __require("crypto")?.webcrypto?.subtle;
1884
+ if (subtleCrypto) return;
1885
+ } catch {
1886
+ }
1887
+ try {
1888
+ subtleCrypto = (await import("crypto"))?.webcrypto?.subtle;
1889
+ } catch {
1890
+ }
1891
+ if (!subtleCrypto) {
1892
+ throw new Error(`SubtleCrypto is not available in this environment.
1893
+ Please ensure you're running in an environment that supports Web Crypto API,
1894
+ or submit an issue to https://github.com/apify/apify-shared-js so we can help you further.`);
1895
+ }
1896
+ }
1876
1897
  }
1877
- __name(ensureCryptoSubtleExists, "ensureCryptoSubtleExists");
1898
+ __name(ensureSubtleCryptoExists, "ensureSubtleCryptoExists");
1878
1899
  async function createHmacSignatureAsync(secretKey, message) {
1879
- await ensureCryptoSubtleExists();
1900
+ await ensureSubtleCryptoExists();
1880
1901
  const encoder = new TextEncoder();
1881
- const key = await webcrypto.importKey(
1902
+ const key = await subtleCrypto.importKey(
1882
1903
  "raw",
1883
1904
  encoder.encode(secretKey),
1884
1905
  { name: "HMAC", hash: "SHA-256" },
1885
1906
  false,
1886
1907
  ["sign"]
1887
1908
  );
1888
- const signatureBuffer = await webcrypto.sign(
1909
+ const signatureBuffer = await subtleCrypto.sign(
1889
1910
  "HMAC",
1890
1911
  key,
1891
1912
  encoder.encode(message)