@base44-preview/cli 0.0.45-pr.406.30e44d9 → 0.0.45-pr.406.9125087

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
@@ -248900,7 +248900,7 @@ function getTypesCommand() {
248900
248900
  // src/cli/dev/dev-server/main.ts
248901
248901
  import { dirname as dirname14, join as join20 } from "node:path";
248902
248902
  var import_cors = __toESM(require_lib4(), 1);
248903
- var import_express6 = __toESM(require_express(), 1);
248903
+ var import_express5 = __toESM(require_express(), 1);
248904
248904
 
248905
248905
  // ../../node_modules/get-port/index.js
248906
248906
  import net from "node:net";
@@ -249288,11 +249288,23 @@ function nanoid3(size = 21) {
249288
249288
  return id2;
249289
249289
  }
249290
249290
 
249291
+ // src/cli/dev/dev-server/utils.ts
249292
+ function stripInternalFields(doc2) {
249293
+ if (Array.isArray(doc2)) {
249294
+ return doc2.map((d5) => stripInternalFields(d5));
249295
+ }
249296
+ const { _id, ...rest } = doc2;
249297
+ return rest;
249298
+ }
249299
+ var getNowISOTimestamp = () => {
249300
+ return new Date().toISOString().replace("Z", "000");
249301
+ };
249302
+
249291
249303
  // src/cli/dev/dev-server/db/validator.ts
249292
249304
  class EntityValidationError extends Error {
249293
249305
  context;
249294
249306
  constructor(context) {
249295
- super();
249307
+ super(context.message);
249296
249308
  this.context = context;
249297
249309
  }
249298
249310
  }
@@ -249445,11 +249457,24 @@ class Database {
249445
249457
  schemas = new Map;
249446
249458
  validator = new Validator;
249447
249459
  async load(entities) {
249448
- const userDataStore = new import_nedb.default;
249449
- this.collections.set(USER_COLLECTION, userDataStore);
249460
+ await this.loadUserCollection(entities);
249461
+ for (const entity2 of entities) {
249462
+ const entityName = this.normalizeName(entity2.name);
249463
+ if (entityName === USER_COLLECTION) {
249464
+ continue;
249465
+ }
249466
+ this.collections.set(entityName, new import_nedb.default);
249467
+ this.schemas.set(entityName, entity2);
249468
+ }
249469
+ }
249470
+ async loadUserCollection(entities) {
249471
+ const userEntity = entities.find((e8) => this.normalizeName(e8.name) === USER_COLLECTION);
249472
+ this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
249473
+ const collection = new import_nedb.default;
249474
+ this.collections.set(USER_COLLECTION, collection);
249450
249475
  const userInfo = await readAuth();
249451
- const now = new Date().toISOString().replace("Z", "000");
249452
- await userDataStore.insertAsync({
249476
+ const now = getNowISOTimestamp();
249477
+ await collection.insertAsync({
249453
249478
  id: nanoid3(),
249454
249479
  email: userInfo.email,
249455
249480
  full_name: userInfo.name,
@@ -249461,33 +249486,28 @@ class Database {
249461
249486
  created_date: now,
249462
249487
  updated_date: now
249463
249488
  });
249464
- for (const entity2 of entities) {
249465
- const entityName = this.normalizeName(entity2.name);
249466
- const clonedEntity = structuredClone(entity2);
249467
- if (entityName === USER_COLLECTION) {
249468
- ["full_name", "email"].forEach((predefinedField) => {
249469
- if (predefinedField in clonedEntity.properties) {
249470
- throw new Error(`Error syncing entities: Invalid User schema: User schema cannot contain base fields: ${predefinedField}. These fields are built-in and managed by the system.`);
249471
- }
249472
- });
249473
- clonedEntity.properties.full_name = { type: "string" };
249474
- clonedEntity.properties.email = { type: "string" };
249475
- } else {
249476
- this.collections.set(entityName, new import_nedb.default);
249477
- }
249478
- this.schemas.set(entityName, clonedEntity);
249479
- }
249480
- if (!this.schemas.has(USER_COLLECTION)) {
249481
- this.schemas.set(USER_COLLECTION, {
249489
+ }
249490
+ buildUserSchema(customUserEntity) {
249491
+ const builtInFields = {
249492
+ full_name: { type: "string" },
249493
+ email: { type: "string" }
249494
+ };
249495
+ if (!customUserEntity) {
249496
+ return {
249482
249497
  name: "User",
249483
249498
  type: "object",
249484
- properties: {
249485
- full_name: { type: "string" },
249486
- email: { type: "string" },
249487
- role: { type: "string" }
249488
- }
249489
- });
249499
+ properties: { ...builtInFields, role: { type: "string" } }
249500
+ };
249501
+ }
249502
+ for (const field of Object.keys(builtInFields)) {
249503
+ if (field in customUserEntity.properties) {
249504
+ throw new Error(`Error syncing entities: Invalid User schema: User schema cannot contain base fields: ${field}. These fields are built-in and managed by the system.`);
249505
+ }
249490
249506
  }
249507
+ return {
249508
+ ...customUserEntity,
249509
+ properties: { ...customUserEntity.properties, ...builtInFields }
249510
+ };
249491
249511
  }
249492
249512
  getCollection(name2) {
249493
249513
  return this.collections.get(this.normalizeName(name2));
@@ -249562,18 +249582,7 @@ var import_express3 = __toESM(require_express(), 1);
249562
249582
 
249563
249583
  // src/cli/dev/dev-server/routes/entities/entities-user-router.ts
249564
249584
  var import_express2 = __toESM(require_express(), 1);
249565
-
249566
- // src/cli/dev/dev-server/routes/entities/utils.ts
249567
- function stripInternalFields(doc2) {
249568
- if (Array.isArray(doc2)) {
249569
- return doc2.map((d5) => stripInternalFields(d5));
249570
- }
249571
- const { _id, ...rest } = doc2;
249572
- return rest;
249573
- }
249574
-
249575
- // src/cli/dev/dev-server/routes/entities/entities-user-router.ts
249576
- async function createUserRouter(db2, logger) {
249585
+ function createUserRouter(db2, logger) {
249577
249586
  const router = import_express2.Router({ mergeParams: true });
249578
249587
  const parseBody = import_express2.json();
249579
249588
  router.get("/:id", async (req, res) => {
@@ -249594,7 +249603,7 @@ async function createUserRouter(db2, logger) {
249594
249603
  const userInfo = await readAuth();
249595
249604
  const currentUser = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: userInfo.email });
249596
249605
  if (currentUser) {
249597
- const now = new Date().toISOString().replace("Z", "000");
249606
+ const now = getNowISOTimestamp();
249598
249607
  res.json({
249599
249608
  created_by: userInfo.email,
249600
249609
  created_by_id: currentUser.id,
@@ -249608,9 +249617,6 @@ async function createUserRouter(db2, logger) {
249608
249617
  res.status(404).json({ error: "Unable to read data for the current user" });
249609
249618
  }
249610
249619
  });
249611
- router.post("/", async (_req, res) => {
249612
- res.json({});
249613
- });
249614
249620
  router.post("/bulk", async (_req, res) => {
249615
249621
  res.json({});
249616
249622
  });
@@ -249634,7 +249640,7 @@ async function createUserRouter(db2, logger) {
249634
249640
  if (!updResult?.affectedDocuments) {
249635
249641
  throw new Error(`Failed to update user`);
249636
249642
  }
249637
- res.json(updResult.affectedDocuments);
249643
+ res.json(stripInternalFields(updResult.affectedDocuments));
249638
249644
  } catch (error48) {
249639
249645
  if (error48 instanceof EntityValidationError) {
249640
249646
  res.status(422).json(error48.context);
@@ -249969,18 +249975,6 @@ function createCustomIntegrationRoutes(remoteProxy, logger) {
249969
249975
  return router;
249970
249976
  }
249971
249977
 
249972
- // src/cli/dev/dev-server/routes/users.ts
249973
- var import_express5 = __toESM(require_express(), 1);
249974
- function createUsersRoutes() {
249975
- const router = import_express5.Router({ mergeParams: true });
249976
- const parseBody = import_express5.json();
249977
- router.post("/invite-user", parseBody, (req, _res, next) => {
249978
- console.log("invite-user", req.body);
249979
- next();
249980
- });
249981
- return router;
249982
- }
249983
-
249984
249978
  // src/cli/dev/dev-server/watcher.ts
249985
249979
  import { EventEmitter as EventEmitter4 } from "node:events";
249986
249980
  import { relative as relative6 } from "node:path";
@@ -251685,7 +251679,7 @@ async function createDevServer(options8) {
251685
251679
  const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
251686
251680
  const baseUrl = `http://localhost:${port}`;
251687
251681
  const { functions, entities, project: project2 } = await options8.loadResources();
251688
- const app = import_express6.default();
251682
+ const app = import_express5.default();
251689
251683
  const remoteProxy = import_http_proxy_middleware2.createProxyMiddleware({
251690
251684
  target: BASE44_APP_URL,
251691
251685
  changeOrigin: true
@@ -251711,8 +251705,6 @@ async function createDevServer(options8) {
251711
251705
  next();
251712
251706
  });
251713
251707
  const devLogger = createDevLogger();
251714
- const usersRoutes = createUsersRoutes();
251715
- app.use("/api/apps/:appId/users", usersRoutes);
251716
251708
  const functionManager = new FunctionManager(functions, devLogger, options8.denoWrapperPath);
251717
251709
  const functionRoutes = createFunctionRouter(functionManager, devLogger);
251718
251710
  app.use("/api/apps/:appId/functions", functionRoutes);
@@ -251746,7 +251738,7 @@ async function createDevServer(options8) {
251746
251738
  }
251747
251739
  next();
251748
251740
  });
251749
- app.use("/media", import_express6.default.static(mediaFilesDir));
251741
+ app.use("/media", import_express5.default.static(mediaFilesDir));
251750
251742
  const integrationRoutes = createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, devLogger);
251751
251743
  app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
251752
251744
  const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
@@ -256209,4 +256201,4 @@ export {
256209
256201
  CLIExitError
256210
256202
  };
256211
256203
 
256212
- //# debugId=76FBDD916243B1D364756E2164756E21
256204
+ //# debugId=1F83CA1A65BEF01964756E2164756E21