create-nymbal-app 0.5.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 (35) hide show
  1. package/dist/index.js +7 -1
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/scaffold/templates/astro/package.json +25 -25
  5. package/scaffold/templates/astro/src/lib/api.ts +53 -21
  6. package/scaffold/templates/astro/src/pages/404.astro +3 -0
  7. package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +11 -3
  8. package/scaffold/templates/astro/src/pages/alerts/confirm.astro +59 -0
  9. package/scaffold/templates/astro/src/pages/alerts/unsubscribe.astro +53 -0
  10. package/scaffold/templates/astro/src/pages/category/[slug].astro +8 -6
  11. package/scaffold/templates/astro/src/pages/checkout.astro +2 -2
  12. package/scaffold/templates/astro/src/pages/index.astro +7 -0
  13. package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +13 -2
  14. package/scaffold/templates/astro/src/pages/product/[slug].astro +20 -4
  15. package/scaffold/templates/astro/src/scripts/order-status.ts +3 -1
  16. package/scaffold/templates/astro/src/scripts/pdp.ts +5 -0
  17. package/scaffold/templates/astro/src/styles/pages/account.css +4 -0
  18. package/scaffold/templates/nextjs/app/(catalog)/home/[key]/page.tsx +6 -1
  19. package/scaffold/templates/nextjs/app/(catalog)/product/[slug]/page.tsx +22 -3
  20. package/scaffold/templates/nextjs/app/(shopper)/account/orders/[orderNumber]/page.tsx +10 -3
  21. package/scaffold/templates/nextjs/app/(shopper)/alerts/AlertLinkForm.tsx +90 -0
  22. package/scaffold/templates/nextjs/app/(shopper)/alerts/LinkInvalid.tsx +19 -0
  23. package/scaffold/templates/nextjs/app/(shopper)/alerts/actions.ts +33 -0
  24. package/scaffold/templates/nextjs/app/(shopper)/alerts/confirm/page.tsx +19 -0
  25. package/scaffold/templates/nextjs/app/(shopper)/alerts/unsubscribe/page.tsx +17 -0
  26. package/scaffold/templates/nextjs/app/(shopper)/checkout/CheckoutView.tsx +16 -9
  27. package/scaffold/templates/nextjs/app/(shopper)/not-found.tsx +6 -0
  28. package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/page.tsx +21 -5
  29. package/scaffold/templates/nextjs/app/not-found.tsx +1 -1
  30. package/scaffold/templates/nextjs/components/client/OrderStatusRefresh.tsx +8 -2
  31. package/scaffold/templates/nextjs/components/client/ProductInteractive.tsx +18 -1
  32. package/scaffold/templates/nextjs/components/client/elements.tsx +2 -0
  33. package/scaffold/templates/nextjs/lib/api.ts +55 -15
  34. package/scaffold/templates/nextjs/next.config.mjs +9 -0
  35. package/scaffold/templates/nextjs/package.json +26 -26
@@ -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 { Cart, Category, Order, ProductSortKey, StoreCapabilities } from '@nymbalhq/types'
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,22 @@ export async function fetchCategories(): Promise<Category[]> {
112
119
  return envelope.data
113
120
  }
114
121
 
115
- export async function fetchOrder(orderNumber: string): Promise<Order | null> {
116
- try {
117
- const res = await fetch(`${API_URL}/api/orders/${encodeURIComponent(orderNumber)}`, {
118
- cache: 'no-store',
119
- })
120
- if (!res.ok) return null
121
- const envelope = (await res.json()) as { data: Order }
122
- return envelope.data ?? null
123
- } catch (err) {
124
- unstable_rethrow(err)
125
- console.error('[api] fetchOrder failed', err)
126
- return null
127
- }
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.
126
+ */
127
+ export async function loadOrder(orderNumber: string, key?: string): Promise<ShopperOrder | null> {
128
+ const url = `${API_URL}/api/orders/${encodeURIComponent(orderNumber)}`
129
+ const res = await fetch(url, {
130
+ cache: 'no-store',
131
+ headers: key ? { [ORDER_KEY_HEADER]: key } : {},
132
+ })
133
+ if (res.status === 404) return null
134
+ if (!res.ok) throw new Error(`[api] GET ${url} answered ${res.status}`)
135
+ const envelope = (await res.json()) as { data?: ShopperOrder | null }
136
+ if (!envelope.data) throw new Error(`[api] GET ${url} answered no data`)
137
+ return envelope.data
128
138
  }
129
139
 
130
140
  export async function fetchReviews(productId: string): Promise<ReviewsListResult> {
@@ -203,3 +213,33 @@ export async function fetchSearch(
203
213
  return null
204
214
  }
205
215
  }
216
+
217
+ /** An alert link's token posted to the API from this server; null when the API refuses the link (404, or 400). */
218
+ async function postAlertToken<T>(path: string, token: string): Promise<T | null> {
219
+ const res = await fetch(`${API_URL}${path}`, {
220
+ method: 'POST',
221
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
222
+ body: JSON.stringify({ token }),
223
+ cache: 'no-store',
224
+ })
225
+ if (res.status === 404 || res.status === 400) return null
226
+ if (!res.ok) throw new Error(`[api] POST ${path} answered ${res.status}`)
227
+ return ((await res.json()) as { data: T }).data
228
+ }
229
+
230
+ export interface AlertConfirmation {
231
+ kind: AlertKind
232
+ product: { name: string; slug: string }
233
+ }
234
+
235
+ /** Confirms the alert a confirmation email's link names; null when the link is not valid; rejects when the API fails. */
236
+ export function confirmAlert(token: string): Promise<AlertConfirmation | null> {
237
+ return postAlertToken<AlertConfirmation>('/api/alerts/confirm', token)
238
+ }
239
+
240
+ /** Stops the alert an email's unsubscribe link names; false when the link is not valid; rejects when the API fails. */
241
+ export async function unsubscribeAlert(token: string): Promise<boolean> {
242
+ return (
243
+ (await postAlertToken<{ status: 'unsubscribed' }>('/api/alerts/unsubscribe', token)) !== null
244
+ )
245
+ }
@@ -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.2.0",
21
- "@nymbalhq/config": "1.2.0",
22
- "@nymbalhq/platform": "1.2.0",
23
- "@nymbalhq/stack": "1.2.0",
20
+ "nymbal": "1.4.0",
21
+ "@nymbalhq/config": "1.4.0",
22
+ "@nymbalhq/platform": "1.4.0",
23
+ "@nymbalhq/stack": "1.4.0",
24
24
  "next": "^16.4.2",
25
25
  "react": "^19.3.1",
26
26
  "react-dom": "^19.3.1",
27
- "@nymbalhq/sdk": "1.2.0",
28
- "@nymbalhq/react": "1.2.0",
29
- "@nymbalhq/web-components": "1.2.0",
30
- "@nymbalhq/types": "1.2.0"
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"
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.2.0",
42
- "@nymbalhq/config": "1.2.0",
43
- "@nymbalhq/http": "1.2.0",
44
- "@nymbalhq/platform": "1.2.0",
45
- "@nymbalhq/react": "1.2.0",
46
- "@nymbalhq/sdk": "1.2.0",
47
- "@nymbalhq/stack": "1.2.0",
48
- "@nymbalhq/types": "1.2.0",
49
- "@nymbalhq/web-components": "1.2.0"
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"
50
50
  }
51
51
  },
52
52
  "overrides": {
53
- "nymbal": "1.2.0",
54
- "@nymbalhq/config": "1.2.0",
55
- "@nymbalhq/http": "1.2.0",
56
- "@nymbalhq/platform": "1.2.0",
57
- "@nymbalhq/react": "1.2.0",
58
- "@nymbalhq/sdk": "1.2.0",
59
- "@nymbalhq/stack": "1.2.0",
60
- "@nymbalhq/types": "1.2.0",
61
- "@nymbalhq/web-components": "1.2.0"
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"
62
62
  }
63
63
  }