create-brainerce-store 1.17.0 → 1.19.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 (65) hide show
  1. package/dist/index.js +31 -9
  2. package/messages/en.json +366 -359
  3. package/messages/he.json +366 -359
  4. package/package.json +45 -45
  5. package/templates/nextjs/base/next.config.ts +31 -31
  6. package/templates/nextjs/base/scripts/fetch-store-info.mjs +81 -81
  7. package/templates/nextjs/base/src/app/.well-known/apple-developer-merchantid-domain-association/route.ts +26 -26
  8. package/templates/nextjs/base/src/app/account/layout.tsx +9 -9
  9. package/templates/nextjs/base/src/app/account/page.tsx +122 -122
  10. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +14 -14
  11. package/templates/nextjs/base/src/app/api/auth/me/route.ts +56 -56
  12. package/templates/nextjs/base/src/app/api/auth/oauth-callback/route.ts +59 -59
  13. package/templates/nextjs/base/src/app/api/auth/reset-callback/route.ts +41 -41
  14. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +77 -77
  15. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +198 -198
  16. package/templates/nextjs/base/src/app/auth/callback/page.tsx +92 -92
  17. package/templates/nextjs/base/src/app/cart/layout.tsx +9 -9
  18. package/templates/nextjs/base/src/app/cart/page.tsx +204 -199
  19. package/templates/nextjs/base/src/app/checkout/layout.tsx +9 -9
  20. package/templates/nextjs/base/src/app/checkout/page.tsx +860 -860
  21. package/templates/nextjs/base/src/app/forgot-password/page.tsx +112 -112
  22. package/templates/nextjs/base/src/app/layout.tsx.ejs +75 -0
  23. package/templates/nextjs/base/src/app/login/layout.tsx +9 -9
  24. package/templates/nextjs/base/src/app/login/page.tsx +59 -59
  25. package/templates/nextjs/base/src/app/order-confirmation/layout.tsx +9 -9
  26. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +254 -254
  27. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +67 -67
  28. package/templates/nextjs/base/src/app/products/[slug]/product-client-section.tsx +486 -486
  29. package/templates/nextjs/base/src/app/products/layout.tsx +18 -18
  30. package/templates/nextjs/base/src/app/products/page.tsx +431 -431
  31. package/templates/nextjs/base/src/app/register/layout.tsx +9 -9
  32. package/templates/nextjs/base/src/app/register/page.tsx +65 -65
  33. package/templates/nextjs/base/src/app/reset-password/page.tsx +132 -132
  34. package/templates/nextjs/base/src/app/robots.ts +14 -14
  35. package/templates/nextjs/base/src/app/sitemap.ts +25 -25
  36. package/templates/nextjs/base/src/app/verify-email/page.tsx +258 -258
  37. package/templates/nextjs/base/src/components/account/address-book.tsx +432 -432
  38. package/templates/nextjs/base/src/components/account/order-history.tsx +350 -350
  39. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -137
  40. package/templates/nextjs/base/src/components/auth/register-form.tsx +232 -232
  41. package/templates/nextjs/base/src/components/cart/cart-bundle-offer.tsx +247 -111
  42. package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -153
  43. package/templates/nextjs/base/src/components/cart/cart-upgrade-banner.tsx +142 -142
  44. package/templates/nextjs/base/src/components/cart/free-shipping-bar.tsx +59 -59
  45. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +415 -415
  46. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +243 -83
  47. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +519 -473
  48. package/templates/nextjs/base/src/components/layout/footer.tsx +41 -41
  49. package/templates/nextjs/base/src/components/layout/header.tsx +336 -336
  50. package/templates/nextjs/base/src/components/layout/language-switcher.tsx.ejs +63 -0
  51. package/templates/nextjs/base/src/components/products/discount-badge.tsx +22 -22
  52. package/templates/nextjs/base/src/components/products/frequently-bought-together.tsx +202 -202
  53. package/templates/nextjs/base/src/components/products/product-card.tsx +218 -218
  54. package/templates/nextjs/base/src/components/products/recommendation-section.tsx +107 -107
  55. package/templates/nextjs/base/src/components/products/stock-badge.tsx +63 -63
  56. package/templates/nextjs/base/src/components/products/variant-selector.tsx +292 -292
  57. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +72 -72
  58. package/templates/nextjs/base/src/i18n.ts.ejs +21 -0
  59. package/templates/nextjs/base/src/lib/auth.ts +149 -149
  60. package/templates/nextjs/base/src/lib/brainerce.ts.ejs +9 -0
  61. package/templates/nextjs/base/src/lib/translations.ts.ejs +31 -0
  62. package/templates/nextjs/base/src/middleware.ts.ejs +81 -0
  63. package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +41 -0
  64. package/templates/nextjs/base/src/lib/translations.ts +0 -11
  65. package/templates/nextjs/base/src/middleware.ts +0 -25
@@ -5,6 +5,10 @@ import type { StoreInfo, Cart, CustomerProfile } from 'brainerce';
5
5
  import { getCartTotals } from 'brainerce';
6
6
  import { getClient, initClient, setStoredCartId } from '@/lib/brainerce';
7
7
  import { checkAuthStatus, proxyLogout } from '@/lib/auth';
8
+ <% if (i18nEnabled) { %>
9
+ import { MessagesContext } from '@/lib/translations';
10
+ import { getMessages, defaultLocale } from '@/i18n';
11
+ <% } %>
8
12
 
9
13
  // ---- Store Info Context ----
10
14
  interface StoreInfoContextValue {
@@ -64,7 +68,11 @@ export function useCart() {
64
68
  }
65
69
 
66
70
  // ---- Provider Component ----
71
+ <% if (i18nEnabled) { %>
72
+ export function StoreProvider({ children, locale }: { children: React.ReactNode; locale?: string }) {
73
+ <% } else { %>
67
74
  export function StoreProvider({ children }: { children: React.ReactNode }) {
75
+ <% } %>
68
76
  const [storeInfo, setStoreInfo] = useState<StoreInfo | null>(null);
69
77
  const [storeLoading, setStoreLoading] = useState(true);
70
78
  const [isLoggedIn, setIsLoggedIn] = useState(false);
@@ -72,6 +80,9 @@ export function StoreProvider({ children }: { children: React.ReactNode }) {
72
80
  const [authLoading, setAuthLoading] = useState(true);
73
81
  const [cart, setCart] = useState<Cart | null>(null);
74
82
  const [cartLoading, setCartLoading] = useState(true);
83
+ <% if (i18nEnabled) { %>
84
+ const [messages, setMessages] = useState<Record<string, Record<string, string>>>({});
85
+ <% } %>
75
86
 
76
87
  // Check auth status via httpOnly cookie (server-side validation)
77
88
  const refreshAuth = useCallback(async () => {
@@ -90,6 +101,16 @@ export function StoreProvider({ children }: { children: React.ReactNode }) {
90
101
  // Initialize client, check auth, and fetch store info
91
102
  useEffect(() => {
92
103
  const client = initClient();
104
+ <% if (i18nEnabled) { %>
105
+
106
+ // Set locale on SDK client for translated product content
107
+ if (locale) {
108
+ client.setLocale(locale);
109
+ }
110
+
111
+ // Load UI message strings for current locale
112
+ getMessages(locale || defaultLocale).then(setMessages);
113
+ <% } %>
93
114
 
94
115
  // Optimistic check: if brainerce_logged_in cookie exists, assume logged in
95
116
  // while we validate the actual token server-side
@@ -106,7 +127,11 @@ export function StoreProvider({ children }: { children: React.ReactNode }) {
106
127
  .then(setStoreInfo)
107
128
  .catch(console.error)
108
129
  .finally(() => setStoreLoading(false));
130
+ <% if (i18nEnabled) { %>
131
+ }, [refreshAuth, locale]);
132
+ <% } else { %>
109
133
  }, [refreshAuth]);
134
+ <% } %>
110
135
 
111
136
  // Cart management
112
137
  const refreshCart = useCallback(async () => {
@@ -159,6 +184,21 @@ export function StoreProvider({ children }: { children: React.ReactNode }) {
159
184
 
160
185
  const totals = cart ? getCartTotals(cart) : { subtotal: 0, discount: 0, shipping: 0, total: 0 };
161
186
 
187
+ <% if (i18nEnabled) { %>
188
+ return (
189
+ <MessagesContext.Provider value={messages}>
190
+ <StoreInfoContext.Provider value={{ storeInfo, loading: storeLoading }}>
191
+ <AuthContext.Provider value={{ isLoggedIn, authLoading, customer, login, logout }}>
192
+ <CartContext.Provider
193
+ value={{ cart, cartLoading, refreshCart, itemCount, totals }}
194
+ >
195
+ {children}
196
+ </CartContext.Provider>
197
+ </AuthContext.Provider>
198
+ </StoreInfoContext.Provider>
199
+ </MessagesContext.Provider>
200
+ );
201
+ <% } else { %>
162
202
  return (
163
203
  <StoreInfoContext.Provider value={{ storeInfo, loading: storeLoading }}>
164
204
  <AuthContext.Provider value={{ isLoggedIn, authLoading, customer, login, logout }}>
@@ -170,4 +210,5 @@ export function StoreProvider({ children }: { children: React.ReactNode }) {
170
210
  </AuthContext.Provider>
171
211
  </StoreInfoContext.Provider>
172
212
  );
213
+ <% } %>
173
214
  }
@@ -1,11 +0,0 @@
1
- import { messages } from '@/i18n';
2
-
3
- type Messages = typeof messages;
4
- type Namespace = keyof Messages;
5
-
6
- export function useTranslations<N extends Namespace>(namespace: N) {
7
- const ns = messages[namespace] as Record<string, string>;
8
- return function t(key: keyof Messages[N]): string {
9
- return ns[key as string] || `${String(namespace)}.${key as string}`;
10
- };
11
- }
@@ -1,25 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
-
3
- const TOKEN_COOKIE = 'brainerce_customer_token';
4
-
5
- /** Routes that require customer authentication */
6
- const PROTECTED_PATHS = ['/account'];
7
-
8
- export function middleware(request: NextRequest) {
9
- const { pathname } = request.nextUrl;
10
- const isProtected = PROTECTED_PATHS.some((p) => pathname.startsWith(p));
11
-
12
- if (isProtected) {
13
- const token = request.cookies.get(TOKEN_COOKIE);
14
- if (!token?.value) {
15
- const loginUrl = new URL('/login', request.url);
16
- return NextResponse.redirect(loginUrl);
17
- }
18
- }
19
-
20
- return NextResponse.next();
21
- }
22
-
23
- export const config = {
24
- matcher: ['/account/:path*'],
25
- };