@swell/apps-sdk 1.0.181 → 1.0.183

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
@@ -888,7 +888,10 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
888
888
  }
889
889
  return this._resolve().then(() => this.makeIterator());
890
890
  }
891
- makeIterator() {
891
+ async makeIterator() {
892
+ if (isLikePromise(this.results)) {
893
+ await this.results;
894
+ }
892
895
  return (this.results || []).values();
893
896
  }
894
897
  _clone(newProps) {
@@ -3640,11 +3643,11 @@ function arrayToObject(arr, key = "id") {
3640
3643
  );
3641
3644
  }
3642
3645
  function getCountryCodeFromLocale(locale) {
3643
- const split = locale.split(/-|_/);
3644
- const country = split.pop()?.toUpperCase();
3645
- const lang = split.join("-");
3646
- const code = country ? country : LANG_TO_COUNTRY_CODES[lang] || "";
3647
- return code.toLowerCase();
3646
+ const [lang, country] = locale.split(/-|_/);
3647
+ if (country) {
3648
+ return country.toLowerCase();
3649
+ }
3650
+ return (LANG_TO_COUNTRY_CODES[lang] || "").toLowerCase();
3648
3651
  }
3649
3652
  function getCountryByCurrency(currencyCode) {
3650
3653
  if (currencyCode in CURRENCY_COUNTRIES) {
@@ -10216,6 +10219,9 @@ function getLocalizedValue(value, locale) {
10216
10219
 
10217
10220
  // src/compatibility/shopify-fonts.ts
10218
10221
  function shopifyFontToThemeFront(shopifyFontSetting) {
10222
+ if (typeof shopifyFontSetting !== "string") {
10223
+ return null;
10224
+ }
10219
10225
  const pos = shopifyFontSetting.lastIndexOf("_");
10220
10226
  const familyId = shopifyFontSetting.substring(0, pos);
10221
10227
  const variantId = shopifyFontSetting.substring(pos + 1);
@@ -12643,7 +12649,7 @@ function ShopifyCart(instance, cart) {
12643
12649
  );
12644
12650
  }),
12645
12651
  items_subtotal_price: defer(() => instance.toShopifyPrice(cart.sub_total)),
12646
- note: defer(() => cart.comments),
12652
+ note: deferWith(cart, (cart2) => cart2.comments),
12647
12653
  original_total_price: deferWith(
12648
12654
  cart,
12649
12655
  (cart2) => instance.toShopifyPrice(cart2.sub_total)
@@ -13728,15 +13734,10 @@ var CollectionsDrop = class extends Drop10 {
13728
13734
  switch (typeof key) {
13729
13735
  case "string": {
13730
13736
  if (key === "all") {
13731
- let resource = this.#map.get(key);
13732
- if (resource === void 0) {
13733
- resource = ShopifyCollection(
13734
- this.#instance,
13735
- new AllCategoryResource(this.#instance)
13736
- );
13737
- this.#map.set(key, resource);
13738
- }
13739
- return resource;
13737
+ return this.getAllCollection();
13738
+ }
13739
+ if (key === "size") {
13740
+ return this.getAllCollectionsSize();
13740
13741
  }
13741
13742
  return this.getCollection(key);
13742
13743
  }
@@ -13766,6 +13767,21 @@ var CollectionsDrop = class extends Drop10 {
13766
13767
  }
13767
13768
  return resource;
13768
13769
  }
13770
+ getAllCollection() {
13771
+ let resource = this.#map.get("all");
13772
+ if (resource === void 0) {
13773
+ resource = ShopifyCollection(
13774
+ this.#instance,
13775
+ new AllCategoryResource(this.#instance)
13776
+ );
13777
+ this.#map.set("all", resource);
13778
+ }
13779
+ return resource;
13780
+ }
13781
+ getAllCollectionsSize() {
13782
+ const count = this.#instance.theme.globals.shop?.collections_count;
13783
+ return count || 0;
13784
+ }
13769
13785
  };
13770
13786
  var Collections = class extends SwellStorefrontCollection {
13771
13787
  #drop;
@@ -15543,7 +15559,7 @@ var tags = {
15543
15559
  };
15544
15560
  function bindTags(liquidSwell) {
15545
15561
  Object.entries(tags).forEach(
15546
- ([tag, bind66]) => liquidSwell.registerTag(tag, bind66(liquidSwell))
15562
+ ([tag, bind67]) => liquidSwell.registerTag(tag, bind67(liquidSwell))
15547
15563
  );
15548
15564
  }
15549
15565
 
@@ -15811,8 +15827,22 @@ function bind37(_liquidSwell) {
15811
15827
  };
15812
15828
  }
15813
15829
 
15814
- // src/liquid/filters/font_face.ts
15830
+ // src/liquid/filters/escape.ts
15831
+ import { escape } from "lodash-es";
15815
15832
  function bind38(_liquidSwell) {
15833
+ return function escapeTag(input) {
15834
+ if (!input?.startsWith) {
15835
+ return input;
15836
+ }
15837
+ if (input.startsWith("<img") || input.startsWith("<video")) {
15838
+ return input;
15839
+ }
15840
+ return escape(input);
15841
+ };
15842
+ }
15843
+
15844
+ // src/liquid/filters/font_face.ts
15845
+ function bind39(_liquidSwell) {
15816
15846
  return (fontSetting, ...params) => {
15817
15847
  if (!fontSetting) {
15818
15848
  return null;
@@ -15824,14 +15854,14 @@ function bind38(_liquidSwell) {
15824
15854
  }
15825
15855
 
15826
15856
  // src/liquid/filters/font_modify.ts
15827
- function bind39(_liquidSwell) {
15857
+ function bind40(_liquidSwell) {
15828
15858
  return (fontSetting, prop, value) => {
15829
15859
  return ThemeFont.clone(fontSetting).modify(prop, value);
15830
15860
  };
15831
15861
  }
15832
15862
 
15833
15863
  // src/liquid/filters/font_url.ts
15834
- function bind40(_liquidSwell) {
15864
+ function bind41(_liquidSwell) {
15835
15865
  return (fontSetting) => {
15836
15866
  return ThemeFont.get(fontSetting).url();
15837
15867
  };
@@ -15881,14 +15911,14 @@ var format_address_default = {
15881
15911
 
15882
15912
  // src/liquid/filters/handleize.ts
15883
15913
  import { kebabCase } from "lodash-es";
15884
- function bind41(_liquidSwell) {
15914
+ function bind42(_liquidSwell) {
15885
15915
  return function filterHandleize(handle) {
15886
15916
  return kebabCase(handle);
15887
15917
  };
15888
15918
  }
15889
15919
 
15890
15920
  // src/liquid/filters/image_tag.ts
15891
- function bind42(_liquidSwell) {
15921
+ function bind43(_liquidSwell) {
15892
15922
  return function filterImageTag(imageUrl, ...params) {
15893
15923
  imageUrl = String(imageUrl || "");
15894
15924
  let {
@@ -16052,7 +16082,7 @@ var filterDefinition = {
16052
16082
  var image_url_default = filterDefinition;
16053
16083
 
16054
16084
  // src/liquid/filters/inline_asset_content.ts
16055
- function bind43(liquidSwell) {
16085
+ function bind44(liquidSwell) {
16056
16086
  return async (assetPath) => {
16057
16087
  const config = await liquidSwell.theme.getThemeConfig(
16058
16088
  `theme/assets/${assetPath}`
@@ -16062,14 +16092,14 @@ function bind43(liquidSwell) {
16062
16092
  }
16063
16093
 
16064
16094
  // src/liquid/filters/json.ts
16065
- function bind44(_liquidSwell) {
16095
+ function bind45(_liquidSwell) {
16066
16096
  return async function filterJson(input, space = 0) {
16067
16097
  return jsonStringifyAsync(input, space);
16068
16098
  };
16069
16099
  }
16070
16100
 
16071
16101
  // src/liquid/filters/json_pretty.ts
16072
- function bind45(_liquidSwell) {
16102
+ function bind46(_liquidSwell) {
16073
16103
  return async function filterJsonPretty(input, space = 2) {
16074
16104
  const output = await jsonStringifyAsync(input, space);
16075
16105
  return `<pre>${output}</pre>`;
@@ -16079,25 +16109,18 @@ function bind45(_liquidSwell) {
16079
16109
  // src/liquid/filters/locale_flag.ts
16080
16110
  import { hasFlag } from "country-flag-icons";
16081
16111
  import * as flags from "country-flag-icons/string/1x1";
16082
- function getCountryCode(localCode) {
16083
- if (localCode.includes("-")) {
16084
- return localCode.split("-")[1].toUpperCase();
16085
- } else {
16086
- return localCode.toUpperCase();
16087
- }
16088
- }
16089
- function bind46(_liquidSwell) {
16112
+ function bind47(_liquidSwell) {
16090
16113
  return (localeCode) => {
16091
16114
  if (typeof localeCode !== "string") {
16092
16115
  return flags.US;
16093
16116
  }
16094
- const countryCode = getCountryCode(localeCode);
16117
+ const countryCode = getCountryCodeFromLocale(localeCode).toUpperCase();
16095
16118
  return hasFlag(countryCode) ? flags[countryCode] : flags.US;
16096
16119
  };
16097
16120
  }
16098
16121
 
16099
16122
  // src/liquid/filters/minus.ts
16100
- function bind47(_liquidSwell) {
16123
+ function bind48(_liquidSwell) {
16101
16124
  return (first, second) => {
16102
16125
  const firstValue = isNumber(first) ? first : 0;
16103
16126
  const secondValue = isNumber(second) ? second : 0;
@@ -16106,7 +16129,7 @@ function bind47(_liquidSwell) {
16106
16129
  }
16107
16130
 
16108
16131
  // src/liquid/filters/money.ts
16109
- function bind48(liquidSwell) {
16132
+ function bind49(liquidSwell) {
16110
16133
  return function filterMoney(value) {
16111
16134
  const amount = getMoneyAmount(liquidSwell, value);
16112
16135
  return liquidSwell.renderCurrency(amount);
@@ -16123,7 +16146,7 @@ function getMoneyAmount(liquidSwell, value) {
16123
16146
  }
16124
16147
 
16125
16148
  // src/liquid/filters/money_with_currency.ts
16126
- function bind49(liquidSwell) {
16149
+ function bind50(liquidSwell) {
16127
16150
  return function filterMoneyWithCurrency(value) {
16128
16151
  const { currency } = liquidSwell.theme.swell.getStorefrontLocalization();
16129
16152
  const amount = getMoneyAmount(liquidSwell, value);
@@ -16132,7 +16155,7 @@ function bind49(liquidSwell) {
16132
16155
  }
16133
16156
 
16134
16157
  // src/liquid/filters/money_without_currency.ts
16135
- function bind50(liquidSwell) {
16158
+ function bind51(liquidSwell) {
16136
16159
  return function filterMoneyWithoutCurrency(value) {
16137
16160
  const amount = getMoneyAmount(liquidSwell, value);
16138
16161
  return liquidSwell.renderCurrency(amount).replace(/[^0-9.,]/g, "");
@@ -16140,7 +16163,7 @@ function bind50(liquidSwell) {
16140
16163
  }
16141
16164
 
16142
16165
  // src/liquid/filters/money_without_trailing_zeros.ts
16143
- function bind51(liquidSwell) {
16166
+ function bind52(liquidSwell) {
16144
16167
  return function filterMoneyWithoutTrailingZeros(value) {
16145
16168
  const amount = getMoneyAmount(liquidSwell, value);
16146
16169
  return liquidSwell.renderCurrency(amount).split(".")[0].split(",")[0];
@@ -16148,21 +16171,21 @@ function bind51(liquidSwell) {
16148
16171
  }
16149
16172
 
16150
16173
  // src/liquid/filters/script_tag.ts
16151
- function bind52(_liquidSwell) {
16174
+ function bind53(_liquidSwell) {
16152
16175
  return function filterScriptTag(assetUrl) {
16153
16176
  return `<script src="${assetUrl}" type="text/javascript"></script>`;
16154
16177
  };
16155
16178
  }
16156
16179
 
16157
16180
  // src/liquid/filters/stylesheet_tag.ts
16158
- function bind53(_liquidSwell) {
16181
+ function bind54(_liquidSwell) {
16159
16182
  return function filterStyleSheetTag(assetUrl) {
16160
16183
  return `<link href="${assetUrl}" rel="stylesheet" type="text/css" media="all" />`;
16161
16184
  };
16162
16185
  }
16163
16186
 
16164
16187
  // src/liquid/filters/time_tag.ts
16165
- function bind54(_liquidSwell) {
16188
+ function bind55(_liquidSwell) {
16166
16189
  const dateFilter = bind33(_liquidSwell);
16167
16190
  return (dateValue, ...params) => {
16168
16191
  const date = ensureDate(dateValue);
@@ -16173,7 +16196,7 @@ function bind54(_liquidSwell) {
16173
16196
  }
16174
16197
 
16175
16198
  // src/liquid/filters/translate.ts
16176
- function bind55(liquidSwell) {
16199
+ function bind56(liquidSwell) {
16177
16200
  return async function filterTranslate(key, params) {
16178
16201
  const props = params && paramsToProps(params);
16179
16202
  const str = await liquidSwell.renderTranslation(key, props);
@@ -16182,7 +16205,7 @@ function bind55(liquidSwell) {
16182
16205
  }
16183
16206
 
16184
16207
  // src/liquid/filters/where.ts
16185
- function bind56(_liquidSwell) {
16208
+ function bind57(_liquidSwell) {
16186
16209
  return function* filterWhere(arr, property, expected) {
16187
16210
  const results = [];
16188
16211
  const list = yield resolveEnumerable(arr);
@@ -16236,7 +16259,7 @@ function getSizesFromParam(param) {
16236
16259
  height: height ? Number(height) : void 0
16237
16260
  };
16238
16261
  }
16239
- function bind57(liquidSwell) {
16262
+ function bind58(liquidSwell) {
16240
16263
  return async function filterAssetImgUrl(assetPath, size = "small") {
16241
16264
  const imageUrl = await liquidSwell.getAssetUrl(assetPath).then((url) => url || "");
16242
16265
  const sizes = getSizesFromParam(size);
@@ -16252,14 +16275,14 @@ function bind57(liquidSwell) {
16252
16275
  }
16253
16276
 
16254
16277
  // src/liquid/filters/shopify/hex_to_rgba.ts
16255
- function bind58(_liquidSwell) {
16278
+ function bind59(_liquidSwell) {
16256
16279
  return (color, alpha) => {
16257
16280
  return ThemeColor.get(color).rgba(alpha || 1);
16258
16281
  };
16259
16282
  }
16260
16283
 
16261
16284
  // src/liquid/filters/shopify/img_url.ts
16262
- function bind59(liquidSwell) {
16285
+ function bind60(liquidSwell) {
16263
16286
  return async function filterImgUrl(input, ...params) {
16264
16287
  const url = await getImageUrlFromInput(input, liquidSwell);
16265
16288
  if (typeof url !== "string" || url === "") {
@@ -16297,14 +16320,14 @@ var item_count_for_variant_default = {
16297
16320
  };
16298
16321
 
16299
16322
  // src/liquid/filters/shopify/payment_button.ts
16300
- function bind60(_liquidSwell) {
16323
+ function bind61(_liquidSwell) {
16301
16324
  return (form) => {
16302
- return null;
16325
+ return `<button style="display: block; visibility: hidden;"></button>`;
16303
16326
  };
16304
16327
  }
16305
16328
 
16306
16329
  // src/liquid/filters/shopify/payment_terms.ts
16307
- function bind61(_liquidSwell) {
16330
+ function bind62(_liquidSwell) {
16308
16331
  return (form) => {
16309
16332
  return null;
16310
16333
  };
@@ -16406,7 +16429,7 @@ var svgs = {
16406
16429
  var placeholder_svgs_default = svgs;
16407
16430
 
16408
16431
  // src/liquid/filters/shopify/placeholder_svg_tag.ts
16409
- function bind62(_liquidSwell) {
16432
+ function bind63(_liquidSwell) {
16410
16433
  return function filterPlaceholderSvgTag(name, className) {
16411
16434
  const svg = placeholder_svgs_default[name];
16412
16435
  if (typeof svg === "object" && svg !== null) {
@@ -16417,7 +16440,7 @@ function bind62(_liquidSwell) {
16417
16440
  }
16418
16441
 
16419
16442
  // src/liquid/filters/shopify/shopify_asset_url.ts
16420
- function bind63(_liquidSwell) {
16443
+ function bind64(_liquidSwell) {
16421
16444
  return function filterShopifyAssetUrl(input) {
16422
16445
  if (typeof input === "string") {
16423
16446
  switch (input) {
@@ -16442,7 +16465,7 @@ function bind63(_liquidSwell) {
16442
16465
  }
16443
16466
 
16444
16467
  // src/liquid/filters/shopify/structured_data.ts
16445
- function bind64(_liquidSwell) {
16468
+ function bind65(_liquidSwell) {
16446
16469
  return async function filterStructuredData(input) {
16447
16470
  let value = input;
16448
16471
  if (value instanceof StorefrontResource) {
@@ -16520,7 +16543,7 @@ function convertToSchemaOrgProductGroup(product) {
16520
16543
  }
16521
16544
 
16522
16545
  // src/liquid/filters/inline_editable.ts
16523
- function bind65(_liquidSwell) {
16546
+ function bind66(_liquidSwell) {
16524
16547
  return (value, key) => {
16525
16548
  if (typeof value === "object" && "value" in value) {
16526
16549
  value = value.value;
@@ -16551,43 +16574,44 @@ var filters = {
16551
16574
  default_errors: bind35,
16552
16575
  divided_by: bind36,
16553
16576
  embedded_content: bind37,
16554
- font_face: bind38,
16555
- font_modify: bind39,
16556
- font_url: bind40,
16577
+ escape: bind38,
16578
+ font_face: bind39,
16579
+ font_modify: bind40,
16580
+ font_url: bind41,
16557
16581
  format_address: format_address_default,
16558
- handle: bind41,
16582
+ handle: bind42,
16559
16583
  // alias
16560
- handleize: bind41,
16561
- image_tag: bind42,
16584
+ handleize: bind42,
16585
+ image_tag: bind43,
16562
16586
  image_url: image_url_default,
16563
- inline_asset_content: bind43,
16564
- json: bind44,
16565
- json_pretty: bind45,
16566
- locale_flag: bind46,
16567
- minus: bind47,
16568
- money: bind48,
16569
- money_with_currency: bind49,
16570
- money_without_currency: bind50,
16571
- money_without_trailing_zeros: bind51,
16572
- script_tag: bind52,
16573
- stylesheet_tag: bind53,
16574
- time_tag: bind54,
16575
- translate: bind55,
16576
- t: bind55,
16587
+ inline_asset_content: bind44,
16588
+ json: bind45,
16589
+ json_pretty: bind46,
16590
+ locale_flag: bind47,
16591
+ minus: bind48,
16592
+ money: bind49,
16593
+ money_with_currency: bind50,
16594
+ money_without_currency: bind51,
16595
+ money_without_trailing_zeros: bind52,
16596
+ script_tag: bind53,
16597
+ stylesheet_tag: bind54,
16598
+ time_tag: bind55,
16599
+ translate: bind56,
16600
+ t: bind56,
16577
16601
  // alias
16578
- where: bind56,
16602
+ where: bind57,
16579
16603
  // Shopify compatibility only
16580
- asset_img_url: bind57,
16581
- hex_to_rgba: bind58,
16582
- img_url: bind59,
16604
+ asset_img_url: bind58,
16605
+ hex_to_rgba: bind59,
16606
+ img_url: bind60,
16583
16607
  item_count_for_variant: item_count_for_variant_default,
16584
- payment_button: bind60,
16585
- payment_terms: bind61,
16586
- placeholder_svg_tag: bind62,
16587
- shopify_asset_url: bind63,
16588
- structured_data: bind64,
16608
+ payment_button: bind61,
16609
+ payment_terms: bind62,
16610
+ placeholder_svg_tag: bind63,
16611
+ shopify_asset_url: bind64,
16612
+ structured_data: bind65,
16589
16613
  // Swell only
16590
- inline_editable: bind65
16614
+ inline_editable: bind66
16591
16615
  };
16592
16616
  function bindFilters(liquidSwell) {
16593
16617
  for (const [tag, handler] of Object.entries(filters)) {
@@ -16601,8 +16625,8 @@ function bindFilters(liquidSwell) {
16601
16625
  }
16602
16626
  }
16603
16627
  }
16604
- function bindWithResolvedProps(liquidSwell, bind66, resolve = []) {
16605
- const handler = bind66(liquidSwell);
16628
+ function bindWithResolvedProps(liquidSwell, bind67, resolve = []) {
16629
+ const handler = bind67(liquidSwell);
16606
16630
  if (!Array.isArray(resolve)) {
16607
16631
  return handler;
16608
16632
  }
@@ -18813,7 +18837,7 @@ function resolveSectionSettings(theme, sectionConfig, index) {
18813
18837
  let blocks = settings.section.blocks?.filter(
18814
18838
  (block) => block.disabled !== true
18815
18839
  );
18816
- blocks = blocks?.map((block) => ({
18840
+ blocks = blocks?.filter((block) => Boolean(block.type)).map((block) => ({
18817
18841
  ...block,
18818
18842
  ...getBlockAttributes(theme, block),
18819
18843
  settings: resolveThemeSettings(