replayBreadcrumbFrameData.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {BreadcrumbType} from 'sentry/types/breadcrumbs';
  2. import {RawBreadcrumbFrame} from 'sentry/utils/replays/types';
  3. type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
  4. type TestableFrame<Cat extends RawBreadcrumbFrame['category']> = Overwrite<
  5. Partial<Extract<RawBreadcrumbFrame, {category: Cat}>>,
  6. {timestamp: Date}
  7. >;
  8. type MockFrame<Cat extends RawBreadcrumbFrame['category']> = Extract<
  9. RawBreadcrumbFrame,
  10. {category: Cat}
  11. >;
  12. export function ReplayConsoleFrameFixture(
  13. fields: TestableFrame<'console'>
  14. ): MockFrame<'console'> {
  15. return {
  16. category: 'console',
  17. data: fields.data ?? {
  18. logger: 'unknown',
  19. },
  20. level: fields.level ?? 'fatal',
  21. message: fields.message ?? '',
  22. timestamp: fields.timestamp.getTime() / 1000,
  23. type: BreadcrumbType.DEBUG,
  24. };
  25. }
  26. export function ReplayClickFrameFixture(
  27. fields: TestableFrame<'ui.click'>
  28. ): MockFrame<'ui.click'> {
  29. return {
  30. category: 'ui.click',
  31. data: fields.data ?? {},
  32. message: fields.message ?? '',
  33. timestamp: fields.timestamp.getTime() / 1000,
  34. type: BreadcrumbType.UI,
  35. };
  36. }
  37. export function ReplayInputFrameFixture(
  38. fields: TestableFrame<'ui.input'>
  39. ): MockFrame<'ui.input'> {
  40. return {
  41. category: 'ui.input',
  42. message: fields.message ?? '',
  43. timestamp: fields.timestamp.getTime() / 1000,
  44. type: BreadcrumbType.DEFAULT,
  45. };
  46. }
  47. export function ReplayKeyboardEventFrameFixture(
  48. fields: TestableFrame<'ui.keyDown'>
  49. ): MockFrame<'ui.keyDown'> {
  50. return {
  51. category: 'ui.keyDown',
  52. data: fields.data ?? {
  53. altKey: false,
  54. ctrlKey: false,
  55. key: 'A',
  56. metaKey: false,
  57. shiftKey: false,
  58. },
  59. message: fields.message,
  60. timestamp: fields.timestamp.getTime() / 1000,
  61. type: BreadcrumbType.DEFAULT,
  62. };
  63. }
  64. export function ReplayBlurFrameFixture(
  65. fields: TestableFrame<'ui.blur'>
  66. ): MockFrame<'ui.blur'> {
  67. return {
  68. category: 'ui.blur',
  69. message: fields.message,
  70. timestamp: fields.timestamp.getTime() / 1000,
  71. type: BreadcrumbType.DEFAULT,
  72. };
  73. }
  74. export function ReplayFocusFrameFixture(
  75. fields: TestableFrame<'ui.focus'>
  76. ): MockFrame<'ui.focus'> {
  77. return {
  78. category: 'ui.focus',
  79. message: fields.message,
  80. timestamp: fields.timestamp.getTime() / 1000,
  81. type: BreadcrumbType.DEFAULT,
  82. };
  83. }
  84. export function ReplaySlowClickFrameFixture(
  85. fields: TestableFrame<'ui.slowClickDetected'>
  86. ): MockFrame<'ui.slowClickDetected'> {
  87. return {
  88. category: 'ui.slowClickDetected',
  89. data: fields.data ?? {
  90. clickCount: undefined,
  91. endReason: '',
  92. timeAfterClickMs: 5,
  93. url: '/',
  94. },
  95. message: fields.message,
  96. timestamp: fields.timestamp.getTime() / 1000,
  97. type: BreadcrumbType.DEFAULT,
  98. };
  99. }
  100. export function ReplayMutationFrameFixture(
  101. fields: TestableFrame<'replay.mutations'>
  102. ): MockFrame<'replay.mutations'> {
  103. return {
  104. category: 'replay.mutations',
  105. data: fields.data ?? {
  106. count: 1100,
  107. limit: true,
  108. },
  109. message: fields.message,
  110. timestamp: fields.timestamp.getTime() / 1000,
  111. type: '',
  112. };
  113. }
  114. export function ReplayNavFrameFixture(
  115. fields: TestableFrame<'navigation'>
  116. ): MockFrame<'navigation'> {
  117. return {
  118. category: 'navigation',
  119. data: fields.data ?? {
  120. from: '',
  121. to: '',
  122. },
  123. message: fields.message ?? '',
  124. timestamp: fields.timestamp.getTime() / 1000,
  125. type: '',
  126. };
  127. }