Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/cli/commands/agents/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import { dirname, join } from "node:path";
import { log } from "@clack/prompts";
import { Command } from "commander";
import type { CLIContext } from "@/cli/types.js";
import { readProjectConfig } from "@/core/index.js";
import { fetchAgents, writeAgents } from "@/core/resources/agent/index.js";
import type { ProjectSDK } from "@/core/sdk.js";
import { runCommand, runTask } from "../../utils/index.js";
import type { RunCommandResult } from "../../utils/runCommand.js";

async function pullAgentsAction(): Promise<RunCommandResult> {
const { project } = await readProjectConfig();
async function pullAgentsAction(sdk: ProjectSDK): Promise<RunCommandResult> {
const { project } = await sdk.project.readConfig();

const configDir = dirname(project.configPath);
const agentsDir = join(configDir, project.agentsDir);

const remoteAgents = await runTask(
"Fetching agents from Base44",
async () => {
return await fetchAgents();
return await sdk.agents.fetch();
},
{
successMessage: "Agents fetched successfully",
Expand All @@ -31,7 +30,7 @@ async function pullAgentsAction(): Promise<RunCommandResult> {
const { written, deleted } = await runTask(
"Writing agent files",
async () => {
return await writeAgents(agentsDir, remoteAgents.items);
return await sdk.agents.writeLocal(agentsDir, remoteAgents.items);
},
{
successMessage: "Agent files written successfully",
Expand Down
9 changes: 4 additions & 5 deletions src/cli/commands/agents/push.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { log } from "@clack/prompts";
import { Command } from "commander";
import type { CLIContext } from "@/cli/types.js";
import { readProjectConfig } from "@/core/index.js";
import { pushAgents } from "@/core/resources/agent/index.js";
import type { ProjectSDK } from "@/core/sdk.js";
import { runCommand, runTask } from "../../utils/index.js";
import type { RunCommandResult } from "../../utils/runCommand.js";

async function pushAgentsAction(): Promise<RunCommandResult> {
const { agents } = await readProjectConfig();
async function pushAgentsAction(sdk: ProjectSDK): Promise<RunCommandResult> {
const { agents } = await sdk.project.readConfig();

log.info(
agents.length === 0
Expand All @@ -18,7 +17,7 @@ async function pushAgentsAction(): Promise<RunCommandResult> {
const result = await runTask(
"Pushing agents to Base44",
async () => {
return await pushAgents(agents);
return await sdk.agents.push(agents);
},
{
successMessage: "Agents pushed successfully",
Expand Down
30 changes: 15 additions & 15 deletions src/cli/commands/auth/login-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import type { RunCommandResult } from "@/cli/utils/runCommand.js";
import { theme } from "@/cli/utils/theme.js";
import type {
DeviceCodeResponse,
ProjectSDK,
TokenResponse,
UserInfoResponse,
} from "@/core/auth/index.js";
import {
generateDeviceCode,
getTokenFromDeviceCode,
getUserInfo,
writeAuth,
} from "@/core/auth/index.js";
} from "@/core/sdk.js";

async function generateAndDisplayDeviceCode(): Promise<DeviceCodeResponse> {
async function generateAndDisplayDeviceCode(
sdk: ProjectSDK
): Promise<DeviceCodeResponse> {
const deviceCodeResponse = await runTask(
"Generating device code...",
async () => {
return await generateDeviceCode();
return await sdk.auth.generateDeviceCode();
},
{
successMessage: "Device code generated",
Expand All @@ -36,6 +33,7 @@ async function generateAndDisplayDeviceCode(): Promise<DeviceCodeResponse> {
}

async function waitForAuthentication(
sdk: ProjectSDK,
deviceCode: string,
expiresIn: number,
interval: number
Expand All @@ -48,7 +46,7 @@ async function waitForAuthentication(
async () => {
await pWaitFor(
async () => {
const result = await getTokenFromDeviceCode(deviceCode);
const result = await sdk.auth.getTokenFromDeviceCode(deviceCode);
if (result !== null) {
tokenResponse = result;
return true;
Expand Down Expand Up @@ -81,12 +79,13 @@ async function waitForAuthentication(
}

async function saveAuthData(
sdk: ProjectSDK,
response: TokenResponse,
userInfo: UserInfoResponse
): Promise<void> {
const expiresAt = Date.now() + response.expiresIn * 1000;

await writeAuth({
await sdk.auth.write({
accessToken: response.accessToken,
refreshToken: response.refreshToken,
expiresAt,
Expand All @@ -99,18 +98,19 @@ async function saveAuthData(
* Execute the login flow (device code authentication).
* This function is separate from the command to avoid circular dependencies.
*/
export async function login(): Promise<RunCommandResult> {
const deviceCodeResponse = await generateAndDisplayDeviceCode();
export async function login(sdk: ProjectSDK): Promise<RunCommandResult> {
const deviceCodeResponse = await generateAndDisplayDeviceCode(sdk);

const token = await waitForAuthentication(
sdk,
deviceCodeResponse.deviceCode,
deviceCodeResponse.expiresIn,
deviceCodeResponse.interval
);

const userInfo = await getUserInfo(token.accessToken);
const userInfo = await sdk.auth.getUserInfo(token.accessToken);

await saveAuthData(token, userInfo);
await saveAuthData(sdk, token, userInfo);

return {
outroMessage: `Successfully logged in as ${theme.styles.bold(userInfo.email)}`,
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/auth/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Command } from "commander";
import type { CLIContext } from "@/cli/types.js";
import { runCommand } from "@/cli/utils/index.js";
import type { RunCommandResult } from "@/cli/utils/runCommand.js";
import { deleteAuth } from "@/core/auth/index.js";
import type { ProjectSDK } from "@/core/sdk.js";

async function logout(): Promise<RunCommandResult> {
await deleteAuth();
async function logout(sdk: ProjectSDK): Promise<RunCommandResult> {
await sdk.auth.delete();
return { outroMessage: "Logged out successfully" };
}

Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/auth/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Command } from "commander";
import type { CLIContext } from "@/cli/types.js";
import { runCommand, theme } from "@/cli/utils/index.js";
import type { RunCommandResult } from "@/cli/utils/runCommand.js";
import { readAuth } from "@/core/auth/index.js";
import type { ProjectSDK } from "@/core/sdk.js";

async function whoami(): Promise<RunCommandResult> {
const auth = await readAuth();
async function whoami(sdk: ProjectSDK): Promise<RunCommandResult> {
const auth = await sdk.auth.read();
return { outroMessage: `Logged in as: ${theme.styles.bold(auth.email)}` };
}

Expand Down
6 changes: 4 additions & 2 deletions src/cli/commands/dashboard/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import open from "open";
import type { CLIContext } from "@/cli/types.js";
import { getDashboardUrl, runCommand } from "@/cli/utils/index.js";
import type { RunCommandResult } from "@/cli/utils/runCommand.js";
import type { ProjectSDK } from "@/core/sdk.js";

async function openDashboard(): Promise<RunCommandResult> {
const dashboardUrl = getDashboardUrl();
async function openDashboard(sdk: ProjectSDK): Promise<RunCommandResult> {
const appId = sdk.project.getAppConfig().id;
const dashboardUrl = getDashboardUrl(appId);

if (!process.env.CI) {
await open(dashboardUrl);
Expand Down
9 changes: 4 additions & 5 deletions src/cli/commands/entities/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Command } from "commander";
import type { CLIContext } from "@/cli/types.js";
import { runCommand, runTask } from "@/cli/utils/index.js";
import type { RunCommandResult } from "@/cli/utils/runCommand.js";
import { readProjectConfig } from "@/core/index.js";
import { pushEntities } from "@/core/resources/entity/index.js";
import type { ProjectSDK } from "@/core/sdk.js";

async function pushEntitiesAction(): Promise<RunCommandResult> {
const { entities } = await readProjectConfig();
async function pushEntitiesAction(sdk: ProjectSDK): Promise<RunCommandResult> {
const { entities } = await sdk.project.readConfig();

if (entities.length === 0) {
return { outroMessage: "No entities found in project" };
Expand All @@ -19,7 +18,7 @@ async function pushEntitiesAction(): Promise<RunCommandResult> {
const result = await runTask(
"Pushing entities to Base44",
async () => {
return await pushEntities(entities);
return await sdk.entities.push(entities);
},
{
successMessage: "Entities pushed successfully",
Expand Down
11 changes: 6 additions & 5 deletions src/cli/commands/functions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import type { CLIContext } from "@/cli/types.js";
import { runCommand, runTask } from "@/cli/utils/index.js";
import type { RunCommandResult } from "@/cli/utils/runCommand.js";
import { ApiError } from "@/core/errors.js";
import { readProjectConfig } from "@/core/index.js";
import { pushFunctions } from "@/core/resources/function/index.js";
import type { ProjectSDK } from "@/core/sdk.js";

async function deployFunctionsAction(): Promise<RunCommandResult> {
const { functions } = await readProjectConfig();
async function deployFunctionsAction(
sdk: ProjectSDK
): Promise<RunCommandResult> {
const { functions } = await sdk.project.readConfig();

if (functions.length === 0) {
return {
Expand All @@ -24,7 +25,7 @@ async function deployFunctionsAction(): Promise<RunCommandResult> {
const result = await runTask(
"Deploying functions to Base44",
async () => {
return await pushFunctions(functions);
return await sdk.functions.push(functions);
},
{
successMessage: "Functions deployed successfully",
Expand Down
Loading
Loading