@dynatrace/react-native-plugin 2.331.1 → 2.335.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.
Files changed (48) hide show
  1. package/README.md +136 -177
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/dynatrace/android/agent/DynatraceRNBridgeImpl.kt +7 -1
  4. package/android/src/main/java/com/dynatrace/android/agent/DynatraceUtils.kt +1 -0
  5. package/android/src/new/java/com/dynatrace/android/agent/DynatraceRNBridge.kt +1 -0
  6. package/android/src/old/java/com/dynatrace/android/agent/DynatraceRNBridge.kt +2 -1
  7. package/files/plugin-runtime.gradle +27 -13
  8. package/files/plugin.gradle +1 -1
  9. package/instrumentation/BabelPluginDynatrace.js +1 -0
  10. package/instrumentation/DynatraceInstrumentation.js +1 -1
  11. package/instrumentation/jsx/CreateElement.js +106 -6
  12. package/instrumentation/jsx/JsxDevRuntime.js +2 -6
  13. package/instrumentation/jsx/JsxRuntime.js +6 -10
  14. package/instrumentation/libs/UserInteraction.js +114 -0
  15. package/instrumentation/libs/community/gesture-handler/Touchables.InstrInfo.js +2 -0
  16. package/instrumentation/libs/community/gesture-handler/Touchables.js +3 -1
  17. package/instrumentation/libs/community/gesture-handler/index.js +3 -1
  18. package/instrumentation/libs/withOnPressMonitoring.js +55 -3
  19. package/ios/DynatraceRNBridge.mm +8 -1
  20. package/lib/core/Application.js +2 -0
  21. package/lib/core/Dynatrace.js +2 -1
  22. package/lib/core/UserPrivacyOptions.js +8 -1
  23. package/lib/core/configuration/ConfigurationHandler.js +21 -0
  24. package/lib/dynatrace-reporter.js +0 -14
  25. package/lib/dynatrace-transformer.js +10 -13
  26. package/lib/features/ui-interaction/Config.js +42 -0
  27. package/lib/features/ui-interaction/IUserInteractionEvent.js +16 -0
  28. package/lib/features/ui-interaction/Plugin.Fragment.Test.js +170 -0
  29. package/lib/features/ui-interaction/Plugin.js +289 -0
  30. package/lib/features/ui-interaction/RootDetection.js +51 -0
  31. package/lib/features/ui-interaction/RootWrapper.js +236 -0
  32. package/lib/features/ui-interaction/Run.js +38 -0
  33. package/lib/features/ui-interaction/Runtime.js +827 -0
  34. package/lib/features/ui-interaction/TouchMetaResolver.js +492 -0
  35. package/lib/features/ui-interaction/Types.js +14 -0
  36. package/lib/next/Dynatrace.js +1 -1
  37. package/lib/next/configuration/INativeRuntimeConfiguration.js +1 -0
  38. package/lib/next/configuration/RuntimeConfigurationObserver.js +47 -12
  39. package/lib/next/events/EventPipeline.js +9 -0
  40. package/package.json +19 -13
  41. package/react-native-dynatrace.podspec +1 -1
  42. package/scripts/Android.js +75 -62
  43. package/scripts/Config.js +12 -1
  44. package/scripts/core/InstrumentCall.js +1 -2
  45. package/scripts/core/LineOffsetAnalyzeCall.js +9 -15
  46. package/src/lib/core/interface/NativeDynatraceBridge.ts +1 -0
  47. package/types.d.ts +22 -9
  48. package/scripts/util/ReactOptions.js +0 -21
@@ -1 +1 @@
1
- var a,n=require("@babel/runtime/helpers/interopRequireDefault"),e=n(require("@babel/runtime/helpers/toConsumableArray")),c=(Object.defineProperty(exports,"t",{value:!0}),exports.instrument=void 0,require("path")),u=require("jscodeshift"),i=require("jscodeshift/src/Collection"),r=require("../scripts/FileOperationHelper"),l=require("../scripts/PathsConstants"),f=require("../lib/core/util/GetValuesFromPackage"),t=require("../scripts/util/InstrumentUtil"),o=require("./libs/react-native/Touchables.InstrInfo"),s=require("./libs/react-native/RefreshControl.InstrInfo"),v=require("./libs/react-native/Switch.InstrInfo"),d=require("./libs/community/gesture-handler/Touchables.InstrInfo"),p=require("./libs/community/Picker.InstrInfo"),m=require("./model/Types"),g=require("./parser/ParserUtil"),y=((n=>{n[n.i=-1]="Filtered",n[n.u=0]="Normal",n[n.o=1]="ReactNative",n[n.l=2]="React",n[n.v=3]="ReactNativeCssInterop"})(a=a||{}),[]),q=(y.push.apply(y,(0,e.default)(o.instrumentationInfo)),y.push.apply(y,(0,e.default)(s.instrumentationInfo)),y.push.apply(y,(0,e.default)(v.instrumentationInfo)),y.push.apply(y,(0,e.default)(d.instrumentationInfo)),y.push.apply(y,(0,e.default)(p.instrumentationInfo)),["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"]),b="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(n,e,r){e=O(e);var t=z(e);if(t!==a.i){var i=!1,u=N(e,n);if(t===a.l)U(u),i=!0;else if(t===a.o)e.endsWith("AppRegistryImpl.js")?null!=r&&r.autoStart&&V(u)&&(i=!0):e.endsWith("AppRegistry.js")?null!=r&&r.autoStart&&w(u)&&(i=!0):e.endsWith("renderApplication.js")?(A(u),i=!0):e.endsWith("ExceptionsManager.js")&&(o=void 0!==r&&r.autoStart&&r.errorHandler.enabled,J(u,r.errorHandler.reportFatalErrorAsCrash,o),i=!0);else if(t===a.v)i=G(u)||i;else{var o=k(e,r);if(r.navigation.enabled&&L(e,u))i=!0;else{if(!o.input&&!o.lifecycle)return null!=r&&r.debug&&console.log("Dynatrace - Filtered All: ".concat(e)),I(e),n;o.lifecycle&&A(u)&&(i=!0),o.input&&y.forEach(function(n){n=X(u,n);u=n.root,i=i||n.p})}}i?(n=u.toSource({quote:"single"}),h(n,e)):I(e),null!=r&&r.debug&&i&&console.log("Dynatrace - Modified Filename: "+e)}else e.includes(c.join("@dynatrace","react-native-plugin"))&&e.endsWith(c.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==r&&(t=(0,f.getHostAppBundleInfo)(l.default.getPackageJsonFile()),o=N(e,n),void 0!==r.lifecycle&&x(o,"getLifecycleUpdate",r.lifecycle.includeUpdate),void 0!==r.debug&&x(o,"getLogLevel",r.debug?0:1),void 0!==r.bundleName?x(o,"getBundleName",r.bundleName):null!==t&&x(o,"getBundleName",null==t?void 0:t.name),void 0!==r.bundleVersion?x(o,"getBundleVersion",r.bundleVersion):null!==t&&x(o,"getBundleVersion",null==t?void 0:t.version),void 0!==r.input&&void 0!==r.input.actionNamePrivacy&&x(o,"getActionNamePrivacy",r.input.actionNamePrivacy),void 0!==r.errorHandler&&(x(o,"isErrorHandlerEnabled",r.errorHandler.enabled),x(o,"isReportFatalErrorAsCrash",r.errorHandler.reportFatalErrorAsCrash)),r.autoStart&&x(o,"isAutoStartupEnabled",r.autoStart),n=o.toSource({quote:"single"}),h(n,e));return n},L=(exports.instrument=instrument,function(n,e){return!!T(n,e)&&(n="import { monitorNavigation } from '".concat(b,"/react-navigation/ReactNavigation';"),e.find(u.ImportDeclaration).at(0).insertBefore(n),!0)}),T=function(n,e){var r=!1;return n.includes("@react-navigation")&&n.includes("core")&&(n.includes("BaseNavigationContainer.js")||n.includes("BaseNavigationContainer.tsx"))&&e.find(u.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(n){r=!0,n.parent.insertAfter("monitorNavigation(getRootState);")}),r},A=function(n){var e=n.findJSXElements(),t=!1;return 0<e.length&&(n.find(u.FunctionDeclaration).forEach(function(n){var e,r=(0,i.fromPaths)([n]);0<r.findJSXElements().length&&null!=n&&null!=n.value&&null!=n.value.id&&n.value.id.name.toString()&&(e=r.find(u.ClassDeclaration),r=r.find(u.ClassExpression),0===e.length)&&0===r.length&&(j(n,m.Types.FunctionalComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ClassDeclaration).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n&&null!=n.value&&n.value.id&&n.value.id.name.toString()&&(j(n,m.Types.ClassComponent,n.value.id.name.toString()),t=!0)}),n.find(u.ArrowFunctionExpression).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.id&&null!=n.parent.value.id.name&&(j(n,m.Types.FunctionalComponent,n.parent.value.id.name),t=!0)}),n.find(u.FunctionExpression).forEach(function(n){0<(0,i.fromPaths)([n]).findJSXElements().length&&null!=n.parent&&null!=n.parent.value&&null!=n.parent.value.id&&null!=n.parent.value.id.name&&(j(n,m.Types.FunctionalComponent,n.parent.value.id.name),t=!0)})),t},j=function(n,e,r){for(e=u.expressionStatement(u.assignmentExpression("=",u.memberExpression(u.identifier(r),u.identifier("_dtInfo")),M(e,r)));"body"!==(null==n?void 0:n.parentPath.name);)n=n.parentPath;void 0!==n.parentPath&&n.insertAfter(e)},M=function(n,e){return u.objectExpression([u.objectProperty(u.identifier("type"),u.numericLiteral(n)),u.objectProperty(u.identifier("name"),u.stringLiteral(e))])},x=function(n,e,r){var n=n.find(u.Identifier).filter(function(n){return n.node.name===e});1===n.length&&"ReturnStatement"===(n=n.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof r&&(n.argument=u.booleanLiteral(r)),"string"==typeof r&&(n.argument=u.stringLiteral(r)),"number"==typeof r)&&(n.argument=u.numericLiteral(r))},N=function(n,e){return u.withParser((0,g.chooseParser)(n,e))(e)},O=function(n){return c.isAbsolute(n)?n.replace(l.default.getApplicationPath()+c.sep,""):n},I=function(n){try{var e=c.join(l.default.getBuildPath(),n+t.INSTRUMENTED_FILE_EXTENSION);r.default.checkIfFileExistsSync(e),r.default.deleteFileSync(e)}catch(n){}},h=function(n,e){e=c.join(l.default.getBuildPath(),e);try{r.default.checkIfFileExistsSync(c.dirname(e))}catch(n){r.default.createDirectorySync(c.dirname(e))}r.default.writeTextToFileSync(e+t.INSTRUMENTED_FILE_EXTENSION,n)},k=function(n,e){var r={input:!1,lifecycle:!1};return void 0!==e&&(void 0!==e.lifecycle&&void 0!==e.lifecycle.instrument&&e.lifecycle.instrument(n)&&(r.lifecycle=!0),void 0!==e.input)&&void 0!==e.input.instrument&&e.input.instrument(n)&&(r.input=!0),r},U=function(n){var e,n=n.find(u.Program);1===n.length&&(e=u.expressionStatement(u.callExpression(u.memberExpression(u.callExpression(u.identifier("require"),[u.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),u.identifier("instrumentCreateElement")),[u.memberExpression(u.identifier("module"),u.identifier("exports"))])),n.paths()[0].node.body.push(e))},V=function(n){var e=n.find(u.FunctionDeclaration,{id:{name:"runApplication"}});return 1===e.length&&(D(n,{m:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,_("_DynatraceApplicationHandler","startup",[])),!0)},w=function(n){var e=n.find(u.ObjectMethod,{key:{name:"runApplication"}});return 1===e.length&&(D(n,{m:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),R(e.get().value.body.body,0,_("_DynatraceApplicationHandler","startup",[])),!0)},J=function(n,r,t){var i=u;n.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(n){var e=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(r),i.literal(t)]),e=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(n.node.body.body)),e]));n.node.body.body=[e]})},G=function(n){var e=!1,n=n.find(u.CallExpression,{callee:{name:"require"}});return n.find(u.Literal,{value:"react/jsx-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-runtime",e=!0,n}),n.find(u.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(n){n=n.node;return n.value="@dynatrace/react-native-plugin/jsx-dev-runtime",e=!0,n}),e},R=function(n,e){for(var r=arguments.length,t=new Array(2<r?r-2:0),i=2;i<r;i++)t[i-2]=arguments[i];return n.splice.apply(n,[e,0].concat(t))},z=function(n){if(n.includes("@dynatrace"))return a.i;var e=c.extname(n);if(".js"!==e&&".ts"!==e&&".tsx"!==e&&".jsx"!==e)return a.i;for(var r=c.parse(n),t=r.dir.split(c.sep),i=0;i<t.length;i++)if("node_modules"===t[i]){if("react-native"===t[i+1]||"create-react-class"===t[i+1]||"react-clone-referenced-element"===t[i+1])return q.includes(r.name)?a.o:a.i;if("react"===t[i+1]&&"index"===r.name)return a.l;if("react-native-css-interop"===t[i+1]&&("jsx-runtime"===r.name||"jsx-dev-runtime"===r.name))return a.v}return a.u},K=function(n,e,r){var t=Q(n,e,r);return W(n,e,r)||t},Q=function(n,e,r){var t=Y(n,e);return 0<t.length&&(void 0!==(t=H(t,e.reference,!1))&&(r.m=t.localName),tn(n,r),!0)},W=function(n,e,r){var t=C(n,e.module);if(1===t.length){t=H(t,e.reference,!0);if(void 0!==t)return un(n,r.defaultImport,t.localName,"ImportNamespaceSpecifier"===t.type),!0}return!1},X=function(n,e){var r=JSON.parse(JSON.stringify(e.new));return{root:n,p:K(n,e.old,r)||Z(n,e.old,e.new.defaultImport)}},Y=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module&&null!=n.node.specifiers&&n.node.specifiers.some(function(n){return E(n)&&n.imported.name===e.reference||n.local&&n.local.name===e.reference})})},E=function(n){return void 0!==n.imported},Z=function(n,e,r){var t=!1;return n.find(u.CallExpression).filter(function(n){return $(n.node.callee)&&nn(n.node.arguments[0])&&n.node.arguments[0].value===e.module&&void 0!==n.parent}).forEach(function(n){(void 0===n.parent.value.property||void 0!==n.parent.value.property&&void 0!==n.parent.value.property.name&&n.parent.value.property.name===e.reference)&&(n.node.arguments[0].value=r,t=t||!0)}),t},$=function(n){return"require"===n.name},nn=function(n){return"StringLiteral"===n.type||"Literal"===n.type},C=function(n,e){return n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e})},H=function(n,r,t){var i;return n.forEach(function(n){void 0!==n.node.specifiers&&(n.node.specifiers=n.node.specifiers.filter(function(n){var e;return E(n)&&!t?((e=n.imported.name!==r)||null==n.local||n.imported.name===n.local.name||(i={localName:n.local.name.toString(),type:n.type}),e):!(!E(n)&&t&&(null!=n.local&&(i={localName:n.local.name.toString(),type:n.type}),1))}),0===n.node.specifiers.length)&&n.prune()}),i},en=function(n,e){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e.module}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(P(e))})},rn=function(n,e,r){n.find(u.ImportDeclaration).filter(function(n){return n.node.source.value===e}).forEach(function(n){null!=n.node.specifiers&&n.node.specifiers.push(r)})},S=function(n,e,r){var t=n.find(u.ImportDeclaration);0<t.length?u(t.paths()[0]).insertAfter(B(e,r)):1===(t=n.find(u.Program)).length&&t.paths()[0].node.body.unshift(B(e,r))},tn=function(n,e){0<C(n,e.module).length?en(n,e):S(n,e.module,[P(e)])},un=function(n,e,r,t){var i=C(n,e),t=(t?vn:sn)(r);0<i.length?rn(n,e,t):S(n,e,[t])},D=function(n,e){n=n.find(u.VariableDeclaration);0<n.length&&u(n.paths()[0]).insertAfter(an(e))},_=function(n,e,r){return u.expressionStatement(on(n,e,r))},on=function(n,e,r){return u.callExpression(fn(n,e),r)},an=function(n){return u.variableDeclaration("var",[cn(n)])},cn=function(n){return u.variableDeclarator(void 0!==n.m?u.identifier(n.m):u.identifier(n.reference),(0<n.reference.length?ln:F)(n))},ln=function(n){return u.memberExpression(F(n),u.identifier(n.reference))},fn=function(n,e){return u.memberExpression(u.identifier(n),u.identifier(e))},F=function(n){return u.callExpression(u.identifier("require"),[u.literal(n.module)])},B=function(n,e){return u.importDeclaration(e,u.literal(n))},P=function(n){return void 0!==n.m?u.importSpecifier(u.identifier(n.reference),u.identifier(n.m)):u.importSpecifier(u.identifier(n.reference))},sn=function(n){return u.importDefaultSpecifier(u.identifier(n))},vn=function(n){return u.importNamespaceSpecifier(u.identifier(n))};
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));function _createForOfIteratorHelper(e,t){var n,r,i,o,a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(a)return i=!(r=!0),{s:function(){a=a.call(e)},n:function(){var e=a.next();return r=e.done,e},e:function(e){i=!0,n=e},f:function(){try{r||null==a.return||a.return()}finally{if(i)throw n}}};if(Array.isArray(e)||(a=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return a&&(e=a),o=0,{s:t=function(){},n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.instrument=void 0;var FileType,nodePath=require("path"),jscodeshift=require("jscodeshift"),Collection_1=require("jscodeshift/src/Collection"),FileOperationHelper_1=require("../scripts/FileOperationHelper"),PathsConstants_1=require("../scripts/PathsConstants"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),InstrumentUtil_1=require("../scripts/util/InstrumentUtil"),Run_1=require("../lib/features/ui-interaction/Run"),Touchables_InstrInfo_1=require("./libs/react-native/Touchables.InstrInfo"),RefreshControl_InstrInfo_1=require("./libs/react-native/RefreshControl.InstrInfo"),Switch_InstrInfo_1=require("./libs/react-native/Switch.InstrInfo"),Touchables_InstrInfo_2=require("./libs/community/gesture-handler/Touchables.InstrInfo"),Picker_InstrInfo_1=require("./libs/community/Picker.InstrInfo"),Types_1=require("./model/Types"),ParserUtil_1=require("./parser/ParserUtil"),referenceListInput=((e=>{e[e.Filtered=-1]="Filtered",e[e.Normal=0]="Normal",e[e.ReactNative=1]="ReactNative",e[e.React=2]="React",e[e.ReactNativeCssInterop=3]="ReactNativeCssInterop"})(FileType=FileType||{}),[]),whiteList=(referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(RefreshControl_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Switch_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_2.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Picker_InstrInfo_1.instrumentationInfo)),new Set(["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"])),instrumentationLibraryFolder="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(e,t,n){t=correctFilename(t);var r=shouldInstrumentFile(t);if(r!==FileType.Filtered){var i=!1,o=parseSource(t,e);if(r===FileType.React)addCreateElementInstrumentation(o),i=!0;else if(r===FileType.ReactNative)t.endsWith("AppRegistryImpl.js")?null!=n&&n.autoStart&&addStartupCallRegistryImpl(o)&&(i=!0):t.endsWith("AppRegistry.js")?null!=n&&n.autoStart&&addStartupCallRegistry(o)&&(i=!0):t.endsWith("renderApplication.js")?(addInfoToComponent(o),i=!0):t.endsWith("ExceptionsManager.js")&&(a=void 0!==n&&n.autoStart&&n.errorHandler.enabled,addReportErrorToDynatraceCall(o,n.errorHandler.reportFatalErrorAsCrash,a),i=!0);else if(r===FileType.ReactNativeCssInterop)i=replaceReactWithDynatraceJsxRuntime(o)||i;else{var a=getInstrumentationList(t,n),r=[{isEnabled:function(e,t){return!0===(null==t?void 0:t.userInteraction)},run:function(e,t,n){return(0,Run_1.runDTUserInteraction)(e,t,n)}}].filter(function(e){return e.isEnabled(t,n)});if(n.navigation.enabled&&instrumentReactNavigation(t,o))i=!0;else{if(!a.input&&!a.lifecycle&&0===r.length)return null!=n&&n.debug&&console.log("Dynatrace - Filtered All: ".concat(t)),deleteTransformation(t),e;a.lifecycle&&addInfoToComponent(o)&&(i=!0),a.input&&referenceListInput.forEach(function(e){e=swapReferences(o,e);o=e.root,i=i||e.modified})}var s,l=_createForOfIteratorHelper(r);try{for(l.s();!(s=l.n()).done;){var c=s.value;try{var u=c.run(o,t,n),o=u.root;u.modified&&(i=!0)}catch(e){var f=e instanceof Error?e.stack||e.message:String(e);null!=n&&n.debug&&console.log("[DynatraceInstrumentationRaw]: Feature instrumentation failed for ".concat(t,": ").concat(f))}}}catch(e){l.e(e)}finally{l.f()}}var a=i?o.toSource({quote:"single"}):e;i?writeTransformation(e=a,t):deleteTransformation(t),null!=n&&n.debug&&i&&console.log("Dynatrace - Modified Filename: "+t)}else t.includes(nodePath.join("@dynatrace","react-native-plugin"))&&t.endsWith(nodePath.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==n&&(r=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),a=parseSource(t,e),void 0!==n.lifecycle&&changeConfigurationValue(a,"getLifecycleUpdate",n.lifecycle.includeUpdate),void 0!==n.debug&&changeConfigurationValue(a,"getLogLevel",n.debug?0:1),void 0!==n.bundleName?changeConfigurationValue(a,"getBundleName",n.bundleName):null!==r&&changeConfigurationValue(a,"getBundleName",null==r?void 0:r.name),void 0!==n.bundleVersion?changeConfigurationValue(a,"getBundleVersion",n.bundleVersion):null!==r&&changeConfigurationValue(a,"getBundleVersion",null==r?void 0:r.version),void 0!==n.input&&void 0!==n.input.actionNamePrivacy&&changeConfigurationValue(a,"getActionNamePrivacy",n.input.actionNamePrivacy),void 0!==n.errorHandler&&(changeConfigurationValue(a,"isErrorHandlerEnabled",n.errorHandler.enabled),changeConfigurationValue(a,"isReportFatalErrorAsCrash",n.errorHandler.reportFatalErrorAsCrash)),n.autoStart&&changeConfigurationValue(a,"isAutoStartupEnabled",n.autoStart),e=a.toSource({quote:"single"}),writeTransformation(e,t));return e},instrumentReactNavigation=(exports.instrument=instrument,function(e,t){return!!instrumentReactBaseNavigationContainer(e,t)&&(e="import { monitorNavigation } from '".concat(instrumentationLibraryFolder,"/react-navigation/ReactNavigation';"),t.find(jscodeshift.ImportDeclaration).at(0).insertBefore(e),!0)}),instrumentReactBaseNavigationContainer=function(e,t){var n=!1;return e.includes("@react-navigation")&&e.includes("core")&&(e.includes("BaseNavigationContainer.js")||e.includes("BaseNavigationContainer.tsx"))&&t.find(jscodeshift.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(e){n=!0,e.parent.insertAfter("monitorNavigation(getRootState);")}),n},addInfoToComponent=function(e){var t=e.findJSXElements(),r=!1;return 0<t.length&&(e.find(jscodeshift.FunctionDeclaration).forEach(function(e){var t,n=(0,Collection_1.fromPaths)([e]);0<n.findJSXElements().length&&null!=e&&null!=e.value&&null!=e.value.id&&e.value.id.name.toString()&&(t=n.find(jscodeshift.ClassDeclaration),n=n.find(jscodeshift.ClassExpression),0===t.length)&&0===n.length&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.value.id.name.toString()),r=!0)}),e.find(jscodeshift.ClassDeclaration).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e&&null!=e.value&&e.value.id&&e.value.id.name.toString()&&(insertExpressionIntoNextBody(e,Types_1.Types.ClassComponent,e.value.id.name.toString()),r=!0)}),e.find(jscodeshift.ArrowFunctionExpression).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e.parent&&null!=e.parent.value&&null!=e.parent.value.id&&null!=e.parent.value.id.name&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.parent.value.id.name),r=!0)}),e.find(jscodeshift.FunctionExpression).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e.parent&&null!=e.parent.value&&null!=e.parent.value.id&&null!=e.parent.value.id.name&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.parent.value.id.name),r=!0)})),r},insertExpressionIntoNextBody=function(e,t,n){for(t=jscodeshift.expressionStatement(jscodeshift.assignmentExpression("=",jscodeshift.memberExpression(jscodeshift.identifier(n),jscodeshift.identifier("_dtInfo")),createComponentInfo(t,n)));"body"!==(null==e?void 0:e.parentPath.name);)e=e.parentPath;void 0!==e.parentPath&&e.insertAfter(t)},createComponentInfo=function(e,t){return jscodeshift.objectExpression([jscodeshift.objectProperty(jscodeshift.identifier("type"),jscodeshift.numericLiteral(e)),jscodeshift.objectProperty(jscodeshift.identifier("name"),jscodeshift.stringLiteral(t))])},changeConfigurationValue=function(e,t,n){var e=e.find(jscodeshift.Identifier).filter(function(e){return e.node.name===t});1===e.length&&"ReturnStatement"===(e=e.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof n&&(e.argument=jscodeshift.booleanLiteral(n)),"string"==typeof n&&(e.argument=jscodeshift.stringLiteral(n)),"number"==typeof n)&&(e.argument=jscodeshift.numericLiteral(n))},parseSource=function(e,t){return jscodeshift.withParser((0,ParserUtil_1.chooseParser)(e,t))(t)},correctFilename=function(e){return nodePath.isAbsolute(e)?e.replace(PathsConstants_1.default.getApplicationPath()+nodePath.sep,""):e},deleteTransformation=function(e){try{var t=nodePath.join(PathsConstants_1.default.getBuildPath(),e+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION);FileOperationHelper_1.default.checkIfFileExistsSync(t),FileOperationHelper_1.default.deleteFileSync(t)}catch(e){}},writeTransformation=function(e,t){t=nodePath.join(PathsConstants_1.default.getBuildPath(),t);try{FileOperationHelper_1.default.checkIfFileExistsSync(nodePath.dirname(t))}catch(e){FileOperationHelper_1.default.createDirectorySync(nodePath.dirname(t))}FileOperationHelper_1.default.writeTextToFileSync(t+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION,e)},getInstrumentationList=function(e,t){var n={input:!1,lifecycle:!1};return void 0!==t&&(void 0!==t.lifecycle&&void 0!==t.lifecycle.instrument&&t.lifecycle.instrument(e)&&(n.lifecycle=!0),void 0!==t.input)&&void 0!==t.input.instrument&&t.input.instrument(e)&&(n.input=!0),n},addCreateElementInstrumentation=function(e){var t,e=e.find(jscodeshift.Program);1===e.length&&(t=jscodeshift.expressionStatement(jscodeshift.callExpression(jscodeshift.memberExpression(jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),jscodeshift.identifier("instrumentCreateElement")),[jscodeshift.memberExpression(jscodeshift.identifier("module"),jscodeshift.identifier("exports"))])),e.paths()[0].node.body.push(t))},addStartupCallRegistryImpl=function(e){var t=e.find(jscodeshift.FunctionDeclaration,{id:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addStartupCallRegistry=function(e){var t=e.find(jscodeshift.ObjectMethod,{key:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addReportErrorToDynatraceCall=function(e,n,r){var i=jscodeshift;e.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(e){var t=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(n),i.literal(r)]),t=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(e.node.body.body)),t]));e.node.body.body=[t]})},replaceReactWithDynatraceJsxRuntime=function(e){var t=!1,e=e.find(jscodeshift.CallExpression,{callee:{name:"require"}});return e.find(jscodeshift.Literal,{value:"react/jsx-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-runtime",t=!0,e}),e.find(jscodeshift.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-dev-runtime",t=!0,e}),t},insertInArray=function(e,t){for(var n=arguments.length,r=new Array(2<n?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];return e.splice.apply(e,[t,0].concat(r))},shouldInstrumentFile=function(e){if(e.includes("@dynatrace"))return FileType.Filtered;var t=nodePath.extname(e);if(".js"!==t&&".ts"!==t&&".tsx"!==t&&".jsx"!==t)return FileType.Filtered;for(var n=nodePath.parse(e),r=n.dir.split(nodePath.sep),i=0;i<r.length;i++)if("node_modules"===r[i]){if("react-native"===r[i+1]||"create-react-class"===r[i+1]||"react-clone-referenced-element"===r[i+1])return whiteList.has(n.name)?FileType.ReactNative:FileType.Filtered;if("react"===r[i+1]&&"index"===n.name)return FileType.React;if("react-native-css-interop"===r[i+1]&&("jsx-runtime"===n.name||"jsx-dev-runtime"===n.name))return FileType.ReactNativeCssInterop}return FileType.Normal},handleImports=function(e,t,n){var r=handleDestructuredImport(e,t,n);return handleDefaultImport(e,t,n)||r},handleDestructuredImport=function(e,t,n){var r=findImportSpecifier(e,t);return 0<r.length&&(void 0!==(r=removeImportSpecifier(r,t.reference,!1))&&(n.customName=r.localName),addReference(e,n),!0)},handleDefaultImport=function(e,t,n){var r=findImportDeclaration(e,t.module);if(1===r.length){r=removeImportSpecifier(r,t.reference,!0);if(void 0!==r)return addDefaultImport(e,n.defaultImport,r.localName,"ImportNamespaceSpecifier"===r.type),!0}return!1},swapReferences=function(e,t){var n=JSON.parse(JSON.stringify(t.new));return{root:e,modified:handleImports(e,t.old,n)||modifyRequireModule(e,t.old,t.new.defaultImport)}},findImportSpecifier=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module&&null!=e.node.specifiers&&e.node.specifiers.some(function(e){return isImportSpecifier(e)&&e.imported.name===t.reference||e.local&&e.local.name===t.reference})})},isImportSpecifier=function(e){return void 0!==e.imported},modifyRequireModule=function(e,t,n){var r=!1;return e.find(jscodeshift.CallExpression).filter(function(e){return isRequire(e.node.callee)&&isArgumentALiteral(e.node.arguments[0])&&e.node.arguments[0].value===t.module&&void 0!==e.parent}).forEach(function(e){(void 0===e.parent.value.property||void 0!==e.parent.value.property&&void 0!==e.parent.value.property.name&&e.parent.value.property.name===t.reference)&&(e.node.arguments[0].value=n,r=r||!0)}),r},isRequire=function(e){return"require"===e.name},isArgumentALiteral=function(e){return"StringLiteral"===e.type||"Literal"===e.type},findImportDeclaration=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t})},removeImportSpecifier=function(e,n,r){var i;return e.forEach(function(e){void 0!==e.node.specifiers&&(e.node.specifiers=e.node.specifiers.filter(function(e){var t;return isImportSpecifier(e)&&!r?((t=e.imported.name!==n)||null==e.local||e.imported.name===e.local.name||(i={localName:e.local.name.toString(),type:e.type}),t):!(!isImportSpecifier(e)&&r&&(null!=e.local&&(i={localName:e.local.name.toString(),type:e.type}),1))}),0===e.node.specifiers.length)&&e.prune()}),i},insertImportSpecifier=function(e,t){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(importSpecifier(t))})},insertImportDefaultSpecifier=function(e,t,n){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(n)})},insertImportDeclaration=function(e,t,n){var r=e.find(jscodeshift.ImportDeclaration);0<r.length?jscodeshift(r.paths()[0]).insertAfter(importDeclaration(t,n)):1===(r=e.find(jscodeshift.Program)).length&&r.paths()[0].node.body.unshift(importDeclaration(t,n))},addReference=function(e,t){0<findImportDeclaration(e,t.module).length?insertImportSpecifier(e,t):insertImportDeclaration(e,t.module,[importSpecifier(t)])},addDefaultImport=function(e,t,n,r){var i=findImportDeclaration(e,t),r=(r?importNamespaceSpecifier:importDefaultSpecifier)(n);0<i.length?insertImportDefaultSpecifier(e,t,r):insertImportDeclaration(e,t,[r])},addRequire=function(e,t){e=e.find(jscodeshift.VariableDeclaration);0<e.length&&jscodeshift(e.paths()[0]).insertAfter(requireDeclaration(t))},expressionStatement=function(e,t,n){return jscodeshift.expressionStatement(callExpression(e,t,n))},callExpression=function(e,t,n){return jscodeshift.callExpression(memberExpression(e,t),n)},requireDeclaration=function(e){return jscodeshift.variableDeclaration("var",[requireDeclarator(e)])},requireDeclarator=function(e){return jscodeshift.variableDeclarator(void 0!==e.customName?jscodeshift.identifier(e.customName):jscodeshift.identifier(e.reference),(0<e.reference.length?memberExpressionRequire:requireExpression)(e))},memberExpressionRequire=function(e){return jscodeshift.memberExpression(requireExpression(e),jscodeshift.identifier(e.reference))},memberExpression=function(e,t){return jscodeshift.memberExpression(jscodeshift.identifier(e),jscodeshift.identifier(t))},requireExpression=function(e){return jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.literal(e.module)])},importDeclaration=function(e,t){return jscodeshift.importDeclaration(t,jscodeshift.literal(e))},importSpecifier=function(e){return void 0!==e.customName?jscodeshift.importSpecifier(jscodeshift.identifier(e.reference),jscodeshift.identifier(e.customName)):jscodeshift.importSpecifier(jscodeshift.identifier(e.reference))},importDefaultSpecifier=function(e){return jscodeshift.importDefaultSpecifier(jscodeshift.identifier(e))},importNamespaceSpecifier=function(e){return jscodeshift.importNamespaceSpecifier(jscodeshift.identifier(e))};
@@ -1,29 +1,129 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createElement = void 0;
4
+ const react_1 = require("react");
4
5
  const Types_1 = require("../model/Types");
5
6
  const ElementHelper_1 = require("./ElementHelper");
6
7
  const ClassComponent_1 = require("./components/ClassComponent");
7
8
  const FunctionalComponent_1 = require("./components/FunctionalComponent");
8
- const react_1 = require("react");
9
+ const PRESS_PROP_KEYS = [
10
+ 'onPress',
11
+ 'onLongPress',
12
+ 'onPressIn',
13
+ 'onPressOut',
14
+ 'onTap',
15
+ 'onClick',
16
+ ];
17
+ const getGlobalPressHook = () => {
18
+ const g = (typeof globalThis !== 'undefined' && globalThis) ||
19
+ (typeof global !== 'undefined' && global) ||
20
+ (typeof window !== 'undefined' && window) ||
21
+ undefined;
22
+ return g === null || g === void 0 ? void 0 : g.__DT_UI_PLUGIN_PRESS_HOOK__;
23
+ };
24
+ const getDisplayName = (type) => {
25
+ if (!type) {
26
+ return 'Unknown';
27
+ }
28
+ if (typeof type === 'string') {
29
+ return type;
30
+ }
31
+ return (type.displayName ||
32
+ type.name ||
33
+ (type.constructor && type.constructor.name) ||
34
+ 'Anonymous');
35
+ };
36
+ const guessTouchableName = (type, props) => {
37
+ if (!props) {
38
+ return getDisplayName(type);
39
+ }
40
+ if (typeof props.dtActionName === 'string' && props.dtActionName.length) {
41
+ return props.dtActionName;
42
+ }
43
+ if (typeof props.title === 'string' && props.title.length) {
44
+ return props.title;
45
+ }
46
+ if (typeof props.accessibilityLabel === 'string' &&
47
+ props.accessibilityLabel.length) {
48
+ return props.accessibilityLabel;
49
+ }
50
+ if (typeof props.testID === 'string' && props.testID.length) {
51
+ return props.testID;
52
+ }
53
+ return getDisplayName(type);
54
+ };
55
+ const mapHandlerToPhase = (handler) => {
56
+ if (handler === 'onPressIn') {
57
+ return 'press-in';
58
+ }
59
+ if (handler === 'onPressOut') {
60
+ return 'press-out';
61
+ }
62
+ return 'press';
63
+ };
64
+ const attachPressHookToProps = (type, props) => {
65
+ if (!props) {
66
+ return props;
67
+ }
68
+ const hook = getGlobalPressHook();
69
+ if (!hook) {
70
+ return props;
71
+ }
72
+ let cloned = null;
73
+ const wrapOne = (key) => {
74
+ const orig = props[key];
75
+ if (typeof orig !== 'function') {
76
+ return;
77
+ }
78
+ if (!cloned) {
79
+ cloned = Object.assign({}, props);
80
+ }
81
+ cloned[key] = (...args) => {
82
+ var _a;
83
+ try {
84
+ const evt = args[0];
85
+ const nativeEvent = (_a = evt === null || evt === void 0 ? void 0 : evt.nativeEvent) !== null && _a !== void 0 ? _a : evt;
86
+ const touchableName = guessTouchableName(type, props);
87
+ hook({
88
+ phase: mapHandlerToPhase(key),
89
+ handler: key,
90
+ touchableName,
91
+ nativeEvent,
92
+ });
93
+ }
94
+ catch (e) {
95
+ const errorMsg = e instanceof Error ? e.stack || e.message : String(e);
96
+ console.log(`[CreateElement]: DT press hook failed: ${errorMsg}`);
97
+ }
98
+ return orig(...args);
99
+ };
100
+ };
101
+ for (const key of PRESS_PROP_KEYS) {
102
+ wrapOne(key);
103
+ }
104
+ return cloned || props;
105
+ };
9
106
  const createElement = (type, props, ...children) => {
10
- if (type != null && type._dtInfo != null && !(0, ElementHelper_1.isDtActionIgnore)(props)) {
107
+ const patchedProps = attachPressHookToProps(type, props);
108
+ if (type != null &&
109
+ type._dtInfo != null &&
110
+ !(0, ElementHelper_1.isDtActionIgnore)(patchedProps)) {
11
111
  if (type._dtInfo.type === Types_1.Types.FunctionalComponent) {
12
112
  return (0, react_1.createElement)(FunctionalComponent_1.DynatraceFunctionalComponent, {
13
- children: (0, react_1.createElement)(type, props, ...children),
113
+ children: (0, react_1.createElement)(type, patchedProps, ...children),
14
114
  });
15
115
  }
16
116
  else if (type._dtInfo.type === Types_1.Types.ClassComponent &&
17
117
  type.prototype !== undefined &&
18
118
  type.prototype.isReactComponent !== undefined) {
19
119
  return (0, react_1.createElement)(ClassComponent_1.DynatraceClassComponent, {
20
- children: (0, react_1.createElement)(type, props, ...children),
120
+ children: (0, react_1.createElement)(type, patchedProps, ...children),
21
121
  });
22
122
  }
23
123
  else {
24
- (0, ElementHelper_1.modifyElement)(type, props);
124
+ (0, ElementHelper_1.modifyElement)(type, patchedProps);
25
125
  }
26
126
  }
27
- return (0, react_1.createElement)(type, props, ...children);
127
+ return (0, react_1.createElement)(type, patchedProps, ...children);
28
128
  };
29
129
  exports.createElement = createElement;
@@ -11,9 +11,7 @@ try {
11
11
  args[0]._dtInfo !== undefined &&
12
12
  !(0, ElementHelper_1.isDtActionIgnore)(args[1])) {
13
13
  if (args[0]._dtInfo.type === Types_1.Types.FunctionalComponent) {
14
- const wrapperProps = {
15
- children: ReactDevRuntime.jsxDEV(...args),
16
- };
14
+ const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: ReactDevRuntime.jsxDEV(...args) });
17
15
  wrapperProps.dtActionName =
18
16
  args[1] !== undefined && args[1].dtActionName !== undefined
19
17
  ? args[1].dtActionName
@@ -28,9 +26,7 @@ try {
28
26
  else if (args[0]._dtInfo.type === Types_1.Types.ClassComponent &&
29
27
  args[0].prototype !== undefined &&
30
28
  args[0].prototype.isReactComponent !== undefined) {
31
- const wrapperProps = {
32
- children: ReactDevRuntime.jsxDEV(...args),
33
- };
29
+ const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: ReactDevRuntime.jsxDEV(...args) });
34
30
  if (args[2] !== undefined) {
35
31
  return ReactDevRuntime.jsxDEV(ClassComponent_1.DynatraceClassComponent, wrapperProps, args[2] + '_dt');
36
32
  }
@@ -10,31 +10,27 @@ const instrumentJsxCall = (jsxFunction) => (...args) => {
10
10
  args[0]._dtInfo !== undefined &&
11
11
  !(0, ElementHelper_1.isDtActionIgnore)(args[1])) {
12
12
  if (args[0]._dtInfo.type === Types_1.Types.FunctionalComponent) {
13
- const wrapperProps = {
14
- children: jsxFunction(...args),
15
- };
13
+ const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: jsxFunction(...args) });
16
14
  wrapperProps.dtActionName =
17
15
  args[1] !== undefined && args[1].dtActionName !== undefined
18
16
  ? args[1].dtActionName
19
17
  : args[0]._dtInfo.name;
20
18
  if (args[2] !== undefined) {
21
- return jsxFunction(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps, args[2] + '_dt');
19
+ return ReactRuntime.jsx(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps, args[2] + '_dt');
22
20
  }
23
21
  else {
24
- return jsxFunction(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps);
22
+ return ReactRuntime.jsx(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps);
25
23
  }
26
24
  }
27
25
  else if (args[0]._dtInfo.type === Types_1.Types.ClassComponent &&
28
26
  args[0].prototype !== undefined &&
29
27
  args[0].prototype.isReactComponent !== undefined) {
30
- const wrapperProps = {
31
- children: jsxFunction(...args),
32
- };
28
+ const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: jsxFunction(...args) });
33
29
  if (args[2] !== undefined) {
34
- return jsxFunction(ClassComponent_1.DynatraceClassComponent, wrapperProps, args[2] + '_dt');
30
+ return ReactRuntime.jsx(ClassComponent_1.DynatraceClassComponent, wrapperProps, args[2] + '_dt');
35
31
  }
36
32
  else {
37
- return jsxFunction(ClassComponent_1.DynatraceClassComponent, wrapperProps);
33
+ return ReactRuntime.jsx(ClassComponent_1.DynatraceClassComponent, wrapperProps);
38
34
  }
39
35
  }
40
36
  (0, ElementHelper_1.modifyElement)(args[0], args[1]);
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RootWrapper = exports.wrapProvider = exports.notifyPress = void 0;
4
+ const React = require("react");
5
+ const react_native_1 = require("react-native");
6
+ const ConfigurationHandler_1 = require("../../lib/core/configuration/ConfigurationHandler");
7
+ const EventPipeline_1 = require("../../lib/next/events/EventPipeline");
8
+ const TOUCH_FLUSH_DELAY = 250;
9
+ let pendingTouch = null;
10
+ const getFiberPath = (fiber) => {
11
+ var _a, _b, _c;
12
+ let anyParentMasked = false;
13
+ let path = [];
14
+ let lastDtName;
15
+ while (fiber != null) {
16
+ const dtInfoName = (_a = fiber.type) === null || _a === void 0 ? void 0 : _a.dtName;
17
+ const dtName = (_b = fiber.memoizedProps) === null || _b === void 0 ? void 0 : _b.dtName;
18
+ const effectiveName = dtName !== null && dtName !== void 0 ? dtName : dtInfoName;
19
+ if (effectiveName && effectiveName !== lastDtName) {
20
+ path = [effectiveName, ...path];
21
+ lastDtName = effectiveName;
22
+ }
23
+ anyParentMasked =
24
+ anyParentMasked || ((_c = fiber.memoizedProps) === null || _c === void 0 ? void 0 : _c.dtMask) == true;
25
+ fiber = fiber.return;
26
+ }
27
+ return { path, anyParentMasked };
28
+ };
29
+ const flatten = (children) => Array.isArray(children) ? children.map(String).join('') : String(children);
30
+ function findRCTTextChild(fiber) {
31
+ let node = fiber.child;
32
+ while (node) {
33
+ if (node.type === 'RCTText') {
34
+ return node;
35
+ }
36
+ const found = findRCTTextChild(node);
37
+ if (found)
38
+ return found;
39
+ node = node.sibling;
40
+ }
41
+ return null;
42
+ }
43
+ const getHostComponentInfo = (event) => {
44
+ var _a, _b;
45
+ let fiber = event._targetInst;
46
+ if (!fiber) {
47
+ console.warn('Assumption violated: _targetInst not found');
48
+ return undefined;
49
+ }
50
+ if (fiber.type === 'RNGestureHandlerButton') {
51
+ fiber = (_a = findRCTTextChild(fiber)) !== null && _a !== void 0 ? _a : fiber;
52
+ }
53
+ if (typeof fiber.type !== 'string') {
54
+ console.warn('Assumption violated: leaf fiber not a host component');
55
+ return undefined;
56
+ }
57
+ const { path, anyParentMasked } = getFiberPath(fiber);
58
+ const id = path.join('/');
59
+ const leaf = path[path.length - 1];
60
+ const components = [leaf];
61
+ const { nameOrigin, detectedName } = fiber.type !== 'RCTText'
62
+ ? {
63
+ nameOrigin: 'component',
64
+ detectedName: (_b = fiber.memoizedProps.accessibilityLabel) !== null && _b !== void 0 ? _b : leaf,
65
+ }
66
+ : anyParentMasked
67
+ ? {
68
+ nameOrigin: 'masked',
69
+ detectedName: '***',
70
+ }
71
+ : {
72
+ nameOrigin: 'text',
73
+ detectedName: flatten(fiber.memoizedProps.children),
74
+ };
75
+ return { id, components, detectedName, nameOrigin };
76
+ };
77
+ const flushTouch = (responderComponentInfo) => {
78
+ if (!pendingTouch)
79
+ return;
80
+ const { touchedComponentInfo, positions, timeoutId } = pendingTouch;
81
+ clearTimeout(timeoutId);
82
+ pendingTouch = null;
83
+ const event = Object.assign({ 'characteristics.has_user_interaction': true, 'ui_element.detected_name': touchedComponentInfo.detectedName, 'ui_element.components': touchedComponentInfo.components, 'ui_element.id': touchedComponentInfo.id, 'interaction.type': 'touch', positions, 'ui_element.name_origin': touchedComponentInfo.nameOrigin }, (responderComponentInfo && {
84
+ 'ui_element.responder.detected_name': responderComponentInfo.detectedName,
85
+ 'ui_element.responder.components': responderComponentInfo.components,
86
+ 'ui_element.responder.id': responderComponentInfo.id,
87
+ 'ui_element.responder.name_origin': responderComponentInfo.nameOrigin,
88
+ }));
89
+ EventPipeline_1.EventPipeline.insertEvent(event);
90
+ };
91
+ const onTouch = (e) => {
92
+ if (!ConfigurationHandler_1.ConfigurationHandler.isUserInteractionEnabled())
93
+ return;
94
+ flushTouch();
95
+ const touchedComponentInfo = getHostComponentInfo(e);
96
+ if (!touchedComponentInfo)
97
+ return;
98
+ const { pageX, pageY } = e.nativeEvent;
99
+ const positions = [{ x: Math.trunc(pageX), y: Math.trunc(pageY) }];
100
+ const timeoutId = setTimeout(flushTouch, TOUCH_FLUSH_DELAY);
101
+ pendingTouch = { touchedComponentInfo, positions, timeoutId };
102
+ };
103
+ const notifyPress = (event) => flushTouch(getHostComponentInfo(event));
104
+ exports.notifyPress = notifyPress;
105
+ const wrapProvider = (originalProvider) => () => {
106
+ const Original = originalProvider();
107
+ return function DtRootWrapped(props) {
108
+ return (React.createElement(exports.RootWrapper, null,
109
+ React.createElement(Original, Object.assign({}, props))));
110
+ };
111
+ };
112
+ exports.wrapProvider = wrapProvider;
113
+ const RootWrapper = ({ children }) => (React.createElement(react_native_1.View, { pointerEvents: "box-none", collapsable: false, style: { flex: 1 }, onTouchStart: onTouch }, children));
114
+ exports.RootWrapper = RootWrapper;
@@ -21,3 +21,5 @@ exports.instrumentationInfo.push(generateInstrumentation('TouchableOpacity'));
21
21
  exports.instrumentationInfo.push(generateInstrumentation('TouchableNativeFeedback'));
22
22
  exports.instrumentationInfo.push(generateInstrumentation('TouchableWithoutFeedback'));
23
23
  exports.instrumentationInfo.push(generateInstrumentation('RectButton'));
24
+ exports.instrumentationInfo.push(generateInstrumentation('BorderlessButton'));
25
+ exports.instrumentationInfo.push(generateInstrumentation('BaseButton'));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableNativeFeedback = exports.TouchableHighlight = exports.TouchableOpacity = void 0;
3
+ exports.BaseButton = exports.BorderlessButton = exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableNativeFeedback = exports.TouchableHighlight = exports.TouchableOpacity = void 0;
4
4
  const GestureHandler = require("react-native-gesture-handler");
5
5
  const withOnPressMonitoring_1 = require("../../withOnPressMonitoring");
6
6
  exports.TouchableOpacity = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.TouchableOpacity, 'Touchable');
@@ -8,3 +8,5 @@ exports.TouchableHighlight = (0, withOnPressMonitoring_1.withOnPressMonitoring)(
8
8
  exports.TouchableNativeFeedback = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.TouchableNativeFeedback, 'Touchable');
9
9
  exports.TouchableWithoutFeedback = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.TouchableWithoutFeedback, 'Touchable');
10
10
  exports.RectButton = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.RectButton, 'Button');
11
+ exports.BorderlessButton = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.BorderlessButton, 'Button');
12
+ exports.BaseButton = (0, withOnPressMonitoring_1.withOnPressMonitoring)(GestureHandler.BaseButton, 'Button');
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableOpacity = exports.TouchableNativeFeedback = exports.TouchableHighlight = void 0;
3
+ exports.BaseButton = exports.BorderlessButton = exports.RectButton = exports.TouchableWithoutFeedback = exports.TouchableOpacity = exports.TouchableNativeFeedback = exports.TouchableHighlight = void 0;
4
4
  var Touchables_1 = require("./Touchables");
5
5
  Object.defineProperty(exports, "TouchableHighlight", { enumerable: true, get: function () { return Touchables_1.TouchableHighlight; } });
6
6
  Object.defineProperty(exports, "TouchableNativeFeedback", { enumerable: true, get: function () { return Touchables_1.TouchableNativeFeedback; } });
7
7
  Object.defineProperty(exports, "TouchableOpacity", { enumerable: true, get: function () { return Touchables_1.TouchableOpacity; } });
8
8
  Object.defineProperty(exports, "TouchableWithoutFeedback", { enumerable: true, get: function () { return Touchables_1.TouchableWithoutFeedback; } });
9
9
  Object.defineProperty(exports, "RectButton", { enumerable: true, get: function () { return Touchables_1.RectButton; } });
10
+ Object.defineProperty(exports, "BorderlessButton", { enumerable: true, get: function () { return Touchables_1.BorderlessButton; } });
11
+ Object.defineProperty(exports, "BaseButton", { enumerable: true, get: function () { return Touchables_1.BaseButton; } });
@@ -7,26 +7,78 @@ const ConsoleLogger_1 = require("../../lib/core/logging/ConsoleLogger");
7
7
  const ConfigurationHandler_1 = require("../../lib/core/configuration/ConfigurationHandler");
8
8
  const Dynatrace_1 = require("../../lib/core/Dynatrace");
9
9
  const ComponentUtil_1 = require("../jsx/components/ComponentUtil");
10
+ const UserInteraction_1 = require("./UserInteraction");
10
11
  const Logger = new ConsoleLogger_1.ConsoleLogger('TouchableHelper');
11
12
  function withOnPressMonitoring(Component, fallbackName) {
12
13
  return React.forwardRef((props, ref) => {
13
14
  const { onPress, onLongPress } = props;
14
15
  const touchableName = (0, exports.chooseTouchableName)(props, fallbackName);
15
16
  const dynatraceIgnored = (0, ComponentUtil_1.isDynatraceIgnored)(props);
17
+ const isRNButton = 'title' in props && typeof props.title === 'string';
18
+ const isRectButton = fallbackName === 'Button';
19
+ const isButtonLike = isRNButton || isRectButton;
20
+ const buttonLabel = isRNButton ? String(props.title) : null;
16
21
  const propsWithoutRef = Object.assign(Object.assign(Object.assign({}, props), (!dynatraceIgnored &&
17
22
  onPress && {
18
- onPress: (0, exports.wrapOnPress)(onPress, touchableName),
23
+ onPress: (0, exports.wrapOnPress)(onPress, touchableName, isButtonLike, buttonLabel),
19
24
  })), (!dynatraceIgnored &&
20
25
  onLongPress && {
21
- onLongPress: (0, exports.wrapOnPress)(onLongPress, touchableName),
26
+ onLongPress: (0, exports.wrapOnPress)(onLongPress, touchableName, isButtonLike, buttonLabel),
22
27
  }));
23
28
  const propsWithRef = Object.assign(Object.assign({}, propsWithoutRef), { ref });
24
29
  return React.createElement(Component, Object.assign({}, propsWithRef));
25
30
  });
26
31
  }
27
32
  exports.withOnPressMonitoring = withOnPressMonitoring;
28
- const wrapOnPress = (onPress, touchableName) => {
33
+ const dtGetUiBridge = () => {
34
+ const g = globalThis;
35
+ return g && g.__DT_UII_BRIDGE ? g.__DT_UII_BRIDGE : null;
36
+ };
37
+ const dtBuildPressPath = (startPath, touchableName) => {
38
+ const base = (startPath && String(startPath)) || '';
39
+ if (!base)
40
+ return `Touchable(${touchableName})`;
41
+ const cut1 = base.lastIndexOf('/Text');
42
+ const cut2 = base.lastIndexOf('/Text(');
43
+ const cut = Math.max(cut1, cut2);
44
+ const parent = cut > 0 ? base.slice(0, cut) : base;
45
+ return parent + `/Touchable(${touchableName})`;
46
+ };
47
+ const wrapOnPress = (onPress, touchableName, isButtonLike, buttonLabel) => {
29
48
  return (...args) => {
49
+ const bridge = dtGetUiBridge();
50
+ if (bridge && typeof bridge.registerPress === 'function') {
51
+ try {
52
+ const e = args && args[0];
53
+ const ne = e && e.nativeEvent;
54
+ const x = Number(ne && ne.pageX);
55
+ const y = Number(ne && ne.pageY);
56
+ const pos = Number.isFinite(x) && Number.isFinite(y)
57
+ ? { x, y }
58
+ : undefined;
59
+ const startPath = bridge.getStartPath &&
60
+ typeof bridge.getStartPath === 'function'
61
+ ? bridge.getStartPath()
62
+ : null;
63
+ const nameForBridge = isButtonLike
64
+ ? buttonLabel || touchableName
65
+ : touchableName;
66
+ bridge.registerPress({
67
+ path: dtBuildPressPath(startPath, nameForBridge),
68
+ elementName: nameForBridge,
69
+ pos,
70
+ });
71
+ }
72
+ catch (e) {
73
+ const errorMsg = e instanceof Error ? e.stack || e.message : String(e);
74
+ Logger.debug(`registerPress bridge hook failed: ${errorMsg}`);
75
+ }
76
+ }
77
+ if (args[0] &&
78
+ typeof args[0] === 'object' &&
79
+ 'nativeEvent' in args[0]) {
80
+ (0, UserInteraction_1.notifyPress)(args[0]);
81
+ }
30
82
  if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
31
83
  Logger.info('React Native plugin has not been started yet! Touch will not be reported!');
32
84
  onPress(...args);
@@ -279,6 +279,7 @@ template<typename T = void> std::enable_if_t<(facebook::react::ReactNativeVersio
279
279
  /**
280
280
  * Triggered when starting to emit events
281
281
  */
282
+
282
283
  - (void)startObserving
283
284
  {
284
285
  hasListeners = YES;
@@ -720,7 +721,7 @@ RCT_EXPORT_METHOD(getUserPrivacyOptions:(NSString *) platform findEventsWithReso
720
721
  level = DataCollectionOff;
721
722
  }
722
723
 
723
- NSDictionary *privacyDict = @{@"dataCollectionLevel": level, @"crashReportingOptedIn": [NSNumber numberWithBool: privacyConfig.crashReportingOptedIn]};
724
+ NSDictionary *privacyDict = @{@"dataCollectionLevel": level, @"crashReportingOptedIn": [NSNumber numberWithBool: privacyConfig.crashReportingOptedIn], @"screenRecordOptedIn": [NSNumber numberWithBool: privacyConfig.screenRecordOptedIn]};
724
725
 
725
726
  resolve(privacyDict);
726
727
  }
@@ -750,6 +751,12 @@ RCT_EXPORT_METHOD(applyUserPrivacyOptions:(NSDictionary *) userPrivacyOptions pl
750
751
  // do nothing and keep current value
751
752
  }
752
753
 
754
+ if ([[userPrivacyOptions valueForKey:@"_screenRecordOptedIn"] isEqual: @(YES)]) {
755
+ privacyConfig.screenRecordOptedIn = @(YES);
756
+ } else if ([[userPrivacyOptions valueForKey:@"_screenRecordOptedIn"] isEqual: @(NO)]) {
757
+ privacyConfig.screenRecordOptedIn = @(NO);
758
+ }
759
+
753
760
  [Dynatrace applyUserPrivacyOptions:privacyConfig completion:^(BOOL successful) {
754
761
  // do nothing with callback
755
762
  }];
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApplicationHandler = void 0;
4
4
  const AppStartObserver_1 = require("../next/appstart/AppStartObserver");
5
+ const RuntimeConfigurationObserver_1 = require("../next/configuration/RuntimeConfigurationObserver");
5
6
  const ConfigurationBuilder_1 = require("./configuration/ConfigurationBuilder");
6
7
  const ConfigurationHandler_1 = require("./configuration/ConfigurationHandler");
7
8
  const ConsoleLogger_1 = require("./logging/ConsoleLogger");
8
9
  AppStartObserver_1.AppStartObserver.call();
10
+ RuntimeConfigurationObserver_1.RuntimeConfigurationObserver.call();
9
11
  const logger = new ConsoleLogger_1.ConsoleLogger('ApplicationHandler');
10
12
  exports.ApplicationHandler = {
11
13
  startup: (configuration) => {
@@ -287,10 +287,11 @@ exports.Dynatrace = {
287
287
  }
288
288
  },
289
289
  getUserPrivacyOptions: (platform) => __awaiter(void 0, void 0, void 0, function* () {
290
+ var _a;
290
291
  if (ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
291
292
  logger.debug('getUserPrivacyOptions()');
292
293
  const options = yield DynatraceBridge_1.DynatraceNative.getUserPrivacyOptions(platform === null || platform === void 0 ? void 0 : platform.toString());
293
- const currentOptions = new UserPrivacyOptions_1.UserPrivacyOptions((0, DataCollectionLevel_1.StringToDataCollectionLevel)(options.dataCollectionLevel), options.crashReportingOptedIn);
294
+ const currentOptions = new UserPrivacyOptions_1.UserPrivacyOptions((0, DataCollectionLevel_1.StringToDataCollectionLevel)(options.dataCollectionLevel), options.crashReportingOptedIn, (_a = options.screenRecordOptedIn) !== null && _a !== void 0 ? _a : false);
294
295
  return currentOptions;
295
296
  }
296
297
  else {
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserPrivacyOptions = void 0;
4
4
  class UserPrivacyOptions {
5
- constructor(dataCollectionLevel, crashReportingOptedIn) {
5
+ constructor(dataCollectionLevel, crashReportingOptedIn, screenRecordOptedIn = false) {
6
6
  this._dataCollectionLevel = dataCollectionLevel;
7
7
  this._crashReportingOptedIn = crashReportingOptedIn;
8
+ this._screenRecordOptedIn = screenRecordOptedIn;
8
9
  }
9
10
  get dataCollectionLevel() {
10
11
  return this._dataCollectionLevel;
@@ -18,5 +19,11 @@ class UserPrivacyOptions {
18
19
  set dataCollectionLevel(dataCollectionLevel) {
19
20
  this._dataCollectionLevel = dataCollectionLevel;
20
21
  }
22
+ get screenRecordOptedIn() {
23
+ return this._screenRecordOptedIn;
24
+ }
25
+ set screenRecordOptedIn(screenRecordOptedIn) {
26
+ this._screenRecordOptedIn = screenRecordOptedIn;
27
+ }
21
28
  }
22
29
  exports.UserPrivacyOptions = UserPrivacyOptions;
@@ -4,10 +4,14 @@ exports.ConfigurationHandler = void 0;
4
4
  const RuntimeConfigurationObserver_1 = require("../../next/configuration/RuntimeConfigurationObserver");
5
5
  const LogLevel_1 = require("../logging/LogLevel");
6
6
  let _configuration;
7
+ let _uiiEnabledLastKnownGood = undefined;
7
8
  exports.ConfigurationHandler = {
8
9
  setConfiguration(configuration) {
9
10
  _configuration = configuration;
10
11
  },
12
+ setUserInteractionEnabledLastKnownGood(value) {
13
+ _uiiEnabledLastKnownGood = value;
14
+ },
11
15
  isConfigurationAvailable: () => _configuration !== undefined,
12
16
  isErrorHandlerEnabled: () => _configuration.errorHandler,
13
17
  isReportFatalErrorAsCrash: () => _configuration.reportFatalErrorAsCrash,
@@ -16,6 +20,23 @@ exports.ConfigurationHandler = {
16
20
  isLifecycleUpdateEnabled: () => _configuration.lifecycleUpdate,
17
21
  isActionNamePrivacyEnabled: () => _configuration.actionNamePrivacy,
18
22
  isGrailEnabled: () => RuntimeConfigurationObserver_1.RuntimeConfigurationObserver.getCurrentRuntimeConfiguration()['3rd_gen_enabled'],
23
+ isUserInteractionEnabled: () => {
24
+ const isRuntimeConfigInitiated = RuntimeConfigurationObserver_1.RuntimeConfigurationObserver.isInitiated();
25
+ if (isRuntimeConfigInitiated) {
26
+ const realTimeconfiguration = RuntimeConfigurationObserver_1.RuntimeConfigurationObserver.getCurrentRuntimeConfiguration();
27
+ const remoteUIConfiguration = realTimeconfiguration
28
+ ? realTimeconfiguration.touch_interaction_enabled
29
+ : undefined;
30
+ if (typeof remoteUIConfiguration === 'boolean') {
31
+ _uiiEnabledLastKnownGood = remoteUIConfiguration;
32
+ return remoteUIConfiguration;
33
+ }
34
+ }
35
+ if (typeof _uiiEnabledLastKnownGood === 'boolean') {
36
+ return _uiiEnabledLastKnownGood;
37
+ }
38
+ return false;
39
+ },
19
40
  isRuntimeConfigurationInitiated: () => RuntimeConfigurationObserver_1.RuntimeConfigurationObserver.isInitiated(),
20
41
  getBundleName: () => _configuration.bundleName,
21
42
  getBundleVersion: () => _configuration.bundleVersion,