@backstage/backend-app-api 0.6.0-next.2 → 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/CHANGELOG.md +32 -0
- package/alpha/package.json +1 -1
- package/config.d.ts +19 -0
- package/dist/alpha.cjs.js +7 -1
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/index.cjs.js +381 -250
- package/dist/index.cjs.js.map +1 -1
- package/package.json +13 -12
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$
|
|
616
|
+
var __accessCheck$b = (obj, member, msg) => {
|
|
616
617
|
if (!member.has(obj))
|
|
617
618
|
throw TypeError("Cannot " + msg);
|
|
618
619
|
};
|
|
619
|
-
var __privateGet$
|
|
620
|
-
__accessCheck$
|
|
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$
|
|
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$
|
|
629
|
-
__accessCheck$
|
|
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$
|
|
637
|
-
__privateAdd$
|
|
638
|
-
__privateSet$
|
|
639
|
-
__privateSet$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
750
|
+
const logger = __privateGet$a(this, _logger).child({
|
|
750
751
|
type: "errorHandler"
|
|
751
752
|
});
|
|
752
753
|
return (rawError, req, res, next) => {
|
|
@@ -805,31 +806,31 @@ const escapeRegExp = (text) => {
|
|
|
805
806
|
return text.replace(/[.*+?^${}(\)|[\]\\]/g, "\\$&");
|
|
806
807
|
};
|
|
807
808
|
|
|
808
|
-
var __accessCheck$
|
|
809
|
+
var __accessCheck$a = (obj, member, msg) => {
|
|
809
810
|
if (!member.has(obj))
|
|
810
811
|
throw TypeError("Cannot " + msg);
|
|
811
812
|
};
|
|
812
|
-
var __privateGet$
|
|
813
|
-
__accessCheck$
|
|
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$
|
|
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$
|
|
822
|
-
__accessCheck$
|
|
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$
|
|
830
|
-
__privateAdd$
|
|
831
|
-
__privateSet$
|
|
832
|
-
__privateSet$
|
|
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.
|
|
@@ -914,44 +915,44 @@ const _WinstonLogger = class _WinstonLogger {
|
|
|
914
915
|
);
|
|
915
916
|
}
|
|
916
917
|
error(message, meta) {
|
|
917
|
-
__privateGet$
|
|
918
|
+
__privateGet$9(this, _winston).error(message, meta);
|
|
918
919
|
}
|
|
919
920
|
warn(message, meta) {
|
|
920
|
-
__privateGet$
|
|
921
|
+
__privateGet$9(this, _winston).warn(message, meta);
|
|
921
922
|
}
|
|
922
923
|
info(message, meta) {
|
|
923
|
-
__privateGet$
|
|
924
|
+
__privateGet$9(this, _winston).info(message, meta);
|
|
924
925
|
}
|
|
925
926
|
debug(message, meta) {
|
|
926
|
-
__privateGet$
|
|
927
|
+
__privateGet$9(this, _winston).debug(message, meta);
|
|
927
928
|
}
|
|
928
929
|
child(meta) {
|
|
929
|
-
return new _WinstonLogger(__privateGet$
|
|
930
|
+
return new _WinstonLogger(__privateGet$9(this, _winston).child(meta));
|
|
930
931
|
}
|
|
931
932
|
addRedactions(redactions) {
|
|
932
933
|
var _a;
|
|
933
|
-
(_a = __privateGet$
|
|
934
|
+
(_a = __privateGet$9(this, _addRedactions)) == null ? void 0 : _a.call(this, redactions);
|
|
934
935
|
}
|
|
935
936
|
};
|
|
936
937
|
_winston = new WeakMap();
|
|
937
938
|
_addRedactions = new WeakMap();
|
|
938
939
|
let WinstonLogger = _WinstonLogger;
|
|
939
940
|
|
|
940
|
-
var __accessCheck$
|
|
941
|
+
var __accessCheck$9 = (obj, member, msg) => {
|
|
941
942
|
if (!member.has(obj))
|
|
942
943
|
throw TypeError("Cannot " + msg);
|
|
943
944
|
};
|
|
944
|
-
var __privateGet$
|
|
945
|
-
__accessCheck$
|
|
945
|
+
var __privateGet$8 = (obj, member, getter) => {
|
|
946
|
+
__accessCheck$9(obj, member, "read from private field");
|
|
946
947
|
return getter ? getter.call(obj) : member.get(obj);
|
|
947
948
|
};
|
|
948
|
-
var __privateAdd$
|
|
949
|
+
var __privateAdd$9 = (obj, member, value) => {
|
|
949
950
|
if (member.has(obj))
|
|
950
951
|
throw TypeError("Cannot add the same private member more than once");
|
|
951
952
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
952
953
|
};
|
|
953
|
-
var __privateSet$
|
|
954
|
-
__accessCheck$
|
|
954
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
|
955
|
+
__accessCheck$9(obj, member, "write to private field");
|
|
955
956
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
956
957
|
return value;
|
|
957
958
|
};
|
|
@@ -959,25 +960,25 @@ var _hasStarted$1, _startupTasks$1, _hasShutdown, _shutdownTasks;
|
|
|
959
960
|
class BackendLifecycleImpl {
|
|
960
961
|
constructor(logger) {
|
|
961
962
|
this.logger = logger;
|
|
962
|
-
__privateAdd$
|
|
963
|
-
__privateAdd$
|
|
964
|
-
__privateAdd$
|
|
965
|
-
__privateAdd$
|
|
963
|
+
__privateAdd$9(this, _hasStarted$1, false);
|
|
964
|
+
__privateAdd$9(this, _startupTasks$1, []);
|
|
965
|
+
__privateAdd$9(this, _hasShutdown, false);
|
|
966
|
+
__privateAdd$9(this, _shutdownTasks, []);
|
|
966
967
|
}
|
|
967
968
|
addStartupHook(hook, options) {
|
|
968
|
-
if (__privateGet$
|
|
969
|
+
if (__privateGet$8(this, _hasStarted$1)) {
|
|
969
970
|
throw new Error("Attempted to add startup hook after startup");
|
|
970
971
|
}
|
|
971
|
-
__privateGet$
|
|
972
|
+
__privateGet$8(this, _startupTasks$1).push({ hook, options });
|
|
972
973
|
}
|
|
973
974
|
async startup() {
|
|
974
|
-
if (__privateGet$
|
|
975
|
+
if (__privateGet$8(this, _hasStarted$1)) {
|
|
975
976
|
return;
|
|
976
977
|
}
|
|
977
|
-
__privateSet$
|
|
978
|
-
this.logger.debug(`Running ${__privateGet$
|
|
978
|
+
__privateSet$8(this, _hasStarted$1, true);
|
|
979
|
+
this.logger.debug(`Running ${__privateGet$8(this, _startupTasks$1).length} startup tasks...`);
|
|
979
980
|
await Promise.all(
|
|
980
|
-
__privateGet$
|
|
981
|
+
__privateGet$8(this, _startupTasks$1).map(async ({ hook, options }) => {
|
|
981
982
|
var _a;
|
|
982
983
|
const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
|
|
983
984
|
try {
|
|
@@ -990,21 +991,21 @@ class BackendLifecycleImpl {
|
|
|
990
991
|
);
|
|
991
992
|
}
|
|
992
993
|
addShutdownHook(hook, options) {
|
|
993
|
-
if (__privateGet$
|
|
994
|
+
if (__privateGet$8(this, _hasShutdown)) {
|
|
994
995
|
throw new Error("Attempted to add shutdown hook after shutdown");
|
|
995
996
|
}
|
|
996
|
-
__privateGet$
|
|
997
|
+
__privateGet$8(this, _shutdownTasks).push({ hook, options });
|
|
997
998
|
}
|
|
998
999
|
async shutdown() {
|
|
999
|
-
if (__privateGet$
|
|
1000
|
+
if (__privateGet$8(this, _hasShutdown)) {
|
|
1000
1001
|
return;
|
|
1001
1002
|
}
|
|
1002
|
-
__privateSet$
|
|
1003
|
+
__privateSet$8(this, _hasShutdown, true);
|
|
1003
1004
|
this.logger.debug(
|
|
1004
|
-
`Running ${__privateGet$
|
|
1005
|
+
`Running ${__privateGet$8(this, _shutdownTasks).length} shutdown tasks...`
|
|
1005
1006
|
);
|
|
1006
1007
|
await Promise.all(
|
|
1007
|
-
__privateGet$
|
|
1008
|
+
__privateGet$8(this, _shutdownTasks).map(async ({ hook, options }) => {
|
|
1008
1009
|
var _a;
|
|
1009
1010
|
const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
|
|
1010
1011
|
try {
|
|
@@ -1031,21 +1032,21 @@ const rootLifecycleServiceFactory = backendPluginApi.createServiceFactory({
|
|
|
1031
1032
|
}
|
|
1032
1033
|
});
|
|
1033
1034
|
|
|
1034
|
-
var __accessCheck$
|
|
1035
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
|
1035
1036
|
if (!member.has(obj))
|
|
1036
1037
|
throw TypeError("Cannot " + msg);
|
|
1037
1038
|
};
|
|
1038
|
-
var __privateGet$
|
|
1039
|
-
__accessCheck$
|
|
1039
|
+
var __privateGet$7 = (obj, member, getter) => {
|
|
1040
|
+
__accessCheck$8(obj, member, "read from private field");
|
|
1040
1041
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1041
1042
|
};
|
|
1042
|
-
var __privateAdd$
|
|
1043
|
+
var __privateAdd$8 = (obj, member, value) => {
|
|
1043
1044
|
if (member.has(obj))
|
|
1044
1045
|
throw TypeError("Cannot add the same private member more than once");
|
|
1045
1046
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1046
1047
|
};
|
|
1047
|
-
var __privateSet$
|
|
1048
|
-
__accessCheck$
|
|
1048
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
|
1049
|
+
__accessCheck$8(obj, member, "write to private field");
|
|
1049
1050
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1050
1051
|
return value;
|
|
1051
1052
|
};
|
|
@@ -1055,25 +1056,25 @@ class BackendPluginLifecycleImpl {
|
|
|
1055
1056
|
this.logger = logger;
|
|
1056
1057
|
this.rootLifecycle = rootLifecycle;
|
|
1057
1058
|
this.pluginMetadata = pluginMetadata;
|
|
1058
|
-
__privateAdd$
|
|
1059
|
-
__privateAdd$
|
|
1059
|
+
__privateAdd$8(this, _hasStarted, false);
|
|
1060
|
+
__privateAdd$8(this, _startupTasks, []);
|
|
1060
1061
|
}
|
|
1061
1062
|
addStartupHook(hook, options) {
|
|
1062
|
-
if (__privateGet$
|
|
1063
|
+
if (__privateGet$7(this, _hasStarted)) {
|
|
1063
1064
|
throw new Error("Attempted to add startup hook after startup");
|
|
1064
1065
|
}
|
|
1065
|
-
__privateGet$
|
|
1066
|
+
__privateGet$7(this, _startupTasks).push({ hook, options });
|
|
1066
1067
|
}
|
|
1067
1068
|
async startup() {
|
|
1068
|
-
if (__privateGet$
|
|
1069
|
+
if (__privateGet$7(this, _hasStarted)) {
|
|
1069
1070
|
return;
|
|
1070
1071
|
}
|
|
1071
|
-
__privateSet$
|
|
1072
|
+
__privateSet$7(this, _hasStarted, true);
|
|
1072
1073
|
this.logger.debug(
|
|
1073
|
-
`Running ${__privateGet$
|
|
1074
|
+
`Running ${__privateGet$7(this, _startupTasks).length} plugin startup tasks...`
|
|
1074
1075
|
);
|
|
1075
1076
|
await Promise.all(
|
|
1076
|
-
__privateGet$
|
|
1077
|
+
__privateGet$7(this, _startupTasks).map(async ({ hook, options }) => {
|
|
1077
1078
|
var _a;
|
|
1078
1079
|
const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
|
|
1079
1080
|
try {
|
|
@@ -1111,26 +1112,26 @@ const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
|
|
|
1111
1112
|
}
|
|
1112
1113
|
});
|
|
1113
1114
|
|
|
1114
|
-
var __accessCheck$
|
|
1115
|
+
var __accessCheck$7 = (obj, member, msg) => {
|
|
1115
1116
|
if (!member.has(obj))
|
|
1116
1117
|
throw TypeError("Cannot " + msg);
|
|
1117
1118
|
};
|
|
1118
|
-
var __privateGet$
|
|
1119
|
-
__accessCheck$
|
|
1119
|
+
var __privateGet$6 = (obj, member, getter) => {
|
|
1120
|
+
__accessCheck$7(obj, member, "read from private field");
|
|
1120
1121
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1121
1122
|
};
|
|
1122
|
-
var __privateAdd$
|
|
1123
|
+
var __privateAdd$7 = (obj, member, value) => {
|
|
1123
1124
|
if (member.has(obj))
|
|
1124
1125
|
throw TypeError("Cannot add the same private member more than once");
|
|
1125
1126
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1126
1127
|
};
|
|
1127
|
-
var __privateSet$
|
|
1128
|
-
__accessCheck$
|
|
1128
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
|
1129
|
+
__accessCheck$7(obj, member, "write to private field");
|
|
1129
1130
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1130
1131
|
return value;
|
|
1131
1132
|
};
|
|
1132
|
-
var __privateMethod$
|
|
1133
|
-
__accessCheck$
|
|
1133
|
+
var __privateMethod$6 = (obj, member, method) => {
|
|
1134
|
+
__accessCheck$7(obj, member, "access private method");
|
|
1134
1135
|
return method;
|
|
1135
1136
|
};
|
|
1136
1137
|
var _nodeIds, _cycleKeys, _getCycleKey, getCycleKey_fn, _nodes, _allProvided;
|
|
@@ -1150,21 +1151,21 @@ class Node {
|
|
|
1150
1151
|
}
|
|
1151
1152
|
const _CycleKeySet = class _CycleKeySet {
|
|
1152
1153
|
constructor(nodes) {
|
|
1153
|
-
__privateAdd$
|
|
1154
|
-
__privateAdd$
|
|
1155
|
-
__privateAdd$
|
|
1156
|
-
__privateSet$
|
|
1157
|
-
__privateSet$
|
|
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());
|
|
1158
1159
|
}
|
|
1159
1160
|
static from(nodes) {
|
|
1160
1161
|
return new _CycleKeySet(nodes);
|
|
1161
1162
|
}
|
|
1162
1163
|
tryAdd(path) {
|
|
1163
|
-
const cycleKey = __privateMethod$
|
|
1164
|
-
if (__privateGet$
|
|
1164
|
+
const cycleKey = __privateMethod$6(this, _getCycleKey, getCycleKey_fn).call(this, path);
|
|
1165
|
+
if (__privateGet$6(this, _cycleKeys).has(cycleKey)) {
|
|
1165
1166
|
return false;
|
|
1166
1167
|
}
|
|
1167
|
-
__privateGet$
|
|
1168
|
+
__privateGet$6(this, _cycleKeys).add(cycleKey);
|
|
1168
1169
|
return true;
|
|
1169
1170
|
}
|
|
1170
1171
|
};
|
|
@@ -1172,18 +1173,18 @@ _nodeIds = new WeakMap();
|
|
|
1172
1173
|
_cycleKeys = new WeakMap();
|
|
1173
1174
|
_getCycleKey = new WeakSet();
|
|
1174
1175
|
getCycleKey_fn = function(path) {
|
|
1175
|
-
return path.map((n) => __privateGet$
|
|
1176
|
+
return path.map((n) => __privateGet$6(this, _nodeIds).get(n)).sort().join(",");
|
|
1176
1177
|
};
|
|
1177
1178
|
let CycleKeySet = _CycleKeySet;
|
|
1178
1179
|
const _DependencyGraph = class _DependencyGraph {
|
|
1179
1180
|
constructor(nodes) {
|
|
1180
|
-
__privateAdd$
|
|
1181
|
-
__privateAdd$
|
|
1182
|
-
__privateSet$
|
|
1183
|
-
__privateSet$
|
|
1184
|
-
for (const node of __privateGet$
|
|
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()) {
|
|
1185
1186
|
for (const produced of node.provides) {
|
|
1186
|
-
__privateGet$
|
|
1187
|
+
__privateGet$6(this, _allProvided).add(produced);
|
|
1187
1188
|
}
|
|
1188
1189
|
}
|
|
1189
1190
|
}
|
|
@@ -1207,9 +1208,9 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1207
1208
|
*/
|
|
1208
1209
|
findUnsatisfiedDeps() {
|
|
1209
1210
|
const unsatisfiedDependencies = [];
|
|
1210
|
-
for (const node of __privateGet$
|
|
1211
|
+
for (const node of __privateGet$6(this, _nodes).values()) {
|
|
1211
1212
|
const unsatisfied = Array.from(node.consumes).filter(
|
|
1212
|
-
(id) => !__privateGet$
|
|
1213
|
+
(id) => !__privateGet$6(this, _allProvided).has(id)
|
|
1213
1214
|
);
|
|
1214
1215
|
if (unsatisfied.length > 0) {
|
|
1215
1216
|
unsatisfiedDependencies.push({ value: node.value, unsatisfied });
|
|
@@ -1229,8 +1230,8 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1229
1230
|
* form a cycle, with the same node as the first and last element of the array.
|
|
1230
1231
|
*/
|
|
1231
1232
|
*detectCircularDependencies() {
|
|
1232
|
-
const cycleKeys = CycleKeySet.from(__privateGet$
|
|
1233
|
-
for (const startNode of __privateGet$
|
|
1233
|
+
const cycleKeys = CycleKeySet.from(__privateGet$6(this, _nodes));
|
|
1234
|
+
for (const startNode of __privateGet$6(this, _nodes)) {
|
|
1234
1235
|
const visited = /* @__PURE__ */ new Set();
|
|
1235
1236
|
const stack = new Array([
|
|
1236
1237
|
startNode,
|
|
@@ -1243,7 +1244,7 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1243
1244
|
}
|
|
1244
1245
|
visited.add(node);
|
|
1245
1246
|
for (const consumed of node.consumes) {
|
|
1246
|
-
const providerNodes = __privateGet$
|
|
1247
|
+
const providerNodes = __privateGet$6(this, _nodes).filter(
|
|
1247
1248
|
(other) => other.provides.has(consumed)
|
|
1248
1249
|
);
|
|
1249
1250
|
for (const provider of providerNodes) {
|
|
@@ -1272,9 +1273,9 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1272
1273
|
* Dependencies of nodes that are not produced by any other nodes will be ignored.
|
|
1273
1274
|
*/
|
|
1274
1275
|
async parallelTopologicalTraversal(fn) {
|
|
1275
|
-
const allProvided = __privateGet$
|
|
1276
|
+
const allProvided = __privateGet$6(this, _allProvided);
|
|
1276
1277
|
const producedSoFar = /* @__PURE__ */ new Set();
|
|
1277
|
-
const waiting = new Set(__privateGet$
|
|
1278
|
+
const waiting = new Set(__privateGet$6(this, _nodes).values());
|
|
1278
1279
|
const visited = /* @__PURE__ */ new Set();
|
|
1279
1280
|
const results = new Array();
|
|
1280
1281
|
let inFlight = 0;
|
|
@@ -1320,26 +1321,26 @@ _nodes = new WeakMap();
|
|
|
1320
1321
|
_allProvided = new WeakMap();
|
|
1321
1322
|
let DependencyGraph = _DependencyGraph;
|
|
1322
1323
|
|
|
1323
|
-
var __accessCheck$
|
|
1324
|
+
var __accessCheck$6 = (obj, member, msg) => {
|
|
1324
1325
|
if (!member.has(obj))
|
|
1325
1326
|
throw TypeError("Cannot " + msg);
|
|
1326
1327
|
};
|
|
1327
|
-
var __privateGet$
|
|
1328
|
-
__accessCheck$
|
|
1328
|
+
var __privateGet$5 = (obj, member, getter) => {
|
|
1329
|
+
__accessCheck$6(obj, member, "read from private field");
|
|
1329
1330
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1330
1331
|
};
|
|
1331
|
-
var __privateAdd$
|
|
1332
|
+
var __privateAdd$6 = (obj, member, value) => {
|
|
1332
1333
|
if (member.has(obj))
|
|
1333
1334
|
throw TypeError("Cannot add the same private member more than once");
|
|
1334
1335
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1335
1336
|
};
|
|
1336
|
-
var __privateSet$
|
|
1337
|
-
__accessCheck$
|
|
1337
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
|
1338
|
+
__accessCheck$6(obj, member, "write to private field");
|
|
1338
1339
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1339
1340
|
return value;
|
|
1340
1341
|
};
|
|
1341
|
-
var __privateMethod$
|
|
1342
|
-
__accessCheck$
|
|
1342
|
+
var __privateMethod$5 = (obj, member, method) => {
|
|
1343
|
+
__accessCheck$6(obj, member, "access private method");
|
|
1343
1344
|
return method;
|
|
1344
1345
|
};
|
|
1345
1346
|
var _providedFactories, _loadedDefaultFactories, _implementations, _rootServiceImplementations, _addedFactoryIds, _instantiatedFactories, _resolveFactory, resolveFactory_fn, _checkForMissingDeps, checkForMissingDeps_fn;
|
|
@@ -1362,19 +1363,19 @@ const pluginMetadataServiceFactory = backendPluginApi.createServiceFactory(
|
|
|
1362
1363
|
);
|
|
1363
1364
|
const _ServiceRegistry = class _ServiceRegistry {
|
|
1364
1365
|
constructor(factories) {
|
|
1365
|
-
__privateAdd$
|
|
1366
|
-
__privateAdd$
|
|
1367
|
-
__privateAdd$
|
|
1368
|
-
__privateAdd$
|
|
1369
|
-
__privateAdd$
|
|
1370
|
-
__privateAdd$
|
|
1371
|
-
__privateAdd$
|
|
1372
|
-
__privateAdd$
|
|
1373
|
-
__privateSet$
|
|
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(
|
|
1374
1375
|
factories.map((sf) => [sf.service.id, toInternalServiceFactory(sf)])
|
|
1375
1376
|
));
|
|
1376
|
-
__privateSet$
|
|
1377
|
-
__privateSet$
|
|
1377
|
+
__privateSet$5(this, _loadedDefaultFactories, /* @__PURE__ */ new Map());
|
|
1378
|
+
__privateSet$5(this, _implementations, /* @__PURE__ */ new Map());
|
|
1378
1379
|
}
|
|
1379
1380
|
static create(factories) {
|
|
1380
1381
|
const registry = new _ServiceRegistry(factories);
|
|
@@ -1383,7 +1384,7 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1383
1384
|
}
|
|
1384
1385
|
checkForCircularDeps() {
|
|
1385
1386
|
const graph = DependencyGraph.fromIterable(
|
|
1386
|
-
Array.from(__privateGet$
|
|
1387
|
+
Array.from(__privateGet$5(this, _providedFactories)).map(
|
|
1387
1388
|
([serviceId, serviceFactory]) => ({
|
|
1388
1389
|
value: serviceId,
|
|
1389
1390
|
provides: [serviceId],
|
|
@@ -1405,30 +1406,30 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1405
1406
|
`The ${backendPluginApi.coreServices.pluginMetadata.id} service cannot be overridden`
|
|
1406
1407
|
);
|
|
1407
1408
|
}
|
|
1408
|
-
if (__privateGet$
|
|
1409
|
+
if (__privateGet$5(this, _addedFactoryIds).has(factoryId)) {
|
|
1409
1410
|
throw new Error(
|
|
1410
1411
|
`Duplicate service implementations provided for ${factoryId}`
|
|
1411
1412
|
);
|
|
1412
1413
|
}
|
|
1413
|
-
if (__privateGet$
|
|
1414
|
+
if (__privateGet$5(this, _instantiatedFactories).has(factoryId)) {
|
|
1414
1415
|
throw new Error(
|
|
1415
1416
|
`Unable to set service factory with id ${factoryId}, service has already been instantiated`
|
|
1416
1417
|
);
|
|
1417
1418
|
}
|
|
1418
|
-
__privateGet$
|
|
1419
|
-
__privateGet$
|
|
1419
|
+
__privateGet$5(this, _addedFactoryIds).add(factoryId);
|
|
1420
|
+
__privateGet$5(this, _providedFactories).set(factoryId, toInternalServiceFactory(factory));
|
|
1420
1421
|
}
|
|
1421
1422
|
getServiceRefs() {
|
|
1422
|
-
return Array.from(__privateGet$
|
|
1423
|
+
return Array.from(__privateGet$5(this, _providedFactories).values()).map((f) => f.service);
|
|
1423
1424
|
}
|
|
1424
1425
|
get(ref, pluginId) {
|
|
1425
1426
|
var _a;
|
|
1426
|
-
__privateGet$
|
|
1427
|
-
return (_a = __privateMethod$
|
|
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) => {
|
|
1428
1429
|
if (factory.service.scope === "root") {
|
|
1429
|
-
let existing = __privateGet$
|
|
1430
|
+
let existing = __privateGet$5(this, _rootServiceImplementations).get(factory);
|
|
1430
1431
|
if (!existing) {
|
|
1431
|
-
__privateMethod$
|
|
1432
|
+
__privateMethod$5(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
|
|
1432
1433
|
const rootDeps = new Array();
|
|
1433
1434
|
for (const [name, serviceRef] of Object.entries(factory.deps)) {
|
|
1434
1435
|
if (serviceRef.scope !== "root") {
|
|
@@ -1442,13 +1443,13 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1442
1443
|
existing = Promise.all(rootDeps).then(
|
|
1443
1444
|
(entries) => factory.factory(Object.fromEntries(entries), void 0)
|
|
1444
1445
|
);
|
|
1445
|
-
__privateGet$
|
|
1446
|
+
__privateGet$5(this, _rootServiceImplementations).set(factory, existing);
|
|
1446
1447
|
}
|
|
1447
1448
|
return existing;
|
|
1448
1449
|
}
|
|
1449
|
-
let implementation = __privateGet$
|
|
1450
|
+
let implementation = __privateGet$5(this, _implementations).get(factory);
|
|
1450
1451
|
if (!implementation) {
|
|
1451
|
-
__privateMethod$
|
|
1452
|
+
__privateMethod$5(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
|
|
1452
1453
|
const rootDeps = new Array();
|
|
1453
1454
|
for (const [name, serviceRef] of Object.entries(factory.deps)) {
|
|
1454
1455
|
if (serviceRef.scope === "root") {
|
|
@@ -1470,7 +1471,7 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1470
1471
|
}),
|
|
1471
1472
|
byPlugin: /* @__PURE__ */ new Map()
|
|
1472
1473
|
};
|
|
1473
|
-
__privateGet$
|
|
1474
|
+
__privateGet$5(this, _implementations).set(factory, implementation);
|
|
1474
1475
|
}
|
|
1475
1476
|
let result = implementation.byPlugin.get(pluginId);
|
|
1476
1477
|
if (!result) {
|
|
@@ -1508,18 +1509,18 @@ resolveFactory_fn = function(ref, pluginId) {
|
|
|
1508
1509
|
toInternalServiceFactory(pluginMetadataServiceFactory({ pluginId }))
|
|
1509
1510
|
);
|
|
1510
1511
|
}
|
|
1511
|
-
let resolvedFactory = __privateGet$
|
|
1512
|
+
let resolvedFactory = __privateGet$5(this, _providedFactories).get(ref.id);
|
|
1512
1513
|
const { __defaultFactory: defaultFactory } = ref;
|
|
1513
1514
|
if (!resolvedFactory && !defaultFactory) {
|
|
1514
1515
|
return void 0;
|
|
1515
1516
|
}
|
|
1516
1517
|
if (!resolvedFactory) {
|
|
1517
|
-
let loadedFactory = __privateGet$
|
|
1518
|
+
let loadedFactory = __privateGet$5(this, _loadedDefaultFactories).get(defaultFactory);
|
|
1518
1519
|
if (!loadedFactory) {
|
|
1519
1520
|
loadedFactory = Promise.resolve().then(() => defaultFactory(ref)).then(
|
|
1520
1521
|
(f) => toInternalServiceFactory(typeof f === "function" ? f() : f)
|
|
1521
1522
|
);
|
|
1522
|
-
__privateGet$
|
|
1523
|
+
__privateGet$5(this, _loadedDefaultFactories).set(defaultFactory, loadedFactory);
|
|
1523
1524
|
}
|
|
1524
1525
|
resolvedFactory = loadedFactory.catch((error) => {
|
|
1525
1526
|
throw new Error(
|
|
@@ -1537,7 +1538,7 @@ checkForMissingDeps_fn = function(factory, pluginId) {
|
|
|
1537
1538
|
if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
|
|
1538
1539
|
return false;
|
|
1539
1540
|
}
|
|
1540
|
-
if (__privateGet$
|
|
1541
|
+
if (__privateGet$5(this, _providedFactories).get(ref.id)) {
|
|
1541
1542
|
return false;
|
|
1542
1543
|
}
|
|
1543
1544
|
return !ref.__defaultFactory;
|
|
@@ -1551,52 +1552,52 @@ checkForMissingDeps_fn = function(factory, pluginId) {
|
|
|
1551
1552
|
};
|
|
1552
1553
|
let ServiceRegistry = _ServiceRegistry;
|
|
1553
1554
|
|
|
1554
|
-
var __accessCheck$
|
|
1555
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
|
1555
1556
|
if (!member.has(obj))
|
|
1556
1557
|
throw TypeError("Cannot " + msg);
|
|
1557
1558
|
};
|
|
1558
|
-
var __privateGet$
|
|
1559
|
-
__accessCheck$
|
|
1559
|
+
var __privateGet$4 = (obj, member, getter) => {
|
|
1560
|
+
__accessCheck$5(obj, member, "read from private field");
|
|
1560
1561
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1561
1562
|
};
|
|
1562
|
-
var __privateAdd$
|
|
1563
|
+
var __privateAdd$5 = (obj, member, value) => {
|
|
1563
1564
|
if (member.has(obj))
|
|
1564
1565
|
throw TypeError("Cannot add the same private member more than once");
|
|
1565
1566
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1566
1567
|
};
|
|
1567
|
-
var __privateSet$
|
|
1568
|
-
__accessCheck$
|
|
1568
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
|
1569
|
+
__accessCheck$5(obj, member, "write to private field");
|
|
1569
1570
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1570
1571
|
return value;
|
|
1571
1572
|
};
|
|
1572
|
-
var __privateMethod$
|
|
1573
|
-
__accessCheck$
|
|
1573
|
+
var __privateMethod$4 = (obj, member, method) => {
|
|
1574
|
+
__accessCheck$5(obj, member, "access private method");
|
|
1574
1575
|
return method;
|
|
1575
1576
|
};
|
|
1576
1577
|
var _startPromise, _features, _extensionPoints, _serviceRegistry, _registeredFeatures, _getInitDeps, getInitDeps_fn, _addFeature, addFeature_fn, _doStart, doStart_fn, _getRootLifecycleImpl, getRootLifecycleImpl_fn, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn;
|
|
1577
1578
|
class BackendInitializer {
|
|
1578
1579
|
constructor(defaultApiFactories) {
|
|
1579
|
-
__privateAdd$
|
|
1580
|
-
__privateAdd$
|
|
1581
|
-
__privateAdd$
|
|
1580
|
+
__privateAdd$5(this, _getInitDeps);
|
|
1581
|
+
__privateAdd$5(this, _addFeature);
|
|
1582
|
+
__privateAdd$5(this, _doStart);
|
|
1582
1583
|
// Bit of a hacky way to grab the lifecycle services, potentially find a nicer way to do this
|
|
1583
|
-
__privateAdd$
|
|
1584
|
-
__privateAdd$
|
|
1585
|
-
__privateAdd$
|
|
1586
|
-
__privateAdd$
|
|
1587
|
-
__privateAdd$
|
|
1588
|
-
__privateAdd$
|
|
1589
|
-
__privateAdd$
|
|
1590
|
-
__privateSet$
|
|
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]));
|
|
1591
1592
|
}
|
|
1592
1593
|
add(feature) {
|
|
1593
|
-
if (__privateGet$
|
|
1594
|
+
if (__privateGet$4(this, _startPromise)) {
|
|
1594
1595
|
throw new Error("feature can not be added after the backend has started");
|
|
1595
1596
|
}
|
|
1596
|
-
__privateGet$
|
|
1597
|
+
__privateGet$4(this, _registeredFeatures).push(Promise.resolve(feature));
|
|
1597
1598
|
}
|
|
1598
1599
|
async start() {
|
|
1599
|
-
if (__privateGet$
|
|
1600
|
+
if (__privateGet$4(this, _startPromise)) {
|
|
1600
1601
|
throw new Error("Backend has already started");
|
|
1601
1602
|
}
|
|
1602
1603
|
const exitHandler = async () => {
|
|
@@ -1614,18 +1615,18 @@ class BackendInitializer {
|
|
|
1614
1615
|
process.addListener("SIGTERM", exitHandler);
|
|
1615
1616
|
process.addListener("SIGINT", exitHandler);
|
|
1616
1617
|
process.addListener("beforeExit", exitHandler);
|
|
1617
|
-
__privateSet$
|
|
1618
|
-
await __privateGet$
|
|
1618
|
+
__privateSet$4(this, _startPromise, __privateMethod$4(this, _doStart, doStart_fn).call(this));
|
|
1619
|
+
await __privateGet$4(this, _startPromise);
|
|
1619
1620
|
}
|
|
1620
1621
|
async stop() {
|
|
1621
|
-
if (!__privateGet$
|
|
1622
|
+
if (!__privateGet$4(this, _startPromise)) {
|
|
1622
1623
|
return;
|
|
1623
1624
|
}
|
|
1624
1625
|
try {
|
|
1625
|
-
await __privateGet$
|
|
1626
|
+
await __privateGet$4(this, _startPromise);
|
|
1626
1627
|
} catch (error) {
|
|
1627
1628
|
}
|
|
1628
|
-
const lifecycleService = await __privateMethod$
|
|
1629
|
+
const lifecycleService = await __privateMethod$4(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
|
|
1629
1630
|
await lifecycleService.shutdown();
|
|
1630
1631
|
}
|
|
1631
1632
|
}
|
|
@@ -1639,7 +1640,7 @@ getInitDeps_fn = async function(deps, pluginId, moduleId) {
|
|
|
1639
1640
|
const result = /* @__PURE__ */ new Map();
|
|
1640
1641
|
const missingRefs = /* @__PURE__ */ new Set();
|
|
1641
1642
|
for (const [name, ref] of Object.entries(deps)) {
|
|
1642
|
-
const ep = __privateGet$
|
|
1643
|
+
const ep = __privateGet$4(this, _extensionPoints).get(ref.id);
|
|
1643
1644
|
if (ep) {
|
|
1644
1645
|
if (ep.pluginId !== pluginId) {
|
|
1645
1646
|
throw new Error(
|
|
@@ -1648,7 +1649,7 @@ getInitDeps_fn = async function(deps, pluginId, moduleId) {
|
|
|
1648
1649
|
}
|
|
1649
1650
|
result.set(name, ep.impl);
|
|
1650
1651
|
} else {
|
|
1651
|
-
const impl = await __privateGet$
|
|
1652
|
+
const impl = await __privateGet$4(this, _serviceRegistry).get(
|
|
1652
1653
|
ref,
|
|
1653
1654
|
pluginId
|
|
1654
1655
|
);
|
|
@@ -1675,14 +1676,14 @@ addFeature_fn = function(feature) {
|
|
|
1675
1676
|
);
|
|
1676
1677
|
}
|
|
1677
1678
|
if (isServiceFactory(feature)) {
|
|
1678
|
-
__privateGet$
|
|
1679
|
+
__privateGet$4(this, _serviceRegistry).add(feature);
|
|
1679
1680
|
} else if (isInternalBackendFeature(feature)) {
|
|
1680
1681
|
if (feature.version !== "v1") {
|
|
1681
1682
|
throw new Error(
|
|
1682
1683
|
`Failed to add feature, invalid version '${feature.version}'`
|
|
1683
1684
|
);
|
|
1684
1685
|
}
|
|
1685
|
-
__privateGet$
|
|
1686
|
+
__privateGet$4(this, _features).push(feature);
|
|
1686
1687
|
} else {
|
|
1687
1688
|
throw new Error(
|
|
1688
1689
|
`Failed to add feature, invalid feature ${JSON.stringify(feature)}`
|
|
@@ -1691,39 +1692,39 @@ addFeature_fn = function(feature) {
|
|
|
1691
1692
|
};
|
|
1692
1693
|
_doStart = new WeakSet();
|
|
1693
1694
|
doStart_fn = async function() {
|
|
1694
|
-
__privateGet$
|
|
1695
|
-
for (const feature of __privateGet$
|
|
1696
|
-
__privateMethod$
|
|
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);
|
|
1697
1698
|
}
|
|
1698
|
-
const featureDiscovery = await __privateGet$
|
|
1699
|
+
const featureDiscovery = await __privateGet$4(this, _serviceRegistry).get(
|
|
1699
1700
|
alpha.featureDiscoveryServiceRef,
|
|
1700
1701
|
"root"
|
|
1701
1702
|
);
|
|
1702
1703
|
if (featureDiscovery) {
|
|
1703
1704
|
const { features } = await featureDiscovery.getBackendFeatures();
|
|
1704
1705
|
for (const feature of features) {
|
|
1705
|
-
__privateMethod$
|
|
1706
|
+
__privateMethod$4(this, _addFeature, addFeature_fn).call(this, feature);
|
|
1706
1707
|
}
|
|
1707
|
-
__privateGet$
|
|
1708
|
+
__privateGet$4(this, _serviceRegistry).checkForCircularDeps();
|
|
1708
1709
|
}
|
|
1709
|
-
for (const ref of __privateGet$
|
|
1710
|
+
for (const ref of __privateGet$4(this, _serviceRegistry).getServiceRefs()) {
|
|
1710
1711
|
if (ref.scope === "root") {
|
|
1711
|
-
await __privateGet$
|
|
1712
|
+
await __privateGet$4(this, _serviceRegistry).get(ref, "root");
|
|
1712
1713
|
}
|
|
1713
1714
|
}
|
|
1714
1715
|
const pluginInits = /* @__PURE__ */ new Map();
|
|
1715
1716
|
const moduleInits = /* @__PURE__ */ new Map();
|
|
1716
|
-
for (const feature of __privateGet$
|
|
1717
|
+
for (const feature of __privateGet$4(this, _features)) {
|
|
1717
1718
|
for (const r of feature.getRegistrations()) {
|
|
1718
1719
|
const provides = /* @__PURE__ */ new Set();
|
|
1719
1720
|
if (r.type === "plugin" || r.type === "module") {
|
|
1720
1721
|
for (const [extRef, extImpl] of r.extensionPoints) {
|
|
1721
|
-
if (__privateGet$
|
|
1722
|
+
if (__privateGet$4(this, _extensionPoints).has(extRef.id)) {
|
|
1722
1723
|
throw new Error(
|
|
1723
1724
|
`ExtensionPoint with ID '${extRef.id}' is already registered`
|
|
1724
1725
|
);
|
|
1725
1726
|
}
|
|
1726
|
-
__privateGet$
|
|
1727
|
+
__privateGet$4(this, _extensionPoints).set(extRef.id, {
|
|
1727
1728
|
impl: extImpl,
|
|
1728
1729
|
pluginId: r.pluginId
|
|
1729
1730
|
});
|
|
@@ -1783,7 +1784,7 @@ doStart_fn = async function() {
|
|
|
1783
1784
|
}
|
|
1784
1785
|
await tree.parallelTopologicalTraversal(
|
|
1785
1786
|
async ({ moduleId, moduleInit }) => {
|
|
1786
|
-
const moduleDeps = await __privateMethod$
|
|
1787
|
+
const moduleDeps = await __privateMethod$4(this, _getInitDeps, getInitDeps_fn).call(this, moduleInit.init.deps, pluginId, moduleId);
|
|
1787
1788
|
await moduleInit.init.func(moduleDeps).catch((error) => {
|
|
1788
1789
|
throw new errors.ForwardedError(
|
|
1789
1790
|
`Module '${moduleId}' for plugin '${pluginId}' startup failed`,
|
|
@@ -1795,7 +1796,7 @@ doStart_fn = async function() {
|
|
|
1795
1796
|
}
|
|
1796
1797
|
const pluginInit = pluginInits.get(pluginId);
|
|
1797
1798
|
if (pluginInit) {
|
|
1798
|
-
const pluginDeps = await __privateMethod$
|
|
1799
|
+
const pluginDeps = await __privateMethod$4(this, _getInitDeps, getInitDeps_fn).call(this, pluginInit.init.deps, pluginId);
|
|
1799
1800
|
await pluginInit.init.func(pluginDeps).catch((error) => {
|
|
1800
1801
|
throw new errors.ForwardedError(
|
|
1801
1802
|
`Plugin '${pluginId}' startup failed`,
|
|
@@ -1803,14 +1804,14 @@ doStart_fn = async function() {
|
|
|
1803
1804
|
);
|
|
1804
1805
|
});
|
|
1805
1806
|
}
|
|
1806
|
-
const lifecycleService2 = await __privateMethod$
|
|
1807
|
+
const lifecycleService2 = await __privateMethod$4(this, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn).call(this, pluginId);
|
|
1807
1808
|
await lifecycleService2.startup();
|
|
1808
1809
|
})
|
|
1809
1810
|
);
|
|
1810
|
-
const lifecycleService = await __privateMethod$
|
|
1811
|
+
const lifecycleService = await __privateMethod$4(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
|
|
1811
1812
|
await lifecycleService.startup();
|
|
1812
1813
|
if (process.env.NODE_ENV !== "test") {
|
|
1813
|
-
const rootLogger = await __privateGet$
|
|
1814
|
+
const rootLogger = await __privateGet$4(this, _serviceRegistry).get(
|
|
1814
1815
|
backendPluginApi.coreServices.rootLogger,
|
|
1815
1816
|
"root"
|
|
1816
1817
|
);
|
|
@@ -1826,7 +1827,7 @@ doStart_fn = async function() {
|
|
|
1826
1827
|
};
|
|
1827
1828
|
_getRootLifecycleImpl = new WeakSet();
|
|
1828
1829
|
getRootLifecycleImpl_fn = async function() {
|
|
1829
|
-
const lifecycleService = await __privateGet$
|
|
1830
|
+
const lifecycleService = await __privateGet$4(this, _serviceRegistry).get(
|
|
1830
1831
|
backendPluginApi.coreServices.rootLifecycle,
|
|
1831
1832
|
"root"
|
|
1832
1833
|
);
|
|
@@ -1837,7 +1838,7 @@ getRootLifecycleImpl_fn = async function() {
|
|
|
1837
1838
|
};
|
|
1838
1839
|
_getPluginLifecycleImpl = new WeakSet();
|
|
1839
1840
|
getPluginLifecycleImpl_fn = async function(pluginId) {
|
|
1840
|
-
const lifecycleService = await __privateGet$
|
|
1841
|
+
const lifecycleService = await __privateGet$4(this, _serviceRegistry).get(
|
|
1841
1842
|
backendPluginApi.coreServices.lifecycle,
|
|
1842
1843
|
pluginId
|
|
1843
1844
|
);
|
|
@@ -1853,42 +1854,42 @@ function isInternalBackendFeature(feature) {
|
|
|
1853
1854
|
return typeof feature.getRegistrations === "function";
|
|
1854
1855
|
}
|
|
1855
1856
|
|
|
1856
|
-
var __accessCheck$
|
|
1857
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
1857
1858
|
if (!member.has(obj))
|
|
1858
1859
|
throw TypeError("Cannot " + msg);
|
|
1859
1860
|
};
|
|
1860
|
-
var __privateGet$
|
|
1861
|
-
__accessCheck$
|
|
1861
|
+
var __privateGet$3 = (obj, member, getter) => {
|
|
1862
|
+
__accessCheck$4(obj, member, "read from private field");
|
|
1862
1863
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1863
1864
|
};
|
|
1864
|
-
var __privateAdd$
|
|
1865
|
+
var __privateAdd$4 = (obj, member, value) => {
|
|
1865
1866
|
if (member.has(obj))
|
|
1866
1867
|
throw TypeError("Cannot add the same private member more than once");
|
|
1867
1868
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1868
1869
|
};
|
|
1869
|
-
var __privateSet$
|
|
1870
|
-
__accessCheck$
|
|
1870
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
|
1871
|
+
__accessCheck$4(obj, member, "write to private field");
|
|
1871
1872
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1872
1873
|
return value;
|
|
1873
1874
|
};
|
|
1874
1875
|
var _initializer;
|
|
1875
1876
|
class BackstageBackend {
|
|
1876
1877
|
constructor(defaultServiceFactories) {
|
|
1877
|
-
__privateAdd$
|
|
1878
|
-
__privateSet$
|
|
1878
|
+
__privateAdd$4(this, _initializer, void 0);
|
|
1879
|
+
__privateSet$3(this, _initializer, new BackendInitializer(defaultServiceFactories));
|
|
1879
1880
|
}
|
|
1880
1881
|
add(feature) {
|
|
1881
1882
|
if (isPromise(feature)) {
|
|
1882
|
-
__privateGet$
|
|
1883
|
+
__privateGet$3(this, _initializer).add(feature.then((f) => unwrapFeature(f.default)));
|
|
1883
1884
|
} else {
|
|
1884
|
-
__privateGet$
|
|
1885
|
+
__privateGet$3(this, _initializer).add(unwrapFeature(feature));
|
|
1885
1886
|
}
|
|
1886
1887
|
}
|
|
1887
1888
|
async start() {
|
|
1888
|
-
await __privateGet$
|
|
1889
|
+
await __privateGet$3(this, _initializer).start();
|
|
1889
1890
|
}
|
|
1890
1891
|
async stop() {
|
|
1891
|
-
await __privateGet$
|
|
1892
|
+
await __privateGet$3(this, _initializer).stop();
|
|
1892
1893
|
}
|
|
1893
1894
|
}
|
|
1894
1895
|
_initializer = new WeakMap();
|
|
@@ -1934,17 +1935,17 @@ function createSpecializedBackend(options) {
|
|
|
1934
1935
|
return new BackstageBackend(services);
|
|
1935
1936
|
}
|
|
1936
1937
|
|
|
1937
|
-
var __accessCheck$
|
|
1938
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
|
1938
1939
|
if (!member.has(obj))
|
|
1939
1940
|
throw TypeError("Cannot " + msg);
|
|
1940
1941
|
};
|
|
1941
|
-
var __privateAdd$
|
|
1942
|
+
var __privateAdd$3 = (obj, member, value) => {
|
|
1942
1943
|
if (member.has(obj))
|
|
1943
1944
|
throw TypeError("Cannot add the same private member more than once");
|
|
1944
1945
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1945
1946
|
};
|
|
1946
|
-
var __privateMethod$
|
|
1947
|
-
__accessCheck$
|
|
1947
|
+
var __privateMethod$3 = (obj, member, method) => {
|
|
1948
|
+
__accessCheck$3(obj, member, "access private method");
|
|
1948
1949
|
return method;
|
|
1949
1950
|
};
|
|
1950
1951
|
var _getJwtExpiration, getJwtExpiration_fn;
|
|
@@ -1998,7 +1999,7 @@ class DefaultAuthService {
|
|
|
1998
1999
|
this.identity = identity;
|
|
1999
2000
|
this.pluginId = pluginId;
|
|
2000
2001
|
this.disableDefaultAuthPolicy = disableDefaultAuthPolicy;
|
|
2001
|
-
__privateAdd$
|
|
2002
|
+
__privateAdd$3(this, _getJwtExpiration);
|
|
2002
2003
|
}
|
|
2003
2004
|
// allowLimitedAccess is currently ignored, since we currently always use the full user tokens
|
|
2004
2005
|
async authenticate(token) {
|
|
@@ -2018,7 +2019,7 @@ class DefaultAuthService {
|
|
|
2018
2019
|
return createCredentialsWithUserPrincipal(
|
|
2019
2020
|
identity.identity.userEntityRef,
|
|
2020
2021
|
token,
|
|
2021
|
-
__privateMethod$
|
|
2022
|
+
__privateMethod$3(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token)
|
|
2022
2023
|
);
|
|
2023
2024
|
}
|
|
2024
2025
|
isPrincipal(credentials, type) {
|
|
@@ -2065,7 +2066,7 @@ class DefaultAuthService {
|
|
|
2065
2066
|
"User credentials is unexpectedly missing token"
|
|
2066
2067
|
);
|
|
2067
2068
|
}
|
|
2068
|
-
return { token, expiresAt: __privateMethod$
|
|
2069
|
+
return { token, expiresAt: __privateMethod$3(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token) };
|
|
2069
2070
|
}
|
|
2070
2071
|
}
|
|
2071
2072
|
_getJwtExpiration = new WeakSet();
|
|
@@ -2249,26 +2250,26 @@ const discoveryServiceFactory = backendPluginApi.createServiceFactory({
|
|
|
2249
2250
|
}
|
|
2250
2251
|
});
|
|
2251
2252
|
|
|
2252
|
-
var __accessCheck$
|
|
2253
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
|
2253
2254
|
if (!member.has(obj))
|
|
2254
2255
|
throw TypeError("Cannot " + msg);
|
|
2255
2256
|
};
|
|
2256
|
-
var __privateGet$
|
|
2257
|
-
__accessCheck$
|
|
2257
|
+
var __privateGet$2 = (obj, member, getter) => {
|
|
2258
|
+
__accessCheck$2(obj, member, "read from private field");
|
|
2258
2259
|
return getter ? getter.call(obj) : member.get(obj);
|
|
2259
2260
|
};
|
|
2260
|
-
var __privateAdd$
|
|
2261
|
+
var __privateAdd$2 = (obj, member, value) => {
|
|
2261
2262
|
if (member.has(obj))
|
|
2262
2263
|
throw TypeError("Cannot add the same private member more than once");
|
|
2263
2264
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2264
2265
|
};
|
|
2265
|
-
var __privateSet$
|
|
2266
|
-
__accessCheck$
|
|
2266
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
|
2267
|
+
__accessCheck$2(obj, member, "write to private field");
|
|
2267
2268
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
2268
2269
|
return value;
|
|
2269
2270
|
};
|
|
2270
|
-
var __privateMethod$
|
|
2271
|
-
__accessCheck$
|
|
2271
|
+
var __privateMethod$2 = (obj, member, method) => {
|
|
2272
|
+
__accessCheck$2(obj, member, "access private method");
|
|
2272
2273
|
return method;
|
|
2273
2274
|
};
|
|
2274
2275
|
var _auth, _discovery, _pluginId, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn, _getCredentials, getCredentials_fn, _getLimitedCredentials, getLimitedCredentials_fn, _existingCookieExpiration, existingCookieExpiration_fn;
|
|
@@ -2303,37 +2304,37 @@ const credentialsSymbol = Symbol("backstage-credentials");
|
|
|
2303
2304
|
const limitedCredentialsSymbol = Symbol("backstage-limited-credentials");
|
|
2304
2305
|
class DefaultHttpAuthService {
|
|
2305
2306
|
constructor(auth, discovery, pluginId) {
|
|
2306
|
-
__privateAdd$
|
|
2307
|
-
__privateAdd$
|
|
2308
|
-
__privateAdd$
|
|
2309
|
-
__privateAdd$
|
|
2310
|
-
__privateAdd$
|
|
2311
|
-
__privateAdd$
|
|
2312
|
-
__privateAdd$
|
|
2313
|
-
__privateAdd$
|
|
2314
|
-
__privateSet$
|
|
2315
|
-
__privateSet$
|
|
2316
|
-
__privateSet$
|
|
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);
|
|
2317
2318
|
}
|
|
2318
2319
|
async credentials(req, options) {
|
|
2319
|
-
const credentials = (options == null ? void 0 : options.allowLimitedAccess) ? await __privateMethod$
|
|
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);
|
|
2320
2321
|
const allowed = options == null ? void 0 : options.allow;
|
|
2321
2322
|
if (!allowed) {
|
|
2322
2323
|
return credentials;
|
|
2323
2324
|
}
|
|
2324
|
-
if (__privateGet$
|
|
2325
|
+
if (__privateGet$2(this, _auth).isPrincipal(credentials, "none")) {
|
|
2325
2326
|
if (allowed.includes("none")) {
|
|
2326
2327
|
return credentials;
|
|
2327
2328
|
}
|
|
2328
2329
|
throw new errors.AuthenticationError("Missing credentials");
|
|
2329
|
-
} else if (__privateGet$
|
|
2330
|
+
} else if (__privateGet$2(this, _auth).isPrincipal(credentials, "user")) {
|
|
2330
2331
|
if (allowed.includes("user")) {
|
|
2331
2332
|
return credentials;
|
|
2332
2333
|
}
|
|
2333
2334
|
throw new errors.NotAllowedError(
|
|
2334
2335
|
`This endpoint does not allow 'user' credentials`
|
|
2335
2336
|
);
|
|
2336
|
-
} else if (__privateGet$
|
|
2337
|
+
} else if (__privateGet$2(this, _auth).isPrincipal(credentials, "service")) {
|
|
2337
2338
|
if (allowed.includes("service")) {
|
|
2338
2339
|
return credentials;
|
|
2339
2340
|
}
|
|
@@ -2351,7 +2352,7 @@ class DefaultHttpAuthService {
|
|
|
2351
2352
|
}
|
|
2352
2353
|
let credentials;
|
|
2353
2354
|
if (options == null ? void 0 : options.credentials) {
|
|
2354
|
-
if (!__privateGet$
|
|
2355
|
+
if (!__privateGet$2(this, _auth).isPrincipal(options.credentials, "user")) {
|
|
2355
2356
|
throw new errors.AuthenticationError(
|
|
2356
2357
|
"Refused to issue cookie for non-user principal"
|
|
2357
2358
|
);
|
|
@@ -2360,17 +2361,17 @@ class DefaultHttpAuthService {
|
|
|
2360
2361
|
} else {
|
|
2361
2362
|
credentials = await this.credentials(res.req, { allow: ["user"] });
|
|
2362
2363
|
}
|
|
2363
|
-
const existingExpiresAt = await __privateMethod$
|
|
2364
|
+
const existingExpiresAt = await __privateMethod$2(this, _existingCookieExpiration, existingCookieExpiration_fn).call(this, res.req);
|
|
2364
2365
|
if (existingExpiresAt && !willExpireSoon(existingExpiresAt)) {
|
|
2365
2366
|
return { expiresAt: existingExpiresAt };
|
|
2366
2367
|
}
|
|
2367
2368
|
const originHeader = res.req.headers.origin;
|
|
2368
2369
|
const origin = !originHeader || originHeader === "null" ? void 0 : originHeader;
|
|
2369
|
-
const externalBaseUrlStr = await __privateGet$
|
|
2370
|
-
__privateGet$
|
|
2370
|
+
const externalBaseUrlStr = await __privateGet$2(this, _discovery).getExternalBaseUrl(
|
|
2371
|
+
__privateGet$2(this, _pluginId)
|
|
2371
2372
|
);
|
|
2372
2373
|
const externalBaseUrl = new URL(origin != null ? origin : externalBaseUrlStr);
|
|
2373
|
-
const { token, expiresAt } = await __privateGet$
|
|
2374
|
+
const { token, expiresAt } = await __privateGet$2(this, _auth).getLimitedUserToken(
|
|
2374
2375
|
credentials
|
|
2375
2376
|
);
|
|
2376
2377
|
if (!token) {
|
|
@@ -2395,35 +2396,35 @@ _extractCredentialsFromRequest = new WeakSet();
|
|
|
2395
2396
|
extractCredentialsFromRequest_fn = async function(req) {
|
|
2396
2397
|
const token = getTokenFromRequest(req);
|
|
2397
2398
|
if (!token) {
|
|
2398
|
-
return await __privateGet$
|
|
2399
|
+
return await __privateGet$2(this, _auth).getNoneCredentials();
|
|
2399
2400
|
}
|
|
2400
|
-
return await __privateGet$
|
|
2401
|
+
return await __privateGet$2(this, _auth).authenticate(token);
|
|
2401
2402
|
};
|
|
2402
2403
|
_extractLimitedCredentialsFromRequest = new WeakSet();
|
|
2403
2404
|
extractLimitedCredentialsFromRequest_fn = async function(req) {
|
|
2404
2405
|
const token = getTokenFromRequest(req);
|
|
2405
2406
|
if (token) {
|
|
2406
|
-
return await __privateGet$
|
|
2407
|
+
return await __privateGet$2(this, _auth).authenticate(token, {
|
|
2407
2408
|
allowLimitedAccess: true
|
|
2408
2409
|
});
|
|
2409
2410
|
}
|
|
2410
2411
|
const cookie = getCookieFromRequest(req);
|
|
2411
2412
|
if (cookie) {
|
|
2412
|
-
return await __privateGet$
|
|
2413
|
+
return await __privateGet$2(this, _auth).authenticate(cookie, {
|
|
2413
2414
|
allowLimitedAccess: true
|
|
2414
2415
|
});
|
|
2415
2416
|
}
|
|
2416
|
-
return await __privateGet$
|
|
2417
|
+
return await __privateGet$2(this, _auth).getNoneCredentials();
|
|
2417
2418
|
};
|
|
2418
2419
|
_getCredentials = new WeakSet();
|
|
2419
2420
|
getCredentials_fn = async function(req) {
|
|
2420
2421
|
var _a;
|
|
2421
|
-
return (_a = req[credentialsSymbol]) != null ? _a : req[credentialsSymbol] = __privateMethod$
|
|
2422
|
+
return (_a = req[credentialsSymbol]) != null ? _a : req[credentialsSymbol] = __privateMethod$2(this, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn).call(this, req);
|
|
2422
2423
|
};
|
|
2423
2424
|
_getLimitedCredentials = new WeakSet();
|
|
2424
2425
|
getLimitedCredentials_fn = async function(req) {
|
|
2425
2426
|
var _a;
|
|
2426
|
-
return (_a = req[limitedCredentialsSymbol]) != null ? _a : req[limitedCredentialsSymbol] = __privateMethod$
|
|
2427
|
+
return (_a = req[limitedCredentialsSymbol]) != null ? _a : req[limitedCredentialsSymbol] = __privateMethod$2(this, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn).call(this, req);
|
|
2427
2428
|
};
|
|
2428
2429
|
_existingCookieExpiration = new WeakSet();
|
|
2429
2430
|
existingCookieExpiration_fn = async function(req) {
|
|
@@ -2431,10 +2432,10 @@ existingCookieExpiration_fn = async function(req) {
|
|
|
2431
2432
|
if (!existingCookie) {
|
|
2432
2433
|
return void 0;
|
|
2433
2434
|
}
|
|
2434
|
-
const existingCredentials = await __privateGet$
|
|
2435
|
+
const existingCredentials = await __privateGet$2(this, _auth).authenticate(existingCookie, {
|
|
2435
2436
|
allowLimitedAccess: true
|
|
2436
2437
|
});
|
|
2437
|
-
if (!__privateGet$
|
|
2438
|
+
if (!__privateGet$2(this, _auth).isPrincipal(existingCredentials, "user")) {
|
|
2438
2439
|
return void 0;
|
|
2439
2440
|
}
|
|
2440
2441
|
return existingCredentials.expiresAt;
|
|
@@ -2495,6 +2496,105 @@ function createLifecycleMiddleware(options) {
|
|
|
2495
2496
|
};
|
|
2496
2497
|
}
|
|
2497
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
|
+
|
|
2498
2598
|
function createPathPolicyPredicate(policyPath) {
|
|
2499
2599
|
if (policyPath === "/" || policyPath === "*") {
|
|
2500
2600
|
return () => true;
|
|
@@ -2507,8 +2607,8 @@ function createPathPolicyPredicate(policyPath) {
|
|
|
2507
2607
|
};
|
|
2508
2608
|
}
|
|
2509
2609
|
function createCredentialsBarrier(options) {
|
|
2510
|
-
const { httpAuth, config } = options;
|
|
2511
|
-
const disableDefaultAuthPolicy = config.getOptionalBoolean(
|
|
2610
|
+
const { httpAuth, config: config$1, cache } = options;
|
|
2611
|
+
const disableDefaultAuthPolicy = config$1.getOptionalBoolean(
|
|
2512
2612
|
"backend.auth.dangerouslyDisableDefaultAuthPolicy"
|
|
2513
2613
|
);
|
|
2514
2614
|
if (disableDefaultAuthPolicy) {
|
|
@@ -2520,12 +2620,31 @@ function createCredentialsBarrier(options) {
|
|
|
2520
2620
|
}
|
|
2521
2621
|
const unauthenticatedPredicates = new Array();
|
|
2522
2622
|
const cookiePredicates = new Array();
|
|
2523
|
-
const
|
|
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) => {
|
|
2524
2643
|
const allowsUnauthenticated = unauthenticatedPredicates.some(
|
|
2525
2644
|
(predicate) => predicate(req.path)
|
|
2526
2645
|
);
|
|
2527
2646
|
if (allowsUnauthenticated) {
|
|
2528
|
-
next
|
|
2647
|
+
limiter(req, res, next);
|
|
2529
2648
|
return;
|
|
2530
2649
|
}
|
|
2531
2650
|
const allowsCookie = cookiePredicates.some(
|
|
@@ -2555,19 +2674,31 @@ const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
|
|
|
2555
2674
|
(options) => ({
|
|
2556
2675
|
service: backendPluginApi.coreServices.httpRouter,
|
|
2557
2676
|
deps: {
|
|
2677
|
+
cache: backendPluginApi.coreServices.cache,
|
|
2558
2678
|
plugin: backendPluginApi.coreServices.pluginMetadata,
|
|
2559
2679
|
config: backendPluginApi.coreServices.rootConfig,
|
|
2560
2680
|
lifecycle: backendPluginApi.coreServices.lifecycle,
|
|
2561
2681
|
rootHttpRouter: backendPluginApi.coreServices.rootHttpRouter,
|
|
2562
2682
|
httpAuth: backendPluginApi.coreServices.httpAuth
|
|
2563
2683
|
},
|
|
2564
|
-
async factory({
|
|
2684
|
+
async factory({
|
|
2685
|
+
httpAuth,
|
|
2686
|
+
config,
|
|
2687
|
+
cache,
|
|
2688
|
+
plugin,
|
|
2689
|
+
rootHttpRouter,
|
|
2690
|
+
lifecycle
|
|
2691
|
+
}) {
|
|
2565
2692
|
var _a;
|
|
2566
2693
|
const getPath = (_a = options == null ? void 0 : options.getPath) != null ? _a : (id) => `/api/${id}`;
|
|
2567
2694
|
const path = getPath(plugin.getId());
|
|
2568
2695
|
const router = PromiseRouter__default["default"]();
|
|
2569
2696
|
rootHttpRouter.use(path, router);
|
|
2570
|
-
const credentialsBarrier = createCredentialsBarrier({
|
|
2697
|
+
const credentialsBarrier = createCredentialsBarrier({
|
|
2698
|
+
httpAuth,
|
|
2699
|
+
config,
|
|
2700
|
+
cache
|
|
2701
|
+
});
|
|
2571
2702
|
router.use(createLifecycleMiddleware({ lifecycle }));
|
|
2572
2703
|
router.use(credentialsBarrier.middleware);
|
|
2573
2704
|
return {
|