@brainerce/mcp-server 3.7.0 → 3.8.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/bin/stdio.js CHANGED
@@ -2200,9 +2200,12 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
2200
2200
  const client = getServerClient();
2201
2201
  client.setLocale(locale);
2202
2202
  const product = await client.getProductBySlug(slug);
2203
+ // NEVER feed raw HTML into <meta name="description"> \u2014 product.description
2204
+ // is often rich-text HTML. Strip tags first, then truncate on a word
2205
+ // boundary. See buildMetaDescription() in lib/seo.ts.
2203
2206
  return {
2204
2207
  title: product.seoTitle || product.name,
2205
- description: product.seoDescription || product.description?.slice(0, 160),
2208
+ description: product.seoDescription || buildMetaDescription(product.description) || product.name,
2206
2209
  };
2207
2210
  }
2208
2211
  \`\`\`
@@ -2318,11 +2321,25 @@ Because the backend already overlays everything, UI code is just:
2318
2321
 
2319
2322
  ### RTL handling
2320
2323
 
2321
- For RTL locales (\`he\`, \`ar\`), set \`<html dir="rtl">\` in the root layout and
2322
- let flexbox reverse automatically. Do NOT add \`flex-row-reverse\` on top of
2323
- \`dir="rtl"\` \u2014 that's a double-swap. DO swap directional icons (chevrons,
2324
- arrows) manually. Use logical CSS properties (\`ms-*\`/\`me-*\`) instead of
2325
- \`ml-*\`/\`mr-*\`.
2324
+ Resolve direction with \`client.getStoreDirection(locale)\` \u2014 it returns
2325
+ \`'ltr' | 'rtl'\` for any BCP-47 tag (Arabic, Hebrew, Persian, Urdu, Yiddish
2326
+ today; future RTL locales added by the platform are picked up automatically).
2327
+ Do NOT maintain your own RTL locale set.
2328
+
2329
+ \`\`\`tsx
2330
+ // app/[locale]/layout.tsx
2331
+ const dir = client.getStoreDirection(locale);
2332
+ return <html lang={locale} dir={dir}>...</html>;
2333
+ \`\`\`
2334
+
2335
+ For static rendering, \`storeInfo.i18n.defaultDirection\` carries the store's
2336
+ default direction, and each entry in \`storeInfo.i18n.supportedLocaleObjects\`
2337
+ includes its own \`direction\`.
2338
+
2339
+ Let flexbox reverse automatically once \`<html dir="rtl">\` is set. Do NOT add
2340
+ \`flex-row-reverse\` on top \u2014 that's a double-swap. DO swap directional icons
2341
+ (chevrons, arrows) manually. Use logical CSS properties (\`ms-*\`/\`me-*\`)
2342
+ instead of \`ml-*\`/\`mr-*\`.
2326
2343
 
2327
2344
  ### Language switcher
2328
2345
 
@@ -2699,6 +2716,141 @@ and a \`newsletter\` form embedded in the footer), render each form from its
2699
2716
  own \`contactForms.get(key, locale)\` call. The \`formKey\` you pass to
2700
2717
  \`createInquiry\` must match.`;
2701
2718
  }
2719
+ function getContentSection() {
2720
+ return `## Content \u2014 typed merchant content store
2721
+
2722
+ Brainerce ships a typed content store so merchants can edit site chrome, FAQ,
2723
+ static pages, and inline rich-text blocks in the dashboard \u2014 without
2724
+ re-prompting the AI that built their storefront. Every row has a \`type\` +
2725
+ \`key\` + typed \`data\` payload + free-form \`customFields\`.
2726
+
2727
+ **Six content types.** Each one has a fixed \`data\` shape; the SDK's TypeScript
2728
+ generics keep them in lockstep:
2729
+
2730
+ | Type | Use for | \`data\` shape (abbreviated) |
2731
+ | -------------- | -------------------------------------- | --------------------------- |
2732
+ | \`FAQ\` | Q/A accordions | \`{ items: { question, answer }[] }\` |
2733
+ | \`FOOTER\` | Site footer (chrome) | \`{ columns, copyright?, social? }\` |
2734
+ | \`HEADER\` | Top nav + logo + CTA (chrome) | \`{ logo?, navItems, cta? }\` |
2735
+ | \`ANNOUNCEMENT\`| Banners; time-bound by \`startsAt/endsAt\` | \`{ message, severity, dismissible, ... }\` |
2736
+ | \`RICH_TEXT\` | Free-form HTML blocks embedded inline | \`{ html }\` |
2737
+ | \`PAGE\` | Static pages with slug + SEO | \`{ slug, title, html, seo? }\` |
2738
+
2739
+ Run \`get-type-definitions\` with \`domain: 'content'\` for the full interfaces.
2740
+
2741
+ ### Default key
2742
+
2743
+ Every type has \`'main'\` as its universal default key. \`client.content.faq.get()\`
2744
+ with no arguments resolves to \`key='main'\`. Topical keys (\`'shipping'\`,
2745
+ \`'holiday-2026'\`, \`'about'\`) are merchant-named.
2746
+
2747
+ ### Reading content (any SDK mode)
2748
+
2749
+ Public reads work in vibe-coded mode, storefront mode, and admin mode. They
2750
+ return \`null\` on 404 \u2014 render hard-coded fallbacks so the page never crashes
2751
+ when the merchant hasn't seeded yet.
2752
+
2753
+ \`\`\`ts
2754
+ // Single entry, default key 'main', resolved to a locale
2755
+ const faq = await client.content.faq.get('main', locale);
2756
+ if (faq) {
2757
+ faq.data.items.forEach(({ question, answer }) => {
2758
+ // Render question + sanitize(answer)
2759
+ });
2760
+ }
2761
+
2762
+ // All entries of a type
2763
+ const allFaqs = await client.content.faq.list(locale);
2764
+
2765
+ // Page by URL slug \u2014 for app/[slug]/page.tsx
2766
+ const page = await client.content.page.getBySlug(slug, locale);
2767
+ if (!page) notFound();
2768
+ \`\`\`
2769
+
2770
+ ### Security \u2014 sanitize HTML before rendering
2771
+
2772
+ \`FAQ.items[i].answer\`, \`RICH_TEXT.html\`, and \`PAGE.html\` carry
2773
+ MERCHANT-AUTHORED HTML. The server does NOT pre-sanitize \u2014 some merchants
2774
+ embed iframes (e.g. YouTube) which strict sanitizers would strip. ALWAYS
2775
+ sanitize on the storefront before injecting:
2776
+
2777
+ \`\`\`ts
2778
+ // Recommended: isomorphic-dompurify
2779
+ import DOMPurify from 'isomorphic-dompurify';
2780
+ const safe = DOMPurify.sanitize(rawHtml);
2781
+ <div dangerouslySetInnerHTML={{ __html: safe }} />;
2782
+ \`\`\`
2783
+
2784
+ Skipping this is XSS.
2785
+
2786
+ ### Custom fields
2787
+
2788
+ Every Content row carries a free-form \`customFields: Record<string, string>\`.
2789
+ Merchants add arbitrary key-value extras (\`helpEmail\`, \`phoneNumber\`,
2790
+ \`foundedYear\`) that you can opt into reading:
2791
+
2792
+ \`\`\`ts
2793
+ const faq = await client.content.faq.get('shipping');
2794
+ <a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
2795
+ \`\`\`
2796
+
2797
+ The shape is whatever the merchant entered. Read keys you expect; ignore the rest.
2798
+
2799
+ ### Locale resolution
2800
+
2801
+ All public reads accept a \`locale\` argument. The server resolves
2802
+ \`translations[locale]\` server-side and returns the resolved \`data\` payload \u2014
2803
+ the storefront does NOT need to do its own overlay. Empty / missing translations
2804
+ fall through to the default-locale value.
2805
+
2806
+ ### Cache
2807
+
2808
+ Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
2809
+ Merchant edits propagate within ~5 minutes. Don't layer extra client-side
2810
+ caching beyond Next.js's default fetch cache.
2811
+
2812
+ ### Admin writes (apiKey mode)
2813
+
2814
+ \`\`\`ts
2815
+ const adminClient = new BrainerceClient({ apiKey: process.env.BRAINERCE_API_KEY });
2816
+
2817
+ // Create \u2014 always starts in DRAFT
2818
+ const faq = await adminClient.content.faq.create({
2819
+ key: 'shipping',
2820
+ name: 'Shipping FAQ',
2821
+ data: { items: [{ question: 'How long?', answer: 'Most orders ship in 2 days.' }] },
2822
+ });
2823
+
2824
+ // Update (data replaces wholesale; last-write-wins on the data field)
2825
+ await adminClient.content.update(faq.id, {
2826
+ data: { items: [{ question: 'How long?', answer: 'Updated answer.' }] },
2827
+ });
2828
+
2829
+ // Publish / unpublish
2830
+ await adminClient.content.publish(faq.id);
2831
+ await adminClient.content.unpublish(faq.id);
2832
+
2833
+ // Hard delete
2834
+ await adminClient.content.remove(faq.id);
2835
+ \`\`\`
2836
+
2837
+ Write operations throw if called from vibe-coded or storefront mode.
2838
+
2839
+ ### Reserved key convention
2840
+
2841
+ \`'main'\` is reserved as the universal default. Don't use it for topical
2842
+ entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'\`,
2843
+ \`'holiday-2026'\`). The validation rule is \`^[a-z][a-z0-9-]*$\`, max 64 chars.
2844
+
2845
+ ### See also
2846
+
2847
+ - \`get-business-flows\` with \`flow: 'content-bootstrap'\` for the full
2848
+ layout / FAQ / page recipe.
2849
+ - \`get-required-features\` lists each Content surface (\`site-header\`,
2850
+ \`site-footer\`, \`announcement-bar\`, \`faq-page\`, \`static-pages\`).
2851
+ - \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
2852
+ interfaces.`;
2853
+ }
2702
2854
  function getSectionByTopic(topic, connectionId, currency) {
2703
2855
  const cid = connectionId || "vc_YOUR_CONNECTION_ID";
2704
2856
  const cur = currency || "USD";
@@ -2745,6 +2897,8 @@ function getSectionByTopic(topic, connectionId, currency) {
2745
2897
  return getAdminApiSection();
2746
2898
  case "inquiries":
2747
2899
  return getContactInquiriesSection();
2900
+ case "content":
2901
+ return getContentSection();
2748
2902
  case "all":
2749
2903
  return [
2750
2904
  "# Brainerce SDK \u2014 full topic dump",
@@ -2833,10 +2987,14 @@ function getSectionByTopic(topic, connectionId, currency) {
2833
2987
  "",
2834
2988
  "---",
2835
2989
  "",
2836
- getContactInquiriesSection()
2990
+ getContactInquiriesSection(),
2991
+ "",
2992
+ "---",
2993
+ "",
2994
+ getContentSection()
2837
2995
  ].join("\n");
2838
2996
  default:
2839
- return `Unknown topic: "${topic}". Available topics: setup, products, cart, checkout, checkout-custom-fields, payment, auth, order-confirmation, inventory, discounts, recommendations, product-customization-fields, tax, i18n, critical-rules, type-reference, admin, inquiries, all`;
2997
+ return `Unknown topic: "${topic}". Available topics: setup, products, cart, checkout, checkout-custom-fields, payment, auth, order-confirmation, inventory, discounts, recommendations, product-customization-fields, tax, i18n, critical-rules, type-reference, admin, inquiries, content, all`;
2840
2998
  }
2841
2999
  }
2842
3000
 
@@ -2864,6 +3022,7 @@ var GET_SDK_DOCS_SCHEMA = {
2864
3022
  "i18n",
2865
3023
  "admin",
2866
3024
  "inquiries",
3025
+ "content",
2867
3026
  "all"
2868
3027
  ]).describe("The SDK documentation topic to retrieve"),
2869
3028
  salesChannelId: import_zod.z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
@@ -3856,6 +4015,156 @@ export interface ModifierValidationError {
3856
4015
  // The cart line then carries:
3857
4016
  // cart.items[i].modifiers \u2014 CartItemModifierLine[]
3858
4017
  // cart.items[i].modifiersTotal \u2014 decimal string of the paid (non-free) deltas`;
4018
+ var CONTENT_TYPES = `// ---- Content (typed merchant content store) ----
4019
+ // Brainerce ships a typed content store so merchants can edit FAQ, footer,
4020
+ // header, announcements, rich text, and static pages in the dashboard
4021
+ // without re-prompting the AI that built the storefront. Every row has a
4022
+ // 'type' + 'key' + typed 'data' payload + free-form 'customFields'.
4023
+ //
4024
+ // SECURITY (read carefully):
4025
+ // RICH_TEXT.html, PAGE.html, and FAQ answers are MERCHANT-AUTHORED HTML.
4026
+ // ALWAYS sanitize with isomorphic-dompurify (or equivalent) before
4027
+ // injecting via dangerouslySetInnerHTML. The server does NOT pre-sanitize
4028
+ // because some merchants embed iframes (e.g. YouTube) which strict
4029
+ // sanitizers would strip; the storefront chooses the policy.
4030
+ //
4031
+ // 404 contract: client.content.<type>.get(key) returns null when no
4032
+ // PUBLISHED row exists. Always render a hard-coded fallback on null so
4033
+ // the page never crashes when the merchant hasn't seeded yet.
4034
+ //
4035
+ // Default key: every type has 'main' as its universal default. Pass no
4036
+ // argument to fetch the main entry; pass a custom key ('shipping',
4037
+ // 'holiday-2026', 'about') for topical entries.
4038
+
4039
+ export type ContentType = 'FAQ' | 'FOOTER' | 'HEADER' | 'ANNOUNCEMENT' | 'RICH_TEXT' | 'PAGE';
4040
+ export type ContentStatus = 'DRAFT' | 'PUBLISHED';
4041
+
4042
+ export interface FaqItem {
4043
+ question: string;
4044
+ /** Sanitized HTML \u2014 sanitize before rendering. */
4045
+ answer: string;
4046
+ }
4047
+ export interface FaqContent { items: FaqItem[] }
4048
+
4049
+ export interface FooterLink { label: string; url: string }
4050
+ export interface FooterColumn { title: string; links: FooterLink[] }
4051
+ export interface FooterSocialLink { platform: string; url: string } // 'instagram' | 'facebook' | 'x' | ...
4052
+ export interface FooterContent {
4053
+ columns: FooterColumn[];
4054
+ copyright?: string;
4055
+ social?: FooterSocialLink[];
4056
+ }
4057
+
4058
+ export interface HeaderLogo { src: string; alt: string }
4059
+ export interface HeaderNavItem { label: string; url: string }
4060
+ export interface HeaderCta { label: string; url: string }
4061
+ export interface HeaderContent {
4062
+ logo?: HeaderLogo;
4063
+ navItems: HeaderNavItem[];
4064
+ cta?: HeaderCta;
4065
+ }
4066
+
4067
+ export type AnnouncementSeverity = 'info' | 'warning' | 'success';
4068
+ export interface AnnouncementContent {
4069
+ message: string;
4070
+ severity: AnnouncementSeverity;
4071
+ dismissible: boolean;
4072
+ /** ISO 8601 \u2014 filter client-side. */
4073
+ startsAt?: string;
4074
+ endsAt?: string;
4075
+ ctaLabel?: string;
4076
+ ctaHref?: string;
4077
+ }
4078
+
4079
+ export interface RichTextContent {
4080
+ /** Raw HTML \u2014 sanitize before rendering. */
4081
+ html: string;
4082
+ }
4083
+
4084
+ export interface PageSeo {
4085
+ title?: string;
4086
+ description?: string;
4087
+ ogImage?: string;
4088
+ }
4089
+ export interface PageContent {
4090
+ /** URL slug, lower-kebab. */
4091
+ slug: string;
4092
+ title: string;
4093
+ /** Raw HTML \u2014 sanitize before rendering. */
4094
+ html: string;
4095
+ seo?: PageSeo;
4096
+ }
4097
+
4098
+ export interface ContentSummary {
4099
+ id: string;
4100
+ type: ContentType;
4101
+ key: string;
4102
+ name: string;
4103
+ status: ContentStatus;
4104
+ position: number;
4105
+ updatedAt: string;
4106
+ }
4107
+
4108
+ export interface Content<T extends ContentType = ContentType> extends ContentSummary {
4109
+ type: T;
4110
+ data: T extends 'FAQ' ? FaqContent
4111
+ : T extends 'FOOTER' ? FooterContent
4112
+ : T extends 'HEADER' ? HeaderContent
4113
+ : T extends 'ANNOUNCEMENT' ? AnnouncementContent
4114
+ : T extends 'RICH_TEXT' ? RichTextContent
4115
+ : T extends 'PAGE' ? PageContent
4116
+ : never;
4117
+ /** Free-form merchant-defined extras. Read keys the merchant told you to expect. */
4118
+ customFields: Record<string, string>;
4119
+ salesChannelIds: string[];
4120
+ }
4121
+
4122
+ // ---- SDK usage examples ----
4123
+ //
4124
+ // FAQ \u2014 render an accordion from the main FAQ (or a topical one):
4125
+ // const faq = await client.content.faq.get('main', locale); // 'shipping', 'returns', ...
4126
+ // if (faq) {
4127
+ // faq.data.items.forEach(({ question, answer }) => {
4128
+ // // Render question + sanitize(answer) \u2014 never inject raw HTML.
4129
+ // });
4130
+ // }
4131
+ //
4132
+ // Footer \u2014 server component in root layout:
4133
+ // const footer = await client.content.footer.get('main', locale);
4134
+ // if (!footer) return <Fallback />;
4135
+ // // Render footer.data.columns, footer.data.social, footer.data.copyright
4136
+ //
4137
+ // Header \u2014 same pattern as footer:
4138
+ // const header = await client.content.header.get('main', locale);
4139
+ //
4140
+ // Announcement \u2014 multiple may be active; filter by date client-side:
4141
+ // const announcements = await client.content.announcement.list(locale);
4142
+ // const now = Date.now();
4143
+ // const active = announcements.filter((a) => {
4144
+ // const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
4145
+ // const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
4146
+ // return startOk && endOk;
4147
+ // });
4148
+ //
4149
+ // Rich text \u2014 inline block anywhere on a page:
4150
+ // const block = await client.content.richText.get('about-intro', locale);
4151
+ // <div dangerouslySetInnerHTML={{ __html: sanitize(block.data.html) }} />
4152
+ //
4153
+ // Page \u2014 catch-all route by slug (e.g. /about, /terms, /privacy):
4154
+ // // app/[slug]/page.tsx
4155
+ // const page = await client.content.page.getBySlug(params.slug, locale);
4156
+ // if (!page) notFound();
4157
+ // // page.data.title, page.data.html, page.data.seo
4158
+ // return <article dangerouslySetInnerHTML={{ __html: sanitize(page.data.html) }} />;
4159
+ //
4160
+ // Custom fields \u2014 every Content row carries a free-form Record<string, string>:
4161
+ // const faq = await client.content.faq.get('shipping');
4162
+ // <a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
4163
+ //
4164
+ // Cache \u2014 public reads carry Cache-Control: public, max-age=300,
4165
+ // stale-while-revalidate=60. Storefront changes propagate within ~5 min
4166
+ // of the merchant publishing. Do not add extra client-side caching
4167
+ // beyond Next.js's default fetch cache.`;
3859
4168
  var TYPES_BY_DOMAIN = {
3860
4169
  products: PRODUCTS_TYPES,
3861
4170
  cart: CART_TYPES,
@@ -3866,7 +4175,8 @@ var TYPES_BY_DOMAIN = {
3866
4175
  helpers: HELPERS_TYPES,
3867
4176
  inquiries: INQUIRIES_TYPES,
3868
4177
  reviews: REVIEWS_TYPES,
3869
- "modifier-groups": MODIFIER_GROUPS_TYPES
4178
+ "modifier-groups": MODIFIER_GROUPS_TYPES,
4179
+ content: CONTENT_TYPES
3870
4180
  };
3871
4181
  function getTypesByDomain(domain) {
3872
4182
  if (domain === "all") {
@@ -3897,9 +4207,10 @@ var GET_TYPE_DEFINITIONS_SCHEMA = {
3897
4207
  "helpers",
3898
4208
  "inquiries",
3899
4209
  "reviews",
4210
+ "content",
3900
4211
  "all"
3901
4212
  ]).describe(
3902
- 'The domain of types to retrieve. Use "helpers" for helper function signatures and common types like StoreInfo, PaginatedResponse.'
4213
+ 'The domain of types to retrieve. Use "helpers" for helper function signatures and common types like StoreInfo, PaginatedResponse. Use "content" for FAQ / Footer / Header / Announcement / RichText / Page.'
3903
4214
  )
3904
4215
  };
3905
4216
  async function handleGetTypeDefinitions(args) {
@@ -4446,8 +4757,10 @@ client.setLocale(locale);
4446
4757
  // order bumps, search suggestions, discount banners, nudges,
4447
4758
  // badges, order history.
4448
4759
 
4449
- // For RTL locales (he, ar), set the document direction.
4450
- // Framework-neutral: document.documentElement.setAttribute('dir', 'rtl');`,
4760
+ // For RTL direction, do not hardcode the locale list. Ask the SDK:
4761
+ // const dir = client.getStoreDirection(currentLocale); // 'ltr' | 'rtl'
4762
+ // document.documentElement.setAttribute('dir', dir);
4763
+ // (Or in React: <html dir={dir}>...</html>.)`,
4451
4764
  "order-history-full": `// Full "My Orders" account page. Render every piece of data the server
4452
4765
  // already returns \u2014 not just order number / total / status.
4453
4766
  //
@@ -5539,7 +5852,7 @@ var RULES = {
5539
5852
  body: `- NEVER hardcode currency, locale, or language strings. Read them from \`get-store-info\` / \`get-store-capabilities\` and use the configured values.
5540
5853
  - NEVER format prices with \`toFixed(2)\` or custom logic. Use \`formatPrice()\` from the SDK \u2014 it honors the store's currency and locale.
5541
5854
  - When the store has i18n enabled (\`capabilities.store.i18n.enabled === true\`), you MUST call \`client.setLocale(locale)\` at app init and include a language switcher. All SDK reads will then return localized content automatically.
5542
- - For RTL locales (\`he\`, \`ar\`), set the document direction to RTL. Do not manually reverse flex layouts \u2014 the platform's CSS reversal handles it.`
5855
+ - For RTL direction, do NOT maintain a local list of RTL locales. Call \`client.getStoreDirection(locale)\` \u2014 it returns \`'ltr' | 'rtl'\` for any BCP-47 tag (covers Arabic, Hebrew, Persian, Urdu, Yiddish, and any future RTL locales the platform adds). Set \`<html dir={...}>\` from this value. The platform's CSS reversal handles flex layouts \u2014 do not manually swap them.`
5543
5856
  },
5544
5857
  types: {
5545
5858
  title: "Type safety",
@@ -5587,6 +5900,7 @@ var GET_BUSINESS_FLOWS_SCHEMA = {
5587
5900
  "cart-persistence",
5588
5901
  "inventory-reservation",
5589
5902
  "product-customization",
5903
+ "content-bootstrap",
5590
5904
  "all"
5591
5905
  ]).describe('Which flow to retrieve. Use "all" to get every flow.')
5592
5906
  };
@@ -5777,6 +6091,76 @@ Server-side guardrails that WILL reject bad requests (so validate client-side to
5777
6091
  - More than 10 uploads per IP per minute \u2192 429.
5778
6092
 
5779
6093
  Never render customization fields without also wiring the upload + metadata flow \u2014 a form that submits nothing is worse than no form at all.`
6094
+ },
6095
+ "content-bootstrap": {
6096
+ title: "Content Bootstrap \u2014 site chrome & static content",
6097
+ body: `Every Brainerce storefront should render merchant-defined site chrome (header, footer, announcements, FAQ, static pages) from the Content API. The merchant edits these in the Brainerce dashboard; storefronts pick up changes within ~5 minutes (public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`).
6098
+
6099
+ 1. **Fetch chrome at the root layout** (server component if Next.js). All three return \`null\` on 404 \u2014 render hard-coded fallbacks so the page never crashes when the merchant hasn't seeded yet.
6100
+ \`\`\`ts
6101
+ const [header, footer, announcements] = await Promise.all([
6102
+ client.content.header.get('main', locale),
6103
+ client.content.footer.get('main', locale),
6104
+ client.content.announcement.list(locale),
6105
+ ]);
6106
+ \`\`\`
6107
+
6108
+ 2. **FAQ \u2014 fetch lazily on the FAQ page.** Default key is \`'main'\`; pass a topical key (\`'shipping'\`, \`'returns'\`) for sub-FAQs.
6109
+ \`\`\`ts
6110
+ const faq = await client.content.faq.get('main', locale);
6111
+ if (faq) {
6112
+ faq.data.items.forEach(({ question, answer }) => {
6113
+ // sanitize(answer) \u2014 see step 4
6114
+ });
6115
+ }
6116
+ \`\`\`
6117
+
6118
+ 3. **Static pages \u2014 catch-all route by slug:**
6119
+ \`\`\`tsx
6120
+ // app/[slug]/page.tsx
6121
+ export default async function Page({ params }) {
6122
+ const page = await client.content.page.getBySlug(params.slug, locale);
6123
+ if (!page) notFound();
6124
+ return (
6125
+ <article dangerouslySetInnerHTML={{ __html: sanitize(page.data.html) }} />
6126
+ );
6127
+ }
6128
+ \`\`\`
6129
+
6130
+ 4. **SECURITY \u2014 sanitize HTML before rendering.** \`FAQ.items[i].answer\`, \`PAGE.html\`, and \`RICH_TEXT.html\` are merchant-authored HTML. The server does NOT pre-sanitize because some merchants embed iframes (e.g. YouTube). Always sanitize at the edge of your render:
6131
+ \`\`\`ts
6132
+ import DOMPurify from 'isomorphic-dompurify';
6133
+ const safe = DOMPurify.sanitize(rawHtml);
6134
+ <div dangerouslySetInnerHTML={{ __html: safe }} />;
6135
+ \`\`\`
6136
+ Skipping this is XSS.
6137
+
6138
+ 5. **Announcements \u2014 multiple may be active; filter by date client-side:**
6139
+ \`\`\`ts
6140
+ const now = Date.now();
6141
+ const visible = announcements.filter((a) => {
6142
+ const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
6143
+ const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
6144
+ return startOk && endOk;
6145
+ });
6146
+ \`\`\`
6147
+
6148
+ 6. **RTL direction \u2014 call \`client.getStoreDirection(locale)\`:**
6149
+ \`\`\`tsx
6150
+ const dir = client.getStoreDirection(locale);
6151
+ <html lang={locale} dir={dir}>...</html>
6152
+ \`\`\`
6153
+ Do NOT maintain a local RTL locale set \u2014 the SDK helper covers Arabic / Hebrew / Persian / Urdu / Yiddish today and picks up any future RTL locale automatically.
6154
+
6155
+ 7. **Custom fields \u2014 every Content row has free-form \`customFields: Record<string, string>\`.** Read keys the merchant told you to expect:
6156
+ \`\`\`ts
6157
+ const faq = await client.content.faq.get('shipping');
6158
+ <a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
6159
+ \`\`\`
6160
+
6161
+ 8. **Cache:** public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`. Don't add extra client-side caching beyond Next.js's default fetch cache \u2014 merchants expect their edits to appear within ~5 minutes.
6162
+
6163
+ **Translations.** All public reads accept a \`locale\` argument; the server resolves \`translations[locale]\` server-side. Empty / missing overlays fall through to the default-locale value. The storefront does NOT need to do its own per-field overlay \u2014 call with the active locale and render what comes back.`
5780
6164
  }
5781
6165
  };
5782
6166
  var FLOW_ORDER = [
@@ -5788,7 +6172,8 @@ var FLOW_ORDER = [
5788
6172
  "order-confirmation",
5789
6173
  "cart-persistence",
5790
6174
  "inventory-reservation",
5791
- "product-customization"
6175
+ "product-customization",
6176
+ "content-bootstrap"
5792
6177
  ];
5793
6178
  async function handleGetBusinessFlows(args) {
5794
6179
  const header = "# Brainerce Business Flows\n\nThese sequences are framework-neutral and non-negotiable. Your framework and file layout are your choice \u2014 the order of SDK calls and the error handling is not.";
@@ -6000,11 +6385,57 @@ var FEATURES = [
6000
6385
  {
6001
6386
  id: "i18n",
6002
6387
  title: "Serve multiple languages with a language switcher",
6003
- description: "When i18n is enabled, the experience routes by locale, sets the SDK locale (client.setLocale), includes a language switcher in the header, and renders RTL locales (he, ar) with the correct document direction.",
6004
- sdk: "client.setLocale(locale). Read supported locales from get-store-capabilities.store.i18n.",
6388
+ description: "When i18n is enabled, the experience routes by locale, sets the SDK locale (client.setLocale), includes a language switcher in the header, and renders the correct document direction by reading client.getStoreDirection(locale) \u2014 do not hardcode an RTL locale set.",
6389
+ sdk: "client.setLocale(locale). client.getStoreDirection(locale) for <html dir>. Read supported locales from get-store-capabilities.store.i18n.",
6005
6390
  mandatory: "conditional",
6006
6391
  capabilityFlag: "i18n",
6007
6392
  whenDisabledNote: "This store is single-language. Do not build the language switcher."
6393
+ },
6394
+ {
6395
+ id: "site-header",
6396
+ title: "Site header from merchant content (logo + nav + CTA)",
6397
+ description: 'Fetch client.content.header.get("main", locale) in the root layout. Returns null when the merchant has not seeded yet \u2014 render a hard-coded fallback so the page never crashes. Renders header.data.logo, header.data.navItems[], header.data.cta if present.',
6398
+ sdk: 'client.content.header.get("main", locale)',
6399
+ flowRef: "content-bootstrap",
6400
+ mandatory: "mandatory"
6401
+ },
6402
+ {
6403
+ id: "site-footer",
6404
+ title: "Site footer from merchant content (columns + social + copyright)",
6405
+ description: 'Fetch client.content.footer.get("main", locale) in the root layout. Returns null when unseeded \u2014 render a hard-coded fallback. Render footer.data.columns[].links, footer.data.social[], footer.data.copyright.',
6406
+ sdk: 'client.content.footer.get("main", locale)',
6407
+ flowRef: "content-bootstrap",
6408
+ mandatory: "mandatory"
6409
+ },
6410
+ {
6411
+ id: "announcement-bar",
6412
+ title: "Announcement bar at the top of every page",
6413
+ description: "Fetch client.content.announcement.list(locale) in the root layout. Filter by data.startsAt / data.endsAt client-side. Render a dismissible bar when data.dismissible=true. Build the UI anyway \u2014 it auto-hides when no announcements exist.",
6414
+ sdk: "client.content.announcement.list(locale)",
6415
+ flowRef: "content-bootstrap",
6416
+ mandatory: "conditional",
6417
+ capabilityFlag: "hasContent",
6418
+ whenDisabledNote: "Store has no published Content rows yet. Build the announcement bar anyway \u2014 it auto-hides on empty."
6419
+ },
6420
+ {
6421
+ id: "faq-page",
6422
+ title: "FAQ page rendered from merchant content",
6423
+ description: 'Build /faq as an accordion fed by client.content.faq.get("main", locale). For topical FAQs, use a key parameter (shipping, returns, ...). Always sanitize answer HTML before injecting via dangerouslySetInnerHTML. Build the page anyway \u2014 it auto-hides or 404s when no FAQ rows exist.',
6424
+ sdk: 'client.content.faq.get("main", locale), client.content.faq.list(locale)',
6425
+ flowRef: "content-bootstrap",
6426
+ mandatory: "conditional",
6427
+ capabilityFlag: "hasContent",
6428
+ whenDisabledNote: "No FAQ content yet. Build /faq anyway \u2014 it auto-hides on empty."
6429
+ },
6430
+ {
6431
+ id: "static-pages",
6432
+ title: "Static pages from merchant content (About, Terms, Privacy, \u2026)",
6433
+ description: "Mount a catch-all app/[slug]/page.tsx route. Inside, call client.content.page.getBySlug(params.slug, locale). On null \u2192 notFound(). On hit, sanitize page.data.html before injecting via dangerouslySetInnerHTML. Generate <Metadata> from page.data.seo. Build the route anyway \u2014 it 404s on unknown slugs.",
6434
+ sdk: "client.content.page.getBySlug(slug, locale), client.content.page.list(locale)",
6435
+ flowRef: "content-bootstrap",
6436
+ mandatory: "conditional",
6437
+ capabilityFlag: "hasContent",
6438
+ whenDisabledNote: "No static pages yet. Build the catch-all route anyway \u2014 it 404s on unknown slugs."
6008
6439
  }
6009
6440
  ];
6010
6441
  function isFeatureActive(feature, caps) {
@@ -6055,6 +6486,7 @@ function renderCapabilitiesSummary(caps) {
6055
6486
  );
6056
6487
  lines.push(`- Downloadable products: ${caps.features.hasDownloadableProducts ? "yes" : "no"}`);
6057
6488
  lines.push(`- Checkout custom fields: ${caps.features.hasCheckoutCustomFields ? "yes" : "no"}`);
6489
+ lines.push(`- Content (FAQ/footer/header/announcements/pages): ${caps.features.hasContent ? "seeded" : "none \u2014 build chrome UI with fallbacks"}`);
6058
6490
  lines.push(
6059
6491
  `- Email verification: ${caps.connection.requireEmailVerification ? "required" : "not required (still build the verify-email flow)"}`
6060
6492
  );
package/dist/index.d.mts CHANGED
@@ -76,6 +76,8 @@ interface StoreCapabilities {
76
76
  hasDownloadableProducts: boolean;
77
77
  hasCoupons: boolean;
78
78
  hasCheckoutCustomFields: boolean;
79
+ /** True when at least one PUBLISHED Content row exists for the store. */
80
+ hasContent?: boolean;
79
81
  };
80
82
  }
81
83
  declare function fetchStoreCapabilities(connectionId: string, baseUrl?: string): Promise<StoreCapabilities>;
package/dist/index.d.ts CHANGED
@@ -76,6 +76,8 @@ interface StoreCapabilities {
76
76
  hasDownloadableProducts: boolean;
77
77
  hasCoupons: boolean;
78
78
  hasCheckoutCustomFields: boolean;
79
+ /** True when at least one PUBLISHED Content row exists for the store. */
80
+ hasContent?: boolean;
79
81
  };
80
82
  }
81
83
  declare function fetchStoreCapabilities(connectionId: string, baseUrl?: string): Promise<StoreCapabilities>;