@misiki/gocommerce-connector 0.11.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 +3 -0
- package/dist/{index-90wdO5MM.d.cts → index-Bu4bVBBm.d.cts} +393 -5
- package/dist/{index-90wdO5MM.d.ts → index-Bu4bVBBm.d.ts} +393 -5
- package/dist/index.cjs +178 -3
- 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 +176 -4
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +175 -3
- 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 +175 -3
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { b as AddressService, d as Approval, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, o as CartService, p as CatalogService, r as CategoryService, s as ChatService, v as CheckoutService, y as CollectionService, z as Company, D as CompanyOrder, E as ContactService, F as CountryService, G as CouponService, I as Credit, J as CurrencyService, L as DealService, M as DemoRequestService, N as EngineRequest, O as EnquiryService, S as FaqService, T as FeedbackService, U as FooterSettings, X as GalleryService, Y as HeaderSettings, Z as HomeLayout, _ as HomeLayoutSection, $ as HomeService, a1 as InitService, a2 as Invitation, a3 as LayoutCollection, a4 as LayoutPage, a5 as LayoutService, a6 as Lead, a8 as MeilisearchService, a9 as Member, ac as MenuService, af as NewsletterService, aj as OrderService, ak as PageLayout, al as PageService, an as PaymentMethodService, ap as PluginService, ap as PluginsService, aq as PopularSearchService, ar as PopularityService, av as ProductService, aw as ProfileService, ax as Quote, ay as REDIRECT_GATEWAYS, az as ReelsService, aA as RegionService, aB as RejectedLine, aE as ReviewService, aH as SearchService, aI as SettingService, aI as SettingsService, aK as SiteChrome, aL as SiteFooter, aM as SiteHeader, aN as SocialLink, aO as StateService, aQ as StoreService, aS as StorefrontMenu, aV as ThemeSettings, aW as ThemeSettingsResult, aX as UploadService, aY as UserService, a$ as VariantService, b0 as VarniCustomDesignService, b1 as VarniCustomProductService, b3 as VendorService, b4 as WarrantyService, 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, bn as currencyService, bo as dealService, bp as demoRequestService, br as emptyPage, bs as enquiryService, bt as faqService, bu as feedbackService, by as galleryService, bz as homeService, bA as initService, bB as layoutService, bC as mediaUrl, bD as meilisearchService, bE as menuService, 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, 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, cg as toPage, cj as toStorefrontFacets, 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';
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { b as AddressService, d as Approval, f as AuthService, g as AutocompleteService, B as B2bPlaced, h as B2bRole, i as B2bService, j as BannerService, k as BaseService, l as BlogService, o as CartService, p as CatalogService, r as CategoryService, s as ChatService, v as CheckoutService, y as CollectionService, z as Company, D as CompanyOrder, E as ContactService, F as CountryService, G as CouponService, I as Credit, J as CurrencyService, L as DealService, M as DemoRequestService, N as EngineRequest, O as EnquiryService, S as FaqService, T as FeedbackService, U as FooterSettings, X as GalleryService, Y as HeaderSettings, Z as HomeLayout, _ as HomeLayoutSection, $ as HomeService, a1 as InitService, a2 as Invitation, a3 as LayoutCollection, a4 as LayoutPage, a5 as LayoutService, a6 as Lead, a8 as MeilisearchService, a9 as Member, ac as MenuService, af as NewsletterService, aj as OrderService, ak as PageLayout, al as PageService, an as PaymentMethodService, ap as PluginService, ap as PluginsService, aq as PopularSearchService, ar as PopularityService, av as ProductService, aw as ProfileService, ax as Quote, ay as REDIRECT_GATEWAYS, az as ReelsService, aA as RegionService, aB as RejectedLine, aE as ReviewService, aH as SearchService, aI as SettingService, aI as SettingsService, aK as SiteChrome, aL as SiteFooter, aM as SiteHeader, aN as SocialLink, aO as StateService, aQ as StoreService, aS as StorefrontMenu, aV as ThemeSettings, aW as ThemeSettingsResult, aX as UploadService, aY as UserService, a$ as VariantService, b0 as VarniCustomDesignService, b1 as VarniCustomProductService, b3 as VendorService, b4 as WarrantyService, 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, bn as currencyService, bo as dealService, bp as demoRequestService, br as emptyPage, bs as enquiryService, bt as faqService, bu as feedbackService, by as galleryService, bz as homeService, bA as initService, bB as layoutService, bC as mediaUrl, bD as meilisearchService, bE as menuService, 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, 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, cg as toPage, cj as toStorefrontFacets, 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';
|
package/dist/services/index.js
CHANGED
|
@@ -731,7 +731,12 @@ function toCartLine(l, extra = {}) {
|
|
|
731
731
|
variantTitle: l.variant_label ?? "",
|
|
732
732
|
qty: l.quantity,
|
|
733
733
|
price: toMajor(l.unit_price),
|
|
734
|
-
|
|
734
|
+
// The variant's compare-at price, where the shop set one above what the
|
|
735
|
+
// line costs: what the basket's "you save" is measured from.
|
|
736
|
+
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),
|
|
737
|
+
/** The add-on this line was bought as (D133), or null on an ordinary line. */
|
|
738
|
+
addOnId: l.add_on_id ? str(l.add_on_id) : null,
|
|
739
|
+
addOnFor: l.add_on_for ? str(l.add_on_for) : null,
|
|
735
740
|
subtotal: toMajor(l.total),
|
|
736
741
|
total: toMajor(l.total),
|
|
737
742
|
inStock: l.in_stock,
|
|
@@ -964,6 +969,45 @@ function toUser(c) {
|
|
|
964
969
|
updatedAt: c.updated_at
|
|
965
970
|
};
|
|
966
971
|
}
|
|
972
|
+
function toAddOn(a) {
|
|
973
|
+
return {
|
|
974
|
+
id: str(a.id),
|
|
975
|
+
productId: str(a.item.product_id),
|
|
976
|
+
variantId: str(a.variant_id),
|
|
977
|
+
slug: a.item.slug,
|
|
978
|
+
title: a.item.title,
|
|
979
|
+
variantTitle: a.item.variant_label ?? "",
|
|
980
|
+
thumbnail: mediaUrl(a.item.image_url ?? null),
|
|
981
|
+
price: toMajor(a.offer_price ?? a.price),
|
|
982
|
+
regularPrice: toMajor(a.price),
|
|
983
|
+
hasOffer: !!a.offer_price && a.offer_price.amount_minor < a.price.amount_minor,
|
|
984
|
+
inStock: a.item.in_stock
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
function toCartOffer(o, currency) {
|
|
988
|
+
const isPercent = o.kind === "percentage";
|
|
989
|
+
return {
|
|
990
|
+
code: o.code,
|
|
991
|
+
title: o.title,
|
|
992
|
+
isPercent,
|
|
993
|
+
freeShipping: o.kind === "free_shipping",
|
|
994
|
+
/** The percentage for a percentage code, the amount for a fixed one. */
|
|
995
|
+
value: isPercent ? (o.value_bp ?? 0) / 100 : minorToMajor(o.value_minor ?? 0, currency),
|
|
996
|
+
minAmount: o.min_subtotal_minor ? minorToMajor(o.min_subtotal_minor, currency) : null,
|
|
997
|
+
applies: o.applies,
|
|
998
|
+
amount: o.amount ? toMajor(o.amount) : null,
|
|
999
|
+
remaining: o.remaining ? toMajor(o.remaining) : null,
|
|
1000
|
+
reason: o.reason ?? ""
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
function toFreeShipping(f) {
|
|
1004
|
+
return {
|
|
1005
|
+
qualifies: f.qualifies,
|
|
1006
|
+
threshold: f.threshold ? toMajor(f.threshold) : null,
|
|
1007
|
+
remaining: f.remaining ? toMajor(f.remaining) : null,
|
|
1008
|
+
subtotal: toMajor(f.subtotal)
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
967
1011
|
|
|
968
1012
|
// src/cache.ts
|
|
969
1013
|
var TTL_MS = 6e4;
|
|
@@ -1288,6 +1332,36 @@ var ProductService = class extends CatalogService {
|
|
|
1288
1332
|
if (!category) return this.list({ page, limit });
|
|
1289
1333
|
return this.list({ page, limit, categories: category.slug });
|
|
1290
1334
|
}
|
|
1335
|
+
/**
|
|
1336
|
+
* What the shop offers with a product, ticked in its buy box (D133): each
|
|
1337
|
+
* add-on at the price ticking it adds. Only add-ons that can be bought
|
|
1338
|
+
* arrive; an engine without the route offers none.
|
|
1339
|
+
*/
|
|
1340
|
+
async listAddOns({ product }) {
|
|
1341
|
+
const p = await this.findProduct(String(product));
|
|
1342
|
+
try {
|
|
1343
|
+
return (await this.data("/api/add-ons", { query: { product_id: p.id } }) ?? []).map(toAddOn);
|
|
1344
|
+
} catch (err) {
|
|
1345
|
+
if (err instanceof GoCommerceError && err.status === 404) return [];
|
|
1346
|
+
throw err;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* "You may also like": the products the shop chose for this one, at their
|
|
1351
|
+
* own prices (D133). Curated only, and empty when none were chosen: the
|
|
1352
|
+
* related products already fill in from the category, and the page should
|
|
1353
|
+
* not draw the same fill twice.
|
|
1354
|
+
*/
|
|
1355
|
+
async listCrossSells({ product, limit }) {
|
|
1356
|
+
const p = await this.findProduct(String(product));
|
|
1357
|
+
try {
|
|
1358
|
+
const rows = await this.data("/api/cross-sells", { query: { product_id: p.id, limit } }) ?? [];
|
|
1359
|
+
return rows.map((r) => toProduct(r));
|
|
1360
|
+
} catch (err) {
|
|
1361
|
+
if (err instanceof GoCommerceError && err.status === 404) return [];
|
|
1362
|
+
throw err;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1291
1365
|
async relatedTo(slug, limit) {
|
|
1292
1366
|
const size = Math.min(100, Math.max(1, Number(limit) || PAGE_SIZE));
|
|
1293
1367
|
const p = await this.findProduct(slug);
|
|
@@ -1627,6 +1701,88 @@ var CartService = class extends BaseService {
|
|
|
1627
1701
|
throw err;
|
|
1628
1702
|
}
|
|
1629
1703
|
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Adds an add-on from a product's "Complete the set" (D133) at its offer
|
|
1706
|
+
* price. The product it is offered with has to be in the bag already, so
|
|
1707
|
+
* this is called after adding it; the engine refuses one too many with the
|
|
1708
|
+
* sentence the shopper is shown.
|
|
1709
|
+
*/
|
|
1710
|
+
async addAddOn({ cartId, addOnId, qty = 1 }) {
|
|
1711
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1712
|
+
if (!id2) throw new GoCommerceError("Add the product to your bag first.", 409);
|
|
1713
|
+
return this.present(
|
|
1714
|
+
await this.data(`/api/carts/${encodeURIComponent(id2)}/line-items`, {
|
|
1715
|
+
method: "POST",
|
|
1716
|
+
body: { add_on_id: Number(addOnId), quantity: Number(qty) }
|
|
1717
|
+
})
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* The codes the shop chose to show (D133), each with what it takes off this
|
|
1722
|
+
* bag or how much more the bag needs. None without a bag.
|
|
1723
|
+
*/
|
|
1724
|
+
async getOffers({ cartId } = {}) {
|
|
1725
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1726
|
+
if (!id2) return [];
|
|
1727
|
+
try {
|
|
1728
|
+
const rows = await this.data(`/api/carts/${encodeURIComponent(id2)}/offers`) ?? [];
|
|
1729
|
+
const currency = await this.currency();
|
|
1730
|
+
return rows.map((o) => toCartOffer(o, o.amount?.currency ?? o.remaining?.currency ?? currency));
|
|
1731
|
+
} catch (err) {
|
|
1732
|
+
if (err instanceof GoCommerceError && err.status === 404) return [];
|
|
1733
|
+
throw err;
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* How far the bag is from free delivery (D133), read from the store's own
|
|
1738
|
+
* rates for the country (the store's own when none is given). Null when
|
|
1739
|
+
* the engine cannot say: a bar with a made-up figure is worse than none.
|
|
1740
|
+
*/
|
|
1741
|
+
async getFreeShipping({ cartId, country, state } = {}) {
|
|
1742
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1743
|
+
if (!id2) return null;
|
|
1744
|
+
const where = country ?? cartExtras(id2).shippingAddress?.country ?? void 0;
|
|
1745
|
+
try {
|
|
1746
|
+
return toFreeShipping(
|
|
1747
|
+
await this.data(`/api/carts/${encodeURIComponent(id2)}/free-shipping`, {
|
|
1748
|
+
query: { country: where || void 0, state: state || void 0 }
|
|
1749
|
+
})
|
|
1750
|
+
);
|
|
1751
|
+
} catch (err) {
|
|
1752
|
+
if (err instanceof GoCommerceError && err.status === 404) return null;
|
|
1753
|
+
throw err;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* "You may be interested in" (D133): what the bag's products suggest, less
|
|
1758
|
+
* what it holds; with nothing curated, the first product's related
|
|
1759
|
+
* products, still less what it holds.
|
|
1760
|
+
*/
|
|
1761
|
+
async listCrossSells({ cartId, limit = 12 } = {}) {
|
|
1762
|
+
const id2 = clean(cartId) ?? storedCartId();
|
|
1763
|
+
if (!id2) return [];
|
|
1764
|
+
let curated = [];
|
|
1765
|
+
try {
|
|
1766
|
+
curated = await this.data(`/api/carts/${encodeURIComponent(id2)}/cross-sells`, { query: { limit } }) ?? [];
|
|
1767
|
+
} catch (err) {
|
|
1768
|
+
if (!(err instanceof GoCommerceError) || err.status !== 404) throw err;
|
|
1769
|
+
}
|
|
1770
|
+
if (curated.length) return curated.map((p) => toProduct(p));
|
|
1771
|
+
let cart;
|
|
1772
|
+
try {
|
|
1773
|
+
cart = await this.data(`/api/carts/${encodeURIComponent(id2)}`);
|
|
1774
|
+
} catch {
|
|
1775
|
+
return [];
|
|
1776
|
+
}
|
|
1777
|
+
const held = new Set((cart.line_items ?? []).map((l) => String(l.product_id)));
|
|
1778
|
+
const first = cart.line_items?.[0];
|
|
1779
|
+
if (!first) return [];
|
|
1780
|
+
const related = await new ProductService(this._fetch).listRelatedProducts({
|
|
1781
|
+
product: String(first.product_id),
|
|
1782
|
+
limit: limit + held.size
|
|
1783
|
+
});
|
|
1784
|
+
return related.data.filter((p) => !held.has(String(p.id))).slice(0, limit);
|
|
1785
|
+
}
|
|
1630
1786
|
/** `qty` is the new total; 0 takes the line out. */
|
|
1631
1787
|
async updateCart({
|
|
1632
1788
|
cartId,
|
|
@@ -2060,7 +2216,20 @@ var paymentMethodService = new PaymentMethodService();
|
|
|
2060
2216
|
// src/services/coupon-service.ts
|
|
2061
2217
|
var CouponService = class extends BaseService {
|
|
2062
2218
|
async listCoupons(_args = {}) {
|
|
2063
|
-
|
|
2219
|
+
const offers = await new CartService(this._fetch).getOffers().catch(() => []);
|
|
2220
|
+
if (!offers.length) return emptyPage();
|
|
2221
|
+
const data = offers.map((o) => ({
|
|
2222
|
+
id: o.code,
|
|
2223
|
+
code: o.code,
|
|
2224
|
+
title: o.title,
|
|
2225
|
+
isPercent: o.isPercent,
|
|
2226
|
+
amount: o.value,
|
|
2227
|
+
minAmount: o.minAmount,
|
|
2228
|
+
description: o.applies ? o.title : o.remaining !== null ? `${o.title}. Add ${o.remaining} more to use this.` : o.reason || o.title,
|
|
2229
|
+
applies: o.applies,
|
|
2230
|
+
remaining: o.remaining
|
|
2231
|
+
}));
|
|
2232
|
+
return { data, count: data.length, pageSize: data.length, noOfPage: 1, page: 1 };
|
|
2064
2233
|
}
|
|
2065
2234
|
};
|
|
2066
2235
|
var couponService = new CouponService();
|
|
@@ -2810,7 +2979,10 @@ var StoreService = class extends BaseService {
|
|
|
2810
2979
|
},
|
|
2811
2980
|
// The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
|
|
2812
2981
|
// switch (D131) can only show it while that is on.
|
|
2813
|
-
newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) }
|
|
2982
|
+
newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) },
|
|
2983
|
+
// Discount codes are core: every GoCommerce store takes them, so
|
|
2984
|
+
// the code box is shown whatever the static record says.
|
|
2985
|
+
isDiscountCoupons: { ...basePlugins.isDiscountCoupons, active: true }
|
|
2814
2986
|
},
|
|
2815
2987
|
...menus?.length ? { menu: menus } : {},
|
|
2816
2988
|
...deliverable(base, ships),
|