@base44-preview/cli 0.0.44-pr.405.2f92c9f → 0.0.44-pr.406.b97f4ba

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -248424,7 +248424,7 @@ function getTypesCommand(context) {
248424
248424
  // src/cli/dev/dev-server/main.ts
248425
248425
  import { dirname as dirname13, join as join18 } from "node:path";
248426
248426
  var import_cors = __toESM(require_lib4(), 1);
248427
- var import_express4 = __toESM(require_express(), 1);
248427
+ var import_express6 = __toESM(require_express(), 1);
248428
248428
 
248429
248429
  // ../../node_modules/get-port/index.js
248430
248430
  import net from "node:net";
@@ -248784,11 +248784,14 @@ var import_nedb = __toESM(require_nedb(), 1);
248784
248784
 
248785
248785
  class Database {
248786
248786
  collections = new Map;
248787
- load(entities) {
248788
- for (const entity2 of entities) {
248789
- this.collections.set(entity2.name, new import_nedb.default);
248787
+ initCollections(names) {
248788
+ for (const name2 of names) {
248789
+ this.collections.set(name2, new import_nedb.default);
248790
248790
  }
248791
248791
  }
248792
+ hasCollection(name2) {
248793
+ return this.collections.has(name2);
248794
+ }
248792
248795
  getCollection(name2) {
248793
248796
  return this.collections.get(name2);
248794
248797
  }
@@ -248835,8 +248838,8 @@ function broadcastEntityEvent(io6, appId, entityName, event) {
248835
248838
  });
248836
248839
  }
248837
248840
 
248838
- // src/cli/dev/dev-server/routes/entities.ts
248839
- var import_express2 = __toESM(require_express(), 1);
248841
+ // src/cli/dev/dev-server/routes/entities/entities-router.ts
248842
+ var import_express3 = __toESM(require_express(), 1);
248840
248843
 
248841
248844
  // ../../node_modules/nanoid/index.js
248842
248845
  import { webcrypto as crypto } from "node:crypto";
@@ -248868,7 +248871,52 @@ function nanoid3(size = 21) {
248868
248871
  return id2;
248869
248872
  }
248870
248873
 
248871
- // src/cli/dev/dev-server/routes/entities.ts
248874
+ // src/cli/dev/dev-server/routes/entities/entities-user-router.ts
248875
+ var import_express2 = __toESM(require_express(), 1);
248876
+
248877
+ // src/cli/dev/dev-server/routes/entities/utils.ts
248878
+ function stripInternalFields(doc2) {
248879
+ if (Array.isArray(doc2)) {
248880
+ return doc2.map((d5) => stripInternalFields(d5));
248881
+ }
248882
+ const { _id, ...rest } = doc2;
248883
+ return rest;
248884
+ }
248885
+
248886
+ // src/cli/dev/dev-server/routes/entities/entities-user-router.ts
248887
+ async function createUserRouter(db2) {
248888
+ if (!db2.hasCollection("User")) {
248889
+ db2.initCollections(["User"]);
248890
+ }
248891
+ const userInfo = await readAuth();
248892
+ const now = new Date().toISOString().replace("Z", "000");
248893
+ const idMe = nanoid3();
248894
+ await db2.getCollection("User")?.insertAsync({
248895
+ id: idMe,
248896
+ email: userInfo.email,
248897
+ full_name: userInfo.name,
248898
+ is_service: false,
248899
+ is_verified: true,
248900
+ disabled: null,
248901
+ role: "admin",
248902
+ collaborator_role: "editor",
248903
+ created_date: now,
248904
+ updated_date: now
248905
+ });
248906
+ const router = import_express2.Router({ mergeParams: true });
248907
+ router.get("/:id", async (req, res) => {
248908
+ const id2 = req.params.id === "me" ? idMe : req.params.id;
248909
+ const result = await db2.getCollection("User")?.findOneAsync({ id: id2 });
248910
+ if (!result) {
248911
+ res.status(404).json({ error: `User with id "${req.params.id}" not found` });
248912
+ return;
248913
+ }
248914
+ res.json(stripInternalFields(result));
248915
+ });
248916
+ return router;
248917
+ }
248918
+
248919
+ // src/cli/dev/dev-server/routes/entities/entities-router.ts
248872
248920
  function parseSort(sort) {
248873
248921
  if (!sort) {
248874
248922
  return;
@@ -248891,16 +248939,9 @@ function parseFields(fields) {
248891
248939
  }
248892
248940
  return Object.keys(projection).length > 0 ? projection : undefined;
248893
248941
  }
248894
- function stripInternalFields(doc2) {
248895
- if (Array.isArray(doc2)) {
248896
- return doc2.map((d5) => stripInternalFields(d5));
248897
- }
248898
- const { _id, ...rest } = doc2;
248899
- return rest;
248900
- }
248901
- function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
248902
- const router = import_express2.Router({ mergeParams: true });
248903
- const parseBody = import_express2.json();
248942
+ async function createEntityRoutes(db2, logger, broadcast) {
248943
+ const router = import_express3.Router({ mergeParams: true });
248944
+ const parseBody = import_express3.json();
248904
248945
  function withCollection(handler) {
248905
248946
  return async (req, res) => {
248906
248947
  const collection = db2.getCollection(req.params.entityName);
@@ -248926,11 +248967,8 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
248926
248967
  }
248927
248968
  broadcast(appId, entityName, createData(data));
248928
248969
  }
248929
- router.get("/User/:id", (req, res, next) => {
248930
- logger.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
248931
- req.url = req.originalUrl;
248932
- remoteProxy(req, res, next);
248933
- });
248970
+ const userRouter = await createUserRouter(db2);
248971
+ router.use("/User", userRouter);
248934
248972
  router.get("/:entityName/:id", withCollection(async (req, res, collection) => {
248935
248973
  const { entityName, id: id2 } = req.params;
248936
248974
  try {
@@ -249081,7 +249119,7 @@ function createEntityRoutes(db2, logger, remoteProxy, broadcast) {
249081
249119
  }
249082
249120
 
249083
249121
  // src/cli/dev/dev-server/routes/integrations.ts
249084
- var import_express3 = __toESM(require_express(), 1);
249122
+ var import_express4 = __toESM(require_express(), 1);
249085
249123
  var import_multer = __toESM(require_multer(), 1);
249086
249124
  import { createHash, randomUUID as randomUUID4 } from "node:crypto";
249087
249125
  import fs28 from "node:fs";
@@ -249090,8 +249128,8 @@ function createFileToken(fileUri) {
249090
249128
  return createHash("sha256").update(fileUri).digest("hex");
249091
249129
  }
249092
249130
  function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger) {
249093
- const router = import_express3.Router({ mergeParams: true });
249094
- const parseBody = import_express3.json();
249131
+ const router = import_express4.Router({ mergeParams: true });
249132
+ const parseBody = import_express4.json();
249095
249133
  const privateFilesDir = path18.join(mediaFilesDir, "private");
249096
249134
  fs28.mkdirSync(mediaFilesDir, { recursive: true });
249097
249135
  fs28.mkdirSync(privateFilesDir, { recursive: true });
@@ -249161,7 +249199,7 @@ function createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, logger) {
249161
249199
  return router;
249162
249200
  }
249163
249201
  function createCustomIntegrationRoutes(remoteProxy, logger) {
249164
- const router = import_express3.Router({ mergeParams: true });
249202
+ const router = import_express4.Router({ mergeParams: true });
249165
249203
  router.post("/:slug/:operationId", (req, res, next) => {
249166
249204
  logger.warn(`"${req.originalUrl}" is not supported in local development, passing call to production`);
249167
249205
  req.url = req.originalUrl;
@@ -249170,6 +249208,18 @@ function createCustomIntegrationRoutes(remoteProxy, logger) {
249170
249208
  return router;
249171
249209
  }
249172
249210
 
249211
+ // src/cli/dev/dev-server/routes/users.ts
249212
+ var import_express5 = __toESM(require_express(), 1);
249213
+ function createUsersRoutes() {
249214
+ const router = import_express5.Router({ mergeParams: true });
249215
+ const parseBody = import_express5.json();
249216
+ router.post("/invite-user", parseBody, (req, _res, next) => {
249217
+ console.log("invite-user", req.body);
249218
+ next();
249219
+ });
249220
+ return router;
249221
+ }
249222
+
249173
249223
  // src/cli/dev/dev-server/watcher.ts
249174
249224
  import { EventEmitter as EventEmitter4 } from "node:events";
249175
249225
  import { relative as relative6 } from "node:path";
@@ -250874,7 +250924,7 @@ async function createDevServer(options8) {
250874
250924
  const port = userPort ?? await getPorts({ port: DEFAULT_PORT });
250875
250925
  const baseUrl = `http://localhost:${port}`;
250876
250926
  const { functions, entities, project: project2 } = await options8.loadResources();
250877
- const app = import_express4.default();
250927
+ const app = import_express6.default();
250878
250928
  const remoteProxy = import_http_proxy_middleware2.createProxyMiddleware({
250879
250929
  target: BASE44_APP_URL,
250880
250930
  changeOrigin: true
@@ -250891,7 +250941,17 @@ async function createDevServer(options8) {
250891
250941
  }
250892
250942
  next();
250893
250943
  });
250944
+ app.use((req, res, next) => {
250945
+ const auth2 = req.headers.authorization;
250946
+ if (!auth2 || !auth2.startsWith("Bearer ")) {
250947
+ res.status(401).json({ error: "Unauthorized" });
250948
+ return;
250949
+ }
250950
+ next();
250951
+ });
250894
250952
  const devLogger = createDevLogger();
250953
+ const usersRoutes = createUsersRoutes();
250954
+ app.use("/api/apps/:appId/users", usersRoutes);
250895
250955
  const functionManager = new FunctionManager(functions, devLogger, options8.denoWrapperPath);
250896
250956
  const functionRoutes = createFunctionRouter(functionManager, devLogger);
250897
250957
  app.use("/api/apps/:appId/functions", functionRoutes);
@@ -250899,12 +250959,12 @@ async function createDevServer(options8) {
250899
250959
  R2.info(`Loaded functions: ${functionManager.getFunctionNames().join(", ")}`);
250900
250960
  }
250901
250961
  const db2 = new Database;
250902
- db2.load(entities);
250962
+ db2.initCollections(entities.map((entity2) => entity2.name));
250903
250963
  if (db2.getCollectionNames().length > 0) {
250904
250964
  R2.info(`Loaded entities: ${db2.getCollectionNames().join(", ")}`);
250905
250965
  }
250906
250966
  let emitEntityEvent = () => {};
250907
- const entityRoutes = createEntityRoutes(db2, devLogger, remoteProxy, (...args) => emitEntityEvent(...args));
250967
+ const entityRoutes = await createEntityRoutes(db2, devLogger, (...args) => emitEntityEvent(...args));
250908
250968
  app.use("/api/apps/:appId/entities", entityRoutes);
250909
250969
  const { path: mediaFilesDir } = await $dir();
250910
250970
  app.use("/media/private/:fileUri", (req, res, next) => {
@@ -250925,7 +250985,7 @@ async function createDevServer(options8) {
250925
250985
  }
250926
250986
  next();
250927
250987
  });
250928
- app.use("/media", import_express4.default.static(mediaFilesDir));
250988
+ app.use("/media", import_express6.default.static(mediaFilesDir));
250929
250989
  const integrationRoutes = createIntegrationRoutes(mediaFilesDir, baseUrl, remoteProxy, devLogger);
250930
250990
  app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
250931
250991
  const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
@@ -250974,7 +251034,7 @@ async function createDevServer(options8) {
250974
251034
  if (previousEntityCount > 0) {
250975
251035
  devLogger.log("Entities directory changed, clearing data...");
250976
251036
  }
250977
- db2.load(entities2);
251037
+ db2.initCollections(entities2.map((entity2) => entity2.name));
250978
251038
  if (db2.getCollectionNames().length > 0) {
250979
251039
  devLogger.log(`Loaded entities: ${db2.getCollectionNames().join(", ")}`);
250980
251040
  }
@@ -255375,4 +255435,4 @@ export {
255375
255435
  CLIExitError
255376
255436
  };
255377
255437
 
255378
- //# debugId=29A9031B09883B8D64756E2164756E21
255438
+ //# debugId=6ACA581A680E964E64756E2164756E21