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