@base44-preview/cli 0.0.50-pr.481.c44e2a5 → 0.0.50-pr.481.dbe6b4f

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
@@ -253941,23 +253941,29 @@ function evaluateOperator(recordValue, operator) {
253941
253941
  for (const [op2, opValue] of Object.entries(operator)) {
253942
253942
  switch (op2) {
253943
253943
  case "$in":
253944
- if (!Array.isArray(opValue) || !opValue.includes(recordValue))
253944
+ if (!Array.isArray(opValue) || !opValue.includes(recordValue)) {
253945
253945
  return false;
253946
+ }
253946
253947
  break;
253947
253948
  case "$nin":
253948
- if (Array.isArray(opValue) && opValue.includes(recordValue))
253949
+ if (!Array.isArray(opValue) || opValue.includes(recordValue)) {
253949
253950
  return false;
253951
+ }
253950
253952
  break;
253951
253953
  case "$ne":
253952
253954
  if (recordValue === opValue)
253953
253955
  return false;
253954
253956
  break;
253955
253957
  case "$all":
253956
- if (!Array.isArray(recordValue) || !Array.isArray(opValue))
253958
+ if (!Array.isArray(recordValue) || !Array.isArray(opValue)) {
253957
253959
  return false;
253958
- if (!opValue.every((v10) => recordValue.includes(v10)))
253960
+ }
253961
+ if (!opValue.every((v10) => recordValue.includes(v10))) {
253959
253962
  return false;
253963
+ }
253960
253964
  break;
253965
+ default:
253966
+ return false;
253961
253967
  }
253962
253968
  }
253963
253969
  return true;
@@ -254212,9 +254218,15 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254212
254218
  const parseBody = import_express4.json();
254213
254219
  function withCollection(handler) {
254214
254220
  return async (req, res) => {
254215
- const collection = db2.getCollection(req.params.entityName);
254221
+ const { entityName } = req.params;
254222
+ const collection = db2.getCollection(entityName);
254216
254223
  if (!collection) {
254217
- res.status(404).json({ error: `Entity "${req.params.entityName}" not found` });
254224
+ res.status(404).json({ error: `Entity "${entityName}" not found` });
254225
+ return;
254226
+ }
254227
+ const schema10 = db2.getSchema(entityName);
254228
+ if (!schema10) {
254229
+ res.status(404).json({ error: `Schema for "${entityName}" not found` });
254218
254230
  return;
254219
254231
  }
254220
254232
  let currentUser;
@@ -254223,7 +254235,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254223
254235
  const { payload } = import_jsonwebtoken3.default.decode(auth2.replace("Bearer ", ""), { complete: true }) ?? {};
254224
254236
  currentUser = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: payload?.sub });
254225
254237
  } catch {}
254226
- await handler(req, res, collection, currentUser);
254238
+ await handler(req, res, collection, schema10, currentUser);
254227
254239
  };
254228
254240
  }
254229
254241
  function emit(appId, entityName, type, data) {
@@ -254243,7 +254255,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254243
254255
  }
254244
254256
  const userRouter = createUserRouter(db2, logger2);
254245
254257
  router.use("/User", userRouter);
254246
- router.get("/:entityName/:id", withCollection(async (req, res, collection, currentUser) => {
254258
+ router.get("/:entityName/:id", withCollection(async (req, res, collection, schema10, currentUser) => {
254247
254259
  const { entityName, id: id2 } = req.params;
254248
254260
  try {
254249
254261
  const doc2 = await collection.findOneAsync({ id: id2 });
@@ -254251,38 +254263,27 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254251
254263
  res.status(404).json({ error: `Record with id "${id2}" not found` });
254252
254264
  return;
254253
254265
  }
254254
- const schema10 = db2.getSchema(entityName);
254255
- if (!checkRLS(schema10?.rls?.read, doc2, currentUser)) {
254266
+ if (!checkRLS(schema10.rls?.read, doc2, currentUser)) {
254256
254267
  res.status(404).json({
254257
- message: `Entity Task with ID ${id2} not found`
254268
+ message: `Entity ${entityName} with ID ${id2} not found`
254258
254269
  });
254259
254270
  return;
254260
254271
  }
254261
- let result = stripInternalFields(doc2);
254262
- if (schema10) {
254263
- result = applyFLS(result, schema10, currentUser, "read");
254264
- }
254272
+ const result = applyFLS(stripInternalFields(doc2), schema10, currentUser, "read");
254265
254273
  res.json(result);
254266
254274
  } catch (error48) {
254267
254275
  logger2.error(`Error in GET /${entityName}/${id2}:`, error48);
254268
254276
  res.status(500).json({ error: "Internal server error" });
254269
254277
  }
254270
254278
  }));
254271
- router.get("/:entityName", withCollection(async (req, res, collection, currentUser) => {
254279
+ router.get("/:entityName", withCollection(async (req, res, collection, schema10, currentUser) => {
254272
254280
  const { entityName } = req.params;
254273
254281
  try {
254274
- const schema10 = db2.getSchema(entityName);
254275
- if (schema10?.rls?.read === false) {
254276
- res.json([]);
254277
- return;
254278
- }
254279
254282
  let results = stripInternalFields(await queryEntity(collection, req.query));
254280
- if (schema10?.rls?.read && schema10.rls.read !== true) {
254283
+ if (schema10.rls?.read && schema10.rls.read !== true) {
254281
254284
  results = results.filter((doc2) => checkRLS(schema10.rls.read, doc2, currentUser));
254282
254285
  }
254283
- if (schema10) {
254284
- results = results.map((doc2) => applyFLS(doc2, schema10, currentUser, "read"));
254285
- }
254286
+ results = results.map((doc2) => applyFLS(doc2, schema10, currentUser, "read"));
254286
254287
  res.json(results);
254287
254288
  } catch (error48) {
254288
254289
  if (error48 instanceof InvalidInputError) {
@@ -254293,12 +254294,11 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254293
254294
  }
254294
254295
  }
254295
254296
  }));
254296
- router.post("/:entityName", parseBody, withCollection(async (req, res, collection, currentUser) => {
254297
+ router.post("/:entityName", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254297
254298
  const { appId, entityName } = req.params;
254298
254299
  try {
254299
254300
  const now = new Date().toISOString();
254300
254301
  const { _id, ...body } = req.body;
254301
- const schema10 = db2.getSchema(entityName);
254302
254302
  if (!checkRLS(schema10?.rls?.create, {
254303
254303
  ...body,
254304
254304
  created_by: currentUser?.email,
@@ -254307,10 +254307,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254307
254307
  res.status(403).json({ error: "Permission denied" });
254308
254308
  return;
254309
254309
  }
254310
- let filteredBody = db2.prepareRecord(entityName, body);
254311
- if (schema10) {
254312
- filteredBody = applyFLS(filteredBody, schema10, currentUser, "write");
254313
- }
254310
+ const filteredBody = applyFLS(db2.prepareRecord(entityName, body), schema10, currentUser, "write");
254314
254311
  db2.validate(entityName, filteredBody);
254315
254312
  const record2 = {
254316
254313
  ...filteredBody,
@@ -254320,7 +254317,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254320
254317
  created_date: now,
254321
254318
  updated_date: now
254322
254319
  };
254323
- const inserted = stripInternalFields(await collection.insertAsync(record2));
254320
+ const inserted = applyFLS(stripInternalFields(await collection.insertAsync(record2)), schema10, currentUser, "read");
254324
254321
  emit(appId, entityName, "create", inserted);
254325
254322
  res.status(201).json(inserted);
254326
254323
  } catch (error48) {
@@ -254332,7 +254329,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254332
254329
  res.status(500).json({ error: "Internal server error" });
254333
254330
  }
254334
254331
  }));
254335
- router.post("/:entityName/bulk", parseBody, withCollection(async (req, res, collection, currentUser) => {
254332
+ router.post("/:entityName/bulk", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254336
254333
  const { appId, entityName } = req.params;
254337
254334
  if (!Array.isArray(req.body)) {
254338
254335
  res.status(400).json({ error: "Request body must be an array" });
@@ -254340,7 +254337,6 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254340
254337
  }
254341
254338
  try {
254342
254339
  const now = new Date().toISOString();
254343
- const schema10 = db2.getSchema(entityName);
254344
254340
  const records = [];
254345
254341
  for (const record2 of req.body) {
254346
254342
  if (!checkRLS(schema10?.rls?.create, {
@@ -254377,12 +254373,11 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254377
254373
  res.status(500).json({ error: "Internal server error" });
254378
254374
  }
254379
254375
  }));
254380
- router.put("/:entityName/:id", parseBody, withCollection(async (req, res, collection, currentUser) => {
254376
+ router.put("/:entityName/:id", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254381
254377
  const { appId, entityName, id: id2 } = req.params;
254382
254378
  const { id: _id, created_date: _created_date, ...body } = req.body;
254383
254379
  try {
254384
- const schema10 = db2.getSchema(entityName);
254385
- if (schema10?.rls?.update !== undefined) {
254380
+ if (schema10.rls?.update !== undefined) {
254386
254381
  const existing = await collection.findOneAsync({ id: id2 });
254387
254382
  if (!existing) {
254388
254383
  res.status(404).json({ error: `Record with id "${id2}" not found` });
@@ -254390,15 +254385,12 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254390
254385
  }
254391
254386
  if (!checkRLS(schema10.rls.update, existing, currentUser)) {
254392
254387
  res.status(404).json({
254393
- message: `Entity Task with ID ${id2} not found`
254388
+ message: `Entity ${entityName} with ID ${id2} not found`
254394
254389
  });
254395
254390
  return;
254396
254391
  }
254397
254392
  }
254398
- let filteredBody = db2.prepareRecord(entityName, body, true);
254399
- if (schema10) {
254400
- filteredBody = applyFLS(filteredBody, schema10, currentUser, "write");
254401
- }
254393
+ const filteredBody = applyFLS(db2.prepareRecord(entityName, body, true), schema10, currentUser, "write");
254402
254394
  db2.validate(entityName, filteredBody, true);
254403
254395
  const updateData = {
254404
254396
  ...filteredBody,
@@ -254409,7 +254401,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254409
254401
  res.status(404).json({ error: `Record with id "${id2}" not found` });
254410
254402
  return;
254411
254403
  }
254412
- const updated = stripInternalFields(result.affectedDocuments);
254404
+ const updated = applyFLS(stripInternalFields(result.affectedDocuments), schema10, currentUser, "read");
254413
254405
  emit(appId, entityName, "update", updated);
254414
254406
  res.json(updated);
254415
254407
  } catch (error48) {
@@ -254421,7 +254413,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254421
254413
  res.status(500).json({ error: "Internal server error" });
254422
254414
  }
254423
254415
  }));
254424
- router.delete("/:entityName/:id", withCollection(async (req, res, collection, currentUser) => {
254416
+ router.delete("/:entityName/:id", withCollection(async (req, res, collection, schema10, currentUser) => {
254425
254417
  const { appId, entityName, id: id2 } = req.params;
254426
254418
  try {
254427
254419
  const doc2 = await collection.findOneAsync({ id: id2 });
@@ -254429,10 +254421,9 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254429
254421
  res.status(404).json({ error: `Record with id "${id2}" not found` });
254430
254422
  return;
254431
254423
  }
254432
- const schema10 = db2.getSchema(entityName);
254433
- if (!checkRLS(schema10?.rls?.delete, doc2, currentUser)) {
254424
+ if (!checkRLS(schema10.rls?.delete, doc2, currentUser)) {
254434
254425
  res.status(404).json({
254435
- message: `Entity Task with ID ${id2} not found`
254426
+ message: `Entity ${entityName} with ID ${id2} not found`
254436
254427
  });
254437
254428
  return;
254438
254429
  }
@@ -254444,11 +254435,10 @@ async function createEntityRoutes(db2, logger2, broadcast) {
254444
254435
  res.status(500).json({ error: "Internal server error" });
254445
254436
  }
254446
254437
  }));
254447
- router.delete("/:entityName", parseBody, withCollection(async (req, res, collection, currentUser) => {
254438
+ router.delete("/:entityName", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
254448
254439
  const { entityName } = req.params;
254449
254440
  try {
254450
254441
  const query = req.body || {};
254451
- const schema10 = db2.getSchema(entityName);
254452
254442
  const rlsDelete = schema10?.rls?.delete;
254453
254443
  if (rlsDelete !== undefined && rlsDelete !== true) {
254454
254444
  if (rlsDelete === false) {
@@ -256264,7 +256254,9 @@ var DEFAULT_PORT = 4400;
256264
256254
  var BASE44_APP_URL = "https://base44.app";
256265
256255
  async function createDevServer(options8) {
256266
256256
  const { port: userPort } = options8;
256267
- const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
256257
+ const port = userPort ?? await getPorts({
256258
+ port: process.env.IS_TEST === "true" ? undefined : DEFAULT_PORT
256259
+ });
256268
256260
  const baseUrl = `http://localhost:${port}`;
256269
256261
  const { functions, entities, project: project2 } = await options8.loadResources();
256270
256262
  const app = import_express6.default();
@@ -260876,4 +260868,4 @@ export {
260876
260868
  CLIExitError
260877
260869
  };
260878
260870
 
260879
- //# debugId=7538A503FE5FF74364756E2164756E21
260871
+ //# debugId=731CCB72EF64A04D64756E2164756E21