@backstage/backend-app-api 0.2.5-next.0 → 0.3.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.

Potentially problematic release.


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

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