@backstage/backend-plugin-api 0.0.0-nightly-20230104022659 → 0.0.0-nightly-20230106022925
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -5
- package/alpha/package.json +1 -1
- package/dist/index.alpha.d.ts +133 -14
- package/dist/index.beta.d.ts +133 -14
- package/dist/index.cjs.js +3 -44
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +133 -14
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
# @backstage/backend-plugin-api
|
|
2
2
|
|
|
3
|
-
## 0.0.0-nightly-
|
|
3
|
+
## 0.0.0-nightly-20230106022925
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8e06f3cf00: Moved `loggerToWinstonLogger` to `@backstage/backend-common`.
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
11
|
- 6cfd4d7073: Added `RootLifecycleService` and `rootLifecycleServiceRef`, as well as added a `labels` option to the existing `LifecycleServiceShutdownHook`.
|
|
12
|
+
- 02b119ff93: Added a new `rootHttpRouterServiceRef` and `RootHttpRouterService` interface.
|
|
8
13
|
- 5e2cebe9a3: Migrate `UrlReader` into this package to gradually remove the dependency on backend-common.
|
|
14
|
+
- 5437fe488f: Migrated types related to `TokenManagerService`, `CacheService` and `DatabaseService` into backend-plugin-api.
|
|
9
15
|
- 6f02d23b01: Moved `PluginEndpointDiscovery` type from backend-common to backend-plugin-api.
|
|
10
16
|
- 16054afdec: Documented `coreServices` an all of its members.
|
|
11
17
|
- Updated dependencies
|
|
12
|
-
- @backstage/
|
|
13
|
-
- @backstage/
|
|
14
|
-
- @backstage/
|
|
15
|
-
- @backstage/plugin-permission-common@0.0.0-nightly-
|
|
18
|
+
- @backstage/config@0.0.0-nightly-20230106022925
|
|
19
|
+
- @backstage/backend-tasks@0.0.0-nightly-20230106022925
|
|
20
|
+
- @backstage/types@1.0.2
|
|
21
|
+
- @backstage/plugin-permission-common@0.0.0-nightly-20230106022925
|
|
16
22
|
|
|
17
23
|
## 0.2.1-next.0
|
|
18
24
|
|
package/alpha/package.json
CHANGED
package/dist/index.alpha.d.ts
CHANGED
|
@@ -8,14 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { Config } from '@backstage/config';
|
|
10
10
|
import { Handler } from 'express';
|
|
11
|
-
import {
|
|
11
|
+
import { JsonValue } from '@backstage/types';
|
|
12
|
+
import { Knex } from 'knex';
|
|
12
13
|
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
|
13
|
-
import { PluginCacheManager } from '@backstage/backend-common';
|
|
14
|
-
import { PluginDatabaseManager } from '@backstage/backend-common';
|
|
15
14
|
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
16
15
|
import { Readable } from 'stream';
|
|
17
|
-
import { TokenManager } from '@backstage/backend-common';
|
|
18
|
-
import { TransportStreamOptions } from 'winston-transport';
|
|
19
16
|
|
|
20
17
|
/** @public */
|
|
21
18
|
export declare interface BackendFeature {
|
|
@@ -49,8 +46,73 @@ export declare interface BackendRegistrationPoints {
|
|
|
49
46
|
}): void;
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
49
|
+
/**
|
|
50
|
+
* A pre-configured, storage agnostic cache client suitable for use by
|
|
51
|
+
* Backstage plugins.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export declare interface CacheClient {
|
|
56
|
+
/**
|
|
57
|
+
* Reads data from a cache store for the given key. If no data was found,
|
|
58
|
+
* returns undefined.
|
|
59
|
+
*/
|
|
60
|
+
get(key: string): Promise<JsonValue | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Writes the given data to a cache store, associated with the given key. An
|
|
63
|
+
* optional TTL may also be provided, otherwise it defaults to the TTL that
|
|
64
|
+
* was provided when the client was instantiated.
|
|
65
|
+
*/
|
|
66
|
+
set(key: string, value: JsonValue, options?: CacheClientSetOptions): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the given key from the cache store.
|
|
69
|
+
*/
|
|
70
|
+
delete(key: string): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Options given when constructing a {@link CacheClient}.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export declare type CacheClientOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* An optional default TTL (in milliseconds) to be set when getting a client
|
|
81
|
+
* instance. If not provided, data will persist indefinitely by default (or
|
|
82
|
+
* can be configured per entry at set-time).
|
|
83
|
+
*/
|
|
84
|
+
defaultTtl?: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Options passed to {@link CacheClient.set}.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare type CacheClientSetOptions = {
|
|
93
|
+
/**
|
|
94
|
+
* Optional TTL in milliseconds. Defaults to the TTL provided when the client
|
|
95
|
+
* was set up (or no TTL if none are provided).
|
|
96
|
+
*/
|
|
97
|
+
ttl?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Manages access to cache stores that plugins get.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare interface CacheService {
|
|
106
|
+
/**
|
|
107
|
+
* Provides backend plugins cache connections for themselves.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
*
|
|
111
|
+
* The purpose of this method is to allow plugins to get isolated data stores
|
|
112
|
+
* so that plugins are discouraged from cache-level integration and/or cache
|
|
113
|
+
* key collisions.
|
|
114
|
+
*/
|
|
115
|
+
getClient: (options?: CacheClientOptions) => CacheClient;
|
|
54
116
|
}
|
|
55
117
|
|
|
56
118
|
/**
|
|
@@ -119,6 +181,12 @@ export declare namespace coreServices {
|
|
|
119
181
|
* @public
|
|
120
182
|
*/
|
|
121
183
|
const pluginMetadata: ServiceRef<PluginMetadataService, "plugin">;
|
|
184
|
+
/**
|
|
185
|
+
* The service reference for the root scoped {@link RootHttpRouterService}.
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
const rootHttpRouter: ServiceRef<RootHttpRouterService, "root">;
|
|
122
190
|
/**
|
|
123
191
|
* The service reference for the root scoped {@link RootLifecycleService}.
|
|
124
192
|
*
|
|
@@ -201,8 +269,30 @@ export declare function createServiceRef<T>(options: {
|
|
|
201
269
|
defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
202
270
|
}): ServiceRef<T, 'root'>;
|
|
203
271
|
|
|
204
|
-
/**
|
|
205
|
-
|
|
272
|
+
/**
|
|
273
|
+
* The DatabaseService manages access to databases that Plugins get.
|
|
274
|
+
*gs
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
export declare interface DatabaseService {
|
|
278
|
+
/**
|
|
279
|
+
* getClient provides backend plugins database connections for itself.
|
|
280
|
+
*
|
|
281
|
+
* The purpose of this method is to allow plugins to get isolated data
|
|
282
|
+
* stores so that plugins are discouraged from database integration.
|
|
283
|
+
*/
|
|
284
|
+
getClient(): Promise<Knex>;
|
|
285
|
+
/**
|
|
286
|
+
* This property is used to control the behavior of database migrations.
|
|
287
|
+
*/
|
|
288
|
+
migrations?: {
|
|
289
|
+
/**
|
|
290
|
+
* skip database migrations. Useful if connecting to a read-only database.
|
|
291
|
+
*
|
|
292
|
+
* @defaultValue false
|
|
293
|
+
*/
|
|
294
|
+
skip?: boolean;
|
|
295
|
+
};
|
|
206
296
|
}
|
|
207
297
|
|
|
208
298
|
/**
|
|
@@ -307,9 +397,6 @@ export declare interface LoggerService {
|
|
|
307
397
|
child(meta: LogMeta): LoggerService;
|
|
308
398
|
}
|
|
309
399
|
|
|
310
|
-
/** @public */
|
|
311
|
-
export declare function loggerToWinstonLogger(logger: LoggerService, opts?: TransportStreamOptions): Logger;
|
|
312
|
-
|
|
313
400
|
/**
|
|
314
401
|
* @public
|
|
315
402
|
*/
|
|
@@ -501,6 +588,17 @@ export declare type ReadUrlResponse = {
|
|
|
501
588
|
etag?: string;
|
|
502
589
|
};
|
|
503
590
|
|
|
591
|
+
/**
|
|
592
|
+
* @public
|
|
593
|
+
*/
|
|
594
|
+
export declare interface RootHttpRouterService {
|
|
595
|
+
/**
|
|
596
|
+
* Registers a handler at the root of the backend router.
|
|
597
|
+
* The path is required and may not be empty.
|
|
598
|
+
*/
|
|
599
|
+
use(path: string, handler: Handler): void;
|
|
600
|
+
}
|
|
601
|
+
|
|
504
602
|
/** @public */
|
|
505
603
|
export declare interface RootLifecycleService extends LifecycleService {
|
|
506
604
|
}
|
|
@@ -631,8 +729,29 @@ declare type ServiceRefsToInstances<T extends {
|
|
|
631
729
|
}[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
|
|
632
730
|
};
|
|
633
731
|
|
|
634
|
-
/**
|
|
635
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Interface for creating and validating tokens.
|
|
734
|
+
*
|
|
735
|
+
* @public
|
|
736
|
+
*/
|
|
737
|
+
export declare interface TokenManagerService {
|
|
738
|
+
/**
|
|
739
|
+
* Fetches a valid token.
|
|
740
|
+
*
|
|
741
|
+
* @remarks
|
|
742
|
+
*
|
|
743
|
+
* Tokens are valid for roughly one hour; the actual deadline is set in the
|
|
744
|
+
* payload `exp` claim. Never hold on to tokens for reuse; always ask for a
|
|
745
|
+
* new one for each outgoing request. This ensures that you always get a
|
|
746
|
+
* valid, fresh one.
|
|
747
|
+
*/
|
|
748
|
+
getToken(): Promise<{
|
|
749
|
+
token: string;
|
|
750
|
+
}>;
|
|
751
|
+
/**
|
|
752
|
+
* Validates a given token.
|
|
753
|
+
*/
|
|
754
|
+
authenticate(token: string): Promise<void>;
|
|
636
755
|
}
|
|
637
756
|
|
|
638
757
|
/** @public */
|
package/dist/index.beta.d.ts
CHANGED
|
@@ -8,14 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { Config } from '@backstage/config';
|
|
10
10
|
import { Handler } from 'express';
|
|
11
|
-
import {
|
|
11
|
+
import { JsonValue } from '@backstage/types';
|
|
12
|
+
import { Knex } from 'knex';
|
|
12
13
|
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
|
13
|
-
import { PluginCacheManager } from '@backstage/backend-common';
|
|
14
|
-
import { PluginDatabaseManager } from '@backstage/backend-common';
|
|
15
14
|
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
16
15
|
import { Readable } from 'stream';
|
|
17
|
-
import { TokenManager } from '@backstage/backend-common';
|
|
18
|
-
import { TransportStreamOptions } from 'winston-transport';
|
|
19
16
|
|
|
20
17
|
/** @public */
|
|
21
18
|
export declare interface BackendFeature {
|
|
@@ -49,8 +46,73 @@ export declare interface BackendRegistrationPoints {
|
|
|
49
46
|
}): void;
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
49
|
+
/**
|
|
50
|
+
* A pre-configured, storage agnostic cache client suitable for use by
|
|
51
|
+
* Backstage plugins.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export declare interface CacheClient {
|
|
56
|
+
/**
|
|
57
|
+
* Reads data from a cache store for the given key. If no data was found,
|
|
58
|
+
* returns undefined.
|
|
59
|
+
*/
|
|
60
|
+
get(key: string): Promise<JsonValue | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Writes the given data to a cache store, associated with the given key. An
|
|
63
|
+
* optional TTL may also be provided, otherwise it defaults to the TTL that
|
|
64
|
+
* was provided when the client was instantiated.
|
|
65
|
+
*/
|
|
66
|
+
set(key: string, value: JsonValue, options?: CacheClientSetOptions): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the given key from the cache store.
|
|
69
|
+
*/
|
|
70
|
+
delete(key: string): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Options given when constructing a {@link CacheClient}.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export declare type CacheClientOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* An optional default TTL (in milliseconds) to be set when getting a client
|
|
81
|
+
* instance. If not provided, data will persist indefinitely by default (or
|
|
82
|
+
* can be configured per entry at set-time).
|
|
83
|
+
*/
|
|
84
|
+
defaultTtl?: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Options passed to {@link CacheClient.set}.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare type CacheClientSetOptions = {
|
|
93
|
+
/**
|
|
94
|
+
* Optional TTL in milliseconds. Defaults to the TTL provided when the client
|
|
95
|
+
* was set up (or no TTL if none are provided).
|
|
96
|
+
*/
|
|
97
|
+
ttl?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Manages access to cache stores that plugins get.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare interface CacheService {
|
|
106
|
+
/**
|
|
107
|
+
* Provides backend plugins cache connections for themselves.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
*
|
|
111
|
+
* The purpose of this method is to allow plugins to get isolated data stores
|
|
112
|
+
* so that plugins are discouraged from cache-level integration and/or cache
|
|
113
|
+
* key collisions.
|
|
114
|
+
*/
|
|
115
|
+
getClient: (options?: CacheClientOptions) => CacheClient;
|
|
54
116
|
}
|
|
55
117
|
|
|
56
118
|
/**
|
|
@@ -119,6 +181,12 @@ export declare namespace coreServices {
|
|
|
119
181
|
* @public
|
|
120
182
|
*/
|
|
121
183
|
const pluginMetadata: ServiceRef<PluginMetadataService, "plugin">;
|
|
184
|
+
/**
|
|
185
|
+
* The service reference for the root scoped {@link RootHttpRouterService}.
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
const rootHttpRouter: ServiceRef<RootHttpRouterService, "root">;
|
|
122
190
|
/**
|
|
123
191
|
* The service reference for the root scoped {@link RootLifecycleService}.
|
|
124
192
|
*
|
|
@@ -201,8 +269,30 @@ export declare function createServiceRef<T>(options: {
|
|
|
201
269
|
defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
202
270
|
}): ServiceRef<T, 'root'>;
|
|
203
271
|
|
|
204
|
-
/**
|
|
205
|
-
|
|
272
|
+
/**
|
|
273
|
+
* The DatabaseService manages access to databases that Plugins get.
|
|
274
|
+
*gs
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
export declare interface DatabaseService {
|
|
278
|
+
/**
|
|
279
|
+
* getClient provides backend plugins database connections for itself.
|
|
280
|
+
*
|
|
281
|
+
* The purpose of this method is to allow plugins to get isolated data
|
|
282
|
+
* stores so that plugins are discouraged from database integration.
|
|
283
|
+
*/
|
|
284
|
+
getClient(): Promise<Knex>;
|
|
285
|
+
/**
|
|
286
|
+
* This property is used to control the behavior of database migrations.
|
|
287
|
+
*/
|
|
288
|
+
migrations?: {
|
|
289
|
+
/**
|
|
290
|
+
* skip database migrations. Useful if connecting to a read-only database.
|
|
291
|
+
*
|
|
292
|
+
* @defaultValue false
|
|
293
|
+
*/
|
|
294
|
+
skip?: boolean;
|
|
295
|
+
};
|
|
206
296
|
}
|
|
207
297
|
|
|
208
298
|
/**
|
|
@@ -307,9 +397,6 @@ export declare interface LoggerService {
|
|
|
307
397
|
child(meta: LogMeta): LoggerService;
|
|
308
398
|
}
|
|
309
399
|
|
|
310
|
-
/** @public */
|
|
311
|
-
export declare function loggerToWinstonLogger(logger: LoggerService, opts?: TransportStreamOptions): Logger;
|
|
312
|
-
|
|
313
400
|
/**
|
|
314
401
|
* @public
|
|
315
402
|
*/
|
|
@@ -501,6 +588,17 @@ export declare type ReadUrlResponse = {
|
|
|
501
588
|
etag?: string;
|
|
502
589
|
};
|
|
503
590
|
|
|
591
|
+
/**
|
|
592
|
+
* @public
|
|
593
|
+
*/
|
|
594
|
+
export declare interface RootHttpRouterService {
|
|
595
|
+
/**
|
|
596
|
+
* Registers a handler at the root of the backend router.
|
|
597
|
+
* The path is required and may not be empty.
|
|
598
|
+
*/
|
|
599
|
+
use(path: string, handler: Handler): void;
|
|
600
|
+
}
|
|
601
|
+
|
|
504
602
|
/** @public */
|
|
505
603
|
export declare interface RootLifecycleService extends LifecycleService {
|
|
506
604
|
}
|
|
@@ -631,8 +729,29 @@ declare type ServiceRefsToInstances<T extends {
|
|
|
631
729
|
}[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
|
|
632
730
|
};
|
|
633
731
|
|
|
634
|
-
/**
|
|
635
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Interface for creating and validating tokens.
|
|
734
|
+
*
|
|
735
|
+
* @public
|
|
736
|
+
*/
|
|
737
|
+
export declare interface TokenManagerService {
|
|
738
|
+
/**
|
|
739
|
+
* Fetches a valid token.
|
|
740
|
+
*
|
|
741
|
+
* @remarks
|
|
742
|
+
*
|
|
743
|
+
* Tokens are valid for roughly one hour; the actual deadline is set in the
|
|
744
|
+
* payload `exp` claim. Never hold on to tokens for reuse; always ask for a
|
|
745
|
+
* new one for each outgoing request. This ensures that you always get a
|
|
746
|
+
* valid, fresh one.
|
|
747
|
+
*/
|
|
748
|
+
getToken(): Promise<{
|
|
749
|
+
token: string;
|
|
750
|
+
}>;
|
|
751
|
+
/**
|
|
752
|
+
* Validates a given token.
|
|
753
|
+
*/
|
|
754
|
+
authenticate(token: string): Promise<void>;
|
|
636
755
|
}
|
|
637
756
|
|
|
638
757
|
/** @public */
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,13 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var winston = require('winston');
|
|
6
|
-
var Transport = require('winston-transport');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var Transport__default = /*#__PURE__*/_interopDefaultLegacy(Transport);
|
|
11
|
-
|
|
12
5
|
function createServiceRef(options) {
|
|
13
6
|
const { id, scope = "plugin", defaultFactory } = options;
|
|
14
7
|
return {
|
|
@@ -21,6 +14,7 @@ function createServiceRef(options) {
|
|
|
21
14
|
return `serviceRef{${options.id}}`;
|
|
22
15
|
},
|
|
23
16
|
$$ref: "service",
|
|
17
|
+
// TODO: declare
|
|
24
18
|
__defaultFactory: defaultFactory
|
|
25
19
|
};
|
|
26
20
|
}
|
|
@@ -48,6 +42,7 @@ exports.coreServices = void 0;
|
|
|
48
42
|
coreServices2.logger = createServiceRef({ id: "core.logger" });
|
|
49
43
|
coreServices2.permissions = createServiceRef({ id: "core.permissions" });
|
|
50
44
|
coreServices2.pluginMetadata = createServiceRef({ id: "core.pluginMetadata" });
|
|
45
|
+
coreServices2.rootHttpRouter = createServiceRef({ id: "core.rootHttpRouter", scope: "root" });
|
|
51
46
|
coreServices2.rootLifecycle = createServiceRef({ id: "core.rootLifecycle", scope: "root" });
|
|
52
47
|
coreServices2.rootLogger = createServiceRef({ id: "core.rootLogger", scope: "root" });
|
|
53
48
|
coreServices2.scheduler = createServiceRef({ id: "core.scheduler" });
|
|
@@ -55,42 +50,6 @@ exports.coreServices = void 0;
|
|
|
55
50
|
coreServices2.urlReader = createServiceRef({ id: "core.urlReader" });
|
|
56
51
|
})(exports.coreServices || (exports.coreServices = {}));
|
|
57
52
|
|
|
58
|
-
class BackstageLoggerTransport extends Transport__default["default"] {
|
|
59
|
-
constructor(backstageLogger, opts) {
|
|
60
|
-
super(opts);
|
|
61
|
-
this.backstageLogger = backstageLogger;
|
|
62
|
-
}
|
|
63
|
-
log(info, callback) {
|
|
64
|
-
if (typeof info !== "object" || info === null) {
|
|
65
|
-
callback();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const { level, message, ...meta } = info;
|
|
69
|
-
switch (level) {
|
|
70
|
-
case "error":
|
|
71
|
-
this.backstageLogger.error(String(message), meta);
|
|
72
|
-
break;
|
|
73
|
-
case "warn":
|
|
74
|
-
this.backstageLogger.warn(String(message), meta);
|
|
75
|
-
break;
|
|
76
|
-
case "info":
|
|
77
|
-
this.backstageLogger.info(String(message), meta);
|
|
78
|
-
break;
|
|
79
|
-
case "debug":
|
|
80
|
-
this.backstageLogger.debug(String(message), meta);
|
|
81
|
-
break;
|
|
82
|
-
default:
|
|
83
|
-
this.backstageLogger.info(String(message), meta);
|
|
84
|
-
}
|
|
85
|
-
callback();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function loggerToWinstonLogger(logger, opts) {
|
|
89
|
-
return winston.createLogger({
|
|
90
|
-
transports: [new BackstageLoggerTransport(logger, opts)]
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
53
|
function createExtensionPoint(options) {
|
|
95
54
|
return {
|
|
96
55
|
id: options.id,
|
|
@@ -101,6 +60,7 @@ function createExtensionPoint(options) {
|
|
|
101
60
|
return `extensionPoint{${options.id}}`;
|
|
102
61
|
},
|
|
103
62
|
$$ref: "extension-point"
|
|
63
|
+
// TODO: declare
|
|
104
64
|
};
|
|
105
65
|
}
|
|
106
66
|
function createBackendPlugin(config) {
|
|
@@ -125,5 +85,4 @@ exports.createBackendPlugin = createBackendPlugin;
|
|
|
125
85
|
exports.createExtensionPoint = createExtensionPoint;
|
|
126
86
|
exports.createServiceFactory = createServiceFactory;
|
|
127
87
|
exports.createServiceRef = createServiceRef;
|
|
128
|
-
exports.loggerToWinstonLogger = loggerToWinstonLogger;
|
|
129
88
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/coreServices.ts","../src/services/helpers/loggerToWinstonLogger.ts","../src/wiring/factories.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * TODO\n *\n * @public\n */\nexport type ServiceRef<\n TService,\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n id: string;\n\n /**\n * This determines the scope at which this service is available.\n *\n * Root scoped services are available to all other services but\n * may only depend on other root scoped services.\n *\n * Plugin scoped services are only available to other plugin scoped\n * services but may depend on all other services.\n */\n scope: TScope;\n\n /**\n * Utility for getting the type of the service, using `typeof serviceRef.T`.\n * Attempting to actually read this value will result in an exception.\n */\n T: TService;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type ServiceFactory<TService = unknown> =\n | {\n // This scope prop is needed in addition to the service ref, as TypeScript\n // can't properly discriminate the two factory types otherwise.\n scope: 'root';\n service: ServiceRef<TService, 'root'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<TService>;\n }\n | {\n scope: 'plugin';\n service: ServiceRef<TService, 'plugin'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<\n (deps: { [key in string]: unknown }) => Promise<TService>\n >;\n };\n\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin';\n defaultFactory?: (\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'plugin'>;\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope: 'root';\n defaultFactory?: (\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'root'>;\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin' | 'root';\n defaultFactory?:\n | ((\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>)\n | ((\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>);\n}): ServiceRef<T> {\n const { id, scope = 'plugin', defaultFactory } = options;\n return {\n id,\n scope,\n get T(): T {\n throw new Error(`tried to read ServiceRef.T of ${this}`);\n },\n toString() {\n return `serviceRef{${options.id}}`;\n },\n $$ref: 'service', // TODO: declare\n __defaultFactory: defaultFactory,\n } as ServiceRef<T, typeof scope> & {\n __defaultFactory?: (\n service: ServiceRef<T>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n };\n}\n\n/** @ignore */\ntype ServiceRefsToInstances<\n T extends { [key in string]: ServiceRef<unknown> },\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n [name in {\n [key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;\n }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;\n};\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends object | undefined = undefined,\n>(config: {\n service: ServiceRef<TService, TScope>;\n deps: TDeps;\n factory(\n deps: ServiceRefsToInstances<TDeps, 'root'>,\n options: TOpts,\n ): TScope extends 'root'\n ? Promise<TImpl>\n : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;\n}): undefined extends TOpts\n ? (options?: TOpts) => ServiceFactory<TService>\n : (options: TOpts) => ServiceFactory<TService> {\n return (options?: TOpts) =>\n ({\n scope: config.service.scope,\n service: config.service,\n deps: config.deps,\n factory(deps: ServiceRefsToInstances<TDeps, 'root'>) {\n return config.factory(deps, options!);\n },\n } as ServiceFactory<TService>);\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system';\n\n/**\n * All core services references\n *\n * @public\n */\nexport namespace coreServices {\n /**\n * The service reference for the plugin scoped {@link CacheService}.\n *\n * @public\n */\n export const cache = createServiceRef<import('./CacheService').CacheService>({\n id: 'core.cache',\n });\n\n /**\n * The service reference for the root scoped {@link ConfigService}.\n *\n * @public\n */\n export const config = createServiceRef<\n import('./ConfigService').ConfigService\n >({ id: 'core.config', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link DatabaseService}.\n *\n * @public\n */\n export const database = createServiceRef<\n import('./DatabaseService').DatabaseService\n >({ id: 'core.database' });\n\n /**\n * The service reference for the plugin scoped {@link DiscoveryService}.\n *\n * @public\n */\n export const discovery = createServiceRef<\n import('./DiscoveryService').DiscoveryService\n >({ id: 'core.discovery' });\n\n /**\n * The service reference for the plugin scoped {@link HttpRouterService}.\n *\n * @public\n */\n export const httpRouter = createServiceRef<\n import('./HttpRouterService').HttpRouterService\n >({ id: 'core.httpRouter' });\n\n /**\n * The service reference for the plugin scoped {@link LifecycleService}.\n *\n * @public\n */\n export const lifecycle = createServiceRef<\n import('./LifecycleService').LifecycleService\n >({ id: 'core.lifecycle' });\n\n /**\n * The service reference for the plugin scoped {@link LoggerService}.\n *\n * @public\n */\n export const logger = createServiceRef<\n import('./LoggerService').LoggerService\n >({ id: 'core.logger' });\n\n /**\n * The service reference for the plugin scoped {@link PermissionsService}.\n *\n * @public\n */\n export const permissions = createServiceRef<\n import('./PermissionsService').PermissionsService\n >({ id: 'core.permissions' });\n\n /**\n * The service reference for the plugin scoped {@link PluginMetadataService}.\n *\n * @public\n */\n export const pluginMetadata = createServiceRef<\n import('./PluginMetadataService').PluginMetadataService\n >({ id: 'core.pluginMetadata' });\n\n /**\n * The service reference for the root scoped {@link RootLifecycleService}.\n *\n * @public\n */\n export const rootLifecycle = createServiceRef<\n import('./RootLifecycleService').RootLifecycleService\n >({ id: 'core.rootLifecycle', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLoggerService}.\n *\n * @public\n */\n export const rootLogger = createServiceRef<\n import('./RootLoggerService').RootLoggerService\n >({ id: 'core.rootLogger', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link SchedulerService}.\n *\n * @public\n */\n export const scheduler = createServiceRef<\n import('./SchedulerService').SchedulerService\n >({ id: 'core.scheduler' });\n\n /**\n * The service reference for the plugin scoped {@link TokenManagerService}.\n *\n * @public\n */\n export const tokenManager = createServiceRef<\n import('./TokenManagerService').TokenManagerService\n >({ id: 'core.tokenManager' });\n\n /**\n * The service reference for the plugin scoped {@link UrlReaderService}.\n *\n * @public\n */\n export const urlReader = createServiceRef<\n import('./UrlReaderService').UrlReaderService\n >({ id: 'core.urlReader' });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '../definitions';\nimport { Logger as WinstonLogger, createLogger } from 'winston';\nimport Transport, { TransportStreamOptions } from 'winston-transport';\n\nclass BackstageLoggerTransport extends Transport {\n constructor(\n private readonly backstageLogger: LoggerService,\n opts?: TransportStreamOptions,\n ) {\n super(opts);\n }\n\n log(info: unknown, callback: VoidFunction) {\n if (typeof info !== 'object' || info === null) {\n callback();\n return;\n }\n const { level, message, ...meta } = info as { [name: string]: unknown };\n switch (level) {\n case 'error':\n this.backstageLogger.error(String(message), meta);\n break;\n case 'warn':\n this.backstageLogger.warn(String(message), meta);\n break;\n case 'info':\n this.backstageLogger.info(String(message), meta);\n break;\n case 'debug':\n this.backstageLogger.debug(String(message), meta);\n break;\n default:\n this.backstageLogger.info(String(message), meta);\n }\n callback();\n }\n}\n\n/** @public */\nexport function loggerToWinstonLogger(\n logger: LoggerService,\n opts?: TransportStreamOptions,\n): WinstonLogger {\n return createLogger({\n transports: [new BackstageLoggerTransport(logger, opts)],\n });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BackendRegistrationPoints,\n BackendFeature,\n ExtensionPoint,\n} from './types';\n\n/** @public */\nexport function createExtensionPoint<T>(options: {\n id: string;\n}): ExtensionPoint<T> {\n return {\n id: options.id,\n get T(): T {\n throw new Error(`tried to read ExtensionPoint.T of ${this}`);\n },\n toString() {\n return `extensionPoint{${options.id}}`;\n },\n $$ref: 'extension-point', // TODO: declare\n };\n}\n\n/** @public */\nexport interface BackendPluginConfig<TOptions> {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}\n\n/** @public */\nexport function createBackendPlugin<\n TOptions extends object | undefined = undefined,\n>(config: {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: config.id,\n register(register: BackendRegistrationPoints) {\n return config.register(register, options!);\n },\n });\n}\n\n/** @public */\nexport interface BackendModuleConfig<TOptions> {\n pluginId: string;\n moduleId: string;\n register(\n reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,\n options: TOptions,\n ): void;\n}\n\n/**\n * @public\n *\n * Creates a new backend module for a given plugin.\n *\n * The `moduleId` should be equal to the module-specific prefix of the exported name, such\n * that the full name is `moduleId + PluginId + \"Module\"`. For example, a GitHub entity\n * provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,\n * and the full exported name would be `githubEntityProviderCatalogModule`.\n *\n * The `pluginId` should exactly match the `id` of the plugin that the module extends.\n */\nexport function createBackendModule<\n TOptions extends object | undefined = undefined,\n>(\n config: BackendModuleConfig<TOptions>,\n): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: `${config.pluginId}.${config.moduleId}`,\n register(register: BackendRegistrationPoints) {\n // TODO: Hide registerExtensionPoint\n return config.register(register, options!);\n },\n });\n}\n"],"names":["coreServices","Transport","createLogger"],"mappings":";;;;;;;;;;;AAuFO,SAAS,iBAAoB,OAUlB,EAAA;AAChB,EAAA,MAAM,EAAE,EAAA,EAAI,KAAQ,GAAA,QAAA,EAAU,gBAAmB,GAAA,OAAA,CAAA;AACjD,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAI,CAAO,GAAA;AACT,MAAM,MAAA,IAAI,KAAM,CAAA,CAAA,8BAAA,EAAiC,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KACzD;AAA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C9B,IAAI,MAAO,CAAA,EAAA;AAAA,IACX,SAAS,QAAqC,EAAA;AAC5C,MAAO,OAAA,MAAA,CAAO,QAAS,CAAA,QAAA,EAAU,OAAQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF,CAAA;AAwBO,SAAS,oBAGd,MAGwC,EAAA;AACxC,EAAA,OAAO,CAAC,OAAwB,MAAA;AAAA,IAC9B,EAAI,EAAA,CAAA,EAAG,MAAO,CAAA,QAAA,CAAA,CAAA,EAAY,MAAO,CAAA,QAAA,CAAA,CAAA;AAAA,IACjC,SAAS,QAAqC,EAAA;AAE5C,MAAO,OAAA,MAAA,CAAO,QAAS,CAAA,QAAA,EAAU,OAAQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/services/system/types.ts","../src/services/definitions/coreServices.ts","../src/wiring/factories.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * TODO\n *\n * @public\n */\nexport type ServiceRef<\n TService,\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n id: string;\n\n /**\n * This determines the scope at which this service is available.\n *\n * Root scoped services are available to all other services but\n * may only depend on other root scoped services.\n *\n * Plugin scoped services are only available to other plugin scoped\n * services but may depend on all other services.\n */\n scope: TScope;\n\n /**\n * Utility for getting the type of the service, using `typeof serviceRef.T`.\n * Attempting to actually read this value will result in an exception.\n */\n T: TService;\n\n toString(): string;\n\n $$ref: 'service';\n};\n\n/** @public */\nexport type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };\n\n/** @public */\nexport type ServiceFactory<TService = unknown> =\n | {\n // This scope prop is needed in addition to the service ref, as TypeScript\n // can't properly discriminate the two factory types otherwise.\n scope: 'root';\n service: ServiceRef<TService, 'root'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<TService>;\n }\n | {\n scope: 'plugin';\n service: ServiceRef<TService, 'plugin'>;\n deps: { [key in string]: ServiceRef<unknown> };\n factory(deps: { [key in string]: unknown }): Promise<\n (deps: { [key in string]: unknown }) => Promise<TService>\n >;\n };\n\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin';\n defaultFactory?: (\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'plugin'>;\n/** @public */\nexport function createServiceRef<T>(options: {\n id: string;\n scope: 'root';\n defaultFactory?: (\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n}): ServiceRef<T, 'root'>;\nexport function createServiceRef<T>(options: {\n id: string;\n scope?: 'plugin' | 'root';\n defaultFactory?:\n | ((\n service: ServiceRef<T, 'plugin'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>)\n | ((\n service: ServiceRef<T, 'root'>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>);\n}): ServiceRef<T> {\n const { id, scope = 'plugin', defaultFactory } = options;\n return {\n id,\n scope,\n get T(): T {\n throw new Error(`tried to read ServiceRef.T of ${this}`);\n },\n toString() {\n return `serviceRef{${options.id}}`;\n },\n $$ref: 'service', // TODO: declare\n __defaultFactory: defaultFactory,\n } as ServiceRef<T, typeof scope> & {\n __defaultFactory?: (\n service: ServiceRef<T>,\n ) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;\n };\n}\n\n/** @ignore */\ntype ServiceRefsToInstances<\n T extends { [key in string]: ServiceRef<unknown> },\n TScope extends 'root' | 'plugin' = 'root' | 'plugin',\n> = {\n [name in {\n [key in keyof T]: T[key] extends ServiceRef<unknown, TScope> ? key : never;\n }[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;\n};\n\n/**\n * @public\n */\nexport function createServiceFactory<\n TService,\n TScope extends 'root' | 'plugin',\n TImpl extends TService,\n TDeps extends { [name in string]: ServiceRef<unknown> },\n TOpts extends object | undefined = undefined,\n>(config: {\n service: ServiceRef<TService, TScope>;\n deps: TDeps;\n factory(\n deps: ServiceRefsToInstances<TDeps, 'root'>,\n options: TOpts,\n ): TScope extends 'root'\n ? Promise<TImpl>\n : Promise<(deps: ServiceRefsToInstances<TDeps>) => Promise<TImpl>>;\n}): undefined extends TOpts\n ? (options?: TOpts) => ServiceFactory<TService>\n : (options: TOpts) => ServiceFactory<TService> {\n return (options?: TOpts) =>\n ({\n scope: config.service.scope,\n service: config.service,\n deps: config.deps,\n factory(deps: ServiceRefsToInstances<TDeps, 'root'>) {\n return config.factory(deps, options!);\n },\n } as ServiceFactory<TService>);\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createServiceRef } from '../system';\n\n/**\n * All core services references\n *\n * @public\n */\nexport namespace coreServices {\n /**\n * The service reference for the plugin scoped {@link CacheService}.\n *\n * @public\n */\n export const cache = createServiceRef<import('./CacheService').CacheService>({\n id: 'core.cache',\n });\n\n /**\n * The service reference for the root scoped {@link ConfigService}.\n *\n * @public\n */\n export const config = createServiceRef<\n import('./ConfigService').ConfigService\n >({ id: 'core.config', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link DatabaseService}.\n *\n * @public\n */\n export const database = createServiceRef<\n import('./DatabaseService').DatabaseService\n >({ id: 'core.database' });\n\n /**\n * The service reference for the plugin scoped {@link DiscoveryService}.\n *\n * @public\n */\n export const discovery = createServiceRef<\n import('./DiscoveryService').DiscoveryService\n >({ id: 'core.discovery' });\n\n /**\n * The service reference for the plugin scoped {@link HttpRouterService}.\n *\n * @public\n */\n export const httpRouter = createServiceRef<\n import('./HttpRouterService').HttpRouterService\n >({ id: 'core.httpRouter' });\n\n /**\n * The service reference for the plugin scoped {@link LifecycleService}.\n *\n * @public\n */\n export const lifecycle = createServiceRef<\n import('./LifecycleService').LifecycleService\n >({ id: 'core.lifecycle' });\n\n /**\n * The service reference for the plugin scoped {@link LoggerService}.\n *\n * @public\n */\n export const logger = createServiceRef<\n import('./LoggerService').LoggerService\n >({ id: 'core.logger' });\n\n /**\n * The service reference for the plugin scoped {@link PermissionsService}.\n *\n * @public\n */\n export const permissions = createServiceRef<\n import('./PermissionsService').PermissionsService\n >({ id: 'core.permissions' });\n\n /**\n * The service reference for the plugin scoped {@link PluginMetadataService}.\n *\n * @public\n */\n export const pluginMetadata = createServiceRef<\n import('./PluginMetadataService').PluginMetadataService\n >({ id: 'core.pluginMetadata' });\n\n /**\n * The service reference for the root scoped {@link RootHttpRouterService}.\n *\n * @public\n */\n export const rootHttpRouter = createServiceRef<\n import('./RootHttpRouterService').RootHttpRouterService\n >({ id: 'core.rootHttpRouter', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLifecycleService}.\n *\n * @public\n */\n export const rootLifecycle = createServiceRef<\n import('./RootLifecycleService').RootLifecycleService\n >({ id: 'core.rootLifecycle', scope: 'root' });\n\n /**\n * The service reference for the root scoped {@link RootLoggerService}.\n *\n * @public\n */\n export const rootLogger = createServiceRef<\n import('./RootLoggerService').RootLoggerService\n >({ id: 'core.rootLogger', scope: 'root' });\n\n /**\n * The service reference for the plugin scoped {@link SchedulerService}.\n *\n * @public\n */\n export const scheduler = createServiceRef<\n import('./SchedulerService').SchedulerService\n >({ id: 'core.scheduler' });\n\n /**\n * The service reference for the plugin scoped {@link TokenManagerService}.\n *\n * @public\n */\n export const tokenManager = createServiceRef<\n import('./TokenManagerService').TokenManagerService\n >({ id: 'core.tokenManager' });\n\n /**\n * The service reference for the plugin scoped {@link UrlReaderService}.\n *\n * @public\n */\n export const urlReader = createServiceRef<\n import('./UrlReaderService').UrlReaderService\n >({ id: 'core.urlReader' });\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BackendRegistrationPoints,\n BackendFeature,\n ExtensionPoint,\n} from './types';\n\n/** @public */\nexport function createExtensionPoint<T>(options: {\n id: string;\n}): ExtensionPoint<T> {\n return {\n id: options.id,\n get T(): T {\n throw new Error(`tried to read ExtensionPoint.T of ${this}`);\n },\n toString() {\n return `extensionPoint{${options.id}}`;\n },\n $$ref: 'extension-point', // TODO: declare\n };\n}\n\n/** @public */\nexport interface BackendPluginConfig<TOptions> {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}\n\n/** @public */\nexport function createBackendPlugin<\n TOptions extends object | undefined = undefined,\n>(config: {\n id: string;\n register(reg: BackendRegistrationPoints, options: TOptions): void;\n}): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: config.id,\n register(register: BackendRegistrationPoints) {\n return config.register(register, options!);\n },\n });\n}\n\n/** @public */\nexport interface BackendModuleConfig<TOptions> {\n pluginId: string;\n moduleId: string;\n register(\n reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,\n options: TOptions,\n ): void;\n}\n\n/**\n * @public\n *\n * Creates a new backend module for a given plugin.\n *\n * The `moduleId` should be equal to the module-specific prefix of the exported name, such\n * that the full name is `moduleId + PluginId + \"Module\"`. For example, a GitHub entity\n * provider module for the `catalog` plugin might have the module ID `'githubEntityProvider'`,\n * and the full exported name would be `githubEntityProviderCatalogModule`.\n *\n * The `pluginId` should exactly match the `id` of the plugin that the module extends.\n */\nexport function createBackendModule<\n TOptions extends object | undefined = undefined,\n>(\n config: BackendModuleConfig<TOptions>,\n): undefined extends TOptions\n ? (options?: TOptions) => BackendFeature\n : (options: TOptions) => BackendFeature {\n return (options?: TOptions) => ({\n id: `${config.pluginId}.${config.moduleId}`,\n register(register: BackendRegistrationPoints) {\n // TODO: Hide registerExtensionPoint\n return config.register(register, options!);\n },\n });\n}\n"],"names":["coreServices"],"mappings":";;;;AAuFO,SAAS,iBAAoB,OAUlB,EAAA;AAChB,EAAA,MAAM,EAAE,EAAA,EAAI,KAAQ,GAAA,QAAA,EAAU,gBAAmB,GAAA,OAAA,CAAA;AACjD,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAI,CAAO,GAAA;AACT,MAAM,MAAA,IAAI,KAAM,CAAA,CAAA,8BAAA,EAAiC,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KACzD;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,cAAc,OAAQ,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA;AAAA,KAC/B;AAAA,IACA,KAAO,EAAA,SAAA;AAAA;AAAA,IACP,gBAAkB,EAAA,cAAA;AAAA,GACpB,CAAA;AAKF,CAAA;AAeO,SAAS,qBAMd,MAW+C,EAAA;AAC/C,EAAA,OAAO,CAAC,OACL,MAAA;AAAA,IACC,KAAA,EAAO,OAAO,OAAQ,CAAA,KAAA;A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,CAAA,QAAA,CAAA,CAAA,EAAY,MAAO,CAAA,QAAA,CAAA,CAAA;AAAA,IACjC,SAAS,QAAqC,EAAA;AAE5C,MAAO,OAAA,MAAA,CAAO,QAAS,CAAA,QAAA,EAAU,OAAQ,CAAA,CAAA;AAAA,KAC3C;AAAA,GACF,CAAA,CAAA;AACF;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,14 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { Config } from '@backstage/config';
|
|
10
10
|
import { Handler } from 'express';
|
|
11
|
-
import {
|
|
11
|
+
import { JsonValue } from '@backstage/types';
|
|
12
|
+
import { Knex } from 'knex';
|
|
12
13
|
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
|
13
|
-
import { PluginCacheManager } from '@backstage/backend-common';
|
|
14
|
-
import { PluginDatabaseManager } from '@backstage/backend-common';
|
|
15
14
|
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
16
15
|
import { Readable } from 'stream';
|
|
17
|
-
import { TokenManager } from '@backstage/backend-common';
|
|
18
|
-
import { TransportStreamOptions } from 'winston-transport';
|
|
19
16
|
|
|
20
17
|
/** @public */
|
|
21
18
|
export declare interface BackendFeature {
|
|
@@ -49,8 +46,73 @@ export declare interface BackendRegistrationPoints {
|
|
|
49
46
|
}): void;
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
49
|
+
/**
|
|
50
|
+
* A pre-configured, storage agnostic cache client suitable for use by
|
|
51
|
+
* Backstage plugins.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export declare interface CacheClient {
|
|
56
|
+
/**
|
|
57
|
+
* Reads data from a cache store for the given key. If no data was found,
|
|
58
|
+
* returns undefined.
|
|
59
|
+
*/
|
|
60
|
+
get(key: string): Promise<JsonValue | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Writes the given data to a cache store, associated with the given key. An
|
|
63
|
+
* optional TTL may also be provided, otherwise it defaults to the TTL that
|
|
64
|
+
* was provided when the client was instantiated.
|
|
65
|
+
*/
|
|
66
|
+
set(key: string, value: JsonValue, options?: CacheClientSetOptions): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the given key from the cache store.
|
|
69
|
+
*/
|
|
70
|
+
delete(key: string): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Options given when constructing a {@link CacheClient}.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export declare type CacheClientOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* An optional default TTL (in milliseconds) to be set when getting a client
|
|
81
|
+
* instance. If not provided, data will persist indefinitely by default (or
|
|
82
|
+
* can be configured per entry at set-time).
|
|
83
|
+
*/
|
|
84
|
+
defaultTtl?: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Options passed to {@link CacheClient.set}.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare type CacheClientSetOptions = {
|
|
93
|
+
/**
|
|
94
|
+
* Optional TTL in milliseconds. Defaults to the TTL provided when the client
|
|
95
|
+
* was set up (or no TTL if none are provided).
|
|
96
|
+
*/
|
|
97
|
+
ttl?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Manages access to cache stores that plugins get.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare interface CacheService {
|
|
106
|
+
/**
|
|
107
|
+
* Provides backend plugins cache connections for themselves.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
*
|
|
111
|
+
* The purpose of this method is to allow plugins to get isolated data stores
|
|
112
|
+
* so that plugins are discouraged from cache-level integration and/or cache
|
|
113
|
+
* key collisions.
|
|
114
|
+
*/
|
|
115
|
+
getClient: (options?: CacheClientOptions) => CacheClient;
|
|
54
116
|
}
|
|
55
117
|
|
|
56
118
|
/**
|
|
@@ -119,6 +181,12 @@ export declare namespace coreServices {
|
|
|
119
181
|
* @public
|
|
120
182
|
*/
|
|
121
183
|
const pluginMetadata: ServiceRef<PluginMetadataService, "plugin">;
|
|
184
|
+
/**
|
|
185
|
+
* The service reference for the root scoped {@link RootHttpRouterService}.
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
const rootHttpRouter: ServiceRef<RootHttpRouterService, "root">;
|
|
122
190
|
/**
|
|
123
191
|
* The service reference for the root scoped {@link RootLifecycleService}.
|
|
124
192
|
*
|
|
@@ -201,8 +269,30 @@ export declare function createServiceRef<T>(options: {
|
|
|
201
269
|
defaultFactory?: (service: ServiceRef<T, 'root'>) => Promise<ServiceFactory<T> | (() => ServiceFactory<T>)>;
|
|
202
270
|
}): ServiceRef<T, 'root'>;
|
|
203
271
|
|
|
204
|
-
/**
|
|
205
|
-
|
|
272
|
+
/**
|
|
273
|
+
* The DatabaseService manages access to databases that Plugins get.
|
|
274
|
+
*gs
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
export declare interface DatabaseService {
|
|
278
|
+
/**
|
|
279
|
+
* getClient provides backend plugins database connections for itself.
|
|
280
|
+
*
|
|
281
|
+
* The purpose of this method is to allow plugins to get isolated data
|
|
282
|
+
* stores so that plugins are discouraged from database integration.
|
|
283
|
+
*/
|
|
284
|
+
getClient(): Promise<Knex>;
|
|
285
|
+
/**
|
|
286
|
+
* This property is used to control the behavior of database migrations.
|
|
287
|
+
*/
|
|
288
|
+
migrations?: {
|
|
289
|
+
/**
|
|
290
|
+
* skip database migrations. Useful if connecting to a read-only database.
|
|
291
|
+
*
|
|
292
|
+
* @defaultValue false
|
|
293
|
+
*/
|
|
294
|
+
skip?: boolean;
|
|
295
|
+
};
|
|
206
296
|
}
|
|
207
297
|
|
|
208
298
|
/**
|
|
@@ -307,9 +397,6 @@ export declare interface LoggerService {
|
|
|
307
397
|
child(meta: LogMeta): LoggerService;
|
|
308
398
|
}
|
|
309
399
|
|
|
310
|
-
/** @public */
|
|
311
|
-
export declare function loggerToWinstonLogger(logger: LoggerService, opts?: TransportStreamOptions): Logger;
|
|
312
|
-
|
|
313
400
|
/**
|
|
314
401
|
* @public
|
|
315
402
|
*/
|
|
@@ -501,6 +588,17 @@ export declare type ReadUrlResponse = {
|
|
|
501
588
|
etag?: string;
|
|
502
589
|
};
|
|
503
590
|
|
|
591
|
+
/**
|
|
592
|
+
* @public
|
|
593
|
+
*/
|
|
594
|
+
export declare interface RootHttpRouterService {
|
|
595
|
+
/**
|
|
596
|
+
* Registers a handler at the root of the backend router.
|
|
597
|
+
* The path is required and may not be empty.
|
|
598
|
+
*/
|
|
599
|
+
use(path: string, handler: Handler): void;
|
|
600
|
+
}
|
|
601
|
+
|
|
504
602
|
/** @public */
|
|
505
603
|
export declare interface RootLifecycleService extends LifecycleService {
|
|
506
604
|
}
|
|
@@ -631,8 +729,29 @@ declare type ServiceRefsToInstances<T extends {
|
|
|
631
729
|
}[keyof T]]: T[name] extends ServiceRef<infer TImpl> ? TImpl : never;
|
|
632
730
|
};
|
|
633
731
|
|
|
634
|
-
/**
|
|
635
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Interface for creating and validating tokens.
|
|
734
|
+
*
|
|
735
|
+
* @public
|
|
736
|
+
*/
|
|
737
|
+
export declare interface TokenManagerService {
|
|
738
|
+
/**
|
|
739
|
+
* Fetches a valid token.
|
|
740
|
+
*
|
|
741
|
+
* @remarks
|
|
742
|
+
*
|
|
743
|
+
* Tokens are valid for roughly one hour; the actual deadline is set in the
|
|
744
|
+
* payload `exp` claim. Never hold on to tokens for reuse; always ask for a
|
|
745
|
+
* new one for each outgoing request. This ensures that you always get a
|
|
746
|
+
* valid, fresh one.
|
|
747
|
+
*/
|
|
748
|
+
getToken(): Promise<{
|
|
749
|
+
token: string;
|
|
750
|
+
}>;
|
|
751
|
+
/**
|
|
752
|
+
* Validates a given token.
|
|
753
|
+
*/
|
|
754
|
+
authenticate(token: string): Promise<void>;
|
|
636
755
|
}
|
|
637
756
|
|
|
638
757
|
/** @public */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-plugin-api",
|
|
3
3
|
"description": "Core API used by Backstage backend plugins",
|
|
4
|
-
"version": "0.0.0-nightly-
|
|
4
|
+
"version": "0.0.0-nightly-20230106022925",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
@@ -33,17 +33,16 @@
|
|
|
33
33
|
"start": "backstage-cli package start"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@backstage/backend-
|
|
37
|
-
"@backstage/
|
|
38
|
-
"@backstage/
|
|
39
|
-
"@backstage/
|
|
36
|
+
"@backstage/backend-tasks": "^0.0.0-nightly-20230106022925",
|
|
37
|
+
"@backstage/config": "^0.0.0-nightly-20230106022925",
|
|
38
|
+
"@backstage/plugin-permission-common": "^0.0.0-nightly-20230106022925",
|
|
39
|
+
"@backstage/types": "^1.0.2",
|
|
40
40
|
"@types/express": "^4.17.6",
|
|
41
41
|
"express": "^4.17.1",
|
|
42
|
-
"
|
|
43
|
-
"winston-transport": "^4.5.0"
|
|
42
|
+
"knex": "^2.0.0"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"@backstage/cli": "^0.0.0-nightly-
|
|
45
|
+
"@backstage/cli": "^0.0.0-nightly-20230106022925"
|
|
47
46
|
},
|
|
48
47
|
"files": [
|
|
49
48
|
"dist",
|