@misiki/gocommerce-connector 0.3.0 → 0.3.1

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.
@@ -191,6 +191,12 @@ var rememberWishlistToken = (token) => writeLocal(WISHLIST, token);
191
191
  var forgetWishlistToken = () => removeLocal(WISHLIST);
192
192
 
193
193
  // src/services/base.service.ts
194
+ function mediaUrl(url) {
195
+ if (!url) return null;
196
+ if (!url.startsWith("/") || url.startsWith("//")) return url;
197
+ const { apiUrl, proxyPath } = BaseService.getCredentials();
198
+ return (proxyPath || apiUrl || "").trim().replace(/\/+$/, "") + url;
199
+ }
194
200
  var BaseService = class _BaseService {
195
201
  static _credentials = { apiUrl: "" };
196
202
  _fetch;
@@ -414,7 +420,8 @@ var liveVariants = (p) => arr(p.variants).filter((v) => v.active);
414
420
  function variantImages(v) {
415
421
  const out = [];
416
422
  for (const img of [v.image, ...arr(v.images)]) {
417
- if (img?.url && (img.kind ?? "image") === "image" && !out.includes(img.url)) out.push(img.url);
423
+ const url = mediaUrl(img?.url);
424
+ if (url && (img?.kind ?? "image") === "image" && !out.includes(url)) out.push(url);
418
425
  }
419
426
  return out;
420
427
  }
@@ -423,7 +430,7 @@ function productImages(p) {
423
430
  const push = (url) => {
424
431
  if (url && !out.includes(url)) out.push(url);
425
432
  };
426
- push(p.image_url);
433
+ push(mediaUrl(p.image_url));
427
434
  for (const v of arr(p.variants)) for (const url of variantImages(v)) push(url);
428
435
  return out;
429
436
  }
@@ -553,9 +560,9 @@ function fromSearchDoc(d) {
553
560
  mrp: price,
554
561
  minPrice: price,
555
562
  maxPrice: minorToMajor(d.price_max_minor, d.currency),
556
- thumbnail: d.image ?? null,
557
- image_url: d.image ?? null,
558
- images: d.image ?? "",
563
+ thumbnail: mediaUrl(d.image),
564
+ image_url: mediaUrl(d.image),
565
+ images: mediaUrl(d.image) ?? "",
559
566
  stock: d.in_stock ? 1 : 0,
560
567
  hasStock: d.in_stock,
561
568
  // The index cannot say how much is left, only whether any is; a card
@@ -584,7 +591,7 @@ function toCategory(c) {
584
591
  level: c.depth,
585
592
  rank: c.position,
586
593
  childCount: c.child_count,
587
- thumbnail: c.metadata?.image ?? null,
594
+ thumbnail: mediaUrl(c.metadata?.image),
588
595
  description: c.metadata?.description ?? null,
589
596
  isActive: true,
590
597
  isFeatured: false,
@@ -604,7 +611,7 @@ function toCollection(c) {
604
611
  description: c.description || null,
605
612
  subTitle: null,
606
613
  rank: str(c.position),
607
- thumbnail: c.metadata?.image ?? null,
614
+ thumbnail: mediaUrl(c.metadata?.image),
608
615
  isActive: true,
609
616
  metaTitle: c.title,
610
617
  metaDescription: c.description || null,
@@ -687,7 +694,7 @@ function toCartLine(l, extra = {}) {
687
694
  title: l.title,
688
695
  name: l.title,
689
696
  slug: extra.slug ?? "",
690
- thumbnail: extra.thumbnail ?? null,
697
+ thumbnail: mediaUrl(extra.thumbnail),
691
698
  variantTitle: l.variant_label ?? "",
692
699
  qty: l.quantity,
693
700
  price: toMajor(l.unit_price),
@@ -795,8 +802,8 @@ function toOrderLine(l, currency) {
795
802
  title: l.title,
796
803
  name: l.title,
797
804
  slug: "",
798
- thumbnail: l.image_url ?? null,
799
- img: l.image_url ?? null,
805
+ thumbnail: mediaUrl(l.image_url),
806
+ img: mediaUrl(l.image_url),
800
807
  variantTitle: l.variant_label ?? "",
801
808
  qty: l.quantity,
802
809
  shippedQty: l.shipped_quantity,
@@ -1954,7 +1961,7 @@ var OrderService = class extends BaseService {
1954
1961
  productId: l.product_id,
1955
1962
  variantId: l.variant_id,
1956
1963
  title: l.title,
1957
- img: l.image_url ?? null,
1964
+ img: mediaUrl(l.image_url),
1958
1965
  price: toMajor(l.unit_price),
1959
1966
  qty: l.quantity
1960
1967
  });
@@ -3133,6 +3140,7 @@ exports.feedbackService = feedbackService;
3133
3140
  exports.galleryService = galleryService;
3134
3141
  exports.homeService = homeService;
3135
3142
  exports.initService = initService;
3143
+ exports.mediaUrl = mediaUrl;
3136
3144
  exports.meilisearchService = meilisearchService;
3137
3145
  exports.menuService = menuService;
3138
3146
  exports.newsletterService = newsletterService;