@runtimescope/collector 0.9.2 → 0.9.3

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.ts CHANGED
@@ -984,6 +984,8 @@ declare class EventStore {
984
984
  getAllEvents(sinceSeconds?: number, sessionId?: string, projectId?: string): RuntimeEvent[];
985
985
  getSessionIdsForProject(appName: string): string[];
986
986
  getSessionIdsForProjectId(projectId: string): string[];
987
+ /** Re-tag all sessions with oldProjectId to use newProjectId. */
988
+ retagSessions(oldProjectId: string, newProjectId: string): void;
987
989
  /** Check if an event belongs to the given projectId (via its session). */
988
990
  private matchesProjectId;
989
991
  getStateEvents(filter?: StateFilter): StateEvent[];
@@ -1094,8 +1096,17 @@ interface InfrastructureConfig {
1094
1096
  }>;
1095
1097
  services?: Record<string, string>;
1096
1098
  }
1099
+ /** Minimal interface for PmStore used by rebuildAppIndex (avoids circular deps). */
1100
+ interface PmStoreIndexSource {
1101
+ listProjects(): Array<{
1102
+ runtimeApps?: string[];
1103
+ runtimeProjectId?: string;
1104
+ path?: string;
1105
+ }>;
1106
+ }
1097
1107
  declare class ProjectManager {
1098
1108
  private readonly baseDir;
1109
+ private appProjectIndex;
1099
1110
  constructor(baseDir?: string);
1100
1111
  get rootDir(): string;
1101
1112
  getProjectDir(projectName: string): string;
@@ -1116,6 +1127,14 @@ declare class ProjectManager {
1116
1127
  setProjectIdForApp(appName: string, projectId: string): void;
1117
1128
  /** Resolve a projectId to an appName by scanning all project configs. Returns null if not found. */
1118
1129
  getAppForProjectId(projectId: string): string | null;
1130
+ /**
1131
+ * Build reverse index: appName -> projectId.
1132
+ * Scans all project configs, PM projects with runtimeApps + runtimeProjectId,
1133
+ * and project-level .runtimescope/config.json files from PM project paths.
1134
+ */
1135
+ rebuildAppIndex(pmStore?: PmStoreIndexSource): void;
1136
+ /** O(1) lookup from the cached index. */
1137
+ resolveAppProjectId(appName: string): string | null;
1119
1138
  resolveEnvVars(value: string): string;
1120
1139
  private mkdirp;
1121
1140
  private readJson;
@@ -1129,6 +1148,21 @@ declare class ProjectManager {
1129
1148
  private parseSimpleYaml;
1130
1149
  }
1131
1150
 
1151
+ /** Minimal interface for PmStore to avoid circular dependencies. */
1152
+ interface PmStoreLike {
1153
+ findProjectIdByApp(appName: string): string | null;
1154
+ }
1155
+ /** Generate a new project ID (proj_ + 12 random alphanumeric chars). */
1156
+ declare function generateProjectId(): string;
1157
+ /** Validate that a string is a well-formed project ID. */
1158
+ declare function isValidProjectId(id: string): boolean;
1159
+ /**
1160
+ * Look up or create a project ID for a given appName.
1161
+ * Persists the ID in the ProjectManager config so the same appName
1162
+ * always returns the same project ID (idempotent).
1163
+ */
1164
+ declare function getOrCreateProjectId(projectManager: ProjectManager, appName: string): string;
1165
+
1132
1166
  interface RateLimitConfig {
1133
1167
  maxEventsPerSecond?: number;
1134
1168
  maxEventsPerMinute?: number;
@@ -1192,6 +1226,7 @@ declare class CollectorServer {
1192
1226
  private pruneTimer;
1193
1227
  private heartbeatTimer;
1194
1228
  private tlsConfig;
1229
+ private pmStore;
1195
1230
  constructor(options?: CollectorServerOptions);
1196
1231
  getStore(): EventStore;
1197
1232
  getPort(): number | null;
@@ -1200,6 +1235,8 @@ declare class CollectorServer {
1200
1235
  getSqliteStore(projectName: string): SqliteStore | undefined;
1201
1236
  getSqliteStores(): Map<string, SqliteStore>;
1202
1237
  getRateLimiter(): SessionRateLimiter;
1238
+ /** Set the PmStore for project ID resolution (called after construction when PmStore is available). */
1239
+ setPmStore(pmStore: PmStoreLike | null): void;
1203
1240
  onConnect(cb: (sessionId: string, projectName: string, projectId?: string) => void): void;
1204
1241
  onDisconnect(cb: (sessionId: string, projectName: string, projectId?: string) => void): void;
1205
1242
  start(options?: CollectorServerOptions): Promise<void>;
@@ -1258,20 +1295,11 @@ declare class RingBuffer<T> {
1258
1295
  */
1259
1296
  declare function detectIssues(events: RuntimeEvent[]): DetectedIssue[];
1260
1297
 
1261
- /** Generate a new project ID (proj_ + 12 random alphanumeric chars). */
1262
- declare function generateProjectId(): string;
1263
- /** Validate that a string is a well-formed project ID. */
1264
- declare function isValidProjectId(id: string): boolean;
1265
- /**
1266
- * Look up or create a project ID for a given appName.
1267
- * Persists the ID in the ProjectManager config so the same appName
1268
- * always returns the same project ID (idempotent).
1269
- */
1270
- declare function getOrCreateProjectId(projectManager: ProjectManager, appName: string): string;
1271
-
1272
1298
  interface RuntimeScopeProjectConfig {
1273
1299
  /** Stable project identifier (proj_xxx). Groups all SDKs for this project. */
1274
1300
  projectId: string;
1301
+ /** DSN connection string: runtimescope://<projectId>@<host>:<port>/<appName> */
1302
+ dsn?: string;
1275
1303
  /** Human-readable project name. */
1276
1304
  appName: string;
1277
1305
  /** Optional description for dashboard/reports. */
@@ -1343,6 +1371,26 @@ declare function scaffoldProjectConfig(projectDir: string, opts: {
1343
1371
  * Returns the main appName plus any SDK-specific appNames.
1344
1372
  */
1345
1373
  declare function resolveProjectAppNames(config: RuntimeScopeProjectConfig): string[];
1374
+ interface MigratablePmStore {
1375
+ listProjects(): Array<{
1376
+ id: string;
1377
+ name: string;
1378
+ path?: string;
1379
+ runtimeApps?: string[];
1380
+ runtimeProjectId?: string;
1381
+ }>;
1382
+ updateProject(id: string, updates: Record<string, unknown>): void;
1383
+ }
1384
+ interface MigrationResult {
1385
+ unified: number;
1386
+ skipped: number;
1387
+ details: string[];
1388
+ }
1389
+ /**
1390
+ * Scan PM projects with multiple runtimeApps and ensure all their
1391
+ * appNames share the same canonical projectId (from .runtimescope/config.json).
1392
+ */
1393
+ declare function migrateProjectIds(projectManager: ProjectManager, pmStore?: MigratablePmStore | null): MigrationResult;
1346
1394
 
1347
1395
  declare function isSqliteAvailable(): boolean;
1348
1396
 
@@ -1693,6 +1741,8 @@ declare class PmStore {
1693
1741
  * Returns the project ID if linked, null if no match found.
1694
1742
  */
1695
1743
  autoLinkApp(appName: string, projectId?: string): string | null;
1744
+ /** Find a project's runtimeProjectId by checking if appName appears in any project's runtimeApps. */
1745
+ findProjectIdByApp(appName: string): string | null;
1696
1746
  listCategories(): string[];
1697
1747
  private mapProjectRow;
1698
1748
  createTask(task: PmTask): PmTask;
@@ -1754,6 +1804,14 @@ declare class PmStore {
1754
1804
  category?: string;
1755
1805
  }): Promise<Buffer>;
1756
1806
  private mapCapexRow;
1807
+ deleteProject(id: string): void;
1808
+ isDeletedPath(path: string): boolean;
1809
+ recoverProject(path: string): void;
1810
+ listDeletedProjects(): Array<{
1811
+ path: string;
1812
+ name: string;
1813
+ deletedAt: number;
1814
+ }>;
1757
1815
  close(): void;
1758
1816
  }
1759
1817
  interface ProjectSummaryRow {
@@ -1929,4 +1987,4 @@ declare function parseProcessList(): ProcessInfo[];
1929
1987
  /** Get RSS memory in MB for a given PID. Cross-platform. */
1930
1988
  declare function getProcessMemoryMB(pid: number): number;
1931
1989
 
1932
- export { type ApiChangeRecord, type ApiContract, type ApiContractField, ApiDiscoveryEngine, type ApiEndpoint, type ApiEndpointHealth, type ApiKeyEntry, type AuthConfig, type AuthInfo, AuthManager, BUILT_IN_RULES, type BackgroundSpriteSheet, type BaseEvent, type BuildMeta, type BuildStatus, type CSSArchitecture, type CSSCustomProperty, type CapexClassification, type CapexSummary, type CaptureConfig, CollectorServer, type CollectorServerOptions, type ColorToken, type CommandResponse, type ComputedStyleEntry, ConnectionManager, type ConsoleEvent, type ConsoleFilter, type ConsoleLevel, type CustomEvent, type CustomEventFilter, DataBrowser, type DatabaseConnectionConfig, type DatabaseEvent, type DatabaseFilter, type DatabaseOperation, type DatabaseSchema, type DatabaseSource, type DeployLog, type DetectedBuildTool, type DetectedFramework, type DetectedHosting, type DetectedIssue, type DetectedMetaFramework, type DetectedUILibrary, type DevProcess, type DevProcessType, type DomSnapshotEvent, type ElementSnapshotNode, type EventBatchPayload, EventStore, type EventType, type FontFaceInfo, type FontUsage, type FormFieldInfo, type GitCommit, type GitFileChange, type GitFileStatus, type GitStatus, type GlobalConfig, type GraphQLOperation, type HandshakePayload, type HeadingInfo, type HistoricalFilter, HttpServer, type HttpServerOptions, type IconFontInfo, type ImageAsset, type IndexSuggestion, InfraConnector, type InfraOverview, type InfrastructureConfig, type InlineSVGAsset, type InteractiveElementInfo, type IssueSeverity, type LandmarkInfo, type LayoutNode, type ManagedConnection, type MaskSpriteSheet, type MemoryFile, type MetricDelta, type NavigationEvent, type NetworkEvent, type NetworkFilter, type NormalizedQueryStats, type PerformanceEvent, type PerformanceFilter, type PerformanceMetricName, type PmCapexEntry, type PmNote, type PmProject, type PmSession, PmStore, type PmTask, type PortUsage, type ProcessInfo, ProcessMonitor, type ProjectConfig, ProjectDiscovery, ProjectManager, type ProjectPhase, type ProjectStatus, type RateLimitConfig, type ReadOptions, type ReadResult, type ReconAccessibilityEvent, type ReconAssetInventoryEvent, type ReconComputedStylesEvent, type ReconDesignTokensEvent, type ReconElementSnapshotEvent, type ReconEventType, type ReconFilter, type ReconFontsEvent, type ReconLayoutTreeEvent, type ReconMetadataEvent, type RedactionRule, Redactor, type RedactorConfig, type RenderComponentProfile, type RenderEvent, type RenderFilter, RingBuffer, type RulesFiles, type RuntimeEvent, type RuntimeLog, type RuntimeScopeProjectConfig, type SVGSpriteSymbol, type SchemaColumn, type SchemaForeignKey, type SchemaIndex, SchemaIntrospector, type SchemaTable, type SdkEntry, type ServerCommand, type ServerMetricName, type ServiceInfo, type SessionDiffResult, type SessionEvent, type SessionInfo, type SessionInfoExtended, SessionManager, type SessionMetrics, SessionRateLimiter, type SessionSnapshot, type SessionStats, type SpacingValue, type SpriteFrame, SqliteStore, type SqliteStoreOptions, type StateEvent, type StateFilter, type TaskPriority, type TaskSource, type TaskStatus, type TechStackDetection, type TimelineFilter, type TlsConfig, type ToolResponse, type TypographyToken, type UIInteractionAction, type UIInteractionEvent, type UIInteractionFilter, type UserContext, type WSMessage, type WebVitalRating, type WorkType, type WriteOptions, type WriteResult, aggregateQueryStats, calculateActiveMinutes, calculateCostMicrodollars, compareSessions, detectIssues, detectN1Queries, detectOverfetching, detectSlowQueries, findPidsInDirectory, generateApiKey, generateProjectId, getListenPorts, getOrCreateProjectId, getPidsOnPort, getProcessCwd, getProcessMemoryMB, isSqliteAvailable, isValidProjectId, loadTlsOptions, parseProcessList, parseSessionJsonl, readProjectConfig, resolveProjectAppNames, resolveTlsConfig, scaffoldProjectConfig, suggestIndexes, writeProjectConfig };
1990
+ export { type ApiChangeRecord, type ApiContract, type ApiContractField, ApiDiscoveryEngine, type ApiEndpoint, type ApiEndpointHealth, type ApiKeyEntry, type AuthConfig, type AuthInfo, AuthManager, BUILT_IN_RULES, type BackgroundSpriteSheet, type BaseEvent, type BuildMeta, type BuildStatus, type CSSArchitecture, type CSSCustomProperty, type CapexClassification, type CapexSummary, type CaptureConfig, CollectorServer, type CollectorServerOptions, type ColorToken, type CommandResponse, type ComputedStyleEntry, ConnectionManager, type ConsoleEvent, type ConsoleFilter, type ConsoleLevel, type CustomEvent, type CustomEventFilter, DataBrowser, type DatabaseConnectionConfig, type DatabaseEvent, type DatabaseFilter, type DatabaseOperation, type DatabaseSchema, type DatabaseSource, type DeployLog, type DetectedBuildTool, type DetectedFramework, type DetectedHosting, type DetectedIssue, type DetectedMetaFramework, type DetectedUILibrary, type DevProcess, type DevProcessType, type DomSnapshotEvent, type ElementSnapshotNode, type EventBatchPayload, EventStore, type EventType, type FontFaceInfo, type FontUsage, type FormFieldInfo, type GitCommit, type GitFileChange, type GitFileStatus, type GitStatus, type GlobalConfig, type GraphQLOperation, type HandshakePayload, type HeadingInfo, type HistoricalFilter, HttpServer, type HttpServerOptions, type IconFontInfo, type ImageAsset, type IndexSuggestion, InfraConnector, type InfraOverview, type InfrastructureConfig, type InlineSVGAsset, type InteractiveElementInfo, type IssueSeverity, type LandmarkInfo, type LayoutNode, type ManagedConnection, type MaskSpriteSheet, type MemoryFile, type MetricDelta, type NavigationEvent, type NetworkEvent, type NetworkFilter, type NormalizedQueryStats, type PerformanceEvent, type PerformanceFilter, type PerformanceMetricName, type PmCapexEntry, type PmNote, type PmProject, type PmSession, PmStore, type PmStoreIndexSource, type PmTask, type PortUsage, type ProcessInfo, ProcessMonitor, type ProjectConfig, ProjectDiscovery, ProjectManager, type ProjectPhase, type ProjectStatus, type RateLimitConfig, type ReadOptions, type ReadResult, type ReconAccessibilityEvent, type ReconAssetInventoryEvent, type ReconComputedStylesEvent, type ReconDesignTokensEvent, type ReconElementSnapshotEvent, type ReconEventType, type ReconFilter, type ReconFontsEvent, type ReconLayoutTreeEvent, type ReconMetadataEvent, type RedactionRule, Redactor, type RedactorConfig, type RenderComponentProfile, type RenderEvent, type RenderFilter, RingBuffer, type RulesFiles, type RuntimeEvent, type RuntimeLog, type RuntimeScopeProjectConfig, type SVGSpriteSymbol, type SchemaColumn, type SchemaForeignKey, type SchemaIndex, SchemaIntrospector, type SchemaTable, type SdkEntry, type ServerCommand, type ServerMetricName, type ServiceInfo, type SessionDiffResult, type SessionEvent, type SessionInfo, type SessionInfoExtended, SessionManager, type SessionMetrics, SessionRateLimiter, type SessionSnapshot, type SessionStats, type SpacingValue, type SpriteFrame, SqliteStore, type SqliteStoreOptions, type StateEvent, type StateFilter, type TaskPriority, type TaskSource, type TaskStatus, type TechStackDetection, type TimelineFilter, type TlsConfig, type ToolResponse, type TypographyToken, type UIInteractionAction, type UIInteractionEvent, type UIInteractionFilter, type UserContext, type WSMessage, type WebVitalRating, type WorkType, type WriteOptions, type WriteResult, aggregateQueryStats, calculateActiveMinutes, calculateCostMicrodollars, compareSessions, detectIssues, detectN1Queries, detectOverfetching, detectSlowQueries, findPidsInDirectory, generateApiKey, generateProjectId, getListenPorts, getOrCreateProjectId, getPidsOnPort, getProcessCwd, getProcessMemoryMB, isSqliteAvailable, isValidProjectId, loadTlsOptions, migrateProjectIds, parseProcessList, parseSessionJsonl, readProjectConfig, resolveProjectAppNames, resolveTlsConfig, scaffoldProjectConfig, suggestIndexes, writeProjectConfig };
package/dist/index.js CHANGED
@@ -25,10 +25,15 @@ import {
25
25
  isSqliteAvailable,
26
26
  isValidProjectId,
27
27
  loadTlsOptions,
28
+ migrateProjectIds,
28
29
  parseProcessList,
29
30
  parseSessionJsonl,
30
- resolveTlsConfig
31
- } from "./chunk-GENCCHYK.js";
31
+ readProjectConfig,
32
+ resolveProjectAppNames,
33
+ resolveTlsConfig,
34
+ scaffoldProjectConfig,
35
+ writeProjectConfig
36
+ } from "./chunk-MM44DN7Y.js";
32
37
  import {
33
38
  __require
34
39
  } from "./chunk-UP2VWCW5.js";
@@ -334,76 +339,6 @@ function detectPoorWebVitals(events) {
334
339
  return issues;
335
340
  }
336
341
 
337
- // src/project-config.ts
338
- import { readFileSync, existsSync, writeFileSync, mkdirSync } from "fs";
339
- import { join } from "path";
340
- var DEFAULT_CAPTURE = {
341
- network: true,
342
- console: true,
343
- xhr: true,
344
- body: false,
345
- performance: true,
346
- renders: true,
347
- navigation: true,
348
- clicks: false,
349
- http: false,
350
- errors: true,
351
- stackTraces: false
352
- };
353
- function readProjectConfig(projectDir) {
354
- const configPath = join(projectDir, ".runtimescope", "config.json");
355
- if (!existsSync(configPath)) return null;
356
- try {
357
- const content = readFileSync(configPath, "utf-8");
358
- return JSON.parse(content);
359
- } catch {
360
- return null;
361
- }
362
- }
363
- function writeProjectConfig(projectDir, config) {
364
- const dir = join(projectDir, ".runtimescope");
365
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
366
- writeFileSync(join(dir, "config.json"), JSON.stringify(config, null, 2) + "\n", "utf-8");
367
- }
368
- function scaffoldProjectConfig(projectDir, opts) {
369
- const existing = readProjectConfig(projectDir);
370
- if (existing) {
371
- if (opts.sdkType) {
372
- const alreadyHas = existing.sdks.some((s) => s.type === opts.sdkType);
373
- if (!alreadyHas) {
374
- existing.sdks.push({
375
- type: opts.sdkType,
376
- framework: opts.framework,
377
- appName: opts.appName !== existing.appName ? opts.appName : void 0
378
- });
379
- writeProjectConfig(projectDir, existing);
380
- }
381
- }
382
- return existing;
383
- }
384
- const config = {
385
- projectId: generateProjectId(),
386
- appName: opts.appName,
387
- description: opts.description,
388
- sdks: opts.sdkType ? [{ type: opts.sdkType, framework: opts.framework }] : [],
389
- capture: { ...DEFAULT_CAPTURE },
390
- category: opts.category
391
- };
392
- writeProjectConfig(projectDir, config);
393
- const gitignorePath = join(projectDir, ".runtimescope", ".gitignore");
394
- if (!existsSync(gitignorePath)) {
395
- writeFileSync(gitignorePath, "# Keep config.json committed, ignore local state\n*.log\n*.db\n.env\n", "utf-8");
396
- }
397
- return config;
398
- }
399
- function resolveProjectAppNames(config) {
400
- const names = /* @__PURE__ */ new Set([config.appName]);
401
- for (const sdk of config.sdks) {
402
- if (sdk.appName) names.add(sdk.appName);
403
- }
404
- return Array.from(names);
405
- }
406
-
407
342
  // src/engines/api-discovery.ts
408
343
  var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
409
344
  var NUMERIC_RE = /^\d+$/;
@@ -2134,6 +2069,7 @@ export {
2134
2069
  isSqliteAvailable,
2135
2070
  isValidProjectId,
2136
2071
  loadTlsOptions,
2072
+ migrateProjectIds,
2137
2073
  parseProcessList,
2138
2074
  parseSessionJsonl,
2139
2075
  readProjectConfig,