@backstage/backend-plugin-api 0.4.0 → 0.4.1-next.1

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