@misiki/gocommerce-connector 0.12.0 → 0.13.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, 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';
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, aw as ProductService, ax as ProfileService, ay as Quote, az as REDIRECT_GATEWAYS, aA as ReelsService, aB as RegionService, aC as RejectedLine, aF as ReviewService, aI as SearchService, aJ as SettingService, aJ as SettingsService, aL as SiteChrome, aM as SiteFooter, aN as SiteHeader, aO as SocialLink, aP as StateService, aR as StoreService, aT as StorefrontMenu, aW as ThemeSettings, aX as ThemeSettingsResult, aY as UploadService, aZ as UserService, b0 as VariantService, b1 as VarniCustomDesignService, b2 as VarniCustomProductService, b4 as VendorService, b5 as WarrantyService, b8 as WishlistService, b9 as addressService, ba as authService, bb as autocompleteService, bc as b2bService, bd as bannerService, be as blogService, bf as cartService, bg as categoryService, bh as chatService, bi as checkoutService, bj as collectionService, bk as contactService, bl as countryService, bm as couponService, bo as currencyService, bp as dealService, bq as demoRequestService, bs as emptyPage, bt as enquiryService, bu as faqService, bv as feedbackService, bz as galleryService, bA as homeService, bB as initService, bC as layoutService, bD as mediaUrl, bE as meilisearchService, bF as menuService, bH as newsletterService, bI as orderService, bJ as ownDomain, bK as pageService, bL as paymentMethodService, bM as pluginService, bN as pluginsService, bO as popularSearchService, bP as popularityService, bS as productService, bU as profileService, bV as qs, bW as reelsService, bX as regionService, bY as reviewService, bZ as searchService, b_ as setRequestHost, b$ as settingService, c0 as settingsService, c1 as stateService, c2 as staticStore, c3 as storeForHost, c4 as storeService, ci as toPage, cl as toStorefrontFacets, cp as uploadService, cq as userService, cr as variantService, cs as varniCustomDesignService, ct as varniCustomProductService, cu as vendorService, cv as warrantyService, cw as wishlistService } from '../index-DHKyh3CU.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, 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';
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, aw as ProductService, ax as ProfileService, ay as Quote, az as REDIRECT_GATEWAYS, aA as ReelsService, aB as RegionService, aC as RejectedLine, aF as ReviewService, aI as SearchService, aJ as SettingService, aJ as SettingsService, aL as SiteChrome, aM as SiteFooter, aN as SiteHeader, aO as SocialLink, aP as StateService, aR as StoreService, aT as StorefrontMenu, aW as ThemeSettings, aX as ThemeSettingsResult, aY as UploadService, aZ as UserService, b0 as VariantService, b1 as VarniCustomDesignService, b2 as VarniCustomProductService, b4 as VendorService, b5 as WarrantyService, b8 as WishlistService, b9 as addressService, ba as authService, bb as autocompleteService, bc as b2bService, bd as bannerService, be as blogService, bf as cartService, bg as categoryService, bh as chatService, bi as checkoutService, bj as collectionService, bk as contactService, bl as countryService, bm as couponService, bo as currencyService, bp as dealService, bq as demoRequestService, bs as emptyPage, bt as enquiryService, bu as faqService, bv as feedbackService, bz as galleryService, bA as homeService, bB as initService, bC as layoutService, bD as mediaUrl, bE as meilisearchService, bF as menuService, bH as newsletterService, bI as orderService, bJ as ownDomain, bK as pageService, bL as paymentMethodService, bM as pluginService, bN as pluginsService, bO as popularSearchService, bP as popularityService, bS as productService, bU as profileService, bV as qs, bW as reelsService, bX as regionService, bY as reviewService, bZ as searchService, b_ as setRequestHost, b$ as settingService, c0 as settingsService, c1 as stateService, c2 as staticStore, c3 as storeForHost, c4 as storeService, ci as toPage, cl as toStorefrontFacets, cp as uploadService, cq as userService, cr as variantService, cs as varniCustomDesignService, ct as varniCustomProductService, cu as vendorService, cv as warrantyService, cw as wishlistService } from '../index-DHKyh3CU.js';
@@ -464,9 +464,27 @@ function productImages(p) {
464
464
  if (url && !out.includes(url)) out.push(url);
465
465
  };
466
466
  push(mediaUrl(p.image_url));
467
+ for (const m of arr(p.media)) if (m.kind === "image") push(mediaUrl(m.url));
467
468
  for (const v of arr(p.variants)) for (const url of variantImages(v)) push(url);
468
469
  return out;
469
470
  }
471
+ function productVideos(p) {
472
+ const out = [];
473
+ for (const m of arr(p.media)) {
474
+ const url = m.kind === "video" ? mediaUrl(m.url) : null;
475
+ if (url && !out.includes(url)) out.push(url);
476
+ }
477
+ return out;
478
+ }
479
+ function highlightsOf(p) {
480
+ const raw = p.metadata?.highlights;
481
+ if (!Array.isArray(raw)) return [];
482
+ return raw.filter((s) => typeof s === "string").map((s) => s.trim()).filter(Boolean);
483
+ }
484
+ function freeGiftOf(p) {
485
+ const raw = p.metadata?.free_gift;
486
+ return typeof raw === "string" && raw.trim() ? raw.trim() : null;
487
+ }
470
488
  function toVariant(v, p, optionless) {
471
489
  const images = variantImages(v);
472
490
  const options = arr(p.options);
@@ -514,6 +532,7 @@ function toProduct(p, extra = {}) {
514
532
  const lead = live[0] ?? arr(p.variants)[0];
515
533
  const optionless = arr(p.options).length === 0;
516
534
  const images = productImages(p);
535
+ const videos = productVideos(p);
517
536
  const prices = live.map((v) => toMajor(v.price));
518
537
  const tracked = live.filter((v) => v.track_inventory);
519
538
  const category = p.category;
@@ -540,8 +559,14 @@ function toProduct(p, extra = {}) {
540
559
  originCountry: lead?.origin_country ?? null,
541
560
  thumbnail: images[0] ?? null,
542
561
  image_url: images[0] ?? null,
543
- images: images.join(","),
562
+ images: [...images, ...videos].join(","),
544
563
  imageList: images,
564
+ videos,
565
+ // What the buy box says beside the price (D134): plain text, drawn as text.
566
+ highlights: highlightsOf(p),
567
+ freeGift: freeGiftOf(p),
568
+ // Counted by the engine, rounded down, and absent rather than zero.
569
+ soldAtLeast: typeof p.sold_at_least === "number" && p.sold_at_least > 0 ? p.sold_at_least : null,
545
570
  // Product-level stock is what a card shows before a variant is picked:
546
571
  // buyable when any live variant is, counted only where counting means
547
572
  // something.
@@ -714,7 +739,9 @@ function toIdentityAddress(a) {
714
739
  state: e.state ?? "",
715
740
  postal_code: e.postal_code,
716
741
  country: e.country,
717
- ...a.label ? { label: String(a.label) } : {},
742
+ // Sent whenever the form has it, empty included: the engine keeps a label it is not sent, so
743
+ // leaving out an emptied one would keep the old Home or Work (D134).
744
+ ...typeof a.label === "string" ? { label: a.label } : {},
718
745
  ...a.isPrimary ? { is_default: true } : {}
719
746
  };
720
747
  }
@@ -2667,6 +2694,24 @@ var AddressService = class extends BaseService {
2667
2694
  });
2668
2695
  return fromIdentityAddress(a, currentMe()?.email);
2669
2696
  }
2697
+ /**
2698
+ * The city and state for a postcode (D134), for the address form to fill
2699
+ * in. India's six-digit PIN codes only, from the directory the engine was
2700
+ * given; null for anything it cannot answer, so the form simply leaves the
2701
+ * fields to the shopper.
2702
+ */
2703
+ async lookupPostcode({ country = "IN", postcode }) {
2704
+ const code = String(postcode ?? "").trim();
2705
+ const cc = String(country ?? "").trim().toUpperCase();
2706
+ if (cc !== "IN" || !/^[1-9][0-9]{5}$/.test(code)) return null;
2707
+ try {
2708
+ const p = await this.data(`/api/postcodes/${cc}/${code}`);
2709
+ return { country: p.country, postcode: p.postcode, city: p.city, state: p.state, stateCode: p.state_code };
2710
+ } catch (err) {
2711
+ if (err instanceof GoCommerceError && (err.status === 404 || err.status === 400)) return null;
2712
+ throw err;
2713
+ }
2714
+ }
2670
2715
  async deleteAddress(id2) {
2671
2716
  await this.engine(`/x/identity/me/addresses/${enc(id2)}`, { method: "DELETE", auth: true });
2672
2717
  return { id: String(id2), deleted: true };