// packages/skill-shared/src/auth/refresher.ts
import axios from 'axios';
import { NotAuthenticatedError } from '../errors.js';
import { ERPLOGIN_PATH } from './constants.js';
export async function refreshCookieAndUserInfo(apiUrl, key) {
    if (!key)
        throw new NotAuthenticatedError();
    const url = `${apiUrl.replace(/\/+$/, '')}${ERPLOGIN_PATH}`;
    const res = await axios.post(url, null, {
        headers: { 'client-type': 'cli' },
        params: { key },
    });
    const setCookieHeader = res.headers['set-cookie'] ?? [];
    if (setCookieHeader.length === 0)
        throw new NotAuthenticatedError();
    if (!res.data?.success || !res.data?.obj)
        throw new NotAuthenticatedError();
    return {
        cookie: setCookieHeader.join('; '),
        userInfo: res.data.obj,
    };
}
//# sourceMappingURL=refresher.js.map