@servicetitan/journey 3.0.0 → 3.0.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.
@@ -6,7 +6,7 @@ export { normalizeTagValue } from '../core/sanitize';
6
6
  *
7
7
  * Prefer exposing the initialized instance as `globalThis.DD_RUM` (ST host:
8
8
  * `datadogGuard`). `sendToDatadog` resolves `DD_RUM` first, then `__stJourney.rum`
9
- * (this fallback), then the bundle's imported `datadogRum`.
9
+ * (this fallback); with neither present the event is dropped.
10
10
  *
11
11
  * Calling `setJourneyRum` while `globalThis.DD_RUM` is already set logs a warning —
12
12
  * the call is redundant because `sendToDatadog` prefers `DD_RUM`.
@@ -1 +1 @@
1
- {"version":3,"file":"datadog.d.ts","sourceRoot":"","sources":["../../src/sinks/datadog.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAUrD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAQhD;AA2BD,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CA0BzD"}
1
+ {"version":3,"file":"datadog.d.ts","sourceRoot":"","sources":["../../src/sinks/datadog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAkBrD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAQhD;AAsBD,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAyBzD"}
@@ -1,4 +1,3 @@
1
- import { datadogRum } from '@datadog/browser-rum';
2
1
  import { isSanitizedJourneyEvent, sanitizeJourneyEvent } from '../core/sanitize';
3
2
  import { getJourneyRumFallback, setJourneyRumFallback } from '../global';
4
3
  export { normalizeTagValue } from '../core/sanitize';
@@ -13,7 +12,7 @@ function getDdRum() {
13
12
  *
14
13
  * Prefer exposing the initialized instance as `globalThis.DD_RUM` (ST host:
15
14
  * `datadogGuard`). `sendToDatadog` resolves `DD_RUM` first, then `__stJourney.rum`
16
- * (this fallback), then the bundle's imported `datadogRum`.
15
+ * (this fallback); with neither present the event is dropped.
17
16
  *
18
17
  * Calling `setJourneyRum` while `globalThis.DD_RUM` is already set logs a warning —
19
18
  * the call is redundant because `sendToDatadog` prefers `DD_RUM`.
@@ -25,12 +24,8 @@ function getDdRum() {
25
24
  setJourneyRumFallback(rum);
26
25
  }
27
26
  function resolveRum() {
28
- const ddRum = getDdRum();
29
- if (ddRum) {
30
- return ddRum;
31
- }
32
- const shared = getJourneyRumFallback();
33
- return shared !== null && shared !== void 0 ? shared : datadogRum;
27
+ var _getDdRum;
28
+ return (_getDdRum = getDdRum()) !== null && _getDdRum !== void 0 ? _getDdRum : getJourneyRumFallback();
34
29
  }
35
30
  function toDatadogStep(step) {
36
31
  /* eslint-disable @typescript-eslint/naming-convention -- Datadog RUM wire format (snake_case) */ return {
@@ -51,8 +46,7 @@ function toDatadogStep(step) {
51
46
  /* eslint-enable @typescript-eslint/naming-convention */ }
52
47
  /** Ship one terminal journey as a RUM custom action (`user_journey`). */ export function sendToDatadog(payload) {
53
48
  const rum = resolveRum();
54
- // Skip bad/missing host stubs uninit RUM still buffers addAction safely.
55
- if (typeof rum.addAction !== 'function') {
49
+ if (!rum || typeof rum.addAction !== 'function') {
56
50
  return;
57
51
  }
58
52
  const j = isSanitizedJourneyEvent(payload) ? payload.journey : sanitizeJourneyEvent(payload).journey;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sinks/datadog.ts"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\n\nimport { isSanitizedJourneyEvent, sanitizeJourneyEvent } from '../core/sanitize';\nimport { getJourneyRumFallback, setJourneyRumFallback } from '../global';\nimport type { JourneyEvent, JourneyStepEvent } from '../core/types';\n\nexport { normalizeTagValue } from '../core/sanitize';\n\nconst JOURNEY_ACTION = 'user_journey';\n\nconst DD_RUM_KEY = 'DD_RUM';\n\nfunction getDdRum(): typeof datadogRum | undefined {\n return (globalThis as Record<string, unknown>)[DD_RUM_KEY] as typeof datadogRum | undefined;\n}\n\n/**\n * Publish a RUM instance for MFE bundles to share — **only needed if\n * `globalThis.DD_RUM` is not set**.\n *\n * Prefer exposing the initialized instance as `globalThis.DD_RUM` (ST host:\n * `datadogGuard`). `sendToDatadog` resolves `DD_RUM` first, then `__stJourney.rum`\n * (this fallback), then the bundle's imported `datadogRum`.\n *\n * Calling `setJourneyRum` while `globalThis.DD_RUM` is already set logs a warning —\n * the call is redundant because `sendToDatadog` prefers `DD_RUM`.\n */\nexport function setJourneyRum(rum: unknown): void {\n if (getDdRum()) {\n // eslint-disable-next-line no-console -- soft-deprecate redundant bridge use\n console.warn(\n '[journey] setJourneyRum() is unnecessary when globalThis.DD_RUM is set — sendToDatadog already prefers DD_RUM'\n );\n }\n setJourneyRumFallback(rum);\n}\n\nfunction resolveRum(): typeof datadogRum {\n const ddRum = getDdRum();\n if (ddRum) {\n return ddRum;\n }\n const shared = getJourneyRumFallback();\n return (shared as typeof datadogRum | undefined) ?? datadogRum;\n}\n\nfunction toDatadogStep(step: JourneyStepEvent) {\n /* eslint-disable @typescript-eslint/naming-convention -- Datadog RUM wire format (snake_case) */\n return {\n name: step.name,\n start_ms: step.startMs,\n duration_ms: step.durationMs,\n outcome: step.outcome,\n ...(step.reason ? { reason: step.reason } : {}),\n ...(step.httpStatus !== undefined ? { http_status: step.httpStatus } : {}),\n ...(step.attributes && Object.keys(step.attributes).length\n ? { attributes: step.attributes }\n : {}),\n };\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n\n/** Ship one terminal journey as a RUM custom action (`user_journey`). */\nexport function sendToDatadog(payload: JourneyEvent): void {\n const rum = resolveRum();\n // Skip bad/missing host stubs — uninit RUM still buffers addAction safely.\n if (typeof rum.addAction !== 'function') {\n return;\n }\n\n const j = isSanitizedJourneyEvent(payload)\n ? payload.journey\n : sanitizeJourneyEvent(payload).journey;\n /* eslint-disable @typescript-eslint/naming-convention -- Datadog RUM wire format (snake_case) */\n rum.addAction(JOURNEY_ACTION, {\n journey: {\n name: j.name,\n team: j.team,\n group: j.group,\n service: j.service,\n outcome: j.outcome,\n ...(j.reason ? { reason: j.reason } : {}),\n duration_ms: j.durationMs,\n steps: j.steps.map(toDatadogStep),\n ...(j.expected ? { expected: j.expected } : {}),\n ...(j.tags ? { tags: j.tags } : {}),\n },\n });\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n"],"names":["datadogRum","isSanitizedJourneyEvent","sanitizeJourneyEvent","getJourneyRumFallback","setJourneyRumFallback","normalizeTagValue","JOURNEY_ACTION","DD_RUM_KEY","getDdRum","globalThis","setJourneyRum","rum","console","warn","resolveRum","ddRum","shared","toDatadogStep","step","name","start_ms","startMs","duration_ms","durationMs","outcome","reason","httpStatus","undefined","http_status","attributes","Object","keys","length","sendToDatadog","payload","addAction","j","journey","team","group","service","steps","map","expected","tags"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAElD,SAASC,uBAAuB,EAAEC,oBAAoB,QAAQ,mBAAmB;AACjF,SAASC,qBAAqB,EAAEC,qBAAqB,QAAQ,YAAY;AAGzE,SAASC,iBAAiB,QAAQ,mBAAmB;AAErD,MAAMC,iBAAiB;AAEvB,MAAMC,aAAa;AAEnB,SAASC;IACL,OAAO,AAACC,UAAsC,CAACF,WAAW;AAC9D;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASG,cAAcC,GAAY;IACtC,IAAIH,YAAY;QACZ,6EAA6E;QAC7EI,QAAQC,IAAI,CACR;IAER;IACAT,sBAAsBO;AAC1B;AAEA,SAASG;IACL,MAAMC,QAAQP;IACd,IAAIO,OAAO;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UP,EAAEO,QAAQ;YAAC,IAAI,CAAC,CAAC;YAC9C,GAAIP,EAAEQ,IAAI,GAAG;gBAAEA,MAAMR,EAAEQ,IAAI;YAAC,IAAI,CAAC,CAAC;QACtC;IACJ;AACA,sDAAsD,GAC1D"}
1
+ {"version":3,"sources":["../../src/sinks/datadog.ts"],"sourcesContent":["import { isSanitizedJourneyEvent, sanitizeJourneyEvent } from '../core/sanitize';\nimport { getJourneyRumFallback, setJourneyRumFallback } from '../global';\nimport type { JourneyEvent, JourneyStepEvent } from '../core/types';\n\nexport { normalizeTagValue } from '../core/sanitize';\n\nconst JOURNEY_ACTION = 'user_journey';\n\nconst DD_RUM_KEY = 'DD_RUM';\n\n/**\n * Not imported from @datadog/browser-rum on purpose: importing it sets globalThis.DD_RUM at\n * module load, which lets an MFE bundle replace the host's initialized RUM instance.\n */\ninterface RumLike {\n addAction(name: string, context?: object): void;\n}\n\nfunction getDdRum(): RumLike | undefined {\n return (globalThis as Record<string, unknown>)[DD_RUM_KEY] as RumLike | undefined;\n}\n\n/**\n * Publish a RUM instance for MFE bundles to share — **only needed if\n * `globalThis.DD_RUM` is not set**.\n *\n * Prefer exposing the initialized instance as `globalThis.DD_RUM` (ST host:\n * `datadogGuard`). `sendToDatadog` resolves `DD_RUM` first, then `__stJourney.rum`\n * (this fallback); with neither present the event is dropped.\n *\n * Calling `setJourneyRum` while `globalThis.DD_RUM` is already set logs a warning —\n * the call is redundant because `sendToDatadog` prefers `DD_RUM`.\n */\nexport function setJourneyRum(rum: unknown): void {\n if (getDdRum()) {\n // eslint-disable-next-line no-console -- soft-deprecate redundant bridge use\n console.warn(\n '[journey] setJourneyRum() is unnecessary when globalThis.DD_RUM is set — sendToDatadog already prefers DD_RUM'\n );\n }\n setJourneyRumFallback(rum);\n}\n\nfunction resolveRum(): RumLike | undefined {\n return getDdRum() ?? (getJourneyRumFallback() as RumLike | undefined);\n}\n\nfunction toDatadogStep(step: JourneyStepEvent) {\n /* eslint-disable @typescript-eslint/naming-convention -- Datadog RUM wire format (snake_case) */\n return {\n name: step.name,\n start_ms: step.startMs,\n duration_ms: step.durationMs,\n outcome: step.outcome,\n ...(step.reason ? { reason: step.reason } : {}),\n ...(step.httpStatus !== undefined ? { http_status: step.httpStatus } : {}),\n ...(step.attributes && Object.keys(step.attributes).length\n ? { attributes: step.attributes }\n : {}),\n };\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n\n/** Ship one terminal journey as a RUM custom action (`user_journey`). */\nexport function sendToDatadog(payload: JourneyEvent): void {\n const rum = resolveRum();\n if (!rum || typeof rum.addAction !== 'function') {\n return;\n }\n\n const j = isSanitizedJourneyEvent(payload)\n ? payload.journey\n : sanitizeJourneyEvent(payload).journey;\n /* eslint-disable @typescript-eslint/naming-convention -- Datadog RUM wire format (snake_case) */\n rum.addAction(JOURNEY_ACTION, {\n journey: {\n name: j.name,\n team: j.team,\n group: j.group,\n service: j.service,\n outcome: j.outcome,\n ...(j.reason ? { reason: j.reason } : {}),\n duration_ms: j.durationMs,\n steps: j.steps.map(toDatadogStep),\n ...(j.expected ? { expected: j.expected } : {}),\n ...(j.tags ? { tags: j.tags } : {}),\n },\n });\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n"],"names":["isSanitizedJourneyEvent","sanitizeJourneyEvent","getJourneyRumFallback","setJourneyRumFallback","normalizeTagValue","JOURNEY_ACTION","DD_RUM_KEY","getDdRum","globalThis","setJourneyRum","rum","console","warn","resolveRum","toDatadogStep","step","name","start_ms","startMs","duration_ms","durationMs","outcome","reason","httpStatus","undefined","http_status","attributes","Object","keys","length","sendToDatadog","payload","addAction","j","journey","team","group","service","steps","map","expected","tags"],"mappings":"AAAA,SAASA,uBAAuB,EAAEC,oBAAoB,QAAQ,mBAAmB;AACjF,SAASC,qBAAqB,EAAEC,qBAAqB,QAAQ,YAAY;AAGzE,SAASC,iBAAiB,QAAQ,mBAAmB;AAErD,MAAMC,iBAAiB;AAEvB,MAAMC,aAAa;AAUnB,SAASC;IACL,OAAO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AQW,EAAEX,MAAM;YAAC,IAAI,CAAC,CAAC;YACxCH,aAAac,EAAEb,UAAU;YACzBkB,OAAOL,EAAEK,KAAK,CAACC,GAAG,CAACzB;YACnB,GAAImB,EAAEO,QAAQ,GAAG;gBAAEA,UAAUP,EAAEO,QAAQ;YAAC,IAAI,CAAC,CAAC;YAC9C,GAAIP,EAAEQ,IAAI,GAAG;gBAAEA,MAAMR,EAAEQ,IAAI;YAAC,IAAI,CAAC,CAAC;QACtC;IACJ;AACA,sDAAsD,GAC1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/journey",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Critical user journey monitoring — reports good/bad/excluded verdicts to Datadog RUM as a custom action",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/journey",
6
6
  "repository": {
@@ -25,14 +25,12 @@
25
25
  "src"
26
26
  ],
27
27
  "devDependencies": {
28
- "@datadog/browser-rum": "^7.5.0",
29
28
  "@testing-library/jest-dom": "^6.4.2",
30
29
  "@testing-library/react": "^14.2.1",
31
30
  "@types/react": "~18.2.55",
32
31
  "react": "^18.2.0"
33
32
  },
34
33
  "peerDependencies": {
35
- "@datadog/browser-rum": ">=6.19.0",
36
34
  "react": ">=17.0.2"
37
35
  },
38
36
  "publishConfig": {
@@ -41,5 +39,5 @@
41
39
  "cli": {
42
40
  "webpack": false
43
41
  },
44
- "gitHead": "1ebcfc7b65a6b2979cbb89a93d411abe7144ca51"
42
+ "gitHead": "58ea11444816cf865f5ba5af38fbbdc8b69a3211"
45
43
  }
@@ -1,14 +1,7 @@
1
1
  /** @jest-environment jsdom */
2
2
  const addAction = jest.fn();
3
- const importedAddAction = jest.fn();
4
3
  const ddRumAddAction = jest.fn();
5
4
 
6
- jest.mock('@datadog/browser-rum', () => ({
7
- datadogRum: {
8
- addAction: (...args: unknown[]) => importedAddAction(...args),
9
- },
10
- }));
11
-
12
5
  import type { JourneyEvent } from '../../core/types';
13
6
  import { ST_JOURNEY_GLOBAL_KEY, type StJourneyGlobal } from '../../global';
14
7
  import { normalizeTagValue, sendToDatadog, setJourneyRum } from '../../sinks/datadog';
@@ -43,7 +36,6 @@ describe('[journey] setJourneyRum / sendToDatadog', () => {
43
36
 
44
37
  beforeEach(() => {
45
38
  addAction.mockClear();
46
- importedAddAction.mockClear();
47
39
  ddRumAddAction.mockClear();
48
40
  clearJourneyRumFallback();
49
41
  delete (globalThis as Record<string, unknown>)[DD_RUM_KEY];
@@ -59,11 +51,8 @@ describe('[journey] setJourneyRum / sendToDatadog', () => {
59
51
  describe('without a shared RUM instance', () => {
60
52
  const subject = () => sendToDatadog(sampleEvent());
61
53
 
62
- test('falls back to the imported datadogRum', () => {
63
- subject();
64
-
65
- expect(importedAddAction).toHaveBeenCalledTimes(1);
66
- expect(importedAddAction.mock.calls[0][0]).toBe('user_journey');
54
+ test('drops the event without throwing', () => {
55
+ expect(subject).not.toThrow();
67
56
  expect(addAction).not.toHaveBeenCalled();
68
57
  });
69
58
  });
@@ -80,7 +69,6 @@ describe('[journey] setJourneyRum / sendToDatadog', () => {
80
69
 
81
70
  expect(ddRumAddAction).toHaveBeenCalledTimes(1);
82
71
  expect(addAction).not.toHaveBeenCalled();
83
- expect(importedAddAction).not.toHaveBeenCalled();
84
72
  });
85
73
  });
86
74
 
@@ -89,7 +77,6 @@ describe('[journey] setJourneyRum / sendToDatadog', () => {
89
77
  (globalThis as Record<string, unknown>)[DD_RUM_KEY] = {};
90
78
 
91
79
  expect(() => sendToDatadog(sampleEvent())).not.toThrow();
92
- expect(importedAddAction).not.toHaveBeenCalled();
93
80
  expect(addAction).not.toHaveBeenCalled();
94
81
  });
95
82
  });
@@ -120,7 +107,6 @@ describe('[journey] setJourneyRum / sendToDatadog', () => {
120
107
  subject();
121
108
 
122
109
  expect(addAction).toHaveBeenCalledTimes(1);
123
- expect(importedAddAction).not.toHaveBeenCalled();
124
110
  expect(warnSpy).not.toHaveBeenCalled();
125
111
  });
126
112
 
@@ -1,5 +1,3 @@
1
- import { datadogRum } from '@datadog/browser-rum';
2
-
3
1
  import { isSanitizedJourneyEvent, sanitizeJourneyEvent } from '../core/sanitize';
4
2
  import { getJourneyRumFallback, setJourneyRumFallback } from '../global';
5
3
  import type { JourneyEvent, JourneyStepEvent } from '../core/types';
@@ -10,8 +8,16 @@ const JOURNEY_ACTION = 'user_journey';
10
8
 
11
9
  const DD_RUM_KEY = 'DD_RUM';
12
10
 
13
- function getDdRum(): typeof datadogRum | undefined {
14
- return (globalThis as Record<string, unknown>)[DD_RUM_KEY] as typeof datadogRum | undefined;
11
+ /**
12
+ * Not imported from @datadog/browser-rum on purpose: importing it sets globalThis.DD_RUM at
13
+ * module load, which lets an MFE bundle replace the host's initialized RUM instance.
14
+ */
15
+ interface RumLike {
16
+ addAction(name: string, context?: object): void;
17
+ }
18
+
19
+ function getDdRum(): RumLike | undefined {
20
+ return (globalThis as Record<string, unknown>)[DD_RUM_KEY] as RumLike | undefined;
15
21
  }
16
22
 
17
23
  /**
@@ -20,7 +26,7 @@ function getDdRum(): typeof datadogRum | undefined {
20
26
  *
21
27
  * Prefer exposing the initialized instance as `globalThis.DD_RUM` (ST host:
22
28
  * `datadogGuard`). `sendToDatadog` resolves `DD_RUM` first, then `__stJourney.rum`
23
- * (this fallback), then the bundle's imported `datadogRum`.
29
+ * (this fallback); with neither present the event is dropped.
24
30
  *
25
31
  * Calling `setJourneyRum` while `globalThis.DD_RUM` is already set logs a warning —
26
32
  * the call is redundant because `sendToDatadog` prefers `DD_RUM`.
@@ -35,13 +41,8 @@ export function setJourneyRum(rum: unknown): void {
35
41
  setJourneyRumFallback(rum);
36
42
  }
37
43
 
38
- function resolveRum(): typeof datadogRum {
39
- const ddRum = getDdRum();
40
- if (ddRum) {
41
- return ddRum;
42
- }
43
- const shared = getJourneyRumFallback();
44
- return (shared as typeof datadogRum | undefined) ?? datadogRum;
44
+ function resolveRum(): RumLike | undefined {
45
+ return getDdRum() ?? (getJourneyRumFallback() as RumLike | undefined);
45
46
  }
46
47
 
47
48
  function toDatadogStep(step: JourneyStepEvent) {
@@ -63,8 +64,7 @@ function toDatadogStep(step: JourneyStepEvent) {
63
64
  /** Ship one terminal journey as a RUM custom action (`user_journey`). */
64
65
  export function sendToDatadog(payload: JourneyEvent): void {
65
66
  const rum = resolveRum();
66
- // Skip bad/missing host stubs uninit RUM still buffers addAction safely.
67
- if (typeof rum.addAction !== 'function') {
67
+ if (!rum || typeof rum.addAction !== 'function') {
68
68
  return;
69
69
  }
70
70