@backstage/backend-app-api 0.6.0-next.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -30,6 +30,7 @@ var cookie = require('cookie');
30
30
  var PromiseRouter = require('express-promise-router');
31
31
  var types = require('@backstage/types');
32
32
  var pathToRegexp = require('path-to-regexp');
33
+ var expressRateLimit = require('express-rate-limit');
33
34
  var pluginAuthNode = require('@backstage/plugin-auth-node');
34
35
  var pluginPermissionNode = require('@backstage/plugin-permission-node');
35
36
  var express = require('express');
@@ -70,18 +71,18 @@ var PromiseRouter__default = /*#__PURE__*/_interopDefaultLegacy(PromiseRouter);
70
71
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
71
72
  var trimEnd__default = /*#__PURE__*/_interopDefaultLegacy(trimEnd);
72
73
 
73
- var __defProp = Object.defineProperty;
74
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
75
- var __publicField = (obj, key, value) => {
76
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
74
+ var __defProp$1 = Object.defineProperty;
75
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
76
+ var __publicField$1 = (obj, key, value) => {
77
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
77
78
  return value;
78
79
  };
79
80
  class ObservableConfigProxy {
80
81
  constructor(parent, parentKey) {
81
82
  this.parent = parent;
82
83
  this.parentKey = parentKey;
83
- __publicField(this, "config", new config.ConfigReader({}));
84
- __publicField(this, "subscribers", []);
84
+ __publicField$1(this, "config", new config.ConfigReader({}));
85
+ __publicField$1(this, "subscribers", []);
85
86
  if (parent && !parentKey) {
86
87
  throw new Error("parentKey is required if parent is set");
87
88
  }
@@ -612,31 +613,31 @@ function applyInternalErrorFilter(error, logger) {
612
613
  return error;
613
614
  }
614
615
 
615
- var __accessCheck$a = (obj, member, msg) => {
616
+ var __accessCheck$b = (obj, member, msg) => {
616
617
  if (!member.has(obj))
617
618
  throw TypeError("Cannot " + msg);
618
619
  };
619
- var __privateGet$9 = (obj, member, getter) => {
620
- __accessCheck$a(obj, member, "read from private field");
620
+ var __privateGet$a = (obj, member, getter) => {
621
+ __accessCheck$b(obj, member, "read from private field");
621
622
  return getter ? getter.call(obj) : member.get(obj);
622
623
  };
623
- var __privateAdd$a = (obj, member, value) => {
624
+ var __privateAdd$b = (obj, member, value) => {
624
625
  if (member.has(obj))
625
626
  throw TypeError("Cannot add the same private member more than once");
626
627
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
627
628
  };
628
- var __privateSet$9 = (obj, member, value, setter) => {
629
- __accessCheck$a(obj, member, "write to private field");
629
+ var __privateSet$a = (obj, member, value, setter) => {
630
+ __accessCheck$b(obj, member, "write to private field");
630
631
  setter ? setter.call(obj, value) : member.set(obj, value);
631
632
  return value;
632
633
  };
633
634
  var _config, _logger;
634
635
  const _MiddlewareFactory = class _MiddlewareFactory {
635
636
  constructor(options) {
636
- __privateAdd$a(this, _config, void 0);
637
- __privateAdd$a(this, _logger, void 0);
638
- __privateSet$9(this, _config, options.config);
639
- __privateSet$9(this, _logger, options.logger);
637
+ __privateAdd$b(this, _config, void 0);
638
+ __privateAdd$b(this, _logger, void 0);
639
+ __privateSet$a(this, _config, options.config);
640
+ __privateSet$a(this, _logger, options.logger);
640
641
  }
641
642
  /**
642
643
  * Creates a new {@link MiddlewareFactory}.
@@ -682,7 +683,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
682
683
  * @returns An Express request handler
683
684
  */
684
685
  logging() {
685
- const logger = __privateGet$9(this, _logger).child({
686
+ const logger = __privateGet$a(this, _logger).child({
686
687
  type: "incomingRequest"
687
688
  });
688
689
  return morgan__default["default"]("combined", {
@@ -706,7 +707,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
706
707
  * @returns An Express request handler
707
708
  */
708
709
  helmet() {
709
- return helmet__default["default"](readHelmetOptions(__privateGet$9(this, _config).getOptionalConfig("backend")));
710
+ return helmet__default["default"](readHelmetOptions(__privateGet$a(this, _config).getOptionalConfig("backend")));
710
711
  }
711
712
  /**
712
713
  * Returns a middleware that implements the cors library.
@@ -721,7 +722,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
721
722
  * @returns An Express request handler
722
723
  */
723
724
  cors() {
724
- return cors__default["default"](readCorsOptions(__privateGet$9(this, _config).getOptionalConfig("backend")));
725
+ return cors__default["default"](readCorsOptions(__privateGet$a(this, _config).getOptionalConfig("backend")));
725
726
  }
726
727
  /**
727
728
  * Express middleware to handle errors during request processing.
@@ -746,7 +747,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
746
747
  error(options = {}) {
747
748
  var _a;
748
749
  const showStackTraces = (_a = options.showStackTraces) != null ? _a : process.env.NODE_ENV === "development";
749
- const logger = __privateGet$9(this, _logger).child({
750
+ const logger = __privateGet$a(this, _logger).child({
750
751
  type: "errorHandler"
751
752
  });
752
753
  return (rawError, req, res, next) => {
@@ -805,42 +806,46 @@ const escapeRegExp = (text) => {
805
806
  return text.replace(/[.*+?^${}(\)|[\]\\]/g, "\\$&");
806
807
  };
807
808
 
808
- var __accessCheck$9 = (obj, member, msg) => {
809
+ var __accessCheck$a = (obj, member, msg) => {
809
810
  if (!member.has(obj))
810
811
  throw TypeError("Cannot " + msg);
811
812
  };
812
- var __privateGet$8 = (obj, member, getter) => {
813
- __accessCheck$9(obj, member, "read from private field");
813
+ var __privateGet$9 = (obj, member, getter) => {
814
+ __accessCheck$a(obj, member, "read from private field");
814
815
  return getter ? getter.call(obj) : member.get(obj);
815
816
  };
816
- var __privateAdd$9 = (obj, member, value) => {
817
+ var __privateAdd$a = (obj, member, value) => {
817
818
  if (member.has(obj))
818
819
  throw TypeError("Cannot add the same private member more than once");
819
820
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
820
821
  };
821
- var __privateSet$8 = (obj, member, value, setter) => {
822
- __accessCheck$9(obj, member, "write to private field");
822
+ var __privateSet$9 = (obj, member, value, setter) => {
823
+ __accessCheck$a(obj, member, "write to private field");
823
824
  setter ? setter.call(obj, value) : member.set(obj, value);
824
825
  return value;
825
826
  };
826
827
  var _winston, _addRedactions;
827
828
  const _WinstonLogger = class _WinstonLogger {
828
829
  constructor(winston, addRedactions) {
829
- __privateAdd$9(this, _winston, void 0);
830
- __privateAdd$9(this, _addRedactions, void 0);
831
- __privateSet$8(this, _winston, winston);
832
- __privateSet$8(this, _addRedactions, addRedactions);
830
+ __privateAdd$a(this, _winston, void 0);
831
+ __privateAdd$a(this, _addRedactions, void 0);
832
+ __privateSet$9(this, _winston, winston);
833
+ __privateSet$9(this, _addRedactions, addRedactions);
833
834
  }
834
835
  /**
835
836
  * Creates a {@link WinstonLogger} instance.
836
837
  */
837
838
  static create(options) {
838
- var _a;
839
+ var _a, _b;
839
840
  const redacter = _WinstonLogger.redacter();
841
+ const defaultFormatter = process.env.NODE_ENV === "production" ? winston.format.json() : _WinstonLogger.colorFormat();
840
842
  let logger = winston.createLogger({
841
- level: options.level,
842
- format: winston.format.combine(redacter.format, options.format),
843
- transports: (_a = options.transports) != null ? _a : new winston.transports.Console()
843
+ level: process.env.LOG_LEVEL || options.level || "info",
844
+ format: winston.format.combine(
845
+ redacter.format,
846
+ (_a = options.format) != null ? _a : defaultFormatter
847
+ ),
848
+ transports: (_b = options.transports) != null ? _b : new winston.transports.Console()
844
849
  });
845
850
  if (options.meta) {
846
851
  logger = logger.child(options.meta);
@@ -910,44 +915,44 @@ const _WinstonLogger = class _WinstonLogger {
910
915
  );
911
916
  }
912
917
  error(message, meta) {
913
- __privateGet$8(this, _winston).error(message, meta);
918
+ __privateGet$9(this, _winston).error(message, meta);
914
919
  }
915
920
  warn(message, meta) {
916
- __privateGet$8(this, _winston).warn(message, meta);
921
+ __privateGet$9(this, _winston).warn(message, meta);
917
922
  }
918
923
  info(message, meta) {
919
- __privateGet$8(this, _winston).info(message, meta);
924
+ __privateGet$9(this, _winston).info(message, meta);
920
925
  }
921
926
  debug(message, meta) {
922
- __privateGet$8(this, _winston).debug(message, meta);
927
+ __privateGet$9(this, _winston).debug(message, meta);
923
928
  }
924
929
  child(meta) {
925
- return new _WinstonLogger(__privateGet$8(this, _winston).child(meta));
930
+ return new _WinstonLogger(__privateGet$9(this, _winston).child(meta));
926
931
  }
927
932
  addRedactions(redactions) {
928
933
  var _a;
929
- (_a = __privateGet$8(this, _addRedactions)) == null ? void 0 : _a.call(this, redactions);
934
+ (_a = __privateGet$9(this, _addRedactions)) == null ? void 0 : _a.call(this, redactions);
930
935
  }
931
936
  };
932
937
  _winston = new WeakMap();
933
938
  _addRedactions = new WeakMap();
934
939
  let WinstonLogger = _WinstonLogger;
935
940
 
936
- var __accessCheck$8 = (obj, member, msg) => {
941
+ var __accessCheck$9 = (obj, member, msg) => {
937
942
  if (!member.has(obj))
938
943
  throw TypeError("Cannot " + msg);
939
944
  };
940
- var __privateGet$7 = (obj, member, getter) => {
941
- __accessCheck$8(obj, member, "read from private field");
945
+ var __privateGet$8 = (obj, member, getter) => {
946
+ __accessCheck$9(obj, member, "read from private field");
942
947
  return getter ? getter.call(obj) : member.get(obj);
943
948
  };
944
- var __privateAdd$8 = (obj, member, value) => {
949
+ var __privateAdd$9 = (obj, member, value) => {
945
950
  if (member.has(obj))
946
951
  throw TypeError("Cannot add the same private member more than once");
947
952
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
948
953
  };
949
- var __privateSet$7 = (obj, member, value, setter) => {
950
- __accessCheck$8(obj, member, "write to private field");
954
+ var __privateSet$8 = (obj, member, value, setter) => {
955
+ __accessCheck$9(obj, member, "write to private field");
951
956
  setter ? setter.call(obj, value) : member.set(obj, value);
952
957
  return value;
953
958
  };
@@ -955,25 +960,25 @@ var _hasStarted$1, _startupTasks$1, _hasShutdown, _shutdownTasks;
955
960
  class BackendLifecycleImpl {
956
961
  constructor(logger) {
957
962
  this.logger = logger;
958
- __privateAdd$8(this, _hasStarted$1, false);
959
- __privateAdd$8(this, _startupTasks$1, []);
960
- __privateAdd$8(this, _hasShutdown, false);
961
- __privateAdd$8(this, _shutdownTasks, []);
963
+ __privateAdd$9(this, _hasStarted$1, false);
964
+ __privateAdd$9(this, _startupTasks$1, []);
965
+ __privateAdd$9(this, _hasShutdown, false);
966
+ __privateAdd$9(this, _shutdownTasks, []);
962
967
  }
963
968
  addStartupHook(hook, options) {
964
- if (__privateGet$7(this, _hasStarted$1)) {
969
+ if (__privateGet$8(this, _hasStarted$1)) {
965
970
  throw new Error("Attempted to add startup hook after startup");
966
971
  }
967
- __privateGet$7(this, _startupTasks$1).push({ hook, options });
972
+ __privateGet$8(this, _startupTasks$1).push({ hook, options });
968
973
  }
969
974
  async startup() {
970
- if (__privateGet$7(this, _hasStarted$1)) {
975
+ if (__privateGet$8(this, _hasStarted$1)) {
971
976
  return;
972
977
  }
973
- __privateSet$7(this, _hasStarted$1, true);
974
- this.logger.debug(`Running ${__privateGet$7(this, _startupTasks$1).length} startup tasks...`);
978
+ __privateSet$8(this, _hasStarted$1, true);
979
+ this.logger.debug(`Running ${__privateGet$8(this, _startupTasks$1).length} startup tasks...`);
975
980
  await Promise.all(
976
- __privateGet$7(this, _startupTasks$1).map(async ({ hook, options }) => {
981
+ __privateGet$8(this, _startupTasks$1).map(async ({ hook, options }) => {
977
982
  var _a;
978
983
  const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
979
984
  try {
@@ -986,21 +991,21 @@ class BackendLifecycleImpl {
986
991
  );
987
992
  }
988
993
  addShutdownHook(hook, options) {
989
- if (__privateGet$7(this, _hasShutdown)) {
994
+ if (__privateGet$8(this, _hasShutdown)) {
990
995
  throw new Error("Attempted to add shutdown hook after shutdown");
991
996
  }
992
- __privateGet$7(this, _shutdownTasks).push({ hook, options });
997
+ __privateGet$8(this, _shutdownTasks).push({ hook, options });
993
998
  }
994
999
  async shutdown() {
995
- if (__privateGet$7(this, _hasShutdown)) {
1000
+ if (__privateGet$8(this, _hasShutdown)) {
996
1001
  return;
997
1002
  }
998
- __privateSet$7(this, _hasShutdown, true);
1003
+ __privateSet$8(this, _hasShutdown, true);
999
1004
  this.logger.debug(
1000
- `Running ${__privateGet$7(this, _shutdownTasks).length} shutdown tasks...`
1005
+ `Running ${__privateGet$8(this, _shutdownTasks).length} shutdown tasks...`
1001
1006
  );
1002
1007
  await Promise.all(
1003
- __privateGet$7(this, _shutdownTasks).map(async ({ hook, options }) => {
1008
+ __privateGet$8(this, _shutdownTasks).map(async ({ hook, options }) => {
1004
1009
  var _a;
1005
1010
  const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
1006
1011
  try {
@@ -1027,21 +1032,21 @@ const rootLifecycleServiceFactory = backendPluginApi.createServiceFactory({
1027
1032
  }
1028
1033
  });
1029
1034
 
1030
- var __accessCheck$7 = (obj, member, msg) => {
1035
+ var __accessCheck$8 = (obj, member, msg) => {
1031
1036
  if (!member.has(obj))
1032
1037
  throw TypeError("Cannot " + msg);
1033
1038
  };
1034
- var __privateGet$6 = (obj, member, getter) => {
1035
- __accessCheck$7(obj, member, "read from private field");
1039
+ var __privateGet$7 = (obj, member, getter) => {
1040
+ __accessCheck$8(obj, member, "read from private field");
1036
1041
  return getter ? getter.call(obj) : member.get(obj);
1037
1042
  };
1038
- var __privateAdd$7 = (obj, member, value) => {
1043
+ var __privateAdd$8 = (obj, member, value) => {
1039
1044
  if (member.has(obj))
1040
1045
  throw TypeError("Cannot add the same private member more than once");
1041
1046
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1042
1047
  };
1043
- var __privateSet$6 = (obj, member, value, setter) => {
1044
- __accessCheck$7(obj, member, "write to private field");
1048
+ var __privateSet$7 = (obj, member, value, setter) => {
1049
+ __accessCheck$8(obj, member, "write to private field");
1045
1050
  setter ? setter.call(obj, value) : member.set(obj, value);
1046
1051
  return value;
1047
1052
  };
@@ -1051,25 +1056,25 @@ class BackendPluginLifecycleImpl {
1051
1056
  this.logger = logger;
1052
1057
  this.rootLifecycle = rootLifecycle;
1053
1058
  this.pluginMetadata = pluginMetadata;
1054
- __privateAdd$7(this, _hasStarted, false);
1055
- __privateAdd$7(this, _startupTasks, []);
1059
+ __privateAdd$8(this, _hasStarted, false);
1060
+ __privateAdd$8(this, _startupTasks, []);
1056
1061
  }
1057
1062
  addStartupHook(hook, options) {
1058
- if (__privateGet$6(this, _hasStarted)) {
1063
+ if (__privateGet$7(this, _hasStarted)) {
1059
1064
  throw new Error("Attempted to add startup hook after startup");
1060
1065
  }
1061
- __privateGet$6(this, _startupTasks).push({ hook, options });
1066
+ __privateGet$7(this, _startupTasks).push({ hook, options });
1062
1067
  }
1063
1068
  async startup() {
1064
- if (__privateGet$6(this, _hasStarted)) {
1069
+ if (__privateGet$7(this, _hasStarted)) {
1065
1070
  return;
1066
1071
  }
1067
- __privateSet$6(this, _hasStarted, true);
1072
+ __privateSet$7(this, _hasStarted, true);
1068
1073
  this.logger.debug(
1069
- `Running ${__privateGet$6(this, _startupTasks).length} plugin startup tasks...`
1074
+ `Running ${__privateGet$7(this, _startupTasks).length} plugin startup tasks...`
1070
1075
  );
1071
1076
  await Promise.all(
1072
- __privateGet$6(this, _startupTasks).map(async ({ hook, options }) => {
1077
+ __privateGet$7(this, _startupTasks).map(async ({ hook, options }) => {
1073
1078
  var _a;
1074
1079
  const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
1075
1080
  try {
@@ -1107,26 +1112,26 @@ const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
1107
1112
  }
1108
1113
  });
1109
1114
 
1110
- var __accessCheck$6 = (obj, member, msg) => {
1115
+ var __accessCheck$7 = (obj, member, msg) => {
1111
1116
  if (!member.has(obj))
1112
1117
  throw TypeError("Cannot " + msg);
1113
1118
  };
1114
- var __privateGet$5 = (obj, member, getter) => {
1115
- __accessCheck$6(obj, member, "read from private field");
1119
+ var __privateGet$6 = (obj, member, getter) => {
1120
+ __accessCheck$7(obj, member, "read from private field");
1116
1121
  return getter ? getter.call(obj) : member.get(obj);
1117
1122
  };
1118
- var __privateAdd$6 = (obj, member, value) => {
1123
+ var __privateAdd$7 = (obj, member, value) => {
1119
1124
  if (member.has(obj))
1120
1125
  throw TypeError("Cannot add the same private member more than once");
1121
1126
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1122
1127
  };
1123
- var __privateSet$5 = (obj, member, value, setter) => {
1124
- __accessCheck$6(obj, member, "write to private field");
1128
+ var __privateSet$6 = (obj, member, value, setter) => {
1129
+ __accessCheck$7(obj, member, "write to private field");
1125
1130
  setter ? setter.call(obj, value) : member.set(obj, value);
1126
1131
  return value;
1127
1132
  };
1128
- var __privateMethod$5 = (obj, member, method) => {
1129
- __accessCheck$6(obj, member, "access private method");
1133
+ var __privateMethod$6 = (obj, member, method) => {
1134
+ __accessCheck$7(obj, member, "access private method");
1130
1135
  return method;
1131
1136
  };
1132
1137
  var _nodeIds, _cycleKeys, _getCycleKey, getCycleKey_fn, _nodes, _allProvided;
@@ -1146,21 +1151,21 @@ class Node {
1146
1151
  }
1147
1152
  const _CycleKeySet = class _CycleKeySet {
1148
1153
  constructor(nodes) {
1149
- __privateAdd$6(this, _getCycleKey);
1150
- __privateAdd$6(this, _nodeIds, void 0);
1151
- __privateAdd$6(this, _cycleKeys, void 0);
1152
- __privateSet$5(this, _nodeIds, new Map(nodes.map((n, i) => [n.value, i])));
1153
- __privateSet$5(this, _cycleKeys, /* @__PURE__ */ new Set());
1154
+ __privateAdd$7(this, _getCycleKey);
1155
+ __privateAdd$7(this, _nodeIds, void 0);
1156
+ __privateAdd$7(this, _cycleKeys, void 0);
1157
+ __privateSet$6(this, _nodeIds, new Map(nodes.map((n, i) => [n.value, i])));
1158
+ __privateSet$6(this, _cycleKeys, /* @__PURE__ */ new Set());
1154
1159
  }
1155
1160
  static from(nodes) {
1156
1161
  return new _CycleKeySet(nodes);
1157
1162
  }
1158
1163
  tryAdd(path) {
1159
- const cycleKey = __privateMethod$5(this, _getCycleKey, getCycleKey_fn).call(this, path);
1160
- if (__privateGet$5(this, _cycleKeys).has(cycleKey)) {
1164
+ const cycleKey = __privateMethod$6(this, _getCycleKey, getCycleKey_fn).call(this, path);
1165
+ if (__privateGet$6(this, _cycleKeys).has(cycleKey)) {
1161
1166
  return false;
1162
1167
  }
1163
- __privateGet$5(this, _cycleKeys).add(cycleKey);
1168
+ __privateGet$6(this, _cycleKeys).add(cycleKey);
1164
1169
  return true;
1165
1170
  }
1166
1171
  };
@@ -1168,18 +1173,18 @@ _nodeIds = new WeakMap();
1168
1173
  _cycleKeys = new WeakMap();
1169
1174
  _getCycleKey = new WeakSet();
1170
1175
  getCycleKey_fn = function(path) {
1171
- return path.map((n) => __privateGet$5(this, _nodeIds).get(n)).sort().join(",");
1176
+ return path.map((n) => __privateGet$6(this, _nodeIds).get(n)).sort().join(",");
1172
1177
  };
1173
1178
  let CycleKeySet = _CycleKeySet;
1174
1179
  const _DependencyGraph = class _DependencyGraph {
1175
1180
  constructor(nodes) {
1176
- __privateAdd$6(this, _nodes, void 0);
1177
- __privateAdd$6(this, _allProvided, void 0);
1178
- __privateSet$5(this, _nodes, nodes);
1179
- __privateSet$5(this, _allProvided, /* @__PURE__ */ new Set());
1180
- for (const node of __privateGet$5(this, _nodes).values()) {
1181
+ __privateAdd$7(this, _nodes, void 0);
1182
+ __privateAdd$7(this, _allProvided, void 0);
1183
+ __privateSet$6(this, _nodes, nodes);
1184
+ __privateSet$6(this, _allProvided, /* @__PURE__ */ new Set());
1185
+ for (const node of __privateGet$6(this, _nodes).values()) {
1181
1186
  for (const produced of node.provides) {
1182
- __privateGet$5(this, _allProvided).add(produced);
1187
+ __privateGet$6(this, _allProvided).add(produced);
1183
1188
  }
1184
1189
  }
1185
1190
  }
@@ -1203,9 +1208,9 @@ const _DependencyGraph = class _DependencyGraph {
1203
1208
  */
1204
1209
  findUnsatisfiedDeps() {
1205
1210
  const unsatisfiedDependencies = [];
1206
- for (const node of __privateGet$5(this, _nodes).values()) {
1211
+ for (const node of __privateGet$6(this, _nodes).values()) {
1207
1212
  const unsatisfied = Array.from(node.consumes).filter(
1208
- (id) => !__privateGet$5(this, _allProvided).has(id)
1213
+ (id) => !__privateGet$6(this, _allProvided).has(id)
1209
1214
  );
1210
1215
  if (unsatisfied.length > 0) {
1211
1216
  unsatisfiedDependencies.push({ value: node.value, unsatisfied });
@@ -1225,8 +1230,8 @@ const _DependencyGraph = class _DependencyGraph {
1225
1230
  * form a cycle, with the same node as the first and last element of the array.
1226
1231
  */
1227
1232
  *detectCircularDependencies() {
1228
- const cycleKeys = CycleKeySet.from(__privateGet$5(this, _nodes));
1229
- for (const startNode of __privateGet$5(this, _nodes)) {
1233
+ const cycleKeys = CycleKeySet.from(__privateGet$6(this, _nodes));
1234
+ for (const startNode of __privateGet$6(this, _nodes)) {
1230
1235
  const visited = /* @__PURE__ */ new Set();
1231
1236
  const stack = new Array([
1232
1237
  startNode,
@@ -1239,7 +1244,7 @@ const _DependencyGraph = class _DependencyGraph {
1239
1244
  }
1240
1245
  visited.add(node);
1241
1246
  for (const consumed of node.consumes) {
1242
- const providerNodes = __privateGet$5(this, _nodes).filter(
1247
+ const providerNodes = __privateGet$6(this, _nodes).filter(
1243
1248
  (other) => other.provides.has(consumed)
1244
1249
  );
1245
1250
  for (const provider of providerNodes) {
@@ -1268,9 +1273,9 @@ const _DependencyGraph = class _DependencyGraph {
1268
1273
  * Dependencies of nodes that are not produced by any other nodes will be ignored.
1269
1274
  */
1270
1275
  async parallelTopologicalTraversal(fn) {
1271
- const allProvided = __privateGet$5(this, _allProvided);
1276
+ const allProvided = __privateGet$6(this, _allProvided);
1272
1277
  const producedSoFar = /* @__PURE__ */ new Set();
1273
- const waiting = new Set(__privateGet$5(this, _nodes).values());
1278
+ const waiting = new Set(__privateGet$6(this, _nodes).values());
1274
1279
  const visited = /* @__PURE__ */ new Set();
1275
1280
  const results = new Array();
1276
1281
  let inFlight = 0;
@@ -1316,26 +1321,26 @@ _nodes = new WeakMap();
1316
1321
  _allProvided = new WeakMap();
1317
1322
  let DependencyGraph = _DependencyGraph;
1318
1323
 
1319
- var __accessCheck$5 = (obj, member, msg) => {
1324
+ var __accessCheck$6 = (obj, member, msg) => {
1320
1325
  if (!member.has(obj))
1321
1326
  throw TypeError("Cannot " + msg);
1322
1327
  };
1323
- var __privateGet$4 = (obj, member, getter) => {
1324
- __accessCheck$5(obj, member, "read from private field");
1328
+ var __privateGet$5 = (obj, member, getter) => {
1329
+ __accessCheck$6(obj, member, "read from private field");
1325
1330
  return getter ? getter.call(obj) : member.get(obj);
1326
1331
  };
1327
- var __privateAdd$5 = (obj, member, value) => {
1332
+ var __privateAdd$6 = (obj, member, value) => {
1328
1333
  if (member.has(obj))
1329
1334
  throw TypeError("Cannot add the same private member more than once");
1330
1335
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1331
1336
  };
1332
- var __privateSet$4 = (obj, member, value, setter) => {
1333
- __accessCheck$5(obj, member, "write to private field");
1337
+ var __privateSet$5 = (obj, member, value, setter) => {
1338
+ __accessCheck$6(obj, member, "write to private field");
1334
1339
  setter ? setter.call(obj, value) : member.set(obj, value);
1335
1340
  return value;
1336
1341
  };
1337
- var __privateMethod$4 = (obj, member, method) => {
1338
- __accessCheck$5(obj, member, "access private method");
1342
+ var __privateMethod$5 = (obj, member, method) => {
1343
+ __accessCheck$6(obj, member, "access private method");
1339
1344
  return method;
1340
1345
  };
1341
1346
  var _providedFactories, _loadedDefaultFactories, _implementations, _rootServiceImplementations, _addedFactoryIds, _instantiatedFactories, _resolveFactory, resolveFactory_fn, _checkForMissingDeps, checkForMissingDeps_fn;
@@ -1358,19 +1363,19 @@ const pluginMetadataServiceFactory = backendPluginApi.createServiceFactory(
1358
1363
  );
1359
1364
  const _ServiceRegistry = class _ServiceRegistry {
1360
1365
  constructor(factories) {
1361
- __privateAdd$5(this, _resolveFactory);
1362
- __privateAdd$5(this, _checkForMissingDeps);
1363
- __privateAdd$5(this, _providedFactories, void 0);
1364
- __privateAdd$5(this, _loadedDefaultFactories, void 0);
1365
- __privateAdd$5(this, _implementations, void 0);
1366
- __privateAdd$5(this, _rootServiceImplementations, /* @__PURE__ */ new Map());
1367
- __privateAdd$5(this, _addedFactoryIds, /* @__PURE__ */ new Set());
1368
- __privateAdd$5(this, _instantiatedFactories, /* @__PURE__ */ new Set());
1369
- __privateSet$4(this, _providedFactories, new Map(
1366
+ __privateAdd$6(this, _resolveFactory);
1367
+ __privateAdd$6(this, _checkForMissingDeps);
1368
+ __privateAdd$6(this, _providedFactories, void 0);
1369
+ __privateAdd$6(this, _loadedDefaultFactories, void 0);
1370
+ __privateAdd$6(this, _implementations, void 0);
1371
+ __privateAdd$6(this, _rootServiceImplementations, /* @__PURE__ */ new Map());
1372
+ __privateAdd$6(this, _addedFactoryIds, /* @__PURE__ */ new Set());
1373
+ __privateAdd$6(this, _instantiatedFactories, /* @__PURE__ */ new Set());
1374
+ __privateSet$5(this, _providedFactories, new Map(
1370
1375
  factories.map((sf) => [sf.service.id, toInternalServiceFactory(sf)])
1371
1376
  ));
1372
- __privateSet$4(this, _loadedDefaultFactories, /* @__PURE__ */ new Map());
1373
- __privateSet$4(this, _implementations, /* @__PURE__ */ new Map());
1377
+ __privateSet$5(this, _loadedDefaultFactories, /* @__PURE__ */ new Map());
1378
+ __privateSet$5(this, _implementations, /* @__PURE__ */ new Map());
1374
1379
  }
1375
1380
  static create(factories) {
1376
1381
  const registry = new _ServiceRegistry(factories);
@@ -1379,7 +1384,7 @@ const _ServiceRegistry = class _ServiceRegistry {
1379
1384
  }
1380
1385
  checkForCircularDeps() {
1381
1386
  const graph = DependencyGraph.fromIterable(
1382
- Array.from(__privateGet$4(this, _providedFactories)).map(
1387
+ Array.from(__privateGet$5(this, _providedFactories)).map(
1383
1388
  ([serviceId, serviceFactory]) => ({
1384
1389
  value: serviceId,
1385
1390
  provides: [serviceId],
@@ -1401,30 +1406,30 @@ const _ServiceRegistry = class _ServiceRegistry {
1401
1406
  `The ${backendPluginApi.coreServices.pluginMetadata.id} service cannot be overridden`
1402
1407
  );
1403
1408
  }
1404
- if (__privateGet$4(this, _addedFactoryIds).has(factoryId)) {
1409
+ if (__privateGet$5(this, _addedFactoryIds).has(factoryId)) {
1405
1410
  throw new Error(
1406
1411
  `Duplicate service implementations provided for ${factoryId}`
1407
1412
  );
1408
1413
  }
1409
- if (__privateGet$4(this, _instantiatedFactories).has(factoryId)) {
1414
+ if (__privateGet$5(this, _instantiatedFactories).has(factoryId)) {
1410
1415
  throw new Error(
1411
1416
  `Unable to set service factory with id ${factoryId}, service has already been instantiated`
1412
1417
  );
1413
1418
  }
1414
- __privateGet$4(this, _addedFactoryIds).add(factoryId);
1415
- __privateGet$4(this, _providedFactories).set(factoryId, toInternalServiceFactory(factory));
1419
+ __privateGet$5(this, _addedFactoryIds).add(factoryId);
1420
+ __privateGet$5(this, _providedFactories).set(factoryId, toInternalServiceFactory(factory));
1416
1421
  }
1417
1422
  getServiceRefs() {
1418
- return Array.from(__privateGet$4(this, _providedFactories).values()).map((f) => f.service);
1423
+ return Array.from(__privateGet$5(this, _providedFactories).values()).map((f) => f.service);
1419
1424
  }
1420
1425
  get(ref, pluginId) {
1421
1426
  var _a;
1422
- __privateGet$4(this, _instantiatedFactories).add(ref.id);
1423
- return (_a = __privateMethod$4(this, _resolveFactory, resolveFactory_fn).call(this, ref, pluginId)) == null ? void 0 : _a.then((factory) => {
1427
+ __privateGet$5(this, _instantiatedFactories).add(ref.id);
1428
+ return (_a = __privateMethod$5(this, _resolveFactory, resolveFactory_fn).call(this, ref, pluginId)) == null ? void 0 : _a.then((factory) => {
1424
1429
  if (factory.service.scope === "root") {
1425
- let existing = __privateGet$4(this, _rootServiceImplementations).get(factory);
1430
+ let existing = __privateGet$5(this, _rootServiceImplementations).get(factory);
1426
1431
  if (!existing) {
1427
- __privateMethod$4(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
1432
+ __privateMethod$5(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
1428
1433
  const rootDeps = new Array();
1429
1434
  for (const [name, serviceRef] of Object.entries(factory.deps)) {
1430
1435
  if (serviceRef.scope !== "root") {
@@ -1438,13 +1443,13 @@ const _ServiceRegistry = class _ServiceRegistry {
1438
1443
  existing = Promise.all(rootDeps).then(
1439
1444
  (entries) => factory.factory(Object.fromEntries(entries), void 0)
1440
1445
  );
1441
- __privateGet$4(this, _rootServiceImplementations).set(factory, existing);
1446
+ __privateGet$5(this, _rootServiceImplementations).set(factory, existing);
1442
1447
  }
1443
1448
  return existing;
1444
1449
  }
1445
- let implementation = __privateGet$4(this, _implementations).get(factory);
1450
+ let implementation = __privateGet$5(this, _implementations).get(factory);
1446
1451
  if (!implementation) {
1447
- __privateMethod$4(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
1452
+ __privateMethod$5(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
1448
1453
  const rootDeps = new Array();
1449
1454
  for (const [name, serviceRef] of Object.entries(factory.deps)) {
1450
1455
  if (serviceRef.scope === "root") {
@@ -1466,7 +1471,7 @@ const _ServiceRegistry = class _ServiceRegistry {
1466
1471
  }),
1467
1472
  byPlugin: /* @__PURE__ */ new Map()
1468
1473
  };
1469
- __privateGet$4(this, _implementations).set(factory, implementation);
1474
+ __privateGet$5(this, _implementations).set(factory, implementation);
1470
1475
  }
1471
1476
  let result = implementation.byPlugin.get(pluginId);
1472
1477
  if (!result) {
@@ -1504,18 +1509,18 @@ resolveFactory_fn = function(ref, pluginId) {
1504
1509
  toInternalServiceFactory(pluginMetadataServiceFactory({ pluginId }))
1505
1510
  );
1506
1511
  }
1507
- let resolvedFactory = __privateGet$4(this, _providedFactories).get(ref.id);
1512
+ let resolvedFactory = __privateGet$5(this, _providedFactories).get(ref.id);
1508
1513
  const { __defaultFactory: defaultFactory } = ref;
1509
1514
  if (!resolvedFactory && !defaultFactory) {
1510
1515
  return void 0;
1511
1516
  }
1512
1517
  if (!resolvedFactory) {
1513
- let loadedFactory = __privateGet$4(this, _loadedDefaultFactories).get(defaultFactory);
1518
+ let loadedFactory = __privateGet$5(this, _loadedDefaultFactories).get(defaultFactory);
1514
1519
  if (!loadedFactory) {
1515
1520
  loadedFactory = Promise.resolve().then(() => defaultFactory(ref)).then(
1516
1521
  (f) => toInternalServiceFactory(typeof f === "function" ? f() : f)
1517
1522
  );
1518
- __privateGet$4(this, _loadedDefaultFactories).set(defaultFactory, loadedFactory);
1523
+ __privateGet$5(this, _loadedDefaultFactories).set(defaultFactory, loadedFactory);
1519
1524
  }
1520
1525
  resolvedFactory = loadedFactory.catch((error) => {
1521
1526
  throw new Error(
@@ -1533,7 +1538,7 @@ checkForMissingDeps_fn = function(factory, pluginId) {
1533
1538
  if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
1534
1539
  return false;
1535
1540
  }
1536
- if (__privateGet$4(this, _providedFactories).get(ref.id)) {
1541
+ if (__privateGet$5(this, _providedFactories).get(ref.id)) {
1537
1542
  return false;
1538
1543
  }
1539
1544
  return !ref.__defaultFactory;
@@ -1547,52 +1552,52 @@ checkForMissingDeps_fn = function(factory, pluginId) {
1547
1552
  };
1548
1553
  let ServiceRegistry = _ServiceRegistry;
1549
1554
 
1550
- var __accessCheck$4 = (obj, member, msg) => {
1555
+ var __accessCheck$5 = (obj, member, msg) => {
1551
1556
  if (!member.has(obj))
1552
1557
  throw TypeError("Cannot " + msg);
1553
1558
  };
1554
- var __privateGet$3 = (obj, member, getter) => {
1555
- __accessCheck$4(obj, member, "read from private field");
1559
+ var __privateGet$4 = (obj, member, getter) => {
1560
+ __accessCheck$5(obj, member, "read from private field");
1556
1561
  return getter ? getter.call(obj) : member.get(obj);
1557
1562
  };
1558
- var __privateAdd$4 = (obj, member, value) => {
1563
+ var __privateAdd$5 = (obj, member, value) => {
1559
1564
  if (member.has(obj))
1560
1565
  throw TypeError("Cannot add the same private member more than once");
1561
1566
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1562
1567
  };
1563
- var __privateSet$3 = (obj, member, value, setter) => {
1564
- __accessCheck$4(obj, member, "write to private field");
1568
+ var __privateSet$4 = (obj, member, value, setter) => {
1569
+ __accessCheck$5(obj, member, "write to private field");
1565
1570
  setter ? setter.call(obj, value) : member.set(obj, value);
1566
1571
  return value;
1567
1572
  };
1568
- var __privateMethod$3 = (obj, member, method) => {
1569
- __accessCheck$4(obj, member, "access private method");
1573
+ var __privateMethod$4 = (obj, member, method) => {
1574
+ __accessCheck$5(obj, member, "access private method");
1570
1575
  return method;
1571
1576
  };
1572
1577
  var _startPromise, _features, _extensionPoints, _serviceRegistry, _registeredFeatures, _getInitDeps, getInitDeps_fn, _addFeature, addFeature_fn, _doStart, doStart_fn, _getRootLifecycleImpl, getRootLifecycleImpl_fn, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn;
1573
1578
  class BackendInitializer {
1574
1579
  constructor(defaultApiFactories) {
1575
- __privateAdd$4(this, _getInitDeps);
1576
- __privateAdd$4(this, _addFeature);
1577
- __privateAdd$4(this, _doStart);
1580
+ __privateAdd$5(this, _getInitDeps);
1581
+ __privateAdd$5(this, _addFeature);
1582
+ __privateAdd$5(this, _doStart);
1578
1583
  // Bit of a hacky way to grab the lifecycle services, potentially find a nicer way to do this
1579
- __privateAdd$4(this, _getRootLifecycleImpl);
1580
- __privateAdd$4(this, _getPluginLifecycleImpl);
1581
- __privateAdd$4(this, _startPromise, void 0);
1582
- __privateAdd$4(this, _features, new Array());
1583
- __privateAdd$4(this, _extensionPoints, /* @__PURE__ */ new Map());
1584
- __privateAdd$4(this, _serviceRegistry, void 0);
1585
- __privateAdd$4(this, _registeredFeatures, new Array());
1586
- __privateSet$3(this, _serviceRegistry, ServiceRegistry.create([...defaultApiFactories]));
1584
+ __privateAdd$5(this, _getRootLifecycleImpl);
1585
+ __privateAdd$5(this, _getPluginLifecycleImpl);
1586
+ __privateAdd$5(this, _startPromise, void 0);
1587
+ __privateAdd$5(this, _features, new Array());
1588
+ __privateAdd$5(this, _extensionPoints, /* @__PURE__ */ new Map());
1589
+ __privateAdd$5(this, _serviceRegistry, void 0);
1590
+ __privateAdd$5(this, _registeredFeatures, new Array());
1591
+ __privateSet$4(this, _serviceRegistry, ServiceRegistry.create([...defaultApiFactories]));
1587
1592
  }
1588
1593
  add(feature) {
1589
- if (__privateGet$3(this, _startPromise)) {
1594
+ if (__privateGet$4(this, _startPromise)) {
1590
1595
  throw new Error("feature can not be added after the backend has started");
1591
1596
  }
1592
- __privateGet$3(this, _registeredFeatures).push(Promise.resolve(feature));
1597
+ __privateGet$4(this, _registeredFeatures).push(Promise.resolve(feature));
1593
1598
  }
1594
1599
  async start() {
1595
- if (__privateGet$3(this, _startPromise)) {
1600
+ if (__privateGet$4(this, _startPromise)) {
1596
1601
  throw new Error("Backend has already started");
1597
1602
  }
1598
1603
  const exitHandler = async () => {
@@ -1610,18 +1615,18 @@ class BackendInitializer {
1610
1615
  process.addListener("SIGTERM", exitHandler);
1611
1616
  process.addListener("SIGINT", exitHandler);
1612
1617
  process.addListener("beforeExit", exitHandler);
1613
- __privateSet$3(this, _startPromise, __privateMethod$3(this, _doStart, doStart_fn).call(this));
1614
- await __privateGet$3(this, _startPromise);
1618
+ __privateSet$4(this, _startPromise, __privateMethod$4(this, _doStart, doStart_fn).call(this));
1619
+ await __privateGet$4(this, _startPromise);
1615
1620
  }
1616
1621
  async stop() {
1617
- if (!__privateGet$3(this, _startPromise)) {
1622
+ if (!__privateGet$4(this, _startPromise)) {
1618
1623
  return;
1619
1624
  }
1620
1625
  try {
1621
- await __privateGet$3(this, _startPromise);
1626
+ await __privateGet$4(this, _startPromise);
1622
1627
  } catch (error) {
1623
1628
  }
1624
- const lifecycleService = await __privateMethod$3(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
1629
+ const lifecycleService = await __privateMethod$4(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
1625
1630
  await lifecycleService.shutdown();
1626
1631
  }
1627
1632
  }
@@ -1635,7 +1640,7 @@ getInitDeps_fn = async function(deps, pluginId, moduleId) {
1635
1640
  const result = /* @__PURE__ */ new Map();
1636
1641
  const missingRefs = /* @__PURE__ */ new Set();
1637
1642
  for (const [name, ref] of Object.entries(deps)) {
1638
- const ep = __privateGet$3(this, _extensionPoints).get(ref.id);
1643
+ const ep = __privateGet$4(this, _extensionPoints).get(ref.id);
1639
1644
  if (ep) {
1640
1645
  if (ep.pluginId !== pluginId) {
1641
1646
  throw new Error(
@@ -1644,7 +1649,7 @@ getInitDeps_fn = async function(deps, pluginId, moduleId) {
1644
1649
  }
1645
1650
  result.set(name, ep.impl);
1646
1651
  } else {
1647
- const impl = await __privateGet$3(this, _serviceRegistry).get(
1652
+ const impl = await __privateGet$4(this, _serviceRegistry).get(
1648
1653
  ref,
1649
1654
  pluginId
1650
1655
  );
@@ -1671,14 +1676,14 @@ addFeature_fn = function(feature) {
1671
1676
  );
1672
1677
  }
1673
1678
  if (isServiceFactory(feature)) {
1674
- __privateGet$3(this, _serviceRegistry).add(feature);
1679
+ __privateGet$4(this, _serviceRegistry).add(feature);
1675
1680
  } else if (isInternalBackendFeature(feature)) {
1676
1681
  if (feature.version !== "v1") {
1677
1682
  throw new Error(
1678
1683
  `Failed to add feature, invalid version '${feature.version}'`
1679
1684
  );
1680
1685
  }
1681
- __privateGet$3(this, _features).push(feature);
1686
+ __privateGet$4(this, _features).push(feature);
1682
1687
  } else {
1683
1688
  throw new Error(
1684
1689
  `Failed to add feature, invalid feature ${JSON.stringify(feature)}`
@@ -1687,39 +1692,39 @@ addFeature_fn = function(feature) {
1687
1692
  };
1688
1693
  _doStart = new WeakSet();
1689
1694
  doStart_fn = async function() {
1690
- __privateGet$3(this, _serviceRegistry).checkForCircularDeps();
1691
- for (const feature of __privateGet$3(this, _registeredFeatures)) {
1692
- __privateMethod$3(this, _addFeature, addFeature_fn).call(this, await feature);
1695
+ __privateGet$4(this, _serviceRegistry).checkForCircularDeps();
1696
+ for (const feature of __privateGet$4(this, _registeredFeatures)) {
1697
+ __privateMethod$4(this, _addFeature, addFeature_fn).call(this, await feature);
1693
1698
  }
1694
- const featureDiscovery = await __privateGet$3(this, _serviceRegistry).get(
1699
+ const featureDiscovery = await __privateGet$4(this, _serviceRegistry).get(
1695
1700
  alpha.featureDiscoveryServiceRef,
1696
1701
  "root"
1697
1702
  );
1698
1703
  if (featureDiscovery) {
1699
1704
  const { features } = await featureDiscovery.getBackendFeatures();
1700
1705
  for (const feature of features) {
1701
- __privateMethod$3(this, _addFeature, addFeature_fn).call(this, feature);
1706
+ __privateMethod$4(this, _addFeature, addFeature_fn).call(this, feature);
1702
1707
  }
1703
- __privateGet$3(this, _serviceRegistry).checkForCircularDeps();
1708
+ __privateGet$4(this, _serviceRegistry).checkForCircularDeps();
1704
1709
  }
1705
- for (const ref of __privateGet$3(this, _serviceRegistry).getServiceRefs()) {
1710
+ for (const ref of __privateGet$4(this, _serviceRegistry).getServiceRefs()) {
1706
1711
  if (ref.scope === "root") {
1707
- await __privateGet$3(this, _serviceRegistry).get(ref, "root");
1712
+ await __privateGet$4(this, _serviceRegistry).get(ref, "root");
1708
1713
  }
1709
1714
  }
1710
1715
  const pluginInits = /* @__PURE__ */ new Map();
1711
1716
  const moduleInits = /* @__PURE__ */ new Map();
1712
- for (const feature of __privateGet$3(this, _features)) {
1717
+ for (const feature of __privateGet$4(this, _features)) {
1713
1718
  for (const r of feature.getRegistrations()) {
1714
1719
  const provides = /* @__PURE__ */ new Set();
1715
1720
  if (r.type === "plugin" || r.type === "module") {
1716
1721
  for (const [extRef, extImpl] of r.extensionPoints) {
1717
- if (__privateGet$3(this, _extensionPoints).has(extRef.id)) {
1722
+ if (__privateGet$4(this, _extensionPoints).has(extRef.id)) {
1718
1723
  throw new Error(
1719
1724
  `ExtensionPoint with ID '${extRef.id}' is already registered`
1720
1725
  );
1721
1726
  }
1722
- __privateGet$3(this, _extensionPoints).set(extRef.id, {
1727
+ __privateGet$4(this, _extensionPoints).set(extRef.id, {
1723
1728
  impl: extImpl,
1724
1729
  pluginId: r.pluginId
1725
1730
  });
@@ -1779,7 +1784,7 @@ doStart_fn = async function() {
1779
1784
  }
1780
1785
  await tree.parallelTopologicalTraversal(
1781
1786
  async ({ moduleId, moduleInit }) => {
1782
- const moduleDeps = await __privateMethod$3(this, _getInitDeps, getInitDeps_fn).call(this, moduleInit.init.deps, pluginId, moduleId);
1787
+ const moduleDeps = await __privateMethod$4(this, _getInitDeps, getInitDeps_fn).call(this, moduleInit.init.deps, pluginId, moduleId);
1783
1788
  await moduleInit.init.func(moduleDeps).catch((error) => {
1784
1789
  throw new errors.ForwardedError(
1785
1790
  `Module '${moduleId}' for plugin '${pluginId}' startup failed`,
@@ -1791,7 +1796,7 @@ doStart_fn = async function() {
1791
1796
  }
1792
1797
  const pluginInit = pluginInits.get(pluginId);
1793
1798
  if (pluginInit) {
1794
- const pluginDeps = await __privateMethod$3(this, _getInitDeps, getInitDeps_fn).call(this, pluginInit.init.deps, pluginId);
1799
+ const pluginDeps = await __privateMethod$4(this, _getInitDeps, getInitDeps_fn).call(this, pluginInit.init.deps, pluginId);
1795
1800
  await pluginInit.init.func(pluginDeps).catch((error) => {
1796
1801
  throw new errors.ForwardedError(
1797
1802
  `Plugin '${pluginId}' startup failed`,
@@ -1799,14 +1804,14 @@ doStart_fn = async function() {
1799
1804
  );
1800
1805
  });
1801
1806
  }
1802
- const lifecycleService2 = await __privateMethod$3(this, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn).call(this, pluginId);
1807
+ const lifecycleService2 = await __privateMethod$4(this, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn).call(this, pluginId);
1803
1808
  await lifecycleService2.startup();
1804
1809
  })
1805
1810
  );
1806
- const lifecycleService = await __privateMethod$3(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
1811
+ const lifecycleService = await __privateMethod$4(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
1807
1812
  await lifecycleService.startup();
1808
1813
  if (process.env.NODE_ENV !== "test") {
1809
- const rootLogger = await __privateGet$3(this, _serviceRegistry).get(
1814
+ const rootLogger = await __privateGet$4(this, _serviceRegistry).get(
1810
1815
  backendPluginApi.coreServices.rootLogger,
1811
1816
  "root"
1812
1817
  );
@@ -1822,7 +1827,7 @@ doStart_fn = async function() {
1822
1827
  };
1823
1828
  _getRootLifecycleImpl = new WeakSet();
1824
1829
  getRootLifecycleImpl_fn = async function() {
1825
- const lifecycleService = await __privateGet$3(this, _serviceRegistry).get(
1830
+ const lifecycleService = await __privateGet$4(this, _serviceRegistry).get(
1826
1831
  backendPluginApi.coreServices.rootLifecycle,
1827
1832
  "root"
1828
1833
  );
@@ -1833,7 +1838,7 @@ getRootLifecycleImpl_fn = async function() {
1833
1838
  };
1834
1839
  _getPluginLifecycleImpl = new WeakSet();
1835
1840
  getPluginLifecycleImpl_fn = async function(pluginId) {
1836
- const lifecycleService = await __privateGet$3(this, _serviceRegistry).get(
1841
+ const lifecycleService = await __privateGet$4(this, _serviceRegistry).get(
1837
1842
  backendPluginApi.coreServices.lifecycle,
1838
1843
  pluginId
1839
1844
  );
@@ -1849,42 +1854,42 @@ function isInternalBackendFeature(feature) {
1849
1854
  return typeof feature.getRegistrations === "function";
1850
1855
  }
1851
1856
 
1852
- var __accessCheck$3 = (obj, member, msg) => {
1857
+ var __accessCheck$4 = (obj, member, msg) => {
1853
1858
  if (!member.has(obj))
1854
1859
  throw TypeError("Cannot " + msg);
1855
1860
  };
1856
- var __privateGet$2 = (obj, member, getter) => {
1857
- __accessCheck$3(obj, member, "read from private field");
1861
+ var __privateGet$3 = (obj, member, getter) => {
1862
+ __accessCheck$4(obj, member, "read from private field");
1858
1863
  return getter ? getter.call(obj) : member.get(obj);
1859
1864
  };
1860
- var __privateAdd$3 = (obj, member, value) => {
1865
+ var __privateAdd$4 = (obj, member, value) => {
1861
1866
  if (member.has(obj))
1862
1867
  throw TypeError("Cannot add the same private member more than once");
1863
1868
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1864
1869
  };
1865
- var __privateSet$2 = (obj, member, value, setter) => {
1866
- __accessCheck$3(obj, member, "write to private field");
1870
+ var __privateSet$3 = (obj, member, value, setter) => {
1871
+ __accessCheck$4(obj, member, "write to private field");
1867
1872
  setter ? setter.call(obj, value) : member.set(obj, value);
1868
1873
  return value;
1869
1874
  };
1870
1875
  var _initializer;
1871
1876
  class BackstageBackend {
1872
1877
  constructor(defaultServiceFactories) {
1873
- __privateAdd$3(this, _initializer, void 0);
1874
- __privateSet$2(this, _initializer, new BackendInitializer(defaultServiceFactories));
1878
+ __privateAdd$4(this, _initializer, void 0);
1879
+ __privateSet$3(this, _initializer, new BackendInitializer(defaultServiceFactories));
1875
1880
  }
1876
1881
  add(feature) {
1877
1882
  if (isPromise(feature)) {
1878
- __privateGet$2(this, _initializer).add(feature.then((f) => unwrapFeature(f.default)));
1883
+ __privateGet$3(this, _initializer).add(feature.then((f) => unwrapFeature(f.default)));
1879
1884
  } else {
1880
- __privateGet$2(this, _initializer).add(unwrapFeature(feature));
1885
+ __privateGet$3(this, _initializer).add(unwrapFeature(feature));
1881
1886
  }
1882
1887
  }
1883
1888
  async start() {
1884
- await __privateGet$2(this, _initializer).start();
1889
+ await __privateGet$3(this, _initializer).start();
1885
1890
  }
1886
1891
  async stop() {
1887
- await __privateGet$2(this, _initializer).stop();
1892
+ await __privateGet$3(this, _initializer).stop();
1888
1893
  }
1889
1894
  }
1890
1895
  _initializer = new WeakMap();
@@ -1930,17 +1935,17 @@ function createSpecializedBackend(options) {
1930
1935
  return new BackstageBackend(services);
1931
1936
  }
1932
1937
 
1933
- var __accessCheck$2 = (obj, member, msg) => {
1938
+ var __accessCheck$3 = (obj, member, msg) => {
1934
1939
  if (!member.has(obj))
1935
1940
  throw TypeError("Cannot " + msg);
1936
1941
  };
1937
- var __privateAdd$2 = (obj, member, value) => {
1942
+ var __privateAdd$3 = (obj, member, value) => {
1938
1943
  if (member.has(obj))
1939
1944
  throw TypeError("Cannot add the same private member more than once");
1940
1945
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1941
1946
  };
1942
- var __privateMethod$2 = (obj, member, method) => {
1943
- __accessCheck$2(obj, member, "access private method");
1947
+ var __privateMethod$3 = (obj, member, method) => {
1948
+ __accessCheck$3(obj, member, "access private method");
1944
1949
  return method;
1945
1950
  };
1946
1951
  var _getJwtExpiration, getJwtExpiration_fn;
@@ -1994,7 +1999,7 @@ class DefaultAuthService {
1994
1999
  this.identity = identity;
1995
2000
  this.pluginId = pluginId;
1996
2001
  this.disableDefaultAuthPolicy = disableDefaultAuthPolicy;
1997
- __privateAdd$2(this, _getJwtExpiration);
2002
+ __privateAdd$3(this, _getJwtExpiration);
1998
2003
  }
1999
2004
  // allowLimitedAccess is currently ignored, since we currently always use the full user tokens
2000
2005
  async authenticate(token) {
@@ -2014,7 +2019,7 @@ class DefaultAuthService {
2014
2019
  return createCredentialsWithUserPrincipal(
2015
2020
  identity.identity.userEntityRef,
2016
2021
  token,
2017
- __privateMethod$2(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token)
2022
+ __privateMethod$3(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token)
2018
2023
  );
2019
2024
  }
2020
2025
  isPrincipal(credentials, type) {
@@ -2061,7 +2066,7 @@ class DefaultAuthService {
2061
2066
  "User credentials is unexpectedly missing token"
2062
2067
  );
2063
2068
  }
2064
- return { token, expiresAt: __privateMethod$2(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token) };
2069
+ return { token, expiresAt: __privateMethod$3(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token) };
2065
2070
  }
2066
2071
  }
2067
2072
  _getJwtExpiration = new WeakSet();
@@ -2121,7 +2126,8 @@ const rootConfigServiceFactory = backendPluginApi.createServiceFactory(
2121
2126
  async factory() {
2122
2127
  const source = configLoader.ConfigSources.default({
2123
2128
  argv: options == null ? void 0 : options.argv,
2124
- remote: options == null ? void 0 : options.remote
2129
+ remote: options == null ? void 0 : options.remote,
2130
+ watch: options == null ? void 0 : options.watch
2125
2131
  });
2126
2132
  console.log(`Loading config from ${source}`);
2127
2133
  return await configLoader.ConfigSources.toConfig(source);
@@ -2244,26 +2250,26 @@ const discoveryServiceFactory = backendPluginApi.createServiceFactory({
2244
2250
  }
2245
2251
  });
2246
2252
 
2247
- var __accessCheck$1 = (obj, member, msg) => {
2253
+ var __accessCheck$2 = (obj, member, msg) => {
2248
2254
  if (!member.has(obj))
2249
2255
  throw TypeError("Cannot " + msg);
2250
2256
  };
2251
- var __privateGet$1 = (obj, member, getter) => {
2252
- __accessCheck$1(obj, member, "read from private field");
2257
+ var __privateGet$2 = (obj, member, getter) => {
2258
+ __accessCheck$2(obj, member, "read from private field");
2253
2259
  return getter ? getter.call(obj) : member.get(obj);
2254
2260
  };
2255
- var __privateAdd$1 = (obj, member, value) => {
2261
+ var __privateAdd$2 = (obj, member, value) => {
2256
2262
  if (member.has(obj))
2257
2263
  throw TypeError("Cannot add the same private member more than once");
2258
2264
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2259
2265
  };
2260
- var __privateSet$1 = (obj, member, value, setter) => {
2261
- __accessCheck$1(obj, member, "write to private field");
2266
+ var __privateSet$2 = (obj, member, value, setter) => {
2267
+ __accessCheck$2(obj, member, "write to private field");
2262
2268
  setter ? setter.call(obj, value) : member.set(obj, value);
2263
2269
  return value;
2264
2270
  };
2265
- var __privateMethod$1 = (obj, member, method) => {
2266
- __accessCheck$1(obj, member, "access private method");
2271
+ var __privateMethod$2 = (obj, member, method) => {
2272
+ __accessCheck$2(obj, member, "access private method");
2267
2273
  return method;
2268
2274
  };
2269
2275
  var _auth, _discovery, _pluginId, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn, _getCredentials, getCredentials_fn, _getLimitedCredentials, getLimitedCredentials_fn, _existingCookieExpiration, existingCookieExpiration_fn;
@@ -2298,37 +2304,37 @@ const credentialsSymbol = Symbol("backstage-credentials");
2298
2304
  const limitedCredentialsSymbol = Symbol("backstage-limited-credentials");
2299
2305
  class DefaultHttpAuthService {
2300
2306
  constructor(auth, discovery, pluginId) {
2301
- __privateAdd$1(this, _extractCredentialsFromRequest);
2302
- __privateAdd$1(this, _extractLimitedCredentialsFromRequest);
2303
- __privateAdd$1(this, _getCredentials);
2304
- __privateAdd$1(this, _getLimitedCredentials);
2305
- __privateAdd$1(this, _existingCookieExpiration);
2306
- __privateAdd$1(this, _auth, void 0);
2307
- __privateAdd$1(this, _discovery, void 0);
2308
- __privateAdd$1(this, _pluginId, void 0);
2309
- __privateSet$1(this, _auth, auth);
2310
- __privateSet$1(this, _discovery, discovery);
2311
- __privateSet$1(this, _pluginId, pluginId);
2307
+ __privateAdd$2(this, _extractCredentialsFromRequest);
2308
+ __privateAdd$2(this, _extractLimitedCredentialsFromRequest);
2309
+ __privateAdd$2(this, _getCredentials);
2310
+ __privateAdd$2(this, _getLimitedCredentials);
2311
+ __privateAdd$2(this, _existingCookieExpiration);
2312
+ __privateAdd$2(this, _auth, void 0);
2313
+ __privateAdd$2(this, _discovery, void 0);
2314
+ __privateAdd$2(this, _pluginId, void 0);
2315
+ __privateSet$2(this, _auth, auth);
2316
+ __privateSet$2(this, _discovery, discovery);
2317
+ __privateSet$2(this, _pluginId, pluginId);
2312
2318
  }
2313
2319
  async credentials(req, options) {
2314
- const credentials = (options == null ? void 0 : options.allowLimitedAccess) ? await __privateMethod$1(this, _getLimitedCredentials, getLimitedCredentials_fn).call(this, req) : await __privateMethod$1(this, _getCredentials, getCredentials_fn).call(this, req);
2320
+ const credentials = (options == null ? void 0 : options.allowLimitedAccess) ? await __privateMethod$2(this, _getLimitedCredentials, getLimitedCredentials_fn).call(this, req) : await __privateMethod$2(this, _getCredentials, getCredentials_fn).call(this, req);
2315
2321
  const allowed = options == null ? void 0 : options.allow;
2316
2322
  if (!allowed) {
2317
2323
  return credentials;
2318
2324
  }
2319
- if (__privateGet$1(this, _auth).isPrincipal(credentials, "none")) {
2325
+ if (__privateGet$2(this, _auth).isPrincipal(credentials, "none")) {
2320
2326
  if (allowed.includes("none")) {
2321
2327
  return credentials;
2322
2328
  }
2323
2329
  throw new errors.AuthenticationError("Missing credentials");
2324
- } else if (__privateGet$1(this, _auth).isPrincipal(credentials, "user")) {
2330
+ } else if (__privateGet$2(this, _auth).isPrincipal(credentials, "user")) {
2325
2331
  if (allowed.includes("user")) {
2326
2332
  return credentials;
2327
2333
  }
2328
2334
  throw new errors.NotAllowedError(
2329
2335
  `This endpoint does not allow 'user' credentials`
2330
2336
  );
2331
- } else if (__privateGet$1(this, _auth).isPrincipal(credentials, "service")) {
2337
+ } else if (__privateGet$2(this, _auth).isPrincipal(credentials, "service")) {
2332
2338
  if (allowed.includes("service")) {
2333
2339
  return credentials;
2334
2340
  }
@@ -2346,7 +2352,7 @@ class DefaultHttpAuthService {
2346
2352
  }
2347
2353
  let credentials;
2348
2354
  if (options == null ? void 0 : options.credentials) {
2349
- if (!__privateGet$1(this, _auth).isPrincipal(options.credentials, "user")) {
2355
+ if (!__privateGet$2(this, _auth).isPrincipal(options.credentials, "user")) {
2350
2356
  throw new errors.AuthenticationError(
2351
2357
  "Refused to issue cookie for non-user principal"
2352
2358
  );
@@ -2355,17 +2361,17 @@ class DefaultHttpAuthService {
2355
2361
  } else {
2356
2362
  credentials = await this.credentials(res.req, { allow: ["user"] });
2357
2363
  }
2358
- const existingExpiresAt = await __privateMethod$1(this, _existingCookieExpiration, existingCookieExpiration_fn).call(this, res.req);
2364
+ const existingExpiresAt = await __privateMethod$2(this, _existingCookieExpiration, existingCookieExpiration_fn).call(this, res.req);
2359
2365
  if (existingExpiresAt && !willExpireSoon(existingExpiresAt)) {
2360
2366
  return { expiresAt: existingExpiresAt };
2361
2367
  }
2362
2368
  const originHeader = res.req.headers.origin;
2363
2369
  const origin = !originHeader || originHeader === "null" ? void 0 : originHeader;
2364
- const externalBaseUrlStr = await __privateGet$1(this, _discovery).getExternalBaseUrl(
2365
- __privateGet$1(this, _pluginId)
2370
+ const externalBaseUrlStr = await __privateGet$2(this, _discovery).getExternalBaseUrl(
2371
+ __privateGet$2(this, _pluginId)
2366
2372
  );
2367
2373
  const externalBaseUrl = new URL(origin != null ? origin : externalBaseUrlStr);
2368
- const { token, expiresAt } = await __privateGet$1(this, _auth).getLimitedUserToken(
2374
+ const { token, expiresAt } = await __privateGet$2(this, _auth).getLimitedUserToken(
2369
2375
  credentials
2370
2376
  );
2371
2377
  if (!token) {
@@ -2390,35 +2396,35 @@ _extractCredentialsFromRequest = new WeakSet();
2390
2396
  extractCredentialsFromRequest_fn = async function(req) {
2391
2397
  const token = getTokenFromRequest(req);
2392
2398
  if (!token) {
2393
- return await __privateGet$1(this, _auth).getNoneCredentials();
2399
+ return await __privateGet$2(this, _auth).getNoneCredentials();
2394
2400
  }
2395
- return await __privateGet$1(this, _auth).authenticate(token);
2401
+ return await __privateGet$2(this, _auth).authenticate(token);
2396
2402
  };
2397
2403
  _extractLimitedCredentialsFromRequest = new WeakSet();
2398
2404
  extractLimitedCredentialsFromRequest_fn = async function(req) {
2399
2405
  const token = getTokenFromRequest(req);
2400
2406
  if (token) {
2401
- return await __privateGet$1(this, _auth).authenticate(token, {
2407
+ return await __privateGet$2(this, _auth).authenticate(token, {
2402
2408
  allowLimitedAccess: true
2403
2409
  });
2404
2410
  }
2405
2411
  const cookie = getCookieFromRequest(req);
2406
2412
  if (cookie) {
2407
- return await __privateGet$1(this, _auth).authenticate(cookie, {
2413
+ return await __privateGet$2(this, _auth).authenticate(cookie, {
2408
2414
  allowLimitedAccess: true
2409
2415
  });
2410
2416
  }
2411
- return await __privateGet$1(this, _auth).getNoneCredentials();
2417
+ return await __privateGet$2(this, _auth).getNoneCredentials();
2412
2418
  };
2413
2419
  _getCredentials = new WeakSet();
2414
2420
  getCredentials_fn = async function(req) {
2415
2421
  var _a;
2416
- return (_a = req[credentialsSymbol]) != null ? _a : req[credentialsSymbol] = __privateMethod$1(this, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn).call(this, req);
2422
+ return (_a = req[credentialsSymbol]) != null ? _a : req[credentialsSymbol] = __privateMethod$2(this, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn).call(this, req);
2417
2423
  };
2418
2424
  _getLimitedCredentials = new WeakSet();
2419
2425
  getLimitedCredentials_fn = async function(req) {
2420
2426
  var _a;
2421
- return (_a = req[limitedCredentialsSymbol]) != null ? _a : req[limitedCredentialsSymbol] = __privateMethod$1(this, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn).call(this, req);
2427
+ return (_a = req[limitedCredentialsSymbol]) != null ? _a : req[limitedCredentialsSymbol] = __privateMethod$2(this, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn).call(this, req);
2422
2428
  };
2423
2429
  _existingCookieExpiration = new WeakSet();
2424
2430
  existingCookieExpiration_fn = async function(req) {
@@ -2426,10 +2432,10 @@ existingCookieExpiration_fn = async function(req) {
2426
2432
  if (!existingCookie) {
2427
2433
  return void 0;
2428
2434
  }
2429
- const existingCredentials = await __privateGet$1(this, _auth).authenticate(existingCookie, {
2435
+ const existingCredentials = await __privateGet$2(this, _auth).authenticate(existingCookie, {
2430
2436
  allowLimitedAccess: true
2431
2437
  });
2432
- if (!__privateGet$1(this, _auth).isPrincipal(existingCredentials, "user")) {
2438
+ if (!__privateGet$2(this, _auth).isPrincipal(existingCredentials, "user")) {
2433
2439
  return void 0;
2434
2440
  }
2435
2441
  return existingCredentials.expiresAt;
@@ -2490,6 +2496,105 @@ function createLifecycleMiddleware(options) {
2490
2496
  };
2491
2497
  }
2492
2498
 
2499
+ var __defProp = Object.defineProperty;
2500
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2501
+ var __publicField = (obj, key, value) => {
2502
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2503
+ return value;
2504
+ };
2505
+ var __accessCheck$1 = (obj, member, msg) => {
2506
+ if (!member.has(obj))
2507
+ throw TypeError("Cannot " + msg);
2508
+ };
2509
+ var __privateGet$1 = (obj, member, getter) => {
2510
+ __accessCheck$1(obj, member, "read from private field");
2511
+ return getter ? getter.call(obj) : member.get(obj);
2512
+ };
2513
+ var __privateAdd$1 = (obj, member, value) => {
2514
+ if (member.has(obj))
2515
+ throw TypeError("Cannot add the same private member more than once");
2516
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2517
+ };
2518
+ var __privateSet$1 = (obj, member, value, setter) => {
2519
+ __accessCheck$1(obj, member, "write to private field");
2520
+ setter ? setter.call(obj, value) : member.set(obj, value);
2521
+ return value;
2522
+ };
2523
+ var __privateMethod$1 = (obj, member, method) => {
2524
+ __accessCheck$1(obj, member, "access private method");
2525
+ return method;
2526
+ };
2527
+ var _cache, _getDefaultValue, getDefaultValue_fn;
2528
+ const _RateLimitStore = class _RateLimitStore {
2529
+ constructor(options) {
2530
+ __privateAdd$1(this, _getDefaultValue);
2531
+ /**
2532
+ * The duration of time before which all hit counts are reset (in milliseconds).
2533
+ * default: 60 requests per minute
2534
+ */
2535
+ __publicField(this, "windowMs", 1 * 60 * 1e3);
2536
+ __publicField(this, "prefix");
2537
+ __privateAdd$1(this, _cache, void 0);
2538
+ var _a;
2539
+ this.prefix = (_a = options.prefix) != null ? _a : "unauthorized_rate_limit_";
2540
+ __privateSet$1(this, _cache, options.cache);
2541
+ }
2542
+ static fromOptions(options) {
2543
+ return new _RateLimitStore(options);
2544
+ }
2545
+ init(options) {
2546
+ if (options.windowMs) {
2547
+ this.windowMs = options.windowMs;
2548
+ }
2549
+ }
2550
+ prefixKey(key) {
2551
+ return `${this.prefix}${key}`;
2552
+ }
2553
+ async get(key) {
2554
+ var _a;
2555
+ const value = (_a = await __privateGet$1(this, _cache).get(this.prefixKey(key))) != null ? _a : __privateMethod$1(this, _getDefaultValue, getDefaultValue_fn).call(this);
2556
+ return {
2557
+ totalHits: value.totalHits,
2558
+ resetTime: new Date(value.resetTime)
2559
+ };
2560
+ }
2561
+ async increment(key) {
2562
+ var _a;
2563
+ const value = (_a = await __privateGet$1(this, _cache).get(this.prefixKey(key))) != null ? _a : __privateMethod$1(this, _getDefaultValue, getDefaultValue_fn).call(this);
2564
+ const totalHits = value.totalHits + 1;
2565
+ const resetTime = value.resetTime;
2566
+ await __privateGet$1(this, _cache).set(
2567
+ this.prefixKey(key),
2568
+ { totalHits, resetTime },
2569
+ { ttl: this.windowMs }
2570
+ );
2571
+ return {
2572
+ totalHits,
2573
+ resetTime: new Date(resetTime)
2574
+ };
2575
+ }
2576
+ async decrement(key) {
2577
+ var _a;
2578
+ const value = (_a = await __privateGet$1(this, _cache).get(this.prefixKey(key))) != null ? _a : __privateMethod$1(this, _getDefaultValue, getDefaultValue_fn).call(this);
2579
+ const totalHits = value.totalHits > 0 ? value.totalHits - 1 : 0;
2580
+ const resetTime = value.resetTime;
2581
+ await __privateGet$1(this, _cache).set(
2582
+ this.prefixKey(key),
2583
+ { totalHits, resetTime },
2584
+ { ttl: this.windowMs }
2585
+ );
2586
+ }
2587
+ async resetKey(key) {
2588
+ await __privateGet$1(this, _cache).delete(this.prefixKey(key));
2589
+ }
2590
+ };
2591
+ _cache = new WeakMap();
2592
+ _getDefaultValue = new WeakSet();
2593
+ getDefaultValue_fn = function() {
2594
+ return { totalHits: 0, resetTime: Date.now() + this.windowMs };
2595
+ };
2596
+ let RateLimitStore = _RateLimitStore;
2597
+
2493
2598
  function createPathPolicyPredicate(policyPath) {
2494
2599
  if (policyPath === "/" || policyPath === "*") {
2495
2600
  return () => true;
@@ -2502,8 +2607,8 @@ function createPathPolicyPredicate(policyPath) {
2502
2607
  };
2503
2608
  }
2504
2609
  function createCredentialsBarrier(options) {
2505
- const { httpAuth, config } = options;
2506
- const disableDefaultAuthPolicy = config.getOptionalBoolean(
2610
+ const { httpAuth, config: config$1, cache } = options;
2611
+ const disableDefaultAuthPolicy = config$1.getOptionalBoolean(
2507
2612
  "backend.auth.dangerouslyDisableDefaultAuthPolicy"
2508
2613
  );
2509
2614
  if (disableDefaultAuthPolicy) {
@@ -2515,12 +2620,31 @@ function createCredentialsBarrier(options) {
2515
2620
  }
2516
2621
  const unauthenticatedPredicates = new Array();
2517
2622
  const cookiePredicates = new Array();
2518
- const middleware = (req, _, next) => {
2623
+ const rateLimitConfig = config$1.getOptional("backend.rateLimit.unauthorized");
2624
+ const disabled = rateLimitConfig === false || typeof rateLimitConfig === "object" && (config$1 == null ? void 0 : config$1.getOptionalBoolean("backend.rateLimit.unauthorized.disabled")) === true;
2625
+ const duration = typeof rateLimitConfig === "object" && (config$1 == null ? void 0 : config$1.has("backend.rateLimit.unauthorized.window")) ? config.readDurationFromConfig(
2626
+ config$1.getConfig("backend.rateLimit.unauthorized.window")
2627
+ ) : void 0;
2628
+ const windowMs = duration ? types.durationToMilliseconds(duration) : 1 * 60 * 1e3;
2629
+ const max = typeof rateLimitConfig === "object" && (config$1 == null ? void 0 : config$1.has("backend.rateLimit.unauthorized.max")) ? config$1.getNumber("backend.rateLimit.unauthorized.max") : 60;
2630
+ const limiter = expressRateLimit.rateLimit({
2631
+ windowMs,
2632
+ limit: max,
2633
+ standardHeaders: true,
2634
+ // Return rate limit info in the `RateLimit-*` headers
2635
+ legacyHeaders: false,
2636
+ // Disable the `X-RateLimit-*` headers,
2637
+ store: RateLimitStore.fromOptions({ cache }),
2638
+ skip() {
2639
+ return disabled;
2640
+ }
2641
+ });
2642
+ const middleware = (req, res, next) => {
2519
2643
  const allowsUnauthenticated = unauthenticatedPredicates.some(
2520
2644
  (predicate) => predicate(req.path)
2521
2645
  );
2522
2646
  if (allowsUnauthenticated) {
2523
- next();
2647
+ limiter(req, res, next);
2524
2648
  return;
2525
2649
  }
2526
2650
  const allowsCookie = cookiePredicates.some(
@@ -2550,19 +2674,31 @@ const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
2550
2674
  (options) => ({
2551
2675
  service: backendPluginApi.coreServices.httpRouter,
2552
2676
  deps: {
2677
+ cache: backendPluginApi.coreServices.cache,
2553
2678
  plugin: backendPluginApi.coreServices.pluginMetadata,
2554
2679
  config: backendPluginApi.coreServices.rootConfig,
2555
2680
  lifecycle: backendPluginApi.coreServices.lifecycle,
2556
2681
  rootHttpRouter: backendPluginApi.coreServices.rootHttpRouter,
2557
2682
  httpAuth: backendPluginApi.coreServices.httpAuth
2558
2683
  },
2559
- async factory({ httpAuth, config, plugin, rootHttpRouter, lifecycle }) {
2684
+ async factory({
2685
+ httpAuth,
2686
+ config,
2687
+ cache,
2688
+ plugin,
2689
+ rootHttpRouter,
2690
+ lifecycle
2691
+ }) {
2560
2692
  var _a;
2561
2693
  const getPath = (_a = options == null ? void 0 : options.getPath) != null ? _a : (id) => `/api/${id}`;
2562
2694
  const path = getPath(plugin.getId());
2563
2695
  const router = PromiseRouter__default["default"]();
2564
2696
  rootHttpRouter.use(path, router);
2565
- const credentialsBarrier = createCredentialsBarrier({ httpAuth, config });
2697
+ const credentialsBarrier = createCredentialsBarrier({
2698
+ httpAuth,
2699
+ config,
2700
+ cache
2701
+ });
2566
2702
  router.use(createLifecycleMiddleware({ lifecycle }));
2567
2703
  router.use(credentialsBarrier.middleware);
2568
2704
  return {