@swell/apps-sdk 1.0.188 → 1.0.189
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.cjs +17 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +17 -1
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +17 -1
- package/dist/index.mjs.map +2 -2
- package/dist/src/api.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5220,12 +5220,27 @@ var Swell = class _Swell {
|
|
|
5220
5220
|
shouldBypassCache() {
|
|
5221
5221
|
return this.headers?.["x-cache-bypass"] === "revalidation";
|
|
5222
5222
|
}
|
|
5223
|
+
/**
|
|
5224
|
+
* Returns fields from the current account that may affect requests.
|
|
5225
|
+
* Currently, only the 'group' field is returned.
|
|
5226
|
+
* It is preferable to use the account_id from storefrontContext rather than the swell-session cookie, as the cookie contains a lot of other data
|
|
5227
|
+
* This increases the overall cache size
|
|
5228
|
+
*/
|
|
5229
|
+
getAccountCacheKey() {
|
|
5230
|
+
const storefrontContext = this.storefrontContext;
|
|
5231
|
+
const group = storefrontContext?.account?.group || "";
|
|
5232
|
+
return `${group}`;
|
|
5233
|
+
}
|
|
5223
5234
|
/**
|
|
5224
5235
|
* Fetches a resource.
|
|
5225
5236
|
* First attempts to fetch from cache.
|
|
5226
5237
|
*/
|
|
5227
5238
|
async getCachedResource(key, args, handler, isCacheble = true) {
|
|
5228
|
-
const cacheKey = getCacheKey(key, [
|
|
5239
|
+
const cacheKey = getCacheKey(key, [
|
|
5240
|
+
this.instanceId,
|
|
5241
|
+
this.getAccountCacheKey(),
|
|
5242
|
+
args
|
|
5243
|
+
]);
|
|
5229
5244
|
const cache = this.getResourceCache();
|
|
5230
5245
|
if (this.shouldBypassCache()) {
|
|
5231
5246
|
return cache.fetch(cacheKey, handler, void 0, isCacheble);
|
|
@@ -5392,6 +5407,7 @@ var Swell = class _Swell {
|
|
|
5392
5407
|
if (this.isStorefrontRequestCacheable(method, url, opt)) {
|
|
5393
5408
|
const key = getCacheKey("request", [
|
|
5394
5409
|
this.instanceId,
|
|
5410
|
+
this.getAccountCacheKey(),
|
|
5395
5411
|
method,
|
|
5396
5412
|
url,
|
|
5397
5413
|
id,
|