mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-05 13:29:44 +02:00
Phase 1: Monorepo infrastructure - Add Turborepo with turbo.json pipeline (build, dev, typecheck, test) - Update pnpm-workspace.yaml to include packages/* - Create shared TypeScript config (packages/tsconfig) Phase 2: Extract packages/core (zero react-dom, all-platform reuse) - Move domain types, API client, logger, utils → packages/core/ - Move TanStack Query modules (issues, inbox, workspace, runtimes) - Move Zustand stores (auth, workspace, issues, navigation, modals) - Move realtime sync (WSProvider, hooks, ws-updaters) - Refactor auth/workspace stores to factory pattern for DI - Refactor ApiClient with onUnauthorized callback - Refactor useWorkspaceId to React Context (WorkspaceIdProvider) - Refactor WSProvider to accept wsUrl + store props - Create apps/web/platform/ bridge layer (api singleton, store instances) - Update 91 import paths across apps/web/ - Fix 3 test files for new import paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
30 lines
927 B
TypeScript
30 lines
927 B
TypeScript
import { ApiClient } from "@multica/core/api/client";
|
|
import { setApiInstance } from "@multica/core/api";
|
|
import { createLogger } from "@multica/core/logger";
|
|
|
|
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "";
|
|
|
|
export const api = new ApiClient(API_BASE_URL, {
|
|
logger: createLogger("api"),
|
|
onUnauthorized: () => {
|
|
if (typeof window !== "undefined") {
|
|
localStorage.removeItem("multica_token");
|
|
localStorage.removeItem("multica_workspace_id");
|
|
if (window.location.pathname !== "/") {
|
|
window.location.href = "/";
|
|
}
|
|
}
|
|
},
|
|
});
|
|
|
|
// Register as the global singleton for @multica/core queries/mutations
|
|
setApiInstance(api);
|
|
|
|
// Hydrate from localStorage
|
|
if (typeof window !== "undefined") {
|
|
const token = localStorage.getItem("multica_token");
|
|
if (token) api.setToken(token);
|
|
const wsId = localStorage.getItem("multica_workspace_id");
|
|
if (wsId) api.setWorkspaceId(wsId);
|
|
}
|