@asteby/storefront 0.7.0 → 0.8.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.
package/dist/mock.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { aB as Shop, ah as Product, w as Collection, aI as Theme, $ as Page, U as Menu, b as Article, C as Cart, A as Address, y as Customer, Z as Order, a2 as PaymentAttemptResult, ao as PromotionAnnouncement } from './types-CSMuPSQA.cjs';
1
+ import { aB as Shop, ah as Product, w as Collection, aI as Theme, $ as Page, U as Menu, b as Article, C as Cart, A as Address, y as Customer, Z as Order, a2 as PaymentAttemptResult, ao as PromotionAnnouncement, aA as ShippingRate, a8 as PaymentMethod } from './types-CSMuPSQA.cjs';
2
2
  import './geo.cjs';
3
3
 
4
4
  /**
@@ -58,6 +58,13 @@ type MockStorefrontOptions = {
58
58
  announcements?: PromotionAnnouncement[];
59
59
  /** Payment attempts allowed per checkout before `429 too_many_attempts` (default 5). */
60
60
  maxPaymentAttempts?: number;
61
+ /**
62
+ * Carrier-style rates served by `delivery-options` instead of the flat / express pair (to design a checkout with
63
+ * carriers, ETAs and quote deadlines). `expires_at` missing: 24 h from the request. Free shipping still applies.
64
+ */
65
+ shippingRates?: ShippingRate[];
66
+ /** Methods served by `payment-methods` (default one builtin `mock`). */
67
+ paymentMethods?: PaymentMethod[];
61
68
  };
62
69
  type CartRecord = {
63
70
  id: string;
package/dist/mock.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { aB as Shop, ah as Product, w as Collection, aI as Theme, $ as Page, U as Menu, b as Article, C as Cart, A as Address, y as Customer, Z as Order, a2 as PaymentAttemptResult, ao as PromotionAnnouncement } from './types-iGGZ9EiC.js';
1
+ import { aB as Shop, ah as Product, w as Collection, aI as Theme, $ as Page, U as Menu, b as Article, C as Cart, A as Address, y as Customer, Z as Order, a2 as PaymentAttemptResult, ao as PromotionAnnouncement, aA as ShippingRate, a8 as PaymentMethod } from './types-iGGZ9EiC.js';
2
2
  import './geo.js';
3
3
 
4
4
  /**
@@ -58,6 +58,13 @@ type MockStorefrontOptions = {
58
58
  announcements?: PromotionAnnouncement[];
59
59
  /** Payment attempts allowed per checkout before `429 too_many_attempts` (default 5). */
60
60
  maxPaymentAttempts?: number;
61
+ /**
62
+ * Carrier-style rates served by `delivery-options` instead of the flat / express pair (to design a checkout with
63
+ * carriers, ETAs and quote deadlines). `expires_at` missing: 24 h from the request. Free shipping still applies.
64
+ */
65
+ shippingRates?: ShippingRate[];
66
+ /** Methods served by `payment-methods` (default one builtin `mock`). */
67
+ paymentMethods?: PaymentMethod[];
61
68
  };
62
69
  type CartRecord = {
63
70
  id: string;
package/dist/mock.js CHANGED
@@ -631,6 +631,10 @@ function createMockStorefront(options = {}) {
631
631
  function shippingRates(subtotalCents) {
632
632
  const freeMin = state.shop.policies.free_shipping_min;
633
633
  const free = freeMin !== null && subtotalCents >= toCents(freeMin.amount);
634
+ if (options.shippingRates?.length) {
635
+ const expires = new Date(Date.now() + 24 * 36e5).toISOString();
636
+ return options.shippingRates.map((r) => ({ ...r, expires_at: r.expires_at ?? expires, cost: free ? fromCents(0, r.cost.currency_code) : r.cost }));
637
+ }
634
638
  return [
635
639
  { id: "flat", title: free ? "Env\xEDo est\xE1ndar (gratis)" : "Env\xEDo est\xE1ndar", cost: fromCents(free ? 0 : flatShippingCents, currency), eta: "2 a 5 d\xEDas h\xE1biles" },
636
640
  { id: "express", title: "Env\xEDo expr\xE9s", cost: fromCents(flatShippingCents + 1e4, currency), eta: "1 a 2 d\xEDas h\xE1biles" }
@@ -862,7 +866,7 @@ function createMockStorefront(options = {}) {
862
866
  });
863
867
  route("GET", "/carts/:id/payment-methods", "cart:write", ({ params }) => {
864
868
  getCartRecord(params[0]);
865
- return { body: { methods: [{ key: "mock", kind: "builtin", default: true }], market: null }, cache: "private" };
869
+ return { body: { methods: options.paymentMethods ?? [{ key: "mock", kind: "builtin", default: true }], market: null }, cache: "private" };
866
870
  });
867
871
  route("PUT", "/carts/:id/delivery", "cart:write", ({ params, body }) => {
868
872
  const cart = getCartRecord(params[0]);