@dispatchitapp/core 1.0.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.
- package/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/index.cjs +457 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +288 -0
- package/dist/index.d.ts +288 -0
- package/dist/index.js +401 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
type Level = "fatal" | "error" | "warning" | "info" | "debug";
|
|
2
|
+
type TagValue = string | number | boolean | null;
|
|
3
|
+
type Tags = Record<string, TagValue>;
|
|
4
|
+
interface DispatchFrame {
|
|
5
|
+
abs_path?: string | null;
|
|
6
|
+
filename?: string | null;
|
|
7
|
+
function?: string | null;
|
|
8
|
+
lineno: number;
|
|
9
|
+
colno?: number | null;
|
|
10
|
+
in_app?: boolean;
|
|
11
|
+
pre_context?: string[];
|
|
12
|
+
context_line?: string;
|
|
13
|
+
post_context?: string[];
|
|
14
|
+
}
|
|
15
|
+
interface DispatchStacktrace {
|
|
16
|
+
frames: DispatchFrame[];
|
|
17
|
+
}
|
|
18
|
+
interface DispatchMechanism {
|
|
19
|
+
type: string;
|
|
20
|
+
handled: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface DispatchExceptionValue {
|
|
23
|
+
type: string;
|
|
24
|
+
value: string;
|
|
25
|
+
mechanism: DispatchMechanism;
|
|
26
|
+
stacktrace: DispatchStacktrace;
|
|
27
|
+
}
|
|
28
|
+
interface DispatchUser {
|
|
29
|
+
id?: string | null;
|
|
30
|
+
email?: string | null;
|
|
31
|
+
ip_address?: string | null;
|
|
32
|
+
}
|
|
33
|
+
interface DispatchRequest {
|
|
34
|
+
url?: string | null;
|
|
35
|
+
method?: string | null;
|
|
36
|
+
query_string?: string | null;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
data?: Record<string, unknown> | null;
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
interface DispatchSdk {
|
|
42
|
+
name: string;
|
|
43
|
+
version: string;
|
|
44
|
+
}
|
|
45
|
+
interface DispatchEvent {
|
|
46
|
+
event_id: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
platform: string;
|
|
49
|
+
level: Level;
|
|
50
|
+
environment: string;
|
|
51
|
+
release?: string | null;
|
|
52
|
+
server_name?: string | null;
|
|
53
|
+
transaction?: string | null;
|
|
54
|
+
exception: {
|
|
55
|
+
values: DispatchExceptionValue[];
|
|
56
|
+
};
|
|
57
|
+
request?: DispatchRequest;
|
|
58
|
+
user?: DispatchUser;
|
|
59
|
+
tags?: Tags;
|
|
60
|
+
sdk?: DispatchSdk;
|
|
61
|
+
}
|
|
62
|
+
interface TicketReporter {
|
|
63
|
+
email?: string | null;
|
|
64
|
+
external_id?: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface TicketAttachment {
|
|
67
|
+
filename?: string;
|
|
68
|
+
content_type?: string;
|
|
69
|
+
data: string;
|
|
70
|
+
}
|
|
71
|
+
interface TicketBody {
|
|
72
|
+
description: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
source?: string;
|
|
75
|
+
severity?: string | null;
|
|
76
|
+
reporter?: TicketReporter | null;
|
|
77
|
+
metadata?: Record<string, unknown>;
|
|
78
|
+
screenshots?: TicketAttachment[];
|
|
79
|
+
attachments?: TicketAttachment[];
|
|
80
|
+
}
|
|
81
|
+
interface TicketPayload {
|
|
82
|
+
ticket: TicketBody;
|
|
83
|
+
}
|
|
84
|
+
interface TicketResponse {
|
|
85
|
+
id: number;
|
|
86
|
+
status: string;
|
|
87
|
+
url: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare const DEFAULT_ENDPOINT = "https://dispatchit.app/api/v1/tickets";
|
|
91
|
+
declare const DEFAULT_ENABLED_ENVIRONMENTS: string[];
|
|
92
|
+
interface DispatchOptions {
|
|
93
|
+
/** Project API token (prefix dsp_live_). Required. */
|
|
94
|
+
apiKey: string;
|
|
95
|
+
/** Tickets endpoint. Default https://dispatchit.app/api/v1/tickets. */
|
|
96
|
+
endpoint?: string;
|
|
97
|
+
/** Error-ingest endpoint. Default: `endpoint` with the last path segment swapped to /store. */
|
|
98
|
+
errorEndpoint?: string;
|
|
99
|
+
/** Deploy environment. Default process.env.NODE_ENV, else "production". */
|
|
100
|
+
environment?: string;
|
|
101
|
+
/** Release identifier, e.g. a git SHA. */
|
|
102
|
+
release?: string | null;
|
|
103
|
+
/** Environments in which capture is active. Default ["production", "staging"]; [] means all. */
|
|
104
|
+
enabledEnvironments?: string[];
|
|
105
|
+
/** Master switch for exception capture. Default true. */
|
|
106
|
+
captureExceptions?: boolean;
|
|
107
|
+
/** Fraction of errors to report, 0..1. Default 1.0. */
|
|
108
|
+
errorSampleRate?: number;
|
|
109
|
+
/** Last chance to mutate or drop an event. Return null to drop. */
|
|
110
|
+
beforeSend?: ((event: DispatchEvent) => DispatchEvent | null) | null;
|
|
111
|
+
/** Static affected-user (server adapters resolve a per-request user instead). */
|
|
112
|
+
user?: DispatchUser | null;
|
|
113
|
+
/** Static tags attached to every event. */
|
|
114
|
+
tags?: Tags;
|
|
115
|
+
/** Identifies the producing SDK. Server adapters override the name (e.g. "dispatch-node"). */
|
|
116
|
+
sdk?: {
|
|
117
|
+
name: string;
|
|
118
|
+
version: string;
|
|
119
|
+
};
|
|
120
|
+
/** Log internal failures to console. Default false. */
|
|
121
|
+
debug?: boolean;
|
|
122
|
+
/** Base URL for human-facing report links. Default: the origin of `endpoint`. */
|
|
123
|
+
reportBaseUrl?: string | null;
|
|
124
|
+
/** Budget (ms) for draining the event queue at process exit; 0 skips the exit flush.
|
|
125
|
+
* Default 3000. Mirrors the gem's shutdown_timeout (seconds there, ms here). */
|
|
126
|
+
shutdownTimeout?: number;
|
|
127
|
+
}
|
|
128
|
+
interface DispatchConfig {
|
|
129
|
+
apiKey: string;
|
|
130
|
+
endpoint: string;
|
|
131
|
+
errorEndpoint: string;
|
|
132
|
+
reportBaseUrl: string | null;
|
|
133
|
+
environment: string;
|
|
134
|
+
release: string | null;
|
|
135
|
+
enabledEnvironments: string[];
|
|
136
|
+
captureExceptions: boolean;
|
|
137
|
+
errorSampleRate: number;
|
|
138
|
+
beforeSend: ((event: DispatchEvent) => DispatchEvent | null) | null;
|
|
139
|
+
user: DispatchUser | null;
|
|
140
|
+
tags: Tags;
|
|
141
|
+
sdk: {
|
|
142
|
+
name: string;
|
|
143
|
+
version: string;
|
|
144
|
+
};
|
|
145
|
+
debug: boolean;
|
|
146
|
+
shutdownTimeout: number;
|
|
147
|
+
}
|
|
148
|
+
declare function deriveErrorEndpoint(endpoint: string): string;
|
|
149
|
+
declare function deriveReportBaseUrl(endpoint: string): string | null;
|
|
150
|
+
declare function resolveConfig(options: DispatchOptions): DispatchConfig;
|
|
151
|
+
declare function configured(c: DispatchConfig): boolean;
|
|
152
|
+
declare function environmentEnabled(c: DispatchConfig): boolean;
|
|
153
|
+
declare function errorTrackingEnabled(c: DispatchConfig): boolean;
|
|
154
|
+
|
|
155
|
+
interface ReportInput {
|
|
156
|
+
/** Required. The human-readable description of the issue. */
|
|
157
|
+
description: string;
|
|
158
|
+
title?: string;
|
|
159
|
+
/** One of low/medium/high/critical. Unknown values are dropped server-side. */
|
|
160
|
+
severity?: string | null;
|
|
161
|
+
/** Origin of the report. Default "api". */
|
|
162
|
+
source?: string;
|
|
163
|
+
metadata?: Record<string, unknown>;
|
|
164
|
+
reporter?: TicketReporter | null;
|
|
165
|
+
/** Links the ticket to an already-captured error group (e.g. a request id or event_id). */
|
|
166
|
+
correlationId?: string | null;
|
|
167
|
+
attachments?: TicketAttachment[];
|
|
168
|
+
}
|
|
169
|
+
declare function buildTicketPayload(input: ReportInput): TicketPayload;
|
|
170
|
+
|
|
171
|
+
declare const QUEUE_LIMIT = 100;
|
|
172
|
+
interface Transport {
|
|
173
|
+
/** Enqueue an error event for asynchronous delivery (off the hot path). */
|
|
174
|
+
sendEvent(event: DispatchEvent): void;
|
|
175
|
+
/** Synchronously POST a ticket and return the parsed response (or null on failure). */
|
|
176
|
+
postTicket(payload: TicketPayload): Promise<TicketResponse | null>;
|
|
177
|
+
/** Resolve once the queue has drained (or the timeout elapses). */
|
|
178
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
179
|
+
}
|
|
180
|
+
type FetchLike = (input: string, init: {
|
|
181
|
+
method: string;
|
|
182
|
+
headers: Record<string, string>;
|
|
183
|
+
body: string;
|
|
184
|
+
keepalive?: boolean;
|
|
185
|
+
}) => Promise<{
|
|
186
|
+
ok: boolean;
|
|
187
|
+
status: number;
|
|
188
|
+
json(): Promise<unknown>;
|
|
189
|
+
}>;
|
|
190
|
+
declare function sdkHeader(config: DispatchConfig): string;
|
|
191
|
+
declare class FetchTransport implements Transport {
|
|
192
|
+
protected readonly config: DispatchConfig;
|
|
193
|
+
private queue;
|
|
194
|
+
private draining;
|
|
195
|
+
private readonly fetchImpl;
|
|
196
|
+
constructor(config: DispatchConfig, fetchImpl?: FetchLike);
|
|
197
|
+
sendEvent(event: DispatchEvent): void;
|
|
198
|
+
postTicket(payload: TicketPayload): Promise<TicketResponse | null>;
|
|
199
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
200
|
+
private kick;
|
|
201
|
+
private drain;
|
|
202
|
+
protected post(url: string, body: unknown): Promise<{
|
|
203
|
+
ok: boolean;
|
|
204
|
+
status: number;
|
|
205
|
+
json(): Promise<unknown>;
|
|
206
|
+
} | null>;
|
|
207
|
+
protected warn(message: string): void;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface CaptureContext {
|
|
211
|
+
level?: Level;
|
|
212
|
+
/** Defaults to true for manual capture; framework handlers pass false for unhandled errors. */
|
|
213
|
+
handled?: boolean;
|
|
214
|
+
user?: DispatchUser | null;
|
|
215
|
+
tags?: Tags;
|
|
216
|
+
request?: DispatchRequest;
|
|
217
|
+
transaction?: string | null;
|
|
218
|
+
serverName?: string | null;
|
|
219
|
+
}
|
|
220
|
+
interface ClientOptions extends DispatchOptions {
|
|
221
|
+
/** Override the transport (tests, or a runtime-specific transport). */
|
|
222
|
+
transport?: Transport;
|
|
223
|
+
/** The originating runtime written into event.platform. Default "javascript". */
|
|
224
|
+
platform?: string;
|
|
225
|
+
/** Injectable stack parser (e.g. the Node V8 parser, or a browser parser). */
|
|
226
|
+
parseStack?: (stack?: string | null) => DispatchFrame[];
|
|
227
|
+
/** Injectable RNG for deterministic sampling in tests. */
|
|
228
|
+
rng?: () => number;
|
|
229
|
+
}
|
|
230
|
+
declare class Client {
|
|
231
|
+
readonly config: DispatchConfig;
|
|
232
|
+
readonly transport: Transport;
|
|
233
|
+
private readonly platform;
|
|
234
|
+
private readonly parseStack;
|
|
235
|
+
private readonly rng;
|
|
236
|
+
constructor(options: ClientOptions);
|
|
237
|
+
captureException(error: unknown, context?: CaptureContext): void;
|
|
238
|
+
report(input: ReportInput): Promise<TicketResponse | null>;
|
|
239
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
240
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
declare const MAX_CAUSES = 5;
|
|
244
|
+
declare const VALUE_MAX_LENGTH = 2000;
|
|
245
|
+
interface BuildEventInput {
|
|
246
|
+
config: DispatchConfig;
|
|
247
|
+
handled: boolean;
|
|
248
|
+
platform?: string;
|
|
249
|
+
level?: Level;
|
|
250
|
+
user?: DispatchUser | null;
|
|
251
|
+
tags?: Tags;
|
|
252
|
+
request?: DispatchRequest;
|
|
253
|
+
transaction?: string | null;
|
|
254
|
+
serverName?: string | null;
|
|
255
|
+
/** Injectable for runtime-specific parsing (e.g. the Node V8 parser). Defaults to core's. */
|
|
256
|
+
parseStack?: (stack?: string | null) => DispatchFrame[];
|
|
257
|
+
/** Injectable for deterministic tests. */
|
|
258
|
+
now?: () => number;
|
|
259
|
+
uuid?: () => string;
|
|
260
|
+
}
|
|
261
|
+
declare function buildEvent(error: unknown, input: BuildEventInput): DispatchEvent;
|
|
262
|
+
|
|
263
|
+
declare const MAX_FRAMES = 100;
|
|
264
|
+
declare function parseStack(stack?: string | null): DispatchFrame[];
|
|
265
|
+
|
|
266
|
+
declare function sampledOut(rate: number, rng?: () => number): boolean;
|
|
267
|
+
|
|
268
|
+
declare function alreadyCaptured(error: unknown): boolean;
|
|
269
|
+
declare function markCaptured(error: unknown): void;
|
|
270
|
+
|
|
271
|
+
declare const SDK_NAME = "dispatch-js";
|
|
272
|
+
declare const SDK_VERSION = "1.0.0";
|
|
273
|
+
declare const CONTRACT_VERSION = "1";
|
|
274
|
+
|
|
275
|
+
/** Initialise the default client. Call once at startup. Returns it for direct use. */
|
|
276
|
+
declare function init(options: ClientOptions): Client;
|
|
277
|
+
/** The default client, or null if init() hasn't been called. */
|
|
278
|
+
declare function getClient(): Client | null;
|
|
279
|
+
/** Report a handled (or, from adapters, unhandled) exception via the default client. */
|
|
280
|
+
declare function captureException(error: unknown, context?: CaptureContext): void;
|
|
281
|
+
/** File a curated ticket via the default client. Resolves null if uninitialised. */
|
|
282
|
+
declare function report(input: ReportInput): Promise<TicketResponse | null>;
|
|
283
|
+
/** Wait for queued events to flush. Resolves true if the queue drained in time. */
|
|
284
|
+
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
285
|
+
/** Flush and stop using the default client. */
|
|
286
|
+
declare function close(timeoutMs?: number): Promise<boolean>;
|
|
287
|
+
|
|
288
|
+
export { CONTRACT_VERSION, type CaptureContext, Client, type ClientOptions, DEFAULT_ENABLED_ENVIRONMENTS, DEFAULT_ENDPOINT, type DispatchConfig, type DispatchEvent, type DispatchExceptionValue, type DispatchFrame, type DispatchMechanism, type DispatchOptions, type DispatchRequest, type DispatchSdk, type DispatchStacktrace, type DispatchUser, type FetchLike, FetchTransport, type Level, MAX_CAUSES, MAX_FRAMES, QUEUE_LIMIT, type ReportInput, SDK_NAME, SDK_VERSION, type TagValue, type Tags, type TicketAttachment, type TicketBody, type TicketPayload, type TicketReporter, type TicketResponse, type Transport, VALUE_MAX_LENGTH, alreadyCaptured, buildEvent, buildTicketPayload, captureException, close, configured, deriveErrorEndpoint, deriveReportBaseUrl, environmentEnabled, errorTrackingEnabled, flush, getClient, init, markCaptured, parseStack, report, resolveConfig, sampledOut, sdkHeader };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
type Level = "fatal" | "error" | "warning" | "info" | "debug";
|
|
2
|
+
type TagValue = string | number | boolean | null;
|
|
3
|
+
type Tags = Record<string, TagValue>;
|
|
4
|
+
interface DispatchFrame {
|
|
5
|
+
abs_path?: string | null;
|
|
6
|
+
filename?: string | null;
|
|
7
|
+
function?: string | null;
|
|
8
|
+
lineno: number;
|
|
9
|
+
colno?: number | null;
|
|
10
|
+
in_app?: boolean;
|
|
11
|
+
pre_context?: string[];
|
|
12
|
+
context_line?: string;
|
|
13
|
+
post_context?: string[];
|
|
14
|
+
}
|
|
15
|
+
interface DispatchStacktrace {
|
|
16
|
+
frames: DispatchFrame[];
|
|
17
|
+
}
|
|
18
|
+
interface DispatchMechanism {
|
|
19
|
+
type: string;
|
|
20
|
+
handled: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface DispatchExceptionValue {
|
|
23
|
+
type: string;
|
|
24
|
+
value: string;
|
|
25
|
+
mechanism: DispatchMechanism;
|
|
26
|
+
stacktrace: DispatchStacktrace;
|
|
27
|
+
}
|
|
28
|
+
interface DispatchUser {
|
|
29
|
+
id?: string | null;
|
|
30
|
+
email?: string | null;
|
|
31
|
+
ip_address?: string | null;
|
|
32
|
+
}
|
|
33
|
+
interface DispatchRequest {
|
|
34
|
+
url?: string | null;
|
|
35
|
+
method?: string | null;
|
|
36
|
+
query_string?: string | null;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
data?: Record<string, unknown> | null;
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
interface DispatchSdk {
|
|
42
|
+
name: string;
|
|
43
|
+
version: string;
|
|
44
|
+
}
|
|
45
|
+
interface DispatchEvent {
|
|
46
|
+
event_id: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
platform: string;
|
|
49
|
+
level: Level;
|
|
50
|
+
environment: string;
|
|
51
|
+
release?: string | null;
|
|
52
|
+
server_name?: string | null;
|
|
53
|
+
transaction?: string | null;
|
|
54
|
+
exception: {
|
|
55
|
+
values: DispatchExceptionValue[];
|
|
56
|
+
};
|
|
57
|
+
request?: DispatchRequest;
|
|
58
|
+
user?: DispatchUser;
|
|
59
|
+
tags?: Tags;
|
|
60
|
+
sdk?: DispatchSdk;
|
|
61
|
+
}
|
|
62
|
+
interface TicketReporter {
|
|
63
|
+
email?: string | null;
|
|
64
|
+
external_id?: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface TicketAttachment {
|
|
67
|
+
filename?: string;
|
|
68
|
+
content_type?: string;
|
|
69
|
+
data: string;
|
|
70
|
+
}
|
|
71
|
+
interface TicketBody {
|
|
72
|
+
description: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
source?: string;
|
|
75
|
+
severity?: string | null;
|
|
76
|
+
reporter?: TicketReporter | null;
|
|
77
|
+
metadata?: Record<string, unknown>;
|
|
78
|
+
screenshots?: TicketAttachment[];
|
|
79
|
+
attachments?: TicketAttachment[];
|
|
80
|
+
}
|
|
81
|
+
interface TicketPayload {
|
|
82
|
+
ticket: TicketBody;
|
|
83
|
+
}
|
|
84
|
+
interface TicketResponse {
|
|
85
|
+
id: number;
|
|
86
|
+
status: string;
|
|
87
|
+
url: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare const DEFAULT_ENDPOINT = "https://dispatchit.app/api/v1/tickets";
|
|
91
|
+
declare const DEFAULT_ENABLED_ENVIRONMENTS: string[];
|
|
92
|
+
interface DispatchOptions {
|
|
93
|
+
/** Project API token (prefix dsp_live_). Required. */
|
|
94
|
+
apiKey: string;
|
|
95
|
+
/** Tickets endpoint. Default https://dispatchit.app/api/v1/tickets. */
|
|
96
|
+
endpoint?: string;
|
|
97
|
+
/** Error-ingest endpoint. Default: `endpoint` with the last path segment swapped to /store. */
|
|
98
|
+
errorEndpoint?: string;
|
|
99
|
+
/** Deploy environment. Default process.env.NODE_ENV, else "production". */
|
|
100
|
+
environment?: string;
|
|
101
|
+
/** Release identifier, e.g. a git SHA. */
|
|
102
|
+
release?: string | null;
|
|
103
|
+
/** Environments in which capture is active. Default ["production", "staging"]; [] means all. */
|
|
104
|
+
enabledEnvironments?: string[];
|
|
105
|
+
/** Master switch for exception capture. Default true. */
|
|
106
|
+
captureExceptions?: boolean;
|
|
107
|
+
/** Fraction of errors to report, 0..1. Default 1.0. */
|
|
108
|
+
errorSampleRate?: number;
|
|
109
|
+
/** Last chance to mutate or drop an event. Return null to drop. */
|
|
110
|
+
beforeSend?: ((event: DispatchEvent) => DispatchEvent | null) | null;
|
|
111
|
+
/** Static affected-user (server adapters resolve a per-request user instead). */
|
|
112
|
+
user?: DispatchUser | null;
|
|
113
|
+
/** Static tags attached to every event. */
|
|
114
|
+
tags?: Tags;
|
|
115
|
+
/** Identifies the producing SDK. Server adapters override the name (e.g. "dispatch-node"). */
|
|
116
|
+
sdk?: {
|
|
117
|
+
name: string;
|
|
118
|
+
version: string;
|
|
119
|
+
};
|
|
120
|
+
/** Log internal failures to console. Default false. */
|
|
121
|
+
debug?: boolean;
|
|
122
|
+
/** Base URL for human-facing report links. Default: the origin of `endpoint`. */
|
|
123
|
+
reportBaseUrl?: string | null;
|
|
124
|
+
/** Budget (ms) for draining the event queue at process exit; 0 skips the exit flush.
|
|
125
|
+
* Default 3000. Mirrors the gem's shutdown_timeout (seconds there, ms here). */
|
|
126
|
+
shutdownTimeout?: number;
|
|
127
|
+
}
|
|
128
|
+
interface DispatchConfig {
|
|
129
|
+
apiKey: string;
|
|
130
|
+
endpoint: string;
|
|
131
|
+
errorEndpoint: string;
|
|
132
|
+
reportBaseUrl: string | null;
|
|
133
|
+
environment: string;
|
|
134
|
+
release: string | null;
|
|
135
|
+
enabledEnvironments: string[];
|
|
136
|
+
captureExceptions: boolean;
|
|
137
|
+
errorSampleRate: number;
|
|
138
|
+
beforeSend: ((event: DispatchEvent) => DispatchEvent | null) | null;
|
|
139
|
+
user: DispatchUser | null;
|
|
140
|
+
tags: Tags;
|
|
141
|
+
sdk: {
|
|
142
|
+
name: string;
|
|
143
|
+
version: string;
|
|
144
|
+
};
|
|
145
|
+
debug: boolean;
|
|
146
|
+
shutdownTimeout: number;
|
|
147
|
+
}
|
|
148
|
+
declare function deriveErrorEndpoint(endpoint: string): string;
|
|
149
|
+
declare function deriveReportBaseUrl(endpoint: string): string | null;
|
|
150
|
+
declare function resolveConfig(options: DispatchOptions): DispatchConfig;
|
|
151
|
+
declare function configured(c: DispatchConfig): boolean;
|
|
152
|
+
declare function environmentEnabled(c: DispatchConfig): boolean;
|
|
153
|
+
declare function errorTrackingEnabled(c: DispatchConfig): boolean;
|
|
154
|
+
|
|
155
|
+
interface ReportInput {
|
|
156
|
+
/** Required. The human-readable description of the issue. */
|
|
157
|
+
description: string;
|
|
158
|
+
title?: string;
|
|
159
|
+
/** One of low/medium/high/critical. Unknown values are dropped server-side. */
|
|
160
|
+
severity?: string | null;
|
|
161
|
+
/** Origin of the report. Default "api". */
|
|
162
|
+
source?: string;
|
|
163
|
+
metadata?: Record<string, unknown>;
|
|
164
|
+
reporter?: TicketReporter | null;
|
|
165
|
+
/** Links the ticket to an already-captured error group (e.g. a request id or event_id). */
|
|
166
|
+
correlationId?: string | null;
|
|
167
|
+
attachments?: TicketAttachment[];
|
|
168
|
+
}
|
|
169
|
+
declare function buildTicketPayload(input: ReportInput): TicketPayload;
|
|
170
|
+
|
|
171
|
+
declare const QUEUE_LIMIT = 100;
|
|
172
|
+
interface Transport {
|
|
173
|
+
/** Enqueue an error event for asynchronous delivery (off the hot path). */
|
|
174
|
+
sendEvent(event: DispatchEvent): void;
|
|
175
|
+
/** Synchronously POST a ticket and return the parsed response (or null on failure). */
|
|
176
|
+
postTicket(payload: TicketPayload): Promise<TicketResponse | null>;
|
|
177
|
+
/** Resolve once the queue has drained (or the timeout elapses). */
|
|
178
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
179
|
+
}
|
|
180
|
+
type FetchLike = (input: string, init: {
|
|
181
|
+
method: string;
|
|
182
|
+
headers: Record<string, string>;
|
|
183
|
+
body: string;
|
|
184
|
+
keepalive?: boolean;
|
|
185
|
+
}) => Promise<{
|
|
186
|
+
ok: boolean;
|
|
187
|
+
status: number;
|
|
188
|
+
json(): Promise<unknown>;
|
|
189
|
+
}>;
|
|
190
|
+
declare function sdkHeader(config: DispatchConfig): string;
|
|
191
|
+
declare class FetchTransport implements Transport {
|
|
192
|
+
protected readonly config: DispatchConfig;
|
|
193
|
+
private queue;
|
|
194
|
+
private draining;
|
|
195
|
+
private readonly fetchImpl;
|
|
196
|
+
constructor(config: DispatchConfig, fetchImpl?: FetchLike);
|
|
197
|
+
sendEvent(event: DispatchEvent): void;
|
|
198
|
+
postTicket(payload: TicketPayload): Promise<TicketResponse | null>;
|
|
199
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
200
|
+
private kick;
|
|
201
|
+
private drain;
|
|
202
|
+
protected post(url: string, body: unknown): Promise<{
|
|
203
|
+
ok: boolean;
|
|
204
|
+
status: number;
|
|
205
|
+
json(): Promise<unknown>;
|
|
206
|
+
} | null>;
|
|
207
|
+
protected warn(message: string): void;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface CaptureContext {
|
|
211
|
+
level?: Level;
|
|
212
|
+
/** Defaults to true for manual capture; framework handlers pass false for unhandled errors. */
|
|
213
|
+
handled?: boolean;
|
|
214
|
+
user?: DispatchUser | null;
|
|
215
|
+
tags?: Tags;
|
|
216
|
+
request?: DispatchRequest;
|
|
217
|
+
transaction?: string | null;
|
|
218
|
+
serverName?: string | null;
|
|
219
|
+
}
|
|
220
|
+
interface ClientOptions extends DispatchOptions {
|
|
221
|
+
/** Override the transport (tests, or a runtime-specific transport). */
|
|
222
|
+
transport?: Transport;
|
|
223
|
+
/** The originating runtime written into event.platform. Default "javascript". */
|
|
224
|
+
platform?: string;
|
|
225
|
+
/** Injectable stack parser (e.g. the Node V8 parser, or a browser parser). */
|
|
226
|
+
parseStack?: (stack?: string | null) => DispatchFrame[];
|
|
227
|
+
/** Injectable RNG for deterministic sampling in tests. */
|
|
228
|
+
rng?: () => number;
|
|
229
|
+
}
|
|
230
|
+
declare class Client {
|
|
231
|
+
readonly config: DispatchConfig;
|
|
232
|
+
readonly transport: Transport;
|
|
233
|
+
private readonly platform;
|
|
234
|
+
private readonly parseStack;
|
|
235
|
+
private readonly rng;
|
|
236
|
+
constructor(options: ClientOptions);
|
|
237
|
+
captureException(error: unknown, context?: CaptureContext): void;
|
|
238
|
+
report(input: ReportInput): Promise<TicketResponse | null>;
|
|
239
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
240
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
declare const MAX_CAUSES = 5;
|
|
244
|
+
declare const VALUE_MAX_LENGTH = 2000;
|
|
245
|
+
interface BuildEventInput {
|
|
246
|
+
config: DispatchConfig;
|
|
247
|
+
handled: boolean;
|
|
248
|
+
platform?: string;
|
|
249
|
+
level?: Level;
|
|
250
|
+
user?: DispatchUser | null;
|
|
251
|
+
tags?: Tags;
|
|
252
|
+
request?: DispatchRequest;
|
|
253
|
+
transaction?: string | null;
|
|
254
|
+
serverName?: string | null;
|
|
255
|
+
/** Injectable for runtime-specific parsing (e.g. the Node V8 parser). Defaults to core's. */
|
|
256
|
+
parseStack?: (stack?: string | null) => DispatchFrame[];
|
|
257
|
+
/** Injectable for deterministic tests. */
|
|
258
|
+
now?: () => number;
|
|
259
|
+
uuid?: () => string;
|
|
260
|
+
}
|
|
261
|
+
declare function buildEvent(error: unknown, input: BuildEventInput): DispatchEvent;
|
|
262
|
+
|
|
263
|
+
declare const MAX_FRAMES = 100;
|
|
264
|
+
declare function parseStack(stack?: string | null): DispatchFrame[];
|
|
265
|
+
|
|
266
|
+
declare function sampledOut(rate: number, rng?: () => number): boolean;
|
|
267
|
+
|
|
268
|
+
declare function alreadyCaptured(error: unknown): boolean;
|
|
269
|
+
declare function markCaptured(error: unknown): void;
|
|
270
|
+
|
|
271
|
+
declare const SDK_NAME = "dispatch-js";
|
|
272
|
+
declare const SDK_VERSION = "1.0.0";
|
|
273
|
+
declare const CONTRACT_VERSION = "1";
|
|
274
|
+
|
|
275
|
+
/** Initialise the default client. Call once at startup. Returns it for direct use. */
|
|
276
|
+
declare function init(options: ClientOptions): Client;
|
|
277
|
+
/** The default client, or null if init() hasn't been called. */
|
|
278
|
+
declare function getClient(): Client | null;
|
|
279
|
+
/** Report a handled (or, from adapters, unhandled) exception via the default client. */
|
|
280
|
+
declare function captureException(error: unknown, context?: CaptureContext): void;
|
|
281
|
+
/** File a curated ticket via the default client. Resolves null if uninitialised. */
|
|
282
|
+
declare function report(input: ReportInput): Promise<TicketResponse | null>;
|
|
283
|
+
/** Wait for queued events to flush. Resolves true if the queue drained in time. */
|
|
284
|
+
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
285
|
+
/** Flush and stop using the default client. */
|
|
286
|
+
declare function close(timeoutMs?: number): Promise<boolean>;
|
|
287
|
+
|
|
288
|
+
export { CONTRACT_VERSION, type CaptureContext, Client, type ClientOptions, DEFAULT_ENABLED_ENVIRONMENTS, DEFAULT_ENDPOINT, type DispatchConfig, type DispatchEvent, type DispatchExceptionValue, type DispatchFrame, type DispatchMechanism, type DispatchOptions, type DispatchRequest, type DispatchSdk, type DispatchStacktrace, type DispatchUser, type FetchLike, FetchTransport, type Level, MAX_CAUSES, MAX_FRAMES, QUEUE_LIMIT, type ReportInput, SDK_NAME, SDK_VERSION, type TagValue, type Tags, type TicketAttachment, type TicketBody, type TicketPayload, type TicketReporter, type TicketResponse, type Transport, VALUE_MAX_LENGTH, alreadyCaptured, buildEvent, buildTicketPayload, captureException, close, configured, deriveErrorEndpoint, deriveReportBaseUrl, environmentEnabled, errorTrackingEnabled, flush, getClient, init, markCaptured, parseStack, report, resolveConfig, sampledOut, sdkHeader };
|