@base44-preview/cli 0.0.50-pr.475.b600821 → 0.0.50-pr.475.b981e6a

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
@@ -243211,6 +243211,7 @@ var package_default = {
243211
243211
  "@types/ejs": "^3.1.5",
243212
243212
  "@types/express": "^5.0.6",
243213
243213
  "@types/json-schema": "^7.0.15",
243214
+ "@types/jsonwebtoken": "^9.0.10",
243214
243215
  "@types/lodash": "^4.17.24",
243215
243216
  "@types/multer": "^2.0.0",
243216
243217
  "@types/node": "^22.10.5",
@@ -243229,6 +243230,7 @@ var package_default = {
243229
243230
  globby: "^16.1.0",
243230
243231
  "http-proxy-middleware": "^3.0.5",
243231
243232
  "json-schema-to-typescript": "^15.0.4",
243233
+ jsonwebtoken: "^9.0.3",
243232
243234
  json5: "^2.2.3",
243233
243235
  ky: "^1.14.2",
243234
243236
  lodash: "^4.17.23",
@@ -253321,7 +253323,9 @@ class Validator {
253321
253323
  }
253322
253324
 
253323
253325
  // src/cli/dev/dev-server/db/database.ts
253326
+ var PRIVATE_COLLECTION_PREFIX = "$";
253324
253327
  var USER_COLLECTION = "user";
253328
+ var PRIVATE_USER_COLLECTION = PRIVATE_COLLECTION_PREFIX + USER_COLLECTION;
253325
253329
 
253326
253330
  class Database {
253327
253331
  collections = new Map;
@@ -253343,6 +253347,7 @@ class Database {
253343
253347
  this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
253344
253348
  const collection = new import_nedb.default;
253345
253349
  this.collections.set(USER_COLLECTION, collection);
253350
+ this.collections.set(PRIVATE_USER_COLLECTION, new import_nedb.default);
253346
253351
  const userInfo = await readAuth();
253347
253352
  const now = getNowISOTimestamp();
253348
253353
  await collection.insertAsync({
@@ -253384,7 +253389,9 @@ class Database {
253384
253389
  return this.collections.get(this.normalizeName(name2));
253385
253390
  }
253386
253391
  getCollectionNames() {
253387
- return Array.from(this.collections.keys());
253392
+ return Array.from(this.collections.keys()).filter((name2) => {
253393
+ return !name2.startsWith(PRIVATE_COLLECTION_PREFIX);
253394
+ });
253388
253395
  }
253389
253396
  dropAll() {
253390
253397
  for (const collection of this.collections.values()) {
@@ -253461,16 +253468,17 @@ var createJwtToken = (email3) => {
253461
253468
  expiresIn: "360d"
253462
253469
  });
253463
253470
  };
253471
+ var LoginBody = object({ email: email2(), password: string2() });
253472
+ var VerifyOtpBody = object({ email: email2(), otp_code: string2() });
253464
253473
  function createAuthRouter(db2, logger2) {
253465
253474
  const router = import_express2.Router({ mergeParams: true });
253466
- const userRegistrPendingMap = new Map;
253467
253475
  const parseBody = import_express2.json();
253468
253476
  router.post("/login", parseBody, async (req, res) => {
253469
- const { email: email3, password } = req.body;
253477
+ const { email: email3, password } = LoginBody.parse(req.body);
253470
253478
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253471
253479
  if (result) {
253472
- const registeredUserData = userRegistrPendingMap.get(email3);
253473
- if (result.role === "admin" || registeredUserData?.password === password) {
253480
+ const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
253481
+ if (result.role === "admin" || privateUserData?.password === password) {
253474
253482
  res.json({
253475
253483
  access_token: createJwtToken(email3),
253476
253484
  success: true,
@@ -253490,7 +253498,7 @@ function createAuthRouter(db2, logger2) {
253490
253498
  res.status(401).json({ error: "Unauthorized" });
253491
253499
  });
253492
253500
  router.post("/register", parseBody, async (req, res) => {
253493
- const { email: email3, password } = req.body;
253501
+ const { email: email3, password } = LoginBody.parse(req.body);
253494
253502
  if ((password || "").length < 8) {
253495
253503
  res.status(400).json({
253496
253504
  detail: "Password must be at least 8 characters long",
@@ -253512,15 +253520,30 @@ function createAuthRouter(db2, logger2) {
253512
253520
  });
253513
253521
  return;
253514
253522
  }
253515
- const otpCode = generateCode();
253516
- const id2 = nanoid3();
253517
- userRegistrPendingMap.set(email3, {
253518
- id: id2,
253519
- email: email3,
253520
- otpCode,
253521
- password,
253522
- createdAt: +Date.now()
253523
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253524
+ const privateUserData = await privateUserCollection?.findOneAsync({
253525
+ email: email3
253523
253526
  });
253527
+ const otpCode = generateCode();
253528
+ const id2 = privateUserData ? privateUserData.id : nanoid3();
253529
+ if (!privateUserData) {
253530
+ await privateUserCollection?.insertAsync({
253531
+ id: id2,
253532
+ email: email3,
253533
+ otpCode,
253534
+ password,
253535
+ createdAt: Date.now()
253536
+ });
253537
+ } else {
253538
+ await privateUserCollection?.updateAsync({
253539
+ email: email3
253540
+ }, {
253541
+ $set: {
253542
+ otpCode,
253543
+ createdAt: Date.now()
253544
+ }
253545
+ });
253546
+ }
253524
253547
  logger2.log(theme.styles.info(`
253525
253548
  In order to complete registration use this verification code: ${otpCode}
253526
253549
  `));
@@ -253531,17 +253554,24 @@ In order to complete registration use this verification code: ${otpCode}
253531
253554
  });
253532
253555
  });
253533
253556
  router.post("/verify-otp", parseBody, async (req, res) => {
253534
- const { email: email3, otp_code } = req.body;
253535
- const userData = userRegistrPendingMap.get(email3);
253536
- if (userData && userData.otpCode === otp_code) {
253537
- if (+Date.now() - userData.createdAt < 10 * 60 * 1000) {
253538
- userData.otpCode = undefined;
253557
+ const { email: email3, otp_code } = VerifyOtpBody.parse(req.body);
253558
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253559
+ const privateUserData = await privateUserCollection?.findOneAsync({
253560
+ email: email3
253561
+ });
253562
+ if (privateUserData && privateUserData.otpCode === otp_code) {
253563
+ if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253564
+ await privateUserCollection?.updateAsync({
253565
+ email: email3
253566
+ }, {
253567
+ $unset: { otpCode: true }
253568
+ });
253539
253569
  const collection = db2.getCollection(USER_COLLECTION);
253540
253570
  const now = getNowISOTimestamp();
253541
253571
  const nameFromEmailMatch = /^([^@]+)/.exec(email3);
253542
253572
  const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
253543
253573
  await collection?.insertAsync({
253544
- id: userData.id,
253574
+ id: privateUserData.id,
253545
253575
  email: email3,
253546
253576
  full_name: fullName,
253547
253577
  is_service: false,
@@ -253553,7 +253583,7 @@ In order to complete registration use this verification code: ${otpCode}
253553
253583
  updated_date: now
253554
253584
  });
253555
253585
  res.json({
253556
- id: userData.id,
253586
+ id: privateUserData.id,
253557
253587
  access_token: createJwtToken(email3),
253558
253588
  message: "Email verified successfully. You are now logged in.",
253559
253589
  success: true
@@ -260365,4 +260395,4 @@ export {
260365
260395
  CLIExitError
260366
260396
  };
260367
260397
 
260368
- //# debugId=404C42E5E0DB4C5E64756E2164756E21
260398
+ //# debugId=8BC0D7129D49BDE164756E2164756E21