import { resetUserExpiryWithType, setExternalReference, setUser } from "./set-user.js";
import { getExternalUser } from "./get-user.js";
export async function addUser(data) {
    return setUser(data);
}
export async function addExternalUser(data, existingUser) {
    const { externalId, externalType, ...rest } = data;
    let user = existingUser ?? await addUser({
        ...rest,
        externalType,
    });
    if (existingUser && user.externalType !== externalType && user.externalType === "anonymous") {
        user = await resetUserExpiryWithType(user, externalType);
    }
    await setExternalReference({
        externalType,
        externalId,
        userId: user.userId,
        expiresAt: user.expiresAt,
    });
    return user;
}
export async function addAnonymousUser() {
    const user = await addUser({
        externalType: "anonymous",
    });
    await getExternalUser(user.externalType, user.userId, user);
    return user;
}
//# sourceMappingURL=add-user.js.map