@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.cjs CHANGED
@@ -36,7 +36,7 @@ __export(index_exports, {
36
36
  FILE_DATA_INCLUDE_QUERY: () => FILE_DATA_INCLUDE_QUERY,
37
37
  GEO_DATA: () => GEO_DATA,
38
38
  LANG_TO_COUNTRY_CODES: () => LANG_TO_COUNTRY_CODES,
39
- LiquidSwell: () => LiquidSwell29,
39
+ LiquidSwell: () => LiquidSwell30,
40
40
  MAX_QUERY_PAGE_LIMIT: () => MAX_QUERY_PAGE_LIMIT,
41
41
  MockRecordResource: () => MockRecordResource,
42
42
  MockRecordSingleton: () => MockRecordSingleton,
@@ -7774,7 +7774,7 @@ var MAX_TTL = YEAR;
7774
7774
  var SHORT_TTL = 5 * SECOND;
7775
7775
 
7776
7776
  // src/cache/worker-cache-proxy.ts
7777
- var CACHE_NAME = "swell-cache-v1";
7777
+ var CACHE_NAME = "swell-cache-v011";
7778
7778
  var CACHE_KEY_ORIGIN = "https://cache.swell.store";
7779
7779
  var WorkerCacheProxy = class {
7780
7780
  swell;
@@ -7823,6 +7823,7 @@ var WorkerCacheProxy = class {
7823
7823
  }
7824
7824
  });
7825
7825
  await cache.put(keyUrl, response);
7826
+ logger.debug("[SDK] cache put done", { keyUrl });
7826
7827
  } catch {
7827
7828
  }
7828
7829
  }
@@ -19198,7 +19199,7 @@ var tags = {
19198
19199
  };
19199
19200
  function bindTags(liquidSwell) {
19200
19201
  Object.entries(tags).forEach(
19201
- ([tag, bind63]) => liquidSwell.registerTag(tag, bind63(liquidSwell))
19202
+ ([tag, bind64]) => liquidSwell.registerTag(tag, bind64(liquidSwell))
19202
19203
  );
19203
19204
  }
19204
19205
 
@@ -19366,8 +19367,60 @@ function applyStrftimeFormat(format, date) {
19366
19367
  return (0, import_strftime.default)(format, date);
19367
19368
  }
19368
19369
 
19369
- // src/liquid/filters/default_errors.ts
19370
+ // src/liquid/filters/date_next_interval.ts
19370
19371
  function bind34(_liquidSwell) {
19372
+ return (dateValue, interval, intervalCount) => {
19373
+ const date = ensureDate(dateValue);
19374
+ const result = getNextIntervalDate(date, interval, Number(intervalCount));
19375
+ return result ? new Date(result).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
19376
+ };
19377
+ }
19378
+ function getNextIntervalDate(date, interval, intervalCount) {
19379
+ if (!interval || !date) {
19380
+ return;
19381
+ }
19382
+ if (interval === "monthly" || interval === 30) {
19383
+ return dateNextMonth(date, intervalCount);
19384
+ }
19385
+ let intervalDays = 0;
19386
+ if (typeof interval === "string") {
19387
+ if (interval === "daily") {
19388
+ intervalDays = 1;
19389
+ } else if (interval === "weekly") {
19390
+ intervalDays = 7;
19391
+ } else if (interval === "yearly") {
19392
+ intervalDays = 365;
19393
+ }
19394
+ }
19395
+ if (intervalDays <= 0) {
19396
+ return;
19397
+ }
19398
+ return time(date) + intervalDays * intervalCount * 86400 * 1e3;
19399
+ }
19400
+ function dateNextMonth(startDate, intervalCount) {
19401
+ const date = new Date(startDate);
19402
+ const nextDate = new Date(date);
19403
+ nextDate.setUTCMonth(date.getMonth() + (intervalCount || 1));
19404
+ if (nextDate.getDate() !== date.getDate()) {
19405
+ nextDate.setDate(nextDate.getDate() - nextDate.getDate());
19406
+ }
19407
+ return nextDate.getTime();
19408
+ }
19409
+ function time(date) {
19410
+ if (date === void 0) {
19411
+ return Date.now();
19412
+ }
19413
+ if (typeof date === "number" || typeof date === "string") {
19414
+ return new Date(date).getTime();
19415
+ }
19416
+ if (date instanceof Date) {
19417
+ return date.getTime();
19418
+ }
19419
+ return Date.now();
19420
+ }
19421
+
19422
+ // src/liquid/filters/default_errors.ts
19423
+ function bind35(_liquidSwell) {
19371
19424
  return async function filterDefaultError(errors) {
19372
19425
  if (!errors) {
19373
19426
  return "";
@@ -19393,7 +19446,7 @@ function bind34(_liquidSwell) {
19393
19446
  }
19394
19447
 
19395
19448
  // src/liquid/filters/divided_by.ts
19396
- function bind35(_liquidSwell) {
19449
+ function bind36(_liquidSwell) {
19397
19450
  return (dividend, divisor, integerArithmetic) => {
19398
19451
  if (!isNumber(dividend) || !isNumber(divisor)) {
19399
19452
  return dividend;
@@ -19404,7 +19457,7 @@ function bind35(_liquidSwell) {
19404
19457
 
19405
19458
  // src/liquid/filters/embedded_content.ts
19406
19459
  var import_lodash_es10 = require("lodash-es");
19407
- function bind36(_liquidSwell) {
19460
+ function bind37(_liquidSwell) {
19408
19461
  return (value, tag = "iframe") => {
19409
19462
  const escapeIframes = value.replaceAll(`<${tag}`, `&lt;${tag}`).replaceAll(`</${tag}`, `&lt;/${tag}`);
19410
19463
  const removeTags = escapeIframes.replaceAll(/<(.*?)>/gi, "");
@@ -19415,7 +19468,7 @@ function bind36(_liquidSwell) {
19415
19468
  }
19416
19469
 
19417
19470
  // src/liquid/filters/font_face.ts
19418
- function bind37(_liquidSwell) {
19471
+ function bind38(_liquidSwell) {
19419
19472
  return (fontSetting, ...params) => {
19420
19473
  if (!fontSetting) {
19421
19474
  return null;
@@ -19427,14 +19480,14 @@ function bind37(_liquidSwell) {
19427
19480
  }
19428
19481
 
19429
19482
  // src/liquid/filters/font_modify.ts
19430
- function bind38(_liquidSwell) {
19483
+ function bind39(_liquidSwell) {
19431
19484
  return (fontSetting, prop, value) => {
19432
19485
  return ThemeFont.clone(fontSetting).modify(prop, value);
19433
19486
  };
19434
19487
  }
19435
19488
 
19436
19489
  // src/liquid/filters/font_url.ts
19437
- function bind39(_liquidSwell) {
19490
+ function bind40(_liquidSwell) {
19438
19491
  return (fontSetting) => {
19439
19492
  return ThemeFont.get(fontSetting).url();
19440
19493
  };
@@ -19484,14 +19537,14 @@ var format_address_default = {
19484
19537
 
19485
19538
  // src/liquid/filters/handleize.ts
19486
19539
  var import_lodash_es11 = require("lodash-es");
19487
- function bind40(_liquidSwell) {
19540
+ function bind41(_liquidSwell) {
19488
19541
  return function filterHandleize(handle) {
19489
19542
  return (0, import_lodash_es11.kebabCase)(handle);
19490
19543
  };
19491
19544
  }
19492
19545
 
19493
19546
  // src/liquid/filters/image_tag.ts
19494
- function bind41(_liquidSwell) {
19547
+ function bind42(_liquidSwell) {
19495
19548
  return function filterImageTag(imageUrl, ...params) {
19496
19549
  imageUrl = String(imageUrl || "");
19497
19550
  let {
@@ -19655,7 +19708,7 @@ var filterDefinition = {
19655
19708
  var image_url_default = filterDefinition;
19656
19709
 
19657
19710
  // src/liquid/filters/inline_asset_content.ts
19658
- function bind42(liquidSwell) {
19711
+ function bind43(liquidSwell) {
19659
19712
  return async (assetPath) => {
19660
19713
  const config = await liquidSwell.theme.getThemeConfig(
19661
19714
  `theme/assets/${assetPath}`
@@ -19665,14 +19718,14 @@ function bind42(liquidSwell) {
19665
19718
  }
19666
19719
 
19667
19720
  // src/liquid/filters/json.ts
19668
- function bind43(_liquidSwell) {
19721
+ function bind44(_liquidSwell) {
19669
19722
  return async function filterJson(input, space = 0) {
19670
19723
  return jsonStringifyAsync(input, space);
19671
19724
  };
19672
19725
  }
19673
19726
 
19674
19727
  // src/liquid/filters/json_pretty.ts
19675
- function bind44(_liquidSwell) {
19728
+ function bind45(_liquidSwell) {
19676
19729
  return async function filterJsonPretty(input, space = 2) {
19677
19730
  const output = await jsonStringifyAsync(input, space);
19678
19731
  return `<pre>${output}</pre>`;
@@ -19689,7 +19742,7 @@ function getCountryCode(localCode) {
19689
19742
  return localCode.toUpperCase();
19690
19743
  }
19691
19744
  }
19692
- function bind45(_liquidSwell) {
19745
+ function bind46(_liquidSwell) {
19693
19746
  return (localeCode) => {
19694
19747
  if (typeof localeCode !== "string") {
19695
19748
  return flags.US;
@@ -19700,7 +19753,7 @@ function bind45(_liquidSwell) {
19700
19753
  }
19701
19754
 
19702
19755
  // src/liquid/filters/money.ts
19703
- function bind46(liquidSwell) {
19756
+ function bind47(liquidSwell) {
19704
19757
  return function filterMoney(value) {
19705
19758
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
19706
19759
  return liquidSwell.renderCurrency(amount);
@@ -19708,7 +19761,7 @@ function bind46(liquidSwell) {
19708
19761
  }
19709
19762
 
19710
19763
  // src/liquid/filters/money_with_currency.ts
19711
- function bind47(liquidSwell) {
19764
+ function bind48(liquidSwell) {
19712
19765
  return function filterMoneyWithCurrency(value) {
19713
19766
  const { currency } = liquidSwell.theme.swell.getStorefrontLocalization();
19714
19767
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
@@ -19717,7 +19770,7 @@ function bind47(liquidSwell) {
19717
19770
  }
19718
19771
 
19719
19772
  // src/liquid/filters/money_without_currency.ts
19720
- function bind48(liquidSwell) {
19773
+ function bind49(liquidSwell) {
19721
19774
  return function filterMoneyWithoutCurrency(value) {
19722
19775
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
19723
19776
  return liquidSwell.renderCurrency(amount).replace(/[^0-9.,]/g, "");
@@ -19725,7 +19778,7 @@ function bind48(liquidSwell) {
19725
19778
  }
19726
19779
 
19727
19780
  // src/liquid/filters/money_without_trailing_zeros.ts
19728
- function bind49(liquidSwell) {
19781
+ function bind50(liquidSwell) {
19729
19782
  return function filterMoneyWithoutTrailingZeros(value) {
19730
19783
  const amount = value instanceof MoneyDrop ? value.toFloat() : Number(value || 0);
19731
19784
  return liquidSwell.renderCurrency(amount).split(".")[0].split(",")[0];
@@ -19733,21 +19786,21 @@ function bind49(liquidSwell) {
19733
19786
  }
19734
19787
 
19735
19788
  // src/liquid/filters/script_tag.ts
19736
- function bind50(_liquidSwell) {
19789
+ function bind51(_liquidSwell) {
19737
19790
  return function filterScriptTag(assetUrl) {
19738
19791
  return `<script src="${assetUrl}" type="text/javascript"></script>`;
19739
19792
  };
19740
19793
  }
19741
19794
 
19742
19795
  // src/liquid/filters/stylesheet_tag.ts
19743
- function bind51(_liquidSwell) {
19796
+ function bind52(_liquidSwell) {
19744
19797
  return function filterStyleSheetTag(assetUrl) {
19745
19798
  return `<link href="${assetUrl}" rel="stylesheet" type="text/css" media="all" />`;
19746
19799
  };
19747
19800
  }
19748
19801
 
19749
19802
  // src/liquid/filters/time_tag.ts
19750
- function bind52(_liquidSwell) {
19803
+ function bind53(_liquidSwell) {
19751
19804
  const dateFilter = bind33(_liquidSwell);
19752
19805
  return (dateValue, ...params) => {
19753
19806
  const date = ensureDate(dateValue);
@@ -19758,7 +19811,7 @@ function bind52(_liquidSwell) {
19758
19811
  }
19759
19812
 
19760
19813
  // src/liquid/filters/translate.ts
19761
- function bind53(liquidSwell) {
19814
+ function bind54(liquidSwell) {
19762
19815
  return async function filterTranslate(key, params) {
19763
19816
  const props = params && paramsToProps(params);
19764
19817
  const str = await liquidSwell.renderTranslation(key, props);
@@ -19767,7 +19820,7 @@ function bind53(liquidSwell) {
19767
19820
  }
19768
19821
 
19769
19822
  // src/liquid/filters/where.ts
19770
- function bind54(_liquidSwell) {
19823
+ function bind55(_liquidSwell) {
19771
19824
  return function* filterWhere(arr, property, expected) {
19772
19825
  const results = [];
19773
19826
  const list = yield resolveEnumerable(arr);
@@ -19821,7 +19874,7 @@ function getSizesFromParam(param) {
19821
19874
  height: height ? Number(height) : void 0
19822
19875
  };
19823
19876
  }
19824
- function bind55(liquidSwell) {
19877
+ function bind56(liquidSwell) {
19825
19878
  return async function filterAssetImgUrl(assetPath, size = "small") {
19826
19879
  const imageUrl = await liquidSwell.getAssetUrl(assetPath).then((url) => url || "");
19827
19880
  const sizes = getSizesFromParam(size);
@@ -19837,7 +19890,7 @@ function bind55(liquidSwell) {
19837
19890
  }
19838
19891
 
19839
19892
  // src/liquid/filters/shopify/hex_to_rgba.ts
19840
- function bind56(_liquidSwell) {
19893
+ function bind57(_liquidSwell) {
19841
19894
  return (color, alpha) => {
19842
19895
  return ThemeColor.get(color).rgba(alpha || 1);
19843
19896
  };
@@ -19857,14 +19910,14 @@ var item_count_for_variant_default = {
19857
19910
  };
19858
19911
 
19859
19912
  // src/liquid/filters/shopify/payment_button.ts
19860
- function bind57(_liquidSwell) {
19913
+ function bind58(_liquidSwell) {
19861
19914
  return (form) => {
19862
19915
  return null;
19863
19916
  };
19864
19917
  }
19865
19918
 
19866
19919
  // src/liquid/filters/shopify/payment_terms.ts
19867
- function bind58(_liquidSwell) {
19920
+ function bind59(_liquidSwell) {
19868
19921
  return (form) => {
19869
19922
  return null;
19870
19923
  };
@@ -19966,7 +20019,7 @@ var svgs = {
19966
20019
  var placeholder_svgs_default = svgs;
19967
20020
 
19968
20021
  // src/liquid/filters/shopify/placeholder_svg_tag.ts
19969
- function bind59(_liquidSwell) {
20022
+ function bind60(_liquidSwell) {
19970
20023
  return function filterPlaceholderSvgTag(name, className) {
19971
20024
  const svg = placeholder_svgs_default[name];
19972
20025
  if (typeof svg === "object" && svg !== null) {
@@ -19977,7 +20030,7 @@ function bind59(_liquidSwell) {
19977
20030
  }
19978
20031
 
19979
20032
  // src/liquid/filters/shopify/shopify_asset_url.ts
19980
- function bind60(_liquidSwell) {
20033
+ function bind61(_liquidSwell) {
19981
20034
  return function filterShopifyAssetUrl(input) {
19982
20035
  if (typeof input === "string") {
19983
20036
  switch (input) {
@@ -20002,7 +20055,7 @@ function bind60(_liquidSwell) {
20002
20055
  }
20003
20056
 
20004
20057
  // src/liquid/filters/shopify/structured_data.ts
20005
- function bind61(_liquidSwell) {
20058
+ function bind62(_liquidSwell) {
20006
20059
  return async function filterStructuredData(input) {
20007
20060
  let value = input;
20008
20061
  if (value instanceof StorefrontResource) {
@@ -20080,7 +20133,7 @@ function convertToSchemaOrgProductGroup(product) {
20080
20133
  }
20081
20134
 
20082
20135
  // src/liquid/filters/inline_editable.ts
20083
- function bind62(_liquidSwell) {
20136
+ function bind63(_liquidSwell) {
20084
20137
  return (value, key) => {
20085
20138
  if (typeof value === "object" && "value" in value) {
20086
20139
  value = value.value;
@@ -20106,45 +20159,46 @@ var filters = {
20106
20159
  color_to_hex: bind30,
20107
20160
  color_to_hsl: bind31,
20108
20161
  color_to_rgb: bind32,
20162
+ date_next_interval: bind34,
20109
20163
  date: bind33,
20110
- default_errors: bind34,
20111
- divided_by: bind35,
20112
- embedded_content: bind36,
20113
- font_face: bind37,
20114
- font_modify: bind38,
20115
- font_url: bind39,
20164
+ default_errors: bind35,
20165
+ divided_by: bind36,
20166
+ embedded_content: bind37,
20167
+ font_face: bind38,
20168
+ font_modify: bind39,
20169
+ font_url: bind40,
20116
20170
  format_address: format_address_default,
20117
- handle: bind40,
20171
+ handle: bind41,
20118
20172
  // alias
20119
- handleize: bind40,
20120
- image_tag: bind41,
20173
+ handleize: bind41,
20174
+ image_tag: bind42,
20121
20175
  image_url: image_url_default,
20122
- inline_asset_content: bind42,
20123
- json: bind43,
20124
- json_pretty: bind44,
20125
- locale_flag: bind45,
20126
- money: bind46,
20127
- money_with_currency: bind47,
20128
- money_without_currency: bind48,
20129
- money_without_trailing_zeros: bind49,
20130
- script_tag: bind50,
20131
- stylesheet_tag: bind51,
20132
- time_tag: bind52,
20133
- translate: bind53,
20134
- t: bind53,
20176
+ inline_asset_content: bind43,
20177
+ json: bind44,
20178
+ json_pretty: bind45,
20179
+ locale_flag: bind46,
20180
+ money: bind47,
20181
+ money_with_currency: bind48,
20182
+ money_without_currency: bind49,
20183
+ money_without_trailing_zeros: bind50,
20184
+ script_tag: bind51,
20185
+ stylesheet_tag: bind52,
20186
+ time_tag: bind53,
20187
+ translate: bind54,
20188
+ t: bind54,
20135
20189
  // alias
20136
- where: bind54,
20190
+ where: bind55,
20137
20191
  // Shopify compatibility only
20138
- asset_img_url: bind55,
20139
- hex_to_rgba: bind56,
20192
+ asset_img_url: bind56,
20193
+ hex_to_rgba: bind57,
20140
20194
  item_count_for_variant: item_count_for_variant_default,
20141
- payment_button: bind57,
20142
- payment_terms: bind58,
20143
- placeholder_svg_tag: bind59,
20144
- shopify_asset_url: bind60,
20145
- structured_data: bind61,
20195
+ payment_button: bind58,
20196
+ payment_terms: bind59,
20197
+ placeholder_svg_tag: bind60,
20198
+ shopify_asset_url: bind61,
20199
+ structured_data: bind62,
20146
20200
  // Swell only
20147
- inline_editable: bind62
20201
+ inline_editable: bind63
20148
20202
  };
20149
20203
  function bindFilters(liquidSwell) {
20150
20204
  for (const [tag, handler] of Object.entries(filters)) {
@@ -20158,8 +20212,8 @@ function bindFilters(liquidSwell) {
20158
20212
  }
20159
20213
  }
20160
20214
  }
20161
- function bindWithResolvedProps(liquidSwell, bind63, resolve = []) {
20162
- const handler = bind63(liquidSwell);
20215
+ function bindWithResolvedProps(liquidSwell, bind64, resolve = []) {
20216
+ const handler = bind64(liquidSwell);
20163
20217
  if (!Array.isArray(resolve)) {
20164
20218
  return handler;
20165
20219
  }
@@ -20376,7 +20430,7 @@ function isThemeColorLike(value) {
20376
20430
  }
20377
20431
 
20378
20432
  // src/liquid/index.ts
20379
- var LiquidSwell29 = class extends import_liquidjs30.Liquid {
20433
+ var LiquidSwell30 = class extends import_liquidjs30.Liquid {
20380
20434
  theme;
20381
20435
  getThemeConfig;
20382
20436
  getThemeTemplateConfigByType;
@@ -20644,9 +20698,9 @@ var ThemeLoader = class {
20644
20698
  fields: "id, name, type, file, file_path, hash"
20645
20699
  // NO file_data
20646
20700
  };
20701
+ const cache = new WorkerCacheProxy(this.swell);
20702
+ const versionHash = this.swell.swellHeaders["theme-version-hash"];
20647
20703
  try {
20648
- const cache = new WorkerCacheProxy(this.swell);
20649
- const versionHash = this.swell.swellHeaders["theme-version-hash"];
20650
20704
  const cached = await cache.get(
20651
20705
  "/:themes:configs",
20652
20706
  query,
@@ -20667,14 +20721,13 @@ var ThemeLoader = class {
20667
20721
  query
20668
20722
  );
20669
20723
  const configs = response?.results || [];
20670
- try {
20671
- const cache = new WorkerCacheProxy(this.swell);
20672
- const versionHash = this.swell.swellHeaders["theme-version-hash"];
20673
- await cache.put("/:themes:configs", query, configs, {
20674
- version: versionHash || null
20675
- });
20676
- } catch (err) {
20677
- logger.warn("[ThemeLoader] Cache write failed", err);
20724
+ const ctx = this.swell.workerCtx || globalThis.executionContext;
20725
+ if (ctx && typeof ctx.waitUntil === "function") {
20726
+ ctx.waitUntil(
20727
+ cache.put("/:themes:configs", query, configs, {
20728
+ version: versionHash || null
20729
+ })
20730
+ );
20678
20731
  }
20679
20732
  return configs;
20680
20733
  }
@@ -20965,7 +21018,7 @@ var SwellTheme3 = class {
20965
21018
  this.forms = forms;
20966
21019
  this.resources = resources;
20967
21020
  this.shopifyCompatibilityClass = shopifyCompatibilityClass || ShopifyCompatibility2;
20968
- this.liquidSwell = new LiquidSwell29({
21021
+ this.liquidSwell = new LiquidSwell30({
20969
21022
  theme: this,
20970
21023
  getThemeConfig: this.getThemeConfig.bind(this),
20971
21024
  getAssetUrl: this.getAssetUrl.bind(this),