@akinon/next 1.93.0-snapshot-ZERO-3586-20250827140833 → 1.93.0-snapshot-ZERO-3586-20250827142629

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @akinon/next
2
2
 
3
- ## 1.93.0-snapshot-ZERO-3586-20250827140833
3
+ ## 1.93.0-snapshot-ZERO-3586-20250827142629
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -46,7 +46,7 @@
46
46
  - bbe18b9ff: ZERO-2575: Fix build error
47
47
  - 17bfadc4: ZERO-3275: Disable OpenTelemetry monitoring in production environment
48
48
  - 35dfb8f8: ZERO-3363: Refactor URL handling in checkout and redirection middlewares to use url.origin instead of process.env.NEXT_PUBLIC_URL
49
- - 4920742c: Disable getCachedTranslations
49
+ - 4920742c2: Disable getCachedTranslations
50
50
  - b6e5b624: ZERO-3257: Enhance locale middleware to redirect using existing or default locale and support 303 status for POST requests
51
51
  - 0de55738: ZERO-3418: Update remotePatterns hostname to allow all subdomains
52
52
  - 7e56d6b6: ZERO-2841: Update api tagTypes
package/lib/cache.ts CHANGED
@@ -3,12 +3,25 @@ import { RedisClientType } from 'redis';
3
3
  import Settings from 'settings';
4
4
  import { CacheOptions } from '../types';
5
5
  import logger from '../utils/log';
6
- import * as zstd from 'node-zstandard';
7
-
8
6
  const CACHE_VERSION = 'v2';
9
7
 
10
- // Simple check if we're in Node.js environment where compression works
11
- const isCompressionAvailable = typeof window === 'undefined';
8
+ let zstd: any = null;
9
+ let isInitialized = false;
10
+
11
+ const getZstd = async () => {
12
+ if (zstd === null) {
13
+ try {
14
+ zstd = await import('@dweb-browser/zstd-wasm');
15
+ if (!isInitialized) {
16
+ await zstd.init();
17
+ isInitialized = true;
18
+ }
19
+ } catch (error) {
20
+ zstd = false; // Mark as failed
21
+ }
22
+ }
23
+ return zstd || null;
24
+ };
12
25
 
13
26
  const hashCacheKey = (object?: Record<string, string>) => {
14
27
  if (!object) {
@@ -200,9 +213,7 @@ export class Cache {
200
213
  const defaultOptions: CacheOptions = {
201
214
  cache: true,
202
215
  expire: Settings.redis.defaultExpirationTime,
203
- compressed:
204
- process.env.CACHE_COMPRESSION_ENABLED !== 'false' &&
205
- isCompressionAvailable
216
+ compressed: process.env.CACHE_COMPRESSION_ENABLED !== 'false'
206
217
  };
207
218
 
208
219
  const _options = Object.assign(defaultOptions, options);
@@ -381,8 +392,10 @@ export class Cache {
381
392
  });
382
393
  }
383
394
 
384
- if (!isCompressionAvailable) {
385
- // Browser environment, store uncompressed
395
+ const zstdModule = await getZstd();
396
+
397
+ if (!zstdModule) {
398
+ // Edge Runtime or browser environment, store uncompressed
386
399
  if (expire) {
387
400
  await client.set(key, serializedValue, { EX: expire });
388
401
  } else {
@@ -390,17 +403,22 @@ export class Cache {
390
403
  }
391
404
 
392
405
  success = true;
393
- logger.debug('Redis set success (uncompressed - browser)', {
394
- key,
395
- size: serializedValue.length
396
- });
406
+ logger.debug(
407
+ 'Redis set success (uncompressed - no compression available)',
408
+ {
409
+ key,
410
+ size: serializedValue.length
411
+ }
412
+ );
397
413
  } else {
398
414
  try {
399
- // Use node-zstandard API - simple and direct
400
- const inputBuffer = Buffer.from(serializedValue, 'utf8');
401
- const compressed = zstd.compress(inputBuffer, 3);
415
+ // Use @dweb-browser/zstd-wasm API
416
+ const inputBuffer = new Uint8Array(
417
+ Buffer.from(serializedValue, 'utf8')
418
+ );
419
+ const compressed = zstdModule.compress(inputBuffer, 3);
402
420
 
403
- const compressedBase64 = compressed.toString('base64');
421
+ const compressedBase64 = Buffer.from(compressed).toString('base64');
404
422
 
405
423
  if (expire) {
406
424
  await client.set(key, compressedBase64, { EX: expire });
@@ -472,18 +490,26 @@ export class Cache {
472
490
 
473
491
  let decompressed: Buffer;
474
492
  try {
475
- if (!isCompressionAvailable) {
476
- // Browser environment, try direct JSON parse
493
+ const zstdModule = await getZstd();
494
+
495
+ if (!zstdModule) {
496
+ // Edge Runtime or browser environment, try direct JSON parse
477
497
  const rawString = compressed;
478
498
  const parsedData = JSON.parse(rawString);
479
- logger.debug('Data read as uncompressed (browser)', {
480
- key
481
- });
499
+ logger.debug(
500
+ 'Data read as uncompressed (no compression available)',
501
+ {
502
+ key
503
+ }
504
+ );
482
505
  return parsedData;
483
506
  }
484
507
 
485
- // Use node-zstandard API - simple and direct
486
- decompressed = zstd.decompress(compressedBuffer);
508
+ // Use @dweb-browser/zstd-wasm API
509
+ const decompressedArray = zstdModule.decompress(
510
+ new Uint8Array(compressedBuffer)
511
+ );
512
+ decompressed = Buffer.from(decompressedArray);
487
513
  } catch (error) {
488
514
  logger.debug(
489
515
  'Failed to decompress with zstd, trying fallback methods',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.93.0-snapshot-ZERO-3586-20250827140833",
4
+ "version": "1.93.0-snapshot-ZERO-3586-20250827142629",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "test": "jest"
18
18
  },
19
19
  "dependencies": {
20
- "node-zstandard": "^1.0.0",
20
+ "@dweb-browser/zstd-wasm": "^1.0.3",
21
21
  "@neshca/cache-handler": "1.9.0",
22
22
  "@opentelemetry/exporter-trace-otlp-http": "0.46.0",
23
23
  "@opentelemetry/resources": "1.19.0",
@@ -35,7 +35,7 @@
35
35
  "set-cookie-parser": "2.6.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@akinon/eslint-plugin-projectzero": "1.93.0-snapshot-ZERO-3586-20250827140833",
38
+ "@akinon/eslint-plugin-projectzero": "1.93.0-snapshot-ZERO-3586-20250827142629",
39
39
  "@babel/core": "7.26.10",
40
40
  "@babel/preset-env": "7.26.9",
41
41
  "@babel/preset-typescript": "7.27.0",