@backstage/backend-plugin-api 0.2.0-next.3 → 0.2.1-next.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.
package/dist/index.d.ts CHANGED
@@ -4,18 +4,19 @@
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
- import { Logger as Logger_2 } from 'winston';
11
+ import { Logger } from 'winston';
10
12
  import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
11
13
  import { PermissionEvaluator } from '@backstage/plugin-permission-common';
12
14
  import { PluginCacheManager } from '@backstage/backend-common';
13
15
  import { PluginDatabaseManager } from '@backstage/backend-common';
14
- import { PluginEndpointDiscovery } from '@backstage/backend-common';
15
16
  import { PluginTaskScheduler } from '@backstage/backend-tasks';
17
+ import { Readable } from 'stream';
16
18
  import { TokenManager } from '@backstage/backend-common';
17
19
  import { TransportStreamOptions } from 'winston-transport';
18
- import { UrlReader } from '@backstage/backend-common';
19
20
 
20
21
  /** @public */
21
22
  export declare interface BackendFeature {
@@ -23,23 +24,6 @@ export declare interface BackendFeature {
23
24
  register(reg: BackendRegistrationPoints): void;
24
25
  }
25
26
 
26
- /**
27
- * @public
28
- **/
29
- export declare interface BackendLifecycle {
30
- /**
31
- * Register a function to be called when the backend is shutting down.
32
- */
33
- addShutdownHook(options: BackendLifecycleShutdownHook): void;
34
- }
35
-
36
- /**
37
- * @public
38
- **/
39
- export declare type BackendLifecycleShutdownHook = {
40
- fn: () => void | Promise<void>;
41
- };
42
-
43
27
  /** @public */
44
28
  export declare interface BackendModuleConfig<TOptions> {
45
29
  pluginId: string;
@@ -66,11 +50,19 @@ export declare interface BackendRegistrationPoints {
66
50
  }): void;
67
51
  }
68
52
 
53
+ /** @public */
54
+ export declare type CacheService = PluginCacheManager;
55
+
69
56
  /**
70
57
  * @public
71
58
  */
72
59
  declare const cacheServiceRef: ServiceRef<PluginCacheManager, "plugin">;
73
60
 
61
+ /**
62
+ * @public
63
+ */
64
+ export declare type ConfigService = Config;
65
+
74
66
  /**
75
67
  * @public
76
68
  */
@@ -88,6 +80,7 @@ declare namespace coreServices {
88
80
  tokenManagerServiceRef as tokenManager,
89
81
  permissionsServiceRef as permissions,
90
82
  schedulerServiceRef as scheduler,
83
+ rootLifecycleServiceRef as rootLifecycle,
91
84
  rootLoggerServiceRef as rootLogger,
92
85
  pluginMetadataServiceRef as pluginMetadata,
93
86
  lifecycleServiceRef as lifecycle
@@ -145,15 +138,65 @@ export declare function createServiceRef<T>(options: {
145
138
  defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
146
139
  }): ServiceRef<T, 'root'>;
147
140
 
141
+ /** @public */
142
+ export declare type DatabaseService = PluginDatabaseManager;
143
+
148
144
  /**
149
145
  * @public
150
146
  */
151
147
  declare const databaseServiceRef: ServiceRef<PluginDatabaseManager, "plugin">;
152
148
 
149
+ /**
150
+ * The DiscoveryService is used to provide a mechanism for backend
151
+ * plugins to discover the endpoints for itself or other backend plugins.
152
+ *
153
+ * The purpose of the discovery API is to allow for many different deployment
154
+ * setups and routing methods through a central configuration, instead
155
+ * of letting each individual plugin manage that configuration.
156
+ *
157
+ * Implementations of the discovery API can be as simple as a URL pattern
158
+ * using the pluginId, but could also have overrides for individual plugins,
159
+ * or query a separate discovery service.
160
+ *
161
+ * @public
162
+ */
163
+ export declare type DiscoveryService = {
164
+ /**
165
+ * Returns the internal HTTP base URL for a given plugin, without a trailing slash.
166
+ *
167
+ * The returned URL should point to an internal endpoint for the plugin, with
168
+ * the shortest route possible. The URL should be used for service-to-service
169
+ * communication within a Backstage backend deployment.
170
+ *
171
+ * This method must always be called just before making a request, as opposed to
172
+ * fetching the URL when constructing an API client. That is to ensure that more
173
+ * flexible routing patterns can be supported.
174
+ *
175
+ * For example, asking for the URL for `catalog` may return something
176
+ * like `http://10.1.2.3/api/catalog`
177
+ */
178
+ getBaseUrl(pluginId: string): Promise<string>;
179
+ /**
180
+ * Returns the external HTTP base backend URL for a given plugin, without a trailing slash.
181
+ *
182
+ * The returned URL should point to an external endpoint for the plugin, such that
183
+ * it is reachable from the Backstage frontend and other external services. The returned
184
+ * URL should be usable for example as a callback / webhook URL.
185
+ *
186
+ * The returned URL should be stable and in general not change unless other static
187
+ * or external configuration is changed. Changes should not come as a surprise
188
+ * to an operator of the Backstage backend.
189
+ *
190
+ * For example, asking for the URL for `catalog` may return something
191
+ * like `https://backstage.example.com/api/catalog`
192
+ */
193
+ getExternalBaseUrl(pluginId: string): Promise<string>;
194
+ };
195
+
153
196
  /**
154
197
  * @public
155
198
  */
156
- declare const discoveryServiceRef: ServiceRef<PluginEndpointDiscovery, "plugin">;
199
+ declare const discoveryServiceRef: ServiceRef<DiscoveryService, "plugin">;
157
200
 
158
201
  /**
159
202
  * TODO
@@ -183,56 +226,333 @@ export declare interface HttpRouterService {
183
226
  */
184
227
  declare const httpRouterServiceRef: ServiceRef<HttpRouterService, "plugin">;
185
228
 
229
+ /**
230
+ * @public
231
+ **/
232
+ export declare interface LifecycleService {
233
+ /**
234
+ * Register a function to be called when the backend is shutting down.
235
+ */
236
+ addShutdownHook(options: LifecycleServiceShutdownHook): void;
237
+ }
238
+
186
239
  /**
187
240
  * @public
188
241
  */
189
- declare const lifecycleServiceRef: ServiceRef<BackendLifecycle, "plugin">;
242
+ declare const lifecycleServiceRef: ServiceRef<LifecycleService, "plugin">;
243
+
244
+ /**
245
+ * @public
246
+ **/
247
+ export declare type LifecycleServiceShutdownHook = {
248
+ fn: () => void | Promise<void>;
249
+ /** Labels to help identify the shutdown hook */
250
+ labels?: Record<string, string>;
251
+ };
190
252
 
191
253
  /**
192
254
  * @public
193
255
  */
194
- export declare interface Logger {
195
- info(message: string): void;
196
- child(fields: {
197
- [name: string]: string;
198
- }): Logger;
256
+ export declare interface LoggerService {
257
+ error(message: string, meta?: Error | LogMeta): void;
258
+ warn(message: string, meta?: Error | LogMeta): void;
259
+ info(message: string, meta?: Error | LogMeta): void;
260
+ debug(message: string, meta?: Error | LogMeta): void;
261
+ child(meta: LogMeta): LoggerService;
199
262
  }
200
263
 
201
264
  /**
202
265
  * @public
203
266
  */
204
- declare const loggerServiceRef: ServiceRef<Logger, "plugin">;
267
+ declare const loggerServiceRef: ServiceRef<LoggerService, "plugin">;
205
268
 
206
269
  /** @public */
207
- export declare function loggerToWinstonLogger(logger: Logger, opts?: TransportStreamOptions): Logger_2;
270
+ export declare function loggerToWinstonLogger(logger: LoggerService, opts?: TransportStreamOptions): Logger;
208
271
 
209
272
  /**
210
273
  * @public
211
274
  */
212
- declare const permissionsServiceRef: ServiceRef<PermissionAuthorizer | PermissionEvaluator, "plugin">;
275
+ export declare type LogMeta = {
276
+ [name: string]: unknown;
277
+ };
278
+
279
+ /** @public */
280
+ export declare type PermissionsService = PermissionEvaluator | PermissionAuthorizer;
213
281
 
214
282
  /**
215
283
  * @public
216
284
  */
217
- export declare interface PluginMetadata {
285
+ declare const permissionsServiceRef: ServiceRef<PermissionsService, "plugin">;
286
+
287
+ /**
288
+ * @public
289
+ */
290
+ export declare interface PluginMetadataService {
218
291
  getId(): string;
219
292
  }
220
293
 
221
294
  /**
222
295
  * @public
223
296
  */
224
- declare const pluginMetadataServiceRef: ServiceRef<PluginMetadata, "plugin">;
297
+ declare const pluginMetadataServiceRef: ServiceRef<PluginMetadataService, "plugin">;
225
298
 
226
299
  /**
300
+ * An options object for {@link UrlReaderService.readTree} operations.
301
+ *
227
302
  * @public
228
303
  */
229
- declare const rootLoggerServiceRef: ServiceRef<Logger, "root">;
304
+ export declare type ReadTreeOptions = {
305
+ /**
306
+ * A filter that can be used to select which files should be included.
307
+ *
308
+ * @remarks
309
+ *
310
+ * The path passed to the filter function is the relative path from the URL
311
+ * that the file tree is fetched from, without any leading '/'.
312
+ *
313
+ * For example, given the URL https://github.com/my/repo/tree/master/my-dir, a file
314
+ * at https://github.com/my/repo/blob/master/my-dir/my-subdir/my-file.txt will
315
+ * be represented as my-subdir/my-file.txt
316
+ *
317
+ * If no filter is provided, all files are extracted.
318
+ */
319
+ filter?(path: string, info?: {
320
+ size: number;
321
+ }): boolean;
322
+ /**
323
+ * An ETag which can be provided to check whether a
324
+ * {@link UrlReaderService.readTree} response has changed from a previous execution.
325
+ *
326
+ * @remarks
327
+ *
328
+ * In the {@link UrlReaderService.readTree} response, an ETag is returned along with
329
+ * the tree blob. The ETag is a unique identifier of the tree blob, usually
330
+ * the commit SHA or ETag from the target.
331
+ *
332
+ * When an ETag is given as a request option, {@link UrlReaderService.readTree} will
333
+ * first compare the ETag against the ETag on the target branch. If they
334
+ * match, {@link UrlReaderService.readTree} will throw a
335
+ * {@link @backstage/errors#NotModifiedError} indicating that the response
336
+ * will not differ from the previous response which included this particular
337
+ * ETag. If they do not match, {@link UrlReaderService.readTree} will return the
338
+ * rest of the response along with a new ETag.
339
+ */
340
+ etag?: string;
341
+ /**
342
+ * An abort signal to pass down to the underlying request.
343
+ *
344
+ * @remarks
345
+ *
346
+ * Not all reader implementations may take this field into account.
347
+ */
348
+ signal?: AbortSignal;
349
+ };
350
+
351
+ /**
352
+ * A response object for {@link UrlReaderService.readTree} operations.
353
+ *
354
+ * @public
355
+ */
356
+ export declare type ReadTreeResponse = {
357
+ /**
358
+ * Returns an array of all the files inside the tree, and corresponding
359
+ * functions to read their content.
360
+ */
361
+ files(): Promise<ReadTreeResponseFile[]>;
362
+ /**
363
+ * Returns the tree contents as a binary archive, using a stream.
364
+ */
365
+ archive(): Promise<NodeJS.ReadableStream>;
366
+ /**
367
+ * Extracts the tree response into a directory and returns the path of the
368
+ * directory.
369
+ *
370
+ * **NOTE**: It is the responsibility of the caller to remove the directory after use.
371
+ */
372
+ dir(options?: ReadTreeResponseDirOptions): Promise<string>;
373
+ /**
374
+ * Etag returned by content provider.
375
+ *
376
+ * @remarks
377
+ *
378
+ * Can be used to compare and cache responses when doing subsequent calls.
379
+ */
380
+ etag: string;
381
+ };
382
+
383
+ /**
384
+ * Options that control {@link ReadTreeResponse.dir} execution.
385
+ *
386
+ * @public
387
+ */
388
+ export declare type ReadTreeResponseDirOptions = {
389
+ /**
390
+ * The directory to write files to.
391
+ *
392
+ * @remarks
393
+ *
394
+ * Defaults to the OS tmpdir, or `backend.workingDirectory` if set in config.
395
+ */
396
+ targetDir?: string;
397
+ };
398
+
399
+ /**
400
+ * Represents a single file in a {@link UrlReaderService.readTree} response.
401
+ *
402
+ * @public
403
+ */
404
+ export declare type ReadTreeResponseFile = {
405
+ path: string;
406
+ content(): Promise<Buffer>;
407
+ };
408
+
409
+ /**
410
+ * An options object for readUrl operations.
411
+ *
412
+ * @public
413
+ */
414
+ export declare type ReadUrlOptions = {
415
+ /**
416
+ * An ETag which can be provided to check whether a
417
+ * {@link UrlReaderService.readUrl} response has changed from a previous execution.
418
+ *
419
+ * @remarks
420
+ *
421
+ * In the {@link UrlReaderService.readUrl} response, an ETag is returned along with
422
+ * the data. The ETag is a unique identifier of the data, usually the commit
423
+ * SHA or ETag from the target.
424
+ *
425
+ * When an ETag is given in ReadUrlOptions, {@link UrlReaderService.readUrl} will
426
+ * first compare the ETag against the ETag of the target. If they match,
427
+ * {@link UrlReaderService.readUrl} will throw a
428
+ * {@link @backstage/errors#NotModifiedError} indicating that the response
429
+ * will not differ from the previous response which included this particular
430
+ * ETag. If they do not match, {@link UrlReaderService.readUrl} will return the rest
431
+ * of the response along with a new ETag.
432
+ */
433
+ etag?: string;
434
+ /**
435
+ * An abort signal to pass down to the underlying request.
436
+ *
437
+ * @remarks
438
+ *
439
+ * Not all reader implementations may take this field into account.
440
+ */
441
+ signal?: AbortSignal;
442
+ };
443
+
444
+ /**
445
+ * A response object for {@link UrlReaderService.readUrl} operations.
446
+ *
447
+ * @public
448
+ */
449
+ export declare type ReadUrlResponse = {
450
+ /**
451
+ * Returns the data that was read from the remote URL.
452
+ */
453
+ buffer(): Promise<Buffer>;
454
+ /**
455
+ * Returns the data that was read from the remote URL as a Readable stream.
456
+ *
457
+ * @remarks
458
+ *
459
+ * This method will be required in a future release.
460
+ */
461
+ stream?(): Readable;
462
+ /**
463
+ * Etag returned by content provider.
464
+ *
465
+ * @remarks
466
+ *
467
+ * Can be used to compare and cache responses when doing subsequent calls.
468
+ */
469
+ etag?: string;
470
+ };
471
+
472
+ /** @public */
473
+ export declare type RootLifecycleService = LifecycleService;
474
+
475
+ /**
476
+ * @public
477
+ */
478
+ declare const rootLifecycleServiceRef: ServiceRef<LifecycleService, "root">;
479
+
480
+ /** @public */
481
+ export declare type RootLoggerService = LoggerService;
482
+
483
+ /**
484
+ * @public
485
+ */
486
+ declare const rootLoggerServiceRef: ServiceRef<LoggerService, "root">;
487
+
488
+ /** @public */
489
+ export declare type SchedulerService = PluginTaskScheduler;
230
490
 
231
491
  /**
232
492
  * @public
233
493
  */
234
494
  declare const schedulerServiceRef: ServiceRef<PluginTaskScheduler, "plugin">;
235
495
 
496
+ /**
497
+ * An options object for search operations.
498
+ *
499
+ * @public
500
+ */
501
+ export declare type SearchOptions = {
502
+ /**
503
+ * An etag can be provided to check whether the search response has changed from a previous execution.
504
+ *
505
+ * In the search() response, an etag is returned along with the files. The etag is a unique identifier
506
+ * of the current tree, usually the commit SHA or etag from the target.
507
+ *
508
+ * When an etag is given in SearchOptions, search will first compare the etag against the etag
509
+ * on the target branch. If they match, search will throw a NotModifiedError indicating that the search
510
+ * response will not differ from the previous response which included this particular etag. If they mismatch,
511
+ * search will return the rest of SearchResponse along with a new etag.
512
+ */
513
+ etag?: string;
514
+ /**
515
+ * An abort signal to pass down to the underlying request.
516
+ *
517
+ * @remarks
518
+ *
519
+ * Not all reader implementations may take this field into account.
520
+ */
521
+ signal?: AbortSignal;
522
+ };
523
+
524
+ /**
525
+ * The output of a search operation.
526
+ *
527
+ * @public
528
+ */
529
+ export declare type SearchResponse = {
530
+ /**
531
+ * The files that matched the search query.
532
+ */
533
+ files: SearchResponseFile[];
534
+ /**
535
+ * A unique identifier of the current remote tree, usually the commit SHA or etag from the target.
536
+ */
537
+ etag: string;
538
+ };
539
+
540
+ /**
541
+ * Represents a single file in a search response.
542
+ *
543
+ * @public
544
+ */
545
+ export declare type SearchResponseFile = {
546
+ /**
547
+ * The full URL to the file.
548
+ */
549
+ url: string;
550
+ /**
551
+ * The binary contents of the file.
552
+ */
553
+ content(): Promise<Buffer>;
554
+ };
555
+
236
556
  /** @public */
237
557
  export declare type ServiceFactory<TService = unknown> = {
238
558
  scope: 'root';
@@ -291,6 +611,9 @@ declare type ServiceRefsToInstances<T extends {
291
611
  }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
292
612
  };
293
613
 
614
+ /** @public */
615
+ export declare type TokenManagerService = TokenManager;
616
+
294
617
  /**
295
618
  * @public
296
619
  */
@@ -301,9 +624,29 @@ export declare type TypesToServiceRef<T> = {
301
624
  [key in keyof T]: ServiceRef<T[key]>;
302
625
  };
303
626
 
627
+ /**
628
+ * A generic interface for fetching plain data from URLs.
629
+ *
630
+ * @public
631
+ */
632
+ export declare type UrlReaderService = {
633
+ /**
634
+ * Reads a single file and return its content.
635
+ */
636
+ readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
637
+ /**
638
+ * Reads a full or partial file tree.
639
+ */
640
+ readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
641
+ /**
642
+ * Searches for a file in a tree using a glob pattern.
643
+ */
644
+ search(url: string, options?: SearchOptions): Promise<SearchResponse>;
645
+ };
646
+
304
647
  /**
305
648
  * @public
306
649
  */
307
- declare const urlReaderServiceRef: ServiceRef<UrlReader, "plugin">;
650
+ declare const urlReaderServiceRef: ServiceRef<UrlReaderService, "plugin">;
308
651
 
309
652
  export { }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/backend-plugin-api",
3
3
  "description": "Core API used by Backstage backend plugins",
4
- "version": "0.2.0-next.3",
4
+ "version": "0.2.1-next.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {
@@ -33,17 +33,17 @@
33
33
  "start": "backstage-cli package start"
34
34
  },
35
35
  "dependencies": {
36
- "@backstage/backend-common": "^0.17.0-next.3",
37
- "@backstage/backend-tasks": "^0.4.0-next.3",
38
- "@backstage/config": "^1.0.5-next.1",
39
- "@backstage/plugin-permission-common": "^0.7.2-next.2",
36
+ "@backstage/backend-common": "^0.18.0-next.0",
37
+ "@backstage/backend-tasks": "^0.4.1-next.0",
38
+ "@backstage/config": "^1.0.6-next.0",
39
+ "@backstage/plugin-permission-common": "^0.7.3-next.0",
40
40
  "@types/express": "^4.17.6",
41
41
  "express": "^4.17.1",
42
42
  "winston": "^3.2.1",
43
43
  "winston-transport": "^4.5.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@backstage/cli": "^0.22.0-next.4"
46
+ "@backstage/cli": "^0.22.1-next.1"
47
47
  },
48
48
  "files": [
49
49
  "dist",