devlogs-node 2.2.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.
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Build info helper for devlogs node client.
3
+ *
4
+ * Provides a stable build identifier that applications can use to tag
5
+ * every log entry without requiring git at runtime.
6
+ */
7
+ /**
8
+ * Source of the build info.
9
+ */
10
+ export type BuildInfoSource = 'file' | 'env' | 'generated';
11
+ /**
12
+ * Build information resolved from file, environment, or generated.
13
+ */
14
+ export interface BuildInfo {
15
+ /** Unique build identifier (always non-empty). */
16
+ buildId: string;
17
+ /** Git branch name, if available. */
18
+ branch: string | null;
19
+ /** UTC timestamp in format YYYYMMDDTHHMMSSZ. */
20
+ timestampUtc: string;
21
+ /** Source of the build info. */
22
+ source: BuildInfoSource;
23
+ /** File path used for build info, if any. */
24
+ path: string | null;
25
+ }
26
+ /**
27
+ * Build info file format (JSON).
28
+ */
29
+ export interface BuildInfoFile {
30
+ build_id?: string;
31
+ branch?: string;
32
+ timestamp_utc?: string;
33
+ [key: string]: unknown;
34
+ }
35
+ /**
36
+ * Options for resolving build info.
37
+ */
38
+ export interface BuildInfoOptions {
39
+ /** Explicit build info data (e.g., injected at build time). */
40
+ data?: BuildInfoFile;
41
+ /** Environment variable prefix (default: "DEVLOGS_"). */
42
+ envPrefix?: string;
43
+ /** Custom function to get current time (for testing). */
44
+ nowFn?: () => Date;
45
+ /** Environment variables to use. Defaults to process.env. */
46
+ env?: Record<string, string | undefined>;
47
+ }
48
+ /**
49
+ * Format a Date as compact ISO-like UTC timestamp: YYYYMMDDTHHMMSSZ.
50
+ */
51
+ export declare function formatTimestamp(date: Date): string;
52
+ /**
53
+ * Resolve build information from data, environment, or generate it.
54
+ *
55
+ * Priority order:
56
+ * 1. Environment variable BUILD_ID (highest precedence)
57
+ * 2. Provided build info data (from file)
58
+ * 3. Environment variables for branch/timestamp
59
+ * 4. Generated values
60
+ */
61
+ export declare function resolveBuildInfo(options?: BuildInfoOptions): BuildInfo;
62
+ /**
63
+ * Convenience function that returns only the build_id string.
64
+ */
65
+ export declare function resolveBuildId(options?: BuildInfoOptions): string;
66
+ /**
67
+ * Create build info data object for writing to .build.json during build.
68
+ */
69
+ export declare function createBuildInfoData(options?: {
70
+ branch?: string;
71
+ nowFn?: () => Date;
72
+ }): BuildInfoFile;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Time-based circuit breaker with auto-recovery.
3
+ *
4
+ * Port of the Go SDK circuit breaker pattern:
5
+ * - Opens on failure, pauses indexing for `duration` (default 60s)
6
+ * - Auto-resets after duration expires (time-based)
7
+ * - Closes immediately on explicit success (RecordSuccess)
8
+ * - Throttles error output to once per `errorInterval` (default 10s)
9
+ */
10
+ export declare class CircuitBreaker {
11
+ private isOpen;
12
+ private openUntil;
13
+ private lastErrorPrinted;
14
+ private readonly duration;
15
+ private readonly errorInterval;
16
+ private readonly stderr;
17
+ /**
18
+ * @param duration - How long to keep circuit open in ms (default: 60000)
19
+ * @param errorInterval - Min interval between error prints in ms (default: 10000)
20
+ * @param stderr - Output function for error messages (default: process.stderr.write)
21
+ */
22
+ constructor(duration?: number, errorInterval?: number, stderr?: (msg: string) => void);
23
+ /**
24
+ * Check if the circuit breaker is open (should skip indexing).
25
+ * Auto-resets if duration has expired.
26
+ */
27
+ shouldSkip(): boolean;
28
+ /**
29
+ * Record a failure - opens the circuit breaker.
30
+ */
31
+ recordFailure(err: unknown): void;
32
+ /**
33
+ * Record a success - closes the circuit breaker.
34
+ */
35
+ recordSuccess(): void;
36
+ }
@@ -0,0 +1,19 @@
1
+ import type { DevlogsConfig, LogDocument } from './types';
2
+ import { CircuitBreaker } from './circuit-breaker';
3
+ /**
4
+ * Dual-mode HTTP client for sending log documents.
5
+ *
6
+ * - OpenSearch mode: POST to /{index}/_doc with Basic auth
7
+ * - Collector mode: POST to / with optional Bearer token
8
+ * - Fire-and-forget: does not await response
9
+ * - Circuit breaker: stops sending on failures, auto-recovers
10
+ */
11
+ export declare class DevlogsClient {
12
+ private readonly config;
13
+ private readonly cb;
14
+ constructor(config: DevlogsConfig, cb?: CircuitBreaker);
15
+ /**
16
+ * Send a log document. Fire-and-forget - does not block.
17
+ */
18
+ send(doc: LogDocument): void;
19
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Parsed environment config from DEVLOGS_* vars and .env.devlogs files.
3
+ */
4
+ export interface EnvConfig {
5
+ url?: string;
6
+ index?: string;
7
+ application?: string;
8
+ component?: string;
9
+ area?: string;
10
+ environment?: string;
11
+ version?: string;
12
+ }
13
+ /**
14
+ * Load environment variables from .env.devlogs (preferred) or .env file.
15
+ * Only sets variables that are not already defined in process.env.
16
+ * Called once automatically on first config load.
17
+ */
18
+ export declare function loadDotenv(): void;
19
+ /**
20
+ * Reset the loaded state (for testing).
21
+ */
22
+ export declare function resetDotenvLoaded(): void;
23
+ /**
24
+ * Load configuration from DEVLOGS_* environment variables.
25
+ * Automatically loads .env.devlogs on first call.
26
+ */
27
+ export declare function loadEnvConfig(): EnvConfig;
@@ -0,0 +1,37 @@
1
+ import type { LogContext } from './types';
2
+ /**
3
+ * Set the default context values (called during init).
4
+ */
5
+ export declare function setDefaultContext(ctx: Partial<LogContext>): void;
6
+ /**
7
+ * Get the current logging context.
8
+ * Returns the AsyncLocalStorage context if inside withContext/withOperation,
9
+ * otherwise returns the default (module-level) context.
10
+ */
11
+ export declare function getContext(): LogContext;
12
+ /**
13
+ * Set the application area in the current context.
14
+ */
15
+ export declare function setArea(area: string | null): void;
16
+ /**
17
+ * Set the operation ID in the current context.
18
+ */
19
+ export declare function setOperationId(operationId: string | null): void;
20
+ /**
21
+ * Set custom fields in the current context.
22
+ */
23
+ export declare function setFields(fields: Record<string, unknown>): void;
24
+ /**
25
+ * Run a function with a temporary operation ID in an isolated async context.
26
+ * The operation ID is automatically scoped to the callback and its async children.
27
+ */
28
+ export declare function withOperation<T>(operationId: string, fn: () => T): T;
29
+ /**
30
+ * Run a function with a fully isolated async context.
31
+ * Changes made inside the callback don't affect the parent context.
32
+ */
33
+ export declare function withContext<T>(overrides: Partial<LogContext>, fn: () => T): T;
34
+ /**
35
+ * Reset the default context (for testing/destroy).
36
+ */
37
+ export declare function resetContext(): void;