@brainerce/mcp-server 3.8.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/http.js +677 -47
- package/dist/bin/stdio.js +511 -23
- package/dist/index.d.mts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +511 -23
- package/dist/index.mjs +511 -23
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -703,7 +703,7 @@ const growProvider = providers.find(p => p.provider === 'grow');
|
|
|
703
703
|
const paypalProvider = providers.find(p => p.provider === 'paypal');
|
|
704
704
|
\`\`\`
|
|
705
705
|
|
|
706
|
-
Each provider has: \`id\`, \`provider\` (flexible string \u2014 \`'stripe'\`, \`'grow'\`, \`'paypal'\`, \`'cardcom'\`, \`'sandbox'\`, and future providers), \`name\`, \`publicKey\`, \`stripeAccountId\` (Stripe only), \`supportedMethods\`, \`testMode\`, \`isDefault\`.
|
|
706
|
+
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\`.
|
|
707
707
|
|
|
708
708
|
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**:
|
|
709
709
|
|
|
@@ -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
|
|
@@ -2249,7 +2260,17 @@ overlay needed:
|
|
|
2249
2260
|
- \`variants[].name\`
|
|
2250
2261
|
- \`variant.attributes\` keys and values \u2014 \`getVariantOptions(variant)\` returns translated attribute names and option values automatically
|
|
2251
2262
|
- \`productAttributeOptions[].attribute.name\`, \`attributeOption.name\`
|
|
2252
|
-
- \`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\`)
|
|
2253
2274
|
|
|
2254
2275
|
**Taxonomy (\`getCategories\`, \`getBrands\`, \`getTags\`):**
|
|
2255
2276
|
- \`name\` on each item
|
|
@@ -2341,6 +2362,67 @@ Read \`storeInfo.i18n.supportedLocales\` and render a switcher in the header
|
|
|
2341
2362
|
that navigates to \`/{otherLocale}/{currentPathWithoutLocale}\`. The middleware
|
|
2342
2363
|
handles the canonical redirect when the user picks the default locale.`;
|
|
2343
2364
|
}
|
|
2365
|
+
function getMultilingualSeoSection() {
|
|
2366
|
+
return `## Multilingual SEO
|
|
2367
|
+
|
|
2368
|
+
### Slugs per locale (IMPORTANT)
|
|
2369
|
+
|
|
2370
|
+
Brainerce stores per-locale slugs in \`Product.translations[locale].slug\`.
|
|
2371
|
+
The API exposes them as \`product.localeSlugs\` \u2014 a flat \`Record<string, string>\`.
|
|
2372
|
+
|
|
2373
|
+
\`\`\`typescript
|
|
2374
|
+
// product.localeSlugs = { he: '\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4', en: 'yoga-mattress', ar: '\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627' }
|
|
2375
|
+
const locSlug = product.localeSlugs?.[locale] ?? product.slug;
|
|
2376
|
+
\`\`\`
|
|
2377
|
+
|
|
2378
|
+
Use AI translation (\`translateEntities\` / the AI Translate button in the admin) to populate
|
|
2379
|
+
locale-specific slugs automatically. Until translated, all locales fall back to the base slug
|
|
2380
|
+
(which Google still accepts \u2014 it resolves to the correct locale content via Accept-Language).
|
|
2381
|
+
|
|
2382
|
+
### hreflang tags
|
|
2383
|
+
|
|
2384
|
+
Every product page in a multi-locale store MUST emit bidirectional hreflang tags or Google
|
|
2385
|
+
ignores them entirely. The scaffolded template generates them automatically when
|
|
2386
|
+
\`NEXT_PUBLIC_BRAINERCE_LOCALES=he,en\` is set.
|
|
2387
|
+
|
|
2388
|
+
\`\`\`html
|
|
2389
|
+
<!-- Example output for /en/products/yoga-mattress -->
|
|
2390
|
+
<link rel="alternate" hreflang="he" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
|
|
2391
|
+
<link rel="alternate" hreflang="en" href="https://store.com/en/products/yoga-mattress" />
|
|
2392
|
+
<link rel="alternate" hreflang="x-default" href="https://store.com/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4" />
|
|
2393
|
+
\`\`\`
|
|
2394
|
+
|
|
2395
|
+
If building a custom storefront, add to \`generateMetadata()\`:
|
|
2396
|
+
\`\`\`typescript
|
|
2397
|
+
alternates: {
|
|
2398
|
+
canonical: locale === defaultLoc ? \`/products/\${slug}\` : \`/\${locale}/products/\${slug}\`,
|
|
2399
|
+
languages: {
|
|
2400
|
+
he: \`\${baseUrl}/products/\${localeSlugs.he ?? baseSlug}\`,
|
|
2401
|
+
en: \`\${baseUrl}/en/products/\${localeSlugs.en ?? baseSlug}\`,
|
|
2402
|
+
'x-default': \`\${baseUrl}/products/\${localeSlugs[defaultLoc] ?? baseSlug}\`,
|
|
2403
|
+
},
|
|
2404
|
+
},
|
|
2405
|
+
\`\`\`
|
|
2406
|
+
|
|
2407
|
+
### URL structure
|
|
2408
|
+
|
|
2409
|
+
Google-recommended for headless storefronts:
|
|
2410
|
+
- Default locale: \`/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4\` (no prefix)
|
|
2411
|
+
- Other locales: \`/en/products/yoga-mattress\` (prefixed)
|
|
2412
|
+
- \u274C Never: \`?locale=he\` query params (Google rates these as "Not recommended")
|
|
2413
|
+
|
|
2414
|
+
### Sitemap
|
|
2415
|
+
|
|
2416
|
+
The scaffolded \`sitemap.ts\` generates per-locale entries automatically:
|
|
2417
|
+
\`\`\`
|
|
2418
|
+
/products/\u05DE\u05D6\u05E8\u05DF-\u05D9\u05D5\u05D2\u05D4 (he \u2014 default, no prefix)
|
|
2419
|
+
/en/products/yoga-mattress (en)
|
|
2420
|
+
/ar/products/\u062D\u0635\u064A\u0631\u0629-\u064A\u0648\u063A\u0627 (ar)
|
|
2421
|
+
\`\`\`
|
|
2422
|
+
|
|
2423
|
+
Hebrew, Arabic, and other non-Latin slugs are fully supported \u2014 Google recommends
|
|
2424
|
+
using the audience's language in URLs and indexes non-ASCII characters correctly.`;
|
|
2425
|
+
}
|
|
2344
2426
|
function getAdminApiSection() {
|
|
2345
2427
|
return `## Admin API (v0.19.0+)
|
|
2346
2428
|
|
|
@@ -2351,7 +2433,9 @@ const admin = new BrainerceClient({ apiKey: 'brainerce_...' });
|
|
|
2351
2433
|
|
|
2352
2434
|
// Taxonomy: listCategories(), listBrands(), listTags(), listAttributes()
|
|
2353
2435
|
// Shipping: listShippingZones(), createZoneShippingRate()
|
|
2354
|
-
// Tax: getTaxRates(), createTaxRate()
|
|
2436
|
+
// Tax: getTaxRates(), createTaxRate() \u2014 a rate may target a tax class via taxClassId
|
|
2437
|
+
// Tax classes: getTaxClasses(), createTaxClass(), assignTaxClass(), mergeTaxClasses() (scope tax-classes:*)
|
|
2438
|
+
// Regions: getRegions(), createRegion(), setDefaultRegion(), updateRegionPaymentProviders() (scope regions:*)
|
|
2355
2439
|
// Metafields: getMetafieldDefinitions(), setProductMetafield()
|
|
2356
2440
|
// Team: getTeamMembers(), inviteTeamMember()
|
|
2357
2441
|
// Email: getEmailTemplates(), createEmailTemplate()
|
|
@@ -2359,6 +2443,13 @@ const admin = new BrainerceClient({ apiKey: 'brainerce_...' });
|
|
|
2359
2443
|
// OAuth: getOAuthProviders(), configureOAuthProvider()
|
|
2360
2444
|
\`\`\`
|
|
2361
2445
|
|
|
2446
|
+
Store-level team management (\`inviteStoreMember\`, \`updateStoreMember\`) is the
|
|
2447
|
+
canonical replacement for the deprecated account-level helpers above. The
|
|
2448
|
+
invite accepts an optional \`salesChannelIds\` (vibe-coded \`connectionId\`s,
|
|
2449
|
+
\`vc_*\`) to restrict a member to specific channels \u2014 omit or pass \`[]\` for all
|
|
2450
|
+
channels. Use \`updateStoreMemberSalesChannels(storeId, memberId, { salesChannelIds })\`
|
|
2451
|
+
to change that scope later.
|
|
2452
|
+
|
|
2362
2453
|
### Per-Channel Publishing
|
|
2363
2454
|
|
|
2364
2455
|
Categories, tags, brands, and metafield definitions are gated to specific
|
|
@@ -2390,7 +2481,97 @@ calls fail with \`404 Not Found\`.
|
|
|
2390
2481
|
|
|
2391
2482
|
The vibe-coded read endpoints (used by storefront SDK calls in \`connectionId\`
|
|
2392
2483
|
mode) automatically filter by these junction tables, so storefronts never see
|
|
2393
|
-
entities that weren't published to their site
|
|
2484
|
+
entities that weren't published to their site.
|
|
2485
|
+
|
|
2486
|
+
### Tax classes (differential tax rates)
|
|
2487
|
+
|
|
2488
|
+
Charge different rates for different product types. A \`TaxRate\` may target a
|
|
2489
|
+
class via \`taxClassId\`; a rate with \`taxClassId: null\` is the **Standard
|
|
2490
|
+
fallback**. Checkout resolves each line's class **variant \u2192 product \u2192 category
|
|
2491
|
+
\u2192 store default \u2192 null**, then picks the matching rate (Standard if none).
|
|
2492
|
+
\`rate\` is a whole percentage (\`7.25\` = 7.25%). Requires the
|
|
2493
|
+
\`tax-classes:read\` / \`tax-classes:write\` scopes.
|
|
2494
|
+
|
|
2495
|
+
\`\`\`typescript
|
|
2496
|
+
const food = await admin.createTaxClass({ name: 'Food', slug: 'food' });
|
|
2497
|
+
await admin.assignTaxClass(food.id, { productIds: ['prod_1'], categoryIds: ['cat_food'] });
|
|
2498
|
+
|
|
2499
|
+
// class-specific rate \u2014 only food lines use it; everything else uses Standard
|
|
2500
|
+
await admin.createTaxRate({ name: 'VAT (Food)', rate: 0, country: 'GB', taxClassId: food.id });
|
|
2501
|
+
|
|
2502
|
+
// delete is blocked (409) while dependents exist \u2014 merge moves FKs then deletes:
|
|
2503
|
+
await admin.mergeTaxClasses(food.id, standardClassId);
|
|
2504
|
+
\`\`\`
|
|
2505
|
+
|
|
2506
|
+
Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreTaxClasses()\` lists
|
|
2507
|
+
the store's classes (storefront-safe fields only) for a transparency badge.
|
|
2508
|
+
|
|
2509
|
+
For a buyer-facing tax preview on PDP / PLP / cart, \`estimateTax({ country,
|
|
2510
|
+
subtotal })\` returns the tax portion at the Standard rate for the buyer's
|
|
2511
|
+
country. **Non-binding** \u2014 the authoritative tax still runs at checkout with
|
|
2512
|
+
the full shipping address (state / postal / per-class). Always render with an
|
|
2513
|
+
"Estimate" affordance.
|
|
2514
|
+
|
|
2515
|
+
\`\`\`typescript
|
|
2516
|
+
const { estimatedTax, rate, currency, note } = await store.estimateTax({
|
|
2517
|
+
country: 'IT', subtotal: 100,
|
|
2518
|
+
});
|
|
2519
|
+
// \u2192 { appliesTax: true, rate: 22, estimatedTax: 22, currency: 'EUR',
|
|
2520
|
+
// note: 'Estimate \u2014 final tax calculated at checkout\u2026' }
|
|
2521
|
+
\`\`\`
|
|
2522
|
+
|
|
2523
|
+
### Regions (multi-currency / per-region providers)
|
|
2524
|
+
|
|
2525
|
+
A region binds countries \u2192 currency + tax-display mode + enabled payment
|
|
2526
|
+
providers. Manage them via the SDK (scopes \`regions:read\` / \`regions:write\`).
|
|
2527
|
+
\`detectRegion\` is a pure client-side helper to map a buyer's country to a
|
|
2528
|
+
region; pass the resolved \`regionId\` to \`createCheckout\` to associate the
|
|
2529
|
+
checkout with a region (recorded for reporting + provider scoping; currency
|
|
2530
|
+
follows the cart until FX price conversion lands).
|
|
2531
|
+
|
|
2532
|
+
\`\`\`typescript
|
|
2533
|
+
const eu = await admin.createRegion({
|
|
2534
|
+
name: 'EU', currency: 'EUR', countries: ['DE', 'FR'],
|
|
2535
|
+
taxInclusive: true, paymentProviderIds: ['app_inst_stripe'],
|
|
2536
|
+
});
|
|
2537
|
+
await admin.setDefaultRegion(eu.id);
|
|
2538
|
+
|
|
2539
|
+
const { data: regions } = await admin.getRegions();
|
|
2540
|
+
const region = admin.detectRegion('DE', regions); // \u2192 eu, else default, else null
|
|
2541
|
+
\`\`\`
|
|
2542
|
+
|
|
2543
|
+
Storefront (public, no apiKey \u2014 \`storeId\` mode): \`getStoreRegions()\` lists
|
|
2544
|
+
active regions, \`getStoreRegion(id)\` returns one region + its payment providers.
|
|
2545
|
+
Pair with \`detectRegion\` to pick the buyer's region for currency display.
|
|
2546
|
+
|
|
2547
|
+
\`\`\`typescript
|
|
2548
|
+
const store = new BrainerceClient({ storeId: 'store_123' });
|
|
2549
|
+
const { data: regions } = await store.getStoreRegions();
|
|
2550
|
+
const region = await store.getStoreRegion(regions[0].id);
|
|
2551
|
+
\`\`\`
|
|
2552
|
+
|
|
2553
|
+
For a single round trip, \`getAutoRegion(country)\` resolves a buyer's country
|
|
2554
|
+
to a region server-side. Brainerce does NOT derive the country from the request
|
|
2555
|
+
IP (the storefront server is what reaches the backend, not the end-customer) \u2014
|
|
2556
|
+
your storefront extracts the country from its edge runtime (Cloudflare
|
|
2557
|
+
\`CF-IPCountry\`, Vercel \`request.geo?.country\`, Fastly \`client-geo-country\`,
|
|
2558
|
+
etc.) and forwards it. Returns \`matched=true\` on explicit country hit, \`false\`
|
|
2559
|
+
when falling back to the default region.
|
|
2560
|
+
|
|
2561
|
+
\`\`\`typescript
|
|
2562
|
+
const country = headers.get('cf-ipcountry') ?? 'US';
|
|
2563
|
+
const { region, matched } = await store.getAutoRegion(country);
|
|
2564
|
+
\`\`\`
|
|
2565
|
+
|
|
2566
|
+
A shipping zone can be limited to regions via \`regionIds\` \u2014 the zone is then
|
|
2567
|
+
only offered to checkouts that resolved to one of those regions. Empty/omitted =
|
|
2568
|
+
available for any region (default); each id must belong to the same store.
|
|
2569
|
+
|
|
2570
|
+
\`\`\`typescript
|
|
2571
|
+
await admin.createShippingZone({
|
|
2572
|
+
name: 'EU Express', countries: ['DE', 'FR', 'IT'], regionIds: [eu.id],
|
|
2573
|
+
});
|
|
2574
|
+
\`\`\``;
|
|
2394
2575
|
}
|
|
2395
2576
|
function getContactInquiriesSection() {
|
|
2396
2577
|
return `## Contact Inquiries & Forms (optional)
|
|
@@ -2845,6 +3026,146 @@ entries \u2014 pick a descriptive slug (\`'shipping'\`, \`'returns'\`, \`'about'
|
|
|
2845
3026
|
- \`get-type-definitions\` with \`domain: 'content'\` for the TypeScript
|
|
2846
3027
|
interfaces.`;
|
|
2847
3028
|
}
|
|
3029
|
+
function getBlogSection() {
|
|
3030
|
+
return `## Blog
|
|
3031
|
+
|
|
3032
|
+
Merchants write and schedule blog posts in **Content \u2192 Blog** in the dashboard.
|
|
3033
|
+
Storefronts choose their own URL scheme \u2014 render posts at \`/blog/[slug]\`,
|
|
3034
|
+
\`/articles/[slug]\`, or whatever fits the brand.
|
|
3035
|
+
|
|
3036
|
+
Public reads carry \`Cache-Control: public, max-age=300, stale-while-revalidate=60\`.
|
|
3037
|
+
|
|
3038
|
+
**Scheduling:** A post is visible once \`status === 'PUBLISHED'\` and
|
|
3039
|
+
\`publishedAt <= now()\`. Set a future \`publishedAt\` while publishing to
|
|
3040
|
+
schedule \u2014 no cron needed; visibility is computed at query time.
|
|
3041
|
+
|
|
3042
|
+
### Reading posts (any SDK mode)
|
|
3043
|
+
|
|
3044
|
+
\`\`\`typescript
|
|
3045
|
+
// List published posts
|
|
3046
|
+
const { data: posts, meta } = await client.blog.getPosts({ page: 1, limit: 10 });
|
|
3047
|
+
|
|
3048
|
+
// Filter by category or tag
|
|
3049
|
+
const { data: news } = await client.blog.getPosts({ category: 'news' });
|
|
3050
|
+
const { data: tips } = await client.blog.getPosts({ tag: 'tutorial' });
|
|
3051
|
+
|
|
3052
|
+
// Fetch one by slug (returns null on 404)
|
|
3053
|
+
const post = await client.blog.getPost('my-first-post');
|
|
3054
|
+
if (post) {
|
|
3055
|
+
console.log(post.title); // string
|
|
3056
|
+
console.log(post.content); // HTML string from rich-text editor
|
|
3057
|
+
console.log(post.excerpt); // optional short summary
|
|
3058
|
+
console.log(post.tags); // string[]
|
|
3059
|
+
console.log(post.coverImageUrl, post.coverImageAlt);
|
|
3060
|
+
console.log(post.publishedAt); // ISO 8601 or undefined
|
|
3061
|
+
}
|
|
3062
|
+
\`\`\`
|
|
3063
|
+
|
|
3064
|
+
### BlogPost fields
|
|
3065
|
+
|
|
3066
|
+
| Field | Type | Notes |
|
|
3067
|
+
| ----------------- | ----------- | ------------------------------------- |
|
|
3068
|
+
| \`id\` | string | |
|
|
3069
|
+
| \`title\` | string | |
|
|
3070
|
+
| \`slug\` | string | Unique per store, URL-safe |
|
|
3071
|
+
| \`category\` | string? | Free-form (e.g. \`'news'\`) |
|
|
3072
|
+
| \`content\` | string | HTML from rich-text editor |
|
|
3073
|
+
| \`excerpt\` | string? | Short summary for listing cards |
|
|
3074
|
+
| \`coverImageUrl\` | string? | |
|
|
3075
|
+
| \`coverImageAlt\` | string? | |
|
|
3076
|
+
| \`author\` | string? | |
|
|
3077
|
+
| \`tags\` | string[] | |
|
|
3078
|
+
| \`publishedAt\` | string? | ISO 8601; null = publish immediately |
|
|
3079
|
+
| \`seoTitle\` | string? | |
|
|
3080
|
+
| \`seoDescription\`| string? | |
|
|
3081
|
+
| \`ogImageUrl\` | string? | |
|
|
3082
|
+
|
|
3083
|
+
### Rendering blog content
|
|
3084
|
+
|
|
3085
|
+
\`\`\`tsx
|
|
3086
|
+
// app/blog/[slug]/page.tsx
|
|
3087
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
3088
|
+
|
|
3089
|
+
const post = await brainerce.blog.getPost(params.slug);
|
|
3090
|
+
if (!post) notFound();
|
|
3091
|
+
|
|
3092
|
+
// Always sanitize before rendering HTML \u2014 treat external-origin content as untrusted
|
|
3093
|
+
const safeHtml = DOMPurify.sanitize(post.content);
|
|
3094
|
+
return <div dangerouslySetInnerHTML={{ __html: safeHtml }} className="prose" />;
|
|
3095
|
+
\`\`\`
|
|
3096
|
+
|
|
3097
|
+
The \`content\` field is HTML produced by the Lexical rich-text editor.
|
|
3098
|
+
**Always sanitize with DOMPurify (or equivalent) before rendering via
|
|
3099
|
+
\`dangerouslySetInnerHTML\`** \u2014 even though the content originates from your
|
|
3100
|
+
own editor, defense-in-depth prevents any stored-XSS path if content is ever
|
|
3101
|
+
migrated or imported from an external source.
|
|
3102
|
+
Apply a \`prose\` class (Tailwind Typography) for automatic styling.
|
|
3103
|
+
|
|
3104
|
+
### REST endpoints
|
|
3105
|
+
|
|
3106
|
+
| Method | Path | Returns |
|
|
3107
|
+
|--------|------|---------|
|
|
3108
|
+
| GET | \`/api/stores/:storeId/blog/posts\` | \`BlogPostListResponse\` |
|
|
3109
|
+
| GET | \`/api/stores/:storeId/blog/posts/:slug\` | \`BlogPost\` or 404 |
|
|
3110
|
+
| GET | \`/api/vc/:connectionId/blog/posts\` | Same, channel-scoped |
|
|
3111
|
+
| GET | \`/api/vc/:connectionId/blog/posts/:slug\` | \`BlogPost\` or 404 |
|
|
3112
|
+
`;
|
|
3113
|
+
}
|
|
3114
|
+
function getStorefrontBotSection(connectionId) {
|
|
3115
|
+
return `## Storefront Bot (AI chat widget)
|
|
3116
|
+
|
|
3117
|
+
The store's AI shopping assistant. ALL configuration (name, avatar, colors,
|
|
3118
|
+
greeting, starter questions, capabilities, guardrails) lives in the merchant
|
|
3119
|
+
dashboard \u2014 the embed never decides behavior, and the widget renders nothing
|
|
3120
|
+
until the merchant switches the bot Live.
|
|
3121
|
+
|
|
3122
|
+
### Zero-code embed (any site)
|
|
3123
|
+
|
|
3124
|
+
\`\`\`html
|
|
3125
|
+
<script src="https://cdn.brainerce.com/bot.js" data-connection-id="${connectionId}" defer></script>
|
|
3126
|
+
\`\`\`
|
|
3127
|
+
|
|
3128
|
+
Keep the tag exactly this bare \u2014 do NOT add \`integrity\` or \`crossorigin\`
|
|
3129
|
+
(the bootstrap is intentionally mutable; it is origin-pinned by CSP instead).
|
|
3130
|
+
|
|
3131
|
+
### SDK mount (React / Next.js / any bundler)
|
|
3132
|
+
|
|
3133
|
+
\`\`\`ts
|
|
3134
|
+
import { BrainerceBot } from 'brainerce/bot';
|
|
3135
|
+
|
|
3136
|
+
// client-side only (e.g. in a useEffect) \u2014 mounts a floating chat bubble
|
|
3137
|
+
const bot = await BrainerceBot.mount({ connectionId: '${connectionId}' });
|
|
3138
|
+
bot?.destroy(); // optional teardown
|
|
3139
|
+
\`\`\`
|
|
3140
|
+
|
|
3141
|
+
\`mount\` resolves to \`null\` when the bot is disabled (FREE plan, switched
|
|
3142
|
+
off, or unconfigured) \u2014 safe to call unconditionally. Options: \`connectionId\`
|
|
3143
|
+
(required), \`baseUrl\` (API origin override), \`target\` (mount element),
|
|
3144
|
+
\`onAddToCart\` (\`({ productId, variantId, quantity }) => boolean | Promise<boolean>\`
|
|
3145
|
+
\u2014 route the widget's cart adds through the site's own cart; \`variantId\` is
|
|
3146
|
+
null for simple products; return false to fall back to the product page).
|
|
3147
|
+
|
|
3148
|
+
Behavior: persists an anonymous session in localStorage, restores the
|
|
3149
|
+
conversation on revisit, streams answers, and shows product recommendation
|
|
3150
|
+
cards (image, price, add-to-cart / view). Multi-variant products get an
|
|
3151
|
+
in-card variant picker; shoppers can also ask the assistant to add an item
|
|
3152
|
+
and it goes through the same cart chain. Zero-result searches feed the
|
|
3153
|
+
merchant's "unmet demand" analytics. Aside from shopper-initiated cart adds,
|
|
3154
|
+
the bot is read-only.
|
|
3155
|
+
|
|
3156
|
+
Add-to-cart resolution chain: \`onAddToCart\` option \u2192 cancelable
|
|
3157
|
+
\`brainerce:bot:add-to-cart\` CustomEvent on window
|
|
3158
|
+
(\`detail: { productId, variantId, quantity, connectionId }\`; call
|
|
3159
|
+
preventDefault() after handling) \u2192 navigate to the product page.
|
|
3160
|
+
|
|
3161
|
+
Rules:
|
|
3162
|
+
- Mount once per page; do not pass any visual config \u2014 the dashboard owns it.
|
|
3163
|
+
- Do not wrap or restyle the widget; it renders in its own Shadow DOM.
|
|
3164
|
+
- Product card links expect the conventional \`/products/<slug>\` route.
|
|
3165
|
+
- Wire \`onAddToCart\` to the site's cart (see the cart section) so the header
|
|
3166
|
+
count updates when the bot adds items.
|
|
3167
|
+
`;
|
|
3168
|
+
}
|
|
2848
3169
|
function getSectionByTopic(topic, connectionId, currency) {
|
|
2849
3170
|
const cid = connectionId || "vc_YOUR_CONNECTION_ID";
|
|
2850
3171
|
const cur = currency || "USD";
|
|
@@ -2883,6 +3204,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2883
3204
|
return getTaxDisplaySection(cur);
|
|
2884
3205
|
case "i18n":
|
|
2885
3206
|
return getI18nSection();
|
|
3207
|
+
case "multilingual-seo":
|
|
3208
|
+
case "hreflang":
|
|
3209
|
+
case "seo-i18n":
|
|
3210
|
+
return getMultilingualSeoSection();
|
|
2886
3211
|
case "critical-rules":
|
|
2887
3212
|
return getCriticalRulesSection() + "\n\n" + getTypeQuickReference();
|
|
2888
3213
|
case "type-reference":
|
|
@@ -2893,6 +3218,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2893
3218
|
return getContactInquiriesSection();
|
|
2894
3219
|
case "content":
|
|
2895
3220
|
return getContentSection();
|
|
3221
|
+
case "blog":
|
|
3222
|
+
return getBlogSection();
|
|
3223
|
+
case "storefront-bot":
|
|
3224
|
+
return getStorefrontBotSection(cid);
|
|
2896
3225
|
case "all":
|
|
2897
3226
|
return [
|
|
2898
3227
|
"# Brainerce SDK \u2014 full topic dump",
|
|
@@ -2977,6 +3306,10 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2977
3306
|
"",
|
|
2978
3307
|
"---",
|
|
2979
3308
|
"",
|
|
3309
|
+
getMultilingualSeoSection(),
|
|
3310
|
+
"",
|
|
3311
|
+
"---",
|
|
3312
|
+
"",
|
|
2980
3313
|
getAdminApiSection(),
|
|
2981
3314
|
"",
|
|
2982
3315
|
"---",
|
|
@@ -2985,10 +3318,18 @@ function getSectionByTopic(topic, connectionId, currency) {
|
|
|
2985
3318
|
"",
|
|
2986
3319
|
"---",
|
|
2987
3320
|
"",
|
|
2988
|
-
getContentSection()
|
|
3321
|
+
getContentSection(),
|
|
3322
|
+
"",
|
|
3323
|
+
"---",
|
|
3324
|
+
"",
|
|
3325
|
+
getBlogSection(),
|
|
3326
|
+
"",
|
|
3327
|
+
"---",
|
|
3328
|
+
"",
|
|
3329
|
+
getStorefrontBotSection(cid)
|
|
2989
3330
|
].join("\n");
|
|
2990
3331
|
default:
|
|
2991
|
-
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`;
|
|
3332
|
+
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`;
|
|
2992
3333
|
}
|
|
2993
3334
|
}
|
|
2994
3335
|
|
|
@@ -3017,6 +3358,7 @@ var GET_SDK_DOCS_SCHEMA = {
|
|
|
3017
3358
|
"admin",
|
|
3018
3359
|
"inquiries",
|
|
3019
3360
|
"content",
|
|
3361
|
+
"storefront-bot",
|
|
3020
3362
|
"all"
|
|
3021
3363
|
]).describe("The SDK documentation topic to retrieve"),
|
|
3022
3364
|
salesChannelId: z.string().optional().describe("Sales channel ID (starts with vc_). Used to personalize setup code."),
|
|
@@ -3048,12 +3390,18 @@ interface Product {
|
|
|
3048
3390
|
description?: string | null;
|
|
3049
3391
|
descriptionFormat?: 'text' | 'html' | 'markdown' | null;
|
|
3050
3392
|
sku: string;
|
|
3051
|
-
basePrice: string; //
|
|
3052
|
-
salePrice?: string | null;
|
|
3393
|
+
basePrice: string; // For VARIABLE products: MIN(variants.price). For SIMPLE: the parent price. parseFloat() for math.
|
|
3394
|
+
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.
|
|
3053
3395
|
costPrice?: string | null;
|
|
3054
|
-
priceMin?: string | null; // Lowest variant price (VARIABLE products)
|
|
3055
|
-
priceMax?: string | null; // Highest variant price (VARIABLE products).
|
|
3396
|
+
priceMin?: string | null; // Lowest variant price (VARIABLE products) \u2014 same as basePrice for VARIABLE, kept for back-compat and JSON-LD range display.
|
|
3397
|
+
priceMax?: string | null; // Highest variant price (VARIABLE products). Use with priceMin for "\u20AA49 \u2013 \u20AA199" range.
|
|
3056
3398
|
priceVaries?: boolean; // true when variant prices differ \u2014 show "\u20AA49 \u2013 \u20AA199" range.
|
|
3399
|
+
// 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.
|
|
3400
|
+
displayPrice?: string; // basePrice \xD7 daily FX rate, in displayCurrency.
|
|
3401
|
+
displaySalePrice?: string; // salePrice \xD7 rate (if salePrice present).
|
|
3402
|
+
displayPriceMin?: string; // priceMin \xD7 rate (VARIABLE products).
|
|
3403
|
+
displayPriceMax?: string; // priceMax \xD7 rate (VARIABLE products).
|
|
3404
|
+
displayCurrency?: string; // ISO 4217 of the region \u2014 e.g. "EUR".
|
|
3057
3405
|
status: string;
|
|
3058
3406
|
type: 'SIMPLE' | 'VARIABLE';
|
|
3059
3407
|
isDownloadable?: boolean;
|
|
@@ -3097,6 +3445,10 @@ interface ProductVariant {
|
|
|
3097
3445
|
name?: string | null;
|
|
3098
3446
|
price?: string | null;
|
|
3099
3447
|
salePrice?: string | null;
|
|
3448
|
+
// FX DISPLAY overlay (PRD \xA723) \u2014 same semantics as on the parent Product.
|
|
3449
|
+
displayPrice?: string;
|
|
3450
|
+
displaySalePrice?: string;
|
|
3451
|
+
displayCurrency?: string;
|
|
3100
3452
|
attributes?: Record<string, string> | null;
|
|
3101
3453
|
options?: Array<{ name: string; value: string }>;
|
|
3102
3454
|
inventory?: InventoryInfo | null;
|
|
@@ -3168,6 +3520,11 @@ interface ProductQueryParams {
|
|
|
3168
3520
|
metafields?: Record<string, string | string[]>;
|
|
3169
3521
|
sortBy?: 'name' | 'price' | 'createdAt';
|
|
3170
3522
|
sortOrder?: 'asc' | 'desc';
|
|
3523
|
+
// PRD \xA722: resolve DISPLAY prices for this region. When set + valid, each
|
|
3524
|
+
// product/variant gains resolvedPrice/resolvedCurrency/priceSource (additive;
|
|
3525
|
+
// basePrice/salePrice untouched). Absent/invalid region \u2192 nothing attached.
|
|
3526
|
+
// Display-only. Ignored in vibe-coded (vc_*) mode (storefront/admin paths only).
|
|
3527
|
+
regionId?: string;
|
|
3171
3528
|
}
|
|
3172
3529
|
|
|
3173
3530
|
interface SearchSuggestions {
|
|
@@ -3293,6 +3650,7 @@ interface Checkout {
|
|
|
3293
3650
|
status: CheckoutStatus;
|
|
3294
3651
|
email?: string | null;
|
|
3295
3652
|
customerId?: string | null;
|
|
3653
|
+
regionId?: string | null; // multi-region: recorded for reporting + provider scoping (currency follows the cart until FX lands)
|
|
3296
3654
|
shippingAddress?: CheckoutAddress | null;
|
|
3297
3655
|
billingAddress?: CheckoutAddress | null;
|
|
3298
3656
|
shippingRateId?: string | null;
|
|
@@ -3369,6 +3727,7 @@ interface CreateCheckoutDto {
|
|
|
3369
3727
|
cartId: string;
|
|
3370
3728
|
customerId?: string;
|
|
3371
3729
|
selectedItemIds?: string[]; // Partial checkout
|
|
3730
|
+
regionId?: string; // multi-region: associate the checkout with a region (must belong to the store; 400 if unknown)
|
|
3372
3731
|
}
|
|
3373
3732
|
|
|
3374
3733
|
// startGuestCheckout() return type \u2014 DISCRIMINATED UNION
|
|
@@ -3387,6 +3746,8 @@ interface TaxBreakdownItem {
|
|
|
3387
3746
|
name: string;
|
|
3388
3747
|
rate: number; // decimal: 0.17 = 17%
|
|
3389
3748
|
amount: number;
|
|
3749
|
+
taxClassId?: string | null; // rate's tax class (null = Standard)
|
|
3750
|
+
taxClassSlug?: string | null; // class slug for attribution (null = Standard)
|
|
3390
3751
|
}`;
|
|
3391
3752
|
var ORDERS_TYPES = `// ---- Orders ----
|
|
3392
3753
|
|
|
@@ -3444,6 +3805,7 @@ interface OrderItem {
|
|
|
3444
3805
|
// Snapshot of buyer-submitted customization values captured at checkout.
|
|
3445
3806
|
// Keyed by metafield slug. \`value\` is string[] for MULTI_SELECT / GALLERY, string otherwise.
|
|
3446
3807
|
customizations?: Record<string, { label: string; value: string | string[]; type: string }>;
|
|
3808
|
+
taxClassSlug?: string; // frozen slug of the line's resolved tax class (omitted = Standard fallback)
|
|
3447
3809
|
}
|
|
3448
3810
|
|
|
3449
3811
|
interface OrderCustomer {
|
|
@@ -3626,7 +3988,7 @@ function formatPrice(priceString: string | number | undefined | null, options?:
|
|
|
3626
3988
|
function getProductPrice(product: Pick<Product, 'basePrice' | 'salePrice'>): number;
|
|
3627
3989
|
function getProductPriceInfo(product: Pick<Product, 'basePrice' | 'salePrice' | 'discount' | 'priceMin' | 'priceVaries'>): {
|
|
3628
3990
|
price: number; originalPrice: number; isOnSale: boolean; discountAmount: number; discountPercent: number;
|
|
3629
|
-
}; //
|
|
3991
|
+
}; // 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.
|
|
3630
3992
|
function getVariantPrice(variant: Pick<ProductVariant, 'price' | 'salePrice'>, productBasePrice: string): number;
|
|
3631
3993
|
|
|
3632
3994
|
// Cart helpers
|
|
@@ -4159,6 +4521,122 @@ export interface Content<T extends ContentType = ContentType> extends ContentSum
|
|
|
4159
4521
|
// stale-while-revalidate=60. Storefront changes propagate within ~5 min
|
|
4160
4522
|
// of the merchant publishing. Do not add extra client-side caching
|
|
4161
4523
|
// beyond Next.js's default fetch cache.`;
|
|
4524
|
+
var REGIONS_TYPES = `// ---- Regions & Tax Classes (Admin mode, apiKey) ----
|
|
4525
|
+
// storeId is derived from the API key \u2014 never pass it on admin calls.
|
|
4526
|
+
|
|
4527
|
+
// ---- Regions ---- (scopes: regions:read / regions:write)
|
|
4528
|
+
// A region binds countries \u2192 currency + tax-display mode + payment providers.
|
|
4529
|
+
interface Region {
|
|
4530
|
+
id: string;
|
|
4531
|
+
accountId: string;
|
|
4532
|
+
storeId: string;
|
|
4533
|
+
name: string;
|
|
4534
|
+
slug: string;
|
|
4535
|
+
currency: string; // ISO 4217, e.g. "EUR"
|
|
4536
|
+
countries: string[]; // ISO 3166-1 alpha-2, e.g. ["DE","FR"]
|
|
4537
|
+
taxInclusive: boolean; // show prices tax-inclusive in this region?
|
|
4538
|
+
automaticTaxes: boolean;
|
|
4539
|
+
isDefault: boolean; // fallback when buyer's country maps to no region
|
|
4540
|
+
isActive: boolean;
|
|
4541
|
+
paymentProviders?: RegionPaymentProvider[];
|
|
4542
|
+
createdAt: string;
|
|
4543
|
+
updatedAt: string;
|
|
4544
|
+
}
|
|
4545
|
+
|
|
4546
|
+
interface RegionPaymentProvider {
|
|
4547
|
+
id: string;
|
|
4548
|
+
regionId: string;
|
|
4549
|
+
appInstallationId: string;
|
|
4550
|
+
isEnabled: boolean;
|
|
4551
|
+
createdAt: string;
|
|
4552
|
+
}
|
|
4553
|
+
|
|
4554
|
+
interface CreateRegionDto {
|
|
4555
|
+
name: string;
|
|
4556
|
+
currency: string; // ISO 4217
|
|
4557
|
+
countries: string[]; // ISO 3166-1 alpha-2
|
|
4558
|
+
taxInclusive?: boolean;
|
|
4559
|
+
automaticTaxes?: boolean;
|
|
4560
|
+
isDefault?: boolean;
|
|
4561
|
+
paymentProviderIds?: string[]; // AppInstallation IDs to enable here
|
|
4562
|
+
}
|
|
4563
|
+
interface UpdateRegionDto extends Partial<CreateRegionDto> { isActive?: boolean }
|
|
4564
|
+
|
|
4565
|
+
// client.detectRegion(country, regions): Region | null \u2014 pure, no network.
|
|
4566
|
+
// \u2192 region whose countries includes the code, else the default region, else null.
|
|
4567
|
+
// Pass the resolved regionId to createCheckout to associate the checkout with a
|
|
4568
|
+
// region (recorded for reporting + provider scoping; currency follows the cart
|
|
4569
|
+
// until FX price conversion lands).
|
|
4570
|
+
//
|
|
4571
|
+
// Storefront (public, no apiKey \u2014 storeId mode):
|
|
4572
|
+
interface PublicRegion {
|
|
4573
|
+
id: string; name: string; slug: string; currency: string;
|
|
4574
|
+
countries: string[]; taxInclusive: boolean; isDefault: boolean;
|
|
4575
|
+
}
|
|
4576
|
+
interface PublicRegionDetail extends PublicRegion {
|
|
4577
|
+
paymentProviders: Array<{ id: string; appId: string; name: string | null }>;
|
|
4578
|
+
}
|
|
4579
|
+
// getStoreRegions(): { data: PublicRegion[] } \u2014 active regions, default first.
|
|
4580
|
+
// getStoreRegion(regionId): PublicRegionDetail \u2014 one region + its providers.
|
|
4581
|
+
interface AutoRegionResponse {
|
|
4582
|
+
region: PublicRegion | null;
|
|
4583
|
+
matched: boolean; // true=country was in a region's list; false=fell back to default
|
|
4584
|
+
country: string; // upper-cased ISO-3166-1 alpha-2; '' when caller omitted it
|
|
4585
|
+
}
|
|
4586
|
+
// getAutoRegion(country): AutoRegionResponse \u2014 server-side resolution in one
|
|
4587
|
+
// round trip. Pair with the country your edge runtime extracts
|
|
4588
|
+
// (CF-IPCountry / request.geo.country / etc.) \u2014 Brainerce does NOT derive the
|
|
4589
|
+
// country from the request IP server-side (storefront != end-customer).
|
|
4590
|
+
|
|
4591
|
+
// ---- Tax Classes ---- (scopes: tax-classes:read / tax-classes:write)
|
|
4592
|
+
// Charge differential rates by product type. A TaxRate may target a class via
|
|
4593
|
+
// taxClassId; a rate with taxClassId=null is the Standard fallback. Per-line
|
|
4594
|
+
// resolution: variant \u2192 product \u2192 category \u2192 store default \u2192 null.
|
|
4595
|
+
interface TaxClass {
|
|
4596
|
+
id: string;
|
|
4597
|
+
accountId: string;
|
|
4598
|
+
storeId: string;
|
|
4599
|
+
name: string;
|
|
4600
|
+
slug: string; // kebab-case, unique per store
|
|
4601
|
+
description?: string | null;
|
|
4602
|
+
isDefault: boolean; // auto-applied to products without an explicit class
|
|
4603
|
+
createdAt: string;
|
|
4604
|
+
updatedAt: string;
|
|
4605
|
+
}
|
|
4606
|
+
interface CreateTaxClassDto { name: string; slug: string; description?: string; isDefault?: boolean }
|
|
4607
|
+
type UpdateTaxClassDto = Partial<CreateTaxClassDto>;
|
|
4608
|
+
// Bulk-assign a class to entities:
|
|
4609
|
+
interface AssignTaxClassDto { productIds?: string[]; variantIds?: string[]; categoryIds?: string[] }
|
|
4610
|
+
|
|
4611
|
+
// TaxRate / CreateTaxRateDto carry an optional taxClassId (null = Standard).
|
|
4612
|
+
// rate is a WHOLE PERCENTAGE (7.25 = 7.25%).
|
|
4613
|
+
//
|
|
4614
|
+
// SDK methods (admin):
|
|
4615
|
+
// Regions: getRegions(), getRegion(id), createRegion(dto), updateRegion(id, dto),
|
|
4616
|
+
// deleteRegion(id), setDefaultRegion(id), updateRegionPaymentProviders(id, ids),
|
|
4617
|
+
// addRegionCountries(id, codes), removeRegionCountry(id, code),
|
|
4618
|
+
// getRegionCompatibleProviders(id), detectRegion(country, regions)
|
|
4619
|
+
// Tax classes: getTaxClasses(), getTaxClass(id), createTaxClass(dto), updateTaxClass(id, dto),
|
|
4620
|
+
// deleteTaxClass(id), setDefaultTaxClass(id), assignTaxClass(id, dto),
|
|
4621
|
+
// mergeTaxClasses(id, targetId)
|
|
4622
|
+
//
|
|
4623
|
+
// SDK methods (storefront, public \u2014 storeId mode, no apiKey):
|
|
4624
|
+
// getStoreRegions(), getStoreRegion(id), getAutoRegion(country)
|
|
4625
|
+
// getStoreTaxClasses(), estimateTax({ country?, subtotal })
|
|
4626
|
+
//
|
|
4627
|
+
// estimateTax returns:
|
|
4628
|
+
interface TaxEstimateResponse {
|
|
4629
|
+
appliesTax: boolean;
|
|
4630
|
+
rate: number | null; // percent (18 = 18%) \u2014 null when no matching rule
|
|
4631
|
+
rateName: string | null;
|
|
4632
|
+
estimatedTax: number; // tax portion of subtotal in store currency
|
|
4633
|
+
pricesIncludeTax: boolean;
|
|
4634
|
+
currency: string; // store currency (cart/order currency)
|
|
4635
|
+
note: string; // disclaimer \u2014 preview is non-binding
|
|
4636
|
+
}
|
|
4637
|
+
// Non-binding by design: the authoritative tax runs at checkout against the
|
|
4638
|
+
// full shipping address. The country comes from your edge runtime
|
|
4639
|
+
// (CF-IPCountry / request.geo.country / etc.), NOT the request IP.`;
|
|
4162
4640
|
var TYPES_BY_DOMAIN = {
|
|
4163
4641
|
products: PRODUCTS_TYPES,
|
|
4164
4642
|
cart: CART_TYPES,
|
|
@@ -4170,7 +4648,8 @@ var TYPES_BY_DOMAIN = {
|
|
|
4170
4648
|
inquiries: INQUIRIES_TYPES,
|
|
4171
4649
|
reviews: REVIEWS_TYPES,
|
|
4172
4650
|
"modifier-groups": MODIFIER_GROUPS_TYPES,
|
|
4173
|
-
content: CONTENT_TYPES
|
|
4651
|
+
content: CONTENT_TYPES,
|
|
4652
|
+
regions: REGIONS_TYPES
|
|
4174
4653
|
};
|
|
4175
4654
|
function getTypesByDomain(domain) {
|
|
4176
4655
|
if (domain === "all") {
|
|
@@ -4201,10 +4680,12 @@ var GET_TYPE_DEFINITIONS_SCHEMA = {
|
|
|
4201
4680
|
"helpers",
|
|
4202
4681
|
"inquiries",
|
|
4203
4682
|
"reviews",
|
|
4683
|
+
"modifier-groups",
|
|
4204
4684
|
"content",
|
|
4685
|
+
"regions",
|
|
4205
4686
|
"all"
|
|
4206
4687
|
]).describe(
|
|
4207
|
-
'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.'
|
|
4688
|
+
'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.'
|
|
4208
4689
|
)
|
|
4209
4690
|
};
|
|
4210
4691
|
async function handleGetTypeDefinitions(args) {
|
|
@@ -5994,11 +6475,16 @@ Build both steps EVEN IF the store has no email provider configured today \u2014
|
|
|
5994
6475
|
});
|
|
5995
6476
|
window.location.href = authorizationUrl; // full-page redirect, NOT a popup
|
|
5996
6477
|
\`\`\`
|
|
5997
|
-
3. **On the callback page** the URL contains \`
|
|
6478
|
+
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:
|
|
5998
6479
|
\`\`\`ts
|
|
5999
|
-
const
|
|
6000
|
-
|
|
6480
|
+
const params = new URLSearchParams(location.search);
|
|
6481
|
+
const code = params.get('auth_code');
|
|
6482
|
+
if (code) {
|
|
6483
|
+
const result = await client.exchangeOAuthCode(code);
|
|
6484
|
+
client.setCustomerToken(result.token); // then redirect to account
|
|
6485
|
+
}
|
|
6001
6486
|
\`\`\`
|
|
6487
|
+
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.
|
|
6002
6488
|
4. **On \`oauth_error\`:** redirect to login with an error message.
|
|
6003
6489
|
|
|
6004
6490
|
Build the OAuth button region AND the callback handler even when no providers are configured. They auto-hide.`
|
|
@@ -6480,7 +6966,9 @@ function renderCapabilitiesSummary(caps) {
|
|
|
6480
6966
|
);
|
|
6481
6967
|
lines.push(`- Downloadable products: ${caps.features.hasDownloadableProducts ? "yes" : "no"}`);
|
|
6482
6968
|
lines.push(`- Checkout custom fields: ${caps.features.hasCheckoutCustomFields ? "yes" : "no"}`);
|
|
6483
|
-
lines.push(
|
|
6969
|
+
lines.push(
|
|
6970
|
+
`- Content (FAQ/footer/header/announcements/pages): ${caps.features.hasContent ? "seeded" : "none \u2014 build chrome UI with fallbacks"}`
|
|
6971
|
+
);
|
|
6484
6972
|
lines.push(
|
|
6485
6973
|
`- Email verification: ${caps.connection.requireEmailVerification ? "required" : "not required (still build the verify-email flow)"}`
|
|
6486
6974
|
);
|