@atlashub/smartstack-cli 2.2.0 → 2.3.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/index.js CHANGED
@@ -125351,6 +125351,13 @@ var import_bcryptjs = __toESM(require_bcryptjs());
125351
125351
  var import_fs4 = require("fs");
125352
125352
  var import_path9 = require("path");
125353
125353
  var import_child_process8 = require("child_process");
125354
+ function tryLoadNativeDriver() {
125355
+ try {
125356
+ return require("mssql/msnodesqlv8");
125357
+ } catch {
125358
+ return null;
125359
+ }
125360
+ }
125354
125361
  var DEFAULT_CONFIG = {
125355
125362
  schema: "core",
125356
125363
  usersTable: "auth_Users",
@@ -125558,53 +125565,77 @@ adminCommand.command("reset").description("Reset the localAdmin account password
125558
125565
  console.log(source_default.green("\u2550".repeat(60)));
125559
125566
  console.log();
125560
125567
  };
125568
+ const resetViaMssql = async (sqlModule) => {
125569
+ spinner.text = "Connected. Checking account...";
125570
+ const checkResult = await sqlModule.query`
125571
+ SELECT COUNT(*) as count
125572
+ FROM [core].[auth_Users]
125573
+ WHERE Email = ${adminEmail}
125574
+ `;
125575
+ const exists = checkResult.recordset[0].count > 0;
125576
+ if (!exists) {
125577
+ spinner.fail(`Account ${source_default.yellow(adminEmail)} does not exist.`);
125578
+ logger.error("Cannot reset password for non-existent account.");
125579
+ logger.info("Use the application seeding or AdminTool to create the account first.");
125580
+ await sqlModule.close();
125581
+ process.exit(1);
125582
+ }
125583
+ spinner.text = "Generating new password...";
125584
+ const newPassword = generatePassword();
125585
+ const passwordHash = await import_bcryptjs.default.hash(newPassword, 10);
125586
+ spinner.text = "Updating password...";
125587
+ await sqlModule.query`
125588
+ UPDATE [core].[auth_Users]
125589
+ SET PasswordHash = ${passwordHash},
125590
+ UpdatedAt = ${/* @__PURE__ */ new Date()}
125591
+ WHERE Email = ${adminEmail}
125592
+ `;
125593
+ await sqlModule.close();
125594
+ spinner.succeed("Password reset successfully!");
125595
+ displayPasswordResult(adminEmail, newPassword);
125596
+ };
125597
+ const tryWithSqlCmd = async () => {
125598
+ try {
125599
+ await resetViaSqlCmd();
125600
+ } catch (winAuthError) {
125601
+ if (isLoginFailure(winAuthError)) {
125602
+ spinner.fail("Windows Authentication failed");
125603
+ console.log();
125604
+ const sqlCreds = await promptSqlCredentials();
125605
+ if (!sqlCreds) {
125606
+ process.exit(1);
125607
+ }
125608
+ spinner.start("Retrying with SQL Server credentials...");
125609
+ await resetViaSqlCmd(sqlCreds);
125610
+ } else {
125611
+ throw winAuthError;
125612
+ }
125613
+ }
125614
+ };
125561
125615
  try {
125562
125616
  if (connInfo.useWindowsAuth) {
125563
- try {
125564
- await resetViaSqlCmd();
125565
- } catch (winAuthError) {
125566
- if (isLoginFailure(winAuthError)) {
125567
- spinner.fail("Windows Authentication failed");
125568
- console.log();
125569
- const sqlCreds = await promptSqlCredentials();
125570
- if (!sqlCreds) {
125571
- process.exit(1);
125617
+ const nativeDriver = tryLoadNativeDriver();
125618
+ let nativeConnected = false;
125619
+ if (nativeDriver) {
125620
+ try {
125621
+ spinner.text = "Connecting with Windows Authentication...";
125622
+ await nativeDriver.connect(connectionString);
125623
+ nativeConnected = true;
125624
+ await resetViaMssql(nativeDriver);
125625
+ } catch (nativeError) {
125626
+ if (nativeConnected) throw nativeError;
125627
+ try {
125628
+ await nativeDriver.close();
125629
+ } catch {
125572
125630
  }
125573
- spinner.start("Retrying with SQL Server credentials...");
125574
- await resetViaSqlCmd(sqlCreds);
125575
- } else {
125576
- throw winAuthError;
125577
125631
  }
125578
125632
  }
125633
+ if (!nativeConnected) {
125634
+ await tryWithSqlCmd();
125635
+ }
125579
125636
  } else {
125580
125637
  await import_mssql.default.connect(connectionString);
125581
- spinner.text = "Connected. Checking account...";
125582
- const checkResult = await import_mssql.default.query`
125583
- SELECT COUNT(*) as count
125584
- FROM [core].[auth_Users]
125585
- WHERE Email = ${adminEmail}
125586
- `;
125587
- const exists = checkResult.recordset[0].count > 0;
125588
- if (!exists) {
125589
- spinner.fail(`Account ${source_default.yellow(adminEmail)} does not exist.`);
125590
- logger.error("Cannot reset password for non-existent account.");
125591
- logger.info("Use the application seeding or AdminTool to create the account first.");
125592
- await import_mssql.default.close();
125593
- process.exit(1);
125594
- }
125595
- spinner.text = "Generating new password...";
125596
- const newPassword = generatePassword();
125597
- const passwordHash = await import_bcryptjs.default.hash(newPassword, 10);
125598
- spinner.text = "Updating password...";
125599
- await import_mssql.default.query`
125600
- UPDATE [core].[auth_Users]
125601
- SET PasswordHash = ${passwordHash},
125602
- UpdatedAt = ${/* @__PURE__ */ new Date()}
125603
- WHERE Email = ${adminEmail}
125604
- `;
125605
- await import_mssql.default.close();
125606
- spinner.succeed("Password reset successfully!");
125607
- displayPasswordResult(adminEmail, newPassword);
125638
+ await resetViaMssql(import_mssql.default);
125608
125639
  }
125609
125640
  } catch (error) {
125610
125641
  spinner.fail("Failed to reset password");
@@ -125622,11 +125653,9 @@ adminCommand.command("reset").description("Reset the localAdmin account password
125622
125653
  logger.info(` 3. Or use: ${source_default.cyan('ss admin reset --connection "Server=...;Database=...;User Id=sa;Password=..."')}`);
125623
125654
  }
125624
125655
  }
125625
- if (!connInfo.useWindowsAuth) {
125626
- try {
125627
- await import_mssql.default.close();
125628
- } catch {
125629
- }
125656
+ try {
125657
+ await import_mssql.default.close();
125658
+ } catch {
125630
125659
  }
125631
125660
  process.exit(1);
125632
125661
  }