@ceon-oy/monitor-sdk 1.5.3 → 1.5.7
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/index.d.mts +22 -12
- package/dist/index.d.ts +22 -12
- package/dist/index.js +46 -12
- package/dist/index.mjs +46 -12
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -189,6 +189,18 @@ interface SdkHealthResultsResponse {
|
|
|
189
189
|
total: number;
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
+
interface ProjectSettings {
|
|
193
|
+
name: string;
|
|
194
|
+
vulnerabilityScanIntervalHours: number;
|
|
195
|
+
scanRequestedAt: string | null;
|
|
196
|
+
techScanRequestedAt: string | null;
|
|
197
|
+
metricsEnabled?: boolean;
|
|
198
|
+
metricsIntervalSeconds?: number;
|
|
199
|
+
metricsDiskPaths?: string[];
|
|
200
|
+
metricsCpuThreshold?: number;
|
|
201
|
+
metricsRamThreshold?: number;
|
|
202
|
+
metricsDiskThreshold?: number;
|
|
203
|
+
}
|
|
192
204
|
|
|
193
205
|
declare class MonitorClient {
|
|
194
206
|
private apiKey;
|
|
@@ -291,18 +303,16 @@ declare class MonitorClient {
|
|
|
291
303
|
* Fetch project settings from the monitoring server.
|
|
292
304
|
* Returns configuration including vulnerability scan interval and scan request timestamps.
|
|
293
305
|
*/
|
|
294
|
-
fetchProjectSettings(): Promise<
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
metricsDiskThreshold?: number;
|
|
305
|
-
} | null>;
|
|
306
|
+
fetchProjectSettings(): Promise<ProjectSettings | null>;
|
|
307
|
+
/**
|
|
308
|
+
* Fetch project settings, retrying a couple of times on failure before giving up.
|
|
309
|
+
* A single transient failure here (a slow DNS lookup, a brief server hiccup at
|
|
310
|
+
* boot) used to permanently disable auto-audit for the process's entire
|
|
311
|
+
* lifetime, since this call only ever ran once at startup. Retrying a few
|
|
312
|
+
* seconds apart absorbs that kind of one-off blip instead of needing a full
|
|
313
|
+
* process restart to recover.
|
|
314
|
+
*/
|
|
315
|
+
private fetchProjectSettingsWithRetry;
|
|
306
316
|
/**
|
|
307
317
|
* Setup automatic vulnerability scanning based on server-configured interval.
|
|
308
318
|
* Fetches settings from server and sets up recurring scans.
|
package/dist/index.d.ts
CHANGED
|
@@ -189,6 +189,18 @@ interface SdkHealthResultsResponse {
|
|
|
189
189
|
total: number;
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
+
interface ProjectSettings {
|
|
193
|
+
name: string;
|
|
194
|
+
vulnerabilityScanIntervalHours: number;
|
|
195
|
+
scanRequestedAt: string | null;
|
|
196
|
+
techScanRequestedAt: string | null;
|
|
197
|
+
metricsEnabled?: boolean;
|
|
198
|
+
metricsIntervalSeconds?: number;
|
|
199
|
+
metricsDiskPaths?: string[];
|
|
200
|
+
metricsCpuThreshold?: number;
|
|
201
|
+
metricsRamThreshold?: number;
|
|
202
|
+
metricsDiskThreshold?: number;
|
|
203
|
+
}
|
|
192
204
|
|
|
193
205
|
declare class MonitorClient {
|
|
194
206
|
private apiKey;
|
|
@@ -291,18 +303,16 @@ declare class MonitorClient {
|
|
|
291
303
|
* Fetch project settings from the monitoring server.
|
|
292
304
|
* Returns configuration including vulnerability scan interval and scan request timestamps.
|
|
293
305
|
*/
|
|
294
|
-
fetchProjectSettings(): Promise<
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
metricsDiskThreshold?: number;
|
|
305
|
-
} | null>;
|
|
306
|
+
fetchProjectSettings(): Promise<ProjectSettings | null>;
|
|
307
|
+
/**
|
|
308
|
+
* Fetch project settings, retrying a couple of times on failure before giving up.
|
|
309
|
+
* A single transient failure here (a slow DNS lookup, a brief server hiccup at
|
|
310
|
+
* boot) used to permanently disable auto-audit for the process's entire
|
|
311
|
+
* lifetime, since this call only ever ran once at startup. Retrying a few
|
|
312
|
+
* seconds apart absorbs that kind of one-off blip instead of needing a full
|
|
313
|
+
* process restart to recover.
|
|
314
|
+
*/
|
|
315
|
+
private fetchProjectSettingsWithRetry;
|
|
306
316
|
/**
|
|
307
317
|
* Setup automatic vulnerability scanning based on server-configured interval.
|
|
308
318
|
* Fetches settings from server and sets up recurring scans.
|
package/dist/index.js
CHANGED
|
@@ -53,10 +53,15 @@ var CONFIG_LIMITS = {
|
|
|
53
53
|
// 10MB
|
|
54
54
|
AUDIT_TIMEOUT_MS: 6e4,
|
|
55
55
|
// 60 seconds (default)
|
|
56
|
-
MAX_AUDIT_TIMEOUT_MS:
|
|
57
|
-
//
|
|
56
|
+
MAX_AUDIT_TIMEOUT_MS: 18e5,
|
|
57
|
+
// 30 minutes (max configurable) - was 5 minutes, which every
|
|
58
|
+
// real npm audit run on Cloud Run (slow registry egress) exceeded, silently returning null
|
|
58
59
|
SETTINGS_POLL_INTERVAL_MS: 5 * 60 * 1e3,
|
|
59
60
|
// 5 minutes
|
|
61
|
+
SETUP_SETTINGS_MAX_ATTEMPTS: 3,
|
|
62
|
+
// retry a transient failure fetching settings at startup
|
|
63
|
+
SETUP_SETTINGS_RETRY_DELAY_MS: 5e3,
|
|
64
|
+
// before falling back to the periodic poll to self-heal
|
|
60
65
|
REGISTRY_TIMEOUT_MS: 5e3,
|
|
61
66
|
// 5 seconds (default)
|
|
62
67
|
MAX_REGISTRY_TIMEOUT_MS: 3e4,
|
|
@@ -489,15 +494,46 @@ var MonitorClient = class {
|
|
|
489
494
|
return null;
|
|
490
495
|
}
|
|
491
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Fetch project settings, retrying a couple of times on failure before giving up.
|
|
499
|
+
* A single transient failure here (a slow DNS lookup, a brief server hiccup at
|
|
500
|
+
* boot) used to permanently disable auto-audit for the process's entire
|
|
501
|
+
* lifetime, since this call only ever ran once at startup. Retrying a few
|
|
502
|
+
* seconds apart absorbs that kind of one-off blip instead of needing a full
|
|
503
|
+
* process restart to recover.
|
|
504
|
+
*/
|
|
505
|
+
async fetchProjectSettingsWithRetry() {
|
|
506
|
+
for (let attempt = 1; attempt <= CONFIG_LIMITS.SETUP_SETTINGS_MAX_ATTEMPTS; attempt++) {
|
|
507
|
+
const settings = await this.fetchProjectSettings();
|
|
508
|
+
if (settings) {
|
|
509
|
+
return settings;
|
|
510
|
+
}
|
|
511
|
+
if (attempt < CONFIG_LIMITS.SETUP_SETTINGS_MAX_ATTEMPTS) {
|
|
512
|
+
console.warn(
|
|
513
|
+
`[MonitorClient] Fetching project settings failed (attempt ${attempt}/${CONFIG_LIMITS.SETUP_SETTINGS_MAX_ATTEMPTS}), retrying...`
|
|
514
|
+
);
|
|
515
|
+
await new Promise((resolve) => setTimeout(resolve, CONFIG_LIMITS.SETUP_SETTINGS_RETRY_DELAY_MS));
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
492
520
|
/**
|
|
493
521
|
* Setup automatic vulnerability scanning based on server-configured interval.
|
|
494
522
|
* Fetches settings from server and sets up recurring scans.
|
|
495
523
|
* Also sets up polling for on-demand scan requests from the server.
|
|
496
524
|
*/
|
|
497
525
|
async setupAutoAudit() {
|
|
498
|
-
const settings = await this.
|
|
526
|
+
const settings = await this.fetchProjectSettingsWithRetry();
|
|
527
|
+
console.log("[MonitorClient] Polling for scan requests enabled (every 5 minutes)");
|
|
528
|
+
this.settingsPollingTimer = setInterval(() => {
|
|
529
|
+
this.checkForScanRequest().catch((err) => {
|
|
530
|
+
this.reportError("SETTINGS_POLL", "Scan request check failed", err);
|
|
531
|
+
});
|
|
532
|
+
}, CONFIG_LIMITS.SETTINGS_POLL_INTERVAL_MS);
|
|
499
533
|
if (!settings) {
|
|
500
|
-
|
|
534
|
+
const message = "Could not fetch project settings after retrying at startup; will keep retrying every 5 minutes";
|
|
535
|
+
console.warn(`[MonitorClient] ${message}`);
|
|
536
|
+
this.reportError("AUDIT_SETUP", message);
|
|
501
537
|
return;
|
|
502
538
|
}
|
|
503
539
|
if (settings.scanRequestedAt) {
|
|
@@ -515,12 +551,6 @@ var MonitorClient = class {
|
|
|
515
551
|
await this.runScanAndTrackTime();
|
|
516
552
|
this.setAuditInterval(intervalHours);
|
|
517
553
|
}
|
|
518
|
-
console.log("[MonitorClient] Polling for scan requests enabled (every 5 minutes)");
|
|
519
|
-
this.settingsPollingTimer = setInterval(() => {
|
|
520
|
-
this.checkForScanRequest().catch((err) => {
|
|
521
|
-
this.reportError("SETTINGS_POLL", "Scan request check failed", err);
|
|
522
|
-
});
|
|
523
|
-
}, CONFIG_LIMITS.SETTINGS_POLL_INTERVAL_MS);
|
|
524
554
|
}
|
|
525
555
|
/**
|
|
526
556
|
* (Re)configure the recurring audit timer for the given interval, replacing
|
|
@@ -1261,7 +1291,9 @@ var MonitorClient = class {
|
|
|
1261
1291
|
maxBuffer: CONFIG_LIMITS.AUDIT_MAX_BUFFER
|
|
1262
1292
|
});
|
|
1263
1293
|
if (result2.timedOut) {
|
|
1264
|
-
|
|
1294
|
+
const message = `yarn audit timed out after ${this.auditTimeoutMs}ms`;
|
|
1295
|
+
console.error(`[MonitorClient] ${message}`);
|
|
1296
|
+
this.reportError("VULNERABILITY_SCAN", message);
|
|
1265
1297
|
return null;
|
|
1266
1298
|
}
|
|
1267
1299
|
auditOutput = result2.stdout;
|
|
@@ -1294,7 +1326,9 @@ var MonitorClient = class {
|
|
|
1294
1326
|
maxBuffer: CONFIG_LIMITS.AUDIT_MAX_BUFFER
|
|
1295
1327
|
});
|
|
1296
1328
|
if (result2.timedOut) {
|
|
1297
|
-
|
|
1329
|
+
const message = `npm audit timed out after ${this.auditTimeoutMs}ms`;
|
|
1330
|
+
console.error(`[MonitorClient] ${message}`);
|
|
1331
|
+
this.reportError("VULNERABILITY_SCAN", message);
|
|
1298
1332
|
return null;
|
|
1299
1333
|
}
|
|
1300
1334
|
auditOutput = result2.stdout;
|
package/dist/index.mjs
CHANGED
|
@@ -17,10 +17,15 @@ var CONFIG_LIMITS = {
|
|
|
17
17
|
// 10MB
|
|
18
18
|
AUDIT_TIMEOUT_MS: 6e4,
|
|
19
19
|
// 60 seconds (default)
|
|
20
|
-
MAX_AUDIT_TIMEOUT_MS:
|
|
21
|
-
//
|
|
20
|
+
MAX_AUDIT_TIMEOUT_MS: 18e5,
|
|
21
|
+
// 30 minutes (max configurable) - was 5 minutes, which every
|
|
22
|
+
// real npm audit run on Cloud Run (slow registry egress) exceeded, silently returning null
|
|
22
23
|
SETTINGS_POLL_INTERVAL_MS: 5 * 60 * 1e3,
|
|
23
24
|
// 5 minutes
|
|
25
|
+
SETUP_SETTINGS_MAX_ATTEMPTS: 3,
|
|
26
|
+
// retry a transient failure fetching settings at startup
|
|
27
|
+
SETUP_SETTINGS_RETRY_DELAY_MS: 5e3,
|
|
28
|
+
// before falling back to the periodic poll to self-heal
|
|
24
29
|
REGISTRY_TIMEOUT_MS: 5e3,
|
|
25
30
|
// 5 seconds (default)
|
|
26
31
|
MAX_REGISTRY_TIMEOUT_MS: 3e4,
|
|
@@ -453,15 +458,46 @@ var MonitorClient = class {
|
|
|
453
458
|
return null;
|
|
454
459
|
}
|
|
455
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Fetch project settings, retrying a couple of times on failure before giving up.
|
|
463
|
+
* A single transient failure here (a slow DNS lookup, a brief server hiccup at
|
|
464
|
+
* boot) used to permanently disable auto-audit for the process's entire
|
|
465
|
+
* lifetime, since this call only ever ran once at startup. Retrying a few
|
|
466
|
+
* seconds apart absorbs that kind of one-off blip instead of needing a full
|
|
467
|
+
* process restart to recover.
|
|
468
|
+
*/
|
|
469
|
+
async fetchProjectSettingsWithRetry() {
|
|
470
|
+
for (let attempt = 1; attempt <= CONFIG_LIMITS.SETUP_SETTINGS_MAX_ATTEMPTS; attempt++) {
|
|
471
|
+
const settings = await this.fetchProjectSettings();
|
|
472
|
+
if (settings) {
|
|
473
|
+
return settings;
|
|
474
|
+
}
|
|
475
|
+
if (attempt < CONFIG_LIMITS.SETUP_SETTINGS_MAX_ATTEMPTS) {
|
|
476
|
+
console.warn(
|
|
477
|
+
`[MonitorClient] Fetching project settings failed (attempt ${attempt}/${CONFIG_LIMITS.SETUP_SETTINGS_MAX_ATTEMPTS}), retrying...`
|
|
478
|
+
);
|
|
479
|
+
await new Promise((resolve) => setTimeout(resolve, CONFIG_LIMITS.SETUP_SETTINGS_RETRY_DELAY_MS));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
456
484
|
/**
|
|
457
485
|
* Setup automatic vulnerability scanning based on server-configured interval.
|
|
458
486
|
* Fetches settings from server and sets up recurring scans.
|
|
459
487
|
* Also sets up polling for on-demand scan requests from the server.
|
|
460
488
|
*/
|
|
461
489
|
async setupAutoAudit() {
|
|
462
|
-
const settings = await this.
|
|
490
|
+
const settings = await this.fetchProjectSettingsWithRetry();
|
|
491
|
+
console.log("[MonitorClient] Polling for scan requests enabled (every 5 minutes)");
|
|
492
|
+
this.settingsPollingTimer = setInterval(() => {
|
|
493
|
+
this.checkForScanRequest().catch((err) => {
|
|
494
|
+
this.reportError("SETTINGS_POLL", "Scan request check failed", err);
|
|
495
|
+
});
|
|
496
|
+
}, CONFIG_LIMITS.SETTINGS_POLL_INTERVAL_MS);
|
|
463
497
|
if (!settings) {
|
|
464
|
-
|
|
498
|
+
const message = "Could not fetch project settings after retrying at startup; will keep retrying every 5 minutes";
|
|
499
|
+
console.warn(`[MonitorClient] ${message}`);
|
|
500
|
+
this.reportError("AUDIT_SETUP", message);
|
|
465
501
|
return;
|
|
466
502
|
}
|
|
467
503
|
if (settings.scanRequestedAt) {
|
|
@@ -479,12 +515,6 @@ var MonitorClient = class {
|
|
|
479
515
|
await this.runScanAndTrackTime();
|
|
480
516
|
this.setAuditInterval(intervalHours);
|
|
481
517
|
}
|
|
482
|
-
console.log("[MonitorClient] Polling for scan requests enabled (every 5 minutes)");
|
|
483
|
-
this.settingsPollingTimer = setInterval(() => {
|
|
484
|
-
this.checkForScanRequest().catch((err) => {
|
|
485
|
-
this.reportError("SETTINGS_POLL", "Scan request check failed", err);
|
|
486
|
-
});
|
|
487
|
-
}, CONFIG_LIMITS.SETTINGS_POLL_INTERVAL_MS);
|
|
488
518
|
}
|
|
489
519
|
/**
|
|
490
520
|
* (Re)configure the recurring audit timer for the given interval, replacing
|
|
@@ -1225,7 +1255,9 @@ var MonitorClient = class {
|
|
|
1225
1255
|
maxBuffer: CONFIG_LIMITS.AUDIT_MAX_BUFFER
|
|
1226
1256
|
});
|
|
1227
1257
|
if (result2.timedOut) {
|
|
1228
|
-
|
|
1258
|
+
const message = `yarn audit timed out after ${this.auditTimeoutMs}ms`;
|
|
1259
|
+
console.error(`[MonitorClient] ${message}`);
|
|
1260
|
+
this.reportError("VULNERABILITY_SCAN", message);
|
|
1229
1261
|
return null;
|
|
1230
1262
|
}
|
|
1231
1263
|
auditOutput = result2.stdout;
|
|
@@ -1258,7 +1290,9 @@ var MonitorClient = class {
|
|
|
1258
1290
|
maxBuffer: CONFIG_LIMITS.AUDIT_MAX_BUFFER
|
|
1259
1291
|
});
|
|
1260
1292
|
if (result2.timedOut) {
|
|
1261
|
-
|
|
1293
|
+
const message = `npm audit timed out after ${this.auditTimeoutMs}ms`;
|
|
1294
|
+
console.error(`[MonitorClient] ${message}`);
|
|
1295
|
+
this.reportError("VULNERABILITY_SCAN", message);
|
|
1262
1296
|
return null;
|
|
1263
1297
|
}
|
|
1264
1298
|
auditOutput = result2.stdout;
|
package/package.json
CHANGED