@misiki/gocommerce-connector 0.23.0 → 0.24.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.
@@ -1 +1 @@
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, Z as GoogleReview, _ as GoogleReviewService, $ as GoogleReviews, a1 as HeaderSettings, a2 as HomeLayout, a3 as HomeLayoutSection, a4 as HomeService, a6 as InitService, a7 as Invitation, a8 as LayoutCollection, a9 as LayoutPage, aa as LayoutService, ab as Lead, ad as MeilisearchService, ae as Member, ah as MenuService, ak as NewsletterService, ap as OrderService, aq as PageLayout, ar as PageService, at as PaymentMethodService, av as PluginService, av as PluginsService, aw as PopularSearchService, ax as PopularityService, aC as ProductService, aD as ProfileService, aE as Quote, aF as REDIRECT_GATEWAYS, aG as ReelsService, aH as RegionService, aI as RejectedLine, aL as ReviewService, aO as SearchService, aP as SettingService, aP as SettingsService, aR as SiteChrome, aS as SiteFooter, aT as SiteHeader, aU as SocialLink, aV as StateService, aX as StoreService, aZ as StorefrontMenu, b0 as ThemeSettings, b1 as ThemeSettingsResult, b2 as UploadService, b3 as UserService, b6 as VariantService, b7 as VarniCustomDesignService, b8 as VarniCustomProductService, ba as VendorService, bb as WarrantyService, bc as WhatsappConsent, bd as WhatsappConsentOffer, be as WhatsappService, bh as WishlistService, bi as addressService, bj as authService, bk as autocompleteService, bl as b2bService, bm as bannerService, bn as blogService, bo as cartService, bp as categoryService, bq as chatService, br as checkoutService, bs as collectionService, bt as contactService, bu as countryService, bv as couponService, bx as currencyService, by as dealService, bz as demoRequestService, bB as emptyPage, bC as enquiryService, bD as faqService, bE as feedbackService, bI as galleryService, bJ as googleReviewService, bK as homeService, bL as initService, bM as layoutService, bN as mediaUrl, bO as meilisearchService, bP as menuService, bR as newsletterService, bS as orderService, bT as ownDomain, bU as pageService, bV as paymentMethodService, bW as pluginService, bX as pluginsService, bY as popularSearchService, bZ as popularityService, c0 as productService, c2 as profileService, c3 as qs, c4 as reelsService, c5 as regionService, c6 as reviewService, c7 as searchService, c8 as setRequestHost, c9 as settingService, ca as settingsService, cb as stateService, cc as staticStore, cd as storeForHost, ce as storeService, cs as toPage, cv as toStorefrontFacets, cz as uploadService, cA as userService, cB as variantService, cC as varniCustomDesignService, cD as varniCustomProductService, cE as vendorService, cF as warrantyService, cG as whatsappService, cH as wishlistService } from '../index-BM6hYdQs.cjs';
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, N as CustomizerEditor, O as CustomizerFile, Q as CustomizerSavedDesign, R as CustomizerService, U as DealService, V as DemoRequestService, W as EngineRequest, X as EnquiryService, $ as FaqService, a0 as FeedbackService, a1 as FooterSettings, a4 as GalleryService, a6 as GoogleReview, a7 as GoogleReviewService, a8 as GoogleReviews, aa as HeaderSettings, ab as HomeLayout, ac as HomeLayoutSection, ad as HomeService, af as InitService, ag as Invitation, ah as LayoutCollection, ai as LayoutPage, aj as LayoutService, ak as Lead, am as MeilisearchService, an as Member, aq as MenuService, at as NewsletterService, ay as OrderService, az as PageLayout, aA as PageService, aC as PaymentMethodService, aE as PluginService, aE as PluginsService, aF as PopularSearchService, aG as PopularityService, aL as ProductService, aM as ProfileService, aN as Quote, aO as REDIRECT_GATEWAYS, aP as ReelsService, aQ as RegionService, aR as RejectedLine, aU as ReviewService, aX as SearchService, aY as SettingService, aY as SettingsService, a_ as SiteChrome, a$ as SiteFooter, b0 as SiteHeader, b1 as SocialLink, b2 as StateService, b4 as StoreService, b6 as StorefrontMenu, b9 as ThemeSettings, ba as ThemeSettingsResult, bb as UploadService, bc as UserService, bf as VariantService, bg as VarniCustomDesignService, bh as VarniCustomProductService, bj as VendorService, bk as WarrantyService, bl as WhatsappConsent, bm as WhatsappConsentOffer, bn as WhatsappService, bq as WishlistService, br as addressService, bs as authService, bt as autocompleteService, bu as b2bService, bv as bannerService, bw as blogService, bx as cartService, by as categoryService, bz as chatService, bA as checkoutService, bB as collectionService, bC as contactService, bD as countryService, bE as couponService, bG as currencyService, bH as customizerService, bI as dealService, bJ as demoRequestService, bL as emptyPage, bM as enquiryService, bN as faqService, bO as feedbackService, bS as galleryService, bT as googleReviewService, bU as homeService, bV as initService, bW as layoutService, bX as mediaUrl, bY as meilisearchService, bZ as menuService, b$ as newsletterService, c0 as orderService, c1 as ownDomain, c2 as pageService, c3 as paymentMethodService, c4 as pluginService, c5 as pluginsService, c6 as popularSearchService, c7 as popularityService, ca as productService, cc as profileService, cd as qs, ce as reelsService, cf as regionService, cg as reviewService, ch as searchService, ci as setRequestHost, cj as settingService, ck as settingsService, cl as stateService, cm as staticStore, cn as storeForHost, co as storeService, cC as toPage, cF as toStorefrontFacets, cJ as uploadService, cK as userService, cL as variantService, cM as varniCustomDesignService, cN as varniCustomProductService, cO as vendorService, cP as warrantyService, cQ as whatsappService, cR as wishlistService } from '../index-BWg1KptA.cjs';
@@ -1 +1 @@
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, Z as GoogleReview, _ as GoogleReviewService, $ as GoogleReviews, a1 as HeaderSettings, a2 as HomeLayout, a3 as HomeLayoutSection, a4 as HomeService, a6 as InitService, a7 as Invitation, a8 as LayoutCollection, a9 as LayoutPage, aa as LayoutService, ab as Lead, ad as MeilisearchService, ae as Member, ah as MenuService, ak as NewsletterService, ap as OrderService, aq as PageLayout, ar as PageService, at as PaymentMethodService, av as PluginService, av as PluginsService, aw as PopularSearchService, ax as PopularityService, aC as ProductService, aD as ProfileService, aE as Quote, aF as REDIRECT_GATEWAYS, aG as ReelsService, aH as RegionService, aI as RejectedLine, aL as ReviewService, aO as SearchService, aP as SettingService, aP as SettingsService, aR as SiteChrome, aS as SiteFooter, aT as SiteHeader, aU as SocialLink, aV as StateService, aX as StoreService, aZ as StorefrontMenu, b0 as ThemeSettings, b1 as ThemeSettingsResult, b2 as UploadService, b3 as UserService, b6 as VariantService, b7 as VarniCustomDesignService, b8 as VarniCustomProductService, ba as VendorService, bb as WarrantyService, bc as WhatsappConsent, bd as WhatsappConsentOffer, be as WhatsappService, bh as WishlistService, bi as addressService, bj as authService, bk as autocompleteService, bl as b2bService, bm as bannerService, bn as blogService, bo as cartService, bp as categoryService, bq as chatService, br as checkoutService, bs as collectionService, bt as contactService, bu as countryService, bv as couponService, bx as currencyService, by as dealService, bz as demoRequestService, bB as emptyPage, bC as enquiryService, bD as faqService, bE as feedbackService, bI as galleryService, bJ as googleReviewService, bK as homeService, bL as initService, bM as layoutService, bN as mediaUrl, bO as meilisearchService, bP as menuService, bR as newsletterService, bS as orderService, bT as ownDomain, bU as pageService, bV as paymentMethodService, bW as pluginService, bX as pluginsService, bY as popularSearchService, bZ as popularityService, c0 as productService, c2 as profileService, c3 as qs, c4 as reelsService, c5 as regionService, c6 as reviewService, c7 as searchService, c8 as setRequestHost, c9 as settingService, ca as settingsService, cb as stateService, cc as staticStore, cd as storeForHost, ce as storeService, cs as toPage, cv as toStorefrontFacets, cz as uploadService, cA as userService, cB as variantService, cC as varniCustomDesignService, cD as varniCustomProductService, cE as vendorService, cF as warrantyService, cG as whatsappService, cH as wishlistService } from '../index-BM6hYdQs.js';
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, N as CustomizerEditor, O as CustomizerFile, Q as CustomizerSavedDesign, R as CustomizerService, U as DealService, V as DemoRequestService, W as EngineRequest, X as EnquiryService, $ as FaqService, a0 as FeedbackService, a1 as FooterSettings, a4 as GalleryService, a6 as GoogleReview, a7 as GoogleReviewService, a8 as GoogleReviews, aa as HeaderSettings, ab as HomeLayout, ac as HomeLayoutSection, ad as HomeService, af as InitService, ag as Invitation, ah as LayoutCollection, ai as LayoutPage, aj as LayoutService, ak as Lead, am as MeilisearchService, an as Member, aq as MenuService, at as NewsletterService, ay as OrderService, az as PageLayout, aA as PageService, aC as PaymentMethodService, aE as PluginService, aE as PluginsService, aF as PopularSearchService, aG as PopularityService, aL as ProductService, aM as ProfileService, aN as Quote, aO as REDIRECT_GATEWAYS, aP as ReelsService, aQ as RegionService, aR as RejectedLine, aU as ReviewService, aX as SearchService, aY as SettingService, aY as SettingsService, a_ as SiteChrome, a$ as SiteFooter, b0 as SiteHeader, b1 as SocialLink, b2 as StateService, b4 as StoreService, b6 as StorefrontMenu, b9 as ThemeSettings, ba as ThemeSettingsResult, bb as UploadService, bc as UserService, bf as VariantService, bg as VarniCustomDesignService, bh as VarniCustomProductService, bj as VendorService, bk as WarrantyService, bl as WhatsappConsent, bm as WhatsappConsentOffer, bn as WhatsappService, bq as WishlistService, br as addressService, bs as authService, bt as autocompleteService, bu as b2bService, bv as bannerService, bw as blogService, bx as cartService, by as categoryService, bz as chatService, bA as checkoutService, bB as collectionService, bC as contactService, bD as countryService, bE as couponService, bG as currencyService, bH as customizerService, bI as dealService, bJ as demoRequestService, bL as emptyPage, bM as enquiryService, bN as faqService, bO as feedbackService, bS as galleryService, bT as googleReviewService, bU as homeService, bV as initService, bW as layoutService, bX as mediaUrl, bY as meilisearchService, bZ as menuService, b$ as newsletterService, c0 as orderService, c1 as ownDomain, c2 as pageService, c3 as paymentMethodService, c4 as pluginService, c5 as pluginsService, c6 as popularSearchService, c7 as popularityService, ca as productService, cc as profileService, cd as qs, ce as reelsService, cf as regionService, cg as reviewService, ch as searchService, ci as setRequestHost, cj as settingService, ck as settingsService, cl as stateService, cm as staticStore, cn as storeForHost, co as storeService, cC as toPage, cF as toStorefrontFacets, cJ as uploadService, cK as userService, cL as variantService, cM as varniCustomDesignService, cN as varniCustomProductService, cO as vendorService, cP as warrantyService, cQ as whatsappService, cR as wishlistService } from '../index-BWg1KptA.js';
@@ -302,7 +302,8 @@ var BaseService = class _BaseService {
302
302
  const lang = (req.method ?? "GET") === "GET" ? this.creds.language : void 0;
303
303
  const url = this.engineURL(path, lang ? { lang, ...req.query } : req.query);
304
304
  const headers = { Accept: "application/json", ...req.headers };
305
- if (req.body !== void 0) headers["Content-Type"] = "application/json";
305
+ const form = req.body instanceof FormData ? req.body : void 0;
306
+ if (req.body !== void 0 && !form) headers["Content-Type"] = "application/json";
306
307
  const store = this.store;
307
308
  if (store) headers["X-Store"] = store;
308
309
  if (req.auth) {
@@ -313,7 +314,7 @@ var BaseService = class _BaseService {
313
314
  const init = {
314
315
  method: req.method ?? "GET",
315
316
  headers,
316
- body: req.body === void 0 ? void 0 : JSON.stringify(req.body)
317
+ body: form ?? (req.body === void 0 ? void 0 : JSON.stringify(req.body))
317
318
  };
318
319
  let res;
319
320
  try {
@@ -810,6 +811,9 @@ function toCartLine(l, extra = {}) {
810
811
  /** The add-on this line was bought as (D133), or null on an ordinary line. */
811
812
  addOnId: l.add_on_id ? str(l.add_on_id) : null,
812
813
  addOnFor: l.add_on_for ? str(l.add_on_for) : null,
814
+ /** The shopper's own design this line is made to (D162) and its picture, or null on a line sold as it is. */
815
+ designId: l.design_id ?? null,
816
+ designPreview: mediaUrl(l.design_preview_url),
813
817
  subtotal: toMajor(l.total),
814
818
  total: toMajor(l.total),
815
819
  inStock: l.in_stock,
@@ -924,6 +928,8 @@ function toOrderLine(l, currency) {
924
928
  total: toMajor(l.total),
925
929
  currencyCode: currency,
926
930
  status: l.shipped_quantity >= l.quantity ? "Shipped" : "Pending",
931
+ designId: l.metadata?.design?.id ?? null,
932
+ designPreview: mediaUrl(l.metadata?.design?.preview_url),
927
933
  files: [],
928
934
  usedOptions: []
929
935
  };
@@ -1754,13 +1760,16 @@ var CartService = class extends BaseService {
1754
1760
  }
1755
1761
  /**
1756
1762
  * `qty` is a change, not a total: +1 from a product page, −1 from a card's
1757
- * minus button. With no cart yet, one is opened and remembered.
1763
+ * minus button. With no cart yet, one is opened and remembered. A
1764
+ * `designId` from `customizerService.saveDesign` makes the variant to the
1765
+ * shopper's design, on a line of its own.
1758
1766
  */
1759
1767
  async addToCart({
1760
1768
  cartId,
1761
1769
  lineId,
1762
1770
  qty = 1,
1763
- variantId
1771
+ variantId,
1772
+ designId
1764
1773
  }) {
1765
1774
  let id2 = clean(cartId) ?? storedCartId();
1766
1775
  if (lineId && id2) {
@@ -1774,21 +1783,16 @@ var CartService = class extends BaseService {
1774
1783
  if (qty === REMOVE || Number(qty) <= 0) return this.getCartByCartId(id2);
1775
1784
  if (!variantId) throw new GoCommerceError("Please choose an option before adding this to your bag.", 400);
1776
1785
  if (!id2) id2 = await this.open();
1786
+ const body = { variant_id: Number(variantId), quantity: Number(qty), ...designId ? { design_id: designId } : {} };
1777
1787
  try {
1778
1788
  return await this.present(
1779
- await this.data(`/api/carts/${encodeURIComponent(id2)}/line-items`, {
1780
- method: "POST",
1781
- body: { variant_id: Number(variantId), quantity: Number(qty) }
1782
- })
1789
+ await this.data(`/api/carts/${encodeURIComponent(id2)}/line-items`, { method: "POST", body })
1783
1790
  );
1784
1791
  } catch (err) {
1785
- if (err instanceof GoCommerceError && (err.status === 404 || /checked out/.test(err.message))) {
1792
+ if (err instanceof GoCommerceError && /cart not found|checked out/.test(err.message)) {
1786
1793
  const fresh = await this.open();
1787
1794
  return this.present(
1788
- await this.data(`/api/carts/${encodeURIComponent(fresh)}/line-items`, {
1789
- method: "POST",
1790
- body: { variant_id: Number(variantId), quantity: Number(qty) }
1791
- })
1795
+ await this.data(`/api/carts/${encodeURIComponent(fresh)}/line-items`, { method: "POST", body })
1792
1796
  );
1793
1797
  }
1794
1798
  throw err;
@@ -2025,6 +2029,54 @@ var CartService = class extends BaseService {
2025
2029
  var clean = (id2) => id2 && id2 !== "undefined" && id2 !== "null" ? id2 : null;
2026
2030
  var cartService = new CartService();
2027
2031
 
2032
+ // src/services/customizer-service.ts
2033
+ var CustomizerService = class extends BaseService {
2034
+ facts = new StoreFacts(this._fetch);
2035
+ /** Null when the product cannot be designed, or on any failure: the page draws without the editor. */
2036
+ async setup(productId) {
2037
+ const plugins = await this.facts.plugins().catch(() => null);
2038
+ if (plugins && !plugins.has("customizer")) return null;
2039
+ const path = `/x/customizer/products/${encodeURIComponent(String(productId))}`;
2040
+ const s = await this.data(path).catch(() => null);
2041
+ if (!s) return null;
2042
+ return {
2043
+ productId: String(s.product_id),
2044
+ mockup: { ...s.mockup, url: media(s.mockup.url) },
2045
+ overlayUrl: mediaUrl(s.overlay_url),
2046
+ printArea: s.print_area,
2047
+ printSize: { widthMm: s.print_size.width_mm, heightMm: s.print_size.height_mm, dpi: s.print_size.dpi },
2048
+ tools: s.tools,
2049
+ fonts: s.fonts,
2050
+ stickers: s.stickers.map((k) => ({ ...k, url: media(k.url) })),
2051
+ minPhotoPx: s.min_photo_px,
2052
+ consent: s.consent
2053
+ };
2054
+ }
2055
+ /** A photo, or the finished preview or print file. The engine's refusal is thrown with its message. */
2056
+ async upload(file, filename) {
2057
+ const body = new FormData();
2058
+ body.append("file", file, filename);
2059
+ const u = await this.data("/x/customizer/uploads", { method: "POST", body });
2060
+ return { uploadId: u.upload_id, url: media(u.url), width: u.width, height: u.height };
2061
+ }
2062
+ /** The document goes as it is: the order keeps it, and whatever renders the print reads it there. */
2063
+ async saveDesign(design) {
2064
+ const d = await this.data("/x/customizer/designs", {
2065
+ method: "POST",
2066
+ body: {
2067
+ product_id: Number(design.productId),
2068
+ variant_id: Number(design.variantId),
2069
+ preview_upload_id: design.previewUploadId,
2070
+ print_upload_id: design.printUploadId,
2071
+ document: design.document
2072
+ }
2073
+ });
2074
+ return { designId: d.design_id, previewUrl: media(d.preview_url) };
2075
+ }
2076
+ };
2077
+ var media = (url) => mediaUrl(url) ?? url;
2078
+ var customizerService = new CustomizerService();
2079
+
2028
2080
  // src/services/checkout-service.ts
2029
2081
  var CheckoutService = class extends BaseService {
2030
2082
  /** Delivery options for the address on the cart: `{ data: [{ id, name, base_rate }] }`. */
@@ -4007,6 +4059,6 @@ function attemptKey(request) {
4007
4059
  }
4008
4060
  var b2bService = new B2bService();
4009
4061
 
4010
- export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoogleReviewService, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, 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, WhatsappService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, collectionService, contactService, countryService, couponService, currencyService, dealService, demoRequestService, emptyPage, enquiryService, faqService, feedbackService, galleryService, googleReviewService, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, productService, profileService, qs, reelsService, regionService, reviewService, searchService, setRequestHost, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toPage, toStorefrontFacets, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, whatsappService, wishlistService };
4062
+ export { AddressService, AuthService, AutocompleteService, B2bService, BannerService, BaseService, BlogService, CartService, CatalogService, CategoryService, ChatService, CheckoutService, CollectionService, ContactService, CountryService, CouponService, CurrencyService, CustomizerService, DealService, DemoRequestService, EnquiryService, FaqService, FeedbackService, GalleryService, GoogleReviewService, HomeService, InitService, LayoutService, MeilisearchService, MenuService, NewsletterService, 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, WhatsappService, WishlistService, addressService, authService, autocompleteService, b2bService, bannerService, blogService, cartService, categoryService, chatService, checkoutService, collectionService, contactService, countryService, couponService, currencyService, customizerService, dealService, demoRequestService, emptyPage, enquiryService, faqService, feedbackService, galleryService, googleReviewService, homeService, initService, layoutService, mediaUrl, meilisearchService, menuService, newsletterService, orderService, ownDomain, pageService, paymentMethodService, pluginService, pluginsService, popularSearchService, popularityService, productService, profileService, qs, reelsService, regionService, reviewService, searchService, setRequestHost, settingService, settingsService, stateService, staticStore, storeForHost, storeService, toPage, toStorefrontFacets, uploadService, userService, variantService, varniCustomDesignService, varniCustomProductService, vendorService, warrantyService, whatsappService, wishlistService };
4011
4063
  //# sourceMappingURL=index.js.map
4012
4064
  //# sourceMappingURL=index.js.map