@watchguard-4331/agent 0.1.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,171 @@
1
+ var __createBinding = (undefined && undefined.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __exportStar = (undefined && undefined.__exportStar) || function(m, exports) {
13
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ __exportStar(require("./errors.cjs"), exports);
17
+ __exportStar(require("./helpers/parseUtil.cjs"), exports);
18
+ __exportStar(require("./helpers/typeAliases.cjs"), exports);
19
+ __exportStar(require("./helpers/util.cjs"), exports);
20
+ __exportStar(require("./types.cjs"), exports);
21
+ __exportStar(require("./ZodError.cjs"), exports);
22
+
23
+ declare const SampleSchema: undefined<"kind", [undefined<{
24
+ kind: undefined<"heartbeat">;
25
+ at: undefined;
26
+ }, "strip", undefined, {
27
+ kind: "heartbeat";
28
+ at: string;
29
+ }, {
30
+ kind: "heartbeat";
31
+ at: string;
32
+ }>, undefined<{
33
+ kind: undefined<"error">;
34
+ at: undefined;
35
+ fn: undefined;
36
+ message: undefined;
37
+ stack: undefined<undefined>;
38
+ }, "strip", undefined, {
39
+ kind: "error";
40
+ at: string;
41
+ message: string;
42
+ fn: string;
43
+ stack?: string | undefined;
44
+ }, {
45
+ kind: "error";
46
+ at: string;
47
+ message: string;
48
+ fn: string;
49
+ stack?: string | undefined;
50
+ }>, undefined<{
51
+ kind: undefined<"perf">;
52
+ at: undefined;
53
+ fn: undefined;
54
+ latencyMs: undefined;
55
+ coldStart: undefined;
56
+ }, "strip", undefined, {
57
+ kind: "perf";
58
+ at: string;
59
+ fn: string;
60
+ latencyMs: number;
61
+ coldStart: boolean;
62
+ }, {
63
+ kind: "perf";
64
+ at: string;
65
+ fn: string;
66
+ latencyMs: number;
67
+ coldStart: boolean;
68
+ }>]>;
69
+ type Sample = undefined<typeof SampleSchema>;
70
+
71
+ interface RepairCommand {
72
+ incidentId: string;
73
+ appId: string;
74
+ action: string;
75
+ issuedAt: string;
76
+ nonce: string;
77
+ }
78
+ declare function signCommand(cmd: RepairCommand, secret: string): string;
79
+ declare function verifyCommand(cmd: RepairCommand, signature: string, secret: string): boolean;
80
+
81
+ type Transport = (url: string, body: string, headers: Record<string, string>) => Promise<{
82
+ ok: boolean;
83
+ }>;
84
+ interface ReporterOptions {
85
+ appId: string;
86
+ ingestUrl: string;
87
+ apiKey: string;
88
+ transport: Transport;
89
+ now: () => string;
90
+ maxRetries: number;
91
+ }
92
+ declare class Reporter {
93
+ private readonly opts;
94
+ constructor(opts: ReporterOptions);
95
+ send(samples: Sample[]): Promise<void>;
96
+ }
97
+
98
+ interface CaptureContext {
99
+ fn: string;
100
+ record: (sample: Sample) => void;
101
+ clockMs: () => number;
102
+ now: () => string;
103
+ }
104
+ declare function captureErrors<A extends unknown[], R>(fn: (...args: A) => Promise<R>, ctx: CaptureContext): (...args: A) => Promise<R>;
105
+
106
+ interface TelemetryBufferOptions {
107
+ maxSize: number;
108
+ onFlush: (samples: Sample[]) => void;
109
+ }
110
+ declare class TelemetryBuffer {
111
+ private readonly opts;
112
+ private samples;
113
+ constructor(opts: TelemetryBufferOptions);
114
+ add(sample: Sample): void;
115
+ flushNow(): void;
116
+ }
117
+
118
+ interface HealthStatus {
119
+ status: "ok";
120
+ appId: string;
121
+ at: string;
122
+ }
123
+ declare function healthStatus(appId: string, now: () => string): HealthStatus;
124
+
125
+ /** Transport backed by the global fetch — telemetry loss never throws. */
126
+ declare const fetchTransport: Transport;
127
+
128
+ type RepairHandler = (command: RepairCommand) => Promise<void>;
129
+ type CommandResultStatus = "ok" | "failed" | "unsupported";
130
+ interface CommandResult {
131
+ status: CommandResultStatus;
132
+ detail: string;
133
+ }
134
+ declare function handleCommand(command: RepairCommand, handlers: Record<string, RepairHandler>): Promise<CommandResult>;
135
+ interface CommandRequest {
136
+ rawBody: string;
137
+ signature: string;
138
+ secret: string;
139
+ appId: string;
140
+ nowMs: number;
141
+ maxAgeMs?: number;
142
+ handlers: Record<string, RepairHandler>;
143
+ }
144
+ interface HttpResult {
145
+ status: number;
146
+ body: {
147
+ result: string;
148
+ detail?: string;
149
+ };
150
+ }
151
+ declare function handleCommandRequest(req: CommandRequest): Promise<HttpResult>;
152
+
153
+ interface InitOptions {
154
+ appId: string;
155
+ ingestUrl: string;
156
+ apiKey: string;
157
+ transport: Transport;
158
+ now?: () => string;
159
+ clockMs?: () => number;
160
+ maxBatch?: number;
161
+ maxRetries?: number;
162
+ }
163
+ interface Agent {
164
+ record: (sample: Sample) => void;
165
+ flush: () => void;
166
+ heartbeat: () => void;
167
+ wrap: <A extends unknown[], R>(fnName: string, fn: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
168
+ }
169
+ declare function init(opts: InitOptions): Agent;
170
+
171
+ export { type Agent, type CommandRequest, type CommandResult, type HealthStatus, type HttpResult, type InitOptions, type RepairCommand, type RepairHandler, Reporter, TelemetryBuffer, captureErrors, fetchTransport, handleCommand, handleCommandRequest, healthStatus, init, signCommand, verifyCommand };
@@ -0,0 +1,171 @@
1
+ var __createBinding = (undefined && undefined.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __exportStar = (undefined && undefined.__exportStar) || function(m, exports) {
13
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ __exportStar(require("./errors.cjs"), exports);
17
+ __exportStar(require("./helpers/parseUtil.cjs"), exports);
18
+ __exportStar(require("./helpers/typeAliases.cjs"), exports);
19
+ __exportStar(require("./helpers/util.cjs"), exports);
20
+ __exportStar(require("./types.cjs"), exports);
21
+ __exportStar(require("./ZodError.cjs"), exports);
22
+
23
+ declare const SampleSchema: undefined<"kind", [undefined<{
24
+ kind: undefined<"heartbeat">;
25
+ at: undefined;
26
+ }, "strip", undefined, {
27
+ kind: "heartbeat";
28
+ at: string;
29
+ }, {
30
+ kind: "heartbeat";
31
+ at: string;
32
+ }>, undefined<{
33
+ kind: undefined<"error">;
34
+ at: undefined;
35
+ fn: undefined;
36
+ message: undefined;
37
+ stack: undefined<undefined>;
38
+ }, "strip", undefined, {
39
+ kind: "error";
40
+ at: string;
41
+ message: string;
42
+ fn: string;
43
+ stack?: string | undefined;
44
+ }, {
45
+ kind: "error";
46
+ at: string;
47
+ message: string;
48
+ fn: string;
49
+ stack?: string | undefined;
50
+ }>, undefined<{
51
+ kind: undefined<"perf">;
52
+ at: undefined;
53
+ fn: undefined;
54
+ latencyMs: undefined;
55
+ coldStart: undefined;
56
+ }, "strip", undefined, {
57
+ kind: "perf";
58
+ at: string;
59
+ fn: string;
60
+ latencyMs: number;
61
+ coldStart: boolean;
62
+ }, {
63
+ kind: "perf";
64
+ at: string;
65
+ fn: string;
66
+ latencyMs: number;
67
+ coldStart: boolean;
68
+ }>]>;
69
+ type Sample = undefined<typeof SampleSchema>;
70
+
71
+ interface RepairCommand {
72
+ incidentId: string;
73
+ appId: string;
74
+ action: string;
75
+ issuedAt: string;
76
+ nonce: string;
77
+ }
78
+ declare function signCommand(cmd: RepairCommand, secret: string): string;
79
+ declare function verifyCommand(cmd: RepairCommand, signature: string, secret: string): boolean;
80
+
81
+ type Transport = (url: string, body: string, headers: Record<string, string>) => Promise<{
82
+ ok: boolean;
83
+ }>;
84
+ interface ReporterOptions {
85
+ appId: string;
86
+ ingestUrl: string;
87
+ apiKey: string;
88
+ transport: Transport;
89
+ now: () => string;
90
+ maxRetries: number;
91
+ }
92
+ declare class Reporter {
93
+ private readonly opts;
94
+ constructor(opts: ReporterOptions);
95
+ send(samples: Sample[]): Promise<void>;
96
+ }
97
+
98
+ interface CaptureContext {
99
+ fn: string;
100
+ record: (sample: Sample) => void;
101
+ clockMs: () => number;
102
+ now: () => string;
103
+ }
104
+ declare function captureErrors<A extends unknown[], R>(fn: (...args: A) => Promise<R>, ctx: CaptureContext): (...args: A) => Promise<R>;
105
+
106
+ interface TelemetryBufferOptions {
107
+ maxSize: number;
108
+ onFlush: (samples: Sample[]) => void;
109
+ }
110
+ declare class TelemetryBuffer {
111
+ private readonly opts;
112
+ private samples;
113
+ constructor(opts: TelemetryBufferOptions);
114
+ add(sample: Sample): void;
115
+ flushNow(): void;
116
+ }
117
+
118
+ interface HealthStatus {
119
+ status: "ok";
120
+ appId: string;
121
+ at: string;
122
+ }
123
+ declare function healthStatus(appId: string, now: () => string): HealthStatus;
124
+
125
+ /** Transport backed by the global fetch — telemetry loss never throws. */
126
+ declare const fetchTransport: Transport;
127
+
128
+ type RepairHandler = (command: RepairCommand) => Promise<void>;
129
+ type CommandResultStatus = "ok" | "failed" | "unsupported";
130
+ interface CommandResult {
131
+ status: CommandResultStatus;
132
+ detail: string;
133
+ }
134
+ declare function handleCommand(command: RepairCommand, handlers: Record<string, RepairHandler>): Promise<CommandResult>;
135
+ interface CommandRequest {
136
+ rawBody: string;
137
+ signature: string;
138
+ secret: string;
139
+ appId: string;
140
+ nowMs: number;
141
+ maxAgeMs?: number;
142
+ handlers: Record<string, RepairHandler>;
143
+ }
144
+ interface HttpResult {
145
+ status: number;
146
+ body: {
147
+ result: string;
148
+ detail?: string;
149
+ };
150
+ }
151
+ declare function handleCommandRequest(req: CommandRequest): Promise<HttpResult>;
152
+
153
+ interface InitOptions {
154
+ appId: string;
155
+ ingestUrl: string;
156
+ apiKey: string;
157
+ transport: Transport;
158
+ now?: () => string;
159
+ clockMs?: () => number;
160
+ maxBatch?: number;
161
+ maxRetries?: number;
162
+ }
163
+ interface Agent {
164
+ record: (sample: Sample) => void;
165
+ flush: () => void;
166
+ heartbeat: () => void;
167
+ wrap: <A extends unknown[], R>(fnName: string, fn: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
168
+ }
169
+ declare function init(opts: InitOptions): Agent;
170
+
171
+ export { type Agent, type CommandRequest, type CommandResult, type HealthStatus, type HttpResult, type InitOptions, type RepairCommand, type RepairHandler, Reporter, TelemetryBuffer, captureErrors, fetchTransport, handleCommand, handleCommandRequest, healthStatus, init, signCommand, verifyCommand };