@absolutejs/vulnerabilities-postgres 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alerts.d.ts +5 -1
- package/dist/index.js +15 -5
- package/package.json +1 -1
package/dist/alerts.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type VulnerabilityAlertPolicyVersion = {
|
|
|
16
16
|
export type ActiveVulnerabilityAlertPolicy = {
|
|
17
17
|
configuration: VulnerabilityAlertConfiguration;
|
|
18
18
|
tenantId: string;
|
|
19
|
-
version: number;
|
|
19
|
+
version: number | null;
|
|
20
20
|
};
|
|
21
21
|
export type VulnerabilityAlertIncidentRow = {
|
|
22
22
|
acknowledged_at: Date | null;
|
|
@@ -77,6 +77,8 @@ export declare class VulnerabilityAlertConflictError extends Error {
|
|
|
77
77
|
}
|
|
78
78
|
export declare class VulnerabilityAlertNotFoundError extends Error {
|
|
79
79
|
}
|
|
80
|
+
export declare class VulnerabilityAlertValidationError extends Error {
|
|
81
|
+
}
|
|
80
82
|
export type VulnerabilityAlertPolicyStore = {
|
|
81
83
|
activate: (input: {
|
|
82
84
|
activatedAt: string;
|
|
@@ -124,11 +126,13 @@ export type VulnerabilityAlertIncidentStore = {
|
|
|
124
126
|
observedAt?: string;
|
|
125
127
|
}) => Promise<"observed" | "opened" | "reopened">;
|
|
126
128
|
processEscalations: (input: {
|
|
129
|
+
fallbackPolicy?: ActiveVulnerabilityAlertPolicy;
|
|
127
130
|
policies: ReadonlyMap<string, ActiveVulnerabilityAlertPolicy>;
|
|
128
131
|
tenantIds?: readonly string[];
|
|
129
132
|
}) => Promise<number>;
|
|
130
133
|
resolveInactive: (input: {
|
|
131
134
|
activeAlertIds: ReadonlySet<string>;
|
|
135
|
+
fallbackPolicy?: ActiveVulnerabilityAlertPolicy;
|
|
132
136
|
policies: ReadonlyMap<string, ActiveVulnerabilityAlertPolicy>;
|
|
133
137
|
resolvedAt?: string;
|
|
134
138
|
tenantIds?: readonly string[];
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,9 @@ class VulnerabilityAlertConflictError extends Error {
|
|
|
23
23
|
|
|
24
24
|
class VulnerabilityAlertNotFoundError extends Error {
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
class VulnerabilityAlertValidationError extends Error {
|
|
28
|
+
}
|
|
26
29
|
var IDENTIFIER = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
27
30
|
var tables = (prefix) => ({
|
|
28
31
|
deliveries: `${prefix}_alert_deliveries`,
|
|
@@ -150,10 +153,15 @@ var createPostgresVulnerabilityAlertStores = (options) => {
|
|
|
150
153
|
const alertPolicies = {
|
|
151
154
|
activate: async (input) => {
|
|
152
155
|
await ready();
|
|
153
|
-
|
|
156
|
+
let configuration;
|
|
157
|
+
try {
|
|
158
|
+
configuration = validateVulnerabilityAlertConfiguration(input.configuration);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
throw new VulnerabilityAlertValidationError(error instanceof Error ? error.message : "Policy is invalid");
|
|
161
|
+
}
|
|
154
162
|
const reason = input.reason.trim();
|
|
155
163
|
if (!reason)
|
|
156
|
-
throw new
|
|
164
|
+
throw new VulnerabilityAlertValidationError("Policy activation reason is required");
|
|
157
165
|
return transaction(sql, async (tx) => {
|
|
158
166
|
await tx`SELECT pg_advisory_xact_lock(hashtext(${`vulnerability-alert-policy:${input.tenantId}`}))`;
|
|
159
167
|
const [latest] = await tx`SELECT COALESCE(MAX(version), 0)::integer AS version FROM ${tx.unsafe(table.policies)} WHERE tenant_id = ${input.tenantId}`;
|
|
@@ -266,13 +274,13 @@ var createPostgresVulnerabilityAlertStores = (options) => {
|
|
|
266
274
|
return sql`SELECT * FROM ${sql.unsafe(table.incidents)} ORDER BY last_observed_at DESC LIMIT ${boundedLimit(requestedLimit)}`;
|
|
267
275
|
},
|
|
268
276
|
observe,
|
|
269
|
-
processEscalations: async ({ policies, tenantIds }) => {
|
|
277
|
+
processEscalations: async ({ fallbackPolicy, policies, tenantIds }) => {
|
|
270
278
|
await ready();
|
|
271
279
|
const tenants = tenantPredicate(tenantIds);
|
|
272
280
|
const due = await sql`SELECT alert_id, asset_id, occurrence_count, severity, tenant_id FROM ${sql.unsafe(table.incidents)} WHERE status = 'open' AND next_escalation_at <= now() AND (${tenants}::jsonb IS NULL OR tenant_id IN (SELECT jsonb_array_elements_text(${tenants}::jsonb)))`;
|
|
273
281
|
let processed = 0;
|
|
274
282
|
for (const incident of due) {
|
|
275
|
-
const policy = policies.get(incident.tenant_id);
|
|
283
|
+
const policy = policies.get(incident.tenant_id) ?? fallbackPolicy;
|
|
276
284
|
if (!policy)
|
|
277
285
|
continue;
|
|
278
286
|
const changed = await transaction(sql, async (tx) => {
|
|
@@ -294,6 +302,7 @@ var createPostgresVulnerabilityAlertStores = (options) => {
|
|
|
294
302
|
},
|
|
295
303
|
resolveInactive: async ({
|
|
296
304
|
activeAlertIds,
|
|
305
|
+
fallbackPolicy,
|
|
297
306
|
policies,
|
|
298
307
|
resolvedAt,
|
|
299
308
|
tenantIds
|
|
@@ -306,7 +315,7 @@ var createPostgresVulnerabilityAlertStores = (options) => {
|
|
|
306
315
|
for (const incident of open) {
|
|
307
316
|
if (activeAlertIds.has(incident.alert_id))
|
|
308
317
|
continue;
|
|
309
|
-
const policy = policies.get(incident.tenant_id);
|
|
318
|
+
const policy = policies.get(incident.tenant_id) ?? fallbackPolicy;
|
|
310
319
|
if (!policy)
|
|
311
320
|
continue;
|
|
312
321
|
const changed = await transaction(sql, async (tx) => {
|
|
@@ -1298,6 +1307,7 @@ export {
|
|
|
1298
1307
|
vulnerabilityAlertPostgresSchemaSql,
|
|
1299
1308
|
createPostgresVulnerabilityStore,
|
|
1300
1309
|
createPostgresVulnerabilityAlertStores,
|
|
1310
|
+
VulnerabilityAlertValidationError,
|
|
1301
1311
|
VulnerabilityAlertNotFoundError,
|
|
1302
1312
|
VulnerabilityAlertConflictError
|
|
1303
1313
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/vulnerabilities-postgres",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Durable Postgres feeds, findings, alert incidents, policy history, delivery queues, remediation evidence, and risk assessments for AbsoluteJS vulnerability management.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BSL-1.1",
|