@moonbase.sh/vue 0.4.27 → 0.4.32

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/dist/index.cjs CHANGED
@@ -365,13 +365,14 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
365
365
  return this.currentUser.value;
366
366
  }
367
367
  async updateStorefront() {
368
+ var _a;
368
369
  const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
369
370
  if (latestStorefront) {
370
371
  if (typeof window !== "undefined")
371
372
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
372
373
  this.storefront.value = latestStorefront;
373
374
  this.loadedStorefront.value = true;
374
- if (!this.currentOrder.value.currency || !latestStorefront.enabledCurrencies.includes(this.currentOrder.value.currency)) {
375
+ if (!this.currentOrder.value.currency || !((_a = latestStorefront.enabledCurrencies) == null ? void 0 : _a.includes(this.currentOrder.value.currency))) {
375
376
  this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
376
377
  }
377
378
  this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
@@ -413,6 +414,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
413
414
  }
414
415
  }
415
416
  async refreshOrder() {
417
+ var _a;
416
418
  try {
417
419
  const latestOrder = await this.client.orders.get(this.currentOrder.value.id, { abort: this.refreshOrderAbortController.signal });
418
420
  if (latestOrder) {
@@ -422,7 +424,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
422
424
  latestOrder.items = this.enrichLineItems(latestOrder.items);
423
425
  if (typeof window !== "undefined")
424
426
  localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
425
- if (this.storefront.value && !this.storefront.value.enabledCurrencies.includes(latestOrder.currency)) {
427
+ if (this.storefront.value && !((_a = this.storefront.value.enabledCurrencies) == null ? void 0 : _a.includes(latestOrder.currency))) {
426
428
  latestOrder.currency = this.storefront.value.suggestedCurrency;
427
429
  }
428
430
  this.currentOrder.value = latestOrder;
@@ -711,7 +713,7 @@ function useCart(context) {
711
713
  const pickedVariation = variations.find((v) => v.id === item.variationId);
712
714
  price = (_i = (_h = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _h : (_g = bundle == null ? void 0 : bundle.defaultVariation) == null ? void 0 : _g.price[currency]) != null ? _i : 0;
713
715
  }
714
- const offer = (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId);
716
+ const offer = item.offerId ? (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId) : null;
715
717
  if (offer && import_storefront_api4.OfferUtils.eligible(offer, storefront.currentOrder.value)) {
716
718
  const offerDiscount = import_storefront_api4.DiscountUtils.apply(offer.discount, { [currency]: price });
717
719
  price -= offerDiscount[currency];
@@ -790,13 +792,15 @@ function useCart(context) {
790
792
  }
791
793
  function addReplacedBundleProducts(cartItem) {
792
794
  var _a, _b;
795
+ if (!storefront)
796
+ return;
793
797
  if (cartItem.type === "Bundle" && cartItem.replaced && cartItem.replaced.length > 0) {
794
798
  for (const { productId, variationId } of cartItem.replaced.map((composite) => ({ productId: composite.split("/")[0], variationId: composite.split("/")[1] }))) {
795
- const product = storefront == null ? void 0 : storefront.storefront.value.products.find((p) => p.id === productId);
799
+ const product = storefront.storefront.value.products.find((p) => p.id === productId);
796
800
  const variation = (_a = product == null ? void 0 : product.variations) == null ? void 0 : _a.find((v) => v.id === variationId);
797
- if (product && variation && !(storefront == null ? void 0 : storefront.currentOrder.value.items.some((i) => i.type === "Product" && i.productId === productId))) {
801
+ if (product && variation && !storefront.currentOrder.value.items.some((i) => i.type === "Product" && i.productId === productId)) {
798
802
  const id = `p/${product.id}/${variationId}`;
799
- storefront == null ? void 0 : storefront.currentOrder.value.items.push({
803
+ storefront.currentOrder.value.items.push({
800
804
  id,
801
805
  type: "Product",
802
806
  productId: product.id,
@@ -813,6 +817,19 @@ function useCart(context) {
813
817
  }
814
818
  }
815
819
  }
820
+ function pruneIneligibleOffers() {
821
+ var _a;
822
+ if (!storefront)
823
+ return;
824
+ for (const item of storefront.currentOrder.value.items) {
825
+ if (item.offerId) {
826
+ const offer = (_a = storefront.storefront.value.offers) == null ? void 0 : _a.find((o) => o.id === item.offerId);
827
+ if (!offer || !import_storefront_api4.OfferUtils.eligible(offer, storefront.currentOrder.value)) {
828
+ item.offerId = void 0;
829
+ }
830
+ }
831
+ }
832
+ }
816
833
  return {
817
834
  items: (0, import_vue6.computed)(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
818
835
  currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
@@ -827,6 +844,7 @@ function useCart(context) {
827
844
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItemRef.id);
828
845
  storefront.currentOrder.value.items.splice(index, 1);
829
846
  addReplacedBundleProducts(cartItem);
847
+ pruneIneligibleOffers();
830
848
  }
831
849
  const _ = storefront.pushOrderContent();
832
850
  return cartItem;
@@ -835,6 +853,7 @@ function useCart(context) {
835
853
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItem.id);
836
854
  storefront.currentOrder.value.items.splice(index, 1);
837
855
  addReplacedBundleProducts(cartItem);
856
+ pruneIneligibleOffers();
838
857
  const _ = storefront.pushOrderContent();
839
858
  },
840
859
  checkout: async (options) => {
package/dist/index.js CHANGED
@@ -333,13 +333,14 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
333
333
  return this.currentUser.value;
334
334
  }
335
335
  async updateStorefront() {
336
+ var _a;
336
337
  const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
337
338
  if (latestStorefront) {
338
339
  if (typeof window !== "undefined")
339
340
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
340
341
  this.storefront.value = latestStorefront;
341
342
  this.loadedStorefront.value = true;
342
- if (!this.currentOrder.value.currency || !latestStorefront.enabledCurrencies.includes(this.currentOrder.value.currency)) {
343
+ if (!this.currentOrder.value.currency || !((_a = latestStorefront.enabledCurrencies) == null ? void 0 : _a.includes(this.currentOrder.value.currency))) {
343
344
  this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
344
345
  }
345
346
  this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
@@ -381,6 +382,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
381
382
  }
382
383
  }
383
384
  async refreshOrder() {
385
+ var _a;
384
386
  try {
385
387
  const latestOrder = await this.client.orders.get(this.currentOrder.value.id, { abort: this.refreshOrderAbortController.signal });
386
388
  if (latestOrder) {
@@ -390,7 +392,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
390
392
  latestOrder.items = this.enrichLineItems(latestOrder.items);
391
393
  if (typeof window !== "undefined")
392
394
  localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
393
- if (this.storefront.value && !this.storefront.value.enabledCurrencies.includes(latestOrder.currency)) {
395
+ if (this.storefront.value && !((_a = this.storefront.value.enabledCurrencies) == null ? void 0 : _a.includes(latestOrder.currency))) {
394
396
  latestOrder.currency = this.storefront.value.suggestedCurrency;
395
397
  }
396
398
  this.currentOrder.value = latestOrder;
@@ -679,7 +681,7 @@ function useCart(context) {
679
681
  const pickedVariation = variations.find((v) => v.id === item.variationId);
680
682
  price = (_i = (_h = pickedVariation == null ? void 0 : pickedVariation.price[currency]) != null ? _h : (_g = bundle == null ? void 0 : bundle.defaultVariation) == null ? void 0 : _g.price[currency]) != null ? _i : 0;
681
683
  }
682
- const offer = (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId);
684
+ const offer = item.offerId ? (_j = storefront.storefront.value.offers) == null ? void 0 : _j.find((o) => o.id === item.offerId) : null;
683
685
  if (offer && OfferUtils2.eligible(offer, storefront.currentOrder.value)) {
684
686
  const offerDiscount = DiscountUtils.apply(offer.discount, { [currency]: price });
685
687
  price -= offerDiscount[currency];
@@ -758,13 +760,15 @@ function useCart(context) {
758
760
  }
759
761
  function addReplacedBundleProducts(cartItem) {
760
762
  var _a, _b;
763
+ if (!storefront)
764
+ return;
761
765
  if (cartItem.type === "Bundle" && cartItem.replaced && cartItem.replaced.length > 0) {
762
766
  for (const { productId, variationId } of cartItem.replaced.map((composite) => ({ productId: composite.split("/")[0], variationId: composite.split("/")[1] }))) {
763
- const product = storefront == null ? void 0 : storefront.storefront.value.products.find((p) => p.id === productId);
767
+ const product = storefront.storefront.value.products.find((p) => p.id === productId);
764
768
  const variation = (_a = product == null ? void 0 : product.variations) == null ? void 0 : _a.find((v) => v.id === variationId);
765
- if (product && variation && !(storefront == null ? void 0 : storefront.currentOrder.value.items.some((i) => i.type === "Product" && i.productId === productId))) {
769
+ if (product && variation && !storefront.currentOrder.value.items.some((i) => i.type === "Product" && i.productId === productId)) {
766
770
  const id = `p/${product.id}/${variationId}`;
767
- storefront == null ? void 0 : storefront.currentOrder.value.items.push({
771
+ storefront.currentOrder.value.items.push({
768
772
  id,
769
773
  type: "Product",
770
774
  productId: product.id,
@@ -781,6 +785,19 @@ function useCart(context) {
781
785
  }
782
786
  }
783
787
  }
788
+ function pruneIneligibleOffers() {
789
+ var _a;
790
+ if (!storefront)
791
+ return;
792
+ for (const item of storefront.currentOrder.value.items) {
793
+ if (item.offerId) {
794
+ const offer = (_a = storefront.storefront.value.offers) == null ? void 0 : _a.find((o) => o.id === item.offerId);
795
+ if (!offer || !OfferUtils2.eligible(offer, storefront.currentOrder.value)) {
796
+ item.offerId = void 0;
797
+ }
798
+ }
799
+ }
800
+ }
784
801
  return {
785
802
  items: computed4(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
786
803
  currency: computed4(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
@@ -795,6 +812,7 @@ function useCart(context) {
795
812
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItemRef.id);
796
813
  storefront.currentOrder.value.items.splice(index, 1);
797
814
  addReplacedBundleProducts(cartItem);
815
+ pruneIneligibleOffers();
798
816
  }
799
817
  const _ = storefront.pushOrderContent();
800
818
  return cartItem;
@@ -803,6 +821,7 @@ function useCart(context) {
803
821
  const index = storefront.currentOrder.value.items.findIndex((i) => i.id === cartItem.id);
804
822
  storefront.currentOrder.value.items.splice(index, 1);
805
823
  addReplacedBundleProducts(cartItem);
824
+ pruneIneligibleOffers();
806
825
  const _ = storefront.pushOrderContent();
807
826
  },
808
827
  checkout: async (options) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.4.27",
4
+ "version": "0.4.32",
5
5
  "description": "Package to let you build vue.js storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "@vue/devtools-api": "^6.6.3",
20
20
  "uuid": "^9.0.1",
21
21
  "zod": "^3.23.8",
22
- "@moonbase.sh/storefront-api": "0.4.27"
22
+ "@moonbase.sh/storefront-api": "0.4.32"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",