"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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.configPath = exports.resolveConfig = exports.writeConfigFile = exports.readConfigFile = exports.DEFAULT_ENDPOINT = void 0; /** * Config storage for inkreach-teable CLI. * * Stores endpoint + token at ~/.inkreach-teable/config.json, with environment variable * overrides INKREACH_TEABLE_ENDPOINT / INKREACH_TEABLE_TOKEN. The --endpoint / --token / --base-id * global flags take the highest precedence (handled by resolveOptions()). */ const fs = __importStar(require("node:fs")); const path = __importStar(require("node:path")); const os = __importStar(require("node:os")); const CONFIG_DIR = path.join(os.homedir(), '.inkreach-teable'); const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json'); exports.DEFAULT_ENDPOINT = 'http://localhost:3000'; function readConfigFile() { try { const raw = fs.readFileSync(CONFIG_FILE, 'utf8'); return JSON.parse(raw); } catch { return {}; } } exports.readConfigFile = readConfigFile; function writeConfigFile(cfg) { if (!fs.existsSync(CONFIG_DIR)) { fs.mkdirSync(CONFIG_DIR, { recursive: true }); } const merged = { ...readConfigFile(), ...cfg }; fs.writeFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2) + '\n', { mode: 0o600 }); } exports.writeConfigFile = writeConfigFile; function resolveConfig(overrides) { const file = readConfigFile(); return { endpoint: overrides?.endpoint || process.env.INKREACH_TEABLE_ENDPOINT || file.endpoint || exports.DEFAULT_ENDPOINT, token: overrides?.token || process.env.INKREACH_TEABLE_TOKEN || file.token || '', baseId: overrides?.baseId || process.env.INKREACH_TEABLE_BASE_ID || file.baseId, }; } exports.resolveConfig = resolveConfig; function configPath() { return CONFIG_FILE; } exports.configPath = configPath;