@backstage/backend-app-api 0.6.0 → 0.6.2
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 +36 -0
- package/alpha/package.json +1 -1
- package/config.d.ts +0 -19
- package/dist/alpha.cjs.js +3 -5
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/index.cjs.js +281 -414
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +8 -9
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var path = require('path');
|
|
6
4
|
var parseArgs = require('minimist');
|
|
7
5
|
var cliCommon = require('@backstage/cli-common');
|
|
@@ -30,17 +28,16 @@ var cookie = require('cookie');
|
|
|
30
28
|
var PromiseRouter = require('express-promise-router');
|
|
31
29
|
var types = require('@backstage/types');
|
|
32
30
|
var pathToRegexp = require('path-to-regexp');
|
|
33
|
-
var expressRateLimit = require('express-rate-limit');
|
|
34
31
|
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
35
32
|
var pluginPermissionNode = require('@backstage/plugin-permission-node');
|
|
36
33
|
var express = require('express');
|
|
37
34
|
var trimEnd = require('lodash/trimEnd');
|
|
38
35
|
var backendTasks = require('@backstage/backend-tasks');
|
|
39
36
|
|
|
40
|
-
function
|
|
37
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
41
38
|
|
|
42
|
-
function
|
|
43
|
-
if (e && e
|
|
39
|
+
function _interopNamespaceCompat(e) {
|
|
40
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
44
41
|
var n = Object.create(null);
|
|
45
42
|
if (e) {
|
|
46
43
|
Object.keys(e).forEach(function (k) {
|
|
@@ -53,36 +50,36 @@ function _interopNamespace(e) {
|
|
|
53
50
|
}
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
|
-
n
|
|
53
|
+
n.default = e;
|
|
57
54
|
return Object.freeze(n);
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
var parseArgs__default = /*#__PURE__*/
|
|
61
|
-
var http__namespace = /*#__PURE__*/
|
|
62
|
-
var https__namespace = /*#__PURE__*/
|
|
63
|
-
var stoppableServer__default = /*#__PURE__*/
|
|
64
|
-
var fs__default = /*#__PURE__*/
|
|
65
|
-
var forge__default = /*#__PURE__*/
|
|
66
|
-
var cors__default = /*#__PURE__*/
|
|
67
|
-
var helmet__default = /*#__PURE__*/
|
|
68
|
-
var morgan__default = /*#__PURE__*/
|
|
69
|
-
var compression__default = /*#__PURE__*/
|
|
70
|
-
var PromiseRouter__default = /*#__PURE__*/
|
|
71
|
-
var express__default = /*#__PURE__*/
|
|
72
|
-
var trimEnd__default = /*#__PURE__*/
|
|
57
|
+
var parseArgs__default = /*#__PURE__*/_interopDefaultCompat(parseArgs);
|
|
58
|
+
var http__namespace = /*#__PURE__*/_interopNamespaceCompat(http);
|
|
59
|
+
var https__namespace = /*#__PURE__*/_interopNamespaceCompat(https);
|
|
60
|
+
var stoppableServer__default = /*#__PURE__*/_interopDefaultCompat(stoppableServer);
|
|
61
|
+
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
62
|
+
var forge__default = /*#__PURE__*/_interopDefaultCompat(forge);
|
|
63
|
+
var cors__default = /*#__PURE__*/_interopDefaultCompat(cors);
|
|
64
|
+
var helmet__default = /*#__PURE__*/_interopDefaultCompat(helmet);
|
|
65
|
+
var morgan__default = /*#__PURE__*/_interopDefaultCompat(morgan);
|
|
66
|
+
var compression__default = /*#__PURE__*/_interopDefaultCompat(compression);
|
|
67
|
+
var PromiseRouter__default = /*#__PURE__*/_interopDefaultCompat(PromiseRouter);
|
|
68
|
+
var express__default = /*#__PURE__*/_interopDefaultCompat(express);
|
|
69
|
+
var trimEnd__default = /*#__PURE__*/_interopDefaultCompat(trimEnd);
|
|
73
70
|
|
|
74
|
-
var __defProp
|
|
75
|
-
var __defNormalProp
|
|
76
|
-
var __publicField
|
|
77
|
-
__defNormalProp
|
|
71
|
+
var __defProp = Object.defineProperty;
|
|
72
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
73
|
+
var __publicField = (obj, key, value) => {
|
|
74
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
78
75
|
return value;
|
|
79
76
|
};
|
|
80
77
|
class ObservableConfigProxy {
|
|
81
78
|
constructor(parent, parentKey) {
|
|
82
79
|
this.parent = parent;
|
|
83
80
|
this.parentKey = parentKey;
|
|
84
|
-
__publicField
|
|
85
|
-
__publicField
|
|
81
|
+
__publicField(this, "config", new config.ConfigReader({}));
|
|
82
|
+
__publicField(this, "subscribers", []);
|
|
86
83
|
if (parent && !parentKey) {
|
|
87
84
|
throw new Error("parentKey is required if parent is set");
|
|
88
85
|
}
|
|
@@ -224,7 +221,7 @@ async function createConfigSecretEnumerator(options) {
|
|
|
224
221
|
}
|
|
225
222
|
async function loadBackendConfig(options) {
|
|
226
223
|
var _a, _b;
|
|
227
|
-
const args = parseArgs__default
|
|
224
|
+
const args = parseArgs__default.default(options.argv);
|
|
228
225
|
const configTargets = [(_a = args.config) != null ? _a : []].flat().map((arg) => isValidUrl(arg) ? { url: arg } : { path: path.resolve(arg) });
|
|
229
226
|
const paths = cliCommon.findPaths(__dirname);
|
|
230
227
|
let currentCancelFunc = void 0;
|
|
@@ -330,20 +327,20 @@ function readHttpsOptions(config) {
|
|
|
330
327
|
const FIVE_DAYS_IN_MS = 5 * 24 * 60 * 60 * 1e3;
|
|
331
328
|
const IP_HOSTNAME_REGEX = /:|^\d+\.\d+\.\d+\.\d+$/;
|
|
332
329
|
async function getGeneratedCertificate(hostname, logger) {
|
|
333
|
-
const hasModules = await fs__default
|
|
330
|
+
const hasModules = await fs__default.default.pathExists("node_modules");
|
|
334
331
|
let certPath;
|
|
335
332
|
if (hasModules) {
|
|
336
333
|
certPath = path.resolve(
|
|
337
334
|
"node_modules/.cache/backstage-backend/dev-cert.pem"
|
|
338
335
|
);
|
|
339
|
-
await fs__default
|
|
336
|
+
await fs__default.default.ensureDir(path.dirname(certPath));
|
|
340
337
|
} else {
|
|
341
338
|
certPath = path.resolve(".dev-cert.pem");
|
|
342
339
|
}
|
|
343
|
-
if (await fs__default
|
|
340
|
+
if (await fs__default.default.pathExists(certPath)) {
|
|
344
341
|
try {
|
|
345
|
-
const cert = await fs__default
|
|
346
|
-
const crt = forge__default
|
|
342
|
+
const cert = await fs__default.default.readFile(certPath);
|
|
343
|
+
const crt = forge__default.default.pki.certificateFromPem(cert.toString());
|
|
347
344
|
const remainingMs = crt.validity.notAfter.getTime() - Date.now();
|
|
348
345
|
if (remainingMs > FIVE_DAYS_IN_MS) {
|
|
349
346
|
logger.info("Using existing self-signed certificate");
|
|
@@ -358,7 +355,7 @@ async function getGeneratedCertificate(hostname, logger) {
|
|
|
358
355
|
}
|
|
359
356
|
logger.info("Generating new self-signed certificate");
|
|
360
357
|
const newCert = await generateCertificate(hostname);
|
|
361
|
-
await fs__default
|
|
358
|
+
await fs__default.default.writeFile(certPath, newCert.cert + newCert.key, "utf8");
|
|
362
359
|
return newCert;
|
|
363
360
|
}
|
|
364
361
|
async function generateCertificate(hostname) {
|
|
@@ -446,7 +443,7 @@ async function generateCertificate(hostname) {
|
|
|
446
443
|
|
|
447
444
|
async function createHttpServer(listener, options, deps) {
|
|
448
445
|
const server = await createServer(listener, options, deps);
|
|
449
|
-
const stopper = stoppableServer__default
|
|
446
|
+
const stopper = stoppableServer__default.default(server, 0);
|
|
450
447
|
const stopServer = stopper.stop.bind(stopper);
|
|
451
448
|
return Object.assign(server, {
|
|
452
449
|
start() {
|
|
@@ -532,7 +529,7 @@ function readCspDirectives(config) {
|
|
|
532
529
|
return result;
|
|
533
530
|
}
|
|
534
531
|
function applyCspDirectives(directives) {
|
|
535
|
-
const result = helmet__default
|
|
532
|
+
const result = helmet__default.default.contentSecurityPolicy.getDefaultDirectives();
|
|
536
533
|
result["script-src"] = ["'self'", "'unsafe-eval'"];
|
|
537
534
|
delete result["form-action"];
|
|
538
535
|
if (directives) {
|
|
@@ -613,31 +610,31 @@ function applyInternalErrorFilter(error, logger) {
|
|
|
613
610
|
return error;
|
|
614
611
|
}
|
|
615
612
|
|
|
616
|
-
var __accessCheck$
|
|
613
|
+
var __accessCheck$a = (obj, member, msg) => {
|
|
617
614
|
if (!member.has(obj))
|
|
618
615
|
throw TypeError("Cannot " + msg);
|
|
619
616
|
};
|
|
620
|
-
var __privateGet$
|
|
621
|
-
__accessCheck$
|
|
617
|
+
var __privateGet$9 = (obj, member, getter) => {
|
|
618
|
+
__accessCheck$a(obj, member, "read from private field");
|
|
622
619
|
return getter ? getter.call(obj) : member.get(obj);
|
|
623
620
|
};
|
|
624
|
-
var __privateAdd$
|
|
621
|
+
var __privateAdd$a = (obj, member, value) => {
|
|
625
622
|
if (member.has(obj))
|
|
626
623
|
throw TypeError("Cannot add the same private member more than once");
|
|
627
624
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
628
625
|
};
|
|
629
|
-
var __privateSet$
|
|
630
|
-
__accessCheck$
|
|
626
|
+
var __privateSet$9 = (obj, member, value, setter) => {
|
|
627
|
+
__accessCheck$a(obj, member, "write to private field");
|
|
631
628
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
632
629
|
return value;
|
|
633
630
|
};
|
|
634
631
|
var _config, _logger;
|
|
635
632
|
const _MiddlewareFactory = class _MiddlewareFactory {
|
|
636
633
|
constructor(options) {
|
|
637
|
-
__privateAdd$
|
|
638
|
-
__privateAdd$
|
|
639
|
-
__privateSet$
|
|
640
|
-
__privateSet$
|
|
634
|
+
__privateAdd$a(this, _config, void 0);
|
|
635
|
+
__privateAdd$a(this, _logger, void 0);
|
|
636
|
+
__privateSet$9(this, _config, options.config);
|
|
637
|
+
__privateSet$9(this, _logger, options.logger);
|
|
641
638
|
}
|
|
642
639
|
/**
|
|
643
640
|
* Creates a new {@link MiddlewareFactory}.
|
|
@@ -669,7 +666,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
|
|
|
669
666
|
* that traverse through the middleware.
|
|
670
667
|
*/
|
|
671
668
|
compression() {
|
|
672
|
-
return compression__default
|
|
669
|
+
return compression__default.default();
|
|
673
670
|
}
|
|
674
671
|
/**
|
|
675
672
|
* Returns a request logging middleware.
|
|
@@ -683,10 +680,10 @@ const _MiddlewareFactory = class _MiddlewareFactory {
|
|
|
683
680
|
* @returns An Express request handler
|
|
684
681
|
*/
|
|
685
682
|
logging() {
|
|
686
|
-
const logger = __privateGet$
|
|
683
|
+
const logger = __privateGet$9(this, _logger).child({
|
|
687
684
|
type: "incomingRequest"
|
|
688
685
|
});
|
|
689
|
-
return morgan__default
|
|
686
|
+
return morgan__default.default("combined", {
|
|
690
687
|
stream: {
|
|
691
688
|
write(message) {
|
|
692
689
|
logger.info(message.trimEnd());
|
|
@@ -707,7 +704,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
|
|
|
707
704
|
* @returns An Express request handler
|
|
708
705
|
*/
|
|
709
706
|
helmet() {
|
|
710
|
-
return helmet__default
|
|
707
|
+
return helmet__default.default(readHelmetOptions(__privateGet$9(this, _config).getOptionalConfig("backend")));
|
|
711
708
|
}
|
|
712
709
|
/**
|
|
713
710
|
* Returns a middleware that implements the cors library.
|
|
@@ -722,7 +719,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
|
|
|
722
719
|
* @returns An Express request handler
|
|
723
720
|
*/
|
|
724
721
|
cors() {
|
|
725
|
-
return cors__default
|
|
722
|
+
return cors__default.default(readCorsOptions(__privateGet$9(this, _config).getOptionalConfig("backend")));
|
|
726
723
|
}
|
|
727
724
|
/**
|
|
728
725
|
* Express middleware to handle errors during request processing.
|
|
@@ -747,7 +744,7 @@ const _MiddlewareFactory = class _MiddlewareFactory {
|
|
|
747
744
|
error(options = {}) {
|
|
748
745
|
var _a;
|
|
749
746
|
const showStackTraces = (_a = options.showStackTraces) != null ? _a : process.env.NODE_ENV === "development";
|
|
750
|
-
const logger = __privateGet$
|
|
747
|
+
const logger = __privateGet$9(this, _logger).child({
|
|
751
748
|
type: "errorHandler"
|
|
752
749
|
});
|
|
753
750
|
return (rawError, req, res, next) => {
|
|
@@ -806,31 +803,31 @@ const escapeRegExp = (text) => {
|
|
|
806
803
|
return text.replace(/[.*+?^${}(\)|[\]\\]/g, "\\$&");
|
|
807
804
|
};
|
|
808
805
|
|
|
809
|
-
var __accessCheck$
|
|
806
|
+
var __accessCheck$9 = (obj, member, msg) => {
|
|
810
807
|
if (!member.has(obj))
|
|
811
808
|
throw TypeError("Cannot " + msg);
|
|
812
809
|
};
|
|
813
|
-
var __privateGet$
|
|
814
|
-
__accessCheck$
|
|
810
|
+
var __privateGet$8 = (obj, member, getter) => {
|
|
811
|
+
__accessCheck$9(obj, member, "read from private field");
|
|
815
812
|
return getter ? getter.call(obj) : member.get(obj);
|
|
816
813
|
};
|
|
817
|
-
var __privateAdd$
|
|
814
|
+
var __privateAdd$9 = (obj, member, value) => {
|
|
818
815
|
if (member.has(obj))
|
|
819
816
|
throw TypeError("Cannot add the same private member more than once");
|
|
820
817
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
821
818
|
};
|
|
822
|
-
var __privateSet$
|
|
823
|
-
__accessCheck$
|
|
819
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
|
820
|
+
__accessCheck$9(obj, member, "write to private field");
|
|
824
821
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
825
822
|
return value;
|
|
826
823
|
};
|
|
827
824
|
var _winston, _addRedactions;
|
|
828
825
|
const _WinstonLogger = class _WinstonLogger {
|
|
829
826
|
constructor(winston, addRedactions) {
|
|
830
|
-
__privateAdd$
|
|
831
|
-
__privateAdd$
|
|
832
|
-
__privateSet$
|
|
833
|
-
__privateSet$
|
|
827
|
+
__privateAdd$9(this, _winston, void 0);
|
|
828
|
+
__privateAdd$9(this, _addRedactions, void 0);
|
|
829
|
+
__privateSet$8(this, _winston, winston);
|
|
830
|
+
__privateSet$8(this, _addRedactions, addRedactions);
|
|
834
831
|
}
|
|
835
832
|
/**
|
|
836
833
|
* Creates a {@link WinstonLogger} instance.
|
|
@@ -915,44 +912,44 @@ const _WinstonLogger = class _WinstonLogger {
|
|
|
915
912
|
);
|
|
916
913
|
}
|
|
917
914
|
error(message, meta) {
|
|
918
|
-
__privateGet$
|
|
915
|
+
__privateGet$8(this, _winston).error(message, meta);
|
|
919
916
|
}
|
|
920
917
|
warn(message, meta) {
|
|
921
|
-
__privateGet$
|
|
918
|
+
__privateGet$8(this, _winston).warn(message, meta);
|
|
922
919
|
}
|
|
923
920
|
info(message, meta) {
|
|
924
|
-
__privateGet$
|
|
921
|
+
__privateGet$8(this, _winston).info(message, meta);
|
|
925
922
|
}
|
|
926
923
|
debug(message, meta) {
|
|
927
|
-
__privateGet$
|
|
924
|
+
__privateGet$8(this, _winston).debug(message, meta);
|
|
928
925
|
}
|
|
929
926
|
child(meta) {
|
|
930
|
-
return new _WinstonLogger(__privateGet$
|
|
927
|
+
return new _WinstonLogger(__privateGet$8(this, _winston).child(meta));
|
|
931
928
|
}
|
|
932
929
|
addRedactions(redactions) {
|
|
933
930
|
var _a;
|
|
934
|
-
(_a = __privateGet$
|
|
931
|
+
(_a = __privateGet$8(this, _addRedactions)) == null ? void 0 : _a.call(this, redactions);
|
|
935
932
|
}
|
|
936
933
|
};
|
|
937
934
|
_winston = new WeakMap();
|
|
938
935
|
_addRedactions = new WeakMap();
|
|
939
936
|
let WinstonLogger = _WinstonLogger;
|
|
940
937
|
|
|
941
|
-
var __accessCheck$
|
|
938
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
|
942
939
|
if (!member.has(obj))
|
|
943
940
|
throw TypeError("Cannot " + msg);
|
|
944
941
|
};
|
|
945
|
-
var __privateGet$
|
|
946
|
-
__accessCheck$
|
|
942
|
+
var __privateGet$7 = (obj, member, getter) => {
|
|
943
|
+
__accessCheck$8(obj, member, "read from private field");
|
|
947
944
|
return getter ? getter.call(obj) : member.get(obj);
|
|
948
945
|
};
|
|
949
|
-
var __privateAdd$
|
|
946
|
+
var __privateAdd$8 = (obj, member, value) => {
|
|
950
947
|
if (member.has(obj))
|
|
951
948
|
throw TypeError("Cannot add the same private member more than once");
|
|
952
949
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
953
950
|
};
|
|
954
|
-
var __privateSet$
|
|
955
|
-
__accessCheck$
|
|
951
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
|
952
|
+
__accessCheck$8(obj, member, "write to private field");
|
|
956
953
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
957
954
|
return value;
|
|
958
955
|
};
|
|
@@ -960,25 +957,25 @@ var _hasStarted$1, _startupTasks$1, _hasShutdown, _shutdownTasks;
|
|
|
960
957
|
class BackendLifecycleImpl {
|
|
961
958
|
constructor(logger) {
|
|
962
959
|
this.logger = logger;
|
|
963
|
-
__privateAdd$
|
|
964
|
-
__privateAdd$
|
|
965
|
-
__privateAdd$
|
|
966
|
-
__privateAdd$
|
|
960
|
+
__privateAdd$8(this, _hasStarted$1, false);
|
|
961
|
+
__privateAdd$8(this, _startupTasks$1, []);
|
|
962
|
+
__privateAdd$8(this, _hasShutdown, false);
|
|
963
|
+
__privateAdd$8(this, _shutdownTasks, []);
|
|
967
964
|
}
|
|
968
965
|
addStartupHook(hook, options) {
|
|
969
|
-
if (__privateGet$
|
|
966
|
+
if (__privateGet$7(this, _hasStarted$1)) {
|
|
970
967
|
throw new Error("Attempted to add startup hook after startup");
|
|
971
968
|
}
|
|
972
|
-
__privateGet$
|
|
969
|
+
__privateGet$7(this, _startupTasks$1).push({ hook, options });
|
|
973
970
|
}
|
|
974
971
|
async startup() {
|
|
975
|
-
if (__privateGet$
|
|
972
|
+
if (__privateGet$7(this, _hasStarted$1)) {
|
|
976
973
|
return;
|
|
977
974
|
}
|
|
978
|
-
__privateSet$
|
|
979
|
-
this.logger.debug(`Running ${__privateGet$
|
|
975
|
+
__privateSet$7(this, _hasStarted$1, true);
|
|
976
|
+
this.logger.debug(`Running ${__privateGet$7(this, _startupTasks$1).length} startup tasks...`);
|
|
980
977
|
await Promise.all(
|
|
981
|
-
__privateGet$
|
|
978
|
+
__privateGet$7(this, _startupTasks$1).map(async ({ hook, options }) => {
|
|
982
979
|
var _a;
|
|
983
980
|
const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
|
|
984
981
|
try {
|
|
@@ -991,21 +988,21 @@ class BackendLifecycleImpl {
|
|
|
991
988
|
);
|
|
992
989
|
}
|
|
993
990
|
addShutdownHook(hook, options) {
|
|
994
|
-
if (__privateGet$
|
|
991
|
+
if (__privateGet$7(this, _hasShutdown)) {
|
|
995
992
|
throw new Error("Attempted to add shutdown hook after shutdown");
|
|
996
993
|
}
|
|
997
|
-
__privateGet$
|
|
994
|
+
__privateGet$7(this, _shutdownTasks).push({ hook, options });
|
|
998
995
|
}
|
|
999
996
|
async shutdown() {
|
|
1000
|
-
if (__privateGet$
|
|
997
|
+
if (__privateGet$7(this, _hasShutdown)) {
|
|
1001
998
|
return;
|
|
1002
999
|
}
|
|
1003
|
-
__privateSet$
|
|
1000
|
+
__privateSet$7(this, _hasShutdown, true);
|
|
1004
1001
|
this.logger.debug(
|
|
1005
|
-
`Running ${__privateGet$
|
|
1002
|
+
`Running ${__privateGet$7(this, _shutdownTasks).length} shutdown tasks...`
|
|
1006
1003
|
);
|
|
1007
1004
|
await Promise.all(
|
|
1008
|
-
__privateGet$
|
|
1005
|
+
__privateGet$7(this, _shutdownTasks).map(async ({ hook, options }) => {
|
|
1009
1006
|
var _a;
|
|
1010
1007
|
const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
|
|
1011
1008
|
try {
|
|
@@ -1032,21 +1029,21 @@ const rootLifecycleServiceFactory = backendPluginApi.createServiceFactory({
|
|
|
1032
1029
|
}
|
|
1033
1030
|
});
|
|
1034
1031
|
|
|
1035
|
-
var __accessCheck$
|
|
1032
|
+
var __accessCheck$7 = (obj, member, msg) => {
|
|
1036
1033
|
if (!member.has(obj))
|
|
1037
1034
|
throw TypeError("Cannot " + msg);
|
|
1038
1035
|
};
|
|
1039
|
-
var __privateGet$
|
|
1040
|
-
__accessCheck$
|
|
1036
|
+
var __privateGet$6 = (obj, member, getter) => {
|
|
1037
|
+
__accessCheck$7(obj, member, "read from private field");
|
|
1041
1038
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1042
1039
|
};
|
|
1043
|
-
var __privateAdd$
|
|
1040
|
+
var __privateAdd$7 = (obj, member, value) => {
|
|
1044
1041
|
if (member.has(obj))
|
|
1045
1042
|
throw TypeError("Cannot add the same private member more than once");
|
|
1046
1043
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1047
1044
|
};
|
|
1048
|
-
var __privateSet$
|
|
1049
|
-
__accessCheck$
|
|
1045
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
|
1046
|
+
__accessCheck$7(obj, member, "write to private field");
|
|
1050
1047
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1051
1048
|
return value;
|
|
1052
1049
|
};
|
|
@@ -1056,25 +1053,25 @@ class BackendPluginLifecycleImpl {
|
|
|
1056
1053
|
this.logger = logger;
|
|
1057
1054
|
this.rootLifecycle = rootLifecycle;
|
|
1058
1055
|
this.pluginMetadata = pluginMetadata;
|
|
1059
|
-
__privateAdd$
|
|
1060
|
-
__privateAdd$
|
|
1056
|
+
__privateAdd$7(this, _hasStarted, false);
|
|
1057
|
+
__privateAdd$7(this, _startupTasks, []);
|
|
1061
1058
|
}
|
|
1062
1059
|
addStartupHook(hook, options) {
|
|
1063
|
-
if (__privateGet$
|
|
1060
|
+
if (__privateGet$6(this, _hasStarted)) {
|
|
1064
1061
|
throw new Error("Attempted to add startup hook after startup");
|
|
1065
1062
|
}
|
|
1066
|
-
__privateGet$
|
|
1063
|
+
__privateGet$6(this, _startupTasks).push({ hook, options });
|
|
1067
1064
|
}
|
|
1068
1065
|
async startup() {
|
|
1069
|
-
if (__privateGet$
|
|
1066
|
+
if (__privateGet$6(this, _hasStarted)) {
|
|
1070
1067
|
return;
|
|
1071
1068
|
}
|
|
1072
|
-
__privateSet$
|
|
1069
|
+
__privateSet$6(this, _hasStarted, true);
|
|
1073
1070
|
this.logger.debug(
|
|
1074
|
-
`Running ${__privateGet$
|
|
1071
|
+
`Running ${__privateGet$6(this, _startupTasks).length} plugin startup tasks...`
|
|
1075
1072
|
);
|
|
1076
1073
|
await Promise.all(
|
|
1077
|
-
__privateGet$
|
|
1074
|
+
__privateGet$6(this, _startupTasks).map(async ({ hook, options }) => {
|
|
1078
1075
|
var _a;
|
|
1079
1076
|
const logger = (_a = options == null ? void 0 : options.logger) != null ? _a : this.logger;
|
|
1080
1077
|
try {
|
|
@@ -1112,26 +1109,26 @@ const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
|
|
|
1112
1109
|
}
|
|
1113
1110
|
});
|
|
1114
1111
|
|
|
1115
|
-
var __accessCheck$
|
|
1112
|
+
var __accessCheck$6 = (obj, member, msg) => {
|
|
1116
1113
|
if (!member.has(obj))
|
|
1117
1114
|
throw TypeError("Cannot " + msg);
|
|
1118
1115
|
};
|
|
1119
|
-
var __privateGet$
|
|
1120
|
-
__accessCheck$
|
|
1116
|
+
var __privateGet$5 = (obj, member, getter) => {
|
|
1117
|
+
__accessCheck$6(obj, member, "read from private field");
|
|
1121
1118
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1122
1119
|
};
|
|
1123
|
-
var __privateAdd$
|
|
1120
|
+
var __privateAdd$6 = (obj, member, value) => {
|
|
1124
1121
|
if (member.has(obj))
|
|
1125
1122
|
throw TypeError("Cannot add the same private member more than once");
|
|
1126
1123
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1127
1124
|
};
|
|
1128
|
-
var __privateSet$
|
|
1129
|
-
__accessCheck$
|
|
1125
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
|
1126
|
+
__accessCheck$6(obj, member, "write to private field");
|
|
1130
1127
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1131
1128
|
return value;
|
|
1132
1129
|
};
|
|
1133
|
-
var __privateMethod$
|
|
1134
|
-
__accessCheck$
|
|
1130
|
+
var __privateMethod$5 = (obj, member, method) => {
|
|
1131
|
+
__accessCheck$6(obj, member, "access private method");
|
|
1135
1132
|
return method;
|
|
1136
1133
|
};
|
|
1137
1134
|
var _nodeIds, _cycleKeys, _getCycleKey, getCycleKey_fn, _nodes, _allProvided;
|
|
@@ -1151,21 +1148,21 @@ class Node {
|
|
|
1151
1148
|
}
|
|
1152
1149
|
const _CycleKeySet = class _CycleKeySet {
|
|
1153
1150
|
constructor(nodes) {
|
|
1154
|
-
__privateAdd$
|
|
1155
|
-
__privateAdd$
|
|
1156
|
-
__privateAdd$
|
|
1157
|
-
__privateSet$
|
|
1158
|
-
__privateSet$
|
|
1151
|
+
__privateAdd$6(this, _getCycleKey);
|
|
1152
|
+
__privateAdd$6(this, _nodeIds, void 0);
|
|
1153
|
+
__privateAdd$6(this, _cycleKeys, void 0);
|
|
1154
|
+
__privateSet$5(this, _nodeIds, new Map(nodes.map((n, i) => [n.value, i])));
|
|
1155
|
+
__privateSet$5(this, _cycleKeys, /* @__PURE__ */ new Set());
|
|
1159
1156
|
}
|
|
1160
1157
|
static from(nodes) {
|
|
1161
1158
|
return new _CycleKeySet(nodes);
|
|
1162
1159
|
}
|
|
1163
1160
|
tryAdd(path) {
|
|
1164
|
-
const cycleKey = __privateMethod$
|
|
1165
|
-
if (__privateGet$
|
|
1161
|
+
const cycleKey = __privateMethod$5(this, _getCycleKey, getCycleKey_fn).call(this, path);
|
|
1162
|
+
if (__privateGet$5(this, _cycleKeys).has(cycleKey)) {
|
|
1166
1163
|
return false;
|
|
1167
1164
|
}
|
|
1168
|
-
__privateGet$
|
|
1165
|
+
__privateGet$5(this, _cycleKeys).add(cycleKey);
|
|
1169
1166
|
return true;
|
|
1170
1167
|
}
|
|
1171
1168
|
};
|
|
@@ -1173,18 +1170,18 @@ _nodeIds = new WeakMap();
|
|
|
1173
1170
|
_cycleKeys = new WeakMap();
|
|
1174
1171
|
_getCycleKey = new WeakSet();
|
|
1175
1172
|
getCycleKey_fn = function(path) {
|
|
1176
|
-
return path.map((n) => __privateGet$
|
|
1173
|
+
return path.map((n) => __privateGet$5(this, _nodeIds).get(n)).sort().join(",");
|
|
1177
1174
|
};
|
|
1178
1175
|
let CycleKeySet = _CycleKeySet;
|
|
1179
1176
|
const _DependencyGraph = class _DependencyGraph {
|
|
1180
1177
|
constructor(nodes) {
|
|
1181
|
-
__privateAdd$
|
|
1182
|
-
__privateAdd$
|
|
1183
|
-
__privateSet$
|
|
1184
|
-
__privateSet$
|
|
1185
|
-
for (const node of __privateGet$
|
|
1178
|
+
__privateAdd$6(this, _nodes, void 0);
|
|
1179
|
+
__privateAdd$6(this, _allProvided, void 0);
|
|
1180
|
+
__privateSet$5(this, _nodes, nodes);
|
|
1181
|
+
__privateSet$5(this, _allProvided, /* @__PURE__ */ new Set());
|
|
1182
|
+
for (const node of __privateGet$5(this, _nodes).values()) {
|
|
1186
1183
|
for (const produced of node.provides) {
|
|
1187
|
-
__privateGet$
|
|
1184
|
+
__privateGet$5(this, _allProvided).add(produced);
|
|
1188
1185
|
}
|
|
1189
1186
|
}
|
|
1190
1187
|
}
|
|
@@ -1208,9 +1205,9 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1208
1205
|
*/
|
|
1209
1206
|
findUnsatisfiedDeps() {
|
|
1210
1207
|
const unsatisfiedDependencies = [];
|
|
1211
|
-
for (const node of __privateGet$
|
|
1208
|
+
for (const node of __privateGet$5(this, _nodes).values()) {
|
|
1212
1209
|
const unsatisfied = Array.from(node.consumes).filter(
|
|
1213
|
-
(id) => !__privateGet$
|
|
1210
|
+
(id) => !__privateGet$5(this, _allProvided).has(id)
|
|
1214
1211
|
);
|
|
1215
1212
|
if (unsatisfied.length > 0) {
|
|
1216
1213
|
unsatisfiedDependencies.push({ value: node.value, unsatisfied });
|
|
@@ -1230,8 +1227,8 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1230
1227
|
* form a cycle, with the same node as the first and last element of the array.
|
|
1231
1228
|
*/
|
|
1232
1229
|
*detectCircularDependencies() {
|
|
1233
|
-
const cycleKeys = CycleKeySet.from(__privateGet$
|
|
1234
|
-
for (const startNode of __privateGet$
|
|
1230
|
+
const cycleKeys = CycleKeySet.from(__privateGet$5(this, _nodes));
|
|
1231
|
+
for (const startNode of __privateGet$5(this, _nodes)) {
|
|
1235
1232
|
const visited = /* @__PURE__ */ new Set();
|
|
1236
1233
|
const stack = new Array([
|
|
1237
1234
|
startNode,
|
|
@@ -1244,7 +1241,7 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1244
1241
|
}
|
|
1245
1242
|
visited.add(node);
|
|
1246
1243
|
for (const consumed of node.consumes) {
|
|
1247
|
-
const providerNodes = __privateGet$
|
|
1244
|
+
const providerNodes = __privateGet$5(this, _nodes).filter(
|
|
1248
1245
|
(other) => other.provides.has(consumed)
|
|
1249
1246
|
);
|
|
1250
1247
|
for (const provider of providerNodes) {
|
|
@@ -1273,9 +1270,9 @@ const _DependencyGraph = class _DependencyGraph {
|
|
|
1273
1270
|
* Dependencies of nodes that are not produced by any other nodes will be ignored.
|
|
1274
1271
|
*/
|
|
1275
1272
|
async parallelTopologicalTraversal(fn) {
|
|
1276
|
-
const allProvided = __privateGet$
|
|
1273
|
+
const allProvided = __privateGet$5(this, _allProvided);
|
|
1277
1274
|
const producedSoFar = /* @__PURE__ */ new Set();
|
|
1278
|
-
const waiting = new Set(__privateGet$
|
|
1275
|
+
const waiting = new Set(__privateGet$5(this, _nodes).values());
|
|
1279
1276
|
const visited = /* @__PURE__ */ new Set();
|
|
1280
1277
|
const results = new Array();
|
|
1281
1278
|
let inFlight = 0;
|
|
@@ -1321,26 +1318,26 @@ _nodes = new WeakMap();
|
|
|
1321
1318
|
_allProvided = new WeakMap();
|
|
1322
1319
|
let DependencyGraph = _DependencyGraph;
|
|
1323
1320
|
|
|
1324
|
-
var __accessCheck$
|
|
1321
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
|
1325
1322
|
if (!member.has(obj))
|
|
1326
1323
|
throw TypeError("Cannot " + msg);
|
|
1327
1324
|
};
|
|
1328
|
-
var __privateGet$
|
|
1329
|
-
__accessCheck$
|
|
1325
|
+
var __privateGet$4 = (obj, member, getter) => {
|
|
1326
|
+
__accessCheck$5(obj, member, "read from private field");
|
|
1330
1327
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1331
1328
|
};
|
|
1332
|
-
var __privateAdd$
|
|
1329
|
+
var __privateAdd$5 = (obj, member, value) => {
|
|
1333
1330
|
if (member.has(obj))
|
|
1334
1331
|
throw TypeError("Cannot add the same private member more than once");
|
|
1335
1332
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1336
1333
|
};
|
|
1337
|
-
var __privateSet$
|
|
1338
|
-
__accessCheck$
|
|
1334
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
|
1335
|
+
__accessCheck$5(obj, member, "write to private field");
|
|
1339
1336
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1340
1337
|
return value;
|
|
1341
1338
|
};
|
|
1342
|
-
var __privateMethod$
|
|
1343
|
-
__accessCheck$
|
|
1339
|
+
var __privateMethod$4 = (obj, member, method) => {
|
|
1340
|
+
__accessCheck$5(obj, member, "access private method");
|
|
1344
1341
|
return method;
|
|
1345
1342
|
};
|
|
1346
1343
|
var _providedFactories, _loadedDefaultFactories, _implementations, _rootServiceImplementations, _addedFactoryIds, _instantiatedFactories, _resolveFactory, resolveFactory_fn, _checkForMissingDeps, checkForMissingDeps_fn;
|
|
@@ -1363,19 +1360,19 @@ const pluginMetadataServiceFactory = backendPluginApi.createServiceFactory(
|
|
|
1363
1360
|
);
|
|
1364
1361
|
const _ServiceRegistry = class _ServiceRegistry {
|
|
1365
1362
|
constructor(factories) {
|
|
1366
|
-
__privateAdd$
|
|
1367
|
-
__privateAdd$
|
|
1368
|
-
__privateAdd$
|
|
1369
|
-
__privateAdd$
|
|
1370
|
-
__privateAdd$
|
|
1371
|
-
__privateAdd$
|
|
1372
|
-
__privateAdd$
|
|
1373
|
-
__privateAdd$
|
|
1374
|
-
__privateSet$
|
|
1363
|
+
__privateAdd$5(this, _resolveFactory);
|
|
1364
|
+
__privateAdd$5(this, _checkForMissingDeps);
|
|
1365
|
+
__privateAdd$5(this, _providedFactories, void 0);
|
|
1366
|
+
__privateAdd$5(this, _loadedDefaultFactories, void 0);
|
|
1367
|
+
__privateAdd$5(this, _implementations, void 0);
|
|
1368
|
+
__privateAdd$5(this, _rootServiceImplementations, /* @__PURE__ */ new Map());
|
|
1369
|
+
__privateAdd$5(this, _addedFactoryIds, /* @__PURE__ */ new Set());
|
|
1370
|
+
__privateAdd$5(this, _instantiatedFactories, /* @__PURE__ */ new Set());
|
|
1371
|
+
__privateSet$4(this, _providedFactories, new Map(
|
|
1375
1372
|
factories.map((sf) => [sf.service.id, toInternalServiceFactory(sf)])
|
|
1376
1373
|
));
|
|
1377
|
-
__privateSet$
|
|
1378
|
-
__privateSet$
|
|
1374
|
+
__privateSet$4(this, _loadedDefaultFactories, /* @__PURE__ */ new Map());
|
|
1375
|
+
__privateSet$4(this, _implementations, /* @__PURE__ */ new Map());
|
|
1379
1376
|
}
|
|
1380
1377
|
static create(factories) {
|
|
1381
1378
|
const registry = new _ServiceRegistry(factories);
|
|
@@ -1384,7 +1381,7 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1384
1381
|
}
|
|
1385
1382
|
checkForCircularDeps() {
|
|
1386
1383
|
const graph = DependencyGraph.fromIterable(
|
|
1387
|
-
Array.from(__privateGet$
|
|
1384
|
+
Array.from(__privateGet$4(this, _providedFactories)).map(
|
|
1388
1385
|
([serviceId, serviceFactory]) => ({
|
|
1389
1386
|
value: serviceId,
|
|
1390
1387
|
provides: [serviceId],
|
|
@@ -1406,30 +1403,30 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1406
1403
|
`The ${backendPluginApi.coreServices.pluginMetadata.id} service cannot be overridden`
|
|
1407
1404
|
);
|
|
1408
1405
|
}
|
|
1409
|
-
if (__privateGet$
|
|
1406
|
+
if (__privateGet$4(this, _addedFactoryIds).has(factoryId)) {
|
|
1410
1407
|
throw new Error(
|
|
1411
1408
|
`Duplicate service implementations provided for ${factoryId}`
|
|
1412
1409
|
);
|
|
1413
1410
|
}
|
|
1414
|
-
if (__privateGet$
|
|
1411
|
+
if (__privateGet$4(this, _instantiatedFactories).has(factoryId)) {
|
|
1415
1412
|
throw new Error(
|
|
1416
1413
|
`Unable to set service factory with id ${factoryId}, service has already been instantiated`
|
|
1417
1414
|
);
|
|
1418
1415
|
}
|
|
1419
|
-
__privateGet$
|
|
1420
|
-
__privateGet$
|
|
1416
|
+
__privateGet$4(this, _addedFactoryIds).add(factoryId);
|
|
1417
|
+
__privateGet$4(this, _providedFactories).set(factoryId, toInternalServiceFactory(factory));
|
|
1421
1418
|
}
|
|
1422
1419
|
getServiceRefs() {
|
|
1423
|
-
return Array.from(__privateGet$
|
|
1420
|
+
return Array.from(__privateGet$4(this, _providedFactories).values()).map((f) => f.service);
|
|
1424
1421
|
}
|
|
1425
1422
|
get(ref, pluginId) {
|
|
1426
1423
|
var _a;
|
|
1427
|
-
__privateGet$
|
|
1428
|
-
return (_a = __privateMethod$
|
|
1424
|
+
__privateGet$4(this, _instantiatedFactories).add(ref.id);
|
|
1425
|
+
return (_a = __privateMethod$4(this, _resolveFactory, resolveFactory_fn).call(this, ref, pluginId)) == null ? void 0 : _a.then((factory) => {
|
|
1429
1426
|
if (factory.service.scope === "root") {
|
|
1430
|
-
let existing = __privateGet$
|
|
1427
|
+
let existing = __privateGet$4(this, _rootServiceImplementations).get(factory);
|
|
1431
1428
|
if (!existing) {
|
|
1432
|
-
__privateMethod$
|
|
1429
|
+
__privateMethod$4(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
|
|
1433
1430
|
const rootDeps = new Array();
|
|
1434
1431
|
for (const [name, serviceRef] of Object.entries(factory.deps)) {
|
|
1435
1432
|
if (serviceRef.scope !== "root") {
|
|
@@ -1443,13 +1440,13 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1443
1440
|
existing = Promise.all(rootDeps).then(
|
|
1444
1441
|
(entries) => factory.factory(Object.fromEntries(entries), void 0)
|
|
1445
1442
|
);
|
|
1446
|
-
__privateGet$
|
|
1443
|
+
__privateGet$4(this, _rootServiceImplementations).set(factory, existing);
|
|
1447
1444
|
}
|
|
1448
1445
|
return existing;
|
|
1449
1446
|
}
|
|
1450
|
-
let implementation = __privateGet$
|
|
1447
|
+
let implementation = __privateGet$4(this, _implementations).get(factory);
|
|
1451
1448
|
if (!implementation) {
|
|
1452
|
-
__privateMethod$
|
|
1449
|
+
__privateMethod$4(this, _checkForMissingDeps, checkForMissingDeps_fn).call(this, factory, pluginId);
|
|
1453
1450
|
const rootDeps = new Array();
|
|
1454
1451
|
for (const [name, serviceRef] of Object.entries(factory.deps)) {
|
|
1455
1452
|
if (serviceRef.scope === "root") {
|
|
@@ -1471,7 +1468,7 @@ const _ServiceRegistry = class _ServiceRegistry {
|
|
|
1471
1468
|
}),
|
|
1472
1469
|
byPlugin: /* @__PURE__ */ new Map()
|
|
1473
1470
|
};
|
|
1474
|
-
__privateGet$
|
|
1471
|
+
__privateGet$4(this, _implementations).set(factory, implementation);
|
|
1475
1472
|
}
|
|
1476
1473
|
let result = implementation.byPlugin.get(pluginId);
|
|
1477
1474
|
if (!result) {
|
|
@@ -1509,18 +1506,18 @@ resolveFactory_fn = function(ref, pluginId) {
|
|
|
1509
1506
|
toInternalServiceFactory(pluginMetadataServiceFactory({ pluginId }))
|
|
1510
1507
|
);
|
|
1511
1508
|
}
|
|
1512
|
-
let resolvedFactory = __privateGet$
|
|
1509
|
+
let resolvedFactory = __privateGet$4(this, _providedFactories).get(ref.id);
|
|
1513
1510
|
const { __defaultFactory: defaultFactory } = ref;
|
|
1514
1511
|
if (!resolvedFactory && !defaultFactory) {
|
|
1515
1512
|
return void 0;
|
|
1516
1513
|
}
|
|
1517
1514
|
if (!resolvedFactory) {
|
|
1518
|
-
let loadedFactory = __privateGet$
|
|
1515
|
+
let loadedFactory = __privateGet$4(this, _loadedDefaultFactories).get(defaultFactory);
|
|
1519
1516
|
if (!loadedFactory) {
|
|
1520
1517
|
loadedFactory = Promise.resolve().then(() => defaultFactory(ref)).then(
|
|
1521
1518
|
(f) => toInternalServiceFactory(typeof f === "function" ? f() : f)
|
|
1522
1519
|
);
|
|
1523
|
-
__privateGet$
|
|
1520
|
+
__privateGet$4(this, _loadedDefaultFactories).set(defaultFactory, loadedFactory);
|
|
1524
1521
|
}
|
|
1525
1522
|
resolvedFactory = loadedFactory.catch((error) => {
|
|
1526
1523
|
throw new Error(
|
|
@@ -1538,7 +1535,7 @@ checkForMissingDeps_fn = function(factory, pluginId) {
|
|
|
1538
1535
|
if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
|
|
1539
1536
|
return false;
|
|
1540
1537
|
}
|
|
1541
|
-
if (__privateGet$
|
|
1538
|
+
if (__privateGet$4(this, _providedFactories).get(ref.id)) {
|
|
1542
1539
|
return false;
|
|
1543
1540
|
}
|
|
1544
1541
|
return !ref.__defaultFactory;
|
|
@@ -1552,52 +1549,52 @@ checkForMissingDeps_fn = function(factory, pluginId) {
|
|
|
1552
1549
|
};
|
|
1553
1550
|
let ServiceRegistry = _ServiceRegistry;
|
|
1554
1551
|
|
|
1555
|
-
var __accessCheck$
|
|
1552
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
1556
1553
|
if (!member.has(obj))
|
|
1557
1554
|
throw TypeError("Cannot " + msg);
|
|
1558
1555
|
};
|
|
1559
|
-
var __privateGet$
|
|
1560
|
-
__accessCheck$
|
|
1556
|
+
var __privateGet$3 = (obj, member, getter) => {
|
|
1557
|
+
__accessCheck$4(obj, member, "read from private field");
|
|
1561
1558
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1562
1559
|
};
|
|
1563
|
-
var __privateAdd$
|
|
1560
|
+
var __privateAdd$4 = (obj, member, value) => {
|
|
1564
1561
|
if (member.has(obj))
|
|
1565
1562
|
throw TypeError("Cannot add the same private member more than once");
|
|
1566
1563
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1567
1564
|
};
|
|
1568
|
-
var __privateSet$
|
|
1569
|
-
__accessCheck$
|
|
1565
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
|
1566
|
+
__accessCheck$4(obj, member, "write to private field");
|
|
1570
1567
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1571
1568
|
return value;
|
|
1572
1569
|
};
|
|
1573
|
-
var __privateMethod$
|
|
1574
|
-
__accessCheck$
|
|
1570
|
+
var __privateMethod$3 = (obj, member, method) => {
|
|
1571
|
+
__accessCheck$4(obj, member, "access private method");
|
|
1575
1572
|
return method;
|
|
1576
1573
|
};
|
|
1577
1574
|
var _startPromise, _features, _extensionPoints, _serviceRegistry, _registeredFeatures, _getInitDeps, getInitDeps_fn, _addFeature, addFeature_fn, _doStart, doStart_fn, _getRootLifecycleImpl, getRootLifecycleImpl_fn, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn;
|
|
1578
1575
|
class BackendInitializer {
|
|
1579
1576
|
constructor(defaultApiFactories) {
|
|
1580
|
-
__privateAdd$
|
|
1581
|
-
__privateAdd$
|
|
1582
|
-
__privateAdd$
|
|
1577
|
+
__privateAdd$4(this, _getInitDeps);
|
|
1578
|
+
__privateAdd$4(this, _addFeature);
|
|
1579
|
+
__privateAdd$4(this, _doStart);
|
|
1583
1580
|
// Bit of a hacky way to grab the lifecycle services, potentially find a nicer way to do this
|
|
1584
|
-
__privateAdd$
|
|
1585
|
-
__privateAdd$
|
|
1586
|
-
__privateAdd$
|
|
1587
|
-
__privateAdd$
|
|
1588
|
-
__privateAdd$
|
|
1589
|
-
__privateAdd$
|
|
1590
|
-
__privateAdd$
|
|
1591
|
-
__privateSet$
|
|
1581
|
+
__privateAdd$4(this, _getRootLifecycleImpl);
|
|
1582
|
+
__privateAdd$4(this, _getPluginLifecycleImpl);
|
|
1583
|
+
__privateAdd$4(this, _startPromise, void 0);
|
|
1584
|
+
__privateAdd$4(this, _features, new Array());
|
|
1585
|
+
__privateAdd$4(this, _extensionPoints, /* @__PURE__ */ new Map());
|
|
1586
|
+
__privateAdd$4(this, _serviceRegistry, void 0);
|
|
1587
|
+
__privateAdd$4(this, _registeredFeatures, new Array());
|
|
1588
|
+
__privateSet$3(this, _serviceRegistry, ServiceRegistry.create([...defaultApiFactories]));
|
|
1592
1589
|
}
|
|
1593
1590
|
add(feature) {
|
|
1594
|
-
if (__privateGet$
|
|
1591
|
+
if (__privateGet$3(this, _startPromise)) {
|
|
1595
1592
|
throw new Error("feature can not be added after the backend has started");
|
|
1596
1593
|
}
|
|
1597
|
-
__privateGet$
|
|
1594
|
+
__privateGet$3(this, _registeredFeatures).push(Promise.resolve(feature));
|
|
1598
1595
|
}
|
|
1599
1596
|
async start() {
|
|
1600
|
-
if (__privateGet$
|
|
1597
|
+
if (__privateGet$3(this, _startPromise)) {
|
|
1601
1598
|
throw new Error("Backend has already started");
|
|
1602
1599
|
}
|
|
1603
1600
|
const exitHandler = async () => {
|
|
@@ -1615,18 +1612,18 @@ class BackendInitializer {
|
|
|
1615
1612
|
process.addListener("SIGTERM", exitHandler);
|
|
1616
1613
|
process.addListener("SIGINT", exitHandler);
|
|
1617
1614
|
process.addListener("beforeExit", exitHandler);
|
|
1618
|
-
__privateSet$
|
|
1619
|
-
await __privateGet$
|
|
1615
|
+
__privateSet$3(this, _startPromise, __privateMethod$3(this, _doStart, doStart_fn).call(this));
|
|
1616
|
+
await __privateGet$3(this, _startPromise);
|
|
1620
1617
|
}
|
|
1621
1618
|
async stop() {
|
|
1622
|
-
if (!__privateGet$
|
|
1619
|
+
if (!__privateGet$3(this, _startPromise)) {
|
|
1623
1620
|
return;
|
|
1624
1621
|
}
|
|
1625
1622
|
try {
|
|
1626
|
-
await __privateGet$
|
|
1623
|
+
await __privateGet$3(this, _startPromise);
|
|
1627
1624
|
} catch (error) {
|
|
1628
1625
|
}
|
|
1629
|
-
const lifecycleService = await __privateMethod$
|
|
1626
|
+
const lifecycleService = await __privateMethod$3(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
|
|
1630
1627
|
await lifecycleService.shutdown();
|
|
1631
1628
|
}
|
|
1632
1629
|
}
|
|
@@ -1640,7 +1637,7 @@ getInitDeps_fn = async function(deps, pluginId, moduleId) {
|
|
|
1640
1637
|
const result = /* @__PURE__ */ new Map();
|
|
1641
1638
|
const missingRefs = /* @__PURE__ */ new Set();
|
|
1642
1639
|
for (const [name, ref] of Object.entries(deps)) {
|
|
1643
|
-
const ep = __privateGet$
|
|
1640
|
+
const ep = __privateGet$3(this, _extensionPoints).get(ref.id);
|
|
1644
1641
|
if (ep) {
|
|
1645
1642
|
if (ep.pluginId !== pluginId) {
|
|
1646
1643
|
throw new Error(
|
|
@@ -1649,7 +1646,7 @@ getInitDeps_fn = async function(deps, pluginId, moduleId) {
|
|
|
1649
1646
|
}
|
|
1650
1647
|
result.set(name, ep.impl);
|
|
1651
1648
|
} else {
|
|
1652
|
-
const impl = await __privateGet$
|
|
1649
|
+
const impl = await __privateGet$3(this, _serviceRegistry).get(
|
|
1653
1650
|
ref,
|
|
1654
1651
|
pluginId
|
|
1655
1652
|
);
|
|
@@ -1676,14 +1673,14 @@ addFeature_fn = function(feature) {
|
|
|
1676
1673
|
);
|
|
1677
1674
|
}
|
|
1678
1675
|
if (isServiceFactory(feature)) {
|
|
1679
|
-
__privateGet$
|
|
1676
|
+
__privateGet$3(this, _serviceRegistry).add(feature);
|
|
1680
1677
|
} else if (isInternalBackendFeature(feature)) {
|
|
1681
1678
|
if (feature.version !== "v1") {
|
|
1682
1679
|
throw new Error(
|
|
1683
1680
|
`Failed to add feature, invalid version '${feature.version}'`
|
|
1684
1681
|
);
|
|
1685
1682
|
}
|
|
1686
|
-
__privateGet$
|
|
1683
|
+
__privateGet$3(this, _features).push(feature);
|
|
1687
1684
|
} else {
|
|
1688
1685
|
throw new Error(
|
|
1689
1686
|
`Failed to add feature, invalid feature ${JSON.stringify(feature)}`
|
|
@@ -1692,39 +1689,39 @@ addFeature_fn = function(feature) {
|
|
|
1692
1689
|
};
|
|
1693
1690
|
_doStart = new WeakSet();
|
|
1694
1691
|
doStart_fn = async function() {
|
|
1695
|
-
__privateGet$
|
|
1696
|
-
for (const feature of __privateGet$
|
|
1697
|
-
__privateMethod$
|
|
1692
|
+
__privateGet$3(this, _serviceRegistry).checkForCircularDeps();
|
|
1693
|
+
for (const feature of __privateGet$3(this, _registeredFeatures)) {
|
|
1694
|
+
__privateMethod$3(this, _addFeature, addFeature_fn).call(this, await feature);
|
|
1698
1695
|
}
|
|
1699
|
-
const featureDiscovery = await __privateGet$
|
|
1696
|
+
const featureDiscovery = await __privateGet$3(this, _serviceRegistry).get(
|
|
1700
1697
|
alpha.featureDiscoveryServiceRef,
|
|
1701
1698
|
"root"
|
|
1702
1699
|
);
|
|
1703
1700
|
if (featureDiscovery) {
|
|
1704
1701
|
const { features } = await featureDiscovery.getBackendFeatures();
|
|
1705
1702
|
for (const feature of features) {
|
|
1706
|
-
__privateMethod$
|
|
1703
|
+
__privateMethod$3(this, _addFeature, addFeature_fn).call(this, feature);
|
|
1707
1704
|
}
|
|
1708
|
-
__privateGet$
|
|
1705
|
+
__privateGet$3(this, _serviceRegistry).checkForCircularDeps();
|
|
1709
1706
|
}
|
|
1710
|
-
for (const ref of __privateGet$
|
|
1707
|
+
for (const ref of __privateGet$3(this, _serviceRegistry).getServiceRefs()) {
|
|
1711
1708
|
if (ref.scope === "root") {
|
|
1712
|
-
await __privateGet$
|
|
1709
|
+
await __privateGet$3(this, _serviceRegistry).get(ref, "root");
|
|
1713
1710
|
}
|
|
1714
1711
|
}
|
|
1715
1712
|
const pluginInits = /* @__PURE__ */ new Map();
|
|
1716
1713
|
const moduleInits = /* @__PURE__ */ new Map();
|
|
1717
|
-
for (const feature of __privateGet$
|
|
1714
|
+
for (const feature of __privateGet$3(this, _features)) {
|
|
1718
1715
|
for (const r of feature.getRegistrations()) {
|
|
1719
1716
|
const provides = /* @__PURE__ */ new Set();
|
|
1720
1717
|
if (r.type === "plugin" || r.type === "module") {
|
|
1721
1718
|
for (const [extRef, extImpl] of r.extensionPoints) {
|
|
1722
|
-
if (__privateGet$
|
|
1719
|
+
if (__privateGet$3(this, _extensionPoints).has(extRef.id)) {
|
|
1723
1720
|
throw new Error(
|
|
1724
1721
|
`ExtensionPoint with ID '${extRef.id}' is already registered`
|
|
1725
1722
|
);
|
|
1726
1723
|
}
|
|
1727
|
-
__privateGet$
|
|
1724
|
+
__privateGet$3(this, _extensionPoints).set(extRef.id, {
|
|
1728
1725
|
impl: extImpl,
|
|
1729
1726
|
pluginId: r.pluginId
|
|
1730
1727
|
});
|
|
@@ -1784,7 +1781,7 @@ doStart_fn = async function() {
|
|
|
1784
1781
|
}
|
|
1785
1782
|
await tree.parallelTopologicalTraversal(
|
|
1786
1783
|
async ({ moduleId, moduleInit }) => {
|
|
1787
|
-
const moduleDeps = await __privateMethod$
|
|
1784
|
+
const moduleDeps = await __privateMethod$3(this, _getInitDeps, getInitDeps_fn).call(this, moduleInit.init.deps, pluginId, moduleId);
|
|
1788
1785
|
await moduleInit.init.func(moduleDeps).catch((error) => {
|
|
1789
1786
|
throw new errors.ForwardedError(
|
|
1790
1787
|
`Module '${moduleId}' for plugin '${pluginId}' startup failed`,
|
|
@@ -1796,7 +1793,7 @@ doStart_fn = async function() {
|
|
|
1796
1793
|
}
|
|
1797
1794
|
const pluginInit = pluginInits.get(pluginId);
|
|
1798
1795
|
if (pluginInit) {
|
|
1799
|
-
const pluginDeps = await __privateMethod$
|
|
1796
|
+
const pluginDeps = await __privateMethod$3(this, _getInitDeps, getInitDeps_fn).call(this, pluginInit.init.deps, pluginId);
|
|
1800
1797
|
await pluginInit.init.func(pluginDeps).catch((error) => {
|
|
1801
1798
|
throw new errors.ForwardedError(
|
|
1802
1799
|
`Plugin '${pluginId}' startup failed`,
|
|
@@ -1804,14 +1801,14 @@ doStart_fn = async function() {
|
|
|
1804
1801
|
);
|
|
1805
1802
|
});
|
|
1806
1803
|
}
|
|
1807
|
-
const lifecycleService2 = await __privateMethod$
|
|
1804
|
+
const lifecycleService2 = await __privateMethod$3(this, _getPluginLifecycleImpl, getPluginLifecycleImpl_fn).call(this, pluginId);
|
|
1808
1805
|
await lifecycleService2.startup();
|
|
1809
1806
|
})
|
|
1810
1807
|
);
|
|
1811
|
-
const lifecycleService = await __privateMethod$
|
|
1808
|
+
const lifecycleService = await __privateMethod$3(this, _getRootLifecycleImpl, getRootLifecycleImpl_fn).call(this);
|
|
1812
1809
|
await lifecycleService.startup();
|
|
1813
1810
|
if (process.env.NODE_ENV !== "test") {
|
|
1814
|
-
const rootLogger = await __privateGet$
|
|
1811
|
+
const rootLogger = await __privateGet$3(this, _serviceRegistry).get(
|
|
1815
1812
|
backendPluginApi.coreServices.rootLogger,
|
|
1816
1813
|
"root"
|
|
1817
1814
|
);
|
|
@@ -1827,7 +1824,7 @@ doStart_fn = async function() {
|
|
|
1827
1824
|
};
|
|
1828
1825
|
_getRootLifecycleImpl = new WeakSet();
|
|
1829
1826
|
getRootLifecycleImpl_fn = async function() {
|
|
1830
|
-
const lifecycleService = await __privateGet$
|
|
1827
|
+
const lifecycleService = await __privateGet$3(this, _serviceRegistry).get(
|
|
1831
1828
|
backendPluginApi.coreServices.rootLifecycle,
|
|
1832
1829
|
"root"
|
|
1833
1830
|
);
|
|
@@ -1838,7 +1835,7 @@ getRootLifecycleImpl_fn = async function() {
|
|
|
1838
1835
|
};
|
|
1839
1836
|
_getPluginLifecycleImpl = new WeakSet();
|
|
1840
1837
|
getPluginLifecycleImpl_fn = async function(pluginId) {
|
|
1841
|
-
const lifecycleService = await __privateGet$
|
|
1838
|
+
const lifecycleService = await __privateGet$3(this, _serviceRegistry).get(
|
|
1842
1839
|
backendPluginApi.coreServices.lifecycle,
|
|
1843
1840
|
pluginId
|
|
1844
1841
|
);
|
|
@@ -1854,42 +1851,42 @@ function isInternalBackendFeature(feature) {
|
|
|
1854
1851
|
return typeof feature.getRegistrations === "function";
|
|
1855
1852
|
}
|
|
1856
1853
|
|
|
1857
|
-
var __accessCheck$
|
|
1854
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
|
1858
1855
|
if (!member.has(obj))
|
|
1859
1856
|
throw TypeError("Cannot " + msg);
|
|
1860
1857
|
};
|
|
1861
|
-
var __privateGet$
|
|
1862
|
-
__accessCheck$
|
|
1858
|
+
var __privateGet$2 = (obj, member, getter) => {
|
|
1859
|
+
__accessCheck$3(obj, member, "read from private field");
|
|
1863
1860
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1864
1861
|
};
|
|
1865
|
-
var __privateAdd$
|
|
1862
|
+
var __privateAdd$3 = (obj, member, value) => {
|
|
1866
1863
|
if (member.has(obj))
|
|
1867
1864
|
throw TypeError("Cannot add the same private member more than once");
|
|
1868
1865
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1869
1866
|
};
|
|
1870
|
-
var __privateSet$
|
|
1871
|
-
__accessCheck$
|
|
1867
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
|
1868
|
+
__accessCheck$3(obj, member, "write to private field");
|
|
1872
1869
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1873
1870
|
return value;
|
|
1874
1871
|
};
|
|
1875
1872
|
var _initializer;
|
|
1876
1873
|
class BackstageBackend {
|
|
1877
1874
|
constructor(defaultServiceFactories) {
|
|
1878
|
-
__privateAdd$
|
|
1879
|
-
__privateSet$
|
|
1875
|
+
__privateAdd$3(this, _initializer, void 0);
|
|
1876
|
+
__privateSet$2(this, _initializer, new BackendInitializer(defaultServiceFactories));
|
|
1880
1877
|
}
|
|
1881
1878
|
add(feature) {
|
|
1882
1879
|
if (isPromise(feature)) {
|
|
1883
|
-
__privateGet$
|
|
1880
|
+
__privateGet$2(this, _initializer).add(feature.then((f) => unwrapFeature(f.default)));
|
|
1884
1881
|
} else {
|
|
1885
|
-
__privateGet$
|
|
1882
|
+
__privateGet$2(this, _initializer).add(unwrapFeature(feature));
|
|
1886
1883
|
}
|
|
1887
1884
|
}
|
|
1888
1885
|
async start() {
|
|
1889
|
-
await __privateGet$
|
|
1886
|
+
await __privateGet$2(this, _initializer).start();
|
|
1890
1887
|
}
|
|
1891
1888
|
async stop() {
|
|
1892
|
-
await __privateGet$
|
|
1889
|
+
await __privateGet$2(this, _initializer).stop();
|
|
1893
1890
|
}
|
|
1894
1891
|
}
|
|
1895
1892
|
_initializer = new WeakMap();
|
|
@@ -1935,17 +1932,17 @@ function createSpecializedBackend(options) {
|
|
|
1935
1932
|
return new BackstageBackend(services);
|
|
1936
1933
|
}
|
|
1937
1934
|
|
|
1938
|
-
var __accessCheck$
|
|
1935
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
|
1939
1936
|
if (!member.has(obj))
|
|
1940
1937
|
throw TypeError("Cannot " + msg);
|
|
1941
1938
|
};
|
|
1942
|
-
var __privateAdd$
|
|
1939
|
+
var __privateAdd$2 = (obj, member, value) => {
|
|
1943
1940
|
if (member.has(obj))
|
|
1944
1941
|
throw TypeError("Cannot add the same private member more than once");
|
|
1945
1942
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1946
1943
|
};
|
|
1947
|
-
var __privateMethod$
|
|
1948
|
-
__accessCheck$
|
|
1944
|
+
var __privateMethod$2 = (obj, member, method) => {
|
|
1945
|
+
__accessCheck$2(obj, member, "access private method");
|
|
1949
1946
|
return method;
|
|
1950
1947
|
};
|
|
1951
1948
|
var _getJwtExpiration, getJwtExpiration_fn;
|
|
@@ -1999,7 +1996,7 @@ class DefaultAuthService {
|
|
|
1999
1996
|
this.identity = identity;
|
|
2000
1997
|
this.pluginId = pluginId;
|
|
2001
1998
|
this.disableDefaultAuthPolicy = disableDefaultAuthPolicy;
|
|
2002
|
-
__privateAdd$
|
|
1999
|
+
__privateAdd$2(this, _getJwtExpiration);
|
|
2003
2000
|
}
|
|
2004
2001
|
// allowLimitedAccess is currently ignored, since we currently always use the full user tokens
|
|
2005
2002
|
async authenticate(token) {
|
|
@@ -2019,7 +2016,7 @@ class DefaultAuthService {
|
|
|
2019
2016
|
return createCredentialsWithUserPrincipal(
|
|
2020
2017
|
identity.identity.userEntityRef,
|
|
2021
2018
|
token,
|
|
2022
|
-
__privateMethod$
|
|
2019
|
+
__privateMethod$2(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token)
|
|
2023
2020
|
);
|
|
2024
2021
|
}
|
|
2025
2022
|
isPrincipal(credentials, type) {
|
|
@@ -2066,7 +2063,7 @@ class DefaultAuthService {
|
|
|
2066
2063
|
"User credentials is unexpectedly missing token"
|
|
2067
2064
|
);
|
|
2068
2065
|
}
|
|
2069
|
-
return { token, expiresAt: __privateMethod$
|
|
2066
|
+
return { token, expiresAt: __privateMethod$2(this, _getJwtExpiration, getJwtExpiration_fn).call(this, token) };
|
|
2070
2067
|
}
|
|
2071
2068
|
}
|
|
2072
2069
|
_getJwtExpiration = new WeakSet();
|
|
@@ -2250,26 +2247,26 @@ const discoveryServiceFactory = backendPluginApi.createServiceFactory({
|
|
|
2250
2247
|
}
|
|
2251
2248
|
});
|
|
2252
2249
|
|
|
2253
|
-
var __accessCheck$
|
|
2250
|
+
var __accessCheck$1 = (obj, member, msg) => {
|
|
2254
2251
|
if (!member.has(obj))
|
|
2255
2252
|
throw TypeError("Cannot " + msg);
|
|
2256
2253
|
};
|
|
2257
|
-
var __privateGet$
|
|
2258
|
-
__accessCheck$
|
|
2254
|
+
var __privateGet$1 = (obj, member, getter) => {
|
|
2255
|
+
__accessCheck$1(obj, member, "read from private field");
|
|
2259
2256
|
return getter ? getter.call(obj) : member.get(obj);
|
|
2260
2257
|
};
|
|
2261
|
-
var __privateAdd$
|
|
2258
|
+
var __privateAdd$1 = (obj, member, value) => {
|
|
2262
2259
|
if (member.has(obj))
|
|
2263
2260
|
throw TypeError("Cannot add the same private member more than once");
|
|
2264
2261
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2265
2262
|
};
|
|
2266
|
-
var __privateSet$
|
|
2267
|
-
__accessCheck$
|
|
2263
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
|
2264
|
+
__accessCheck$1(obj, member, "write to private field");
|
|
2268
2265
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
2269
2266
|
return value;
|
|
2270
2267
|
};
|
|
2271
|
-
var __privateMethod$
|
|
2272
|
-
__accessCheck$
|
|
2268
|
+
var __privateMethod$1 = (obj, member, method) => {
|
|
2269
|
+
__accessCheck$1(obj, member, "access private method");
|
|
2273
2270
|
return method;
|
|
2274
2271
|
};
|
|
2275
2272
|
var _auth, _discovery, _pluginId, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn, _getCredentials, getCredentials_fn, _getLimitedCredentials, getLimitedCredentials_fn, _existingCookieExpiration, existingCookieExpiration_fn;
|
|
@@ -2304,37 +2301,37 @@ const credentialsSymbol = Symbol("backstage-credentials");
|
|
|
2304
2301
|
const limitedCredentialsSymbol = Symbol("backstage-limited-credentials");
|
|
2305
2302
|
class DefaultHttpAuthService {
|
|
2306
2303
|
constructor(auth, discovery, pluginId) {
|
|
2307
|
-
__privateAdd$
|
|
2308
|
-
__privateAdd$
|
|
2309
|
-
__privateAdd$
|
|
2310
|
-
__privateAdd$
|
|
2311
|
-
__privateAdd$
|
|
2312
|
-
__privateAdd$
|
|
2313
|
-
__privateAdd$
|
|
2314
|
-
__privateAdd$
|
|
2315
|
-
__privateSet$
|
|
2316
|
-
__privateSet$
|
|
2317
|
-
__privateSet$
|
|
2304
|
+
__privateAdd$1(this, _extractCredentialsFromRequest);
|
|
2305
|
+
__privateAdd$1(this, _extractLimitedCredentialsFromRequest);
|
|
2306
|
+
__privateAdd$1(this, _getCredentials);
|
|
2307
|
+
__privateAdd$1(this, _getLimitedCredentials);
|
|
2308
|
+
__privateAdd$1(this, _existingCookieExpiration);
|
|
2309
|
+
__privateAdd$1(this, _auth, void 0);
|
|
2310
|
+
__privateAdd$1(this, _discovery, void 0);
|
|
2311
|
+
__privateAdd$1(this, _pluginId, void 0);
|
|
2312
|
+
__privateSet$1(this, _auth, auth);
|
|
2313
|
+
__privateSet$1(this, _discovery, discovery);
|
|
2314
|
+
__privateSet$1(this, _pluginId, pluginId);
|
|
2318
2315
|
}
|
|
2319
2316
|
async credentials(req, options) {
|
|
2320
|
-
const credentials = (options == null ? void 0 : options.allowLimitedAccess) ? await __privateMethod$
|
|
2317
|
+
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);
|
|
2321
2318
|
const allowed = options == null ? void 0 : options.allow;
|
|
2322
2319
|
if (!allowed) {
|
|
2323
2320
|
return credentials;
|
|
2324
2321
|
}
|
|
2325
|
-
if (__privateGet$
|
|
2322
|
+
if (__privateGet$1(this, _auth).isPrincipal(credentials, "none")) {
|
|
2326
2323
|
if (allowed.includes("none")) {
|
|
2327
2324
|
return credentials;
|
|
2328
2325
|
}
|
|
2329
2326
|
throw new errors.AuthenticationError("Missing credentials");
|
|
2330
|
-
} else if (__privateGet$
|
|
2327
|
+
} else if (__privateGet$1(this, _auth).isPrincipal(credentials, "user")) {
|
|
2331
2328
|
if (allowed.includes("user")) {
|
|
2332
2329
|
return credentials;
|
|
2333
2330
|
}
|
|
2334
2331
|
throw new errors.NotAllowedError(
|
|
2335
2332
|
`This endpoint does not allow 'user' credentials`
|
|
2336
2333
|
);
|
|
2337
|
-
} else if (__privateGet$
|
|
2334
|
+
} else if (__privateGet$1(this, _auth).isPrincipal(credentials, "service")) {
|
|
2338
2335
|
if (allowed.includes("service")) {
|
|
2339
2336
|
return credentials;
|
|
2340
2337
|
}
|
|
@@ -2352,7 +2349,7 @@ class DefaultHttpAuthService {
|
|
|
2352
2349
|
}
|
|
2353
2350
|
let credentials;
|
|
2354
2351
|
if (options == null ? void 0 : options.credentials) {
|
|
2355
|
-
if (!__privateGet$
|
|
2352
|
+
if (!__privateGet$1(this, _auth).isPrincipal(options.credentials, "user")) {
|
|
2356
2353
|
throw new errors.AuthenticationError(
|
|
2357
2354
|
"Refused to issue cookie for non-user principal"
|
|
2358
2355
|
);
|
|
@@ -2361,17 +2358,17 @@ class DefaultHttpAuthService {
|
|
|
2361
2358
|
} else {
|
|
2362
2359
|
credentials = await this.credentials(res.req, { allow: ["user"] });
|
|
2363
2360
|
}
|
|
2364
|
-
const existingExpiresAt = await __privateMethod$
|
|
2361
|
+
const existingExpiresAt = await __privateMethod$1(this, _existingCookieExpiration, existingCookieExpiration_fn).call(this, res.req);
|
|
2365
2362
|
if (existingExpiresAt && !willExpireSoon(existingExpiresAt)) {
|
|
2366
2363
|
return { expiresAt: existingExpiresAt };
|
|
2367
2364
|
}
|
|
2368
2365
|
const originHeader = res.req.headers.origin;
|
|
2369
2366
|
const origin = !originHeader || originHeader === "null" ? void 0 : originHeader;
|
|
2370
|
-
const externalBaseUrlStr = await __privateGet$
|
|
2371
|
-
__privateGet$
|
|
2367
|
+
const externalBaseUrlStr = await __privateGet$1(this, _discovery).getExternalBaseUrl(
|
|
2368
|
+
__privateGet$1(this, _pluginId)
|
|
2372
2369
|
);
|
|
2373
2370
|
const externalBaseUrl = new URL(origin != null ? origin : externalBaseUrlStr);
|
|
2374
|
-
const { token, expiresAt } = await __privateGet$
|
|
2371
|
+
const { token, expiresAt } = await __privateGet$1(this, _auth).getLimitedUserToken(
|
|
2375
2372
|
credentials
|
|
2376
2373
|
);
|
|
2377
2374
|
if (!token) {
|
|
@@ -2396,35 +2393,35 @@ _extractCredentialsFromRequest = new WeakSet();
|
|
|
2396
2393
|
extractCredentialsFromRequest_fn = async function(req) {
|
|
2397
2394
|
const token = getTokenFromRequest(req);
|
|
2398
2395
|
if (!token) {
|
|
2399
|
-
return await __privateGet$
|
|
2396
|
+
return await __privateGet$1(this, _auth).getNoneCredentials();
|
|
2400
2397
|
}
|
|
2401
|
-
return await __privateGet$
|
|
2398
|
+
return await __privateGet$1(this, _auth).authenticate(token);
|
|
2402
2399
|
};
|
|
2403
2400
|
_extractLimitedCredentialsFromRequest = new WeakSet();
|
|
2404
2401
|
extractLimitedCredentialsFromRequest_fn = async function(req) {
|
|
2405
2402
|
const token = getTokenFromRequest(req);
|
|
2406
2403
|
if (token) {
|
|
2407
|
-
return await __privateGet$
|
|
2404
|
+
return await __privateGet$1(this, _auth).authenticate(token, {
|
|
2408
2405
|
allowLimitedAccess: true
|
|
2409
2406
|
});
|
|
2410
2407
|
}
|
|
2411
2408
|
const cookie = getCookieFromRequest(req);
|
|
2412
2409
|
if (cookie) {
|
|
2413
|
-
return await __privateGet$
|
|
2410
|
+
return await __privateGet$1(this, _auth).authenticate(cookie, {
|
|
2414
2411
|
allowLimitedAccess: true
|
|
2415
2412
|
});
|
|
2416
2413
|
}
|
|
2417
|
-
return await __privateGet$
|
|
2414
|
+
return await __privateGet$1(this, _auth).getNoneCredentials();
|
|
2418
2415
|
};
|
|
2419
2416
|
_getCredentials = new WeakSet();
|
|
2420
2417
|
getCredentials_fn = async function(req) {
|
|
2421
2418
|
var _a;
|
|
2422
|
-
return (_a = req[credentialsSymbol]) != null ? _a : req[credentialsSymbol] = __privateMethod$
|
|
2419
|
+
return (_a = req[credentialsSymbol]) != null ? _a : req[credentialsSymbol] = __privateMethod$1(this, _extractCredentialsFromRequest, extractCredentialsFromRequest_fn).call(this, req);
|
|
2423
2420
|
};
|
|
2424
2421
|
_getLimitedCredentials = new WeakSet();
|
|
2425
2422
|
getLimitedCredentials_fn = async function(req) {
|
|
2426
2423
|
var _a;
|
|
2427
|
-
return (_a = req[limitedCredentialsSymbol]) != null ? _a : req[limitedCredentialsSymbol] = __privateMethod$
|
|
2424
|
+
return (_a = req[limitedCredentialsSymbol]) != null ? _a : req[limitedCredentialsSymbol] = __privateMethod$1(this, _extractLimitedCredentialsFromRequest, extractLimitedCredentialsFromRequest_fn).call(this, req);
|
|
2428
2425
|
};
|
|
2429
2426
|
_existingCookieExpiration = new WeakSet();
|
|
2430
2427
|
existingCookieExpiration_fn = async function(req) {
|
|
@@ -2432,10 +2429,10 @@ existingCookieExpiration_fn = async function(req) {
|
|
|
2432
2429
|
if (!existingCookie) {
|
|
2433
2430
|
return void 0;
|
|
2434
2431
|
}
|
|
2435
|
-
const existingCredentials = await __privateGet$
|
|
2432
|
+
const existingCredentials = await __privateGet$1(this, _auth).authenticate(existingCookie, {
|
|
2436
2433
|
allowLimitedAccess: true
|
|
2437
2434
|
});
|
|
2438
|
-
if (!__privateGet$
|
|
2435
|
+
if (!__privateGet$1(this, _auth).isPrincipal(existingCredentials, "user")) {
|
|
2439
2436
|
return void 0;
|
|
2440
2437
|
}
|
|
2441
2438
|
return existingCredentials.expiresAt;
|
|
@@ -2496,105 +2493,6 @@ function createLifecycleMiddleware(options) {
|
|
|
2496
2493
|
};
|
|
2497
2494
|
}
|
|
2498
2495
|
|
|
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
|
-
|
|
2598
2496
|
function createPathPolicyPredicate(policyPath) {
|
|
2599
2497
|
if (policyPath === "/" || policyPath === "*") {
|
|
2600
2498
|
return () => true;
|
|
@@ -2607,8 +2505,8 @@ function createPathPolicyPredicate(policyPath) {
|
|
|
2607
2505
|
};
|
|
2608
2506
|
}
|
|
2609
2507
|
function createCredentialsBarrier(options) {
|
|
2610
|
-
const { httpAuth, config
|
|
2611
|
-
const disableDefaultAuthPolicy = config
|
|
2508
|
+
const { httpAuth, config } = options;
|
|
2509
|
+
const disableDefaultAuthPolicy = config.getOptionalBoolean(
|
|
2612
2510
|
"backend.auth.dangerouslyDisableDefaultAuthPolicy"
|
|
2613
2511
|
);
|
|
2614
2512
|
if (disableDefaultAuthPolicy) {
|
|
@@ -2620,31 +2518,12 @@ function createCredentialsBarrier(options) {
|
|
|
2620
2518
|
}
|
|
2621
2519
|
const unauthenticatedPredicates = new Array();
|
|
2622
2520
|
const cookiePredicates = new Array();
|
|
2623
|
-
const
|
|
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) => {
|
|
2521
|
+
const middleware = (req, _, next) => {
|
|
2643
2522
|
const allowsUnauthenticated = unauthenticatedPredicates.some(
|
|
2644
2523
|
(predicate) => predicate(req.path)
|
|
2645
2524
|
);
|
|
2646
2525
|
if (allowsUnauthenticated) {
|
|
2647
|
-
|
|
2526
|
+
next();
|
|
2648
2527
|
return;
|
|
2649
2528
|
}
|
|
2650
2529
|
const allowsCookie = cookiePredicates.some(
|
|
@@ -2674,31 +2553,19 @@ const httpRouterServiceFactory = backendPluginApi.createServiceFactory(
|
|
|
2674
2553
|
(options) => ({
|
|
2675
2554
|
service: backendPluginApi.coreServices.httpRouter,
|
|
2676
2555
|
deps: {
|
|
2677
|
-
cache: backendPluginApi.coreServices.cache,
|
|
2678
2556
|
plugin: backendPluginApi.coreServices.pluginMetadata,
|
|
2679
2557
|
config: backendPluginApi.coreServices.rootConfig,
|
|
2680
2558
|
lifecycle: backendPluginApi.coreServices.lifecycle,
|
|
2681
2559
|
rootHttpRouter: backendPluginApi.coreServices.rootHttpRouter,
|
|
2682
2560
|
httpAuth: backendPluginApi.coreServices.httpAuth
|
|
2683
2561
|
},
|
|
2684
|
-
async factory({
|
|
2685
|
-
httpAuth,
|
|
2686
|
-
config,
|
|
2687
|
-
cache,
|
|
2688
|
-
plugin,
|
|
2689
|
-
rootHttpRouter,
|
|
2690
|
-
lifecycle
|
|
2691
|
-
}) {
|
|
2562
|
+
async factory({ httpAuth, config, plugin, rootHttpRouter, lifecycle }) {
|
|
2692
2563
|
var _a;
|
|
2693
2564
|
const getPath = (_a = options == null ? void 0 : options.getPath) != null ? _a : (id) => `/api/${id}`;
|
|
2694
2565
|
const path = getPath(plugin.getId());
|
|
2695
|
-
const router = PromiseRouter__default
|
|
2566
|
+
const router = PromiseRouter__default.default();
|
|
2696
2567
|
rootHttpRouter.use(path, router);
|
|
2697
|
-
const credentialsBarrier = createCredentialsBarrier({
|
|
2698
|
-
httpAuth,
|
|
2699
|
-
config,
|
|
2700
|
-
cache
|
|
2701
|
-
});
|
|
2568
|
+
const credentialsBarrier = createCredentialsBarrier({ httpAuth, config });
|
|
2702
2569
|
router.use(createLifecycleMiddleware({ lifecycle }));
|
|
2703
2570
|
router.use(credentialsBarrier.middleware);
|
|
2704
2571
|
return {
|
|
@@ -2777,7 +2644,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
2777
2644
|
};
|
|
2778
2645
|
var _indexPath, _router, _namedRoutes, _indexRouter, _existingPaths, _findConflictingPath, findConflictingPath_fn;
|
|
2779
2646
|
function normalizePath(path) {
|
|
2780
|
-
return `${trimEnd__default
|
|
2647
|
+
return `${trimEnd__default.default(path, "/")}/`;
|
|
2781
2648
|
}
|
|
2782
2649
|
const _DefaultRootHttpRouter = class _DefaultRootHttpRouter {
|
|
2783
2650
|
constructor(indexPath) {
|
|
@@ -2868,7 +2735,7 @@ const rootHttpRouterServiceFactory = backendPluginApi.createServiceFactory(
|
|
|
2868
2735
|
async factory({ config, rootLogger, lifecycle }) {
|
|
2869
2736
|
const { indexPath, configure = defaultConfigure } = options != null ? options : {};
|
|
2870
2737
|
const logger = rootLogger.child({ service: "rootHttpRouter" });
|
|
2871
|
-
const app = express__default
|
|
2738
|
+
const app = express__default.default();
|
|
2872
2739
|
const router = DefaultRootHttpRouter.create({ indexPath });
|
|
2873
2740
|
const middleware = MiddlewareFactory.create({ config, logger });
|
|
2874
2741
|
configure({
|