@base44-preview/cli 0.0.50-pr.475.9d797d7 → 0.0.50-pr.475.a662eb9

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/cli/index.js CHANGED
@@ -243244,6 +243244,7 @@ var package_default = {
243244
243244
  typescript: "^5.7.2",
243245
243245
  vitest: "^4.0.16",
243246
243246
  yaml: "^2.8.2",
243247
+ qs: "^6.12.3",
243247
243248
  zod: "^4.3.5"
243248
243249
  },
243249
243250
  engines: {
@@ -253320,7 +253321,9 @@ class Validator {
253320
253321
  }
253321
253322
 
253322
253323
  // src/cli/dev/dev-server/db/database.ts
253324
+ var PRIVATE_COLLECTION_PREFIX = "$";
253323
253325
  var USER_COLLECTION = "user";
253326
+ var PRIVATE_USER_COLLECTION = PRIVATE_COLLECTION_PREFIX + USER_COLLECTION;
253324
253327
 
253325
253328
  class Database {
253326
253329
  collections = new Map;
@@ -253342,6 +253345,7 @@ class Database {
253342
253345
  this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
253343
253346
  const collection = new import_nedb.default;
253344
253347
  this.collections.set(USER_COLLECTION, collection);
253348
+ this.collections.set(PRIVATE_USER_COLLECTION, new import_nedb.default);
253345
253349
  const userInfo = await readAuth();
253346
253350
  const now = getNowISOTimestamp();
253347
253351
  await collection.insertAsync({
@@ -253383,7 +253387,9 @@ class Database {
253383
253387
  return this.collections.get(this.normalizeName(name2));
253384
253388
  }
253385
253389
  getCollectionNames() {
253386
- return Array.from(this.collections.keys());
253390
+ return Array.from(this.collections.keys()).filter((name2) => {
253391
+ return !name2.startsWith(PRIVATE_COLLECTION_PREFIX);
253392
+ });
253387
253393
  }
253388
253394
  dropAll() {
253389
253395
  for (const collection of this.collections.values()) {
@@ -253460,26 +253466,29 @@ var createJwtToken = (email3) => {
253460
253466
  expiresIn: "360d"
253461
253467
  });
253462
253468
  };
253463
- var UserRegiterSchema = object({
253464
- id: string2(),
253465
- email: email2(),
253466
- otpCode: string2().length(6),
253467
- password: string2().min(8),
253468
- createdAt: number2().min(1)
253469
- });
253470
253469
  function createAuthRouter(db2, logger2) {
253471
253470
  const router = import_express2.Router({ mergeParams: true });
253472
- const userRegitrPendingMap = new Map;
253473
253471
  const parseBody = import_express2.json();
253474
253472
  router.post("/login", parseBody, async (req, res) => {
253475
- const { email: email3, password: _password } = req.body;
253473
+ const { email: email3, password } = req.body;
253476
253474
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253477
253475
  if (result) {
253478
- res.json({
253479
- access_token: createJwtToken(email3),
253480
- success: true,
253481
- user: {}
253482
- });
253476
+ const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
253477
+ if (result.role === "admin" || privateUserData?.password === password) {
253478
+ res.json({
253479
+ access_token: createJwtToken(email3),
253480
+ success: true,
253481
+ user: {}
253482
+ });
253483
+ } else {
253484
+ res.status(400).json({
253485
+ detail: "Invalid email or password",
253486
+ error_type: "HTTPException",
253487
+ message: "Invalid email or password",
253488
+ request_id: null,
253489
+ traceback: ""
253490
+ });
253491
+ }
253483
253492
  return;
253484
253493
  }
253485
253494
  res.status(401).json({ error: "Unauthorized" });
@@ -253507,15 +253516,21 @@ function createAuthRouter(db2, logger2) {
253507
253516
  });
253508
253517
  return;
253509
253518
  }
253510
- const otpCode = generateCode();
253511
- const id2 = nanoid3();
253512
- userRegitrPendingMap.set(email3, {
253513
- id: id2,
253514
- email: email3,
253515
- otpCode,
253516
- password,
253517
- createdAt: +Date.now()
253519
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253520
+ const privateUserData = await privateUserCollection?.findOneAsync({
253521
+ email: email3
253518
253522
  });
253523
+ const otpCode = privateUserData ? privateUserData.otpCode : generateCode();
253524
+ const id2 = privateUserData ? privateUserData.id : nanoid3();
253525
+ if (!privateUserData) {
253526
+ await privateUserCollection?.insertAsync({
253527
+ id: id2,
253528
+ email: email3,
253529
+ otpCode,
253530
+ password,
253531
+ createdAt: +Date.now()
253532
+ });
253533
+ }
253519
253534
  logger2.log(theme.styles.info(`
253520
253535
  In order to complete registration use this verification code: ${otpCode}
253521
253536
  `));
@@ -253527,15 +253542,25 @@ In order to complete registration use this verification code: ${otpCode}
253527
253542
  });
253528
253543
  router.post("/verify-otp", parseBody, async (req, res) => {
253529
253544
  const { email: email3, otp_code } = req.body;
253530
- const userData = userRegitrPendingMap.get(email3);
253531
- if (userData && userData.otpCode === otp_code) {
253532
- if (+Date.now() - userData.createdAt < 10 * 60 * 1000) {
253545
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253546
+ const privateUserData = await privateUserCollection?.findOneAsync({
253547
+ email: email3
253548
+ });
253549
+ if (privateUserData && privateUserData.otpCode === otp_code) {
253550
+ if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253551
+ privateUserCollection?.updateAsync({
253552
+ email: email3
253553
+ }, {
253554
+ $set: {
253555
+ otpCode: undefined
253556
+ }
253557
+ });
253533
253558
  const collection = db2.getCollection(USER_COLLECTION);
253534
253559
  const now = getNowISOTimestamp();
253535
253560
  const nameFromEmailMatch = /^([^@]+)/.exec(email3);
253536
253561
  const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
253537
253562
  await collection?.insertAsync({
253538
- id: userData.id,
253563
+ id: privateUserData.id,
253539
253564
  email: email3,
253540
253565
  full_name: fullName,
253541
253566
  is_service: false,
@@ -253547,7 +253572,7 @@ In order to complete registration use this verification code: ${otpCode}
253547
253572
  updated_date: now
253548
253573
  });
253549
253574
  res.json({
253550
- id: userData.id,
253575
+ id: privateUserData.id,
253551
253576
  access_token: createJwtToken(email3),
253552
253577
  message: "Email verified successfully. You are now logged in.",
253553
253578
  success: true
@@ -255715,7 +255740,7 @@ class WatchBase44 extends EventEmitter4 {
255715
255740
  var DEFAULT_PORT = 4400;
255716
255741
  var BASE44_APP_URL = "https://base44.app";
255717
255742
  async function createDevServer(options8) {
255718
- const { port: userPort, cwd } = options8;
255743
+ const { port: userPort } = options8;
255719
255744
  const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
255720
255745
  const baseUrl = `http://localhost:${port}`;
255721
255746
  const { functions, entities, project: project2 } = await options8.loadResources();
@@ -260359,4 +260384,4 @@ export {
260359
260384
  CLIExitError
260360
260385
  };
260361
260386
 
260362
- //# debugId=5FDDF606296BF31964756E2164756E21
260387
+ //# debugId=00A0741C1AAAE2DF64756E2164756E21