@asteby/storefront 0.1.0 → 0.3.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/index.cjs +11 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -5
- package/dist/index.d.ts +18 -5
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/mock.cjs +25 -6
- package/dist/mock.cjs.map +1 -1
- package/dist/mock.d.cts +2 -1
- package/dist/mock.d.ts +2 -1
- package/dist/mock.js +25 -6
- package/dist/mock.js.map +1 -1
- package/dist/{types-BdaQ9Pxq.d.cts → types-CTXB8Dnl.d.cts} +97 -7
- package/dist/{types-BdaQ9Pxq.d.ts → types-CTXB8Dnl.d.ts} +97 -7
- package/package.json +1 -1
package/dist/mock.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
@@ -78,6 +78,7 @@ type MockState = {
|
|
|
78
78
|
status: number;
|
|
79
79
|
body: unknown;
|
|
80
80
|
}>;
|
|
81
|
+
checkouts: Map<string, unknown>;
|
|
81
82
|
seq: number;
|
|
82
83
|
};
|
|
83
84
|
declare function createMockStorefront(options?: MockStorefrontOptions): {
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
@@ -78,6 +78,7 @@ type MockState = {
|
|
|
78
78
|
status: number;
|
|
79
79
|
body: unknown;
|
|
80
80
|
}>;
|
|
81
|
+
checkouts: Map<string, unknown>;
|
|
81
82
|
seq: number;
|
|
82
83
|
};
|
|
83
84
|
declare function createMockStorefront(options?: MockStorefrontOptions): {
|
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 >
|
|
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;
|
|
@@ -360,6 +360,7 @@ function createMockStorefront(options = {}) {
|
|
|
360
360
|
otps: /* @__PURE__ */ new Map(),
|
|
361
361
|
sessions: /* @__PURE__ */ new Map(),
|
|
362
362
|
idempotency: /* @__PURE__ */ new Map(),
|
|
363
|
+
checkouts: /* @__PURE__ */ new Map(),
|
|
363
364
|
seq: 0
|
|
364
365
|
};
|
|
365
366
|
}
|
|
@@ -634,7 +635,7 @@ function createMockStorefront(options = {}) {
|
|
|
634
635
|
const nodes = skus.flatMap((sku) => {
|
|
635
636
|
for (const p of state.products) {
|
|
636
637
|
const v = p.variants.find((x) => x.sku === sku);
|
|
637
|
-
if (v) return [{ sku, quantity_available: v.quantity_available
|
|
638
|
+
if (v) return [{ sku, quantity_available: v.quantity_available }];
|
|
638
639
|
}
|
|
639
640
|
return [];
|
|
640
641
|
});
|
|
@@ -711,10 +712,14 @@ function createMockStorefront(options = {}) {
|
|
|
711
712
|
const cart = renderCart(getCartRecord(params[0]));
|
|
712
713
|
const net = toCents(cart.cost.subtotal.amount) - toCents(cart.cost.discount.amount);
|
|
713
714
|
return {
|
|
714
|
-
body: { rates: shippingRates(net), pickup: state.shop.branches.map((b) => ({ branch_id: b.id, name: b.name })) },
|
|
715
|
+
body: { rates: shippingRates(net), pickup: state.shop.branches.map((b) => ({ branch_id: b.id, name: b.name })), partial: false, unavailable: [] },
|
|
715
716
|
cache: "private"
|
|
716
717
|
};
|
|
717
718
|
});
|
|
719
|
+
route("GET", "/carts/:id/payment-methods", "cart:write", ({ params }) => {
|
|
720
|
+
getCartRecord(params[0]);
|
|
721
|
+
return { body: { methods: [{ key: "mock", kind: "builtin", default: true }], market: null }, cache: "private" };
|
|
722
|
+
});
|
|
718
723
|
route("PUT", "/carts/:id/delivery", "cart:write", ({ params, body }) => {
|
|
719
724
|
const cart = getCartRecord(params[0]);
|
|
720
725
|
if (body.method === "shipping") {
|
|
@@ -782,13 +787,27 @@ function createMockStorefront(options = {}) {
|
|
|
782
787
|
});
|
|
783
788
|
const redirect = new URL(`https://mock.local/pay/${orderId}`);
|
|
784
789
|
redirect.searchParams.set("return_url", body.return_url);
|
|
790
|
+
const checkoutId = nextId("chk");
|
|
785
791
|
const result = {
|
|
786
792
|
order: { id: orderId, number },
|
|
787
|
-
payment: { provider: "mock", status: "pending", redirect_url: redirect.toString(), client_secret: null }
|
|
793
|
+
payment: { provider: "mock", status: "pending", redirect_url: redirect.toString(), client_secret: null, instructions: null },
|
|
794
|
+
checkout: {
|
|
795
|
+
id: checkoutId,
|
|
796
|
+
status: "pending",
|
|
797
|
+
external_order_id: orderId,
|
|
798
|
+
total: cart.cost.total,
|
|
799
|
+
stock_hold_expires_at: new Date(Date.now() + 30 * 6e4).toISOString()
|
|
800
|
+
}
|
|
788
801
|
};
|
|
802
|
+
state.checkouts.set(checkoutId, result);
|
|
789
803
|
if (key) state.idempotency.set(`${params[0]}:${key}`, { status: 201, body: result });
|
|
790
804
|
return { status: 201, body: result, cache: "private" };
|
|
791
805
|
});
|
|
806
|
+
route("GET", "/checkouts/:id", "checkout:write", ({ params }) => {
|
|
807
|
+
const found = state.checkouts.get(params[0]);
|
|
808
|
+
if (!found) throw new HttpError(404, "not_found", "Checkout not found");
|
|
809
|
+
return { body: found, cache: "private" };
|
|
810
|
+
});
|
|
792
811
|
route("POST", "/customer/otp", "customer:write", ({ body }) => {
|
|
793
812
|
state.otps.set(identifierOf(body), otpCode);
|
|
794
813
|
return { status: 204 };
|
|
@@ -887,7 +906,7 @@ function createMockStorefront(options = {}) {
|
|
|
887
906
|
if (tag) items = items.filter((a) => a.tags.includes(tag));
|
|
888
907
|
const q = search.get("q")?.toLowerCase();
|
|
889
908
|
if (q) items = items.filter((a) => `${a.title} ${a.excerpt ?? ""}`.toLowerCase().includes(q));
|
|
890
|
-
return { body: paginate(items, search, 10), cache: "public" };
|
|
909
|
+
return { body: paginate(items, search, 10, 50), cache: "public" };
|
|
891
910
|
});
|
|
892
911
|
route("GET", "/content/articles/:handle", "content:read", ({ params, search }) => ({
|
|
893
912
|
body: requireNode(state.articles.find((a) => a.handle === params[0]), `Article ${params[0]}`),
|