create-brainerce-store 1.36.0 → 1.39.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.
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  "package.json"(exports2, module2) {
32
32
  module2.exports = {
33
33
  name: "create-brainerce-store",
34
- version: "1.36.0",
34
+ version: "1.39.0",
35
35
  description: "Scaffold a production-ready e-commerce storefront connected to Brainerce",
36
36
  bin: {
37
37
  "create-brainerce-store": "dist/index.js"
@@ -153,7 +153,10 @@ var ALLOWED_PACKAGE_MANAGERS = [
153
153
  "bun"
154
154
  ];
155
155
  var BRAINERCE_RUNTIME_DEPS = Object.freeze({
156
- brainerce: "^1.23.0",
156
+ // 1.26 = adds client.content namespace (FAQ / Footer / Header / Announcement /
157
+ // RichText / Page). Scaffolded stores need this minimum to use the content
158
+ // components shipped under src/components/content/.
159
+ brainerce: "^1.26.0",
157
160
  "isomorphic-dompurify": "^3.8.0"
158
161
  });
159
162
 
@@ -332,8 +335,10 @@ async function runInteractive(defaults) {
332
335
  var import_path = __toESM(require("path"));
333
336
  var import_fs_extra = __toESM(require("fs-extra"));
334
337
  var import_ejs = __toESM(require("ejs"));
338
+ var RTL_LANGUAGE_PRIMARIES = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur", "yi"]);
335
339
  function getDirection(language) {
336
- return language === "he" ? "rtl" : "ltr";
340
+ const primary = language.split("-")[0].toLowerCase();
341
+ return RTL_LANGUAGE_PRIMARIES.has(primary) ? "rtl" : "ltr";
337
342
  }
338
343
  function stripControlChars(value) {
339
344
  return value.replace(/\p{Cc}/gu, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-brainerce-store",
3
- "version": "1.36.0",
3
+ "version": "1.39.0",
4
4
  "description": "Scaffold a production-ready e-commerce storefront connected to Brainerce",
5
5
  "bin": {
6
6
  "create-brainerce-store": "dist/index.js"
@@ -0,0 +1,46 @@
1
+ /**
2
+ * FAQ page — fully driven by the merchant's dashboard configuration.
3
+ *
4
+ * The merchant configures FAQs in the Brainerce dashboard under
5
+ * Sell → Content → FAQ
6
+ *
7
+ * This page fetches the merchant's *primary* FAQ (key='main'). For topical
8
+ * FAQs (e.g. /faq/shipping), copy this route to `app/faq/[topic]/page.tsx`
9
+ * and pass `params.topic` to `client.content.faq.get(topic, locale)`.
10
+ */
11
+ import * as React from 'react';
12
+ import type { Metadata } from 'next';
13
+
14
+ import { getServerClient } from '@/lib/brainerce';
15
+ import { FaqSection } from '@/components/content/faq-section';
16
+ <% if (i18nEnabled) { %>
17
+ type PageProps = {
18
+ params: Promise<{ locale: string }>;
19
+ };
20
+
21
+ export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
22
+ const { locale } = await params;
23
+ const faq = await getServerClient(locale).content.faq.get('main', locale).catch(() => null);
24
+ return {
25
+ title: faq?.name ?? 'FAQ',
26
+ };
27
+ }
28
+
29
+ export default async function FaqPage({ params }: PageProps) {
30
+ const { locale } = await params;
31
+ const faq = await getServerClient(locale).content.faq.get('main', locale).catch(() => null);
32
+ return <FaqSection faq={faq} />;
33
+ }
34
+ <% } else { %>
35
+ export async function generateMetadata(): Promise<Metadata> {
36
+ const faq = await getServerClient().content.faq.get('main').catch(() => null);
37
+ return {
38
+ title: faq?.name ?? 'FAQ',
39
+ };
40
+ }
41
+
42
+ export default async function FaqPage() {
43
+ const faq = await getServerClient().content.faq.get('main').catch(() => null);
44
+ return <FaqSection faq={faq} />;
45
+ }
46
+ <% } %>
@@ -0,0 +1,98 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { Link } from '@/lib/navigation';
5
+ import type { Product, DiscountBanner } from 'brainerce';
6
+ import { getClient } from '@/lib/brainerce';
7
+ import { useStoreInfo } from '@/providers/store-provider';
8
+ import { ProductGrid } from '@/components/products/product-grid';
9
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
10
+ import { useTranslations } from '@/lib/translations';
11
+
12
+ export function HomeClient() {
13
+ const { storeInfo, loading: storeLoading } = useStoreInfo();
14
+ const [products, setProducts] = useState<Product[]>([]);
15
+ const [banners, setBanners] = useState<DiscountBanner[]>([]);
16
+ const [loading, setLoading] = useState(true);
17
+ const t = useTranslations('home');
18
+ const tc = useTranslations('common');
19
+
20
+ useEffect(() => {
21
+ async function load() {
22
+ try {
23
+ const client = getClient();
24
+ const [productsRes, bannersRes] = await Promise.allSettled([
25
+ client.getProducts({ limit: 8, sortBy: 'createdAt', sortOrder: 'desc' }),
26
+ client.getDiscountBanners(),
27
+ ]);
28
+
29
+ if (productsRes.status === 'fulfilled') {
30
+ setProducts(productsRes.value.data);
31
+ }
32
+ if (bannersRes.status === 'fulfilled') {
33
+ setBanners(bannersRes.value);
34
+ }
35
+ } catch (err) {
36
+ console.error('Failed to load home page data:', err);
37
+ } finally {
38
+ setLoading(false);
39
+ }
40
+ }
41
+
42
+ load();
43
+ }, []);
44
+
45
+ if (storeLoading || loading) {
46
+ return (
47
+ <div className="flex min-h-[60vh] items-center justify-center">
48
+ <LoadingSpinner size="lg" />
49
+ </div>
50
+ );
51
+ }
52
+
53
+ return (
54
+ <div>
55
+ {/* Discount Banners */}
56
+ {banners.length > 0 && (
57
+ <div className="bg-primary text-primary-foreground">
58
+ <div className="mx-auto max-w-7xl px-4 py-2 sm:px-6 lg:px-8">
59
+ <div className="flex items-center justify-center gap-4 overflow-x-auto text-sm font-medium">
60
+ {banners.map((banner) => (
61
+ <span key={banner.ruleId}>{banner.text}</span>
62
+ ))}
63
+ </div>
64
+ </div>
65
+ </div>
66
+ )}
67
+
68
+ {/* Hero Section */}
69
+ <section className="bg-muted">
70
+ <div className="mx-auto max-w-7xl px-4 py-20 text-center sm:px-6 lg:px-8">
71
+ <h1 className="text-foreground text-4xl font-bold tracking-tight sm:text-5xl">
72
+ {t('welcomeTo')} {storeInfo?.name || tc('store')}
73
+ </h1>
74
+ <p className="text-muted-foreground mx-auto mt-4 max-w-2xl text-lg">
75
+ {t('heroSubtitle')}
76
+ </p>
77
+ <Link
78
+ href="/products"
79
+ className="bg-primary text-primary-foreground mt-8 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
80
+ >
81
+ {tc('shopNow')}
82
+ </Link>
83
+ </div>
84
+ </section>
85
+
86
+ {/* Featured Products */}
87
+ <section className="mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8">
88
+ <div className="mb-8 flex items-center justify-between">
89
+ <h2 className="text-foreground text-2xl font-bold">{t('featuredProducts')}</h2>
90
+ <Link href="/products" className="text-primary text-sm font-medium hover:underline">
91
+ {tc('viewAll')}
92
+ </Link>
93
+ </div>
94
+ <ProductGrid products={products} />
95
+ </section>
96
+ </div>
97
+ );
98
+ }
@@ -2,8 +2,10 @@
2
2
  import type { Metadata } from 'next';
3
3
  <%- fontImport %>
4
4
  import { StoreProvider } from '@/providers/store-provider';
5
- import { Header } from '@/components/layout/header';
6
- import { Footer } from '@/components/layout/footer';
5
+ import { AnnouncementBar } from '@/components/content/announcement-bar';
6
+ import { SiteHeader } from '@/components/content/site-header';
7
+ import { SiteFooter } from '@/components/content/site-footer';
8
+ import { getServerClient } from '@/lib/brainerce';
7
9
  import { getDirection, supportedLocales } from '@/i18n';
8
10
  import { getNonce } from '@/lib/nonce';
9
11
  import '../globals.css';
@@ -54,6 +56,17 @@ export default async function RootLayout({
54
56
  const dir = getDirection(locale);
55
57
  const nonce = await getNonce();
56
58
 
59
+ // Merchant-driven layout chrome — fetched server-side. Each call falls back
60
+ // to null/[] on 404 so the layout never crashes when the merchant hasn't
61
+ // seeded a particular content type yet. New stores ship with default rows
62
+ // seeded by the backend (StoresService.seedDefaultContent).
63
+ const client = getServerClient(locale);
64
+ const [announcements, siteHeader, siteFooter] = await Promise.all([
65
+ client.content.announcement.list(locale).catch(() => []),
66
+ client.content.header.get('main', locale).catch(() => null),
67
+ client.content.footer.get('main', locale).catch(() => null),
68
+ ]);
69
+
57
70
  return (
58
71
  <html lang={locale} dir={dir}>
59
72
  <head>
@@ -72,9 +85,10 @@ export default async function RootLayout({
72
85
  <body className={font.className}>
73
86
  <StoreProvider locale={locale}>
74
87
  <div className="min-h-screen flex flex-col">
75
- <Header />
88
+ <AnnouncementBar announcements={announcements} />
89
+ <SiteHeader header={siteHeader} />
76
90
  <main className="flex-1">{children}</main>
77
- <Footer />
91
+ <SiteFooter footer={siteFooter} storeName={<%- storeNameJs %>} />
78
92
  </div>
79
93
  </StoreProvider>
80
94
  </body>
@@ -85,8 +99,10 @@ export default async function RootLayout({
85
99
  import type { Metadata } from 'next';
86
100
  <%- fontImport %>
87
101
  import { StoreProvider } from '@/providers/store-provider';
88
- import { Header } from '@/components/layout/header';
89
- import { Footer } from '@/components/layout/footer';
102
+ import { AnnouncementBar } from '@/components/content/announcement-bar';
103
+ import { SiteHeader } from '@/components/content/site-header';
104
+ import { SiteFooter } from '@/components/content/site-footer';
105
+ import { getServerClient } from '@/lib/brainerce';
90
106
  import { getNonce } from '@/lib/nonce';
91
107
  import './globals.css';
92
108
 
@@ -128,6 +144,18 @@ export default async function RootLayout({
128
144
  children: React.ReactNode;
129
145
  }) {
130
146
  const nonce = await getNonce();
147
+
148
+ // Merchant-driven layout chrome — fetched server-side. Each call falls back
149
+ // to null/[] on 404 so the layout never crashes when the merchant hasn't
150
+ // seeded a particular content type yet. New stores ship with default rows
151
+ // seeded by the backend (StoresService.seedDefaultContent).
152
+ const client = getServerClient();
153
+ const [announcements, siteHeader, siteFooter] = await Promise.all([
154
+ client.content.announcement.list().catch(() => []),
155
+ client.content.header.get('main').catch(() => null),
156
+ client.content.footer.get('main').catch(() => null),
157
+ ]);
158
+
131
159
  return (
132
160
  <html lang="<%= language %>" dir="<%= direction %>">
133
161
  <head>
@@ -146,9 +174,10 @@ export default async function RootLayout({
146
174
  <body className={font.className}>
147
175
  <StoreProvider>
148
176
  <div className="min-h-screen flex flex-col">
149
- <Header />
177
+ <AnnouncementBar announcements={announcements} />
178
+ <SiteHeader header={siteHeader} />
150
179
  <main className="flex-1">{children}</main>
151
- <Footer />
180
+ <SiteFooter footer={siteFooter} storeName={<%- storeNameJs %>} />
152
181
  </div>
153
182
  </StoreProvider>
154
183
  </body>
@@ -1,98 +1,53 @@
1
- 'use client';
2
-
3
- import { useEffect, useState } from 'react';
4
- import { Link } from '@/lib/navigation';
5
- import type { Product, DiscountBanner } from 'brainerce';
6
- import { getClient } from '@/lib/brainerce';
7
- import { useStoreInfo } from '@/providers/store-provider';
8
- import { ProductGrid } from '@/components/products/product-grid';
9
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
10
- import { useTranslations } from '@/lib/translations';
11
-
12
- export default function HomePage() {
13
- const { storeInfo, loading: storeLoading } = useStoreInfo();
14
- const [products, setProducts] = useState<Product[]>([]);
15
- const [banners, setBanners] = useState<DiscountBanner[]>([]);
16
- const [loading, setLoading] = useState(true);
17
- const t = useTranslations('home');
18
- const tc = useTranslations('common');
19
-
20
- useEffect(() => {
21
- async function load() {
22
- try {
23
- const client = getClient();
24
- const [productsRes, bannersRes] = await Promise.allSettled([
25
- client.getProducts({ limit: 8, sortBy: 'createdAt', sortOrder: 'desc' }),
26
- client.getDiscountBanners(),
27
- ]);
28
-
29
- if (productsRes.status === 'fulfilled') {
30
- setProducts(productsRes.value.data);
31
- }
32
- if (bannersRes.status === 'fulfilled') {
33
- setBanners(bannersRes.value);
34
- }
35
- } catch (err) {
36
- console.error('Failed to load home page data:', err);
37
- } finally {
38
- setLoading(false);
39
- }
40
- }
41
-
42
- load();
43
- }, []);
44
-
45
- if (storeLoading || loading) {
46
- return (
47
- <div className="flex min-h-[60vh] items-center justify-center">
48
- <LoadingSpinner size="lg" />
49
- </div>
50
- );
51
- }
52
-
53
- return (
54
- <div>
55
- {/* Discount Banners */}
56
- {banners.length > 0 && (
57
- <div className="bg-primary text-primary-foreground">
58
- <div className="mx-auto max-w-7xl px-4 py-2 sm:px-6 lg:px-8">
59
- <div className="flex items-center justify-center gap-4 overflow-x-auto text-sm font-medium">
60
- {banners.map((banner) => (
61
- <span key={banner.ruleId}>{banner.text}</span>
62
- ))}
63
- </div>
64
- </div>
65
- </div>
66
- )}
67
-
68
- {/* Hero Section */}
69
- <section className="bg-muted">
70
- <div className="mx-auto max-w-7xl px-4 py-20 text-center sm:px-6 lg:px-8">
71
- <h1 className="text-foreground text-4xl font-bold tracking-tight sm:text-5xl">
72
- {t('welcomeTo')} {storeInfo?.name || tc('store')}
73
- </h1>
74
- <p className="text-muted-foreground mx-auto mt-4 max-w-2xl text-lg">
75
- {t('heroSubtitle')}
76
- </p>
77
- <Link
78
- href="/products"
79
- className="bg-primary text-primary-foreground mt-8 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
80
- >
81
- {tc('shopNow')}
82
- </Link>
83
- </div>
84
- </section>
85
-
86
- {/* Featured Products */}
87
- <section className="mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8">
88
- <div className="mb-8 flex items-center justify-between">
89
- <h2 className="text-foreground text-2xl font-bold">{t('featuredProducts')}</h2>
90
- <Link href="/products" className="text-primary text-sm font-medium hover:underline">
91
- {tc('viewAll')}
92
- </Link>
93
- </div>
94
- <ProductGrid products={products} />
95
- </section>
96
- </div>
97
- );
98
- }
1
+ import type { Metadata } from 'next';
2
+ import { getServerClient } from '@/lib/brainerce';
3
+ import { buildMetaDescription } from '@/lib/seo';
4
+ import { OrganizationJsonLd } from '@/components/seo/organization-json-ld';
5
+ import { HomeClient } from './home-client';
6
+
7
+ // Build homepage metadata server-side so Google, Facebook, WhatsApp etc.
8
+ // see a real <meta name="description"> on first request. Falls back to the
9
+ // store name when the merchant hasn't authored a meta description yet.
10
+ export async function generateMetadata(): Promise<Metadata> {
11
+ try {
12
+ const storeInfo = await getServerClient().getStoreInfo();
13
+ const description = buildMetaDescription(storeInfo.metaDescription) || undefined;
14
+ return {
15
+ title: storeInfo.name,
16
+ description,
17
+ openGraph: {
18
+ title: storeInfo.name,
19
+ description,
20
+ type: 'website',
21
+ },
22
+ twitter: {
23
+ card: 'summary_large_image',
24
+ title: storeInfo.name,
25
+ description,
26
+ },
27
+ };
28
+ } catch {
29
+ return {};
30
+ }
31
+ }
32
+
33
+ export default async function HomePage() {
34
+ // Fetch store info server-side so the JSON-LD is in the initial HTML —
35
+ // crawlers and AI Overviews see it without needing to execute JavaScript.
36
+ // Failure here is non-fatal: the client component re-fetches via the
37
+ // StoreProvider so the page still renders.
38
+ let storeInfo = null;
39
+ try {
40
+ storeInfo = await getServerClient().getStoreInfo();
41
+ } catch {
42
+ storeInfo = null;
43
+ }
44
+
45
+ const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || '';
46
+
47
+ return (
48
+ <>
49
+ {storeInfo && baseUrl ? <OrganizationJsonLd storeInfo={storeInfo} baseUrl={baseUrl} /> : null}
50
+ <HomeClient />
51
+ </>
52
+ );
53
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Static page route — fully driven by the merchant's dashboard.
3
+ *
4
+ * The merchant creates pages in the Brainerce dashboard under
5
+ * Sell → Content → Page (one row per page, each with its own `slug`)
6
+ *
7
+ * This catch-all renders any PAGE by its `data.slug`. `/pages/about` →
8
+ * fetches PAGE with slug='about'. Mounting under `/pages/` (rather than
9
+ * the root) keeps the route from clashing with existing static routes
10
+ * like /cart, /login, /products.
11
+ *
12
+ * Security: page HTML is sanitized via `sanitizeHtml` before injecting.
13
+ */
14
+ import * as React from 'react';
15
+ import type { Metadata } from 'next';
16
+ import { notFound } from 'next/navigation';
17
+
18
+ import { getServerClient } from '@/lib/brainerce';
19
+ import { sanitizeHtml } from '@/lib/sanitize';
20
+
21
+ <% if (i18nEnabled) { %>
22
+ type PageProps = {
23
+ params: Promise<{ locale: string; slug: string }>;
24
+ };
25
+
26
+ export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
27
+ const { locale, slug } = await params;
28
+ const page = await getServerClient(locale).content.page.getBySlug(slug, locale).catch(() => null);
29
+ if (!page) return { title: slug };
30
+ const seo = page.data.seo ?? {};
31
+ return {
32
+ title: seo.title ?? page.data.title,
33
+ description: seo.description,
34
+ openGraph: seo.ogImage ? { images: [{ url: seo.ogImage }] } : undefined,
35
+ };
36
+ }
37
+
38
+ export default async function StaticPage({ params }: PageProps) {
39
+ const { locale, slug } = await params;
40
+ const page = await getServerClient(locale).content.page.getBySlug(slug, locale).catch(() => null);
41
+ if (!page) notFound();
42
+ return (
43
+ <article className="mx-auto max-w-3xl px-4 py-10 sm:px-6 lg:px-8">
44
+ <h1 className="text-foreground mb-6 text-2xl font-semibold sm:text-3xl">
45
+ {page.data.title}
46
+ </h1>
47
+ <div
48
+ className="prose prose-sm dark:prose-invert max-w-none"
49
+ dangerouslySetInnerHTML={{ __html: sanitizeHtml(page.data.html) }}
50
+ />
51
+ </article>
52
+ );
53
+ }
54
+ <% } else { %>
55
+ type PageProps = {
56
+ params: Promise<{ slug: string }>;
57
+ };
58
+
59
+ export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
60
+ const { slug } = await params;
61
+ const page = await getServerClient().content.page.getBySlug(slug).catch(() => null);
62
+ if (!page) return { title: slug };
63
+ const seo = page.data.seo ?? {};
64
+ return {
65
+ title: seo.title ?? page.data.title,
66
+ description: seo.description,
67
+ openGraph: seo.ogImage ? { images: [{ url: seo.ogImage }] } : undefined,
68
+ };
69
+ }
70
+
71
+ export default async function StaticPage({ params }: PageProps) {
72
+ const { slug } = await params;
73
+ const page = await getServerClient().content.page.getBySlug(slug).catch(() => null);
74
+ if (!page) notFound();
75
+ return (
76
+ <article className="mx-auto max-w-3xl px-4 py-10 sm:px-6 lg:px-8">
77
+ <h1 className="text-foreground mb-6 text-2xl font-semibold sm:text-3xl">
78
+ {page.data.title}
79
+ </h1>
80
+ <div
81
+ className="prose prose-sm dark:prose-invert max-w-none"
82
+ dangerouslySetInnerHTML={{ __html: sanitizeHtml(page.data.html) }}
83
+ />
84
+ </article>
85
+ );
86
+ }
87
+ <% } %>
@@ -1,6 +1,7 @@
1
1
  import type { Metadata } from 'next';
2
2
  import { notFound } from 'next/navigation';
3
3
  import { getServerClient } from '@/lib/brainerce';
4
+ import { buildMetaDescription } from '@/lib/seo';
4
5
  import { ProductJsonLd } from '@/components/seo/product-json-ld';
5
6
  import { ReviewsSection } from '@/components/reviews/reviews-section';
6
7
  import { ProductClientSection } from './product-client-section';
@@ -16,12 +17,13 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
16
17
  const client = getServerClient(locale);
17
18
  const product = await client.getProductBySlug(slug);
18
19
  const imageUrl = product.images?.[0]?.url;
19
- // Prefer merchant-authored SEO copy; fall back to the visible name/description.
20
- // Both are served already locale-resolved by the backend.
20
+ // Prefer merchant-authored SEO copy; fall back to a stripped+truncated
21
+ // version of the visible description, then product name. We must NEVER
22
+ // emit raw HTML or a mid-word cut into <meta name="description">.
21
23
  const seoTitle = (product as { seoTitle?: string | null }).seoTitle || product.name;
22
24
  const seoDescription =
23
25
  (product as { seoDescription?: string | null }).seoDescription ||
24
- product.description?.substring(0, 160) ||
26
+ buildMetaDescription(product.description) ||
25
27
  product.name;
26
28
 
27
29
  return {