@weaverse/hydrogen 5.15.2 → 5.16.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
@@ -396,6 +396,7 @@ declare class WeaverseClient {
396
396
  */
397
397
  private readonly directFetch;
398
398
  private getApiUrl;
399
+ private isExternalPublicApiUrl;
399
400
  /**
400
401
  * Fetch data with caching support for both design mode and production.
401
402
  * Uses direct fetch in design mode, Hydrogen's withCache in production.
@@ -567,6 +568,12 @@ interface WeaverseHydrogenParams extends Omit<WeaverseCoreParams, 'ItemConstruct
567
568
  weaverseApiBase: string;
568
569
  weaverseApiKey: string;
569
570
  weaverseHost: string;
571
+ /**
572
+ * Public data API origin. Keep `weaverseHost` for Studio scripts/editor
573
+ * assets; point this at the Cloudflare proxy (`https://api.weaverse.io`)
574
+ * when edge caching is enabled.
575
+ */
576
+ weaversePublicApiBase?: string;
570
577
  weaverseVersion?: string;
571
578
  }
572
579
  type HydrogenComponent<T extends HydrogenComponentProps = any> = {
@@ -592,6 +599,7 @@ type WeaverseProjectConfigs = {
592
599
  projectId: string;
593
600
  weaverseHost: string;
594
601
  weaverseApiBase: string;
602
+ weaversePublicApiBase?: string;
595
603
  weaverseApiKey: string;
596
604
  weaverseVersion?: string;
597
605
  isDesignMode?: boolean;
@@ -935,6 +943,7 @@ declare module '@shopify/hydrogen' {
935
943
  WEAVERSE_API_KEY: string;
936
944
  WEAVERSE_HOST?: string;
937
945
  WEAVERSE_PROJECT_ID: string;
946
+ WEAVERSE_PUBLIC_API_BASE?: string;
938
947
  }
939
948
  }
940
949
  /**
package/dist/index.d.ts CHANGED
@@ -396,6 +396,7 @@ declare class WeaverseClient {
396
396
  */
397
397
  private readonly directFetch;
398
398
  private getApiUrl;
399
+ private isExternalPublicApiUrl;
399
400
  /**
400
401
  * Fetch data with caching support for both design mode and production.
401
402
  * Uses direct fetch in design mode, Hydrogen's withCache in production.
@@ -567,6 +568,12 @@ interface WeaverseHydrogenParams extends Omit<WeaverseCoreParams, 'ItemConstruct
567
568
  weaverseApiBase: string;
568
569
  weaverseApiKey: string;
569
570
  weaverseHost: string;
571
+ /**
572
+ * Public data API origin. Keep `weaverseHost` for Studio scripts/editor
573
+ * assets; point this at the Cloudflare proxy (`https://api.weaverse.io`)
574
+ * when edge caching is enabled.
575
+ */
576
+ weaversePublicApiBase?: string;
570
577
  weaverseVersion?: string;
571
578
  }
572
579
  type HydrogenComponent<T extends HydrogenComponentProps = any> = {
@@ -592,6 +599,7 @@ type WeaverseProjectConfigs = {
592
599
  projectId: string;
593
600
  weaverseHost: string;
594
601
  weaverseApiBase: string;
602
+ weaversePublicApiBase?: string;
595
603
  weaverseApiKey: string;
596
604
  weaverseVersion?: string;
597
605
  isDesignMode?: boolean;
@@ -935,6 +943,7 @@ declare module '@shopify/hydrogen' {
935
943
  WEAVERSE_API_KEY: string;
936
944
  WEAVERSE_HOST?: string;
937
945
  WEAVERSE_PROJECT_ID: string;
946
+ WEAVERSE_PUBLIC_API_BASE?: string;
938
947
  }
939
948
  }
940
949
  /**
package/dist/index.js CHANGED
@@ -297,6 +297,7 @@ function getWeaverseConfigs(request, env) {
297
297
  WEAVERSE_PROJECT_ID,
298
298
  WEAVERSE_API_KEY,
299
299
  WEAVERSE_HOST,
300
+ WEAVERSE_PUBLIC_API_BASE,
300
301
  PUBLIC_STORE_DOMAIN,
301
302
  PUBLIC_STOREFRONT_API_TOKEN
302
303
  } = env || {};
@@ -312,11 +313,14 @@ function getWeaverseConfigs(request, env) {
312
313
  } = queries;
313
314
  let url = new URL(request.url);
314
315
  let isRevisionPreview = url.searchParams.has("__revisionId");
315
- let resolvedWeaverseHost = weaverseHost || WEAVERSE_HOST || envFromProcess.WEAVERSE_HOST || "https://studio.weaverse.io";
316
+ let configuredWeaverseHost = WEAVERSE_HOST || envFromProcess.WEAVERSE_HOST;
317
+ let resolvedWeaverseHost = weaverseHost || configuredWeaverseHost || "https://studio.weaverse.io";
318
+ let resolvedWeaverseApiBase = weaverseHost ? weaverseHost : WEAVERSE_PUBLIC_API_BASE || envFromProcess.WEAVERSE_PUBLIC_API_BASE || (configuredWeaverseHost && configuredWeaverseHost !== "https://studio.weaverse.io" ? configuredWeaverseHost : "https://api.weaverse.io");
316
319
  return {
317
320
  projectId: weaverseProjectId || WEAVERSE_PROJECT_ID || envFromProcess.WEAVERSE_PROJECT_ID || "",
318
321
  weaverseHost: resolvedWeaverseHost,
319
- weaverseApiBase: resolvedWeaverseHost,
322
+ weaverseApiBase: resolvedWeaverseApiBase,
323
+ weaversePublicApiBase: resolvedWeaverseApiBase,
320
324
  weaverseApiKey: weaverseApiKey || WEAVERSE_API_KEY || envFromProcess.WEAVERSE_API_KEY || "",
321
325
  weaverseVersion: weaverseVersion || "",
322
326
  isDesignMode,
@@ -955,15 +959,21 @@ var StudioBridge = react$1.memo(({ context }) => {
955
959
  useStudio(context);
956
960
  return null;
957
961
  });
962
+ var registeredComponentLists = /* @__PURE__ */ new WeakSet();
958
963
  function RenderRoot(props) {
959
964
  const { data, components, dataContext } = props;
960
- for (const comp of [...components, ...defaultComponents]) {
961
- comp?.schema?.type && registerComponent({
962
- type: comp?.schema.type,
963
- Component: comp.default,
964
- schema: comp.schema,
965
- loader: comp.loader
966
- });
965
+ if (!registeredComponentLists.has(components)) {
966
+ for (const comp of [...components, ...defaultComponents]) {
967
+ if (comp?.schema?.type) {
968
+ registerComponent({
969
+ type: comp.schema.type,
970
+ Component: comp.default,
971
+ schema: comp.schema,
972
+ loader: comp.loader
973
+ });
974
+ }
975
+ }
976
+ registeredComponentLists.add(components);
967
977
  }
968
978
  const { page, configs, project, pageAssignment } = data || {};
969
979
  const weaverse = createWeaverseInstance({
@@ -988,7 +998,10 @@ var WeaverseHydrogenRoot = react$1.memo(
988
998
  errorComponent: ErrorComponent = ({ error }) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: error instanceof Error ? error.message : "An unexpected error occurred" })
989
999
  }) => {
990
1000
  const matches = reactRouter.useMatches();
991
- const enhancedDataContext = createWeaverseDataContext(matches);
1001
+ const enhancedDataContext = react$1.useMemo(
1002
+ () => createWeaverseDataContext(matches),
1003
+ [matches]
1004
+ );
992
1005
  const ownLoaderData = reactRouter.useLoaderData();
993
1006
  const weaverseData = react$1.useMemo(
994
1007
  () => pickWeaverseData(dataProp, ownLoaderData, matches),
@@ -1429,8 +1442,12 @@ var WeaverseClient = class {
1429
1442
  };
1430
1443
  // Helper method for building API URLs consistently
1431
1444
  getApiUrl(endpoint) {
1432
- const { weaverseHost } = this.configs;
1433
- return `${weaverseHost}/api/public/${endpoint}`;
1445
+ const { weaverseApiBase } = this.configs;
1446
+ return `${weaverseApiBase}/api/public/${endpoint}`;
1447
+ }
1448
+ isExternalPublicApiUrl(url) {
1449
+ const { weaverseApiBase, weaverseHost } = this.configs;
1450
+ return weaverseApiBase !== weaverseHost && url.startsWith(`${weaverseApiBase}/api/public/`);
1434
1451
  }
1435
1452
  /**
1436
1453
  * Fetch data with caching support for both design mode and production.
@@ -1463,7 +1480,7 @@ var WeaverseClient = class {
1463
1480
  cacheTarget || "default"
1464
1481
  ];
1465
1482
  let result;
1466
- if (this.configs.isDesignMode || this.configs.isRevisionPreview) {
1483
+ if (this.configs.isDesignMode || this.configs.isRevisionPreview || this.isExternalPublicApiUrl(url)) {
1467
1484
  result = await this.directFetch(url, fetchOptions);
1468
1485
  } else {
1469
1486
  result = await this.withCache.fetch(url, fetchOptions, {
@@ -1644,7 +1661,7 @@ var WeaverseClient = class {
1644
1661
  * Paginates automatically, never throws, returns accumulated results on partial failure.
1645
1662
  */
1646
1663
  async fetchCustomPages(opts) {
1647
- const { weaverseHost, projectId } = this.configs;
1664
+ const { weaverseApiBase, projectId } = this.configs;
1648
1665
  const entries = [];
1649
1666
  const MAX_PAGES = 100;
1650
1667
  let cursor = null;
@@ -1660,7 +1677,7 @@ var WeaverseClient = class {
1660
1677
  params.set("cursor", cursor);
1661
1678
  }
1662
1679
  const qs = params.toString();
1663
- const url = `${weaverseHost}/api/public/v1/projects/${projectId}/custom-pages${qs ? `?${qs}` : ""}`;
1680
+ const url = `${weaverseApiBase}/api/public/v1/projects/${projectId}/custom-pages${qs ? `?${qs}` : ""}`;
1664
1681
  try {
1665
1682
  const result = await this.fetchWithCache(url, { cacheTarget: "custom-pages" });
1666
1683
  entries.push(...result.data || []);