@servicetitan/journey 2.1.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.
Files changed (163) hide show
  1. package/README.md +1 -1
  2. package/dist/__test-utils__/test-runtime.d.ts.map +1 -1
  3. package/dist/__test-utils__/test-runtime.js +9 -2
  4. package/dist/__test-utils__/test-runtime.js.map +1 -1
  5. package/dist/__tests__/core/sanitize.test.d.ts +2 -0
  6. package/dist/__tests__/core/sanitize.test.d.ts.map +1 -0
  7. package/dist/__tests__/hardening.test.d.ts +2 -0
  8. package/dist/__tests__/hardening.test.d.ts.map +1 -0
  9. package/dist/__tests__/integrations/host-mfe.test.d.ts +2 -0
  10. package/dist/__tests__/integrations/host-mfe.test.d.ts.map +1 -0
  11. package/dist/__tests__/integrations/use-journey-step.test.d.ts +2 -0
  12. package/dist/__tests__/integrations/use-journey-step.test.d.ts.map +1 -0
  13. package/dist/config.d.ts +57 -13
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +87 -24
  16. package/dist/config.js.map +1 -1
  17. package/dist/core/abort-error.d.ts +4 -0
  18. package/dist/core/abort-error.d.ts.map +1 -0
  19. package/dist/core/abort-error.js +22 -0
  20. package/dist/core/abort-error.js.map +1 -0
  21. package/dist/core/api.d.ts +22 -9
  22. package/dist/core/api.d.ts.map +1 -1
  23. package/dist/core/api.js +77 -30
  24. package/dist/core/api.js.map +1 -1
  25. package/dist/core/endpoint-policy.d.ts +14 -4
  26. package/dist/core/endpoint-policy.d.ts.map +1 -1
  27. package/dist/core/endpoint-policy.js +32 -1
  28. package/dist/core/endpoint-policy.js.map +1 -1
  29. package/dist/core/index.d.ts +4 -3
  30. package/dist/core/index.d.ts.map +1 -1
  31. package/dist/core/index.js +3 -3
  32. package/dist/core/index.js.map +1 -1
  33. package/dist/core/limits.d.ts +29 -0
  34. package/dist/core/limits.d.ts.map +1 -0
  35. package/dist/core/limits.js +63 -0
  36. package/dist/core/limits.js.map +1 -0
  37. package/dist/core/request-policy.d.ts +39 -0
  38. package/dist/core/request-policy.d.ts.map +1 -0
  39. package/dist/core/request-policy.js +18 -0
  40. package/dist/core/request-policy.js.map +1 -0
  41. package/dist/core/runtime.d.ts +65 -15
  42. package/dist/core/runtime.d.ts.map +1 -1
  43. package/dist/core/runtime.js +403 -126
  44. package/dist/core/runtime.js.map +1 -1
  45. package/dist/core/sanitize.d.ts +23 -0
  46. package/dist/core/sanitize.d.ts.map +1 -0
  47. package/dist/core/sanitize.js +143 -0
  48. package/dist/core/sanitize.js.map +1 -0
  49. package/dist/core/step-tag.d.ts +25 -6
  50. package/dist/core/step-tag.d.ts.map +1 -1
  51. package/dist/core/step-tag.js +56 -10
  52. package/dist/core/step-tag.js.map +1 -1
  53. package/dist/core/types.d.ts +73 -25
  54. package/dist/core/types.d.ts.map +1 -1
  55. package/dist/core/types.js +4 -1
  56. package/dist/core/types.js.map +1 -1
  57. package/dist/global.d.ts +91 -13
  58. package/dist/global.d.ts.map +1 -1
  59. package/dist/global.js +235 -25
  60. package/dist/global.js.map +1 -1
  61. package/dist/index.d.ts +7 -8
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +4 -6
  64. package/dist/index.js.map +1 -1
  65. package/dist/integrations/axios.d.ts +5 -1
  66. package/dist/integrations/axios.d.ts.map +1 -1
  67. package/dist/integrations/axios.js +146 -34
  68. package/dist/integrations/axios.js.map +1 -1
  69. package/dist/integrations/fetch.d.ts +3 -2
  70. package/dist/integrations/fetch.d.ts.map +1 -1
  71. package/dist/integrations/fetch.js +105 -26
  72. package/dist/integrations/fetch.js.map +1 -1
  73. package/dist/integrations/http-report.d.ts +27 -0
  74. package/dist/integrations/http-report.d.ts.map +1 -0
  75. package/dist/integrations/http-report.js +123 -0
  76. package/dist/integrations/http-report.js.map +1 -0
  77. package/dist/integrations/jquery/index.d.ts +8 -4
  78. package/dist/integrations/jquery/index.d.ts.map +1 -1
  79. package/dist/integrations/jquery/index.js +26 -8
  80. package/dist/integrations/jquery/index.js.map +1 -1
  81. package/dist/integrations/jquery/instrument.d.ts +14 -5
  82. package/dist/integrations/jquery/instrument.d.ts.map +1 -1
  83. package/dist/integrations/jquery/instrument.js +111 -29
  84. package/dist/integrations/jquery/instrument.js.map +1 -1
  85. package/dist/integrations/react/context.d.ts +4 -1
  86. package/dist/integrations/react/context.d.ts.map +1 -1
  87. package/dist/integrations/react/context.js +4 -1
  88. package/dist/integrations/react/context.js.map +1 -1
  89. package/dist/integrations/react/scope.d.ts +14 -3
  90. package/dist/integrations/react/scope.d.ts.map +1 -1
  91. package/dist/integrations/react/scope.js +46 -8
  92. package/dist/integrations/react/scope.js.map +1 -1
  93. package/dist/integrations/react/stable-config-keys.d.ts +6 -0
  94. package/dist/integrations/react/stable-config-keys.d.ts.map +1 -0
  95. package/dist/integrations/react/stable-config-keys.js +21 -0
  96. package/dist/integrations/react/stable-config-keys.js.map +1 -0
  97. package/dist/integrations/react/use-journey-step.d.ts +11 -0
  98. package/dist/integrations/react/use-journey-step.d.ts.map +1 -0
  99. package/dist/integrations/react/use-journey-step.js +19 -0
  100. package/dist/integrations/react/use-journey-step.js.map +1 -0
  101. package/dist/integrations/request-key.d.ts +8 -3
  102. package/dist/integrations/request-key.d.ts.map +1 -1
  103. package/dist/integrations/request-key.js +10 -9
  104. package/dist/integrations/request-key.js.map +1 -1
  105. package/dist/integrations/soft-skip.d.ts +7 -0
  106. package/dist/integrations/soft-skip.d.ts.map +1 -0
  107. package/dist/integrations/soft-skip.js +30 -0
  108. package/dist/integrations/soft-skip.js.map +1 -0
  109. package/dist/sinks/console.d.ts.map +1 -1
  110. package/dist/sinks/console.js +2 -1
  111. package/dist/sinks/console.js.map +1 -1
  112. package/dist/sinks/datadog.d.ts +2 -2
  113. package/dist/sinks/datadog.d.ts.map +1 -1
  114. package/dist/sinks/datadog.js +18 -28
  115. package/dist/sinks/datadog.js.map +1 -1
  116. package/package.json +2 -4
  117. package/src/__test-utils__/test-runtime.ts +9 -2
  118. package/src/__tests__/config.test.ts +150 -31
  119. package/src/__tests__/core/ambient.test.ts +16 -10
  120. package/src/__tests__/core/api.test.ts +7 -7
  121. package/src/__tests__/core/define-journey.test.ts +28 -11
  122. package/src/__tests__/core/requests.test.ts +49 -31
  123. package/src/__tests__/core/runtime.test.ts +67 -20
  124. package/src/__tests__/core/sanitize.test.ts +69 -0
  125. package/src/__tests__/core/step.test.ts +132 -36
  126. package/src/__tests__/core/timeouts.test.ts +69 -4
  127. package/src/__tests__/global.test.ts +44 -3
  128. package/src/__tests__/hardening.test.ts +613 -0
  129. package/src/__tests__/integrations/axios.test.ts +247 -27
  130. package/src/__tests__/integrations/expose-app-journey.test.ts +9 -3
  131. package/src/__tests__/integrations/fetch.test.ts +153 -19
  132. package/src/__tests__/integrations/host-mfe.test.ts +548 -0
  133. package/src/__tests__/integrations/jquery.test.ts +209 -34
  134. package/src/__tests__/integrations/scope.test.tsx +160 -2
  135. package/src/__tests__/integrations/use-journey-step.test.tsx +43 -0
  136. package/src/__tests__/sinks/console.test.ts +9 -4
  137. package/src/__tests__/sinks/datadog.test.ts +48 -15
  138. package/src/config.ts +162 -38
  139. package/src/core/abort-error.ts +24 -0
  140. package/src/core/api.ts +83 -33
  141. package/src/core/endpoint-policy.ts +46 -4
  142. package/src/core/index.ts +12 -4
  143. package/src/core/limits.ts +73 -0
  144. package/src/core/request-policy.ts +66 -0
  145. package/src/core/runtime.ts +507 -133
  146. package/src/core/sanitize.ts +177 -0
  147. package/src/core/step-tag.ts +82 -12
  148. package/src/core/types.ts +79 -25
  149. package/src/global.ts +312 -42
  150. package/src/index.ts +17 -17
  151. package/src/integrations/axios.ts +183 -45
  152. package/src/integrations/fetch.ts +125 -39
  153. package/src/integrations/http-report.ts +184 -0
  154. package/src/integrations/jquery/index.ts +34 -10
  155. package/src/integrations/jquery/instrument.ts +126 -42
  156. package/src/integrations/react/context.ts +4 -1
  157. package/src/integrations/react/scope.tsx +59 -9
  158. package/src/integrations/react/stable-config-keys.ts +28 -0
  159. package/src/integrations/react/use-journey-step.ts +31 -0
  160. package/src/integrations/request-key.ts +18 -10
  161. package/src/integrations/soft-skip.ts +35 -0
  162. package/src/sinks/console.ts +2 -1
  163. package/src/sinks/datadog.ts +35 -41
package/dist/global.js CHANGED
@@ -1,30 +1,44 @@
1
1
  /** Force-enable journey host wiring outside go* hosts (`__stJourney.enable()`). */ export const JOURNEY_ENABLED_STORAGE_KEY = 'st:journey:enabled';
2
2
  /** Opt-in journey console logging (`__stJourney.enableDebugging()`). */ export const JOURNEY_DEBUG_STORAGE_KEY = 'st:journey:debug';
3
3
  /** @internal Shared cross-bundle bag on globalThis (`rum` fallback + DevTools helpers). */ export const ST_JOURNEY_GLOBAL_KEY = '__stJourney';
4
- let runtimeSeq = 0;
4
+ /** Bump when shared bag shape / policy semantics change incompatibly. */ export const ST_JOURNEY_SCHEMA_VERSION = 2;
5
+ let warnedMissingSlowRequests = false;
6
+ let debugEnabledCache;
7
+ const MAX_INSTRUMENT_RECORDS = 32;
8
+ function storageFor(key) {
9
+ return key === JOURNEY_DEBUG_STORAGE_KEY ? globalThis.sessionStorage : globalThis.localStorage;
10
+ }
5
11
  function readFlag(key) {
6
12
  try {
7
- var _globalThis_localStorage;
8
- return ((_globalThis_localStorage = globalThis.localStorage) === null || _globalThis_localStorage === void 0 ? void 0 : _globalThis_localStorage.getItem(key)) === 'true';
13
+ var _storageFor;
14
+ return ((_storageFor = storageFor(key)) === null || _storageFor === void 0 ? void 0 : _storageFor.getItem(key)) === 'true';
9
15
  } catch (unused) {
10
16
  return false;
11
17
  }
12
18
  }
13
19
  function writeFlag(key, on) {
14
20
  try {
21
+ const storage = storageFor(key);
15
22
  if (on) {
16
- var _globalThis_localStorage;
17
- (_globalThis_localStorage = globalThis.localStorage) === null || _globalThis_localStorage === void 0 ? void 0 : _globalThis_localStorage.setItem(key, 'true');
23
+ storage === null || storage === void 0 ? void 0 : storage.setItem(key, 'true');
18
24
  } else {
19
- var _globalThis_localStorage1;
20
- (_globalThis_localStorage1 = globalThis.localStorage) === null || _globalThis_localStorage1 === void 0 ? void 0 : _globalThis_localStorage1.removeItem(key);
25
+ storage === null || storage === void 0 ? void 0 : storage.removeItem(key);
21
26
  }
22
27
  } catch (unused) {
23
28
  // ignore storage failures (privacy mode, non-browser)
24
29
  }
25
30
  }
26
- /** True when `localStorage['st:journey:enabled'] === 'true'` (force-on outside go*). */ export function isJourneyEnabled() {
27
- return readFlag(JOURNEY_ENABLED_STORAGE_KEY);
31
+ /**
32
+ * Host default for journey wiring (e.g. RUM initialized). Stored on `__stJourney` so
33
+ * MFEs see the same value without importing Datadog. Call once after RUM init.
34
+ */ export function setJourneyDefaultEnabled(enabled) {
35
+ ensureGlobal().defaultEnabled = enabled === true;
36
+ }
37
+ /**
38
+ * True when the host default is on or force-enable is set
39
+ * (`st:journey:enabled` / `__stJourney.enable()`).
40
+ */ export function isJourneyEnabled() {
41
+ return ensureGlobal().defaultEnabled === true || readFlag(JOURNEY_ENABLED_STORAGE_KEY);
28
42
  }
29
43
  /** Set the force-enable flag. Reload after calling from DevTools. */ export function enableJourney() {
30
44
  writeFlag(JOURNEY_ENABLED_STORAGE_KEY, true);
@@ -32,18 +46,55 @@ function writeFlag(key, on) {
32
46
  /** Clear the force-enable flag. Reload after calling from DevTools. */ export function disableJourney() {
33
47
  writeFlag(JOURNEY_ENABLED_STORAGE_KEY, false);
34
48
  }
35
- /** True when `localStorage['st:journey:debug'] === 'true'`. */ export function isJourneyDebugEnabled() {
36
- return readFlag(JOURNEY_DEBUG_STORAGE_KEY);
49
+ /** True when `sessionStorage['st:journey:debug'] === 'true'`. */ export function isJourneyDebugEnabled() {
50
+ const next = readFlag(JOURNEY_DEBUG_STORAGE_KEY);
51
+ if (debugEnabledCache !== next) {
52
+ debugEnabledCache = next;
53
+ }
54
+ return debugEnabledCache;
37
55
  }
38
56
  /** Set the console-debug flag. Reload after calling from DevTools. */ export function enableJourneyDebugging() {
39
57
  writeFlag(JOURNEY_DEBUG_STORAGE_KEY, true);
58
+ debugEnabledCache = true;
40
59
  }
41
60
  /** Clear the console-debug flag. Reload after calling from DevTools. */ export function disableJourneyDebugging() {
42
61
  writeFlag(JOURNEY_DEBUG_STORAGE_KEY, false);
62
+ debugEnabledCache = false;
43
63
  }
44
64
  function hasRum() {
45
65
  return globalThis.DD_RUM != null || getJourneyRumFallback() != null;
46
66
  }
67
+ function snapshotOf(entry) {
68
+ if (entry == null || typeof entry !== 'object') {
69
+ return undefined;
70
+ }
71
+ const rec = entry;
72
+ try {
73
+ if (typeof rec.getSnapshot === 'function') {
74
+ var _rec_id, _withId_policyOverlay;
75
+ const snap = rec.getSnapshot();
76
+ const withId = snap.id ? snap : {
77
+ ...snap,
78
+ id: (_rec_id = rec.id) !== null && _rec_id !== void 0 ? _rec_id : ''
79
+ };
80
+ return {
81
+ ...withId,
82
+ policyOverlay: (_withId_policyOverlay = withId.policyOverlay) !== null && _withId_policyOverlay !== void 0 ? _withId_policyOverlay : {
83
+ slowRequests: false,
84
+ httpAbortedRequests: false,
85
+ httpClientErrorRequests: false,
86
+ autoAttributeRequests: false
87
+ }
88
+ };
89
+ }
90
+ if (typeof rec.getDebugSnapshot === 'function') {
91
+ return rec.getDebugSnapshot();
92
+ }
93
+ } catch (unused) {
94
+ return undefined;
95
+ }
96
+ return undefined;
97
+ }
47
98
  function buildDebugState(runtimes) {
48
99
  if (!isJourneyDebugEnabled()) {
49
100
  return {
@@ -57,10 +108,16 @@ function buildDebugState(runtimes) {
57
108
  enabled: isJourneyEnabled(),
58
109
  debug: true,
59
110
  hasRum: hasRum(),
60
- runtimes: runtimes.map((entry)=>({
61
- id: entry.id,
62
- ...entry.getSnapshot()
63
- }))
111
+ runtimes: runtimes.map(snapshotOf).filter((snap)=>snap != null)
112
+ };
113
+ }
114
+ function createEmptyPolicies() {
115
+ return {
116
+ slowRequestsConfigured: false,
117
+ httpAbortedRequests: 'continue',
118
+ httpClientErrorRequests: 'continue',
119
+ autoAttributeRequests: true,
120
+ locked: false
64
121
  };
65
122
  }
66
123
  function ensureGlobal() {
@@ -69,12 +126,35 @@ function ensureGlobal() {
69
126
  const existing = g[ST_JOURNEY_GLOBAL_KEY];
70
127
  // Reuse when a prior load already installed the full surface (incl. enable).
71
128
  if ((existing === null || existing === void 0 ? void 0 : existing.runtimeRegistrations) && typeof existing.enable === 'function') {
129
+ var _existing, _policies, _existing1, _instrumentedAxios, _existing2, _instrumentedFetch, _existing3, _instrumentedJquery, _existing4, _instrumentRecords;
130
+ if (existing.schemaVersion != null && existing.schemaVersion !== ST_JOURNEY_SCHEMA_VERSION) {
131
+ // eslint-disable-next-line no-console -- cross-bundle version skew
132
+ console.warn(`[journey] __stJourney.schemaVersion mismatch: bag=${existing.schemaVersion}, package=${ST_JOURNEY_SCHEMA_VERSION}`);
133
+ } else {
134
+ var _existing5, _schemaVersion;
135
+ (_schemaVersion = (_existing5 = existing).schemaVersion) !== null && _schemaVersion !== void 0 ? _schemaVersion : _existing5.schemaVersion = ST_JOURNEY_SCHEMA_VERSION;
136
+ }
137
+ (_policies = (_existing = existing).policies) !== null && _policies !== void 0 ? _policies : _existing.policies = createEmptyPolicies();
138
+ if (existing.policies.locked !== true && existing.policies.locked !== false) {
139
+ existing.policies.locked = false;
140
+ }
141
+ (_instrumentedAxios = (_existing1 = existing).instrumentedAxios) !== null && _instrumentedAxios !== void 0 ? _instrumentedAxios : _existing1.instrumentedAxios = new WeakSet();
142
+ (_instrumentedFetch = (_existing2 = existing).instrumentedFetch) !== null && _instrumentedFetch !== void 0 ? _instrumentedFetch : _existing2.instrumentedFetch = new WeakSet();
143
+ (_instrumentedJquery = (_existing3 = existing).instrumentedJquery) !== null && _instrumentedJquery !== void 0 ? _instrumentedJquery : _existing3.instrumentedJquery = new WeakSet();
144
+ (_instrumentRecords = (_existing4 = existing).instrumentRecords) !== null && _instrumentRecords !== void 0 ? _instrumentRecords : _existing4.instrumentRecords = [];
72
145
  return existing;
73
146
  }
74
147
  const runtimes = (_ref = existing === null || existing === void 0 ? void 0 : existing.runtimeRegistrations) !== null && _ref !== void 0 ? _ref : [];
75
148
  const api = {
76
149
  rum: existing === null || existing === void 0 ? void 0 : existing.rum,
150
+ schemaVersion: ST_JOURNEY_SCHEMA_VERSION,
151
+ defaultEnabled: (existing === null || existing === void 0 ? void 0 : existing.defaultEnabled) === true,
77
152
  runtimeRegistrations: runtimes,
153
+ policies: createEmptyPolicies(),
154
+ instrumentedAxios: new WeakSet(),
155
+ instrumentedFetch: new WeakSet(),
156
+ instrumentedJquery: new WeakSet(),
157
+ instrumentRecords: [],
78
158
  enable: enableJourney,
79
159
  disable: disableJourney,
80
160
  isEnabled: isJourneyEnabled,
@@ -88,19 +168,112 @@ function ensureGlobal() {
88
168
  g[ST_JOURNEY_GLOBAL_KEY] = api;
89
169
  return api;
90
170
  }
171
+ /** @internal Shared policies bag. */ export function getSharedPolicies() {
172
+ return ensureGlobal().policies;
173
+ }
174
+ export function areSharedPoliciesLocked() {
175
+ return ensureGlobal().policies.locked === true;
176
+ }
177
+ function freezePolicies(policies) {
178
+ const next = {
179
+ ...policies,
180
+ locked: true
181
+ };
182
+ if (next.slowRequests) {
183
+ const endpoints = next.slowRequests.endpoints ? Object.freeze([
184
+ ...next.slowRequests.endpoints
185
+ ]) : next.slowRequests.endpoints;
186
+ next.slowRequests = Object.freeze({
187
+ ...next.slowRequests,
188
+ endpoints
189
+ });
190
+ }
191
+ return Object.freeze(next);
192
+ }
91
193
  /**
92
- * @internal Register this bundle's module runtime on `__stJourney` so DevTools can
93
- * list every host/MFE engine copy on the page.
94
- */ export function registerJourneyRuntime(runtime) {
95
- const globalApi = ensureGlobal();
96
- const id = `runtime-${++runtimeSeq}`;
97
- globalApi.runtimeRegistrations.push({
98
- id,
99
- getSnapshot: ()=>runtime.getDebugSnapshot()
194
+ * First writer: merge `patch` into the shared bag and freeze it.
195
+ * Returns false when already locked (caller should overlay locally instead).
196
+ */ export function seedSharedPolicies(patch) {
197
+ const api = ensureGlobal();
198
+ if (api.policies.locked) {
199
+ return false;
200
+ }
201
+ api.policies = freezePolicies({
202
+ ...api.policies,
203
+ ...patch
100
204
  });
205
+ return true;
206
+ }
207
+ export function getAutoAttributeRequests() {
208
+ return ensureGlobal().policies.autoAttributeRequests !== false;
101
209
  }
102
- /** @internal Ensure `__stJourney` exists (idempotent). */ export function installJourneyGlobal() {
103
- ensureGlobal();
210
+ export function getHttpAbortedRequestsPolicy() {
211
+ return ensureGlobal().policies.httpAbortedRequests;
212
+ }
213
+ export function getHttpClientErrorRequestsPolicy() {
214
+ return ensureGlobal().policies.httpClientErrorRequests;
215
+ }
216
+ export function getSharedSlowRequests() {
217
+ return ensureGlobal().policies.slowRequests;
218
+ }
219
+ export function areSharedSlowRequestsConfigured() {
220
+ return ensureGlobal().policies.slowRequestsConfigured === true;
221
+ }
222
+ /** One-time warn when transports are wired without explicit slowRequests. */ export function warnIfSlowRequestsUnset() {
223
+ if (warnedMissingSlowRequests || areSharedSlowRequestsConfigured()) {
224
+ return;
225
+ }
226
+ warnedMissingSlowRequests = true;
227
+ // eslint-disable-next-line no-console -- host config guidance
228
+ console.warn('[journey] using default slowRequests.defaultMs=4000 — set configureJourney({ slowRequests }) to tune');
229
+ }
230
+ /** @internal Reset shared policies (tests / teardown). */ export function resetSharedPolicies() {
231
+ const api = ensureGlobal();
232
+ api.policies = createEmptyPolicies();
233
+ warnedMissingSlowRequests = false;
234
+ debugEnabledCache = undefined;
235
+ }
236
+ export function getInstrumentedAxiosSet() {
237
+ return ensureGlobal().instrumentedAxios;
238
+ }
239
+ export function getInstrumentedFetchSet() {
240
+ return ensureGlobal().instrumentedFetch;
241
+ }
242
+ export function getInstrumentedJquerySet() {
243
+ return ensureGlobal().instrumentedJquery;
244
+ }
245
+ export function registerInstrumentRecord(record) {
246
+ const api = ensureGlobal();
247
+ if (api.instrumentRecords.length >= MAX_INSTRUMENT_RECORDS) {
248
+ // eslint-disable-next-line no-console -- defensive cap for repeated instrumentation
249
+ console.warn('[journey] instrumentRecords cap reached — call teardownJourney()');
250
+ return;
251
+ }
252
+ api.instrumentRecords.push(record);
253
+ }
254
+ export function setFetchRestore(restore) {
255
+ ensureGlobal().fetchRestore = restore;
256
+ }
257
+ /**
258
+ * @internal Register this bundle's engine on `__stJourney` so DevTools can list
259
+ * every host/MFE copy on the page. Auto-assigns `runtime-N` when `runtime.id` is empty.
260
+ * Replaces an existing registration with the same id (HMR / test re-register).
261
+ */ export function registerJourneyRuntime(runtime, options) {
262
+ const bag = ensureGlobal();
263
+ if (runtime.id === '') {
264
+ runtime.id = `runtime-${bag.runtimeRegistrations.length + 1}`;
265
+ }
266
+ const entry = {
267
+ id: runtime.id,
268
+ getSnapshot: ()=>runtime.getDebugSnapshot(),
269
+ teardown: options === null || options === void 0 ? void 0 : options.teardown
270
+ };
271
+ const existing = bag.runtimeRegistrations.findIndex((reg)=>reg.id === runtime.id);
272
+ if (existing >= 0) {
273
+ bag.runtimeRegistrations[existing] = entry;
274
+ } else {
275
+ bag.runtimeRegistrations.push(entry);
276
+ }
104
277
  }
105
278
  /**
106
279
  * @internal Store a fallback RUM instance on `__stJourney.rum` when `DD_RUM` is absent.
@@ -112,5 +285,42 @@ function ensureGlobal() {
112
285
  const existing = globalThis[ST_JOURNEY_GLOBAL_KEY];
113
286
  return existing === null || existing === void 0 ? void 0 : existing.rum;
114
287
  }
288
+ /**
289
+ * Dispose HTTP instrumentation hooks and reset registered engines that supplied a
290
+ * teardown callback. Intended for tests (e.g. afterEach). Prefer `resetJourney`
291
+ * when you only need this bundle's engine state.
292
+ */ export function teardownJourney() {
293
+ const api = ensureGlobal();
294
+ for (const record of api.instrumentRecords){
295
+ record.disposed = true;
296
+ try {
297
+ var _record_restore;
298
+ (_record_restore = record.restore) === null || _record_restore === void 0 ? void 0 : _record_restore.call(record);
299
+ } catch (unused) {
300
+ // ignore restore failures
301
+ }
302
+ }
303
+ api.instrumentRecords = [];
304
+ try {
305
+ var _api_fetchRestore;
306
+ (_api_fetchRestore = api.fetchRestore) === null || _api_fetchRestore === void 0 ? void 0 : _api_fetchRestore.call(api);
307
+ } catch (unused) {
308
+ // ignore
309
+ }
310
+ api.fetchRestore = undefined;
311
+ const kept = [];
312
+ for (const entry of api.runtimeRegistrations){
313
+ if (entry.teardown) {
314
+ try {
315
+ entry.teardown();
316
+ } catch (unused) {
317
+ // ignore
318
+ }
319
+ continue;
320
+ }
321
+ kept.push(entry);
322
+ }
323
+ api.runtimeRegistrations = kept;
324
+ }
115
325
 
116
326
  //# sourceMappingURL=global.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/global.ts"],"sourcesContent":["import type { JourneyRuntime, JourneyRuntimeDebugSnapshot } from './core/runtime';\n\n/** Force-enable journey host wiring outside go* hosts (`__stJourney.enable()`). */\nexport const JOURNEY_ENABLED_STORAGE_KEY = 'st:journey:enabled';\n\n/** Opt-in journey console logging (`__stJourney.enableDebugging()`). */\nexport const JOURNEY_DEBUG_STORAGE_KEY = 'st:journey:debug';\n\n/** @internal Shared cross-bundle bag on globalThis (`rum` fallback + DevTools helpers). */\nexport const ST_JOURNEY_GLOBAL_KEY = '__stJourney';\n\nexport interface JourneyDebugRuntimeEntry extends JourneyRuntimeDebugSnapshot {\n id: string;\n}\n\nexport interface JourneyDebugState {\n /** Force-enable flag (`st:journey:enabled`). */\n enabled: boolean;\n /** Console-logging flag (`st:journey:debug`). */\n debug: boolean;\n hasRum: boolean;\n runtimes: JourneyDebugRuntimeEntry[];\n}\n\n/**\n * @internal Cross-bundle surface on `globalThis.__stJourney`.\n * Prefer importing `isJourneyEnabled` / `isJourneyDebugEnabled` from the package in app code.\n */\nexport interface StJourneyGlobal {\n /**\n * Fallback RUM instance from `setJourneyRum` when `globalThis.DD_RUM` is absent.\n * Prefer `DD_RUM` (ST host: `datadogGuard`).\n */\n rum?: unknown;\n enable(): void;\n disable(): void;\n isEnabled(): boolean;\n enableDebugging(): void;\n disableDebugging(): void;\n isDebugEnabled(): boolean;\n /**\n * Open-journey snapshot for DevTools. Returns empty `runtimes` unless debugging\n * is enabled (`enableDebugging()` / `st:journey:debug`).\n */\n getDebugState(): JourneyDebugState;\n}\n\ninterface RuntimeRegistration {\n id: string;\n getSnapshot: () => JourneyRuntimeDebugSnapshot;\n}\n\ninterface StJourneyGlobalInternal extends StJourneyGlobal {\n /** @internal */\n runtimeRegistrations: RuntimeRegistration[];\n}\n\nlet runtimeSeq = 0;\n\nfunction readFlag(key: string): boolean {\n try {\n return globalThis.localStorage?.getItem(key) === 'true';\n } catch {\n return false;\n }\n}\n\nfunction writeFlag(key: string, on: boolean): void {\n try {\n if (on) {\n globalThis.localStorage?.setItem(key, 'true');\n } else {\n globalThis.localStorage?.removeItem(key);\n }\n } catch {\n // ignore storage failures (privacy mode, non-browser)\n }\n}\n\n/** True when `localStorage['st:journey:enabled'] === 'true'` (force-on outside go*). */\nexport function isJourneyEnabled(): boolean {\n return readFlag(JOURNEY_ENABLED_STORAGE_KEY);\n}\n\n/** Set the force-enable flag. Reload after calling from DevTools. */\nexport function enableJourney(): void {\n writeFlag(JOURNEY_ENABLED_STORAGE_KEY, true);\n}\n\n/** Clear the force-enable flag. Reload after calling from DevTools. */\nexport function disableJourney(): void {\n writeFlag(JOURNEY_ENABLED_STORAGE_KEY, false);\n}\n\n/** True when `localStorage['st:journey:debug'] === 'true'`. */\nexport function isJourneyDebugEnabled(): boolean {\n return readFlag(JOURNEY_DEBUG_STORAGE_KEY);\n}\n\n/** Set the console-debug flag. Reload after calling from DevTools. */\nexport function enableJourneyDebugging(): void {\n writeFlag(JOURNEY_DEBUG_STORAGE_KEY, true);\n}\n\n/** Clear the console-debug flag. Reload after calling from DevTools. */\nexport function disableJourneyDebugging(): void {\n writeFlag(JOURNEY_DEBUG_STORAGE_KEY, false);\n}\n\nfunction hasRum(): boolean {\n return (\n (globalThis as Record<string, unknown>).DD_RUM != null || getJourneyRumFallback() != null\n );\n}\n\nfunction buildDebugState(runtimes: RuntimeRegistration[]): JourneyDebugState {\n if (!isJourneyDebugEnabled()) {\n return {\n enabled: isJourneyEnabled(),\n debug: false,\n hasRum: hasRum(),\n runtimes: [],\n };\n }\n\n return {\n enabled: isJourneyEnabled(),\n debug: true,\n hasRum: hasRum(),\n runtimes: runtimes.map(entry => ({\n id: entry.id,\n ...entry.getSnapshot(),\n })),\n };\n}\n\nfunction ensureGlobal(): StJourneyGlobalInternal {\n const g = globalThis as Record<string, unknown>;\n const existing = g[ST_JOURNEY_GLOBAL_KEY] as StJourneyGlobalInternal | undefined;\n // Reuse when a prior load already installed the full surface (incl. enable).\n if (existing?.runtimeRegistrations && typeof existing.enable === 'function') {\n return existing;\n }\n\n const runtimes: RuntimeRegistration[] = existing?.runtimeRegistrations ?? [];\n\n const api: StJourneyGlobalInternal = {\n rum: existing?.rum,\n runtimeRegistrations: runtimes,\n enable: enableJourney,\n disable: disableJourney,\n isEnabled: isJourneyEnabled,\n enableDebugging: enableJourneyDebugging,\n disableDebugging: disableJourneyDebugging,\n isDebugEnabled: isJourneyDebugEnabled,\n getDebugState() {\n return buildDebugState(api.runtimeRegistrations);\n },\n };\n\n g[ST_JOURNEY_GLOBAL_KEY] = api;\n return api;\n}\n\n/**\n * @internal Register this bundle's module runtime on `__stJourney` so DevTools can\n * list every host/MFE engine copy on the page.\n */\nexport function registerJourneyRuntime(runtime: JourneyRuntime): void {\n const globalApi = ensureGlobal();\n const id = `runtime-${++runtimeSeq}`;\n globalApi.runtimeRegistrations.push({\n id,\n getSnapshot: () => runtime.getDebugSnapshot(),\n });\n}\n\n/** @internal Ensure `__stJourney` exists (idempotent). */\nexport function installJourneyGlobal(): void {\n ensureGlobal();\n}\n\n/**\n * @internal Store a fallback RUM instance on `__stJourney.rum` when `DD_RUM` is absent.\n * Used by `setJourneyRum`.\n */\nexport function setJourneyRumFallback(rum: unknown): void {\n ensureGlobal().rum = rum;\n}\n\n/** @internal Read `__stJourney.rum` (setJourneyRum fallback). */\nexport function getJourneyRumFallback(): unknown {\n const existing = (globalThis as Record<string, unknown>)[ST_JOURNEY_GLOBAL_KEY] as\n StJourneyGlobal | undefined;\n return existing?.rum;\n}\n"],"names":["JOURNEY_ENABLED_STORAGE_KEY","JOURNEY_DEBUG_STORAGE_KEY","ST_JOURNEY_GLOBAL_KEY","runtimeSeq","readFlag","key","globalThis","localStorage","getItem","writeFlag","on","setItem","removeItem","isJourneyEnabled","enableJourney","disableJourney","isJourneyDebugEnabled","enableJourneyDebugging","disableJourneyDebugging","hasRum","DD_RUM","getJourneyRumFallback","buildDebugState","runtimes","enabled","debug","map","entry","id","getSnapshot","ensureGlobal","g","existing","runtimeRegistrations","enable","api","rum","disable","isEnabled","enableDebugging","disableDebugging","isDebugEnabled","getDebugState","registerJourneyRuntime","runtime","globalApi","push","getDebugSnapshot","installJourneyGlobal","setJourneyRumFallback"],"mappings":"AAEA,iFAAiF,GACjF,OAAO,MAAMA,8BAA8B,qBAAqB;AAEhE,sEAAsE,GACtE,OAAO,MAAMC,4BAA4B,mBAAmB;AAE5D,yFAAyF,GACzF,OAAO,MAAMC,wBAAwB,cAAc;AAgDnD,IAAIC,aAAa;AAEjB,SAASC,SAASC,GAAW;IACzB,IAAI;YACOC;QAAP,OAAOA,EAAAA,2BAAAA,WAAWC,YAAY,cAAvBD,+CAAAA,yBAAyBE,OAAO,CAACH,UAAS;IACrD,EAAE,eAAM;QACJ,OAAO;IACX;AACJ;AAEA,SAASI,UAAUJ,GAAW,EAAEK,EAAW;IACvC,IAAI;QACA,IAAIA,IAAI;gBACJJ;aAAAA,2BAAAA,WAAWC,YAAY,cAAvBD,+CAAAA,yBAAyBK,OAAO,CAACN,KAAK;QAC1C,OAAO;gBACHC;aAAAA,4BAAAA,WAAWC,YAAY,cAAvBD,gDAAAA,0BAAyBM,UAAU,CAACP;QACxC;IACJ,EAAE,eAAM;IACJ,sDAAsD;IAC1D;AACJ;AAEA,sFAAsF,GACtF,OAAO,SAASQ;IACZ,OAAOT,SAASJ;AACpB;AAEA,mEAAmE,GACnE,OAAO,SAASc;IACZL,UAAUT,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ACX;AAEA;;;CAGC,GACD,OAAO,SAASQ,uBAAuBC,OAAuB;IAC1D,MAAMC,YAAYf;IAClB,MAAMF,KAAK,CAAC,QAAQ,EAAE,EAAEzB,YAAY;IACpC0C,UAAUZ,oBAAoB,CAACa,IAAI,CAAC;QAChClB;QACAC,aAAa,IAAMe,QAAQG,gBAAgB;IAC/C;AACJ;AAEA,wDAAwD,GACxD,OAAO,SAASC;IACZlB;AACJ;AAEA;;;CAGC,GACD,OAAO,SAASmB,sBAAsBb,GAAY;IAC9CN,eAAeM,GAAG,GAAGA;AACzB;AAEA,+DAA+D,GAC/D,OAAO,SAASf;IACZ,MAAMW,WAAW,AAAC1B,UAAsC,CAACJ,sBAAsB;IAE/E,OAAO8B,qBAAAA,+BAAAA,SAAUI,GAAG;AACxB"}
1
+ {"version":3,"sources":["../src/global.ts"],"sourcesContent":["import type { SlowRequestConfig } from './core/endpoint-policy';\nimport { type RequestPolicyConfig } from './core/request-policy';\nimport type { JourneyRuntime, JourneyRuntimeDebugSnapshot } from './core/runtime';\n\n/** Force-enable journey host wiring outside go* hosts (`__stJourney.enable()`). */\nexport const JOURNEY_ENABLED_STORAGE_KEY = 'st:journey:enabled';\n\n/** Opt-in journey console logging (`__stJourney.enableDebugging()`). */\nexport const JOURNEY_DEBUG_STORAGE_KEY = 'st:journey:debug';\n\n/** @internal Shared cross-bundle bag on globalThis (`rum` fallback + DevTools helpers). */\nexport const ST_JOURNEY_GLOBAL_KEY = '__stJourney';\n\n/** Bump when shared bag shape / policy semantics change incompatibly. */\nexport const ST_JOURNEY_SCHEMA_VERSION = 2;\n\nexport interface JourneyDebugState {\n /** Host default or force-enable (`isJourneyEnabled()`). */\n enabled: boolean;\n /** Console-logging flag (`st:journey:debug`). */\n debug: boolean;\n hasRum: boolean;\n runtimes: JourneyRuntimeDebugSnapshot[];\n}\n\n/** Shared host policies visible to every package copy on the page. */\nexport interface JourneySharedPolicies {\n slowRequests?: SlowRequestConfig;\n /** Whether shared slowRequests were explicitly set via configureJourney. */\n slowRequestsConfigured: boolean;\n httpAbortedRequests: RequestPolicyConfig;\n httpClientErrorRequests: RequestPolicyConfig;\n autoAttributeRequests: boolean;\n /** True after the first configureJourney that set any shared policy knob. */\n locked: boolean;\n}\n\n/** DevTools registration — `{ id, getSnapshot }` so older package copies can still list runtimes. */\nexport interface RuntimeRegistration {\n id: string;\n getSnapshot: () => JourneyRuntimeDebugSnapshot;\n teardown?: () => void;\n}\n\n/** @internal Restore/dispose record for HTTP instrumentation. */\nexport interface InstrumentRecord {\n disposed: boolean;\n restore?: () => void;\n}\n\n/**\n * Cross-bundle surface on `globalThis.__stJourney`.\n * Prefer importing `isJourneyEnabled` / `isJourneyDebugEnabled` from the package in app code.\n */\nexport interface StJourneyGlobal {\n /**\n * Fallback RUM instance from `setJourneyRum` when `globalThis.DD_RUM` is absent.\n * Prefer `DD_RUM` (ST host: `datadogGuard`).\n */\n rum?: unknown;\n /** Shared bag schema; mismatched copies warn but continue. */\n schemaVersion?: number;\n /** Host default enable (e.g. RUM active). Set via `setJourneyDefaultEnabled`. */\n defaultEnabled?: boolean;\n /** Shared configureJourney policies. */\n policies: JourneySharedPolicies;\n /**\n * Bundle runtimes registered for DevTools `getDebugState()`.\n * `{ id, getSnapshot }` so mixed package copies can list each other.\n */\n runtimeRegistrations: RuntimeRegistration[];\n /** @internal Cross-bundle instrumented axios/fetch/jquery targets. */\n instrumentedAxios: WeakSet<object>;\n instrumentedFetch: WeakSet<object>;\n instrumentedJquery: WeakSet<object>;\n /** @internal Active instrument records for teardown. */\n instrumentRecords: InstrumentRecord[];\n fetchRestore?: () => void;\n enable(): void;\n disable(): void;\n isEnabled(): boolean;\n enableDebugging(): void;\n disableDebugging(): void;\n isDebugEnabled(): boolean;\n /**\n * Open-journey snapshot for DevTools. Returns empty `runtimes` unless debugging\n * is enabled (`enableDebugging()` / `st:journey:debug`).\n */\n getDebugState(): JourneyDebugState;\n}\n\nlet warnedMissingSlowRequests = false;\nlet debugEnabledCache: boolean | undefined;\nconst MAX_INSTRUMENT_RECORDS = 32;\n\nfunction storageFor(key: string): Storage | undefined {\n return key === JOURNEY_DEBUG_STORAGE_KEY ? globalThis.sessionStorage : globalThis.localStorage;\n}\n\nfunction readFlag(key: string): boolean {\n try {\n return storageFor(key)?.getItem(key) === 'true';\n } catch {\n return false;\n }\n}\n\nfunction writeFlag(key: string, on: boolean): void {\n try {\n const storage = storageFor(key);\n if (on) {\n storage?.setItem(key, 'true');\n } else {\n storage?.removeItem(key);\n }\n } catch {\n // ignore storage failures (privacy mode, non-browser)\n }\n}\n\n/**\n * Host default for journey wiring (e.g. RUM initialized). Stored on `__stJourney` so\n * MFEs see the same value without importing Datadog. Call once after RUM init.\n */\nexport function setJourneyDefaultEnabled(enabled: boolean): void {\n ensureGlobal().defaultEnabled = enabled === true;\n}\n\n/**\n * True when the host default is on or force-enable is set\n * (`st:journey:enabled` / `__stJourney.enable()`).\n */\nexport function isJourneyEnabled(): boolean {\n return ensureGlobal().defaultEnabled === true || readFlag(JOURNEY_ENABLED_STORAGE_KEY);\n}\n\n/** Set the force-enable flag. Reload after calling from DevTools. */\nexport function enableJourney(): void {\n writeFlag(JOURNEY_ENABLED_STORAGE_KEY, true);\n}\n\n/** Clear the force-enable flag. Reload after calling from DevTools. */\nexport function disableJourney(): void {\n writeFlag(JOURNEY_ENABLED_STORAGE_KEY, false);\n}\n\n/** True when `sessionStorage['st:journey:debug'] === 'true'`. */\nexport function isJourneyDebugEnabled(): boolean {\n const next = readFlag(JOURNEY_DEBUG_STORAGE_KEY);\n if (debugEnabledCache !== next) {\n debugEnabledCache = next;\n }\n return debugEnabledCache;\n}\n\n/** Set the console-debug flag. Reload after calling from DevTools. */\nexport function enableJourneyDebugging(): void {\n writeFlag(JOURNEY_DEBUG_STORAGE_KEY, true);\n debugEnabledCache = true;\n}\n\n/** Clear the console-debug flag. Reload after calling from DevTools. */\nexport function disableJourneyDebugging(): void {\n writeFlag(JOURNEY_DEBUG_STORAGE_KEY, false);\n debugEnabledCache = false;\n}\n\nfunction hasRum(): boolean {\n return (\n (globalThis as Record<string, unknown>).DD_RUM != null || getJourneyRumFallback() != null\n );\n}\n\nfunction snapshotOf(entry: unknown): JourneyRuntimeDebugSnapshot | undefined {\n if (entry == null || typeof entry !== 'object') {\n return undefined;\n }\n const rec = entry as {\n id?: string;\n getSnapshot?: () => JourneyRuntimeDebugSnapshot;\n getDebugSnapshot?: () => JourneyRuntimeDebugSnapshot;\n };\n try {\n if (typeof rec.getSnapshot === 'function') {\n const snap = rec.getSnapshot();\n const withId = snap.id ? snap : { ...snap, id: rec.id ?? '' };\n return {\n ...withId,\n policyOverlay: withId.policyOverlay ?? {\n slowRequests: false,\n httpAbortedRequests: false,\n httpClientErrorRequests: false,\n autoAttributeRequests: false,\n },\n };\n }\n if (typeof rec.getDebugSnapshot === 'function') {\n return rec.getDebugSnapshot();\n }\n } catch {\n return undefined;\n }\n return undefined;\n}\n\nfunction buildDebugState(runtimes: readonly unknown[]): JourneyDebugState {\n if (!isJourneyDebugEnabled()) {\n return {\n enabled: isJourneyEnabled(),\n debug: false,\n hasRum: hasRum(),\n runtimes: [],\n };\n }\n\n return {\n enabled: isJourneyEnabled(),\n debug: true,\n hasRum: hasRum(),\n runtimes: runtimes\n .map(snapshotOf)\n .filter((snap): snap is JourneyRuntimeDebugSnapshot => snap != null),\n };\n}\n\nfunction createEmptyPolicies(): JourneySharedPolicies {\n return {\n slowRequestsConfigured: false,\n httpAbortedRequests: 'continue',\n httpClientErrorRequests: 'continue',\n autoAttributeRequests: true,\n locked: false,\n };\n}\n\nfunction ensureGlobal(): StJourneyGlobal {\n const g = globalThis as Record<string, unknown>;\n const existing = g[ST_JOURNEY_GLOBAL_KEY] as StJourneyGlobal | undefined;\n // Reuse when a prior load already installed the full surface (incl. enable).\n if (existing?.runtimeRegistrations && typeof existing.enable === 'function') {\n if (\n existing.schemaVersion != null &&\n existing.schemaVersion !== ST_JOURNEY_SCHEMA_VERSION\n ) {\n // eslint-disable-next-line no-console -- cross-bundle version skew\n console.warn(\n `[journey] __stJourney.schemaVersion mismatch: bag=${existing.schemaVersion}, package=${ST_JOURNEY_SCHEMA_VERSION}`\n );\n } else {\n existing.schemaVersion ??= ST_JOURNEY_SCHEMA_VERSION;\n }\n existing.policies ??= createEmptyPolicies();\n if (existing.policies.locked !== true && existing.policies.locked !== false) {\n existing.policies.locked = false;\n }\n existing.instrumentedAxios ??= new WeakSet();\n existing.instrumentedFetch ??= new WeakSet();\n existing.instrumentedJquery ??= new WeakSet();\n existing.instrumentRecords ??= [];\n return existing;\n }\n\n const runtimes: RuntimeRegistration[] = existing?.runtimeRegistrations ?? [];\n\n const api: StJourneyGlobal = {\n rum: existing?.rum,\n schemaVersion: ST_JOURNEY_SCHEMA_VERSION,\n defaultEnabled: existing?.defaultEnabled === true,\n runtimeRegistrations: runtimes,\n policies: createEmptyPolicies(),\n instrumentedAxios: new WeakSet(),\n instrumentedFetch: new WeakSet(),\n instrumentedJquery: new WeakSet(),\n instrumentRecords: [],\n enable: enableJourney,\n disable: disableJourney,\n isEnabled: isJourneyEnabled,\n enableDebugging: enableJourneyDebugging,\n disableDebugging: disableJourneyDebugging,\n isDebugEnabled: isJourneyDebugEnabled,\n getDebugState() {\n return buildDebugState(api.runtimeRegistrations);\n },\n };\n\n g[ST_JOURNEY_GLOBAL_KEY] = api;\n return api;\n}\n\n/** @internal Shared policies bag. */\nexport function getSharedPolicies(): JourneySharedPolicies {\n return ensureGlobal().policies;\n}\n\nexport function areSharedPoliciesLocked(): boolean {\n return ensureGlobal().policies.locked === true;\n}\n\nfunction freezePolicies(policies: JourneySharedPolicies): JourneySharedPolicies {\n const next: JourneySharedPolicies = { ...policies, locked: true };\n if (next.slowRequests) {\n const endpoints = next.slowRequests.endpoints\n ? Object.freeze([...next.slowRequests.endpoints])\n : next.slowRequests.endpoints;\n next.slowRequests = Object.freeze({ ...next.slowRequests, endpoints });\n }\n return Object.freeze(next);\n}\n\n/**\n * First writer: merge `patch` into the shared bag and freeze it.\n * Returns false when already locked (caller should overlay locally instead).\n */\nexport function seedSharedPolicies(patch: Partial<Omit<JourneySharedPolicies, 'locked'>>): boolean {\n const api = ensureGlobal();\n if (api.policies.locked) {\n return false;\n }\n api.policies = freezePolicies({ ...api.policies, ...patch });\n return true;\n}\n\nexport function getAutoAttributeRequests(): boolean {\n return ensureGlobal().policies.autoAttributeRequests !== false;\n}\n\nexport function getHttpAbortedRequestsPolicy(): RequestPolicyConfig {\n return ensureGlobal().policies.httpAbortedRequests;\n}\n\nexport function getHttpClientErrorRequestsPolicy(): RequestPolicyConfig {\n return ensureGlobal().policies.httpClientErrorRequests;\n}\n\nexport function getSharedSlowRequests(): SlowRequestConfig | undefined {\n return ensureGlobal().policies.slowRequests;\n}\n\nexport function areSharedSlowRequestsConfigured(): boolean {\n return ensureGlobal().policies.slowRequestsConfigured === true;\n}\n\n/** One-time warn when transports are wired without explicit slowRequests. */\nexport function warnIfSlowRequestsUnset(): void {\n if (warnedMissingSlowRequests || areSharedSlowRequestsConfigured()) {\n return;\n }\n warnedMissingSlowRequests = true;\n // eslint-disable-next-line no-console -- host config guidance\n console.warn(\n '[journey] using default slowRequests.defaultMs=4000 — set configureJourney({ slowRequests }) to tune'\n );\n}\n\n/** @internal Reset shared policies (tests / teardown). */\nexport function resetSharedPolicies(): void {\n const api = ensureGlobal();\n api.policies = createEmptyPolicies();\n warnedMissingSlowRequests = false;\n debugEnabledCache = undefined;\n}\n\nexport function getInstrumentedAxiosSet(): WeakSet<object> {\n return ensureGlobal().instrumentedAxios;\n}\n\nexport function getInstrumentedFetchSet(): WeakSet<object> {\n return ensureGlobal().instrumentedFetch;\n}\n\nexport function getInstrumentedJquerySet(): WeakSet<object> {\n return ensureGlobal().instrumentedJquery;\n}\n\nexport function registerInstrumentRecord(record: InstrumentRecord): void {\n const api = ensureGlobal();\n if (api.instrumentRecords.length >= MAX_INSTRUMENT_RECORDS) {\n // eslint-disable-next-line no-console -- defensive cap for repeated instrumentation\n console.warn('[journey] instrumentRecords cap reached — call teardownJourney()');\n return;\n }\n api.instrumentRecords.push(record);\n}\n\nexport function setFetchRestore(restore: (() => void) | undefined): void {\n ensureGlobal().fetchRestore = restore;\n}\n\n/**\n * @internal Register this bundle's engine on `__stJourney` so DevTools can list\n * every host/MFE copy on the page. Auto-assigns `runtime-N` when `runtime.id` is empty.\n * Replaces an existing registration with the same id (HMR / test re-register).\n */\nexport function registerJourneyRuntime(\n runtime: JourneyRuntime,\n options?: { teardown?: () => void }\n): void {\n const bag = ensureGlobal();\n if (runtime.id === '') {\n (runtime as { id: string }).id = `runtime-${bag.runtimeRegistrations.length + 1}`;\n }\n const entry: RuntimeRegistration = {\n id: runtime.id,\n getSnapshot: () => runtime.getDebugSnapshot(),\n teardown: options?.teardown,\n };\n const existing = bag.runtimeRegistrations.findIndex(reg => reg.id === runtime.id);\n if (existing >= 0) {\n bag.runtimeRegistrations[existing] = entry;\n } else {\n bag.runtimeRegistrations.push(entry);\n }\n}\n\n/**\n * @internal Store a fallback RUM instance on `__stJourney.rum` when `DD_RUM` is absent.\n * Used by `setJourneyRum`.\n */\nexport function setJourneyRumFallback(rum: unknown): void {\n ensureGlobal().rum = rum;\n}\n\n/** @internal Read `__stJourney.rum` (setJourneyRum fallback). */\nexport function getJourneyRumFallback(): unknown {\n const existing = (globalThis as Record<string, unknown>)[ST_JOURNEY_GLOBAL_KEY] as\n StJourneyGlobal | undefined;\n return existing?.rum;\n}\n\n/**\n * Dispose HTTP instrumentation hooks and reset registered engines that supplied a\n * teardown callback. Intended for tests (e.g. afterEach). Prefer `resetJourney`\n * when you only need this bundle's engine state.\n */\nexport function teardownJourney(): void {\n const api = ensureGlobal();\n for (const record of api.instrumentRecords) {\n record.disposed = true;\n try {\n record.restore?.();\n } catch {\n // ignore restore failures\n }\n }\n api.instrumentRecords = [];\n try {\n api.fetchRestore?.();\n } catch {\n // ignore\n }\n api.fetchRestore = undefined;\n\n const kept: RuntimeRegistration[] = [];\n for (const entry of api.runtimeRegistrations) {\n if (entry.teardown) {\n try {\n entry.teardown();\n } catch {\n // ignore\n }\n continue;\n }\n kept.push(entry);\n }\n api.runtimeRegistrations = kept;\n}\n"],"names":["JOURNEY_ENABLED_STORAGE_KEY","JOURNEY_DEBUG_STORAGE_KEY","ST_JOURNEY_GLOBAL_KEY","ST_JOURNEY_SCHEMA_VERSION","warnedMissingSlowRequests","debugEnabledCache","MAX_INSTRUMENT_RECORDS","storageFor","key","globalThis","sessionStorage","localStorage","readFlag","getItem","writeFlag","on","storage","setItem","removeItem","setJourneyDefaultEnabled","enabled","ensureGlobal","defaultEnabled","isJourneyEnabled","enableJourney","disableJourney","isJourneyDebugEnabled","next","enableJourneyDebugging","disableJourneyDebugging","hasRum","DD_RUM","getJourneyRumFallback","snapshotOf","entry","undefined","rec","getSnapshot","withId","snap","id","policyOverlay","slowRequests","httpAbortedRequests","httpClientErrorRequests","autoAttributeRequests","getDebugSnapshot","buildDebugState","runtimes","debug","map","filter","createEmptyPolicies","slowRequestsConfigured","locked","g","existing","runtimeRegistrations","enable","schemaVersion","console","warn","policies","instrumentedAxios","WeakSet","instrumentedFetch","instrumentedJquery","instrumentRecords","api","rum","disable","isEnabled","enableDebugging","disableDebugging","isDebugEnabled","getDebugState","getSharedPolicies","areSharedPoliciesLocked","freezePolicies","endpoints","Object","freeze","seedSharedPolicies","patch","getAutoAttributeRequests","getHttpAbortedRequestsPolicy","getHttpClientErrorRequestsPolicy","getSharedSlowRequests","areSharedSlowRequestsConfigured","warnIfSlowRequestsUnset","resetSharedPolicies","getInstrumentedAxiosSet","getInstrumentedFetchSet","getInstrumentedJquerySet","registerInstrumentRecord","record","length","push","setFetchRestore","restore","fetchRestore","registerJourneyRuntime","runtime","options","bag","teardown","findIndex","reg","setJourneyRumFallback","teardownJourney","disposed","kept"],"mappings":"AAIA,iFAAiF,GACjF,OAAO,MAAMA,8BAA8B,qBAAqB;AAEhE,sEAAsE,GACtE,OAAO,MAAMC,4BAA4B,mBAAmB;AA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AoB,CAAE;QAC1C,IAAIvB,MAAMuE,QAAQ,EAAE;YAChB,IAAI;gBACAvE,MAAMuE,QAAQ;YAClB,EAAE,eAAM;YACJ,SAAS;YACb;YACA;QACJ;QACAM,KAAKd,IAAI,CAAC/D;IACd;IACAkC,IAAIX,oBAAoB,GAAGsD;AAC/B"}
package/dist/index.d.ts CHANGED
@@ -1,20 +1,19 @@
1
1
  import './config';
2
- export { defineJourney, completeJourney, excludeJourney, failJourney, journeyStep, setJourneyTags, activeJourneyStep, reportBackendRequest, resolveJourneyStep, JourneyStepTag, type JourneyDef, type JourneyHandle, type JourneyNameLike, type JourneyStepOptions, type JourneyStepRef, type JourneyStepTarget, type StepHandle, } from './core';
3
- export { configureJourney, type AppRequestTimeouts, type EndpointPolicy, type JourneyConfig, } from './config';
2
+ export { defineJourney, completeJourney, excludeJourney, failJourney, journeyStep, setJourneyTags, singleInFlightJourneyStep, resolveStamp, JourneyStepStamp, type JourneyDef, type JourneyHandle, type JourneyNameLike, type JourneyStepOptions, type JourneyStepTarget, type StepHandle, } from './core';
3
+ export { configureJourney, type JourneyConfig } from './config';
4
+ export type { EndpointPolicy, SlowRequestConfig } from './core/endpoint-policy';
5
+ export type { JourneyHttpPolicyContext, JourneyHttpScore, JourneyHttpScoreContext, JourneyRequestPolicy, JourneyStampOptions, RequestPolicyConfig, } from './core/request-policy';
4
6
  export type { JourneySink } from './core';
5
- /**
6
- * @internal Accidentally exported — removing it is a breaking change, so it stays
7
- * for compatibility. Not part of the supported public API. Test helper only.
8
- */
9
- export { resetJourney } from './core';
10
7
  export { instrumentAxios } from './integrations/axios';
11
8
  export { instrumentFetch } from './integrations/fetch';
12
9
  export { exposeAppJourney, instrumentJquery } from './integrations/jquery';
13
10
  export { requestKey, type JourneyTimedMeta } from './integrations/request-key';
14
- export { disableJourney, disableJourneyDebugging, enableJourney, enableJourneyDebugging, isJourneyDebugEnabled, isJourneyEnabled, } from './global';
11
+ export { onHttpComplete, type HttpCompleteReport } from './integrations/http-report';
12
+ export { disableJourney, disableJourneyDebugging, enableJourney, enableJourneyDebugging, isJourneyDebugEnabled, isJourneyEnabled, setJourneyDefaultEnabled, teardownJourney, } from './global';
15
13
  export { sendToConsole } from './sinks/console';
16
14
  export { normalizeTagValue, sendToDatadog, setJourneyRum } from './sinks/datadog';
17
15
  export type { JourneyEvent, JourneyStepEvent, TagValue } from './core';
18
16
  export { useJourneyName, useOptionalJourneyName } from './integrations/react/context';
19
17
  export { JourneyScope } from './integrations/react/scope';
18
+ export { useJourneyStep } from './integrations/react/use-journey-step';
20
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,UAAU,CAAC;AAElB,OAAO,EAEH,aAAa,EAEb,eAAe,EACf,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,EAEd,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,UAAU,GAClB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACH,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,aAAa,GACrB,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;A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AgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EACH,cAAc,EACd,uBAAuB,EACvB,aAAa,EACb,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,eAAe,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAElF,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC"}
package/dist/index.js CHANGED
@@ -6,20 +6,18 @@
6
6
  export { // Preferred app API.
7
7
  defineJourney, // Name-string lifecycle (prefer handle methods when you own the journey).
8
8
  completeJourney, excludeJourney, failJourney, journeyStep, setJourneyTags, // Custom transport adapters / request attribution.
9
- activeJourneyStep, reportBackendRequest, resolveJourneyStep, JourneyStepTag } from './core';
9
+ singleInFlightJourneyStep, resolveStamp, JourneyStepStamp } from './core';
10
10
  export { configureJourney } from './config';
11
- /**
12
- * @internal Accidentally exported — removing it is a breaking change, so it stays
13
- * for compatibility. Not part of the supported public API. Test helper only.
14
- */ export { resetJourney } from './core';
15
11
  export { instrumentAxios } from './integrations/axios';
16
12
  export { instrumentFetch } from './integrations/fetch';
17
13
  export { exposeAppJourney, instrumentJquery } from './integrations/jquery';
18
14
  export { requestKey } from './integrations/request-key';
19
- export { disableJourney, disableJourneyDebugging, enableJourney, enableJourneyDebugging, isJourneyDebugEnabled, isJourneyEnabled } from './global';
15
+ export { onHttpComplete } from './integrations/http-report';
16
+ export { disableJourney, disableJourneyDebugging, enableJourney, enableJourneyDebugging, isJourneyDebugEnabled, isJourneyEnabled, setJourneyDefaultEnabled, teardownJourney } from './global';
20
17
  export { sendToConsole } from './sinks/console';
21
18
  export { normalizeTagValue, sendToDatadog, setJourneyRum } from './sinks/datadog';
22
19
  export { useJourneyName, useOptionalJourneyName } from './integrations/react/context';
23
20
  export { JourneyScope } from './integrations/react/scope';
21
+ export { useJourneyStep } from './integrations/react/use-journey-step';
24
22
 
25
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*\n * Force-evaluate config so the default Datadog sink registers even when consumers only\n * import core APIs (defineJourney, etc.). Paired with package.json \"sideEffects\" for\n * config — otherwise bundlers with sideEffects:false would drop an unused re-export.\n */\nimport './config';\n\nexport {\n // Preferred app API.\n defineJourney,\n // Name-string lifecycle (prefer handle methods when you own the journey).\n completeJourney,\n excludeJourney,\n failJourney,\n journeyStep,\n setJourneyTags,\n // Custom transport adapters / request attribution.\n activeJourneyStep,\n reportBackendRequest,\n resolveJourneyStep,\n JourneyStepTag,\n type JourneyDef,\n type JourneyHandle,\n type JourneyNameLike,\n type JourneyStepOptions,\n type JourneyStepRef,\n type JourneyStepTarget,\n type StepHandle,\n} from './core';\n\nexport {\n configureJourney,\n type AppRequestTimeouts,\n type EndpointPolicy,\n type JourneyConfig,\n} from './config';\n\nexport type { JourneySink } from './core';\n\n/**\n * @internal Accidentally exported — removing it is a breaking change, so it stays\n * for compatibility. Not part of the supported public API. Test helper only.\n */\nexport { resetJourney } from './core';\n\nexport { instrumentAxios } from './integrations/axios';\nexport { instrumentFetch } from './integrations/fetch';\nexport { exposeAppJourney, instrumentJquery } from './integrations/jquery';\nexport { requestKey, type JourneyTimedMeta } from './integrations/request-key';\nexport {\n disableJourney,\n disableJourneyDebugging,\n enableJourney,\n enableJourneyDebugging,\n isJourneyDebugEnabled,\n isJourneyEnabled,\n} from './global';\nexport { sendToConsole } from './sinks/console';\nexport { normalizeTagValue, sendToDatadog, setJourneyRum } from './sinks/datadog';\n\nexport type { JourneyEvent, JourneyStepEvent, TagValue } from './core';\n\nexport { useJourneyName, useOptionalJourneyName } from './integrations/react/context';\nexport { JourneyScope } from './integrations/react/scope';\n"],"names":["defineJourney","completeJourney","excludeJourney","failJourney","journeyStep","setJourneyTags","activeJourneyStep","reportBackendRequest","resolveJourneyStep","JourneyStepTag","configureJourney","resetJourney","instrumentAxios","instrumentFetch","exposeAppJourney","instrumentJquery","requestKey","disableJourney","disableJourneyDebugging","enableJourney","enableJourneyDebugging","isJourneyDebugEnabled","isJourneyEnabled","sendToConsole","normalizeTagValue","sendToDatadog","setJourneyRum","useJourneyName","useOptionalJourneyName","JourneyScope"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,WAAW;AAElB,SACI,qBAAqB;AACrBA,aAAa,EACb,0EAA0E;AAC1EC,eAAe,EACfC,cAAc,EACdC,WAAW,EACXC,WAAW,EACXC,cAAc,EACd,mDAAmD;AACnDC,iBAAiB,EACjBC,oBAAoB,EACpBC,kBAAkB,EAClBC,cAAc,QAQX,SAAS;AAEhB,SACIC,gBAAgB,QAIb,WAAW;AAIlB;;;CAGC,GACD,SAASC,YAAY,QAAQ,SAAS;AAEtC,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,wBAAwB;AAC3E,SAASC,UAAU,QAA+B,6BAA6B;AAC/E,SACIC,cAAc,EACdC,uBAAuB,EACvBC,aAAa,EACbC,sBAAsB,EACtBC,qBAAqB,EACrBC,gBAAgB,QACb,WAAW;AAClB,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,aAAa,QAAQ,kBAAkB;AAIlF,SAASC,cAAc,EAAEC,sBAAsB,QAAQ,+BAA+B;AACtF,SAASC,YAAY,QAAQ,6BAA6B"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*\n * Force-evaluate config so the default Datadog sink registers even when consumers only\n * import core APIs (defineJourney, etc.). Paired with package.json \"sideEffects\" for\n * config — otherwise bundlers with sideEffects:false would drop an unused re-export.\n */\nimport './config';\n\nexport {\n // Preferred app API.\n defineJourney,\n // Name-string lifecycle (prefer handle methods when you own the journey).\n completeJourney,\n excludeJourney,\n failJourney,\n journeyStep,\n setJourneyTags,\n // Custom transport adapters / request attribution.\n singleInFlightJourneyStep,\n resolveStamp,\n JourneyStepStamp,\n type JourneyDef,\n type JourneyHandle,\n type JourneyNameLike,\n type JourneyStepOptions,\n type JourneyStepTarget,\n type StepHandle,\n} from './core';\n\nexport { configureJourney, type JourneyConfig } from './config';\nexport type { EndpointPolicy, SlowRequestConfig } from './core/endpoint-policy';\nexport type {\n JourneyHttpPolicyContext,\n JourneyHttpScore,\n JourneyHttpScoreContext,\n JourneyRequestPolicy,\n JourneyStampOptions,\n RequestPolicyConfig,\n} from './core/request-policy';\n\nexport type { JourneySink } from './core';\n\nexport { instrumentAxios } from './integrations/axios';\nexport { instrumentFetch } from './integrations/fetch';\nexport { exposeAppJourney, instrumentJquery } from './integrations/jquery';\nexport { requestKey, type JourneyTimedMeta } from './integrations/request-key';\nexport { onHttpComplete, type HttpCompleteReport } from './integrations/http-report';\nexport {\n disableJourney,\n disableJourneyDebugging,\n enableJourney,\n enableJourneyDebugging,\n isJourneyDebugEnabled,\n isJourneyEnabled,\n setJourneyDefaultEnabled,\n teardownJourney,\n} from './global';\nexport { sendToConsole } from './sinks/console';\nexport { normalizeTagValue, sendToDatadog, setJourneyRum } from './sinks/datadog';\n\nexport type { JourneyEvent, JourneyStepEvent, TagValue } from './core';\n\nexport { useJourneyName, useOptionalJourneyName } from './integrations/react/context';\nexport { JourneyScope } from './integrations/react/scope';\nexport { useJourneyStep } from './integrations/react/use-journey-step';\n"],"names":["defineJourney","completeJourney","excludeJourney","failJourney","journeyStep","setJourneyTags","singleInFlightJourneyStep","resolveStamp","JourneyStepStamp","configureJourney","instrumentAxios","instrumentFetch","exposeAppJourney","instrumentJquery","requestKey","onHttpComplete","disableJourney","disableJourneyDebugging","enableJourney","enableJourneyDebugging","isJourneyDebugEnabled","isJourneyEnabled","setJourneyDefaultEnabled","teardownJourney","sendToConsole","normalizeTagValue","sendToDatadog","setJourneyRum","useJourneyName","useOptionalJourneyName","JourneyScope","useJourneyStep"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,WAAW;AAElB,SACI,qBAAqB;AACrBA,aAAa,EACb,0EAA0E;AAC1EC,eAAe,EACfC,cAAc,EACdC,WAAW,EACXC,WAAW,EACXC,cAAc,EACd,mDAAmD;AACnDC,yBAAyB,EACzBC,YAAY,EACZC,gBAAgB,QAOb,SAAS;AAEhB,SAASC,gBAAgB,QAA4B,WAAW;AAahE,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,eAAe,QAAQ,uBAAuB;AACvD,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,wBAAwB;AAC3E,SAASC,UAAU,QAA+B,6BAA6B;AAC/E,SAASC,cAAc,QAAiC,6BAA6B;AACrF,SACIC,cAAc,EACdC,uBAAuB,EACvBC,aAAa,EACbC,sBAAsB,EACtBC,qBAAqB,EACrBC,gBAAgB,EAChBC,wBAAwB,EACxBC,eAAe,QACZ,WAAW;AAClB,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,aAAa,QAAQ,kBAAkB;AAIlF,SAASC,cAAc,EAAEC,sBAAsB,QAAQ,+BAA+B;AACtF,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,cAAc,QAAQ,wCAAwC"}
@@ -8,9 +8,11 @@ export interface AxiosLikeInstance {
8
8
  interceptors: {
9
9
  request: {
10
10
  use(onFulfilled: (config: any) => any): unknown;
11
+ eject?(id: unknown): void;
11
12
  };
12
13
  response: {
13
14
  use(onFulfilled: (response: any) => any, onRejected?: (error: any) => any): unknown;
15
+ eject?(id: unknown): void;
14
16
  };
15
17
  };
16
18
  }
@@ -18,6 +20,8 @@ export interface AxiosLikeInstance {
18
20
  * Wire an axios instance into the journey engine (observation-only).
19
21
  * Call once per instance (idempotent). Register any async request interceptors
20
22
  * (e.g. auth) before this call so this one runs first.
23
+ * Soft-skips when `instance` is missing or not axios-like — hosts can pass axios as-is.
24
+ * Returns a restore function that disposes handlers (they no-op after restore).
21
25
  */
22
- export declare function instrumentAxios(instance: AxiosLikeInstance): void;
26
+ export declare function instrumentAxios(instance: AxiosLikeInstance | null | undefined): () => void;
23
27
  //# sourceMappingURL=axios.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../src/integrations/axios.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,YAAY,EAAE;QACV,OAAO,EAAE;YAAE,GAAG,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAA;SAAE,CAAC;QAC7D,QAAQ,EAAE;YACN,GAAG,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC;SACvF,CAAC;KACL,CAAC;CACL;AAoBD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAwCjE"}
1
+ {"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../src/integrations/axios.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,EA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