@intuitionrobotics/thunderstorm 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-backend/api/v1/utils/health/get.d.ts +4 -12
- package/dist/app-backend/api/v1/utils/health/get.d.ts.map +1 -1
- package/dist/app-backend/api/v1/utils/health/get.js +40 -50
- package/dist/app-backend/api/v1/utils/health/get.js.map +1 -1
- package/dist/app-backend/api/v1/utils/version/assert.d.ts +2 -8
- package/dist/app-backend/api/v1/utils/version/assert.d.ts.map +1 -1
- package/dist/app-backend/api/v1/utils/version/assert.js +7 -15
- package/dist/app-backend/api/v1/utils/version/assert.js.map +1 -1
- package/dist/app-backend/core/Storm.js +2 -2
- package/dist/app-backend/core/Storm.js.map +1 -1
- package/dist/app-backend/modules/server/HttpServer.js +2 -2
- package/dist/app-backend/modules/server/HttpServer.js.map +1 -1
- package/dist/app-backend/modules/server/app-middleware.d.ts +1 -1
- package/dist/app-backend/modules/server/app-middleware.js +4 -4
- package/dist/app-backend/modules/server/app-middleware.js.map +1 -1
- package/dist/app-backend/modules/server/handler.d.ts +8 -0
- package/dist/app-backend/modules/server/handler.d.ts.map +1 -1
- package/dist/app-backend/modules/server/handler.js +18 -3
- package/dist/app-backend/modules/server/handler.js.map +1 -1
- package/dist/app-backend/modules/server/requireAuth.d.ts +19 -0
- package/dist/app-backend/modules/server/requireAuth.d.ts.map +1 -1
- package/dist/app-backend/modules/server/requireAuth.js +38 -0
- package/dist/app-backend/modules/server/requireAuth.js.map +1 -1
- package/dist/app-backend/modules/server/server-api.d.ts +6 -46
- package/dist/app-backend/modules/server/server-api.d.ts.map +1 -1
- package/dist/app-backend/modules/server/server-api.js +20 -186
- package/dist/app-backend/modules/server/server-api.js.map +1 -1
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +6 -5
- package/dist/backend.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare class ServerApi_Health_Class extends ServerApi<ApiTypeBinder<"health", HealthReport, void, {}>> {
|
|
6
|
-
private appVersion?;
|
|
7
|
-
constructor();
|
|
8
|
-
setVersion(version: string): this;
|
|
9
|
-
protected process(_request: ExpressRequest, response: ApiResponse): Promise<HealthReport>;
|
|
10
|
-
}
|
|
11
|
-
export declare const ServerApi_Health: ServerApi_Health_Class;
|
|
12
|
-
export default ServerApi_Health;
|
|
1
|
+
import { type RequestHandler } from "express";
|
|
2
|
+
export declare const healthHandler: (opts?: {
|
|
3
|
+
version?: string;
|
|
4
|
+
}) => RequestHandler;
|
|
13
5
|
//# sourceMappingURL=get.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/health/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/health/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,cAAc,EAAC,MAAM,SAAS,CAAC;AA8B5C,eAAO,MAAM,aAAa,GAAI,OAAM;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,KAAG,cAuClC,CAAC"}
|
|
@@ -1,67 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {} from "
|
|
1
|
+
import {} from "express";
|
|
2
|
+
import { handler } from "../../../../modules/server/handler.js";
|
|
3
|
+
import {} from "../../../../../shared/types.js";
|
|
4
4
|
import { Storm } from "../../../../core/Storm.js";
|
|
5
5
|
import { currentTimeMillies } from "@intuitionrobotics/ts-common";
|
|
6
6
|
import { isHealthCheckContributor } from "../../../../../shared/health.js";
|
|
7
7
|
const statusRank = { pass: 0, warn: 1, fail: 2 };
|
|
8
8
|
const worse = (a, b) => (statusRank[a] >= statusRank[b] ? a : b);
|
|
9
|
-
// Smart, transparent health endpoint.
|
|
9
|
+
// Smart, transparent health endpoint — the raw-Express `handler(fn)` form.
|
|
10
10
|
//
|
|
11
11
|
// TRANSPARENT — the framework never injects this for you. Mount it explicitly
|
|
12
12
|
// from your routes file (one visible line), choosing your own path:
|
|
13
13
|
//
|
|
14
|
-
// import {
|
|
15
|
-
// v1.get("/health",
|
|
16
|
-
// v1.get("/health",
|
|
14
|
+
// import {healthHandler} from "@intuitionrobotics/thunderstorm/backend";
|
|
15
|
+
// v1.get("/health", healthHandler()); // or
|
|
16
|
+
// v1.get("/health", healthHandler({version}));
|
|
17
17
|
//
|
|
18
18
|
// SMART — it enumerates every loaded Storm module and reports env / node /
|
|
19
19
|
// uptime. Any module implementing HealthCheckContributor (getHealth())
|
|
20
20
|
// contributes real subsystem health; the overall status is the worst of them,
|
|
21
21
|
// and a "fail" is reflected as HTTP 503 so load balancers / uptime probes can
|
|
22
22
|
// gate on it.
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export const healthHandler = (opts = {}) => handler(async (_req, res) => {
|
|
24
|
+
const storm = Storm?.getInstance();
|
|
25
|
+
const modules = storm ? storm.filterModules(() => true) : [];
|
|
26
|
+
const moduleHealth = await Promise.all(modules.map(async (module) => {
|
|
27
|
+
const name = module.getName();
|
|
28
|
+
if (!isHealthCheckContributor(module))
|
|
29
|
+
return { name, status: "pass" };
|
|
30
|
+
try {
|
|
31
|
+
const contribution = await module.getHealth();
|
|
32
|
+
return { name, status: contribution.status, detail: contribution.detail };
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
return { name, status: "fail", detail: e?.message ?? "getHealth() threw" };
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
const status = moduleHealth.reduce((worst, m) => worse(worst, m.status), "pass");
|
|
39
|
+
const report = {
|
|
40
|
+
status,
|
|
41
|
+
env: storm?.getEnvironment() ?? "unknown",
|
|
42
|
+
node: process.version,
|
|
43
|
+
uptimeSec: Math.floor(process.uptime()),
|
|
44
|
+
timestamp: currentTimeMillies(),
|
|
45
|
+
modules: moduleHealth,
|
|
46
|
+
version: opts.version
|
|
47
|
+
};
|
|
48
|
+
// A failing health check must surface as 503 (probes gate on it); writing
|
|
49
|
+
// res directly makes handler()'s autoSend a no-op. Otherwise return the
|
|
50
|
+
// report and autoSend emits 200.
|
|
51
|
+
if (status === "fail") {
|
|
52
|
+
res.status(503).json(report);
|
|
53
|
+
return;
|
|
28
54
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
async process(_request, response) {
|
|
34
|
-
const storm = Storm.getInstance();
|
|
35
|
-
const modules = storm ? storm.filterModules(() => true) : [];
|
|
36
|
-
const moduleHealth = await Promise.all(modules.map(async (module) => {
|
|
37
|
-
const name = module.getName();
|
|
38
|
-
if (!isHealthCheckContributor(module))
|
|
39
|
-
return { name, status: "pass" };
|
|
40
|
-
try {
|
|
41
|
-
const contribution = await module.getHealth();
|
|
42
|
-
return { name, status: contribution.status, detail: contribution.detail };
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
return { name, status: "fail", detail: e?.message ?? "getHealth() threw" };
|
|
46
|
-
}
|
|
47
|
-
}));
|
|
48
|
-
const status = moduleHealth.reduce((worst, m) => worse(worst, m.status), "pass");
|
|
49
|
-
const report = {
|
|
50
|
-
status,
|
|
51
|
-
env: storm?.getEnvironment() ?? "unknown",
|
|
52
|
-
node: process.version,
|
|
53
|
-
uptimeSec: Math.floor(process.uptime()),
|
|
54
|
-
timestamp: currentTimeMillies(),
|
|
55
|
-
modules: moduleHealth,
|
|
56
|
-
version: this.appVersion
|
|
57
|
-
};
|
|
58
|
-
// Consuming the response here with 503 is safe: ServerApi.call() checks
|
|
59
|
-
// isConsumed() before it would otherwise send the 200 itself.
|
|
60
|
-
if (status === "fail")
|
|
61
|
-
response.json(503, report);
|
|
62
|
-
return report;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export const ServerApi_Health = new ServerApi_Health_Class();
|
|
66
|
-
export default ServerApi_Health;
|
|
55
|
+
return report;
|
|
56
|
+
}, { printResponse: false });
|
|
67
57
|
//# sourceMappingURL=get.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/health/get.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/health/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAC,OAAO,EAAC,MAAM,uCAAuC,CAAC;AAC9D,OAAO,EAAoB,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,KAAK,EAAC,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAIH,wBAAwB,EAE3B,MAAM,iCAAiC,CAAC;AAEzC,MAAM,UAAU,GAAoC,EAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAC,CAAC;AAChF,MAAM,KAAK,GAAG,CAAC,CAAe,EAAE,CAAe,EAAgB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3G,2EAA2E;AAC3E,EAAE;AACF,8EAA8E;AAC9E,oEAAoE;AACpE,EAAE;AACF,2EAA2E;AAC3E,oEAAoE;AACpE,iDAAiD;AACjD,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,8EAA8E;AAC9E,8EAA8E;AAC9E,cAAc;AACd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,EAAE,OAAO,CAAC,OAAO;QACrB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACvC,SAAS,EAAE,kBAAkB,EAAE;QAC/B,OAAO,EAAE,YAAY;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;KACxB,CAAC;IAEF,0EAA0E;IAC1E,wEAAwE;IACxE,iCAAiC;IACjC,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACpB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO;IACX,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC,EAAE,EAAC,aAAa,EAAE,KAAK,EAAC,CAAC,CAAC"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
+
import { type TypedHandler } from "@intuitionrobotics/thunderstorm/backend";
|
|
1
2
|
import { type ApiBinder_AssertAppVersion } from "../../../../../shared/force-upgrade.js";
|
|
2
|
-
|
|
3
|
-
import { type ExpressRequest } from "../../../../utils/types.js";
|
|
4
|
-
declare class ServerApi_AssertAppVersion extends ServerApi<ApiBinder_AssertAppVersion> {
|
|
5
|
-
constructor();
|
|
6
|
-
protected process(request: ExpressRequest, _response: ApiResponse, _queryParams: {}, _body: void): Promise<import("../../../../../shared/force-upgrade.js").UpgradeRequired>;
|
|
7
|
-
}
|
|
8
|
-
declare const _default: ServerApi_AssertAppVersion;
|
|
9
|
-
export default _default;
|
|
3
|
+
export declare const assert: TypedHandler<ApiBinder_AssertAppVersion>;
|
|
10
4
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/version/assert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/version/assert.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,KAAK,YAAY,EAAsB,MAAM,yCAAyC,CAAC;AAC/F,OAAO,EAAC,KAAK,0BAA0B,EAAC,MAAM,wCAAwC,CAAC;AAEvF,eAAO,MAAM,MAAM,EAAE,YAAY,CAAC,0BAA0B,CAG3D,CAAC"}
|
|
@@ -18,19 +18,11 @@
|
|
|
18
18
|
* See the License for the specific language governing permissions and
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
super(HttpMethod.GET, "assert");
|
|
29
|
-
this.addHeaderToLog(HeaderKey_PlatformVersion, HeaderKey_PlatformName);
|
|
30
|
-
}
|
|
31
|
-
async process(request, _response, _queryParams, _body) {
|
|
32
|
-
return ForceUpgrade.compareVersion(request);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export default new ServerApi_AssertAppVersion();
|
|
21
|
+
import {} from "@intuitionrobotics/thunderstorm/backend";
|
|
22
|
+
import {} from "../../../../../shared/force-upgrade.js";
|
|
23
|
+
import { ForceUpgrade } from "../../../../modules/ForceUpgrade.js";
|
|
24
|
+
export const assert = async (req) => {
|
|
25
|
+
const request = req;
|
|
26
|
+
return ForceUpgrade.compareVersion(request);
|
|
27
|
+
};
|
|
36
28
|
//# sourceMappingURL=assert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/version/assert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../../../../src/main/app-backend/api/v1/utils/version/assert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAwC,MAAM,yCAAyC,CAAC;AAC/F,OAAO,EAAiC,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAC,YAAY,EAAC,MAAM,qCAAqC,CAAC;AACjE,MAAM,CAAC,MAAM,MAAM,GAA6C,KAAK,EAAE,GAAG,EAAE,EAAE;IAC1E,MAAM,OAAO,GAAG,GAAqB,CAAC;IACtC,OAAO,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { BadImplementationException, BeLogged, LogClient, LogClient_Function, Lo
|
|
|
2
2
|
import { FirebaseFunction } from '@intuitionrobotics/firebase/backend-functions';
|
|
3
3
|
import {} from "../modules/server/HttpServer.js";
|
|
4
4
|
import { ApiFunction } from "../modules/server/ApiFunction.js";
|
|
5
|
-
import {
|
|
5
|
+
import { apiDebug } from "../modules/server/server-api.js";
|
|
6
6
|
import { BaseStorm } from "./BaseStorm.js";
|
|
7
7
|
import {} from "express";
|
|
8
8
|
import { DefaultApiErrorMessageComposer } from "../modules/server/server-errors.js";
|
|
@@ -57,7 +57,7 @@ export class Storm extends BaseStorm {
|
|
|
57
57
|
}
|
|
58
58
|
init() {
|
|
59
59
|
BeLogged.addClient(process.env.GCLOUD_PROJECT && process.env.FUNCTIONS_EMULATOR ? LogClient_Terminal : this.logClient);
|
|
60
|
-
|
|
60
|
+
apiDebug.enabled = !!this.config?.isDebug;
|
|
61
61
|
// The backend NEVER eagerly initializes modules (deliberately not super.init()).
|
|
62
62
|
// Registration only wires references; module resources resolve lazily on first
|
|
63
63
|
// use, so a function's container only allocates what its handler actually touches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storm.js","sourceRoot":"","sources":["../../../src/main/app-backend/core/Storm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,QAAQ,EAAE,SAAS,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAC7I,OAAO,EAEH,gBAAgB,EAEnB,MAAM,+CAA+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;QACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import compression from 'compression';
|
|
2
2
|
import cors from 'cors';
|
|
3
3
|
import { addItemToArray, LogLevel, Module } from "@intuitionrobotics/ts-common";
|
|
4
|
-
import {
|
|
4
|
+
import { apiDebug } from "./server-api.js";
|
|
5
5
|
import { ApiException } from "../../exceptions.js";
|
|
6
6
|
import express from "express";
|
|
7
7
|
import { HeaderKey_FunctionExecutionId, HeaderKey_JWT } from '../_imports.js';
|
|
@@ -52,7 +52,7 @@ export class HttpServer_Class extends Module {
|
|
|
52
52
|
// infra, deliberately eager (and cheap), unlike app modules which must not
|
|
53
53
|
// override the (never-called) init().
|
|
54
54
|
setup() {
|
|
55
|
-
this.setMinLevel(
|
|
55
|
+
this.setMinLevel(apiDebug.enabled ? LogLevel.Verbose : LogLevel.Info);
|
|
56
56
|
if (this.config.baseUrl)
|
|
57
57
|
this.config.baseUrl = HttpServer_Class.normalizeBaseUrl(this.config.baseUrl);
|
|
58
58
|
this.express.use((req, _res, next) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpServer.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/HttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"HttpServer.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/HttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAE9E,OAAO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AAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAEjC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA;IAC9C,CAAC;IAED,uEAAuE;IACvE,sEAAsE;IACtE,oEAAoE;IACpE,sEAAsE;IACtE,yCAAyC;IACzC,EAAE;IACF,wEAAwE;IACxE,8EAA8E;IAC9E,0EAA0E;IACnE,WAAW,CAAC,MAAgC,EAAE,YAAoB,EAAE;QACvE,IAAI,SAAS;YACT,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;;YAEpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACJ;AAED,MAAM,OAAO,SAAS;IACD,GAAG,CAAS;IACZ,YAAY,CAAS;IAEtC,YAAY,GAAW,EAAE,eAAuB,GAAG;QAC/C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,GAAG,CAAC,OAAuB;QACvB,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK;YACN,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,4BAA4B,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAEtF,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
|
|
@@ -3,7 +3,7 @@ import { type ErrorRequestHandler } from "express";
|
|
|
3
3
|
* The single app-level error handler for raw (`handler()`-wrapped) endpoints.
|
|
4
4
|
* Register it LAST, after the router (see `ApiFunction`). It routes the error
|
|
5
5
|
* through the shared `composeApiError` pipeline, then writes the response with
|
|
6
|
-
* the same shape + `
|
|
6
|
+
* the same shape + `apiDebug.enabled` gating as `ApiResponse.serverError` /
|
|
7
7
|
* `ApiResponse.exception` (server-api.ts:428-440).
|
|
8
8
|
*
|
|
9
9
|
* Legacy `ServerApi` endpoints never reach here (they catch internally), so
|
|
@@ -2,7 +2,7 @@ import { Logger } from "@intuitionrobotics/ts-common";
|
|
|
2
2
|
import {} from "express";
|
|
3
3
|
import { parse } from "url";
|
|
4
4
|
import { composeApiError } from "./api-error.js";
|
|
5
|
-
import {
|
|
5
|
+
import { apiDebug } from "./server-api.js";
|
|
6
6
|
import { HttpMethod } from "../../../shared/types.js";
|
|
7
7
|
const logger = new Logger("terminalErrorHandler");
|
|
8
8
|
/**
|
|
@@ -24,7 +24,7 @@ function requestDataFrom(req) {
|
|
|
24
24
|
* The single app-level error handler for raw (`handler()`-wrapped) endpoints.
|
|
25
25
|
* Register it LAST, after the router (see `ApiFunction`). It routes the error
|
|
26
26
|
* through the shared `composeApiError` pipeline, then writes the response with
|
|
27
|
-
* the same shape + `
|
|
27
|
+
* the same shape + `apiDebug.enabled` gating as `ApiResponse.serverError` /
|
|
28
28
|
* `ApiResponse.exception` (server-api.ts:428-440).
|
|
29
29
|
*
|
|
30
30
|
* Legacy `ServerApi` endpoints never reach here (they catch internally), so
|
|
@@ -38,13 +38,13 @@ export function terminalErrorHandler() {
|
|
|
38
38
|
return next(err);
|
|
39
39
|
const apiException = await composeApiError(err, requestDataFrom(req), logger);
|
|
40
40
|
const responseBody = apiException.responseBody;
|
|
41
|
-
if (!
|
|
41
|
+
if (!apiDebug.enabled)
|
|
42
42
|
delete responseBody.debugMessage;
|
|
43
43
|
if (apiException.responseCode === 500) {
|
|
44
44
|
const cause = apiException.cause;
|
|
45
45
|
const stack = cause ? cause.stack : apiException.stack;
|
|
46
46
|
const message = (cause ? cause.message : apiException.message) || "";
|
|
47
|
-
res.status(500).set("Content-Type", "text/plain").send(
|
|
47
|
+
res.status(500).set("Content-Type", "text/plain").send(apiDebug.enabled && stack ? stack : message);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
res.status(apiException.responseCode).set("Content-Type", "application/json").send(JSON.stringify(responseBody, null, 2));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-middleware.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/app-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAwC,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAC,KAAK,EAAC,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"app-middleware.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/app-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAwC,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAC,KAAK,EAAC,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAC,QAAQ,EAAuB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAEpD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAElD;;;;GAIG;AACH,SAAS,eAAe,CAAC,GAAY;IACjC,OAAO;QACH,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAe;QAC9E,WAAW,EAAE,GAAG,CAAC,IAAI;QACrB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK;QACjC,IAAI,EAAE,GAAG,CAAC,IAAI;KACjB,CAAC;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,CAAC"}
|
|
@@ -26,4 +26,12 @@ export type HandlerOptions = {
|
|
|
26
26
|
* `res.headersSent`, autoSend is a no-op. Rule: return a value XOR write `res`.
|
|
27
27
|
*/
|
|
28
28
|
export declare function handler<Binder extends ApiTypeBinder<any, any, any, any>>(fn: TypedHandler<Binder>, opts?: HandlerOptions): RequestHandler;
|
|
29
|
+
/**
|
|
30
|
+
* A redirect endpoint as an Express `RequestHandler` — the functional
|
|
31
|
+
* replacement for the old `ServerApi_Redirect`. Appends the incoming query
|
|
32
|
+
* params to the target URL (same shape the class produced) and redirects.
|
|
33
|
+
*
|
|
34
|
+
* router.all("/old-path", redirectHandler(301, "/api/v1/new-path"));
|
|
35
|
+
*/
|
|
36
|
+
export declare function redirectHandler(responseCode: number, redirectUrl: string): RequestHandler;
|
|
29
37
|
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAC,KAAK,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAI5D;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IACrE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAE/F;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IACrE,CAAC,GAAG,EAAE,YAAY,C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AAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;AAErI,MAAM,MAAM,cAAc,GAAG;IAIzB,aAAa,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,MAAM,SAAS,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACpE,EAAE,EAAE,YAAY,CAAC,MAAM,CAAC,EACxB,IAAI,GAAE,cAAmB,GAC1B,cAAc,CAOhB;AAgCD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,CAOzF"}
|
|
@@ -18,7 +18,7 @@ export function handler(fn, opts = {}) {
|
|
|
18
18
|
return (req, res, next) => {
|
|
19
19
|
Promise.resolve()
|
|
20
20
|
.then(() => fn(req, res, next))
|
|
21
|
-
.then(value => autoSend(res, value, opts))
|
|
21
|
+
.then(value => autoSend(req, res, value, opts))
|
|
22
22
|
.catch(next);
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -27,7 +27,7 @@ export function handler(fn, opts = {}) {
|
|
|
27
27
|
* (server-api.ts:170-187) — including the 2-space JSON formatting and the
|
|
28
28
|
* case-insensitive "<html" sniff — so migrated endpoints stay byte-identical.
|
|
29
29
|
*/
|
|
30
|
-
function autoSend(res, value, opts) {
|
|
30
|
+
function autoSend(req, res, value, opts) {
|
|
31
31
|
if (res.headersSent)
|
|
32
32
|
return; // handler wrote the response itself (stream/SSE/redirect/manual res.*)
|
|
33
33
|
if (value === undefined || value === null) {
|
|
@@ -35,7 +35,7 @@ function autoSend(res, value, opts) {
|
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
if (opts.printResponse !== false)
|
|
38
|
-
logger.logVerbose(
|
|
38
|
+
logger.logVerbose(`${req.method} ${req.originalUrl} -- Response:`, value);
|
|
39
39
|
if (typeof value === "object") {
|
|
40
40
|
res.status(200).set("Content-Type", "application/json").send(JSON.stringify(value, null, 2));
|
|
41
41
|
return;
|
|
@@ -46,4 +46,19 @@ function autoSend(res, value, opts) {
|
|
|
46
46
|
}
|
|
47
47
|
res.status(200).set("Content-Type", "text/plain").send(String(value));
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* A redirect endpoint as an Express `RequestHandler` — the functional
|
|
51
|
+
* replacement for the old `ServerApi_Redirect`. Appends the incoming query
|
|
52
|
+
* params to the target URL (same shape the class produced) and redirects.
|
|
53
|
+
*
|
|
54
|
+
* router.all("/old-path", redirectHandler(301, "/api/v1/new-path"));
|
|
55
|
+
*/
|
|
56
|
+
export function redirectHandler(responseCode, redirectUrl) {
|
|
57
|
+
return (req, res) => {
|
|
58
|
+
const q = (req.query ?? {});
|
|
59
|
+
const keys = Object.keys(q);
|
|
60
|
+
const query = keys.length ? keys.reduce((c, k) => `${c}&${k}=${q[k]}`, "?") : "";
|
|
61
|
+
res.redirect(responseCode, `${redirectUrl}${query}`);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
49
64
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAqE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAoB,MAAM,0BAA0B,CAAC;AAE5D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC;AAuBzC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CACnB,EAAwB,EACxB,OAAuB,EAAE;IAEzB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACtB,OAAO,CAAC,OAAO,EAAE;aACZ,IAAI,CAAC,GAAG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AAE,CAAC;QACjF,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type Request, type RequestHandler, type Response } from "express";
|
|
2
|
+
import { type ServerApi_Middleware } from "./HttpServer.js";
|
|
3
|
+
import { ApiResponse } from "./server-api.js";
|
|
2
4
|
/**
|
|
3
5
|
* The auth logic itself (session/JWT validation + scope checks) lives in the
|
|
4
6
|
* CONSUMER (e.g. `AccountModule.validateSession` / `KasperoProxy.validateRequest`),
|
|
@@ -21,4 +23,21 @@ export type AuthValidator = (req: Request, scopes: string[], res: Response) => P
|
|
|
21
23
|
* level (`router.use(requireAuth())`).
|
|
22
24
|
*/
|
|
23
25
|
export declare function makeRequireAuth(validator: AuthValidator): (...scopes: string[]) => RequestHandler;
|
|
26
|
+
/**
|
|
27
|
+
* Adapt a raw Express `res` to the `ApiResponse` a legacy `ServerApi_Middleware`
|
|
28
|
+
* expects. ApiResponse is now a thin res-backed helper, so this hands the gate a
|
|
29
|
+
* real, fully-functional one (setHeader/setHeaders for JWT refresh, redirect for
|
|
30
|
+
* SAML, json/text/… all delegate to `res`).
|
|
31
|
+
*/
|
|
32
|
+
export declare const headerSink: (res: Response) => ApiResponse;
|
|
33
|
+
/**
|
|
34
|
+
* Wrap a legacy `ServerApi_Middleware` `(request, data, response, scopes) => ctx`
|
|
35
|
+
* as Express middleware — so existing authz/proxy gates run at the route site
|
|
36
|
+
* without rewriting their logic (no fresh security review). Any returned context
|
|
37
|
+
* object is merged onto `req` (e.g. `req.account`); rejections flow to the
|
|
38
|
+
* app-level terminal error handler via `next(err)`.
|
|
39
|
+
*
|
|
40
|
+
* router.post("/x", useMiddleware(RemoteProxy.Middleware), handler(fn));
|
|
41
|
+
*/
|
|
42
|
+
export declare const useMiddleware: (mw: ServerApi_Middleware, ...scopes: string[]) => RequestHandler;
|
|
24
43
|
//# sourceMappingURL=requireAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireAuth.d.ts","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/requireAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE5F;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAE5G;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,aAAa,IAC5C,GAAG,QAAQ,MAAM,EAAE,KAAG,cAAc,CAU/C"}
|
|
1
|
+
{"version":3,"file":"requireAuth.d.ts","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/requireAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE5F,OAAO,EAAC,KAAK,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,WAAW,EAAuB,MAAM,iBAAiB,CAAC;AAIlE;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAE5G;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,aAAa,IAC5C,GAAG,QAAQ,MAAM,EAAE,KAAG,cAAc,CAU/C;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,QAAQ,KAAG,WAAiE,CAAC;AAE7G;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,IAAI,oBAAoB,EAAE,GAAG,QAAQ,MAAM,EAAE,KAAG,cAgBzE,CAAC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import {} from "express";
|
|
2
|
+
import { parse } from "url";
|
|
3
|
+
import {} from "./HttpServer.js";
|
|
4
|
+
import { ApiResponse } from "./server-api.js";
|
|
5
|
+
import { HttpMethod } from "../../../shared/types.js";
|
|
6
|
+
import {} from "../../utils/types.js";
|
|
2
7
|
/**
|
|
3
8
|
* Build a `requireAuth(...scopes)` middleware from a consumer auth validator.
|
|
4
9
|
*
|
|
@@ -20,4 +25,37 @@ export function makeRequireAuth(validator) {
|
|
|
20
25
|
.catch(next);
|
|
21
26
|
};
|
|
22
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Adapt a raw Express `res` to the `ApiResponse` a legacy `ServerApi_Middleware`
|
|
30
|
+
* expects. ApiResponse is now a thin res-backed helper, so this hands the gate a
|
|
31
|
+
* real, fully-functional one (setHeader/setHeaders for JWT refresh, redirect for
|
|
32
|
+
* SAML, json/text/… all delegate to `res`).
|
|
33
|
+
*/
|
|
34
|
+
export const headerSink = (res) => new ApiResponse(res);
|
|
35
|
+
/**
|
|
36
|
+
* Wrap a legacy `ServerApi_Middleware` `(request, data, response, scopes) => ctx`
|
|
37
|
+
* as Express middleware — so existing authz/proxy gates run at the route site
|
|
38
|
+
* without rewriting their logic (no fresh security review). Any returned context
|
|
39
|
+
* object is merged onto `req` (e.g. `req.account`); rejections flow to the
|
|
40
|
+
* app-level terminal error handler via `next(err)`.
|
|
41
|
+
*
|
|
42
|
+
* router.post("/x", useMiddleware(RemoteProxy.Middleware), handler(fn));
|
|
43
|
+
*/
|
|
44
|
+
export const useMiddleware = (mw, ...scopes) => (req, res, next) => {
|
|
45
|
+
const data = {
|
|
46
|
+
method: req.method.toLowerCase(),
|
|
47
|
+
originalUrl: req.originalUrl,
|
|
48
|
+
headers: req.headers,
|
|
49
|
+
url: req.url,
|
|
50
|
+
query: parse(req.url, true).query,
|
|
51
|
+
body: req.body
|
|
52
|
+
};
|
|
53
|
+
Promise.resolve(mw(req, data, headerSink(res), scopes))
|
|
54
|
+
.then(ctx => {
|
|
55
|
+
if (ctx && typeof ctx === "object")
|
|
56
|
+
Object.assign(req, ctx);
|
|
57
|
+
next();
|
|
58
|
+
})
|
|
59
|
+
.catch(next);
|
|
60
|
+
};
|
|
23
61
|
//# sourceMappingURL=requireAuth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireAuth.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/requireAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"requireAuth.js","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/requireAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAC,KAAK,EAAC,MAAM,KAAK,CAAC;AAC1B,OAAO,EAA2B,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,WAAW,EAAuB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAA2C,MAAM,sBAAsB,CAAC;AAc/E;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACpD,OAAO,CAAC,GAAG,MAAgB,EAAkB,EAAE,CAC3C,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAChD,OAAO,CAAC,OAAO,EAAE;aACZ,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;aACvC,IAAI,CAAC,OAAO,CAAC,EAAE;YACZ,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;YACtB,IAAI,EAAE,CAAC;QACX,CAAC,CAAC;aACD,KAAK,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;AACV,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAa,EAAe,EAAE,CAAC,IAAI,WAAW,CAAC,GAAiC,CAAC,CAAC;AAE7G;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAwB,EAAE,GAAG,MAAgB,EAAkB,EAAE,CAC3F,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAChD,MAAM,IAAI,GAAoB;QAC1B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW,EAAgB;QAC9C,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK;QACjC,IAAI,EAAE,GAAG,CAAC,IAAI;KACjB,CAAC;IACF,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAgC,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;SAC/E,IAAI,CAAC,GAAG,CAAC,EAAE;QACR,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5D,IAAI,EAAE,CAAC;IACX,CAAC,CAAC;SACD,KAAK,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Logger, type ObjectTS, type ValidatorTypeResolver } from "@intuitionrobotics/ts-common";
|
|
2
1
|
import { Stream } from "stream";
|
|
3
|
-
import { type ServerApi_Middleware } from "./HttpServer.js";
|
|
4
2
|
import { type IncomingHttpHeaders } from "http";
|
|
5
|
-
import { type
|
|
3
|
+
import { type HttpMethod } from "../../../shared/types.js";
|
|
6
4
|
import { ApiException } from "../../exceptions.js";
|
|
7
|
-
import { type
|
|
5
|
+
import { type ExpressResponse } from "../../utils/types.js";
|
|
8
6
|
export type HttpRequestData = {
|
|
9
7
|
originalUrl: string;
|
|
10
8
|
headers: IncomingHttpHeaders;
|
|
@@ -13,51 +11,13 @@ export type HttpRequestData = {
|
|
|
13
11
|
body: any;
|
|
14
12
|
method: HttpMethod;
|
|
15
13
|
};
|
|
16
|
-
export declare
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
readonly headersToLog: string[];
|
|
20
|
-
readonly method: HttpMethod;
|
|
21
|
-
readonly relativePath: string;
|
|
22
|
-
private middlewares?;
|
|
23
|
-
private bodyValidator?;
|
|
24
|
-
private queryValidator?;
|
|
25
|
-
private scopes;
|
|
26
|
-
protected constructor(method: HttpMethod, relativePath?: string, tag?: string);
|
|
27
|
-
private _handler?;
|
|
28
|
-
get handler(): (req: ExpressRequest, res: ExpressResponse, next?: (err?: any) => void) => Promise<void>;
|
|
29
|
-
shouldPrintResponse(): boolean;
|
|
30
|
-
setMiddlewares(...middlewares: ServerApi_Middleware[]): this;
|
|
31
|
-
addMiddlewares(...middlewares: ServerApi_Middleware[]): this;
|
|
32
|
-
setScopes(...scopes: string[]): this;
|
|
33
|
-
getScopes(): string[];
|
|
34
|
-
addHeaderToLog(...headersToLog: string[]): void;
|
|
35
|
-
setBodyValidator(bodyValidator: ValidatorTypeResolver<B>): void;
|
|
36
|
-
setQueryValidator(queryValidator: ValidatorTypeResolver<P>): void;
|
|
37
|
-
asProxy(): ServerApi<Binder>;
|
|
38
|
-
dontPrintResponse(): void;
|
|
39
|
-
setMaxResponsePrintSize(printResponseMaxSizeBytes: number): void;
|
|
40
|
-
assertProperty: <T extends object, K extends keyof T = keyof T>(instance: T, key: K | K[], statusCode?: number, check?: string | ((propValue: T[K]) => void)) => void;
|
|
41
|
-
call(req: ExpressRequest, res: ExpressResponse): Promise<void>;
|
|
42
|
-
private applyMiddlewares;
|
|
43
|
-
protected abstract process(request: ExpressRequest, response: ApiResponse, queryParams: P, body: B, context: ObjectTS): Promise<R>;
|
|
44
|
-
}
|
|
45
|
-
export declare class ServerApi_Proxy<Binder extends ApiTypeBinder<string, R, B, P>, R = Binder["response"], B = Binder["body"], P extends QueryParams = Binder["queryParams"]> extends ServerApi<Binder> {
|
|
46
|
-
private readonly api;
|
|
47
|
-
constructor(api: ServerApi<any>);
|
|
48
|
-
protected process(request: ExpressRequest, response: ApiResponse, queryParams: P, body: B, context: ObjectTS): Promise<R>;
|
|
49
|
-
}
|
|
50
|
-
export declare class ServerApi_Redirect extends ServerApi<any> {
|
|
51
|
-
private readonly responseCode;
|
|
52
|
-
private readonly redirectUrl;
|
|
53
|
-
constructor(apiName: string, responseCode: number, redirectUrl: string);
|
|
54
|
-
protected process(request: ExpressRequest, response: ApiResponse, queryParams: QueryParams, _body: any): Promise<void>;
|
|
55
|
-
}
|
|
14
|
+
export declare const apiDebug: {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
};
|
|
56
17
|
export declare class ApiResponse {
|
|
57
|
-
private api;
|
|
58
18
|
private readonly res;
|
|
59
19
|
private consumed;
|
|
60
|
-
constructor(
|
|
20
|
+
constructor(res: ExpressResponse);
|
|
61
21
|
isConsumed(): boolean;
|
|
62
22
|
private consume;
|
|
63
23
|
stream(responseCode: number, stream: Stream, headers?: any): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-api.d.ts","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/server-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-api.d.ts","sourceRoot":"","sources":["../../../../src/main/app-backend/modules/server/server-api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,KAAK,mBAAmB,EAAC,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAC,KAAK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