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

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.

Potentially problematic release.


This version of @backstage/backend-app-api might be problematic. Click here for more details.

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();
@@ -1148,6 +1147,23 @@ var __privateMethod$1 = (obj, member, method) => {
1148
1147
  return method;
1149
1148
  };
1150
1149
  var _providedFactories, _loadedDefaultFactories, _implementations, _rootServiceImplementations, _resolveFactory, resolveFactory_fn, _checkForMissingDeps, checkForMissingDeps_fn;
1150
+ function toInternalServiceFactory(factory) {
1151
+ const f = factory;
1152
+ if (f.$$type !== "@backstage/ServiceFactory") {
1153
+ throw new Error(`Invalid service factory, bad type '${f.$$type}'`);
1154
+ }
1155
+ if (f.version !== "v1") {
1156
+ throw new Error(`Invalid service factory, bad version '${f.version}'`);
1157
+ }
1158
+ return f;
1159
+ }
1160
+ const pluginMetadataServiceFactory = backendPluginApi.createServiceFactory(
1161
+ (options) => ({
1162
+ service: backendPluginApi.coreServices.pluginMetadata,
1163
+ deps: {},
1164
+ factory: async () => ({ getId: () => options.pluginId })
1165
+ })
1166
+ );
1151
1167
  class ServiceRegistry {
1152
1168
  constructor(factories) {
1153
1169
  __privateAdd$2(this, _resolveFactory);
@@ -1156,7 +1172,9 @@ class ServiceRegistry {
1156
1172
  __privateAdd$2(this, _loadedDefaultFactories, void 0);
1157
1173
  __privateAdd$2(this, _implementations, void 0);
1158
1174
  __privateAdd$2(this, _rootServiceImplementations, /* @__PURE__ */ new Map());
1159
- __privateSet$2(this, _providedFactories, new Map(factories.map((f) => [f.service.id, f])));
1175
+ __privateSet$2(this, _providedFactories, new Map(
1176
+ factories.map((sf) => [sf.service.id, toInternalServiceFactory(sf)])
1177
+ ));
1160
1178
  __privateSet$2(this, _loadedDefaultFactories, /* @__PURE__ */ new Map());
1161
1179
  __privateSet$2(this, _implementations, /* @__PURE__ */ new Map());
1162
1180
  }
@@ -1166,7 +1184,7 @@ class ServiceRegistry {
1166
1184
  get(ref, pluginId) {
1167
1185
  var _a;
1168
1186
  return (_a = __privateMethod$1(this, _resolveFactory, resolveFactory_fn).call(this, ref, pluginId)) == null ? void 0 : _a.then((factory) => {
1169
- if (factory.scope === "root") {
1187
+ if (factory.service.scope === "root") {
1170
1188
  let existing = __privateGet$2(this, _rootServiceImplementations).get(factory);
1171
1189
  if (!existing) {
1172
1190
  __privateMethod$1(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
@@ -1181,7 +1199,7 @@ class ServiceRegistry {
1181
1199
  rootDeps.push(target.then((impl) => [name, impl]));
1182
1200
  }
1183
1201
  existing = Promise.all(rootDeps).then(
1184
- (entries) => factory.factory(Object.fromEntries(entries))
1202
+ (entries) => factory.factory(Object.fromEntries(entries), void 0)
1185
1203
  );
1186
1204
  __privateGet$2(this, _rootServiceImplementations).set(factory, existing);
1187
1205
  }
@@ -1243,12 +1261,9 @@ _rootServiceImplementations = new WeakMap();
1243
1261
  _resolveFactory = new WeakSet();
1244
1262
  resolveFactory_fn = function(ref, pluginId) {
1245
1263
  if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
1246
- return Promise.resolve({
1247
- scope: "plugin",
1248
- service: backendPluginApi.coreServices.pluginMetadata,
1249
- deps: {},
1250
- factory: async () => ({ getId: () => pluginId })
1251
- });
1264
+ return Promise.resolve(
1265
+ toInternalServiceFactory(pluginMetadataServiceFactory({ pluginId }))
1266
+ );
1252
1267
  }
1253
1268
  let resolvedFactory = __privateGet$2(this, _providedFactories).get(ref.id);
1254
1269
  const { __defaultFactory: defaultFactory } = ref;
@@ -1259,7 +1274,7 @@ resolveFactory_fn = function(ref, pluginId) {
1259
1274
  let loadedFactory = __privateGet$2(this, _loadedDefaultFactories).get(defaultFactory);
1260
1275
  if (!loadedFactory) {
1261
1276
  loadedFactory = Promise.resolve().then(() => defaultFactory(ref)).then(
1262
- (f) => typeof f === "function" ? f() : f
1277
+ (f) => toInternalServiceFactory(typeof f === "function" ? f() : f)
1263
1278
  );
1264
1279
  __privateGet$2(this, _loadedDefaultFactories).set(defaultFactory, loadedFactory);
1265
1280
  }
@@ -1356,7 +1371,7 @@ function createSpecializedBackend(options) {
1356
1371
  return new BackstageBackend(services);
1357
1372
  }
1358
1373
 
1359
- const cacheFactory = backendPluginApi.createServiceFactory({
1374
+ const cacheServiceFactory = backendPluginApi.createServiceFactory({
1360
1375
  service: backendPluginApi.coreServices.cache,
1361
1376
  deps: {
1362
1377
  config: backendPluginApi.coreServices.config,
@@ -1370,17 +1385,19 @@ const cacheFactory = backendPluginApi.createServiceFactory({
1370
1385
  }
1371
1386
  });
1372
1387
 
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
- });
1388
+ const configServiceFactory = backendPluginApi.createServiceFactory(
1389
+ (options) => ({
1390
+ service: backendPluginApi.coreServices.config,
1391
+ deps: {},
1392
+ async factory({}) {
1393
+ const { argv = process.argv, remote } = options != null ? options : {};
1394
+ const { config } = await loadBackendConfig({ argv, remote });
1395
+ return config;
1396
+ }
1397
+ })
1398
+ );
1382
1399
 
1383
- const databaseFactory = backendPluginApi.createServiceFactory({
1400
+ const databaseServiceFactory = backendPluginApi.createServiceFactory({
1384
1401
  service: backendPluginApi.coreServices.database,
1385
1402
  deps: {
1386
1403
  config: backendPluginApi.coreServices.config,
@@ -1404,7 +1421,7 @@ const databaseFactory = backendPluginApi.createServiceFactory({
1404
1421
  }
1405
1422
  });
1406
1423
 
1407
- const discoveryFactory = backendPluginApi.createServiceFactory({
1424
+ const discoveryServiceFactory = backendPluginApi.createServiceFactory({
1408
1425
  service: backendPluginApi.coreServices.discovery,
1409
1426
  deps: {
1410
1427
  config: backendPluginApi.coreServices.config
@@ -1414,7 +1431,7 @@ const discoveryFactory = backendPluginApi.createServiceFactory({
1414
1431
  }
1415
1432
  });
1416
1433
 
1417
- const httpRouterFactory = backendPluginApi.createServiceFactory(
1434
+ const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
1418
1435
  (options) => ({
1419
1436
  service: backendPluginApi.coreServices.httpRouter,
1420
1437
  deps: {
@@ -1434,7 +1451,7 @@ const httpRouterFactory = backendPluginApi.createServiceFactory(
1434
1451
  })
1435
1452
  );
1436
1453
 
1437
- const identityFactory = backendPluginApi.createServiceFactory(
1454
+ const identityServiceFactory = backendPluginApi.createServiceFactory(
1438
1455
  (options) => ({
1439
1456
  service: backendPluginApi.coreServices.identity,
1440
1457
  deps: {
@@ -1446,7 +1463,7 @@ const identityFactory = backendPluginApi.createServiceFactory(
1446
1463
  })
1447
1464
  );
1448
1465
 
1449
- const lifecycleFactory = backendPluginApi.createServiceFactory({
1466
+ const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
1450
1467
  service: backendPluginApi.coreServices.lifecycle,
1451
1468
  deps: {
1452
1469
  logger: backendPluginApi.coreServices.logger,
@@ -1466,7 +1483,7 @@ const lifecycleFactory = backendPluginApi.createServiceFactory({
1466
1483
  }
1467
1484
  });
1468
1485
 
1469
- const loggerFactory = backendPluginApi.createServiceFactory({
1486
+ const loggerServiceFactory = backendPluginApi.createServiceFactory({
1470
1487
  service: backendPluginApi.coreServices.logger,
1471
1488
  deps: {
1472
1489
  rootLogger: backendPluginApi.coreServices.rootLogger,
@@ -1477,7 +1494,7 @@ const loggerFactory = backendPluginApi.createServiceFactory({
1477
1494
  }
1478
1495
  });
1479
1496
 
1480
- const permissionsFactory = backendPluginApi.createServiceFactory({
1497
+ const permissionsServiceFactory = backendPluginApi.createServiceFactory({
1481
1498
  service: backendPluginApi.coreServices.permissions,
1482
1499
  deps: {
1483
1500
  config: backendPluginApi.coreServices.config,
@@ -1586,11 +1603,8 @@ findConflictingPath_fn = function(newPath) {
1586
1603
  return void 0;
1587
1604
  };
1588
1605
 
1589
- function defaultConfigure({
1590
- app,
1591
- routes,
1592
- middleware
1593
- }) {
1606
+ function defaultConfigure(context) {
1607
+ const { app, routes, middleware } = context;
1594
1608
  app.use(middleware.helmet());
1595
1609
  app.use(middleware.cors());
1596
1610
  app.use(middleware.compression());
@@ -1599,41 +1613,41 @@ function defaultConfigure({
1599
1613
  app.use(middleware.notFound());
1600
1614
  app.use(middleware.error());
1601
1615
  }
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
- });
1616
+ const rootHttpRouterServiceFactory = backendPluginApi.createServiceFactory(
1617
+ (options) => ({
1618
+ service: backendPluginApi.coreServices.rootHttpRouter,
1619
+ deps: {
1620
+ config: backendPluginApi.coreServices.config,
1621
+ rootLogger: backendPluginApi.coreServices.rootLogger,
1622
+ lifecycle: backendPluginApi.coreServices.rootLifecycle
1623
+ },
1624
+ async factory({ config, rootLogger, lifecycle }) {
1625
+ const { indexPath, configure = defaultConfigure } = options != null ? options : {};
1626
+ const logger = rootLogger.child({ service: "rootHttpRouter" });
1627
+ const app = express__default["default"]();
1628
+ const router = DefaultRootHttpRouter.create({ indexPath });
1629
+ const middleware = MiddlewareFactory.create({ config, logger });
1630
+ configure({
1631
+ app,
1632
+ routes: router.handler(),
1633
+ middleware,
1634
+ config,
1635
+ logger,
1636
+ lifecycle
1637
+ });
1638
+ const server = await createHttpServer(
1639
+ app,
1640
+ readHttpServerOptions(config.getOptionalConfig("backend")),
1641
+ { logger }
1642
+ );
1643
+ lifecycle.addShutdownHook(() => server.stop());
1644
+ await server.start();
1645
+ return router;
1646
+ }
1647
+ })
1648
+ );
1635
1649
 
1636
- const rootLoggerFactory = backendPluginApi.createServiceFactory({
1650
+ const rootLoggerServiceFactory = backendPluginApi.createServiceFactory({
1637
1651
  service: backendPluginApi.coreServices.rootLogger,
1638
1652
  deps: {
1639
1653
  config: backendPluginApi.coreServices.config
@@ -1655,7 +1669,7 @@ const rootLoggerFactory = backendPluginApi.createServiceFactory({
1655
1669
  }
1656
1670
  });
1657
1671
 
1658
- const schedulerFactory = backendPluginApi.createServiceFactory({
1672
+ const schedulerServiceFactory = backendPluginApi.createServiceFactory({
1659
1673
  service: backendPluginApi.coreServices.scheduler,
1660
1674
  deps: {
1661
1675
  plugin: backendPluginApi.coreServices.pluginMetadata,
@@ -1671,7 +1685,7 @@ const schedulerFactory = backendPluginApi.createServiceFactory({
1671
1685
  }
1672
1686
  });
1673
1687
 
1674
- const tokenManagerFactory = backendPluginApi.createServiceFactory({
1688
+ const tokenManagerServiceFactory = backendPluginApi.createServiceFactory({
1675
1689
  service: backendPluginApi.coreServices.tokenManager,
1676
1690
  deps: {
1677
1691
  config: backendPluginApi.coreServices.config,
@@ -1687,7 +1701,7 @@ const tokenManagerFactory = backendPluginApi.createServiceFactory({
1687
1701
  }
1688
1702
  });
1689
1703
 
1690
- const urlReaderFactory = backendPluginApi.createServiceFactory({
1704
+ const urlReaderServiceFactory = backendPluginApi.createServiceFactory({
1691
1705
  service: backendPluginApi.coreServices.urlReader,
1692
1706
  deps: {
1693
1707
  config: backendPluginApi.coreServices.config,
@@ -1704,26 +1718,26 @@ const urlReaderFactory = backendPluginApi.createServiceFactory({
1704
1718
  exports.DefaultRootHttpRouter = DefaultRootHttpRouter;
1705
1719
  exports.MiddlewareFactory = MiddlewareFactory;
1706
1720
  exports.WinstonLogger = WinstonLogger;
1707
- exports.cacheFactory = cacheFactory;
1708
- exports.configFactory = configFactory;
1721
+ exports.cacheServiceFactory = cacheServiceFactory;
1722
+ exports.configServiceFactory = configServiceFactory;
1709
1723
  exports.createConfigSecretEnumerator = createConfigSecretEnumerator;
1710
1724
  exports.createHttpServer = createHttpServer;
1711
1725
  exports.createSpecializedBackend = createSpecializedBackend;
1712
- exports.databaseFactory = databaseFactory;
1713
- exports.discoveryFactory = discoveryFactory;
1714
- exports.httpRouterFactory = httpRouterFactory;
1715
- exports.identityFactory = identityFactory;
1716
- exports.lifecycleFactory = lifecycleFactory;
1726
+ exports.databaseServiceFactory = databaseServiceFactory;
1727
+ exports.discoveryServiceFactory = discoveryServiceFactory;
1728
+ exports.httpRouterServiceFactory = httpRouterServiceFactory;
1729
+ exports.identityServiceFactory = identityServiceFactory;
1730
+ exports.lifecycleServiceFactory = lifecycleServiceFactory;
1717
1731
  exports.loadBackendConfig = loadBackendConfig;
1718
- exports.loggerFactory = loggerFactory;
1719
- exports.permissionsFactory = permissionsFactory;
1732
+ exports.loggerServiceFactory = loggerServiceFactory;
1733
+ exports.permissionsServiceFactory = permissionsServiceFactory;
1720
1734
  exports.readCorsOptions = readCorsOptions;
1721
1735
  exports.readHelmetOptions = readHelmetOptions;
1722
1736
  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;
1737
+ exports.rootHttpRouterServiceFactory = rootHttpRouterServiceFactory;
1738
+ exports.rootLifecycleServiceFactory = rootLifecycleServiceFactory;
1739
+ exports.rootLoggerServiceFactory = rootLoggerServiceFactory;
1740
+ exports.schedulerServiceFactory = schedulerServiceFactory;
1741
+ exports.tokenManagerServiceFactory = tokenManagerServiceFactory;
1742
+ exports.urlReaderServiceFactory = urlReaderServiceFactory;
1729
1743
  //# sourceMappingURL=index.cjs.js.map