@backstage/backend-app-api 0.0.0-nightly-20230207022622 → 0.0.0-nightly-20230208023037

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -295,7 +295,7 @@ function readHttpsOptions(config) {
295
295
  }
296
296
  return {
297
297
  certificate: {
298
- type: "plain",
298
+ type: "pem",
299
299
  cert: cc.getString("certificate.cert"),
300
300
  key: cc.getString("certificate.key")
301
301
  }
@@ -929,7 +929,7 @@ class BackendLifecycleImpl {
929
929
  }
930
930
  _isCalled = new WeakMap();
931
931
  _shutdownTasks = new WeakMap();
932
- const rootLifecycleFactory = backendPluginApi.createServiceFactory({
932
+ const rootLifecycleServiceFactory = backendPluginApi.createServiceFactory({
933
933
  service: backendPluginApi.coreServices.rootLifecycle,
934
934
  deps: {
935
935
  logger: backendPluginApi.coreServices.rootLogger
@@ -968,17 +968,28 @@ class BackendInitializer {
968
968
  __privateAdd$3(this, _doStart);
969
969
  __privateAdd$3(this, _resolveInitOrder);
970
970
  __privateAdd$3(this, _startPromise, void 0);
971
- __privateAdd$3(this, _features, /* @__PURE__ */ new Map());
971
+ __privateAdd$3(this, _features, new Array());
972
972
  __privateAdd$3(this, _registerInits, new Array());
973
973
  __privateAdd$3(this, _extensionPoints, /* @__PURE__ */ new Map());
974
974
  __privateAdd$3(this, _serviceHolder, void 0);
975
975
  __privateSet$3(this, _serviceHolder, serviceHolder);
976
976
  }
977
- add(feature, options) {
977
+ add(feature) {
978
978
  if (__privateGet$3(this, _startPromise)) {
979
979
  throw new Error("feature can not be added after the backend has started");
980
980
  }
981
- __privateGet$3(this, _features).set(feature, options);
981
+ if (feature.$$type !== "@backstage/BackendFeature") {
982
+ throw new Error(
983
+ `Failed to add feature, invalid type '${feature.$$type}'`
984
+ );
985
+ }
986
+ const internalFeature = feature;
987
+ if (internalFeature.version !== "v1") {
988
+ throw new Error(
989
+ `Failed to add feature, invalid version '${internalFeature.version}'`
990
+ );
991
+ }
992
+ __privateGet$3(this, _features).push(internalFeature);
982
993
  }
983
994
  async start() {
984
995
  if (__privateGet$3(this, _startPromise)) {
@@ -1060,44 +1071,32 @@ doStart_fn = async function() {
1060
1071
  await __privateGet$3(this, _serviceHolder).get(ref, "root");
1061
1072
  }
1062
1073
  }
1063
- for (const [feature] of __privateGet$3(this, _features)) {
1064
- const provides = /* @__PURE__ */ new Set();
1065
- let registerInit = void 0;
1066
- feature.register({
1067
- registerExtensionPoint: (extensionPointRef, impl) => {
1068
- if (registerInit) {
1069
- throw new Error("registerExtensionPoint called after registerInit");
1070
- }
1071
- if (__privateGet$3(this, _extensionPoints).has(extensionPointRef)) {
1072
- throw new Error(`API ${extensionPointRef.id} already registered`);
1073
- }
1074
- __privateGet$3(this, _extensionPoints).set(extensionPointRef, impl);
1075
- provides.add(extensionPointRef);
1076
- },
1077
- registerInit: (registerOptions) => {
1078
- if (registerInit) {
1079
- throw new Error("registerInit must only be called once");
1074
+ for (const feature of __privateGet$3(this, _features)) {
1075
+ for (const r of feature.getRegistrations()) {
1076
+ const provides = /* @__PURE__ */ new Set();
1077
+ if (r.type === "plugin") {
1078
+ for (const [extRef, extImpl] of r.extensionPoints) {
1079
+ if (__privateGet$3(this, _extensionPoints).has(extRef)) {
1080
+ throw new Error(
1081
+ `ExtensionPoint with ID '${extRef.id}' is already registered`
1082
+ );
1083
+ }
1084
+ __privateGet$3(this, _extensionPoints).set(extRef, extImpl);
1085
+ provides.add(extRef);
1080
1086
  }
1081
- registerInit = {
1082
- id: feature.id,
1083
- provides,
1084
- consumes: new Set(Object.values(registerOptions.deps)),
1085
- deps: registerOptions.deps,
1086
- init: registerOptions.init
1087
- };
1088
1087
  }
1089
- });
1090
- if (!registerInit) {
1091
- throw new Error(
1092
- `registerInit was not called by register in ${feature.id}`
1093
- );
1088
+ __privateGet$3(this, _registerInits).push({
1089
+ id: r.type === "plugin" ? r.pluginId : `${r.pluginId}.${r.moduleId}`,
1090
+ provides,
1091
+ consumes: new Set(Object.values(r.init.deps)),
1092
+ init: r.init
1093
+ });
1094
1094
  }
1095
- __privateGet$3(this, _registerInits).push(registerInit);
1096
1095
  }
1097
1096
  const orderedRegisterResults = __privateMethod$2(this, _resolveInitOrder, resolveInitOrder_fn).call(this, __privateGet$3(this, _registerInits));
1098
1097
  for (const registerInit of orderedRegisterResults) {
1099
- const deps = await __privateMethod$2(this, _getInitDeps, getInitDeps_fn).call(this, registerInit.deps, registerInit.id);
1100
- await registerInit.init(deps);
1098
+ const deps = await __privateMethod$2(this, _getInitDeps, getInitDeps_fn).call(this, registerInit.init.deps, registerInit.id);
1099
+ await registerInit.init.func(deps);
1101
1100
  }
1102
1101
  };
1103
1102
  _resolveInitOrder = new WeakSet();
@@ -1356,7 +1355,7 @@ function createSpecializedBackend(options) {
1356
1355
  return new BackstageBackend(services);
1357
1356
  }
1358
1357
 
1359
- const cacheFactory = backendPluginApi.createServiceFactory({
1358
+ const cacheServiceFactory = backendPluginApi.createServiceFactory({
1360
1359
  service: backendPluginApi.coreServices.cache,
1361
1360
  deps: {
1362
1361
  config: backendPluginApi.coreServices.config,
@@ -1370,17 +1369,19 @@ const cacheFactory = backendPluginApi.createServiceFactory({
1370
1369
  }
1371
1370
  });
1372
1371
 
1373
- const configFactory = backendPluginApi.createServiceFactory({
1374
- service: backendPluginApi.coreServices.config,
1375
- deps: {},
1376
- async factory({}, options) {
1377
- const { argv = process.argv, remote } = options != null ? options : {};
1378
- const { config } = await loadBackendConfig({ argv, remote });
1379
- return config;
1380
- }
1381
- });
1372
+ const configServiceFactory = backendPluginApi.createServiceFactory(
1373
+ (options) => ({
1374
+ service: backendPluginApi.coreServices.config,
1375
+ deps: {},
1376
+ async factory({}) {
1377
+ const { argv = process.argv, remote } = options != null ? options : {};
1378
+ const { config } = await loadBackendConfig({ argv, remote });
1379
+ return config;
1380
+ }
1381
+ })
1382
+ );
1382
1383
 
1383
- const databaseFactory = backendPluginApi.createServiceFactory({
1384
+ const databaseServiceFactory = backendPluginApi.createServiceFactory({
1384
1385
  service: backendPluginApi.coreServices.database,
1385
1386
  deps: {
1386
1387
  config: backendPluginApi.coreServices.config,
@@ -1404,7 +1405,7 @@ const databaseFactory = backendPluginApi.createServiceFactory({
1404
1405
  }
1405
1406
  });
1406
1407
 
1407
- const discoveryFactory = backendPluginApi.createServiceFactory({
1408
+ const discoveryServiceFactory = backendPluginApi.createServiceFactory({
1408
1409
  service: backendPluginApi.coreServices.discovery,
1409
1410
  deps: {
1410
1411
  config: backendPluginApi.coreServices.config
@@ -1414,7 +1415,7 @@ const discoveryFactory = backendPluginApi.createServiceFactory({
1414
1415
  }
1415
1416
  });
1416
1417
 
1417
- const httpRouterFactory = backendPluginApi.createServiceFactory(
1418
+ const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
1418
1419
  (options) => ({
1419
1420
  service: backendPluginApi.coreServices.httpRouter,
1420
1421
  deps: {
@@ -1434,7 +1435,7 @@ const httpRouterFactory = backendPluginApi.createServiceFactory(
1434
1435
  })
1435
1436
  );
1436
1437
 
1437
- const identityFactory = backendPluginApi.createServiceFactory(
1438
+ const identityServiceFactory = backendPluginApi.createServiceFactory(
1438
1439
  (options) => ({
1439
1440
  service: backendPluginApi.coreServices.identity,
1440
1441
  deps: {
@@ -1446,7 +1447,7 @@ const identityFactory = backendPluginApi.createServiceFactory(
1446
1447
  })
1447
1448
  );
1448
1449
 
1449
- const lifecycleFactory = backendPluginApi.createServiceFactory({
1450
+ const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
1450
1451
  service: backendPluginApi.coreServices.lifecycle,
1451
1452
  deps: {
1452
1453
  logger: backendPluginApi.coreServices.logger,
@@ -1466,7 +1467,7 @@ const lifecycleFactory = backendPluginApi.createServiceFactory({
1466
1467
  }
1467
1468
  });
1468
1469
 
1469
- const loggerFactory = backendPluginApi.createServiceFactory({
1470
+ const loggerServiceFactory = backendPluginApi.createServiceFactory({
1470
1471
  service: backendPluginApi.coreServices.logger,
1471
1472
  deps: {
1472
1473
  rootLogger: backendPluginApi.coreServices.rootLogger,
@@ -1477,7 +1478,7 @@ const loggerFactory = backendPluginApi.createServiceFactory({
1477
1478
  }
1478
1479
  });
1479
1480
 
1480
- const permissionsFactory = backendPluginApi.createServiceFactory({
1481
+ const permissionsServiceFactory = backendPluginApi.createServiceFactory({
1481
1482
  service: backendPluginApi.coreServices.permissions,
1482
1483
  deps: {
1483
1484
  config: backendPluginApi.coreServices.config,
@@ -1586,11 +1587,8 @@ findConflictingPath_fn = function(newPath) {
1586
1587
  return void 0;
1587
1588
  };
1588
1589
 
1589
- function defaultConfigure({
1590
- app,
1591
- routes,
1592
- middleware
1593
- }) {
1590
+ function defaultConfigure(context) {
1591
+ const { app, routes, middleware } = context;
1594
1592
  app.use(middleware.helmet());
1595
1593
  app.use(middleware.cors());
1596
1594
  app.use(middleware.compression());
@@ -1599,41 +1597,41 @@ function defaultConfigure({
1599
1597
  app.use(middleware.notFound());
1600
1598
  app.use(middleware.error());
1601
1599
  }
1602
- const rootHttpRouterFactory = backendPluginApi.createServiceFactory({
1603
- service: backendPluginApi.coreServices.rootHttpRouter,
1604
- deps: {
1605
- config: backendPluginApi.coreServices.config,
1606
- rootLogger: backendPluginApi.coreServices.rootLogger,
1607
- lifecycle: backendPluginApi.coreServices.rootLifecycle
1608
- },
1609
- async factory({ config, rootLogger, lifecycle }, {
1610
- indexPath,
1611
- configure = defaultConfigure
1612
- } = {}) {
1613
- const logger = rootLogger.child({ service: "rootHttpRouter" });
1614
- const app = express__default["default"]();
1615
- const router = DefaultRootHttpRouter.create({ indexPath });
1616
- const middleware = MiddlewareFactory.create({ config, logger });
1617
- configure({
1618
- app,
1619
- routes: router.handler(),
1620
- middleware,
1621
- config,
1622
- logger,
1623
- lifecycle
1624
- });
1625
- const server = await createHttpServer(
1626
- app,
1627
- readHttpServerOptions(config.getOptionalConfig("backend")),
1628
- { logger }
1629
- );
1630
- lifecycle.addShutdownHook(() => server.stop());
1631
- await server.start();
1632
- return router;
1633
- }
1634
- });
1600
+ const rootHttpRouterServiceFactory = backendPluginApi.createServiceFactory(
1601
+ (options) => ({
1602
+ service: backendPluginApi.coreServices.rootHttpRouter,
1603
+ deps: {
1604
+ config: backendPluginApi.coreServices.config,
1605
+ rootLogger: backendPluginApi.coreServices.rootLogger,
1606
+ lifecycle: backendPluginApi.coreServices.rootLifecycle
1607
+ },
1608
+ async factory({ config, rootLogger, lifecycle }) {
1609
+ const { indexPath, configure = defaultConfigure } = options != null ? options : {};
1610
+ const logger = rootLogger.child({ service: "rootHttpRouter" });
1611
+ const app = express__default["default"]();
1612
+ const router = DefaultRootHttpRouter.create({ indexPath });
1613
+ const middleware = MiddlewareFactory.create({ config, logger });
1614
+ configure({
1615
+ app,
1616
+ routes: router.handler(),
1617
+ middleware,
1618
+ config,
1619
+ logger,
1620
+ lifecycle
1621
+ });
1622
+ const server = await createHttpServer(
1623
+ app,
1624
+ readHttpServerOptions(config.getOptionalConfig("backend")),
1625
+ { logger }
1626
+ );
1627
+ lifecycle.addShutdownHook(() => server.stop());
1628
+ await server.start();
1629
+ return router;
1630
+ }
1631
+ })
1632
+ );
1635
1633
 
1636
- const rootLoggerFactory = backendPluginApi.createServiceFactory({
1634
+ const rootLoggerServiceFactory = backendPluginApi.createServiceFactory({
1637
1635
  service: backendPluginApi.coreServices.rootLogger,
1638
1636
  deps: {
1639
1637
  config: backendPluginApi.coreServices.config
@@ -1655,7 +1653,7 @@ const rootLoggerFactory = backendPluginApi.createServiceFactory({
1655
1653
  }
1656
1654
  });
1657
1655
 
1658
- const schedulerFactory = backendPluginApi.createServiceFactory({
1656
+ const schedulerServiceFactory = backendPluginApi.createServiceFactory({
1659
1657
  service: backendPluginApi.coreServices.scheduler,
1660
1658
  deps: {
1661
1659
  plugin: backendPluginApi.coreServices.pluginMetadata,
@@ -1671,7 +1669,7 @@ const schedulerFactory = backendPluginApi.createServiceFactory({
1671
1669
  }
1672
1670
  });
1673
1671
 
1674
- const tokenManagerFactory = backendPluginApi.createServiceFactory({
1672
+ const tokenManagerServiceFactory = backendPluginApi.createServiceFactory({
1675
1673
  service: backendPluginApi.coreServices.tokenManager,
1676
1674
  deps: {
1677
1675
  config: backendPluginApi.coreServices.config,
@@ -1687,7 +1685,7 @@ const tokenManagerFactory = backendPluginApi.createServiceFactory({
1687
1685
  }
1688
1686
  });
1689
1687
 
1690
- const urlReaderFactory = backendPluginApi.createServiceFactory({
1688
+ const urlReaderServiceFactory = backendPluginApi.createServiceFactory({
1691
1689
  service: backendPluginApi.coreServices.urlReader,
1692
1690
  deps: {
1693
1691
  config: backendPluginApi.coreServices.config,
@@ -1704,26 +1702,26 @@ const urlReaderFactory = backendPluginApi.createServiceFactory({
1704
1702
  exports.DefaultRootHttpRouter = DefaultRootHttpRouter;
1705
1703
  exports.MiddlewareFactory = MiddlewareFactory;
1706
1704
  exports.WinstonLogger = WinstonLogger;
1707
- exports.cacheFactory = cacheFactory;
1708
- exports.configFactory = configFactory;
1705
+ exports.cacheServiceFactory = cacheServiceFactory;
1706
+ exports.configServiceFactory = configServiceFactory;
1709
1707
  exports.createConfigSecretEnumerator = createConfigSecretEnumerator;
1710
1708
  exports.createHttpServer = createHttpServer;
1711
1709
  exports.createSpecializedBackend = createSpecializedBackend;
1712
- exports.databaseFactory = databaseFactory;
1713
- exports.discoveryFactory = discoveryFactory;
1714
- exports.httpRouterFactory = httpRouterFactory;
1715
- exports.identityFactory = identityFactory;
1716
- exports.lifecycleFactory = lifecycleFactory;
1710
+ exports.databaseServiceFactory = databaseServiceFactory;
1711
+ exports.discoveryServiceFactory = discoveryServiceFactory;
1712
+ exports.httpRouterServiceFactory = httpRouterServiceFactory;
1713
+ exports.identityServiceFactory = identityServiceFactory;
1714
+ exports.lifecycleServiceFactory = lifecycleServiceFactory;
1717
1715
  exports.loadBackendConfig = loadBackendConfig;
1718
- exports.loggerFactory = loggerFactory;
1719
- exports.permissionsFactory = permissionsFactory;
1716
+ exports.loggerServiceFactory = loggerServiceFactory;
1717
+ exports.permissionsServiceFactory = permissionsServiceFactory;
1720
1718
  exports.readCorsOptions = readCorsOptions;
1721
1719
  exports.readHelmetOptions = readHelmetOptions;
1722
1720
  exports.readHttpServerOptions = readHttpServerOptions;
1723
- exports.rootHttpRouterFactory = rootHttpRouterFactory;
1724
- exports.rootLifecycleFactory = rootLifecycleFactory;
1725
- exports.rootLoggerFactory = rootLoggerFactory;
1726
- exports.schedulerFactory = schedulerFactory;
1727
- exports.tokenManagerFactory = tokenManagerFactory;
1728
- exports.urlReaderFactory = urlReaderFactory;
1721
+ exports.rootHttpRouterServiceFactory = rootHttpRouterServiceFactory;
1722
+ exports.rootLifecycleServiceFactory = rootLifecycleServiceFactory;
1723
+ exports.rootLoggerServiceFactory = rootLoggerServiceFactory;
1724
+ exports.schedulerServiceFactory = schedulerServiceFactory;
1725
+ exports.tokenManagerServiceFactory = tokenManagerServiceFactory;
1726
+ exports.urlReaderServiceFactory = urlReaderServiceFactory;
1729
1727
  //# sourceMappingURL=index.cjs.js.map