@swell/apps-sdk 1.0.168 → 1.0.169

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
@@ -1106,10 +1106,10 @@ var FILE_DATA_INCLUDE_QUERY = {
1106
1106
  { content_type: { $regex: "^image/svg" } }
1107
1107
  ]
1108
1108
  },
1109
- // Do not return assets unless they end with .liquid.[ext] or css/js/svg
1109
+ // Do not return assets unless they end with .liquid or css/js/svg
1110
1110
  $or: [
1111
1111
  { file_path: { $regex: "^(?!theme/assets/)" } },
1112
- { file_path: { $regex: ".liquid.[a-zA-Z0-9]+$" } },
1112
+ { file_path: { $regex: ".liquid$" } },
1113
1113
  { file_path: { $regex: ".(css|js|svg)$" } }
1114
1114
  ]
1115
1115
  }
@@ -7632,6 +7632,33 @@ var ThemeFileCache = class {
7632
7632
  }
7633
7633
  };
7634
7634
 
7635
+ // src/cache/content-cache.ts
7636
+ var DEFAULT_TTL2 = 90 * 24 * 60 * 60 * 1e3;
7637
+ var ContentCache = class {
7638
+ cache;
7639
+ defaultTtl;
7640
+ constructor(options) {
7641
+ const { defaultTtl, ...cacheOptions } = options || {};
7642
+ this.defaultTtl = defaultTtl ?? DEFAULT_TTL2;
7643
+ this.cache = new Cache({
7644
+ ttl: this.defaultTtl,
7645
+ ...cacheOptions
7646
+ });
7647
+ }
7648
+ /**
7649
+ * Get content from cache
7650
+ */
7651
+ async get(key) {
7652
+ return this.cache.get(key);
7653
+ }
7654
+ /**
7655
+ * Set content in cache
7656
+ */
7657
+ async set(key, value, ttl) {
7658
+ await this.cache.set(key, value, ttl ?? this.defaultTtl);
7659
+ }
7660
+ };
7661
+
7635
7662
  // src/resources/addresses.ts
7636
7663
  var SwellAddresses = class extends SwellStorefrontCollection {
7637
7664
  constructor(swell, query) {
@@ -18562,7 +18589,9 @@ function bind15(liquidSwell) {
18562
18589
  scope[filepath] = yield evalToken6(this.withVar, ctx);
18563
18590
  }
18564
18591
  ctx.push(ctx.opts.jekyllInclude ? { include: scope } : scope);
18565
- const output = yield liquidSwell.getComponentPath(filepath).then((path) => liquidSwell.getThemeConfig(path)).then((themeConfig) => liquidSwell.renderTemplate(themeConfig, scope));
18592
+ const output = yield liquidSwell.getComponentPath(filepath).then((path) => liquidSwell.getThemeConfig(path)).then(
18593
+ (themeConfig) => liquidSwell.renderTemplate(themeConfig, ctx.getAll())
18594
+ );
18566
18595
  emitter.write(output);
18567
18596
  ctx.pop();
18568
18597
  ctx.restoreRegister(saved);
@@ -18656,7 +18685,7 @@ var tags = {
18656
18685
  };
18657
18686
  function bindTags(liquidSwell) {
18658
18687
  Object.entries(tags).forEach(
18659
- ([tag, bind64]) => liquidSwell.registerTag(tag, bind64(liquidSwell))
18688
+ ([tag, bind65]) => liquidSwell.registerTag(tag, bind65(liquidSwell))
18660
18689
  );
18661
18690
  }
18662
18691
 
@@ -18818,7 +18847,7 @@ function applyDateFormat(type, date) {
18818
18847
  }
18819
18848
  }
18820
18849
  function isCustomDateFormat(format) {
18821
- return format.includes("%");
18850
+ return Boolean(format) && format.includes("%");
18822
18851
  }
18823
18852
  function applyStrftimeFormat(format, date) {
18824
18853
  return strftime(format, date);
@@ -19353,6 +19382,38 @@ function bind57(_liquidSwell) {
19353
19382
  };
19354
19383
  }
19355
19384
 
19385
+ // src/liquid/filters/shopify/img_url.ts
19386
+ function bind58(_liquidSwell) {
19387
+ return function filterImgUrl(input, ...params) {
19388
+ if (!input) return "";
19389
+ let url;
19390
+ if (typeof input === "object") {
19391
+ if (input.url) {
19392
+ url = input.url;
19393
+ } else {
19394
+ return "";
19395
+ }
19396
+ } else {
19397
+ url = String(input);
19398
+ }
19399
+ const query = [];
19400
+ params.forEach((param) => {
19401
+ if (!param) {
19402
+ return;
19403
+ }
19404
+ const [key, value] = param.includes(":") ? param.split(":").map((s) => s.trim()) : [param, void 0];
19405
+ if (/^w\d+$/.test(key)) {
19406
+ query.push(`width=${key.slice(1)}`);
19407
+ } else if (/^h\d+$/.test(key)) {
19408
+ query.push(`height=${key.slice(1)}`);
19409
+ } else if (key === "crop" && value) {
19410
+ query.push(`crop=${encodeURIComponent(value)}`);
19411
+ }
19412
+ });
19413
+ return query.length ? `${url}?${query.join("&")}` : url;
19414
+ };
19415
+ }
19416
+
19356
19417
  // src/liquid/filters/shopify/item_count_for_variant.ts
19357
19418
  var item_count_for_variant_default = {
19358
19419
  bind(_liquidSwell) {
@@ -19367,14 +19428,14 @@ var item_count_for_variant_default = {
19367
19428
  };
19368
19429
 
19369
19430
  // src/liquid/filters/shopify/payment_button.ts
19370
- function bind58(_liquidSwell) {
19431
+ function bind59(_liquidSwell) {
19371
19432
  return (form) => {
19372
19433
  return null;
19373
19434
  };
19374
19435
  }
19375
19436
 
19376
19437
  // src/liquid/filters/shopify/payment_terms.ts
19377
- function bind59(_liquidSwell) {
19438
+ function bind60(_liquidSwell) {
19378
19439
  return (form) => {
19379
19440
  return null;
19380
19441
  };
@@ -19476,7 +19537,7 @@ var svgs = {
19476
19537
  var placeholder_svgs_default = svgs;
19477
19538
 
19478
19539
  // src/liquid/filters/shopify/placeholder_svg_tag.ts
19479
- function bind60(_liquidSwell) {
19540
+ function bind61(_liquidSwell) {
19480
19541
  return function filterPlaceholderSvgTag(name, className) {
19481
19542
  const svg = placeholder_svgs_default[name];
19482
19543
  if (typeof svg === "object" && svg !== null) {
@@ -19487,7 +19548,7 @@ function bind60(_liquidSwell) {
19487
19548
  }
19488
19549
 
19489
19550
  // src/liquid/filters/shopify/shopify_asset_url.ts
19490
- function bind61(_liquidSwell) {
19551
+ function bind62(_liquidSwell) {
19491
19552
  return function filterShopifyAssetUrl(input) {
19492
19553
  if (typeof input === "string") {
19493
19554
  switch (input) {
@@ -19512,7 +19573,7 @@ function bind61(_liquidSwell) {
19512
19573
  }
19513
19574
 
19514
19575
  // src/liquid/filters/shopify/structured_data.ts
19515
- function bind62(_liquidSwell) {
19576
+ function bind63(_liquidSwell) {
19516
19577
  return async function filterStructuredData(input) {
19517
19578
  let value = input;
19518
19579
  if (value instanceof StorefrontResource) {
@@ -19590,7 +19651,7 @@ function convertToSchemaOrgProductGroup(product) {
19590
19651
  }
19591
19652
 
19592
19653
  // src/liquid/filters/inline_editable.ts
19593
- function bind63(_liquidSwell) {
19654
+ function bind64(_liquidSwell) {
19594
19655
  return (value, key) => {
19595
19656
  if (typeof value === "object" && "value" in value) {
19596
19657
  value = value.value;
@@ -19648,14 +19709,15 @@ var filters = {
19648
19709
  // Shopify compatibility only
19649
19710
  asset_img_url: bind56,
19650
19711
  hex_to_rgba: bind57,
19712
+ img_url: bind58,
19651
19713
  item_count_for_variant: item_count_for_variant_default,
19652
- payment_button: bind58,
19653
- payment_terms: bind59,
19654
- placeholder_svg_tag: bind60,
19655
- shopify_asset_url: bind61,
19656
- structured_data: bind62,
19714
+ payment_button: bind59,
19715
+ payment_terms: bind60,
19716
+ placeholder_svg_tag: bind61,
19717
+ shopify_asset_url: bind62,
19718
+ structured_data: bind63,
19657
19719
  // Swell only
19658
- inline_editable: bind63
19720
+ inline_editable: bind64
19659
19721
  };
19660
19722
  function bindFilters(liquidSwell) {
19661
19723
  for (const [tag, handler] of Object.entries(filters)) {
@@ -19669,8 +19731,8 @@ function bindFilters(liquidSwell) {
19669
19731
  }
19670
19732
  }
19671
19733
  }
19672
- function bindWithResolvedProps(liquidSwell, bind64, resolve = []) {
19673
- const handler = bind64(liquidSwell);
19734
+ function bindWithResolvedProps(liquidSwell, bind65, resolve = []) {
19735
+ const handler = bind65(liquidSwell);
19674
19736
  if (!Array.isArray(resolve)) {
19675
19737
  return handler;
19676
19738
  }
@@ -20480,6 +20542,7 @@ var SwellTheme3 = class {
20480
20542
  globals;
20481
20543
  forms;
20482
20544
  resources;
20545
+ dynamicAssetUrl;
20483
20546
  liquidSwell;
20484
20547
  themeLoader;
20485
20548
  page;
@@ -20493,13 +20556,20 @@ var SwellTheme3 = class {
20493
20556
  themeSettingFilePath = "theme/config/theme.json";
20494
20557
  pageSectionGroups = null;
20495
20558
  constructor(swell, options = {}) {
20496
- const { forms, resources, globals, shopifyCompatibilityClass } = options;
20559
+ const {
20560
+ forms,
20561
+ resources,
20562
+ globals,
20563
+ dynamicAssetUrl,
20564
+ shopifyCompatibilityClass
20565
+ } = options;
20497
20566
  this.swell = swell;
20498
20567
  this.props = this.getSwellAppThemeProps(swell.config);
20499
20568
  this.shopifyCompatibilityConfig = swell.shopifyCompatibilityConfig || null;
20500
20569
  this.globals = globals || {};
20501
20570
  this.forms = forms;
20502
20571
  this.resources = resources;
20572
+ this.dynamicAssetUrl = dynamicAssetUrl;
20503
20573
  this.shopifyCompatibilityClass = shopifyCompatibilityClass || ShopifyCompatibility2;
20504
20574
  this.liquidSwell = new LiquidSwell30({
20505
20575
  theme: this,
@@ -20564,10 +20634,7 @@ var SwellTheme3 = class {
20564
20634
  geo,
20565
20635
  configs,
20566
20636
  language: configs?.language,
20567
- ...pageRecord ? getRecordGlobals(this, pageRecord) : {
20568
- page_title: page.title,
20569
- page_description: page.description
20570
- },
20637
+ ...pageRecord ? getRecordGlobals(this, pageRecord) : { page_title: page.title, page_description: page.description },
20571
20638
  all_country_option_tags: countryOptions,
20572
20639
  country_option_tags: countryOptions,
20573
20640
  canonical_url: `${store.url}${this.swell.url?.pathname || ""}`,
@@ -20595,13 +20662,8 @@ var SwellTheme3 = class {
20595
20662
  if (this.shopifyCompatibility) {
20596
20663
  this.shopifyCompatibility.adaptGlobals(globals, this.globals);
20597
20664
  }
20598
- this.globals = {
20599
- ...this.globals,
20600
- ...globals
20601
- };
20602
- this.liquidSwell.options.globals = {
20603
- ...this.globals
20604
- };
20665
+ this.globals = { ...this.globals, ...globals };
20666
+ this.liquidSwell.options.globals = { ...this.globals };
20605
20667
  }
20606
20668
  async getSettingsAndConfigs() {
20607
20669
  const geo = GEO_DATA;
@@ -20853,10 +20915,7 @@ var SwellTheme3 = class {
20853
20915
  return Object.keys(serializedFormData).length > 0 ? serializedFormData : null;
20854
20916
  }
20855
20917
  setGlobalData(data = {}) {
20856
- this.globalData = {
20857
- ...this.globalData,
20858
- ...data
20859
- };
20918
+ this.globalData = { ...this.globalData, ...data };
20860
20919
  this.setGlobals(this.globalData);
20861
20920
  }
20862
20921
  serializeGlobalData() {
@@ -21175,11 +21234,31 @@ var SwellTheme3 = class {
21175
21234
  async getAssetConfig(assetName) {
21176
21235
  return await this.getThemeConfig(`theme/assets/${assetName}`) ?? await this.getThemeConfig(`assets/${assetName}`) ?? null;
21177
21236
  }
21237
+ async getDynamicAssetUrl(filePath) {
21238
+ if (!this.dynamicAssetUrl) {
21239
+ return null;
21240
+ }
21241
+ const assetName = `${filePath}.liquid`;
21242
+ const assetConfig = await this.getAssetConfig(assetName);
21243
+ if (!assetConfig) {
21244
+ return null;
21245
+ }
21246
+ if (!this.dynamicAssetUrl.endsWith("/")) {
21247
+ this.dynamicAssetUrl += "/";
21248
+ }
21249
+ const settingsConfig = this._getTemplateConfigByType(
21250
+ "config",
21251
+ "settings_data",
21252
+ "json"
21253
+ );
21254
+ const settingsHash = settingsConfig?.hash;
21255
+ return settingsHash ? `${this.dynamicAssetUrl}v/${settingsHash}/${assetName}` : `${this.dynamicAssetUrl}${assetName}`;
21256
+ }
21178
21257
  async getAssetUrl(filePath) {
21179
21258
  const assetConfig = await this.getAssetConfig(filePath);
21180
21259
  const file = assetConfig?.file;
21181
21260
  if (!file) {
21182
- return null;
21261
+ return this.getDynamicAssetUrl(filePath);
21183
21262
  }
21184
21263
  const fileUrl = file.url || null;
21185
21264
  if (!fileUrl) {
@@ -21267,10 +21346,7 @@ var SwellTheme3 = class {
21267
21346
  if (schemaStartIndex === -1 || schemaEndIndex === -1) {
21268
21347
  return null;
21269
21348
  }
21270
- return {
21271
- ...config,
21272
- file_data: schemaTag + schemaData + schemaEndTag
21273
- };
21349
+ return { ...config, file_data: schemaTag + schemaData + schemaEndTag };
21274
21350
  }
21275
21351
  async renderThemeTemplate(filePath, data) {
21276
21352
  const config = await this.getThemeTemplateConfig(filePath);
@@ -21446,9 +21522,7 @@ ${content.slice(pos)}`;
21446
21522
  const pageSectionGroup = {
21447
21523
  // use original pageId to return exactly the requested section id
21448
21524
  id: originalPageId,
21449
- sections: {
21450
- [sectionKey]: oldSections[sectionKey]
21451
- }
21525
+ sections: { [sectionKey]: oldSections[sectionKey] }
21452
21526
  };
21453
21527
  const [pageSection] = await this.renderPageSections(
21454
21528
  pageSectionGroup,
@@ -21595,10 +21669,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
21595
21669
  }
21596
21670
  return {
21597
21671
  ...block,
21598
- settings: {
21599
- ...blockDefaults,
21600
- ...block.settings || void 0
21601
- }
21672
+ settings: { ...blockDefaults, ...block.settings || void 0 }
21602
21673
  };
21603
21674
  }
21604
21675
  );
@@ -21735,10 +21806,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
21735
21806
  )}</style>`;
21736
21807
  }
21737
21808
  }
21738
- return {
21739
- ...sectionConfig,
21740
- output
21741
- };
21809
+ return { ...sectionConfig, output };
21742
21810
  })
21743
21811
  );
21744
21812
  }
@@ -21801,10 +21869,7 @@ function resolveSectionSettings(theme, sectionConfig, index) {
21801
21869
  return settings;
21802
21870
  }
21803
21871
  const editorSettings = [
21804
- {
21805
- label: schema.label,
21806
- fields: schema.fields
21807
- }
21872
+ { label: schema.label, fields: schema.fields }
21808
21873
  ];
21809
21874
  let blocks = settings.section.blocks?.filter(
21810
21875
  (block) => block.disabled !== true
@@ -22637,7 +22702,6 @@ var HtmlCache = class {
22637
22702
  }
22638
22703
  generateVersionHash(headers) {
22639
22704
  const swellData = this.extractSwellData(headers);
22640
- const acceptLang = headers.get("accept-language") || "";
22641
22705
  const versionFactors = {
22642
22706
  store: headers.get("swell-storefront-id") || "",
22643
22707
  app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
@@ -22645,7 +22709,7 @@ var HtmlCache = class {
22645
22709
  theme: headers.get("swell-theme-version-hash") || "",
22646
22710
  modified: headers.get("swell-cache-modified") || "",
22647
22711
  currency: swellData["swell-currency"] || "USD",
22648
- locale: headers.get("x-locale") || acceptLang.split(",")[0].trim().toLowerCase() || "default",
22712
+ locale: headers.get("x-locale") || swellData["swell-locale"] || "en-US",
22649
22713
  context: headers.get("swell-storefront-context"),
22650
22714
  epoch: this.epoch
22651
22715
  };
@@ -22939,6 +23003,7 @@ export {
22939
23003
  CartResource,
22940
23004
  CategoriesResource,
22941
23005
  CategoryResource,
23006
+ ContentCache,
22942
23007
  DEFAULT_CACHE_RULES,
22943
23008
  DEFAULT_QUERY_PAGE_LIMIT,
22944
23009
  DeferredShopifyResource,