-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathinit.js
177 lines (169 loc) · 6.21 KB
/
init.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { FEATURE_FLAGS } from '../../features/generic_events/constants'
import { isValidSelector } from '../dom/query-selector'
import { DEFAULT_EXPIRES_MS, DEFAULT_INACTIVE_MS } from '../session/constants'
import { warn } from '../util/console'
import { getNREUMInitializedAgent } from '../window/nreum'
import { getModeledObject } from './configurable'
/**
* @typedef {import('./init-types').Init} Init
*/
const nrMask = '[data-nr-mask]'
/**
* @returns {Init} the default configuration object
*/
const model = () => {
const hiddenState = {
feature_flags: [],
experimental: {
marks: false,
measures: false,
resources: false
},
mask_selector: '*',
block_selector: '[data-nr-block]',
mask_input_options: {
color: false,
date: false,
'datetime-local': false,
email: false,
month: false,
number: false,
range: false,
search: false,
tel: false,
text: false,
time: false,
url: false,
week: false,
// unify textarea and select element with text input
textarea: false,
select: false,
password: true // This will be enforced to always be true in the setter
}
}
return {
ajax: { deny_list: undefined, block_internal: true, enabled: true, autoStart: true },
api: {
allow_registered_children: true,
duplicate_registered_data: false
},
distributed_tracing: {
enabled: undefined,
exclude_newrelic_header: undefined,
cors_use_newrelic_header: undefined,
cors_use_tracecontext_headers: undefined,
allowed_origins: undefined
},
get feature_flags () { return hiddenState.feature_flags },
set feature_flags (val) { hiddenState.feature_flags = val },
generic_events: { enabled: true, autoStart: true },
harvest: { interval: 30 },
jserrors: { enabled: true, autoStart: true },
logging: { enabled: true, autoStart: true },
metrics: { enabled: true, autoStart: true },
obfuscate: undefined,
page_action: { enabled: true },
page_view_event: { enabled: true, autoStart: true },
page_view_timing: { enabled: true, autoStart: true },
performance: {
get capture_marks () { return hiddenState.feature_flags.includes(FEATURE_FLAGS.MARKS) || hiddenState.experimental.marks },
set capture_marks (val) { hiddenState.experimental.marks = val },
get capture_measures () { return hiddenState.feature_flags.includes(FEATURE_FLAGS.MEASURES) || hiddenState.experimental.measures },
set capture_measures (val) { hiddenState.experimental.measures = val },
capture_detail: true,
resources: {
get enabled () { return hiddenState.feature_flags.includes(FEATURE_FLAGS.RESOURCES) || hiddenState.experimental.resources },
set enabled (val) { hiddenState.experimental.resources = val },
asset_types: [],
first_party_domains: [],
ignore_newrelic: true
}
},
privacy: { cookies_enabled: true },
proxy: {
assets: undefined,
beacon: undefined
},
session: {
expiresMs: DEFAULT_EXPIRES_MS,
inactiveMs: DEFAULT_INACTIVE_MS
},
session_replay: {
autoStart: true,
enabled: false,
preload: false,
sampling_rate: 10,
error_sampling_rate: 100,
collect_fonts: false,
inline_images: false,
fix_stylesheets: true,
// recording config settings
mask_all_inputs: true,
// this has a getter/setter to facilitate validation of the selectors
get mask_text_selector () { return hiddenState.mask_selector },
set mask_text_selector (val) {
if (isValidSelector(val)) hiddenState.mask_selector = `${val},${nrMask}`
else if (val === '' || val === null) hiddenState.mask_selector = nrMask
else warn(5, val)
},
// these properties only have getters because they are enforcable constants and should error if someone tries to override them
get block_class () { return 'nr-block' },
get ignore_class () { return 'nr-ignore' },
get mask_text_class () { return 'nr-mask' },
// props with a getter and setter are used to extend enforcable constants with customer input
// we must preserve data-nr-block no matter what else the customer sets
get block_selector () {
return hiddenState.block_selector
},
set block_selector (val) {
if (isValidSelector(val)) hiddenState.block_selector += `,${val}`
else if (val !== '') warn(6, val)
},
// password: must always be present and true no matter what customer sets
get mask_input_options () {
return hiddenState.mask_input_options
},
set mask_input_options (val) {
if (val && typeof val === 'object') hiddenState.mask_input_options = { ...val, password: true }
else warn(7, val)
}
},
session_trace: { enabled: true, autoStart: true },
soft_navigations: { enabled: true, autoStart: true },
spa: { enabled: true, autoStart: true },
ssl: undefined,
user_actions: { enabled: true, elementAttributes: ['id', 'className', 'tagName', 'type'] }
}
}
const _cache = {}
const missingAgentIdError = 'All configuration objects require an agent identifier!'
export function getConfiguration (id) {
if (!id) throw new Error(missingAgentIdError)
if (!_cache[id]) throw new Error(`Configuration for ${id} was never set`)
return _cache[id]
}
export function setConfiguration (id, obj) {
if (!id) throw new Error(missingAgentIdError)
_cache[id] = getModeledObject(obj, model())
const agentInst = getNREUMInitializedAgent(id)
if (agentInst) agentInst.init = _cache[id]
}
export function getConfigurationValue (id, path) {
if (!id) throw new Error(missingAgentIdError)
var val = getConfiguration(id)
if (val) {
var parts = path.split('.')
for (var i = 0; i < parts.length - 1; i++) {
val = val[parts[i]]
if (typeof val !== 'object') return
}
val = val[parts[parts.length - 1]]
}
return val
}
// TO DO: a setConfigurationValue equivalent may be nice so individual
// properties can be tuned instead of reseting the whole model per call to `setConfiguration(agentIdentifier, {})`