@swell/apps-sdk 1.0.187 → 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 +25 -4
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +25 -4
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +25 -4
- package/dist/index.mjs.map +2 -2
- package/dist/src/api.d.ts +7 -0
- package/dist/src/resources/swell_types.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4983,12 +4983,17 @@ function transformSwellVariant(params, product, variant) {
|
|
|
4983
4983
|
var SwellVariant = class extends SwellStorefrontRecord {
|
|
4984
4984
|
product;
|
|
4985
4985
|
constructor(swell, product, id, query) {
|
|
4986
|
+
const params = swell.queryParams;
|
|
4986
4987
|
super(swell, "products:variants", id, query, async function() {
|
|
4987
4988
|
const variant = await this._swell.get(
|
|
4988
|
-
"/products:variants
|
|
4989
|
-
{ id: this._id }
|
|
4989
|
+
"/products:variants/:last",
|
|
4990
|
+
{ $or: [{ id: this._id }, { sku: this._id }] }
|
|
4991
|
+
);
|
|
4992
|
+
return transformSwellVariant(
|
|
4993
|
+
params,
|
|
4994
|
+
product instanceof SwellStorefrontRecord ? await product.resolve() : product,
|
|
4995
|
+
variant
|
|
4990
4996
|
);
|
|
4991
|
-
return variant ?? null;
|
|
4992
4997
|
});
|
|
4993
4998
|
this.product = product;
|
|
4994
4999
|
}
|
|
@@ -5215,12 +5220,27 @@ var Swell = class _Swell {
|
|
|
5215
5220
|
shouldBypassCache() {
|
|
5216
5221
|
return this.headers?.["x-cache-bypass"] === "revalidation";
|
|
5217
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
|
+
}
|
|
5218
5234
|
/**
|
|
5219
5235
|
* Fetches a resource.
|
|
5220
5236
|
* First attempts to fetch from cache.
|
|
5221
5237
|
*/
|
|
5222
5238
|
async getCachedResource(key, args, handler, isCacheble = true) {
|
|
5223
|
-
const cacheKey = getCacheKey(key, [
|
|
5239
|
+
const cacheKey = getCacheKey(key, [
|
|
5240
|
+
this.instanceId,
|
|
5241
|
+
this.getAccountCacheKey(),
|
|
5242
|
+
args
|
|
5243
|
+
]);
|
|
5224
5244
|
const cache = this.getResourceCache();
|
|
5225
5245
|
if (this.shouldBypassCache()) {
|
|
5226
5246
|
return cache.fetch(cacheKey, handler, void 0, isCacheble);
|
|
@@ -5387,6 +5407,7 @@ var Swell = class _Swell {
|
|
|
5387
5407
|
if (this.isStorefrontRequestCacheable(method, url, opt)) {
|
|
5388
5408
|
const key = getCacheKey("request", [
|
|
5389
5409
|
this.instanceId,
|
|
5410
|
+
this.getAccountCacheKey(),
|
|
5390
5411
|
method,
|
|
5391
5412
|
url,
|
|
5392
5413
|
id,
|