@asteby/storefront 0.1.0 → 0.2.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 { _ as Shop, K as Product, o as Collection, a5 as Theme, P as Page, M as Menu, b as Article, C as Cart, A as Address, q as Customer, O as Order } from './types-BdaQ9Pxq.cjs';
1
+ import { a1 as Shop, Q as Product, p as Collection, a8 as Theme, P as Page, M as Menu, b as Article, C as Cart, A as Address, r as Customer, O as Order } from './types-CTXB8Dnl.cjs';
2
2
 
3
3
  /**
4
4
  * Placeholder image source for all seed data. Swap it (or pass `imageUrl` to
package/dist/mock.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Shop, K as Product, o as Collection, a5 as Theme, P as Page, M as Menu, b as Article, C as Cart, A as Address, q as Customer, O as Order } from './types-BdaQ9Pxq.js';
1
+ import { a1 as Shop, Q as Product, p as Collection, a8 as Theme, P as Page, M as Menu, b as Article, C as Cart, A as Address, r as Customer, O as Order } from './types-CTXB8Dnl.js';
2
2
 
3
3
  /**
4
4
  * Placeholder image source for all seed data. Swap it (or pass `imageUrl` to
package/dist/mock.js CHANGED
@@ -309,9 +309,9 @@ function decodeCursor(cursor) {
309
309
  throw new HttpError(400, "validation", "Invalid cursor", "after");
310
310
  }
311
311
  }
312
- function paginate(items, search, defaultFirst = 24) {
312
+ function paginate(items, search, defaultFirst = 24, maxFirst = 100) {
313
313
  const first = search.has("first") ? Number(search.get("first")) : defaultFirst;
314
- if (!Number.isInteger(first) || first < 1 || first > 100) throw new HttpError(400, "validation", "`first` must be between 1 and 100", "first");
314
+ if (!Number.isInteger(first) || first < 1 || first > maxFirst) throw new HttpError(400, "validation", `\`first\` must be between 1 and ${maxFirst}`, "first");
315
315
  const start = decodeCursor(search.get("after"));
316
316
  const nodes = items.slice(start, start + first);
317
317
  const end = start + nodes.length;
@@ -634,7 +634,7 @@ function createMockStorefront(options = {}) {
634
634
  const nodes = skus.flatMap((sku) => {
635
635
  for (const p of state.products) {
636
636
  const v = p.variants.find((x) => x.sku === sku);
637
- if (v) return [{ sku, quantity_available: v.quantity_available ?? 0 }];
637
+ if (v) return [{ sku, quantity_available: v.quantity_available }];
638
638
  }
639
639
  return [];
640
640
  });
@@ -711,10 +711,14 @@ function createMockStorefront(options = {}) {
711
711
  const cart = renderCart(getCartRecord(params[0]));
712
712
  const net = toCents(cart.cost.subtotal.amount) - toCents(cart.cost.discount.amount);
713
713
  return {
714
- body: { rates: shippingRates(net), pickup: state.shop.branches.map((b) => ({ branch_id: b.id, name: b.name })) },
714
+ body: { rates: shippingRates(net), pickup: state.shop.branches.map((b) => ({ branch_id: b.id, name: b.name })), partial: false, unavailable: [] },
715
715
  cache: "private"
716
716
  };
717
717
  });
718
+ route("GET", "/carts/:id/payment-methods", "cart:write", ({ params }) => {
719
+ getCartRecord(params[0]);
720
+ return { body: { methods: [{ key: "mock", kind: "builtin", default: true }], market: null }, cache: "private" };
721
+ });
718
722
  route("PUT", "/carts/:id/delivery", "cart:write", ({ params, body }) => {
719
723
  const cart = getCartRecord(params[0]);
720
724
  if (body.method === "shipping") {
@@ -782,9 +786,17 @@ function createMockStorefront(options = {}) {
782
786
  });
783
787
  const redirect = new URL(`https://mock.local/pay/${orderId}`);
784
788
  redirect.searchParams.set("return_url", body.return_url);
789
+ const checkoutId = nextId("chk");
785
790
  const result = {
786
791
  order: { id: orderId, number },
787
- payment: { provider: "mock", status: "pending", redirect_url: redirect.toString(), client_secret: null }
792
+ payment: { provider: "mock", status: "pending", redirect_url: redirect.toString(), client_secret: null, instructions: null },
793
+ checkout: {
794
+ id: checkoutId,
795
+ status: "pending",
796
+ external_order_id: orderId,
797
+ total: cart.cost.total,
798
+ stock_hold_expires_at: new Date(Date.now() + 30 * 6e4).toISOString()
799
+ }
788
800
  };
789
801
  if (key) state.idempotency.set(`${params[0]}:${key}`, { status: 201, body: result });
790
802
  return { status: 201, body: result, cache: "private" };
@@ -887,7 +899,7 @@ function createMockStorefront(options = {}) {
887
899
  if (tag) items = items.filter((a) => a.tags.includes(tag));
888
900
  const q = search.get("q")?.toLowerCase();
889
901
  if (q) items = items.filter((a) => `${a.title} ${a.excerpt ?? ""}`.toLowerCase().includes(q));
890
- return { body: paginate(items, search, 10), cache: "public" };
902
+ return { body: paginate(items, search, 10, 50), cache: "public" };
891
903
  });
892
904
  route("GET", "/content/articles/:handle", "content:read", ({ params, search }) => ({
893
905
  body: requireNode(state.articles.find((a) => a.handle === params[0]), `Article ${params[0]}`),