@base44-preview/cli 0.0.47-pr.370.f58c3ef → 0.0.47-pr.406.1043c2c
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 +243 -114
- package/dist/cli/index.js.map +14 -12
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -179494,19 +179494,19 @@ var require_base64id = __commonJS((exports, module) => {
|
|
|
179494
179494
|
/*!
|
|
179495
179495
|
* base64id v0.1.0
|
|
179496
179496
|
*/
|
|
179497
|
-
var
|
|
179497
|
+
var crypto2 = __require("crypto");
|
|
179498
179498
|
var Base64Id = function() {};
|
|
179499
179499
|
Base64Id.prototype.getRandomBytes = function(bytes) {
|
|
179500
179500
|
var BUFFER_SIZE = 4096;
|
|
179501
179501
|
var self2 = this;
|
|
179502
179502
|
bytes = bytes || 12;
|
|
179503
179503
|
if (bytes > BUFFER_SIZE) {
|
|
179504
|
-
return
|
|
179504
|
+
return crypto2.randomBytes(bytes);
|
|
179505
179505
|
}
|
|
179506
179506
|
var bytesInBuffer = parseInt(BUFFER_SIZE / bytes);
|
|
179507
179507
|
var threshold = parseInt(bytesInBuffer * 0.85);
|
|
179508
179508
|
if (!threshold) {
|
|
179509
|
-
return
|
|
179509
|
+
return crypto2.randomBytes(bytes);
|
|
179510
179510
|
}
|
|
179511
179511
|
if (this.bytesBufferIndex == null) {
|
|
179512
179512
|
this.bytesBufferIndex = -1;
|
|
@@ -179518,14 +179518,14 @@ var require_base64id = __commonJS((exports, module) => {
|
|
|
179518
179518
|
if (this.bytesBufferIndex == -1 || this.bytesBufferIndex > threshold) {
|
|
179519
179519
|
if (!this.isGeneratingBytes) {
|
|
179520
179520
|
this.isGeneratingBytes = true;
|
|
179521
|
-
|
|
179521
|
+
crypto2.randomBytes(BUFFER_SIZE, function(err, bytes2) {
|
|
179522
179522
|
self2.bytesBuffer = bytes2;
|
|
179523
179523
|
self2.bytesBufferIndex = 0;
|
|
179524
179524
|
self2.isGeneratingBytes = false;
|
|
179525
179525
|
});
|
|
179526
179526
|
}
|
|
179527
179527
|
if (this.bytesBufferIndex == -1) {
|
|
179528
|
-
return
|
|
179528
|
+
return crypto2.randomBytes(bytes);
|
|
179529
179529
|
}
|
|
179530
179530
|
}
|
|
179531
179531
|
var result = this.bytesBuffer.slice(bytes * this.bytesBufferIndex, bytes * (this.bytesBufferIndex + 1));
|
|
@@ -179539,7 +179539,7 @@ var require_base64id = __commonJS((exports, module) => {
|
|
|
179539
179539
|
}
|
|
179540
179540
|
this.sequenceNumber = this.sequenceNumber + 1 | 0;
|
|
179541
179541
|
rand.writeInt32BE(this.sequenceNumber, 11);
|
|
179542
|
-
if (
|
|
179542
|
+
if (crypto2.randomBytes) {
|
|
179543
179543
|
this.getRandomBytes(12).copy(rand);
|
|
179544
179544
|
} else {
|
|
179545
179545
|
[0, 4, 8].forEach(function(i5) {
|
|
@@ -231030,15 +231030,11 @@ var SiteConfigSchema = exports_external.object({
|
|
|
231030
231030
|
outputDirectory: exports_external.string().optional(),
|
|
231031
231031
|
installCommand: exports_external.string().optional()
|
|
231032
231032
|
});
|
|
231033
|
-
var VisibilitySchema = exports_external.enum(["public", "private", "workspace"], {
|
|
231034
|
-
error: 'Invalid visibility value. Allowed values: "public", "private", "workspace"'
|
|
231035
|
-
});
|
|
231036
231033
|
var ProjectConfigSchema = exports_external.object({
|
|
231037
231034
|
name: exports_external.string({
|
|
231038
231035
|
error: "App name cannot be empty"
|
|
231039
231036
|
}).min(1, "App name cannot be empty"),
|
|
231040
231037
|
description: exports_external.string().optional(),
|
|
231041
|
-
visibility: VisibilitySchema.optional(),
|
|
231042
231038
|
site: SiteConfigSchema.optional(),
|
|
231043
231039
|
entitiesDir: exports_external.string().optional().default("entities"),
|
|
231044
231040
|
functionsDir: exports_external.string().optional().default("functions"),
|
|
@@ -239376,7 +239372,7 @@ async function createProject(projectName, description) {
|
|
|
239376
239372
|
name: projectName,
|
|
239377
239373
|
user_description: description ?? `Backend for '${projectName}'`,
|
|
239378
239374
|
is_managed_source_code: false,
|
|
239379
|
-
public_settings: "
|
|
239375
|
+
public_settings: "public_without_login"
|
|
239380
239376
|
}
|
|
239381
239377
|
});
|
|
239382
239378
|
} catch (error48) {
|
|
@@ -239390,23 +239386,6 @@ async function createProject(projectName, description) {
|
|
|
239390
239386
|
projectId: result.data.id
|
|
239391
239387
|
};
|
|
239392
239388
|
}
|
|
239393
|
-
var VISIBILITY_TO_PUBLIC_SETTINGS = {
|
|
239394
|
-
public: "public_without_login",
|
|
239395
|
-
private: "private_with_login",
|
|
239396
|
-
workspace: "workspace_with_login"
|
|
239397
|
-
};
|
|
239398
|
-
async function updateProjectVisibility(visibility) {
|
|
239399
|
-
const { id } = getAppConfig();
|
|
239400
|
-
try {
|
|
239401
|
-
await base44Client.put(`api/apps/${id}`, {
|
|
239402
|
-
json: {
|
|
239403
|
-
public_settings: VISIBILITY_TO_PUBLIC_SETTINGS[visibility]
|
|
239404
|
-
}
|
|
239405
|
-
});
|
|
239406
|
-
} catch (error48) {
|
|
239407
|
-
throw await ApiError.fromHttpError(error48, "updating project visibility");
|
|
239408
|
-
}
|
|
239409
|
-
}
|
|
239410
239389
|
async function listProjects() {
|
|
239411
239390
|
let response;
|
|
239412
239391
|
try {
|
|
@@ -239736,9 +239715,6 @@ async function deployAll(projectData, options) {
|
|
|
239736
239715
|
});
|
|
239737
239716
|
await agentResource.push(agents);
|
|
239738
239717
|
const { results: connectorResults } = await pushConnectors(connectors);
|
|
239739
|
-
if (project.visibility) {
|
|
239740
|
-
await updateProjectVisibility(project.visibility);
|
|
239741
|
-
}
|
|
239742
239718
|
if (project.site?.outputDirectory) {
|
|
239743
239719
|
const outputDir = resolve(project.root, project.site.outputDirectory);
|
|
239744
239720
|
const { appUrl } = await deploySite(outputDir);
|
|
@@ -248950,7 +248926,7 @@ function getTypesCommand() {
|
|
|
248950
248926
|
// src/cli/dev/dev-server/main.ts
|
|
248951
248927
|
import { dirname as dirname14, join as join20 } from "node:path";
|
|
248952
248928
|
var import_cors = __toESM(require_lib4(), 1);
|
|
248953
|
-
var
|
|
248929
|
+
var import_express5 = __toESM(require_express(), 1);
|
|
248954
248930
|
|
|
248955
248931
|
// ../../node_modules/get-port/index.js
|
|
248956
248932
|
import net from "node:net";
|
|
@@ -249301,7 +249277,56 @@ function createFunctionRouter(manager, logger) {
|
|
|
249301
249277
|
// src/cli/dev/dev-server/db/database.ts
|
|
249302
249278
|
var import_nedb = __toESM(require_nedb(), 1);
|
|
249303
249279
|
|
|
249280
|
+
// ../../node_modules/nanoid/index.js
|
|
249281
|
+
import { webcrypto as crypto } from "node:crypto";
|
|
249282
|
+
|
|
249283
|
+
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
249284
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
249285
|
+
|
|
249286
|
+
// ../../node_modules/nanoid/index.js
|
|
249287
|
+
var POOL_SIZE_MULTIPLIER = 128;
|
|
249288
|
+
var pool;
|
|
249289
|
+
var poolOffset;
|
|
249290
|
+
function fillPool(bytes) {
|
|
249291
|
+
if (!pool || pool.length < bytes) {
|
|
249292
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
249293
|
+
crypto.getRandomValues(pool);
|
|
249294
|
+
poolOffset = 0;
|
|
249295
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
249296
|
+
crypto.getRandomValues(pool);
|
|
249297
|
+
poolOffset = 0;
|
|
249298
|
+
}
|
|
249299
|
+
poolOffset += bytes;
|
|
249300
|
+
}
|
|
249301
|
+
function nanoid3(size = 21) {
|
|
249302
|
+
fillPool(size |= 0);
|
|
249303
|
+
let id2 = "";
|
|
249304
|
+
for (let i5 = poolOffset - size;i5 < poolOffset; i5++) {
|
|
249305
|
+
id2 += urlAlphabet[pool[i5] & 63];
|
|
249306
|
+
}
|
|
249307
|
+
return id2;
|
|
249308
|
+
}
|
|
249309
|
+
|
|
249310
|
+
// src/cli/dev/dev-server/utils.ts
|
|
249311
|
+
function stripInternalFields(doc2) {
|
|
249312
|
+
if (Array.isArray(doc2)) {
|
|
249313
|
+
return doc2.map((d5) => stripInternalFields(d5));
|
|
249314
|
+
}
|
|
249315
|
+
const { _id, ...rest } = doc2;
|
|
249316
|
+
return rest;
|
|
249317
|
+
}
|
|
249318
|
+
var getNowISOTimestamp = () => {
|
|
249319
|
+
return new Date().toISOString().replace("Z", "000");
|
|
249320
|
+
};
|
|
249321
|
+
|
|
249304
249322
|
// src/cli/dev/dev-server/db/validator.ts
|
|
249323
|
+
class EntityValidationError extends Error {
|
|
249324
|
+
context;
|
|
249325
|
+
constructor(context) {
|
|
249326
|
+
super(context.message);
|
|
249327
|
+
this.context = context;
|
|
249328
|
+
}
|
|
249329
|
+
}
|
|
249305
249330
|
var fieldTypes = [
|
|
249306
249331
|
"string",
|
|
249307
249332
|
"integer",
|
|
@@ -249337,16 +249362,13 @@ class Validator {
|
|
|
249337
249362
|
if (!partial2) {
|
|
249338
249363
|
const requiredFieldsResponse = this.validateRequiredFields(record2, entitySchema);
|
|
249339
249364
|
if (requiredFieldsResponse.hasError) {
|
|
249340
|
-
|
|
249365
|
+
throw new EntityValidationError(requiredFieldsResponse.error);
|
|
249341
249366
|
}
|
|
249342
249367
|
}
|
|
249343
249368
|
const fieldTypesResponse = this.validateFieldTypes(record2, entitySchema);
|
|
249344
249369
|
if (fieldTypesResponse.hasError) {
|
|
249345
|
-
|
|
249370
|
+
throw new EntityValidationError(fieldTypesResponse.error);
|
|
249346
249371
|
}
|
|
249347
|
-
return {
|
|
249348
|
-
hasError: false
|
|
249349
|
-
};
|
|
249350
249372
|
}
|
|
249351
249373
|
createValidationError(message) {
|
|
249352
249374
|
return {
|
|
@@ -249447,18 +249469,67 @@ class Validator {
|
|
|
249447
249469
|
}
|
|
249448
249470
|
|
|
249449
249471
|
// src/cli/dev/dev-server/db/database.ts
|
|
249472
|
+
var USER_COLLECTION = "user";
|
|
249473
|
+
|
|
249450
249474
|
class Database {
|
|
249451
249475
|
collections = new Map;
|
|
249452
249476
|
schemas = new Map;
|
|
249453
249477
|
validator = new Validator;
|
|
249454
|
-
load(entities) {
|
|
249478
|
+
async load(entities) {
|
|
249479
|
+
await this.loadUserCollection(entities);
|
|
249455
249480
|
for (const entity2 of entities) {
|
|
249456
|
-
this.
|
|
249457
|
-
|
|
249481
|
+
const entityName = this.normalizeName(entity2.name);
|
|
249482
|
+
if (entityName === USER_COLLECTION) {
|
|
249483
|
+
continue;
|
|
249484
|
+
}
|
|
249485
|
+
this.collections.set(entityName, new import_nedb.default);
|
|
249486
|
+
this.schemas.set(entityName, entity2);
|
|
249458
249487
|
}
|
|
249459
249488
|
}
|
|
249489
|
+
async loadUserCollection(entities) {
|
|
249490
|
+
const userEntity = entities.find((e8) => this.normalizeName(e8.name) === USER_COLLECTION);
|
|
249491
|
+
this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
|
|
249492
|
+
const collection = new import_nedb.default;
|
|
249493
|
+
this.collections.set(USER_COLLECTION, collection);
|
|
249494
|
+
const userInfo = await readAuth();
|
|
249495
|
+
const now = getNowISOTimestamp();
|
|
249496
|
+
await collection.insertAsync({
|
|
249497
|
+
id: nanoid3(),
|
|
249498
|
+
email: userInfo.email,
|
|
249499
|
+
full_name: userInfo.name,
|
|
249500
|
+
is_service: false,
|
|
249501
|
+
is_verified: true,
|
|
249502
|
+
disabled: null,
|
|
249503
|
+
role: "admin",
|
|
249504
|
+
collaborator_role: "editor",
|
|
249505
|
+
created_date: now,
|
|
249506
|
+
updated_date: now
|
|
249507
|
+
});
|
|
249508
|
+
}
|
|
249509
|
+
buildUserSchema(customUserEntity) {
|
|
249510
|
+
const builtInFields = {
|
|
249511
|
+
full_name: { type: "string" },
|
|
249512
|
+
email: { type: "string" }
|
|
249513
|
+
};
|
|
249514
|
+
if (!customUserEntity) {
|
|
249515
|
+
return {
|
|
249516
|
+
name: "User",
|
|
249517
|
+
type: "object",
|
|
249518
|
+
properties: { ...builtInFields, role: { type: "string" } }
|
|
249519
|
+
};
|
|
249520
|
+
}
|
|
249521
|
+
for (const field of Object.keys(builtInFields)) {
|
|
249522
|
+
if (field in customUserEntity.properties) {
|
|
249523
|
+
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.`);
|
|
249524
|
+
}
|
|
249525
|
+
}
|
|
249526
|
+
return {
|
|
249527
|
+
...customUserEntity,
|
|
249528
|
+
properties: { ...customUserEntity.properties, ...builtInFields }
|
|
249529
|
+
};
|
|
249530
|
+
}
|
|
249460
249531
|
getCollection(name2) {
|
|
249461
|
-
return this.collections.get(name2);
|
|
249532
|
+
return this.collections.get(this.normalizeName(name2));
|
|
249462
249533
|
}
|
|
249463
249534
|
getCollectionNames() {
|
|
249464
249535
|
return Array.from(this.collections.keys());
|
|
@@ -249471,14 +249542,14 @@ class Database {
|
|
|
249471
249542
|
this.schemas.clear();
|
|
249472
249543
|
}
|
|
249473
249544
|
validate(entityName, record2, partial2 = false) {
|
|
249474
|
-
const schema9 = this.schemas.get(entityName);
|
|
249545
|
+
const schema9 = this.schemas.get(this.normalizeName(entityName));
|
|
249475
249546
|
if (!schema9) {
|
|
249476
249547
|
throw new Error(`Entity "${entityName}" not found`);
|
|
249477
249548
|
}
|
|
249478
249549
|
return this.validator.validate(record2, schema9, partial2);
|
|
249479
249550
|
}
|
|
249480
249551
|
prepareRecord(entityName, record2, partial2 = false) {
|
|
249481
|
-
const schema9 = this.schemas.get(entityName);
|
|
249552
|
+
const schema9 = this.schemas.get(this.normalizeName(entityName));
|
|
249482
249553
|
if (!schema9) {
|
|
249483
249554
|
throw new Error(`Entity "${entityName}" not found`);
|
|
249484
249555
|
}
|
|
@@ -249488,6 +249559,9 @@ class Database {
|
|
|
249488
249559
|
}
|
|
249489
249560
|
return this.validator.applyDefaults(filteredRecord, schema9);
|
|
249490
249561
|
}
|
|
249562
|
+
normalizeName(entityName) {
|
|
249563
|
+
return entityName.toLowerCase();
|
|
249564
|
+
}
|
|
249491
249565
|
}
|
|
249492
249566
|
|
|
249493
249567
|
// ../../node_modules/socket.io/wrapper.mjs
|
|
@@ -249522,40 +249596,105 @@ function broadcastEntityEvent(io6, appId, entityName, event) {
|
|
|
249522
249596
|
});
|
|
249523
249597
|
}
|
|
249524
249598
|
|
|
249525
|
-
// src/cli/dev/dev-server/routes/entities.ts
|
|
249526
|
-
var
|
|
249527
|
-
|
|
249528
|
-
// ../../node_modules/nanoid/index.js
|
|
249529
|
-
import { webcrypto as crypto } from "node:crypto";
|
|
249530
|
-
|
|
249531
|
-
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
249532
|
-
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
249599
|
+
// src/cli/dev/dev-server/routes/entities/entities-router.ts
|
|
249600
|
+
var import_express3 = __toESM(require_express(), 1);
|
|
249533
249601
|
|
|
249534
|
-
//
|
|
249535
|
-
var
|
|
249536
|
-
|
|
249537
|
-
|
|
249538
|
-
|
|
249539
|
-
|
|
249540
|
-
|
|
249541
|
-
|
|
249542
|
-
|
|
249543
|
-
|
|
249544
|
-
|
|
249545
|
-
|
|
249546
|
-
}
|
|
249547
|
-
|
|
249548
|
-
|
|
249549
|
-
|
|
249550
|
-
|
|
249551
|
-
|
|
249552
|
-
|
|
249553
|
-
|
|
249554
|
-
|
|
249555
|
-
|
|
249602
|
+
// src/cli/dev/dev-server/routes/entities/entities-user-router.ts
|
|
249603
|
+
var import_express2 = __toESM(require_express(), 1);
|
|
249604
|
+
function createUserRouter(db2, logger) {
|
|
249605
|
+
const router = import_express2.Router({ mergeParams: true });
|
|
249606
|
+
const parseBody = import_express2.json();
|
|
249607
|
+
router.use((req, res, next) => {
|
|
249608
|
+
const auth2 = req.headers.authorization;
|
|
249609
|
+
if (!auth2 || !auth2.startsWith("Bearer ")) {
|
|
249610
|
+
res.status(401).json({ error: "Unauthorized" });
|
|
249611
|
+
return;
|
|
249612
|
+
}
|
|
249613
|
+
next();
|
|
249614
|
+
});
|
|
249615
|
+
router.get("/:id", async (req, res) => {
|
|
249616
|
+
let result;
|
|
249617
|
+
if (req.params.id === "me") {
|
|
249618
|
+
const userInfo = await readAuth();
|
|
249619
|
+
result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: userInfo.email });
|
|
249620
|
+
} else {
|
|
249621
|
+
result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ id: req.params.id });
|
|
249622
|
+
}
|
|
249623
|
+
if (!result) {
|
|
249624
|
+
res.status(404).json({ error: `User with id "${req.params.id}" not found` });
|
|
249625
|
+
return;
|
|
249626
|
+
}
|
|
249627
|
+
res.json(stripInternalFields(result));
|
|
249628
|
+
});
|
|
249629
|
+
router.post("/", parseBody, async (req, res) => {
|
|
249630
|
+
const userInfo = await readAuth();
|
|
249631
|
+
const currentUser = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: userInfo.email });
|
|
249632
|
+
if (currentUser) {
|
|
249633
|
+
const now = getNowISOTimestamp();
|
|
249634
|
+
res.json({
|
|
249635
|
+
created_by: userInfo.email,
|
|
249636
|
+
created_by_id: currentUser.id,
|
|
249637
|
+
id: nanoid3(),
|
|
249638
|
+
created_date: now,
|
|
249639
|
+
updated_date: now,
|
|
249640
|
+
is_sample: false,
|
|
249641
|
+
...req.body
|
|
249642
|
+
});
|
|
249643
|
+
} else {
|
|
249644
|
+
res.status(404).json({ error: "Unable to read data for the current user" });
|
|
249645
|
+
}
|
|
249646
|
+
});
|
|
249647
|
+
router.post("/bulk", async (_req, res) => {
|
|
249648
|
+
res.json({});
|
|
249649
|
+
});
|
|
249650
|
+
router.put("/:id", parseBody, async (req, res) => {
|
|
249651
|
+
const restrictedFields = ["full_name", "email", "role"];
|
|
249652
|
+
const collection = db2.getCollection(USER_COLLECTION);
|
|
249653
|
+
const userInfo = await readAuth();
|
|
249654
|
+
const userRecord = req.params.id === "me" ? await collection?.findOneAsync({
|
|
249655
|
+
email: userInfo.email
|
|
249656
|
+
}) : await collection?.findOneAsync({
|
|
249657
|
+
id: req.params.id
|
|
249658
|
+
});
|
|
249659
|
+
if (userRecord) {
|
|
249660
|
+
try {
|
|
249661
|
+
const { id: _id, created_date: _created_date, ...body } = req.body;
|
|
249662
|
+
const filteredBody = db2.prepareRecord(USER_COLLECTION, body, true);
|
|
249663
|
+
const allowedFields = {};
|
|
249664
|
+
for (const [key2, property] of Object.entries(filteredBody)) {
|
|
249665
|
+
if (!restrictedFields.includes(key2)) {
|
|
249666
|
+
allowedFields[key2] = property;
|
|
249667
|
+
}
|
|
249668
|
+
}
|
|
249669
|
+
db2.validate(USER_COLLECTION, allowedFields, true);
|
|
249670
|
+
const updateData = {
|
|
249671
|
+
...allowedFields,
|
|
249672
|
+
updated_date: new Date().toISOString()
|
|
249673
|
+
};
|
|
249674
|
+
const updResult = await collection?.updateAsync({ id: userRecord.id }, { $set: updateData }, { returnUpdatedDocs: true });
|
|
249675
|
+
if (!updResult?.affectedDocuments) {
|
|
249676
|
+
throw new Error(`Failed to update user`);
|
|
249677
|
+
}
|
|
249678
|
+
res.json(stripInternalFields(updResult.affectedDocuments));
|
|
249679
|
+
} catch (error48) {
|
|
249680
|
+
if (error48 instanceof EntityValidationError) {
|
|
249681
|
+
res.status(422).json(error48.context);
|
|
249682
|
+
return;
|
|
249683
|
+
}
|
|
249684
|
+
logger.error(`Error in PUT /${USER_COLLECTION}/${req.params.id}:`, error48);
|
|
249685
|
+
res.status(500).json({ error: "Internal server error" });
|
|
249686
|
+
}
|
|
249687
|
+
} else {
|
|
249688
|
+
res.status(404).json({ error: `User record not found` });
|
|
249689
|
+
}
|
|
249690
|
+
});
|
|
249691
|
+
router.delete("/:id", async (_req, res) => {
|
|
249692
|
+
res.json({});
|
|
249693
|
+
});
|
|
249694
|
+
return router;
|
|
249556
249695
|
}
|
|
249557
249696
|
|
|
249558
|
-
// src/cli/dev/dev-server/routes/entities.ts
|
|
249697
|
+
// src/cli/dev/dev-server/routes/entities/entities-router.ts
|
|
249559
249698
|
function parseSort(sort) {
|
|
249560
249699
|
if (!sort) {
|
|
249561
249700
|
return;
|
|
@@ -249578,16 +249717,9 @@ function parseFields(fields) {
|
|
|
249578
249717
|
}
|
|
249579
249718
|
return Object.keys(projection).length > 0 ? projection : undefined;
|
|
249580
249719
|
}
|
|
249581
|
-
function
|
|
249582
|
-
|
|
249583
|
-
|
|
249584
|
-
}
|
|
249585
|
-
const { _id, ...rest } = doc2;
|
|
249586
|
-
return rest;
|
|
249587
|
-
}
|
|
249588
|
-
function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
249589
|
-
const router = import_express2.Router({ mergeParams: true });
|
|
249590
|
-
const parseBody = import_express2.json();
|
|
249720
|
+
async function createEntityRoutes(db2, logger, broadcast) {
|
|
249721
|
+
const router = import_express3.Router({ mergeParams: true });
|
|
249722
|
+
const parseBody = import_express3.json();
|
|
249591
249723
|
function withCollection(handler) {
|
|
249592
249724
|
return async (req, res) => {
|
|
249593
249725
|
const collection = db2.getCollection(req.params.entityName);
|
|
@@ -249613,11 +249745,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249613
249745
|
}
|
|
249614
249746
|
broadcast(appId, entityName, createData(data));
|
|
249615
249747
|
}
|
|
249616
|
-
|
|
249617
|
-
|
|
249618
|
-
req.url = req.originalUrl;
|
|
249619
|
-
remoteProxy(req, res, next);
|
|
249620
|
-
});
|
|
249748
|
+
const userRouter = createUserRouter(db2, logger);
|
|
249749
|
+
router.use("/User", userRouter);
|
|
249621
249750
|
router.get("/:entityName/:id", withCollection(async (req, res, collection) => {
|
|
249622
249751
|
const { entityName, id: id2 } = req.params;
|
|
249623
249752
|
try {
|
|
@@ -249679,11 +249808,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249679
249808
|
const now = new Date().toISOString();
|
|
249680
249809
|
const { _id, ...body } = req.body;
|
|
249681
249810
|
const filteredBody = db2.prepareRecord(entityName, body);
|
|
249682
|
-
|
|
249683
|
-
if (validation.hasError) {
|
|
249684
|
-
res.status(422).json(validation.error);
|
|
249685
|
-
return;
|
|
249686
|
-
}
|
|
249811
|
+
db2.validate(entityName, filteredBody);
|
|
249687
249812
|
const record2 = {
|
|
249688
249813
|
...filteredBody,
|
|
249689
249814
|
id: nanoid3(),
|
|
@@ -249694,6 +249819,10 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249694
249819
|
emit(appId, entityName, "create", inserted);
|
|
249695
249820
|
res.status(201).json(inserted);
|
|
249696
249821
|
} catch (error48) {
|
|
249822
|
+
if (error48 instanceof EntityValidationError) {
|
|
249823
|
+
res.status(422).json(error48.context);
|
|
249824
|
+
return;
|
|
249825
|
+
}
|
|
249697
249826
|
logger.error(`Error in POST /${entityName}:`, error48);
|
|
249698
249827
|
res.status(500).json({ error: "Internal server error" });
|
|
249699
249828
|
}
|
|
@@ -249709,11 +249838,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249709
249838
|
const records = [];
|
|
249710
249839
|
for (const record2 of req.body) {
|
|
249711
249840
|
const filteredRecord = db2.prepareRecord(entityName, record2);
|
|
249712
|
-
|
|
249713
|
-
if (validation.hasError) {
|
|
249714
|
-
res.status(422).json(validation.error);
|
|
249715
|
-
return;
|
|
249716
|
-
}
|
|
249841
|
+
db2.validate(entityName, filteredRecord);
|
|
249717
249842
|
records.push({
|
|
249718
249843
|
...filteredRecord,
|
|
249719
249844
|
id: nanoid3(),
|
|
@@ -249725,6 +249850,10 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249725
249850
|
emit(appId, entityName, "create", inserted);
|
|
249726
249851
|
res.status(201).json(inserted);
|
|
249727
249852
|
} catch (error48) {
|
|
249853
|
+
if (error48 instanceof EntityValidationError) {
|
|
249854
|
+
res.status(422).json(error48.context);
|
|
249855
|
+
return;
|
|
249856
|
+
}
|
|
249728
249857
|
logger.error(`Error in POST /${entityName}/bulk:`, error48);
|
|
249729
249858
|
res.status(500).json({ error: "Internal server error" });
|
|
249730
249859
|
}
|
|
@@ -249734,11 +249863,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249734
249863
|
const { id: _id, created_date: _created_date, ...body } = req.body;
|
|
249735
249864
|
try {
|
|
249736
249865
|
const filteredBody = db2.prepareRecord(entityName, body, true);
|
|
249737
|
-
|
|
249738
|
-
if (validation.hasError) {
|
|
249739
|
-
res.status(422).json(validation.error);
|
|
249740
|
-
return;
|
|
249741
|
-
}
|
|
249866
|
+
db2.validate(entityName, filteredBody, true);
|
|
249742
249867
|
const updateData = {
|
|
249743
249868
|
...filteredBody,
|
|
249744
249869
|
updated_date: new Date().toISOString()
|
|
@@ -249752,6 +249877,10 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249752
249877
|
emit(appId, entityName, "update", updated);
|
|
249753
249878
|
res.json(updated);
|
|
249754
249879
|
} catch (error48) {
|
|
249880
|
+
if (error48 instanceof EntityValidationError) {
|
|
249881
|
+
res.status(422).json(error48.context);
|
|
249882
|
+
return;
|
|
249883
|
+
}
|
|
249755
249884
|
logger.error(`Error in PUT /${entityName}/${id2}:`, error48);
|
|
249756
249885
|
res.status(500).json({ error: "Internal server error" });
|
|
249757
249886
|
}
|
|
@@ -249789,7 +249918,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249789
249918
|
}
|
|
249790
249919
|
|
|
249791
249920
|
// src/cli/dev/dev-server/routes/integrations.ts
|
|
249792
|
-
var
|
|
249921
|
+
var import_express4 = __toESM(require_express(), 1);
|
|
249793
249922
|
var import_multer = __toESM(require_multer(), 1);
|
|
249794
249923
|
import { createHash, randomUUID as randomUUID4 } from "node:crypto";
|
|
249795
249924
|
import fs28 from "node:fs";
|
|
@@ -249798,8 +249927,8 @@ function createFileToken(fileUri) {
|
|
|
249798
249927
|
return createHash("sha256").update(fileUri).digest("hex");
|
|
249799
249928
|
}
|
|
249800
249929
|
function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger) {
|
|
249801
|
-
const router =
|
|
249802
|
-
const parseBody =
|
|
249930
|
+
const router = import_express4.Router({ mergeParams: true });
|
|
249931
|
+
const parseBody = import_express4.json();
|
|
249803
249932
|
const privateFilesDir = path18.join(mediaFilesDir, "private");
|
|
249804
249933
|
fs28.mkdirSync(mediaFilesDir, { recursive: true });
|
|
249805
249934
|
fs28.mkdirSync(privateFilesDir, { recursive: true });
|
|
@@ -249869,7 +249998,7 @@ function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger) {
|
|
|
249869
249998
|
return router;
|
|
249870
249999
|
}
|
|
249871
250000
|
function createCustomIntegrationRoutes(remoteProxy, logger) {
|
|
249872
|
-
const router =
|
|
250001
|
+
const router = import_express4.Router({ mergeParams: true });
|
|
249873
250002
|
router.post("/:slug/:operationId", (req, res, next) => {
|
|
249874
250003
|
logger.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
|
|
249875
250004
|
req.url = req.originalUrl;
|
|
@@ -251582,7 +251711,7 @@ async function createDevServer(options8) {
|
|
|
251582
251711
|
const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
|
|
251583
251712
|
const baseUrl = `http://localhost:${port}`;
|
|
251584
251713
|
const { functions, entities, project: project2 } = await options8.loadResources();
|
|
251585
|
-
const app =
|
|
251714
|
+
const app = import_express5.default();
|
|
251586
251715
|
const remoteProxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
251587
251716
|
target: BASE44_APP_URL,
|
|
251588
251717
|
changeOrigin: true
|
|
@@ -251607,12 +251736,12 @@ async function createDevServer(options8) {
|
|
|
251607
251736
|
R2.info(`Loaded functions: ${functionManager.getFunctionNames().join(", ")}`);
|
|
251608
251737
|
}
|
|
251609
251738
|
const db2 = new Database;
|
|
251610
|
-
db2.load(entities);
|
|
251739
|
+
await db2.load(entities);
|
|
251611
251740
|
if (db2.getCollectionNames().length > 0) {
|
|
251612
251741
|
R2.info(`Loaded entities: ${db2.getCollectionNames().join(", ")}`);
|
|
251613
251742
|
}
|
|
251614
251743
|
let emitEntityEvent = () => {};
|
|
251615
|
-
const entityRoutes = createEntityRoutes(db2, devLogger,
|
|
251744
|
+
const entityRoutes = await createEntityRoutes(db2, devLogger, (...args) => emitEntityEvent(...args));
|
|
251616
251745
|
app.use("/api/apps/:appId/entities", entityRoutes);
|
|
251617
251746
|
const { path: mediaFilesDir } = await $dir();
|
|
251618
251747
|
app.use("/media/private/:fileUri", (req, res, next) => {
|
|
@@ -251633,7 +251762,7 @@ async function createDevServer(options8) {
|
|
|
251633
251762
|
}
|
|
251634
251763
|
next();
|
|
251635
251764
|
});
|
|
251636
|
-
app.use("/media",
|
|
251765
|
+
app.use("/media", import_express5.default.static(mediaFilesDir));
|
|
251637
251766
|
const integrationRoutes = createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, devLogger);
|
|
251638
251767
|
app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
|
|
251639
251768
|
const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
|
|
@@ -251682,7 +251811,7 @@ async function createDevServer(options8) {
|
|
|
251682
251811
|
if (previousEntityCount > 0) {
|
|
251683
251812
|
devLogger.log("Entities directory changed, clearing data...");
|
|
251684
251813
|
}
|
|
251685
|
-
db2.load(entities2);
|
|
251814
|
+
await db2.load(entities2);
|
|
251686
251815
|
if (db2.getCollectionNames().length > 0) {
|
|
251687
251816
|
devLogger.log(`Loaded entities: ${db2.getCollectionNames().join(", ")}`);
|
|
251688
251817
|
}
|
|
@@ -256184,4 +256313,4 @@ export {
|
|
|
256184
256313
|
CLIExitError
|
|
256185
256314
|
};
|
|
256186
256315
|
|
|
256187
|
-
//# debugId=
|
|
256316
|
+
//# debugId=57B9E512088F387964756E2164756E21
|