create-brainerce-store 1.13.0 → 1.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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.13.0",
34
+ version: "1.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-brainerce-store",
3
- "version": "1.13.0",
3
+ "version": "1.14.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,6 +1,10 @@
1
1
  # Brainerce Connection
2
2
  NEXT_PUBLIC_BRAINERCE_CONNECTION_ID=<%= connectionId %>
3
3
 
4
+ # Store info (pre-fetched during setup to avoid flash on first load)
5
+ NEXT_PUBLIC_STORE_NAME=<%= storeName %>
6
+ NEXT_PUBLIC_STORE_CURRENCY=<%= currency %>
7
+
4
8
  # Backend API URL (server-side only — used by BFF proxy and SSR, never exposed to browser)
5
9
  BRAINERCE_API_URL=<%= apiBaseUrl %>
6
10
 
@@ -6,10 +6,11 @@
6
6
  "dev": "next dev",
7
7
  "build": "next build",
8
8
  "start": "next start",
9
- "lint": "next lint"
9
+ "lint": "next lint",
10
+ "setup": "node scripts/fetch-store-info.mjs"
10
11
  },
11
12
  "dependencies": {
12
- "brainerce": "^1.0.0",
13
+ "brainerce": "^1.11.0",
13
14
  "next": "^15.0.0",
14
15
  "react": "^19.0.0",
15
16
  "react-dom": "^19.0.0",
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Setup script: fetches store info from Brainerce using the connection ID
3
+ * and saves NEXT_PUBLIC_STORE_NAME (and other public fields) to .env.local.
4
+ *
5
+ * Run: node scripts/fetch-store-info.mjs
6
+ */
7
+
8
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
9
+ import { join } from 'path';
10
+
11
+ const envPath = join(process.cwd(), '.env.local');
12
+
13
+ if (!existsSync(envPath)) {
14
+ console.error('❌ .env.local not found. Create it first with NEXT_PUBLIC_BRAINERCE_CONNECTION_ID set.');
15
+ process.exit(1);
16
+ }
17
+
18
+ const envContent = readFileSync(envPath, 'utf-8');
19
+
20
+ function getVar(content, key) {
21
+ const match = content.match(new RegExp(`^${key}=(.*)$`, 'm'));
22
+ return match ? match[1].trim() : null;
23
+ }
24
+
25
+ function setVar(content, key, value) {
26
+ const regex = new RegExp(`^${key}=.*$`, 'm');
27
+ if (regex.test(content)) {
28
+ return content.replace(regex, `${key}=${value}`);
29
+ }
30
+ return content.trimEnd() + `\n${key}=${value}\n`;
31
+ }
32
+
33
+ const connectionId = getVar(envContent, 'NEXT_PUBLIC_BRAINERCE_CONNECTION_ID');
34
+ const apiUrl = (getVar(envContent, 'BRAINERCE_API_URL') || 'https://api.brainerce.com').replace(/\/$/, '');
35
+
36
+ if (!connectionId) {
37
+ console.error('❌ NEXT_PUBLIC_BRAINERCE_CONNECTION_ID is not set in .env.local');
38
+ process.exit(1);
39
+ }
40
+
41
+ console.log(`Fetching store info for connection: ${connectionId} ...`);
42
+
43
+ let storeInfo;
44
+ try {
45
+ const res = await fetch(`${apiUrl}/api/vc/${connectionId}/info`);
46
+ if (!res.ok) {
47
+ console.error(`❌ API returned ${res.status}: ${await res.text()}`);
48
+ process.exit(1);
49
+ }
50
+ storeInfo = await res.json();
51
+ } catch (err) {
52
+ console.error(`❌ Failed to reach ${apiUrl}: ${err.message}`);
53
+ process.exit(1);
54
+ }
55
+
56
+ const name = storeInfo.name;
57
+ const currency = storeInfo.currency;
58
+
59
+ if (!name) {
60
+ console.error('❌ Store info response has no `name` field:', storeInfo);
61
+ process.exit(1);
62
+ }
63
+
64
+ let updated = envContent;
65
+ updated = setVar(updated, 'NEXT_PUBLIC_STORE_NAME', name);
66
+ if (currency) {
67
+ updated = setVar(updated, 'NEXT_PUBLIC_STORE_CURRENCY', currency);
68
+ }
69
+
70
+ writeFileSync(envPath, updated, 'utf-8');
71
+
72
+ console.log(`✓ NEXT_PUBLIC_STORE_NAME=${name}`);
73
+ if (currency) console.log(`✓ NEXT_PUBLIC_STORE_CURRENCY=${currency}`);
74
+ console.log('Done. Restart the dev server for changes to take effect.');