@swell/apps-sdk 1.0.182 → 1.0.184

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
@@ -12649,7 +12649,7 @@ function ShopifyCart(instance, cart) {
12649
12649
  );
12650
12650
  }),
12651
12651
  items_subtotal_price: defer(() => instance.toShopifyPrice(cart.sub_total)),
12652
- note: defer(() => cart.comments),
12652
+ note: deferWith(cart, (cart2) => cart2.comments),
12653
12653
  original_total_price: deferWith(
12654
12654
  cart,
12655
12655
  (cart2) => instance.toShopifyPrice(cart2.sub_total)
@@ -13734,15 +13734,10 @@ var CollectionsDrop = class extends Drop10 {
13734
13734
  switch (typeof key) {
13735
13735
  case "string": {
13736
13736
  if (key === "all") {
13737
- let resource = this.#map.get(key);
13738
- if (resource === void 0) {
13739
- resource = ShopifyCollection(
13740
- this.#instance,
13741
- new AllCategoryResource(this.#instance)
13742
- );
13743
- this.#map.set(key, resource);
13744
- }
13745
- return resource;
13737
+ return this.getAllCollection();
13738
+ }
13739
+ if (key === "size") {
13740
+ return this.getAllCollectionsSize();
13746
13741
  }
13747
13742
  return this.getCollection(key);
13748
13743
  }
@@ -13772,6 +13767,21 @@ var CollectionsDrop = class extends Drop10 {
13772
13767
  }
13773
13768
  return resource;
13774
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
+ }
13775
13785
  };
13776
13786
  var Collections = class extends SwellStorefrontCollection {
13777
13787
  #drop;
@@ -15549,7 +15559,7 @@ var tags = {
15549
15559
  };
15550
15560
  function bindTags(liquidSwell) {
15551
15561
  Object.entries(tags).forEach(
15552
- ([tag, bind66]) => liquidSwell.registerTag(tag, bind66(liquidSwell))
15562
+ ([tag, bind67]) => liquidSwell.registerTag(tag, bind67(liquidSwell))
15553
15563
  );
15554
15564
  }
15555
15565
 
@@ -15817,8 +15827,22 @@ function bind37(_liquidSwell) {
15817
15827
  };
15818
15828
  }
15819
15829
 
15820
- // src/liquid/filters/font_face.ts
15830
+ // src/liquid/filters/escape.ts
15831
+ import { escape } from "lodash-es";
15821
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) {
15822
15846
  return (fontSetting, ...params) => {
15823
15847
  if (!fontSetting) {
15824
15848
  return null;
@@ -15830,14 +15854,14 @@ function bind38(_liquidSwell) {
15830
15854
  }
15831
15855
 
15832
15856
  // src/liquid/filters/font_modify.ts
15833
- function bind39(_liquidSwell) {
15857
+ function bind40(_liquidSwell) {
15834
15858
  return (fontSetting, prop, value) => {
15835
15859
  return ThemeFont.clone(fontSetting).modify(prop, value);
15836
15860
  };
15837
15861
  }
15838
15862
 
15839
15863
  // src/liquid/filters/font_url.ts
15840
- function bind40(_liquidSwell) {
15864
+ function bind41(_liquidSwell) {
15841
15865
  return (fontSetting) => {
15842
15866
  return ThemeFont.get(fontSetting).url();
15843
15867
  };
@@ -15887,14 +15911,14 @@ var format_address_default = {
15887
15911
 
15888
15912
  // src/liquid/filters/handleize.ts
15889
15913
  import { kebabCase } from "lodash-es";
15890
- function bind41(_liquidSwell) {
15914
+ function bind42(_liquidSwell) {
15891
15915
  return function filterHandleize(handle) {
15892
15916
  return kebabCase(handle);
15893
15917
  };
15894
15918
  }
15895
15919
 
15896
15920
  // src/liquid/filters/image_tag.ts
15897
- function bind42(_liquidSwell) {
15921
+ function bind43(_liquidSwell) {
15898
15922
  return function filterImageTag(imageUrl, ...params) {
15899
15923
  imageUrl = String(imageUrl || "");
15900
15924
  let {
@@ -16058,7 +16082,7 @@ var filterDefinition = {
16058
16082
  var image_url_default = filterDefinition;
16059
16083
 
16060
16084
  // src/liquid/filters/inline_asset_content.ts
16061
- function bind43(liquidSwell) {
16085
+ function bind44(liquidSwell) {
16062
16086
  return async (assetPath) => {
16063
16087
  const config = await liquidSwell.theme.getThemeConfig(
16064
16088
  `theme/assets/${assetPath}`
@@ -16068,14 +16092,14 @@ function bind43(liquidSwell) {
16068
16092
  }
16069
16093
 
16070
16094
  // src/liquid/filters/json.ts
16071
- function bind44(_liquidSwell) {
16095
+ function bind45(_liquidSwell) {
16072
16096
  return async function filterJson(input, space = 0) {
16073
16097
  return jsonStringifyAsync(input, space);
16074
16098
  };
16075
16099
  }
16076
16100
 
16077
16101
  // src/liquid/filters/json_pretty.ts
16078
- function bind45(_liquidSwell) {
16102
+ function bind46(_liquidSwell) {
16079
16103
  return async function filterJsonPretty(input, space = 2) {
16080
16104
  const output = await jsonStringifyAsync(input, space);
16081
16105
  return `<pre>${output}</pre>`;
@@ -16085,7 +16109,7 @@ function bind45(_liquidSwell) {
16085
16109
  // src/liquid/filters/locale_flag.ts
16086
16110
  import { hasFlag } from "country-flag-icons";
16087
16111
  import * as flags from "country-flag-icons/string/1x1";
16088
- function bind46(_liquidSwell) {
16112
+ function bind47(_liquidSwell) {
16089
16113
  return (localeCode) => {
16090
16114
  if (typeof localeCode !== "string") {
16091
16115
  return flags.US;
@@ -16096,7 +16120,7 @@ function bind46(_liquidSwell) {
16096
16120
  }
16097
16121
 
16098
16122
  // src/liquid/filters/minus.ts
16099
- function bind47(_liquidSwell) {
16123
+ function bind48(_liquidSwell) {
16100
16124
  return (first, second) => {
16101
16125
  const firstValue = isNumber(first) ? first : 0;
16102
16126
  const secondValue = isNumber(second) ? second : 0;
@@ -16105,7 +16129,7 @@ function bind47(_liquidSwell) {
16105
16129
  }
16106
16130
 
16107
16131
  // src/liquid/filters/money.ts
16108
- function bind48(liquidSwell) {
16132
+ function bind49(liquidSwell) {
16109
16133
  return function filterMoney(value) {
16110
16134
  const amount = getMoneyAmount(liquidSwell, value);
16111
16135
  return liquidSwell.renderCurrency(amount);
@@ -16122,7 +16146,7 @@ function getMoneyAmount(liquidSwell, value) {
16122
16146
  }
16123
16147
 
16124
16148
  // src/liquid/filters/money_with_currency.ts
16125
- function bind49(liquidSwell) {
16149
+ function bind50(liquidSwell) {
16126
16150
  return function filterMoneyWithCurrency(value) {
16127
16151
  const { currency } = liquidSwell.theme.swell.getStorefrontLocalization();
16128
16152
  const amount = getMoneyAmount(liquidSwell, value);
@@ -16131,7 +16155,7 @@ function bind49(liquidSwell) {
16131
16155
  }
16132
16156
 
16133
16157
  // src/liquid/filters/money_without_currency.ts
16134
- function bind50(liquidSwell) {
16158
+ function bind51(liquidSwell) {
16135
16159
  return function filterMoneyWithoutCurrency(value) {
16136
16160
  const amount = getMoneyAmount(liquidSwell, value);
16137
16161
  return liquidSwell.renderCurrency(amount).replace(/[^0-9.,]/g, "");
@@ -16139,7 +16163,7 @@ function bind50(liquidSwell) {
16139
16163
  }
16140
16164
 
16141
16165
  // src/liquid/filters/money_without_trailing_zeros.ts
16142
- function bind51(liquidSwell) {
16166
+ function bind52(liquidSwell) {
16143
16167
  return function filterMoneyWithoutTrailingZeros(value) {
16144
16168
  const amount = getMoneyAmount(liquidSwell, value);
16145
16169
  return liquidSwell.renderCurrency(amount).split(".")[0].split(",")[0];
@@ -16147,21 +16171,21 @@ function bind51(liquidSwell) {
16147
16171
  }
16148
16172
 
16149
16173
  // src/liquid/filters/script_tag.ts
16150
- function bind52(_liquidSwell) {
16174
+ function bind53(_liquidSwell) {
16151
16175
  return function filterScriptTag(assetUrl) {
16152
16176
  return `<script src="${assetUrl}" type="text/javascript"></script>`;
16153
16177
  };
16154
16178
  }
16155
16179
 
16156
16180
  // src/liquid/filters/stylesheet_tag.ts
16157
- function bind53(_liquidSwell) {
16181
+ function bind54(_liquidSwell) {
16158
16182
  return function filterStyleSheetTag(assetUrl) {
16159
16183
  return `<link href="${assetUrl}" rel="stylesheet" type="text/css" media="all" />`;
16160
16184
  };
16161
16185
  }
16162
16186
 
16163
16187
  // src/liquid/filters/time_tag.ts
16164
- function bind54(_liquidSwell) {
16188
+ function bind55(_liquidSwell) {
16165
16189
  const dateFilter = bind33(_liquidSwell);
16166
16190
  return (dateValue, ...params) => {
16167
16191
  const date = ensureDate(dateValue);
@@ -16172,7 +16196,7 @@ function bind54(_liquidSwell) {
16172
16196
  }
16173
16197
 
16174
16198
  // src/liquid/filters/translate.ts
16175
- function bind55(liquidSwell) {
16199
+ function bind56(liquidSwell) {
16176
16200
  return async function filterTranslate(key, params) {
16177
16201
  const props = params && paramsToProps(params);
16178
16202
  const str = await liquidSwell.renderTranslation(key, props);
@@ -16181,7 +16205,7 @@ function bind55(liquidSwell) {
16181
16205
  }
16182
16206
 
16183
16207
  // src/liquid/filters/where.ts
16184
- function bind56(_liquidSwell) {
16208
+ function bind57(_liquidSwell) {
16185
16209
  return function* filterWhere(arr, property, expected) {
16186
16210
  const results = [];
16187
16211
  const list = yield resolveEnumerable(arr);
@@ -16235,7 +16259,7 @@ function getSizesFromParam(param) {
16235
16259
  height: height ? Number(height) : void 0
16236
16260
  };
16237
16261
  }
16238
- function bind57(liquidSwell) {
16262
+ function bind58(liquidSwell) {
16239
16263
  return async function filterAssetImgUrl(assetPath, size = "small") {
16240
16264
  const imageUrl = await liquidSwell.getAssetUrl(assetPath).then((url) => url || "");
16241
16265
  const sizes = getSizesFromParam(size);
@@ -16251,14 +16275,14 @@ function bind57(liquidSwell) {
16251
16275
  }
16252
16276
 
16253
16277
  // src/liquid/filters/shopify/hex_to_rgba.ts
16254
- function bind58(_liquidSwell) {
16278
+ function bind59(_liquidSwell) {
16255
16279
  return (color, alpha) => {
16256
16280
  return ThemeColor.get(color).rgba(alpha || 1);
16257
16281
  };
16258
16282
  }
16259
16283
 
16260
16284
  // src/liquid/filters/shopify/img_url.ts
16261
- function bind59(liquidSwell) {
16285
+ function bind60(liquidSwell) {
16262
16286
  return async function filterImgUrl(input, ...params) {
16263
16287
  const url = await getImageUrlFromInput(input, liquidSwell);
16264
16288
  if (typeof url !== "string" || url === "") {
@@ -16296,14 +16320,14 @@ var item_count_for_variant_default = {
16296
16320
  };
16297
16321
 
16298
16322
  // src/liquid/filters/shopify/payment_button.ts
16299
- function bind60(_liquidSwell) {
16323
+ function bind61(_liquidSwell) {
16300
16324
  return (form) => {
16301
16325
  return `<button style="display: block; visibility: hidden;"></button>`;
16302
16326
  };
16303
16327
  }
16304
16328
 
16305
16329
  // src/liquid/filters/shopify/payment_terms.ts
16306
- function bind61(_liquidSwell) {
16330
+ function bind62(_liquidSwell) {
16307
16331
  return (form) => {
16308
16332
  return null;
16309
16333
  };
@@ -16405,7 +16429,7 @@ var svgs = {
16405
16429
  var placeholder_svgs_default = svgs;
16406
16430
 
16407
16431
  // src/liquid/filters/shopify/placeholder_svg_tag.ts
16408
- function bind62(_liquidSwell) {
16432
+ function bind63(_liquidSwell) {
16409
16433
  return function filterPlaceholderSvgTag(name, className) {
16410
16434
  const svg = placeholder_svgs_default[name];
16411
16435
  if (typeof svg === "object" && svg !== null) {
@@ -16416,7 +16440,7 @@ function bind62(_liquidSwell) {
16416
16440
  }
16417
16441
 
16418
16442
  // src/liquid/filters/shopify/shopify_asset_url.ts
16419
- function bind63(_liquidSwell) {
16443
+ function bind64(_liquidSwell) {
16420
16444
  return function filterShopifyAssetUrl(input) {
16421
16445
  if (typeof input === "string") {
16422
16446
  switch (input) {
@@ -16441,7 +16465,7 @@ function bind63(_liquidSwell) {
16441
16465
  }
16442
16466
 
16443
16467
  // src/liquid/filters/shopify/structured_data.ts
16444
- function bind64(_liquidSwell) {
16468
+ function bind65(_liquidSwell) {
16445
16469
  return async function filterStructuredData(input) {
16446
16470
  let value = input;
16447
16471
  if (value instanceof StorefrontResource) {
@@ -16519,7 +16543,7 @@ function convertToSchemaOrgProductGroup(product) {
16519
16543
  }
16520
16544
 
16521
16545
  // src/liquid/filters/inline_editable.ts
16522
- function bind65(_liquidSwell) {
16546
+ function bind66(_liquidSwell) {
16523
16547
  return (value, key) => {
16524
16548
  if (typeof value === "object" && "value" in value) {
16525
16549
  value = value.value;
@@ -16550,43 +16574,44 @@ var filters = {
16550
16574
  default_errors: bind35,
16551
16575
  divided_by: bind36,
16552
16576
  embedded_content: bind37,
16553
- font_face: bind38,
16554
- font_modify: bind39,
16555
- font_url: bind40,
16577
+ escape: bind38,
16578
+ font_face: bind39,
16579
+ font_modify: bind40,
16580
+ font_url: bind41,
16556
16581
  format_address: format_address_default,
16557
- handle: bind41,
16582
+ handle: bind42,
16558
16583
  // alias
16559
- handleize: bind41,
16560
- image_tag: bind42,
16584
+ handleize: bind42,
16585
+ image_tag: bind43,
16561
16586
  image_url: image_url_default,
16562
- inline_asset_content: bind43,
16563
- json: bind44,
16564
- json_pretty: bind45,
16565
- locale_flag: bind46,
16566
- minus: bind47,
16567
- money: bind48,
16568
- money_with_currency: bind49,
16569
- money_without_currency: bind50,
16570
- money_without_trailing_zeros: bind51,
16571
- script_tag: bind52,
16572
- stylesheet_tag: bind53,
16573
- time_tag: bind54,
16574
- translate: bind55,
16575
- 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,
16576
16601
  // alias
16577
- where: bind56,
16602
+ where: bind57,
16578
16603
  // Shopify compatibility only
16579
- asset_img_url: bind57,
16580
- hex_to_rgba: bind58,
16581
- img_url: bind59,
16604
+ asset_img_url: bind58,
16605
+ hex_to_rgba: bind59,
16606
+ img_url: bind60,
16582
16607
  item_count_for_variant: item_count_for_variant_default,
16583
- payment_button: bind60,
16584
- payment_terms: bind61,
16585
- placeholder_svg_tag: bind62,
16586
- shopify_asset_url: bind63,
16587
- 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,
16588
16613
  // Swell only
16589
- inline_editable: bind65
16614
+ inline_editable: bind66
16590
16615
  };
16591
16616
  function bindFilters(liquidSwell) {
16592
16617
  for (const [tag, handler] of Object.entries(filters)) {
@@ -16600,8 +16625,8 @@ function bindFilters(liquidSwell) {
16600
16625
  }
16601
16626
  }
16602
16627
  }
16603
- function bindWithResolvedProps(liquidSwell, bind66, resolve = []) {
16604
- const handler = bind66(liquidSwell);
16628
+ function bindWithResolvedProps(liquidSwell, bind67, resolve = []) {
16629
+ const handler = bind67(liquidSwell);
16605
16630
  if (!Array.isArray(resolve)) {
16606
16631
  return handler;
16607
16632
  }
@@ -17416,14 +17441,14 @@ function getRobotsGlobals(canonicalUrl) {
17416
17441
  default_groups: [
17417
17442
  {
17418
17443
  user_agent: RobotsRule.from("User-agent", "*"),
17419
- // sitemap: RobotsRule.from('Sitemap', sitemapUrl),
17444
+ sitemap: RobotsRule.from("Sitemap", sitemapUrl),
17420
17445
  rules: defaultRules.map(
17421
17446
  (rule) => RobotsRule.from(rule.directive, rule.value)
17422
17447
  )
17423
17448
  },
17424
17449
  {
17425
17450
  user_agent: RobotsRule.from("User-agent", "AhrefsBot"),
17426
- // sitemap: RobotsRule.from('Sitemap', sitemapUrl),
17451
+ sitemap: RobotsRule.from("Sitemap", sitemapUrl),
17427
17452
  rules: [
17428
17453
  RobotsRule.from("Crawl-delay", "10"),
17429
17454
  ...defaultRules.map(
@@ -17433,7 +17458,7 @@ function getRobotsGlobals(canonicalUrl) {
17433
17458
  },
17434
17459
  {
17435
17460
  user_agent: RobotsRule.from("User-agent", "AhrefsSiteAudit"),
17436
- // sitemap: RobotsRule.from('Sitemap', sitemapUrl),
17461
+ sitemap: RobotsRule.from("Sitemap", sitemapUrl),
17437
17462
  rules: [
17438
17463
  RobotsRule.from("Crawl-delay", "10"),
17439
17464
  ...defaultRules.map(
@@ -19393,6 +19418,35 @@ var DEFAULT_CACHE_RULES = {
19393
19418
  },
19394
19419
  pathRules: [{ path: "/checkout/*", skip: true }]
19395
19420
  };
19421
+ var SANITIZE_CLIENT_HEADERS = Object.freeze([
19422
+ "connection",
19423
+ "proxy-connection",
19424
+ "keep-alive",
19425
+ "transfer-encoding",
19426
+ "upgrade",
19427
+ "proxy-authenticate",
19428
+ "proxy-authorization",
19429
+ "te",
19430
+ "trailers",
19431
+ "via",
19432
+ "alt-svc",
19433
+ "content-length",
19434
+ "content-encoding",
19435
+ // Also strip any legacy internal metadata keys
19436
+ "x-original-ttl",
19437
+ "x-original-swr",
19438
+ "x-cache-time"
19439
+ ]);
19440
+ var CACHE_KEY_HEADERS = Object.freeze([
19441
+ "cookie",
19442
+ "swell-storefront-id",
19443
+ "swell-app-id",
19444
+ "swell-access-token",
19445
+ "swell-theme-version-hash",
19446
+ "swell-cache-modified",
19447
+ "x-locale",
19448
+ "swell-storefront-context"
19449
+ ]);
19396
19450
  var HtmlCache = class {
19397
19451
  epoch;
19398
19452
  backend;
@@ -19400,7 +19454,23 @@ var HtmlCache = class {
19400
19454
  constructor(epoch, backend, cacheRules = DEFAULT_CACHE_RULES) {
19401
19455
  this.epoch = epoch;
19402
19456
  this.backend = backend;
19403
- this.cacheRules = cacheRules;
19457
+ this.cacheRules = {
19458
+ ...cacheRules,
19459
+ pathRules: cacheRules.pathRules?.map((rule) => ({
19460
+ ...rule,
19461
+ regex: this.convertPathToRegex(rule.path)
19462
+ }))
19463
+ };
19464
+ }
19465
+ /**
19466
+ * Converts wildcard pattern to regex and tests against path.
19467
+ *
19468
+ * - `*` matches any characters except `/`
19469
+ * - `**` matches any characters including `/`
19470
+ */
19471
+ convertPathToRegex(pattern) {
19472
+ const regex = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "___DOUBLE_STAR___").replace(/\*/g, "[^/]*").replace(/___DOUBLE_STAR___/g, ".*");
19473
+ return new RegExp(`^${regex}$`);
19404
19474
  }
19405
19475
  async get(request) {
19406
19476
  const trace = createTraceId();
@@ -19491,18 +19561,18 @@ var HtmlCache = class {
19491
19561
  );
19492
19562
  return;
19493
19563
  }
19494
- const cacheTimeISO = (/* @__PURE__ */ new Date()).toISOString();
19564
+ const date = /* @__PURE__ */ new Date();
19495
19565
  const headers = this.normalizeHeaders(response.headers);
19496
19566
  const entry = {
19497
19567
  status: response.status,
19498
19568
  statusText: response.statusText,
19499
19569
  headers,
19500
19570
  body,
19501
- cacheTimeISO,
19571
+ cacheTimeISO: date.toISOString(),
19502
19572
  ttl,
19503
19573
  swr,
19504
19574
  etag: this.quoteETag(headers["etag"] || md5(body)),
19505
- lastModifiedUTC: headers["last-modified"] || new Date(cacheTimeISO).toUTCString()
19575
+ lastModifiedUTC: headers["last-modified"] || date.toUTCString()
19506
19576
  };
19507
19577
  const hardExpireSeconds = ttl + swr;
19508
19578
  await this.backend.write(cacheKey, entry, hardExpireSeconds);
@@ -19527,8 +19597,13 @@ var HtmlCache = class {
19527
19597
  }
19528
19598
  }
19529
19599
  canReadFromCache(request) {
19530
- const method = request.method.toUpperCase();
19531
- if (!(method === "GET" || method === "HEAD")) return false;
19600
+ switch (request.method.toUpperCase()) {
19601
+ case "GET":
19602
+ case "HEAD":
19603
+ break;
19604
+ default:
19605
+ return false;
19606
+ }
19532
19607
  const res = this.resolvePathRule(request);
19533
19608
  if (res.skip) return false;
19534
19609
  return this.isRequestCacheable(request);
@@ -19594,7 +19669,7 @@ var HtmlCache = class {
19594
19669
  try {
19595
19670
  const ifModDate = new Date(ifModifiedSince);
19596
19671
  const lastModDate = new Date(lastModified);
19597
- if (isNaN(ifModDate.getTime()) || isNaN(lastModDate.getTime())) {
19672
+ if (Number.isNaN(ifModDate.getTime()) || Number.isNaN(lastModDate.getTime())) {
19598
19673
  return false;
19599
19674
  }
19600
19675
  return ifModDate >= lastModDate;
@@ -19624,31 +19699,25 @@ var HtmlCache = class {
19624
19699
  return `"${value}"`;
19625
19700
  }
19626
19701
  sanitizeClientHeaders(headers) {
19627
- const HOP_BY_HOP = [
19628
- "connection",
19629
- "proxy-connection",
19630
- "keep-alive",
19631
- "transfer-encoding",
19632
- "upgrade",
19633
- "proxy-authenticate",
19634
- "proxy-authorization",
19635
- "te",
19636
- "trailers",
19637
- "via",
19638
- "alt-svc",
19639
- "content-length"
19640
- ];
19641
- for (const h of HOP_BY_HOP) headers.delete(h);
19642
- headers.delete("content-encoding");
19643
- headers.delete("x-original-ttl");
19644
- headers.delete("x-original-swr");
19645
- headers.delete("x-cache-time");
19702
+ for (const name of SANITIZE_CLIENT_HEADERS) {
19703
+ headers.delete(name);
19704
+ }
19705
+ }
19706
+ getCacheKeyHeaders(headers) {
19707
+ const acc = new Headers();
19708
+ for (const name of CACHE_KEY_HEADERS) {
19709
+ const value = headers.get(name);
19710
+ if (value) {
19711
+ acc.set(name, value);
19712
+ }
19713
+ }
19714
+ return acc;
19646
19715
  }
19647
19716
  generateVersionHash(headers) {
19648
- const swellData = this.extractSwellData(headers);
19717
+ const swellData = this.extractSwellData(headers.get("cookie"));
19649
19718
  const versionFactors = {
19650
19719
  store: headers.get("swell-storefront-id") || "",
19651
- app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
19720
+ app: headers.get("swell-app-id") || "",
19652
19721
  auth: headers.get("swell-access-token") || "",
19653
19722
  theme: headers.get("swell-theme-version-hash") || "",
19654
19723
  modified: headers.get("swell-cache-modified") || "",
@@ -19659,8 +19728,7 @@ var HtmlCache = class {
19659
19728
  };
19660
19729
  return md5(JSON.stringify(versionFactors));
19661
19730
  }
19662
- extractSwellData(headers) {
19663
- const cookie = headers.get("cookie");
19731
+ extractSwellData(cookie) {
19664
19732
  if (!cookie) return {};
19665
19733
  const swellDataMatch = cookie.match(/swell-data=([^;]+)/);
19666
19734
  if (!swellDataMatch) return {};
@@ -19712,15 +19780,6 @@ var HtmlCache = class {
19712
19780
  const age = (Date.now() - t) / 1e3;
19713
19781
  return age < 0 ? 0 : age;
19714
19782
  }
19715
- /**
19716
- * Converts wildcard pattern to regex and tests against path.
19717
- * - * matches any characters except /
19718
- * - ** matches any characters including /
19719
- */
19720
- pathMatches(pattern, path) {
19721
- const regex = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "___DOUBLE_STAR___").replace(/\*/g, "[^/]*").replace(/___DOUBLE_STAR___/g, ".*");
19722
- return new RegExp(`^${regex}$`).test(path);
19723
- }
19724
19783
  normalizeHeaders(headers) {
19725
19784
  const normalized = {};
19726
19785
  headers.forEach((value, key) => {
@@ -19731,16 +19790,10 @@ var HtmlCache = class {
19731
19790
  resolvePathRule(request) {
19732
19791
  const url = new URL(request.url);
19733
19792
  const mode = this.getDeploymentMode(request.headers);
19734
- const defaults = this.cacheRules.defaults?.[mode] ?? DEFAULT_CACHE_RULES.defaults[mode];
19735
- let rule;
19736
- if (this.cacheRules.pathRules) {
19737
- for (const r of this.cacheRules.pathRules) {
19738
- if (this.pathMatches(r.path, url.pathname)) {
19739
- rule = r;
19740
- break;
19741
- }
19742
- }
19743
- }
19793
+ const defaults = this.cacheRules.defaults?.[mode] ?? DEFAULT_CACHE_RULES.defaults?.[mode];
19794
+ const rule = this.cacheRules.pathRules?.find(
19795
+ (r) => r.regex.test(url.pathname)
19796
+ );
19744
19797
  const effectiveTTL = (rule?.ttl !== void 0 ? rule.ttl : defaults?.ttl) ?? defaults.ttl;
19745
19798
  const effectiveSWR = (rule?.swr !== void 0 ? rule.swr : defaults?.swr) ?? defaults.swr;
19746
19799
  return {
@@ -19752,27 +19805,29 @@ var HtmlCache = class {
19752
19805
  };
19753
19806
  }
19754
19807
  normalizeSearchParams(searchParams) {
19755
- const ignoredParams = [
19756
- "utm_source",
19757
- "utm_medium",
19758
- "utm_campaign",
19759
- "utm_content",
19760
- "utm_term",
19761
- "fbclid",
19762
- "gclid",
19763
- "gbraid",
19764
- "wbraid",
19765
- "ref",
19766
- "source",
19767
- "mc_cid",
19768
- "mc_eid"
19769
- ];
19770
19808
  const relevantParams = [];
19771
19809
  searchParams.forEach((value, key) => {
19772
- if (!ignoredParams.includes(key)) {
19773
- relevantParams.push(
19774
- `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
19775
- );
19810
+ switch (key) {
19811
+ case "utm_source":
19812
+ case "utm_medium":
19813
+ case "utm_campaign":
19814
+ case "utm_content":
19815
+ case "utm_term":
19816
+ case "fbclid":
19817
+ case "gclid":
19818
+ case "gbraid":
19819
+ case "wbraid":
19820
+ case "ref":
19821
+ case "source":
19822
+ case "mc_cid":
19823
+ case "mc_eid":
19824
+ break;
19825
+ default: {
19826
+ relevantParams.push(
19827
+ `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
19828
+ );
19829
+ break;
19830
+ }
19776
19831
  }
19777
19832
  });
19778
19833
  return relevantParams.sort().join("&");