// src/lib/config.ts
var COOKIE_NAMES = {
  /** Encrypted session data (userId, privateKey, keyId, algorithm) */
  SESSION: "spfn_session",
  /** Current key ID (for key rotation) */
  SESSION_KEY_ID: "spfn_session_key_id"
};
function parseDuration(duration) {
  if (typeof duration === "number") {
    return duration;
  }
  const match = duration.match(/^(\d+)([dhms]?)$/);
  if (!match) {
    throw new Error(`Invalid duration format: ${duration}. Use format like '30d', '12h', '45m', '3600s', or plain number.`);
  }
  const value = parseInt(match[1], 10);
  const unit = match[2] || "s";
  switch (unit) {
    case "d":
      return value * 24 * 60 * 60;
    case "h":
      return value * 60 * 60;
    case "m":
      return value * 60;
    case "s":
      return value;
    default:
      throw new Error(`Unknown duration unit: ${unit}`);
  }
}
var globalConfig = {
  sessionTtl: "7d"
  // Default: 7 days
};
function configureAuth(config) {
  globalConfig = {
    ...globalConfig,
    ...config
  };
}
function getAuthConfig() {
  return { ...globalConfig };
}
function getSessionTtl(override) {
  if (override !== void 0) {
    return parseDuration(override);
  }
  if (globalConfig.sessionTtl !== void 0) {
    return parseDuration(globalConfig.sessionTtl);
  }
  const envTtl = process.env.SPFN_AUTH_SESSION_TTL;
  if (envTtl) {
    return parseDuration(envTtl);
  }
  return 7 * 24 * 60 * 60;
}
export {
  COOKIE_NAMES,
  configureAuth,
  getAuthConfig,
  getSessionTtl,
  parseDuration
};
//# sourceMappingURL=config.js.map