create-brainerce-store 1.22.0 → 1.23.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.
Files changed (2) hide show
  1. package/dist/index.js +41 -44
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -326,7 +326,7 @@ async function scaffold(options) {
326
326
  fontImport: fontConfig.fontImport,
327
327
  fontVariable: fontConfig.fontVariable,
328
328
  ogLocale,
329
- apiBaseUrl: "https://api.brainerce.com",
329
+ apiBaseUrl: options.apiBaseUrl || "https://api.brainerce.com",
330
330
  i18nEnabled: isMultiLocale,
331
331
  supportedLocales: JSON.stringify(supportedLocales),
332
332
  defaultLocale
@@ -410,47 +410,39 @@ async function copyWithEjs(srcDir, destDir, vars) {
410
410
  }
411
411
 
412
412
  // src/fetch-store-info.ts
413
- var import_https = __toESM(require("https"));
414
- var import_http = __toESM(require("http"));
415
413
  async function fetchStoreInfo(connectionId, baseUrl = "https://api.brainerce.com") {
416
414
  const url = `${baseUrl}/api/vc/${connectionId}/info`;
417
- return new Promise((resolve, reject) => {
418
- const client = url.startsWith("https") ? import_https.default : import_http.default;
419
- const req = client.get(url, { timeout: 1e4 }, (res) => {
420
- let data = "";
421
- res.on("data", (chunk) => {
422
- data += chunk;
423
- });
424
- res.on("end", () => {
425
- if (res.statusCode && res.statusCode >= 400) {
426
- if (res.statusCode === 404) {
427
- reject(new Error(`Connection ID "${connectionId}" not found. Check your dashboard.`));
428
- } else {
429
- reject(new Error(`API returned status ${res.statusCode}`));
430
- }
431
- return;
432
- }
433
- try {
434
- const json = JSON.parse(data);
435
- resolve({
436
- name: json.name || json.storeName || "My Store",
437
- currency: json.currency || "USD",
438
- language: json.language || "en",
439
- ...json.i18n ? { i18n: json.i18n } : {}
440
- });
441
- } catch {
442
- reject(new Error("Invalid response from API"));
443
- }
444
- });
445
- });
446
- req.on("error", (err) => {
447
- reject(new Error(`Failed to connect to Brainerce API: ${err.message}`));
448
- });
449
- req.on("timeout", () => {
450
- req.destroy();
451
- reject(new Error("Request timed out"));
452
- });
453
- });
415
+ const controller = new AbortController();
416
+ const timeout = setTimeout(() => controller.abort(), 1e4);
417
+ let res;
418
+ try {
419
+ res = await fetch(url, { signal: controller.signal });
420
+ } catch (err) {
421
+ if (err.name === "AbortError") {
422
+ throw new Error("Request timed out");
423
+ }
424
+ throw new Error(`Failed to connect to Brainerce API: ${err.message}`);
425
+ } finally {
426
+ clearTimeout(timeout);
427
+ }
428
+ if (res.status === 404) {
429
+ throw new Error(`Connection ID "${connectionId}" not found. Check your dashboard.`);
430
+ }
431
+ if (!res.ok) {
432
+ throw new Error(`API returned status ${res.status}`);
433
+ }
434
+ let json;
435
+ try {
436
+ json = await res.json();
437
+ } catch {
438
+ throw new Error("Invalid response from API");
439
+ }
440
+ return {
441
+ name: json.name || json.storeName || "My Store",
442
+ currency: json.currency || "USD",
443
+ language: json.language || "en",
444
+ ...json.i18n ? { i18n: json.i18n } : {}
445
+ };
454
446
  }
455
447
 
456
448
  // src/utils/logger.ts
@@ -502,9 +494,9 @@ function createSpinner(text) {
502
494
  var pkg = require_package();
503
495
  async function checkForUpdate(name, current) {
504
496
  try {
505
- const https2 = require("https");
497
+ const https = require("https");
506
498
  return await new Promise((resolve) => {
507
- const req = https2.get(
499
+ const req = https.get(
508
500
  `https://registry.npmjs.org/${name}/latest`,
509
501
  { timeout: 3e3 },
510
502
  (res) => {
@@ -531,7 +523,10 @@ async function checkForUpdate(name, current) {
531
523
  }
532
524
  }
533
525
  var program = new import_commander.Command();
534
- program.name("create-brainerce-store").description("Scaffold a production-ready e-commerce storefront connected to Brainerce").version(pkg.version).argument("[project-name]", "Name for the project directory").option("--connection-id <id>", "Brainerce vibe-coded connection ID (vc_*)").option("--language <lang>", "Store language (en, he)").option("--framework <framework>", "Framework to use", "nextjs").option("--theme <theme>", "Theme to apply", "minimal").option("--pkg-manager <manager>", "Package manager (npm, pnpm, yarn, bun)").option("--no-git", "Skip git initialization").option("--no-install", "Skip dependency installation").action(async (projectNameArg, options) => {
526
+ program.name("create-brainerce-store").description("Scaffold a production-ready e-commerce storefront connected to Brainerce").version(pkg.version).argument("[project-name]", "Name for the project directory").option("--connection-id <id>", "Brainerce vibe-coded connection ID (vc_*)").option(
527
+ "--api-url <url>",
528
+ "Brainerce API base URL (overrides BRAINERCE_API_URL env, defaults to https://api.brainerce.com)"
529
+ ).option("--language <lang>", "Store language (en, he)").option("--framework <framework>", "Framework to use", "nextjs").option("--theme <theme>", "Theme to apply", "minimal").option("--pkg-manager <manager>", "Package manager (npm, pnpm, yarn, bun)").option("--no-git", "Skip git initialization").option("--no-install", "Skip dependency installation").action(async (projectNameArg, options) => {
535
530
  try {
536
531
  logger.banner(pkg.version);
537
532
  const updateCheck = checkForUpdate(pkg.name, pkg.version);
@@ -542,6 +537,7 @@ program.name("create-brainerce-store").description("Scaffold a production-ready
542
537
  scaffoldInPlace = true;
543
538
  }
544
539
  let connectionId = options.connectionId;
540
+ const apiBaseUrl = (options.apiUrl || process.env.BRAINERCE_API_URL || "https://api.brainerce.com").replace(/\/$/, "");
545
541
  let language = options.language;
546
542
  let framework = options.framework;
547
543
  let theme = options.theme;
@@ -578,7 +574,7 @@ program.name("create-brainerce-store").description("Scaffold a production-ready
578
574
  spinner.start();
579
575
  let storeInfo;
580
576
  try {
581
- storeInfo = await fetchStoreInfo(connectionId);
577
+ storeInfo = await fetchStoreInfo(connectionId, apiBaseUrl);
582
578
  const i18nStatus = storeInfo.i18n?.enabled && storeInfo.i18n.supportedLocales.length > 1 ? ` | i18n: ${storeInfo.i18n.supportedLocales.join(", ")}` : "";
583
579
  spinner.succeed(
584
580
  `Store: "${storeInfo.name}" | ${storeInfo.currency} | ${storeInfo.language}${i18nStatus}`
@@ -598,6 +594,7 @@ program.name("create-brainerce-store").description("Scaffold a production-ready
598
594
  await scaffold({
599
595
  projectName,
600
596
  connectionId,
597
+ apiBaseUrl,
601
598
  framework,
602
599
  theme,
603
600
  storeName: storeInfo.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-brainerce-store",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "Scaffold a production-ready e-commerce storefront connected to Brainerce",
5
5
  "bin": {
6
6
  "create-brainerce-store": "dist/index.js"