UNPKG

@posthog/wizard

Version:

The PostHog wizard helps you to configure your project

109 lines 4.07 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultMCPClient = exports.MCPClient = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const defaults_1 = require("./defaults"); const lodash_1 = require("lodash"); class MCPClient { name; } exports.MCPClient = MCPClient; class DefaultMCPClient extends MCPClient { name = 'Default'; constructor() { super(); } async isServerInstalled() { try { const configPath = await this.getConfigPath(); if (!fs.existsSync(configPath)) { return false; } const configContent = await fs.promises.readFile(configPath, 'utf8'); const config = JSON.parse(configContent); return 'mcpServers' in config && 'posthog' in config.mcpServers; } catch { return false; } } async addServer(apiKey) { try { const configPath = await this.getConfigPath(); const configDir = path.dirname(configPath); await fs.promises.mkdir(configDir, { recursive: true }); const newServerConfig = { mcpServers: { posthog: (0, defaults_1.getDefaultServerConfig)(apiKey), }, }; let existingConfig = {}; if (fs.existsSync(configPath)) { const existingContent = await fs.promises.readFile(configPath, 'utf8'); existingConfig = JSON.parse(existingContent); } const mergedConfig = (0, lodash_1.merge)({}, existingConfig, newServerConfig); await fs.promises.writeFile(configPath, JSON.stringify(mergedConfig, null, 2), 'utf8'); return { success: true }; } catch { // } return { success: false }; } async removeServer() { try { const configPath = await this.getConfigPath(); if (!fs.existsSync(configPath)) { return { success: false }; } const configContent = await fs.promises.readFile(configPath, 'utf8'); const config = JSON.parse(configContent); if ('mcpServers' in config && 'posthog' in config.mcpServers) { delete config.mcpServers.posthog; await fs.promises.writeFile(configPath, JSON.stringify(config, null, 2), 'utf8'); return { success: true }; } } catch { // } return { success: false }; } } exports.DefaultMCPClient = DefaultMCPClient; //# sourceMappingURL=MCPClient.js.map