@datadog/mobile-react-native 2.11.1 → 2.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-sourcemaps.gradle +5 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +1 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/metro/plugin/debugIdHelper.js +4 -5
- package/lib/commonjs/metro/plugin/debugIdHelper.js.map +1 -1
- package/lib/commonjs/metro/plugin/metroSerializer.js +7 -11
- package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
- package/lib/commonjs/metro/plugin/utils.js +145 -66
- package/lib/commonjs/metro/plugin/utils.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +43 -21
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -2
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/ddBabelUtils.js +120 -0
- package/lib/commonjs/rum/instrumentation/interactionTracking/ddBabelUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +1 -0
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/metro/plugin/debugIdHelper.js +3 -3
- package/lib/module/metro/plugin/debugIdHelper.js.map +1 -1
- package/lib/module/metro/plugin/metroSerializer.js +6 -8
- package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
- package/lib/module/metro/plugin/utils.js +134 -60
- package/lib/module/metro/plugin/utils.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +43 -21
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -2
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/ddBabelUtils.js +113 -0
- package/lib/module/rum/instrumentation/interactionTracking/ddBabelUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/debugIdHelper.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/utils.d.ts +62 -11
- package/lib/typescript/metro/plugin/utils.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts +19 -5
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/ddBabelUtils.d.ts +9 -0
- package/lib/typescript/rum/instrumentation/interactionTracking/ddBabelUtils.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +2 -0
- package/src/index.tsx +3 -1
- package/src/metro/__tests__/__utils__/serializerUtils.ts +6 -4
- package/src/metro/__tests__/metro.test.ts +254 -0
- package/src/metro/metro.d.ts +4 -4
- package/src/metro/plugin/debugIdHelper.ts +3 -3
- package/src/metro/plugin/metroSerializer.ts +8 -9
- package/src/metro/plugin/utils.ts +189 -86
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +83 -33
- package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +2 -2
- package/src/rum/instrumentation/interactionTracking/ddBabelUtils.ts +146 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/utils/telemetry.js +0 -23
- package/lib/commonjs/utils/telemetry.js.map +0 -1
- package/lib/module/utils/telemetry.js +0 -16
- package/lib/module/utils/telemetry.js.map +0 -1
- package/lib/typescript/utils/telemetry.d.ts +0 -7
- package/lib/typescript/utils/telemetry.d.ts.map +0 -1
- package/src/utils/telemetry.ts +0 -17
|
@@ -3,29 +3,75 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
6
|
+
import type baseJSBundle from 'metro/private/DeltaBundler/Serializers/baseJSBundle';
|
|
7
|
+
import type sourceMapString from 'metro/private/DeltaBundler/Serializers/sourceMapString';
|
|
8
|
+
import type bundleToString from 'metro/private/lib/bundleToString';
|
|
9
|
+
import type countLines from 'metro/private/lib/countLines';
|
|
10
10
|
import type CountingSet from 'metro/src/lib/CountingSet';
|
|
11
11
|
import type { ReadOnlyGraph, Module, MixedOutput } from 'metro';
|
|
12
12
|
|
|
13
13
|
import type { DefaultConfigOptions } from './types/expoTypes';
|
|
14
14
|
import type {
|
|
15
15
|
MetroSerializerOutput,
|
|
16
|
-
MetroBundleWithMap
|
|
17
|
-
SourceMapString
|
|
16
|
+
MetroBundleWithMap
|
|
18
17
|
} from './types/metroTypes';
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* Lazy-init
|
|
20
|
+
* Lazy-init cache for modules loaded through `safeRequireDefaultExport`.
|
|
21
|
+
*/
|
|
22
|
+
const lazyLoadedModules: { [key: string]: any } = {};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Lazy-init reference for {@link getSourceMapStringFunction} resolved function.
|
|
26
|
+
*/
|
|
27
|
+
let sourceMapStringFunction: typeof sourceMapString | undefined;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Safely loads and returns the `baseJSBundle` function from Metro's internal modules.
|
|
31
|
+
* Supports multiple Metro versions with different internal paths.
|
|
32
|
+
*/
|
|
33
|
+
export const getBaseJSBundleFunction = (): typeof baseJSBundle =>
|
|
34
|
+
lazyRequireDefaultExport([
|
|
35
|
+
'metro/private/DeltaBundler/Serializers/baseJSBundle',
|
|
36
|
+
'metro/src/DeltaBundler/Serializers/baseJSBundle'
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Safely loads and returns the `countLines` function from Metro's internal modules.
|
|
41
|
+
* Supports multiple Metro versions with different internal paths.
|
|
42
|
+
*/
|
|
43
|
+
export const getCountLinesFunction = (): typeof countLines =>
|
|
44
|
+
lazyRequireDefaultExport([
|
|
45
|
+
'metro/private/lib/countLines',
|
|
46
|
+
'metro/src/lib/countLines'
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Safely loads and returns the `bundleToString` function from Metro's internal modules.
|
|
51
|
+
* Supports multiple Metro versions with different internal paths.
|
|
22
52
|
*/
|
|
23
|
-
|
|
53
|
+
export const getBundleToStringFunction = (): typeof bundleToString =>
|
|
54
|
+
lazyRequireDefaultExport([
|
|
55
|
+
'metro/private/lib/bundleToString',
|
|
56
|
+
'metro/src/lib/bundleToString'
|
|
57
|
+
]);
|
|
24
58
|
|
|
25
59
|
/**
|
|
26
|
-
*
|
|
60
|
+
* CountingSet was added in Metro 0.71.2 - a modified `Set` that only deletes items when the
|
|
61
|
+
* number of `delete(item)` calls matches the number of `add(item)` calls.
|
|
62
|
+
*
|
|
63
|
+
* https://github.com/facebook/metro/commit/fc29a1177f883144674cf85a813b58567f69d545
|
|
27
64
|
*/
|
|
28
|
-
|
|
65
|
+
export const getCreateCountingSetFunction: () => () => CountingSet<string> = () => {
|
|
66
|
+
const CountingSetClass = safeLazyRequireDefaultExport<typeof CountingSet>([
|
|
67
|
+
'metro/private/lib/CountingSet',
|
|
68
|
+
'metro/src/lib/CountingSet'
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
return CountingSetClass
|
|
72
|
+
? () => new CountingSetClass<string>()
|
|
73
|
+
: () => (new Set() as unknown) as CountingSet<string>;
|
|
74
|
+
};
|
|
29
75
|
|
|
30
76
|
/**
|
|
31
77
|
* Lazy-init reference for {@link getDefaultExpoConfig} resolved function.
|
|
@@ -37,6 +83,45 @@ let getDefaultExpoConfigFunc:
|
|
|
37
83
|
) => DefaultConfigOptions)
|
|
38
84
|
| undefined;
|
|
39
85
|
|
|
86
|
+
/**
|
|
87
|
+
* In Metro versions prior to v0.80.10, `sourceMapString` was exported as a default export.
|
|
88
|
+
* Starting with v0.80.10, it became a named export.
|
|
89
|
+
*
|
|
90
|
+
* @returns The resolved `sourceMapString` function, of type {@link sourceMapString}
|
|
91
|
+
*/
|
|
92
|
+
export const getSourceMapStringFunction = (): typeof sourceMapString => {
|
|
93
|
+
if (sourceMapStringFunction) {
|
|
94
|
+
return sourceMapStringFunction;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const sourceMapStringModule = safeRequireDefaultExport([
|
|
98
|
+
'metro/private/DeltaBundler/Serializers/sourceMapString',
|
|
99
|
+
'metro/src/DeltaBundler/Serializers/sourceMapString'
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
if (typeof sourceMapStringModule === 'function') {
|
|
103
|
+
sourceMapStringFunction = sourceMapStringModule as typeof sourceMapString;
|
|
104
|
+
} else if (
|
|
105
|
+
sourceMapStringModule &&
|
|
106
|
+
typeof sourceMapStringModule === 'object' &&
|
|
107
|
+
typeof (sourceMapStringModule as { sourceMapString: any })[
|
|
108
|
+
'sourceMapString'
|
|
109
|
+
] === 'function'
|
|
110
|
+
) {
|
|
111
|
+
sourceMapStringFunction = (sourceMapStringModule as {
|
|
112
|
+
sourceMapString: typeof sourceMapString;
|
|
113
|
+
}).sourceMapString;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!sourceMapStringFunction) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"[DATADOG METRO PLUGIN] Unexpected error: Cannot resolve sourceMapString function from Metro's internal modules."
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return sourceMapStringFunction;
|
|
123
|
+
};
|
|
124
|
+
|
|
40
125
|
/**
|
|
41
126
|
* This function ensures that modules in source maps are sorted in the same
|
|
42
127
|
* order as in a plain JS bundle.
|
|
@@ -60,71 +145,6 @@ export function getSortedModules(
|
|
|
60
145
|
);
|
|
61
146
|
}
|
|
62
147
|
|
|
63
|
-
/**
|
|
64
|
-
* CountingSet was added in Metro 0.71.2 - a modified `Set` that only deletes items when the
|
|
65
|
-
* number of `delete(item)` calls matches the number of `add(item)` calls.
|
|
66
|
-
*
|
|
67
|
-
* https://github.com/facebook/metro/commit/fc29a1177f883144674cf85a813b58567f69d545
|
|
68
|
-
*/
|
|
69
|
-
export const createCountingSet = () => {
|
|
70
|
-
if (createCountingSetFunc) {
|
|
71
|
-
return createCountingSetFunc();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
createCountingSetFunc = () => {
|
|
76
|
-
const {
|
|
77
|
-
default: MetroCountingSet
|
|
78
|
-
// eslint-disable-next-line global-require, import/no-extraneous-dependencies, @typescript-eslint/no-var-requires
|
|
79
|
-
} = require('metro/src/lib/CountingSet');
|
|
80
|
-
return new MetroCountingSet();
|
|
81
|
-
};
|
|
82
|
-
} catch (_) {
|
|
83
|
-
createCountingSetFunc = () =>
|
|
84
|
-
(new Set() as unknown) as CountingSet<string>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return createCountingSetFunc();
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* In Metro versions prior to v0.80.10, `sourceMapString` was exported as a default export.
|
|
91
|
-
* Starting with v0.80.10, it became a named export.
|
|
92
|
-
*
|
|
93
|
-
* @returns The resolved `sourceMapString` function, of type {@link SourceMapString}
|
|
94
|
-
*/
|
|
95
|
-
export const metroSourceMapString: SourceMapString = (
|
|
96
|
-
modules: Module<MixedOutput>[],
|
|
97
|
-
options: {
|
|
98
|
-
excludeSource?: boolean;
|
|
99
|
-
processModuleFilter?: (module: Module<MixedOutput>) => boolean;
|
|
100
|
-
shouldAddToIgnoreList?: (module: Module<MixedOutput>) => boolean;
|
|
101
|
-
}
|
|
102
|
-
): string => {
|
|
103
|
-
if (sourceMapStringFunc) {
|
|
104
|
-
return sourceMapStringFunc(modules, options);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (typeof sourceMapString === 'function') {
|
|
108
|
-
sourceMapStringFunc = sourceMapString;
|
|
109
|
-
} else if (
|
|
110
|
-
sourceMapString &&
|
|
111
|
-
typeof sourceMapString === 'object' &&
|
|
112
|
-
typeof sourceMapString['sourceMapString'] === 'function'
|
|
113
|
-
) {
|
|
114
|
-
sourceMapStringFunc = (sourceMapString as {
|
|
115
|
-
sourceMapString: SourceMapString;
|
|
116
|
-
}).sourceMapString;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!sourceMapStringFunc) {
|
|
120
|
-
throw new Error(
|
|
121
|
-
"[DATADOG METRO PLUGIN] Cannot find sourceMapString function in 'metro/src/DeltaBundler/Serializers/sourceMapString'"
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return sourceMapStringFunc(modules, options);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
148
|
/**
|
|
129
149
|
* Converts the serializer result of type {@link MetroSerializerOutput} to {@link MetroBundleWithMap}.
|
|
130
150
|
*/
|
|
@@ -160,18 +180,101 @@ export const getDefaultExpoConfig = (
|
|
|
160
180
|
projectRoot: string,
|
|
161
181
|
options: DefaultConfigOptions
|
|
162
182
|
): DefaultConfigOptions => {
|
|
163
|
-
if (
|
|
183
|
+
if (getDefaultExpoConfigFunc) {
|
|
184
|
+
return getDefaultExpoConfigFunc(projectRoot, options);
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
188
|
+
const metroConfig = require('expo/metro-config');
|
|
189
|
+
getDefaultExpoConfigFunc = metroConfig.getDefaultConfig;
|
|
190
|
+
return metroConfig.getDefaultConfig(projectRoot, options);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
'Cannot load `expo/metro-config`. Make sure Expo is properly set up in your project.'
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Safely requires a module from multiple possible paths, returning its default export if found.
|
|
200
|
+
* Caches the result to avoid redundant requires.
|
|
201
|
+
* Useful for supporting multiple Metro versions with different internal paths.
|
|
202
|
+
* @param modulePaths The list of possible module paths to try.
|
|
203
|
+
* @returns the default export of the first successfully required module.
|
|
204
|
+
* @throws if none of the module paths could be resolved.
|
|
205
|
+
*/
|
|
206
|
+
export const lazyRequireDefaultExport = <T>(modulePaths: string[]): T => {
|
|
207
|
+
const resolvedModule = safeLazyRequireDefaultExport<T>(modulePaths);
|
|
208
|
+
if (!resolvedModule) {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`[DATADOG METRO PLUGIN] Unexpected error: cannot find module in any of the following paths: ${modulePaths.join(
|
|
211
|
+
', '
|
|
212
|
+
)}`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
return resolvedModule;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Safely requires a module from multiple possible paths, returning its default export if found.
|
|
220
|
+
* Caches the result to avoid redundant requires.
|
|
221
|
+
* Useful for supporting multiple Metro versions with different internal paths.
|
|
222
|
+
* @param modulePaths The list of possible module paths to try.
|
|
223
|
+
* @returns the default export of the first successfully required module, or `undefined` if none could be resolved.
|
|
224
|
+
*/
|
|
225
|
+
export const safeLazyRequireDefaultExport = <T>(
|
|
226
|
+
modulePaths: string[]
|
|
227
|
+
): T | undefined => {
|
|
228
|
+
const cacheKey = modulePaths.join('|');
|
|
229
|
+
if (lazyLoadedModules[cacheKey]) {
|
|
230
|
+
return lazyLoadedModules[cacheKey] as T;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const resolvedModule = safeRequireDefaultExport<T>(modulePaths);
|
|
234
|
+
|
|
235
|
+
lazyLoadedModules[cacheKey] = resolvedModule;
|
|
236
|
+
return resolvedModule;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Safely requires a module from multiple possible paths, returning its default export if found.
|
|
241
|
+
* Useful for supporting multiple Metro versions with different internal paths.
|
|
242
|
+
* @param modulePaths The list of possible module paths to try.
|
|
243
|
+
* @returns the default export of the first successfully required module, or `undefined` if none could be resolved.
|
|
244
|
+
*/
|
|
245
|
+
export function safeRequireDefaultExport<T>(
|
|
246
|
+
modulePaths: string[]
|
|
247
|
+
): T | undefined {
|
|
248
|
+
let resolvedModule: T | undefined;
|
|
249
|
+
for (const modulePath of modulePaths) {
|
|
164
250
|
try {
|
|
165
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
251
|
+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies, @typescript-eslint/no-var-requires, import/no-dynamic-require
|
|
252
|
+
const mod = require(modulePath);
|
|
253
|
+
const defaultExport = getDefaultExport<T>(mod);
|
|
254
|
+
if (defaultExport) {
|
|
255
|
+
return defaultExport;
|
|
256
|
+
}
|
|
257
|
+
} catch (_) {
|
|
258
|
+
// Try next path
|
|
173
259
|
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return resolvedModule;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Safely extracts the default export from a module, if it exists.
|
|
267
|
+
* Useful for supporting both CommonJS and ESM-syntax exports.
|
|
268
|
+
* Supports upcoming Metro v0.83.2 https://github.com/facebook/metro/commit/5d301d7177af455fc6a94a0ba464639677cdf4b4.
|
|
269
|
+
*/
|
|
270
|
+
export function getDefaultExport<T>(module: { default: T } | T): T | undefined {
|
|
271
|
+
if (!module) {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (typeof module === 'object' && 'default' in module) {
|
|
276
|
+
return module.default as T;
|
|
174
277
|
} else {
|
|
175
|
-
return
|
|
278
|
+
return module as T;
|
|
176
279
|
}
|
|
177
|
-
}
|
|
280
|
+
}
|
|
@@ -4,13 +4,10 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { InternalLog } from '../../../InternalLog';
|
|
8
|
-
import { SdkVerbosity } from '../../../SdkVerbosity';
|
|
9
|
-
import DdNativeRum from '../../../specs/NativeDdRum';
|
|
10
7
|
import DdSdk from '../../../specs/NativeDdSdk';
|
|
11
|
-
import { getBabelTelemetryConfig } from '../../../utils/telemetry';
|
|
12
8
|
import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
|
|
13
9
|
import type { TimeProvider } from '../../../utils/time-provider/TimeProvider';
|
|
10
|
+
import type { DdRum } from '../../DdRum';
|
|
14
11
|
import { BABEL_PLUGIN_TELEMETRY } from '../../constants';
|
|
15
12
|
import type { RumActionType } from '../../types';
|
|
16
13
|
import { ActionSource } from '../../types';
|
|
@@ -26,10 +23,13 @@ type BabelConfig = {
|
|
|
26
23
|
};
|
|
27
24
|
|
|
28
25
|
type TargetObject = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
getContent: (() => string[]) | undefined;
|
|
27
|
+
options: { useContent: boolean; useNamePrefix: boolean };
|
|
28
|
+
handlerArgs: any[];
|
|
29
|
+
componentName: string;
|
|
30
|
+
'dd-action-name': string[];
|
|
31
|
+
accessibilityLabel: string[];
|
|
32
|
+
[key: string]: any;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export class DdBabelInteractionTracking {
|
|
@@ -44,26 +44,47 @@ export class DdBabelInteractionTracking {
|
|
|
44
44
|
|
|
45
45
|
private telemetrySent: boolean = false;
|
|
46
46
|
|
|
47
|
+
private ddRum: typeof DdRum | null = null;
|
|
48
|
+
|
|
47
49
|
isInitialized: boolean = false;
|
|
48
50
|
|
|
49
|
-
private constructor() {
|
|
51
|
+
private constructor(ddRum?: typeof DdRum) {
|
|
50
52
|
if (DdBabelInteractionTracking.instance) {
|
|
51
53
|
throw new Error(StateErrors.ALREADY_INITIALIZED);
|
|
52
54
|
}
|
|
53
55
|
|
|
56
|
+
if (ddRum) {
|
|
57
|
+
this.ddRum = ddRum;
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
DdBabelInteractionTracking.instance = this;
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
static getInstance() {
|
|
63
|
+
static getInstance(ddRum?: typeof DdRum) {
|
|
58
64
|
if (!DdBabelInteractionTracking.instance) {
|
|
59
|
-
DdBabelInteractionTracking.instance = new DdBabelInteractionTracking(
|
|
65
|
+
DdBabelInteractionTracking.instance = new DdBabelInteractionTracking(
|
|
66
|
+
ddRum
|
|
67
|
+
);
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
return DdBabelInteractionTracking.instance;
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
static getTelemetryConfig() {
|
|
74
|
+
return {
|
|
75
|
+
babel_plugin: {
|
|
76
|
+
enabled: !!globalThis.__DD_RN_BABEL_PLUGIN_ENABLED__,
|
|
77
|
+
track_interactions: !!DdBabelInteractionTracking.config
|
|
78
|
+
.trackInteractions
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
private getTargetName(targetObject: TargetObject) {
|
|
66
84
|
const {
|
|
85
|
+
getContent,
|
|
86
|
+
options,
|
|
87
|
+
handlerArgs,
|
|
67
88
|
componentName,
|
|
68
89
|
'dd-action-name': actionName,
|
|
69
90
|
accessibilityLabel,
|
|
@@ -72,20 +93,44 @@ export class DdBabelInteractionTracking {
|
|
|
72
93
|
|
|
73
94
|
const { useAccessibilityLabel } = DdBabelInteractionTracking.config;
|
|
74
95
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
const tryContent = () => {
|
|
97
|
+
const content = getContent?.();
|
|
98
|
+
if (content && content.length > 0) {
|
|
99
|
+
return content;
|
|
100
|
+
}
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getAccessibilityLabel = () =>
|
|
106
|
+
useAccessibilityLabel && accessibilityLabel
|
|
107
|
+
? accessibilityLabel
|
|
108
|
+
: null;
|
|
109
|
+
|
|
110
|
+
const index = handlerArgs
|
|
111
|
+
? handlerArgs.find(x => typeof x === 'number') || 0
|
|
112
|
+
: 0;
|
|
113
|
+
|
|
114
|
+
// Order: content → actionName → actionNameAttribute → accessibilityLabel
|
|
115
|
+
const selectedContent =
|
|
116
|
+
tryContent() ||
|
|
117
|
+
actionName ||
|
|
118
|
+
Object.values(attrs)[0] ||
|
|
119
|
+
getAccessibilityLabel();
|
|
83
120
|
|
|
84
|
-
if (
|
|
85
|
-
return
|
|
121
|
+
if (!selectedContent) {
|
|
122
|
+
return componentName;
|
|
86
123
|
}
|
|
87
124
|
|
|
88
|
-
|
|
125
|
+
// Fail-safe in case the our 'index' value turns out to not be a real index
|
|
126
|
+
const output =
|
|
127
|
+
index + 1 > selectedContent.length || index < 0
|
|
128
|
+
? selectedContent[0]
|
|
129
|
+
: selectedContent[index];
|
|
130
|
+
|
|
131
|
+
return options.useNamePrefix
|
|
132
|
+
? `${componentName} ("${output}")`
|
|
133
|
+
: output;
|
|
89
134
|
}
|
|
90
135
|
|
|
91
136
|
wrapRumAction(
|
|
@@ -99,7 +144,7 @@ export class DdBabelInteractionTracking {
|
|
|
99
144
|
if (!this.telemetrySent) {
|
|
100
145
|
DdSdk?.sendTelemetryLog(
|
|
101
146
|
BABEL_PLUGIN_TELEMETRY,
|
|
102
|
-
|
|
147
|
+
DdBabelInteractionTracking.getTelemetryConfig(),
|
|
103
148
|
{ onlyOnce: true }
|
|
104
149
|
);
|
|
105
150
|
|
|
@@ -111,17 +156,22 @@ export class DdBabelInteractionTracking {
|
|
|
111
156
|
const { trackInteractions } = DdBabelInteractionTracking.config;
|
|
112
157
|
|
|
113
158
|
if (trackInteractions) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
159
|
+
this.ddRum
|
|
160
|
+
?.addAction(
|
|
161
|
+
action,
|
|
162
|
+
targetName,
|
|
163
|
+
{ '__dd.action_source': ActionSource.BABEL },
|
|
164
|
+
this.timeProvider.now()
|
|
165
|
+
)
|
|
166
|
+
.catch(e => {
|
|
167
|
+
if (e instanceof Error) {
|
|
168
|
+
DdSdk?.telemetryError(
|
|
169
|
+
e.message,
|
|
170
|
+
e.stack || '',
|
|
171
|
+
'BabelActionTrack'
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
125
175
|
}
|
|
126
176
|
|
|
127
177
|
return result;
|
|
@@ -10,9 +10,9 @@ import { InternalLog } from '../../../InternalLog';
|
|
|
10
10
|
import { SdkVerbosity } from '../../../SdkVerbosity';
|
|
11
11
|
import { DdSdk } from '../../../sdk/DdSdk';
|
|
12
12
|
import { getErrorMessage } from '../../../utils/errorUtils';
|
|
13
|
-
import { getBabelTelemetryConfig } from '../../../utils/telemetry';
|
|
14
13
|
import { BABEL_PLUGIN_TELEMETRY } from '../../constants';
|
|
15
14
|
|
|
15
|
+
import { DdBabelInteractionTracking } from './DdBabelInteractionTracking';
|
|
16
16
|
import type { DdEventsInterceptorOptions } from './DdEventsInterceptor';
|
|
17
17
|
import { DdEventsInterceptor } from './DdEventsInterceptor';
|
|
18
18
|
import type { EventsInterceptor } from './EventsInterceptor';
|
|
@@ -74,7 +74,7 @@ export class DdRumUserInteractionTracking {
|
|
|
74
74
|
|
|
75
75
|
DdSdk?.sendTelemetryLog(
|
|
76
76
|
BABEL_PLUGIN_TELEMETRY,
|
|
77
|
-
|
|
77
|
+
DdBabelInteractionTracking.getTelemetryConfig(),
|
|
78
78
|
{ onlyOnce: true }
|
|
79
79
|
);
|
|
80
80
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type ExtractChild =
|
|
4
|
+
| string
|
|
5
|
+
| number
|
|
6
|
+
| boolean
|
|
7
|
+
| React.ReactElement
|
|
8
|
+
| Iterable<React.ReactNode>
|
|
9
|
+
| React.ReactPortal;
|
|
10
|
+
|
|
11
|
+
const LABEL_PROPS = ['children', 'label', 'title', 'text'];
|
|
12
|
+
|
|
13
|
+
const normalize = (s: string) => s.replace(/\s+/g, ' ').trim();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extracts readable text from arbitrary values commonly found in React trees.
|
|
17
|
+
*
|
|
18
|
+
* @param node - Any value: primitives, arrays, iterables, functions, or React elements.
|
|
19
|
+
* @param prefer - Optional list of preferred values (e.g., title/label) to attempt first.
|
|
20
|
+
* @returns Array of strings.
|
|
21
|
+
*/
|
|
22
|
+
export function __ddExtractText(node: any, prefer?: any[]): string[] {
|
|
23
|
+
// If caller provided preferred values (title/label/etc.), use those first.
|
|
24
|
+
if (Array.isArray(prefer)) {
|
|
25
|
+
const preferred = prefer
|
|
26
|
+
.flatMap(v => __ddExtractText(v)) // recurse so expressions/arrays work
|
|
27
|
+
.map(normalize)
|
|
28
|
+
.filter(Boolean);
|
|
29
|
+
|
|
30
|
+
if (preferred.length) {
|
|
31
|
+
return preferred;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Base cases
|
|
36
|
+
if (node == null || typeof node === 'boolean') {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof node === 'string' || typeof node === 'number') {
|
|
41
|
+
return [normalize(String(node))];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Arrays / iterables → flatten results (don’t concatenate yet)
|
|
45
|
+
if (Array.isArray(node)) {
|
|
46
|
+
return node
|
|
47
|
+
.flatMap(x => __ddExtractText(x))
|
|
48
|
+
.map(normalize)
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof node === 'object' && Symbol.iterator in node) {
|
|
53
|
+
return Array.from(node as Iterable<any>)
|
|
54
|
+
.flatMap(x => __ddExtractText(x))
|
|
55
|
+
.map(normalize)
|
|
56
|
+
.filter(Boolean);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Zero-arg render prop
|
|
60
|
+
if (typeof node === 'function' && node.length === 0) {
|
|
61
|
+
try {
|
|
62
|
+
return __ddExtractText(node());
|
|
63
|
+
} catch {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// React elements
|
|
69
|
+
if (React.isValidElement(node)) {
|
|
70
|
+
const props: any = (node as any).props ?? {};
|
|
71
|
+
|
|
72
|
+
// If the element itself has a direct label-ish prop, prefer it.
|
|
73
|
+
for (const propKey of LABEL_PROPS) {
|
|
74
|
+
if (propKey === 'children') {
|
|
75
|
+
continue; // handle children below
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const propValue = props[propKey];
|
|
79
|
+
if (propValue != null) {
|
|
80
|
+
const got = __ddExtractText(propValue)
|
|
81
|
+
.map(normalize)
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
|
|
84
|
+
if (got.length) {
|
|
85
|
+
return got;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Inspect children. Decide whether to return ONE joined label or MANY.
|
|
91
|
+
const rawChildData = (Array.isArray(props.children)
|
|
92
|
+
? props.children
|
|
93
|
+
: [props.children]) as ExtractChild[];
|
|
94
|
+
|
|
95
|
+
const children = rawChildData.filter(c => c != null && c !== false);
|
|
96
|
+
|
|
97
|
+
if (children.length === 0) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Extract each child to a list of strings (not joined)
|
|
102
|
+
const perChild = children.map(child => __ddExtractText(child));
|
|
103
|
+
|
|
104
|
+
// Heuristic: treat as *compound* if multiple children look like “items”
|
|
105
|
+
// e.g., at least two direct children have a label-ish prop or yield non-empty text individually.
|
|
106
|
+
let labeledChildCount = 0;
|
|
107
|
+
children.forEach((child, i) => {
|
|
108
|
+
let hasLabelProp = false;
|
|
109
|
+
|
|
110
|
+
if (React.isValidElement(child)) {
|
|
111
|
+
const childProps: any = (child as any).props ?? {};
|
|
112
|
+
hasLabelProp = LABEL_PROPS.some(k => childProps?.[k] != null);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const childTextCount = perChild[i].filter(Boolean).length;
|
|
116
|
+
if (hasLabelProp || childTextCount > 0) {
|
|
117
|
+
labeledChildCount++;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const flat = perChild.flat().map(normalize).filter(Boolean);
|
|
122
|
+
|
|
123
|
+
// If there are multiple *direct* labelled children, return many (compound).
|
|
124
|
+
// Otherwise, return a single joined label.
|
|
125
|
+
if (labeledChildCount > 1) {
|
|
126
|
+
// De-duplicate while preserving order
|
|
127
|
+
const seen = new Set<string>();
|
|
128
|
+
const out: string[] = [];
|
|
129
|
+
|
|
130
|
+
for (const str of flat) {
|
|
131
|
+
const key = str;
|
|
132
|
+
if (!seen.has(key)) {
|
|
133
|
+
seen.add(key);
|
|
134
|
+
out.push(str);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Not “compound”: join everything into one readable string
|
|
141
|
+
const joined = normalize(flat.join(' '));
|
|
142
|
+
return joined ? [joined] : [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return [];
|
|
146
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '2.
|
|
2
|
+
export const version = '2.12.1';
|