@swell/apps-sdk 1.0.168 → 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 +123 -57
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +121 -57
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +122 -57
- package/dist/index.mjs.map +4 -4
- package/dist/src/cache/content-cache.d.ts +21 -0
- 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.js
CHANGED
|
@@ -1133,10 +1133,10 @@
|
|
|
1133
1133
|
{ content_type: { $regex: "^image/svg" } }
|
|
1134
1134
|
]
|
|
1135
1135
|
},
|
|
1136
|
-
// Do not return assets unless they end with .liquid
|
|
1136
|
+
// Do not return assets unless they end with .liquid or css/js/svg
|
|
1137
1137
|
$or: [
|
|
1138
1138
|
{ file_path: { $regex: "^(?!theme/assets/)" } },
|
|
1139
|
-
{ file_path: { $regex: ".liquid
|
|
1139
|
+
{ file_path: { $regex: ".liquid$" } },
|
|
1140
1140
|
{ file_path: { $regex: ".(css|js|svg)$" } }
|
|
1141
1141
|
]
|
|
1142
1142
|
}
|
|
@@ -7659,6 +7659,33 @@
|
|
|
7659
7659
|
}
|
|
7660
7660
|
};
|
|
7661
7661
|
|
|
7662
|
+
// src/cache/content-cache.ts
|
|
7663
|
+
var DEFAULT_TTL2 = 90 * 24 * 60 * 60 * 1e3;
|
|
7664
|
+
var ContentCache = class {
|
|
7665
|
+
cache;
|
|
7666
|
+
defaultTtl;
|
|
7667
|
+
constructor(options) {
|
|
7668
|
+
const { defaultTtl, ...cacheOptions } = options || {};
|
|
7669
|
+
this.defaultTtl = defaultTtl ?? DEFAULT_TTL2;
|
|
7670
|
+
this.cache = new Cache({
|
|
7671
|
+
ttl: this.defaultTtl,
|
|
7672
|
+
...cacheOptions
|
|
7673
|
+
});
|
|
7674
|
+
}
|
|
7675
|
+
/**
|
|
7676
|
+
* Get content from cache
|
|
7677
|
+
*/
|
|
7678
|
+
async get(key) {
|
|
7679
|
+
return this.cache.get(key);
|
|
7680
|
+
}
|
|
7681
|
+
/**
|
|
7682
|
+
* Set content in cache
|
|
7683
|
+
*/
|
|
7684
|
+
async set(key, value, ttl) {
|
|
7685
|
+
await this.cache.set(key, value, ttl ?? this.defaultTtl);
|
|
7686
|
+
}
|
|
7687
|
+
};
|
|
7688
|
+
|
|
7662
7689
|
// src/resources/addresses.ts
|
|
7663
7690
|
var SwellAddresses = class extends SwellStorefrontCollection {
|
|
7664
7691
|
constructor(swell, query) {
|
|
@@ -18581,7 +18608,9 @@ ${injects.join("\n")}<\/script>`;
|
|
|
18581
18608
|
scope[filepath] = yield (0, import_liquidjs25.evalToken)(this.withVar, ctx);
|
|
18582
18609
|
}
|
|
18583
18610
|
ctx.push(ctx.opts.jekyllInclude ? { include: scope } : scope);
|
|
18584
|
-
const output = yield liquidSwell.getComponentPath(filepath).then((path) => liquidSwell.getThemeConfig(path)).then(
|
|
18611
|
+
const output = yield liquidSwell.getComponentPath(filepath).then((path) => liquidSwell.getThemeConfig(path)).then(
|
|
18612
|
+
(themeConfig) => liquidSwell.renderTemplate(themeConfig, ctx.getAll())
|
|
18613
|
+
);
|
|
18585
18614
|
emitter.write(output);
|
|
18586
18615
|
ctx.pop();
|
|
18587
18616
|
ctx.restoreRegister(saved);
|
|
@@ -18675,7 +18704,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
18675
18704
|
};
|
|
18676
18705
|
function bindTags(liquidSwell) {
|
|
18677
18706
|
Object.entries(tags).forEach(
|
|
18678
|
-
([tag,
|
|
18707
|
+
([tag, bind65]) => liquidSwell.registerTag(tag, bind65(liquidSwell))
|
|
18679
18708
|
);
|
|
18680
18709
|
}
|
|
18681
18710
|
|
|
@@ -18837,7 +18866,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
18837
18866
|
}
|
|
18838
18867
|
}
|
|
18839
18868
|
function isCustomDateFormat(format) {
|
|
18840
|
-
return format.includes("%");
|
|
18869
|
+
return Boolean(format) && format.includes("%");
|
|
18841
18870
|
}
|
|
18842
18871
|
function applyStrftimeFormat(format, date) {
|
|
18843
18872
|
return (0, import_strftime.default)(format, date);
|
|
@@ -19372,6 +19401,38 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19372
19401
|
};
|
|
19373
19402
|
}
|
|
19374
19403
|
|
|
19404
|
+
// src/liquid/filters/shopify/img_url.ts
|
|
19405
|
+
function bind58(_liquidSwell) {
|
|
19406
|
+
return function filterImgUrl(input, ...params) {
|
|
19407
|
+
if (!input) return "";
|
|
19408
|
+
let url;
|
|
19409
|
+
if (typeof input === "object") {
|
|
19410
|
+
if (input.url) {
|
|
19411
|
+
url = input.url;
|
|
19412
|
+
} else {
|
|
19413
|
+
return "";
|
|
19414
|
+
}
|
|
19415
|
+
} else {
|
|
19416
|
+
url = String(input);
|
|
19417
|
+
}
|
|
19418
|
+
const query = [];
|
|
19419
|
+
params.forEach((param) => {
|
|
19420
|
+
if (!param) {
|
|
19421
|
+
return;
|
|
19422
|
+
}
|
|
19423
|
+
const [key, value] = param.includes(":") ? param.split(":").map((s) => s.trim()) : [param, void 0];
|
|
19424
|
+
if (/^w\d+$/.test(key)) {
|
|
19425
|
+
query.push(`width=${key.slice(1)}`);
|
|
19426
|
+
} else if (/^h\d+$/.test(key)) {
|
|
19427
|
+
query.push(`height=${key.slice(1)}`);
|
|
19428
|
+
} else if (key === "crop" && value) {
|
|
19429
|
+
query.push(`crop=${encodeURIComponent(value)}`);
|
|
19430
|
+
}
|
|
19431
|
+
});
|
|
19432
|
+
return query.length ? `${url}?${query.join("&")}` : url;
|
|
19433
|
+
};
|
|
19434
|
+
}
|
|
19435
|
+
|
|
19375
19436
|
// src/liquid/filters/shopify/item_count_for_variant.ts
|
|
19376
19437
|
var item_count_for_variant_default = {
|
|
19377
19438
|
bind(_liquidSwell) {
|
|
@@ -19386,14 +19447,14 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19386
19447
|
};
|
|
19387
19448
|
|
|
19388
19449
|
// src/liquid/filters/shopify/payment_button.ts
|
|
19389
|
-
function
|
|
19450
|
+
function bind59(_liquidSwell) {
|
|
19390
19451
|
return (form) => {
|
|
19391
19452
|
return null;
|
|
19392
19453
|
};
|
|
19393
19454
|
}
|
|
19394
19455
|
|
|
19395
19456
|
// src/liquid/filters/shopify/payment_terms.ts
|
|
19396
|
-
function
|
|
19457
|
+
function bind60(_liquidSwell) {
|
|
19397
19458
|
return (form) => {
|
|
19398
19459
|
return null;
|
|
19399
19460
|
};
|
|
@@ -19495,7 +19556,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19495
19556
|
var placeholder_svgs_default = svgs;
|
|
19496
19557
|
|
|
19497
19558
|
// src/liquid/filters/shopify/placeholder_svg_tag.ts
|
|
19498
|
-
function
|
|
19559
|
+
function bind61(_liquidSwell) {
|
|
19499
19560
|
return function filterPlaceholderSvgTag(name, className) {
|
|
19500
19561
|
const svg = placeholder_svgs_default[name];
|
|
19501
19562
|
if (typeof svg === "object" && svg !== null) {
|
|
@@ -19506,7 +19567,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19506
19567
|
}
|
|
19507
19568
|
|
|
19508
19569
|
// src/liquid/filters/shopify/shopify_asset_url.ts
|
|
19509
|
-
function
|
|
19570
|
+
function bind62(_liquidSwell) {
|
|
19510
19571
|
return function filterShopifyAssetUrl(input) {
|
|
19511
19572
|
if (typeof input === "string") {
|
|
19512
19573
|
switch (input) {
|
|
@@ -19531,7 +19592,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19531
19592
|
}
|
|
19532
19593
|
|
|
19533
19594
|
// src/liquid/filters/shopify/structured_data.ts
|
|
19534
|
-
function
|
|
19595
|
+
function bind63(_liquidSwell) {
|
|
19535
19596
|
return async function filterStructuredData(input) {
|
|
19536
19597
|
let value = input;
|
|
19537
19598
|
if (value instanceof StorefrontResource) {
|
|
@@ -19609,7 +19670,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19609
19670
|
}
|
|
19610
19671
|
|
|
19611
19672
|
// src/liquid/filters/inline_editable.ts
|
|
19612
|
-
function
|
|
19673
|
+
function bind64(_liquidSwell) {
|
|
19613
19674
|
return (value, key) => {
|
|
19614
19675
|
if (typeof value === "object" && "value" in value) {
|
|
19615
19676
|
value = value.value;
|
|
@@ -19667,14 +19728,15 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19667
19728
|
// Shopify compatibility only
|
|
19668
19729
|
asset_img_url: bind56,
|
|
19669
19730
|
hex_to_rgba: bind57,
|
|
19731
|
+
img_url: bind58,
|
|
19670
19732
|
item_count_for_variant: item_count_for_variant_default,
|
|
19671
|
-
payment_button:
|
|
19672
|
-
payment_terms:
|
|
19673
|
-
placeholder_svg_tag:
|
|
19674
|
-
shopify_asset_url:
|
|
19675
|
-
structured_data:
|
|
19733
|
+
payment_button: bind59,
|
|
19734
|
+
payment_terms: bind60,
|
|
19735
|
+
placeholder_svg_tag: bind61,
|
|
19736
|
+
shopify_asset_url: bind62,
|
|
19737
|
+
structured_data: bind63,
|
|
19676
19738
|
// Swell only
|
|
19677
|
-
inline_editable:
|
|
19739
|
+
inline_editable: bind64
|
|
19678
19740
|
};
|
|
19679
19741
|
function bindFilters(liquidSwell) {
|
|
19680
19742
|
for (const [tag, handler] of Object.entries(filters)) {
|
|
@@ -19688,8 +19750,8 @@ ${injects.join("\n")}<\/script>`;
|
|
|
19688
19750
|
}
|
|
19689
19751
|
}
|
|
19690
19752
|
}
|
|
19691
|
-
function bindWithResolvedProps(liquidSwell,
|
|
19692
|
-
const handler =
|
|
19753
|
+
function bindWithResolvedProps(liquidSwell, bind65, resolve = []) {
|
|
19754
|
+
const handler = bind65(liquidSwell);
|
|
19693
19755
|
if (!Array.isArray(resolve)) {
|
|
19694
19756
|
return handler;
|
|
19695
19757
|
}
|
|
@@ -20499,6 +20561,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
20499
20561
|
globals;
|
|
20500
20562
|
forms;
|
|
20501
20563
|
resources;
|
|
20564
|
+
dynamicAssetUrl;
|
|
20502
20565
|
liquidSwell;
|
|
20503
20566
|
themeLoader;
|
|
20504
20567
|
page;
|
|
@@ -20512,13 +20575,20 @@ ${injects.join("\n")}<\/script>`;
|
|
|
20512
20575
|
themeSettingFilePath = "theme/config/theme.json";
|
|
20513
20576
|
pageSectionGroups = null;
|
|
20514
20577
|
constructor(swell, options = {}) {
|
|
20515
|
-
const {
|
|
20578
|
+
const {
|
|
20579
|
+
forms,
|
|
20580
|
+
resources,
|
|
20581
|
+
globals,
|
|
20582
|
+
dynamicAssetUrl,
|
|
20583
|
+
shopifyCompatibilityClass
|
|
20584
|
+
} = options;
|
|
20516
20585
|
this.swell = swell;
|
|
20517
20586
|
this.props = this.getSwellAppThemeProps(swell.config);
|
|
20518
20587
|
this.shopifyCompatibilityConfig = swell.shopifyCompatibilityConfig || null;
|
|
20519
20588
|
this.globals = globals || {};
|
|
20520
20589
|
this.forms = forms;
|
|
20521
20590
|
this.resources = resources;
|
|
20591
|
+
this.dynamicAssetUrl = dynamicAssetUrl;
|
|
20522
20592
|
this.shopifyCompatibilityClass = shopifyCompatibilityClass || ShopifyCompatibility2;
|
|
20523
20593
|
this.liquidSwell = new LiquidSwell30({
|
|
20524
20594
|
theme: this,
|
|
@@ -20583,10 +20653,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
20583
20653
|
geo,
|
|
20584
20654
|
configs,
|
|
20585
20655
|
language: configs?.language,
|
|
20586
|
-
...pageRecord ? getRecordGlobals(this, pageRecord) : {
|
|
20587
|
-
page_title: page.title,
|
|
20588
|
-
page_description: page.description
|
|
20589
|
-
},
|
|
20656
|
+
...pageRecord ? getRecordGlobals(this, pageRecord) : { page_title: page.title, page_description: page.description },
|
|
20590
20657
|
all_country_option_tags: countryOptions,
|
|
20591
20658
|
country_option_tags: countryOptions,
|
|
20592
20659
|
canonical_url: `${store.url}${this.swell.url?.pathname || ""}`,
|
|
@@ -20614,13 +20681,8 @@ ${injects.join("\n")}<\/script>`;
|
|
|
20614
20681
|
if (this.shopifyCompatibility) {
|
|
20615
20682
|
this.shopifyCompatibility.adaptGlobals(globals, this.globals);
|
|
20616
20683
|
}
|
|
20617
|
-
this.globals = {
|
|
20618
|
-
|
|
20619
|
-
...globals
|
|
20620
|
-
};
|
|
20621
|
-
this.liquidSwell.options.globals = {
|
|
20622
|
-
...this.globals
|
|
20623
|
-
};
|
|
20684
|
+
this.globals = { ...this.globals, ...globals };
|
|
20685
|
+
this.liquidSwell.options.globals = { ...this.globals };
|
|
20624
20686
|
}
|
|
20625
20687
|
async getSettingsAndConfigs() {
|
|
20626
20688
|
const geo = GEO_DATA;
|
|
@@ -20872,10 +20934,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
20872
20934
|
return Object.keys(serializedFormData).length > 0 ? serializedFormData : null;
|
|
20873
20935
|
}
|
|
20874
20936
|
setGlobalData(data = {}) {
|
|
20875
|
-
this.globalData = {
|
|
20876
|
-
...this.globalData,
|
|
20877
|
-
...data
|
|
20878
|
-
};
|
|
20937
|
+
this.globalData = { ...this.globalData, ...data };
|
|
20879
20938
|
this.setGlobals(this.globalData);
|
|
20880
20939
|
}
|
|
20881
20940
|
serializeGlobalData() {
|
|
@@ -21194,11 +21253,31 @@ ${injects.join("\n")}<\/script>`;
|
|
|
21194
21253
|
async getAssetConfig(assetName) {
|
|
21195
21254
|
return await this.getThemeConfig(`theme/assets/${assetName}`) ?? await this.getThemeConfig(`assets/${assetName}`) ?? null;
|
|
21196
21255
|
}
|
|
21256
|
+
async getDynamicAssetUrl(filePath) {
|
|
21257
|
+
if (!this.dynamicAssetUrl) {
|
|
21258
|
+
return null;
|
|
21259
|
+
}
|
|
21260
|
+
const assetName = `${filePath}.liquid`;
|
|
21261
|
+
const assetConfig = await this.getAssetConfig(assetName);
|
|
21262
|
+
if (!assetConfig) {
|
|
21263
|
+
return null;
|
|
21264
|
+
}
|
|
21265
|
+
if (!this.dynamicAssetUrl.endsWith("/")) {
|
|
21266
|
+
this.dynamicAssetUrl += "/";
|
|
21267
|
+
}
|
|
21268
|
+
const settingsConfig = this._getTemplateConfigByType(
|
|
21269
|
+
"config",
|
|
21270
|
+
"settings_data",
|
|
21271
|
+
"json"
|
|
21272
|
+
);
|
|
21273
|
+
const settingsHash = settingsConfig?.hash;
|
|
21274
|
+
return settingsHash ? `${this.dynamicAssetUrl}v/${settingsHash}/${assetName}` : `${this.dynamicAssetUrl}${assetName}`;
|
|
21275
|
+
}
|
|
21197
21276
|
async getAssetUrl(filePath) {
|
|
21198
21277
|
const assetConfig = await this.getAssetConfig(filePath);
|
|
21199
21278
|
const file = assetConfig?.file;
|
|
21200
21279
|
if (!file) {
|
|
21201
|
-
return
|
|
21280
|
+
return this.getDynamicAssetUrl(filePath);
|
|
21202
21281
|
}
|
|
21203
21282
|
const fileUrl = file.url || null;
|
|
21204
21283
|
if (!fileUrl) {
|
|
@@ -21286,10 +21365,7 @@ ${injects.join("\n")}<\/script>`;
|
|
|
21286
21365
|
if (schemaStartIndex === -1 || schemaEndIndex === -1) {
|
|
21287
21366
|
return null;
|
|
21288
21367
|
}
|
|
21289
|
-
return {
|
|
21290
|
-
...config,
|
|
21291
|
-
file_data: schemaTag + schemaData + schemaEndTag
|
|
21292
|
-
};
|
|
21368
|
+
return { ...config, file_data: schemaTag + schemaData + schemaEndTag };
|
|
21293
21369
|
}
|
|
21294
21370
|
async renderThemeTemplate(filePath, data) {
|
|
21295
21371
|
const config = await this.getThemeTemplateConfig(filePath);
|
|
@@ -21465,9 +21541,7 @@ ${content.slice(pos)}`;
|
|
|
21465
21541
|
const pageSectionGroup = {
|
|
21466
21542
|
// use original pageId to return exactly the requested section id
|
|
21467
21543
|
id: originalPageId,
|
|
21468
|
-
sections: {
|
|
21469
|
-
[sectionKey]: oldSections[sectionKey]
|
|
21470
|
-
}
|
|
21544
|
+
sections: { [sectionKey]: oldSections[sectionKey] }
|
|
21471
21545
|
};
|
|
21472
21546
|
const [pageSection] = await this.renderPageSections(
|
|
21473
21547
|
pageSectionGroup,
|
|
@@ -21614,10 +21688,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
21614
21688
|
}
|
|
21615
21689
|
return {
|
|
21616
21690
|
...block,
|
|
21617
|
-
settings: {
|
|
21618
|
-
...blockDefaults,
|
|
21619
|
-
...block.settings || void 0
|
|
21620
|
-
}
|
|
21691
|
+
settings: { ...blockDefaults, ...block.settings || void 0 }
|
|
21621
21692
|
};
|
|
21622
21693
|
}
|
|
21623
21694
|
);
|
|
@@ -21754,10 +21825,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
21754
21825
|
)}</style>`;
|
|
21755
21826
|
}
|
|
21756
21827
|
}
|
|
21757
|
-
return {
|
|
21758
|
-
...sectionConfig,
|
|
21759
|
-
output
|
|
21760
|
-
};
|
|
21828
|
+
return { ...sectionConfig, output };
|
|
21761
21829
|
})
|
|
21762
21830
|
);
|
|
21763
21831
|
}
|
|
@@ -21820,10 +21888,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
21820
21888
|
return settings;
|
|
21821
21889
|
}
|
|
21822
21890
|
const editorSettings = [
|
|
21823
|
-
{
|
|
21824
|
-
label: schema.label,
|
|
21825
|
-
fields: schema.fields
|
|
21826
|
-
}
|
|
21891
|
+
{ label: schema.label, fields: schema.fields }
|
|
21827
21892
|
];
|
|
21828
21893
|
let blocks = settings.section.blocks?.filter(
|
|
21829
21894
|
(block) => block.disabled !== true
|
|
@@ -22656,7 +22721,6 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
22656
22721
|
}
|
|
22657
22722
|
generateVersionHash(headers) {
|
|
22658
22723
|
const swellData = this.extractSwellData(headers);
|
|
22659
|
-
const acceptLang = headers.get("accept-language") || "";
|
|
22660
22724
|
const versionFactors = {
|
|
22661
22725
|
store: headers.get("swell-storefront-id") || "",
|
|
22662
22726
|
app: (headers.get("swell-app-id") || "") + "@" + (headers.get("host") || ""),
|
|
@@ -22664,7 +22728,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
22664
22728
|
theme: headers.get("swell-theme-version-hash") || "",
|
|
22665
22729
|
modified: headers.get("swell-cache-modified") || "",
|
|
22666
22730
|
currency: swellData["swell-currency"] || "USD",
|
|
22667
|
-
locale: headers.get("x-locale") ||
|
|
22731
|
+
locale: headers.get("x-locale") || swellData["swell-locale"] || "en-US",
|
|
22668
22732
|
context: headers.get("swell-storefront-context"),
|
|
22669
22733
|
epoch: this.epoch
|
|
22670
22734
|
};
|