@swell/apps-sdk 1.0.164 → 1.0.166
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 -13
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +33 -13
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +33 -13
- package/dist/index.mjs.map +2 -2
- package/dist/src/theme/theme-loader.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20269,12 +20269,15 @@ var ThemeLoader = class _ThemeLoader {
|
|
|
20269
20269
|
logger.warn("[ThemeLoader] No configs found");
|
|
20270
20270
|
return;
|
|
20271
20271
|
}
|
|
20272
|
+
const eligibleConfigs = this.filterConfigsForDataInclusion(configMetadata);
|
|
20272
20273
|
logger.debug("[ThemeLoader] Loading configs", {
|
|
20273
|
-
total: configMetadata.length
|
|
20274
|
+
total: configMetadata.length,
|
|
20275
|
+
eligible: eligibleConfigs.length,
|
|
20276
|
+
filtered: configMetadata.length - eligibleConfigs.length
|
|
20274
20277
|
});
|
|
20275
20278
|
const flavor = getKVFlavor(this.swell.workerEnv);
|
|
20276
20279
|
const storage = new ThemeFileCache(this.swell.workerEnv, flavor);
|
|
20277
|
-
const kvHydrated = await storage.getFiles(
|
|
20280
|
+
const kvHydrated = await storage.getFiles(eligibleConfigs);
|
|
20278
20281
|
const completeConfigs = await this.ensureConfigsHaveData(kvHydrated);
|
|
20279
20282
|
for (const config of completeConfigs) {
|
|
20280
20283
|
this.configs.set(config.file_path, config);
|
|
@@ -20414,6 +20417,26 @@ var ThemeLoader = class _ThemeLoader {
|
|
|
20414
20417
|
preview: swellHeaders["deployment-mode"] === "editor" || swellHeaders["deployment-mode"] === "preview" ? true : { $ne: true }
|
|
20415
20418
|
};
|
|
20416
20419
|
}
|
|
20420
|
+
/**
|
|
20421
|
+
* Check if a config should have file_data based on FILE_DATA_INCLUDE_QUERY rules.
|
|
20422
|
+
* This mirrors the server-side logic to avoid fetching data for configs that won't have it.
|
|
20423
|
+
*/
|
|
20424
|
+
shouldIncludeFileData(config) {
|
|
20425
|
+
const { file_path, file } = config;
|
|
20426
|
+
const pathConditionMet = !/^theme\/assets\//.test(file_path) || // NOT in theme/assets/
|
|
20427
|
+
/\.liquid$/.test(file_path) || // ends with .liquid
|
|
20428
|
+
/\.(css|js|svg)$/.test(file_path);
|
|
20429
|
+
const contentTypeMet = !file.content_type?.startsWith("image") && !file.content_type?.startsWith("video") || // NOT image AND NOT video
|
|
20430
|
+
file.content_type?.startsWith("image/svg");
|
|
20431
|
+
return pathConditionMet && contentTypeMet;
|
|
20432
|
+
}
|
|
20433
|
+
/**
|
|
20434
|
+
* Filter configs to only those eligible for file_data.
|
|
20435
|
+
* Aligns with FILE_DATA_INCLUDE_QUERY server-side logic.
|
|
20436
|
+
*/
|
|
20437
|
+
filterConfigsForDataInclusion(configs) {
|
|
20438
|
+
return configs.filter((config) => this.shouldIncludeFileData(config));
|
|
20439
|
+
}
|
|
20417
20440
|
/**
|
|
20418
20441
|
* Build cache key with tenant isolation for metadata
|
|
20419
20442
|
*/
|
|
@@ -21598,15 +21621,14 @@ ${content.slice(pos)}`;
|
|
|
21598
21621
|
async renderDataFields(data, fields) {
|
|
21599
21622
|
const promises = [];
|
|
21600
21623
|
for (const key of fields) {
|
|
21601
|
-
|
|
21602
|
-
|
|
21603
|
-
|
|
21604
|
-
|
|
21605
|
-
|
|
21606
|
-
|
|
21607
|
-
|
|
21608
|
-
|
|
21609
|
-
}
|
|
21624
|
+
const promise = typeof data[key] === "string" ? this.renderTemplateString(data[key], data) : Promise.resolve();
|
|
21625
|
+
promises.push(
|
|
21626
|
+
promise.then((value) => {
|
|
21627
|
+
return value ? value : this.globals[key];
|
|
21628
|
+
}).then((value) => {
|
|
21629
|
+
data[key] = value;
|
|
21630
|
+
})
|
|
21631
|
+
);
|
|
21610
21632
|
}
|
|
21611
21633
|
if (promises.length > 0) {
|
|
21612
21634
|
data = { ...data };
|
|
@@ -22749,7 +22771,6 @@ var HtmlCache = class {
|
|
|
22749
22771
|
generateVersionHash(headers) {
|
|
22750
22772
|
const swellData = this.extractSwellData(headers);
|
|
22751
22773
|
const acceptLang = headers.get("accept-language") || "";
|
|
22752
|
-
const accept = headers.get("accept") || "";
|
|
22753
22774
|
const versionFactors = {
|
|
22754
22775
|
store: headers.get("swell-storefront-id") || "",
|
|
22755
22776
|
app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
|
|
@@ -22759,7 +22780,6 @@ var HtmlCache = class {
|
|
|
22759
22780
|
currency: swellData["swell-currency"] || "USD",
|
|
22760
22781
|
locale: headers.get("x-locale") || acceptLang.split(",")[0].trim().toLowerCase() || "default",
|
|
22761
22782
|
context: headers.get("swell-storefront-context"),
|
|
22762
|
-
accept,
|
|
22763
22783
|
epoch: this.epoch
|
|
22764
22784
|
};
|
|
22765
22785
|
return md5(JSON.stringify(versionFactors));
|