replayBreadcrumbFrameData.ts 3.2 KB

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