@misiki/gocommerce-connector 0.10.0 → 0.12.0
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/README.md +4 -0
- package/dist/{index-mqcHZ96i.d.cts → index-Bu4bVBBm.d.cts} +460 -7
- package/dist/{index-mqcHZ96i.d.ts → index-Bu4bVBBm.d.ts} +460 -7
- package/dist/index.cjs +231 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +229 -8
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +228 -7
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +228 -7
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as
|
|
1
|
+
export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutResult, v as CheckoutService, w as CmsPage, x as Collection, y as CollectionService, z as Company, D as CompanyOrder, E as ContactService, F as CountryService, G as CouponService, H as Credentials, I as Credit, J as CurrencyService, K as Customer, L as DealService, M as DemoRequestService, N as EngineRequest, O as EnquiryService, P as Envelope, Q as FacetValue, R as Faq, S as FaqService, T as FeedbackService, U as FooterSettings, V as FreeShipping, W as Fulfillment, X as GalleryService, Y as HeaderSettings, Z as HomeLayout, _ as HomeLayoutSection, $ as HomeService, a0 as IdentityAddress, a1 as InitService, a2 as Invitation, a3 as LayoutCollection, a4 as LayoutPage, a5 as LayoutService, a6 as Lead, a7 as ListMeta, a8 as MeilisearchService, a9 as Member, aa as Menu, ab as MenuItem, ac as MenuService, ad as MenuSummary, ae as Money, af as NewsletterService, ag as Offer, ah as Order, ai as OrderLine, aj as OrderService, ak as PageLayout, al as PageService, am as PaymentIntent, an as PaymentMethodService, ao as Plugin, ap as PluginService, ap as PluginsService, aq as PopularSearchService, ar as PopularityService, as as Product, at as ProductFacets, au as ProductOption, av as ProductService, aw as ProfileService, ax as Quote, ay as REDIRECT_GATEWAYS, az as ReelsService, aA as RegionService, aB as RejectedLine, aC as Review, aD as ReviewPage, aE as ReviewService, aF as SearchDoc, aG as SearchResult, aH as SearchService, aI as SettingService, aI as SettingsService, aJ as ShippingRate, aK as SiteChrome, aL as SiteFooter, aM as SiteHeader, aN as SocialLink, aO as StateService, aP as StoreProfile, aQ as StoreService, aR as StorefrontCategory, aS as StorefrontMenu, aT as StorefrontOrder, aU as StorefrontProduct, aV as ThemeSettings, aW as ThemeSettingsResult, aX as UploadService, aY as UserService, aZ as Variant, a_ as VariantImage, a$ as VariantService, b0 as VarniCustomDesignService, b1 as VarniCustomProductService, b2 as Vendor, b3 as VendorService, b4 as WarrantyService, b5 as Wishlist, b6 as WishlistItem, b7 as WishlistService, b8 as addressService, b9 as authService, ba as autocompleteService, bb as b2bService, bc as bannerService, bd as blogService, be as cartService, bf as categoryService, bg as chatService, bh as checkoutService, bi as collectionService, bj as contactService, bk as countryService, bl as couponService, bm as currencyExponent, bn as currencyService, bo as dealService, bp as demoRequestService, bq as emptyCart, br as emptyPage, bs as enquiryService, bt as faqService, bu as feedbackService, bv as fromEngineAddress, bw as fromIdentityAddress, bx as fromSearchDoc, by as galleryService, bz as homeService, bA as initService, bB as layoutService, bC as mediaUrl, bD as meilisearchService, bE as menuService, bF as minorToMajor, bG as newsletterService, bH as orderService, bI as ownDomain, bJ as pageService, bK as paymentMethodService, bL as pluginService, bM as pluginsService, bN as popularSearchService, bO as popularityService, bP as priceOf, bQ as productImages, bR as productService, bS as profileService, bT as qs, bU as reelsService, bV as regionService, bW as reviewService, bX as searchService, bY as setRequestHost, bZ as settingService, b_ as settingsService, b$ as stateService, c0 as staticStore, c1 as storeForHost, c2 as storeService, c3 as toAddOn, c4 as toCart, c5 as toCartLine, c6 as toCartOffer, c7 as toCategory, c8 as toCmsPage, c9 as toCollection, ca as toEngineAddress, cb as toFreeShipping, cc as toIdentityAddress, cd as toMajor, ce as toMinor, cf as toOrder, cg as toPage, ch as toProduct, ci as toRating, cj as toStorefrontFacets, ck as toUser, cl as toVariant, cm as toVendor, cn as uploadService, co as userService, cp as variantService, cq as varniCustomDesignService, cr as varniCustomProductService, cs as vendorService, ct as warrantyService, cu as wishlistService } from './index-Bu4bVBBm.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The two ways a call through this connector fails.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as
|
|
1
|
+
export { A as AddOn, a as Address, b as AddressService, c as AppliedDiscount, d as Approval, e as AuthResponse, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, C as Cart, m as CartLine, n as CartOffer, o as CartService, p as CatalogService, q as Category, r as CategoryService, s as ChatService, t as CheckoutOptions, u as CheckoutResult, v as CheckoutService, w as CmsPage, x as Collection, y as CollectionService, z as Company, D as CompanyOrder, E as ContactService, F as CountryService, G as CouponService, H as Credentials, I as Credit, J as CurrencyService, K as Customer, L as DealService, M as DemoRequestService, N as EngineRequest, O as EnquiryService, P as Envelope, Q as FacetValue, R as Faq, S as FaqService, T as FeedbackService, U as FooterSettings, V as FreeShipping, W as Fulfillment, X as GalleryService, Y as HeaderSettings, Z as HomeLayout, _ as HomeLayoutSection, $ as HomeService, a0 as IdentityAddress, a1 as InitService, a2 as Invitation, a3 as LayoutCollection, a4 as LayoutPage, a5 as LayoutService, a6 as Lead, a7 as ListMeta, a8 as MeilisearchService, a9 as Member, aa as Menu, ab as MenuItem, ac as MenuService, ad as MenuSummary, ae as Money, af as NewsletterService, ag as Offer, ah as Order, ai as OrderLine, aj as OrderService, ak as PageLayout, al as PageService, am as PaymentIntent, an as PaymentMethodService, ao as Plugin, ap as PluginService, ap as PluginsService, aq as PopularSearchService, ar as PopularityService, as as Product, at as ProductFacets, au as ProductOption, av as ProductService, aw as ProfileService, ax as Quote, ay as REDIRECT_GATEWAYS, az as ReelsService, aA as RegionService, aB as RejectedLine, aC as Review, aD as ReviewPage, aE as ReviewService, aF as SearchDoc, aG as SearchResult, aH as SearchService, aI as SettingService, aI as SettingsService, aJ as ShippingRate, aK as SiteChrome, aL as SiteFooter, aM as SiteHeader, aN as SocialLink, aO as StateService, aP as StoreProfile, aQ as StoreService, aR as StorefrontCategory, aS as StorefrontMenu, aT as StorefrontOrder, aU as StorefrontProduct, aV as ThemeSettings, aW as ThemeSettingsResult, aX as UploadService, aY as UserService, aZ as Variant, a_ as VariantImage, a$ as VariantService, b0 as VarniCustomDesignService, b1 as VarniCustomProductService, b2 as Vendor, b3 as VendorService, b4 as WarrantyService, b5 as Wishlist, b6 as WishlistItem, b7 as WishlistService, b8 as addressService, b9 as authService, ba as autocompleteService, bb as b2bService, bc as bannerService, bd as blogService, be as cartService, bf as categoryService, bg as chatService, bh as checkoutService, bi as collectionService, bj as contactService, bk as countryService, bl as couponService, bm as currencyExponent, bn as currencyService, bo as dealService, bp as demoRequestService, bq as emptyCart, br as emptyPage, bs as enquiryService, bt as faqService, bu as feedbackService, bv as fromEngineAddress, bw as fromIdentityAddress, bx as fromSearchDoc, by as galleryService, bz as homeService, bA as initService, bB as layoutService, bC as mediaUrl, bD as meilisearchService, bE as menuService, bF as minorToMajor, bG as newsletterService, bH as orderService, bI as ownDomain, bJ as pageService, bK as paymentMethodService, bL as pluginService, bM as pluginsService, bN as popularSearchService, bO as popularityService, bP as priceOf, bQ as productImages, bR as productService, bS as profileService, bT as qs, bU as reelsService, bV as regionService, bW as reviewService, bX as searchService, bY as setRequestHost, bZ as settingService, b_ as settingsService, b$ as stateService, c0 as staticStore, c1 as storeForHost, c2 as storeService, c3 as toAddOn, c4 as toCart, c5 as toCartLine, c6 as toCartOffer, c7 as toCategory, c8 as toCmsPage, c9 as toCollection, ca as toEngineAddress, cb as toFreeShipping, cc as toIdentityAddress, cd as toMajor, ce as toMinor, cf as toOrder, cg as toPage, ch as toProduct, ci as toRating, cj as toStorefrontFacets, ck as toUser, cl as toVariant, cm as toVendor, cn as uploadService, co as userService, cp as variantService, cq as varniCustomDesignService, cr as varniCustomProductService, cs as vendorService, ct as warrantyService, cu as wishlistService } from './index-Bu4bVBBm.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The two ways a call through this connector fails.
|
package/dist/index.js
CHANGED
|
@@ -763,7 +763,12 @@ function toCartLine(l, extra = {}) {
|
|
|
763
763
|
variantTitle: l.variant_label ?? "",
|
|
764
764
|
qty: l.quantity,
|
|
765
765
|
price: toMajor(l.unit_price),
|
|
766
|
-
|
|
766
|
+
// The variant's compare-at price, where the shop set one above what the
|
|
767
|
+
// line costs: what the basket's "you save" is measured from.
|
|
768
|
+
mrp: l.compare_at_price && l.compare_at_price.amount_minor > l.unit_price.amount_minor ? toMajor(l.compare_at_price) : toMajor(l.unit_price),
|
|
769
|
+
/** The add-on this line was bought as (D133), or null on an ordinary line. */
|
|
770
|
+
addOnId: l.add_on_id ? str(l.add_on_id) : null,
|
|
771
|
+
addOnFor: l.add_on_for ? str(l.add_on_for) : null,
|
|
767
772
|
subtotal: toMajor(l.total),
|
|
768
773
|
total: toMajor(l.total),
|
|
769
774
|
inStock: l.in_stock,
|
|
@@ -997,6 +1002,45 @@ function toUser(c) {
|
|
|
997
1002
|
};
|
|
998
1003
|
}
|
|
999
1004
|
var priceOf = (m) => m ? toMajor(m) : 0;
|
|
1005
|
+
function toAddOn(a) {
|
|
1006
|
+
return {
|
|
1007
|
+
id: str(a.id),
|
|
1008
|
+
productId: str(a.item.product_id),
|
|
1009
|
+
variantId: str(a.variant_id),
|
|
1010
|
+
slug: a.item.slug,
|
|
1011
|
+
title: a.item.title,
|
|
1012
|
+
variantTitle: a.item.variant_label ?? "",
|
|
1013
|
+
thumbnail: mediaUrl(a.item.image_url ?? null),
|
|
1014
|
+
price: toMajor(a.offer_price ?? a.price),
|
|
1015
|
+
regularPrice: toMajor(a.price),
|
|
1016
|
+
hasOffer: !!a.offer_price && a.offer_price.amount_minor < a.price.amount_minor,
|
|
1017
|
+
inStock: a.item.in_stock
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
function toCartOffer(o, currency) {
|
|
1021
|
+
const isPercent = o.kind === "percentage";
|
|
1022
|
+
return {
|
|
1023
|
+
code: o.code,
|
|
1024
|
+
title: o.title,
|
|
1025
|
+
isPercent,
|
|
1026
|
+
freeShipping: o.kind === "free_shipping",
|
|
1027
|
+
/** The percentage for a percentage code, the amount for a fixed one. */
|
|
1028
|
+
value: isPercent ? (o.value_bp ?? 0) / 100 : minorToMajor(o.value_minor ?? 0, currency),
|
|
1029
|
+
minAmount: o.min_subtotal_minor ? minorToMajor(o.min_subtotal_minor, currency) : null,
|
|
1030
|
+
applies: o.applies,
|
|
1031
|
+
amount: o.amount ? toMajor(o.amount) : null,
|
|
1032
|
+
remaining: o.remaining ? toMajor(o.remaining) : null,
|
|
1033
|
+
reason: o.reason ?? ""
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
function toFreeShipping(f) {
|
|
1037
|
+
return {
|
|
1038
|
+
qualifies: f.qualifies,
|
|
1039
|
+
threshold: f.threshold ? toMajor(f.threshold) : null,
|
|
1040
|
+
remaining: f.remaining ? toMajor(f.remaining) : null,
|
|
1041
|
+
subtotal: toMajor(f.subtotal)
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1000
1044
|
|
|
1001
1045
|
// src/services/facts.ts
|
|
1002
1046
|
var StoreFacts = class extends BaseService {
|
|
@@ -1307,6 +1351,36 @@ var ProductService = class extends CatalogService {
|
|
|
1307
1351
|
if (!category) return this.list({ page, limit });
|
|
1308
1352
|
return this.list({ page, limit, categories: category.slug });
|
|
1309
1353
|
}
|
|
1354
|
+
/**
|
|
1355
|
+
* What the shop offers with a product, ticked in its buy box (D133): each
|
|
1356
|
+
* add-on at the price ticking it adds. Only add-ons that can be bought
|
|
1357
|
+
* arrive; an engine without the route offers none.
|
|
1358
|
+
*/
|
|
1359
|
+
async listAddOns({ product }) {
|
|
1360
|
+
const p = await this.findProduct(String(product));
|
|
1361
|
+
try {
|
|
1362
|
+
return (await this.data("/api/add-ons", { query: { product_id: p.id } }) ?? []).map(toAddOn);
|
|
1363
|
+
} catch (err) {
|
|
1364
|
+
if (err instanceof GoCommerceError && err.status === 404) return [];
|
|
1365
|
+
throw err;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* "You may also like": the products the shop chose for this one, at their
|
|
1370
|
+
* own prices (D133). Curated only, and empty when none were chosen: the
|
|
1371
|
+
* related products already fill in from the category, and the page should
|
|
1372
|
+
* not draw the same fill twice.
|
|
1373
|
+
*/
|
|
1374
|
+
async listCrossSells({ product, limit }) {
|
|
1375
|
+
const p = await this.findProduct(String(product));
|
|
1376
|
+
try {
|
|
1377
|
+
const rows = await this.data("/api/cross-sells", { query: { product_id: p.id, limit } }) ?? [];
|
|
1378
|
+
return rows.map((r) => toProduct(r));
|
|
1379
|
+
} catch (err) {
|
|
1380
|
+
if (err instanceof GoCommerceError && err.status === 404) return [];
|
|
1381
|
+
throw err;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1310
1384
|
async relatedTo(slug, limit) {
|
|
1311
1385
|
const size = Math.min(100, Math.max(1, Number(limit) || PAGE_SIZE));
|
|
1312
1386
|
const p = await this.findProduct(slug);
|
|
@@ -1646,6 +1720,88 @@ var CartService = class extends BaseService {
|
|
|
1646
1720
|
throw err;
|
|
1647
1721
|
}
|
|
1648
1722
|
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Adds an add-on from a product's "Complete the set" (D133) at its offer
|
|
1725
|
+
* price. The product it is offered with has to be in the bag already, so
|
|
1726
|
+
* this is called after adding it; the engine refuses one too many with the
|
|
1727
|
+
* sentence the shopper is shown.
|
|
1728
|
+
*/
|
|
1729
|
+
async addAddOn({ cartId, addOnId, qty = 1 }) {
|
|
1730
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1731
|
+
if (!id2) throw new GoCommerceError("Add the product to your bag first.", 409);
|
|
1732
|
+
return this.present(
|
|
1733
|
+
await this.data(`/api/carts/${encodeURIComponent(id2)}/line-items`, {
|
|
1734
|
+
method: "POST",
|
|
1735
|
+
body: { add_on_id: Number(addOnId), quantity: Number(qty) }
|
|
1736
|
+
})
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* The codes the shop chose to show (D133), each with what it takes off this
|
|
1741
|
+
* bag or how much more the bag needs. None without a bag.
|
|
1742
|
+
*/
|
|
1743
|
+
async getOffers({ cartId } = {}) {
|
|
1744
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1745
|
+
if (!id2) return [];
|
|
1746
|
+
try {
|
|
1747
|
+
const rows = await this.data(`/api/carts/${encodeURIComponent(id2)}/offers`) ?? [];
|
|
1748
|
+
const currency = await this.currency();
|
|
1749
|
+
return rows.map((o) => toCartOffer(o, o.amount?.currency ?? o.remaining?.currency ?? currency));
|
|
1750
|
+
} catch (err) {
|
|
1751
|
+
if (err instanceof GoCommerceError && err.status === 404) return [];
|
|
1752
|
+
throw err;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
/**
|
|
1756
|
+
* How far the bag is from free delivery (D133), read from the store's own
|
|
1757
|
+
* rates for the country (the store's own when none is given). Null when
|
|
1758
|
+
* the engine cannot say: a bar with a made-up figure is worse than none.
|
|
1759
|
+
*/
|
|
1760
|
+
async getFreeShipping({ cartId, country, state } = {}) {
|
|
1761
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1762
|
+
if (!id2) return null;
|
|
1763
|
+
const where = country ?? cartExtras(id2).shippingAddress?.country ?? void 0;
|
|
1764
|
+
try {
|
|
1765
|
+
return toFreeShipping(
|
|
1766
|
+
await this.data(`/api/carts/${encodeURIComponent(id2)}/free-shipping`, {
|
|
1767
|
+
query: { country: where || void 0, state: state || void 0 }
|
|
1768
|
+
})
|
|
1769
|
+
);
|
|
1770
|
+
} catch (err) {
|
|
1771
|
+
if (err instanceof GoCommerceError && err.status === 404) return null;
|
|
1772
|
+
throw err;
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* "You may be interested in" (D133): what the bag's products suggest, less
|
|
1777
|
+
* what it holds; with nothing curated, the first product's related
|
|
1778
|
+
* products, still less what it holds.
|
|
1779
|
+
*/
|
|
1780
|
+
async listCrossSells({ cartId, limit = 12 } = {}) {
|
|
1781
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1782
|
+
if (!id2) return [];
|
|
1783
|
+
let curated = [];
|
|
1784
|
+
try {
|
|
1785
|
+
curated = await this.data(`/api/carts/${encodeURIComponent(id2)}/cross-sells`, { query: { limit } }) ?? [];
|
|
1786
|
+
} catch (err) {
|
|
1787
|
+
if (!(err instanceof GoCommerceError) || err.status !== 404) throw err;
|
|
1788
|
+
}
|
|
1789
|
+
if (curated.length) return curated.map((p) => toProduct(p));
|
|
1790
|
+
let cart;
|
|
1791
|
+
try {
|
|
1792
|
+
cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
|
|
1793
|
+
} catch {
|
|
1794
|
+
return [];
|
|
1795
|
+
}
|
|
1796
|
+
const held = new Set((cart.line_items ?? []).map((l) => String(l.product_id)));
|
|
1797
|
+
const first = cart.line_items?.[0];
|
|
1798
|
+
if (!first) return [];
|
|
1799
|
+
const related = await new ProductService(this._fetch).listRelatedProducts({
|
|
1800
|
+
product: String(first.product_id),
|
|
1801
|
+
limit: limit + held.size
|
|
1802
|
+
});
|
|
1803
|
+
return related.data.filter((p) => !held.has(String(p.id))).slice(0, limit);
|
|
1804
|
+
}
|
|
1649
1805
|
/** `qty` is the new total; 0 takes the line out. */
|
|
1650
1806
|
async updateCart({
|
|
1651
1807
|
cartId,
|
|
@@ -2079,7 +2235,20 @@ var paymentMethodService = new PaymentMethodService();
|
|
|
2079
2235
|
// src/services/coupon-service.ts
|
|
2080
2236
|
var CouponService = class extends BaseService {
|
|
2081
2237
|
async listCoupons(_args = {}) {
|
|
2082
|
-
|
|
2238
|
+
const offers = await new CartService(this._fetch).getOffers().catch(() => []);
|
|
2239
|
+
if (!offers.length) return emptyPage();
|
|
2240
|
+
const data = offers.map((o) => ({
|
|
2241
|
+
id: o.code,
|
|
2242
|
+
code: o.code,
|
|
2243
|
+
title: o.title,
|
|
2244
|
+
isPercent: o.isPercent,
|
|
2245
|
+
amount: o.value,
|
|
2246
|
+
minAmount: o.minAmount,
|
|
2247
|
+
description: o.applies ? o.title : o.remaining !== null ? `${o.title}. Add ${o.remaining} more to use this.` : o.reason || o.title,
|
|
2248
|
+
applies: o.applies,
|
|
2249
|
+
remaining: o.remaining
|
|
2250
|
+
}));
|
|
2251
|
+
return { data, count: data.length, pageSize: data.length, noOfPage: 1, page: 1 };
|
|
2083
2252
|
}
|
|
2084
2253
|
};
|
|
2085
2254
|
var couponService = new CouponService();
|
|
@@ -2677,21 +2846,38 @@ var MenuService = class extends BaseService {
|
|
|
2677
2846
|
const m = await this.data(`/x/navigation/menus/${encodeURIComponent(handle)}`);
|
|
2678
2847
|
return { menuId: m.handle, name: m.title, items: (m.items ?? []).map(toItem) };
|
|
2679
2848
|
}
|
|
2680
|
-
/**
|
|
2849
|
+
/**
|
|
2850
|
+
* The header and footer menus, or `null` when the module is not there. Cached: a menu is
|
|
2851
|
+
* store-level. Each is the menu the shop chose for it in the theme editor's header or footer
|
|
2852
|
+
* (GoCommerce D131), still under the `header` / `footer` id every storefront looks for, so the
|
|
2853
|
+
* choice reaches every place that draws one; the menus named so are the default.
|
|
2854
|
+
*/
|
|
2681
2855
|
async engineMenus() {
|
|
2682
2856
|
if (!await this.facts.pluginOn("navigation")) return null;
|
|
2683
2857
|
return remember(`${this.engineBase()}|${this.store ?? ""}|menus`, async () => {
|
|
2684
2858
|
const out = [];
|
|
2685
|
-
for (const
|
|
2859
|
+
for (const part of ["header", "footer"]) {
|
|
2686
2860
|
try {
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2861
|
+
const handle = await this.chosenMenu(part);
|
|
2862
|
+
const m = await this.data(`/x/navigation/menus/${encodeURIComponent(handle)}`);
|
|
2863
|
+
out.push({ menuId: part, name: m.title, items: (m.items ?? []).map(toItem) });
|
|
2689
2864
|
} catch {
|
|
2690
2865
|
}
|
|
2691
2866
|
}
|
|
2692
2867
|
return out;
|
|
2693
2868
|
}).catch(() => null);
|
|
2694
2869
|
}
|
|
2870
|
+
/** The handle of the menu the published header or footer names, else the part's own name. */
|
|
2871
|
+
async chosenMenu(part) {
|
|
2872
|
+
if (!await this.facts.pluginOn("layouts")) return part;
|
|
2873
|
+
try {
|
|
2874
|
+
const layout = await this.data(`/x/layouts/${part}`);
|
|
2875
|
+
const menu = layout?.sections?.find((s) => s.type === part)?.settings?.menu;
|
|
2876
|
+
return typeof menu === "string" && menu ? menu : part;
|
|
2877
|
+
} catch {
|
|
2878
|
+
return part;
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2695
2881
|
};
|
|
2696
2882
|
var menuService = new MenuService();
|
|
2697
2883
|
|
|
@@ -2806,7 +2992,13 @@ var StoreService = class extends BaseService {
|
|
|
2806
2992
|
isProductReviewsAndRatings: {
|
|
2807
2993
|
...basePlugins.isProductReviewsAndRatings,
|
|
2808
2994
|
...flag(plugins.has("product-reviews"))
|
|
2809
|
-
}
|
|
2995
|
+
},
|
|
2996
|
+
// The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
|
|
2997
|
+
// switch (D131) can only show it while that is on.
|
|
2998
|
+
newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) },
|
|
2999
|
+
// Discount codes are core: every GoCommerce store takes them, so
|
|
3000
|
+
// the code box is shown whatever the static record says.
|
|
3001
|
+
isDiscountCoupons: { ...basePlugins.isDiscountCoupons, active: true }
|
|
2810
3002
|
},
|
|
2811
3003
|
...menus?.length ? { menu: menus } : {},
|
|
2812
3004
|
...deliverable(base, ships),
|
|
@@ -2921,6 +3113,35 @@ var LayoutService = class extends BaseService {
|
|
|
2921
3113
|
return null;
|
|
2922
3114
|
}
|
|
2923
3115
|
}
|
|
3116
|
+
/**
|
|
3117
|
+
* The header the shop set in the theme editor (D131), drawn on every
|
|
3118
|
+
* page: the published one, or a preview key's draft. Null — the
|
|
3119
|
+
* storefront's own header — when none is published, the editor is off, the
|
|
3120
|
+
* engine is older, or anything fails: a header is never worth an error page.
|
|
3121
|
+
*/
|
|
3122
|
+
async getHeader({ preview } = {}) {
|
|
3123
|
+
return this.chrome("header", preview);
|
|
3124
|
+
}
|
|
3125
|
+
/** The footer the shop set in the theme editor (D131); null for the storefront's own, as getHeader. */
|
|
3126
|
+
async getFooter({ preview } = {}) {
|
|
3127
|
+
return this.chrome("footer", preview);
|
|
3128
|
+
}
|
|
3129
|
+
async chrome(page, preview) {
|
|
3130
|
+
let layout;
|
|
3131
|
+
try {
|
|
3132
|
+
layout = await this.getPageLayout(page, { preview });
|
|
3133
|
+
} catch {
|
|
3134
|
+
return null;
|
|
3135
|
+
}
|
|
3136
|
+
const section = layout?.sections.find((s) => s.type === page);
|
|
3137
|
+
if (!layout || !section) return null;
|
|
3138
|
+
const settings = { ...section.settings };
|
|
3139
|
+
let menu = null;
|
|
3140
|
+
if (typeof settings.menu === "string" && settings.menu) {
|
|
3141
|
+
menu = await new MenuService(this._fetch).getMenu(settings.menu).catch(() => null);
|
|
3142
|
+
}
|
|
3143
|
+
return { revision: layout.revision, preview: layout.preview, settings, menu };
|
|
3144
|
+
}
|
|
2924
3145
|
};
|
|
2925
3146
|
function tokens(v) {
|
|
2926
3147
|
return v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length ? { ...v } : null;
|
|
@@ -3483,6 +3704,6 @@ function attemptKey(request) {
|
|
|
3483
3704
|
}
|
|
3484
3705
|
var b2bService = new B2bService();
|
|
3485
3706
|
|
|
3486
|
-
export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, NotSupportedError, OrderService, PageService, PaymentMethodService, PluginService, PluginService as PluginsService, PopularSearchService, PopularityService, ProductService, ProfileService, REDIRECT_GATEWAYS, ReelsService, RegionService, ReviewService, SearchService, SettingService, SettingService as SettingsService, StateService, StoreService, UploadService, UserService, VariantService, VarniCustomDesignService, VarniCustomProductService, VendorService, WarrantyService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toCart, toCartLine, toCategory, toCmsPage, toCollection, toEngineAddress, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
|
|
3707
|
+
export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoCommerceError, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, NotSupportedError, OrderService, PageService, PaymentMethodService, PluginService, PluginService as PluginsService, PopularSearchService, PopularityService, ProductService, ProfileService, REDIRECT_GATEWAYS, ReelsService, RegionService, ReviewService, SearchService, SettingService, SettingService as SettingsService, StateService, StoreService, UploadService, UserService, VariantService, VarniCustomDesignService, VarniCustomProductService, VendorService, WarrantyService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, forgetAll as clearStoreCache, collectionService, connectorName, contactService, countryService, couponService, currencyExponent, currencyService, dealService, demoRequestService, emptyCart, emptyPage, enquiryService, faqService, feedbackService, fromEngineAddress, fromIdentityAddress, fromSearchDoc, galleryService, hasStaticStore, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, minorToMajor, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, priceOf, productImages, productService, profileService, qs, readStaticStore, reelsService, regionService, reviewService, searchService, serveRestLocally, setRequestHost, setStaticStore, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toAddOn, toCart, toCartLine, toCartOffer, toCategory, toCmsPage, toCollection, toEngineAddress, toFreeShipping, toIdentityAddress, toMajor, toMinor, toOrder, toPage, toProduct, toRating, toStorefrontFacets, toUser, toVariant, toVendor, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, wishlistService };
|
|
3487
3708
|
//# sourceMappingURL=index.js.map
|
|
3488
3709
|
//# sourceMappingURL=index.js.map
|