@backstage/backend-app-api 0.0.0-nightly-20230220023355 → 0.0.0-nightly-20230222023132

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.

Potentially problematic release.


This version of @backstage/backend-app-api might be problematic. Click here for more details.

@@ -1,476 +0,0 @@
1
- /**
2
- * Core API used by Backstage backend apps.
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- /// <reference types="node" />
8
-
9
- import { BackendFeature } from '@backstage/backend-plugin-api';
10
- import { CacheClient } from '@backstage/backend-common';
11
- import { Config } from '@backstage/config';
12
- import { ConfigService } from '@backstage/backend-plugin-api';
13
- import { CorsOptions } from 'cors';
14
- import { ErrorRequestHandler } from 'express';
15
- import { Express as Express_2 } from 'express';
16
- import { Format } from 'logform';
17
- import { Handler } from 'express';
18
- import { HelmetOptions } from 'helmet';
19
- import * as http from 'http';
20
- import { HttpRouterService } from '@backstage/backend-plugin-api';
21
- import { IdentityService } from '@backstage/backend-plugin-api';
22
- import { JsonObject } from '@backstage/types';
23
- import { LifecycleService } from '@backstage/backend-plugin-api';
24
- import { LoadConfigOptionsRemote } from '@backstage/config-loader';
25
- import { LoggerService } from '@backstage/backend-plugin-api';
26
- import { PermissionsService } from '@backstage/backend-plugin-api';
27
- import { PluginDatabaseManager } from '@backstage/backend-common';
28
- import { PluginEndpointDiscovery } from '@backstage/backend-common';
29
- import { RequestHandler } from 'express';
30
- import { RequestListener } from 'http';
31
- import { RootHttpRouterService } from '@backstage/backend-plugin-api';
32
- import { RootLifecycleService } from '@backstage/backend-plugin-api';
33
- import { RootLoggerService } from '@backstage/backend-plugin-api';
34
- import { SchedulerService } from '@backstage/backend-plugin-api';
35
- import { ServiceFactory } from '@backstage/backend-plugin-api';
36
- import { ServiceFactoryOrFunction } from '@backstage/backend-plugin-api';
37
- import { TokenManagerService } from '@backstage/backend-plugin-api';
38
- import { transport } from 'winston';
39
- import { UrlReader } from '@backstage/backend-common';
40
-
41
- /**
42
- * @public
43
- */
44
- export declare interface Backend {
45
- add(feature: BackendFeature): void;
46
- start(): Promise<void>;
47
- stop(): Promise<void>;
48
- }
49
-
50
- /** @public */
51
- export declare const cacheServiceFactory: () => ServiceFactory<CacheClient, "plugin">;
52
-
53
- /** @public */
54
- export declare interface ConfigFactoryOptions {
55
- /**
56
- * Process arguments to use instead of the default `process.argv()`.
57
- */
58
- argv?: string[];
59
- /**
60
- * Enables and sets options for remote configuration loading.
61
- */
62
- remote?: LoadConfigOptionsRemote;
63
- }
64
-
65
- /** @public */
66
- export declare const configServiceFactory: (options?: ConfigFactoryOptions | undefined) => ServiceFactory<ConfigService, "root">;
67
-
68
- /** @public */
69
- export declare function createConfigSecretEnumerator(options: {
70
- logger: LoggerService;
71
- dir?: string;
72
- }): Promise<(config: Config) => Iterable<string>>;
73
-
74
- /**
75
- * Creates a Node.js HTTP or HTTPS server instance.
76
- *
77
- * @public
78
- */
79
- export declare function createHttpServer(listener: RequestListener, options: HttpServerOptions, deps: {
80
- logger: LoggerService;
81
- }): Promise<ExtendedHttpServer>;
82
-
83
- /**
84
- * @public
85
- */
86
- export declare function createSpecializedBackend(options: CreateSpecializedBackendOptions): Backend;
87
-
88
- /**
89
- * @public
90
- */
91
- export declare interface CreateSpecializedBackendOptions {
92
- services: ServiceFactoryOrFunction[];
93
- }
94
-
95
- /** @public */
96
- export declare const databaseServiceFactory: () => ServiceFactory<PluginDatabaseManager, "plugin">;
97
-
98
- /**
99
- * The default implementation of the {@link @backstage/backend-plugin-api#RootHttpRouterService} interface for
100
- * {@link @backstage/backend-plugin-api#coreServices.rootHttpRouter}.
101
- *
102
- * @public
103
- */
104
- export declare class DefaultRootHttpRouter implements RootHttpRouterService {
105
- #private;
106
- static create(options?: DefaultRootHttpRouterOptions): DefaultRootHttpRouter;
107
- private constructor();
108
- use(path: string, handler: Handler): void;
109
- handler(): Handler;
110
- }
111
-
112
- /**
113
- * Options for the {@link DefaultRootHttpRouter} class.
114
- *
115
- * @public
116
- */
117
- export declare interface DefaultRootHttpRouterOptions {
118
- /**
119
- * The path to forward all unmatched requests to. Defaults to '/api/app' if
120
- * not given. Disables index path behavior if false is given.
121
- */
122
- indexPath?: string | false;
123
- }
124
-
125
- /** @public */
126
- export declare const discoveryServiceFactory: () => ServiceFactory<PluginEndpointDiscovery, "plugin">;
127
-
128
- /**
129
- * An HTTP server extended with utility methods.
130
- *
131
- * @public
132
- */
133
- export declare interface ExtendedHttpServer extends http.Server {
134
- start(): Promise<void>;
135
- stop(): Promise<void>;
136
- port(): number;
137
- }
138
-
139
- /**
140
- * @public
141
- */
142
- export declare interface HttpRouterFactoryOptions {
143
- /**
144
- * A callback used to generate the path for each plugin, defaults to `/api/{pluginId}`.
145
- */
146
- getPath?(pluginId: string): string;
147
- }
148
-
149
- /** @public */
150
- export declare const httpRouterServiceFactory: (options?: HttpRouterFactoryOptions | undefined) => ServiceFactory<HttpRouterService, "plugin">;
151
-
152
- /**
153
- * Options for configuring HTTPS for an HTTP server.
154
- *
155
- * @public
156
- */
157
- export declare type HttpServerCertificateOptions = {
158
- type: 'pem';
159
- key: string;
160
- cert: string;
161
- } | {
162
- type: 'generated';
163
- hostname: string;
164
- };
165
-
166
- /**
167
- * Options for starting up an HTTP server.
168
- *
169
- * @public
170
- */
171
- export declare type HttpServerOptions = {
172
- listen: {
173
- port: number;
174
- host: string;
175
- };
176
- https?: {
177
- certificate: HttpServerCertificateOptions;
178
- };
179
- };
180
-
181
- /**
182
- * An identity client options object which allows extra configurations
183
- *
184
- * @public
185
- */
186
- export declare type IdentityFactoryOptions = {
187
- issuer?: string;
188
- /** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
189
- * More info on supported algorithms: https://github.com/panva/jose */
190
- algorithms?: string[];
191
- };
192
-
193
- /** @public */
194
- export declare const identityServiceFactory: (options?: IdentityFactoryOptions | undefined) => ServiceFactory<IdentityService, "plugin">;
195
-
196
- /**
197
- * Allows plugins to register shutdown hooks that are run when the process is about to exit.
198
- * @public
199
- */
200
- export declare const lifecycleServiceFactory: () => ServiceFactory<LifecycleService, "plugin">;
201
-
202
- /**
203
- * Load configuration for a Backend.
204
- *
205
- * This function should only be called once, during the initialization of the backend.
206
- *
207
- * @public
208
- */
209
- export declare function loadBackendConfig(options: {
210
- remote?: LoadConfigOptionsRemote;
211
- argv: string[];
212
- }): Promise<{
213
- config: Config;
214
- }>;
215
-
216
- /** @public */
217
- export declare const loggerServiceFactory: () => ServiceFactory<LoggerService, "plugin">;
218
-
219
- /**
220
- * A utility to configure common middleware.
221
- *
222
- * @public
223
- */
224
- export declare class MiddlewareFactory {
225
- #private;
226
- /**
227
- * Creates a new {@link MiddlewareFactory}.
228
- */
229
- static create(options: MiddlewareFactoryOptions): MiddlewareFactory;
230
- private constructor();
231
- /**
232
- * Returns a middleware that unconditionally produces a 404 error response.
233
- *
234
- * @remarks
235
- *
236
- * Typically you want to place this middleware at the end of the chain, such
237
- * that it's the last one attempted after no other routes matched.
238
- *
239
- * @returns An Express request handler
240
- */
241
- notFound(): RequestHandler;
242
- /**
243
- * Returns the compression middleware.
244
- *
245
- * @remarks
246
- *
247
- * The middleware will attempt to compress response bodies for all requests
248
- * that traverse through the middleware.
249
- */
250
- compression(): RequestHandler;
251
- /**
252
- * Returns a request logging middleware.
253
- *
254
- * @remarks
255
- *
256
- * Typically you want to place this middleware at the start of the chain, such
257
- * that it always logs requests whether they are "caught" by handlers farther
258
- * down or not.
259
- *
260
- * @returns An Express request handler
261
- */
262
- logging(): RequestHandler;
263
- /**
264
- * Returns a middleware that implements the helmet library.
265
- *
266
- * @remarks
267
- *
268
- * This middleware applies security policies to incoming requests and outgoing
269
- * responses. It is configured using config keys such as `backend.csp`.
270
- *
271
- * @see {@link https://helmetjs.github.io/}
272
- *
273
- * @returns An Express request handler
274
- */
275
- helmet(): RequestHandler;
276
- /**
277
- * Returns a middleware that implements the cors library.
278
- *
279
- * @remarks
280
- *
281
- * This middleware handles CORS. It is configured using the config key
282
- * `backend.cors`.
283
- *
284
- * @see {@link https://github.com/expressjs/cors}
285
- *
286
- * @returns An Express request handler
287
- */
288
- cors(): RequestHandler;
289
- /**
290
- * Express middleware to handle errors during request processing.
291
- *
292
- * @remarks
293
- *
294
- * This is commonly the very last middleware in the chain.
295
- *
296
- * Its primary purpose is not to do translation of business logic exceptions,
297
- * but rather to be a global catch-all for uncaught "fatal" errors that are
298
- * expected to result in a 500 error. However, it also does handle some common
299
- * error types (such as http-error exceptions, and the well-known error types
300
- * in the `@backstage/errors` package) and returns the enclosed status code
301
- * accordingly.
302
- *
303
- * It will also produce a response body with a serialized form of the error,
304
- * unless a previous handler already did send a body. See
305
- * {@link @backstage/errors#ErrorResponseBody} for the response shape used.
306
- *
307
- * @returns An Express error request handler
308
- */
309
- error(options?: MiddlewareFactoryErrorOptions): ErrorRequestHandler;
310
- }
311
-
312
- /**
313
- * Options passed to the {@link MiddlewareFactory.error} middleware.
314
- *
315
- * @public
316
- */
317
- export declare interface MiddlewareFactoryErrorOptions {
318
- /**
319
- * Whether error response bodies should show error stack traces or not.
320
- *
321
- * If not specified, by default shows stack traces only in development mode.
322
- */
323
- showStackTraces?: boolean;
324
- /**
325
- * Whether any 4xx errors should be logged or not.
326
- *
327
- * If not specified, default to only logging 5xx errors.
328
- */
329
- logAllErrors?: boolean;
330
- }
331
-
332
- /**
333
- * Options used to create a {@link MiddlewareFactory}.
334
- *
335
- * @public
336
- */
337
- export declare interface MiddlewareFactoryOptions {
338
- config: ConfigService;
339
- logger: LoggerService;
340
- }
341
-
342
- /** @public */
343
- export declare const permissionsServiceFactory: () => ServiceFactory<PermissionsService, "plugin">;
344
-
345
- /**
346
- * Attempts to read a CORS options object from the backend configuration object.
347
- *
348
- * @public
349
- * @param config - The backend configuration object.
350
- * @returns A CORS options object, or undefined if no cors configuration is present.
351
- *
352
- * @example
353
- * ```ts
354
- * const corsOptions = readCorsOptions(config.getConfig('backend'));
355
- * ```
356
- */
357
- export declare function readCorsOptions(config?: Config): CorsOptions;
358
-
359
- /**
360
- * Attempts to read Helmet options from the backend configuration object.
361
- *
362
- * @public
363
- * @param config - The backend configuration object.
364
- * @returns A Helmet options object, or undefined if no Helmet configuration is present.
365
- *
366
- * @example
367
- * ```ts
368
- * const helmetOptions = readHelmetOptions(config.getConfig('backend'));
369
- * ```
370
- */
371
- export declare function readHelmetOptions(config?: Config): HelmetOptions;
372
-
373
- /**
374
- * Reads {@link HttpServerOptions} from a {@link @backstage/config#Config} object.
375
- *
376
- * @public
377
- * @remarks
378
- *
379
- * The provided configuration object should contain the `listen` and
380
- * additional keys directly.
381
- *
382
- * @example
383
- * ```ts
384
- * const opts = readHttpServerOptions(config.getConfig('backend'));
385
- * ```
386
- */
387
- export declare function readHttpServerOptions(config?: Config): HttpServerOptions;
388
-
389
- /**
390
- * @public
391
- */
392
- export declare interface RootHttpRouterConfigureContext {
393
- app: Express_2;
394
- middleware: MiddlewareFactory;
395
- routes: RequestHandler;
396
- config: ConfigService;
397
- logger: LoggerService;
398
- lifecycle: LifecycleService;
399
- }
400
-
401
- /**
402
- * @public
403
- */
404
- export declare type RootHttpRouterFactoryOptions = {
405
- /**
406
- * The path to forward all unmatched requests to. Defaults to '/api/app' if
407
- * not given. Disables index path behavior if false is given.
408
- */
409
- indexPath?: string | false;
410
- configure?(context: RootHttpRouterConfigureContext): void;
411
- };
412
-
413
- /** @public */
414
- export declare const rootHttpRouterServiceFactory: (options?: RootHttpRouterFactoryOptions | undefined) => ServiceFactory<RootHttpRouterService, "root">;
415
-
416
- /**
417
- * Allows plugins to register shutdown hooks that are run when the process is about to exit.
418
- *
419
- * @public
420
- */
421
- export declare const rootLifecycleServiceFactory: () => ServiceFactory<RootLifecycleService, "root">;
422
-
423
- /** @public */
424
- export declare const rootLoggerServiceFactory: () => ServiceFactory<RootLoggerService, "root">;
425
-
426
- /** @public */
427
- export declare const schedulerServiceFactory: () => ServiceFactory<SchedulerService, "plugin">;
428
-
429
- /** @public */
430
- export declare const tokenManagerServiceFactory: () => ServiceFactory<TokenManagerService, "plugin">;
431
-
432
- /** @public */
433
- export declare const urlReaderServiceFactory: () => ServiceFactory<UrlReader, "plugin">;
434
-
435
- /**
436
- * A {@link @backstage/backend-plugin-api#LoggerService} implementation based on winston.
437
- *
438
- * @public
439
- */
440
- export declare class WinstonLogger implements RootLoggerService {
441
- #private;
442
- /**
443
- * Creates a {@link WinstonLogger} instance.
444
- */
445
- static create(options: WinstonLoggerOptions): WinstonLogger;
446
- /**
447
- * Creates a winston log formatter for redacting secrets.
448
- */
449
- static redacter(): {
450
- format: Format;
451
- add: (redactions: Iterable<string>) => void;
452
- };
453
- /**
454
- * Creates a pretty printed winston log formatter.
455
- */
456
- static colorFormat(): Format;
457
- private constructor();
458
- error(message: string, meta?: JsonObject): void;
459
- warn(message: string, meta?: JsonObject): void;
460
- info(message: string, meta?: JsonObject): void;
461
- debug(message: string, meta?: JsonObject): void;
462
- child(meta: JsonObject): LoggerService;
463
- addRedactions(redactions: Iterable<string>): void;
464
- }
465
-
466
- /**
467
- * @public
468
- */
469
- export declare interface WinstonLoggerOptions {
470
- meta?: JsonObject;
471
- level: string;
472
- format: Format;
473
- transports: transport[];
474
- }
475
-
476
- export { }