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,76 +1,73 @@
1
- import type { Metadata } from 'next';
2
- import { headers } from 'next/headers';
3
- import { notFound } from 'next/navigation';
4
- import { getServerClient } from '@/lib/brainerce';
5
- import { ProductJsonLd } from '@/components/seo/product-json-ld';
6
- import { ProductClientSection } from './product-client-section';
7
-
8
- type Props = {
9
- params: Promise<{ slug: string }>;
10
- };
11
-
12
- // Read the locale the middleware set on this request so the SDK can resolve
13
- // translated slugs (translations[locale].slug) in addition to the base slug.
14
- async function getRequestLocale(): Promise<string | undefined> {
15
- return (await headers()).get('x-locale') ?? undefined;
16
- }
17
-
18
- export async function generateMetadata({ params }: Props): Promise<Metadata> {
19
- const { slug } = await params;
20
- const locale = await getRequestLocale();
21
-
22
- try {
23
- const client = getServerClient();
24
- const product = await client.getProductBySlug(slug, { locale });
25
- const imageUrl = product.images?.[0]?.url;
26
- const description = product.description?.substring(0, 160) || product.name;
27
-
28
- return {
29
- title: product.name,
30
- description,
31
- alternates: {
32
- canonical: `/products/${slug}`,
33
- },
34
- openGraph: {
35
- title: product.name,
36
- description,
37
- images: imageUrl ? [{ url: imageUrl, alt: product.name }] : [],
38
- type: 'website',
39
- },
40
- twitter: {
41
- card: 'summary_large_image',
42
- title: product.name,
43
- description,
44
- images: imageUrl ? [imageUrl] : [],
45
- },
46
- };
47
- } catch {
48
- return {
49
- title: 'Product not found',
50
- };
51
- }
52
- }
53
-
54
- export default async function ProductDetailPage({ params }: Props) {
55
- const { slug } = await params;
56
- const locale = await getRequestLocale();
57
-
58
- let product;
59
- try {
60
- const client = getServerClient();
61
- product = await client.getProductBySlug(slug, { locale });
62
- } catch {
63
- notFound();
64
- }
65
-
66
- const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || '';
67
- const productUrl = `${baseUrl}/products/${slug}`;
68
- const currency = process.env.NEXT_PUBLIC_STORE_CURRENCY || 'USD';
69
-
70
- return (
71
- <>
72
- <ProductJsonLd product={product} url={productUrl} currency={currency} />
73
- <ProductClientSection product={product} />
74
- </>
75
- );
76
- }
1
+ import type { Metadata } from 'next';
2
+ import { notFound } from 'next/navigation';
3
+ import { getServerClient } from '@/lib/brainerce';
4
+ import { ProductJsonLd } from '@/components/seo/product-json-ld';
5
+ import { ProductClientSection } from './product-client-section';
6
+
7
+ type Props = {
8
+ params: Promise<{ slug: string; locale?: string }>;
9
+ };
10
+
11
+ export async function generateMetadata({ params }: Props): Promise<Metadata> {
12
+ const { slug, locale } = await params;
13
+
14
+ try {
15
+ const client = getServerClient(locale);
16
+ const product = await client.getProductBySlug(slug);
17
+ const imageUrl = product.images?.[0]?.url;
18
+ // Prefer merchant-authored SEO copy; fall back to the visible name/description.
19
+ // Both are served already locale-resolved by the backend.
20
+ const seoTitle = (product as { seoTitle?: string | null }).seoTitle || product.name;
21
+ const seoDescription =
22
+ (product as { seoDescription?: string | null }).seoDescription ||
23
+ product.description?.substring(0, 160) ||
24
+ product.name;
25
+
26
+ return {
27
+ title: seoTitle,
28
+ description: seoDescription,
29
+ alternates: {
30
+ canonical: `/products/${slug}`,
31
+ },
32
+ openGraph: {
33
+ title: seoTitle,
34
+ description: seoDescription,
35
+ images: imageUrl ? [{ url: imageUrl, alt: product.name }] : [],
36
+ type: 'website',
37
+ },
38
+ twitter: {
39
+ card: 'summary_large_image',
40
+ title: seoTitle,
41
+ description: seoDescription,
42
+ images: imageUrl ? [imageUrl] : [],
43
+ },
44
+ };
45
+ } catch {
46
+ return {
47
+ title: 'Product not found',
48
+ };
49
+ }
50
+ }
51
+
52
+ export default async function ProductDetailPage({ params }: Props) {
53
+ const { slug, locale } = await params;
54
+
55
+ let product;
56
+ try {
57
+ const client = getServerClient(locale);
58
+ product = await client.getProductBySlug(slug);
59
+ } catch {
60
+ notFound();
61
+ }
62
+
63
+ const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || '';
64
+ const productUrl = `${baseUrl}/products/${slug}`;
65
+ const currency = process.env.NEXT_PUBLIC_STORE_CURRENCY || 'USD';
66
+
67
+ return (
68
+ <>
69
+ <ProductJsonLd product={product} url={productUrl} currency={currency} />
70
+ <ProductClientSection product={product} />
71
+ </>
72
+ );
73
+ }