@ceon-oy/monitor-sdk 1.0.14 → 1.0.15

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 CHANGED
@@ -43,11 +43,14 @@ interface MonitorClientConfig {
43
43
  auditPaths?: AuditPath[];
44
44
  /** Include devDependencies when tracking dependencies (default: false) */
45
45
  includeDevDependencies?: boolean;
46
+ /** Enable fetching latest versions from npm registry (default: true) */
47
+ versionCheckEnabled?: boolean;
46
48
  }
47
49
  interface TechnologyItem {
48
50
  name: string;
49
51
  version: string;
50
52
  type?: TechnologyType;
53
+ latestVersion?: string;
51
54
  }
52
55
  interface ErrorContext {
53
56
  severity?: Severity;
@@ -178,6 +181,7 @@ declare class MonitorClient {
178
181
  private lastScanTime;
179
182
  private lastKnownScanRequestedAt;
180
183
  private lastKnownTechScanRequestedAt;
184
+ private versionCheckEnabled;
181
185
  constructor(config: MonitorClientConfig);
182
186
  /**
183
187
  * Security: Validate and sanitize metadata to prevent oversized payloads
@@ -229,10 +233,24 @@ declare class MonitorClient {
229
233
  private startFlushTimer;
230
234
  private stopFlushTimer;
231
235
  syncDependencies(): Promise<void>;
236
+ /**
237
+ * Enrich technologies with latest version information from npm registry.
238
+ * Only runs if versionCheckEnabled is true.
239
+ */
240
+ private enrichWithLatestVersions;
232
241
  syncTechnologies(technologies: TechnologyItem[]): Promise<void>;
233
242
  private readPackageJson;
234
243
  private readPackageJsonFromPath;
235
244
  private shouldExclude;
245
+ /**
246
+ * Fetch the latest version of a package from npm registry.
247
+ * Returns null if the package cannot be found or the request fails.
248
+ */
249
+ private fetchLatestVersion;
250
+ /**
251
+ * Fetch latest versions for multiple packages in parallel with concurrency limit.
252
+ */
253
+ private fetchLatestVersions;
236
254
  private sendTechnologies;
237
255
  private sendTechnologiesWithEnvironment;
238
256
  /**
package/dist/index.d.ts CHANGED
@@ -43,11 +43,14 @@ interface MonitorClientConfig {
43
43
  auditPaths?: AuditPath[];
44
44
  /** Include devDependencies when tracking dependencies (default: false) */
45
45
  includeDevDependencies?: boolean;
46
+ /** Enable fetching latest versions from npm registry (default: true) */
47
+ versionCheckEnabled?: boolean;
46
48
  }
47
49
  interface TechnologyItem {
48
50
  name: string;
49
51
  version: string;
50
52
  type?: TechnologyType;
53
+ latestVersion?: string;
51
54
  }
52
55
  interface ErrorContext {
53
56
  severity?: Severity;
@@ -178,6 +181,7 @@ declare class MonitorClient {
178
181
  private lastScanTime;
179
182
  private lastKnownScanRequestedAt;
180
183
  private lastKnownTechScanRequestedAt;
184
+ private versionCheckEnabled;
181
185
  constructor(config: MonitorClientConfig);
182
186
  /**
183
187
  * Security: Validate and sanitize metadata to prevent oversized payloads
@@ -229,10 +233,24 @@ declare class MonitorClient {
229
233
  private startFlushTimer;
230
234
  private stopFlushTimer;
231
235
  syncDependencies(): Promise<void>;
236
+ /**
237
+ * Enrich technologies with latest version information from npm registry.
238
+ * Only runs if versionCheckEnabled is true.
239
+ */
240
+ private enrichWithLatestVersions;
232
241
  syncTechnologies(technologies: TechnologyItem[]): Promise<void>;
233
242
  private readPackageJson;
234
243
  private readPackageJsonFromPath;
235
244
  private shouldExclude;
245
+ /**
246
+ * Fetch the latest version of a package from npm registry.
247
+ * Returns null if the package cannot be found or the request fails.
248
+ */
249
+ private fetchLatestVersion;
250
+ /**
251
+ * Fetch latest versions for multiple packages in parallel with concurrency limit.
252
+ */
253
+ private fetchLatestVersions;
236
254
  private sendTechnologies;
237
255
  private sendTechnologiesWithEnvironment;
238
256
  /**
package/dist/index.js CHANGED
@@ -117,6 +117,7 @@ var MonitorClient = class {
117
117
  this.autoAudit = config.autoAudit || false;
118
118
  this.auditPaths = config.auditPaths;
119
119
  this.includeDevDependencies = config.includeDevDependencies ?? false;
120
+ this.versionCheckEnabled = config.versionCheckEnabled ?? true;
120
121
  this.startFlushTimer();
121
122
  if (this.trackDependencies) {
122
123
  this.syncDependencies().catch((err) => {
@@ -437,17 +438,40 @@ var MonitorClient = class {
437
438
  for (const source of this.dependencySources) {
438
439
  const technologies = await this.readPackageJsonFromPath(source.path);
439
440
  if (technologies.length === 0) continue;
440
- await this.sendTechnologiesWithEnvironment(technologies, source.environment);
441
+ const enrichedTechnologies = await this.enrichWithLatestVersions(technologies);
442
+ await this.sendTechnologiesWithEnvironment(enrichedTechnologies, source.environment);
441
443
  }
442
444
  } else {
443
445
  const technologies = await this.readPackageJson();
444
446
  if (technologies.length === 0) return;
445
- await this.sendTechnologies(technologies);
447
+ const enrichedTechnologies = await this.enrichWithLatestVersions(technologies);
448
+ await this.sendTechnologies(enrichedTechnologies);
446
449
  }
447
450
  } catch (err) {
448
451
  console.error("[MonitorClient] Failed to sync dependencies:", err);
449
452
  }
450
453
  }
454
+ /**
455
+ * Enrich technologies with latest version information from npm registry.
456
+ * Only runs if versionCheckEnabled is true.
457
+ */
458
+ async enrichWithLatestVersions(technologies) {
459
+ if (!this.versionCheckEnabled) {
460
+ return technologies;
461
+ }
462
+ try {
463
+ console.log(`[MonitorClient] Fetching latest versions for ${technologies.length} packages...`);
464
+ const packageNames = technologies.map((t) => t.name);
465
+ const latestVersions = await this.fetchLatestVersions(packageNames);
466
+ return technologies.map((tech) => ({
467
+ ...tech,
468
+ latestVersion: latestVersions.get(tech.name) || void 0
469
+ }));
470
+ } catch (err) {
471
+ console.warn("[MonitorClient] Failed to fetch latest versions, continuing without:", err instanceof Error ? err.message : String(err));
472
+ return technologies;
473
+ }
474
+ }
451
475
  async syncTechnologies(technologies) {
452
476
  await this.sendTechnologies(technologies);
453
477
  }
@@ -514,6 +538,44 @@ var MonitorClient = class {
514
538
  }
515
539
  return false;
516
540
  }
541
+ /**
542
+ * Fetch the latest version of a package from npm registry.
543
+ * Returns null if the package cannot be found or the request fails.
544
+ */
545
+ async fetchLatestVersion(packageName) {
546
+ try {
547
+ const encodedName = encodeURIComponent(packageName).replace("%40", "@");
548
+ const response = await fetch(`https://registry.npmjs.org/${encodedName}`, {
549
+ headers: { "Accept": "application/json" },
550
+ signal: AbortSignal.timeout(5e3)
551
+ });
552
+ if (!response.ok) return null;
553
+ const data = await response.json();
554
+ return data["dist-tags"]?.latest || null;
555
+ } catch {
556
+ return null;
557
+ }
558
+ }
559
+ /**
560
+ * Fetch latest versions for multiple packages in parallel with concurrency limit.
561
+ */
562
+ async fetchLatestVersions(packageNames) {
563
+ const results = /* @__PURE__ */ new Map();
564
+ const concurrencyLimit = 5;
565
+ for (let i = 0; i < packageNames.length; i += concurrencyLimit) {
566
+ const batch = packageNames.slice(i, i + concurrencyLimit);
567
+ const batchResults = await Promise.all(
568
+ batch.map(async (name) => ({
569
+ name,
570
+ version: await this.fetchLatestVersion(name)
571
+ }))
572
+ );
573
+ for (const { name, version } of batchResults) {
574
+ results.set(name, version);
575
+ }
576
+ }
577
+ return results;
578
+ }
517
579
  async sendTechnologies(technologies) {
518
580
  await this.sendTechnologiesWithEnvironment(technologies, this.environment);
519
581
  }
package/dist/index.mjs CHANGED
@@ -81,6 +81,7 @@ var MonitorClient = class {
81
81
  this.autoAudit = config.autoAudit || false;
82
82
  this.auditPaths = config.auditPaths;
83
83
  this.includeDevDependencies = config.includeDevDependencies ?? false;
84
+ this.versionCheckEnabled = config.versionCheckEnabled ?? true;
84
85
  this.startFlushTimer();
85
86
  if (this.trackDependencies) {
86
87
  this.syncDependencies().catch((err) => {
@@ -401,17 +402,40 @@ var MonitorClient = class {
401
402
  for (const source of this.dependencySources) {
402
403
  const technologies = await this.readPackageJsonFromPath(source.path);
403
404
  if (technologies.length === 0) continue;
404
- await this.sendTechnologiesWithEnvironment(technologies, source.environment);
405
+ const enrichedTechnologies = await this.enrichWithLatestVersions(technologies);
406
+ await this.sendTechnologiesWithEnvironment(enrichedTechnologies, source.environment);
405
407
  }
406
408
  } else {
407
409
  const technologies = await this.readPackageJson();
408
410
  if (technologies.length === 0) return;
409
- await this.sendTechnologies(technologies);
411
+ const enrichedTechnologies = await this.enrichWithLatestVersions(technologies);
412
+ await this.sendTechnologies(enrichedTechnologies);
410
413
  }
411
414
  } catch (err) {
412
415
  console.error("[MonitorClient] Failed to sync dependencies:", err);
413
416
  }
414
417
  }
418
+ /**
419
+ * Enrich technologies with latest version information from npm registry.
420
+ * Only runs if versionCheckEnabled is true.
421
+ */
422
+ async enrichWithLatestVersions(technologies) {
423
+ if (!this.versionCheckEnabled) {
424
+ return technologies;
425
+ }
426
+ try {
427
+ console.log(`[MonitorClient] Fetching latest versions for ${technologies.length} packages...`);
428
+ const packageNames = technologies.map((t) => t.name);
429
+ const latestVersions = await this.fetchLatestVersions(packageNames);
430
+ return technologies.map((tech) => ({
431
+ ...tech,
432
+ latestVersion: latestVersions.get(tech.name) || void 0
433
+ }));
434
+ } catch (err) {
435
+ console.warn("[MonitorClient] Failed to fetch latest versions, continuing without:", err instanceof Error ? err.message : String(err));
436
+ return technologies;
437
+ }
438
+ }
415
439
  async syncTechnologies(technologies) {
416
440
  await this.sendTechnologies(technologies);
417
441
  }
@@ -478,6 +502,44 @@ var MonitorClient = class {
478
502
  }
479
503
  return false;
480
504
  }
505
+ /**
506
+ * Fetch the latest version of a package from npm registry.
507
+ * Returns null if the package cannot be found or the request fails.
508
+ */
509
+ async fetchLatestVersion(packageName) {
510
+ try {
511
+ const encodedName = encodeURIComponent(packageName).replace("%40", "@");
512
+ const response = await fetch(`https://registry.npmjs.org/${encodedName}`, {
513
+ headers: { "Accept": "application/json" },
514
+ signal: AbortSignal.timeout(5e3)
515
+ });
516
+ if (!response.ok) return null;
517
+ const data = await response.json();
518
+ return data["dist-tags"]?.latest || null;
519
+ } catch {
520
+ return null;
521
+ }
522
+ }
523
+ /**
524
+ * Fetch latest versions for multiple packages in parallel with concurrency limit.
525
+ */
526
+ async fetchLatestVersions(packageNames) {
527
+ const results = /* @__PURE__ */ new Map();
528
+ const concurrencyLimit = 5;
529
+ for (let i = 0; i < packageNames.length; i += concurrencyLimit) {
530
+ const batch = packageNames.slice(i, i + concurrencyLimit);
531
+ const batchResults = await Promise.all(
532
+ batch.map(async (name) => ({
533
+ name,
534
+ version: await this.fetchLatestVersion(name)
535
+ }))
536
+ );
537
+ for (const { name, version } of batchResults) {
538
+ results.set(name, version);
539
+ }
540
+ }
541
+ return results;
542
+ }
481
543
  async sendTechnologies(technologies) {
482
544
  await this.sendTechnologiesWithEnvironment(technologies, this.environment);
483
545
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ceon-oy/monitor-sdk",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Client SDK for Ceon Monitor - Error tracking, health monitoring, security events, and vulnerability scanning",
5
5
  "author": "Ceon",
6
6
  "license": "MIT",