## API Report File for "@backstage/backend-common"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
/// <reference types="node" />
/// <reference types="webpack-env" />

import { AwsS3Integration } from '@backstage/integration';
import { AzureIntegration } from '@backstage/integration';
import { BitbucketIntegration } from '@backstage/integration';
import { Config } from '@backstage/config';
import cors from 'cors';
import Docker from 'dockerode';
import { ErrorRequestHandler } from 'express';
import express from 'express';
import { GithubCredentialsProvider } from '@backstage/integration';
import { GitHubIntegration } from '@backstage/integration';
import { GitLabIntegration } from '@backstage/integration';
import { isChildPath } from '@backstage/cli-common';
import { JsonValue } from '@backstage/config';
import { Knex } from 'knex';
import { Logger as Logger_2 } from 'winston';
import { MergeResult } from 'isomorphic-git';
import { PushResult } from 'isomorphic-git';
import { Readable } from 'stream';
import { ReadCommitResult } from 'isomorphic-git';
import { RequestHandler } from 'express';
import { Router } from 'express';
import { S3 } from 'aws-sdk';
import { Server } from 'http';
import * as winston from 'winston';
import { Writable } from 'stream';

// Warning: (ae-missing-release-tag) "AwsS3UrlReader" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class AwsS3UrlReader implements UrlReader {
  constructor(
    integration: AwsS3Integration,
    deps: {
      s3: S3;
      treeResponseFactory: ReadTreeResponseFactory;
    },
  );
  // (undocumented)
  static factory: ReaderFactory;
  // (undocumented)
  read(url: string): Promise<Buffer>;
  // (undocumented)
  readTree(url: string): Promise<ReadTreeResponse>;
  // (undocumented)
  readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
  // (undocumented)
  search(): Promise<SearchResponse>;
  // (undocumented)
  toString(): string;
}

// @public (undocumented)
export class AzureUrlReader implements UrlReader {
  constructor(
    integration: AzureIntegration,
    deps: {
      treeResponseFactory: ReadTreeResponseFactory;
    },
  );
  // (undocumented)
  static factory: ReaderFactory;
  // (undocumented)
  read(url: string): Promise<Buffer>;
  // (undocumented)
  readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
  // (undocumented)
  readUrl(url: string, _options?: ReadUrlOptions): Promise<ReadUrlResponse>;
  // (undocumented)
  search(url: string, options?: SearchOptions): Promise<SearchResponse>;
  // (undocumented)
  toString(): string;
}

// @public
export class BitbucketUrlReader implements UrlReader {
  constructor(
    integration: BitbucketIntegration,
    deps: {
      treeResponseFactory: ReadTreeResponseFactory;
    },
  );
  // (undocumented)
  static factory: ReaderFactory;
  // (undocumented)
  read(url: string): Promise<Buffer>;
  // (undocumented)
  readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
  // (undocumented)
  readUrl(url: string, _options?: ReadUrlOptions): Promise<ReadUrlResponse>;
  // (undocumented)
  search(url: string, options?: SearchOptions): Promise<SearchResponse>;
  // (undocumented)
  toString(): string;
}

// @public
export interface CacheClient {
  delete(key: string): Promise<void>;
  get(key: string): Promise<JsonValue | undefined>;
  set(
    key: string,
    value: JsonValue,
    options?: CacheClientSetOptions,
  ): Promise<void>;
}

// @public (undocumented)
export type CacheClientOptions = {
  defaultTtl?: number;
};

// @public (undocumented)
export type CacheClientSetOptions = {
  ttl?: number;
};

// @public
export class CacheManager {
  forPlugin(pluginId: string): PluginCacheManager;
  static fromConfig(
    config: Config,
    options?: CacheManagerOptions,
  ): CacheManager;
}

// @public (undocumented)
export type CacheManagerOptions = {
  logger?: Logger_2;
  onError?: (err: Error) => void;
};

// @public (undocumented)
export const coloredFormat: winston.Logform.Format;

// @public (undocumented)
export interface ContainerRunner {
  // (undocumented)
  runContainer(opts: RunContainerOptions): Promise<void>;
}

// @public @deprecated
export const createDatabase: typeof createDatabaseClient;

// @public
export function createDatabaseClient(
  dbConfig: Config,
  overrides?: Partial<Knex.Config>,
): Knex<any, unknown[]>;

// @public (undocumented)
export function createRootLogger(
  options?: winston.LoggerOptions,
  env?: NodeJS.ProcessEnv,
): winston.Logger;

// @public
export function createServiceBuilder(_module: NodeModule): ServiceBuilder;

// @public (undocumented)
export function createStatusCheckRouter(options: {
  logger: Logger_2;
  path?: string;
  statusCheck?: StatusCheck;
}): Promise<express.Router>;

// @public (undocumented)
export class DatabaseManager {
  forPlugin(pluginId: string): PluginDatabaseManager;
  static fromConfig(config: Config): DatabaseManager;
}

// @public (undocumented)
export class DockerContainerRunner implements ContainerRunner {
  constructor({ dockerClient }: { dockerClient: Docker });
  // (undocumented)
  runContainer({
    imageName,
    command,
    args,
    logStream,
    mountDirs,
    workingDir,
    envVars,
    pullImage,
  }: RunContainerOptions): Promise<void>;
}

// @public
export function ensureDatabaseExists(
  dbConfig: Config,
  ...databases: Array<string>
): Promise<void>;

// @public
export function errorHandler(
  options?: ErrorHandlerOptions,
): ErrorRequestHandler;

// @public (undocumented)
export type ErrorHandlerOptions = {
  showStackTraces?: boolean;
  logger?: Logger_2;
  logClientErrors?: boolean;
};

// @public (undocumented)
export function getRootLogger(): winston.Logger;

// @public
export function getVoidLogger(): winston.Logger;

// @public (undocumented)
export class Git {
  // (undocumented)
  add({ dir, filepath }: { dir: string; filepath: string }): Promise<void>;
  // (undocumented)
  addRemote({
    dir,
    url,
    remote,
  }: {
    dir: string;
    remote: string;
    url: string;
  }): Promise<void>;
  // (undocumented)
  clone({
    url,
    dir,
    ref,
  }: {
    url: string;
    dir: string;
    ref?: string;
  }): Promise<void>;
  // (undocumented)
  commit({
    dir,
    message,
    author,
    committer,
  }: {
    dir: string;
    message: string;
    author: {
      name: string;
      email: string;
    };
    committer: {
      name: string;
      email: string;
    };
  }): Promise<string>;
  // (undocumented)
  currentBranch({
    dir,
    fullName,
  }: {
    dir: string;
    fullName?: boolean;
  }): Promise<string | undefined>;
  // (undocumented)
  fetch({ dir, remote }: { dir: string; remote?: string }): Promise<void>;
  // (undocumented)
  static fromAuth: ({
    username,
    password,
    logger,
  }: {
    username?: string | undefined;
    password?: string | undefined;
    logger?: Logger_2 | undefined;
  }) => Git;
  // (undocumented)
  init({
    dir,
    defaultBranch,
  }: {
    dir: string;
    defaultBranch?: string;
  }): Promise<void>;
  // (undocumented)
  merge({
    dir,
    theirs,
    ours,
    author,
    committer,
  }: {
    dir: string;
    theirs: string;
    ours?: string;
    author: {
      name: string;
      email: string;
    };
    committer: {
      name: string;
      email: string;
    };
  }): Promise<MergeResult>;
  // (undocumented)
  push({ dir, remote }: { dir: string; remote: string }): Promise<PushResult>;
  // (undocumented)
  readCommit({
    dir,
    sha,
  }: {
    dir: string;
    sha: string;
  }): Promise<ReadCommitResult>;
  // (undocumented)
  resolveRef({ dir, ref }: { dir: string; ref: string }): Promise<string>;
}

// @public
export class GithubUrlReader implements UrlReader {
  constructor(
    integration: GitHubIntegration,
    deps: {
      treeResponseFactory: ReadTreeResponseFactory;
      credentialsProvider: GithubCredentialsProvider;
    },
  );
  // (undocumented)
  static factory: ReaderFactory;
  // (undocumented)
  read(url: string): Promise<Buffer>;
  // (undocumented)
  readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
  // (undocumented)
  readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
  // (undocumented)
  search(url: string, options?: SearchOptions): Promise<SearchResponse>;
  // (undocumented)
  toString(): string;
}

// @public (undocumented)
export class GitlabUrlReader implements UrlReader {
  constructor(
    integration: GitLabIntegration,
    deps: {
      treeResponseFactory: ReadTreeResponseFactory;
    },
  );
  // (undocumented)
  static factory: ReaderFactory;
  // (undocumented)
  read(url: string): Promise<Buffer>;
  // (undocumented)
  readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
  // (undocumented)
  readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
  // (undocumented)
  search(url: string, options?: SearchOptions): Promise<SearchResponse>;
  // (undocumented)
  toString(): string;
}

export { isChildPath };

// @public
export function loadBackendConfig(options: {
  logger: Logger_2;
  argv: string[];
}): Promise<Config>;

// @public
export function notFoundHandler(): RequestHandler;

// @public
export type PluginCacheManager = {
  getClient: (options?: CacheClientOptions) => CacheClient;
};

// @public
export interface PluginDatabaseManager {
  getClient(): Promise<Knex>;
}

// @public
export type PluginEndpointDiscovery = {
  getBaseUrl(pluginId: string): Promise<string>;
  getExternalBaseUrl(pluginId: string): Promise<string>;
};

// @public
export type ReaderFactory = (options: {
  config: Config;
  logger: Logger_2;
  treeResponseFactory: ReadTreeResponseFactory;
}) => UrlReaderPredicateTuple[];

// @public
export type ReadTreeOptions = {
  filter?(
    path: string,
    info?: {
      size: number;
    },
  ): boolean;
  etag?: string;
};

// @public
export type ReadTreeResponse = {
  files(): Promise<ReadTreeResponseFile[]>;
  archive(): Promise<NodeJS.ReadableStream>;
  dir(options?: ReadTreeResponseDirOptions): Promise<string>;
  etag: string;
};

// @public (undocumented)
export type ReadTreeResponseDirOptions = {
  targetDir?: string;
};

// @public (undocumented)
export interface ReadTreeResponseFactory {
  // Warning: (ae-forgotten-export) The symbol "FromReadableArrayOptions" needs to be exported by the entry point index.d.ts
  //
  // (undocumented)
  fromReadableArray(
    options: FromReadableArrayOptions,
  ): Promise<ReadTreeResponse>;
  // (undocumented)
  fromTarArchive(
    options: ReadTreeResponseFactoryOptions,
  ): Promise<ReadTreeResponse>;
  // (undocumented)
  fromZipArchive(
    options: ReadTreeResponseFactoryOptions,
  ): Promise<ReadTreeResponse>;
}

// @public (undocumented)
export type ReadTreeResponseFactoryOptions = {
  stream: Readable;
  subpath?: string;
  etag: string;
  filter?: (
    path: string,
    info?: {
      size: number;
    },
  ) => boolean;
};

// @public
export type ReadTreeResponseFile = {
  path: string;
  content(): Promise<Buffer>;
};

// @public
export type ReadUrlOptions = {
  etag?: string;
};

// @public
export type ReadUrlResponse = {
  buffer(): Promise<Buffer>;
  etag?: string;
};

// @public
export function requestLoggingHandler(logger?: Logger_2): RequestHandler;

// @public (undocumented)
export type RequestLoggingHandlerFactory = (
  logger?: Logger_2,
) => RequestHandler;

// @public
export function resolvePackagePath(name: string, ...paths: string[]): string;

// @public
export function resolveSafeChildPath(base: string, path: string): string;

// @public (undocumented)
export type RunContainerOptions = {
  imageName: string;
  command?: string | string[];
  args: string[];
  logStream?: Writable;
  mountDirs?: Record<string, string>;
  workingDir?: string;
  envVars?: Record<string, string>;
  pullImage?: boolean;
};

// @public
export type SearchOptions = {
  etag?: string;
};

// @public
export type SearchResponse = {
  files: SearchResponseFile[];
  etag: string;
};

// @public
export type SearchResponseFile = {
  url: string;
  content(): Promise<Buffer>;
};

// @public (undocumented)
export type ServiceBuilder = {
  loadConfig(config: Config): ServiceBuilder;
  setPort(port: number): ServiceBuilder;
  setHost(host: string): ServiceBuilder;
  setLogger(logger: Logger_2): ServiceBuilder;
  enableCors(options: cors.CorsOptions): ServiceBuilder;
  setHttpsSettings(settings: {
    certificate:
      | {
          key: string;
          cert: string;
        }
      | {
          hostname: string;
        };
  }): ServiceBuilder;
  addRouter(root: string, router: Router | RequestHandler): ServiceBuilder;
  setRequestLoggingHandler(
    requestLoggingHandler: RequestLoggingHandlerFactory,
  ): ServiceBuilder;
  start(): Promise<Server>;
};

// @public (undocumented)
export function setRootLogger(newLogger: winston.Logger): void;

// @public @deprecated
export const SingleConnectionDatabaseManager: typeof DatabaseManager;

// @public
export class SingleHostDiscovery implements PluginEndpointDiscovery {
  static fromConfig(
    config: Config,
    options?: {
      basePath?: string;
    },
  ): SingleHostDiscovery;
  // (undocumented)
  getBaseUrl(pluginId: string): Promise<string>;
  // (undocumented)
  getExternalBaseUrl(pluginId: string): Promise<string>;
}

// @public (undocumented)
export type StatusCheck = () => Promise<any>;

// @public
export function statusCheckHandler(
  options?: StatusCheckHandlerOptions,
): Promise<RequestHandler>;

// @public (undocumented)
export interface StatusCheckHandlerOptions {
  statusCheck?: StatusCheck;
}

// @public
export type UrlReader = {
  read(url: string): Promise<Buffer>;
  readUrl?(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
  readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
  search(url: string, options?: SearchOptions): Promise<SearchResponse>;
};

// @public (undocumented)
export type UrlReaderPredicateTuple = {
  predicate: (url: URL) => boolean;
  reader: UrlReader;
};

// @public
export class UrlReaders {
  static create({ logger, config, factories }: UrlReadersOptions): UrlReader;
  static default({ logger, config, factories }: UrlReadersOptions): UrlReader;
}

// @public (undocumented)
export type UrlReadersOptions = {
  config: Config;
  logger: Logger_2;
  factories?: ReaderFactory[];
};

// @public
export function useHotCleanup(
  _module: NodeModule,
  cancelEffect: () => void,
): void;

// @public
export function useHotMemoize<T>(_module: NodeModule, valueFactory: () => T): T;
```
