UNPKG

@nodesecure/scanner

Version:

A package API to run a static analysis of your module's dependencies.

38 lines 1.22 kB
// Import Internal Dependencies import {} from "../types.js"; export class RegistryTokenStore { #memo = new Map(); #config; #tokenFromEnv; #npmRcEntries; constructor(config, tokenFromEnv, npmRcEntries = {}) { this.#config = config; this.#tokenFromEnv = tokenFromEnv; this.#npmRcEntries = npmRcEntries; } get(registry) { if (!this.#config) { const tokenKey = this.getTokenKey(registry); if (tokenKey in this.#npmRcEntries) { return this.#npmRcEntries[tokenKey]; } return this.#tokenFromEnv; } if (this.#memo.has(registry)) { return this.#memo.get(registry); } const token = this.#config.get(this.getTokenKey(registry), "project") ?? this.#tokenFromEnv; this.#memo.set(registry, token); return token; } getConfig(registry) { return this.#config ? { [this.getKey(registry)]: this.get(registry) } : {}; } getTokenKey(registry) { return `${this.getKey(registry)}:_authToken`; } getKey(registry) { return registry.replace(/https:|http:/, ""); } } //# sourceMappingURL=RegistryTokenStore.js.map