fix: require npm auth for dist-tag mirror

This commit is contained in:
Peter Steinberger
2026-03-31 23:13:35 +01:00
parent 4f83409345
commit d7e9d341cc
7 changed files with 152 additions and 4 deletions

View File

@@ -24,6 +24,12 @@ const CORRECTION_VERSION_REGEX =
* @property {("latest" | "beta")[]} mirrorDistTags
*/
/**
* @typedef {object} NpmDistTagMirrorAuth
* @property {boolean} hasAuth
* @property {"node-auth-token" | "npm-token" | "none"} source
*/
/**
* @param {string} version
* @param {Record<string, string | undefined>} groups
@@ -174,3 +180,24 @@ export function resolveNpmPublishPlan(version, currentBetaVersion) {
mirrorDistTags: ["beta"],
};
}
/**
* @param {{
* nodeAuthToken?: string | null | undefined;
* npmToken?: string | null | undefined;
* }} [params]
* @returns {NpmDistTagMirrorAuth}
*/
export function resolveNpmDistTagMirrorAuth(params = {}) {
const nodeAuthToken = params.nodeAuthToken?.trim();
if (nodeAuthToken) {
return { hasAuth: true, source: "node-auth-token" };
}
const npmToken = params.npmToken?.trim();
if (npmToken) {
return { hasAuth: true, source: "npm-token" };
}
return { hasAuth: false, source: "none" };
}