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

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",
@@ -243244,6 +243246,7 @@ var package_default = {
243244
243246
  typescript: "^5.7.2",
243245
243247
  vitest: "^4.0.16",
243246
243248
  yaml: "^2.8.2",
243249
+ qs: "^6.12.3",
243247
243250
  zod: "^4.3.5"
243248
243251
  },
243249
243252
  engines: {
@@ -253093,9 +253096,13 @@ function createFunctionRouter(manager, logger2) {
253093
253096
  on: {
253094
253097
  proxyReq: (proxyReq, req) => {
253095
253098
  const xAppId = req.headers["x-app-id"];
253099
+ const authorization = req.headers.authorization;
253096
253100
  if (xAppId) {
253097
253101
  proxyReq.setHeader("Base44-App-Id", xAppId);
253098
253102
  }
253103
+ if (authorization) {
253104
+ proxyReq.setHeader("Base44-Service-Authorization", authorization);
253105
+ }
253099
253106
  proxyReq.setHeader("Base44-Api-Url", `${req.protocol}://${req.headers.host}`);
253100
253107
  },
253101
253108
  error: (err, _req, res) => {
@@ -253320,7 +253327,9 @@ class Validator {
253320
253327
  }
253321
253328
 
253322
253329
  // src/cli/dev/dev-server/db/database.ts
253330
+ var PRIVATE_COLLECTION_PREFIX = "$";
253323
253331
  var USER_COLLECTION = "user";
253332
+ var PRIVATE_USER_COLLECTION = PRIVATE_COLLECTION_PREFIX + USER_COLLECTION;
253324
253333
 
253325
253334
  class Database {
253326
253335
  collections = new Map;
@@ -253342,6 +253351,7 @@ class Database {
253342
253351
  this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
253343
253352
  const collection = new import_nedb.default;
253344
253353
  this.collections.set(USER_COLLECTION, collection);
253354
+ this.collections.set(PRIVATE_USER_COLLECTION, new import_nedb.default);
253345
253355
  const userInfo = await readAuth();
253346
253356
  const now = getNowISOTimestamp();
253347
253357
  await collection.insertAsync({
@@ -253383,7 +253393,9 @@ class Database {
253383
253393
  return this.collections.get(this.normalizeName(name2));
253384
253394
  }
253385
253395
  getCollectionNames() {
253386
- return Array.from(this.collections.keys());
253396
+ return Array.from(this.collections.keys()).filter((name2) => {
253397
+ return !name2.startsWith(PRIVATE_COLLECTION_PREFIX);
253398
+ });
253387
253399
  }
253388
253400
  dropAll() {
253389
253401
  for (const collection of this.collections.values()) {
@@ -253460,32 +253472,37 @@ var createJwtToken = (email3) => {
253460
253472
  expiresIn: "360d"
253461
253473
  });
253462
253474
  };
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
- });
253475
+ var LoginBody = object({ email: email2(), password: string2() });
253476
+ var VerifyOtpBody = object({ email: email2(), otp_code: string2() });
253470
253477
  function createAuthRouter(db2, logger2) {
253471
253478
  const router = import_express2.Router({ mergeParams: true });
253472
- const userRegitrPendingMap = new Map;
253473
253479
  const parseBody = import_express2.json();
253474
253480
  router.post("/login", parseBody, async (req, res) => {
253475
- const { email: email3, password: _password } = req.body;
253481
+ const { email: email3, password } = LoginBody.parse(req.body);
253476
253482
  const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
253477
253483
  if (result) {
253478
- res.json({
253479
- access_token: createJwtToken(email3),
253480
- success: true,
253481
- user: {}
253482
- });
253484
+ const privateUserData = await db2.getCollection(PRIVATE_USER_COLLECTION)?.findOneAsync({ email: email3 });
253485
+ if (result.role === "admin" || privateUserData?.password === password) {
253486
+ res.json({
253487
+ access_token: createJwtToken(email3),
253488
+ success: true,
253489
+ user: {}
253490
+ });
253491
+ } else {
253492
+ res.status(400).json({
253493
+ detail: "Invalid email or password",
253494
+ error_type: "HTTPException",
253495
+ message: "Invalid email or password",
253496
+ request_id: null,
253497
+ traceback: ""
253498
+ });
253499
+ }
253483
253500
  return;
253484
253501
  }
253485
253502
  res.status(401).json({ error: "Unauthorized" });
253486
253503
  });
253487
253504
  router.post("/register", parseBody, async (req, res) => {
253488
- const { email: email3, password } = req.body;
253505
+ const { email: email3, password } = LoginBody.parse(req.body);
253489
253506
  if ((password || "").length < 8) {
253490
253507
  res.status(400).json({
253491
253508
  detail: "Password must be at least 8 characters long",
@@ -253507,15 +253524,30 @@ function createAuthRouter(db2, logger2) {
253507
253524
  });
253508
253525
  return;
253509
253526
  }
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()
253527
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253528
+ const privateUserData = await privateUserCollection?.findOneAsync({
253529
+ email: email3
253518
253530
  });
253531
+ const otpCode = generateCode();
253532
+ const id2 = privateUserData ? privateUserData.id : nanoid3();
253533
+ if (!privateUserData) {
253534
+ await privateUserCollection?.insertAsync({
253535
+ id: id2,
253536
+ email: email3,
253537
+ otpCode,
253538
+ password,
253539
+ createdAt: Date.now()
253540
+ });
253541
+ } else {
253542
+ await privateUserCollection?.updateAsync({
253543
+ email: email3
253544
+ }, {
253545
+ $set: {
253546
+ otpCode,
253547
+ createdAt: Date.now()
253548
+ }
253549
+ });
253550
+ }
253519
253551
  logger2.log(theme.styles.info(`
253520
253552
  In order to complete registration use this verification code: ${otpCode}
253521
253553
  `));
@@ -253526,16 +253558,24 @@ In order to complete registration use this verification code: ${otpCode}
253526
253558
  });
253527
253559
  });
253528
253560
  router.post("/verify-otp", parseBody, async (req, res) => {
253529
- 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) {
253561
+ const { email: email3, otp_code } = VerifyOtpBody.parse(req.body);
253562
+ const privateUserCollection = db2.getCollection(PRIVATE_USER_COLLECTION);
253563
+ const privateUserData = await privateUserCollection?.findOneAsync({
253564
+ email: email3
253565
+ });
253566
+ if (privateUserData && privateUserData.otpCode === otp_code) {
253567
+ if (+Date.now() - privateUserData.createdAt < 10 * 60 * 1000) {
253568
+ await privateUserCollection?.updateAsync({
253569
+ email: email3
253570
+ }, {
253571
+ $unset: { otpCode: true }
253572
+ });
253533
253573
  const collection = db2.getCollection(USER_COLLECTION);
253534
253574
  const now = getNowISOTimestamp();
253535
253575
  const nameFromEmailMatch = /^([^@]+)/.exec(email3);
253536
253576
  const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
253537
253577
  await collection?.insertAsync({
253538
- id: userData.id,
253578
+ id: privateUserData.id,
253539
253579
  email: email3,
253540
253580
  full_name: fullName,
253541
253581
  is_service: false,
@@ -253547,7 +253587,7 @@ In order to complete registration use this verification code: ${otpCode}
253547
253587
  updated_date: now
253548
253588
  });
253549
253589
  res.json({
253550
- id: userData.id,
253590
+ id: privateUserData.id,
253551
253591
  access_token: createJwtToken(email3),
253552
253592
  message: "Email verified successfully. You are now logged in.",
253553
253593
  success: true
@@ -255715,7 +255755,7 @@ class WatchBase44 extends EventEmitter4 {
255715
255755
  var DEFAULT_PORT = 4400;
255716
255756
  var BASE44_APP_URL = "https://base44.app";
255717
255757
  async function createDevServer(options8) {
255718
- const { port: userPort, cwd } = options8;
255758
+ const { port: userPort } = options8;
255719
255759
  const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
255720
255760
  const baseUrl = `http://localhost:${port}`;
255721
255761
  const { functions, entities, project: project2 } = await options8.loadResources();
@@ -260359,4 +260399,4 @@ export {
260359
260399
  CLIExitError
260360
260400
  };
260361
260401
 
260362
- //# debugId=5FDDF606296BF31964756E2164756E21
260402
+ //# debugId=CB186C06DA18198C64756E2164756E21