@fayz-ai/storefront 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/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/auth.d.ts +29 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/blocks.d.ts +6 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/components/CartDrawer.d.ts +3 -0
- package/dist/components/CartDrawer.d.ts.map +1 -0
- package/dist/components/CustomerAccountShell.d.ts +13 -0
- package/dist/components/CustomerAccountShell.d.ts.map +1 -0
- package/dist/components/FiltersPanel.d.ts +3 -0
- package/dist/components/FiltersPanel.d.ts.map +1 -0
- package/dist/components/OrderTrackingTimeline.d.ts +7 -0
- package/dist/components/OrderTrackingTimeline.d.ts.map +1 -0
- package/dist/components/Price.d.ts +11 -0
- package/dist/components/Price.d.ts.map +1 -0
- package/dist/components/ProductCard.d.ts +7 -0
- package/dist/components/ProductCard.d.ts.map +1 -0
- package/dist/components/ProductGrid.d.ts +7 -0
- package/dist/components/ProductGrid.d.ts.map +1 -0
- package/dist/components/ProductOptionSelector.d.ts +9 -0
- package/dist/components/ProductOptionSelector.d.ts.map +1 -0
- package/dist/components/ProductSpecs.d.ts +8 -0
- package/dist/components/ProductSpecs.d.ts.map +1 -0
- package/dist/components/QuantityInput.d.ts +12 -0
- package/dist/components/QuantityInput.d.ts.map +1 -0
- package/dist/components/RelatedProducts.d.ts +9 -0
- package/dist/components/RelatedProducts.d.ts.map +1 -0
- package/dist/components/SignInModal.d.ts +19 -0
- package/dist/components/SignInModal.d.ts.map +1 -0
- package/dist/components/StorefrontErrorBoundary.d.ts +20 -0
- package/dist/components/StorefrontErrorBoundary.d.ts.map +1 -0
- package/dist/components/StorefrontFooter.d.ts +3 -0
- package/dist/components/StorefrontFooter.d.ts.map +1 -0
- package/dist/components/StorefrontHeader.d.ts +3 -0
- package/dist/components/StorefrontHeader.d.ts.map +1 -0
- package/dist/components/Toaster.d.ts +3 -0
- package/dist/components/Toaster.d.ts.map +1 -0
- package/dist/components/sections/CategoryShowcase.d.ts +6 -0
- package/dist/components/sections/CategoryShowcase.d.ts.map +1 -0
- package/dist/components/sections/HeroSection.d.ts +9 -0
- package/dist/components/sections/HeroSection.d.ts.map +1 -0
- package/dist/components/sections/MiscSections.d.ts +33 -0
- package/dist/components/sections/MiscSections.d.ts.map +1 -0
- package/dist/components/sections/ProductRail.d.ts +9 -0
- package/dist/components/sections/ProductRail.d.ts.map +1 -0
- package/dist/config.d.ts +149 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/createStorefrontApp.d.ts +16 -0
- package/dist/createStorefrontApp.d.ts.map +1 -0
- package/dist/format.d.ts +3 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useCategories.d.ts +6 -0
- package/dist/hooks/useCategories.d.ts.map +1 -0
- package/dist/hooks/useDiscountValidator.d.ts +14 -0
- package/dist/hooks/useDiscountValidator.d.ts.map +1 -0
- package/dist/hooks/useMyOrders.d.ts +7 -0
- package/dist/hooks/useMyOrders.d.ts.map +1 -0
- package/dist/hooks/useProduct.d.ts +7 -0
- package/dist/hooks/useProduct.d.ts.map +1 -0
- package/dist/hooks/useProducts.d.ts +8 -0
- package/dist/hooks/useProducts.d.ts.map +1 -0
- package/dist/hooks/useStorefrontHead.d.ts +11 -0
- package/dist/hooks/useStorefrontHead.d.ts.map +1 -0
- package/dist/index.cjs +4186 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4085 -0
- package/dist/index.js.map +1 -0
- package/dist/motion.d.ts +19 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/order-status.d.ts +10 -0
- package/dist/order-status.d.ts.map +1 -0
- package/dist/pages/CatalogPage.d.ts +3 -0
- package/dist/pages/CatalogPage.d.ts.map +1 -0
- package/dist/pages/CheckoutPage.d.ts +3 -0
- package/dist/pages/CheckoutPage.d.ts.map +1 -0
- package/dist/pages/HomePage.d.ts +6 -0
- package/dist/pages/HomePage.d.ts.map +1 -0
- package/dist/pages/MyPurchasesPage.d.ts +3 -0
- package/dist/pages/MyPurchasesPage.d.ts.map +1 -0
- package/dist/pages/NotFoundPage.d.ts +4 -0
- package/dist/pages/NotFoundPage.d.ts.map +1 -0
- package/dist/pages/OrderConfirmationPage.d.ts +5 -0
- package/dist/pages/OrderConfirmationPage.d.ts.map +1 -0
- package/dist/pages/PolicyPage.d.ts +15 -0
- package/dist/pages/PolicyPage.d.ts.map +1 -0
- package/dist/pages/ProductDetailPage.d.ts +5 -0
- package/dist/pages/ProductDetailPage.d.ts.map +1 -0
- package/dist/presets.d.ts +33 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/product-options.d.ts +12 -0
- package/dist/product-options.d.ts.map +1 -0
- package/dist/router.d.ts +285 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/scaffold.d.ts +14 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/sections.d.ts +84 -0
- package/dist/sections.d.ts.map +1 -0
- package/dist/slot-contracts.d.ts +34 -0
- package/dist/slot-contracts.d.ts.map +1 -0
- package/dist/stores/cart.store.d.ts +58 -0
- package/dist/stores/cart.store.d.ts.map +1 -0
- package/dist/stores/catalog.store.d.ts +18 -0
- package/dist/stores/catalog.store.d.ts.map +1 -0
- package/dist/stores/session.store.d.ts +23 -0
- package/dist/stores/session.store.d.ts.map +1 -0
- package/dist/stores/toast.store.d.ts +27 -0
- package/dist/stores/toast.store.d.ts.map +1 -0
- package/dist/testids.d.ts +93 -0
- package/dist/testids.d.ts.map +1 -0
- package/dist/theme.d.ts +59 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/workflows/checkout.d.ts +33 -0
- package/dist/workflows/checkout.d.ts.map +1 -0
- package/package.json +56 -0
- package/src/auth.ts +134 -0
- package/src/blocks.tsx +47 -0
- package/src/components/CartDrawer.tsx +250 -0
- package/src/components/CustomerAccountShell.tsx +102 -0
- package/src/components/FiltersPanel.tsx +109 -0
- package/src/components/OrderTrackingTimeline.tsx +135 -0
- package/src/components/Price.tsx +32 -0
- package/src/components/ProductCard.tsx +104 -0
- package/src/components/ProductGrid.tsx +34 -0
- package/src/components/ProductOptionSelector.tsx +50 -0
- package/src/components/ProductSpecs.tsx +75 -0
- package/src/components/QuantityInput.tsx +52 -0
- package/src/components/RelatedProducts.tsx +31 -0
- package/src/components/SignInModal.tsx +120 -0
- package/src/components/StorefrontErrorBoundary.tsx +51 -0
- package/src/components/StorefrontFooter.tsx +100 -0
- package/src/components/StorefrontHeader.tsx +342 -0
- package/src/components/Toaster.tsx +60 -0
- package/src/components/sections/CategoryShowcase.tsx +79 -0
- package/src/components/sections/HeroSection.tsx +177 -0
- package/src/components/sections/MiscSections.tsx +157 -0
- package/src/components/sections/ProductRail.tsx +73 -0
- package/src/config.ts +176 -0
- package/src/createStorefrontApp.tsx +171 -0
- package/src/format.ts +7 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useCategories.ts +26 -0
- package/src/hooks/useDiscountValidator.ts +43 -0
- package/src/hooks/useMyOrders.ts +41 -0
- package/src/hooks/useProduct.ts +36 -0
- package/src/hooks/useProducts.ts +39 -0
- package/src/hooks/useStorefrontHead.ts +25 -0
- package/src/index.ts +132 -0
- package/src/motion.tsx +94 -0
- package/src/order-status.ts +33 -0
- package/src/pages/CatalogPage.tsx +118 -0
- package/src/pages/CheckoutPage.tsx +578 -0
- package/src/pages/HomePage.tsx +12 -0
- package/src/pages/MyPurchasesPage.tsx +310 -0
- package/src/pages/NotFoundPage.tsx +25 -0
- package/src/pages/OrderConfirmationPage.tsx +189 -0
- package/src/pages/PolicyPage.tsx +47 -0
- package/src/pages/ProductDetailPage.tsx +184 -0
- package/src/presets.ts +258 -0
- package/src/product-options.ts +63 -0
- package/src/router.ts +49 -0
- package/src/scaffold.tsx +109 -0
- package/src/sections.ts +69 -0
- package/src/slot-contracts.ts +20 -0
- package/src/stores/cart.store.ts +149 -0
- package/src/stores/catalog.store.ts +39 -0
- package/src/stores/session.store.ts +28 -0
- package/src/stores/toast.store.ts +43 -0
- package/src/testids.ts +103 -0
- package/src/theme.ts +160 -0
- package/src/workflows/checkout.ts +91 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getShopProvider } from '@fayz-ai/shop/runtime'
|
|
2
|
+
import type { Order } from '@fayz-ai/shop/types'
|
|
3
|
+
import { establishCustomerSession } from '../auth'
|
|
4
|
+
import type { ResolvedStorefrontConfig } from '../config'
|
|
5
|
+
import type { CartState } from '../stores/cart.store'
|
|
6
|
+
import { selectShipping } from '../stores/cart.store'
|
|
7
|
+
import type { SessionState } from '../stores/session.store'
|
|
8
|
+
|
|
9
|
+
export interface StorefrontCheckoutCustomer {
|
|
10
|
+
email: string
|
|
11
|
+
name: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface StorefrontCheckoutAddress {
|
|
15
|
+
street?: string
|
|
16
|
+
city?: string
|
|
17
|
+
zip?: string
|
|
18
|
+
notes?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PlaceStorefrontOrderInput {
|
|
22
|
+
config: ResolvedStorefrontConfig
|
|
23
|
+
cart: Pick<CartState, 'lines' | 'discountCode' | 'discountPercent'>
|
|
24
|
+
session?: Pick<SessionState, 'customerId' | 'email'>
|
|
25
|
+
customer: StorefrontCheckoutCustomer
|
|
26
|
+
address?: StorefrontCheckoutAddress
|
|
27
|
+
markPaid?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface PlaceStorefrontOrderResult {
|
|
31
|
+
order: Order
|
|
32
|
+
customerId: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatDeliveryNotes(address: StorefrontCheckoutAddress | undefined): string | undefined {
|
|
36
|
+
if (!address) return undefined
|
|
37
|
+
if (address.notes?.trim()) return address.notes.trim()
|
|
38
|
+
|
|
39
|
+
const parts = [address.street, address.city, address.zip]
|
|
40
|
+
.map((part) => part?.trim())
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
|
|
43
|
+
return parts.length > 0 ? `Entrega: ${parts.join(', ')}` : undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Storefront checkout primitive for custom/generated checkout screens.
|
|
48
|
+
* It owns the order payload math and customer-session handshake so app-owned
|
|
49
|
+
* routes can customize UX without copying provider/business logic.
|
|
50
|
+
*/
|
|
51
|
+
export async function placeStorefrontOrder({
|
|
52
|
+
config,
|
|
53
|
+
cart,
|
|
54
|
+
session,
|
|
55
|
+
customer,
|
|
56
|
+
address,
|
|
57
|
+
markPaid = false,
|
|
58
|
+
}: PlaceStorefrontOrderInput): Promise<PlaceStorefrontOrderResult> {
|
|
59
|
+
const email = customer.email.trim().toLowerCase()
|
|
60
|
+
const name = customer.name.trim()
|
|
61
|
+
const provider = getShopProvider()
|
|
62
|
+
|
|
63
|
+
let customerId = session?.customerId ?? null
|
|
64
|
+
if (!customerId || session?.email !== email) {
|
|
65
|
+
const established = await establishCustomerSession(email, { name })
|
|
66
|
+
customerId = established.customerId
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Trusted placement: send only product ids + quantities. The provider
|
|
70
|
+
// (shop_place_order RPC on Supabase, in-memory parity in mock) re-reads
|
|
71
|
+
// prices, validates the discount, and decrements inventory server-side.
|
|
72
|
+
const order = await provider.placeOrder({
|
|
73
|
+
customerId: customerId ?? undefined,
|
|
74
|
+
customer: { name, email },
|
|
75
|
+
currency: config.currency,
|
|
76
|
+
notes: formatDeliveryNotes(address),
|
|
77
|
+
discountCode: cart.discountCode ?? undefined,
|
|
78
|
+
shippingTotal: selectShipping(cart, config),
|
|
79
|
+
items: cart.lines.map((line) => ({
|
|
80
|
+
productId: line.productId,
|
|
81
|
+
quantity: line.quantity,
|
|
82
|
+
optionsLabel: line.optionsLabel || undefined,
|
|
83
|
+
})),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
if (markPaid) {
|
|
87
|
+
await provider.updateOrder(order.id, { financialStatus: 'paid' })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return { order, customerId: customerId ?? order.customerId ?? '' }
|
|
91
|
+
}
|