// src/commands/auth-creds.ts
import { readFileSync, writeFileSync, mkdirSync, unlinkSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";
function configDir() {
  return join(homedir(), ".deeplake");
}
function credsPath() {
  return join(configDir(), "credentials.json");
}
function loadCredentials() {
  try {
    return JSON.parse(readFileSync(credsPath(), "utf-8"));
  } catch {
    return null;
  }
}
function saveCredentials(creds) {
  mkdirSync(configDir(), { recursive: true, mode: 448 });
  writeFileSync(credsPath(), JSON.stringify({ ...creds, savedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2), { mode: 384 });
}
function deleteCredentials() {
  try {
    unlinkSync(credsPath());
    return true;
  } catch {
    return false;
  }
}

export {
  configDir,
  credsPath,
  loadCredentials,
  saveCredentials,
  deleteCredentials
};
