@openlup/platform 0.28.0 → 0.30.0
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 +369 -156
- package/README.md +220 -4
- package/dist/composition/index.d.ts +1 -0
- package/dist/composition/index.js +1 -0
- package/dist/composition/marketingContribution.d.ts +21 -0
- package/dist/composition/marketingContribution.js +29 -0
- package/dist/composition/nodeHost.d.ts +1 -1
- package/dist/composition/nodeHost.js +3 -2
- package/dist/lifecycle/appUpgrade.d.ts +52 -0
- package/dist/lifecycle/appUpgrade.js +180 -0
- package/dist/lifecycle/index.d.ts +2 -0
- package/dist/lifecycle/index.js +2 -0
- package/dist/lifecycle/postgresInstallQualification.d.ts +51 -0
- package/dist/lifecycle/postgresInstallQualification.js +74 -0
- package/dist/marketing/acquisitionCaseSchemas.d.ts +103 -0
- package/dist/marketing/acquisitionCaseSchemas.js +53 -0
- package/dist/marketing/acquisitionEvidenceSchemas.d.ts +105 -0
- package/dist/marketing/acquisitionEvidenceSchemas.js +55 -0
- package/dist/marketing/analytics/dataLayer.d.ts +18 -0
- package/dist/marketing/analytics/dataLayer.js +111 -0
- package/dist/marketing/analytics/noop.d.ts +9 -0
- package/dist/marketing/analytics/noop.js +8 -0
- package/dist/marketing/analytics/purchaseFacts.d.ts +4 -0
- package/dist/marketing/analytics/purchaseFacts.js +69 -0
- package/dist/marketing/analytics/routePolicy.d.ts +10 -0
- package/dist/marketing/analytics/routePolicy.js +59 -0
- package/dist/marketing/consentEvidence.d.ts +8 -0
- package/dist/marketing/consentEvidence.js +32 -0
- package/dist/marketing/contactLegal.d.ts +14 -0
- package/dist/marketing/contactLegal.js +19 -0
- package/dist/marketing/contracts/acquisition.d.ts +88 -0
- package/dist/marketing/contracts/acquisition.js +1 -0
- package/dist/marketing/contracts/acquisitionPorts.d.ts +49 -0
- package/dist/marketing/contracts/acquisitionPorts.js +1 -0
- package/dist/marketing/contracts/analytics.d.ts +144 -0
- package/dist/marketing/contracts/analytics.js +1 -0
- package/dist/marketing/contracts/contactLegal.d.ts +53 -0
- package/dist/marketing/contracts/contactLegal.js +1 -0
- package/dist/marketing/contracts/index.d.ts +6 -0
- package/dist/marketing/contracts/index.js +1 -0
- package/dist/marketing/contracts/prelaunch.d.ts +39 -0
- package/dist/marketing/contracts/prelaunch.js +1 -0
- package/dist/marketing/index.d.ts +16 -0
- package/dist/marketing/index.js +14 -0
- package/dist/marketing/prelaunchAcquisitionSchemas.d.ts +116 -0
- package/dist/marketing/prelaunchAcquisitionSchemas.js +51 -0
- package/dist/marketing/seo/jsonLd.d.ts +157 -0
- package/dist/marketing/seo/jsonLd.js +127 -0
- package/dist/marketing/seo/metadata.d.ts +41 -0
- package/dist/marketing/seo/metadata.js +36 -0
- package/dist/marketing/seo/serializeJsonLd.d.ts +1 -0
- package/dist/marketing/seo/serializeJsonLd.js +6 -0
- package/dist/marketing/seo/urls.d.ts +14 -0
- package/dist/marketing/seo/urls.js +23 -0
- package/dist/marketing/server/acquisitionCaseDirect.d.ts +4 -0
- package/dist/marketing/server/acquisitionCaseDirect.js +88 -0
- package/dist/marketing/server/acquisitionCaseHandlers.d.ts +28 -0
- package/dist/marketing/server/acquisitionCaseHandlers.js +40 -0
- package/dist/marketing/server/acquisitionCasePorts.d.ts +42 -0
- package/dist/marketing/server/acquisitionCasePorts.js +1 -0
- package/dist/marketing/server/acquisitionEvidenceDirect.d.ts +5 -0
- package/dist/marketing/server/acquisitionEvidenceDirect.js +100 -0
- package/dist/marketing/server/analyticsContext.d.ts +3 -0
- package/dist/marketing/server/analyticsContext.js +65 -0
- package/dist/marketing/server/analyticsContextPorts.d.ts +31 -0
- package/dist/marketing/server/analyticsContextPorts.js +1 -0
- package/dist/marketing/server/bindings.d.ts +14 -0
- package/dist/marketing/server/bindings.js +18 -0
- package/dist/marketing/server/directPorts.d.ts +26 -0
- package/dist/marketing/server/directPorts.js +1 -0
- package/dist/marketing/server/index.d.ts +14 -0
- package/dist/marketing/server/index.js +11 -0
- package/dist/marketing/server/postgres/acquisitionCaseRoutines.d.ts +10 -0
- package/dist/marketing/server/postgres/acquisitionCaseRoutines.js +204 -0
- package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.d.ts +10 -0
- package/dist/marketing/server/postgres/acquisitionEvidenceRoutines.js +107 -0
- package/dist/marketing/server/postgres/index.d.ts +3 -0
- package/dist/marketing/server/postgres/index.js +3 -0
- package/dist/marketing/server/prelaunchAcquisitionDirect.d.ts +4 -0
- package/dist/marketing/server/prelaunchAcquisitionDirect.js +122 -0
- package/dist/marketing/server/privacyContributor.d.ts +66 -0
- package/dist/marketing/server/privacyContributor.js +87 -0
- package/dist/marketing/server/research/adminSurveyResponsesHandler.d.ts +9 -0
- package/dist/marketing/server/research/adminSurveyResponsesHandler.js +53 -0
- package/dist/marketing/server/research/managedSurveyResponseSubmit.d.ts +39 -0
- package/dist/marketing/server/research/managedSurveyResponseSubmit.js +102 -0
- package/dist/marketing/server/research/surveyResponseSubmitHandler.d.ts +8 -0
- package/dist/marketing/server/research/surveyResponseSubmitHandler.js +41 -0
- package/dist/marketing/validation.d.ts +2 -0
- package/dist/marketing/validation.js +3 -0
- package/dist/migrations/postgresRunner.d.ts +9 -0
- package/dist/migrations/postgresRunner.js +17 -10
- package/dist/operations/adminAlertsSchemas.d.ts +153 -0
- package/dist/operations/adminAlertsSchemas.js +69 -0
- package/dist/operations/adminAlertsView.d.ts +73 -0
- package/dist/operations/adminAlertsView.js +184 -0
- package/dist/operations/alertPagingPolicy.d.ts +15 -0
- package/dist/operations/alertPagingPolicy.js +43 -0
- package/dist/operations/alertThrottlePolicy.d.ts +3 -0
- package/dist/operations/alertThrottlePolicy.js +18 -0
- package/dist/operations/clients.d.ts +17 -0
- package/dist/operations/clients.js +32 -0
- package/dist/operations/contracts/admin.d.ts +93 -0
- package/dist/operations/contracts/admin.js +1 -0
- package/dist/operations/contracts/adminAlertsContracts.d.ts +40 -0
- package/dist/operations/contracts/adminAlertsContracts.js +1 -0
- package/dist/operations/contracts/alertHumanContext.d.ts +7 -0
- package/dist/operations/contracts/alertHumanContext.js +1 -0
- package/dist/operations/contracts/index.d.ts +6 -0
- package/dist/operations/contracts/index.js +6 -0
- package/dist/operations/contracts/observabilityContracts.d.ts +41 -0
- package/dist/operations/contracts/observabilityContracts.js +1 -0
- package/dist/operations/contracts/observabilityPorts.d.ts +18 -0
- package/dist/operations/contracts/observabilityPorts.js +1 -0
- package/dist/operations/contracts/ports.d.ts +19 -0
- package/dist/operations/contracts/ports.js +1 -0
- package/dist/operations/errors.d.ts +6 -0
- package/dist/operations/errors.js +6 -0
- package/dist/operations/index.d.ts +9 -0
- package/dist/operations/index.js +9 -0
- package/dist/operations/schemas.d.ts +138 -0
- package/dist/operations/schemas.js +104 -0
- package/dist/operations/server/adminAlertsHandlers.d.ts +16 -0
- package/dist/operations/server/adminAlertsHandlers.js +35 -0
- package/dist/operations/server/adminPipelineHandlers.d.ts +12 -0
- package/dist/operations/server/adminPipelineHandlers.js +48 -0
- package/dist/operations/server/adminSettingsHandlers.d.ts +14 -0
- package/dist/operations/server/adminSettingsHandlers.js +82 -0
- package/dist/operations/server/controlPlaneHandler.d.ts +7 -0
- package/dist/operations/server/controlPlaneHandler.js +54 -0
- package/dist/operations/server/controlPlaneStore.d.ts +12 -0
- package/dist/operations/server/controlPlaneStore.js +138 -0
- package/dist/operations/server/controlPlaneWatchdog.d.ts +7 -0
- package/dist/operations/server/controlPlaneWatchdog.js +20 -0
- package/dist/operations/server/index.d.ts +12 -0
- package/dist/operations/server/index.js +12 -0
- package/dist/operations/server/migrations.d.ts +14 -0
- package/dist/operations/server/migrations.js +7 -0
- package/dist/operations/server/platformWatchdogDecision.d.ts +34 -0
- package/dist/operations/server/platformWatchdogDecision.js +71 -0
- package/dist/operations/server/platformWatchdogDeliveryPolicy.d.ts +10 -0
- package/dist/operations/server/platformWatchdogDeliveryPolicy.js +53 -0
- package/dist/operations/server/platformWatchdogQueue.d.ts +11 -0
- package/dist/operations/server/platformWatchdogQueue.js +94 -0
- package/dist/operations/server/platformWatchdogService.d.ts +47 -0
- package/dist/operations/server/platformWatchdogService.js +105 -0
- package/dist/operations/validation.d.ts +2 -0
- package/dist/operations/validation.js +3 -0
- package/dist/portability/filesystemObjects.d.ts +12 -0
- package/dist/portability/filesystemObjects.js +191 -0
- package/dist/portability/index.d.ts +5 -0
- package/dist/portability/index.js +4 -0
- package/dist/portability/objects.d.ts +63 -0
- package/dist/portability/objects.js +138 -0
- package/dist/portability/postgresRows.d.ts +64 -0
- package/dist/portability/postgresRows.js +182 -0
- package/dist/scheduler/advisoryLock.js +20 -2
- package/dist/scheduler/nodeScheduler.d.ts +2 -2
- package/dist/scheduler/nodeScheduler.js +35 -6
- package/package.json +47 -2
- package/release-gates.json +143 -9
- package/sql/20260814010000_platform_control_plane.sql +286 -0
- package/src/composition/index.ts +1 -0
- package/src/composition/marketingContribution.ts +37 -0
- package/src/composition/nodeHost.ts +4 -3
- package/src/lifecycle/appUpgrade.ts +186 -0
- package/src/lifecycle/index.ts +19 -0
- package/src/lifecycle/postgresInstallQualification.ts +125 -0
- package/src/marketing/acquisitionCaseSchemas.ts +75 -0
- package/src/marketing/acquisitionEvidenceSchemas.ts +72 -0
- package/src/marketing/analytics/dataLayer.ts +100 -0
- package/src/marketing/analytics/noop.ts +14 -0
- package/src/marketing/analytics/purchaseFacts.ts +63 -0
- package/src/marketing/analytics/routePolicy.ts +55 -0
- package/src/marketing/consentEvidence.ts +36 -0
- package/src/marketing/contactLegal.ts +22 -0
- package/src/marketing/contracts/acquisition.ts +50 -0
- package/src/marketing/contracts/acquisitionPorts.ts +48 -0
- package/src/marketing/contracts/analytics.ts +88 -0
- package/src/marketing/contracts/contactLegal.ts +41 -0
- package/src/marketing/contracts/index.ts +17 -0
- package/src/marketing/contracts/prelaunch.ts +15 -0
- package/src/marketing/index.ts +16 -0
- package/src/marketing/prelaunchAcquisitionSchemas.ts +64 -0
- package/src/marketing/seo/jsonLd.ts +153 -0
- package/src/marketing/seo/metadata.ts +62 -0
- package/src/marketing/seo/serializeJsonLd.ts +6 -0
- package/src/marketing/seo/urls.ts +34 -0
- package/src/marketing/server/acquisitionCaseDirect.ts +67 -0
- package/src/marketing/server/acquisitionCaseHandlers.ts +57 -0
- package/src/marketing/server/acquisitionCasePorts.ts +42 -0
- package/src/marketing/server/acquisitionEvidenceDirect.ts +76 -0
- package/src/marketing/server/analyticsContext.ts +55 -0
- package/src/marketing/server/analyticsContextPorts.ts +28 -0
- package/src/marketing/server/bindings.ts +27 -0
- package/src/marketing/server/directPorts.ts +27 -0
- package/src/marketing/server/index.ts +14 -0
- package/src/marketing/server/postgres/acquisitionCaseRoutines.ts +218 -0
- package/src/marketing/server/postgres/acquisitionEvidenceRoutines.ts +103 -0
- package/src/marketing/server/postgres/index.ts +3 -0
- package/src/marketing/server/prelaunchAcquisitionDirect.ts +121 -0
- package/src/marketing/server/privacyContributor.ts +123 -0
- package/src/marketing/server/research/adminSurveyResponsesHandler.ts +78 -0
- package/src/marketing/server/research/managedSurveyResponseSubmit.ts +158 -0
- package/src/marketing/server/research/surveyResponseSubmitHandler.ts +57 -0
- package/src/marketing/validation.ts +3 -0
- package/src/migrations/postgresRunner.ts +24 -9
- package/src/operations/adminAlertsSchemas.ts +78 -0
- package/src/operations/adminAlertsView.ts +238 -0
- package/src/operations/alertPagingPolicy.ts +50 -0
- package/src/operations/alertThrottlePolicy.ts +22 -0
- package/src/operations/clients.ts +44 -0
- package/src/operations/contracts/admin.ts +24 -0
- package/src/operations/contracts/adminAlertsContracts.ts +13 -0
- package/src/operations/contracts/alertHumanContext.ts +17 -0
- package/src/operations/contracts/index.ts +6 -0
- package/src/operations/contracts/observabilityContracts.ts +40 -0
- package/src/operations/contracts/observabilityPorts.ts +30 -0
- package/src/operations/contracts/ports.ts +22 -0
- package/src/operations/errors.ts +6 -0
- package/src/operations/index.ts +9 -0
- package/src/operations/schemas.ts +122 -0
- package/src/operations/server/adminAlertsHandlers.ts +61 -0
- package/src/operations/server/adminPipelineHandlers.ts +73 -0
- package/src/operations/server/adminSettingsHandlers.ts +114 -0
- package/src/operations/server/controlPlaneHandler.ts +56 -0
- package/src/operations/server/controlPlaneStore.ts +150 -0
- package/src/operations/server/controlPlaneWatchdog.ts +28 -0
- package/src/operations/server/index.ts +12 -0
- package/src/operations/server/migrations.ts +7 -0
- package/src/operations/server/platformWatchdogDecision.ts +93 -0
- package/src/operations/server/platformWatchdogDeliveryPolicy.ts +92 -0
- package/src/operations/server/platformWatchdogQueue.ts +96 -0
- package/src/operations/server/platformWatchdogService.ts +209 -0
- package/src/operations/validation.ts +3 -0
- package/src/portability/filesystemObjects.ts +138 -0
- package/src/portability/index.ts +12 -0
- package/src/portability/objects.ts +160 -0
- package/src/portability/postgresRows.ts +169 -0
- package/src/scheduler/advisoryLock.ts +20 -5
- package/src/scheduler/nodeScheduler.ts +28 -8
|
@@ -34,6 +34,15 @@ export interface PlatformMigrationSource {
|
|
|
34
34
|
migrations: readonly PlatformMigrationFile[];
|
|
35
35
|
objectInventoryPayload?: string;
|
|
36
36
|
}): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Optional trusted-source observation/refusal after exact-prefix validation, under the
|
|
39
|
+
* migration session lock. Runs once per operation before any pending SQL or dry-run result.
|
|
40
|
+
* The canonical source uses read-only observations; the callback shares the caller's existing
|
|
41
|
+
* database capability and is not a sandbox or a provisioning/per-unit execution hook.
|
|
42
|
+
*/
|
|
43
|
+
assertSession?(client: PoolClient, applied: readonly (PlatformMigrationManifestEntry & {
|
|
44
|
+
position: number;
|
|
45
|
+
})[]): Promise<void>;
|
|
37
46
|
}
|
|
38
47
|
export interface PostgresMigrationRunnerOptions {
|
|
39
48
|
/** Name of the PostgreSQL advisory lock that serializes migration sessions. */
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
const LEDGER = "public.platform_schema_migrations";
|
|
7
7
|
const ACQUIRE_MIGRATION_LOCK = "SELECT pg_advisory_lock(hashtextextended($1, 0))";
|
|
8
8
|
const RELEASE_MIGRATION_LOCK = "SELECT pg_advisory_unlock(hashtextextended($1, 0)) AS unlocked";
|
|
9
|
+
const ACQUIRE_CATALOG_BOUND_MIGRATION_LOCK = "SELECT pg_catalog.pg_advisory_lock(pg_catalog.hashtextextended($1::pg_catalog.text, 0::pg_catalog.int8))";
|
|
10
|
+
const RELEASE_CATALOG_BOUND_MIGRATION_LOCK = "SELECT pg_catalog.pg_advisory_unlock(pg_catalog.hashtextextended($1::pg_catalog.text, 0::pg_catalog.int8)) AS unlocked";
|
|
11
|
+
const CATALOG_BOUND_LEDGER_EXISTENCE = "SELECT pg_catalog.to_regclass($1::pg_catalog.text) IS NOT NULL AS ledger_exists";
|
|
9
12
|
export function createPostgresMigrationRunner(env, options) {
|
|
10
13
|
const root = options.root ?? process.cwd();
|
|
11
14
|
let pool = null;
|
|
@@ -20,8 +23,10 @@ export function createPostgresMigrationRunner(env, options) {
|
|
|
20
23
|
async status() {
|
|
21
24
|
assertConnectionString(env);
|
|
22
25
|
const plan = loadPlan(root, options.source);
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
const catalogBoundSession = options.source.assertSession !== undefined;
|
|
27
|
+
return withMigrationSession(await getPool(), options.lockName, catalogBoundSession, async (client) => {
|
|
28
|
+
const applied = await readAppliedPrefix(client, plan.units, catalogBoundSession);
|
|
29
|
+
await options.source.assertSession?.(client, applied.map((unit) => ({ file: unit.catalogPath, sha256: unit.sha256, position: unit.position })));
|
|
25
30
|
if (applied.length === plan.units.length)
|
|
26
31
|
await assertObjectInventory(client, plan, options);
|
|
27
32
|
return {
|
|
@@ -33,8 +38,10 @@ export function createPostgresMigrationRunner(env, options) {
|
|
|
33
38
|
async apply(opts) {
|
|
34
39
|
assertConnectionString(env);
|
|
35
40
|
const plan = loadPlan(root, options.source);
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const catalogBoundSession = options.source.assertSession !== undefined;
|
|
42
|
+
return withMigrationSession(await getPool(), options.lockName, catalogBoundSession, async (client) => {
|
|
43
|
+
const already = await readAppliedPrefix(client, plan.units, catalogBoundSession);
|
|
44
|
+
await options.source.assertSession?.(client, already.map((unit) => ({ file: unit.catalogPath, sha256: unit.sha256, position: unit.position })));
|
|
38
45
|
const pending = plan.units.slice(already.length);
|
|
39
46
|
if (opts?.dryRun) {
|
|
40
47
|
if (pending.length === 0)
|
|
@@ -55,7 +62,7 @@ export function createPostgresMigrationRunner(env, options) {
|
|
|
55
62
|
throw new Error(`platform migration ${unit.catalogPath} failed: ${errorMessage(error)}`);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
|
-
const complete = await readAppliedPrefix(client, plan.units);
|
|
65
|
+
const complete = await readAppliedPrefix(client, plan.units, catalogBoundSession);
|
|
59
66
|
if (complete.length !== plan.units.length)
|
|
60
67
|
throw new Error("platform migration ledger is incomplete after apply");
|
|
61
68
|
await assertObjectInventory(client, plan, options);
|
|
@@ -64,14 +71,14 @@ export function createPostgresMigrationRunner(env, options) {
|
|
|
64
71
|
},
|
|
65
72
|
};
|
|
66
73
|
}
|
|
67
|
-
async function withMigrationSession(pool, lockName, operation) {
|
|
74
|
+
async function withMigrationSession(pool, lockName, catalogBoundSession, operation) {
|
|
68
75
|
const client = await pool.connect();
|
|
69
76
|
let locked = false;
|
|
70
77
|
let failed = false;
|
|
71
78
|
let operationFailure;
|
|
72
79
|
let result;
|
|
73
80
|
try {
|
|
74
|
-
await client.query(ACQUIRE_MIGRATION_LOCK, [lockName]);
|
|
81
|
+
await client.query(catalogBoundSession ? ACQUIRE_CATALOG_BOUND_MIGRATION_LOCK : ACQUIRE_MIGRATION_LOCK, [lockName]);
|
|
75
82
|
locked = true;
|
|
76
83
|
result = await operation(client);
|
|
77
84
|
}
|
|
@@ -82,7 +89,7 @@ async function withMigrationSession(pool, lockName, operation) {
|
|
|
82
89
|
let unlockFailure;
|
|
83
90
|
if (locked) {
|
|
84
91
|
try {
|
|
85
|
-
const unlocked = await client.query(RELEASE_MIGRATION_LOCK, [lockName]);
|
|
92
|
+
const unlocked = await client.query(catalogBoundSession ? RELEASE_CATALOG_BOUND_MIGRATION_LOCK : RELEASE_MIGRATION_LOCK, [lockName]);
|
|
86
93
|
if (unlocked.rows[0]?.unlocked !== true)
|
|
87
94
|
throw new Error("PostgreSQL did not release the advisory lock");
|
|
88
95
|
}
|
|
@@ -128,8 +135,8 @@ function loadPlan(root, source) {
|
|
|
128
135
|
}));
|
|
129
136
|
return Object.freeze({ manifest, migrations: catalog.migrations, units: Object.freeze(units) });
|
|
130
137
|
}
|
|
131
|
-
async function readAppliedPrefix(client, units) {
|
|
132
|
-
const exists = await client.query("SELECT to_regclass($1) IS NOT NULL AS ledger_exists", [LEDGER]);
|
|
138
|
+
async function readAppliedPrefix(client, units, catalogBoundSession) {
|
|
139
|
+
const exists = await client.query(catalogBoundSession ? CATALOG_BOUND_LEDGER_EXISTENCE : "SELECT to_regclass($1) IS NOT NULL AS ledger_exists", [LEDGER]);
|
|
133
140
|
if (exists.rows[0]?.ledger_exists !== true)
|
|
134
141
|
return [];
|
|
135
142
|
const result = await client.query(`SELECT catalog_path, sha256, position FROM ${LEDGER} ORDER BY position`);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { z } from "./validation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Admin-facing projection of the platform alert ledger.
|
|
4
|
+
*
|
|
5
|
+
* Only what an operator needs to read; the ledger itself stays service-role only
|
|
6
|
+
* (platform_alerts REVOKEs ALL from `authenticated`), so this shape is served by
|
|
7
|
+
* /api/bff/admin/platform/alerts rather than by PostgREST.
|
|
8
|
+
*/
|
|
9
|
+
export declare const adminAlertSeveritySchema: z.ZodEnum<{
|
|
10
|
+
p0: "p0";
|
|
11
|
+
p1: "p1";
|
|
12
|
+
p2: "p2";
|
|
13
|
+
p3: "p3";
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Audience split, derived from `platform_alerts.owner`:
|
|
17
|
+
* commerce -> a business operator can act on it
|
|
18
|
+
* platform -> engineering owns it; shown for context so the health pill is explainable
|
|
19
|
+
*/
|
|
20
|
+
export declare const adminAlertLaneSchema: z.ZodEnum<{
|
|
21
|
+
commerce: "commerce";
|
|
22
|
+
platform: "platform";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const adminAlertHealthSchema: z.ZodEnum<{
|
|
25
|
+
unknown: "unknown";
|
|
26
|
+
ok: "ok";
|
|
27
|
+
degraded: "degraded";
|
|
28
|
+
down: "down";
|
|
29
|
+
}>;
|
|
30
|
+
export declare const adminAlertSchema: z.ZodObject<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
dedupeKey: z.ZodString;
|
|
33
|
+
lane: z.ZodEnum<{
|
|
34
|
+
commerce: "commerce";
|
|
35
|
+
platform: "platform";
|
|
36
|
+
}>;
|
|
37
|
+
owner: z.ZodString;
|
|
38
|
+
severity: z.ZodEnum<{
|
|
39
|
+
p0: "p0";
|
|
40
|
+
p1: "p1";
|
|
41
|
+
p2: "p2";
|
|
42
|
+
p3: "p3";
|
|
43
|
+
}>;
|
|
44
|
+
status: z.ZodEnum<{
|
|
45
|
+
open: "open";
|
|
46
|
+
acknowledged: "acknowledged";
|
|
47
|
+
}>;
|
|
48
|
+
pageable: z.ZodBoolean;
|
|
49
|
+
title: z.ZodString;
|
|
50
|
+
message: z.ZodString;
|
|
51
|
+
supportCode: z.ZodNullable<z.ZodString>;
|
|
52
|
+
runbookUrl: z.ZodNullable<z.ZodString>;
|
|
53
|
+
firstSeenAt: z.ZodString;
|
|
54
|
+
lastSeenAt: z.ZodString;
|
|
55
|
+
snoozedUntil: z.ZodNullable<z.ZodString>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
export declare const adminAlertsHeartbeatSchema: z.ZodObject<{
|
|
58
|
+
lastSuccessAt: z.ZodNullable<z.ZodString>;
|
|
59
|
+
staleAfterSeconds: z.ZodNumber;
|
|
60
|
+
stale: z.ZodBoolean;
|
|
61
|
+
}, z.core.$strict>;
|
|
62
|
+
export declare const adminAlertsSummarySchema: z.ZodObject<{
|
|
63
|
+
commercePageableCount: z.ZodNumber;
|
|
64
|
+
commerceTotalCount: z.ZodNumber;
|
|
65
|
+
platformPageableCount: z.ZodNumber;
|
|
66
|
+
snoozedCount: z.ZodNumber;
|
|
67
|
+
maxOpenSeverity: z.ZodNullable<z.ZodEnum<{
|
|
68
|
+
p0: "p0";
|
|
69
|
+
p1: "p1";
|
|
70
|
+
p2: "p2";
|
|
71
|
+
p3: "p3";
|
|
72
|
+
}>>;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
export declare const adminAlertsOverviewResponseSchema: z.ZodObject<{
|
|
75
|
+
health: z.ZodEnum<{
|
|
76
|
+
unknown: "unknown";
|
|
77
|
+
ok: "ok";
|
|
78
|
+
degraded: "degraded";
|
|
79
|
+
down: "down";
|
|
80
|
+
}>;
|
|
81
|
+
summary: z.ZodObject<{
|
|
82
|
+
commercePageableCount: z.ZodNumber;
|
|
83
|
+
commerceTotalCount: z.ZodNumber;
|
|
84
|
+
platformPageableCount: z.ZodNumber;
|
|
85
|
+
snoozedCount: z.ZodNumber;
|
|
86
|
+
maxOpenSeverity: z.ZodNullable<z.ZodEnum<{
|
|
87
|
+
p0: "p0";
|
|
88
|
+
p1: "p1";
|
|
89
|
+
p2: "p2";
|
|
90
|
+
p3: "p3";
|
|
91
|
+
}>>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
heartbeat: z.ZodObject<{
|
|
94
|
+
lastSuccessAt: z.ZodNullable<z.ZodString>;
|
|
95
|
+
staleAfterSeconds: z.ZodNumber;
|
|
96
|
+
stale: z.ZodBoolean;
|
|
97
|
+
}, z.core.$strict>;
|
|
98
|
+
alerts: z.ZodArray<z.ZodObject<{
|
|
99
|
+
id: z.ZodString;
|
|
100
|
+
dedupeKey: z.ZodString;
|
|
101
|
+
lane: z.ZodEnum<{
|
|
102
|
+
commerce: "commerce";
|
|
103
|
+
platform: "platform";
|
|
104
|
+
}>;
|
|
105
|
+
owner: z.ZodString;
|
|
106
|
+
severity: z.ZodEnum<{
|
|
107
|
+
p0: "p0";
|
|
108
|
+
p1: "p1";
|
|
109
|
+
p2: "p2";
|
|
110
|
+
p3: "p3";
|
|
111
|
+
}>;
|
|
112
|
+
status: z.ZodEnum<{
|
|
113
|
+
open: "open";
|
|
114
|
+
acknowledged: "acknowledged";
|
|
115
|
+
}>;
|
|
116
|
+
pageable: z.ZodBoolean;
|
|
117
|
+
title: z.ZodString;
|
|
118
|
+
message: z.ZodString;
|
|
119
|
+
supportCode: z.ZodNullable<z.ZodString>;
|
|
120
|
+
runbookUrl: z.ZodNullable<z.ZodString>;
|
|
121
|
+
firstSeenAt: z.ZodString;
|
|
122
|
+
lastSeenAt: z.ZodString;
|
|
123
|
+
snoozedUntil: z.ZodNullable<z.ZodString>;
|
|
124
|
+
}, z.core.$strict>>;
|
|
125
|
+
snoozedAlerts: z.ZodArray<z.ZodObject<{
|
|
126
|
+
id: z.ZodString;
|
|
127
|
+
dedupeKey: z.ZodString;
|
|
128
|
+
lane: z.ZodEnum<{
|
|
129
|
+
commerce: "commerce";
|
|
130
|
+
platform: "platform";
|
|
131
|
+
}>;
|
|
132
|
+
owner: z.ZodString;
|
|
133
|
+
severity: z.ZodEnum<{
|
|
134
|
+
p0: "p0";
|
|
135
|
+
p1: "p1";
|
|
136
|
+
p2: "p2";
|
|
137
|
+
p3: "p3";
|
|
138
|
+
}>;
|
|
139
|
+
status: z.ZodEnum<{
|
|
140
|
+
open: "open";
|
|
141
|
+
acknowledged: "acknowledged";
|
|
142
|
+
}>;
|
|
143
|
+
pageable: z.ZodBoolean;
|
|
144
|
+
title: z.ZodString;
|
|
145
|
+
message: z.ZodString;
|
|
146
|
+
supportCode: z.ZodNullable<z.ZodString>;
|
|
147
|
+
runbookUrl: z.ZodNullable<z.ZodString>;
|
|
148
|
+
firstSeenAt: z.ZodString;
|
|
149
|
+
lastSeenAt: z.ZodString;
|
|
150
|
+
snoozedUntil: z.ZodNullable<z.ZodString>;
|
|
151
|
+
}, z.core.$strict>>;
|
|
152
|
+
generatedAt: z.ZodString;
|
|
153
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "./validation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Admin-facing projection of the platform alert ledger.
|
|
4
|
+
*
|
|
5
|
+
* Only what an operator needs to read; the ledger itself stays service-role only
|
|
6
|
+
* (platform_alerts REVOKEs ALL from `authenticated`), so this shape is served by
|
|
7
|
+
* /api/bff/admin/platform/alerts rather than by PostgREST.
|
|
8
|
+
*/
|
|
9
|
+
export const adminAlertSeveritySchema = z.enum(["p0", "p1", "p2", "p3"]);
|
|
10
|
+
/**
|
|
11
|
+
* Audience split, derived from `platform_alerts.owner`:
|
|
12
|
+
* commerce -> a business operator can act on it
|
|
13
|
+
* platform -> engineering owns it; shown for context so the health pill is explainable
|
|
14
|
+
*/
|
|
15
|
+
export const adminAlertLaneSchema = z.enum(["commerce", "platform"]);
|
|
16
|
+
export const adminAlertHealthSchema = z.enum(["ok", "degraded", "down", "unknown"]);
|
|
17
|
+
const isoDateTimeSchema = z.string().datetime({ offset: true });
|
|
18
|
+
export const adminAlertSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
id: z.string().min(1).max(128),
|
|
21
|
+
dedupeKey: z.string().min(1).max(256),
|
|
22
|
+
lane: adminAlertLaneSchema,
|
|
23
|
+
// Free text on purpose: platform_alerts.owner has no CHECK constraint, so an
|
|
24
|
+
// enum here would throw the whole admin shell on the first new owner string.
|
|
25
|
+
// The open-endedness is absorbed by `lane`.
|
|
26
|
+
owner: z.string().trim().min(1).max(128),
|
|
27
|
+
severity: adminAlertSeveritySchema,
|
|
28
|
+
status: z.enum(["open", "acknowledged"]),
|
|
29
|
+
// Server-decided so every consumer agrees; the client never re-derives it.
|
|
30
|
+
pageable: z.boolean(),
|
|
31
|
+
title: z.string().trim().min(1).max(512),
|
|
32
|
+
message: z.string().trim().max(4096),
|
|
33
|
+
supportCode: z.string().trim().max(128).nullable(),
|
|
34
|
+
runbookUrl: z.string().trim().max(1024).nullable(),
|
|
35
|
+
firstSeenAt: isoDateTimeSchema,
|
|
36
|
+
lastSeenAt: isoDateTimeSchema,
|
|
37
|
+
snoozedUntil: isoDateTimeSchema.nullable(),
|
|
38
|
+
})
|
|
39
|
+
.strict();
|
|
40
|
+
export const adminAlertsHeartbeatSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
lastSuccessAt: isoDateTimeSchema.nullable(),
|
|
43
|
+
staleAfterSeconds: z.number().int().positive(),
|
|
44
|
+
stale: z.boolean(),
|
|
45
|
+
})
|
|
46
|
+
.strict();
|
|
47
|
+
export const adminAlertsSummarySchema = z
|
|
48
|
+
.object({
|
|
49
|
+
/** Drives the bell badge. */
|
|
50
|
+
commercePageableCount: z.number().int().min(0),
|
|
51
|
+
commerceTotalCount: z.number().int().min(0),
|
|
52
|
+
platformPageableCount: z.number().int().min(0),
|
|
53
|
+
/** Visible controlled exceptions; excluded from paging and health degradation. */
|
|
54
|
+
snoozedCount: z.number().int().min(0),
|
|
55
|
+
maxOpenSeverity: adminAlertSeveritySchema.nullable(),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
export const adminAlertsOverviewResponseSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
health: adminAlertHealthSchema,
|
|
61
|
+
summary: adminAlertsSummarySchema,
|
|
62
|
+
heartbeat: adminAlertsHeartbeatSchema,
|
|
63
|
+
alerts: z.array(adminAlertSchema).max(50),
|
|
64
|
+
// Snoozed rows are returned separately from the active-list cap so a
|
|
65
|
+
// controlled exception never disappears behind routine diagnostics.
|
|
66
|
+
snoozedAlerts: z.array(adminAlertSchema).max(200),
|
|
67
|
+
generatedAt: isoDateTimeSchema,
|
|
68
|
+
})
|
|
69
|
+
.strict();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { AdminAlert, AdminAlertHealth, AdminAlertLane, AdminAlertSeverity, AdminAlertsHeartbeat, AdminAlertsOverviewResponse, AdminAlertsSummary } from "./contracts/adminAlertsContracts.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure projection of platform_alerts rows onto the admin shell's badges.
|
|
4
|
+
*
|
|
5
|
+
* All filtering lives here rather than in SQL so the `now` boundary is injectable
|
|
6
|
+
* and every rule is unit-testable without a database.
|
|
7
|
+
*/
|
|
8
|
+
/** Raw ledger row as selected from public.platform_alerts. */
|
|
9
|
+
export type PlatformAlertLedgerRow = {
|
|
10
|
+
id: string;
|
|
11
|
+
dedupe_key: string;
|
|
12
|
+
owner: string;
|
|
13
|
+
severity: string;
|
|
14
|
+
status: string;
|
|
15
|
+
title: string;
|
|
16
|
+
message: string | null;
|
|
17
|
+
support_code: string | null;
|
|
18
|
+
runbook_url: string | null;
|
|
19
|
+
first_seen_at: string;
|
|
20
|
+
last_seen_at: string;
|
|
21
|
+
snoozed_until: string | null;
|
|
22
|
+
};
|
|
23
|
+
export type WatchdogHeartbeatRow = {
|
|
24
|
+
last_success_at: string | null;
|
|
25
|
+
} | null;
|
|
26
|
+
/**
|
|
27
|
+
* Generic scheduled-job alerts inherit `owner` from the job catalog entry, so a
|
|
28
|
+
* commerce-owned job leaks engineer-only noise ("this cron failed") into what
|
|
29
|
+
* should be an operator's queue. They still count toward platform health.
|
|
30
|
+
*/
|
|
31
|
+
export declare const GENERIC_JOB_DEDUPE_PREFIXES: readonly ["job_failed:", "job_missed:", "job_never_succeeded:", "job_stuck_running:", "job_ledger_missing:"];
|
|
32
|
+
/**
|
|
33
|
+
* How old a watchdog heartbeat may be before the health pill stops trusting it.
|
|
34
|
+
*
|
|
35
|
+
* The development-preview reference uses a conservative six-hour stale window
|
|
36
|
+
* independent from any scheduler cadence. It is a policy default, not a
|
|
37
|
+
* scheduling SLA; adopters must review it against their expected maximum
|
|
38
|
+
* heartbeat delay and queue jitter.
|
|
39
|
+
*/
|
|
40
|
+
export declare const WATCHDOG_STALE_AFTER_SECONDS: number;
|
|
41
|
+
export declare function isGenericJobAlert(dedupeKey: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Display bucket. `commerce` means "a business operator can act on this".
|
|
44
|
+
*
|
|
45
|
+
* `commerce/platform` is deliberately excluded: despite the prefix it owns
|
|
46
|
+
* engineering-run plumbing (outbox-dispatch, outbox-prune, abandoned-cart,
|
|
47
|
+
* review-request, reorder-reminder).
|
|
48
|
+
*/
|
|
49
|
+
export declare function classifyLane(owner: string, dedupeKey: string): AdminAlertLane;
|
|
50
|
+
export declare function isSnoozed(snoozedUntil: string | null, now: Date): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Pageable means "this would wake someone up": live and above the paging floor.
|
|
53
|
+
* Acknowledged rows stay pageable on purpose — acknowledged is not resolved, the
|
|
54
|
+
* system is still broken.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isPageable(row: PlatformAlertLedgerRow, now: Date): boolean;
|
|
57
|
+
export declare function toAdminAlert(row: PlatformAlertLedgerRow, now: Date): AdminAlert;
|
|
58
|
+
export declare function worstSeverity(alerts: readonly AdminAlert[]): AdminAlertSeverity | null;
|
|
59
|
+
/**
|
|
60
|
+
* `commercePageableCount` and `platformPageableCount` partition the pageable set,
|
|
61
|
+
* so no alert that would page is ever invisible in the popover.
|
|
62
|
+
*/
|
|
63
|
+
export declare function summarizeAlerts(alerts: readonly AdminAlert[]): AdminAlertsSummary;
|
|
64
|
+
export declare function buildHeartbeat(row: WatchdogHeartbeatRow, now: Date): AdminAlertsHeartbeat;
|
|
65
|
+
/**
|
|
66
|
+
* Staleness beats severity: if the watchdog has not reported recently we do not
|
|
67
|
+
* know the current state, and "unknown" is the only honest answer. There is no
|
|
68
|
+
* path here that renders a green "systems ok" from missing data.
|
|
69
|
+
*/
|
|
70
|
+
export declare function deriveHealth(summary: AdminAlertsSummary, heartbeat: AdminAlertsHeartbeat): AdminAlertHealth;
|
|
71
|
+
/** Alerts returned to the client; counts above stay accurate even when this is truncated. */
|
|
72
|
+
export declare const ADMIN_ALERTS_LIST_LIMIT = 50;
|
|
73
|
+
export declare function buildAlertsOverview(rows: readonly PlatformAlertLedgerRow[], heartbeatRow: WatchdogHeartbeatRow, now: Date): AdminAlertsOverviewResponse;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { DEFAULT_PAGING_MIN_SEVERITY, shouldPage } from "./alertPagingPolicy.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generic scheduled-job alerts inherit `owner` from the job catalog entry, so a
|
|
4
|
+
* commerce-owned job leaks engineer-only noise ("this cron failed") into what
|
|
5
|
+
* should be an operator's queue. They still count toward platform health.
|
|
6
|
+
*/
|
|
7
|
+
export const GENERIC_JOB_DEDUPE_PREFIXES = [
|
|
8
|
+
"job_failed:",
|
|
9
|
+
"job_missed:",
|
|
10
|
+
"job_never_succeeded:",
|
|
11
|
+
"job_stuck_running:",
|
|
12
|
+
"job_ledger_missing:",
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* How old a watchdog heartbeat may be before the health pill stops trusting it.
|
|
16
|
+
*
|
|
17
|
+
* The development-preview reference uses a conservative six-hour stale window
|
|
18
|
+
* independent from any scheduler cadence. It is a policy default, not a
|
|
19
|
+
* scheduling SLA; adopters must review it against their expected maximum
|
|
20
|
+
* heartbeat delay and queue jitter.
|
|
21
|
+
*/
|
|
22
|
+
export const WATCHDOG_STALE_AFTER_SECONDS = 6 * 60 * 60;
|
|
23
|
+
const SEVERITY_RANK = { p0: 0, p1: 1, p2: 2, p3: 3 };
|
|
24
|
+
/**
|
|
25
|
+
* Derived from the paging policy's DEFAULT floor, not from the live threshold:
|
|
26
|
+
* this is a pure projection with no access to PLATFORM_ALERT_PAGING_MIN_SEVERITY,
|
|
27
|
+
* so an operator who overrides that variable makes panel and pager disagree
|
|
28
|
+
* again. Threading the parsed floor through the admin BFF is wave-3 work.
|
|
29
|
+
*/
|
|
30
|
+
function isPageableSeverity(severity) {
|
|
31
|
+
return shouldPage(severity, DEFAULT_PAGING_MIN_SEVERITY);
|
|
32
|
+
}
|
|
33
|
+
export function isGenericJobAlert(dedupeKey) {
|
|
34
|
+
return GENERIC_JOB_DEDUPE_PREFIXES.some((prefix) => dedupeKey.startsWith(prefix));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Display bucket. `commerce` means "a business operator can act on this".
|
|
38
|
+
*
|
|
39
|
+
* `commerce/platform` is deliberately excluded: despite the prefix it owns
|
|
40
|
+
* engineering-run plumbing (outbox-dispatch, outbox-prune, abandoned-cart,
|
|
41
|
+
* review-request, reorder-reminder).
|
|
42
|
+
*/
|
|
43
|
+
export function classifyLane(owner, dedupeKey) {
|
|
44
|
+
if (isGenericJobAlert(dedupeKey))
|
|
45
|
+
return "platform";
|
|
46
|
+
if (!owner.startsWith("commerce/"))
|
|
47
|
+
return "platform";
|
|
48
|
+
if (owner === "commerce/platform")
|
|
49
|
+
return "platform";
|
|
50
|
+
return "commerce";
|
|
51
|
+
}
|
|
52
|
+
export function isSnoozed(snoozedUntil, now) {
|
|
53
|
+
if (!snoozedUntil)
|
|
54
|
+
return false;
|
|
55
|
+
const until = Date.parse(snoozedUntil);
|
|
56
|
+
return Number.isFinite(until) && until > now.getTime();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Unknown severities are treated as p0 — mirrors alertPagingPolicy's fail-safe,
|
|
60
|
+
* where an unrecognised severity always pages rather than silently disappearing.
|
|
61
|
+
*/
|
|
62
|
+
function normalizeSeverity(severity) {
|
|
63
|
+
return severity in SEVERITY_RANK ? severity : "p0";
|
|
64
|
+
}
|
|
65
|
+
function normalizeIso(value) {
|
|
66
|
+
const parsed = Date.parse(value);
|
|
67
|
+
return Number.isFinite(parsed) ? new Date(parsed).toISOString() : value;
|
|
68
|
+
}
|
|
69
|
+
/** Unresolved ledger state, including a controlled snoozed exception. */
|
|
70
|
+
function isOpen(row) {
|
|
71
|
+
if (row.status !== "open" && row.status !== "acknowledged")
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/** Live enough to affect the health badge and paging. */
|
|
76
|
+
function isLive(row, now) {
|
|
77
|
+
return isOpen(row) && !isSnoozed(row.snoozed_until, now);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Pageable means "this would wake someone up": live and above the paging floor.
|
|
81
|
+
* Acknowledged rows stay pageable on purpose — acknowledged is not resolved, the
|
|
82
|
+
* system is still broken.
|
|
83
|
+
*/
|
|
84
|
+
export function isPageable(row, now) {
|
|
85
|
+
return isLive(row, now) && isPageableSeverity(normalizeSeverity(row.severity));
|
|
86
|
+
}
|
|
87
|
+
export function toAdminAlert(row, now) {
|
|
88
|
+
return {
|
|
89
|
+
id: row.id,
|
|
90
|
+
dedupeKey: row.dedupe_key,
|
|
91
|
+
lane: classifyLane(row.owner, row.dedupe_key),
|
|
92
|
+
owner: row.owner,
|
|
93
|
+
severity: normalizeSeverity(row.severity),
|
|
94
|
+
status: row.status === "acknowledged" ? "acknowledged" : "open",
|
|
95
|
+
pageable: isPageable(row, now),
|
|
96
|
+
title: row.title,
|
|
97
|
+
message: row.message ?? "",
|
|
98
|
+
supportCode: row.support_code,
|
|
99
|
+
runbookUrl: row.runbook_url,
|
|
100
|
+
firstSeenAt: normalizeIso(row.first_seen_at),
|
|
101
|
+
lastSeenAt: normalizeIso(row.last_seen_at),
|
|
102
|
+
snoozedUntil: row.snoozed_until ? normalizeIso(row.snoozed_until) : null,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function worstSeverity(alerts) {
|
|
106
|
+
let worst = null;
|
|
107
|
+
for (const alert of alerts) {
|
|
108
|
+
if (!worst || SEVERITY_RANK[alert.severity] < SEVERITY_RANK[worst])
|
|
109
|
+
worst = alert.severity;
|
|
110
|
+
}
|
|
111
|
+
return worst;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* `commercePageableCount` and `platformPageableCount` partition the pageable set,
|
|
115
|
+
* so no alert that would page is ever invisible in the popover.
|
|
116
|
+
*/
|
|
117
|
+
export function summarizeAlerts(alerts) {
|
|
118
|
+
const pageable = alerts.filter((alert) => alert.pageable);
|
|
119
|
+
return {
|
|
120
|
+
commercePageableCount: pageable.filter((alert) => alert.lane === "commerce").length,
|
|
121
|
+
commerceTotalCount: alerts.filter((alert) => alert.lane === "commerce").length,
|
|
122
|
+
platformPageableCount: pageable.filter((alert) => alert.lane === "platform").length,
|
|
123
|
+
snoozedCount: 0,
|
|
124
|
+
maxOpenSeverity: worstSeverity(alerts),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function buildHeartbeat(row, now) {
|
|
128
|
+
const lastSuccessAt = row?.last_success_at ?? null;
|
|
129
|
+
const parsed = lastSuccessAt ? Date.parse(lastSuccessAt) : Number.NaN;
|
|
130
|
+
const stale = !Number.isFinite(parsed) || now.getTime() - parsed > WATCHDOG_STALE_AFTER_SECONDS * 1000;
|
|
131
|
+
return {
|
|
132
|
+
lastSuccessAt: Number.isFinite(parsed) ? new Date(parsed).toISOString() : null,
|
|
133
|
+
staleAfterSeconds: WATCHDOG_STALE_AFTER_SECONDS,
|
|
134
|
+
stale,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Staleness beats severity: if the watchdog has not reported recently we do not
|
|
139
|
+
* know the current state, and "unknown" is the only honest answer. There is no
|
|
140
|
+
* path here that renders a green "systems ok" from missing data.
|
|
141
|
+
*/
|
|
142
|
+
export function deriveHealth(summary, heartbeat) {
|
|
143
|
+
if (heartbeat.stale)
|
|
144
|
+
return "unknown";
|
|
145
|
+
if (summary.maxOpenSeverity === "p0")
|
|
146
|
+
return "down";
|
|
147
|
+
if (summary.maxOpenSeverity === "p1")
|
|
148
|
+
return "degraded";
|
|
149
|
+
return "ok";
|
|
150
|
+
}
|
|
151
|
+
/** Alerts returned to the client; counts above stay accurate even when this is truncated. */
|
|
152
|
+
export const ADMIN_ALERTS_LIST_LIMIT = 50;
|
|
153
|
+
function compareForDisplay(a, b) {
|
|
154
|
+
const bySeverity = SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity];
|
|
155
|
+
if (bySeverity !== 0)
|
|
156
|
+
return bySeverity;
|
|
157
|
+
return Date.parse(b.lastSeenAt) - Date.parse(a.lastSeenAt);
|
|
158
|
+
}
|
|
159
|
+
export function buildAlertsOverview(rows, heartbeatRow, now) {
|
|
160
|
+
const openRows = rows.filter(isOpen);
|
|
161
|
+
const alerts = openRows
|
|
162
|
+
.filter((row) => isLive(row, now))
|
|
163
|
+
.map((row) => toAdminAlert(row, now))
|
|
164
|
+
.sort(compareForDisplay);
|
|
165
|
+
const snoozedAlerts = openRows
|
|
166
|
+
.filter((row) => isSnoozed(row.snoozed_until, now))
|
|
167
|
+
.map((row) => toAdminAlert(row, now))
|
|
168
|
+
.sort(compareForDisplay);
|
|
169
|
+
const summary = {
|
|
170
|
+
...summarizeAlerts(alerts),
|
|
171
|
+
snoozedCount: snoozedAlerts.length,
|
|
172
|
+
};
|
|
173
|
+
const heartbeat = buildHeartbeat(heartbeatRow, now);
|
|
174
|
+
return {
|
|
175
|
+
health: deriveHealth(summary, heartbeat),
|
|
176
|
+
summary,
|
|
177
|
+
heartbeat,
|
|
178
|
+
alerts: alerts.slice(0, ADMIN_ALERTS_LIST_LIMIT),
|
|
179
|
+
// Deliberately separate from the active list's limit: controlled exceptions
|
|
180
|
+
// are relevant audit context, but must not turn the health pill red.
|
|
181
|
+
snoozedAlerts,
|
|
182
|
+
generatedAt: now.toISOString(),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AlertSeverity } from "./contracts/observabilityContracts.js";
|
|
2
|
+
/** Alerts at or above this severity page by default; below it are ledger-only. */
|
|
3
|
+
export declare const DEFAULT_PAGING_MIN_SEVERITY: AlertSeverity;
|
|
4
|
+
/**
|
|
5
|
+
* Whether an alert of `severity` should page given the `minSeverity` threshold.
|
|
6
|
+
*
|
|
7
|
+
* Fail-safe: an unknown/unparseable severity always pages (treated as most
|
|
8
|
+
* urgent). Silence must never be the result of a classification error.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldPage(severity: string, minSeverity?: AlertSeverity): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Parse a paging threshold from configuration (e.g. an env var), falling back to
|
|
13
|
+
* {@link DEFAULT_PAGING_MIN_SEVERITY} for any missing or invalid value.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parsePagingMinSeverity(value: string | null | undefined): AlertSeverity;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const ALERT_SEVERITIES = ["p0", "p1", "p2", "p3"];
|
|
2
|
+
/**
|
|
3
|
+
* Paging policy for platform watchdog alerts.
|
|
4
|
+
*
|
|
5
|
+
* The alert ledger records every severity, but only sufficiently severe alerts
|
|
6
|
+
* should page an on-call channel (e.g. ntfy). Lower-severity alerts stay
|
|
7
|
+
* ledger-only so real incidents are not buried under routine noise.
|
|
8
|
+
*
|
|
9
|
+
* The tiering is settled: **p0 pages** (customers cannot buy, renewals cannot
|
|
10
|
+
* charge, the platform or database is down); **p1 is panel-urgent** and turns
|
|
11
|
+
* the admin health pill `degraded` without waking anyone; **p2/p3** are the
|
|
12
|
+
* panel list and the ledger. An unknown severity still pages: the fail-open
|
|
13
|
+
* rule is unchanged, because silence must never be the result of a
|
|
14
|
+
* classification error.
|
|
15
|
+
*
|
|
16
|
+
* Lower rank == more severe.
|
|
17
|
+
*/
|
|
18
|
+
const SEVERITY_RANK = { p0: 0, p1: 1, p2: 2, p3: 3 };
|
|
19
|
+
/** Alerts at or above this severity page by default; below it are ledger-only. */
|
|
20
|
+
export const DEFAULT_PAGING_MIN_SEVERITY = "p0";
|
|
21
|
+
/**
|
|
22
|
+
* Whether an alert of `severity` should page given the `minSeverity` threshold.
|
|
23
|
+
*
|
|
24
|
+
* Fail-safe: an unknown/unparseable severity always pages (treated as most
|
|
25
|
+
* urgent). Silence must never be the result of a classification error.
|
|
26
|
+
*/
|
|
27
|
+
export function shouldPage(severity, minSeverity = DEFAULT_PAGING_MIN_SEVERITY) {
|
|
28
|
+
const rank = SEVERITY_RANK[severity];
|
|
29
|
+
if (rank === undefined)
|
|
30
|
+
return true;
|
|
31
|
+
return rank <= SEVERITY_RANK[minSeverity];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse a paging threshold from configuration (e.g. an env var), falling back to
|
|
35
|
+
* {@link DEFAULT_PAGING_MIN_SEVERITY} for any missing or invalid value.
|
|
36
|
+
*/
|
|
37
|
+
export function parsePagingMinSeverity(value) {
|
|
38
|
+
const normalized = value?.trim().toLowerCase();
|
|
39
|
+
if (normalized && ALERT_SEVERITIES.includes(normalized)) {
|
|
40
|
+
return normalized;
|
|
41
|
+
}
|
|
42
|
+
return DEFAULT_PAGING_MIN_SEVERITY;
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-severity re-notification cadence for platform watchdog alerts.
|
|
3
|
+
*
|
|
4
|
+
* A firing alert re-pages at most once per this window (keyed off
|
|
5
|
+
* `last_notified_at`). Lower severities re-page less often so a persistent
|
|
6
|
+
* low-severity alert cannot flood the channel, while p0 stays loud.
|
|
7
|
+
*/
|
|
8
|
+
const THROTTLE_SECONDS_BY_SEVERITY = {
|
|
9
|
+
p0: 1 * 60 * 60, // 1h
|
|
10
|
+
p1: 4 * 60 * 60, // 4h
|
|
11
|
+
p2: 12 * 60 * 60, // 12h
|
|
12
|
+
p3: 24 * 60 * 60, // 24h
|
|
13
|
+
};
|
|
14
|
+
/** Fallback window for an unknown/unparseable severity. */
|
|
15
|
+
export const DEFAULT_THROTTLE_SECONDS = 60 * 60;
|
|
16
|
+
export function throttleSecondsForSeverity(severity) {
|
|
17
|
+
return THROTTLE_SECONDS_BY_SEVERITY[severity] ?? DEFAULT_THROTTLE_SECONDS;
|
|
18
|
+
}
|