@backstage/backend-defaults 0.3.3 → 0.4.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +41 -27
  2. package/auth/package.json +1 -1
  3. package/cache/package.json +1 -1
  4. package/database/package.json +1 -1
  5. package/discovery/package.json +1 -1
  6. package/dist/auth.d.ts +1 -1
  7. package/dist/cache.d.ts +1 -1
  8. package/dist/database.d.ts +1 -1
  9. package/dist/discovery.d.ts +1 -1
  10. package/dist/httpAuth.d.ts +1 -1
  11. package/dist/httpRouter.cjs.js +30 -48
  12. package/dist/httpRouter.cjs.js.map +1 -1
  13. package/dist/httpRouter.d.ts +2 -11
  14. package/dist/index.cjs.js +21 -19
  15. package/dist/index.cjs.js.map +1 -1
  16. package/dist/lifecycle.d.ts +1 -1
  17. package/dist/logger.d.ts +1 -1
  18. package/dist/permissions.d.ts +1 -1
  19. package/dist/rootConfig.cjs.js +16 -14
  20. package/dist/rootConfig.cjs.js.map +1 -1
  21. package/dist/rootConfig.d.ts +1 -1
  22. package/dist/rootHealth.cjs.js +40 -0
  23. package/dist/rootHealth.cjs.js.map +1 -0
  24. package/dist/rootHealth.d.ts +9 -0
  25. package/dist/rootHttpRouter.cjs.js +70 -43
  26. package/dist/rootHttpRouter.cjs.js.map +1 -1
  27. package/dist/rootHttpRouter.d.ts +2 -1
  28. package/dist/rootLifecycle.d.ts +1 -1
  29. package/dist/rootLogger.d.ts +1 -1
  30. package/dist/scheduler.d.ts +1 -1
  31. package/dist/urlReader.cjs.js +13 -16
  32. package/dist/urlReader.cjs.js.map +1 -1
  33. package/dist/urlReader.d.ts +1 -1
  34. package/dist/userInfo.d.ts +1 -1
  35. package/httpAuth/package.json +1 -1
  36. package/httpRouter/package.json +1 -1
  37. package/lifecycle/package.json +1 -1
  38. package/logger/package.json +1 -1
  39. package/package.json +18 -12
  40. package/permissions/package.json +1 -1
  41. package/rootConfig/package.json +1 -1
  42. package/rootHealth/package.json +6 -0
  43. package/rootHttpRouter/package.json +1 -1
  44. package/rootLifecycle/package.json +1 -1
  45. package/rootLogger/package.json +1 -1
  46. package/scheduler/package.json +1 -1
  47. package/urlReader/package.json +1 -1
  48. package/userInfo/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,64 +1,78 @@
1
1
  # @backstage/backend-defaults
2
2
 
3
- ## 0.3.3
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1cb84d7: **BREAKING**: Removed the depreacted `getPath` option from `httpRouterServiceFactory`, as well as the `HttpRouterFactoryOptions` type.
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - baec79d: Fix bug where ISO durations could no longer be used for schedules
11
+ - 53ced70: Added a new Root Health Service which adds new endpoints for health checks.
12
+ - 2f99178: The `ServiceFactoryTest.get` method was deprecated and the `ServiceFactoryTest.getSubject` should be used instead. The `getSubject` method has the same behavior, but has a better method name to indicate that the service instance returned is the subject currently being tested.
13
+ - 083eaf9: Fix bug where ISO durations could no longer be used for schedules
14
+ - b05e1e1: Service factories exported by this package have been updated to use the new service factory format that doesn't use a callback.
15
+ - 419f387: Refactor of `rootHttpRouterServiceFactory` to allow it to be constructed with options, but without declaring options via `createServiceFactory`.
16
+ - cb14a05: Repack the package to fix issues with typescript with named exports
17
+ - b9ed1bb: bumped better-sqlite3 from ^9.0.0 to ^11.0.0
18
+ - e28af58: Refactor of `rootConfigServiceFactory` to allow it to be constructed with options, but without declaring options via `createServiceFactory`.
8
19
  - Updated dependencies
9
- - @backstage/backend-plugin-api@0.6.21
10
- - @backstage/backend-common@0.23.2
11
- - @backstage/backend-app-api@0.7.9
12
- - @backstage/plugin-auth-node@0.4.16
13
- - @backstage/plugin-events-node@0.3.7
14
- - @backstage/plugin-permission-node@0.7.32
20
+ - @backstage/backend-plugin-api@0.7.0
21
+ - @backstage/backend-app-api@0.8.0
22
+ - @backstage/backend-common@0.23.3
23
+ - @backstage/plugin-permission-node@0.8.0
24
+ - @backstage/integration@1.13.0
25
+ - @backstage/plugin-events-node@0.3.8
26
+ - @backstage/plugin-auth-node@0.4.17
27
+ - @backstage/config-loader@1.8.1
15
28
  - @backstage/backend-dev-utils@0.1.4
16
29
  - @backstage/cli-common@0.1.14
17
30
  - @backstage/config@1.2.0
18
- - @backstage/config-loader@1.8.1
19
31
  - @backstage/errors@1.2.4
20
- - @backstage/integration@1.12.0
21
32
  - @backstage/integration-aws-node@0.1.12
22
33
  - @backstage/types@1.1.1
23
34
 
24
- ## 0.3.2
35
+ ## 0.3.4-next.1
25
36
 
26
37
  ### Patch Changes
27
38
 
39
+ - b9ed1bb: bumped better-sqlite3 from ^9.0.0 to ^11.0.0
28
40
  - Updated dependencies
29
- - @backstage/backend-app-api@0.7.8
30
- - @backstage/backend-common@0.23.1
41
+ - @backstage/backend-common@0.23.3-next.1
42
+ - @backstage/backend-app-api@0.7.10-next.1
31
43
  - @backstage/backend-dev-utils@0.1.4
32
- - @backstage/backend-plugin-api@0.6.20
44
+ - @backstage/backend-plugin-api@0.6.22-next.1
33
45
  - @backstage/cli-common@0.1.14
34
46
  - @backstage/config@1.2.0
35
47
  - @backstage/config-loader@1.8.1
36
48
  - @backstage/errors@1.2.4
37
- - @backstage/integration@1.12.0
49
+ - @backstage/integration@1.13.0-next.0
38
50
  - @backstage/integration-aws-node@0.1.12
39
51
  - @backstage/types@1.1.1
40
- - @backstage/plugin-auth-node@0.4.15
41
- - @backstage/plugin-events-node@0.3.6
42
- - @backstage/plugin-permission-node@0.7.31
52
+ - @backstage/plugin-auth-node@0.4.17-next.1
53
+ - @backstage/plugin-events-node@0.3.8-next.1
54
+ - @backstage/plugin-permission-node@0.7.33-next.1
43
55
 
44
- ## 0.3.1
56
+ ## 0.3.3-next.0
45
57
 
46
58
  ### Patch Changes
47
59
 
48
- - 2cacbb9: Repack the package to fix issues with typescript with named exports
60
+ - 53ced70: Added a new Root Health Service which adds new endpoints for health checks.
61
+ - 083eaf9: Fix bug where ISO durations could no longer be used for schedules
62
+ - cb14a05: Repack the package to fix issues with typescript with named exports
49
63
  - Updated dependencies
50
- - @backstage/backend-common@0.23.1
51
- - @backstage/backend-app-api@0.7.7
52
- - @backstage/plugin-auth-node@0.4.15
53
- - @backstage/plugin-events-node@0.3.6
54
- - @backstage/plugin-permission-node@0.7.31
64
+ - @backstage/backend-plugin-api@0.6.21-next.0
65
+ - @backstage/backend-common@0.23.2-next.0
66
+ - @backstage/integration@1.13.0-next.0
67
+ - @backstage/backend-app-api@0.7.9-next.0
68
+ - @backstage/plugin-auth-node@0.4.16-next.0
69
+ - @backstage/plugin-events-node@0.3.7-next.0
70
+ - @backstage/plugin-permission-node@0.7.32-next.0
55
71
  - @backstage/backend-dev-utils@0.1.4
56
- - @backstage/backend-plugin-api@0.6.20
57
72
  - @backstage/cli-common@0.1.14
58
73
  - @backstage/config@1.2.0
59
74
  - @backstage/config-loader@1.8.1
60
75
  - @backstage/errors@1.2.4
61
- - @backstage/integration@1.12.0
62
76
  - @backstage/integration-aws-node@0.1.12
63
77
  - @backstage/types@1.1.1
64
78
 
package/auth/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__auth",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "main": "../dist/auth.cjs.js",
5
5
  "types": "../dist/auth.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__cache",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "main": "../dist/cache.cjs.js",
5
5
  "types": "../dist/cache.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__database",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "main": "../dist/database.cjs.js",
5
5
  "types": "../dist/database.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/backend-defaults__discovery",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "main": "../dist/discovery.cjs.js",
5
5
  "types": "../dist/discovery.d.ts"
6
6
  }
package/dist/auth.d.ts CHANGED
@@ -9,6 +9,6 @@ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
9
9
  *
10
10
  * @public
11
11
  */
12
- declare const authServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.AuthService, "plugin">;
12
+ declare const authServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.AuthService, "plugin", undefined>;
13
13
 
14
14
  export { authServiceFactory };
package/dist/cache.d.ts CHANGED
@@ -11,7 +11,7 @@ import { Config } from '@backstage/config';
11
11
  *
12
12
  * @public
13
13
  */
14
- declare const cacheServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.CacheService, "plugin">;
14
+ declare const cacheServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.CacheService, "plugin", undefined>;
15
15
 
16
16
  /**
17
17
  * Options given when constructing a {@link CacheManager}.
@@ -11,7 +11,7 @@ import { Config } from '@backstage/config';
11
11
  *
12
12
  * @public
13
13
  */
14
- declare const databaseServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.DatabaseService, "plugin">;
14
+ declare const databaseServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.DatabaseService, "plugin", undefined>;
15
15
 
16
16
  /**
17
17
  * Creation options for {@link DatabaseManager}.
@@ -11,7 +11,7 @@ import { Config } from '@backstage/config';
11
11
  *
12
12
  * @public
13
13
  */
14
- declare const discoveryServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.DiscoveryService, "plugin">;
14
+ declare const discoveryServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.DiscoveryService, "plugin", undefined>;
15
15
 
16
16
  /**
17
17
  * HostDiscovery is a basic PluginEndpointDiscovery implementation
@@ -10,6 +10,6 @@ import { HttpAuthService } from '@backstage/backend-plugin-api';
10
10
  *
11
11
  * @public
12
12
  */
13
- declare const httpAuthServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<HttpAuthService, "plugin">;
13
+ declare const httpAuthServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<HttpAuthService, "plugin", undefined>;
14
14
 
15
15
  export { httpAuthServiceFactory };
@@ -135,56 +135,38 @@ function createCookieAuthRefreshMiddleware(options) {
135
135
  return router;
136
136
  }
137
137
 
138
- const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
139
- (options) => ({
140
- service: backendPluginApi.coreServices.httpRouter,
141
- initialization: "always",
142
- deps: {
143
- plugin: backendPluginApi.coreServices.pluginMetadata,
144
- config: backendPluginApi.coreServices.rootConfig,
145
- logger: backendPluginApi.coreServices.logger,
146
- lifecycle: backendPluginApi.coreServices.lifecycle,
147
- rootHttpRouter: backendPluginApi.coreServices.rootHttpRouter,
148
- auth: backendPluginApi.coreServices.auth,
149
- httpAuth: backendPluginApi.coreServices.httpAuth
150
- },
151
- async factory({
152
- auth,
138
+ const httpRouterServiceFactory = backendPluginApi.createServiceFactory({
139
+ service: backendPluginApi.coreServices.httpRouter,
140
+ initialization: "always",
141
+ deps: {
142
+ plugin: backendPluginApi.coreServices.pluginMetadata,
143
+ config: backendPluginApi.coreServices.rootConfig,
144
+ lifecycle: backendPluginApi.coreServices.lifecycle,
145
+ rootHttpRouter: backendPluginApi.coreServices.rootHttpRouter,
146
+ auth: backendPluginApi.coreServices.auth,
147
+ httpAuth: backendPluginApi.coreServices.httpAuth
148
+ },
149
+ async factory({ auth, httpAuth, config, plugin, rootHttpRouter, lifecycle }) {
150
+ const router = Router__default.default();
151
+ rootHttpRouter.use(`/api/${plugin.getId()}`, router);
152
+ const credentialsBarrier = createCredentialsBarrier({
153
153
  httpAuth,
154
- config,
155
- logger,
156
- plugin,
157
- rootHttpRouter,
158
- lifecycle
159
- }) {
160
- if (options?.getPath) {
161
- logger.warn(
162
- `DEPRECATION WARNING: The 'getPath' option for HttpRouterService is deprecated. The ability to reconfigure the '/api/' path prefix for plugins will be removed in the future.`
163
- );
154
+ config
155
+ });
156
+ router.use(createAuthIntegrationRouter({ auth }));
157
+ router.use(createLifecycleMiddleware({ lifecycle }));
158
+ router.use(credentialsBarrier.middleware);
159
+ router.use(createCookieAuthRefreshMiddleware({ auth, httpAuth }));
160
+ return {
161
+ use(handler) {
162
+ router.use(handler);
163
+ },
164
+ addAuthPolicy(policy) {
165
+ credentialsBarrier.addAuthPolicy(policy);
164
166
  }
165
- const getPath = options?.getPath ?? ((id) => `/api/${id}`);
166
- const path = getPath(plugin.getId());
167
- const router = Router__default.default();
168
- rootHttpRouter.use(path, router);
169
- const credentialsBarrier = createCredentialsBarrier({
170
- httpAuth,
171
- config
172
- });
173
- router.use(createAuthIntegrationRouter({ auth }));
174
- router.use(createLifecycleMiddleware({ lifecycle }));
175
- router.use(credentialsBarrier.middleware);
176
- router.use(createCookieAuthRefreshMiddleware({ auth, httpAuth }));
177
- return {
178
- use(handler) {
179
- router.use(handler);
180
- },
181
- addAuthPolicy(policy) {
182
- credentialsBarrier.addAuthPolicy(policy);
183
- }
184
- };
185
- }
186
- })
187
- );
167
+ };
168
+ }
169
+ });
188
170
 
189
171
  exports.createLifecycleMiddleware = createLifecycleMiddleware;
190
172
  exports.httpRouterServiceFactory = httpRouterServiceFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"httpRouter.cjs.js","sources":["../src/entrypoints/httpRouter/createLifecycleMiddleware.ts","../src/entrypoints/httpRouter/createCredentialsBarrier.ts","../src/entrypoints/httpRouter/createAuthIntegrationRouter.ts","../src/entrypoints/httpRouter/createCookieAuthRefreshMiddleware.ts","../src/entrypoints/httpRouter/httpRouterServiceFactory.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\nimport { LifecycleService } from '@backstage/backend-plugin-api';\nimport { ServiceUnavailableError } from '@backstage/errors';\nimport { HumanDuration, durationToMilliseconds } from '@backstage/types';\nimport { RequestHandler } from 'express';\n\nexport const DEFAULT_TIMEOUT = { seconds: 5 };\n\n/**\n * Options for {@link createLifecycleMiddleware}.\n * @public\n */\nexport interface LifecycleMiddlewareOptions {\n lifecycle: LifecycleService;\n /**\n * The maximum time that paused requests will wait for the service to start, before returning an error.\n *\n * Defaults to 5 seconds.\n */\n startupRequestPauseTimeout?: HumanDuration;\n}\n\n/**\n * Creates a middleware that pauses requests until the service has started.\n *\n * @remarks\n *\n * Requests that arrive before the service has started will be paused until startup is complete.\n * If the service does not start within the provided timeout, the request will be rejected with a\n * {@link @backstage/errors#ServiceUnavailableError}.\n *\n * If the service is shutting down, all requests will be rejected with a\n * {@link @backstage/errors#ServiceUnavailableError}.\n *\n * @public\n */\nexport function createLifecycleMiddleware(\n options: LifecycleMiddlewareOptions,\n): RequestHandler {\n const { lifecycle, startupRequestPauseTimeout = DEFAULT_TIMEOUT } = options;\n\n let state: 'init' | 'up' | 'down' = 'init';\n const waiting = new Set<{\n next: (err?: Error) => void;\n timeout: NodeJS.Timeout;\n }>();\n\n lifecycle.addStartupHook(async () => {\n if (state === 'init') {\n state = 'up';\n for (const item of waiting) {\n clearTimeout(item.timeout);\n item.next();\n }\n waiting.clear();\n }\n });\n\n lifecycle.addShutdownHook(async () => {\n state = 'down';\n\n for (const item of waiting) {\n clearTimeout(item.timeout);\n item.next(new ServiceUnavailableError('Service is shutting down'));\n }\n waiting.clear();\n });\n\n const timeoutMs = durationToMilliseconds(startupRequestPauseTimeout);\n\n return (_req, _res, next) => {\n if (state === 'up') {\n next();\n return;\n } else if (state === 'down') {\n next(new ServiceUnavailableError('Service is shutting down'));\n return;\n }\n\n const item = {\n next,\n timeout: setTimeout(() => {\n if (waiting.delete(item)) {\n next(new ServiceUnavailableError('Service has not started up yet'));\n }\n }, timeoutMs),\n };\n\n waiting.add(item);\n };\n}\n","/*\n * Copyright 2024 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 HttpAuthService,\n HttpRouterServiceAuthPolicy,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { RequestHandler } from 'express';\nimport { pathToRegexp } from 'path-to-regexp';\n\nexport function createPathPolicyPredicate(policyPath: string) {\n if (policyPath === '/' || policyPath === '*') {\n return () => true;\n }\n\n const pathRegex = pathToRegexp(policyPath, undefined, {\n end: false,\n });\n\n return (path: string): boolean => {\n return pathRegex.test(path);\n };\n}\n\nexport function createCredentialsBarrier(options: {\n httpAuth: HttpAuthService;\n config: RootConfigService;\n}): {\n middleware: RequestHandler;\n addAuthPolicy: (policy: HttpRouterServiceAuthPolicy) => void;\n} {\n const { httpAuth, config } = options;\n\n const disableDefaultAuthPolicy = config.getOptionalBoolean(\n 'backend.auth.dangerouslyDisableDefaultAuthPolicy',\n );\n\n if (disableDefaultAuthPolicy) {\n return {\n middleware: (_req, _res, next) => next(),\n addAuthPolicy: () => {},\n };\n }\n\n const unauthenticatedPredicates = new Array<(path: string) => boolean>();\n const cookiePredicates = new Array<(path: string) => boolean>();\n\n const middleware: RequestHandler = (req, _, next) => {\n const allowsUnauthenticated = unauthenticatedPredicates.some(predicate =>\n predicate(req.path),\n );\n\n if (allowsUnauthenticated) {\n next();\n return;\n }\n\n const allowsCookie = cookiePredicates.some(predicate =>\n predicate(req.path),\n );\n\n httpAuth\n .credentials(req, {\n allow: ['user', 'service'],\n allowLimitedAccess: allowsCookie,\n })\n .then(\n () => next(),\n err => next(err),\n );\n };\n\n const addAuthPolicy = (policy: HttpRouterServiceAuthPolicy) => {\n if (policy.allow === 'unauthenticated') {\n unauthenticatedPredicates.push(createPathPolicyPredicate(policy.path));\n } else if (policy.allow === 'user-cookie') {\n cookiePredicates.push(createPathPolicyPredicate(policy.path));\n } else {\n throw new Error('Invalid auth policy');\n }\n };\n\n return { middleware, addAuthPolicy };\n}\n","/*\n * Copyright 2024 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 { AuthService } from '@backstage/backend-plugin-api';\nimport express from 'express';\nimport Router from 'express-promise-router';\n\nexport function createAuthIntegrationRouter(options: {\n auth: AuthService;\n}): express.Router {\n const router = Router();\n\n router.get('/.backstage/auth/v1/jwks.json', async (_req, res) => {\n const { keys } = await options.auth.listPublicServiceKeys();\n\n res.json({ keys });\n });\n\n return router;\n}\n","/*\n * Copyright 2024 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 { AuthService, HttpAuthService } from '@backstage/backend-plugin-api';\nimport Router from 'express-promise-router';\n\nconst WELL_KNOWN_COOKIE_PATH_V1 = '/.backstage/auth/v1/cookie';\n\n/**\n * @public\n * Creates a middleware that can be used to refresh the cookie for the user.\n */\nexport function createCookieAuthRefreshMiddleware(options: {\n auth: AuthService;\n httpAuth: HttpAuthService;\n}) {\n const { auth, httpAuth } = options;\n const router = Router();\n\n // Endpoint that sets the cookie for the user\n router.get(WELL_KNOWN_COOKIE_PATH_V1, async (_, res) => {\n const { expiresAt } = await httpAuth.issueUserCookie(res);\n res.json({ expiresAt: expiresAt.toISOString() });\n });\n\n // Endpoint that removes the cookie for the user\n router.delete(WELL_KNOWN_COOKIE_PATH_V1, async (_, res) => {\n const credentials = await auth.getNoneCredentials();\n await httpAuth.issueUserCookie(res, { credentials });\n res.status(204).end();\n });\n\n return router;\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 { Handler } from 'express';\nimport PromiseRouter from 'express-promise-router';\nimport {\n coreServices,\n createServiceFactory,\n HttpRouterServiceAuthPolicy,\n} from '@backstage/backend-plugin-api';\nimport { createLifecycleMiddleware } from './createLifecycleMiddleware';\nimport { createCredentialsBarrier } from './createCredentialsBarrier';\nimport { createAuthIntegrationRouter } from './createAuthIntegrationRouter';\nimport { createCookieAuthRefreshMiddleware } from './createCookieAuthRefreshMiddleware';\n\n/**\n * @public\n */\nexport interface HttpRouterFactoryOptions {\n /**\n * A callback used to generate the path for each plugin, defaults to `/api/{pluginId}`.\n */\n getPath?(pluginId: string): string;\n}\n\n/**\n * HTTP route registration for plugins.\n *\n * See {@link @backstage/code-plugin-api#HttpRouterService}\n * and {@link https://backstage.io/docs/backend-system/core-services/http-router | the service docs}\n * for more information.\n *\n * @public\n */\nexport const httpRouterServiceFactory = createServiceFactory(\n (options?: HttpRouterFactoryOptions) => ({\n service: coreServices.httpRouter,\n initialization: 'always',\n deps: {\n plugin: coreServices.pluginMetadata,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n lifecycle: coreServices.lifecycle,\n rootHttpRouter: coreServices.rootHttpRouter,\n auth: coreServices.auth,\n httpAuth: coreServices.httpAuth,\n },\n async factory({\n auth,\n httpAuth,\n config,\n logger,\n plugin,\n rootHttpRouter,\n lifecycle,\n }) {\n if (options?.getPath) {\n logger.warn(\n `DEPRECATION WARNING: The 'getPath' option for HttpRouterService is deprecated. The ability to reconfigure the '/api/' path prefix for plugins will be removed in the future.`,\n );\n }\n const getPath = options?.getPath ?? (id => `/api/${id}`);\n const path = getPath(plugin.getId());\n\n const router = PromiseRouter();\n rootHttpRouter.use(path, router);\n\n const credentialsBarrier = createCredentialsBarrier({\n httpAuth,\n config,\n });\n\n router.use(createAuthIntegrationRouter({ auth }));\n router.use(createLifecycleMiddleware({ lifecycle }));\n router.use(credentialsBarrier.middleware);\n router.use(createCookieAuthRefreshMiddleware({ auth, httpAuth }));\n\n return {\n use(handler: Handler): void {\n router.use(handler);\n },\n addAuthPolicy(policy: HttpRouterServiceAuthPolicy): void {\n credentialsBarrier.addAuthPolicy(policy);\n },\n };\n },\n }),\n);\n"],"names":["ServiceUnavailableError","durationToMilliseconds","pathToRegexp","Router","createServiceFactory","coreServices","PromiseRouter"],"mappings":";;;;;;;;;;;;AAqBa,MAAA,eAAA,GAAkB,EAAE,OAAA,EAAS,CAAE,EAAA,CAAA;AA8BrC,SAAS,0BACd,OACgB,EAAA;AAChB,EAAA,MAAM,EAAE,SAAA,EAAW,0BAA6B,GAAA,eAAA,EAAoB,GAAA,OAAA,CAAA;AAEpE,EAAA,IAAI,KA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OAAA;AAAA,QACL,IAAI,OAAwB,EAAA;AAC1B,UAAA,MAAA,CAAO,IAAI,OAAO,CAAA,CAAA;AAAA,SACpB;AAAA,QACA,cAAc,MAA2C,EAAA;AACvD,UAAA,kBAAA,CAAmB,cAAc,MAAM,CAAA,CAAA;AAAA,SACzC;AAAA,OACF,CAAA;AAAA,KACF;AAAA,GACF,CAAA;AACF;;;;;"}
1
+ {"version":3,"file":"httpRouter.cjs.js","sources":["../src/entrypoints/httpRouter/createLifecycleMiddleware.ts","../src/entrypoints/httpRouter/createCredentialsBarrier.ts","../src/entrypoints/httpRouter/createAuthIntegrationRouter.ts","../src/entrypoints/httpRouter/createCookieAuthRefreshMiddleware.ts","../src/entrypoints/httpRouter/httpRouterServiceFactory.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\nimport { LifecycleService } from '@backstage/backend-plugin-api';\nimport { ServiceUnavailableError } from '@backstage/errors';\nimport { HumanDuration, durationToMilliseconds } from '@backstage/types';\nimport { RequestHandler } from 'express';\n\nexport const DEFAULT_TIMEOUT = { seconds: 5 };\n\n/**\n * Options for {@link createLifecycleMiddleware}.\n * @public\n */\nexport interface LifecycleMiddlewareOptions {\n lifecycle: LifecycleService;\n /**\n * The maximum time that paused requests will wait for the service to start, before returning an error.\n *\n * Defaults to 5 seconds.\n */\n startupRequestPauseTimeout?: HumanDuration;\n}\n\n/**\n * Creates a middleware that pauses requests until the service has started.\n *\n * @remarks\n *\n * Requests that arrive before the service has started will be paused until startup is complete.\n * If the service does not start within the provided timeout, the request will be rejected with a\n * {@link @backstage/errors#ServiceUnavailableError}.\n *\n * If the service is shutting down, all requests will be rejected with a\n * {@link @backstage/errors#ServiceUnavailableError}.\n *\n * @public\n */\nexport function createLifecycleMiddleware(\n options: LifecycleMiddlewareOptions,\n): RequestHandler {\n const { lifecycle, startupRequestPauseTimeout = DEFAULT_TIMEOUT } = options;\n\n let state: 'init' | 'up' | 'down' = 'init';\n const waiting = new Set<{\n next: (err?: Error) => void;\n timeout: NodeJS.Timeout;\n }>();\n\n lifecycle.addStartupHook(async () => {\n if (state === 'init') {\n state = 'up';\n for (const item of waiting) {\n clearTimeout(item.timeout);\n item.next();\n }\n waiting.clear();\n }\n });\n\n lifecycle.addShutdownHook(async () => {\n state = 'down';\n\n for (const item of waiting) {\n clearTimeout(item.timeout);\n item.next(new ServiceUnavailableError('Service is shutting down'));\n }\n waiting.clear();\n });\n\n const timeoutMs = durationToMilliseconds(startupRequestPauseTimeout);\n\n return (_req, _res, next) => {\n if (state === 'up') {\n next();\n return;\n } else if (state === 'down') {\n next(new ServiceUnavailableError('Service is shutting down'));\n return;\n }\n\n const item = {\n next,\n timeout: setTimeout(() => {\n if (waiting.delete(item)) {\n next(new ServiceUnavailableError('Service has not started up yet'));\n }\n }, timeoutMs),\n };\n\n waiting.add(item);\n };\n}\n","/*\n * Copyright 2024 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 HttpAuthService,\n HttpRouterServiceAuthPolicy,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { RequestHandler } from 'express';\nimport { pathToRegexp } from 'path-to-regexp';\n\nexport function createPathPolicyPredicate(policyPath: string) {\n if (policyPath === '/' || policyPath === '*') {\n return () => true;\n }\n\n const pathRegex = pathToRegexp(policyPath, undefined, {\n end: false,\n });\n\n return (path: string): boolean => {\n return pathRegex.test(path);\n };\n}\n\nexport function createCredentialsBarrier(options: {\n httpAuth: HttpAuthService;\n config: RootConfigService;\n}): {\n middleware: RequestHandler;\n addAuthPolicy: (policy: HttpRouterServiceAuthPolicy) => void;\n} {\n const { httpAuth, config } = options;\n\n const disableDefaultAuthPolicy = config.getOptionalBoolean(\n 'backend.auth.dangerouslyDisableDefaultAuthPolicy',\n );\n\n if (disableDefaultAuthPolicy) {\n return {\n middleware: (_req, _res, next) => next(),\n addAuthPolicy: () => {},\n };\n }\n\n const unauthenticatedPredicates = new Array<(path: string) => boolean>();\n const cookiePredicates = new Array<(path: string) => boolean>();\n\n const middleware: RequestHandler = (req, _, next) => {\n const allowsUnauthenticated = unauthenticatedPredicates.some(predicate =>\n predicate(req.path),\n );\n\n if (allowsUnauthenticated) {\n next();\n return;\n }\n\n const allowsCookie = cookiePredicates.some(predicate =>\n predicate(req.path),\n );\n\n httpAuth\n .credentials(req, {\n allow: ['user', 'service'],\n allowLimitedAccess: allowsCookie,\n })\n .then(\n () => next(),\n err => next(err),\n );\n };\n\n const addAuthPolicy = (policy: HttpRouterServiceAuthPolicy) => {\n if (policy.allow === 'unauthenticated') {\n unauthenticatedPredicates.push(createPathPolicyPredicate(policy.path));\n } else if (policy.allow === 'user-cookie') {\n cookiePredicates.push(createPathPolicyPredicate(policy.path));\n } else {\n throw new Error('Invalid auth policy');\n }\n };\n\n return { middleware, addAuthPolicy };\n}\n","/*\n * Copyright 2024 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 { AuthService } from '@backstage/backend-plugin-api';\nimport express from 'express';\nimport Router from 'express-promise-router';\n\nexport function createAuthIntegrationRouter(options: {\n auth: AuthService;\n}): express.Router {\n const router = Router();\n\n router.get('/.backstage/auth/v1/jwks.json', async (_req, res) => {\n const { keys } = await options.auth.listPublicServiceKeys();\n\n res.json({ keys });\n });\n\n return router;\n}\n","/*\n * Copyright 2024 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 { AuthService, HttpAuthService } from '@backstage/backend-plugin-api';\nimport Router from 'express-promise-router';\n\nconst WELL_KNOWN_COOKIE_PATH_V1 = '/.backstage/auth/v1/cookie';\n\n/**\n * @public\n * Creates a middleware that can be used to refresh the cookie for the user.\n */\nexport function createCookieAuthRefreshMiddleware(options: {\n auth: AuthService;\n httpAuth: HttpAuthService;\n}) {\n const { auth, httpAuth } = options;\n const router = Router();\n\n // Endpoint that sets the cookie for the user\n router.get(WELL_KNOWN_COOKIE_PATH_V1, async (_, res) => {\n const { expiresAt } = await httpAuth.issueUserCookie(res);\n res.json({ expiresAt: expiresAt.toISOString() });\n });\n\n // Endpoint that removes the cookie for the user\n router.delete(WELL_KNOWN_COOKIE_PATH_V1, async (_, res) => {\n const credentials = await auth.getNoneCredentials();\n await httpAuth.issueUserCookie(res, { credentials });\n res.status(204).end();\n });\n\n return router;\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 { Handler } from 'express';\nimport PromiseRouter from 'express-promise-router';\nimport {\n coreServices,\n createServiceFactory,\n HttpRouterServiceAuthPolicy,\n} from '@backstage/backend-plugin-api';\nimport { createLifecycleMiddleware } from './createLifecycleMiddleware';\nimport { createCredentialsBarrier } from './createCredentialsBarrier';\nimport { createAuthIntegrationRouter } from './createAuthIntegrationRouter';\nimport { createCookieAuthRefreshMiddleware } from './createCookieAuthRefreshMiddleware';\n\n/**\n * HTTP route registration for plugins.\n *\n * See {@link @backstage/code-plugin-api#HttpRouterService}\n * and {@link https://backstage.io/docs/backend-system/core-services/http-router | the service docs}\n * for more information.\n *\n * @public\n */\nexport const httpRouterServiceFactory = createServiceFactory({\n service: coreServices.httpRouter,\n initialization: 'always',\n deps: {\n plugin: coreServices.pluginMetadata,\n config: coreServices.rootConfig,\n lifecycle: coreServices.lifecycle,\n rootHttpRouter: coreServices.rootHttpRouter,\n auth: coreServices.auth,\n httpAuth: coreServices.httpAuth,\n },\n async factory({ auth, httpAuth, config, plugin, rootHttpRouter, lifecycle }) {\n const router = PromiseRouter();\n\n rootHttpRouter.use(`/api/${plugin.getId()}`, router);\n\n const credentialsBarrier = createCredentialsBarrier({\n httpAuth,\n config,\n });\n\n router.use(createAuthIntegrationRouter({ auth }));\n router.use(createLifecycleMiddleware({ lifecycle }));\n router.use(credentialsBarrier.middleware);\n router.use(createCookieAuthRefreshMiddleware({ auth, httpAuth }));\n\n return {\n use(handler: Handler): void {\n router.use(handler);\n },\n addAuthPolicy(policy: HttpRouterServiceAuthPolicy): void {\n credentialsBarrier.addAuthPolicy(policy);\n },\n };\n },\n});\n"],"names":["ServiceUnavailableError","durationToMilliseconds","pathToRegexp","Router","createServiceFactory","coreServices","P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CAAA;AAAA,OACzC;AAAA,KACF,CAAA;AAAA,GACF;AACF,CAAC;;;;;"}
@@ -3,15 +3,6 @@ import { LifecycleService } from '@backstage/backend-plugin-api';
3
3
  import { HumanDuration } from '@backstage/types';
4
4
  import { RequestHandler } from 'express';
5
5
 
6
- /**
7
- * @public
8
- */
9
- interface HttpRouterFactoryOptions {
10
- /**
11
- * A callback used to generate the path for each plugin, defaults to `/api/{pluginId}`.
12
- */
13
- getPath?(pluginId: string): string;
14
- }
15
6
  /**
16
7
  * HTTP route registration for plugins.
17
8
  *
@@ -21,7 +12,7 @@ interface HttpRouterFactoryOptions {
21
12
  *
22
13
  * @public
23
14
  */
24
- declare const httpRouterServiceFactory: (options?: HttpRouterFactoryOptions | undefined) => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.HttpRouterService, "plugin">;
15
+ declare const httpRouterServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.HttpRouterService, "plugin", undefined>;
25
16
 
26
17
  /**
27
18
  * Options for {@link createLifecycleMiddleware}.
@@ -52,4 +43,4 @@ interface LifecycleMiddlewareOptions {
52
43
  */
53
44
  declare function createLifecycleMiddleware(options: LifecycleMiddlewareOptions): RequestHandler;
54
45
 
55
- export { type HttpRouterFactoryOptions, type LifecycleMiddlewareOptions, createLifecycleMiddleware, httpRouterServiceFactory };
46
+ export { type LifecycleMiddlewareOptions, createLifecycleMiddleware, httpRouterServiceFactory };
package/dist/index.cjs.js CHANGED
@@ -11,6 +11,7 @@ var lifecycle = require('@backstage/backend-defaults/lifecycle');
11
11
  var logger = require('@backstage/backend-defaults/logger');
12
12
  var permissions = require('@backstage/backend-defaults/permissions');
13
13
  var rootConfig = require('@backstage/backend-defaults/rootConfig');
14
+ var rootHealth = require('@backstage/backend-defaults/rootHealth');
14
15
  var rootHttpRouter = require('@backstage/backend-defaults/rootHttpRouter');
15
16
  var rootLifecycle = require('@backstage/backend-defaults/rootLifecycle');
16
17
  var rootLogger = require('@backstage/backend-defaults/rootLogger');
@@ -20,25 +21,26 @@ var userInfo = require('@backstage/backend-defaults/userInfo');
20
21
  var pluginEventsNode = require('@backstage/plugin-events-node');
21
22
 
22
23
  const defaultServiceFactories = [
23
- auth.authServiceFactory(),
24
- cache.cacheServiceFactory(),
25
- rootConfig.rootConfigServiceFactory(),
26
- database.databaseServiceFactory(),
27
- discovery.discoveryServiceFactory(),
28
- httpAuth.httpAuthServiceFactory(),
29
- httpRouter.httpRouterServiceFactory(),
30
- backendAppApi.identityServiceFactory(),
31
- lifecycle.lifecycleServiceFactory(),
32
- logger.loggerServiceFactory(),
33
- permissions.permissionsServiceFactory(),
34
- rootHttpRouter.rootHttpRouterServiceFactory(),
35
- rootLifecycle.rootLifecycleServiceFactory(),
36
- rootLogger.rootLoggerServiceFactory(),
37
- scheduler.schedulerServiceFactory(),
38
- backendAppApi.tokenManagerServiceFactory(),
39
- userInfo.userInfoServiceFactory(),
40
- urlReader.urlReaderServiceFactory(),
41
- pluginEventsNode.eventsServiceFactory()
24
+ auth.authServiceFactory,
25
+ cache.cacheServiceFactory,
26
+ rootConfig.rootConfigServiceFactory,
27
+ database.databaseServiceFactory,
28
+ discovery.discoveryServiceFactory,
29
+ httpAuth.httpAuthServiceFactory,
30
+ httpRouter.httpRouterServiceFactory,
31
+ backendAppApi.identityServiceFactory,
32
+ lifecycle.lifecycleServiceFactory,
33
+ logger.loggerServiceFactory,
34
+ permissions.permissionsServiceFactory,
35
+ rootHealth.rootHealthServiceFactory,
36
+ rootHttpRouter.rootHttpRouterServiceFactory,
37
+ rootLifecycle.rootLifecycleServiceFactory,
38
+ rootLogger.rootLoggerServiceFactory,
39
+ scheduler.schedulerServiceFactory,
40
+ backendAppApi.tokenManagerServiceFactory,
41
+ userInfo.userInfoServiceFactory,
42
+ urlReader.urlReaderServiceFactory,
43
+ pluginEventsNode.eventsServiceFactory
42
44
  ];
43
45
  function createBackend() {
44
46
  return backendAppApi.createSpecializedBackend({ defaultServiceFactories });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/CreateBackend.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\nimport {\n Backend,\n createSpecializedBackend,\n identityServiceFactory,\n tokenManagerServiceFactory,\n} from '@backstage/backend-app-api';\nimport { authServiceFactory } from '@backstage/backend-defaults/auth';\nimport { cacheServiceFactory } from '@backstage/backend-defaults/cache';\nimport { databaseServiceFactory } from '@backstage/backend-defaults/database';\nimport { discoveryServiceFactory } from '@backstage/backend-defaults/discovery';\nimport { httpAuthServiceFactory } from '@backstage/backend-defaults/httpAuth';\nimport { httpRouterServiceFactory } from '@backstage/backend-defaults/httpRouter';\nimport { lifecycleServiceFactory } from '@backstage/backend-defaults/lifecycle';\nimport { loggerServiceFactory } from '@backstage/backend-defaults/logger';\nimport { permissionsServiceFactory } from '@backstage/backend-defaults/permissions';\nimport { rootConfigServiceFactory } from '@backstage/backend-defaults/rootConfig';\nimport { rootHttpRouterServiceFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { rootLifecycleServiceFactory } from '@backstage/backend-defaults/rootLifecycle';\nimport { rootLoggerServiceFactory } from '@backstage/backend-defaults/rootLogger';\nimport { schedulerServiceFactory } from '@backstage/backend-defaults/scheduler';\nimport { urlReaderServiceFactory } from '@backstage/backend-defaults/urlReader';\nimport { userInfoServiceFactory } from '@backstage/backend-defaults/userInfo';\nimport { eventsServiceFactory } from '@backstage/plugin-events-node';\n\nexport const defaultServiceFactories = [\n authServiceFactory(),\n cacheServiceFactory(),\n rootConfigServiceFactory(),\n databaseServiceFactory(),\n discoveryServiceFactory(),\n httpAuthServiceFactory(),\n httpRouterServiceFactory(),\n identityServiceFactory(),\n lifecycleServiceFactory(),\n loggerServiceFactory(),\n permissionsServiceFactory(),\n rootHttpRouterServiceFactory(),\n rootLifecycleServiceFactory(),\n rootLoggerServiceFactory(),\n schedulerServiceFactory(),\n tokenManagerServiceFactory(),\n userInfoServiceFactory(),\n urlReaderServiceFactory(),\n eventsServiceFactory(),\n];\n\n/**\n * @public\n */\nexport function createBackend(): Backend {\n return createSpecializedBackend({ defaultServiceFactories });\n}\n"],"names":["authServiceFactory","cacheServiceFactory","rootConfigServiceFactory","databaseServiceFactory","discoveryServiceFactory","httpAuthServiceFactory","httpRouterServiceFactory","identityServiceFactory","lifecycleServiceFactory","loggerServiceFactory","permissionsServiceFactory","rootHttpRouterServiceFactory","rootLifecycleServiceFactory","rootLoggerServiceFactory","schedulerServiceFactory","tokenManagerServiceFactory","userInfoServiceFactory","urlReaderServiceFactory","eventsServiceFactory","createSpecializedBackend"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,uBAA0B,GAAA;AAAA,EACrCA,uBAAmB,EAAA;AAAA,EACnBC,yBAAoB,EAAA;AAAA,EACpBC,mCAAyB,EAAA;AAAA,EACzBC,+BAAuB,EAAA;AAAA,EACvBC,iCAAwB,EAAA;AAAA,EACxBC,+BAAuB,EAAA;AAAA,EACvBC,mCAAyB,EAAA;AAAA,EACzBC,oCAAuB,EAAA;AAAA,EACvBC,iCAAwB,EAAA;AAAA,EACxBC,2BAAqB,EAAA;AAAA,EACrBC,qCAA0B,EAAA;AAAA,EAC1BC,2CAA6B,EAAA;AAAA,EAC7BC,yCAA4B,EAAA;AAAA,EAC5BC,mCAAyB,EAAA;AAAA,EACzBC,iCAAwB,EAAA;AAAA,EACxBC,wCAA2B,EAAA;AAAA,EAC3BC,+BAAuB,EAAA;AAAA,EACvBC,iCAAwB,EAAA;AAAA,EACxBC,qCAAqB,EAAA;AACvB,CAAA,CAAA;AAKO,SAAS,aAAyB,GAAA;AACvC,EAAO,OAAAC,sCAAA,CAAyB,EAAE,uBAAA,EAAyB,CAAA,CAAA;AAC7D;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/CreateBackend.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\nimport {\n Backend,\n createSpecializedBackend,\n identityServiceFactory,\n tokenManagerServiceFactory,\n} from '@backstage/backend-app-api';\nimport { authServiceFactory } from '@backstage/backend-defaults/auth';\nimport { cacheServiceFactory } from '@backstage/backend-defaults/cache';\nimport { databaseServiceFactory } from '@backstage/backend-defaults/database';\nimport { discoveryServiceFactory } from '@backstage/backend-defaults/discovery';\nimport { httpAuthServiceFactory } from '@backstage/backend-defaults/httpAuth';\nimport { httpRouterServiceFactory } from '@backstage/backend-defaults/httpRouter';\nimport { lifecycleServiceFactory } from '@backstage/backend-defaults/lifecycle';\nimport { loggerServiceFactory } from '@backstage/backend-defaults/logger';\nimport { permissionsServiceFactory } from '@backstage/backend-defaults/permissions';\nimport { rootConfigServiceFactory } from '@backstage/backend-defaults/rootConfig';\nimport { rootHealthServiceFactory } from '@backstage/backend-defaults/rootHealth';\nimport { rootHttpRouterServiceFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { rootLifecycleServiceFactory } from '@backstage/backend-defaults/rootLifecycle';\nimport { rootLoggerServiceFactory } from '@backstage/backend-defaults/rootLogger';\nimport { schedulerServiceFactory } from '@backstage/backend-defaults/scheduler';\nimport { urlReaderServiceFactory } from '@backstage/backend-defaults/urlReader';\nimport { userInfoServiceFactory } from '@backstage/backend-defaults/userInfo';\nimport { eventsServiceFactory } from '@backstage/plugin-events-node';\n\nexport const defaultServiceFactories = [\n authServiceFactory,\n cacheServiceFactory,\n rootConfigServiceFactory,\n databaseServiceFactory,\n discoveryServiceFactory,\n httpAuthServiceFactory,\n httpRouterServiceFactory,\n identityServiceFactory,\n lifecycleServiceFactory,\n loggerServiceFactory,\n permissionsServiceFactory,\n rootHealthServiceFactory,\n rootHttpRouterServiceFactory,\n rootLifecycleServiceFactory,\n rootLoggerServiceFactory,\n schedulerServiceFactory,\n tokenManagerServiceFactory,\n userInfoServiceFactory,\n urlReaderServiceFactory,\n eventsServiceFactory,\n];\n\n/**\n * @public\n */\nexport function createBackend(): Backend {\n return createSpecializedBackend({ defaultServiceFactories });\n}\n"],"names":["authServiceFactory","cacheServiceFactory","rootConfigServiceFactory","databaseServiceFactory","discoveryServiceFactory","httpAuthServiceFactory","httpRouterServiceFactory","identityServiceFactory","lifecycleServiceFactory","loggerServiceFactory","permissionsServiceFactory","rootHealthServiceFactory","rootHttpRouterServiceFactory","rootLifecycleServiceFactory","rootLoggerServiceFactory","schedulerServiceFactory","tokenManagerServiceFactory","userInfoServiceFactory","urlReaderServiceFactory","eventsServiceFactory","createSpecializedBackend"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyCO,MAAM,uBAA0B,GAAA;AAAA,EACrCA,uBAAA;AAAA,EACAC,yBAAA;AAAA,EACAC,mCAAA;AAAA,EACAC,+BAAA;AAAA,EACAC,iCAAA;AAAA,EACAC,+BAAA;AAAA,EACAC,mCAAA;AAAA,EACAC,oCAAA;AAAA,EACAC,iCAAA;AAAA,EACAC,2BAAA;AAAA,EACAC,qCAAA;AAAA,EACAC,mCAAA;AAAA,EACAC,2CAAA;AAAA,EACAC,yCAAA;AAAA,EACAC,mCAAA;AAAA,EACAC,iCAAA;AAAA,EACAC,wCAAA;AAAA,EACAC,+BAAA;AAAA,EACAC,iCAAA;AAAA,EACAC,qCAAA;AACF,CAAA,CAAA;AAKO,SAAS,aAAyB,GAAA;AACvC,EAAO,OAAAC,sCAAA,CAAyB,EAAE,uBAAA,EAAyB,CAAA,CAAA;AAC7D;;;;"}
@@ -10,6 +10,6 @@ import { LifecycleService } from '@backstage/backend-plugin-api';
10
10
  *
11
11
  * @public
12
12
  */
13
- declare const lifecycleServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<LifecycleService, "plugin">;
13
+ declare const lifecycleServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<LifecycleService, "plugin", undefined>;
14
14
 
15
15
  export { lifecycleServiceFactory };
package/dist/logger.d.ts CHANGED
@@ -9,6 +9,6 @@ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
9
9
  *
10
10
  * @public
11
11
  */
12
- declare const loggerServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.LoggerService, "plugin">;
12
+ declare const loggerServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.LoggerService, "plugin", undefined>;
13
13
 
14
14
  export { loggerServiceFactory };
@@ -9,6 +9,6 @@ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
9
9
  *
10
10
  * @public
11
11
  */
12
- declare const permissionsServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.PermissionsService, "plugin">;
12
+ declare const permissionsServiceFactory: _backstage_backend_plugin_api.ServiceFactoryCompat<_backstage_backend_plugin_api.PermissionsService, "plugin", undefined>;
13
13
 
14
14
  export { permissionsServiceFactory };
@@ -5,20 +5,22 @@ var backendPluginApi = require('@backstage/backend-plugin-api');
5
5
  var configLoader = require('@backstage/config-loader');
6
6
  require('@manypkg/get-packages');
7
7
 
8
- const rootConfigServiceFactory = backendPluginApi.createServiceFactory(
9
- (options) => ({
10
- service: backendPluginApi.coreServices.rootConfig,
11
- deps: {},
12
- async factory() {
13
- const source = configLoader.ConfigSources.default({
14
- argv: options?.argv,
15
- remote: options?.remote,
16
- watch: options?.watch
17
- });
18
- console.log(`Loading config from ${source}`);
19
- return await configLoader.ConfigSources.toConfig(source);
20
- }
21
- })
8
+ const rootConfigServiceFactoryWithOptions = (options) => backendPluginApi.createServiceFactory({
9
+ service: backendPluginApi.coreServices.rootConfig,
10
+ deps: {},
11
+ async factory() {
12
+ const source = configLoader.ConfigSources.default({
13
+ argv: options?.argv,
14
+ remote: options?.remote,
15
+ watch: options?.watch
16
+ });
17
+ console.log(`Loading config from ${source}`);
18
+ return await configLoader.ConfigSources.toConfig(source);
19
+ }
20
+ })();
21
+ const rootConfigServiceFactory = Object.assign(
22
+ rootConfigServiceFactoryWithOptions,
23
+ rootConfigServiceFactoryWithOptions()
22
24
  );
23
25
 
24
26
  exports.createConfigSecretEnumerator = createConfigSecretEnumerator.createConfigSecretEnumerator;
@@ -1 +1 @@
1
- {"version":3,"file":"rootConfig.cjs.js","sources":["../src/entrypoints/rootConfig/rootConfigServiceFactory.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\nimport {\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport {\n ConfigSources,\n RemoteConfigSourceOptions,\n} from '@backstage/config-loader';\n\n/**\n * Access to static configuration.\n *\n * See {@link @backstage/code-plugin-api#RootConfigService}\n * and {@link https://backstage.io/docs/backend-system/core-services/root-config | the service docs}\n * for more information.\n *\n * @public\n */\nexport interface RootConfigFactoryOptions {\n /**\n * Process arguments to use instead of the default `process.argv()`.\n */\n argv?: string[];\n\n /**\n * Enables and sets options for remote configuration loading.\n */\n remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;\n watch?: boolean;\n}\n\n/**\n * @public\n */\nexport const rootConfigServiceFactory = createServiceFactory(\n (options?: RootConfigFactoryOptions) => ({\n service: coreServices.rootConfig,\n deps: {},\n async factory() {\n const source = ConfigSources.default({\n argv: options?.argv,\n remote: options?.remote,\n watch: options?.watch,\n });\n console.log(`Loading config from ${source}`);\n return await ConfigSources.toConfig(source);\n },\n }),\n);\n"],"names":["createServiceFactory","coreServices","ConfigSources"],"mappings":";;;;;;;AAkDO,MAAM,wBAA2B,GAAAA,qCAAA;AAAA,EACtC,CAAC,OAAwC,MAAA;AAAA,IACvC,SAASC,6BAAa,CAAA,UAAA;AAAA,IACtB,MAAM,EAAC;AAAA,IACP,MAAM,OAAU,GAAA;AACd,MAAM,MAAA,MAAA,GAASC,2BAAc,OAAQ,CAAA;AAAA,QACnC,MAAM,OAAS,EAAA,IAAA;AAAA,QACf,QAAQ,OAAS,EAAA,MAAA;AAAA,QACjB,OAAO,OAAS,EAAA,KAAA;AAAA,OACjB,CAAA,CAAA;AACD,MAAQ,OAAA,CAAA,GAAA,CAAI,CAAuB,oBAAA,EAAA,MAAM,CAAE,CAAA,CAAA,CAAA;AAC3C,MAAO,OAAA,MAAMA,0BAAc,CAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AAAA,KAC5C;AAAA,GACF,CAAA;AACF;;;;;"}
1
+ {"version":3,"file":"rootConfig.cjs.js","sources":["../src/entrypoints/rootConfig/rootConfigServiceFactory.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\nimport {\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport {\n ConfigSources,\n RemoteConfigSourceOptions,\n} from '@backstage/config-loader';\n\n/**\n * Access to static configuration.\n *\n * See {@link @backstage/code-plugin-api#RootConfigService}\n * and {@link https://backstage.io/docs/backend-system/core-services/root-config | the service docs}\n * for more information.\n *\n * @public\n */\nexport interface RootConfigFactoryOptions {\n /**\n * Process arguments to use instead of the default `process.argv()`.\n */\n argv?: string[];\n\n /**\n * Enables and sets options for remote configuration loading.\n */\n remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;\n watch?: boolean;\n}\n\nexport const rootConfigServiceFactoryWithOptions = (\n options?: RootConfigFactoryOptions,\n) =>\n createServiceFactory({\n service: coreServices.rootConfig,\n deps: {},\n async factory() {\n const source = ConfigSources.default({\n argv: options?.argv,\n remote: options?.remote,\n watch: options?.watch,\n });\n console.log(`Loading config from ${source}`);\n return await ConfigSources.toConfig(source);\n },\n })();\n\n/**\n * @public\n */\nexport const rootConfigServiceFactory = Object.assign(\n rootConfigServiceFactoryWithOptions,\n rootConfigServiceFactoryWithOptions(),\n);\n"],"names":["createServiceFactory","coreServices","ConfigSources"],"mappings":";;;;;;;AA+Ca,MAAA,mCAAA,GAAsC,CACjD,OAAA,KAEAA,qCAAqB,CAAA;AAAA,EACnB,SAASC,6BAAa,CAAA,UAAA;AAAA,EACtB,MAAM,EAAC;AAAA,EACP,MAAM,OAAU,GAAA;AACd,IAAM,MAAA,MAAA,GAASC,2BAAc,OAAQ,CAAA;AAAA,MACnC,MAAM,OAAS,EAAA,IAAA;AAAA,MACf,QAAQ,OAAS,EAAA,MAAA;AAAA,MACjB,OAAO,OAAS,EAAA,KAAA;AAAA,KACjB,CAAA,CAAA;AACD,IAAQ,OAAA,CAAA,GAAA,CAAI,CAAuB,oBAAA,EAAA,MAAM,CAAE,CAAA,CAAA,CAAA;AAC3C,IAAO,OAAA,MAAMA,0BAAc,CAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AAAA,GAC5C;AACF,CAAC,CAAE,EAAA,CAAA;AAKE,MAAM,2BAA2B,MAAO,CAAA,MAAA;AAAA,EAC7C,mCAAA;AAAA,EACA,mCAAoC,EAAA;AACtC;;;;;"}
@@ -33,6 +33,6 @@ interface RootConfigFactoryOptions {
33
33
  /**
34
34
  * @public
35
35
  */
36
- declare const rootConfigServiceFactory: (options?: RootConfigFactoryOptions | undefined) => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.RootConfigService, "root">;
36
+ declare const rootConfigServiceFactory: ((options?: RootConfigFactoryOptions) => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.RootConfigService, "root">) & _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.RootConfigService, "root">;
37
37
 
38
38
  export { type RootConfigFactoryOptions, createConfigSecretEnumerator, rootConfigServiceFactory };
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+
5
+ class DefaultRootHealthService {
6
+ constructor(options) {
7
+ this.options = options;
8
+ options.lifecycle.addStartupHook(() => {
9
+ this.#isRunning = true;
10
+ });
11
+ options.lifecycle.addShutdownHook(() => {
12
+ this.#isRunning = false;
13
+ });
14
+ }
15
+ #isRunning = false;
16
+ async getLiveness() {
17
+ return { status: 200, payload: { status: "ok" } };
18
+ }
19
+ async getReadiness() {
20
+ if (!this.#isRunning) {
21
+ return {
22
+ status: 503,
23
+ payload: { message: "Backend has not started yet", status: "error" }
24
+ };
25
+ }
26
+ return { status: 200, payload: { status: "ok" } };
27
+ }
28
+ }
29
+ const rootHealthServiceFactory = backendPluginApi.createServiceFactory({
30
+ service: backendPluginApi.coreServices.rootHealth,
31
+ deps: {
32
+ lifecycle: backendPluginApi.coreServices.rootLifecycle
33
+ },
34
+ async factory({ lifecycle }) {
35
+ return new DefaultRootHealthService({ lifecycle });
36
+ }
37
+ });
38
+
39
+ exports.rootHealthServiceFactory = rootHealthServiceFactory;
40
+ //# sourceMappingURL=rootHealth.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rootHealth.cjs.js","sources":["../src/entrypoints/rootHealth/rootHealthServiceFactory.ts"],"sourcesContent":["/*\n * Copyright 2024 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 RootHealthService,\n RootLifecycleService,\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\n\n/** @internal */\nexport class DefaultRootHealthService implements RootHealthService {\n #isRunning = false;\n\n constructor(readonly options: { lifecycle: RootLifecycleService }) {\n options.lifecycle.addStartupHook(() => {\n this.#isRunning = true;\n });\n options.lifecycle.addShutdownHook(() => {\n this.#isRunning = false;\n });\n }\n\n async getLiveness(): Promise<{ status: number; payload?: any }> {\n return { status: 200, payload: { status: 'ok' } };\n }\n\n async getReadiness(): Promise<{ status: number; payload?: any }> {\n if (!this.#isRunning) {\n return {\n status: 503,\n payload: { message: 'Backend has not started yet', status: 'error' },\n };\n }\n\n return { status: 200, payload: { status: 'ok' } };\n }\n}\n\n/**\n * @public\n */\nexport const rootHealthServiceFactory = createServiceFactory({\n service: coreServices.rootHealth,\n deps: {\n lifecycle: coreServices.rootLifecycle,\n },\n async factory({ lifecycle }) {\n return new DefaultRootHealthService({ lifecycle });\n },\n});\n"],"names":["createServiceFactory","coreServices"],"mappings":";;;;AAwBO,MAAM,wBAAsD,CAAA;AAAA,EAGjE,YAAqB,OAA8C,EAAA;AAA9C,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA,CAAA;AACnB,IAAQ,OAAA,CAAA,SAAA,CAA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