@base44-preview/cli 0.0.47-pr.370.b77da88 → 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 -113
- 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"], {
|
|
231034
|
-
error: 'Invalid visibility value. Allowed values: "public", "private"'
|
|
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,22 +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
|
-
};
|
|
239397
|
-
async function updateProjectVisibility(visibility) {
|
|
239398
|
-
const { id } = getAppConfig();
|
|
239399
|
-
try {
|
|
239400
|
-
await base44Client.put(`api/apps/${id}`, {
|
|
239401
|
-
json: {
|
|
239402
|
-
public_settings: VISIBILITY_TO_PUBLIC_SETTINGS[visibility]
|
|
239403
|
-
}
|
|
239404
|
-
});
|
|
239405
|
-
} catch (error48) {
|
|
239406
|
-
throw await ApiError.fromHttpError(error48, "updating project visibility");
|
|
239407
|
-
}
|
|
239408
|
-
}
|
|
239409
239389
|
async function listProjects() {
|
|
239410
239390
|
let response;
|
|
239411
239391
|
try {
|
|
@@ -239735,9 +239715,6 @@ async function deployAll(projectData, options) {
|
|
|
239735
239715
|
});
|
|
239736
239716
|
await agentResource.push(agents);
|
|
239737
239717
|
const { results: connectorResults } = await pushConnectors(connectors);
|
|
239738
|
-
if (project.visibility) {
|
|
239739
|
-
await updateProjectVisibility(project.visibility);
|
|
239740
|
-
}
|
|
239741
239718
|
if (project.site?.outputDirectory) {
|
|
239742
239719
|
const outputDir = resolve(project.root, project.site.outputDirectory);
|
|
239743
239720
|
const { appUrl } = await deploySite(outputDir);
|
|
@@ -248949,7 +248926,7 @@ function getTypesCommand() {
|
|
|
248949
248926
|
// src/cli/dev/dev-server/main.ts
|
|
248950
248927
|
import { dirname as dirname14, join as join20 } from "node:path";
|
|
248951
248928
|
var import_cors = __toESM(require_lib4(), 1);
|
|
248952
|
-
var
|
|
248929
|
+
var import_express5 = __toESM(require_express(), 1);
|
|
248953
248930
|
|
|
248954
248931
|
// ../../node_modules/get-port/index.js
|
|
248955
248932
|
import net from "node:net";
|
|
@@ -249300,7 +249277,56 @@ function createFunctionRouter(manager, logger) {
|
|
|
249300
249277
|
// src/cli/dev/dev-server/db/database.ts
|
|
249301
249278
|
var import_nedb = __toESM(require_nedb(), 1);
|
|
249302
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
|
+
|
|
249303
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
|
+
}
|
|
249304
249330
|
var fieldTypes = [
|
|
249305
249331
|
"string",
|
|
249306
249332
|
"integer",
|
|
@@ -249336,16 +249362,13 @@ class Validator {
|
|
|
249336
249362
|
if (!partial2) {
|
|
249337
249363
|
const requiredFieldsResponse = this.validateRequiredFields(record2, entitySchema);
|
|
249338
249364
|
if (requiredFieldsResponse.hasError) {
|
|
249339
|
-
|
|
249365
|
+
throw new EntityValidationError(requiredFieldsResponse.error);
|
|
249340
249366
|
}
|
|
249341
249367
|
}
|
|
249342
249368
|
const fieldTypesResponse = this.validateFieldTypes(record2, entitySchema);
|
|
249343
249369
|
if (fieldTypesResponse.hasError) {
|
|
249344
|
-
|
|
249370
|
+
throw new EntityValidationError(fieldTypesResponse.error);
|
|
249345
249371
|
}
|
|
249346
|
-
return {
|
|
249347
|
-
hasError: false
|
|
249348
|
-
};
|
|
249349
249372
|
}
|
|
249350
249373
|
createValidationError(message) {
|
|
249351
249374
|
return {
|
|
@@ -249446,18 +249469,67 @@ class Validator {
|
|
|
249446
249469
|
}
|
|
249447
249470
|
|
|
249448
249471
|
// src/cli/dev/dev-server/db/database.ts
|
|
249472
|
+
var USER_COLLECTION = "user";
|
|
249473
|
+
|
|
249449
249474
|
class Database {
|
|
249450
249475
|
collections = new Map;
|
|
249451
249476
|
schemas = new Map;
|
|
249452
249477
|
validator = new Validator;
|
|
249453
|
-
load(entities) {
|
|
249478
|
+
async load(entities) {
|
|
249479
|
+
await this.loadUserCollection(entities);
|
|
249454
249480
|
for (const entity2 of entities) {
|
|
249455
|
-
this.
|
|
249456
|
-
|
|
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);
|
|
249457
249487
|
}
|
|
249458
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
|
+
}
|
|
249459
249531
|
getCollection(name2) {
|
|
249460
|
-
return this.collections.get(name2);
|
|
249532
|
+
return this.collections.get(this.normalizeName(name2));
|
|
249461
249533
|
}
|
|
249462
249534
|
getCollectionNames() {
|
|
249463
249535
|
return Array.from(this.collections.keys());
|
|
@@ -249470,14 +249542,14 @@ class Database {
|
|
|
249470
249542
|
this.schemas.clear();
|
|
249471
249543
|
}
|
|
249472
249544
|
validate(entityName, record2, partial2 = false) {
|
|
249473
|
-
const schema9 = this.schemas.get(entityName);
|
|
249545
|
+
const schema9 = this.schemas.get(this.normalizeName(entityName));
|
|
249474
249546
|
if (!schema9) {
|
|
249475
249547
|
throw new Error(`Entity "${entityName}" not found`);
|
|
249476
249548
|
}
|
|
249477
249549
|
return this.validator.validate(record2, schema9, partial2);
|
|
249478
249550
|
}
|
|
249479
249551
|
prepareRecord(entityName, record2, partial2 = false) {
|
|
249480
|
-
const schema9 = this.schemas.get(entityName);
|
|
249552
|
+
const schema9 = this.schemas.get(this.normalizeName(entityName));
|
|
249481
249553
|
if (!schema9) {
|
|
249482
249554
|
throw new Error(`Entity "${entityName}" not found`);
|
|
249483
249555
|
}
|
|
@@ -249487,6 +249559,9 @@ class Database {
|
|
|
249487
249559
|
}
|
|
249488
249560
|
return this.validator.applyDefaults(filteredRecord, schema9);
|
|
249489
249561
|
}
|
|
249562
|
+
normalizeName(entityName) {
|
|
249563
|
+
return entityName.toLowerCase();
|
|
249564
|
+
}
|
|
249490
249565
|
}
|
|
249491
249566
|
|
|
249492
249567
|
// ../../node_modules/socket.io/wrapper.mjs
|
|
@@ -249521,40 +249596,105 @@ function broadcastEntityEvent(io6, appId, entityName, event) {
|
|
|
249521
249596
|
});
|
|
249522
249597
|
}
|
|
249523
249598
|
|
|
249524
|
-
// src/cli/dev/dev-server/routes/entities.ts
|
|
249525
|
-
var
|
|
249526
|
-
|
|
249527
|
-
// ../../node_modules/nanoid/index.js
|
|
249528
|
-
import { webcrypto as crypto } from "node:crypto";
|
|
249529
|
-
|
|
249530
|
-
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
249531
|
-
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
249599
|
+
// src/cli/dev/dev-server/routes/entities/entities-router.ts
|
|
249600
|
+
var import_express3 = __toESM(require_express(), 1);
|
|
249532
249601
|
|
|
249533
|
-
//
|
|
249534
|
-
var
|
|
249535
|
-
|
|
249536
|
-
|
|
249537
|
-
|
|
249538
|
-
|
|
249539
|
-
|
|
249540
|
-
|
|
249541
|
-
|
|
249542
|
-
|
|
249543
|
-
|
|
249544
|
-
|
|
249545
|
-
}
|
|
249546
|
-
|
|
249547
|
-
|
|
249548
|
-
|
|
249549
|
-
|
|
249550
|
-
|
|
249551
|
-
|
|
249552
|
-
|
|
249553
|
-
|
|
249554
|
-
|
|
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;
|
|
249555
249695
|
}
|
|
249556
249696
|
|
|
249557
|
-
// src/cli/dev/dev-server/routes/entities.ts
|
|
249697
|
+
// src/cli/dev/dev-server/routes/entities/entities-router.ts
|
|
249558
249698
|
function parseSort(sort) {
|
|
249559
249699
|
if (!sort) {
|
|
249560
249700
|
return;
|
|
@@ -249577,16 +249717,9 @@ function parseFields(fields) {
|
|
|
249577
249717
|
}
|
|
249578
249718
|
return Object.keys(projection).length > 0 ? projection : undefined;
|
|
249579
249719
|
}
|
|
249580
|
-
function
|
|
249581
|
-
|
|
249582
|
-
|
|
249583
|
-
}
|
|
249584
|
-
const { _id, ...rest } = doc2;
|
|
249585
|
-
return rest;
|
|
249586
|
-
}
|
|
249587
|
-
function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
249588
|
-
const router = import_express2.Router({ mergeParams: true });
|
|
249589
|
-
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();
|
|
249590
249723
|
function withCollection(handler) {
|
|
249591
249724
|
return async (req, res) => {
|
|
249592
249725
|
const collection = db2.getCollection(req.params.entityName);
|
|
@@ -249612,11 +249745,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249612
249745
|
}
|
|
249613
249746
|
broadcast(appId, entityName, createData(data));
|
|
249614
249747
|
}
|
|
249615
|
-
|
|
249616
|
-
|
|
249617
|
-
req.url = req.originalUrl;
|
|
249618
|
-
remoteProxy(req, res, next);
|
|
249619
|
-
});
|
|
249748
|
+
const userRouter = createUserRouter(db2, logger);
|
|
249749
|
+
router.use("/User", userRouter);
|
|
249620
249750
|
router.get("/:entityName/:id", withCollection(async (req, res, collection) => {
|
|
249621
249751
|
const { entityName, id: id2 } = req.params;
|
|
249622
249752
|
try {
|
|
@@ -249678,11 +249808,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249678
249808
|
const now = new Date().toISOString();
|
|
249679
249809
|
const { _id, ...body } = req.body;
|
|
249680
249810
|
const filteredBody = db2.prepareRecord(entityName, body);
|
|
249681
|
-
|
|
249682
|
-
if (validation.hasError) {
|
|
249683
|
-
res.status(422).json(validation.error);
|
|
249684
|
-
return;
|
|
249685
|
-
}
|
|
249811
|
+
db2.validate(entityName, filteredBody);
|
|
249686
249812
|
const record2 = {
|
|
249687
249813
|
...filteredBody,
|
|
249688
249814
|
id: nanoid3(),
|
|
@@ -249693,6 +249819,10 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249693
249819
|
emit(appId, entityName, "create", inserted);
|
|
249694
249820
|
res.status(201).json(inserted);
|
|
249695
249821
|
} catch (error48) {
|
|
249822
|
+
if (error48 instanceof EntityValidationError) {
|
|
249823
|
+
res.status(422).json(error48.context);
|
|
249824
|
+
return;
|
|
249825
|
+
}
|
|
249696
249826
|
logger.error(`Error in POST /${entityName}:`, error48);
|
|
249697
249827
|
res.status(500).json({ error: "Internal server error" });
|
|
249698
249828
|
}
|
|
@@ -249708,11 +249838,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249708
249838
|
const records = [];
|
|
249709
249839
|
for (const record2 of req.body) {
|
|
249710
249840
|
const filteredRecord = db2.prepareRecord(entityName, record2);
|
|
249711
|
-
|
|
249712
|
-
if (validation.hasError) {
|
|
249713
|
-
res.status(422).json(validation.error);
|
|
249714
|
-
return;
|
|
249715
|
-
}
|
|
249841
|
+
db2.validate(entityName, filteredRecord);
|
|
249716
249842
|
records.push({
|
|
249717
249843
|
...filteredRecord,
|
|
249718
249844
|
id: nanoid3(),
|
|
@@ -249724,6 +249850,10 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249724
249850
|
emit(appId, entityName, "create", inserted);
|
|
249725
249851
|
res.status(201).json(inserted);
|
|
249726
249852
|
} catch (error48) {
|
|
249853
|
+
if (error48 instanceof EntityValidationError) {
|
|
249854
|
+
res.status(422).json(error48.context);
|
|
249855
|
+
return;
|
|
249856
|
+
}
|
|
249727
249857
|
logger.error(`Error in POST /${entityName}/bulk:`, error48);
|
|
249728
249858
|
res.status(500).json({ error: "Internal server error" });
|
|
249729
249859
|
}
|
|
@@ -249733,11 +249863,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249733
249863
|
const { id: _id, created_date: _created_date, ...body } = req.body;
|
|
249734
249864
|
try {
|
|
249735
249865
|
const filteredBody = db2.prepareRecord(entityName, body, true);
|
|
249736
|
-
|
|
249737
|
-
if (validation.hasError) {
|
|
249738
|
-
res.status(422).json(validation.error);
|
|
249739
|
-
return;
|
|
249740
|
-
}
|
|
249866
|
+
db2.validate(entityName, filteredBody, true);
|
|
249741
249867
|
const updateData = {
|
|
249742
249868
|
...filteredBody,
|
|
249743
249869
|
updated_date: new Date().toISOString()
|
|
@@ -249751,6 +249877,10 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249751
249877
|
emit(appId, entityName, "update", updated);
|
|
249752
249878
|
res.json(updated);
|
|
249753
249879
|
} catch (error48) {
|
|
249880
|
+
if (error48 instanceof EntityValidationError) {
|
|
249881
|
+
res.status(422).json(error48.context);
|
|
249882
|
+
return;
|
|
249883
|
+
}
|
|
249754
249884
|
logger.error(`Error in PUT /${entityName}/${id2}:`, error48);
|
|
249755
249885
|
res.status(500).json({ error: "Internal server error" });
|
|
249756
249886
|
}
|
|
@@ -249788,7 +249918,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
|
|
|
249788
249918
|
}
|
|
249789
249919
|
|
|
249790
249920
|
// src/cli/dev/dev-server/routes/integrations.ts
|
|
249791
|
-
var
|
|
249921
|
+
var import_express4 = __toESM(require_express(), 1);
|
|
249792
249922
|
var import_multer = __toESM(require_multer(), 1);
|
|
249793
249923
|
import { createHash, randomUUID as randomUUID4 } from "node:crypto";
|
|
249794
249924
|
import fs28 from "node:fs";
|
|
@@ -249797,8 +249927,8 @@ function createFileToken(fileUri) {
|
|
|
249797
249927
|
return createHash("sha256").update(fileUri).digest("hex");
|
|
249798
249928
|
}
|
|
249799
249929
|
function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger) {
|
|
249800
|
-
const router =
|
|
249801
|
-
const parseBody =
|
|
249930
|
+
const router = import_express4.Router({ mergeParams: true });
|
|
249931
|
+
const parseBody = import_express4.json();
|
|
249802
249932
|
const privateFilesDir = path18.join(mediaFilesDir, "private");
|
|
249803
249933
|
fs28.mkdirSync(mediaFilesDir, { recursive: true });
|
|
249804
249934
|
fs28.mkdirSync(privateFilesDir, { recursive: true });
|
|
@@ -249868,7 +249998,7 @@ function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger) {
|
|
|
249868
249998
|
return router;
|
|
249869
249999
|
}
|
|
249870
250000
|
function createCustomIntegrationRoutes(remoteProxy, logger) {
|
|
249871
|
-
const router =
|
|
250001
|
+
const router = import_express4.Router({ mergeParams: true });
|
|
249872
250002
|
router.post("/:slug/:operationId", (req, res, next) => {
|
|
249873
250003
|
logger.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
|
|
249874
250004
|
req.url = req.originalUrl;
|
|
@@ -251581,7 +251711,7 @@ async function createDevServer(options8) {
|
|
|
251581
251711
|
const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
|
|
251582
251712
|
const baseUrl = `http://localhost:${port}`;
|
|
251583
251713
|
const { functions, entities, project: project2 } = await options8.loadResources();
|
|
251584
|
-
const app =
|
|
251714
|
+
const app = import_express5.default();
|
|
251585
251715
|
const remoteProxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
251586
251716
|
target: BASE44_APP_URL,
|
|
251587
251717
|
changeOrigin: true
|
|
@@ -251606,12 +251736,12 @@ async function createDevServer(options8) {
|
|
|
251606
251736
|
R2.info(`Loaded functions: ${functionManager.getFunctionNames().join(", ")}`);
|
|
251607
251737
|
}
|
|
251608
251738
|
const db2 = new Database;
|
|
251609
|
-
db2.load(entities);
|
|
251739
|
+
await db2.load(entities);
|
|
251610
251740
|
if (db2.getCollectionNames().length > 0) {
|
|
251611
251741
|
R2.info(`Loaded entities: ${db2.getCollectionNames().join(", ")}`);
|
|
251612
251742
|
}
|
|
251613
251743
|
let emitEntityEvent = () => {};
|
|
251614
|
-
const entityRoutes = createEntityRoutes(db2, devLogger,
|
|
251744
|
+
const entityRoutes = await createEntityRoutes(db2, devLogger, (...args) => emitEntityEvent(...args));
|
|
251615
251745
|
app.use("/api/apps/:appId/entities", entityRoutes);
|
|
251616
251746
|
const { path: mediaFilesDir } = await $dir();
|
|
251617
251747
|
app.use("/media/private/:fileUri", (req, res, next) => {
|
|
@@ -251632,7 +251762,7 @@ async function createDevServer(options8) {
|
|
|
251632
251762
|
}
|
|
251633
251763
|
next();
|
|
251634
251764
|
});
|
|
251635
|
-
app.use("/media",
|
|
251765
|
+
app.use("/media", import_express5.default.static(mediaFilesDir));
|
|
251636
251766
|
const integrationRoutes = createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, devLogger);
|
|
251637
251767
|
app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
|
|
251638
251768
|
const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
|
|
@@ -251681,7 +251811,7 @@ async function createDevServer(options8) {
|
|
|
251681
251811
|
if (previousEntityCount > 0) {
|
|
251682
251812
|
devLogger.log("Entities directory changed, clearing data...");
|
|
251683
251813
|
}
|
|
251684
|
-
db2.load(entities2);
|
|
251814
|
+
await db2.load(entities2);
|
|
251685
251815
|
if (db2.getCollectionNames().length > 0) {
|
|
251686
251816
|
devLogger.log(`Loaded entities: ${db2.getCollectionNames().join(", ")}`);
|
|
251687
251817
|
}
|
|
@@ -256183,4 +256313,4 @@ export {
|
|
|
256183
256313
|
CLIExitError
|
|
256184
256314
|
};
|
|
256185
256315
|
|
|
256186
|
-
//# debugId=
|
|
256316
|
+
//# debugId=57B9E512088F387964756E2164756E21
|