@backstage/backend-plugin-api 0.0.0-nightly-20230103022231 → 0.0.0-nightly-20230104022659

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.
package/CHANGELOG.md CHANGED
@@ -1,14 +1,31 @@
1
1
  # @backstage/backend-plugin-api
2
2
 
3
- ## 0.0.0-nightly-20230103022231
3
+ ## 0.0.0-nightly-20230104022659
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - 6cfd4d7073: Added `RootLifecycleService` and `rootLifecycleServiceRef`, as well as added a `labels` option to the existing `LifecycleServiceShutdownHook`.
8
+ - 5e2cebe9a3: Migrate `UrlReader` into this package to gradually remove the dependency on backend-common.
9
+ - 6f02d23b01: Moved `PluginEndpointDiscovery` type from backend-common to backend-plugin-api.
10
+ - 16054afdec: Documented `coreServices` an all of its members.
7
11
  - Updated dependencies
8
- - @backstage/config@0.0.0-nightly-20230103022231
9
- - @backstage/backend-common@0.0.0-nightly-20230103022231
10
- - @backstage/backend-tasks@0.0.0-nightly-20230103022231
11
- - @backstage/plugin-permission-common@0.0.0-nightly-20230103022231
12
+ - @backstage/backend-common@0.0.0-nightly-20230104022659
13
+ - @backstage/config@0.0.0-nightly-20230104022659
14
+ - @backstage/backend-tasks@0.0.0-nightly-20230104022659
15
+ - @backstage/plugin-permission-common@0.0.0-nightly-20230104022659
16
+
17
+ ## 0.2.1-next.0
18
+
19
+ ### Patch Changes
20
+
21
+ - 6cfd4d7073: Added `RootLifecycleService` and `rootLifecycleServiceRef`, as well as added a `labels` option to the existing `LifecycleServiceShutdownHook`.
22
+ - 5e2cebe9a3: Migrate `UrlReader` into this package to gradually remove the dependency on backend-common.
23
+ - 6f02d23b01: Moved `PluginEndpointDiscovery` type from backend-common to backend-plugin-api.
24
+ - Updated dependencies
25
+ - @backstage/backend-common@0.18.0-next.0
26
+ - @backstage/config@1.0.6-next.0
27
+ - @backstage/backend-tasks@0.4.1-next.0
28
+ - @backstage/plugin-permission-common@0.7.3-next.0
12
29
 
13
30
  ## 0.2.0
14
31
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-plugin-api",
3
- "version": "0.0.0-nightly-20230103022231",
3
+ "version": "0.0.0-nightly-20230104022659",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -4,18 +4,18 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ /// <reference types="node" />
8
+
7
9
  import { Config } from '@backstage/config';
8
10
  import { Handler } from 'express';
9
11
  import { Logger } from 'winston';
10
- import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
11
12
  import { PermissionEvaluator } from '@backstage/plugin-permission-common';
12
13
  import { PluginCacheManager } from '@backstage/backend-common';
13
14
  import { PluginDatabaseManager } from '@backstage/backend-common';
14
- import { PluginEndpointDiscovery } from '@backstage/backend-common';
15
15
  import { PluginTaskScheduler } from '@backstage/backend-tasks';
16
+ import { Readable } from 'stream';
16
17
  import { TokenManager } from '@backstage/backend-common';
17
18
  import { TransportStreamOptions } from 'winston-transport';
18
- import { UrlReader } from '@backstage/backend-common';
19
19
 
20
20
  /** @public */
21
21
  export declare interface BackendFeature {
@@ -50,41 +50,106 @@ export declare interface BackendRegistrationPoints {
50
50
  }
51
51
 
52
52
  /** @public */
53
- export declare type CacheService = PluginCacheManager;
54
-
55
- /**
56
- * @public
57
- */
58
- declare const cacheServiceRef: ServiceRef<PluginCacheManager, "plugin">;
53
+ export declare interface CacheService extends PluginCacheManager {
54
+ }
59
55
 
60
56
  /**
61
57
  * @public
62
58
  */
63
- export declare type ConfigService = Config;
59
+ export declare interface ConfigService extends Config {
60
+ }
64
61
 
65
62
  /**
63
+ * All core services references
64
+ *
66
65
  * @public
67
66
  */
68
- declare const configServiceRef: ServiceRef<Config, "root">;
69
-
70
- declare namespace coreServices {
71
- export {
72
- configServiceRef as config,
73
- httpRouterServiceRef as httpRouter,
74
- loggerServiceRef as logger,
75
- urlReaderServiceRef as urlReader,
76
- cacheServiceRef as cache,
77
- databaseServiceRef as database,
78
- discoveryServiceRef as discovery,
79
- tokenManagerServiceRef as tokenManager,
80
- permissionsServiceRef as permissions,
81
- schedulerServiceRef as scheduler,
82
- rootLoggerServiceRef as rootLogger,
83
- pluginMetadataServiceRef as pluginMetadata,
84
- lifecycleServiceRef as lifecycle
85
- }
67
+ export declare namespace coreServices {
68
+ /**
69
+ * The service reference for the plugin scoped {@link CacheService}.
70
+ *
71
+ * @public
72
+ */
73
+ const cache: ServiceRef<CacheService, "plugin">;
74
+ /**
75
+ * The service reference for the root scoped {@link ConfigService}.
76
+ *
77
+ * @public
78
+ */
79
+ const config: ServiceRef<ConfigService, "root">;
80
+ /**
81
+ * The service reference for the plugin scoped {@link DatabaseService}.
82
+ *
83
+ * @public
84
+ */
85
+ const database: ServiceRef<DatabaseService, "plugin">;
86
+ /**
87
+ * The service reference for the plugin scoped {@link DiscoveryService}.
88
+ *
89
+ * @public
90
+ */
91
+ const discovery: ServiceRef<DiscoveryService, "plugin">;
92
+ /**
93
+ * The service reference for the plugin scoped {@link HttpRouterService}.
94
+ *
95
+ * @public
96
+ */
97
+ const httpRouter: ServiceRef<HttpRouterService, "plugin">;
98
+ /**
99
+ * The service reference for the plugin scoped {@link LifecycleService}.
100
+ *
101
+ * @public
102
+ */
103
+ const lifecycle: ServiceRef<LifecycleService, "plugin">;
104
+ /**
105
+ * The service reference for the plugin scoped {@link LoggerService}.
106
+ *
107
+ * @public
108
+ */
109
+ const logger: ServiceRef<LoggerService, "plugin">;
110
+ /**
111
+ * The service reference for the plugin scoped {@link PermissionsService}.
112
+ *
113
+ * @public
114
+ */
115
+ const permissions: ServiceRef<PermissionsService, "plugin">;
116
+ /**
117
+ * The service reference for the plugin scoped {@link PluginMetadataService}.
118
+ *
119
+ * @public
120
+ */
121
+ const pluginMetadata: ServiceRef<PluginMetadataService, "plugin">;
122
+ /**
123
+ * The service reference for the root scoped {@link RootLifecycleService}.
124
+ *
125
+ * @public
126
+ */
127
+ const rootLifecycle: ServiceRef<RootLifecycleService, "root">;
128
+ /**
129
+ * The service reference for the root scoped {@link RootLoggerService}.
130
+ *
131
+ * @public
132
+ */
133
+ const rootLogger: ServiceRef<RootLoggerService, "root">;
134
+ /**
135
+ * The service reference for the plugin scoped {@link SchedulerService}.
136
+ *
137
+ * @public
138
+ */
139
+ const scheduler: ServiceRef<SchedulerService, "plugin">;
140
+ /**
141
+ * The service reference for the plugin scoped {@link TokenManagerService}.
142
+ *
143
+ * @public
144
+ */
145
+ const tokenManager: ServiceRef<TokenManagerService, "plugin">;
146
+ /**
147
+ * The service reference for the plugin scoped {@link UrlReaderService}.
148
+ *
149
+ * @public
150
+ */
151
+ const urlReader: ServiceRef<UrlReaderService, "plugin">;
86
152
  }
87
- export { coreServices }
88
153
 
89
154
  /**
90
155
  * @public
@@ -137,20 +202,55 @@ export declare function createServiceRef<T>(options: {
137
202
  }): ServiceRef<T, 'root'>;
138
203
 
139
204
  /** @public */
140
- export declare type DatabaseService = PluginDatabaseManager;
141
-
142
- /**
143
- * @public
144
- */
145
- declare const databaseServiceRef: ServiceRef<PluginDatabaseManager, "plugin">;
146
-
147
- /** @public */
148
- export declare type DiscoveryService = PluginEndpointDiscovery;
205
+ export declare interface DatabaseService extends PluginDatabaseManager {
206
+ }
149
207
 
150
208
  /**
209
+ * The DiscoveryService is used to provide a mechanism for backend
210
+ * plugins to discover the endpoints for itself or other backend plugins.
211
+ *
212
+ * The purpose of the discovery API is to allow for many different deployment
213
+ * setups and routing methods through a central configuration, instead
214
+ * of letting each individual plugin manage that configuration.
215
+ *
216
+ * Implementations of the discovery API can be as simple as a URL pattern
217
+ * using the pluginId, but could also have overrides for individual plugins,
218
+ * or query a separate discovery service.
219
+ *
151
220
  * @public
152
221
  */
153
- declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery, "plugin">;
222
+ export declare interface DiscoveryService {
223
+ /**
224
+ * Returns the internal HTTP base URL for a given plugin, without a trailing slash.
225
+ *
226
+ * The returned URL should point to an internal endpoint for the plugin, with
227
+ * the shortest route possible. The URL should be used for service-to-service
228
+ * communication within a Backstage backend deployment.
229
+ *
230
+ * This method must always be called just before making a request, as opposed to
231
+ * fetching the URL when constructing an API client. That is to ensure that more
232
+ * flexible routing patterns can be supported.
233
+ *
234
+ * For example, asking for the URL for `catalog` may return something
235
+ * like `http://10.1.2.3/api/catalog`
236
+ */
237
+ getBaseUrl(pluginId: string): Promise<string>;
238
+ /**
239
+ * Returns the external HTTP base backend URL for a given plugin, without a trailing slash.
240
+ *
241
+ * The returned URL should point to an external endpoint for the plugin, such that
242
+ * it is reachable from the Backstage frontend and other external services. The returned
243
+ * URL should be usable for example as a callback / webhook URL.
244
+ *
245
+ * The returned URL should be stable and in general not change unless other static
246
+ * or external configuration is changed. Changes should not come as a surprise
247
+ * to an operator of the Backstage backend.
248
+ *
249
+ * For example, asking for the URL for `catalog` may return something
250
+ * like `https://backstage.example.com/api/catalog`
251
+ */
252
+ getExternalBaseUrl(pluginId: string): Promise<string>;
253
+ }
154
254
 
155
255
  /**
156
256
  * TODO
@@ -175,11 +275,6 @@ export declare interface HttpRouterService {
175
275
  use(handler: Handler): void;
176
276
  }
177
277
 
178
- /**
179
- * @public
180
- */
181
- declare const httpRouterServiceRef: ServiceRef<HttpRouterService, "plugin">;
182
-
183
278
  /**
184
279
  * @public
185
280
  **/
@@ -190,19 +285,18 @@ export declare interface LifecycleService {
190
285
  addShutdownHook(options: LifecycleServiceShutdownHook): void;
191
286
  }
192
287
 
193
- /**
194
- * @public
195
- */
196
- declare const lifecycleServiceRef: ServiceRef<LifecycleService, "plugin">;
197
-
198
288
  /**
199
289
  * @public
200
290
  **/
201
291
  export declare type LifecycleServiceShutdownHook = {
202
292
  fn: () => void | Promise<void>;
293
+ /** Labels to help identify the shutdown hook */
294
+ labels?: Record<string, string>;
203
295
  };
204
296
 
205
297
  /**
298
+ * A service that provides a logging facility.
299
+ *
206
300
  * @public
207
301
  */
208
302
  export declare interface LoggerService {
@@ -213,11 +307,6 @@ export declare interface LoggerService {
213
307
  child(meta: LogMeta): LoggerService;
214
308
  }
215
309
 
216
- /**
217
- * @public
218
- */
219
- declare const loggerServiceRef: ServiceRef<LoggerService, "plugin">;
220
-
221
310
  /** @public */
222
311
  export declare function loggerToWinstonLogger(logger: LoggerService, opts?: TransportStreamOptions): Logger;
223
312
 
@@ -229,40 +318,260 @@ export declare type LogMeta = {
229
318
  };
230
319
 
231
320
  /** @public */
232
- export declare type PermissionsService = PermissionEvaluator | PermissionAuthorizer;
321
+ export declare interface PermissionsService extends PermissionEvaluator {
322
+ }
233
323
 
234
324
  /**
235
325
  * @public
236
326
  */
237
- declare const permissionsServiceRef: ServiceRef<PermissionsService, "plugin">;
327
+ export declare interface PluginMetadataService {
328
+ getId(): string;
329
+ }
238
330
 
239
331
  /**
332
+ * An options object for {@link UrlReaderService.readTree} operations.
333
+ *
240
334
  * @public
241
335
  */
242
- export declare interface PluginMetadataService {
243
- getId(): string;
244
- }
336
+ export declare type ReadTreeOptions = {
337
+ /**
338
+ * A filter that can be used to select which files should be included.
339
+ *
340
+ * @remarks
341
+ *
342
+ * The path passed to the filter function is the relative path from the URL
343
+ * that the file tree is fetched from, without any leading '/'.
344
+ *
345
+ * For example, given the URL https://github.com/my/repo/tree/master/my-dir, a file
346
+ * at https://github.com/my/repo/blob/master/my-dir/my-subdir/my-file.txt will
347
+ * be represented as my-subdir/my-file.txt
348
+ *
349
+ * If no filter is provided, all files are extracted.
350
+ */
351
+ filter?(path: string, info?: {
352
+ size: number;
353
+ }): boolean;
354
+ /**
355
+ * An ETag which can be provided to check whether a
356
+ * {@link UrlReaderService.readTree} response has changed from a previous execution.
357
+ *
358
+ * @remarks
359
+ *
360
+ * In the {@link UrlReaderService.readTree} response, an ETag is returned along with
361
+ * the tree blob. The ETag is a unique identifier of the tree blob, usually
362
+ * the commit SHA or ETag from the target.
363
+ *
364
+ * When an ETag is given as a request option, {@link UrlReaderService.readTree} will
365
+ * first compare the ETag against the ETag on the target branch. If they
366
+ * match, {@link UrlReaderService.readTree} will throw a
367
+ * {@link @backstage/errors#NotModifiedError} indicating that the response
368
+ * will not differ from the previous response which included this particular
369
+ * ETag. If they do not match, {@link UrlReaderService.readTree} will return the
370
+ * rest of the response along with a new ETag.
371
+ */
372
+ etag?: string;
373
+ /**
374
+ * An abort signal to pass down to the underlying request.
375
+ *
376
+ * @remarks
377
+ *
378
+ * Not all reader implementations may take this field into account.
379
+ */
380
+ signal?: AbortSignal;
381
+ };
245
382
 
246
383
  /**
384
+ * A response object for {@link UrlReaderService.readTree} operations.
385
+ *
247
386
  * @public
248
387
  */
249
- declare const pluginMetadataServiceRef: ServiceRef<PluginMetadataService, "plugin">;
388
+ export declare type ReadTreeResponse = {
389
+ /**
390
+ * Returns an array of all the files inside the tree, and corresponding
391
+ * functions to read their content.
392
+ */
393
+ files(): Promise<ReadTreeResponseFile[]>;
394
+ /**
395
+ * Returns the tree contents as a binary archive, using a stream.
396
+ */
397
+ archive(): Promise<NodeJS.ReadableStream>;
398
+ /**
399
+ * Extracts the tree response into a directory and returns the path of the
400
+ * directory.
401
+ *
402
+ * **NOTE**: It is the responsibility of the caller to remove the directory after use.
403
+ */
404
+ dir(options?: ReadTreeResponseDirOptions): Promise<string>;
405
+ /**
406
+ * Etag returned by content provider.
407
+ *
408
+ * @remarks
409
+ *
410
+ * Can be used to compare and cache responses when doing subsequent calls.
411
+ */
412
+ etag: string;
413
+ };
250
414
 
251
- /** @public */
252
- export declare type RootLoggerService = LoggerService;
415
+ /**
416
+ * Options that control {@link ReadTreeResponse.dir} execution.
417
+ *
418
+ * @public
419
+ */
420
+ export declare type ReadTreeResponseDirOptions = {
421
+ /**
422
+ * The directory to write files to.
423
+ *
424
+ * @remarks
425
+ *
426
+ * Defaults to the OS tmpdir, or `backend.workingDirectory` if set in config.
427
+ */
428
+ targetDir?: string;
429
+ };
430
+
431
+ /**
432
+ * Represents a single file in a {@link UrlReaderService.readTree} response.
433
+ *
434
+ * @public
435
+ */
436
+ export declare type ReadTreeResponseFile = {
437
+ path: string;
438
+ content(): Promise<Buffer>;
439
+ };
253
440
 
254
441
  /**
442
+ * An options object for readUrl operations.
443
+ *
255
444
  * @public
256
445
  */
257
- declare const rootLoggerServiceRef: ServiceRef<LoggerService, "root">;
446
+ export declare type ReadUrlOptions = {
447
+ /**
448
+ * An ETag which can be provided to check whether a
449
+ * {@link UrlReaderService.readUrl} response has changed from a previous execution.
450
+ *
451
+ * @remarks
452
+ *
453
+ * In the {@link UrlReaderService.readUrl} response, an ETag is returned along with
454
+ * the data. The ETag is a unique identifier of the data, usually the commit
455
+ * SHA or ETag from the target.
456
+ *
457
+ * When an ETag is given in ReadUrlOptions, {@link UrlReaderService.readUrl} will
458
+ * first compare the ETag against the ETag of the target. If they match,
459
+ * {@link UrlReaderService.readUrl} will throw a
460
+ * {@link @backstage/errors#NotModifiedError} indicating that the response
461
+ * will not differ from the previous response which included this particular
462
+ * ETag. If they do not match, {@link UrlReaderService.readUrl} will return the rest
463
+ * of the response along with a new ETag.
464
+ */
465
+ etag?: string;
466
+ /**
467
+ * An abort signal to pass down to the underlying request.
468
+ *
469
+ * @remarks
470
+ *
471
+ * Not all reader implementations may take this field into account.
472
+ */
473
+ signal?: AbortSignal;
474
+ };
475
+
476
+ /**
477
+ * A response object for {@link UrlReaderService.readUrl} operations.
478
+ *
479
+ * @public
480
+ */
481
+ export declare type ReadUrlResponse = {
482
+ /**
483
+ * Returns the data that was read from the remote URL.
484
+ */
485
+ buffer(): Promise<Buffer>;
486
+ /**
487
+ * Returns the data that was read from the remote URL as a Readable stream.
488
+ *
489
+ * @remarks
490
+ *
491
+ * This method will be required in a future release.
492
+ */
493
+ stream?(): Readable;
494
+ /**
495
+ * Etag returned by content provider.
496
+ *
497
+ * @remarks
498
+ *
499
+ * Can be used to compare and cache responses when doing subsequent calls.
500
+ */
501
+ etag?: string;
502
+ };
503
+
504
+ /** @public */
505
+ export declare interface RootLifecycleService extends LifecycleService {
506
+ }
507
+
508
+ /** @public */
509
+ export declare interface RootLoggerService extends LoggerService {
510
+ }
258
511
 
259
512
  /** @public */
260
- export declare type SchedulerService = PluginTaskScheduler;
513
+ export declare interface SchedulerService extends PluginTaskScheduler {
514
+ }
515
+
516
+ /**
517
+ * An options object for search operations.
518
+ *
519
+ * @public
520
+ */
521
+ export declare type SearchOptions = {
522
+ /**
523
+ * An etag can be provided to check whether the search response has changed from a previous execution.
524
+ *
525
+ * In the search() response, an etag is returned along with the files. The etag is a unique identifier
526
+ * of the current tree, usually the commit SHA or etag from the target.
527
+ *
528
+ * When an etag is given in SearchOptions, search will first compare the etag against the etag
529
+ * on the target branch. If they match, search will throw a NotModifiedError indicating that the search
530
+ * response will not differ from the previous response which included this particular etag. If they mismatch,
531
+ * search will return the rest of SearchResponse along with a new etag.
532
+ */
533
+ etag?: string;
534
+ /**
535
+ * An abort signal to pass down to the underlying request.
536
+ *
537
+ * @remarks
538
+ *
539
+ * Not all reader implementations may take this field into account.
540
+ */
541
+ signal?: AbortSignal;
542
+ };
543
+
544
+ /**
545
+ * The output of a search operation.
546
+ *
547
+ * @public
548
+ */
549
+ export declare type SearchResponse = {
550
+ /**
551
+ * The files that matched the search query.
552
+ */
553
+ files: SearchResponseFile[];
554
+ /**
555
+ * A unique identifier of the current remote tree, usually the commit SHA or etag from the target.
556
+ */
557
+ etag: string;
558
+ };
261
559
 
262
560
  /**
561
+ * Represents a single file in a search response.
562
+ *
263
563
  * @public
264
564
  */
265
- declare const schedulerServiceRef: ServiceRef<PluginTaskScheduler, "plugin">;
565
+ export declare type SearchResponseFile = {
566
+ /**
567
+ * The full URL to the file.
568
+ */
569
+ url: string;
570
+ /**
571
+ * The binary contents of the file.
572
+ */
573
+ content(): Promise<Buffer>;
574
+ };
266
575
 
267
576
  /** @public */
268
577
  export declare type ServiceFactory<TService = unknown> = {
@@ -323,24 +632,32 @@ declare type ServiceRefsToInstances<T extends {
323
632
  };
324
633
 
325
634
  /** @public */
326
- export declare type TokenManagerService = TokenManager;
327
-
328
- /**
329
- * @public
330
- */
331
- declare const tokenManagerServiceRef: ServiceRef<TokenManager, "plugin">;
635
+ export declare interface TokenManagerService extends TokenManager {
636
+ }
332
637
 
333
638
  /** @public */
334
639
  export declare type TypesToServiceRef<T> = {
335
640
  [key in keyof T]: ServiceRef<T[key]>;
336
641
  };
337
642
 
338
- /** @public */
339
- export declare type UrlReaderService = UrlReader;
340
-
341
643
  /**
644
+ * A generic interface for fetching plain data from URLs.
645
+ *
342
646
  * @public
343
647
  */
344
- declare const urlReaderServiceRef: ServiceRef<UrlReader, "plugin">;
648
+ export declare interface UrlReaderService {
649
+ /**
650
+ * Reads a single file and return its content.
651
+ */
652
+ readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
653
+ /**
654
+ * Reads a full or partial file tree.
655
+ */
656
+ readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
657
+ /**
658
+ * Searches for a file in a tree using a glob pattern.
659
+ */
660
+ search(url: string, options?: SearchOptions): Promise<SearchResponse>;
661
+ }
345
662
 
346
663
  export { }