Skip to content

Commit b428db6

Browse files
authored
Merge pull request #14 from codex-team/upd/types-for-js-catcher
chore(catcher): types for js and php catchers added
2 parents 1c00f49 + 69951b0 commit b428db6

File tree

22 files changed

+327
-92
lines changed

22 files changed

+327
-92
lines changed

build/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from "./src/base/event/affectedUser";
55
export * from "./src/base/event/backtraceFrame";
66
export * from "./src/base/event/event";
77
export * from "./src/base/event/sourceCodeLine";
8+
export * from "./src/base/event/addons";
89
export * from "./src/dbScheme/businessOperation";
910
export * from "./src/dbScheme/groupedEvent";
1011
export * from "./src/dbScheme/notificationsChannels";
@@ -21,3 +22,4 @@ export * from "./src/notifications/createProjectNotifications";
2122
export * from "./src/notifications/receiveTypes";
2223
export * from "./src/notifications/updateProjectNotifications";
2324
export * from "./src/notifications/userNotification";
25+
export * from './src/utils';

build/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ __exportStar(require("./src/base/event/affectedUser"), exports);
1717
__exportStar(require("./src/base/event/backtraceFrame"), exports);
1818
__exportStar(require("./src/base/event/event"), exports);
1919
__exportStar(require("./src/base/event/sourceCodeLine"), exports);
20+
__exportStar(require("./src/base/event/addons"), exports);
2021
__exportStar(require("./src/dbScheme/businessOperation"), exports);
2122
__exportStar(require("./src/dbScheme/groupedEvent"), exports);
2223
__exportStar(require("./src/dbScheme/notificationsChannels"), exports);
@@ -33,3 +34,4 @@ __exportStar(require("./src/notifications/createProjectNotifications"), exports)
3334
__exportStar(require("./src/notifications/receiveTypes"), exports);
3435
__exportStar(require("./src/notifications/updateProjectNotifications"), exports);
3536
__exportStar(require("./src/notifications/userNotification"), exports);
37+
__exportStar(require("./src/utils"), exports);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { JavaScriptAddons, WindowData, VueIntegrationAddons } from './javascript';
2+
import { PhpAddons } from './php';
3+
/**
4+
* Union Type describing all catcher-specific additional data
5+
*/
6+
declare type EventAddons = JavaScriptAddons | PhpAddons;
7+
export { JavaScriptAddons, WindowData, VueIntegrationAddons, PhpAddons, EventAddons, };

build/src/base/event/addons/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Json } from '../../../utils';
2+
/**
3+
* Additional data that can be sent by the JavaScript Catcher
4+
*/
5+
export interface JavaScriptAddons {
6+
/**
7+
* Information about the window
8+
*/
9+
window: WindowData;
10+
/**
11+
* User Agent string
12+
*/
13+
userAgent: string;
14+
/**
15+
* Where error happened
16+
*/
17+
url: string;
18+
/**
19+
* Query parameters for the current URL
20+
*/
21+
get?: Json;
22+
/**
23+
* Unparsed error data that can be send by enabling 'debug' option on the catcher side
24+
*/
25+
RAW_EVENT_DATA?: Json;
26+
/**
27+
* Vue integration data
28+
*/
29+
vue?: VueIntegrationAddons;
30+
}
31+
/**
32+
* Information about the window
33+
*/
34+
export interface WindowData {
35+
/**
36+
* Window offset width in pixels
37+
*/
38+
innerWidth: number;
39+
/**
40+
* Window offset height in pixels
41+
*/
42+
innerHeight: number;
43+
}
44+
/**
45+
* Additional data spoiled from Vue app
46+
*/
47+
export interface VueIntegrationAddons {
48+
/**
49+
* A Vue-specific error info, e.g. which lifecycle hook the error was found in.
50+
*/
51+
lifecycle: string;
52+
/**
53+
* Component name where error occurred
54+
*/
55+
component: string;
56+
/**
57+
* Component props
58+
*/
59+
props?: Json;
60+
/**
61+
* Component local variables
62+
*/
63+
data?: Json;
64+
/**
65+
* Component computed variables
66+
*/
67+
computed?: Json;
68+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

build/src/base/event/addons/php.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Json } from '../../../utils';
2+
/**
3+
* This interface represents data that can be additionally collected by PHP Catcher
4+
*/
5+
export interface PhpAddons {
6+
/**
7+
* GET parameters
8+
*/
9+
get?: Json;
10+
/**
11+
* POST parameters
12+
*/
13+
post?: Json;
14+
/**
15+
* HTTP Headers
16+
*/
17+
headers?: Json;
18+
}

build/src/base/event/addons/php.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

build/src/base/event/event.d.ts

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,29 @@
1-
import { BacktraceFrame } from "./backtraceFrame";
2-
import { AffectedUser } from "./affectedUser";
3-
/**
4-
* Represents simple JSON-like document
5-
*/
6-
declare type Dict = {
7-
[key: string]: DictNode;
8-
};
9-
/**
10-
* Represents possible field values in Dict
11-
*/
12-
declare type DictNode = string | number | boolean | Dict;
1+
import { BacktraceFrame } from './backtraceFrame';
2+
import { AffectedUser } from './affectedUser';
3+
import { EventAddons } from './addons';
4+
import { Json } from '../../utils';
135
/**
146
* Information about event
157
* That object will be send as 'payload' to the Collector
168
*/
17-
export interface EventData {
9+
export interface EventData<CatcherAddons extends EventAddons> {
1810
/**
1911
* Event title
2012
*/
2113
title: string;
2214
/**
23-
* Occurrence time
24-
* [!] Must be a Unix timestamp in seconds (example: 1567009247.576)
15+
* Event type (severity level)
2516
*/
26-
timestamp: number;
17+
type?: string;
2718
/**
2819
* Stack
2920
* From the latest call to the earliest
3021
*/
3122
backtrace?: BacktraceFrame[];
32-
/**
33-
* GET parameters
34-
*/
35-
get?: object;
36-
/**
37-
* POST parameters
38-
*/
39-
post?: object;
40-
/**
41-
* Headers map
42-
*/
43-
headers?: object;
4423
/**
4524
* Catcher-specific information
4625
*/
47-
addons?: Dict | string;
26+
addons?: CatcherAddons | string;
4827
/**
4928
* Current release (aka version, revision) of an application
5029
*/
@@ -56,26 +35,38 @@ export interface EventData {
5635
/**
5736
* Any other information collected and passed by user
5837
*/
59-
context?: Dict | string;
38+
context?: EventContext | string;
39+
}
40+
/**
41+
* Event accepted and processed by Collector.
42+
* It sets the timestamp to the event payload.
43+
*/
44+
export interface EventDataAccepted<EventAddons> extends EventData<EventAddons> {
45+
/**
46+
* Occurrence time
47+
* Unix timestamp in seconds (example: 1567009247.576)
48+
* (Set by the Collector)
49+
*/
50+
timestamp: number;
6051
}
6152
/**
6253
* Event data with decoded unsafe fields
6354
*/
64-
export interface DecodedEventData extends EventData {
55+
export interface DecodedEventData<EventAddons> extends EventDataAccepted<EventAddons> {
6556
/**
6657
* Decoded context
6758
*/
68-
context?: Dict;
59+
context?: EventContext;
6960
/**
7061
* Decoded addons
7162
*/
72-
addons?: Dict;
63+
addons?: EventAddons;
7364
}
7465
/**
7566
* Event data with encoded unsafe fields
7667
*
7768
*/
78-
export interface EncodedEventData extends EventData {
69+
export interface EncodedEventData extends EventDataAccepted<EventAddons> {
7970
/**
8071
* Encoded context
8172
*/
@@ -85,4 +76,7 @@ export interface EncodedEventData extends EventData {
8576
*/
8677
addons?: string;
8778
}
88-
export {};
79+
/**
80+
* Context is any additional data sent by developer
81+
*/
82+
export declare type EventContext = Json;

build/src/dbScheme/groupedEvent.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ObjectId } from "mongodb";
2-
import { DecodedEventData, EncodedEventData, EventData } from "../base/event/event";
2+
import { DecodedEventData, EncodedEventData, EventDataAccepted } from "../base/event/event";
33
import { UserDBScheme } from "./user";
4+
import { EventAddons } from '../base/event/addons';
45
/**
56
* Event data after grouper-worker transformation to store it in database
67
*/
@@ -24,7 +25,7 @@ export interface GroupedEventDBScheme {
2425
/**
2526
* Event data
2627
*/
27-
payload: EventData;
28+
payload: EventDataAccepted<EventAddons>;
2829
/**
2930
* How many users catch this error
3031
*/
@@ -38,7 +39,7 @@ export interface GroupedEventDBScheme {
3839
* Grouped event with decoded event data
3940
*/
4041
export interface DecodedGroupedEvent extends GroupedEventDBScheme {
41-
payload: DecodedEventData;
42+
payload: DecodedEventData<EventAddons>;
4243
}
4344
/**
4445
* Grouped event with encoded event data

0 commit comments

Comments
 (0)