@flareapp/core 2.7.0 → 2.9.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,463 @@
1
+ //#region src/framework.d.ts
2
+ /**
3
+ * Framework names the Flare backend recognises. Wire format, so the values never change: they ship as
4
+ * `flare.framework.name` and (lowercased) as `context.custom.framework`.
5
+ *
6
+ * `Js` and `Node` are the base SDKs' fallback claim, overwritten when a framework package tags its
7
+ * own name. `NodeElectron` is an Electron main process; its renderers report their own.
8
+ */
9
+ declare const FrameworkName: {
10
+ readonly Js: "js";
11
+ readonly Node: "node";
12
+ readonly NodeElectron: "node-electron";
13
+ readonly React: "react";
14
+ readonly Vue: "vue";
15
+ readonly Svelte: "svelte";
16
+ readonly SvelteKit: "sveltekit";
17
+ readonly ReactNative: "react-native";
18
+ };
19
+ type FrameworkName = (typeof FrameworkName)[keyof typeof FrameworkName];
20
+ //#endregion
21
+ //#region src/spanTypes.d.ts
22
+ /**
23
+ * Span types the Flare backend recognises. Wire format, so the values never change: they ship as the
24
+ * `flare.span_type` attribute and the backend groups performance data by them.
25
+ *
26
+ * These are the browser client's set. They live in core because core's `SpanOptions.spanType` needs
27
+ * to name them and core cannot import from `@flareapp/js`.
28
+ */
29
+ declare const BrowserSpanType: {
30
+ readonly Pageload: "browser_pageload";
31
+ readonly Navigation: "browser_navigation";
32
+ readonly Fetch: "browser_fetch";
33
+ readonly Xhr: "browser_xhr";
34
+ readonly Component: "browser_component";
35
+ readonly WebVital: "browser_web_vital";
36
+ };
37
+ type BrowserSpanType = (typeof BrowserSpanType)[keyof typeof BrowserSpanType];
38
+ /** Any other value stays legal, so a host SDK can stamp its own without a core release. */
39
+ type SpanTypeName = BrowserSpanType | (string & {});
40
+ declare const BrowserSpanEventType: {
41
+ readonly Click: "browser_click";
42
+ readonly Input: "browser_input";
43
+ readonly RouteChange: "browser_route_change";
44
+ };
45
+ type BrowserSpanEventType = (typeof BrowserSpanEventType)[keyof typeof BrowserSpanEventType];
46
+ //#endregion
47
+ //#region src/types.d.ts
48
+ type MessageLevel = 'debug' | 'info' | 'notice' | 'warning' | 'error' | 'critical' | 'alert' | 'emergency';
49
+ type AttributeValue = string | number | boolean | null | AttributeValue[] | {
50
+ [key: string]: AttributeValue;
51
+ };
52
+ type Attributes = Record<string, AttributeValue>;
53
+ /**
54
+ * An identified user passed to `Flare.setUser`. Known fields map to the backend keys: `id`->`user.id`,
55
+ * `email`->`user.email`, `fullName`->`user.full_name`, `ipAddress`->`client.address`. Any other key lands in
56
+ * `user.attributes`. Caveat: the open index signature means a misspelled known field (e.g. `full_name` for `fullName`)
57
+ * silently lands in `user.attributes` with no type error. Spell the four known fields exactly.
58
+ */
59
+ type User = {
60
+ id?: string | number;
61
+ email?: string;
62
+ fullName?: string;
63
+ ipAddress?: string;
64
+ [key: string]: AttributeValue | undefined;
65
+ };
66
+ type Config = {
67
+ key: string | null;
68
+ version: string;
69
+ sourcemapVersionId: string;
70
+ stage: string;
71
+ maxGlowsPerReport: number;
72
+ enableBreadcrumbs: boolean;
73
+ maxBreadcrumbs: number;
74
+ reportBrowserExtensionErrors: boolean;
75
+ ingestUrl: string;
76
+ debug: boolean;
77
+ urlDenylist: RegExp;
78
+ replaceDefaultUrlDenylist: boolean;
79
+ sampleRate: number;
80
+ enableLogs: boolean;
81
+ logsIngestUrl: string;
82
+ minimumLogLevel?: MessageLevel;
83
+ serviceName?: string;
84
+ maxLogBufferSize: number;
85
+ logFlushIntervalMs: number;
86
+ logFlushMaxBytes: number;
87
+ keepaliveMaxBytes: number;
88
+ enableTracing: boolean;
89
+ tracesIngestUrl: string;
90
+ tracesSampleRate: number;
91
+ tracesSampler?: TracesSampler;
92
+ /**
93
+ * URLs a W3C `traceparent` header may be attached to on outgoing requests. Default (unset): same-origin + relative
94
+ * only; `[]` disables all injection. Each entry matches by String.includes (string) or RegExp.test. Attaching
95
+ * cross-origin forces a CORS preflight; the target server must allow the `traceparent` request header.
96
+ */
97
+ tracePropagationTargets?: (string | RegExp)[]; /** Idle-span: ms of no open child spans before a pageload/navigation root closes. Browser default 1000. */
98
+ idleTimeout?: number; /** Idle-span: hard cap in ms from root start before it closes regardless of activity. Browser default 30000. */
99
+ finalTimeout?: number; /** Idle-span: if a child span stays open this many ms, the root closes anyway. Browser default 15000. */
100
+ childSpanTimeout?: number;
101
+ maxSpanBufferSize: number;
102
+ spanFlushIntervalMs: number;
103
+ spanFlushMaxBytes: number;
104
+ maxSpansPerTrace: number;
105
+ maxAttributesPerSpan: number;
106
+ maxEventsPerSpan: number;
107
+ maxAttributesPerSpanEvent: number;
108
+ beforeEvaluate: (error: Error) => Error | false | null | Promise<Error | false | null>;
109
+ beforeSubmit: (report: Report) => Report | false | null | Promise<Report | false | null>;
110
+ };
111
+ type StackFrame = {
112
+ file: string;
113
+ lineNumber: number;
114
+ columnNumber?: number;
115
+ method?: string;
116
+ class?: string;
117
+ codeSnippet?: {
118
+ [line: number]: string;
119
+ };
120
+ isApplicationFrame?: boolean;
121
+ arguments?: unknown[];
122
+ };
123
+ type SpanEvent = {
124
+ type: string;
125
+ startTimeUnixNano: number;
126
+ endTimeUnixNano: number | null;
127
+ attributes: Attributes;
128
+ };
129
+ type OverriddenGrouping = 'exception_class' | 'exception_message' | 'exception_message_and_class' | 'full_stacktrace_and_exception_class_and_code';
130
+ type Report = {
131
+ exceptionClass?: string | null;
132
+ message?: string | null;
133
+ code?: string;
134
+ seenAtUnixNano: number;
135
+ isLog?: boolean;
136
+ level?: MessageLevel;
137
+ sourcemapVersionId?: string;
138
+ trackingUuid?: string;
139
+ handled?: boolean;
140
+ openFrameIndex?: number;
141
+ applicationPath?: string;
142
+ overriddenGrouping?: OverriddenGrouping | null;
143
+ stacktrace: StackFrame[];
144
+ events: SpanEvent[];
145
+ attributes: Attributes;
146
+ };
147
+ type Glow = {
148
+ time: number;
149
+ microtime: number;
150
+ name: string;
151
+ messageLevel: MessageLevel;
152
+ metaData: Record<string, unknown> | Record<string, unknown>[];
153
+ };
154
+ /** The values the backend accepts for `flare.entry_point.type`. Anything else is dropped. */
155
+ type EntryPointType = 'web' | 'queue' | 'cli';
156
+ type EntryPointHandler = {
157
+ identifier?: string;
158
+ name?: string;
159
+ type?: string;
160
+ };
161
+ type SdkInfo = {
162
+ name: string;
163
+ version: string;
164
+ };
165
+ /**
166
+ * The framework identity an SDK reports. `name` is wire format, not a display string: first-party
167
+ * SDKs use a `FrameworkName`. A host app may call `setFramework` with its own value (e.g. `express`),
168
+ * which the backend treats as unknown rather than rejecting, so the type stays open.
169
+ */
170
+ type Framework = {
171
+ name: FrameworkName | (string & {});
172
+ version?: string;
173
+ };
174
+ type AnyValue = {
175
+ stringValue: string;
176
+ } | {
177
+ boolValue: boolean;
178
+ } | {
179
+ intValue: number;
180
+ } | {
181
+ doubleValue: number;
182
+ } | {
183
+ arrayValue: {
184
+ values: AnyValue[];
185
+ };
186
+ } | {
187
+ kvlistValue: {
188
+ values: KeyValue[];
189
+ };
190
+ };
191
+ type KeyValue = {
192
+ key: string;
193
+ value: AnyValue;
194
+ };
195
+ type OtelResource = {
196
+ attributes: KeyValue[];
197
+ droppedAttributesCount: number;
198
+ };
199
+ type OtelScope = {
200
+ name: string;
201
+ version: string;
202
+ attributes: KeyValue[];
203
+ droppedAttributesCount: number;
204
+ };
205
+ type OtelLogRecord = {
206
+ timeUnixNano: string;
207
+ observedTimeUnixNano: string;
208
+ severityNumber: number;
209
+ severityText: string;
210
+ body: AnyValue;
211
+ attributes: KeyValue[];
212
+ flags: number;
213
+ droppedAttributesCount: number;
214
+ };
215
+ type LogsEnvelope = {
216
+ resourceLogs: Array<{
217
+ resource: OtelResource;
218
+ scopeLogs: Array<{
219
+ scope: OtelScope;
220
+ logRecords: OtelLogRecord[];
221
+ }>;
222
+ }>;
223
+ };
224
+ type BufferedLog = {
225
+ timeUnixNano: string;
226
+ severityNumber: number;
227
+ severityText: string;
228
+ message: string;
229
+ recordAttributes: KeyValue[];
230
+ resourceAttributes: Attributes;
231
+ };
232
+ /** OTel status codes. Wire format: these numbers ship in the span envelope, so the values never change. */
233
+ declare const SpanStatusCode: {
234
+ readonly Unset: 0;
235
+ readonly Ok: 1;
236
+ readonly Error: 2;
237
+ };
238
+ type SpanStatusCode = (typeof SpanStatusCode)[keyof typeof SpanStatusCode];
239
+ type SpanStatus = {
240
+ code: SpanStatusCode;
241
+ message?: string;
242
+ };
243
+ type SpanOptions = {
244
+ parent?: Span | {
245
+ traceId: string;
246
+ spanId: string;
247
+ };
248
+ attributes?: Attributes;
249
+ startTimeUnixNano?: number;
250
+ spanType?: SpanTypeName;
251
+ /**
252
+ * Start this span as a new trace root, ignoring any ambient active span, so a
253
+ * root opened inside `withSpan(...)` does not become a mid-trace child.
254
+ */
255
+ forceRoot?: boolean; /** Use this exact span id instead of generating one (manual span stitching). */
256
+ spanId?: string; /** This span's slot against `maxSpansPerTrace` was already taken by `Tracer.claimSpanSlot`. */
257
+ claimed?: boolean;
258
+ };
259
+ interface Span {
260
+ readonly traceId: string;
261
+ readonly spanId: string;
262
+ readonly parentSpanId: string | null;
263
+ name: string;
264
+ readonly isRecording: boolean;
265
+ readonly endTimeUnixNano: number;
266
+ setAttribute(key: string, value: AttributeValue): this;
267
+ setStatus(status: SpanStatus): this;
268
+ addEvent(name: string, attributes?: Attributes): this;
269
+ end(endTimeUnixNano?: number): void;
270
+ }
271
+ type SamplingContext = {
272
+ name: string;
273
+ parentSampled?: boolean;
274
+ attributes: Attributes;
275
+ spanType?: SpanTypeName;
276
+ };
277
+ type TracesSampler = (ctx: SamplingContext) => number | boolean;
278
+ type BufferedSpanEvent = {
279
+ name: string;
280
+ timeUnixNano: number;
281
+ attributes: KeyValue[];
282
+ droppedAttributesCount: number;
283
+ };
284
+ type BufferedSpan = {
285
+ traceId: string;
286
+ spanId: string;
287
+ parentSpanId: string | null;
288
+ name: string;
289
+ startTimeUnixNano: number;
290
+ endTimeUnixNano: number;
291
+ status: SpanStatus;
292
+ recordAttributes: KeyValue[];
293
+ droppedAttributesCount: number;
294
+ droppedEventsCount: number;
295
+ events: BufferedSpanEvent[];
296
+ };
297
+ type OtelSpan = {
298
+ traceId: string;
299
+ spanId: string;
300
+ parentSpanId: string | null;
301
+ name: string;
302
+ startTimeUnixNano: number;
303
+ endTimeUnixNano: number;
304
+ status: SpanStatus;
305
+ attributes: KeyValue[];
306
+ events: BufferedSpanEvent[];
307
+ droppedAttributesCount: number;
308
+ droppedEventsCount: number;
309
+ links: never[];
310
+ droppedLinksCount: number;
311
+ };
312
+ type TracesEnvelope = {
313
+ resourceSpans: Array<{
314
+ resource: OtelResource;
315
+ scopeSpans: Array<{
316
+ scope: OtelScope;
317
+ spans: OtelSpan[];
318
+ }>;
319
+ }>;
320
+ };
321
+ //#endregion
322
+ //#region src/util/assert.d.ts
323
+ declare function assert(value: unknown, message: string, debug: boolean): boolean;
324
+ //#endregion
325
+ //#region src/util/assertKey.d.ts
326
+ declare function assertKey(key: unknown, debug: boolean): boolean;
327
+ //#endregion
328
+ //#region src/util/componentMatcher.d.ts
329
+ /** What a framework integration's `profileComponents` option accepts. */
330
+ type ProfileComponentsOption = boolean | (string | RegExp)[];
331
+ /**
332
+ * Built once so a mount costs one name resolution and one match. Strings match exactly, regexes by
333
+ * `test()`.
334
+ */
335
+ declare function createComponentMatcher(option: ProfileComponentsOption): (name: string) => boolean;
336
+ //#endregion
337
+ //#region src/util/convertToError.d.ts
338
+ declare function convertToError(error: unknown): Error;
339
+ //#endregion
340
+ //#region src/util/createIdentityTagger.d.ts
341
+ /** Minimal surface the tagger needs; the browser Flare and any subclass satisfy it structurally. */
342
+ interface SdkTaggable {
343
+ setSdkInfo(info: SdkInfo): unknown;
344
+ setFramework(framework: Framework): unknown;
345
+ }
346
+ /**
347
+ * A per-package SDK/framework identity tagger. Holds its own WeakSet guards, so each Flare instance
348
+ * (singleton or injected renderer) gets each of the two tags at most once.
349
+ *
350
+ * `frameworkName` is `FrameworkName` rather than `string` because those are the exact values the backend
351
+ * recognises, so a first-party package cannot invent one. A host app that needs its own name calls
352
+ * `setFramework` directly.
353
+ */
354
+ declare function createIdentityTagger(config: {
355
+ sdkName: string;
356
+ sdkVersion: string;
357
+ frameworkName: FrameworkName;
358
+ }): {
359
+ registerSdkIdentity(flare: SdkTaggable): void;
360
+ tagFramework(flare: SdkTaggable, frameworkVersion?: string): void;
361
+ };
362
+ //#endregion
363
+ //#region src/util/extractCode.d.ts
364
+ declare function extractCode(error: Error): string | undefined;
365
+ //#endregion
366
+ //#region src/util/flatJsonStringify.d.ts
367
+ /**
368
+ * JSON.stringify hardened for untrusted glow / addContext data: cycles become "[Circular]", a BigInt
369
+ * its decimal string, and a throwing getter "[Getter threw]", each of which would otherwise throw and
370
+ * drop the whole report.
371
+ */
372
+ declare function flatJsonStringify(json: object): string;
373
+ //#endregion
374
+ //#region src/util/glowsToEvents.d.ts
375
+ declare function glowsToEvents(glows: Glow[]): SpanEvent[];
376
+ //#endregion
377
+ //#region src/util/timelineEvents.d.ts
378
+ declare function timelineEvents(glows: Glow[], breadcrumbs: SpanEvent[]): SpanEvent[];
379
+ //#endregion
380
+ //#region src/util/now.d.ts
381
+ declare function now(): number;
382
+ //#endregion
383
+ //#region src/util/redactUrl.d.ts
384
+ declare const DEFAULT_URL_DENYLIST: RegExp;
385
+ declare function resolveDenylist(custom?: RegExp, replaceDefault?: boolean, defaultDenylist?: RegExp): RegExp;
386
+ /**
387
+ * Strips userinfo (`user:pass@`) from an absolute URL and replaces query-string values whose key
388
+ * matches `denylist` with `[redacted]`. Path segments are left untouched.
389
+ */
390
+ declare function redactUrlQuery(fullPath: string, denylist?: RegExp): string;
391
+ /**
392
+ * Value-side mirror of `redactUrlQuery`: a new object where any value whose key matches `denylist`
393
+ * becomes `[redacted]`. Null-prototype result so a `__proto__` key is stored, not swallowed.
394
+ */
395
+ declare function redactObjectValues(obj: Record<string, unknown>, denylist?: RegExp): Record<string, unknown>;
396
+ /**
397
+ * decodeURIComponent throws on malformed escape sequences (`%E0`, lone `%`, etc). Falls back to the
398
+ * raw key in that case rather than aborting the whole redaction pass.
399
+ */
400
+ declare function safeDecode(value: string): string;
401
+ //#endregion
402
+ //#region src/util/rejection.d.ts
403
+ type RejectionReporter = {
404
+ /** Error / stack-bearing reasons: preserve the stack. */reportSilently: (error: Error) => void; /** Stackless reasons. May return a promise; `routeRejection` swallows any rejection from it. */
405
+ reportUnhandledRejection: (message: string) => unknown;
406
+ };
407
+ /** Best-effort human-readable description of an arbitrary rejection reason. */
408
+ declare function describeRejectionReason(reason: unknown): string;
409
+ /**
410
+ * Routes by whether `reason` carries a stack: stack-bearing reasons go to `reportSilently`, stackless
411
+ * ones to `reportUnhandledRejection`.
412
+ * The `.catch` is what stops a transport failure from surfacing as a second unhandled rejection.
413
+ * `reportSilently` is assumed async and left unwrapped, so a synchronous throw there still propagates.
414
+ */
415
+ declare function routeRejection(reporter: RejectionReporter, reason: unknown): void;
416
+ //#endregion
417
+ //#region src/util/safeClone.d.ts
418
+ type SafeCloneOptions = {
419
+ mode: 'json';
420
+ } | {
421
+ mode: 'display';
422
+ maxDepth: number;
423
+ arrayCap: number;
424
+ objectKeyCap: number;
425
+ stringCap: number;
426
+ denylist: RegExp;
427
+ };
428
+ /**
429
+ * One JSON-safe recursive clone shared by flatJsonStringify (json mode) and vue serializeProps
430
+ * (display mode). Cycles become "[Circular]", a BigInt its decimal string, and a throwing getter
431
+ * "[Getter threw]" in both modes. json mode passes functions / symbols / non-plain objects through
432
+ * (so JSON.stringify still drops functions and calls Date.toJSON); display mode replaces them with
433
+ * placeholders and applies the depth / array / key / string caps and the key denylist.
434
+ */
435
+ declare function safeClone(value: unknown, options: SafeCloneOptions): unknown;
436
+ //#endregion
437
+ //#region src/util/statelessRegExp.d.ts
438
+ /**
439
+ * A `/g` or `/y` regex carries `lastIndex` between `test()` calls, so every other call misses. Returns
440
+ * a copy rather than mutating what the caller handed us.
441
+ */
442
+ declare function withoutStatefulFlags(pattern: RegExp): RegExp;
443
+ declare function withoutStatefulFlags(pattern: RegExp | undefined): RegExp | undefined;
444
+ //#endregion
445
+ //#region src/util/toCustomContext.d.ts
446
+ /** Wraps a framework payload as the `context.custom` attribute a report expects. */
447
+ declare function toCustomContext(framework: string, payload: AttributeValue): Attributes;
448
+ //#endregion
449
+ //#region src/util/urlAttributes.d.ts
450
+ /** Well past any routable URL, but short enough that an inline `data:` payload cannot ride along. */
451
+ declare const MAX_URL_LENGTH = 2048;
452
+ /**
453
+ * Builds the OTel `url.*` attributes for one absolute URL.
454
+ *
455
+ * Redacts the URL first and splits it after, so `url.full` and `url.query` always show the same
456
+ * redacted values.
457
+ *
458
+ * Leaves out `url.query` when there is no query string. Returns only `url.full` when the URL cannot
459
+ * be parsed, for example a relative one.
460
+ */
461
+ declare function urlAttributes(url: string, denylist?: RegExp): Attributes;
462
+ //#endregion
463
+ export { TracesSampler as $, BufferedLog as A, OtelLogRecord as B, ProfileComponentsOption as C, AnyValue as D, assert as E, Framework as F, SdkInfo as G, OverriddenGrouping as H, Glow as I, SpanOptions as J, Span as K, KeyValue as L, Config as M, EntryPointHandler as N, AttributeValue as O, EntryPointType as P, TracesEnvelope as Q, LogsEnvelope as R, convertToError as S, assertKey as T, Report as U, OtelSpan as V, SamplingContext as W, SpanStatusCode as X, SpanStatus as Y, StackFrame as Z, glowsToEvents as _, SafeCloneOptions as a, SdkTaggable as b, describeRejectionReason as c, redactObjectValues as d, User as et, redactUrlQuery as f, timelineEvents as g, now as h, withoutStatefulFlags as i, FrameworkName as it, BufferedSpan as j, Attributes as k, routeRejection as l, safeDecode as m, urlAttributes as n, BrowserSpanType as nt, safeClone as o, resolveDenylist as p, SpanEvent as q, toCustomContext as r, SpanTypeName as rt, RejectionReporter as s, MAX_URL_LENGTH as t, BrowserSpanEventType as tt, DEFAULT_URL_DENYLIST as u, flatJsonStringify as v, createComponentMatcher as w, createIdentityTagger as x, extractCode as y, MessageLevel as z };