@hszrdm/create-commerce 1.0.3 → 1.2.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 (69) hide show
  1. package/bin/create-commerce.mjs +9 -2
  2. package/package.json +1 -1
  3. package/src/cli.mjs +5 -2
  4. package/templates/backend/.env.example +66 -7
  5. package/templates/backend/medusa-config.ts +17 -1
  6. package/templates/backend/package.json +2 -1
  7. package/templates/backend/src/scripts/core-init.ts +13 -1
  8. package/templates/storefront/next-env.d.ts +4 -1
  9. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
  10. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +46 -10
  11. package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
  12. package/templates/storefront/src/app/account/page.tsx +12 -1
  13. package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
  14. package/templates/storefront/src/app/checkout/page.tsx +12 -3
  15. package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
  16. package/templates/storefront/src/app/core-ux.css +244 -0
  17. package/templates/storefront/src/app/layout.tsx +40 -14
  18. package/templates/storefront/src/app/legal/page.tsx +11 -5
  19. package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
  20. package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
  21. package/templates/storefront/src/app/page.tsx +18 -12
  22. package/templates/storefront/src/app/reset-password/page.tsx +8 -2
  23. package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
  24. package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
  25. package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
  26. package/templates/storefront/src/components/account-dashboard.tsx +197 -76
  27. package/templates/storefront/src/components/account-wishlist.tsx +95 -0
  28. package/templates/storefront/src/components/add-to-cart.tsx +127 -18
  29. package/templates/storefront/src/components/back-to-top.tsx +26 -0
  30. package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
  31. package/templates/storefront/src/components/cart-provider.tsx +29 -12
  32. package/templates/storefront/src/components/cart-view.tsx +96 -32
  33. package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
  34. package/templates/storefront/src/components/checkout-flow.tsx +354 -102
  35. package/templates/storefront/src/components/form-ux.tsx +47 -0
  36. package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
  37. package/templates/storefront/src/components/newsletter-action.tsx +66 -0
  38. package/templates/storefront/src/components/order-detail.tsx +84 -45
  39. package/templates/storefront/src/components/product-card.tsx +16 -8
  40. package/templates/storefront/src/components/product-gallery.tsx +64 -0
  41. package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
  42. package/templates/storefront/src/components/reset-password-form.tsx +19 -13
  43. package/templates/storefront/src/components/share-button.tsx +63 -0
  44. package/templates/storefront/src/components/storefront-header.tsx +88 -20
  45. package/templates/storefront/src/components/stripe-payment.tsx +20 -4
  46. package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
  47. package/templates/storefront/src/components/toast-provider.tsx +92 -0
  48. package/templates/storefront/src/components/variant-price-display.tsx +31 -0
  49. package/templates/storefront/src/components/wishlist-button.tsx +88 -0
  50. package/templates/storefront/src/lib/core/account.ts +3 -0
  51. package/templates/storefront/src/lib/core/catalog.ts +37 -5
  52. package/templates/storefront/src/lib/core/client.ts +5 -0
  53. package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
  54. package/templates/storefront/src/lib/core/cms.ts +171 -0
  55. package/templates/storefront/src/lib/core/commerce.ts +14 -4
  56. package/templates/storefront/src/lib/core/form-ux.ts +57 -0
  57. package/templates/storefront/src/lib/core/leads.ts +50 -0
  58. package/templates/storefront/src/lib/core/newsletter.ts +53 -0
  59. package/templates/storefront/src/lib/core/pricing.ts +68 -0
  60. package/templates/storefront/src/lib/core/quotes.ts +43 -0
  61. package/templates/storefront/src/lib/core/reviews.ts +40 -0
  62. package/templates/storefront/src/lib/core/seo.ts +44 -6
  63. package/templates/storefront/src/lib/core/share.ts +57 -0
  64. package/templates/storefront/src/lib/core/wishlist.ts +88 -0
  65. package/templates/storefront/src/lib/storefront-copy.ts +435 -0
  66. package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
  67. package/templates/storefront/src/lib/storefront-routes.ts +94 -0
  68. package/templates/storefront/src/proxy.ts +145 -0
  69. package/templates/storefront/tsconfig.json +23 -5
@@ -0,0 +1,94 @@
1
+ export const STOREFRONT_ROUTES = {
2
+ hu: {
3
+ medusaLocale: "hu-HU",
4
+ home: "/hu",
5
+ products: "/hu/termekek",
6
+ categories: "/hu/kategoriak",
7
+ cart: "/hu/kosar",
8
+ checkout: "/hu/penztar",
9
+ checkoutSuccess: "/hu/penztar/sikeres-rendeles",
10
+ account: "/hu/fiokom",
11
+ wishlist: "/hu/fiokom/kedvencek",
12
+ orders: "/hu/fiokom/rendelesek",
13
+ resetPassword: "/hu/jelszo-visszaallitas",
14
+ legal: "/hu/jogi",
15
+ },
16
+ en: {
17
+ medusaLocale: "en-US",
18
+ home: "/en",
19
+ products: "/en/products",
20
+ categories: "/en/categories",
21
+ cart: "/en/cart",
22
+ checkout: "/en/checkout",
23
+ checkoutSuccess: "/en/checkout/success",
24
+ account: "/en/account",
25
+ wishlist: "/en/account/wishlist",
26
+ orders: "/en/account/orders",
27
+ resetPassword: "/en/reset-password",
28
+ legal: "/en/legal",
29
+ },
30
+ } as const
31
+
32
+ export type StorefrontLocale = keyof typeof STOREFRONT_ROUTES
33
+
34
+ export function storefrontLocale(value: unknown, fallback: StorefrontLocale = "hu"): StorefrontLocale {
35
+ const normalized = String(value || "").trim().toLowerCase()
36
+ if (normalized === "en" || normalized.startsWith("en-")) return "en"
37
+ if (normalized === "hu" || normalized.startsWith("hu-")) return "hu"
38
+ return fallback
39
+ }
40
+
41
+ export function localeFromPathname(pathname: string, fallback: StorefrontLocale = "hu") {
42
+ const first = pathname.split("/").filter(Boolean)[0]
43
+ return storefrontLocale(first, fallback)
44
+ }
45
+
46
+ export function medusaLocale(locale: StorefrontLocale) {
47
+ return STOREFRONT_ROUTES[locale].medusaLocale
48
+ }
49
+
50
+ export function productPath(locale: StorefrontLocale, handle: string) {
51
+ return `${STOREFRONT_ROUTES[locale].products}/${encodeURIComponent(handle)}`
52
+ }
53
+
54
+ export function categoryPath(locale: StorefrontLocale, handle: string) {
55
+ return `${STOREFRONT_ROUTES[locale].categories}/${encodeURIComponent(handle)}`
56
+ }
57
+
58
+ export function orderPath(locale: StorefrontLocale, orderId: string) {
59
+ return `${STOREFRONT_ROUTES[locale].orders}/${encodeURIComponent(orderId)}`
60
+ }
61
+
62
+ export function equivalentLocalePath(
63
+ pathname: string,
64
+ targetLocale: StorefrontLocale,
65
+ ) {
66
+ const sourceLocale = localeFromPathname(pathname)
67
+ if (sourceLocale === targetLocale) return pathname
68
+
69
+ const source = STOREFRONT_ROUTES[sourceLocale]
70
+ const target = STOREFRONT_ROUTES[targetLocale]
71
+
72
+ if (pathname === source.home) return target.home
73
+ if (pathname === source.products) return target.products
74
+ if (pathname.startsWith(`${source.products}/`)) {
75
+ return `${target.products}/${pathname.slice(source.products.length + 1)}`
76
+ }
77
+ if (pathname === source.categories) return target.categories
78
+ if (pathname.startsWith(`${source.categories}/`)) {
79
+ return `${target.categories}/${pathname.slice(source.categories.length + 1)}`
80
+ }
81
+ if (pathname === source.cart) return target.cart
82
+ if (pathname === source.checkout) return target.checkout
83
+ if (pathname === source.checkoutSuccess) return target.checkoutSuccess
84
+ if (pathname === source.account) return target.account
85
+ if (pathname === source.wishlist) return target.wishlist
86
+ if (pathname === source.orders) return target.orders
87
+ if (pathname.startsWith(`${source.orders}/`)) {
88
+ return `${target.orders}/${pathname.slice(source.orders.length + 1)}`
89
+ }
90
+ if (pathname === source.resetPassword) return target.resetPassword
91
+ if (pathname === source.legal) return target.legal
92
+
93
+ return target.home
94
+ }
@@ -0,0 +1,145 @@
1
+ import { NextRequest, NextResponse } from "next/server"
2
+ import {
3
+ STOREFRONT_ROUTES,
4
+ localeFromPathname,
5
+ type StorefrontLocale,
6
+ } from "./lib/storefront-routes"
7
+
8
+ const LOCALE_COOKIE = "hszrdm_storefront_locale"
9
+ const LOCALE_HEADER = "x-hszrdm-storefront-locale"
10
+
11
+ export function proxy(request: NextRequest) {
12
+ const pathname = request.nextUrl.pathname
13
+
14
+ if (isInfrastructurePath(pathname)) {
15
+ return NextResponse.next()
16
+ }
17
+
18
+ const cookieLocale = normalizeCookieLocale(request.cookies.get(LOCALE_COOKIE)?.value)
19
+ const pathLocale = /^\/(hu|en)(?:\/|$)/.test(pathname)
20
+ ? localeFromPathname(pathname)
21
+ : null
22
+ const locale = pathLocale || cookieLocale || "hu"
23
+
24
+ const redirectPath = legacyRedirect(pathname, locale)
25
+ if (redirectPath) {
26
+ const target = request.nextUrl.clone()
27
+ target.pathname = redirectPath
28
+ const response = NextResponse.redirect(target, 308)
29
+ response.cookies.set(LOCALE_COOKIE, locale, cookieOptions())
30
+ return response
31
+ }
32
+
33
+ const internalPath = internalRewrite(pathname, locale)
34
+ const requestHeaders = new Headers(request.headers)
35
+ requestHeaders.set(LOCALE_HEADER, locale)
36
+
37
+ const response = internalPath
38
+ ? NextResponse.rewrite(withPath(request, internalPath), {
39
+ request: { headers: requestHeaders },
40
+ })
41
+ : NextResponse.next({ request: { headers: requestHeaders } })
42
+
43
+ response.cookies.set(LOCALE_COOKIE, locale, cookieOptions())
44
+ return response
45
+ }
46
+
47
+ export const config = {
48
+ matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
49
+ }
50
+
51
+ function legacyRedirect(pathname: string, locale: StorefrontLocale) {
52
+ if (pathname === "/") return STOREFRONT_ROUTES[locale].home
53
+
54
+ if (pathname === "/cart") return STOREFRONT_ROUTES[locale].cart
55
+ if (pathname === "/checkout") return STOREFRONT_ROUTES[locale].checkout
56
+ if (pathname === "/checkout/success") return STOREFRONT_ROUTES[locale].checkoutSuccess
57
+ if (pathname === "/account") return STOREFRONT_ROUTES[locale].account
58
+ if (pathname === "/account/wishlist") return STOREFRONT_ROUTES[locale].wishlist
59
+ if (pathname.startsWith("/account/orders/")) {
60
+ return `${STOREFRONT_ROUTES[locale].orders}/${pathname.slice("/account/orders/".length)}`
61
+ }
62
+ if (pathname === "/reset-password") return STOREFRONT_ROUTES[locale].resetPassword
63
+ if (pathname === "/legal") return STOREFRONT_ROUTES[locale].legal
64
+
65
+ if (pathname === "/hu/products") return STOREFRONT_ROUTES.hu.products
66
+ if (pathname.startsWith("/hu/products/")) {
67
+ return `${STOREFRONT_ROUTES.hu.products}/${pathname.slice("/hu/products/".length)}`
68
+ }
69
+ if (pathname === "/hu/categories") return STOREFRONT_ROUTES.hu.categories
70
+ if (pathname.startsWith("/hu/categories/")) {
71
+ return `${STOREFRONT_ROUTES.hu.categories}/${pathname.slice("/hu/categories/".length)}`
72
+ }
73
+ if (pathname === "/hu/cart") return STOREFRONT_ROUTES.hu.cart
74
+ if (pathname === "/hu/checkout") return STOREFRONT_ROUTES.hu.checkout
75
+ if (pathname === "/hu/checkout/success") return STOREFRONT_ROUTES.hu.checkoutSuccess
76
+ if (pathname === "/hu/account") return STOREFRONT_ROUTES.hu.account
77
+ if (pathname === "/hu/account/wishlist") return STOREFRONT_ROUTES.hu.wishlist
78
+ if (pathname.startsWith("/hu/account/orders/")) {
79
+ return `${STOREFRONT_ROUTES.hu.orders}/${pathname.slice("/hu/account/orders/".length)}`
80
+ }
81
+ if (pathname === "/hu/reset-password") return STOREFRONT_ROUTES.hu.resetPassword
82
+ if (pathname === "/hu/legal") return STOREFRONT_ROUTES.hu.legal
83
+
84
+ return null
85
+ }
86
+
87
+ function internalRewrite(pathname: string, locale: StorefrontLocale) {
88
+ const routes = STOREFRONT_ROUTES[locale]
89
+
90
+ if (pathname === routes.home) return "/"
91
+
92
+ if (locale === "hu") {
93
+ if (pathname === routes.products) return "/hu/products"
94
+ if (pathname.startsWith(`${routes.products}/`)) {
95
+ return `/hu/products/${pathname.slice(routes.products.length + 1)}`
96
+ }
97
+ if (pathname === routes.categories) return "/hu/categories"
98
+ if (pathname.startsWith(`${routes.categories}/`)) {
99
+ return `/hu/categories/${pathname.slice(routes.categories.length + 1)}`
100
+ }
101
+ }
102
+
103
+ if (pathname === routes.cart) return "/cart"
104
+ if (pathname === routes.checkout) return "/checkout"
105
+ if (pathname === routes.checkoutSuccess) return "/checkout/success"
106
+ if (pathname === routes.account) return "/account"
107
+ if (pathname === routes.wishlist) return "/account/wishlist"
108
+ if (pathname.startsWith(`${routes.orders}/`)) {
109
+ return `/account/orders/${pathname.slice(routes.orders.length + 1)}`
110
+ }
111
+ if (pathname === routes.resetPassword) return "/reset-password"
112
+ if (pathname === routes.legal) return "/legal"
113
+
114
+ return null
115
+ }
116
+
117
+ function withPath(request: NextRequest, pathname: string) {
118
+ const target = request.nextUrl.clone()
119
+ target.pathname = pathname
120
+ return target
121
+ }
122
+
123
+ function normalizeCookieLocale(value: string | undefined): StorefrontLocale | null {
124
+ return value === "hu" || value === "en" ? value : null
125
+ }
126
+
127
+ function cookieOptions() {
128
+ return {
129
+ path: "/",
130
+ sameSite: "lax" as const,
131
+ httpOnly: false,
132
+ secure: process.env.NODE_ENV === "production",
133
+ maxAge: 60 * 60 * 24 * 365,
134
+ }
135
+ }
136
+
137
+ function isInfrastructurePath(pathname: string) {
138
+ return (
139
+ pathname === "/robots.txt" ||
140
+ pathname === "/sitemap.xml" ||
141
+ pathname.startsWith("/sitemap.xml/") ||
142
+ pathname.startsWith("/api/") ||
143
+ pathname.startsWith("/static/")
144
+ )
145
+ }
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "lib": ["dom", "dom.iterable", "esnext"],
4
+ "lib": [
5
+ "dom",
6
+ "dom.iterable",
7
+ "esnext"
8
+ ],
5
9
  "allowJs": false,
6
10
  "skipLibCheck": true,
7
11
  "strict": true,
@@ -13,11 +17,25 @@
13
17
  "isolatedModules": true,
14
18
  "jsx": "react-jsx",
15
19
  "incremental": true,
16
- "plugins": [{ "name": "next" }],
20
+ "plugins": [
21
+ {
22
+ "name": "next"
23
+ }
24
+ ],
17
25
  "paths": {
18
- "@/*": ["./src/*"]
26
+ "@/*": [
27
+ "./src/*"
28
+ ]
19
29
  }
20
30
  },
21
- "include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx", ".next/types/**/*.ts"],
22
- "exclude": ["node_modules"]
31
+ "include": [
32
+ "next-env.d.ts",
33
+ "src/**/*.ts",
34
+ "src/**/*.tsx",
35
+ ".next/types/**/*.ts",
36
+ ".next/dev/types/**/*.ts"
37
+ ],
38
+ "exclude": [
39
+ "node_modules"
40
+ ]
23
41
  }