@@ -15,7 +15,8 @@ import { PackumentExtractor, type DateProvider } from "./PackumentExtractor.js";
1515import { fetchNpmAvatars } from "./fetchNpmAvatars.js" ;
1616import type {
1717 Dependency ,
18- DependencyConfusionWarning
18+ DependencyConfusionWarning ,
19+ TokenStore
1920} from "../types.js" ;
2021import { Logger } from "../class/logger.class.js" ;
2122import { getLinks } from "../utils/getLinks.js" ;
@@ -30,6 +31,7 @@ await i18n.extendFromSystemPath(
3031
3132type PackumentNpmApiOptions = {
3233 registry : string ;
34+ token ?: string ;
3335} ;
3436
3537export interface NpmApiClient {
@@ -42,12 +44,14 @@ export interface NpmRegistryProviderOptions {
4244 dateProvider ?: DateProvider ;
4345 npmApiClient ?: NpmApiClient ;
4446 registry ?: string ;
47+ tokenStore ?: TokenStore ;
4548}
4649
4750export class NpmRegistryProvider {
4851 #date: DateProvider | undefined ;
4952 #npmApiClient: NpmApiClient ;
5053 #registry: string ;
54+ #tokenStore: TokenStore | undefined ;
5155
5256 name : string ;
5357 version : string ;
@@ -60,7 +64,8 @@ export class NpmRegistryProvider {
6064 const {
6165 dateProvider = undefined ,
6266 npmApiClient = npmRegistrySDK ,
63- registry = npmRegistrySDK . getLocalRegistryURL ( )
67+ registry = npmRegistrySDK . getLocalRegistryURL ( ) ,
68+ tokenStore = undefined
6469 } = options ;
6570
6671 this . name = name ;
@@ -69,14 +74,16 @@ export class NpmRegistryProvider {
6974 this . #date = dateProvider ;
7075 this . #npmApiClient = npmApiClient ;
7176 this . #registry = registry ;
77+ this . #tokenStore = tokenStore ;
7278 }
7379
7480 async collectPackageVersionData ( ) {
7581 const packumentVersion = await this . #npmApiClient. packumentVersion (
7682 this . name ,
7783 this . version ,
7884 {
79- registry : this . #registry
85+ registry : this . #registry,
86+ token : this . #tokenStore?. get ( this . #registry)
8087 }
8188 ) ;
8289
@@ -95,7 +102,8 @@ export class NpmRegistryProvider {
95102
96103 async collectPackageData ( ) {
97104 const packument = await this . #npmApiClient. packument ( this . name , {
98- registry : this . #registry
105+ registry : this . #registry,
106+ token : this . #tokenStore?. get ( this . #registry)
99107 } ) ;
100108 const packumentVersion = packument . versions [ this . version ] ;
101109
@@ -167,7 +175,8 @@ export class NpmRegistryProvider {
167175 }
168176 try {
169177 const packumentVersionFromPublicRegistry = await this . #npmApiClient. packumentVersion ( this . name , this . version , {
170- registry : getNpmRegistryURL ( )
178+ registry : getNpmRegistryURL ( ) ,
179+ token : this . #tokenStore?. get ( getNpmRegistryURL ( ) )
171180 } ) ;
172181 if ( ! this . #hasSameSignatures( signatures , packumentVersionFromPublicRegistry . dist . signatures ) ) {
173182 this . #addDependencyConfusionWarning( warnings , await i18n . getToken ( "scanner.dependency_confusion" ) ) ;
0 commit comments