@decohere/http 0.0.1-dev.130 → 0.0.1-dev.20261105.103
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/es6/src/routing/services/route-registry.js +5 -0
- package/package.json +9 -14
- package/commonjs/src/app/app.js +0 -166
- package/commonjs/src/app/index.js +0 -19
- package/commonjs/src/app/module.js +0 -17
- package/commonjs/src/auth/ability.js +0 -54
- package/commonjs/src/auth/auth.config.js +0 -23
- package/commonjs/src/auth/auth.extensions.js +0 -106
- package/commonjs/src/auth/auth.types.js +0 -65
- package/commonjs/src/auth/casl-authorization.service.js +0 -36
- package/commonjs/src/auth/index.js +0 -23
- package/commonjs/src/auth/principal-provider.js +0 -19
- package/commonjs/src/auth/safe-outbound-url.js +0 -102
- package/commonjs/src/auth/token-service.js +0 -151
- package/commonjs/src/builder/builder.js +0 -95
- package/commonjs/src/builder/index.js +0 -18
- package/commonjs/src/const.js +0 -86
- package/commonjs/src/health/health.controller.js +0 -75
- package/commonjs/src/health/health.extensions.js +0 -50
- package/commonjs/src/health/index.js +0 -21
- package/commonjs/src/health/readiness.service.js +0 -67
- package/commonjs/src/health/readiness.types.js +0 -7
- package/commonjs/src/hosting/hosted-service-host.js +0 -88
- package/commonjs/src/hosting/hosted-service.js +0 -11
- package/commonjs/src/hosting/index.js +0 -19
- package/commonjs/src/http/http.compression.js +0 -27
- package/commonjs/src/http/http.extensions.js +0 -269
- package/commonjs/src/http/http.options.js +0 -26
- package/commonjs/src/http/http.options.store.js +0 -20
- package/commonjs/src/http/http.security.js +0 -27
- package/commonjs/src/http/http.static.js +0 -248
- package/commonjs/src/http/index.js +0 -22
- package/commonjs/src/index.js +0 -27
- package/commonjs/src/openapi/index.js +0 -45
- package/commonjs/src/openapi/openapi.generator.js +0 -103
- package/commonjs/src/openapi/openapi.types.js +0 -4
- package/commonjs/src/openapi/request-schema.js +0 -187
- package/commonjs/src/openapi/request-validator.js +0 -85
- package/commonjs/src/providers/fastify.provider.js +0 -391
- package/commonjs/src/providers/index.js +0 -18
- package/commonjs/src/routing/decorators/argument.decorator.js +0 -49
- package/commonjs/src/routing/decorators/auth.decorator.js +0 -70
- package/commonjs/src/routing/decorators/controller.decorator.js +0 -16
- package/commonjs/src/routing/decorators/field.decorator.js +0 -25
- package/commonjs/src/routing/decorators/index.js +0 -24
- package/commonjs/src/routing/decorators/request.decorator.js +0 -30
- package/commonjs/src/routing/decorators/response.decorator.js +0 -34
- package/commonjs/src/routing/decorators/route.decorator.js +0 -67
- package/commonjs/src/routing/filters/exception-filter-host.js +0 -145
- package/commonjs/src/routing/filters/exception-filter.js +0 -28
- package/commonjs/src/routing/http.types.js +0 -99
- package/commonjs/src/routing/index.js +0 -25
- package/commonjs/src/routing/middleware/http-access-log.middleware.js +0 -47
- package/commonjs/src/routing/middleware/middleware.js +0 -20
- package/commonjs/src/routing/middleware/request-id.js +0 -30
- package/commonjs/src/routing/path.util.js +0 -51
- package/commonjs/src/routing/pipes/index.js +0 -18
- package/commonjs/src/routing/pipes/pipes.js +0 -145
- package/commonjs/src/routing/services/index.js +0 -18
- package/commonjs/src/routing/services/route-argument-resolver.js +0 -77
- package/commonjs/src/routing/services/route-registry.js +0 -194
- package/commonjs/src/routing/services/router.js +0 -158
- package/commonjs/src/sse/index.js +0 -26
- package/commonjs/src/sse/sse.decorator.js +0 -42
- package/commonjs/src/sse/sse.encoder.js +0 -73
- package/commonjs/src/sse/sse.types.js +0 -36
- package/commonjs/src/sse/sse.wire.js +0 -40
- package/commonjs/src/testing/boot-module.js +0 -38
- package/commonjs/src/testing/index.js +0 -20
- package/commonjs/src/testing/sse-reader.js +0 -98
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "assertSafeOutboundUrl", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return assertSafeOutboundUrl;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _promises = require("node:dns/promises");
|
|
12
|
-
const _nodenet = require("node:net");
|
|
13
|
-
async function assertSafeOutboundUrl(raw, label) {
|
|
14
|
-
let url;
|
|
15
|
-
try {
|
|
16
|
-
url = new URL(raw);
|
|
17
|
-
} catch {
|
|
18
|
-
throw new Error(`Invalid ${label}: ${raw}`);
|
|
19
|
-
}
|
|
20
|
-
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
21
|
-
throw new Error(`${label} must use http or https (got ${url.protocol})`);
|
|
22
|
-
}
|
|
23
|
-
if (url.username || url.password) {
|
|
24
|
-
throw new Error(`${label} must not include credentials`);
|
|
25
|
-
}
|
|
26
|
-
const hostname = url.hostname.replace(/^\[|\]$/g, "");
|
|
27
|
-
if (isBlockedHostname(hostname)) {
|
|
28
|
-
throw new Error(`${label} host is not allowed (${hostname})`);
|
|
29
|
-
}
|
|
30
|
-
const ips = await resolveIps(hostname);
|
|
31
|
-
const allowLoopback = isLoopbackAllowed();
|
|
32
|
-
for (const ip of ips){
|
|
33
|
-
if (isBlockedIp(ip, allowLoopback)) {
|
|
34
|
-
throw new Error(`${label} resolves to a blocked address (${ip})`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (url.protocol === "http:") {
|
|
38
|
-
const loopbackOnly = isLoopbackHostname(hostname) || ips.length > 0 && ips.every((ip)=>isLoopbackIp(ip));
|
|
39
|
-
if (!loopbackOnly || !allowLoopback) {
|
|
40
|
-
throw new Error(`${label} must use https unless targeting loopback in development/test`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
function isLoopbackAllowed() {
|
|
46
|
-
const env = process.env.NODE_ENV ?? "";
|
|
47
|
-
return env === "development" || env === "dev" || env === "test";
|
|
48
|
-
}
|
|
49
|
-
function isLoopbackHostname(hostname) {
|
|
50
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
|
|
51
|
-
}
|
|
52
|
-
function isBlockedHostname(hostname) {
|
|
53
|
-
const lower = hostname.toLowerCase();
|
|
54
|
-
return lower === "metadata.google.internal" || lower === "metadata" || lower.endsWith(".metadata.google.internal");
|
|
55
|
-
}
|
|
56
|
-
async function resolveIps(hostname) {
|
|
57
|
-
if ((0, _nodenet.isIP)(hostname)) {
|
|
58
|
-
return [
|
|
59
|
-
hostname
|
|
60
|
-
];
|
|
61
|
-
}
|
|
62
|
-
const results = await (0, _promises.lookup)(hostname, {
|
|
63
|
-
all: true,
|
|
64
|
-
verbatim: true
|
|
65
|
-
});
|
|
66
|
-
return results.map((r)=>r.address);
|
|
67
|
-
}
|
|
68
|
-
function isLoopbackIp(ip) {
|
|
69
|
-
const list = new _nodenet.BlockList();
|
|
70
|
-
list.addSubnet("127.0.0.0", 8, "ipv4");
|
|
71
|
-
list.addAddress("::1", "ipv6");
|
|
72
|
-
list.addSubnet("::ffff:127.0.0.0", 104, "ipv6");
|
|
73
|
-
return list.check(ip);
|
|
74
|
-
}
|
|
75
|
-
function isBlockedIp(ip, allowLoopback) {
|
|
76
|
-
if (allowLoopback && isLoopbackIp(ip)) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
const list = new _nodenet.BlockList();
|
|
80
|
-
// IPv4 special-use / private
|
|
81
|
-
list.addSubnet("0.0.0.0", 8, "ipv4");
|
|
82
|
-
list.addSubnet("10.0.0.0", 8, "ipv4");
|
|
83
|
-
list.addSubnet("100.64.0.0", 10, "ipv4"); // shared address space
|
|
84
|
-
list.addSubnet("127.0.0.0", 8, "ipv4");
|
|
85
|
-
list.addSubnet("169.254.0.0", 16, "ipv4"); // link-local / cloud metadata
|
|
86
|
-
list.addSubnet("172.16.0.0", 12, "ipv4");
|
|
87
|
-
list.addSubnet("192.168.0.0", 16, "ipv4");
|
|
88
|
-
list.addSubnet("198.18.0.0", 15, "ipv4"); // benchmarking
|
|
89
|
-
// IPv6
|
|
90
|
-
list.addAddress("::1", "ipv6");
|
|
91
|
-
list.addSubnet("fc00::", 7, "ipv6"); // unique local
|
|
92
|
-
list.addSubnet("fe80::", 10, "ipv6"); // link-local
|
|
93
|
-
if (list.check(ip)) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
// Mapped IPv4 inside IPv6 (::ffff:a.b.c.d)
|
|
97
|
-
const mapped = ip.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
|
|
98
|
-
if (mapped) {
|
|
99
|
-
return isBlockedIp(mapped[1], allowLoopback);
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "TokenService", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TokenService;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _jose = require("jose");
|
|
12
|
-
const _httptypes = require("../routing/http.types.js");
|
|
13
|
-
const _ability = require("./ability.js");
|
|
14
|
-
const _authtypes = require("./auth.types.js");
|
|
15
|
-
const _safeoutboundurl = require("./safe-outbound-url.js");
|
|
16
|
-
class TokenService {
|
|
17
|
-
config;
|
|
18
|
-
principalMapper;
|
|
19
|
-
/** Lazily resolved JWKS set when using OIDC discovery. */ discoveryJwks;
|
|
20
|
-
discoveryIssuer;
|
|
21
|
-
/** Remote key set for `jwksUrl` mode, created once so jose can cache the keys. */ configuredJwks;
|
|
22
|
-
constructor(config, principalMapper){
|
|
23
|
-
if ((0, _authtypes.isDevStaticConfig)(config)) {
|
|
24
|
-
(0, _authtypes.assertDevStaticAllowed)();
|
|
25
|
-
} else {
|
|
26
|
-
(0, _authtypes.assertNonEmptyAudience)(config.audience);
|
|
27
|
-
}
|
|
28
|
-
this.config = config;
|
|
29
|
-
this.principalMapper = principalMapper;
|
|
30
|
-
}
|
|
31
|
-
async verifyRequest(request) {
|
|
32
|
-
const authHeader = request.headers.authorization;
|
|
33
|
-
if (!authHeader) {
|
|
34
|
-
throw new _httptypes.UnauthorizedError("Missing Authorization header");
|
|
35
|
-
}
|
|
36
|
-
const spaceIdx = authHeader.indexOf(" ");
|
|
37
|
-
if (spaceIdx === -1) {
|
|
38
|
-
throw new _httptypes.UnauthorizedError("Malformed Authorization header");
|
|
39
|
-
}
|
|
40
|
-
const scheme = authHeader.slice(0, spaceIdx);
|
|
41
|
-
if (scheme !== "Bearer") {
|
|
42
|
-
throw new _httptypes.UnauthorizedError(`Unsupported authorization scheme: ${scheme}`);
|
|
43
|
-
}
|
|
44
|
-
const credentials = authHeader.slice(spaceIdx + 1);
|
|
45
|
-
return this.verify(credentials);
|
|
46
|
-
}
|
|
47
|
-
async verify(credentials) {
|
|
48
|
-
if ((0, _authtypes.isDevStaticConfig)(this.config)) {
|
|
49
|
-
return this.config.devStatic;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const { key, issuer, audience } = await this.resolveVerificationContext();
|
|
53
|
-
// jose's overloads don't accept Key | JWKS-getter as a union; runtime does.
|
|
54
|
-
const { payload } = await (0, _jose.jwtVerify)(credentials, key, {
|
|
55
|
-
issuer,
|
|
56
|
-
audience
|
|
57
|
-
});
|
|
58
|
-
return this.mapPrincipal(payload);
|
|
59
|
-
} catch (err) {
|
|
60
|
-
throw new _httptypes.UnauthorizedError(err instanceof Error ? err.message : "Token verification failed");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Resolve how to verify tokens for the configured strategy:
|
|
65
|
-
* - OIDC discovery → fetch JWKS + issuer from `/.well-known/openid-configuration`
|
|
66
|
-
* - explicit JWKS URL → remote key set + configured issuer/audience
|
|
67
|
-
* - public key / shared secret → static key material + configured issuer/audience
|
|
68
|
-
*/ async resolveVerificationContext() {
|
|
69
|
-
if ((0, _authtypes.isDiscoveryConfig)(this.config)) {
|
|
70
|
-
const { jwks, issuer } = await this.resolveOidcDiscovery();
|
|
71
|
-
return {
|
|
72
|
-
key: jwks,
|
|
73
|
-
issuer,
|
|
74
|
-
audience: this.config.audience
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
if ((0, _authtypes.isJwksConfig)(this.config)) {
|
|
78
|
-
this.configuredJwks ??= (0, _jose.createRemoteJWKSet)(await (0, _safeoutboundurl.assertSafeOutboundUrl)(this.config.jwksUrl, "jwksUrl"));
|
|
79
|
-
return {
|
|
80
|
-
key: this.configuredJwks,
|
|
81
|
-
issuer: this.config.issuer,
|
|
82
|
-
audience: this.config.audience
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
key: await this.getStaticKey(),
|
|
87
|
-
issuer: this.config.issuer,
|
|
88
|
-
audience: this.config.audience
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
async resolveOidcDiscovery() {
|
|
92
|
-
if (this.discoveryJwks && this.discoveryIssuer) {
|
|
93
|
-
return {
|
|
94
|
-
jwks: this.discoveryJwks,
|
|
95
|
-
issuer: this.discoveryIssuer
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const { discoveryUrl } = this.config;
|
|
99
|
-
await (0, _safeoutboundurl.assertSafeOutboundUrl)(discoveryUrl, "discoveryUrl");
|
|
100
|
-
const resp = await fetch(`${discoveryUrl.replace(/\/$/, "")}/.well-known/openid-configuration`, {
|
|
101
|
-
redirect: "error"
|
|
102
|
-
});
|
|
103
|
-
if (!resp.ok) {
|
|
104
|
-
throw new Error(`OIDC discovery failed for ${discoveryUrl}: HTTP ${resp.status}`);
|
|
105
|
-
}
|
|
106
|
-
const doc = await resp.json();
|
|
107
|
-
if (typeof doc.jwks_uri !== "string" || doc.jwks_uri.length === 0) {
|
|
108
|
-
throw new Error(`OIDC discovery for ${discoveryUrl} did not return jwks_uri`);
|
|
109
|
-
}
|
|
110
|
-
const jwksUrl = await (0, _safeoutboundurl.assertSafeOutboundUrl)(doc.jwks_uri, "jwks_uri");
|
|
111
|
-
this.discoveryIssuer = doc.issuer;
|
|
112
|
-
this.discoveryJwks = (0, _jose.createRemoteJWKSet)(jwksUrl);
|
|
113
|
-
return {
|
|
114
|
-
jwks: this.discoveryJwks,
|
|
115
|
-
issuer: this.discoveryIssuer
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Sign a payload and return a JWT string.
|
|
120
|
-
* Only available when configured with a SecretConfig (HS256).
|
|
121
|
-
* For RS256/ES256 issuance, the caller is responsible for key management.
|
|
122
|
-
*/ async sign(payload, expiresIn = "1h") {
|
|
123
|
-
if (!(0, _authtypes.isSecretConfig)(this.config)) {
|
|
124
|
-
throw new Error("TokenService.sign() requires SecretConfig (shared secret / HS256)");
|
|
125
|
-
}
|
|
126
|
-
const key = new TextEncoder().encode(this.config.secret);
|
|
127
|
-
return new _jose.SignJWT(payload).setProtectedHeader({
|
|
128
|
-
alg: "HS256"
|
|
129
|
-
}).setIssuedAt().setIssuer(this.config.issuer ?? "").setAudience(this.config.audience ?? "").setExpirationTime(expiresIn).sign(key);
|
|
130
|
-
}
|
|
131
|
-
async getStaticKey() {
|
|
132
|
-
if ((0, _authtypes.isPublicKeyConfig)(this.config)) {
|
|
133
|
-
const cfg = this.config;
|
|
134
|
-
const trimmed = cfg.publicKey.trim();
|
|
135
|
-
if (trimmed.startsWith("{")) {
|
|
136
|
-
const jwk = JSON.parse(trimmed);
|
|
137
|
-
return (0, _jose.importJWK)(jwk);
|
|
138
|
-
}
|
|
139
|
-
return (0, _jose.importSPKI)(trimmed, cfg.algorithms?.[0] ?? "RS256");
|
|
140
|
-
}
|
|
141
|
-
if ((0, _authtypes.isSecretConfig)(this.config)) {
|
|
142
|
-
const enc = new TextEncoder().encode(this.config.secret);
|
|
143
|
-
return enc;
|
|
144
|
-
}
|
|
145
|
-
throw new Error("Invalid TokenService configuration");
|
|
146
|
-
}
|
|
147
|
-
mapPrincipal(payload) {
|
|
148
|
-
if (this.principalMapper) return this.principalMapper(payload);
|
|
149
|
-
return (0, _ability.createPrincipalFromPayload)(payload);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Builder", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Builder;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _crucible = require("@decohere/crucible");
|
|
12
|
-
const _configuration = require("@decohere/core/configuration");
|
|
13
|
-
const _scribe = require("@decohere/scribe");
|
|
14
|
-
const _app = require("../app/app.js");
|
|
15
|
-
const _const = require("../const.js");
|
|
16
|
-
const _hostedservicehost = require("../hosting/hosted-service-host.js");
|
|
17
|
-
class Builder {
|
|
18
|
-
static create(options) {
|
|
19
|
-
return new Builder(options);
|
|
20
|
-
}
|
|
21
|
-
containerBuilder;
|
|
22
|
-
applicationName;
|
|
23
|
-
logger = _scribe.scribe.logger("name");
|
|
24
|
-
userServices = [];
|
|
25
|
-
preBuildSteps = [];
|
|
26
|
-
postBuildSteps = [];
|
|
27
|
-
hostedServices = new _hostedservicehost.HostedServiceHost();
|
|
28
|
-
constructor(options){
|
|
29
|
-
this.containerBuilder = options?.containerBuilder ?? new _crucible.ServiceContainerBuilder();
|
|
30
|
-
this.applicationName = options?.applicationName;
|
|
31
|
-
}
|
|
32
|
-
withServices(userServices) {
|
|
33
|
-
this.userServices.push(userServices);
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Run {@link HostedService}s for the life of the app: started in this order before the HTTP
|
|
38
|
-
* server listens, stopped in reverse when the app stops (including SIGTERM and Flux reboots).
|
|
39
|
-
* Each is registered as a singleton, so other services can inject it by its class.
|
|
40
|
-
*/ withHostedService(...types) {
|
|
41
|
-
for (const type of types)this.containerBuilder.registerSingleton(type);
|
|
42
|
-
this.hostedServices.add(...types);
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
registerPreBuildStep(step) {
|
|
46
|
-
this.preBuildSteps.push(step);
|
|
47
|
-
}
|
|
48
|
-
registerPostBuildStep(step) {
|
|
49
|
-
this.postBuildSteps.push(step);
|
|
50
|
-
}
|
|
51
|
-
async buildAndStart(type) {
|
|
52
|
-
const app = await this.build(type);
|
|
53
|
-
await app.start();
|
|
54
|
-
this.logger.info("App started...");
|
|
55
|
-
return app;
|
|
56
|
-
}
|
|
57
|
-
async build(type) {
|
|
58
|
-
this.logger.info("Building App...");
|
|
59
|
-
this.configureUserServices();
|
|
60
|
-
this.configureApp(type);
|
|
61
|
-
await this.runPreBuildSteps(this.containerBuilder);
|
|
62
|
-
const container = this.containerBuilder.build();
|
|
63
|
-
await this.runPostBuildSteps(container);
|
|
64
|
-
const app = this.resolveApp(container, type);
|
|
65
|
-
return app;
|
|
66
|
-
}
|
|
67
|
-
configureUserServices() {
|
|
68
|
-
for (const userService of this.userServices){
|
|
69
|
-
userService(this.containerBuilder);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async runPreBuildSteps(containerBuilder) {
|
|
73
|
-
if (this.preBuildSteps.length === 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const container = containerBuilder.build();
|
|
77
|
-
const config = container.resolve(_configuration.ConfigurationServiceToken);
|
|
78
|
-
for (const step of this.preBuildSteps){
|
|
79
|
-
await step(config, containerBuilder);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async runPostBuildSteps(container) {
|
|
83
|
-
for (const step of this.postBuildSteps){
|
|
84
|
-
await step(container);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
configureApp(type) {
|
|
88
|
-
this.containerBuilder.registerSingleton(_const.HostedServiceHostToken, this.hostedServices);
|
|
89
|
-
this.containerBuilder.registerSingleton(type ?? _app.App);
|
|
90
|
-
}
|
|
91
|
-
resolveApp(container, type) {
|
|
92
|
-
const app = type ? container.resolve(type) : container.resolve(_app.App);
|
|
93
|
-
return app;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./builder.js"), exports);
|
|
6
|
-
function _export_star(from, to) {
|
|
7
|
-
Object.keys(from).forEach(function(k) {
|
|
8
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
-
Object.defineProperty(to, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return from[k];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return from;
|
|
18
|
-
}
|
package/commonjs/src/const.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get AuthorizationServiceToken () {
|
|
13
|
-
return AuthorizationServiceToken;
|
|
14
|
-
},
|
|
15
|
-
get ExceptionFilterHostToken () {
|
|
16
|
-
return ExceptionFilterHostToken;
|
|
17
|
-
},
|
|
18
|
-
get HTTPMethods () {
|
|
19
|
-
return HTTPMethods;
|
|
20
|
-
},
|
|
21
|
-
get HostedServiceHostToken () {
|
|
22
|
-
return HostedServiceHostToken;
|
|
23
|
-
},
|
|
24
|
-
get HttpOptionsToken () {
|
|
25
|
-
return HttpOptionsToken;
|
|
26
|
-
},
|
|
27
|
-
get HttpProviderToken () {
|
|
28
|
-
return HttpProviderToken;
|
|
29
|
-
},
|
|
30
|
-
get IPrincipalProviderToken () {
|
|
31
|
-
return IPrincipalProviderToken;
|
|
32
|
-
},
|
|
33
|
-
get MetadataKeys () {
|
|
34
|
-
return MetadataKeys;
|
|
35
|
-
},
|
|
36
|
-
get PrincipalToken () {
|
|
37
|
-
return PrincipalToken;
|
|
38
|
-
},
|
|
39
|
-
get ReadinessCheckToken () {
|
|
40
|
-
return ReadinessCheckToken;
|
|
41
|
-
},
|
|
42
|
-
get ReadinessServiceToken () {
|
|
43
|
-
return ReadinessServiceToken;
|
|
44
|
-
},
|
|
45
|
-
get RouteRegistryToken () {
|
|
46
|
-
return RouteRegistryToken;
|
|
47
|
-
},
|
|
48
|
-
get RouterToken () {
|
|
49
|
-
return RouterToken;
|
|
50
|
-
},
|
|
51
|
-
get TokenServiceToken () {
|
|
52
|
-
return TokenServiceToken;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
const RoutingKey = "http:Routing";
|
|
56
|
-
const RouteRegistryToken = Symbol("RouteRegistryToken");
|
|
57
|
-
const HttpProviderToken = Symbol("HttpProviderToken");
|
|
58
|
-
const RouterToken = Symbol("RouterToken");
|
|
59
|
-
const PrincipalToken = Symbol("PrincipalToken");
|
|
60
|
-
const IPrincipalProviderToken = Symbol("IPrincipalProvider");
|
|
61
|
-
const TokenServiceToken = Symbol("TokenService");
|
|
62
|
-
const AuthorizationServiceToken = Symbol("AuthorizationService");
|
|
63
|
-
const HttpOptionsToken = Symbol("HttpOptions");
|
|
64
|
-
const ExceptionFilterHostToken = Symbol("ExceptionFilterHost");
|
|
65
|
-
const ReadinessCheckToken = Symbol("ReadinessCheck");
|
|
66
|
-
const ReadinessServiceToken = Symbol("ReadinessService");
|
|
67
|
-
const HostedServiceHostToken = Symbol("HostedServiceHost");
|
|
68
|
-
const HTTPMethods = {
|
|
69
|
-
GET: "GET",
|
|
70
|
-
PUT: "PUT",
|
|
71
|
-
POST: "POST",
|
|
72
|
-
PATCH: "PATCH",
|
|
73
|
-
DELETE: "DELETE"
|
|
74
|
-
};
|
|
75
|
-
const MetadataKeys = {
|
|
76
|
-
controller: `${RoutingKey}:controller`,
|
|
77
|
-
route: `${RoutingKey}:route`,
|
|
78
|
-
parameter: `${RoutingKey}:parameter`,
|
|
79
|
-
fieldMap: `${RoutingKey}:fieldMap`,
|
|
80
|
-
authorize: `${RoutingKey}:authorize`,
|
|
81
|
-
allowAnonymous: `${RoutingKey}:allowAnonymous`,
|
|
82
|
-
httpCode: `${RoutingKey}:httpCode`,
|
|
83
|
-
headers: `${RoutingKey}:headers`,
|
|
84
|
-
catch: `${RoutingKey}:catch`,
|
|
85
|
-
sse: `${RoutingKey}:sse`
|
|
86
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "HealthController", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return HealthController;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _decorators = require("@decohere/crucible/decorators");
|
|
12
|
-
const _const = require("../const.js");
|
|
13
|
-
const _httptypes = require("../routing/http.types.js");
|
|
14
|
-
const _index = require("../routing/index.js");
|
|
15
|
-
const _readinessservice = require("./readiness.service.js");
|
|
16
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
17
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
19
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
20
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
-
}
|
|
22
|
-
function _ts_metadata(k, v) {
|
|
23
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
24
|
-
}
|
|
25
|
-
function _ts_param(paramIndex, decorator) {
|
|
26
|
-
return function(target, key) {
|
|
27
|
-
decorator(target, key, paramIndex);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
class HealthController {
|
|
31
|
-
readiness;
|
|
32
|
-
constructor(readiness){
|
|
33
|
-
this.readiness = readiness;
|
|
34
|
-
}
|
|
35
|
-
health() {
|
|
36
|
-
return {
|
|
37
|
-
status: "ok"
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
async ready() {
|
|
41
|
-
const result = await this.readiness.checkAll();
|
|
42
|
-
if (!result.ok) {
|
|
43
|
-
throw new _httptypes.HttpError("Not ready", 503);
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
status: "ok"
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
_ts_decorate([
|
|
51
|
-
(0, _index.AllowAnonymous)(),
|
|
52
|
-
(0, _index.Get)("/health"),
|
|
53
|
-
_ts_metadata("design:type", Function),
|
|
54
|
-
_ts_metadata("design:paramtypes", []),
|
|
55
|
-
_ts_metadata("design:returntype", void 0)
|
|
56
|
-
], HealthController.prototype, "health", null);
|
|
57
|
-
_ts_decorate([
|
|
58
|
-
(0, _index.AllowAnonymous)(),
|
|
59
|
-
(0, _index.Get)("/ready"),
|
|
60
|
-
_ts_metadata("design:type", Function),
|
|
61
|
-
_ts_metadata("design:paramtypes", []),
|
|
62
|
-
_ts_metadata("design:returntype", Promise)
|
|
63
|
-
], HealthController.prototype, "ready", null);
|
|
64
|
-
HealthController = _ts_decorate([
|
|
65
|
-
(0, _index.Controller)({
|
|
66
|
-
prefix: "/",
|
|
67
|
-
globalPrefix: false
|
|
68
|
-
}),
|
|
69
|
-
(0, _decorators.injectable)(),
|
|
70
|
-
_ts_param(0, (0, _decorators.inject)(_const.ReadinessServiceToken)),
|
|
71
|
-
_ts_metadata("design:type", Function),
|
|
72
|
-
_ts_metadata("design:paramtypes", [
|
|
73
|
-
typeof _readinessservice.ReadinessService === "undefined" ? Object : _readinessservice.ReadinessService
|
|
74
|
-
])
|
|
75
|
-
], HealthController);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "BuilderExtensions", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return BuilderExtensions;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _extensibility = require("@decohere/core/extensibility");
|
|
12
|
-
const _builder = require("../builder/builder.js");
|
|
13
|
-
const _const = require("../const.js");
|
|
14
|
-
require("../http/http.extensions.js");
|
|
15
|
-
const _httpoptionsstore = require("../http/http.options.store.js");
|
|
16
|
-
const _healthcontroller = require("./health.controller.js");
|
|
17
|
-
const _readinessservice = require("./readiness.service.js");
|
|
18
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
}
|
|
24
|
-
function _ts_metadata(k, v) {
|
|
25
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
26
|
-
}
|
|
27
|
-
class BuilderExtensions {
|
|
28
|
-
static withHealth(builder, options) {
|
|
29
|
-
builder.withServices((containerBuilder)=>{
|
|
30
|
-
containerBuilder.registerSingleton(_const.ReadinessServiceToken, _readinessservice.ReadinessService);
|
|
31
|
-
for (const check of options?.checks ?? []){
|
|
32
|
-
containerBuilder.registerSingleton(_const.ReadinessCheckToken, check);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
if (options?.underGlobalPrefix === true) {
|
|
36
|
-
(0, _httpoptionsstore.getOrCreateHttpOptions)(builder).underGlobalPrefix.add(_healthcontroller.HealthController);
|
|
37
|
-
}
|
|
38
|
-
builder.withControllers(_healthcontroller.HealthController);
|
|
39
|
-
return builder;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
_ts_decorate([
|
|
43
|
-
(0, _extensibility.extension)(_builder.Builder),
|
|
44
|
-
_ts_metadata("design:type", Function),
|
|
45
|
-
_ts_metadata("design:paramtypes", [
|
|
46
|
-
typeof _builder.Builder === "undefined" ? Object : _builder.Builder,
|
|
47
|
-
typeof WithHealthOptions === "undefined" ? Object : WithHealthOptions
|
|
48
|
-
]),
|
|
49
|
-
_ts_metadata("design:returntype", void 0)
|
|
50
|
-
], BuilderExtensions, "withHealth", null);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./health.controller.js"), exports);
|
|
6
|
-
_export_star(require("./health.extensions.js"), exports);
|
|
7
|
-
_export_star(require("./readiness.service.js"), exports);
|
|
8
|
-
_export_star(require("./readiness.types.js"), exports);
|
|
9
|
-
function _export_star(from, to) {
|
|
10
|
-
Object.keys(from).forEach(function(k) {
|
|
11
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
-
Object.defineProperty(to, k, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function() {
|
|
15
|
-
return from[k];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return from;
|
|
21
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "ReadinessService", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return ReadinessService;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _decorators = require("@decohere/crucible/decorators");
|
|
12
|
-
const _const = require("../const.js");
|
|
13
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
14
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
-
}
|
|
19
|
-
function _ts_metadata(k, v) {
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
|
-
}
|
|
22
|
-
function _ts_param(paramIndex, decorator) {
|
|
23
|
-
return function(target, key) {
|
|
24
|
-
decorator(target, key, paramIndex);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
class ReadinessService {
|
|
28
|
-
hostedServices;
|
|
29
|
-
checks;
|
|
30
|
-
constructor(checks = [], hostedServices){
|
|
31
|
-
this.hostedServices = hostedServices;
|
|
32
|
-
this.checks = checks;
|
|
33
|
-
}
|
|
34
|
-
/** Registered checks, then each started hosted service that has a `check()` (still warming up). */ async checkAll() {
|
|
35
|
-
const failures = [];
|
|
36
|
-
const probes = [
|
|
37
|
-
...this.checks,
|
|
38
|
-
...this.hostedServices?.readinessChecks() ?? []
|
|
39
|
-
];
|
|
40
|
-
for (const probe of probes){
|
|
41
|
-
try {
|
|
42
|
-
await probe.check();
|
|
43
|
-
} catch {
|
|
44
|
-
failures.push(probe.name);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (failures.length > 0) {
|
|
48
|
-
return {
|
|
49
|
-
ok: false,
|
|
50
|
-
failures
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
ok: true
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
ReadinessService = _ts_decorate([
|
|
59
|
-
(0, _decorators.injectable)(),
|
|
60
|
-
_ts_param(0, (0, _decorators.inject)(_const.ReadinessCheckToken)),
|
|
61
|
-
_ts_param(1, (0, _decorators.inject)(_const.HostedServiceHostToken)),
|
|
62
|
-
_ts_metadata("design:type", Function),
|
|
63
|
-
_ts_metadata("design:paramtypes", [
|
|
64
|
-
Array,
|
|
65
|
-
typeof HostedServiceHost === "undefined" ? Object : HostedServiceHost
|
|
66
|
-
])
|
|
67
|
-
], ReadinessService);
|