create-brainerce-store 1.28.13 → 1.28.17

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 (24) hide show
  1. package/dist/index.js +1 -1
  2. package/messages/en.json +390 -389
  3. package/messages/he.json +390 -389
  4. package/package.json +46 -46
  5. package/templates/nextjs/base/next.config.ts +47 -47
  6. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +15 -15
  7. package/templates/nextjs/base/src/app/api/auth/oauth-callback/route.ts +66 -66
  8. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +76 -76
  9. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +235 -229
  10. package/templates/nextjs/base/src/app/checkout/page.tsx +975 -975
  11. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +73 -76
  12. package/templates/nextjs/base/src/app/products/[slug]/product-client-section.tsx +529 -501
  13. package/templates/nextjs/base/src/app/products/page.tsx +475 -482
  14. package/templates/nextjs/base/src/app/reset-password/page.tsx +138 -138
  15. package/templates/nextjs/base/src/components/auth/register-form.tsx +245 -245
  16. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +416 -416
  17. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +656 -656
  18. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +88 -88
  19. package/templates/nextjs/base/src/lib/brainerce.ts.ejs +6 -2
  20. package/templates/nextjs/base/src/lib/csrf.ts +11 -11
  21. package/templates/nextjs/base/src/lib/nonce.ts +10 -10
  22. package/templates/nextjs/base/src/lib/safe-redirect.ts +45 -45
  23. package/templates/nextjs/base/src/lib/sanitize-html.ts +93 -93
  24. package/templates/nextjs/base/src/lib/validation.ts +37 -37
@@ -1,245 +1,245 @@
1
- 'use client';
2
-
3
- import { useState, useMemo } from 'react';
4
- import { useTranslations } from '@/lib/translations';
5
- import { cn } from '@/lib/utils';
6
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
- import { getPasswordError } from '@/lib/validation';
8
-
9
- interface RegisterData {
10
- firstName: string;
11
- lastName: string;
12
- email: string;
13
- password: string;
14
- acceptsMarketing: boolean;
15
- }
16
-
17
- interface RegisterFormProps {
18
- onSubmit: (data: RegisterData) => Promise<void>;
19
- error?: string | null;
20
- className?: string;
21
- }
22
-
23
- function getPasswordStrength(password: string): { label: string; color: string; width: string } {
24
- if (password.length === 0) return { label: '', color: '', width: 'w-0' };
25
- if (password.length < 8) return { label: 'tooShort', color: 'bg-destructive', width: 'w-1/4' };
26
-
27
- let score = 0;
28
- if (password.length >= 8) score++;
29
- if (/[A-Z]/.test(password)) score++;
30
- if (/[0-9]/.test(password)) score++;
31
- if (/[^A-Za-z0-9]/.test(password)) score++;
32
-
33
- if (score <= 1) return { label: 'weak', color: 'bg-orange-500', width: 'w-1/3' };
34
- if (score <= 2) return { label: 'fair', color: 'bg-yellow-500', width: 'w-1/2' };
35
- if (score <= 3) return { label: 'good', color: 'bg-primary', width: 'w-3/4' };
36
- return { label: 'strong', color: 'bg-green-500', width: 'w-full' };
37
- }
38
-
39
- export function RegisterForm({ onSubmit, error, className }: RegisterFormProps) {
40
- const t = useTranslations('auth');
41
- const tf = useTranslations('checkoutForm');
42
- const [firstName, setFirstName] = useState('');
43
- const [lastName, setLastName] = useState('');
44
- const [email, setEmail] = useState('');
45
- const [password, setPassword] = useState('');
46
- const [privacyAccepted, setPrivacyAccepted] = useState(false);
47
- const [privacyError, setPrivacyError] = useState(false);
48
- const [passwordError, setPasswordError] = useState<string | null>(null);
49
- const [acceptsMarketing, setAcceptsMarketing] = useState(false);
50
- const [loading, setLoading] = useState(false);
51
-
52
- const strength = useMemo(() => getPasswordStrength(password), [password]);
53
-
54
- async function handleSubmit(e: React.FormEvent) {
55
- e.preventDefault();
56
- if (loading) return;
57
-
58
- const pwCode = getPasswordError(password);
59
- if (pwCode) {
60
- setPasswordError(t(pwCode));
61
- return;
62
- }
63
- setPasswordError(null);
64
-
65
- if (!privacyAccepted) {
66
- setPrivacyError(true);
67
- return;
68
- }
69
-
70
- try {
71
- setLoading(true);
72
- await onSubmit({ firstName, lastName, email, password, acceptsMarketing });
73
- } finally {
74
- setLoading(false);
75
- }
76
- }
77
-
78
- return (
79
- <form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
80
- {error && (
81
- <div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
82
- {error}
83
- </div>
84
- )}
85
-
86
- <div className="grid grid-cols-2 gap-3">
87
- <div>
88
- <label
89
- htmlFor="register-first-name"
90
- className="text-foreground mb-1.5 block text-sm font-medium"
91
- >
92
- {tf('firstName')}
93
- </label>
94
- <input
95
- id="register-first-name"
96
- type="text"
97
- required
98
- value={firstName}
99
- onChange={(e) => setFirstName(e.target.value)}
100
- placeholder={t('firstNamePlaceholder')}
101
- autoComplete="given-name"
102
- className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
103
- />
104
- </div>
105
-
106
- <div>
107
- <label
108
- htmlFor="register-last-name"
109
- className="text-foreground mb-1.5 block text-sm font-medium"
110
- >
111
- {tf('lastName')}
112
- </label>
113
- <input
114
- id="register-last-name"
115
- type="text"
116
- required
117
- value={lastName}
118
- onChange={(e) => setLastName(e.target.value)}
119
- placeholder={t('lastNamePlaceholder')}
120
- autoComplete="family-name"
121
- className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
122
- />
123
- </div>
124
- </div>
125
-
126
- <div>
127
- <label
128
- htmlFor="register-email"
129
- className="text-foreground mb-1.5 block text-sm font-medium"
130
- >
131
- {t('email')}
132
- </label>
133
- <input
134
- id="register-email"
135
- type="email"
136
- required
137
- value={email}
138
- onChange={(e) => setEmail(e.target.value)}
139
- placeholder={t('emailPlaceholder')}
140
- autoComplete="email"
141
- className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
142
- />
143
- </div>
144
-
145
- <div>
146
- <label
147
- htmlFor="register-password"
148
- className="text-foreground mb-1.5 block text-sm font-medium"
149
- >
150
- {t('password')}
151
- </label>
152
- <input
153
- id="register-password"
154
- type="password"
155
- required
156
- minLength={8}
157
- value={password}
158
- onChange={(e) => {
159
- setPassword(e.target.value);
160
- if (passwordError) setPasswordError(null);
161
- }}
162
- placeholder={t('atLeastChars')}
163
- autoComplete="new-password"
164
- className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
165
- />
166
- {password.length > 0 && (
167
- <div className="mt-2">
168
- <div className="bg-muted h-1.5 w-full overflow-hidden rounded-full">
169
- <div
170
- className={cn(
171
- 'h-full rounded-full transition-all duration-300',
172
- strength.color,
173
- strength.width
174
- )}
175
- />
176
- </div>
177
- <p className="text-muted-foreground mt-1 text-xs">
178
- {strength.label
179
- ? t(strength.label as 'tooShort' | 'weak' | 'fair' | 'good' | 'strong')
180
- : ''}
181
- </p>
182
- </div>
183
- )}
184
- {passwordError && <p className="text-destructive mt-1 text-xs">{passwordError}</p>}
185
- </div>
186
-
187
- {/* Privacy Policy (required) */}
188
- <div>
189
- <label className="flex cursor-pointer items-start gap-2">
190
- <input
191
- type="checkbox"
192
- checked={privacyAccepted}
193
- onChange={(e) => {
194
- setPrivacyAccepted(e.target.checked);
195
- setPrivacyError(false);
196
- }}
197
- className="accent-primary mt-0.5"
198
- />
199
- <span className="text-muted-foreground text-sm">
200
- {t('privacyAcceptPrefix')}{' '}
201
- <a
202
- href="/privacy"
203
- target="_blank"
204
- rel="noopener noreferrer"
205
- className="text-primary underline underline-offset-2"
206
- >
207
- {t('privacyPolicyLink')}
208
- </a>{' '}
209
- <span className="text-destructive">*</span>
210
- </span>
211
- </label>
212
- {privacyError && <p className="text-destructive mt-1 text-xs">{t('privacyRequired')}</p>}
213
- </div>
214
-
215
- {/* Marketing consent (optional) */}
216
- <label className="flex cursor-pointer items-start gap-2">
217
- <input
218
- type="checkbox"
219
- checked={acceptsMarketing}
220
- onChange={(e) => setAcceptsMarketing(e.target.checked)}
221
- className="accent-primary mt-0.5"
222
- />
223
- <span className="text-muted-foreground text-sm">{t('acceptsMarketing')}</span>
224
- </label>
225
-
226
- <button
227
- type="submit"
228
- disabled={loading}
229
- className="bg-primary text-primary-foreground flex h-10 w-full items-center justify-center gap-2 rounded text-sm font-medium transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
230
- >
231
- {loading ? (
232
- <>
233
- <LoadingSpinner
234
- size="sm"
235
- className="border-primary-foreground/30 border-t-primary-foreground"
236
- />
237
- {t('creatingAccount')}
238
- </>
239
- ) : (
240
- t('createAccount')
241
- )}
242
- </button>
243
- </form>
244
- );
245
- }
1
+ 'use client';
2
+
3
+ import { useState, useMemo } from 'react';
4
+ import { useTranslations } from '@/lib/translations';
5
+ import { cn } from '@/lib/utils';
6
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
+ import { getPasswordError } from '@/lib/validation';
8
+
9
+ interface RegisterData {
10
+ firstName: string;
11
+ lastName: string;
12
+ email: string;
13
+ password: string;
14
+ acceptsMarketing: boolean;
15
+ }
16
+
17
+ interface RegisterFormProps {
18
+ onSubmit: (data: RegisterData) => Promise<void>;
19
+ error?: string | null;
20
+ className?: string;
21
+ }
22
+
23
+ function getPasswordStrength(password: string): { label: string; color: string; width: string } {
24
+ if (password.length === 0) return { label: '', color: '', width: 'w-0' };
25
+ if (password.length < 8) return { label: 'tooShort', color: 'bg-destructive', width: 'w-1/4' };
26
+
27
+ let score = 0;
28
+ if (password.length >= 8) score++;
29
+ if (/[A-Z]/.test(password)) score++;
30
+ if (/[0-9]/.test(password)) score++;
31
+ if (/[^A-Za-z0-9]/.test(password)) score++;
32
+
33
+ if (score <= 1) return { label: 'weak', color: 'bg-orange-500', width: 'w-1/3' };
34
+ if (score <= 2) return { label: 'fair', color: 'bg-yellow-500', width: 'w-1/2' };
35
+ if (score <= 3) return { label: 'good', color: 'bg-primary', width: 'w-3/4' };
36
+ return { label: 'strong', color: 'bg-green-500', width: 'w-full' };
37
+ }
38
+
39
+ export function RegisterForm({ onSubmit, error, className }: RegisterFormProps) {
40
+ const t = useTranslations('auth');
41
+ const tf = useTranslations('checkoutForm');
42
+ const [firstName, setFirstName] = useState('');
43
+ const [lastName, setLastName] = useState('');
44
+ const [email, setEmail] = useState('');
45
+ const [password, setPassword] = useState('');
46
+ const [privacyAccepted, setPrivacyAccepted] = useState(false);
47
+ const [privacyError, setPrivacyError] = useState(false);
48
+ const [passwordError, setPasswordError] = useState<string | null>(null);
49
+ const [acceptsMarketing, setAcceptsMarketing] = useState(false);
50
+ const [loading, setLoading] = useState(false);
51
+
52
+ const strength = useMemo(() => getPasswordStrength(password), [password]);
53
+
54
+ async function handleSubmit(e: React.FormEvent) {
55
+ e.preventDefault();
56
+ if (loading) return;
57
+
58
+ const pwCode = getPasswordError(password);
59
+ if (pwCode) {
60
+ setPasswordError(t(pwCode));
61
+ return;
62
+ }
63
+ setPasswordError(null);
64
+
65
+ if (!privacyAccepted) {
66
+ setPrivacyError(true);
67
+ return;
68
+ }
69
+
70
+ try {
71
+ setLoading(true);
72
+ await onSubmit({ firstName, lastName, email, password, acceptsMarketing });
73
+ } finally {
74
+ setLoading(false);
75
+ }
76
+ }
77
+
78
+ return (
79
+ <form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
80
+ {error && (
81
+ <div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
82
+ {error}
83
+ </div>
84
+ )}
85
+
86
+ <div className="grid grid-cols-2 gap-3">
87
+ <div>
88
+ <label
89
+ htmlFor="register-first-name"
90
+ className="text-foreground mb-1.5 block text-sm font-medium"
91
+ >
92
+ {tf('firstName')}
93
+ </label>
94
+ <input
95
+ id="register-first-name"
96
+ type="text"
97
+ required
98
+ value={firstName}
99
+ onChange={(e) => setFirstName(e.target.value)}
100
+ placeholder={t('firstNamePlaceholder')}
101
+ autoComplete="given-name"
102
+ className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
103
+ />
104
+ </div>
105
+
106
+ <div>
107
+ <label
108
+ htmlFor="register-last-name"
109
+ className="text-foreground mb-1.5 block text-sm font-medium"
110
+ >
111
+ {tf('lastName')}
112
+ </label>
113
+ <input
114
+ id="register-last-name"
115
+ type="text"
116
+ required
117
+ value={lastName}
118
+ onChange={(e) => setLastName(e.target.value)}
119
+ placeholder={t('lastNamePlaceholder')}
120
+ autoComplete="family-name"
121
+ className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
122
+ />
123
+ </div>
124
+ </div>
125
+
126
+ <div>
127
+ <label
128
+ htmlFor="register-email"
129
+ className="text-foreground mb-1.5 block text-sm font-medium"
130
+ >
131
+ {t('email')}
132
+ </label>
133
+ <input
134
+ id="register-email"
135
+ type="email"
136
+ required
137
+ value={email}
138
+ onChange={(e) => setEmail(e.target.value)}
139
+ placeholder={t('emailPlaceholder')}
140
+ autoComplete="email"
141
+ className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
142
+ />
143
+ </div>
144
+
145
+ <div>
146
+ <label
147
+ htmlFor="register-password"
148
+ className="text-foreground mb-1.5 block text-sm font-medium"
149
+ >
150
+ {t('password')}
151
+ </label>
152
+ <input
153
+ id="register-password"
154
+ type="password"
155
+ required
156
+ minLength={8}
157
+ value={password}
158
+ onChange={(e) => {
159
+ setPassword(e.target.value);
160
+ if (passwordError) setPasswordError(null);
161
+ }}
162
+ placeholder={t('atLeastChars')}
163
+ autoComplete="new-password"
164
+ className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
165
+ />
166
+ {password.length > 0 && (
167
+ <div className="mt-2">
168
+ <div className="bg-muted h-1.5 w-full overflow-hidden rounded-full">
169
+ <div
170
+ className={cn(
171
+ 'h-full rounded-full transition-all duration-300',
172
+ strength.color,
173
+ strength.width
174
+ )}
175
+ />
176
+ </div>
177
+ <p className="text-muted-foreground mt-1 text-xs">
178
+ {strength.label
179
+ ? t(strength.label as 'tooShort' | 'weak' | 'fair' | 'good' | 'strong')
180
+ : ''}
181
+ </p>
182
+ </div>
183
+ )}
184
+ {passwordError && <p className="text-destructive mt-1 text-xs">{passwordError}</p>}
185
+ </div>
186
+
187
+ {/* Privacy Policy (required) */}
188
+ <div>
189
+ <label className="flex cursor-pointer items-start gap-2">
190
+ <input
191
+ type="checkbox"
192
+ checked={privacyAccepted}
193
+ onChange={(e) => {
194
+ setPrivacyAccepted(e.target.checked);
195
+ setPrivacyError(false);
196
+ }}
197
+ className="accent-primary mt-0.5"
198
+ />
199
+ <span className="text-muted-foreground text-sm">
200
+ {t('privacyAcceptPrefix')}{' '}
201
+ <a
202
+ href="/privacy"
203
+ target="_blank"
204
+ rel="noopener noreferrer"
205
+ className="text-primary underline underline-offset-2"
206
+ >
207
+ {t('privacyPolicyLink')}
208
+ </a>{' '}
209
+ <span className="text-destructive">*</span>
210
+ </span>
211
+ </label>
212
+ {privacyError && <p className="text-destructive mt-1 text-xs">{t('privacyRequired')}</p>}
213
+ </div>
214
+
215
+ {/* Marketing consent (optional) */}
216
+ <label className="flex cursor-pointer items-start gap-2">
217
+ <input
218
+ type="checkbox"
219
+ checked={acceptsMarketing}
220
+ onChange={(e) => setAcceptsMarketing(e.target.checked)}
221
+ className="accent-primary mt-0.5"
222
+ />
223
+ <span className="text-muted-foreground text-sm">{t('acceptsMarketing')}</span>
224
+ </label>
225
+
226
+ <button
227
+ type="submit"
228
+ disabled={loading}
229
+ className="bg-primary text-primary-foreground flex h-10 w-full items-center justify-center gap-2 rounded text-sm font-medium transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
230
+ >
231
+ {loading ? (
232
+ <>
233
+ <LoadingSpinner
234
+ size="sm"
235
+ className="border-primary-foreground/30 border-t-primary-foreground"
236
+ />
237
+ {t('creatingAccount')}
238
+ </>
239
+ ) : (
240
+ t('createAccount')
241
+ )}
242
+ </button>
243
+ </form>
244
+ );
245
+ }