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
@@ -0,0 +1,11 @@
1
+ import type { Metadata } from 'next'
2
+ import { renderNymbal } from '@/lib/render'
3
+ import { RegisterView } from './RegisterView'
4
+
5
+ export const metadata: Metadata = {
6
+ title: 'Create Account',
7
+ }
8
+
9
+ export default function RegisterPage() {
10
+ return <RegisterView serverHtml={renderNymbal('nymbal-register-form').__html} />
11
+ }
@@ -0,0 +1,90 @@
1
+ 'use client'
2
+
3
+ import Link from 'next/link'
4
+ import { useActionState } from 'react'
5
+ import styles from '@/styles/pages/error.module.css'
6
+ import { confirmAlertAction, unsubscribeAlertAction } from './actions'
7
+ import { LinkInvalid } from './LinkInvalid'
8
+
9
+ const PAGES = {
10
+ confirm: {
11
+ action: confirmAlertAction,
12
+ title: 'Confirm your email alert',
13
+ message: 'Press the button to start the alert this email asked for.',
14
+ label: 'Confirm alert',
15
+ invalid: 'It may be from an older email, or the alert has been stopped.',
16
+ },
17
+ unsubscribe: {
18
+ action: unsubscribeAlertAction,
19
+ title: 'Stop this email alert',
20
+ message: "Press the button and we won't email you about this product again.",
21
+ label: 'Unsubscribe',
22
+ invalid: 'Check that the whole link from the email was opened.',
23
+ },
24
+ }
25
+
26
+ /**
27
+ * An alert link's page: opening it changes nothing, so a mail scanner that fetches it, or runs its scripts, leaves
28
+ * the alert as it was. The button posts the token to a server action, with JavaScript on or off.
29
+ */
30
+ export function AlertLinkForm({ kind, token }: { kind: keyof typeof PAGES; token: string }) {
31
+ const page = PAGES[kind]
32
+ const [state, formAction, pending] = useActionState(page.action, null)
33
+
34
+ if (state === null) {
35
+ return (
36
+ <form action={formAction} className={styles.page} data-testid={`alert-${kind}-form`}>
37
+ <div className={styles.wrapper}>
38
+ <h1 className={styles.title}>{page.title}</h1>
39
+ <p className={styles.message}>{page.message}</p>
40
+ <input type="hidden" name="token" value={token} />
41
+ <div className={styles.actions}>
42
+ <button
43
+ type="submit"
44
+ className={styles.homeLink}
45
+ data-testid={`alert-${kind}-submit`}
46
+ disabled={pending}
47
+ >
48
+ {page.label}
49
+ </button>
50
+ </div>
51
+ </div>
52
+ </form>
53
+ )
54
+ }
55
+ if (state.result === 'invalid') return <LinkInvalid message={page.invalid} />
56
+ if (state.result === 'unsubscribed') {
57
+ return (
58
+ <div className={styles.page} data-testid="alert-unsubscribed">
59
+ <div className={styles.wrapper}>
60
+ <h1 className={styles.title}>Your alert is off</h1>
61
+ <p className={styles.message}>We won&apos;t email you about this product again.</p>
62
+ <div className={styles.actions}>
63
+ <Link href="/products" className={styles.homeLink}>
64
+ Browse Products
65
+ </Link>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ )
70
+ }
71
+ const { kind: alertKind, product } = state.confirmation
72
+ return (
73
+ <div className={styles.page} data-testid="alert-confirmed" data-kind={alertKind}>
74
+ <div className={styles.wrapper}>
75
+ <h1 className={styles.title}>Your alert is on</h1>
76
+ {alertKind === 'price_drop' ? (
77
+ <p className={styles.message}>
78
+ We&apos;ll email you when the price of{' '}
79
+ <Link href={`/product/${product.slug}`}>{product.name}</Link> drops.
80
+ </p>
81
+ ) : (
82
+ <p className={styles.message}>
83
+ We&apos;ll email you once when <Link href={`/product/${product.slug}`}>{product.name}</Link>{' '}
84
+ is back in stock.
85
+ </p>
86
+ )}
87
+ </div>
88
+ </div>
89
+ )
90
+ }
@@ -0,0 +1,19 @@
1
+ import Link from 'next/link'
2
+ import styles from '@/styles/pages/error.module.css'
3
+
4
+ /** What an alert link that the store refuses shows: an older email's confirmation, or a link cut short. */
5
+ export function LinkInvalid({ message }: { message: string }) {
6
+ return (
7
+ <div className={styles.page} data-testid="alert-link-invalid">
8
+ <div className={styles.wrapper}>
9
+ <h1 className={styles.title}>This link is not valid</h1>
10
+ <p className={styles.message}>{message}</p>
11
+ <div className={styles.actions}>
12
+ <Link href="/products" className={styles.homeLink}>
13
+ Browse Products
14
+ </Link>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ )
19
+ }
@@ -0,0 +1,33 @@
1
+ 'use server'
2
+
3
+ import { confirmAlert, unsubscribeAlert, type AlertConfirmation } from '@/lib/api'
4
+
5
+ /** What a press of an alert page's button shows. */
6
+ export type AlertLinkResult =
7
+ | { result: 'confirmed'; confirmation: AlertConfirmation }
8
+ | { result: 'unsubscribed' }
9
+ | { result: 'invalid' }
10
+
11
+ function tokenOf(form: FormData): string {
12
+ const token = form.get('token')
13
+ return typeof token === 'string' ? token : ''
14
+ }
15
+
16
+ // The token is posted on from this server, so the browser needs no CSRF cookie.
17
+ export async function confirmAlertAction(
18
+ _previous: AlertLinkResult | null,
19
+ form: FormData,
20
+ ): Promise<AlertLinkResult> {
21
+ const token = tokenOf(form)
22
+ const confirmation = token === '' ? null : await confirmAlert(token)
23
+ return confirmation ? { result: 'confirmed', confirmation } : { result: 'invalid' }
24
+ }
25
+
26
+ export async function unsubscribeAlertAction(
27
+ _previous: AlertLinkResult | null,
28
+ form: FormData,
29
+ ): Promise<AlertLinkResult> {
30
+ const token = tokenOf(form)
31
+ const stopped = token === '' ? false : await unsubscribeAlert(token)
32
+ return stopped ? { result: 'unsubscribed' } : { result: 'invalid' }
33
+ }
@@ -0,0 +1,19 @@
1
+ import type { Metadata } from 'next'
2
+ import { AlertLinkForm } from '../AlertLinkForm'
3
+ import { LinkInvalid } from '../LinkInvalid'
4
+
5
+ export const metadata: Metadata = { title: 'Email alert' }
6
+
7
+ interface ConfirmPageProps {
8
+ searchParams: Promise<{ token?: string | string[] }>
9
+ }
10
+
11
+ // The link in a confirmation email: it shows the button and calls no API until the button is pressed.
12
+ export default async function ConfirmAlertPage({ searchParams }: ConfirmPageProps) {
13
+ const { token } = await searchParams
14
+ const value = typeof token === 'string' ? token : ''
15
+ if (value === '') {
16
+ return <LinkInvalid message="It may be from an older email, or the alert has been stopped." />
17
+ }
18
+ return <AlertLinkForm kind="confirm" token={value} />
19
+ }
@@ -0,0 +1,17 @@
1
+ import type { Metadata } from 'next'
2
+ import { AlertLinkForm } from '../AlertLinkForm'
3
+ import { LinkInvalid } from '../LinkInvalid'
4
+
5
+ export const metadata: Metadata = { title: 'Back-in-stock alert' }
6
+
7
+ interface UnsubscribePageProps {
8
+ searchParams: Promise<{ token?: string | string[] }>
9
+ }
10
+
11
+ // The unsubscribe link every alert email carries: it shows the button and calls no API until the button is pressed.
12
+ export default async function UnsubscribeAlertPage({ searchParams }: UnsubscribePageProps) {
13
+ const { token } = await searchParams
14
+ const value = typeof token === 'string' ? token : ''
15
+ if (value === '') return <LinkInvalid message="Check that the whole link from the email was opened." />
16
+ return <AlertLinkForm kind="unsubscribe" token={value} />
17
+ }
@@ -0,0 +1,5 @@
1
+ 'use client'
2
+
3
+ import { CartPage } from '@nymbalhq/react'
4
+
5
+ export default CartPage
@@ -0,0 +1,22 @@
1
+ import type { Metadata } from 'next'
2
+ import { headers } from 'next/headers'
3
+ import { fetchCart } from '@/lib/api'
4
+ import { renderNymbal } from '@/lib/render'
5
+ import CartPage from './CartView'
6
+
7
+ export const metadata: Metadata = {
8
+ title: 'Shopping Cart',
9
+ }
10
+
11
+ export default async function CartRoute() {
12
+ const cart = await fetchCart((await headers()).get('cookie'))
13
+ const serverHtml = renderNymbal(
14
+ 'nymbal-cart-page',
15
+ cart === null ? {} : { cart: JSON.stringify(cart) },
16
+ ).__html
17
+ return (
18
+ <div className="container section" data-testid="cart-page">
19
+ <CartPage cart={cart ?? undefined} serverHtml={serverHtml} />
20
+ </div>
21
+ )
22
+ }
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+
3
+ import { useCallback, useEffect } from 'react'
4
+ import { Checkout } from '@nymbalhq/react'
5
+ import { NymbalPaymentElement } from '@nymbalhq/web-components/elements/nymbal-payment-element'
6
+ import type { CartProjection } from '@/lib/api'
7
+
8
+ /**
9
+ * The element places the order; the page only goes to it. The server rendered the checkout with its payment element
10
+ * as a light-DOM child (`serverHtml`), which is defined here: it stays mounted by its driver in the browser.
11
+ */
12
+ export function CheckoutView({
13
+ cart,
14
+ serverHtml,
15
+ }: {
16
+ cart: CartProjection | null
17
+ serverHtml: string
18
+ }) {
19
+ // A full load, not router.push: the order page's URL carries its key, and only a document of its own takes the
20
+ // page's Referrer-Policy header. A soft navigation leaves it in the checkout's document, whose requests (its
21
+ // script chunks among them) refer the keyed URL on.
22
+ const onPlaced = useCallback((event: CustomEvent<{ orderNumber: string; orderKey?: string }>) => {
23
+ const { orderNumber, orderKey } = event.detail
24
+ window.location.assign(
25
+ `/order/${encodeURIComponent(orderNumber)}${orderKey ? `?key=${encodeURIComponent(orderKey)}` : ''}`,
26
+ )
27
+ }, [])
28
+
29
+ useEffect(() => {
30
+ NymbalPaymentElement.define()
31
+ }, [])
32
+
33
+ return <Checkout cart={cart ?? undefined} serverHtml={serverHtml} onPlaced={onPlaced} />
34
+ }
@@ -0,0 +1,39 @@
1
+ import type { Metadata } from 'next'
2
+ import { headers } from 'next/headers'
3
+ import { fetchCapabilities, fetchCart } from '@/lib/api'
4
+ import { renderNymbal } from '@/lib/render'
5
+ import { CheckoutView } from './CheckoutView'
6
+
7
+ export const metadata: Metadata = {
8
+ title: 'Checkout',
9
+ }
10
+
11
+ const escapeAttribute = (value: string): string =>
12
+ value.replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;')
13
+
14
+ export default async function CheckoutRoute() {
15
+ const [capabilities, cart] = await Promise.all([
16
+ fetchCapabilities(),
17
+ headers().then((h) => fetchCart(h.get('cookie'))),
18
+ ])
19
+ if (capabilities === null) {
20
+ throw new Error(
21
+ 'The store did not answer GET /api/capabilities, so checkout cannot tell how to take a payment.',
22
+ )
23
+ }
24
+ // The payments adapter's client half, as the checkout's light-DOM child in its payment slot; a driver the project
25
+ // registers in lib/client.ts renders it.
26
+ const payment = `<nymbal-payment-element slot="payment" client="${escapeAttribute(
27
+ JSON.stringify(capabilities.payments.client),
28
+ )}" data-testid="payment-element"></nymbal-payment-element>`
29
+ const serverHtml = renderNymbal(
30
+ 'nymbal-checkout',
31
+ cart === null ? {} : { cart: JSON.stringify(cart) },
32
+ payment,
33
+ ).__html
34
+ return (
35
+ <div className="container section">
36
+ <CheckoutView cart={cart} serverHtml={serverHtml} />
37
+ </div>
38
+ )
39
+ }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from 'react'
2
+ import { Header } from '@/components/server/Header'
3
+
4
+ // The shopper's own pages render per request: the header reads the cart cookie, so its count is in the HTML.
5
+ export default function ShopperLayout({ children }: { children: ReactNode }) {
6
+ return (
7
+ <>
8
+ <Header shopper />
9
+ <main id="main">{children}</main>
10
+ </>
11
+ )
12
+ }
@@ -0,0 +1,6 @@
1
+ import { NotFoundView } from '@/components/server/NotFoundView'
2
+
3
+ // A shopper page with nothing to show (an order the store does not know), under the shopper's header.
4
+ export default function ShopperNotFound() {
5
+ return <NotFoundView />
6
+ }
@@ -1,20 +1,25 @@
1
1
  import type { Metadata } from 'next'
2
2
  import { notFound } from 'next/navigation'
3
3
  import Link from 'next/link'
4
- import { fetchOrder } from '@/lib/api'
5
- import { OrderSummary } from '@/components/server/OrderSummary'
4
+ import { loadOrder } from '@/lib/api'
5
+ import { OrderSummary, OrderTimeline } from '@/components/client/elements'
6
+ import { renderNymbal } from '@/lib/render'
6
7
  import { OrderStatusRefresh } from '@/components/client/OrderStatusRefresh'
7
8
  import { isPaid, orderHeading } from '@/lib/order-status'
8
9
  import styles from '@/styles/pages/confirmation.module.css'
9
10
 
10
11
  interface OrderPageProps {
11
12
  params: Promise<{ orderNumber: string }>
13
+ searchParams: Promise<{ key?: string | string[] }>
12
14
  }
13
15
 
16
+ // The URL carries the order's key (`?key=`), so nothing this page links to or loads may be told the URL: the meta
17
+ // tag here, and the header next.config.mjs sets on every /order/<n> response, the not-found render's too.
14
18
  export async function generateMetadata({ params }: OrderPageProps): Promise<Metadata> {
15
19
  const { orderNumber } = await params
16
20
  return {
17
21
  title: `Order ${orderNumber}`,
22
+ referrer: 'no-referrer',
18
23
  }
19
24
  }
20
25
 
@@ -53,16 +58,35 @@ function AddressBlock({
53
58
  )
54
59
  }
55
60
 
56
- export default async function OrderPage({ params }: OrderPageProps) {
61
+ export default async function OrderPage({ params, searchParams }: OrderPageProps) {
57
62
  const { orderNumber } = await params
58
- const order = await fetchOrder(orderNumber)
63
+ const { key: keyParam } = await searchParams
64
+ const key = Array.isArray(keyParam) ? keyParam[0] : keyParam
65
+ // Rejects when the API fails, so a failed read is a 500 and never a 404 for an order the shopper has.
66
+ const order = await loadOrder(orderNumber, key)
59
67
 
60
68
  if (!order) notFound()
61
69
  const paid = isPaid(order.status)
70
+ const items = order.lineItems.map((item) => ({
71
+ name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
72
+ qty: item.qty,
73
+ unitPriceMinor: item.unitPriceMinor,
74
+ lineTotalMinor: item.lineTotalMinor,
75
+ }))
76
+ const summary = {
77
+ items: JSON.stringify(items),
78
+ 'subtotal-minor': String(order.subtotalMinor),
79
+ 'discount-minor': String(order.discountTotalMinor ?? 0),
80
+ 'shipping-minor': String(order.shippingTotalMinor ?? 0),
81
+ 'tax-minor': String(order.taxTotalMinor ?? 0),
82
+ 'total-minor': String(order.totalMinor),
83
+ currency: order.currency,
84
+ }
85
+ const timeline = order.timeline ?? []
62
86
 
63
87
  return (
64
88
  <div className={`container ${styles.page}`}>
65
- <OrderStatusRefresh orderNumber={order.orderNumber} status={order.status} />
89
+ <OrderStatusRefresh orderNumber={order.orderNumber} orderKey={key} status={order.status} />
66
90
  <div className={styles.wrapper}>
67
91
  <div className={styles.successHeader}>
68
92
  {paid && (
@@ -96,13 +120,24 @@ export default async function OrderPage({ params }: OrderPageProps) {
96
120
  </p>
97
121
  </div>
98
122
 
123
+ <OrderTimeline
124
+ className={styles.summary}
125
+ entries={timeline}
126
+ serverHtml={
127
+ renderNymbal('nymbal-order-timeline', { entries: JSON.stringify(timeline) }).__html
128
+ }
129
+ />
130
+
99
131
  <OrderSummary
100
- items={order.lineItems}
132
+ className={styles.summary}
133
+ items={items}
101
134
  subtotalMinor={order.subtotalMinor}
102
- currency={order.currency}
103
- shippingTotalMinor={order.shippingTotalMinor}
104
- taxTotalMinor={order.taxTotalMinor}
135
+ discountMinor={order.discountTotalMinor ?? 0}
136
+ shippingMinor={order.shippingTotalMinor ?? 0}
137
+ taxMinor={order.taxTotalMinor ?? 0}
105
138
  totalMinor={order.totalMinor}
139
+ currency={order.currency}
140
+ serverHtml={renderNymbal('nymbal-order-summary', summary).__html}
106
141
  />
107
142
 
108
143
  <div className={styles.orderCard}>
@@ -10,7 +10,7 @@ interface ErrorProps {
10
10
 
11
11
  export default function ErrorPage({ error: _error, reset }: ErrorProps) {
12
12
  return (
13
- <div className={styles.page}>
13
+ <main id="main" className={styles.page}>
14
14
  <div className={styles.wrapper}>
15
15
  <div className={styles.icon}>
16
16
  <svg
@@ -35,15 +35,11 @@ export default function ErrorPage({ error: _error, reset }: ErrorProps) {
35
35
  <Link href="/" className={styles.homeLink}>
36
36
  Go Home
37
37
  </Link>
38
- <button
39
- type="button"
40
- className={styles.retryButton}
41
- onClick={reset}
42
- >
38
+ <button type="button" className={styles.retryButton} onClick={reset}>
43
39
  Try Again
44
40
  </button>
45
41
  </div>
46
42
  </div>
47
- </div>
43
+ </main>
48
44
  )
49
45
  }
@@ -0,0 +1,13 @@
1
+ import { FOOTER_COLUMNS } from '@/lib/chrome'
2
+ import { fragment } from '@/lib/fragments'
3
+ import { renderElement } from '@/lib/render'
4
+
5
+ export const revalidate = 86400
6
+
7
+ export function GET(): Response {
8
+ return fragment(
9
+ renderElement('nymbal-site-footer', {
10
+ attributes: { columns: JSON.stringify(FOOTER_COLUMNS) },
11
+ }),
12
+ )
13
+ }
@@ -0,0 +1,18 @@
1
+ import { fragment, noFragment } from '@/lib/fragments'
2
+ import { canSearch, siteHeader } from '@/lib/header'
3
+ import { renderElement } from '@/lib/render'
4
+
5
+ export const revalidate = 3600
6
+ // A dynamic segment, so the build prerenders nothing when the API may be down; next.config.mjs rewrites
7
+ // `/fragments/<name>` to `/fragments/<name>/index`.
8
+ export function generateStaticParams(): Array<{ key: string }> {
9
+ return []
10
+ }
11
+
12
+ export async function GET(
13
+ _request: Request,
14
+ { params }: { params: Promise<{ key: string }> },
15
+ ): Promise<Response> {
16
+ if ((await params).key !== 'index') return noFragment()
17
+ return fragment(renderElement('nymbal-site-header', siteHeader(await canSearch())))
18
+ }
@@ -0,0 +1,23 @@
1
+ import { fetchCategories } from '@/lib/api'
2
+ import { fragment, noFragment } from '@/lib/fragments'
3
+ import { renderElement } from '@/lib/render'
4
+
5
+ export const revalidate = 21600
6
+ // A dynamic segment, so the build prerenders nothing when the API may be down; next.config.mjs rewrites
7
+ // `/fragments/<name>` to `/fragments/<name>/index`.
8
+ export function generateStaticParams(): Array<{ key: string }> {
9
+ return []
10
+ }
11
+
12
+ export async function GET(
13
+ _request: Request,
14
+ { params }: { params: Promise<{ key: string }> },
15
+ ): Promise<Response> {
16
+ if ((await params).key !== 'index') return noFragment()
17
+ const categories = await fetchCategories()
18
+ return fragment(
19
+ renderElement('nymbal-category-nav', {
20
+ attributes: { categories: JSON.stringify(categories) },
21
+ }),
22
+ )
23
+ }
@@ -0,0 +1,22 @@
1
+ import { fetchProduct } from '@/lib/api'
2
+ import { fragment, noFragment } from '@/lib/fragments'
3
+ import { cardProductOf, renderElement } from '@/lib/render'
4
+
5
+ export const revalidate = 300
6
+ // The build prerenders no product, since the API may be down then.
7
+ export function generateStaticParams(): Array<{ slug: string }> {
8
+ return []
9
+ }
10
+
11
+ export async function GET(
12
+ _request: Request,
13
+ { params }: { params: Promise<{ slug: string }> },
14
+ ): Promise<Response> {
15
+ const product = await fetchProduct((await params).slug)
16
+ if (product === null) return noFragment()
17
+ return fragment(
18
+ renderElement('nymbal-product-card', {
19
+ attributes: { product: JSON.stringify(cardProductOf(product)) },
20
+ }),
21
+ )
22
+ }
@@ -1,4 +1,4 @@
1
- @import '@nymbalhq/web-components/tokens.css';
1
+ @import './tokens.css';
2
2
 
3
3
  /* ── CSS Reset ─────────────────────────────────────────────────────── */
4
4
 
@@ -169,7 +169,8 @@ a:focus-visible {
169
169
  border: 1px solid transparent;
170
170
  border-radius: var(--nymbal-radius-md);
171
171
  cursor: pointer;
172
- transition: background-color var(--nymbal-transition-fast),
172
+ transition:
173
+ background-color var(--nymbal-transition-fast),
173
174
  color var(--nymbal-transition-fast),
174
175
  border-color var(--nymbal-transition-fast),
175
176
  box-shadow var(--nymbal-transition-fast);
@@ -243,7 +244,8 @@ select {
243
244
  background-color: var(--nymbal-color-surface);
244
245
  border: 1px solid var(--nymbal-color-border);
245
246
  border-radius: var(--nymbal-radius-md);
246
- transition: border-color var(--nymbal-transition-fast),
247
+ transition:
248
+ border-color var(--nymbal-transition-fast),
247
249
  box-shadow var(--nymbal-transition-fast);
248
250
  appearance: none;
249
251
  }
@@ -281,26 +283,6 @@ label {
281
283
  margin-top: var(--nymbal-spacing-xs);
282
284
  }
283
285
 
284
- /* ── Product Grid ──────────────────────────────────────────────────── */
285
-
286
- .product-grid {
287
- display: grid;
288
- grid-template-columns: 1fr;
289
- gap: var(--nymbal-spacing-lg);
290
- }
291
-
292
- @media (min-width: 640px) {
293
- .product-grid {
294
- grid-template-columns: repeat(2, 1fr);
295
- }
296
- }
297
-
298
- @media (min-width: 1024px) {
299
- .product-grid {
300
- grid-template-columns: repeat(4, 1fr);
301
- }
302
- }
303
-
304
286
  /* ── Link Styles ───────────────────────────────────────────────────── */
305
287
 
306
288
  .link-muted {
@@ -2,25 +2,28 @@ import type { ReactNode } from 'react'
2
2
  import type { Metadata } from 'next'
3
3
  import './globals.css'
4
4
  import { NymbalSetup } from '@/components/client/NymbalSetup'
5
- import { Header } from '@/components/server/Header'
6
- import { Footer } from '@/components/server/Footer'
5
+ import { SiteFooter } from '@/components/client/elements'
7
6
  import { SkipNav } from '@/components/server/SkipNav'
8
7
  import { CartDrawerToggle } from '@/components/client/CartDrawerToggle'
8
+ import { FOOTER_COLUMNS } from '@/lib/chrome'
9
+ import { renderNymbal } from '@/lib/render'
9
10
 
10
11
  export const metadata: Metadata = {
11
12
  title: { default: 'Nymbal Store', template: '%s | Nymbal' },
12
13
  description: 'Shop the Nymbal store',
13
14
  }
14
15
 
16
+ // The root layout makes no API call: Next renders the 404 under it at build, when the API may be down. Each route
17
+ // group's layout brings the header the group's pages share, (catalog)'s cached for every shopper, (shopper)'s per request.
15
18
  export default function RootLayout({ children }: { children: ReactNode }) {
19
+ const footer = renderNymbal('nymbal-site-footer', { columns: JSON.stringify(FOOTER_COLUMNS) })
16
20
  return (
17
21
  <html lang="en">
18
22
  <body>
19
23
  <NymbalSetup>
20
24
  <SkipNav />
21
- <Header />
22
- <main id="main">{children}</main>
23
- <Footer />
25
+ {children}
26
+ <SiteFooter columns={FOOTER_COLUMNS} serverHtml={footer.__html} />
24
27
  <CartDrawerToggle />
25
28
  </NymbalSetup>
26
29
  </body>
@@ -1,38 +1,14 @@
1
- import Link from 'next/link'
2
- import styles from '@/styles/pages/error.module.css'
1
+ import { PlainHeader } from '@/components/server/Header'
2
+ import { NotFoundView } from '@/components/server/NotFoundView'
3
3
 
4
+ // A URL no route matches.
4
5
  export default function NotFound() {
5
6
  return (
6
- <div className={styles.page}>
7
- <div className={styles.wrapper}>
8
- <div className={`${styles.icon} ${styles.notFoundIcon}`}>
9
- <svg
10
- viewBox="0 0 24 24"
11
- fill="none"
12
- stroke="currentColor"
13
- strokeWidth="2"
14
- strokeLinecap="round"
15
- strokeLinejoin="round"
16
- aria-hidden="true"
17
- >
18
- <circle cx="11" cy="11" r="8" />
19
- <line x1="21" y1="21" x2="16.65" y2="16.65" />
20
- </svg>
21
- </div>
22
- <p className={styles.statusCode}>404</p>
23
- <h1 className={styles.title}>Page Not Found</h1>
24
- <p className={styles.message}>
25
- The page you are looking for does not exist or may have been moved.
26
- </p>
27
- <div className={styles.actions}>
28
- <Link href="/" className={styles.homeLink}>
29
- Go Home
30
- </Link>
31
- <Link href="/products" className={styles.retryButton}>
32
- Browse Products
33
- </Link>
34
- </div>
35
- </div>
36
- </div>
7
+ <>
8
+ <PlainHeader />
9
+ <main id="main">
10
+ <NotFoundView />
11
+ </main>
12
+ </>
37
13
  )
38
14
  }