@swell/apps-sdk 1.0.154 → 1.0.156

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
@@ -7654,7 +7654,7 @@
7654
7654
  var SHORT_TTL = 5 * SECOND;
7655
7655
 
7656
7656
  // src/cache/worker-cache-proxy.ts
7657
- var CACHE_NAME = "swell-cache-v1";
7657
+ var CACHE_NAME = "swell-cache-v011";
7658
7658
  var CACHE_KEY_ORIGIN = "https://cache.swell.store";
7659
7659
  var WorkerCacheProxy = class {
7660
7660
  swell;
@@ -7703,6 +7703,7 @@
7703
7703
  }
7704
7704
  });
7705
7705
  await cache.put(keyUrl, response);
7706
+ logger.debug("[SDK] cache put done", { keyUrl });
7706
7707
  } catch {
7707
7708
  }
7708
7709
  }
@@ -19078,7 +19079,7 @@ ${injects.join("\n")}<\/script>`;
19078
19079
  };
19079
19080
  function bindTags(liquidSwell) {
19080
19081
  Object.entries(tags).forEach(
19081
- ([tag, bind63]) => liquidSwell.registerTag(tag, bind63(liquidSwell))
19082
+ ([tag, bind64]) => liquidSwell.registerTag(tag, bind64(liquidSwell))
19082
19083
  );
19083
19084
  }
19084
19085
 
@@ -19246,8 +19247,60 @@ ${injects.join("\n")}<\/script>`;
19246
19247
  return (0, import_strftime.default)(format, date);
19247
19248
  }
19248
19249
 
19249
- // src/liquid/filters/default_errors.ts
19250
+ // src/liquid/filters/date_next_interval.ts
19250
19251
  function bind34(_liquidSwell) {
19252
+ return (dateValue, interval, intervalCount) => {
19253
+ const date = ensureDate(dateValue);
19254
+ const result = getNextIntervalDate(date, interval, Number(intervalCount));
19255
+ return result ? new Date(result).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
19256
+ };
19257
+ }
19258
+ function getNextIntervalDate(date, interval, intervalCount) {
19259
+ if (!interval || !date) {
19260
+ return;
19261
+ }
19262
+ if (interval === "monthly" || interval === 30) {
19263
+ return dateNextMonth(date, intervalCount);
19264
+ }
19265
+ let intervalDays = 0;
19266
+ if (typeof interval === "string") {
19267
+ if (interval === "daily") {
19268
+ intervalDays = 1;
19269
+ } else if (interval === "weekly") {
19270
+ intervalDays = 7;
19271
+ } else if (interval === "yearly") {
19272
+ intervalDays = 365;
19273
+ }
19274
+ }
19275
+ if (intervalDays <= 0) {
19276
+ return;
19277
+ }
19278
+ return time(date) + intervalDays * intervalCount * 86400 * 1e3;
19279
+ }
19280
+ function dateNextMonth(startDate, intervalCount) {
19281
+ const date = new Date(startDate);
19282
+ const nextDate = new Date(date);
19283
+ nextDate.setUTCMonth(date.getMonth() + (intervalCount || 1));
19284
+ if (nextDate.getDate() !== date.getDate()) {
19285
+ nextDate.setDate(nextDate.getDate() - nextDate.getDate());
19286
+ }
19287
+ return nextDate.getTime();
19288
+ }
19289
+ function time(date) {
19290
+ if (date === void 0) {
19291
+ return Date.now();
19292
+ }
19293
+ if (typeof date === "number" || typeof date === "string") {
19294
+ return new Date(date).getTime();
19295
+ }
19296
+ if (date instanceof Date) {
19297
+ return date.getTime();
19298
+ }
19299
+ return Date.now();
19300
+ }
19301
+
19302
+ // src/liquid/filters/default_errors.ts
19303
+ function bind35(_liquidSwell) {
19251
19304
  return async function filterDefaultError(errors) {
19252
19305
  if (!errors) {
19253
19306
  return "";
@@ -19273,7 +19326,7 @@ ${injects.join("\n")}<\/script>`;
19273
19326
  }
19274
19327
 
19275
19328
  // src/liquid/filters/divided_by.ts
19276
- function bind35(_liquidSwell) {
19329
+ function bind36(_liquidSwell) {
19277
19330
  return (dividend, divisor, integerArithmetic) => {
19278
19331
  if (!isNumber(dividend) || !isNumber(divisor)) {
19279
19332
  return dividend;
@@ -19284,7 +19337,7 @@ ${injects.join("\n")}<\/script>`;
19284
19337
 
19285
19338
  // src/liquid/filters/embedded_content.ts
19286
19339
  var import_lodash_es10 = __require("lodash-es");
19287
- function bind36(_liquidSwell) {
19340
+ function bind37(_liquidSwell) {
19288
19341
  return (value, tag = "iframe") => {
19289
19342
  const escapeIframes = value.replaceAll(`<${tag}`, `&lt;${tag}`).replaceAll(`</${tag}`, `&lt;/${tag}`);
19290
19343
  const removeTags = escapeIframes.replaceAll(/<(.*?)>/gi, "");
@@ -19295,7 +19348,7 @@ ${injects.join("\n")}<\/script>`;
19295
19348
  }
19296
19349
 
19297
19350
  // src/liquid/filters/font_face.ts
19298
- function bind37(_liquidSwell) {
19351
+ function bind38(_liquidSwell) {
19299
19352
  return (fontSetting, ...params) => {
19300
19353
  if (!fontSetting) {
19301
19354
  return null;
@@ -19307,14 +19360,14 @@ ${injects.join("\n")}<\/script>`;
19307
19360
  }
19308
19361
 
19309
19362
  // src/liquid/filters/font_modify.ts
19310
- function bind38(_liquidSwell) {
19363
+ function bind39(_liquidSwell) {
19311
19364
  return (fontSetting, prop, value) => {
19312
19365
  return ThemeFont.clone(fontSetting).modify(prop, value);
19313
19366
  };
19314
19367
  }
19315
19368
 
19316
19369
  // src/liquid/filters/font_url.ts
19317
- function bind39(_liquidSwell) {
19370
+ function bind40(_liquidSwell) {
19318
19371
  return (fontSetting) => {
19319
19372
  return ThemeFont.get(fontSetting).url();
19320
19373
  };
@@ -19364,14 +19417,14 @@ ${injects.join("\n")}<\/script>`;
19364
19417
 
19365
19418
  // src/liquid/filters/handleize.ts
19366
19419
  var import_lodash_es11 = __require("lodash-es");
19367
- function bind40(_liquidSwell) {
19420
+ function bind41(_liquidSwell) {
19368
19421
  return function filterHandleize(handle) {
19369
19422
  return (0, import_lodash_es11.kebabCase)(handle);
19370
19423
  };
19371
19424
  }
19372
19425
 
19373
19426
  // src/liquid/filters/image_tag.ts
19374
- function bind41(_liquidSwell) {
19427
+ function bind42(_liquidSwell) {
19375
19428
  return function filterImageTag(imageUrl, ...params) {
19376
19429
  imageUrl = String(imageUrl || "");
19377
19430
  let {
@@ -19535,7 +19588,7 @@ ${injects.join("\n")}<\/script>`;
19535
19588
  var image_url_default = filterDefinition;
19536
19589
 
19537
19590
  // src/liquid/filters/inline_asset_content.ts
19538
- function bind42(liquidSwell) {
19591
+ function bind43(liquidSwell) {
19539
19592
  return async (assetPath) => {
19540
19593
  const config = await liquidSwell.theme.getThemeConfig(
19541
19594
  `theme/assets/${assetPath}`
@@ -19545,14 +19598,14 @@ ${injects.join("\n")}<\/script>`;
19545
19598
  }
19546
19599
 
19547
19600
  // src/liquid/filters/json.ts
19548
- function bind43(_liquidSwell) {
19601
+ function bind44(_liquidSwell) {
19549
19602
  return async function filterJson(input, space = 0) {
19550
19603
  return jsonStringifyAsync(input, space);
19551
19604
  };
19552
19605
  }
19553
19606
 
19554
19607
  // src/liquid/filters/json_pretty.ts
19555
- function bind44(_liquidSwell) {
19608
+ function bind45(_liquidSwell) {
19556
19609
  return async function filterJsonPretty(input, space = 2) {
19557
19610
  const output = await jsonStringifyAsync(input, space);
19558
19611
  return `<pre>${output}</pre>`;
@@ -19569,7 +19622,7 @@ ${injects.join("\n")}<\/script>`;
19569
19622
  return localCode.toUpperCase();
19570
19623
  }
19571
19624
  }
19572
- function bind45(_liquidSwell) {
19625
+ function bind46(_liquidSwell) {
19573
19626
  return (localeCode) => {
19574
19627
  if (typeof localeCode !== "string") {
19575
19628
  return flags.US;
@@ -19580,7 +19633,7 @@ ${injects.join("\n")}<\/script>`;
19580
19633
  }
19581
19634
 
19582
19635
  // src/liquid/filters/money.ts
19583
- function bind46(liquidSwell) {
19636
+ function bind47(liquidSwell) {
19584
19637
  return function filterMoney(value) {
19585
19638
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
19586
19639
  return liquidSwell.renderCurrency(amount);
@@ -19588,7 +19641,7 @@ ${injects.join("\n")}<\/script>`;
19588
19641
  }
19589
19642
 
19590
19643
  // src/liquid/filters/money_with_currency.ts
19591
- function bind47(liquidSwell) {
19644
+ function bind48(liquidSwell) {
19592
19645
  return function filterMoneyWithCurrency(value) {
19593
19646
  const { currency } = liquidSwell.theme.swell.getStorefrontLocalization();
19594
19647
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
@@ -19597,7 +19650,7 @@ ${injects.join("\n")}<\/script>`;
19597
19650
  }
19598
19651
 
19599
19652
  // src/liquid/filters/money_without_currency.ts
19600
- function bind48(liquidSwell) {
19653
+ function bind49(liquidSwell) {
19601
19654
  return function filterMoneyWithoutCurrency(value) {
19602
19655
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
19603
19656
  return liquidSwell.renderCurrency(amount).replace(/[^0-9.,]/g, "");
@@ -19605,7 +19658,7 @@ ${injects.join("\n")}<\/script>`;
19605
19658
  }
19606
19659
 
19607
19660
  // src/liquid/filters/money_without_trailing_zeros.ts
19608
- function bind49(liquidSwell) {
19661
+ function bind50(liquidSwell) {
19609
19662
  return function filterMoneyWithoutTrailingZeros(value) {
19610
19663
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
19611
19664
  return liquidSwell.renderCurrency(amount).split(".")[0].split(",")[0];
@@ -19613,21 +19666,21 @@ ${injects.join("\n")}<\/script>`;
19613
19666
  }
19614
19667
 
19615
19668
  // src/liquid/filters/script_tag.ts
19616
- function bind50(_liquidSwell) {
19669
+ function bind51(_liquidSwell) {
19617
19670
  return function filterScriptTag(assetUrl) {
19618
19671
  return `<script src="${assetUrl}" type="text/javascript"><\/script>`;
19619
19672
  };
19620
19673
  }
19621
19674
 
19622
19675
  // src/liquid/filters/stylesheet_tag.ts
19623
- function bind51(_liquidSwell) {
19676
+ function bind52(_liquidSwell) {
19624
19677
  return function filterStyleSheetTag(assetUrl) {
19625
19678
  return `<link href="${assetUrl}" rel="stylesheet" type="text/css" media="all" />`;
19626
19679
  };
19627
19680
  }
19628
19681
 
19629
19682
  // src/liquid/filters/time_tag.ts
19630
- function bind52(_liquidSwell) {
19683
+ function bind53(_liquidSwell) {
19631
19684
  const dateFilter = bind33(_liquidSwell);
19632
19685
  return (dateValue, ...params) => {
19633
19686
  const date = ensureDate(dateValue);
@@ -19638,7 +19691,7 @@ ${injects.join("\n")}<\/script>`;
19638
19691
  }
19639
19692
 
19640
19693
  // src/liquid/filters/translate.ts
19641
- function bind53(liquidSwell) {
19694
+ function bind54(liquidSwell) {
19642
19695
  return async function filterTranslate(key, params) {
19643
19696
  const props = params && paramsToProps(params);
19644
19697
  const str = await liquidSwell.renderTranslation(key, props);
@@ -19647,7 +19700,7 @@ ${injects.join("\n")}<\/script>`;
19647
19700
  }
19648
19701
 
19649
19702
  // src/liquid/filters/where.ts
19650
- function bind54(_liquidSwell) {
19703
+ function bind55(_liquidSwell) {
19651
19704
  return function* filterWhere(arr, property, expected) {
19652
19705
  const results = [];
19653
19706
  const list = yield resolveEnumerable(arr);
@@ -19701,7 +19754,7 @@ ${injects.join("\n")}<\/script>`;
19701
19754
  height: height ? Number(height) : void 0
19702
19755
  };
19703
19756
  }
19704
- function bind55(liquidSwell) {
19757
+ function bind56(liquidSwell) {
19705
19758
  return async function filterAssetImgUrl(assetPath, size = "small") {
19706
19759
  const imageUrl = await liquidSwell.getAssetUrl(assetPath).then((url) => url || "");
19707
19760
  const sizes = getSizesFromParam(size);
@@ -19717,7 +19770,7 @@ ${injects.join("\n")}<\/script>`;
19717
19770
  }
19718
19771
 
19719
19772
  // src/liquid/filters/shopify/hex_to_rgba.ts
19720
- function bind56(_liquidSwell) {
19773
+ function bind57(_liquidSwell) {
19721
19774
  return (color, alpha) => {
19722
19775
  return ThemeColor.get(color).rgba(alpha || 1);
19723
19776
  };
@@ -19737,14 +19790,14 @@ ${injects.join("\n")}<\/script>`;
19737
19790
  };
19738
19791
 
19739
19792
  // src/liquid/filters/shopify/payment_button.ts
19740
- function bind57(_liquidSwell) {
19793
+ function bind58(_liquidSwell) {
19741
19794
  return (form) => {
19742
19795
  return null;
19743
19796
  };
19744
19797
  }
19745
19798
 
19746
19799
  // src/liquid/filters/shopify/payment_terms.ts
19747
- function bind58(_liquidSwell) {
19800
+ function bind59(_liquidSwell) {
19748
19801
  return (form) => {
19749
19802
  return null;
19750
19803
  };
@@ -19846,7 +19899,7 @@ ${injects.join("\n")}<\/script>`;
19846
19899
  var placeholder_svgs_default = svgs;
19847
19900
 
19848
19901
  // src/liquid/filters/shopify/placeholder_svg_tag.ts
19849
- function bind59(_liquidSwell) {
19902
+ function bind60(_liquidSwell) {
19850
19903
  return function filterPlaceholderSvgTag(name, className) {
19851
19904
  const svg = placeholder_svgs_default[name];
19852
19905
  if (typeof svg === "object" && svg !== null) {
@@ -19857,7 +19910,7 @@ ${injects.join("\n")}<\/script>`;
19857
19910
  }
19858
19911
 
19859
19912
  // src/liquid/filters/shopify/shopify_asset_url.ts
19860
- function bind60(_liquidSwell) {
19913
+ function bind61(_liquidSwell) {
19861
19914
  return function filterShopifyAssetUrl(input) {
19862
19915
  if (typeof input === "string") {
19863
19916
  switch (input) {
@@ -19882,7 +19935,7 @@ ${injects.join("\n")}<\/script>`;
19882
19935
  }
19883
19936
 
19884
19937
  // src/liquid/filters/shopify/structured_data.ts
19885
- function bind61(_liquidSwell) {
19938
+ function bind62(_liquidSwell) {
19886
19939
  return async function filterStructuredData(input) {
19887
19940
  let value = input;
19888
19941
  if (value instanceof StorefrontResource) {
@@ -19960,7 +20013,7 @@ ${injects.join("\n")}<\/script>`;
19960
20013
  }
19961
20014
 
19962
20015
  // src/liquid/filters/inline_editable.ts
19963
- function bind62(_liquidSwell) {
20016
+ function bind63(_liquidSwell) {
19964
20017
  return (value, key) => {
19965
20018
  if (typeof value === "object" && "value" in value) {
19966
20019
  value = value.value;
@@ -19986,45 +20039,46 @@ ${injects.join("\n")}<\/script>`;
19986
20039
  color_to_hex: bind30,
19987
20040
  color_to_hsl: bind31,
19988
20041
  color_to_rgb: bind32,
20042
+ date_next_interval: bind34,
19989
20043
  date: bind33,
19990
- default_errors: bind34,
19991
- divided_by: bind35,
19992
- embedded_content: bind36,
19993
- font_face: bind37,
19994
- font_modify: bind38,
19995
- font_url: bind39,
20044
+ default_errors: bind35,
20045
+ divided_by: bind36,
20046
+ embedded_content: bind37,
20047
+ font_face: bind38,
20048
+ font_modify: bind39,
20049
+ font_url: bind40,
19996
20050
  format_address: format_address_default,
19997
- handle: bind40,
20051
+ handle: bind41,
19998
20052
  // alias
19999
- handleize: bind40,
20000
- image_tag: bind41,
20053
+ handleize: bind41,
20054
+ image_tag: bind42,
20001
20055
  image_url: image_url_default,
20002
- inline_asset_content: bind42,
20003
- json: bind43,
20004
- json_pretty: bind44,
20005
- locale_flag: bind45,
20006
- money: bind46,
20007
- money_with_currency: bind47,
20008
- money_without_currency: bind48,
20009
- money_without_trailing_zeros: bind49,
20010
- script_tag: bind50,
20011
- stylesheet_tag: bind51,
20012
- time_tag: bind52,
20013
- translate: bind53,
20014
- t: bind53,
20056
+ inline_asset_content: bind43,
20057
+ json: bind44,
20058
+ json_pretty: bind45,
20059
+ locale_flag: bind46,
20060
+ money: bind47,
20061
+ money_with_currency: bind48,
20062
+ money_without_currency: bind49,
20063
+ money_without_trailing_zeros: bind50,
20064
+ script_tag: bind51,
20065
+ stylesheet_tag: bind52,
20066
+ time_tag: bind53,
20067
+ translate: bind54,
20068
+ t: bind54,
20015
20069
  // alias
20016
- where: bind54,
20070
+ where: bind55,
20017
20071
  // Shopify compatibility only
20018
- asset_img_url: bind55,
20019
- hex_to_rgba: bind56,
20072
+ asset_img_url: bind56,
20073
+ hex_to_rgba: bind57,
20020
20074
  item_count_for_variant: item_count_for_variant_default,
20021
- payment_button: bind57,
20022
- payment_terms: bind58,
20023
- placeholder_svg_tag: bind59,
20024
- shopify_asset_url: bind60,
20025
- structured_data: bind61,
20075
+ payment_button: bind58,
20076
+ payment_terms: bind59,
20077
+ placeholder_svg_tag: bind60,
20078
+ shopify_asset_url: bind61,
20079
+ structured_data: bind62,
20026
20080
  // Swell only
20027
- inline_editable: bind62
20081
+ inline_editable: bind63
20028
20082
  };
20029
20083
  function bindFilters(liquidSwell) {
20030
20084
  for (const [tag, handler] of Object.entries(filters)) {
@@ -20038,8 +20092,8 @@ ${injects.join("\n")}<\/script>`;
20038
20092
  }
20039
20093
  }
20040
20094
  }
20041
- function bindWithResolvedProps(liquidSwell, bind63, resolve = []) {
20042
- const handler = bind63(liquidSwell);
20095
+ function bindWithResolvedProps(liquidSwell, bind64, resolve = []) {
20096
+ const handler = bind64(liquidSwell);
20043
20097
  if (!Array.isArray(resolve)) {
20044
20098
  return handler;
20045
20099
  }
@@ -20256,7 +20310,7 @@ ${injects.join("\n")}<\/script>`;
20256
20310
  }
20257
20311
 
20258
20312
  // src/liquid/index.ts
20259
- var LiquidSwell29 = class extends import_liquidjs30.Liquid {
20313
+ var LiquidSwell30 = class extends import_liquidjs30.Liquid {
20260
20314
  theme;
20261
20315
  getThemeConfig;
20262
20316
  getThemeTemplateConfigByType;
@@ -20524,9 +20578,9 @@ ${injects.join("\n")}<\/script>`;
20524
20578
  fields: "id, name, type, file, file_path, hash"
20525
20579
  // NO file_data
20526
20580
  };
20581
+ const cache = new WorkerCacheProxy(this.swell);
20582
+ const versionHash = this.swell.swellHeaders["theme-version-hash"];
20527
20583
  try {
20528
- const cache = new WorkerCacheProxy(this.swell);
20529
- const versionHash = this.swell.swellHeaders["theme-version-hash"];
20530
20584
  const cached = await cache.get(
20531
20585
  "/:themes:configs",
20532
20586
  query,
@@ -20547,14 +20601,13 @@ ${injects.join("\n")}<\/script>`;
20547
20601
  query
20548
20602
  );
20549
20603
  const configs = response?.results || [];
20550
- try {
20551
- const cache = new WorkerCacheProxy(this.swell);
20552
- const versionHash = this.swell.swellHeaders["theme-version-hash"];
20553
- await cache.put("/:themes:configs", query, configs, {
20554
- version: versionHash || null
20555
- });
20556
- } catch (err) {
20557
- logger.warn("[ThemeLoader] Cache write failed", err);
20604
+ const ctx = this.swell.workerCtx || globalThis.executionContext;
20605
+ if (ctx && typeof ctx.waitUntil === "function") {
20606
+ ctx.waitUntil(
20607
+ cache.put("/:themes:configs", query, configs, {
20608
+ version: versionHash || null
20609
+ })
20610
+ );
20558
20611
  }
20559
20612
  return configs;
20560
20613
  }
@@ -20845,7 +20898,7 @@ ${injects.join("\n")}<\/script>`;
20845
20898
  this.forms = forms;
20846
20899
  this.resources = resources;
20847
20900
  this.shopifyCompatibilityClass = shopifyCompatibilityClass || ShopifyCompatibility2;
20848
- this.liquidSwell = new LiquidSwell29({
20901
+ this.liquidSwell = new LiquidSwell30({
20849
20902
  theme: this,
20850
20903
  getThemeConfig: this.getThemeConfig.bind(this),
20851
20904
  getAssetUrl: this.getAssetUrl.bind(this),