@swell/apps-sdk 1.0.163 → 1.0.165

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.js CHANGED
@@ -20148,12 +20148,15 @@ ${injects.join("\n")}<\/script>`;
20148
20148
  logger.warn("[ThemeLoader] No configs found");
20149
20149
  return;
20150
20150
  }
20151
+ const eligibleConfigs = this.filterConfigsForDataInclusion(configMetadata);
20151
20152
  logger.debug("[ThemeLoader] Loading configs", {
20152
- total: configMetadata.length
20153
+ total: configMetadata.length,
20154
+ eligible: eligibleConfigs.length,
20155
+ filtered: configMetadata.length - eligibleConfigs.length
20153
20156
  });
20154
20157
  const flavor = getKVFlavor(this.swell.workerEnv);
20155
20158
  const storage = new ThemeFileCache(this.swell.workerEnv, flavor);
20156
- const kvHydrated = await storage.getFiles(configMetadata);
20159
+ const kvHydrated = await storage.getFiles(eligibleConfigs);
20157
20160
  const completeConfigs = await this.ensureConfigsHaveData(kvHydrated);
20158
20161
  for (const config of completeConfigs) {
20159
20162
  this.configs.set(config.file_path, config);
@@ -20293,6 +20296,26 @@ ${injects.join("\n")}<\/script>`;
20293
20296
  preview: swellHeaders["deployment-mode"] === "editor" || swellHeaders["deployment-mode"] === "preview" ? true : { $ne: true }
20294
20297
  };
20295
20298
  }
20299
+ /**
20300
+ * Check if a config should have file_data based on FILE_DATA_INCLUDE_QUERY rules.
20301
+ * This mirrors the server-side logic to avoid fetching data for configs that won't have it.
20302
+ */
20303
+ shouldIncludeFileData(config) {
20304
+ const { file_path, file } = config;
20305
+ const pathConditionMet = !/^theme\/assets\//.test(file_path) || // NOT in theme/assets/
20306
+ /\.liquid$/.test(file_path) || // ends with .liquid
20307
+ /\.(css|js|svg)$/.test(file_path);
20308
+ const contentTypeMet = !file.content_type?.startsWith("image") && !file.content_type?.startsWith("video") || // NOT image AND NOT video
20309
+ file.content_type?.startsWith("image/svg");
20310
+ return pathConditionMet && contentTypeMet;
20311
+ }
20312
+ /**
20313
+ * Filter configs to only those eligible for file_data.
20314
+ * Aligns with FILE_DATA_INCLUDE_QUERY server-side logic.
20315
+ */
20316
+ filterConfigsForDataInclusion(configs) {
20317
+ return configs.filter((config) => this.shouldIncludeFileData(config));
20318
+ }
20296
20319
  /**
20297
20320
  * Build cache key with tenant isolation for metadata
20298
20321
  */
@@ -22628,17 +22651,15 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
22628
22651
  generateVersionHash(headers) {
22629
22652
  const swellData = this.extractSwellData(headers);
22630
22653
  const acceptLang = headers.get("accept-language") || "";
22631
- const accept = headers.get("accept") || "";
22632
22654
  const versionFactors = {
22633
22655
  store: headers.get("swell-storefront-id") || "",
22634
- app: (headers.get("swell-app-id") || "") + "@" + (swellData["swell-app-version"] || ""),
22656
+ app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
22635
22657
  auth: headers.get("swell-access-token") || "",
22636
22658
  theme: headers.get("swell-theme-version-hash") || "",
22637
22659
  modified: headers.get("swell-cache-modified") || "",
22638
22660
  currency: swellData["swell-currency"] || "USD",
22639
22661
  locale: headers.get("x-locale") || acceptLang.split(",")[0].trim().toLowerCase() || "default",
22640
22662
  context: headers.get("swell-storefront-context"),
22641
- accept,
22642
22663
  epoch: this.epoch
22643
22664
  };
22644
22665
  return md5(JSON.stringify(versionFactors));