@swell/apps-sdk 1.0.129 → 1.0.132

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
@@ -7080,108 +7080,144 @@
7080
7080
  };
7081
7081
 
7082
7082
  // src/resources/product_helpers.ts
7083
- function calculateAddOptionsPrice(product, queryParams) {
7084
- const { option_values = "" } = queryParams;
7085
- const queryOptionValues = option_values;
7086
- const optionValues = queryOptionValues.split(",");
7087
- const addPrice = product.options?.reduce((acc, option) => {
7088
- if (!option.active || !option.values || option.values.length <= 0) {
7089
- return acc;
7090
- }
7091
- if (option.input_type !== "select") {
7092
- return acc;
7093
- }
7094
- for (const value of option.values) {
7095
- if (optionValues.includes(value.id)) {
7096
- return acc + (value.price || 0);
7097
- }
7098
- }
7099
- return acc + (option.values[0].price || 0);
7100
- }, 0);
7101
- return product.price + (addPrice || 0);
7102
- }
7103
- function calculateAddOptionsVariantPrice(product, variant, queryParams) {
7104
- const { option_values = "" } = queryParams;
7105
- const queryOptionValues = option_values;
7106
- const optionValues = queryOptionValues.split(",");
7107
- const addPrice = product.options?.reduce((acc, option) => {
7108
- if (option.variant || // skip variant options
7109
- !option.active || !option.values || option.values.length <= 0) {
7110
- return acc;
7111
- }
7112
- if (option.input_type !== "select") {
7113
- return acc;
7114
- }
7115
- for (const value of option.values) {
7116
- if (optionValues.includes(value.id)) {
7117
- return acc + (value.price || 0);
7118
- }
7119
- }
7120
- return acc + (option.values[0].price || 0);
7121
- }, 0);
7122
- let price = product.price;
7123
- if (variant.price !== null && variant.price !== void 0) {
7124
- price = variant.price;
7125
- }
7126
- return price + (addPrice || 0);
7127
- }
7128
7083
  function getAvailableVariants(product) {
7129
7084
  return (product.variants?.results?.slice()?.reverse() || []).filter(
7130
7085
  (variant) => variant.stock_status === "in_stock" || !variant.stock_status
7131
7086
  );
7132
7087
  }
7133
- function getSelectedSwellVariant(product, queryParams) {
7134
- const { variant: queryVariant, option_values } = queryParams;
7135
- const queryOptionValues = option_values;
7088
+ function isOptionValueAvailable(option, value, product, availableVariants) {
7089
+ if (!option.variant) {
7090
+ return true;
7091
+ }
7092
+ const hasVariants = product.variants?.results.length > 0;
7093
+ if (!hasVariants) {
7094
+ return true;
7095
+ }
7096
+ const variants = availableVariants || getAvailableVariants(product);
7097
+ return variants.some(
7098
+ (variant) => variant.option_value_ids.includes(value.id)
7099
+ );
7100
+ }
7101
+ function isOptionValueSelected(option, value, product, queryParams, selectedVariant) {
7102
+ let variant;
7103
+ if (option.variant) {
7104
+ variant = selectedVariant || getSelectedVariant(product, queryParams);
7105
+ }
7106
+ const selectedOptionValues = getSelectedVariantOptionValues(
7107
+ product,
7108
+ queryParams,
7109
+ variant
7110
+ );
7111
+ return selectedOptionValues.includes(value.id);
7112
+ }
7113
+ function getSelectedVariant(product, queryParams) {
7114
+ const {
7115
+ variant: queryVariant,
7116
+ option_values: queryOptionValues,
7117
+ selected_option_value: selectedOptionValue
7118
+ } = queryParams;
7136
7119
  const variants = getAvailableVariants(product);
7137
7120
  let selectedVariant = void 0;
7138
7121
  if (queryVariant) {
7139
7122
  selectedVariant = variants.find((variant) => variant.id === queryVariant);
7140
7123
  } else if (queryOptionValues) {
7141
7124
  const optionValues = queryOptionValues.split(",");
7142
- selectedVariant = variants.find(
7143
- (variant) => variant.option_value_ids.every(
7125
+ selectedVariant = variants.find((variant) => {
7126
+ if (variant.option_value_ids.length !== optionValues.length) {
7127
+ return false;
7128
+ }
7129
+ return variant.option_value_ids.every(
7144
7130
  (optionValueId) => optionValues.includes(optionValueId)
7145
- )
7146
- );
7131
+ );
7132
+ });
7133
+ if (!selectedVariant && selectedOptionValue) {
7134
+ selectedVariant = variants.filter(
7135
+ (variant) => variant.option_value_ids.includes(selectedOptionValue)
7136
+ )[0];
7137
+ }
7147
7138
  }
7148
7139
  return selectedVariant || variants?.[0] || void 0;
7149
7140
  }
7150
- function getSelectedVariant(product, queryParams) {
7151
- return getSelectedSwellVariant(
7141
+ function getSelectedVariantOptionValues(product, queryParams, variant) {
7142
+ if (variant) {
7143
+ return variant.option_value_ids;
7144
+ }
7145
+ const { option_values: queryOptionValues = "" } = queryParams;
7146
+ const optionValues = queryOptionValues.split(",");
7147
+ return (product.options || []).reduce((acc, option) => {
7148
+ if (!option.values) {
7149
+ return acc;
7150
+ }
7151
+ const hasOptionValues = option.values.length > 0;
7152
+ if (!option.active || !hasOptionValues) {
7153
+ return acc;
7154
+ }
7155
+ const value = option.values.find(
7156
+ (value2) => optionValues.includes(value2.id)
7157
+ );
7158
+ if (value) {
7159
+ acc.push(value.id);
7160
+ }
7161
+ return acc;
7162
+ }, []);
7163
+ }
7164
+ function getPurchaseOptions(product, queryParams) {
7165
+ if (!product?.purchase_options) {
7166
+ return null;
7167
+ }
7168
+ const { standard, subscription } = product.purchase_options;
7169
+ const selectedPurchaseOptionType = getSelectedPurchaseOptionType(
7152
7170
  product,
7153
7171
  queryParams
7154
7172
  );
7173
+ const purchaseOptions = {};
7174
+ if (standard) {
7175
+ purchaseOptions.standard = {
7176
+ ...standard,
7177
+ selected: selectedPurchaseOptionType === "standard"
7178
+ };
7179
+ }
7180
+ if (subscription) {
7181
+ const selectedPlan = getSelectedSubscriptionPurchaseOptionPlan(
7182
+ selectedPurchaseOptionType,
7183
+ subscription,
7184
+ queryParams
7185
+ );
7186
+ purchaseOptions.subscription = {
7187
+ ...subscription,
7188
+ selected: selectedPurchaseOptionType === "subscription",
7189
+ plans: subscription.plans.map((plan) => ({
7190
+ ...plan,
7191
+ selected: selectedPlan ? plan.id === selectedPlan.id : false
7192
+ }))
7193
+ };
7194
+ }
7195
+ return Object.keys(purchaseOptions).length > 0 ? purchaseOptions : null;
7155
7196
  }
7156
- function getSelectedOptionValues(product, queryParams) {
7157
- const variant = getSelectedSwellVariant(product, queryParams);
7158
- return getSelectedVariantOptionValues(product, variant, queryParams);
7197
+ function getSelectedPurchaseOptionType(product, queryParams) {
7198
+ const { purchase_options: purchaseOptions } = product;
7199
+ if (!purchaseOptions) {
7200
+ return null;
7201
+ }
7202
+ const { purchase_option: purchaseOption } = queryParams;
7203
+ const purchaseOptionType = purchaseOption?.type;
7204
+ if (purchaseOptionType && purchaseOptionType in purchaseOptions) {
7205
+ return purchaseOptionType;
7206
+ }
7207
+ return purchaseOptions.standard ? "standard" : "subscription";
7159
7208
  }
7160
- function getSelectedVariantOptionValues(product, variant, queryParams) {
7161
- const { option_values = "" } = queryParams;
7162
- const queryOptionValues = option_values;
7163
- const optionValues = queryOptionValues.split(",");
7164
- const selectedValues = variant ? [...variant.option_value_ids || []] : [];
7165
- const values = [];
7166
- for (const option of product.options || []) {
7167
- if (option.active && option.values && option.values.length > 0 && option.input_type === "select") {
7168
- let selectedByVariantId = "";
7169
- let selectedByOptionId = "";
7170
- for (const value of option.values) {
7171
- if (selectedValues.includes(value.id)) {
7172
- selectedByVariantId = value.id;
7173
- break;
7174
- }
7175
- if (optionValues.includes(value.id)) {
7176
- selectedByOptionId = value.id;
7177
- }
7178
- }
7179
- values.push(
7180
- selectedByVariantId || selectedByOptionId || option.values[0].id
7181
- );
7182
- }
7209
+ function getSelectedSubscriptionPurchaseOptionPlan(selectedPurchaseOptionType, subscriptionPurchaseOption, queryParams) {
7210
+ if (selectedPurchaseOptionType !== "subscription") {
7211
+ return null;
7183
7212
  }
7184
- return values;
7213
+ const { purchase_option: purchaseOption } = queryParams;
7214
+ let selectedPlan = null;
7215
+ if (purchaseOption?.plan_id) {
7216
+ selectedPlan = subscriptionPurchaseOption.plans.find(
7217
+ (plan) => plan.id === purchaseOption.plan_id
7218
+ );
7219
+ }
7220
+ return selectedPlan || subscriptionPurchaseOption.plans[0];
7185
7221
  }
7186
7222
 
7187
7223
  // src/resources/variant.ts
@@ -7195,11 +7231,10 @@
7195
7231
  return {
7196
7232
  ...variant,
7197
7233
  // add swell properties there
7198
- price: calculateAddOptionsVariantPrice(product, variant, params),
7199
7234
  selected_option_values: getSelectedVariantOptionValues(
7200
7235
  product,
7201
- variant,
7202
- params
7236
+ params,
7237
+ variant
7203
7238
  )
7204
7239
  };
7205
7240
  }
@@ -7212,8 +7247,8 @@
7212
7247
  const newProduct = {
7213
7248
  ...product,
7214
7249
  // add swell properties there
7215
- price: calculateAddOptionsPrice(product, params),
7216
- selected_option_values: getSelectedOptionValues(product, params)
7250
+ selected_option_values: getSelectedVariantOptionValues(product, params),
7251
+ purchase_options: getPurchaseOptions(product, params)
7217
7252
  };
7218
7253
  if (Array.isArray(newProduct.variants?.results)) {
7219
7254
  newProduct.variants = {
@@ -7570,14 +7605,10 @@
7570
7605
  }
7571
7606
  };
7572
7607
  function getCacheKey(key, args) {
7573
- let cacheKey = key;
7574
7608
  if (Array.isArray(args) && args.length > 0) {
7575
- cacheKey += `_${JSON.stringify(args)}`;
7609
+ return `${key}_${md5(JSON.stringify(args))}`;
7576
7610
  }
7577
- if (cacheKey.length > 512) {
7578
- cacheKey = `${cacheKey.slice(0, 480)}${md5(cacheKey)}`;
7579
- }
7580
- return cacheKey;
7611
+ return key;
7581
7612
  }
7582
7613
  var SwellBackendAPI = class {
7583
7614
  apiHost = DEFAULT_API_HOST;
@@ -7709,11 +7740,12 @@ ${formattedMessage}`;
7709
7740
  var import_json53 = __toESM(__require("json5"), 1);
7710
7741
  var import_lodash_es4 = __require("lodash-es");
7711
7742
  var NO_INLINE = true;
7712
- async function getEasyblocksPageTemplate(theme, pageId) {
7743
+ async function getEasyblocksPageTemplate(theme, pageId, altTemplate) {
7713
7744
  let templateConfig = null;
7714
7745
  templateConfig = await theme.getThemeTemplateConfigByType(
7715
7746
  "templates",
7716
- pageId
7747
+ pageId,
7748
+ altTemplate
7717
7749
  );
7718
7750
  if (templateConfig) {
7719
7751
  if (templateConfig.file_path.endsWith(".liquid")) {
@@ -8084,11 +8116,7 @@ ${formattedMessage}`;
8084
8116
  );
8085
8117
  }
8086
8118
  }
8087
- return list.filter((template) => {
8088
- return Object.keys(template.entry).some(
8089
- (key) => key !== "_id" && key !== "_component"
8090
- );
8091
- });
8119
+ return list;
8092
8120
  }
8093
8121
  function getEasyblocksPagePropsWithConfigs(themeGlobals, allSections, pageSections, layoutSectionGroups, pageId) {
8094
8122
  const rootComponent = {
@@ -13767,8 +13795,7 @@ ${formattedMessage}`;
13767
13795
  (blog2) => blog2.date_published || blog2.date_created
13768
13796
  ),
13769
13797
  tags: defer(() => blog.tags),
13770
- template_suffix: void 0,
13771
- // TODO
13798
+ template_suffix: defer(() => blog.theme_template),
13772
13799
  title: defer(() => blog.title),
13773
13800
  updated_at: deferWith(
13774
13801
  blog,
@@ -13837,8 +13864,7 @@ ${formattedMessage}`;
13837
13864
  // TODO
13838
13865
  tags: allTags,
13839
13866
  // TODO: this should only apply to articles in the current view
13840
- template_suffix: void 0,
13841
- // TODO
13867
+ template_suffix: defer(() => blogCategory.theme_template),
13842
13868
  title: defer(() => blogCategory.title),
13843
13869
  url: deferWith(
13844
13870
  blogCategory,
@@ -14101,29 +14127,23 @@ ${formattedMessage}`;
14101
14127
  if (!Array.isArray(product2.options)) {
14102
14128
  return {};
14103
14129
  }
14104
- let index = 0;
14130
+ const { queryParams } = instance.swell;
14131
+ const variants = getAvailableVariants(product2);
14132
+ const variant = getSelectedVariant(product2, queryParams);
14105
14133
  return product2.options.reduce(
14106
- (acc, option) => {
14107
- if (option.active && option.name) {
14108
- acc[option.name.toLowerCase()] = {
14109
- name: option.name,
14110
- position: ++index,
14111
- selected_value: void 0,
14112
- // variant_option: option.variant,
14113
- values: option.values?.map(
14114
- (value) => ShopifyProductOptionValue({
14115
- available: true,
14116
- id: value.id,
14117
- name: value.name,
14118
- product_url: void 0,
14119
- selected: false,
14120
- swatch: void 0,
14121
- variant: void 0
14122
- // addPrice: value.price,
14123
- })
14124
- ) ?? []
14125
- };
14134
+ (acc, option, index) => {
14135
+ if (!option.active || !option.name) {
14136
+ return acc;
14126
14137
  }
14138
+ acc[option.name.toLowerCase()] = getOption(
14139
+ option,
14140
+ index,
14141
+ product2,
14142
+ instance,
14143
+ depth,
14144
+ variants,
14145
+ variant
14146
+ );
14127
14147
  return acc;
14128
14148
  },
14129
14149
  {}
@@ -14135,33 +14155,20 @@ ${formattedMessage}`;
14135
14155
  if (!Array.isArray(product2.options)) {
14136
14156
  return [];
14137
14157
  }
14138
- const variant = getSelectedVariant(product2, instance.swell.queryParams);
14139
- const optionValues = variant?.option_value_ids || [];
14140
- return product2.options.filter((option) => option.active && option.name).map((option, index) => {
14141
- return {
14142
- name: option.name,
14143
- position: index + 1,
14144
- selected_value: void 0,
14145
- // variant_option: option.variant,
14146
- values: option.values?.map(
14147
- (value) => ShopifyProductOptionValue({
14148
- available: true,
14149
- id: value.id,
14150
- name: value.name,
14151
- product_url: void 0,
14152
- selected: optionValues.includes(value.id),
14153
- swatch: void 0,
14154
- variant: ShopifyVariant(
14155
- instance,
14156
- variant || product2,
14157
- product2,
14158
- depth + 1
14159
- )
14160
- // addPrice: value.price,
14161
- })
14162
- )
14163
- };
14164
- });
14158
+ const { queryParams } = instance.swell;
14159
+ const variants = getAvailableVariants(product2);
14160
+ const variant = getSelectedVariant(product2, queryParams);
14161
+ return product2.options.filter((option) => option.active && option.name).map(
14162
+ (option, index) => getOption(
14163
+ option,
14164
+ index,
14165
+ product2,
14166
+ instance,
14167
+ depth,
14168
+ variants,
14169
+ variant
14170
+ )
14171
+ );
14165
14172
  }
14166
14173
  ),
14167
14174
  price: deferWith(product, (product2) => product2.price),
@@ -14236,7 +14243,7 @@ ${formattedMessage}`;
14236
14243
  selected_variant: void 0,
14237
14244
  selling_plan_groups: [],
14238
14245
  tags: defer(() => product.tags),
14239
- template_suffix: void 0,
14246
+ template_suffix: defer(() => product.theme_template),
14240
14247
  title: defer(() => product.name),
14241
14248
  type: defer(() => product.type),
14242
14249
  url: deferWith(product, (product2) => `/products/${product2.slug}`),
@@ -14262,6 +14269,38 @@ ${formattedMessage}`;
14262
14269
  function isLikeShopifyProduct(value) {
14263
14270
  return typeof value === "object" && value !== null && Object.hasOwn(value, "variants") && Object.hasOwn(value, "gift_card?") && Object.hasOwn(value, "price_varies") && Object.hasOwn(value, "has_only_default_variant");
14264
14271
  }
14272
+ function getOption(option, index, product, instance, depth, variants, variant) {
14273
+ const { queryParams } = instance.swell;
14274
+ return {
14275
+ ...option,
14276
+ name: option.name,
14277
+ position: index + 1,
14278
+ selected_value: void 0,
14279
+ values: option.values?.map(
14280
+ (value) => ShopifyProductOptionValue({
14281
+ ...value,
14282
+ available: isOptionValueAvailable(option, value, product, variants),
14283
+ id: value.id,
14284
+ name: value.name,
14285
+ product_url: void 0,
14286
+ selected: isOptionValueSelected(
14287
+ option,
14288
+ value,
14289
+ product,
14290
+ queryParams,
14291
+ variant
14292
+ ),
14293
+ swatch: void 0,
14294
+ variant: ShopifyVariant(
14295
+ instance,
14296
+ variant || product,
14297
+ product,
14298
+ depth + 1
14299
+ )
14300
+ })
14301
+ )
14302
+ };
14303
+ }
14265
14304
 
14266
14305
  // src/compatibility/shopify-objects/line_item.ts
14267
14306
  function ShopifyLineItem(instance, item, cart, options = {}) {
@@ -14376,26 +14415,8 @@ ${formattedMessage}`;
14376
14415
  function resolveSubscription(item) {
14377
14416
  const purchaseOption = item?.purchase_option;
14378
14417
  if (purchaseOption?.type !== "subscription") {
14379
- return void 0;
14380
- }
14381
- const trialDays = purchaseOption.billing_schedule?.trial_days || 0;
14382
- const trialText = trialDays > 0 ? ` (Includes ${trialDays} trial day${trialDays === 1 ? "" : "s"})` : "";
14383
- const intervalCount = purchaseOption.billing_schedule?.interval_count || 1;
14384
- let intervalText = "day";
14385
- switch (purchaseOption.billing_schedule?.interval) {
14386
- case "weekly":
14387
- intervalText = "wk";
14388
- break;
14389
- case "monthly":
14390
- intervalText = "mo";
14391
- break;
14392
- case "yearly":
14393
- intervalText = "yr";
14394
- break;
14395
- default:
14418
+ return;
14396
14419
  }
14397
- const periodText = `${intervalCount > 1 ? intervalCount : ""}${intervalText}`;
14398
- const text = `${periodText}${trialText}`;
14399
14420
  return {
14400
14421
  checkout_charge_amount: item.price,
14401
14422
  compare_at_price: item.price,
@@ -14405,14 +14426,11 @@ ${formattedMessage}`;
14405
14426
  remaining_balance_charge_amount: 0,
14406
14427
  selling_plan_group_id: purchaseOption.plan_id,
14407
14428
  selling_plan: {
14408
- id: 0,
14429
+ id: purchaseOption.plan_id,
14409
14430
  group_id: purchaseOption.plan_id,
14410
14431
  name: purchaseOption.plan_name,
14411
14432
  description: purchaseOption.plan_description,
14412
- // billing_schedule: purchaseOption.billing_schedule,
14413
14433
  options: [],
14414
- // provide as separate parts to properly render currency
14415
- // planPriceText: text,
14416
14434
  checkout_charge: { value: item.price, value_type: "price" },
14417
14435
  recurring_deliveries: item.delivery === "shipment",
14418
14436
  price_adjustments: [],
@@ -14537,10 +14555,7 @@ ${formattedMessage}`;
14537
14555
  }),
14538
14556
  items_subtotal_price: defer(() => cart.sub_total),
14539
14557
  note: defer(() => cart.comments),
14540
- original_total_price: deferWith(
14541
- cart,
14542
- (cart2) => cart2.sub_total + cart2.item_discount
14543
- ),
14558
+ original_total_price: deferWith(cart, (cart2) => cart2.capture_total),
14544
14559
  requires_shipping: defer(() => Boolean(cart.shipment_delivery)),
14545
14560
  taxes_included: defer(() => Boolean(cart.item_tax_included)),
14546
14561
  total_discount: defer(() => cart.discount_total),
@@ -14748,7 +14763,7 @@ ${formattedMessage}`;
14748
14763
  sort_by: defer(() => category.sort),
14749
14764
  sort_options: defer(() => category.sort_options),
14750
14765
  tags: [],
14751
- template_suffix: void 0,
14766
+ template_suffix: defer(() => category.theme_template),
14752
14767
  title: defer(() => category.name),
14753
14768
  url: deferWith(category, (category2) => `/collections/${category2.slug}`)
14754
14769
  });
@@ -15549,8 +15564,7 @@ ${formattedMessage}`;
15549
15564
  page,
15550
15565
  (page2) => page2.date_published || page2.date_created
15551
15566
  ),
15552
- template_suffix: void 0,
15553
- // TODO
15567
+ template_suffix: defer(() => page.theme_template),
15554
15568
  title: deferWith(page, (page2) => page2.title || page2.name),
15555
15569
  // Due to deprecated name field
15556
15570
  url: deferWith(page, (page2) => `/pages/${page2.slug}`)
@@ -15886,17 +15900,13 @@ ${formattedMessage}`;
15886
15900
  this.queryParamsMap = this.getQueryParamsMap();
15887
15901
  }
15888
15902
  initGlobals(globals) {
15889
- const { request, page } = globals;
15890
- this.pageId = this.getPageType(globals.page?.id);
15891
- globals.page = {
15892
- ...page || void 0
15893
- };
15903
+ const { request } = globals;
15894
15904
  globals.request = {
15895
15905
  ...request || void 0,
15896
15906
  design_mode: this.swell.isEditor,
15897
15907
  visual_section_preview: false,
15898
15908
  // TODO: Add support for visual section preview
15899
- page_type: page?.id
15909
+ page_type: ""
15900
15910
  };
15901
15911
  globals.collections = new CollectionsDrop(this);
15902
15912
  globals.current_page = this.swell.queryParams.page || 1;
@@ -15905,6 +15915,8 @@ ${formattedMessage}`;
15905
15915
  adaptGlobals(globals, prevGlobals) {
15906
15916
  if (globals.page) {
15907
15917
  this.pageId = this.getPageType(globals.page.id);
15918
+ const request = globals.request || prevGlobals.request;
15919
+ request.page_type = globals.page.id;
15908
15920
  }
15909
15921
  if (globals.request) {
15910
15922
  const page = globals.page || prevGlobals.page;
@@ -18983,12 +18995,10 @@ ${injects.join("\n")}<\/script>`;
18983
18995
  getSwellAppThemeProps(swellConfig) {
18984
18996
  return swellConfig?.storefront?.theme || {};
18985
18997
  }
18986
- async initGlobals(pageId) {
18987
- this.pageId = pageId;
18998
+ async initGlobals() {
18988
18999
  await this.themeLoader.init(this.themeConfigs || void 0);
18989
19000
  const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
18990
- const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId);
18991
- this.page = page;
19001
+ const { settings, request, cart, account, customer } = await this.resolvePageData(store, configs);
18992
19002
  const globals = {
18993
19003
  ...this.globalData,
18994
19004
  store,
@@ -18996,7 +19006,7 @@ ${injects.join("\n")}<\/script>`;
18996
19006
  session,
18997
19007
  request,
18998
19008
  menus,
18999
- page,
19009
+ page: {},
19000
19010
  cart,
19001
19011
  account,
19002
19012
  customer,
@@ -19027,6 +19037,45 @@ ${injects.join("\n")}<\/script>`;
19027
19037
  ...this.globals
19028
19038
  };
19029
19039
  }
19040
+ async initPageGlobals(pageId, altTemplate) {
19041
+ this.pageId = pageId;
19042
+ const swellPage = this.props.pages?.find(
19043
+ (page2) => page2.id === pageId
19044
+ );
19045
+ const page = {
19046
+ ...swellPage,
19047
+ current: Number(this.swell.queryParams.page) || 1,
19048
+ url: this.swell.url.pathname,
19049
+ custom: !swellPage,
19050
+ slug: void 0,
19051
+ description: void 0,
19052
+ $locale: void 0
19053
+ };
19054
+ if (pageId) {
19055
+ const templateConfig = await this.getThemeTemplateConfigByType(
19056
+ "templates",
19057
+ pageId,
19058
+ altTemplate
19059
+ );
19060
+ let pageSchema;
19061
+ try {
19062
+ pageSchema = import_json56.default.parse(
19063
+ templateConfig?.file_data || "{}"
19064
+ );
19065
+ } catch (err) {
19066
+ console.warn(err);
19067
+ }
19068
+ if (pageSchema?.page) {
19069
+ const { slug, label, description, $locale } = pageSchema.page;
19070
+ page.slug = slug;
19071
+ page.label = label || page.label;
19072
+ page.description = description;
19073
+ page.$locale = $locale;
19074
+ }
19075
+ }
19076
+ this.page = page;
19077
+ this.setGlobals({ page });
19078
+ }
19030
19079
  async getSettingsAndConfigs() {
19031
19080
  const geo = GEO_DATA;
19032
19081
  const [storefrontSettings, settingConfigs] = await Promise.all([
@@ -19076,7 +19125,7 @@ ${injects.join("\n")}<\/script>`;
19076
19125
  configs
19077
19126
  };
19078
19127
  }
19079
- async resolvePageData(store, configs, pageId) {
19128
+ async resolvePageData(store, configs) {
19080
19129
  const configVersion = String(
19081
19130
  this.swell.swellHeaders["theme-config-version"]
19082
19131
  );
@@ -19108,39 +19157,6 @@ ${injects.join("\n")}<\/script>`;
19108
19157
  is_editor: this.swell.isEditor,
19109
19158
  is_preview: this.swell.isPreview
19110
19159
  };
19111
- const swellPage = this.props.pages?.find(
19112
- (page2) => page2.id === pageId
19113
- );
19114
- const page = {
19115
- ...swellPage,
19116
- current: Number(this.swell.queryParams.page) || 1,
19117
- url: this.swell.url.pathname,
19118
- custom: !swellPage,
19119
- slug: void 0,
19120
- description: void 0,
19121
- $locale: void 0
19122
- };
19123
- if (pageId) {
19124
- const templateConfig = await this.getThemeTemplateConfigByType(
19125
- "templates",
19126
- pageId
19127
- );
19128
- let pageSchema;
19129
- try {
19130
- pageSchema = import_json56.default.parse(
19131
- templateConfig?.file_data || "{}"
19132
- );
19133
- } catch (err) {
19134
- console.warn(err);
19135
- }
19136
- if (pageSchema?.page) {
19137
- const { slug, label, description, $locale } = pageSchema.page;
19138
- page.slug = slug;
19139
- page.label = label || page.label;
19140
- page.description = description;
19141
- page.$locale = $locale;
19142
- }
19143
- }
19144
19160
  const [cart, account] = await Promise.all([
19145
19161
  this.fetchSingletonResourceCached(
19146
19162
  "cart",
@@ -19163,7 +19179,6 @@ ${injects.join("\n")}<\/script>`;
19163
19179
  return {
19164
19180
  settings,
19165
19181
  request,
19166
- page,
19167
19182
  cart,
19168
19183
  account,
19169
19184
  customer
@@ -19523,15 +19538,15 @@ ${injects.join("\n")}<\/script>`;
19523
19538
  async preloadThemeConfigs(version, configs) {
19524
19539
  await this.themeLoader.preloadTheme(version, configs);
19525
19540
  }
19526
- getPageConfigPath(pageId) {
19541
+ getPageConfigPath(pageId, altTemplate) {
19527
19542
  if (this.shopifyCompatibility) {
19528
19543
  const configPath = this.shopifyCompatibility.getThemeFilePath(
19529
19544
  "templates",
19530
19545
  pageId
19531
19546
  );
19532
- return `theme/${configPath}.json`;
19547
+ return `${withSuffix(`theme/${configPath}`, altTemplate)}.json`;
19533
19548
  }
19534
- return `theme/templates/${pageId}.json`;
19549
+ return `${withSuffix(`theme/templates/${pageId}`, altTemplate)}.json`;
19535
19550
  }
19536
19551
  async getThemeConfig(filePath) {
19537
19552
  if (this.themeConfigs !== null) {
@@ -19560,12 +19575,11 @@ ${injects.join("\n")}<\/script>`;
19560
19575
  }
19561
19576
  return this.getThemeConfig(`${filePath}.liquid`);
19562
19577
  }
19563
- async getThemeTemplateConfigByType(type, name) {
19564
- const templatesByPriority = [`${type}/${name}`];
19578
+ async getThemeTemplateConfigByType(type, name, suffix) {
19579
+ const templatesByPriority = [withSuffix(`${type}/${name}`, suffix)];
19565
19580
  if (this.shopifyCompatibility) {
19566
- templatesByPriority.push(
19567
- this.shopifyCompatibility.getThemeFilePath(type, name)
19568
- );
19581
+ const path = this.shopifyCompatibility.getThemeFilePath(type, name);
19582
+ templatesByPriority.push(withSuffix(path, suffix));
19569
19583
  }
19570
19584
  for (const filePath of templatesByPriority) {
19571
19585
  const templateConfig = await this.getThemeTemplateConfig(
@@ -19734,7 +19748,8 @@ ${content.slice(pos)}`;
19734
19748
  if (altTemplateId) {
19735
19749
  templateConfig = await this.getThemeTemplateConfigByType(
19736
19750
  "templates",
19737
- `${name}.${altTemplateId}`
19751
+ name,
19752
+ altTemplateId
19738
19753
  );
19739
19754
  }
19740
19755
  if (!templateConfig) {
@@ -20031,10 +20046,11 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
20031
20046
  /**
20032
20047
  * Get a list of sections and section groups in a page layout.
20033
20048
  */
20034
- async getPageSectionGroups(pageId) {
20049
+ async getPageSectionGroups(pageId, altTemplate) {
20035
20050
  const pageConfig = await this.getThemeTemplateConfigByType(
20036
20051
  "templates",
20037
- pageId
20052
+ pageId,
20053
+ altTemplate
20038
20054
  );
20039
20055
  if (pageConfig === null) {
20040
20056
  return [];
@@ -20351,6 +20367,9 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
20351
20367
  }
20352
20368
  return list[0];
20353
20369
  }
20370
+ function withSuffix(path, suffix) {
20371
+ return suffix ? `${path}.${suffix}` : path;
20372
+ }
20354
20373
 
20355
20374
  // src/menus.ts
20356
20375
  async function resolveMenuSettings(theme, menus, options) {