create-brainerce-store 1.43.0 → 1.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/index.js +1 -1
  2. package/messages/en.json +1 -0
  3. package/messages/he.json +1 -0
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/next.config.ts +68 -69
  6. package/templates/nextjs/base/scripts/fetch-store-info.mjs +91 -93
  7. package/templates/nextjs/base/src/app/checkout/page.tsx +1004 -982
  8. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +118 -118
  9. package/templates/nextjs/base/src/components/account/order-history.tsx +368 -368
  10. package/templates/nextjs/base/src/components/cart/cart-bundle-offer.tsx +111 -111
  11. package/templates/nextjs/base/src/components/cart/cart-item.tsx +152 -152
  12. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +108 -108
  13. package/templates/nextjs/base/src/components/cart/cart-upgrade-banner.tsx +141 -141
  14. package/templates/nextjs/base/src/components/cart/free-shipping-bar.tsx +62 -62
  15. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +242 -242
  16. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +198 -198
  17. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +109 -109
  18. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +74 -64
  19. package/templates/nextjs/base/src/components/products/frequently-bought-together.tsx +203 -203
  20. package/templates/nextjs/base/src/components/products/variant-selector.tsx +291 -291
  21. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +125 -129
  22. package/templates/nextjs/base/src/components/shared/price-display.tsx +61 -61
  23. package/templates/nextjs/base/src/lib/resolve-currency.ts +1 -6
  24. package/templates/nextjs/base/src/lib/use-currency.ts +1 -6
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.0",
34
+ version: "1.43.1",
35
35
  description: "Scaffold a production-ready e-commerce storefront connected to Brainerce",
36
36
  bin: {
37
37
  "create-brainerce-store": "dist/index.js"
package/messages/en.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "no": "No",
12
12
  "total": "Total",
13
13
  "subtotal": "Subtotal",
14
+ "subtotalExclTax": "Subtotal (excl. tax)",
14
15
  "discount": "Discount",
15
16
  "generalDiscount": "General Discount",
16
17
  "couponDiscount": "Coupon",
package/messages/he.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "no": "לא",
12
12
  "total": "סה\"כ",
13
13
  "subtotal": "סיכום ביניים",
14
+ "subtotalExclTax": "סיכום ביניים (לפני מע\"מ)",
14
15
  "discount": "הנחה",
15
16
  "generalDiscount": "הנחה כללית",
16
17
  "couponDiscount": "קופון",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-brainerce-store",
3
- "version": "1.43.0",
3
+ "version": "1.43.1",
4
4
  "description": "Scaffold a production-ready e-commerce storefront connected to Brainerce",
5
5
  "bin": {
6
6
  "create-brainerce-store": "dist/index.js"
@@ -1,69 +1,68 @@
1
- import type { NextConfig } from 'next';
2
-
3
- // Build-time invariant — fail loud if NEXT_PUBLIC_STORE_CURRENCY is missing
4
- // for a production build. Next.js inlines NEXT_PUBLIC_* into the client
5
- // bundle at `next build` time; once inlined, the value cannot be patched at
6
- // deploy time. A missing env here is the root cause of non-USD stores ending
7
- // up with `$5,096` baked into their HTML (and indexed by Googlebot).
8
- //
9
- // In dev (`next dev`) we only warn, so local-only experiments don't break.
10
- if (!process.env.NEXT_PUBLIC_STORE_CURRENCY) {
11
- const msg =
12
- 'NEXT_PUBLIC_STORE_CURRENCY is not set.\n' +
13
- 'Next.js inlines NEXT_PUBLIC_* vars into the client bundle at build time;\n' +
14
- 'a missing value will silently fall back to USD in storefront price displays\n' +
15
- 'and ship that to search-engine crawlers. Set it in .env.local (written by\n' +
16
- 'create-brainerce-store) or in your CI / hosting build env (Coolify / Vercel).';
17
- if (process.env.NODE_ENV === 'production') {
18
- throw new Error(`[next.config] ${msg}`);
19
- } else {
20
- // eslint-disable-next-line no-console
21
- console.warn(`[next.config] warning: ${msg}`);
22
- }
23
- }
24
-
25
- const nextConfig: NextConfig = {
26
- // isomorphic-dompurify ships jsdom, which at runtime reads stylesheet files
27
- // from its own package directory. Webpack bundling breaks those relative
28
- // lookups — loading it externally from node_modules keeps the paths intact.
29
- serverExternalPackages: ['isomorphic-dompurify'],
30
- images: {
31
- // The storefront is a consumer of the Brainerce API it has to render
32
- // whatever image URLs the API returns. In practice those URLs can be on
33
- // cdn.brainerce.com OR on an upstream merchant host (WooCommerce, Shopify,
34
- // self-hosted) depending on whether the product's image-import job has
35
- // completed on the backend. Rather than hard-fail on unknown hosts, skip
36
- // the server-side optimizer entirely and let the browser fetch each image
37
- // directly from origin. No server-side fetching → no SSRF or DoS surface
38
- // on this Next server. Trade-off: no webp/resize/lazy optimization, so
39
- // LCP is marginally worse. Acceptable; the storefront is not the right
40
- // layer to enforce a hostname policy.
41
- unoptimized: true,
42
- },
43
- async headers() {
44
- return [
45
- {
46
- source: '/(.*)',
47
- headers: [
48
- {
49
- key: 'Strict-Transport-Security',
50
- value: 'max-age=63072000; includeSubDomains; preload',
51
- },
52
- { key: 'X-Content-Type-Options', value: 'nosniff' },
53
- // SAMEORIGIN (not DENY) so iframe-based payment providers (e.g. Cardcom)
54
- // can redirect the iframe back to /payment-complete on the storefront
55
- // itself after a successful charge the postMessage relay needs the
56
- // parent frame to be able to render our own same-origin page.
57
- { key: 'X-Frame-Options', value: 'SAMEORIGIN' },
58
- { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
59
- {
60
- key: 'Permissions-Policy',
61
- value: 'camera=(), microphone=(), geolocation=(), interest-cohort=()',
62
- },
63
- ],
64
- },
65
- ];
66
- },
67
- };
68
-
69
- export default nextConfig;
1
+ import type { NextConfig } from 'next';
2
+
3
+ // Build-time invariant — fail loud if NEXT_PUBLIC_STORE_CURRENCY is missing
4
+ // for a production build. Next.js inlines NEXT_PUBLIC_* into the client
5
+ // bundle at `next build` time; once inlined, the value cannot be patched at
6
+ // deploy time. A missing env here is the root cause of non-USD stores ending
7
+ // up with `$5,096` baked into their HTML (and indexed by Googlebot).
8
+ //
9
+ // In dev (`next dev`) we only warn, so local-only experiments don't break.
10
+ if (!process.env.NEXT_PUBLIC_STORE_CURRENCY) {
11
+ const msg =
12
+ 'NEXT_PUBLIC_STORE_CURRENCY is not set.\n' +
13
+ 'Next.js inlines NEXT_PUBLIC_* vars into the client bundle at build time;\n' +
14
+ 'a missing value will silently fall back to USD in storefront price displays\n' +
15
+ 'and ship that to search-engine crawlers. Set it in .env.local (written by\n' +
16
+ 'create-brainerce-store) or in your CI / hosting build env (Coolify / Vercel).';
17
+ if (process.env.NODE_ENV === 'production') {
18
+ throw new Error(`[next.config] ${msg}`);
19
+ } else {
20
+ console.warn(`[next.config] warning: ${msg}`);
21
+ }
22
+ }
23
+
24
+ const nextConfig: NextConfig = {
25
+ // isomorphic-dompurify ships jsdom, which at runtime reads stylesheet files
26
+ // from its own package directory. Webpack bundling breaks those relative
27
+ // lookups loading it externally from node_modules keeps the paths intact.
28
+ serverExternalPackages: ['isomorphic-dompurify'],
29
+ images: {
30
+ // The storefront is a consumer of the Brainerce API — it has to render
31
+ // whatever image URLs the API returns. In practice those URLs can be on
32
+ // cdn.brainerce.com OR on an upstream merchant host (WooCommerce, Shopify,
33
+ // self-hosted) depending on whether the product's image-import job has
34
+ // completed on the backend. Rather than hard-fail on unknown hosts, skip
35
+ // the server-side optimizer entirely and let the browser fetch each image
36
+ // directly from origin. No server-side fetching no SSRF or DoS surface
37
+ // on this Next server. Trade-off: no webp/resize/lazy optimization, so
38
+ // LCP is marginally worse. Acceptable; the storefront is not the right
39
+ // layer to enforce a hostname policy.
40
+ unoptimized: true,
41
+ },
42
+ async headers() {
43
+ return [
44
+ {
45
+ source: '/(.*)',
46
+ headers: [
47
+ {
48
+ key: 'Strict-Transport-Security',
49
+ value: 'max-age=63072000; includeSubDomains; preload',
50
+ },
51
+ { key: 'X-Content-Type-Options', value: 'nosniff' },
52
+ // SAMEORIGIN (not DENY) so iframe-based payment providers (e.g. Cardcom)
53
+ // can redirect the iframe back to /payment-complete on the storefront
54
+ // itself after a successful charge the postMessage relay needs the
55
+ // parent frame to be able to render our own same-origin page.
56
+ { key: 'X-Frame-Options', value: 'SAMEORIGIN' },
57
+ { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
58
+ {
59
+ key: 'Permissions-Policy',
60
+ value: 'camera=(), microphone=(), geolocation=(), interest-cohort=()',
61
+ },
62
+ ],
63
+ },
64
+ ];
65
+ },
66
+ };
67
+
68
+ export default nextConfig;
@@ -1,93 +1,91 @@
1
- /* global process, console, fetch */
2
- /* eslint-disable no-console */
3
- /**
4
- * Setup script: fetches store info from Brainerce using the connection ID
5
- * and saves NEXT_PUBLIC_STORE_NAME (and other public fields) to .env.local.
6
- *
7
- * Run: node scripts/fetch-store-info.mjs
8
- */
9
-
10
- import { readFileSync, writeFileSync, existsSync } from 'fs';
11
- import { join } from 'path';
12
-
13
- const envPath = join(process.cwd(), '.env.local');
14
-
15
- if (!existsSync(envPath)) {
16
- console.error(
17
- '❌ .env.local not found. Create it first with NEXT_PUBLIC_BRAINERCE_SALES_CHANNEL_ID set.'
18
- );
19
- process.exit(1);
20
- }
21
-
22
- const envContent = readFileSync(envPath, 'utf-8');
23
-
24
- function getVar(content, key) {
25
- const match = content.match(new RegExp(`^${key}=(.*)$`, 'm'));
26
- return match ? match[1].trim() : null;
27
- }
28
-
29
- function setVar(content, key, value) {
30
- const regex = new RegExp(`^${key}=.*$`, 'm');
31
- if (regex.test(content)) {
32
- return content.replace(regex, `${key}=${value}`);
33
- }
34
- return content.trimEnd() + `\n${key}=${value}\n`;
35
- }
36
-
37
- // Read either env var name. The new one is preferred; the old one is a soft
38
- // alias kept for backwards compatibility — the SDK accepts both.
39
- const connectionId =
40
- getVar(envContent, 'NEXT_PUBLIC_BRAINERCE_SALES_CHANNEL_ID') ||
41
- getVar(envContent, 'NEXT_PUBLIC_BRAINERCE_CONNECTION_ID');
42
- const apiUrl = (getVar(envContent, 'BRAINERCE_API_URL') || 'https://api.brainerce.com').replace(
43
- /\/$/,
44
- ''
45
- );
46
-
47
- if (!connectionId) {
48
- console.error(
49
- '❌ NEXT_PUBLIC_BRAINERCE_SALES_CHANNEL_ID is not set in .env.local'
50
- );
51
- process.exit(1);
52
- }
53
-
54
- console.log(`Fetching store info for sales channel: ${connectionId} ...`);
55
-
56
- let storeInfo;
57
- try {
58
- const res = await fetch(`${apiUrl}/api/vc/${connectionId}/info`);
59
- if (!res.ok) {
60
- console.error(`❌ API returned ${res.status}: ${await res.text()}`);
61
- process.exit(1);
62
- }
63
- storeInfo = await res.json();
64
- } catch (err) {
65
- console.error(`❌ Failed to reach ${apiUrl}: ${err.message}`);
66
- process.exit(1);
67
- }
68
-
69
- const name = storeInfo.name;
70
- const currency = storeInfo.currency;
71
-
72
- if (!name) {
73
- console.error('❌ Store info response has no `name` field:', storeInfo);
74
- process.exit(1);
75
- }
76
- // Currency is NOT NULL in the backend schema a response without it
77
- // is a real backend bug, not a "use the default" signal. Fail loud rather
78
- // than silently leaving the env stale (which would bake the previous
79
- // value into the next client bundle build).
80
- if (!currency) {
81
- console.error('❌ Store info response has no `currency` field:', storeInfo);
82
- process.exit(1);
83
- }
84
-
85
- let updated = envContent;
86
- updated = setVar(updated, 'NEXT_PUBLIC_STORE_NAME', name);
87
- updated = setVar(updated, 'NEXT_PUBLIC_STORE_CURRENCY', currency);
88
-
89
- writeFileSync(envPath, updated, 'utf-8');
90
-
91
- console.log(`✓ NEXT_PUBLIC_STORE_NAME=${name}`);
92
- console.log(`✓ NEXT_PUBLIC_STORE_CURRENCY=${currency}`);
93
- console.log('Done. Restart the dev server for changes to take effect.');
1
+ /* global process, console, fetch */
2
+ /* eslint-disable no-console */
3
+ /**
4
+ * Setup script: fetches store info from Brainerce using the connection ID
5
+ * and saves NEXT_PUBLIC_STORE_NAME (and other public fields) to .env.local.
6
+ *
7
+ * Run: node scripts/fetch-store-info.mjs
8
+ */
9
+
10
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
11
+ import { join } from 'path';
12
+
13
+ const envPath = join(process.cwd(), '.env.local');
14
+
15
+ if (!existsSync(envPath)) {
16
+ console.error(
17
+ '❌ .env.local not found. Create it first with NEXT_PUBLIC_BRAINERCE_SALES_CHANNEL_ID set.'
18
+ );
19
+ process.exit(1);
20
+ }
21
+
22
+ const envContent = readFileSync(envPath, 'utf-8');
23
+
24
+ function getVar(content, key) {
25
+ const match = content.match(new RegExp(`^${key}=(.*)$`, 'm'));
26
+ return match ? match[1].trim() : null;
27
+ }
28
+
29
+ function setVar(content, key, value) {
30
+ const regex = new RegExp(`^${key}=.*$`, 'm');
31
+ if (regex.test(content)) {
32
+ return content.replace(regex, `${key}=${value}`);
33
+ }
34
+ return content.trimEnd() + `\n${key}=${value}\n`;
35
+ }
36
+
37
+ // Read either env var name. The new one is preferred; the old one is a soft
38
+ // alias kept for backwards compatibility — the SDK accepts both.
39
+ const connectionId =
40
+ getVar(envContent, 'NEXT_PUBLIC_BRAINERCE_SALES_CHANNEL_ID') ||
41
+ getVar(envContent, 'NEXT_PUBLIC_BRAINERCE_CONNECTION_ID');
42
+ const apiUrl = (getVar(envContent, 'BRAINERCE_API_URL') || 'https://api.brainerce.com').replace(
43
+ /\/$/,
44
+ ''
45
+ );
46
+
47
+ if (!connectionId) {
48
+ console.error('❌ NEXT_PUBLIC_BRAINERCE_SALES_CHANNEL_ID is not set in .env.local');
49
+ process.exit(1);
50
+ }
51
+
52
+ console.log(`Fetching store info for sales channel: ${connectionId} ...`);
53
+
54
+ let storeInfo;
55
+ try {
56
+ const res = await fetch(`${apiUrl}/api/vc/${connectionId}/info`);
57
+ if (!res.ok) {
58
+ console.error(`❌ API returned ${res.status}: ${await res.text()}`);
59
+ process.exit(1);
60
+ }
61
+ storeInfo = await res.json();
62
+ } catch (err) {
63
+ console.error(`❌ Failed to reach ${apiUrl}: ${err.message}`);
64
+ process.exit(1);
65
+ }
66
+
67
+ const name = storeInfo.name;
68
+ const currency = storeInfo.currency;
69
+
70
+ if (!name) {
71
+ console.error('❌ Store info response has no `name` field:', storeInfo);
72
+ process.exit(1);
73
+ }
74
+ // Currency is NOT NULL in the backend schema — a response without it
75
+ // is a real backend bug, not a "use the default" signal. Fail loud rather
76
+ // than silently leaving the env stale (which would bake the previous
77
+ // value into the next client bundle build).
78
+ if (!currency) {
79
+ console.error('❌ Store info response has no `currency` field:', storeInfo);
80
+ process.exit(1);
81
+ }
82
+
83
+ let updated = envContent;
84
+ updated = setVar(updated, 'NEXT_PUBLIC_STORE_NAME', name);
85
+ updated = setVar(updated, 'NEXT_PUBLIC_STORE_CURRENCY', currency);
86
+
87
+ writeFileSync(envPath, updated, 'utf-8');
88
+
89
+ console.log(`✓ NEXT_PUBLIC_STORE_NAME=${name}`);
90
+ console.log(`✓ NEXT_PUBLIC_STORE_CURRENCY=${currency}`);
91
+ console.log('Done. Restart the dev server for changes to take effect.');