@codacy/analysis-runner 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +96 -31
  2. package/dist/index.js +1360 -1017
  3. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -410,9 +410,14 @@ declare function parseAutoFilters(raw: string): {
410
410
  * The generated client (src/api/client/) is produced from the Codacy OpenAPI spec
411
411
  * and should never be edited by hand. All API interactions go through this file.
412
412
  *
413
- * Authentication: Codacy uses an `api-token` header (not Bearer). We set it via
414
- * `OpenAPI.HEADERS` before each call group. `configureApiToken()` must be called
415
- * before any authenticated endpoint is used.
413
+ * Authentication: Codacy uses an `api-token` header (account token) or a
414
+ * `project-token` header (repository token). `configureApiToken()`
415
+ * sets exactly one via `OpenAPI.HEADERS` and must be called before any
416
+ * authenticated endpoint is used. Most operations only accept `api-token`; a
417
+ * small whitelisted subset of repository-scoped reads (`getRepository`,
418
+ * `listRepositoryTools`, `listRepositoryToolPatterns`, `listIgnoredFiles`) also
419
+ * accept `project-token` — the backend rejects it everywhere else exactly as
420
+ * if no token had been sent.
416
421
  *
417
422
  * Pagination: all list endpoints use cursor-based pagination. `fetchAllPages()`
418
423
  * follows cursors until the response contains no next cursor.
@@ -428,12 +433,41 @@ interface IgnoredFilesResult {
428
433
  capped: boolean;
429
434
  }
430
435
  /**
431
- * Configures the API token used for authenticated requests.
432
- * Must be called before `getRepository`, `listRepositoryTools`, or
433
- * `listRepositoryToolPatterns`. Public endpoints (listTools, listPatterns)
434
- * do not require a token.
436
+ * Auth for API calls that accept either an account token or a repository
437
+ * (project) token — currently only the 4 reads `initRemoteConfig` makes. A
438
+ * discriminated union (same shape and naming as `UploadAuth` in `upload.ts`)
439
+ * so "exactly one token" is a compile-time guarantee, not a runtime check,
440
+ * and so there is never a "both configured" state for the backend to have to
441
+ * arbitrate — sending both was never useful anyway, since the backend always
442
+ * prefers `api-token` when both are present.
435
443
  */
436
- declare function configureApiToken(token: string): void;
444
+ type RemoteAuth = {
445
+ kind: "account-token";
446
+ token: string;
447
+ } | {
448
+ kind: "repository-token";
449
+ token: string;
450
+ };
451
+ /**
452
+ * Configures the auth header used for authenticated requests. Must be called
453
+ * before `getRepository`, `listRepositoryTools`, `listRepositoryToolPatterns`,
454
+ * or `listIgnoredFiles`. Public endpoints (listTools, listPatterns) do not
455
+ * require a token.
456
+ *
457
+ * Accepts a bare account-token string, for source compatibility with this
458
+ * function's original `(token: string)` shape — this is a published package,
459
+ * and embedders (a VSCode extension, an MCP server) call it directly with a
460
+ * bare string — or a {@link RemoteAuth} object to configure a repository
461
+ * token instead. Throws if given neither a non-empty string nor a valid
462
+ * `RemoteAuth`, rather than silently configuring no auth at all.
463
+ *
464
+ * Fully replaces any previously configured auth — it does not merge with a
465
+ * prior call. A process driving multiple auth contexts (e.g. an embedder
466
+ * juggling an account token for one repository and a project token for
467
+ * another) must call this again immediately before each authenticated call
468
+ * group, the same way `initRemoteConfig` does internally.
469
+ */
470
+ declare function configureApiToken(auth: string | RemoteAuth): void;
437
471
  /**
438
472
  * Validates an API token by calling the authenticated user endpoint.
439
473
  * Returns user info on success; caller should catch errors for invalid tokens.
@@ -447,7 +481,8 @@ declare function validateApiToken(token: string): Promise<{
447
481
  * Fetches files individually ignored in Codacy Cloud for a repository.
448
482
  * Uses cursor-based pagination capped at 10 pages (1000 files max) to avoid
449
483
  * unbounded fetching for repositories with very large ignore lists.
450
- * Requires `configureApiToken()` to have been called.
484
+ * Requires `configureApiToken()` to have been called with an account token
485
+ * or a repository (project) token — this operation accepts either.
451
486
  */
452
487
  declare function listIgnoredFiles(provider: string, org: string, repo: string): Promise<IgnoredFilesResult>;
453
488
 
@@ -557,6 +592,13 @@ interface InitRemoteStats {
557
592
  * as unsupported (cloud-only) entries (subject to the trackability filter — deprecated and
558
593
  * client-side/standalone-only tools are skipped).
559
594
  *
595
+ * @param auth - Account token or repository (project) token — a repository token alone
596
+ * is enough for all four API calls this function makes, no login required. Also
597
+ * accepts a bare account-token string, for source compatibility with callers written
598
+ * against this function's original `apiToken: string` shape — this parameter used to
599
+ * be exactly that, and this is a published package (embedders like a VSCode extension
600
+ * or MCP server call it directly), so the old call shape must keep working unchanged.
601
+ * See {@link configureApiToken} for the exact accepted shapes and validation.
560
602
  * @param onRemoteToolsFound - Optional callback invoked once after the list of enabled
561
603
  * remote tools is fetched. Receives the total count of enabled tools and the count
562
604
  * that have a registered local adapter. Fires before per-tool pattern fetching begins.
@@ -566,7 +608,7 @@ interface InitRemoteStats {
566
608
  * @param onIgnoredFilesFetched - Optional callback invoked after cloud-ignored files are
567
609
  * fetched. Receives the count and whether the 1000-file cap was reached.
568
610
  */
569
- declare function initRemoteConfig(repositoryRoot: string, provider: string, organization: string, repositoryName: string, adapters: Readonly<ToolAdapter>[], apiToken: string, onRemoteToolsFound?: (totalEnabledTools: number, matchedAdapters: number) => void, onToolProcessed?: (displayName: string, patternCount: number, usesConfigFile: boolean) => void, onIgnoredFilesFetched?: (count: number, capped: boolean) => void): Promise<{
611
+ declare function initRemoteConfig(repositoryRoot: string, provider: string, organization: string, repositoryName: string, adapters: Readonly<ToolAdapter>[], auth: string | RemoteAuth, onRemoteToolsFound?: (totalEnabledTools: number, matchedAdapters: number) => void, onToolProcessed?: (displayName: string, patternCount: number, usesConfigFile: boolean) => void, onIgnoredFilesFetched?: (count: number, capped: boolean) => void): Promise<{
570
612
  config: CodacyConfig;
571
613
  stats: InitRemoteStats;
572
614
  }>;
@@ -852,6 +894,7 @@ declare function createLogger(options?: LoggerOptions): Logger;
852
894
  *
853
895
  * All crypto uses Node.js built-in `crypto` — no external dependencies.
854
896
  */
897
+
855
898
  /**
856
899
  * Encrypts and saves an API token to ~/.codacy/credentials.
857
900
  * Creates the ~/.codacy/ directory if it doesn't exist.
@@ -876,6 +919,41 @@ declare function deleteCredentials(): Promise<boolean>;
876
919
  * 3. Throws with instructions if neither source has a token.
877
920
  */
878
921
  declare function resolveApiToken(): Promise<string>;
922
+ /**
923
+ * Resolves auth for `init --remote` / `update-config --remote`: an explicit
924
+ * repository token (`repositoryToken` argument, or `CODACY_PROJECT_TOKEN`)
925
+ * wins outright — matching `upload`'s precedence for the same flag
926
+ * (`upload.ts:87-90`) — without even attempting to resolve an account token,
927
+ * so an explicitly-scoped run never pays the cost of loading a stored login
928
+ * it didn't ask for, and is never silently re-scoped to a broader token an
929
+ * ambient `CODACY_API_TOKEN` or prior `login` happens to leave lying around.
930
+ * Only when no repository token is given does this fall back to an account
931
+ * token, read the same way {@link resolveApiToken} does (env var, then
932
+ * stored credentials) — inlined here rather than calling it, so a missing
933
+ * account token falls through to the error below instead of throwing.
934
+ */
935
+ declare function resolveRemoteAuth(repositoryToken?: string): Promise<RemoteAuth>;
936
+
937
+ /**
938
+ * Turning a raw manifest identifier into an entity.
939
+ *
940
+ * Classification is **scoped to the ecosystem the identifier came from**, with no
941
+ * global fallback. A fallback is the bug this module exists to prevent: with one
942
+ * name-keyed catalog, the sbt artifact `requests` (com.lihaoyi) matched PyPI's
943
+ * Requests, and any bare gem or crate name could borrow another language's
944
+ * package. An artifact id is only meaningful inside its own registry, so that is
945
+ * the only place it is looked up.
946
+ */
947
+
948
+ /**
949
+ * Display names of every entity discovery can emit.
950
+ *
951
+ * Kept for consumers that report on the catalog. Note it is **not** the set of
952
+ * gating keys — those are entity keys ({@link getEntityProviders}) — precisely
953
+ * because display names are not unique: Angular 2+, AngularJS and AngularDart all
954
+ * display as "Angular".
955
+ */
956
+ declare function getKnownDisplayNames(): Set<string>;
879
957
 
880
958
  /**
881
959
  * Repository discovery — scans a codebase and identifies languages, file patterns,
@@ -884,8 +962,12 @@ declare function resolveApiToken(): Promise<string>;
884
962
  * The discover() function is the main entry point. It runs a 4-phase pipeline:
885
963
  * 1. File discovery (extensions, notable files)
886
964
  * 2. Language detection (reuses detectLanguages)
887
- * 3. Manifest parsing (dependency extraction)
888
- * 4. Dependency classification (framework / library / platform / tool)
965
+ * 3. Manifest parsing (dependency extraction, per owning ecosystem)
966
+ * 4. Classification (raw identifier → entity, scoped to that ecosystem)
967
+ *
968
+ * The static knowledge behind phases 3 and 4 lives in `./ecosystems/` (one module
969
+ * per package registry), `./signals.ts` and `./notable-files.ts`; the entity
970
+ * vocabulary itself is in `@codacy/tooling`.
889
971
  */
890
972
 
891
973
  /** Options for the discover function. */
@@ -897,7 +979,7 @@ interface DiscoverOptions {
897
979
  *
898
980
  * Callers that feed discovery into configuration decisions **must** pass the
899
981
  * same excludes `analyze` will apply (see `resolveDiscoveryExcludes` in
900
- * `./codacy-yaml`). Otherwise discovery reports languages, frameworks, and
982
+ * `../codacy-yaml`). Otherwise discovery reports languages, frameworks, and
901
983
  * libraries that only exist in excluded paths — e.g. a tool-orchestration
902
984
  * monorepo whose per-language sample files all live under
903
985
  * `**\/test/fixtures/**` looks like a 20-language polyglot repo, and every
@@ -911,23 +993,6 @@ interface DiscoverOptions {
911
993
  */
912
994
  declare function discover(repositoryRoot: string, options?: DiscoverOptions): Promise<DiscoveryResult>;
913
995
 
914
- /**
915
- * Discovery catalog — static knowledge base for the discover command.
916
- *
917
- * Contains manifest file parsers, a curated dependency classification catalog,
918
- * and notable file detection rules. All parsers are pure functions that accept
919
- * raw file content and return dependency name arrays. They never throw.
920
- */
921
-
922
- /**
923
- * Every display name discovery can emit from a dependency/file/package.json signal.
924
- * This is the authoritative set a framework-mapping key must belong to (together
925
- * with detected language names) for its patterns to ever gate on. The drift-guard
926
- * test uses it to catch mapping keys that no signal can produce (e.g. a rename
927
- * like react-intl → formatjs that updates the mapping but not the catalog).
928
- */
929
- declare function getKnownDisplayNames(): Set<string>;
930
-
931
996
  /**
932
997
  * Git repository introspection helpers used by commands that need to know
933
998
  * *where* they are (repository root) and *what* they are looking at (the current
@@ -1119,4 +1184,4 @@ declare function buildPayloads(issues: NormalizedIssue[], resolveShortName: (too
1119
1184
  */
1120
1185
  declare function uploadReport(options: UploadOptions): Promise<UploadResult>;
1121
1186
 
1122
- export { type AdapterFactory, type AnalyzeOptions, type AutoFilters, type CategoryFilter, type CodacyYamlConfig, type CodacyYamlEngineConfig, type ConfigOperation, type DiscoverOptions, type DiscoveryExcludes, type ExecutionMode, type IgnoredFilesResult, type InitAutoStats, type InitDefaultStats, type InitDiscoveryOptions, type InitLocalStats, type InitRemoteStats, type LoggerOptions, type MergeOptions, type NormalizedIssue, type PatternMetadataLookup, type SeverityFilter, type UploadAuth, type UploadOptions, type UploadResult, analyze, applyCodacyYamlExcludes, applyConfigOperation, buildPayloads, buildToolConfig, clearAdapters, computePatternSummary, configureApiToken, createCodacyConfig, createLogger, createNullLogger, deleteCredentials, detectLanguages, diffConfigs, discover, formatOutput, formatTextSummary, getAdapter, getKnownDisplayNames, getRegisteredAdapters, getRegisteredDescriptors, initAutoConfig, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, intersectConfigs, listDiffFiles, listIgnoredFiles, listPrFiles, listStagedFiles, loadCredentials, mergeConfigs, parseAutoFilters, parseReport, pruneEmptyTools, readBaselineConfig, readCodacyConfig, readCodacyYaml, registerAdapter, registerLazyAdapter, registerUnsupportedTool, resolveApiToken, resolveBaselinePath, resolveConfigPath, resolveDiscoveryExcludes, resolveEngineToAdapter, resolveHeadCommit, resolveRepositoryRoot, resolveResultsApiBaseUrl, rotateLogFiles, saveCredentials, updateConfigIncremental, uploadReport, validateApiToken, writeBaselineConfig, writeCodacyConfig, writeCodacyConfigFile };
1187
+ export { type AdapterFactory, type AnalyzeOptions, type AutoFilters, type CategoryFilter, type CodacyYamlConfig, type CodacyYamlEngineConfig, type ConfigOperation, type DiscoverOptions, type DiscoveryExcludes, type ExecutionMode, type IgnoredFilesResult, type InitAutoStats, type InitDefaultStats, type InitDiscoveryOptions, type InitLocalStats, type InitRemoteStats, type LoggerOptions, type MergeOptions, type NormalizedIssue, type PatternMetadataLookup, type RemoteAuth, type SeverityFilter, type UploadAuth, type UploadOptions, type UploadResult, analyze, applyCodacyYamlExcludes, applyConfigOperation, buildPayloads, buildToolConfig, clearAdapters, computePatternSummary, configureApiToken, createCodacyConfig, createLogger, createNullLogger, deleteCredentials, detectLanguages, diffConfigs, discover, formatOutput, formatTextSummary, getAdapter, getKnownDisplayNames, getRegisteredAdapters, getRegisteredDescriptors, initAutoConfig, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, intersectConfigs, listDiffFiles, listIgnoredFiles, listPrFiles, listStagedFiles, loadCredentials, mergeConfigs, parseAutoFilters, parseReport, pruneEmptyTools, readBaselineConfig, readCodacyConfig, readCodacyYaml, registerAdapter, registerLazyAdapter, registerUnsupportedTool, resolveApiToken, resolveBaselinePath, resolveConfigPath, resolveDiscoveryExcludes, resolveEngineToAdapter, resolveHeadCommit, resolveRemoteAuth, resolveRepositoryRoot, resolveResultsApiBaseUrl, rotateLogFiles, saveCredentials, updateConfigIncremental, uploadReport, validateApiToken, writeBaselineConfig, writeCodacyConfig, writeCodacyConfigFile };