create-nymbal-app 0.4.0 → 0.6.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.
Files changed (175) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/index.js +14 -5
  3. package/dist/index.js.map +1 -1
  4. package/package.json +5 -4
  5. package/scaffold/project/astro/src/pages/index.astro +13 -15
  6. package/scaffold/templates/astro/_dot.node-version +1 -1
  7. package/scaffold/templates/astro/astro.config.mjs +23 -0
  8. package/scaffold/templates/astro/package.json +26 -26
  9. package/scaffold/templates/astro/src/components/SkipNav.astro +3 -1
  10. package/scaffold/templates/astro/src/elements/index.ts +11 -0
  11. package/scaffold/templates/astro/src/layouts/BaseLayout.astro +15 -4
  12. package/scaffold/templates/astro/src/lib/api.ts +162 -38
  13. package/scaffold/templates/astro/src/lib/chrome.ts +59 -0
  14. package/scaffold/templates/astro/src/lib/client.ts +4 -4
  15. package/scaffold/templates/astro/src/lib/fragments.ts +48 -0
  16. package/scaffold/templates/astro/src/lib/server-elements.ts +5 -0
  17. package/scaffold/templates/astro/src/middleware.ts +37 -0
  18. package/scaffold/templates/astro/src/pages/404.astro +3 -0
  19. package/scaffold/templates/astro/src/pages/account/addresses.astro +5 -97
  20. package/scaffold/templates/astro/src/pages/account/login.astro +7 -34
  21. package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +11 -3
  22. package/scaffold/templates/astro/src/pages/account/profile.astro +6 -56
  23. package/scaffold/templates/astro/src/pages/account/register.astro +7 -73
  24. package/scaffold/templates/astro/src/pages/alerts/confirm.astro +59 -0
  25. package/scaffold/templates/astro/src/pages/alerts/unsubscribe.astro +53 -0
  26. package/scaffold/templates/astro/src/pages/cart.astro +14 -7
  27. package/scaffold/templates/astro/src/pages/category/[slug].astro +25 -27
  28. package/scaffold/templates/astro/src/pages/checkout.astro +30 -94
  29. package/scaffold/templates/astro/src/pages/fragments/footer.astro +5 -2
  30. package/scaffold/templates/astro/src/pages/fragments/header.astro +12 -2
  31. package/scaffold/templates/astro/src/pages/fragments/nav.astro +8 -5
  32. package/scaffold/templates/astro/src/pages/fragments/product/[slug].astro +9 -10
  33. package/scaffold/templates/astro/src/pages/index.astro +25 -15
  34. package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +34 -45
  35. package/scaffold/templates/astro/src/pages/product/[slug].astro +64 -34
  36. package/scaffold/templates/astro/src/pages/products/index.astro +16 -21
  37. package/scaffold/templates/astro/src/pages/search.astro +10 -11
  38. package/scaffold/templates/astro/src/scripts/init-client.ts +14 -0
  39. package/scaffold/templates/astro/src/scripts/order-status.ts +3 -1
  40. package/scaffold/templates/astro/src/scripts/pdp.ts +29 -21
  41. package/scaffold/templates/astro/src/scripts/plp.ts +15 -93
  42. package/scaffold/templates/astro/src/scripts/search.ts +7 -132
  43. package/scaffold/templates/astro/src/scripts/signed-in-redirect.ts +4 -0
  44. package/scaffold/templates/astro/src/styles/global.css +49 -45
  45. package/scaffold/templates/astro/src/styles/pages/account.css +4 -90
  46. package/scaffold/templates/astro/src/styles/pages/confirmation.css +6 -0
  47. package/scaffold/templates/astro/src/styles/pages/home.css +9 -100
  48. package/scaffold/templates/astro/src/styles/pages/pdp.css +5 -171
  49. package/scaffold/templates/astro/src/styles/pages/plp.css +3 -42
  50. package/scaffold/templates/astro/src/styles/pages/search.css +4 -110
  51. package/scaffold/templates/astro/src/styles/tokens.css +56 -0
  52. package/scaffold/templates/nextjs/_dot.node-version +1 -1
  53. package/scaffold/templates/nextjs/app/(catalog)/category/[slug]/page.tsx +74 -0
  54. package/scaffold/templates/nextjs/app/(catalog)/home/[key]/page.tsx +85 -0
  55. package/scaffold/templates/nextjs/app/(catalog)/layout.tsx +13 -0
  56. package/scaffold/templates/nextjs/app/(catalog)/not-found.tsx +7 -0
  57. package/scaffold/templates/nextjs/app/(catalog)/product/[slug]/page.tsx +201 -0
  58. package/scaffold/templates/nextjs/app/(catalog)/products/page.tsx +62 -0
  59. package/scaffold/templates/nextjs/app/(catalog)/search/SearchView.tsx +90 -0
  60. package/scaffold/templates/nextjs/app/(catalog)/search/page.tsx +46 -0
  61. package/scaffold/templates/nextjs/app/(shopper)/account/addresses/AddressesView.tsx +5 -0
  62. package/scaffold/templates/nextjs/app/(shopper)/account/addresses/page.tsx +17 -0
  63. package/scaffold/templates/nextjs/app/(shopper)/account/login/LoginView.tsx +28 -0
  64. package/scaffold/templates/nextjs/app/(shopper)/account/login/page.tsx +23 -0
  65. package/scaffold/templates/nextjs/app/{account → (shopper)/account}/orders/[orderNumber]/page.tsx +10 -3
  66. package/scaffold/templates/nextjs/app/(shopper)/account/profile/ProfileView.tsx +5 -0
  67. package/scaffold/templates/nextjs/app/(shopper)/account/profile/page.tsx +20 -0
  68. package/scaffold/templates/nextjs/app/(shopper)/account/register/RegisterView.tsx +26 -0
  69. package/scaffold/templates/nextjs/app/(shopper)/account/register/page.tsx +11 -0
  70. package/scaffold/templates/nextjs/app/(shopper)/alerts/AlertLinkForm.tsx +90 -0
  71. package/scaffold/templates/nextjs/app/(shopper)/alerts/LinkInvalid.tsx +19 -0
  72. package/scaffold/templates/nextjs/app/(shopper)/alerts/actions.ts +33 -0
  73. package/scaffold/templates/nextjs/app/(shopper)/alerts/confirm/page.tsx +19 -0
  74. package/scaffold/templates/nextjs/app/(shopper)/alerts/unsubscribe/page.tsx +17 -0
  75. package/scaffold/templates/nextjs/app/(shopper)/cart/CartView.tsx +5 -0
  76. package/scaffold/templates/nextjs/app/(shopper)/cart/page.tsx +22 -0
  77. package/scaffold/templates/nextjs/app/(shopper)/checkout/CheckoutView.tsx +34 -0
  78. package/scaffold/templates/nextjs/app/(shopper)/checkout/page.tsx +39 -0
  79. package/scaffold/templates/nextjs/app/(shopper)/layout.tsx +12 -0
  80. package/scaffold/templates/nextjs/app/(shopper)/not-found.tsx +6 -0
  81. package/scaffold/templates/nextjs/app/{order → (shopper)/order}/[orderNumber]/page.tsx +44 -9
  82. package/scaffold/templates/nextjs/app/error.tsx +3 -7
  83. package/scaffold/templates/nextjs/app/fragments/footer/route.ts +13 -0
  84. package/scaffold/templates/nextjs/app/fragments/header/[key]/route.ts +18 -0
  85. package/scaffold/templates/nextjs/app/fragments/nav/[key]/route.ts +23 -0
  86. package/scaffold/templates/nextjs/app/fragments/product/[slug]/route.ts +22 -0
  87. package/scaffold/templates/nextjs/app/globals.css +5 -23
  88. package/scaffold/templates/nextjs/app/layout.tsx +8 -5
  89. package/scaffold/templates/nextjs/app/not-found.tsx +9 -33
  90. package/scaffold/templates/nextjs/app/tokens.css +56 -0
  91. package/scaffold/templates/nextjs/components/client/ListingControls.tsx +87 -0
  92. package/scaffold/templates/nextjs/components/client/NymbalSetup.tsx +48 -6
  93. package/scaffold/templates/nextjs/components/client/OrderStatusRefresh.tsx +8 -2
  94. package/scaffold/templates/nextjs/components/client/ProductInteractive.tsx +47 -15
  95. package/scaffold/templates/nextjs/components/client/elements.tsx +17 -0
  96. package/scaffold/templates/nextjs/components/server/Header.tsx +33 -102
  97. package/scaffold/templates/nextjs/components/server/NotFoundView.tsx +39 -0
  98. package/scaffold/templates/nextjs/components/server/SkipNav.tsx +7 -3
  99. package/scaffold/templates/nextjs/elements/index.ts +12 -0
  100. package/scaffold/templates/nextjs/lib/api.ts +198 -62
  101. package/scaffold/templates/nextjs/lib/chrome.ts +40 -0
  102. package/scaffold/templates/nextjs/lib/fragments.ts +16 -0
  103. package/scaffold/templates/nextjs/lib/header.ts +39 -0
  104. package/scaffold/templates/nextjs/lib/render.ts +14 -0
  105. package/scaffold/templates/nextjs/next.config.mjs +41 -0
  106. package/scaffold/templates/nextjs/package.json +28 -27
  107. package/scaffold/templates/nextjs/styles/pages/account.module.css +0 -70
  108. package/scaffold/templates/nextjs/styles/pages/confirmation.module.css +6 -85
  109. package/scaffold/templates/nextjs/styles/pages/home.module.css +2 -103
  110. package/scaffold/templates/nextjs/styles/pages/pdp.module.css +3 -183
  111. package/scaffold/templates/nextjs/styles/pages/plp.module.css +9 -143
  112. package/scaffold/templates/nextjs/styles/pages/search.module.css +1 -145
  113. package/scaffold/templates/nextjs/tsconfig.dist.json +5 -0
  114. package/scaffold/templates/astro/src/components/AddressForm.astro +0 -107
  115. package/scaffold/templates/astro/src/components/Breadcrumb.astro +0 -20
  116. package/scaffold/templates/astro/src/components/CategoryNav.astro +0 -27
  117. package/scaffold/templates/astro/src/components/CheckoutSteps.astro +0 -29
  118. package/scaffold/templates/astro/src/components/Footer.astro +0 -108
  119. package/scaffold/templates/astro/src/components/Header.astro +0 -198
  120. package/scaffold/templates/astro/src/components/ImageGallery.astro +0 -42
  121. package/scaffold/templates/astro/src/components/OrderSummary.astro +0 -53
  122. package/scaffold/templates/astro/src/components/Pagination.astro +0 -13
  123. package/scaffold/templates/astro/src/components/PriceDisplay.astro +0 -25
  124. package/scaffold/templates/astro/src/components/ProductCard.astro +0 -44
  125. package/scaffold/templates/astro/src/components/RelatedProducts.astro +0 -28
  126. package/scaffold/templates/astro/src/components/ReviewForm.astro +0 -74
  127. package/scaffold/templates/astro/src/components/ReviewList.astro +0 -41
  128. package/scaffold/templates/astro/src/components/StockBadge.astro +0 -15
  129. package/scaffold/templates/astro/src/scripts/auth-forms.ts +0 -82
  130. package/scaffold/templates/astro/src/scripts/cart-page.ts +0 -118
  131. package/scaffold/templates/astro/src/scripts/checkout.ts +0 -271
  132. package/scaffold/templates/astro/src/scripts/image-gallery.ts +0 -22
  133. package/scaffold/templates/astro/src/scripts/profile-form.ts +0 -57
  134. package/scaffold/templates/astro/src/scripts/review-form.ts +0 -27
  135. package/scaffold/templates/astro/src/styles/pages/cart.css +0 -215
  136. package/scaffold/templates/astro/src/styles/pages/checkout.css +0 -270
  137. package/scaffold/templates/nextjs/app/account/addresses/page.tsx +0 -10
  138. package/scaffold/templates/nextjs/app/account/login/page.tsx +0 -23
  139. package/scaffold/templates/nextjs/app/account/profile/page.tsx +0 -10
  140. package/scaffold/templates/nextjs/app/account/register/page.tsx +0 -10
  141. package/scaffold/templates/nextjs/app/cart/page.tsx +0 -10
  142. package/scaffold/templates/nextjs/app/category/[slug]/page.tsx +0 -61
  143. package/scaffold/templates/nextjs/app/checkout/page.tsx +0 -17
  144. package/scaffold/templates/nextjs/app/page.tsx +0 -63
  145. package/scaffold/templates/nextjs/app/product/[slug]/page.tsx +0 -111
  146. package/scaffold/templates/nextjs/app/products/page.tsx +0 -40
  147. package/scaffold/templates/nextjs/app/search/page.tsx +0 -24
  148. package/scaffold/templates/nextjs/components/client/AddressManager.tsx +0 -181
  149. package/scaffold/templates/nextjs/components/client/CartPage.tsx +0 -121
  150. package/scaffold/templates/nextjs/components/client/CheckoutForm.tsx +0 -482
  151. package/scaffold/templates/nextjs/components/client/ImageGallery.tsx +0 -68
  152. package/scaffold/templates/nextjs/components/client/LoginForm.tsx +0 -89
  153. package/scaffold/templates/nextjs/components/client/MiniCartWrapper.tsx +0 -12
  154. package/scaffold/templates/nextjs/components/client/ProductGrid.tsx +0 -137
  155. package/scaffold/templates/nextjs/components/client/ProfileForm.tsx +0 -112
  156. package/scaffold/templates/nextjs/components/client/RegisterForm.tsx +0 -131
  157. package/scaffold/templates/nextjs/components/client/ReviewForm.tsx +0 -116
  158. package/scaffold/templates/nextjs/components/client/SearchBarWrapper.tsx +0 -27
  159. package/scaffold/templates/nextjs/components/client/SearchResults.tsx +0 -181
  160. package/scaffold/templates/nextjs/components/server/Breadcrumb.tsx +0 -36
  161. package/scaffold/templates/nextjs/components/server/CategoryNav.tsx +0 -29
  162. package/scaffold/templates/nextjs/components/server/CheckoutSteps.tsx +0 -60
  163. package/scaffold/templates/nextjs/components/server/Footer.module.css +0 -64
  164. package/scaffold/templates/nextjs/components/server/Footer.tsx +0 -79
  165. package/scaffold/templates/nextjs/components/server/Header.module.css +0 -147
  166. package/scaffold/templates/nextjs/components/server/OrderSummary.tsx +0 -79
  167. package/scaffold/templates/nextjs/components/server/PriceDisplay.tsx +0 -31
  168. package/scaffold/templates/nextjs/components/server/ProductCard.tsx +0 -59
  169. package/scaffold/templates/nextjs/components/server/RelatedProducts.tsx +0 -31
  170. package/scaffold/templates/nextjs/components/server/ReviewList.tsx +0 -62
  171. package/scaffold/templates/nextjs/styles/pages/cart.module.css +0 -240
  172. package/scaffold/templates/nextjs/styles/pages/checkout.module.css +0 -404
  173. /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/layout.tsx +0 -0
  174. /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/orders/page.tsx +0 -0
  175. /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/page.tsx +0 -0
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  import '../styles/pages/home.css'
3
+ import NymbalElement from '@nymbalhq/web-components/astro'
4
+ import { cardImageOf, cardProductOf } from '@nymbalhq/web-components/ssr'
3
5
  import BaseLayout from '../layouts/BaseLayout.astro'
4
6
  import HeroSection from '../components/HeroSection.astro'
5
- import CategoryNav from '../components/CategoryNav.astro'
6
- import ProductCard from '../components/ProductCard.astro'
7
7
  import NewsletterSignup from '../components/NewsletterSignup.astro'
8
8
  import { fetchProducts, fetchCategories } from '../lib/api'
9
9
  import { organizationJsonLd } from '../lib/seo'
@@ -12,17 +12,21 @@ const [productResult, categories] = await Promise.all([
12
12
  fetchProducts({ limit: 8 }),
13
13
  fetchCategories(),
14
14
  ])
15
+ const products = productResult.items.map(cardProductOf)
16
+ // The first card's image is the page's likely LCP, and the preload scanner never reaches it inside the grid's shadow
17
+ // root: the head starts it.
18
+ const firstImage = products[0] === undefined ? null : cardImageOf(products[0]).url
15
19
 
16
- const products = productResult.items
17
20
  const jsonLd = organizationJsonLd('Nymbal', Astro.url.origin)
18
21
  ---
19
22
 
20
23
  <BaseLayout title="Nymbal — Modern Storefront" jsonLd={jsonLd}>
24
+ {firstImage && <link slot="head" rel="preload" as="image" href={firstImage} fetchpriority="high" />}
21
25
  <HeroSection />
22
26
 
23
27
  <section class="section container">
24
28
  <h2 class="section-title">Shop by Category</h2>
25
- <CategoryNav categories={categories} />
29
+ <NymbalElement tag="nymbal-category-nav" attributes={{ categories: JSON.stringify(categories) }} />
26
30
  </section>
27
31
 
28
32
  <section class="featured-section section">
@@ -31,19 +35,25 @@ const jsonLd = organizationJsonLd('Nymbal', Astro.url.origin)
31
35
  <h2 class="section-title" style="margin-bottom: 0;">Featured Products</h2>
32
36
  <a href="/products" class="featured-link">View all</a>
33
37
  </div>
34
- {products.length > 0 ? (
35
- <div class="product-grid">
36
- {products.map((product) => (
37
- <ProductCard product={product} />
38
- ))}
39
- </div>
40
- ) : (
41
- <p style="text-align: center; color: var(--nymbal-color-text-muted, #71717a);">
42
- Products coming soon.
43
- </p>
44
- )}
38
+ <NymbalElement tag="nymbal-product-grid" attributes={{ products: JSON.stringify(products) }} />
45
39
  </div>
46
40
  </section>
47
41
 
48
42
  <NewsletterSignup />
43
+
44
+ <!-- The shopper's own list, read in the browser: a bare tag, so no shopper's list is in the page's HTML. -->
45
+ <div class="container">
46
+ <nymbal-recently-viewed data-testid="recently-viewed"></nymbal-recently-viewed>
47
+ </div>
49
48
  </BaseLayout>
49
+
50
+ <script>
51
+ import '../lib/client.js'
52
+ import { NymbalCategoryNav } from '@nymbalhq/web-components/elements/nymbal-category-nav'
53
+ import { NymbalProductGrid } from '@nymbalhq/web-components/elements/nymbal-product-grid'
54
+ import { NymbalRecentlyViewed } from '@nymbalhq/web-components/elements/nymbal-recently-viewed'
55
+
56
+ NymbalCategoryNav.define()
57
+ NymbalProductGrid.define()
58
+ NymbalRecentlyViewed.define()
59
+ </script>
@@ -1,21 +1,37 @@
1
1
  ---
2
2
  import '../../styles/pages/confirmation.css'
3
3
  import BaseLayout from '../../layouts/BaseLayout.astro'
4
- import OrderSummary from '../../components/OrderSummary.astro'
4
+ import NymbalElement from '@nymbalhq/web-components/astro'
5
5
  import { fetchOrder } from '../../lib/api'
6
- import { formatPrice } from '../../lib/format'
7
6
  import { isPaid, orderHeading } from '../../lib/order-status'
8
7
 
8
+ // The URL carries the order's key (`?key=`), so nothing this page links to or loads may be told the URL: a header
9
+ // and the meta tag below. The rewrite to /404 drops the header, so the not-found page sets its own.
10
+ Astro.response.headers.set('Referrer-Policy', 'no-referrer')
11
+
9
12
  const { orderNumber } = Astro.params
10
- const order = await fetchOrder(orderNumber!)
13
+ const key = Astro.url.searchParams.get('key') ?? undefined
14
+ // Rejects when the API fails, so a failed read is a 500 and never a 404 for an order the shopper has.
15
+ const order = await fetchOrder(orderNumber!, key)
11
16
 
12
- if (!order) return Astro.redirect('/404')
17
+ if (!order) return Astro.rewrite('/404')
13
18
 
14
- const lineItems = (order.lineItems ?? []).map((item) => ({
15
- name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
16
- qty: item.qty,
17
- priceMinor: item.unitPriceMinor,
18
- }))
19
+ const summary = {
20
+ items: JSON.stringify(
21
+ (order.lineItems ?? []).map((item) => ({
22
+ name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
23
+ qty: item.qty,
24
+ unitPriceMinor: item.unitPriceMinor,
25
+ lineTotalMinor: item.lineTotalMinor,
26
+ })),
27
+ ),
28
+ 'subtotal-minor': String(order.subtotalMinor),
29
+ 'discount-minor': String(order.discountTotalMinor ?? 0),
30
+ 'shipping-minor': String(order.shippingTotalMinor ?? 0),
31
+ 'tax-minor': String(order.taxTotalMinor ?? 0),
32
+ 'total-minor': String(order.totalMinor),
33
+ currency: order.currency,
34
+ }
19
35
 
20
36
  const shippingAddress = order.shippingAddress
21
37
  const heading = orderHeading(order.status)
@@ -23,6 +39,7 @@ const paid = isPaid(order.status)
23
39
  ---
24
40
 
25
41
  <BaseLayout title={`${heading} | Nymbal`} description="Your order with Nymbal.">
42
+ <meta slot="head" name="referrer" content="no-referrer" />
26
43
  <div class="container section">
27
44
  <div class="confirmation-page" data-order-number={order.orderNumber} data-order-status={order.status}>
28
45
  {paid && (
@@ -63,44 +80,11 @@ const paid = isPaid(order.status)
63
80
  <dd style="text-transform: capitalize;" data-testid="order-status">{order.status}</dd>
64
81
  </div>
65
82
  </dl>
83
+ </div>
66
84
 
67
- <div class="confirmation-items">
68
- {lineItems.map((item) => (
69
- <div class="confirmation-item">
70
- <span>
71
- <span class="confirmation-item-name">{item.name}</span>
72
- <span class="confirmation-item-qty"> x{item.qty}</span>
73
- </span>
74
- <span class="confirmation-item-price">
75
- {formatPrice(item.priceMinor * item.qty, order.currency)}
76
- </span>
77
- </div>
78
- ))}
79
- </div>
85
+ <NymbalElement tag="nymbal-order-timeline" attributes={{ class: 'confirmation-summary', entries: JSON.stringify(order.timeline ?? []) }} />
80
86
 
81
- <div class="confirmation-totals">
82
- <div class="confirmation-total-row">
83
- <span>Subtotal</span>
84
- <span>{formatPrice(order.subtotalMinor, order.currency)}</span>
85
- </div>
86
- {order.shippingTotalMinor != null && (
87
- <div class="confirmation-total-row">
88
- <span>Shipping</span>
89
- <span>{order.shippingTotalMinor === 0 ? 'Free' : formatPrice(order.shippingTotalMinor, order.currency)}</span>
90
- </div>
91
- )}
92
- {order.taxTotalMinor != null && (
93
- <div class="confirmation-total-row">
94
- <span>Tax</span>
95
- <span>{formatPrice(order.taxTotalMinor, order.currency)}</span>
96
- </div>
97
- )}
98
- <div class="confirmation-total-row grand-total">
99
- <span>Total</span>
100
- <span>{formatPrice(order.totalMinor, order.currency)}</span>
101
- </div>
102
- </div>
103
- </div>
87
+ <NymbalElement tag="nymbal-order-summary" attributes={{ class: 'confirmation-summary', ...summary }} />
104
88
 
105
89
  {shippingAddress && (
106
90
  <div class="confirmation-card">
@@ -124,4 +108,9 @@ const paid = isPaid(order.status)
124
108
 
125
109
  <script>
126
110
  import '../../scripts/order-status.js'
111
+ import { NymbalOrderSummary } from '@nymbalhq/web-components/elements/nymbal-order-summary'
112
+ import { NymbalOrderTimeline } from '@nymbalhq/web-components/elements/nymbal-order-timeline'
113
+
114
+ NymbalOrderSummary.define()
115
+ NymbalOrderTimeline.define()
127
116
  </script>
@@ -1,27 +1,24 @@
1
1
  ---
2
2
  import '../../styles/pages/pdp.css'
3
3
  import BaseLayout from '../../layouts/BaseLayout.astro'
4
- import Breadcrumb from '../../components/Breadcrumb.astro'
5
- import ImageGallery from '../../components/ImageGallery.astro'
6
- import PriceDisplay from '../../components/PriceDisplay.astro'
7
- import StockBadge from '../../components/StockBadge.astro'
8
- import ReviewList from '../../components/ReviewList.astro'
9
- import ReviewForm from '../../components/ReviewForm.astro'
10
- import RelatedProducts from '../../components/RelatedProducts.astro'
11
- import { fetchProduct, fetchReviews, fetchProducts } from '../../lib/api'
4
+ import NymbalElement from '@nymbalhq/web-components/astro'
5
+ import { cardProductOf } from '@nymbalhq/web-components/ssr'
6
+ import { loadProduct, fetchReviews, fetchProducts, fetchCapabilities } from '../../lib/api'
12
7
  import { productJsonLd, breadcrumbJsonLd } from '../../lib/seo'
13
8
 
14
9
  const { slug } = Astro.params
15
10
 
16
- const product = await fetchProduct(slug!)
17
- if (!product) return Astro.redirect('/404')
11
+ // Rejects when the API fails, so a failed read is a 500 and never a 404 for a product the store has.
12
+ const product = await loadProduct(slug!)
13
+ if (!product) return Astro.rewrite('/404')
18
14
 
19
- const [reviewsResult, relatedResult] = await Promise.all([
15
+ const [reviewsResult, relatedResult, capabilities] = await Promise.all([
20
16
  fetchReviews(product.id),
21
17
  fetchProducts({
22
18
  limit: 4,
23
- category: product.categoryIds?.[0] ?? undefined,
19
+ category: product.categories?.[0]?.slug,
24
20
  }),
21
+ fetchCapabilities(),
25
22
  ])
26
23
 
27
24
  const reviews = reviewsResult.items ?? []
@@ -45,48 +42,70 @@ const breadcrumb = breadcrumbJsonLd([
45
42
  { name: product.name, url: `${Astro.url.origin}/product/${product.slug}` },
46
43
  ])
47
44
 
45
+ // The alert form only where the store's email reaches a mailbox (an API older than the report says nothing): back in
46
+ // stock for a variant out of stock, price drop for one in stock.
47
+ const offersAlerts = capabilities?.email?.delivers === true && defaultVariant !== undefined
48
+
48
49
  // The selector derives its option groups from the product's variants.
49
50
  const hasVariantChoice = (product.variants?.length ?? 0) > 1
50
51
  ---
51
52
 
52
53
  <BaseLayout title={`${product.name} | Nymbal`} description={product.shortDescription ?? product.description ?? ''} jsonLd={jsonLd}>
54
+ <!-- The gallery's main image is the page's LCP: the browser starts it before it parses the body. -->
55
+ <link slot="head" rel="preload" as="image" href={images[0]!.url} fetchpriority="high" />
53
56
  <div class="container section" data-product-slug={product.slug}>
54
- <Breadcrumb
55
- items={[
56
- { label: 'Home', href: '/' },
57
- { label: 'Products', href: '/products' },
58
- { label: product.name },
59
- ]}
57
+ <NymbalElement
58
+ tag="nymbal-breadcrumb"
59
+ attributes={{
60
+ items: JSON.stringify([
61
+ { label: 'Home', href: '/' },
62
+ { label: 'Products', href: '/products' },
63
+ { label: product.name },
64
+ ]),
65
+ }}
60
66
  />
61
67
 
62
68
  <div class="pdp-layout">
63
- <ImageGallery images={images} />
69
+ <NymbalElement tag="nymbal-image-gallery" attributes={{ class: 'pdp-gallery', images: JSON.stringify(images) }} />
64
70
 
65
71
  <div class="pdp-info">
66
72
  <h1 class="pdp-title" data-testid="product-title">{product.name}</h1>
67
73
 
68
- <PriceDisplay
69
- priceMinor={defaultVariant?.priceMinor ?? product.priceMinor}
70
- currency={product.currency ?? 'GBP'}
74
+ <NymbalElement
75
+ tag="nymbal-product-price"
76
+ attributes={{
77
+ 'product-id': product.id,
78
+ 'price-minor': String(defaultVariant?.priceMinor ?? product.priceMinor ?? 0),
79
+ currency: product.currency ?? 'GBP',
80
+ }}
71
81
  />
72
-
73
- <StockBadge stock={stock} />
82
+ <NymbalElement tag="nymbal-stock-badge" attributes={{ 'product-id': product.id, stock: String(stock) }} />
74
83
 
75
84
  <div class="pdp-actions">
76
85
  {hasVariantChoice && (
77
- <nymbal-variant-selector></nymbal-variant-selector>
86
+ <NymbalElement tag="nymbal-variant-selector" attributes={{ product: JSON.stringify(product) }} />
78
87
  )}
79
88
 
80
89
  <div class="pdp-add-row">
81
- <nymbal-quantity-selector value="1" min="1" max="99"></nymbal-quantity-selector>
82
- <nymbal-add-to-cart
83
- variant-id={defaultVariant?.id ?? product.id}
84
- qty="1"
85
- disabled={stock <= 0}
86
- ></nymbal-add-to-cart>
90
+ <NymbalElement tag="nymbal-quantity-selector" attributes={{ value: '1', min: '1', max: '99' }} />
91
+ <NymbalElement
92
+ tag="nymbal-add-to-cart"
93
+ attributes={{
94
+ 'variant-id': defaultVariant?.id ?? product.id,
95
+ qty: '1',
96
+ ...(stock <= 0 && { disabled: '' }),
97
+ }}
98
+ />
87
99
  </div>
88
100
  </div>
89
101
 
102
+ {offersAlerts && (
103
+ <NymbalElement
104
+ tag="nymbal-notify-me"
105
+ attributes={{ 'product-id': product.id, 'variant-id': defaultVariant!.id, stock: String(stock) }}
106
+ />
107
+ )}
108
+
90
109
  {product.description && (
91
110
  <div class="pdp-description" data-testid="product-description">
92
111
  <Fragment set:html={product.description} />
@@ -97,11 +116,22 @@ const hasVariantChoice = (product.variants?.length ?? 0) > 1
97
116
 
98
117
  <section class="pdp-reviews">
99
118
  <h2 class="pdp-reviews-title">Customer Reviews</h2>
100
- <ReviewList reviews={reviews} />
101
- <ReviewForm productId={product.id} />
119
+ <NymbalElement tag="nymbal-review-list" attributes={{ reviews: JSON.stringify(reviews) }} />
120
+ <NymbalElement tag="nymbal-review-form" attributes={{ class: 'pdp-review-form', 'product-id': product.id }} />
102
121
  </section>
103
122
 
104
- <RelatedProducts products={relatedProducts} />
123
+ {relatedProducts.length > 0 && (
124
+ <section class="section">
125
+ <h2 class="section-title">You may also like</h2>
126
+ <NymbalElement
127
+ tag="nymbal-product-grid"
128
+ attributes={{ products: JSON.stringify(relatedProducts.map(cardProductOf)), lazy: '' }}
129
+ />
130
+ </section>
131
+ )}
132
+
133
+ <!-- The shopper's own list, read in the browser: a bare tag, so no shopper's list is in the page's HTML. -->
134
+ <nymbal-recently-viewed data-testid="recently-viewed" current={product.id}></nymbal-recently-viewed>
105
135
  </div>
106
136
  </BaseLayout>
107
137
 
@@ -1,10 +1,8 @@
1
1
  ---
2
2
  import '../../styles/pages/plp.css'
3
- import '../../styles/pages/home.css'
4
3
  import BaseLayout from '../../layouts/BaseLayout.astro'
5
- import Breadcrumb from '../../components/Breadcrumb.astro'
6
- import ProductCard from '../../components/ProductCard.astro'
7
- import Pagination from '../../components/Pagination.astro'
4
+ import NymbalElement from '@nymbalhq/web-components/astro'
5
+ import { cardImageOf, cardProductOf } from '@nymbalhq/web-components/ssr'
8
6
  import { PRODUCT_SORT_LABELS } from '@nymbalhq/types'
9
7
  import { fetchProducts, fetchCategories, fetchCapabilities, sortFromUrl } from '../../lib/api'
10
8
 
@@ -17,17 +15,20 @@ const [productResult, categories] = await Promise.all([
17
15
  fetchCategories(),
18
16
  ])
19
17
 
20
- const products = productResult.items
18
+ const products = productResult.items.map(cardProductOf)
19
+ // The first card's image is the page's LCP, and the preload scanner never reaches it inside the grid's shadow root:
20
+ // the head starts it.
21
+ const firstImage = products[0] === undefined ? null : cardImageOf(products[0]).url
21
22
  const facets = productResult.facets ?? []
22
23
  ---
23
24
 
24
25
  <BaseLayout title="All Products | Nymbal" description="Browse our full product collection.">
26
+ {firstImage && <link slot="head" rel="preload" as="image" href={firstImage} fetchpriority="high" />}
25
27
  <div class="container section">
26
- <Breadcrumb items={[{ label: 'Home', href: '/' }, { label: 'Products' }]} />
28
+ <NymbalElement tag="nymbal-breadcrumb" attributes={{ items: JSON.stringify([{ label: 'Home', href: '/' }, { label: 'Products' }]) }} />
27
29
 
28
30
  <div class="plp-header">
29
31
  <h1 class="plp-title">All Products</h1>
30
- <p class="plp-count" id="product-count">{products.length} products</p>
31
32
  </div>
32
33
 
33
34
  <div class="plp-layout">
@@ -57,20 +58,14 @@ const facets = productResult.facets ?? []
57
58
  </div>
58
59
  )}
59
60
 
60
- <div class="product-grid" id="product-grid">
61
- {products.map((product) => (
62
- <ProductCard product={product} />
63
- ))}
64
- </div>
65
-
66
- {products.length === 0 && (
67
- <div class="plp-empty">
68
- <h2 class="plp-empty-title">No products found</h2>
69
- <p class="plp-empty-text">Try adjusting your filters.</p>
70
- </div>
71
- )}
72
-
73
- <Pagination />
61
+ <NymbalElement
62
+ tag="nymbal-product-grid"
63
+ attributes={{
64
+ products: JSON.stringify(products),
65
+ source: 'product-list',
66
+ ...(productResult.nextCursor !== null && { 'has-more': '' }),
67
+ }}
68
+ />
74
69
  </div>
75
70
  </div>
76
71
  </div>
@@ -1,8 +1,14 @@
1
1
  ---
2
2
  import '../styles/pages/search.css'
3
- import '../styles/pages/home.css'
4
- import '../styles/pages/plp.css'
3
+ import NymbalElement from '@nymbalhq/web-components/astro'
5
4
  import BaseLayout from '../layouts/BaseLayout.astro'
5
+ import { fetchSearch } from '../lib/api'
6
+
7
+ const q = Astro.url.searchParams.get('q')?.trim() ?? ''
8
+ const search = q === '' ? null : await fetchSearch(q, Astro.url.searchParams.get('category'))
9
+ // The results the page's search would show, so they are in the HTML; the search store takes over once it answers.
10
+ const results: Record<string, string> =
11
+ search === null ? {} : { results: JSON.stringify(search.items), query: q }
6
12
  ---
7
13
 
8
14
  <BaseLayout title="Search | Nymbal" description="Search our product catalogue.">
@@ -22,18 +28,11 @@ import BaseLayout from '../layouts/BaseLayout.astro'
22
28
  </div>
23
29
 
24
30
  <div class="container section">
25
- <p class="search-query-label" id="search-query-label" style="display:none; margin-bottom: var(--nymbal-spacing-md, 1rem);"></p>
26
31
  <div class="search-layout">
27
32
  <aside class="search-sidebar">
28
- <nymbal-product-filter source="search"></nymbal-product-filter>
33
+ <nymbal-product-filter source="search" empty></nymbal-product-filter>
29
34
  </aside>
30
- <div id="search-results" data-testid="search-results">
31
- <div class="search-empty">
32
- <div class="search-empty-icon" aria-hidden="true">&#128269;</div>
33
- <h2 class="search-empty-title">Search our store</h2>
34
- <p class="search-empty-text">Type a keyword to find products.</p>
35
- </div>
36
- </div>
35
+ <NymbalElement tag="nymbal-search-results" attributes={{ 'data-testid': 'search-results', ...results }} />
37
36
  </div>
38
37
  </div>
39
38
  </BaseLayout>
@@ -1,4 +1,18 @@
1
1
  import '../lib/client.js'
2
+ import { NymbalCartDrawer } from '@nymbalhq/web-components/elements/nymbal-cart-drawer'
3
+ import { NymbalMiniCart } from '@nymbalhq/web-components/elements/nymbal-mini-cart'
4
+ import { NymbalSearchBar } from '@nymbalhq/web-components/elements/nymbal-search-bar'
5
+ import { NymbalSiteFooter } from '@nymbalhq/web-components/elements/nymbal-site-footer'
6
+ import { NymbalSiteHeader } from '@nymbalhq/web-components/elements/nymbal-site-header'
7
+ import { NymbalToast } from '@nymbalhq/web-components/elements/nymbal-toast'
8
+
9
+ // The layout's elements; each page script defines the ones its page renders.
10
+ NymbalSiteHeader.define()
11
+ NymbalSiteFooter.define()
12
+ NymbalSearchBar.define()
13
+ NymbalMiniCart.define()
14
+ NymbalCartDrawer.define()
15
+ NymbalToast.define()
2
16
 
3
17
  // Navigate to checkout when the cart drawer checkout button is clicked
4
18
  document.addEventListener('nymbal:cart:checkout-clicked', () => {
@@ -8,12 +8,14 @@ const POLL_FOR_MS = 10_000
8
8
  const root = document.querySelector<HTMLElement>('[data-order-number][data-order-status]')
9
9
  const orderNumber = root?.dataset.orderNumber
10
10
  const shown = root?.dataset.orderStatus
11
+ // The page's own key, from its URL: the API answers a guest's order to its key only.
12
+ const key = new URLSearchParams(window.location.search).get('key')
11
13
 
12
14
  if (orderNumber && shown === 'pending') {
13
15
  const until = Date.now() + POLL_FOR_MS
14
16
  const poll = async (): Promise<void> => {
15
17
  try {
16
- const order = await client.customer.orders.get(orderNumber)
18
+ const order = await client.customer.orders.get(orderNumber, key ? { key } : {})
17
19
  if (order.status !== shown) {
18
20
  window.location.reload()
19
21
  return
@@ -1,6 +1,31 @@
1
- import { STOCK_LABELS, stockLevel } from '@nymbalhq/types'
1
+ import { NymbalAddToCart } from '@nymbalhq/web-components/elements/nymbal-add-to-cart'
2
+ import { NymbalBreadcrumb } from '@nymbalhq/web-components/elements/nymbal-breadcrumb'
3
+ import { NymbalImageGallery } from '@nymbalhq/web-components/elements/nymbal-image-gallery'
4
+ import { NymbalNotifyMe } from '@nymbalhq/web-components/elements/nymbal-notify-me'
5
+ import { NymbalProductGrid } from '@nymbalhq/web-components/elements/nymbal-product-grid'
6
+ import { NymbalProductPrice } from '@nymbalhq/web-components/elements/nymbal-product-price'
7
+ import { NymbalQuantitySelector } from '@nymbalhq/web-components/elements/nymbal-quantity-selector'
8
+ import { NymbalRecentlyViewed } from '@nymbalhq/web-components/elements/nymbal-recently-viewed'
9
+ import { NymbalReviewForm } from '@nymbalhq/web-components/elements/nymbal-review-form'
10
+ import { NymbalReviewList } from '@nymbalhq/web-components/elements/nymbal-review-list'
11
+ import { NymbalStockBadge } from '@nymbalhq/web-components/elements/nymbal-stock-badge'
12
+ import { NymbalVariantSelector } from '@nymbalhq/web-components/elements/nymbal-variant-selector'
2
13
  import { client } from '../lib/client.js'
3
- import { formatPrice } from '../lib/format.js'
14
+
15
+ NymbalBreadcrumb.define()
16
+ NymbalImageGallery.define()
17
+ NymbalProductPrice.define()
18
+ NymbalStockBadge.define()
19
+ NymbalVariantSelector.define()
20
+ NymbalQuantitySelector.define()
21
+ NymbalAddToCart.define()
22
+ NymbalReviewList.define()
23
+ NymbalReviewForm.define()
24
+ NymbalRecentlyViewed.define()
25
+ // The related grid is there only when the product has relations.
26
+ if (document.querySelector('nymbal-product-grid') !== null) NymbalProductGrid.define()
27
+ // The back-in-stock form is there only when the store's email delivers.
28
+ if (document.querySelector('nymbal-notify-me') !== null) NymbalNotifyMe.define()
4
29
 
5
30
  const slug = document.querySelector<HTMLElement>('[data-product-slug]')?.dataset.productSlug
6
31
  const addRow = document.querySelector<HTMLElement>('.pdp-add-row')
@@ -20,32 +45,15 @@ if (slug) {
20
45
  addToCart?.setAttribute('qty', String(e.detail.value))
21
46
  }) as EventListener)
22
47
 
48
+ // The price and the stock badge follow the store themselves; the add row is the page's.
23
49
  client.product.subscribe(() => {
24
50
  const { product, selectedVariant } = client.product.getState()
25
51
  if (!product) return
26
52
  const variant = selectedVariant ?? product.variants?.[0]
27
53
 
28
- const priceEl = document.querySelector('[data-testid="product-price"]')
29
- if (priceEl) {
30
- const price = formatPrice(
31
- variant?.priceMinor ?? product.priceMinor ?? 0,
32
- product.currency ?? 'GBP',
33
- )
34
- priceEl.innerHTML = `<span>${price}</span>`
35
- }
36
-
37
- const stock = variant?.stock ?? 0
38
- const level = stockLevel(stock)
39
- const badge = document.querySelector<HTMLElement>('[data-testid="stock-badge"]')
40
- if (badge) {
41
- badge.dataset.level = level
42
- const label = badge.querySelector('[data-stock-label]')
43
- if (label) label.textContent = STOCK_LABELS[level]
44
- }
45
-
46
54
  if (addToCart && variant) {
47
55
  addToCart.setAttribute('variant-id', variant.id)
48
- addToCart.toggleAttribute('disabled', stock <= 0)
56
+ addToCart.toggleAttribute('disabled', (variant.stock ?? 0) <= 0)
49
57
  }
50
58
 
51
59
  if (variant && variant.id !== shownVariantId) {