@weaverse/hydrogen 5.8.7 → 5.8.8
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 +135 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -914,6 +914,23 @@ var WeaverseClient = class {
|
|
|
914
914
|
}
|
|
915
915
|
return `${weaverseHost}/api/public/${endpoint}`;
|
|
916
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Fetch data with caching support for both design mode and production.
|
|
919
|
+
* Uses direct fetch in design mode, Hydrogen's withCache in production.
|
|
920
|
+
* Automatically includes projectId in cache key for multi-project isolation.
|
|
921
|
+
*
|
|
922
|
+
* @param url - The URL to fetch from
|
|
923
|
+
* @param options - Fetch options including optional cache strategy
|
|
924
|
+
* @returns Promise resolving to the fetched data
|
|
925
|
+
*
|
|
926
|
+
* @example
|
|
927
|
+
* ```typescript
|
|
928
|
+
* const data = await weaverse.fetchWithCache<MyData>(
|
|
929
|
+
* 'https://api.example.com/data',
|
|
930
|
+
* { method: 'POST', body: JSON.stringify({ key: 'value' }) }
|
|
931
|
+
* )
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
917
934
|
fetchWithCache = async (url, options = {}) => {
|
|
918
935
|
const strategy = options.strategy || CacheCustom(DEFAULT_CACHE_STRATEGY);
|
|
919
936
|
const cacheKey = [
|
|
@@ -938,6 +955,19 @@ var WeaverseClient = class {
|
|
|
938
955
|
}
|
|
939
956
|
return result.data;
|
|
940
957
|
};
|
|
958
|
+
/**
|
|
959
|
+
* Load theme settings from Weaverse API with fallback to schema defaults.
|
|
960
|
+
* Merges remote settings with local theme schema and handles design mode serialization.
|
|
961
|
+
*
|
|
962
|
+
* @param strategy - Optional cache strategy override
|
|
963
|
+
* @returns Promise resolving to theme settings response
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
* ```typescript
|
|
967
|
+
* const settings = await weaverse.loadThemeSettings()
|
|
968
|
+
* const primaryColor = settings.theme.colors?.primary
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
941
971
|
loadThemeSettings = async (strategy) => {
|
|
942
972
|
const defaultThemeSettings = generateDataFromSchema(this.themeSchema);
|
|
943
973
|
try {
|
|
@@ -1013,6 +1043,13 @@ var WeaverseClient = class {
|
|
|
1013
1043
|
};
|
|
1014
1044
|
}
|
|
1015
1045
|
};
|
|
1046
|
+
/**
|
|
1047
|
+
* Generate fallback page with default structure when page data is unavailable.
|
|
1048
|
+
* Used internally when API returns no page or when page needs default content.
|
|
1049
|
+
*
|
|
1050
|
+
* @param message - Custom message to display in the fallback page
|
|
1051
|
+
* @returns HydrogenPageData with single main component containing the message
|
|
1052
|
+
*/
|
|
1016
1053
|
generateFallbackPage = (message) => {
|
|
1017
1054
|
const rootId = crypto.randomUUID();
|
|
1018
1055
|
return {
|
|
@@ -1028,6 +1065,34 @@ var WeaverseClient = class {
|
|
|
1028
1065
|
]
|
|
1029
1066
|
};
|
|
1030
1067
|
};
|
|
1068
|
+
/**
|
|
1069
|
+
* Load page data from Weaverse API with optional route-level project override.
|
|
1070
|
+
* Fetches page content, executes component loaders, and handles empty items fallback.
|
|
1071
|
+
*
|
|
1072
|
+
* @param params - Optional page loading parameters
|
|
1073
|
+
* @param params.type - Page type (HOME, PAGE, PRODUCT, COLLECTION, etc.)
|
|
1074
|
+
* @param params.handle - Page handle for dynamic routes
|
|
1075
|
+
* @param params.locale - Locale override
|
|
1076
|
+
* @param params.projectId - Route-level project ID override (for multi-project)
|
|
1077
|
+
* @param params.strategy - Custom cache strategy override
|
|
1078
|
+
* @returns Promise resolving to page data or null on error
|
|
1079
|
+
*
|
|
1080
|
+
* @example
|
|
1081
|
+
* ```typescript
|
|
1082
|
+
* // Basic usage
|
|
1083
|
+
* const data = await weaverse.loadPage()
|
|
1084
|
+
*
|
|
1085
|
+
* // With page type
|
|
1086
|
+
* const data = await weaverse.loadPage({ type: 'HOME' })
|
|
1087
|
+
*
|
|
1088
|
+
* // Route-level project override
|
|
1089
|
+
* const data = await weaverse.loadPage({
|
|
1090
|
+
* type: 'PAGE',
|
|
1091
|
+
* handle: 'about',
|
|
1092
|
+
* projectId: 'campaign-project-123'
|
|
1093
|
+
* })
|
|
1094
|
+
* ```
|
|
1095
|
+
*/
|
|
1031
1096
|
loadPage = async (params = {}) => {
|
|
1032
1097
|
try {
|
|
1033
1098
|
const { request, storefront, basePageRequestBody, basePageConfigs } = this;
|