@weaverse/hydrogen 5.14.1 → 5.15.0

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/index.d.mts CHANGED
@@ -293,6 +293,7 @@ declare function withWeaverse(Component: ComponentType<any>, options?: WithWeave
293
293
  */
294
294
  declare function useThemeSettings<T = HydrogenThemeSettings>(): T;
295
295
 
296
+ type BuilderApiCacheTarget = 'custom-pages' | 'merchant-overrides' | 'project' | 'theme-settings';
296
297
  declare class WeaverseClient {
297
298
  API: "v1";
298
299
  basePageConfigs: Omit<WeaverseProjectConfigs, 'requestInfo'>;
@@ -413,6 +414,7 @@ declare class WeaverseClient {
413
414
  * ```
414
415
  */
415
416
  fetchWithCache: <T = unknown>(url: string, options?: RequestInit & {
417
+ cacheTarget?: BuilderApiCacheTarget;
416
418
  strategy?: CachingStrategy;
417
419
  }) => Promise<T>;
418
420
  /**
package/dist/index.d.ts CHANGED
@@ -293,6 +293,7 @@ declare function withWeaverse(Component: ComponentType<any>, options?: WithWeave
293
293
  */
294
294
  declare function useThemeSettings<T = HydrogenThemeSettings>(): T;
295
295
 
296
+ type BuilderApiCacheTarget = 'custom-pages' | 'merchant-overrides' | 'project' | 'theme-settings';
296
297
  declare class WeaverseClient {
297
298
  API: "v1";
298
299
  basePageConfigs: Omit<WeaverseProjectConfigs, 'requestInfo'>;
@@ -413,6 +414,7 @@ declare class WeaverseClient {
413
414
  * ```
414
415
  */
415
416
  fetchWithCache: <T = unknown>(url: string, options?: RequestInit & {
417
+ cacheTarget?: BuilderApiCacheTarget;
416
418
  strategy?: CachingStrategy;
417
419
  }) => Promise<T>;
418
420
  /**
package/dist/index.js CHANGED
@@ -995,19 +995,34 @@ function useThemeSettings() {
995
995
  return settings;
996
996
  }
997
997
  var CACHE_DURATIONS = {
998
- /** Short cache for frequently changing content (10 seconds) */
999
- SHORT: 10,
1000
- /** Long cache duration - 23 hours to maximize CDN hits before daily refresh */
1001
- LONG: 82800
998
+ /** Short browser freshness for content that can change in Builder */
999
+ SHORT: 60,
1000
+ /** Shared cache freshness for anonymous storefront traffic */
1001
+ SHARED_SHORT: 300,
1002
+ /** Long stale window so slow Builder responses do not block storefront rendering */
1003
+ LONG: 86400,
1004
+ /** Extra freshness for sitemap-like index data */
1005
+ STATIC: 3600
1002
1006
  };
1003
1007
  var DEFAULT_FETCH_TIMEOUT_MS = 1e4;
1004
1008
  var API_PATH = "v1";
1005
1009
  var DEFAULT_CACHE_STRATEGY = {
1006
1010
  maxAge: CACHE_DURATIONS.SHORT,
1007
- sMaxAge: CACHE_DURATIONS.SHORT,
1011
+ sMaxAge: CACHE_DURATIONS.SHARED_SHORT,
1008
1012
  staleWhileRevalidate: CACHE_DURATIONS.LONG,
1009
1013
  staleIfError: CACHE_DURATIONS.LONG
1010
1014
  };
1015
+ var SMART_CACHE_STRATEGIES = {
1016
+ project: DEFAULT_CACHE_STRATEGY,
1017
+ "theme-settings": DEFAULT_CACHE_STRATEGY,
1018
+ "merchant-overrides": DEFAULT_CACHE_STRATEGY,
1019
+ "custom-pages": {
1020
+ maxAge: CACHE_DURATIONS.SHORT,
1021
+ sMaxAge: CACHE_DURATIONS.STATIC,
1022
+ staleWhileRevalidate: CACHE_DURATIONS.LONG,
1023
+ staleIfError: CACHE_DURATIONS.LONG
1024
+ }
1025
+ };
1011
1026
  var WeaverseClient = class {
1012
1027
  API = API_PATH;
1013
1028
  basePageConfigs;
@@ -1349,19 +1364,23 @@ var WeaverseClient = class {
1349
1364
  * ```
1350
1365
  */
1351
1366
  fetchWithCache = async (url, options = {}) => {
1352
- const strategy = options.strategy || hydrogen.CacheCustom(DEFAULT_CACHE_STRATEGY);
1367
+ const { cacheTarget, strategy: strategyOverride, ...fetchOptions } = options;
1368
+ const strategy = strategyOverride || hydrogen.CacheCustom(
1369
+ cacheTarget ? SMART_CACHE_STRATEGIES[cacheTarget] : DEFAULT_CACHE_STRATEGY
1370
+ );
1353
1371
  const cacheKey = [
1354
1372
  "weaverse-fetch",
1355
1373
  url,
1356
1374
  options.method || "GET",
1357
- options.body,
1358
- this.configs.projectId
1375
+ fetchOptions.body,
1376
+ this.configs.projectId,
1377
+ cacheTarget || "default"
1359
1378
  ];
1360
1379
  let result;
1361
- if (this.configs.isDesignMode) {
1362
- result = await this.directFetch(url, options);
1380
+ if (this.configs.isDesignMode || this.configs.isRevisionPreview) {
1381
+ result = await this.directFetch(url, fetchOptions);
1363
1382
  } else {
1364
- result = await this.withCache.fetch(url, options, {
1383
+ result = await this.withCache.fetch(url, fetchOptions, {
1365
1384
  cacheKey,
1366
1385
  cacheStrategy: strategy,
1367
1386
  shouldCacheResponse: (response) => {
@@ -1398,6 +1417,7 @@ var WeaverseClient = class {
1398
1417
  const [data, merchantOverrides] = await Promise.all([
1399
1418
  this.fetchWithCache(url, {
1400
1419
  method: "POST",
1420
+ cacheTarget: "theme-settings",
1401
1421
  strategy,
1402
1422
  body,
1403
1423
  headers: {
@@ -1492,6 +1512,7 @@ var WeaverseClient = class {
1492
1512
  url,
1493
1513
  {
1494
1514
  method: "GET",
1515
+ cacheTarget: "merchant-overrides",
1495
1516
  strategy,
1496
1517
  headers: {
1497
1518
  Accept: "application/json"
@@ -1555,7 +1576,7 @@ var WeaverseClient = class {
1555
1576
  const qs = params.toString();
1556
1577
  const url = `${weaverseHost}/api/public/v1/projects/${projectId}/custom-pages${qs ? `?${qs}` : ""}`;
1557
1578
  try {
1558
- const result = await this.fetchWithCache(url);
1579
+ const result = await this.fetchWithCache(url, { cacheTarget: "custom-pages" });
1559
1580
  entries.push(...result.data || []);
1560
1581
  if (!result.nextCursor) {
1561
1582
  return entries;
@@ -1655,6 +1676,7 @@ var WeaverseClient = class {
1655
1676
  const url = this.getApiUrl("project");
1656
1677
  const projectData = await this.fetchWithCache(url, {
1657
1678
  ...reqInit,
1679
+ cacheTarget: "project",
1658
1680
  strategy
1659
1681
  });
1660
1682
  if (hasError(projectData)) {