@a-company/sentinel 0.2.0 → 3.5.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.
@@ -0,0 +1,129 @@
1
+ import { l as CreateIncidentInput, a as SymbolicIncidentRecord, w as IncidentQueryOptions, v as IncidentNote, m as CreatePatternInput, e as FailurePattern, Z as PatternQueryOptions, k as CreateGroupInput, I as IncidentGroup, ab as ResolutionQueryOptions, ac as ResolutionRecord, b as SentinelStats, c as SymbolHealth, f as PatternExport, B as BackupExport, a5 as PracticeEventInput, a6 as PracticeEventQuery, a4 as PracticeEvent, y as LogEntryInput, G as LogQueryOptions, L as LogEntry, ag as ServiceRegistration, af as ServiceInfo, A as AppState, Q as MetricInput, R as MetricQueryOptions, O as MetricEntry, N as MetricAggregation, an as TraceSpanInput, ao as TraceView } from './types-BmVoO1iF.js';
2
+
3
+ /**
4
+ * Paradigm Sentinel - SQLite Storage Layer
5
+ *
6
+ * Persistent storage for incidents, patterns, groups, and resolutions.
7
+ * Uses sql.js for pure JavaScript SQLite (no native compilation needed).
8
+ */
9
+
10
+ declare class SentinelStorage {
11
+ private db;
12
+ private dbPath;
13
+ private incidentCounter;
14
+ private initialized;
15
+ constructor(dbPath?: string);
16
+ private getDefaultDbPath;
17
+ private createSchema;
18
+ private save;
19
+ recordIncident(input: CreateIncidentInput): string;
20
+ private initializeSync;
21
+ /**
22
+ * Run schema migrations from older versions
23
+ */
24
+ private migrateSchema;
25
+ /**
26
+ * Ensure the storage is ready for use. Must be called once before using storage methods.
27
+ */
28
+ ensureReady(): Promise<void>;
29
+ getIncident(id: string): SymbolicIncidentRecord | null;
30
+ getRecentIncidents(options?: IncidentQueryOptions): SymbolicIncidentRecord[];
31
+ updateIncident(id: string, updates: Partial<SymbolicIncidentRecord>): void;
32
+ addIncidentNote(incidentId: string, note: Omit<IncidentNote, 'id'>): void;
33
+ linkIncidents(incidentId: string, relatedId: string): void;
34
+ getIncidentCount(options?: IncidentQueryOptions): number;
35
+ addPattern(input: CreatePatternInput): string;
36
+ getPattern(id: string): FailurePattern | null;
37
+ getAllPatterns(options?: PatternQueryOptions): FailurePattern[];
38
+ updatePattern(id: string, updates: Partial<FailurePattern>): void;
39
+ deletePattern(id: string): void;
40
+ updatePatternConfidence(patternId: string, event: 'matched' | 'resolved' | 'recurred'): void;
41
+ createGroup(input: CreateGroupInput): string;
42
+ getGroup(id: string): IncidentGroup | null;
43
+ getGroups(options?: {
44
+ limit?: number;
45
+ }): IncidentGroup[];
46
+ addToGroup(groupId: string, incidentId: string): void;
47
+ recordResolution(resolution: {
48
+ incidentId: string;
49
+ patternId?: string;
50
+ commitHash?: string;
51
+ prUrl?: string;
52
+ notes?: string;
53
+ }): void;
54
+ markRecurred(incidentId: string): void;
55
+ getResolutionHistory(options?: ResolutionQueryOptions): ResolutionRecord[];
56
+ getStats(period: {
57
+ start: string;
58
+ end: string;
59
+ }): SentinelStats;
60
+ getSymbolHealth(symbol: string): SymbolHealth;
61
+ exportPatterns(options?: {
62
+ includePrivate?: boolean;
63
+ }): PatternExport;
64
+ importPatterns(data: PatternExport, options?: {
65
+ overwrite?: boolean;
66
+ }): {
67
+ imported: number;
68
+ skipped: number;
69
+ };
70
+ exportBackup(): BackupExport;
71
+ importBackup(data: BackupExport): void;
72
+ private rowToIncident;
73
+ private rowToPattern;
74
+ private rowToGroup;
75
+ recordPracticeEvent(input: PracticeEventInput): string;
76
+ getPracticeEvents(options?: PracticeEventQuery): PracticeEvent[];
77
+ getPracticeEventCount(options?: PracticeEventQuery): number;
78
+ getComplianceRate(options?: PracticeEventQuery): {
79
+ total: number;
80
+ followed: number;
81
+ skipped: number;
82
+ partial: number;
83
+ rate: number;
84
+ };
85
+ private rowToPracticeEvent;
86
+ private inferSymbolType;
87
+ insertLog(input: LogEntryInput): string;
88
+ insertLogBatch(entries: LogEntryInput[]): {
89
+ accepted: number;
90
+ errors: string[];
91
+ };
92
+ queryLogs(options?: LogQueryOptions): LogEntry[];
93
+ getLogCount(options?: LogQueryOptions): number;
94
+ pruneLogs(maxCount: number): number;
95
+ private rowToLogEntry;
96
+ registerService(reg: ServiceRegistration): void;
97
+ updateServiceLastSeen(name: string): void;
98
+ getServices(): ServiceInfo[];
99
+ upsertAppState(state: AppState): void;
100
+ getAppState(service: string, sessionId?: string): AppState[];
101
+ getAllAppStates(): AppState[];
102
+ private rowToAppState;
103
+ insertMetric(input: MetricInput): string;
104
+ insertMetricBatch(entries: MetricInput[]): {
105
+ accepted: number;
106
+ errors: string[];
107
+ };
108
+ queryMetrics(options?: MetricQueryOptions): MetricEntry[];
109
+ getMetricCount(options?: MetricQueryOptions): number;
110
+ aggregateMetric(name: string, options?: {
111
+ service?: string;
112
+ since?: string;
113
+ until?: string;
114
+ }): MetricAggregation;
115
+ pruneMetrics(maxCount: number): number;
116
+ private rowToMetricEntry;
117
+ insertSpan(input: TraceSpanInput): string;
118
+ getTrace(traceId: string): TraceView | null;
119
+ queryTraces(options?: {
120
+ service?: string;
121
+ symbol?: string;
122
+ since?: string;
123
+ limit?: number;
124
+ }): TraceView[];
125
+ private rowToTraceSpan;
126
+ close(): void;
127
+ }
128
+
129
+ export { SentinelStorage as S };
@@ -0,0 +1,185 @@
1
+ import { z as LogLevel, Q as MetricInput } from './types-BmVoO1iF.js';
2
+
3
+ /**
4
+ * Sentinel Client SDK
5
+ *
6
+ * Lightweight client for sending structured logs to the Sentinel server.
7
+ * Features batching, ring buffer, auto-retry, and graceful degradation.
8
+ *
9
+ * Usage:
10
+ * import { createSentinelClient } from '@a-company/sentinel';
11
+ * const client = createSentinelClient({ service: 'my-app' });
12
+ * client.info('#checkout', 'Order placed', { orderId: '123' });
13
+ * await client.close();
14
+ */
15
+
16
+ interface SentinelClientOptions {
17
+ /** Sentinel server URL (default: http://localhost:3838) */
18
+ url?: string;
19
+ /** Service name (required) */
20
+ service: string;
21
+ /** Service version */
22
+ version?: string;
23
+ /** Environment (development, staging, production) */
24
+ environment?: string;
25
+ /** Auth token for protected servers */
26
+ token?: string;
27
+ /** Batch size before auto-flush (default: 50) */
28
+ batchSize?: number;
29
+ /** Flush interval in ms (default: 5000) */
30
+ flushIntervalMs?: number;
31
+ /** Max entries in ring buffer before dropping oldest (default: 1000) */
32
+ maxBufferSize?: number;
33
+ /** Max retry attempts on network failure (default: 3) */
34
+ maxRetries?: number;
35
+ /** Retry backoff base in ms (default: 1000) */
36
+ retryBackoffMs?: number;
37
+ /** Callback when entries are dropped from buffer overflow */
38
+ onDrop?: (count: number) => void;
39
+ /** Callback on flush error */
40
+ onError?: (error: Error) => void;
41
+ }
42
+ interface SpanContext {
43
+ traceId: string;
44
+ spanId: string;
45
+ end: (status?: 'ok' | 'error') => Promise<void>;
46
+ }
47
+ declare class SentinelClient {
48
+ private readonly url;
49
+ private readonly service;
50
+ private readonly version;
51
+ private readonly environment;
52
+ private readonly token;
53
+ private readonly batchSize;
54
+ private readonly maxBufferSize;
55
+ private readonly maxRetries;
56
+ private readonly retryBackoffMs;
57
+ private readonly onDrop;
58
+ private readonly onError;
59
+ private readonly sessionId;
60
+ private logBuffer;
61
+ private metricsBuffer;
62
+ private flushTimer;
63
+ private closed;
64
+ private beforeUnloadHandler;
65
+ constructor(options: SentinelClientOptions);
66
+ /** Log a debug-level message */
67
+ debug(symbol: string, message: string, data?: Record<string, unknown>): void;
68
+ /** Log an info-level message */
69
+ info(symbol: string, message: string, data?: Record<string, unknown>): void;
70
+ /** Log a warn-level message */
71
+ warn(symbol: string, message: string, data?: Record<string, unknown>): void;
72
+ /** Log an error-level message */
73
+ error(symbol: string, message: string, data?: Record<string, unknown>): void;
74
+ /** Log a message at the specified level */
75
+ log(level: LogLevel, symbol: string, message: string, data?: Record<string, unknown>): void;
76
+ /** Record a counter metric (increments) */
77
+ counter(name: string, value?: number, tags?: Record<string, string>): void;
78
+ /** Record a gauge metric (current value) */
79
+ gauge(name: string, value: number, tags?: Record<string, string>): void;
80
+ /** Record a histogram metric (distribution) */
81
+ histogram(name: string, value: number, tags?: Record<string, string>): void;
82
+ /** Record a metric of any type */
83
+ metric(input: Omit<MetricInput, 'service'>): void;
84
+ /** Push an application state snapshot to the server */
85
+ pushState(state: Record<string, unknown>, activeFlows?: string[], activeGates?: string[]): Promise<void>;
86
+ /** Start a trace span. Call end() on the returned SpanContext when the operation completes. */
87
+ startSpan(symbol: string, operation: string, parentSpanId?: string): SpanContext;
88
+ /** Flush all buffered logs and metrics to the server */
89
+ flush(): Promise<void>;
90
+ /** Flush remaining entries and shut down the client */
91
+ close(): Promise<void>;
92
+ /** Get the session ID assigned to this client instance */
93
+ getSessionId(): string;
94
+ /**
95
+ * Synchronous best-effort flush using sendBeacon (browser) or sync XHR fallback.
96
+ * Used in beforeunload where async is unreliable.
97
+ */
98
+ private flushSync;
99
+ /** Register this service with the Sentinel server (fire-and-forget) */
100
+ private registerService;
101
+ /** Push a log entry into the ring buffer, enforcing maxBufferSize */
102
+ private pushToLogBuffer;
103
+ /** Push a metric entry into the ring buffer, enforcing maxBufferSize */
104
+ private pushToMetricsBuffer;
105
+ /** Drain and return all entries from the log buffer */
106
+ private drainLogBuffer;
107
+ /** Drain and return all entries from the metrics buffer */
108
+ private drainMetricsBuffer;
109
+ /** Send log entries to the server with retry */
110
+ private sendLogs;
111
+ /** Send metric entries to the server with retry */
112
+ private sendMetrics;
113
+ /**
114
+ * POST JSON to the Sentinel server with exponential backoff retry.
115
+ * Retries on network errors and 5xx responses. Does NOT retry on 4xx.
116
+ */
117
+ private post;
118
+ /** Get the fetch function, falling back to globalThis.fetch */
119
+ private getFetch;
120
+ /** Wait with exponential backoff */
121
+ private backoff;
122
+ /** Handle an error, calling the onError callback if provided */
123
+ private handleError;
124
+ }
125
+ /**
126
+ * Create a new SentinelClient instance.
127
+ *
128
+ * Usage:
129
+ * const client = createSentinelClient({ service: 'my-app', environment: 'production' });
130
+ * client.info('#checkout', 'Order placed', { orderId: '123' });
131
+ */
132
+ declare function createSentinelClient(options: SentinelClientOptions): SentinelClient;
133
+
134
+ /**
135
+ * SentinelTransport — Bridge between Paradigm Logger and Sentinel Client
136
+ *
137
+ * Uses structural typing to match LogTransport interface without
138
+ * importing from @a-company/paradigm-logger (avoids hard dependency).
139
+ *
140
+ * Usage:
141
+ * import { enableSentinel } from '@a-company/sentinel/transport';
142
+ * import { log } from '@a-company/paradigm-logger';
143
+ * enableSentinel(log, { service: 'my-app' });
144
+ */
145
+
146
+ /** Structurally matches LogTransport.send() entry shape */
147
+ interface LogEntry {
148
+ level: string;
149
+ symbol: string;
150
+ symbolType: string;
151
+ message: string;
152
+ data?: Record<string, unknown>;
153
+ correlationId?: string;
154
+ timestamp: string;
155
+ }
156
+ /** Structurally matches ParadigmLogger.addTransport() */
157
+ interface LoggerWithTransports {
158
+ addTransport(transport: {
159
+ send(entry: LogEntry): void;
160
+ }): void;
161
+ removeTransport(transport: {
162
+ send(entry: LogEntry): void;
163
+ }): void;
164
+ }
165
+ declare class SentinelTransport {
166
+ readonly client: SentinelClient;
167
+ constructor(client: SentinelClient);
168
+ send(entry: LogEntry): void;
169
+ }
170
+ /**
171
+ * Create a SentinelTransport from an existing client or options.
172
+ *
173
+ * const transport = createSentinelTransport(client);
174
+ * log.addTransport(transport);
175
+ */
176
+ declare function createSentinelTransport(clientOrOptions: SentinelClient | SentinelClientOptions): SentinelTransport;
177
+ /**
178
+ * One-line setup: creates a SentinelTransport and attaches it to a logger.
179
+ *
180
+ * import { log } from '@a-company/paradigm-logger';
181
+ * const transport = enableSentinel(log, { service: 'my-app' });
182
+ */
183
+ declare function enableSentinel(logger: LoggerWithTransports, clientOrOptions: SentinelClient | SentinelClientOptions): SentinelTransport;
184
+
185
+ export { SentinelClient as S, type SentinelClientOptions as a, SentinelTransport as b, type SpanContext as c, createSentinelClient as d, createSentinelTransport as e, enableSentinel as f };
@@ -0,0 +1,2 @@
1
+ export { b as SentinelTransport, e as createSentinelTransport, f as enableSentinel } from './transport-DqamniUy.js';
2
+ import './types-BmVoO1iF.js';
@@ -0,0 +1,10 @@
1
+ import {
2
+ SentinelTransport,
3
+ createSentinelTransport,
4
+ enableSentinel
5
+ } from "./chunk-VQ3SIN7S.js";
6
+ export {
7
+ SentinelTransport,
8
+ createSentinelTransport,
9
+ enableSentinel
10
+ };