-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.ts
65 lines (53 loc) · 1.32 KB
/
events.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
type Primitive = string | number | null | void
interface PrimitiveHash {
[key: string]: Primitive
}
type Attribute = Primitive | Primitive[] | PrimitiveHash | PrimitiveHash[]
export interface Attributes {
[key: string]: Attribute
}
export class AnalyticsEvent {
action: string
attributes: Attributes
constructor(action: string, attributes: Attributes) {
this.action = action
this.attributes = attributes
}
update(attributes: Attributes) {
Object.assign(this.attributes, attributes)
}
getName(): string {
return this.action
}
toJSON() {
return {
action: this.action,
attributes: this.attributes
}
}
}
export class Exception {
error: Error
attributes: Attributes
constructor(error: Error, attributes: Attributes) {
this.error = error
this.attributes = attributes
}
update(attributes: Attributes) {
Object.assign(this.attributes, attributes)
}
getName(): string {
return this.error.name
}
getMessage(): string {
return this.error.message
}
toJSON() {
return {
error: this.error.name,
message: this.error.message,
attributes: this.attributes,
stack: this.error.stack
}
}
}