@swell/apps-sdk 1.0.167 → 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.cjs +170 -96
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +168 -96
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +169 -96
- package/dist/index.mjs.map +4 -4
- package/dist/src/cache/content-cache.d.ts +21 -0
- package/dist/src/cache/html-cache/html-cache.d.ts +9 -1
- package/dist/src/cache/index.d.ts +2 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/liquid/filters/index.d.ts +2 -0
- package/dist/src/liquid/filters/shopify/img_url.d.ts +3 -0
- package/dist/src/theme.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
CartResource: () => CartResource,
|
|
43
43
|
CategoriesResource: () => CategoriesResource,
|
|
44
44
|
CategoryResource: () => CategoryResource,
|
|
45
|
+
ContentCache: () => ContentCache,
|
|
45
46
|
DEFAULT_CACHE_RULES: () => DEFAULT_CACHE_RULES,
|
|
46
47
|
DEFAULT_QUERY_PAGE_LIMIT: () => DEFAULT_QUERY_PAGE_LIMIT,
|
|
47
48
|
DeferredShopifyResource: () => DeferredShopifyResource,
|
|
@@ -1254,10 +1255,10 @@ var FILE_DATA_INCLUDE_QUERY = {
|
|
|
1254
1255
|
{ content_type: { $regex: "^image/svg" } }
|
|
1255
1256
|
]
|
|
1256
1257
|
},
|
|
1257
|
-
// Do not return assets unless they end with .liquid
|
|
1258
|
+
// Do not return assets unless they end with .liquid or css/js/svg
|
|
1258
1259
|
$or: [
|
|
1259
1260
|
{ file_path: { $regex: "^(?!theme/assets/)" } },
|
|
1260
|
-
{ file_path: { $regex: ".liquid
|
|
1261
|
+
{ file_path: { $regex: ".liquid$" } },
|
|
1261
1262
|
{ file_path: { $regex: ".(css|js|svg)$" } }
|
|
1262
1263
|
]
|
|
1263
1264
|
}
|
|
@@ -7780,6 +7781,33 @@ var ThemeFileCache = class {
|
|
|
7780
7781
|
}
|
|
7781
7782
|
};
|
|
7782
7783
|
|
|
7784
|
+
// src/cache/content-cache.ts
|
|
7785
|
+
var DEFAULT_TTL2 = 90 * 24 * 60 * 60 * 1e3;
|
|
7786
|
+
var ContentCache = class {
|
|
7787
|
+
cache;
|
|
7788
|
+
defaultTtl;
|
|
7789
|
+
constructor(options) {
|
|
7790
|
+
const { defaultTtl, ...cacheOptions } = options || {};
|
|
7791
|
+
this.defaultTtl = defaultTtl ?? DEFAULT_TTL2;
|
|
7792
|
+
this.cache = new Cache({
|
|
7793
|
+
ttl: this.defaultTtl,
|
|
7794
|
+
...cacheOptions
|
|
7795
|
+
});
|
|
7796
|
+
}
|
|
7797
|
+
/**
|
|
7798
|
+
* Get content from cache
|
|
7799
|
+
*/
|
|
7800
|
+
async get(key) {
|
|
7801
|
+
return this.cache.get(key);
|
|
7802
|
+
}
|
|
7803
|
+
/**
|
|
7804
|
+
* Set content in cache
|
|
7805
|
+
*/
|
|
7806
|
+
async set(key, value, ttl) {
|
|
7807
|
+
await this.cache.set(key, value, ttl ?? this.defaultTtl);
|
|
7808
|
+
}
|
|
7809
|
+
};
|
|
7810
|
+
|
|
7783
7811
|
// src/resources/addresses.ts
|
|
7784
7812
|
var SwellAddresses = class extends SwellStorefrontCollection {
|
|
7785
7813
|
constructor(swell, query) {
|
|
@@ -14916,10 +14944,10 @@ function ShopifyArticle(instance, blog, blogCategory) {
|
|
|
14916
14944
|
blog,
|
|
14917
14945
|
(blog2) => blog2.date_updated || blog2.date_created
|
|
14918
14946
|
),
|
|
14919
|
-
url: deferWith(
|
|
14920
|
-
|
|
14921
|
-
|
|
14922
|
-
),
|
|
14947
|
+
url: deferWith([blog, blog.category], (blog2, blogCategory2) => {
|
|
14948
|
+
const blogCategoryId = blogCategory2?.slug || blogCategory2?.id || blog2.category_id;
|
|
14949
|
+
return blogCategoryId ? `/blogs/${blogCategoryId}/${blog2.slug}` : "";
|
|
14950
|
+
}),
|
|
14923
14951
|
user: defer(() => blog.author),
|
|
14924
14952
|
// Comments not supported
|
|
14925
14953
|
comment_post_url: "",
|
|
@@ -18702,7 +18730,9 @@ function bind15(liquidSwell) {
|
|
|
18702
18730
|
scope[filepath] = yield (0, import_liquidjs25.evalToken)(this.withVar, ctx);
|
|
18703
18731
|
}
|
|
18704
18732
|
ctx.push(ctx.opts.jekyllInclude ? { include: scope } : scope);
|
|
18705
|
-
const output = yield liquidSwell.getComponentPath(filepath).then((path) => liquidSwell.getThemeConfig(path)).then(
|
|
18733
|
+
const output = yield liquidSwell.getComponentPath(filepath).then((path) => liquidSwell.getThemeConfig(path)).then(
|
|
18734
|
+
(themeConfig) => liquidSwell.renderTemplate(themeConfig, ctx.getAll())
|
|
18735
|
+
);
|
|
18706
18736
|
emitter.write(output);
|
|
18707
18737
|
ctx.pop();
|
|
18708
18738
|
ctx.restoreRegister(saved);
|
|
@@ -18796,7 +18826,7 @@ var tags = {
|
|
|
18796
18826
|
};
|
|
18797
18827
|
function bindTags(liquidSwell) {
|
|
18798
18828
|
Object.entries(tags).forEach(
|
|
18799
|
-
([tag,
|
|
18829
|
+
([tag, bind65]) => liquidSwell.registerTag(tag, bind65(liquidSwell))
|
|
18800
18830
|
);
|
|
18801
18831
|
}
|
|
18802
18832
|
|
|
@@ -18958,7 +18988,7 @@ function applyDateFormat(type, date) {
|
|
|
18958
18988
|
}
|
|
18959
18989
|
}
|
|
18960
18990
|
function isCustomDateFormat(format) {
|
|
18961
|
-
return format.includes("%");
|
|
18991
|
+
return Boolean(format) && format.includes("%");
|
|
18962
18992
|
}
|
|
18963
18993
|
function applyStrftimeFormat(format, date) {
|
|
18964
18994
|
return (0, import_strftime.default)(format, date);
|
|
@@ -19493,6 +19523,38 @@ function bind57(_liquidSwell) {
|
|
|
19493
19523
|
};
|
|
19494
19524
|
}
|
|
19495
19525
|
|
|
19526
|
+
// src/liquid/filters/shopify/img_url.ts
|
|
19527
|
+
function bind58(_liquidSwell) {
|
|
19528
|
+
return function filterImgUrl(input, ...params) {
|
|
19529
|
+
if (!input) return "";
|
|
19530
|
+
let url;
|
|
19531
|
+
if (typeof input === "object") {
|
|
19532
|
+
if (input.url) {
|
|
19533
|
+
url = input.url;
|
|
19534
|
+
} else {
|
|
19535
|
+
return "";
|
|
19536
|
+
}
|
|
19537
|
+
} else {
|
|
19538
|
+
url = String(input);
|
|
19539
|
+
}
|
|
19540
|
+
const query = [];
|
|
19541
|
+
params.forEach((param) => {
|
|
19542
|
+
if (!param) {
|
|
19543
|
+
return;
|
|
19544
|
+
}
|
|
19545
|
+
const [key, value] = param.includes(":") ? param.split(":").map((s) => s.trim()) : [param, void 0];
|
|
19546
|
+
if (/^w\d+$/.test(key)) {
|
|
19547
|
+
query.push(`width=${key.slice(1)}`);
|
|
19548
|
+
} else if (/^h\d+$/.test(key)) {
|
|
19549
|
+
query.push(`height=${key.slice(1)}`);
|
|
19550
|
+
} else if (key === "crop" && value) {
|
|
19551
|
+
query.push(`crop=${encodeURIComponent(value)}`);
|
|
19552
|
+
}
|
|
19553
|
+
});
|
|
19554
|
+
return query.length ? `${url}?${query.join("&")}` : url;
|
|
19555
|
+
};
|
|
19556
|
+
}
|
|
19557
|
+
|
|
19496
19558
|
// src/liquid/filters/shopify/item_count_for_variant.ts
|
|
19497
19559
|
var item_count_for_variant_default = {
|
|
19498
19560
|
bind(_liquidSwell) {
|
|
@@ -19507,14 +19569,14 @@ var item_count_for_variant_default = {
|
|
|
19507
19569
|
};
|
|
19508
19570
|
|
|
19509
19571
|
// src/liquid/filters/shopify/payment_button.ts
|
|
19510
|
-
function
|
|
19572
|
+
function bind59(_liquidSwell) {
|
|
19511
19573
|
return (form) => {
|
|
19512
19574
|
return null;
|
|
19513
19575
|
};
|
|
19514
19576
|
}
|
|
19515
19577
|
|
|
19516
19578
|
// src/liquid/filters/shopify/payment_terms.ts
|
|
19517
|
-
function
|
|
19579
|
+
function bind60(_liquidSwell) {
|
|
19518
19580
|
return (form) => {
|
|
19519
19581
|
return null;
|
|
19520
19582
|
};
|
|
@@ -19616,7 +19678,7 @@ var svgs = {
|
|
|
19616
19678
|
var placeholder_svgs_default = svgs;
|
|
19617
19679
|
|
|
19618
19680
|
// src/liquid/filters/shopify/placeholder_svg_tag.ts
|
|
19619
|
-
function
|
|
19681
|
+
function bind61(_liquidSwell) {
|
|
19620
19682
|
return function filterPlaceholderSvgTag(name, className) {
|
|
19621
19683
|
const svg = placeholder_svgs_default[name];
|
|
19622
19684
|
if (typeof svg === "object" && svg !== null) {
|
|
@@ -19627,7 +19689,7 @@ function bind60(_liquidSwell) {
|
|
|
19627
19689
|
}
|
|
19628
19690
|
|
|
19629
19691
|
// src/liquid/filters/shopify/shopify_asset_url.ts
|
|
19630
|
-
function
|
|
19692
|
+
function bind62(_liquidSwell) {
|
|
19631
19693
|
return function filterShopifyAssetUrl(input) {
|
|
19632
19694
|
if (typeof input === "string") {
|
|
19633
19695
|
switch (input) {
|
|
@@ -19652,7 +19714,7 @@ function bind61(_liquidSwell) {
|
|
|
19652
19714
|
}
|
|
19653
19715
|
|
|
19654
19716
|
// src/liquid/filters/shopify/structured_data.ts
|
|
19655
|
-
function
|
|
19717
|
+
function bind63(_liquidSwell) {
|
|
19656
19718
|
return async function filterStructuredData(input) {
|
|
19657
19719
|
let value = input;
|
|
19658
19720
|
if (value instanceof StorefrontResource) {
|
|
@@ -19730,7 +19792,7 @@ function convertToSchemaOrgProductGroup(product) {
|
|
|
19730
19792
|
}
|
|
19731
19793
|
|
|
19732
19794
|
// src/liquid/filters/inline_editable.ts
|
|
19733
|
-
function
|
|
19795
|
+
function bind64(_liquidSwell) {
|
|
19734
19796
|
return (value, key) => {
|
|
19735
19797
|
if (typeof value === "object" && "value" in value) {
|
|
19736
19798
|
value = value.value;
|
|
@@ -19788,14 +19850,15 @@ var filters = {
|
|
|
19788
19850
|
// Shopify compatibility only
|
|
19789
19851
|
asset_img_url: bind56,
|
|
19790
19852
|
hex_to_rgba: bind57,
|
|
19853
|
+
img_url: bind58,
|
|
19791
19854
|
item_count_for_variant: item_count_for_variant_default,
|
|
19792
|
-
payment_button:
|
|
19793
|
-
payment_terms:
|
|
19794
|
-
placeholder_svg_tag:
|
|
19795
|
-
shopify_asset_url:
|
|
19796
|
-
structured_data:
|
|
19855
|
+
payment_button: bind59,
|
|
19856
|
+
payment_terms: bind60,
|
|
19857
|
+
placeholder_svg_tag: bind61,
|
|
19858
|
+
shopify_asset_url: bind62,
|
|
19859
|
+
structured_data: bind63,
|
|
19797
19860
|
// Swell only
|
|
19798
|
-
inline_editable:
|
|
19861
|
+
inline_editable: bind64
|
|
19799
19862
|
};
|
|
19800
19863
|
function bindFilters(liquidSwell) {
|
|
19801
19864
|
for (const [tag, handler] of Object.entries(filters)) {
|
|
@@ -19809,8 +19872,8 @@ function bindFilters(liquidSwell) {
|
|
|
19809
19872
|
}
|
|
19810
19873
|
}
|
|
19811
19874
|
}
|
|
19812
|
-
function bindWithResolvedProps(liquidSwell,
|
|
19813
|
-
const handler =
|
|
19875
|
+
function bindWithResolvedProps(liquidSwell, bind65, resolve = []) {
|
|
19876
|
+
const handler = bind65(liquidSwell);
|
|
19814
19877
|
if (!Array.isArray(resolve)) {
|
|
19815
19878
|
return handler;
|
|
19816
19879
|
}
|
|
@@ -20620,6 +20683,7 @@ var SwellTheme3 = class {
|
|
|
20620
20683
|
globals;
|
|
20621
20684
|
forms;
|
|
20622
20685
|
resources;
|
|
20686
|
+
dynamicAssetUrl;
|
|
20623
20687
|
liquidSwell;
|
|
20624
20688
|
themeLoader;
|
|
20625
20689
|
page;
|
|
@@ -20633,13 +20697,20 @@ var SwellTheme3 = class {
|
|
|
20633
20697
|
themeSettingFilePath = "theme/config/theme.json";
|
|
20634
20698
|
pageSectionGroups = null;
|
|
20635
20699
|
constructor(swell, options = {}) {
|
|
20636
|
-
const {
|
|
20700
|
+
const {
|
|
20701
|
+
forms,
|
|
20702
|
+
resources,
|
|
20703
|
+
globals,
|
|
20704
|
+
dynamicAssetUrl,
|
|
20705
|
+
shopifyCompatibilityClass
|
|
20706
|
+
} = options;
|
|
20637
20707
|
this.swell = swell;
|
|
20638
20708
|
this.props = this.getSwellAppThemeProps(swell.config);
|
|
20639
20709
|
this.shopifyCompatibilityConfig = swell.shopifyCompatibilityConfig || null;
|
|
20640
20710
|
this.globals = globals || {};
|
|
20641
20711
|
this.forms = forms;
|
|
20642
20712
|
this.resources = resources;
|
|
20713
|
+
this.dynamicAssetUrl = dynamicAssetUrl;
|
|
20643
20714
|
this.shopifyCompatibilityClass = shopifyCompatibilityClass || ShopifyCompatibility2;
|
|
20644
20715
|
this.liquidSwell = new LiquidSwell30({
|
|
20645
20716
|
theme: this,
|
|
@@ -20704,10 +20775,7 @@ var SwellTheme3 = class {
|
|
|
20704
20775
|
geo,
|
|
20705
20776
|
configs,
|
|
20706
20777
|
language: configs?.language,
|
|
20707
|
-
...pageRecord ? getRecordGlobals(this, pageRecord) : {
|
|
20708
|
-
page_title: page.title,
|
|
20709
|
-
page_description: page.description
|
|
20710
|
-
},
|
|
20778
|
+
...pageRecord ? getRecordGlobals(this, pageRecord) : { page_title: page.title, page_description: page.description },
|
|
20711
20779
|
all_country_option_tags: countryOptions,
|
|
20712
20780
|
country_option_tags: countryOptions,
|
|
20713
20781
|
canonical_url: `${store.url}${this.swell.url?.pathname || ""}`,
|
|
@@ -20735,13 +20803,8 @@ var SwellTheme3 = class {
|
|
|
20735
20803
|
if (this.shopifyCompatibility) {
|
|
20736
20804
|
this.shopifyCompatibility.adaptGlobals(globals, this.globals);
|
|
20737
20805
|
}
|
|
20738
|
-
this.globals = {
|
|
20739
|
-
|
|
20740
|
-
...globals
|
|
20741
|
-
};
|
|
20742
|
-
this.liquidSwell.options.globals = {
|
|
20743
|
-
...this.globals
|
|
20744
|
-
};
|
|
20806
|
+
this.globals = { ...this.globals, ...globals };
|
|
20807
|
+
this.liquidSwell.options.globals = { ...this.globals };
|
|
20745
20808
|
}
|
|
20746
20809
|
async getSettingsAndConfigs() {
|
|
20747
20810
|
const geo = GEO_DATA;
|
|
@@ -20993,10 +21056,7 @@ var SwellTheme3 = class {
|
|
|
20993
21056
|
return Object.keys(serializedFormData).length > 0 ? serializedFormData : null;
|
|
20994
21057
|
}
|
|
20995
21058
|
setGlobalData(data = {}) {
|
|
20996
|
-
this.globalData = {
|
|
20997
|
-
...this.globalData,
|
|
20998
|
-
...data
|
|
20999
|
-
};
|
|
21059
|
+
this.globalData = { ...this.globalData, ...data };
|
|
21000
21060
|
this.setGlobals(this.globalData);
|
|
21001
21061
|
}
|
|
21002
21062
|
serializeGlobalData() {
|
|
@@ -21315,11 +21375,31 @@ var SwellTheme3 = class {
|
|
|
21315
21375
|
async getAssetConfig(assetName) {
|
|
21316
21376
|
return await this.getThemeConfig(`theme/assets/${assetName}`) ?? await this.getThemeConfig(`assets/${assetName}`) ?? null;
|
|
21317
21377
|
}
|
|
21378
|
+
async getDynamicAssetUrl(filePath) {
|
|
21379
|
+
if (!this.dynamicAssetUrl) {
|
|
21380
|
+
return null;
|
|
21381
|
+
}
|
|
21382
|
+
const assetName = `${filePath}.liquid`;
|
|
21383
|
+
const assetConfig = await this.getAssetConfig(assetName);
|
|
21384
|
+
if (!assetConfig) {
|
|
21385
|
+
return null;
|
|
21386
|
+
}
|
|
21387
|
+
if (!this.dynamicAssetUrl.endsWith("/")) {
|
|
21388
|
+
this.dynamicAssetUrl += "/";
|
|
21389
|
+
}
|
|
21390
|
+
const settingsConfig = this._getTemplateConfigByType(
|
|
21391
|
+
"config",
|
|
21392
|
+
"settings_data",
|
|
21393
|
+
"json"
|
|
21394
|
+
);
|
|
21395
|
+
const settingsHash = settingsConfig?.hash;
|
|
21396
|
+
return settingsHash ? `${this.dynamicAssetUrl}v/${settingsHash}/${assetName}` : `${this.dynamicAssetUrl}${assetName}`;
|
|
21397
|
+
}
|
|
21318
21398
|
async getAssetUrl(filePath) {
|
|
21319
21399
|
const assetConfig = await this.getAssetConfig(filePath);
|
|
21320
21400
|
const file = assetConfig?.file;
|
|
21321
21401
|
if (!file) {
|
|
21322
|
-
return
|
|
21402
|
+
return this.getDynamicAssetUrl(filePath);
|
|
21323
21403
|
}
|
|
21324
21404
|
const fileUrl = file.url || null;
|
|
21325
21405
|
if (!fileUrl) {
|
|
@@ -21407,10 +21487,7 @@ var SwellTheme3 = class {
|
|
|
21407
21487
|
if (schemaStartIndex === -1 || schemaEndIndex === -1) {
|
|
21408
21488
|
return null;
|
|
21409
21489
|
}
|
|
21410
|
-
return {
|
|
21411
|
-
...config,
|
|
21412
|
-
file_data: schemaTag + schemaData + schemaEndTag
|
|
21413
|
-
};
|
|
21490
|
+
return { ...config, file_data: schemaTag + schemaData + schemaEndTag };
|
|
21414
21491
|
}
|
|
21415
21492
|
async renderThemeTemplate(filePath, data) {
|
|
21416
21493
|
const config = await this.getThemeTemplateConfig(filePath);
|
|
@@ -21586,9 +21663,7 @@ ${content.slice(pos)}`;
|
|
|
21586
21663
|
const pageSectionGroup = {
|
|
21587
21664
|
// use original pageId to return exactly the requested section id
|
|
21588
21665
|
id: originalPageId,
|
|
21589
|
-
sections: {
|
|
21590
|
-
[sectionKey]: oldSections[sectionKey]
|
|
21591
|
-
}
|
|
21666
|
+
sections: { [sectionKey]: oldSections[sectionKey] }
|
|
21592
21667
|
};
|
|
21593
21668
|
const [pageSection] = await this.renderPageSections(
|
|
21594
21669
|
pageSectionGroup,
|
|
@@ -21735,10 +21810,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
21735
21810
|
}
|
|
21736
21811
|
return {
|
|
21737
21812
|
...block,
|
|
21738
|
-
settings: {
|
|
21739
|
-
...blockDefaults,
|
|
21740
|
-
...block.settings || void 0
|
|
21741
|
-
}
|
|
21813
|
+
settings: { ...blockDefaults, ...block.settings || void 0 }
|
|
21742
21814
|
};
|
|
21743
21815
|
}
|
|
21744
21816
|
);
|
|
@@ -21875,10 +21947,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
21875
21947
|
)}</style>`;
|
|
21876
21948
|
}
|
|
21877
21949
|
}
|
|
21878
|
-
return {
|
|
21879
|
-
...sectionConfig,
|
|
21880
|
-
output
|
|
21881
|
-
};
|
|
21950
|
+
return { ...sectionConfig, output };
|
|
21882
21951
|
})
|
|
21883
21952
|
);
|
|
21884
21953
|
}
|
|
@@ -21941,10 +22010,7 @@ function resolveSectionSettings(theme, sectionConfig, index) {
|
|
|
21941
22010
|
return settings;
|
|
21942
22011
|
}
|
|
21943
22012
|
const editorSettings = [
|
|
21944
|
-
{
|
|
21945
|
-
label: schema.label,
|
|
21946
|
-
fields: schema.fields
|
|
21947
|
-
}
|
|
22013
|
+
{ label: schema.label, fields: schema.fields }
|
|
21948
22014
|
];
|
|
21949
22015
|
let blocks = settings.section.blocks?.filter(
|
|
21950
22016
|
(block) => block.disabled !== true
|
|
@@ -22659,11 +22725,18 @@ var HtmlCache = class {
|
|
|
22659
22725
|
}
|
|
22660
22726
|
canReadFromCache(request) {
|
|
22661
22727
|
const method = request.method.toUpperCase();
|
|
22662
|
-
|
|
22728
|
+
if (!(method === "GET" || method === "HEAD")) return false;
|
|
22729
|
+
const res = this.resolvePathRule(request);
|
|
22730
|
+
if (res.skip) return false;
|
|
22731
|
+
return this.isRequestCacheable(request);
|
|
22663
22732
|
}
|
|
22664
22733
|
canWriteToCache(request, response) {
|
|
22665
22734
|
const method = request.method.toUpperCase();
|
|
22666
|
-
|
|
22735
|
+
if (method !== "GET" || !response.ok) return false;
|
|
22736
|
+
const res = this.resolvePathRule(request);
|
|
22737
|
+
if (res.skip) return false;
|
|
22738
|
+
if (!this.isRequestCacheable(request)) return false;
|
|
22739
|
+
return this.isResponseCacheable(response, res.rule);
|
|
22667
22740
|
}
|
|
22668
22741
|
createRevalidationRequest(request) {
|
|
22669
22742
|
const headers = new Headers(request.headers);
|
|
@@ -22770,7 +22843,6 @@ var HtmlCache = class {
|
|
|
22770
22843
|
}
|
|
22771
22844
|
generateVersionHash(headers) {
|
|
22772
22845
|
const swellData = this.extractSwellData(headers);
|
|
22773
|
-
const acceptLang = headers.get("accept-language") || "";
|
|
22774
22846
|
const versionFactors = {
|
|
22775
22847
|
store: headers.get("swell-storefront-id") || "",
|
|
22776
22848
|
app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
|
|
@@ -22778,7 +22850,7 @@ var HtmlCache = class {
|
|
|
22778
22850
|
theme: headers.get("swell-theme-version-hash") || "",
|
|
22779
22851
|
modified: headers.get("swell-cache-modified") || "",
|
|
22780
22852
|
currency: swellData["swell-currency"] || "USD",
|
|
22781
|
-
locale: headers.get("x-locale") ||
|
|
22853
|
+
locale: headers.get("x-locale") || swellData["swell-locale"] || "en-US",
|
|
22782
22854
|
context: headers.get("swell-storefront-context"),
|
|
22783
22855
|
epoch: this.epoch
|
|
22784
22856
|
};
|
|
@@ -22796,22 +22868,20 @@ var HtmlCache = class {
|
|
|
22796
22868
|
}
|
|
22797
22869
|
}
|
|
22798
22870
|
isRequestCacheable(request) {
|
|
22799
|
-
const url = new URL(request.url);
|
|
22800
22871
|
if (request.headers.get("swell-deployment-mode") === "editor") return false;
|
|
22801
|
-
if (this.cacheRules.pathRules) {
|
|
22802
|
-
for (const rule of this.cacheRules.pathRules) {
|
|
22803
|
-
if (this.pathMatches(rule.path, url.pathname) && rule.skip) {
|
|
22804
|
-
return false;
|
|
22805
|
-
}
|
|
22806
|
-
}
|
|
22807
|
-
}
|
|
22808
22872
|
if (request.headers.get("cache-control")?.includes("no-cache"))
|
|
22809
22873
|
return false;
|
|
22810
22874
|
return true;
|
|
22811
22875
|
}
|
|
22812
|
-
isResponseCacheable(response) {
|
|
22813
|
-
|
|
22814
|
-
|
|
22876
|
+
isResponseCacheable(response, matchedRule) {
|
|
22877
|
+
const contentType = response.headers.get("content-type") || "";
|
|
22878
|
+
const allowed = matchedRule?.contentTypes;
|
|
22879
|
+
if (Array.isArray(allowed) && allowed.length > 0) {
|
|
22880
|
+
const ok = allowed.some((ct) => contentType.toLowerCase().startsWith(ct));
|
|
22881
|
+
if (!ok) return false;
|
|
22882
|
+
} else {
|
|
22883
|
+
if (!contentType.includes("text/html")) return false;
|
|
22884
|
+
}
|
|
22815
22885
|
if (response.headers.get("set-cookie")) return false;
|
|
22816
22886
|
const cacheControl = response.headers.get("cache-control");
|
|
22817
22887
|
if (cacheControl?.includes("no-store") || cacheControl?.includes("private"))
|
|
@@ -22823,30 +22893,10 @@ var HtmlCache = class {
|
|
|
22823
22893
|
return mode === "preview" ? "preview" : "live";
|
|
22824
22894
|
}
|
|
22825
22895
|
getTTLForRequest(request) {
|
|
22826
|
-
|
|
22827
|
-
const mode = this.getDeploymentMode(request.headers);
|
|
22828
|
-
if (this.cacheRules.pathRules) {
|
|
22829
|
-
for (const rule of this.cacheRules.pathRules) {
|
|
22830
|
-
if (this.pathMatches(rule.path, url.pathname) && rule.ttl !== void 0) {
|
|
22831
|
-
return rule.ttl;
|
|
22832
|
-
}
|
|
22833
|
-
}
|
|
22834
|
-
}
|
|
22835
|
-
const defaults = this.cacheRules.defaults?.[mode];
|
|
22836
|
-
return defaults?.ttl ?? DEFAULT_CACHE_RULES.defaults[mode].ttl;
|
|
22896
|
+
return this.resolvePathRule(request).effectiveTTL;
|
|
22837
22897
|
}
|
|
22838
22898
|
getSWRForRequest(request) {
|
|
22839
|
-
|
|
22840
|
-
const mode = this.getDeploymentMode(request.headers);
|
|
22841
|
-
if (this.cacheRules.pathRules) {
|
|
22842
|
-
for (const rule of this.cacheRules.pathRules) {
|
|
22843
|
-
if (this.pathMatches(rule.path, url.pathname) && rule.swr !== void 0) {
|
|
22844
|
-
return rule.swr;
|
|
22845
|
-
}
|
|
22846
|
-
}
|
|
22847
|
-
}
|
|
22848
|
-
const defaults = this.cacheRules.defaults?.[mode];
|
|
22849
|
-
return defaults?.swr ?? DEFAULT_CACHE_RULES.defaults[mode].swr;
|
|
22899
|
+
return this.resolvePathRule(request).effectiveSWR;
|
|
22850
22900
|
}
|
|
22851
22901
|
getEntryAge(entry) {
|
|
22852
22902
|
const t = Date.parse(entry.cacheTimeISO);
|
|
@@ -22870,6 +22920,29 @@ var HtmlCache = class {
|
|
|
22870
22920
|
});
|
|
22871
22921
|
return normalized;
|
|
22872
22922
|
}
|
|
22923
|
+
resolvePathRule(request) {
|
|
22924
|
+
const url = new URL(request.url);
|
|
22925
|
+
const mode = this.getDeploymentMode(request.headers);
|
|
22926
|
+
const defaults = this.cacheRules.defaults?.[mode] ?? DEFAULT_CACHE_RULES.defaults[mode];
|
|
22927
|
+
let rule;
|
|
22928
|
+
if (this.cacheRules.pathRules) {
|
|
22929
|
+
for (const r of this.cacheRules.pathRules) {
|
|
22930
|
+
if (this.pathMatches(r.path, url.pathname)) {
|
|
22931
|
+
rule = r;
|
|
22932
|
+
break;
|
|
22933
|
+
}
|
|
22934
|
+
}
|
|
22935
|
+
}
|
|
22936
|
+
const effectiveTTL = (rule?.ttl !== void 0 ? rule.ttl : defaults?.ttl) ?? defaults.ttl;
|
|
22937
|
+
const effectiveSWR = (rule?.swr !== void 0 ? rule.swr : defaults?.swr) ?? defaults.swr;
|
|
22938
|
+
return {
|
|
22939
|
+
rule,
|
|
22940
|
+
mode,
|
|
22941
|
+
effectiveTTL,
|
|
22942
|
+
effectiveSWR,
|
|
22943
|
+
skip: Boolean(rule?.skip)
|
|
22944
|
+
};
|
|
22945
|
+
}
|
|
22873
22946
|
normalizeSearchParams(searchParams) {
|
|
22874
22947
|
const ignoredParams = [
|
|
22875
22948
|
"utm_source",
|
|
@@ -23072,6 +23145,7 @@ function getHtmlCache(env, cacheRules) {
|
|
|
23072
23145
|
CartResource,
|
|
23073
23146
|
CategoriesResource,
|
|
23074
23147
|
CategoryResource,
|
|
23148
|
+
ContentCache,
|
|
23075
23149
|
DEFAULT_CACHE_RULES,
|
|
23076
23150
|
DEFAULT_QUERY_PAGE_LIMIT,
|
|
23077
23151
|
DeferredShopifyResource,
|