@base44-preview/cli 0.0.50-pr.481.d091ce8 → 0.0.50-pr.481.e4f75d4
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 +33 -44
- package/dist/cli/index.js.map +4 -4
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -253962,6 +253962,8 @@ function evaluateOperator(recordValue, operator) {
|
|
|
253962
253962
|
return false;
|
|
253963
253963
|
}
|
|
253964
253964
|
break;
|
|
253965
|
+
default:
|
|
253966
|
+
return false;
|
|
253965
253967
|
}
|
|
253966
253968
|
}
|
|
253967
253969
|
return true;
|
|
@@ -254026,6 +254028,9 @@ function checkRLS(rule, record2, user) {
|
|
|
254026
254028
|
return evaluateCondition(rule, record2, user);
|
|
254027
254029
|
}
|
|
254028
254030
|
function applyFLS(record2, schema10, user, operation) {
|
|
254031
|
+
if (Array.isArray(record2)) {
|
|
254032
|
+
return record2.map((r5) => applyFLS(r5, schema10, user, operation));
|
|
254033
|
+
}
|
|
254029
254034
|
const result = {};
|
|
254030
254035
|
for (const [key2, value] of Object.entries(record2)) {
|
|
254031
254036
|
const rule = schema10.properties[key2]?.rls?.[operation];
|
|
@@ -254216,9 +254221,15 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254216
254221
|
const parseBody = import_express4.json();
|
|
254217
254222
|
function withCollection(handler) {
|
|
254218
254223
|
return async (req, res) => {
|
|
254219
|
-
const
|
|
254224
|
+
const { entityName } = req.params;
|
|
254225
|
+
const collection = db2.getCollection(entityName);
|
|
254220
254226
|
if (!collection) {
|
|
254221
|
-
res.status(404).json({ error: `Entity "${
|
|
254227
|
+
res.status(404).json({ error: `Entity "${entityName}" not found` });
|
|
254228
|
+
return;
|
|
254229
|
+
}
|
|
254230
|
+
const schema10 = db2.getSchema(entityName);
|
|
254231
|
+
if (!schema10) {
|
|
254232
|
+
res.status(404).json({ error: `Schema for "${entityName}" not found` });
|
|
254222
254233
|
return;
|
|
254223
254234
|
}
|
|
254224
254235
|
let currentUser;
|
|
@@ -254227,7 +254238,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254227
254238
|
const { payload } = import_jsonwebtoken3.default.decode(auth2.replace("Bearer ", ""), { complete: true }) ?? {};
|
|
254228
254239
|
currentUser = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: payload?.sub });
|
|
254229
254240
|
} catch {}
|
|
254230
|
-
await handler(req, res, collection, currentUser);
|
|
254241
|
+
await handler(req, res, collection, schema10, currentUser);
|
|
254231
254242
|
};
|
|
254232
254243
|
}
|
|
254233
254244
|
function emit(appId, entityName, type, data) {
|
|
@@ -254247,7 +254258,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254247
254258
|
}
|
|
254248
254259
|
const userRouter = createUserRouter(db2, logger2);
|
|
254249
254260
|
router.use("/User", userRouter);
|
|
254250
|
-
router.get("/:entityName/:id", withCollection(async (req, res, collection, currentUser) => {
|
|
254261
|
+
router.get("/:entityName/:id", withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254251
254262
|
const { entityName, id: id2 } = req.params;
|
|
254252
254263
|
try {
|
|
254253
254264
|
const doc2 = await collection.findOneAsync({ id: id2 });
|
|
@@ -254255,38 +254266,27 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254255
254266
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
254256
254267
|
return;
|
|
254257
254268
|
}
|
|
254258
|
-
|
|
254259
|
-
if (!checkRLS(schema10?.rls?.read, doc2, currentUser)) {
|
|
254269
|
+
if (!checkRLS(schema10.rls?.read, doc2, currentUser)) {
|
|
254260
254270
|
res.status(404).json({
|
|
254261
254271
|
message: `Entity ${entityName} with ID ${id2} not found`
|
|
254262
254272
|
});
|
|
254263
254273
|
return;
|
|
254264
254274
|
}
|
|
254265
|
-
|
|
254266
|
-
if (schema10) {
|
|
254267
|
-
result = applyFLS(result, schema10, currentUser, "read");
|
|
254268
|
-
}
|
|
254275
|
+
const result = applyFLS(stripInternalFields(doc2), schema10, currentUser, "read");
|
|
254269
254276
|
res.json(result);
|
|
254270
254277
|
} catch (error48) {
|
|
254271
254278
|
logger2.error(`Error in GET /${entityName}/${id2}:`, error48);
|
|
254272
254279
|
res.status(500).json({ error: "Internal server error" });
|
|
254273
254280
|
}
|
|
254274
254281
|
}));
|
|
254275
|
-
router.get("/:entityName", withCollection(async (req, res, collection, currentUser) => {
|
|
254282
|
+
router.get("/:entityName", withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254276
254283
|
const { entityName } = req.params;
|
|
254277
254284
|
try {
|
|
254278
|
-
const schema10 = db2.getSchema(entityName);
|
|
254279
|
-
if (schema10?.rls?.read === false) {
|
|
254280
|
-
res.json([]);
|
|
254281
|
-
return;
|
|
254282
|
-
}
|
|
254283
254285
|
let results = stripInternalFields(await queryEntity(collection, req.query));
|
|
254284
|
-
if (schema10
|
|
254286
|
+
if (schema10.rls?.read && schema10.rls.read !== true) {
|
|
254285
254287
|
results = results.filter((doc2) => checkRLS(schema10.rls.read, doc2, currentUser));
|
|
254286
254288
|
}
|
|
254287
|
-
|
|
254288
|
-
results = results.map((doc2) => applyFLS(doc2, schema10, currentUser, "read"));
|
|
254289
|
-
}
|
|
254289
|
+
results = results.map((doc2) => applyFLS(doc2, schema10, currentUser, "read"));
|
|
254290
254290
|
res.json(results);
|
|
254291
254291
|
} catch (error48) {
|
|
254292
254292
|
if (error48 instanceof InvalidInputError) {
|
|
@@ -254297,12 +254297,11 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254297
254297
|
}
|
|
254298
254298
|
}
|
|
254299
254299
|
}));
|
|
254300
|
-
router.post("/:entityName", parseBody, withCollection(async (req, res, collection, currentUser) => {
|
|
254300
|
+
router.post("/:entityName", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254301
254301
|
const { appId, entityName } = req.params;
|
|
254302
254302
|
try {
|
|
254303
254303
|
const now = new Date().toISOString();
|
|
254304
254304
|
const { _id, ...body } = req.body;
|
|
254305
|
-
const schema10 = db2.getSchema(entityName);
|
|
254306
254305
|
if (!checkRLS(schema10?.rls?.create, {
|
|
254307
254306
|
...body,
|
|
254308
254307
|
created_by: currentUser?.email,
|
|
@@ -254311,10 +254310,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254311
254310
|
res.status(403).json({ error: "Permission denied" });
|
|
254312
254311
|
return;
|
|
254313
254312
|
}
|
|
254314
|
-
|
|
254315
|
-
if (schema10) {
|
|
254316
|
-
filteredBody = applyFLS(filteredBody, schema10, currentUser, "write");
|
|
254317
|
-
}
|
|
254313
|
+
const filteredBody = applyFLS(db2.prepareRecord(entityName, body), schema10, currentUser, "write");
|
|
254318
254314
|
db2.validate(entityName, filteredBody);
|
|
254319
254315
|
const record2 = {
|
|
254320
254316
|
...filteredBody,
|
|
@@ -254324,7 +254320,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254324
254320
|
created_date: now,
|
|
254325
254321
|
updated_date: now
|
|
254326
254322
|
};
|
|
254327
|
-
const inserted = stripInternalFields(await collection.insertAsync(record2));
|
|
254323
|
+
const inserted = applyFLS(stripInternalFields(await collection.insertAsync(record2)), schema10, currentUser, "read");
|
|
254328
254324
|
emit(appId, entityName, "create", inserted);
|
|
254329
254325
|
res.status(201).json(inserted);
|
|
254330
254326
|
} catch (error48) {
|
|
@@ -254336,7 +254332,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254336
254332
|
res.status(500).json({ error: "Internal server error" });
|
|
254337
254333
|
}
|
|
254338
254334
|
}));
|
|
254339
|
-
router.post("/:entityName/bulk", parseBody, withCollection(async (req, res, collection, currentUser) => {
|
|
254335
|
+
router.post("/:entityName/bulk", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254340
254336
|
const { appId, entityName } = req.params;
|
|
254341
254337
|
if (!Array.isArray(req.body)) {
|
|
254342
254338
|
res.status(400).json({ error: "Request body must be an array" });
|
|
@@ -254344,7 +254340,6 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254344
254340
|
}
|
|
254345
254341
|
try {
|
|
254346
254342
|
const now = new Date().toISOString();
|
|
254347
|
-
const schema10 = db2.getSchema(entityName);
|
|
254348
254343
|
const records = [];
|
|
254349
254344
|
for (const record2 of req.body) {
|
|
254350
254345
|
if (!checkRLS(schema10?.rls?.create, {
|
|
@@ -254369,7 +254364,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254369
254364
|
updated_date: now
|
|
254370
254365
|
});
|
|
254371
254366
|
}
|
|
254372
|
-
const inserted = stripInternalFields(await collection.insertAsync(records));
|
|
254367
|
+
const inserted = applyFLS(stripInternalFields(await collection.insertAsync(records)), schema10, currentUser, "read");
|
|
254373
254368
|
emit(appId, entityName, "create", inserted);
|
|
254374
254369
|
res.status(201).json(inserted);
|
|
254375
254370
|
} catch (error48) {
|
|
@@ -254381,12 +254376,11 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254381
254376
|
res.status(500).json({ error: "Internal server error" });
|
|
254382
254377
|
}
|
|
254383
254378
|
}));
|
|
254384
|
-
router.put("/:entityName/:id", parseBody, withCollection(async (req, res, collection, currentUser) => {
|
|
254379
|
+
router.put("/:entityName/:id", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254385
254380
|
const { appId, entityName, id: id2 } = req.params;
|
|
254386
254381
|
const { id: _id, created_date: _created_date, ...body } = req.body;
|
|
254387
254382
|
try {
|
|
254388
|
-
|
|
254389
|
-
if (schema10?.rls?.update !== undefined) {
|
|
254383
|
+
if (schema10.rls?.update !== undefined) {
|
|
254390
254384
|
const existing = await collection.findOneAsync({ id: id2 });
|
|
254391
254385
|
if (!existing) {
|
|
254392
254386
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
@@ -254399,10 +254393,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254399
254393
|
return;
|
|
254400
254394
|
}
|
|
254401
254395
|
}
|
|
254402
|
-
|
|
254403
|
-
if (schema10) {
|
|
254404
|
-
filteredBody = applyFLS(filteredBody, schema10, currentUser, "write");
|
|
254405
|
-
}
|
|
254396
|
+
const filteredBody = applyFLS(db2.prepareRecord(entityName, body, true), schema10, currentUser, "write");
|
|
254406
254397
|
db2.validate(entityName, filteredBody, true);
|
|
254407
254398
|
const updateData = {
|
|
254408
254399
|
...filteredBody,
|
|
@@ -254413,7 +254404,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254413
254404
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
254414
254405
|
return;
|
|
254415
254406
|
}
|
|
254416
|
-
const updated = stripInternalFields(result.affectedDocuments);
|
|
254407
|
+
const updated = applyFLS(stripInternalFields(result.affectedDocuments), schema10, currentUser, "read");
|
|
254417
254408
|
emit(appId, entityName, "update", updated);
|
|
254418
254409
|
res.json(updated);
|
|
254419
254410
|
} catch (error48) {
|
|
@@ -254425,7 +254416,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254425
254416
|
res.status(500).json({ error: "Internal server error" });
|
|
254426
254417
|
}
|
|
254427
254418
|
}));
|
|
254428
|
-
router.delete("/:entityName/:id", withCollection(async (req, res, collection, currentUser) => {
|
|
254419
|
+
router.delete("/:entityName/:id", withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254429
254420
|
const { appId, entityName, id: id2 } = req.params;
|
|
254430
254421
|
try {
|
|
254431
254422
|
const doc2 = await collection.findOneAsync({ id: id2 });
|
|
@@ -254433,8 +254424,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254433
254424
|
res.status(404).json({ error: `Record with id "${id2}" not found` });
|
|
254434
254425
|
return;
|
|
254435
254426
|
}
|
|
254436
|
-
|
|
254437
|
-
if (!checkRLS(schema10?.rls?.delete, doc2, currentUser)) {
|
|
254427
|
+
if (!checkRLS(schema10.rls?.delete, doc2, currentUser)) {
|
|
254438
254428
|
res.status(404).json({
|
|
254439
254429
|
message: `Entity ${entityName} with ID ${id2} not found`
|
|
254440
254430
|
});
|
|
@@ -254448,11 +254438,10 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
254448
254438
|
res.status(500).json({ error: "Internal server error" });
|
|
254449
254439
|
}
|
|
254450
254440
|
}));
|
|
254451
|
-
router.delete("/:entityName", parseBody, withCollection(async (req, res, collection, currentUser) => {
|
|
254441
|
+
router.delete("/:entityName", parseBody, withCollection(async (req, res, collection, schema10, currentUser) => {
|
|
254452
254442
|
const { entityName } = req.params;
|
|
254453
254443
|
try {
|
|
254454
254444
|
const query = req.body || {};
|
|
254455
|
-
const schema10 = db2.getSchema(entityName);
|
|
254456
254445
|
const rlsDelete = schema10?.rls?.delete;
|
|
254457
254446
|
if (rlsDelete !== undefined && rlsDelete !== true) {
|
|
254458
254447
|
if (rlsDelete === false) {
|
|
@@ -260882,4 +260871,4 @@ export {
|
|
|
260882
260871
|
CLIExitError
|
|
260883
260872
|
};
|
|
260884
260873
|
|
|
260885
|
-
//# debugId=
|
|
260874
|
+
//# debugId=F32E631496E2C78D64756E2164756E21
|