@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.mjs
CHANGED
|
@@ -713,18 +713,31 @@ var StorefrontResource = class {
|
|
|
713
713
|
return this._compatibilityProps[prop];
|
|
714
714
|
}
|
|
715
715
|
};
|
|
716
|
+
var RESOURCE_CLONE_PROPS = Object.freeze([
|
|
717
|
+
"_defaultGetter",
|
|
718
|
+
"_getResourceObject",
|
|
719
|
+
"_collection",
|
|
720
|
+
"_swell",
|
|
721
|
+
"_query",
|
|
722
|
+
"_params",
|
|
723
|
+
"_id",
|
|
724
|
+
"_resourceName"
|
|
725
|
+
]);
|
|
716
726
|
function cloneStorefrontResource(input) {
|
|
717
|
-
const resourceName = input._resourceName;
|
|
727
|
+
const resourceName = input._resourceName || input.constructor?.name;
|
|
718
728
|
const ClonedClass = class extends StorefrontResource {
|
|
719
729
|
};
|
|
720
730
|
Object.defineProperty(ClonedClass, "name", {
|
|
721
731
|
value: resourceName
|
|
722
732
|
});
|
|
723
733
|
const clone = new ClonedClass(input._getter);
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
734
|
+
for (const key of RESOURCE_CLONE_PROPS) {
|
|
735
|
+
if (input[key] !== void 0) {
|
|
736
|
+
Object.defineProperty(clone, key, {
|
|
737
|
+
value: input[key]
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
728
741
|
return clone;
|
|
729
742
|
}
|
|
730
743
|
var SwellStorefrontResource = class extends StorefrontResource {
|
|
@@ -743,7 +756,7 @@ var SwellStorefrontResource = class extends StorefrontResource {
|
|
|
743
756
|
_getProxy() {
|
|
744
757
|
return super._getProxy();
|
|
745
758
|
}
|
|
746
|
-
|
|
759
|
+
_getResourceObject() {
|
|
747
760
|
const { _swell, _collection } = this;
|
|
748
761
|
this._resource = (_swell?.storefront)[_collection];
|
|
749
762
|
if (_swell && _collection.startsWith("content/")) {
|
|
@@ -800,7 +813,7 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
800
813
|
return properQuery;
|
|
801
814
|
}
|
|
802
815
|
_defaultGetter() {
|
|
803
|
-
const resource = this.
|
|
816
|
+
const resource = this._getResourceObject();
|
|
804
817
|
async function defaultGetter() {
|
|
805
818
|
return resource.list(this._query);
|
|
806
819
|
}
|
|
@@ -927,7 +940,7 @@ var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
|
927
940
|
return super._getProxy();
|
|
928
941
|
}
|
|
929
942
|
_defaultGetter() {
|
|
930
|
-
const resource = this.
|
|
943
|
+
const resource = this._getResourceObject();
|
|
931
944
|
async function defaultGetter() {
|
|
932
945
|
return resource.get(this._id, this._query);
|
|
933
946
|
}
|
|
@@ -986,7 +999,7 @@ var SwellStorefrontSingleton = class extends SwellStorefrontResource {
|
|
|
986
999
|
_collection,
|
|
987
1000
|
_swell: { storefrontContext }
|
|
988
1001
|
} = this;
|
|
989
|
-
const resource = this.
|
|
1002
|
+
const resource = this._getResourceObject();
|
|
990
1003
|
async function defaultGetter() {
|
|
991
1004
|
if (storefrontContext[_collection] !== void 0) {
|
|
992
1005
|
return storefrontContext[_collection];
|
|
@@ -7614,7 +7627,7 @@ var MAX_TTL = YEAR;
|
|
|
7614
7627
|
var SHORT_TTL = 5 * SECOND;
|
|
7615
7628
|
|
|
7616
7629
|
// src/cache/worker-cache-proxy.ts
|
|
7617
|
-
var CACHE_NAME = "swell-cache-
|
|
7630
|
+
var CACHE_NAME = "swell-cache-v011";
|
|
7618
7631
|
var CACHE_KEY_ORIGIN = "https://cache.swell.store";
|
|
7619
7632
|
var WorkerCacheProxy = class {
|
|
7620
7633
|
swell;
|
|
@@ -7663,6 +7676,7 @@ var WorkerCacheProxy = class {
|
|
|
7663
7676
|
}
|
|
7664
7677
|
});
|
|
7665
7678
|
await cache.put(keyUrl, response);
|
|
7679
|
+
logger.debug("[SDK] cache put done", { keyUrl });
|
|
7666
7680
|
} catch {
|
|
7667
7681
|
}
|
|
7668
7682
|
}
|
|
@@ -20492,9 +20506,9 @@ var ThemeLoader = class {
|
|
|
20492
20506
|
fields: "id, name, type, file, file_path, hash"
|
|
20493
20507
|
// NO file_data
|
|
20494
20508
|
};
|
|
20509
|
+
const cache = new WorkerCacheProxy(this.swell);
|
|
20510
|
+
const versionHash = this.swell.swellHeaders["theme-version-hash"];
|
|
20495
20511
|
try {
|
|
20496
|
-
const cache = new WorkerCacheProxy(this.swell);
|
|
20497
|
-
const versionHash = this.swell.swellHeaders["theme-version-hash"];
|
|
20498
20512
|
const cached = await cache.get(
|
|
20499
20513
|
"/:themes:configs",
|
|
20500
20514
|
query,
|
|
@@ -20515,14 +20529,13 @@ var ThemeLoader = class {
|
|
|
20515
20529
|
query
|
|
20516
20530
|
);
|
|
20517
20531
|
const configs = response?.results || [];
|
|
20518
|
-
|
|
20519
|
-
|
|
20520
|
-
|
|
20521
|
-
|
|
20522
|
-
|
|
20523
|
-
|
|
20524
|
-
|
|
20525
|
-
logger.warn("[ThemeLoader] Cache write failed", err);
|
|
20532
|
+
const ctx = this.swell.workerCtx || globalThis.executionContext;
|
|
20533
|
+
if (ctx && typeof ctx.waitUntil === "function") {
|
|
20534
|
+
ctx.waitUntil(
|
|
20535
|
+
cache.put("/:themes:configs", query, configs, {
|
|
20536
|
+
version: versionHash || null
|
|
20537
|
+
})
|
|
20538
|
+
);
|
|
20526
20539
|
}
|
|
20527
20540
|
return configs;
|
|
20528
20541
|
}
|