@backstage/backend-plugin-api 0.4.0-next.2 → 0.4.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.
@@ -1,956 +0,0 @@
1
- /**
2
- * Core API used by Backstage backend plugins.
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- /// <reference types="node" />
8
-
9
- import { Config } from '@backstage/config';
10
- import { Handler } from 'express';
11
- import { IdentityApi } from '@backstage/plugin-auth-node';
12
- import { JsonObject } from '@backstage/types';
13
- import { JsonValue } from '@backstage/types';
14
- import { Knex } from 'knex';
15
- import { PermissionEvaluator } from '@backstage/plugin-permission-common';
16
- import { PluginTaskScheduler } from '@backstage/backend-tasks';
17
- import { Readable } from 'stream';
18
-
19
- /** @public */
20
- export declare interface BackendFeature {
21
- $$type: '@backstage/BackendFeature';
22
- }
23
-
24
- /**
25
- * The configuration options passed to {@link createBackendModule}.
26
- *
27
- * @public
28
- * @see {@link https://backstage.io/docs/backend-system/architecture/modules | The architecture of modules}
29
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
30
- */
31
- export declare interface BackendModuleConfig {
32
- /**
33
- * The ID of this plugin.
34
- *
35
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
36
- */
37
- pluginId: string;
38
- /**
39
- * Should exactly match the `id` of the plugin that the module extends.
40
- */
41
- moduleId: string;
42
- register(reg: BackendModuleRegistrationPoints): void;
43
- }
44
-
45
- /**
46
- * The callbacks passed to the `register` method of a backend module.
47
- *
48
- * @public
49
- */
50
- export declare interface BackendModuleRegistrationPoints {
51
- registerInit<Deps extends {
52
- [name in string]: unknown;
53
- }>(options: {
54
- deps: {
55
- [name in keyof Deps]: ServiceRef<Deps[name]> | ExtensionPoint<Deps[name]>;
56
- };
57
- init(deps: Deps): Promise<void>;
58
- }): void;
59
- }
60
-
61
- /**
62
- * The configuration options passed to {@link createBackendPlugin}.
63
- *
64
- * @public
65
- * @see {@link https://backstage.io/docs/backend-system/architecture/plugins | The architecture of plugins}
66
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
67
- */
68
- export declare interface BackendPluginConfig {
69
- /**
70
- * The ID of this plugin.
71
- *
72
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
73
- */
74
- pluginId: string;
75
- register(reg: BackendPluginRegistrationPoints): void;
76
- }
77
-
78
- /**
79
- * The callbacks passed to the `register` method of a backend plugin.
80
- *
81
- * @public
82
- */
83
- export declare interface BackendPluginRegistrationPoints {
84
- registerExtensionPoint<TExtensionPoint>(ref: ExtensionPoint<TExtensionPoint>, impl: TExtensionPoint): void;
85
- registerInit<Deps extends {
86
- [name in string]: unknown;
87
- }>(options: {
88
- deps: {
89
- [name in keyof Deps]: ServiceRef<Deps[name]>;
90
- };
91
- init(deps: Deps): Promise<void>;
92
- }): void;
93
- }
94
-
95
- /**
96
- * A pre-configured, storage agnostic cache client suitable for use by
97
- * Backstage plugins.
98
- *
99
- * @public
100
- */
101
- export declare interface CacheClient {
102
- /**
103
- * Reads data from a cache store for the given key. If no data was found,
104
- * returns undefined.
105
- */
106
- get(key: string): Promise<JsonValue | undefined>;
107
- /**
108
- * Writes the given data to a cache store, associated with the given key. An
109
- * optional TTL may also be provided, otherwise it defaults to the TTL that
110
- * was provided when the client was instantiated.
111
- */
112
- set(key: string, value: JsonValue, options?: CacheClientSetOptions): Promise<void>;
113
- /**
114
- * Removes the given key from the cache store.
115
- */
116
- delete(key: string): Promise<void>;
117
- }
118
-
119
- /**
120
- * Options given when constructing a {@link CacheClient}.
121
- *
122
- * @public
123
- */
124
- export declare type CacheClientOptions = {
125
- /**
126
- * An optional default TTL (in milliseconds) to be set when getting a client
127
- * instance. If not provided, data will persist indefinitely by default (or
128
- * can be configured per entry at set-time).
129
- */
130
- defaultTtl?: number;
131
- };
132
-
133
- /**
134
- * Options passed to {@link CacheClient.set}.
135
- *
136
- * @public
137
- */
138
- export declare type CacheClientSetOptions = {
139
- /**
140
- * Optional TTL in milliseconds. Defaults to the TTL provided when the client
141
- * was set up (or no TTL if none are provided).
142
- */
143
- ttl?: number;
144
- };
145
-
146
- /**
147
- * Manages access to cache stores that plugins get.
148
- *
149
- * @public
150
- */
151
- export declare interface CacheService {
152
- /**
153
- * Provides backend plugins cache connections for themselves.
154
- *
155
- * @remarks
156
- *
157
- * The purpose of this method is to allow plugins to get isolated data stores
158
- * so that plugins are discouraged from cache-level integration and/or cache
159
- * key collisions.
160
- */
161
- getClient: (options?: CacheClientOptions) => CacheClient;
162
- }
163
-
164
- /**
165
- * @public
166
- */
167
- export declare interface ConfigService extends Config {
168
- }
169
-
170
- /**
171
- * All core services references
172
- *
173
- * @public
174
- */
175
- export declare namespace coreServices {
176
- /**
177
- * The service reference for the plugin scoped {@link CacheService}.
178
- *
179
- * @public
180
- */
181
- const cache: ServiceRef<CacheService, "plugin">;
182
- /**
183
- * The service reference for the root scoped {@link ConfigService}.
184
- *
185
- * @public
186
- */
187
- const config: ServiceRef<ConfigService, "root">;
188
- /**
189
- * The service reference for the plugin scoped {@link DatabaseService}.
190
- *
191
- * @public
192
- */
193
- const database: ServiceRef<DatabaseService, "plugin">;
194
- /**
195
- * The service reference for the plugin scoped {@link DiscoveryService}.
196
- *
197
- * @public
198
- */
199
- const discovery: ServiceRef<DiscoveryService, "plugin">;
200
- /**
201
- * The service reference for the plugin scoped {@link HttpRouterService}.
202
- *
203
- * @public
204
- */
205
- const httpRouter: ServiceRef<HttpRouterService, "plugin">;
206
- /**
207
- * The service reference for the plugin scoped {@link LifecycleService}.
208
- *
209
- * @public
210
- */
211
- const lifecycle: ServiceRef<LifecycleService, "plugin">;
212
- /**
213
- * The service reference for the plugin scoped {@link LoggerService}.
214
- *
215
- * @public
216
- */
217
- const logger: ServiceRef<LoggerService, "plugin">;
218
- /**
219
- * The service reference for the plugin scoped {@link PermissionsService}.
220
- *
221
- * @public
222
- */
223
- const permissions: ServiceRef<PermissionsService, "plugin">;
224
- /**
225
- * The service reference for the plugin scoped {@link PluginMetadataService}.
226
- *
227
- * @public
228
- */
229
- const pluginMetadata: ServiceRef<PluginMetadataService, "plugin">;
230
- /**
231
- * The service reference for the root scoped {@link RootHttpRouterService}.
232
- *
233
- * @public
234
- */
235
- const rootHttpRouter: ServiceRef<RootHttpRouterService, "root">;
236
- /**
237
- * The service reference for the root scoped {@link RootLifecycleService}.
238
- *
239
- * @public
240
- */
241
- const rootLifecycle: ServiceRef<RootLifecycleService, "root">;
242
- /**
243
- * The service reference for the root scoped {@link RootLoggerService}.
244
- *
245
- * @public
246
- */
247
- const rootLogger: ServiceRef<RootLoggerService, "root">;
248
- /**
249
- * The service reference for the plugin scoped {@link SchedulerService}.
250
- *
251
- * @public
252
- */
253
- const scheduler: ServiceRef<SchedulerService, "plugin">;
254
- /**
255
- * The service reference for the plugin scoped {@link TokenManagerService}.
256
- *
257
- * @public
258
- */
259
- const tokenManager: ServiceRef<TokenManagerService, "plugin">;
260
- /**
261
- * The service reference for the plugin scoped {@link UrlReaderService}.
262
- *
263
- * @public
264
- */
265
- const urlReader: ServiceRef<UrlReaderService, "plugin">;
266
- /**
267
- * The service reference for the plugin scoped {@link IdentityService}.
268
- *
269
- * @public
270
- */
271
- const identity: ServiceRef<IdentityService, "plugin">;
272
- }
273
-
274
- /**
275
- * Creates a new backend module for a given plugin.
276
- *
277
- * @public
278
- * @see {@link https://backstage.io/docs/backend-system/architecture/modules | The architecture of modules}
279
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
280
- */
281
- export declare function createBackendModule<TOptions extends [options?: object] = []>(config: BackendModuleConfig | ((...params: TOptions) => BackendModuleConfig)): (...params: TOptions) => BackendFeature;
282
-
283
- /**
284
- * Creates a new backend plugin.
285
- *
286
- * @public
287
- * @see {@link https://backstage.io/docs/backend-system/architecture/plugins | The architecture of plugins}
288
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
289
- */
290
- export declare function createBackendPlugin<TOptions extends [options?: object] = []>(config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig)): (...params: TOptions) => BackendFeature;
291
-
292
- /**
293
- * Creates a new backend extension point.
294
- *
295
- * @public
296
- * @see {@link https://backstage.io/docs/backend-system/architecture/extension-points | The architecture of extension points}
297
- */
298
- export declare function createExtensionPoint<T>(config: ExtensionPointConfig): ExtensionPoint<T>;
299
-
300
- /**
301
- * Creates a root scoped service factory without options.
302
- *
303
- * @public
304
- * @param config - The service factory configuration.
305
- */
306
- export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
307
- [name in string]: ServiceRef<unknown>;
308
- }, TOpts extends object | undefined = undefined>(config: RootServiceFactoryConfig<TService, TImpl, TDeps>): () => ServiceFactory<TService>;
309
-
310
- /**
311
- * Creates a root scoped service factory with optional options.
312
- *
313
- * @public
314
- * @param config - The service factory configuration.
315
- */
316
- export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
317
- [name in string]: ServiceRef<unknown>;
318
- }, TOpts extends object | undefined = undefined>(config: (options?: TOpts) => RootServiceFactoryConfig<TService, TImpl, TDeps>): (options?: TOpts) => ServiceFactory<TService>;
319
-
320
- /**
321
- * Creates a root scoped service factory with required options.
322
- *
323
- * @public
324
- * @param config - The service factory configuration.
325
- */
326
- export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
327
- [name in string]: ServiceRef<unknown>;
328
- }, TOpts extends object | undefined = undefined>(config: (options: TOpts) => RootServiceFactoryConfig<TService, TImpl, TDeps>): (options: TOpts) => ServiceFactory<TService>;
329
-
330
- /**
331
- * Creates a plugin scoped service factory without options.
332
- *
333
- * @public
334
- * @param config - The service factory configuration.
335
- */
336
- export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
337
- [name in string]: ServiceRef<unknown>;
338
- }, TContext = undefined, TOpts extends object | undefined = undefined>(config: PluginServiceFactoryConfig<TService, TContext, TImpl, TDeps>): () => ServiceFactory<TService>;
339
-
340
- /**
341
- * Creates a plugin scoped service factory with optional options.
342
- *
343
- * @public
344
- * @param config - The service factory configuration.
345
- */
346
- export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
347
- [name in string]: ServiceRef<unknown>;
348
- }, TContext = undefined, TOpts extends object | undefined = undefined>(config: (options?: TOpts) => PluginServiceFactoryConfig<TService, TContext, TImpl, TDeps>): (options?: TOpts) => ServiceFactory<TService>;
349
-
350
- /**
351
- * Creates a plugin scoped service factory with required options.
352
- *
353
- * @public
354
- * @param config - The service factory configuration.
355
- */
356
- export declare function createServiceFactory<TService, TImpl extends TService, TDeps extends {
357
- [name in string]: ServiceRef<unknown>;
358
- }, TContext = undefined, TOpts extends object | undefined = undefined>(config: PluginServiceFactoryConfig<TService, TContext, TImpl, TDeps> | ((options: TOpts) => PluginServiceFactoryConfig<TService, TContext, TImpl, TDeps>)): (options: TOpts) => ServiceFactory<TService>;
359
-
360
- /**
361
- * Creates a new service definition. This overload is used to create plugin scoped services.
362
- *
363
- * @public
364
- */
365
- export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'plugin'>): ServiceRef<TService, 'plugin'>;
366
-
367
- /**
368
- * Creates a new service definition. This overload is used to create root scoped services.
369
- *
370
- * @public
371
- */
372
- export declare function createServiceRef<TService>(config: ServiceRefConfig<TService, 'root'>): ServiceRef<TService, 'root'>;
373
-
374
- /**
375
- * Creates a shared backend environment which can be used to create multiple
376
- * backends.
377
- *
378
- * @public
379
- */
380
- export declare function createSharedEnvironment<TOptions extends [options?: object] = []>(config: SharedBackendEnvironmentConfig | ((...params: TOptions) => SharedBackendEnvironmentConfig)): (...options: TOptions) => SharedBackendEnvironment;
381
-
382
- /**
383
- * The DatabaseService manages access to databases that Plugins get.
384
- *
385
- * @public
386
- */
387
- export declare interface DatabaseService {
388
- /**
389
- * getClient provides backend plugins database connections for itself.
390
- *
391
- * The purpose of this method is to allow plugins to get isolated data
392
- * stores so that plugins are discouraged from database integration.
393
- */
394
- getClient(): Promise<Knex>;
395
- /**
396
- * This property is used to control the behavior of database migrations.
397
- */
398
- migrations?: {
399
- /**
400
- * skip database migrations. Useful if connecting to a read-only database.
401
- *
402
- * @defaultValue false
403
- */
404
- skip?: boolean;
405
- };
406
- }
407
-
408
- /**
409
- * The DiscoveryService is used to provide a mechanism for backend
410
- * plugins to discover the endpoints for itself or other backend plugins.
411
- *
412
- * The purpose of the discovery API is to allow for many different deployment
413
- * setups and routing methods through a central configuration, instead
414
- * of letting each individual plugin manage that configuration.
415
- *
416
- * Implementations of the discovery API can be as simple as a URL pattern
417
- * using the pluginId, but could also have overrides for individual plugins,
418
- * or query a separate discovery service.
419
- *
420
- * @public
421
- */
422
- export declare interface DiscoveryService {
423
- /**
424
- * Returns the internal HTTP base URL for a given plugin, without a trailing slash.
425
- *
426
- * The returned URL should point to an internal endpoint for the plugin, with
427
- * the shortest route possible. The URL should be used for service-to-service
428
- * communication within a Backstage backend deployment.
429
- *
430
- * This method must always be called just before making a request, as opposed to
431
- * fetching the URL when constructing an API client. That is to ensure that more
432
- * flexible routing patterns can be supported.
433
- *
434
- * For example, asking for the URL for `catalog` may return something
435
- * like `http://10.1.2.3/api/catalog`
436
- */
437
- getBaseUrl(pluginId: string): Promise<string>;
438
- /**
439
- * Returns the external HTTP base backend URL for a given plugin, without a trailing slash.
440
- *
441
- * The returned URL should point to an external endpoint for the plugin, such that
442
- * it is reachable from the Backstage frontend and other external services. The returned
443
- * URL should be usable for example as a callback / webhook URL.
444
- *
445
- * The returned URL should be stable and in general not change unless other static
446
- * or external configuration is changed. Changes should not come as a surprise
447
- * to an operator of the Backstage backend.
448
- *
449
- * For example, asking for the URL for `catalog` may return something
450
- * like `https://backstage.example.com/api/catalog`
451
- */
452
- getExternalBaseUrl(pluginId: string): Promise<string>;
453
- }
454
-
455
- /**
456
- * TODO
457
- *
458
- * @public
459
- */
460
- export declare type ExtensionPoint<T> = {
461
- id: string;
462
- /**
463
- * Utility for getting the type of the extension point, using `typeof extensionPoint.T`.
464
- * Attempting to actually read this value will result in an exception.
465
- */
466
- T: T;
467
- toString(): string;
468
- $$type: '@backstage/ExtensionPoint';
469
- };
470
-
471
- /**
472
- * The configuration options passed to {@link createExtensionPoint}.
473
- *
474
- * @public
475
- * @see {@link https://backstage.io/docs/backend-system/architecture/extension-points | The architecture of extension points}
476
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
477
- */
478
- export declare interface ExtensionPointConfig {
479
- /**
480
- * The ID of this extension point.
481
- *
482
- * @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
483
- */
484
- id: string;
485
- }
486
-
487
- /**
488
- * @public
489
- */
490
- export declare interface HttpRouterService {
491
- use(handler: Handler): void;
492
- }
493
-
494
- /** @public */
495
- export declare interface IdentityService extends IdentityApi {
496
- }
497
-
498
- /**
499
- * @public
500
- */
501
- export declare interface LifecycleService {
502
- /**
503
- * Register a function to be called when the backend is shutting down.
504
- */
505
- addShutdownHook(hook: LifecycleServiceShutdownHook, options?: LifecycleServiceShutdownOptions): void;
506
- }
507
-
508
- /**
509
- * @public
510
- */
511
- export declare type LifecycleServiceShutdownHook = () => void | Promise<void>;
512
-
513
- /**
514
- * @public
515
- */
516
- export declare interface LifecycleServiceShutdownOptions {
517
- /**
518
- * Optional {@link LoggerService} that will be used for logging instead of the default logger.
519
- */
520
- logger?: LoggerService;
521
- }
522
-
523
- /**
524
- * A service that provides a logging facility.
525
- *
526
- * @public
527
- */
528
- export declare interface LoggerService {
529
- error(message: string, meta?: Error | JsonObject): void;
530
- warn(message: string, meta?: Error | JsonObject): void;
531
- info(message: string, meta?: Error | JsonObject): void;
532
- debug(message: string, meta?: Error | JsonObject): void;
533
- child(meta: JsonObject): LoggerService;
534
- }
535
-
536
- /** @public */
537
- export declare interface PermissionsService extends PermissionEvaluator {
538
- }
539
-
540
- /**
541
- * @public
542
- */
543
- export declare interface PluginMetadataService {
544
- getId(): string;
545
- }
546
-
547
- /** @public */
548
- export declare interface PluginServiceFactoryConfig<TService, TContext, TImpl extends TService, TDeps extends {
549
- [name in string]: ServiceRef<unknown>;
550
- }> {
551
- service: ServiceRef<TService, 'plugin'>;
552
- deps: TDeps;
553
- createRootContext?(deps: ServiceRefsToInstances<TDeps, 'root'>): TContext | Promise<TContext>;
554
- factory(deps: ServiceRefsToInstances<TDeps>, context: TContext): TImpl | Promise<TImpl>;
555
- }
556
-
557
- /**
558
- * An options object for {@link UrlReaderService.readTree} operations.
559
- *
560
- * @public
561
- */
562
- export declare type ReadTreeOptions = {
563
- /**
564
- * A filter that can be used to select which files should be included.
565
- *
566
- * @remarks
567
- *
568
- * The path passed to the filter function is the relative path from the URL
569
- * that the file tree is fetched from, without any leading '/'.
570
- *
571
- * For example, given the URL https://github.com/my/repo/tree/master/my-dir, a file
572
- * at https://github.com/my/repo/blob/master/my-dir/my-subdir/my-file.txt will
573
- * be represented as my-subdir/my-file.txt
574
- *
575
- * If no filter is provided, all files are extracted.
576
- */
577
- filter?(path: string, info?: {
578
- size: number;
579
- }): boolean;
580
- /**
581
- * An ETag which can be provided to check whether a
582
- * {@link UrlReaderService.readTree} response has changed from a previous execution.
583
- *
584
- * @remarks
585
- *
586
- * In the {@link UrlReaderService.readTree} response, an ETag is returned along with
587
- * the tree blob. The ETag is a unique identifier of the tree blob, usually
588
- * the commit SHA or ETag from the target.
589
- *
590
- * When an ETag is given as a request option, {@link UrlReaderService.readTree} will
591
- * first compare the ETag against the ETag on the target branch. If they
592
- * match, {@link UrlReaderService.readTree} will throw a
593
- * {@link @backstage/errors#NotModifiedError} indicating that the response
594
- * will not differ from the previous response which included this particular
595
- * ETag. If they do not match, {@link UrlReaderService.readTree} will return the
596
- * rest of the response along with a new ETag.
597
- */
598
- etag?: string;
599
- /**
600
- * An abort signal to pass down to the underlying request.
601
- *
602
- * @remarks
603
- *
604
- * Not all reader implementations may take this field into account.
605
- */
606
- signal?: AbortSignal;
607
- };
608
-
609
- /**
610
- * A response object for {@link UrlReaderService.readTree} operations.
611
- *
612
- * @public
613
- */
614
- export declare type ReadTreeResponse = {
615
- /**
616
- * Returns an array of all the files inside the tree, and corresponding
617
- * functions to read their content.
618
- */
619
- files(): Promise<ReadTreeResponseFile[]>;
620
- /**
621
- * Returns the tree contents as a binary archive, using a stream.
622
- */
623
- archive(): Promise<NodeJS.ReadableStream>;
624
- /**
625
- * Extracts the tree response into a directory and returns the path of the
626
- * directory.
627
- *
628
- * **NOTE**: It is the responsibility of the caller to remove the directory after use.
629
- */
630
- dir(options?: ReadTreeResponseDirOptions): Promise<string>;
631
- /**
632
- * Etag returned by content provider.
633
- *
634
- * @remarks
635
- *
636
- * Can be used to compare and cache responses when doing subsequent calls.
637
- */
638
- etag: string;
639
- };
640
-
641
- /**
642
- * Options that control {@link ReadTreeResponse.dir} execution.
643
- *
644
- * @public
645
- */
646
- export declare type ReadTreeResponseDirOptions = {
647
- /**
648
- * The directory to write files to.
649
- *
650
- * @remarks
651
- *
652
- * Defaults to the OS tmpdir, or `backend.workingDirectory` if set in config.
653
- */
654
- targetDir?: string;
655
- };
656
-
657
- /**
658
- * Represents a single file in a {@link UrlReaderService.readTree} response.
659
- *
660
- * @public
661
- */
662
- export declare type ReadTreeResponseFile = {
663
- path: string;
664
- content(): Promise<Buffer>;
665
- };
666
-
667
- /**
668
- * An options object for readUrl operations.
669
- *
670
- * @public
671
- */
672
- export declare type ReadUrlOptions = {
673
- /**
674
- * An ETag which can be provided to check whether a
675
- * {@link UrlReaderService.readUrl} response has changed from a previous execution.
676
- *
677
- * @remarks
678
- *
679
- * In the {@link UrlReaderService.readUrl} response, an ETag is returned along with
680
- * the data. The ETag is a unique identifier of the data, usually the commit
681
- * SHA or ETag from the target.
682
- *
683
- * When an ETag is given in ReadUrlOptions, {@link UrlReaderService.readUrl} will
684
- * first compare the ETag against the ETag of the target. If they match,
685
- * {@link UrlReaderService.readUrl} will throw a
686
- * {@link @backstage/errors#NotModifiedError} indicating that the response
687
- * will not differ from the previous response which included this particular
688
- * ETag. If they do not match, {@link UrlReaderService.readUrl} will return the rest
689
- * of the response along with a new ETag.
690
- */
691
- etag?: string;
692
- /**
693
- * An abort signal to pass down to the underlying request.
694
- *
695
- * @remarks
696
- *
697
- * Not all reader implementations may take this field into account.
698
- */
699
- signal?: AbortSignal;
700
- };
701
-
702
- /**
703
- * A response object for {@link UrlReaderService.readUrl} operations.
704
- *
705
- * @public
706
- */
707
- export declare type ReadUrlResponse = {
708
- /**
709
- * Returns the data that was read from the remote URL.
710
- */
711
- buffer(): Promise<Buffer>;
712
- /**
713
- * Returns the data that was read from the remote URL as a Readable stream.
714
- *
715
- * @remarks
716
- *
717
- * This method will be required in a future release.
718
- */
719
- stream?(): Readable;
720
- /**
721
- * Etag returned by content provider.
722
- *
723
- * @remarks
724
- *
725
- * Can be used to compare and cache responses when doing subsequent calls.
726
- */
727
- etag?: string;
728
- };
729
-
730
- /**
731
- * @public
732
- */
733
- export declare interface RootHttpRouterService {
734
- /**
735
- * Registers a handler at the root of the backend router.
736
- * The path is required and may not be empty.
737
- */
738
- use(path: string, handler: Handler): void;
739
- }
740
-
741
- /** @public */
742
- export declare interface RootLifecycleService extends LifecycleService {
743
- }
744
-
745
- /** @public */
746
- export declare interface RootLoggerService extends LoggerService {
747
- }
748
-
749
- /** @public */
750
- export declare interface RootServiceFactoryConfig<TService, TImpl extends TService, TDeps extends {
751
- [name in string]: ServiceRef<unknown>;
752
- }> {
753
- service: ServiceRef<TService, 'root'>;
754
- deps: TDeps;
755
- factory(deps: ServiceRefsToInstances<TDeps, 'root'>): TImpl | Promise<TImpl>;
756
- }
757
-
758
- /** @public */
759
- export declare interface SchedulerService extends PluginTaskScheduler {
760
- }
761
-
762
- /**
763
- * An options object for search operations.
764
- *
765
- * @public
766
- */
767
- export declare type SearchOptions = {
768
- /**
769
- * An etag can be provided to check whether the search response has changed from a previous execution.
770
- *
771
- * In the search() response, an etag is returned along with the files. The etag is a unique identifier
772
- * of the current tree, usually the commit SHA or etag from the target.
773
- *
774
- * When an etag is given in SearchOptions, search will first compare the etag against the etag
775
- * on the target branch. If they match, search will throw a NotModifiedError indicating that the search
776
- * response will not differ from the previous response which included this particular etag. If they mismatch,
777
- * search will return the rest of SearchResponse along with a new etag.
778
- */
779
- etag?: string;
780
- /**
781
- * An abort signal to pass down to the underlying request.
782
- *
783
- * @remarks
784
- *
785
- * Not all reader implementations may take this field into account.
786
- */
787
- signal?: AbortSignal;
788
- };
789
-
790
- /**
791
- * The output of a search operation.
792
- *
793
- * @public
794
- */
795
- export declare type SearchResponse = {
796
- /**
797
- * The files that matched the search query.
798
- */
799
- files: SearchResponseFile[];
800
- /**
801
- * A unique identifier of the current remote tree, usually the commit SHA or etag from the target.
802
- */
803
- etag: string;
804
- };
805
-
806
- /**
807
- * Represents a single file in a search response.
808
- *
809
- * @public
810
- */
811
- export declare type SearchResponseFile = {
812
- /**
813
- * The full URL to the file.
814
- */
815
- url: string;
816
- /**
817
- * The binary contents of the file.
818
- */
819
- content(): Promise<Buffer>;
820
- };
821
-
822
- /** @public */
823
- export declare type ServiceFactory<TService = unknown> = {
824
- scope: 'root';
825
- service: ServiceRef<TService, 'root'>;
826
- deps: {
827
- [key in string]: ServiceRef<unknown>;
828
- };
829
- factory(deps: {
830
- [key in string]: unknown;
831
- }): Promise<TService>;
832
- } | {
833
- scope: 'plugin';
834
- service: ServiceRef<TService, 'plugin'>;
835
- deps: {
836
- [key in string]: ServiceRef<unknown>;
837
- };
838
- createRootContext?(deps: {
839
- [key in string]: unknown;
840
- }): Promise<unknown>;
841
- factory(deps: {
842
- [key in string]: unknown;
843
- }, context: unknown): Promise<TService>;
844
- };
845
-
846
- /**
847
- * Represents either a {@link ServiceFactory} or a function that returns one.
848
- *
849
- * @public
850
- */
851
- export declare type ServiceFactoryOrFunction<TService = unknown> = ServiceFactory<TService> | (() => ServiceFactory<TService>);
852
-
853
- /**
854
- * TODO
855
- *
856
- * @public
857
- */
858
- export declare type ServiceRef<TService, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
859
- id: string;
860
- /**
861
- * This determines the scope at which this service is available.
862
- *
863
- * Root scoped services are available to all other services but
864
- * may only depend on other root scoped services.
865
- *
866
- * Plugin scoped services are only available to other plugin scoped
867
- * services but may depend on all other services.
868
- */
869
- scope: TScope;
870
- /**
871
- * Utility for getting the type of the service, using `typeof serviceRef.T`.
872
- * Attempting to actually read this value will result in an exception.
873
- */
874
- T: TService;
875
- toString(): string;
876
- $$type: '@backstage/ServiceRef';
877
- };
878
-
879
- /** @public */
880
- export declare interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
881
- id: string;
882
- scope?: TScope;
883
- defaultFactory?: (service: ServiceRef<TService, TScope>) => Promise<ServiceFactoryOrFunction<TService>>;
884
- }
885
-
886
- /** @ignore */
887
- declare type ServiceRefsToInstances<T extends {
888
- [key in string]: ServiceRef<unknown>;
889
- }, TScope extends 'root' | 'plugin' = 'root' | 'plugin'> = {
890
- [key in keyof T as T[key]['scope'] extends TScope ? key : never]: T[key]['T'];
891
- };
892
-
893
- /**
894
- * An opaque type that represents the contents of a shared backend environment.
895
- *
896
- * @public
897
- */
898
- export declare interface SharedBackendEnvironment {
899
- $$type: '@backstage/SharedBackendEnvironment';
900
- }
901
-
902
- /**
903
- * The configuration options passed to {@link createSharedEnvironment}.
904
- *
905
- * @public
906
- */
907
- export declare interface SharedBackendEnvironmentConfig {
908
- services?: ServiceFactoryOrFunction[];
909
- }
910
-
911
- /**
912
- * Interface for creating and validating tokens.
913
- *
914
- * @public
915
- */
916
- export declare interface TokenManagerService {
917
- /**
918
- * Fetches a valid token.
919
- *
920
- * @remarks
921
- *
922
- * Tokens are valid for roughly one hour; the actual deadline is set in the
923
- * payload `exp` claim. Never hold on to tokens for reuse; always ask for a
924
- * new one for each outgoing request. This ensures that you always get a
925
- * valid, fresh one.
926
- */
927
- getToken(): Promise<{
928
- token: string;
929
- }>;
930
- /**
931
- * Validates a given token.
932
- */
933
- authenticate(token: string): Promise<void>;
934
- }
935
-
936
- /**
937
- * A generic interface for fetching plain data from URLs.
938
- *
939
- * @public
940
- */
941
- export declare interface UrlReaderService {
942
- /**
943
- * Reads a single file and return its content.
944
- */
945
- readUrl(url: string, options?: ReadUrlOptions): Promise<ReadUrlResponse>;
946
- /**
947
- * Reads a full or partial file tree.
948
- */
949
- readTree(url: string, options?: ReadTreeOptions): Promise<ReadTreeResponse>;
950
- /**
951
- * Searches for a file in a tree using a glob pattern.
952
- */
953
- search(url: string, options?: SearchOptions): Promise<SearchResponse>;
954
- }
955
-
956
- export { }