@swell/apps-sdk 1.0.153 → 1.0.155
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 +33 -20
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +33 -20
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +33 -20
- package/dist/index.mjs.map +2 -2
- package/dist/src/resources.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -860,18 +860,31 @@ var StorefrontResource = class {
|
|
|
860
860
|
return this._compatibilityProps[prop];
|
|
861
861
|
}
|
|
862
862
|
};
|
|
863
|
+
var RESOURCE_CLONE_PROPS = Object.freeze([
|
|
864
|
+
"_defaultGetter",
|
|
865
|
+
"_getResourceObject",
|
|
866
|
+
"_collection",
|
|
867
|
+
"_swell",
|
|
868
|
+
"_query",
|
|
869
|
+
"_params",
|
|
870
|
+
"_id",
|
|
871
|
+
"_resourceName"
|
|
872
|
+
]);
|
|
863
873
|
function cloneStorefrontResource(input) {
|
|
864
|
-
const resourceName = input._resourceName;
|
|
874
|
+
const resourceName = input._resourceName || input.constructor?.name;
|
|
865
875
|
const ClonedClass = class extends StorefrontResource {
|
|
866
876
|
};
|
|
867
877
|
Object.defineProperty(ClonedClass, "name", {
|
|
868
878
|
value: resourceName
|
|
869
879
|
});
|
|
870
880
|
const clone = new ClonedClass(input._getter);
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
881
|
+
for (const key of RESOURCE_CLONE_PROPS) {
|
|
882
|
+
if (input[key] !== void 0) {
|
|
883
|
+
Object.defineProperty(clone, key, {
|
|
884
|
+
value: input[key]
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
}
|
|
875
888
|
return clone;
|
|
876
889
|
}
|
|
877
890
|
var SwellStorefrontResource = class extends StorefrontResource {
|
|
@@ -890,7 +903,7 @@ var SwellStorefrontResource = class extends StorefrontResource {
|
|
|
890
903
|
_getProxy() {
|
|
891
904
|
return super._getProxy();
|
|
892
905
|
}
|
|
893
|
-
|
|
906
|
+
_getResourceObject() {
|
|
894
907
|
const { _swell, _collection } = this;
|
|
895
908
|
this._resource = (_swell?.storefront)[_collection];
|
|
896
909
|
if (_swell && _collection.startsWith("content/")) {
|
|
@@ -947,7 +960,7 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
947
960
|
return properQuery;
|
|
948
961
|
}
|
|
949
962
|
_defaultGetter() {
|
|
950
|
-
const resource = this.
|
|
963
|
+
const resource = this._getResourceObject();
|
|
951
964
|
async function defaultGetter() {
|
|
952
965
|
return resource.list(this._query);
|
|
953
966
|
}
|
|
@@ -1074,7 +1087,7 @@ var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
|
1074
1087
|
return super._getProxy();
|
|
1075
1088
|
}
|
|
1076
1089
|
_defaultGetter() {
|
|
1077
|
-
const resource = this.
|
|
1090
|
+
const resource = this._getResourceObject();
|
|
1078
1091
|
async function defaultGetter() {
|
|
1079
1092
|
return resource.get(this._id, this._query);
|
|
1080
1093
|
}
|
|
@@ -1133,7 +1146,7 @@ var SwellStorefrontSingleton = class extends SwellStorefrontResource {
|
|
|
1133
1146
|
_collection,
|
|
1134
1147
|
_swell: { storefrontContext }
|
|
1135
1148
|
} = this;
|
|
1136
|
-
const resource = this.
|
|
1149
|
+
const resource = this._getResourceObject();
|
|
1137
1150
|
async function defaultGetter() {
|
|
1138
1151
|
if (storefrontContext[_collection] !== void 0) {
|
|
1139
1152
|
return storefrontContext[_collection];
|
|
@@ -7761,7 +7774,7 @@ var MAX_TTL = YEAR;
|
|
|
7761
7774
|
var SHORT_TTL = 5 * SECOND;
|
|
7762
7775
|
|
|
7763
7776
|
// src/cache/worker-cache-proxy.ts
|
|
7764
|
-
var CACHE_NAME = "swell-cache-
|
|
7777
|
+
var CACHE_NAME = "swell-cache-v011";
|
|
7765
7778
|
var CACHE_KEY_ORIGIN = "https://cache.swell.store";
|
|
7766
7779
|
var WorkerCacheProxy = class {
|
|
7767
7780
|
swell;
|
|
@@ -7810,6 +7823,7 @@ var WorkerCacheProxy = class {
|
|
|
7810
7823
|
}
|
|
7811
7824
|
});
|
|
7812
7825
|
await cache.put(keyUrl, response);
|
|
7826
|
+
logger.debug("[SDK] cache put done", { keyUrl });
|
|
7813
7827
|
} catch {
|
|
7814
7828
|
}
|
|
7815
7829
|
}
|
|
@@ -20631,9 +20645,9 @@ var ThemeLoader = class {
|
|
|
20631
20645
|
fields: "id, name, type, file, file_path, hash"
|
|
20632
20646
|
// NO file_data
|
|
20633
20647
|
};
|
|
20648
|
+
const cache = new WorkerCacheProxy(this.swell);
|
|
20649
|
+
const versionHash = this.swell.swellHeaders["theme-version-hash"];
|
|
20634
20650
|
try {
|
|
20635
|
-
const cache = new WorkerCacheProxy(this.swell);
|
|
20636
|
-
const versionHash = this.swell.swellHeaders["theme-version-hash"];
|
|
20637
20651
|
const cached = await cache.get(
|
|
20638
20652
|
"/:themes:configs",
|
|
20639
20653
|
query,
|
|
@@ -20654,14 +20668,13 @@ var ThemeLoader = class {
|
|
|
20654
20668
|
query
|
|
20655
20669
|
);
|
|
20656
20670
|
const configs = response?.results || [];
|
|
20657
|
-
|
|
20658
|
-
|
|
20659
|
-
|
|
20660
|
-
|
|
20661
|
-
|
|
20662
|
-
|
|
20663
|
-
|
|
20664
|
-
logger.warn("[ThemeLoader] Cache write failed", err);
|
|
20671
|
+
const ctx = this.swell.workerCtx || globalThis.executionContext;
|
|
20672
|
+
if (ctx && typeof ctx.waitUntil === "function") {
|
|
20673
|
+
ctx.waitUntil(
|
|
20674
|
+
cache.put("/:themes:configs", query, configs, {
|
|
20675
|
+
version: versionHash || null
|
|
20676
|
+
})
|
|
20677
|
+
);
|
|
20665
20678
|
}
|
|
20666
20679
|
return configs;
|
|
20667
20680
|
}
|