11import fs from 'fs' ;
2+ import { logger } from "./Logger/Logger" ;
23
34/**
45 * Base configuration class for SCANOSS SDK services.
@@ -42,7 +43,7 @@ export abstract class BaseConfig {
4243 this . IGNORE_CERT_ERRORS = config . IGNORE_CERT_ERRORS ?? false ;
4344 this . API_URL = config . API_URL || BaseConfig . getDefaultURL ( ) ;
4445 }
45- this . API_URL = this . API_URL || BaseConfig . getDefaultURL ( ) ;
46+ this . API_URL = BaseConfig . getDefaultURL ( ) ;
4647 }
4748
4849 /**
@@ -69,7 +70,31 @@ export abstract class BaseConfig {
6970 * @param currentUrl - The current API URL
7071 * @returns The resolved API URL
7172 */
72- protected abstract resolveApiUrl ( apiKey : string , currentUrl : string ) : string ;
73+ /**
74+ * Resolves the appropriate scanner URL based on API key presence and current URL.
75+ * If an API key is provided and the current URL is the default, returns the premium
76+ * scanner URL, otherwise appends '/scan/direct' to the current URL.
77+ * @param apiKey - The API key (if any)
78+ * @param currentUrl - The current API URL
79+ * @returns The resolved scanner URL
80+ */
81+ protected resolveApiUrl ( apiKey : string , currentUrl : string ) : string {
82+ let url = new URL ( currentUrl ) ;
83+ if ( url . pathname !== '/' ) {
84+ logger . warn ( `Removing ${ url . pathname } from ${ currentUrl } ` ) ;
85+ currentUrl = url . origin ;
86+ }
87+ if ( ! apiKey ) {
88+ if ( currentUrl !== BaseConfig . getDefaultURL ( ) ) {
89+ return currentUrl ;
90+ }
91+ return BaseConfig . getDefaultURL ( ) ;
92+ }
93+ if ( currentUrl !== BaseConfig . getDefaultURL ( ) && currentUrl !== BaseConfig . getPremiumURL ( ) ) {
94+ return currentUrl ;
95+ }
96+ return BaseConfig . getPremiumURL ( ) ;
97+ }
7398
7499 /**
75100 * Sets the HTTPS proxy server URL.
0 commit comments