@weaverse/hydrogen 5.21.1 → 5.22.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.js +39 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -13
- package/dist/index.mjs.map +1 -1
- package/dist/types/weaverse-client.d.ts +7 -0
- package/dist/types/weaverse-client.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/weaverse-client.ts +88 -16
package/dist/index.js
CHANGED
|
@@ -1365,6 +1365,8 @@ var SMART_CACHE_STRATEGIES = {
|
|
|
1365
1365
|
staleIfError: CACHE_DURATIONS.LONG
|
|
1366
1366
|
}
|
|
1367
1367
|
};
|
|
1368
|
+
var bodyFreeCacheRequests = /* @__PURE__ */ new WeakSet();
|
|
1369
|
+
var BODY_FREE_CACHE_SENTINEL = "\0weaverse:body-free";
|
|
1368
1370
|
var WeaverseClient = class {
|
|
1369
1371
|
/** Builder API version used by this client. */
|
|
1370
1372
|
API = API_PATH;
|
|
@@ -1748,7 +1750,12 @@ var WeaverseClient = class {
|
|
|
1748
1750
|
"weaverse-fetch",
|
|
1749
1751
|
url,
|
|
1750
1752
|
options.method || "GET",
|
|
1751
|
-
fetchOptions.body,
|
|
1753
|
+
bodyFreeCacheRequests.has(options) ? BODY_FREE_CACHE_SENTINEL : fetchOptions.body,
|
|
1754
|
+
// WeakSet-derived discriminator: this slot cannot be produced by any
|
|
1755
|
+
// caller-supplied shape, so no external call can reach the marked
|
|
1756
|
+
// identity — even one that happens to send the sentinel string as its
|
|
1757
|
+
// body.
|
|
1758
|
+
bodyFreeCacheRequests.has(options),
|
|
1752
1759
|
this.configs.projectId,
|
|
1753
1760
|
cacheTarget || "default"
|
|
1754
1761
|
];
|
|
@@ -1767,6 +1774,19 @@ var WeaverseClient = class {
|
|
|
1767
1774
|
}
|
|
1768
1775
|
return result.data;
|
|
1769
1776
|
};
|
|
1777
|
+
/**
|
|
1778
|
+
* Safe origin of the incoming storefront request: scheme, host and explicit
|
|
1779
|
+
* port. Userinfo, path, query and fragment are dropped, so no customer
|
|
1780
|
+
* route or credential-bearing value leaves the storefront. Returns undefined
|
|
1781
|
+
* for a non-http(s) request so the field is simply omitted.
|
|
1782
|
+
*/
|
|
1783
|
+
safeStorefrontOrigin() {
|
|
1784
|
+
const { protocol, host } = this.parsedUrl;
|
|
1785
|
+
if (protocol !== "http:" && protocol !== "https:") {
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
return host ? `${protocol}//${host}` : void 0;
|
|
1789
|
+
}
|
|
1770
1790
|
/**
|
|
1771
1791
|
* Load theme settings from Weaverse API with fallback to schema defaults.
|
|
1772
1792
|
* Merges remote settings with local theme schema and handles design mode serialization.
|
|
@@ -1789,19 +1809,25 @@ var WeaverseClient = class {
|
|
|
1789
1809
|
throw new Error("Missing Weaverse projectId!");
|
|
1790
1810
|
}
|
|
1791
1811
|
const url = this.getApiUrl("project_configs");
|
|
1792
|
-
const body = JSON.stringify({
|
|
1812
|
+
const body = JSON.stringify({
|
|
1813
|
+
isDesignMode,
|
|
1814
|
+
projectId,
|
|
1815
|
+
storefrontUrl: this.safeStorefrontOrigin()
|
|
1816
|
+
});
|
|
1817
|
+
const themeSettingsOptions = {
|
|
1818
|
+
method: "POST",
|
|
1819
|
+
cacheTarget: "theme-settings",
|
|
1820
|
+
strategy,
|
|
1821
|
+
body,
|
|
1822
|
+
headers: {
|
|
1823
|
+
"Content-Type": "application/json",
|
|
1824
|
+
Accept: "application/json",
|
|
1825
|
+
"Accept-Encoding": "gzip, deflate, br"
|
|
1826
|
+
}
|
|
1827
|
+
};
|
|
1828
|
+
bodyFreeCacheRequests.add(themeSettingsOptions);
|
|
1793
1829
|
const [data, merchantOverrides] = await Promise.all([
|
|
1794
|
-
this.fetchWithCache(url,
|
|
1795
|
-
method: "POST",
|
|
1796
|
-
cacheTarget: "theme-settings",
|
|
1797
|
-
strategy,
|
|
1798
|
-
body,
|
|
1799
|
-
headers: {
|
|
1800
|
-
"Content-Type": "application/json",
|
|
1801
|
-
Accept: "application/json",
|
|
1802
|
-
"Accept-Encoding": "gzip, deflate, br"
|
|
1803
|
-
}
|
|
1804
|
-
}),
|
|
1830
|
+
this.fetchWithCache(url, themeSettingsOptions),
|
|
1805
1831
|
this.fetchMerchantOverrides(strategy)
|
|
1806
1832
|
]);
|
|
1807
1833
|
let result = data;
|