@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/index.js
CHANGED
|
@@ -186,7 +186,26 @@ import {
|
|
|
186
186
|
getDescriptionContent, isHtmlDescription,
|
|
187
187
|
getProductMetafieldValue, getProductCustomizationFields,
|
|
188
188
|
} from 'brainerce';
|
|
189
|
-
|
|
189
|
+
\`\`\`
|
|
190
|
+
|
|
191
|
+
### Available features \u2014 request each topic for full docs
|
|
192
|
+
|
|
193
|
+
| Topic | What it covers |
|
|
194
|
+
|-------|----------------|
|
|
195
|
+
| \`products\` | Catalog listing, search, PDP, variants, swatches, stock, attributes |
|
|
196
|
+
| \`cart\` | Guest + logged-in cart, add/remove/update, reservations |
|
|
197
|
+
| \`checkout\` | Guest + customer checkout, shipping, address |
|
|
198
|
+
| \`payment\` | Payment providers, intents, status polling, confirmation |
|
|
199
|
+
| \`auth\` | Customer sign-up, login, OAuth, email verification |
|
|
200
|
+
| \`discounts\` | Coupons, banners, nudges |
|
|
201
|
+
| \`recommendations\` | Cross-sell / upsell grids |
|
|
202
|
+
| \`reviews\` | Product reviews & ratings |
|
|
203
|
+
| \`inventory\` | Stock badges, reservation countdown |
|
|
204
|
+
| \`inquiries\` | Contact / custom forms |
|
|
205
|
+
| \`i18n\` | Multi-language, RTL |
|
|
206
|
+
| \`admin\` | Server-to-server admin API (products, orders, customers) |
|
|
207
|
+
| \`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. |
|
|
208
|
+
| \`content\` | Blog, articles, static pages |`;
|
|
190
209
|
}
|
|
191
210
|
function getCheckoutFlowSection(_currency) {
|
|
192
211
|
return `## \u26A0\uFE0F CHECKOUT FLOW (CRITICAL \u2014 READ CAREFULLY!)
|
|
@@ -735,7 +754,7 @@ const growProvider = providers.find(p => p.provider === 'grow');
|
|
|
735
754
|
const paypalProvider = providers.find(p => p.provider === 'paypal');
|
|
736
755
|
\`\`\`
|
|
737
756
|
|
|
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\`.
|
|
757
|
+
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
758
|
|
|
740
759
|
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
760
|
|
|
@@ -1908,8 +1927,8 @@ function getTaxDisplaySection(_currency) {
|
|
|
1908
1927
|
| Product Page | \u274C No | "Price excludes tax" (optional note) |
|
|
1909
1928
|
| Cart Page | \u26A0\uFE0F "Calculated at checkout" | No address yet |
|
|
1910
1929
|
| Checkout (before address) | \u26A0\uFE0F "Enter address to calculate" | Waiting for location |
|
|
1911
|
-
| Checkout (after address) | \u2705 **REQUIRED** | \`checkout.taxAmount\` |
|
|
1912
|
-
| Order Confirmation | \u2705 **REQUIRED** | \`order.taxAmount\` |
|
|
1930
|
+
| Checkout (after address) | \u2705 **REQUIRED** | \`checkout.taxAmount\` (0 in VAT mode \u2192 \`checkout.taxBreakdown.totalTax\`) |
|
|
1931
|
+
| Order Confirmation | \u2705 **REQUIRED** | \`order.taxAmount\` (0 in VAT mode \u2192 \`order.taxBreakdown.totalTax\`) |
|
|
1913
1932
|
|
|
1914
1933
|
### Cart Page \u2014 Partial Display
|
|
1915
1934
|
|
|
@@ -1961,7 +1980,13 @@ const totals = getCartTotals(cart);
|
|
|
1961
1980
|
<div className="flex justify-between text-green-600"><span>Discount</span><span>-{formatPrice(order.discountAmount, { currency: order.currency })}</span></div>
|
|
1962
1981
|
)}
|
|
1963
1982
|
<div className="flex justify-between"><span>Shipping</span><span>{formatPrice(order.shippingAmount, { currency: order.currency })}</span></div>
|
|
1964
|
-
|
|
1983
|
+
{/* Inclusive (VAT) stores keep taxAmount="0" \u2014 the real VAT is on taxBreakdown.totalTax. */}
|
|
1984
|
+
{(() => {
|
|
1985
|
+
const tax = parseFloat(order.taxAmount || '0') || order.taxBreakdown?.totalTax || 0;
|
|
1986
|
+
if (tax <= 0) return null;
|
|
1987
|
+
const incl = order.taxBreakdown?.pricesIncludeTax;
|
|
1988
|
+
return <div className="flex justify-between"><span>{incl ? 'Tax (incl.)' : 'Tax'}</span><span>{formatPrice(tax, { currency: order.currency })}</span></div>;
|
|
1989
|
+
})()}
|
|
1965
1990
|
<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>
|
|
1966
1991
|
</div>
|
|
1967
1992
|
\`\`\``;
|
|
@@ -2090,7 +2115,7 @@ A useful order card includes ALL of the following when the data is present. Each
|
|
|
2090
2115
|
| **Tracking** | \`order.trackingNumber\`, \`order.trackingUrl\`, \`order.carrier\`, \`order.shippedAt\`, \`order.deliveredAt\` | Link out to \`trackingUrl\` when set. |
|
|
2091
2116
|
| **Payment** | \`order.paymentMethod\`, \`order.financialStatus\` | Badge \`financialStatus\` (paid / pending / refunded / partially_refunded). |
|
|
2092
2117
|
| Downloads | \`order.hasDownloads\` \u2192 \`client.getOrderDownloads(id)\` | Separate call; returns \`OrderDownloadLink[]\`. |
|
|
2093
|
-
| Financial summary | \`order.subtotal\`, \`order.appliedDiscounts\`, \`order.couponCode\` + \`couponDiscount\`, \`order.shippingAmount\`, \`order.taxAmount\`, \`order.totalAmount\` | Breakdown rows + final total. |
|
|
2118
|
+
| 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.)". |
|
|
2094
2119
|
|
|
2095
2120
|
#### Rendering \`order.items[i].customizations\` by type
|
|
2096
2121
|
|
|
@@ -2394,6 +2419,67 @@ Read \`storeInfo.i18n.supportedLocales\` and render a switcher in the header
|
|
|
2394
2419
|
that navigates to \`/{otherLocale}/{currentPathWithoutLocale}\`. The middleware
|
|
2395
2420
|
handles the canonical redirect when the user picks the default locale.`;
|
|
2396
2421
|
}
|
|
2422
|
+
function getMultilingualSeoSection() {
|
|
2423
|
+
return `## Multilingual SEO
|
|
2424
|
+
|
|
2425
|
+
### Slugs per locale (IMPORTANT)
|
|
2426
|
+
|
|
2427
|
+
Brainerce stores per-locale slugs in \`Product.translations[locale].slug\`.
|
|
2428
|
+
The API exposes them as \`product.localeSlugs\` \u2014 a flat \`Record<string, string>\`.
|
|
2429
|
+
|
|
2430
|
+
\`\`\`typescript
|
|
2431
|
+
// product.localeSlugs = { he: '\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4', en: 'yoga-mattress', ar: '\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627' }
|
|
2432
|
+
const locSlug = product.localeSlugs?.[locale] ?? product.slug;
|
|
2433
|
+
\`\`\`
|
|
2434
|
+
|
|
2435
|
+
Use AI translation (\`translateEntities\` / the AI Translate button in the admin) to populate
|
|
2436
|
+
locale-specific slugs automatically. Until translated, all locales fall back to the base slug
|
|
2437
|
+
(which Google still accepts \u2014 it resolves to the correct locale content via Accept-Language).
|
|
2438
|
+
|
|
2439
|
+
### hreflang tags
|
|
2440
|
+
|
|
2441
|
+
Every product page in a multi-locale store MUST emit bidirectional hreflang tags or Google
|
|
2442
|
+
ignores them entirely. The scaffolded template generates them automatically when
|
|
2443
|
+
\`NEXT_PUBLIC_BRAINERCE_LOCALES=he,en\` is set.
|
|
2444
|
+
|
|
2445
|
+
\`\`\`html
|
|
2446
|
+
<!-- Example output for /en/products/yoga-mattress -->
|
|
2447
|
+
<link rel="alternate" hreflang="he" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
|
|
2448
|
+
<link rel="alternate" hreflang="en" href="https://store.com/en/products/yoga-mattress" />
|
|
2449
|
+
<link rel="alternate" hreflang="x-default" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
|
|
2450
|
+
\`\`\`
|
|
2451
|
+
|
|
2452
|
+
If building a custom storefront, add to \`generateMetadata()\`:
|
|
2453
|
+
\`\`\`typescript
|
|
2454
|
+
alternates: {
|
|
2455
|
+
canonical: locale === defaultLoc ? \`/products/\${slug}\` : \`/\${locale}/products/\${slug}\`,
|
|
2456
|
+
languages: {
|
|
2457
|
+
he: \`\${baseUrl}/products/\${localeSlugs.he ?? baseSlug}\`,
|
|
2458
|
+
en: \`\${baseUrl}/en/products/\${localeSlugs.en ?? baseSlug}\`,
|
|
2459
|
+
'x-default': \`\${baseUrl}/products/\${localeSlugs[defaultLoc] ?? baseSlug}\`,
|
|
2460
|
+
},
|
|
2461
|
+
},
|
|
2462
|
+
\`\`\`
|
|
2463
|
+
|
|
2464
|
+
### URL structure
|
|
2465
|
+
|
|
2466
|
+
Google-recommended for headless storefronts:
|
|
2467
|
+
- Default locale: \`/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4\` (no prefix)
|
|
2468
|
+
- Other locales: \`/en/products/yoga-mattress\` (prefixed)
|
|
2469
|
+
- \u274C Never: \`?locale=he\` query params (Google rates these as "Not recommended")
|
|
2470
|
+
|
|
2471
|
+
### Sitemap
|
|
2472
|
+
|
|
2473
|
+
The scaffolded \`sitemap.ts\` generates per-locale entries automatically:
|
|
2474
|
+
\`\`\`
|
|
2475
|
+
/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4 (he \u2014 default, no prefix)
|
|
2476
|
+
/en/products/yoga-mattress (en)
|
|
2477
|
+
/ar/products/\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627 (ar)
|
|
2478
|
+
\`\`\`
|
|
2479
|
+
|
|
2480
|
+
Hebrew, Arabic, and other non-Latin slugs are fully supported \u2014 Google recommends
|
|
2481
|
+
using the audience's language in URLs and indexes non-ASCII characters correctly.`;
|
|
2482
|
+
}
|
|
2397
2483
|
function getAdminApiSection() {
|
|
2398
2484
|
return `## Admin API (v0.19.0+)
|
|
2399
2485
|
|
|
@@ -2477,6 +2563,20 @@ await admin.mergeTaxClasses(food.id, standardClassId);
|
|
|
2477
2563
|
Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreTaxClasses()\` lists
|
|
2478
2564
|
the store's classes (storefront-safe fields only) for a transparency badge.
|
|
2479
2565
|
|
|
2566
|
+
For a buyer-facing tax preview on PDP / PLP / cart, \`estimateTax({ country,
|
|
2567
|
+
subtotal })\` returns the tax portion at the Standard rate for the buyer's
|
|
2568
|
+
country. **Non-binding** \u2014 the authoritative tax still runs at checkout with
|
|
2569
|
+
the full shipping address (state / postal / per-class). Always render with an
|
|
2570
|
+
"Estimate" affordance.
|
|
2571
|
+
|
|
2572
|
+
\`\`\`typescript
|
|
2573
|
+
const { estimatedTax, rate, currency, note } = await store.estimateTax({
|
|
2574
|
+
country: 'IT', subtotal: 100,
|
|
2575
|
+
});
|
|
2576
|
+
// \u2192 { appliesTax: true, rate: 22, estimatedTax: 22, currency: 'EUR',
|
|
2577
|
+
// note: 'Estimate \u2014 final tax calculated at checkout\u2026' }
|
|
2578
|
+
\`\`\`
|
|
2579
|
+
|
|
2480
2580
|
### Regions (multi-currency / per-region providers)
|
|
2481
2581
|
|
|
2482
2582
|
A region binds countries \u2192 currency + tax-display mode + enabled payment
|
|
@@ -2507,6 +2607,19 @@ const { data: regions } = await store.getStoreRegions();
|
|
|
2507
2607
|
const region = await store.getStoreRegion(regions[0].id);
|
|
2508
2608
|
\`\`\`
|
|
2509
2609
|
|
|
2610
|
+
For a single round trip, \`getAutoRegion(country)\` resolves a buyer's country
|
|
2611
|
+
to a region server-side. Brainerce does NOT derive the country from the request
|
|
2612
|
+
IP (the storefront server is what reaches the backend, not the end-customer) \u2014
|
|
2613
|
+
your storefront extracts the country from its edge runtime (Cloudflare
|
|
2614
|
+
\`CF-IPCountry\`, Vercel \`request.geo?.country\`, Fastly \`client-geo-country\`,
|
|
2615
|
+
etc.) and forwards it. Returns \`matched=true\` on explicit country hit, \`false\`
|
|
2616
|
+
when falling back to the default region.
|
|
2617
|
+
|
|
2618
|
+
\`\`\`typescript
|
|
2619
|
+
const country = headers.get('cf-ipcountry') ?? 'US';
|
|
2620
|
+
const { region, matched } = await store.getAutoRegion(country);
|
|
2621
|
+
\`\`\`
|
|
2622
|
+
|
|
2510
2623
|
A shipping zone can be limited to regions via \`regionIds\` \u2014 the zone is then
|
|
2511
2624
|
only offered to checkouts that resolved to one of those regions. Empty/omitted =
|
|
2512
2625
|
available for any region (default); each id must belong to the same store.
|
|
@@ -2970,6 +3083,146 @@ entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'
|
|
|
2970
3083
|
- \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
|
|
2971
3084
|
interfaces.`;
|
|
2972
3085
|
}
|
|
3086
|
+
function getBlogSection() {
|
|
3087
|
+
return `## Blog
|
|
3088
|
+
|
|
3089
|
+
Merchants write and schedule blog posts in **Content \u2192 Blog** in the dashboard.
|
|
3090
|
+
Storefronts choose their own URL scheme \u2014 render posts at \`/blog/[slug]\`,
|
|
3091
|
+
\`/articles/[slug]\`, or whatever fits the brand.
|
|
3092
|
+
|
|
3093
|
+
Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
|
|
3094
|
+
|
|
3095
|
+
**Scheduling:** A post is visible once \`status === 'PUBLISHED'\` and
|
|
3096
|
+
\`publishedAt <= now()\`. Set a future \`publishedAt\` while publishing to
|
|
3097
|
+
schedule \u2014 no cron needed; visibility is computed at query time.
|
|
3098
|
+
|
|
3099
|
+
### Reading posts (any SDK mode)
|
|
3100
|
+
|
|
3101
|
+
\`\`\`typescript
|
|
3102
|
+
// List published posts
|
|
3103
|
+
const { data: posts, meta } = await client.blog.getPosts({ page: 1, limit: 10 });
|
|
3104
|
+
|
|
3105
|
+
// Filter by category or tag
|
|
3106
|
+
const { data: news } = await client.blog.getPosts({ category: 'news' });
|
|
3107
|
+
const { data: tips } = await client.blog.getPosts({ tag: 'tutorial' });
|
|
3108
|
+
|
|
3109
|
+
// Fetch one by slug (returns null on 404)
|
|
3110
|
+
const post = await client.blog.getPost('my-first-post');
|
|
3111
|
+
if (post) {
|
|
3112
|
+
console.log(post.title); // string
|
|
3113
|
+
console.log(post.content); // HTML string from rich-text editor
|
|
3114
|
+
console.log(post.excerpt); // optional short summary
|
|
3115
|
+
console.log(post.tags); // string[]
|
|
3116
|
+
console.log(post.coverImageUrl, post.coverImageAlt);
|
|
3117
|
+
console.log(post.publishedAt); // ISO 8601 or undefined
|
|
3118
|
+
}
|
|
3119
|
+
\`\`\`
|
|
3120
|
+
|
|
3121
|
+
### BlogPost fields
|
|
3122
|
+
|
|
3123
|
+
| Field | Type | Notes |
|
|
3124
|
+
| ----------------- | ----------- | ------------------------------------- |
|
|
3125
|
+
| \`id\` | string | |
|
|
3126
|
+
| \`title\` | string | |
|
|
3127
|
+
| \`slug\` | string | Unique per store, URL-safe |
|
|
3128
|
+
| \`category\` | string? | Free-form (e.g. \`'news'\`) |
|
|
3129
|
+
| \`content\` | string | HTML from rich-text editor |
|
|
3130
|
+
| \`excerpt\` | string? | Short summary for listing cards |
|
|
3131
|
+
| \`coverImageUrl\` | string? | |
|
|
3132
|
+
| \`coverImageAlt\` | string? | |
|
|
3133
|
+
| \`author\` | string? | |
|
|
3134
|
+
| \`tags\` | string[] | |
|
|
3135
|
+
| \`publishedAt\` | string? | ISO 8601; null = publish immediately |
|
|
3136
|
+
| \`seoTitle\` | string? | |
|
|
3137
|
+
| \`seoDescription\`| string? | |
|
|
3138
|
+
| \`ogImageUrl\` | string? | |
|
|
3139
|
+
|
|
3140
|
+
### Rendering blog content
|
|
3141
|
+
|
|
3142
|
+
\`\`\`tsx
|
|
3143
|
+
// app/blog/[slug]/page.tsx
|
|
3144
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
3145
|
+
|
|
3146
|
+
const post = await brainerce.blog.getPost(params.slug);
|
|
3147
|
+
if (!post) notFound();
|
|
3148
|
+
|
|
3149
|
+
// Always sanitize before rendering HTML \u2014 treat external-origin content as untrusted
|
|
3150
|
+
const safeHtml = DOMPurify.sanitize(post.content);
|
|
3151
|
+
return <div dangerouslySetInnerHTML={{ __html: safeHtml }} className="prose" />;
|
|
3152
|
+
\`\`\`
|
|
3153
|
+
|
|
3154
|
+
The \`content\` field is HTML produced by the Lexical rich-text editor.
|
|
3155
|
+
**Always sanitize with DOMPurify (or equivalent) before rendering via
|
|
3156
|
+
\`dangerouslySetInnerHTML\`** \u2014 even though the content originates from your
|
|
3157
|
+
own editor, defense-in-depth prevents any stored-XSS path if content is ever
|
|
3158
|
+
migrated or imported from an external source.
|
|
3159
|
+
Apply a \`prose\` class (Tailwind Typography) for automatic styling.
|
|
3160
|
+
|
|
3161
|
+
### REST endpoints
|
|
3162
|
+
|
|
3163
|
+
| Method | Path | Returns |
|
|
3164
|
+
|--------|------|---------|
|
|
3165
|
+
| GET | \`/api/stores/:storeId/blog/posts\` | \`BlogPostListResponse\` |
|
|
3166
|
+
| GET | \`/api/stores/:storeId/blog/posts/:slug\` | \`BlogPost\` or 404 |
|
|
3167
|
+
| GET | \`/api/vc/:connectionId/blog/posts\` | Same, channel-scoped |
|
|
3168
|
+
| GET | \`/api/vc/:connectionId/blog/posts/:slug\` | \`BlogPost\` or 404 |
|
|
3169
|
+
`;
|
|
3170
|
+
}
|
|
3171
|
+
function getStorefrontBotSection(connectionId) {
|
|
3172
|
+
return `## Storefront Bot (AI chat widget)
|
|
3173
|
+
|
|
3174
|
+
The store's AI shopping assistant. ALL configuration (name, avatar, colors,
|
|
3175
|
+
greeting, starter questions, capabilities, guardrails) lives in the merchant
|
|
3176
|
+
dashboard \u2014 the embed never decides behavior, and the widget renders nothing
|
|
3177
|
+
until the merchant switches the bot Live.
|
|
3178
|
+
|
|
3179
|
+
### Zero-code embed (any site)
|
|
3180
|
+
|
|
3181
|
+
\`\`\`html
|
|
3182
|
+
<script src="https://cdn.brainerce.com/bot.js" data-connection-id="${connectionId}" defer></script>
|
|
3183
|
+
\`\`\`
|
|
3184
|
+
|
|
3185
|
+
Keep the tag exactly this bare \u2014 do NOT add \`integrity\` or \`crossorigin\`
|
|
3186
|
+
(the bootstrap is intentionally mutable; it is origin-pinned by CSP instead).
|
|
3187
|
+
|
|
3188
|
+
### SDK mount (React / Next.js / any bundler)
|
|
3189
|
+
|
|
3190
|
+
\`\`\`ts
|
|
3191
|
+
import { BrainerceBot } from 'brainerce/bot';
|
|
3192
|
+
|
|
3193
|
+
// client-side only (e.g. in a useEffect) \u2014 mounts a floating chat bubble
|
|
3194
|
+
const bot = await BrainerceBot.mount({ connectionId: '${connectionId}' });
|
|
3195
|
+
bot?.destroy(); // optional teardown
|
|
3196
|
+
\`\`\`
|
|
3197
|
+
|
|
3198
|
+
\`mount\` resolves to \`null\` when the bot is disabled (FREE plan, switched
|
|
3199
|
+
off, or unconfigured) \u2014 safe to call unconditionally. Options: \`connectionId\`
|
|
3200
|
+
(required), \`baseUrl\` (API origin override), \`target\` (mount element),
|
|
3201
|
+
\`onAddToCart\` (\`({ productId, variantId, quantity }) => boolean | Promise<boolean>\`
|
|
3202
|
+
\u2014 route the widget's cart adds through the site's own cart; \`variantId\` is
|
|
3203
|
+
null for simple products; return false to fall back to the product page).
|
|
3204
|
+
|
|
3205
|
+
Behavior: persists an anonymous session in localStorage, restores the
|
|
3206
|
+
conversation on revisit, streams answers, and shows product recommendation
|
|
3207
|
+
cards (image, price, add-to-cart / view). Multi-variant products get an
|
|
3208
|
+
in-card variant picker; shoppers can also ask the assistant to add an item
|
|
3209
|
+
and it goes through the same cart chain. Zero-result searches feed the
|
|
3210
|
+
merchant's "unmet demand" analytics. Aside from shopper-initiated cart adds,
|
|
3211
|
+
the bot is read-only.
|
|
3212
|
+
|
|
3213
|
+
Add-to-cart resolution chain: \`onAddToCart\` option \u2192 cancelable
|
|
3214
|
+
\`brainerce:bot:add-to-cart\` CustomEvent on window
|
|
3215
|
+
(\`detail: { productId, variantId, quantity, connectionId }\`; call
|
|
3216
|
+
preventDefault() after handling) \u2192 navigate to the product page.
|
|
3217
|
+
|
|
3218
|
+
Rules:
|
|
3219
|
+
- Mount once per page; do not pass any visual config \u2014 the dashboard owns it.
|
|
3220
|
+
- Do not wrap or restyle the widget; it renders in its own Shadow DOM.
|
|
3221
|
+
- Product card links expect the conventional \`/products/<slug>\` route.
|
|
3222
|
+
- Wire \`onAddToCart\` to the site's cart (see the cart section) so the header
|
|
3223
|
+
count updates when the bot adds items.
|
|
3224
|
+
`;
|
|
3225
|
+
}
|
|
2973
3226
|
function getSectionByTopic(topic, connectionId, currency) {
|
|
2974
3227
|
const cid = connectionId || "vc_YOUR_CONNECTION_ID";
|
|
2975
3228
|
const cur = currency || "USD";
|
|
@@ -3008,6 +3261,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
3008
3261
|
return getTaxDisplaySection(cur);
|
|
3009
3262
|
case "i18n":
|
|
3010
3263
|
return getI18nSection();
|
|
3264
|
+
case "multilingual-seo":
|
|
3265
|
+
case "hreflang":
|
|
3266
|
+
case "seo-i18n":
|
|
3267
|
+
return getMultilingualSeoSection();
|
|
3011
3268
|
case "critical-rules":
|
|
3012
3269
|
return getCriticalRulesSection() + "\n\n" + getTypeQuickReference();
|
|
3013
3270
|
case "type-reference":
|
|
@@ -3018,6 +3275,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
3018
3275
|
return getContactInquiriesSection();
|
|
3019
3276
|
case "content":
|
|
3020
3277
|
return getContentSection();
|
|
3278
|
+
case "blog":
|
|
3279
|
+
return getBlogSection();
|
|
3280
|
+
case "storefront-bot":
|
|
3281
|
+
return getStorefrontBotSection(cid);
|
|
3021
3282
|
case "all":
|
|
3022
3283
|
return [
|
|
3023
3284
|
"# Brainerce SDK \u2014 full topic dump",
|
|
@@ -3102,6 +3363,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
3102
3363
|
"",
|
|
3103
3364
|
"---",
|
|
3104
3365
|
"",
|
|
3366
|
+
getMultilingualSeoSection(),
|
|
3367
|
+
"",
|
|
3368
|
+
"---",
|
|
3369
|
+
"",
|
|
3105
3370
|
getAdminApiSection(),
|
|
3106
3371
|
"",
|
|
3107
3372
|
"---",
|
|
@@ -3110,10 +3375,18 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
3110
3375
|
"",
|
|
3111
3376
|
"---",
|
|
3112
3377
|
"",
|
|
3113
|
-
getContentSection()
|
|
3378
|
+
getContentSection(),
|
|
3379
|
+
"",
|
|
3380
|
+
"---",
|
|
3381
|
+
"",
|
|
3382
|
+
getBlogSection(),
|
|
3383
|
+
"",
|
|
3384
|
+
"---",
|
|
3385
|
+
"",
|
|
3386
|
+
getStorefrontBotSection(cid)
|
|
3114
3387
|
].join("\n");
|
|
3115
3388
|
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`;
|
|
3389
|
+
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
3390
|
}
|
|
3118
3391
|
}
|
|
3119
3392
|
|
|
@@ -3142,6 +3415,7 @@ var GET_SDK_DOCS_SCHEMA = {
|
|
|
3142
3415
|
"admin",
|
|
3143
3416
|
"inquiries",
|
|
3144
3417
|
"content",
|
|
3418
|
+
"storefront-bot",
|
|
3145
3419
|
"all"
|
|
3146
3420
|
]).describe("The SDK documentation topic to retrieve"),
|
|
3147
3421
|
salesChannelId: import_zod.z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
|
|
@@ -3179,6 +3453,12 @@ interface Product {
|
|
|
3179
3453
|
priceMin?: string | null; // Lowest variant price (VARIABLE products) \u2014 same as basePrice for VARIABLE, kept for back-compat and JSON-LD range display.
|
|
3180
3454
|
priceMax?: string | null; // Highest variant price (VARIABLE products). Use with priceMin for "\u20AA49 \u2013 \u20AA199" range.
|
|
3181
3455
|
priceVaries?: boolean; // true when variant prices differ \u2014 show "\u20AA49 \u2013 \u20AA199" range.
|
|
3456
|
+
// 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.
|
|
3457
|
+
displayPrice?: string; // basePrice \xD7 daily FX rate, in displayCurrency.
|
|
3458
|
+
displaySalePrice?: string; // salePrice \xD7 rate (if salePrice present).
|
|
3459
|
+
displayPriceMin?: string; // priceMin \xD7 rate (VARIABLE products).
|
|
3460
|
+
displayPriceMax?: string; // priceMax \xD7 rate (VARIABLE products).
|
|
3461
|
+
displayCurrency?: string; // ISO 4217 of the region \u2014 e.g. "EUR".
|
|
3182
3462
|
status: string;
|
|
3183
3463
|
type: 'SIMPLE' | 'VARIABLE';
|
|
3184
3464
|
isDownloadable?: boolean;
|
|
@@ -3222,6 +3502,10 @@ interface ProductVariant {
|
|
|
3222
3502
|
name?: string | null;
|
|
3223
3503
|
price?: string | null;
|
|
3224
3504
|
salePrice?: string | null;
|
|
3505
|
+
// FX DISPLAY overlay (PRD \xA723) \u2014 same semantics as on the parent Product.
|
|
3506
|
+
displayPrice?: string;
|
|
3507
|
+
displaySalePrice?: string;
|
|
3508
|
+
displayCurrency?: string;
|
|
3225
3509
|
attributes?: Record<string, string> | null;
|
|
3226
3510
|
options?: Array<{ name: string; value: string }>;
|
|
3227
3511
|
inventory?: InventoryInfo | null;
|
|
@@ -3534,6 +3818,8 @@ interface Order {
|
|
|
3534
3818
|
totalAmount: string; // ALWAYS use this, not .total
|
|
3535
3819
|
total?: string; // optional alias
|
|
3536
3820
|
currency?: string;
|
|
3821
|
+
taxAmount?: string | null; // 0 in inclusive (VAT) mode \u2014 read taxBreakdown.totalTax
|
|
3822
|
+
taxBreakdown?: TaxBreakdown | null; // carries the included VAT when prices include tax
|
|
3537
3823
|
customer?: OrderCustomer | null;
|
|
3538
3824
|
items: OrderItem[];
|
|
3539
3825
|
itemCount?: number;
|
|
@@ -4351,6 +4637,15 @@ interface PublicRegionDetail extends PublicRegion {
|
|
|
4351
4637
|
}
|
|
4352
4638
|
// getStoreRegions(): { data: PublicRegion[] } \u2014 active regions, default first.
|
|
4353
4639
|
// getStoreRegion(regionId): PublicRegionDetail \u2014 one region + its providers.
|
|
4640
|
+
interface AutoRegionResponse {
|
|
4641
|
+
region: PublicRegion | null;
|
|
4642
|
+
matched: boolean; // true=country was in a region's list; false=fell back to default
|
|
4643
|
+
country: string; // upper-cased ISO-3166-1 alpha-2; '' when caller omitted it
|
|
4644
|
+
}
|
|
4645
|
+
// getAutoRegion(country): AutoRegionResponse \u2014 server-side resolution in one
|
|
4646
|
+
// round trip. Pair with the country your edge runtime extracts
|
|
4647
|
+
// (CF-IPCountry / request.geo.country / etc.) \u2014 Brainerce does NOT derive the
|
|
4648
|
+
// country from the request IP server-side (storefront != end-customer).
|
|
4354
4649
|
|
|
4355
4650
|
// ---- Tax Classes ---- (scopes: tax-classes:read / tax-classes:write)
|
|
4356
4651
|
// Charge differential rates by product type. A TaxRate may target a class via
|
|
@@ -4382,7 +4677,25 @@ interface AssignTaxClassDto { productIds?: string[]; variantIds?: string[]; cate
|
|
|
4382
4677
|
// getRegionCompatibleProviders(id), detectRegion(country, regions)
|
|
4383
4678
|
// Tax classes: getTaxClasses(), getTaxClass(id), createTaxClass(dto), updateTaxClass(id, dto),
|
|
4384
4679
|
// deleteTaxClass(id), setDefaultTaxClass(id), assignTaxClass(id, dto),
|
|
4385
|
-
// mergeTaxClasses(id, targetId)
|
|
4680
|
+
// mergeTaxClasses(id, targetId)
|
|
4681
|
+
//
|
|
4682
|
+
// SDK methods (storefront, public \u2014 storeId mode, no apiKey):
|
|
4683
|
+
// getStoreRegions(), getStoreRegion(id), getAutoRegion(country)
|
|
4684
|
+
// getStoreTaxClasses(), estimateTax({ country?, subtotal })
|
|
4685
|
+
//
|
|
4686
|
+
// estimateTax returns:
|
|
4687
|
+
interface TaxEstimateResponse {
|
|
4688
|
+
appliesTax: boolean;
|
|
4689
|
+
rate: number | null; // percent (18 = 18%) \u2014 null when no matching rule
|
|
4690
|
+
rateName: string | null;
|
|
4691
|
+
estimatedTax: number; // tax portion of subtotal in store currency
|
|
4692
|
+
pricesIncludeTax: boolean;
|
|
4693
|
+
currency: string; // store currency (cart/order currency)
|
|
4694
|
+
note: string; // disclaimer \u2014 preview is non-binding
|
|
4695
|
+
}
|
|
4696
|
+
// Non-binding by design: the authoritative tax runs at checkout against the
|
|
4697
|
+
// full shipping address. The country comes from your edge runtime
|
|
4698
|
+
// (CF-IPCountry / request.geo.country / etc.), NOT the request IP.`;
|
|
4386
4699
|
var TYPES_BY_DOMAIN = {
|
|
4387
4700
|
products: PRODUCTS_TYPES,
|
|
4388
4701
|
cart: CART_TYPES,
|