@atlaskit/react-ufo 2.3.2 → 2.4.0

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 (33) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/common/constants.js +2 -1
  3. package/dist/cjs/create-payload/common/utils/index.js +61 -2
  4. package/dist/cjs/create-payload/index.js +22 -47
  5. package/dist/cjs/vc/index.js +3 -4
  6. package/dist/cjs/vc/vc-observer/index.js +6 -0
  7. package/dist/es2019/common/constants.js +2 -1
  8. package/dist/es2019/create-payload/common/utils/index.js +53 -2
  9. package/dist/es2019/create-payload/index.js +5 -31
  10. package/dist/es2019/vc/index.js +3 -4
  11. package/dist/es2019/vc/vc-observer/index.js +3 -0
  12. package/dist/esm/common/constants.js +2 -1
  13. package/dist/esm/create-payload/common/utils/index.js +57 -2
  14. package/dist/esm/create-payload/index.js +7 -32
  15. package/dist/esm/vc/index.js +3 -4
  16. package/dist/esm/vc/vc-observer/index.js +6 -0
  17. package/dist/types/common/constants.d.ts +1 -1
  18. package/dist/types/common/vc/types.d.ts +1 -1
  19. package/dist/types/create-payload/common/types.d.ts +1 -1
  20. package/dist/types/create-payload/common/utils/index.d.ts +15 -1
  21. package/dist/types/create-payload/index.d.ts +144 -144
  22. package/dist/types/interaction-context/index.d.ts +1 -1
  23. package/dist/types/vc/index.d.ts +3 -0
  24. package/dist/types/vc/vc-observer/index.d.ts +2 -1
  25. package/dist/types-ts4.5/common/constants.d.ts +1 -1
  26. package/dist/types-ts4.5/common/vc/types.d.ts +1 -1
  27. package/dist/types-ts4.5/create-payload/common/types.d.ts +1 -1
  28. package/dist/types-ts4.5/create-payload/common/utils/index.d.ts +15 -1
  29. package/dist/types-ts4.5/create-payload/index.d.ts +144 -144
  30. package/dist/types-ts4.5/interaction-context/index.d.ts +1 -1
  31. package/dist/types-ts4.5/vc/index.d.ts +3 -0
  32. package/dist/types-ts4.5/vc/vc-observer/index.d.ts +2 -1
  33. package/package.json +4 -1
@@ -21,7 +21,7 @@ import * as resourceTiming from '../resource-timing';
21
21
  import { roundEpsilon } from '../round-number';
22
22
  import * as ssr from '../ssr';
23
23
  import { getVCObserver } from '../vc';
24
- import { isSegmentLabel, sanitizeUfoName } from './common/utils';
24
+ import { buildSegmentTree, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
25
25
  function getUfoNameOverride(interaction) {
26
26
  var ufoName = interaction.ufoName,
27
27
  apdex = interaction.apdex;
@@ -39,17 +39,6 @@ function getUfoNameOverride(interaction) {
39
39
  return ufoName;
40
40
  }
41
41
  }
42
- function stringifyLabelStackFully(labelStack) {
43
- return labelStack.map(function (l) {
44
- if (isSegmentLabel(l)) {
45
- return "".concat(l.name, ":").concat(l.segmentId);
46
- }
47
- return l.name;
48
- }).join('/');
49
- }
50
- function labelStackStartWith(labelStack, startWith) {
51
- return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
52
- }
53
42
  function getEarliestLegacyStopTime(interaction, labelStack) {
54
43
  var earliestLegacyStopTime = null;
55
44
  interaction.apdex.forEach(function (a) {
@@ -335,18 +324,6 @@ var getTracingContextData = function getTracingContextData(interaction) {
335
324
  }
336
325
  return tracingContextData;
337
326
  };
338
-
339
- // interaction metric
340
-
341
- function optimizeLabelStack(labelStack) {
342
- return labelStack.map(function (ls) {
343
- return _objectSpread({
344
- n: ls.name
345
- }, ls.segmentId ? {
346
- s: ls.segmentId
347
- } : {});
348
- });
349
- }
350
327
  function optimizeCustomData(interaction) {
351
328
  var customData = interaction.customData,
352
329
  legacyMetrics = interaction.legacyMetrics;
@@ -520,7 +497,7 @@ function optimizeRequestInfo(requestInfo, interactionStart) {
520
497
  return updatedRequestInfo;
521
498
  }
522
499
  function optimizeCustomTimings(customTimings, interactionStart) {
523
- var updatedCustomTimings = customTimings.reduce(function (result, item) {
500
+ return customTimings.reduce(function (result, item) {
524
501
  Object.keys(item.data).forEach(function (key) {
525
502
  if (item.data[key].startTime >= interactionStart) {
526
503
  result.push({
@@ -534,7 +511,6 @@ function optimizeCustomTimings(customTimings, interactionStart) {
534
511
  });
535
512
  return result;
536
513
  }, []);
537
- return updatedCustomTimings;
538
514
  }
539
515
  function optimizeMarks(marks) {
540
516
  return marks.map(function (_ref4) {
@@ -559,8 +535,6 @@ function optimizeApdex(apdex) {
559
535
  } : {});
560
536
  });
561
537
  }
562
-
563
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
564
538
  function objectToArray() {
565
539
  var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
566
540
  return Object.keys(obj).reduce(function (result, key) {
@@ -569,9 +543,7 @@ function objectToArray() {
569
543
  data: obj[key]
570
544
  });
571
545
  return result;
572
- },
573
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
574
- []);
546
+ }, []);
575
547
  }
576
548
  function getBM3SubmetricsTimings(submetrics) {
577
549
  if (!submetrics) {
@@ -647,6 +619,9 @@ function createInteractionMetricsPayload(interaction, interactionId) {
647
619
  var pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
648
620
  var pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
649
621
  var segments = config.killswitchNestedSegments ? [] : knownSegments;
622
+ var segmentTree = buildSegmentTree(segments.map(function (segment) {
623
+ return segment.labelStack;
624
+ }));
650
625
  var isDetailedPayload = pageVisibilityAtTTAI === 'visible';
651
626
  var isPageLoad = type === 'page_load';
652
627
  var calculatePageVisibilityFromTheStartOfPageLoad = config.enableBetterPageVisibilityApi && isPageLoad;
@@ -752,7 +727,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
752
727
  apdex: optimizeApdex(interaction.apdex),
753
728
  end: Math.round(end),
754
729
  start: Math.round(start),
755
- segments: segments.map(function (_ref7) {
730
+ segments: REACT_UFO_VERSION === '2.0.0' ? segmentTree : segments.map(function (_ref7) {
756
731
  var labelStack = _ref7.labelStack,
757
732
  others = _objectWithoutProperties(_ref7, _excluded4);
758
733
  return _objectSpread(_objectSpread({}, others), {}, {
@@ -1,9 +1,8 @@
1
1
  import { VCObserver } from './vc-observer';
2
- var instance = null;
3
2
  export var getVCObserver = function getVCObserver() {
4
3
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
5
- if (instance === null) {
6
- instance = new VCObserver(opts);
4
+ if (!globalThis.__vcObserver) {
5
+ globalThis.__vcObserver = new VCObserver(opts);
7
6
  }
8
- return instance;
7
+ return globalThis.__vcObserver;
9
8
  };
@@ -357,6 +357,12 @@ export var VCObserver = /*#__PURE__*/function () {
357
357
  var stopTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : performance.now();
358
358
  this.observers.setReactRootRenderStop(stopTime);
359
359
  }
360
+ }, {
361
+ key: "abortObservation",
362
+ value: function abortObservation() {
363
+ var abortReason = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'custom';
364
+ this.setAbortReason(abortReason, performance.now());
365
+ }
360
366
  }, {
361
367
  key: "setAbortReason",
362
368
  value: function setAbortReason(abort, timestamp) {
@@ -1 +1 @@
1
- export declare const REACT_UFO_VERSION = "1.0.1";
1
+ export declare const REACT_UFO_VERSION: string;
@@ -4,7 +4,7 @@ export declare const AbortEvent: {
4
4
  readonly keydown: "keydown";
5
5
  readonly resize: "resize";
6
6
  };
7
- export type VCAbortReason = 'scroll' | 'keypress' | 'resize' | 'error' | 'not-supported';
7
+ export type VCAbortReason = 'custom' | 'scroll' | 'keypress' | 'resize' | 'error' | 'not-supported';
8
8
  export type VCAbortReasonType = {
9
9
  reason: null | VCAbortReason;
10
10
  info: string;
@@ -1,4 +1,4 @@
1
1
  export type OptimizedLabelStack = {
2
2
  n: string;
3
3
  s?: string;
4
- }[];
4
+ }[] | string;
@@ -1,3 +1,17 @@
1
- import { type SegmentLabel } from '../../../interaction-context';
1
+ import type { LabelStack, SegmentLabel } from '../../../interaction-context';
2
+ export type SegmentItem = {
3
+ n: string;
4
+ c?: Record<string, SegmentItem>;
5
+ };
6
+ export type SegmentTree = {
7
+ r: SegmentItem;
8
+ };
2
9
  export declare const sanitizeUfoName: (name: string) => string;
3
10
  export declare function isSegmentLabel(obj: any): obj is SegmentLabel;
11
+ export declare function buildSegmentTree(labelStacks: LabelStack[]): SegmentTree;
12
+ export declare function stringifyLabelStackFully(labelStack: LabelStack): string;
13
+ export declare function labelStackStartWith(labelStack: LabelStack, startWith: LabelStack): boolean;
14
+ export declare function optimizeLabelStack(labelStack: LabelStack): string | {
15
+ s?: string | undefined;
16
+ n: string;
17
+ }[];