@moonbase.sh/vue 0.3.8 → 0.3.10

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
@@ -291,6 +291,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
291
291
  if (!this.currentOrder.value.currency) {
292
292
  this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
293
293
  }
294
+ this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
294
295
  }
295
296
  return latestStorefront;
296
297
  }
@@ -335,6 +336,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
335
336
  if (latestOrder.status !== import_storefront_api2.OrderStatus.Open) {
336
337
  this.resetOrder();
337
338
  } else {
339
+ latestOrder.items = this.enrichLineItems(latestOrder.items);
338
340
  if (typeof window !== "undefined")
339
341
  localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
340
342
  this.currentOrder.value = latestOrder;
@@ -367,6 +369,37 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
367
369
  console.warn("Could not surrender order:", err);
368
370
  }
369
371
  }
372
+ enrichLineItems(lineItems) {
373
+ if (this.storefront) {
374
+ return lineItems.map((item) => {
375
+ var _a, _b;
376
+ if (item.type === "Product") {
377
+ const product = this.storefront.value.products.find((p) => p.id === item.productId);
378
+ const variations = (product == null ? void 0 : product.variations) || [];
379
+ const variation = variations.find((v) => v.id === item.variationId);
380
+ return {
381
+ ...item,
382
+ product,
383
+ variation,
384
+ price: variation == null ? void 0 : variation.price,
385
+ appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
386
+ };
387
+ } else {
388
+ const bundle = this.storefront.value.bundles.find((b) => b.id === item.bundleId);
389
+ const variations = (bundle == null ? void 0 : bundle.variations) || [];
390
+ const variation = variations.find((v) => v.id === item.variationId);
391
+ return {
392
+ ...item,
393
+ bundle,
394
+ variation,
395
+ price: variation == null ? void 0 : variation.price,
396
+ appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
397
+ };
398
+ }
399
+ });
400
+ }
401
+ return lineItems;
402
+ }
370
403
  };
371
404
  _StorefrontContextImpl.userKey = "moonbase_user";
372
405
  _StorefrontContextImpl.sessionKey = "moonbase_session";
@@ -592,32 +625,7 @@ function useCart(context) {
592
625
  return { amount: total2, currency };
593
626
  });
594
627
  return {
595
- items: (0, import_vue6.computed)(() => storefront.currentOrder.value.items.map((item) => {
596
- var _a, _b;
597
- if (item.type === "Product") {
598
- const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
599
- const variations = (product == null ? void 0 : product.variations) || [];
600
- const variation = variations.find((v) => v.id === item.variationId);
601
- return {
602
- ...item,
603
- product,
604
- variation,
605
- price: variation == null ? void 0 : variation.price,
606
- appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
607
- };
608
- } else {
609
- const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
610
- const variations = (bundle == null ? void 0 : bundle.variations) || [];
611
- const variation = variations.find((v) => v.id === item.variationId);
612
- return {
613
- ...item,
614
- bundle,
615
- variation,
616
- price: variation == null ? void 0 : variation.price,
617
- appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
618
- };
619
- }
620
- })),
628
+ items: (0, import_vue6.computed)(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
621
629
  currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
622
630
  total,
623
631
  addToCart: (item, variation) => {
@@ -700,6 +708,7 @@ function useCart(context) {
700
708
  const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
701
709
  returnUrl: absoluteReturnUrl
702
710
  }, storefront.hasUtm ? storefront.utm.value : void 0);
711
+ updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
703
712
  window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
704
713
  detail: { order: updatedOrder, total: total.value }
705
714
  }));
@@ -775,6 +784,7 @@ async function useCheckout(items, options, context) {
775
784
  }, {
776
785
  returnUrl: absoluteReturnUrl
777
786
  }, storefront.hasUtm ? storefront.utm.value : void 0);
787
+ updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
778
788
  window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
779
789
  detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
780
790
  var _a2, _b2;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
2
- import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
2
+ import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor } from '@moonbase.sh/storefront-api';
3
3
  export * from '@moonbase.sh/storefront-api';
4
4
  import * as vue from 'vue';
5
- import { Plugin, Ref, App, UnwrapRef, InjectionKey } from 'vue';
5
+ import { Ref, UnwrapRef, Plugin, App, InjectionKey } from 'vue';
6
6
 
7
7
  interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
8
8
  configuration: MoonbaseConfiguration;
@@ -22,6 +22,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
22
22
  pushOrderContent: () => Promise<void>;
23
23
  resetOrder: () => void;
24
24
  surrenderOrder: () => Promise<void>;
25
+ enrichLineItems: (lineItems: LineItem[]) => LineItem[];
25
26
  closeCheckout: () => void;
26
27
  onCheckoutInitiated: (callback: (order: OpenOrder, total: Money) => void) => void;
27
28
  onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
2
- import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor, LineItem } from '@moonbase.sh/storefront-api';
2
+ import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, LineItem, OpenOrder, Money, CompletedOrder, ActivationRequest, Address, CommunicationPreferences, StorefrontBundle, StorefrontProduct, PricingVariation, ActivationMethod, Activation, Download, Vendor } from '@moonbase.sh/storefront-api';
3
3
  export * from '@moonbase.sh/storefront-api';
4
4
  import * as vue from 'vue';
5
- import { Plugin, Ref, App, UnwrapRef, InjectionKey } from 'vue';
5
+ import { Ref, UnwrapRef, Plugin, App, InjectionKey } from 'vue';
6
6
 
7
7
  interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
8
8
  configuration: MoonbaseConfiguration;
@@ -22,6 +22,7 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
22
22
  pushOrderContent: () => Promise<void>;
23
23
  resetOrder: () => void;
24
24
  surrenderOrder: () => Promise<void>;
25
+ enrichLineItems: (lineItems: LineItem[]) => LineItem[];
25
26
  closeCheckout: () => void;
26
27
  onCheckoutInitiated: (callback: (order: OpenOrder, total: Money) => void) => void;
27
28
  onCheckoutCompleted: (callback: (order: CompletedOrder) => void) => void;
package/dist/index.js CHANGED
@@ -261,6 +261,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
261
261
  if (!this.currentOrder.value.currency) {
262
262
  this.currentOrder.value.currency = latestStorefront.suggestedCurrency;
263
263
  }
264
+ this.currentOrder.value.items = this.enrichLineItems(this.currentOrder.value.items);
264
265
  }
265
266
  return latestStorefront;
266
267
  }
@@ -305,6 +306,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
305
306
  if (latestOrder.status !== OrderStatus.Open) {
306
307
  this.resetOrder();
307
308
  } else {
309
+ latestOrder.items = this.enrichLineItems(latestOrder.items);
308
310
  if (typeof window !== "undefined")
309
311
  localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
310
312
  this.currentOrder.value = latestOrder;
@@ -337,6 +339,37 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
337
339
  console.warn("Could not surrender order:", err);
338
340
  }
339
341
  }
342
+ enrichLineItems(lineItems) {
343
+ if (this.storefront) {
344
+ return lineItems.map((item) => {
345
+ var _a, _b;
346
+ if (item.type === "Product") {
347
+ const product = this.storefront.value.products.find((p) => p.id === item.productId);
348
+ const variations = (product == null ? void 0 : product.variations) || [];
349
+ const variation = variations.find((v) => v.id === item.variationId);
350
+ return {
351
+ ...item,
352
+ product,
353
+ variation,
354
+ price: variation == null ? void 0 : variation.price,
355
+ appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
356
+ };
357
+ } else {
358
+ const bundle = this.storefront.value.bundles.find((b) => b.id === item.bundleId);
359
+ const variations = (bundle == null ? void 0 : bundle.variations) || [];
360
+ const variation = variations.find((v) => v.id === item.variationId);
361
+ return {
362
+ ...item,
363
+ bundle,
364
+ variation,
365
+ price: variation == null ? void 0 : variation.price,
366
+ appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
367
+ };
368
+ }
369
+ });
370
+ }
371
+ return lineItems;
372
+ }
340
373
  };
341
374
  _StorefrontContextImpl.userKey = "moonbase_user";
342
375
  _StorefrontContextImpl.sessionKey = "moonbase_session";
@@ -562,32 +595,7 @@ function useCart(context) {
562
595
  return { amount: total2, currency };
563
596
  });
564
597
  return {
565
- items: computed4(() => storefront.currentOrder.value.items.map((item) => {
566
- var _a, _b;
567
- if (item.type === "Product") {
568
- const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
569
- const variations = (product == null ? void 0 : product.variations) || [];
570
- const variation = variations.find((v) => v.id === item.variationId);
571
- return {
572
- ...item,
573
- product,
574
- variation,
575
- price: variation == null ? void 0 : variation.price,
576
- appliedDiscount: (_a = variation == null ? void 0 : variation.discount) != null ? _a : item.appliedDiscount
577
- };
578
- } else {
579
- const bundle = storefront.storefront.value.bundles.find((b) => b.id === item.bundleId);
580
- const variations = (bundle == null ? void 0 : bundle.variations) || [];
581
- const variation = variations.find((v) => v.id === item.variationId);
582
- return {
583
- ...item,
584
- bundle,
585
- variation,
586
- price: variation == null ? void 0 : variation.price,
587
- appliedDiscount: (_b = variation == null ? void 0 : variation.discount) != null ? _b : item.appliedDiscount
588
- };
589
- }
590
- })),
598
+ items: computed4(() => storefront.enrichLineItems(storefront.currentOrder.value.items)),
591
599
  currency: computed4(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
592
600
  total,
593
601
  addToCart: (item, variation) => {
@@ -670,6 +678,7 @@ function useCart(context) {
670
678
  const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
671
679
  returnUrl: absoluteReturnUrl
672
680
  }, storefront.hasUtm ? storefront.utm.value : void 0);
681
+ updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
673
682
  window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
674
683
  detail: { order: updatedOrder, total: total.value }
675
684
  }));
@@ -745,6 +754,7 @@ async function useCheckout(items, options, context) {
745
754
  }, {
746
755
  returnUrl: absoluteReturnUrl
747
756
  }, storefront.hasUtm ? storefront.utm.value : void 0);
757
+ updatedOrder.items = storefront.enrichLineItems(updatedOrder.items);
748
758
  window.dispatchEvent(new CustomEvent("moonbase-checkout-initiated", {
749
759
  detail: { order: updatedOrder, total: { amount: items.reduce((a, item) => {
750
760
  var _a2, _b2;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.3.8",
4
+ "version": "0.3.10",
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.3.8"
22
+ "@moonbase.sh/storefront-api": "0.3.10"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",