@base44-preview/cli 0.0.50-pr.475.feeb89c → 0.0.50-pr.480.b87871d
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 +137 -254
- package/dist/cli/index.js.map +12 -14
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -219926,8 +219926,7 @@ var theme = {
|
|
|
219926
219926
|
bold: source_default.bold,
|
|
219927
219927
|
dim: source_default.dim,
|
|
219928
219928
|
error: source_default.red,
|
|
219929
|
-
warn: source_default.yellow
|
|
219930
|
-
info: source_default.cyan
|
|
219929
|
+
warn: source_default.yellow
|
|
219931
219930
|
},
|
|
219932
219931
|
format: {
|
|
219933
219932
|
errorContext(ctx) {
|
|
@@ -241539,12 +241538,27 @@ var ToolConfigSchema = exports_external.union([
|
|
|
241539
241538
|
EntityToolConfigSchema,
|
|
241540
241539
|
BackendFunctionToolConfigSchema
|
|
241541
241540
|
]);
|
|
241541
|
+
var EntityAccessRuleSchema = exports_external.union([
|
|
241542
|
+
exports_external.boolean(),
|
|
241543
|
+
exports_external.record(exports_external.string(), exports_external.unknown())
|
|
241544
|
+
]);
|
|
241545
|
+
var AgentAccessConfigSchema = exports_external.object({
|
|
241546
|
+
entities: exports_external.record(exports_external.string(), exports_external.record(exports_external.string(), EntityAccessRuleSchema)).optional().default({}),
|
|
241547
|
+
functions: exports_external.array(exports_external.string()).optional().default([])
|
|
241548
|
+
});
|
|
241549
|
+
var CodeModeConfigSchema = exports_external.object({
|
|
241550
|
+
access: AgentAccessConfigSchema.optional().default({
|
|
241551
|
+
entities: {},
|
|
241552
|
+
functions: []
|
|
241553
|
+
})
|
|
241554
|
+
});
|
|
241542
241555
|
var AgentConfigSchema = exports_external.looseObject({
|
|
241543
241556
|
name: exports_external.string().trim().min(1).max(100),
|
|
241544
241557
|
description: exports_external.string().trim().min(1, "Description is required"),
|
|
241545
241558
|
instructions: exports_external.string().trim().min(1, "Instructions are required"),
|
|
241546
241559
|
tool_configs: exports_external.array(ToolConfigSchema).optional().default([]),
|
|
241547
|
-
whatsapp_greeting: exports_external.string().nullable().optional()
|
|
241560
|
+
whatsapp_greeting: exports_external.string().nullable().optional(),
|
|
241561
|
+
code_mode: CodeModeConfigSchema.optional()
|
|
241548
241562
|
});
|
|
241549
241563
|
var SyncAgentsResponseSchema = exports_external.object({
|
|
241550
241564
|
created: exports_external.array(exports_external.string()),
|
|
@@ -242595,11 +242609,51 @@ var EntityAutomationSchema = AutomationBaseSchema.extend({
|
|
|
242595
242609
|
entity_name: exports_external.string().min(1, "Entity name cannot be empty"),
|
|
242596
242610
|
event_types: exports_external.array(exports_external.enum(["create", "update", "delete"])).min(1, "At least one event type is required")
|
|
242597
242611
|
});
|
|
242612
|
+
var KnownConditionOperators = [
|
|
242613
|
+
"equals",
|
|
242614
|
+
"not_equals",
|
|
242615
|
+
"gt",
|
|
242616
|
+
"gte",
|
|
242617
|
+
"lt",
|
|
242618
|
+
"lte",
|
|
242619
|
+
"contains",
|
|
242620
|
+
"not_contains",
|
|
242621
|
+
"starts_with",
|
|
242622
|
+
"ends_with",
|
|
242623
|
+
"in_list",
|
|
242624
|
+
"not_in_list",
|
|
242625
|
+
"exists",
|
|
242626
|
+
"not_exists",
|
|
242627
|
+
"is_empty",
|
|
242628
|
+
"is_not_empty"
|
|
242629
|
+
];
|
|
242630
|
+
var ConditionOperatorSchema = exports_external.union([
|
|
242631
|
+
exports_external.enum(KnownConditionOperators),
|
|
242632
|
+
exports_external.string().min(1)
|
|
242633
|
+
]);
|
|
242634
|
+
var TriggerConditionSchema = exports_external.object({
|
|
242635
|
+
field: exports_external.string().min(1),
|
|
242636
|
+
operator: ConditionOperatorSchema,
|
|
242637
|
+
value: exports_external.unknown().nullable().optional()
|
|
242638
|
+
});
|
|
242639
|
+
var TriggerLogicSchema = exports_external.enum(["and", "or"]);
|
|
242640
|
+
var TriggerConditionGroupSchema = exports_external.lazy(() => exports_external.object({
|
|
242641
|
+
logic: TriggerLogicSchema.optional(),
|
|
242642
|
+
conditions: exports_external.array(exports_external.union([TriggerConditionSchema, TriggerConditionGroupSchema])).min(1)
|
|
242643
|
+
}));
|
|
242644
|
+
var ConnectorAutomationSchema = AutomationBaseSchema.extend({
|
|
242645
|
+
type: exports_external.literal("connector"),
|
|
242646
|
+
integration_type: IntegrationTypeSchema,
|
|
242647
|
+
events: exports_external.array(exports_external.string()),
|
|
242648
|
+
resource_id: exports_external.string().nullable().optional(),
|
|
242649
|
+
trigger_conditions: TriggerConditionGroupSchema.nullable().optional()
|
|
242650
|
+
});
|
|
242598
242651
|
var AutomationSchema = exports_external.union([
|
|
242599
242652
|
ScheduledOneTimeSchema,
|
|
242600
242653
|
ScheduledCronSchema,
|
|
242601
242654
|
ScheduledSimpleSchema,
|
|
242602
|
-
EntityAutomationSchema
|
|
242655
|
+
EntityAutomationSchema,
|
|
242656
|
+
ConnectorAutomationSchema
|
|
242603
242657
|
]);
|
|
242604
242658
|
var FunctionConfigSchema = exports_external.object({
|
|
242605
242659
|
name: FunctionNameSchema,
|
|
@@ -243244,7 +243298,6 @@ var package_default = {
|
|
|
243244
243298
|
typescript: "^5.7.2",
|
|
243245
243299
|
vitest: "^4.0.16",
|
|
243246
243300
|
yaml: "^2.8.2",
|
|
243247
|
-
qs: "^6.12.3",
|
|
243248
243301
|
zod: "^4.3.5"
|
|
243249
243302
|
},
|
|
243250
243303
|
engines: {
|
|
@@ -252757,12 +252810,9 @@ function getTypesCommand() {
|
|
|
252757
252810
|
return new Command("types").description("Manage TypeScript type generation").addCommand(getTypesGenerateCommand());
|
|
252758
252811
|
}
|
|
252759
252812
|
|
|
252760
|
-
// src/cli/commands/dev.ts
|
|
252761
|
-
import process21 from "node:process";
|
|
252762
|
-
|
|
252763
252813
|
// src/cli/dev/dev-server/main.ts
|
|
252764
252814
|
var import_cors = __toESM(require_lib4(), 1);
|
|
252765
|
-
var
|
|
252815
|
+
var import_express5 = __toESM(require_express(), 1);
|
|
252766
252816
|
import { dirname as dirname16, join as join23 } from "node:path";
|
|
252767
252817
|
|
|
252768
252818
|
// ../../node_modules/get-port/index.js
|
|
@@ -253094,9 +253144,13 @@ function createFunctionRouter(manager, logger2) {
|
|
|
253094
253144
|
on: {
|
|
253095
253145
|
proxyReq: (proxyReq, req) => {
|
|
253096
253146
|
const xAppId = req.headers["x-app-id"];
|
|
253147
|
+
const authorization = req.headers.authorization;
|
|
253097
253148
|
if (xAppId) {
|
|
253098
253149
|
proxyReq.setHeader("Base44-App-Id", xAppId);
|
|
253099
253150
|
}
|
|
253151
|
+
if (authorization) {
|
|
253152
|
+
proxyReq.setHeader("Base44-Service-Authorization", authorization);
|
|
253153
|
+
}
|
|
253100
253154
|
proxyReq.setHeader("Base44-Api-Url", `${req.protocol}://${req.headers.host}`);
|
|
253101
253155
|
},
|
|
253102
253156
|
error: (err, _req, res) => {
|
|
@@ -253322,7 +253376,6 @@ class Validator {
|
|
|
253322
253376
|
|
|
253323
253377
|
// src/cli/dev/dev-server/db/database.ts
|
|
253324
253378
|
var USER_COLLECTION = "user";
|
|
253325
|
-
var PRIVATE_COLLECTION_PREFIX = "$";
|
|
253326
253379
|
|
|
253327
253380
|
class Database {
|
|
253328
253381
|
collections = new Map;
|
|
@@ -253344,7 +253397,6 @@ class Database {
|
|
|
253344
253397
|
this.schemas.set(USER_COLLECTION, this.buildUserSchema(userEntity));
|
|
253345
253398
|
const collection = new import_nedb.default;
|
|
253346
253399
|
this.collections.set(USER_COLLECTION, collection);
|
|
253347
|
-
this.collections.set(PRIVATE_COLLECTION_PREFIX + USER_COLLECTION, new import_nedb.default);
|
|
253348
253400
|
const userInfo = await readAuth();
|
|
253349
253401
|
const now = getNowISOTimestamp();
|
|
253350
253402
|
await collection.insertAsync({
|
|
@@ -253386,9 +253438,7 @@ class Database {
|
|
|
253386
253438
|
return this.collections.get(this.normalizeName(name2));
|
|
253387
253439
|
}
|
|
253388
253440
|
getCollectionNames() {
|
|
253389
|
-
return Array.from(this.collections.keys())
|
|
253390
|
-
return !name2.startsWith(PRIVATE_COLLECTION_PREFIX);
|
|
253391
|
-
});
|
|
253441
|
+
return Array.from(this.collections.keys());
|
|
253392
253442
|
}
|
|
253393
253443
|
dropAll() {
|
|
253394
253444
|
for (const collection of this.collections.values()) {
|
|
@@ -253452,205 +253502,15 @@ function broadcastEntityEvent(io6, appId, entityName, event) {
|
|
|
253452
253502
|
});
|
|
253453
253503
|
}
|
|
253454
253504
|
|
|
253455
|
-
// src/cli/dev/dev-server/routes/auth-router.ts
|
|
253456
|
-
var import_express2 = __toESM(require_express(), 1);
|
|
253457
|
-
var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
|
|
253458
|
-
import { randomInt } from "node:crypto";
|
|
253459
|
-
var LOCAL_DEV_SECRET = "LOCAL_DEV_SECRET";
|
|
253460
|
-
var generateCode = () => {
|
|
253461
|
-
return randomInt(1e5, 1e6).toString();
|
|
253462
|
-
};
|
|
253463
|
-
var createJwtToken = (email3) => {
|
|
253464
|
-
return import_jsonwebtoken.default.sign({ sub: email3 }, LOCAL_DEV_SECRET, {
|
|
253465
|
-
expiresIn: "360d"
|
|
253466
|
-
});
|
|
253467
|
-
};
|
|
253468
|
-
function createAuthRouter(db2, logger2) {
|
|
253469
|
-
const router = import_express2.Router({ mergeParams: true });
|
|
253470
|
-
const userRegistrPendingMap = new Map;
|
|
253471
|
-
const parseBody = import_express2.json();
|
|
253472
|
-
router.post("/login", parseBody, async (req, res) => {
|
|
253473
|
-
const { email: email3, password } = req.body;
|
|
253474
|
-
const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
|
|
253475
|
-
if (result) {
|
|
253476
|
-
const registeredUserData = userRegistrPendingMap.get(email3);
|
|
253477
|
-
if (result.role === "admin" || registeredUserData?.password === password) {
|
|
253478
|
-
res.json({
|
|
253479
|
-
access_token: createJwtToken(email3),
|
|
253480
|
-
success: true,
|
|
253481
|
-
user: {}
|
|
253482
|
-
});
|
|
253483
|
-
} else {
|
|
253484
|
-
res.status(400).json({
|
|
253485
|
-
detail: "Invalid email or password",
|
|
253486
|
-
error_type: "HTTPException",
|
|
253487
|
-
message: "Invalid email or password",
|
|
253488
|
-
request_id: null,
|
|
253489
|
-
traceback: ""
|
|
253490
|
-
});
|
|
253491
|
-
}
|
|
253492
|
-
return;
|
|
253493
|
-
}
|
|
253494
|
-
res.status(401).json({ error: "Unauthorized" });
|
|
253495
|
-
});
|
|
253496
|
-
router.post("/register", parseBody, async (req, res) => {
|
|
253497
|
-
const { email: email3, password } = req.body;
|
|
253498
|
-
if ((password || "").length < 8) {
|
|
253499
|
-
res.status(400).json({
|
|
253500
|
-
detail: "Password must be at least 8 characters long",
|
|
253501
|
-
error_type: "HTTPException",
|
|
253502
|
-
message: "Password must be at least 8 characters long",
|
|
253503
|
-
request_id: null,
|
|
253504
|
-
traceback: ""
|
|
253505
|
-
});
|
|
253506
|
-
return;
|
|
253507
|
-
}
|
|
253508
|
-
const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: email3 });
|
|
253509
|
-
if (result) {
|
|
253510
|
-
res.status(400).json({
|
|
253511
|
-
detail: "A user with this email already exists",
|
|
253512
|
-
error_type: "HTTPException",
|
|
253513
|
-
message: "A user with this email already exists",
|
|
253514
|
-
request_id: null,
|
|
253515
|
-
traceback: ""
|
|
253516
|
-
});
|
|
253517
|
-
return;
|
|
253518
|
-
}
|
|
253519
|
-
const otpCode = generateCode();
|
|
253520
|
-
const id2 = nanoid3();
|
|
253521
|
-
userRegistrPendingMap.set(email3, {
|
|
253522
|
-
id: id2,
|
|
253523
|
-
email: email3,
|
|
253524
|
-
otpCode,
|
|
253525
|
-
password,
|
|
253526
|
-
createdAt: +Date.now()
|
|
253527
|
-
});
|
|
253528
|
-
logger2.log(theme.styles.info(`
|
|
253529
|
-
In order to complete registration use this verification code: ${otpCode}
|
|
253530
|
-
`));
|
|
253531
|
-
res.json({
|
|
253532
|
-
id: id2,
|
|
253533
|
-
message: "Registration successful. Please check your email for the verification code.",
|
|
253534
|
-
otp_expires_in_minutes: 10
|
|
253535
|
-
});
|
|
253536
|
-
});
|
|
253537
|
-
router.post("/verify-otp", parseBody, async (req, res) => {
|
|
253538
|
-
const { email: email3, otp_code } = req.body;
|
|
253539
|
-
const userData = userRegistrPendingMap.get(email3);
|
|
253540
|
-
if (userData && userData.otpCode === otp_code) {
|
|
253541
|
-
if (+Date.now() - userData.createdAt < 10 * 60 * 1000) {
|
|
253542
|
-
userData.otpCode = undefined;
|
|
253543
|
-
const collection = db2.getCollection(USER_COLLECTION);
|
|
253544
|
-
const now = getNowISOTimestamp();
|
|
253545
|
-
const nameFromEmailMatch = /^([^@]+)/.exec(email3);
|
|
253546
|
-
const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
|
|
253547
|
-
await collection?.insertAsync({
|
|
253548
|
-
id: userData.id,
|
|
253549
|
-
email: email3,
|
|
253550
|
-
full_name: fullName,
|
|
253551
|
-
is_service: false,
|
|
253552
|
-
is_verified: true,
|
|
253553
|
-
disabled: null,
|
|
253554
|
-
role: "user",
|
|
253555
|
-
collaborator_role: "editor",
|
|
253556
|
-
created_date: now,
|
|
253557
|
-
updated_date: now
|
|
253558
|
-
});
|
|
253559
|
-
res.json({
|
|
253560
|
-
id: userData.id,
|
|
253561
|
-
access_token: createJwtToken(email3),
|
|
253562
|
-
message: "Email verified successfully. You are now logged in.",
|
|
253563
|
-
success: true
|
|
253564
|
-
});
|
|
253565
|
-
} else {
|
|
253566
|
-
res.status(400).json({
|
|
253567
|
-
detail: "Verification code has expired",
|
|
253568
|
-
error_type: "HTTPException",
|
|
253569
|
-
message: "Verification code has expired",
|
|
253570
|
-
request_id: null,
|
|
253571
|
-
traceback: ""
|
|
253572
|
-
});
|
|
253573
|
-
}
|
|
253574
|
-
} else {
|
|
253575
|
-
const appId = req.params.appId;
|
|
253576
|
-
res.status(500).json({
|
|
253577
|
-
detail: `{'email': '${email3}', 'app_id': '${appId}}'} -> Object not found`,
|
|
253578
|
-
error_type: "ObjectNotFoundError",
|
|
253579
|
-
message: `{'email': '${email3}', 'app_id': '${appId}}'} -> Object not found`,
|
|
253580
|
-
request_id: null,
|
|
253581
|
-
traceback: ""
|
|
253582
|
-
});
|
|
253583
|
-
}
|
|
253584
|
-
});
|
|
253585
|
-
return router;
|
|
253586
|
-
}
|
|
253587
|
-
|
|
253588
253505
|
// src/cli/dev/dev-server/routes/entities/entities-router.ts
|
|
253589
|
-
var
|
|
253590
|
-
|
|
253591
|
-
// src/cli/dev/dev-server/db/entity-queries.ts
|
|
253592
|
-
function parseSort(sort) {
|
|
253593
|
-
if (!sort) {
|
|
253594
|
-
return;
|
|
253595
|
-
}
|
|
253596
|
-
if (sort.startsWith("-")) {
|
|
253597
|
-
return { [sort.slice(1)]: -1 };
|
|
253598
|
-
}
|
|
253599
|
-
return { [sort]: 1 };
|
|
253600
|
-
}
|
|
253601
|
-
function parseFields(fields) {
|
|
253602
|
-
if (!fields) {
|
|
253603
|
-
return;
|
|
253604
|
-
}
|
|
253605
|
-
const projection = {};
|
|
253606
|
-
for (const field of fields.split(",")) {
|
|
253607
|
-
const trimmed = field.trim();
|
|
253608
|
-
if (trimmed) {
|
|
253609
|
-
projection[trimmed] = 1;
|
|
253610
|
-
}
|
|
253611
|
-
}
|
|
253612
|
-
return Object.keys(projection).length > 0 ? projection : undefined;
|
|
253613
|
-
}
|
|
253614
|
-
var queryEntity = async (collection, reqQuery) => {
|
|
253615
|
-
const { sort, limit, skip: skip2, fields, q: q13 } = reqQuery;
|
|
253616
|
-
let query = {};
|
|
253617
|
-
if (q13 && typeof q13 === "string") {
|
|
253618
|
-
try {
|
|
253619
|
-
query = JSON.parse(q13);
|
|
253620
|
-
} catch {
|
|
253621
|
-
throw new InvalidInputError("Invalid query parameter 'q'");
|
|
253622
|
-
}
|
|
253623
|
-
}
|
|
253624
|
-
let cursor3 = collection.findAsync(query);
|
|
253625
|
-
const sortObj = parseSort(sort);
|
|
253626
|
-
if (sortObj) {
|
|
253627
|
-
cursor3 = cursor3.sort(sortObj);
|
|
253628
|
-
}
|
|
253629
|
-
if (skip2) {
|
|
253630
|
-
const skipNum = Number.parseInt(skip2, 10);
|
|
253631
|
-
if (!Number.isNaN(skipNum)) {
|
|
253632
|
-
cursor3 = cursor3.skip(skipNum);
|
|
253633
|
-
}
|
|
253634
|
-
}
|
|
253635
|
-
if (limit) {
|
|
253636
|
-
const limitNum = Number.parseInt(limit, 10);
|
|
253637
|
-
if (!Number.isNaN(limitNum)) {
|
|
253638
|
-
cursor3 = cursor3.limit(limitNum);
|
|
253639
|
-
}
|
|
253640
|
-
}
|
|
253641
|
-
const projection = parseFields(fields);
|
|
253642
|
-
if (projection) {
|
|
253643
|
-
cursor3 = cursor3.projection(projection);
|
|
253644
|
-
}
|
|
253645
|
-
return cursor3;
|
|
253646
|
-
};
|
|
253506
|
+
var import_express3 = __toESM(require_express(), 1);
|
|
253647
253507
|
|
|
253648
253508
|
// src/cli/dev/dev-server/routes/entities/entities-user-router.ts
|
|
253649
|
-
var
|
|
253650
|
-
var
|
|
253509
|
+
var import_express2 = __toESM(require_express(), 1);
|
|
253510
|
+
var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
|
|
253651
253511
|
function createUserRouter(db2, logger2) {
|
|
253652
|
-
const router =
|
|
253653
|
-
const parseBody =
|
|
253512
|
+
const router = import_express2.Router({ mergeParams: true });
|
|
253513
|
+
const parseBody = import_express2.json();
|
|
253654
253514
|
function withAuth(handler) {
|
|
253655
253515
|
return async (req, res) => {
|
|
253656
253516
|
const auth2 = req.headers.authorization;
|
|
@@ -253659,7 +253519,7 @@ function createUserRouter(db2, logger2) {
|
|
|
253659
253519
|
return;
|
|
253660
253520
|
}
|
|
253661
253521
|
try {
|
|
253662
|
-
const { payload } =
|
|
253522
|
+
const { payload } = import_jsonwebtoken.default.decode(auth2.replace("Bearer ", ""), { complete: true }) ?? {};
|
|
253663
253523
|
const result = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: payload?.sub });
|
|
253664
253524
|
if (!result) {
|
|
253665
253525
|
res.status(404).json({ error: "Unable to read data for the current user" });
|
|
@@ -253692,28 +253552,6 @@ function createUserRouter(db2, logger2) {
|
|
|
253692
253552
|
...req.body
|
|
253693
253553
|
});
|
|
253694
253554
|
}));
|
|
253695
|
-
router.get("/", withAuth(async (req, res, currentUser) => {
|
|
253696
|
-
const collection = db2.getCollection(USER_COLLECTION);
|
|
253697
|
-
if (!collection) {
|
|
253698
|
-
res.status(404).json({ error: `Entity "${USER_COLLECTION}" not found` });
|
|
253699
|
-
return;
|
|
253700
|
-
}
|
|
253701
|
-
try {
|
|
253702
|
-
if (currentUser.role === "admin") {
|
|
253703
|
-
const result = await queryEntity(collection, req.query);
|
|
253704
|
-
res.json(stripInternalFields(result));
|
|
253705
|
-
} else {
|
|
253706
|
-
res.json([stripInternalFields(currentUser)]);
|
|
253707
|
-
}
|
|
253708
|
-
} catch (error48) {
|
|
253709
|
-
if (error48 instanceof InvalidInputError) {
|
|
253710
|
-
res.status(400).json({ error: error48.message });
|
|
253711
|
-
} else {
|
|
253712
|
-
logger2.error(`Error in GET /${USER_COLLECTION}:`, error48);
|
|
253713
|
-
res.status(500).json({ error: "Internal server error" });
|
|
253714
|
-
}
|
|
253715
|
-
}
|
|
253716
|
-
}));
|
|
253717
253555
|
router.post("/bulk", async (_req, res) => {
|
|
253718
253556
|
res.json({});
|
|
253719
253557
|
});
|
|
@@ -253763,9 +253601,31 @@ function createUserRouter(db2, logger2) {
|
|
|
253763
253601
|
}
|
|
253764
253602
|
|
|
253765
253603
|
// src/cli/dev/dev-server/routes/entities/entities-router.ts
|
|
253604
|
+
function parseSort(sort) {
|
|
253605
|
+
if (!sort) {
|
|
253606
|
+
return;
|
|
253607
|
+
}
|
|
253608
|
+
if (sort.startsWith("-")) {
|
|
253609
|
+
return { [sort.slice(1)]: -1 };
|
|
253610
|
+
}
|
|
253611
|
+
return { [sort]: 1 };
|
|
253612
|
+
}
|
|
253613
|
+
function parseFields(fields) {
|
|
253614
|
+
if (!fields) {
|
|
253615
|
+
return;
|
|
253616
|
+
}
|
|
253617
|
+
const projection = {};
|
|
253618
|
+
for (const field of fields.split(",")) {
|
|
253619
|
+
const trimmed = field.trim();
|
|
253620
|
+
if (trimmed) {
|
|
253621
|
+
projection[trimmed] = 1;
|
|
253622
|
+
}
|
|
253623
|
+
}
|
|
253624
|
+
return Object.keys(projection).length > 0 ? projection : undefined;
|
|
253625
|
+
}
|
|
253766
253626
|
async function createEntityRoutes(db2, logger2, broadcast) {
|
|
253767
|
-
const router =
|
|
253768
|
-
const parseBody =
|
|
253627
|
+
const router = import_express3.Router({ mergeParams: true });
|
|
253628
|
+
const parseBody = import_express3.json();
|
|
253769
253629
|
function withCollection(handler) {
|
|
253770
253630
|
return async (req, res) => {
|
|
253771
253631
|
const collection = db2.getCollection(req.params.entityName);
|
|
@@ -253810,14 +253670,42 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
253810
253670
|
router.get("/:entityName", withCollection(async (req, res, collection) => {
|
|
253811
253671
|
const { entityName } = req.params;
|
|
253812
253672
|
try {
|
|
253813
|
-
|
|
253814
|
-
|
|
253815
|
-
if (
|
|
253816
|
-
|
|
253817
|
-
|
|
253818
|
-
|
|
253819
|
-
|
|
253673
|
+
const { sort, limit, skip: skip2, fields, q: q13 } = req.query;
|
|
253674
|
+
let query = {};
|
|
253675
|
+
if (q13 && typeof q13 === "string") {
|
|
253676
|
+
try {
|
|
253677
|
+
query = JSON.parse(q13);
|
|
253678
|
+
} catch {
|
|
253679
|
+
res.status(400).json({ error: "Invalid query parameter 'q'" });
|
|
253680
|
+
return;
|
|
253681
|
+
}
|
|
253682
|
+
}
|
|
253683
|
+
let cursor3 = collection.findAsync(query);
|
|
253684
|
+
const sortObj = parseSort(sort);
|
|
253685
|
+
if (sortObj) {
|
|
253686
|
+
cursor3 = cursor3.sort(sortObj);
|
|
253687
|
+
}
|
|
253688
|
+
if (skip2) {
|
|
253689
|
+
const skipNum = Number.parseInt(skip2, 10);
|
|
253690
|
+
if (!Number.isNaN(skipNum)) {
|
|
253691
|
+
cursor3 = cursor3.skip(skipNum);
|
|
253692
|
+
}
|
|
253693
|
+
}
|
|
253694
|
+
if (limit) {
|
|
253695
|
+
const limitNum = Number.parseInt(limit, 10);
|
|
253696
|
+
if (!Number.isNaN(limitNum)) {
|
|
253697
|
+
cursor3 = cursor3.limit(limitNum);
|
|
253698
|
+
}
|
|
253699
|
+
}
|
|
253700
|
+
const projection = parseFields(fields);
|
|
253701
|
+
if (projection) {
|
|
253702
|
+
cursor3 = cursor3.projection(projection);
|
|
253820
253703
|
}
|
|
253704
|
+
const docs = await cursor3;
|
|
253705
|
+
res.json(stripInternalFields(docs));
|
|
253706
|
+
} catch (error48) {
|
|
253707
|
+
logger2.error(`Error in GET /${entityName}:`, error48);
|
|
253708
|
+
res.status(500).json({ error: "Internal server error" });
|
|
253821
253709
|
}
|
|
253822
253710
|
}));
|
|
253823
253711
|
router.post("/:entityName", parseBody, withCollection(async (req, res, collection) => {
|
|
@@ -253936,7 +253824,7 @@ async function createEntityRoutes(db2, logger2, broadcast) {
|
|
|
253936
253824
|
}
|
|
253937
253825
|
|
|
253938
253826
|
// src/cli/dev/dev-server/routes/integrations.ts
|
|
253939
|
-
var
|
|
253827
|
+
var import_express4 = __toESM(require_express(), 1);
|
|
253940
253828
|
var import_multer = __toESM(require_multer(), 1);
|
|
253941
253829
|
import { createHash, randomUUID as randomUUID4 } from "node:crypto";
|
|
253942
253830
|
import fs28 from "node:fs";
|
|
@@ -253945,8 +253833,8 @@ function createFileToken(fileUri) {
|
|
|
253945
253833
|
return createHash("sha256").update(fileUri).digest("hex");
|
|
253946
253834
|
}
|
|
253947
253835
|
function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger2) {
|
|
253948
|
-
const router =
|
|
253949
|
-
const parseBody =
|
|
253836
|
+
const router = import_express4.Router({ mergeParams: true });
|
|
253837
|
+
const parseBody = import_express4.json();
|
|
253950
253838
|
const privateFilesDir = path18.join(mediaFilesDir, "private");
|
|
253951
253839
|
fs28.mkdirSync(mediaFilesDir, { recursive: true });
|
|
253952
253840
|
fs28.mkdirSync(privateFilesDir, { recursive: true });
|
|
@@ -254016,7 +253904,7 @@ function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger2) {
|
|
|
254016
253904
|
return router;
|
|
254017
253905
|
}
|
|
254018
253906
|
function createCustomIntegrationRoutes(remoteProxy, logger2) {
|
|
254019
|
-
const router =
|
|
253907
|
+
const router = import_express4.Router({ mergeParams: true });
|
|
254020
253908
|
router.post("/:slug/:operationId", (req, res, next) => {
|
|
254021
253909
|
logger2.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
|
|
254022
253910
|
req.url = req.originalUrl;
|
|
@@ -255729,7 +255617,7 @@ async function createDevServer(options8) {
|
|
|
255729
255617
|
const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
|
|
255730
255618
|
const baseUrl = `http://localhost:${port}`;
|
|
255731
255619
|
const { functions, entities, project: project2 } = await options8.loadResources();
|
|
255732
|
-
const app =
|
|
255620
|
+
const app = import_express5.default();
|
|
255733
255621
|
const remoteProxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
255734
255622
|
target: BASE44_APP_URL,
|
|
255735
255623
|
changeOrigin: true
|
|
@@ -255761,8 +255649,6 @@ async function createDevServer(options8) {
|
|
|
255761
255649
|
let emitEntityEvent = () => {};
|
|
255762
255650
|
const entityRoutes = await createEntityRoutes(db2, devLogger, (...args) => emitEntityEvent(...args));
|
|
255763
255651
|
app.use("/api/apps/:appId/entities", entityRoutes);
|
|
255764
|
-
const authRouter = createAuthRouter(db2, devLogger);
|
|
255765
|
-
app.use("/api/apps/:appId/auth", authRouter);
|
|
255766
255652
|
const { path: mediaFilesDir } = await $dir();
|
|
255767
255653
|
app.use("/media/private/:fileUri", (req, res, next) => {
|
|
255768
255654
|
const { fileUri } = req.params;
|
|
@@ -255782,15 +255668,13 @@ async function createDevServer(options8) {
|
|
|
255782
255668
|
}
|
|
255783
255669
|
next();
|
|
255784
255670
|
});
|
|
255785
|
-
app.use("/media",
|
|
255671
|
+
app.use("/media", import_express5.default.static(mediaFilesDir));
|
|
255786
255672
|
const integrationRoutes = createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, devLogger);
|
|
255787
255673
|
app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
|
|
255788
255674
|
const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
|
|
255789
255675
|
app.use("/api/apps/:appId/integrations/custom", customIntegrationRoutes);
|
|
255790
255676
|
app.use((req, res, next) => {
|
|
255791
|
-
|
|
255792
|
-
devLogger.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
|
|
255793
|
-
}
|
|
255677
|
+
devLogger.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
|
|
255794
255678
|
remoteProxy(req, res, next);
|
|
255795
255679
|
});
|
|
255796
255680
|
const server = await new Promise((resolve8, reject) => {
|
|
@@ -255861,7 +255745,6 @@ async function devAction({ log }, options8) {
|
|
|
255861
255745
|
const { port: resolvedPort } = await createDevServer({
|
|
255862
255746
|
log,
|
|
255863
255747
|
port,
|
|
255864
|
-
cwd: process21.cwd(),
|
|
255865
255748
|
denoWrapperPath: getDenoWrapperPath(),
|
|
255866
255749
|
loadResources: async () => {
|
|
255867
255750
|
const { functions, entities, project: project2 } = await readProjectConfig();
|
|
@@ -260369,4 +260252,4 @@ export {
|
|
|
260369
260252
|
CLIExitError
|
|
260370
260253
|
};
|
|
260371
260254
|
|
|
260372
|
-
//# debugId=
|
|
260255
|
+
//# debugId=C6E0C5B984DF777364756E2164756E21
|