diff --git a/src/cli/commands/agents/pull.ts b/src/cli/commands/agents/pull.ts index 282bec85..f5206d0f 100644 --- a/src/cli/commands/agents/pull.ts +++ b/src/cli/commands/agents/pull.ts @@ -2,13 +2,12 @@ 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 { - const { project } = await readProjectConfig(); +async function pullAgentsAction(sdk: ProjectSDK): Promise { + const { project } = await sdk.project.readConfig(); const configDir = dirname(project.configPath); const agentsDir = join(configDir, project.agentsDir); @@ -16,7 +15,7 @@ async function pullAgentsAction(): Promise { const remoteAgents = await runTask( "Fetching agents from Base44", async () => { - return await fetchAgents(); + return await sdk.agents.fetch(); }, { successMessage: "Agents fetched successfully", @@ -31,7 +30,7 @@ async function pullAgentsAction(): Promise { 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", diff --git a/src/cli/commands/agents/push.ts b/src/cli/commands/agents/push.ts index 8a55032d..ef9eb5e2 100644 --- a/src/cli/commands/agents/push.ts +++ b/src/cli/commands/agents/push.ts @@ -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 { - const { agents } = await readProjectConfig(); +async function pushAgentsAction(sdk: ProjectSDK): Promise { + const { agents } = await sdk.project.readConfig(); log.info( agents.length === 0 @@ -18,7 +17,7 @@ async function pushAgentsAction(): Promise { const result = await runTask( "Pushing agents to Base44", async () => { - return await pushAgents(agents); + return await sdk.agents.push(agents); }, { successMessage: "Agents pushed successfully", diff --git a/src/cli/commands/auth/login-flow.ts b/src/cli/commands/auth/login-flow.ts index 261a4fc0..fc167d83 100644 --- a/src/cli/commands/auth/login-flow.ts +++ b/src/cli/commands/auth/login-flow.ts @@ -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 { +async function generateAndDisplayDeviceCode( + sdk: ProjectSDK +): Promise { const deviceCodeResponse = await runTask( "Generating device code...", async () => { - return await generateDeviceCode(); + return await sdk.auth.generateDeviceCode(); }, { successMessage: "Device code generated", @@ -36,6 +33,7 @@ async function generateAndDisplayDeviceCode(): Promise { } async function waitForAuthentication( + sdk: ProjectSDK, deviceCode: string, expiresIn: number, interval: number @@ -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; @@ -81,12 +79,13 @@ async function waitForAuthentication( } async function saveAuthData( + sdk: ProjectSDK, response: TokenResponse, userInfo: UserInfoResponse ): Promise { const expiresAt = Date.now() + response.expiresIn * 1000; - await writeAuth({ + await sdk.auth.write({ accessToken: response.accessToken, refreshToken: response.refreshToken, expiresAt, @@ -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 { - const deviceCodeResponse = await generateAndDisplayDeviceCode(); +export async function login(sdk: ProjectSDK): Promise { + 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)}`, diff --git a/src/cli/commands/auth/logout.ts b/src/cli/commands/auth/logout.ts index 540c15fd..3d1027ea 100644 --- a/src/cli/commands/auth/logout.ts +++ b/src/cli/commands/auth/logout.ts @@ -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 { - await deleteAuth(); +async function logout(sdk: ProjectSDK): Promise { + await sdk.auth.delete(); return { outroMessage: "Logged out successfully" }; } diff --git a/src/cli/commands/auth/whoami.ts b/src/cli/commands/auth/whoami.ts index a1d9f77c..57f398f4 100644 --- a/src/cli/commands/auth/whoami.ts +++ b/src/cli/commands/auth/whoami.ts @@ -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 { - const auth = await readAuth(); +async function whoami(sdk: ProjectSDK): Promise { + const auth = await sdk.auth.read(); return { outroMessage: `Logged in as: ${theme.styles.bold(auth.email)}` }; } diff --git a/src/cli/commands/dashboard/open.ts b/src/cli/commands/dashboard/open.ts index b0b6018b..9e95bbc2 100644 --- a/src/cli/commands/dashboard/open.ts +++ b/src/cli/commands/dashboard/open.ts @@ -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 { - const dashboardUrl = getDashboardUrl(); +async function openDashboard(sdk: ProjectSDK): Promise { + const appId = sdk.project.getAppConfig().id; + const dashboardUrl = getDashboardUrl(appId); if (!process.env.CI) { await open(dashboardUrl); diff --git a/src/cli/commands/entities/push.ts b/src/cli/commands/entities/push.ts index 7b08da72..40ca978e 100644 --- a/src/cli/commands/entities/push.ts +++ b/src/cli/commands/entities/push.ts @@ -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 { - const { entities } = await readProjectConfig(); +async function pushEntitiesAction(sdk: ProjectSDK): Promise { + const { entities } = await sdk.project.readConfig(); if (entities.length === 0) { return { outroMessage: "No entities found in project" }; @@ -19,7 +18,7 @@ async function pushEntitiesAction(): Promise { const result = await runTask( "Pushing entities to Base44", async () => { - return await pushEntities(entities); + return await sdk.entities.push(entities); }, { successMessage: "Entities pushed successfully", diff --git a/src/cli/commands/functions/deploy.ts b/src/cli/commands/functions/deploy.ts index 1c5fa797..7ed7a96a 100644 --- a/src/cli/commands/functions/deploy.ts +++ b/src/cli/commands/functions/deploy.ts @@ -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 { - const { functions } = await readProjectConfig(); +async function deployFunctionsAction( + sdk: ProjectSDK +): Promise { + const { functions } = await sdk.project.readConfig(); if (functions.length === 0) { return { @@ -24,7 +25,7 @@ async function deployFunctionsAction(): Promise { const result = await runTask( "Deploying functions to Base44", async () => { - return await pushFunctions(functions); + return await sdk.functions.push(functions); }, { successMessage: "Functions deployed successfully", diff --git a/src/cli/commands/project/create.ts b/src/cli/commands/project/create.ts index ea1a26a8..870f6fd9 100644 --- a/src/cli/commands/project/create.ts +++ b/src/cli/commands/project/create.ts @@ -14,14 +14,7 @@ import { } from "@/cli/utils/index.js"; import type { RunCommandResult } from "@/cli/utils/runCommand.js"; import { InvalidInputError } from "@/core/errors.js"; -import { deploySite, isDirEmpty, pushEntities } from "@/core/index.js"; -import type { Template } from "@/core/project/index.js"; -import { - createProjectFiles, - listTemplates, - readProjectConfig, - setAppConfig, -} from "@/core/project/index.js"; +import type { ProjectSDK, Template } from "@/core/sdk.js"; const DEFAULT_TEMPLATE_ID = "backend-only"; @@ -33,8 +26,11 @@ interface CreateOptions { skills?: boolean; } -async function getTemplateById(templateId: string): Promise