create-nymbal-app 0.5.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.
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scaffold/templates/astro/astro.config.mjs +3 -0
- package/scaffold/templates/astro/package.json +25 -25
- package/scaffold/templates/astro/src/layouts/AccountLayout.astro +1 -0
- package/scaffold/templates/astro/src/layouts/BaseLayout.astro +3 -1
- package/scaffold/templates/astro/src/lib/api.ts +64 -22
- package/scaffold/templates/astro/src/lib/client.ts +5 -2
- package/scaffold/templates/astro/src/pages/404.astro +3 -0
- package/scaffold/templates/astro/src/pages/account/index.astro +1 -0
- package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +11 -3
- package/scaffold/templates/astro/src/pages/alerts/confirm.astro +59 -0
- package/scaffold/templates/astro/src/pages/alerts/unsubscribe.astro +53 -0
- package/scaffold/templates/astro/src/pages/cart.astro +3 -0
- package/scaffold/templates/astro/src/pages/category/[slug].astro +8 -6
- package/scaffold/templates/astro/src/pages/checkout.astro +10 -3
- package/scaffold/templates/astro/src/pages/index.astro +7 -0
- package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +158 -54
- package/scaffold/templates/astro/src/pages/product/[slug].astro +20 -4
- package/scaffold/templates/astro/src/scripts/account-guard.ts +1 -0
- package/scaffold/templates/astro/src/scripts/order-access.ts +154 -0
- package/scaffold/templates/astro/src/scripts/order-status.ts +3 -1
- package/scaffold/templates/astro/src/scripts/pdp.ts +6 -0
- package/scaffold/templates/astro/src/scripts/plp.ts +1 -0
- package/scaffold/templates/astro/src/scripts/search.ts +1 -0
- package/scaffold/templates/astro/src/styles/pages/account.css +4 -0
- package/scaffold/templates/nextjs/app/(catalog)/home/[key]/page.tsx +6 -1
- package/scaffold/templates/nextjs/app/(catalog)/product/[slug]/page.tsx +22 -3
- package/scaffold/templates/nextjs/app/(shopper)/account/orders/[orderNumber]/page.tsx +10 -3
- package/scaffold/templates/nextjs/app/(shopper)/alerts/AlertLinkForm.tsx +90 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/LinkInvalid.tsx +19 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/actions.ts +33 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/confirm/page.tsx +19 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/unsubscribe/page.tsx +17 -0
- package/scaffold/templates/nextjs/app/(shopper)/checkout/CheckoutView.tsx +20 -9
- package/scaffold/templates/nextjs/app/(shopper)/not-found.tsx +6 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderDetails.tsx +23 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderEmailPrompt.tsx +90 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderLinkForm.tsx +73 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderNotFound.tsx +25 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderView.tsx +140 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/not-found.tsx +6 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/page.tsx +17 -129
- package/scaffold/templates/nextjs/app/not-found.tsx +1 -1
- package/scaffold/templates/nextjs/components/client/OrderStatusRefresh.tsx +8 -2
- package/scaffold/templates/nextjs/components/client/ProductInteractive.tsx +18 -1
- package/scaffold/templates/nextjs/components/client/elements.tsx +2 -0
- package/scaffold/templates/nextjs/lib/api.ts +62 -14
- package/scaffold/templates/nextjs/next.config.mjs +9 -0
- package/scaffold/templates/nextjs/package.json +26 -26
|
@@ -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
|
+
}
|
|
@@ -1,146 +1,34 @@
|
|
|
1
1
|
import type { Metadata } from 'next'
|
|
2
2
|
import { notFound } from 'next/navigation'
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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'
|
|
3
|
+
import { loadOrder } from '@/lib/api'
|
|
4
|
+
import { OrderDetails } from './OrderDetails'
|
|
5
|
+
import { OrderEmailPrompt } from './OrderEmailPrompt'
|
|
10
6
|
|
|
11
7
|
interface OrderPageProps {
|
|
12
8
|
params: Promise<{ orderNumber: string }>
|
|
9
|
+
searchParams: Promise<{ key?: string | string[] }>
|
|
13
10
|
}
|
|
14
11
|
|
|
12
|
+
// The URL carries the order's key (`?key=`), so nothing this page links to or loads may be told the URL: the meta
|
|
13
|
+
// tag here, and the header next.config.mjs sets on every /order/<n> response, the not-found render's too.
|
|
15
14
|
export async function generateMetadata({ params }: OrderPageProps): Promise<Metadata> {
|
|
16
15
|
const { orderNumber } = await params
|
|
17
16
|
return {
|
|
18
17
|
title: `Order ${orderNumber}`,
|
|
18
|
+
referrer: 'no-referrer',
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
function
|
|
23
|
-
title,
|
|
24
|
-
address,
|
|
25
|
-
}: {
|
|
26
|
-
title: string
|
|
27
|
-
address: {
|
|
28
|
-
firstName?: string
|
|
29
|
-
lastName?: string
|
|
30
|
-
addressLine1: string
|
|
31
|
-
addressLine2?: string
|
|
32
|
-
city: string
|
|
33
|
-
region: string
|
|
34
|
-
postalCode: string
|
|
35
|
-
country: string
|
|
36
|
-
} | null
|
|
37
|
-
}) {
|
|
38
|
-
if (!address) return null
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<div className={styles.addressCard}>
|
|
42
|
-
<h4 className={styles.addressTitle}>{title}</h4>
|
|
43
|
-
<p className={styles.addressText}>
|
|
44
|
-
{address.firstName} {address.lastName}
|
|
45
|
-
<br />
|
|
46
|
-
{address.addressLine1}
|
|
47
|
-
{address.addressLine2 && <>, {address.addressLine2}</>}
|
|
48
|
-
<br />
|
|
49
|
-
{address.city}, {address.region} {address.postalCode}
|
|
50
|
-
<br />
|
|
51
|
-
{address.country}
|
|
52
|
-
</p>
|
|
53
|
-
</div>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default async function OrderPage({ params }: OrderPageProps) {
|
|
22
|
+
export default async function OrderPage({ params, searchParams }: OrderPageProps) {
|
|
58
23
|
const { orderNumber } = await params
|
|
59
|
-
const
|
|
60
|
-
|
|
24
|
+
const { key: keyParam } = await searchParams
|
|
25
|
+
const key = Array.isArray(keyParam) ? keyParam[0] : keyParam
|
|
26
|
+
// Rejects when the API fails, so a failed read is a 500 and never a 404 for an order the shopper has.
|
|
27
|
+
const order = await loadOrder(orderNumber, key)
|
|
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 ?? ''} />
|
|
61
32
|
if (!order) notFound()
|
|
62
|
-
|
|
63
|
-
const items = order.lineItems.map((item) => ({
|
|
64
|
-
name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
|
|
65
|
-
qty: item.qty,
|
|
66
|
-
unitPriceMinor: item.unitPriceMinor,
|
|
67
|
-
lineTotalMinor: item.lineTotalMinor,
|
|
68
|
-
}))
|
|
69
|
-
const summary = {
|
|
70
|
-
items: JSON.stringify(items),
|
|
71
|
-
'subtotal-minor': String(order.subtotalMinor),
|
|
72
|
-
'discount-minor': String(order.discountTotalMinor ?? 0),
|
|
73
|
-
'shipping-minor': String(order.shippingTotalMinor ?? 0),
|
|
74
|
-
'tax-minor': String(order.taxTotalMinor ?? 0),
|
|
75
|
-
'total-minor': String(order.totalMinor),
|
|
76
|
-
currency: order.currency,
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<div className={`container ${styles.page}`}>
|
|
81
|
-
<OrderStatusRefresh orderNumber={order.orderNumber} status={order.status} />
|
|
82
|
-
<div className={styles.wrapper}>
|
|
83
|
-
<div className={styles.successHeader}>
|
|
84
|
-
{paid && (
|
|
85
|
-
<div className={styles.checkCircle}>
|
|
86
|
-
<svg
|
|
87
|
-
viewBox="0 0 24 24"
|
|
88
|
-
fill="none"
|
|
89
|
-
stroke="currentColor"
|
|
90
|
-
strokeWidth="2"
|
|
91
|
-
strokeLinecap="round"
|
|
92
|
-
strokeLinejoin="round"
|
|
93
|
-
aria-hidden="true"
|
|
94
|
-
>
|
|
95
|
-
<polyline points="20 6 9 17 4 12" />
|
|
96
|
-
</svg>
|
|
97
|
-
</div>
|
|
98
|
-
)}
|
|
99
|
-
<h1 className={styles.successTitle} data-testid="order-heading">
|
|
100
|
-
{orderHeading(order.status)}
|
|
101
|
-
</h1>
|
|
102
|
-
<p className={styles.successSubtitle}>
|
|
103
|
-
{paid ? 'Thank you for your order. ' : ''}Your order number is{' '}
|
|
104
|
-
<span className={styles.orderNumber} data-testid="order-number">
|
|
105
|
-
{order.orderNumber}
|
|
106
|
-
</span>
|
|
107
|
-
. Status:{' '}
|
|
108
|
-
<span data-testid="order-status" style={{ textTransform: 'capitalize' }}>
|
|
109
|
-
{order.status}
|
|
110
|
-
</span>
|
|
111
|
-
.{order.status === 'pending' && ' We will confirm it once the payment arrives.'}
|
|
112
|
-
</p>
|
|
113
|
-
</div>
|
|
114
|
-
|
|
115
|
-
<OrderSummary
|
|
116
|
-
className={styles.summary}
|
|
117
|
-
items={items}
|
|
118
|
-
subtotalMinor={order.subtotalMinor}
|
|
119
|
-
discountMinor={order.discountTotalMinor ?? 0}
|
|
120
|
-
shippingMinor={order.shippingTotalMinor ?? 0}
|
|
121
|
-
taxMinor={order.taxTotalMinor ?? 0}
|
|
122
|
-
totalMinor={order.totalMinor}
|
|
123
|
-
currency={order.currency}
|
|
124
|
-
serverHtml={renderNymbal('nymbal-order-summary', summary).__html}
|
|
125
|
-
/>
|
|
126
|
-
|
|
127
|
-
<div className={styles.orderCard}>
|
|
128
|
-
<h3 className={styles.orderCardTitle}>Delivery Details</h3>
|
|
129
|
-
<div className={styles.addressGrid}>
|
|
130
|
-
<AddressBlock title="Shipping Address" address={order.shippingAddress} />
|
|
131
|
-
<AddressBlock title="Billing Address" address={order.billingAddress} />
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
|
134
|
-
|
|
135
|
-
<div className={styles.actions}>
|
|
136
|
-
<Link href="/products" className={styles.continueButton}>
|
|
137
|
-
Continue Shopping
|
|
138
|
-
</Link>
|
|
139
|
-
<Link href="/account/orders" className={styles.orderLink}>
|
|
140
|
-
View All Orders
|
|
141
|
-
</Link>
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
</div>
|
|
145
|
-
)
|
|
33
|
+
return <OrderDetails order={order} {...(key !== undefined && { orderKey: key })} />
|
|
146
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PlainHeader } from '@/components/server/Header'
|
|
2
2
|
import { NotFoundView } from '@/components/server/NotFoundView'
|
|
3
3
|
|
|
4
|
-
// A URL no route matches
|
|
4
|
+
// A URL no route matches.
|
|
5
5
|
export default function NotFound() {
|
|
6
6
|
return (
|
|
7
7
|
<>
|
|
@@ -12,9 +12,12 @@ const POLL_FOR_MS = 10_000
|
|
|
12
12
|
|
|
13
13
|
export function OrderStatusRefresh({
|
|
14
14
|
orderNumber,
|
|
15
|
+
orderKey,
|
|
15
16
|
status,
|
|
16
17
|
}: {
|
|
17
18
|
orderNumber: string
|
|
19
|
+
/** The page's `?key=`: the API answers a guest's order to its key only. */
|
|
20
|
+
orderKey?: string | undefined
|
|
18
21
|
status: OrderStatus
|
|
19
22
|
}) {
|
|
20
23
|
const router = useRouter()
|
|
@@ -26,7 +29,10 @@ export function OrderStatusRefresh({
|
|
|
26
29
|
let stopped = false
|
|
27
30
|
const poll = async () => {
|
|
28
31
|
try {
|
|
29
|
-
const order = await getNymbalClient().customer.orders.get(
|
|
32
|
+
const order = await getNymbalClient().customer.orders.get(
|
|
33
|
+
orderNumber,
|
|
34
|
+
orderKey ? { key: orderKey } : {},
|
|
35
|
+
)
|
|
30
36
|
if (stopped) return
|
|
31
37
|
if (order.status !== status) {
|
|
32
38
|
router.refresh()
|
|
@@ -42,7 +48,7 @@ export function OrderStatusRefresh({
|
|
|
42
48
|
stopped = true
|
|
43
49
|
clearTimeout(timer)
|
|
44
50
|
}
|
|
45
|
-
}, [orderNumber, status, router])
|
|
51
|
+
}, [orderNumber, orderKey, status, router])
|
|
46
52
|
|
|
47
53
|
return null
|
|
48
54
|
}
|
|
@@ -9,11 +9,14 @@ import {
|
|
|
9
9
|
ProductPrice,
|
|
10
10
|
QuantitySelector,
|
|
11
11
|
StockBadge,
|
|
12
|
+
NotifyMe,
|
|
12
13
|
} from '@nymbalhq/react'
|
|
13
14
|
import styles from '@/styles/pages/pdp.module.css'
|
|
14
15
|
|
|
15
16
|
interface ProductInteractiveProps {
|
|
16
17
|
product: DenormalisedProduct
|
|
18
|
+
/** The store's email delivers, so the page offers a back-in-stock alert (GET /api/capabilities). */
|
|
19
|
+
offersAlerts?: boolean
|
|
17
20
|
/** The server's render of each element, for the product's first variant (app/product/[slug]/page.tsx). */
|
|
18
21
|
serverHtml?: {
|
|
19
22
|
price: string
|
|
@@ -21,10 +24,15 @@ interface ProductInteractiveProps {
|
|
|
21
24
|
variantSelector: string
|
|
22
25
|
quantity: string
|
|
23
26
|
addToCart: string
|
|
27
|
+
notifyMe?: string | undefined
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
export function ProductInteractive({
|
|
31
|
+
export function ProductInteractive({
|
|
32
|
+
product,
|
|
33
|
+
offersAlerts = false,
|
|
34
|
+
serverHtml,
|
|
35
|
+
}: ProductInteractiveProps) {
|
|
28
36
|
const { selectedVariant } = useProduct(product.slug)
|
|
29
37
|
|
|
30
38
|
const variant = selectedVariant ?? product.variants?.[0]
|
|
@@ -92,6 +100,15 @@ export function ProductInteractive({ product, serverHtml }: ProductInteractivePr
|
|
|
92
100
|
serverHtml={serverHtml?.addToCart}
|
|
93
101
|
/>
|
|
94
102
|
</div>
|
|
103
|
+
|
|
104
|
+
{offersAlerts && first !== undefined && (
|
|
105
|
+
<NotifyMe
|
|
106
|
+
productId={product.id}
|
|
107
|
+
variantId={first.id}
|
|
108
|
+
stock={first.stock ?? 0}
|
|
109
|
+
serverHtml={serverHtml?.notifyMe}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
95
112
|
</div>
|
|
96
113
|
)
|
|
97
114
|
}
|
|
@@ -6,8 +6,15 @@ import type {
|
|
|
6
6
|
ProductSearchResult,
|
|
7
7
|
ReviewsListResult,
|
|
8
8
|
} from '@nymbalhq/sdk'
|
|
9
|
-
import { DEFAULT_PRODUCT_SORT, PRODUCT_SORT_KEYS } from '@nymbalhq/types'
|
|
10
|
-
import type {
|
|
9
|
+
import { DEFAULT_PRODUCT_SORT, ORDER_KEY_HEADER, PRODUCT_SORT_KEYS } from '@nymbalhq/types'
|
|
10
|
+
import type {
|
|
11
|
+
AlertKind,
|
|
12
|
+
Cart,
|
|
13
|
+
Category,
|
|
14
|
+
ProductSortKey,
|
|
15
|
+
ShopperOrder,
|
|
16
|
+
StoreCapabilities,
|
|
17
|
+
} from '@nymbalhq/types'
|
|
11
18
|
|
|
12
19
|
const API_URL = process.env.NYMBAL_API_URL ?? 'http://localhost:3001'
|
|
13
20
|
|
|
@@ -112,19 +119,30 @@ export async function fetchCategories(): Promise<Category[]> {
|
|
|
112
119
|
return envelope.data
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
/**
|
|
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.
|
|
128
|
+
*/
|
|
129
|
+
export async function loadOrder(
|
|
130
|
+
orderNumber: string,
|
|
131
|
+
key?: string,
|
|
132
|
+
): Promise<ShopperOrder | 'expired' | null> {
|
|
133
|
+
const url = `${API_URL}/api/orders/${encodeURIComponent(orderNumber)}`
|
|
134
|
+
const res = await fetch(url, {
|
|
135
|
+
cache: 'no-store',
|
|
136
|
+
headers: key ? { [ORDER_KEY_HEADER]: key } : {},
|
|
137
|
+
})
|
|
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
|
|
127
141
|
}
|
|
142
|
+
if (!res.ok) throw new Error(`[api] GET ${url} answered ${res.status}`)
|
|
143
|
+
const envelope = (await res.json()) as { data?: ShopperOrder | null }
|
|
144
|
+
if (!envelope.data) throw new Error(`[api] GET ${url} answered no data`)
|
|
145
|
+
return envelope.data
|
|
128
146
|
}
|
|
129
147
|
|
|
130
148
|
export async function fetchReviews(productId: string): Promise<ReviewsListResult> {
|
|
@@ -203,3 +221,33 @@ export async function fetchSearch(
|
|
|
203
221
|
return null
|
|
204
222
|
}
|
|
205
223
|
}
|
|
224
|
+
|
|
225
|
+
/** An alert link's token posted to the API from this server; null when the API refuses the link (404, or 400). */
|
|
226
|
+
async function postAlertToken<T>(path: string, token: string): Promise<T | null> {
|
|
227
|
+
const res = await fetch(`${API_URL}${path}`, {
|
|
228
|
+
method: 'POST',
|
|
229
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
230
|
+
body: JSON.stringify({ token }),
|
|
231
|
+
cache: 'no-store',
|
|
232
|
+
})
|
|
233
|
+
if (res.status === 404 || res.status === 400) return null
|
|
234
|
+
if (!res.ok) throw new Error(`[api] POST ${path} answered ${res.status}`)
|
|
235
|
+
return ((await res.json()) as { data: T }).data
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface AlertConfirmation {
|
|
239
|
+
kind: AlertKind
|
|
240
|
+
product: { name: string; slug: string }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Confirms the alert a confirmation email's link names; null when the link is not valid; rejects when the API fails. */
|
|
244
|
+
export function confirmAlert(token: string): Promise<AlertConfirmation | null> {
|
|
245
|
+
return postAlertToken<AlertConfirmation>('/api/alerts/confirm', token)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Stops the alert an email's unsubscribe link names; false when the link is not valid; rejects when the API fails. */
|
|
249
|
+
export async function unsubscribeAlert(token: string): Promise<boolean> {
|
|
250
|
+
return (
|
|
251
|
+
(await postAlertToken<{ status: 'unsubscribed' }>('/api/alerts/unsubscribe', token)) !== null
|
|
252
|
+
)
|
|
253
|
+
}
|
|
@@ -31,6 +31,15 @@ const nextConfig = {
|
|
|
31
31
|
],
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
+
// The order page's URL carries the order's key; no request from it, nor from its not-found render, may refer it on.
|
|
35
|
+
async headers() {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
source: '/order/:orderNumber',
|
|
39
|
+
headers: [{ key: 'Referrer-Policy', value: 'no-referrer' }],
|
|
40
|
+
},
|
|
41
|
+
]
|
|
42
|
+
},
|
|
34
43
|
transpilePackages: ['@nymbalhq/sdk', '@nymbalhq/react', '@nymbalhq/web-components'],
|
|
35
44
|
images: {
|
|
36
45
|
remotePatterns: [{ protocol: 'https', hostname: '**' }],
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"seed": "nymbal seed"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"nymbal": "1.
|
|
21
|
-
"@nymbalhq/config": "1.
|
|
22
|
-
"@nymbalhq/platform": "1.
|
|
23
|
-
"@nymbalhq/stack": "1.
|
|
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.
|
|
28
|
-
"@nymbalhq/react": "1.
|
|
29
|
-
"@nymbalhq/web-components": "1.
|
|
30
|
-
"@nymbalhq/types": "1.
|
|
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.
|
|
42
|
-
"@nymbalhq/config": "1.
|
|
43
|
-
"@nymbalhq/http": "1.
|
|
44
|
-
"@nymbalhq/platform": "1.
|
|
45
|
-
"@nymbalhq/react": "1.
|
|
46
|
-
"@nymbalhq/sdk": "1.
|
|
47
|
-
"@nymbalhq/stack": "1.
|
|
48
|
-
"@nymbalhq/types": "1.
|
|
49
|
-
"@nymbalhq/web-components": "1.
|
|
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.
|
|
54
|
-
"@nymbalhq/config": "1.
|
|
55
|
-
"@nymbalhq/http": "1.
|
|
56
|
-
"@nymbalhq/platform": "1.
|
|
57
|
-
"@nymbalhq/react": "1.
|
|
58
|
-
"@nymbalhq/sdk": "1.
|
|
59
|
-
"@nymbalhq/stack": "1.
|
|
60
|
-
"@nymbalhq/types": "1.
|
|
61
|
-
"@nymbalhq/web-components": "1.
|
|
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
|
}
|