@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/http.js +448 -16
- package/dist/bin/stdio.js +448 -16
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +448 -16
- package/dist/index.mjs +448 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2226,9 +2226,12 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
|
2226
2226
|
const client = getServerClient();
|
|
2227
2227
|
client.setLocale(locale);
|
|
2228
2228
|
const product = await client.getProductBySlug(slug);
|
|
2229
|
+
// NEVER feed raw HTML into <meta name="description"> \u2014 product.description
|
|
2230
|
+
// is often rich-text HTML. Strip tags first, then truncate on a word
|
|
2231
|
+
// boundary. See buildMetaDescription() in lib/seo.ts.
|
|
2229
2232
|
return {
|
|
2230
2233
|
title: product.seoTitle || product.name,
|
|
2231
|
-
description: product.seoDescription || product.description
|
|
2234
|
+
description: product.seoDescription || buildMetaDescription(product.description) || product.name,
|
|
2232
2235
|
};
|
|
2233
2236
|
}
|
|
2234
2237
|
\`\`\`
|
|
@@ -2344,11 +2347,25 @@ Because the backend already overlays everything, UI code is just:
|
|
|
2344
2347
|
|
|
2345
2348
|
### RTL handling
|
|
2346
2349
|
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2350
|
+
Resolve direction with \`client.getStoreDirection(locale)\` \u2014 it returns
|
|
2351
|
+
\`'ltr' | 'rtl'\` for any BCP-47 tag (Arabic, Hebrew, Persian, Urdu, Yiddish
|
|
2352
|
+
today; future RTL locales added by the platform are picked up automatically).
|
|
2353
|
+
Do NOT maintain your own RTL locale set.
|
|
2354
|
+
|
|
2355
|
+
\`\`\`tsx
|
|
2356
|
+
// app/[locale]/layout.tsx
|
|
2357
|
+
const dir = client.getStoreDirection(locale);
|
|
2358
|
+
return <html lang={locale} dir={dir}>...</html>;
|
|
2359
|
+
\`\`\`
|
|
2360
|
+
|
|
2361
|
+
For static rendering, \`storeInfo.i18n.defaultDirection\` carries the store's
|
|
2362
|
+
default direction, and each entry in \`storeInfo.i18n.supportedLocaleObjects\`
|
|
2363
|
+
includes its own \`direction\`.
|
|
2364
|
+
|
|
2365
|
+
Let flexbox reverse automatically once \`<html dir="rtl">\` is set. Do NOT add
|
|
2366
|
+
\`flex-row-reverse\` on top \u2014 that's a double-swap. DO swap directional icons
|
|
2367
|
+
(chevrons, arrows) manually. Use logical CSS properties (\`ms-*\`/\`me-*\`)
|
|
2368
|
+
instead of \`ml-*\`/\`mr-*\`.
|
|
2352
2369
|
|
|
2353
2370
|
### Language switcher
|
|
2354
2371
|
|
|
@@ -2725,6 +2742,141 @@ and a \`newsletter\` form embedded in the footer), render each form from its
|
|
|
2725
2742
|
own \`contactForms.get(key, locale)\` call. The \`formKey\` you pass to
|
|
2726
2743
|
\`createInquiry\` must match.`;
|
|
2727
2744
|
}
|
|
2745
|
+
function getContentSection() {
|
|
2746
|
+
return `## Content \u2014 typed merchant content store
|
|
2747
|
+
|
|
2748
|
+
Brainerce ships a typed content store so merchants can edit site chrome, FAQ,
|
|
2749
|
+
static pages, and inline rich-text blocks in the dashboard \u2014 without
|
|
2750
|
+
re-prompting the AI that built their storefront. Every row has a \`type\` +
|
|
2751
|
+
\`key\` + typed \`data\` payload + free-form \`customFields\`.
|
|
2752
|
+
|
|
2753
|
+
**Six content types.** Each one has a fixed \`data\` shape; the SDK's TypeScript
|
|
2754
|
+
generics keep them in lockstep:
|
|
2755
|
+
|
|
2756
|
+
| Type | Use for | \`data\` shape (abbreviated) |
|
|
2757
|
+
| -------------- | -------------------------------------- | --------------------------- |
|
|
2758
|
+
| \`FAQ\` | Q/A accordions | \`{ items: { question, answer }[] }\` |
|
|
2759
|
+
| \`FOOTER\` | Site footer (chrome) | \`{ columns, copyright?, social? }\` |
|
|
2760
|
+
| \`HEADER\` | Top nav + logo + CTA (chrome) | \`{ logo?, navItems, cta? }\` |
|
|
2761
|
+
| \`ANNOUNCEMENT\`| Banners; time-bound by \`startsAt/endsAt\` | \`{ message, severity, dismissible, ... }\` |
|
|
2762
|
+
| \`RICH_TEXT\` | Free-form HTML blocks embedded inline | \`{ html }\` |
|
|
2763
|
+
| \`PAGE\` | Static pages with slug + SEO | \`{ slug, title, html, seo? }\` |
|
|
2764
|
+
|
|
2765
|
+
Run \`get-type-definitions\` with \`domain: 'content'\` for the full interfaces.
|
|
2766
|
+
|
|
2767
|
+
### Default key
|
|
2768
|
+
|
|
2769
|
+
Every type has \`'main'\` as its universal default key. \`client.content.faq.get()\`
|
|
2770
|
+
with no arguments resolves to \`key='main'\`. Topical keys (\`'shipping'\`,
|
|
2771
|
+
\`'holiday-2026'\`, \`'about'\`) are merchant-named.
|
|
2772
|
+
|
|
2773
|
+
### Reading content (any SDK mode)
|
|
2774
|
+
|
|
2775
|
+
Public reads work in vibe-coded mode, storefront mode, and admin mode. They
|
|
2776
|
+
return \`null\` on 404 \u2014 render hard-coded fallbacks so the page never crashes
|
|
2777
|
+
when the merchant hasn't seeded yet.
|
|
2778
|
+
|
|
2779
|
+
\`\`\`ts
|
|
2780
|
+
// Single entry, default key 'main', resolved to a locale
|
|
2781
|
+
const faq = await client.content.faq.get('main', locale);
|
|
2782
|
+
if (faq) {
|
|
2783
|
+
faq.data.items.forEach(({ question, answer }) => {
|
|
2784
|
+
// Render question + sanitize(answer)
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
// All entries of a type
|
|
2789
|
+
const allFaqs = await client.content.faq.list(locale);
|
|
2790
|
+
|
|
2791
|
+
// Page by URL slug \u2014 for app/[slug]/page.tsx
|
|
2792
|
+
const page = await client.content.page.getBySlug(slug, locale);
|
|
2793
|
+
if (!page) notFound();
|
|
2794
|
+
\`\`\`
|
|
2795
|
+
|
|
2796
|
+
### Security \u2014 sanitize HTML before rendering
|
|
2797
|
+
|
|
2798
|
+
\`FAQ.items[i].answer\`, \`RICH_TEXT.html\`, and \`PAGE.html\` carry
|
|
2799
|
+
MERCHANT-AUTHORED HTML. The server does NOT pre-sanitize \u2014 some merchants
|
|
2800
|
+
embed iframes (e.g. YouTube) which strict sanitizers would strip. ALWAYS
|
|
2801
|
+
sanitize on the storefront before injecting:
|
|
2802
|
+
|
|
2803
|
+
\`\`\`ts
|
|
2804
|
+
// Recommended: isomorphic-dompurify
|
|
2805
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
2806
|
+
const safe = DOMPurify.sanitize(rawHtml);
|
|
2807
|
+
<div dangerouslySetInnerHTML={{ __html: safe }} />;
|
|
2808
|
+
\`\`\`
|
|
2809
|
+
|
|
2810
|
+
Skipping this is XSS.
|
|
2811
|
+
|
|
2812
|
+
### Custom fields
|
|
2813
|
+
|
|
2814
|
+
Every Content row carries a free-form \`customFields: Record<string, string>\`.
|
|
2815
|
+
Merchants add arbitrary key-value extras (\`helpEmail\`, \`phoneNumber\`,
|
|
2816
|
+
\`foundedYear\`) that you can opt into reading:
|
|
2817
|
+
|
|
2818
|
+
\`\`\`ts
|
|
2819
|
+
const faq = await client.content.faq.get('shipping');
|
|
2820
|
+
<a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
|
|
2821
|
+
\`\`\`
|
|
2822
|
+
|
|
2823
|
+
The shape is whatever the merchant entered. Read keys you expect; ignore the rest.
|
|
2824
|
+
|
|
2825
|
+
### Locale resolution
|
|
2826
|
+
|
|
2827
|
+
All public reads accept a \`locale\` argument. The server resolves
|
|
2828
|
+
\`translations[locale]\` server-side and returns the resolved \`data\` payload \u2014
|
|
2829
|
+
the storefront does NOT need to do its own overlay. Empty / missing translations
|
|
2830
|
+
fall through to the default-locale value.
|
|
2831
|
+
|
|
2832
|
+
### Cache
|
|
2833
|
+
|
|
2834
|
+
Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
|
|
2835
|
+
Merchant edits propagate within ~5 minutes. Don't layer extra client-side
|
|
2836
|
+
caching beyond Next.js's default fetch cache.
|
|
2837
|
+
|
|
2838
|
+
### Admin writes (apiKey mode)
|
|
2839
|
+
|
|
2840
|
+
\`\`\`ts
|
|
2841
|
+
const adminClient = new BrainerceClient({ apiKey: process.env.BRAINERCE_API_KEY });
|
|
2842
|
+
|
|
2843
|
+
// Create \u2014 always starts in DRAFT
|
|
2844
|
+
const faq = await adminClient.content.faq.create({
|
|
2845
|
+
key: 'shipping',
|
|
2846
|
+
name: 'Shipping FAQ',
|
|
2847
|
+
data: { items: [{ question: 'How long?', answer: 'Most orders ship in 2 days.' }] },
|
|
2848
|
+
});
|
|
2849
|
+
|
|
2850
|
+
// Update (data replaces wholesale; last-write-wins on the data field)
|
|
2851
|
+
await adminClient.content.update(faq.id, {
|
|
2852
|
+
data: { items: [{ question: 'How long?', answer: 'Updated answer.' }] },
|
|
2853
|
+
});
|
|
2854
|
+
|
|
2855
|
+
// Publish / unpublish
|
|
2856
|
+
await adminClient.content.publish(faq.id);
|
|
2857
|
+
await adminClient.content.unpublish(faq.id);
|
|
2858
|
+
|
|
2859
|
+
// Hard delete
|
|
2860
|
+
await adminClient.content.remove(faq.id);
|
|
2861
|
+
\`\`\`
|
|
2862
|
+
|
|
2863
|
+
Write operations throw if called from vibe-coded or storefront mode.
|
|
2864
|
+
|
|
2865
|
+
### Reserved key convention
|
|
2866
|
+
|
|
2867
|
+
\`'main'\` is reserved as the universal default. Don't use it for topical
|
|
2868
|
+
entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'\`,
|
|
2869
|
+
\`'holiday-2026'\`). The validation rule is \`^[a-z][a-z0-9-]*$\`, max 64 chars.
|
|
2870
|
+
|
|
2871
|
+
### See also
|
|
2872
|
+
|
|
2873
|
+
- \`get-business-flows\` with \`flow: 'content-bootstrap'\` for the full
|
|
2874
|
+
layout / FAQ / page recipe.
|
|
2875
|
+
- \`get-required-features\` lists each Content surface (\`site-header\`,
|
|
2876
|
+
\`site-footer\`, \`announcement-bar\`, \`faq-page\`, \`static-pages\`).
|
|
2877
|
+
- \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
|
|
2878
|
+
interfaces.`;
|
|
2879
|
+
}
|
|
2728
2880
|
function getSectionByTopic(topic, connectionId, currency) {
|
|
2729
2881
|
const cid = connectionId || "vc_YOUR_CONNECTION_ID";
|
|
2730
2882
|
const cur = currency || "USD";
|
|
@@ -2771,6 +2923,8 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2771
2923
|
return getAdminApiSection();
|
|
2772
2924
|
case "inquiries":
|
|
2773
2925
|
return getContactInquiriesSection();
|
|
2926
|
+
case "content":
|
|
2927
|
+
return getContentSection();
|
|
2774
2928
|
case "all":
|
|
2775
2929
|
return [
|
|
2776
2930
|
"# Brainerce SDK \u2014 full topic dump",
|
|
@@ -2859,10 +3013,14 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2859
3013
|
"",
|
|
2860
3014
|
"---",
|
|
2861
3015
|
"",
|
|
2862
|
-
getContactInquiriesSection()
|
|
3016
|
+
getContactInquiriesSection(),
|
|
3017
|
+
"",
|
|
3018
|
+
"---",
|
|
3019
|
+
"",
|
|
3020
|
+
getContentSection()
|
|
2863
3021
|
].join("\n");
|
|
2864
3022
|
default:
|
|
2865
|
-
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`;
|
|
3023
|
+
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`;
|
|
2866
3024
|
}
|
|
2867
3025
|
}
|
|
2868
3026
|
|
|
@@ -2890,6 +3048,7 @@ var GET_SDK_DOCS_SCHEMA = {
|
|
|
2890
3048
|
"i18n",
|
|
2891
3049
|
"admin",
|
|
2892
3050
|
"inquiries",
|
|
3051
|
+
"content",
|
|
2893
3052
|
"all"
|
|
2894
3053
|
]).describe("The SDK documentation topic to retrieve"),
|
|
2895
3054
|
salesChannelId: import_zod.z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
|
|
@@ -3882,6 +4041,156 @@ export interface ModifierValidationError {
|
|
|
3882
4041
|
// The cart line then carries:
|
|
3883
4042
|
// cart.items[i].modifiers \u2014 CartItemModifierLine[]
|
|
3884
4043
|
// cart.items[i].modifiersTotal \u2014 decimal string of the paid (non-free) deltas`;
|
|
4044
|
+
var CONTENT_TYPES = `// ---- Content (typed merchant content store) ----
|
|
4045
|
+
// Brainerce ships a typed content store so merchants can edit FAQ, footer,
|
|
4046
|
+
// header, announcements, rich text, and static pages in the dashboard
|
|
4047
|
+
// without re-prompting the AI that built the storefront. Every row has a
|
|
4048
|
+
// 'type' + 'key' + typed 'data' payload + free-form 'customFields'.
|
|
4049
|
+
//
|
|
4050
|
+
// SECURITY (read carefully):
|
|
4051
|
+
// RICH_TEXT.html, PAGE.html, and FAQ answers are MERCHANT-AUTHORED HTML.
|
|
4052
|
+
// ALWAYS sanitize with isomorphic-dompurify (or equivalent) before
|
|
4053
|
+
// injecting via dangerouslySetInnerHTML. The server does NOT pre-sanitize
|
|
4054
|
+
// because some merchants embed iframes (e.g. YouTube) which strict
|
|
4055
|
+
// sanitizers would strip; the storefront chooses the policy.
|
|
4056
|
+
//
|
|
4057
|
+
// 404 contract: client.content.<type>.get(key) returns null when no
|
|
4058
|
+
// PUBLISHED row exists. Always render a hard-coded fallback on null so
|
|
4059
|
+
// the page never crashes when the merchant hasn't seeded yet.
|
|
4060
|
+
//
|
|
4061
|
+
// Default key: every type has 'main' as its universal default. Pass no
|
|
4062
|
+
// argument to fetch the main entry; pass a custom key ('shipping',
|
|
4063
|
+
// 'holiday-2026', 'about') for topical entries.
|
|
4064
|
+
|
|
4065
|
+
export type ContentType = 'FAQ' | 'FOOTER' | 'HEADER' | 'ANNOUNCEMENT' | 'RICH_TEXT' | 'PAGE';
|
|
4066
|
+
export type ContentStatus = 'DRAFT' | 'PUBLISHED';
|
|
4067
|
+
|
|
4068
|
+
export interface FaqItem {
|
|
4069
|
+
question: string;
|
|
4070
|
+
/** Sanitized HTML \u2014 sanitize before rendering. */
|
|
4071
|
+
answer: string;
|
|
4072
|
+
}
|
|
4073
|
+
export interface FaqContent { items: FaqItem[] }
|
|
4074
|
+
|
|
4075
|
+
export interface FooterLink { label: string; url: string }
|
|
4076
|
+
export interface FooterColumn { title: string; links: FooterLink[] }
|
|
4077
|
+
export interface FooterSocialLink { platform: string; url: string } // 'instagram' | 'facebook' | 'x' | ...
|
|
4078
|
+
export interface FooterContent {
|
|
4079
|
+
columns: FooterColumn[];
|
|
4080
|
+
copyright?: string;
|
|
4081
|
+
social?: FooterSocialLink[];
|
|
4082
|
+
}
|
|
4083
|
+
|
|
4084
|
+
export interface HeaderLogo { src: string; alt: string }
|
|
4085
|
+
export interface HeaderNavItem { label: string; url: string }
|
|
4086
|
+
export interface HeaderCta { label: string; url: string }
|
|
4087
|
+
export interface HeaderContent {
|
|
4088
|
+
logo?: HeaderLogo;
|
|
4089
|
+
navItems: HeaderNavItem[];
|
|
4090
|
+
cta?: HeaderCta;
|
|
4091
|
+
}
|
|
4092
|
+
|
|
4093
|
+
export type AnnouncementSeverity = 'info' | 'warning' | 'success';
|
|
4094
|
+
export interface AnnouncementContent {
|
|
4095
|
+
message: string;
|
|
4096
|
+
severity: AnnouncementSeverity;
|
|
4097
|
+
dismissible: boolean;
|
|
4098
|
+
/** ISO 8601 \u2014 filter client-side. */
|
|
4099
|
+
startsAt?: string;
|
|
4100
|
+
endsAt?: string;
|
|
4101
|
+
ctaLabel?: string;
|
|
4102
|
+
ctaHref?: string;
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
export interface RichTextContent {
|
|
4106
|
+
/** Raw HTML \u2014 sanitize before rendering. */
|
|
4107
|
+
html: string;
|
|
4108
|
+
}
|
|
4109
|
+
|
|
4110
|
+
export interface PageSeo {
|
|
4111
|
+
title?: string;
|
|
4112
|
+
description?: string;
|
|
4113
|
+
ogImage?: string;
|
|
4114
|
+
}
|
|
4115
|
+
export interface PageContent {
|
|
4116
|
+
/** URL slug, lower-kebab. */
|
|
4117
|
+
slug: string;
|
|
4118
|
+
title: string;
|
|
4119
|
+
/** Raw HTML \u2014 sanitize before rendering. */
|
|
4120
|
+
html: string;
|
|
4121
|
+
seo?: PageSeo;
|
|
4122
|
+
}
|
|
4123
|
+
|
|
4124
|
+
export interface ContentSummary {
|
|
4125
|
+
id: string;
|
|
4126
|
+
type: ContentType;
|
|
4127
|
+
key: string;
|
|
4128
|
+
name: string;
|
|
4129
|
+
status: ContentStatus;
|
|
4130
|
+
position: number;
|
|
4131
|
+
updatedAt: string;
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4134
|
+
export interface Content<T extends ContentType = ContentType> extends ContentSummary {
|
|
4135
|
+
type: T;
|
|
4136
|
+
data: T extends 'FAQ' ? FaqContent
|
|
4137
|
+
: T extends 'FOOTER' ? FooterContent
|
|
4138
|
+
: T extends 'HEADER' ? HeaderContent
|
|
4139
|
+
: T extends 'ANNOUNCEMENT' ? AnnouncementContent
|
|
4140
|
+
: T extends 'RICH_TEXT' ? RichTextContent
|
|
4141
|
+
: T extends 'PAGE' ? PageContent
|
|
4142
|
+
: never;
|
|
4143
|
+
/** Free-form merchant-defined extras. Read keys the merchant told you to expect. */
|
|
4144
|
+
customFields: Record<string, string>;
|
|
4145
|
+
salesChannelIds: string[];
|
|
4146
|
+
}
|
|
4147
|
+
|
|
4148
|
+
// ---- SDK usage examples ----
|
|
4149
|
+
//
|
|
4150
|
+
// FAQ \u2014 render an accordion from the main FAQ (or a topical one):
|
|
4151
|
+
// const faq = await client.content.faq.get('main', locale); // 'shipping', 'returns', ...
|
|
4152
|
+
// if (faq) {
|
|
4153
|
+
// faq.data.items.forEach(({ question, answer }) => {
|
|
4154
|
+
// // Render question + sanitize(answer) \u2014 never inject raw HTML.
|
|
4155
|
+
// });
|
|
4156
|
+
// }
|
|
4157
|
+
//
|
|
4158
|
+
// Footer \u2014 server component in root layout:
|
|
4159
|
+
// const footer = await client.content.footer.get('main', locale);
|
|
4160
|
+
// if (!footer) return <Fallback />;
|
|
4161
|
+
// // Render footer.data.columns, footer.data.social, footer.data.copyright
|
|
4162
|
+
//
|
|
4163
|
+
// Header \u2014 same pattern as footer:
|
|
4164
|
+
// const header = await client.content.header.get('main', locale);
|
|
4165
|
+
//
|
|
4166
|
+
// Announcement \u2014 multiple may be active; filter by date client-side:
|
|
4167
|
+
// const announcements = await client.content.announcement.list(locale);
|
|
4168
|
+
// const now = Date.now();
|
|
4169
|
+
// const active = announcements.filter((a) => {
|
|
4170
|
+
// const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
|
|
4171
|
+
// const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
|
|
4172
|
+
// return startOk && endOk;
|
|
4173
|
+
// });
|
|
4174
|
+
//
|
|
4175
|
+
// Rich text \u2014 inline block anywhere on a page:
|
|
4176
|
+
// const block = await client.content.richText.get('about-intro', locale);
|
|
4177
|
+
// <div dangerouslySetInnerHTML={{ __html: sanitize(block.data.html) }} />
|
|
4178
|
+
//
|
|
4179
|
+
// Page \u2014 catch-all route by slug (e.g. /about, /terms, /privacy):
|
|
4180
|
+
// // app/[slug]/page.tsx
|
|
4181
|
+
// const page = await client.content.page.getBySlug(params.slug, locale);
|
|
4182
|
+
// if (!page) notFound();
|
|
4183
|
+
// // page.data.title, page.data.html, page.data.seo
|
|
4184
|
+
// return <article dangerouslySetInnerHTML={{ __html: sanitize(page.data.html) }} />;
|
|
4185
|
+
//
|
|
4186
|
+
// Custom fields \u2014 every Content row carries a free-form Record<string, string>:
|
|
4187
|
+
// const faq = await client.content.faq.get('shipping');
|
|
4188
|
+
// <a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
|
|
4189
|
+
//
|
|
4190
|
+
// Cache \u2014 public reads carry Cache-Control: public, max-age=300,
|
|
4191
|
+
// stale-while-revalidate=60. Storefront changes propagate within ~5 min
|
|
4192
|
+
// of the merchant publishing. Do not add extra client-side caching
|
|
4193
|
+
// beyond Next.js's default fetch cache.`;
|
|
3885
4194
|
var TYPES_BY_DOMAIN = {
|
|
3886
4195
|
products: PRODUCTS_TYPES,
|
|
3887
4196
|
cart: CART_TYPES,
|
|
@@ -3892,7 +4201,8 @@ var TYPES_BY_DOMAIN = {
|
|
|
3892
4201
|
helpers: HELPERS_TYPES,
|
|
3893
4202
|
inquiries: INQUIRIES_TYPES,
|
|
3894
4203
|
reviews: REVIEWS_TYPES,
|
|
3895
|
-
"modifier-groups": MODIFIER_GROUPS_TYPES
|
|
4204
|
+
"modifier-groups": MODIFIER_GROUPS_TYPES,
|
|
4205
|
+
content: CONTENT_TYPES
|
|
3896
4206
|
};
|
|
3897
4207
|
function getTypesByDomain(domain) {
|
|
3898
4208
|
if (domain === "all") {
|
|
@@ -3923,9 +4233,10 @@ var GET_TYPE_DEFINITIONS_SCHEMA = {
|
|
|
3923
4233
|
"helpers",
|
|
3924
4234
|
"inquiries",
|
|
3925
4235
|
"reviews",
|
|
4236
|
+
"content",
|
|
3926
4237
|
"all"
|
|
3927
4238
|
]).describe(
|
|
3928
|
-
'The domain of types to retrieve. Use "helpers" for helper function signatures and common types like StoreInfo, PaginatedResponse.'
|
|
4239
|
+
'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.'
|
|
3929
4240
|
)
|
|
3930
4241
|
};
|
|
3931
4242
|
async function handleGetTypeDefinitions(args) {
|
|
@@ -4472,8 +4783,10 @@ client.setLocale(locale);
|
|
|
4472
4783
|
// order bumps, search suggestions, discount banners, nudges,
|
|
4473
4784
|
// badges, order history.
|
|
4474
4785
|
|
|
4475
|
-
// For RTL
|
|
4476
|
-
//
|
|
4786
|
+
// For RTL direction, do not hardcode the locale list. Ask the SDK:
|
|
4787
|
+
// const dir = client.getStoreDirection(currentLocale); // 'ltr' | 'rtl'
|
|
4788
|
+
// document.documentElement.setAttribute('dir', dir);
|
|
4789
|
+
// (Or in React: <html dir={dir}>...</html>.)`,
|
|
4477
4790
|
"order-history-full": `// Full "My Orders" account page. Render every piece of data the server
|
|
4478
4791
|
// already returns \u2014 not just order number / total / status.
|
|
4479
4792
|
//
|
|
@@ -5565,7 +5878,7 @@ var RULES = {
|
|
|
5565
5878
|
body: `- NEVER hardcode currency, locale, or language strings. Read them from \`get-store-info\` / \`get-store-capabilities\` and use the configured values.
|
|
5566
5879
|
- NEVER format prices with \`toFixed(2)\` or custom logic. Use \`formatPrice()\` from the SDK \u2014 it honors the store's currency and locale.
|
|
5567
5880
|
- 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.
|
|
5568
|
-
- For RTL locales (\`
|
|
5881
|
+
- 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.`
|
|
5569
5882
|
},
|
|
5570
5883
|
types: {
|
|
5571
5884
|
title: "Type safety",
|
|
@@ -5613,6 +5926,7 @@ var GET_BUSINESS_FLOWS_SCHEMA = {
|
|
|
5613
5926
|
"cart-persistence",
|
|
5614
5927
|
"inventory-reservation",
|
|
5615
5928
|
"product-customization",
|
|
5929
|
+
"content-bootstrap",
|
|
5616
5930
|
"all"
|
|
5617
5931
|
]).describe('Which flow to retrieve. Use "all" to get every flow.')
|
|
5618
5932
|
};
|
|
@@ -5803,6 +6117,76 @@ Server-side guardrails that WILL reject bad requests (so validate client-side to
|
|
|
5803
6117
|
- More than 10 uploads per IP per minute \u2192 429.
|
|
5804
6118
|
|
|
5805
6119
|
Never render customization fields without also wiring the upload + metadata flow \u2014 a form that submits nothing is worse than no form at all.`
|
|
6120
|
+
},
|
|
6121
|
+
"content-bootstrap": {
|
|
6122
|
+
title: "Content Bootstrap \u2014 site chrome & static content",
|
|
6123
|
+
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\`).
|
|
6124
|
+
|
|
6125
|
+
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.
|
|
6126
|
+
\`\`\`ts
|
|
6127
|
+
const [header, footer, announcements] = await Promise.all([
|
|
6128
|
+
client.content.header.get('main', locale),
|
|
6129
|
+
client.content.footer.get('main', locale),
|
|
6130
|
+
client.content.announcement.list(locale),
|
|
6131
|
+
]);
|
|
6132
|
+
\`\`\`
|
|
6133
|
+
|
|
6134
|
+
2. **FAQ \u2014 fetch lazily on the FAQ page.** Default key is \`'main'\`; pass a topical key (\`'shipping'\`, \`'returns'\`) for sub-FAQs.
|
|
6135
|
+
\`\`\`ts
|
|
6136
|
+
const faq = await client.content.faq.get('main', locale);
|
|
6137
|
+
if (faq) {
|
|
6138
|
+
faq.data.items.forEach(({ question, answer }) => {
|
|
6139
|
+
// sanitize(answer) \u2014 see step 4
|
|
6140
|
+
});
|
|
6141
|
+
}
|
|
6142
|
+
\`\`\`
|
|
6143
|
+
|
|
6144
|
+
3. **Static pages \u2014 catch-all route by slug:**
|
|
6145
|
+
\`\`\`tsx
|
|
6146
|
+
// app/[slug]/page.tsx
|
|
6147
|
+
export default async function Page({ params }) {
|
|
6148
|
+
const page = await client.content.page.getBySlug(params.slug, locale);
|
|
6149
|
+
if (!page) notFound();
|
|
6150
|
+
return (
|
|
6151
|
+
<article dangerouslySetInnerHTML={{ __html: sanitize(page.data.html) }} />
|
|
6152
|
+
);
|
|
6153
|
+
}
|
|
6154
|
+
\`\`\`
|
|
6155
|
+
|
|
6156
|
+
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:
|
|
6157
|
+
\`\`\`ts
|
|
6158
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
6159
|
+
const safe = DOMPurify.sanitize(rawHtml);
|
|
6160
|
+
<div dangerouslySetInnerHTML={{ __html: safe }} />;
|
|
6161
|
+
\`\`\`
|
|
6162
|
+
Skipping this is XSS.
|
|
6163
|
+
|
|
6164
|
+
5. **Announcements \u2014 multiple may be active; filter by date client-side:**
|
|
6165
|
+
\`\`\`ts
|
|
6166
|
+
const now = Date.now();
|
|
6167
|
+
const visible = announcements.filter((a) => {
|
|
6168
|
+
const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
|
|
6169
|
+
const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
|
|
6170
|
+
return startOk && endOk;
|
|
6171
|
+
});
|
|
6172
|
+
\`\`\`
|
|
6173
|
+
|
|
6174
|
+
6. **RTL direction \u2014 call \`client.getStoreDirection(locale)\`:**
|
|
6175
|
+
\`\`\`tsx
|
|
6176
|
+
const dir = client.getStoreDirection(locale);
|
|
6177
|
+
<html lang={locale} dir={dir}>...</html>
|
|
6178
|
+
\`\`\`
|
|
6179
|
+
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.
|
|
6180
|
+
|
|
6181
|
+
7. **Custom fields \u2014 every Content row has free-form \`customFields: Record<string, string>\`.** Read keys the merchant told you to expect:
|
|
6182
|
+
\`\`\`ts
|
|
6183
|
+
const faq = await client.content.faq.get('shipping');
|
|
6184
|
+
<a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
|
|
6185
|
+
\`\`\`
|
|
6186
|
+
|
|
6187
|
+
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.
|
|
6188
|
+
|
|
6189
|
+
**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.`
|
|
5806
6190
|
}
|
|
5807
6191
|
};
|
|
5808
6192
|
var FLOW_ORDER = [
|
|
@@ -5814,7 +6198,8 @@ var FLOW_ORDER = [
|
|
|
5814
6198
|
"order-confirmation",
|
|
5815
6199
|
"cart-persistence",
|
|
5816
6200
|
"inventory-reservation",
|
|
5817
|
-
"product-customization"
|
|
6201
|
+
"product-customization",
|
|
6202
|
+
"content-bootstrap"
|
|
5818
6203
|
];
|
|
5819
6204
|
async function handleGetBusinessFlows(args) {
|
|
5820
6205
|
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.";
|
|
@@ -6026,11 +6411,57 @@ var FEATURES = [
|
|
|
6026
6411
|
{
|
|
6027
6412
|
id: "i18n",
|
|
6028
6413
|
title: "Serve multiple languages with a language switcher",
|
|
6029
|
-
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
|
|
6030
|
-
sdk: "client.setLocale(locale). Read supported locales from get-store-capabilities.store.i18n.",
|
|
6414
|
+
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.",
|
|
6415
|
+
sdk: "client.setLocale(locale). client.getStoreDirection(locale) for <html dir>. Read supported locales from get-store-capabilities.store.i18n.",
|
|
6031
6416
|
mandatory: "conditional",
|
|
6032
6417
|
capabilityFlag: "i18n",
|
|
6033
6418
|
whenDisabledNote: "This store is single-language. Do not build the language switcher."
|
|
6419
|
+
},
|
|
6420
|
+
{
|
|
6421
|
+
id: "site-header",
|
|
6422
|
+
title: "Site header from merchant content (logo + nav + CTA)",
|
|
6423
|
+
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.',
|
|
6424
|
+
sdk: 'client.content.header.get("main", locale)',
|
|
6425
|
+
flowRef: "content-bootstrap",
|
|
6426
|
+
mandatory: "mandatory"
|
|
6427
|
+
},
|
|
6428
|
+
{
|
|
6429
|
+
id: "site-footer",
|
|
6430
|
+
title: "Site footer from merchant content (columns + social + copyright)",
|
|
6431
|
+
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.',
|
|
6432
|
+
sdk: 'client.content.footer.get("main", locale)',
|
|
6433
|
+
flowRef: "content-bootstrap",
|
|
6434
|
+
mandatory: "mandatory"
|
|
6435
|
+
},
|
|
6436
|
+
{
|
|
6437
|
+
id: "announcement-bar",
|
|
6438
|
+
title: "Announcement bar at the top of every page",
|
|
6439
|
+
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.",
|
|
6440
|
+
sdk: "client.content.announcement.list(locale)",
|
|
6441
|
+
flowRef: "content-bootstrap",
|
|
6442
|
+
mandatory: "conditional",
|
|
6443
|
+
capabilityFlag: "hasContent",
|
|
6444
|
+
whenDisabledNote: "Store has no published Content rows yet. Build the announcement bar anyway \u2014 it auto-hides on empty."
|
|
6445
|
+
},
|
|
6446
|
+
{
|
|
6447
|
+
id: "faq-page",
|
|
6448
|
+
title: "FAQ page rendered from merchant content",
|
|
6449
|
+
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.',
|
|
6450
|
+
sdk: 'client.content.faq.get("main", locale), client.content.faq.list(locale)',
|
|
6451
|
+
flowRef: "content-bootstrap",
|
|
6452
|
+
mandatory: "conditional",
|
|
6453
|
+
capabilityFlag: "hasContent",
|
|
6454
|
+
whenDisabledNote: "No FAQ content yet. Build /faq anyway \u2014 it auto-hides on empty."
|
|
6455
|
+
},
|
|
6456
|
+
{
|
|
6457
|
+
id: "static-pages",
|
|
6458
|
+
title: "Static pages from merchant content (About, Terms, Privacy, \u2026)",
|
|
6459
|
+
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.",
|
|
6460
|
+
sdk: "client.content.page.getBySlug(slug, locale), client.content.page.list(locale)",
|
|
6461
|
+
flowRef: "content-bootstrap",
|
|
6462
|
+
mandatory: "conditional",
|
|
6463
|
+
capabilityFlag: "hasContent",
|
|
6464
|
+
whenDisabledNote: "No static pages yet. Build the catch-all route anyway \u2014 it 404s on unknown slugs."
|
|
6034
6465
|
}
|
|
6035
6466
|
];
|
|
6036
6467
|
function isFeatureActive(feature, caps) {
|
|
@@ -6081,6 +6512,7 @@ function renderCapabilitiesSummary(caps) {
|
|
|
6081
6512
|
);
|
|
6082
6513
|
lines.push(`- Downloadable products: ${caps.features.hasDownloadableProducts ? "yes" : "no"}`);
|
|
6083
6514
|
lines.push(`- Checkout custom fields: ${caps.features.hasCheckoutCustomFields ? "yes" : "no"}`);
|
|
6515
|
+
lines.push(`- Content (FAQ/footer/header/announcements/pages): ${caps.features.hasContent ? "seeded" : "none \u2014 build chrome UI with fallbacks"}`);
|
|
6084
6516
|
lines.push(
|
|
6085
6517
|
`- Email verification: ${caps.connection.requireEmailVerification ? "required" : "not required (still build the verify-email flow)"}`
|
|
6086
6518
|
);
|