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