@fallow-cli/beacon 0.1.0 → 0.1.1

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,8 @@
1
+ import type { BeaconConfig, CoveragePayload, FunctionCoverage } from "./types";
2
+ type BrowserBeacon = {
3
+ start: () => void;
4
+ stop: () => void;
5
+ flush: () => Promise<void>;
6
+ };
7
+ export declare const createBrowserBeacon: (config: BeaconConfig) => BrowserBeacon;
8
+ export type { BeaconConfig, BrowserBeacon, CoveragePayload, FunctionCoverage };
package/dist/node.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { BeaconConfig, CoveragePayload, FunctionCoverage } from "./types";
2
+ type NodeBeacon = {
3
+ start: () => void;
4
+ stop: () => Promise<void>;
5
+ flush: () => Promise<void>;
6
+ };
7
+ export declare const createNodeBeacon: (config: BeaconConfig) => NodeBeacon;
8
+ export type { BeaconConfig, CoveragePayload, FunctionCoverage, NodeBeacon };
@@ -0,0 +1,21 @@
1
+ import type { BeaconConfig, CoveragePayload, TransportState } from "./types";
2
+ /**
3
+ * Generates a unique payload ID. Prefers `crypto.randomUUID()` (Node 14.17+, modern browsers),
4
+ * falling back to a timestamp + random suffix for older runtimes.
5
+ */
6
+ export declare const generatePayloadId: () => string;
7
+ export type Transport = {
8
+ enqueue: (payload: CoveragePayload) => void;
9
+ flush: () => Promise<void>;
10
+ destroy: () => void;
11
+ state: () => TransportState;
12
+ pendingCount: () => number;
13
+ };
14
+ export declare const createTransport: (config: BeaconConfig) => Transport;
15
+ /**
16
+ * Best-effort send via navigator.sendBeacon() for browser unload scenarios.
17
+ * No auth header is sent (sendBeacon does not support custom headers).
18
+ * The server will reject with 401 — this is fire-and-forget with no delivery guarantee.
19
+ * Returns true if the browser accepted the beacon into its send queue.
20
+ */
21
+ export declare const sendBeaconFallback: (endpoint: string, payload: CoveragePayload) => boolean;
@@ -0,0 +1,46 @@
1
+ export type SnapshotSchedule = "idle" | "interval" | "manual";
2
+ export type BeaconConfig = {
3
+ apiKey: string;
4
+ projectId: string;
5
+ endpoint: string;
6
+ sampleRate?: number;
7
+ snapshotSchedule?: SnapshotSchedule;
8
+ environment?: string;
9
+ commitSha?: string;
10
+ flushIntervalMs?: number;
11
+ maxQueueSize?: number;
12
+ maxBatchSize?: number;
13
+ enabled?: boolean;
14
+ beforeSend?: (data: CoveragePayload) => CoveragePayload | null;
15
+ denyPaths?: RegExp[];
16
+ onFallback?: () => void;
17
+ };
18
+ export type TrackingState = "called" | "never_called" | "untracked";
19
+ export type FunctionCoverage = {
20
+ filePath: string;
21
+ functionName: string;
22
+ lineNumber: number | null;
23
+ hitCount: number;
24
+ trackingState: TrackingState;
25
+ };
26
+ export type CoveragePayload = {
27
+ payloadId: string;
28
+ projectId: string;
29
+ environment: string | undefined;
30
+ commitSha: string | undefined;
31
+ timestamp: string;
32
+ functions: FunctionCoverage[];
33
+ };
34
+ export type IngestResponse = {
35
+ data: {
36
+ ingestIds: string[];
37
+ accepted: boolean;
38
+ };
39
+ };
40
+ export type TransportState = "active" | "backoff" | "shutdown";
41
+ export type ClientReportReason = "queue_overflow" | "ratelimit_backoff" | "network_error" | "auth_failure";
42
+ export type ClientReport = {
43
+ reason: ClientReportReason;
44
+ droppedCount: number;
45
+ timestamp: string;
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fallow-cli/beacon",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Lightweight production coverage beacon for fallow cloud",
5
5
  "keywords": [
6
6
  "coverage",
@@ -29,7 +29,7 @@
29
29
  }
30
30
  },
31
31
  "scripts": {
32
- "build": "bun build src/node.ts src/browser.ts --outdir dist --target node",
32
+ "build": "bun build src/node.ts src/browser.ts --outdir dist --target node && tsc --emitDeclarationOnly --outDir dist",
33
33
  "test": "vitest run",
34
34
  "typecheck": "tsc --noEmit"
35
35
  },