@base44-preview/cli 0.0.50-pr.481.3fd0022 → 0.0.50-pr.481.74f9319

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
@@ -253295,15 +253295,21 @@ class FunctionManager {
253295
253295
  this.setupProcessHandlers(name2, process21);
253296
253296
  return this.waitForReady(name2, runningFunc);
253297
253297
  }
253298
- reload(functions) {
253299
- this.stopAll();
253298
+ async reload(functions) {
253299
+ await this.stopAll();
253300
253300
  this.functions = new Map(functions.map((f7) => [f7.name, f7]));
253301
253301
  }
253302
- stopAll() {
253303
- for (const [name2, { process: process21 }] of this.running) {
253302
+ async stopAll() {
253303
+ await Promise.all(Array.from(this.running, ([name2, { process: proc2 }]) => {
253304
253304
  this.logger.log(`Stopping function: ${name2}`);
253305
- process21.kill();
253306
- }
253305
+ const exited = new Promise((r5) => proc2.once("exit", () => r5()));
253306
+ if (process.platform === "win32" && proc2.pid) {
253307
+ spawn2("taskkill", ["/pid", String(proc2.pid), "/T", "/F"]);
253308
+ } else {
253309
+ proc2.kill();
253310
+ }
253311
+ return exited;
253312
+ }));
253307
253313
  this.running.clear();
253308
253314
  this.starting.clear();
253309
253315
  }
@@ -253946,10 +253952,7 @@ function evaluateOperator(recordValue, operator) {
253946
253952
  }
253947
253953
  break;
253948
253954
  case "$nin":
253949
- if (!Array.isArray(opValue)) {
253950
- return false;
253951
- }
253952
- if (Array.isArray(opValue) && opValue.includes(recordValue)) {
253955
+ if (!Array.isArray(opValue) || opValue.includes(recordValue)) {
253953
253956
  return false;
253954
253957
  }
253955
253958
  break;
@@ -253965,6 +253968,8 @@ function evaluateOperator(recordValue, operator) {
253965
253968
  return false;
253966
253969
  }
253967
253970
  break;
253971
+ default:
253972
+ return false;
253968
253973
  }
253969
253974
  }
253970
253975
  return true;
@@ -254029,6 +254034,9 @@ function checkRLS(rule, record2, user) {
254029
254034
  return evaluateCondition(rule, record2, user);
254030
254035
  }
254031
254036
  function applyFLS(record2, schema10, user, operation) {
254037
+ if (Array.isArray(record2)) {
254038
+ return record2.map((r5) => applyFLS(r5, schema10, user, operation));
254039
+ }
254032
254040
  const result = {};
254033
254041
  for (const [key2, value] of Object.entries(record2)) {
254034
254042
  const rule = schema10.properties[key2]?.rls?.[operation];
@@ -254219,9 +254227,15 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254219
254227
  const parseBody = import_express4.json();
254220
254228
  function withCollection(handler) {
254221
254229
  return async (req, res) => {
254222
- const collection = db2.getCollection(req.params.entityName);
254230
+ const { entityName } = req.params;
254231
+ const collection = db2.getCollection(entityName);
254223
254232
  if (!collection) {
254224
- res.status(404).json({ error: `Entity "${req.params.entityName}" not found` });
254233
+ res.status(404).json({ error: `Entity "${entityName}" not found` });
254234
+ return;
254235
+ }
254236
+ const schema10 = db2.getSchema(entityName);
254237
+ if (!schema10) {
254238
+ res.status(404).json({ error: `Schema for "${entityName}" not found` });
254225
254239
  return;
254226
254240
  }
254227
254241
  let currentUser;
@@ -254230,7 +254244,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254230
254244
  const { payload } = import_jsonwebtoken3.default.decode(auth2.replace("Bearer ", ""), { complete: true }) ?? {};
254231
254245
  currentUser = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: payload?.sub });
254232
254246
  } catch {}
254233
- await handler(req, res, collection, currentUser);
254247
+ await handler(req, res, collection, schema10, currentUser);
254234
254248
  };
254235
254249
  }
254236
254250
  function emit(appId, entityName, type, data) {
@@ -254250,7 +254264,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254250
254264
  }
254251
254265
  const userRouter = createUserRouter(db2, logger2);
254252
254266
  router.use("/User", userRouter);
254253
- router.get("/:entityName/:id", withCollection(async (req, res, collection, currentUser) => {
254267
+ router.get("/:entityName/:id", withCollection(async (req, res, collection, schema10, currentUser) => {
254254
254268
  const { entityName, id: id2 } = req.params;
254255
254269
  try {
254256
254270
  const doc2 = await collection.findOneAsync({ id: id2 });
@@ -254258,38 +254272,27 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254258
254272
  res.status(404).json({ error: `Record with id "${id2}" not found` });
254259
254273
  return;
254260
254274
  }
254261
- const schema10 = db2.getSchema(entityName);
254262
- if (!checkRLS(schema10?.rls?.read, doc2, currentUser)) {
254275
+ if (!checkRLS(schema10.rls?.read, doc2, currentUser)) {
254263
254276
  res.status(404).json({
254264
254277
  message: `Entity ${entityName} with ID ${id2} not found`
254265
254278
  });
254266
254279
  return;
254267
254280
  }
254268
- let result = stripInternalFields(doc2);
254269
- if (schema10) {
254270
- result = applyFLS(result, schema10, currentUser, "read");
254271
- }
254281
+ const result = applyFLS(stripInternalFields(doc2), schema10, currentUser, "read");
254272
254282
  res.json(result);
254273
254283
  } catch (error48) {
254274
254284
  logger2.error(`Error in GET /${entityName}/${id2}:`, error48);
254275
254285
  res.status(500).json({ error: "Internal server error" });
254276
254286
  }
254277
254287
  }));
254278
- router.get("/:entityName", withCollection(async (req, res, collection, currentUser) => {
254288
+ router.get("/:entityName", withCollection(async (req, res, collection, schema10, currentUser) => {
254279
254289
  const { entityName } = req.params;
254280
254290
  try {
254281
- const schema10 = db2.getSchema(entityName);
254282
- if (schema10?.rls?.read === false) {
254283
- res.json([]);
254284
- return;
254285
- }
254286
254291
  let results = stripInternalFields(await queryEntity(collection, req.query));
254287
- if (schema10?.rls?.read && schema10.rls.read !== true) {
254292
+ if (schema10.rls?.read && schema10.rls.read !== true) {
254288
254293
  results = results.filter((doc2) => checkRLS(schema10.rls.read, doc2, currentUser));
254289
254294
  }
254290
- if (schema10) {
254291
- results = results.map((doc2) => applyFLS(doc2, schema10, currentUser, "read"));
254292
- }
254295
+ results = results.map((doc2) => applyFLS(doc2, schema10, currentUser, "read"));
254293
254296
  res.json(results);
254294
254297
  } catch (error48) {
254295
254298
  if (error48 instanceof InvalidInputError) {
@@ -254300,12 +254303,11 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254300
254303
  }
254301
254304
  }
254302
254305
  }));
254303
- router.post("/:entityName", parseBody, withCollection(async (req, res, collection, currentUser) => {
254306
+ router.post("/:entityName", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254304
254307
  const { appId, entityName } = req.params;
254305
254308
  try {
254306
254309
  const now = new Date().toISOString();
254307
254310
  const { _id, ...body } = req.body;
254308
- const schema10 = db2.getSchema(entityName);
254309
254311
  if (!checkRLS(schema10?.rls?.create, {
254310
254312
  ...body,
254311
254313
  created_by: currentUser?.email,
@@ -254314,10 +254316,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254314
254316
  res.status(403).json({ error: "Permission denied" });
254315
254317
  return;
254316
254318
  }
254317
- let filteredBody = db2.prepareRecord(entityName, body);
254318
- if (schema10) {
254319
- filteredBody = applyFLS(filteredBody, schema10, currentUser, "write");
254320
- }
254319
+ const filteredBody = applyFLS(db2.prepareRecord(entityName, body), schema10, currentUser, "write");
254321
254320
  db2.validate(entityName, filteredBody);
254322
254321
  const record2 = {
254323
254322
  ...filteredBody,
@@ -254327,7 +254326,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254327
254326
  created_date: now,
254328
254327
  updated_date: now
254329
254328
  };
254330
- const inserted = stripInternalFields(await collection.insertAsync(record2));
254329
+ const inserted = applyFLS(stripInternalFields(await collection.insertAsync(record2)), schema10, currentUser, "read");
254331
254330
  emit(appId, entityName, "create", inserted);
254332
254331
  res.status(201).json(inserted);
254333
254332
  } catch (error48) {
@@ -254339,7 +254338,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254339
254338
  res.status(500).json({ error: "Internal server error" });
254340
254339
  }
254341
254340
  }));
254342
- router.post("/:entityName/bulk", parseBody, withCollection(async (req, res, collection, currentUser) => {
254341
+ router.post("/:entityName/bulk", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254343
254342
  const { appId, entityName } = req.params;
254344
254343
  if (!Array.isArray(req.body)) {
254345
254344
  res.status(400).json({ error: "Request body must be an array" });
@@ -254347,7 +254346,6 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254347
254346
  }
254348
254347
  try {
254349
254348
  const now = new Date().toISOString();
254350
- const schema10 = db2.getSchema(entityName);
254351
254349
  const records = [];
254352
254350
  for (const record2 of req.body) {
254353
254351
  if (!checkRLS(schema10?.rls?.create, {
@@ -254372,7 +254370,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254372
254370
  updated_date: now
254373
254371
  });
254374
254372
  }
254375
- const inserted = stripInternalFields(await collection.insertAsync(records));
254373
+ const inserted = applyFLS(stripInternalFields(await collection.insertAsync(records)), schema10, currentUser, "read");
254376
254374
  emit(appId, entityName, "create", inserted);
254377
254375
  res.status(201).json(inserted);
254378
254376
  } catch (error48) {
@@ -254384,12 +254382,11 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254384
254382
  res.status(500).json({ error: "Internal server error" });
254385
254383
  }
254386
254384
  }));
254387
- router.put("/:entityName/:id", parseBody, withCollection(async (req, res, collection, currentUser) => {
254385
+ router.put("/:entityName/:id", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254388
254386
  const { appId, entityName, id: id2 } = req.params;
254389
254387
  const { id: _id, created_date: _created_date, ...body } = req.body;
254390
254388
  try {
254391
- const schema10 = db2.getSchema(entityName);
254392
- if (schema10?.rls?.update !== undefined) {
254389
+ if (schema10.rls?.update !== undefined) {
254393
254390
  const existing = await collection.findOneAsync({ id: id2 });
254394
254391
  if (!existing) {
254395
254392
  res.status(404).json({ error: `Record with id "${id2}" not found` });
@@ -254402,10 +254399,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254402
254399
  return;
254403
254400
  }
254404
254401
  }
254405
- let filteredBody = db2.prepareRecord(entityName, body, true);
254406
- if (schema10) {
254407
- filteredBody = applyFLS(filteredBody, schema10, currentUser, "write");
254408
- }
254402
+ const filteredBody = applyFLS(db2.prepareRecord(entityName, body, true), schema10, currentUser, "write");
254409
254403
  db2.validate(entityName, filteredBody, true);
254410
254404
  const updateData = {
254411
254405
  ...filteredBody,
@@ -254416,7 +254410,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254416
254410
  res.status(404).json({ error: `Record with id "${id2}" not found` });
254417
254411
  return;
254418
254412
  }
254419
- const updated = stripInternalFields(result.affectedDocuments);
254413
+ const updated = applyFLS(stripInternalFields(result.affectedDocuments), schema10, currentUser, "read");
254420
254414
  emit(appId, entityName, "update", updated);
254421
254415
  res.json(updated);
254422
254416
  } catch (error48) {
@@ -254428,7 +254422,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254428
254422
  res.status(500).json({ error: "Internal server error" });
254429
254423
  }
254430
254424
  }));
254431
- router.delete("/:entityName/:id", withCollection(async (req, res, collection, currentUser) => {
254425
+ router.delete("/:entityName/:id", withCollection(async (req, res, collection, schema10, currentUser) => {
254432
254426
  const { appId, entityName, id: id2 } = req.params;
254433
254427
  try {
254434
254428
  const doc2 = await collection.findOneAsync({ id: id2 });
@@ -254436,8 +254430,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254436
254430
  res.status(404).json({ error: `Record with id "${id2}" not found` });
254437
254431
  return;
254438
254432
  }
254439
- const schema10 = db2.getSchema(entityName);
254440
- if (!checkRLS(schema10?.rls?.delete, doc2, currentUser)) {
254433
+ if (!checkRLS(schema10.rls?.delete, doc2, currentUser)) {
254441
254434
  res.status(404).json({
254442
254435
  message: `Entity ${entityName} with ID ${id2} not found`
254443
254436
  });
@@ -254451,11 +254444,10 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254451
254444
  res.status(500).json({ error: "Internal server error" });
254452
254445
  }
254453
254446
  }));
254454
- router.delete("/:entityName", parseBody, withCollection(async (req, res, collection, currentUser) => {
254447
+ router.delete("/:entityName", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254455
254448
  const { entityName } = req.params;
254456
254449
  try {
254457
254450
  const query = req.body || {};
254458
- const schema10 = db2.getSchema(entityName);
254459
254451
  const rlsDelete = schema10?.rls?.delete;
254460
254452
  if (rlsDelete !== undefined && rlsDelete !== true) {
254461
254453
  if (rlsDelete === false) {
@@ -256271,7 +256263,9 @@ var DEFAULT_PORT = 4400;
256271
256263
  var BASE44_APP_URL = "https://base44.app";
256272
256264
  async function createDevServer(options8) {
256273
256265
  const { port: userPort } = options8;
256274
- const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
256266
+ const port = userPort ?? await getPorts({
256267
+ port: process.env.IS_TEST === "true" ? undefined : DEFAULT_PORT
256268
+ });
256275
256269
  const baseUrl = `http://localhost:${port}`;
256276
256270
  const { functions, entities, project: project2 } = await options8.loadResources();
256277
256271
  const app = import_express6.default();
@@ -256364,7 +256358,7 @@ async function createDevServer(options8) {
256364
256358
  const { functions: functions2, entities: entities2 } = await options8.loadResources();
256365
256359
  if (name2 === "functions") {
256366
256360
  const previousFunctionCount = functionManager.getFunctionNames().length;
256367
- functionManager.reload(functions2);
256361
+ await functionManager.reload(functions2);
256368
256362
  const names = functionManager.getFunctionNames();
256369
256363
  if (names.length > 0) {
256370
256364
  devLogger.log(`Reloaded functions: ${names.sort().join(", ")}`);
@@ -256389,10 +256383,10 @@ async function createDevServer(options8) {
256389
256383
  }
256390
256384
  });
256391
256385
  await base44ConfigWatcher.start();
256392
- const shutdown = () => {
256386
+ const shutdown = async () => {
256393
256387
  base44ConfigWatcher.close();
256394
256388
  io6.close();
256395
- functionManager.stopAll();
256389
+ await functionManager.stopAll();
256396
256390
  server.close();
256397
256391
  };
256398
256392
  process.on("SIGINT", shutdown);
@@ -260883,4 +260877,4 @@ export {
260883
260877
  CLIExitError
260884
260878
  };
260885
260879
 
260886
- //# debugId=759CD39E93FDA9AF64756E2164756E21
260880
+ //# debugId=2B2A7DAF2A94A3A064756E2164756E21