@bymax-one/nest-auth 1.5.10 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -1
- package/README.md +204 -30
- package/dist/observability/index.cjs +166 -0
- package/dist/observability/index.d.cts +83 -0
- package/dist/observability/index.d.ts +83 -0
- package/dist/observability/index.mjs +163 -0
- package/dist/server/index.cjs +3101 -1792
- package/dist/server/index.d.cts +117 -23
- package/dist/server/index.d.ts +117 -23
- package/dist/server/index.mjs +3099 -1794
- package/package.json +33 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var common = require('@nestjs/common');
|
|
4
|
+
var promClient = require('prom-client');
|
|
5
|
+
var nestAuth = require('@bymax-one/nest-auth');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
12
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
} else {
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
if (d = decorators[i]) {
|
|
16
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
}
|
|
22
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
23
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
25
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
29
|
+
function _ts_param(paramIndex, decorator) {
|
|
30
|
+
return function(target, key) {
|
|
31
|
+
decorator(target, key, paramIndex);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
__name(_ts_param, "_ts_param");
|
|
35
|
+
var METRICS_CONTRIBUTOR_METADATA = "bymax-one:metrics-contributor";
|
|
36
|
+
function countedByPlaneAndOutcome(registry, spec) {
|
|
37
|
+
const { outcomes, read } = spec;
|
|
38
|
+
new promClient.Counter({
|
|
39
|
+
name: spec.name,
|
|
40
|
+
help: spec.help,
|
|
41
|
+
labelNames: [
|
|
42
|
+
"plane",
|
|
43
|
+
"outcome"
|
|
44
|
+
],
|
|
45
|
+
registers: [
|
|
46
|
+
registry
|
|
47
|
+
],
|
|
48
|
+
collect() {
|
|
49
|
+
this.reset();
|
|
50
|
+
const counts = read();
|
|
51
|
+
for (const plane of nestAuth.AUTH_PLANES) {
|
|
52
|
+
for (const outcome of outcomes) this.inc({
|
|
53
|
+
plane,
|
|
54
|
+
outcome
|
|
55
|
+
}, counts[plane][outcome]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
__name(countedByPlaneAndOutcome, "countedByPlaneAndOutcome");
|
|
61
|
+
exports.AuthMetrics = class AuthMetrics {
|
|
62
|
+
static {
|
|
63
|
+
__name(this, "AuthMetrics");
|
|
64
|
+
}
|
|
65
|
+
tally;
|
|
66
|
+
constructor(tally) {
|
|
67
|
+
this.tally = tally;
|
|
68
|
+
}
|
|
69
|
+
/** Registers the collectors; called once at bootstrap by the metrics module. */
|
|
70
|
+
registerMetrics(registry) {
|
|
71
|
+
const { tally } = this;
|
|
72
|
+
countedByPlaneAndOutcome(registry, {
|
|
73
|
+
name: "bymax_auth_logins_total",
|
|
74
|
+
help: "Login attempts by plane and outcome.",
|
|
75
|
+
outcomes: nestAuth.LOGIN_OUTCOMES,
|
|
76
|
+
read: /* @__PURE__ */ __name(() => tally.snapshot().logins, "read")
|
|
77
|
+
});
|
|
78
|
+
countedByPlaneAndOutcome(registry, {
|
|
79
|
+
name: "bymax_auth_refresh_total",
|
|
80
|
+
help: "Refresh attempts by plane and outcome.",
|
|
81
|
+
outcomes: nestAuth.REFRESH_OUTCOMES,
|
|
82
|
+
read: /* @__PURE__ */ __name(() => tally.snapshot().refreshes, "read")
|
|
83
|
+
});
|
|
84
|
+
countedByPlaneAndOutcome(registry, {
|
|
85
|
+
name: "bymax_auth_mfa_verifications_total",
|
|
86
|
+
help: "MFA verifications by plane and outcome.",
|
|
87
|
+
outcomes: nestAuth.MFA_OUTCOMES,
|
|
88
|
+
read: /* @__PURE__ */ __name(() => tally.snapshot().mfa, "read")
|
|
89
|
+
});
|
|
90
|
+
new promClient.Counter({
|
|
91
|
+
name: "bymax_auth_bruteforce_lockouts_total",
|
|
92
|
+
help: "Identifiers locked out after too many failed attempts.",
|
|
93
|
+
registers: [
|
|
94
|
+
registry
|
|
95
|
+
],
|
|
96
|
+
collect() {
|
|
97
|
+
this.reset();
|
|
98
|
+
this.inc(tally.snapshot().lockouts);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.AuthMetrics = _ts_decorate([
|
|
104
|
+
common.SetMetadata(METRICS_CONTRIBUTOR_METADATA, true),
|
|
105
|
+
common.Injectable(),
|
|
106
|
+
_ts_param(0, common.Inject(nestAuth.AuthMetricsTally)),
|
|
107
|
+
_ts_metadata("design:type", Function),
|
|
108
|
+
_ts_metadata("design:paramtypes", [
|
|
109
|
+
typeof nestAuth.AuthMetricsTally === "undefined" ? Object : nestAuth.AuthMetricsTally
|
|
110
|
+
])
|
|
111
|
+
], exports.AuthMetrics);
|
|
112
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
113
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
114
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
115
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
116
|
+
} else {
|
|
117
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
118
|
+
if (d = decorators[i]) {
|
|
119
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
124
|
+
}
|
|
125
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
126
|
+
function _ts_metadata2(metadataKey, metadataValue) {
|
|
127
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
128
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
132
|
+
function _ts_param2(paramIndex, decorator) {
|
|
133
|
+
return function(target, key) {
|
|
134
|
+
decorator(target, key, paramIndex);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
__name(_ts_param2, "_ts_param");
|
|
138
|
+
var HEALTH_INDICATOR_METADATA = "bymax-one:health-indicator";
|
|
139
|
+
exports.AuthRedisHealthIndicator = class AuthRedisHealthIndicator {
|
|
140
|
+
static {
|
|
141
|
+
__name(this, "AuthRedisHealthIndicator");
|
|
142
|
+
}
|
|
143
|
+
probe;
|
|
144
|
+
name = "auth-redis";
|
|
145
|
+
constructor(probe) {
|
|
146
|
+
this.probe = probe;
|
|
147
|
+
}
|
|
148
|
+
/** Whether the store answers in time; the aggregator's signal ends the wait. */
|
|
149
|
+
async check(signal) {
|
|
150
|
+
return {
|
|
151
|
+
status: await this.probe.ping(signal) ? "up" : "down"
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
exports.AuthRedisHealthIndicator = _ts_decorate2([
|
|
156
|
+
common.SetMetadata(HEALTH_INDICATOR_METADATA, true),
|
|
157
|
+
common.Injectable(),
|
|
158
|
+
_ts_param2(0, common.Inject(nestAuth.AuthHealthProbe)),
|
|
159
|
+
_ts_metadata2("design:type", Function),
|
|
160
|
+
_ts_metadata2("design:paramtypes", [
|
|
161
|
+
typeof nestAuth.AuthHealthProbe === "undefined" ? Object : nestAuth.AuthHealthProbe
|
|
162
|
+
])
|
|
163
|
+
], exports.AuthRedisHealthIndicator);
|
|
164
|
+
|
|
165
|
+
exports.HEALTH_INDICATOR_METADATA = HEALTH_INDICATOR_METADATA;
|
|
166
|
+
exports.METRICS_CONTRIBUTOR_METADATA = METRICS_CONTRIBUTOR_METADATA;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Registry } from 'prom-client';
|
|
2
|
+
import { AuthMetricsTally, AuthHealthProbe } from '@bymax-one/nest-auth';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Publishes what the authentication flows counted to the application's metrics registry.
|
|
6
|
+
*
|
|
7
|
+
* An optional subpath: it names `prom-client`, which an application that publishes no metrics never
|
|
8
|
+
* installs, so nothing outside `src/observability` may import it. The counts are kept by `AuthMetricsTally`
|
|
9
|
+
* in the server entry, in plain numbers; this class only reads them.
|
|
10
|
+
*
|
|
11
|
+
* This package imports no other Bymax library. The contract of `@bymax-one/nest-core` that this class meets is
|
|
12
|
+
* written out below, and the key `BymaxCoreModule` discovers a contributor by is the documented string
|
|
13
|
+
* literal, so nothing here names that package; a spec compares both with the published declarations.
|
|
14
|
+
*
|
|
15
|
+
* @layer Observability
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The registry the application's scrape endpoint serves. */
|
|
19
|
+
type MetricsRegistry = Registry;
|
|
20
|
+
/** What a component that publishes metrics implements: it receives the registry at bootstrap. */
|
|
21
|
+
interface MetricsContributor {
|
|
22
|
+
registerMetrics(registry: MetricsRegistry): void;
|
|
23
|
+
}
|
|
24
|
+
/** The metadata key a metrics module discovers contributors by. */
|
|
25
|
+
declare const METRICS_CONTRIBUTOR_METADATA = "bymax-one:metrics-contributor";
|
|
26
|
+
/**
|
|
27
|
+
* Registers the authentication collectors on the registry the scrape endpoint serves.
|
|
28
|
+
*
|
|
29
|
+
* Every counter is read from the tally on each scrape, after a reset, instead of being written as events
|
|
30
|
+
* arrive: the tally starts counting before this class runs, and a counter fed by events would drop that
|
|
31
|
+
* window. Labels are the closed sets the tally is keyed by; no id, tenant, user, address or message ever
|
|
32
|
+
* becomes one.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // providers: [AuthMetrics] (BymaxCoreModule discovers it and calls registerMetrics once at bootstrap)
|
|
36
|
+
*/
|
|
37
|
+
declare class AuthMetrics implements MetricsContributor {
|
|
38
|
+
private readonly tally;
|
|
39
|
+
constructor(tally: AuthMetricsTally);
|
|
40
|
+
/** Registers the collectors; called once at bootstrap by the metrics module. */
|
|
41
|
+
registerMetrics(registry: MetricsRegistry): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @fileoverview Reports whether the store the authentication flows depend on answers.
|
|
46
|
+
*
|
|
47
|
+
* This package imports no other Bymax library. The readiness contract of `@bymax-one/nest-core` that this
|
|
48
|
+
* class meets is written out below, and the key `BymaxCoreModule` discovers an indicator by is the
|
|
49
|
+
* documented string literal; a spec compares both with the published declarations.
|
|
50
|
+
*
|
|
51
|
+
* @layer Observability
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/** The outcome of one readiness check. */
|
|
55
|
+
interface HealthIndicatorResult {
|
|
56
|
+
status: 'up' | 'down';
|
|
57
|
+
details?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/** What a readiness indicator implements. */
|
|
60
|
+
interface HealthIndicator {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
check(signal?: AbortSignal): Promise<HealthIndicatorResult>;
|
|
63
|
+
}
|
|
64
|
+
/** The metadata key a health module discovers indicators by. */
|
|
65
|
+
declare const HEALTH_INDICATOR_METADATA = "bymax-one:health-indicator";
|
|
66
|
+
/**
|
|
67
|
+
* The readiness check of the authentication store.
|
|
68
|
+
*
|
|
69
|
+
* It asks the Redis client the module was given for a `PING`: one round trip, nothing written and nothing
|
|
70
|
+
* read that a caller owns. A client that rejects, answers anything but `PONG`, or does not answer in time is
|
|
71
|
+
* `down`: the probe gives up after its own timeout, under the aggregator's, and when the aggregator's signal
|
|
72
|
+
* aborts, and the aggregator turns the rejection into a `down` entry, so this class does not catch. No
|
|
73
|
+
* detail is reported, so nothing about the store leaves with it.
|
|
74
|
+
*/
|
|
75
|
+
declare class AuthRedisHealthIndicator implements HealthIndicator {
|
|
76
|
+
private readonly probe;
|
|
77
|
+
readonly name = "auth-redis";
|
|
78
|
+
constructor(probe: AuthHealthProbe);
|
|
79
|
+
/** Whether the store answers in time; the aggregator's signal ends the wait. */
|
|
80
|
+
check(signal?: AbortSignal): Promise<HealthIndicatorResult>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { AuthMetrics, AuthRedisHealthIndicator, HEALTH_INDICATOR_METADATA, METRICS_CONTRIBUTOR_METADATA };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Registry } from 'prom-client';
|
|
2
|
+
import { AuthMetricsTally, AuthHealthProbe } from '@bymax-one/nest-auth';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Publishes what the authentication flows counted to the application's metrics registry.
|
|
6
|
+
*
|
|
7
|
+
* An optional subpath: it names `prom-client`, which an application that publishes no metrics never
|
|
8
|
+
* installs, so nothing outside `src/observability` may import it. The counts are kept by `AuthMetricsTally`
|
|
9
|
+
* in the server entry, in plain numbers; this class only reads them.
|
|
10
|
+
*
|
|
11
|
+
* This package imports no other Bymax library. The contract of `@bymax-one/nest-core` that this class meets is
|
|
12
|
+
* written out below, and the key `BymaxCoreModule` discovers a contributor by is the documented string
|
|
13
|
+
* literal, so nothing here names that package; a spec compares both with the published declarations.
|
|
14
|
+
*
|
|
15
|
+
* @layer Observability
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The registry the application's scrape endpoint serves. */
|
|
19
|
+
type MetricsRegistry = Registry;
|
|
20
|
+
/** What a component that publishes metrics implements: it receives the registry at bootstrap. */
|
|
21
|
+
interface MetricsContributor {
|
|
22
|
+
registerMetrics(registry: MetricsRegistry): void;
|
|
23
|
+
}
|
|
24
|
+
/** The metadata key a metrics module discovers contributors by. */
|
|
25
|
+
declare const METRICS_CONTRIBUTOR_METADATA = "bymax-one:metrics-contributor";
|
|
26
|
+
/**
|
|
27
|
+
* Registers the authentication collectors on the registry the scrape endpoint serves.
|
|
28
|
+
*
|
|
29
|
+
* Every counter is read from the tally on each scrape, after a reset, instead of being written as events
|
|
30
|
+
* arrive: the tally starts counting before this class runs, and a counter fed by events would drop that
|
|
31
|
+
* window. Labels are the closed sets the tally is keyed by; no id, tenant, user, address or message ever
|
|
32
|
+
* becomes one.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // providers: [AuthMetrics] (BymaxCoreModule discovers it and calls registerMetrics once at bootstrap)
|
|
36
|
+
*/
|
|
37
|
+
declare class AuthMetrics implements MetricsContributor {
|
|
38
|
+
private readonly tally;
|
|
39
|
+
constructor(tally: AuthMetricsTally);
|
|
40
|
+
/** Registers the collectors; called once at bootstrap by the metrics module. */
|
|
41
|
+
registerMetrics(registry: MetricsRegistry): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @fileoverview Reports whether the store the authentication flows depend on answers.
|
|
46
|
+
*
|
|
47
|
+
* This package imports no other Bymax library. The readiness contract of `@bymax-one/nest-core` that this
|
|
48
|
+
* class meets is written out below, and the key `BymaxCoreModule` discovers an indicator by is the
|
|
49
|
+
* documented string literal; a spec compares both with the published declarations.
|
|
50
|
+
*
|
|
51
|
+
* @layer Observability
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/** The outcome of one readiness check. */
|
|
55
|
+
interface HealthIndicatorResult {
|
|
56
|
+
status: 'up' | 'down';
|
|
57
|
+
details?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/** What a readiness indicator implements. */
|
|
60
|
+
interface HealthIndicator {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
check(signal?: AbortSignal): Promise<HealthIndicatorResult>;
|
|
63
|
+
}
|
|
64
|
+
/** The metadata key a health module discovers indicators by. */
|
|
65
|
+
declare const HEALTH_INDICATOR_METADATA = "bymax-one:health-indicator";
|
|
66
|
+
/**
|
|
67
|
+
* The readiness check of the authentication store.
|
|
68
|
+
*
|
|
69
|
+
* It asks the Redis client the module was given for a `PING`: one round trip, nothing written and nothing
|
|
70
|
+
* read that a caller owns. A client that rejects, answers anything but `PONG`, or does not answer in time is
|
|
71
|
+
* `down`: the probe gives up after its own timeout, under the aggregator's, and when the aggregator's signal
|
|
72
|
+
* aborts, and the aggregator turns the rejection into a `down` entry, so this class does not catch. No
|
|
73
|
+
* detail is reported, so nothing about the store leaves with it.
|
|
74
|
+
*/
|
|
75
|
+
declare class AuthRedisHealthIndicator implements HealthIndicator {
|
|
76
|
+
private readonly probe;
|
|
77
|
+
readonly name = "auth-redis";
|
|
78
|
+
constructor(probe: AuthHealthProbe);
|
|
79
|
+
/** Whether the store answers in time; the aggregator's signal ends the wait. */
|
|
80
|
+
check(signal?: AbortSignal): Promise<HealthIndicatorResult>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { AuthMetrics, AuthRedisHealthIndicator, HEALTH_INDICATOR_METADATA, METRICS_CONTRIBUTOR_METADATA };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { SetMetadata, Injectable, Inject } from '@nestjs/common';
|
|
2
|
+
import { Counter } from 'prom-client';
|
|
3
|
+
import { AuthMetricsTally, AuthHealthProbe, AUTH_PLANES, LOGIN_OUTCOMES, REFRESH_OUTCOMES, MFA_OUTCOMES } from '@bymax-one/nest-auth';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
10
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
} else {
|
|
12
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
13
|
+
if (d = decorators[i]) {
|
|
14
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
}
|
|
20
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
21
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
22
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
23
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
27
|
+
function _ts_param(paramIndex, decorator) {
|
|
28
|
+
return function(target, key) {
|
|
29
|
+
decorator(target, key, paramIndex);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
__name(_ts_param, "_ts_param");
|
|
33
|
+
var METRICS_CONTRIBUTOR_METADATA = "bymax-one:metrics-contributor";
|
|
34
|
+
function countedByPlaneAndOutcome(registry, spec) {
|
|
35
|
+
const { outcomes, read } = spec;
|
|
36
|
+
new Counter({
|
|
37
|
+
name: spec.name,
|
|
38
|
+
help: spec.help,
|
|
39
|
+
labelNames: [
|
|
40
|
+
"plane",
|
|
41
|
+
"outcome"
|
|
42
|
+
],
|
|
43
|
+
registers: [
|
|
44
|
+
registry
|
|
45
|
+
],
|
|
46
|
+
collect() {
|
|
47
|
+
this.reset();
|
|
48
|
+
const counts = read();
|
|
49
|
+
for (const plane of AUTH_PLANES) {
|
|
50
|
+
for (const outcome of outcomes) this.inc({
|
|
51
|
+
plane,
|
|
52
|
+
outcome
|
|
53
|
+
}, counts[plane][outcome]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
__name(countedByPlaneAndOutcome, "countedByPlaneAndOutcome");
|
|
59
|
+
var AuthMetrics = class {
|
|
60
|
+
static {
|
|
61
|
+
__name(this, "AuthMetrics");
|
|
62
|
+
}
|
|
63
|
+
tally;
|
|
64
|
+
constructor(tally) {
|
|
65
|
+
this.tally = tally;
|
|
66
|
+
}
|
|
67
|
+
/** Registers the collectors; called once at bootstrap by the metrics module. */
|
|
68
|
+
registerMetrics(registry) {
|
|
69
|
+
const { tally } = this;
|
|
70
|
+
countedByPlaneAndOutcome(registry, {
|
|
71
|
+
name: "bymax_auth_logins_total",
|
|
72
|
+
help: "Login attempts by plane and outcome.",
|
|
73
|
+
outcomes: LOGIN_OUTCOMES,
|
|
74
|
+
read: /* @__PURE__ */ __name(() => tally.snapshot().logins, "read")
|
|
75
|
+
});
|
|
76
|
+
countedByPlaneAndOutcome(registry, {
|
|
77
|
+
name: "bymax_auth_refresh_total",
|
|
78
|
+
help: "Refresh attempts by plane and outcome.",
|
|
79
|
+
outcomes: REFRESH_OUTCOMES,
|
|
80
|
+
read: /* @__PURE__ */ __name(() => tally.snapshot().refreshes, "read")
|
|
81
|
+
});
|
|
82
|
+
countedByPlaneAndOutcome(registry, {
|
|
83
|
+
name: "bymax_auth_mfa_verifications_total",
|
|
84
|
+
help: "MFA verifications by plane and outcome.",
|
|
85
|
+
outcomes: MFA_OUTCOMES,
|
|
86
|
+
read: /* @__PURE__ */ __name(() => tally.snapshot().mfa, "read")
|
|
87
|
+
});
|
|
88
|
+
new Counter({
|
|
89
|
+
name: "bymax_auth_bruteforce_lockouts_total",
|
|
90
|
+
help: "Identifiers locked out after too many failed attempts.",
|
|
91
|
+
registers: [
|
|
92
|
+
registry
|
|
93
|
+
],
|
|
94
|
+
collect() {
|
|
95
|
+
this.reset();
|
|
96
|
+
this.inc(tally.snapshot().lockouts);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
AuthMetrics = _ts_decorate([
|
|
102
|
+
SetMetadata(METRICS_CONTRIBUTOR_METADATA, true),
|
|
103
|
+
Injectable(),
|
|
104
|
+
_ts_param(0, Inject(AuthMetricsTally)),
|
|
105
|
+
_ts_metadata("design:type", Function),
|
|
106
|
+
_ts_metadata("design:paramtypes", [
|
|
107
|
+
typeof AuthMetricsTally === "undefined" ? Object : AuthMetricsTally
|
|
108
|
+
])
|
|
109
|
+
], AuthMetrics);
|
|
110
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
111
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
112
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
113
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
114
|
+
} else {
|
|
115
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
116
|
+
if (d = decorators[i]) {
|
|
117
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
122
|
+
}
|
|
123
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
124
|
+
function _ts_metadata2(metadataKey, metadataValue) {
|
|
125
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
126
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
130
|
+
function _ts_param2(paramIndex, decorator) {
|
|
131
|
+
return function(target, key) {
|
|
132
|
+
decorator(target, key, paramIndex);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
__name(_ts_param2, "_ts_param");
|
|
136
|
+
var HEALTH_INDICATOR_METADATA = "bymax-one:health-indicator";
|
|
137
|
+
var AuthRedisHealthIndicator = class {
|
|
138
|
+
static {
|
|
139
|
+
__name(this, "AuthRedisHealthIndicator");
|
|
140
|
+
}
|
|
141
|
+
probe;
|
|
142
|
+
name = "auth-redis";
|
|
143
|
+
constructor(probe) {
|
|
144
|
+
this.probe = probe;
|
|
145
|
+
}
|
|
146
|
+
/** Whether the store answers in time; the aggregator's signal ends the wait. */
|
|
147
|
+
async check(signal) {
|
|
148
|
+
return {
|
|
149
|
+
status: await this.probe.ping(signal) ? "up" : "down"
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
AuthRedisHealthIndicator = _ts_decorate2([
|
|
154
|
+
SetMetadata(HEALTH_INDICATOR_METADATA, true),
|
|
155
|
+
Injectable(),
|
|
156
|
+
_ts_param2(0, Inject(AuthHealthProbe)),
|
|
157
|
+
_ts_metadata2("design:type", Function),
|
|
158
|
+
_ts_metadata2("design:paramtypes", [
|
|
159
|
+
typeof AuthHealthProbe === "undefined" ? Object : AuthHealthProbe
|
|
160
|
+
])
|
|
161
|
+
], AuthRedisHealthIndicator);
|
|
162
|
+
|
|
163
|
+
export { AuthMetrics, AuthRedisHealthIndicator, HEALTH_INDICATOR_METADATA, METRICS_CONTRIBUTOR_METADATA };
|