Skip to content

Commit febd0bb

Browse files
committed
fix: format and lint
1 parent 82927c8 commit febd0bb

13 files changed

+70
-74
lines changed

packages/rum-core/src/domain/action/actionCollection.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createHooks } from '../hooks'
1111
import type { RumMutationRecord } from '../../browser/domMutationObservable'
1212
import type { ActionContexts } from './actionCollection'
1313
import { startActionCollection } from './actionCollection'
14-
import { ActionNameSource } from './getActionNameFromElement'
14+
import { ActionNameSource } from './actionNameConstants'
1515

1616
describe('actionCollection', () => {
1717
const lifeCycle = new LifeCycle()

packages/rum-core/src/domain/action/actionCollection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export function startActionCollection(
3131
windowOpenObservable: Observable<void>,
3232
configuration: RumConfiguration
3333
) {
34-
3534
const { unsubscribe: unsubscribeAutoActionCompleted } = lifeCycle.subscribe(
3635
LifeCycleEventType.AUTO_ACTION_COMPLETED,
3736
(action) => {
@@ -74,7 +73,7 @@ export function startActionCollection(
7473
lifeCycle,
7574
domMutationObservable,
7675
windowOpenObservable,
77-
configuration,
76+
configuration
7877
))
7978
}
8079

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Get the action name from the attribute 'data-dd-action-name' on the element or any of its parent.
3+
* It can also be retrieved from a user defined attribute.
4+
*/
5+
export const DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE = 'data-dd-action-name'
6+
export const ACTION_NAME_PLACEHOLDER = 'Masked Element'
7+
export const enum ActionNameSource {
8+
CUSTOM_ATTRIBUTE = 'custom_attribute',
9+
MASK_PLACEHOLDER = 'mask_placeholder',
10+
TEXT_CONTENT = 'text_content',
11+
STANDARD_ATTRIBUTE = 'standard_attribute',
12+
BLANK = 'blank',
13+
MASK_DISALLOWED = 'mask_disallowed',
14+
}
15+
export interface ActionName {
16+
name: string
17+
nameSource: ActionNameSource
18+
}

packages/rum-core/src/domain/action/getActionNameFromElement.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { appendElement, mockRumConfiguration } from '../../../test'
22
import { NodePrivacyLevel } from '../privacyConstants'
3-
import { ActionNameSource, getActionNameFromElement } from './getActionNameFromElement'
3+
import { getActionNameFromElement } from './getActionNameFromElement'
4+
import { ActionNameSource } from './actionNameConstants'
45

56
const defaultConfiguration = mockRumConfiguration()
67

packages/rum-core/src/domain/action/getActionNameFromElement.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,12 @@ import { safeTruncate } from '@datadog/browser-core'
22
import { NodePrivacyLevel, getPrivacySelector } from '../privacyConstants'
33
import type { RumConfiguration } from '../configuration'
44
import { maskActionName } from './privacy/allowedDictionary'
5-
6-
/**
7-
* Get the action name from the attribute 'data-dd-action-name' on the element or any of its parent.
8-
* It can also be retrieved from a user defined attribute.
9-
*/
10-
export const DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE = 'data-dd-action-name'
11-
export const ACTION_NAME_PLACEHOLDER = 'Masked Element'
12-
export const enum ActionNameSource {
13-
CUSTOM_ATTRIBUTE = 'custom_attribute',
14-
MASK_PLACEHOLDER = 'mask_placeholder',
15-
TEXT_CONTENT = 'text_content',
16-
STANDARD_ATTRIBUTE = 'standard_attribute',
17-
BLANK = 'blank',
18-
MASK_DISALLOWED = 'mask_disallowed',
19-
}
20-
export type ActionName = {
21-
name: string
22-
nameSource: ActionNameSource
23-
}
5+
import {
6+
ActionNameSource,
7+
DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE,
8+
ACTION_NAME_PLACEHOLDER,
9+
} from './actionNameConstants'
10+
import type { ActionName } from './actionNameConstants'
2411

2512
export function getActionNameFromElement(
2613
element: Element,
@@ -50,19 +37,19 @@ export function getActionNameFromElement(
5037
userProgrammaticAttribute,
5138
priorityStrategies,
5239
nodePrivacyLevel || NodePrivacyLevel.MASK_USER_INPUT,
53-
enablePrivacyForActionName,
40+
enablePrivacyForActionName
5441
) ||
5542
getActionNameFromElementForStrategies(
5643
element,
5744
userProgrammaticAttribute,
5845
fallbackStrategies,
5946
nodePrivacyLevel || NodePrivacyLevel.MASK_USER_INPUT,
60-
enablePrivacyForActionName,
47+
enablePrivacyForActionName
6148
) || { name: '', nameSource: ActionNameSource.BLANK }
6249
)
6350
}
6451

65-
function getActionNameFromElementProgrammatically(targetElement: Element, programmaticAttribute: string, nodeSelfPrivacy?: NodePrivacyLevel) {
52+
function getActionNameFromElementProgrammatically(targetElement: Element, programmaticAttribute: string) {
6653
// We don't use getActionNameFromElementForStrategies here, because we want to consider all parents,
6754
// without limit. It is up to the user to declare a relevant naming strategy.
6855
const elementWithAttribute = targetElement.closest(`[${programmaticAttribute}]`)
@@ -146,7 +133,7 @@ function getActionNameFromElementForStrategies(
146133
userProgrammaticAttribute: string | undefined,
147134
strategies: NameStrategy[],
148135
nodeSelfPrivacy: NodePrivacyLevel,
149-
enablePrivacyForActionName?: boolean,
136+
enablePrivacyForActionName?: boolean
150137
) {
151138
let element: Element | null = targetElement
152139
let recursionCounter = 0
@@ -160,7 +147,9 @@ function getActionNameFromElementForStrategies(
160147
for (const strategy of strategies) {
161148
const actionName = strategy(element, userProgrammaticAttribute, enablePrivacyForActionName)
162149
if (actionName) {
163-
const { name, nameSource } = enablePrivacyForActionName ? actionName : maskActionName(actionName, nodeSelfPrivacy)
150+
const { name, nameSource } = enablePrivacyForActionName
151+
? actionName
152+
: maskActionName(actionName, nodeSelfPrivacy)
164153
const trimmedName = name && name.trim()
165154
if (trimmedName) {
166155
return { name: truncate(normalizeWhitespace(trimmedName)), nameSource }

packages/rum-core/src/domain/action/privacy/allowedDictionary.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { ActionType } from '../../../rawRumEvent.types'
22
import { NodePrivacyLevel } from '../../privacyConstants'
3-
import { ActionNameSource } from '../getActionNameFromElement'
3+
import { ActionNameSource } from '../actionNameConstants'
44
import type { ClickActionBase } from '../trackClickActions'
5-
import {
6-
maskActionName,
7-
} from './allowedDictionary'
5+
import { maskActionName } from './allowedDictionary'
86

97
const TEST_STRINGS = {
108
COMPLEX_MIXED: 'test-team-name:💥$$$',
11-
PARAGRAPH_MIXED: "✅ This is an action name in allowlist",
9+
PARAGRAPH_MIXED: '✅ This is an action name in allowlist',
1210
}
1311

14-
1512
describe('createActionNameDictionary and maskActionName', () => {
1613
const clickActionBase: ClickActionBase = {
1714
type: ActionType.CLICK,
@@ -42,7 +39,7 @@ describe('createActionNameDictionary and maskActionName', () => {
4239
})
4340

4441
it('masks words not in allowlist (with dictionary from $DD_ALLOW)', () => {
45-
clickActionBase.name = "This is an action name in allowlist"
42+
clickActionBase.name = 'This is an action name in allowlist'
4643
const testString1 = maskActionName(clickActionBase, NodePrivacyLevel.MASK)
4744
expect(testString1.name).toBe('Masked Element')
4845
expect(testString1.nameSource).toBe(ActionNameSource.MASK_DISALLOWED)

packages/rum-core/src/domain/action/privacy/allowedDictionary.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
11
import { NodePrivacyLevel, TEXT_MASKING_CHAR } from '../../privacyConstants'
2-
import { ACTION_NAME_PLACEHOLDER, ActionName, ActionNameSource } from '../getActionNameFromElement'
2+
import { ACTION_NAME_PLACEHOLDER, ActionNameSource } from '../actionNameConstants'
3+
import type { ActionName } from '../actionNameConstants'
34

45
declare global {
56
interface Window {
67
$DD_ALLOW?: Set<string>
78
}
89
}
910

10-
export function maskTextContent(
11-
text: string,
12-
fixedMask?: string,
13-
): { maskedText: string; hasBeenMasked: boolean } {
11+
export function maskTextContent(text: string, fixedMask?: string): { maskedText: string; hasBeenMasked: boolean } {
1412
if (!text.trim()) {
1513
return { maskedText: text, hasBeenMasked: false }
1614
}
1715
// We are using toLocaleLowerCase when adding to the allowlist to avoid case sensitivity
18-
if(window.$DD_ALLOW && window.$DD_ALLOW.has(text.toLocaleLowerCase())) {
16+
if (window.$DD_ALLOW && window.$DD_ALLOW.has(text.toLocaleLowerCase())) {
1917
return { maskedText: text, hasBeenMasked: false }
20-
} else {
21-
return { maskedText: fixedMask || text.replace(/\S/g, TEXT_MASKING_CHAR), hasBeenMasked: true }
2218
}
19+
return { maskedText: fixedMask || text.replace(/\S/g, TEXT_MASKING_CHAR), hasBeenMasked: true }
2320
}
2421

25-
export function maskActionName(
26-
actionName: ActionName,
27-
nodeSelfPrivacy: NodePrivacyLevel,
28-
): ActionName {
22+
export function maskActionName(actionName: ActionName, nodeSelfPrivacy: NodePrivacyLevel): ActionName {
2923
if (nodeSelfPrivacy === NodePrivacyLevel.ALLOW || nodeSelfPrivacy === NodePrivacyLevel.MASK_USER_INPUT) {
3024
return actionName
31-
} else if (
32-
nodeSelfPrivacy !== NodePrivacyLevel.MASK_UNLESS_ALLOWLISTED &&
33-
(!window.$DD_ALLOW || !window.$DD_ALLOW.size)
34-
) {
25+
}
26+
if (nodeSelfPrivacy !== NodePrivacyLevel.MASK_UNLESS_ALLOWLISTED && (!window.$DD_ALLOW || !window.$DD_ALLOW.size)) {
3527
return actionName
3628
} // if the privacy level is MASK or MASK_USER_INPUT and the allowlist is present, we continue of masking the action name
29+
3730
const { name, nameSource } = actionName
3831
if (!window.$DD_ALLOW || !window.$DD_ALLOW.size) {
3932
return {

packages/rum-core/src/domain/action/trackClickActions.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { ClickAction } from './trackClickActions'
2121
import { finalizeClicks, trackClickActions } from './trackClickActions'
2222
import { MAX_DURATION_BETWEEN_CLICKS } from './clickChain'
2323
import { getInteractionSelector, CLICK_ACTION_MAX_DURATION } from './interactionSelectorCache'
24-
import { ActionNameSource } from './getActionNameFromElement'
24+
import { ActionNameSource } from './actionNameConstants'
2525

2626
// Used to wait some time after the creation of an action
2727
const BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY = PAGE_ACTIVITY_VALIDATION_DELAY * 0.8
@@ -62,7 +62,7 @@ describe('trackClickActions', () => {
6262
lifeCycle,
6363
domMutationObservable,
6464
windowOpenObservable,
65-
mockRumConfiguration(partialConfig),
65+
mockRumConfiguration(partialConfig)
6666
)
6767

6868
findActionId = trackClickActionsResult.actionContexts.findActionId
@@ -508,8 +508,6 @@ describe('trackClickActions', () => {
508508
expect(findActionId()).not.toBeUndefined()
509509
clock.tick(EXPIRE_DELAY)
510510

511-
console.log('events', events)
512-
513511
expect(events.length).toBe(1)
514512
expect(events[0].name).toBe('Click me')
515513
})

packages/rum-core/src/domain/action/trackClickActions.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type { RumMutationRecord } from '../../browser/domMutationObservable'
2424
import type { ClickChain } from './clickChain'
2525
import { createClickChain } from './clickChain'
2626
import { getActionNameFromElement } from './getActionNameFromElement'
27-
import type { ActionNameSource } from './getActionNameFromElement'
27+
import type { ActionNameSource } from './actionNameConstants'
2828
import type { MouseEventOnElement, UserActivity } from './listenActionEvents'
2929
import { listenActionEvents } from './listenActionEvents'
3030
import { computeFrustration } from './computeFrustration'
@@ -67,7 +67,7 @@ export function trackClickActions(
6767
lifeCycle: LifeCycle,
6868
domMutationObservable: Observable<RumMutationRecord[]>,
6969
windowOpenObservable: Observable<void>,
70-
configuration: RumConfiguration,
70+
configuration: RumConfiguration
7171
) {
7272
const history: ClickActionIdHistory = createValueHistory({ expireDelay: ACTION_CONTEXT_TIME_OUT_DELAY })
7373
const stopObservable = new Observable<void>()
@@ -89,13 +89,7 @@ export function trackClickActions(
8989
hadActivityOnPointerDown: () => boolean
9090
}>(configuration, {
9191
onPointerDown: (pointerDownEvent) =>
92-
processPointerDown(
93-
configuration,
94-
lifeCycle,
95-
domMutationObservable,
96-
pointerDownEvent,
97-
windowOpenObservable,
98-
),
92+
processPointerDown(configuration, lifeCycle, domMutationObservable, pointerDownEvent, windowOpenObservable),
9993
onPointerUp: ({ clickActionBase, hadActivityOnPointerDown }, startEvent, getUserActivity) => {
10094
startClickAction(
10195
configuration,
@@ -147,20 +141,25 @@ function processPointerDown(
147141
lifeCycle: LifeCycle,
148142
domMutationObservable: Observable<RumMutationRecord[]>,
149143
pointerDownEvent: MouseEventOnElement,
150-
windowOpenObservable: Observable<void>,
144+
windowOpenObservable: Observable<void>
151145
) {
152146
const nodeSelfPrivacy = getNodePrivacyLevel(pointerDownEvent.target, configuration.defaultPrivacyLevel)
153147
// If the node privacy level is MASK_UNLESS_ALLOWLISTED, we use the default privacy level
154148
// If the enablePrivacyForActionName is true, we use the node privacy level
155149
// Otherwise, we use the allow level
156150
// TODO: we should make enablePrivacyForActionName true by default for the next major version
157-
const nodePrivacyLevel = nodeSelfPrivacy === NodePrivacyLevel.MASK_UNLESS_ALLOWLISTED ? nodeSelfPrivacy : configuration.enablePrivacyForActionName ? nodeSelfPrivacy : NodePrivacyLevel.ALLOW;
151+
const nodePrivacyLevel =
152+
nodeSelfPrivacy === NodePrivacyLevel.MASK_UNLESS_ALLOWLISTED
153+
? nodeSelfPrivacy
154+
: configuration.enablePrivacyForActionName
155+
? nodeSelfPrivacy
156+
: NodePrivacyLevel.ALLOW
158157

159158
if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
160159
return undefined
161160
}
162161

163-
let clickActionBase = computeClickActionBase(pointerDownEvent, nodePrivacyLevel, configuration)
162+
const clickActionBase = computeClickActionBase(pointerDownEvent, nodePrivacyLevel, configuration)
164163

165164
let hadActivityOnPointerDown = false
166165

packages/rum-core/src/domain/getSelectorFromElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './action/getActionNameFromElement'
1+
import { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './action/actionNameConstants'
22

33
/**
44
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:

0 commit comments

Comments
 (0)