@flareapp/js 1.2.1 → 2.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.
@@ -1,96 +0,0 @@
1
- const cachedFiles: { [key: string]: string } = {};
2
-
3
- type CodeSnippet = {
4
- [key: number]: string;
5
- };
6
-
7
- type ReaderResponse = {
8
- codeSnippet: CodeSnippet;
9
- trimmedColumnNumber: number | null;
10
- };
11
-
12
- export function getCodeSnippet(url?: string, lineNumber?: number, columnNumber?: number): Promise<ReaderResponse> {
13
- return new Promise((resolve) => {
14
- if (!url || !lineNumber) {
15
- return resolve({
16
- codeSnippet: {
17
- 0: `Could not read from file: missing file URL or line number. URL: ${url} lineNumber: ${lineNumber}`,
18
- },
19
- trimmedColumnNumber: null,
20
- });
21
- }
22
-
23
- readFile(url).then((fileText) => {
24
- if (!fileText) {
25
- return resolve({
26
- codeSnippet: {
27
- 0: `Could not read from file: Error while opening file at URL ${url}`,
28
- },
29
- trimmedColumnNumber: null,
30
- });
31
- }
32
-
33
- return resolve(readLinesFromFile(fileText, lineNumber, columnNumber));
34
- });
35
- });
36
- }
37
-
38
- function readFile(url: string): Promise<string | null> {
39
- if (cachedFiles[url]) {
40
- return Promise.resolve(cachedFiles[url]);
41
- }
42
-
43
- return fetch(url)
44
- .then((response) => {
45
- if (response.status !== 200) {
46
- return null;
47
- }
48
-
49
- return response.text();
50
- })
51
- .catch(() => null);
52
- }
53
-
54
- export function readLinesFromFile(
55
- fileText: string,
56
- lineNumber: number,
57
- columnNumber?: number,
58
- maxSnippetLineLength = 1000,
59
- maxSnippetLines = 40
60
- ): ReaderResponse {
61
- const codeSnippet: CodeSnippet = {};
62
- let trimmedColumnNumber = null;
63
-
64
- const lines = fileText.split('\n');
65
-
66
- for (let i = -maxSnippetLines / 2; i <= maxSnippetLines / 2; i++) {
67
- const currentLineIndex = lineNumber + i;
68
-
69
- if (currentLineIndex >= 0 && lines[currentLineIndex]) {
70
- const displayLine = currentLineIndex + 1; // the linenumber in a stacktrace is not zero-based like an array
71
-
72
- if (lines[currentLineIndex].length > maxSnippetLineLength) {
73
- if (columnNumber && columnNumber + maxSnippetLineLength / 2 > maxSnippetLineLength) {
74
- codeSnippet[displayLine] = lines[currentLineIndex].substr(
75
- columnNumber - Math.round(maxSnippetLineLength / 2),
76
- maxSnippetLineLength
77
- );
78
-
79
- if (displayLine === lineNumber) {
80
- trimmedColumnNumber = Math.round(maxSnippetLineLength / 2);
81
- }
82
-
83
- continue;
84
- }
85
-
86
- codeSnippet[displayLine] = lines[currentLineIndex].substr(0, maxSnippetLineLength) + '…';
87
-
88
- continue;
89
- }
90
-
91
- codeSnippet[displayLine] = lines[currentLineIndex];
92
- }
93
- }
94
-
95
- return { codeSnippet, trimmedColumnNumber };
96
- }
@@ -1 +0,0 @@
1
- export * from './createStackTrace';
package/src/types.ts DELETED
@@ -1,76 +0,0 @@
1
- export type Config = {
2
- key: string | null;
3
- version: string;
4
- sourcemapVersion: string;
5
- stage: string;
6
- maxGlowsPerReport: number;
7
- reportBrowserExtensionErrors: boolean;
8
- reportingUrl: string;
9
- debug: boolean;
10
- beforeEvaluate: (error: Error) => Error | false | null | Promise<Error | false | null>;
11
- beforeSubmit: (report: Report) => Report | false | null | Promise<Report | false | null>;
12
- };
13
-
14
- export type Report = {
15
- notifier: string;
16
- exception_class: string;
17
- seen_at: number;
18
- message: string;
19
- language: 'javascript';
20
- glows: Glow[];
21
- context: Context;
22
- stacktrace: StackFrame[];
23
- sourcemap_version_id: string;
24
- solutions: Solution[];
25
- stage?: string;
26
- };
27
-
28
- export interface SolutionProviderExtraParameters {}
29
-
30
- export type SolutionProvider = {
31
- canSolve: (error: Error, extraParameters?: SolutionProviderExtraParameters) => boolean | Promise<boolean>;
32
- getSolutions: (error: Error, extraParameters?: SolutionProviderExtraParameters) => Solution[] | Promise<Solution[]>;
33
- };
34
-
35
- export type Solution = {
36
- class: string;
37
- title: string;
38
- description: string;
39
- links: { [label: string]: string };
40
- action_description?: string;
41
- is_runnable?: boolean;
42
- };
43
-
44
- export type Context = {
45
- request?: {
46
- url?: String;
47
- useragent?: String;
48
- referrer?: String; // TODO: Flare doesn't catch this yet
49
- readyState?: String; // TODO: Flare doesn't catch this yet
50
- };
51
- request_data?: {
52
- queryString: { [key: string]: string };
53
- };
54
- cookies?: { [key: string]: string };
55
- [key: string]: any;
56
- };
57
-
58
- export type StackFrame = {
59
- line_number: number;
60
- column_number: number; // TODO: Flare doesn't catch this yet
61
- method: string;
62
- file: string;
63
- code_snippet: { [key: number]: string };
64
- trimmed_column_number: number | null;
65
- class: string;
66
- };
67
-
68
- export type Glow = {
69
- time: number;
70
- microtime: number;
71
- name: String;
72
- message_level: MessageLevel;
73
- meta_data: object | object[];
74
- };
75
-
76
- export type MessageLevel = 'info' | 'debug' | 'warning' | 'error' | 'critical';
@@ -1,9 +0,0 @@
1
- import { CLIENT_VERSION } from '../env';
2
-
3
- export function assert(value: any, message: string, debug: boolean) {
4
- if (debug && !value) {
5
- console.error(`Flare JavaScript client v${CLIENT_VERSION}: ${message}`);
6
- }
7
-
8
- return !!value;
9
- }
@@ -1,11 +0,0 @@
1
- import { assert } from './assert';
2
-
3
- export function assertKey(key: unknown, debug: boolean): boolean {
4
- return assert(
5
- key,
6
- 'The client was not yet initialised with an API key. ' +
7
- "Run client.light('<flare-project-key>') when you initialise your app. " +
8
- "If you are running in dev mode and didn't run the light command on purpose, you can ignore this error.",
9
- debug
10
- );
11
- }
@@ -1,12 +0,0 @@
1
- import { assert } from './assert';
2
-
3
- export function assertSolutionProvider(solutionProvider: object, debug: boolean): boolean {
4
- return (
5
- assert('canSolve' in solutionProvider, 'A solution provider without a [canSolve] property was added.', debug) &&
6
- assert(
7
- 'getSolutions' in solutionProvider,
8
- 'A solution provider without a [getSolutions] property was added.',
9
- debug
10
- )
11
- );
12
- }
@@ -1,25 +0,0 @@
1
- export function flatJsonStringify(json: object): string {
2
- const ancestors = new WeakSet<object>();
3
- const path: object[] = [];
4
-
5
- return JSON.stringify(json, function (this: object, _key, value) {
6
- if (typeof value !== 'object' || value === null) {
7
- return value;
8
- }
9
-
10
- // Pop ancestors that are no longer on the path to `this`.
11
- while (path.length > 0 && path[path.length - 1] !== this) {
12
- const popped = path.pop()!;
13
- ancestors.delete(popped);
14
- }
15
-
16
- if (ancestors.has(value)) {
17
- return '[Circular]';
18
- }
19
-
20
- ancestors.add(value);
21
- path.push(value);
22
-
23
- return value;
24
- });
25
- }
@@ -1,5 +0,0 @@
1
- export function flattenOnce(array: Array<Array<any>>) {
2
- return array.reduce((flat, toFlatten) => {
3
- return flat.concat(toFlatten);
4
- }, []);
5
- }
@@ -1,17 +0,0 @@
1
- import { V2AttributeValue, V2SpanEvent } from '../api/v2WireTypes';
2
- import { Glow } from '../types';
3
-
4
- // glow.microtime is seconds since epoch with sub-second fraction (see util/now.ts).
5
- // V2SpanEvent.startTimeUnixNano is unix nanoseconds.
6
- export function glowsToEvents(glows: Glow[]): V2SpanEvent[] {
7
- return glows.map((glow) => ({
8
- type: 'php_glow',
9
- startTimeUnixNano: Math.round(glow.microtime * 1_000_000_000),
10
- endTimeUnixNano: null,
11
- attributes: {
12
- 'glow.name': String(glow.name),
13
- 'glow.level': glow.message_level,
14
- 'glow.context': (glow.meta_data ?? {}) as V2AttributeValue,
15
- },
16
- }));
17
- }
package/src/util/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './assert';
2
- export * from './assertKey';
3
- export * from './assertSolutionProvider';
4
- export * from './flatJsonStringify';
5
- export * from './flattenOnce';
6
- export * from './glowsToEvents';
7
- export * from './now';
package/src/util/now.ts DELETED
@@ -1,3 +0,0 @@
1
- export function now(): number {
2
- return Math.round(Date.now() / 1000);
3
- }