@base44-preview/cli 0.1.6-pr.579.8e3e3da → 0.1.6-pr.580.20770cc

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.
@@ -9,7 +9,8 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "@base44/sdk": "^0.8.3",
12
+ "@base44/sdk": "^0.8.40",
13
+ "@base44/vite-plugin": "^1.0.30",
13
14
  "lucide-react": "^0.475.0",
14
15
  "react": "^18.2.0",
15
16
  "react-dom": "^18.2.0"
@@ -0,0 +1,14 @@
1
+ import { createClient } from '@base44/sdk';
2
+ import { appParams } from '@/lib/app-params';
3
+
4
+ const { appId, token, functionsVersion, appBaseUrl } = appParams;
5
+
6
+ //Create a client with authentication required
7
+ export const base44 = createClient({
8
+ appId,
9
+ token,
10
+ functionsVersion,
11
+ serverUrl: '',
12
+ requiresAuth: false,
13
+ appBaseUrl
14
+ });
@@ -0,0 +1,54 @@
1
+ const isNode = typeof window === 'undefined';
2
+ const windowObj = isNode ? { localStorage: new Map() } : window;
3
+ const storage = windowObj.localStorage;
4
+
5
+ const toSnakeCase = (str) => {
6
+ return str.replace(/([A-Z])/g, '_$1').toLowerCase();
7
+ }
8
+
9
+ const getAppParamValue = (paramName, { defaultValue = undefined, removeFromUrl = false } = {}) => {
10
+ if (isNode) {
11
+ return defaultValue;
12
+ }
13
+ const storageKey = `base44_${toSnakeCase(paramName)}`;
14
+ const urlParams = new URLSearchParams(window.location.search);
15
+ const searchParam = urlParams.get(paramName);
16
+ if (removeFromUrl) {
17
+ urlParams.delete(paramName);
18
+ const newUrl = `${window.location.pathname}${urlParams.toString() ? `?${urlParams.toString()}` : ""
19
+ }${window.location.hash}`;
20
+ window.history.replaceState({}, document.title, newUrl);
21
+ }
22
+ if (searchParam) {
23
+ storage.setItem(storageKey, searchParam);
24
+ return searchParam;
25
+ }
26
+ if (defaultValue) {
27
+ storage.setItem(storageKey, defaultValue);
28
+ return defaultValue;
29
+ }
30
+ const storedValue = storage.getItem(storageKey);
31
+ if (storedValue) {
32
+ return storedValue;
33
+ }
34
+ return null;
35
+ }
36
+
37
+ const getAppParams = () => {
38
+ if (getAppParamValue("clear_access_token") === 'true') {
39
+ storage.removeItem('base44_access_token');
40
+ storage.removeItem('token');
41
+ }
42
+ return {
43
+ appId: getAppParamValue("app_id", { defaultValue: import.meta.env.VITE_BASE44_APP_ID }),
44
+ token: getAppParamValue("access_token", { removeFromUrl: true }),
45
+ fromUrl: getAppParamValue("from_url", { defaultValue: window.location.href }),
46
+ functionsVersion: getAppParamValue("functions_version", { defaultValue: import.meta.env.VITE_BASE44_FUNCTIONS_VERSION }),
47
+ appBaseUrl: getAppParamValue("app_base_url", { defaultValue: import.meta.env.VITE_BASE44_APP_BASE_URL }),
48
+ }
49
+ }
50
+
51
+
52
+ export const appParams = {
53
+ ...getAppParams()
54
+ }
@@ -1,12 +1,7 @@
1
- import { defineConfig } from 'vite';
1
+ import base44 from '@base44/vite-plugin';
2
2
  import react from '@vitejs/plugin-react';
3
- import path from 'path';
3
+ import { defineConfig } from 'vite';
4
4
 
5
5
  export default defineConfig({
6
- plugins: [react()],
7
- resolve: {
8
- alias: {
9
- '@': path.resolve(__dirname, './src'),
10
- },
11
- },
6
+ plugins: [base44(), react()],
12
7
  });
package/dist/cli/index.js CHANGED
@@ -221304,6 +221304,7 @@ var PROJECT_CONFIG_PATTERNS = [
221304
221304
  ];
221305
221305
  var BASE44_APP_ID_ENV_VAR = "BASE44_APP_ID";
221306
221306
  var DEFAULT_DEV_SERVER_PORT = 4400;
221307
+ var BASE44_APP_URL = "https://base44.app";
221307
221308
  var TYPES_OUTPUT_SUBDIR = ".types";
221308
221309
  var TYPES_FILENAME = "types.d.ts";
221309
221310
  var AUTH_CLIENT_ID = "base44_cli";
@@ -256483,7 +256484,11 @@ async function completeProjectSetup({
256483
256484
  const { appUrl } = await runTask2("Installing dependencies...", async (updateMessage) => {
256484
256485
  await execa({ cwd: resolvedPath, shell: true })`${installCommand}`;
256485
256486
  updateMessage("Building project...");
256486
- await execa({ cwd: resolvedPath, shell: true })`${buildCommand}`;
256487
+ await execa({
256488
+ cwd: resolvedPath,
256489
+ shell: true,
256490
+ env: { VITE_BASE44_APP_ID: projectId }
256491
+ })`${buildCommand}`;
256487
256492
  updateMessage("Deploying site...");
256488
256493
  return await deploySite(join21(resolvedPath, outputDirectory));
256489
256494
  }, {
@@ -258800,10 +258805,6 @@ function stripInternalFields(doc2) {
258800
258805
  var getNowISOTimestamp = () => {
258801
258806
  return new Date().toISOString().replace("Z", "000");
258802
258807
  };
258803
- var deriveFullNameFromEmail = (email3) => {
258804
- const nameFromEmailMatch = /^([^@]+)/.exec(email3);
258805
- return nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
258806
- };
258807
258808
 
258808
258809
  // src/cli/dev/dev-server/db/validator.ts
258809
258810
  class EntityValidationError extends Error {
@@ -259216,7 +259217,8 @@ In order to complete registration use this verification code: ${otpCode}
259216
259217
  });
259217
259218
  const collection = db2.getCollection(USER_COLLECTION);
259218
259219
  const now = getNowISOTimestamp();
259219
- const fullName = deriveFullNameFromEmail(email3);
259220
+ const nameFromEmailMatch = /^([^@]+)/.exec(email3);
259221
+ const fullName = nameFromEmailMatch ? nameFromEmailMatch[1] : email3;
259220
259222
  await collection?.insertAsync({
259221
259223
  id: privateUserData.id,
259222
259224
  email: email3,
@@ -259448,38 +259450,14 @@ async function resolveCurrentUser(db2, req) {
259448
259450
  return { ok: true, user: SERVICE_USER };
259449
259451
  }
259450
259452
  const currentUser = await db2.getCollection(USER_COLLECTION)?.findOneAsync({ email: subject });
259451
- if (currentUser) {
259452
- return { ok: true, user: currentUser };
259453
- }
259454
- const externallyAuthenticatedUser = await createLocalUser(db2, subject);
259455
- if (!externallyAuthenticatedUser) {
259453
+ if (!currentUser) {
259456
259454
  return { ok: false, reason: "not_found" };
259457
259455
  }
259458
- return { ok: true, user: externallyAuthenticatedUser };
259456
+ return { ok: true, user: currentUser };
259459
259457
  } catch {
259460
259458
  return { ok: false, reason: "invalid" };
259461
259459
  }
259462
259460
  }
259463
- async function createLocalUser(db2, email3) {
259464
- const collection = db2.getCollection(USER_COLLECTION);
259465
- if (!collection) {
259466
- return;
259467
- }
259468
- const now = getNowISOTimestamp();
259469
- const inserted = await collection.insertAsync({
259470
- id: nanoid3(),
259471
- email: email3,
259472
- full_name: deriveFullNameFromEmail(email3),
259473
- is_service: false,
259474
- is_verified: true,
259475
- disabled: null,
259476
- role: "user",
259477
- collaborator_role: "editor",
259478
- created_date: now,
259479
- updated_date: now
259480
- });
259481
- return inserted;
259482
- }
259483
259461
 
259484
259462
  // src/cli/dev/dev-server/routes/entities/entities-user-router.ts
259485
259463
  var import_express3 = __toESM(require_express(), 1);
@@ -261722,15 +261700,6 @@ class WatchBase44 extends EventEmitter4 {
261722
261700
 
261723
261701
  // src/cli/dev/dev-server/main.ts
261724
261702
  var DEFAULT_PORT = 4400;
261725
- var BASE44_APP_URL = "https://base44.app";
261726
- function isLocalRedirectTarget(value) {
261727
- try {
261728
- const { protocol, hostname: hostname3 } = new URL(value);
261729
- return (protocol === "http:" || protocol === "https:") && (hostname3 === "localhost" || hostname3 === "127.0.0.1");
261730
- } catch {
261731
- return false;
261732
- }
261733
- }
261734
261703
  async function createDevServer(options8) {
261735
261704
  const { port: userPort } = options8;
261736
261705
  const port = userPort ?? await getPorts({
@@ -261747,13 +261716,6 @@ async function createDevServer(options8) {
261747
261716
  origin: /^http:\/\/localhost(:\d+)?$/,
261748
261717
  credentials: true
261749
261718
  }));
261750
- app.get("/api/apps/auth/logout", (req, res) => {
261751
- const fromUrl = req.query.from_url;
261752
- if (typeof fromUrl === "string" && isLocalRedirectTarget(fromUrl)) {
261753
- return res.redirect(fromUrl);
261754
- }
261755
- res.send("Logged out");
261756
- });
261757
261719
  const AUTH_ROUTE_PATTERN = /^\/api\/apps\/auth(\/|$)/;
261758
261720
  app.use((req, res, next) => {
261759
261721
  if (AUTH_ROUTE_PATTERN.test(req.path)) {
@@ -261921,6 +261883,37 @@ async function createDevServer(options8) {
261921
261883
  return { port, server, isServingFrontend: serveRunner !== undefined };
261922
261884
  }
261923
261885
 
261886
+ // src/cli/dev/remote-serve.ts
261887
+ function startRemoteServe(options8) {
261888
+ const runner = createRemoteServeRunner(options8);
261889
+ stopRunnerOnProcessSignals(runner);
261890
+ runner.onExit((code2) => process.exit(code2 ?? 1));
261891
+ runner.start();
261892
+ }
261893
+ function createRemoteServeRunner({
261894
+ appId,
261895
+ serveCommand,
261896
+ projectRoot
261897
+ }) {
261898
+ if (!serveCommand) {
261899
+ throw new ConfigInvalidError("base44 dev --remote serves the frontend against the production backend, but this project has no site.serveCommand in base44/config.jsonc.");
261900
+ }
261901
+ return new ServeRunner({
261902
+ command: serveCommand,
261903
+ cwd: projectRoot,
261904
+ env: {
261905
+ VITE_BASE44_APP_ID: appId,
261906
+ VITE_BASE44_APP_BASE_URL: BASE44_APP_URL
261907
+ },
261908
+ logger: createDevLogger("frontend", theme.colors.base44Orange)
261909
+ });
261910
+ }
261911
+ function stopRunnerOnProcessSignals(runner) {
261912
+ const stop2 = () => void runner.stop();
261913
+ process.on("SIGINT", stop2);
261914
+ process.on("SIGTERM", stop2);
261915
+ }
261916
+
261924
261917
  // src/cli/commands/dev.ts
261925
261918
  function localServerUrl(port) {
261926
261919
  return `http://localhost:${port}`;
@@ -261930,12 +261923,30 @@ function validateDevOptions(command2) {
261930
261923
  if (appId !== undefined) {
261931
261924
  command2.error(`base44 dev cannot be used with --app-id or ${BASE44_APP_ID_ENV_VAR}.`);
261932
261925
  }
261926
+ const { port, remote } = command2.opts();
261927
+ if (remote && port !== undefined) {
261928
+ command2.error("--port applies to the local backend, which --remote does not start.");
261929
+ }
261930
+ }
261931
+ async function remoteDevAction(app) {
261932
+ const { project: project2 } = await readProjectConfig(app.projectRoot);
261933
+ startRemoteServe({
261934
+ appId: app.id,
261935
+ serveCommand: project2.site?.serveCommand,
261936
+ projectRoot: project2.root
261937
+ });
261938
+ return {
261939
+ outroMessage: `Frontend dev server targets ${theme.styles.bold("production")} — every write hits your live app`
261940
+ };
261933
261941
  }
261934
261942
  async function devAction(ctx, options8) {
261935
261943
  const { log, app } = ctx;
261936
261944
  if (!app?.projectRoot) {
261937
261945
  throw new ConfigInvalidError("base44 dev requires a linked local project. Run it from a project with base44/.app.jsonc.");
261938
261946
  }
261947
+ if (options8.remote) {
261948
+ return remoteDevAction({ id: app.id, projectRoot: app.projectRoot });
261949
+ }
261939
261950
  const port = options8.port ? Number(options8.port) : undefined;
261940
261951
  const appId = app.id;
261941
261952
  const siteUrlPromise = getSiteUrl().catch(() => {
@@ -261956,7 +261967,7 @@ async function devAction(ctx, options8) {
261956
261967
  return { outroMessage };
261957
261968
  }
261958
261969
  function getDevCommand() {
261959
- return new Base44Command("dev").description("Start the development server").option("-p, --port <number>", "Port for the development server").hook("preAction", validateDevOptions).action(devAction);
261970
+ return new Base44Command("dev").description("Start the development server").option("-p, --port <number>", "Port for the development server").option("--remote", "Serve the frontend against the production backend instead of a local one").hook("preAction", validateDevOptions).action(devAction);
261960
261971
  }
261961
261972
 
261962
261973
  // src/core/exec/run-script.ts
@@ -266468,4 +266479,4 @@ export {
266468
266479
  CLIExitError
266469
266480
  };
266470
266481
 
266471
- //# debugId=A2E6A84191681AAC64756E2164756E21
266482
+ //# debugId=D9228B6EC0A3AD0964756E2164756E21