forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationDefaultsPlugin.ts
More file actions
31 lines (27 loc) · 1015 Bytes
/
ConfigurationDefaultsPlugin.ts
File metadata and controls
31 lines (27 loc) · 1015 Bytes
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
import { Utils } from '../../Utils';
import { EventPluginContext } from '../EventPluginContext';
import { IEventPlugin } from '../IEventPlugin';
export class ConfigurationDefaultsPlugin implements IEventPlugin {
public priority: number = 10;
public name: string = 'ConfigurationDefaultsPlugin';
public run(context: EventPluginContext, next?: () => void): void {
const config = context.client.config;
const defaultTags: string[] = config.defaultTags || [];
for (const tag of defaultTags) {
if (!!tag && context.event.tags.indexOf(tag) < 0) {
context.event.tags.push(tag);
}
}
// tslint:disable-next-line:ban-types
const defaultData: Object = config.defaultData || {};
for (const key in defaultData) {
if (!!defaultData[key]) {
const result = JSON.parse(Utils.stringify(defaultData[key], config.dataExclusions));
if (!Utils.isEmpty(result)) {
context.event.data[key] = result;
}
}
}
next && next();
}
}