@brainerce/mcp-server 3.9.0 → 3.11.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
@@ -735,7 +735,7 @@ const growProvider = providers.find(p => p.provider === 'grow');
735
735
  const paypalProvider = providers.find(p => p.provider === 'paypal');
736
736
  \`\`\`
737
737
 
738
- Each provider has: \`id\`, \`provider\` (flexible string \u2014 \`'stripe'\`, \`'grow'\`, \`'paypal'\`, \`'cardcom'\`, \`'sandbox'\`, and future providers), \`name\`, \`publicKey\`, \`stripeAccountId\` (Stripe only), \`supportedMethods\`, \`testMode\`, \`isDefault\`.
738
+ Each provider has: \`id\`, \`provider\` (flexible string \u2014 \`'stripe'\`, \`'grow'\`, \`'paypal'\`, \`'cardcom'\`, \`'morning'\`, \`'takbull'\`, \`'sandbox'\`, and future providers), \`name\`, \`publicKey\`, \`stripeAccountId\` (Stripe only), \`supportedMethods\`, \`testMode\`, \`isDefault\`.
739
739
 
740
740
  The payment intent returned from \`createPaymentIntent()\` includes a \`clientSdk\` object whose \`renderType\` tells you exactly how to render \u2014 **branch on THAT, not on the provider name**:
741
741
 
@@ -2394,6 +2394,67 @@ Read \`storeInfo.i18n.supportedLocales\` and render a switcher in the header
2394
2394
  that navigates to \`/{otherLocale}/{currentPathWithoutLocale}\`. The middleware
2395
2395
  handles the canonical redirect when the user picks the default locale.`;
2396
2396
  }
2397
+ function getMultilingualSeoSection() {
2398
+ return `## Multilingual SEO
2399
+
2400
+ ### Slugs per locale (IMPORTANT)
2401
+
2402
+ Brainerce stores per-locale slugs in \`Product.translations[locale].slug\`.
2403
+ The API exposes them as \`product.localeSlugs\` \u2014 a flat \`Record<string, string>\`.
2404
+
2405
+ \`\`\`typescript
2406
+ // product.localeSlugs = { he: '\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4', en: 'yoga-mattress', ar: '\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627' }
2407
+ const locSlug = product.localeSlugs?.[locale] ?? product.slug;
2408
+ \`\`\`
2409
+
2410
+ Use AI translation (\`translateEntities\` / the AI Translate button in the admin) to populate
2411
+ locale-specific slugs automatically. Until translated, all locales fall back to the base slug
2412
+ (which Google still accepts \u2014 it resolves to the correct locale content via Accept-Language).
2413
+
2414
+ ### hreflang tags
2415
+
2416
+ Every product page in a multi-locale store MUST emit bidirectional hreflang tags or Google
2417
+ ignores them entirely. The scaffolded template generates them automatically when
2418
+ \`NEXT_PUBLIC_BRAINERCE_LOCALES=he,en\` is set.
2419
+
2420
+ \`\`\`html
2421
+ <!-- Example output for /en/products/yoga-mattress -->
2422
+ <link rel="alternate" hreflang="he" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
2423
+ <link rel="alternate" hreflang="en" href="https://store.com/en/products/yoga-mattress" />
2424
+ <link rel="alternate" hreflang="x-default" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
2425
+ \`\`\`
2426
+
2427
+ If building a custom storefront, add to \`generateMetadata()\`:
2428
+ \`\`\`typescript
2429
+ alternates: {
2430
+ canonical: locale === defaultLoc ? \`/products/\${slug}\` : \`/\${locale}/products/\${slug}\`,
2431
+ languages: {
2432
+ he: \`\${baseUrl}/products/\${localeSlugs.he ?? baseSlug}\`,
2433
+ en: \`\${baseUrl}/en/products/\${localeSlugs.en ?? baseSlug}\`,
2434
+ 'x-default': \`\${baseUrl}/products/\${localeSlugs[defaultLoc] ?? baseSlug}\`,
2435
+ },
2436
+ },
2437
+ \`\`\`
2438
+
2439
+ ### URL structure
2440
+
2441
+ Google-recommended for headless storefronts:
2442
+ - Default locale: \`/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4\` (no prefix)
2443
+ - Other locales: \`/en/products/yoga-mattress\` (prefixed)
2444
+ - \u274C Never: \`?locale=he\` query params (Google rates these as "Not recommended")
2445
+
2446
+ ### Sitemap
2447
+
2448
+ The scaffolded \`sitemap.ts\` generates per-locale entries automatically:
2449
+ \`\`\`
2450
+ /products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4 (he \u2014 default, no prefix)
2451
+ /en/products/yoga-mattress (en)
2452
+ /ar/products/\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627 (ar)
2453
+ \`\`\`
2454
+
2455
+ Hebrew, Arabic, and other non-Latin slugs are fully supported \u2014 Google recommends
2456
+ using the audience's language in URLs and indexes non-ASCII characters correctly.`;
2457
+ }
2397
2458
  function getAdminApiSection() {
2398
2459
  return `## Admin API (v0.19.0+)
2399
2460
 
@@ -2477,6 +2538,20 @@ await admin.mergeTaxClasses(food.id, standardClassId);
2477
2538
  Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreTaxClasses()\` lists
2478
2539
  the store's classes (storefront-safe fields only) for a transparency badge.
2479
2540
 
2541
+ For a buyer-facing tax preview on PDP / PLP / cart, \`estimateTax({ country,
2542
+ subtotal })\` returns the tax portion at the Standard rate for the buyer's
2543
+ country. **Non-binding** \u2014 the authoritative tax still runs at checkout with
2544
+ the full shipping address (state / postal / per-class). Always render with an
2545
+ "Estimate" affordance.
2546
+
2547
+ \`\`\`typescript
2548
+ const { estimatedTax, rate, currency, note } = await store.estimateTax({
2549
+ country: 'IT', subtotal: 100,
2550
+ });
2551
+ // \u2192 { appliesTax: true, rate: 22, estimatedTax: 22, currency: 'EUR',
2552
+ // note: 'Estimate \u2014 final tax calculated at checkout\u2026' }
2553
+ \`\`\`
2554
+
2480
2555
  ### Regions (multi-currency / per-region providers)
2481
2556
 
2482
2557
  A region binds countries \u2192 currency + tax-display mode + enabled payment
@@ -2507,6 +2582,19 @@ const { data: regions } = await store.getStoreRegions();
2507
2582
  const region = await store.getStoreRegion(regions[0].id);
2508
2583
  \`\`\`
2509
2584
 
2585
+ For a single round trip, \`getAutoRegion(country)\` resolves a buyer's country
2586
+ to a region server-side. Brainerce does NOT derive the country from the request
2587
+ IP (the storefront server is what reaches the backend, not the end-customer) \u2014
2588
+ your storefront extracts the country from its edge runtime (Cloudflare
2589
+ \`CF-IPCountry\`, Vercel \`request.geo?.country\`, Fastly \`client-geo-country\`,
2590
+ etc.) and forwards it. Returns \`matched=true\` on explicit country hit, \`false\`
2591
+ when falling back to the default region.
2592
+
2593
+ \`\`\`typescript
2594
+ const country = headers.get('cf-ipcountry') ?? 'US';
2595
+ const { region, matched } = await store.getAutoRegion(country);
2596
+ \`\`\`
2597
+
2510
2598
  A shipping zone can be limited to regions via \`regionIds\` \u2014 the zone is then
2511
2599
  only offered to checkouts that resolved to one of those regions. Empty/omitted =
2512
2600
  available for any region (default); each id must belong to the same store.
@@ -2970,6 +3058,146 @@ entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'
2970
3058
  - \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
2971
3059
  interfaces.`;
2972
3060
  }
3061
+ function getBlogSection() {
3062
+ return `## Blog
3063
+
3064
+ Merchants write and schedule blog posts in **Content \u2192 Blog** in the dashboard.
3065
+ Storefronts choose their own URL scheme \u2014 render posts at \`/blog/[slug]\`,
3066
+ \`/articles/[slug]\`, or whatever fits the brand.
3067
+
3068
+ Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
3069
+
3070
+ **Scheduling:** A post is visible once \`status === 'PUBLISHED'\` and
3071
+ \`publishedAt <= now()\`. Set a future \`publishedAt\` while publishing to
3072
+ schedule \u2014 no cron needed; visibility is computed at query time.
3073
+
3074
+ ### Reading posts (any SDK mode)
3075
+
3076
+ \`\`\`typescript
3077
+ // List published posts
3078
+ const { data: posts, meta } = await client.blog.getPosts({ page: 1, limit: 10 });
3079
+
3080
+ // Filter by category or tag
3081
+ const { data: news } = await client.blog.getPosts({ category: 'news' });
3082
+ const { data: tips } = await client.blog.getPosts({ tag: 'tutorial' });
3083
+
3084
+ // Fetch one by slug (returns null on 404)
3085
+ const post = await client.blog.getPost('my-first-post');
3086
+ if (post) {
3087
+ console.log(post.title); // string
3088
+ console.log(post.content); // HTML string from rich-text editor
3089
+ console.log(post.excerpt); // optional short summary
3090
+ console.log(post.tags); // string[]
3091
+ console.log(post.coverImageUrl, post.coverImageAlt);
3092
+ console.log(post.publishedAt); // ISO 8601 or undefined
3093
+ }
3094
+ \`\`\`
3095
+
3096
+ ### BlogPost fields
3097
+
3098
+ | Field | Type | Notes |
3099
+ | ----------------- | ----------- | ------------------------------------- |
3100
+ | \`id\` | string | |
3101
+ | \`title\` | string | |
3102
+ | \`slug\` | string | Unique per store, URL-safe |
3103
+ | \`category\` | string? | Free-form (e.g. \`'news'\`) |
3104
+ | \`content\` | string | HTML from rich-text editor |
3105
+ | \`excerpt\` | string? | Short summary for listing cards |
3106
+ | \`coverImageUrl\` | string? | |
3107
+ | \`coverImageAlt\` | string? | |
3108
+ | \`author\` | string? | |
3109
+ | \`tags\` | string[] | |
3110
+ | \`publishedAt\` | string? | ISO 8601; null = publish immediately |
3111
+ | \`seoTitle\` | string? | |
3112
+ | \`seoDescription\`| string? | |
3113
+ | \`ogImageUrl\` | string? | |
3114
+
3115
+ ### Rendering blog content
3116
+
3117
+ \`\`\`tsx
3118
+ // app/blog/[slug]/page.tsx
3119
+ import DOMPurify from 'isomorphic-dompurify';
3120
+
3121
+ const post = await brainerce.blog.getPost(params.slug);
3122
+ if (!post) notFound();
3123
+
3124
+ // Always sanitize before rendering HTML \u2014 treat external-origin content as untrusted
3125
+ const safeHtml = DOMPurify.sanitize(post.content);
3126
+ return <div dangerouslySetInnerHTML={{ __html: safeHtml }} className="prose" />;
3127
+ \`\`\`
3128
+
3129
+ The \`content\` field is HTML produced by the Lexical rich-text editor.
3130
+ **Always sanitize with DOMPurify (or equivalent) before rendering via
3131
+ \`dangerouslySetInnerHTML\`** \u2014 even though the content originates from your
3132
+ own editor, defense-in-depth prevents any stored-XSS path if content is ever
3133
+ migrated or imported from an external source.
3134
+ Apply a \`prose\` class (Tailwind Typography) for automatic styling.
3135
+
3136
+ ### REST endpoints
3137
+
3138
+ | Method | Path | Returns |
3139
+ |--------|------|---------|
3140
+ | GET | \`/api/stores/:storeId/blog/posts\` | \`BlogPostListResponse\` |
3141
+ | GET | \`/api/stores/:storeId/blog/posts/:slug\` | \`BlogPost\` or 404 |
3142
+ | GET | \`/api/vc/:connectionId/blog/posts\` | Same, channel-scoped |
3143
+ | GET | \`/api/vc/:connectionId/blog/posts/:slug\` | \`BlogPost\` or 404 |
3144
+ `;
3145
+ }
3146
+ function getStorefrontBotSection(connectionId) {
3147
+ return `## Storefront Bot (AI chat widget)
3148
+
3149
+ The store's AI shopping assistant. ALL configuration (name, avatar, colors,
3150
+ greeting, starter questions, capabilities, guardrails) lives in the merchant
3151
+ dashboard \u2014 the embed never decides behavior, and the widget renders nothing
3152
+ until the merchant switches the bot Live.
3153
+
3154
+ ### Zero-code embed (any site)
3155
+
3156
+ \`\`\`html
3157
+ <script src="https://cdn.brainerce.com/bot.js" data-connection-id="${connectionId}" defer></script>
3158
+ \`\`\`
3159
+
3160
+ Keep the tag exactly this bare \u2014 do NOT add \`integrity\` or \`crossorigin\`
3161
+ (the bootstrap is intentionally mutable; it is origin-pinned by CSP instead).
3162
+
3163
+ ### SDK mount (React / Next.js / any bundler)
3164
+
3165
+ \`\`\`ts
3166
+ import { BrainerceBot } from 'brainerce/bot';
3167
+
3168
+ // client-side only (e.g. in a useEffect) \u2014 mounts a floating chat bubble
3169
+ const bot = await BrainerceBot.mount({ connectionId: '${connectionId}' });
3170
+ bot?.destroy(); // optional teardown
3171
+ \`\`\`
3172
+
3173
+ \`mount\` resolves to \`null\` when the bot is disabled (FREE plan, switched
3174
+ off, or unconfigured) \u2014 safe to call unconditionally. Options: \`connectionId\`
3175
+ (required), \`baseUrl\` (API origin override), \`target\` (mount element),
3176
+ \`onAddToCart\` (\`({ productId, variantId, quantity }) => boolean | Promise<boolean>\`
3177
+ \u2014 route the widget's cart adds through the site's own cart; \`variantId\` is
3178
+ null for simple products; return false to fall back to the product page).
3179
+
3180
+ Behavior: persists an anonymous session in localStorage, restores the
3181
+ conversation on revisit, streams answers, and shows product recommendation
3182
+ cards (image, price, add-to-cart / view). Multi-variant products get an
3183
+ in-card variant picker; shoppers can also ask the assistant to add an item
3184
+ and it goes through the same cart chain. Zero-result searches feed the
3185
+ merchant's "unmet demand" analytics. Aside from shopper-initiated cart adds,
3186
+ the bot is read-only.
3187
+
3188
+ Add-to-cart resolution chain: \`onAddToCart\` option \u2192 cancelable
3189
+ \`brainerce:bot:add-to-cart\` CustomEvent on window
3190
+ (\`detail: { productId, variantId, quantity, connectionId }\`; call
3191
+ preventDefault() after handling) \u2192 navigate to the product page.
3192
+
3193
+ Rules:
3194
+ - Mount once per page; do not pass any visual config \u2014 the dashboard owns it.
3195
+ - Do not wrap or restyle the widget; it renders in its own Shadow DOM.
3196
+ - Product card links expect the conventional \`/products/<slug>\` route.
3197
+ - Wire \`onAddToCart\` to the site's cart (see the cart section) so the header
3198
+ count updates when the bot adds items.
3199
+ `;
3200
+ }
2973
3201
  function getSectionByTopic(topic, connectionId, currency) {
2974
3202
  const cid = connectionId || "vc_YOUR_CONNECTION_ID";
2975
3203
  const cur = currency || "USD";
@@ -3008,6 +3236,10 @@ function getSectionByTopic(topic, connectionId, currency) {
3008
3236
  return getTaxDisplaySection(cur);
3009
3237
  case "i18n":
3010
3238
  return getI18nSection();
3239
+ case "multilingual-seo":
3240
+ case "hreflang":
3241
+ case "seo-i18n":
3242
+ return getMultilingualSeoSection();
3011
3243
  case "critical-rules":
3012
3244
  return getCriticalRulesSection() + "\n\n" + getTypeQuickReference();
3013
3245
  case "type-reference":
@@ -3018,6 +3250,10 @@ function getSectionByTopic(topic, connectionId, currency) {
3018
3250
  return getContactInquiriesSection();
3019
3251
  case "content":
3020
3252
  return getContentSection();
3253
+ case "blog":
3254
+ return getBlogSection();
3255
+ case "storefront-bot":
3256
+ return getStorefrontBotSection(cid);
3021
3257
  case "all":
3022
3258
  return [
3023
3259
  "# Brainerce SDK \u2014 full topic dump",
@@ -3102,6 +3338,10 @@ function getSectionByTopic(topic, connectionId, currency) {
3102
3338
  "",
3103
3339
  "---",
3104
3340
  "",
3341
+ getMultilingualSeoSection(),
3342
+ "",
3343
+ "---",
3344
+ "",
3105
3345
  getAdminApiSection(),
3106
3346
  "",
3107
3347
  "---",
@@ -3110,10 +3350,18 @@ function getSectionByTopic(topic, connectionId, currency) {
3110
3350
  "",
3111
3351
  "---",
3112
3352
  "",
3113
- getContentSection()
3353
+ getContentSection(),
3354
+ "",
3355
+ "---",
3356
+ "",
3357
+ getBlogSection(),
3358
+ "",
3359
+ "---",
3360
+ "",
3361
+ getStorefrontBotSection(cid)
3114
3362
  ].join("\n");
3115
3363
  default:
3116
- 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`;
3364
+ 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, blog, all`;
3117
3365
  }
3118
3366
  }
3119
3367
 
@@ -3142,6 +3390,7 @@ var GET_SDK_DOCS_SCHEMA = {
3142
3390
  "admin",
3143
3391
  "inquiries",
3144
3392
  "content",
3393
+ "storefront-bot",
3145
3394
  "all"
3146
3395
  ]).describe("The SDK documentation topic to retrieve"),
3147
3396
  salesChannelId: import_zod.z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
@@ -3179,6 +3428,12 @@ interface Product {
3179
3428
  priceMin?: string | null; // Lowest variant price (VARIABLE products) \u2014 same as basePrice for VARIABLE, kept for back-compat and JSON-LD range display.
3180
3429
  priceMax?: string | null; // Highest variant price (VARIABLE products). Use with priceMin for "\u20AA49 \u2013 \u20AA199" range.
3181
3430
  priceVaries?: boolean; // true when variant prices differ \u2014 show "\u20AA49 \u2013 \u20AA199" range.
3431
+ // FX DISPLAY overlay (PRD \xA723). Set only when getProducts({ regionId }) was called AND region.currency !== store.currency. basePrice/salePrice above stay in store currency \u2014 these are additive, display-only. The buyer is still charged in store currency at checkout; payment provider handles customer-side FX.
3432
+ displayPrice?: string; // basePrice \xD7 daily FX rate, in displayCurrency.
3433
+ displaySalePrice?: string; // salePrice \xD7 rate (if salePrice present).
3434
+ displayPriceMin?: string; // priceMin \xD7 rate (VARIABLE products).
3435
+ displayPriceMax?: string; // priceMax \xD7 rate (VARIABLE products).
3436
+ displayCurrency?: string; // ISO 4217 of the region \u2014 e.g. "EUR".
3182
3437
  status: string;
3183
3438
  type: 'SIMPLE' | 'VARIABLE';
3184
3439
  isDownloadable?: boolean;
@@ -3222,6 +3477,10 @@ interface ProductVariant {
3222
3477
  name?: string | null;
3223
3478
  price?: string | null;
3224
3479
  salePrice?: string | null;
3480
+ // FX DISPLAY overlay (PRD \xA723) \u2014 same semantics as on the parent Product.
3481
+ displayPrice?: string;
3482
+ displaySalePrice?: string;
3483
+ displayCurrency?: string;
3225
3484
  attributes?: Record<string, string> | null;
3226
3485
  options?: Array<{ name: string; value: string }>;
3227
3486
  inventory?: InventoryInfo | null;
@@ -4351,6 +4610,15 @@ interface PublicRegionDetail extends PublicRegion {
4351
4610
  }
4352
4611
  // getStoreRegions(): { data: PublicRegion[] } \u2014 active regions, default first.
4353
4612
  // getStoreRegion(regionId): PublicRegionDetail \u2014 one region + its providers.
4613
+ interface AutoRegionResponse {
4614
+ region: PublicRegion | null;
4615
+ matched: boolean; // true=country was in a region's list; false=fell back to default
4616
+ country: string; // upper-cased ISO-3166-1 alpha-2; '' when caller omitted it
4617
+ }
4618
+ // getAutoRegion(country): AutoRegionResponse \u2014 server-side resolution in one
4619
+ // round trip. Pair with the country your edge runtime extracts
4620
+ // (CF-IPCountry / request.geo.country / etc.) \u2014 Brainerce does NOT derive the
4621
+ // country from the request IP server-side (storefront != end-customer).
4354
4622
 
4355
4623
  // ---- Tax Classes ---- (scopes: tax-classes:read / tax-classes:write)
4356
4624
  // Charge differential rates by product type. A TaxRate may target a class via
@@ -4382,7 +4650,25 @@ interface AssignTaxClassDto { productIds?: string[]; variantIds?: string[]; cate
4382
4650
  // getRegionCompatibleProviders(id), detectRegion(country, regions)
4383
4651
  // Tax classes: getTaxClasses(), getTaxClass(id), createTaxClass(dto), updateTaxClass(id, dto),
4384
4652
  // deleteTaxClass(id), setDefaultTaxClass(id), assignTaxClass(id, dto),
4385
- // mergeTaxClasses(id, targetId)`;
4653
+ // mergeTaxClasses(id, targetId)
4654
+ //
4655
+ // SDK methods (storefront, public \u2014 storeId mode, no apiKey):
4656
+ // getStoreRegions(), getStoreRegion(id), getAutoRegion(country)
4657
+ // getStoreTaxClasses(), estimateTax({ country?, subtotal })
4658
+ //
4659
+ // estimateTax returns:
4660
+ interface TaxEstimateResponse {
4661
+ appliesTax: boolean;
4662
+ rate: number | null; // percent (18 = 18%) \u2014 null when no matching rule
4663
+ rateName: string | null;
4664
+ estimatedTax: number; // tax portion of subtotal in store currency
4665
+ pricesIncludeTax: boolean;
4666
+ currency: string; // store currency (cart/order currency)
4667
+ note: string; // disclaimer \u2014 preview is non-binding
4668
+ }
4669
+ // Non-binding by design: the authoritative tax runs at checkout against the
4670
+ // full shipping address. The country comes from your edge runtime
4671
+ // (CF-IPCountry / request.geo.country / etc.), NOT the request IP.`;
4386
4672
  var TYPES_BY_DOMAIN = {
4387
4673
  products: PRODUCTS_TYPES,
4388
4674
  cart: CART_TYPES,