create-brainerce-store 1.43.1 → 1.43.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  "package.json"(exports2, module2) {
32
32
  module2.exports = {
33
33
  name: "create-brainerce-store",
34
- version: "1.43.1",
34
+ version: "1.43.2",
35
35
  description: "Scaffold a production-ready e-commerce storefront connected to Brainerce",
36
36
  bin: {
37
37
  "create-brainerce-store": "dist/index.js"
@@ -172,12 +172,12 @@ var ALLOWED_PACKAGE_MANAGERS = [
172
172
  "bun"
173
173
  ];
174
174
  var BRAINERCE_RUNTIME_DEPS = Object.freeze({
175
- // 1.27 = first published cut with client.content namespace (FAQ / Footer /
176
- // Header / Announcement / RichText / Page) + getDirectionForLocale helper.
177
- // Scaffolded stores need this minimum to use the content components shipped
178
- // under src/components/content/ and the homepage RichTextBlock mount-point.
179
- // 1.26 had the namespace in source but was published before the cut.
180
- brainerce: "^1.27.0",
175
+ // 1.28 = first cut after the PriceList API removal + the FX-driven display
176
+ // pricing rework (Product.displayPrice / displayCurrency / displaySalePrice
177
+ // attached additively when getProducts is called with a regionId). Older
178
+ // 1.27 had PriceList/Resolved* surface that no longer exists on the
179
+ // backend, so scaffolded stores must pin >=1.28 to compile.
180
+ brainerce: "^1.28.0",
181
181
  "isomorphic-dompurify": "^3.8.0"
182
182
  });
183
183
 
@@ -555,7 +555,10 @@ async function fetchStoreInfo(connectionId, baseUrl = KNOWN_API_URLS.production)
555
555
  const timeout = setTimeout(() => controller.abort(), 1e4);
556
556
  let res;
557
557
  try {
558
- res = await fetch(url, { signal: controller.signal });
558
+ res = await fetch(url, {
559
+ signal: controller.signal,
560
+ headers: { Origin: "http://localhost" }
561
+ });
559
562
  } catch (err) {
560
563
  if (err.name === "AbortError") {
561
564
  throw new Error(`Request to ${baseUrl} timed out`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-brainerce-store",
3
- "version": "1.43.1",
3
+ "version": "1.43.2",
4
4
  "description": "Scaffold a production-ready e-commerce storefront connected to Brainerce",
5
5
  "bin": {
6
6
  "create-brainerce-store": "dist/index.js"
@@ -53,7 +53,14 @@ console.log(`Fetching store info for sales channel: ${connectionId} ...`);
53
53
 
54
54
  let storeInfo;
55
55
  try {
56
- const res = await fetch(`${apiUrl}/api/vc/${connectionId}/info`);
56
+ // /api/vc/* enforces an Origin check: TEST channels accept local/tunnel
57
+ // hosts, LIVE channels require the configured domain. Prefer the project's
58
+ // own NEXT_PUBLIC_SITE_URL (the real domain for a LIVE store), falling back
59
+ // to localhost for local dev against a TEST channel.
60
+ const siteUrl = getVar(envContent, 'NEXT_PUBLIC_SITE_URL') || 'http://localhost:3000';
61
+ const res = await fetch(`${apiUrl}/api/vc/${connectionId}/info`, {
62
+ headers: { Origin: siteUrl },
63
+ });
57
64
  if (!res.ok) {
58
65
  console.error(`❌ API returned ${res.status}: ${await res.text()}`);
59
66
  process.exit(1);
@@ -18,6 +18,41 @@ interface ProductCardProps {
18
18
  className?: string;
19
19
  }
20
20
 
21
+ /**
22
+ * Pick the price + currency to render for a given product (PRD §23 FX overlay).
23
+ *
24
+ * When the storefront passed `regionId` to `getProducts({ regionId })` AND the
25
+ * region currency differs from the store currency, the backend attaches
26
+ * additive `displayPrice` / `displayCurrency` fields. Otherwise we fall back
27
+ * to the canonical store-currency `basePrice` / `salePrice`. Either way the
28
+ * cart still charges in the store currency — this only affects display.
29
+ */
30
+ function pickDisplayPrice(
31
+ product: Product,
32
+ fallbackCurrency: string
33
+ ): { price: number | undefined; salePrice: number | null; currency: string } {
34
+ if (product.displayPrice != null && product.displayCurrency) {
35
+ const sale =
36
+ product.displaySalePrice != null ? parseFloat(product.displaySalePrice) : null;
37
+ return {
38
+ // `displayPrice` is the base price converted to the region currency —
39
+ // it goes into the PriceDisplay `price` (base) slot, NOT the sale slot.
40
+ price: parseFloat(product.displayPrice),
41
+ salePrice: sale != null && !Number.isNaN(sale) ? sale : null,
42
+ currency: product.displayCurrency,
43
+ };
44
+ }
45
+ // Same-currency fallback. `getProductPriceInfo.price` is the EFFECTIVE
46
+ // charged amount (= salePrice when on sale, base otherwise); `originalPrice`
47
+ // is the base. Map them to PriceDisplay's (price = base, salePrice = sale).
48
+ const { price: effective, originalPrice, isOnSale } = getProductPriceInfo(product);
49
+ return {
50
+ price: originalPrice,
51
+ salePrice: isOnSale ? effective : null,
52
+ currency: fallbackCurrency,
53
+ };
54
+ }
55
+
21
56
  function VariantPriceRange({ product }: { product: Product }) {
22
57
  const currency = useCurrency();
23
58
 
@@ -51,6 +86,11 @@ export function ProductCard({ product, className }: ProductCardProps) {
51
86
  const tProd = useTranslations('products');
52
87
  const router = useRouter();
53
88
  const { refreshCart } = useCart();
89
+ const fallbackCurrency = useCurrency();
90
+ // FX overlay (PRD §23): prefer the region-converted display values when the
91
+ // storefront passed regionId to getProducts. Otherwise fall back to the
92
+ // canonical store-currency basePrice / salePrice.
93
+ const display = pickDisplayPrice(product, fallbackCurrency);
54
94
  const { price, originalPrice, isOnSale } = getProductPriceInfo(product);
55
95
  const mainImage = product.images?.[0];
56
96
  const imageUrl = mainImage?.url || null;
@@ -215,7 +255,12 @@ export function ProductCard({ product, className }: ProductCardProps) {
215
255
  {isVariable ? (
216
256
  <VariantPriceRange product={product} />
217
257
  ) : (
218
- <PriceDisplay price={originalPrice} salePrice={isOnSale ? price : undefined} size="sm" />
258
+ <PriceDisplay
259
+ price={display.price ?? originalPrice}
260
+ salePrice={display.salePrice ?? (isOnSale ? price : undefined)}
261
+ currency={display.currency}
262
+ size="sm"
263
+ />
219
264
  )}
220
265
 
221
266
  {/* Stock */}