@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.mjs CHANGED
@@ -20129,12 +20129,15 @@ var ThemeLoader = class _ThemeLoader {
20129
20129
  logger.warn("[ThemeLoader] No configs found");
20130
20130
  return;
20131
20131
  }
20132
+ const eligibleConfigs = this.filterConfigsForDataInclusion(configMetadata);
20132
20133
  logger.debug("[ThemeLoader] Loading configs", {
20133
- total: configMetadata.length
20134
+ total: configMetadata.length,
20135
+ eligible: eligibleConfigs.length,
20136
+ filtered: configMetadata.length - eligibleConfigs.length
20134
20137
  });
20135
20138
  const flavor = getKVFlavor(this.swell.workerEnv);
20136
20139
  const storage = new ThemeFileCache(this.swell.workerEnv, flavor);
20137
- const kvHydrated = await storage.getFiles(configMetadata);
20140
+ const kvHydrated = await storage.getFiles(eligibleConfigs);
20138
20141
  const completeConfigs = await this.ensureConfigsHaveData(kvHydrated);
20139
20142
  for (const config of completeConfigs) {
20140
20143
  this.configs.set(config.file_path, config);
@@ -20274,6 +20277,26 @@ var ThemeLoader = class _ThemeLoader {
20274
20277
  preview: swellHeaders["deployment-mode"] === "editor" || swellHeaders["deployment-mode"] === "preview" ? true : { $ne: true }
20275
20278
  };
20276
20279
  }
20280
+ /**
20281
+ * Check if a config should have file_data based on FILE_DATA_INCLUDE_QUERY rules.
20282
+ * This mirrors the server-side logic to avoid fetching data for configs that won't have it.
20283
+ */
20284
+ shouldIncludeFileData(config) {
20285
+ const { file_path, file } = config;
20286
+ const pathConditionMet = !/^theme\/assets\//.test(file_path) || // NOT in theme/assets/
20287
+ /\.liquid$/.test(file_path) || // ends with .liquid
20288
+ /\.(css|js|svg)$/.test(file_path);
20289
+ const contentTypeMet = !file.content_type?.startsWith("image") && !file.content_type?.startsWith("video") || // NOT image AND NOT video
20290
+ file.content_type?.startsWith("image/svg");
20291
+ return pathConditionMet && contentTypeMet;
20292
+ }
20293
+ /**
20294
+ * Filter configs to only those eligible for file_data.
20295
+ * Aligns with FILE_DATA_INCLUDE_QUERY server-side logic.
20296
+ */
20297
+ filterConfigsForDataInclusion(configs) {
20298
+ return configs.filter((config) => this.shouldIncludeFileData(config));
20299
+ }
20277
20300
  /**
20278
20301
  * Build cache key with tenant isolation for metadata
20279
20302
  */
@@ -21458,15 +21481,14 @@ ${content.slice(pos)}`;
21458
21481
  async renderDataFields(data, fields) {
21459
21482
  const promises = [];
21460
21483
  for (const key of fields) {
21461
- if (typeof data[key] === "string") {
21462
- promises.push(
21463
- this.renderTemplateString(data[key], data).then((value) => {
21464
- if (data) {
21465
- data[key] = value;
21466
- }
21467
- })
21468
- );
21469
- }
21484
+ const promise = typeof data[key] === "string" ? this.renderTemplateString(data[key], data) : Promise.resolve();
21485
+ promises.push(
21486
+ promise.then((value) => {
21487
+ return value ? value : this.globals[key];
21488
+ }).then((value) => {
21489
+ data[key] = value;
21490
+ })
21491
+ );
21470
21492
  }
21471
21493
  if (promises.length > 0) {
21472
21494
  data = { ...data };
@@ -22609,7 +22631,6 @@ var HtmlCache = class {
22609
22631
  generateVersionHash(headers) {
22610
22632
  const swellData = this.extractSwellData(headers);
22611
22633
  const acceptLang = headers.get("accept-language") || "";
22612
- const accept = headers.get("accept") || "";
22613
22634
  const versionFactors = {
22614
22635
  store: headers.get("swell-storefront-id") || "",
22615
22636
  app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
@@ -22619,7 +22640,6 @@ var HtmlCache = class {
22619
22640
  currency: swellData["swell-currency"] || "USD",
22620
22641
  locale: headers.get("x-locale") || acceptLang.split(",")[0].trim().toLowerCase() || "default",
22621
22642
  context: headers.get("swell-storefront-context"),
22622
- accept,
22623
22643
  epoch: this.epoch
22624
22644
  };
22625
22645
  return md5(JSON.stringify(versionFactors));