@base44-preview/cli 0.1.21-pr.642.f600707 → 0.1.22-pr.644.053dbd4

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.
@@ -11,6 +11,9 @@
11
11
  * - BASE44_APP_BASE_URL: App's published URL / subdomain (used for function calls)
12
12
  * - BASE44_PRIVILEGED: When "true", adds the X-Bypass-RLS header (bypass RLS)
13
13
  * - BASE44_DATA_ENV: When set, adds the X-Data-Env header (target data environment)
14
+ * - BASE44_SERVICE_TOKEN: When set, passed as `serviceToken` (enables `base44.asServiceRole`)
15
+ *
16
+ * BASE44_SERVICE_TOKEN is removed from the environment before the user script runs.
14
17
  */
15
18
 
16
19
  export {};
@@ -21,6 +24,8 @@ const accessToken = Deno.env.get("BASE44_ACCESS_TOKEN");
21
24
  const appBaseUrl = Deno.env.get("BASE44_APP_BASE_URL");
22
25
  const isPrivileged = Deno.env.get("BASE44_PRIVILEGED") === "true";
23
26
  const dataEnv = Deno.env.get("BASE44_DATA_ENV");
27
+ const serviceToken = Deno.env.get("BASE44_SERVICE_TOKEN");
28
+ Deno.env.delete("BASE44_SERVICE_TOKEN");
24
29
 
25
30
  if (!scriptPath) {
26
31
  console.error("SCRIPT_PATH environment variable is required");
@@ -46,6 +51,7 @@ if (dataEnv) customHeaders["X-Data-Env"] = dataEnv;
46
51
  const base44 = createClient({
47
52
  appId,
48
53
  token: accessToken,
54
+ ...(serviceToken ? { serviceToken } : {}),
49
55
  serverUrl: appBaseUrl,
50
56
  headers: customHeaders,
51
57
  });
package/dist/cli/index.js CHANGED
@@ -239265,7 +239265,7 @@ import { join as join13 } from "node:path";
239265
239265
  // package.json
239266
239266
  var package_default = {
239267
239267
  name: "base44",
239268
- version: "0.1.21",
239268
+ version: "0.1.22",
239269
239269
  description: "Base44 CLI - Unified interface for managing Base44 applications",
239270
239270
  type: "module",
239271
239271
  bin: {
@@ -256163,11 +256163,63 @@ function getDevCommand() {
256163
256163
  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);
256164
256164
  }
256165
256165
 
256166
+ // src/core/exec/env-target.ts
256167
+ var ACCESS_TOKEN_VAR = "BASE44_EXEC_ACCESS_TOKEN";
256168
+ var SERVER_URL_VAR = "BASE44_EXEC_SERVER_URL";
256169
+ var SERVICE_TOKEN_VAR = "BASE44_EXEC_SERVICE_TOKEN";
256170
+ var EXEC_ENV_VARS = [
256171
+ ACCESS_TOKEN_VAR,
256172
+ SERVER_URL_VAR,
256173
+ SERVICE_TOKEN_VAR
256174
+ ];
256175
+ var PRIVILEGED_ENV_VAR = "BASE44_EXEC_PRIVILEGED";
256176
+ var DATA_ENV_ENV_VAR = "BASE44_EXEC_DATA_ENV";
256177
+ function read3(env, name) {
256178
+ return env[name]?.trim() || undefined;
256179
+ }
256180
+ function hasExecEnvTarget(env = process.env) {
256181
+ return EXEC_ENV_VARS.some((name) => read3(env, name) !== undefined);
256182
+ }
256183
+ function readExecEnvTarget(env = process.env) {
256184
+ if (!hasExecEnvTarget(env)) {
256185
+ return;
256186
+ }
256187
+ const token = read3(env, ACCESS_TOKEN_VAR);
256188
+ const serverUrl = read3(env, SERVER_URL_VAR);
256189
+ if (!token || !serverUrl) {
256190
+ const missing = token ? SERVER_URL_VAR : ACCESS_TOKEN_VAR;
256191
+ throw new InvalidInputError(`${missing} is not set. ${ACCESS_TOKEN_VAR} and ${SERVER_URL_VAR} must be set together.`, {
256192
+ hints: [
256193
+ {
256194
+ message: `Set both ${ACCESS_TOKEN_VAR} and ${SERVER_URL_VAR}, or unset all of them to use your login`
256195
+ }
256196
+ ]
256197
+ });
256198
+ }
256199
+ if (!URL.canParse(serverUrl)) {
256200
+ throw new InvalidInputError(`${SERVER_URL_VAR} is not a valid URL.`);
256201
+ }
256202
+ const serviceToken = read3(env, SERVICE_TOKEN_VAR);
256203
+ return { token, serverUrl, ...serviceToken ? { serviceToken } : {} };
256204
+ }
256166
256205
  // src/core/exec/run-script.ts
256167
256206
  import { spawn as spawn4 } from "node:child_process";
256168
256207
  import { copyFileSync, writeFileSync as writeFileSync3 } from "node:fs";
256208
+ var SERVICE_TOKEN_ENV = "BASE44_SERVICE_TOKEN";
256209
+ function inheritedEnv() {
256210
+ const env = { ...process.env };
256211
+ for (const name of [
256212
+ ...EXEC_ENV_VARS,
256213
+ PRIVILEGED_ENV_VAR,
256214
+ DATA_ENV_ENV_VAR,
256215
+ SERVICE_TOKEN_ENV
256216
+ ]) {
256217
+ delete env[name];
256218
+ }
256219
+ return env;
256220
+ }
256169
256221
  async function runScript(options) {
256170
- const { appId, code, local, privileged, dataEnv } = options;
256222
+ const { appId, code, local, privileged, dataEnv, serviceToken } = options;
256171
256223
  verifyDenoInstalled("to run scripts with exec");
256172
256224
  const cleanupFns = [];
256173
256225
  const tempScript = await $file({ postfix: ".ts" });
@@ -256180,9 +256232,10 @@ async function runScript(options) {
256180
256232
  copyFileSync(getExecWrapperPath(), tempWrapper.path);
256181
256233
  try {
256182
256234
  const exitCode = await new Promise((resolvePromise) => {
256183
- const child = spawn4("deno", ["run", "--allow-all", "--node-modules-dir=auto", tempWrapper.path], {
256235
+ const child = spawn4("deno", ["run", "--allow-all", "--node-modules-dir=none", tempWrapper.path], {
256184
256236
  env: {
256185
- ...process.env,
256237
+ ...inheritedEnv(),
256238
+ ...serviceToken ? { [SERVICE_TOKEN_ENV]: serviceToken } : {},
256186
256239
  SCRIPT_PATH: scriptPath,
256187
256240
  BASE44_APP_ID: appId,
256188
256241
  BASE44_ACCESS_TOKEN: appUserToken,
@@ -256237,6 +256290,10 @@ async function execAction({ app, isNonInteractive }, options) {
256237
256290
  hints: [{ message: "Usage: base44 exec --local --port <port>" }]
256238
256291
  });
256239
256292
  }
256293
+ const envTarget = readExecEnvTarget();
256294
+ if (envTarget && options.local) {
256295
+ throw new InvalidInputError("--local cannot be used when BASE44_EXEC_ACCESS_TOKEN and BASE44_EXEC_SERVER_URL are set.");
256296
+ }
256240
256297
  const noInputError = new InvalidInputError("No input provided. Pipe a script to stdin.", {
256241
256298
  hints: [
256242
256299
  { message: "File: cat ./script.ts | base44 exec" },
@@ -256252,13 +256309,14 @@ async function execAction({ app, isNonInteractive }, options) {
256252
256309
  if (!code.trim()) {
256253
256310
  throw noInputError;
256254
256311
  }
256255
- const local = options.local ? await resolveLocalTarget(options.port !== undefined ? parsePort(options.port) : DEFAULT_DEV_SERVER_PORT) : undefined;
256312
+ const local = envTarget ? { serverUrl: envTarget.serverUrl, token: envTarget.token } : options.local ? await resolveLocalTarget(options.port !== undefined ? parsePort(options.port) : DEFAULT_DEV_SERVER_PORT) : undefined;
256256
256313
  const { exitCode } = await runScript({
256257
256314
  appId: app.id,
256258
256315
  code,
256259
256316
  local,
256260
- privileged: options.privileged,
256261
- dataEnv: options.dataEnv
256317
+ privileged: options.privileged || process.env[PRIVILEGED_ENV_VAR] !== undefined,
256318
+ dataEnv: options.dataEnv ?? process.env[DATA_ENV_ENV_VAR],
256319
+ serviceToken: envTarget?.serviceToken
256262
256320
  });
256263
256321
  if (exitCode !== 0) {
256264
256322
  process.exitCode = exitCode;
@@ -256266,7 +256324,7 @@ async function execAction({ app, isNonInteractive }, options) {
256266
256324
  return {};
256267
256325
  }
256268
256326
  function getExecCommand() {
256269
- return new Base44Command("exec").description("Run a script with the Base44 SDK pre-authenticated as the current user").option("--local", "Run against the local `base44 dev` server instead of the deployed app").option("--port <number>", `Port the local dev server is on (with --local; defaults to ${DEFAULT_DEV_SERVER_PORT})`).option("--privileged", "Run with admin privileges (bypass RLS). Requires app owner/editor role.").option("--data-env <environment>", "Data environment to run against (e.g. dev, prod)").addHelpText("after", `
256327
+ return new Base44Command("exec", { requireAuth: !hasExecEnvTarget() }).description("Run a script with the Base44 SDK pre-authenticated as the current user").option("--local", "Run against the local `base44 dev` server instead of the deployed app").option("--port <number>", `Port the local dev server is on (with --local; defaults to ${DEFAULT_DEV_SERVER_PORT})`).option("--privileged", "Run with admin privileges (bypass RLS). Requires app owner/editor role.").option("--data-env <environment>", "Data environment to run against (e.g. dev, prod)").addHelpText("after", `
256270
256328
  Examples:
256271
256329
  Run a script file:
256272
256330
  $ cat ./script.ts | base44 exec
@@ -260490,4 +260548,4 @@ export {
260490
260548
  runCLI
260491
260549
  };
260492
260550
 
260493
- //# debugId=109E5D924CF39A0264756E2164756E21
260551
+ //# debugId=03B01903A1BCF87864756E2164756E21