@sebastienrousseau/crypto-server 0.0.35 → 0.0.37
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/README.md +128 -73
- package/dist/@types/types.d.ts +1 -0
- package/dist/@types/types.d.ts.map +1 -1
- package/dist/config/auth-policy.d.ts +1 -0
- package/dist/config/auth-policy.d.ts.map +1 -1
- package/dist/config/auth-policy.js +10 -4
- package/dist/config/constants.d.ts +7 -2
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +15 -18
- package/dist/config/env.d.ts +9 -2
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +59 -36
- package/dist/config/settings.d.ts +3 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +24 -0
- package/dist/enterprise/metering.d.ts +5 -5
- package/dist/enterprise/metering.d.ts.map +1 -1
- package/dist/enterprise/metering.js +20 -63
- package/dist/enterprise/types.d.ts +0 -11
- package/dist/enterprise/types.d.ts.map +1 -1
- package/dist/index.js +9 -35
- package/dist/lib/audit.d.ts +18 -0
- package/dist/lib/audit.d.ts.map +1 -0
- package/dist/lib/audit.js +57 -0
- package/dist/lib/auth.d.ts +4 -0
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +15 -1
- package/dist/lib/crypto-workers.d.ts +27 -0
- package/dist/lib/crypto-workers.d.ts.map +1 -0
- package/dist/lib/crypto-workers.js +46 -0
- package/dist/lib/http-metrics.d.ts +13 -0
- package/dist/lib/http-metrics.d.ts.map +1 -0
- package/dist/lib/http-metrics.js +45 -0
- package/dist/lib/key-store.d.ts +15 -1
- package/dist/lib/key-store.d.ts.map +1 -1
- package/dist/lib/key-store.js +128 -44
- package/dist/lib/kms-owners.d.ts +9 -0
- package/dist/lib/kms-owners.d.ts.map +1 -0
- package/dist/lib/kms-owners.js +80 -0
- package/dist/lib/kms-providers.d.ts +15 -0
- package/dist/lib/kms-providers.d.ts.map +1 -0
- package/dist/lib/kms-providers.js +99 -0
- package/dist/lib/lifecycle.d.ts +16 -0
- package/dist/lib/lifecycle.d.ts.map +1 -0
- package/dist/lib/lifecycle.js +50 -0
- package/dist/lib/logger.d.ts +5 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +34 -15
- package/dist/lib/opaque-store.d.ts +13 -0
- package/dist/lib/opaque-store.d.ts.map +1 -1
- package/dist/lib/opaque-store.js +27 -2
- package/dist/lib/problem.d.ts +8 -0
- package/dist/lib/problem.d.ts.map +1 -1
- package/dist/lib/problem.js +25 -15
- package/dist/lib/readiness.d.ts +12 -0
- package/dist/lib/readiness.d.ts.map +1 -0
- package/dist/lib/readiness.js +17 -0
- package/dist/lib/telemetry.d.ts +1 -1
- package/dist/lib/telemetry.d.ts.map +1 -1
- package/dist/lib/telemetry.js +45 -73
- package/dist/routes/index.d.ts +3 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +19 -12
- package/dist/routes/probes.d.ts.map +1 -1
- package/dist/routes/probes.js +4 -10
- package/dist/routes/v1/decrypt.d.ts.map +1 -1
- package/dist/routes/v1/decrypt.js +2 -1
- package/dist/routes/v1/encrypt.d.ts.map +1 -1
- package/dist/routes/v1/encrypt.js +2 -1
- package/dist/routes/v1/generate.d.ts.map +1 -1
- package/dist/routes/v1/generate.js +3 -2
- package/dist/routes/v1/index.js +2 -2
- package/dist/routes/v1/revoke.d.ts.map +1 -1
- package/dist/routes/v1/revoke.js +3 -2
- package/dist/routes/v1/verify.d.ts.map +1 -1
- package/dist/routes/v1/verify.js +27 -12
- package/dist/routes/v2/compliance.js +1 -1
- package/dist/routes/v2/hpke.d.ts.map +1 -1
- package/dist/routes/v2/hpke.js +8 -4
- package/dist/routes/v2/keys.d.ts.map +1 -1
- package/dist/routes/v2/keys.js +24 -2
- package/dist/routes/v2/kms.d.ts +8 -4
- package/dist/routes/v2/kms.d.ts.map +1 -1
- package/dist/routes/v2/kms.js +81 -82
- package/dist/routes/v2/opaque.d.ts.map +1 -1
- package/dist/routes/v2/opaque.js +26 -4
- package/dist/routes/v2/pq-hash-sign.d.ts.map +1 -1
- package/dist/routes/v2/pq-hash-sign.js +2 -4
- package/dist/routes/v2/pq-sign.d.ts.map +1 -1
- package/dist/routes/v2/pq-sign.js +2 -4
- package/dist/routes/v2/pq.d.ts.map +1 -1
- package/dist/routes/v2/pq.js +10 -9
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +40 -15
- package/dist/utils/keys.d.ts +1 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +9 -2
- package/dist/utils/route-helpers.d.ts.map +1 -1
- package/dist/utils/route-helpers.js +5 -10
- package/package.json +6 -8
- package/dist/lib/kdf-runner.d.ts +0 -18
- package/dist/lib/kdf-runner.d.ts.map +0 -1
- package/dist/lib/kdf-runner.js +0 -27
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/lib/lifecycle.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC,MAAM,WAAW,eAAe;IAE9B,SAAS,EAAE,MAAM,CAAC;IAElB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAE7B,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAMD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,GACvB,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CA2BnC;AAGD,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC;IAEtE,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAEvB,OAAO,EAAE,YAAY,CAAC;CACvB;AAQD,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAe3E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gracefulShutdown = gracefulShutdown;
|
|
4
|
+
exports.start = start;
|
|
5
|
+
const env_1 = require("../config/env");
|
|
6
|
+
const server_1 = require("../server");
|
|
7
|
+
function gracefulShutdown(server, options) {
|
|
8
|
+
let started = false;
|
|
9
|
+
return async (signal) => {
|
|
10
|
+
if (started)
|
|
11
|
+
return;
|
|
12
|
+
started = true;
|
|
13
|
+
const { log, exit, timeoutMs } = options;
|
|
14
|
+
log.info({ signal }, "Shutting down gracefully");
|
|
15
|
+
const forceTimer = setTimeout(() => {
|
|
16
|
+
log.error({ shutdownTimeoutMs: timeoutMs }, "Shutdown timed out; forcing exit");
|
|
17
|
+
exit(1);
|
|
18
|
+
}, timeoutMs);
|
|
19
|
+
forceTimer.unref();
|
|
20
|
+
try {
|
|
21
|
+
await server.close();
|
|
22
|
+
await options.onClosed?.();
|
|
23
|
+
log.info("All connections drained. Goodbye.");
|
|
24
|
+
exit(0);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
log.error({ err }, "Error during shutdown");
|
|
28
|
+
exit(1);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
clearTimeout(forceTimer);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function start(options) {
|
|
36
|
+
const config = (0, env_1.loadConfig)(options.env);
|
|
37
|
+
const server = await (0, server_1.init)();
|
|
38
|
+
await server.listen({ port: config.port, host: config.host });
|
|
39
|
+
const base = `${config.protocol}://${config.host}:${server.addresses()[0].port}`;
|
|
40
|
+
options.log.info(`Server listening on ${base}/`);
|
|
41
|
+
options.log.info(`Swagger docs at ${base}/docs`);
|
|
42
|
+
const shutdown = gracefulShutdown(server, {
|
|
43
|
+
...options,
|
|
44
|
+
timeoutMs: config.shutdownTimeoutMs,
|
|
45
|
+
});
|
|
46
|
+
options.signals.on("SIGTERM", () => void shutdown("SIGTERM"));
|
|
47
|
+
options.signals.on("SIGINT", () => void shutdown("SIGINT"));
|
|
48
|
+
return server;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=lifecycle.js.map
|
package/dist/lib/logger.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { pino, type DestinationStream, type Logger } from "pino";
|
|
2
|
+
export declare const LOG_REDACT_PATHS: readonly string[];
|
|
3
|
+
export declare function createLogger(destination?: DestinationStream): Logger;
|
|
4
|
+
export declare function requestIdFrom(header: string | string[] | undefined): string;
|
|
5
|
+
declare const logger: pino.Logger;
|
|
2
6
|
export default logger;
|
|
3
7
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/lib/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,IAAI,EAAE,KAAK,iBAAiB,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAMjE,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAc7C,CAAC;AAGF,wBAAgB,YAAY,CAAC,WAAW,CAAC,EAAE,iBAAiB,GAAG,MAAM,CASpE;AAUD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAI3E;AAGD,QAAA,MAAM,MAAM,aAAiB,CAAC;AAC9B,eAAe,MAAM,CAAC"}
|
package/dist/lib/logger.js
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
exports.LOG_REDACT_PATHS = void 0;
|
|
4
|
+
exports.createLogger = createLogger;
|
|
5
|
+
exports.requestIdFrom = requestIdFrom;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const pino_1 = require("pino");
|
|
8
|
+
exports.LOG_REDACT_PATHS = [
|
|
9
|
+
"req.headers.authorization",
|
|
10
|
+
'req.headers["x-api-key"]',
|
|
11
|
+
"req.headers.cookie",
|
|
12
|
+
"headers.authorization",
|
|
13
|
+
'headers["x-api-key"]',
|
|
14
|
+
...[
|
|
15
|
+
"password",
|
|
16
|
+
"passphrase",
|
|
17
|
+
"privateKey",
|
|
18
|
+
"secretKey",
|
|
19
|
+
"secret",
|
|
20
|
+
"token",
|
|
21
|
+
].flatMap((field) => [field, `*.${field}`]),
|
|
22
|
+
];
|
|
23
|
+
function createLogger(destination) {
|
|
24
|
+
return (0, pino_1.pino)({
|
|
25
|
+
level: process.env["LOG_LEVEL"] ?? "info",
|
|
26
|
+
base: { service: "crypto-server" },
|
|
27
|
+
redact: { paths: [...exports.LOG_REDACT_PATHS] },
|
|
28
|
+
}, destination);
|
|
29
|
+
}
|
|
30
|
+
const REQUEST_ID = /^[A-Za-z0-9._-]{1,128}$/;
|
|
31
|
+
function requestIdFrom(header) {
|
|
32
|
+
return typeof header === "string" && REQUEST_ID.test(header)
|
|
33
|
+
? header
|
|
34
|
+
: (0, crypto_1.randomUUID)();
|
|
35
|
+
}
|
|
36
|
+
const logger = createLogger();
|
|
18
37
|
exports.default = logger;
|
|
19
38
|
//# sourceMappingURL=logger.js.map
|
|
@@ -4,6 +4,15 @@ type ServerSetup = protocols.pake.ServerSetup;
|
|
|
4
4
|
type RegistrationRecord = protocols.pake.RegistrationRecord;
|
|
5
5
|
type ServerLoginState = protocols.pake.ServerLoginState;
|
|
6
6
|
export declare const DEFAULT_OPAQUE_SESSION_TTL_MS: number;
|
|
7
|
+
export declare const DEFAULT_OPAQUE_MAX_RECORDS = 100000;
|
|
8
|
+
export declare const DEFAULT_OPAQUE_MAX_SESSIONS = 10000;
|
|
9
|
+
export interface OpaqueStoreOptions {
|
|
10
|
+
readonly maxRecords?: number;
|
|
11
|
+
readonly maxSessions?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class OpaqueStoreFullError extends Error {
|
|
14
|
+
readonly name = "OpaqueStoreFullError";
|
|
15
|
+
}
|
|
7
16
|
export interface OpaqueActiveSession {
|
|
8
17
|
readonly serverState: ServerLoginState;
|
|
9
18
|
readonly credentialIdentifier: string;
|
|
@@ -15,6 +24,10 @@ export declare class OpaqueStore {
|
|
|
15
24
|
private readonly fakeRecords;
|
|
16
25
|
private readonly records;
|
|
17
26
|
private readonly sessions;
|
|
27
|
+
private readonly maxRecords;
|
|
28
|
+
private readonly maxSessions;
|
|
29
|
+
private nextSweepAt;
|
|
30
|
+
constructor(options?: OpaqueStoreOptions);
|
|
18
31
|
getSetup(suite?: SuiteId): ServerSetup;
|
|
19
32
|
getFakeRecord(suite?: SuiteId): RegistrationRecord;
|
|
20
33
|
setRecord(credentialIdentifier: string, record: RegistrationRecord): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opaque-store.d.ts","sourceRoot":"","sources":["../../src/lib/opaque-store.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,KAAK,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;AACtC,KAAK,WAAW,GAAG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Q,SAAS,CAAC;IACvB,UAAU,eAAe;QAEvB,WAAW,EAAE,WAAW,CAAC;KAC1B;CACF"}
|
package/dist/lib/opaque-store.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpaqueStore = exports.DEFAULT_OPAQUE_SESSION_TTL_MS = void 0;
|
|
3
|
+
exports.OpaqueStore = exports.OpaqueStoreFullError = exports.DEFAULT_OPAQUE_MAX_SESSIONS = exports.DEFAULT_OPAQUE_MAX_RECORDS = exports.DEFAULT_OPAQUE_SESSION_TTL_MS = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
6
6
|
const { pake } = crypto_lib_1.protocols;
|
|
7
7
|
exports.DEFAULT_OPAQUE_SESSION_TTL_MS = 5 * 60 * 1000;
|
|
8
|
+
exports.DEFAULT_OPAQUE_MAX_RECORDS = 100_000;
|
|
9
|
+
exports.DEFAULT_OPAQUE_MAX_SESSIONS = 10_000;
|
|
10
|
+
const SESSION_SWEEP_INTERVAL_MS = 1000;
|
|
11
|
+
class OpaqueStoreFullError extends Error {
|
|
12
|
+
name = "OpaqueStoreFullError";
|
|
13
|
+
}
|
|
14
|
+
exports.OpaqueStoreFullError = OpaqueStoreFullError;
|
|
8
15
|
class OpaqueStore {
|
|
9
16
|
setups = new Map();
|
|
10
17
|
fakeRecords = new Map();
|
|
11
18
|
records = new Map();
|
|
12
19
|
sessions = new Map();
|
|
20
|
+
maxRecords;
|
|
21
|
+
maxSessions;
|
|
22
|
+
nextSweepAt = 0;
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.maxRecords = options.maxRecords ?? exports.DEFAULT_OPAQUE_MAX_RECORDS;
|
|
25
|
+
this.maxSessions = options.maxSessions ?? exports.DEFAULT_OPAQUE_MAX_SESSIONS;
|
|
26
|
+
}
|
|
13
27
|
getSetup(suite = "P256-SHA256") {
|
|
14
28
|
let setup = this.setups.get(suite);
|
|
15
29
|
if (!setup) {
|
|
@@ -27,6 +41,10 @@ class OpaqueStore {
|
|
|
27
41
|
return fake;
|
|
28
42
|
}
|
|
29
43
|
setRecord(credentialIdentifier, record) {
|
|
44
|
+
const isNew = !this.records.has(credentialIdentifier);
|
|
45
|
+
if (isNew && this.records.size >= this.maxRecords) {
|
|
46
|
+
throw new OpaqueStoreFullError("OPAQUE record store is full");
|
|
47
|
+
}
|
|
30
48
|
this.records.set(credentialIdentifier, record);
|
|
31
49
|
}
|
|
32
50
|
getRecord(credentialIdentifier) {
|
|
@@ -36,7 +54,14 @@ class OpaqueStore {
|
|
|
36
54
|
return this.records.has(credentialIdentifier);
|
|
37
55
|
}
|
|
38
56
|
createSession(credentialIdentifier, serverState, suite = "P256-SHA256", ttlMs = exports.DEFAULT_OPAQUE_SESSION_TTL_MS) {
|
|
39
|
-
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
if (now >= this.nextSweepAt || this.sessions.size >= this.maxSessions) {
|
|
59
|
+
this.cleanExpiredSessions();
|
|
60
|
+
this.nextSweepAt = now + SESSION_SWEEP_INTERVAL_MS;
|
|
61
|
+
}
|
|
62
|
+
if (this.sessions.size >= this.maxSessions) {
|
|
63
|
+
throw new OpaqueStoreFullError("Too many OPAQUE logins in progress");
|
|
64
|
+
}
|
|
40
65
|
const sessionId = (0, node_crypto_1.randomUUID)();
|
|
41
66
|
this.sessions.set(sessionId, {
|
|
42
67
|
serverState,
|
package/dist/lib/problem.d.ts
CHANGED
|
@@ -11,11 +11,17 @@ export declare const PROBLEM_TITLES: Readonly<{
|
|
|
11
11
|
"key-not-found": "Key not found";
|
|
12
12
|
"key-algorithm-mismatch": "Key algorithm mismatch";
|
|
13
13
|
"key-store-full": "Key store full";
|
|
14
|
+
"key-quota-exceeded": "Key quota exceeded";
|
|
14
15
|
"payload-too-large": "Payload Too Large";
|
|
15
16
|
"rate-limited": "Too Many Requests";
|
|
16
17
|
"request-error": "Bad Request";
|
|
17
18
|
"internal-error": "Internal Server Error";
|
|
18
19
|
conflict: "Conflict";
|
|
20
|
+
"kms-provider-not-enabled": "KMS provider not enabled";
|
|
21
|
+
"kms-key-not-found": "KMS key not found";
|
|
22
|
+
"kms-key-disabled": "KMS key disabled";
|
|
23
|
+
"not-implemented": "Not Implemented";
|
|
24
|
+
"service-unavailable": "Service Unavailable";
|
|
19
25
|
}>;
|
|
20
26
|
export type ProblemSlug = keyof typeof PROBLEM_TITLES;
|
|
21
27
|
export interface Problem {
|
|
@@ -62,6 +68,8 @@ export interface ProblemSpec {
|
|
|
62
68
|
detail: string;
|
|
63
69
|
extensions: Record<string, unknown>;
|
|
64
70
|
}
|
|
71
|
+
export declare function isWorkerOverload(error: unknown): boolean;
|
|
72
|
+
export declare const busy: () => ProblemSpec;
|
|
65
73
|
export declare function classifyThrown(error: unknown): ProblemSpec;
|
|
66
74
|
export declare function registerProblemHandlers(app: FastifyInstance): void;
|
|
67
75
|
//# sourceMappingURL=problem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"problem.d.ts","sourceRoot":"","sources":["../../src/lib/problem.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"problem.d.ts","sourceRoot":"","sources":["../../src/lib/problem.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAqB,MAAM,+BAA+B,CAAC;AAQ/E,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAG/D,eAAO,MAAM,mBAAmB,gCAAgC,CAAC;AAGjE,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;EAoBzB,CAAC;AAGH,MAAM,MAAM,WAAW,GAA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BAAuB,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAoBlE"}
|
package/dist/lib/problem.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PROBLEM_SCHEMA = exports.PROBLEM_TITLES = exports.PROBLEM_TYPE_PREFIX = exports.PROBLEM_CONTENT_TYPE = void 0;
|
|
3
|
+
exports.busy = exports.PROBLEM_SCHEMA = exports.PROBLEM_TITLES = exports.PROBLEM_TYPE_PREFIX = exports.PROBLEM_CONTENT_TYPE = void 0;
|
|
4
4
|
exports.problem = problem;
|
|
5
5
|
exports.sendProblem = sendProblem;
|
|
6
6
|
exports.cryptoErrorStatus = cryptoErrorStatus;
|
|
7
7
|
exports.isCryptoError = isCryptoError;
|
|
8
|
+
exports.isWorkerOverload = isWorkerOverload;
|
|
8
9
|
exports.classifyThrown = classifyThrown;
|
|
9
10
|
exports.registerProblemHandlers = registerProblemHandlers;
|
|
10
11
|
const http_1 = require("http");
|
|
11
12
|
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
13
|
+
const accel_1 = require("@sebastienrousseau/crypto-lib/accel");
|
|
12
14
|
const key_store_1 = require("./key-store");
|
|
13
15
|
exports.PROBLEM_CONTENT_TYPE = "application/problem+json";
|
|
14
16
|
exports.PROBLEM_TYPE_PREFIX = "urn:crypto-service:problem:";
|
|
@@ -21,11 +23,17 @@ exports.PROBLEM_TITLES = Object.freeze({
|
|
|
21
23
|
"key-not-found": "Key not found",
|
|
22
24
|
"key-algorithm-mismatch": "Key algorithm mismatch",
|
|
23
25
|
"key-store-full": "Key store full",
|
|
26
|
+
"key-quota-exceeded": "Key quota exceeded",
|
|
24
27
|
"payload-too-large": "Payload Too Large",
|
|
25
28
|
"rate-limited": "Too Many Requests",
|
|
26
29
|
"request-error": "Bad Request",
|
|
27
30
|
"internal-error": "Internal Server Error",
|
|
28
31
|
conflict: "Conflict",
|
|
32
|
+
"kms-provider-not-enabled": "KMS provider not enabled",
|
|
33
|
+
"kms-key-not-found": "KMS key not found",
|
|
34
|
+
"kms-key-disabled": "KMS key disabled",
|
|
35
|
+
"not-implemented": "Not Implemented",
|
|
36
|
+
"service-unavailable": "Service Unavailable",
|
|
29
37
|
});
|
|
30
38
|
exports.PROBLEM_SCHEMA = {
|
|
31
39
|
type: "object",
|
|
@@ -54,21 +62,8 @@ function sendProblem(reply, status, slug, detail, extensions) {
|
|
|
54
62
|
const body = problem(status, slug, detail, extensions, pathOf(reply.request));
|
|
55
63
|
return reply.status(status).type(exports.PROBLEM_CONTENT_TYPE).send(body);
|
|
56
64
|
}
|
|
57
|
-
const CRYPTO_INPUT_CODES = new Set([
|
|
58
|
-
"INVALID_KEY",
|
|
59
|
-
"UNSUPPORTED_ALGORITHM",
|
|
60
|
-
"INVALID_HEX",
|
|
61
|
-
"INVALID_CIPHERTEXT",
|
|
62
|
-
"AUTH_FAILED",
|
|
63
|
-
"INVALID_INPUT",
|
|
64
|
-
"OPAQUE_ENVELOPE_RECOVERY",
|
|
65
|
-
"OPAQUE_SERVER_AUTHENTICATION",
|
|
66
|
-
"OPAQUE_CLIENT_AUTHENTICATION",
|
|
67
|
-
"OPAQUE_DESERIALIZE",
|
|
68
|
-
"OPAQUE_INVALID_INPUT",
|
|
69
|
-
]);
|
|
70
65
|
function cryptoErrorStatus(code) {
|
|
71
|
-
return
|
|
66
|
+
return (0, crypto_lib_1.isCallerErrorCode)(code) ? 400 : 500;
|
|
72
67
|
}
|
|
73
68
|
function isCryptoError(error) {
|
|
74
69
|
return error instanceof crypto_lib_1.CryptoError;
|
|
@@ -77,15 +72,28 @@ const KEY_STORE_SLUGS = {
|
|
|
77
72
|
KEY_NOT_FOUND: "key-not-found",
|
|
78
73
|
KEY_ALGORITHM_MISMATCH: "key-algorithm-mismatch",
|
|
79
74
|
KEY_STORE_FULL: "key-store-full",
|
|
75
|
+
KEY_QUOTA_EXCEEDED: "key-quota-exceeded",
|
|
80
76
|
STORAGE_KEY_REQUIRED: "internal-error",
|
|
81
77
|
KEY_INTEGRITY_FAILED: "internal-error",
|
|
82
78
|
KEY_CORRUPTED: "internal-error",
|
|
83
79
|
UNSUPPORTED_STORAGE_ALGORITHM: "internal-error",
|
|
80
|
+
PLAINTEXT_KEY_REFUSED: "internal-error",
|
|
84
81
|
};
|
|
85
82
|
function fieldOf(issue) {
|
|
86
83
|
const missing = issue.params.missingProperty;
|
|
87
84
|
return missing ? `${issue.instancePath}/${missing}` : issue.instancePath;
|
|
88
85
|
}
|
|
86
|
+
function isWorkerOverload(error) {
|
|
87
|
+
return (error instanceof accel_1.WorkerPoolBusyError ||
|
|
88
|
+
error instanceof accel_1.WorkerTaskTimeoutError);
|
|
89
|
+
}
|
|
90
|
+
const busy = () => ({
|
|
91
|
+
status: 503,
|
|
92
|
+
slug: "service-unavailable",
|
|
93
|
+
detail: "The server is busy; retry later",
|
|
94
|
+
extensions: {},
|
|
95
|
+
});
|
|
96
|
+
exports.busy = busy;
|
|
89
97
|
const internal = (extensions = {}) => ({
|
|
90
98
|
status: 500,
|
|
91
99
|
slug: "internal-error",
|
|
@@ -137,6 +145,8 @@ function clientProblem(status, error) {
|
|
|
137
145
|
};
|
|
138
146
|
}
|
|
139
147
|
function classifyThrown(error) {
|
|
148
|
+
if (isWorkerOverload(error))
|
|
149
|
+
return (0, exports.busy)();
|
|
140
150
|
if (isCryptoError(error))
|
|
141
151
|
return cryptoProblem(error);
|
|
142
152
|
if (error instanceof key_store_1.KeyStoreError)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FastifyInstance } from "fastify";
|
|
2
|
+
export interface Lifecycle {
|
|
3
|
+
draining: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare module "fastify" {
|
|
6
|
+
interface FastifyInstance {
|
|
7
|
+
lifecycle: Lifecycle;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare function trackLifecycle(app: FastifyInstance): void;
|
|
11
|
+
export declare function readinessChecks(app: FastifyInstance): Promise<Record<string, boolean>>;
|
|
12
|
+
//# sourceMappingURL=readiness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readiness.d.ts","sourceRoot":"","sources":["../../src/lib/readiness.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,MAAM,WAAW,SAAS;IAExB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,eAAe;QAEvB,SAAS,EAAE,SAAS,CAAC;KACtB;CACF;AAGD,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAKzD;AAGD,wBAAsB,eAAe,CACnC,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAKlC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trackLifecycle = trackLifecycle;
|
|
4
|
+
exports.readinessChecks = readinessChecks;
|
|
5
|
+
function trackLifecycle(app) {
|
|
6
|
+
app.decorate("lifecycle", { draining: false });
|
|
7
|
+
app.addHook("preClose", async () => {
|
|
8
|
+
app.lifecycle.draining = true;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
async function readinessChecks(app) {
|
|
12
|
+
return {
|
|
13
|
+
accepting: !app.lifecycle.draining,
|
|
14
|
+
keyStore: await app.keyStore.writable(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=readiness.js.map
|
package/dist/lib/telemetry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function initTelemetry(): void;
|
|
2
|
+
export declare function telemetryActive(): boolean;
|
|
2
3
|
export declare function shutdownTelemetry(): Promise<void>;
|
|
3
|
-
export declare function traceCryptoOperation<T>(operationName: string, attributes: Record<string, string | number>, fn: () => Promise<T> | T): Promise<T>;
|
|
4
4
|
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/lib/telemetry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/lib/telemetry.ts"],"names":[],"mappings":"AAmEA,wBAAgB,aAAa,IAAI,IAAI,CAyBpC;AAGD,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAKD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAavD"}
|
package/dist/lib/telemetry.js
CHANGED
|
@@ -1,92 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initTelemetry = initTelemetry;
|
|
4
|
+
exports.telemetryActive = telemetryActive;
|
|
4
5
|
exports.shutdownTelemetry = shutdownTelemetry;
|
|
5
|
-
exports.traceCryptoOperation = traceCryptoOperation;
|
|
6
|
-
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
7
|
-
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
8
|
-
const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
9
|
-
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
10
|
-
const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
|
|
11
|
-
const instrumentation_fastify_1 = require("@opentelemetry/instrumentation-fastify");
|
|
12
|
-
const resources_1 = require("@opentelemetry/resources");
|
|
13
6
|
const version_1 = require("./version");
|
|
14
|
-
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
15
|
-
const api_1 = require("@opentelemetry/api");
|
|
16
7
|
const SERVICE_NAME = "crypto-server";
|
|
17
|
-
const SERVICE_VERSION = version_1.PACKAGE_VERSION;
|
|
18
8
|
let sdk;
|
|
9
|
+
let instrumentations = [];
|
|
10
|
+
function loadSdk() {
|
|
11
|
+
return {
|
|
12
|
+
...require("@opentelemetry/sdk-node"),
|
|
13
|
+
...require("@opentelemetry/exporter-trace-otlp-http"),
|
|
14
|
+
...require("@opentelemetry/exporter-metrics-otlp-http"),
|
|
15
|
+
...require("@opentelemetry/sdk-metrics"),
|
|
16
|
+
...require("@opentelemetry/instrumentation-http"),
|
|
17
|
+
...require("@fastify/otel"),
|
|
18
|
+
...require("@opentelemetry/resources"),
|
|
19
|
+
...require("@opentelemetry/semantic-conventions"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
19
22
|
function initTelemetry() {
|
|
20
23
|
const endpoint = process.env["OTEL_EXPORTER_OTLP_ENDPOINT"];
|
|
21
|
-
if (!endpoint
|
|
24
|
+
if (!endpoint || process.env["OTEL_SDK_DISABLED"] === "true" || sdk) {
|
|
22
25
|
return;
|
|
23
26
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const otel = loadSdk();
|
|
28
|
+
instrumentations = [
|
|
29
|
+
new otel.HttpInstrumentation(),
|
|
30
|
+
new otel.FastifyOtelInstrumentation({ registerOnInitialization: true }),
|
|
31
|
+
];
|
|
32
|
+
sdk = new otel.NodeSDK({
|
|
33
|
+
resource: otel.resourceFromAttributes({
|
|
34
|
+
[otel.ATTR_SERVICE_NAME]: SERVICE_NAME,
|
|
35
|
+
[otel.ATTR_SERVICE_VERSION]: version_1.PACKAGE_VERSION,
|
|
36
|
+
}),
|
|
37
|
+
traceExporter: new otel.OTLPTraceExporter({ url: `${endpoint}/v1/traces` }),
|
|
38
|
+
metricReader: new otel.PeriodicExportingMetricReader({
|
|
39
|
+
exporter: new otel.OTLPMetricExporter({ url: `${endpoint}/v1/metrics` }),
|
|
35
40
|
exportIntervalMillis: 30000,
|
|
36
41
|
}),
|
|
37
|
-
instrumentations
|
|
42
|
+
instrumentations,
|
|
38
43
|
});
|
|
39
44
|
sdk.start();
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await sdk.shutdown();
|
|
44
|
-
}
|
|
46
|
+
function telemetryActive() {
|
|
47
|
+
return sdk !== undefined;
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const result = await fn();
|
|
61
|
-
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
62
|
-
operationCounter.add(1, {
|
|
63
|
-
operation: operationName,
|
|
64
|
-
status: "success",
|
|
65
|
-
...attributes,
|
|
66
|
-
});
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
span.setStatus({
|
|
71
|
-
code: api_1.SpanStatusCode.ERROR,
|
|
72
|
-
message: error.message,
|
|
73
|
-
});
|
|
74
|
-
span.recordException(error);
|
|
75
|
-
operationCounter.add(1, {
|
|
76
|
-
operation: operationName,
|
|
77
|
-
status: "error",
|
|
78
|
-
...attributes,
|
|
79
|
-
});
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
const duration = performance.now() - start;
|
|
84
|
-
operationDuration.record(duration, {
|
|
85
|
-
operation: operationName,
|
|
86
|
-
...attributes,
|
|
87
|
-
});
|
|
88
|
-
span.end();
|
|
89
|
-
}
|
|
90
|
-
});
|
|
49
|
+
async function shutdownTelemetry() {
|
|
50
|
+
const running = sdk;
|
|
51
|
+
sdk = undefined;
|
|
52
|
+
for (const instrumentation of instrumentations)
|
|
53
|
+
instrumentation.disable();
|
|
54
|
+
instrumentations = [];
|
|
55
|
+
if (!running)
|
|
56
|
+
return;
|
|
57
|
+
await running.shutdown();
|
|
58
|
+
const api = require("@opentelemetry/api");
|
|
59
|
+
api.trace.disable();
|
|
60
|
+
api.metrics.disable();
|
|
61
|
+
api.propagation.disable();
|
|
62
|
+
api.context.disable();
|
|
91
63
|
}
|
|
92
64
|
//# sourceMappingURL=telemetry.js.map
|
package/dist/routes/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as fastify from "fastify";
|
|
2
|
+
export declare const V1_DEPRECATION = "@1787270400";
|
|
3
|
+
export declare const V1_SUNSET = "Fri, 01 Jan 2027 00:00:00 GMT";
|
|
4
|
+
export declare const V1_MIGRATION_LINK = "<https://github.com/sebastienrousseau/crypto-service/blob/main/MIGRATION.md>; rel=\"deprecation\"; type=\"text/html\"";
|
|
2
5
|
declare const _default: (app: fastify.FastifyInstance) => void;
|
|
3
6
|
export default _default;
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAenC,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAG5C,eAAO,MAAM,SAAS,kCAAkC,CAAC;AAGzD,eAAO,MAAM,iBAAiB,0HACuF,CAAC;yBAGtG,KAAK,OAAO,CAAC,eAAe,KAAG,IAAI;AAAnD,wBAwBE"}
|
package/dist/routes/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.V1_MIGRATION_LINK = exports.V1_SUNSET = exports.V1_DEPRECATION = void 0;
|
|
6
7
|
const decrypt_1 = __importDefault(require("./v1/decrypt"));
|
|
7
8
|
const encrypt_1 = __importDefault(require("./v1/encrypt"));
|
|
8
9
|
const generate_1 = __importDefault(require("./v1/generate"));
|
|
@@ -11,20 +12,26 @@ const revoke_1 = __importDefault(require("./v1/revoke"));
|
|
|
11
12
|
const verify_1 = __importDefault(require("./v1/verify"));
|
|
12
13
|
const v2_1 = __importDefault(require("./v2"));
|
|
13
14
|
const probes_1 = __importDefault(require("./probes"));
|
|
15
|
+
const env_1 = require("../config/env");
|
|
16
|
+
exports.V1_DEPRECATION = "@1787270400";
|
|
17
|
+
exports.V1_SUNSET = "Fri, 01 Jan 2027 00:00:00 GMT";
|
|
18
|
+
exports.V1_MIGRATION_LINK = '<https://github.com/sebastienrousseau/crypto-service/blob/main/MIGRATION.md>; rel="deprecation"; type="text/html"';
|
|
14
19
|
exports.default = (app) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
if ((0, env_1.v1Enabled)()) {
|
|
21
|
+
app.addHook("onSend", async (request, reply) => {
|
|
22
|
+
if (request.url.startsWith("/v1/")) {
|
|
23
|
+
reply.header("Deprecation", exports.V1_DEPRECATION);
|
|
24
|
+
reply.header("Sunset", exports.V1_SUNSET);
|
|
25
|
+
reply.header("Link", exports.V1_MIGRATION_LINK);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
(0, decrypt_1.default)(app);
|
|
29
|
+
(0, encrypt_1.default)(app);
|
|
30
|
+
(0, generate_1.default)(app);
|
|
31
|
+
(0, revoke_1.default)(app);
|
|
32
|
+
(0, verify_1.default)(app);
|
|
33
|
+
}
|
|
25
34
|
(0, index_1.default)(app);
|
|
26
|
-
(0, revoke_1.default)(app);
|
|
27
|
-
(0, verify_1.default)(app);
|
|
28
35
|
(0, v2_1.default)(app);
|
|
29
36
|
(0, probes_1.default)(app);
|
|
30
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"probes.d.ts","sourceRoot":"","sources":["../../src/routes/probes.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"probes.d.ts","sourceRoot":"","sources":["../../src/routes/probes.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAO/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAyDE"}
|
package/dist/routes/probes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const readiness_1 = require("../lib/readiness");
|
|
3
4
|
const startTime = Date.now();
|
|
4
5
|
exports.default = (app) => {
|
|
5
6
|
app.get("/live", { schema: { hide: true } }, async () => {
|
|
@@ -9,13 +10,9 @@ exports.default = (app) => {
|
|
|
9
10
|
};
|
|
10
11
|
});
|
|
11
12
|
app.get("/ready", { schema: { hide: true } }, async (_request, reply) => {
|
|
12
|
-
const checks =
|
|
13
|
-
configLoaded: true,
|
|
14
|
-
serverListening: true,
|
|
15
|
-
};
|
|
13
|
+
const checks = await (0, readiness_1.readinessChecks)(app);
|
|
16
14
|
const allReady = Object.values(checks).every(Boolean);
|
|
17
|
-
|
|
18
|
-
return reply.status(status).send({
|
|
15
|
+
return reply.status(allReady ? 200 : 503).send({
|
|
19
16
|
status: allReady ? "ready" : "not_ready",
|
|
20
17
|
checks,
|
|
21
18
|
});
|
|
@@ -40,10 +37,7 @@ exports.default = (app) => {
|
|
|
40
37
|
"# TYPE process_heap_total_bytes gauge",
|
|
41
38
|
`process_heap_total_bytes ${memUsage.heapTotal}`,
|
|
42
39
|
"",
|
|
43
|
-
|
|
44
|
-
"# TYPE nodejs_version_info gauge",
|
|
45
|
-
`nodejs_version_info{version="${process.version}"} 1`,
|
|
46
|
-
"",
|
|
40
|
+
app.httpMetrics.render(),
|
|
47
41
|
];
|
|
48
42
|
reply.header("content-type", "text/plain; version=0.0.4; charset=utf-8");
|
|
49
43
|
return reply.send(lines.join("\n"));
|