create-brainerce-store 1.66.0 → 1.67.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 (46) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
  3. package/templates/nextjs/base/.env.local.ejs +45 -24
  4. package/templates/nextjs/base/.eslintrc.json +51 -57
  5. package/templates/nextjs/base/AGENTS.md.ejs +107 -81
  6. package/templates/nextjs/base/CLAUDE.md.ejs +118 -92
  7. package/templates/nextjs/base/next.config.ts +103 -86
  8. package/templates/nextjs/base/scripts/fetch-store-info.mjs +104 -97
  9. package/templates/nextjs/base/src/app/agents.md/route.ts +4 -3
  10. package/templates/nextjs/base/src/app/api/auth/me/route.ts +65 -59
  11. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +255 -242
  12. package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +311 -308
  13. package/templates/nextjs/base/src/app/blog/page.tsx.ejs +277 -276
  14. package/templates/nextjs/base/src/app/blog/rss.xml/route.ts +4 -3
  15. package/templates/nextjs/base/src/app/category/[slug]/page.tsx +6 -5
  16. package/templates/nextjs/base/src/app/faq/page.tsx.ejs +46 -46
  17. package/templates/nextjs/base/src/app/indexnow-key.txt/route.ts +25 -26
  18. package/templates/nextjs/base/src/app/layout.tsx.ejs +273 -257
  19. package/templates/nextjs/base/src/app/llms.txt/route.ts +4 -3
  20. package/templates/nextjs/base/src/app/opengraph-image.tsx +1 -1
  21. package/templates/nextjs/base/src/app/page.tsx +65 -64
  22. package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +92 -92
  23. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +6 -5
  24. package/templates/nextjs/base/src/app/robots.ts +3 -2
  25. package/templates/nextjs/base/src/app/sitemap.ts +4 -3
  26. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +294 -292
  27. package/templates/nextjs/base/src/components/seo/article-json-ld.tsx +60 -59
  28. package/templates/nextjs/base/src/components/seo/category-json-ld.tsx +60 -61
  29. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +2 -1
  30. package/templates/nextjs/base/src/core/lib/brainerce.server.ts +81 -0
  31. package/templates/nextjs/base/src/core/lib/brainerce.ts.ejs +60 -110
  32. package/templates/nextjs/base/src/core/lib/site-url.ts +197 -0
  33. package/templates/nextjs/base/src/ui/product/review-form.tsx +294 -294
  34. package/templates/nextjs/base/src/ui/product/reviews-section.tsx.ejs +108 -108
  35. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +301 -285
  36. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +97 -96
  37. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +142 -141
  38. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +139 -138
  39. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +295 -267
  40. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -148
  41. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +72 -71
  42. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +83 -82
  43. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +120 -119
  44. package/templates/nextjs/ui-canvas/product/faq-section.tsx.ejs +54 -0
  45. package/templates/nextjs/ui-canvas/product/review-form.tsx +267 -266
  46. package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +96 -96
@@ -1,266 +1,267 @@
1
- 'use client';
2
-
3
- import { useEffect, useState } from 'react';
4
- import { getClient } from '@/core/lib/brainerce';
5
- import { checkAuthStatus } from '@/core/lib/auth';
6
- import { useTranslations } from '@/core/lib/translations';
7
- import type { MyProductReview, ProductReview } from 'brainerce';
8
-
9
- interface ReviewFormProps {
10
- productId: string;
11
- }
12
-
13
- type Stage =
14
- | { kind: 'loading' }
15
- | { kind: 'signed_out' }
16
- | { kind: 'not_eligible'; reason: MyProductReview['reason'] }
17
- | { kind: 'submit' }
18
- | { kind: 'edit'; review: ProductReview };
19
-
20
- /**
21
- * Single component that decides which UI to render for a customer on a PDP:
22
- * - Loading while we check auth state and eligibility
23
- * - Signed out -> sign-in CTA
24
- * - Signed in but not eligible -> "purchase this product to review"
25
- * - Eligible without review -> submit form
26
- * - Eligible with existing review -> edit/delete form (rating + body prefilled)
27
- *
28
- * DESIGN ME — review submit/edit form; auth via checkAuthStatus(), eligibility
29
- * + existing review via getClient().getMyProductReview(productId).
30
- *
31
- * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with.
32
- */
33
- export function ReviewForm({ productId }: ReviewFormProps) {
34
- const [stage, setStage] = useState<Stage>({ kind: 'loading' });
35
- const t = useTranslations('reviews');
36
-
37
- useEffect(() => {
38
- let cancelled = false;
39
- async function load() {
40
- const auth = await checkAuthStatus();
41
- if (cancelled) return;
42
- if (!auth.isLoggedIn) {
43
- setStage({ kind: 'signed_out' });
44
- return;
45
- }
46
- try {
47
- const me = await getClient().getMyProductReview(productId);
48
- if (cancelled) return;
49
- if (!me.eligible) {
50
- setStage({ kind: 'not_eligible', reason: me.reason });
51
- return;
52
- }
53
- if (me.myReview) {
54
- setStage({ kind: 'edit', review: me.myReview });
55
- return;
56
- }
57
- setStage({ kind: 'submit' });
58
- } catch {
59
- if (!cancelled) setStage({ kind: 'not_eligible', reason: 'product_not_found' });
60
- }
61
- }
62
- void load();
63
- return () => {
64
- cancelled = true;
65
- };
66
- }, [productId]);
67
-
68
- if (stage.kind === 'loading') {
69
- return <p role="status">{t('loading')}</p>;
70
- }
71
-
72
- if (stage.kind === 'signed_out') {
73
- return (
74
- <p>
75
- <a href="/account/login">{t('signIn')}</a> {t('signInSuffix')}
76
- </p>
77
- );
78
- }
79
-
80
- if (stage.kind === 'not_eligible') {
81
- return <NotEligibleMessage reason={stage.reason} />;
82
- }
83
-
84
- if (stage.kind === 'edit') {
85
- return (
86
- <EditReviewBlock
87
- productId={productId}
88
- initial={stage.review}
89
- onDeleted={() => setStage({ kind: 'submit' })}
90
- />
91
- );
92
- }
93
-
94
- return <SubmitReviewBlock productId={productId} />;
95
- }
96
-
97
- function NotEligibleMessage({ reason }: { reason: MyProductReview['reason'] }) {
98
- const t = useTranslations('reviews');
99
- let message: string;
100
- switch (reason) {
101
- case 'no_eligible_order':
102
- message = t('onlyPurchasers');
103
- break;
104
- case 'reviews_disabled':
105
- message = t('reviewsDisabled');
106
- break;
107
- default:
108
- message = t('cannotReview');
109
- }
110
- return <p>{message}</p>;
111
- }
112
-
113
- function SubmitReviewBlock({ productId }: { productId: string }) {
114
- return <ReviewEditor productId={productId} mode="create" initialRating={5} initialBody="" />;
115
- }
116
-
117
- function EditReviewBlock({
118
- productId,
119
- initial,
120
- onDeleted,
121
- }: {
122
- productId: string;
123
- initial: ProductReview;
124
- onDeleted: () => void;
125
- }) {
126
- const [deleting, setDeleting] = useState(false);
127
- const t = useTranslations('reviews');
128
- const [deleteError, setDeleteError] = useState<string | null>(null);
129
-
130
- async function handleDelete() {
131
- if (!window.confirm(t('confirmDelete'))) return;
132
- setDeleting(true);
133
- setDeleteError(null);
134
- try {
135
- await getClient().deleteMyProductReview(productId);
136
- onDeleted();
137
- window.location.reload();
138
- } catch {
139
- setDeleteError(t('deleteFailed'));
140
- } finally {
141
- setDeleting(false);
142
- }
143
- }
144
-
145
- return (
146
- <div>
147
- <ReviewEditor
148
- productId={productId}
149
- mode="edit"
150
- initialRating={initial.rating}
151
- initialBody={initial.body ?? ''}
152
- />
153
- <div className="flex items-center gap-2">
154
- <p>{t('startOver')}</p>
155
- <button type="button" onClick={handleDelete} disabled={deleting}>
156
- {deleting ? t('deleting') : t('deleteReview')}
157
- </button>
158
- </div>
159
- {deleteError && <p role="alert">{deleteError}</p>}
160
- </div>
161
- );
162
- }
163
-
164
- /**
165
- * The actual form. Same shape for create and edit — only the API method
166
- * and the heading differ. Optimistic UX: success state + page reload to
167
- * let the server-rendered reviews list pick up the change.
168
- */
169
- function ReviewEditor({
170
- productId,
171
- mode,
172
- initialRating,
173
- initialBody,
174
- }: {
175
- productId: string;
176
- mode: 'create' | 'edit';
177
- initialRating: number;
178
- initialBody: string;
179
- }) {
180
- const [rating, setRating] = useState(initialRating);
181
- const t = useTranslations('reviews');
182
- const [body, setBody] = useState(initialBody);
183
- const [submitting, setSubmitting] = useState(false);
184
- const [error, setError] = useState<string | null>(null);
185
- const [success, setSuccess] = useState(false);
186
-
187
- async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
188
- event.preventDefault();
189
- setError(null);
190
- setSubmitting(true);
191
- try {
192
- const client = getClient();
193
- const input = { rating, body: body.trim() || undefined };
194
- if (mode === 'edit') {
195
- await client.updateMyProductReview(productId, input);
196
- } else {
197
- await client.submitProductReview(productId, input);
198
- }
199
- setSuccess(true);
200
- setTimeout(() => window.location.reload(), 1200);
201
- } catch (err) {
202
- const status = (err as { status?: number })?.status;
203
- if (status === 409) {
204
- setError(t('alreadySubmitted'));
205
- } else if (status === 403) {
206
- setError(t('onlyPurchasers'));
207
- } else if (status === 429) {
208
- setError(t('tooMany'));
209
- } else {
210
- setError(mode === 'edit' ? t('updateFailed') : t('submitFailed'));
211
- }
212
- } finally {
213
- setSubmitting(false);
214
- }
215
- }
216
-
217
- if (success) {
218
- return <p role="status">{mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}</p>;
219
- }
220
-
221
- return (
222
- <form onSubmit={handleSubmit}>
223
- <h3>{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
224
-
225
- <fieldset>
226
- <legend>{t('yourRating')}</legend>
227
- <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
228
- {[1, 2, 3, 4, 5].map((n) => (
229
- <button
230
- key={n}
231
- type="button"
232
- role="radio"
233
- aria-checked={rating === n}
234
- onClick={() => setRating(n)}
235
- >
236
- {n <= rating ? '★' : '☆'}
237
- </button>
238
- ))}
239
- </div>
240
- </fieldset>
241
-
242
- <label className="block">
243
- {t('yourReview')} <span>({t('optionalField')})</span>
244
- <textarea
245
- value={body}
246
- onChange={(event) => setBody(event.target.value)}
247
- maxLength={5000}
248
- rows={4}
249
- className="block w-full"
250
- />
251
- </label>
252
-
253
- {error && <p role="alert">{error}</p>}
254
-
255
- <button type="submit" disabled={submitting}>
256
- {submitting
257
- ? mode === 'edit'
258
- ? t('saving')
259
- : t('submittingBtn')
260
- : mode === 'edit'
261
- ? t('saveChanges')
262
- : t('submitReview')}
263
- </button>
264
- </form>
265
- );
266
- }
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { Link } from '@/core/lib/navigation';
5
+ import { getClient } from '@/core/lib/brainerce';
6
+ import { checkAuthStatus } from '@/core/lib/auth';
7
+ import { useTranslations } from '@/core/lib/translations';
8
+ import type { MyProductReview, ProductReview } from 'brainerce';
9
+
10
+ interface ReviewFormProps {
11
+ productId: string;
12
+ }
13
+
14
+ type Stage =
15
+ | { kind: 'loading' }
16
+ | { kind: 'signed_out' }
17
+ | { kind: 'not_eligible'; reason: MyProductReview['reason'] }
18
+ | { kind: 'submit' }
19
+ | { kind: 'edit'; review: ProductReview };
20
+
21
+ /**
22
+ * Single component that decides which UI to render for a customer on a PDP:
23
+ * - Loading while we check auth state and eligibility
24
+ * - Signed out -> sign-in CTA
25
+ * - Signed in but not eligible -> "purchase this product to review"
26
+ * - Eligible without review -> submit form
27
+ * - Eligible with existing review -> edit/delete form (rating + body prefilled)
28
+ *
29
+ * DESIGN ME review submit/edit form; auth via checkAuthStatus(), eligibility
30
+ * + existing review via getClient().getMyProductReview(productId).
31
+ *
32
+ * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with.
33
+ */
34
+ export function ReviewForm({ productId }: ReviewFormProps) {
35
+ const [stage, setStage] = useState<Stage>({ kind: 'loading' });
36
+ const t = useTranslations('reviews');
37
+
38
+ useEffect(() => {
39
+ let cancelled = false;
40
+ async function load() {
41
+ const auth = await checkAuthStatus();
42
+ if (cancelled) return;
43
+ if (!auth.isLoggedIn) {
44
+ setStage({ kind: 'signed_out' });
45
+ return;
46
+ }
47
+ try {
48
+ const me = await getClient().getMyProductReview(productId);
49
+ if (cancelled) return;
50
+ if (!me.eligible) {
51
+ setStage({ kind: 'not_eligible', reason: me.reason });
52
+ return;
53
+ }
54
+ if (me.myReview) {
55
+ setStage({ kind: 'edit', review: me.myReview });
56
+ return;
57
+ }
58
+ setStage({ kind: 'submit' });
59
+ } catch {
60
+ if (!cancelled) setStage({ kind: 'not_eligible', reason: 'product_not_found' });
61
+ }
62
+ }
63
+ void load();
64
+ return () => {
65
+ cancelled = true;
66
+ };
67
+ }, [productId]);
68
+
69
+ if (stage.kind === 'loading') {
70
+ return <p role="status">{t('loading')}</p>;
71
+ }
72
+
73
+ if (stage.kind === 'signed_out') {
74
+ return (
75
+ <p>
76
+ <Link href="/login">{t('signIn')}</Link> {t('signInSuffix')}
77
+ </p>
78
+ );
79
+ }
80
+
81
+ if (stage.kind === 'not_eligible') {
82
+ return <NotEligibleMessage reason={stage.reason} />;
83
+ }
84
+
85
+ if (stage.kind === 'edit') {
86
+ return (
87
+ <EditReviewBlock
88
+ productId={productId}
89
+ initial={stage.review}
90
+ onDeleted={() => setStage({ kind: 'submit' })}
91
+ />
92
+ );
93
+ }
94
+
95
+ return <SubmitReviewBlock productId={productId} />;
96
+ }
97
+
98
+ function NotEligibleMessage({ reason }: { reason: MyProductReview['reason'] }) {
99
+ const t = useTranslations('reviews');
100
+ let message: string;
101
+ switch (reason) {
102
+ case 'no_eligible_order':
103
+ message = t('onlyPurchasers');
104
+ break;
105
+ case 'reviews_disabled':
106
+ message = t('reviewsDisabled');
107
+ break;
108
+ default:
109
+ message = t('cannotReview');
110
+ }
111
+ return <p>{message}</p>;
112
+ }
113
+
114
+ function SubmitReviewBlock({ productId }: { productId: string }) {
115
+ return <ReviewEditor productId={productId} mode="create" initialRating={5} initialBody="" />;
116
+ }
117
+
118
+ function EditReviewBlock({
119
+ productId,
120
+ initial,
121
+ onDeleted,
122
+ }: {
123
+ productId: string;
124
+ initial: ProductReview;
125
+ onDeleted: () => void;
126
+ }) {
127
+ const [deleting, setDeleting] = useState(false);
128
+ const t = useTranslations('reviews');
129
+ const [deleteError, setDeleteError] = useState<string | null>(null);
130
+
131
+ async function handleDelete() {
132
+ if (!window.confirm(t('confirmDelete'))) return;
133
+ setDeleting(true);
134
+ setDeleteError(null);
135
+ try {
136
+ await getClient().deleteMyProductReview(productId);
137
+ onDeleted();
138
+ window.location.reload();
139
+ } catch {
140
+ setDeleteError(t('deleteFailed'));
141
+ } finally {
142
+ setDeleting(false);
143
+ }
144
+ }
145
+
146
+ return (
147
+ <div>
148
+ <ReviewEditor
149
+ productId={productId}
150
+ mode="edit"
151
+ initialRating={initial.rating}
152
+ initialBody={initial.body ?? ''}
153
+ />
154
+ <div className="flex items-center gap-2">
155
+ <p>{t('startOver')}</p>
156
+ <button type="button" onClick={handleDelete} disabled={deleting}>
157
+ {deleting ? t('deleting') : t('deleteReview')}
158
+ </button>
159
+ </div>
160
+ {deleteError && <p role="alert">{deleteError}</p>}
161
+ </div>
162
+ );
163
+ }
164
+
165
+ /**
166
+ * The actual form. Same shape for create and edit only the API method
167
+ * and the heading differ. Optimistic UX: success state + page reload to
168
+ * let the server-rendered reviews list pick up the change.
169
+ */
170
+ function ReviewEditor({
171
+ productId,
172
+ mode,
173
+ initialRating,
174
+ initialBody,
175
+ }: {
176
+ productId: string;
177
+ mode: 'create' | 'edit';
178
+ initialRating: number;
179
+ initialBody: string;
180
+ }) {
181
+ const [rating, setRating] = useState(initialRating);
182
+ const t = useTranslations('reviews');
183
+ const [body, setBody] = useState(initialBody);
184
+ const [submitting, setSubmitting] = useState(false);
185
+ const [error, setError] = useState<string | null>(null);
186
+ const [success, setSuccess] = useState(false);
187
+
188
+ async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
189
+ event.preventDefault();
190
+ setError(null);
191
+ setSubmitting(true);
192
+ try {
193
+ const client = getClient();
194
+ const input = { rating, body: body.trim() || undefined };
195
+ if (mode === 'edit') {
196
+ await client.updateMyProductReview(productId, input);
197
+ } else {
198
+ await client.submitProductReview(productId, input);
199
+ }
200
+ setSuccess(true);
201
+ setTimeout(() => window.location.reload(), 1200);
202
+ } catch (err) {
203
+ const status = (err as { status?: number })?.status;
204
+ if (status === 409) {
205
+ setError(t('alreadySubmitted'));
206
+ } else if (status === 403) {
207
+ setError(t('onlyPurchasers'));
208
+ } else if (status === 429) {
209
+ setError(t('tooMany'));
210
+ } else {
211
+ setError(mode === 'edit' ? t('updateFailed') : t('submitFailed'));
212
+ }
213
+ } finally {
214
+ setSubmitting(false);
215
+ }
216
+ }
217
+
218
+ if (success) {
219
+ return <p role="status">{mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}</p>;
220
+ }
221
+
222
+ return (
223
+ <form onSubmit={handleSubmit}>
224
+ <h3>{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
225
+
226
+ <fieldset>
227
+ <legend>{t('yourRating')}</legend>
228
+ <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
229
+ {[1, 2, 3, 4, 5].map((n) => (
230
+ <button
231
+ key={n}
232
+ type="button"
233
+ role="radio"
234
+ aria-checked={rating === n}
235
+ onClick={() => setRating(n)}
236
+ >
237
+ {n <= rating ? '★' : '☆'}
238
+ </button>
239
+ ))}
240
+ </div>
241
+ </fieldset>
242
+
243
+ <label className="block">
244
+ {t('yourReview')} <span>({t('optionalField')})</span>
245
+ <textarea
246
+ value={body}
247
+ onChange={(event) => setBody(event.target.value)}
248
+ maxLength={5000}
249
+ rows={4}
250
+ className="block w-full"
251
+ />
252
+ </label>
253
+
254
+ {error && <p role="alert">{error}</p>}
255
+
256
+ <button type="submit" disabled={submitting}>
257
+ {submitting
258
+ ? mode === 'edit'
259
+ ? t('saving')
260
+ : t('submittingBtn')
261
+ : mode === 'edit'
262
+ ? t('saveChanges')
263
+ : t('submitReview')}
264
+ </button>
265
+ </form>
266
+ );
267
+ }