@brainerce/mcp-server 3.9.0 → 3.11.1
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 +322 -9
- package/dist/bin/stdio.js +322 -9
- package/dist/index.d.mts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +322 -9
- package/dist/index.mjs +322 -9
- package/package.json +53 -53
package/dist/bin/http.js
CHANGED
|
@@ -163,7 +163,26 @@ import {
|
|
|
163
163
|
getDescriptionContent, isHtmlDescription,
|
|
164
164
|
getProductMetafieldValue, getProductCustomizationFields,
|
|
165
165
|
} from 'brainerce';
|
|
166
|
-
|
|
166
|
+
\`\`\`
|
|
167
|
+
|
|
168
|
+
### Available features \u2014 request each topic for full docs
|
|
169
|
+
|
|
170
|
+
| Topic | What it covers |
|
|
171
|
+
|-------|----------------|
|
|
172
|
+
| \`products\` | Catalog listing, search, PDP, variants, swatches, stock, attributes |
|
|
173
|
+
| \`cart\` | Guest + logged-in cart, add/remove/update, reservations |
|
|
174
|
+
| \`checkout\` | Guest + customer checkout, shipping, address |
|
|
175
|
+
| \`payment\` | Payment providers, intents, status polling, confirmation |
|
|
176
|
+
| \`auth\` | Customer sign-up, login, OAuth, email verification |
|
|
177
|
+
| \`discounts\` | Coupons, banners, nudges |
|
|
178
|
+
| \`recommendations\` | Cross-sell / upsell grids |
|
|
179
|
+
| \`reviews\` | Product reviews & ratings |
|
|
180
|
+
| \`inventory\` | Stock badges, reservation countdown |
|
|
181
|
+
| \`inquiries\` | Contact / custom forms |
|
|
182
|
+
| \`i18n\` | Multi-language, RTL |
|
|
183
|
+
| \`admin\` | Server-to-server admin API (products, orders, customers) |
|
|
184
|
+
| \`storefront-bot\` | **AI chat widget** \u2014 add Brainerce's AI shopping assistant to any page with one script tag or \`BrainerceBot.mount()\`. Answers product questions, shows recommendation cards, handles cart adds, opens escalation form. |
|
|
185
|
+
| \`content\` | Blog, articles, static pages |`;
|
|
167
186
|
}
|
|
168
187
|
function getCheckoutFlowSection(_currency) {
|
|
169
188
|
return `## \u26A0\uFE0F CHECKOUT FLOW (CRITICAL \u2014 READ CAREFULLY!)
|
|
@@ -712,7 +731,7 @@ const growProvider = providers.find(p => p.provider === 'grow');
|
|
|
712
731
|
const paypalProvider = providers.find(p => p.provider === 'paypal');
|
|
713
732
|
\`\`\`
|
|
714
733
|
|
|
715
|
-
Each provider has: \`id\`, \`provider\` (flexible string \u2014 \`'stripe'\`, \`'grow'\`, \`'paypal'\`, \`'cardcom'\`, \`'sandbox'\`, and future providers), \`name\`, \`publicKey\`, \`stripeAccountId\` (Stripe only), \`supportedMethods\`, \`testMode\`, \`isDefault\`.
|
|
734
|
+
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\`.
|
|
716
735
|
|
|
717
736
|
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**:
|
|
718
737
|
|
|
@@ -1885,8 +1904,8 @@ function getTaxDisplaySection(_currency) {
|
|
|
1885
1904
|
| Product Page | \u274C No | "Price excludes tax" (optional note) |
|
|
1886
1905
|
| Cart Page | \u26A0\uFE0F "Calculated at checkout" | No address yet |
|
|
1887
1906
|
| Checkout (before address) | \u26A0\uFE0F "Enter address to calculate" | Waiting for location |
|
|
1888
|
-
| Checkout (after address) | \u2705 **REQUIRED** | \`checkout.taxAmount\` |
|
|
1889
|
-
| Order Confirmation | \u2705 **REQUIRED** | \`order.taxAmount\` |
|
|
1907
|
+
| Checkout (after address) | \u2705 **REQUIRED** | \`checkout.taxAmount\` (0 in VAT mode \u2192 \`checkout.taxBreakdown.totalTax\`) |
|
|
1908
|
+
| Order Confirmation | \u2705 **REQUIRED** | \`order.taxAmount\` (0 in VAT mode \u2192 \`order.taxBreakdown.totalTax\`) |
|
|
1890
1909
|
|
|
1891
1910
|
### Cart Page \u2014 Partial Display
|
|
1892
1911
|
|
|
@@ -1938,7 +1957,13 @@ const totals = getCartTotals(cart);
|
|
|
1938
1957
|
<div className="flex justify-between text-green-600"><span>Discount</span><span>-{formatPrice(order.discountAmount, { currency: order.currency })}</span></div>
|
|
1939
1958
|
)}
|
|
1940
1959
|
<div className="flex justify-between"><span>Shipping</span><span>{formatPrice(order.shippingAmount, { currency: order.currency })}</span></div>
|
|
1941
|
-
|
|
1960
|
+
{/* Inclusive (VAT) stores keep taxAmount="0" \u2014 the real VAT is on taxBreakdown.totalTax. */}
|
|
1961
|
+
{(() => {
|
|
1962
|
+
const tax = parseFloat(order.taxAmount || '0') || order.taxBreakdown?.totalTax || 0;
|
|
1963
|
+
if (tax <= 0) return null;
|
|
1964
|
+
const incl = order.taxBreakdown?.pricesIncludeTax;
|
|
1965
|
+
return <div className="flex justify-between"><span>{incl ? 'Tax (incl.)' : 'Tax'}</span><span>{formatPrice(tax, { currency: order.currency })}</span></div>;
|
|
1966
|
+
})()}
|
|
1942
1967
|
<div className="flex justify-between font-bold text-lg border-t pt-2"><span>Total Paid</span><span>{formatPrice(order.totalAmount, { currency: order.currency })}</span></div>
|
|
1943
1968
|
</div>
|
|
1944
1969
|
\`\`\``;
|
|
@@ -2067,7 +2092,7 @@ A useful order card includes ALL of the following when the data is present. Each
|
|
|
2067
2092
|
| **Tracking** | \`order.trackingNumber\`, \`order.trackingUrl\`, \`order.carrier\`, \`order.shippedAt\`, \`order.deliveredAt\` | Link out to \`trackingUrl\` when set. |
|
|
2068
2093
|
| **Payment** | \`order.paymentMethod\`, \`order.financialStatus\` | Badge \`financialStatus\` (paid / pending / refunded / partially_refunded). |
|
|
2069
2094
|
| Downloads | \`order.hasDownloads\` \u2192 \`client.getOrderDownloads(id)\` | Separate call; returns \`OrderDownloadLink[]\`. |
|
|
2070
|
-
| Financial summary | \`order.subtotal\`, \`order.appliedDiscounts\`, \`order.couponCode\` + \`couponDiscount\`, \`order.shippingAmount\`, \`order.taxAmount\`, \`order.totalAmount\` | Breakdown rows + final total. |
|
|
2095
|
+
| Financial summary | \`order.subtotal\`, \`order.appliedDiscounts\`, \`order.couponCode\` + \`couponDiscount\`, \`order.shippingAmount\`, \`order.taxAmount\`, \`order.totalAmount\` | Breakdown rows + final total. In VAT-inclusive mode \`taxAmount\` is 0 \u2014 read \`order.taxBreakdown.totalTax\` and label "Tax (incl.)". |
|
|
2071
2096
|
|
|
2072
2097
|
#### Rendering \`order.items[i].customizations\` by type
|
|
2073
2098
|
|
|
@@ -2371,6 +2396,67 @@ Read \`storeInfo.i18n.supportedLocales\` and render a switcher in the header
|
|
|
2371
2396
|
that navigates to \`/{otherLocale}/{currentPathWithoutLocale}\`. The middleware
|
|
2372
2397
|
handles the canonical redirect when the user picks the default locale.`;
|
|
2373
2398
|
}
|
|
2399
|
+
function getMultilingualSeoSection() {
|
|
2400
|
+
return `## Multilingual SEO
|
|
2401
|
+
|
|
2402
|
+
### Slugs per locale (IMPORTANT)
|
|
2403
|
+
|
|
2404
|
+
Brainerce stores per-locale slugs in \`Product.translations[locale].slug\`.
|
|
2405
|
+
The API exposes them as \`product.localeSlugs\` \u2014 a flat \`Record<string, string>\`.
|
|
2406
|
+
|
|
2407
|
+
\`\`\`typescript
|
|
2408
|
+
// product.localeSlugs = { he: '\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4', en: 'yoga-mattress', ar: '\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627' }
|
|
2409
|
+
const locSlug = product.localeSlugs?.[locale] ?? product.slug;
|
|
2410
|
+
\`\`\`
|
|
2411
|
+
|
|
2412
|
+
Use AI translation (\`translateEntities\` / the AI Translate button in the admin) to populate
|
|
2413
|
+
locale-specific slugs automatically. Until translated, all locales fall back to the base slug
|
|
2414
|
+
(which Google still accepts \u2014 it resolves to the correct locale content via Accept-Language).
|
|
2415
|
+
|
|
2416
|
+
### hreflang tags
|
|
2417
|
+
|
|
2418
|
+
Every product page in a multi-locale store MUST emit bidirectional hreflang tags or Google
|
|
2419
|
+
ignores them entirely. The scaffolded template generates them automatically when
|
|
2420
|
+
\`NEXT_PUBLIC_BRAINERCE_LOCALES=he,en\` is set.
|
|
2421
|
+
|
|
2422
|
+
\`\`\`html
|
|
2423
|
+
<!-- Example output for /en/products/yoga-mattress -->
|
|
2424
|
+
<link rel="alternate" hreflang="he" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
|
|
2425
|
+
<link rel="alternate" hreflang="en" href="https://store.com/en/products/yoga-mattress" />
|
|
2426
|
+
<link rel="alternate" hreflang="x-default" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
|
|
2427
|
+
\`\`\`
|
|
2428
|
+
|
|
2429
|
+
If building a custom storefront, add to \`generateMetadata()\`:
|
|
2430
|
+
\`\`\`typescript
|
|
2431
|
+
alternates: {
|
|
2432
|
+
canonical: locale === defaultLoc ? \`/products/\${slug}\` : \`/\${locale}/products/\${slug}\`,
|
|
2433
|
+
languages: {
|
|
2434
|
+
he: \`\${baseUrl}/products/\${localeSlugs.he ?? baseSlug}\`,
|
|
2435
|
+
en: \`\${baseUrl}/en/products/\${localeSlugs.en ?? baseSlug}\`,
|
|
2436
|
+
'x-default': \`\${baseUrl}/products/\${localeSlugs[defaultLoc] ?? baseSlug}\`,
|
|
2437
|
+
},
|
|
2438
|
+
},
|
|
2439
|
+
\`\`\`
|
|
2440
|
+
|
|
2441
|
+
### URL structure
|
|
2442
|
+
|
|
2443
|
+
Google-recommended for headless storefronts:
|
|
2444
|
+
- Default locale: \`/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4\` (no prefix)
|
|
2445
|
+
- Other locales: \`/en/products/yoga-mattress\` (prefixed)
|
|
2446
|
+
- \u274C Never: \`?locale=he\` query params (Google rates these as "Not recommended")
|
|
2447
|
+
|
|
2448
|
+
### Sitemap
|
|
2449
|
+
|
|
2450
|
+
The scaffolded \`sitemap.ts\` generates per-locale entries automatically:
|
|
2451
|
+
\`\`\`
|
|
2452
|
+
/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4 (he \u2014 default, no prefix)
|
|
2453
|
+
/en/products/yoga-mattress (en)
|
|
2454
|
+
/ar/products/\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627 (ar)
|
|
2455
|
+
\`\`\`
|
|
2456
|
+
|
|
2457
|
+
Hebrew, Arabic, and other non-Latin slugs are fully supported \u2014 Google recommends
|
|
2458
|
+
using the audience's language in URLs and indexes non-ASCII characters correctly.`;
|
|
2459
|
+
}
|
|
2374
2460
|
function getAdminApiSection() {
|
|
2375
2461
|
return `## Admin API (v0.19.0+)
|
|
2376
2462
|
|
|
@@ -2454,6 +2540,20 @@ await admin.mergeTaxClasses(food.id, standardClassId);
|
|
|
2454
2540
|
Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreTaxClasses()\` lists
|
|
2455
2541
|
the store's classes (storefront-safe fields only) for a transparency badge.
|
|
2456
2542
|
|
|
2543
|
+
For a buyer-facing tax preview on PDP / PLP / cart, \`estimateTax({ country,
|
|
2544
|
+
subtotal })\` returns the tax portion at the Standard rate for the buyer's
|
|
2545
|
+
country. **Non-binding** \u2014 the authoritative tax still runs at checkout with
|
|
2546
|
+
the full shipping address (state / postal / per-class). Always render with an
|
|
2547
|
+
"Estimate" affordance.
|
|
2548
|
+
|
|
2549
|
+
\`\`\`typescript
|
|
2550
|
+
const { estimatedTax, rate, currency, note } = await store.estimateTax({
|
|
2551
|
+
country: 'IT', subtotal: 100,
|
|
2552
|
+
});
|
|
2553
|
+
// \u2192 { appliesTax: true, rate: 22, estimatedTax: 22, currency: 'EUR',
|
|
2554
|
+
// note: 'Estimate \u2014 final tax calculated at checkout\u2026' }
|
|
2555
|
+
\`\`\`
|
|
2556
|
+
|
|
2457
2557
|
### Regions (multi-currency / per-region providers)
|
|
2458
2558
|
|
|
2459
2559
|
A region binds countries \u2192 currency + tax-display mode + enabled payment
|
|
@@ -2484,6 +2584,19 @@ const { data: regions } = await store.getStoreRegions();
|
|
|
2484
2584
|
const region = await store.getStoreRegion(regions[0].id);
|
|
2485
2585
|
\`\`\`
|
|
2486
2586
|
|
|
2587
|
+
For a single round trip, \`getAutoRegion(country)\` resolves a buyer's country
|
|
2588
|
+
to a region server-side. Brainerce does NOT derive the country from the request
|
|
2589
|
+
IP (the storefront server is what reaches the backend, not the end-customer) \u2014
|
|
2590
|
+
your storefront extracts the country from its edge runtime (Cloudflare
|
|
2591
|
+
\`CF-IPCountry\`, Vercel \`request.geo?.country\`, Fastly \`client-geo-country\`,
|
|
2592
|
+
etc.) and forwards it. Returns \`matched=true\` on explicit country hit, \`false\`
|
|
2593
|
+
when falling back to the default region.
|
|
2594
|
+
|
|
2595
|
+
\`\`\`typescript
|
|
2596
|
+
const country = headers.get('cf-ipcountry') ?? 'US';
|
|
2597
|
+
const { region, matched } = await store.getAutoRegion(country);
|
|
2598
|
+
\`\`\`
|
|
2599
|
+
|
|
2487
2600
|
A shipping zone can be limited to regions via \`regionIds\` \u2014 the zone is then
|
|
2488
2601
|
only offered to checkouts that resolved to one of those regions. Empty/omitted =
|
|
2489
2602
|
available for any region (default); each id must belong to the same store.
|
|
@@ -2947,6 +3060,146 @@ entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'
|
|
|
2947
3060
|
- \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
|
|
2948
3061
|
interfaces.`;
|
|
2949
3062
|
}
|
|
3063
|
+
function getBlogSection() {
|
|
3064
|
+
return `## Blog
|
|
3065
|
+
|
|
3066
|
+
Merchants write and schedule blog posts in **Content \u2192 Blog** in the dashboard.
|
|
3067
|
+
Storefronts choose their own URL scheme \u2014 render posts at \`/blog/[slug]\`,
|
|
3068
|
+
\`/articles/[slug]\`, or whatever fits the brand.
|
|
3069
|
+
|
|
3070
|
+
Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
|
|
3071
|
+
|
|
3072
|
+
**Scheduling:** A post is visible once \`status === 'PUBLISHED'\` and
|
|
3073
|
+
\`publishedAt <= now()\`. Set a future \`publishedAt\` while publishing to
|
|
3074
|
+
schedule \u2014 no cron needed; visibility is computed at query time.
|
|
3075
|
+
|
|
3076
|
+
### Reading posts (any SDK mode)
|
|
3077
|
+
|
|
3078
|
+
\`\`\`typescript
|
|
3079
|
+
// List published posts
|
|
3080
|
+
const { data: posts, meta } = await client.blog.getPosts({ page: 1, limit: 10 });
|
|
3081
|
+
|
|
3082
|
+
// Filter by category or tag
|
|
3083
|
+
const { data: news } = await client.blog.getPosts({ category: 'news' });
|
|
3084
|
+
const { data: tips } = await client.blog.getPosts({ tag: 'tutorial' });
|
|
3085
|
+
|
|
3086
|
+
// Fetch one by slug (returns null on 404)
|
|
3087
|
+
const post = await client.blog.getPost('my-first-post');
|
|
3088
|
+
if (post) {
|
|
3089
|
+
console.log(post.title); // string
|
|
3090
|
+
console.log(post.content); // HTML string from rich-text editor
|
|
3091
|
+
console.log(post.excerpt); // optional short summary
|
|
3092
|
+
console.log(post.tags); // string[]
|
|
3093
|
+
console.log(post.coverImageUrl, post.coverImageAlt);
|
|
3094
|
+
console.log(post.publishedAt); // ISO 8601 or undefined
|
|
3095
|
+
}
|
|
3096
|
+
\`\`\`
|
|
3097
|
+
|
|
3098
|
+
### BlogPost fields
|
|
3099
|
+
|
|
3100
|
+
| Field | Type | Notes |
|
|
3101
|
+
| ----------------- | ----------- | ------------------------------------- |
|
|
3102
|
+
| \`id\` | string | |
|
|
3103
|
+
| \`title\` | string | |
|
|
3104
|
+
| \`slug\` | string | Unique per store, URL-safe |
|
|
3105
|
+
| \`category\` | string? | Free-form (e.g. \`'news'\`) |
|
|
3106
|
+
| \`content\` | string | HTML from rich-text editor |
|
|
3107
|
+
| \`excerpt\` | string? | Short summary for listing cards |
|
|
3108
|
+
| \`coverImageUrl\` | string? | |
|
|
3109
|
+
| \`coverImageAlt\` | string? | |
|
|
3110
|
+
| \`author\` | string? | |
|
|
3111
|
+
| \`tags\` | string[] | |
|
|
3112
|
+
| \`publishedAt\` | string? | ISO 8601; null = publish immediately |
|
|
3113
|
+
| \`seoTitle\` | string? | |
|
|
3114
|
+
| \`seoDescription\`| string? | |
|
|
3115
|
+
| \`ogImageUrl\` | string? | |
|
|
3116
|
+
|
|
3117
|
+
### Rendering blog content
|
|
3118
|
+
|
|
3119
|
+
\`\`\`tsx
|
|
3120
|
+
// app/blog/[slug]/page.tsx
|
|
3121
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
3122
|
+
|
|
3123
|
+
const post = await brainerce.blog.getPost(params.slug);
|
|
3124
|
+
if (!post) notFound();
|
|
3125
|
+
|
|
3126
|
+
// Always sanitize before rendering HTML \u2014 treat external-origin content as untrusted
|
|
3127
|
+
const safeHtml = DOMPurify.sanitize(post.content);
|
|
3128
|
+
return <div dangerouslySetInnerHTML={{ __html: safeHtml }} className="prose" />;
|
|
3129
|
+
\`\`\`
|
|
3130
|
+
|
|
3131
|
+
The \`content\` field is HTML produced by the Lexical rich-text editor.
|
|
3132
|
+
**Always sanitize with DOMPurify (or equivalent) before rendering via
|
|
3133
|
+
\`dangerouslySetInnerHTML\`** \u2014 even though the content originates from your
|
|
3134
|
+
own editor, defense-in-depth prevents any stored-XSS path if content is ever
|
|
3135
|
+
migrated or imported from an external source.
|
|
3136
|
+
Apply a \`prose\` class (Tailwind Typography) for automatic styling.
|
|
3137
|
+
|
|
3138
|
+
### REST endpoints
|
|
3139
|
+
|
|
3140
|
+
| Method | Path | Returns |
|
|
3141
|
+
|--------|------|---------|
|
|
3142
|
+
| GET | \`/api/stores/:storeId/blog/posts\` | \`BlogPostListResponse\` |
|
|
3143
|
+
| GET | \`/api/stores/:storeId/blog/posts/:slug\` | \`BlogPost\` or 404 |
|
|
3144
|
+
| GET | \`/api/vc/:connectionId/blog/posts\` | Same, channel-scoped |
|
|
3145
|
+
| GET | \`/api/vc/:connectionId/blog/posts/:slug\` | \`BlogPost\` or 404 |
|
|
3146
|
+
`;
|
|
3147
|
+
}
|
|
3148
|
+
function getStorefrontBotSection(connectionId) {
|
|
3149
|
+
return `## Storefront Bot (AI chat widget)
|
|
3150
|
+
|
|
3151
|
+
The store's AI shopping assistant. ALL configuration (name, avatar, colors,
|
|
3152
|
+
greeting, starter questions, capabilities, guardrails) lives in the merchant
|
|
3153
|
+
dashboard \u2014 the embed never decides behavior, and the widget renders nothing
|
|
3154
|
+
until the merchant switches the bot Live.
|
|
3155
|
+
|
|
3156
|
+
### Zero-code embed (any site)
|
|
3157
|
+
|
|
3158
|
+
\`\`\`html
|
|
3159
|
+
<script src="https://cdn.brainerce.com/bot.js" data-connection-id="${connectionId}" defer></script>
|
|
3160
|
+
\`\`\`
|
|
3161
|
+
|
|
3162
|
+
Keep the tag exactly this bare \u2014 do NOT add \`integrity\` or \`crossorigin\`
|
|
3163
|
+
(the bootstrap is intentionally mutable; it is origin-pinned by CSP instead).
|
|
3164
|
+
|
|
3165
|
+
### SDK mount (React / Next.js / any bundler)
|
|
3166
|
+
|
|
3167
|
+
\`\`\`ts
|
|
3168
|
+
import { BrainerceBot } from 'brainerce/bot';
|
|
3169
|
+
|
|
3170
|
+
// client-side only (e.g. in a useEffect) \u2014 mounts a floating chat bubble
|
|
3171
|
+
const bot = await BrainerceBot.mount({ connectionId: '${connectionId}' });
|
|
3172
|
+
bot?.destroy(); // optional teardown
|
|
3173
|
+
\`\`\`
|
|
3174
|
+
|
|
3175
|
+
\`mount\` resolves to \`null\` when the bot is disabled (FREE plan, switched
|
|
3176
|
+
off, or unconfigured) \u2014 safe to call unconditionally. Options: \`connectionId\`
|
|
3177
|
+
(required), \`baseUrl\` (API origin override), \`target\` (mount element),
|
|
3178
|
+
\`onAddToCart\` (\`({ productId, variantId, quantity }) => boolean | Promise<boolean>\`
|
|
3179
|
+
\u2014 route the widget's cart adds through the site's own cart; \`variantId\` is
|
|
3180
|
+
null for simple products; return false to fall back to the product page).
|
|
3181
|
+
|
|
3182
|
+
Behavior: persists an anonymous session in localStorage, restores the
|
|
3183
|
+
conversation on revisit, streams answers, and shows product recommendation
|
|
3184
|
+
cards (image, price, add-to-cart / view). Multi-variant products get an
|
|
3185
|
+
in-card variant picker; shoppers can also ask the assistant to add an item
|
|
3186
|
+
and it goes through the same cart chain. Zero-result searches feed the
|
|
3187
|
+
merchant's "unmet demand" analytics. Aside from shopper-initiated cart adds,
|
|
3188
|
+
the bot is read-only.
|
|
3189
|
+
|
|
3190
|
+
Add-to-cart resolution chain: \`onAddToCart\` option \u2192 cancelable
|
|
3191
|
+
\`brainerce:bot:add-to-cart\` CustomEvent on window
|
|
3192
|
+
(\`detail: { productId, variantId, quantity, connectionId }\`; call
|
|
3193
|
+
preventDefault() after handling) \u2192 navigate to the product page.
|
|
3194
|
+
|
|
3195
|
+
Rules:
|
|
3196
|
+
- Mount once per page; do not pass any visual config \u2014 the dashboard owns it.
|
|
3197
|
+
- Do not wrap or restyle the widget; it renders in its own Shadow DOM.
|
|
3198
|
+
- Product card links expect the conventional \`/products/<slug>\` route.
|
|
3199
|
+
- Wire \`onAddToCart\` to the site's cart (see the cart section) so the header
|
|
3200
|
+
count updates when the bot adds items.
|
|
3201
|
+
`;
|
|
3202
|
+
}
|
|
2950
3203
|
function getSectionByTopic(topic, connectionId, currency) {
|
|
2951
3204
|
const cid = connectionId || "vc_YOUR_CONNECTION_ID";
|
|
2952
3205
|
const cur = currency || "USD";
|
|
@@ -2985,6 +3238,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2985
3238
|
return getTaxDisplaySection(cur);
|
|
2986
3239
|
case "i18n":
|
|
2987
3240
|
return getI18nSection();
|
|
3241
|
+
case "multilingual-seo":
|
|
3242
|
+
case "hreflang":
|
|
3243
|
+
case "seo-i18n":
|
|
3244
|
+
return getMultilingualSeoSection();
|
|
2988
3245
|
case "critical-rules":
|
|
2989
3246
|
return getCriticalRulesSection() + "\n\n" + getTypeQuickReference();
|
|
2990
3247
|
case "type-reference":
|
|
@@ -2995,6 +3252,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2995
3252
|
return getContactInquiriesSection();
|
|
2996
3253
|
case "content":
|
|
2997
3254
|
return getContentSection();
|
|
3255
|
+
case "blog":
|
|
3256
|
+
return getBlogSection();
|
|
3257
|
+
case "storefront-bot":
|
|
3258
|
+
return getStorefrontBotSection(cid);
|
|
2998
3259
|
case "all":
|
|
2999
3260
|
return [
|
|
3000
3261
|
"# Brainerce SDK \u2014 full topic dump",
|
|
@@ -3079,6 +3340,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
3079
3340
|
"",
|
|
3080
3341
|
"---",
|
|
3081
3342
|
"",
|
|
3343
|
+
getMultilingualSeoSection(),
|
|
3344
|
+
"",
|
|
3345
|
+
"---",
|
|
3346
|
+
"",
|
|
3082
3347
|
getAdminApiSection(),
|
|
3083
3348
|
"",
|
|
3084
3349
|
"---",
|
|
@@ -3087,10 +3352,18 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
3087
3352
|
"",
|
|
3088
3353
|
"---",
|
|
3089
3354
|
"",
|
|
3090
|
-
getContentSection()
|
|
3355
|
+
getContentSection(),
|
|
3356
|
+
"",
|
|
3357
|
+
"---",
|
|
3358
|
+
"",
|
|
3359
|
+
getBlogSection(),
|
|
3360
|
+
"",
|
|
3361
|
+
"---",
|
|
3362
|
+
"",
|
|
3363
|
+
getStorefrontBotSection(cid)
|
|
3091
3364
|
].join("\n");
|
|
3092
3365
|
default:
|
|
3093
|
-
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`;
|
|
3366
|
+
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`;
|
|
3094
3367
|
}
|
|
3095
3368
|
}
|
|
3096
3369
|
|
|
@@ -3119,6 +3392,7 @@ var GET_SDK_DOCS_SCHEMA = {
|
|
|
3119
3392
|
"admin",
|
|
3120
3393
|
"inquiries",
|
|
3121
3394
|
"content",
|
|
3395
|
+
"storefront-bot",
|
|
3122
3396
|
"all"
|
|
3123
3397
|
]).describe("The SDK documentation topic to retrieve"),
|
|
3124
3398
|
salesChannelId: import_zod.z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
|
|
@@ -3156,6 +3430,12 @@ interface Product {
|
|
|
3156
3430
|
priceMin?: string | null; // Lowest variant price (VARIABLE products) \u2014 same as basePrice for VARIABLE, kept for back-compat and JSON-LD range display.
|
|
3157
3431
|
priceMax?: string | null; // Highest variant price (VARIABLE products). Use with priceMin for "\u20AA49 \u2013 \u20AA199" range.
|
|
3158
3432
|
priceVaries?: boolean; // true when variant prices differ \u2014 show "\u20AA49 \u2013 \u20AA199" range.
|
|
3433
|
+
// 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.
|
|
3434
|
+
displayPrice?: string; // basePrice \xD7 daily FX rate, in displayCurrency.
|
|
3435
|
+
displaySalePrice?: string; // salePrice \xD7 rate (if salePrice present).
|
|
3436
|
+
displayPriceMin?: string; // priceMin \xD7 rate (VARIABLE products).
|
|
3437
|
+
displayPriceMax?: string; // priceMax \xD7 rate (VARIABLE products).
|
|
3438
|
+
displayCurrency?: string; // ISO 4217 of the region \u2014 e.g. "EUR".
|
|
3159
3439
|
status: string;
|
|
3160
3440
|
type: 'SIMPLE' | 'VARIABLE';
|
|
3161
3441
|
isDownloadable?: boolean;
|
|
@@ -3199,6 +3479,10 @@ interface ProductVariant {
|
|
|
3199
3479
|
name?: string | null;
|
|
3200
3480
|
price?: string | null;
|
|
3201
3481
|
salePrice?: string | null;
|
|
3482
|
+
// FX DISPLAY overlay (PRD \xA723) \u2014 same semantics as on the parent Product.
|
|
3483
|
+
displayPrice?: string;
|
|
3484
|
+
displaySalePrice?: string;
|
|
3485
|
+
displayCurrency?: string;
|
|
3202
3486
|
attributes?: Record<string, string> | null;
|
|
3203
3487
|
options?: Array<{ name: string; value: string }>;
|
|
3204
3488
|
inventory?: InventoryInfo | null;
|
|
@@ -3511,6 +3795,8 @@ interface Order {
|
|
|
3511
3795
|
totalAmount: string; // ALWAYS use this, not .total
|
|
3512
3796
|
total?: string; // optional alias
|
|
3513
3797
|
currency?: string;
|
|
3798
|
+
taxAmount?: string | null; // 0 in inclusive (VAT) mode \u2014 read taxBreakdown.totalTax
|
|
3799
|
+
taxBreakdown?: TaxBreakdown | null; // carries the included VAT when prices include tax
|
|
3514
3800
|
customer?: OrderCustomer | null;
|
|
3515
3801
|
items: OrderItem[];
|
|
3516
3802
|
itemCount?: number;
|
|
@@ -4328,6 +4614,15 @@ interface PublicRegionDetail extends PublicRegion {
|
|
|
4328
4614
|
}
|
|
4329
4615
|
// getStoreRegions(): { data: PublicRegion[] } \u2014 active regions, default first.
|
|
4330
4616
|
// getStoreRegion(regionId): PublicRegionDetail \u2014 one region + its providers.
|
|
4617
|
+
interface AutoRegionResponse {
|
|
4618
|
+
region: PublicRegion | null;
|
|
4619
|
+
matched: boolean; // true=country was in a region's list; false=fell back to default
|
|
4620
|
+
country: string; // upper-cased ISO-3166-1 alpha-2; '' when caller omitted it
|
|
4621
|
+
}
|
|
4622
|
+
// getAutoRegion(country): AutoRegionResponse \u2014 server-side resolution in one
|
|
4623
|
+
// round trip. Pair with the country your edge runtime extracts
|
|
4624
|
+
// (CF-IPCountry / request.geo.country / etc.) \u2014 Brainerce does NOT derive the
|
|
4625
|
+
// country from the request IP server-side (storefront != end-customer).
|
|
4331
4626
|
|
|
4332
4627
|
// ---- Tax Classes ---- (scopes: tax-classes:read / tax-classes:write)
|
|
4333
4628
|
// Charge differential rates by product type. A TaxRate may target a class via
|
|
@@ -4359,7 +4654,25 @@ interface AssignTaxClassDto { productIds?: string[]; variantIds?: string[]; cate
|
|
|
4359
4654
|
// getRegionCompatibleProviders(id), detectRegion(country, regions)
|
|
4360
4655
|
// Tax classes: getTaxClasses(), getTaxClass(id), createTaxClass(dto), updateTaxClass(id, dto),
|
|
4361
4656
|
// deleteTaxClass(id), setDefaultTaxClass(id), assignTaxClass(id, dto),
|
|
4362
|
-
// mergeTaxClasses(id, targetId)
|
|
4657
|
+
// mergeTaxClasses(id, targetId)
|
|
4658
|
+
//
|
|
4659
|
+
// SDK methods (storefront, public \u2014 storeId mode, no apiKey):
|
|
4660
|
+
// getStoreRegions(), getStoreRegion(id), getAutoRegion(country)
|
|
4661
|
+
// getStoreTaxClasses(), estimateTax({ country?, subtotal })
|
|
4662
|
+
//
|
|
4663
|
+
// estimateTax returns:
|
|
4664
|
+
interface TaxEstimateResponse {
|
|
4665
|
+
appliesTax: boolean;
|
|
4666
|
+
rate: number | null; // percent (18 = 18%) \u2014 null when no matching rule
|
|
4667
|
+
rateName: string | null;
|
|
4668
|
+
estimatedTax: number; // tax portion of subtotal in store currency
|
|
4669
|
+
pricesIncludeTax: boolean;
|
|
4670
|
+
currency: string; // store currency (cart/order currency)
|
|
4671
|
+
note: string; // disclaimer \u2014 preview is non-binding
|
|
4672
|
+
}
|
|
4673
|
+
// Non-binding by design: the authoritative tax runs at checkout against the
|
|
4674
|
+
// full shipping address. The country comes from your edge runtime
|
|
4675
|
+
// (CF-IPCountry / request.geo.country / etc.), NOT the request IP.`;
|
|
4363
4676
|
var TYPES_BY_DOMAIN = {
|
|
4364
4677
|
products: PRODUCTS_TYPES,
|
|
4365
4678
|
cart: CART_TYPES,
|