create-nymbal-app 0.6.0 → 0.7.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 (29) hide show
  1. package/dist/index.js +5 -2
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/scaffold/templates/astro/astro.config.mjs +3 -0
  5. package/scaffold/templates/astro/package.json +25 -25
  6. package/scaffold/templates/astro/src/layouts/AccountLayout.astro +1 -0
  7. package/scaffold/templates/astro/src/layouts/BaseLayout.astro +3 -1
  8. package/scaffold/templates/astro/src/lib/api.ts +15 -5
  9. package/scaffold/templates/astro/src/lib/client.ts +5 -2
  10. package/scaffold/templates/astro/src/pages/account/index.astro +1 -0
  11. package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +1 -1
  12. package/scaffold/templates/astro/src/pages/cart.astro +3 -0
  13. package/scaffold/templates/astro/src/pages/checkout.astro +9 -2
  14. package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +152 -59
  15. package/scaffold/templates/astro/src/scripts/account-guard.ts +1 -0
  16. package/scaffold/templates/astro/src/scripts/order-access.ts +154 -0
  17. package/scaffold/templates/astro/src/scripts/pdp.ts +1 -0
  18. package/scaffold/templates/astro/src/scripts/plp.ts +1 -0
  19. package/scaffold/templates/astro/src/scripts/search.ts +1 -0
  20. package/scaffold/templates/nextjs/app/(shopper)/checkout/CheckoutView.tsx +6 -2
  21. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderDetails.tsx +23 -0
  22. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderEmailPrompt.tsx +90 -0
  23. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderLinkForm.tsx +73 -0
  24. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderNotFound.tsx +25 -0
  25. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderView.tsx +140 -0
  26. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/not-found.tsx +6 -0
  27. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/page.tsx +6 -134
  28. package/scaffold/templates/nextjs/lib/api.ts +13 -5
  29. package/scaffold/templates/nextjs/package.json +26 -26
@@ -0,0 +1,25 @@
1
+ import Link from 'next/link'
2
+ import styles from '@/styles/pages/error.module.css'
3
+ import { OrderLinkForm } from './OrderLinkForm'
4
+
5
+ /** The order page's not-found state: what the site's 404 says, and a way to ask for a fresh order link. */
6
+ export function OrderNotFound() {
7
+ return (
8
+ <div className={styles.page}>
9
+ <div className={styles.wrapper}>
10
+ <p className={styles.statusCode}>404</p>
11
+ <h1 className={styles.title}>Order not found</h1>
12
+ <p className={styles.message}>
13
+ This link does not open an order. Give its order number and the email you gave at
14
+ checkout, and we&apos;ll email you a fresh link if they match.
15
+ </p>
16
+ <OrderLinkForm />
17
+ <div className={styles.actions}>
18
+ <Link href="/products" className={styles.retryButton}>
19
+ Browse Products
20
+ </Link>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ )
25
+ }
@@ -0,0 +1,140 @@
1
+ import Link from 'next/link'
2
+ import type { ReactNode } from 'react'
3
+ import type { ShopperAddress, ShopperOrder } from '@nymbalhq/types'
4
+ import { OrderSummary, OrderTimeline } from '@/components/client/elements'
5
+ import { isPaid, orderHeading } from '@/lib/order-status'
6
+ import styles from '@/styles/pages/confirmation.module.css'
7
+
8
+ function AddressBlock({ title, address }: { title: string; address: ShopperAddress }) {
9
+ return (
10
+ <div className={styles.addressCard}>
11
+ <h4 className={styles.addressTitle}>{title}</h4>
12
+ <p className={styles.addressText}>
13
+ {address.firstName} {address.lastName}
14
+ <br />
15
+ {address.addressLine1}
16
+ {address.addressLine2 && <>, {address.addressLine2}</>}
17
+ <br />
18
+ {address.city}, {address.region} {address.postalCode}
19
+ <br />
20
+ {address.country}
21
+ </p>
22
+ </div>
23
+ )
24
+ }
25
+
26
+ /** The order summary element's attributes, as the server renders them and the browser keeps them. */
27
+ export function summaryAttributes(order: ShopperOrder): Record<string, string> {
28
+ return {
29
+ items: JSON.stringify(summaryItems(order)),
30
+ 'subtotal-minor': String(order.subtotalMinor),
31
+ 'discount-minor': String(order.discountTotalMinor ?? 0),
32
+ 'shipping-minor': String(order.shippingTotalMinor ?? 0),
33
+ 'tax-minor': String(order.taxTotalMinor ?? 0),
34
+ 'total-minor': String(order.totalMinor),
35
+ currency: order.currency,
36
+ }
37
+ }
38
+
39
+ function summaryItems(order: ShopperOrder) {
40
+ return order.lineItems.map((item) => ({
41
+ name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
42
+ qty: item.qty,
43
+ unitPriceMinor: item.unitPriceMinor,
44
+ lineTotalMinor: item.lineTotalMinor,
45
+ }))
46
+ }
47
+
48
+ /**
49
+ * The order as its key opens it: the confirmation page's fields and where it ships. A key holder reads no billing
50
+ * address and no email, so the page shows neither. The server passes the elements' server HTML and the status poll;
51
+ * the email prompt renders it in the browser with neither.
52
+ */
53
+ export function OrderView({
54
+ order,
55
+ timelineHtml,
56
+ summaryHtml,
57
+ refresh,
58
+ }: {
59
+ order: ShopperOrder
60
+ timelineHtml?: string
61
+ summaryHtml?: string
62
+ refresh?: ReactNode
63
+ }) {
64
+ const paid = isPaid(order.status)
65
+ const items = summaryItems(order)
66
+ const timeline = order.timeline ?? []
67
+
68
+ return (
69
+ <div className={`container ${styles.page}`}>
70
+ {refresh}
71
+ <div className={styles.wrapper}>
72
+ <div className={styles.successHeader}>
73
+ {paid && (
74
+ <div className={styles.checkCircle}>
75
+ <svg
76
+ viewBox="0 0 24 24"
77
+ fill="none"
78
+ stroke="currentColor"
79
+ strokeWidth="2"
80
+ strokeLinecap="round"
81
+ strokeLinejoin="round"
82
+ aria-hidden="true"
83
+ >
84
+ <polyline points="20 6 9 17 4 12" />
85
+ </svg>
86
+ </div>
87
+ )}
88
+ <h1 className={styles.successTitle} data-testid="order-heading">
89
+ {orderHeading(order.status)}
90
+ </h1>
91
+ <p className={styles.successSubtitle}>
92
+ {paid ? 'Thank you for your order. ' : ''}Your order number is{' '}
93
+ <span className={styles.orderNumber} data-testid="order-number">
94
+ {order.orderNumber}
95
+ </span>
96
+ . Status:{' '}
97
+ <span data-testid="order-status" style={{ textTransform: 'capitalize' }}>
98
+ {order.status}
99
+ </span>
100
+ .{order.status === 'pending' && ' We will confirm it once the payment arrives.'}
101
+ </p>
102
+ </div>
103
+
104
+ <OrderTimeline
105
+ className={styles.summary}
106
+ entries={timeline}
107
+ {...(timelineHtml !== undefined && { serverHtml: timelineHtml })}
108
+ />
109
+
110
+ <OrderSummary
111
+ className={styles.summary}
112
+ items={items}
113
+ subtotalMinor={order.subtotalMinor}
114
+ discountMinor={order.discountTotalMinor ?? 0}
115
+ shippingMinor={order.shippingTotalMinor ?? 0}
116
+ taxMinor={order.taxTotalMinor ?? 0}
117
+ totalMinor={order.totalMinor}
118
+ currency={order.currency}
119
+ {...(summaryHtml !== undefined && { serverHtml: summaryHtml })}
120
+ />
121
+
122
+ <div className={styles.orderCard}>
123
+ <h3 className={styles.orderCardTitle}>Delivery Details</h3>
124
+ <div className={styles.addressGrid}>
125
+ <AddressBlock title="Shipping Address" address={order.shippingAddress} />
126
+ </div>
127
+ </div>
128
+
129
+ <div className={styles.actions}>
130
+ <Link href="/products" className={styles.continueButton}>
131
+ Continue Shopping
132
+ </Link>
133
+ <Link href="/account/orders" className={styles.orderLink}>
134
+ View All Orders
135
+ </Link>
136
+ </div>
137
+ </div>
138
+ </div>
139
+ )
140
+ }
@@ -0,0 +1,6 @@
1
+ import { OrderNotFound } from './OrderNotFound'
2
+
3
+ // An order the store does not know, or one read without what opens it: the shopper can ask for a fresh link.
4
+ export default function OrderPageNotFound() {
5
+ return <OrderNotFound />
6
+ }
@@ -1,12 +1,8 @@
1
1
  import type { Metadata } from 'next'
2
2
  import { notFound } from 'next/navigation'
3
- import Link from 'next/link'
4
3
  import { loadOrder } from '@/lib/api'
5
- import { OrderSummary, OrderTimeline } from '@/components/client/elements'
6
- import { renderNymbal } from '@/lib/render'
7
- import { OrderStatusRefresh } from '@/components/client/OrderStatusRefresh'
8
- import { isPaid, orderHeading } from '@/lib/order-status'
9
- import styles from '@/styles/pages/confirmation.module.css'
4
+ import { OrderDetails } from './OrderDetails'
5
+ import { OrderEmailPrompt } from './OrderEmailPrompt'
10
6
 
11
7
  interface OrderPageProps {
12
8
  params: Promise<{ orderNumber: string }>
@@ -23,41 +19,6 @@ export async function generateMetadata({ params }: OrderPageProps): Promise<Meta
23
19
  }
24
20
  }
25
21
 
26
- function AddressBlock({
27
- title,
28
- address,
29
- }: {
30
- title: string
31
- address: {
32
- firstName?: string
33
- lastName?: string
34
- addressLine1: string
35
- addressLine2?: string
36
- city: string
37
- region: string
38
- postalCode: string
39
- country: string
40
- } | null
41
- }) {
42
- if (!address) return null
43
-
44
- return (
45
- <div className={styles.addressCard}>
46
- <h4 className={styles.addressTitle}>{title}</h4>
47
- <p className={styles.addressText}>
48
- {address.firstName} {address.lastName}
49
- <br />
50
- {address.addressLine1}
51
- {address.addressLine2 && <>, {address.addressLine2}</>}
52
- <br />
53
- {address.city}, {address.region} {address.postalCode}
54
- <br />
55
- {address.country}
56
- </p>
57
- </div>
58
- )
59
- }
60
-
61
22
  export default async function OrderPage({ params, searchParams }: OrderPageProps) {
62
23
  const { orderNumber } = await params
63
24
  const { key: keyParam } = await searchParams
@@ -65,98 +26,9 @@ export default async function OrderPage({ params, searchParams }: OrderPageProps
65
26
  // Rejects when the API fails, so a failed read is a 500 and never a 404 for an order the shopper has.
66
27
  const order = await loadOrder(orderNumber, key)
67
28
 
29
+ // Only the order's own key is told it has expired: the page asks for the order's email to open it.
30
+ if (order === 'expired')
31
+ return <OrderEmailPrompt orderNumber={orderNumber} orderKey={key ?? ''} />
68
32
  if (!order) notFound()
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 ?? []
86
-
87
- return (
88
- <div className={`container ${styles.page}`}>
89
- <OrderStatusRefresh orderNumber={order.orderNumber} orderKey={key} status={order.status} />
90
- <div className={styles.wrapper}>
91
- <div className={styles.successHeader}>
92
- {paid && (
93
- <div className={styles.checkCircle}>
94
- <svg
95
- viewBox="0 0 24 24"
96
- fill="none"
97
- stroke="currentColor"
98
- strokeWidth="2"
99
- strokeLinecap="round"
100
- strokeLinejoin="round"
101
- aria-hidden="true"
102
- >
103
- <polyline points="20 6 9 17 4 12" />
104
- </svg>
105
- </div>
106
- )}
107
- <h1 className={styles.successTitle} data-testid="order-heading">
108
- {orderHeading(order.status)}
109
- </h1>
110
- <p className={styles.successSubtitle}>
111
- {paid ? 'Thank you for your order. ' : ''}Your order number is{' '}
112
- <span className={styles.orderNumber} data-testid="order-number">
113
- {order.orderNumber}
114
- </span>
115
- . Status:{' '}
116
- <span data-testid="order-status" style={{ textTransform: 'capitalize' }}>
117
- {order.status}
118
- </span>
119
- .{order.status === 'pending' && ' We will confirm it once the payment arrives.'}
120
- </p>
121
- </div>
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
-
131
- <OrderSummary
132
- className={styles.summary}
133
- items={items}
134
- subtotalMinor={order.subtotalMinor}
135
- discountMinor={order.discountTotalMinor ?? 0}
136
- shippingMinor={order.shippingTotalMinor ?? 0}
137
- taxMinor={order.taxTotalMinor ?? 0}
138
- totalMinor={order.totalMinor}
139
- currency={order.currency}
140
- serverHtml={renderNymbal('nymbal-order-summary', summary).__html}
141
- />
142
-
143
- <div className={styles.orderCard}>
144
- <h3 className={styles.orderCardTitle}>Delivery Details</h3>
145
- <div className={styles.addressGrid}>
146
- <AddressBlock title="Shipping Address" address={order.shippingAddress} />
147
- <AddressBlock title="Billing Address" address={order.billingAddress} />
148
- </div>
149
- </div>
150
-
151
- <div className={styles.actions}>
152
- <Link href="/products" className={styles.continueButton}>
153
- Continue Shopping
154
- </Link>
155
- <Link href="/account/orders" className={styles.orderLink}>
156
- View All Orders
157
- </Link>
158
- </div>
159
- </div>
160
- </div>
161
- )
33
+ return <OrderDetails order={order} {...(key !== undefined && { orderKey: key })} />
162
34
  }
@@ -120,17 +120,25 @@ export async function fetchCategories(): Promise<Category[]> {
120
120
  }
121
121
 
122
122
  /**
123
- * The order its key opens, `key` being the confirmation URL's `?key=`. Null on a 404, which the API answers alike for
124
- * an unknown number and for an order read without its key; rejects when the API fails, so the order page's failed read
125
- * is a 500 and never a not-found page for an order the shopper has. The key goes in a header, never in the API's URL.
123
+ * The order its key opens, `key` being the confirmation URL's `?key=`. `'expired'` when the API says the key has
124
+ * expired, so the page can ask for the order's email, which the browser sends itself: a read from this server would
125
+ * count every shopper's tries under the server's one address. Null on any other 404, which the API answers alike for
126
+ * an unknown number and an order read without its key; rejects when the API fails, so the order page's failed read is
127
+ * a 500 and never a not-found page for an order the shopper has. The key goes in a header, never in the API's URL.
126
128
  */
127
- export async function loadOrder(orderNumber: string, key?: string): Promise<ShopperOrder | null> {
129
+ export async function loadOrder(
130
+ orderNumber: string,
131
+ key?: string,
132
+ ): Promise<ShopperOrder | 'expired' | null> {
128
133
  const url = `${API_URL}/api/orders/${encodeURIComponent(orderNumber)}`
129
134
  const res = await fetch(url, {
130
135
  cache: 'no-store',
131
136
  headers: key ? { [ORDER_KEY_HEADER]: key } : {},
132
137
  })
133
- if (res.status === 404) return null
138
+ if (res.status === 404) {
139
+ const refusal = (await res.json().catch(() => null)) as { error?: { code?: string } } | null
140
+ return refusal?.error?.code === 'orders.key_expired' ? 'expired' : null
141
+ }
134
142
  if (!res.ok) throw new Error(`[api] GET ${url} answered ${res.status}`)
135
143
  const envelope = (await res.json()) as { data?: ShopperOrder | null }
136
144
  if (!envelope.data) throw new Error(`[api] GET ${url} answered no data`)
@@ -17,17 +17,17 @@
17
17
  "seed": "nymbal seed"
18
18
  },
19
19
  "dependencies": {
20
- "nymbal": "1.4.0",
21
- "@nymbalhq/config": "1.4.0",
22
- "@nymbalhq/platform": "1.4.0",
23
- "@nymbalhq/stack": "1.4.0",
20
+ "nymbal": "1.5.0",
21
+ "@nymbalhq/config": "1.5.0",
22
+ "@nymbalhq/platform": "1.5.0",
23
+ "@nymbalhq/stack": "1.5.0",
24
24
  "next": "^16.4.2",
25
25
  "react": "^19.3.1",
26
26
  "react-dom": "^19.3.1",
27
- "@nymbalhq/sdk": "1.4.0",
28
- "@nymbalhq/react": "1.4.0",
29
- "@nymbalhq/web-components": "1.4.0",
30
- "@nymbalhq/types": "1.4.0"
27
+ "@nymbalhq/sdk": "1.5.0",
28
+ "@nymbalhq/react": "1.5.0",
29
+ "@nymbalhq/web-components": "1.5.0",
30
+ "@nymbalhq/types": "1.5.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.9.0",
@@ -38,26 +38,26 @@
38
38
  },
39
39
  "pnpm": {
40
40
  "overrides": {
41
- "nymbal": "1.4.0",
42
- "@nymbalhq/config": "1.4.0",
43
- "@nymbalhq/http": "1.4.0",
44
- "@nymbalhq/platform": "1.4.0",
45
- "@nymbalhq/react": "1.4.0",
46
- "@nymbalhq/sdk": "1.4.0",
47
- "@nymbalhq/stack": "1.4.0",
48
- "@nymbalhq/types": "1.4.0",
49
- "@nymbalhq/web-components": "1.4.0"
41
+ "nymbal": "1.5.0",
42
+ "@nymbalhq/config": "1.5.0",
43
+ "@nymbalhq/http": "1.5.0",
44
+ "@nymbalhq/platform": "1.5.0",
45
+ "@nymbalhq/react": "1.5.0",
46
+ "@nymbalhq/sdk": "1.5.0",
47
+ "@nymbalhq/stack": "1.5.0",
48
+ "@nymbalhq/types": "1.5.0",
49
+ "@nymbalhq/web-components": "1.5.0"
50
50
  }
51
51
  },
52
52
  "overrides": {
53
- "nymbal": "1.4.0",
54
- "@nymbalhq/config": "1.4.0",
55
- "@nymbalhq/http": "1.4.0",
56
- "@nymbalhq/platform": "1.4.0",
57
- "@nymbalhq/react": "1.4.0",
58
- "@nymbalhq/sdk": "1.4.0",
59
- "@nymbalhq/stack": "1.4.0",
60
- "@nymbalhq/types": "1.4.0",
61
- "@nymbalhq/web-components": "1.4.0"
53
+ "nymbal": "1.5.0",
54
+ "@nymbalhq/config": "1.5.0",
55
+ "@nymbalhq/http": "1.5.0",
56
+ "@nymbalhq/platform": "1.5.0",
57
+ "@nymbalhq/react": "1.5.0",
58
+ "@nymbalhq/sdk": "1.5.0",
59
+ "@nymbalhq/stack": "1.5.0",
60
+ "@nymbalhq/types": "1.5.0",
61
+ "@nymbalhq/web-components": "1.5.0"
62
62
  }
63
63
  }