@brainerce/mcp-server 3.7.0 → 3.9.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 +833 -57
- package/dist/bin/stdio.js +667 -33
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +667 -33
- package/dist/index.mjs +667 -33
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1147,6 +1147,8 @@ const material = getProductMetafieldValue(product, 'material');
|
|
|
1147
1147
|
|
|
1148
1148
|
**Metafield fields:** \`definitionName\` (display label), \`definitionKey\` (lookup key), \`value\`, \`type\` (IMAGE, GALLERY, URL, COLOR, BOOLEAN, DATE, DATETIME, TEXT, TEXTAREA, NUMBER, DIMENSION, WEIGHT, JSON)
|
|
1149
1149
|
|
|
1150
|
+
**Translations:** When the store has i18n enabled and \`client.setLocale()\` is active, both the \`definitionName\` (the merchant-authored label like "Warranty Info" / "\u05DE\u05D9\u05D3\u05E2 \u05D0\u05D7\u05E8\u05D9\u05D5\u05EA") **and** free-text \`value\` come back already translated. No per-call locale param needed.
|
|
1151
|
+
|
|
1150
1152
|
### Product Customization Fields (Customer Input)
|
|
1151
1153
|
|
|
1152
1154
|
Some products allow customers to provide input at purchase time (e.g., text on a cake, upload a logo). Check \`product.customizationFields\` and render input fields accordingly.
|
|
@@ -1280,6 +1282,8 @@ await client.removeCoupon(cartId);
|
|
|
1280
1282
|
const totals = getCartTotals(cart); // { subtotal, discount, shipping, total }
|
|
1281
1283
|
\`\`\`
|
|
1282
1284
|
|
|
1285
|
+
> **Region-restricted coupons:** a coupon may carry \`regionIds\`. If the buyer's checkout region isn't in that list, \`applyCoupon\` / \`applyCheckoutCoupon\` reject the code even when everything else matches. Empty/omitted \`regionIds\` = valid in all regions.
|
|
1286
|
+
|
|
1283
1287
|
**On the checkout page** (after checkout session exists \u2014 ALWAYS use this when checkoutId is available):
|
|
1284
1288
|
\`\`\`typescript
|
|
1285
1289
|
// Applies to cart AND updates checkout totals in one call
|
|
@@ -1607,6 +1611,8 @@ const groups: ModifierGroup[] = product.modifierGroups ?? [];
|
|
|
1607
1611
|
|
|
1608
1612
|
**Money fields are strings.** \`priceDelta\` is \`"5.00"\` (or \`"-2.00"\` for downsell modifiers \u2014 see below). Use \`parseFloat()\` for display arithmetic; never compute the line total client-side \u2014 the server runs the free-allocation policy and returns the final \`unitPrice\` snapshot on the cart line.
|
|
1609
1613
|
|
|
1614
|
+
**Translations are automatic.** Both \`group.name\`/\`group.description\` and each \`modifier.name\`/\`modifier.description\` are overlay-resolved by the server on every read. Call \`client.setLocale('he')\` once and the modifier picker renders in Hebrew with no extra code (\`"\u05EA\u05D5\u05E1\u05E4\u05D5\u05EA"\` / \`"\u05D6\u05D9\u05EA\u05D9\u05DD"\`). See the \`i18n\` topic for the full multi-language flow.
|
|
1615
|
+
|
|
1610
1616
|
### Render: SINGLE \u2192 radio, MULTIPLE \u2192 checkbox
|
|
1611
1617
|
|
|
1612
1618
|
Walk \`groups\` and pick the input type by \`selectionType\`. Sort modifiers by \`position\`.
|
|
@@ -2008,19 +2014,24 @@ window.location.href = authorizationUrl;
|
|
|
2008
2014
|
\`\`\`typescript
|
|
2009
2015
|
const params = new URLSearchParams(window.location.search);
|
|
2010
2016
|
if (params.get('oauth_success') === 'true') {
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2017
|
+
// Single-use auth_code is exchanged for the JWT via POST \u2014 keeps the JWT
|
|
2018
|
+
// out of the URL (browser history, CDN logs, Referer header).
|
|
2019
|
+
const code = params.get('auth_code');
|
|
2020
|
+
if (code) {
|
|
2021
|
+
const result = await client.exchangeOAuthCode(code);
|
|
2022
|
+
client.setCustomerToken(result.token);
|
|
2023
|
+
localStorage.setItem('customerToken', result.token);
|
|
2024
|
+
// Optional: result.customer, result.isNewCustomer, result.redirectUrl
|
|
2016
2025
|
// Link guest cart: await client.linkCart(cartId);
|
|
2017
|
-
window.location.href = '/account';
|
|
2026
|
+
window.location.href = result.redirectUrl || '/account';
|
|
2018
2027
|
}
|
|
2019
2028
|
} else if (params.get('oauth_error')) {
|
|
2020
2029
|
// Show error: params.get('oauth_error')
|
|
2021
2030
|
}
|
|
2022
2031
|
\`\`\`
|
|
2023
2032
|
|
|
2033
|
+
> The legacy redirect format placed the JWT directly in the URL as \`?token=\`. That format is still emitted for backward compatibility, but it will be removed in the next major release \u2014 migrate to \`auth_code\` + \`exchangeOAuthCode()\` now.
|
|
2034
|
+
|
|
2024
2035
|
### Account Page (/account) \u2014 uses getMyProfile() and getMyOrders()
|
|
2025
2036
|
|
|
2026
2037
|
\`\`\`typescript
|
|
@@ -2194,9 +2205,12 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
|
2194
2205
|
const client = getServerClient();
|
|
2195
2206
|
client.setLocale(locale);
|
|
2196
2207
|
const product = await client.getProductBySlug(slug);
|
|
2208
|
+
// NEVER feed raw HTML into <meta name="description"> \u2014 product.description
|
|
2209
|
+
// is often rich-text HTML. Strip tags first, then truncate on a word
|
|
2210
|
+
// boundary. See buildMetaDescription() in lib/seo.ts.
|
|
2197
2211
|
return {
|
|
2198
2212
|
title: product.seoTitle || product.name,
|
|
2199
|
-
description: product.seoDescription || product.description
|
|
2213
|
+
description: product.seoDescription || buildMetaDescription(product.description) || product.name,
|
|
2200
2214
|
};
|
|
2201
2215
|
}
|
|
2202
2216
|
\`\`\`
|
|
@@ -2246,7 +2260,17 @@ overlay needed:
|
|
|
2246
2260
|
- \`variants[].name\`
|
|
2247
2261
|
- \`variant.attributes\` keys and values \u2014 \`getVariantOptions(variant)\` returns translated attribute names and option values automatically
|
|
2248
2262
|
- \`productAttributeOptions[].attribute.name\`, \`attributeOption.name\`
|
|
2249
|
-
- \`metafields[].value\`
|
|
2263
|
+
- \`metafields[].value\` (the free-text values customers submit)
|
|
2264
|
+
- \`metafields[].definition.name\`, \`metafields[].definition.description\` (the merchant-authored custom-field labels \u2014 "Warranty Info" / "\u05DE\u05D9\u05D3\u05E2 \u05D0\u05D7\u05E8\u05D9\u05D5\u05EA")
|
|
2265
|
+
- \`modifierGroups[].name\`, \`modifierGroups[].description\` (the group label shown on the PDP \u2014 e.g. "Toppings" / "\u05EA\u05D5\u05E1\u05E4\u05D5\u05EA")
|
|
2266
|
+
- \`modifierGroups[].modifiers[].name\`, \`modifierGroups[].modifiers[].description\` (each individual modifier \u2014 e.g. "Olives" / "\u05D6\u05D9\u05EA\u05D9\u05DD")
|
|
2267
|
+
|
|
2268
|
+
**Promotional surfaces:**
|
|
2269
|
+
- \`cart.bundles[].name\`, \`cart.bundles[].description\` (the bundle's own merchant-typed label, e.g. "Lunch Combo" / "\u05D0\u05E8\u05D5\u05D7\u05EA \u05E6\u05D4\u05E8\u05D9\u05D9\u05DD")
|
|
2270
|
+
- \`cart.bundles[].offeredProducts[].name\`, \`.slug\` (each product inside the bundle \u2014 fetched fresh from \`Product.translations\`)
|
|
2271
|
+
- \`checkout.bumps[].title\`, \`checkout.bumps[].description\` (the bump headline shown at checkout \u2014 falls back to the translated product name when merchant didn't override)
|
|
2272
|
+
- \`checkout.bumps[].bumpProduct.name\`, \`.slug\` (the underlying product)
|
|
2273
|
+
- Discount-rule names/descriptions (when surfaced as banner text via \`displayConfig\`)
|
|
2250
2274
|
|
|
2251
2275
|
**Taxonomy (\`getCategories\`, \`getBrands\`, \`getTags\`):**
|
|
2252
2276
|
- \`name\` on each item
|
|
@@ -2312,11 +2336,25 @@ Because the backend already overlays everything, UI code is just:
|
|
|
2312
2336
|
|
|
2313
2337
|
### RTL handling
|
|
2314
2338
|
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2339
|
+
Resolve direction with \`client.getStoreDirection(locale)\` \u2014 it returns
|
|
2340
|
+
\`'ltr' | 'rtl'\` for any BCP-47 tag (Arabic, Hebrew, Persian, Urdu, Yiddish
|
|
2341
|
+
today; future RTL locales added by the platform are picked up automatically).
|
|
2342
|
+
Do NOT maintain your own RTL locale set.
|
|
2343
|
+
|
|
2344
|
+
\`\`\`tsx
|
|
2345
|
+
// app/[locale]/layout.tsx
|
|
2346
|
+
const dir = client.getStoreDirection(locale);
|
|
2347
|
+
return <html lang={locale} dir={dir}>...</html>;
|
|
2348
|
+
\`\`\`
|
|
2349
|
+
|
|
2350
|
+
For static rendering, \`storeInfo.i18n.defaultDirection\` carries the store's
|
|
2351
|
+
default direction, and each entry in \`storeInfo.i18n.supportedLocaleObjects\`
|
|
2352
|
+
includes its own \`direction\`.
|
|
2353
|
+
|
|
2354
|
+
Let flexbox reverse automatically once \`<html dir="rtl">\` is set. Do NOT add
|
|
2355
|
+
\`flex-row-reverse\` on top \u2014 that's a double-swap. DO swap directional icons
|
|
2356
|
+
(chevrons, arrows) manually. Use logical CSS properties (\`ms-*\`/\`me-*\`)
|
|
2357
|
+
instead of \`ml-*\`/\`mr-*\`.
|
|
2320
2358
|
|
|
2321
2359
|
### Language switcher
|
|
2322
2360
|
|
|
@@ -2334,7 +2372,9 @@ const admin = new BrainerceClient({ apiKey: 'brainerce_...' });
|
|
|
2334
2372
|
|
|
2335
2373
|
// Taxonomy: listCategories(), listBrands(), listTags(), listAttributes()
|
|
2336
2374
|
// Shipping: listShippingZones(), createZoneShippingRate()
|
|
2337
|
-
// Tax: getTaxRates(), createTaxRate()
|
|
2375
|
+
// Tax: getTaxRates(), createTaxRate() \u2014 a rate may target a tax class via taxClassId
|
|
2376
|
+
// Tax classes: getTaxClasses(), createTaxClass(), assignTaxClass(), mergeTaxClasses() (scope tax-classes:*)
|
|
2377
|
+
// Regions: getRegions(), createRegion(), setDefaultRegion(), updateRegionPaymentProviders() (scope regions:*)
|
|
2338
2378
|
// Metafields: getMetafieldDefinitions(), setProductMetafield()
|
|
2339
2379
|
// Team: getTeamMembers(), inviteTeamMember()
|
|
2340
2380
|
// Email: getEmailTemplates(), createEmailTemplate()
|
|
@@ -2342,6 +2382,13 @@ const admin = new BrainerceClient({ apiKey: 'brainerce_...' });
|
|
|
2342
2382
|
// OAuth: getOAuthProviders(), configureOAuthProvider()
|
|
2343
2383
|
\`\`\`
|
|
2344
2384
|
|
|
2385
|
+
Store-level team management (\`inviteStoreMember\`, \`updateStoreMember\`) is the
|
|
2386
|
+
canonical replacement for the deprecated account-level helpers above. The
|
|
2387
|
+
invite accepts an optional \`salesChannelIds\` (vibe-coded \`connectionId\`s,
|
|
2388
|
+
\`vc_*\`) to restrict a member to specific channels \u2014 omit or pass \`[]\` for all
|
|
2389
|
+
channels. Use \`updateStoreMemberSalesChannels(storeId, memberId, { salesChannelIds })\`
|
|
2390
|
+
to change that scope later.
|
|
2391
|
+
|
|
2345
2392
|
### Per-Channel Publishing
|
|
2346
2393
|
|
|
2347
2394
|
Categories, tags, brands, and metafield definitions are gated to specific
|
|
@@ -2373,7 +2420,70 @@ calls fail with \`404 Not Found\`.
|
|
|
2373
2420
|
|
|
2374
2421
|
The vibe-coded read endpoints (used by storefront SDK calls in \`connectionId\`
|
|
2375
2422
|
mode) automatically filter by these junction tables, so storefronts never see
|
|
2376
|
-
entities that weren't published to their site
|
|
2423
|
+
entities that weren't published to their site.
|
|
2424
|
+
|
|
2425
|
+
### Tax classes (differential tax rates)
|
|
2426
|
+
|
|
2427
|
+
Charge different rates for different product types. A \`TaxRate\` may target a
|
|
2428
|
+
class via \`taxClassId\`; a rate with \`taxClassId: null\` is the **Standard
|
|
2429
|
+
fallback**. Checkout resolves each line's class **variant \u2192 product \u2192 category
|
|
2430
|
+
\u2192 store default \u2192 null**, then picks the matching rate (Standard if none).
|
|
2431
|
+
\`rate\` is a whole percentage (\`7.25\` = 7.25%). Requires the
|
|
2432
|
+
\`tax-classes:read\` / \`tax-classes:write\` scopes.
|
|
2433
|
+
|
|
2434
|
+
\`\`\`typescript
|
|
2435
|
+
const food = await admin.createTaxClass({ name: 'Food', slug: 'food' });
|
|
2436
|
+
await admin.assignTaxClass(food.id, { productIds: ['prod_1'], categoryIds: ['cat_food'] });
|
|
2437
|
+
|
|
2438
|
+
// class-specific rate \u2014 only food lines use it; everything else uses Standard
|
|
2439
|
+
await admin.createTaxRate({ name: 'VAT (Food)', rate: 0, country: 'GB', taxClassId: food.id });
|
|
2440
|
+
|
|
2441
|
+
// delete is blocked (409) while dependents exist \u2014 merge moves FKs then deletes:
|
|
2442
|
+
await admin.mergeTaxClasses(food.id, standardClassId);
|
|
2443
|
+
\`\`\`
|
|
2444
|
+
|
|
2445
|
+
Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreTaxClasses()\` lists
|
|
2446
|
+
the store's classes (storefront-safe fields only) for a transparency badge.
|
|
2447
|
+
|
|
2448
|
+
### Regions (multi-currency / per-region providers)
|
|
2449
|
+
|
|
2450
|
+
A region binds countries \u2192 currency + tax-display mode + enabled payment
|
|
2451
|
+
providers. Manage them via the SDK (scopes \`regions:read\` / \`regions:write\`).
|
|
2452
|
+
\`detectRegion\` is a pure client-side helper to map a buyer's country to a
|
|
2453
|
+
region; pass the resolved \`regionId\` to \`createCheckout\` to associate the
|
|
2454
|
+
checkout with a region (recorded for reporting + provider scoping; currency
|
|
2455
|
+
follows the cart until FX price conversion lands).
|
|
2456
|
+
|
|
2457
|
+
\`\`\`typescript
|
|
2458
|
+
const eu = await admin.createRegion({
|
|
2459
|
+
name: 'EU', currency: 'EUR', countries: ['DE', 'FR'],
|
|
2460
|
+
taxInclusive: true, paymentProviderIds: ['app_inst_stripe'],
|
|
2461
|
+
});
|
|
2462
|
+
await admin.setDefaultRegion(eu.id);
|
|
2463
|
+
|
|
2464
|
+
const { data: regions } = await admin.getRegions();
|
|
2465
|
+
const region = admin.detectRegion('DE', regions); // \u2192 eu, else default, else null
|
|
2466
|
+
\`\`\`
|
|
2467
|
+
|
|
2468
|
+
Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreRegions()\` lists
|
|
2469
|
+
active regions, \`getStoreRegion(id)\` returns one region + its payment providers.
|
|
2470
|
+
Pair with \`detectRegion\` to pick the buyer's region for currency display.
|
|
2471
|
+
|
|
2472
|
+
\`\`\`typescript
|
|
2473
|
+
const store = new BrainerceClient({ storeId: 'store_123' });
|
|
2474
|
+
const { data: regions } = await store.getStoreRegions();
|
|
2475
|
+
const region = await store.getStoreRegion(regions[0].id);
|
|
2476
|
+
\`\`\`
|
|
2477
|
+
|
|
2478
|
+
A shipping zone can be limited to regions via \`regionIds\` \u2014 the zone is then
|
|
2479
|
+
only offered to checkouts that resolved to one of those regions. Empty/omitted =
|
|
2480
|
+
available for any region (default); each id must belong to the same store.
|
|
2481
|
+
|
|
2482
|
+
\`\`\`typescript
|
|
2483
|
+
await admin.createShippingZone({
|
|
2484
|
+
name: 'EU Express', countries: ['DE', 'FR', 'IT'], regionIds: [eu.id],
|
|
2485
|
+
});
|
|
2486
|
+
\`\`\``;
|
|
2377
2487
|
}
|
|
2378
2488
|
function getContactInquiriesSection() {
|
|
2379
2489
|
return `## Contact Inquiries & Forms (optional)
|
|
@@ -2693,6 +2803,141 @@ and a \`newsletter\` form embedded in the footer), render each form from its
|
|
|
2693
2803
|
own \`contactForms.get(key, locale)\` call. The \`formKey\` you pass to
|
|
2694
2804
|
\`createInquiry\` must match.`;
|
|
2695
2805
|
}
|
|
2806
|
+
function getContentSection() {
|
|
2807
|
+
return `## Content \u2014 typed merchant content store
|
|
2808
|
+
|
|
2809
|
+
Brainerce ships a typed content store so merchants can edit site chrome, FAQ,
|
|
2810
|
+
static pages, and inline rich-text blocks in the dashboard \u2014 without
|
|
2811
|
+
re-prompting the AI that built their storefront. Every row has a \`type\` +
|
|
2812
|
+
\`key\` + typed \`data\` payload + free-form \`customFields\`.
|
|
2813
|
+
|
|
2814
|
+
**Six content types.** Each one has a fixed \`data\` shape; the SDK's TypeScript
|
|
2815
|
+
generics keep them in lockstep:
|
|
2816
|
+
|
|
2817
|
+
| Type | Use for | \`data\` shape (abbreviated) |
|
|
2818
|
+
| -------------- | -------------------------------------- | --------------------------- |
|
|
2819
|
+
| \`FAQ\` | Q/A accordions | \`{ items: { question, answer }[] }\` |
|
|
2820
|
+
| \`FOOTER\` | Site footer (chrome) | \`{ columns, copyright?, social? }\` |
|
|
2821
|
+
| \`HEADER\` | Top nav + logo + CTA (chrome) | \`{ logo?, navItems, cta? }\` |
|
|
2822
|
+
| \`ANNOUNCEMENT\`| Banners; time-bound by \`startsAt/endsAt\` | \`{ message, severity, dismissible, ... }\` |
|
|
2823
|
+
| \`RICH_TEXT\` | Free-form HTML blocks embedded inline | \`{ html }\` |
|
|
2824
|
+
| \`PAGE\` | Static pages with slug + SEO | \`{ slug, title, html, seo? }\` |
|
|
2825
|
+
|
|
2826
|
+
Run \`get-type-definitions\` with \`domain: 'content'\` for the full interfaces.
|
|
2827
|
+
|
|
2828
|
+
### Default key
|
|
2829
|
+
|
|
2830
|
+
Every type has \`'main'\` as its universal default key. \`client.content.faq.get()\`
|
|
2831
|
+
with no arguments resolves to \`key='main'\`. Topical keys (\`'shipping'\`,
|
|
2832
|
+
\`'holiday-2026'\`, \`'about'\`) are merchant-named.
|
|
2833
|
+
|
|
2834
|
+
### Reading content (any SDK mode)
|
|
2835
|
+
|
|
2836
|
+
Public reads work in vibe-coded mode, storefront mode, and admin mode. They
|
|
2837
|
+
return \`null\` on 404 \u2014 render hard-coded fallbacks so the page never crashes
|
|
2838
|
+
when the merchant hasn't seeded yet.
|
|
2839
|
+
|
|
2840
|
+
\`\`\`ts
|
|
2841
|
+
// Single entry, default key 'main', resolved to a locale
|
|
2842
|
+
const faq = await client.content.faq.get('main', locale);
|
|
2843
|
+
if (faq) {
|
|
2844
|
+
faq.data.items.forEach(({ question, answer }) => {
|
|
2845
|
+
// Render question + sanitize(answer)
|
|
2846
|
+
});
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
// All entries of a type
|
|
2850
|
+
const allFaqs = await client.content.faq.list(locale);
|
|
2851
|
+
|
|
2852
|
+
// Page by URL slug \u2014 for app/[slug]/page.tsx
|
|
2853
|
+
const page = await client.content.page.getBySlug(slug, locale);
|
|
2854
|
+
if (!page) notFound();
|
|
2855
|
+
\`\`\`
|
|
2856
|
+
|
|
2857
|
+
### Security \u2014 sanitize HTML before rendering
|
|
2858
|
+
|
|
2859
|
+
\`FAQ.items[i].answer\`, \`RICH_TEXT.html\`, and \`PAGE.html\` carry
|
|
2860
|
+
MERCHANT-AUTHORED HTML. The server does NOT pre-sanitize \u2014 some merchants
|
|
2861
|
+
embed iframes (e.g. YouTube) which strict sanitizers would strip. ALWAYS
|
|
2862
|
+
sanitize on the storefront before injecting:
|
|
2863
|
+
|
|
2864
|
+
\`\`\`ts
|
|
2865
|
+
// Recommended: isomorphic-dompurify
|
|
2866
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
2867
|
+
const safe = DOMPurify.sanitize(rawHtml);
|
|
2868
|
+
<div dangerouslySetInnerHTML={{ __html: safe }} />;
|
|
2869
|
+
\`\`\`
|
|
2870
|
+
|
|
2871
|
+
Skipping this is XSS.
|
|
2872
|
+
|
|
2873
|
+
### Custom fields
|
|
2874
|
+
|
|
2875
|
+
Every Content row carries a free-form \`customFields: Record<string, string>\`.
|
|
2876
|
+
Merchants add arbitrary key-value extras (\`helpEmail\`, \`phoneNumber\`,
|
|
2877
|
+
\`foundedYear\`) that you can opt into reading:
|
|
2878
|
+
|
|
2879
|
+
\`\`\`ts
|
|
2880
|
+
const faq = await client.content.faq.get('shipping');
|
|
2881
|
+
<a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
|
|
2882
|
+
\`\`\`
|
|
2883
|
+
|
|
2884
|
+
The shape is whatever the merchant entered. Read keys you expect; ignore the rest.
|
|
2885
|
+
|
|
2886
|
+
### Locale resolution
|
|
2887
|
+
|
|
2888
|
+
All public reads accept a \`locale\` argument. The server resolves
|
|
2889
|
+
\`translations[locale]\` server-side and returns the resolved \`data\` payload \u2014
|
|
2890
|
+
the storefront does NOT need to do its own overlay. Empty / missing translations
|
|
2891
|
+
fall through to the default-locale value.
|
|
2892
|
+
|
|
2893
|
+
### Cache
|
|
2894
|
+
|
|
2895
|
+
Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
|
|
2896
|
+
Merchant edits propagate within ~5 minutes. Don't layer extra client-side
|
|
2897
|
+
caching beyond Next.js's default fetch cache.
|
|
2898
|
+
|
|
2899
|
+
### Admin writes (apiKey mode)
|
|
2900
|
+
|
|
2901
|
+
\`\`\`ts
|
|
2902
|
+
const adminClient = new BrainerceClient({ apiKey: process.env.BRAINERCE_API_KEY });
|
|
2903
|
+
|
|
2904
|
+
// Create \u2014 always starts in DRAFT
|
|
2905
|
+
const faq = await adminClient.content.faq.create({
|
|
2906
|
+
key: 'shipping',
|
|
2907
|
+
name: 'Shipping FAQ',
|
|
2908
|
+
data: { items: [{ question: 'How long?', answer: 'Most orders ship in 2 days.' }] },
|
|
2909
|
+
});
|
|
2910
|
+
|
|
2911
|
+
// Update (data replaces wholesale; last-write-wins on the data field)
|
|
2912
|
+
await adminClient.content.update(faq.id, {
|
|
2913
|
+
data: { items: [{ question: 'How long?', answer: 'Updated answer.' }] },
|
|
2914
|
+
});
|
|
2915
|
+
|
|
2916
|
+
// Publish / unpublish
|
|
2917
|
+
await adminClient.content.publish(faq.id);
|
|
2918
|
+
await adminClient.content.unpublish(faq.id);
|
|
2919
|
+
|
|
2920
|
+
// Hard delete
|
|
2921
|
+
await adminClient.content.remove(faq.id);
|
|
2922
|
+
\`\`\`
|
|
2923
|
+
|
|
2924
|
+
Write operations throw if called from vibe-coded or storefront mode.
|
|
2925
|
+
|
|
2926
|
+
### Reserved key convention
|
|
2927
|
+
|
|
2928
|
+
\`'main'\` is reserved as the universal default. Don't use it for topical
|
|
2929
|
+
entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'\`,
|
|
2930
|
+
\`'holiday-2026'\`). The validation rule is \`^[a-z][a-z0-9-]*$\`, max 64 chars.
|
|
2931
|
+
|
|
2932
|
+
### See also
|
|
2933
|
+
|
|
2934
|
+
- \`get-business-flows\` with \`flow: 'content-bootstrap'\` for the full
|
|
2935
|
+
layout / FAQ / page recipe.
|
|
2936
|
+
- \`get-required-features\` lists each Content surface (\`site-header\`,
|
|
2937
|
+
\`site-footer\`, \`announcement-bar\`, \`faq-page\`, \`static-pages\`).
|
|
2938
|
+
- \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
|
|
2939
|
+
interfaces.`;
|
|
2940
|
+
}
|
|
2696
2941
|
function getSectionByTopic(topic, connectionId, currency) {
|
|
2697
2942
|
const cid = connectionId || "vc_YOUR_CONNECTION_ID";
|
|
2698
2943
|
const cur = currency || "USD";
|
|
@@ -2739,6 +2984,8 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2739
2984
|
return getAdminApiSection();
|
|
2740
2985
|
case "inquiries":
|
|
2741
2986
|
return getContactInquiriesSection();
|
|
2987
|
+
case "content":
|
|
2988
|
+
return getContentSection();
|
|
2742
2989
|
case "all":
|
|
2743
2990
|
return [
|
|
2744
2991
|
"# Brainerce SDK \u2014 full topic dump",
|
|
@@ -2827,10 +3074,14 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2827
3074
|
"",
|
|
2828
3075
|
"---",
|
|
2829
3076
|
"",
|
|
2830
|
-
getContactInquiriesSection()
|
|
3077
|
+
getContactInquiriesSection(),
|
|
3078
|
+
"",
|
|
3079
|
+
"---",
|
|
3080
|
+
"",
|
|
3081
|
+
getContentSection()
|
|
2831
3082
|
].join("\n");
|
|
2832
3083
|
default:
|
|
2833
|
-
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`;
|
|
3084
|
+
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`;
|
|
2834
3085
|
}
|
|
2835
3086
|
}
|
|
2836
3087
|
|
|
@@ -2858,6 +3109,7 @@ var GET_SDK_DOCS_SCHEMA = {
|
|
|
2858
3109
|
"i18n",
|
|
2859
3110
|
"admin",
|
|
2860
3111
|
"inquiries",
|
|
3112
|
+
"content",
|
|
2861
3113
|
"all"
|
|
2862
3114
|
]).describe("The SDK documentation topic to retrieve"),
|
|
2863
3115
|
salesChannelId: z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
|
|
@@ -2889,11 +3141,11 @@ interface Product {
|
|
|
2889
3141
|
description?: string | null;
|
|
2890
3142
|
descriptionFormat?: 'text' | 'html' | 'markdown' | null;
|
|
2891
3143
|
sku: string;
|
|
2892
|
-
basePrice: string; //
|
|
2893
|
-
salePrice?: string | null;
|
|
3144
|
+
basePrice: string; // For VARIABLE products: MIN(variants.price). For SIMPLE: the parent price. parseFloat() for math.
|
|
3145
|
+
salePrice?: string | null; // For VARIABLE: MIN(variants.salePrice WHERE NOT NULL) \u2014 null iff no variant is on sale (WC is_on_sale() semantic). For SIMPLE: the parent sale price. Reliable "on sale?" check: product.salePrice !== null.
|
|
2894
3146
|
costPrice?: string | null;
|
|
2895
|
-
priceMin?: string | null; // Lowest variant price (VARIABLE products)
|
|
2896
|
-
priceMax?: string | null; // Highest variant price (VARIABLE products).
|
|
3147
|
+
priceMin?: string | null; // Lowest variant price (VARIABLE products) \u2014 same as basePrice for VARIABLE, kept for back-compat and JSON-LD range display.
|
|
3148
|
+
priceMax?: string | null; // Highest variant price (VARIABLE products). Use with priceMin for "\u20AA49 \u2013 \u20AA199" range.
|
|
2897
3149
|
priceVaries?: boolean; // true when variant prices differ \u2014 show "\u20AA49 \u2013 \u20AA199" range.
|
|
2898
3150
|
status: string;
|
|
2899
3151
|
type: 'SIMPLE' | 'VARIABLE';
|
|
@@ -3009,6 +3261,11 @@ interface ProductQueryParams {
|
|
|
3009
3261
|
metafields?: Record<string, string | string[]>;
|
|
3010
3262
|
sortBy?: 'name' | 'price' | 'createdAt';
|
|
3011
3263
|
sortOrder?: 'asc' | 'desc';
|
|
3264
|
+
// PRD \xA722: resolve DISPLAY prices for this region. When set + valid, each
|
|
3265
|
+
// product/variant gains resolvedPrice/resolvedCurrency/priceSource (additive;
|
|
3266
|
+
// basePrice/salePrice untouched). Absent/invalid region \u2192 nothing attached.
|
|
3267
|
+
// Display-only. Ignored in vibe-coded (vc_*) mode (storefront/admin paths only).
|
|
3268
|
+
regionId?: string;
|
|
3012
3269
|
}
|
|
3013
3270
|
|
|
3014
3271
|
interface SearchSuggestions {
|
|
@@ -3134,6 +3391,7 @@ interface Checkout {
|
|
|
3134
3391
|
status: CheckoutStatus;
|
|
3135
3392
|
email?: string | null;
|
|
3136
3393
|
customerId?: string | null;
|
|
3394
|
+
regionId?: string | null; // multi-region: recorded for reporting + provider scoping (currency follows the cart until FX lands)
|
|
3137
3395
|
shippingAddress?: CheckoutAddress | null;
|
|
3138
3396
|
billingAddress?: CheckoutAddress | null;
|
|
3139
3397
|
shippingRateId?: string | null;
|
|
@@ -3210,6 +3468,7 @@ interface CreateCheckoutDto {
|
|
|
3210
3468
|
cartId: string;
|
|
3211
3469
|
customerId?: string;
|
|
3212
3470
|
selectedItemIds?: string[]; // Partial checkout
|
|
3471
|
+
regionId?: string; // multi-region: associate the checkout with a region (must belong to the store; 400 if unknown)
|
|
3213
3472
|
}
|
|
3214
3473
|
|
|
3215
3474
|
// startGuestCheckout() return type \u2014 DISCRIMINATED UNION
|
|
@@ -3228,6 +3487,8 @@ interface TaxBreakdownItem {
|
|
|
3228
3487
|
name: string;
|
|
3229
3488
|
rate: number; // decimal: 0.17 = 17%
|
|
3230
3489
|
amount: number;
|
|
3490
|
+
taxClassId?: string | null; // rate's tax class (null = Standard)
|
|
3491
|
+
taxClassSlug?: string | null; // class slug for attribution (null = Standard)
|
|
3231
3492
|
}`;
|
|
3232
3493
|
var ORDERS_TYPES = `// ---- Orders ----
|
|
3233
3494
|
|
|
@@ -3285,6 +3546,7 @@ interface OrderItem {
|
|
|
3285
3546
|
// Snapshot of buyer-submitted customization values captured at checkout.
|
|
3286
3547
|
// Keyed by metafield slug. \`value\` is string[] for MULTI_SELECT / GALLERY, string otherwise.
|
|
3287
3548
|
customizations?: Record<string, { label: string; value: string | string[]; type: string }>;
|
|
3549
|
+
taxClassSlug?: string; // frozen slug of the line's resolved tax class (omitted = Standard fallback)
|
|
3288
3550
|
}
|
|
3289
3551
|
|
|
3290
3552
|
interface OrderCustomer {
|
|
@@ -3467,7 +3729,7 @@ function formatPrice(priceString: string | number | undefined | null, options?:
|
|
|
3467
3729
|
function getProductPrice(product: Pick<Product, 'basePrice' | 'salePrice'>): number;
|
|
3468
3730
|
function getProductPriceInfo(product: Pick<Product, 'basePrice' | 'salePrice' | 'discount' | 'priceMin' | 'priceVaries'>): {
|
|
3469
3731
|
price: number; originalPrice: number; isOnSale: boolean; discountAmount: number; discountPercent: number;
|
|
3470
|
-
}; //
|
|
3732
|
+
}; // For VARIABLE products, basePrice/salePrice are pre-aggregated (MIN of variants) \u2014 the helper just reads them. Use this whenever you need an "on sale?" badge or a "X% off" label.
|
|
3471
3733
|
function getVariantPrice(variant: Pick<ProductVariant, 'price' | 'salePrice'>, productBasePrice: string): number;
|
|
3472
3734
|
|
|
3473
3735
|
// Cart helpers
|
|
@@ -3850,6 +4112,245 @@ export interface ModifierValidationError {
|
|
|
3850
4112
|
// The cart line then carries:
|
|
3851
4113
|
// cart.items[i].modifiers \u2014 CartItemModifierLine[]
|
|
3852
4114
|
// cart.items[i].modifiersTotal \u2014 decimal string of the paid (non-free) deltas`;
|
|
4115
|
+
var CONTENT_TYPES = `// ---- Content (typed merchant content store) ----
|
|
4116
|
+
// Brainerce ships a typed content store so merchants can edit FAQ, footer,
|
|
4117
|
+
// header, announcements, rich text, and static pages in the dashboard
|
|
4118
|
+
// without re-prompting the AI that built the storefront. Every row has a
|
|
4119
|
+
// 'type' + 'key' + typed 'data' payload + free-form 'customFields'.
|
|
4120
|
+
//
|
|
4121
|
+
// SECURITY (read carefully):
|
|
4122
|
+
// RICH_TEXT.html, PAGE.html, and FAQ answers are MERCHANT-AUTHORED HTML.
|
|
4123
|
+
// ALWAYS sanitize with isomorphic-dompurify (or equivalent) before
|
|
4124
|
+
// injecting via dangerouslySetInnerHTML. The server does NOT pre-sanitize
|
|
4125
|
+
// because some merchants embed iframes (e.g. YouTube) which strict
|
|
4126
|
+
// sanitizers would strip; the storefront chooses the policy.
|
|
4127
|
+
//
|
|
4128
|
+
// 404 contract: client.content.<type>.get(key) returns null when no
|
|
4129
|
+
// PUBLISHED row exists. Always render a hard-coded fallback on null so
|
|
4130
|
+
// the page never crashes when the merchant hasn't seeded yet.
|
|
4131
|
+
//
|
|
4132
|
+
// Default key: every type has 'main' as its universal default. Pass no
|
|
4133
|
+
// argument to fetch the main entry; pass a custom key ('shipping',
|
|
4134
|
+
// 'holiday-2026', 'about') for topical entries.
|
|
4135
|
+
|
|
4136
|
+
export type ContentType = 'FAQ' | 'FOOTER' | 'HEADER' | 'ANNOUNCEMENT' | 'RICH_TEXT' | 'PAGE';
|
|
4137
|
+
export type ContentStatus = 'DRAFT' | 'PUBLISHED';
|
|
4138
|
+
|
|
4139
|
+
export interface FaqItem {
|
|
4140
|
+
question: string;
|
|
4141
|
+
/** Sanitized HTML \u2014 sanitize before rendering. */
|
|
4142
|
+
answer: string;
|
|
4143
|
+
}
|
|
4144
|
+
export interface FaqContent { items: FaqItem[] }
|
|
4145
|
+
|
|
4146
|
+
export interface FooterLink { label: string; url: string }
|
|
4147
|
+
export interface FooterColumn { title: string; links: FooterLink[] }
|
|
4148
|
+
export interface FooterSocialLink { platform: string; url: string } // 'instagram' | 'facebook' | 'x' | ...
|
|
4149
|
+
export interface FooterContent {
|
|
4150
|
+
columns: FooterColumn[];
|
|
4151
|
+
copyright?: string;
|
|
4152
|
+
social?: FooterSocialLink[];
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
export interface HeaderLogo { src: string; alt: string }
|
|
4156
|
+
export interface HeaderNavItem { label: string; url: string }
|
|
4157
|
+
export interface HeaderCta { label: string; url: string }
|
|
4158
|
+
export interface HeaderContent {
|
|
4159
|
+
logo?: HeaderLogo;
|
|
4160
|
+
navItems: HeaderNavItem[];
|
|
4161
|
+
cta?: HeaderCta;
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
export type AnnouncementSeverity = 'info' | 'warning' | 'success';
|
|
4165
|
+
export interface AnnouncementContent {
|
|
4166
|
+
message: string;
|
|
4167
|
+
severity: AnnouncementSeverity;
|
|
4168
|
+
dismissible: boolean;
|
|
4169
|
+
/** ISO 8601 \u2014 filter client-side. */
|
|
4170
|
+
startsAt?: string;
|
|
4171
|
+
endsAt?: string;
|
|
4172
|
+
ctaLabel?: string;
|
|
4173
|
+
ctaHref?: string;
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
export interface RichTextContent {
|
|
4177
|
+
/** Raw HTML \u2014 sanitize before rendering. */
|
|
4178
|
+
html: string;
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
export interface PageSeo {
|
|
4182
|
+
title?: string;
|
|
4183
|
+
description?: string;
|
|
4184
|
+
ogImage?: string;
|
|
4185
|
+
}
|
|
4186
|
+
export interface PageContent {
|
|
4187
|
+
/** URL slug, lower-kebab. */
|
|
4188
|
+
slug: string;
|
|
4189
|
+
title: string;
|
|
4190
|
+
/** Raw HTML \u2014 sanitize before rendering. */
|
|
4191
|
+
html: string;
|
|
4192
|
+
seo?: PageSeo;
|
|
4193
|
+
}
|
|
4194
|
+
|
|
4195
|
+
export interface ContentSummary {
|
|
4196
|
+
id: string;
|
|
4197
|
+
type: ContentType;
|
|
4198
|
+
key: string;
|
|
4199
|
+
name: string;
|
|
4200
|
+
status: ContentStatus;
|
|
4201
|
+
position: number;
|
|
4202
|
+
updatedAt: string;
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
export interface Content<T extends ContentType = ContentType> extends ContentSummary {
|
|
4206
|
+
type: T;
|
|
4207
|
+
data: T extends 'FAQ' ? FaqContent
|
|
4208
|
+
: T extends 'FOOTER' ? FooterContent
|
|
4209
|
+
: T extends 'HEADER' ? HeaderContent
|
|
4210
|
+
: T extends 'ANNOUNCEMENT' ? AnnouncementContent
|
|
4211
|
+
: T extends 'RICH_TEXT' ? RichTextContent
|
|
4212
|
+
: T extends 'PAGE' ? PageContent
|
|
4213
|
+
: never;
|
|
4214
|
+
/** Free-form merchant-defined extras. Read keys the merchant told you to expect. */
|
|
4215
|
+
customFields: Record<string, string>;
|
|
4216
|
+
salesChannelIds: string[];
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4219
|
+
// ---- SDK usage examples ----
|
|
4220
|
+
//
|
|
4221
|
+
// FAQ \u2014 render an accordion from the main FAQ (or a topical one):
|
|
4222
|
+
// const faq = await client.content.faq.get('main', locale); // 'shipping', 'returns', ...
|
|
4223
|
+
// if (faq) {
|
|
4224
|
+
// faq.data.items.forEach(({ question, answer }) => {
|
|
4225
|
+
// // Render question + sanitize(answer) \u2014 never inject raw HTML.
|
|
4226
|
+
// });
|
|
4227
|
+
// }
|
|
4228
|
+
//
|
|
4229
|
+
// Footer \u2014 server component in root layout:
|
|
4230
|
+
// const footer = await client.content.footer.get('main', locale);
|
|
4231
|
+
// if (!footer) return <Fallback />;
|
|
4232
|
+
// // Render footer.data.columns, footer.data.social, footer.data.copyright
|
|
4233
|
+
//
|
|
4234
|
+
// Header \u2014 same pattern as footer:
|
|
4235
|
+
// const header = await client.content.header.get('main', locale);
|
|
4236
|
+
//
|
|
4237
|
+
// Announcement \u2014 multiple may be active; filter by date client-side:
|
|
4238
|
+
// const announcements = await client.content.announcement.list(locale);
|
|
4239
|
+
// const now = Date.now();
|
|
4240
|
+
// const active = announcements.filter((a) => {
|
|
4241
|
+
// const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
|
|
4242
|
+
// const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
|
|
4243
|
+
// return startOk && endOk;
|
|
4244
|
+
// });
|
|
4245
|
+
//
|
|
4246
|
+
// Rich text \u2014 inline block anywhere on a page:
|
|
4247
|
+
// const block = await client.content.richText.get('about-intro', locale);
|
|
4248
|
+
// <div dangerouslySetInnerHTML={{ __html: sanitize(block.data.html) }} />
|
|
4249
|
+
//
|
|
4250
|
+
// Page \u2014 catch-all route by slug (e.g. /about, /terms, /privacy):
|
|
4251
|
+
// // app/[slug]/page.tsx
|
|
4252
|
+
// const page = await client.content.page.getBySlug(params.slug, locale);
|
|
4253
|
+
// if (!page) notFound();
|
|
4254
|
+
// // page.data.title, page.data.html, page.data.seo
|
|
4255
|
+
// return <article dangerouslySetInnerHTML={{ __html: sanitize(page.data.html) }} />;
|
|
4256
|
+
//
|
|
4257
|
+
// Custom fields \u2014 every Content row carries a free-form Record<string, string>:
|
|
4258
|
+
// const faq = await client.content.faq.get('shipping');
|
|
4259
|
+
// <a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
|
|
4260
|
+
//
|
|
4261
|
+
// Cache \u2014 public reads carry Cache-Control: public, max-age=300,
|
|
4262
|
+
// stale-while-revalidate=60. Storefront changes propagate within ~5 min
|
|
4263
|
+
// of the merchant publishing. Do not add extra client-side caching
|
|
4264
|
+
// beyond Next.js's default fetch cache.`;
|
|
4265
|
+
var REGIONS_TYPES = `// ---- Regions & Tax Classes (Admin mode, apiKey) ----
|
|
4266
|
+
// storeId is derived from the API key \u2014 never pass it on admin calls.
|
|
4267
|
+
|
|
4268
|
+
// ---- Regions ---- (scopes: regions:read / regions:write)
|
|
4269
|
+
// A region binds countries \u2192 currency + tax-display mode + payment providers.
|
|
4270
|
+
interface Region {
|
|
4271
|
+
id: string;
|
|
4272
|
+
accountId: string;
|
|
4273
|
+
storeId: string;
|
|
4274
|
+
name: string;
|
|
4275
|
+
slug: string;
|
|
4276
|
+
currency: string; // ISO 4217, e.g. "EUR"
|
|
4277
|
+
countries: string[]; // ISO 3166-1 alpha-2, e.g. ["DE","FR"]
|
|
4278
|
+
taxInclusive: boolean; // show prices tax-inclusive in this region?
|
|
4279
|
+
automaticTaxes: boolean;
|
|
4280
|
+
isDefault: boolean; // fallback when buyer's country maps to no region
|
|
4281
|
+
isActive: boolean;
|
|
4282
|
+
paymentProviders?: RegionPaymentProvider[];
|
|
4283
|
+
createdAt: string;
|
|
4284
|
+
updatedAt: string;
|
|
4285
|
+
}
|
|
4286
|
+
|
|
4287
|
+
interface RegionPaymentProvider {
|
|
4288
|
+
id: string;
|
|
4289
|
+
regionId: string;
|
|
4290
|
+
appInstallationId: string;
|
|
4291
|
+
isEnabled: boolean;
|
|
4292
|
+
createdAt: string;
|
|
4293
|
+
}
|
|
4294
|
+
|
|
4295
|
+
interface CreateRegionDto {
|
|
4296
|
+
name: string;
|
|
4297
|
+
currency: string; // ISO 4217
|
|
4298
|
+
countries: string[]; // ISO 3166-1 alpha-2
|
|
4299
|
+
taxInclusive?: boolean;
|
|
4300
|
+
automaticTaxes?: boolean;
|
|
4301
|
+
isDefault?: boolean;
|
|
4302
|
+
paymentProviderIds?: string[]; // AppInstallation IDs to enable here
|
|
4303
|
+
}
|
|
4304
|
+
interface UpdateRegionDto extends Partial<CreateRegionDto> { isActive?: boolean }
|
|
4305
|
+
|
|
4306
|
+
// client.detectRegion(country, regions): Region | null \u2014 pure, no network.
|
|
4307
|
+
// \u2192 region whose countries includes the code, else the default region, else null.
|
|
4308
|
+
// Pass the resolved regionId to createCheckout to associate the checkout with a
|
|
4309
|
+
// region (recorded for reporting + provider scoping; currency follows the cart
|
|
4310
|
+
// until FX price conversion lands).
|
|
4311
|
+
//
|
|
4312
|
+
// Storefront (public, no apiKey \u2014 storeId mode):
|
|
4313
|
+
interface PublicRegion {
|
|
4314
|
+
id: string; name: string; slug: string; currency: string;
|
|
4315
|
+
countries: string[]; taxInclusive: boolean; isDefault: boolean;
|
|
4316
|
+
}
|
|
4317
|
+
interface PublicRegionDetail extends PublicRegion {
|
|
4318
|
+
paymentProviders: Array<{ id: string; appId: string; name: string | null }>;
|
|
4319
|
+
}
|
|
4320
|
+
// getStoreRegions(): { data: PublicRegion[] } \u2014 active regions, default first.
|
|
4321
|
+
// getStoreRegion(regionId): PublicRegionDetail \u2014 one region + its providers.
|
|
4322
|
+
|
|
4323
|
+
// ---- Tax Classes ---- (scopes: tax-classes:read / tax-classes:write)
|
|
4324
|
+
// Charge differential rates by product type. A TaxRate may target a class via
|
|
4325
|
+
// taxClassId; a rate with taxClassId=null is the Standard fallback. Per-line
|
|
4326
|
+
// resolution: variant \u2192 product \u2192 category \u2192 store default \u2192 null.
|
|
4327
|
+
interface TaxClass {
|
|
4328
|
+
id: string;
|
|
4329
|
+
accountId: string;
|
|
4330
|
+
storeId: string;
|
|
4331
|
+
name: string;
|
|
4332
|
+
slug: string; // kebab-case, unique per store
|
|
4333
|
+
description?: string | null;
|
|
4334
|
+
isDefault: boolean; // auto-applied to products without an explicit class
|
|
4335
|
+
createdAt: string;
|
|
4336
|
+
updatedAt: string;
|
|
4337
|
+
}
|
|
4338
|
+
interface CreateTaxClassDto { name: string; slug: string; description?: string; isDefault?: boolean }
|
|
4339
|
+
type UpdateTaxClassDto = Partial<CreateTaxClassDto>;
|
|
4340
|
+
// Bulk-assign a class to entities:
|
|
4341
|
+
interface AssignTaxClassDto { productIds?: string[]; variantIds?: string[]; categoryIds?: string[] }
|
|
4342
|
+
|
|
4343
|
+
// TaxRate / CreateTaxRateDto carry an optional taxClassId (null = Standard).
|
|
4344
|
+
// rate is a WHOLE PERCENTAGE (7.25 = 7.25%).
|
|
4345
|
+
//
|
|
4346
|
+
// SDK methods (admin):
|
|
4347
|
+
// Regions: getRegions(), getRegion(id), createRegion(dto), updateRegion(id, dto),
|
|
4348
|
+
// deleteRegion(id), setDefaultRegion(id), updateRegionPaymentProviders(id, ids),
|
|
4349
|
+
// addRegionCountries(id, codes), removeRegionCountry(id, code),
|
|
4350
|
+
// getRegionCompatibleProviders(id), detectRegion(country, regions)
|
|
4351
|
+
// Tax classes: getTaxClasses(), getTaxClass(id), createTaxClass(dto), updateTaxClass(id, dto),
|
|
4352
|
+
// deleteTaxClass(id), setDefaultTaxClass(id), assignTaxClass(id, dto),
|
|
4353
|
+
// mergeTaxClasses(id, targetId)`;
|
|
3853
4354
|
var TYPES_BY_DOMAIN = {
|
|
3854
4355
|
products: PRODUCTS_TYPES,
|
|
3855
4356
|
cart: CART_TYPES,
|
|
@@ -3860,7 +4361,9 @@ var TYPES_BY_DOMAIN = {
|
|
|
3860
4361
|
helpers: HELPERS_TYPES,
|
|
3861
4362
|
inquiries: INQUIRIES_TYPES,
|
|
3862
4363
|
reviews: REVIEWS_TYPES,
|
|
3863
|
-
"modifier-groups": MODIFIER_GROUPS_TYPES
|
|
4364
|
+
"modifier-groups": MODIFIER_GROUPS_TYPES,
|
|
4365
|
+
content: CONTENT_TYPES,
|
|
4366
|
+
regions: REGIONS_TYPES
|
|
3864
4367
|
};
|
|
3865
4368
|
function getTypesByDomain(domain) {
|
|
3866
4369
|
if (domain === "all") {
|
|
@@ -3891,9 +4394,12 @@ var GET_TYPE_DEFINITIONS_SCHEMA = {
|
|
|
3891
4394
|
"helpers",
|
|
3892
4395
|
"inquiries",
|
|
3893
4396
|
"reviews",
|
|
4397
|
+
"modifier-groups",
|
|
4398
|
+
"content",
|
|
4399
|
+
"regions",
|
|
3894
4400
|
"all"
|
|
3895
4401
|
]).describe(
|
|
3896
|
-
'The domain of types to retrieve. Use "helpers" for helper function signatures and common types like StoreInfo, PaginatedResponse.'
|
|
4402
|
+
'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. Use "regions" for Region / TaxClass admin types.'
|
|
3897
4403
|
)
|
|
3898
4404
|
};
|
|
3899
4405
|
async function handleGetTypeDefinitions(args) {
|
|
@@ -4440,8 +4946,10 @@ client.setLocale(locale);
|
|
|
4440
4946
|
// order bumps, search suggestions, discount banners, nudges,
|
|
4441
4947
|
// badges, order history.
|
|
4442
4948
|
|
|
4443
|
-
// For RTL
|
|
4444
|
-
//
|
|
4949
|
+
// For RTL direction, do not hardcode the locale list. Ask the SDK:
|
|
4950
|
+
// const dir = client.getStoreDirection(currentLocale); // 'ltr' | 'rtl'
|
|
4951
|
+
// document.documentElement.setAttribute('dir', dir);
|
|
4952
|
+
// (Or in React: <html dir={dir}>...</html>.)`,
|
|
4445
4953
|
"order-history-full": `// Full "My Orders" account page. Render every piece of data the server
|
|
4446
4954
|
// already returns \u2014 not just order number / total / status.
|
|
4447
4955
|
//
|
|
@@ -5533,7 +6041,7 @@ var RULES = {
|
|
|
5533
6041
|
body: `- NEVER hardcode currency, locale, or language strings. Read them from \`get-store-info\` / \`get-store-capabilities\` and use the configured values.
|
|
5534
6042
|
- NEVER format prices with \`toFixed(2)\` or custom logic. Use \`formatPrice()\` from the SDK \u2014 it honors the store's currency and locale.
|
|
5535
6043
|
- 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.
|
|
5536
|
-
- For RTL locales (\`
|
|
6044
|
+
- 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.`
|
|
5537
6045
|
},
|
|
5538
6046
|
types: {
|
|
5539
6047
|
title: "Type safety",
|
|
@@ -5581,6 +6089,7 @@ var GET_BUSINESS_FLOWS_SCHEMA = {
|
|
|
5581
6089
|
"cart-persistence",
|
|
5582
6090
|
"inventory-reservation",
|
|
5583
6091
|
"product-customization",
|
|
6092
|
+
"content-bootstrap",
|
|
5584
6093
|
"all"
|
|
5585
6094
|
]).describe('Which flow to retrieve. Use "all" to get every flow.')
|
|
5586
6095
|
};
|
|
@@ -5680,11 +6189,16 @@ Build both steps EVEN IF the store has no email provider configured today \u2014
|
|
|
5680
6189
|
});
|
|
5681
6190
|
window.location.href = authorizationUrl; // full-page redirect, NOT a popup
|
|
5682
6191
|
\`\`\`
|
|
5683
|
-
3. **On the callback page** the URL contains \`
|
|
6192
|
+
3. **On the callback page** the URL contains \`auth_code\` + \`oauth_success\` (or \`oauth_error\`) query params. Exchange the single-use code for the JWT \u2014 never read the token from the URL:
|
|
5684
6193
|
\`\`\`ts
|
|
5685
|
-
const
|
|
5686
|
-
|
|
6194
|
+
const params = new URLSearchParams(location.search);
|
|
6195
|
+
const code = params.get('auth_code');
|
|
6196
|
+
if (code) {
|
|
6197
|
+
const result = await client.exchangeOAuthCode(code);
|
|
6198
|
+
client.setCustomerToken(result.token); // then redirect to account
|
|
6199
|
+
}
|
|
5687
6200
|
\`\`\`
|
|
6201
|
+
The legacy \`?token=\` URL param is still emitted for backward compatibility but will be removed in the next major release \u2014 migrate to \`auth_code\` now.
|
|
5688
6202
|
4. **On \`oauth_error\`:** redirect to login with an error message.
|
|
5689
6203
|
|
|
5690
6204
|
Build the OAuth button region AND the callback handler even when no providers are configured. They auto-hide.`
|
|
@@ -5771,6 +6285,76 @@ Server-side guardrails that WILL reject bad requests (so validate client-side to
|
|
|
5771
6285
|
- More than 10 uploads per IP per minute \u2192 429.
|
|
5772
6286
|
|
|
5773
6287
|
Never render customization fields without also wiring the upload + metadata flow \u2014 a form that submits nothing is worse than no form at all.`
|
|
6288
|
+
},
|
|
6289
|
+
"content-bootstrap": {
|
|
6290
|
+
title: "Content Bootstrap \u2014 site chrome & static content",
|
|
6291
|
+
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\`).
|
|
6292
|
+
|
|
6293
|
+
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.
|
|
6294
|
+
\`\`\`ts
|
|
6295
|
+
const [header, footer, announcements] = await Promise.all([
|
|
6296
|
+
client.content.header.get('main', locale),
|
|
6297
|
+
client.content.footer.get('main', locale),
|
|
6298
|
+
client.content.announcement.list(locale),
|
|
6299
|
+
]);
|
|
6300
|
+
\`\`\`
|
|
6301
|
+
|
|
6302
|
+
2. **FAQ \u2014 fetch lazily on the FAQ page.** Default key is \`'main'\`; pass a topical key (\`'shipping'\`, \`'returns'\`) for sub-FAQs.
|
|
6303
|
+
\`\`\`ts
|
|
6304
|
+
const faq = await client.content.faq.get('main', locale);
|
|
6305
|
+
if (faq) {
|
|
6306
|
+
faq.data.items.forEach(({ question, answer }) => {
|
|
6307
|
+
// sanitize(answer) \u2014 see step 4
|
|
6308
|
+
});
|
|
6309
|
+
}
|
|
6310
|
+
\`\`\`
|
|
6311
|
+
|
|
6312
|
+
3. **Static pages \u2014 catch-all route by slug:**
|
|
6313
|
+
\`\`\`tsx
|
|
6314
|
+
// app/[slug]/page.tsx
|
|
6315
|
+
export default async function Page({ params }) {
|
|
6316
|
+
const page = await client.content.page.getBySlug(params.slug, locale);
|
|
6317
|
+
if (!page) notFound();
|
|
6318
|
+
return (
|
|
6319
|
+
<article dangerouslySetInnerHTML={{ __html: sanitize(page.data.html) }} />
|
|
6320
|
+
);
|
|
6321
|
+
}
|
|
6322
|
+
\`\`\`
|
|
6323
|
+
|
|
6324
|
+
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:
|
|
6325
|
+
\`\`\`ts
|
|
6326
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
6327
|
+
const safe = DOMPurify.sanitize(rawHtml);
|
|
6328
|
+
<div dangerouslySetInnerHTML={{ __html: safe }} />;
|
|
6329
|
+
\`\`\`
|
|
6330
|
+
Skipping this is XSS.
|
|
6331
|
+
|
|
6332
|
+
5. **Announcements \u2014 multiple may be active; filter by date client-side:**
|
|
6333
|
+
\`\`\`ts
|
|
6334
|
+
const now = Date.now();
|
|
6335
|
+
const visible = announcements.filter((a) => {
|
|
6336
|
+
const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
|
|
6337
|
+
const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
|
|
6338
|
+
return startOk && endOk;
|
|
6339
|
+
});
|
|
6340
|
+
\`\`\`
|
|
6341
|
+
|
|
6342
|
+
6. **RTL direction \u2014 call \`client.getStoreDirection(locale)\`:**
|
|
6343
|
+
\`\`\`tsx
|
|
6344
|
+
const dir = client.getStoreDirection(locale);
|
|
6345
|
+
<html lang={locale} dir={dir}>...</html>
|
|
6346
|
+
\`\`\`
|
|
6347
|
+
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.
|
|
6348
|
+
|
|
6349
|
+
7. **Custom fields \u2014 every Content row has free-form \`customFields: Record<string, string>\`.** Read keys the merchant told you to expect:
|
|
6350
|
+
\`\`\`ts
|
|
6351
|
+
const faq = await client.content.faq.get('shipping');
|
|
6352
|
+
<a href={\`mailto:\${faq.customFields.helpEmail}\`}>Need help?</a>
|
|
6353
|
+
\`\`\`
|
|
6354
|
+
|
|
6355
|
+
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.
|
|
6356
|
+
|
|
6357
|
+
**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.`
|
|
5774
6358
|
}
|
|
5775
6359
|
};
|
|
5776
6360
|
var FLOW_ORDER = [
|
|
@@ -5782,7 +6366,8 @@ var FLOW_ORDER = [
|
|
|
5782
6366
|
"order-confirmation",
|
|
5783
6367
|
"cart-persistence",
|
|
5784
6368
|
"inventory-reservation",
|
|
5785
|
-
"product-customization"
|
|
6369
|
+
"product-customization",
|
|
6370
|
+
"content-bootstrap"
|
|
5786
6371
|
];
|
|
5787
6372
|
async function handleGetBusinessFlows(args) {
|
|
5788
6373
|
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.";
|
|
@@ -5994,11 +6579,57 @@ var FEATURES = [
|
|
|
5994
6579
|
{
|
|
5995
6580
|
id: "i18n",
|
|
5996
6581
|
title: "Serve multiple languages with a language switcher",
|
|
5997
|
-
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
|
|
5998
|
-
sdk: "client.setLocale(locale). Read supported locales from get-store-capabilities.store.i18n.",
|
|
6582
|
+
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.",
|
|
6583
|
+
sdk: "client.setLocale(locale). client.getStoreDirection(locale) for <html dir>. Read supported locales from get-store-capabilities.store.i18n.",
|
|
5999
6584
|
mandatory: "conditional",
|
|
6000
6585
|
capabilityFlag: "i18n",
|
|
6001
6586
|
whenDisabledNote: "This store is single-language. Do not build the language switcher."
|
|
6587
|
+
},
|
|
6588
|
+
{
|
|
6589
|
+
id: "site-header",
|
|
6590
|
+
title: "Site header from merchant content (logo + nav + CTA)",
|
|
6591
|
+
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.',
|
|
6592
|
+
sdk: 'client.content.header.get("main", locale)',
|
|
6593
|
+
flowRef: "content-bootstrap",
|
|
6594
|
+
mandatory: "mandatory"
|
|
6595
|
+
},
|
|
6596
|
+
{
|
|
6597
|
+
id: "site-footer",
|
|
6598
|
+
title: "Site footer from merchant content (columns + social + copyright)",
|
|
6599
|
+
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.',
|
|
6600
|
+
sdk: 'client.content.footer.get("main", locale)',
|
|
6601
|
+
flowRef: "content-bootstrap",
|
|
6602
|
+
mandatory: "mandatory"
|
|
6603
|
+
},
|
|
6604
|
+
{
|
|
6605
|
+
id: "announcement-bar",
|
|
6606
|
+
title: "Announcement bar at the top of every page",
|
|
6607
|
+
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.",
|
|
6608
|
+
sdk: "client.content.announcement.list(locale)",
|
|
6609
|
+
flowRef: "content-bootstrap",
|
|
6610
|
+
mandatory: "conditional",
|
|
6611
|
+
capabilityFlag: "hasContent",
|
|
6612
|
+
whenDisabledNote: "Store has no published Content rows yet. Build the announcement bar anyway \u2014 it auto-hides on empty."
|
|
6613
|
+
},
|
|
6614
|
+
{
|
|
6615
|
+
id: "faq-page",
|
|
6616
|
+
title: "FAQ page rendered from merchant content",
|
|
6617
|
+
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.',
|
|
6618
|
+
sdk: 'client.content.faq.get("main", locale), client.content.faq.list(locale)',
|
|
6619
|
+
flowRef: "content-bootstrap",
|
|
6620
|
+
mandatory: "conditional",
|
|
6621
|
+
capabilityFlag: "hasContent",
|
|
6622
|
+
whenDisabledNote: "No FAQ content yet. Build /faq anyway \u2014 it auto-hides on empty."
|
|
6623
|
+
},
|
|
6624
|
+
{
|
|
6625
|
+
id: "static-pages",
|
|
6626
|
+
title: "Static pages from merchant content (About, Terms, Privacy, \u2026)",
|
|
6627
|
+
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.",
|
|
6628
|
+
sdk: "client.content.page.getBySlug(slug, locale), client.content.page.list(locale)",
|
|
6629
|
+
flowRef: "content-bootstrap",
|
|
6630
|
+
mandatory: "conditional",
|
|
6631
|
+
capabilityFlag: "hasContent",
|
|
6632
|
+
whenDisabledNote: "No static pages yet. Build the catch-all route anyway \u2014 it 404s on unknown slugs."
|
|
6002
6633
|
}
|
|
6003
6634
|
];
|
|
6004
6635
|
function isFeatureActive(feature, caps) {
|
|
@@ -6049,6 +6680,9 @@ function renderCapabilitiesSummary(caps) {
|
|
|
6049
6680
|
);
|
|
6050
6681
|
lines.push(`- Downloadable products: ${caps.features.hasDownloadableProducts ? "yes" : "no"}`);
|
|
6051
6682
|
lines.push(`- Checkout custom fields: ${caps.features.hasCheckoutCustomFields ? "yes" : "no"}`);
|
|
6683
|
+
lines.push(
|
|
6684
|
+
`- Content (FAQ/footer/header/announcements/pages): ${caps.features.hasContent ? "seeded" : "none \u2014 build chrome UI with fallbacks"}`
|
|
6685
|
+
);
|
|
6052
6686
|
lines.push(
|
|
6053
6687
|
`- Email verification: ${caps.connection.requireEmailVerification ? "required" : "not required (still build the verify-email flow)"}`
|
|
6054
6688
|
);
|