@weaverse/hydrogen 5.15.2 → 5.16.1
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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +32 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
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
|
|
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:
|
|
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 = 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
|
-
|
|
961
|
-
comp
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
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 = memo(
|
|
|
988
998
|
errorComponent: ErrorComponent = ({ error }) => /* @__PURE__ */ jsx("div", { children: error instanceof Error ? error.message : "An unexpected error occurred" })
|
|
989
999
|
}) => {
|
|
990
1000
|
const matches = useMatches();
|
|
991
|
-
const enhancedDataContext =
|
|
1001
|
+
const enhancedDataContext = useMemo(
|
|
1002
|
+
() => createWeaverseDataContext(matches),
|
|
1003
|
+
[matches]
|
|
1004
|
+
);
|
|
992
1005
|
const ownLoaderData = useLoaderData();
|
|
993
1006
|
const weaverseData = 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 {
|
|
1433
|
-
return `${
|
|
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 {
|
|
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 = `${
|
|
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 || []);
|